insert_kernel_relocs.hss 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. [Main]
  2. Title=__ld_insert_kernel_relocs
  3. See Also=insert_kernel_bss_refs: __ld_insert_kernel_bss_refs, insert_kernel_data_refs: __ld_insert_kernel_data_refs, insert_mlink_relocs: __ld_insert_mlink_relocs, insert_compressed_relocs: __ld_insert_compressed_relocs
  4. [Top]
  5. Relocation entries indicate that the program needs to know some addresses
  6. which are only available at run time. In this case, the addresses referred
  7. to are locations inside the program code or data. Usually, all references to
  8. absolute addresses inside the program are inserted into the section if one
  9. of these two insertions is used; however, sections may be marked as being
  10. handled in another way, which prevents relocation entries to them from being
  11. output in this way. The data section is automatically marked as handled if
  12. it is externalized; the BSS section is marked as handled by referencing
  13. <A HREF="$$LINK(symbols_ld_kernel_bss_table)">__ld_kernel_bss_table</A>, by
  14. using
  15. <A HREF="$$LINK(insert_kernel_bss_refs)">__ld_insert_kernel_bss_refs</A>
  16. before inserting the relocation entries, or by reacting to the
  17. <A HREF="$$LINK(global_imports_auto)">__handle_bss</A> global import.
  18. <BR><BR>
  19. __ld_insert_kernel_relocs uses the kernel format for storing relocation
  20. entries, which is used by kernels on the TI-89, TI-92 Plus, and V200, and by
  21. Fargo v0.2.0:
  22. <UL>
  23. <LI>For each relocation entry...
  24. <UL>
  25. <LI><B>2 bytes:</B> <I>location</I> (may not be 0)</LI>
  26. </UL></LI>
  27. <LI><B>2 bytes:</B> 0</LI>
  28. </UL>
  29. If a program uses this insertion, it must process it as follows:
  30. <UL>
  31. <LI>For each relocation entry...
  32. <UL>
  33. <LI>Get the starting address of the program (via
  34. <A HREF="$$LINK(symbols_ld_entry_point)">__ld_entry_point</A>);</LI>
  35. <LI>Add the <I>location</I> value;</LI>
  36. <LI>Modify the 4-byte value (<I>offset</I>) at the resulting address:
  37. <UL>
  38. <LI>Get the starting address of the program (<I>relocation
  39. address</I>);</LI>
  40. <LI>Add the value of <I>offset</I>;</LI>
  41. <LI>Write the resulting address to the 4-byte space covered by
  42. <I>offset</I>.</LI>
  43. </UL></LI>
  44. </UL></LI>
  45. </UL>
  46. Before program termination, this process has to be reverted, so that it can
  47. be repeated the next time the program starts. Since programs may be moved in
  48. memory while they are not executed, they may <I>not</I> simply deactivate
  49. the relocation code. This would also prevent programs from being transferred
  50. between devices.
  51. <BR><BR>
  52. <B>Note:</B> Relocation entries may only be inserted at a single place in the
  53. program. The reason for this is that the linker may have to add new
  54. relocation entries after they have been written into the section. Instead of
  55. keeping track of which entries have already been processed, we thought it
  56. would be easier to remove them once they have been written into a section.
  57. Also, it is dangerous to use this insertion from anything other than a
  58. startup section.