This second lab will explore how a basic memory paging system works.
This lab is an individual deliverable.
Submit your C code, along with sample output.
Email me your deliverable before midnight 27 September 2024.
You will need a c compiler as well as text editor/IDE to do this lab. If you need a bit of a refresher, our book authors provide a very nice introduction and guide here.
You will implement a simple page table and simulate memory accesses.
We will write a C program that simulates a basic paging system with the following components:
A small virtual address space (e.g., 16 pages)
A physical memory with fewer pages (e.g., 8 pages)
A simple page table to map virtual pages to physical pages
Functions to allocate, access, and free memory
Download it here. Note that this code lacks a bunch of stuff, so there are some errors you will need to address (for example there are some functions you need to write which don't have a return statement (yet).
Correction: Note that the code file contains a reference to a physical_memory variable. You can ignore that. No need to do anything with that for the purposes of this lab (unless you absolutely feel compelled to :) ).
Also be sure to read through the code that is already there so you can understand what the value types for certain states are.
A main() method is provided. You can change this if you like, as long as your program demonstrates the proper functioning of the following components:
Page Table: Creates an array to represent the page table, mapping virtual pages to physical pages.
Memory Allocation: Allocates a virtual page and maps it to an available physical page.
Memory Access (already done): Implements a function that takes a virtual address and returns the corresponding physical address using the page table.
Page Fault Handling (already done): If a virtual page is not mapped, simulate a page fault by printing a message and mapping it to an available physical page.
Memory Deallocation: Frees a virtual page and its corresponding physical page.