LoadSeg
LoadSeg
Load a code segment into memory short segNo ; resource ID of a 'CODE' resource
LoadSeg is called indirectly whenever a call is made to a routine in a code segment that is not in memory. It loads the specified segment and updates the
jump table.
segNo is the segment number of the segment you wish to load. The segment
will be loaded into memory and locked.
Notes: There is a limit to the number of jump table entries the Segment Loader
can have. Since the 68000 uses signed 16-bit offsets for A5- relative
instructions, the maximum offset is 32767. Since each jump table entry
takes up 8 bytes, there can only be 4096 jump table entries, but we need to
subtract the 16 bytes used by the jump table header, so the actual limit is
4094.
Although this limit may seem rather small, you have to remember that
jump table entries only occur if a function is called from outside its own
segment (an intersegment call). For routines that are local to a segment
(an intrasegment call) the linker can call the routine without going through
the jump table.
A few tips on how to cut down the number of jump table entries:
• Segment your code according to its run-time calling chain, rather than
on a file basis.
• Keep utility routines in the same segment as the code that uses them
rather in a separate segment.
• Try to keep your segments close to the maximum size.
Because of the nature of LoadSeg and the structure of the jump table, LoadSeg trashes the first two bytes of a jump table entry before loading a segment. This is important to keep in mind if you ever attempt to do a
LoadSeg on anything that is not a jump table entry.