In this lecture, we will discuss spurious interrupt and how to handle it. The spurious interrupt, as its name implies,
is not a real interrupt. The IRQ used for spurious interrupt is the lowest priority IRQ number
,
that is IRQ7 for the master chip. The spurious interrupt is caused by several reasons
and it does not always occur.
OK, let's see how to handle it. In order to handle the spurious interrupt, we need to implement the handler
for IRQ7. Because we don�t use the slave chip in our system, we only deal with the spurious interrupt
in the master chip. Just like we did before, we set the idt entry first.
Since we need three copies of the code to set idt entries, we just wrap the code into a function.
We call it set handler.
and we use regular return instruction to return from the function.
Now we pass the address of idt entry to rdi register and the address of handler to rax
and then call set handler.
The address of the entry is the base of idt
+32*16
+7*16
since the vector number for IRQ7 is 32+7 and each entry is 16 bytes. We save it in the register rdi
.
The handler is called SIRQ
and copy the address in rax. Then we call set handler.
Next we implement the handler.
As with other interrupt handlers,
we save the state of the cpu in the beginning and restore its state before the handler returns.
You can define macros to wrap push and pop operations in these handlers. For simplicity, I just copy and paste the code here
.
In the handler, the first thing we are going to do is check to see if this is a spurious interrupt.
To perform the check, we read the ISR register of the PIC and check the bit 7 of the value.
If bit 7 is set, then this is a regular interrupt and we will handle it as we did with other interrupts.
If the bit 7 is 0, this is a spurious interrupt and we simply return without sending the end of interrupt
.
To read the ISR register,
we write a value to command register.
The bit 0 to 1 specify reading IRR or ISR registers. 11 means reading ISR register.
Bit 3 is set to 1 meaning that this is the command which reads the ISR register
.
So we move
11 to al and write it to the command register of the master chip.
Then we read the data from the command register using in instruction.
Now the value of ISR register is in the al register.
we test the bit 7 to see if it is 0.
We use jz instruction,
if bit 7 is 0, we will jump to end and return. here we use local label which starts with a dot.
And we define the local label end.
If the bit 7 is 1, then this is a regular interrupt. We need to send end of interrupt to the chip
just as we did in the last video.
So we move 20 to al and write the value to the command register.
OK, we are done. Because the spurious interrupt does not always occur, we don't test it in this video
.