* conf/Makefile.common (CPPFLAGS_KERNEL): Add -DGRUB_KERNEL=1.

* include/grub/dl.h (GRUB_MOD_INIT), (GRUB_MOD_FINI): Define
	functions when compiling for kernel.
This commit is contained in:
Vladimir Serbinenko 2013-10-25 16:07:01 +02:00
parent ea899a5760
commit af81ed880d
13 changed files with 27 additions and 93 deletions

View file

@ -1,3 +1,9 @@
2013-10-25 Vladimir Serbinenko <phcoder@gmail.com>
* conf/Makefile.common (CPPFLAGS_KERNEL): Add -DGRUB_KERNEL=1.
* include/grub/dl.h (GRUB_MOD_INIT), (GRUB_MOD_FINI): Define
functions when compiling for kernel.
2013-10-25 Vladimir Serbinenko <phcoder@gmail.com> 2013-10-25 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/lib/progress.c (grub_file_progress_hook_real): Cast to * grub-core/lib/progress.c (grub_file_progress_hook_real): Cast to

View file

@ -74,7 +74,7 @@ endif
CFLAGS_KERNEL = $(CFLAGS_CPU) $(CFLAGS_PLATFORM) -ffreestanding CFLAGS_KERNEL = $(CFLAGS_CPU) $(CFLAGS_PLATFORM) -ffreestanding
LDFLAGS_KERNEL = $(LDFLAGS_CPU) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -static-libgcc LDFLAGS_KERNEL = $(LDFLAGS_CPU) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -static-libgcc
CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1
CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
if COND_CYGWIN if COND_CYGWIN
STRIPFLAGS_KERNEL = -F elf32-i386 -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version STRIPFLAGS_KERNEL = -F elf32-i386 -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version

View file

@ -183,22 +183,14 @@ grub_cmd_boot (struct grub_command *cmd __attribute__ ((unused)),
static grub_command_t cmd_boot; static grub_command_t cmd_boot;
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
void grub_boot_init (void)
#else
GRUB_MOD_INIT(boot) GRUB_MOD_INIT(boot)
#endif
{ {
cmd_boot = cmd_boot =
grub_register_command ("boot", grub_cmd_boot, grub_register_command ("boot", grub_cmd_boot,
0, N_("Boot an operating system.")); 0, N_("Boot an operating system."));
} }
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
void grub_boot_fini (void)
#else
GRUB_MOD_FINI(boot) GRUB_MOD_FINI(boot)
#endif
{ {
grub_unregister_command (cmd_boot); grub_unregister_command (cmd_boot);
} }

View file

@ -293,21 +293,13 @@ grub_cmd_keymap (struct grub_command *cmd __attribute__ ((unused)),
static grub_command_t cmd; static grub_command_t cmd;
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
void grub_keylayouts_init (void)
#else
GRUB_MOD_INIT(keylayouts) GRUB_MOD_INIT(keylayouts)
#endif
{ {
cmd = grub_register_command ("keymap", grub_cmd_keymap, cmd = grub_register_command ("keymap", grub_cmd_keymap,
0, N_("Load a keyboard layout.")); 0, N_("Load a keyboard layout."));
} }
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
void grub_keylayouts_fini (void)
#else
GRUB_MOD_FINI(keylayouts) GRUB_MOD_FINI(keylayouts)
#endif
{ {
grub_unregister_command (cmd); grub_unregister_command (cmd);
} }

View file

@ -646,22 +646,14 @@ static struct grub_term_input grub_at_keyboard_term =
.getkey = grub_at_keyboard_getkey .getkey = grub_at_keyboard_getkey
}; };
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
void grub_at_keyboard_init (void)
#else
GRUB_MOD_INIT(at_keyboard) GRUB_MOD_INIT(at_keyboard)
#endif
{ {
grub_term_register_input ("at_keyboard", &grub_at_keyboard_term); grub_term_register_input ("at_keyboard", &grub_at_keyboard_term);
grub_loader_register_preboot_hook (grub_at_fini_hw, grub_at_restore_hw, grub_loader_register_preboot_hook (grub_at_fini_hw, grub_at_restore_hw,
GRUB_LOADER_PREBOOT_HOOK_PRIO_CONSOLE); GRUB_LOADER_PREBOOT_HOOK_PRIO_CONSOLE);
} }
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
void grub_at_keyboard_fini (void)
#else
GRUB_MOD_FINI(at_keyboard) GRUB_MOD_FINI(at_keyboard)
#endif
{ {
grub_keyboard_controller_fini (NULL); grub_keyboard_controller_fini (NULL);
grub_term_unregister_input (&grub_at_keyboard_term); grub_term_unregister_input (&grub_at_keyboard_term);

View file

@ -1132,20 +1132,12 @@ grub_gfxterm_get_dimensions (unsigned *width, unsigned *height)
*height = window.height; *height = window.height;
} }
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_COREBOOT)
void grub_gfxterm_init (void)
#else
GRUB_MOD_INIT(gfxterm) GRUB_MOD_INIT(gfxterm)
#endif
{ {
grub_term_register_output ("gfxterm", &grub_video_term); grub_term_register_output ("gfxterm", &grub_video_term);
} }
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_COEBOOT)
void grub_gfxterm_fini (void)
#else
GRUB_MOD_FINI(gfxterm) GRUB_MOD_FINI(gfxterm)
#endif
{ {
grub_term_unregister_output (&grub_video_term); grub_term_unregister_output (&grub_video_term);
} }

