The RedCode Virtual Machine

RedCode executes on a special virtual machine, the RedCode VM (RVM), a multiprocessing, 32-bit, little-endian, register-based machine with a single, linear memory space and no virtual memory mechanism or memory protection whatsoever. The memory of a RVM is made up of 32-bit word cells. A read or write to a single cell is an atomic operation.

Each RVM may have the following unique characteristics:

CPU Speed
Each RVM may run at a different speed from all of the others. The CPU speed of a RVM is given by a single, strictly positive integer, where 1 is the fastest speed. A RVM with a speed of 2 takes, on average, twice as long for each clock cycle as does one with a speed of 1; a speed of 3 takes three times as long per clock cycle, etc.
Memory Size
Each RVM may have a different memory size from every other. The memory size is given by a single, strictly positive integer in the range $ [2^{0},2^{16}$ specifying the number of 32-bit words in the memory. An attempt to access (read, write, or execute) a cell outside the memory range causes an ILLEGAL OPERATION fault in the executing process.
Data Buffer Size
Each RVM may have a different capacity for the size of its incoming data buffer. As data is transmitted to an RVM via the rsw instruction, it is queued on an incoming data buffer. When the capacity is reached, additional data messages are dropped.

Every PROCESS has 32 32-bit general purpose registers, denoted $0-$31, and three special purpose registers, PC, HI, and LO. PC is the program counter and contains the 32-bit address of the instruction currently being executed, while HI and LO are 32-bit registers used for the results of mult and div instructions. HI and LO cannot be manipulated directly, but their values can be copied to standard registers via mfhi and mflo. The register $0 always contains the value 0, regardless of what data has been written to it. The registers $1 and $2 are not reserved, but they do have a special meaning to the system call instruction (see Appendix A). Unlike the standard MIPS assembly language, no other registers are reserved or have special names or meanings.

Finally, every process is associated with a special data structure, the SOCKET, not present in the standard MIPS architecture, that is used to track connections to remote RVMs. SOCKET can be modified only through the special extended instructions open and close and it is used only by the rsw and rfrk instructions. The implementation of SOCKET is not specified by this document -- it is the design team's choice how to provide this service. The important criterion is that every PROCESS can have its own SOCKET, but each PROCESS can have only a single SOCKET open to a remote RVM at a time.

Terran Lane 2004-03-29