How to make runimm work

What is the context of vm?

The state of vm consists of: ip, fp, sp, reg.

ip      is local to vm, hence reentranceable.
fp,sp   are global. They are used in LIFO manner.
reg     must be saved/restored.

"runim" works this way:

[sys_cs]                    [user_cs]

compiler                   user programs

runim    --- eval (1) -->   ...

loadfile <-- eval (2) ---  syscall load fn
stop     --- stop (3) -->   ...

         <-- stop (4) ---  stop
                     
1.  "runim" initiates "eval" (1) (by syscall eval) so the context is switched to user (user_cs) and a number of registers must be saved.  This number depends on how many registers the immediate line of the user program is required.  It is known when genex the im. line.  Now vm runs code in user_cs.

2.  "load" in the user program initiates call to "loadfile" in the compiler object (via syscall load fn) (2).  The context is switched back to sys_cs.  No register is required to be saved as the vm will execute only a simple sequence: call 1 loadfile, stop. The filename is passed to "loadfile" via M[1]. This sequence is generated by vm (at "genload") during its initialisation.

3.  once loadfile finished, the "stop" (3) instruction is executed.  The context is switched back to user_cs to continue.

4.  once the code in im. line reaches "stop" the context is switched back to sys_cs.  All registers used are restored.

24 Oct 2009