View file

@ -270,15 +270,9 @@ static struct grub_term_output grub_vga_text_term =
.progress_update_divisor = GRUB_PROGRESS_FAST .progress_update_divisor = GRUB_PROGRESS_FAST
}; };
/* FIXME: this is was too spaghetti. */
#ifndef MODE_MDA #ifndef MODE_MDA
#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_MULTIBOOT)
void grub_vga_text_init (void)
#else
GRUB_MOD_INIT(vga_text) GRUB_MOD_INIT(vga_text)
#endif
{ {
#ifdef GRUB_MACHINE_COREBOOT #ifdef GRUB_MACHINE_COREBOOT
if (!grub_video_coreboot_fbtable) if (!grub_video_coreboot_fbtable)
@ -286,11 +280,7 @@ GRUB_MOD_INIT(vga_text)
grub_term_register_output ("vga_text", &grub_vga_text_term); grub_term_register_output ("vga_text", &grub_vga_text_term);
} }
#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_MULTIBOOT)
void grub_vga_text_fini (void)
#else
GRUB_MOD_FINI(vga_text) GRUB_MOD_FINI(vga_text)
#endif
{ {
grub_term_unregister_output (&grub_vga_text_term); grub_term_unregister_output (&grub_vga_text_term);
} }

View file

@ -379,11 +379,7 @@ grub_serial_unregister_driver (struct grub_serial_driver *driver)
static grub_extcmd_t cmd; static grub_extcmd_t cmd;
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
void grub_serial_init (void)
#else
GRUB_MOD_INIT(serial) GRUB_MOD_INIT(serial)
#endif
{ {
cmd = grub_register_extcmd ("serial", grub_cmd_serial, 0, cmd = grub_register_extcmd ("serial", grub_cmd_serial, 0,
N_("[OPTIONS...]"), N_("[OPTIONS...]"),
@ -410,11 +406,7 @@ GRUB_MOD_INIT(serial)
#endif #endif
} }
#if defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS)
void grub_serial_fini (void)
#else
GRUB_MOD_FINI(serial) GRUB_MOD_FINI(serial)
#endif
{ {
while (grub_serial_ports) while (grub_serial_ports)
grub_serial_unregister (grub_serial_ports); grub_serial_unregister (grub_serial_ports);

View file

@ -763,13 +763,7 @@ grub_cmd_terminfo (grub_extcmd_context_t ctxt, int argc, char **args)
static grub_extcmd_t cmd; static grub_extcmd_t cmd;
#if defined (GRUB_MACHINE_IEEE1275) || defined (GRUB_MACHINE_MIPS_LOONGSON) \
|| defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_ARC) \
|| defined (GRUB_MACHINE_UBOOT)
void grub_terminfo_init (void)
#else
GRUB_MOD_INIT(terminfo) GRUB_MOD_INIT(terminfo)
#endif
{ {
cmd = grub_register_extcmd ("terminfo", grub_cmd_terminfo, 0, cmd = grub_register_extcmd ("terminfo", grub_cmd_terminfo, 0,
N_("[[-a|-u|-v] [-g WxH] TERM [TYPE]]"), N_("[[-a|-u|-v] [-g WxH] TERM [TYPE]]"),
@ -777,11 +771,7 @@ GRUB_MOD_INIT(terminfo)
options); options);
} }
#if defined (GRUB_MACHINE_IEEE1275) || defined (GRUB_MACHINE_MIPS_LOONGSON) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_ARC)
void grub_terminfo_fini (void)
#else
GRUB_MOD_FINI(terminfo) GRUB_MOD_FINI(terminfo)
#endif
{ {
grub_unregister_extcmd (cmd); grub_unregister_extcmd (cmd);
} }

View file

@ -224,20 +224,12 @@ static struct grub_video_adapter grub_video_radeon_fuloong2e_adapter =
.next = 0 .next = 0
}; };
#ifdef GRUB_MACHINE_MIPS_LOONGSON
void grub_video_radeon_fuloong2e_init (void)
#else
GRUB_MOD_INIT(video_radeon_fuloong2e) GRUB_MOD_INIT(video_radeon_fuloong2e)
#endif
{ {
grub_video_register (&grub_video_radeon_fuloong2e_adapter); grub_video_register (&grub_video_radeon_fuloong2e_adapter);
} }
#ifdef GRUB_MACHINE_MIPS_LOONGSON
void grub_video_radeon_fuloong2e_fini (void)
#else
GRUB_MOD_FINI(video_radeon_fuloong2e) GRUB_MOD_FINI(video_radeon_fuloong2e)
#endif
{ {
grub_video_unregister (&grub_video_radeon_fuloong2e_adapter); grub_video_unregister (&grub_video_radeon_fuloong2e_adapter);
} }

View file

@ -437,20 +437,12 @@ static struct grub_video_adapter grub_video_sis315pro_adapter =
.next = 0 .next = 0
}; };
#ifdef GRUB_MACHINE_MIPS_LOONGSON
void grub_video_sis315pro_init (void)
#else
GRUB_MOD_INIT(video_sis315pro) GRUB_MOD_INIT(video_sis315pro)
#endif
{ {
grub_video_register (&grub_video_sis315pro_adapter); grub_video_register (&grub_video_sis315pro_adapter);
} }
#ifdef GRUB_MACHINE_MIPS_LOONGSON
void grub_video_sis315pro_fini (void)
#else
GRUB_MOD_FINI(video_sis315pro) GRUB_MOD_FINI(video_sis315pro)
#endif
{ {
grub_video_unregister (&grub_video_sis315pro_adapter); grub_video_unregister (&grub_video_sis315pro_adapter);
} }

