Add poll support
This commit is contained in:
parent
650b92b3ae
commit
2f55bfdfa3
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -28,6 +28,9 @@ name = "bitflags"
|
|||||||
version = "2.6.0"
|
version = "2.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
@ -87,6 +90,7 @@ checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
|
|||||||
name = "file_rpc"
|
name = "file_rpc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"postcard",
|
"postcard",
|
||||||
"serde",
|
"serde",
|
||||||
@ -204,6 +208,7 @@ dependencies = [
|
|||||||
"file_rpc",
|
"file_rpc",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"pc-keyboard",
|
"pc-keyboard",
|
||||||
|
"slab",
|
||||||
"syslog_rpc",
|
"syslog_rpc",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
]
|
]
|
||||||
@ -273,6 +278,15 @@ dependencies = [
|
|||||||
"syn 2.0.77",
|
"syn 2.0.77",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "slab"
|
||||||
|
version = "0.4.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.13.2"
|
version = "1.13.2"
|
||||||
|
@ -10,5 +10,6 @@ devfs_rpc = { version = "0.1.0", path = "../devfs/devfs_rpc" }
|
|||||||
file_rpc = { version = "0.1.0", path = "../file_rpc" }
|
file_rpc = { version = "0.1.0", path = "../file_rpc" }
|
||||||
parking_lot = "0.12.3"
|
parking_lot = "0.12.3"
|
||||||
pc-keyboard = "0.7.0"
|
pc-keyboard = "0.7.0"
|
||||||
|
slab = "0.4.9"
|
||||||
syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" }
|
syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" }
|
||||||
x86_64 = "0.15.1"
|
x86_64 = "0.15.1"
|
||||||
|
@ -191,8 +191,6 @@ impl Ps2Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub fn initialize(&mut self) -> Result<(), Ps2InitFailure> {
|
pub fn initialize(&mut self) -> Result<(), Ps2InitFailure> {
|
||||||
let mut ports = self.ports.lock();
|
let mut ports = self.ports.lock();
|
||||||
|
|
||||||
@ -276,18 +274,21 @@ impl Ps2Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_port1(&self, data: u8) {
|
pub fn write_port1(&self, data: u8) {
|
||||||
self.ports.lock().send_command(Ps2ControllerCommand::WritePort1Input(data));
|
self.ports
|
||||||
|
.lock()
|
||||||
|
.send_command(Ps2ControllerCommand::WritePort1Input(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn write_port2(&self, data: u8) {
|
pub fn write_port2(&self, data: u8) {
|
||||||
self.ports.lock().send_command(Ps2ControllerCommand::WritePort2Input(data));
|
self.ports
|
||||||
|
.lock()
|
||||||
|
.send_command(Ps2ControllerCommand::WritePort2Input(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_interrupt(&self) {
|
pub fn handle_interrupt(&self) {
|
||||||
let mut ports = self.ports.lock();
|
let mut ports = self.ports.lock();
|
||||||
if ports.get_status().contains(Ps2Status::OutputBufFull) {
|
if ports.get_status().contains(Ps2Status::OutputBufFull) {
|
||||||
let data = unsafe {ports.data_port.read()};
|
let data = unsafe { ports.data_port.read() };
|
||||||
self.port1_output_bytes.lock().push_back(data);
|
self.port1_output_bytes.lock().push_back(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
72
src/main.rs
72
src/main.rs
@ -1,10 +1,19 @@
|
|||||||
mod controller;
|
mod controller;
|
||||||
|
|
||||||
use std::{collections::VecDeque, os::mikros::{ipc, syscalls}, sync::OnceLock};
|
use std::{
|
||||||
|
collections::VecDeque,
|
||||||
|
os::mikros::{ipc, syscalls},
|
||||||
|
sync::OnceLock,
|
||||||
|
usize,
|
||||||
|
};
|
||||||
|
|
||||||
use controller::Ps2Controller;
|
use controller::Ps2Controller;
|
||||||
|
use file_rpc::PollEvents;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use pc_keyboard::{layouts::Us104Key, EventDecoder, HandleControl, KeyCode, KeyEvent, ScancodeSet, ScancodeSet2};
|
use pc_keyboard::{
|
||||||
|
layouts::Us104Key, EventDecoder, HandleControl, KeyCode, KeyEvent, ScancodeSet, ScancodeSet2,
|
||||||
|
};
|
||||||
|
use slab::Slab;
|
||||||
|
|
||||||
static CONTROLLER: OnceLock<Ps2Controller> = OnceLock::new();
|
static CONTROLLER: OnceLock<Ps2Controller> = OnceLock::new();
|
||||||
|
|
||||||
@ -18,7 +27,9 @@ impl dev_driver_rpc::Server for DevServ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FileServ;
|
struct FileServ {
|
||||||
|
polls: Mutex<Slab<PollEvents>>,
|
||||||
|
}
|
||||||
|
|
||||||
impl file_rpc::Server for FileServ {
|
impl file_rpc::Server for FileServ {
|
||||||
fn read(
|
fn read(
|
||||||
@ -33,14 +44,14 @@ impl file_rpc::Server for FileServ {
|
|||||||
while remaining_len > 0 {
|
while remaining_len > 0 {
|
||||||
let mut keypress_buf = KEYPRESS_BUF.lock();
|
let mut keypress_buf = KEYPRESS_BUF.lock();
|
||||||
let Some(c) = keypress_buf.pop_front() else {
|
let Some(c) = keypress_buf.pop_front() else {
|
||||||
break
|
break;
|
||||||
};
|
};
|
||||||
let str = c.encode_utf8(&mut encode_buf);
|
let str = c.encode_utf8(&mut encode_buf);
|
||||||
let bytes = str.as_bytes();
|
let bytes = str.as_bytes();
|
||||||
if bytes.len() > remaining_len {
|
if bytes.len() > remaining_len {
|
||||||
keypress_buf.push_front(c);
|
keypress_buf.push_front(c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buf.extend_from_slice(bytes);
|
buf.extend_from_slice(bytes);
|
||||||
remaining_len -= bytes.len();
|
remaining_len -= bytes.len();
|
||||||
}
|
}
|
||||||
@ -56,14 +67,49 @@ impl file_rpc::Server for FileServ {
|
|||||||
fn size(&self, _fd: u64) -> Option<u64> {
|
fn size(&self, _fd: u64) -> Option<u64> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dup(&self, fd: u64) -> Option<u64> {
|
fn dup(&self, fd: u64) -> Option<u64> {
|
||||||
Some(fd)
|
Some(fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn register_poll(&self, _fd: u64, events: PollEvents) -> u64 {
|
||||||
|
self.polls.lock().insert(events) as u64
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poll(&self, poll_id: u64) -> Option<PollEvents> {
|
||||||
|
let poll_id = poll_id as usize;
|
||||||
|
let req_events = *(self.polls.lock().get(poll_id)?);
|
||||||
|
if !req_events.contains(PollEvents::POLLIN) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
loop {
|
||||||
|
if !KEYPRESS_BUF.lock().is_empty() {
|
||||||
|
if !self.polls.lock().contains(poll_id) {
|
||||||
|
return None;
|
||||||
|
} else {
|
||||||
|
self.polls.lock().remove(poll_id);
|
||||||
|
return Some(PollEvents::POLLIN);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ipc::process_messages();
|
||||||
|
process_keyboard_data();
|
||||||
|
if !self.polls.lock().contains(poll_id) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cancel_poll(&self, poll_id: u64) {
|
||||||
|
self.polls.lock().remove(poll_id as usize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SCANDODE_DECODER: Mutex<ScancodeSet2> = Mutex::new(ScancodeSet2::new());
|
static SCANDODE_DECODER: Mutex<ScancodeSet2> = Mutex::new(ScancodeSet2::new());
|
||||||
static EVENT_DECODER: Mutex<EventDecoder<Us104Key>> = Mutex::new(EventDecoder::new(Us104Key, HandleControl::MapLettersToUnicode));
|
static EVENT_DECODER: Mutex<EventDecoder<Us104Key>> = Mutex::new(EventDecoder::new(
|
||||||
|
Us104Key,
|
||||||
|
HandleControl::MapLettersToUnicode,
|
||||||
|
));
|
||||||
|
|
||||||
fn process_keyboard_data() {
|
fn process_keyboard_data() {
|
||||||
let mut scancode_decoder = SCANDODE_DECODER.lock();
|
let mut scancode_decoder = SCANDODE_DECODER.lock();
|
||||||
@ -150,7 +196,9 @@ fn main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
syslog_client.send_text_message("ps2", "Setting keyboard to scan code set 2").unwrap();
|
syslog_client
|
||||||
|
.send_text_message("ps2", "Setting keyboard to scan code set 2")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
controller.write_port1(0xF5);
|
controller.write_port1(0xF5);
|
||||||
loop {
|
loop {
|
||||||
@ -190,10 +238,14 @@ fn main() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog_client.send_text_message("ps2", "Set keyboard to scan code set 2").unwrap();
|
syslog_client
|
||||||
|
.send_text_message("ps2", "Set keyboard to scan code set 2")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
dev_driver_rpc::register_server(Box::new(DevServ));
|
dev_driver_rpc::register_server(Box::new(DevServ));
|
||||||
file_rpc::register_server(Box::new(FileServ));
|
file_rpc::register_server(Box::new(FileServ {
|
||||||
|
polls: Mutex::new(Slab::new()),
|
||||||
|
}));
|
||||||
let devfs_pid;
|
let devfs_pid;
|
||||||
loop {
|
loop {
|
||||||
if let Some(pid) = syscalls::try_get_registered(1) {
|
if let Some(pid) = syscalls::try_get_registered(1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user