0

《Operating systems design and oragnization》3rd, page 351. The keyboard interrupt service routine is kbd_interrupt (line 15335), called whenever a key is pressed or released. It calls scode to get the scan code from the keyboard controller chip. ... all raw scan codes are placed in the circular buffer and the tp->tty _events flag for the current console is raised (line 15350). ...and that kbd_interrupt returns immediately after this. ... A continue statement at line 13795 causes a new iteration of the main loop to begin immediately, at line 13764. When execution transfers to the top of the loop the tp->tty _events flag for the console device is now found to be set, and kb _read (line 15360), the device-specific routine, is called using the pointer in the tp->tty _devread field of the console's tty structure. Kb_read takes scan codes from the keyboard's circular buffer and places ASCII codes in its local buffer.

I think the ibuf cann't have more than one scan code. so I think a char variable is enough. Why does the circular ibuf exist?

ling
  • 11

1 Answers1

1

My question to you would have to be: why do you think you can only have one scan code in the buffer at a time?

Interrupts are very similar to threaded code in that you don't know what order the bits of code will execute in. This particular interrupt will be fired whenever a key is pressed, independent of what other code may or may not be doing at the time (assuming interrupts haven't been disabled of course).

It's quite possible that you may get two interrupts in quick succession before a scan code can be extracted from the buffer.

The Minix3 source code allows for a 32-byte buffer which is considered big enough to handle the possibility of keys being pressed faster than they can be extracted. If the buffer fills up, subsequent key-presses are lost (the keyboard hardware is strobed to extract the keycode but it is not added to the buffer).

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • In minix 3, kernel change the interrupt to a HARD_INT message, terminal driver process the interrupt as a message. – ling Apr 23 '13 at 09:15