Move a bunch of init code to Kernel::initialize()

- Kernel owns a MemoryManager, which is responsible for initializing the GDT.
- Kernel is passed a new StartupInformation struct (borrowed this one from
  Ghost) which contains a bunch of handy tidbits for setting things up.
- Cleaned out even more stuff from kmain()
This commit is contained in:
Eryn Wells 2016-03-25 01:21:49 -04:00
parent b9ece9bbcb
commit bcfba2c167
3 changed files with 50 additions and 33 deletions

View file

@ -22,6 +22,7 @@
#error "This file should be compiled with an ix86-elf compiler!"
#endif
// Linker script defined symbols. See linker.ld.
extern u32 kernelStart;
extern u32 kernelEnd;
@ -32,40 +33,17 @@ void
kmain(multiboot::Information *information,
u32 magic)
{
multiboot::Information::setInformation(information);
auto info = multiboot::Information::information();
auto& kernel = kernel::Kernel::systemKernel();
kernel.initialize();
kernel::StartupInformation startupInformation;
startupInformation.kernelStart = u32(&kernelStart);
startupInformation.kernelEnd = u32(&kernelEnd);
startupInformation.multibootInformation = information;
kernel.initialize(startupInformation);
auto& console = kernel.console();
auto start = u32(&kernelStart);
auto end = u32(&kernelEnd);
console.printFormat("Kernel start: 0x%08lX\n", start);
console.printFormat("Kernel end: 0x%08lX\n", end);
console.printFormat("Kernel size: %ld bytes\n", end - start);
console.printFormat("Command line: \"%s\"\n", info->commandLine());
console.printFormat("Memory map:\n");
console.printFormat(" available: lower = %ld KB, upper = %ld KB\n", info->lowerMemoryKB(), info->upperMemoryKB());
for (auto it = info->memoryMapBegin(); it != info->memoryMapEnd(); ++it) {
auto begin = (*it).base;
auto end = begin + (*it).length - 1;
console.printFormat(" begin = 0x%08lX %08lX, end = 0x%08lX %08lX (%s)\n",
u32(begin >> 32), u32(begin & 0xFFFFFFFF),
u32(end >> 32), u32(end & 0xFFFFFFFF),
(*it).type == 1 ? "available" : "reserved");
}
auto& gdt = x86::GDT::systemGDT();
gdt.setNullDescriptor(0);
gdt.setDescriptor(1, x86::GDT::DescriptorSpec::kernelSegment(0, 0xFFFFFFFF, x86::GDT::Type::CodeEXR));
gdt.setDescriptor(2, x86::GDT::DescriptorSpec::kernelSegment(0, 0xFFFFFFFF, x86::GDT::Type::DataRW));
gdt.load();
console.printString("GDT loaded\n");
auto& interruptHandler = x86::InterruptHandler::systemInterruptHandler();
interruptHandler.initialize();
interruptHandler.enableInterrupts();