Skip to content

Commit

Permalink
fix hpet
Browse files Browse the repository at this point in the history
  • Loading branch information
yzcode committed Apr 23, 2018
1 parent b52203a commit 3f34e15
Showing 1 changed file with 70 additions and 68 deletions.
138 changes: 70 additions & 68 deletions src/platform/i386/idt.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,74 +95,76 @@ remap_irq_table(void)
void
idt_init(const cpuid_t cpu_id)
{
idt_ptr.limit = (sizeof(struct idt_entry) * NUM_IDT_ENTRIES) - 1;
idt_ptr.base = (u32_t)&(idt_entries);
memset(&(idt_entries), 0, sizeof(struct idt_entry) * NUM_IDT_ENTRIES);

outb(0x20, 0x11);
outb(0xA0, 0x11);
outb(0x21, 0x20);
outb(0xA1, 0x28);
outb(0x21, 0x04);
outb(0xA1, 0x02);
outb(0x21, 0x01);
outb(0xA1, 0x01);
outb(0x21, 0x0);
outb(0xA1, 0x0);

idt_set_gate(IRQ_DIV_BY_ZERO_ERR_FAULT, (u32_t)div_by_zero_err_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_DEBUG_TRAP, (u32_t)debug_trap_irq, 0x08, 0x8E);
idt_set_gate(IRQ_BREAKPOINT_TRAP, (u32_t)breakpoint_trap_irq, 0x08, 0x8E);
idt_set_gate(IRQ_OVERFLOW_TRAP, (u32_t)overflow_trap_irq, 0x08, 0x8E);
idt_set_gate(IRQ_BOUND_RANGE_EXCEED_FAULT, (u32_t)bound_range_exceed_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_INVALID_OPCODE_FAULT, (u32_t)invalid_opcode_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_DEVICE_NOT_AVAIL_FAULT, (u32_t)device_not_avail_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_DOUBLE_FAULT_ABORT, (u32_t)double_fault_abort_irq, 0x08, 0x8E);
idt_set_gate(IRQ_INVALID_TSS_FAULT, (u32_t)invalid_tss_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_SEG_NOT_PRESENT_FAULT, (u32_t)seg_not_present_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_STACK_SEG_FAULT, (u32_t)stack_seg_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_GEN_PROTECT_FAULT, (u32_t)gen_protect_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_PAGE_FAULT, (u32_t)page_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_X87_FLOAT_PT_EXCEPT_FAULT, (u32_t)x87_float_pt_except_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_ALIGN_CHECK_FAULT, (u32_t)align_check_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_MACHINE_CHECK_ABORT, (u32_t)machine_check_abort_irq, 0x08, 0x8E);
idt_set_gate(IRQ_SMID_FLOAT_PT_EXCEPT_FAULT, (u32_t)smid_float_pt_except_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_VIRTUALIZATION_EXCEPT_FAULT, (u32_t)virtualization_except_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_SECURITY_EXCEPT_FAULT, (u32_t)security_except_fault_irq, 0x08, 0x8E);

idt_set_gate(HW_PERIODIC, (u32_t)periodic_irq, 0x08, 0x8E);
idt_set_gate(HW_KEYBOARD, (u32_t)keyboard_irq, 0x08, 0x8E);
idt_set_gate(HW_ID3, (u32_t)handler_hw_34, 0x08, 0x8E);
idt_set_gate(HW_ID4, (u32_t)handler_hw_35, 0x08, 0x8E);
idt_set_gate(HW_SERIAL, (u32_t)serial_irq, 0x08, 0x8E);
idt_set_gate(HW_ID6, (u32_t)handler_hw_37, 0x08, 0x8E);
idt_set_gate(HW_ID7, (u32_t)handler_hw_38, 0x08, 0x8E);
idt_set_gate(HW_ID8, (u32_t)handler_hw_39, 0x08, 0x8E);
idt_set_gate(HW_ONESHOT, (u32_t)oneshot_irq, 0x08, 0x8E);
idt_set_gate(HW_ID10, (u32_t)handler_hw_41, 0x08, 0x8E);
idt_set_gate(HW_ID11, (u32_t)handler_hw_42, 0x08, 0x8E);
idt_set_gate(HW_ID12, (u32_t)handler_hw_43, 0x08, 0x8E);
idt_set_gate(HW_ID13, (u32_t)handler_hw_44, 0x08, 0x8E);
idt_set_gate(HW_ID14, (u32_t)handler_hw_45, 0x08, 0x8E);
idt_set_gate(HW_ID15, (u32_t)handler_hw_46, 0x08, 0x8E);
idt_set_gate(HW_ID16, (u32_t)handler_hw_47, 0x08, 0x8E);
idt_set_gate(HW_ID17, (u32_t)handler_hw_48, 0x08, 0x8E);
idt_set_gate(HW_ID18, (u32_t)handler_hw_49, 0x08, 0x8E);
idt_set_gate(HW_ID19, (u32_t)handler_hw_50, 0x08, 0x8E);
idt_set_gate(HW_ID20, (u32_t)handler_hw_51, 0x08, 0x8E);
idt_set_gate(HW_ID21, (u32_t)handler_hw_52, 0x08, 0x8E);
idt_set_gate(HW_ID22, (u32_t)handler_hw_53, 0x08, 0x8E);
idt_set_gate(HW_ID23, (u32_t)handler_hw_54, 0x08, 0x8E);
idt_set_gate(HW_ID24, (u32_t)handler_hw_55, 0x08, 0x8E);
idt_set_gate(HW_ID25, (u32_t)handler_hw_56, 0x08, 0x8E);
idt_set_gate(HW_ID26, (u32_t)handler_hw_57, 0x08, 0x8E);
idt_set_gate(HW_ID27, (u32_t)handler_hw_58, 0x08, 0x8E);
idt_set_gate(HW_ID28, (u32_t)handler_hw_59, 0x08, 0x8E);
idt_set_gate(HW_ID29, (u32_t)handler_hw_60, 0x08, 0x8E);
idt_set_gate(HW_ID30, (u32_t)handler_hw_61, 0x08, 0x8E);
idt_set_gate(HW_ID31, (u32_t)handler_hw_62, 0x08, 0x8E);
idt_set_gate(HW_LAPIC_SPURIOUS, (u32_t)lapic_spurious_irq, 0x08, 0x8E);
idt_set_gate(HW_LAPIC_TIMER, (u32_t)lapic_timer_irq, 0x08, 0x8E);
if (cpu_id == INIT_CORE) {
idt_ptr.limit = (sizeof(struct idt_entry) * NUM_IDT_ENTRIES) - 1;
idt_ptr.base = (u32_t)&(idt_entries);
memset(&(idt_entries), 0, sizeof(struct idt_entry) * NUM_IDT_ENTRIES);

outb(0x20, 0x11);
outb(0xA0, 0x11);
outb(0x21, 0x20);
outb(0xA1, 0x28);
outb(0x21, 0x04);
outb(0xA1, 0x02);
outb(0x21, 0x01);
outb(0xA1, 0x01);
outb(0x21, 0x0);
outb(0xA1, 0x0);

idt_set_gate(IRQ_DIV_BY_ZERO_ERR_FAULT, (u32_t)div_by_zero_err_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_DEBUG_TRAP, (u32_t)debug_trap_irq, 0x08, 0x8E);
idt_set_gate(IRQ_BREAKPOINT_TRAP, (u32_t)breakpoint_trap_irq, 0x08, 0x8E);
idt_set_gate(IRQ_OVERFLOW_TRAP, (u32_t)overflow_trap_irq, 0x08, 0x8E);
idt_set_gate(IRQ_BOUND_RANGE_EXCEED_FAULT, (u32_t)bound_range_exceed_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_INVALID_OPCODE_FAULT, (u32_t)invalid_opcode_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_DEVICE_NOT_AVAIL_FAULT, (u32_t)device_not_avail_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_DOUBLE_FAULT_ABORT, (u32_t)double_fault_abort_irq, 0x08, 0x8E);
idt_set_gate(IRQ_INVALID_TSS_FAULT, (u32_t)invalid_tss_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_SEG_NOT_PRESENT_FAULT, (u32_t)seg_not_present_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_STACK_SEG_FAULT, (u32_t)stack_seg_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_GEN_PROTECT_FAULT, (u32_t)gen_protect_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_PAGE_FAULT, (u32_t)page_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_X87_FLOAT_PT_EXCEPT_FAULT, (u32_t)x87_float_pt_except_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_ALIGN_CHECK_FAULT, (u32_t)align_check_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_MACHINE_CHECK_ABORT, (u32_t)machine_check_abort_irq, 0x08, 0x8E);
idt_set_gate(IRQ_SMID_FLOAT_PT_EXCEPT_FAULT, (u32_t)smid_float_pt_except_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_VIRTUALIZATION_EXCEPT_FAULT, (u32_t)virtualization_except_fault_irq, 0x08, 0x8E);
idt_set_gate(IRQ_SECURITY_EXCEPT_FAULT, (u32_t)security_except_fault_irq, 0x08, 0x8E);

idt_set_gate(HW_PERIODIC, (u32_t)periodic_irq, 0x08, 0x8E);
idt_set_gate(HW_KEYBOARD, (u32_t)keyboard_irq, 0x08, 0x8E);
idt_set_gate(HW_ID3, (u32_t)handler_hw_34, 0x08, 0x8E);
idt_set_gate(HW_ID4, (u32_t)handler_hw_35, 0x08, 0x8E);
idt_set_gate(HW_SERIAL, (u32_t)serial_irq, 0x08, 0x8E);
idt_set_gate(HW_ID6, (u32_t)handler_hw_37, 0x08, 0x8E);
idt_set_gate(HW_ID7, (u32_t)handler_hw_38, 0x08, 0x8E);
idt_set_gate(HW_ID8, (u32_t)handler_hw_39, 0x08, 0x8E);
idt_set_gate(HW_ONESHOT, (u32_t)oneshot_irq, 0x08, 0x8E);
idt_set_gate(HW_ID10, (u32_t)handler_hw_41, 0x08, 0x8E);
idt_set_gate(HW_ID11, (u32_t)handler_hw_42, 0x08, 0x8E);
idt_set_gate(HW_ID12, (u32_t)handler_hw_43, 0x08, 0x8E);
idt_set_gate(HW_ID13, (u32_t)handler_hw_44, 0x08, 0x8E);
idt_set_gate(HW_ID14, (u32_t)handler_hw_45, 0x08, 0x8E);
idt_set_gate(HW_ID15, (u32_t)handler_hw_46, 0x08, 0x8E);
idt_set_gate(HW_ID16, (u32_t)handler_hw_47, 0x08, 0x8E);
idt_set_gate(HW_ID17, (u32_t)handler_hw_48, 0x08, 0x8E);
idt_set_gate(HW_ID18, (u32_t)handler_hw_49, 0x08, 0x8E);
idt_set_gate(HW_ID19, (u32_t)handler_hw_50, 0x08, 0x8E);
idt_set_gate(HW_ID20, (u32_t)handler_hw_51, 0x08, 0x8E);
idt_set_gate(HW_ID21, (u32_t)handler_hw_52, 0x08, 0x8E);
idt_set_gate(HW_ID22, (u32_t)handler_hw_53, 0x08, 0x8E);
idt_set_gate(HW_ID23, (u32_t)handler_hw_54, 0x08, 0x8E);
idt_set_gate(HW_ID24, (u32_t)handler_hw_55, 0x08, 0x8E);
idt_set_gate(HW_ID25, (u32_t)handler_hw_56, 0x08, 0x8E);
idt_set_gate(HW_ID26, (u32_t)handler_hw_57, 0x08, 0x8E);
idt_set_gate(HW_ID27, (u32_t)handler_hw_58, 0x08, 0x8E);
idt_set_gate(HW_ID28, (u32_t)handler_hw_59, 0x08, 0x8E);
idt_set_gate(HW_ID29, (u32_t)handler_hw_60, 0x08, 0x8E);
idt_set_gate(HW_ID30, (u32_t)handler_hw_61, 0x08, 0x8E);
idt_set_gate(HW_ID31, (u32_t)handler_hw_62, 0x08, 0x8E);
idt_set_gate(HW_LAPIC_SPURIOUS, (u32_t)lapic_spurious_irq, 0x08, 0x8E);
idt_set_gate(HW_LAPIC_TIMER, (u32_t)lapic_timer_irq, 0x08, 0x8E);
}

This comment has been minimized.

Copy link
@phanikishoreg

phanikishoreg Apr 23, 2018

Member

There is a lot going on in the "if" condition..

You should probably do this:

         if (cpu != INIT_CORE) goto gate_set;

         //set idt gate info

gate_set:
         //remaining..

This comment has been minimized.

Copy link
@phanikishoreg

phanikishoreg Apr 23, 2018

Member

And wow, this fixes HPET stuff? I have no idea how your debugging led to finding this as a problem, good job..


struct {
unsigned short length;
Expand Down

0 comments on commit 3f34e15

Please sign in to comment.