summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/arm
diff options
context:
space:
mode:
Diffstat (limited to 'libc/sysdeps/linux/arm')
-rw-r--r--libc/sysdeps/linux/arm/Makefile11
-rw-r--r--libc/sysdeps/linux/arm/crt0pic.S74
2 files changed, 83 insertions, 2 deletions
diff --git a/libc/sysdeps/linux/arm/Makefile b/libc/sysdeps/linux/arm/Makefile
index c6505c93c..4b23adae7 100644
--- a/libc/sysdeps/linux/arm/Makefile
+++ b/libc/sysdeps/linux/arm/Makefile
@@ -25,7 +25,14 @@ include $(TOPDIR)Rules.mak
LIBC=$(TOPDIR)libc.a
ASFLAGS=$(CFLAGS)
-CRT0=crt0.S
+TARGET_MACHINE_TYPE=$(shell $(CC) -dumpmachine)
+
+ifeq ($(TARGET_MACHINE_TYPE),arm-pic-elf)
+ CRT0=crt0pic.S
+else
+ CRT0=crt0.S
+endif
+
CRT0_OBJ=$(patsubst %.S,%.o, $(CRT0))
SSRC=longjmp.S setjmp.S
@@ -43,7 +50,7 @@ $(LIBC): ar-target
ar-target: $(OBJS) $(CRT0_OBJ)
$(AR) $(ARFLAGS) $(LIBC) $(OBJS)
- cp $(CRT0_OBJ) $(TOPDIR)$(CRT0_OBJ)
+ cp $(CRT0_OBJ) $(TOPDIR)crt0.o
$(CRT0_OBJ): %.o : %.S
$(CC) $(CFLAGS) -c $< -o $@
diff --git a/libc/sysdeps/linux/arm/crt0pic.S b/libc/sysdeps/linux/arm/crt0pic.S
new file mode 100644
index 000000000..8e2257865
--- /dev/null
+++ b/libc/sysdeps/linux/arm/crt0pic.S
@@ -0,0 +1,74 @@
+.text
+ .align 2
+ .global __environ
+ .global _start
+ .global exit
+ .global main
+ .global __libc_init
+ .global __init_stdio
+ .global __stdio_close_all
+ .global _void_void_null_func
+
+ .type _start,%function
+ .type exit,%function
+ .type main,%function
+ .type __libc_init,%function
+ .type __init_stdio,%function
+ .type __stdio_close_all,%function
+ .type _void_void_null_func,%function
+
+
+
+@ r0 = argc
+@ r1 = argv
+@ r2 = envp
+@ sl = data segment
+
+.text
+_start:
+ @ adjust the data segment base pointer
+ ldr r3,=__data_start
+ sub sl,sl,r3
+ mov r9,sl
+
+ ldr r3, .L3
+ str r2,[r9,r3]
+ ldr r0,[sp, #0]
+ ldr r1,[sp, #4]
+ ldr r2,[sp, #8]
+
+ /* Tell libc to initialize whatever it needs */
+ bl __libc_init
+ bl __init_stdio
+ bl main
+/* ldr r0,=0 */
+ bl exit
+
+_void_void_null_func:
+ nop
+
+.weak __libc_init
+__libc_init = _void_void_null_func
+
+.weak __init_stdio
+__init_stdio = _void_void_null_func
+
+.weak __stdio_close_all
+__stdio_close_all = _void_void_null_func
+
+.align 2
+.L3:
+ .word environ
+
+
+.data
+ .align 2
+ .global __environ
+
+__environ:
+ .long 0
+
+.weak environ
+environ = __environ
+
+