From: John Hodge Date: Sat, 31 May 2014 05:36:52 +0000 (+0800) Subject: Usermode/crt0 - Added shared version for libraries X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=ac1ebb0d8f390a13be96f4cb6186f50473817d34;p=tpg%2Facess2.git Usermode/crt0 - Added shared version for libraries --- diff --git a/Usermode/Libraries/crt0.o_src/Makefile b/Usermode/Libraries/crt0.o_src/Makefile index a68fefa0..c1966ad3 100644 --- a/Usermode/Libraries/crt0.o_src/Makefile +++ b/Usermode/Libraries/crt0.o_src/Makefile @@ -4,7 +4,9 @@ -include ../Makefile.cfg -BIN = $(OUTPUTDIR)Libs/crt0.o $(OUTPUTDIR)Libs/crti.o $(OUTPUTDIR)Libs/crtn.o +BIN = $(OUTPUTDIR)Libs/crt0.o $(OUTPUTDIR)Libs/crt0S.o $(OUTPUTDIR)Libs/crti.o $(OUTPUTDIR)Libs/crtn.o + +CFLAGS := -std=c99 .PHONY: all clean install utest utest-build generate_exp @@ -19,12 +21,15 @@ clean: utest generate_exp utest-build utest-run: @echo > /dev/null -$(OUTPUTDIR)Libs/%.o: %.c +$(OUTPUTDIR)Libs/%.o: %.c Makefile + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) -c $< -o $@ +$(OUTPUTDIR)Libs/%S.o: %S.c Makefile @mkdir -p $(dir $@) - $(CC) -c $< -o $@ + $(CC) $(CFLAGS) -c $< -o $@ -fPIC $(OUTPUTDIR)Libs/%.o: $(ARCHDIR)-%.S @mkdir -p $(dir $@) - $(CC) -c $< -o $@ + $(CC) $(CFLAGS) -c $< -o $@ #$(OUTPUTDIR)Libs/crt0.o: obj-$(ARCH)/crt0_asm.o obj-$(ARCH)/crt0_c.o # @mkdir -p $(dir $@) diff --git a/Usermode/Libraries/crt0.o_src/crt0.c b/Usermode/Libraries/crt0.o_src/crt0.c index a87cfbf9..3cdbe119 100644 --- a/Usermode/Libraries/crt0.o_src/crt0.c +++ b/Usermode/Libraries/crt0.o_src/crt0.c @@ -9,7 +9,6 @@ typedef void (*constructor_t)(void); 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)); @@ -19,15 +18,13 @@ void _start(int argc, char *argv[], char **envp) __attribute__ ((alias("start")) void start(int argc, char *argv[], char **envp) { - int i; - int rv; - - for( i = 0; _crtbegin_ctors[i]; i ++ ) + // TODO: isn't this handled by _init? + for( int i = 0; _crtbegin_ctors[i]; i ++ ) _crtbegin_ctors[i](); _init(); - rv = main(argc, argv, envp); + int rv = main(argc, argv, envp); if( _crt0_exit_handler ) _crt0_exit_handler(); diff --git a/Usermode/Libraries/crt0.o_src/crt0S.c b/Usermode/Libraries/crt0.o_src/crt0S.c new file mode 100644 index 00000000..1f35ce45 --- /dev/null +++ b/Usermode/Libraries/crt0.o_src/crt0S.c @@ -0,0 +1,23 @@ +/* + * Acess2 + * - CRT0 Shared library version + */ + +typedef void (*exithandler_t)(void); +typedef void (*constructor_t)(void); + +extern void _SysDebug(const char *, ...); +extern void _init(void); +extern void _fini(void); +extern int SoMain(void *Base, int argc, char *argv[], char **envp) __attribute__((weak)); + +int SoStart(void *Base, int argc, char *argv[], char **envp) +{ + //_SysDebug("SoStart(%p,%i,%p)", Base, argc, argv); + _init(); + + if( SoMain ) + return SoMain(Base, argc, argv, envp); + else + return 0; +}