2015-10-10 16:03:53 +00:00
|
|
|
#include <base.hpp>
|
2015-10-10 12:59:23 +00:00
|
|
|
#include <output.hpp>
|
|
|
|
#include <serial.hpp>
|
2015-10-10 16:03:53 +00:00
|
|
|
#include <textDISP.hpp>
|
2015-10-10 17:34:31 +00:00
|
|
|
#include <gdt.hpp>
|
2015-10-11 10:38:56 +00:00
|
|
|
#include <idt.hpp>
|
2015-10-13 14:11:06 +00:00
|
|
|
#include <keyboard.hpp>
|
2015-10-18 19:57:31 +00:00
|
|
|
#include <Multitasking.h>
|
2016-02-04 11:57:35 +00:00
|
|
|
#include <multiboot.h>
|
2015-10-11 10:38:56 +00:00
|
|
|
extern "C" void intr_stub_0(void);
|
2016-02-04 11:57:35 +00:00
|
|
|
void main();
|
2015-10-10 16:03:53 +00:00
|
|
|
namespace MTGosHAL {
|
2015-10-14 18:02:41 +00:00
|
|
|
Serial debug;
|
|
|
|
Screen out;
|
|
|
|
Screen err;
|
|
|
|
Keyboard in;
|
|
|
|
IDT idt;
|
|
|
|
GDT gdt;
|
2015-10-18 19:57:31 +00:00
|
|
|
Multitasking tasks;
|
2016-02-04 11:57:35 +00:00
|
|
|
void main(int eax, struct multiboot_info* ebx) {
|
2015-10-14 18:02:41 +00:00
|
|
|
out << BG_color::BLACK << FG_color::WHITE << "Loading MTGos...\n";
|
|
|
|
err << BG_color::BLACK << FG_color::RED;
|
2016-02-04 11:57:35 +00:00
|
|
|
if(eax!=0x2BADB002)
|
|
|
|
err << "System wasn't loaded by a Multiboot-conformant launcher!\n";
|
2015-10-15 18:14:04 +00:00
|
|
|
debug << "Hello debugger! This is MTGos v00r01\nThese logs are probably very long, so please redirect the output to a file.\n";
|
2015-10-10 17:34:31 +00:00
|
|
|
gdt.setEntry(0, 0, 0, 0);
|
|
|
|
gdt.setEntry(1, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_CODESEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT);
|
|
|
|
gdt.setEntry(2, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_DATASEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT);
|
|
|
|
gdt.setEntry(3, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_CODESEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT | GDT_FLAG_RING3);
|
|
|
|
gdt.setEntry(4, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_DATASEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT | GDT_FLAG_RING3);
|
|
|
|
gdt.setEntry(5, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_TSS | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT);
|
|
|
|
gdt.setEntry(6, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_TSS | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT);
|
|
|
|
gdt.apply();
|
2015-10-14 18:02:41 +00:00
|
|
|
debug << "We are now creating the IDT.\n";
|
2015-10-11 10:38:56 +00:00
|
|
|
for(int i=0;i<256;i++) {
|
2015-10-14 18:02:41 +00:00
|
|
|
idt.setEntry(i, (void *)((uint32_t)&intr_stub_0+i*16), SEG_KERNEL, IDT_INTERRUPT_GATE | IDT_SEG_32_BIT | IDT_RING_0 | IDT_USED);
|
2015-10-11 10:38:56 +00:00
|
|
|
}
|
2015-10-14 18:02:41 +00:00
|
|
|
idt.setEntry(48, (void *)((uint32_t)&intr_stub_0+768), SEG_KERNEL, IDT_TRAP_GATE | IDT_SEG_32_BIT | IDT_RING_0 | IDT_USED);
|
|
|
|
idt.setEntry(8, (void *)((uint32_t)&intr_stub_0+128), SEG_DBL_FAULT, IDT_TASK_GATE | IDT_SEG_32_BIT | IDT_RING_0 | IDT_USED);
|
|
|
|
idt.apply();
|
2015-10-11 10:38:56 +00:00
|
|
|
sti();
|
2016-02-04 11:57:35 +00:00
|
|
|
::main();
|
2015-10-10 16:03:53 +00:00
|
|
|
for(;;);
|
2015-10-10 12:59:23 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-14 18:02:41 +00:00
|
|
|
typedef void (*constructor)();
|
|
|
|
extern "C" constructor start_ctors;
|
|
|
|
extern "C" constructor end_ctors;
|
2016-02-04 11:57:35 +00:00
|
|
|
extern "C" void init(int eax, struct multiboot_info* ebx) {
|
2015-10-14 18:02:41 +00:00
|
|
|
for(constructor* i = &start_ctors; i != &end_ctors; ++i)
|
|
|
|
(*i)();
|
2016-02-04 11:57:35 +00:00
|
|
|
MTGosHAL::main(eax, ebx);
|
2015-10-10 12:59:23 +00:00
|
|
|
}
|
|
|
|
extern "C" void __cxa_pure_virtual() {
|
2015-10-14 18:02:41 +00:00
|
|
|
MTGosHAL::debug << "A pure virtual function just got called.\n";
|
2015-10-10 12:59:23 +00:00
|
|
|
}
|
|
|
|
|