Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual
Product codes
SW006021-1
C Language Features
2012 Microchip Technology Inc.
DS52053B-page 197
5.10.1.4
STATUS REGISTER PRESERVATION
The resetbits suboption of the --RUNTIME option (see 4.8.50 “--RUNTIME: Spec-
ify Runtime Environment”) preserves some of the bits in the STATUS register before
being clobbered by the remainder of the runtime startup code. The state of these bits
can be examined after recovering from a Reset condition to determine the cause of the
Reset.
ify Runtime Environment”) preserves some of the bits in the STATUS register before
being clobbered by the remainder of the runtime startup code. The state of these bits
can be examined after recovering from a Reset condition to determine the cause of the
Reset.
The entire STATUS register is saved to an assembly variable ___resetbits. This
variable can be accessed from C code using the declaration:
variable can be accessed from C code using the declaration:
extern unsigned char __resetbits;
The compiler defines the assembly symbols ___powerdown and ___timeout to rep-
resent the bit address of the Power-down and Time-out bits within the STATUS register
and can be used if required. These can be accessed from C code using the
declarations:
resent the bit address of the Power-down and Time-out bits within the STATUS register
and can be used if required. These can be accessed from C code using the
declarations:
extern bit __powerdown;
extern bit __timeout;
In the above symbols, note that the C variables use two leading underscore characters,
and the assembly equivalent symbols use three. See Section 5.12.3.1 “Equivalent
Assembly Symbols” for more details of the mapping.
and the assembly equivalent symbols use three. See Section 5.12.3.1 “Equivalent
Assembly Symbols” for more details of the mapping.
See Section 4.9 “MPLAB IDE V8 Universal Toolsuite Equivalents” for use of this
option in MPLAB IDE.
option in MPLAB IDE.
5.10.2
The Powerup Routine
Some hardware configurations require special initialization, often within the first few
instruction cycles after Reset. To achieve this there is a hook to the Reset vector pro-
vided via the powerup routine.
instruction cycles after Reset. To achieve this there is a hook to the Reset vector pro-
vided via the powerup routine.
This routine can be supplied in a user-defined assembler module that will be executed
immediately after Reset. A template powerup routine is provided in the file pow-
erup.as
immediately after Reset. A template powerup routine is provided in the file pow-
erup.as
which is located in the sources directory of your compiler distribution. Refer
to comments in this file for more details.
The file should be copied to your working directory, modified and included into your
project as a source file. No special linker options or other code is required. The compiler
will detect if you have defined a powerup routine and will automatically use it, provided
the code in this routine is contained in a psect called powerup.
project as a source file. No special linker options or other code is required. The compiler
will detect if you have defined a powerup routine and will automatically use it, provided
the code in this routine is contained in a psect called powerup.
For correct operation (when using the default compiler-generated runtime startup
code), the code must end with a GOTO instruction to the label called start. As with all
user-defined assembly code, any code inside this file must take into consideration pro-
gram memory paging and/or data memory banking, as well as any applicable errata
issues for the device you are using. The program’s entry point is already defined by the
runtime startup code, so this should not be specified in the power-up routine with the
END
code), the code must end with a GOTO instruction to the label called start. As with all
user-defined assembly code, any code inside this file must take into consideration pro-
gram memory paging and/or data memory banking, as well as any applicable errata
issues for the device you are using. The program’s entry point is already defined by the
runtime startup code, so this should not be specified in the power-up routine with the
END
directive (if used). See Section 6.4.9.2 “END” for more information on this
assembler directive.