コード例 #1
0
 public void pageLoad(Disk disk, RAM ram, pcbQueue pcbQueue)
 {
     //for each pcb load the first 4 pages in RAM
     while (pcbQueue.ramIterator < 30)
     {
         for (int i = 0; i < 4; i++)
         {
             pageLoadRam(disk, pcbQueue.queue[pcbQueue.ramIterator].pageTable[i], ram);
         }
         pcbQueue.ramIterator++;
     }
 }
コード例 #2
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;
     }
 }
コード例 #3
0
 public void loadRAM(Disk disk, RAM ram, pcbQueue pcbQueue, int i)
 {
     //Load an individual job from disk to RAM, starting at process disk address and ending at disk address + spaceReq
     pcbQueue.queue[i].ramBaseAddress      = iterator;
     pcbQueue.queue[i].programCounter      = iterator;
     pcbQueue.queue[i].ramLoadTime         = DateTime.Now.TimeOfDay;
     pcbQueue.queue[i].inputBufferAddress  = pcbQueue.queue[i].ramBaseAddress + pcbQueue.queue[i].wordCount * 32 + 1;
     pcbQueue.queue[i].outputBufferAddress = pcbQueue.queue[i].inputBufferAddress + pcbQueue.queue[i].inputBuffer * 32 + 1;
     pcbQueue.queue[i].tempBufferAddress   = pcbQueue.queue[i].outputBufferAddress + pcbQueue.queue[i].outputBuffer * 32 + 1;
     for (int j = pcbQueue.queue[i].diskAddress; j <= pcbQueue.queue[i].diskAddress + pcbQueue.queue[i].spaceReq; j++)
     {
         ram.data[iterator] = disk.data[j];
         iterator++;
     }
     pcbQueue.ramIterator++; //By the end of this function, the queue's iterator will points to next process to be loaded
 }
コード例 #4
0
        public Boolean spaceAvailable(int iterator, int spaceReq, RAM ram) //Tells us if space is available starting at position [iterator] up to [iterator+spaceReq]
        {
            Boolean result = true;

            for (int i = iterator; i <= iterator + spaceReq; i++)
            {
                if (i == 32768 || i < 0) //If we reach the last index of RAM
                {
                    return(result = false);
                }
                if (ram.data[i] != -1)
                {
                    return(result = false);
                }
            }
            return(result);
        }
コード例 #5
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());
         }
     }
 }
コード例 #6
0
        public void pageLoadRam(Disk disk, page page, RAM ram)
        {
            int index = ram.getFreeFrame();

            if (index == ram.frameList.Length)
            {
                return; //no available memory
            }
            page.frameNumber               = index;
            page.ramBaseAddress            = ram.frameList[index].startAddress;
            ram.frameList[index].available = false;
            int ramPointer  = ram.frameList[index].startAddress;
            int diskPointer = page.diskBaseAddress;

            for (int i = 0; i < 128; i++)
            {
                ram.data[ramPointer] = disk.data[diskPointer];
                ramPointer++;
                diskPointer++;
            }
            page.valid = true;
        }
コード例 #7
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++;
            }
        }
コード例 #8
0
ファイル: pcbQueue.cs プロジェクト: rmoser3/SimOS
        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);
        }
コード例 #9
0
 public void requestPageLoad(Disk disk, RAM ram, page page)
 {
     pageLoadRam(disk, page, ram);
 }
コード例 #10
0
 public void signal(RAM ram, Scheduler schedule, PCB pcb) //Deallocates a jobs memory after completion
 {
     schedule.releaseMem(ram, pcb);
 }