Vault 7: Projects

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

Deprecated Features
2012-2013 Microchip Technology Inc. DS50002071C-page 297
A function that can alter the value of a global register variable cannot safely be called
from a function compiled without this variable, because it could clobber the value the
caller expects to find there on return. Therefore, the function that is the entry point into
the part of the program that uses the global register variable must explicitly save and
restore the value that belongs to its caller.
The library function longjmp will restore to each global register variable the value it
had at the time of the setjmp.
All global register variable declarations must precede all function definitions. If such a
declaration appears after function definitions, the register may be used for other
purposes in the preceding functions.
Global register variables may not have initial values, because an executable file has no
means to supply initial contents for a register.
F.3.2 Specifying Registers for Local Variables
You can define a local register variable with a specified register like this:
register int *foo asm ("w8");
Here w8 is the name of the register that should be used. Note that this is the same
syntax used for defining global register variables, but for a local variable it would appear
within a function.
Defining such a register variable does not reserve the register; it remains available for
other uses in places where flow control determines the variables value is not live.
Using this feature may leave the compiler too few available registers to compile certain
functions.
This option does not ensure that the compiler will generate code that has this variable
in the register you specify at all times. You may not code an explicit reference to this
register in an asm statement and assume it will always refer to this variable.
Assignments to local register variables may be deleted when they appear to be
unused. References to local register variables may be deleted, moved or simplified.
F.4 CHANGING NON-AUTO VARIABLE ALLOCATION
Another way to locate data is by placing the variable into a user-defined section, and
specifying the starting address of that section in a custom linker script. This is done as
follows:
1. Modify the data declaration in the C source to specify a user-defined section.
2. Add the user-defined section to a custom linker script file to specify the starting
address of the section.
For example, to locate the variable Mabonga at address 0x1000 in data memory, first
declare the variable as follows in the C source:
int __attribute__((__section__(".myDataSection"))) Mabonga =
1;
The section attribute specifies that the variable should be placed in a section
named.myDataSection, rather than the default .data section. It does not specify
where the user-defined section is to be located. Again, that must be done in a custom
linker script, as follows. Using the device-specific linker script as a base, add the fol-
lowing section definition:
.myDataSection 0x1000 :
{
*(.myDataSection);
} >data

e-Highlighter

Click to send permalink to address bar, or right-click to copy permalink.

Un-highlight all Un-highlight selectionu Highlight selectionh