TD3:I5 Implement PageProvide, untested for now

This commit is contained in:
Yorick Barbanneau 2021-12-07 22:50:52 +01:00
parent f3fe45a1de
commit 469c62ee82
5 changed files with 65 additions and 2 deletions

View file

@ -31,7 +31,8 @@ THREAD_O := main.o list.o scheduler.o synch.o synchlist.o \
stats.o sysdep.o timer.o stats.o sysdep.o timer.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 userthread.o consoledriver.o machine.o mipssim.o translate.o \
userthread.o papeprovider.o
VM_O := VM_O :=

View file

@ -61,6 +61,10 @@ 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 CHANGED
pageProvider = new PageProvider((int)(MemorySize/PageSize));
#endif
DEBUG ('a', "Allocated page: %i\n", page);
#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++)

View file

@ -26,6 +26,10 @@
#include "translate.h" #include "translate.h"
#include "disk.h" #include "disk.h"
#ifdef CHANGED
#include "pageprovider.h"
#endif
// Definitions related to the size, and format of user memory // Definitions related to the size, and format of user memory
#define PageSize SectorSize // set the page size equal to #define PageSize SectorSize // set the page size equal to
@ -201,7 +205,9 @@ class Machine:public dontcopythis {
TranslationEntry *currentPageTable; TranslationEntry *currentPageTable;
unsigned int currentPageTableSize; unsigned int currentPageTableSize;
#ifdef CHANGED
PageProvider * pageProvider;
#endif // CHANGED
private: private:
bool singleStep; // drop back into the debugger after each bool singleStep; // drop back into the debugger after each
// simulated instruction // simulated instruction

View file

@ -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

View file

@ -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