| __ld_insert_kernel_ram_calls

Previous | Automatically Inserted Section Contents | Next

__ld_insert_kernel_ram_calls can be used to handle RAM calls. It inserts references to RAM calls in the format used by kernels:

- If the program uses at least one RAM call...
  - 2 bytes: the number of different RAM calls minus 1
  - For each RAM call...
    - 2 bytes: RAM call information:
      - Bits 0 through 13: index
      - Bit 14: type (0: RAM call; 1: extra RAM address)
      - Bit 15: size (0: 4 bytes; 1: 2 bytes)
    - Relocation table for this RAM call:
      - For each reference...
        - 2 bytes: location (may not be 0)
      - 2 bytes: 0

If a program uses this insertion, it must process it as follows:

- For each RAM call...
  - For each relocation entry...
    - Get the starting address of the program (via __ld_entry_point);
    - Add the location value;
    - Modify the value (offset) at the resulting address (2 or 4 bytes depending on size):
      - If type indicates an extra RAM address:
        - Determine the location of the extra RAM table row indexed by index (see _extraram);
        - Get the correct value for the current calculator from this row;
        Else:
        - Get the address/value of the RAM function/variable indexed by index;
      - Add the value of offset;
      - Write the resulting address/value to the space covered by offset.

Before program termination, this process has to be reverted, so that it can be repeated the next time the program starts. Simply deactivating the relocation code would prevent programs from being transferred between devices.