From ab93ad2de12a1376d98fcc6c533ccefc3f64654a Mon Sep 17 00:00:00 2001 From: lucic71 Date: Tue, 28 Jun 2022 19:40:51 +0300 Subject: [PATCH] Updated vmm and pmm --- kernel/include/kernel/pmm.h | 6 ++-- kernel/include/kernel/vmm.h | 70 ++++++++++--------------------------- kernel/pmm/src/pmm.c | 4 +-- 3 files changed, 24 insertions(+), 56 deletions(-) diff --git a/kernel/include/kernel/pmm.h b/kernel/include/kernel/pmm.h index f33ff6b..a9ef40e 100644 --- a/kernel/include/kernel/pmm.h +++ b/kernel/include/kernel/pmm.h @@ -12,12 +12,12 @@ * pmm_init: * Initializes the Physical Memory Manager. * - * @param mmap_addr - Physical memory address of memory map data structure - * @param size - Size of available physical memory in KB + * @param pmmap_addr - Physical memory address of memory map data structure + * @param size - Size of available physical memory in KB * */ -void pmm_init(uint32_t mmap_addr, size_t size); +void pmm_init(uint32_t pmmap_addr, size_t size); /* * pmm_init_region: diff --git a/kernel/include/kernel/vmm.h b/kernel/include/kernel/vmm.h index e34e8b8..13c2b1d 100644 --- a/kernel/include/kernel/vmm.h +++ b/kernel/include/kernel/vmm.h @@ -1,71 +1,39 @@ #ifndef VMM_H_ #define VMM_H_ +#include + /* * vmm_init: - * Initialize the Virtual Memory Manager. + * Initialize the Virtual Memory Manager. At the moment it does not + * support Higher Half Kernel. It just identity-maps the first 4MB + * of physical memory. * */ void vmm_init(void); -/* - * vmm_ptable_search: - * Given a virtual address, search for its corresponding entry - * in Page Table. - * - * @param ptable - Pointer to the beginning of the Page Table - * @param virt_addr - Virtual address - * - * @return - Pointer to corresponding Page Table entry - * - */ - -uint32_t *vmm_ptable_search(uint32_t *ptable, uint32_t virt_addr); - -/* - * vmm_pdir_search: - * Given a virtual address, search for its corresponding entry - * in Page Directory. - * - * @param pdir - Pointer to the beginning of the Page Directory - * @param virt_addr - Virtual address - * - * @return - Pointer to corresponding Page Directory entry - * - */ - -uint32_t *vmm_pdir_search(uint32_t *pdir, uint32_t virt_addr); - -/* - * vmm_install_pdir: - * Install a Page Directory. - * - * @param pdir - Pointer to a Page Directory - * - */ - -void vmm_install_pdir(uint32_t *pdir); - -/* - * vmm_flush_tlb: - * Flush the Translation Lookaside Buffer. - * - * @param virt_tlb - Virtual address of TLB - * - */ - -void vmm_flush_tlb(uint32_t virt_tlb); - /* * vmm_map_page: - * Maps physical address to virtual address. + * Maps physical address to virtual address. This routine must be called + * only after paging was enabled (aka after vmm_init). * * @param phys - Physical address * @param virt - Virtual address * */ -void vmm_map_addr(uint32_t phys, uint32_t virt); +int vmm_map_addr(uint32_t phys, uint32_t virt); + +/* + * vmm_unmap_page: + * Unmaps a virtual address. This routine must be called only after paging + * was enabled (aka after vmm_init). + * + * @param virt - Virtual address + * + */ + +void vmm_unmap_addr(uint32_t virt); #endif diff --git a/kernel/pmm/src/pmm.c b/kernel/pmm/src/pmm.c index 09e9d53..e322fa9 100644 --- a/kernel/pmm/src/pmm.c +++ b/kernel/pmm/src/pmm.c @@ -17,12 +17,12 @@ * */ -void pmm_init(uint32_t mmap_addr, size_t size) { +void pmm_init(uint32_t pmmap_addr, size_t size) { mem_size = size; max_blocks = (mem_size * 1024) / BLOCK_SIZE; used_blocks = max_blocks; - pmmap = (uint32_t *) mmap_addr; + pmmap = (uint32_t *) pmmap_addr; pmmap_size = mem_size / BLOCKS_PER_BYTE; if (mem_size % BLOCKS_PER_BYTE)