# Vault 7: Projects

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

### Protego

# MPLAB XC16 C-Compiler

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

MPLAB
®
XC16 C Compiler Users Guide
DS50002071C-page 154  2012-2013 Microchip Technology Inc.
10.4.2.3 ISR CONSIDERATIONS
A data access using managed PSV pointers is definitely not atomic, meaning it can
take several instructions to complete the access. Care should be taken if an access
should not be interrupted.
Furthermore an Interrupt Service Routine (ISR) never really knows what the current
state of the PSVPAG register will be. Unfortunately the compiler is not really in any posi-
tion to determine whether or not this is important in all cases.
The compiler will make the simplifying assumption that the writer of the interrupt service
routine will know whether or not the automatic, compiler managed PSVPAG is required
by the ISR. This is required to access any constant data in the auto_psv space or any
string literals or constants when the default -mconst-in-code option is selected.
When defining an interrupt service routine, it is best to specify whether or not it is nec-
essary to assert the default setting of the PSVPAG SFR.
This is achieved by adding a further attribute to the interrupt function definition:
 auto_psv - the compiler will set the PSVPAG register to the correct value for
accessing the auto_psv space, ensuring that it is restored when exiting the ISR
 no_auto_psv - the compiler will not set the PSVPAG register
For example:
void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void) {
IFS0bits.T1IF = 0;
}
The choice is provided so that, if you are especially conscious of interrupt latency, you
may select the best option. Saving and setting the PSVPAG will consume approximately
3 cycles at the entry to the function and one further cycle to restore the setting upon
exit from the function.
Note that boot or secure interrupt service routines will use a different setting of the
PSVPAG register for their constant data.
10.4.3 Size Limitations of Program Memory Variables
Arrays of any type (including arrays of aggregate types) can be qualified const and
placed in the program memory. So too can structure and union aggregate types, see
Section 8.6 Structures and Unions. These objects can often become large in size
and may affect memory allocation.
For objects allocated in a compiler-managed PSV window (auto_psv space) the total
memory available for allocation is limited by the size of the PSV window itself. Thus no
single object can be larger than the size of the PSV window, and all such objects must
not total larger than this window.
The variables allocated to program memory are subject to similar constraints as data
space objects in terms of maximum size, but they are allocated to the larger program
space rather than data space memory. Section 10.3.1.3 Non-Auto Variable Size
Limits which describes defining and using large arrays is also applicable to objects in
program space memory.

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