contrib: replace the BSD-3-Clause license tag
[fw/openocd] / contrib / loaders / flash / msp432 / startup_msp432p4.c
1 /* SPDX-License-Identifier: BSD-3-Clause */
2
3 /******************************************************************************
4 *
5 * Copyright (C) 2012-2018 Texas Instruments Incorporated - http://www.ti.com/
6 *
7 ******************************************************************************/
8
9 #include <stdint.h>
10
11 /* Entry point for the application. */
12 extern int main();
13
14 /* Reserve space for the system stack. */
15 extern uint32_t __stack_top;
16
17 typedef void(*pFunc)(void);
18
19 /* Interrupt handler prototypes */
20 void default_handler(void);
21 void reset_handler(void);
22
23 /*
24  * The vector table.  Note that the proper constructs must be placed on this to
25  * ensure that it ends up at physical address 0x0000.0000 or at the start of
26  * the program if located at a start address other than 0.
27  */
28 void (* const intr_vectors[])(void) __attribute__((section(".intvecs"))) = {
29         (pFunc)&__stack_top, /* The initial stack pointer */
30         reset_handler,       /* The reset handler         */
31         default_handler,     /* The NMI handler           */
32         default_handler,     /* The hard fault handler    */
33         default_handler,     /* The MPU fault handler     */
34         default_handler,     /* The bus fault handler     */
35         default_handler,     /* The usage fault handler   */
36         0,                   /* Reserved                  */
37         0,                   /* Reserved                  */
38         0,                   /* Reserved                  */
39         0,                   /* Reserved                  */
40         default_handler,     /* SVCall handler            */
41         default_handler,     /* Debug monitor handler     */
42         0,                   /* Reserved                  */
43         default_handler,     /* The PendSV handler        */
44         default_handler      /* The SysTick handler       */
45 };
46
47 /*
48  * The following are constructs created by the linker, indicating where
49  * the "data" and "bss" segments reside in memory.  The initializers for
50  * the "data" segment resides immediately following the "text" segment.
51  */
52 extern uint32_t __bss_start__;
53 extern uint32_t __bss_end__;
54
55 /*
56  * This is the code that gets called when the processor first starts execution
57  * following a reset event.  Only the absolutely necessary set is performed,
58  * after which the application supplied entry() routine is called.  Any fancy
59  * actions (such as making decisions based on the reset cause register, and
60  * resetting the bits in that register) are left solely in the hands of the
61  * application.
62  */
63 __attribute__((section(".reset"))) __attribute__((naked))
64 void reset_handler(void)
65 {
66         /* Set stack pointer */
67         __asm("    MOVW.W  r0, #0x1700\n"
68                   "    MOVT.W  r0, #0x0100\n"
69                   "    mov     sp, r0\n");
70
71         /* Zero fill the bss segment. */
72         __asm("    ldr     r0, =__bss_start__\n"
73                   "    ldr     r1, =__bss_end__\n"
74                   "    mov     r2, #0\n"
75                   "    .thumb_func\n"
76                   "zero_loop:\n"
77                   "    cmp     r0, r1\n"
78                   "    it      lt\n"
79                   "    strlt   r2, [r0], #4\n"
80                   "    blt     zero_loop");
81
82         /* Call the application's entry point. */
83         main();
84 }
85
86 /*
87  * This is the code that gets called when the processor receives an unexpected
88  * interrupt.  This simply enters an infinite loop, preserving the system state
89  * for examination by a debugger.
90  */
91 void default_handler(void)
92 {
93         /* Enter an infinite loop. */
94         while (1)
95                 ;
96 }