2019-10-06 17:16:19 +02:00
|
|
|
// main.rs
|
|
|
|
// main file of the kernel
|
|
|
|
|
|
|
|
#![no_std] // This is a free standing program
|
|
|
|
#![no_main] // This has no crt0
|
2019-10-21 13:10:53 +02:00
|
|
|
#![feature(custom_test_frameworks)]
|
|
|
|
#![test_runner(dendrobates_tinctoreus_azureus::test_runner)]
|
|
|
|
#![reexport_test_harness_main = "test_main"]
|
|
|
|
|
|
|
|
use polling_serial::{serial_print, serial_println};
|
2019-11-04 13:54:43 +01:00
|
|
|
use vga_buffer::{print, println, set_colors, Color, ForegroundColor};
|
2019-10-06 17:16:19 +02:00
|
|
|
|
|
|
|
use core::fmt::Write;
|
2019-10-21 13:10:53 +02:00
|
|
|
use core::panic::PanicInfo;
|
|
|
|
use vga_buffer; // required for custom panic handler
|
2019-10-06 17:16:19 +02:00
|
|
|
|
2019-11-04 13:54:43 +01:00
|
|
|
use dendrobates_tinctoreus_azureus::hlt_loop;
|
2019-10-06 17:16:19 +02:00
|
|
|
use x86_64;
|
|
|
|
|
2019-11-10 17:42:14 +01:00
|
|
|
use bootloader::{entry_point, BootInfo};
|
2019-11-04 14:48:49 +01:00
|
|
|
|
2019-10-06 17:16:19 +02:00
|
|
|
// Custom panic handler, required for freestanding program
|
2019-10-21 13:10:53 +02:00
|
|
|
#[cfg(not(test))]
|
2019-10-06 17:16:19 +02:00
|
|
|
#[panic_handler]
|
2019-10-21 13:10:53 +02:00
|
|
|
fn panic(info: &PanicInfo) -> ! {
|
|
|
|
serial_println!("{}", info);
|
2019-11-04 13:54:43 +01:00
|
|
|
set_colors(ForegroundColor::LightRed, Color::Blue);
|
2019-10-21 13:10:53 +02:00
|
|
|
println!("{}", info);
|
2019-11-04 13:54:43 +01:00
|
|
|
x86_64::instructions::bochs_breakpoint();
|
|
|
|
hlt_loop();
|
2019-10-06 17:16:19 +02:00
|
|
|
}
|
|
|
|
|
2019-11-04 14:48:49 +01:00
|
|
|
entry_point!(kernel_main);
|
|
|
|
|
2019-10-06 17:16:19 +02:00
|
|
|
// Kernel entry point
|
2019-11-10 17:42:14 +01:00
|
|
|
fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
2019-10-06 17:16:19 +02:00
|
|
|
// TODO: Take care of cpuid stuff and set-up all floating point exetnsions
|
|
|
|
// TODO: We may also need to enable debug registers ?
|
|
|
|
|
2019-10-21 13:10:53 +02:00
|
|
|
println!("Hello Blue Frog");
|
2019-11-04 13:54:43 +01:00
|
|
|
dendrobates_tinctoreus_azureus::init();
|
|
|
|
x86_64::instructions::interrupts::int3(); // new
|
2019-10-21 13:10:53 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
test_main();
|
2019-10-06 17:16:19 +02:00
|
|
|
|
2019-11-12 18:04:11 +01:00
|
|
|
|
2019-11-04 13:54:43 +01:00
|
|
|
|
|
|
|
x86_64::instructions::interrupts::int3();
|
|
|
|
|
2019-11-04 14:48:49 +01:00
|
|
|
use x86_64::registers::control::Cr3;
|
|
|
|
|
|
|
|
let (level_4_page_table, flags) = Cr3::read();
|
|
|
|
println!(
|
|
|
|
"Level 4 page table at: {:?}, flags {:?}",
|
|
|
|
level_4_page_table.start_address(),
|
|
|
|
flags
|
|
|
|
);
|
2019-11-12 18:04:11 +01:00
|
|
|
serial_println!(
|
|
|
|
"Level 4 page table at: {:?}, flags {:?}",
|
|
|
|
level_4_page_table.start_address(),
|
|
|
|
flags
|
|
|
|
);
|
2019-11-04 14:48:49 +01:00
|
|
|
|
2019-11-12 18:04:11 +01:00
|
|
|
serial_println!("Preparing nasty fault...");
|
2019-11-04 13:54:43 +01:00
|
|
|
unsafe {
|
|
|
|
*(0xdeadbeef as *mut u64) = 42;
|
|
|
|
}
|
|
|
|
|
2019-11-12 18:04:11 +01:00
|
|
|
serial_println!("Survived ? oO");
|
2019-11-04 13:54:43 +01:00
|
|
|
|
2019-10-06 17:16:19 +02:00
|
|
|
// magic break ?
|
2019-10-21 13:10:53 +02:00
|
|
|
// x86_64::instructions::bochs_breakpoint();
|
|
|
|
panic!("Ooops Sorry");
|
|
|
|
}
|
2019-10-06 17:16:19 +02:00
|
|
|
|
2019-10-21 13:10:53 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
#[panic_handler]
|
|
|
|
fn panic(info: &PanicInfo) -> ! {
|
|
|
|
use dendrobates_tinctoreus_azureus::test_panic_handler;
|
|
|
|
test_panic_handler(info);
|
|
|
|
}
|
2019-10-06 17:16:19 +02:00
|
|
|
|
2019-10-21 13:10:53 +02:00
|
|
|
#[test_case]
|
|
|
|
fn float_test() {
|
|
|
|
serial_println!("Testing float computations...");
|
|
|
|
use volatile::Volatile;
|
|
|
|
// Make a few floating points test;
|
|
|
|
let vf: f32 = 84798.0;
|
|
|
|
let vd: f64 = 0.828494623655914;
|
|
|
|
|
|
|
|
let a: Volatile<f32> = Volatile::new(42.0);
|
|
|
|
let b: Volatile<f32> = Volatile::new(2019.);
|
|
|
|
let rf = a.read() * b.read();
|
|
|
|
|
|
|
|
let c: Volatile<f64> = Volatile::new(15.410);
|
|
|
|
let d: Volatile<f64> = Volatile::new(18.600);
|
|
|
|
|
|
|
|
let rd = c.read() / d.read();
|
|
|
|
|
|
|
|
serial_print!(
|
|
|
|
" {:?} * {:?} = {:?} expected {:?}...",
|
|
|
|
a.read(),
|
|
|
|
b.read(),
|
|
|
|
rf,
|
|
|
|
vf
|
|
|
|
);
|
|
|
|
if (rf == vf) {
|
|
|
|
serial_println!("[ok]");
|
|
|
|
} else {
|
|
|
|
serial_println!("[fail]");
|
|
|
|
}
|
|
|
|
serial_print!(
|
|
|
|
" {:?} / {:?} = {:?} expected {:?}...",
|
|
|
|
c.read(),
|
|
|
|
d.read(),
|
|
|
|
rd,
|
|
|
|
vd
|
|
|
|
);
|
|
|
|
if (rd == vd) {
|
|
|
|
serial_println!("[ok]");
|
|
|
|
} else {
|
|
|
|
serial_println!("[fail]");
|
|
|
|
}
|
|
|
|
assert_eq!(rf, vf);
|
|
|
|
assert_eq!(rd, vd);
|
|
|
|
serial_println!("Testing float computations... [ok]");
|
2019-10-06 17:16:19 +02:00
|
|
|
}
|
2019-10-21 13:10:53 +02:00
|
|
|
|
|
|
|
//#[test_case]
|
|
|
|
//fn failing_assertion() {
|
|
|
|
// print!("trivial assertion... ");
|
|
|
|
// serial_print!("trivial assertion... ");
|
|
|
|
// assert_eq!(1, 1);
|
|
|
|
// println!("[ok]");
|
|
|
|
// serial_println!("[ok]");
|
|
|
|
//}
|