为什么从实模式切换到保护模式之前需要禁用中断? [英] Why do interrupts need to be disabled before switching to protected mode from real mode?

查看:474
本文介绍了为什么从实模式切换到保护模式之前需要禁用中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很多其他的系统(和一些引导程序),它们都从中断(cli)禁用,然后才从实模式切换到保护模式.为什么我们需要这样做?

I saw in many many oses (and some bootloader), they all disable interrupt (cli) before switch to protected mode from real mode. Why we need do that?

推荐答案

BIOS使用PIT中断(IRQ0)来跟踪时间.进入保护模式后,实模式中断处理将不再有效.保护模式下的CPU需要保护模式IDT(中断描述符表).进入保护模式后,IDTR(IDT寄存器)中的IDT限制设置为0(任何中断号都会使CPU生成异常),因此,一旦PIT(或其他任何东西)生成了中断,CPU就会生成一个异常,将产生另一个异常,触发#DF(双重故障),并因此触发#TF(三重故障).

BIOSes use PIT interrupt (IRQ0) to track time. As soon as you enter protected mode, real mode interrupt handling is no longer valid; CPU in protected mode requires protected mode IDT (Interrupt Descriptor Table). Upon entering protected mode, IDT limit in IDTR (IDT Register) is set to 0 (any interrupt number makes CPU generate an exception), so as soon as PIT (or anything else) generates an interrupt, the CPU will generate an exception, which will make another exception generated, triggering #DF (double fault) and, by consequence, #TF (triple fault).

此外,在保护模式下发生的IRQ0将触发#DE(除例外)ISR(中断服务程序),因为从0到31的中断向量被保留用于保护模式下的异常.

Also, IRQ0 happening in protected mode will trigger #DE (divide exception) ISR (interrupt service routine), as interrupt vectors from 0 to 31 are reserved for exceptions in protected mode.

因此,(最有可能发生的中断可能是除PIT之外的其他中断)发生的顺序是这样的(注意:这是假定PIT中断将首先被触发,但是正如我之前所说的,它实际上可以是任何中断,每个都会导致#DF和三重错误):

So, the (most probable, as other interrupts than PIT might happen too) order of things that happen is like this (note: this assumes that PIT interrupt will be triggered first, but, as I said before, it can essentially be any interrupt, each will lead to #DF and triple fault):

  1. 在CR0中设置了PE位.
  2. 发生PIT中断,PIC(可编程中断控制器)在其#0引脚上获取信号.
  3. 未设置PIC重新映射,因此它会触发CPU上的IRQ0.
  4. IRQ0(= #DE)尝试执行中断处理程序,但IDT的限制为0,因此生成了(IIRC)#GP(常规保护错误).
  5. IDT的限制为0,因此生成了#DF.
  6. IDT的限制为0,因此会生成#TF.
  7. CPU停止或重新启动.

这篇关于为什么从实模式切换到保护模式之前需要禁用中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