Thursday, August 25, 2011

Virtual Machines

One of the best resources about virtual machines (both high-level language VMs and system VMs) is Jim Smith's and Ravi Nair's book Virtual Machines: Versatile Platforms for Systems and Processes.

The TinyVM is a small, fast and lightweight virtual machine written in pure ANSI C. The source code of this toy virtual machine can easily be read and understood in just a few minutes.
The create_vm (tvm.c) function creates a virtual machine instance by allocating its memory and stack. It also parses a TinyVM program that contains TinyVM assembly language opcodes from a text file. The interpret_program (tvm_program.cfunction reads the TinyVM program into a list of instructions and into a further list containing the arguments for all instructions.
The TinyVM has some registers which are mapped to memory (see field registers in struct tvm_memory_t of file tvm_memory.h).
After parsing a program the TinyVM runs it using run_vm (tvm.c). This function contains the interpreter loop of the virtual machine which executes the program by interpreting the list of instructions.

Some more interesting resources about virtual machines:

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.