The following section describes the role of the target-specific startup code.
When you create a new project to produce an executable file using a target-specific
project template, a file containing the default startup code for the
target 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, select
the file in the Project Explorer and select Import to copy the file
to your project directory.
ARM and Cortex-A/Cortex-R startup code
The target startup file typically consists of the exception vector table and the default
set of exception handlers.
- _vectors — This is the exception vector table. It is put into its
own .vectors section in order to ensure that it is can be placed at
a specific address which is usually 0x00000000 or the start of Flash memory.
The vector table contains jump instructions to the
particular exception handlers. It is recommended that absolute jump instructions
are used ldr pc, =handler_address rather than relative
branch instructions b handler_address since many devices shadow
the memory at address zero to start execution but the program will be linked
to run at a different address.
- reset_handler — The reset handler will
usually carry out any target-specific initialization and then will jump to the
_start entry point. In a C system, the _start entry point is in the
crt0.s file. During development it is usual to replace the reset handler with
an endless loop which will stop the device running potentially dangerous
in-development code directly out of reset. In development the debugger will start
the device from the specified debug entry point.
- undef_handler — This is the default, undefined-instruction exception
handler.*
- swi_handler — This is the default, software-interrupt exception
handler.*
- pabort_handler — This is the default, prefetch-abort exception
handler.*
- dabort_handler — This is the default, data-abort exception handler.*
- irq_handler — This is the default, IRQ-exception handler.*
- fiq_handler — This is the default, FIQ-exception handler.*
* Declared as a weak symbol to allow the user to override the implementation.
Note that ARM and Cortex-A/Cortex-R exception handlers must be written in ARM assembly code.
The CPU or board support package of the project you have created will
typically supply an ARM assembly-coded irq_handler implementation
that will enable you to write interrupt service routines as C functions.
Cortex-M startup code
The target startup file typically consists of the exception vector
table and the default set of exception handlers.
- _vectors — This is the exception vector table. It is put into its
own .vectors section in order to ensure that it can be placed at a
specific address which is usually 0x00000000 or the start of Flash memory.
The vector table is structured as follows:
- The first entry is the initial value of the stack pointer.
- The second entry is the address of the reset handler function.
The reset handler will usually carry out any
target-specific initialization and then jump to the _start entry point.
In a C system, the _start entry point is in the thumb_crt0.s file.
During development it is usual to replace this jump with an endless loop
which will stop the device running potentially dangerous in-development
code directly out of reset. In development the debugger will start
the device from the specified debug entry point.
- The following 15 entries are the addresses of the standard Cortex-M
exception handlers ending with the SysTick_ISR entry.
- Subsequent entries are addresses of device-specific interrupt sources
and their associated handlers.
For each exception handler, a weak symbol is declared that will implement
an endless loop. You can implement your own exception handler as a regular
C function. Note that the name of the C function must match the name in the
startup code e.g. void SysTick_ISR(void). You can use the C preprocessor
to rename the symbol in the startup code if you have existing code with
different exception handler names e.g. SysTick_ISR=SysTick_Handler.