diff options
author | Danny Holman <dholman@gymli.org> | 2025-01-12 01:17:36 -0600 |
---|---|---|
committer | Danny Holman <dholman@gymli.org> | 2025-01-12 01:19:11 -0600 |
commit | 95cd78840f0891e60f5ebecc8a8eb4fbaf3c2ebf (patch) | |
tree | c8c35347b50477929727fa5be9f5d0f55cbe18fd /arch/i386/kernel/pmem.c | |
parent | arch: i386: kmalloc: fix last element being ignored (diff) | |
download | box-95cd78840f0891e60f5ebecc8a8eb4fbaf3c2ebf.tar.gz box-95cd78840f0891e60f5ebecc8a8eb4fbaf3c2ebf.tar.zst box-95cd78840f0891e60f5ebecc8a8eb4fbaf3c2ebf.zip |
PROJECT RESTRUCTURING
Move the entire kernel into its own directory. Create new directories
for system commands, libraries and other required essentials for a
complete Unix-like operating system.
Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to '')
-rw-r--r-- | kernel/arch/x86/kernel/pmem.c (renamed from arch/i386/kernel/pmem.c) | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/arch/i386/kernel/pmem.c b/kernel/arch/x86/kernel/pmem.c index 40e3400..edf71d9 100644 --- a/arch/i386/kernel/pmem.c +++ b/kernel/arch/x86/kernel/pmem.c @@ -6,6 +6,7 @@ #include <libk/io.h> #include <libk/string.h> +static uintptr_t bitmap[5]; static struct pfa_page freelist; void pfa_init(struct mboot_info *header) { @@ -17,6 +18,9 @@ void pfa_init(struct mboot_info *header) { } } +uintptr_t pfa_alloc_dma(size_t num_pages) { +} + uintptr_t pfa_alloc(size_t num_pages) { struct pfa_page *temp = (struct pfa_page*)PAGE_TMP_MAP; map_page(freelist.next, PAGE_TMP_MAP, PD_PRES | PD_RW); @@ -27,6 +31,23 @@ uintptr_t pfa_alloc(size_t num_pages) { return ret; } +void pfa_free_dma(uintptr_t paddr, size_t num_pages) { + if (paddr % PAGE_SIZE != 0) + panic("Task attempted to free non-aligned memory"); + if (paddr >= KSTART && paddr < KEND) + return; + if (paddr >= 0x00080000 && paddr < 0x00100000) + return; + + int index = 0; + int bit = 0; + for (uintptr_t i = paddr; i < paddr + (num_pages * PAGE_SIZE); i += PAGE_SIZE) { + index = i / PAGE_SIZE / 32; + bit = i / PAGE_SIZE % 32; + bitmap[index] |= 1 << bit; + } +} + void pfa_free(uintptr_t paddr, size_t num_pages) { uintptr_t addr; struct pfa_page *temp = (struct pfa_page*)PAGE_TMP_MAP; |