在我自己的操作系统内核中的周期性RTC中断

periodic RTC interrupt in My own OS kernel

本文关键字:周期性 RTC 中断 系统内核 我自己 自己的 操作      更新时间:2023-10-16

我目前正在用c++编程一个内核。因此,作为内核的基本部分,我在我的内核中实现了一个中断处理模块,它工作得很好。但是它不能为RTC IRQ8中断工作

这是启用irq的代码:

void IDT::enable_irq(unsigned short x, void (*handler)(), unsigned char control){
    current_mask &= ~(1<<x) ;   //Zero off the IRQ mask to enable
if (x>=8)
{
    current_mask &= ~(1<<2);
    set_int((x + SLAVE_VEC - 7),(unsigned long) handler, control);
}
else            //Sets the appropriate interrupt at the same time
{
    set_int((x + MASTER_VEC),(unsigned long) handler, control);
}
outb(PICMI, current_mask & 0xff);
outb(PICSI, (current_mask >> 8) & 0xff);
}

set_int是在IDT中添加中断项的函数。

如果我调用它,它可以很好地用于键盘中断:

enable_irq(1,kbInt,INT_GATE|BITS_32|PRESENT|RING_2);

但是如果我为irq8(即RTC)调用它,则它不起作用。

enable_irq(8,rtcInt,INT_GATE|BITS_32|PRESENT|RING_2);

给出如下错误:An unhandled interrupt has occurred...

然后我按照本教程的说明:http://wiki.osdev.org/RTC

但是我想做的是,我想在每个中断上生成周期性RTC中断和屏幕上的显示时间。或者我想在每个RTC中断上调用一个特定的函数

那么谁能帮我解决这个问题呢?

谢谢。

你的代码中的数学是错误的。

if (x>=8) 
{ 
    current_mask &= ~(1<<2); 
    set_int((x + SLAVE_VEC - 7),(unsigned long) handler, control); 
} 

将在IDT中的0x41位置安装处理程序,如果SLAVE_VEC是0x40(正如您的评论所暗示的),当您肯定想将其安装在0x40位置时,因为0x40是由PIC为IRQ8触发的中断(再次,假设PIC配置为具有0x40的基数)。

你的代码应该是:-

if (x>=8) 
{ 
    current_mask &= ~(1<<2); 
    set_int((x + SLAVE_VEC - 8),(unsigned long) handler, control); 
} 

将正确配置IRQ8的0x40 IDT项。