[Main]
Title=__ld_insert_kernel_rom_calls
See Also=insert_mlink_rom_calls: __ld_insert_mlink_rom_calls, insert_compressed_rom_calls: __ld_insert_compressed_rom_calls

[Top]
__ld_insert_kernel_rom_calls can be used to handle
<A HREF="$$LINK(symbols_rom_call)">ROM calls</A>. It inserts references to
ROM calls in the format used by kernels:
<UL>
<LI>If the program uses at least one ROM call...
    <UL>
    <LI><B>2 bytes:</B> the number of different ROM calls minus 1</LI>
    <LI>For each ROM call...
        <UL>
        <LI><B>2 bytes:</B> <I>index</I> of the ROM call</LI>
        <LI>Relocation table for this ROM call:
            <UL>
            <LI>For each reference...
                <UL>
                <LI><B>2 bytes:</B> <I>location</I> (may not be 0)</LI>
                </UL></LI>
            <LI><B>2 bytes:</B> 0</LI>
            </UL></LI>
        </UL></LI>
    </UL></LI>
</UL>
If a program uses this insertion, it must process it as follows:
<UL>
<LI>For each ROM call...
    <UL>
    <LI>For each relocation entry...
        <UL>
        <LI>Get the starting address of the program (via
            <A HREF="$$LINK(symbols_ld_entry_point)">__ld_entry_point</A>);</LI>
        <LI>Add the <I>location</I> value;</LI>
        <LI>Modify the 4-byte value (<I>offset</I>) at the resulting address:
            <UL>
            <LI>Get the address of the ROM function/variable indexed by
                <I>index</I>;</LI>
            <LI>Add the value of <I>offset</I>;</LI>
            <LI>Write the resulting address to the 4-byte space covered by
                <I>offset</I>.</LI>
            </UL></LI>
        </UL></LI>
    </UL></LI>
</UL>
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.
