A.5.3 Transferring Variables with Initial Values from ROM to RAM

The _INITSCT function in the resetprg.c file of the startup routine is used to transfer variables with initial values from ROM to RAM. To add a section to be transferred, add the following description to the dbsct.c file.

[Example]

<dbsct.c>
...
#pragma section C C$DSEC
extern const struct {
     _UBYTE *rom_s;       /* Start address of the initialized data section in ROM */
     _UBYTE *rom_e;       /* End address of the initialized data section in ROM */
     _UBYTE *ram_s;       /* Start address of the initialized data section in RAM */
}   _DTBL[] = {
     { __sectop("D"), __secend("D"), __sectop("R") },
     { __sectop("D_2"), __secend("D_2"), __sectop("R_2") },
     { __sectop("D_1"), __secend("D_1"), __sectop("R_1") }
};
...

In the above example, the addresses used in the INITSCT function are stored in the table in order to transfer the contents of the D, D_2, and D_1 sections to the R, R_2, and R_1 sections. Note that the location addresses of the D, D_2, D_1, R, R_2, and R_1 sections should be specified by the
-start option of the optimizing linkage editor. The relocation solution by transferring data from ROM to RAM should be specified by the -rom option of the optimizing linkage editor.