Exemple #1
0
 public void Run(vm machine)
 {
     if (machine.A == TERMINATE) {
         machine.RN = false;
     } else if (machine.A == BREAK) {
         machine.BRK = true;
     } else if (machine.A == UNLOAD_DEVICE) {
         int device = machine.AX;
         machine.UnloadDevice(device);
     } else if (machine.A == LOAD_PROGRAM) {
         int device = machine.AX;
         StorageDevice disk = (StorageDevice)machine.GetDevice(device);
         machine.LoadProgram(disk.GetData());
     } else if (machine.A == GET_ROM_DEVICE) {
         for (int i = 0; i < machine.NumberOfDevices(); i++) {
             VMDevice device = machine.GetDevice(i);
             if(device is VirtualROMDisk) {
                 machine.EX = i;
                 if(machine.AX <= 0) {
                     return;
                 }
                 machine.AX--;
             }
         }
         throw new Exception("No ROM devices found!");
     }
 }
Exemple #2
0
        public CPU(vm Machine)
        {
            this.machine = Machine;

            hardwareinterupts = new HardwareInterupt[] {
                new CoreInterupt(),
                new TerminalInterupt(),
                new HDIInterupt(),
            };
        }
Exemple #3
0
 public CallStack(vm Machine, Memory RAM)
 {
     machine = Machine;
     ram = RAM;
 }
Exemple #4
0
        public void Run(vm machine)
        {
            if (machine.A == PRINTCH) {
                Console.Write ((char)machine.B);
            } else if (machine.A == PRINTSTR) {
                string str = machine.pager.PopString (machine.CR3);
                Console.Write (str);
            } else if (machine.A == PRINTINT) {
                Console.Write (machine.AX);
            } else if (machine.A == PRINTFLT) {
                Console.Write (machine.EAX);
            } else if (machine.A == READCH) {
                machine.E = (byte)Console.Read ();
            } else if (machine.A == READSTR) {
                string str = Console.ReadLine ();
                machine.pager.Push (str, machine.CR3);
            } else if (machine.A == READINT) {
                machine.AX = Convert.ToInt32 (Console.ReadLine ());
            } else if (machine.A == READFLT) {
                machine.EAX = (float)Convert.ToInt32 (Console.ReadLine ());
            } else if (machine.A == PRINTB) {
                Console.Write (machine.B);
            } else if (machine.A == READB) {
                machine.E = Convert.ToByte (Console.ReadLine ());
            } else if (machine.A == CLEAR) {
                Console.Clear ();
            } else if (machine.A == CHFGCOLOR) {

            }
        }
Exemple #5
0
 public void Run(vm machine)
 {
     if(machine.A == GETDIR)	{
         machine.pager.Push(machine.hdi.GetWorkingDirectory(),machine.CR3);
     } else if (machine.A == CHANGEDIR) {
         string path = machine.pager.PopString(machine.CR3);
         machine.hdi.ChangeDirectory(path);
     } else if (machine.A == CREATEDIR) {
         string dir = machine.pager.PopString(machine.CR3);
         machine.hdi.CreateDirectory(dir);
     } else if (machine.A == CREATEFILE) {
         string filename = machine.pager.PopString(machine.CR3);
         machine.hdi.CreateFile(filename);
     } else if (machine.A == OPENFILE) {
         string filename = machine.pager.PopString(machine.CR3);
         machine.hdi.OpenFile(filename);
     } else if (machine.A == CLOSEFILE) {
         machine.hdi.CloseFile();
     } else if (machine.A == READBYTES) {
         int len = machine.AX;
         uint addr = machine.DA;
         byte[] data = machine.hdi.ReadBytes(len);
         if(machine.pager.checkVAT(addr,(uint)len,machine.CR3)) {
         } else {
         }
     } else if (machine.A == WRITEBYTES) {
     } else if (machine.A == LOADPROGRAM) {
         byte[] program = machine.hdi.ReadAllBytes();
         machine.LoadProgram(program);
     } else if (machine.A == DIREXISTS) {
         string name = machine.pager.PopString(machine.CR3);
         machine.CP = machine.hdi.DirectoryExists(name);
     } else if (machine.A == FILEEXISTS) {
         string name = machine.pager.PopString(machine.CR3);
         machine.CP = machine.hdi.FileExists(name);
     }
 }
