diff options
| author | Raghuram Subramani <raghus2247@gmail.com> | 2025-01-31 04:41:37 -0500 |
|---|---|---|
| committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-01-31 04:41:37 -0500 |
| commit | b2e01f02bc9a575ae57a06060df5d807bcf46220 (patch) | |
| tree | 64f29371fcb97f67ff9e3332409cb1aa64d38af9 /kernel/include | |
| parent | 7a0025ab97c42dfa350afbe4d545088c6e16a95a (diff) | |
{physical_mm,virtual_mm,kmalloc}: C->C++
Diffstat (limited to 'kernel/include')
| -rw-r--r-- | kernel/include/kernel/spinlock.h | 15 | ||||
| -rw-r--r-- | kernel/include/libk/kmalloc.h | 8 | ||||
| -rw-r--r-- | kernel/include/mm/physical_mm.h | 35 | ||||
| -rw-r--r-- | kernel/include/mm/virtual_mm.h | 23 |
4 files changed, 32 insertions, 49 deletions
diff --git a/kernel/include/kernel/spinlock.h b/kernel/include/kernel/spinlock.h index e7b8228..ed6bb86 100644 --- a/kernel/include/kernel/spinlock.h +++ b/kernel/include/kernel/spinlock.h @@ -19,17 +19,16 @@ #ifndef __kernel_spinlock_h #define __kernel_spinlock_h -#include <stdatomic.h> +#include <stdint.h> -#ifdef __cplusplus -extern "C" { -#endif +typedef uint8_t spinlock_t; + +namespace Spinlock +{ -void spinlock_acquire(atomic_flag *lock); -void spinlock_release(atomic_flag *lock); +void acquire(spinlock_t volatile *lock); +void release(spinlock_t volatile *lock); -#ifdef __cplusplus } -#endif #endif diff --git a/kernel/include/libk/kmalloc.h b/kernel/include/libk/kmalloc.h index e124c70..85e247a 100644 --- a/kernel/include/libk/kmalloc.h +++ b/kernel/include/libk/kmalloc.h @@ -21,10 +21,6 @@ #include <stdint.h> -#ifdef __cplusplus -extern "C" { -#endif - #define MIN_PAGES 4 typedef struct memory_chunk_t { @@ -36,8 +32,4 @@ typedef struct memory_chunk_t { void *kmalloc(uint32_t size); -#ifdef __cplusplus -} -#endif - #endif diff --git a/kernel/include/mm/physical_mm.h b/kernel/include/mm/physical_mm.h index 0058cc5..b5631c5 100644 --- a/kernel/include/mm/physical_mm.h +++ b/kernel/include/mm/physical_mm.h @@ -31,27 +31,22 @@ /* This is the maximum number of blocks for a 4GiB system. */ #define MAX_BLOCKS 1048576 -#ifdef __cplusplus -extern "C" { -#endif - -void physical_mm_init(void); - -uint32_t physical_mm_find_free_block(void); +namespace PhysicalMM +{ + +void init(void); +uint32_t find_free_block(void); +void *allocate_block(void); +void free_block(void *physical_address); + +void set_used(const uint32_t bit, + uint32_t *total_free_blocks, + uint32_t *memory_map); +void set_usable(const uint32_t bit, + uint32_t *total_free_blocks, + uint32_t *memory_map); +bool test_bit(const uint32_t bit, 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, - uint32_t *memory_map); -void physical_mm_set_usable(const uint32_t bit, - uint32_t *total_free_blocks, - uint32_t *memory_map); -bool physical_mm_test_bit(const uint32_t bit, uint32_t *memory_map); - -#ifdef __cplusplus } -#endif #endif diff --git a/kernel/include/mm/virtual_mm.h b/kernel/include/mm/virtual_mm.h index 6246ce3..313b1f9 100644 --- a/kernel/include/mm/virtual_mm.h +++ b/kernel/include/mm/virtual_mm.h @@ -69,52 +69,49 @@ #define VIRTUAL_ADDRESS(pd_index, pt_index) \ (((pd_index) << 22) | ((pt_index) << 12)) -#ifdef __cplusplus -extern "C" { -#endif +namespace VirtualMM +{ /* * Loads a given page directory into CR0 */ -void virtual_mm_load_page_directory(uint32_t *page_directory); +void load_page_directory(uint32_t *page_directory); /* * Switches the current page directory to a given page directory */ -bool virtual_mm_switch_page_directory(uint32_t *page_directory); +bool switch_page_directory(uint32_t *page_directory); /* * Initialize the virtual memory manager */ -void virtual_mm_initialize(void); +void init(void); /* * Map a physical address to a virtual address */ -void virtual_mm_map_page(void *physical_address, void *virtual_address); +void map_page(void *physical_address, void *virtual_address); /* * Unmap a page starting at virtual address */ -void virtual_mm_unmap_page(void *virtual_address); +void unmap_page(void *virtual_address); /* * Find a virtual address with n consecutive free addresses. */ -void *virtual_mm_find_free_addresses(uint32_t n_pages); +void *find_free_addresses(uint32_t n_pages); /* * Allocate and map n pages. */ -void *virtual_mm_alloc_pages(uint32_t n_pages); +void *alloc_pages(uint32_t n_pages); /* * Free n pages from the starting address. */ -void virtual_mm_free_pages(void *starting_address, uint32_t n_pages); +void free_pages(void *starting_address, uint32_t n_pages); -#ifdef __cplusplus } -#endif #endif |
