All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hold shift or control to disable timeout even timeout=0
@ 2008-07-24  0:52 David Fries
  2008-07-24  1:13 ` Pavel Roskin
  0 siblings, 1 reply; 4+ messages in thread
From: David Fries @ 2008-07-24  0:52 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 7067 bytes --]

There are various projects trying to speed up booting a computer.
Here is a patch designed to do just that.  grub by default waits a few
seconds to give the user the chance to interact with the menu or
command line.  Currently for a fast bootup a timeout of zero can be
specified, but then you loose any chance at interacting with grub.  It
would be better to have a zero timeout delay, and yet be able to
interact when needed.

While booting, BIOS reads and tracks the status of key presses.  At
grub boot time it can be queried to find out if control or shift are
held, even if they were pressed before grub started executing.  This
patch will disable the timeout if shift or control are held to allow
interaction if desired, and if not timeout=0 will allow boot to
proceed without a timeout delay.

This calls the getshiftflags BIOS int 16h function 2 in startup.S, to
find out the status of the shift and control keys (among others).  The
required header and source files were modified to expose
grub_getshiftflags.  menu.c checks grub_getshiftflags and will disable
the timeout.


Index: kern/term.c
===================================================================
--- kern/term.c	(revision 1702)
+++ kern/term.c	(working copy)
@@ -186,6 +186,14 @@
   return (grub_cur_term->checkkey) ();
 }
 
+int
+grub_getshiftflags (void)
+{
+  if (!grub_cur_term->getshiftflags)
+    return 0;
+  return (grub_cur_term->getshiftflags) ();
+}
+
 grub_uint16_t
 grub_getxy (void)
 {
Index: kern/i386/pc/startup.S
===================================================================
--- kern/i386/pc/startup.S	(revision 1702)
+++ kern/i386/pc/startup.S	(working copy)
@@ -1333,7 +1333,36 @@
 	popl	%ebp
 	ret
 
+
+/*
+ * int grub_console_getshiftflags (void)
+ *	Get the currently held modifier keys and flags, 0 none held.
+ * BIOS call "INT 16H Function 02H" get shift flags
+ *	Call with	%ah = 0x2
+ *	Return:		%ah = "AH destroyed by many BIOSes"
+ *			%al = shift flags
+ *	See include/grub/term.h GRUB_THERM_* for flag values.
+ */
+FUNCTION(grub_console_getshiftflags)
+	pushl	%ebp
+	xorl	%edx, %edx	/* zero */
 	
+	call	prot_to_real	/* enter real mode */
+	.code16
+
+	movb	$0x2, %ah
+	int	$0x16
+
+	movb	%al, %dl	/* Only 8 bits are kept */
+
+	DATA32	call	real_to_prot
+	.code32
+
+	movl	%edx, %eax	/* flags in %eax for return */
+	popl	%ebp
+	ret
+
+
 /*
  * grub_uint16_t grub_console_getxy (void)
  * BIOS call "INT 10H Function 03h" to get cursor position
Index: include/grub/term.h
===================================================================
--- include/grub/term.h	(revision 1702)
+++ include/grub/term.h	(working copy)
@@ -33,6 +33,16 @@
 #define GRUB_TERM_TAB		'\t'
 #define GRUB_TERM_BACKSPACE	'\b'
 
+/* Bit values for keys helpd by grub_getshiftflags (). */
+#define GRUB_TERM_RSHIFT_DOWN		0x01
+#define GRUB_TERM_LSHIFT_DOWN		0x02
+#define GRUB_TERM_CTRL_DOWN		0x04
+#define GRUB_TERM_ALT_DOWN		0x08
+#define GRUB_TERM_SCROLLLOCK_DOWN	0x10
+#define GRUB_TERM_NUMLOCK_DOWN		0x20
+#define GRUB_TERM_CAPSLOCK_DOWN		0x40
+#define GRUB_TERM_INSERT_ACTIVE		0x80
+
 #ifndef ASM_FILE
 
 #include <grub/err.h>
@@ -155,11 +165,16 @@
      encoded in Unicode.  */
   grub_ssize_t (*getcharwidth) (grub_uint32_t c);
   
-  /* Check if any input character is available.  */
+  /* Check if any input character is available.  -1 if a key is not available,
+   * otherwise the key value (which is not removed).
+   */
   int (*checkkey) (void);
   
-  /* Get a character.  */
+  /* Get a character blocking if necessary.  */
   int (*getkey) (void);
+
+  /* Get the currently held modifier keys and flags, 0 none held. */
+  int (*getshiftflags) (void);
   
   /* Get the screen size. The return value is ((Width << 8) | Height).  */
   grub_uint16_t (*getwh) (void);
@@ -210,6 +225,7 @@
 grub_ssize_t EXPORT_FUNC(grub_getcharwidth) (grub_uint32_t code);
 int EXPORT_FUNC(grub_getkey) (void);
 int EXPORT_FUNC(grub_checkkey) (void);
+int EXPORT_FUNC(grub_getshiftflags) (void);
 grub_uint16_t EXPORT_FUNC(grub_getwh) (void);
 grub_uint16_t EXPORT_FUNC(grub_getxy) (void);
 void EXPORT_FUNC(grub_gotoxy) (grub_uint8_t x, grub_uint8_t y);
Index: include/grub/i386/pc/console.h
===================================================================
--- include/grub/i386/pc/console.h	(revision 1702)
+++ include/grub/i386/pc/console.h	(working copy)
@@ -42,6 +42,7 @@
 void grub_console_real_putchar (int c);
 int EXPORT_FUNC(grub_console_checkkey) (void);
 int EXPORT_FUNC(grub_console_getkey) (void);
+int EXPORT_FUNC(grub_console_getshiftflags) (void);
 grub_uint16_t grub_console_getxy (void);
 void grub_console_gotoxy (grub_uint8_t x, grub_uint8_t y);
 void grub_console_cls (void);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 1725)
+++ ChangeLog	(working copy)
@@ -1,3 +1,18 @@
+2008-07-23  David Fries <David@Fries.net>
+
+	Allow holding control or shift to abort timeout, even timeout=0.  This
+	allows no timeout delay and still be interactive.
+
+	* kern/term.c: add function grub_getshiftflags
+	* kern/i386/pc/startup.S: add grub_console_getshiftflags
+	* include/grub/term.h: add flag #defines, add getshiftflags function
+	pointer, export grub_getshiftflags
+	* include/grub/i386/pc/console.h: prototype for
+	grub_console_getshiftflags
+	* normal/menu.c(run_menu): check for shift or control and abort
+	timeout
+	* term/i386/pc/console.c: set .getshiftflags
+
 2008-07-23  Robert Millan  <rmh@aybabtu.com>
 
 	* Makefile.in (UNICODE_ARROWS, UNICODE_LINES): New variables (they
Index: normal/menu.c
===================================================================
--- normal/menu.c	(revision 1702)
+++ normal/menu.c	(working copy)
@@ -339,6 +339,15 @@
   if (default_entry < 0 || default_entry >= menu->size)
     default_entry = 0;
 
+  /* If shift or control are held when menu starts, abort the timeout.
+     This was added to allow a timeout of 0 to speed the boot time, and
+     still allow access to the grub menu if desired. */
+  if (grub_getshiftflags () &
+      (GRUB_TERM_RSHIFT_DOWN | GRUB_TERM_LSHIFT_DOWN | GRUB_TERM_CTRL_DOWN))
+    {
+      grub_env_unset ("timeout");
+    }
+
   /* If timeout is 0, drawing is pointless (and ugly).  */
   if (get_timeout () == 0)
     return default_entry;
Index: term/i386/pc/console.c
===================================================================
--- term/i386/pc/console.c	(revision 1702)
+++ term/i386/pc/console.c	(working copy)
@@ -134,6 +134,7 @@
     .getcharwidth = grub_console_getcharwidth,
     .checkkey = grub_console_checkkey,
     .getkey = grub_console_getkey,
+    .getshiftflags = grub_console_getshiftflags,
     .getwh = grub_console_getwh,
     .getxy = grub_console_getxy,
     .gotoxy = grub_console_gotoxy,

-- 
David Fries <david@fries.net>
http://fries.net/~david/ (PGP encryption key available)

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hold shift or control to disable timeout even timeout=0
  2008-07-24  0:52 [PATCH] hold shift or control to disable timeout even timeout=0 David Fries
@ 2008-07-24  1:13 ` Pavel Roskin
  2008-07-24  1:36   ` David Fries
  0 siblings, 1 reply; 4+ messages in thread
From: Pavel Roskin @ 2008-07-24  1:13 UTC (permalink / raw)
  To: The development of GRUB 2

On Wed, 2008-07-23 at 19:52 -0500, David Fries wrote:

> This calls the getshiftflags BIOS int 16h function 2 in startup.S, to
> find out the status of the shift and control keys (among others).  The
> required header and source files were modified to expose
> grub_getshiftflags.  menu.c checks grub_getshiftflags and will disable
> the timeout.

Cannot we avoid adding code to core.img that it not called from
core.img?  Just because it's written in assembly it doesn't mean it
should be in the in the core.

Sure, we are better off now that we are using lzma, but it we start
adding stuff mindlessly, core.img can again grow too large for some
setups.

-- 
Regards,
Pavel Roskin



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hold shift or control to disable timeout even timeout=0
  2008-07-24  1:13 ` Pavel Roskin
