Initialize the frame allocator

Does not actually do anything yet...
This commit is contained in:
Eryn Wells 2016-04-09 13:51:47 -04:00
parent d8306cf995
commit 9f911e2197
6 changed files with 60 additions and 10 deletions

View file

@ -66,7 +66,7 @@ Kernel::initialize(const StartupInformation& startupInformation)
(*it).type == 1 ? "available" : "reserved"); (*it).type == 1 ? "available" : "reserved");
} }
mMemoryManager.initialize(); mMemoryManager.initialize(startupInformation);
} }

View file

@ -24,6 +24,7 @@ files = [
'kstd/Memory.cc', 'kstd/Memory.cc',
'kstd/PrintFormat.cc', 'kstd/PrintFormat.cc',
'memory/FrameAllocator.cc',
'memory/Memory.cc', 'memory/Memory.cc',
] ]

View file

@ -6,10 +6,33 @@
* An object to tracks and allocate physical page frames. * An object to tracks and allocate physical page frames.
*/ */
#include "FrameAllocator.hh" #include "Kernel.hh"
#include "kstd/Memory.hh"
#include "kstd/PrintFormat.hh"
#include "memory/FrameAllocator.hh"
namespace kernel { namespace kernel {
FrameAllocator::FrameAllocator()
: mBitmap(nullptr),
mBitmapSize(0)
{ }
void
FrameAllocator::initialize(const StartupInformation& startupInformation)
{
// Page frame bitmap starts immediately after the kernel.
mBitmap = reinterpret_cast<u8*>(startupInformation.kernelEnd);
const u32 pageSize = startupInformation.pageSize;
const u32 numberOfPages = startupInformation.multibootInformation->memoryKB() * 1024 / pageSize;
mBitmapSize = numberOfPages / (sizeof(FrameBitmap) * 8);
kstd::printFormat("Allocated bitmap of %ld bytes for %ld pages at 0x%08lX\n", mBitmapSize, numberOfPages, u32(mBitmap));
// TODO: Before modifying this memory, maybe make sure none of the multiboot information is hanging out there?
kstd::Memory::zero(mBitmap, mBitmapSize);
}
} /* namespace kernel */ } /* namespace kernel */

View file

@ -9,10 +9,25 @@
#ifndef __MEMORY_FRAMEALLOCATOR_HH__ #ifndef __MEMORY_FRAMEALLOCATOR_HH__
#define __MEMORY_FRAMEALLOCATOR_HH__ #define __MEMORY_FRAMEALLOCATOR_HH__
#include "StartupInformation.hh"
#include "kstd/Types.hh"
namespace kernel { namespace kernel {
struct FrameAllocator struct FrameAllocator
{ {
FrameAllocator();
void initialize(const StartupInformation& startupInformation);
private:
typedef u8 FrameBitmap;
/** Starting address of the frame allocation bitmap. */
FrameBitmap* mBitmap;
/** Size of the bitmap in bytes. */
u32 mBitmapSize;
}; };
} /* namespace */ } /* namespace */

View file

@ -6,8 +6,8 @@
* Top-level classes for managing system memory. * Top-level classes for managing system memory.
*/ */
#include "Memory.hh"
#include "kstd/PrintFormat.hh" #include "kstd/PrintFormat.hh"
#include "memory/Memory.hh"
namespace kernel { namespace kernel {
@ -15,11 +15,16 @@ namespace kernel {
* Public * Public
*/ */
MemoryManager::MemoryManager()
: mGDT(),
mFrameAllocator()
{ }
void void
MemoryManager::initialize() MemoryManager::initialize(const StartupInformation& startupInformation)
{ {
initializeGDT(); initializeGDT();
kstd::printFormat("GDT loaded\n"); mFrameAllocator.initialize(startupInformation);
} }
/* /*
@ -33,6 +38,7 @@ MemoryManager::initializeGDT()
mGDT.setDescriptor(1, x86::GDT::DescriptorSpec::kernelSegment(0, 0xFFFFFFFF, x86::GDT::Type::CodeEXR)); mGDT.setDescriptor(1, x86::GDT::DescriptorSpec::kernelSegment(0, 0xFFFFFFFF, x86::GDT::Type::CodeEXR));
mGDT.setDescriptor(2, x86::GDT::DescriptorSpec::kernelSegment(0, 0xFFFFFFFF, x86::GDT::Type::DataRW)); mGDT.setDescriptor(2, x86::GDT::DescriptorSpec::kernelSegment(0, 0xFFFFFFFF, x86::GDT::Type::DataRW));
mGDT.load(); mGDT.load();
kstd::printFormat("GDT loaded\n");
} }
} /* namespace kernel */ } /* namespace kernel */

View file

@ -6,25 +6,30 @@
* Declaration of top-level classes for managing system memory. * Declaration of top-level classes for managing system memory.
*/ */
#ifndef __MEMORY_HH__ #ifndef __MEMORY_MEMORY_HH__
#define __MEMORY_HH__ #define __MEMORY_MEMORY_HH__
#include "Console.hh" #include "Console.hh"
#include "Descriptors.hh" #include "Descriptors.hh"
#include "StartupInformation.hh"
#include "memory/FrameAllocator.hh"
namespace kernel { namespace kernel {
struct MemoryManager struct MemoryManager
{ {
void initialize(); MemoryManager();
void initialize(const StartupInformation& startupInformation);
private: private:
x86::GDT mGDT; x86::GDT mGDT;
kernel::FrameAllocator mFrameAllocator;
void initializeGDT(); void initializeGDT();
}; };
} /* namespace kernel */ } /* namespace kernel */
#endif /* __MEMORY_HH__ */ #endif /* __MEMORY_MEMORY_HH__ */