From ba9b715c591e25f04497b285a193c98e2fb86cd7 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Fri, 23 Dec 2011 13:09:09 +0100 Subject: [PATCH] Added a global variable at the end of the kernel to detect its size. This lets the kernel use any memory not directly used by it or the init ramdisk. Although, now we test whether the kernel fits into the identitymapped area. It can't really grow down there, unless it wants to collide with user-space. Instead, modules and the like (when they are invented), should be put in the upper memory. Or in their own user-space process, yay, microkernel! --- sortix/Makefile | 1 + sortix/end.cpp | 33 ++++++++++++++++++++++++++ sortix/x86-family/memorymanagement.cpp | 16 ++++++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 sortix/end.cpp diff --git a/sortix/Makefile b/sortix/Makefile index 0d857f91..d196e2d2 100644 --- a/sortix/Makefile +++ b/sortix/Makefile @@ -87,6 +87,7 @@ fs/devfs.o \ fs/initfs.o \ fs/ramfs.o \ ../libmaxsi/libmaxsi-sortix.a \ +end.o # Must be last JSOBJS:=$(subst .o,-js.o,$(OBJS)) diff --git a/sortix/end.cpp b/sortix/end.cpp new file mode 100644 index 00000000..2f620704 --- /dev/null +++ b/sortix/end.cpp @@ -0,0 +1,33 @@ +/****************************************************************************** + + COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011. + + This file is part of Sortix. + + Sortix is free software: you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + Sortix is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along + with Sortix. If not, see . + + end.cpp + Places a symbol at the end of the kernel binary. This allows us to easily + detect the size of the kernel. Be sure to put this one last in the linking + command. + +******************************************************************************/ + +#include "platform.h" + +namespace Sortix +{ + size_t end; // Put in the bss, the last segment. +} + diff --git a/sortix/x86-family/memorymanagement.cpp b/sortix/x86-family/memorymanagement.cpp index a998678d..da684126 100644 --- a/sortix/x86-family/memorymanagement.cpp +++ b/sortix/x86-family/memorymanagement.cpp @@ -35,7 +35,7 @@ using namespace Maxsi; namespace Sortix { - const addr_t KERNELEND = 0x200000UL; + extern size_t end; namespace Page { @@ -57,11 +57,21 @@ namespace Sortix void Init(multiboot_info_t* bootinfo) { + const size_t MAXKERNELEND = 0x400000UL; /* 4 MiB */ + addr_t kernelend = Page::AlignUp((addr_t) &end); + if ( MAXKERNELEND < kernelend ) + { + Log::PrintF("Warning: The kernel is too big! It ends at 0x%zx, " + "but the highest ending address supported is 0x%zx. " + "The system may not boot correctly.\n", kernelend, + MAXKERNELEND); + } + Page::pagesnotonstack = 0; Page::totalmem = 0; // The first mebibytes are reserved for use by the kernel. - Page::pagesallocated = KERNELEND >> 12UL; + Page::pagesallocated = kernelend >> 12UL; if ( !( bootinfo->flags & MULTIBOOT_INFO_MEM_MAP ) ) { @@ -109,7 +119,7 @@ namespace Sortix addr_t highest = regionend; // Don't allocate the kernel. - if ( lowest < KERNELEND ) { processed = KERNELEND; continue; } + if ( lowest < kernelend ) { processed = kernelend; continue; } // Don't give any of our modules to the physical page // allocator, we'll need them.