* [PATCH] Add support for a basic boot menu to the bios
@ 2007-09-12 19:55 Jeremy Katz
[not found] ` <1189626953.16586.6.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
0 siblings, 1 reply; 9+ messages in thread
From: Jeremy Katz @ 2007-09-12 19:55 UTC (permalink / raw)
To: kvm-devel
[-- Attachment #1: Type: text/plain, Size: 952 bytes --]
I sent this to the bochs list earlier today, but given that kvm is
already carrying patches for the BIOS, it may be worthwhile/interesting
to add this also as it can make the user experience substantially nicer.
-- Begin forwarded message --
The attached patch adds support for a relatively basic boot device
selection menu to the bochs bios code.
Instead of immediately booting from the boot device set in the cmos, we
wait for 3 seconds for the user to press F10; if they press it, then we
show a basic boot menu that they can select what device to boot from.
Otherwise, we continue on with what was setup before running the virtual
machine. The advantage is that users can change their boot device just
on rebooting a virtual machine rather than having to stop and then
restart it.
This includes the wait routines added by VirtualBox
(http://www.virtualbox.org) in their modifications to the rombios as
they made things a bit easier.
Jeremy
[-- Attachment #2: bochs-boot-menu.patch --]
[-- Type: text/x-patch, Size: 6630 bytes --]
Index: rombios.c
===================================================================
RCS file: /cvsroot/bochs/bochs/bios/rombios.c,v
retrieving revision 1.182
diff -u -u -r1.182 rombios.c
--- rombios.c 1 Aug 2007 17:09:51 -0000 1.182
+++ rombios.c 11 Sep 2007 15:10:53 -0000
@@ -1950,6 +1950,289 @@
return;
}
+#define WAIT_HZ 64
+/**
+ * Check for keystroke.
+ * @returns True if keystroke available, False if not.
+ */
+Bit8u check_for_keystroke()
+{
+ASM_START
+ mov ax, #0x100
+ int #0x16
+ jz no_key
+ mov al, #1
+ jmp done
+no_key:
+ xor al, al
+done:
+ASM_END
+}
+
+/**
+ * Get keystroke.
+ * @returns BIOS scan code.
+ */
+Bit8u get_keystroke()
+{
+ASM_START
+ mov ax, #0x0
+ int #0x16
+ xchg ah, al
+ASM_END
+}
+
+/**
+ * Waits (sleeps) for the given number of ticks.
+ * Checks for keystroke.
+ *
+ * @returns BIOS scan code if available, 0 if not.
+ * @param ticks Number of ticks to sleep.
+ * @param stop_on_key Whether to stop immediately upon keypress.
+ */
+Bit8u wait(ticks, stop_on_key)
+ Bit16u ticks;
+ Bit8u stop_on_key;
+{
+ long ticks_to_wait, delta;
+ Bit32u prev_ticks, t;
+ Bit8u scan_code = 0;
+
+ /*
+ * The 0:046c wraps around at 'midnight' according to a 18.2Hz clock.
+ * We also have to be careful about interrupt storms.
+ */
+ASM_START
+ pushf
+ sti
+ASM_END
+ ticks_to_wait = ticks;
+ prev_ticks = read_dword(0x0, 0x46c);
+ do
+ {
+ASM_START
+ hlt
+ASM_END
+ t = read_dword(0x0, 0x46c);
+ if (t > prev_ticks)
+ {
+ delta = t - prev_ticks; /* The temp var is required or bcc screws up. */
+ ticks_to_wait -= delta;
+ }
+ else if (t < prev_ticks)
+ ticks_to_wait -= t; /* wrapped */
+ prev_ticks = t;
+
+ if (check_for_keystroke())
+ {
+ scan_code = get_keystroke();
+ bios_printf(BIOS_PRINTF_DEBUG, "Key pressed: %x\n", scan_code);
+ if (stop_on_key)
+ return scan_code;
+ }
+ } while (ticks_to_wait > 0);
+ASM_START
+ popf
+ASM_END
+ return scan_code;
+}
+
+void wait_init()
+{
+ /* The default is 18.2 ticks per second (~55ms tick interval).
+ Set the timer to 16ms ticks (64K / (Hz / (PIT_HZ / 64K)) = count).
+ 0x10000 / (1000 / (1193182 / 0x10000)) = 1193 (0x04a9)
+ 0x10000 / ( 128 / (1193182 / 0x10000)) = 9321 (0x2469)
+ 0x10000 / ( 64 / (1193182 / 0x10000)) = 18643 (0x48d3) */
+ASM_START
+ mov al, #0x34 ; timer0: binary count, 16bit count, mode 2
+ out 0x43, al
+ mov al, #0xd3 ; Low byte - 64Hz
+ out 0x40, al
+ mov al, #0x48 ; High byte - 64Hz
+ out 0x40, al
+ASM_END
+}
+
+void wait_uninit()
+{
+ASM_START
+ pushf
+ cli
+
+ /* Restore the timer to the default 18.2Hz. */
+ mov al, #0x34 ; timer0: binary count, 16bit count, mode 2
+ out 0x43, al
+ xor ax, ax ; maximum count of 0000H = 18.2Hz
+ out 0x40, al
+ out 0x40, al
+
+ /*
+ * Reinitialize the tick and rollover counts since we've
+ * screwed them up by running the timer at WAIT_HZ for a while.
+ */
+ pushad
+ push ds
+ mov ds, ax ; already 0
+ call timer_tick_post
+ pop ds
+ popad
+
+ popf
+ASM_END
+}
+
+static void clearscreen() {
+ /* Hide cursor, clear screen and move cursor to starting position */
+ASM_START
+ push bx
+ push cx
+ push dx
+
+ mov ax, #0x100
+ mov cx, #0x1000
+ int #0x10
+
+ mov ax, #0x700
+ mov bh, #7
+ xor cx, cx
+ mov dx, #0x184f
+ int #0x10
+
+ mov ax, #0x200
+ xor bx, bx
+ xor dx, dx
+ int #0x10
+
+ pop dx
+ pop cx
+ pop bx
+ASM_END
+}
+
+int bootmenu(selected)
+ int selected;
+{
+ Bit8u scode;
+ int max;
+
+ /* get the number of boot devices */
+ max = read_word(IPL_SEG, IPL_COUNT_OFFSET);
+
+ for(;;) {
+ clearscreen();
+ printf("\n\n\n\n\n\n\n");
+ printf(" Select boot device\n\n");
+ printf(" 1. Floppy\n");
+ printf(" 2. Hard drive\n");
+ printf(" 3. CD-ROM\n");
+ if (max == 4)
+ printf(" 4. Network\n");
+ printf("\n\n Currently selected: %d\n", selected);
+
+ do {
+ scode = wait(WAIT_HZ, 1);
+ } while (scode == 0);
+ switch(scode) {
+ case 0x02:
+ case 0x03:
+ case 0x04:
+ selected = scode - 1;
+ break;
+ case 0x05:
+ if (max == 4)
+ selected = scode -1 ;
+ else
+ scode = 0;
+ break;
+ case 0x48:
+ selected -= 1;
+ if (selected < 1)
+ selected = 1;
+ scode = 0;
+ break;
+ case 0x50:
+ selected += 1;
+ if (selected > max)
+ selected = max;
+ scode = 0;
+ break;
+ case 0x1c:
+ break;
+ default:
+ scode = 0;
+ break;
+ }
+ if (scode != 0)
+ break;
+ }
+
+ switch (selected) {
+ case 1:
+ return 0x3D;
+ case 2:
+ return 0x3E;
+ case 3:
+ return 0x3F;
+ case 4:
+ return 0x58;
+ default:
+ return 0;
+ }
+}
+
+void interactive_bootkey()
+{
+ Bit16u i;
+ Bit8u scan = 0;
+
+ /* Set PIT to 1ms ticks */
+ wait_init();
+
+ printf("\n\nPress F10 to select boot device.\n");
+ for (i = 3; i > 0; i--)
+ {
+ scan = wait(WAIT_HZ, 0);
+ switch (scan) {
+ case 0x3D:
+ case 0x3E:
+ case 0x3F:
+ case 0x58:
+ break;
+ case 0x44:
+ scan = bootmenu(inb_cmos(0x3d));
+ break;
+ default:
+ scan = 0;
+ break;
+ }
+ if (scan != 0)
+ break;
+ }
+
+ /* set the default based on the keypress or menu */
+ switch(scan) {
+ case 0x3D:
+ outb_cmos(0x3d, 0x01);
+ break;
+ case 0x3E:
+ outb_cmos(0x3d, 0x02);
+ break;
+ case 0x3F:
+ outb_cmos(0x3d, 0x03);
+ break;
+ case 0x58:
+ outb_cmos(0x3d, 0x04);
+ break;
+ default:
+ break;
+ }
+
+ /* Restore PIT ticks */
+ wait_uninit();
+}
+
+
void
nmi_handler_msg()
{
@@ -10193,6 +10476,8 @@
;;
#endif // BX_ELTORITO_BOOT
+ call _interactive_bootkey
+
sti ;; enable interrupts
int #0x19
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 186 bytes --]
_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add support for a basic boot menu to the bios
[not found] ` <1189626953.16586.6.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2007-09-12 20:19 ` Anthony Liguori
[not found] ` <46E849DE.3040103-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2007-09-14 20:14 ` Anthony Liguori
2007-09-16 20:00 ` Avi Kivity
2 siblings, 1 reply; 9+ messages in thread
From: Anthony Liguori @ 2007-09-12 20:19 UTC (permalink / raw)
To: Jeremy Katz; +Cc: kvm-devel
Very cool!
My mailer doesn't want to quote your patch, but I noticed the following:
> +
> + /* set the default based on the keypress or menu */
> + switch(scan) {
> + case 0x3D:
> + outb_cmos(0x3d, 0x01);
> + break;
> + case 0x3E:
> + outb_cmos(0x3d, 0x02);
> + break;
> + case 0x3F:
> + outb_cmos(0x3d, 0x03);
> + break;
> + case 0x58:
> + outb_cmos(0x3d, 0x04);
> + break;
> + default:
> + break;
> + }
> +
> + /* Restore PIT ticks */
> + wait_uninit();
> +}
But the CMOS memory isn't persisted in QEMU. Another nice patch
(although certainly not required IMHO for this to go in), would be to
make nvram optionally persistent for QEMU so these settings would
persist across boots.
Regards,
Anthony Liguori
Jeremy Katz wrote:
> I sent this to the bochs list earlier today, but given that kvm is
> already carrying patches for the BIOS, it may be worthwhile/interesting
> to add this also as it can make the user experience substantially nicer.
>
> -- Begin forwarded message --
>
> The attached patch adds support for a relatively basic boot device
> selection menu to the bochs bios code.
>
> Instead of immediately booting from the boot device set in the cmos, we
> wait for 3 seconds for the user to press F10; if they press it, then we
> show a basic boot menu that they can select what device to boot from.
> Otherwise, we continue on with what was setup before running the virtual
> machine. The advantage is that users can change their boot device just
> on rebooting a virtual machine rather than having to stop and then
> restart it.
>
> This includes the wait routines added by VirtualBox
> (http://www.virtualbox.org) in their modifications to the rombios as
> they made things a bit easier.
>
> Jeremy
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> ------------------------------------------------------------------------
>
> _______________________________________________
> kvm-devel mailing list
> kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/kvm-devel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add support for a basic boot menu to the bios
[not found] ` <46E849DE.3040103-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
@ 2007-09-12 20:25 ` Jeremy Katz
0 siblings, 0 replies; 9+ messages in thread
From: Jeremy Katz @ 2007-09-12 20:25 UTC (permalink / raw)
To: Anthony Liguori; +Cc: kvm-devel
On Wed, 2007-09-12 at 15:19 -0500, Anthony Liguori wrote:
> Very cool!
Long-term itch of mine scratched :-)
> My mailer doesn't want to quote your patch, but I noticed the following:
>
> > +
> > + /* set the default based on the keypress or menu */
[snip]
> But the CMOS memory isn't persisted in QEMU. Another nice patch
> (although certainly not required IMHO for this to go in), would be to
> make nvram optionally persistent for QEMU so these settings would
> persist across boots.
Yeah, the lack of persistence is sort of a "feature" in this case. If
you use the similar menus on most real hardware, they don't persist (you
have to go into the bios setup screens to make it persist). That said,
if things were to persist, then we'd probably want to change the patch
to set something else which was looked at prior to the CMOS
Jeremy
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add support for a basic boot menu to the bios
[not found] ` <1189626953.16586.6.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-09-12 20:19 ` Anthony Liguori
@ 2007-09-14 20:14 ` Anthony Liguori
2007-09-16 20:00 ` Avi Kivity
2 siblings, 0 replies; 9+ messages in thread
From: Anthony Liguori @ 2007-09-14 20:14 UTC (permalink / raw)
To: Jeremy Katz; +Cc: kvm-devel
Hi Jeremy,
I gave this patch a try today against the latest git
1edeb9c05aa034633978f31e2c773a1be55ed337 and I cannot get past the
"Press F10..." prompt. I'm on an Intel Core 2 Duo processor. It does
work though with -no-kvm.
Have you tested this patch with KVM?
Regards,
Anthony Liguori
Jeremy Katz wrote:
> I sent this to the bochs list earlier today, but given that kvm is
> already carrying patches for the BIOS, it may be worthwhile/interesting
> to add this also as it can make the user experience substantially nicer.
>
> -- Begin forwarded message --
>
> The attached patch adds support for a relatively basic boot device
> selection menu to the bochs bios code.
> Hi J
> Instead of immediately booting from the boot device set in the cmos, we
> wait for 3 seconds for the user to press F10; if they press it, then we
> show a basic boot menu that they can select what device to boot from.
> Otherwise, we continue on with what was setup before running the virtual
> machine. The advantage is that users can change their boot device just
> on rebooting a virtual machine rather than having to stop and then
> restart it.
>
> This includes the wait routines added by VirtualBox
> (http://www.virtualbox.org) in their modifications to the rombios as
> they made things a bit easier.
>
> Jeremy
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> ------------------------------------------------------------------------
>
> _______________________________________________
> kvm-devel mailing list
> kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/kvm-devel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add support for a basic boot menu to the bios
[not found] ` <1189626953.16586.6.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-09-12 20:19 ` Anthony Liguori
2007-09-14 20:14 ` Anthony Liguori
@ 2007-09-16 20:00 ` Avi Kivity
[not found] ` <46ED8B5B.40903-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2 siblings, 1 reply; 9+ messages in thread
From: Avi Kivity @ 2007-09-16 20:00 UTC (permalink / raw)
To: Jeremy Katz; +Cc: kvm-devel
Jeremy Katz wrote:
> I sent this to the bochs list earlier today, but given that kvm is
> already carrying patches for the BIOS, it may be worthwhile/interesting
> to add this also as it can make the user experience substantially nicer.
>
> -- Begin forwarded message --
>
> The attached patch adds support for a relatively basic boot device
> selection menu to the bochs bios code.
>
> Instead of immediately booting from the boot device set in the cmos, we
> wait for 3 seconds for the user to press F10; if they press it, then we
> show a basic boot menu that they can select what device to boot from.
> Otherwise, we continue on with what was setup before running the virtual
> machine. The advantage is that users can change their boot device just
> on rebooting a virtual machine rather than having to stop and then
> restart it.
>
> This includes the wait routines added by VirtualBox
> (http://www.virtualbox.org) in their modifications to the rombios as
> they made things a bit easier.
>
>
This is nice! Two comments:
- it would be nice for qemu to provide the bios an indication if the
'-boot' parameter was specified to qemu. if so, the bios should skip
the menu on first bootup, reducing the boot delay. On subsequent boots
the menu should be offered. This is primarily useful in managed
environments.
- coding this stuff in rombios32.c instead of rombios.c (with its
strange idea of C) is *much* preferable for maintainability. As far as
i can tell, there is no reason not to do so, especially for code which
is not called from the 16-bit OS.
--
Any sufficiently difficult bug is indistinguishable from a feature.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add support for a basic boot menu to the bios
[not found] ` <46ED8B5B.40903-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
@ 2007-09-17 15:23 ` Luca
[not found] ` <68676e00709170823m3247c3eaj7d268166ecc8c013-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-09-19 20:08 ` Jeremy Katz
1 sibling, 1 reply; 9+ messages in thread
From: Luca @ 2007-09-17 15:23 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel, Jeremy Katz
On 9/16/07, Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org> wrote:
> - coding this stuff in rombios32.c instead of rombios.c (with its
> strange idea of C) is *much* preferable for maintainability.
The strange code style is due to the compiler used (bcc). I see that
today it's possible to make as and gcc to emit 16bit code (e.g. HPA
rewrote i386 boot code in plain C)...
Luca
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add support for a basic boot menu to the bios
[not found] ` <68676e00709170823m3247c3eaj7d268166ecc8c013-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2007-09-17 17:30 ` Avi Kivity
0 siblings, 0 replies; 9+ messages in thread
From: Avi Kivity @ 2007-09-17 17:30 UTC (permalink / raw)
To: Luca; +Cc: kvm-devel, Jeremy Katz
Luca wrote:
> On 9/16/07, Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org> wrote:
>
>> - coding this stuff in rombios32.c instead of rombios.c (with its
>> strange idea of C) is *much* preferable for maintainability.
>>
>
> The strange code style is due to the compiler used (bcc). I see that
> today it's possible to make as and gcc to emit 16bit code (e.g. HPA
> rewrote i386 boot code in plain C)...
>
>
It's simpler and better to code it in 32-bit mode in rombios32.c, where
there are no restrictions like with the 16-bit mode.
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add support for a basic boot menu to the bios
[not found] ` <46ED8B5B.40903-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-09-17 15:23 ` Luca
@ 2007-09-19 20:08 ` Jeremy Katz
[not found] ` <1190232486.10222.37.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
1 sibling, 1 reply; 9+ messages in thread
From: Jeremy Katz @ 2007-09-19 20:08 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm-devel
[-- Attachment #1: Type: text/plain, Size: 1690 bytes --]
On Sun, 2007-09-16 at 22:00 +0200, Avi Kivity wrote:
> > The attached patch adds support for a relatively basic boot device
> > selection menu to the bochs bios code.
[snip]
> This is nice! Two comments:
>
> - it would be nice for qemu to provide the bios an indication if the
> '-boot' parameter was specified to qemu. if so, the bios should skip
> the menu on first bootup, reducing the boot delay. On subsequent boots
> the menu should be offered. This is primarily useful in managed
> environments.
While this could be nice, at the same time, -boot is going to be getting
passed for a long time, even when it's no longer needed, just due to
people not updating their tools. So I almost think it's better to take
the 3 second hit since it's going to be there every other time. We
could tweak it to be a little bit less, but 3 seems in line with what
other BIOSes seem to do.
> - coding this stuff in rombios32.c instead of rombios.c (with its
> strange idea of C) is *much* preferable for maintainability. As far as
> i can tell, there is no reason not to do so, especially for code which
> is not called from the 16-bit OS.
The code is called from the 16-bit OS, though. It needs to be done
after rom scanning has been done so that we can show network or not as
appropriate. And unless I'm missing something, calling into rombios32.c
outside of rombios32_init() is going to add just as much
hard-to-maintain code.
Updated patch against kvm git attached that actually works with kvm.
Also ends up being a little bit simpler because we're doing less mucking
around with the timer.
Signed-off-by: Jeremy Katz <katzj-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Jeremy
[-- Attachment #2: kvm-bootmenu.patch --]
[-- Type: text/x-patch, Size: 5865 bytes --]
diff --git a/bios/BIOS-bochs-latest b/bios/BIOS-bochs-latest
index c10ae62..e13af69 100644
Binary files a/bios/BIOS-bochs-latest and b/bios/BIOS-bochs-latest differ
diff --git a/bios/BIOS-bochs-legacy b/bios/BIOS-bochs-legacy
index 131e62b..5c03460 100644
Binary files a/bios/BIOS-bochs-legacy and b/bios/BIOS-bochs-legacy differ
diff --git a/bios/rombios.c b/bios/rombios.c
index ac918ad..4ebdb71 100644
--- a/bios/rombios.c
+++ b/bios/rombios.c
@@ -1950,6 +1950,228 @@ print_cdromboot_failure( code )
return;
}
+#define WAIT_HZ 18
+/**
+ * Check for keystroke.
+ * @returns True if keystroke available, False if not.
+ */
+Bit8u check_for_keystroke()
+{
+ASM_START
+ mov ax, #0x100
+ int #0x16
+ jz no_key
+ mov al, #1
+ jmp done
+no_key:
+ xor al, al
+done:
+ASM_END
+}
+
+/**
+ * Get keystroke.
+ * @returns BIOS scan code.
+ */
+Bit8u get_keystroke()
+{
+ASM_START
+ mov ax, #0x0
+ int #0x16
+ xchg ah, al
+ASM_END
+}
+
+/**
+ * Waits (sleeps) for the given number of ticks.
+ * Checks for keystroke.
+ *
+ * @returns BIOS scan code if available, 0 if not.
+ * @param ticks Number of ticks to sleep.
+ * @param stop_on_key Whether to stop immediately upon keypress.
+ */
+Bit8u wait(ticks, stop_on_key)
+ Bit16u ticks;
+ Bit8u stop_on_key;
+{
+ long ticks_to_wait, delta;
+ Bit32u prev_ticks, t;
+ Bit8u scan_code = 0;
+
+ /*
+ * The 0:046c wraps around at 'midnight' according to a 18.2Hz clock.
+ * We also have to be careful about interrupt storms.
+ */
+ ticks_to_wait = ticks;
+ prev_ticks = read_dword(0x0, 0x46c);
+ do
+ {
+ t = read_dword(0x0, 0x46c);
+ if (t > prev_ticks)
+ {
+ delta = t - prev_ticks; /* The temp var is required or bcc screws up. */
+ ticks_to_wait -= delta;
+ }
+ else if (t < prev_ticks)
+ ticks_to_wait -= t; /* wrapped */
+ prev_ticks = t;
+
+ if (check_for_keystroke())
+ {
+ scan_code = get_keystroke();
+ bios_printf(BIOS_PRINTF_DEBUG, "Key pressed: %x\n", scan_code);
+ if (stop_on_key)
+ return scan_code;
+ }
+ } while (ticks_to_wait > 0);
+ return scan_code;
+}
+
+static void clearscreen() {
+ /* Hide cursor, clear screen and move cursor to starting position */
+ASM_START
+ push bx
+ push cx
+ push dx
+
+ mov ax, #0x100
+ mov cx, #0x1000
+ int #0x10
+
+ mov ax, #0x700
+ mov bh, #7
+ xor cx, cx
+ mov dx, #0x184f
+ int #0x10
+
+ mov ax, #0x200
+ xor bx, bx
+ xor dx, dx
+ int #0x10
+
+ pop dx
+ pop cx
+ pop bx
+ASM_END
+}
+
+int bootmenu(selected)
+ int selected;
+{
+ Bit8u scode;
+ int max;
+
+ /* get the number of boot devices */
+ max = read_word(IPL_SEG, IPL_COUNT_OFFSET);
+
+ for(;;) {
+ clearscreen();
+ bios_printf(BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO, "\n\n\n\n\n\n\n");
+ bios_printf(BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO, " Select boot device\n\n");
+ bios_printf(BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO, " 1. Floppy\n");
+ bios_printf(BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO, " 2. Hard drive\n");
+ bios_printf(BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO, " 3. CD-ROM\n");
+ if (max == 4)
+ bios_printf(BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO, " 4. Network\n");
+ bios_printf(BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO, "\n\n Currently selected: %d\n", selected);
+
+ do {
+ scode = wait(WAIT_HZ, 1);
+ } while (scode == 0);
+ switch(scode) {
+ case 0x02:
+ case 0x03:
+ case 0x04:
+ selected = scode - 1;
+ break;
+ case 0x05:
+ if (max == 4)
+ selected = scode -1 ;
+ else
+ scode = 0;
+ break;
+ case 0x48:
+ selected -= 1;
+ if (selected < 1)
+ selected = 1;
+ scode = 0;
+ break;
+ case 0x50:
+ selected += 1;
+ if (selected > max)
+ selected = max;
+ scode = 0;
+ break;
+ case 0x1c:
+ break;
+ default:
+ scode = 0;
+ break;
+ }
+ if (scode != 0)
+ break;
+ }
+
+ switch (selected) {
+ case 1:
+ return 0x3D;
+ case 2:
+ return 0x3E;
+ case 3:
+ return 0x3F;
+ case 4:
+ return 0x58;
+ default:
+ return 0;
+ }
+}
+
+void interactive_bootkey()
+{
+ Bit16u i;
+ Bit8u scan = 0;
+
+ bios_printf(BIOS_PRINTF_SCREEN | BIOS_PRINTF_INFO, "\n\nPress F10 to select boot device.\n");
+ for (i = 3; i > 0; i--)
+ {
+ scan = wait(WAIT_HZ, 0);
+ switch (scan) {
+ case 0x3D:
+ case 0x3E:
+ case 0x3F:
+ case 0x58:
+ break;
+ case 0x44:
+ scan = bootmenu(inb_cmos(0x3d));
+ break;
+ default:
+ scan = 0;
+ break;
+ }
+ if (scan != 0)
+ break;
+ }
+
+ /* set the default based on the keypress or menu */
+ switch(scan) {
+ case 0x3D:
+ outb_cmos(0x3d, 0x01);
+ break;
+ case 0x3E:
+ outb_cmos(0x3d, 0x02);
+ break;
+ case 0x3F:
+ outb_cmos(0x3d, 0x03);
+ break;
+ case 0x58:
+ outb_cmos(0x3d, 0x04);
+ break;
+ default:
+ break;
+ }
+}
+
+
void
nmi_handler_msg()
{
@@ -10226,6 +10448,8 @@ post_default_ints:
;;
#endif // BX_ELTORITO_BOOT
+ call _interactive_bootkey
+
sti ;; enable interrupts
int #0x19
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 186 bytes --]
_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] Add support for a basic boot menu to the bios
[not found] ` <1190232486.10222.37.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2007-09-20 6:02 ` Avi Kivity
0 siblings, 0 replies; 9+ messages in thread
From: Avi Kivity @ 2007-09-20 6:02 UTC (permalink / raw)
To: Jeremy Katz; +Cc: kvm-devel
Jeremy Katz wrote:
> On Sun, 2007-09-16 at 22:00 +0200, Avi Kivity wrote:
>
>>> The attached patch adds support for a relatively basic boot device
>>> selection menu to the bochs bios code.
>>>
> [snip]
>
>> This is nice! Two comments:
>>
>> - it would be nice for qemu to provide the bios an indication if the
>> '-boot' parameter was specified to qemu. if so, the bios should skip
>> the menu on first bootup, reducing the boot delay. On subsequent boots
>> the menu should be offered. This is primarily useful in managed
>> environments.
>>
>
> While this could be nice, at the same time, -boot is going to be getting
> passed for a long time, even when it's no longer needed, just due to
> people not updating their tools. So I almost think it's better to take
> the 3 second hit since it's going to be there every other time. We
> could tweak it to be a little bit less, but 3 seems in line with what
> other BIOSes seem to do.
>
>
I almost agree. Let people upgrade their tools, they ought to have many
reasons besides the boot menu.
[we could add a -dont-show-boot-menu parameter to make this explicit,
but I don't think we should]
>> - coding this stuff in rombios32.c instead of rombios.c (with its
>> strange idea of C) is *much* preferable for maintainability. As far as
>> i can tell, there is no reason not to do so, especially for code which
>> is not called from the 16-bit OS.
>>
>
> The code is called from the 16-bit OS, though.
No, it's called from the boot code. We're not returning to DOS after
int 19.
> It needs to be done
> after rom scanning has been done so that we can show network or not as
> appropriate. And unless I'm missing something, calling into rombios32.c
> outside of rombios32_init() is going to add just as much
> hard-to-maintain code.
>
Why? the thunk into 32-bit mode can be shared and is a small piece of
code. The boot menu is much larger and can potentially grow (to control
other options besides the boot device).
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2007-09-20 6:02 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-12 19:55 [PATCH] Add support for a basic boot menu to the bios Jeremy Katz
[not found] ` <1189626953.16586.6.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-09-12 20:19 ` Anthony Liguori
[not found] ` <46E849DE.3040103-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2007-09-12 20:25 ` Jeremy Katz
2007-09-14 20:14 ` Anthony Liguori
2007-09-16 20:00 ` Avi Kivity
[not found] ` <46ED8B5B.40903-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-09-17 15:23 ` Luca
[not found] ` <68676e00709170823m3247c3eaj7d268166ecc8c013-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-09-17 17:30 ` Avi Kivity
2007-09-19 20:08 ` Jeremy Katz
[not found] ` <1190232486.10222.37.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-09-20 6:02 ` Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox