summaryrefslogtreecommitdiff
path: root/kernel/src/main.rs
blob: 8b21eeffb10f65f77417c25555a764c239261274 (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
#![no_main]
#![feature(custom_test_frameworks)]
#![feature(abi_x86_interrupt)]
#![feature(panic_info_message)]
#![feature(asm)]
#![test_runner(crate::testing::test_runner)]
#![no_std]

pub mod interrupts;
pub mod io;
pub mod testing;

use core::fmt::Write;
pub use io::qemu::{exit_qemu, QemuExitCode};
pub use io::vga_text::OStream;
pub use io::{qemu, serial, vga_text};

#[no_mangle]
extern "C" fn _start() -> ! {
    kernel::init();

    let apic = interrupts::apic::Apic::new().expect("no APIC support");
    let mut apic = unsafe { interrupts::apic::set_local_apic(apic) };

    apic.set_timer_interrupt_handler(
        interrupts::apic::TimerDivideConfig::Div16,
        interrupts::InterruptType::Timer,
    );

    x86_64::instructions::interrupts::enable();

    let mut stdout = OStream::new();
    stdout.print(b"apic initialisation complete\n");
    x86_64::instructions::interrupts::int3();

    if cfg!(test) {
        qemu::exit_qemu(qemu::QemuExitCode::Success);
    }
    loop {}
}

#[panic_handler]
#[no_mangle]
extern "C" fn panic_handler(info: &core::panic::PanicInfo) -> ! {
    if cfg!(test) {
        testing::serial_panic(info);
    }
    testing::panic(info);
}