Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include #include #include #include student _ code.h bool is _ entry _ valid ( PageTableEntry pte ) { return ( pte &
#include
#include
#include
#include
#include
#include "studentcode.h
bool isentryvalidPageTableEntry pte
return pte & singlebitmaskVALIDBIT;
bool isreadenabledPageTableEntry pte
todo
Question: Implement this function. Hint: it can take as little as line.
return isbitsetpte READBIT;
bool iswriteenabledPageTableEntry pte
todo
return pte & singlebitmaskWRITEBIT;
bool isexecuteenabledPageTableEntry pte
todo
return pte & singlebitmaskEXECBIT;
PFN findfreepageMMU m
for PFN i ; i NUMFRAMES; i
if mpageusedi Check if the page is not used
return i; Return the first free page index
return ; Indicate no free pages found
PFN convertPageTableEntrytoPFNPageTableEntry pte
todo
PageTableEntry mask ~PageTableEntry; All bits set to
mask mask NUMBITSINBYTE sizeofPageTableEntry; Shift to get least significant bits
return pte & mask;
Page Table Functions
PageTableEntry getpagetableentryMMUpagetableMMU m VPN vpn
todo
return mpagepointervpn;
PFN mappageMMUpagetableMMU m VPN vpn bool canread, bool canwrite, bool canexec
todo
PFN pfn findfreepagem;
if pfn NUMFRAMES
No free page found
return pfn; Handle this case accordingly
Set the page as used
mpageusedpfn true;
PageTableEntry entry ; Initialize to zero
if canread entry singlebitmaskREADBIT;
if canwrite entry singlebitmaskWRITEBIT;
if canexec entry singlebitmaskEXECBIT;
Set PFN bits
entry pfn;
Assuming pagepointer is a D array representing the page table
mpagepointervpn entry;
return pfn;
Page getpageMMU m VirtualAddress va bool forread, bool forwrite, bool forexecute
todo
VPN vpn va NUMOFFSETBITS; Extract the VPN from the VirtualAddress
PageTableEntry pte mgetpagetableentrym vpn;
if isentryvalidpte return NULL; Page not present
if forread && isreadenabledpte return NULL; No read permission
if forwrite && iswriteenabledpte return NULL; No write permission
if forexecute && isexecuteenabledpte return NULL; No execute permission
PFN pfn convertPageTableEntrytoPFNpte;
return Pagemphysicalmemory pfn PAGESIZE;
char readbyteMMU m VirtualAddress va
todo
Page page getpagem va true, false, false;
if page
OFFSET offset va & getmaskNUMOFFSETBITS;
return pagedataoffset;
Handle error if page is NULL, eg no read permission or page not present
return ;
void writebyteMMU m VirtualAddress va char val
todo
Page page getpagem va false, true, false;
if page
OFFSET offset va & getmaskNUMOFFSETBITS;
pagedataoffset val;
My two test cases are failing.
These are the taest cases.
"FAILED":
"mappageMMUpagetable",
"endtoend"
These are the test cases.
TestMMUPageTable, mappageMMUpagetable
See the random number
srand timeNULL;
Create a new MMU
MMU m newMMUpagetable;
Create the page pointer aka the page pointer so we can use it
mpagepointer callocNUMPAGES, sizeofPageTableEntry;
mpageused callocNUMFRAMES, sizeofbool;
for int i ; i NUMBEROFREPEATS; i
int pagetotest rand NUMPAGES;
mappageMMUpagetable
&m The MMU we created
pagetotest, The page number we're testing
pagetotest Something random but repeatable
pagetotest Something random but repeatable
pagetotest Something random but repeatable
;
PageTableEntry pte mpagepointerpagetotest;
Check that the PageTableEntry is pointing to the right place
crassert
getmaskNUMPFNBITS NUMOFFSETBITS & pte
i
;
crassertisentryvalidpte;
crassertisreadenabledpte pagetotest ;
crassertiswriteenabledpte pagetotest ;
crassertisexecuteenabledpte pagetotest ;
cleanupMMUm;
void writestringMMU m VirtualAddress va char str
int i;
for i ; stri; i
writebytem vai stri;
writebytem vai;
TestMMUPageTable, endtoend
Create a new MMU
MMU m newMMUpagetable;
for VPN vpn ; vpn NUMPAGES ; vpn
if vpn NUMPAGES
mmappage&m vpn true, true, true;
else
mmappage&m vpn vpn
Can you solve the problem?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started