gcc_startup_nrf9160.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /*
  2. Copyright (c) 2009-2018 ARM Limited. All rights reserved.
  3. SPDX-License-Identifier: Apache-2.0
  4. Licensed under the Apache License, Version 2.0 (the License); you may
  5. not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an AS IS BASIS, WITHOUT
  10. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. NOTICE: This file has been modified by Nordic Semiconductor ASA.
  14. */
  15. .syntax unified
  16. .arch armv8-m.main
  17. #ifdef __STARTUP_CONFIG
  18. #include "startup_config.h"
  19. #ifndef __STARTUP_CONFIG_STACK_ALIGNEMENT
  20. #define __STARTUP_CONFIG_STACK_ALIGNEMENT 3
  21. #endif
  22. #endif
  23. .section .stack
  24. #if defined(__STARTUP_CONFIG)
  25. .align __STARTUP_CONFIG_STACK_ALIGNEMENT
  26. .equ Stack_Size, __STARTUP_CONFIG_STACK_SIZE
  27. #elif defined(__STACK_SIZE)
  28. .align 3
  29. .equ Stack_Size, __STACK_SIZE
  30. #else
  31. .align 3
  32. .equ Stack_Size, 8192
  33. #endif
  34. .globl __StackTop
  35. .globl __StackLimit
  36. __StackLimit:
  37. .space Stack_Size
  38. .size __StackLimit, . - __StackLimit
  39. __StackTop:
  40. .size __StackTop, . - __StackTop
  41. .section .heap
  42. .align 3
  43. #if defined(__STARTUP_CONFIG)
  44. .equ Heap_Size, __STARTUP_CONFIG_HEAP_SIZE
  45. #elif defined(__HEAP_SIZE)
  46. .equ Heap_Size, __HEAP_SIZE
  47. #else
  48. .equ Heap_Size, 8192
  49. #endif
  50. .globl __HeapBase
  51. .globl __HeapLimit
  52. __HeapBase:
  53. .if Heap_Size
  54. .space Heap_Size
  55. .endif
  56. .size __HeapBase, . - __HeapBase
  57. __HeapLimit:
  58. .size __HeapLimit, . - __HeapLimit
  59. .section .isr_vector
  60. .align 2
  61. .globl __isr_vector
  62. __isr_vector:
  63. .long __StackTop /* Top of Stack */
  64. .long Reset_Handler
  65. .long NMI_Handler
  66. .long HardFault_Handler
  67. .long MemoryManagement_Handler
  68. .long BusFault_Handler
  69. .long UsageFault_Handler
  70. .long SecureFault_Handler
  71. .long 0 /*Reserved */
  72. .long 0 /*Reserved */
  73. .long 0 /*Reserved */
  74. .long SVC_Handler
  75. .long DebugMon_Handler
  76. .long 0 /*Reserved */
  77. .long PendSV_Handler
  78. .long SysTick_Handler
  79. /* External Interrupts */
  80. .long 0 /*Reserved */
  81. .long 0 /*Reserved */
  82. .long 0 /*Reserved */
  83. .long SPU_IRQHandler
  84. .long 0 /*Reserved */
  85. .long CLOCK_POWER_IRQHandler
  86. .long 0 /*Reserved */
  87. .long 0 /*Reserved */
  88. .long UARTE0_SPIM0_SPIS0_TWIM0_TWIS0_IRQHandler
  89. .long UARTE1_SPIM1_SPIS1_TWIM1_TWIS1_IRQHandler
  90. .long UARTE2_SPIM2_SPIS2_TWIM2_TWIS2_IRQHandler
  91. .long UARTE3_SPIM3_SPIS3_TWIM3_TWIS3_IRQHandler
  92. .long 0 /*Reserved */
  93. .long GPIOTE0_IRQHandler
  94. .long SAADC_IRQHandler
  95. .long TIMER0_IRQHandler
  96. .long TIMER1_IRQHandler
  97. .long TIMER2_IRQHandler
  98. .long 0 /*Reserved */
  99. .long 0 /*Reserved */
  100. .long RTC0_IRQHandler
  101. .long RTC1_IRQHandler
  102. .long 0 /*Reserved */
  103. .long 0 /*Reserved */
  104. .long WDT_IRQHandler
  105. .long 0 /*Reserved */
  106. .long 0 /*Reserved */
  107. .long EGU0_IRQHandler
  108. .long EGU1_IRQHandler
  109. .long EGU2_IRQHandler
  110. .long EGU3_IRQHandler
  111. .long EGU4_IRQHandler
  112. .long EGU5_IRQHandler
  113. .long PWM0_IRQHandler
  114. .long PWM1_IRQHandler
  115. .long PWM2_IRQHandler
  116. .long PWM3_IRQHandler
  117. .long 0 /*Reserved */
  118. .long PDM_IRQHandler
  119. .long 0 /*Reserved */
  120. .long I2S_IRQHandler
  121. .long 0 /*Reserved */
  122. .long IPC_IRQHandler
  123. .long 0 /*Reserved */
  124. .long FPU_IRQHandler
  125. .long 0 /*Reserved */
  126. .long 0 /*Reserved */
  127. .long 0 /*Reserved */
  128. .long 0 /*Reserved */
  129. .long GPIOTE1_IRQHandler
  130. .long 0 /*Reserved */
  131. .long 0 /*Reserved */
  132. .long 0 /*Reserved */
  133. .long 0 /*Reserved */
  134. .long 0 /*Reserved */
  135. .long 0 /*Reserved */
  136. .long 0 /*Reserved */
  137. .long KMU_IRQHandler
  138. .long 0 /*Reserved */
  139. .long 0 /*Reserved */
  140. .long 0 /*Reserved */
  141. .long 0 /*Reserved */
  142. .long 0 /*Reserved */
  143. .long 0 /*Reserved */
  144. .long CRYPTOCELL_IRQHandler
  145. .long 0 /*Reserved */
  146. .long 0 /*Reserved */
  147. .long 0 /*Reserved */
  148. .long 0 /*Reserved */
  149. .long 0 /*Reserved */
  150. .long 0 /*Reserved */
  151. .long 0 /*Reserved */
  152. .long 0 /*Reserved */
  153. .long 0 /*Reserved */
  154. .long 0 /*Reserved */
  155. .long 0 /*Reserved */
  156. .long 0 /*Reserved */
  157. .long 0 /*Reserved */
  158. .long 0 /*Reserved */
  159. .long 0 /*Reserved */
  160. .long 0 /*Reserved */
  161. .long 0 /*Reserved */
  162. .long 0 /*Reserved */
  163. .long 0 /*Reserved */
  164. .long 0 /*Reserved */
  165. .long 0 /*Reserved */
  166. .long 0 /*Reserved */
  167. .long 0 /*Reserved */
  168. .long 0 /*Reserved */
  169. .long 0 /*Reserved */
  170. .long 0 /*Reserved */
  171. .long 0 /*Reserved */
  172. .long 0 /*Reserved */
  173. .long 0 /*Reserved */
  174. .long 0 /*Reserved */
  175. .long 0 /*Reserved */
  176. .long 0 /*Reserved */
  177. .long 0 /*Reserved */
  178. .long 0 /*Reserved */
  179. .long 0 /*Reserved */
  180. .long 0 /*Reserved */
  181. .long 0 /*Reserved */
  182. .long 0 /*Reserved */
  183. .long 0 /*Reserved */
  184. .long 0 /*Reserved */
  185. .long 0 /*Reserved */
  186. .long 0 /*Reserved */
  187. .long 0 /*Reserved */
  188. .long 0 /*Reserved */
  189. .long 0 /*Reserved */
  190. .long 0 /*Reserved */
  191. .long 0 /*Reserved */
  192. .long 0 /*Reserved */
  193. .long 0 /*Reserved */
  194. .long 0 /*Reserved */
  195. .long 0 /*Reserved */
  196. .long 0 /*Reserved */
  197. .long 0 /*Reserved */
  198. .long 0 /*Reserved */
  199. .long 0 /*Reserved */
  200. .long 0 /*Reserved */
  201. .long 0 /*Reserved */
  202. .long 0 /*Reserved */
  203. .long 0 /*Reserved */
  204. .long 0 /*Reserved */
  205. .long 0 /*Reserved */
  206. .long 0 /*Reserved */
  207. .long 0 /*Reserved */
  208. .long 0 /*Reserved */
  209. .long 0 /*Reserved */
  210. .long 0 /*Reserved */
  211. .long 0 /*Reserved */
  212. .long 0 /*Reserved */
  213. .long 0 /*Reserved */
  214. .long 0 /*Reserved */
  215. .long 0 /*Reserved */
  216. .long 0 /*Reserved */
  217. .long 0 /*Reserved */
  218. .long 0 /*Reserved */
  219. .long 0 /*Reserved */
  220. .long 0 /*Reserved */
  221. .long 0 /*Reserved */
  222. .long 0 /*Reserved */
  223. .long 0 /*Reserved */
  224. .long 0 /*Reserved */
  225. .long 0 /*Reserved */
  226. .long 0 /*Reserved */
  227. .long 0 /*Reserved */
  228. .long 0 /*Reserved */
  229. .long 0 /*Reserved */
  230. .long 0 /*Reserved */
  231. .long 0 /*Reserved */
  232. .long 0 /*Reserved */
  233. .long 0 /*Reserved */
  234. .long 0 /*Reserved */
  235. .long 0 /*Reserved */
  236. .long 0 /*Reserved */
  237. .long 0 /*Reserved */
  238. .long 0 /*Reserved */
  239. .long 0 /*Reserved */
  240. .long 0 /*Reserved */
  241. .long 0 /*Reserved */
  242. .long 0 /*Reserved */
  243. .long 0 /*Reserved */
  244. .long 0 /*Reserved */
  245. .long 0 /*Reserved */
  246. .long 0 /*Reserved */
  247. .long 0 /*Reserved */
  248. .long 0 /*Reserved */
  249. .long 0 /*Reserved */
  250. .long 0 /*Reserved */
  251. .long 0 /*Reserved */
  252. .long 0 /*Reserved */
  253. .long 0 /*Reserved */
  254. .long 0 /*Reserved */
  255. .long 0 /*Reserved */
  256. .long 0 /*Reserved */
  257. .long 0 /*Reserved */
  258. .long 0 /*Reserved */
  259. .long 0 /*Reserved */
  260. .long 0 /*Reserved */
  261. .long 0 /*Reserved */
  262. .long 0 /*Reserved */
  263. .long 0 /*Reserved */
  264. .long 0 /*Reserved */
  265. .long 0 /*Reserved */
  266. .long 0 /*Reserved */
  267. .long 0 /*Reserved */
  268. .long 0 /*Reserved */
  269. .long 0 /*Reserved */
  270. .long 0 /*Reserved */
  271. .long 0 /*Reserved */
  272. .long 0 /*Reserved */
  273. .long 0 /*Reserved */
  274. .long 0 /*Reserved */
  275. .long 0 /*Reserved */
  276. .long 0 /*Reserved */
  277. .long 0 /*Reserved */
  278. .long 0 /*Reserved */
  279. .long 0 /*Reserved */
  280. .long 0 /*Reserved */
  281. .long 0 /*Reserved */
  282. .long 0 /*Reserved */
  283. .long 0 /*Reserved */
  284. .long 0 /*Reserved */
  285. .long 0 /*Reserved */
  286. .long 0 /*Reserved */
  287. .long 0 /*Reserved */
  288. .long 0 /*Reserved */
  289. .long 0 /*Reserved */
  290. .long 0 /*Reserved */
  291. .long 0 /*Reserved */
  292. .long 0 /*Reserved */
  293. .long 0 /*Reserved */
  294. .long 0 /*Reserved */
  295. .long 0 /*Reserved */
  296. .long 0 /*Reserved */
  297. .long 0 /*Reserved */
  298. .long 0 /*Reserved */
  299. .long 0 /*Reserved */
  300. .long 0 /*Reserved */
  301. .long 0 /*Reserved */
  302. .long 0 /*Reserved */
  303. .long 0 /*Reserved */
  304. .long 0 /*Reserved */
  305. .long 0 /*Reserved */
  306. .long 0 /*Reserved */
  307. .long 0 /*Reserved */
  308. .long 0 /*Reserved */
  309. .long 0 /*Reserved */
  310. .long 0 /*Reserved */
  311. .long 0 /*Reserved */
  312. .long 0 /*Reserved */
  313. .long 0 /*Reserved */
  314. .long 0 /*Reserved */
  315. .long 0 /*Reserved */
  316. .long 0 /*Reserved */
  317. .long 0 /*Reserved */
  318. .long 0 /*Reserved */
  319. .long 0 /*Reserved */
  320. .size __isr_vector, . - __isr_vector
  321. /* Reset Handler */
  322. .text
  323. .thumb
  324. .thumb_func
  325. .align 1
  326. .globl Reset_Handler
  327. .type Reset_Handler, %function
  328. Reset_Handler:
  329. /* Loop to copy data from read only memory to RAM.
  330. * The ranges of copy from/to are specified by following symbols:
  331. * __etext: LMA of start of the section to copy from. Usually end of text
  332. * __data_start__: VMA of start of the section to copy to.
  333. * __bss_start__: VMA of end of the section to copy to. Normally __data_end__ is used, but by using __bss_start__
  334. * the user can add their own initialized data section before BSS section with the INTERT AFTER command.
  335. *
  336. * All addresses must be aligned to 4 bytes boundary.
  337. */
  338. ldr r1, =__etext
  339. ldr r2, =__data_start__
  340. ldr r3, =__bss_start__
  341. subs r3, r3, r2
  342. ble .L_loop1_done
  343. .L_loop1:
  344. subs r3, r3, #4
  345. ldr r0, [r1,r3]
  346. str r0, [r2,r3]
  347. bgt .L_loop1
  348. .L_loop1_done:
  349. /* This part of work usually is done in C library startup code. Otherwise,
  350. * define __STARTUP_CLEAR_BSS to enable it in this startup. This section
  351. * clears the RAM where BSS data is located.
  352. *
  353. * The BSS section is specified by following symbols
  354. * __bss_start__: start of the BSS section.
  355. * __bss_end__: end of the BSS section.
  356. *
  357. * All addresses must be aligned to 4 bytes boundary.
  358. */
  359. #ifdef __STARTUP_CLEAR_BSS
  360. ldr r1, =__bss_start__
  361. ldr r2, =__bss_end__
  362. movs r0, 0
  363. subs r2, r2, r1
  364. ble .L_loop3_done
  365. .L_loop3:
  366. subs r2, r2, #4
  367. str r0, [r1, r2]
  368. bgt .L_loop3
  369. .L_loop3_done:
  370. #endif /* __STARTUP_CLEAR_BSS */
  371. /* Execute SystemInit function. */
  372. bl SystemInit
  373. /* Call _start function provided by libraries.
  374. * If those libraries are not accessible, define __START as your entry point.
  375. */
  376. #ifndef __START
  377. #define __START _start
  378. #endif
  379. bl __START
  380. .pool
  381. .size Reset_Handler,.-Reset_Handler
  382. .section ".text"
  383. /* Dummy Exception Handlers (infinite loops which can be modified) */
  384. .weak NMI_Handler
  385. .type NMI_Handler, %function
  386. NMI_Handler:
  387. b .
  388. .size NMI_Handler, . - NMI_Handler
  389. .weak HardFault_Handler
  390. .type HardFault_Handler, %function
  391. HardFault_Handler:
  392. b .
  393. .size HardFault_Handler, . - HardFault_Handler
  394. .weak MemoryManagement_Handler
  395. .type MemoryManagement_Handler, %function
  396. MemoryManagement_Handler:
  397. b .
  398. .size MemoryManagement_Handler, . - MemoryManagement_Handler
  399. .weak BusFault_Handler
  400. .type BusFault_Handler, %function
  401. BusFault_Handler:
  402. b .
  403. .size BusFault_Handler, . - BusFault_Handler
  404. .weak UsageFault_Handler
  405. .type UsageFault_Handler, %function
  406. UsageFault_Handler:
  407. b .
  408. .size UsageFault_Handler, . - UsageFault_Handler
  409. .weak SecureFault_Handler
  410. .type SecureFault_Handler, %function
  411. SecureFault_Handler:
  412. b .
  413. .size SecureFault_Handler, . - SecureFault_Handler
  414. .weak SVC_Handler
  415. .type SVC_Handler, %function
  416. SVC_Handler:
  417. b .
  418. .size SVC_Handler, . - SVC_Handler
  419. .weak DebugMon_Handler
  420. .type DebugMon_Handler, %function
  421. DebugMon_Handler:
  422. b .
  423. .size DebugMon_Handler, . - DebugMon_Handler
  424. .weak PendSV_Handler
  425. .type PendSV_Handler, %function
  426. PendSV_Handler:
  427. b .
  428. .size PendSV_Handler, . - PendSV_Handler
  429. .weak SysTick_Handler
  430. .type SysTick_Handler, %function
  431. SysTick_Handler:
  432. b .
  433. .size SysTick_Handler, . - SysTick_Handler
  434. /* IRQ Handlers */
  435. .globl Default_Handler
  436. .type Default_Handler, %function
  437. Default_Handler:
  438. b .
  439. .size Default_Handler, . - Default_Handler
  440. .macro IRQ handler
  441. .weak \handler
  442. .set \handler, Default_Handler
  443. .endm
  444. IRQ SPU_IRQHandler
  445. IRQ CLOCK_POWER_IRQHandler
  446. IRQ UARTE0_SPIM0_SPIS0_TWIM0_TWIS0_IRQHandler
  447. IRQ UARTE1_SPIM1_SPIS1_TWIM1_TWIS1_IRQHandler
  448. IRQ UARTE2_SPIM2_SPIS2_TWIM2_TWIS2_IRQHandler
  449. IRQ UARTE3_SPIM3_SPIS3_TWIM3_TWIS3_IRQHandler
  450. IRQ GPIOTE0_IRQHandler
  451. IRQ SAADC_IRQHandler
  452. IRQ TIMER0_IRQHandler
  453. IRQ TIMER1_IRQHandler
  454. IRQ TIMER2_IRQHandler
  455. IRQ RTC0_IRQHandler
  456. IRQ RTC1_IRQHandler
  457. IRQ WDT_IRQHandler
  458. IRQ EGU0_IRQHandler
  459. IRQ EGU1_IRQHandler
  460. IRQ EGU2_IRQHandler
  461. IRQ EGU3_IRQHandler
  462. IRQ EGU4_IRQHandler
  463. IRQ EGU5_IRQHandler
  464. IRQ PWM0_IRQHandler
  465. IRQ PWM1_IRQHandler
  466. IRQ PWM2_IRQHandler
  467. IRQ PWM3_IRQHandler
  468. IRQ PDM_IRQHandler
  469. IRQ I2S_IRQHandler
  470. IRQ IPC_IRQHandler
  471. IRQ FPU_IRQHandler
  472. IRQ GPIOTE1_IRQHandler
  473. IRQ KMU_IRQHandler
  474. IRQ CRYPTOCELL_IRQHandler
  475. .end