startup_keil.s 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. ;******************************************************************************
  2. ;
  3. ;! @file startup_keil.s
  4. ;!
  5. ;! @brief Definitions for Apollo2 interrupt handlers, the vector table, and the stack.
  6. ;
  7. ;******************************************************************************
  8. ;******************************************************************************
  9. ;
  10. ; Copyright (c) 2017, Ambiq Micro
  11. ; All rights reserved.
  12. ;
  13. ; Redistribution and use in source and binary forms, with or without
  14. ; modification, are permitted provided that the following conditions are met:
  15. ;
  16. ; 1. Redistributions of source code must retain the above copyright notice,
  17. ; this list of conditions and the following disclaimer.
  18. ;
  19. ; 2. Redistributions in binary form must reproduce the above copyright
  20. ; notice, this list of conditions and the following disclaimer in the
  21. ; documentation and/or other materials provided with the distribution.
  22. ;
  23. ; 3. Neither the name of the copyright holder nor the names of its
  24. ; contributors may be used to endorse or promote products derived from this
  25. ; software without specific prior written permission.
  26. ;
  27. ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. ; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. ; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. ; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  31. ; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. ; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. ; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. ; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  35. ; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. ; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. ; POSSIBILITY OF SUCH DAMAGE.
  38. ;
  39. ; This is part of revision 1.2.9 of the AmbiqSuite Development Package.
  40. ;
  41. ;******************************************************************************
  42. ;******************************************************************************
  43. ;
  44. ; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
  45. ;************************************************************************
  46. Stack EQU 0x00001000
  47. ;******************************************************************************
  48. ;
  49. ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
  50. ;
  51. ;******************************************************************************
  52. Heap EQU 0x00000000
  53. ;******************************************************************************
  54. ;
  55. ; Allocate space for the stack.
  56. ;
  57. ;******************************************************************************
  58. AREA STACK, NOINIT, READWRITE, ALIGN=3
  59. StackMem
  60. SPACE Stack
  61. __initial_sp
  62. ;******************************************************************************
  63. ;
  64. ; Allocate space for the heap.
  65. ;
  66. ;******************************************************************************
  67. AREA HEAP, NOINIT, READWRITE, ALIGN=3
  68. __heap_base
  69. HeapMem
  70. SPACE Heap
  71. __heap_limit
  72. ;******************************************************************************
  73. ;
  74. ; Indicate that the code in this file preserves 8-byte alignment of the stack.
  75. ;
  76. ;******************************************************************************
  77. PRESERVE8
  78. ;******************************************************************************
  79. ;
  80. ; Place code into the reset code section.
  81. ;
  82. ;******************************************************************************
  83. AREA RESET, CODE, READONLY
  84. THUMB
  85. ;******************************************************************************
  86. ;
  87. ; The vector table.
  88. ;
  89. ;******************************************************************************
  90. ;
  91. ; Note: Aliasing and weakly exporting am_mpufault_isr, am_busfault_isr, and
  92. ; am_usagefault_isr does not work if am_fault_isr is defined externally.
  93. ; Therefore, we'll explicitly use am_fault_isr in the table for those vectors.
  94. ;
  95. EXPORT __Vectors
  96. __Vectors
  97. DCD StackMem + Stack ; Top of Stack
  98. DCD Reset_Handler ; Reset Handler
  99. DCD NMI_Handler ; NMI Handler
  100. DCD HardFault_Handler ; Hard Fault Handler
  101. DCD MemoryManagement_Handler ; The MPU fault handler
  102. DCD BusFault_Handler ; The bus fault handler
  103. DCD UsageFault_Handler ; The usage fault handler
  104. DCD 0 ; Reserved
  105. DCD 0 ; Reserved
  106. DCD 0 ; Reserved
  107. DCD 0 ; Reserved
  108. DCD SVC_Handler ; SVCall handler
  109. DCD DebugMon_Handler ; Debug monitor handler
  110. DCD 0 ; Reserved
  111. DCD PendSV_Handler ; The PendSV handler
  112. DCD SysTick_Handler ; The SysTick handler
  113. ; Peripheral Interrupts
  114. DCD am_brownout_isr ; 0: Reserved
  115. DCD am_watchdog_isr ; 1: Reserved
  116. DCD am_clkgen_isr ; 2: CLKGEN
  117. DCD am_vcomp_isr ; 3: Voltage Comparator
  118. DCD am_ioslave_ios_isr ; 4: I/O Slave general
  119. DCD am_ioslave_acc_isr ; 5: I/O Slave access
  120. DCD am_iomaster0_isr ; 6: I/O Master 0
  121. DCD am_iomaster1_isr ; 7: I/O Master 1
  122. DCD am_iomaster2_isr ; 8: I/O Master 2
  123. DCD am_iomaster3_isr ; 9: I/O Master 3
  124. DCD am_iomaster4_isr ; 10: I/O Master 4
  125. DCD am_iomaster5_isr ; 11: I/O Master 5
  126. DCD am_gpio_isr ; 12: GPIO
  127. DCD am_ctimer_isr ; 13: CTIMER
  128. DCD am_uart0_isr ; 14: UART0
  129. DCD am_uart1_isr ; 15: UART1
  130. DCD am_adc_isr ; 16: ADC
  131. DCD am_pdm_isr ; 17: PDM
  132. DCD am_stimer_isr ; 18: SYSTEM TIMER
  133. DCD am_stimer_cmpr0_isr ; 19: SYSTEM TIMER COMPARE0
  134. DCD am_stimer_cmpr1_isr ; 20: SYSTEM TIMER COMPARE1
  135. DCD am_stimer_cmpr2_isr ; 21: SYSTEM TIMER COMPARE2
  136. DCD am_stimer_cmpr3_isr ; 22: SYSTEM TIMER COMPARE3
  137. DCD am_stimer_cmpr4_isr ; 23: SYSTEM TIMER COMPARE4
  138. DCD am_stimer_cmpr5_isr ; 24: SYSTEM TIMER COMPARE5
  139. DCD am_stimer_cmpr6_isr ; 25: SYSTEM TIMER COMPARE6
  140. DCD am_stimer_cmpr7_isr ; 26: SYSTEM TIMER COMPARE7
  141. DCD am_flash_isr ; 27: FLASH
  142. DCD am_software0_isr ; 28: SOFTWARE0
  143. DCD am_software1_isr ; 29: SOFTWARE1
  144. DCD am_software2_isr ; 30: SOFTWARE2
  145. DCD am_software3_isr ; 31: SOFTWARE3
  146. __Vectors_End
  147. __Vectors_Size EQU __Vectors_End - __Vectors
  148. ;******************************************************************************
  149. ;
  150. ; This is the code that gets called when the processor first starts execution
  151. ; following a reset event.
  152. ;
  153. ;******************************************************************************
  154. Reset_Handler PROC
  155. EXPORT Reset_Handler [WEAK]
  156. IMPORT __main
  157. ; Enable the FPU.
  158. MOVW R0, #0xED88
  159. MOVT R0, #0xE000
  160. LDR R1, [R0]
  161. ORR R1, #0x00F00000
  162. STR R1, [R0]
  163. DSB
  164. ISB
  165. ; Branch to main.
  166. LDR R0, =__main
  167. BX R0
  168. ENDP
  169. ;******************************************************************************
  170. ;
  171. ; Weak Exception Handlers.
  172. ;
  173. ;******************************************************************************
  174. NMI_Handler PROC
  175. EXPORT NMI_Handler [WEAK]
  176. B .
  177. ENDP
  178. HardFault_Handler\
  179. PROC
  180. EXPORT HardFault_Handler [WEAK]
  181. B .
  182. ENDP
  183. MemoryManagement_Handler\
  184. PROC
  185. EXPORT MemoryManagement_Handler [WEAK]
  186. B .
  187. ENDP
  188. BusFault_Handler\
  189. PROC
  190. EXPORT BusFault_Handler [WEAK]
  191. B .
  192. ENDP
  193. UsageFault_Handler\
  194. PROC
  195. EXPORT UsageFault_Handler [WEAK]
  196. B .
  197. ENDP
  198. SVC_Handler PROC
  199. EXPORT SVC_Handler [WEAK]
  200. B .
  201. ENDP
  202. DebugMon_Handler\
  203. PROC
  204. EXPORT DebugMon_Handler [WEAK]
  205. B .
  206. ENDP
  207. PendSV_Handler PROC
  208. EXPORT PendSV_Handler [WEAK]
  209. B .
  210. ENDP
  211. SysTick_Handler PROC
  212. EXPORT SysTick_Handler [WEAK]
  213. B .
  214. ENDP
  215. am_default_isr PROC
  216. EXPORT am_brownout_isr [WEAK]
  217. EXPORT am_watchdog_isr [WEAK]
  218. EXPORT am_clkgen_isr [WEAK]
  219. EXPORT am_vcomp_isr [WEAK]
  220. EXPORT am_ioslave_ios_isr [WEAK]
  221. EXPORT am_ioslave_acc_isr [WEAK]
  222. EXPORT am_iomaster0_isr [WEAK]
  223. EXPORT am_iomaster1_isr [WEAK]
  224. EXPORT am_iomaster2_isr [WEAK]
  225. EXPORT am_iomaster3_isr [WEAK]
  226. EXPORT am_iomaster4_isr [WEAK]
  227. EXPORT am_iomaster5_isr [WEAK]
  228. EXPORT am_gpio_isr [WEAK]
  229. EXPORT am_ctimer_isr [WEAK]
  230. EXPORT am_uart0_isr [WEAK]
  231. EXPORT am_uart1_isr [WEAK]
  232. EXPORT am_adc_isr [WEAK]
  233. EXPORT am_pdm_isr [WEAK]
  234. EXPORT am_stimer_isr [WEAK]
  235. EXPORT am_stimer_cmpr0_isr [WEAK]
  236. EXPORT am_stimer_cmpr1_isr [WEAK]
  237. EXPORT am_stimer_cmpr2_isr [WEAK]
  238. EXPORT am_stimer_cmpr3_isr [WEAK]
  239. EXPORT am_stimer_cmpr4_isr [WEAK]
  240. EXPORT am_stimer_cmpr5_isr [WEAK]
  241. EXPORT am_stimer_cmpr6_isr [WEAK]
  242. EXPORT am_stimer_cmpr7_isr [WEAK]
  243. EXPORT am_flash_isr [WEAK]
  244. EXPORT am_software0_isr [WEAK]
  245. EXPORT am_software1_isr [WEAK]
  246. EXPORT am_software2_isr [WEAK]
  247. EXPORT am_software3_isr [WEAK]
  248. am_brownout_isr
  249. am_watchdog_isr
  250. am_clkgen_isr
  251. am_vcomp_isr
  252. am_ioslave_ios_isr
  253. am_ioslave_acc_isr
  254. am_iomaster0_isr
  255. am_iomaster1_isr
  256. am_iomaster2_isr
  257. am_iomaster3_isr
  258. am_iomaster4_isr
  259. am_iomaster5_isr
  260. am_gpio_isr
  261. am_ctimer_isr
  262. am_uart0_isr
  263. am_uart1_isr
  264. am_adc_isr
  265. am_pdm_isr
  266. am_stimer_isr
  267. am_stimer_cmpr0_isr
  268. am_stimer_cmpr1_isr
  269. am_stimer_cmpr2_isr
  270. am_stimer_cmpr3_isr
  271. am_stimer_cmpr4_isr
  272. am_stimer_cmpr5_isr
  273. am_stimer_cmpr6_isr
  274. am_stimer_cmpr7_isr
  275. am_flash_isr
  276. am_software0_isr
  277. am_software1_isr
  278. am_software2_isr
  279. am_software3_isr
  280. ; all device interrupts go here unless the weak label is over
  281. ; ridden in the linker hard spin so the debugger will know it
  282. ; was an unhandled interrupt request a come-from-buffer or
  283. ; instruction trace hardware would sure be nice if you get here
  284. B .
  285. ENDP
  286. ;******************************************************************************
  287. ;
  288. ; Align the end of the section.
  289. ;
  290. ;******************************************************************************
  291. ALIGN
  292. ;******************************************************************************
  293. ;
  294. ; Initialization of the heap and stack.
  295. ;
  296. ;******************************************************************************
  297. AREA |.text|, CODE, READONLY
  298. ;******************************************************************************
  299. ;
  300. ; User Initial Stack & Heap.
  301. ;
  302. ;******************************************************************************
  303. IF :DEF: __MICROLIB
  304. EXPORT __initial_sp
  305. EXPORT __heap_base
  306. EXPORT __heap_limit
  307. ELSE
  308. IMPORT __use_two_region_memory
  309. EXPORT __user_initial_stackheap
  310. __user_initial_stackheap PROC
  311. LDR R0, =HeapMem
  312. LDR R1, =(StackMem + Stack)
  313. LDR R2, =(HeapMem + Heap)
  314. LDR R3, =StackMem
  315. BX LR
  316. ENDP
  317. ENDIF
  318. ;******************************************************************************
  319. ;
  320. ; Align the end of the section.
  321. ;
  322. ;******************************************************************************
  323. ALIGN
  324. ;******************************************************************************
  325. ;
  326. ; All Done
  327. ;
  328. ;******************************************************************************
  329. END