2004-09-10 Yoshinori K. Okuji <okuji@enbug.org>

* normal/menu.c: Include grub/loader.h and grub/machine/time.h.
  (print_message): Add a missing newline.
  (run_menu): Added timeout support.
  (run_menu_entry): New local function.
  (grub_menu_run): Added support for booting.

  * kern/loader.c (grub_loader_is_loaded): New function.

  * include/grub/powerpc/ieee1275/time.h: Include grub/symbol.h.
  (grub_get_rtc): Exported.

  * include/grub/i386/pc/time.h: Include grub/symbol.h.
  (grub_get_rtc): Exported.

  * include/grub/normal.h (struct grub_command_list): Remove
  constant from the member `command'.

  * include/grub/loader.h (grub_loader_is_loaded): Declared.

  * include/grub/err.h (GRUB_ERR_INVALID_COMMAND): New constant.

  * conf/i386-pc.rmk (kernel_img_HEADERS): Added machine/time.h.
This commit is contained in:
okuji 2004-09-10 20:31:55 +00:00
parent aa0335603c
commit 3c52136a94
10 changed files with 209 additions and 65 deletions

View file

@ -1,3 +1,28 @@
2004-09-10 Yoshinori K. Okuji <okuji@enbug.org>
* normal/menu.c: Include grub/loader.h and grub/machine/time.h.
(print_message): Add a missing newline.
(run_menu): Added timeout support.
(run_menu_entry): New local function.
(grub_menu_run): Added support for booting.
* kern/loader.c (grub_loader_is_loaded): New function.
* include/grub/powerpc/ieee1275/time.h: Include grub/symbol.h.
(grub_get_rtc): Exported.
* include/grub/i386/pc/time.h: Include grub/symbol.h.
(grub_get_rtc): Exported.
* include/grub/normal.h (struct grub_command_list): Remove
constant from the member `command'.
* include/grub/loader.h (grub_loader_is_loaded): Declared.
* include/grub/err.h (GRUB_ERR_INVALID_COMMAND): New constant.
* conf/i386-pc.rmk (kernel_img_HEADERS): Added machine/time.h.
2004-08-28 Marco Gerards <metgerards@student.han.nl> 2004-08-28 Marco Gerards <metgerards@student.han.nl>
Add support for the JFS filesystem. Add support for the JFS filesystem.

View file

@ -249,11 +249,11 @@ kernel_img-symlist.d: symlist.c
-include kernel_img-symlist.d -include kernel_img-symlist.d
kernel_img_HEADERS = boot.h device.h disk.h dl.h elf.h err.h \ kernel_img_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
file.h fs.h kernel.h loader.h misc.h mm.h net.h rescue.h symbol.h \ file.h fs.h kernel.h loader.h misc.h mm.h net.h rescue.h symbol.h \
term.h types.h machine/biosdisk.h machine/boot.h \ term.h types.h machine/biosdisk.h machine/boot.h \
machine/console.h machine/init.h machine/memory.h \ machine/console.h machine/init.h machine/memory.h \
machine/loader.h machine/partition.h machine/vga.h arg.h env.h machine/loader.h machine/partition.h machine/time.h machine/vga.h
kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200 kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200

View file

@ -29,11 +29,11 @@ kernel_img_SOURCES = kern/i386/pc/startup.S kern/main.c kern/device.c \
kern/env.c disk/i386/pc/biosdisk.c \ kern/env.c disk/i386/pc/biosdisk.c \
term/i386/pc/console.c \ term/i386/pc/console.c \
symlist.c symlist.c
kernel_img_HEADERS = boot.h device.h disk.h dl.h elf.h err.h \ kernel_img_HEADERS = arg.h boot.h device.h disk.h dl.h elf.h env.h err.h \
file.h fs.h kernel.h loader.h misc.h mm.h net.h rescue.h symbol.h \ file.h fs.h kernel.h loader.h misc.h mm.h net.h rescue.h symbol.h \
term.h types.h machine/biosdisk.h machine/boot.h \ term.h types.h machine/biosdisk.h machine/boot.h \
machine/console.h machine/init.h machine/memory.h \ machine/console.h machine/init.h machine/memory.h \
machine/loader.h machine/partition.h machine/vga.h arg.h env.h machine/loader.h machine/partition.h machine/time.h machine/vga.h
kernel_img_CFLAGS = $(COMMON_CFLAGS) kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200 kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200

View file

@ -1,7 +1,7 @@
/* err.h - error numbers and prototypes */ /* err.h - error numbers and prototypes */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003 Free Software Foundation, Inc. * Copyright (C) 2002,2003,2004 Free Software Foundation, Inc.
* *
* GRUB is free software; you can redistribute it and/or modify * GRUB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -41,6 +41,7 @@ typedef enum
GRUB_ERR_READ_ERROR, GRUB_ERR_READ_ERROR,
GRUB_ERR_WRITE_ERROR, GRUB_ERR_WRITE_ERROR,
GRUB_ERR_UNKNOWN_COMMAND, GRUB_ERR_UNKNOWN_COMMAND,
GRUB_ERR_INVALID_COMMAND,
GRUB_ERR_BAD_ARGUMENT, GRUB_ERR_BAD_ARGUMENT,
GRUB_ERR_BAD_PART_TABLE, GRUB_ERR_BAD_PART_TABLE,
GRUB_ERR_UNKNOWN_OS, GRUB_ERR_UNKNOWN_OS,

View file

@ -1,6 +1,6 @@
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2003 Free Software Foundation, Inc. * Copyright (C) 2003,2004 Free Software Foundation, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,6 +20,8 @@
#ifndef KERNEL_TIME_HEADER #ifndef KERNEL_TIME_HEADER
#define KERNEL_TIME_HEADER 1 #define KERNEL_TIME_HEADER 1
#include <grub/symbol.h>
#ifdef GRUB_UTIL #ifdef GRUB_UTIL
# include <time.h> # include <time.h>
# define GRUB_TICKS_PER_SECOND CLOCKS_PER_SEC # define GRUB_TICKS_PER_SECOND CLOCKS_PER_SEC
@ -28,6 +30,6 @@
#endif #endif
/* Return the real time in ticks. */ /* Return the real time in ticks. */
grub_uint32_t grub_get_rtc (void); grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void);
#endif /* ! KERNEL_TIME_HEADER */ #endif /* ! KERNEL_TIME_HEADER */

View file

@ -1,7 +1,7 @@
/* loader.h - OS loaders */ /* loader.h - OS loaders */
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003 Free Software Foundation, Inc. * Copyright (C) 2002,2003,2004 Free Software Foundation, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -29,6 +29,7 @@
extern grub_addr_t EXPORT_VAR(grub_os_area_addr); extern grub_addr_t EXPORT_VAR(grub_os_area_addr);
extern grub_size_t EXPORT_VAR(grub_os_area_size); extern grub_size_t EXPORT_VAR(grub_os_area_size);
int EXPORT_FUNC(grub_loader_is_loaded) (void);
void EXPORT_FUNC(grub_loader_set) (grub_err_t (*boot) (void), void EXPORT_FUNC(grub_loader_set) (grub_err_t (*boot) (void),
grub_err_t (*unload) (void)); grub_err_t (*unload) (void));
void EXPORT_FUNC(grub_loader_unset) (void); void EXPORT_FUNC(grub_loader_unset) (void);

View file

