* 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-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>
Add support for the JFS filesystem.
-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 \
term.h types.h machine/biosdisk.h machine/boot.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_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200
kern/env.c disk/i386/pc/biosdisk.c \
term/i386/pc/console.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 \
term.h types.h machine/biosdisk.h machine/boot.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_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200
/* err.h - error numbers and prototypes */
/*
* 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
* it under the terms of the GNU General Public License as published by
GRUB_ERR_READ_ERROR,
GRUB_ERR_WRITE_ERROR,
GRUB_ERR_UNKNOWN_COMMAND,
+ GRUB_ERR_INVALID_COMMAND,
GRUB_ERR_BAD_ARGUMENT,
GRUB_ERR_BAD_PART_TABLE,
GRUB_ERR_UNKNOWN_OS,
/*
* 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
* it under the terms of the GNU General Public License as published by
#ifndef KERNEL_TIME_HEADER
#define KERNEL_TIME_HEADER 1
+#include <grub/symbol.h>
+
#ifdef GRUB_UTIL
# include <time.h>
# define GRUB_TICKS_PER_SECOND CLOCKS_PER_SEC
#endif
/* 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 */
/* loader.h - OS loaders */
/*
* 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
* it under the terms of the GNU General Public License as published by
extern grub_addr_t EXPORT_VAR(grub_os_area_addr);
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),
grub_err_t (*unload) (void));
void EXPORT_FUNC(grub_loader_unset) (void);
struct grub_command_list
{
/* The string of a command. */
- const char *command;
+ char *command;
/* The next element. */
struct grub_command_list *next;
/*
* 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
* it under the terms of the GNU General Public License as published by
#ifndef KERNEL_TIME_HEADER
#define KERNEL_TIME_HEADER 1
+#include <grub/symbol.h>
+
#ifdef GRUB_UTIL
# include <time.h>
# define GRUB_TICKS_PER_SECOND CLOCKS_PER_SEC
#endif
/* 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 */
/*
* 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
* it under the terms of the GNU General Public License as published by
static int grub_loader_loaded;
+int
+grub_loader_is_loaded (void)
+{
+ return grub_loader_loaded;
+}
+
void
grub_loader_set (grub_err_t (*boot) (void),
grub_err_t (*unload) (void))
/*
* 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
* it under the terms of the GNU General Public License as published by
#include <grub/normal.h>
#include <grub/term.h>
#include <grub/misc.h>
+#include <grub/loader.h>
+#include <grub/machine/time.h>
/* FIXME: These below are all runaround. */
Press enter to boot the selected OS, \'e\' to edit the\n\
commands before booting, or \'c\' for a command-line.");
if (nested)
- grub_printf ("\
+ grub_printf ("\n\
ESC to return previous menu.");
}
run_menu (grub_menu_t menu, int nested)
{
int first, offset;
+ unsigned long saved_time;
grub_setcursor (0);
init_page (nested);
print_entries (menu, first, offset);
grub_refresh ();
+
+ /* Initialize the time. */
+ saved_time = grub_get_rtc ();
while (1)
{
int c;
- c = GRUB_TERM_ASCII_CHAR (grub_getkey ());
- switch (c)
+ if (menu->timeout > 0)
{
- case 16:
- case '^':
- if (offset > 0)
+ unsigned long current_time;
+
+ current_time = grub_get_rtc ();
+ if (current_time - saved_time >= GRUB_TICKS_PER_SECOND)
{
- print_entry (4 + offset, 0, get_entry (menu, first + offset));
- offset--;
- print_entry (4 + offset, 1, get_entry (menu, first + offset));
+ menu->timeout--;
+ saved_time = current_time;
}
- else if (first > 0)
+
+ 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)
{
- first--;
- print_entries (menu, first, offset);
+ grub_gotoxy (3, 22);
+ grub_printf (" ");
+ menu->timeout = -1;
+ menu->fallback_entry = -1;
+ grub_gotoxy (74, 4 + offset);
}
- break;
-
- case 14:
- case 'v':
- if (menu->size > first + offset + 1)
+
+ switch (c)
{
- if (offset < 11)
+ case 16:
+ case '^':
+ if (offset > 0)
{
print_entry (4 + offset, 0,
get_entry (menu, first + offset));
- offset++;
+ offset--;
print_entry (4 + offset, 1,
get_entry (menu, first + offset));
}
- else
+ else if (first > 0)
{
- first++;
+ first--;
print_entries (menu, first, offset);
}
- }
- break;
-
- case '\n':
- case '\r':
- case 6:
- grub_setcursor (1);
- return first + offset;
-
- case '\e':
- if (nested)
- {
+ break;
+
+ case 14:
+ case 'v':
+ if (menu->size > first + offset + 1)
+ {
+ if (offset < 11)
+ {
+ print_entry (4 + offset, 0,
+ get_entry (menu, first + offset));
+ 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);
+ return first + offset;
+
+ case '\e':
+ if (nested)
+ {
+ grub_setcursor (1);
+ return -1;
+ }
+ break;
+
+ case 'c':
grub_setcursor (1);
- return -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;
+ /* Never reach here. */
+ return -1;
+}
- default:
+/* 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;
}
- grub_refresh ();
+ if (! (c->flags & GRUB_COMMAND_FLAG_NO_ECHO))
+ grub_printf ("%s\n", cl->command);
+
+ if (grub_command_execute (cl->command) != 0)
+ break;
}
-
- /* Never reach here. */
- return -1;
+
+ if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
+ /* Implicit execution of boot, only if something is loaded. */
+ grub_command_execute ("boot");
}
void
while (1)
{
int boot_entry;
+ grub_menu_entry_t e;
boot_entry = run_menu (menu, nested);
if (boot_entry < 0)
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 ();
+ }
}
}