ps2.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/dl.h>
  19. #include <grub/misc.h>
  20. #include <grub/term.h>
  21. #include <grub/keyboard_layouts.h>
  22. #include <grub/ps2.h>
  23. #define KEYBOARD_LED_SCROLL (1 << 0)
  24. #define KEYBOARD_LED_NUM (1 << 1)
  25. #define KEYBOARD_LED_CAPS (1 << 2)
  26. static const grub_uint8_t set1_mapping[128] =
  27. {
  28. /* 0x00 */ 0 /* Unused */, GRUB_KEYBOARD_KEY_ESCAPE,
  29. /* 0x02 */ GRUB_KEYBOARD_KEY_1, GRUB_KEYBOARD_KEY_2,
  30. /* 0x04 */ GRUB_KEYBOARD_KEY_3, GRUB_KEYBOARD_KEY_4,
  31. /* 0x06 */ GRUB_KEYBOARD_KEY_5, GRUB_KEYBOARD_KEY_6,
  32. /* 0x08 */ GRUB_KEYBOARD_KEY_7, GRUB_KEYBOARD_KEY_8,
  33. /* 0x0a */ GRUB_KEYBOARD_KEY_9, GRUB_KEYBOARD_KEY_0,
  34. /* 0x0c */ GRUB_KEYBOARD_KEY_DASH, GRUB_KEYBOARD_KEY_EQUAL,
  35. /* 0x0e */ GRUB_KEYBOARD_KEY_BACKSPACE, GRUB_KEYBOARD_KEY_TAB,
  36. /* 0x10 */ GRUB_KEYBOARD_KEY_Q, GRUB_KEYBOARD_KEY_W,
  37. /* 0x12 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_R,
  38. /* 0x14 */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_Y,
  39. /* 0x16 */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_I,
  40. /* 0x18 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_P,
  41. /* 0x1a */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_RBRACKET,
  42. /* 0x1c */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_LEFT_CTRL,
  43. /* 0x1e */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_S,
  44. /* 0x20 */ GRUB_KEYBOARD_KEY_D, GRUB_KEYBOARD_KEY_F,
  45. /* 0x22 */ GRUB_KEYBOARD_KEY_G, GRUB_KEYBOARD_KEY_H,
  46. /* 0x24 */ GRUB_KEYBOARD_KEY_J, GRUB_KEYBOARD_KEY_K,
  47. /* 0x26 */ GRUB_KEYBOARD_KEY_L, GRUB_KEYBOARD_KEY_SEMICOLON,
  48. /* 0x28 */ GRUB_KEYBOARD_KEY_DQUOTE, GRUB_KEYBOARD_KEY_RQUOTE,
  49. /* 0x2a */ GRUB_KEYBOARD_KEY_LEFT_SHIFT, GRUB_KEYBOARD_KEY_BACKSLASH,
  50. /* 0x2c */ GRUB_KEYBOARD_KEY_Z, GRUB_KEYBOARD_KEY_X,
  51. /* 0x2e */ GRUB_KEYBOARD_KEY_C, GRUB_KEYBOARD_KEY_V,
  52. /* 0x30 */ GRUB_KEYBOARD_KEY_B, GRUB_KEYBOARD_KEY_N,
  53. /* 0x32 */ GRUB_KEYBOARD_KEY_M, GRUB_KEYBOARD_KEY_COMMA,
  54. /* 0x34 */ GRUB_KEYBOARD_KEY_DOT, GRUB_KEYBOARD_KEY_SLASH,
  55. /* 0x36 */ GRUB_KEYBOARD_KEY_RIGHT_SHIFT, GRUB_KEYBOARD_KEY_NUMMUL,
  56. /* 0x38 */ GRUB_KEYBOARD_KEY_LEFT_ALT, GRUB_KEYBOARD_KEY_SPACE,
  57. /* 0x3a */ GRUB_KEYBOARD_KEY_CAPS_LOCK, GRUB_KEYBOARD_KEY_F1,
  58. /* 0x3c */ GRUB_KEYBOARD_KEY_F2, GRUB_KEYBOARD_KEY_F3,
  59. /* 0x3e */ GRUB_KEYBOARD_KEY_F4, GRUB_KEYBOARD_KEY_F5,
  60. /* 0x40 */ GRUB_KEYBOARD_KEY_F6, GRUB_KEYBOARD_KEY_F7,
  61. /* 0x42 */ GRUB_KEYBOARD_KEY_F8, GRUB_KEYBOARD_KEY_F9,
  62. /* 0x44 */ GRUB_KEYBOARD_KEY_F10, GRUB_KEYBOARD_KEY_NUM_LOCK,
  63. /* 0x46 */ GRUB_KEYBOARD_KEY_SCROLL_LOCK, GRUB_KEYBOARD_KEY_NUM7,
  64. /* 0x48 */ GRUB_KEYBOARD_KEY_NUM8, GRUB_KEYBOARD_KEY_NUM9,
  65. /* 0x4a */ GRUB_KEYBOARD_KEY_NUMMINUS, GRUB_KEYBOARD_KEY_NUM4,
  66. /* 0x4c */ GRUB_KEYBOARD_KEY_NUM5, GRUB_KEYBOARD_KEY_NUM6,
  67. /* 0x4e */ GRUB_KEYBOARD_KEY_NUMPLUS, GRUB_KEYBOARD_KEY_NUM1,
  68. /* 0x50 */ GRUB_KEYBOARD_KEY_NUM2, GRUB_KEYBOARD_KEY_NUM3,
  69. /* 0x52 */ GRUB_KEYBOARD_KEY_NUM0, GRUB_KEYBOARD_KEY_NUMDOT,
  70. /* 0x54 */ 0, 0,
  71. /* 0x56 */ GRUB_KEYBOARD_KEY_102ND, GRUB_KEYBOARD_KEY_F11,
  72. /* 0x58 */ GRUB_KEYBOARD_KEY_F12, 0,
  73. /* 0x5a */ 0, 0,
  74. /* 0x5c */ 0, 0,
  75. /* 0x5e */ 0, 0,
  76. /* 0x60 */ 0, 0,
  77. /* 0x62 */ 0, 0,
  78. /* OLPC keys. Just mapped to normal keys. */
  79. /* 0x64 */ 0, GRUB_KEYBOARD_KEY_UP,
  80. /* 0x66 */ GRUB_KEYBOARD_KEY_DOWN, GRUB_KEYBOARD_KEY_LEFT,
  81. /* 0x68 */ GRUB_KEYBOARD_KEY_RIGHT, 0,
  82. /* 0x6a */ 0, 0,
  83. /* 0x6c */ 0, 0,
  84. /* 0x6e */ 0, 0,
  85. /* 0x70 */ 0, 0,
  86. /* 0x72 */ 0, GRUB_KEYBOARD_KEY_JP_RO,
  87. /* 0x74 */ 0, 0,
  88. /* 0x76 */ 0, 0,
  89. /* 0x78 */ 0, 0,
  90. /* 0x7a */ 0, 0,
  91. /* 0x7c */ 0, GRUB_KEYBOARD_KEY_JP_YEN,
  92. /* 0x7e */ GRUB_KEYBOARD_KEY_KPCOMMA
  93. };
  94. static const struct
  95. {
  96. grub_uint8_t from, to;
  97. } set1_e0_mapping[] =
  98. {
  99. {0x1c, GRUB_KEYBOARD_KEY_NUMENTER},
  100. {0x1d, GRUB_KEYBOARD_KEY_RIGHT_CTRL},
  101. {0x35, GRUB_KEYBOARD_KEY_NUMSLASH },
  102. {0x38, GRUB_KEYBOARD_KEY_RIGHT_ALT},
  103. {0x47, GRUB_KEYBOARD_KEY_HOME},
  104. {0x48, GRUB_KEYBOARD_KEY_UP},
  105. {0x49, GRUB_KEYBOARD_KEY_PPAGE},
  106. {0x4b, GRUB_KEYBOARD_KEY_LEFT},
  107. {0x4d, GRUB_KEYBOARD_KEY_RIGHT},
  108. {0x4f, GRUB_KEYBOARD_KEY_END},
  109. {0x50, GRUB_KEYBOARD_KEY_DOWN},
  110. {0x51, GRUB_KEYBOARD_KEY_NPAGE},
  111. {0x52, GRUB_KEYBOARD_KEY_INSERT},
  112. {0x53, GRUB_KEYBOARD_KEY_DELETE},
  113. };
  114. static const grub_uint8_t set2_mapping[256] =
  115. {
  116. /* 0x00 */ 0, GRUB_KEYBOARD_KEY_F9,
  117. /* 0x02 */ 0, GRUB_KEYBOARD_KEY_F5,
  118. /* 0x04 */ GRUB_KEYBOARD_KEY_F3, GRUB_KEYBOARD_KEY_F1,
  119. /* 0x06 */ GRUB_KEYBOARD_KEY_F2, GRUB_KEYBOARD_KEY_F12,
  120. /* 0x08 */ 0, GRUB_KEYBOARD_KEY_F10,
  121. /* 0x0a */ GRUB_KEYBOARD_KEY_F8, GRUB_KEYBOARD_KEY_F6,
  122. /* 0x0c */ GRUB_KEYBOARD_KEY_F4, GRUB_KEYBOARD_KEY_TAB,
  123. /* 0x0e */ GRUB_KEYBOARD_KEY_RQUOTE, 0,
  124. /* 0x10 */ 0, GRUB_KEYBOARD_KEY_LEFT_ALT,
  125. /* 0x12 */ GRUB_KEYBOARD_KEY_LEFT_SHIFT, 0,
  126. /* 0x14 */ GRUB_KEYBOARD_KEY_LEFT_CTRL, GRUB_KEYBOARD_KEY_Q,
  127. /* 0x16 */ GRUB_KEYBOARD_KEY_1, 0,
  128. /* 0x18 */ 0, 0,
  129. /* 0x1a */ GRUB_KEYBOARD_KEY_Z, GRUB_KEYBOARD_KEY_S,
  130. /* 0x1c */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_W,
  131. /* 0x1e */ GRUB_KEYBOARD_KEY_2, 0,
  132. /* 0x20 */ 0, GRUB_KEYBOARD_KEY_C,
  133. /* 0x22 */ GRUB_KEYBOARD_KEY_X, GRUB_KEYBOARD_KEY_D,
  134. /* 0x24 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_4,
  135. /* 0x26 */ GRUB_KEYBOARD_KEY_3, 0,
  136. /* 0x28 */ 0, GRUB_KEYBOARD_KEY_SPACE,
  137. /* 0x2a */ GRUB_KEYBOARD_KEY_V, GRUB_KEYBOARD_KEY_F,
  138. /* 0x2c */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_R,
  139. /* 0x2e */ GRUB_KEYBOARD_KEY_5, 0,
  140. /* 0x30 */ 0, GRUB_KEYBOARD_KEY_N,
  141. /* 0x32 */ GRUB_KEYBOARD_KEY_B, GRUB_KEYBOARD_KEY_H,
  142. /* 0x34 */ GRUB_KEYBOARD_KEY_G, GRUB_KEYBOARD_KEY_Y,
  143. /* 0x36 */ GRUB_KEYBOARD_KEY_6, 0,
  144. /* 0x38 */ 0, 0,
  145. /* 0x3a */ GRUB_KEYBOARD_KEY_M, GRUB_KEYBOARD_KEY_J,
  146. /* 0x3c */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_7,
  147. /* 0x3e */ GRUB_KEYBOARD_KEY_8, 0,
  148. /* 0x40 */ 0, GRUB_KEYBOARD_KEY_COMMA,
  149. /* 0x42 */ GRUB_KEYBOARD_KEY_K, GRUB_KEYBOARD_KEY_I,
  150. /* 0x44 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_0,
  151. /* 0x46 */ GRUB_KEYBOARD_KEY_9, 0,
  152. /* 0x48 */ 0, GRUB_KEYBOARD_KEY_DOT,
  153. /* 0x4a */ GRUB_KEYBOARD_KEY_SLASH, GRUB_KEYBOARD_KEY_L,
  154. /* 0x4c */ GRUB_KEYBOARD_KEY_SEMICOLON, GRUB_KEYBOARD_KEY_P,
  155. /* 0x4e */ GRUB_KEYBOARD_KEY_DASH, 0,
  156. /* 0x50 */ 0, GRUB_KEYBOARD_KEY_JP_RO,
  157. /* 0x52 */ GRUB_KEYBOARD_KEY_DQUOTE, 0,
  158. /* 0x54 */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_EQUAL,
  159. /* 0x56 */ 0, 0,
  160. /* 0x58 */ GRUB_KEYBOARD_KEY_CAPS_LOCK, GRUB_KEYBOARD_KEY_RIGHT_SHIFT,
  161. /* 0x5a */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_RBRACKET,
  162. /* 0x5c */ 0, GRUB_KEYBOARD_KEY_BACKSLASH,
  163. /* 0x5e */ 0, 0,
  164. /* 0x60 */ 0, GRUB_KEYBOARD_KEY_102ND,
  165. /* 0x62 */ 0, 0,
  166. /* 0x64 */ 0, 0,
  167. /* 0x66 */ GRUB_KEYBOARD_KEY_BACKSPACE, 0,
  168. /* 0x68 */ 0, GRUB_KEYBOARD_KEY_NUM1,
  169. /* 0x6a */ GRUB_KEYBOARD_KEY_JP_YEN, GRUB_KEYBOARD_KEY_NUM4,
  170. /* 0x6c */ GRUB_KEYBOARD_KEY_NUM7, GRUB_KEYBOARD_KEY_KPCOMMA,
  171. /* 0x6e */ 0, 0,
  172. /* 0x70 */ GRUB_KEYBOARD_KEY_NUM0, GRUB_KEYBOARD_KEY_NUMDOT,
  173. /* 0x72 */ GRUB_KEYBOARD_KEY_NUM2, GRUB_KEYBOARD_KEY_NUM5,
  174. /* 0x74 */ GRUB_KEYBOARD_KEY_NUM6, GRUB_KEYBOARD_KEY_NUM8,
  175. /* 0x76 */ GRUB_KEYBOARD_KEY_ESCAPE, GRUB_KEYBOARD_KEY_NUM_LOCK,
  176. /* 0x78 */ GRUB_KEYBOARD_KEY_F11, GRUB_KEYBOARD_KEY_NUMPLUS,
  177. /* 0x7a */ GRUB_KEYBOARD_KEY_NUM3, GRUB_KEYBOARD_KEY_NUMMINUS,
  178. /* 0x7c */ GRUB_KEYBOARD_KEY_NUMMUL, GRUB_KEYBOARD_KEY_NUM9,
  179. /* 0x7e */ GRUB_KEYBOARD_KEY_SCROLL_LOCK, 0,
  180. /* 0x80 */ 0, 0,
  181. /* 0x82 */ 0, GRUB_KEYBOARD_KEY_F7,
  182. };
  183. static const struct
  184. {
  185. grub_uint8_t from, to;
  186. } set2_e0_mapping[] =
  187. {
  188. {0x11, GRUB_KEYBOARD_KEY_RIGHT_ALT},
  189. {0x14, GRUB_KEYBOARD_KEY_RIGHT_CTRL},
  190. {0x4a, GRUB_KEYBOARD_KEY_NUMSLASH},
  191. {0x5a, GRUB_KEYBOARD_KEY_NUMENTER},
  192. {0x69, GRUB_KEYBOARD_KEY_END},
  193. {0x6b, GRUB_KEYBOARD_KEY_LEFT},
  194. {0x6c, GRUB_KEYBOARD_KEY_HOME},
  195. {0x70, GRUB_KEYBOARD_KEY_INSERT},
  196. {0x71, GRUB_KEYBOARD_KEY_DELETE},
  197. {0x72, GRUB_KEYBOARD_KEY_DOWN},
  198. {0x74, GRUB_KEYBOARD_KEY_RIGHT},
  199. {0x75, GRUB_KEYBOARD_KEY_UP},
  200. {0x7a, GRUB_KEYBOARD_KEY_NPAGE},
  201. {0x7d, GRUB_KEYBOARD_KEY_PPAGE},
  202. };
  203. static int
  204. fetch_key (struct grub_ps2_state *ps2_state, grub_uint8_t at_key, int *is_break)
  205. {
  206. int was_ext = 0;
  207. int ret = 0;
  208. /* May happen if no keyboard is connected. Just ignore this. */
  209. if (at_key == 0xff)
  210. return -1;
  211. if (at_key == 0xe0)
  212. {
  213. ps2_state->e0_received = 1;
  214. return -1;
  215. }
  216. if ((ps2_state->current_set == 2 || ps2_state->current_set == 3) && at_key == 0xf0)
  217. {
  218. ps2_state->f0_received = 1;
  219. return -1;
  220. }
  221. /* Setting LEDs may generate ACKs. */
  222. if (at_key == GRUB_AT_ACK)
  223. return -1;
  224. was_ext = ps2_state->e0_received;
  225. ps2_state->e0_received = 0;
  226. switch (ps2_state->current_set)
  227. {
  228. case 1:
  229. *is_break = !!(at_key & 0x80);
  230. if (!was_ext)
  231. ret = set1_mapping[at_key & 0x7f];
  232. else
  233. {
  234. unsigned i;
  235. for (i = 0; i < ARRAY_SIZE (set1_e0_mapping); i++)
  236. if (set1_e0_mapping[i].from == (at_key & 0x7f))
  237. {
  238. ret = set1_e0_mapping[i].to;
  239. break;
  240. }
  241. }
  242. break;
  243. case 2:
  244. *is_break = ps2_state->f0_received;
  245. ps2_state->f0_received = 0;
  246. if (!was_ext)
  247. ret = set2_mapping[at_key];
  248. else
  249. {
  250. unsigned i;
  251. for (i = 0; i < ARRAY_SIZE (set2_e0_mapping); i++)
  252. if (set2_e0_mapping[i].from == at_key)
  253. {
  254. ret = set2_e0_mapping[i].to;
  255. break;
  256. }
  257. }
  258. break;
  259. default:
  260. return -1;
  261. }
  262. if (!ret)
  263. {
  264. if (was_ext)
  265. grub_dprintf ("atkeyb", "Unknown key 0xe0+0x%02x from set %d\n",
  266. at_key, ps2_state->current_set);
  267. else
  268. grub_dprintf ("atkeyb", "Unknown key 0x%02x from set %d\n",
  269. at_key, ps2_state->current_set);
  270. return -1;
  271. }
  272. return ret;
  273. }
  274. /* FIXME: This should become an interrupt service routine. For now
  275. it's just used to catch events from control keys. */
  276. static int
  277. grub_keyboard_isr (struct grub_ps2_state *ps2_state,
  278. grub_keyboard_key_t key, int is_break)
  279. {
  280. if (!is_break)
  281. switch (key)
  282. {
  283. case GRUB_KEYBOARD_KEY_LEFT_SHIFT:
  284. ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_LSHIFT;
  285. return 1;
  286. case GRUB_KEYBOARD_KEY_RIGHT_SHIFT:
  287. ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_RSHIFT;
  288. return 1;
  289. case GRUB_KEYBOARD_KEY_LEFT_CTRL:
  290. ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_LCTRL;
  291. return 1;
  292. case GRUB_KEYBOARD_KEY_RIGHT_CTRL:
  293. ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_RCTRL;
  294. return 1;
  295. case GRUB_KEYBOARD_KEY_RIGHT_ALT:
  296. ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_RALT;
  297. return 1;
  298. case GRUB_KEYBOARD_KEY_LEFT_ALT:
  299. ps2_state->at_keyboard_status |= GRUB_TERM_STATUS_LALT;
  300. return 1;
  301. default:
  302. return 0;
  303. }
  304. else
  305. switch (key)
  306. {
  307. case GRUB_KEYBOARD_KEY_LEFT_SHIFT:
  308. ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_LSHIFT;
  309. return 1;
  310. case GRUB_KEYBOARD_KEY_RIGHT_SHIFT:
  311. ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_RSHIFT;
  312. return 1;
  313. case GRUB_KEYBOARD_KEY_LEFT_CTRL:
  314. ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_LCTRL;
  315. return 1;
  316. case GRUB_KEYBOARD_KEY_RIGHT_CTRL:
  317. ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_RCTRL;
  318. return 1;
  319. case GRUB_KEYBOARD_KEY_RIGHT_ALT:
  320. ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_RALT;
  321. return 1;
  322. case GRUB_KEYBOARD_KEY_LEFT_ALT:
  323. ps2_state->at_keyboard_status &= ~GRUB_TERM_STATUS_LALT;
  324. return 1;
  325. default:
  326. return 0;
  327. }
  328. }
  329. /* If there is a key pending, return it; otherwise return GRUB_TERM_NO_KEY. */
  330. int
  331. grub_ps2_process_incoming_byte (struct grub_ps2_state *ps2_state,
  332. grub_uint8_t at_key)
  333. {
  334. int code;
  335. int is_break = 0;
  336. code = fetch_key (ps2_state, at_key, &is_break);
  337. if (code == -1)
  338. return GRUB_TERM_NO_KEY;
  339. if (grub_keyboard_isr (ps2_state, code, is_break))
  340. return GRUB_TERM_NO_KEY;
  341. if (is_break)
  342. return GRUB_TERM_NO_KEY;
  343. #ifdef DEBUG_AT_KEYBOARD
  344. grub_dprintf ("atkeyb", "Detected key 0x%x\n", code);
  345. #endif
  346. switch (code)
  347. {
  348. case GRUB_KEYBOARD_KEY_CAPS_LOCK:
  349. ps2_state->at_keyboard_status ^= GRUB_TERM_STATUS_CAPS;
  350. ps2_state->led_status ^= KEYBOARD_LED_CAPS;
  351. #ifdef DEBUG_AT_KEYBOARD
  352. grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(ps2_state->at_keyboard_status & GRUB_KEYBOARD_STATUS_CAPS_LOCK));
  353. #endif
  354. return GRUB_TERM_NO_KEY;
  355. case GRUB_KEYBOARD_KEY_NUM_LOCK:
  356. ps2_state->at_keyboard_status ^= GRUB_TERM_STATUS_NUM;
  357. ps2_state->led_status ^= KEYBOARD_LED_NUM;
  358. #ifdef DEBUG_AT_KEYBOARD
  359. grub_dprintf ("atkeyb", "num_lock = %d\n", !!(ps2_state->at_keyboard_status & GRUB_KEYBOARD_STATUS_NUM_LOCK));
  360. #endif
  361. return GRUB_TERM_NO_KEY;
  362. case GRUB_KEYBOARD_KEY_SCROLL_LOCK:
  363. ps2_state->at_keyboard_status ^= GRUB_TERM_STATUS_SCROLL;
  364. ps2_state->led_status ^= KEYBOARD_LED_SCROLL;
  365. return GRUB_TERM_NO_KEY;
  366. default:
  367. return grub_term_map_key (code, ps2_state->at_keyboard_status);
  368. }
  369. }