From 531f4701324707e58c56167274463735cab3f14a Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 5 Jan 2023 03:44:41 +0200 Subject: [PATCH] Kernel: Add helper to map pages with base address and size This allows us to easily map enough pages for buffer with known size VESA driver can now allocate enough memory for whole framebuffer if it doesn't fit in a single page (1920x1080 for example) --- kernel/arch/i386/Paging.cpp | 7 +++++++ kernel/arch/i386/VESA.cpp | 2 +- kernel/include/kernel/Paging.h | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/arch/i386/Paging.cpp b/kernel/arch/i386/Paging.cpp index d7b651e7..7bd0a758 100644 --- a/kernel/arch/i386/Paging.cpp +++ b/kernel/arch/i386/Paging.cpp @@ -85,4 +85,11 @@ namespace Paging asm volatile("invlpg (%0)" :: "r"(address) : "memory"); } + void MapPages(uintptr_t address, size_t size) + { + address = (address >> 21) << 21; + for (size_t offset = 0; offset < size; offset += 1 << 21) + MapPage(address + offset); + } + } \ No newline at end of file diff --git a/kernel/arch/i386/VESA.cpp b/kernel/arch/i386/VESA.cpp index 4413dc1b..65165858 100644 --- a/kernel/arch/i386/VESA.cpp +++ b/kernel/arch/i386/VESA.cpp @@ -98,7 +98,7 @@ namespace VESA s_height = framebuffer.height; s_mode = framebuffer.type; - Paging::MapPage(framebuffer.addr); + Paging::MapPages(s_addr, s_pitch * s_height); if (s_mode == MULTIBOOT_FRAMEBUFFER_TYPE_GRAPHICS) { diff --git a/kernel/include/kernel/Paging.h b/kernel/include/kernel/Paging.h index 024fe531..4b208d5a 100644 --- a/kernel/include/kernel/Paging.h +++ b/kernel/include/kernel/Paging.h @@ -1,5 +1,6 @@ #pragma once +#include #include namespace Paging @@ -8,5 +9,6 @@ namespace Paging void Initialize(); void MapPage(uintptr_t address); + void MapPages(uintptr_t address, size_t size); } \ No newline at end of file