@ -70,7 +70,7 @@ typedef struct grub_command *grub_command_t;
struct grub_command_list struct grub_command_list
{ {
/* The string of a command. */ /* The string of a command. */
const char *command; char *command;
/* The next element. */ /* The next element. */
struct grub_command_list *next; struct grub_command_list *next;

View file

@ -1,6 +1,6 @@
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2003 Marco Gerards <metgerards@student.han.nl> * Copyright (C) 2003,2004 Marco Gerards <metgerards@student.han.nl>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,6 +20,8 @@
#ifndef KERNEL_TIME_HEADER #ifndef KERNEL_TIME_HEADER
#define KERNEL_TIME_HEADER 1 #define KERNEL_TIME_HEADER 1
#include <grub/symbol.h>
#ifdef GRUB_UTIL #ifdef GRUB_UTIL
# include <time.h> # include <time.h>
# define GRUB_TICKS_PER_SECOND CLOCKS_PER_SEC # define GRUB_TICKS_PER_SECOND CLOCKS_PER_SEC
@ -28,6 +30,6 @@
#endif #endif
/* Return the real time in ticks. */ /* Return the real time in ticks. */
grub_uint32_t grub_get_rtc (void); grub_uint32_t EXPORT_FUNC (grub_get_rtc) (void);
#endif /* ! KERNEL_TIME_HEADER */ #endif /* ! KERNEL_TIME_HEADER */

View file

@ -1,6 +1,6 @@
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2003 Free Software Foundation, Inc. * Copyright (C) 2002,2003,2004 Free Software Foundation, Inc.
* *
* GRUB is free software; you can redistribute it and/or modify * GRUB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -27,6 +27,12 @@ static grub_err_t (*grub_loader_unload_func) (void);
static int grub_loader_loaded; static int grub_loader_loaded;
int
grub_loader_is_loaded (void)
{
return grub_loader_loaded;
}
void void
grub_loader_set (grub_err_t (*boot) (void), grub_loader_set (grub_err_t (*boot) (void),
grub_err_t (*unload) (void)) grub_err_t (*unload) (void))

View file

@ -1,6 +1,6 @@
/* /*
* GRUB -- GRand Unified Bootloader * GRUB -- GRand Unified Bootloader
* Copyright (C) 2003 Free Software Foundation, Inc. * Copyright (C) 2003,2004 Free Software Foundation, Inc.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,6 +20,8 @@
#include <grub/normal.h> #include <grub/normal.h>
#include <grub/term.h> #include <grub/term.h>
#include <grub/misc.h> #include <grub/misc.h>
#include <grub/loader.h>
#include <grub/machine/time.h>
/* FIXME: These below are all runaround. */ /* FIXME: These below are all runaround. */
@ -80,7 +82,7 @@ print_message (int nested)
Press enter to boot the selected OS, \'e\' to edit the\n\ Press enter to boot the selected OS, \'e\' to edit the\n\
commands before booting, or \'c\' for a command-line."); commands before booting, or \'c\' for a command-line.");
if (nested) if (nested)
grub_printf ("\ grub_printf ("\n\
ESC to return previous menu."); ESC to return previous menu.");
} }
@ -170,6 +172,7 @@ static int
run_menu (grub_menu_t menu, int nested) run_menu (grub_menu_t menu, int nested)
{ {
int first, offset; int first, offset;
unsigned long saved_time;
grub_setcursor (0); grub_setcursor (0);
@ -184,93 +187,197 @@ run_menu (grub_menu_t menu, int nested)
init_page (nested); init_page (nested);
print_entries (menu, first, offset); print_entries (menu, first, offset);
grub_refresh (); grub_refresh ();
/* Initialize the time. */
saved_time = grub_get_rtc ();
while (1) while (1)
{ {
int c; int c;
c = GRUB_TERM_ASCII_CHAR (grub_getkey ()); if (menu->timeout > 0)
switch (c)
{ {
case 16: unsigned long current_time;
case '^':
if (offset > 0)
{
print_entry (4 + offset, 0, get_entry (menu, first + offset));
offset--;
print_entry (4 + offset, 1, get_entry (menu, first + offset));
}
else if (first > 0)
{
first--;
print_entries (menu, first, offset);
}
break;
case 14: current_time = grub_get_rtc ();
case 'v': if (current_time - saved_time >= GRUB_TICKS_PER_SECOND)
if (menu->size > first + offset + 1)
{ {
if (offset < 11) menu->timeout--;
saved_time = current_time;
}
grub_gotoxy (3, 22);
grub_printf ("The highlighted entry will be booted automatically in %d seconds. ",
menu->timeout);
grub_gotoxy (74, 4 + offset);
grub_refresh ();
}
if (menu->timeout == 0)
return menu->default_entry;
if (grub_checkkey () >= 0 || menu->timeout < 0)
{
c = GRUB_TERM_ASCII_CHAR (grub_getkey ());
if (menu->timeout >= 0)
{
grub_gotoxy (3, 22);
grub_printf (" ");
menu->timeout = -1;
menu->fallback_entry = -1;
grub_gotoxy (74, 4 + offset);
}
switch (c)
{
case 16:
case '^':
if (offset > 0)
{ {
print_entry (4 + offset, 0, print_entry (4 + offset, 0,
get_entry (menu, first + offset)); get_entry (menu, first + offset));
offset++; offset--;
print_entry (4 + offset, 1, print_entry (4 + offset, 1,
get_entry (menu, first + offset)); get_entry (menu, first + offset));
} }
else else if (first > 0)
{ {
first++; first--;
print_entries (menu, first, offset); print_entries (menu, first, offset);
} }
} break;
break;
case 14:
case '\n': case 'v':
case '\r': if (menu->size > first + offset + 1)
case 6: {
grub_setcursor (1); if (offset < 11)
return first + offset; {
print_entry (4 + offset, 0,
case '\e': get_entry (menu, first + offset));
if (nested) offset++;
{ print_entry (4 + offset, 1,
get_entry (menu, first + offset));
}
else
{
first++;
print_entries (menu, first, offset);
}
}
break;
case '\n':
case '\r':
case 6:
grub_setcursor (1); grub_setcursor (1);
return -1; return first + offset;
case '\e':
if (nested)
{
grub_setcursor (1);
return -1;
}
break;
case 'c':
grub_setcursor (1);
grub_cmdline_run (1);
grub_setcursor (0);
init_page (nested);
print_entries (menu, first, offset);
break;
default:
break;
} }
break;
grub_refresh ();
case 'c':
grub_setcursor (1);
grub_cmdline_run (1);
grub_setcursor (0);
init_page (nested);
print_entries (menu, first, offset);
break;
default:
break;
} }
grub_refresh ();
} }
/* Never reach here. */ /* Never reach here. */
return -1; return -1;
} }
/* Run a menu entry. */
static void
run_menu_entry (grub_menu_entry_t entry)
{
grub_command_list_t cl;
for (cl = entry->command_list; cl != 0; cl = cl->next)
{
grub_command_t c;
c = grub_command_find (cl->command);
if (! c)
break;
if (! (c->flags & GRUB_COMMAND_FLAG_CMDLINE))
{
grub_error (GRUB_ERR_INVALID_COMMAND,
"invalid command `%s'",
cl->command);
break;
}
if (! (c->flags & GRUB_COMMAND_FLAG_NO_ECHO))
grub_printf ("%s\n", cl->command);
if (grub_command_execute (cl->command) != 0)
break;
}
if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
/* Implicit execution of boot, only if something is loaded. */
grub_command_execute ("boot");
}
void void
grub_menu_run (grub_menu_t menu, int nested) grub_menu_run (grub_menu_t menu, int nested)
{ {
while (1) while (1)
{ {
int boot_entry; int boot_entry;
grub_menu_entry_t e;
boot_entry = run_menu (menu, nested); boot_entry = run_menu (menu, nested);
if (boot_entry < 0) if (boot_entry < 0)
break; break;
/* FIXME: Boot the entry. */ grub_cls ();
grub_setcursor (1);
e = get_entry (menu, boot_entry);
grub_printf (" Booting \'%s\'\n\n", e->title);
run_menu_entry (e);
/* Deal with a fallback entry. */
/* FIXME: Mutiple fallback entries like GRUB Legacy. */
if (menu->fallback_entry >= 0)
{
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
e = get_entry (menu, menu->fallback_entry);
menu->fallback_entry = -1;
grub_printf ("\n Falling back to \'%s\'\n\n", e->title);
run_menu_entry (e);
}
if (grub_errno != GRUB_ERR_NONE)
{
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
/* Wait until the user pushes any key so that the user
can see what happened. */
grub_printf ("\nPress any key to continue...");
(void) grub_getkey ();
}
} }
} }