@ 2008-07-24  1:36   ` David Fries
  2008-07-24  1:45     ` Pavel Roskin
  0 siblings, 1 reply; 4+ messages in thread
From: David Fries @ 2008-07-24  1:36 UTC (permalink / raw)
  To: The development of GRUB 2; +Cc: Pavel Roskin

On Wed, Jul 23, 2008 at 09:13:58PM -0400, Pavel Roskin wrote:
> On Wed, 2008-07-23 at 19:52 -0500, David Fries wrote:
> 
> > This calls the getshiftflags BIOS int 16h function 2 in startup.S, to
> > find out the status of the shift and control keys (among others).  The
> > required header and source files were modified to expose
> > grub_getshiftflags.  menu.c checks grub_getshiftflags and will disable
> > the timeout.
> 
> Cannot we avoid adding code to core.img that it not called from
> core.img?  Just because it's written in assembly it doesn't mean it
> should be in the in the core.

I could make the argument that it is ten assmebly instructions, but I
think the stronger case is the other two keyboard reading routines are
right there in the same file.

I suppose the grub_checkkey and the new grub_getshiftflags could both
be moved out of core.img, but where would they go and how would they
get assigned to the grub_term structure?

> Sure, we are better off now that we are using lzma, but it we start
> adding stuff mindlessly, core.img can again grow too large for some
> setups.
> 
> -- 
> Regards,
> Pavel Roskin
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel

