From bc5bf258a0e3d43d95adfadfa7abce42fffba2e8 Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Thu, 20 Jul 2017 18:51:52 +0100 Subject: [PATCH] made the PMM work and a lot faster. Does not like OOM events, seemingly --- kernel/arch/arm/3ds11/layout.ld | 1 + kernel/arch/arm/3ds9/layout.ld | 1 + kernel/arch/arm/raspi2/layout.ld | 1 + kernel/arch/x86/pc/layout.ld | 1 + kernel/arch/x86/pc/start.cpp | 2 +- kernel/arch/x86_64/pc/flags.cmake | 2 +- kernel/arch/x86_64/pc/layout.ld | 1 + kernel/hw/pc/pmm/pmm.cpp | 17 +++++++++++++++-- kernel/hw/pmm/pmm.cpp | 12 ++++++++++-- kernel/src/include/pmm.hpp | 3 +++ kernel/src/main.cpp | 4 ++++ kernel/src/pmm.cpp | 20 ++++---------------- 12 files changed, 43 insertions(+), 22 deletions(-) diff --git a/kernel/arch/arm/3ds11/layout.ld b/kernel/arch/arm/3ds11/layout.ld index 07324f7..2e09831 100644 --- a/kernel/arch/arm/3ds11/layout.ld +++ b/kernel/arch/arm/3ds11/layout.ld @@ -30,6 +30,7 @@ SECTIONS { } .bss : { *(.bss) + *(.bss.*) *(COMMON) } kernel_end = .; diff --git a/kernel/arch/arm/3ds9/layout.ld b/kernel/arch/arm/3ds9/layout.ld index b5bc1e2..e61eb33 100644 --- a/kernel/arch/arm/3ds9/layout.ld +++ b/kernel/arch/arm/3ds9/layout.ld @@ -30,6 +30,7 @@ SECTIONS { } .bss : { *(.bss) + *(.bss.*) *(COMMON) } kernel_end = .; diff --git a/kernel/arch/arm/raspi2/layout.ld b/kernel/arch/arm/raspi2/layout.ld index b35fa71..4459c65 100644 --- a/kernel/arch/arm/raspi2/layout.ld +++ b/kernel/arch/arm/raspi2/layout.ld @@ -30,6 +30,7 @@ SECTIONS { } .bss : { *(.bss) + *(.bss.*) *(COMMON) } kernel_end = .; diff --git a/kernel/arch/x86/pc/layout.ld b/kernel/arch/x86/pc/layout.ld index 6d7b451..47859c8 100644 --- a/kernel/arch/x86/pc/layout.ld +++ b/kernel/arch/x86/pc/layout.ld @@ -30,6 +30,7 @@ SECTIONS { } .bss : { *(.bss) + *(.bss.*) *(COMMON) } kernel_end = .; diff --git a/kernel/arch/x86/pc/start.cpp b/kernel/arch/x86/pc/start.cpp index b1bfe74..9d4598c 100644 --- a/kernel/arch/x86/pc/start.cpp +++ b/kernel/arch/x86/pc/start.cpp @@ -28,5 +28,5 @@ void drivers_init() { initIDT(); PIC::initPIC(0x20, 0x28); asm volatile("sti"); - asm volatile("int $0"); + asm volatile("int $0x20"); } diff --git a/kernel/arch/x86_64/pc/flags.cmake b/kernel/arch/x86_64/pc/flags.cmake index ef08166..5f99a7d 100644 --- a/kernel/arch/x86_64/pc/flags.cmake +++ b/kernel/arch/x86_64/pc/flags.cmake @@ -1,3 +1,3 @@ -SET(PLATFORM_C_FLAGS "-I../../kernel/arch/x86_64/pc/include -O2") +SET(PLATFORM_C_FLAGS "-I../../kernel/arch/x86_64/pc/include -O0") SET(PLATFORM_CXX_FLAGS "${PLATFORM_C_FLAGS}") SET(PLATFORM_ASM_FLAGS "${PLATFORM_C_FLAGS}") diff --git a/kernel/arch/x86_64/pc/layout.ld b/kernel/arch/x86_64/pc/layout.ld index 35b97b7..8a8b8d8 100644 --- a/kernel/arch/x86_64/pc/layout.ld +++ b/kernel/arch/x86_64/pc/layout.ld @@ -30,6 +30,7 @@ SECTIONS { } .bss : { *(.bss) + *(.bss.*) *(COMMON) } kernel_end = .; diff --git a/kernel/hw/pc/pmm/pmm.cpp b/kernel/hw/pc/pmm/pmm.cpp index b5e31d9..35a3d7f 100644 --- a/kernel/hw/pc/pmm/pmm.cpp +++ b/kernel/hw/pc/pmm/pmm.cpp @@ -1,12 +1,25 @@ #include "pmm.hpp" -PMM_MB::PMM_MB(multiboot_info_t *mb_info): PMM(0x1000), mb_info(mb_info) {} +PMM_MB::PMM_MB(multiboot_info_t *mb_info): PMM(0x1000), mb_info(mb_info) { + auto mmap = (multiboot_memory_map_t*)((uintptr_t)(mb_info->mmap_addr)); + uint32_t count = mb_info->mmap_length / sizeof(mmap[0]); + for(uint32_t i=0;i highest_page) + highest_page = (phys_t)(mmap[i].addr + mmap[i].len); + } + fill(); +} PMM_MB::~PMM_MB() {} auto PMM_MB::isFree(phys_t addr) -> bool { auto mmap = (multiboot_memory_map_t*)((uintptr_t)(mb_info->mmap_addr)); bool free=false; - for(uint32_t i=0;immap_length;i++) { + uint32_t count = mb_info->mmap_length / sizeof(mmap[0]); + for(uint32_t i=0;i addr) || (mmap[i].addr + mmap[i].len < addr)) continue; if(mmap[i].type != MULTIBOOT_MEMORY_AVAILABLE) diff --git a/kernel/hw/pmm/pmm.cpp b/kernel/hw/pmm/pmm.cpp index f479fd7..4d26da6 100644 --- a/kernel/hw/pmm/pmm.cpp +++ b/kernel/hw/pmm/pmm.cpp @@ -83,7 +83,6 @@ PMM_MMAP::PMM_MMAP(): PMM(0x1000) { switch(tag.id) { case 0: case 1: - case 5: break; //Ignored for now case 2: //CPUARCH if(tag.CPUARCH.value != @@ -111,10 +110,19 @@ PMM_MMAP::PMM_MMAP(): PMM(0x1000) { case 4: bits = tag.BITS.value; break; + case 5: + if(tag.REGION.permission != PERM::RWX) + break; + if(tag.REGION.start < lowest_page) + lowest_page = tag.REGION.start; + if(tag.REGION.end > highest_page) + highest_page = tag.REGION.end; + break; default: for(;;); } } + fill(); } PMM_MMAP::~PMM_MMAP() {} auto PMM_MMAP::isFree(phys_t addr) -> bool { @@ -125,7 +133,7 @@ auto PMM_MMAP::isFree(phys_t addr) -> bool { off+=tag.size+2; if(tag.id != 5) continue; - if((tag.REGION.start > addr) || (tag.REGION.end < addr)) + if((tag.REGION.start > addr) || (tag.REGION.end <= addr)) continue; if(tag.REGION.permission == PERM::RWX) return PMM::isFree(addr); diff --git a/kernel/src/include/pmm.hpp b/kernel/src/include/pmm.hpp index a2c58df..6a55910 100644 --- a/kernel/src/include/pmm.hpp +++ b/kernel/src/include/pmm.hpp @@ -16,7 +16,10 @@ class PMM { protected: PMM_ent *head; ///< Head of the linked list virtual auto isFree(phys_t addr) -> bool; ///< Returns true if the provided page is free to use + auto fill() -> void; phys_t page_size; ///< Contains the size of a single memory page, in bytes + phys_t lowest_page; + phys_t highest_page; public: PMM(phys_t page_size); virtual ~PMM(); diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index 2b95515..a4ebd42 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -12,5 +12,9 @@ void main() { drivers_init(); *out << "Hello!\n"; *out << "ใƒ†ใ‚นใƒˆ\n"; + while(true) { + out->puti((*pmm, 1)); + *out << "\n"; + } for (auto dtor = &start_dtors; dtor != &end_dtors; dtor++) (**dtor)(); } diff --git a/kernel/src/pmm.cpp b/kernel/src/pmm.cpp index 7cac7d2..5885e73 100644 --- a/kernel/src/pmm.cpp +++ b/kernel/src/pmm.cpp @@ -7,28 +7,16 @@ auto PMM::isFree(phys_t addr) -> bool { return false; phys_t start = (phys_t)(&kernel_start); phys_t end = (phys_t)(&kernel_end); - if((addr >= start) or (addr < end)) + if((addr >= start) && (addr < end)) return false; return true; } -PMM::PMM(phys_t page_size): page_size(page_size), head(nullptr) { -#ifndef __x86_64__ - for(phys_t i=page_size; i; i+=page_size) { +PMM::PMM(phys_t page_size): page_size(page_size), head(nullptr) {} +void PMM::fill() { + for(phys_t i=lowest_page; i