简体   繁体   English

BIOS 如何区分中断(08h-12h)和 INT 指令,以及 CPU 内部的实际异常?

[英]How does the BIOS distinguish Interrupt(08h-12h) from INT instructions, vs. actual exceptions inside the CPU?

This is purely academic, out of date, out of curiosity.这纯粹是学术性的,过时的,出于好奇。 Let's back to 1990s, before the Windows, when real-mode DOS programs were common.让我们回到 1990 年代,在 Windows 出现之前,实模式 DOS 程序很常见。

The BIOS remapped the INT 08H+ for their own interrupt handler, for instance, int 10H for VGA MODE switch, int 13H for hard driver. BIOS 为自己的中断处理程序重新映射了 INT 08H+,例如,int 10H 用于 VGA 模式开关,int 13H 用于硬盘驱动程序。 ( Table of software-interrupt numbers ) 软件中断编号表

But, as we can see in Intel® 64 and IA-32 Architectures Software Developer Manuals, we can know that there are also many real-address exception that can cause interrupt.但是,正如我们在英特尔® 64 和 IA-32 架构软件开发人员手册中看到的那样,我们可以知道也有许多实地址异常会导致中断。 For example, #DE divide exception raising interrupt vector 0h , or x87 FPU raising 10h ( https://wiki.osdev.org/IVT )例如,#DE 除异常引发中断向量0h ,或 x87 FPU 引发10h ( https://wiki.osdev.org/IVT )

If a programmer intentionally or unintentionally makes the CPU raise those exceptions on its own, by running instructions like bound that can trigger a BOUND Range Exceeded exception, how does the BIOS or anything else distinguish that from an INT 5 software interrupt to make as PRINT SCREEN call, for instance.如果程序员有意或无意bound让 CPU 通过运行诸如可以触发BOUND Range Exceeded异常的指令来自行引发这些异常,那么 BIOS 或其他任何东西如何将其与INT 5软件中断区分开来,使其成为PRINT SCREEN打电话,例如。 It's the same IVT entry so the same interrupt handler will be invoked for either case.这是相同的 IVT 条目,因此对于任何一种情况都将调用相同的中断处理程序。

What's more, IRQ makes if you want to use keyboard you can't trigger those interrupts.更重要的是,如果你想使用键盘,IRQ 就无法触发这些中断。 ( OSdev IRQ assignments table ) OSdev IRQ 分配表

As so many Intel's default interrupt is remapped by the bios, things became unreasonable.由于BIOS重新映射了许多Intel的默认中断,因此事情变得不合理。


This was cross-posted to retrocomputing.SE and also has an answer there.这是交叉发布到retrocomputing.SE并且在那里也有答案。

How does the BIOS distinguish Interrupt(08h-12h) from INT instructions, vs. actual exceptions inside the CPU? BIOS 如何区分中断(08h-12h)和 INT 指令,以及 CPU 内部的实际异常?

Mostly it doesn't.大多数情况下不会。 It assumes interrupts 0x08 to 0x0F are IRQs (from PIC chip/devices);它假设中断 0x08 到 0x0F 是 IRQ(来自 PIC 芯片/设备); does nothing useful when the interrupt is a software interrupt (and sends an EOI to PIC chip that can cause problems in some cases);当中断是软件中断时没有任何用处(并且在某些情况下会向 PIC 芯片发送 EOI,这可能会导致问题); and crashes and/or locks up (via. an "exception -> return to faulty code -> exception -> return to faulty code ..." loop) when its an exception.并在异常时崩溃和/或锁定(通过“异常->返回错误代码->异常->返回错误代码...”循环)。

In theory it's possible to ask the corresponding PIC chip if there's an IRQ in service to tell the difference between a real IRQ and other causes (software interrupt, exception and "spurious IRQ 7 or 15");理论上,可以询问相应的 PIC 芯片是否有 IRQ 在服务中,以区分真正的 IRQ 和其他原因(软件中断、异常和“虚假 IRQ 7 或 15”); and also possible to examine the bytes at "return CS:IP" to tell the difference between a software interrupt and other causes (exception, spurious IRQ).并且还可以检查“返回 CS:IP”处的字节,以区分软件中断和其他原因(异常、虚假 IRQ)。 There is no "exception 0x0F" (it's reserved);没有“异常 0x0F”(保留); so this set of "possible in theory" covers all of the cases.所以这组“理论上可能”涵盖了所有的情况。

Nobody does it.没有人这样做。

An OS solves the problem by reconfiguring the PIC chip and/or IO APIC to ensure there's no conflicts between exceptions and IRQs, and using privilege levels to ensure that a software interrupt for interrupts used by exceptions or IRQs cause a general protection fault.操作系统通过重新配置 PIC 芯片和/或 IO APIC 来解决问题,以确保异常和 IRQ 之间没有冲突,并使用特权级别来确保异常或 IRQ 使用的中断的软件中断会导致一般保护错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM