2016-03-19 03:45:23 -04:00
|
|
|
/* Main.cc
|
|
|
|
* vim: set tw=80:
|
|
|
|
* Eryn Wells <eryn@erynwells.me>
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Entry point for the kernel in C/C++.
|
|
|
|
*/
|
|
|
|
|
2016-02-26 22:31:34 -08:00
|
|
|
#include <stddef.h>
|
2016-02-27 13:50:51 -05:00
|
|
|
#include "Console.hh"
|
2016-02-28 23:26:42 -05:00
|
|
|
#include "Descriptors.hh"
|
2016-03-09 01:23:06 -05:00
|
|
|
#include "Interrupts.hh"
|
2016-03-23 00:33:45 -04:00
|
|
|
#include "Kernel.hh"
|
2016-03-19 03:45:23 -04:00
|
|
|
#include "Multiboot.hh"
|
2016-03-20 12:56:43 -04:00
|
|
|
#include "kstd/Types.hh"
|
2016-02-26 22:31:34 -08:00
|
|
|
|
|
|
|
#if defined(__linux__)
|
|
|
|
#error "This file should be compiled with a cross-compiler, not the Linux system compiler!"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(__i386__)
|
|
|
|
#error "This file should be compiled with an ix86-elf compiler!"
|
|
|
|
#endif
|
|
|
|
|
2016-02-28 13:33:20 -05:00
|
|
|
|
|
|
|
/** The beginning of the world... */
|
|
|
|
extern "C"
|
|
|
|
void
|
2016-03-23 01:01:16 -04:00
|
|
|
kmain(multiboot::Information *information,
|
|
|
|
u32 magic)
|
2016-03-01 12:01:51 -05:00
|
|
|
{
|
2016-03-19 03:45:23 -04:00
|
|
|
multiboot::Information::setInformation(information);
|
|
|
|
auto info = multiboot::Information::information();
|
|
|
|
|
2016-03-23 01:42:52 -04:00
|
|
|
auto& kernel = kernel::Kernel::systemKernel();
|
|
|
|
kernel.initialize();
|
|
|
|
|
|
|
|
auto& console = kernel.console();
|
2016-03-19 03:45:23 -04:00
|
|
|
|
2016-03-20 00:43:26 -04:00
|
|
|
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());
|
2016-03-20 03:38:52 -04:00
|
|
|
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",
|
2016-03-20 12:56:43 -04:00
|
|
|
u32(begin >> 32), u32(begin & 0xFFFFFFFF),
|
|
|
|
u32(end >> 32), u32(end & 0xFFFFFFFF),
|
2016-03-20 03:38:52 -04:00
|
|
|
(*it).type == 1 ? "available" : "reserved");
|
|
|
|
}
|
2016-03-19 03:45:23 -04:00
|
|
|
|
2016-03-12 19:14:36 -05:00
|
|
|
auto& gdt = x86::GDT::systemGDT();
|
2016-03-01 12:01:51 -05:00
|
|
|
gdt.setNullDescriptor(0);
|
2016-03-13 12:52:32 -04:00
|
|
|
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));
|
2016-03-01 12:01:51 -05:00
|
|
|
gdt.load();
|
2016-03-13 13:32:52 -04:00
|
|
|
console.printString("GDT loaded\n");
|
2016-03-02 02:57:35 -05:00
|
|
|
|
2016-03-12 19:14:36 -05:00
|
|
|
auto& interruptHandler = x86::InterruptHandler::systemInterruptHandler();
|
2016-03-09 01:23:06 -05:00
|
|
|
interruptHandler.initialize();
|
2016-03-13 12:52:47 -04:00
|
|
|
interruptHandler.enableInterrupts();
|
2016-03-13 13:32:52 -04:00
|
|
|
console.printString("Interrupts enabled\n");
|
2016-03-13 12:52:47 -04:00
|
|
|
|
2016-03-23 00:55:42 -04:00
|
|
|
kernel::Kernel::systemKernel().halt();
|
2016-03-01 12:01:51 -05:00
|
|
|
}
|