fix some ioapic bugs
@@ -22,6 +22,8 @@ pub fn init() {
init_irq_table();
irq_add_handle(Timer + IRQ0, Box::new(timer));
irq_add_handle(COM1 + IRQ0, Box::new(com1));
+ // irq_add_handle(Keyboard + IRQ0, Box::new(keyboard));
+ // irq_enable_raw(Keyboard, Keyboard + IRQ0);
irq_enable_raw(COM1, COM1 + IRQ0);
}
@@ -88,10 +90,10 @@ pub fn irq_handle(irq: u8) {
#[export_name = "hal_ioapic_set_handle"]
pub fn set_handle(global_irq: u32, handle: InterruptHandle) -> Option<u8> {
info!("set_handle irq={:#x?}", global_irq);
- if global_irq == 1 {
- irq_add_handle(global_irq as u8 + IRQ0, handle);
- return Some(global_irq as u8 + IRQ0);
- }
+ // if global_irq == 1 {
+ // irq_add_handle(global_irq as u8 + IRQ0, handle);
+ // return Some(global_irq as u8 + IRQ0);
+ // }
let ioapic_info = if let Some(x) = get_ioapic(global_irq) {
x
} else {
@@ -101,7 +103,7 @@ pub fn set_handle(global_irq: u32, handle: InterruptHandle) -> Option<u8> {
let offset = (global_irq - ioapic_info.global_system_interrupt_base) as u8;
let irq = ioapic.irq_vector(offset);
irq_add_handle(irq, handle).map(|x| {
- ioapic.set_irq_vector(offset, irq);
+ ioapic.set_irq_vector(offset, x);
x
})
}
@@ -132,11 +134,13 @@ pub fn irq_add_handle(irq: u8, handle: InterruptHandle) -> Option<u8> {
let mut table = IRQ_TABLE.lock();
// allocate a valid irq number
if irq == 0 {
- for (id, entry) in table.iter_mut().enumerate() {
- if let None = entry {
- *entry = Some(handle);
+ let mut id = 0x20;
+ while id < table.len() {
+ if let None = table[id] {
+ table[id] = Some(handle);
return Some(id as u8);
}
+ id += 1;
}
return None;
}
@@ -203,10 +207,10 @@ pub fn overwrite_handler(msi_id: u32, handle: Box<dyn Fn() + Send + Sync>) -> bo
#[export_name = "hal_irq_enable"]
pub fn irq_enable(irq: u32) {
info!("irq_enable irq={:#x?}", irq);
- if irq == 1 {
- irq_enable_raw(irq as u8, irq as u8 + IRQ0);
- return;
- }
+ // if irq == 1 {
+ // irq_enable_raw(irq as u8, irq as u8 + IRQ0);
+ // return;
+ // }
if let Some(x) = get_ioapic(irq) {
let mut ioapic = ioapic_controller(&x);
ioapic.enable((irq - x.global_system_interrupt_base) as u8, 0);
