The initial setting routine (PowerOn_Reset_PC) is a function that contains the procedures required before and after executing the main function. Processings required in the initial setting routine are described below in order.
The PSW register necessary for performing the initial setting processing is initialized. For example, disabling interrupts is set in PSW during the initial setting processing to prevent from accepting interrupts.
All bits in PSW are initialized to 0 at a reset, and the interrupt enable bit (I bit) is also initialized to 0 (interrupt disabled state).
The stack pointer (USP register and ISP register) is initialized. The #pragma entry declaration for the PowerOn_Reset_PC function makes the compiler automatically create the ISP/USP initialization code at the beginning of the function.
This procedure does not have to be written because the PowerOn_Reset_PC function is declared by #pragma entry.
When the base option is used in the compiler, general registers used as base addresses in the entire program need to be initialized. The #pragma entry declaration for the PowerOn_Reset_PC function makes the compiler automatically create the initialization code for each register at the beginning of the function.
This procedure does not have to be written because the PowerOn_Reset_PC function is declared by #pragma entry.
The address of the variable vector table is written to INTB. FINTV, FPSW, BPC, BPSW, EXTB, and DPSW are also initialized as required. These registers can be initialized using the intrinsic functions of the compiler.
Note however that only PSW is not initialized because it holds the interrupt mask setting.
The initialization routine for RAM area sections (_INITSCT) is called. Uninitialized data sections are initialized to zero. For initialized data sections, the initial values of the ROM area are copied to the RAM area. _INITSCT is provided as a standard library.
The user needs to write the sections to be initialized to the tables for section initialization (DTBL and BTBL). The section address operator is used to set the start and end addresses of the sections used by the _INITSCT function.
Section names in the section initialization tables are declared, using C$BSEC for uninitialized data areas, and C$DSEC for initialized data areas.
A coding example is shown below.
The routine for performing necessary initialization processing (_INITLIB) is called when the C/C++ library functions are used.
In order to set only those values which are necessary for the functions that are actually to be used, please refer to the following guidelines.
When an initial setting is required in the prepared low-level interface routines, the initial setting (_INIT_LOWLEVEL) in accordance with the specifications of the low-level interface routines is necessary. |
When using the rand function or strtok function, initial settings other than those for standard I/O (_INIT_OTHERLIB) are necessary. |
An example of a program to perform initial library settings is shown below.
Specify the filename for the standard I/O file. This name is used in the low-level interface routine "open". |
In the case of a console or other interactive device, a flag is set to prevent the use of buffering. |
When developing a C++ program, the routine (_CALL_INIT) for calling the constructor of a class object that is declared as global is called. _CALL_INIT is provided as a standard library.
The PSW register is initialized. The interrupt mask setting is canceled here.
After a reset, operation is in privileged mode (PM bit in PSW is 0). To switch to user mode, intrinsic function chg_pmusr is executed.
When using the chg_pmusr function, some care should be taken. Refer to the description of chg_pmusr in 4.2.6 Intrinsic Functions.
The main function is executed.
When developing a C++ program, the routine (_CALL_END) for calling the destructor of a class object that is declared as global is called. _CALL_END is provided as a standard library.