-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
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 $@
+
+++ /dev/null
-@
-@ 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
--- /dev/null
+/*
+ * 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;
+}
+++ /dev/null
-;
-; 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
+++ /dev/null
-;
-; 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
--- /dev/null
+
+void *_crtbegin_ctors[0] __attribute__((section(".ctors")));
--- /dev/null
+
+void *_crtend_ctors[1] __attribute__((section(".ctors")));