ChibiOS/RT
2.6.0
Startup Support
Collaboration diagram for Startup Support:

Detailed Description

ChibiOS/RT provides its own generic startup file for the ARM Cortex-Mx port. Of course it is not mandatory to use it but care should be taken about the startup phase details.

Startup Process

The startup process, as implemented, is the following:

  1. Interrupts are masked globally.
  2. The two stacks are initialized by assigning them the sizes defined in the linker script (also known as scatter file).
  3. The CPU state is switched to Privileged and the PSP stack is used.
  4. An early initialization routine __early_init() is invoked, if the symbol is not defined then an empty default routine is executed (weak symbol).
  5. DATA and BSS segments are initialized.
  6. Constructors are invoked.
  7. The main() function is invoked with no parameters.
  8. Destructors are invoked.
  9. A branch is performed to the weak symbol _default_exit(). The default code is an endless empty loop.

Expected linker symbols

The startup code starts at the symbol ResetHandler and expects the following symbols to be defined in the linker script:

Additionally the kernel expects the following symbols:

Functions

void main (void)
 Application main() function.
void __early_init (void)
 Early initialization.
void __late_init (void)
 Late initialization.
void _default_exit (void)
 Default main() function exit handler.
void ResetHandler (void)
 Reset vector.

Startup settings

#define CRT0_CONTROL_INIT   0x00000002
 Control special register initialization value.
#define CRT0_STACKS_FILL_PATTERN   0x55555555
 Stack segments initialization switch.
#define CRT0_INIT_STACKS   TRUE
 Stack segments initialization switch.
#define CRT0_INIT_DATA   TRUE
 DATA segment initialization switch.
#define CRT0_INIT_BSS   TRUE
 BSS segment initialization switch.
#define CRT0_CALL_CONSTRUCTORS   TRUE
 Constructors invocation switch.
#define CRT0_CALL_DESTRUCTORS   TRUE
 Destructors invocation switch.

Symbols from the scatter file

uint32_t __main_stack_base__
 Main stack lower boundary.
uint32_t __main_stack_end__
 Main stack initial position.
uint32_t __process_stack_base__
 Process stack lower boundary.
uint32_t __process_stack_end__
 Process stack initial position.
uint32_t _textdata
 ROM image of the data segment start.
uint32_t _data
 Data segment start.
uint32_t _edata
 Data segment end.
uint32_t _bss_start
 BSS segment start.
uint32_t _bss_end
 BSS segment end.
funcp_t __init_array_start
 Constructors table start.
funcp_t __init_array_end
 Constructors table end.
funcp_t __fini_array_start
 Destructors table start.
funcp_t __fini_array_end
 Destructors table end.

Function Documentation

void main ( void  )

Application main() function.

Referenced by ResetHandler().

void __early_init ( void  )

Early initialization.

This hook is invoked immediately after the stack initialization and before the DATA and BSS segments initialization. The default behavior is to do nothing.

Note:
This function is a weak symbol.

Definition at line 234 of file crt0.c.

Referenced by ResetHandler().

void __late_init ( void  )

Late initialization.

This hook is invoked after the DATA and BSS segments initialization and before any static constructor. The default behavior is to do nothing.

Note:
This function is a weak symbol.

Definition at line 246 of file crt0.c.

Referenced by ResetHandler().

void _default_exit ( void  )

Default main() function exit handler.

This handler is invoked or the main() function exit. The default behavior is to enter an infinite loop.

Note:
This function is a weak symbol.

Definition at line 257 of file crt0.c.

Referenced by ResetHandler().


Variable Documentation

Main stack lower boundary.

This symbol must be exported by the linker script and represents the main stack lower boundary.

Referenced by ResetHandler().

Main stack initial position.

This symbol must be exported by the linker script and represents the main stack initial position.

Referenced by ResetHandler().

Process stack lower boundary.

This symbol must be exported by the linker script and represents the process stack lower boundary.

Referenced by ResetHandler().

Process stack initial position.

This symbol must be exported by the linker script and represents the process stack initial position.

Referenced by ResetHandler().

uint32_t _textdata

ROM image of the data segment start.

Precondition:
The symbol must be aligned to a 32 bits boundary.

Referenced by ResetHandler().

uint32_t _data

Data segment start.

Precondition:
The symbol must be aligned to a 32 bits boundary.

Referenced by ResetHandler().

uint32_t _edata

Data segment end.

Precondition:
The symbol must be aligned to a 32 bits boundary.

Referenced by ResetHandler().

uint32_t _bss_start

BSS segment start.

Precondition:
The symbol must be aligned to a 32 bits boundary.

Referenced by ResetHandler().

uint32_t _bss_end

BSS segment end.

Precondition:
The symbol must be aligned to a 32 bits boundary.

Referenced by ResetHandler().

Constructors table start.

Precondition:
The symbol must be aligned to a 32 bits boundary.

Referenced by ResetHandler().

Constructors table end.

Precondition:
The symbol must be aligned to a 32 bits boundary.

Referenced by ResetHandler().

Destructors table start.

Precondition:
The symbol must be aligned to a 32 bits boundary.

Referenced by ResetHandler().

Destructors table end.

Precondition:
The symbol must be aligned to a 32 bits boundary.

Referenced by ResetHandler().


Define Documentation

#define CRT0_CONTROL_INIT   0x00000002

Control special register initialization value.

The system is setup to run in privileged mode using the PSP stack (dual stack mode).

Definition at line 81 of file crt0.c.

Referenced by ResetHandler().

#define CRT0_STACKS_FILL_PATTERN   0x55555555

Stack segments initialization switch.

Definition at line 88 of file crt0.c.

Referenced by ResetHandler().

#define CRT0_INIT_STACKS   TRUE

Stack segments initialization switch.

Definition at line 95 of file crt0.c.

#define CRT0_INIT_DATA   TRUE

DATA segment initialization switch.

Definition at line 102 of file crt0.c.

#define CRT0_INIT_BSS   TRUE

BSS segment initialization switch.

Definition at line 109 of file crt0.c.

#define CRT0_CALL_CONSTRUCTORS   TRUE

Constructors invocation switch.

Definition at line 116 of file crt0.c.

#define CRT0_CALL_DESTRUCTORS   TRUE

Destructors invocation switch.

Definition at line 123 of file crt0.c.