summaryrefslogtreecommitdiff
path: root/kernel/src/lib.rs
blob: a8be053e7d54ac9b19dbb77f49ff716a132bb470 (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
#![allow(unused_attributes)]
#![no_main]
#![feature(custom_test_frameworks)]
#![feature(abi_x86_interrupt)]
#![feature(panic_info_message)]
#![feature(asm)]
#![test_runner(crate::testing::serial_test_runner)]
#![reexport_test_harness_main = "test_main"]
#![no_std]

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

pub use io::qemu::{exit_qemu, QemuExitCode};
pub use io::vga_text::OStream;
pub use io::{qemu, serial, vga_text};
pub use qemu::*;

#[cfg(test)]
#[no_mangle]
pub extern "C" fn _start() -> ! {
    init();
    test_main();
    #[allow(clippy::empty_loop)]
    loop {}
}

#[cfg(test)]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
    testing::serial_panic(info)
}

pub fn init() {
    interrupts::gdt::init();
    interrupts::idt::init();
    let apic = unsafe {
        interrupts::apic::try_initialize_local_apic()
            .as_mut()
            .expect("no APIC support")
    };

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

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