println 实现

ch2
zhangxinyu 2 years ago
parent fc02e9f961
commit 34f0dde511

@ -1,4 +1,5 @@
use core::fmt::{Arguments, Write, Result}; use core::fmt::{Arguments, Write, Result};
use crate::syscall::sys_write;
struct Stdout; struct Stdout;
@ -6,7 +7,7 @@ const STDOUT: usize = 1;
impl Write for Stdout { impl Write for Stdout {
fn write_str(&mut self, s: &str) -> Result { fn write_str(&mut self, s: &str) -> Result {
// ... todo 实现系统调用 sys_write(STDOUT, s.as_bytes());
Ok(()) Ok(())
} }
} }

@ -1,16 +1,17 @@
use core::panic::PanicInfo; use core::panic::PanicInfo;
use crate::println;
#[panic_handler] #[panic_handler]
fn panic(info: &PanicInfo) -> ! { fn panic(info: &PanicInfo) -> ! {
if let Some(location) = info.location() { if let Some(location) = info.location() {
// println!( println!(
// "Panicked at {}:{} {}", "Panicked at {}:{} {}",
// location.file(), location.file(),
// location.line(), location.line(),
// info.message().unwrap() info.message().unwrap()
// ); );
} else { } else {
// println!("Panicked: {}", info.message().unwrap()); println!("Panicked: {}", info.message().unwrap());
} }
loop { loop {

Loading…
Cancel
Save