Usermode/crt0 - Replaced crtbegin/crtend with crti/crtn
authorJohn Hodge <[email protected]>
Mon, 26 May 2014 09:45:12 +0000 (17:45 +0800)
committerJohn Hodge <[email protected]>
Mon, 26 May 2014 09:45:12 +0000 (17:45 +0800)
Usermode/Libraries/crt0.o_src/Makefile
Usermode/Libraries/crt0.o_src/crt0.c
Usermode/Libraries/crt0.o_src/x86-crti.S [new file with mode: 0644]
Usermode/Libraries/crt0.o_src/x86-crtn.S [new file with mode: 0644]

index 3c20896..a68fefa 100644 (file)
@@ -4,7 +4,7 @@
 
 -include ../Makefile.cfg
 
-BIN = $(OUTPUTDIR)Libs/crt0.o $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o
+BIN = $(OUTPUTDIR)Libs/crt0.o $(OUTPUTDIR)Libs/crti.o $(OUTPUTDIR)Libs/crtn.o
 
 .PHONY: all clean install utest utest-build generate_exp
 
@@ -22,6 +22,9 @@ utest generate_exp utest-build utest-run:
 $(OUTPUTDIR)Libs/%.o: %.c
        @mkdir -p $(dir $@)
        $(CC) -c $< -o $@
+$(OUTPUTDIR)Libs/%.o: $(ARCHDIR)-%.S
+       @mkdir -p $(dir $@)
+       $(CC) -c $< -o $@
 
 #$(OUTPUTDIR)Libs/crt0.o: obj-$(ARCH)/crt0_asm.o obj-$(ARCH)/crt0_c.o
 #      @mkdir -p $(dir $@)
index 8363aea..a87cfbf 100644 (file)
@@ -10,6 +10,8 @@ constructor_t _crtbegin_ctors[0] __attribute__((section(".ctors")));
 
 exithandler_t  _crt0_exit_handler;
 //extern constructor_t _crtbegin_ctors[];
+extern void    _init(void);
+extern void    _fini(void);
 extern void    _exit(int status) __attribute__((noreturn));
 extern int     main(int argc, char *argv[], char **envp);
 
@@ -22,11 +24,13 @@ void start(int argc, char *argv[], char **envp)
        
        for( i = 0; _crtbegin_ctors[i]; i ++ )
                _crtbegin_ctors[i]();
+       
+       _init();
 
        rv = main(argc, argv, envp);
        
        if( _crt0_exit_handler )
                _crt0_exit_handler();
-
+       _fini();
        _exit(rv);
 }
diff --git a/Usermode/Libraries/crt0.o_src/x86-crti.S b/Usermode/Libraries/crt0.o_src/x86-crti.S
new file mode 100644 (file)
index 0000000..cebea3e
--- /dev/null
@@ -0,0 +1,15 @@
+.section .init
+.global _init
+.type _init, @function
+_init:
+       push %ebp
+       movl %esp, %ebp
+       /* gcc will nicely put the contents of crtbegin.o's .init section here. */
+
+.section .fini
+.global _fini
+.type _fini, @function
+_fini:
+       push %ebp
+       movl %esp, %ebp
+       /* gcc will nicely put the contents of crtbegin.o's .fini section here. */
diff --git a/Usermode/Libraries/crt0.o_src/x86-crtn.S b/Usermode/Libraries/crt0.o_src/x86-crtn.S
new file mode 100644 (file)
index 0000000..33957bf
--- /dev/null
@@ -0,0 +1,9 @@
+.section .init
+       /* gcc will nicely put the contents of crtend.o's .init section here. */
+       popl %ebp
+       ret
+
+.section .fini
+       /* gcc will nicely put the contents of crtend.o's .fini section here. */
+       popl %ebp
+       ret

UCC git Repository :: git.ucc.asn.au