2009-04-14 Bean <bean123ch@gmail.com>

* Makefile.in (pkglib_DATA): Add handler.lst.
	(handler.lst): New rule.

	* conf/i386-pc.rmk (normal_mod_SOURCES): Add normal/handler.c.
	* conf/i386-coreboot.rmk: Likewise.
	* conf/i386-ieee1275.rmk: Likewise.
	* conf/i386-efi.rmk: Likewise.
	* conf/x86_64-efi.rmk: Likewise.
	* conf/powerpc-ieee1275.rmk: Likewise.
	* conf/sparc64-ieee1275.rmk: Likewise.

	* genhandlerlist.sh: New file.

	* genmk.rb: Add rules to generate handler.lst.

	* include/grub/normal.h (grub_file_getline): New function definition.
	(read_handler_list): Likewise.
	(free_handler_list): Likewise.

	* include/grub/term.h (grub_term_register_input): Add name parameter
	for auto generation of handler.lst.
	(grub_term_register_output): Likewise.

	* normal/handler.c: New file.

	* normal/main.c (get_line): Renamed to grub_file_getline.
	(read_config_file): Use the newly renamed grub_file_getline.
	(read_command_list): Likewise.
	(read_fs_list): Likewise.
	(grub_normal_execute): Call read_handler_list to parse handler.lst.
	(GRUB_MOD_FINI): Call free_handler_list to free handler list.

	* term/efi/console.c (grub_console_init): Add name parameter for auto
	generation of handler.lst.
	* term/gfxterm.c: Likewise.
	* term/i386/pc/at_keyboard.c: Likewise.
	* term/i386/pc/console.c: Likewise.
	* term/i386/pc/serial.c: Likewise.
	* term/i386/pc/vesafb.c: Likewise.
	* term/i386/pc/vga.c: Likewise.
	* term/i386/pc/vga_text.c: Likewise.
	* term/ieee1275/ofconsole.c: Likewise.
	* term/usb_keyboard.c: Likewise.
This commit is contained in:
bean 2009-04-14 18:12:14 +00:00
parent 33c846be29
commit d05f0df3eb
26 changed files with 352 additions and 34 deletions

View File

@ -1,3 +1,49 @@
2009-04-14 Bean <bean123ch@gmail.com>
* Makefile.in (pkglib_DATA): Add handler.lst.
(handler.lst): New rule.
* conf/i386-pc.rmk (normal_mod_SOURCES): Add normal/handler.c.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-ieee1275.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/sparc64-ieee1275.rmk: Likewise.
* genhandlerlist.sh: New file.
* genmk.rb: Add rules to generate handler.lst.
* include/grub/normal.h (grub_file_getline): New function definition.
(read_handler_list): Likewise.
(free_handler_list): Likewise.
* include/grub/term.h (grub_term_register_input): Add name parameter
for auto generation of handler.lst.
(grub_term_register_output): Likewise.
* normal/handler.c: New file.
* normal/main.c (get_line): Renamed to grub_file_getline.
(read_config_file): Use the newly renamed grub_file_getline.
(read_command_list): Likewise.
(read_fs_list): Likewise.
(grub_normal_execute): Call read_handler_list to parse handler.lst.
(GRUB_MOD_FINI): Call free_handler_list to free handler list.
* term/efi/console.c (grub_console_init): Add name parameter for auto
generation of handler.lst.
* term/gfxterm.c: Likewise.
* term/i386/pc/at_keyboard.c: Likewise.
* term/i386/pc/console.c: Likewise.
* term/i386/pc/serial.c: Likewise.
* term/i386/pc/vesafb.c: Likewise.
* term/i386/pc/vga.c: Likewise.
* term/i386/pc/vga_text.c: Likewise.
* term/ieee1275/ofconsole.c: Likewise.
* term/usb_keyboard.c: Likewise.
2009-04-14 Bean <bean123ch@gmail.com>
* util/grub-pe2elf.c (write_symbol_table): Terminate short name symbol

View File

