Question: #include #include #include #include #include #include student _ code.h bool is _ entry _ valid ( PageTableEntry pte ) { return is _ bit
#include
#include
#include
#include
#include
#include "studentcode.h
bool isentryvalidPageTableEntry pte
return isbitsetpte VALIDBIT;
bool isreadenabledPageTableEntry pte
return isbitsetpte READBIT;
bool iswriteenabledPageTableEntry pte
return isbitsetpte WRITEBIT;
bool isexecuteenabledPageTableEntry pte
return isbitsetpte EXECBIT;
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
Find a free page
PFN pfn findfreepagem;
if pfn NUMFRAMES
No free page found
return pfn; Handle this case accordingly
Set the page as used
mpageusedpfn true;
Construct the page table entry
PageTableEntry entry pfn NUMOFFSETBITS;
if canread entry singlebitmaskREADBIT;
if canwrite entry singlebitmaskWRITEBIT;
if canexec entry singlebitmaskEXECBIT;
Set the entry in the page table
mpagepointervpn entry;
return pfn;
Page getpageMMU m VirtualAddress va bool forread, bool forwrite, bool forexecute
Extract VPN from the VirtualAddress
VPN vpn va NUMOFFSETBITS;
Access page table entry directly from MMU
PageTableEntry pte mpagepointervpn;
Check permissions and validity
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
Convert PageTableEntry to PFN
PFN pfn convertPageTableEntrytoPFNpte;
Return the page pointer
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;
I am failing test cases as shown in the pic.
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 vpn vpn ;
VirtualAddress va b NUMVPNBITS NUMOFFSETBITSb;
char str;
str "hello";
these are the two test cases i am failing.
Please solve my my error
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
