You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "realmode.h"
  2. #include "timer.h"
  3. #include "latch.h"
  4. #include "bios.h"
  5. #define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
  6. #define K_STATUS 0x64 /* keyboard status */
  7. #define K_CMD 0x64 /* keybd ctlr command (write-only) */
  8. #define K_OBUF_FUL 0x01 /* output buffer full */
  9. #define K_IBUF_FUL 0x02 /* input buffer full */
  10. #define KC_CMD_WIN 0xd0 /* read output port */
  11. #define KC_CMD_WOUT 0xd1 /* write output port */
  12. #define KB_SET_A20 0xdf /* enable A20,
  13. enable output buffer full interrupt
  14. enable data line
  15. disable clock line */
  16. #define KB_UNSET_A20 0xdd /* enable A20,
  17. enable output buffer full interrupt
  18. enable data line
  19. disable clock line */
  20. enum { Disable_A20 = 0x2400, Enable_A20 = 0x2401, Query_A20_Status = 0x2402,
  21. Query_A20_Support = 0x2403 };
  22. #define CF ( 1 << 0 )
  23. #ifndef IBM_L40
  24. static void empty_8042 ( void )
  25. {
  26. unsigned long time;
  27. char st;
  28. time = currticks() + TICKS_PER_SEC; /* max wait of 1 second */
  29. while ((((st = inb(K_CMD)) & K_OBUF_FUL) ||
  30. (st & K_IBUF_FUL)) &&
  31. currticks() < time)
  32. inb(K_RDWR);
  33. }
  34. #endif /* IBM_L40 */
  35. /*
  36. * Gate A20 for high memory
  37. *
  38. * Note that this function gets called as part of the return path from
  39. * librm's real_call, which is used to make the int15 call if librm is
  40. * being used. To avoid an infinite recursion, we make gateA20_set
  41. * return immediately if it is already part of the call stack.
  42. */
  43. void gateA20_set ( void ) {
  44. static char reentry_guard = 0;
  45. uint16_t flags, status;
  46. if ( reentry_guard )
  47. return;
  48. reentry_guard = 1;
  49. REAL_EXEC ( rm_enableA20,
  50. "sti\n\t"
  51. "stc\n\t"
  52. "int $0x15\n\t"
  53. "pushfw\n\t"
  54. "popw %%bx\n\t"
  55. "cli\n\t",
  56. 2,
  57. OUT_CONSTRAINTS ( "=a" ( status ), "=b" ( flags ) ),
  58. IN_CONSTRAINTS ( "a" ( Enable_A20 ) ),
  59. CLOBBER ( "ecx", "edx", "ebp", "esi", "edi" ) );
  60. if ( ( flags & CF ) ||
  61. ( ( status >> 8 ) & 0xff ) ) {
  62. /* INT 15 method failed, try alternatives */
  63. #ifdef IBM_L40
  64. outb(0x2, 0x92);
  65. #else /* IBM_L40 */
  66. empty_8042();
  67. outb(KC_CMD_WOUT, K_CMD);
  68. empty_8042();
  69. outb(KB_SET_A20, K_RDWR);
  70. empty_8042();
  71. #endif /* IBM_L40 */
  72. }
  73. reentry_guard = 0;
  74. }
  75. void gateA20_unset ( void ) {
  76. /* Not currently implemented */
  77. }