/// <summary>
 /// Constructor for process control block with construction flags
 /// </summary>
 /// <param name="flags"> flags to use to construct this PCB</param>
 public ProcessControlBlock(PCBFlags flags)
 {
     this.CPUID           = flags.CPUID;
     this.OSID            = flags.OSID;
     this.processID       = flags.processID;
     this.ProcessName     = flags.processName;
     this.processState    = flags.processState;
     this.programName     = flags.programName;
     this.baseAddress     = flags.baseAddress;
     this.startAddress    = flags.startAddress;
     this.processPriority = flags.processPriority;
     this.avgBurstTime    = flags.avgBurstTime;
     this.avgWaitingTime  = flags.avgWaitingTime;
     this.resourceStarved = flags.resourceStarved;
     if (flags.allocatedResources == null)
     {
         this.allocatedResources = new List <SimulatorResource>();
     }
     else
     {
         this.allocatedResources = flags.allocatedResources;
     }
     if (flags.requestedResources == null)
     {
         this.allocatedResources = new List <SimulatorResource>();
     }
     else
     {
         this.allocatedResources = flags.allocatedResources;
     }
     this.specialRegisters = flags.specialRegisters;
     this.registers        = flags.registers;
     this.lifetimeMills    = flags.lifetimeMills;
 }
Example #2
0
        /// <summary>
        /// This function creates the flags required to construct a PCB (Process Control Block)
        /// </summary>
        /// <param name="currentProcess"> a reference to the process that the PCB will belong to</param>
        /// <returns> a struct containing the flags to create a PCB or null if an error occurred</returns>
        private PCBFlags?CreatePCBFlags(ref SimulatorProcess currentProcess)
        {
            //SimulatorProcess currentProcess = waitingQueue.Peek();
            PCBFlags flags = new PCBFlags();

            flags.CPUID = currentProcess.CPUID;
            flags.OSID  = currentProcess.OSID;
            flags.allocatedResources = currentProcess.AllocatedResources;
            flags.avgBurstTime       = 0;
            flags.avgWaitingTime     = 0; //TODO calculate correct values
            flags.baseAddress        = currentProcess.Program.BaseAddress;
            flags.proceessMemory     = currentProcess.ProcessMemory;
            flags.processID          = currentProcess.ProcessID;
            flags.processName        = currentProcess.ProcessName;
            flags.processPriority    = currentProcess.ProcessPriority;
            flags.CPUID              = 0; //TODO Change this once multiple CPU's are implemented
            flags.processState       = currentProcess.CurrentState;
            flags.programName        = currentProcess.ProgramName;
            flags.requestedResources = currentProcess.RequestedResources;
            flags.resourceStarved    = currentProcess.ResourceStarved;
            flags.startAddress       = currentProcess.Program.BaseAddress; // TODO Implement program start address
            flags.lifetimeMills      = (int)(currentProcess.ProcessLifetime - lifetime.ElapsedMilliseconds);
            flags.registers          = new Register[21];
            for (int i = 0; i < flags.registers.Length; i++)
            {
                string registerName = String.Empty;
                if (i < 10)
                {
                    registerName = "R0" + i;
                }
                else
                {
                    registerName = "R" + i;
                }
                flags.registers[i] = Register.FindRegister(registerName);
            }
            flags.specialRegisters    = new SpecialRegister[7];
            flags.specialRegisters[0] = SpecialRegister.PC;
            flags.specialRegisters[1] = SpecialRegister.BR;
            flags.specialRegisters[2] = SpecialRegister.SP;
            flags.specialRegisters[3] = SpecialRegister.IR;
            flags.specialRegisters[4] = SpecialRegister.SR;
            flags.specialRegisters[5] = SpecialRegister.MAR;
            flags.specialRegisters[6] = SpecialRegister.MDR;
            return(flags);
        }