Microchip Technology SW006021-1N User Manual
C Language Features
2012 Microchip Technology Inc.
DS52053B-page 229
The assembly code associated with ordinary functions is still placed in a “text” section,
but as there are now two pages of flash, we have to ensure that both pages can be
used. If each function was placed into the same section, they will be merged by the
linker and that section would grow until it is too large to fit into either page. To ensure
that all the “text” sections do not merge, each function is placed in its own unique num-
bered section: text0, text1, text2, etc. As these sections do not have the same
name, they will not be merged by the linker.
but as there are now two pages of flash, we have to ensure that both pages can be
used. If each function was placed into the same section, they will be merged by the
linker and that section would grow until it is too large to fit into either page. To ensure
that all the “text” sections do not merge, each function is placed in its own unique num-
bered section: text0, text1, text2, etc. As these sections do not have the same
name, they will not be merged by the linker.
The linker option to define the CODE class might now look like:
-ACODE=0-7ffhx2
which tells the linker that CODE represents two pages of memory: one from 0 to 7ffh and
another from 800h to fffh.
another from 800h to fffh.
This specification indicates that there is some sort of memory boundary that occurs at
address 800h (the devices internal memory page) and is very different to a class defi-
nition that reads -ACODE=0-fffh, which covers the same memory range, but which
does not have the boundary. The linker will try allocating each textx section to one
page (class memory range); if it does not fit, it will try the other.
address 800h (the devices internal memory page) and is very different to a class defi-
nition that reads -ACODE=0-fffh, which covers the same memory range, but which
does not have the boundary. The linker will try allocating each textx section to one
page (class memory range); if it does not fit, it will try the other.
If an interrupt function is encountered, the int_text section is selected for this code.
As this is separate to the sections used to hold ordinary functions, it can be linked
explicitly at the interrupt vector location. Assuming that the interrupt vector is at address
4, the linker option to locate this section might look like the following, see
Section 7.2.19 “-Pspec”.
As this is separate to the sections used to hold ordinary functions, it can be linked
explicitly at the interrupt vector location. Assuming that the interrupt vector is at address
4, the linker option to locate this section might look like the following, see
Section 7.2.19 “-Pspec”.
-pint_text=4h
For simplicity in this example, initialized variables are treated as they were in the pre-
vious example, even though there are now two RAM banks; i.e., they are always
allocated in the first bank of RAM.
vious example, even though there are now two RAM banks; i.e., they are always
allocated in the first bank of RAM.
In the previous example we ignored the code that would have copied the initial values
from flash into RAM. This code is executed after Reset and before the function main,
and forms part of the runtime startup code. It reads each initial value from flash and
writes this to the corresponding variable in the RAM space. Provided the order in which
the variables are allocated memory in RAM matches the order their initial values are
allocated in flash, a single loop can be used to perform the copy. Even though the vari-
ables might be defined at many places in the source code, the order in memory of each
variable and value will be preserved since the compiler uses sections to hold the code
associated with each.
from flash into RAM. This code is executed after Reset and before the function main,
and forms part of the runtime startup code. It reads each initial value from flash and
writes this to the corresponding variable in the RAM space. Provided the order in which
the variables are allocated memory in RAM matches the order their initial values are
allocated in flash, a single loop can be used to perform the copy. Even though the vari-
ables might be defined at many places in the source code, the order in memory of each
variable and value will be preserved since the compiler uses sections to hold the code
associated with each.
This runtime startup code is output into a section called init. Code which jumps to the
runtime startup codes is placed in the reset_vec section, which is linked to the Reset
location. By linking these sections in the same page, the jump from one section to
another will be shorter and faster. The linker options to make this happen might look
like:
runtime startup codes is placed in the reset_vec section, which is linked to the Reset
location. By linking these sections in the same page, the jump from one section to
another will be shorter and faster. The linker options to make this happen might look
like:
-preset_vec=0
-pinit=int_text
which says that the Reset vector code is linked to address 0 (which is the Reset vector
location) and that the init section, which contains the runtime startup code, should be
linked immediately after the interrupt code in the int_text section. If the int_text
section is empty; i.e., there is no interrupt code defined in the program, then init will
be placed at address 4.
location) and that the init section, which contains the runtime startup code, should be
linked immediately after the interrupt code in the int_text section. If the int_text
section is empty; i.e., there is no interrupt code defined in the program, then init will
be placed at address 4.