Interrupt Window
My question is, why do you need to inhibit interrupts during the following assembly sequence? Won't the interrupt just save all the registers and bring them back after it is done, so there is no loss of data?
cli
inb (%d开发者_如何学Cx), %al
orb $0x01, %al
outb %al, (%dx)
sti
Won't the interrupt just save all the registers and bring them back after it is done, so there is no loss of data?
Yes, it would. However, some I/O ports are time-sensitive and might not work properly if read/write sequence is interrupted. Or the interrupt affects the port somehow (e.g. you're reading the UART register and a character arrives, triggering the serial interrupt and changing the UART state). Or you could be writing to a port which is itself related to interrupt handling (e.g. the interrupt controller). It's hard to say if it's really necessary without more details, but in general it's better to be safe than sorry.
In this particular case you are reading a value from a port, changing one bit, and writing it out again. To work as a read-modify-write cycle the code has to be uninterrupted.
Otherwise, if another interrupt happens during this sequence, and changes another bit, you would overwrite that change when continuing. Not good!
精彩评论