Updated pmm interface and changed print_memory_map declaration

This commit is contained in:
lucic71 2022-06-28 19:40:51 +03:00
parent e866816279
commit 3aa8f7360d
3 changed files with 63 additions and 16 deletions

View File

@ -3,6 +3,61 @@
#include "kernel/multiboot.h"
#include <stdint.h>
#include <stddef.h>
/* 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

View File

@ -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();

View File

@ -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,