Skip to content

Commit 9dc5fbc

Browse files
committed
fix(arch): enable IRQ0 and IRQ1 in UEFI temporarily
1 parent a966107 commit 9dc5fbc

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

kernel/src/interrupts.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use pic8259::ChainedPics;
44
use spin::Mutex;
55
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
66

7-
// PIC primário
7+
/// Primary PIC
88
pub const PIC_1_OFFSET: u8 = 32;
9-
// PIC secundário
9+
/// Secondary PIC
1010
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
1111

1212
pub static PICS: Mutex<ChainedPics> =
@@ -34,6 +34,7 @@ lazy_static! {
3434
let mut idt = InterruptDescriptorTable::new();
3535
idt.breakpoint.set_handler_fn(breakpoint_handler);
3636
idt.page_fault.set_handler_fn(page_fault_handler);
37+
3738
unsafe {
3839
idt.double_fault
3940
.set_handler_fn(double_fault_handler)
@@ -43,6 +44,7 @@ lazy_static! {
4344
.set_handler_fn(generic_protection_fault_handler)
4445
.set_stack_index(gdt::GENERIC_PROTECTION_FAULT_IST_INDEX);
4546
}
47+
4648
idt[InterruptIndex::Timer.as_usize()].set_handler_fn(timer_interrupt_handler);
4749
idt[InterruptIndex::Keyboard.as_usize()].set_handler_fn(keyboard_interrupt_handler);
4850
idt

kernel/src/lib.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,26 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
5353
pub fn init() {
5454
interrupts::init_idt();
5555
gdt::init();
56-
// unsafe { interrupts::PICS.lock().initialize() };
56+
unsafe {
57+
interrupts::PICS.lock().initialize();
58+
59+
// FIXME: Set up APIC.
60+
// This is used for enabling timer and keyboard interrupts.
61+
// 0xFC = PIC1 and 0xFF = PIC2
62+
// Bit 1 means that IRQ is disabled. Bit 0 means that IRQ is enabled.
63+
//
64+
// PIC1 (Master PIC) IRQs:
65+
// * IRQ0: Timer (PIT)
66+
// * IRQ1: PS/2 Keyboard
67+
// * IRQ2: Cascade to PIC2
68+
// PIC2 (Slave) IRQs:
69+
// * IRQ8: Real time clock
70+
// * IRQ9: ACPI
71+
//
72+
// 0xFC = 1111 1100 (Only IRQ0 and IRQ1 is enabled)
73+
// 0xFF = 1111 1111 (All IRQs is disabled)
74+
interrupts::PICS.lock().write_masks(0xFC, 0xFF);
75+
};
5776
x86_64::instructions::interrupts::enable();
5877
}
5978

kernel/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::panic::PanicInfo;
1414
#[cfg(userspace)]
1515
use kernel::userspace;
1616
use kernel::{
17-
framebuffer, println,
17+
framebuffer, hlt_loop, println,
1818
task::{Task, executor::Executor, keyboard},
1919
};
2020

@@ -77,6 +77,8 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
7777
executor.spawn(Task::new(keyboard::print_keypresses()));
7878
executor.run();
7979

80+
hlt_loop();
81+
8082
#[cfg(test)]
8183
test_main();
8284
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
.arg(format!("format=raw,file={uefi_path}"));
1212
cmd.arg("-bios").arg(ovmf_prebuilt::ovmf_pure_efi());
1313
cmd.arg("-monitor").arg("stdio");
14-
// cmd.arg("-d").arg("int");
14+
cmd.arg("-d").arg("int");
1515
cmd.arg("-no-reboot");
1616
cmd.arg("-no-shutdown");
1717
cmd.arg("-s");

0 commit comments

Comments
 (0)