Microchip Technology SW006022-1N Data Sheet
Memory Allocation and Access
2012 Microchip Technology Inc.
DS52071B-page 127
7.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.
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.
7.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:
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 7.7 “Extended
Data Space Access”.
Data Space Access”.
Typically there is no need to specify __psv__ or __prog__ for an object placed in
space(auto_psv)
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:
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:
object in the normal way. For example:
pFLASH = &FLASH_variable;
7.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).
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)
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.
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.
change to the function calling conventions.