| __ld_insert_preos_compressed_tables

Previous | Automatically Inserted Section Contents | Next

__ld_insert_preos_compressed_tables is the most complex of the automatic insertions. It inserts all relocation-related tables in the compressed format expected by PreOs 0.68 or higher. PreOs expects those tables to be pointed to by the same pointer, so they need to be inserted all at once. The reference address expected by PreOs is the same for all relocation tables: 36 (0x24). It is defined as the end address of the smallest possible header/stub combination. (However, the smallest possible stub is not usable in practice because it does not emit any error messages. Therefore, the address does not correspond to any actual address in TIGCCLIB, so it is hard-coded in the linker.) The tables it inserts are, in order:

- Library import table:
  - For each referenced library...
    - 8 bytes: library variable name
    - 1 byte: 0
    - 1 byte: minimum version number (see Minimum Library Versions)
  - For each referenced library (again)...
    - PreOs index (see below): number of imported functions/variables minus 1
    - For each imported function/variable...
      - PreOs index (see below): index of the function/variable (relative to the previous one)
      - Relocation table for this function/variable. See __ld_insert_compressed_relocs for the format used.
- ROM call import table:
  - PreOs index (see below): the number of different ROM calls minus 1
  - For each ROM call...
    - PreOs index (see below): index of the ROM call (relative to the previous one)
    - A compressed relocation table for this ROM call. See __ld_insert_compressed_relocs for the format used.
- RAM call import table, in the same format as the ROM call import table. The indices used are the indices after setting the size and type flags described under __ld_insert_kernel_ram_calls.
- Relocation table: See __ld_insert_compressed_relocs for the format used.
- BSS relocation table:
  - 2 bytes: BSS size / 4
  - A compressed relocation table. See __ld_insert_compressed_bss_refs for the format used.

PreOs uses a special format for the indices. It is not the same as for the relocation table. Instead, a PreOs index is encoded using one of the following formats:

- 1 byte: offset (must be between 0x00 and 0xFD)
- 2 bytes:
  - 1 byte: 0xFE
  - 1 byte: offset - 0xFE
- 3 bytes:
  - 1 byte: 0xFF
  - 2 bytes: index (not offset!)

where index is the actual index, and offset is index + 1 for the first index and the difference between index and the previous index for the following ones.
Note: Since parts of this insertion are dealing with relocs, the limitations of __ld_insert_kernel_relocs also apply to this insertion.

See also: __ld_insert_compressed_relocs, __ld_insert_compressed_rom_calls, __ld_insert_kernel_ram_calls, __ld_insert_compressed_bss_refs