Specifications

14
A Minimal PowerPCª Boot Sequence for
Executing Compiled C Program
s
Sample Boot Sequence
The transition from .S and .c Þles to .o Þles is accomplished using gcc -c :
ppcinit.o: ppcinit.h ppcinit.S
$(CC) -c ppcinit.S
test.o: test.c
$(CC) -c test.c
$(CC) must be deÞned as the path to the cross-compiler. (See Part V, ÒSource Files,Ó Section 5.5,
ÒMakeÞle.Ó) Note that the assembly source Þle is named
ppcinit.S as opposed to ppcinit.s. This causes the
preprocessor
to run and strip out the C++ style comments. In the makeÞle, all references to test should be
changed to match the name of the user program to be linked with the boot program. The build command for
test should be changed to specify the appropriate dependencies and build options.
Once all source Þles have been compiled, the resultant object Þles must be linked together into an
executable. For this purpose, the GNU linker should be invoked with a custom linker control script. This
linker script speciÞes the starting address for the program, as well as the post-relocation addresses of the
text, data, and bss sections. In addition, it deÞnes symbols that are used by the relocation portion of the boot
sequence to determine the locations and lengths of the various sections as described in Table 8.
The linker script provides default values for IMAGE_TEXT_START (0xFFF0_0000),
TEXT_START(0x0000_0000), IMAGE_DATA_START, and DATA_START. The data section is located at
the Þrst appropriately aligned address following the text section. To change these defaults, the user may add
deÞnitions for these variables to the makeÞle, which passes these options to the linker when it is invoked.
Table 8. ld.Script Variables
Variable DeÞnition Value
_img_text_start The location of the start of the text section in the compiled
imageÑThis value is derived from the LOADADDR or the text
section.
IMAGE_TEXT_START
_img_text_end The location of the end of the text section in the ROM imageÑ
Derived from the LOADADDR of the text section and the size of
the text section.
_img_text_start +
SIZEOF(.text)
_Þnal_text_start The address of the start of the text section after relocationÑ
Derived from the ADDR speciÞed for the text section.
TEXT_START
_img_data_start The location of the start of the data section in the compiled
imageÑ This value is usually equal to the image address of the
start of the text section plus the size of the text section.
IMAGE_DATA_START, if
deÞned in MakeÞle;
(LOADADDR(.text) +
SIZEOF(.text)) by default
_Þnal_data_start The location of the start of the data section after relocationÑ
This value is usually equal to the post-relocation address of the
start of the text section plus the size of the text section.
DATA_START, if deÞned
in MakeÞle;
(ADDR(.text) +
SIZEOF(.text)) by default
_Þnal_data_end The location of the end of the data section after relocationÑThis
value is equal to the start of the data section plus the size of the
data section.
_Þnal_data_start +
SIZEOF(.data)
_bss_start The destination start address for the bss sectionÑTypically set
equal to the relocation address for the data section plus the
length of the data section.
ADDR(.data) +
SIZEOF(.data)
_bss_end The destination end address for the bss section. _bss_start +
SIZEOF(.bss)