From c2e4e8c96ffcfe990eb94401d9e81a81dd6ec9ea Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 25 Jan 2019 14:16:29 +0100 Subject: [PATCH] Add and use hlt_loop function --- src/interrupts.rs | 4 ++-- src/lib.rs | 6 ++++++ src/main.rs | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/interrupts.rs b/src/interrupts.rs index f308e172..d6f80904 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -3,7 +3,7 @@ // for a Windows system. #![cfg(not(windows))] -use crate::{gdt, print, println}; +use crate::{gdt, hlt_loop, print, println}; use lazy_static::lazy_static; use pic8259_simple::ChainedPics; use spin; @@ -45,7 +45,7 @@ extern "x86-interrupt" fn double_fault_handler( _error_code: u64, ) { println!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame); - loop {} + hlt_loop(); } extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: &mut ExceptionStackFrame) { diff --git a/src/lib.rs b/src/lib.rs index 0bd6fe54..34debc4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,3 +12,9 @@ pub unsafe fn exit_qemu() { let mut port = Port::::new(0xf4); port.write(0); } + +pub fn hlt_loop() -> ! { + loop { + x86_64::instructions::hlt(); + } +} diff --git a/src/main.rs b/src/main.rs index 1cdc2645..a5173ea9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ pub extern "C" fn _start() -> ! { x86_64::instructions::interrupts::enable(); println!("It did not crash!"); - loop {} + blog_os::hlt_loop(); } /// This function is called on panic. @@ -26,5 +26,5 @@ pub extern "C" fn _start() -> ! { #[panic_handler] fn panic(info: &PanicInfo) -> ! { println!("{}", info); - loop {} + blog_os::hlt_loop(); }