Comments
Loading Dream Comments...
You must be logged in to write a comment - Log In
static int g_FrameCount = 0; // GLOBAL check to cause swapping when no more RAM
static PageFrame* g_LRUhead = NULL; // GLOBAL LRU list head
static int g_SwapLBA = 0; // GLOBAL Swappable Page LBA
class PageHeader {
DaTime m_timestamp;
char m_name[16]; // TODO
unsigned long m_chksum; // TODO
byte m_attribflags; // TODO
unsigned long m_version; // TODO
AddressRegister m_AddressRegs[32]; //TODO
public:
PageHeader() {
m_timestamp = NOW;
}
};
class PageFrame {
PageFrame* m_LRUprior;
PageFrame* m_LRUnext;
handle m_h;
int m_lba;
PageHeader m_ph;
unsigned char m_page [32768];
public:
PageFrame(handle h, int lba) {
MUTEXBEGIN
g_FrameCount++;
m_LRUnext = g_LRUhead; // Put this page on the front of the list
g_LRUhead = this;
m_LRUprior = NULL; // This is the most recent page
m_h = h;
m_lba = lba;
FILE_READ(m_h, m_lba, &m_page);
MUTEXEND
}
~PageFrame(void) {
this.CheckPoint();
MUTEXBEGIN
g_FrameCount--;
PageFrame* p = m_LRUprior;
PageFrame* n = m_LRUnext;
p->m_LRUnext = n;
if (n==NULL) g_SwapLBA = p->m_lba;
n->m_LRUprior = p;
MUTEXEND
}
void CheckPoint(void) {
m_timestamp = NOW;
MUTEXBEGIN
FILE_WRITE(m_h, m_lba, m_page);
MUTEXEND
}
unsigned char* operator() () {
MUTEXBEGIN
// Put us at the front of the LRU list
PageFrame* p = m_LRUprior;
PageFrame* n = m_LRUnext;
m_LRUprior = NULL;
m_LRUnext = g_LRUhead;
g_LRUhead = this;
p->m_LRUnext = n;
if (n==NULL) g_SwapLBA = p->m_lba;
n->m_LRUprior = p;
MUTEXEND
return m_page;
}
};
// For the MS-Windows version, define FILE_READ and FILE_WRITE as their Win32 equivalents. Also MUTEXBEGIN and MUTEXEND for multithread safety! For standalone (BIOS) mode, define FILE_READ and FILE_WRITE using INT 13h calls. For Linux or Mac systems, use the appropriate API's. Note that FILE_READ and FILE_WRITE each transfer a 32768 byte block at file position lba*32768. (I.E. The system paging size is 32kB). Have phun :)