Page 1 of 1

bochs PIC and APIC

Posted: Wed Jun 20, 2012 6:28 pm
by vjain20
Hi,
In my kernel timer interrupts are generated by initializing 8259 PIC and PIT. But now I want to use APIC for generating timer interrupts.
So I recomplied bochs to cpu-level 6 to enable APIC. But now it seems that when I initialize the 8259 PIC, timer interrupts get generated automatically . This happens even when both PIT and APIC timer are disabled. However if I do not initialize the 8259,the code throws a double fault.
I don't understand why is timer interrupt generated just by initializing the PIC.

-Thanks
Vaibhav Jain

Re: bochs PIC and APIC

Posted: Wed Jun 20, 2012 7:14 pm
by Nessphoro
AFAIK, timer interrupts are generated at ~17 times per second on boot.

Re: bochs PIC and APIC

Posted: Wed Jun 20, 2012 11:46 pm
by vjain20
AFAIK, timer interrupts are generated at ~17 times per second on boot.
So does that mean that we do not need to initialize any timer for timer interrupts ?
Also why does enabling PIC cause a timer interrupt ? Or is it the interrupt by the APIC timer ?









Thanks
Vaibhav Jain

Re: bochs PIC and APIC

Posted: Wed Jun 20, 2012 11:47 pm
by Combuster
Not all BIOSes do it that way.

Re: bochs PIC and APIC

Posted: Thu Jun 21, 2012 2:11 am
by vjain20
I checked on qemu also. If I do not initialize the PIC I get a double fault. I am unable to
figure out why. I have all the 255 interrupt handlers (stubs printing the interrupt number) installed but none of them gets called.

Code: Select all

Next at t=219627445
(0) [0x00000000001011a9] 0008:c00011a9 (kmain+185): sti                       ; fb
<bochs:3> s
(0) [0x00000000001011aa] 0008:c00011aa (kmain+186): add esp, 0x0000008c       ; 81c48c000000
<bochs:3> s
Next at t=157572693
(0) [0x0000000000102ce8] 0008:c0002ce8 (isr08+1): push 0x00000008           ; 6808000000
Here add esp, 0x0000008c is the line just before ret and just after sti. The whole function runs fine but at this point it throws a double fault.

However if I enable the PIC (with PIT disabled), I get a timer interrupt - Interrupt 32.

Code: Select all

(0) [0x00000000001011af] 0008:c00011af (kmain+18b): add esp, 0x0000008c       ; 81c48c000000
<bochs:3> s
Next at t=158411476
(0) [0x0000000000102e45] 0008:c0002e45 (isr32+1): push 0x00000000           ; 6800000000
I don't understand why disabling the PIC is causing a double fault and why enabling it is causing a timer interrupt even when PIT is disabled.


- Thanks
Vaibhav Jain

Re: bochs PIC and APIC

Posted: Thu Jun 21, 2012 4:20 am
by Combuster
Because you can't technically disable the PIT.

Re: bochs PIC and APIC

Posted: Thu Jun 21, 2012 6:57 pm
by vjain20
Because you can't technically disable the PIT
What I meant by disabling PIT is that I am not initializing the PIT channel and counter.
Does the PIT continue to generate interrupt even if it has not been initialized?
If that is the case how can I use only the local APIC to generate timer interrupts ? I want to do away with the PIT.




-Thanks
Vaibhav Jain

Re: bochs PIC and APIC

Posted: Fri Jun 22, 2012 3:06 am
by Combuster
ooookay..
Image
This sums up to not reading the wiki pages (PIT for example), making assumptions based on total guesswork, not searching, and completely ignoring the FAQ (as demonstrated by the double fault).

Learn to program, please.

Re: bochs PIC and APIC

Posted: Fri Jun 22, 2012 11:59 pm
by vjain20
:oops:
ok I read some more and found that PIT is initialized by BIOS (from the PIT wiki)
On reading the 8259_PIC wiki I found that for working with local APIC the PIC needs to be disabled. I did that but found that the code was still throwing double fault but not every time. From this post -
http://forum.osdev.org/viewtopic.php?f=15&t=23096 I got to know that even if all the interrupts are masked the PIC can still send spurious interrupts.
You'd mask all IRQs in the PIC so they can't occur, and use the I/O APICs instead. However, it is still technically possible for the PIC chips to generate spurious IRQs (which can't be masked or prevented in the PIC); so just in case you'd still need to remap the PICs even though you aren't using them, and have spurious IRQ handlers for the PICs.
So I first configured the PIC to remap the IRQs and then masked all the interrupts.This stopped the double fault.
Now for configuring the APIC timer I am using the code from the APIC timer and APIC wiki.
But the problem is that APIC timer is not working. I read the code and tried to understand it. I don't see any problem with the code.
The interrupt handler is not getting called . To verify if interrupt is being generated I am reading the current count register in a loop
but the count doesn't seem to change. I don't know what should I do.
(Please excuse me for my lack of effort shown by copying the code for APIC Timer)

-Thanks
Vaibhav Jain