This tip has been extracted from the full Finding the Cause of Reset article.
The Microchip baseline and mid-range PIC® MCU devices employ a special feature that lets you establish the cause of a device reset once your program has restarted. This feature uses two bits in the STATUS register, namely the PD bit, which is set on power-up and cleared when SLEEP is invoked; and the TO bit, which is cleared if a watchdog time-out occurred and caused a device wake-up.
Since the content of the STATUS register could be lost before your code can access it, the MPLAB® XC8 C Compiler provides a feature which can automatically copy the STATUS register to a location that can be accessed from C code at a later time. This step takes place at the beginning of the runtime startup code, and so it will be executed shortly after the reset has taken place.
To access the saved content of the STATUS register, your C code should declare and reference the symbol __resetbits (note the two leading underscores). You can also declare and reference the symbols __powerdown and __timeout, which hold copies of the Power-down and Time-out bits, respectively. If required, declare these as follows in your program.
This STATUS register preservation feature is automatically enabled once you access any of the above symbols in your project.