Пример #1
0
 public void releaseMem(RAM ram, PCB pcb) //Releases an individual processes memory
 {
     for (int i = pcb.ramBaseAddress; i <= pcb.ramBaseAddress + pcb.spaceReq; i++)
     {
         if (i >= ram.data.Length || i < 0)
         {
             if (debugMode)
             {
                 Console.WriteLine("ERROR! i is " + i);
             }
         }
         ram.data[i] = -1;
     }
 }
Пример #2
0
 public void sortQueue() //Makes the queue a priority queue
 {
     for (int i = 0; i < this.queue.Length - 1; i++)
     {
         for (int j = i + 1; j < this.queue.Length; j++)
         {
             if (this.queue[i].priority > this.queue[j].priority)
             {
                 PCB temp = new PCB();
                 temp          = this.queue[i];
                 this.queue[i] = this.queue[j];
                 this.queue[j] = temp;
             }
         }
     }
 }
Пример #3
0
 public void execute(RAM ram, pcbQueue pcbQueue, Scheduler schedule, cpuQueue que)
 {
     while (pcbQueue.jobsComplete() == false)
     {
         while (this != que.head || pcbQueue.cpuIterator >= pcbQueue.ramIterator)
         {
             //do nothing
             if (pcbQueue.jobsComplete() == true)
             {
                 return;
             }
             Thread.Yield();
         }
         PCB temp = pcbQueue.queue[pcbQueue.cpuIterator];
         if (debugMode)
         {
             Console.WriteLine("CPU " + this.id + " executing job " + temp.processID);
         }
         pcbQueue.cpuIterator++;
         que.deQueue();
         temp.startTime = DateTime.Now.TimeOfDay;
         temp.waitTime  = temp.startTime - temp.ramLoadTime;
         PopulateInstructionList(ram, temp);
         this.StartWork(temp);
         temp.timeCompleted = DateTime.Now.TimeOfDay;
         if (debugMode)
         {
             temp.core = pcbQueue.getCoreDump(temp, ram);
         }
         temp.executionTime = temp.timeCompleted - temp.startTime;
         temp.complete      = true;
         this.signal(ram, schedule, temp);
         if (debugMode)
         {
             Console.WriteLine("Process " + temp.processID + " complete!");
         }
         que.enQueue(this);
         if (debugMode)
         {
             Console.WriteLine("Jobs complete? " + pcbQueue.jobsComplete());
         }
     }
 }
Пример #4
0
        public void PopulateInstructionList(RAM ram, PCB pcb)
        {
            string instruction       = "";
            int    lowerBound        = pcb.ramBaseAddress;
            int    upperBound        = lowerBound + (pcb.wordCount * 32);
            int    instructionsCount = upperBound / 32 - lowerBound / 32;
            int    count             = 1;

            if (lowerBound == -1)
            {
                return;
            }
            for (int j = lowerBound + 1; j < upperBound - 1; j++)
            {
                instruction += ram.data[j - 1];
                if (count % 32 == 0)
                {
                    instructionList.Add(instruction);
                    instruction = "";
                }
                count++;
            }
        }
Пример #5
0
        public string getCoreDump(PCB pcb, RAM ram)
        {
            var dumpString = ram.coreDump(pcb.ramBaseAddress, pcb.ramBaseAddress + (pcb.wordCount + pcb.inputBuffer + pcb.outputBuffer + pcb.tempBuffer) * 32);

            return(dumpString);
        }
Пример #6
0
        public void StartWork(PCB pcb)
        {
            for (int i = 0; i < instructionList.Count; i++)
            {
                type   = Utility.BinaryToDecimal(instructionList[i].Substring(0, 2));
                opcode = Utility.BinaryToDecimal(instructionList[i].Substring(2, 6));
                switch (type)
                {
                //Example Arithmetic Operation that assigns the sum of regS1 and regS2 to regD
                //00_000101_0000_0001_0010_000000000000 (without the underscores)
                case 0:
                    //2 bits 0(type) + 6 bits opcode + 4 bits regS1 + 4 bits regS2 + 4 bits regD + 12 bits 0 = 32 bit instruction for Arithmetic
                    if (debugMode)
                    {
                        Console.WriteLine("Performing an ARITHMETIC operation");
                    }
                    regS1 = Utility.BinaryToDecimal(instructionList[i].Substring(8, 4));
                    regS2 = Utility.BinaryToDecimal(instructionList[i].Substring(12, 4));
                    regD  = Utility.BinaryToDecimal(instructionList[i].Substring(16, 4));
                    ExecuteOPCode(opcode);
                    break;

                case 1:
                    //2 bits 01(type) + 6 bits opcode + 4 bits regB + 4 bits regD + 16 bits address = 32 bits for Conditional Branch
                    if (debugMode)
                    {
                        Console.WriteLine("Performing a CONDITIONAL BRANCH operation");
                    }
                    regB    = Utility.BinaryToDecimal(instructionList[i].Substring(8, 4));
                    regD    = Utility.BinaryToDecimal(instructionList[i].Substring(12, 4));
                    address = Utility.BinaryToDecimal(instructionList[i].Substring(16, 16));
                    ExecuteOPCode(opcode);
                    break;

                case 2:
                    //2 bits 10(type) + 6 bits opcode + 24 bits address = 32 bits for Uncondition Jump
                    if (debugMode)
                    {
                        Console.WriteLine("Performing an UNCONDITIONAL JUMP operation");
                    }
                    address = Utility.BinaryToDecimal(instructionList[i].Substring(8, 24));
                    ExecuteOPCode(opcode);
                    break;

                case 3:
                    //2 bits 11(type) + 6 bits opcode + 4 bits reg1 + 4 bits reg2 + 16 bits address = 32 bits for Input/Output
                    if (debugMode)
                    {
                        Console.WriteLine("Performing an I/O operation");
                    }
                    pcb.ioOps++;
                    reg1    = Utility.BinaryToDecimal(instructionList[i].Substring(8, 4));
                    reg2    = Utility.BinaryToDecimal(instructionList[i].Substring(12, 4));
                    address = Utility.BinaryToDecimal(instructionList[i].Substring(16, 16));
                    ExecuteOPCode(opcode);
                    break;

                default:
                    break;
                }
            }
            instructionList.Clear();
        }
Пример #7
0
 public void signal(RAM ram, Scheduler schedule, PCB pcb) //Deallocates a jobs memory after completion
 {
     schedule.releaseMem(ram, pcb);
 }