[U-Boot-Users] why jump at absolute address in start.S

Murray Jensen Murray.Jensen at csiro.au
Fri Jan 3 07:15:14 CET 2003


On Fri, 03 Jan 2003 11:47:22 +0800, Laudney Ren <bren at sjtu.edu.cn> writes:
>I'm reading cpu/mpc8xx/start.S and found the following:
>
>        /*
>          * Calculate absolute address in FLASH and jump there
>          */
>
>         lis     r3, CFG_MONITOR_BASE at h
>         ori     r3, r3, CFG_MONITOR_BASE at l
>         addi    r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
>         mtlr    r3
>         blr
>
>Why do we need to calculate the absolutely address?
>Why should we do it here, instead of everywhere?

U-Boot (aka ppcboot - since you are looking at cpu/mpc8xx) is compiled using
the "-mrelocatable" flag i.e. my understanding of this is that all text
references will be relative so that the code may be relocated at run time.

The bit of code above is special - at this point the CPU will be executing
at whatever address the reset configuration dictates (for 8xx I think the CPU
will read from the data bus at hard reset, which the board designer will have
wired up for you - I forget what the options are, but just assume the address
will be somewhere that you don't want it to be :-). In addition, the memory
controller will be set up so that the boot device (e.g. flash) appears
repeated throughout the entire physical address space (see the hard reset
state of OR0/BR0).

CFG_MONITOR_BASE is the physical address where you want the boot device to
reside. It will be used to program the memory controller registers which
select the boot device (OR0/BR0). As soon as the mask in OR0 is programmed
correctly, the boot device will disappear from the entire address space, and
be accessible only at the base address programmed in BR0.

This code jumps to the address that the boot device will appear at after you
program the memory controller registers, so that the boot device will not
disappear out from underneath you.

Because the code is relocatable you can jump to any address you like - as
long as the offset within the boot device is correct. "_start" is the address
where the CPU will "start" execution - i.e. the hard reset vector. "in_flash"
is where we want to continue execution after the jump (its the next instruction
after the "blr" above - therefore this really isn't a jump because you simply
execute the next instruction). EXC_OFF_SYS_RESET is added because we need the
address to be relative to the start of the boot device, not the hard reset
vector.

I think I got in over my head here - I started out trying to keep this answer
simple, but there is too much background you need to know to understand this
code. The 8xx (and 8260) are very configurable - there are other ways you
could do this, this is just the way ppcboot decided to do it. This code will
work regardless of the hardware reset configuration - so I quite like it.

I hope I've helped rather than hindered :-) In particular, I hope I've got
all the above correct - I'm sure someone will correct me if I'm wrong.
Cheers!
								Murray...
--
Murray Jensen, CSIRO Manufacturing & Infra. Tech.      Phone: +61 3 9662 7763
Locked Bag No. 9, Preston, Vic, 3072, Australia.         Fax: +61 3 9662 7853
Internet: Murray.Jensen at csiro.au

Hymod project: http://www.msa.cmst.csiro.au/projects/Hymod/

To the extent permitted by law, CSIRO does not represent, warrant and/or
guarantee that the integrity of this communication has been maintained or
that the communication is free of errors, virus, interception or interference.

The information contained in this e-mail may be confidential or privileged.
Any unauthorised use or disclosure is prohibited. If you have received this
e-mail in error, please delete it immediately and notify Murray Jensen on
+61 3 9662 7763. Thank you.




More information about the U-Boot mailing list