someone
someone

Reputation:

Disable Hardware & Software Interrupts

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!

Upvotes: 9

Views: 14327

Answers (3)

saeed eivazi
saeed eivazi

Reputation: 19

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!

Upvotes: 2

Ludwig Weinzierl
Ludwig Weinzierl

Reputation: 16614

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.

Upvotes: 12

Goz
Goz

Reputation: 62323

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.

Upvotes: 3

Related Questions