添加user_console用户态的print相关接口,但是并未实现系统调用

ch2
zhangxinyu 2 years ago
parent 8b8d353e86
commit 5ce82f274e

@ -1,9 +1,9 @@
#![no_std]
#![no_main]
use user_lib;
use user_lib::*;
#[no_mangle]
fn main() {
println!("123");
}

@ -2,7 +2,8 @@
#![feature(linkage)] // 开启弱链接特性
#![feature(panic_info_message)]
mod user_lang_items;
pub mod user_lang_items;
pub use user_lang_items::*;
#[linkage = "weak"] // 设置我们默认的main函数, 弱链接
#[no_mangle]

@ -1 +1,2 @@
pub mod user_panic;
pub mod user_console;

@ -0,0 +1,31 @@
use core::fmt::{Arguments, Write, Result};
struct Stdout;
const STDOUT: usize = 1;
impl Write for Stdout {
fn write_str(&mut self, s: &str) -> Result {
// ... todo 实现系统调用
Ok(())
}
}
pub fn print(args: Arguments) {
Stdout.write_fmt(args).unwrap();
}
#[macro_export]
macro_rules! print {
($fmt: literal $(, $($arg: tt)+)?) => {
$crate::user_console::print(format_args!($fmt $(, $($arg)+)?));
}
}
#[macro_export]
macro_rules! println {
($fmt: literal $(, $($arg: tt)+)?) => {
$crate::user_console::print(format_args!(concat!($fmt, "\n") $(, $($arg)+)?));
}
}
Loading…
Cancel
Save