assembly - x86 汇编中断服务例程可以调用另一个中断吗?

标签 assembly x86 interrupt interrupt-handling

我可以在独立的 x686 环境中从中断服务例程中调用中断吗?

因此,可以执行以下操作:

isr:
    pusha
    call doSomething
    int 21h
    popa
iret

如果可能,那么这些嵌套的中断是否有任何重大的塌陷?

最佳答案

虽然处理器对嵌套中断没有基本限制,但 MS-DOS 和 BIOS 服务是不可重入的。也就是说,在硬件中断期间调用它们通常是不安全的,因为在 CPU 已经在执行 MS-DOS 或 BIOS 功能时可能会发生中断。

要从硬件中断服务例程中使用 MS-DOS 和 BIOS 服务,您可以采取许多步骤来确保可以安全地使用它们。您需要做的事情相当复杂,除此之外,您还需要监视 InDos 标志并 Hook 其他中断,因此我将向您指出 section on reentrency在汇编语言程序设计的艺术中。它在涵盖所有细节方面做得非常好。

这是该部分的摘录。这只是您可能需要做的一部分:

MS-DOS provides a special one-byte flag (InDOS) that contains a zero if DOS is currently active and a non-zero value if DOS is already processing an application request. By testing the InDOS flag your TSR can determine if it can safely make a DOS call. If this flag is zero, you can always make the DOS call. If this flag contains one, you may not be able to make the DOS call. MS-DOS provides a function call, Get InDOS Flag Address, that returns the address of the InDOS flag. To use this function, load ah with 34h and call DOS. DOS will return the address of the InDOS flag in es:bx. If you save this address, your resident programs will be able to test the InDOS flag to see if DOS is active.

Actually, there are two flags you should test, the InDOS flag and the critical error flag (criterr). Both of these flags should contain zero before you call DOS from a TSR. In DOS version 3.1 and later, the critical error flag appears in the byte just before the InDOS flag.

So what should you do if these flags aren't both zero? It's easy enough to say "hey, come back and do this stuff later when MS-DOS returns back to the user program." But how do you do this? For example, if a keyboard interrupt activates your TSR and you pass control on to the real keyboard handler because DOS is busy, you can't expect your TSR to be magically restarted later on when DOS is no longer active.

The trick is to patch your TSR into the timer interrupt as well as the keyboard interrupt. [...]

关于assembly - x86 汇编中断服务例程可以调用另一个中断吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25584477/

相关文章:

c++ - 加载 128 位混合 float+int 数据?

loops - 在x86/x86_64中,如何才能 "jump if not zero"而不影响进位标志?

C++ 变量在中断后的中断重置期间发生变化

c - 如何修复在 EXTI9-5 上多次触发的中断?

c - 为什么键盘中断在 QEMU 中起作用,但在真实硬件上不起作用?

assembly - 字节码和汇编语言是一回事吗?

ubuntu - 如何在 nasm 上运行这个汇编代码?

java - 如何编写可中断的方法

assembly - 在汇编代码中,.cfi 指令如何工作?

c - 哪种 MCU(Cortex-M) 适用于时间关键的 GPIO 应用?