Allow userspace to handle IRQs (WIP). Create basic keyboard handler
This commit is contained in:
parent
4bcee99d9f
commit
36fde7c7c5
7
Makefile
7
Makefile
|
@ -26,6 +26,7 @@ clean:
|
||||||
cargo clean --manifest-path libstd/Cargo.toml
|
cargo clean --manifest-path libstd/Cargo.toml
|
||||||
cargo clean --manifest-path init/Cargo.toml
|
cargo clean --manifest-path init/Cargo.toml
|
||||||
cargo clean --manifest-path ion/Cargo.toml
|
cargo clean --manifest-path ion/Cargo.toml
|
||||||
|
cargo clean --manifest-path drivers/atkbd/Cargo.toml
|
||||||
cargo clean --manifest-path drivers/pcid/Cargo.toml
|
cargo clean --manifest-path drivers/pcid/Cargo.toml
|
||||||
rm -rf build
|
rm -rf build
|
||||||
|
|
||||||
|
@ -133,4 +134,8 @@ $(BUILD)/pcid: drivers/pcid/Cargo.toml drivers/pcid/src/** $(BUILD)/libstd.rlib
|
||||||
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
||||||
strip $@
|
strip $@
|
||||||
|
|
||||||
$(BUILD)/initfs.rs: $(BUILD)/init $(BUILD)/ion $(BUILD)/pcid
|
$(BUILD)/ps2d: drivers/ps2d/Cargo.toml drivers/ps2d/src/** $(BUILD)/libstd.rlib
|
||||||
|
$(CARGO) rustc --manifest-path $< $(CARGOFLAGS) -o $@
|
||||||
|
strip $@
|
||||||
|
|
||||||
|
$(BUILD)/initfs.rs: $(BUILD)/init $(BUILD)/ion $(BUILD)/pcid $(BUILD)/ps2d
|
||||||
|
|
|
@ -17,6 +17,14 @@ unsafe fn slave_ack() {
|
||||||
master_ack();
|
master_ack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub unsafe fn acknowledge(irq: usize) {
|
||||||
|
if irq >= 8 {
|
||||||
|
slave_ack();
|
||||||
|
} else {
|
||||||
|
master_ack();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interrupt!(pit, {
|
interrupt!(pit, {
|
||||||
COUNTS.lock()[0] += 1;
|
COUNTS.lock()[0] += 1;
|
||||||
master_ack();
|
master_ack();
|
||||||
|
@ -24,10 +32,6 @@ interrupt!(pit, {
|
||||||
|
|
||||||
interrupt!(keyboard, {
|
interrupt!(keyboard, {
|
||||||
COUNTS.lock()[1] += 1;
|
COUNTS.lock()[1] += 1;
|
||||||
if let Some(ref mut keyboard) = *PS2_KEYBOARD.lock(){
|
|
||||||
keyboard.on_irq();
|
|
||||||
}
|
|
||||||
master_ack();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
interrupt!(cascade, {
|
interrupt!(cascade, {
|
||||||
|
|
6
drivers/ps2d/Cargo.toml
Normal file
6
drivers/ps2d/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "ps2d"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[dependencies.syscall]
|
||||||
|
path = "../../syscall/"
|
59
drivers/ps2d/src/main.rs
Normal file
59
drivers/ps2d/src/main.rs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#![feature(asm)]
|
||||||
|
|
||||||
|
extern crate syscall;
|
||||||
|
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
|
use syscall::iopl;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if true {
|
||||||
|
unsafe {
|
||||||
|
iopl(3).expect("pskbd: failed to get I/O permission");
|
||||||
|
asm!("cli" :::: "intel", "volatile");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut file = File::open("irq:1").expect("pskbd: failed to open irq:1");
|
||||||
|
|
||||||
|
println!("pskbd: Reading keyboard IRQs");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let mut irqs = [0; 8];
|
||||||
|
file.read(&mut irqs).expect("pskbd: failed to read irq:1");
|
||||||
|
|
||||||
|
let data: u8;
|
||||||
|
unsafe {
|
||||||
|
asm!("in al, dx" : "={al}"(data) : "{dx}"(0x60) : : "intel", "volatile");
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("pskbd: IRQ {}: {:X}", unsafe { *(irqs.as_ptr() as *const usize) }, data);
|
||||||
|
|
||||||
|
file.write(&irqs).expect("pskbd: failed to write irq:1");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unsafe {
|
||||||
|
iopl(3).expect("psmsd: failed to get I/O permission");
|
||||||
|
asm!("cli" :::: "intel", "volatile");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut file = File::open("irq:12").expect("psmsd: failed to open irq:12");
|
||||||
|
|
||||||
|
println!("psmsd: Reading mouse IRQs");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let mut count = [0; 8];
|
||||||
|
file.read(&mut count).expect("psmsd: failed to read irq:12");
|
||||||
|
|
||||||
|
let data: u8;
|
||||||
|
unsafe {
|
||||||
|
asm!("in al, dx" : "={al}"(data) : "{dx}"(0x60) : : "intel", "volatile");
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("psmsd: IRQ: {:X}", data);
|
||||||
|
|
||||||
|
file.write(&count).expect("psmsd: failed to write irq:12");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ pub struct Memory {
|
||||||
flags: EntryFlags
|
flags: EntryFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum SharedMemory {
|
pub enum SharedMemory {
|
||||||
Owned(Arc<Mutex<Memory>>),
|
Owned(Arc<Mutex<Memory>>),
|
||||||
Borrowed(Weak<Mutex<Memory>>)
|
Borrowed(Weak<Mutex<Memory>>)
|
||||||
|
|
|
@ -21,7 +21,8 @@ impl InitFsScheme {
|
||||||
files.insert(b"bin/init", include_bytes!("../../build/userspace/init"));
|
files.insert(b"bin/init", include_bytes!("../../build/userspace/init"));
|
||||||
files.insert(b"bin/ion", include_bytes!("../../build/userspace/ion"));
|
files.insert(b"bin/ion", include_bytes!("../../build/userspace/ion"));
|
||||||
files.insert(b"bin/pcid", include_bytes!("../../build/userspace/pcid"));
|
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 {
|
InitFsScheme {
|
||||||
next_id: 0,
|
next_id: 0,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use core::{mem, str};
|
use core::{mem, str};
|
||||||
|
|
||||||
use arch::interrupt::irq::COUNTS;
|
use arch::interrupt::irq::{COUNTS, acknowledge};
|
||||||
use context;
|
use context;
|
||||||
use syscall::{Error, Result};
|
use syscall::{Error, Result};
|
||||||
use super::Scheme;
|
use super::Scheme;
|
||||||
|
@ -10,7 +10,9 @@ pub struct IrqScheme;
|
||||||
impl Scheme for IrqScheme {
|
impl Scheme for IrqScheme {
|
||||||
fn open(&mut self, path: &[u8], _flags: usize) -> Result<usize> {
|
fn open(&mut self, path: &[u8], _flags: usize) -> Result<usize> {
|
||||||
let path_str = str::from_utf8(path).or(Err(Error::NoEntry))?;
|
let path_str = str::from_utf8(path).or(Err(Error::NoEntry))?;
|
||||||
|
|
||||||
let id = path_str.parse::<usize>().or(Err(Error::NoEntry))?;
|
let id = path_str.parse::<usize>().or(Err(Error::NoEntry))?;
|
||||||
|
|
||||||
if id < COUNTS.lock().len() {
|
if id < COUNTS.lock().len() {
|
||||||
Ok(id)
|
Ok(id)
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,35 +21,49 @@ impl Scheme for IrqScheme {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dup(&mut self, file: usize) -> Result<usize> {
|
fn dup(&mut self, file: usize) -> Result<usize> {
|
||||||
Ok(file)
|
Err(Error::NotPermitted)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read(&mut self, file: usize, buffer: &mut [u8]) -> Result<usize> {
|
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
|
// Ensures that the length of the buffer is larger than the size of a usize
|
||||||
if buffer.len() >= mem::size_of::<usize>() {
|
if buffer.len() >= mem::size_of::<usize>() {
|
||||||
let current = COUNTS.lock()[file];
|
let prev = { COUNTS.lock()[file] };
|
||||||
loop {
|
loop {
|
||||||
let next = COUNTS.lock()[file];
|
{
|
||||||
if next != current {
|
let current = COUNTS.lock()[file];
|
||||||
|
if prev != current {
|
||||||
// Safe if the length of the buffer is larger than the size of a usize
|
// Safe if the length of the buffer is larger than the size of a usize
|
||||||
assert!(buffer.len() >= mem::size_of::<usize>());
|
assert!(buffer.len() >= mem::size_of::<usize>());
|
||||||
unsafe { *(buffer.as_mut_ptr() as *mut usize) = next };
|
unsafe { *(buffer.as_mut_ptr() as *mut usize) = current; }
|
||||||
return Ok(mem::size_of::<usize>());
|
return Ok(mem::size_of::<usize>());
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Safe if all locks have been dropped
|
// Safe if all locks have been dropped
|
||||||
unsafe { context::switch(); }
|
unsafe { context::switch(); }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Err(Error::InvalidValue)
|
Err(Error::InvalidValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&mut self, _file: usize, _buffer: &[u8]) -> Result<usize> {
|
fn write(&mut self, file: usize, buffer: &[u8]) -> Result<usize> {
|
||||||
Err(Error::NotPermitted)
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,11 +96,11 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<usize> {
|
||||||
|
|
||||||
if flags & CLONE_VM == CLONE_VM {
|
if flags & CLONE_VM == CLONE_VM {
|
||||||
for memory_shared in context.image.iter() {
|
for memory_shared in context.image.iter() {
|
||||||
image.push(memory_shared.borrow());
|
image.push(memory_shared.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref heap_shared) = context.heap {
|
if let Some(ref heap_shared) = context.heap {
|
||||||
heap_option = Some(heap_shared.borrow());
|
heap_option = Some(heap_shared.clone());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for memory_shared in context.image.iter() {
|
for memory_shared in context.image.iter() {
|
||||||
|
|
Loading…
Reference in a new issue