/*! * @fn void cpumon_Set_IDT_Func(idt, func) * * @param GATE_STRUCT* - address of the idt vector * @param PVOID - function to set in IDT * * @return None No return needed * * @brief Set up the interrupt handler. * @brief Save the old handler for restoration when done * */ static VOID cpumon_Set_IDT_Func ( GATE_STRUCT *idt, PVOID func ) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) _set_gate(&idt[CPU_PERF_VECTOR], GATE_INTERRUPT, (unsigned long) func, 3, 0); #else #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0) unsigned long cr0_value; #endif GATE_STRUCT local; // _set_gate() cannot be used because the IDT table is not exported. pack_gate(&local, GATE_INTERRUPT, (unsigned long)func, 3, 0, __KERNEL_CS); // From 3.10 kernel, the IDT memory has been moved to a read-only location // which is controlled by the bit 16 in the CR0 register. // The write protection should be temporarily released to update the IDT. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0) cr0_value = read_cr0(); write_cr0(cr0_value & ~X86_CR0_WP); #endif write_idt_entry((idt), CPU_PERF_VECTOR, &local); #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0) write_cr0(cr0_value); #endif #endif return; }
void init_timer(){ write_port(0x43,0b00110100); write_port(0x40,(uint8_t)(1193180/CLOCK_FREQUENCY)); write_port(0x40,(uint8_t)((1193180/CLOCK_FREQUENCY)>>8)); timer_list_id = 0; timer_list = (timer_t *)TIMER_LIST_ADDRESS; for(int i = 0;i<TIMER_LIST_NUMBER;i++){ (timer_list+i)->exist = 0; } write_idt_entry(0x30,&timer_interrupt,INTERRUPT_GATE|INTERRUPT_NOT_FOR_PAGING); }
void init_floppy() { floppy_motor = 0; floppy_C = 0; cli(); init_floppy_DMA(); write_idt_entry(0x36,&floppy_interrupt,INTERRUPT_GATE|INTERRUPT_NOT_FOR_PAGING); sti(); floppy_reset(); add_timer(9,floppy_motor_enabled,0); //Delay 500ms }
/*! * @fn void cpumon_Set_IDT_Func(idt, func) * * @param GATE_STRUCT* - address of the idt vector * @param PVOID - function to set in IDT * * @return None No return needed * * @brief Set up the interrupt handler. * @brief Save the old handler for restoration when done * */ static VOID cpumon_Set_IDT_Func ( GATE_STRUCT *idt, PVOID func ) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) _set_gate(&idt[CPU_PERF_VECTOR], GATE_INTERRUPT, (unsigned long) func, 3, 0); #else GATE_STRUCT local; // _set_gate() cannot be used because the IDT table is not exported. pack_gate(&local, GATE_INTERRUPT, (unsigned long)func, 3, 0, __KERNEL_CS); write_idt_entry(idt, CPU_PERF_VECTOR, &local); #endif return; }
static inline void _set_gate(int gate, unsigned int type, void *addr, unsigned short seg) { __u32 a, b; pack_gate(&a, &b, (unsigned long)addr, seg, type, 0); write_idt_entry(idt_table, gate, a, b); }