cstartup.s 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 ARMCMx/RVCT/cstartup.s
  15. * @brief Generic RVCT Cortex-Mx startup file.
  16. *
  17. * @addtogroup ARMCMx_RVCT_STARTUP
  18. * @{
  19. */
  20. #if !defined(__DOXYGEN__)
  21. ;/* <<< Use Configuration Wizard in Context Menu >>> */
  22. ;// <h> Main Stack Configuration (IRQ Stack)
  23. ;// <o> Main Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
  24. ;// </h>
  25. main_stack_size EQU 0x00000400
  26. ;// <h> Process Stack Configuration
  27. ;// <o> Process Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
  28. ;// </h>
  29. proc_stack_size EQU 0x00000400
  30. ;// <h> C-runtime heap size
  31. ;// <o> C-runtime heap size (in Bytes) <0x0-0xFFFFFFFF:8>
  32. ;// </h>
  33. heap_size EQU 0x00000400
  34. AREA MSTACK, NOINIT, READWRITE, ALIGN=3
  35. main_stack_mem SPACE main_stack_size
  36. EXPORT __initial_msp
  37. __initial_msp
  38. AREA CSTACK, NOINIT, READWRITE, ALIGN=3
  39. __main_thread_stack_base__
  40. EXPORT __main_thread_stack_base__
  41. proc_stack_mem SPACE proc_stack_size
  42. EXPORT __initial_sp
  43. __initial_sp
  44. AREA HEAP, NOINIT, READWRITE, ALIGN=3
  45. __heap_base
  46. Heap_Mem SPACE heap_size
  47. __heap_limit
  48. CONTROL_MODE_PRIVILEGED EQU 0
  49. CONTROL_MODE_UNPRIVILEGED EQU 1
  50. CONTROL_USE_MSP EQU 0
  51. CONTROL_USE_PSP EQU 2
  52. PRESERVE8
  53. THUMB
  54. AREA |.text|, CODE, READONLY
  55. /*
  56. * Reset handler.
  57. */
  58. IMPORT __main
  59. EXPORT Reset_Handler
  60. Reset_Handler PROC
  61. cpsid i
  62. ldr r0, =__initial_sp
  63. msr PSP, r0
  64. movs r0, #CONTROL_MODE_PRIVILEGED :OR: CONTROL_USE_PSP
  65. msr CONTROL, r0
  66. isb
  67. bl __early_init
  68. IF {CPU} = "Cortex-M4.fp"
  69. LDR R0, =0xE000ED88 ; Enable CP10,CP11
  70. LDR R1, [R0]
  71. ORR R1, R1, #(0xF << 20)
  72. STR R1, [R0]
  73. ENDIF
  74. ldr r0, =__main
  75. bx r0
  76. ENDP
  77. __early_init PROC
  78. EXPORT __early_init [WEAK]
  79. bx lr
  80. ENDP
  81. ALIGN
  82. /*
  83. * User Initial Stack & Heap.
  84. */
  85. IF :DEF:__MICROLIB
  86. EXPORT __initial_sp
  87. EXPORT __heap_base
  88. EXPORT __heap_limit
  89. ELSE
  90. IMPORT __use_two_region_memory
  91. EXPORT __user_initial_stackheap
  92. __user_initial_stackheap
  93. ldr r0, =Heap_Mem
  94. ldr r1, =(proc_stack_mem + proc_stack_size)
  95. ldr r2, =(Heap_Mem + heap_size)
  96. ldr r3, =proc_stack_mem
  97. bx lr
  98. ALIGN
  99. ENDIF
  100. END
  101. #endif /* !defined(__DOXYGEN__) */
  102. /**< @} */