Presentation is loading. Please wait.

Presentation is loading. Please wait.

SICvm A SIC Based Virtual Machine Prepared by Anoop U.Thomas V Hariharan Hari Sankar S Santhosh N.Raju.

Similar presentations


Presentation on theme: "SICvm A SIC Based Virtual Machine Prepared by Anoop U.Thomas V Hariharan Hari Sankar S Santhosh N.Raju."— Presentation transcript:

1 SICvm A SIC Based Virtual Machine Prepared by Anoop U.Thomas V Hariharan Hari Sankar S Santhosh N.Raju

2 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net Introduction  In this project we aim to develop a Virtual Machine  The Machine will be based on the Hypothetical Machine described by Leland L.Beck in System Software called Simplified Instructional Computer (SIC)

3 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net A Background on Virtual Machines  The term virtual machine is used to refer to the environment created by an emulator, where software is used to emulate an operating system for the end user.  Church–Turing thesis - implies that any operating environment can be emulated within any other.  In practice, it can be quite difficult, particularly when the exact behavior of the system to be emulated is not documented and has to be deduced through reverse engineering

4 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net How to Achieve Virtualization ?  This can be done using three major ways: 1) Full Virtualization — the virtual machine simulates the complete hardware, allowing an unmodified OS for a completely different CPU to be run. 2) Paravirtualization — the virtual machine does not simulate hardware but instead offers a special API that requires OS modifications. 3) Native Virtualization — the virtual machine only partially simulates enough hardware to allow an unmodified OS to be run in isolation, but the guest OS must be designed for the same type of CPU.  In order to achieve Virtualization we need to have two things. 1) A Virtual Machine (VM) 2) A Virtual Machine Monitor (VMM)

5 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net A Background On SIC  Simplified Instructional Computer (SIC) is a hypothetical computer described in Leland Beck's book System Software.  Most real microprocessors have lots of quirks built-in to increase efficiency.  SIC provides a much simplified view of systems hardware from the perspective of systems programmer  SIC has two versions, a standard version, SIC, and an extended version, SIC/XE.

6 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The SIC Architecture  Memory: 1)Word size: 3 bytes (24 bits) 2)Total size: 32,768 bytes (215). Thus any memory address will need at most 15 bits to be referenced ('almost' four hex characters)  Registers: Total Registers: Five 1)Accumulator (A): Used for most of the operations (number 0) 2)Index (X): Used for indexed addressing (number 1) 3)Linkage (L): Stores return addresses for JSUB (number 2) 4)Program Counter (PC): Address for next instruction (number 8) 5)Status Word (SW): Information and condition codes (number 9).

7 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The SIC Architecture (Continued…)  Instruction Formats: 1) Opcode: First 8 bits, direct translation from the Operation Code Table 2) Flag (x): next bit indicates address mode (0 direct - 1 indexed) 3) Address: next 15 bits, indicate address of operand according to address mode.  Addressing Modes: 1) Only two possible addressing modes 2) Direct (x = 0): operand address goes as it is 3) Indexed (x = 1): value to be added to the value stored at the register x to obtain real address of the operand. OPCODEXADDRESS

8 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net Why Choose SIC To Make A Virtual Machine ?  SIC is a generic view point of a system, that is simple to develop and implement compared to architectures like x86 etc  The SIC architecture is pretty flexible and extendible to other architectures just by simple modifications. This can be achieved in the VM by simple code modifications  SIC machine is used as a study tool for systems programming and this VM helps the better understanding of this machine

9 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The Planning Process  Virtual Machines can be designed in two ways 1) High Level Emulation (Top Down Approach) 2) Low Level Emulation (Bottom Up Approach)  We choose Low Level Emulation 1) The system to be developed was not a very complex system 2) The operational details of the system was known in detail

10 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net Issues Faced In The Planning Process  We couldn’t get enough detailed documentation on how to develop a Virtual Machine  Existing projects like Bochs and Xen were too complex and large to be studied in the given short period of time

11 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The Development Process  The Development Process is divided into 3 Stages 1) Development of SICvm – The Virtual Machine 2) Development of the SIC Assembler 3) Development of the Essential System Programs for SIC

12 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net Tools Used in Development of SICvm  gcc – The GNU compiler collection  make utility  gdb – The GNU Debugger  emacs, vi etc – Text Editing  Windows / Linux Operating System Environment was used in development

