为什么中断处理程序入口代码检查进位标志?
我试图在虚拟机中生成中断并编写了一个简单的中断处理程序,但是当我尝试测试此中断生成和处理时,内核因页面错误而崩溃。现在我调试了这个问题,发现在“entry_64.S”文件中,调用“error_entry”将寄存器压入堆栈并检查 GS,其中有以下代码:
xorl %ebx,%ebx
testl $3,CS+8(%rsp)
je error_kernelspace
error_swapgs:
SWAPGS
处理中断时,CPU 将把 EFLAGS 推送到 (rsp)+CS +8 位置。因此,在上面的代码“testl”指令中,检查中断时是否设置了标志位的进位标志,以检测中断是处于内核模式还是用户模式。
有人可以解释一下为什么这里选中了进位标志吗?
I am trying to generate an interrupt in a VM and have written a simple interrupt handler but when I try to test this interrupt generation and handling, kernel crashes because of page fault. Now I debugged the issue and found out that in 'entry_64.S' file where 'error_entry' is called to push registers onto stack and check for GS there following code:
xorl %ebx,%ebx
testl $3,CS+8(%rsp)
je error_kernelspace
error_swapgs:
SWAPGS
When interrupt is handled, CPU will push EFLAGS to (rsp)+CS+8 location. So in above code 'testl' instruction check if flag's Carry flag was set at the time of interrupt to detect if interrupt was in kernel mode or in user mode.
Can please someone explain why Carry flag is checked here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,我认为它正在检查 CS 是否对应于内核线程,请参阅
ret_from_fork
。Actually, I think it's checking whether CS corresponds to a kernel thread, see the comment for a similar construct at
ret_from_fork
.