From 7baf28a82d85fb76e2197bd770df8d19eeab1647 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Fri, 26 Nov 2021 08:38:39 +0100 Subject: [PATCH] MMU but in C --- kernel/paging.c | 10 ++++++++-- kernel/paging.h | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/kernel/paging.c b/kernel/paging.c index a4f1296..97faaab 100644 --- a/kernel/paging.c +++ b/kernel/paging.c @@ -1,8 +1,14 @@ #include "paging.h" +// Page Entry struct struct page_entry { unsigned int index; unsigned int start_addr; -}; +} page_table[PAGE_TABLE_SIZE]; -page_entry page_table[PAGE_TABLE_SIZE]; +int get_phys_addr(int virt_addr) { + int index = virt_addr / PAGE_SIZE; // page index for the virtual address + int offset = virt_addr % PAGE_SIZE; // actual physical offset for the address + + return page_table[index].start_addr + offset; +} diff --git a/kernel/paging.h b/kernel/paging.h index fa20b2e..9fb6bc2 100644 --- a/kernel/paging.h +++ b/kernel/paging.h @@ -2,5 +2,6 @@ #define PAGE_TABLE_SIZE 128 struct page_entry; -// page_entry page_table[PAGE_TABLE_SIZE]; +char** heap_alloc(unsigned int size); // Process heap allocation +int get_phys_addr(int virt_addr);