13 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The SICvm Machine  Usually an emulator is divided into modules that correspond roughly to the emulated computer's subsystems. In our SICvm we have the following modules 1) A CPU emulator or CPU simulator (the two terms are mostly interchangeable) 2) A memory subsystem module 3) The I/O devices emulators  Buses are not emulated in SICvm

14 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The CPU Emulator  In any virtual machine this is the most complicated part to emulate  We have implemented an interpreter based CPU Emulation  The logic of the simulated CPU can then more or less be directly translated into software algorithms, creating a software re- implementation that basically mirrors the original hardware implementation.

15 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The CPU Implementation Details  Each regsiter is emulated using variables  The CPU accomplishes basic fetch using the fetch() function that does 3 types of fetch 1) Opcode fetch (1 Cycle) 2) Operand fetch (2 Cycles) 3) Data fetch (3 Cycles) 4) Device Code fetch (1 Cycle Byte fetch)  The CPU accomplished storing using a store() fuctions that does the storing of variables from registers to memory locations. This always does a 3 cycle operation  The execute () function executes the instructions

16 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The CPU Implementation Details (Continued…)  Basic CPU Operation was implemented using the following algorithm do { check Interrupts; opval = fetch (OPCODE); switch (opval) { case ADD: case MUL: case SUB: case DIV: operand = fetch (opval); execute (ARITHMETIC, opval, operand) break; case (logical instructions): …… case (load-store instructions): …… case (I/O Instructions): …… } } while (opval != HLT);

17 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The Memory Subsystem  It is possible for the memory subsystem emulation to be reduced to simply an array of elements  The SICvm has 1 MB of memory //Memory Declaration unsigned char *mem; //Allocate Memory Dynamically mem = (unsigned char*) malloc (MEMSIZE);  The memory is segmented into System area (from 0x00000 to 0x00FFF) and User area (from 0x01000 to 0xFFFFF)  The memory is accessed by the fetch () and store () fuctions. Direct memory access is also done by STCH and LDCH instructions

18 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The Memory Subsystem (Continued…) //Standard fetch function int fetch (int type) { int temp; switch (type) { //OPCODE fetching Logic case OPCODE: get opcode; return opcode; //OPERAND fetch Logic case OPERAND: get operand; return operand; //DATA fetch Logic case DATA: get data; return data; //Device Code Fetch Logic case DEVCODE: get devcode; return devcode; } return -1; } //Standard store function void store (int reg) { int temp; //Store the 1st 8 bits temp = reg & 0xFF0000; temp = temp >> 16; mem[operand++] = temp; //Store the 2nd 8 bits temp = reg & 0xFF00; temp = temp >> 8; mem[operand++] = temp; //Store the 3rd 8 bits temp = reg & 0xFF; mem[operand] = temp; }

19 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The Memory Subsystem (Continued…) Memory Address Contents F xxxxxx xxxxxxxx 1010xxxxxxxx xxxxxxxx A X L PC SW OPCODEOPERANDDATA Registers One Cycle Fetch Two Cycle Fetch Three Cycle Fetch

20 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The I/O Subsystem  The current version of SICvm supports input devices and output devices  The input devices are numbered F1, F2, …  The output devices are numbered 01, 02,...  Special device 00 is the Boot ROM that contains the bootstrap loader  Special device F0 is standard input (Keyboard)  Special device A0 is standard output (Monitor)  All other devices are represented as files in the running operating system with the prefix “DEV”  Device Access Delays are emulated for actual device behaviour

21 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The SICvm Architecture SICvm CPU DEV00 (ROM) DEVF0 (Keyboard) DEVF1 DEVA0 (Monitor) DEV06 SICvm’s Memory

22 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net Interrupt Handling In SICvm  All Interrupts in SICvm are generated in the Emulated Hardware Level  Interrupts are generated when errors (like division by zero) are found.  Currently on detecting an interrupt the system goes into a HALT state and prevents further execution

23 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net Interrupts Defined in SICvm  Interrupts in SICvm are defined in “interrupt.h” 1) INT_OVF 0 //Overflow Interrupt 2) INT_DIVZERO 1 //Divide by Zero Interrupt 3) INT_SEGFAULT 2 //Segmentation Fault 4) INT_INVALID 3 //Invalid Instruction 5) INT_BADMEM 4 //Insufficient Memory 6) INT_DEVERR 5 //Bad or Inaccessible Device 7) INT_BADBOOT 6 //DEV00 Not found 8) INT_BADLOAD 7 //DEVF1 Not found 9) INT_OUTOFMEM 8 //Memory Range out of Bounds 10) INT_NONE -1 //No Interrupts Set

