# Vault 7: Projects

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

### Protego

# MPLAB XC16 C-Compiler

- 1
- 2
…
- 151
- 152
- 153
- 154
- 155
…
- 365
- 366

Memory Allocation and Access
 2012-2013 Microchip Technology Inc. DS50002071C-page 153
10.4.2 Access of objects in Program Memory
Allocating objects to program memory and accessing them are considered as two sep-
arate issues. The compiler requires that you qualify variables to indicate how they are
accessed. You can choose to have the compiler manage access of these objects, or
do this yourself, which can be more efficient, but more complex.
10.4.2.1 MANAGED PSV ACCESS
The compiler introduces several new qualifiers (CV-qualifiers for the language lawyers
in the audience). Like a const volatile qualifier, the new qualifiers can be applied
to objects or pointer targets. These qualifiers are:
 __psv__ for accessing objects that do not cross a PSV boundary, such as those
allocated in space(auto_psv) or space(psv)
 __prog__ for accessing objects that may cross a PSV boundary, specifically
those allocated in space(prog), but it may be applied to any object in Flash
 __eds__ for accessing objects that may be in FLASH or the extended data
space (for devices with > 32K of RAM), see __eds__ in Section 10.7 Extended
Data Space Access.
Typically there is no need to specify __psv__ or __prog__ for an object placed in
space(auto_psv).
Defining a variable in a compiler managed Flash space is accomplished by:
__psv__ unsigned int FLASH_variable __attribute__((space(psv)));
Reading from the variable now will cause the compiler to generate code that adjusts
the appropriate PSV page SFR as necessary to access the variable correctly. These
qualifiers can equally decorate pointers:
__psv__ unsigned int *pFLASH;
produces a pointer to something in PSV, which can be assigned to a managed PSV
object in the normal way. For example:
pFLASH = &FLASH_variable;
10.4.2.2 OBJECT COMPATIBILITY MODEL
Since functions in secure segments set PSVPAG to their respective psv constant sec-
tions, a convention must be established for managing multiple values of the PSVPAG
register. In previous versions of the compiler, a single value of PSVPAG was set during
program startup if the default constants-in-code memory model was selected. The
compiler relied upon that preset value for accessing const variables and string literals,
as well as any variables specifically nominated with space(auto_psv).
MPLAB XC16 provides support for multiple values of PSVPAG. Variables declared with
space(auto_psv) may be combined with secure segment constant variables and/or
managed psv variables in the same source file. Precompiled objects that assume a
single, pre-set value of PSVPAG are link-compatible with objects that define secure seg-
ment psv constants or managed psv variables.
Even though PSVPAG is considered to be a compiler-managed resource, there is no
change to the function calling conventions.

- 1
- 2
…
- 151
- 152
- 153
- 154
- 155
…
- 365
- 366