root -+-- CMakeLists.txt
|-- main.c
|-- Makefile
+-- inc
| |-- memory.h
| |-- process.h
| |-- PTE.h
| |-- simulator.h
| |-- TLB.h
| +-- utils.h
|
+-- src
|-- memory.c
|-- process.c
|-- simulator.c
+-- TLB.c
You will need one of CMakeLists.txt and Makefile to compile. You pick either of them. Gradescope will use the Makefile.
memory.c and process.c,
where the resource allocation code is given.
simulator.h/c: status_t allocate_page(Process *process, addr_t address, addr_t physical_address)simulator.h/c: status_t deallocate_page(Process *process, addr_t address)simulator.h/c: status_t write_byte(Process *process, addr_t address, const byte_t *byte)simulator.h/c: status_t read_byte(Process *process, addr_t address, byte_t *byte)TLB.h/c: unsigned read_TLB(proc_id_t pid, unsigned vpn)TLB.h/c: void write_TLB(proc_id_t pid, unsigned vpn, unsigned ppn)TLB.h/c: void remove_TLB(proc_id_t pid, unsigned vpn)simulator.h/c)#define L1_BITS 12 bits as the index, and the L2 page table takes #define L2_BITS 8 bits.
status_t allocate_page(Process *process, addr_t address, addr_t physical_address):process: the process that we're working with.address: the virtual address of the page.physical_address: the physical address of the page.SUCCESS if the page is successfully allocated, otherwise return ERROR.address and physical_address are both addresses instead of page numbers, and the input is guaranteed to be page-aligned.
It is possible (and should work perfectly) that two different virtual pages are mapped to the same physical page, no matter whether the two virtual pages are in the same process or not.
ERROR in these two scenarios:
If the physical memory is not large enough to provide the required physical page.
If the virtual page has already been allocated.
status_t deallocate_page(Process *process, addr_t address):process: the process that we're working with.address: the virtual address of the page.SUCCESS if the page is successfully deallocated, otherwise return ERROR.ERROR in this case.
In addition, if the last page in the L2 page table is deallocated, you should also deallocate the page table to save memory.
status_t write_byte(Process *process, addr_t address, const byte_t *byte) and status_t read_byte(Process *process, addr_t address, byte_t *byte):address with the value of const byte_t *byte, or read the value from the address and copy it to
byte_t *byte.
ERROR if the address is not allocated.TLB_HITSUCCESSTLB.h/c)clock in struct TLB and lut in TLB_entry to help you implement the
LRU policy. You can also have your own implementation.
process->pid, and the pid of the TLB can be obtained by tlb->pid.
git commitgit pushgoto step_2;-Wpedantic -Wall -Wextra -Wvla -Werror -std=c11Valgrind will be used to detect memory leaks on runtime.return SUCCESS. We will manually check this kind of (or similar) implementation and will give 0 points for it.