crtzero.S 3.6 KB

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