Specifications
A Minimal PowerPCª Boot Sequence for
15
Executing Compiled C Programs
Sample Boot Sequence
The example .text section is located at 0xFFF0_0000 in the compiled image and at 0x0000_0000 after the
relocation. The sample boot code places its Þrst executable instruction at an offset of 0x0100 from the start
address using the .space assembler directive. This means that this Þrst instruction will be located at the
PowerPC system reset vector, 0xFFF0_0100, and it is executed when system reset occurs.
The text section is composed of the text, read-only data, and global offset table portions from the different
.o Þles. The symbols _img_text_start and _img_text_end are deÞned for use by the relocation code and refer
to the beginning and end addresses of the text section in the compiled image. The address of the text section
after the relocation is saved in _Þnal_text_start:
TEXT_START = DEFINED(TEXT_START)? TEXT_START: 0x00000000;
IMAGE_TEXT_START = DEFINED(IMAGE_TEXT_START)? IMAGE_TEXT_START:
0xFFF00000;
.text TEXT_START: AT (IMAGE_TEXT_START)
{
*(.text)
*(.rodata)
*(.rodata1)
*(.got1);
}
_img_text_start = LOADADDR(.text);
_img_text_end = (LOADADDR(.text) + SIZEOF(.text));
_final_text_start = ADDR(.text);
Note the use of the LOADADDR(), ADDR(), and SIZEOF() functions. These functions are built in to the
linker and are used to obtain information about the sections:
¥ LOADADDR() returns the absolute load address of the speciÞed section. This address corresponds
to the location of the section in the compiled image.
¥ The ADDR() function returns the location of the named section after relocation.
¥ SIZEOF() is used to determine the length of a section, in bytes.
In the sample shown above for the .text section, LOADADDR(.text) returns 0xFFF0_0000 and ADDR(.text)
returns 0x0000_0000 for the default case.
The data section of the linker script is a bit more complex since the location of the data section is dependent
upon the location and length of the text section. It contains all initialized, modiÞable data, including the
small data sections. If the data is relocated during the initialization sequence, its new location must speciÞed
so that references to variables refer to the relocated copy.
In this example, the data section is located immediately following the text section data, both in the compiled
image and after relocation:
DATA_START = DEFINED(DATA_START)? DATA_START: (((ADDR(.text) +
SIZEOF(.text)) & 0xFFFFFFE0) + 0x00000020);
IMAGE_DATA_START = DEFINED(IMAGE_DATA_START)? IMAGE_DATA_START:
(((LOADADDR(.text) + SIZEOF(.text)) & 0xFFFFFFE0) + 0x00000020);
.data DATA_START: AT (IMAGE_DATA_START)
{
_final_data_start = .;
*(.data)
*(.data1)
*(.sdata)
*(.sdata2)
*(.got.plt)
*(.got)