Commit a60773c1 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

PS/2 driver convert to char

parent aeabb66d
static ENGLISH: [[char; 3]; 58] = [
['\0', '\0', '\0'],
['\x1B', '\x1B', '\x1B'],
['1', '!', '1'],
['2', '@', '2'],
['3', '#', '3'],
['4', '$', '4'],
['5', '%', '5'],
['6', '^', '6'],
['7', '&', '7'],
['8', '*', '8'],
['9', '(', '9'],
['0', ')', '0'],
['-', '_', '-'],
['=', '+', '='],
['\0', '\0', '\0'],
['\t', '\t', '\t'],
['q', 'Q', 'q'],
['w', 'W', 'w'],
['e', 'E', 'e'],
['r', 'R', 'r'],
['t', 'T', 't'],
['y', 'Y', 'y'],
['u', 'U', 'u'],
['i', 'I', 'i'],
['o', 'O', 'o'],
['p', 'P', 'p'],
['[', '{', '['],
[']', '}', ']'],
['\n', '\n', '\n'],
['\0', '\0', '\0'],
['a', 'A', 'a'],
['s', 'S', 's'],
['d', 'D', 'd'],
['f', 'F', 'f'],
['g', 'G', 'g'],
['h', 'H', 'h'],
['j', 'J', 'j'],
['k', 'K', 'k'],
['l', 'L', 'l'],
[';', ':', ';'],
['\'', '"', '\''],
['`', '~', '`'],
['\0', '\0', '\0'],
['\\', '|', '\\'],
['z', 'Z', 'z'],
['x', 'X', 'x'],
['c', 'C', 'c'],
['v', 'V', 'v'],
['b', 'B', 'b'],
['n', 'N', 'n'],
['m', 'M', 'm'],
[',', '<', ','],
['.', '>', '.'],
['/', '?', '/'],
['\0', '\0', '\0'],
['\0', '\0', '\0'],
['\0', '\0', '\0'],
[' ', ' ', ' ']
];
pub fn get_char(scancode: u8) -> char {
if let Some(c) = ENGLISH.get(scancode as usize) {
c[0]
} else {
'\0'
}
}
......@@ -9,62 +9,69 @@ use std::thread;
use syscall::iopl;
fn main() {
println!("PS/2 driver launching");
mod keymap;
thread::spawn(|| {
unsafe {
iopl(3).expect("pskbd: failed to get I/O permission");
asm!("cli" :::: "intel", "volatile");
}
fn keyboard() {
let mut file = File::open("irq:1").expect("pskbd: failed to open irq:1");
let mut file = File::open("irq:1").expect("pskbd: failed to open irq:1");
loop {
let mut irqs = [0; 8];
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");
}
println!("pskbd: Reading keyboard IRQs");
let (scancode, pressed) = if data >= 0x80 {
(data - 0x80, false)
} else {
(data, true)
};
println!("pskbd: IRQ {}: {:X}: {:X}: {}: {}", unsafe { *(irqs.as_ptr() as *const usize) }, data, scancode, keymap::get_char(scancode), pressed);
loop {
let mut irqs = [0; 8];
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");
}
file.write(&irqs).expect("pskbd: failed to write irq:1");
} else {
thread::yield_now();
}
}
}
println!("pskbd: IRQ {}: {:X}", unsafe { *(irqs.as_ptr() as *const usize) }, data);
fn mouse() {
let mut file = File::open("irq:12").expect("psmsd: failed to open irq:12");
file.write(&irqs).expect("pskbd: failed to write irq:1");
} else {
thread::yield_now();
loop {
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}", unsafe { *(irqs.as_ptr() as *const usize) }, data);
file.write(&irqs).expect("psmsd: failed to write irq:12");
} else {
thread::yield_now();
}
});
}
}
fn main() {
thread::spawn(|| {
unsafe {
iopl(3).expect("psmsd: failed to get I/O permission");
iopl(3).expect("pskbd: 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 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}", unsafe { *(irqs.as_ptr() as *const usize) }, data);
keyboard();
});
file.write(&irqs).expect("psmsd: failed to write irq:12");
} else {
thread::yield_now();
}
thread::spawn(|| {
unsafe {
iopl(3).expect("psmsd: failed to get I/O permission");
asm!("cli" :::: "intel", "volatile");
}
});
println!("PS/2 driver running in background");
mouse();
});
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment