开发者

Why Interrupt handler entry code check Carry flag?

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' instruct开发者_StackOverflowion 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?


Actually, I think it's checking whether CS corresponds to a kernel thread, see the comment for a similar construct at ret_from_fork.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