Specifications
24 A Minimal PowerPCÂȘ Boot Sequence for
Executing Compiled C Programs
Source Files
//---------------------------------------------------------------------------
// Label: relocate_image
//
// copy this image and the user code into RAM space.
// Note that the starting locations of text, data, and bss are
// defined in the ld.script. Make sure these definitions,
// as well as the definition for STACK_LOC in ppcinit.h, give
// ample room for your image.
//---------------------------------------------------------------------------
relocate_image:
addis r3,0,_img_text_start@h
ori r3,r3,_img_text_start@l
addis r4,0,_final_text_start@h
ori r4,r4,_final_text_start@l
// are they the same? No need to relocate if so
cmp 0,0,r3,r4
beq relocate_data
addis r7,0,_img_text_end@h
ori r7,r7,_img_text_end@l
cont:
lwzx r5,0,r3
stwx r5,0,r4
lwzx r8,0,r4
cmp 0,0,r8,r5
bne error
addi r4,r4,4
addi r3,r3,4
cmp 0,0,r3,r7
ble cont
relocate_data:
addis r3,0,_final_data_start@h
ori r3,r3,_final_data_start@l
addis r7,0,_final_data_end@h
ori r7,r7,_final_data_end@l
addis r4,0,_img_data_start@h
ori r4,r4,_img_data_start@l
cmp 0,0,r3,r4 // is the data not relocated?
beq clear_bss // if not, go do the bss