24 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The Assembler  The machine code for SIC is generated using a standard 2 Pass assembler as described in Leland L.Beck  In order to support additional features few modifications were made to the assembler 1) Support for the HLT instruction 2) Support to generate bootstrap code 3) Support to generate loader code 4) Support for Immediate Indexed Addressing 5) An External OPTAB.TXT for adding extra instructions  The assembler is also accompanied by a macroprocessor if any macro expansion is required

25 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net Essential SIC Softwares  In order for the SIC Virtual Machine to work we needed essential system software 1) A Bootstrap loader to be placed in DEV00 2) An Absolute Loader to load normal SIC programs into SICvm’s memory. Placed in DEVF1 3) A Shell in order to communicate with the SIC hardware in DEVF2

26 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The Bootstrap Loader Design  The bootstrap loader is based on Beck’s Bootstrap Loader mentioned in System Software  Algorithm: read character while (1) { if (character != EOF) { convert to hex representation move byte to memory location increment location counter } else { goto memory location 0x80 } }

27 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The Loader Design  The loader design algorithm is again borrowed from Beck’s System Software  The loader implemented is an absolute loader  Algorithm: read Header record verify Header read First Text record while (record type != ‘E’) { convert character object code to hex form move object code to specified location read next object program record } jump to specified address

28 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The Shell Design  In order to make the SIC machine more interactive we designed a minimal shell to interact with the machine  The current shell can interpret 3 commands 1) Load from a device 2) Execute the loaded program 3) Quit the shell  Algorithm: while (1) { get input from keyboard switch (input) { case ‘l’: invoke loader and load from dev break; case ‘e’: jump to currently loaded program address case ‘q’: jump to HLT } }

29 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net The Hierarchical Structure Real Machine VMM (Host OS) SICvm SIC Shell (SU MODE) SIC User Programs (U MODE)

30 SICvm Features Demonstration Now we will demonstrate various features of SICvm

31 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net Summary of Various Features  The Machine runs on the standard ASCII set (refer Appendix B of System Software by Leland L.Beck)  The VM currently supports 5 Devices. 1 ROM device (DEV00), 3 Input Devices (DEVF1, DEVF2, DEVF3) and 1 Output Device (DEV06). The machine can work with up to 2 Devices (1 Input and 1 Output) simultaneously.  Dynamic Memory dump of the machine can be shown on the screen.  Supports 1 MB of Memory Space, Out of bounds error detection  Introduced HLT instruction (opcode 0x76) for stopping program after execution.  Introduced Interrupt handling to handle exceptions and error that is detected during the runtime of the program

32 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net Summary of Various Features (Continued…)  Introduction of 2 special devices F0 (standard input) and A0 (standard output) so that SIC machine can use Keyboard and Monitor Devices  Developed a Minimal Shell to communicate with SIC Machine Directly  Introduced Immediate Indexed Mode Addressing  Runs programs in both user mode and supervisor mode  Has the ability to work with 2 Devices (1 Input and 1 Output) Simultaneously  Memory Management, In form of segmentation  Advanced I/O device handling like emulating device delays  Ability to run on both Linux and Windows Platform

33 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net Features Currently Underdevelopment  Introduction of clocking to CPU  Introduction of a display device for SIC  Extension of current machine to support SIC / XE Architecture  A Full fledged working shell / operating environment for the machine  A Dynamically Debuggable interactive interface  A Virtual Machine Monitor for the SICvm

34 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net Conclusion  Provide developers a quick guide in understanding and developing emulators and virtual machines  Easy Extensibility to support various Exisiting and non existing Machine Architectures  Helping aid for students of computer science and engineering, especially when dealing with Systems programming as they will have an environment for developing and testing programs that are written for SIC

35 SICvm – A SIC Based Virtual Machine sicvm.sourceforge.net References  Leland L.Beck - System Software  Hopcroft and Ullmann - Theory of Computation  Hennesy and Patterson - Computer Organization and Design (Used in Referring General Computer Hardware Organization)  A.K Ray - Advanced Microprocessors (Used In Studying of implementation of Segments in 8086)  Dennis Ritche and Brian W.Kernigham - The C Programming Language (General Programming References)  How to: Writing a computer Emulator (General Emulator Programming References)  Wikipedia – (General Reference)http://en.wikipedia.org

36 Thank You Any Questions or Queries


Download ppt "SICvm A SIC Based Virtual Machine Prepared by Anoop U.Thomas V Hariharan Hari Sankar S Santhosh N.Raju."

Similar presentations


Ads by Google