aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-01-09 12:28:43 -0500
committerRaghuram Subramani <raghus2247@gmail.com>2025-01-09 12:28:43 -0500
commit36b9c0960d8cf7900e4b7cec16b2d6a2fd801e67 (patch)
tree62e59b8fdbc9309815790c2cc68312865d0e61ab
parentc39920c3a3ef0544feef6c325673506c0e3fac88 (diff)
Revert "kernel: mm: physical: Refactor into separate files"
This reverts commit c39920c3a3ef0544feef6c325673506c0e3fac88.
-rw-r--r--kernel/CMakeLists.txt3
-rw-r--r--kernel/include/mm/physical_mm.h9
-rw-r--r--kernel/mm/physical_mm/allocation.c51
-rw-r--r--kernel/mm/physical_mm/physical_mm.c (renamed from kernel/mm/physical_mm/initialization.c)41
4 files changed, 45 insertions, 59 deletions
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt
index 6535f04..973abb2 100644
--- a/kernel/CMakeLists.txt
+++ b/kernel/CMakeLists.txt
@@ -12,8 +12,7 @@ set(SRC
kernel/io/io.c
mm/memory_map.c
- mm/physical_mm/initialization.c
- mm/physical_mm/allocation.c
+ mm/physical_mm/physical_mm.c
mm/physical_mm/memory_map.c
drivers/vga_text_buffer/vga_text_buffer.c
diff --git a/kernel/include/mm/physical_mm.h b/kernel/include/mm/physical_mm.h
index 06039eb..6befcb0 100644
--- a/kernel/include/mm/physical_mm.h
+++ b/kernel/include/mm/physical_mm.h
@@ -34,13 +34,10 @@
void physical_mm_init(void);
-uint32_t physical_mm_find_first_free_block(uint32_t *memory_map);
+uint32_t physical_mm_find_first_free_block(void);
-void *physical_mm_allocate_block(uint32_t *total_free_blocks,
- uint32_t *memory_map);
-void physical_mm_free_block(void *physical_address,
- uint32_t *total_free_blocks,
- uint32_t *memory_map);
+void *physical_mm_allocate_block(void);
+void physical_mm_free_block(void *physical_address);
void physical_mm_set_used(const uint32_t bit,
uint32_t *total_free_blocks,
diff --git a/kernel/mm/physical_mm/allocation.c b/kernel/mm/physical_mm/allocation.c
deleted file mode 100644
index 85d945f..0000000
--- a/kernel/mm/physical_mm/allocation.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include <stdbool.h>
-#include <stdint.h>
-
-#include <libk/stdio.h>
-
-#include <mm/physical_mm.h>
-
-#include <kernel/halt.h>
-
-uint32_t
-physical_mm_find_first_free_block(uint32_t *memory_map)
-{
- /* 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 (memory_map[i] != 0xffffffff)
- /* Test each bit to see if it's zero */
- for (uint32_t j = 0; j < BITMAP_ENTRY_SIZE; j++)
- if (!physical_mm_test_bit(i * BITMAP_ENTRY_SIZE + j, 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 *
-physical_mm_allocate_block(uint32_t *total_free_blocks, uint32_t *memory_map)
-{
- if (total_free_blocks == 0) {
- printk("physical_mm", "No more free blocks!");
- return NULL;
- }
-
- uint32_t block = physical_mm_find_first_free_block(memory_map);
-
- physical_mm_set_used(block, total_free_blocks, memory_map);
-
- uint32_t physical_address = block * BLOCK_SIZE;
- return (void *) physical_address;
-}
-
-void
-physical_mm_free_block(void *physical_address,
- uint32_t *total_free_blocks,
- uint32_t *memory_map)
-{
- uint32_t block = ((uint32_t) physical_address) / BLOCK_SIZE;
- physical_mm_set_usable(block, total_free_blocks, memory_map);
-}
diff --git a/kernel/mm/physical_mm/initialization.c b/kernel/mm/physical_mm/physical_mm.c
index 779760c..2040fbd 100644
--- a/kernel/mm/physical_mm/initialization.c
+++ b/kernel/mm/physical_mm/physical_mm.c
@@ -112,3 +112,44 @@ physical_mm_init(void)
free_blcks);
#endif
}
+
+uint32_t
+physical_mm_find_first_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 (memory_map[i] != 0xffffffff)
+ /* Test each bit to see if it's zero */
+ for (uint32_t j = 0; j < BITMAP_ENTRY_SIZE; j++)
+ if (!physical_mm_test_bit(i * BITMAP_ENTRY_SIZE + j, 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 *
+physical_mm_allocate_block(void)
+{
+ if (total_free_blocks == 0) {
+ printk("physical_mm", "No more free blocks!");
+ return NULL;
+ }
+
+ uint32_t block = physical_mm_find_first_free_block();
+
+ physical_mm_set_used(block, &total_free_blocks, memory_map);
+
+ uint32_t physical_address = block * BLOCK_SIZE;
+ return (void *) physical_address;
+}
+
+void
+physical_mm_free_block(void *physical_address)
+{
+ uint32_t block = ((uint32_t) physical_address) / BLOCK_SIZE;
+ physical_mm_set_usable(block, &total_free_blocks, memory_map);
+}