About _init and _start

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

About _init and _start

Post by m0skit0 »

Just a quick question: _init is for data intialization and it is executed before _start... is this right? Because ELF header sets entry point for _start address.
The Incredible Bill Gates wrote:The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

As long as _start is set to the entry point it runs before _init, well in actual fact your _start routine is responsible for calling _init
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Post by m0skit0 »

Arigato sensei :)
The Incredible Bill Gates wrote:The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

tyranid what is the difference between module_start and _start ?
does the function module_start call _start ?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

There is no difference, module_start is just a synonym for _start. The reason you will see module_start being used is that the actual name sony used (based on reversing the hash) and so in certain situations we use that name for ease.
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

when i don"t declare _start and declare module_start the linker complain about _start missing.

Code: Select all

	.globl	module_info
	.section	.rodata.sceModuleInfo,"a",@progbits
	.align	4
	.type	module_info, @object
	.size	module_info, 52
module_info:
	.half	0
	.byte	1
	.byte	1
	.ascii	"Hello world\000"
	.space	15
	.byte	0
	.word	_gp
	.word	__lib_ent_top
	.word	__lib_ent_bottom
	.word	__lib_stub_top
	.word	__lib_stub_bottom
	.set push
        .section .lib.ent.top, "a", @progbits
        .align 2
        .word 0
__lib_ent_top:
        .section .lib.ent.btm, "a", @progbits
        .align 2
__lib_ent_bottom:
        .word 0
        .section .lib.stub.top, "a", @progbits
        .align 2
        .word 0
__lib_stub_top:
        .section .lib.stub.btm, "a", @progbits
        .align 2
__lib_stub_bottom:
        .word 0
IMPORT_START	"LoadExecForKernel",0x00010000
 IMPORT_FUNC	"LoadExecForKernel",0x05572A5F,sceKernelExitGame  
        .set pop
        .text
        .rdata
	.align	2
$LC2:
	.ascii	"Hello World from ASM Mips!\000"
	.align	2
	.globl	module_start
	.set	nomips16

  

    .text 
_start:
module_start:
	
	.set	noreorder
	
	addiu	$sp,$sp,-8
	sw	$31,4($sp)
	sw	$fp,0($sp)
	move	$fp,$sp
#	jal	pspDebugScreenInit
#	nop

	lui	$2,%hi($LC2)
	addiu	$4,$2,%lo($LC2)
#	jal	pspDebugScreenPrintf
#	nop

	jal	sceKernelExitGame
	nop

	move	$2,$0
	move	$sp,$fp
	lw	$31,4($sp)
	lw	$fp,0($sp)
	addiu	$sp,$sp,8
	j	$31
	nop
sp-gcc -I. -I/home/f731/pspdev/psp/sdk/include -O2 -G0 -Wall -mno-crt0 -nostartfiles -I. -I/home/f731/pspdev/psp/sdk/include -O2 -G0 -Wall -mno-crt0 -nostartfiles -o helloworld.o helloworld.s
/home/f731/pspdev/lib/gcc/psp/4.3.2/../../../../psp/bin/ld: AVERTISSEMENT: ne peut trouver le symbole d'entrée _start; utilise par défaut 0000000008900018

i try to make a hello world program in asm mips for kernel 3.x

when i add .globl _start the warning dissaspear
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Add -S to the CFLAGS in the makefile and make one of the simple examples that come with the SDK. That will generate assembly files for everything. That's the best way to figure all that out.
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

Done JF thx a lot. I was studying mips assembler with a emulator called
yams. But there was a lot of pseudo code generated that are elf related and not
mips related like progbits etc ...(thx m0skit0 for the explantion)
The purpose was just to make a hello world in asm working on the psp on en 3.x firmware.

nb: I was obliged to add the -c so the linkedit is not performed and the .S file
is not deleted but if you do that you must also see at the source of the crt0.s
of the sdk to have a working sample ;)

psp-gcc -I/home/f731/pspdev/psp/sdk/include -O2 -G0 -Wall -c -S main.c
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Oh, yeah - I keep forgetting you need to put those two switches together. :)
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

When building a program as an ELF it uses _start (for legacy reasons) when building a prx it uses module_start (for crazy reasons)
Post Reply