-- 
David Fries <david@fries.net>
http://fries.net/~david/ (PGP encryption key available)



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] hold shift or control to disable timeout even timeout=0
  2008-07-24  1:36   ` David Fries
@ 2008-07-24  1:45     ` Pavel Roskin
  0 siblings, 0 replies; 4+ messages in thread
From: Pavel Roskin @ 2008-07-24  1:45 UTC (permalink / raw)
  To: The development of GRUB 2

On Wed, 2008-07-23 at 20:36 -0500, David Fries wrote:

> I could make the argument that it is ten assmebly instructions, but I
> think the stronger case is the other two keyboard reading routines are
> right there in the same file.
> 
> I suppose the grub_checkkey and the new grub_getshiftflags could both
> be moved out of core.img, but where would they go and how would they
> get assigned to the grub_term structure?

I think they should be in normal.mod, and should be assigned in the
normal.mod initialization.  Maybe it could be a new file with
architecture specific code needed for normal.mod support.

-- 
Regards,
Pavel Roskin



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-07-24  1:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-24  0:52 [PATCH] hold shift or control to disable timeout even timeout=0 David Fries
2008-07-24  1:13 ` Pavel Roskin
2008-07-24  1:36   ` David Fries
2008-07-24  1:45     ` Pavel Roskin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.