Skip to content

Commit 1c958e3

Browse files
committed
Add new keyboard handling subroutine, minor cleanup
1 parent 02bfd36 commit 1c958e3

4 files changed

Lines changed: 46 additions & 5 deletions

File tree

src/abi/idt.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,14 @@ extern "x86-interrupt" fn keyboard_handler(_stack: InterruptStackFrame) {
125125
let scancode = crate::input::port::read_u8(0x60);
126126

127127
unsafe {
128-
#[expect(static_mut_refs)] // this is bad but i cant figure out how to fix
128+
crate::input::keyboard::push_scancode(scancode);
129+
130+
/*#[expect(static_mut_refs)] // this is bad but i cant figure out how to fix
129131
for s in crate::input::irq::RECEPTORS.iter() {
130132
if s.pid != 0 {
131133
s.push_irq(scancode);
132134
}
133-
}
135+
}*/
134136
}
135137

136138
// Acknowledge the PIC

src/abi/timer_interrupt.asm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ global timer_interrupt_stub
55
extern schedule
66

77
timer_interrupt_stub:
8+
cli
89
push r15
910
push r14
1011
push r13
@@ -41,6 +42,7 @@ timer_interrupt_stub:
4142
pop r13
4243
pop r14
4344
pop r15
45+
sti
4446

4547
iretq
4648

src/input/keyboard.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ pub extern "C" fn keyboard_loop() -> ! {
8181
render_prompt();
8282

8383
loop {
84-
let key = keyboard_read_scancode();
84+
//let key = keyboard_read_scancode();
85+
let key = load_scancode();
8586

8687
if key & 0x80 != 0 {
8788
// Key released
@@ -559,3 +560,40 @@ pub fn split_cmd(input: &[u8]) -> (&[u8], &[u8]) {
559560
(trimmed, &[])
560561
}
561562
}
563+
564+
//
565+
//
566+
//
567+
568+
pub unsafe fn push_scancode(scancode: u8) {
569+
SCANCODE_BUF[SCANCODE_BUF_HEAD] = scancode;
570+
SCANCODE_BUF_HEAD += 1;
571+
SCANCODE_BUF_HEAD %= 2048;
572+
573+
SCANCODE_BUF_LOCKED = false;
574+
//crate::task::process::resume(3);
575+
}
576+
577+
static mut SCANCODE_BUF_HEAD: usize = 0;
578+
static mut SCANCODE_BUF: [u8; 2048] = [0; 2048];
579+
pub static mut SCANCODE_BUF_LOCKED: bool = true;
580+
581+
pub fn load_scancode() -> u8 {
582+
loop {
583+
unsafe {
584+
if SCANCODE_BUF_LOCKED {
585+
//crate::task::process::idle();
586+
core::arch::asm!("pause");
587+
continue;
588+
}
589+
590+
/*if port::read(0x64) & 1 == 0 {
591+
SCANCODE_BUF_LOCKED = true;
592+
continue;
593+
}*/
594+
595+
SCANCODE_BUF_LOCKED = true;
596+
return SCANCODE_BUF[(SCANCODE_BUF_HEAD - 1) % 2048];
597+
}
598+
}
599+
}

src/task/process.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ pub unsafe fn crash() {
123123
PROCESS_LIST[CURRENT_PID].as_mut().unwrap().status = Status::Crashed;
124124
}
125125

126-
/*core::arch::asm!("int 0x20");
127-
loop {
126+
/*loop {
128127
core::arch::asm!("hlt");
129128
}*/
130129
}

0 commit comments

Comments
 (0)