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.

gateA20.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. unsigned int discard_a;
  46. unsigned int flags;
  47. if ( reentry_guard )
  48. return;
  49. reentry_guard = 1;
  50. __asm__ __volatile__ ( REAL_CODE ( "sti\n\t"
  51. "stc\n\t"
  52. "int $0x15\n\t"
  53. "pushfw\n\t"
  54. "popw %w0\n\t"
  55. "cli\n\t" )
  56. : "=r" ( flags ), "=a" ( discard_a )
  57. : "a" ( Enable_A20 ) );
  58. if ( flags & CF ) {
  59. /* INT 15 method failed, try alternatives */
  60. #ifdef IBM_L40
  61. outb(0x2, 0x92);
  62. #else /* IBM_L40 */
  63. empty_8042();
  64. outb(KC_CMD_WOUT, K_CMD);
  65. empty_8042();
  66. outb(KB_SET_A20, K_RDWR);
  67. empty_8042();
  68. #endif /* IBM_L40 */
  69. }
  70. reentry_guard = 0;
  71. }
  72. void gateA20_unset ( void ) {
  73. /* Not currently implemented */
  74. }