2 * idata.c - startup code evaluating gputils' cinit structure
4 * This code fragment copies initialized data from ROM to their
5 * assigned RAM locations. The requierd cinit structure is created
6 * by gputils' linker and comprises initial values of all linked in
9 * (c) 2007 by Raphael Neider <rneider @ web.de>
11 * This file is part of SDCC's pic14 library and distributed under
12 * the terms of the GPLv2 with linking exception; see COPYING in some
13 * parent directory for details.
17 * We call the user's main() after initialization is done.
19 extern void main(void);
22 * Force generation of _cinit symbol.
24 static char force_cinit = 0;
27 * This struct describes one initialized variable.
30 unsigned src; // source address of data in CODE space
31 unsigned dst; // destination address of values in DATA space
32 unsigned size; // number of bytes to copy from `src' to `dst'
36 * This structure provides the number and position of the above
37 * structs. to initialize all variables in the .hex file.
39 extern __code struct {
40 unsigned records; // number of entries in this file
41 cinit_t entry[]; // intialization descriptor
45 * Iterate over all records and copy values from ROM to RAM.
48 _sdcc_gsinit_startup(void)
56 cptr = &cinit.entry[0];
58 // iterate over all cinit entries
61 src = (__code char *) cptr->src;
62 dst = (__data char *) cptr->dst;
64 // copy data byte-wise from ROM to RAM
71 // XXX: might need to clear the watchdog timer here...
75 // call main after initialization