The following section describes the role of the C runtime startup code, crt0.s (and the Cortex-M3/Thumb-2 equivalent thumb_crt0.s).

When you create a new project to produce an executable file using a target specific project template, the crt0.s file will be added to the project. Initially a shared version of this file will be added to the project, if you want to modify this file you should select the file in the project explorer and then select Import to copy the file to your project directory.

The entry point of the C runtime startup code is _start. In a typical system this will be called by the target-specific startup code after it has initialized the target.

The C runtime carries out the following actions:

- Initialize the stacks.
- Copy the contents of the .data (initialized data) section from non-volatile memory should it be required.
- Copy the contents of the .fast section from non-volatile memory to SRAM should it be required.
- Initialize the .bss section.
- Initialize the heap.
- Call constructors.
- If compiled with FULL_LIBRARY get the command line from the host using debug_getargs and set registers to supply argc and argv to main.
- Call the main entry point.
- On return from main or (if compiled with FULL_LIBRARY) a call to exit.
- If compiled with FULL_LIBRARY call destructors.
- If compiled with FULL_LIBRARY call atexit functions.
- If compiled with FULL_LIBRARY call debug_exit supplying the return result from main.
- Wait in exit loop.

### Stacks

The ARM maintains six separate stacks. The position and size of these stacks are specified in the project's section placement or memory map file by the following program sections:

- .stack — System and User mode stack.
- .stack_svc — Supervisor mode stack
- .stack_irq — IRQ mode stack
- .stack_fiq — FIQ mode stack
- .stack_abt — Abort mode stack.
- .stack_und — Undefined mode stack.

The crt0.s startup code references these sections and initializes each of the stack pointer registers to point to the appropriate memory location. To change the location in memory of a particular stack, the section should be moved to the required position in the section placement or memory map file.

There is a Stack Size linker project property for each stack, you can modify this property in order to alter each stack maximum size. For compatibility with earlier versions of CrossStudio you can also specify the stack size using the stack section's Size property in the section placement or memory map file.

Should your application not require one or more of these stacks to be set up you can remove the sections from the memory map file or set the size to 0 and remove the initialization code from the crt0.s file.

### .data Section

The .data section contains the initialized data. If the run address is different from the load address, as it would be in a FLASH based application in order to allow the program to run from reset, the crt0.s startup code will copy the .data section from the load address to the run address before calling the main entry point.

### .fast Section

For performance reasons it is a common requirement with embedded systems to have critical code running from fast memory, the .fast section can be used to simplify this. If the .fast section's run address is different from the load address the crt0.s startup code will copy the .fast section from the load address to the run address before calling the main entry point.

### .bss Section

The .bss section contains the zero initialized data. The crt0.s startup code references the .bss section and sets its contents to zero.

### Heap

The position and size of the heap is specified in the project's section placement or memory map file by the .heap program section.

The crt0.s startup code references this section and initializes the heap. To change the position of the heap, the section should be moved to the required position in the section placement or memory map file.

There is a Heap Size linker project property, you can modify this property in order to alter the heap size. For compatibility with earlier versions of CrossStudio you can also specify the heap size using the heap section's Size property in the section placement or memory map file.

Should your application not require the heap functions, you can remove the heap section from the memory map file or set the size to 0 and remove the heap initialization code from the crt0.s file.