Usermode/crt0 - Cleaned up and added ctrbegin/crtend for .ctors support
authorJohn Hodge <[email protected]>
Thu, 17 Nov 2011 14:11:16 +0000 (22:11 +0800)
committerJohn Hodge <[email protected]>
Thu, 17 Nov 2011 14:11:16 +0000 (22:11 +0800)
Usermode/Libraries/crt0.o_src/Makefile
Usermode/Libraries/crt0.o_src/crt0.armv7.S [deleted file]
Usermode/Libraries/crt0.o_src/crt0.c [new file with mode: 0644]
Usermode/Libraries/crt0.o_src/crt0.x86.asm [deleted file]
Usermode/Libraries/crt0.o_src/crt0.x86_64.asm [deleted file]
Usermode/Libraries/crt0.o_src/crtbegin.c [new file with mode: 0644]
Usermode/Libraries/crt0.o_src/crtend.c [new file with mode: 0644]

index 8e4787d..55ae732 100644 (file)
@@ -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 (file)
index 157ba15..0000000
+++ /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 (file)
index 0000000..7c0e3ff
--- /dev/null
@@ -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 (file)
index 531a378..0000000
+++ /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 (file)
index fb0115d..0000000
+++ /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 (file)
index 0000000..8e18f89
--- /dev/null
@@ -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 (file)
index 0000000..466b7c7
--- /dev/null
@@ -0,0 +1,2 @@
+
+void   *_crtend_ctors[1] __attribute__((section(".ctors")));

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