From 3aa8f7360dced8fbdfdeb7692ce42af07fba14a6 Mon Sep 17 00:00:00 2001 From: lucic71 Date: Tue, 28 Jun 2022 19:40:51 +0300 Subject: [PATCH] Updated pmm interface and changed print_memory_map declaration --- kernel/include/kernel/pmm.h | 57 ++++++++++++++++++++++++++++++++++++- kernel/kernel/kernel.c | 7 ++++- kernel/pmm/src/mmap.c | 15 +--------- 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/kernel/include/kernel/pmm.h b/kernel/include/kernel/pmm.h index da3e56a..2375ce6 100644 --- a/kernel/include/kernel/pmm.h +++ b/kernel/include/kernel/pmm.h @@ -3,6 +3,61 @@ #include "kernel/multiboot.h" +#include +#include + +/* The only supported block size is 4KB. */ + +/* + * pmm_init: + * Initializes the Physical Memory Manager. + * + * @param size - Size of available physical memory + * @param mmap_addr - Physical memory address of memory map data structure + * + */ + +void pmm_init(size_t size, uint32_t mmap_addr); + +/* + * pmm_init_region: + * Initializes a memory region of specified size. + * + * @param base - Base address for region + * @param size - Size of region + * + */ + +void pmm_init_region(uint32_t base, size_t size); + +/* + * pmm_deinit_region: + * Deinitializes a memory region of specified size. + * + * @param base - Base address for region + * @param size - Size of region + * + */ + +void pmm_deinit_region(uint32_t base, size_t size); + +/* + * pmm_alloc_block: + * Allocates a memory block and returns a generic pointer to its physical + * address. + * + */ + +void *pmm_alloc_block(void); + +/* + * pmm_free_block: + * Frees a memory block. + * + */ + +void pmm_free_block(void *p); + /* * print_memory_map * Using the multiboot structure, print memory regions, size @@ -12,7 +67,7 @@ * */ -void print_memory_map(multiboot_info_t *mb_info); +void print_memory_map(multiboot_memory_map_t *mmap, multiboot_memory_map_t *mmap_end); /* * print_ksections diff --git a/kernel/kernel/kernel.c b/kernel/kernel/kernel.c index fe59882..b44e83f 100644 --- a/kernel/kernel/kernel.c +++ b/kernel/kernel/kernel.c @@ -26,7 +26,12 @@ void kmain(multiboot_info_t *mb_info, uint32_t mb_magic) { if (!mb_info) panic("Invalid multiboot pointer"); - print_memory_map(mb_info); + if (!(mb_info->flags & MULTIBOOT_INFO_MEMORY)) + panic("There is no memory info in multiboot"); + + printf("mem_lower: 0x%x B, mem_upper: 0x%x B\n\n", mb_info->mem_lower * 1024, mb_info->mem_upper * 1024); + print_memory_map((multiboot_memory_map_t *) mb_info->mmap_addr, + (multiboot_memory_map_t *) (mb_info->mmap_addr + mb_info->mmap_length)); puts(""); print_kernel_map(); diff --git a/kernel/pmm/src/mmap.c b/kernel/pmm/src/mmap.c index 6ed4b59..b38f8fe 100644 --- a/kernel/pmm/src/mmap.c +++ b/kernel/pmm/src/mmap.c @@ -25,23 +25,10 @@ static char *mem_types[] = { * */ -void print_memory_map(multiboot_info_t *mb_info) { - - if (!(mb_info->flags & MULTIBOOT_INFO_MEM_MAP)) { - - puts("There is no info about memory map"); - return; - - } +void print_memory_map(multiboot_memory_map_t *mmap, multiboot_memory_map_t *mmap_end) { printf("Physical Memory Map:\n"); - multiboot_memory_map_t *mmap = - (multiboot_memory_map_t *) mb_info->mmap_addr; - - multiboot_memory_map_t *mmap_end = - (multiboot_memory_map_t *) (mb_info->mmap_addr + mb_info->mmap_length); - for (int i = 0; mmap < mmap_end; mmap++, i++) { printf("region: %d start: 0x%x length: 0x%x type: %d ", i,