diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-09-16 11:43:14 -0400 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-09-16 11:43:14 -0400 |
commit | fa7e8e6534451c0e8f755bcb9c7bad1d99de001f (patch) | |
tree | a4d72349caba1aac788ce8a0e2f62c59c07f6166 | |
parent | 926c59b9d34d84ef4aee995a6b868be858b6c84e (diff) |
mm: physical_mm: add comments to function headers
-rw-r--r-- | kernel/include/mm/physical_mm.h | 20 | ||||
-rw-r--r-- | kernel/mm/physical_mm/bitmap.cc | 6 | ||||
-rw-r--r-- | kernel/mm/physical_mm/physical_mm.cc | 36 |
3 files changed, 37 insertions, 25 deletions
diff --git a/kernel/include/mm/physical_mm.h b/kernel/include/mm/physical_mm.h index 2fa85ea..3075bf9 100644 --- a/kernel/include/mm/physical_mm.h +++ b/kernel/include/mm/physical_mm.h @@ -34,17 +34,35 @@ namespace PhysicalMM { +/* Initialize the memory map by getting all free regions, setting all blocks to + * used, initializing regions marked free by the memory map provided by + * multiboot, and deinitializing the memory used by the kernel */ void initialize(void); -uint32_t find_free_block(void); + +/* Find and allocate a free memory block, returning the physical address of the + * block */ void *allocate_block(void); + +/* Free an allocated memory block, given the physical address (from + * allocate_block) */ void free_block(void *physical_address); +/*-- BITMAP --*/ + +/* Marks the block as 'used' */ void set_used(const uint32_t bit, uint32_t *total_free_blocks, uint32_t *memory_map); + +/* Marks the block as 'unused' */ void set_usable(const uint32_t bit, uint32_t *total_free_blocks, uint32_t *memory_map); + +/* 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); } diff --git a/kernel/mm/physical_mm/bitmap.cc b/kernel/mm/physical_mm/bitmap.cc index 6284173..1c1285d 100644 --- a/kernel/mm/physical_mm/bitmap.cc +++ b/kernel/mm/physical_mm/bitmap.cc @@ -23,7 +23,6 @@ namespace PhysicalMM { -/* Marks the block as 'used' */ void set_used(const uint32_t bit, uint32_t *total_free_blocks, uint32_t *memory_map) { @@ -33,7 +32,6 @@ set_used(const uint32_t bit, uint32_t *total_free_blocks, uint32_t *memory_map) memory_map[memory_map_index] |= bitmask; } -/* Marks the block as 'unused' */ void set_usable(const uint32_t bit, uint32_t *total_free_blocks, @@ -45,10 +43,6 @@ set_usable(const uint32_t bit, 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) { diff --git a/kernel/mm/physical_mm/physical_mm.cc b/kernel/mm/physical_mm/physical_mm.cc index b270d6b..dc9bf0e 100644 --- a/kernel/mm/physical_mm/physical_mm.cc +++ b/kernel/mm/physical_mm/physical_mm.cc @@ -89,6 +89,24 @@ deinitialize_region(uint32_t start, uint32_t length) set_used(bit++, &l_total_free_blocks, l_memory_map); } +ALWAYS_INLINE static uint32_t +find_free_block(void) +{ + /* TODO: Why doesn't using block_count instead of MAX_BLOCKS work? */ + for (uint32_t i = 0; i < MAX_BLOCKS / BITMAP_ENTRY_SIZE; i++) + /* At least one block in the entry isn't in use */ + if (l_memory_map[i] != 0xffffffff) + /* Test each bit to see if it's zero */ + for (uint32_t j = 0; j < BITMAP_ENTRY_SIZE; j++) + if (!test_bit(i * BITMAP_ENTRY_SIZE + j, l_memory_map)) + return i * BITMAP_ENTRY_SIZE + j; + + /* Shouldn't be reached, since we're keeping track of the number of free + * blocks */ + ASSERT_NOT_REACHED(); + return -1; +} + void initialize(void) { @@ -128,24 +146,6 @@ initialize(void) printk("physical_mm", "Total free blocks: 0x%x", l_total_free_blocks); } -uint32_t -find_free_block(void) -{ - /* TODO: Why doesn't using block_count instead of MAX_BLOCKS work? */ - for (uint32_t i = 0; i < MAX_BLOCKS / BITMAP_ENTRY_SIZE; i++) - /* At least one block in the entry isn't in use */ - if (l_memory_map[i] != 0xffffffff) - /* Test each bit to see if it's zero */ - for (uint32_t j = 0; j < BITMAP_ENTRY_SIZE; j++) - if (!test_bit(i * BITMAP_ENTRY_SIZE + j, l_memory_map)) - return i * BITMAP_ENTRY_SIZE + j; - - /* Shouldn't be reached, since we're keeping track of the number of free - * blocks */ - ASSERT_NOT_REACHED(); - return -1; -} - void * allocate_block(void) { |