redox/kernel/scheme/debug.rs

69 lines
1.7 KiB
Rust
Raw Normal View History

2016-08-15 05:38:32 +02:00
use core::str;
use core::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
use spin::Once;
2016-08-26 01:03:01 +02:00
use context;
use sync::WaitQueue;
use syscall::error::*;
use syscall::flag::EVENT_READ;
use syscall::scheme::Scheme;
2016-08-15 05:38:32 +02:00
pub static DEBUG_SCHEME_ID: AtomicUsize = ATOMIC_USIZE_INIT;
/// Input queue
static INPUT: Once<WaitQueue<u8>> = Once::new();
/// Initialize input queue, called if needed
fn init_input() -> WaitQueue<u8> {
WaitQueue::new()
}
/// Add to the input queue
#[no_mangle]
pub extern fn debug_input(b: u8) {
let len = INPUT.call_once(init_input).send(b);
context::event::trigger(DEBUG_SCHEME_ID.load(Ordering::SeqCst), 0, EVENT_READ, len);
}
2016-08-15 05:38:32 +02:00
pub struct DebugScheme;
impl Scheme for DebugScheme {
2016-10-06 02:01:05 +02:00
fn open(&self, _path: &[u8], _flags: usize, _uid: u32, _gid: u32) -> Result<usize> {
2016-08-15 05:38:32 +02:00
Ok(0)
}
fn dup(&self, _file: usize, _buf: &[u8]) -> Result<usize> {
2016-09-12 01:31:21 +02:00
Ok(0)
}
2016-08-15 05:38:32 +02:00
/// Read the file `number` into the `buffer`
///
/// Returns the number of bytes read
fn read(&self, _file: usize, buf: &mut [u8]) -> Result<usize> {
2016-10-20 20:31:39 +02:00
Ok(INPUT.call_once(init_input).receive_into(buf, true))
2016-08-15 05:38:32 +02:00
}
/// Write the `buffer` to the `file`
///
/// Returns the number of bytes written
fn write(&self, _file: usize, buffer: &[u8]) -> Result<usize> {
2016-08-15 05:38:32 +02:00
//TODO: Write bytes, do not convert to str
print!("{}", unsafe { str::from_utf8_unchecked(buffer) });
Ok(buffer.len())
}
fn fevent(&self, _file: usize, _flags: usize) -> Result<usize> {
Ok(0)
}
fn fsync(&self, _file: usize) -> Result<usize> {
Ok(0)
}
2016-08-15 05:38:32 +02:00
/// Close the file `number`
fn close(&self, _file: usize) -> Result<usize> {
Ok(0)
2016-08-15 05:38:32 +02:00
}
}