summaryrefslogtreecommitdiff
path: root/kernel/src/main.rs
blob: a0e1e5646cb9a56d3f0958fbcb6a03b12db5a00b (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
#![no_main]
#![feature(compiler_builtins_lib)]
#![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");

    loop {
        stdout.set_col(0);
        use core::fmt::Write;
        //let n = apic.get_timer_value();
        let n = apic.get_error_code();
        write!(&mut stdout, "timer: {}             ", n);
        //write!(&mut stdout, "timer: {:08x}             ", apic.ptr() as usize);
    }

    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);
}