summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/nds32/crt1.S
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2016-04-21 01:25:29 +0200
committerWaldemar Brodkorb <wbx@uclibc-ng.org>2016-06-30 03:24:42 +0200
commitee92c0fe5c1b9d59508273916e2c9a75b68dbc13 (patch)
tree65a22258b12f84325910fc2ad47e2b02696ef593 /libc/sysdeps/linux/nds32/crt1.S
parentdd46699e46decb7273f44dc2cbf307f096dc39e8 (diff)
nds32: add support for new architecture
Add support for Andes Technology NDS32 architecture. See here http://www.andestech.com/en/index/index.htm for more informaton. Verification of the port from an older uClibc port was done on a sponsored AG101p board. The testsuite only has 5 errors, three are related to an existing bug in dlclose() with LT.old, also happening on cris32 and m68k. Failures to fallocate/posix_fallocate are unresolved. Thanks to Andes Technology sponsoring the hardware and being very helpful while doing the uClibc-ng porting. Signed-off-by: Waldemar Brodkorb <wbx@uclibc-ng.org>
Diffstat (limited to 'libc/sysdeps/linux/nds32/crt1.S')
-rw-r--r--libc/sysdeps/linux/nds32/crt1.S96
1 files changed, 96 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/nds32/crt1.S b/libc/sysdeps/linux/nds32/crt1.S
new file mode 100644
index 000000000..54544010f
--- /dev/null
+++ b/libc/sysdeps/linux/nds32/crt1.S
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2016 Andes Technology, Inc.
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ */
+
+/* Startup code compliant to the ELF NDS32 ABI */
+
+#include <sys/regdef.h>
+#include <features.h>
+#define BP_SYM(name) name
+
+/* We need to call:
+ __uClibc_main (int (*main) (int, char **, char **), int argc,
+ char **argv, void (*init) (void), void (*fini) (void),
+ void (*rtld_fini) (void), void *stack_end)
+*/
+
+.text
+ .globl _start
+ .type _start,@function
+ .type _init,@function
+ .type _fini,@function
+#ifndef __UCLIBC_CTOR_DTOR__
+ .weak _init
+ .weak _fini
+#endif
+ .type main,@function
+ .type __uClibc_main,@function
+#ifdef SHARED
+.pic
+1:
+ ret
+#endif
+
+_start:
+ movi $fp, 0 ! clear FP
+ lwi $r1, [$sp + 0] ! r1 = argc
+ addi $r2, $sp, 4 ! r2 = argv
+
+ /* align sp to 8-byte boundary */
+ movi $r0, -8
+ and $sp, $sp, $r0
+
+ addi $r6, $sp, 0 ! r6 = stack top
+
+#ifdef SHARED
+ /* set gp register */
+#ifdef __NDS32_N1213_43U1H__
+ jal 1b
+ sethi $gp, HI20(_GLOBAL_OFFSET_TABLE_)
+ ori $gp, $gp, LO12(_GLOBAL_OFFSET_TABLE_ + 4)
+ add $gp, $lp, $gp
+#else
+ mfusr $r15, $PC
+ sethi $gp, HI20(_GLOBAL_OFFSET_TABLE_+4)
+ ori $gp, $gp, LO12(_GLOBAL_OFFSET_TABLE_ + 8)
+ add $gp, $r15, $gp
+#endif
+
+ la $r3, _init@GOTOFF
+ la $r4, _fini@GOTOFF
+ la $r0, main@GOT
+
+ /* push everything to stack, r5 is rtld_fini and r7 is garbage */
+ pushm $r0, $r7
+
+ /* now start it up */
+ bal __uClibc_main@PLT
+
+ /* should never get here */
+ bal abort@PLT
+#else
+ la $gp, _SDA_BASE_ ! init GP for small data access
+
+ la $r3, _init
+ la $r4, _fini
+ la $r0, main
+
+ /* push everything to stack, r5 is rtld_fini and r7 is garbage */
+ pushm $r0, $r7
+
+ /* now start it up */
+ bal __uClibc_main
+
+ /* should never get here */
+ bal abort
+#endif
+ ret
+
+/* Define a symbol for the first piece of initialized data. */
+ .data
+ .globl __data_start
+__data_start:
+ .long 0
+ .weak data_start
+ data_start = __data_start