2016-02-26 22:31:34 -08:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.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-06 13:00:38 -05:00
|
|
|
#include "PIC.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-27 12:34:36 -05:00
|
|
|
/** Called very early, before global initialization. */
|
2016-02-26 22:31:34 -08:00
|
|
|
extern "C"
|
|
|
|
void
|
|
|
|
kearly()
|
2016-02-27 13:50:51 -05:00
|
|
|
{
|
2016-03-01 12:01:51 -05:00
|
|
|
using kernel::Console;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a console object for early use because global initialization
|
|
|
|
* hasn't happened yet.
|
|
|
|
*/
|
|
|
|
Console console;
|
2016-02-27 13:50:51 -05:00
|
|
|
console.clear(kernel::Console::Color::Blue);
|
2016-02-28 13:33:20 -05:00
|
|
|
console.writeString("Loading system ...\n");
|
2016-02-27 13:50:51 -05:00
|
|
|
}
|
2016-02-28 13:33:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
/** The beginning of the world... */
|
|
|
|
extern "C"
|
|
|
|
void
|
|
|
|
kmain()
|
2016-03-01 12:01:51 -05:00
|
|
|
{
|
|
|
|
// Reinitialize the system console now that we have global static objects.
|
2016-03-06 13:01:02 -05:00
|
|
|
auto console = kernel::Console::systemConsole();
|
|
|
|
console.clear(kernel::Console::Color::Blue);
|
2016-03-01 12:01:51 -05:00
|
|
|
|
2016-03-09 01:12:05 -05:00
|
|
|
auto gdt = x86::GDT::systemGDT();
|
2016-03-01 12:01:51 -05:00
|
|
|
gdt.setNullDescriptor(0);
|
2016-03-09 01:12:05 -05:00
|
|
|
gdt.setDescriptor(1, x86::GDT::DescriptorSpec::kernelSegment(0, 0x000FFFFF, x86::GDT::Type::CodeEXR));
|
|
|
|
gdt.setDescriptor(2, x86::GDT::DescriptorSpec::kernelSegment(0, 0x000FFFFF, x86::GDT::Type::DataRW));
|
2016-03-01 12:01:51 -05:00
|
|
|
gdt.load();
|
|
|
|
|
|
|
|
console.writeString("GDT loaded\n");
|
2016-03-02 02:57:35 -05:00
|
|
|
|
2016-03-09 01:12:05 -05:00
|
|
|
auto idt = x86::IDT::systemIDT();
|
2016-03-02 02:57:35 -05:00
|
|
|
idt.load();
|
|
|
|
|
|
|
|
console.writeString("IDT loaded\n");
|
2016-03-06 13:00:38 -05:00
|
|
|
|
2016-03-09 00:28:19 -05:00
|
|
|
auto pic = x86::PIC::systemPIC();
|
2016-03-06 13:00:38 -05:00
|
|
|
pic.remap(0x20, 0x28, 2); // Map hardware IRQs to interrupt vectors 32 through 48.
|
|
|
|
|
|
|
|
console.writeString("Hardware interrupts programmed\n");
|
2016-03-01 12:01:51 -05:00
|
|
|
}
|