Skip to content

Commit de84ef2

Browse files
committed
f
1 parent 2ae7812 commit de84ef2

3 files changed

Lines changed: 18 additions & 21 deletions

File tree

src/arch/x86_64/kernel/interrupts.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use x86_64::structures::idt::InterruptDescriptorTable;
1313
pub use x86_64::structures::idt::InterruptStackFrame as ExceptionStackFrame;
1414

1515
use crate::arch::x86_64::kernel::core_local::{core_scheduler, increment_irq_counter};
16+
use crate::arch::x86_64::kernel::pic::PIC1_OFFSET;
1617
use crate::arch::x86_64::kernel::{apic, processor};
1718
use crate::arch::x86_64::mm::paging::{BasePageSize, PageSize, page_fault_handler};
1819
use crate::arch::x86_64::swapgs;
@@ -21,7 +22,6 @@ use crate::drivers::InterruptHandlerQueue;
2122
use crate::drivers::mmio::get_interrupt_handlers;
2223
#[cfg(feature = "pci")]
2324
use crate::drivers::pci::get_interrupt_handlers;
24-
use crate::kernel::pic::PIC1_INTERRUPT_OFFSET;
2525
use crate::scheduler::{self, CoreId};
2626

2727
static IRQ_HANDLERS: OnceCell<HashMap<u8, InterruptHandlerQueue, RandomState>> = OnceCell::new();
@@ -30,7 +30,6 @@ static IRQ_NAMES: InterruptTicketMutex<HashMap<u8, &'static str, RandomState>> =
3030

3131
pub(crate) const IST_ENTRIES: usize = 4;
3232
pub(crate) const IST_SIZE: usize = 8 * BasePageSize::SIZE as usize;
33-
pub(crate) const IDT_EXTERNAL_INTERRUPT_OFFSET: u8 = 32; // Interrupts 0..32 are fixed or reserved, external interrupts start at 32
3433

