I'm trying to get a deeper understanding of how system calls and hardware interrupts are implemented, and something that keeps confusing me is how they differ with respect to how they're handled. For example, I am aware that one way a system call (at least used to) be initiated is through the x86 INT 0x80
instruction.
-
Does the processor handle this the exact same way as if, say, a hardware peripheral would have interrupted the CPU? If not, at what point do they differ? My understanding is they both index the IDT, just with different indices in the vector.
-
In that same sense, my understanding is there's this idea of a
softirq
to handle the "bottom half" processing, but I only see this form of "software interrupt" in reference to being enqueued to run by physical hardware interrupts. Do system call "software interrupts" also triggersoftirq
s for processing? That terminology confuses me a bit as well, as I've seen people refer to system calls as "software interrupts" yetsoftirq
s as "software interrupts" as well.
Best Answer
INT 0x80h
is an old way to call kernel services (system functions). Currently,syscalls
are used to invoke these services as they are faster than calling the interrupt. You can check this mapping in kernel's Interrupt Descriptor Table idt.c and in line 50 in the irq_vectors.h file.The important bit that I believe answers your question is the header of that last file, where you can see how interrupt requests (IRQs) are organized.
It really does not matter if it is by electrical means or software means. Whenever an interrupt is triggered, the kernel looks for its ID in the IDT and runs (in kernel mode) the associated interrupt handler. As they have to be really fast, they normally set some info to be handled later on by a
softirq
or atasklet
. Read chapter 2 (fast read...) of the Unreliable Guide To Hacking The Linux KernelLet me recommend also reading this really good and thorough answer at stackoverflow to Intel x86 vs x64 system call question, where
INT 0x80h
,sysenter
andsyscall
are put in context...I wrote my own (so very modest and still under construction) self learning page about interrupts and signals to help me understand the relation of signals and traps with interrupts (for instance SIGFPE - divide by zero).