diff --git a/code/Makefile.common b/code/Makefile.common index 23fb09a..971481c 100644 --- a/code/Makefile.common +++ b/code/Makefile.common @@ -31,7 +31,8 @@ THREAD_O := main.o list.o scheduler.o synch.o synchlist.o \ stats.o sysdep.o timer.o USERPROG_O := addrspace.o bitmap.o exception.o progtest.o console.o \ - consoledriver.o machine.o mipssim.o translate.o userthread.o + consoledriver.o machine.o mipssim.o translate.o \ + userthread.o papeprovider.o VM_O := diff --git a/code/machine/machine.cc b/code/machine/machine.cc index af290ec..6593c34 100644 --- a/code/machine/machine.cc +++ b/code/machine/machine.cc @@ -61,6 +61,10 @@ Machine::Machine(bool debug) mainMemory = new char[MemorySize]; for (i = 0; i < MemorySize; i++) mainMemory[i] = 0; + #ifdef CHANGED + pageProvider = new PageProvider((int)(MemorySize/PageSize)); + #endif + DEBUG ('a', "Allocated page: %i\n", page); #ifdef USE_TLB tlb = new TranslationEntry[TLBSize]; for (i = 0; i < TLBSize; i++) diff --git a/code/machine/machine.h b/code/machine/machine.h index 79556db..5e00f85 100644 --- a/code/machine/machine.h +++ b/code/machine/machine.h @@ -26,6 +26,10 @@ #include "translate.h" #include "disk.h" +#ifdef CHANGED +#include "pageprovider.h" +#endif + // Definitions related to the size, and format of user memory #define PageSize SectorSize // set the page size equal to @@ -201,7 +205,9 @@ class Machine:public dontcopythis { TranslationEntry *currentPageTable; unsigned int currentPageTableSize; - + #ifdef CHANGED + PageProvider * pageProvider; + #endif // CHANGED private: bool singleStep; // drop back into the debugger after each // simulated instruction diff --git a/code/userprog/pageprovider.cc b/code/userprog/pageprovider.cc new file mode 100644 index 0000000..0a75e96 --- /dev/null +++ b/code/userprog/pageprovider.cc @@ -0,0 +1,33 @@ +#ifdef CHANGED +#include "bitmap.h" +#include "pageprovider.h" +#include "system.h" + +PageProvider::PageProvider(int n) { + page = new BitMap(n); + page->Mark(0); +} + +PageProvider::~PageProvider(){ + delete page; +} + +int PageProvider::GetEmptyPage() { + int page = page->Find(); + if(emptyPage != -1) + return -1; + memset(machine->mainMemory+emptyPage * PageSize, 0, PageSize); + DEBUG ('a', "Allocated page: %i\n", page); + return page; +} + +void PageProvider::ReleasePage(int n) { + DEBUG ('a', "Release page: %i\n", page); + page->Clear(n); +} + +int PageProvider::NumAvailPage() { + return page->NumClear(); +} + +#endif //CHANGED diff --git a/code/userprog/pageprovider.h b/code/userprog/pageprovider.h new file mode 100644 index 0000000..357be32 --- /dev/null +++ b/code/userprog/pageprovider.h @@ -0,0 +1,19 @@ +#ifndef PAGEPROVIDER_H +#define PAGEPROVIDER_H +#ifdef CHANGED + +#include "bitmap.h" + +class PageProvider { +public: + PageProvider(int n); + ~PageProvider(); + int GetEmptyPage(); + void ReleasePage(int n); + int NumAvailPage(); + BitMap* page; +}; + +#endif +#endif // PAGEPROVIDER_H +