3534
pub(crate) static IDT: InterruptSpinMutex<InterruptDescriptorTable> =
3635
InterruptSpinMutex::new(InterruptDescriptorTable::new());
@@ -93,11 +92,11 @@ pub(crate) fn enable_and_wait() {
9392
pub(crate) fn install() {
9493
let mut idt = IDT.lock();
9594

96-
set_general_handler!(&mut *idt, abort, 0..IDT_EXTERNAL_INTERRUPT_OFFSET);
97-
set_general_handler!(&mut *idt, handle_interrupt, IDT_EXTERNAL_INTERRUPT_OFFSET..);
95+
set_general_handler!(&mut *idt, abort, 0..32);
96+
set_general_handler!(&mut *idt, handle_interrupt, 32..);
9897

9998
unsafe {
100-
for i in IDT_EXTERNAL_INTERRUPT_OFFSET..=255 {
99+
for i in 32..=255 {
101100
let addr = idt[i].handler_addr();
102101
idt[i].set_handler_addr(addr).set_stack_index(0);
103102
}
@@ -177,7 +176,7 @@ fn handle_interrupt(stack_frame: ExceptionStackFrame, index: u8, _error_code: Op
177176
use crate::scheduler::PerCoreSchedulerExt;
178177

179178
if let Some(handlers) = IRQ_HANDLERS.get()
180-
&& let Some(map) = handlers.get(&(index - IDT_EXTERNAL_INTERRUPT_OFFSET))
179+
&& let Some(map) = handlers.get(&(index - PIC1_OFFSET))
181180
{
182181
for handler in map.iter() {
183182
handler();
@@ -338,9 +337,7 @@ extern "x86-interrupt" fn virtualization_exception(stack_frame: ExceptionStackFr
338337

339338
pub(crate) fn add_irq_name(irq_number: u8, name: &'static str) {
340339
debug!("Register name \"{name}\" for interrupt {irq_number}");
341-
IRQ_NAMES
342-
.lock()
343-
.insert(PIC1_INTERRUPT_OFFSET + irq_number, name);
340+
IRQ_NAMES.lock().insert(PIC1_OFFSET + irq_number, name);
344341
}
345342

346343
fn get_irq_name(irq_number: u8) -> Option<&'static str> {

src/arch/x86_64/kernel/pic.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use x86_64::instructions::port::Port;
22

33
use super::interrupts::IDT;
4-
use crate::arch::x86_64::kernel::interrupts::{ExceptionStackFrame, IDT_EXTERNAL_INTERRUPT_OFFSET};
4+
use crate::arch::x86_64::kernel::interrupts::ExceptionStackFrame;
55
use crate::arch::x86_64::swapgs;
66
use crate::scheduler;
77

@@ -10,8 +10,8 @@ const PIC1_DATA: Port<u8> = Port::new(0x21);
1010
const PIC2_COMMAND: Port<u8> = Port::new(0xa0);
1111
const PIC2_DATA: Port<u8> = Port::new(0xa1);
1212

13-
pub const PIC1_INTERRUPT_OFFSET: u8 = IDT_EXTERNAL_INTERRUPT_OFFSET;
14-
const PIC2_INTERRUPT_OFFSET: u8 = PIC1_INTERRUPT_OFFSET + 8;
13+
pub const PIC1_OFFSET: u8 = 32;
14+
const PIC2_OFFSET: u8 = PIC1_OFFSET + 8;
1515
const SPURIOUS_IRQ_NUMBER: u8 = 7;
1616

1717
/// End-Of-Interrupt Command for an Intel 8259 Programmable Interrupt Controller (PIC).
@@ -42,10 +42,10 @@ pub fn init() {
4242
// This is especially true for real hardware. So provide a handler for them.
4343
unsafe {
4444
let mut idt = IDT.lock();
45-
idt[PIC1_INTERRUPT_OFFSET + SPURIOUS_IRQ_NUMBER]
45+
idt[PIC1_OFFSET + SPURIOUS_IRQ_NUMBER]
4646
.set_handler_fn(spurious_interrupt_on_master)
4747
.set_stack_index(0);
48-
idt[PIC2_INTERRUPT_OFFSET + SPURIOUS_IRQ_NUMBER]
48+
idt[PIC2_OFFSET + SPURIOUS_IRQ_NUMBER]
4949
.set_handler_fn(spurious_interrupt_on_slave)
5050
.set_stack_index(0);
5151

@@ -65,8 +65,8 @@ pub fn init() {
6565
pic2_command.write(0x11);
6666

6767
// Map PIC1 to interrupt numbers >= 32 and PIC2 to interrupt numbers >= 40.
68-
pic1_data.write(PIC1_INTERRUPT_OFFSET);
69-
pic2_data.write(PIC2_INTERRUPT_OFFSET);
68+
pic1_data.write(PIC1_OFFSET);
69+
pic2_data.write(PIC2_OFFSET);
7070

7171
// Configure PIC1 as master and PIC2 as slave.
7272
pic1_data.write(0x04);
@@ -102,15 +102,15 @@ extern "x86-interrupt" fn spurious_interrupt_on_slave(stack_frame: ExceptionStac
102102
}
103103

104104
fn edit_mask(int_no: u8, insert: bool) {
105-
let mut port = if int_no >= PIC2_INTERRUPT_OFFSET {
105+
let mut port = if int_no >= PIC2_OFFSET {
106106
PIC2_DATA
107107
} else {
108108
PIC1_DATA
109109
};
110-
let offset = if int_no >= PIC2_INTERRUPT_OFFSET {
111-
PIC2_INTERRUPT_OFFSET
110+
let offset = if int_no >= PIC2_OFFSET {
111+
PIC2_OFFSET
112112
} else {
113-
PIC1_INTERRUPT_OFFSET
113+
PIC1_OFFSET
114114
};
115115

116116
unsafe {

src/arch/x86_64/kernel/pit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use x86_64::instructions::port::Port;
55
use crate::arch::x86_64::kernel::pic;
66

77
const PIT_CLOCK: u64 = 1_193_182;
8-
pub const PIT_INTERRUPT_NUMBER: u8 = pic::PIC1_INTERRUPT_OFFSET;
8+
pub const PIT_INTERRUPT_NUMBER: u8 = pic::PIC1_OFFSET;
99

1010
const PIT_CHANNEL0_DATA: Port<u8> = Port::new(0x40);
1111
const PIT_CHANNEL1_DATA: Port<u8> = Port::new(0x41);

0 commit comments

Comments
 (0)