In article <
[email protected]>,
[email protected] says...
My 1802 target for LCC just defines and initializes globals in the
static assembly so that, for example, if you restart it, the
original initializers are not refreshed. Is that standard C?
I'm working now on a target that splits the code off for ROM and I
need a way to initialize RAM globals.
For a stand-alone system it is not so much that the compiler does this,
as it is that you need to coordinate the compiler generated modules
with the linker and (custom?) libraries to get things where you want
them in ROM and RAM. You may need a 'program-launcher' routine (for
C run-time start-off / _crtso_()) like the following illustration -
---------------------------8>< snip here ---------------------------
#include "ROM_DEFS.h" // where ram_init_image blob is in ROM
#include "RAM_DEFS.h" // RAM init and zeroed bases & lengths
extern void main(void); // for stand-alone
void _crtso_(void) {
sys_start:
// power-up/reset comes here w/o stack call, frame, etc.
// may need to use assembly code to init stack pointer here
// here, all args are compile/link time constants -
memcopy(&init_ram_base, &ram_init_image, RAM_INIT_LENGTH);
memset(&zero_ram_base, 0, RAM_ZERO_LENGTH);
main(void); // perhaps sets-up interrupts
exit(void); // does not return
// never reached, so no return
}
void exit(void) {
while(1) ; // interrupts still running forever?
// never reached, so does not return
}
---------------------------8>< snip here ---------------------------
You need to put all your initiaized (RAM) globals into one (separate)
module, and compile/link it into a binary blob image to be placed
into ROM. Putting all your default-zeroed globals into their own
module helps make them into a contigious RAM block for memset().
You have to cover your own globals, and any in libraries too.
Code and read-only globals might be linked into ROM.
LCC needs you to do this manualy. Other compilers like SDCC try to
help you to specify them in the program source.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)