hw4 test
This commit is contained in:
@@ -18,57 +18,84 @@
|
||||
|
||||
#define UserStackSize 1024 // increase this as necessary!
|
||||
|
||||
class FrameTable {
|
||||
public:
|
||||
FrameTable();
|
||||
~FrameTable();
|
||||
|
||||
int Allocate();
|
||||
void Release(int phyPageNum);
|
||||
size_t RemainSize();
|
||||
|
||||
private:
|
||||
struct Node {
|
||||
Node *next;
|
||||
int idx;
|
||||
Node(int idx = -1);
|
||||
};
|
||||
|
||||
Node *begin, *end;
|
||||
|
||||
size_t available;
|
||||
int *useCount;
|
||||
};
|
||||
|
||||
class AddrSpace {
|
||||
public:
|
||||
AddrSpace(); // Create an address space.
|
||||
~AddrSpace(); // De-allocate an address space
|
||||
public:
|
||||
AddrSpace(); // Create an address space.
|
||||
~AddrSpace(); // De-allocate an address space
|
||||
|
||||
bool Load(char *fileName); // Load a program into addr space from
|
||||
// a file
|
||||
// return false if not found
|
||||
bool Load(char* fileName); // Load a program into addr space from
|
||||
// a file
|
||||
// return false if not found
|
||||
|
||||
void Execute(char *fileName); // Run a program
|
||||
// assumes the program has already
|
||||
// been loaded
|
||||
void Execute(char* fileName); // Run a program
|
||||
// assumes the program has already
|
||||
// been loaded
|
||||
|
||||
void SaveState(); // Save/restore address space-specific
|
||||
void RestoreState(); // info on a context switch
|
||||
void SaveState(); // Save/restore address space-specific
|
||||
void RestoreState(); // info on a context switch
|
||||
|
||||
// Translate virtual address _vaddr_
|
||||
// to physical address _paddr_. _mode_
|
||||
// is 0 for Read, 1 for Write.
|
||||
ExceptionType Translate(unsigned int vaddr, unsigned int *paddr, int mode);
|
||||
// Translate virtual address _vaddr_
|
||||
// to physical address _paddr_. _mode_
|
||||
// is 0 for Read, 1 for Write.
|
||||
ExceptionType Translate(unsigned int vaddr, unsigned int* paddr, int mode);
|
||||
|
||||
private:
|
||||
TranslationEntry *pageTable;
|
||||
unsigned int numPages; // Number of pages in the virtual
|
||||
// address space
|
||||
private:
|
||||
TranslationEntry* pageTable; // Assume linear page table translation
|
||||
// for now!
|
||||
unsigned int numPages; // Number of pages in the virtual
|
||||
// address space
|
||||
|
||||
void InitRegisters(); // Initialize user-level CPU registers,
|
||||
// before jumping to user code
|
||||
void InitRegisters(); // Initialize user-level CPU registers,
|
||||
// before jumping to user code
|
||||
|
||||
};
|
||||
|
||||
#endif // ADDRSPACE_H
|
||||
|
||||
#ifndef FRAME_TABLE_H
|
||||
#define FRAME_TABLE_H
|
||||
|
||||
#include "machine.h"
|
||||
#include "list.h"
|
||||
|
||||
/**
|
||||
* Data structure of Virtual Memory
|
||||
*/
|
||||
typedef TranslationEntry* PageTable;
|
||||
|
||||
/**
|
||||
* Data structure of Physical Memory
|
||||
*/
|
||||
class FrameTable {
|
||||
public:
|
||||
/**
|
||||
* Initialize a frame table
|
||||
*/
|
||||
FrameTable();
|
||||
~FrameTable();
|
||||
|
||||
/**
|
||||
* Allocate pageNum of frames (pages) and collect
|
||||
* corresponding translation information into a page table.
|
||||
*
|
||||
* @param pageNum numbers of pages
|
||||
* @return a new Page table, NULL if not enough memory space
|
||||
*/
|
||||
PageTable Allocate(uint pageNum);
|
||||
|
||||
/**
|
||||
* Release the physical memory frame
|
||||
* which the info stored in PageTable
|
||||
*/
|
||||
void Release(PageTable ptb, int pageNum);
|
||||
|
||||
/**
|
||||
* @return the remaining numbers of entry of the frame table
|
||||
*/
|
||||
uint RemainSize();
|
||||
|
||||
private:
|
||||
List<int> available;
|
||||
};
|
||||
|
||||
#endif /* FRAME_TABLE_H */
|
||||
Reference in New Issue
Block a user