background:
flash at 0x02000000/2M, SDRAM at 0x10000/16M, processor: ks8695.
the Bootloader and OS are burned into the flash, when resetting, OS is copied to SDRAM at address 0x10000, then set PC(program counter) to 0x10000 (that is, run the OS).
since the PC is set to 0x10000(since the processor can execute the first instruction of OS at this point), why is it necessary to specify the absolute address of the Text Section of the OS(through setting -Ttext=0x10000) when linking it? (when I set -Ttext to 0x0, the OS won’t run properly).
Best regards,
wenlujon
Your PC is at 0x10000, so you have to link it at 0x10000, because your code is doing absolute addressing.
The bootloader is not doing any linking or symbol resolution, it is just copying some binary blob to 0x10000 and then setting the PC to 0x10000. So your code has to be prepared to run at 0x10000, that is why you need to specify this in the linker.
function call are usually done using PC relative addressing, but this is not necessary the case when you want to have access to data. Assume you have a table T. If you are linked at 0x0, and your table is at 0x1234. You may have some instruction that refer to this address.
Now you move your code to 0x10000. Your table address is now 0x11234, but your code does not now it has been moved, so it tries to load data at 0x1234, where there is nothing, or crap.
Now when you link your code with an offset, the set of instruction that was used to access T is modified accordingly. That is all what linking is for, resolving symbol into adrresses !