drain.c 576 B

1234567891011121314151617181920212223242526
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <errno.h>
  4. #include <string.h>
  5. #include <sys/cpu.h>
  6. void drain_keyboard(void)
  7. {
  8. /* Prevent "ghost typing" and keyboard buffer snooping */
  9. volatile char junk;
  10. int rv;
  11. do {
  12. rv = read(0, (char *)&junk, 1);
  13. } while (rv > 0);
  14. junk = 0;
  15. cli();
  16. *(volatile uint8_t *)0x419 = 0; /* Alt-XXX keyboard area */
  17. *(volatile uint16_t *)0x41a = 0x1e; /* Keyboard buffer empty */
  18. *(volatile uint16_t *)0x41c = 0x1e;
  19. memset((void *)0x41e, 0, 32); /* Clear the actual keyboard buffer */
  20. sti();
  21. }