Runtime Startup Code

A C program requires certain objects to be initialized and the device to be in a particular state before it can begin execution of its function main(). It is the job of the runtime startup code to perform these tasks, specifically (and in no particular order):

Rather than the traditional method of linking in a generic, precompiled routine, MPLAB XC8 determines what runtime startup code is required from the user’s program. Details of the files used and how the process can be controlled are described in Startup and Initialization. The following sections detail the tasks performed by the runtime startup code.

The runtime startup code assumes that the device has just come out of Reset and that registers will be holding their power-on-reset value. If your program is an application invoked by a bootloader that will have already executed, you might need to ensure that data bank 0 is selected so that the runtime startup code executes correctly. This can be achieved by placing the appropriate code sequence towards the end of the bootloader as in-line assembly.

The following table lists the significant assembly labels used by the startup and powerup code.

Table 1. SIGNIFICANT ASSEMBLY LABELS
Label Location
reset_vec at the Reset vector location (0x0)
powerup the beginning of the powerup routine, if used
start the beginning of the runtime startup code, in startup.s
start_initialization the beginning of the C initialization startup code, in the C output code