@ -139,7 +139,7 @@ include $(srcdir)/conf/$(target_cpu)-$(platform).mk
### General targets.
CLEANFILES += $(pkglib_DATA) $(pkgdata_DATA)
pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst
pkglib_DATA += moddep.lst command.lst fs.lst partmap.lst handler.lst
moddep.lst: $(DEFSYMFILES) $(UNDSYMFILES) genmoddep.awk
cat $(DEFSYMFILES) /dev/null \
| $(AWK) -f $(srcdir)/genmoddep.awk $(UNDSYMFILES) > $@ \
@ -154,6 +154,9 @@ fs.lst: $(FSFILES)
partmap.lst: $(PARTMAPFILES)
cat $^ /dev/null | sort > $@
handler.lst: $(HANDLERFILES)
cat $^ /dev/null | sort > $@
ifeq (, $(UNIFONT_BDF))
else

View File

@ -117,7 +117,7 @@ linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# Please put arch dependant part of normal.mod at the end of list to
# keep it simpler to update to different architectures.
#
normal_mod_SOURCES = normal/cmdline.c normal/command.c \
normal_mod_SOURCES = normal/cmdline.c normal/command.c normal/handler.c \
normal/completion.c normal/datetime.c normal/execute.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_text.c \

View File

@ -121,7 +121,7 @@ kernel_syms.lst: $(addprefix include/grub/,$(kernel_mod_HEADERS)) config.h genke
# Please put arch dependant part of normal.mod at the end of list to
# keep it simpler to update to different architectures.
#
normal_mod_SOURCES = normal/cmdline.c normal/command.c \
normal_mod_SOURCES = normal/cmdline.c normal/command.c normal/handler.c \
normal/completion.c normal/datetime.c normal/execute.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_text.c \

View File

@ -113,7 +113,7 @@ pkglib_MODULES = normal.mod halt.mod reboot.mod suspend.mod \
# Please put arch dependant part of normal.mod at the end of list to
# keep it simpler to update to different architectures.
#
normal_mod_SOURCES = normal/cmdline.c normal/command.c \
normal_mod_SOURCES = normal/cmdline.c normal/command.c normal/handler.c \
normal/completion.c normal/datetime.c normal/execute.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_text.c \

View File

@ -212,7 +212,7 @@ linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# keep it simpler to update to different architectures.
#
normal_mod_SOURCES = normal/cmdline.c normal/command.c normal/datetime.c \
normal/completion.c normal/execute.c \
normal/completion.c normal/execute.c normal/handler.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_text.c \
normal/color.c \

View File

@ -128,7 +128,7 @@ linux_mod_LDFLAGS = $(COMMON_LDFLAGS)
# keep it simpler to update to different architectures.
#
normal_mod_SOURCES = normal/cmdline.c normal/command.c normal/datetime.c \
normal/completion.c normal/execute.c \
normal/completion.c normal/execute.c normal/handler.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_text.c \
normal/color.c \

View File

@ -169,7 +169,7 @@ sfs_mod_LDFLAGS = $(COMMON_LDFLAGS)
normal_mod_SOURCES = normal/arg.c normal/cmdline.c normal/command.c \
normal/datetime.c normal/completion.c normal/execute.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_text.c \
normal/handler.c normal/menu_text.c \
normal/color.c \
normal/menu_viewer.c normal/menu_entry.c \
normal/misc.c grub_script.tab.c \

View File

@ -124,7 +124,7 @@ kernel_syms.lst: $(addprefix include/grub/,$(kernel_mod_HEADERS)) config.h genke
# Please put arch dependant part of normal.mod at the end of list to
# keep it simpler to update to different architectures.
#
normal_mod_SOURCES = normal/cmdline.c normal/command.c \
normal_mod_SOURCES = normal/cmdline.c normal/command.c normal/handler.c \
normal/completion.c normal/datetime.c normal/execute.c \
normal/function.c normal/lexer.c normal/main.c normal/menu.c \
normal/menu_text.c \

23
genhandlerlist.sh Normal file
View File

@ -0,0 +1,23 @@
#! /bin/sh
#
# Copyright (C) 2009 Free Software Foundation, Inc.
#
# This script is free software; the author
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
# Read source code from stdin and detect command names.
module=$1
grep -v "^#" | sed -n \
-e "/grub_parser_register *( *\"/{s/.*( *\"\([^\"]*\)\".*/parser.\1: $module/;p;}" \
-e "/grub_reader_register *( *\"/{s/.*( *\"\([^\"]*\)\".*/reader.\1: $module/;p;}" \
-e "/grub_term_register_input *( *\"/{s/.*( *\"\([^\"]*\)\".*/terminal_input.\1: $module/;p;}" \
-e "/grub_term_register_output *( *\"/{s/.*( *\"\([^\"]*\)\".*/terminal_output.\1: $module/;p;}" \
-e "/grub_menu_viewer_register *( *\"/{s/.*( *\"\([^\"]*\)\".*/menu_viewer.\1: $module/;p;}"

