53d8ea8c7585f6bc4e1c31232160f97fd81a180c
[fw/openocd] / contrib / loaders / flash / cc26xx / startup.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 *  Redistributions of source code must retain the above copyright
10 *  notice, this list of conditions and the following disclaimer.
11 *
12 *  Redistributions in binary form must reproduce the above copyright
13 *  notice, this list of conditions and the following disclaimer in the
14 *  documentation and/or other materials provided with the
15 *  distribution.
16 *
17 *  Neither the name of Texas Instruments Incorporated nor the names of
18 *  its contributors may be used to endorse or promote products derived
19 *  from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 ******************************************************************************/
34
35 #include <stdint.h>
36
37 /******************************************************************************
38 *
39 * The entry point for the application startup code.
40 *
41 ******************************************************************************/
42 extern int main(void);
43
44 /******************************************************************************
45 *
46 * Reserve space for the system stack.
47 *
48 ******************************************************************************/
49 __attribute__ ((section(".stack")))
50 static uint32_t stack[100];
51 const uint32_t stack_pntr = (uint32_t)stack + sizeof(stack);
52
53 /******************************************************************************
54 *
55 * The following are constructs created by the linker indicating where
56 * the "bss" and "ebss" segments reside in memory.
57 *
58 ******************************************************************************/
59 extern uint32_t _bss;
60 extern uint32_t _ebss;
61
62 /******************************************************************************
63 *
64 * This is the entry point that handles setting the stack within the allowed
65 * workspace, initializing the .bss segment, and then jumping to main.
66 *
67 ******************************************************************************/
68 __attribute__ ((section(".entry")))
69 void entry(void)
70 {
71         /* Workaround for ITT instructions. */
72         __asm("         NOP");
73         __asm("         NOP");
74         __asm("         NOP");
75         __asm("         NOP");
76
77         /* Initialize stack pointer */
78         __asm("         ldr             sp, =stack_pntr");
79
80         /* Zero fill the bss segment. */
81         __asm("         ldr     r0, =_bss\n"
82                   "             ldr     r1, =_ebss\n"
83                   "             mov     r2, #0\n"
84                   "             .thumb_func\n"
85                   "     zero_loop:\n"
86                   "             cmp             r0, r1\n"
87                   "             it              lt\n"
88                   "             strlt   r2, [r0], #4\n"
89                   "             blt             zero_loop");
90
91         /* Call the application's entry point. */
92         main();
93
94         /* If we ever return, enter an infinite loop */
95         while (1)
96                 ;
97 }