Initialize the frame allocator
Does not actually do anything yet...
This commit is contained in:
parent
d8306cf995
commit
9f911e2197
6 changed files with 60 additions and 10 deletions
|
@ -66,7 +66,7 @@ Kernel::initialize(const StartupInformation& startupInformation)
|
|||
(*it).type == 1 ? "available" : "reserved");
|
||||
}
|
||||
|
||||
mMemoryManager.initialize();
|
||||
mMemoryManager.initialize(startupInformation);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ files = [
|
|||
'kstd/Memory.cc',
|
||||
'kstd/PrintFormat.cc',
|
||||
|
||||
'memory/FrameAllocator.cc',
|
||||
'memory/Memory.cc',
|
||||
]
|
||||
|
||||
|
|
|
@ -6,10 +6,33 @@
|
|||
* 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 {
|
||||
|
||||
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 */
|
||||
|
|
|
@ -9,10 +9,25 @@
|
|||
#ifndef __MEMORY_FRAMEALLOCATOR_HH__
|
||||
#define __MEMORY_FRAMEALLOCATOR_HH__
|
||||
|
||||
#include "StartupInformation.hh"
|
||||
#include "kstd/Types.hh"
|
||||
|
||||
|
||||
namespace kernel {
|
||||
|
||||
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 */
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* Top-level classes for managing system memory.
|
||||
*/
|
||||
|
||||
#include "Memory.hh"
|
||||
#include "kstd/PrintFormat.hh"
|
||||
#include "memory/Memory.hh"
|
||||
|
||||
namespace kernel {
|
||||
|
||||
|
@ -15,11 +15,16 @@ namespace kernel {
|
|||
* Public
|
||||
*/
|
||||
|
||||
MemoryManager::MemoryManager()
|
||||
: mGDT(),
|
||||
mFrameAllocator()
|
||||
{ }
|
||||
|
||||
void
|
||||
MemoryManager::initialize()
|
||||
MemoryManager::initialize(const StartupInformation& startupInformation)
|
||||
{
|
||||
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(2, x86::GDT::DescriptorSpec::kernelSegment(0, 0xFFFFFFFF, x86::GDT::Type::DataRW));
|
||||
mGDT.load();
|
||||
kstd::printFormat("GDT loaded\n");
|
||||
}
|
||||
|
||||
} /* namespace kernel */
|
||||
|
|
|
@ -6,25 +6,30 @@
|
|||
* Declaration of top-level classes for managing system memory.
|
||||
*/
|
||||
|
||||
#ifndef __MEMORY_HH__
|
||||
#define __MEMORY_HH__
|
||||
#ifndef __MEMORY_MEMORY_HH__
|
||||
#define __MEMORY_MEMORY_HH__
|
||||
|
||||
#include "Console.hh"
|
||||
#include "Descriptors.hh"
|
||||
#include "StartupInformation.hh"
|
||||
#include "memory/FrameAllocator.hh"
|
||||
|
||||
|
||||
namespace kernel {
|
||||
|
||||
struct MemoryManager
|
||||
{
|
||||
void initialize();
|
||||
MemoryManager();
|
||||
|
||||
void initialize(const StartupInformation& startupInformation);
|
||||
|
||||
private:
|
||||
x86::GDT mGDT;
|
||||
kernel::FrameAllocator mFrameAllocator;
|
||||
|
||||
void initializeGDT();
|
||||
};
|
||||
|
||||
} /* namespace kernel */
|
||||
|
||||
#endif /* __MEMORY_HH__ */
|
||||
#endif /* __MEMORY_MEMORY_HH__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue