From e91718648e6fcadb707f890ad508c940aaf4a4c0 Mon Sep 17 00:00:00 2001 From: Jackey-Huo Date: Fri, 3 May 2019 11:33:44 +0800 Subject: [PATCH] add htif read function for rocket-chip --- kernel/src/arch/riscv32/mod.rs | 7 ------- kernel/src/fs/stdio.rs | 16 ++++++++++++++-- kernel/src/shell.rs | 5 ++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/kernel/src/arch/riscv32/mod.rs b/kernel/src/arch/riscv32/mod.rs index a0c5cd91..e22b7d9e 100644 --- a/kernel/src/arch/riscv32/mod.rs +++ b/kernel/src/arch/riscv32/mod.rs @@ -48,13 +48,6 @@ pub extern "C" fn rust_main(hartid: usize, device_tree_paddr: usize) -> ! { hartid, device_tree_vaddr ); - //while true { - //let fuck_char = get_char_fuck(); - //if fuck_char as u8 != 254 { - //print!("{0}", fuck_char as char); - //} - //} - crate::logging::init(); interrupt::init(); memory::init(device_tree_vaddr); diff --git a/kernel/src/fs/stdio.rs b/kernel/src/fs/stdio.rs index 3967e412..429b80c6 100644 --- a/kernel/src/fs/stdio.rs +++ b/kernel/src/fs/stdio.rs @@ -28,7 +28,14 @@ impl Stdin { return c; } } - #[cfg(not(feature = "board_k210"))] + #[cfg(feature = "board_rocket_chip")] + loop { + let c = crate::arch::io::getchar(); + if c != '\0' && c as u8 != 254 { + return c; + } + } + #[cfg(not(any(feature = "board_k210", feature = "board_rocket_chip")))] loop { let ret = self.buf.lock().pop_front(); match ret { @@ -38,7 +45,12 @@ impl Stdin { } } pub fn can_read(&self) -> bool { - self.buf.lock().len() > 0 + // Currently, rocket-chip implementation rely on htif interface, the serial interrupt DO + // NOT work, so return true always + #[cfg(feature = "board_rocket_chip")] + return true; + #[cfg(not(feature = "board_rocket_chip"))] + return self.buf.lock().len() > 0; } } diff --git a/kernel/src/shell.rs b/kernel/src/shell.rs index 3e28227e..816be570 100644 --- a/kernel/src/shell.rs +++ b/kernel/src/shell.rs @@ -5,6 +5,7 @@ use crate::fs::{INodeExt, ROOT_INODE}; use crate::process::*; use alloc::string::String; use alloc::vec::Vec; +use crate::arch::io; #[cfg(not(feature = "run_cmdline"))] pub fn add_user_shell() { @@ -31,10 +32,12 @@ pub fn add_user_shell() { let init_args = vec!["busybox".into(), "ash".into()]; if let Ok(inode) = ROOT_INODE.lookup(init_shell) { + println!("use fucking up busybox"); processor() .manager() .add(Thread::new_user(&inode, init_shell, init_args, init_envs)); } else { + println!("not use fucking up busybox, but shell"); processor().manager().add(Thread::new_kernel(shell, 0)); } } @@ -46,9 +49,9 @@ pub fn add_user_shell() { println!("not use the fucking up busybox"); processor().manager().add(Thread::new_user( &inode, + "/busybox", cmdline.split(' ').map(|s| s.into()).collect(), Vec::new(), - Vec::new(), )); }