From 578904198c2c3a29bf374d8b7f359dac848007ac Mon Sep 17 00:00:00 2001 From: guillaume didier Date: Tue, 12 Nov 2019 18:04:11 +0100 Subject: [PATCH] Get things to run under linux, also fix serial console --- rust-toolchain | 3 ++- scripts/bochsrc | 10 +++++----- src/interrupts.rs | 13 +++++++++---- src/main.rs | 10 ++++++++-- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/rust-toolchain b/rust-toolchain index 580640b..c1a4c6b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1,2 @@ -nightly-2019-09-28 \ No newline at end of file +nightly + diff --git a/scripts/bochsrc b/scripts/bochsrc index bc0c6c1..3b45ca6 100644 --- a/scripts/bochsrc +++ b/scripts/bochsrc @@ -16,7 +16,7 @@ # 'usb_ehci', 'usb_ohci', 'usb_uhci', 'usb_xhci' and 'voodoo'. #======================================================================= #plugin_ctrl: unmapped=0, e1000=1 # unload 'unmapped' and load 'e1000' -plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1 +plugin_ctrl: unmapped=1, biosdev=1, speaker=0, extfpuirq=1, parallel=1, serial=1 #======================================================================= # CONFIG_INTERFACE # @@ -34,7 +34,7 @@ plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1 # NOTE: if you use the "wx" configuration interface, you must also use # the "wx" display library. #======================================================================= -config_interface: textconfig +#config_interface: textconfig #config_interface: win32config #config_interface: wx @@ -91,7 +91,7 @@ config_interface: textconfig #display_library: win32 #display_library: wx #display_library: x -#display_library: gui_debug +display_library: x, options="gui_debug" #======================================================================= # CPU: @@ -185,7 +185,7 @@ config_interface: textconfig # 2.2.6 2.6Ghz Intel Core 2 Duo with WinXP/g++ 3.4 21 to 25 Mips # 2.2.6 2.1Ghz Athlon XP with Linux 2.6/g++ 3.4 12 to 15 Mips #======================================================================= -cpu: model=ryzen, count=1,, reset_on_triple_fault=0 +cpu: model=corei7_sandy_bridge_2600k, count=1, ips=50000000, reset_on_triple_fault=0 #======================================================================= # CPUID: @@ -857,7 +857,7 @@ debugger_log: - # com4: enabled=1, mode=pipe-client, dev=\\.\pipe\mypipe # com4: enabled=1, mode=pipe-server, dev=\\.\pipe\mypipe #======================================================================= -com1: enabled=1, mode=term, dev=/dev/stdin +com1: enabled=1, mode=socket-server, dev=127.0.0.1:8000 #======================================================================= diff --git a/src/interrupts.rs b/src/interrupts.rs index 18880a6..e709eee 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -60,6 +60,7 @@ extern "x86-interrupt" fn double_fault_handler(sf: &mut InterruptStackFrame, e: } use x86_64::structures::idt::PageFaultErrorCode; +use x86_64::instructions::bochs_breakpoint; extern "x86-interrupt" fn page_fault_handler(sf: &mut InterruptStackFrame, e: PageFaultErrorCode) { // LLVM bug causing misaligned stacks when error codes are present. @@ -76,9 +77,13 @@ extern "x86-interrupt" fn page_fault_handler(sf: &mut InterruptStackFrame, e: Pa error_code = *(&e as *const PageFaultErrorCode).offset(1) as PageFaultErrorCode; } - println!("EXCEPTION: PAGE FAULT"); - println!("Accessed Address: {:?}", Cr2::read()); - println!("Error Code: {:?}", error_code); - println!("{:#?}", stack_frame); + serial_println!("EXCEPTION: PAGE FAULT"); + serial_println!("Accessed Address: {:?}", Cr2::read()); + serial_println!("Error Code: {:?}", error_code); + serial_println!("{:#?}", stack_frame); + + serial_println!("Halting..."); + bochs_breakpoint(); + hlt_loop(); } diff --git a/src/main.rs b/src/main.rs index 04e61d9..19bdb5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,7 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { #[cfg(test)] test_main(); - println!("Preparing nasty fault..."); + x86_64::instructions::interrupts::int3(); @@ -55,12 +55,18 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { level_4_page_table.start_address(), flags ); + serial_println!( + "Level 4 page table at: {:?}, flags {:?}", + level_4_page_table.start_address(), + flags + ); + serial_println!("Preparing nasty fault..."); unsafe { *(0xdeadbeef as *mut u64) = 42; } - println!("Survived ? oO"); + serial_println!("Survived ? oO"); // magic break ? // x86_64::instructions::bochs_breakpoint();