diff --git a/README.md b/README.md index cfd03e3..ea3fb39 100644 --- a/README.md +++ b/README.md @@ -113,8 +113,8 @@ qemu-system-i386 -cdrom gratos.x86.grub.iso - [x] try to implement `memory dumping` and `debug` in the last "mini-shell" subject - [ ] KFS-4 (gratOS:0.4.0): - [ ] Mandatory: - - [ ] Registers cleaning - - [ ] Stack saving + - [x] Registers cleaning + - [x] Stack saving - [x] Hardware Interrupts - [ ] Software Interrupts - [x] A Interrupts Descriptor Table diff --git a/src/driver/shell/mod.rs b/src/driver/shell/mod.rs index 3e8e80b..34e6348 100644 --- a/src/driver/shell/mod.rs +++ b/src/driver/shell/mod.rs @@ -1,4 +1,4 @@ -mod debug; +pub mod debug; mod hexdump; use super::console::{self, NUMBER_OF_REGULAR_TTY}; diff --git a/src/main.rs b/src/main.rs index 65865f4..751306d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,9 +17,10 @@ use crate::{ driver::{ console::{self, FG_RED, FG_RESET, RESET}, keyboard::ps2::KEYBOARD, - pic, shell, + pic, + shell::{self, debug::print_stack}, }, - power::halt, + power::{clean_registers::clean_registers, halt}, }; use core::{ arch::{asm, global_asm}, @@ -30,7 +31,11 @@ use core::{ fn panic(info: &PanicInfo) -> ! { println!("{RESET}{FG_RED}"); println!("{info}"); + print_stack(128); print!("{FG_RESET}"); + unsafe { + clean_registers(); + } halt::halt(); } diff --git a/src/power/clean_registers.rs b/src/power/clean_registers.rs new file mode 100644 index 0000000..a90c523 --- /dev/null +++ b/src/power/clean_registers.rs @@ -0,0 +1,16 @@ +use core::arch::asm; + +pub unsafe fn clean_registers() { + unsafe { + asm!( + "xor eax, eax", + "xor ebx, ebx", + "xor ecx, ecx", + "xor edx, edx", + "xor esi, esi", + "xor edi, edi", + "xor ebp, ebp", + options(nomem, nostack, preserves_flags) + ); + } +} diff --git a/src/power/mod.rs b/src/power/mod.rs index 2f64f12..35a305b 100644 --- a/src/power/mod.rs +++ b/src/power/mod.rs @@ -1,3 +1,4 @@ +pub mod clean_registers; pub mod halt; pub mod reboot; pub mod shutdown;