Seperate PS/2 keyboard and mouse driver
This commit is contained in:
parent
70a2faa0c7
commit
727647dbf1
|
@ -4,6 +4,7 @@ use x86::io;
|
|||
use device::ps2::{PS2_KEYBOARD, PS2_MOUSE};
|
||||
use device::serial::{COM1, COM2};
|
||||
|
||||
pub static ACKS: Mutex<[usize; 16]> = Mutex::new([0; 16]);
|
||||
pub static COUNTS: Mutex<[usize; 16]> = Mutex::new([0; 16]);
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -88,10 +89,6 @@ interrupt!(pci3, {
|
|||
|
||||
interrupt!(mouse, {
|
||||
COUNTS.lock()[12] += 1;
|
||||
if let Some(ref mut mouse) = *PS2_MOUSE.lock() {
|
||||
mouse.on_irq();
|
||||
}
|
||||
slave_ack();
|
||||
});
|
||||
|
||||
interrupt!(fpu, {
|
||||
|
|
|
@ -73,8 +73,7 @@ pub extern crate x86;
|
|||
macro_rules! print {
|
||||
($($arg:tt)*) => ({
|
||||
use core::fmt::Write;
|
||||
let mut console = $crate::console::CONSOLE.lock();
|
||||
let _ = write!(console, $($arg)*);
|
||||
let _ = write!($crate::console::CONSOLE.lock(), $($arg)*);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,15 @@ extern crate syscall;
|
|||
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use std::mem;
|
||||
use std::thread;
|
||||
|
||||
use syscall::iopl;
|
||||
|
||||
fn main() {
|
||||
if true {
|
||||
println!("PS/2 driver launching");
|
||||
|
||||
thread::spawn(|| {
|
||||
unsafe {
|
||||
iopl(3).expect("pskbd: failed to get I/O permission");
|
||||
asm!("cli" :::: "intel", "volatile");
|
||||
|
@ -21,8 +24,7 @@ fn main() {
|
|||
|
||||
loop {
|
||||
let mut irqs = [0; 8];
|
||||
file.read(&mut irqs).expect("pskbd: failed to read irq:1");
|
||||
|
||||
if file.read(&mut irqs).expect("pskbd: failed to read irq:1") >= mem::size_of::<usize>() {
|
||||
let data: u8;
|
||||
unsafe {
|
||||
asm!("in al, dx" : "={al}"(data) : "{dx}"(0x60) : : "intel", "volatile");
|
||||
|
@ -31,8 +33,13 @@ fn main() {
|
|||
println!("pskbd: IRQ {}: {:X}", unsafe { *(irqs.as_ptr() as *const usize) }, data);
|
||||
|
||||
file.write(&irqs).expect("pskbd: failed to write irq:1");
|
||||
}
|
||||
} else {
|
||||
thread::yield_now();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
thread::spawn(|| {
|
||||
unsafe {
|
||||
iopl(3).expect("psmsd: failed to get I/O permission");
|
||||
asm!("cli" :::: "intel", "volatile");
|
||||
|
@ -43,17 +50,21 @@ fn main() {
|
|||
println!("psmsd: Reading mouse IRQs");
|
||||
|
||||
loop {
|
||||
let mut count = [0; 8];
|
||||
file.read(&mut count).expect("psmsd: failed to read irq:12");
|
||||
|
||||
let mut irqs = [0; 8];
|
||||
if file.read(&mut irqs).expect("psmsd: failed to read irq:12") >= mem::size_of::<usize>() {
|
||||
let data: u8;
|
||||
unsafe {
|
||||
asm!("in al, dx" : "={al}"(data) : "{dx}"(0x60) : : "intel", "volatile");
|
||||
}
|
||||
|
||||
println!("psmsd: IRQ: {:X}", data);
|
||||
println!("psmsd: IRQ {}: {:X}", unsafe { *(irqs.as_ptr() as *const usize) }, data);
|
||||
|
||||
file.write(&count).expect("psmsd: failed to write irq:12");
|
||||
file.write(&irqs).expect("psmsd: failed to write irq:12");
|
||||
} else {
|
||||
thread::yield_now();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
println!("PS/2 driver running in background");
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ pub unsafe fn switch() {
|
|||
return;
|
||||
}
|
||||
|
||||
//println!("Switch {} to {}", (&*from_ptr).id, (&*to_ptr).id);
|
||||
|
||||
(&mut *from_ptr).running = false;
|
||||
(&mut *to_ptr).running = true;
|
||||
if let Some(ref stack) = (*to_ptr).kstack {
|
||||
|
|
|
@ -22,7 +22,7 @@ impl InitFsScheme {
|
|||
files.insert(b"bin/ion", include_bytes!("../../build/userspace/ion"));
|
||||
files.insert(b"bin/pcid", include_bytes!("../../build/userspace/pcid"));
|
||||
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");
|
||||
files.insert(b"etc/init.rc", b"#initfs:bin/pcid\ninitfs:bin/ps2d\n#initfs:bin/ion");
|
||||
|
||||
InitFsScheme {
|
||||
next_id: 0,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use core::{mem, str};
|
||||
|
||||
use arch::interrupt::irq::{COUNTS, acknowledge};
|
||||
use arch::interrupt::irq::{ACKS, COUNTS, acknowledge};
|
||||
use context;
|
||||
use syscall::{Error, Result};
|
||||
use super::Scheme;
|
||||
|
@ -27,20 +27,15 @@ impl Scheme for IrqScheme {
|
|||
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 prev = { COUNTS.lock()[file] };
|
||||
loop {
|
||||
{
|
||||
let ack = ACKS.lock()[file];
|
||||
let current = COUNTS.lock()[file];
|
||||
if prev != current {
|
||||
if ack != 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 {
|
||||
return Ok(0);
|
||||
}
|
||||
} else {
|
||||
Err(Error::InvalidValue)
|
||||
|
@ -50,9 +45,10 @@ impl Scheme for IrqScheme {
|
|||
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 ack = unsafe { *(buffer.as_ptr() as *const usize) };
|
||||
let current = COUNTS.lock()[file];
|
||||
if prev == current {
|
||||
if ack == current {
|
||||
ACKS.lock()[file] = ack;
|
||||
unsafe { acknowledge(file); }
|
||||
return Ok(mem::size_of::<usize>());
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue