
I don"t understand this particular line of code:
ld %g7, [%g7]
This moves the value pointed to by %g7 into register %g7. %g7 points to the location that stores the address of _start. This is the address where u-boot is to be copied (the destination address).
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.
Yes, you are correct. %g7 points to where the (link time) address of _start is stored (not the current execution address of _start).
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?
This just lets you store u-boot in memory at any address. When you being execution, the code is simply copied to TEXT_BASE, that's all. This initial bsr just lets us know where we begin execution, the value in %g7 after the bsr is the target address plus 4.
Currently, for convenience and simplicity, the u-boot code, data, and command table are currently located contiguously.
There's no magic here ... just load the binary to some arbitrary address, then single step through the code -- it'll help you understand :-)
Best Regards, --Scott