Fix PIC, add small delays when initializing
This commit is contained in:
@ -186,7 +186,6 @@ void intr_init(void) {
|
||||
idt_init();
|
||||
intr_pic_init();
|
||||
intr_pit_init();
|
||||
intr_disable();
|
||||
}
|
||||
|
||||
void intr_dumpframe(IntrStackFrame *frame) {
|
||||
@ -246,12 +245,18 @@ void intr_handleintr(IntrStackFrame *frame) {
|
||||
cpu_hang();
|
||||
}
|
||||
} else if (frame->trapnum >= 32 && frame->trapnum <= 47) {
|
||||
intr_pic_eoi();
|
||||
IntrHandler *ih, *ihtmp;
|
||||
LL_FOREACH_SAFE(INTR_HANDLERS, ih, ihtmp) {
|
||||
if ((uint64_t)ih->irq == frame->trapnum) {
|
||||
ih->fn(frame);
|
||||
if (frame->trapnum == INTR_IRQBASE+0) {
|
||||
PIT_TICKS++;
|
||||
intr_pic_eoi(frame->trapnum >= 40);
|
||||
proc_sched((void *)frame);
|
||||
} else {
|
||||
IntrHandler *ih, *ihtmp;
|
||||
LL_FOREACH_SAFE(INTR_HANDLERS, ih, ihtmp) {
|
||||
if ((uint64_t)ih->irq == frame->trapnum) {
|
||||
ih->fn(frame);
|
||||
}
|
||||
}
|
||||
intr_pic_eoi(frame->trapnum >= 40);
|
||||
}
|
||||
} else if (frame->trapnum == 0x80) {
|
||||
intr_syscalldispatch(frame);
|
||||
|
||||
@ -25,22 +25,44 @@
|
||||
|
||||
void intr_pic_init(void) {
|
||||
io_out8(PIC1_CMD, ICW1_INIT | ICW1_ICW4);
|
||||
io_wait();
|
||||
io_out8(PIC2_CMD, ICW1_INIT | ICW1_ICW4);
|
||||
io_wait();
|
||||
|
||||
io_out8(PIC1_DATA, INTR_IRQBASE);
|
||||
io_wait();
|
||||
io_out8(PIC2_DATA, INTR_IRQBASE+8);
|
||||
io_wait();
|
||||
|
||||
io_out8(PIC1_DATA, 2);
|
||||
io_wait();
|
||||
io_out8(PIC2_DATA, 2);
|
||||
io_wait();
|
||||
|
||||
io_out8(PIC1_DATA, ICW4_8086);
|
||||
io_wait();
|
||||
io_out8(PIC2_DATA, ICW4_8086);
|
||||
io_wait();
|
||||
|
||||
io_out8(PIC1_DATA, 0);
|
||||
io_out8(PIC2_DATA, 0);
|
||||
intr_pic_mask();
|
||||
}
|
||||
|
||||
void intr_pic_eoi(void) {
|
||||
io_out8(PIC2_CMD, PIC_EOI);
|
||||
void intr_pic_mask(void) {
|
||||
io_out8(PIC1_DATA, 0xFF);
|
||||
io_wait();
|
||||
io_out8(PIC2_DATA, 0xFF);
|
||||
io_wait();
|
||||
}
|
||||
|
||||
void intr_pic_unmask(void) {
|
||||
io_out8(PIC1_DATA, 0);
|
||||
io_wait();
|
||||
io_out8(PIC2_DATA, 0);
|
||||
io_wait();
|
||||
}
|
||||
|
||||
void intr_pic_eoi(bool pic2) {
|
||||
if (pic2)
|
||||
io_out8(PIC2_CMD, PIC_EOI);
|
||||
io_out8(PIC1_CMD, PIC_EOI);
|
||||
}
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
#ifndef INTR_PIC_H_
|
||||
#define INTR_PIC_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
void intr_pic_init(void);
|
||||
void intr_pic_eoi(void);
|
||||
void intr_pic_eoi(bool pic2);
|
||||
void intr_pic_mask(void);
|
||||
void intr_pic_unmask(void);
|
||||
|
||||
#endif // INTR_PIC_H_
|
||||
|
||||
@ -31,13 +31,7 @@ void intr_pit_wait(uint32_t ms) {
|
||||
while (PIT_TICKS - now < ms);
|
||||
}
|
||||
|
||||
void intr_pit_intr(IntrStackFrame *frame) {
|
||||
PIT_TICKS++;
|
||||
}
|
||||
|
||||
void intr_pit_init(void) {
|
||||
intr_attchhandler(&intr_pit_intr, INTR_IRQBASE+0);
|
||||
|
||||
uint32_t hz = 1000;
|
||||
uint32_t div = PIT_FREQ / hz;
|
||||
io_out8(PIT_CMD, PIT_CMD_BINARY | PIT_CMD_MODE3 | PIT_CMD_RW_BOTH | PIT_CMD_COUNTER0);
|
||||
|
||||
Reference in New Issue
Block a user