您的位置:首页 > 其它

操作系统学习笔记(29)--初始化Trap

2010-06-01 22:30 274 查看
和中断处理类似

 

1 写Trap处理函数

2 在Trap号中添加该函数地址

 

 

在中断处理号中添加Trap处理函数地址即可。

 

 

Trap Gate和中断Gate是一样的。

 

Interrupt 12—Stack Fault Exception(#SS)

Interrupt 13—General Protection Exception (#GP)

 

下面的是个简单实例

/*
* Handler for general protection faults and other bad errors.
* Kill the current thread (which caused the fault).
*/
static void GPF_Handler(struct Interrupt_State* state)
{
/* Send the thread to the reaper... */
Print("Exception %d received, killing thread %p/n",
state->intNum, g_currentThread);
Dump_Interrupt_State(state);

Exit(-1);

/* We will never get here */
KASSERT(false);
}

/*
* Initialize handlers for processor traps.
*/
void Init_Traps(void)
{
Install_Interrupt_Handler(12, &GPF_Handler);  /* stack exception */
Install_Interrupt_Handler(13, &GPF_Handler);  /* general protection fault */
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  exception thread struct kill