View file

@ -796,20 +796,12 @@ static struct grub_video_adapter grub_video_sm712_adapter =
.next = 0 .next = 0
}; };
#ifdef GRUB_MACHINE_MIPS_LOONGSON
void grub_video_sm712_init (void)
#else
GRUB_MOD_INIT(video_sm712) GRUB_MOD_INIT(video_sm712)
#endif
{ {
grub_video_register (&grub_video_sm712_adapter); grub_video_register (&grub_video_sm712_adapter);
} }
#ifdef GRUB_MACHINE_MIPS_LOONGSON
void grub_video_sm712_fini (void)
#else
GRUB_MOD_FINI(video_sm712) GRUB_MOD_FINI(video_sm712)
#endif
{ {
grub_video_unregister (&grub_video_sm712_adapter); grub_video_unregister (&grub_video_sm712_adapter);
} }

View file

@ -35,25 +35,38 @@
*/ */
#ifndef ASM_FILE #ifndef ASM_FILE
#if !defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU)
#ifndef GRUB_MOD_INIT #ifndef GRUB_MOD_INIT
#if !defined (GRUB_UTIL) && !defined (GRUB_MACHINE_EMU) && !defined (GRUB_KERNEL)
#define GRUB_MOD_INIT(name) \ #define GRUB_MOD_INIT(name) \
static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \ static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
static void \ static void \
grub_mod_init (grub_dl_t mod __attribute__ ((unused))) grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
#endif
#ifndef GRUB_MOD_FINI
#define GRUB_MOD_FINI(name) \ #define GRUB_MOD_FINI(name) \
static void grub_mod_fini (void) __attribute__ ((used)); \ static void grub_mod_fini (void) __attribute__ ((used)); \
static void \ static void \
grub_mod_fini (void) grub_mod_fini (void)
#endif
#elif defined (GRUB_KERNEL)
#define GRUB_MOD_INIT(name) \
static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
void \
grub_##name##_init (void) { grub_mod_init (0); } \
static void \
grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
#define GRUB_MOD_FINI(name) \
static void grub_mod_fini (void) __attribute__ ((used)); \
void \
grub_##name##_fini (void) { grub_mod_fini (); } \
static void \
grub_mod_fini (void)
#else #else
#ifndef GRUB_MOD_INIT
#define GRUB_MOD_INIT(name) \ #define GRUB_MOD_INIT(name) \
static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \ static void grub_mod_init (grub_dl_t mod __attribute__ ((unused))) __attribute__ ((used)); \
void grub_##name##_init (void); \ void grub_##name##_init (void); \
@ -61,9 +74,7 @@ void \
grub_##name##_init (void) { grub_mod_init (0); } \ grub_##name##_init (void) { grub_mod_init (0); } \
static void \ static void \
grub_mod_init (grub_dl_t mod __attribute__ ((unused))) grub_mod_init (grub_dl_t mod __attribute__ ((unused)))
#endif
#ifndef GRUB_MOD_FINI
#define GRUB_MOD_FINI(name) \ #define GRUB_MOD_FINI(name) \
static void grub_mod_fini (void) __attribute__ ((used)); \ static void grub_mod_fini (void) __attribute__ ((used)); \
void grub_##name##_fini (void); \ void grub_##name##_fini (void); \
@ -71,6 +82,7 @@ void \
grub_##name##_fini (void) { grub_mod_fini (); } \ grub_##name##_fini (void) { grub_mod_fini (); } \
static void \ static void \
grub_mod_fini (void) grub_mod_fini (void)
#endif #endif
#endif #endif