How to find if an interrupt generated by the program or not?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Coconut9
Member
Member
Posts: 51
Joined: Sat May 20, 2017 1:25 am
Location: PCI bus: 3, slot: 9, function: 5

How to find if an interrupt generated by the program or not?

Post by Coconut9 »

Is there an fast way to find if an interrupt has been generated by the program, the cpu or the LOCAL APIC?
I thought to "pop" the first stack value and test if the point that the value points (program EIP) is equal to 0xCD (int instruction in binary).
Do there exist also a way to block code that runs on ring 3 execute the specific interrupt (if do to generate #GP)?
How people react when a new update of your OS is coming:
Linux user: Cool, more free stuff!
Mac user: Ooh I have to pay!
Windows user: Ah not again!
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: How to find if an interrupt generated by the program or

Post by Korona »

If you're using the local APIC, you can check its ISR register to see if the interrupt is hardware generated. You can also do that for the legacy PIC, however it is not advisable to do so, as reads from the PIC need to go through the system bus and chipset and are much slower than reads from the APIC.

Checking the instruction is not sound as an hardware IRQ might trigger at an "int" instruction boundary.

The IDT has bits that determine the privilege level that is require to invoke each vector using the "int" instruction. The CPU itself only generates faults (i.e. vector number < 32).
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
Post Reply