for powerpc & i386-pc. This patch was more so started by Hollis
Blanchard getting multiboot 2 working for powerpc and I added to it
and cleaned it up.
One of the ideas with this patch is to keep everything under one
command for the user. So instead of having a "multiboot2" & "module2"
command, I created a proxy like mechanism so that you have only one
command for both multiboot 1 & 2 ... "multiboot". This is where
"loader/multiboot_loader.c" comes from. I could have integrated things
more but I figure the current approach will less likely break
anything.
So if your OS is multiboot 2 capable, the user would do the following
to load it up from a grub prompt:
grub> multiboot <location of kernel> <kernel args>
grub> module <some image> <multiboot tag> <image arguments>
grub> module <isome mage> <multiboot tag> <image arguments>
grub .....
The other thing that this patch does is it begins to make the
multiboot 1 code a bit more architecture agnostic so IF someone wanted
to implement it on another architecture they can.
A bit of file moving around and definition renaming is also apart of
this patch. I have also taken the time to make sure that it does not
break multiboot 1 loading on i386-pc. But mulitboot 2 may still need a
little more testing and work for i386-pc. Powerpc multiboot 2 has been
heavily tested and does work.
* geninitheader.sh: Process file specified in first parameter rather
than hardcoding grub_modules_init.lst.
* geninit.sh: Likewise. Also, construct header name dynamicaly rather
than hardcoding grub_modules_init.h.
* conf/common.rmk: Rename grub_modules_init.[ch] files associated with
grub-emu to grub_emu_init.[ch]. Add rules to build analogous
grub_probe_init.[ch] and grub_setup_init.[ch].
* conf/powerpc-ieee1275.rmk (grub_emu_DEPENDENCIES): Replace
grub_modules_init.h with grub_emu_init.h.
(grub_probe_DEPENDENCIES, grub_probe_SOURCES): Add new
grub_probe_init.[ch] files.
* conf/i386-efi.rmk: Likewise.
* conf/i386-pc.rmk: Likewise.
(grub_setup_DEPENDENCIES, grub_setup_SOURCES): Add new
grub_setup_init.[ch] files.
* util/grub-emu.c: Replace grub_modules_init.h with grub_emu_init.h.
* util/grub-probe.c: Include grub_probe_init.h. Use grub_init_all()
to initialize modules rather than a list of hardcoded functions.
* util/i386/pc/grub-setup.c: Include grub_setup_init.h. Use
grub_init_all() to initialize modules rather than a list of hardcoded
functions.
* conf/powerpc-ieee1275.rmk: Enable grub-mkdevicemap and grub-probe.
* include/grub/partition.h: Declare grub_apple_partition_map_init and
grub_apple_partition_map_fini.
* util/biosdisk.c
(grub_util_biosdisk_open): Replace BLKGETSIZE with BLKGETSIZE64 (needed
to access >2 TiB disks).
Print disk->total_sectors with %llu instead of %lu, since this
variable is always 64-bit (prevents wrong disk size from being displayed
on either >2 TiB disk or big-endian CPU).
(grub_util_biosdisk_get_grub_dev): Convert gpt_partition_map handling
into a generic case that supports all (sane) partition maps.
Stop using grub_cpu_to_le32() on dos_part / bsd_part since it actually
breaks big-endian.
* util/grub-probe.c: Call grub_apple_partition_map_init() before probe()
and grub_apple_partition_map_fini() after that.
* conf/powerpc-ieee1275.rmk (kernel_elf_LDFLAGS): Link at 64KB.
* kern/powerpc/ieee1275/init.c (_end): Add declaration.
(_start): Likewise.
(grub_arch_modules_addr): Return address after `_end'.
* util/powerpc/ieee1275/grub-mkimage.c: Include grub/misc.h.
(load_modules): Use new parameter as `p_paddr' and `p_vaddr'.
(add_segments): Calculate `_end' from phdr size and location.
(ALIGN_UP): Moved to ...
* include/grub/misc.h: here.
* include/grub/powerpc/ieee1275/kernel.h (GRUB_IEEE1275_MOD_ALIGN):
New macro.
(GRUB_IEEE1275_MODULE_BASE): Removed.
* Makefile.in (enable_grub_emu): New variable.
* configure.ac (--enable-grub-emu): New option.
Do the checks for (n)curses only if `--enable-grub-emu' is requested.
* conf/i386-efi.rmk (sbin_UTILITIES): Add `grub-emu' only if requested.
* conf/i386-pc.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/sparc64-ieee1275.rmk (bin_UTILITIES): Likewise.
* commands/blocklist.c: New file.
* DISTLIST: Added commands/blocklist.c.
* term/efi/console.c (grub_console_highlight_color): Use a lighter
color for the background, and a daker color for the foreground.
(grub_console_checkkey): Return READ_KEY.
(grub_console_cls): Set the background to
GRUB_EFI_BACKGROUND_BLACK temporarily to clean out the screen.
* kern/efi/efi.c (grub_efi_exit_boot_services): New function.
* include/grub/i386/linux.h (struct linux_kernel_params): Fixed
the size of "padding5", "hd0_drive_info" and "hd1_drive_info".
* include/grub/efi/efi.h (grub_efi_exit_boot_services): New
prototype.
* include/grub/efi/api.h (GRUB_EFI_TEXT_ATTR): Do not shift
BG. The spec is wrong again.
* include/grub/normal.h [GRUB_UTIL] (grub_blocklist_init): New
prototype.
[GRUB_UTIL] (grub_blocklist_fini): Likewise.
* conf/i386-pc.rmk (grub_emu_SOURCES): Added
commands/blocklist.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise.
* conf/common.rmk (pkgdata_MODULES): Added blocklist.mod.
(blocklist_mod_SOURCES): New variable.
(blocklist_mod_CFLAGS): Likewise.
(blocklist_mod_LDFLAGS): Likewise.
Use the environment context in the menu. Remove the commands
"default" and "timeout", and use variables instead.
* normal/menu.c: Include grub/env.h.
(print_entry): Cast TITLE to silence gcc.
(get_timeout): New function.
(set_timeout): Likewise.
(get_entry_number): Likewise.
(run_menu): Use a default entry, a fallback entry and a timeout
in the environment variables "default", "fallback" and
"timeout". Also, tweak the default entry if it is not within the
current menu entries.
(grub_menu_run): Use a fallback entry in the environment variable
"fallback".
* normal/main.c (read_config_file): Do not initialize
NEWMENU->DEFAULT_ENTRY, NEWMENU->FALLBACK_ENTRY or
NEWMENU->TIMEOUT.
(grub_normal_execute): Use a data slot to store the menu.
* include/grub/normal.h (struct grub_menu): Removed default_entry,
fallback_entry and timeout.
(struct grub_menu_list): Removed.
(grub_menu_list_t): Likewise.
(struct grub_context): Likewise.
(grub_context_t): Likewise.
(grub_context_get): Likewise.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
(grub_default_init): Likewise.
(grub_default_fini): Likewise.
(grub_timeout_init): Likewise.
(grub_timeout_fini): Likewise.
* conf/sparc64-ieee1275.rmk (pkgdata_MODULES): Removed default.mod
and timeout.mod.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-pc.rmk (grub_emu_SOURCES): Removed commands/default.c,
commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/i386-efi.rmk (grub_emu_SOURCES): Removed
commands/default.c, commands/timeout.c and normal/context.c.
(normal_mod_SOURCES): Removed normal/context.c.
* conf/common.rmk (pkgdata_MODULES): Removed default.mod and
timeout.mod.
(default_mod_SOURCES): Removed.
(default_mod_CFLAGS): Likewise.
(default_mod_LDFLAGS): Likewise.
(timeout_mod_SOURCES): Removed.
(timeout_mod_CFLAGS): Likewise.
(timeout_mod_LDFLAGS): Likewise.
* DISTLIST: Removed commands/default.c, commands/timeout.c and
normal/context.c.
* commands/default.c: Removed.
* commands/timeout.c: Likewise.
* normal/context.c: Likewise.
* include/grub/parser.h: New file.
* kern/parser.c: Likewise.
* conf/i386-pc.rmk (kernel_img_SOURCES): Add `kern/parser.c'.
(grub_setup_SOURCES): Likewise.
(grub_probefs_SOURCES): Likewise.
(grub_emu_SOURCES): Likewise.
(kernel_img_HEADERS): Add `parser.h'.
* conf/powerpc-ieee1275.rmk (grubof_HEADERS): Add `parser.h'.
(grub_emu_SOURCES): Add `kern/parser.c'.
(grubof_SOURCES): Likewise.
* conf/sparc64-ieee1275.rmk (grubof_HEADERS): Add `parser.h'.
(grubof_SOURCES): Add `kern/parser.c'.
* include/grub/misc.h (grub_split_cmdline): Removed prototype.
* kern/misc.c (grub_split_cmdline): Removed function.
* kern/rescue.c: Include <grub/parser.h>.
(grub_enter_rescue_mode): Use `grub_parser_split_cmdline' instead
of `grub_split_cmdline'.
* normal/command.c: Include <grub/parser.h>.
(grub_command_execute): Use `grub_parser_split_cmdline' instead
of `grub_split_cmdline'.
* normal/completion.c: Include <grub/parser.h>.
(cmdline_state): New variable.
(iterate_dir): End the filename with a quote depending on the
command line state.
(get_state): new function.
(grub_normal_do_completion): Use `grub_parser_split_cmdline' to
split the arguments and determine the current argument. When the
argument string is not quoted, escape all spaces.
* DISTLIST: Replaced boot/powerpc/ieee1275/crt0.S and
boot/powerpc/ieee1275/cmain.c with kern/powerpc/ieee1275/crt0.S
and kern/powerpc/ieee1275/cmain.c, respectively.
* boot/powerpc/ieee1275/crt0.S: Moved to ...
* kern/powerpc/ieee1275/crt0.S: ... here.
* boot/powerpc/ieee1275/cmain.c: Moved to ...
* kern/powerpc/ieee1275/cmain.c: ... here.
* conf/powerpc-ieee1275.rmk (grubof_SOURCES): Use
kern/powerpc/ieee1275/crt0.S and kern/powerpc/ieee1275/cmain.c
instead of boot/powerpc/ieee1275/crt0.S and
boot/powerpc/ieee1275/cmain.c, respectively.
* boot/i386/pc/boot.S (lba_mode): Do not store the total number of
sectors. It was not used anyway.
* partmap/pc.c (pc_partition_map_iterate): Include the value of an
invalid magic in thre error.
* commands/search.c: New file.
* util/grub-emu.c (main): Call grub_search_init and
grub_search_fini.
* kern/rescue.c (grub_rescue_print_disks): Removed.
(grub_rescue_print_devices): New function.
(grub_rescue_cmd_ls): Use grub_device_iterate with
grub_rescue_print_devices instead of grub_disk_dev_iterate with
grub_rescue_print_disks.
* kern/partition.c (grub_partition_iterate): Return the result of
PARTMAP->ITERATE instead of GRUB_ERRNO.
* kern/device.c: Include grub/partition.h.
(grub_device_iterate): New function.
* include/grub/partition.h (grub_partition_iterate): Return int
instead of grub_err_t.
* include/grub/normal.h [GRUB_UTIL] (grub_search_init): New
prototype.
[GRUB_UTIL] (grub_search_fini): Likewise.
* include/grub/device.h (grub_device_iterate): New prototype.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Added
commands/search.c.
(pkgdata_MODULES): Added search.mod.
(search_mod_SOURCES): New variable.
(search_mod_CFLAGS): Likewise.
* conf/i386-pc.rmk (grub_emu_SOURCES): Added commands/search.c.
(pkgdata_MODULES): Added search.mod.
(search_mod_SOURCES): New variable.
(search_mod_CFLAGS): Likewise.
* commands/ls.c (grub_ls_list_disks): Renamed to ...
(grub_ls_list_devices): ... this, and use grub_device_iterate.
All callers changed.
* DISTLIST: Added commands/search.c.
* normal/misc.c: New file.
* DISTLIST: Added normal/misc.c.
* partmap/amiga.c (amiga_partition_map_iterate): Add an argument
DISK to HOOK. Call HOOK with DISK.
* partmap/apple.c (apple_partition_map_iterate): Likewise.
* partmap/pc.c (pc_partition_map_iterate): Likewise.
* partmap/sun.c (sun_partition_map_iterate): Likewise.
* normal/menu_entry.c (struct screen): Added a new member
"completion_shown".
(completion_buffer): New global variable.
(make_screen): Set SCREEN->COMPLETION_SHOWN to zero.
(store_completion): New function.
(complete): Likewise.
(clear_completions): Likewise.
(grub_menu_entry_run): If SCREEN->COMPLETION_SHOWN is non-zero,
call clear_completions and reset SCREEN->COMPLETION_SHOWN. If C is
a tab, call complete.
* normal/completion.c (disk_dev): Removed.
(print_simple_completion): Likewise.
(print_partition_completion): Likewise.
(print_func): New global variable.
(add_completion): Do not take the arguments WHAT or PRINT any
longer. Added a new argument TYPE. Instead of printing directly,
call PRINT_FUNC if not NULL.
All callers changed.
(complete_device): Use a local variable DEV instead of
DISK_DEV. Do not move CURRENT_WORD to the end of a device name.
(grub_normal_do_completion): Take a new argument HOOK. Do not
initialize DISK_DEV. Initialize PRINT_FUNC to HOOK. If RET is an
empty string, return NULL instead.
All callers changed.
* normal/cmdline.c (print_completion): New function.
* kern/partition.c (grub_partition_iterate): Add an argument DISK
to HOOK.
All callers changed.
* kern/disk.c (grub_print_partinfo): Removed.
* include/grub/partition.h (struct grub_partition_map): Add a new
argument DISK into HOOK of ITERATE.
(grub_partition_iterate): Add a new argument DISK to HOOK.
* include/grub/normal.h (enum grub_completion_type): New enum.
(grub_completion_type_t): New type.
(GRUB_COMPLETION_TYPE_COMMAND): New constant.
(GRUB_COMPLETION_TYPE_DEVICE): Likewise.
(GRUB_COMPLETION_TYPE_PARTITION): Likewise.
(GRUB_COMPLETION_TYPE_FILE): Likewise.
(grub_normal_do_completion): Added a new argument HOOK.
(grub_normal_print_device_info): New prototype.
* include/grub/disk.h (grub_print_partinfo): Removed.
* conf/i386-pc.rmk (grub_emu_SOURCES): Added normal/misc.c.
(normal_mod_SOURCES): Likewise.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Likewise.
(normal_mod_SOURCES): Likewise.
* commands/ls.c (grub_ls_list_disks): Use
grub_normal_print_device_info instead of grub_print_partinfo. Free
PNAME.
(grub_ls_list_files): Use grub_normal_print_device_info instead of
duplicating the code.
* DISTLIST: Added normal/completion.c.
* normal/completion.c: New file.
* term/i386/pc/console.c (grub_console_getwh): New function.
(grub_console_term): Assign grub_console_getwh to getwh.
* normal/cmdline.c (grub_tab_complete): Removed. Now the same
function is defined in normal/completion.c as
grub_normal_do_completion.
(grub_cmdline_get): Use grub_normal_do_completion instead of
grub_tab_complete.
* kern/partition.c (grub_partition_map_iterate): Return 1 if HOOK
returns non-zero, otherwise return 0.
(grub_partition_iterate): First, probe the partition map. Then,
call ITERATE only for this partition map.
* kern/misc.c (grub_strncmp): Rewritten.
* kern/disk.c (grub_disk_dev_iterate): Return 1 if P->ITERATE
returns non-zero. Otherwise return 0.
* include/grub/partition.h (grub_partition_map_iterate): Return
int instead of void.
* include/grub/normal.h (grub_normal_do_completion): New prototype.
* include/grub/misc.h (grub_strncmp): Change the type of N to
grub_size_t.
* include/grub/disk.h (grub_disk_dev_iterate): Return int instead
of void.
* normal/menu.c (draw_border): Cast GRUB_TERM_BORDER_WIDTH to
unsigned explictly before comparing it with I.
* kern/main.c (grub_env_write_root): Add the attribute unused into
VAR.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Added
normal/completion.c.
(normal_mod_SOURCES): Likewise.
* conf/i386-pc.rmk (grub_emu_SOURCES): Likewise.
(normal_mod_SOURCES): Likewise.
* normal/command.c (grub_iterate_commands): If ITERATE returns
non-zero, return one immediately.
* kern/rescue.c (grub_rescue_cmd_rmmod): If the reference count is
negative, unload the module.
* util/i386/pc/grub-setup.c (setup): The name of the PC partition
map is "pc_partition_map" but not "pc".
(usage): Fix the description. The options are --boot-image and
--core-image but not --boot-file or --core-file.
(main): If not specified explicitly, make BOOT_FILE and CORE_FILE
based on DEFAULT_BOOT_FILE and DEFAULT_CORE_FILE with DIR or
DEFAULT_DIRECTORY.
* util/i386/pc/grub-install.in: Do not specify --boot-file or
--core-file. Specify INSTALL_DEVICE as an argument.
* util/console.c: Include config.h.
[HAVE_NCURSeS_CURSES_H]: Include ncurses/curses.h.
[HAVE_NCURSES_H]: Include ncurses.h.
[HAVE_CURSES_H]: Include curses.h.
[!A_NORMAL] (A_NORMAL): Defined as zero.
[!A_STANDOUT] (A_STANDOUT): Likewise.
* conf/i386-pc.rmk (grub_emu_LDFLAGS): Use $(LIBCURSES) instead of
-lncurses.
* conf/powerpc-ieee1275.rmk (grub_emu_LDFLAGS): Likewise.
* configure.ac: Check for curses libraries and headers.
* Makefile.in (LIBCURSES): New variable.
* genmk.rb (Script::rule): Set the executable bits.
* util/i386/pc/biosdisk.c (grub_util_biosdisk_get_grub_dev): The
name of the PC partition map is "pc_partition_map" but not "pc".
* include/grub/powerpc/ieee1275/ieee1275.h: Move ...
* include/grub/ieee1275/ieee1275.h: ... to here. All users updated.
Move `abort', `grub_reboot', and `grub_halt' prototypes ...
* include/grub/powerpc/ieee1275/kernel.h: ... to here.
* commands/ieee1275/halt.c: Include <grub/machine/kernel.h> instead
of <grub/machine/ieee1275.h>.
* commands/ieee1275/reboot.c: Likewise.
* boot/powerpc/ieee1275/ieee1275.c: Move ...
* kern/ieee1275.c: ... to here. All users updated. Change all
parameter structs to use new type `grub_ieee1275_cell_t'.
* term/powerpc/ieee1275/ofconsole.c: Move ...
* term/ieee1275/ofconsole.c: ... to here. All users updated.
* disk/powerpc/ieee1275/ofdisk.c: Move ...
* disk/ieee1275/ofdisk.c: ... to here. All users updated.
* boot/powerpc/ieee1275/cmain.c: Change `grub_ieee1275_entry_fn' type
to return int.
* include/grub/i386/pc/console.h: Move to include/grub/console.h.
Remove unused prototypes. All users updated.
* include/grub/powerpc/ieee1275/console.h: Removed.
* include/grub/powerpc/ieee1275/ieee1275.h: Define
`grub_ieee1275_cell_t'.
* kern/powerpc/ieee1275/openfw.c: Include <grub/machine/kernel.h>.
Cast comparisons with -1 to the correct type.
* loader/powerpc/ieee1275/linux.c (kernel_entry_t): Change parameter
type to match `grub_ieee1275_entry_fn'.
* commands/default.h: New file.
* commands/timeout.h: Likewise.
* normal/context.c: Likewise.
* util/misc.c: Do not include sys/times.h.
Include sys/time.h and grub/machine/time.h.
(grub_get_rtc): Rewritten with gettimeofday.
* util/grub-emu.c (main): Call grub_default_init and
grub_timeout_init before grub_normal_init, and call
grub_timeout_fini and grub_default_fini after grub_main.
* util/console.c (grub_ncurses_checkkey): Return the read
character or -1.
* normal/menu.c (run_menu): Set MENU->TIMEOUT to -1 once it
timeouts.
* normal/main.c (read_config_file): Push MENU. If this fails,
print an error and wait for a user input.
Print an error only if GRUB_ERRNO is not GRUB_ERR_NONE.
If a menu is empty or an error occurs, pop MENU.
(grub_normal_execute): Pop and free MENU after grub_menu_run
returns.
* kern/loader.c (grub_loader_boot): Call grub_machine_fini.
* include/grub/powerpc/ieee1275/time.h [GRUB_UTIL]: Do not
include time.h.
[GRUB_UTIL] (GRUB_TICKS_PER_SECOND): Use the same definition as
without GRUB_UTIL.
* include/grub/i386/pc/time.h [GRUB_UTIL]: Do not include
time.h.
[GRUB_UTIL] (GRUB_TICKS_PER_SECOND): Use the same definition as
without GRUB_UTIL.
* include/grub/normal.h (struct grub_menu_list): New struct.
(grub_menu_list_t): New type.
(struct grub_context): New struct.
(grub_context_t): New type.
(grub_register_command): Got rid of EXPORT_FUNC.
(grub_unregister_command): Likewise.
(grub_context_get): New prototype.
(grub_context_get_current_menu): Likewise.
(grub_context_push_menu): Likewise.
(grub_context_pop_menu): Likewise.
[GRUB_UTIL] (grub_default_init): Likewise.
[GRUB_UTIL] (grub_default_fini): Likewise.
[GRUB_UTIL] (grub_timeout_init): Likewise.
[GRUB_UTIL] (grub_timeout_fini): Likewise.
* conf/i386-pc.rmk (grub_emu_SOURCES): Added commands/default.c,
commands/timeout.c and normal/context.c.
(pkgdata_MODULES): Added default.mod and timeout.mod.
(normal_mod_SOURCES): Added normal/context.c.
(default_mod_SOURCES): New variable.
(default_mod_CFLAGS): Likewise.
(timeout_mod_SOURCES): Likewise.
(timeout_mod_CFLAGS): Likewise.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Copied from
conf/i386-pc.rmk.
(pkgdata_MODULES): Added default.mod and timeout.mod.
(normal_mod_SOURCES): Added normal/context.c.
(default_mod_SOURCES): New variable.
(default_mod_CFLAGS): Likewise.
(timeout_mod_SOURCES): Likewise.
(timeout_mod_CFLAGS): Likewise.
* Makefile.in (all-local): Added $(MKFILES).
Add the loopback device, a device via which files can be accessed
as devices.
* conf/i386-pc.rmk (grub_emu_SOURCES): Add `disk/loopback.c'.
(pkgdata_MODULES): Add loopback.mod.
(loopback_mod_SOURCES): New variable.
(loopback_mod_CFLAGS): Likewise.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Add
`disk/loopback.c'.
(pkgdata_MODULES): Add loopback.mod.
(loopback_mod_SOURCES): New variable.
(loopback_mod_CFLAGS): Likewise.
* disk/loopback.c: new file.
* include/grub/normal.h (grub_loop_init): New prototype.
(grub_loop_fini): New prototype.
* util/grub-emu.c (main): Initialize and de-initialize loopback
support.
* include/grub/disk.h (grub_disk_dev_id): Add
`GRUB_DISK_DEVICE_LOOPBACK_ID'.