Answered step by step
Verified Expert Solution
Link Copied!

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 "student_code.h"
bool is_entry_valid(PageTableEntry pte){
return (pte & single_bit_mask(VALID_BIT))!=0;
}
bool is_read_enabled(PageTableEntry pte){
// todo
// Question: Implement this function. Hint: it can take as little as 1 line.
return is_bit_set(pte, READ_BIT);
}
bool is_write_enabled(PageTableEntry pte){
// todo
return pte & single_bit_mask(WRITE_BIT);
}
bool is_execute_enabled(PageTableEntry pte){
// todo
return pte & single_bit_mask(EXEC_BIT);
}
PFN find_free_page(MMU m){
for (PFN i =0; i NUM_FRAMES; i++){
if (!m.page_used[i]){// Check if the page is not used
return i; // Return the first free page index
}
}
return -1; // Indicate no free pages found
}
PFN convert_PageTableEntry_to_PFN(PageTableEntry pte){
// todo
PageTableEntry mask = ~((PageTableEntry)0); // All bits set to 1
mask = mask >>(NUM_BITS_IN_BYTE * sizeof(PageTableEntry)-4); // Shift to get 4 least significant bits
return pte & mask;
}
/*
* Page Table Functions
*/
PageTableEntry get_pagetableentry__MMU_pagetable(MMU m, VPN vpn){
// todo
return m.page_pointer[vpn];
}
PFN map_page__MMU_pagetable(MMU* m, VPN vpn, bool can_read, bool can_write, bool can_exec){
// todo
PFN pfn = find_free_page(*m);
if (pfn == NUM_FRAMES){
// No free page found
return pfn; // Handle this case accordingly
}
// Set the page as used
m->page_used[pfn]= true;
PageTableEntry entry = pfn;
if (can_read) entry |= single_bit_mask(READ_BIT);
if (can_write) entry |= single_bit_mask(WRITE_BIT);
if (can_exec) entry |= single_bit_mask(EXEC_BIT);
// Assuming page_pointer is a 1D array representing the page table
m->page_pointer[vpn]= entry;
return pfn;
}
/*
* Page Directory Functions
*/
Page* get_page(MMU m, VirtualAddress va, bool for_read, bool for_write, bool for_execute){
// todo
VPN vpn = va >> NUM_OFFSET_BITS; // Extract the VPN from the VirtualAddress
PageTableEntry pte = m.get_pagetableentry(m, vpn);
if (!is_entry_valid(pte)) return NULL; // Page not present
if (for_read && !is_read_enabled(pte)) return NULL; // No read permission
if (for_write && !is_write_enabled(pte)) return NULL; // No write permission
if (for_execute && !is_execute_enabled(pte)) return NULL; // No execute permission
PFN pfn = convert_PageTableEntry_to_PFN(pte);
return (Page*)(m.physical_memory + pfn * PAGE_SIZE);
}
char read_byte(MMU m, VirtualAddress va){
// todo
Page* page = get_page(m, va, true, false, false);
if (page){
OFFSET offset = va & get_mask(NUM_OFFSET_BITS);
return page->data[offset];
}
// Handle error if page is NULL, e.g., no read permission or page not present
return -1;
}
void write_byte(MMU m, VirtualAddress va, char val){
// todo
Page* page = get_page(m, va, false, true, false);
if (page){
OFFSET offset = va & get_mask(NUM_OFFSET_BITS);
page->data[offset]= val;
}
}
Some problem is there in this code that why's the test case end to end and getmap page are failing.
PFN map_page__MMU_pagetable(MMU* m, VPN vpn, bool can_read, bool can_write, bool can_exec){
// todo
PFN pfn = find_free_page(*m);
if (pfn == NUM_FRAMES){
// No free page found
return pfn; // Handle this case accordingly
}
// Set the page as used
m->page_used[pfn]= true;
PageTableEntry entry = pfn;
if (can_read) entry |= single_bit_mask(READ_BIT);
if (can_write) entry |= single_bit_mask(WRITE_BIT);
if (can_exec) entry |= single_bit_mask(EXEC_BIT);
// Assuming page_pointer is a 1D array representing the page table
m->page_pointer[vpn]= entry;
return pfn;
}
/*
* Page Directory Functions
*/
Page* get_page(MMU m, VirtualAddress va, bool for_read, bool for_write, bool for_execute){
// todo
VPN vpn = va >> NUM_OFFSET_BITS; // Extract the VPN from the VirtualAddress
PageTableEntry pte = m.get_pagetableentry(m, vpn);
if (!is_entry_valid(pte)) return NULL; // Page not present
if (for_read && !is_read_enabled(pte)) return NULL; // No read permission
if (for_write && !is_write_enabled(pte)) return NULL; // No write permission
if (for_execute && !is_execute_enabled(pte)) return NULL; // No execute permission
PFN pfn = convert_PageTableEntry_to_PFN(pte);
return (Page*)(m.physical_memory + pfn * PAGE_SIZE);
}
char read_byte(MMU m, VirtualAddress va){
// todo
Page* page = get_page(m, va, true, false, false);
if (page){
OFFSET offset = va & get_mask(NUM_OFFSET_BITS);
return page->data[offset];
}
// Handle error if page is NULL, e.g., no read permission or page not present
return -1;
}
void write_byte(MMU m, VirtualAddress va, char val){
// todo
Page* page = get_page(m, va, false, true, false);
if (page){
OFFSET offset = va
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

More Books

Students also viewed these Databases questions