aboutsummaryrefslogtreecommitdiff
path: root/src/kernel.cc
blob: 33282db2770715a0e6de44d61623d65b9b8ef8eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Check if the compiler thinks you are targeting the wrong operating system. */
#if defined(__linux__)
#error "You are not using a cross-compiler"
#endif

/* This tutorial will only work for the 32-bit ix86 targets. */
#if !defined(__i386__)
#error "This tutorial needs to be compiled with a ix86-elf compiler"
#endif

#include <stdlib.h>
#include <types.h>
#include "cga.h"
#include "gdt.h"
#include "idt.h"
#include "scheduler.h"
#include "serial.h"

#include "keyboard.h"

#include "hardware.h"

typedef void (*constructor)();

extern "C" {

constructor begin_ctors;
constructor end_ctors;
void kernel_constructors() {
  for (constructor* i = &begin_ctors; i != &end_ctors; ++i) (*i)();
}

void dump_multiboot(uint32_t mb_magic, uint32_t mb_addr);
void dump_gdt();

void kernel_main([[maybe_unused]] uint32_t mb_magic, [[maybe_unused]] uint32_t mb_addr) {
#ifdef HAS_SERIAL0
  if constexpr (serial0_console)
    if (serial0.self_check()) Console::set(&serial0);
#endif

#ifdef HAS_VIDEO0
  if constexpr (video0_console) Console::set(&video0);
#endif

  printk("Hello, kernel World!\n");

  dump_multiboot(mb_magic, mb_addr + 0xc0000000);
  // dump_gdt();

  GDT gdt;
  IDT idt{gdt.descriptor(GDT::kcode)};
  Scheduler s{gdt.descriptor(GDT::kcode)};
  Keyboard kb;

  idt.enable();

  while (true) asm volatile("hlt");
}
}  // extern "C"