任务七:
1.中断向量表中一个表项占用多少字节?
2.完成初始化函数idt_init
3.完成中断处理函数trap()
实验过程:
中断向量表中一个表项的代码为:
struct gatedesc {
unsignedgd_off_15_0 : 16; // low 16bits of offset in segment
unsignedgd_ss : 16; // segmentselector
unsignedgd_args : 5; // # args, 0for interrupt/trap gates
unsignedgd_rsv1 : 3; //reserved(should be zero I guess)
unsignedgd_type : 4; //type(STS_{TG,IG32,TG32})
unsigned gd_s: 1; // must be0 (system)
unsignedgd_dpl : 2; //descriptor(meaning new) privilege level
unsigned gd_p: 1; // Present
unsignedgd_off_31_16 : 16; // high bitsof offset in segment
};
将bit位相加共64bit为8字节。
设置函数:
首先打开新加入的文件中,寻找中断向量表
MMU.H中的SETGATE宏进行填充
#define SETGATE(gate, istrap, sel, off, dpl){ \
(gate).gd_off_15_0 = (uint32_t)(off) &0xffff; \
(gate).gd_ss =(sel); \
(gate).gd_args =0; \
(gate).gd_rsv1 =0; \
(gate).gd_type = (istrap) ? STS_TG32 :STS_IG32; \
(gate).gd_s =0; \
(gate).gd_dpl =(dpl); \
(gate).gd_p =1; \
(gate).gd_off_31_16 = (uint32_t)(off) >>16; \
}
说明如下:
/* *
* Set up a normal interrupt/trap gate descriptor
* - istrap: 1 for a trap (= exception) gate, 0 for an interruptgate
* - sel: Code segment selector for interrupt/trap handler
* - off: Offset in code segment for interrupt/trap handler
* - dpl: Descriptor Privilege Level - the privilege level required
* for software to invokethis interrupt/trap gate explicitly
* using an intinstruction.
* */
下面就是有关参数的寻找了,主要使用这个宏进行段选择符的构造
gate:这是为相应的idt数组内容
istrap:系统段设置为1,中断门设置为0
off:为__vectors数组内容
dpl:设置优先级
使用__vector数组时,c程序文件中引用之前,extern声明一下
extern long __vectors[];
/* LAB1 YOUR CODE */
//初始化中断向量表进行操作
int i = 0;
for(i = 0;i <= 255; i++)
{
//设置IDT表的操作
SETGATE(idt[i],0,KERNEL_CS,__vectors[i],3);
}
SETGATE(idt[T_SYSCALL],1,KERNEL_CS,__vectors[T_SYSCALL],0);
lidt(&idt_pd ); //装载IDT表
}
设置时钟进行操作:
char c;
switch (tf->tf_trapno) {
case IRQ_OFFSET + IRQ_TIMER:
if(ticks ==100) //进行时钟进行分析
{
print_ticks();
ticks = 0;
}
else
{
ticks++;
}
break;
试验结果如下: