[U-Boot-Users] Relocation code on NIOS

Maksim Pyatkovskiy makspyat at sbcglobal.net
Mon Jul 5 18:58:06 CEST 2004

Good day,

I am trying to figure how does U-Boot relocates itself on Cyclone
Edition board (DK-1C20). Probably this should be an easy question for
most developers familiar with NIOS, but I can't find the answer
since I am new to this platform.

So, this is my question:

The following lines are located in the early beginning of start.s:

mov %g7, %o7 /* %o7 has return addr -- save in %g7 use later */


pfx %hi(__u_boot_cmd_end)
movi %g5, %lo(__u_boot_cmd_end)
pfx %xhi(__u_boot_cmd_end)
movhi %g5, %xlo(__u_boot_cmd_end) /* %g5 <- end address */

lsli %g7, 1 /* mem = retaddr << 1 */
mov %g6, %g7
subi %g6, 4 /* %g6 <- src addr */
ld %g7, [%g7] /* %g7 <- dst addr */

1: cmp %g7, %g5
skps cc_nz
br 2f
nop /* delay slot */

ld %g0, [%g6]
addi %g6, 4 /* src++ */
st [%g7], %g0
addi %g7, 4 /* dst++ */
br 1b
nop /* delay slot */

I don't understand this particular line of code:

ld %g7, [%g7]

Per my understanding, %g7 keeps the return address. This address
should point to the next instruction of code just after the delay slot
of CALL or BSR used to call u-boot.
So, if %g7 keeps this address, than [%g7] keeps the code (instruction
bytes) located by this address.
In this case "ld %g7, [%g7]" loads 4 bytes from code segment to the

Later this value (instruction bytes) is compared with %g5 that keeps
the end of data segment according to u-boot.lds. I can't understand
why code address is being compared with instruction bytes. Please
explain if possible - what does [%g7] keep and where am I wrong?

Thank you!

More information about the U-Boot mailing list