blob: 42de2be16f816bc740efde31ea08180584553c40 (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
//! # Kernel
//!
//! Kernel Start
#![no_std] // don't link the Rust standard library
#![no_main] // disable all Rust-level entry points
#![feature(const_mut_refs)]
#![feature(custom_test_frameworks)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]
mod serial;
mod sync;
mod tests;
mod vga;
use serial::*;
use vga::*;
use core::panic::PanicInfo;
#[cfg(test)]
mod qemu;
#[cfg(test)]
use qemu::*;
#[cfg(test)]
use tests::*;
/// This function is called on panic.
#[cfg(test)]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
serial_println!("[failed]\n");
serial_println!("Error: {}\n", info);
exit_qemu(QemuExitCode::Failed);
loop {}
}
/// This function is called on panic.
#[cfg(not(test))]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
println!("{}", info);
loop {}
}
/// # Initialization
///
/// Provides serial and VGA initialization.
fn kernel_init() {
WRITER.init();
SERIAL1.init();
}
/// # x86_64 Kernel
#[no_mangle]
pub extern "C" fn _start() -> ! {
kernel_init();
#[cfg(not(test))]
{
WRITER.write_string("Hello World!");
WRITER.write_string("\n\nHi\n");
println!("{}", 5);
}
#[cfg(test)]
test_main();
loop {}
}
|