From 8251da342161767fe203627223ccd4a7026701c6 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Fri, 4 Sep 2026 11:31:40 -0400 Subject: initial commit. working on tasking --- arch/x86_64/boot/limine/framebuffer.c | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 arch/x86_64/boot/limine/framebuffer.c (limited to 'arch/x86_64/boot/limine') diff --git a/arch/x86_64/boot/limine/framebuffer.c b/arch/x86_64/boot/limine/framebuffer.c new file mode 100644 index 0000000..aa93496 --- /dev/null +++ b/arch/x86_64/boot/limine/framebuffer.c @@ -0,0 +1,48 @@ +#include "arch/x86_64/hal/paging.h" +#include "jove.h" +#include "config.h" +#include "hal/framebuffer.h" +#include "lib/printf.h" + +/*We don't know the size of the framebuffer until runtime, but at the same + * time we don't want to dynamically allocate from physical memory. In this + * case we allocate memory for the maximum supported framebuffer at compile + * time and only use what we need at runtime.*/ +#define FRAMEBUFFER_MAX_BYTES (FRAMEBUFFER_MAX_WIDTH * FRAMEBUFFER_MAX_WIDTH * 4) +#define FRAMEBUFFER_MAX_PAGES ((FRAMEBUFFER_MAX_BYTES + 4095) / 0x1000) +#define FRAMEBUFFER_MAX_HUGEPAGES ((FRAMEBUFFER_MAX_PAGES + 511) / 512) +#define FRAMEBUFFER_MAX_GIANTPAGES ((FRAMEBUFFER_MAX_HUGEPAGES + 511) / 512) + +PAGEALIGN static page_t fb_pml2[FRAMEBUFFER_MAX_GIANTPAGES][512]; + +extern page_t _kernel_pml3[512]; + +void* +fb_remap(uintptr_t fb_address, + size_t fb_bytes) +{ + fb_address &= ~IDENT_VIRT_BASE; + size_t fb_pages = (fb_bytes + 4095) >> 12; + size_t fb_hugepages = (fb_pages + 511) >> 9; + size_t fb_giantpages = (fb_hugepages + 511) >> 9; + + if(fb_pages > FRAMEBUFFER_MAX_PAGES) { + kprintf("Framebuffer is too big! Please recompile the kernel with a bigger framebuffer allowance!"); + return NULL; + } + + for(size_t pml2 = 0; pml2 < fb_giantpages; pml2++) { + uintptr_t fb_pml2_pptr = KPTR_TOPHYS((uintptr_t)fb_pml2[pml2]); + _kernel_pml3[pml2].value = fb_pml2_pptr | PAGE_PRESENT | PAGE_GLOBAL | PAGE_WRITEABLE; + } + + for(size_t pml1 = 0; pml1 < fb_hugepages; pml1++) { + size_t pml2 = pml1 >> 9; + size_t pml1_mod = pml1 % 512; + uintptr_t fb_off = fb_address + (pml1 << 21); + fb_pml2[pml2][pml1_mod].value = fb_off | PAGE_PRESENT | PAGE_GLOBAL | PAGE_WRITEABLE | PAGE_PS; + } + + uintptr_t fb_virt = IDENT_VIRT_BASE | (511ULL << PMLI_SHL(3)); + return (void*)fb_virt; +} -- cgit v1.2.3