禁用硬件和软件中断

发布于 2024-08-06 08:23:40 字数 123 浏览 6 评论 0 原文

是否可以使用 ASM/C/C++ 程序禁用所有中断以完全控制处理器?

如果是的话->如何?

如果没有-> “原子”操作系统调用如何工作(例如进入关键部分)?

感谢您的帮助!

Is it possible to disable all interrupts with a ASM/C/C++ program to get full control about the processor?

If yes -> how?

If not -> how do "atomic" operation system calls work (for example entering a critical section)?

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

赢得她心 2024-08-13 08:23:40

在 x86 汇编中,命令为

  • sti 设置中断启用位
  • cli 清除中断启用位

这些命令设置和清除 IF 标志。当IF标志被置位时,CPU将处理硬件中断,当该标志被清零时,CPU将忽略硬件中断。但它不影响不可屏蔽中断的处理,也不影响软件中断或异常。这些指令在非特权模式下也不起作用(通常高于环 0 的所有内容,具体取决于 IOPL ) 尽管。

In x86 assembly the the commands are

  • sti set interrupt enable bit
  • cli clear interrupt enable bit

These commands set and clear the IF Flag. When the IF flag is set, the CPU will handle hardware interrupts, and when it is clear the CPU will ignore hardware interrupts. It does not affect the handling of non-maskable interrupts though, nor does it affect software interrupts or exceptions. These instructions also don't work in unprivileged mode (usually everything higher than ring 0, depending on IOPL) though.

忆悲凉 2024-08-13 08:23:40

在 x86 和大多数其他现代处理器上,您可以获得原子指令。在另一个线程/处理器可以访问该内存之前保证不会完成执行。

在 Win32 下,您拥有 Interlocked* 函数,可以在受支持的平台上从您那里抽象出这些功能。

在 MIPS 上,很多指令可以有一个 .I 添加到指令末尾以保证互锁。

on x86 and most other modern processors you can get atomic instructions. Ones that are GURANTEED not to be finished executing before another thread/processor can access that memory.

Under Win32 you have the Interlocked* functions that abstract that from you on supported platforms.

On a MIPS a lot of instruction can have a .I added to the end of the instruction to guarantee interlocking.

凑诗 2024-08-13 08:23:40

x86 在 FLAGS 寄存器中有一个中断标志 (IF)。当该标志设置为 0 时,硬件中断被禁用,否则它们被启用。命令 cli 将此标志设置为 0,sti 将其设置为 1。将值加载到 FLAGS 寄存器的指令(例如 popf 和 iret)也可能会修改此标志。

祝你好运!

The x86 has an interrupt flag (IF) in the FLAGS register. When this flag is set to 0, hardware interrupts are disabled, otherwise they are enabled. The command cli sets this flag to 0, and sti sets it to 1. Instructions that load values into the FLAGS register (such as popf and iret) may also modify this flag.

good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文