Allow userspace to handle IRQs (WIP). Create basic keyboard handler

This commit is contained in:
Jeremy Soller 2016-09-18 20:17:08 -06:00
parent 4bcee99d9f
commit 36fde7c7c5
8 changed files with 115 additions and 24 deletions

View file

@ -21,7 +21,8 @@ impl InitFsScheme {
files.insert(b"bin/init", include_bytes!("../../build/userspace/init"));
files.insert(b"bin/ion", include_bytes!("../../build/userspace/ion"));
files.insert(b"bin/pcid", include_bytes!("../../build/userspace/pcid"));
files.insert(b"etc/init.rc", b"echo testing\ninitfs:bin/pcid\ninitfs:bin/ion");
files.insert(b"bin/ps2d", include_bytes!("../../build/userspace/ps2d"));
files.insert(b"etc/init.rc", b"echo testing\n#initfs:bin/pcid\ninitfs:bin/ps2d\n#initfs:bin/ion");
InitFsScheme {
next_id: 0,

View file

@ -1,6 +1,6 @@
use core::{mem, str};
use arch::interrupt::irq::COUNTS;
use arch::interrupt::irq::{COUNTS, acknowledge};
use context;
use syscall::{Error, Result};
use super::Scheme;
@ -10,7 +10,9 @@ pub struct IrqScheme;
impl Scheme for IrqScheme {
fn open(&mut self, path: &[u8], _flags: usize) -> Result<usize> {
let path_str = str::from_utf8(path).or(Err(Error::NoEntry))?;
let id = path_str.parse::<usize>().or(Err(Error::NoEntry))?;
if id < COUNTS.lock().len() {
Ok(id)
} else {
@ -19,35 +21,49 @@ impl Scheme for IrqScheme {
}
fn dup(&mut self, file: usize) -> Result<usize> {
Ok(file)
Err(Error::NotPermitted)
}
fn read(&mut self, file: usize, buffer: &mut [u8]) -> Result<usize> {
// Ensures that the length of the buffer is larger than the size of a usize
if buffer.len() >= mem::size_of::<usize>() {
let current = COUNTS.lock()[file];
let prev = { COUNTS.lock()[file] };
loop {
let next = COUNTS.lock()[file];
if next != current {
// Safe if the length of the buffer is larger than the size of a usize
assert!(buffer.len() >= mem::size_of::<usize>());
unsafe { *(buffer.as_mut_ptr() as *mut usize) = next };
return Ok(mem::size_of::<usize>());
} else {
// Safe if all locks have been dropped
unsafe { context::switch(); }
{
let current = COUNTS.lock()[file];
if prev != current {
// Safe if the length of the buffer is larger than the size of a usize
assert!(buffer.len() >= mem::size_of::<usize>());
unsafe { *(buffer.as_mut_ptr() as *mut usize) = current; }
return Ok(mem::size_of::<usize>());
}
}
// Safe if all locks have been dropped
unsafe { context::switch(); }
}
} else {
Err(Error::InvalidValue)
}
}
fn write(&mut self, _file: usize, _buffer: &[u8]) -> Result<usize> {
Err(Error::NotPermitted)
fn write(&mut self, file: usize, buffer: &[u8]) -> Result<usize> {
if buffer.len() >= mem::size_of::<usize>() {
assert!(buffer.len() >= mem::size_of::<usize>());
let prev = unsafe { *(buffer.as_ptr() as *const usize) };
let current = COUNTS.lock()[file];
if prev == current {
unsafe { acknowledge(file); }
return Ok(mem::size_of::<usize>());
} else {
return Ok(0);
}
} else {
Err(Error::InvalidValue)
}
}
fn fsync(&mut self, file: usize) -> Result<()> {
fn fsync(&mut self, _file: usize) -> Result<()> {
Ok(())
}