A SERVICE OF

logo

CAVR-4
Part 1. Using the compiler
The DLIB runtime environment
81
Implementation of system startup code
This section presents some general techniques used in the system startup code, including
background information that might be useful if you need to modify it.
Note: Do not modify the file
cstartup.s90 unless required by your application. Your
first option should be to use a customized version of
__low_level_init for
initialization code.
The source files are well commented and are not described in detail in this guide.
For information about assembler source files, see the AVR® IAR Assembler Reference
Guide.
MODULES AND SEGMENT PARTS
To understand how the startup code is designed, you must have a clear understanding of
modules and segment parts, and how the IAR XLINK Linker treats them.
An assembler module starts with a
MODULE directive and ends with an ENDMOD directive.
Each module is logically divided into segment parts, which are the smallest linkable
units. There will be segment parts for constants, code bytes, and for reserved space for
data. Each segment part begins with an
RSEG directive.
When XLINK builds an application, it starts with a small number of modules that have
either been declared using the
__root keyword or have the program entry label
__program_start. The linker then continues to include all modules that are referred
from the already included modules. XLINK then discards unused segment parts.
Segment parts, REQUIRE, and the falling-through trick
The system startup code has been designed to use segment parts so that as little as
possible of unused code will be included in the linked application.
A piece of code or data is not included if it is not used or referred to. To make the linker
always include a piece of code or data, the assembler directive
REQUIRE can be used.
The segment parts defined in the system startup code are guaranteed to be placed
immediately after each other. There are two reasons for this. First, the alignment
requirement of the segment parts is every two bytes. Because the size of all assembler
instructions are multiples of two, this does not allow pad bytes to be placed between
code sections. Second, XLINK will not change the order of the segment parts or
modules, because the segments holding the system startup code are placed using the
-Z
option.