From 37efe37910cfe2304d2eeae0a6e2c2891eec7ca4 Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Sat, 1 Feb 2025 03:49:03 -0500 Subject: misc: init()->initialize() --- kernel/CMakeLists.txt | 2 +- kernel/include/mm/physical_mm.h | 2 +- kernel/include/mm/virtual_mm.h | 2 +- kernel/kernel/kernel.cc | 8 ++--- kernel/libk/kmalloc.cc | 2 +- kernel/mm/physical_mm/bitmap.cc | 60 ++++++++++++++++++++++++++++++++++++ kernel/mm/physical_mm/memory_map.cc | 60 ------------------------------------ kernel/mm/physical_mm/physical_mm.cc | 2 +- kernel/mm/virtual_mm/virtual_mm.cc | 2 +- 9 files changed, 70 insertions(+), 70 deletions(-) create mode 100644 kernel/mm/physical_mm/bitmap.cc delete mode 100644 kernel/mm/physical_mm/memory_map.cc diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index e3212b0..c0903fd 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -21,7 +21,7 @@ set(SRC libk/kmalloc.cc mm/memory_map.cc - mm/physical_mm/memory_map.cc + mm/physical_mm/bitmap.cc mm/physical_mm/physical_mm.cc mm/virtual_mm/virtual_mm.cc ) diff --git a/kernel/include/mm/physical_mm.h b/kernel/include/mm/physical_mm.h index b5631c5..2fa85ea 100644 --- a/kernel/include/mm/physical_mm.h +++ b/kernel/include/mm/physical_mm.h @@ -34,7 +34,7 @@ namespace PhysicalMM { -void init(void); +void initialize(void); uint32_t find_free_block(void); void *allocate_block(void); void free_block(void *physical_address); diff --git a/kernel/include/mm/virtual_mm.h b/kernel/include/mm/virtual_mm.h index 313b1f9..29a7f2b 100644 --- a/kernel/include/mm/virtual_mm.h +++ b/kernel/include/mm/virtual_mm.h @@ -85,7 +85,7 @@ bool switch_page_directory(uint32_t *page_directory); /* * Initialize the virtual memory manager */ -void init(void); +void initialize(void); /* * Map a physical address to a virtual address diff --git a/kernel/kernel/kernel.cc b/kernel/kernel/kernel.cc index 98d1f5f..54eb0e5 100644 --- a/kernel/kernel/kernel.cc +++ b/kernel/kernel/kernel.cc @@ -41,11 +41,11 @@ kernel_main(uint32_t magic, multiboot_info_t *multiboot_info) GDT::load(); MemoryMap::load(multiboot_info); - PhysicalMM::init(); - VirtualMM::init(); + PhysicalMM::initialize(); + VirtualMM::initialize(); - // void *x = virtual_mm_find_free_addresses(1046999); - // printk("debug", "x(0x%x)", x); + void *x = VirtualMM::find_free_addresses(1046999); + printk("debug", "x(0x%x)", x); #if 0 int *x = PhysicalMM::allocate_block(); diff --git a/kernel/libk/kmalloc.cc b/kernel/libk/kmalloc.cc index 4afaa61..3c7dd91 100644 --- a/kernel/libk/kmalloc.cc +++ b/kernel/libk/kmalloc.cc @@ -25,7 +25,7 @@ memory_chunk_t *starting_mc = NULL; -static memory_chunk_t * +memory_chunk_t * add_block(void *address, uint32_t size) { memory_chunk_t *mc = (memory_chunk_t *) address; diff --git a/kernel/mm/physical_mm/bitmap.cc b/kernel/mm/physical_mm/bitmap.cc new file mode 100644 index 0000000..6284173 --- /dev/null +++ b/kernel/mm/physical_mm/bitmap.cc @@ -0,0 +1,60 @@ +/* + * bubbl + * Copyright (C) 2025 Raghuram Subramani + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +namespace PhysicalMM +{ + +/* Marks the block as 'used' */ +void +set_used(const uint32_t bit, uint32_t *total_free_blocks, uint32_t *memory_map) +{ + uint32_t memory_map_index = bit / BITMAP_ENTRY_SIZE; + uint32_t bitmask = 1 << (bit % BITMAP_ENTRY_SIZE); + (*total_free_blocks)--; + memory_map[memory_map_index] |= bitmask; +} + +/* Marks the block as 'unused' */ +void +set_usable(const uint32_t bit, + uint32_t *total_free_blocks, + uint32_t *memory_map) +{ + uint32_t memory_map_index = bit / BITMAP_ENTRY_SIZE; + uint32_t bitmask = 1 << (bit % BITMAP_ENTRY_SIZE); + (*total_free_blocks)++; + memory_map[memory_map_index] &= ~bitmask; +} + +/* Returns: + * True if the bit is set (block is in use) + * False if the bit is unset (block isn't in use) + */ +bool +test_bit(const uint32_t bit, uint32_t *memory_map) +{ + uint32_t memory_map_index = bit / BITMAP_ENTRY_SIZE; + uint32_t bitmask = 1 << (bit % BITMAP_ENTRY_SIZE); + return memory_map[memory_map_index] & bitmask; +} + +} diff --git a/kernel/mm/physical_mm/memory_map.cc b/kernel/mm/physical_mm/memory_map.cc deleted file mode 100644 index 6284173..0000000 --- a/kernel/mm/physical_mm/memory_map.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * bubbl - * Copyright (C) 2025 Raghuram Subramani - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include - -namespace PhysicalMM -{ - -/* Marks the block as 'used' */ -void -set_used(const uint32_t bit, uint32_t *total_free_blocks, uint32_t *memory_map) -{ - uint32_t memory_map_index = bit / BITMAP_ENTRY_SIZE; - uint32_t bitmask = 1 << (bit % BITMAP_ENTRY_SIZE); - (*total_free_blocks)--; - memory_map[memory_map_index] |= bitmask; -} - -/* Marks the block as 'unused' */ -void -set_usable(const uint32_t bit, - uint32_t *total_free_blocks, - uint32_t *memory_map) -{ - uint32_t memory_map_index = bit / BITMAP_ENTRY_SIZE; - uint32_t bitmask = 1 << (bit % BITMAP_ENTRY_SIZE); - (*total_free_blocks)++; - memory_map[memory_map_index] &= ~bitmask; -} - -/* Returns: - * True if the bit is set (block is in use) - * False if the bit is unset (block isn't in use) - */ -bool -test_bit(const uint32_t bit, uint32_t *memory_map) -{ - uint32_t memory_map_index = bit / BITMAP_ENTRY_SIZE; - uint32_t bitmask = 1 << (bit % BITMAP_ENTRY_SIZE); - return memory_map[memory_map_index] & bitmask; -} - -} diff --git a/kernel/mm/physical_mm/physical_mm.cc b/kernel/mm/physical_mm/physical_mm.cc index cc70ea6..fb34aef 100644 --- a/kernel/mm/physical_mm/physical_mm.cc +++ b/kernel/mm/physical_mm/physical_mm.cc @@ -91,7 +91,7 @@ deinitialize_region(uint32_t start, uint32_t length) } void -init(void) +initialize(void) { free_memory_regions_t *free_memory_regions = MemoryMap::get_free_regions(); log_memory_map(free_memory_regions); diff --git a/kernel/mm/virtual_mm/virtual_mm.cc b/kernel/mm/virtual_mm/virtual_mm.cc index 2293083..a3e9fee 100644 --- a/kernel/mm/virtual_mm/virtual_mm.cc +++ b/kernel/mm/virtual_mm/virtual_mm.cc @@ -63,7 +63,7 @@ enable_paging(void) } void -init(void) +initialize(void) { for (uint32_t i = 0; i < 1024; i++) page_table[i] = 0; -- cgit v1.2.3