From: John Hodge Date: Thu, 17 Nov 2011 14:11:16 +0000 (+0800) Subject: Usermode/crt0 - Cleaned up and added ctrbegin/crtend for .ctors support X-Git-Tag: rel0.14~98 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=fb6e2db49eccb97eff2d27b00bdbecb2d3c50b92;p=tpg%2Facess2.git Usermode/crt0 - Cleaned up and added ctrbegin/crtend for .ctors support --- diff --git a/Usermode/Libraries/crt0.o_src/Makefile b/Usermode/Libraries/crt0.o_src/Makefile index 8e4787d6..55ae732c 100644 --- a/Usermode/Libraries/crt0.o_src/Makefile +++ b/Usermode/Libraries/crt0.o_src/Makefile @@ -4,7 +4,7 @@ -include ../Makefile.cfg -BIN = $(OUTPUTDIR)Libs/crt0.o +BIN = $(OUTPUTDIR)Libs/crt0.o $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o .PHONY: all clean install @@ -15,6 +15,19 @@ install: $(BIN) clean: $(RM) $(BIN) -$(BIN): crt0.$(ARCHDIR).$(ASSUFFIX) - @mkdir -p $(dir $(BIN)) - $(AS) $(ASFLAGS) $< -o $@ +$(OUTPUTDIR)Libs/%.o: %.c + @mkdir -p $(dir $@) + $(CC) -c $< -o $@ + +#$(OUTPUTDIR)Libs/crt0.o: obj-$(ARCH)/crt0_asm.o obj-$(ARCH)/crt0_c.o +# @mkdir -p $(dir $@) +# $(LD) -r -o $@ $? + +#obj-$(ARCH)/crt0_asm.o: crt0.$(ARCHDIR).$(ASSUFFIX) +# @mkdir -p $(dir $@) +# $(AS) $(ASFLAGS) $< -o $@ + +#obj-$(ARCH)/crt0_c.o: crt0.c +# @mkdir -p $(dir $@) +# $(CC) -c $< -o $@ + diff --git a/Usermode/Libraries/crt0.o_src/crt0.armv7.S b/Usermode/Libraries/crt0.o_src/crt0.armv7.S deleted file mode 100644 index 157ba15d..00000000 --- a/Usermode/Libraries/crt0.o_src/crt0.armv7.S +++ /dev/null @@ -1,24 +0,0 @@ -@ -@ Acess2 -@ C Runtime 0 -@ - crt0.arm7.asm - -.globl _start -_start: - bl main - push {r0} - - ldr r0, =_crt0_exit_handler - ldr r0, [r0] - tst r0, r0 - blxne r0 - - pop {r0} - - bl _exit - b . @ This should never be reached - -.section .bss -.globl _crt0_exit_handler -_crt0_exit_handler: - .long 0 diff --git a/Usermode/Libraries/crt0.o_src/crt0.c b/Usermode/Libraries/crt0.o_src/crt0.c new file mode 100644 index 00000000..7c0e3ff9 --- /dev/null +++ b/Usermode/Libraries/crt0.o_src/crt0.c @@ -0,0 +1,26 @@ +/* + * Acess2 + * - C Runtime 0 Common Code + */ + +typedef void (*exithandler_t)(void); +typedef void (*constructor_t)(void); + +exithandler_t _crt0_exit_handler; +extern constructor_t _crtbegin_ctors[]; + +int start(int argc, char *argv[], char **envp) +{ + int i; + int rv; + + for( i = 0; _crtbegin_ctors[i]; i ++ ) + _crtbegin_ctors[i](); + + rv = main(argc, argv, envp); + + if( _crt0_exit_handler ) + _crt0_exit_handler(); + + return rv; +} diff --git a/Usermode/Libraries/crt0.o_src/crt0.x86.asm b/Usermode/Libraries/crt0.o_src/crt0.x86.asm deleted file mode 100644 index 531a3783..00000000 --- a/Usermode/Libraries/crt0.o_src/crt0.x86.asm +++ /dev/null @@ -1,30 +0,0 @@ -; -; Acess2 -; C Runtime 0 -; - crt0.asm - -[BITS 32] -[section .text] - - -[global _start] -[global start] -[extern main] -[extern _exit] -_start: -start: - call main - push eax - - mov eax, [_crt0_exit_handler] - test eax, eax - jz .exit - call eax - -.exit: - call _exit - jmp $ ; This should never be reached -[section .bss] -[global _crt0_exit_handler] -_crt0_exit_handler: - resd 1 diff --git a/Usermode/Libraries/crt0.o_src/crt0.x86_64.asm b/Usermode/Libraries/crt0.o_src/crt0.x86_64.asm deleted file mode 100644 index fb0115d5..00000000 --- a/Usermode/Libraries/crt0.o_src/crt0.x86_64.asm +++ /dev/null @@ -1,31 +0,0 @@ -; -; Acess2 -; C Runtime 0 -; - crt0.asm - -[BITS 64] -[section .text] - - -[global _start] -[global start] -[extern main] -[extern _exit] -_start: -start: - call main - push rax - - mov rax, [_crt0_exit_handler] - test rax, rax - jz .exit - call rax - -.exit: - call _exit - jmp $ ; This should never be reached - -[section .bss] -[global _crt0_exit_handler] -_crt0_exit_handler: - resq 1 diff --git a/Usermode/Libraries/crt0.o_src/crtbegin.c b/Usermode/Libraries/crt0.o_src/crtbegin.c new file mode 100644 index 00000000..8e18f89b --- /dev/null +++ b/Usermode/Libraries/crt0.o_src/crtbegin.c @@ -0,0 +1,2 @@ + +void *_crtbegin_ctors[0] __attribute__((section(".ctors"))); diff --git a/Usermode/Libraries/crt0.o_src/crtend.c b/Usermode/Libraries/crt0.o_src/crtend.c new file mode 100644 index 00000000..466b7c70 --- /dev/null +++ b/Usermode/Libraries/crt0.o_src/crtend.c @@ -0,0 +1,2 @@ + +void *_crtend_ctors[1] __attribute__((section(".ctors")));