Bochs or me? (Problem resolved!)
Posted: Wed May 31, 2006 6:59 am
The original thread I created had a lot of long post and haven't made to a second page, which I think led to problems trying to access it. This thread continues Bochs or me? thread.
Btw, I am very glad that Bochs emulates this other wise this may lead to very big bugs in the future.
Here is my routine to handle spurious interrupts:
If you have comments or find anything wrong with it please tell me. I hope it helps other readers overcome sparious interrupts also.
Brendan thanks a ton, because I think I would jumped off a building if it didn't make sense after two more days! I really do appreciate it.
Yes! I went and checked 8259A datasheet, and does say along the lines. If IR7 is spurious then you can ignore it and just do iret. But if IR7 is to be used, then you can read PIC.ISR which should be set to the corresponding IR otherwise would be considered spurious. I assume that IR7 is IRQ-15 for slave?Brendan wrote: It's a pain in the neck, but the PIC chips can generate a "spurious interrupt", which is normally IRQ7 for PIC1 and IRQ15 for PIC2 (and can't be masked).
The idea is that if the PIC chip's "INTR" line is high then the CPU is meant to wait for the interrupt number to come from a PIC chip. If the PIC chip doesn't know why the INTR line is high then it'll send a spurious interrupt so that the CPU does receive an interrupt number and doesn't get all messed up (i.e. wait forever).
Bochs does emulate this spurious interrupt - see "iodev/pic.cc" around line 807.
Btw, I am very glad that Bochs emulates this other wise this may lead to very big bugs in the future.
What I also found out was after masking it correctly (which I did fix up and thanks ) wasn't enough and GPF still was being generated. I finally went and tried to do a software interrupt to 27h (IRQ-7), and it produced a GPF not a #NP (No segment Present). I guess I was wrong to think that it should have made #NP, and after referring back to the holy bible it doesn't specify on IDTs but only in its error codes, hmm which is confusing.Brendan wrote: Out of curiousity, what would happen if your OS got an IRQ7?
Here is my routine to handle spurious interrupts:
Code: Select all
SYSTEM_SPURIOUS equ 0FFh
;==========================================================================
___Interrupt27h PROC SYSCALL
;==========================================================================
;+++++++++++++++STACK+++++++++++++++++++10h++++++++++++++++++++++++++++++++
@EFLAGS equ esp+0Ch
@CS equ esp+08h
@RIP equ esp+04h
push eax ; equ esp+00h
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;;;;; handle spurious NMIs ;;;;;;
test BYTE PTR ds:[swSystemFlags], SYSTEM_SPURIOUS ; guard nesting spurious
jnz short @RETURN ; interrupt events
mov al, 03h ; PIC.OCW3 set function to read ISR (In Service Register)
out 23h, al ; write to PIC.OCW3
in al, 20h ; read ISR
test al, 80h ; if the in-service register does not have IR7 bit set
jz short @RETURN ; this would be a spurious interrupt.
;;;; mutex for spurious guard ;;;;
adc BYTE PTR ds:[swSystemFlags], 7Fh ; only first access to handle will pass the
jp short @RETURN ; the following flags
jo short @RETURN ; NMIs that made it this far will
jc short @RETURN ; return as spurious interrupt.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; normal IRQ-7 routine ;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov al, 20h
out 20h, al ; send EOI to master PIC
mov BYTE PTR ds:[swSystemFlags], 0 ; release spurious guarding
@RETURN:
pop eax
iretd
___Interrupt27h ENDP
Brendan thanks a ton, because I think I would jumped off a building if it didn't make sense after two more days! I really do appreciate it.