Reputation: 2251
IRET can restore the registers from the stack,including EFLAGS, ESP, EIP and so on, but we can also restore the registers all by ourselves. For example, "movl" can be used to restore the %esp register, "jmp" can jump the address pointed to EIP which is stored on the stack.
The linux kernel returns from all interrupts by IRET, which is a weight instruction.
Some kernel operations (like context switches) happen frequently.
Isn't IRET a waste?
Upvotes: 4
Views: 4688
Reputation: 10937
From wikipedija:
The actual code that is invoked when an interrupt occurs is called the Interrupt Service Routine (ISR). When an exception occurs, a program invokes an interrupt, or the hardware raises an interrupt, the processor uses one of several methods (to be discussed) to transfer control to the ISR, whilst allowing the ISR to safely return control to whatever it interrupted after execution is complete. At minimum, FLAGS and CS:IP are saved and the ISR's CS:IP loaded; however, some mechanisms cause a full task switch to occur before the ISR begins (and another task switch when it ends).
So IRET
isn't waste, it is minimum (and the fastest way) to return from ISR. Also all other CPU registers used in ISR must be preserved at begining and restored before IRET
exsecution!
Upvotes: 0
Reputation: 62058
Besides all the heavy stuff IRET
can and often should do in addition to a mere blend of POPF+RETF
, there's one more thing that it does. It has a special function related to non-maskable interrupts (NMIs
).
Concurrent NMIs are delivered to the CPU one by one. IRET
signals to the NMI circuitry that another NMI can now be delivered. No other instruction can do this signalling.
If NMIs could preempt execution of other NMI ISRs, they would be able to cause a stack overflow, which rarely is a good thing. Unless we're talking about this wonderful website. :)
So, all in all, IRET
is not a waste.
Upvotes: 9
Reputation: 91039
Probably because doing all that manually would need even more CPU clocks.
Upvotes: 0