1/* ------------------------------------------------------------------------- */
2/*  @file:    startup_MKE16Z4.s                                              */
3/*  @purpose: CMSIS Cortex-M0P Core Device Startup File                      */
4/*            MKE16Z4                                                        */
5/*  @version: 3.0                                                            */
6/*  @date:    2020-1-22                                                      */
7/*  @build:   b231019                                                        */
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 __isr_vector
22__isr_vector:
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   Reserved16_IRQHandler                           /* Reserved interrupt*/
42    .long   Reserved17_IRQHandler                           /* Reserved interrupt*/
43    .long   Reserved18_IRQHandler                           /* Reserved interrupt*/
44    .long   Reserved19_IRQHandler                           /* Reserved interrupt*/
45    .long   Reserved20_IRQHandler                           /* Reserved interrupt*/
46    .long   FTFA_IRQHandler                                 /* Flash memory single interrupt vector for all sources*/
47    .long   LVD_LVW_IRQHandler                              /* Low-voltage detect, low-voltage warning*/
48    .long   PORTAE_IRQHandler                               /* Pin detect (Port A, E)*/
49    .long   LPI2C0_IRQHandler                               /* Inter-integrated circuit 0 interrupt*/
50    .long   Reserved25_IRQHandler                           /* Reserved interrupt*/
51    .long   LPSPI0_IRQHandler                               /* Serial peripheral Interface 0 interrupt*/
52    .long   Reserved27_IRQHandler                           /* Reserved interrupt*/
53    .long   LPUART0_IRQHandler                              /* Single interrupt vector for all sources*/
54    .long   LPUART1_IRQHandler                              /* Single interrupt vector for all sources*/
55    .long   LPUART2_IRQHandler                              /* Single interrupt vector for all sources*/
56    .long   ADC0_IRQHandler                                 /* ADC0 conversion complete interrupt*/
57    .long   CMP0_IRQHandler                                 /* CMP0 interrupt*/
58    .long   FTM0_IRQHandler                                 /* FTM0 single interrupt vector for all sources*/
59    .long   FTM1_IRQHandler                                 /* FTM1 single interrupt vector for all sources*/
60    .long   Reserved35_IRQHandler                           /* Reserved interrupt*/
61    .long   RTC_IRQHandler                                  /* Single interrupt vector for all sources*/
62    .long   Reserved37_IRQHandler                           /* Reserved interrupt*/
63    .long   LPIT0_IRQHandler                                /* LPIT channel 0-1*/
64    .long   Reserved39_IRQHandler                           /* Reserved interrupt*/
65    .long   TSI_IRQHandler                                  /* TSI interrupt*/
66    .long   PDB0_IRQHandler                                 /* Programmable delay block interrupt*/
67    .long   PORTBCD_IRQHandler                              /* Pin detect (Port B, C, D)*/
68    .long   SCG_RCM_IRQHandler                              /* Single interrupt vector for SCG and RCM*/
69    .long   WDOG_EWM_IRQHandler                             /* Single interrupt vector for WDOG and EWM*/
70    .long   PWT_LPTMR0_IRQHandler                           /* Single interrupt vector for PWT and LPTMR0*/
71    .long   MSCAN_Rx_IRQHandler                             /* MSCAN Rx Interrupt*/
72    .long   MSCAN_ORed_IRQHandler                           /* MSCAN Tx, Err and Wake-up interrupt*/
73
74    .size   __isr_vector, . - __isr_vector
75
76/* Flash Configuration */
77    .section .FlashConfig, "a"
78    .long 0xFFFFFFFF
79    .long 0xFFFFFFFF
80    .long 0xFFFFFFFF
81    .long 0xFFFFFFFE
82
83    .text
84    .thumb
85
86#if defined (__cplusplus)
87#ifdef __REDLIB__
88#error Redlib does not support C++
89#endif
90#endif
91/* Reset Handler */
92
93    .thumb_func
94    .align 2
95    .globl   Reset_Handler
96    .weak    Reset_Handler
97    .type    Reset_Handler, %function
98Reset_Handler:
99    cpsid   i               /* Mask interrupts */
100    .equ    VTOR, 0xE000ED08
101    ldr     r0, =VTOR
102    ldr     r1, =__isr_vector
103    str     r1, [r0]
104    ldr     r2, [r1]
105    msr     msp, r2
106#ifndef __NO_SYSTEM_INIT
107    ldr   r0,=SystemInit
108    blx   r0
109#endif
110/*     Loop to copy data from read only memory to RAM. The ranges
111 *      of copy from/to are specified by following symbols evaluated in
112 *      linker script.
113 *      __etext: End of code section, i.e., begin of data sections to copy from.
114 *      __data_start__/__data_end__: RAM address range that data should be
115 *      copied to. Both must be aligned to 4 bytes boundary.  */
116
117    ldr    r1, =__etext
118    ldr    r2, =__data_start__
119    ldr    r3, =__data_end__
120
121    subs    r3, r2
122    ble     .LC0
123
124.LC1:
125    subs    r3, 4
126    ldr    r0, [r1,r3]
127    str    r0, [r2,r3]
128    bgt    .LC1
129.LC0:
130
131#ifdef __STARTUP_CLEAR_BSS
132/*     This part of work usually is done in C library startup code. Otherwise,
133 *     define this macro to enable it in this startup.
134 *
135 *     Loop to zero out BSS section, which uses following symbols
136 *     in linker script:
137 *      __bss_start__: start of BSS section. Must align to 4
138 *      __bss_end__: end of BSS section. Must align to 4
139 */
140    ldr r1, =__bss_start__
141    ldr r2, =__bss_end__
142
143    subs    r2, r1
144    ble .LC3
145
146    movs    r0, 0
147.LC2:
148    subs    r2, 4
149    str r0, [r1, r2]
150    bgt .LC2
151.LC3:
152#endif
153    cpsie   i               /* Unmask interrupts */
154#ifndef __START
155#ifdef __REDLIB__
156#define __START __main
157#else
158#define __START _start
159#endif
160#endif
161#ifndef __ATOLLIC__
162    ldr   r0,=__START
163    blx   r0
164#else
165    ldr   r0,=__libc_init_array
166    blx   r0
167    ldr   r0,=main
168    bx    r0
169#endif
170    .pool
171    .size Reset_Handler, . - Reset_Handler
172
173    .align  1
174    .thumb_func
175    .weak DefaultISR
176    .type DefaultISR, %function
177DefaultISR:
178    ldr r0, =DefaultISR
179    bx r0
180    .size DefaultISR, . - DefaultISR
181
182    .align 1
183    .thumb_func
184    .weak NMI_Handler
185    .type NMI_Handler, %function
186NMI_Handler:
187    ldr   r0,=NMI_Handler
188    bx    r0
189    .size NMI_Handler, . - NMI_Handler
190
191    .align 1
192    .thumb_func
193    .weak HardFault_Handler
194    .type HardFault_Handler, %function
195HardFault_Handler:
196    ldr   r0,=HardFault_Handler
197    bx    r0
198    .size HardFault_Handler, . - HardFault_Handler
199
200    .align 1
201    .thumb_func
202    .weak SVC_Handler
203    .type SVC_Handler, %function
204SVC_Handler:
205    ldr   r0,=SVC_Handler
206    bx    r0
207    .size SVC_Handler, . - SVC_Handler
208
209    .align 1
210    .thumb_func
211    .weak PendSV_Handler
212    .type PendSV_Handler, %function
213PendSV_Handler:
214    ldr   r0,=PendSV_Handler
215    bx    r0
216    .size PendSV_Handler, . - PendSV_Handler
217
218    .align 1
219    .thumb_func
220    .weak SysTick_Handler
221    .type SysTick_Handler, %function
222SysTick_Handler:
223    ldr   r0,=SysTick_Handler
224    bx    r0
225    .size SysTick_Handler, . - SysTick_Handler
226
227    .align 1
228    .thumb_func
229    .weak LPI2C0_IRQHandler
230    .type LPI2C0_IRQHandler, %function
231LPI2C0_IRQHandler:
232    ldr   r0,=LPI2C0_DriverIRQHandler
233    bx    r0
234    .size LPI2C0_IRQHandler, . - LPI2C0_IRQHandler
235
236    .align 1
237    .thumb_func
238    .weak LPSPI0_IRQHandler
239    .type LPSPI0_IRQHandler, %function
240LPSPI0_IRQHandler:
241    ldr   r0,=LPSPI0_DriverIRQHandler
242    bx    r0
243    .size LPSPI0_IRQHandler, . - LPSPI0_IRQHandler
244
245    .align 1
246    .thumb_func
247    .weak LPUART0_IRQHandler
248    .type LPUART0_IRQHandler, %function
249LPUART0_IRQHandler:
250    ldr   r0,=LPUART0_DriverIRQHandler
251    bx    r0
252    .size LPUART0_IRQHandler, . - LPUART0_IRQHandler
253
254    .align 1
255    .thumb_func
256    .weak LPUART1_IRQHandler
257    .type LPUART1_IRQHandler, %function
258LPUART1_IRQHandler:
259    ldr   r0,=LPUART1_DriverIRQHandler
260    bx    r0
261    .size LPUART1_IRQHandler, . - LPUART1_IRQHandler
262
263    .align 1
264    .thumb_func
265    .weak LPUART2_IRQHandler
266    .type LPUART2_IRQHandler, %function
267LPUART2_IRQHandler:
268    ldr   r0,=LPUART2_DriverIRQHandler
269    bx    r0
270    .size LPUART2_IRQHandler, . - LPUART2_IRQHandler
271
272    .align 1
273    .thumb_func
274    .weak MSCAN_Rx_IRQHandler
275    .type MSCAN_Rx_IRQHandler, %function
276MSCAN_Rx_IRQHandler:
277    ldr   r0,=MSCAN_DriverIRQHandler
278    bx    r0
279    .size MSCAN_Rx_IRQHandler, . - MSCAN_Rx_IRQHandler
280
281    .align 1
282    .thumb_func
283    .weak MSCAN_ORed_IRQHandler
284    .type MSCAN_ORed_IRQHandler, %function
285MSCAN_ORed_IRQHandler:
286    ldr   r0,=MSCAN_DriverIRQHandler
287    bx    r0
288    .size MSCAN_ORed_IRQHandler, . - MSCAN_ORed_IRQHandler
289
290
291/*    Macro to define default handlers. Default handler
292 *    will be weak symbol and just dead loops. They can be
293 *    overwritten by other handlers */
294    .macro def_irq_handler  handler_name
295    .weak \handler_name
296    .set  \handler_name, DefaultISR
297    .endm
298/* Exception Handlers */
299    def_irq_handler    Reserved16_IRQHandler
300    def_irq_handler    Reserved17_IRQHandler
301    def_irq_handler    Reserved18_IRQHandler
302    def_irq_handler    Reserved19_IRQHandler
303    def_irq_handler    Reserved20_IRQHandler
304    def_irq_handler    FTFA_IRQHandler
305    def_irq_handler    LVD_LVW_IRQHandler
306    def_irq_handler    PORTAE_IRQHandler
307    def_irq_handler    LPI2C0_DriverIRQHandler
308    def_irq_handler    Reserved25_IRQHandler
309    def_irq_handler    LPSPI0_DriverIRQHandler
310    def_irq_handler    Reserved27_IRQHandler
311    def_irq_handler    LPUART0_DriverIRQHandler
312    def_irq_handler    LPUART1_DriverIRQHandler
313    def_irq_handler    LPUART2_DriverIRQHandler
314    def_irq_handler    ADC0_IRQHandler
315    def_irq_handler    CMP0_IRQHandler
316    def_irq_handler    FTM0_IRQHandler
317    def_irq_handler    FTM1_IRQHandler
318    def_irq_handler    Reserved35_IRQHandler
319    def_irq_handler    RTC_IRQHandler
320    def_irq_handler    Reserved37_IRQHandler
321    def_irq_handler    LPIT0_IRQHandler
322    def_irq_handler    Reserved39_IRQHandler
323    def_irq_handler    TSI_IRQHandler
324    def_irq_handler    PDB0_IRQHandler
325    def_irq_handler    PORTBCD_IRQHandler
326    def_irq_handler    SCG_RCM_IRQHandler
327    def_irq_handler    WDOG_EWM_IRQHandler
328    def_irq_handler    PWT_LPTMR0_IRQHandler
329    def_irq_handler    MSCAN_DriverIRQHandler
330
331    .end
332