13.07.2015 Views

TASKING VX-toolset for ARM User Guide

TASKING VX-toolset for ARM User Guide

TASKING VX-toolset for ARM User Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9. Run-time EnvironmentThis chapter describes the startup code used by the <strong>TASKING</strong> <strong>VX</strong>-<strong>toolset</strong> <strong>for</strong> <strong>ARM</strong> C Compiler, the vectortable, the stack layout and the heap.9.1. Startup CodeYou need the run-time startup code to build an executable application. The default startup code consistsof the following components:• Initialization code. This code is executed when the program is initiated and be<strong>for</strong>e the function main()is called.• Exit code. This controls the close down of the application after the program's main function terminates.The startup code is part of the C library, and the source is present in the file cstart.asm (<strong>ARM</strong> andThumb), or cstart.c (Thumb2 specific) in the directory lib\src. This code is generic code. It useslinker generated symbols which you can give target specific or application specific values.These symbolsare defined in the linker script file (include.lsl\arm_arch.lsl) and you can specify their values inEclipse or on the command line with linker option --define. If the default run-time startup code does notmatch your configuration, you need to make a copy of the startup file, modify it and add it to your project.A typical example <strong>for</strong> doing this is when main() has arguments, typically argc/argv. In this case cstartneeds to be recompiled with the macro __USE_ARGC_ARGV set. When necessary you can use the macro__ARGCV_BUFSIZE to define the size of the buffer used to pass arguments to main().The entry point of the startup code (reset handler) is label _START. This global label should not beremoved, since the linker uses it in the linker script file. It is also used as the default start address of theapplication.Initialization codeThe following initialization actions are executed be<strong>for</strong>e the application starts:• Load the 'real' program address. This assures that the reset handler is immune <strong>for</strong> any ROM/RAMre-mapping.• Initialize the stack pointers <strong>for</strong> each processor mode. The stack pointers are loaded in memory by thestack address located at a linker generate symbol (<strong>for</strong> example _lc_ub_stack). These symbols aredefined in the linker script file. See Section 9.4, Stack and Heap, <strong>for</strong> detailed in<strong>for</strong>mation on the stack.• Call a user function which initializes hardware.The startup code calls the function __init_hardware.This function has an empty implementation in the C library, which you should change if certain hardwareinitializations, such as ROM/RAM re-mapping or MMU configuration, are required be<strong>for</strong>e calling themain application.• Copy initialized sections from ROM to RAM, using a linker generated table (also known as the 'copytable') and clear uninitialized data sections in RAM.223

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!