diff options
author | Anton Kling <anton@kling.gg> | 2023-10-30 22:12:14 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-10-31 00:18:38 +0100 |
commit | 8a9208612eec8ddae4c418485d848ecfa0613699 (patch) | |
tree | 2f4b29200c2f0c19ae52f45bdb9b38a41b356e30 /kernel/ksbrk.c | |
parent | ca76600acc8bf7a02346efa5bd8f17072210ec01 (diff) |
Meta: Move kernel and userland to their own folders.
This is to allow both the kernel and the userland to share certain
header files and to make the folder structure a bit more clear.
Diffstat (limited to 'kernel/ksbrk.c')
-rw-r--r-- | kernel/ksbrk.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/kernel/ksbrk.c b/kernel/ksbrk.c new file mode 100644 index 0000000..755a4ed --- /dev/null +++ b/kernel/ksbrk.c @@ -0,0 +1,40 @@ +#include <assert.h> +#include <ksbrk.h> +#include <mmu.h> +#include <stddef.h> +#include <stdint.h> + +/* +extern uintptr_t data_end; +extern PageDirectory *kernel_directory; + +#define HEAP 0x00E00000 +#define PHYS 0x403000 +#define PAGE_SIZE ((uintptr_t)0x1000) +void *ksbrk(size_t s) { + uintptr_t rc = (uintptr_t)align_page((void *)data_end); + data_end += s; + data_end = (uintptr_t)align_page((void *)data_end); + + if (!get_active_pagedirectory()) { + // If there is no active pagedirectory we + // just assume that the memory is + // already mapped. + return (void *)rc; + } + mmu_allocate_shared_kernel_region((void *)rc, (data_end - (uintptr_t)rc)); + assert(((uintptr_t)rc % PAGE_SIZE) == 0); + memset((void *)rc, 0xFF, s); + return (void *)rc; +} + +void *ksbrk_physical(size_t s, void **physical) { + void *r = ksbrk(s); + if (physical) { + // if (0 == get_active_pagedirectory()) + // *physical = (void *)((uintptr_t)r - (0xC0000000 + PHYS) + HEAP); + // else + *physical = (void *)virtual_to_physical(r, 0); + } + return r; +}*/ |