/// <summary> /// This function returns from the interrupt routine /// </summary> /// <param name="returnAddress">the logical address to return back to</param> public override void Return(int returnAddress) { handled = true; if (handler.HandlerFunction != null) { handler.HandlerFunction(); } else { SimulatorProgram prog = GetCurrentProgram(); ExecutionUnit unit = GetExecutionUnit(); dynamic procunit = GetCurrentProcessExecutionUnit(); if (procunit == null) { unit = GetExecutionUnit(); unit.LogicalAddress = returnAddress; unit.CurrentIndex = returnAddress / 4; unit.Done = false; unit.Stop = false; } else { procunit.LogicalAddress = returnAddress; procunit.CurrentIndex = returnAddress / 4; procunit.Stop = false; procunit.Done = false; } } }
/// <summary> /// Function that handles the size command /// </summary> /// <param name="name"> the command that is being executed</param> /// <param name="parameters"> any parameters for that command</param> /// <returns> the result of the command</returns> private string SizeCommand(string name, string[] parameters) { if (parameters.Length != 1 && (parameters.Length == 0 || !parameters[0].Equals("pages") || !parameters[0].Equals("bytes"))) { return("Invalid Command syntax use like this: \n" + "//size <bytes|pages> \n"); } dynamic wind = GetMainWindowInstance(); List <SimulatorProgram> programList = wind.ProgramList; SimulatorProgram prog = programList.FirstOrDefault(x => x.Name.Equals(wind.currentProgram)); if (parameters[0].Equals("bytes")) { if (prog == null) { return("ERROR : No program is loaded \n"); } //TODO will need changing when instructions are not the same size. return("Program size = " + Convert.ToString(prog.Instructions.Count * 4) + " bytes \n"); } if (parameters[0].Equals("pages")) { return("Program size = " + Convert.ToString(prog.Pages) + " pages \n"); } return("Invalid Command syntax use like this: \n" + "//size <bytes|pages> \n "); }
public void AddInstructionTest() { SimulatorProgram prog = new SimulatorProgram("Test", 0, 1); Instruction ins = new Instruction(3, 4); prog.Instructions.Add(ins); Assert.AreEqual(prog.Instructions.Count, 1); }
public void AddInstructionTest() { SimulatorProgram prog = new SimulatorProgram("Test", 0, 1); Instruction ins = new Instruction(0, new Operand(Register.R00, EnumOperandType.VALUE), EnumAddressType.UNKNOWN, new Operand(10, EnumOperandType.VALUE), EnumAddressType.UNKNOWN, 4); prog.AddInstruction(ref ins); Assert.AreEqual(prog.Instructions.Count, 1); }
/// <summary> /// This Function gets the program to be executed by the CPU from the main window /// </summary> /// <returns>the program to be executed by the CPU</returns> private SimulatorProgram GetCurrentProgram() { dynamic window = GetMainWindowInstance(); string programName = window.currentProgram; // get the name of the program that is currently loaded List <SimulatorProgram> programs = window.ProgramList; // get a copy of the program list SimulatorProgram prog = programs.Where(x => x.Name.Equals(programName)).FirstOrDefault(); // find the current program in the list return(prog); // return the current program }
public void AddInstructionTest1() { SimulatorProgram prog = new SimulatorProgram("Test", 0, 1); Instruction ins = new Instruction(0, new Operand(Register.R00, EnumOperandType.VALUE), EnumAddressType.UNKNOWN, new Operand(10, EnumOperandType.VALUE), EnumAddressType.UNKNOWN, 4); Instruction ins2 = new Instruction(0, new Operand(Register.R01, EnumOperandType.VALUE), EnumAddressType.UNKNOWN, new Operand(10, EnumOperandType.VALUE), EnumAddressType.UNKNOWN, 4); prog.AddInstruction(ref ins); prog.AddInstruction(ref ins2, 0); Assert.IsTrue(prog.Instructions.Count == 2 && prog.Instructions.ElementAt(0).Equals(ins2)); }
/// <summary> /// Function that handles the program command /// </summary> /// <param name="name"> the command that is being executed</param> /// <param name="parameters"> any parameters for that command</param> /// <returns> the result of the command</returns> private string ProgramCommand(string name, string[] parameters) { dynamic wind = GetMainWindowInstance(); List <SimulatorProgram> programList = wind.ProgramList; SimulatorProgram prog = programList.FirstOrDefault(x => x.Name.Equals(wind.currentProgram)); if (prog == null) { return("ERROR : No program is loaded \n"); } return("Program name = " + prog.Name + "\n"); }
/// <summary> /// Constructor for a process /// </summary> /// <param name="flags"> the flags to create this process with</param> public SimulatorProcess(ProcessFlags flags) { this.program = flags.program; this.programName = flags.programName; this.processName = flags.processName; this.processPriority = flags.processPriority; this.processMemory = flags.processMemory; this.processLifetime = flags.processLifetime; this.processID = flags.processID; this.CPUID = flags.CPUid; this.burstTime = flags.burstTime; this.displayProfile = flags.displayProfile; this.parentDiesChildrenDie = flags.parentDiesChildrenDie; this.delayedProcess = flags.delayedProcess; this.delayedProcessTime = flags.delayedProcessTime; this.delayTimeUnit = flags.delayTimeUnit; this.parentProcess = flags.parentProcess; if (parentProcess != null) { parentProcessID = parentProcess.processID; } else { parentProcessID = -1; } this.childProcesses = flags.childProcesses; this.processSwapped = flags.processSwapped; this.currentState = flags.processState; this.previousState = flags.previousState; this.resourceStarved = flags.resourceStarved; this.allocatedResources = flags.allocatedResources; this.requestedResources = flags.requestedResources; this.processControlBlock = flags.processControlBlock; this.OSid = flags.OSid; this.clockSpeed = flags.clockSpeed; this.unit = new ProcessExecutionUnit(this, clockSpeed); this.lotteryTickets = flags.lotteryTickets; this.ownsSemaphore = flags.ownsSemaphore; this.waitingForSemaphore = flags.waitingForSemaphore; }
public void SimulatorProgramTest1() { SimulatorProgram prog = new SimulatorProgram("Test", 0, 1); Assert.IsInstanceOfType(prog, typeof(SimulatorProgram)); }