From 34f0dde5113ae40bb341cf54e31e8536d25a0cc8 Mon Sep 17 00:00:00 2001 From: zhangxinyu <840317537@qq.com> Date: Wed, 17 May 2023 13:19:12 +0800 Subject: [PATCH] =?UTF-8?q?println=20=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch2/user/src/user_lang_items/user_console.rs | 3 ++- ch2/user/src/user_lang_items/user_panic.rs | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ch2/user/src/user_lang_items/user_console.rs b/ch2/user/src/user_lang_items/user_console.rs index d1ca998..39f3daf 100644 --- a/ch2/user/src/user_lang_items/user_console.rs +++ b/ch2/user/src/user_lang_items/user_console.rs @@ -1,4 +1,5 @@ use core::fmt::{Arguments, Write, Result}; +use crate::syscall::sys_write; struct Stdout; @@ -6,7 +7,7 @@ const STDOUT: usize = 1; impl Write for Stdout { fn write_str(&mut self, s: &str) -> Result { - // ... todo 实现系统调用 + sys_write(STDOUT, s.as_bytes()); Ok(()) } } diff --git a/ch2/user/src/user_lang_items/user_panic.rs b/ch2/user/src/user_lang_items/user_panic.rs index 0fd119e..e38650e 100644 --- a/ch2/user/src/user_lang_items/user_panic.rs +++ b/ch2/user/src/user_lang_items/user_panic.rs @@ -1,16 +1,17 @@ use core::panic::PanicInfo; +use crate::println; #[panic_handler] fn panic(info: &PanicInfo) -> ! { if let Some(location) = info.location() { - // println!( - // "Panicked at {}:{} {}", - // location.file(), - // location.line(), - // info.message().unwrap() - // ); + println!( + "Panicked at {}:{} {}", + location.file(), + location.line(), + info.message().unwrap() + ); } else { - // println!("Panicked: {}", info.message().unwrap()); + println!("Panicked: {}", info.message().unwrap()); } loop {