我已经阅读了有关 BIOS 中断的信息,并且知道它们只能在 8086 实模式下访问。
我的问题:
还有其他可用的中断吗?我已经阅读了有关 DOS 中断的信息,但我很困惑它们是否也可以在实模式下使用,以及 DOS 中断列表是什么。
一旦我们进入保护模式,存储在 0x00 的 BIOS 中断表会发生什么变化?它是替换,还是存在但无法访问?
- 像 0x13 或 0x19 这样的 BIOS 中断,它们是如何实现的?它是在软件中还是通过处理器?
我已经阅读了有关 BIOS 中断的信息,并且知道它们只能在 8086 实模式下访问。
我的问题:
还有其他可用的中断吗?我已经阅读了有关 DOS 中断的信息,但我很困惑它们是否也可以在实模式下使用,以及 DOS 中断列表是什么。
一旦我们进入保护模式,存储在 0x00 的 BIOS 中断表会发生什么变化?它是替换,还是存在但无法访问?
In real mode, you have 256 different SOFTWARE TRIGGERED interrupts. In the early days of BIOS and DOS, they were used as not much more than a "jump address" table. For example, DOS used INT 21 mainly, so applications could be coded to use the INT 21
processor instruction instead of a CALL 1234:5678
- the real address would change with each new version of DOS, but the INT 21 stayed. When dos booted up, it would put the address of its real handler function into that slot of the interrupt table.
The INT XX
processor instruction can use interrupt numbers from 0 to 255, so all of them are available. If there was anything useful in the corresponding interrupt table slot was another thing - there were lots of resident programs however, that used some specific interrupt (which led to collisions if you loaded more than one of these programs).
Apart from this are the HARDWARE interrupts - these are not triggered by software, but by an external device like your keyboard, floppy or hard disk, when they wanted to tell the processor "i need some service". So for example, when you pressed a key on the keyboard, the keyboard controller triggers interrupt 9 (not sure about the number, it's a long time ago, but interrupts 8-15 were reserved for hardware). When booting, the BIOS would put the address of its keyboard-handling-procedure into the corresponding entry of the interrupt table. Whenever you pressed a key, the keyboard controller triggered interrupt 9, which made the processor look up the corresponding address in the interrupt table, call it - this transfers control to the bios - the bios did whatever is neccesary to get the actual key from the keyboard, then returned to the application, which had no idea what hat happened.
So to answer your first question: There are 256 interrupts. 0-7 were used for processor-internal stuff. 07-0F were triggered by hardware. 10-1F were reserved for the Bios, and DOS used 20-27. The rest of them were unused, which means, no valid procedure entry point was stored for them in the interrupt table. (This became very murky later, i'm oversimplifying here).
2nd question: Once you enter protected mode, the interrupt table is replaced by the OS that puts the processor in protected mode, because the BIOS routines were written for the 8086 which did not have a protected mode, often aren't safe to use if not in real mode, and don't handle multitasking well. Any decent OS just has to do this kind of stuff itself. And interrupts from 20-27, which were used by DOS, just have no replacement for them in others OSes. So you can't run dos executables on Linux, apart from not being able to run them, they wouldn't work if they use dos interrupts.
3rd question: The BIOS interrupts themselves are purely software, but they trigger hardware events. Interrupt 13 was for the floppy/hard disk. A program that wanted to read sectors directly from the floppy would fill the processor registers with some predefined values, call interrupt 13 (thus jump into the BIOS routine, the address of which was put into the interrupt table when the BIOS booted), and let the bios do its work. No hardware stuff yet. WITHIN the interrupt handler, of course, the bios would read and write the hardware ports of the floppy controller, but the application didn't have to know about the details.
DOS 中断在 DOS 中可用。(Windows 中的 16 位程序也可以使用它们,因为它在虚拟 8086 模式下运行,并且 Windows 试图呈现像过去一样的环境。)在操作系统开始加载之前它们并不存在,但是……如果您正在构建自己的操作系统,除非您将它们放入,否则它们根本不存在。
一旦你切换到保护模式,你基本上就跑掉了你在切换期间设置的中断描述符表(IDT)。旧表仍然存在,因为它的格式不同,如果在切换之前发生中断,您不能直接覆盖它而不冒麻烦。无论如何,您通常会出于几个原因保留它,包括它在您出于某种原因必须切换回实模式时的有用性。(Windows 9x 曾经这样做。一些驱动程序是 16 位的,没有人想更新它们……所以 Windows 能够让这些驱动程序在实模式下运行。)但是当处理器处于受保护状态时,它不会被使用模式。
处理器不直接参与中断的实际处理。它甚至不知道它正在运行什么类型的计算机。基本上,它只是在 IDT 中看到一个条目并调用该中断处理程序。