Exemple #6
0
        public static void Main(string[] args)
        {
            List<VMDevice> extradevices = new List<VMDevice> ();

            string codetocompile = "";
            bool output = false;
            string outputfile = "";
            bool compileflag = false;
            byte[] biosdata = null;

            #if DEBUG
            string inpdata = Console.ReadLine();
            if(inpdata == "") {
                inpdata = "-cd ../../testing -b bios";
            }
            args = inpdata.Split(' ');
            #endif

            for (int i = 0; i < args.Length; i++) {
                if (args [i] == "-rd") {
                    i++;
                    extradevices.Add (new VirtualROMDisk (args [i]));
                } else if (args [i] == "-i") {
                    i++;
                    codetocompile = File.ReadAllText (args [i]);
                } else if (args [i] == "-o") {
                    output = true;
                    i++;
                    outputfile = args [i];
                } else if (args [i] == "-cd") {
                    i++;
                    Directory.SetCurrentDirectory(args[i]);
                } else if (args[i] == "-c") {
                    compileflag = true;
                } else if (args[i] == "-b") {
                    i++;
                    biosdata = File.ReadAllBytes(args[i]);
                } else if (args[i] == "-h") {
                    Console.WriteLine("Northcode Virtual Machine 2");
                    Console.WriteLine("Usage: nvm [options]");
                    Console.WriteLine("Options:");
                    Console.WriteLine("-cd <directory>\t\t: change working directory, useful for loading bios from somewhere outside of the nvm2 folder");
                    Console.WriteLine("-i <file>\t\t: input file, select and inputfile for the Assembler");
                    Console.WriteLine("-c\t\t\t: compile flag, when selected, code from inputfile will be assembled into nasm");
                    Console.WriteLine("-o <file>\t\t: output file, file for compiler to write assembly into");
                    Console.WriteLine("-rd <file>\t\t: assembly file to be loaded as a virtual ROM disk that can be read by the vm");
                    Console.WriteLine("-h\t\t\t: shows this screen of commands");
                    Console.WriteLine("-b <file>\t\t: Loads a bios to the virtual machine, this is the first program that is run");
                    Console.WriteLine();
                }
            }

            if (compileflag) {
                if (codetocompile == "") {
                    StringBuilder stb = new StringBuilder ();
                    string c = "";
                    while ((c = Console.ReadLine()) != "q") {
                        stb.AppendLine (c);
                    }
                    codetocompile = stb.ToString ();
                }

                Assembler asm = new Assembler(codetocompile);
                asm.Scan();
                asm.Assemble();

                byte[] program = asm.GetProgram();

                if (output) {
                    File.WriteAllBytes (outputfile, program);
                }
                return;
            }
            /*
            for(int i = 0; i < program.Length; i++) {
                Console.WriteLine(i + ": " + program[i]);
            }
            */

            vm machine = new vm();
            foreach (VMDevice device in extradevices) {
                machine.LoadDevice(device);
            }
            if(biosdata == null)
            {
                Console.WriteLine("No bios loaded!");
                Console.ReadLine();
                return;
            }
            machine.LoadBios(biosdata);
            machine.Start();

            /*
             * MEMORY TEST INTERPRETER
            Console.Write("Size of ram (num. of frames (4k blocks)): ");
            int rsize = Convert.ToInt32(Console.ReadLine());
            Memory test = new Memory(Frame.FRAME_SIZE * rsize);
            Pager pager = new Pager(test, 10);

            string cmd = "";
            int selected = -1;
            while ((cmd = Console.ReadLine()) != "") {
                string[] sargs = cmd.Split(' ');
                try {
                    if(sargs[0] == "mkpt") {
                        Console.WriteLine("Created page table at: " + pager.CreatePageEntry(Pager.PAGE_USER_MODE));
                    } else if (sargs[0] == "rmpt") {
                        int pt = selected;
                        selected = -1;
                        pager.FreePageEntry(pager.getEntry(pt));
                        Console.WriteLine("Removed page: " + sargs[1]);
                    } else if(sargs[0] == "select") {
                        selected = Convert.ToInt32(sargs[1]);
                        Console.WriteLine("selected page table " + selected);
                    } else if (sargs[0] == "addpage") {
                        int pt = selected;
                        pager.AddPage(pager.getEntry(pt));
                        Console.WriteLine("Added page");
                    } else if (sargs[0] == "setmem") {
                        int pt = selected;
                        uint stk = Convert.ToUInt32(sargs[1]);
                        uint hep = Convert.ToUInt32(sargs[2]);
                        pager.SetupMemory(pager.getEntry(pt),stk,hep);
                        pager.SetupMemoryAllocation(pager.getEntry(pt));
                    } else if (sargs[0] == "malloc") {
                        int pt = selected;
                        uint size = Convert.ToUInt32(sargs[1]);
                        uint addr = pager.Malloc(size,pager.getEntry(pt));
                        Console.WriteLine("Allocated memory at: " + addr);
                    } else if (sargs[0] == "free") {
                        int pt = selected;
                        uint addr = Convert.ToUInt32(sargs[1]);
                        uint size = Convert.ToUInt32(sargs[2]);
                        pager.free(addr,size,pager.getEntry(pt));
                        Console.WriteLine("Freed up space");
                    } else if (sargs[0] == "dmppt") {
                        int pt = selected;
                        Console.WriteLine("Page table " + pt + " at: " + pager.getEntry(pt).PTAddress);
                        pager.DumpPageTable(pager.getEntry(pt));
                    } else if (sargs[0] == "dmpfl") {
                        int pt = selected;
                        pager.DumpFreeList(pager.getEntry(pt));
                    } else if (sargs[0] == "pushb") {
                        int pt = selected;
                        byte val = Convert.ToByte(sargs[1]);
                        pager.Push(val,pager.getEntry(pt));
                    } else if (sargs[0] == "pushi") {
                        int pt = selected;
                        int val = Convert.ToInt32(sargs[1]);
                        pager.Push(val,pager.getEntry(pt));
                    } else if (sargs[0] == "pushui") {
                        int pt = selected;
                        uint val = Convert.ToUInt32(sargs[1]);
                        pager.Push(val,pager.getEntry(pt));
                    } else if (sargs[0] == "pushf") {
                        int pt = selected;
                        float val = (float)Convert.ToDecimal(sargs[1]);
                        pager.Push(val,pager.getEntry(pt));
                    } else if (sargs[0] == "pushs") {
                        int pt = selected;
                        string val = String.Join(" ",sargs);
                        val = val.Substring(val.IndexOf('\'') + 1,val.LastIndexOf('\'') - (val.IndexOf('\'') + 1));
                        pager.Push(val,pager.getEntry(pt));
                    } else if (sargs[0] == "popb") {
                        int pt = selected;
                        Console.WriteLine(pager.PopByte(pager.getEntry(pt)));
                    } else if (sargs[0] == "popi") {
                        int pt = selected;
                        Console.WriteLine(pager.PopInt(pager.getEntry(pt)));
                    } else if (sargs[0] == "popui") {
                        int pt = selected;
                        Console.WriteLine(pager.PopUInt(pager.getEntry(pt)));
                    } else if (sargs[0] == "popf") {
                        int pt = selected;
                        Console.WriteLine(pager.PopFloat(pager.getEntry(pt)));
                    } else if (sargs[0] == "pops") {
                        int pt = selected;
                        Console.WriteLine(pager.PopString(pager.getEntry(pt)));
                    } else if(sargs[0] == "vat") {
                        uint val = Convert.ToUInt32(sargs[1]);
                        Console.WriteLine(pager.getVAT(val,pager.getEntry(selected)));
                    } else if(sargs[0] == "rvat") {
                        uint val = Convert.ToUInt32(sargs[1]);
                        Console.WriteLine(pager.reverseVAT(val));
                    } else if (sargs[0] == "writeb") {
                        uint addr = Convert.ToUInt32(sargs[1]);
                        byte val = Convert.ToByte(sargs[2]);
                        test.Write(addr,val);
                    } else if (sargs[0] == "writei") {
                        uint addr = Convert.ToUInt32(sargs[1]);
                        int val = Convert.ToInt32(sargs[2]);
                        test.Write(addr,val);
                    } else if (sargs[0] == "writeui") {
                        uint addr = Convert.ToUInt32(sargs[1]);
                        uint val = Convert.ToUInt32(sargs[2]);
                        test.Write(addr,val);
                    } else if (sargs[0] == "writef") {
                        uint addr = Convert.ToUInt32(sargs[1]);
                        float val = (float)Convert.ToDecimal(sargs[2]);
                        test.Write(addr,val);
                    } else if (sargs[0] == "writes") {
                        uint addr = Convert.ToUInt32(sargs[1]);
                        string val = sargs[2];
                        test.Write(addr,val);
                    } else if (sargs[0] == "exit") {
                        break;
                    }
                } catch (IndexOutOfRangeException) {
                    Console.WriteLine("Please select a page table!");
                } catch (Exception ex) {
                    Console.WriteLine("Error: " + ex.Message);
                }
            }
            */
        }