cstart_thumb2.asm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. ;; NOTE: To allow the use of this file for both ARMv6M and ARMv7M,
  2. ;; we will only use 16-bit Thumb intructions.
  3. .extern _lc_ub_stack ; usr/sys mode stack pointer
  4. .extern _lc_ue_stack ; symbol required by debugger
  5. .extern _lc_ub_table ; ROM to RAM copy table
  6. .extern main
  7. .extern _Exit
  8. .extern exit
  9. .weak exit
  10. .global __get_argcv
  11. .weak __get_argcv
  12. .extern __argcvbuf
  13. .weak __argcvbuf
  14. ;;.extern __init_hardware
  15. .extern SystemInit
  16. .if @defined('__PROF_ENABLE__')
  17. .extern __prof_init
  18. .endif
  19. .if @defined('__POSIX__')
  20. .extern posix_main
  21. .extern _posix_boot_stack_top
  22. .endif
  23. .global _START
  24. .section .text.cstart
  25. .thumb
  26. _START:
  27. ;; anticipate possible ROM/RAM remapping
  28. ;; by loading the 'real' program address
  29. ldr r1,=_Next
  30. bx r1
  31. _Next:
  32. ;; initialize the stack pointer
  33. ldr r1,=_lc_ub_stack ; TODO: make this part of the vector table
  34. mov sp,r1
  35. ; Call the clock system intitialization function.
  36. bl SystemInit
  37. ;; copy initialized sections from ROM to RAM
  38. ;; and clear uninitialized data sections in RAM
  39. ldr r3,=_lc_ub_table
  40. movs r0,#0
  41. cploop:
  42. ldr r4,[r3,#0] ; load type
  43. ldr r5,[r3,#4] ; dst address
  44. ldr r6,[r3,#8] ; src address
  45. ldr r7,[r3,#12] ; size
  46. cmp r4,#1
  47. beq copy
  48. cmp r4,#2
  49. beq clear
  50. b done
  51. copy:
  52. subs r7,r7,#1
  53. ldrb r1,[r6,r7]
  54. strb r1,[r5,r7]
  55. bne copy
  56. adds r3,r3,#16
  57. b cploop
  58. clear:
  59. subs r7,r7,#1
  60. strb r0,[r5,r7]
  61. bne clear
  62. adds r3,r3,#16
  63. b cploop
  64. done:
  65. .if @defined('__POSIX__')
  66. ;; posix stack buffer for system upbringing
  67. ldr r0,=_posix_boot_stack_top
  68. ldr r0, [r0]
  69. mov sp,r0
  70. .else
  71. ;; load r10 with end of USR/SYS stack, which is
  72. ;; needed in case stack overflow checking is on
  73. ;; NOTE: use 16-bit instructions only, for ARMv6M
  74. ldr r0,=_lc_ue_stack
  75. mov r10,r0
  76. .endif
  77. .if @defined('__PROF_ENABLE__')
  78. bl __prof_init
  79. .endif
  80. .if @defined('__POSIX__')
  81. ;; call posix_main with no arguments
  82. bl posix_main
  83. .else
  84. ;; retrieve argc and argv (default argv[0]==NULL & argc==0)
  85. bl __get_argcv
  86. ldr r1,=__argcvbuf
  87. ;; call main
  88. bl main
  89. .endif
  90. ;; call exit using the return value from main()
  91. ;; Note. Calling exit will also run all functions
  92. ;; that were supplied through atexit().
  93. bl exit
  94. __get_argcv: ; weak definition
  95. movs r0,#0
  96. bx lr
  97. .ltorg
  98. .endsec
  99. .calls '_START', ' '
  100. .calls '_START','__init_vector_table'
  101. .if @defined('__PROF_ENABLE__')
  102. .calls '_START','__prof_init'
  103. .endif
  104. .if @defined('__POSIX__')
  105. .calls '_START','posix_main'
  106. .else
  107. .calls '_START','__get_argcv'
  108. .calls '_START','main'
  109. .endif
  110. .calls '_START','exit'
  111. .calls '_START','',0
  112. .end