source: ecs_cellMon/firmware/SEGGER_THUMB_Startup.s @ 11

Last change on this file since 11 was 3, checked in by f.jahn, 20 months ago

fw hinzugfügt-->zed

File size: 9.9 KB
Line 
1/*********************************************************************
2*                    SEGGER Microcontroller GmbH                     *
3*                        The Embedded Experts                        *
4**********************************************************************
5*                                                                    *
6*            (c) 2014 - 2021 SEGGER Microcontroller GmbH             *
7*                                                                    *
8*       www.segger.com     Support: support@segger.com               *
9*                                                                    *
10**********************************************************************
11*                                                                    *
12* All rights reserved.                                               *
13*                                                                    *
14* Redistribution and use in source and binary forms, with or         *
15* without modification, are permitted provided that the following    *
16* condition is met:                                                  *
17*                                                                    *
18* - Redistributions of source code must retain the above copyright   *
19*   notice, this condition and the following disclaimer.             *
20*                                                                    *
21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
22* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
23* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
24* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
25* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
26* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
27* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
28* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
29* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
30* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
31* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
32* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
33* DAMAGE.                                                            *
34*                                                                    *
35**********************************************************************
36
37-------------------------- END-OF-HEADER -----------------------------
38
39File      : SEGGER_THUMB_Startup.s
40Purpose   : Generic runtime init startup code for ARM CPUs running
41            in THUMB mode.
42            Designed to work with the SEGGER linker to produce
43            smallest possible executables.
44           
45            This file does not normally require any customization.
46
47Additional information:
48  Preprocessor Definitions
49    FULL_LIBRARY
50      If defined then
51        - argc, argv are set up by calling SEGGER_SEMIHOST_GetArgs().
52        - the exit symbol is defined and executes on return from main.
53        - the exit symbol calls destructors, atexit functions and then
54          calls SEGGER_SEMIHOST_Exit().
55   
56      If not defined then
57        - argc and argv are not valid (main is assumed to not take parameters)
58        - the exit symbol is defined, executes on return from main and
59          halts in a loop.
60*/
61
62        .syntax unified 
63
64/*********************************************************************
65*
66*       Defines, configurable
67*
68**********************************************************************
69*/
70
71#ifndef   APP_ENTRY_POINT
72  #define APP_ENTRY_POINT main
73#endif
74
75#ifndef   ARGSSPACE
76  #define ARGSSPACE 128
77#endif
78
79/*********************************************************************
80*
81*       Macros
82*
83**********************************************************************
84*/
85//
86// Declare a label as function symbol (without switching sections)
87//
88.macro MARK_FUNC Name
89        .global \Name
90        .thumb_func
91        .code 16
92\Name:
93.endm
94//
95// Declare a regular function.
96// Functions from the startup are placed in the init section.
97//
98.macro START_FUNC Name
99        .section .init.\Name, "ax"
100        .global \Name
101        .balign 2
102        .thumb_func
103        .code 16
104\Name:
105.endm
106
107//
108// Declare a weak function
109//
110.macro WEAK_FUNC Name
111        .section .init.\Name, "ax", %progbits
112        .global \Name
113        .weak \Name
114        .balign 2
115        .thumb_func
116        .code 16
117\Name:
118.endm
119
120//
121// Mark the end of a function and calculate its size
122//
123.macro END_FUNC name
124        .size \name,.-\name
125.endm
126
127/*********************************************************************
128*
129*       Externals
130*
131**********************************************************************
132*/
133        .extern APP_ENTRY_POINT     // typically main
134
135/*********************************************************************
136*
137*       Global functions
138*
139**********************************************************************
140*/
141/*********************************************************************
142*
143*       _start
144*
145*  Function description
146*    Entry point for the startup code.
147*    Usually called by the reset handler.
148*    Performs all initialisation, based on the entries in the
149*    linker-generated init table, then calls main().
150*    It is device independent, so there should not be any need for an
151*    end-user to modify it.
152*
153*  Additional information
154*    At this point, the stack pointer should already have been
155*    initialized
156*      - by hardware (such as on Cortex-M),
157*      - by the device-specific reset handler,
158*      - or by the debugger (such as for RAM Code).
159*/
160#undef L
161#define L(label) .L_start_##label
162
163START_FUNC _start
164        //
165        // Call linker init functions which in turn performs the following:
166        // * Perform segment init
167        // * Perform heap init (if used)
168        // * Call constructors of global Objects (if any exist)
169        //
170        ldr     R4, =__SEGGER_init_table__      // Set table pointer to start of initialization table
171L(RunInit):
172        ldr     R0, [R4]                        // Get next initialization function from table
173        adds    R4, R4, #4                      // Increment table pointer to point to function arguments
174        blx     R0                              // Call initialization function
175        b       L(RunInit)
176        //
177MARK_FUNC __SEGGER_init_done
178        //
179        // Time to call main(), the application entry point.
180        //
181#ifndef FULL_LIBRARY
182        //
183        // In a real embedded application ("Free-standing environment"),
184        // main() does not get any arguments,
185        // which means it is not necessary to init R0 and R1.
186        //
187        bl      APP_ENTRY_POINT                 // Call to application entry point (usually main())
188
189END_FUNC _start
190        //
191        // end of _start
192        // Fall-through to exit if main ever returns.
193        //
194MARK_FUNC exit
195        //
196        // In a free-standing environment, if returned from application:
197        // Loop forever.
198        //
199        b       .
200        .size exit,.-exit
201#else
202        //
203        // In a hosted environment,
204        // we need to load R0 and R1 with argc and argv, in order to handle
205        // the command line arguments.
206        // This is required for some programs running under control of a
207        // debugger, such as automated tests.
208        //
209        movs    R0, #ARGSSPACE
210        ldr     R1, =__SEGGER_init_arg_data
211        bl      SEGGER_SEMIHOST_GetArgs
212        ldr     R1, =__SEGGER_init_arg_data
213        bl      APP_ENTRY_POINT                 // Call to application entry point (usually main())
214        bl      exit                            // Call exit function
215        b       .                               // If we unexpectedly return from exit, hang.
216END_FUNC _start
217#endif
218        //
219#ifdef FULL_LIBRARY
220/*********************************************************************
221*
222*       exit
223*
224*  Function description
225*    Exit of the system.
226*    Called on return from application entry point or explicit call
227*    to exit.
228*
229*  Additional information
230*    In a hosted environment exit gracefully, by
231*    saving the return value,
232*    calling destructurs of global objects,
233*    calling registered atexit functions,
234*    and notifying the host/debugger.
235*/
236#undef L
237#define L(label) .L_exit_##label
238
239WEAK_FUNC exit
240        mov     R5, R0                  // Save the exit parameter/return result
241        //
242        // Call destructors
243        //
244        ldr     R0, =__dtors_start__    // Pointer to destructor list
245        ldr     R1, =__dtors_end__
246L(Loop):
247        cmp     R0, R1
248        beq     L(End)                  // Reached end of destructor list? => Done
249        ldr     R2, [R0]                // Load current destructor address into R2
250        adds    R0, R0, #4              // Increment pointer
251        push    {R0-R1}                 // Save R0 and R1
252        blx     R2                      // Call destructor
253        pop     {R0-R1}                 // Restore R0 and R1
254        b       L(Loop)
255L(End):
256        //
257        // Call atexit functions
258        //
259        bl      __SEGGER_RTL_execute_at_exit_fns
260        //
261        // Call debug_exit with return result/exit parameter
262        //
263        mov     R0, R5
264        bl      SEGGER_SEMIHOST_Exit
265        //
266        // If execution is not terminated, loop forever
267        //
268L(ExitLoop):
269        b       L(ExitLoop) // Loop forever.
270END_FUNC exit
271#endif
272
273#ifdef FULL_LIBRARY
274        .bss
275__SEGGER_init_arg_data:
276        .space ARGSSPACE
277        .size __SEGGER_init_arg_data, .-__SEGGER_init_arg_data
278        .type __SEGGER_init_arg_data, %object
279#endif
280
281/*************************** End of file ****************************/
Note: See TracBrowser for help on using the repository browser.