TD3:I6 Use PageProvider in AddrSpace

First Working version, need better error handling
This commit is contained in:
Yorick Barbanneau 2021-12-07 23:54:07 +01:00
parent 7deeec90f1
commit f7eca8c6ac
5 changed files with 16 additions and 9 deletions

View file

@ -32,7 +32,7 @@ THREAD_O := main.o list.o scheduler.o synch.o synchlist.o \
USERPROG_O := addrspace.o bitmap.o exception.o progtest.o console.o \ USERPROG_O := addrspace.o bitmap.o exception.o progtest.o console.o \
consoledriver.o machine.o mipssim.o translate.o \ consoledriver.o machine.o mipssim.o translate.o \
userthread.o papeprovider.o userthread.o pageprovider.o
VM_O := VM_O :=

View file

@ -61,7 +61,7 @@ Machine::Machine(bool debug)
mainMemory = new char[MemorySize]; mainMemory = new char[MemorySize];
for (i = 0; i < MemorySize; i++) for (i = 0; i < MemorySize; i++)
mainMemory[i] = 0; mainMemory[i] = 0;
#ifdef USE_TLB #ifdef USE_TLB
tlb = new TranslationEntry[TLBSize]; tlb = new TranslationEntry[TLBSize];
for (i = 0; i < TLBSize; i++) for (i = 0; i < TLBSize; i++)
tlb[i].valid = FALSE; tlb[i].valid = FALSE;

Binary file not shown.

View file

@ -99,8 +99,13 @@ AddrSpace::AddrSpace (OpenFile * executable)
pageTable = new TranslationEntry[numPages]; pageTable = new TranslationEntry[numPages];
for (i = 0; i < numPages; i++) for (i = 0; i < numPages; i++)
{ {
pageTable[i].physicalPage = i; // for now, phys page # = virtual page # // pageTable[i].physicalPage = i; // for now, phys page # = virtual page #
pageTable[i].valid = TRUE; #ifdef CHANGED
int newPage = pageProvider->GetEmptyPage();
ASSERT(newPage != -1);
pageTable[i].physicalPage = newPage;
#endif
pageTable[i].valid = TRUE;
pageTable[i].use = FALSE; pageTable[i].use = FALSE;
pageTable[i].dirty = FALSE; pageTable[i].dirty = FALSE;
pageTable[i].readOnly = FALSE; // if the code segment was entirely on pageTable[i].readOnly = FALSE; // if the code segment was entirely on

View file

@ -4,6 +4,7 @@
#include "system.h" #include "system.h"
PageProvider::PageProvider(int n) { PageProvider::PageProvider(int n) {
DEBUG ('x', "PageProvider constructor, pages: %i\n", n);
page = new BitMap(n); page = new BitMap(n);
page->Mark(0); page->Mark(0);
} }
@ -13,12 +14,13 @@ PageProvider::~PageProvider(){
} }
int PageProvider::GetEmptyPage() { int PageProvider::GetEmptyPage() {
int page = page->Find(); DEBUG ('x', "GetEmptyPage()\n");
if(emptyPage != -1) int newPage = page->Find();
if(newPage == -1)
return -1; return -1;
memset(machine->mainMemory+emptyPage * PageSize, 0, PageSize); memset(machine->mainMemory+newPage * PageSize, 0, PageSize);
DEBUG ('a', "Allocated page: %i\n", page); DEBUG ('x', "PageProvider: Allocated page: %i\n", newPage);
return page; return newPage;
} }
void PageProvider::ReleasePage(int n) { void PageProvider::ReleasePage(int n) {