1 /* The startup code sample of Andes NDS32 cpu for GNU compiler
2 Copyright (C) 2012-2024 Free Software Foundation, Inc.
3 Contributed by Andes Technology Corporation.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 3, or (at your
10 option) any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 !!==============================================================================
30 !! This is JUST A SAMPLE of nds32 startup code !!
31 !! You can refer this content and implement
32 !! the actual one in newlib/mculib.
34 !!==============================================================================
36 !!------------------------------------------------------------------------------
37 !! Jump to start up code
38 !!------------------------------------------------------------------------------
39 .section .nds32_init, "ax"
42 !!------------------------------------------------------------------------------
43 !! Startup code implementation
44 !!------------------------------------------------------------------------------
51 .type _start, @function
54 la $fp, _FP_BASE_ ! init $fp
55 la $gp, _SDA_BASE_ ! init $gp for small data access
56 movi $lp, 0 ! init $lp
59 la $sp, _stack ! init $sp
60 movi $r0, -8 ! align $sp to 8-byte (use 0xfffffff8)
61 and $sp, $sp, $r0 ! align $sp to 8-byte (filter out lower 3-bit)
64 ! clear BSS, this process can be 4 time faster if data is 4 byte aligned
65 ! if so, use swi.p instead of sbi.p
66 ! the related stuff are defined in linker script
67 la $r0, _edata ! get the starting addr of bss
68 la $r2, _end ! get ending addr of bss
69 beq $r0, $r2, .L_call_main ! if no bss just do nothing
70 movi $r1, 0 ! should be cleared to 0
72 sbi.p $r1, [$r0], 1 ! Set 0 to bss
73 bne $r0, $r2, .L_clear_bss ! Still bytes left to set
76 ! la $r0, _end ! init heap_end
77 ! s.w $r0, heap_end ! save it
81 ! ! argc/argv initialization if necessary; default implementation is in crt1.o
82 ! la $r9, _arg_init ! load address of _arg_init?
83 ! beqz $r9, .L4 ! has _arg_init? no, go check main()
84 ! addi $sp, $sp, -512 ! allocate space for command line + arguments
85 ! move $r6, $sp ! r6 = buffer addr of cmd line
86 ! move $r0, $r6 ! r0 = buffer addr of cmd line
87 ! syscall 6002 ! get cmd line
88 ! move $r0, $r6 ! r0 = buffer addr of cmd line
89 ! addi $r1, $r6, 256 ! r1 = argv
90 ! jral $r9 ! init argc/argv
91 ! addi $r1, $r6, 256 ! r1 = argv
94 ! call main() if main() is provided
95 la $r15, main ! load address of main
99 syscall 0x1 ! use syscall 0x1 to terminate program
100 .size _start, .-_start
103 !! ------------------------------------------------------------------------