Psects are linked together and assigned addresses based on information
supplied to the linker via -Pspec
options. The argument to the
-P
option consists of comma-separated sequences with the form:
-Ppsect=linkaddr+min/loadaddr+min,psect=linkaddr/loadaddr,...
All values can be omitted, in which case a default will apply, depending on previous values. The link address of a psect is the address at which it can be accessed at runtime. The load address is the address at which the psect starts within the output file (HEX or binary file etc.), but it is rarely used by 8-bit PIC devices. The addresses specified can be numerical addresses, the names of other psects, classes, or special tokens.
Examples of the basic and most common forms of this option are:
-Ptext10=02000h
which places (links) the starting address of psect
text10
at address 0x2000;
-PmyData=AUXRAM
which places the psect myData
anywhere in the range of
addresses specified by the linker class AUXRAM
(which would need to be
defined using the -A
option, see A: Define Linker Class), and
-PstartCode=0200h,endCode
which places endCode
immediately after the end of
startCode
, which will start at address 0x200.
The additional variants of this option are rarely needed; but, are described below.
If a link or load address cannot be allowed to fall below a minimum
value, the +min
, suffix indicates the minimum address.
If the link address is a negative number, the psect is linked in reverse order with the top of the psect appearing at the specified address minus one. Psects following a negative address will be placed before the first psect in memory.
If the load address is omitted entirely, it defaults to the link
address. If the slash /
character is supplied with no address
following, the load address will concatenate with the load address of the previous
psect. For example, after processing the option:
-Ptext=0,data=0/,bss
the text
psect will have a link and load address of 0;
data will have a link address of 0 and a load address following that of text. The
bss
psect will concatenate with data in terms of both link and load
addresses.
A load address specified as a dot character, “.
” tells
the linker to set the load address to be the same as the link address.
The final link and load address of psects are shown in the map file (see Psect Information Listed By Module).