1/* ------------------------------------------------------------------------- */
2/*  @file:    startup_LPC824.s                                               */
3/*  @purpose: CMSIS Cortex-M0P Core Device Startup File                      */
4/*            LPC824                                                         */
5/*  @version: 1.1                                                            */
6/*  @date:    2018-2-25                                                      */
7/*  @build:   b231018                                                        */
8/* ------------------------------------------------------------------------- */
9/*                                                                           */
10/* Copyright 1997-2016 Freescale Semiconductor, Inc.                         */
11/* Copyright 2016-2023 NXP                                                   */
12/* SPDX-License-Identifier: BSD-3-Clause                                     */
13/*****************************************************************************/
14/* Version: GCC for ARM Embedded Processors                                  */
15/*****************************************************************************/
16    .syntax unified
17    .arch armv6-m
18
19    .section .isr_vector, "a"
20    .align 2
21    .globl __Vectors
22__Vectors:
23    .long   __StackTop                                      /* Top of Stack */
24    .long   Reset_Handler                                   /* Reset Handler */
25    .long   NMI_Handler                                     /* NMI Handler*/
26    .long   HardFault_Handler                               /* Hard Fault Handler*/
27    .long   0                                               /* Reserved*/
28    .long   0                                               /* Reserved*/
29    .long   0                                               /* Reserved*/
30    .long   0                                               /* Reserved*/
31    .long   0                                               /* Reserved*/
32    .long   0                                               /* Reserved*/
33    .long   0                                               /* Reserved*/
34    .long   SVC_Handler                                     /* SVCall Handler*/
35    .long   0                                               /* Reserved*/
36    .long   0                                               /* Reserved*/
37    .long   PendSV_Handler                                  /* PendSV Handler*/
38    .long   SysTick_Handler                                 /* SysTick Handler*/
39
40                                                            /* External Interrupts*/
41    .long   SPI0_IRQHandler                                 /* SPI0 interrupt*/
42    .long   SPI1_IRQHandler                                 /* SPI1 interrupt*/
43    .long   Reserved18_IRQHandler                           /* Reserved interrupt*/
44    .long   USART0_IRQHandler                               /* USART0 interrupt*/
45    .long   USART1_IRQHandler                               /* USART1 interrupt*/
46    .long   USART2_IRQHandler                               /* USART2 interrupt*/
47    .long   Reserved22_IRQHandler                           /* Reserved interrupt*/
48    .long   I2C1_IRQHandler                                 /* I2C1 interrupt*/
49    .long   I2C0_IRQHandler                                 /* I2C0 interrupt*/
50    .long   SCT0_IRQHandler                                 /* State configurable timer interrupt*/
51    .long   MRT0_IRQHandler                                 /* Multi-rate timer interrupt*/
52    .long   CMP_IRQHandler                                  /* Analog comparator interrupt*/
53    .long   WDT_IRQHandler                                  /* Windowed watchdog timer interrupt*/
54    .long   BOD_IRQHandler                                  /* BOD interrupts*/
55    .long   FLASH_IRQHandler                                /* flash interrupt*/
56    .long   WKT_IRQHandler                                  /* Self-wake-up timer interrupt*/
57    .long   ADC0_SEQA_IRQHandler                            /* ADC0 sequence A completion.*/
58    .long   ADC0_SEQB_IRQHandler                            /* ADC0 sequence B completion.*/
59    .long   ADC0_THCMP_IRQHandler                           /* ADC0 threshold compare and error.*/
60    .long   ADC0_OVR_IRQHandler                             /* ADC0 overrun*/
61    .long   DMA0_IRQHandler                                 /* DMA0 interrupt*/
62    .long   I2C2_IRQHandler                                 /* I2C2 interrupt*/
63    .long   I2C3_IRQHandler                                 /* I2C3 interrupt*/
64    .long   Reserved39_IRQHandler                           /* Reserved interrupt*/
65    .long   PIN_INT0_IRQHandler                             /* Pin interrupt 0 or pattern match engine slice 0 interrupt*/
66    .long   PIN_INT1_IRQHandler                             /* Pin interrupt 1 or pattern match engine slice 1 interrupt*/
67    .long   PIN_INT2_IRQHandler                             /* Pin interrupt 2 or pattern match engine slice 2 interrupt*/
68    .long   PIN_INT3_IRQHandler                             /* Pin interrupt 3 or pattern match engine slice 3 interrupt*/
69    .long   PIN_INT4_IRQHandler                             /* Pin interrupt 4 or pattern match engine slice 4 interrupt*/
70    .long   PIN_INT5_IRQHandler                             /* Pin interrupt 5 or pattern match engine slice 5 interrupt*/
71    .long   PIN_INT6_IRQHandler                             /* Pin interrupt 6 or pattern match engine slice 6 interrupt*/
72    .long   PIN_INT7_IRQHandler                             /* Pin interrupt 7 or pattern match engine slice 7 interrupt*/
73
74    .size   __Vectors, . - __Vectors
75
76/*  Variable to store CRP value in. No code read protection enabled by default
77 *  Code Read Protection level (CRP)
78 *    CRP_Level:
79 *      <0xFFFFFFFF=> Disabled
80 *      <0x4E697370=> NO_ISP
81 *      <0x12345678=> CRP1
82 *      <0x87654321=> CRP2
83 *      <0x43218765=> CRP3
84 */
85    #ifndef NO_CRP
86      .section .crp, "a"
87      .long 0xFFFFFFFF
88    #endif
89
90    .text
91    .thumb
92
93#if defined (__cplusplus)
94#ifdef __REDLIB__
95#error Redlib does not support C++
96#endif
97#endif
98/* Reset Handler */
99
100    .thumb_func
101    .align 2
102    .globl   Reset_Handler
103    .weak    Reset_Handler
104    .type    Reset_Handler, %function
105Reset_Handler:
106    cpsid   i               /* Mask interrupts */
107#ifndef __NO_SYSTEM_INIT
108    ldr   r0,=SystemInit
109    blx   r0
110#endif
111/*     Loop to copy data from read only memory to RAM. The ranges
112 *      of copy from/to are specified by following symbols evaluated in
113 *      linker script.
114 *      __etext: End of code section, i.e., begin of data sections to copy from.
115 *      __data_start__/__data_end__: RAM address range that data should be
116 *      copied to. Both must be aligned to 4 bytes boundary.  */
117
118    ldr    r1, =__etext
119    ldr    r2, =__data_start__
120    ldr    r3, =__data_end__
121
122    subs    r3, r2
123    ble     .LC0
124
125.LC1:
126    subs    r3, 4
127    ldr    r0, [r1,r3]
128    str    r0, [r2,r3]
129    bgt    .LC1
130.LC0:
131
132#ifdef __STARTUP_CLEAR_BSS
133/*     This part of work usually is done in C library startup code. Otherwise,
134 *     define this macro to enable it in this startup.
135 *
136 *     Loop to zero out BSS section, which uses following symbols
137 *     in linker script:
138 *      __bss_start__: start of BSS section. Must align to 4
139 *      __bss_end__: end of BSS section. Must align to 4
140 */
141    ldr r1, =__bss_start__
142    ldr r2, =__bss_end__
143
144    subs    r2, r1
145    ble .LC3
146
147    movs    r0, 0
148.LC2:
149    subs    r2, 4
150    str r0, [r1, r2]
151    bgt .LC2
152.LC3:
153#endif
154    cpsie   i               /* Unmask interrupts */
155#ifndef __START
156#ifdef __REDLIB__
157#define __START __main
158#else
159#define __START _start
160#endif
161#endif
162#ifndef __ATOLLIC__
163    ldr   r0,=__START
164    blx   r0
165#else
166    ldr   r0,=__libc_init_array
167    blx   r0
168    ldr   r0,=main
169    bx    r0
170#endif
171    .pool
172    .size Reset_Handler, . - Reset_Handler
173
174    .align  1
175    .thumb_func
176    .weak DefaultISR
177    .type DefaultISR, %function
178DefaultISR:
179    ldr r0, =DefaultISR
180    bx r0
181    .size DefaultISR, . - DefaultISR
182
183    .align 1
184    .thumb_func
185    .weak NMI_Handler
186    .type NMI_Handler, %function
187NMI_Handler:
188    ldr   r0,=NMI_Handler
189    bx    r0
190    .size NMI_Handler, . - NMI_Handler
191
192    .align 1
193    .thumb_func
194    .weak HardFault_Handler
195    .type HardFault_Handler, %function
196HardFault_Handler:
197    ldr   r0,=HardFault_Handler
198    bx    r0
199    .size HardFault_Handler, . - HardFault_Handler
200
201    .align 1
202    .thumb_func
203    .weak SVC_Handler
204    .type SVC_Handler, %function
205SVC_Handler:
206    ldr   r0,=SVC_Handler
207    bx    r0
208    .size SVC_Handler, . - SVC_Handler
209
210    .align 1
211    .thumb_func
212    .weak PendSV_Handler
213    .type PendSV_Handler, %function
214PendSV_Handler:
215    ldr   r0,=PendSV_Handler
216    bx    r0
217    .size PendSV_Handler, . - PendSV_Handler
218
219    .align 1
220    .thumb_func
221    .weak SysTick_Handler
222    .type SysTick_Handler, %function
223SysTick_Handler:
224    ldr   r0,=SysTick_Handler
225    bx    r0
226    .size SysTick_Handler, . - SysTick_Handler
227
228    .align 1
229    .thumb_func
230    .weak SPI0_IRQHandler
231    .type SPI0_IRQHandler, %function
232SPI0_IRQHandler:
233    ldr   r0,=SPI0_DriverIRQHandler
234    bx    r0
235    .size SPI0_IRQHandler, . - SPI0_IRQHandler
236
237    .align 1
238    .thumb_func
239    .weak SPI1_IRQHandler
240    .type SPI1_IRQHandler, %function
241SPI1_IRQHandler:
242    ldr   r0,=SPI1_DriverIRQHandler
243    bx    r0
244    .size SPI1_IRQHandler, . - SPI1_IRQHandler
245
246    .align 1
247    .thumb_func
248    .weak Reserved18_IRQHandler
249    .type Reserved18_IRQHandler, %function
250Reserved18_IRQHandler:
251    ldr   r0,=Reserved18_DriverIRQHandler
252    bx    r0
253    .size Reserved18_IRQHandler, . - Reserved18_IRQHandler
254
255    .align 1
256    .thumb_func
257    .weak USART0_IRQHandler
258    .type USART0_IRQHandler, %function
259USART0_IRQHandler:
260    ldr   r0,=USART0_DriverIRQHandler
261    bx    r0
262    .size USART0_IRQHandler, . - USART0_IRQHandler
263
264    .align 1
265    .thumb_func
266    .weak USART1_IRQHandler
267    .type USART1_IRQHandler, %function
268USART1_IRQHandler:
269    ldr   r0,=USART1_DriverIRQHandler
270    bx    r0
271    .size USART1_IRQHandler, . - USART1_IRQHandler
272
273    .align 1
274    .thumb_func
275    .weak USART2_IRQHandler
276    .type USART2_IRQHandler, %function
277USART2_IRQHandler:
278    ldr   r0,=USART2_DriverIRQHandler
279    bx    r0
280    .size USART2_IRQHandler, . - USART2_IRQHandler
281
282    .align 1
283    .thumb_func
284    .weak Reserved22_IRQHandler
285    .type Reserved22_IRQHandler, %function
286Reserved22_IRQHandler:
287    ldr   r0,=Reserved22_DriverIRQHandler
288    bx    r0
289    .size Reserved22_IRQHandler, . - Reserved22_IRQHandler
290
291    .align 1
292    .thumb_func
293    .weak I2C1_IRQHandler
294    .type I2C1_IRQHandler, %function
295I2C1_IRQHandler:
296    ldr   r0,=I2C1_DriverIRQHandler
297    bx    r0
298    .size I2C1_IRQHandler, . - I2C1_IRQHandler
299
300    .align 1
301    .thumb_func
302    .weak I2C0_IRQHandler
303    .type I2C0_IRQHandler, %function
304I2C0_IRQHandler:
305    ldr   r0,=I2C0_DriverIRQHandler
306    bx    r0
307    .size I2C0_IRQHandler, . - I2C0_IRQHandler
308
309    .align 1
310    .thumb_func
311    .weak SCT0_IRQHandler
312    .type SCT0_IRQHandler, %function
313SCT0_IRQHandler:
314    ldr   r0,=SCT0_DriverIRQHandler
315    bx    r0
316    .size SCT0_IRQHandler, . - SCT0_IRQHandler
317
318    .align 1
319    .thumb_func
320    .weak MRT0_IRQHandler
321    .type MRT0_IRQHandler, %function
322MRT0_IRQHandler:
323    ldr   r0,=MRT0_DriverIRQHandler
324    bx    r0
325    .size MRT0_IRQHandler, . - MRT0_IRQHandler
326
327    .align 1
328    .thumb_func
329    .weak CMP_IRQHandler
330    .type CMP_IRQHandler, %function
331CMP_IRQHandler:
332    ldr   r0,=CMP_DriverIRQHandler
333    bx    r0
334    .size CMP_IRQHandler, . - CMP_IRQHandler
335
336    .align 1
337    .thumb_func
338    .weak WDT_IRQHandler
339    .type WDT_IRQHandler, %function
340WDT_IRQHandler:
341    ldr   r0,=WDT_DriverIRQHandler
342    bx    r0
343    .size WDT_IRQHandler, . - WDT_IRQHandler
344
345    .align 1
346    .thumb_func
347    .weak BOD_IRQHandler
348    .type BOD_IRQHandler, %function
349BOD_IRQHandler:
350    ldr   r0,=BOD_DriverIRQHandler
351    bx    r0
352    .size BOD_IRQHandler, . - BOD_IRQHandler
353
354    .align 1
355    .thumb_func
356    .weak FLASH_IRQHandler
357    .type FLASH_IRQHandler, %function
358FLASH_IRQHandler:
359    ldr   r0,=FLASH_DriverIRQHandler
360    bx    r0
361    .size FLASH_IRQHandler, . - FLASH_IRQHandler
362
363    .align 1
364    .thumb_func
365    .weak WKT_IRQHandler
366    .type WKT_IRQHandler, %function
367WKT_IRQHandler:
368    ldr   r0,=WKT_DriverIRQHandler
369    bx    r0
370    .size WKT_IRQHandler, . - WKT_IRQHandler
371
372    .align 1
373    .thumb_func
374    .weak ADC0_SEQA_IRQHandler
375    .type ADC0_SEQA_IRQHandler, %function
376ADC0_SEQA_IRQHandler:
377    ldr   r0,=ADC0_SEQA_DriverIRQHandler
378    bx    r0
379    .size ADC0_SEQA_IRQHandler, . - ADC0_SEQA_IRQHandler
380
381    .align 1
382    .thumb_func
383    .weak ADC0_SEQB_IRQHandler
384    .type ADC0_SEQB_IRQHandler, %function
385ADC0_SEQB_IRQHandler:
386    ldr   r0,=ADC0_SEQB_DriverIRQHandler
387    bx    r0
388    .size ADC0_SEQB_IRQHandler, . - ADC0_SEQB_IRQHandler
389
390    .align 1
391    .thumb_func
392    .weak ADC0_THCMP_IRQHandler
393    .type ADC0_THCMP_IRQHandler, %function
394ADC0_THCMP_IRQHandler:
395    ldr   r0,=ADC0_THCMP_DriverIRQHandler
396    bx    r0
397    .size ADC0_THCMP_IRQHandler, . - ADC0_THCMP_IRQHandler
398
399    .align 1
400    .thumb_func
401    .weak ADC0_OVR_IRQHandler
402    .type ADC0_OVR_IRQHandler, %function
403ADC0_OVR_IRQHandler:
404    ldr   r0,=ADC0_OVR_DriverIRQHandler
405    bx    r0
406    .size ADC0_OVR_IRQHandler, . - ADC0_OVR_IRQHandler
407
408    .align 1
409    .thumb_func
410    .weak DMA0_IRQHandler
411    .type DMA0_IRQHandler, %function
412DMA0_IRQHandler:
413    ldr   r0,=DMA0_DriverIRQHandler
414    bx    r0
415    .size DMA0_IRQHandler, . - DMA0_IRQHandler
416
417    .align 1
418    .thumb_func
419    .weak I2C2_IRQHandler
420    .type I2C2_IRQHandler, %function
421I2C2_IRQHandler:
422    ldr   r0,=I2C2_DriverIRQHandler
423    bx    r0
424    .size I2C2_IRQHandler, . - I2C2_IRQHandler
425
426    .align 1
427    .thumb_func
428    .weak I2C3_IRQHandler
429    .type I2C3_IRQHandler, %function
430I2C3_IRQHandler:
431    ldr   r0,=I2C3_DriverIRQHandler
432    bx    r0
433    .size I2C3_IRQHandler, . - I2C3_IRQHandler
434
435    .align 1
436    .thumb_func
437    .weak Reserved39_IRQHandler
438    .type Reserved39_IRQHandler, %function
439Reserved39_IRQHandler:
440    ldr   r0,=Reserved39_DriverIRQHandler
441    bx    r0
442    .size Reserved39_IRQHandler, . - Reserved39_IRQHandler
443
444    .align 1
445    .thumb_func
446    .weak PIN_INT0_IRQHandler
447    .type PIN_INT0_IRQHandler, %function
448PIN_INT0_IRQHandler:
449    ldr   r0,=PIN_INT0_DriverIRQHandler
450    bx    r0
451    .size PIN_INT0_IRQHandler, . - PIN_INT0_IRQHandler
452
453    .align 1
454    .thumb_func
455    .weak PIN_INT1_IRQHandler
456    .type PIN_INT1_IRQHandler, %function
457PIN_INT1_IRQHandler:
458    ldr   r0,=PIN_INT1_DriverIRQHandler
459    bx    r0
460    .size PIN_INT1_IRQHandler, . - PIN_INT1_IRQHandler
461
462    .align 1
463    .thumb_func
464    .weak PIN_INT2_IRQHandler
465    .type PIN_INT2_IRQHandler, %function
466PIN_INT2_IRQHandler:
467    ldr   r0,=PIN_INT2_DriverIRQHandler
468    bx    r0
469    .size PIN_INT2_IRQHandler, . - PIN_INT2_IRQHandler
470
471    .align 1
472    .thumb_func
473    .weak PIN_INT3_IRQHandler
474    .type PIN_INT3_IRQHandler, %function
475PIN_INT3_IRQHandler:
476    ldr   r0,=PIN_INT3_DriverIRQHandler
477    bx    r0
478    .size PIN_INT3_IRQHandler, . - PIN_INT3_IRQHandler
479
480    .align 1
481    .thumb_func
482    .weak PIN_INT4_IRQHandler
483    .type PIN_INT4_IRQHandler, %function
484PIN_INT4_IRQHandler:
485    ldr   r0,=PIN_INT4_DriverIRQHandler
486    bx    r0
487    .size PIN_INT4_IRQHandler, . - PIN_INT4_IRQHandler
488
489    .align 1
490    .thumb_func
491    .weak PIN_INT5_IRQHandler
492    .type PIN_INT5_IRQHandler, %function
493PIN_INT5_IRQHandler:
494    ldr   r0,=PIN_INT5_DriverIRQHandler
495    bx    r0
496    .size PIN_INT5_IRQHandler, . - PIN_INT5_IRQHandler
497
498    .align 1
499    .thumb_func
500    .weak PIN_INT6_IRQHandler
501    .type PIN_INT6_IRQHandler, %function
502PIN_INT6_IRQHandler:
503    ldr   r0,=PIN_INT6_DriverIRQHandler
504    bx    r0
505    .size PIN_INT6_IRQHandler, . - PIN_INT6_IRQHandler
506
507    .align 1
508    .thumb_func
509    .weak PIN_INT7_IRQHandler
510    .type PIN_INT7_IRQHandler, %function
511PIN_INT7_IRQHandler:
512    ldr   r0,=PIN_INT7_DriverIRQHandler
513    bx    r0
514    .size PIN_INT7_IRQHandler, . - PIN_INT7_IRQHandler
515
516
517/*    Macro to define default handlers. Default handler
518 *    will be weak symbol and just dead loops. They can be
519 *    overwritten by other handlers */
520    .macro def_irq_handler  handler_name
521    .weak \handler_name
522    .set  \handler_name, DefaultISR
523    .endm
524    def_irq_handler    SPI0_DriverIRQHandler
525    def_irq_handler    SPI1_DriverIRQHandler
526    def_irq_handler    Reserved18_DriverIRQHandler
527    def_irq_handler    USART0_DriverIRQHandler
528    def_irq_handler    USART1_DriverIRQHandler
529    def_irq_handler    USART2_DriverIRQHandler
530    def_irq_handler    Reserved22_DriverIRQHandler
531    def_irq_handler    I2C1_DriverIRQHandler
532    def_irq_handler    I2C0_DriverIRQHandler
533    def_irq_handler    SCT0_DriverIRQHandler
534    def_irq_handler    MRT0_DriverIRQHandler
535    def_irq_handler    CMP_DriverIRQHandler
536    def_irq_handler    WDT_DriverIRQHandler
537    def_irq_handler    BOD_DriverIRQHandler
538    def_irq_handler    FLASH_DriverIRQHandler
539    def_irq_handler    WKT_DriverIRQHandler
540    def_irq_handler    ADC0_SEQA_DriverIRQHandler
541    def_irq_handler    ADC0_SEQB_DriverIRQHandler
542    def_irq_handler    ADC0_THCMP_DriverIRQHandler
543    def_irq_handler    ADC0_OVR_DriverIRQHandler
544    def_irq_handler    DMA0_DriverIRQHandler
545    def_irq_handler    I2C2_DriverIRQHandler
546    def_irq_handler    I2C3_DriverIRQHandler
547    def_irq_handler    Reserved39_DriverIRQHandler
548    def_irq_handler    PIN_INT0_DriverIRQHandler
549    def_irq_handler    PIN_INT1_DriverIRQHandler
550    def_irq_handler    PIN_INT2_DriverIRQHandler
551    def_irq_handler    PIN_INT3_DriverIRQHandler
552    def_irq_handler    PIN_INT4_DriverIRQHandler
553    def_irq_handler    PIN_INT5_DriverIRQHandler
554    def_irq_handler    PIN_INT6_DriverIRQHandler
555    def_irq_handler    PIN_INT7_DriverIRQHandler
556
557    .end
558