Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual

Product codes
SW006021-1
Page of 518
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.
The entire STATUS register is saved to an assembly variable ___resetbits. This 
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:
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. SeSection 5.12.3.1 “Equivalent 
Assembly Symbols”
 f
or more details of the mapping.
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.
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
 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.
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
 directive (if used). See Section 6.4.9.2 “END” for more information on this 
assembler directive.