6.1.8 G: Use Alternate Segment Selector
When linking programs using segmented, or bank-switched psects, there are two ways the linker can assign segment addresses, or selectors, to each segment. A segment is defined as a contiguous group of psects where each psect in sequence has both its link and load addresses concatenated with the previous psect in the group. The segment address or selector for the segment is the value derived when a segment type relocation is processed by the linker.
By default the segment selector is generated by dividing the base load
address of the segment by the relocation quantum of the segment, which is based on the
reloc=
flag value given to psects at the assembler level (see 4.9.47.16 Reloc Flag). The
-Gspec
option allows an alternate method for calculating
the segment selector. The argument to -G
is a string similar to:
A/10h-4h
where A
represents the load address of the
segment and /
represents division. This means “Take the load address of
the psect, divide by 10 HEX, then subtract 4.” This form can be modified by substituting
N
for A
, *
for /
(to represent multiplication) and adding, rather than subtracting, a constant. The token
N
is replaced by the ordinal number of the segment, which is
allocated by the linker. For example:
N*8+4
means “take the segment number, multiply by 8, then add 4.” The result is the segment selector. This particular example would allocate segment selectors in the sequence 4, 12, 20, ... for the number of segments defined.
The selector of each psect is shown in the map file (see Section 6.4.2.2 “Psect Information Listed by Module”).