# Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

### Protego

# MPLAB XC16 C-Compiler

- 1
- 2
…
- 149
- 150
- 151
- 152
- 153
…
- 365
- 366

Memory Allocation and Access
 2012-2013 Microchip Technology Inc. DS50002071C-page 151
10.4 VARIABLES IN PROGRAM SPACE
The 16-bit core families of processors contain hardware support for accessing data
from within program Flash using a hardware feature that is commonly called Program
Space Visibility (PSV). More detail about how PSV works can be found in device data
sheets or family reference manuals. Also, see Section 10.4.1 Allocation and
Access of Program Memory Objects and Section 14.8.2 PSV Usage with Inter-
rupt Service Routines.
Briefly, the architecture allows the mapping of one 32K page of Flash into the upper
32K of the data address space via the Special Function Register (SFR) PSVPAG or
DSRPAG. By default the compiler only supports direct access to one single PSV page,
referred to as the auto_psv space. In this model, 16-bit data pointers can be used.
However, this can make it difficult to manage large amounts of constant data stored in
Flash on larger devices.
When the option -mconst-in-code is enabled, const-qualified variables that are
not auto are placed in program memory. Any auto variables qualified const are
placed on the stack along with other auto variables.
Any const-qualified (auto or non-auto) variable will always be read-only and any
attempt to write to these in your source code will result in an error being issued by the
compiler.
A const object is usually defined with initial values, as the program cannot write to
these objects at runtime. However this is not a requirement. An uninitialized const
object is allocated space along with other uninitialized RAM variables, but is still
read-only. Here are examples of const object definitions.
const char IOtype = A; // initialized const object
const char buffer[10]; // I reserve memory in RAM
See Chapter 16. Mixing C and Assembly Code for the equivalent assembly sym-
bols that are used to represent const-qualified variables in program memory.
10.4.1 Allocation and Access of Program Memory Objects
There are many objects that are allocated to program memory by the compiler. The fol-
lowing sections indicate those objects and how they are allocated to their final memory
location by the compiler and how they are accessed.
10.4.1.1 STRING AND CONST OBJECTS
By default, the compiler will automatically arrange for strings and const-qualified
initialized variables to be allocated in the auto_psv section, which is mapped into the
PSV window. Specify the -mconst-in-data option to direct the compiler not to use
the PSV window and these objects will be allocated along with other RAM-based vari-
ables.
In the default memory model, the PSV page is fixed to one page which is represented
by the auto_psv memory space. Accessing the single auto PSV page is efficient as
no page manipulation is required. Additional FLASH may be accessed using the tech-
niques introduced in section Section 10.4.2.1 Managed PSV Access.

- 1
- 2
…
- 149
- 150
- 151
- 152
- 153
…
- 365
- 366