diff --git a/do_all.sh b/do_all.sh index 6eeee2d..e3c7cac 100755 --- a/do_all.sh +++ b/do_all.sh @@ -16,7 +16,8 @@ cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/i686-elf.cmake .. && make -j$(nproc) && popd && buildtools/grub-iso.sh && -mv bootable.iso out/x86-pc.iso +mv bootable.iso out/x86-pc.iso && +cp build/kernel/kernel out/x86-pc.elf #x86-PC config { @@ -29,7 +30,8 @@ cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/x86_64-elf.cmake .. && make -j$(nproc) && popd && buildtools/grub-iso.sh && -mv bootable.iso out/x86_64-pc.iso +mv bootable.iso out/x86_64-pc.iso && +cp build/kernel/kernel out/x86_64-pc.elf #arm-3ds9 config { diff --git a/kernel/arch/arm/3ds11/start.cpp b/kernel/arch/arm/3ds11/start.cpp index fb40966..d425139 100644 --- a/kernel/arch/arm/3ds11/start.cpp +++ b/kernel/arch/arm/3ds11/start.cpp @@ -3,11 +3,14 @@ #include #include #include "../../../mmaps/3ds11.mh" +#include "../../../hw/pmm/pmm.hpp" PICAfb term; +PMM_MMAP lpmm; void main(); extern "C" void start() { main(); } void drivers_init() { + pmm=(PMM*)(&lpmm); setMainTTY(&term); --term; initVectors(); diff --git a/kernel/arch/arm/3ds9/start.cpp b/kernel/arch/arm/3ds9/start.cpp index b7fbe53..ed32066 100644 --- a/kernel/arch/arm/3ds9/start.cpp +++ b/kernel/arch/arm/3ds9/start.cpp @@ -3,13 +3,16 @@ #include #include #include "../../../mmaps/3ds9.mh" +#include "../../../hw/pmm/pmm.hpp" PICAfb term; +PMM_MMAP lpmm; void main(); extern "C" void start() { main(); for(;;); } void drivers_init() { + pmm=(PMM*)(&lpmm); setMainTTY(&term); --term; initVectors(); diff --git a/kernel/arch/arm/raspi2/flags.cmake b/kernel/arch/arm/raspi2/flags.cmake index 4652989..5043c1b 100644 --- a/kernel/arch/arm/raspi2/flags.cmake +++ b/kernel/arch/arm/raspi2/flags.cmake @@ -1,3 +1,3 @@ -SET(PLATFORM_C_FLAGS "-I../../kernel/arch/arm/3ds11/include -mcpu=cortex-a7 -mlittle-endian -mtune=cortex-a7 -mfloat-abi=hard -mtp=soft -O2") +SET(PLATFORM_C_FLAGS "-I../../kernel/arch/arm/3ds11/include -mcpu=cortex-a7 -mlittle-endian -mtune=cortex-a7 -mfloat-abi=hard -mtp=soft -O0") SET(PLATFORM_CXX_FLAGS "${PLATFORM_C_FLAGS}") SET(PLATFORM_ASM_FLAGS "${PLATFORM_C_FLAGS}") diff --git a/kernel/arch/arm/raspi2/start.cpp b/kernel/arch/arm/raspi2/start.cpp index 2c28464..63de620 100644 --- a/kernel/arch/arm/raspi2/start.cpp +++ b/kernel/arch/arm/raspi2/start.cpp @@ -3,11 +3,14 @@ #include #include #include "../../../mmaps/raspi2.mh" +#include "../../../hw/pmm/pmm.hpp" Serial term; +PMM_MMAP lpmm; void main(); extern "C" void start() { main(); } void drivers_init() { + pmm=(PMM*)(&lpmm); setMainTTY(&term); --term; initVectors(); diff --git a/kernel/arch/x86/pc/flags.cmake b/kernel/arch/x86/pc/flags.cmake index 06b3777..1ef2bef 100644 --- a/kernel/arch/x86/pc/flags.cmake +++ b/kernel/arch/x86/pc/flags.cmake @@ -1,3 +1,3 @@ -SET(PLATFORM_C_FLAGS "-I../../kernel/arch/x86/pc/include") +SET(PLATFORM_C_FLAGS "-I../../kernel/arch/x86/pc/include -O2") SET(PLATFORM_CXX_FLAGS "${PLATFORM_C_FLAGS}") SET(PLATFORM_ASM_FLAGS "${PLATFORM_C_FLAGS}") diff --git a/kernel/arch/x86/pc/start.cpp b/kernel/arch/x86/pc/start.cpp index d9d2c8c..b1bfe74 100644 --- a/kernel/arch/x86/pc/start.cpp +++ b/kernel/arch/x86/pc/start.cpp @@ -7,6 +7,7 @@ #endif #include "../../../hw/pc/8259/pic.hpp" #include "../../../hw/pc/idt/idt.hpp" +#include "../../../hw/pc/pmm/pmm.hpp" #include static multiboot_info_t *mb_info; #ifndef ENABLE_FRAMEBUFFER @@ -14,12 +15,14 @@ CGATerm term; #else VESAfb term(mb_info); #endif +PMM_MB lpmm(mb_info); void main(); extern "C" void start(int eax, multiboot_info_t *ebx) { mb_info = ebx; main(); } void drivers_init() { + pmm=(PMM*)(&lpmm); setMainTTY(&term); --term; initIDT(); diff --git a/kernel/arch/x86_64/pc/flags.cmake b/kernel/arch/x86_64/pc/flags.cmake index f6c0ea1..ef08166 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") +SET(PLATFORM_C_FLAGS "-I../../kernel/arch/x86_64/pc/include -O2") SET(PLATFORM_CXX_FLAGS "${PLATFORM_C_FLAGS}") SET(PLATFORM_ASM_FLAGS "${PLATFORM_C_FLAGS}") diff --git a/kernel/arch/x86_64/pc/start.cpp b/kernel/arch/x86_64/pc/start.cpp index 40571f4..3ebfcd2 100644 --- a/kernel/arch/x86_64/pc/start.cpp +++ b/kernel/arch/x86_64/pc/start.cpp @@ -7,6 +7,7 @@ #endif #include "../../../hw/pc/8259/pic.hpp" #include "../../../hw/pc/idt/idt.hpp" +#include "../../../hw/pc/pmm/pmm.hpp" #include static multiboot_info_t *mb_info; @@ -15,12 +16,14 @@ CGATerm term; #else VESAfb term(mb_info); #endif +PMM_MB lpmm(mb_info); void main(); extern "C" void start(int eax, multiboot_info_t *ebx) { mb_info = ebx; main(); } void drivers_init() { + pmm=(PMM*)(&lpmm); setMainTTY(&term); --term; initIDT(); diff --git a/kernel/hw/pc/pmm/pmm.cpp b/kernel/hw/pc/pmm/pmm.cpp new file mode 100644 index 0000000..b5e31d9 --- /dev/null +++ b/kernel/hw/pc/pmm/pmm.cpp @@ -0,0 +1,21 @@ +#include "pmm.hpp" +PMM_MB::PMM_MB(multiboot_info_t *mb_info): PMM(0x1000), mb_info(mb_info) {} + +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++) { + if((mmap[i].addr > addr) || (mmap[i].addr + mmap[i].len < addr)) + continue; + if(mmap[i].type != MULTIBOOT_MEMORY_AVAILABLE) + return false; + free=true; + } + if(!free) + return false; + if(addr == (phys_t)((uintptr_t)mb_info)) + return false; + return PMM::isFree(addr); +} diff --git a/kernel/hw/pc/pmm/pmm.hpp b/kernel/hw/pc/pmm/pmm.hpp new file mode 100644 index 0000000..6fa8a67 --- /dev/null +++ b/kernel/hw/pc/pmm/pmm.hpp @@ -0,0 +1,12 @@ +#pragma once +#include +#include +class PMM_MB: public PMM { + protected: + multiboot_info_t *mb_info; + virtual auto isFree(phys_t addr) -> bool; + public: + PMM_MB()=delete; + PMM_MB(multiboot_info_t *mb_info); + virtual ~PMM_MB(); +}; diff --git a/kernel/hw/pmm/pmm.cpp b/kernel/hw/pmm/pmm.cpp index a7662cd..f479fd7 100644 --- a/kernel/hw/pmm/pmm.cpp +++ b/kernel/hw/pmm/pmm.cpp @@ -79,7 +79,7 @@ PMM_MMAP::PMM_MMAP(): PMM(0x1000) { uint8_t *off=(uint8_t*)(&header+1); for(uint32_t i=0;i bool { uint8_t *off=(uint8_t*)(&header+1); for(uint32_t i=0;i addr) || (tag.REGION.end < addr)) diff --git a/kernel/mmaps/raspi2.mc b/kernel/mmaps/raspi2.mc index 9070b65..10f7f44 100644 --- a/kernel/mmaps/raspi2.mc +++ b/kernel/mmaps/raspi2.mc @@ -1,4 +1,4 @@ -DEVICETYPE CONSOLE +DEVICETYPE EMBEDDED DEVICENAME RASPI2 CPUARCH ARM ENDIAN LITTLE diff --git a/kernel/src/include/base.hpp b/kernel/src/include/base.hpp index 6946216..f6862c6 100644 --- a/kernel/src/include/base.hpp +++ b/kernel/src/include/base.hpp @@ -1,7 +1,9 @@ #pragma once #include #include +#include extern TTY *out; ///< main TTY for output +extern PMM *pmm; /*** * Sets the main TTY to some other TTY object. */ diff --git a/kernel/src/object_init.cpp b/kernel/src/object_init.cpp index 77b2475..4b4c763 100644 --- a/kernel/src/object_init.cpp +++ b/kernel/src/object_init.cpp @@ -1,5 +1,6 @@ #include TTY *out; +PMM *pmm; bool tty_set = false; void setMainTTY(TTY *obj) { ++*obj; diff --git a/kernel/src/pmm.cpp b/kernel/src/pmm.cpp index 976d48a..7cac7d2 100644 --- a/kernel/src/pmm.cpp +++ b/kernel/src/pmm.cpp @@ -12,6 +12,23 @@ auto PMM::isFree(phys_t addr) -> bool { 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) { + if(isFree(i)) + *this << i; + } +#else + //Find out highest GB + phys_t top=0; + for(phys_t i=page_size; i<1024*1024*1024*1024; i+=1024*1024*1024) { + if(isFree(i)) + top=i; + } + for(phys_t i=page_size; i < top; i+=page_size) { + if(isFree(i)) + *this << i; + } +#endif } PMM::~PMM() {}