View File

@ -143,6 +143,7 @@ endif
command = 'cmd-' + obj.suffix('lst')
fs = 'fs-' + obj.suffix('lst')
partmap = 'partmap-' + obj.suffix('lst')
handler = 'handler-' + obj.suffix('lst')
dep = deps[i]
flag = if /\.c$/ =~ src then 'CFLAGS' else 'ASFLAGS' end
extra_flags = if /\.S$/ =~ src then '-DASM_FILE=1' else '' end
@ -152,10 +153,11 @@ endif
$(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $<
-include #{dep}
CLEANFILES += #{command} #{fs} #{partmap}
CLEANFILES += #{command} #{fs} #{partmap} #{handler}
COMMANDFILES += #{command}
FSFILES += #{fs}
PARTMAPFILES += #{partmap}
HANDLERFILES += #{handler}
#{command}: #{src} $(#{src}_DEPENDENCIES) gencmdlist.sh
set -e; \
@ -172,6 +174,10 @@ PARTMAPFILES += #{partmap}
$(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \
| sh $(srcdir)/genpartmaplist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1)
#{handler}: #{src} $(#{src}_DEPENDENCIES) genhandlerlist.sh
set -e; \
$(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -E $< \
| sh $(srcdir)/genhandlerlist.sh #{symbolic_name} > $@ || (rm -f $@; exit 1)
"
end.join('')

View File

@ -26,6 +26,7 @@
#include <grub/env.h>
#include <grub/menu.h>
#include <grub/command.h>
#include <grub/file.h>
/* The maximum size of a command-line. */
#define GRUB_MAX_CMDLINE 1600
@ -103,6 +104,10 @@ char *grub_env_write_color_highlight (struct grub_env_var *var, const char *val)
void grub_parse_color_name_pair (grub_uint8_t *ret, const char *name);
void grub_wait_after_message (void);
char *grub_file_getline (grub_file_t file);
void read_handler_list (void);
void free_handler_list (void);
#ifdef GRUB_UTIL
void grub_normal_init (void);
void grub_normal_fini (void);

View File

@ -219,13 +219,15 @@ extern struct grub_handler_class EXPORT_VAR(grub_term_input_class);
extern struct grub_handler_class EXPORT_VAR(grub_term_output_class);
static inline void
grub_term_register_input (grub_term_input_t term)
grub_term_register_input (const char *name __attribute__ ((unused)),
grub_term_input_t term)
{
grub_handler_register (&grub_term_input_class, GRUB_AS_HANDLER (term));
}
static inline void
grub_term_register_output (grub_term_output_t term)
grub_term_register_output (const char *name __attribute__ ((unused)),
grub_term_output_t term)
{
grub_handler_register (&grub_term_output_class, GRUB_AS_HANDLER (term));
}

232
normal/handler.c Normal file
View File

@ -0,0 +1,232 @@
/* handler.c - support handler loading */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2009 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/env.h>
#include <grub/misc.h>
#include <grub/command.h>
#include <grub/handler.h>
#include <grub/normal.h>
struct grub_handler_list
{
struct grub_handler_list *next;
char *name;
grub_command_t cmd;
};
static grub_list_t handler_list;
static grub_err_t
grub_handler_cmd (struct grub_command *cmd,
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
char *p;
grub_handler_class_t class;
grub_handler_t handler;
p = grub_strchr (cmd->name, '.');
if (! p)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid command name");
if (cmd->data)
{
if (! grub_dl_get (cmd->data))
{
grub_dl_t mod;
mod = grub_dl_load (cmd->data);
if (mod)
grub_dl_ref (mod);
else
return grub_errno;
}
grub_free (cmd->data);
cmd->data = 0;
}
*p = 0;
class = grub_named_list_find (GRUB_AS_NAMED_LIST (grub_handler_class_list),
cmd->name);
*p = '.';
if (! class)
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "class not found");
handler = grub_named_list_find (GRUB_AS_NAMED_LIST (class->handler_list),
p + 1);
if (! handler)
return grub_error (GRUB_ERR_FILE_NOT_FOUND, "handler not found");
grub_handler_set_current (class, handler);
return 0;
}
static void
insert_handler (char *name, char *module)
{
struct grub_handler_list *item;
char *data;
if (grub_command_find (name))
return;
item = grub_malloc (sizeof (*item));
if (! item)
return;
item->name = grub_strdup (name);
if (! item->name)
{
grub_free (item);
return;
}
if (module)
{
data = grub_strdup (module);
if (! data)
{
grub_free (item->name);
grub_free (item);
return;
}
}
else
data = 0;
item->cmd = grub_register_command (item->name, grub_handler_cmd, 0,
"Set active handler");
if (! item->cmd)
{
grub_free (data);
grub_free (item->name);
grub_free (item);
return;
}
item->cmd->data = data;
grub_list_push (&handler_list, GRUB_AS_LIST (item));
}
/* Read the file handler.lst for auto-loading. */
void
read_handler_list (void)
{
const char *prefix;
static int first_time = 1;
const char *class_name;
auto int iterate_handler (grub_handler_t handler);
int iterate_handler (grub_handler_t handler)
{
char name[grub_strlen (class_name) + grub_strlen (handler->name) + 2];
grub_strcpy (name, class_name);
grub_strcat (name, ".");
grub_strcat (name, handler->name);
insert_handler (name, 0);
return 0;
}
auto int iterate_class (grub_handler_class_t class);
int iterate_class (grub_handler_class_t class)
{
class_name = class->name;
grub_list_iterate (GRUB_AS_LIST (class->handler_list),
(grub_list_hook_t) iterate_handler);
return 0;
}
/* Make sure that this function does not get executed twice. */
if (! first_time)
return;
first_time = 0;
prefix = grub_env_get ("prefix");
if (prefix)
{
char *filename;
filename = grub_malloc (grub_strlen (prefix) + sizeof ("/handler.lst"));
if (filename)
{
grub_file_t file;
grub_sprintf (filename, "%s/handler.lst", prefix);
file = grub_file_open (filename);
if (file)
{
char *buf = 0;
for (;; grub_free(buf))
{
char *p;
buf = grub_file_getline (file);
if (! buf)
break;
if (! grub_isgraph (buf[0]))
continue;
p = grub_strchr (buf, ':');
if (! p)
continue;
*p = '\0';
while (*++p == ' ')
;
insert_handler (buf, p);
}
grub_file_close (file);
}
grub_free (filename);
}
}
grub_list_iterate (GRUB_AS_LIST (grub_handler_class_list),
(grub_list_hook_t) iterate_class);
/* Ignore errors. */
grub_errno = GRUB_ERR_NONE;
}
void
free_handler_list (void)
{
struct grub_handler_list *item;
while ((item = grub_list_pop (&handler_list)) != 0)
{
grub_free (item->cmd->data);
grub_unregister_command (item->cmd);
grub_free (item->name);
grub_free (item);
}
}

View File

@ -37,8 +37,8 @@ static grub_fs_module_list_t fs_module_list = 0;
#define GRUB_DEFAULT_HISTORY_SIZE 50
/* Read a line from the file FILE. */
static char *
get_line (grub_file_t file)
char *
grub_file_getline (grub_file_t file)
{
char c;
int pos = 0;
@ -310,7 +310,7 @@ read_config_file (const char *config, int nested)
{
currline++;
*line = get_line (file);
*line = grub_file_getline (file);
if (! *line)
return grub_errno;
@ -343,7 +343,7 @@ read_config_file (const char *config, int nested)
int startline;
char *cmdline;
cmdline = get_line (file);
cmdline = grub_file_getline (file);
if (!cmdline)
break;
@ -475,7 +475,7 @@ read_command_list (void)
grub_command_t cmd;
int prio = 0;
buf = get_line (file);
buf = grub_file_getline (file);
if (! buf)
break;
@ -594,7 +594,7 @@ read_fs_list (void)
char *q;
grub_fs_module_list_t fs_mod;
buf = get_line (file);
buf = grub_file_getline (file);
if (! buf)
break;
@ -650,6 +650,7 @@ grub_normal_execute (const char *config, int nested, int batch)
read_command_list ();
read_fs_list ();
read_handler_list ();
if (config)
{
@ -754,4 +755,5 @@ GRUB_MOD_FINI(normal)
{
grub_set_history (0);
grub_unregister_command (cmd_normal);
free_handler_list ();
}

View File

@ -366,8 +366,8 @@ grub_console_init (void)
return;
}
grub_term_register_input (&grub_console_term_input);
grub_term_register_output (&grub_console_term_output);
grub_term_register_input ("console", &grub_console_term_input);
grub_term_register_output ("console", &grub_console_term_output);
}
void

View File

@ -1155,7 +1155,7 @@ static grub_command_t cmd;
GRUB_MOD_INIT(term_gfxterm)
{
my_mod = mod;
grub_term_register_output (&grub_video_term);
grub_term_register_output ("gfxterm", &grub_video_term);
cmd = grub_register_command ("background_image",
grub_gfxterm_background_image_cmd,
0, "Load background image for active terminal");

View File

@ -226,7 +226,7 @@ static struct grub_term_input grub_at_keyboard_term =
GRUB_MOD_INIT(at_keyboard)
{
grub_term_register_input (&grub_at_keyboard_term);
grub_term_register_input ("at_keyboard", &grub_at_keyboard_term);
}
GRUB_MOD_FINI(at_keyboard)

View File

@ -46,8 +46,8 @@ static struct grub_term_output grub_console_term_output =
void
grub_console_init (void)
{
grub_term_register_output (&grub_console_term_output);
grub_term_register_input (&grub_console_term_input);
grub_term_register_output ("console", &grub_console_term_output);
grub_term_register_input ("console", &grub_console_term_input);
}
void

View File

@ -577,8 +577,8 @@ grub_cmd_serial (grub_extcmd_t cmd,
/* Register terminal if not yet registered. */
if (registered == 0)
{
grub_term_register_input (&grub_serial_term_input);
grub_term_register_output (&grub_serial_term_output);
grub_term_register_input ("serial", &grub_serial_term_input);
grub_term_register_output ("serial", &grub_serial_term_output);
registered = 1;
}
}

View File

@ -599,7 +599,7 @@ static struct grub_term_output grub_vesafb_term =
GRUB_MOD_INIT(vesafb)
{
my_mod = mod;
grub_term_register_output (&grub_vesafb_term);
grub_term_register_output ("vesafb", &grub_vesafb_term);
}
GRUB_MOD_FINI(vesafb)

View File

@ -25,7 +25,6 @@
#include <grub/types.h>
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/normal.h>
#include <grub/font.h>
#define DEBUG_VGA 0
@ -509,7 +508,7 @@ GRUB_MOD_INIT(vga)
#ifndef GRUB_UTIL
my_mod = mod;
#endif
grub_term_register_output (&grub_vga_term);
grub_term_register_output ("vga", &grub_vga_term);
}
GRUB_MOD_FINI(vga)

View File

@ -168,7 +168,7 @@ static struct grub_term_output grub_vga_text_term =
GRUB_MOD_INIT(vga_text)
{
grub_term_register_output (&grub_vga_text_term);
grub_term_register_output ("vga_text", &grub_vga_text_term);
}
GRUB_MOD_FINI(vga_text)

View File

@ -420,8 +420,8 @@ static struct grub_term_output grub_ofconsole_term_output =
void
grub_console_init (void)
{
grub_term_register_input (&grub_ofconsole_term_input);
grub_term_register_output (&grub_ofconsole_term_output);
grub_term_register_input ("ofconsole", &grub_ofconsole_term_input);
grub_term_register_output ("ofconsole", &grub_ofconsole_term_output);
}
void

View File

@ -247,7 +247,7 @@ GRUB_MOD_INIT(usb_keyboard)
(void) mod; /* To stop warning. */
grub_usb_hid ();
grub_term_register_input (&grub_usb_keyboard_term);
grub_term_register_input ("usb_keyboard", &grub_usb_keyboard_term);
}
GRUB_MOD_FINI(usb_keyboard)

View File

@ -374,8 +374,8 @@ static struct grub_term_output grub_ncurses_term_output =
void
grub_console_init (void)
{
grub_term_register_output (&grub_ncurses_term_output);
grub_term_register_input (&grub_ncurses_term_input);
grub_term_register_output ("console", &grub_ncurses_term_output);
grub_term_register_input ("console", &grub_ncurses_term_input);
grub_term_set_current_output (&grub_ncurses_term_output);
grub_term_set_current_input (&grub_ncurses_term_input);
}