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 \
consoledriver.o machine.o mipssim.o translate.o \
userthread.o papeprovider.o
userthread.o pageprovider.o
VM_O :=

View file

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

Binary file not shown.

View file

@ -99,7 +99,12 @@ AddrSpace::AddrSpace (OpenFile * executable)
pageTable = new TranslationEntry[numPages];
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 #
#ifdef CHANGED
int newPage = pageProvider->GetEmptyPage();
ASSERT(newPage != -1);
pageTable[i].physicalPage = newPage;
#endif
pageTable[i].valid = TRUE;
pageTable[i].use = FALSE;
pageTable[i].dirty = FALSE;

View file

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