RustForge

rust-kernel

Rustbelt: a hobby x86_64 kernel written in Rust

rust-kernel / src / arch / x86_64 / mod.rs
1162 bytes ยท raw
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
//! The PC's side of the `arch` interface (see src/arch/mod.rs). Stage 22
//! adds no new code for x86_64: these are thin names for the pieces that
//! already exist elsewhere in src/, which stay exactly where they were.

/// Text out: COM1, the serial port (src/serial.rs).
pub mod console {
    pub fn write_str(s: &str) {
        crate::serial::_print(format_args!("{}", s));
    }
}

/// GDT, IDT, the PICs, then `sti` (lib.rs's `init`).
pub mod interrupts {
    pub fn init() {
        crate::init();
    }
    pub fn enable() {
        ::x86_64::instructions::interrupts::enable();
    }
}

/// The PIT tick count (src/interrupts.rs).
pub mod timer {
    pub fn ticks() -> u64 {
        crate::interrupts::ticks()
    }
}

/// Paging: the bootloader turned it on; src/memory.rs takes over.
pub mod paging {
    pub use crate::memory::init;
}

/// End the QEMU run: 0 -> exit code 33, anything else -> 35 (isa-debug-exit).
pub fn exit(code: u32) -> ! {
    crate::exit_qemu(if code == 0 { crate::QemuExitCode::Success } else { crate::QemuExitCode::Failed });
    crate::hlt_loop()
}

/// Stop this CPU for good.
pub fn halt() -> ! {
    crate::hlt_loop()
}