Distinguishing PIT fires from software interrupts

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
gzaloprgm
Member
Member
Posts: 141
Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:

Distinguishing PIT fires from software interrupts

Post by gzaloprgm »

Hi, in my multitasking kernel I am using the PIT as a time base for sleeps (bad idea, I know).

The problem is that if a task keeps calling the scheduler (via int 32 for example), the time starts to drift.

How can I know if an interrupt was a real PIT fire instead of a software interrupt? Is there any way to ask the PIC if it just sent an interrupt?

Cheers,
Gzaloprgm
Visit https://gzalo.com : my web site with electronic circuits, articles, schematics, pcb, calculators, and other things related to electronics.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Distinguishing PIT fires from software interrupts

Post by Combuster »

How can I know if an interrupt was a real PIT fire instead of a software interrupt?
Do not use IRQ0 as a system interrupt, but reserve a system call for that
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Distinguishing PIT fires from software interrupts

Post by Brendan »

Hi,
gzaloprgm wrote:How can I know if an interrupt was a real PIT fire instead of a software interrupt? Is there any way to ask the PIC if it just sent an interrupt?
You can check if the corresponding flag in the PIC's "in service register" is set - if this flag isn't set then you know the PIC didn't send the IRQ.

However, a much better idea is to set the DPL in the IDT entry to zero for all IRQs and exceptions. In this case if any user-level code attempts to call the IRQ handler (or exception handler) using a software interrupt then it'll trigger a general protection fault (but if an genuine IRQ or exception occurs then CPU will still start the interrupt handler, without triggering a general protection fault).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply