# Vault 7: Projects

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

### Protego

# MPLAB XC16 C-Compiler

- 1
- 2
…
- 163
- 164
- 165
- 166
- 167
…
- 365
- 366

Memory Allocation and Access
 2012-2013 Microchip Technology Inc. DS50002071C-page 165
10.9 ALLOCATION OF VARIABLES TO REGISTERS
You may specify a fixed register assignment for a particular C variable. It is not recom-
mended that this be done.
10.10 VARIABLES IN EEPROM
The compiler provides some convenience macro definitions to allow placement of data
into the devices EE data area. This can be done quite simply:
int _EEDATA(2) user_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
user_data will be placed in the EE data space (space(eedata)) reserving 10 words
with the given initial values.
The device provides two ways for programmers to access this area of memory. The first
is via the program space visibility window. The second is by using special machine
instructions (TBLRDx).
10.10.1 Accessing EEDATA via User Managed PSV
The compiler normally manages the PSV window to access constants stored in
program memory. If this is not the case, the PSV window can be used to access
EEDATA memory.
To use the PSV window:
 The psv page register must be set to the appropriate address for the program
memory to be accessed. For EE data this will be 0xFF, but it is best to use the
__builtin_psvpage() function.
 In some devices, the PSV window should also be enabled by setting the PSV bit
in the CORCON register. If this bit is not set, uses of the PSV window will always
read 0x0000.
EXAMPLE 10-1: EEDATA ACCESS VIA PSV
#include <xc.h>
int main(void) {
PSVPAG =
__builtin_psvpage(&user_data);
CORCONbits.PSV = 1;
/* ... */
if (user_data[2]) ;/* do something */
}
These steps need only be done once. Unless psv page is changed, variables in EE
data space may be read by referring to them as normal C variables, as shown in the
example.
Note: Using variables specified in compiler-allocated registers - fixed registers -
is usually unnecessary and occasionally dangerous. This feature is
deprecated and not recommended.
DD
Note: This access model is not compatible with the compiler-managed PSV
(-mconst-in-code) model. You should be careful to prevent conflict.

- 1
- 2
…
- 163
- 164
- 165
- 166
- 167
…
- 365
- 366