9eb0df8ef73d9f05275a18bef38bdebe23f2b1b8
[fw/openocd] / contrib / loaders / flash / cc26xx / startup.c
1 /* SPDX-License-Identifier: BSD-3-Clause */
2
3 /******************************************************************************
4 *
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6 *
7 ******************************************************************************/
8
9 #include <stdint.h>
10
11 /******************************************************************************
12 *
13 * The entry point for the application startup code.
14 *
15 ******************************************************************************/
16 extern int main(void);
17
18 /******************************************************************************
19 *
20 * Reserve space for the system stack.
21 *
22 ******************************************************************************/
23 __attribute__ ((section(".stack")))
24 static uint32_t stack[100];
25 const uint32_t stack_pntr = (uint32_t)stack + sizeof(stack);
26
27 /******************************************************************************
28 *
29 * The following are constructs created by the linker indicating where
30 * the "bss" and "ebss" segments reside in memory.
31 *
32 ******************************************************************************/
33 extern uint32_t _bss;
34 extern uint32_t _ebss;
35
36 /******************************************************************************
37 *
38 * This is the entry point that handles setting the stack within the allowed
39 * workspace, initializing the .bss segment, and then jumping to main.
40 *
41 ******************************************************************************/
42 __attribute__ ((section(".entry")))
43 void entry(void)
44 {
45         /* Workaround for ITT instructions. */
46         __asm("         NOP");
47         __asm("         NOP");
48         __asm("         NOP");
49         __asm("         NOP");
50
51         /* Initialize stack pointer */
52         __asm("         ldr             sp, =stack_pntr");
53
54         /* Zero fill the bss segment. */
55         __asm("         ldr     r0, =_bss\n"
56                   "             ldr     r1, =_ebss\n"
57                   "             mov     r2, #0\n"
58                   "             .thumb_func\n"
59                   "     zero_loop:\n"
60                   "             cmp             r0, r1\n"
61                   "             it              lt\n"
62                   "             strlt   r2, [r0], #4\n"
63                   "             blt             zero_loop");
64
65         /* Call the application's entry point. */
66         main();
67
68         /* If we ever return, enter an infinite loop */
69         while (1)
70                 ;
71 }