Add fsync. Add env scheme, currently hardcoded to get ion to launch. Make serial IRQ send data to debug scheme
This commit is contained in:
parent
1b056395bb
commit
483d466b1a
8 changed files with 164 additions and 4 deletions
|
@ -1,8 +1,25 @@
|
|||
use collections::VecDeque;
|
||||
use core::str;
|
||||
use spin::{Mutex, MutexGuard, Once};
|
||||
|
||||
use context;
|
||||
use syscall::Result;
|
||||
use super::Scheme;
|
||||
|
||||
/// Input
|
||||
static INPUT: Once<Mutex<VecDeque<u8>>> = Once::new();
|
||||
|
||||
/// Initialize contexts, called if needed
|
||||
fn init_input() -> Mutex<VecDeque<u8>> {
|
||||
Mutex::new(VecDeque::new())
|
||||
}
|
||||
|
||||
/// Get the global schemes list, const
|
||||
#[no_mangle]
|
||||
pub extern fn debug_input(b: u8) {
|
||||
INPUT.call_once(init_input).lock().push_back(b)
|
||||
}
|
||||
|
||||
pub struct DebugScheme;
|
||||
|
||||
impl Scheme for DebugScheme {
|
||||
|
@ -17,8 +34,23 @@ impl Scheme for DebugScheme {
|
|||
/// Read the file `number` into the `buffer`
|
||||
///
|
||||
/// Returns the number of bytes read
|
||||
fn read(&mut self, _file: usize, _buffer: &mut [u8]) -> Result<usize> {
|
||||
Ok(0)
|
||||
fn read(&mut self, _file: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
loop {
|
||||
let mut i = 0;
|
||||
{
|
||||
let mut input = INPUT.call_once(init_input).lock();
|
||||
while i < buf.len() && ! input.is_empty() {
|
||||
buf[i] = input.pop_front().expect("debug_input lost byte");
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if i > 0 {
|
||||
return Ok(i);
|
||||
} else {
|
||||
unsafe { context::switch(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Write the `buffer` to the `file`
|
||||
|
@ -30,6 +62,10 @@ impl Scheme for DebugScheme {
|
|||
Ok(buffer.len())
|
||||
}
|
||||
|
||||
fn fsync(&mut self, file: usize) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Close the file `number`
|
||||
fn close(&mut self, _file: usize) -> Result<()> {
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue