crt0.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file crt0.S
  15. * @brief Generic ARM startup file.
  16. *
  17. * @addtogroup ARM_GCC_STARTUP
  18. * @{
  19. */
  20. #if !defined(__DOXYGEN__)
  21. .set MODE_USR, 0x10
  22. .set MODE_FIQ, 0x11
  23. .set MODE_IRQ, 0x12
  24. .set MODE_SVC, 0x13
  25. .set MODE_ABT, 0x17
  26. .set MODE_UND, 0x1B
  27. .set MODE_SYS, 0x1F
  28. .set I_BIT, 0x80
  29. .set F_BIT, 0x40
  30. .text
  31. .code 32
  32. .balign 4
  33. /*
  34. * Reset handler.
  35. */
  36. .global Reset_Handler
  37. Reset_Handler:
  38. /*
  39. * Stack pointers initialization.
  40. */
  41. ldr r0, =__stacks_end__
  42. /* Undefined */
  43. msr CPSR_c, #MODE_UND | I_BIT | F_BIT
  44. mov sp, r0
  45. ldr r1, =__und_stack_size__
  46. sub r0, r0, r1
  47. /* Abort */
  48. msr CPSR_c, #MODE_ABT | I_BIT | F_BIT
  49. mov sp, r0
  50. ldr r1, =__abt_stack_size__
  51. sub r0, r0, r1
  52. /* FIQ */
  53. msr CPSR_c, #MODE_FIQ | I_BIT | F_BIT
  54. mov sp, r0
  55. ldr r1, =__fiq_stack_size__
  56. sub r0, r0, r1
  57. /* IRQ */
  58. msr CPSR_c, #MODE_IRQ | I_BIT | F_BIT
  59. mov sp, r0
  60. ldr r1, =__irq_stack_size__
  61. sub r0, r0, r1
  62. /* Supervisor */
  63. msr CPSR_c, #MODE_SVC | I_BIT | F_BIT
  64. mov sp, r0
  65. ldr r1, =__svc_stack_size__
  66. sub r0, r0, r1
  67. /* System */
  68. msr CPSR_c, #MODE_SYS | I_BIT | F_BIT
  69. mov sp, r0
  70. // ldr r1, =__sys_stack_size__
  71. // sub r0, r0, r1
  72. /*
  73. * Early initialization.
  74. */
  75. bl __early_init
  76. /*
  77. * Data initialization.
  78. * NOTE: It assumes that the DATA size is a multiple of 4.
  79. */
  80. ldr r1, =_textdata
  81. ldr r2, =_data
  82. ldr r3, =_edata
  83. dataloop:
  84. cmp r2, r3
  85. ldrlo r0, [r1], #4
  86. strlo r0, [r2], #4
  87. blo dataloop
  88. /*
  89. * BSS initialization.
  90. * NOTE: It assumes that the BSS size is a multiple of 4.
  91. */
  92. mov r0, #0
  93. ldr r1, =_bss_start
  94. ldr r2, =_bss_end
  95. bssloop:
  96. cmp r1, r2
  97. strlo r0, [r1], #4
  98. blo bssloop
  99. /*
  100. * Late initialization.
  101. */
  102. bl __core_init
  103. bl __late_init
  104. /*
  105. * Main program invocation.
  106. */
  107. bl main
  108. b __default_exit
  109. #endif /* !defined(__DOXYGEN__) */
  110. /** @} */