Interrupts aren't working anymore
This commit is contained in:
54
src/main.rs
54
src/main.rs
@@ -21,14 +21,16 @@ use log::info;
|
||||
use crate::{
|
||||
cursor::{clear_cursor, draw_cursor},
|
||||
io::init_log,
|
||||
keymap::map_keycode,
|
||||
pci::{PciDeviceIterator, scan_virtio_devices},
|
||||
riscv::enable_supervisor_interrupt,
|
||||
scheduler::{SCHEDULER, idle},
|
||||
tty::TTY0,
|
||||
user::{proc2, test},
|
||||
vga::Vga,
|
||||
virtio::{
|
||||
Virtqueue,
|
||||
input::{EventCodeValue, VirtioPciDriver, init_plic_pci},
|
||||
input::{EventCodeValue, VirtioInputEvent, VirtioPciDriver, init_plic_pci},
|
||||
},
|
||||
virtual_fs::{FILE_SYSTEM, VirtualFileSystem, init_file_system},
|
||||
};
|
||||
@@ -42,6 +44,7 @@ mod draw;
|
||||
mod fs;
|
||||
mod interrupt;
|
||||
mod io;
|
||||
mod keymap;
|
||||
mod panic_handler;
|
||||
mod pci;
|
||||
mod process;
|
||||
@@ -69,17 +72,50 @@ const _: () = assert!(core::mem::size_of::<usize>() == core::mem::size_of::<u64>
|
||||
#[cfg(not(target_endian = "little"))]
|
||||
compile_error! {"This kernel implementation assume endianness is little-endian. Some memory access like PCI could not work in big-endian."}
|
||||
|
||||
// 1. Allouer de la mémoire statique alignée pour la queue
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct KeyboardState {
|
||||
// ctrl_modifier: bool,
|
||||
maj_modifier: bool,
|
||||
}
|
||||
|
||||
impl KeyboardState {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
// ctrl_modifier: false,
|
||||
maj_modifier: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static mut KBD_STATE: KeyboardState = KeyboardState::new();
|
||||
static mut KBD_QUEUE: Virtqueue = unsafe { core::mem::zeroed() };
|
||||
pub static mut KBD_DRIVER: VirtioPciDriver = unsafe {
|
||||
VirtioPciDriver::new(
|
||||
|event| {
|
||||
let mut kbd_buffer = FILE_SYSTEM.open("/dev/input/keyboard".as_ref()).unwrap();
|
||||
kbd_buffer
|
||||
.write(core::mem::transmute::<
|
||||
&VirtioInputEvent,
|
||||
&[u8; size_of::<VirtioInputEvent>()],
|
||||
>(event))
|
||||
.unwrap();
|
||||
|
||||
if event.is_key() {
|
||||
let event = event.as_key_event();
|
||||
if event.value == EventCodeValue::Pressed {
|
||||
println!("event: {:#?}", event);
|
||||
kbd_buffer.write(&[event.code as u8]).unwrap();
|
||||
#[allow(clippy::single_match)]
|
||||
match map_keycode(event.code, KBD_STATE.maj_modifier) {
|
||||
keymap::KeyType::Ascii(c) => {
|
||||
let mut buf = [0; 4];
|
||||
let to_send = c.encode_utf8(&mut buf);
|
||||
for c in to_send.as_bytes() {
|
||||
println!("key: {}", c);
|
||||
TTY0.buffer.borrow_mut().push(*c);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// println!("event: {:#?}", event);
|
||||
}
|
||||
} else {
|
||||
// println!("key pressed, {:#?}", event);
|
||||
@@ -135,12 +171,12 @@ pub extern "C" fn supervisor_mode_entry() {
|
||||
info!("Hello World !");
|
||||
// unsafe { Vga.draw_string(10, 10, "Hello World !", Color::WHITE, Color::BLACK) };
|
||||
|
||||
SCHEDULER.lock().create_process(Box::new(test), "proc1");
|
||||
SCHEDULER.lock().create_process(Box::new(proc2), "proc2");
|
||||
// SCHEDULER.lock().create_process(Box::new(test), "proc1");
|
||||
// SCHEDULER.lock().create_process(Box::new(proc2), "proc2");
|
||||
|
||||
SCHEDULER
|
||||
.lock()
|
||||
.create_process_from_file("/usr/bin/test_pic");
|
||||
// SCHEDULER
|
||||
// .lock()
|
||||
// .create_process_from_file("/usr/bin/test_pic");
|
||||
|
||||
enable_supervisor_interrupt();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user