Usermode/crt0 - Added shared version for libraries
authorJohn Hodge <[email protected]>
Sat, 31 May 2014 05:36:52 +0000 (13:36 +0800)
committerJohn Hodge <[email protected]>
Sat, 31 May 2014 05:36:52 +0000 (13:36 +0800)
Usermode/Libraries/crt0.o_src/Makefile
Usermode/Libraries/crt0.o_src/crt0.c
Usermode/Libraries/crt0.o_src/crt0S.c [new file with mode: 0644]

index a68fefa..c1966ad 100644 (file)
@@ -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 $@)
index a87cfbf..3cdbe11 100644 (file)
@@ -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 (file)
index 0000000..1f35ce4
--- /dev/null
@@ -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;
+}

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