为什么 IA-32 架构在调用中断处理程序之前将 EFLAGS 寄存器压入堆栈?
仅仅是因为 EFLAGS 寄存器像开关一样工作吗?那么当它处于活动状态时,中断就被启用,否则,就不是?
比如说,在 Java 程序中,它会是这样的,
while (switch != 0){
keepRunning;
}
Stop;
Is it just because the EFLAGS register works like a switch? So when it's active, the interrupt is enabled, otherwise, it's not?
Say, in a Java program it would be something like,
while (switch != 0){
keepRunning;
}
Stop;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
内核将 EFLAGS 保存在中断堆栈帧中,以便稍后可以恢复中断的任务。 EFLAGS 是内核在堆栈帧中保存的最低限度机器状态的一部分,其中还包括指令指针 (EIP)、代码段 (CS) 以及通常的用户模式堆栈指针 (ESP)。当中断服务例程完成时(使用 IRET 指令),内核恢复 EFLAGS 和堆栈帧中的其余寄存器。
这里的基本原理是,任务可以执行,而不必担心任何随机中断会突然破坏寄存器。这是唯一明智的方法。
The core saves EFLAGS in the interrupt stack frame in order that the interrupted task can be resumed later. EFLAGS is part of the bare minimum machine state saved by the core in the stack frame, which also includes the instruction pointer (EIP), code segment (CS) and usually the user-mode stack pointer (ESP). When the interrupt service routine completes (with the IRET instruction), the core restores EFLAGS and the rest of the registers in the stack frame.
The basic philosophy here is that a task can execute without worry that any random interrupt will suddenly stomp on registers. It's the only sane approach.
我认为原因很简单,寄存器是通过中断而被修改的。即IE(中断使能)标志将被清除。如果 CPU 不推送标志,它将无法修改标志,并且需要额外的状态和额外的指令来获取此隐藏状态。
I believe a reason for this is simply that the registers are modified by virtue of taking an interrupt. Namely the IE (interrupt-enable) flag will be cleared. If the CPU didnt push the flags, it wouldnt be able to modify the flags and would require extra state and extra instructions to get this hidden state.