summaryrefslogtreecommitdiff
path: root/kernel/src/main.rs
blob: 017f4b994c08ac03c1a0230e0badb55c92f4223f (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(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;

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() -> ! {
    interrupts::gdt::init();
    interrupts::idt::init();

    loop {}
    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();

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

    if cfg!(test) {
        qemu::exit_qemu(qemu::QemuExitCode::Success);
    }
    #[allow(clippy::empty_loop)]
    loop {}
}

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