// ----------------------------------------------------------------- // CS 39 Virtual Platform // virtualMachine.hh // Scott F. Kaplan -- sfkaplan@cs.amherst.edu // September 2000 // This is the header file that defines the interface to the virtual // machine module, as well as types and state (if any) that should be // available outside this module. // ----------------------------------------------------------------- // ----------------------------------------------------------------- // Avoid multiple inclusion in a single module. #if !defined (_VIRTUALMACHINE_HH) #define _VIRTUALMACHINE_HH // ----------------------------------------------------------------- // ----------------------------------------------------------------- // A list of types and structures available outside the virtual // machine. // The type for a single byte in the virtual machine. typedef char vMachineByte_t; // A virtual machine word is the basic unit on which the machine // operates. typedef unsigned int vMachineWord_t; // A double word is needed for some special values (such as the clock) // on which the virtual machine operates. typedef unsigned long long vMachineDoubleWord_t; // The type of a pointer to a kernel trap handler. typedef void (*trapHandler_t) (); // An enumerated type that provides values used to identify each // recognized opcode. enum opcode_t { SYSC, // SYStem Call STRR, // SeT Register from Register value STRI, // SeT Register from Immediate value LOAD, // LOAD from memory into register STOR, // STORe from register into memory ADDR, // ADD two Register values ADDI, // ADD a register and an Immediate value SUBR, // SUBtract two Register values SUBI, // SUBtract a register and an Immediate value MULR, // MULtiply two Register values MULI, // MULtiply a register and an Immediate value DIVR, // DIVide two Register values DIVI, // DIVide a register value and an Immediate value ANDR, // AND bitwise two Register values ANDI, // AND bitwise a register and an Immediate value ORR_, // OR bitwise two Register values ORI_, // OR bitwise a Register and an Immediate value NOTR, // NOT bitwise a Register value NOTI, // NOT bitwise an Immediate value SHRL, // SHift bits in a Register to the Left SHRR, // SHift bits in a Register to the Right JMPR, // JuMP execution to the value given in a Register JMPI, // JuMP execution to the value given in an Immediate value BREQ, // BRanch if EQual BRNE, // BRanch if Not Equal BRGT, // BRanch if Greater Than BRLT, // BRanch if Less Than BRGE, // BRanch if Greater than or Equal BRLE, // BRanch of Less than or Equal CALL // Perform a function CALL }; // An enumerated type to represent the different traps. Each name is // given a specific value which becomes the offset into the trap table // (TT) when trapping into the kernel is needed. enum trap_t { SYSTEM_CALL_TRAP = 0, MEMORY_ACCESS_TRAP = 1, CLOCK_INTERRUPT_TRAP = 2, INVALID_INSTRUCTION_TRAP = 3 }; // A constant the represents a virtual machine null pointer. const vMachineWord_t VMACHINE_NULL = 0xFFFFFFFF; // ----------------------------------------------------------------- // ----------------------------------------------------------------- // Names for the registers. extern const unsigned int register_zero; extern const unsigned int register_sp; extern const unsigned int register_fp; extern const unsigned int register_ra; extern const unsigned int register_s0; extern const unsigned int register_s1; extern const unsigned int register_s2; extern const unsigned int register_s3; extern const unsigned int register_a0; extern const unsigned int register_a1; extern const unsigned int register_a2; extern const unsigned int register_a3; extern const unsigned int register_a4; extern const unsigned int register_a5; extern const unsigned int register_a6; extern const unsigned int register_a7; extern const unsigned int register_t0; extern const unsigned int register_t1; extern const unsigned int register_t2; extern const unsigned int register_t3; extern const unsigned int register_t4; extern const unsigned int register_t5; extern const unsigned int register_t6; extern const unsigned int register_t7; extern const unsigned int register_g0; extern const unsigned int register_g1; extern const unsigned int register_g2; extern const unsigned int register_g3; extern const unsigned int register_g4; extern const unsigned int register_g5; extern const unsigned int register_g6; extern const unsigned int register_g7; // ----------------------------------------------------------------- // ----------------------------------------------------------------- // The procedures available to manipulate the virtual machine. // Begin executing by finding the kernel and booting it. void startVMachine (unsigned int mainMemorySize, char* executablePathname); // Return a pointer to the first byte of the virtual machine's main // memory. We use a procedure here to make this data read-only. vMachineByte_t* getMemoryBegin (); // Return a pointer to the byte that *follows* the last byte of the // virtual machine's main memory. We use a procedure here to make // this data read-only. vMachineByte_t* getMemoryEnd (); // Get or set the contents of the given general register. vMachineWord_t getGeneralRegister (unsigned int registerNumber); void setGeneralRegister (unsigned int registerNumber, vMachineWord_t newValue); // Get or set the program counter. vMachineWord_t getPC (); void setPC (vMachineWord_t newPC); // Get or set the tranlsation lookaside buffer (TBR). vMachineWord_t getTBR (); void setTBR (vMachineWord_t newTBR); // Get or set the current interrupt period register. vMachineWord_t getInterruptPeriod (); void setInterruptPeriod (vMachineWord_t newInterruptPeriod); // Get the current clock. vMachineDoubleWord_t getClock (); // Get and set the current base register. vMachineWord_t getBase (); void setBase (vMachineWord_t newBase); // Get and set the current limit register. vMachineWord_t getLimit (); void setLimit (vMachineWord_t newLimit); // ----------------------------------------------------------------- // ----------------------------------------------------------------- #endif // _VIRTUALMACHINE_HH // -----------------------------------------------------------------