_compressed_format_relocs.s 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. | Copyright (C) 2002-2003 Sebastian Reichelt.
  2. | Copyright (C) 2003 Kevin Kofler.
  3. | See License.txt for licensing conditions.
  4. .xdef __handle_relocs_AND___compressed_format_relocs_AND___nostub,__ld_insert_compressed_relocs
  5. | This file requires cleanup code.
  6. .xdef __ref_all___complex_main
  7. .section _st15
  8. __compressed_format_relocs:
  9. | Relocate the program.
  10. lea.l __ld_insert_compressed_relocs(%pc),%a0
  11. lea.l __ld_entry_point(%pc),%a1
  12. move.l %a1,%d0
  13. move.l #__ld_compressed_relocs_ref-__ld_entry_point-4,%d1
  14. clr.w %d2
  15. __compressed_format_relocs_loop_1:
  16. bsr __decode_compressed_offset
  17. bcs.s __compressed_format_relocs_done_1
  18. add.l %d0,0(%a1,%d1.l)
  19. bra.s __compressed_format_relocs_loop_1
  20. __compressed_format_relocs_done_1:
  21. .section _st1090
  22. __compressed_format_relocs_cleanup:
  23. | Unrelocate the program.
  24. lea.l __ld_insert_compressed_relocs(%pc),%a0
  25. lea.l __ld_entry_point(%pc),%a1
  26. move.l %a1,%d0
  27. move.l #__ld_compressed_relocs_ref-__ld_entry_point-4,%d1
  28. clr.w %d2
  29. __compressed_format_relocs_loop_2:
  30. bsr __decode_compressed_offset
  31. bcs.s __compressed_format_relocs_done_2
  32. sub.l %d0,0(%a1,%d1.l)
  33. bra.s __compressed_format_relocs_loop_2
  34. __compressed_format_relocs_done_2:
  35. .section _st10000, "d"
  36. __ld_insert_compressed_relocs:
  37. | The format for the reloc table is as follows:
  38. /* The offset starts at __ld_entry_point - 4 bytes (the smallest encodable
  39. difference).
  40. 00: end of list
  41. 01-7F: add 004-100 (2(value+1)) to the previous offset to get the new one
  42. 80-BF: add 04-22 (2(nibble_value+2)). (Note that 01-7F can be used for
  43. that purpose as well if you are a lazy linker author. :-) But the
  44. nibble-encoding saves some space, so you'd better use it.)
  45. The bytes have the following values (the most significant nibble is
  46. the first one):
  47. Byte 1: n+6 (2+6=8 .. 5+6=B), first data nibble
  48. Byte 2: 2 data nibbles
  49. ...
  50. Byte n: 2 data nibbles
  51. Note that n = ([total number of data nibbles] + 1) / 2. It follows
  52. that the total number of data nibbles must be odd and >=3. Use
  53. byte-encoding (01-7F) otherwise (for all data if the number is <=2,
  54. for the last data nibble only if it is even and >=4). It also must
  55. not exceed 9 (5*2-1), in which case you need to split it up.
  56. C0-FF: the byte starts a full word: 0xC000+difference
  57. add 2(difference+0x81) to the previous offset to get the new one
  58. FFFF is special: it adds 0x80FC to the offset, but the computation
  59. does not stop here, instead another delta is added
  60. (NOTE: numbers below are decimal unless prefixed by "0x"!)
  61. In pseudo-code, this means:
  62. offset=__ld_entry_point-4;
  63. for each (byte) {
  64. switch (byte) {
  65. case 0: stop;
  66. case 0x01..0x7f:
  67. offset+=2*(byte+1);
  68. dump(offset);
  69. break;
  70. case 0x80..0xbf:
  71. n=(byte>>4)-6;
  72. offset+=2*((byte&7)+2);
  73. dump(offset);
  74. for(i=1;i<n;i++) {
  75. offset+=2*((byte>>4)+2);
  76. dump(offset);
  77. offset+=2*((byte&7)+2);
  78. dump(offset);
  79. }
  80. case 0xc0..0xff:
  81. complete the word;
  82. if (word==0xFFFF) {
  83. offset+=0x80FC;
  84. } else {
  85. offset+=2*(word-(0xC000-0x81));
  86. dump(offset);
  87. }
  88. }
  89. } */