TD3:I5 Implement PageProvide, untested for now
This commit is contained in:
parent
f3fe45a1de
commit
469c62ee82
5 changed files with 65 additions and 2 deletions
|
@ -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 :=
|
||||
|
||||
|
|
|
@ -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++)
|
||||
|
|
|
@ -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
|
||||
|
|
33
code/userprog/pageprovider.cc
Normal file
33
code/userprog/pageprovider.cc
Normal 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
|
19
code/userprog/pageprovider.h
Normal file
19
code/userprog/pageprovider.h
Normal 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
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue