blob: 91b18fef5e05f21315b6a22127c0635e14ae6d73 [file] [log] [blame]
Kevin O'Connore0113c92008-04-05 15:51:12 -04001// Menu presented during final phase of "post".
2//
3// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4// Copyright (C) 2002 MandrakeSoft S.A.
5//
6// This file may be distributed under the terms of the GNU GPLv3 license.
7
8#include "biosvar.h" // GET_EBDA
9#include "util.h" // usleep
10
11static u8
12check_for_keystroke()
13{
14 struct bregs br;
15 memset(&br, 0, sizeof(br));
16 br.ah = 1;
17 call16_int(0x16, &br);
18 return !(br.flags & F_ZF);
19}
20
21static u8
22get_keystroke()
23{
24 struct bregs br;
25 memset(&br, 0, sizeof(br));
26 call16_int(0x16, &br);
27 return br.ah;
28}
29
30static void
31udelay_and_check_for_keystroke(u32 usec, int count)
32{
33 int i;
34 for (i = 1; i <= count; i++) {
35 usleep(usec);
36 if (check_for_keystroke())
37 break;
38 }
39}
40
41void
42interactive_bootmenu()
43{
44 while (check_for_keystroke())
45 get_keystroke();
46
47 printf("Press F12 for boot menu.\n\n");
48
49 udelay_and_check_for_keystroke(500000, 5);
50 if (! check_for_keystroke())
51 return;
52 u8 scan_code = get_keystroke();
53 if (scan_code != 0x58)
54 /* not F12 */
55 return;
56
57 while (check_for_keystroke())
58 get_keystroke();
59
60 printf("Select boot device:\n\n");
61
62 int count = GET_EBDA(ipl.count);
63 int i;
64 for (i = 0; i < count; i++) {
65 printf("%d. ", i+1);
66 printf_bootdev(i);
67 printf("\n");
68 }
69
70 for (;;) {
71 scan_code = get_keystroke();
72 if (scan_code == 0x01 || scan_code == 0x58)
73 /* ESC or F12 */
74 break;
75 if (scan_code <= count + 1) {
76 SET_EBDA(ipl.bootfirst, scan_code - 1);
77 break;
78 }
79 }
80 printf("\n");
81}