Node:C Code restrictions, Next:Stack growth direction, Previous:C Code Macros, Up:Simple instructions
Vmgen generates code and performs some optimizations under the assumption that the user-supplied C code does not access the stack pointers or stack items, and that accesses to the instruction pointer only occur through special macros. In general you should heed these restrictions. However, if you need to break these restrictions, read the following.
Accessing a stack or stack pointer directly can be a problem for several reasons:
IF_spTOS(sp[...] = spTOS);
) at
the start and reloading code (e.g., IF_spTOS(spTOS = sp[0])
) at
the end of problematic C code. Vmgen inserts a stack pointer update
before the start of the user-supplied C code, so the flushing code has
to use an index that corrects for that. In the future, this flushing
may be done automatically by mentioning a special string in the C code.
You should access the instruction pointer only through its special
macros (IP
, SET_IP
, IPTOS
); this ensure that these
macros can be implemented in several ways for best performance.
IP
points to the next instruction, and IPTOS
is its
contents.