Merge mainline into install

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-09-15 14:46:53 +02:00
commit 76de44d8ac
127 changed files with 4094 additions and 1995 deletions

385
ChangeLog
View file

@ -1,3 +1,388 @@
2010-09-15 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/gnulib/basename-lgpl.c: Imported.
* grub-core/gnulib/basename.c: Likewise.
* grub-core/gnulib/dirname-lgpl.c: Likewise.
* grub-core/gnulib/dirname.c: Likewise.
* grub-core/gnulib/dirname.h: Likewise.
* grub-core/gnulib/stripslash.c: Likewise.
2010-09-15 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/gnulib/error.c: Resynced.
* grub-core/gnulib/getopt.c: Likewise.
* grub-core/gnulib/getopt_int.h: Likewise.
* grub-core/gnulib/regex.h: Likewise.
* grub-core/gnulib/regex_internal.c: Likewise.
* grub-core/gnulib/regex_internal.h: Likewise.
2010-09-15 Szymon Janc <szymon@janc.net.pl>
* grub-core/lib/xzembed/xz_dec_stream.c (dec_main): Fix index and block
CRC calculations and validity checks.
* grub-core/lib/xzembed/xz_dec_stream.c (dec_index): Fix index CRC
calculations.
2010-09-15 Szymon Janc <szymon@janc.net.pl>
* grub-core/lib/xzembed/xz_dec_stream.c (xz_dec_end): Fix memory leak.
2010-09-14 Vladimir Serbinenko <phcoder@gmail.com>
Fix incorrect echo options handling.
Reported by: Yves Blusseau.
* include/grub/command.h (grub_command_flags_t): New flags
GRUB_COMMAND_ACCEPT_DASH and GRUB_COMMAND_OPTIONS_AT_START.
* grub-core/lib/arg.c (grub_arg_parse): Handle new flags.
* grub-core/commands/echo.c (GRUB_MOD_INIT): Use new flags.
2010-09-14 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/command.h (GRUB_COMMAND_FLAG_CMDLINE): Removed. All
users updated.
(GRUB_COMMAND_FLAG_MENU): Likewise.
(GRUB_COMMAND_FLAG_BOTH): Likewise.
(GRUB_COMMAND_FLAG_TITLE): Removed.
(GRUB_COMMAND_FLAG_NO_ECHO): Likewise.
(GRUB_COMMAND_FLAG_EXTCMD): Moved into enum.
(GRUB_COMMAND_FLAG_DYNCMD): Likewise.
(GRUB_COMMAND_FLAG_BLOCKS): Likewise.
(grub_command_flags_t): New enum. All users updated.
2010-09-14 Seth Goldberg <seth.goldberg@oracle.com>
Fix solaris compilation.
* grub-core/Makefile.core.def (kernel): Include gnulib/error.c on emu.
(grub-emu): Add LIBZFS and LIBNVPAIR to ldadd.
(grub-emu-list): Likewise.
2010-09-14 Vladimir Serbinenko <phcoder@gmail.com>
Remove deprecated root command.
* grub-core/commands/minicmd.c (grub_mini_cmd_root): Removed. All users
updated.
2010-09-14 Vladimir Serbinenko <phcoder@gmail.com>
* util/i386/pc/grub-setup.c: Merge this ...
* util/sparc64/ieee1275/grub-setup.c: ... and this ...
* util/grub-setup.c: ... into this.
* include/grub/sparc64/ieee1275/boot.h (grub_boot_blocklist) [ASM_FILE]:
New struct.
2010-09-14 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/fs/ext2.c (grub_ext2_open): Use return error value when
possible.
2010-09-14 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/partmap/sun.c (sun_partition_map_iterate): Don't needlesly
allocate p.
2010-09-14 Vladimir Serbinenko <phcoder@gmail.com>
* util/grub-mkconfig_lib.in (prepare_grub_to_access_device): Add
explicit root argument to set to prevent UUID to be interpreted as
argument to set.
2010-09-14 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/sparc64/ieee1275/crt0.S: Align stack.
2010-09-14 Vladimir Serbinenko <phcoder@gmail.com>
Don't export grub_gate_a20.
* grub-core/kern/i386/pc/init.c: Remove leftovers.
* grub-core/kern/i386/pc/startup.S (FUNCTION(grub_gate_a20)): Rename
to ...
(grub_gate_a20): ... this. All users updated.
* include/grub/i386/pc/init.h: Removed. All users updated.
2010-09-14 Vladimir Serbinenko <phcoder@gmail.com>
Create euro.pf2 which supports most European languages.
* Makefile.am (grubdata_DATA): Add euro.pf2.
(euro.pf2): New target.
(CLEANFILES): Add euro.pf2.
2010-09-14 Vladimir Serbinenko <phcoder@gmail.com>
* configure.ac: Disable emu-usb by default to prevent inadvertent
device takeover.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
Disable usbserial on grub-emu since our libusb code isn't good enough
yet.
* grub-core/Makefile.core.def (usbserial_common): Disable on emu.
(usbserial_pl2303): Likewise.
(usbserial_ftdi): Likewise.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
* include/grub/disk.h (grub_disk): Remove has_partitions.
All users updated.
* disk/loopback.c (grub_loopback): Remove has_partitions.
All users updated.
(options): Remove partitions. All users updated.
* util/grub-fstest.c (fstest): Don't pass "-p" to loopback.
* util/i386/pc/grub-setup.c (setup): copy partition table only when
actual partition table is found.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
Remove readability checks (too many false negatives).
* util/grub-install.in: Remove readability checks.
* util/grub-mkconfig.in: Likewise.
* util/grub.d/10_hurd.in: Likewise.
* util/grub.d/10_kfreebsd.in: Likewise.
* util/grub.d/10_linux.in: Likewise.
* util/grub-mkconfig_lib.in (is_path_readable_by_grub): Revert to old
way.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
Enable acpi shutdown on all ACPI platforms.
* grub-core/Makefile.core.def (halt): Inlude commands/acpihalt.c
on coreboo, multiboot and EFI.
* grub-core/commands/acpihalt.c (get_sleep_type): Add missing casts.
(grub_acpi_halt): Likewise.
* grub-core/commands/i386/pc/halt.c (grub_halt): Call grub_acpi_halt.
(grub_cmd_halt): Don't call grub_acpi_halt directly.
* grub-core/lib/efi/halt.c (grub_halt): Call grub_acpi_halt.
* grub-core/lib/i386/halt.c (grub_halt)
[GRUB_MACHINE_COREBOOT || GRUB_MACHINE_MULTIBOOT]: Likewise.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/iorw.c (grub_cmd_read): Declare buf in smallest
context.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/video/efi_gop.c: Fix over-80-chars line.
* grub-core/video/efi_uga.c: Likewise.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
Filter devaliases and never open same device twice.
* grub-core/disk/ieee1275/ofdisk.c (last_devpath): New variable.
(last_ihandle): Likewise.
(ofdisk_hash_ent): New member shortest.
(ofdisk_hash_add): Add canonical path too.
(scan): New function.
(grub_ofdisk_iterate): Iterate over hashed entries.
(compute_dev_path): Don't add :0.
(grub_ofdisk_open): Don't really open the disk.
(grub_ofdisk_close): Avoid closing unrelated disk.
(grub_ofdisk_read): Implement reopen logic.
* grub-core/kern/ieee1275/openfw.c (grub_ieee1275_canonicalise_devname):
New function.
* include/grub/ieee1275/ieee1275.h (grub_ieee1275_canonicalise_devname):
New proto.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
Fix sparc64.
* configure.ac (GRUB_KERNEL_MACHINE_LINK_ADDR): Removed.
* grub-core/Makefile.core.def (kernel): Make ldflags just use the
right address. Add sparc64_ieee1275_ldflags.
* grub-core/loader/sparc64/ieee1275/linux.c: Remove leftover include.
* util/grub-mkimagexx.c (locate_sections): Correct grub_host_to_target32
to grub_host_to_target_addr
(load_image): Likewise.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/normal/completion.c (complete_file): Handle device
containing slash.
Fix based on patch by Doug Nazar.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
grub-mknetdir script.
* Makefile.util.def (grub-mknetdir): New module.
* tests/util/grub-shell.in: Support boot=net
* util/grub-mknetdir.in: New file.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
videoinfo on non-vbe.
* grub-core/Makefile.core.def (vbeinfo): Removed.
(vbetest): Removed.
(videoinfo): New module.
* grub-core/commands/i386/pc/vbeinfo.c: Removed.
* grub-core/commands/i386/pc/vbetest.c: Removed.
* grub-core/commands/videoinfo.c: New file.
* grub-core/commands/videotest.c (grub_cmd_videotest): Support mode
specification.
(grub_cmd_videotest) [GRUB_MACHINE_PCBIOS]: Load vbe.mod when invoked
as vbetest.
(GRUB_MOD_INIT) [GRUB_MACHINE_PCBIOS]: New command vbetest.
(GRUB_MOD_FINI) [GRUB_MACHINE_PCBIOS]: Unregister vbetest.
* grub-core/video/efi_gop.c (grub_video_gop_fill_mode_info): Fill
mode_number. New parameter mode. All users updated.
(grub_video_gop_iterate): New function.
(grub_video_efi_gop): New member iterate.
* grub-core/video/i386/pc/vbe.c (framebuffer): Removed leftover fields.
(grub_vbe_set_video_mode): Remove setting useless fields.
(vbe2videoinfo): New function.
(grub_video_vbe_iterate): Likewise.
(grub_video_vbe_setup): Use vbe2videoinfo.
(grub_video_vbe_print_adapter_specific_info): New function.
(grub_video_vbe_adapter): New fields iterate and
print_adapter_specific_info.
* include/grub/video.h (GRUB_VIDEO_MODE_*): Transform into enum.
All users updated.
(grub_video_mode_info): New field mode_number.
(grub_video_adapter): New fields iterate and
print_adapter_specific_info.
2010-09-13 Tristan Gingold <gingold@free.fr>
2010-09-13 Robert Millan <rmh.grub@aybabtu.com>
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/efi/lsefisystab.c: New file.
* grub-core/commands/efi/lssal.c: Likewise.
* grub-core/Makefile.core.def (lsacpi): New module.
(lsefisystab): Likewise.
* include/grub/efi/api.h (GRUB_EFI_SAL_TABLE_GUID): New definition.
(GRUB_EFI_HCDP_TABLE_GUID): Likewise.
(grub_efi_sal_system_table): New struct.
(grub_efi_sal_system_table_entrypoint_descriptor): Likewise.
(grub_efi_sal_system_table_memory_descriptor): Likewise.
(grub_efi_sal_system_table_platform_features): Likewise.
(grub_efi_sal_system_table_translation_register_descriptor): Likewise.
(grub_efi_sal_system_table_purge_translation_coherence): Likewise.
(grub_efi_sal_system_table_ap_wakeup): Likewise.
* include/grub/types.h (PRIuGRUB_UINT64_T): New definition.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
Support explicit user claim that a device is BIOS-visible.
* grub-core/kern/emu/getroot.c (grub_util_get_dev_abstraction):
Return GRUB_DEV_ABSTRACTION_NONE if device is in device.map.
* grub-core/kern/emu/hostdisk.c
(convert_system_partition_to_system_disk): Support mdX.
(find_system_device): New parameter add. All users updated.
(grub_util_biosdisk_is_present): New function.
* include/grub/emu/hostdisk.h (grub_util_biosdisk_is_present): New
proto.
2010-09-13 Vladimir Serbinenko <phcoder@gmail.com>
Search hints support.
* commands/search.c (FUNC_NAME): New arguments hints and nhints.
All users updated.
2010-09-13 Yves Blusseau <blusseau@zetam.org>
Bash completion script for util commands
* Makefile.am: Add util/bash-completion.d directory
* configure.ac: Likewise.
* util/bash-completion.d/Makefile.am: New file.
* util/bash-completion.d/grub-completion.bash.in: Likewise.
2010-09-12 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/normal/term.c (put_glyphs_terminal): Correct sign.
(print_backlog): set backlog_ucs4 and backlog_glyphs.
Reported by: Yves Blusseau.
2010-09-12 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/normal/misc.c (grub_normal_print_device_info): Show
partition size and offset.
2010-09-12 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/wildcard.c (make_regex): Escape brackets.
2010-09-12 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/ls.c (grub_cmd_ls): Accept multiple files.
2010-09-12 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/misc.c (grub_vprintf): Use va_copy when necessary.
(grub_xvasprintf): Likewise.
2010-09-12 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/emu/main.c (main): Call hostfs_init only after init_all.
2010-09-12 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/commands/menuentry.c (append_menu_entry): Don't rely on
args ending with NULL.
2010-09-12 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/lib/xzembed/xz_dec_stream.c (xz_dec_reset): Preserve context
pointer.
2010-09-11 Szymon Janc <szymon@janc.net.pl>
* grub-core/commands/lsacpi.c (grub_cmd_lsacpi): Fix prototype.
2010-09-11 Vladimir Serbinenko <phcoder@gmail.com>
Shutdown using ACPI.
* grub-core/Makefile.core.def (halt): Add commands/acpihalt.c on i386-pc.
* grub-core/commands/acpihalt.c: New file.
* grub-core/commands/i386/pc/halt.c (grub_cmd_halt): Call grub_acpi_halt.
* include/grub/acpi.h (grub_acpi_fadt): New member pm1a.
(grub_acpi_halt): New proto.
(GRUB_ACPI_SLP_EN): New const.
(GRUB_ACPI_SLP_TYP_OFFSET): Likewise.
(GRUB_ACPI_OPCODE_*): New enum.
(GRUB_ACPI_EXTOPCODE_*): Likewise.
2010-09-11 Tristan Gingold <gingold@free.fr>
2010-09-11 Robert Millan <rmh.grub@aybabtu.com>
2010-09-11 Vladimir Serbinenko <phcoder@gmail.com>
* commands/lsacpi.c: New file.
* grub-core/Makefile.core.def (lsacpi): New module.
* include/grub/acpi.h (GRUB_ACPI_FADT_SIGNATURE): New definition.
(GRUB_ACPI_MADT_SIGNATURE): Likewise.
(grub_acpi_madt_entry_header): New struct.
(grub_acpi_madt): Likewise.
(grub_acpi_madt_entry_interrupt_override): Likewise.
(grub_acpi_madt_entry_sapic): Likewise.
(grub_acpi_madt_entry_lsapic): Likewise.
(grub_acpi_madt_entry_platform_int_source): Likewise.
* include/grub/types.h (PRIxGRUB_UINT32_T): New definition.
(PRIuGRUB_UINT32_T): Likewise.
(PRIxGRUB_UINT64_T): Likewise.
2010-09-11 Vladimir Serbinenko <phcoder@gmail.com>
Implement loading palette on ieee1275_fb.
* grub-core/video/ieee1275.c (stdout_ihandle): New variable.
(have_setcolors): Likewise.
(grub_video_ieee1275_init): Fill stdout_ihandle and have_setcolors.
(grub_video_ieee1275_setup): Use grub_video_ieee1275_set_palette.
(grub_video_ieee1275_set_palette): Implement.
2010-09-11 Vladimir Serbinenko <phcoder@gmail.com>
2010-09-11 Colin Watson <cjwatson@ubuntu.com>

View file

@ -1,7 +1,7 @@
AUTOMAKE_OPTIONS = subdir-objects
DEPDIR = .deps-util
SUBDIRS = . grub-core po docs
SUBDIRS = . grub-core po docs util/bash-completion.d
include $(top_srcdir)/conf/Makefile.common
include $(top_srcdir)/conf/Makefile.extra-dist
@ -60,7 +60,7 @@ CLEANFILES += grub_fstest_init.c
if COND_GRUB_MKFONT
if COND_HAVE_FONT_SOURCE
grubdata_DATA = unicode.pf2 ascii.pf2 ascii.h widthspec.h
grubdata_DATA = unicode.pf2 ascii.pf2 euro.pf2 ascii.h widthspec.h
endif
endif
@ -76,6 +76,10 @@ ascii.pf2: $(FONT_SOURCE) grub-mkfont
$(builddir)/grub-mkfont -o $@ $(FONT_SOURCE) -r 0x0-0x7f,$(UNICODE_ARROWS),$(UNICODE_LINES)
CLEANFILES += ascii.pf2
euro.pf2: $(FONT_SOURCE) grub-mkfont
$(builddir)/grub-mkfont -o $@ $(FONT_SOURCE) -r 0x0-0x4ff,0x1e00-0x1fff,$(UNICODE_ARROWS),$(UNICODE_LINES)
CLEANFILES += euro.pf2
ascii.bitmaps: $(FONT_SOURCE) grub-mkfont
$(builddir)/grub-mkfont --ascii-bitmaps -o $@ $(FONT_SOURCE)
CLEANFILES += ascii.bitmaps

View file

@ -232,14 +232,11 @@ program = {
name = grub-setup;
installdir = sbin;
mansection = 8;
i386_pc = util/i386/pc/grub-setup.c;
i386_pc = util/raid.c;
i386_pc = util/lvm.c;
common = util/grub-setup.c;
common = util/raid.c;
common = util/lvm.c;
sparc64_ieee1275 = util/ieee1275/ofpath.c;
sparc64_ieee1275 = util/sparc64/ieee1275/grub-setup.c;
sparc64_ieee1275 = util/raid.c;
sparc64_ieee1275 = util/lvm.c;
ldadd = libgrub.a;
ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL)';
@ -352,6 +349,14 @@ script = {
enable = noemu;
};
script = {
mansection = 8;
installdir = sbin;
name = grub-mknetdir;
common = util/grub-mknetdir.in;
};
script = {
name = grub-mkconfig;
common = util/grub-mkconfig.in;

View file

@ -698,8 +698,8 @@ if test x"$missing_ncurses" = xtrue ; then
AC_MSG_ERROR([grub-emu can't be compiled without ncurses])
fi
if test x"$enable_grub_emu_usb" = xno ; then
grub_emu_usb_excuse="explicitly disabled"
if test x"$enable_grub_emu_usb" != xyes ; then
grub_emu_usb_excuse="not enabled"
fi
if test x"$enable_grub_emu_pci" = xyes ; then
@ -867,20 +867,8 @@ pkglibrootdir='$(libdir)'/`echo $PACKAGE | sed "$program_transform_name"`
AC_SUBST(pkglibrootdir)
AC_SUBST([FONT_SOURCE])
AS_IF([test x$target_cpu = xi386 -a x$platform = xpc],
[AC_SUBST([GRUB_KERNEL_MACHINE_LINK_ADDR], 0x8200)])
AS_IF([test x$target_cpu = xi386 -a x$platform = xcoreboot],
[AC_SUBST([GRUB_KERNEL_MACHINE_LINK_ADDR], 0x8200)])
AS_IF([test x$target_cpu = xi386 -a x$platform = xmultiboot],
[AC_SUBST([GRUB_KERNEL_MACHINE_LINK_ADDR], 0x8200)])
AS_IF([test x$target_cpu = xmips -a x$platform = xyeeloong],
[AC_SUBST([GRUB_KERNEL_MACHINE_LINK_ADDR], 0x80200000)])
AS_IF([test x$target_cpu = xpowerpc -a x$platform = xieee1275],
[AC_SUBST([GRUB_KERNEL_MACHINE_LINK_ADDR], 0x200000)])
AS_IF([test x$target_cpu = xi386 -a x$platform = xqemu],
[AC_SUBST([GRUB_BOOT_MACHINE_LINK_ADDR], 0xffe00)])
AS_IF([test x$target_cpu = xi386 -a x$platform = xieee1275],
[AC_SUBST([GRUB_KERNEL_MACHINE_LINK_ADDR], 0x10000)])
AS_IF([test x$TARGET_APPLE_CC = x1],
[AC_SUBST([USE_APPLE_CC_FIXES], yes)])
@ -939,6 +927,7 @@ AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([grub-core/Makefile])
AC_CONFIG_FILES([po/Makefile])
AC_CONFIG_FILES([docs/Makefile])
AC_CONFIG_FILES([util/bash-completion.d/Makefile])
AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
AC_OUTPUT

View file

@ -0,0 +1,2 @@
[NAME]
grub-mknetdir \- prepare a GRUB netboot directory.

View file

@ -10,20 +10,20 @@ kernel = {
x86_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment';
i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)';
i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_KERNEL_MACHINE_LINK_ADDR)';
i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8200';
i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)';
i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_KERNEL_MACHINE_LINK_ADDR)';
i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8200';
i386_coreboot_ldflags = '-Wl,-Ttext=$(GRUB_KERNEL_MACHINE_LINK_ADDR)';
i386_multiboot_ldflags = '-Wl,-Ttext=$(GRUB_KERNEL_MACHINE_LINK_ADDR)';
i386_ieee1275_ldflags = '-Wl,-Ttext=$(GRUB_KERNEL_MACHINE_LINK_ADDR)';
mips_yeeloong_ldflags = '-Wl,-Ttext,$(GRUB_KERNEL_MACHINE_LINK_ADDR)';
powerpc_ieee1275_ldflags = '-Wl,-Ttext,$(GRUB_KERNEL_MACHINE_LINK_ADDR)';
i386_coreboot_ldflags = '-Wl,-Ttext=0x8200';
i386_multiboot_ldflags = '-Wl,-Ttext=0x8200';
i386_ieee1275_ldflags = '-Wl,-Ttext=0x10000';
mips_yeeloong_ldflags = '-Wl,-Ttext,0x80200000';
powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000';
sparc64_ieee1275_ldflags = '-Wl,-Ttext,0x4400';
mips_yeeloong_cppflags = '-DUSE_ASCII_FAILBACK';
i386_qemu_cppflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)';
i386_qemu_ccasflags = '-DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR)';
emu_cflags = '$(CFLAGS_GNULIB)';
emu_cppflags = '$(CPPFLAGS_GNULIB)';
@ -150,6 +150,7 @@ kernel = {
emu = disk/host.c;
emu = gnulib/progname.c;
emu = gnulib/error.c;
emu = kern/emu/console.c;
emu = kern/emu/getroot.c;
emu = kern/emu/hostdisk.c;
@ -187,7 +188,7 @@ program = {
ldadd = 'kernel.img$(EXEEXT)';
ldadd = '$(MODULE_FILES)';
ldadd = '$(LIBUTIL) $(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER)';
ldadd = '$(LIBUTIL) $(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)';
enable = emu;
};
@ -200,7 +201,7 @@ program = {
emu_nodist = symlist.c;
ldadd = 'kernel.img$(EXEEXT)';
ldadd = '$(LIBUTIL) $(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER)';
ldadd = '$(LIBUTIL) $(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR)';
enable = emu;
};
@ -319,25 +320,19 @@ module = {
module = {
name = usbserial_common;
common = bus/usb/serial/common.c;
enable = emu;
enable = usb;
emu_condition = COND_GRUB_EMU_USB;
};
module = {
name = usbserial_pl2303;
common = bus/usb/serial/pl2303.c;
enable = emu;
enable = usb;
emu_condition = COND_GRUB_EMU_USB;
};
module = {
name = usbserial_ftdi;
common = bus/usb/serial/ftdi.c;
enable = emu;
enable = usb;
emu_condition = COND_GRUB_EMU_USB;
};
module = {
@ -404,7 +399,7 @@ module = {
module = {
name = acpi;
x86 = commands/acpi.c;
common = commands/acpi.c;
x86_efi = commands/efi/acpi.c;
i386_pc = commands/i386/pc/acpi.c;
i386_coreboot = commands/i386/pc/acpi.c;
@ -416,6 +411,33 @@ module = {
enable = i386_multiboot;
};
module = {
name = lsacpi;
common = commands/lsacpi.c;
enable = x86_efi;
enable = i386_pc;
enable = i386_coreboot;
enable = i386_multiboot;
};
module = {
name = lsefisystab;
common = commands/efi/lsefisystab.c;
enable = x86_efi;
};
module = {
name = lssal;
common = commands/efi/lssal.c;
enable = x86_efi;
};
module = {
name = blocklist;
common = commands/blocklist.c;
@ -493,6 +515,10 @@ module = {
name = halt;
nopc = commands/halt.c;
i386_pc = commands/i386/pc/halt.c;
i386_pc = commands/acpihalt.c;
i386_coreboot = commands/acpihalt.c;
i386_multiboot = commands/acpihalt.c;
x86_efi = commands/acpihalt.c;
i386_multiboot = lib/i386/halt.c;
i386_coreboot = lib/i386/halt.c;
i386_qemu = lib/i386/halt.c;
@ -673,15 +699,8 @@ module = {
};
module = {
name = vbeinfo;
i386_pc = commands/i386/pc/vbeinfo.c;
enable = i386_pc;
};
module = {
name = vbetest;
i386_pc = commands/i386/pc/vbetest.c;
enable = i386_pc;
name = videoinfo;
common = commands/videoinfo.c;
};
module = {

View file

@ -324,7 +324,7 @@ setup_common_tables (void)
/* If it's FADT correct DSDT and FACS addresses. */
fadt = (struct grub_acpi_fadt *) cur->addr;
if (grub_memcmp (fadt->hdr.signature, "FACP",
if (grub_memcmp (fadt->hdr.signature, GRUB_ACPI_FADT_SIGNATURE,
sizeof (fadt->hdr.signature)) == 0)
{
fadt->dsdt_addr = PTR_TO_UINT32 (table_dsdt);
@ -527,7 +527,7 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
struct grub_acpi_fadt *fadt = (struct grub_acpi_fadt *) curtable;
/* Set root header variables to the same values
as FACP by default. */
as FADT by default. */
grub_memcpy (&root_oemid, &(fadt->hdr.oemid),
sizeof (root_oemid));
grub_memcpy (&root_oemtable, &(fadt->hdr.oemtable),
@ -758,8 +758,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(acpi)
{
cmd = grub_register_extcmd ("acpi", grub_cmd_acpi,
GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("acpi", grub_cmd_acpi, 0,
N_("[-1|-2] [--exclude=TABLE1,TABLE2|"
"--load-only=table1,table2] FILE1"
" [FILE2] [...]"),

View file

@ -0,0 +1,266 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010 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/acpi.h>
#include <grub/misc.h>
#include <grub/cpu/io.h>
static inline grub_uint32_t
decode_length (const grub_uint8_t *ptr, int *numlen)
{
int num_bytes, i;
grub_uint32_t ret;
if (*ptr < 64)
{
if (numlen)
*numlen = 1;
return *ptr;
}
num_bytes = *ptr >> 6;
if (numlen)
*numlen = num_bytes + 1;
ret = *ptr & 0xf;
ptr++;
for (i = 0; i < num_bytes; i++)
{
ret |= *ptr << (8 * i + 4);
ptr++;
}
return ret;
}
static inline grub_uint32_t
skip_name_string (const grub_uint8_t *ptr, const grub_uint8_t *end)
{
const grub_uint8_t *ptr0 = ptr;
while (ptr < end && (*ptr == '^' || *ptr == '\\'))
ptr++;
switch (*ptr)
{
case '.':
ptr++;
ptr += 8;
break;
case '/':
ptr++;
ptr += 1 + (*ptr) * 4;
break;
case 0:
ptr++;
break;
default:
ptr += 4;
break;
}
return ptr - ptr0;
}
static inline grub_uint32_t
skip_data_ref_object (const grub_uint8_t *ptr, const grub_uint8_t *end)
{
grub_dprintf ("acpi", "data type = 0x%x\n", *ptr);
switch (*ptr)
{
case GRUB_ACPI_OPCODE_PACKAGE:
return 1 + decode_length (ptr + 1, 0);
case GRUB_ACPI_OPCODE_ZERO:
case GRUB_ACPI_OPCODE_ONES:
case GRUB_ACPI_OPCODE_ONE:
return 1;
case GRUB_ACPI_OPCODE_BYTE_CONST:
return 2;
case GRUB_ACPI_OPCODE_WORD_CONST:
return 3;
case GRUB_ACPI_OPCODE_DWORD_CONST:
return 5;
default:
if (*ptr == '^' || *ptr == '\\' || *ptr == '_'
|| (*ptr >= 'A' && *ptr <= 'Z'))
return skip_name_string (ptr, end);
grub_printf ("Unknown opcode 0x%x\n", *ptr);
return 0;
}
}
static inline grub_uint32_t
skip_ext_op (const grub_uint8_t *ptr, const grub_uint8_t *end)
{
const grub_uint8_t *ptr0 = ptr;
int add;
grub_dprintf ("acpi", "Extended opcode: 0x%x\n", *ptr);
switch (*ptr)
{
case GRUB_ACPI_EXTOPCODE_MUTEX:
ptr++;
ptr += skip_name_string (ptr, end);
ptr++;
break;
case GRUB_ACPI_EXTOPCODE_OPERATION_REGION:
ptr++;
ptr += skip_name_string (ptr, end);
ptr++;
ptr += add = skip_data_ref_object (ptr, end);
if (!add)
return 0;
ptr += add = skip_data_ref_object (ptr, end);
if (!add)
return 0;
break;
case GRUB_ACPI_EXTOPCODE_FIELD_OP:
ptr++;
ptr += decode_length (ptr, 0);
break;
default:
grub_printf ("Unexpected extended opcode: 0x%x\n", *ptr);
return 0;
}
return ptr - ptr0;
}
static int
get_sleep_type (grub_uint8_t *table, grub_uint8_t *end)
{
grub_uint8_t *ptr, *prev;
int sleep_type = -1;
ptr = table + sizeof (struct grub_acpi_table_header);
while (ptr < end && prev < ptr)
{
int add;
prev = ptr;
grub_dprintf ("acpi", "Opcode 0x%x\n", *ptr);
grub_dprintf ("acpi", "Tell %x\n", (unsigned) (ptr - table));
switch (*ptr)
{
case GRUB_ACPI_OPCODE_EXTOP:
ptr++;
ptr += add = skip_ext_op (ptr, end);
if (!add)
return -1;
break;
case GRUB_ACPI_OPCODE_NAME:
ptr++;
if (memcmp (ptr, "_S5_", 4) == 0)
{
int ll;
grub_uint8_t *ptr2 = ptr;
ptr2 += 4;
if (*ptr2 != 0x12)
{
grub_printf ("Unknown opcode in _S5: 0x%x\n", *ptr2);
return -1;
}
ptr2++;
decode_length (ptr2, &ll);
ptr2 += ll;
ptr2++;
switch (*ptr2)
{
case GRUB_ACPI_OPCODE_ZERO:
sleep_type = 0;
break;
case GRUB_ACPI_OPCODE_ONE:
sleep_type = 1;
break;
case GRUB_ACPI_OPCODE_BYTE_CONST:
sleep_type = ptr2[1];
break;
default:
grub_printf ("Unknown data type in _S5: 0x%x\n", *ptr2);
return -1;
}
}
ptr += add = skip_name_string (ptr, end);
if (!add)
return -1;
ptr += add = skip_data_ref_object (ptr, end);
if (!add)
return -1;
break;
case GRUB_ACPI_OPCODE_SCOPE:
case GRUB_ACPI_OPCODE_IF:
case GRUB_ACPI_OPCODE_METHOD:
{
ptr++;
ptr += decode_length (ptr, 0);
break;
}
}
}
grub_dprintf ("acpi", "TYP = %d\n", sleep_type);
return sleep_type;
}
void
grub_acpi_halt (void)
{
struct grub_acpi_rsdp_v20 *rsdp2;
struct grub_acpi_rsdp_v10 *rsdp1;
struct grub_acpi_table_header *rsdt;
grub_uint32_t *entry_ptr;
rsdp2 = grub_acpi_get_rsdpv2 ();
if (rsdp2)
rsdp1 = &(rsdp2->rsdpv1);
else
rsdp1 = grub_acpi_get_rsdpv1 ();
grub_dprintf ("acpi", "rsdp1=%p\n", rsdp1);
if (!rsdp1)
return;
rsdt = (struct grub_acpi_table_header *) (grub_addr_t) rsdp1->rsdt_addr;
for (entry_ptr = (grub_uint32_t *) (rsdt + 1);
entry_ptr < (grub_uint32_t *) (((grub_uint8_t *) rsdt)
+ rsdt->length);
entry_ptr++)
{
if (grub_memcmp ((void *) (grub_addr_t) *entry_ptr, "FACP", 4) == 0)
{
grub_uint32_t port;
struct grub_acpi_fadt *fadt
= ((struct grub_acpi_fadt *) (grub_addr_t) *entry_ptr);
struct grub_acpi_table_header *dsdt
= (struct grub_acpi_table_header *) (grub_addr_t) fadt->dsdt_addr;
int sleep_type = -1;
port = fadt->pm1a;
grub_dprintf ("acpi", "PM1a port=%x\n", port);
if (grub_memcmp (dsdt->signature, "DSDT",
sizeof (dsdt->signature)) != 0)
break;
sleep_type = get_sleep_type ((grub_uint8_t *) dsdt,
(grub_uint8_t *) dsdt + dsdt->length);
if (sleep_type < 0 || sleep_type >= 8)
break;
grub_dprintf ("acpi", "SLP_TYP = %d, port = 0x%x\n",
sleep_type, port);
grub_outw (GRUB_ACPI_SLP_EN
| (sleep_type << GRUB_ACPI_SLP_TYP_OFFSET), port & 0xffff);
}
}
grub_printf ("ACPI shutdown failed\n");
}

View file

@ -91,7 +91,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(cat)
{
cmd = grub_register_extcmd ("cat", grub_cmd_cat, GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("cat", grub_cmd_cat, 0,
N_("FILE"), N_("Show the contents of a file."),
options);
}

View file

@ -113,7 +113,9 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(echo)
{
cmd = grub_register_extcmd ("echo", grub_cmd_echo, GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("echo", grub_cmd_echo,
GRUB_COMMAND_ACCEPT_DASH
| GRUB_COMMAND_OPTIONS_AT_START,
N_("[-e|-n] STRING"), N_("Display a line of text."),
options);
}

View file

@ -0,0 +1,107 @@
/* systab.c - Display EFI systab. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/types.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/normal.h>
#include <grub/charset.h>
#include <grub/efi/api.h>
#include <grub/efi/efi.h>
struct guid_mapping
{
grub_efi_guid_t guid;
const char *name;
};
static const struct guid_mapping guid_mappings[] =
{
{ GRUB_EFI_ACPI_20_TABLE_GUID, "ACPI-2.0"},
{ GRUB_EFI_ACPI_TABLE_GUID, "ACPI-1.0"},
{ GRUB_EFI_SAL_TABLE_GUID, "SAL"},
{ GRUB_EFI_SMBIOS_TABLE_GUID, "SMBIOS"},
{ GRUB_EFI_MPS_TABLE_GUID, "MPS"},
{ GRUB_EFI_HCDP_TABLE_GUID, "HCDP"}
};
static grub_err_t
grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
const grub_efi_system_table_t *st = grub_efi_system_table;
grub_efi_configuration_table_t *t;
unsigned int i;
grub_printf ("Signature: %016" PRIxGRUB_UINT64_T " revision: %08x\n",
st->hdr.signature, st->hdr.revision);
{
char *vendor;
grub_uint16_t *vendor_utf16;
grub_printf ("Vendor: ");
for (vendor_utf16 = st->firmware_vendor; *vendor_utf16; vendor_utf16++);
vendor = grub_malloc (4 * (vendor_utf16 - st->firmware_vendor) + 1);
if (!vendor)
return grub_errno;
*grub_utf16_to_utf8 ((grub_uint8_t *) vendor, st->firmware_vendor,
vendor_utf16 - st->firmware_vendor) = 0;
grub_printf ("%s", vendor);
grub_free (vendor);
}
grub_printf (", Version=%x\n", st->firmware_revision);
grub_printf ("%ld tables:\n", st->num_table_entries);
t = st->configuration_table;
for (i = 0; i < st->num_table_entries; i++)
{
unsigned int j;
grub_printf ("%p ", t->vendor_table);
grub_printf ("%08x-%04x-%04x-",
t->vendor_guid.data1, t->vendor_guid.data2,
t->vendor_guid.data3);
for (j = 0; j < 8; j++)
grub_printf ("%02x", t->vendor_guid.data4[j]);
for (j = 0; j < ARRAY_SIZE (guid_mappings); j++)
if (grub_memcmp (&guid_mappings[j].guid, &t->vendor_guid,
sizeof (grub_efi_guid_t)) == 0)
grub_printf (" %s", guid_mappings[j].name);
grub_printf ("\n");
t++;
}
return GRUB_ERR_NONE;
}
static grub_command_t cmd;
GRUB_MOD_INIT(lsefisystab)
{
cmd = grub_register_command ("lsefisystab", grub_cmd_lsefisystab,
"", "Display EFI system tables.");
}
GRUB_MOD_FINI(lsefisystab)
{
grub_unregister_command (cmd);
}

View file

@ -0,0 +1,162 @@
/* systab.c - Display EFI systab. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/types.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/normal.h>
#include <grub/charset.h>
#include <grub/efi/api.h>
#include <grub/efi/efi.h>
static void
disp_sal (void *table)
{
struct grub_efi_sal_system_table *t = table;
void *desc;
grub_uint32_t len, l;
grub_printf ("SAL rev: %02x, signature: %x, len:%x\n",
t->sal_rev, t->signature, t->total_table_len);
grub_printf ("nbr entry: %d, chksum: %02x, SAL version A: %02x B: %02x\n",
t->entry_count, t->checksum,
t->sal_a_version, t->sal_b_version);
grub_printf ("OEM-ID: %-32s\n", t->oem_id);
grub_printf ("Product-ID: %-32s\n", t->product_id);
desc = t->entries;
len = t->total_table_len - sizeof (struct grub_efi_sal_system_table);
while (len > 0)
{
switch (*(grub_uint8_t *) desc)
{
case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_ENTRYPOINT_DESCRIPTOR:
{
struct grub_efi_sal_system_table_entrypoint_descriptor *c = desc;
l = sizeof (*c);
grub_printf (" Entry point: PAL=%016" PRIxGRUB_UINT64_T
" SAL=%016" PRIxGRUB_UINT64_T " GP=%016"
PRIxGRUB_UINT64_T "\n",
c->pal_proc_addr, c->sal_proc_addr,
c->global_data_ptr);
}
break;
case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_MEMORY_DESCRIPTOR:
{
struct grub_efi_sal_system_table_memory_descriptor *c = desc;
l = sizeof (*c);
grub_printf (" Memory descriptor entry addr=%016" PRIxGRUB_UINT64_T
" len=%" PRIuGRUB_UINT64_T "KB\n",
c->addr, c->len * 4);
grub_printf (" sal_used=%d attr=%x AR=%x attr_mask=%x "
"type=%x usage=%x\n",
c->sal_used, c->attr, c->ar, c->attr_mask, c->mem_type,
c->usage);
}
break;
case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_PLATFORM_FEATURES:
{
struct grub_efi_sal_system_table_platform_features *c = desc;
l = sizeof (*c);
grub_printf (" Platform features: %02x", c->flags);
if (c->flags & GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_BUSLOCK)
grub_printf (" BusLock");
if (c->flags & GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_IRQREDIRECT)
grub_printf (" IrqRedirect");
if (c->flags & GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_IPIREDIRECT)
grub_printf (" IPIRedirect");
if (c->flags & GRUB_EFI_SAL_SYSTEM_TABLE_PLATFORM_FEATURE_ITCDRIFT)
grub_printf (" ITCDrift");
grub_printf ("\n");
}
break;
case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_TRANSLATION_REGISTER_DESCRIPTOR:
{
struct grub_efi_sal_system_table_translation_register_descriptor *c
= desc;
l = sizeof (*c);
grub_printf (" TR type=%d num=%d va=%016" PRIxGRUB_UINT64_T
" pte=%016" PRIxGRUB_UINT64_T "\n",
c->register_type, c->register_number,
c->addr, c->page_size);
}
break;
case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_PURGE_TRANSLATION_COHERENCE:
{
struct grub_efi_sal_system_table_purge_translation_coherence *c
= desc;
l = sizeof (*c);
grub_printf (" PTC coherence nbr=%d addr=%016" PRIxGRUB_UINT64_T "\n",
c->ndomains, c->coherence);
}
break;
case GRUB_EFI_SAL_SYSTEM_TABLE_TYPE_AP_WAKEUP:
{
struct grub_efi_sal_system_table_ap_wakeup *c = desc;
l = sizeof (*c);
grub_printf (" AP wake-up: mec=%d vect=%" PRIxGRUB_UINT64_T "\n",
c->mechanism, c->vector);
}
break;
default:
grub_printf (" unknown entry 0x%x\n", *(grub_uint8_t *)desc);
return;
}
desc = (grub_uint8_t *)desc + l;
len -= l;
}
}
static grub_err_t
grub_cmd_lssal (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
const grub_efi_system_table_t *st = grub_efi_system_table;
grub_efi_configuration_table_t *t = st->configuration_table;
unsigned int i;
grub_efi_guid_t guid = GRUB_EFI_SAL_TABLE_GUID;
for (i = 0; i < st->num_table_entries; i++)
{
if (grub_memcmp (&guid, &t->vendor_guid,
sizeof (grub_efi_guid_t)) == 0)
{
disp_sal (t->vendor_table);
return GRUB_ERR_NONE;
}
t++;
}
grub_printf ("SAL not found\n");
return GRUB_ERR_NONE;
}
static grub_command_t cmd;
GRUB_MOD_INIT(lssal)
{
cmd = grub_register_command ("lssal", grub_cmd_lssal, "",
"Display SAL system table.");
}
GRUB_MOD_FINI(lssal)
{
grub_unregister_command (cmd);
}

View file

@ -66,7 +66,7 @@ grub_extcmd_dispatch (struct grub_command *cmd, int argc, char **args)
grub_extcmd_t
grub_register_extcmd_prio (const char *name, grub_extcmd_func_t func,
unsigned flags, const char *summary,
grub_command_flags_t flags, const char *summary,
const char *description,
const struct grub_arg_option *parser,
int prio)
@ -99,7 +99,7 @@ grub_register_extcmd_prio (const char *name, grub_extcmd_func_t func,
grub_extcmd_t
grub_register_extcmd (const char *name, grub_extcmd_func_t func,
unsigned flags, const char *summary,
grub_command_flags_t flags, const char *summary,
const char *description,
const struct grub_arg_option *parser)
{

View file

@ -252,26 +252,22 @@ static grub_extcmd_t cmd, cmd_md5, cmd_sha256, cmd_sha512;
GRUB_MOD_INIT(hashsum)
{
cmd = grub_register_extcmd ("hashsum", grub_cmd_hashsum,
GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("hashsum", grub_cmd_hashsum, 0,
"hashsum -h HASH [-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]",
"Compute or check hash checksum.",
options);
cmd_md5 = grub_register_extcmd ("md5sum", grub_cmd_hashsum,
GRUB_COMMAND_FLAG_BOTH,
cmd_md5 = grub_register_extcmd ("md5sum", grub_cmd_hashsum, 0,
N_("[-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]"),
N_("Compute or check hash checksum."),
options);
cmd_sha256 = grub_register_extcmd ("sha256sum", grub_cmd_hashsum,
GRUB_COMMAND_FLAG_BOTH,
cmd_sha256 = grub_register_extcmd ("sha256sum", grub_cmd_hashsum, 0,
N_("[-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]"),
"Compute or check hash checksum.",
options);
cmd_sha512 = grub_register_extcmd ("sha512sum", grub_cmd_hashsum,
GRUB_COMMAND_FLAG_BOTH,
cmd_sha512 = grub_register_extcmd ("sha512sum", grub_cmd_hashsum, 0,
N_("[-c FILE [-p PREFIX]] "
"[FILE1 [FILE2 ...]]"),
N_("Compute or check hash checksum."),

View file

@ -409,8 +409,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(hdparm)
{
cmd = grub_register_extcmd ("hdparm", grub_cmd_hdparm,
GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("hdparm", grub_cmd_hdparm, 0,
N_("[OPTIONS] DISK"),
N_("Get/set ATA disk parameters."), options);
}

View file

@ -38,8 +38,7 @@ grub_cmd_help (grub_extcmd_context_t ctxt __attribute__ ((unused)), int argc,
grub_command_t cmd;
FOR_COMMANDS(cmd)
{
if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) &&
(cmd->flags & GRUB_COMMAND_FLAG_CMDLINE))
if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE))
{
struct grub_term_output *term;
const char *summary_translated = _(cmd->summary);
@ -131,8 +130,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(help)
{
cmd = grub_register_extcmd ("help", grub_cmd_help,
GRUB_COMMAND_FLAG_CMDLINE,
cmd = grub_register_extcmd ("help", grub_cmd_help, 0,
N_("[PATTERN ...]"),
N_("Show a help message."), 0);
}

View file

@ -119,8 +119,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT (hexdump)
{
cmd = grub_register_extcmd ("hexdump", grub_cmd_hexdump,
GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("hexdump", grub_cmd_hexdump, 0,
N_("[OPTIONS] FILE_OR_DEVICE"),
N_("Dump the contents of a file or memory."),
options);

View file

@ -88,7 +88,7 @@ GRUB_MOD_INIT(cpuid)
done:
#endif
cmd = grub_register_extcmd ("cpuid", grub_cmd_cpuid, GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("cpuid", grub_cmd_cpuid, 0,
"[-l]", N_("Check for CPU features."), options);
}

View file

@ -401,8 +401,7 @@ GRUB_MOD_INIT (drivemap)
{
grub_get_root_biosnumber_saved = grub_get_root_biosnumber;
grub_get_root_biosnumber = grub_get_root_biosnumber_drivemap;
cmd = grub_register_extcmd ("drivemap", grub_cmd_drivemap,
GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("drivemap", grub_cmd_drivemap, 0,
N_("-l | -r | [-s] grubdev osdisk."),
N_("Manage the BIOS drive mappings."),
options);

View file

@ -22,6 +22,7 @@
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/machine/int.h>
#include <grub/acpi.h>
static const struct grub_arg_option options[] =
{
@ -46,6 +47,8 @@ grub_halt (int no_apm)
{
struct grub_bios_int_registers regs;
grub_acpi_halt ();
if (no_apm)
stop ();
@ -100,6 +103,7 @@ grub_cmd_halt (grub_extcmd_context_t ctxt,
{
struct grub_arg_list *state = ctxt->state;
int no_apm = 0;
if (state[0].set)
no_apm = 1;
grub_halt (no_apm);
@ -110,8 +114,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(halt)
{
cmd = grub_register_extcmd ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH,
"[-n]",
cmd = grub_register_extcmd ("halt", grub_cmd_halt, 0, "[-n]",
N_("Halt the system, if possible using APM."),
options);
}

View file

@ -366,8 +366,7 @@ static void *preboot_hook;
GRUB_MOD_INIT (sendkey)
{
cmd = grub_register_extcmd ("sendkey", grub_cmd_sendkey,
GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("sendkey", grub_cmd_sendkey, 0,
"sendkey [KEYSTROKE1] [KEYSTROKE2] ...",
"Emulate a keystroke", options);

View file

@ -1,185 +0,0 @@
/* vbeinfo.c - command to list compatible VBE video modes. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007,2008,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/env.h>
#include <grub/misc.h>
#include <grub/machine/init.h>
#include <grub/machine/vbe.h>
#include <grub/mm.h>
#include <grub/command.h>
#include <grub/i18n.h>
static void *
real2pm (grub_vbe_farptr_t ptr)
{
return (void *) ((((unsigned long) ptr & 0xFFFF0000) >> 12UL)
+ ((unsigned long) ptr & 0x0000FFFF));
}
static grub_err_t
grub_cmd_vbeinfo (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
struct grub_vbe_info_block controller_info;
struct grub_vbe_mode_info_block mode_info_tmp;
grub_uint32_t use_mode = GRUB_VBE_DEFAULT_VIDEO_MODE;
grub_uint16_t *video_mode_list;
grub_uint16_t *p;
grub_uint16_t *saved_video_mode_list;
grub_size_t video_mode_list_size;
grub_err_t err;
char *modevar;
err = grub_vbe_probe (&controller_info);
if (err != GRUB_ERR_NONE)
return err;
grub_printf ("VBE info: version: %d.%d OEM software rev: %d.%d\n",
controller_info.version >> 8,
controller_info.version & 0xFF,
controller_info.oem_software_rev >> 8,
controller_info.oem_software_rev & 0xFF);
/* The total_memory field is in 64 KiB units. */
grub_printf (" total memory: %d KiB\n",
(controller_info.total_memory << 16) / 1024);
/* Because the information on video modes is stored in a temporary place,
it is better to copy it to somewhere safe. */
p = video_mode_list = real2pm (controller_info.video_mode_ptr);
while (*p++ != 0xFFFF)
;
video_mode_list_size = (grub_addr_t) p - (grub_addr_t) video_mode_list;
saved_video_mode_list = grub_malloc (video_mode_list_size);
if (! saved_video_mode_list)
return grub_errno;
grub_memcpy (saved_video_mode_list, video_mode_list, video_mode_list_size);
grub_printf ("List of compatible video modes:\n");
grub_printf ("Legend: P=Packed pixel, D=Direct color, "
"mask/pos=R/G/B/reserved\n");
/* Walk through all video modes listed. */
for (p = saved_video_mode_list; *p != 0xFFFF; p++)
{
const char *memory_model = 0;
grub_uint32_t mode = (grub_uint32_t) *p;
err = grub_vbe_get_video_mode_info (mode, &mode_info_tmp);
if (err != GRUB_ERR_NONE)
{
grub_errno = GRUB_ERR_NONE;
continue;
}
if ((mode_info_tmp.mode_attributes & GRUB_VBE_MODEATTR_SUPPORTED) == 0)
/* If not available, skip it. */
continue;
if ((mode_info_tmp.mode_attributes & GRUB_VBE_MODEATTR_RESERVED_1) == 0)
/* Not enough information. */
continue;
if ((mode_info_tmp.mode_attributes & GRUB_VBE_MODEATTR_COLOR) == 0)
/* Monochrome is unusable. */
continue;
if ((mode_info_tmp.mode_attributes & GRUB_VBE_MODEATTR_LFB_AVAIL) == 0)
/* We support only linear frame buffer modes. */
continue;
if ((mode_info_tmp.mode_attributes & GRUB_VBE_MODEATTR_GRAPHICS) == 0)
/* We allow only graphical modes. */
continue;
switch (mode_info_tmp.memory_model)
{
case GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL:
memory_model = "Packed";
break;
case GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR:
memory_model = "Direct";
break;
default:
break;
}
if (! memory_model)
continue;
grub_printf ("0x%03x: %4d x %4d x %2d %s",
mode,
mode_info_tmp.x_resolution,
mode_info_tmp.y_resolution,
mode_info_tmp.bits_per_pixel,
memory_model);
/* Show mask and position details for direct color modes. */
if (mode_info_tmp.memory_model == GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR)
grub_printf (", mask: %d/%d/%d/%d pos: %d/%d/%d/%d",
mode_info_tmp.red_mask_size,
mode_info_tmp.green_mask_size,
mode_info_tmp.blue_mask_size,
mode_info_tmp.rsvd_mask_size,
mode_info_tmp.red_field_position,
mode_info_tmp.green_field_position,
mode_info_tmp.blue_field_position,
mode_info_tmp.rsvd_field_position);
grub_printf ("\n");
}
grub_free (saved_video_mode_list);
/* Check existence of vbe_mode environment variable. */
modevar = grub_env_get ("vbe_mode");
if (modevar != 0)
{
unsigned long value;
value = grub_strtoul (modevar, 0, 0);
if (grub_errno == GRUB_ERR_NONE)
use_mode = value;
else
grub_errno = GRUB_ERR_NONE;
}
grub_printf ("Configured VBE mode (vbe_mode) = 0x%03x\n", use_mode);
return 0;
}
static grub_command_t cmd;
GRUB_MOD_INIT(vbeinfo)
{
cmd =
grub_register_command ("vbeinfo", grub_cmd_vbeinfo, 0,
N_("List compatible VESA BIOS extension video modes."));
}
GRUB_MOD_FINI(vbeinfo)
{
grub_unregister_command (cmd);
}

View file

@ -1,179 +0,0 @@
/* vbetest.c - command to test VESA BIOS Extension 2.0+ support. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007 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/normal.h>
#include <grub/dl.h>
#include <grub/env.h>
#include <grub/misc.h>
#include <grub/term.h>
#include <grub/machine/init.h>
#include <grub/machine/vbe.h>
#include <grub/video.h>
#include <grub/err.h>
#include <grub/i18n.h>
static grub_err_t
grub_cmd_vbetest (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
grub_err_t err;
char *modevar;
struct grub_vbe_mode_info_block mode_info;
struct grub_vbe_info_block controller_info;
grub_uint32_t use_mode = GRUB_VBE_DEFAULT_VIDEO_MODE;
grub_uint32_t old_mode;
grub_uint8_t *framebuffer = 0;
grub_uint32_t bytes_per_scan_line = 0;
unsigned char *ptr;
int i;
grub_printf ("Probing for VESA BIOS Extension ... ");
/* Check if VESA BIOS exists. */
err = grub_vbe_probe (&controller_info);
if (err != GRUB_ERR_NONE)
return err;
grub_printf ("found!\n");
/* Dump out controller information. */
grub_printf ("VBE signature = %c%c%c%c\n",
controller_info.signature[0],
controller_info.signature[1],
controller_info.signature[2],
controller_info.signature[3]);
grub_printf ("VBE version = %d.%d\n",
controller_info.version >> 8,
controller_info.version & 0xFF);
grub_printf ("OEM string ptr = %08x\n",
controller_info.oem_string_ptr);
grub_printf ("Total memory = %d\n",
controller_info.total_memory);
err = grub_vbe_get_video_mode (&old_mode);
grub_printf ("Get video mode err = %04x\n", err);
if (err == GRUB_ERR_NONE)
grub_printf ("Old video mode = %04x\n", old_mode);
else
grub_errno = GRUB_ERR_NONE;
/* Check existence of vbe_mode environment variable. */
modevar = grub_env_get ("vbe_mode");
if (modevar != 0)
{
unsigned long value;
value = grub_strtoul (modevar, 0, 0);
if (grub_errno == GRUB_ERR_NONE)
use_mode = value;
else
grub_errno = GRUB_ERR_NONE;
}
err = grub_vbe_get_video_mode_info (use_mode, &mode_info);
if (err != GRUB_ERR_NONE)
return err;
/* Dump out details about the mode being tested. */
grub_printf ("mode: 0x%03x\n",
use_mode);
grub_printf ("width : %d\n",
mode_info.x_resolution);
grub_printf ("height: %d\n",
mode_info.y_resolution);
grub_printf ("memory model: %02x\n",
mode_info.memory_model);
grub_printf ("bytes/scanline: %d\n",
mode_info.bytes_per_scan_line);
grub_printf ("bytes/scanline (lin): %d\n",
mode_info.lin_bytes_per_scan_line);
grub_printf ("base address: %08x\n",
mode_info.phys_base_addr);
grub_printf ("red mask/pos: %d/%d\n",
mode_info.red_mask_size,
mode_info.red_field_position);
grub_printf ("green mask/pos: %d/%d\n",
mode_info.green_mask_size,
mode_info.green_field_position);
grub_printf ("blue mask/pos: %d/%d\n",
mode_info.blue_mask_size,
mode_info.blue_field_position);
grub_printf ("Press any key to continue.\n");
grub_getkey ();
/* Setup GFX mode. */
err = grub_vbe_set_video_mode (use_mode, &mode_info);
if (err != GRUB_ERR_NONE)
return err;
/* Determine framebuffer address and how many bytes are in scan line. */
framebuffer = (grub_uint8_t *) mode_info.phys_base_addr;
ptr = framebuffer;
if (controller_info.version >= 0x300)
{
bytes_per_scan_line = mode_info.lin_bytes_per_scan_line;
}
else
{
bytes_per_scan_line = mode_info.bytes_per_scan_line;
}
/* Draw some random data to screen. */
for (i = 0; i < 256 * 256; i++)
{
ptr[i] = i & 0x0F;
}
/* Draw white line to screen. */
for (i = 0; i < 100; i++)
{
ptr[mode_info.bytes_per_scan_line * 50 + i] = 0x0F;
}
/* Draw another white line to screen. */
grub_memset (ptr + bytes_per_scan_line * 51, 0x0f, bytes_per_scan_line);
grub_getkey ();
grub_video_restore ();
/* Restore old video mode. */
grub_vbe_set_video_mode (old_mode, 0);
return grub_errno;
}
static grub_command_t cmd;
GRUB_MOD_INIT(vbetest)
{
cmd = grub_register_command ("vbetest", grub_cmd_vbetest,
0, N_("Test VESA BIOS Extension 2.0+ support."));
}
GRUB_MOD_FINI(vbetest)
{
grub_unregister_command (cmd);
}

View file

@ -40,7 +40,6 @@ grub_cmd_read (grub_extcmd_context_t ctxt, int argc, char **argv)
{
grub_target_addr_t addr;
grub_uint32_t value = 0;
char buf[sizeof ("XXXXXXXX")];
if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid number of arguments");
@ -63,6 +62,7 @@ grub_cmd_read (grub_extcmd_context_t ctxt, int argc, char **argv)
if (ctxt->state[0].set)
{
char buf[sizeof ("XXXXXXXX")];
grub_snprintf (buf, sizeof (buf), "%x", value);
grub_env_set (ctxt->state[0].arg, buf);
}
@ -117,13 +117,13 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv)
GRUB_MOD_INIT(memrw)
{
cmd_read_byte =
grub_register_extcmd ("inb", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
grub_register_extcmd ("inb", grub_cmd_read, 0,
N_("PORT"), N_("Read byte from PORT."), options);
cmd_read_word =
grub_register_extcmd ("inw", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
grub_register_extcmd ("inw", grub_cmd_read, 0,
N_("PORT"), N_("Read word from PORT."), options);
cmd_read_dword =
grub_register_extcmd ("inl", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
grub_register_extcmd ("inl", grub_cmd_read, 0,
N_("PORT"), N_("Read dword from PORT."), options);
cmd_write_byte =
grub_register_command ("outb", grub_cmd_write,

View file

@ -80,8 +80,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(keystatus)
{
cmd = grub_register_extcmd ("keystatus", grub_cmd_keystatus,
GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("keystatus", grub_cmd_keystatus, 0,
N_("[--shift] [--ctrl] [--alt]"),
N_("Check key modifier status."),
options);

View file

@ -375,20 +375,15 @@ static grub_extcmd_t cmd_load, cmd_list, cmd_save;
GRUB_MOD_INIT(loadenv)
{
cmd_load =
grub_register_extcmd ("load_env", grub_cmd_load_env,
GRUB_COMMAND_FLAG_BOTH,
N_("[-f FILE]"),
grub_register_extcmd ("load_env", grub_cmd_load_env, 0, N_("[-f FILE]"),
N_("Load variables from environment block file."),
options);
cmd_list =
grub_register_extcmd ("list_env", grub_cmd_list_env,
GRUB_COMMAND_FLAG_BOTH,
N_("[-f FILE]"),
grub_register_extcmd ("list_env", grub_cmd_list_env, 0, N_("[-f FILE]"),
N_("List variables from environment block file."),
options);
cmd_save =
grub_register_extcmd ("save_env", grub_cmd_save_env,
GRUB_COMMAND_FLAG_BOTH,
grub_register_extcmd ("save_env", grub_cmd_save_env, 0,
N_("[-f FILE] variable_name [...]"),
N_("Save variables to environment block file."),
options);

View file

@ -253,12 +253,14 @@ static grub_err_t
grub_cmd_ls (grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_arg_list *state = ctxt->state;
int i;
if (argc == 0)
grub_ls_list_devices (state[0].set);
else
grub_ls_list_files (args[0], state[0].set, state[2].set,
state[1].set);
for (i = 0; i < argc; i++)
grub_ls_list_files (args[i], state[0].set, state[2].set,
state[1].set);
return 0;
}
@ -267,7 +269,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(ls)
{
cmd = grub_register_extcmd ("ls", grub_cmd_ls, GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("ls", grub_cmd_ls, 0,
N_("[-l|-h|-a] [FILE]"),
N_("List devices and files."), options);
}

250
grub-core/commands/lsacpi.c Normal file
View file

@ -0,0 +1,250 @@
/* acpi.c - Display acpi tables. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008 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/types.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/normal.h>
#include <grub/acpi.h>
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/dl.h>
static void
print_strn (grub_uint8_t *str, grub_size_t len)
{
for (; *str && len; str++, len--)
grub_printf ("%c", *str);
for (len++; len; len--)
grub_printf (" ");
}
#define print_field(x) print_strn(x, sizeof (x))
static void
disp_acpi_table (struct grub_acpi_table_header *t)
{
print_field (t->signature);
grub_printf ("%4" PRIuGRUB_UINT32_T "B rev=%u OEM=", t->length, t->revision);
print_field (t->oemid);
print_field (t->oemtable);
grub_printf ("OEMrev=%08" PRIxGRUB_UINT32_T " ", t->oemrev);
print_field (t->creator_id);
grub_printf (" %08" PRIxGRUB_UINT32_T "\n", t->creator_rev);
}
static void
disp_madt_table (struct grub_acpi_madt *t)
{
struct grub_acpi_madt_entry_header *d;
grub_uint32_t len;
disp_acpi_table (&t->hdr);
grub_printf ("Local APIC=%08" PRIxGRUB_UINT32_T " Flags=%08"
PRIxGRUB_UINT32_T "\n",
t->lapic_addr, t->flags);
len = t->hdr.length - sizeof (struct grub_acpi_madt);
d = t->entries;
for (;len > 0; len -= d->len, d = (void *) ((grub_uint8_t *) d + d->len))
{
grub_printf (" type=%x l=%u ", d->type, d->len);
switch (d->type)
{
case GRUB_ACPI_MADT_ENTRY_TYPE_INTERRUPT_OVERRIDE:
{
struct grub_acpi_madt_entry_interrupt_override *dt = (void *) d;
grub_printf ("Int Override bus=%x src=%x GSI=%08x Flags=%04x\n",
dt->bus, dt->source, dt->global_sys_interrupt,
dt->flags);
}
break;
case GRUB_ACPI_MADT_ENTRY_TYPE_SAPIC:
{
struct grub_acpi_madt_entry_sapic *dt = (void *) d;
grub_printf ("IOSAPIC Id=%02x GSI=%08x Addr=%016" PRIxGRUB_UINT64_T
"\n",
dt->id, dt->global_sys_interrupt_base,
dt->addr);
}
break;
case GRUB_ACPI_MADT_ENTRY_TYPE_LSAPIC:
{
struct grub_acpi_madt_entry_lsapic *dt = (void *) d;
grub_printf ("LSAPIC ProcId=%02x ID=%02x EID=%02x Flags=%x",
dt->cpu_id, dt->id, dt->eid, dt->flags);
if (dt->flags & GRUB_ACPI_MADT_ENTRY_SAPIC_FLAGS_ENABLED)
grub_printf (" Enabled\n");
else
grub_printf (" Disabled\n");
if (d->len > sizeof (struct grub_acpi_madt_entry_sapic))
grub_printf (" UID val=%08x, Str=%s\n", dt->cpu_uid,
dt->cpu_uid_str);
}
break;
case GRUB_ACPI_MADT_ENTRY_TYPE_PLATFORM_INT_SOURCE:
{
struct grub_acpi_madt_entry_platform_int_source *dt = (void *) d;
static const char * const platint_type[] =
{"Nul", "PMI", "INIT", "CPEI"};
grub_printf ("Platform INT flags=%04x type=%02x (%s)"
" ID=%02x EID=%02x\n",
dt->flags, dt->inttype,
(dt->inttype < ARRAY_SIZE (platint_type))
? platint_type[dt->inttype] : "??", dt->cpu_id,
dt->cpu_eid);
grub_printf (" IOSAPIC Vec=%02x GSI=%08x source flags=%08x\n",
dt->sapic_vector, dt->global_sys_int, dt->src_flags);
}
break;
default:
grub_printf (" ??\n");
}
}
}
static void
disp_acpi_xsdt_table (struct grub_acpi_table_header *t)
{
grub_uint32_t len;
grub_uint64_t *desc;
disp_acpi_table (t);
len = t->length - sizeof (*t);
desc = (grub_uint64_t *) (t + 1);
for (; len > 0; desc++, len -= sizeof (*desc))
{
if (sizeof (grub_addr_t) == 4 && *desc >= (1ULL << 32))
{
grub_printf ("Unreachable table\n");
continue;
}
t = (struct grub_acpi_table_header *) (grub_addr_t) *desc;
if (t == NULL)
continue;
if (grub_memcmp (t->signature, GRUB_ACPI_MADT_SIGNATURE,
sizeof (t->signature)) == 0)
disp_madt_table ((struct grub_acpi_madt *) t);
else
disp_acpi_table (t);
}
}
static void
disp_acpi_rsdt_table (struct grub_acpi_table_header *t)
{
grub_uint32_t len;
grub_uint32_t *desc;
disp_acpi_table (t);
len = t->length - sizeof (*t);
desc = (grub_uint32_t *) (t + 1);
for (; len > 0; desc++, len -= sizeof (*desc))
{
t = (struct grub_acpi_table_header *) (grub_addr_t) *desc;
if (t == NULL)
continue;
if (grub_memcmp (t->signature, GRUB_ACPI_MADT_SIGNATURE,
sizeof (t->signature)) == 0)
disp_madt_table ((struct grub_acpi_madt *) t);
else
disp_acpi_table (t);
}
}
static void
disp_acpi_rsdpv1 (struct grub_acpi_rsdp_v10 *rsdp)
{
print_field (rsdp->signature);
grub_printf ("chksum:%02x, OEM-ID: ", rsdp->checksum);
print_field (rsdp->oemid);
grub_printf ("rev=%d\n", rsdp->revision);
grub_printf ("RSDT=%08" PRIxGRUB_UINT32_T "\n", rsdp->rsdt_addr);
}
static void
disp_acpi_rsdpv2 (struct grub_acpi_rsdp_v20 *rsdp)
{
disp_acpi_rsdpv1 (&rsdp->rsdpv1);
grub_printf ("len=%d XSDT=%016" PRIxGRUB_UINT64_T "\n", rsdp->length,
rsdp->xsdt_addr);
}
static const struct grub_arg_option options[] = {
{"v1", '1', 0, N_("Show v1 tables only."), 0, ARG_TYPE_NONE},
{"v2", '2', 0, N_("Show v2 and v3 tablesv only."), 0, ARG_TYPE_NONE}
};
static grub_err_t
grub_cmd_lsacpi (struct grub_extcmd_context *ctxt,
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
if (!ctxt->state[1].set)
{
struct grub_acpi_rsdp_v10 *rsdp1 = grub_acpi_get_rsdpv1 ();
if (!rsdp1)
grub_printf ("No RSDPv1\n");
else
{
grub_printf ("RSDPv1 signature:");
disp_acpi_rsdpv1 (rsdp1);
disp_acpi_rsdt_table ((void *) (grub_addr_t) rsdp1->rsdt_addr);
}
}
if (!ctxt->state[0].set)
{
struct grub_acpi_rsdp_v20 *rsdp2 = grub_acpi_get_rsdpv2 ();
if (!rsdp2)
grub_printf ("No RSDPv2\n");
else
{
if (sizeof (grub_addr_t) == 4 && rsdp2->xsdt_addr >= (1ULL << 32))
grub_printf ("Unreachable RSDPv2\n");
else
{
grub_printf ("RSDPv2 signature:");
disp_acpi_rsdpv2 (rsdp2);
disp_acpi_xsdt_table ((void *) (grub_addr_t) rsdp2->xsdt_addr);
grub_printf ("\n");
}
}
}
return GRUB_ERR_NONE;
}
static grub_extcmd_t cmd;
GRUB_MOD_INIT(lsapi)
{
cmd = grub_register_extcmd ("lsacpi", grub_cmd_lsacpi, 0, N_("[-1|-2]"),
N_("Show ACPI information."), options);
}
GRUB_MOD_FINI(lsacpi)
{
grub_unregister_extcmd (cmd);
}

View file

@ -224,8 +224,8 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(lspci)
{
cmd = grub_register_extcmd ("lspci", grub_cmd_lspci, GRUB_COMMAND_FLAG_BOTH,
"[-i]", N_("List PCI devices."), options);
cmd = grub_register_extcmd ("lspci", grub_cmd_lspci, 0, "[-i]",
N_("List PCI devices."), options);
}
GRUB_MOD_FINI(lspci)

View file

@ -119,13 +119,13 @@ grub_cmd_write (grub_command_t cmd, int argc, char **argv)
GRUB_MOD_INIT(memrw)
{
cmd_read_byte =
grub_register_extcmd ("read_byte", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
grub_register_extcmd ("read_byte", grub_cmd_read, 0,
N_("ADDR"), N_("Read byte from ADDR."), options);
cmd_read_word =
grub_register_extcmd ("read_word", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
grub_register_extcmd ("read_word", grub_cmd_read, 0,
N_("ADDR"), N_("Read word from ADDR."), options);
cmd_read_dword =
grub_register_extcmd ("read_dword", grub_cmd_read, GRUB_COMMAND_FLAG_BOTH,
grub_register_extcmd ("read_dword", grub_cmd_read, 0,
N_("ADDR"), N_("Read dword from ADDR."), options);
cmd_write_byte =
grub_register_command ("write_byte", grub_cmd_write,

View file

@ -128,7 +128,7 @@ append_menu_entry (int argc, const char **args, char **classes,
if (! menu_args)
goto fail;
for (i = 0; args[i]; i++)
for (i = 0; i < argc; i++)
{
menu_args[i] = grub_strdup (args[i]);
if (! menu_args[i])
@ -274,7 +274,7 @@ void
grub_menu_init (void)
{
cmd = grub_register_extcmd ("menuentry", grub_cmd_menuentry,
GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_BLOCKS,
GRUB_COMMAND_FLAG_BLOCKS,
N_("BLOCK"), N_("Define a menuentry."), options);
}

View file

@ -108,40 +108,6 @@ grub_rescue_cmd_info (void)
}
#endif
/* root [DEVICE] */
static grub_err_t
grub_mini_cmd_root (struct grub_command *cmd __attribute__ ((unused)),
int argc, char *argv[])
{
grub_device_t dev;
grub_fs_t fs;
if (argc > 0)
{
char *device_name = grub_file_get_device_name (argv[0]);
if (! device_name)
return grub_errno;
grub_env_set ("root", device_name);
grub_free (device_name);
}
dev = grub_device_open (0);
if (! dev)
return grub_errno;
fs = grub_fs_probe (dev);
if (grub_errno == GRUB_ERR_UNKNOWN_FS)
grub_errno = GRUB_ERR_NONE;
grub_printf ("(%s): Filesystem is %s.\n",
grub_env_get ("root"), fs ? fs->name : "unknown");
grub_device_close (dev);
return 0;
}
/* dump ADDRESS [SIZE] */
static grub_err_t
grub_mini_cmd_dump (struct grub_command *cmd __attribute__ ((unused)),
@ -226,7 +192,7 @@ grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
return 0;
}
static grub_command_t cmd_cat, cmd_help, cmd_root;
static grub_command_t cmd_cat, cmd_help;
static grub_command_t cmd_dump, cmd_rmmod, cmd_lsmod, cmd_exit;
GRUB_MOD_INIT(minicmd)
@ -237,9 +203,6 @@ GRUB_MOD_INIT(minicmd)
cmd_help =
grub_register_command ("help", grub_mini_cmd_help,
0, N_("Show this message."));
cmd_root =
grub_register_command ("root", grub_mini_cmd_root,
N_("[DEVICE]"), N_("Set the root device."));
cmd_dump =
grub_register_command ("dump", grub_mini_cmd_dump,
N_("ADDR"), N_("Dump memory."));
@ -258,7 +221,6 @@ GRUB_MOD_FINI(minicmd)
{
grub_unregister_command (cmd_cat);
grub_unregister_command (cmd_help);
grub_unregister_command (cmd_root);
grub_unregister_command (cmd_dump);
grub_unregister_command (cmd_rmmod);
grub_unregister_command (cmd_lsmod);

View file

@ -150,8 +150,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT (probe)
{
cmd = grub_register_extcmd ("probe", grub_cmd_probe, GRUB_COMMAND_FLAG_BOTH,
N_("[DEVICE]"),
cmd = grub_register_extcmd ("probe", grub_cmd_probe, 0, N_("[DEVICE]"),
N_("Retrieve device info."), options);
}

View file

@ -136,8 +136,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(regexp)
{
cmd = grub_register_extcmd ("regexp", grub_cmd_regexp,
GRUB_COMMAND_FLAG_BOTH, N_("REGEXP STRING"),
cmd = grub_register_extcmd ("regexp", grub_cmd_regexp, 0, N_("REGEXP STRING"),
N_("Test if REGEXP matches STRING."), options);
/* Setup GRUB script wildcard translator. */

View file

@ -28,9 +28,12 @@
#include <grub/command.h>
#include <grub/search.h>
#include <grub/i18n.h>
#include <grub/disk.h>
#include <grub/partition.h>
void
FUNC_NAME (const char *key, const char *var, int no_floppy)
FUNC_NAME (const char *key, const char *var, int no_floppy,
char **hints, unsigned nhints)
{
int count = 0;
grub_fs_autoload_hook_t saved_autoload;
@ -114,22 +117,86 @@ FUNC_NAME (const char *key, const char *var, int no_floppy)
return (found && var);
}
auto int part_hook (grub_disk_t disk, const grub_partition_t partition);
int part_hook (grub_disk_t disk, const grub_partition_t partition)
{
char *partition_name, *devname;
int ret;
partition_name = grub_partition_get_name (partition);
if (! partition_name)
return 1;
devname = grub_xasprintf ("%s,%s", disk->name, partition_name);
grub_free (partition_name);
if (!devname)
return 1;
ret = iterate_device (devname);
grub_free (devname);
return ret;
}
auto void try (void);
void try (void)
{
unsigned i;
for (i = 0; i < nhints; i++)
{
char *end;
if (!hints[i][0])
continue;
end = hints[i] + grub_strlen (hints[i]) - 1;
if (*end == ',')
*end = 0;
if (iterate_device (hints[i]))
{
if (!*end)
*end = ',';
return;
}
if (!*end)
{
grub_device_t dev;
int ret;
dev = grub_device_open (hints[i]);
if (!dev)
{
*end = ',';
continue;
}
if (!dev->disk)
{
grub_device_close (dev);
*end = ',';
continue;
}
ret = grub_partition_iterate (dev->disk, part_hook);
*end = ',';
grub_device_close (dev);
if (ret)
return;
}
}
grub_device_iterate (iterate_device);
}
/* First try without autoloading if we're setting variable. */
if (var)
{
saved_autoload = grub_fs_autoload_hook;
grub_fs_autoload_hook = 0;
grub_device_iterate (iterate_device);
try ();
/* Restore autoload hook. */
grub_fs_autoload_hook = saved_autoload;
/* Retry with autoload if nothing found. */
if (grub_errno == GRUB_ERR_NONE && count == 0)
grub_device_iterate (iterate_device);
try ();
}
else
grub_device_iterate (iterate_device);
try ();
if (grub_errno == GRUB_ERR_NONE && count == 0)
grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key);
@ -142,7 +209,8 @@ grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc,
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no argument specified");
FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0);
FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0, (args + 2),
argc > 2 ? argc - 2 : 0);
return grub_errno;
}
@ -159,7 +227,7 @@ GRUB_MOD_INIT(search_label)
{
cmd =
grub_register_command (COMMAND_NAME, grub_cmd_do_search,
N_("NAME [VARIABLE]"),
N_("NAME [VARIABLE] [HINTS]"),
HELP_MESSAGE);
}

View file

@ -37,6 +37,9 @@ static const struct grub_arg_option options[] =
{"set", 's', GRUB_ARG_OPTION_OPTIONAL,
N_("Set a variable to the first device found."), "VAR", ARG_TYPE_STRING},
{"no-floppy", 'n', 0, N_("Do not probe any floppy drive."), 0, 0},
{"hint", 'h', GRUB_ARG_OPTION_REPEATABLE,
N_("First try the device HINT. If HINT ends in comma, "
"also try subpartitions"), N_("HINT"), ARG_TYPE_STRING},
{0, 0, 0, 0, 0, 0}
};
@ -47,6 +50,7 @@ enum options
SEARCH_FS_UUID,
SEARCH_SET,
SEARCH_NO_FLOPPY,
SEARCH_HINT
};
static grub_err_t
@ -54,6 +58,11 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args)
{
struct grub_arg_list *state = ctxt->state;
const char *var = 0;
int nhints = 0;
if (state[SEARCH_HINT].set)
while (state[SEARCH_HINT].args[nhints])
nhints++;
if (argc == 0)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no argument specified");
@ -62,11 +71,14 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args)
var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root";
if (state[SEARCH_LABEL].set)
grub_search_label (args[0], var, state[SEARCH_NO_FLOPPY].set);
grub_search_label (args[0], var, state[SEARCH_NO_FLOPPY].set,
state[SEARCH_HINT].args, nhints);
else if (state[SEARCH_FS_UUID].set)
grub_search_fs_uuid (args[0], var, state[SEARCH_NO_FLOPPY].set);
grub_search_fs_uuid (args[0], var, state[SEARCH_NO_FLOPPY].set,
state[SEARCH_HINT].args, nhints);
else if (state[SEARCH_FILE].set)
grub_search_fs_file (args[0], var, state[SEARCH_NO_FLOPPY].set);
grub_search_fs_file (args[0], var, state[SEARCH_NO_FLOPPY].set,
state[SEARCH_HINT].args, nhints);
else
return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
@ -78,9 +90,9 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(search)
{
cmd =
grub_register_extcmd ("search", grub_cmd_search,
GRUB_COMMAND_FLAG_BOTH,
N_("search [-f|-l|-u|-s|-n] NAME"),
grub_register_extcmd ("search", grub_cmd_search, 0,
N_("[-f|-l|-u|-s|-n] [--hint HINT [--hint HINT] ...]"
" NAME"),
N_("Search devices by file, filesystem label"
" or filesystem UUID."
" If --set is specified, the first device found is"

View file

@ -329,7 +329,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(setpci)
{
cmd = grub_register_extcmd ("setpci", grub_cmd_setpci, GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("setpci", grub_cmd_setpci, 0,
N_("[-s POSITION] [-d DEVICE] [-v VAR] "
"[REGISTER][=VALUE[:MASK]]"),
N_("Manipulate PCI devices."), options);

View file

@ -101,7 +101,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(sleep)
{
cmd = grub_register_extcmd ("sleep", grub_cmd_sleep, GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("sleep", grub_cmd_sleep, 0,
N_("NUMBER_OF_SECONDS"),
N_("Wait for a specified number of seconds."),
options);

View file

@ -0,0 +1,150 @@
/* videoinfo.c - command to list video modes. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2005,2007,2008,2009,2010 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/video.h>
#include <grub/dl.h>
#include <grub/env.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/command.h>
#include <grub/i18n.h>
static int
hook (const struct grub_video_mode_info *info)
{
if (info->mode_number == GRUB_VIDEO_MODE_NUMBER_INVALID)
grub_printf (" ");
else
grub_printf (" 0x%03x ", info->mode_number);
grub_printf ("%4d x %4d x %2d ", info->width, info->height, info->bpp);
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT)
grub_printf ("Text-only ");
/* Show mask and position details for direct color modes. */
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_RGB)
grub_printf ("Direct, mask: %d/%d/%d/%d pos: %d/%d/%d/%d",
info->red_mask_size,
info->green_mask_size,
info->blue_mask_size,
info->reserved_mask_size,
info->red_field_pos,
info->green_field_pos,
info->blue_field_pos,
info->reserved_field_pos);
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR)
grub_printf ("Packed ");
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_YUV)
grub_printf ("YUV ");
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PLANAR)
grub_printf ("Planar ");
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_HERCULES)
grub_printf ("Hercules ");
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_CGA)
grub_printf ("CGA ");
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_NONCHAIN4)
grub_printf ("Non-chain 4 ");
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP)
grub_printf ("Monochrome ");
if (info->mode_type & GRUB_VIDEO_MODE_TYPE_UNKNOWN)
grub_printf ("Unknown ");
grub_printf ("\n");
return 0;
}
static grub_err_t
grub_cmd_videoinfo (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
grub_video_adapter_t adapter;
grub_video_driver_id_t id;
#ifdef GRUB_MACHINE_PCBIOS
if (grub_strcmp (cmd->name, "vbeinfo") == 0)
grub_dl_load ("vbe");
#endif
id = grub_video_get_driver_id ();
grub_printf ("List of supported video modes:\n");
grub_printf ("Legend: P=Packed pixel, D=Direct color, "
"mask/pos=R/G/B/reserved\n");
FOR_VIDEO_ADAPTERS (adapter)
{
grub_printf ("Adapter '%s':\n", adapter->name);
if (!adapter->iterate)
{
grub_printf (" No info available\n");
continue;
}
if (adapter->id != id)
{
if (adapter->init ())
{
grub_printf (" Failed\n");
grub_errno = GRUB_ERR_NONE;
continue;
}
}
if (adapter->print_adapter_specific_info)
adapter->print_adapter_specific_info ();
adapter->iterate (hook);
if (adapter->id != id)
{
if (adapter->fini ())
{
grub_errno = GRUB_ERR_NONE;
continue;
}
}
}
return GRUB_ERR_NONE;
}
static grub_command_t cmd;
#ifdef GRUB_MACHINE_PCBIOS
static grub_command_t cmd_vbe;
#endif
GRUB_MOD_INIT(videoinfo)
{
cmd = grub_register_command ("videoinfo", grub_cmd_videoinfo, 0,
N_("List available video modes."));
#ifdef GRUB_MACHINE_PCBIOS
cmd_vbe = grub_register_command ("vbeinfo", grub_cmd_videoinfo, 0,
N_("List available video modes."));
#endif
}
GRUB_MOD_FINI(videoinfo)
{
grub_unregister_command (cmd);
#ifdef GRUB_MACHINE_PCBIOS
grub_unregister_command (cmd_vbe);
#endif
}

View file

@ -26,11 +26,11 @@
#include <grub/command.h>
#include <grub/i18n.h>
#include <grub/gfxmenu_view.h>
#include <grub/env.h>
static grub_err_t
grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
int argc, char **args)
{
grub_err_t err;
grub_video_color_t color;
@ -41,8 +41,20 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
int i;
struct grub_video_render_target *text_layer;
grub_video_color_t palette[16];
const char *mode = NULL;
err = grub_video_set_mode ("auto", GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0);
#ifdef GRUB_MACHINE_PCBIOS
if (grub_strcmp (cmd->name, "vbetest") == 0)
grub_dl_load ("vbe");
#endif
mode = grub_env_get ("gfxmode");
if (argc)
mode = args[0];
if (!mode)
mode = "auto";
err = grub_video_set_mode (mode, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0);
if (err)
return err;
@ -180,14 +192,25 @@ grub_cmd_videotest (grub_command_t cmd __attribute__ ((unused)),
}
static grub_command_t cmd;
#ifdef GRUB_MACHINE_PCBIOS
static grub_command_t cmd_vbe;
#endif
GRUB_MOD_INIT(videotest)
{
cmd = grub_register_command ("videotest", grub_cmd_videotest,
"[WxH]",
N_("Test video subsystem in mode WxH."));
#ifdef GRUB_MACHINE_PCBIOS
cmd_vbe = grub_register_command ("vbetest", grub_cmd_videotest,
0, N_("Test video subsystem."));
#endif
}
GRUB_MOD_FINI(videotest)
{
grub_unregister_command (cmd);
#ifdef GRUB_MACHINE_PCBIOS
grub_unregister_command (cmd_vbe);
#endif
}

View file

@ -137,8 +137,10 @@ make_regex (const char *start, const char *end, regex_t *regexp)
break;
case '.':
case '(':
case ')':
buffer[i++] = '\\';
buffer[i++] = '.';
buffer[i++] = ch;
break;
case '*':
@ -152,6 +154,7 @@ make_regex (const char *start, const char *end, regex_t *regexp)
}
buffer[i++] = '$';
buffer[i] = '\0';
grub_dprintf ("expand", "Regexp is %s\n", buffer);
if (regcomp (regexp, buffer, RE_SYNTAX_GNU_AWK))
{
@ -224,6 +227,7 @@ match_devices (const regex_t *regexp, int noparts)
grub_dprintf ("expand", "matching: %s\n", buffer);
if (regexec (regexp, buffer, 0, 0, 0))
{
grub_dprintf ("expand", "not matched\n");
grub_free (buffer);
return 0;
}

View file

@ -723,7 +723,6 @@ grub_ata_open (const char *name, grub_disk_t disk)
disk->id = (unsigned long) dev;
disk->has_partitions = 1;
disk->data = dev;
return 0;

View file

@ -514,16 +514,12 @@ grub_efidisk_open (const char *name, struct grub_disk *disk)
switch (name[0])
{
case 'f':
disk->has_partitions = 0;
d = get_device (fd_devices, num);
break;
case 'c':
/* FIXME: a CDROM should have partitions, but not implemented yet. */
disk->has_partitions = 0;
d = get_device (cd_devices, num);
break;
case 'h':
disk->has_partitions = 1;
d = get_device (hd_devices, num);
break;
default:

View file

@ -43,7 +43,6 @@ grub_host_open (const char *name, grub_disk_t disk)
disk->total_sectors = 0;
disk->id = (unsigned long) "host";
disk->has_partitions = 0;
disk->data = 0;
return GRUB_ERR_NONE;

View file

@ -327,7 +327,6 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
if (drive < 0)
return grub_errno;
disk->has_partitions = 1;
disk->id = drive;
data = (struct grub_biosdisk_data *) grub_zalloc (sizeof (*data));

View file

@ -113,7 +113,6 @@ grub_nand_open (const char *name, grub_disk_t disk)
disk->id = dev_ihandle;
disk->has_partitions = 0;
disk->data = data;
return 0;

View file

@ -23,9 +23,15 @@
#include <grub/ieee1275/ieee1275.h>
#include <grub/ieee1275/ofdisk.h>
static char *last_devpath;
static grub_ieee1275_ihandle_t last_ihandle;
struct ofdisk_hash_ent
{
char *devpath;
/* Pointer to shortest available name on nodes representing canonical names,
otherwise NULL. */
const char *shortest;
struct ofdisk_hash_ent *next;
};
@ -59,60 +65,125 @@ static struct ofdisk_hash_ent *
ofdisk_hash_add (char *devpath)
{
struct ofdisk_hash_ent **head = &ofdisk_hash[ofdisk_hash_fn(devpath)];
struct ofdisk_hash_ent *p = grub_malloc(sizeof (*p));
struct ofdisk_hash_ent *p, *pcan;
char *curcan;
if (p)
p = grub_malloc(sizeof (*p));
if (!p)
return NULL;
p->devpath = devpath;
p->next = *head;
p->shortest = 0;
*head = p;
curcan = grub_ieee1275_canonicalise_devname (devpath);
if (!curcan)
{
p->devpath = devpath;
p->next = *head;
*head = p;
grub_errno = GRUB_ERR_NONE;
return p;
}
pcan = ofdisk_hash_find (curcan);
if (!pcan)
pcan = ofdisk_hash_add (curcan);
else
grub_free (curcan);
if (!pcan)
grub_errno = GRUB_ERR_NONE;
else
{
if (!pcan->shortest
|| grub_strlen (pcan->shortest) > grub_strlen (devpath))
pcan->shortest = devpath;
}
return p;
}
static int
grub_ofdisk_iterate (int (*hook) (const char *name))
static void
scan (void)
{
auto int dev_iterate (struct grub_ieee1275_devalias *alias);
int dev_iterate (struct grub_ieee1275_devalias *alias)
{
int ret = 0;
struct ofdisk_hash_ent *op;
grub_dprintf ("disk", "device name = %s type = %s\n", alias->name,
alias->type);
if (grub_strcmp (alias->type, "block") != 0)
return 0;
grub_dprintf ("disk", "disk name = %s\n", alias->name);
if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY))
op = ofdisk_hash_find (alias->path);
if (!op)
{
grub_ieee1275_phandle_t dev;
char tmp[8];
if (grub_ieee1275_finddevice (alias->path, &dev))
char *name = grub_strdup (alias->name);
if (!name)
{
grub_dprintf ("disk", "finddevice (%s) failed\n", alias->path);
return 0;
}
if (grub_ieee1275_get_property (dev, "iconname", tmp,
sizeof tmp, 0))
{
grub_dprintf ("disk", "get iconname failed\n");
return 0;
}
if (grub_strcmp (tmp, "sdmmc"))
{
grub_dprintf ("disk", "device is not an SD card\n");
grub_errno = GRUB_ERR_NONE;
return 0;
}
op = ofdisk_hash_add (name);
}
if (! grub_strcmp (alias->type, "block") &&
grub_strncmp (alias->name, "cdrom", 5))
ret = hook (alias->name);
return ret;
return 0;
}
return grub_devalias_iterate (dev_iterate);
grub_devalias_iterate (dev_iterate);
grub_ieee1275_devices_iterate (dev_iterate);
}
static int
grub_ofdisk_iterate (int (*hook) (const char *name))
{
unsigned i;
scan ();
for (i = 0; i < ARRAY_SIZE (ofdisk_hash); i++)
{
static struct ofdisk_hash_ent *ent;
for (ent = ofdisk_hash[i]; ent; ent = ent->next)
{
if (!ent->shortest)
continue;
if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY))
{
grub_ieee1275_phandle_t dev;
char tmp[8];
if (grub_ieee1275_finddevice (ent->devpath, &dev))
{
grub_dprintf ("disk", "finddevice (%s) failed\n",
ent->devpath);
continue;
}
if (grub_ieee1275_get_property (dev, "iconname", tmp,
sizeof tmp, 0))
{
grub_dprintf ("disk", "get iconname failed\n");
continue;
}
if (grub_strcmp (tmp, "sdmmc") != 0)
{
grub_dprintf ("disk", "device is not an SD card\n");
continue;
}
}
if (grub_strncmp (ent->shortest, "cdrom", 5) == 0)
continue;
if (hook (ent->shortest))
return 1;
}
}
return 0;
}
static char *
@ -137,11 +208,6 @@ compute_dev_path (const char *name)
*p++ = c;
}
if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0))
{
*p++ = ':';
*p++ = '0';
}
*p++ = '\0';
return devpath;
@ -151,8 +217,6 @@ static grub_err_t
grub_ofdisk_open (const char *name, grub_disk_t disk)
{
grub_ieee1275_phandle_t dev;
grub_ieee1275_ihandle_t dev_ihandle = 0;
struct ofdisk_hash_ent *op;
char *devpath;
/* XXX: This should be large enough for any possible case. */
char prop[64];
@ -162,69 +226,50 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
if (! devpath)
return grub_errno;
op = ofdisk_hash_find (devpath);
if (!op)
op = ofdisk_hash_add (devpath);
grub_dprintf ("disk", "Opening `%s'.\n", devpath);
grub_free (devpath);
if (!op)
return grub_errno;
grub_dprintf ("disk", "Opening `%s'.\n", op->devpath);
if (grub_ieee1275_finddevice (op->devpath, &dev))
{
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read device properties");
goto fail;
}
if (grub_ieee1275_finddevice (devpath, &dev))
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read device properties");
if (grub_ieee1275_get_property (dev, "device_type", prop, sizeof (prop),
&actual))
{
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read the device type");
goto fail;
}
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't read the device type");
if (grub_strcmp (prop, "block"))
{
grub_error (GRUB_ERR_BAD_DEVICE, "not a block device");
goto fail;
}
grub_ieee1275_open (op->devpath, &dev_ihandle);
if (! dev_ihandle)
{
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
goto fail;
}
grub_dprintf ("disk", "Opened `%s' as handle %p.\n", op->devpath,
(void *) (unsigned long) dev_ihandle);
return grub_error (GRUB_ERR_BAD_DEVICE, "not a block device");
/* XXX: There is no property to read the number of blocks. There
should be a property `#blocks', but it is not there. Perhaps it
is possible to use seek for this. */
disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;
disk->id = (unsigned long) op;
{
struct ofdisk_hash_ent *op;
op = ofdisk_hash_find (devpath);
if (!op)
op = ofdisk_hash_add (devpath);
else
grub_free (devpath);
if (!op)
return grub_errno;
disk->id = (unsigned long) op;
disk->data = op->devpath;
}
/* XXX: Read this, somehow. */
disk->has_partitions = 1;
disk->data = (void *) (unsigned long) dev_ihandle;
return 0;
fail:
if (dev_ihandle)
grub_ieee1275_close (dev_ihandle);
return grub_errno;
}
static void
grub_ofdisk_close (grub_disk_t disk)
{
grub_dprintf ("disk", "Closing handle %p.\n",
(void *) disk->data);
grub_ieee1275_close ((grub_ieee1275_ihandle_t) (unsigned long) disk->data);
if (disk->data == last_devpath)
{
if (last_ihandle)
grub_ieee1275_close (last_ihandle);
last_ihandle = 0;
last_devpath = NULL;
}
disk->data = 0;
}
static grub_err_t
@ -234,16 +279,40 @@ grub_ofdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_ssize_t status, actual;
unsigned long long pos;
if (disk->data != last_devpath)
{
if (last_ihandle)
grub_ieee1275_close (last_ihandle);
last_ihandle = 0;
last_devpath = NULL;
if (! grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0))
{
char name2[grub_strlen (disk->data) + 3];
char *p;
grub_strcpy (name2, disk->data);
p = name2 + grub_strlen (name2);
*p++ = ':';
*p++ = '0';
*p = 0;
grub_ieee1275_open (name2, &last_ihandle);
}
else
grub_ieee1275_open (disk->data, &last_ihandle);
if (! last_ihandle)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
last_devpath = disk->data;
}
pos = sector * 512UL;
grub_ieee1275_seek ((grub_ieee1275_ihandle_t) (unsigned long) disk->data,
pos, &status);
grub_ieee1275_seek (last_ihandle, pos, &status);
if (status < 0)
return grub_error (GRUB_ERR_READ_ERROR,
"seek error, can't seek block %llu",
(long long) sector);
grub_ieee1275_read ((grub_ieee1275_ihandle_t) (unsigned long) disk->data,
buf, size * 512UL, &actual);
grub_ieee1275_read (last_ihandle, buf, size * 512UL, &actual);
if (actual != (grub_ssize_t) (size * 512UL))
return grub_error (GRUB_ERR_READ_ERROR, "read error on block: %llu",
(long long) sector);
@ -281,5 +350,10 @@ grub_ofdisk_init (void)
void
grub_ofdisk_fini (void)
{
if (last_ihandle)
grub_ieee1275_close (last_ihandle);
last_ihandle = 0;
last_devpath = NULL;
grub_disk_dev_unregister (&grub_ofdisk_dev);
}

View file

@ -29,7 +29,6 @@ struct grub_loopback
{
char *devname;
grub_file_t file;
int has_partitions;
struct grub_loopback *next;
};
@ -38,7 +37,6 @@ static struct grub_loopback *loopback_list;
static const struct grub_arg_option options[] =
{
{"delete", 'd', 0, N_("Delete the loopback device entry."), 0, 0},
{"partitions", 'p', 0, N_("Simulate a hard drive with partitions."), 0, 0},
{0, 0, 0, 0, 0, 0}
};
@ -106,9 +104,6 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
grub_file_close (newdev->file);
newdev->file = file;
/* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set;
return 0;
}
@ -126,9 +121,6 @@ grub_cmd_loopback (grub_extcmd_context_t ctxt, int argc, char **args)
newdev->file = file;
/* Set has_partitions when `--partitions' was used. */
newdev->has_partitions = state[1].set;
/* Add the new entry to the list. */
newdev->next = loopback_list;
loopback_list = newdev;
@ -174,7 +166,6 @@ grub_loopback_open (const char *name, grub_disk_t disk)
disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;
disk->id = (unsigned long) dev;
disk->has_partitions = dev->has_partitions;
disk->data = dev->file;
return 0;
@ -230,8 +221,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(loopback)
{
cmd = grub_register_extcmd ("loopback", grub_cmd_loopback,
GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("loopback", grub_cmd_loopback, 0,
N_("[-d|-p] DEVICENAME FILE."),
N_("Make a device of a file."), options);
grub_disk_dev_register (&grub_loopback_dev);

View file

@ -150,7 +150,6 @@ grub_lvm_open (const char *name, grub_disk_t disk)
if (! lv)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown LVM device %s", name);
disk->has_partitions = 0;
disk->id = lv->number;
disk->data = lv;
disk->total_sectors = lv->size;
@ -280,7 +279,11 @@ grub_lvm_scan_device (const char *name)
disk = grub_disk_open (name);
if (!disk)
return 0;
{
if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
grub_errno = GRUB_ERR_NONE;
return 0;
}
/* Search for label. */
for (i = 0; i < GRUB_LVM_LABEL_SCAN_SECTORS; i++)
@ -725,6 +728,8 @@ grub_lvm_scan_device (const char *name)
grub_free (metadatabuf);
fail:
grub_disk_close (disk);
if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
grub_errno = GRUB_ERR_NONE;
return 0;
}

View file

@ -41,7 +41,6 @@ grub_memdisk_open (const char *name, grub_disk_t disk)
disk->total_sectors = memdisk_size / GRUB_DISK_SECTOR_SIZE;
disk->id = (unsigned long) "mdsk";
disk->has_partitions = 0;
return GRUB_ERR_NONE;
}

View file

@ -126,7 +126,6 @@ grub_raid_open (const char *name, grub_disk_t disk)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "unknown RAID device %s",
name);
disk->has_partitions = 1;
disk->id = array->number;
disk->data = array;

View file

@ -431,12 +431,6 @@ grub_scsi_open (const char *name, grub_disk_t disk)
"unknown SCSI device");
}
if (scsi->devtype == grub_scsi_devtype_cdrom)
disk->has_partitions = 0;
else
disk->has_partitions = 1;
/* According to USB MS tests specification, issue Test Unit Ready
* until OK */
maxtime = grub_get_time_ms () + 5000; /* It is safer value */

View file

@ -728,22 +728,27 @@ grub_ext2_open (struct grub_file *file, const char *name)
{
struct grub_ext2_data *data;
struct grub_fshelp_node *fdiro = 0;
grub_err_t err;
grub_dl_ref (my_mod);
data = grub_ext2_mount (file->device->disk);
if (! data)
goto fail;
{
err = grub_errno;
goto fail;
}
grub_fshelp_find_file (name, &data->diropen, &fdiro, grub_ext2_iterate_dir,
grub_ext2_read_symlink, GRUB_FSHELP_REG);
if (grub_errno)
err = grub_fshelp_find_file (name, &data->diropen, &fdiro,
grub_ext2_iterate_dir,
grub_ext2_read_symlink, GRUB_FSHELP_REG);
if (err)
goto fail;
if (! fdiro->inode_read)
{
grub_ext2_read_inode (data, fdiro->ino, &fdiro->inode);
if (grub_errno)
err = grub_ext2_read_inode (data, fdiro->ino, &fdiro->inode);
if (err)
goto fail;
}
@ -763,7 +768,7 @@ grub_ext2_open (struct grub_file *file, const char *name)
grub_dl_unref (my_mod);
return grub_errno;
return err;
}
static grub_err_t

View file

@ -176,7 +176,6 @@ grub_pxe_open (const char *name, grub_disk_t disk)
disk->total_sectors = 0;
disk->id = (unsigned long) data;
disk->has_partitions = 0;
disk->data = data;
return GRUB_ERR_NONE;

View file

@ -0,0 +1,75 @@
/* basename.c -- return the last element in a file name
Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2010 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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "dirname.h"
#include <string.h>
/* Return the address of the last file name component of NAME. If
NAME has no relative file name components because it is a file
system root, return the empty string. */
char *
last_component (char const *name)
{
char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
char const *p;
bool saw_slash = false;
while (ISSLASH (*base))
base++;
for (p = base; *p; p++)
{
if (ISSLASH (*p))
saw_slash = true;
else if (saw_slash)
{
base = p;
saw_slash = false;
}
}
return (char *) base;
}
/* Return the length of the basename NAME. Typically NAME is the
value returned by base_name or last_component. Act like strlen
(NAME), except omit all trailing slashes. */
size_t
base_len (char const *name)
{
size_t len;
size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
continue;
if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
&& ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
return 2;
if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
&& len == prefix_len && ISSLASH (name[prefix_len]))
return prefix_len + 1;
return len;
}

View file

@ -0,0 +1,58 @@
/* basename.c -- return the last element in a file name
Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2010 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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "dirname.h"
#include <string.h>
#include "xalloc.h"
#include "xstrndup.h"
char *
base_name (char const *name)
{
char const *base = last_component (name);
size_t length;
/* If there is no last component, then name is a file system root or the
empty string. */
if (! *base)
return xstrndup (name, base_len (name));
/* Collapse a sequence of trailing slashes into one. */
length = base_len (base);
if (ISSLASH (base[length]))
length++;
/* On systems with drive letters, `a/b:c' must return `./b:c' rather
than `b:c' to avoid confusion with a drive letter. On systems
with pure POSIX semantics, this is not an issue. */
if (FILE_SYSTEM_PREFIX_LEN (base))
{
char *p = xmalloc (length + 3);
p[0] = '.';
p[1] = '/';
memcpy (p + 2, base, length);
p[length + 2] = '\0';
return p;
}
/* Finally, copy the basename. */
return xstrndup (base, length);
}

View file

@ -0,0 +1,86 @@
/* dirname.c -- return all but the last element in a file name
Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2010 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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "dirname.h"
#include <stdlib.h>
#include <string.h>
/* Return the length of the prefix of FILE that will be used by
dir_name. If FILE is in the working directory, this returns zero
even though `dir_name (FILE)' will return ".". Works properly even
if there are trailing slashes (by effectively ignoring them). */
size_t
dir_len (char const *file)
{
size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
size_t length;
/* Advance prefix_length beyond important leading slashes. */
prefix_length += (prefix_length != 0
? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
&& ISSLASH (file[prefix_length]))
: (ISSLASH (file[0])
? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
&& ISSLASH (file[1]) && ! ISSLASH (file[2])
? 2 : 1))
: 0));
/* Strip the basename and any redundant slashes before it. */
for (length = last_component (file) - file;
prefix_length < length; length--)
if (! ISSLASH (file[length - 1]))
break;
return length;
}
/* In general, we can't use the builtin `dirname' function if available,
since it has different meanings in different environments.
In some environments the builtin `dirname' modifies its argument.
Return the leading directories part of FILE, allocated with malloc.
Works properly even if there are trailing slashes (by effectively
ignoring them). Return NULL on failure.
If lstat (FILE) would succeed, then { chdir (dir_name (FILE));
lstat (base_name (FILE)); } will access the same file. Likewise,
if the sequence { chdir (dir_name (FILE));
rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE
to "foo" in the same directory FILE was in. */
char *
mdir_name (char const *file)
{
size_t length = dir_len (file);
bool append_dot = (length == 0
|| (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
&& length == FILE_SYSTEM_PREFIX_LEN (file)
&& file[2] != '\0' && ! ISSLASH (file[2])));
char *dir = malloc (length + append_dot + 1);
if (!dir)
return NULL;
memcpy (dir, file, length);
if (append_dot)
dir[length++] = '.';
dir[length] = '\0';
return dir;
}

View file

@ -0,0 +1,38 @@
/* dirname.c -- return all but the last element in a file name
Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2010 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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "dirname.h"
#include <stdlib.h>
#include <string.h>
#include "xalloc.h"
/* Just like mdir_name (dirname-lgpl.c), except, rather than
returning NULL upon malloc failure, here, we report the
"memory exhausted" condition and exit. */
char *
dir_name (char const *file)
{
char *result = mdir_name (file);
if (!result)
xalloc_die ();
return result;
}

View file

@ -0,0 +1,74 @@
/* Take file names apart into directory and base names.
Copyright (C) 1998, 2001, 2003-2006, 2009-2010 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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef DIRNAME_H_
# define DIRNAME_H_ 1
# include <stdbool.h>
# include <stddef.h>
# ifndef DIRECTORY_SEPARATOR
# define DIRECTORY_SEPARATOR '/'
# endif
# ifndef ISSLASH
# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
# endif
# ifndef FILE_SYSTEM_PREFIX_LEN
# if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX
/* This internal macro assumes ASCII, but all hosts that support drive
letters use ASCII. */
# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \
<= 'z' - 'a')
# define FILE_SYSTEM_PREFIX_LEN(Filename) \
(_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0)
# else
# define FILE_SYSTEM_PREFIX_LEN(Filename) 0
# endif
# endif
# ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
# endif
# ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
# endif
# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)])
# else
# define IS_ABSOLUTE_FILE_NAME(F) \
(ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F))
# endif
# define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))
# if GNULIB_DIRNAME
char *base_name (char const *file);
char *dir_name (char const *file);
# endif
char *mdir_name (char const *file);
size_t base_len (char const *file);
size_t dir_len (char const *file);
char *last_component (char const *file);
bool strip_trailing_slashes (char *file);
#endif /* not DIRNAME_H_ */

View file

@ -88,6 +88,15 @@ extern void __error_at_line (int status, int errnum, const char *file_name,
# include <fcntl.h>
# include <unistd.h>
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* Get declarations of the Win32 API functions. */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# endif
/* The gnulib override of fcntl is not needed in this file. */
# undef fcntl
# if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P
# ifndef HAVE_DECL_STRERROR_R
"this configure-time declaration test was not run"
@ -104,10 +113,29 @@ extern char *program_name;
# endif /* HAVE_STRERROR_R || defined strerror_r */
#endif /* not _LIBC */
#if !_LIBC
/* Return non-zero if FD is open. */
static inline int
is_open (int fd)
{
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* On Win32: The initial state of unassigned standard file descriptors is
that they are open but point to an INVALID_HANDLE_VALUE. There is no
fcntl, and the gnulib replacement fcntl does not support F_GETFL. */
return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
# else
# ifndef F_GETFL
# error Please port fcntl to your platform
# endif
return 0 <= fcntl (fd, F_GETFL);
# endif
}
#endif
static inline void
flush_stdout (void)
{
#if !_LIBC && defined F_GETFL
#if !_LIBC
int stdout_fd;
# if GNULIB_FREOPEN_SAFER
@ -124,7 +152,7 @@ flush_stdout (void)
/* POSIX states that fflush (stdout) after fclose is unspecified; it
is safe in glibc, but not on all other platforms. fflush (NULL)
is always defined, but too draconian. */
if (0 <= stdout_fd && 0 <= fcntl (stdout_fd, F_GETFL))
if (0 <= stdout_fd && is_open (stdout_fd))
#endif
fflush (stdout);
}

View file

@ -348,8 +348,6 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
int long_only, struct _getopt_data *d, int posixly_correct)
{
int print_errors = d->opterr;
if (optstring[0] == ':')
print_errors = 0;
if (argc < 1)
return -1;
@ -364,6 +362,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
posixly_correct);
d->__initialized = 1;
}
else if (optstring[0] == '-' || optstring[0] == '+')
optstring++;
if (optstring[0] == ':')
print_errors = 0;
/* Test whether ARGV[optind] points to a non-option argument.
Either it does not have option syntax, or there is an environment flag
@ -633,8 +635,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
char *buf;
if (__asprintf (&buf, _("\
%s: option '%s' requires an argument\n"),
argv[0], argv[d->optind - 1]) >= 0)
%s: option '--%s' requires an argument\n"),
argv[0], pfound->name) >= 0)
{
_IO_flockfile (stderr);
@ -651,8 +653,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
}
#else
fprintf (stderr,
_("%s: option '%s' requires an argument\n"),
argv[0], argv[d->optind - 1]);
_("%s: option '--%s' requires an argument\n"),
argv[0], pfound->name);
#endif
}
d->__nextchar += strlen (d->__nextchar);
@ -736,13 +738,13 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
{
char c = *d->__nextchar++;
char *temp = strchr (optstring, c);
const char *temp = strchr (optstring, c);
/* Increment `optind' when we start to process its last character. */
if (*d->__nextchar == '\0')
++d->optind;
if (temp == NULL || c == ':')
if (temp == NULL || c == ':' || c == ';')
{
if (print_errors)
{
@ -864,7 +866,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
pfound = p;
indfound = option_index;
}
else
else if (long_only
|| pfound->has_arg != p->has_arg
|| pfound->flag != p->flag
|| pfound->val != p->val)
/* Second or later nonexact match found. */
ambig = 1;
}
@ -876,7 +881,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
char *buf;
if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
argv[0], argv[d->optind]) >= 0)
argv[0], d->optarg) >= 0)
{
_IO_flockfile (stderr);
@ -892,7 +897,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
}
#else
fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
argv[0], argv[d->optind]);
argv[0], d->optarg);
#endif
}
d->__nextchar += strlen (d->__nextchar);
@ -955,8 +960,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
char *buf;
if (__asprintf (&buf, _("\
%s: option '%s' requires an argument\n"),
argv[0], argv[d->optind - 1]) >= 0)
%s: option '-W %s' requires an argument\n"),
argv[0], pfound->name) >= 0)
{
_IO_flockfile (stderr);
@ -972,15 +977,17 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
free (buf);
}
#else
fprintf (stderr,
_("%s: option '%s' requires an argument\n"),
argv[0], argv[d->optind - 1]);
fprintf (stderr, _("\
%s: option '-W %s' requires an argument\n"),
argv[0], pfound->name);
#endif
}
d->__nextchar += strlen (d->__nextchar);
return optstring[0] == ':' ? ':' : '?';
}
}
else
d->optarg = NULL;
d->__nextchar += strlen (d->__nextchar);
if (longind != NULL)
*longind = option_index;

View file

@ -30,6 +30,40 @@ extern int _getopt_internal (int ___argc, char **___argv,
/* Reentrant versions which can handle parsing multiple argument
vectors at the same time. */
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,
the default is REQUIRE_ORDER if the environment variable
POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options;
stop option processing when the first non-option is seen.
This is what Unix does.
This mode of operation is selected by either setting the environment
variable POSIXLY_CORRECT, or using `+' as the first character
of the list of option characters, or by calling getopt.
PERMUTE is the default. We permute the contents of ARGV as we
scan, so that eventually all the non-options are at the end.
This allows options to be given in any order, even with programs
that were not written to expect this.
RETURN_IN_ORDER is an option available to programs that were
written to expect options and other ARGV-elements in any order
and that care about the ordering of the two. We describe each
non-option ARGV-element as if it were the argument of an option
with character code 1. Using `-' as the first character of the
list of option characters selects this mode of operation.
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return -1 with `optind' != ARGC. */
enum __ord
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
};
/* Data type for reentrant functions. */
struct _getopt_data
{
@ -54,39 +88,8 @@ struct _getopt_data
by advancing to the next ARGV-element. */
char *__nextchar;
/* Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything,
the default is REQUIRE_ORDER if the environment variable
POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options;
stop option processing when the first non-option is seen.
This is what Unix does.
This mode of operation is selected by either setting the environment
variable POSIXLY_CORRECT, or using `+' as the first character
of the list of option characters, or by calling getopt.
PERMUTE is the default. We permute the contents of ARGV as we
scan, so that eventually all the non-options are at the end.
This allows options to be given in any order, even with programs
that were not written to expect this.
RETURN_IN_ORDER is an option available to programs that were
written to expect options and other ARGV-elements in any order
and that care about the ordering of the two. We describe each
non-option ARGV-element as if it were the argument of an option
with character code 1. Using `-' as the first character of the
list of option characters selects this mode of operation.
The special argument `--' forces an end of option-scanning regardless
of the value of `ordering'. In the case of RETURN_IN_ORDER, only
`--' can cause `getopt' to return -1 with `optind' != ARGC. */
enum
{
REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
} __ordering;
/* See __ord above. */
enum __ord __ordering;
/* If the POSIXLY_CORRECT environment variable is set
or getopt was called. */

View file

@ -114,10 +114,10 @@ typedef unsigned long int reg_syntax_t;
/* If this bit is set, then ^ and $ are always anchors (outside bracket
expressions, of course).
If this bit is not set, then it depends:
^ is an anchor if it is at the beginning of a regular
expression or after an open-group or an alternation operator;
$ is an anchor if it is at the end of a regular expression, or
before a close-group or an alternation operator.
^ is an anchor if it is at the beginning of a regular
expression or after an open-group or an alternation operator;
$ is an anchor if it is at the end of a regular expression, or
before a close-group or an alternation operator.
This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
POSIX draft 11.2 says that * etc. in leading positions is undefined.
@ -219,8 +219,8 @@ typedef unsigned long int reg_syntax_t;
whether ^ should be special. */
# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
/* If this bit is set, then \{ cannot be first in an bre or
immediately after an alternation or begin-group operator. */
/* If this bit is set, then \{ cannot be first in a regex or
immediately after an alternation, open-group or \} operator. */
# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
/* If this bit is set, then no_sub will be set to 1 during
@ -495,8 +495,8 @@ struct re_pattern_buffer
#endif
unsigned int _REG_RE_NAME (regs_allocated) : 2;
/* Set to zero when `regex_compile' compiles a pattern; set to one
by `re_compile_fastmap' if it updates the fastmap. */
/* Set to zero when `re_compile_pattern' compiles a pattern; set to
one by `re_compile_fastmap' if it updates the fastmap. */
unsigned int _REG_RE_NAME (fastmap_accurate) : 1;
/* If set, `re_match_2' does not return information about
@ -610,8 +610,8 @@ extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer,
register data.
Unless this function is called, the first search or match using
PATTERN_BUFFER will allocate its own register data, without
freeing the old data. */
BUFFER will allocate its own register data, without freeing the old
data. */
extern void re_set_registers (struct re_pattern_buffer *__buffer,
struct re_registers *__regs,
__re_size_t __num_regs,

View file

@ -733,15 +733,17 @@ re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
mbstate_t cur_state;
wchar_t wc2;
Idx mlen = raw + pstr->len - p;
unsigned char buf[6];
size_t mbclen;
#if 0 /* dead code: buf is set but never used */
unsigned char buf[6];
if (BE (pstr->trans != NULL, 0))
{
int i = mlen < 6 ? mlen : 6;
while (--i >= 0)
buf[i] = pstr->trans[p[i]];
}
#endif
/* XXX Don't use mbrtowc, we know which conversion
to use (UTF-8 -> UCS4). */
memset (&cur_state, 0, sizeof (cur_state));

View file

@ -467,6 +467,8 @@ static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
# else
/* alloca is implemented with malloc, so just use malloc. */
# define __libc_use_alloca(n) 0
# undef alloca
# define alloca(n) malloc (n)
# endif
#endif

View file

@ -0,0 +1,45 @@
/* stripslash.c -- remove redundant trailing slashes from a file name
Copyright (C) 1990, 2001, 2003-2006, 2009-2010 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
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "dirname.h"
/* Remove trailing slashes from FILE. Return true if a trailing slash
was removed. This is useful when using file name completion from a
shell that adds a "/" after directory names (such as tcsh and
bash), because on symlinks to directories, several system calls
have different semantics according to whether a trailing slash is
present. */
bool
strip_trailing_slashes (char *file)
{
char *base = last_component (file);
char *base_lim;
bool had_slash;
/* last_component returns "" for file system roots, but we need to turn
`///' into `/'. */
if (! *base)
base = file;
base_lim = base + base_len (base);
had_slash = (*base_lim != '\0');
*base_lim = '\0';
return had_slash;
}

View file

@ -39,8 +39,8 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(hello)
{
cmd = grub_register_extcmd ("hello", grub_cmd_hello, GRUB_COMMAND_FLAG_BOTH,
0, N_("Say \"Hello World\"."), 0);
cmd = grub_register_extcmd ("hello", grub_cmd_hello, 0, 0,
N_("Say \"Hello World\"."), 0);
}
GRUB_MOD_FINI(hello)

View file

@ -40,7 +40,7 @@ grub_register_command_prio (const char *name,
cmd->summary = (summary) ? summary : "";
cmd->description = description;
cmd->flags = GRUB_COMMAND_FLAG_BOTH;
cmd->flags = 0;
cmd->prio = prio;
grub_prio_list_insert (GRUB_AS_PRIO_LIST_P (&grub_command_list),

View file

@ -103,7 +103,7 @@ grub_device_iterate (int (*hook) (const char *name))
return 0;
}
if (dev->disk && dev->disk->has_partitions)
if (dev->disk)
{
struct part_ent *p;
int ret = 0;

View file

@ -281,12 +281,6 @@ grub_disk_open (const char *name)
goto fail;
}
if (p && ! disk->has_partitions)
{
grub_error (GRUB_ERR_BAD_DEVICE, "no partition on this disk");
goto fail;
}
disk->dev = dev;
if (p)

View file

@ -572,6 +572,10 @@ int
grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused)))
{
#ifdef __linux__
/* User explicitly claims that this drive is visible by BIOS. */
if (grub_util_biosdisk_is_present (os_dev))
return GRUB_DEV_ABSTRACTION_NONE;
/* Check for LVM. */
if (!strncmp (os_dev, "/dev/mapper/", 12)
&& ! grub_util_is_dmraid (os_dev)

View file

@ -221,7 +221,6 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
"no mapping exists for `%s'", name);
disk->has_partitions = 1;
disk->id = drive;
disk->data = data = xmalloc (sizeof (struct grub_util_biosdisk_data));
data->dev = NULL;
@ -1117,6 +1116,16 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st)
return path;
}
if (strncmp ("md", p, 2) == 0
&& p[2] >= '0' && p[2] <= '9')
{
char *ptr = p + 2;
while (*ptr >= '0' && *ptr <= '9')
ptr++;
*ptr = 0;
return path;
}
/* If this is an IDE, SCSI or Virtio disk. */
if (strncmp ("vdisk", p, 5) == 0
&& p[5] >= 'a' && p[5] <= 'z')
@ -1334,7 +1343,7 @@ device_is_wholedisk (const char *os_dev)
#endif /* defined(__NetBSD__) */
static int
find_system_device (const char *os_dev, struct stat *st)
find_system_device (const char *os_dev, struct stat *st, int add)
{
unsigned int i;
char *os_disk;
@ -1352,6 +1361,9 @@ find_system_device (const char *os_dev, struct stat *st)
return i;
}
if (!add)
return -1;
if (i == ARRAY_SIZE (map))
grub_util_error (_("device count exceeds limit"));
@ -1361,6 +1373,17 @@ find_system_device (const char *os_dev, struct stat *st)
return i;
}
int
grub_util_biosdisk_is_present (const char *os_dev)
{
struct stat st;
if (stat (os_dev, &st) < 0)
return 0;
return find_system_device (os_dev, &st, 0) != -1;
}
char *
grub_util_biosdisk_get_grub_dev (const char *os_dev)
{
@ -1373,7 +1396,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
return 0;
}
drive = find_system_device (os_dev, &st);
drive = find_system_device (os_dev, &st, 1);
if (drive < 0)
{
grub_error (GRUB_ERR_UNKNOWN_DEVICE,

View file

@ -190,13 +190,14 @@ main (int argc, char *argv[])
grub_emu_init ();
grub_console_init ();
grub_host_init ();
grub_hostfs_init ();
/* XXX: This is a bit unportable. */
grub_util_biosdisk_init (dev_map);
grub_init_all ();
grub_hostfs_init ();
grub_emu_post_init ();
/* Make sure that there is a root device. */

View file

@ -19,7 +19,7 @@
#include <grub/kernel.h>
#include <grub/mm.h>
#include <grub/machine/boot.h>
#include <grub/machine/init.h>
#include <grub/i386/floppy.h>
#include <grub/machine/memory.h>
#include <grub/machine/console.h>
#include <grub/machine/kernel.h>
@ -171,11 +171,6 @@ grub_machine_init (void)
if (grub_lower_mem < GRUB_MEMORY_MACHINE_RESERVED_END)
grub_fatal ("too small memory");
#if 0
/* Turn on Gate A20 to access >1MB. */
grub_gate_a20 (1);
#endif
/* FIXME: This prevents loader/i386/linux.c from using low memory. When our
heap implements support for requesting a chunk in low memory, this should
no longer be a problem. */

View file

@ -16,9 +16,8 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/machine/init.h>
#include <grub/machine/int.h>
#include <grub/machine/memory.h>
#include <grub/machine/int.h>
#include <grub/err.h>
#include <grub/types.h>
#include <grub/misc.h>

View file

@ -202,7 +202,7 @@ LOCAL (codestart):
.code32
incl %eax
call EXT_C(grub_gate_a20)
call grub_gate_a20
#ifdef ENABLE_LZMA
movl $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %edi
@ -292,7 +292,7 @@ VARIABLE(grub_boot_drive)
* It also eats any keystrokes in the keyboard buffer. :-(
*/
FUNCTION(grub_gate_a20)
grub_gate_a20:
movl %eax, %edx
gate_a20_test_current_state:
@ -478,7 +478,7 @@ FUNCTION(grub_chainloader_real_boot)
/* Turn off Gate A20 */
xorl %eax, %eax
call EXT_C(grub_gate_a20)
call grub_gate_a20
/* set up to pass boot drive */
popl %edx

View file

@ -423,3 +423,47 @@ grub_reboot (void)
for (;;) ;
}
#endif
/* Resolve aliases. */
char *
grub_ieee1275_canonicalise_devname (const char *path)
{
struct canon_args
{
struct grub_ieee1275_common_hdr common;
grub_ieee1275_cell_t path;
grub_ieee1275_cell_t buf;
grub_ieee1275_cell_t inlen;
grub_ieee1275_cell_t outlen;
}
args;
char *buf = NULL;
grub_size_t bufsize = 64;
int i;
for (i = 0; i < 2; i++)
{
grub_free (buf);
buf = grub_malloc (bufsize);
if (!buf)
return NULL;
INIT_IEEE1275_COMMON (&args.common, "canon", 3, 1);
args.path = (grub_ieee1275_cell_t) path;
args.buf = (grub_ieee1275_cell_t) buf;
args.inlen = (grub_ieee1275_cell_t) (bufsize - 1);
if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
return 0;
if (args.outlen > bufsize - 1)
{
bufsize = args.outlen + 2;
continue;
}
return buf;
}
/* Shouldn't reach here. */
grub_free (buf);
return NULL;
}

View file

@ -196,6 +196,8 @@ grub_vprintf (const char *fmt, va_list args)
grub_size_t s;
static char buf[PREALLOC_SIZE + 1];
char *curbuf = buf;
va_list ap2;
va_copy (ap2, args);
s = grub_vsnprintf_real (buf, PREALLOC_SIZE, fmt, args);
if (s > PREALLOC_SIZE)
@ -210,7 +212,7 @@ grub_vprintf (const char *fmt, va_list args)
buf[PREALLOC_SIZE] = 0;
}
else
s = grub_vsnprintf_real (curbuf, s, fmt, args);
s = grub_vsnprintf_real (curbuf, s, fmt, ap2);
}
grub_xputs (curbuf);
@ -947,11 +949,13 @@ grub_xvasprintf (const char *fmt, va_list ap)
while (1)
{
va_list ap2;
va_copy (ap2, ap);
ret = grub_malloc (as + 1);
if (!ret)
return NULL;
s = grub_vsnprintf_real (ret, as, fmt, ap);
s = grub_vsnprintf_real (ret, as, fmt, ap2);
if (s <= as)
return ret;

View file

@ -61,9 +61,11 @@ codestart:
/* Save ieee1275 stack for future use by booter. */
mov %o6, %o1
/* Our future stack. */
sethi %hi(GRUB_KERNEL_MACHINE_STACK_SIZE - 2047), %o5
or %o5, %lo(GRUB_KERNEL_MACHINE_STACK_SIZE - 2047), %o5
sethi %hi(GRUB_KERNEL_MACHINE_STACK_SIZE), %o5
or %o5, %lo(GRUB_KERNEL_MACHINE_STACK_SIZE), %o5
add %o3, %o5, %o6
and %o6, ~0xff, %o6
sub %o6, 2047, %o6
sub %o2, 4, %o2
sub %o3, 4, %o3

View file

@ -231,7 +231,6 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
{
int curarg;
int arglen;
int complete = 0;
char **argl = 0;
int num = 0;
auto grub_err_t add_arg (char *s);
@ -258,7 +257,8 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
char *option = 0;
/* No option is used. */
if (arg[0] != '-' || grub_strlen (arg) == 1)
if ((num && GRUB_COMMAND_OPTIONS_AT_START)
|| arg[0] != '-' || grub_strlen (arg) == 1)
{
if (add_arg (arg) != 0)
goto fail;
@ -269,11 +269,28 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
/* One or more short options. */
if (arg[1] != '-')
{
char *curshort = arg + 1;
char *curshort;
if (cmd->cmd->flags & GRUB_COMMAND_ACCEPT_DASH)
{
for (curshort = arg + 1; *curshort; curshort++)
if (!find_short (cmd->options, *curshort))
break;
if (*curshort)
{
if (add_arg (arg) != 0)
goto fail;
continue;
}
}
curshort = arg + 1;
while (1)
{
opt = find_short (cmd->options, *curshort);
if (! opt)
{
grub_error (GRUB_ERR_BAD_ARGUMENT,
@ -330,6 +347,14 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
}
opt = find_long (cmd->options, arg + 2, arglen);
if (!opt && (cmd->cmd->flags & GRUB_COMMAND_ACCEPT_DASH))
{
if (add_arg (arg) != 0)
goto fail;
continue;
}
if (! opt)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown argument `%s'", arg);
@ -398,13 +423,12 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
}
}
complete = 1;
*args = argl;
*argnum = num;
return 1;
fail:
return complete;
return 0;
}
struct grub_arg_list*

View file

@ -22,11 +22,13 @@
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/kernel.h>
#include <grub/acpi.h>
void
grub_halt (void)
{
grub_machine_fini ();
grub_acpi_halt ();
efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_SUCCESS, 0, NULL);

View file

@ -18,6 +18,7 @@
#include <grub/cpu/io.h>
#include <grub/misc.h>
#include <grub/acpi.h>
const char bochs_shutdown[] = "Shutdown";
@ -40,6 +41,10 @@ grub_halt (void)
{
unsigned int i;
#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_MULTIBOOT)
grub_acpi_halt ();
#endif
/* Disable interrupts. */
__asm__ __volatile__ ("cli");

View file

@ -270,7 +270,7 @@ static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b)
s->block.hash.uncompressed += s->block.uncompressed;
GRUB_MD_CRC32->write(s->block.hash.crc32_context,
(const uint8_t *)&s->block.hash, sizeof(s->block.hash));
(const uint8_t *)&s->block.hash, 2 * sizeof(vli_type));
++s->block.count;
}
@ -329,8 +329,7 @@ static enum xz_ret dec_index(struct xz_dec *s, struct xz_buf *b)
s->index.hash.uncompressed += s->vli;
GRUB_MD_CRC32->write(s->index.hash.crc32_context,
(const uint8_t *)&s->index.hash,
sizeof(s->index.hash));
(const uint8_t *)&s->index.hash, 2 * sizeof(vli_type));
--s->index.count;
s->index.sequence = SEQ_INDEX_UNPADDED;
@ -671,8 +670,17 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b)
index_update(s, b);
/* Compare the hashes to validate the Index field. */
if (! memeq(&s->block.hash, &s->index.hash, sizeof(s->block.hash)))
GRUB_MD_CRC32->final(s->block.hash.crc32_context);
GRUB_MD_CRC32->final(s->index.hash.crc32_context);
uint32_t block_crc = *(uint32_t*)GRUB_MD_CRC32->read(s->block.hash.crc32_context);
uint32_t index_crc = *(uint32_t*)GRUB_MD_CRC32->read(s->index.hash.crc32_context);
if (s->block.hash.unpadded != s->index.hash.unpadded
|| s->block.hash.uncompressed != s->index.hash.uncompressed
|| block_crc != index_crc)
{
return XZ_DATA_ERROR;
}
s->sequence = SEQ_INDEX_CRC32;
@ -830,8 +838,15 @@ void xz_dec_reset(struct xz_dec *s)
s->allow_buf_error = false;
s->pos = 0;
memzero(&s->block, sizeof(s->block));
memzero(&s->index, sizeof(s->index));
{
uint8_t *t;
t = s->block.hash.crc32_context;
memzero(&s->block, sizeof(s->block));
s->block.hash.crc32_context = t;
t = s->index.hash.crc32_context;
memzero(&s->index, sizeof(s->index));
s->index.hash.crc32_context = t;
}
s->temp.pos = 0;
s->temp.size = STREAM_HEADER_SIZE;
@ -846,6 +861,9 @@ void xz_dec_end(struct xz_dec *s)
{
if (s != NULL) {
xz_dec_lzma2_end(s->lzma2);
kfree(s->index.hash.crc32_context);
kfree(s->block.hash.crc32_context);
kfree(s->crc32_context);
#ifdef XZ_DEC_BCJ
xz_dec_bcj_end(s->bcj);
#endif

View file

@ -1942,16 +1942,13 @@ GRUB_MOD_INIT (bsd)
/* Net and OpenBSD kernels are often compressed. */
grub_dl_load ("gzio");
cmd_freebsd = grub_register_extcmd ("kfreebsd", grub_cmd_freebsd,
GRUB_COMMAND_FLAG_BOTH,
cmd_freebsd = grub_register_extcmd ("kfreebsd", grub_cmd_freebsd, 0,
N_("FILE"), N_("Load kernel of FreeBSD."),
freebsd_opts);
cmd_openbsd = grub_register_extcmd ("kopenbsd", grub_cmd_openbsd,
GRUB_COMMAND_FLAG_BOTH,
cmd_openbsd = grub_register_extcmd ("kopenbsd", grub_cmd_openbsd, 0,
N_("FILE"), N_("Load kernel of OpenBSD."),
openbsd_opts);
cmd_netbsd = grub_register_extcmd ("knetbsd", grub_cmd_netbsd,
GRUB_COMMAND_FLAG_BOTH,
cmd_netbsd = grub_register_extcmd ("knetbsd", grub_cmd_netbsd, 0,
N_("FILE"), N_("Load kernel of NetBSD."),
netbsd_opts);
cmd_freebsd_loadenv =

View file

@ -26,13 +26,13 @@
#include <grub/disk.h>
#include <grub/misc.h>
#include <grub/types.h>
#include <grub/machine/init.h>
#include <grub/partition.h>
#include <grub/machine/memory.h>
#include <grub/dl.h>
#include <grub/command.h>
#include <grub/msdos_partition.h>
#include <grub/machine/biosnum.h>
#include <grub/cpu/floppy.h>
#include <grub/i18n.h>
#include <grub/video.h>
#include <grub/mm.h>

View file

@ -25,7 +25,6 @@
#include <grub/disk.h>
#include <grub/misc.h>
#include <grub/types.h>
#include <grub/machine/init.h>
#include <grub/machine/memory.h>
#include <grub/dl.h>
#include <grub/cpu/linux.h>

View file

@ -24,7 +24,6 @@
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/ieee1275/ieee1275.h>
#include <grub/gzio.h>
#include <grub/command.h>
#include <grub/i18n.h>

View file

@ -1434,8 +1434,7 @@ GRUB_MOD_INIT(xnu)
"Load XNU ramdisk. "
"It will be seen as md0.");
cmd_splash = grub_register_extcmd ("xnu_splash",
grub_cmd_xnu_splash,
GRUB_COMMAND_FLAG_BOTH, 0,
grub_cmd_xnu_splash, 0, 0,
N_("Load a splash image for XNU."),
xnu_splash_cmd_options);

View file

@ -160,14 +160,23 @@ iterate_dev (const char *devname)
if (dev)
{
if (dev->disk && dev->disk->has_partitions)
char tmp[grub_strlen (devname) + sizeof (",")];
grub_memcpy (tmp, devname, grub_strlen (devname));
if (grub_strcmp (devname, current_word) == 0)
{
if (add_completion (devname, ",", GRUB_COMPLETION_TYPE_DEVICE))
if (add_completion (devname, ")", GRUB_COMPLETION_TYPE_PARTITION))
return 1;
if (dev->disk)
if (grub_partition_iterate (dev->disk, iterate_partition))
return 1;
}
else
{
if (add_completion (devname, ")", GRUB_COMPLETION_TYPE_DEVICE))
grub_memcpy (tmp + grub_strlen (devname), "", sizeof (""));
if (add_completion (tmp, "", GRUB_COMPLETION_TYPE_DEVICE))
return 1;
}
}
@ -200,7 +209,7 @@ complete_device (void)
if (dev)
{
if (dev->disk && dev->disk->has_partitions)
if (dev->disk)
{
if (grub_partition_iterate (dev->disk, iterate_partition))
{
@ -247,7 +256,8 @@ complete_file (void)
goto fail;
}
dir = grub_strchr (current_word, '/');
dir = grub_strchr (current_word + (device ? 2 + grub_strlen (device) : 0),
'/');
last_dir = grub_strrchr (current_word, '/');
if (dir)
{
@ -419,11 +429,8 @@ grub_normal_do_completion (char *buf, int *restore,
{
if (cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE)
{
if (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE)
{
if (add_completion (cmd->name, " ", GRUB_COMPLETION_TYPE_COMMAND))
goto fail;
}
if (add_completion (cmd->name, " ", GRUB_COMPLETION_TYPE_COMMAND))
goto fail;
}
}
}

View file

@ -155,7 +155,6 @@ read_command_list (const char *prefix)
grub_dyncmd_dispatcher,
GRUB_COMMAND_FLAG_BLOCKS
| GRUB_COMMAND_FLAG_EXTCMD
| GRUB_COMMAND_FLAG_CMDLINE
| GRUB_COMMAND_FLAG_DYNCMD,
0, N_("not loaded"), 0,
prio);

View file

@ -26,6 +26,7 @@
#include <grub/datetime.h>
#include <grub/term.h>
#include <grub/i18n.h>
#include <grub/partition.h>
/* Print the information on the device NAME. */
grub_err_t
@ -107,10 +108,18 @@ grub_normal_print_device_info (const char *name)
grub_errno = GRUB_ERR_NONE;
}
}
else if (! dev->disk->has_partitions || dev->disk->partition)
grub_printf ("%s", _("Unknown filesystem"));
else
grub_printf ("%s", _("Partition table"));
grub_printf ("%s", _("Not a known filesystem"));
if (dev->disk->partition)
grub_printf (_(" - Partition start at %u"),
grub_partition_get_start (dev->disk->partition));
if (grub_disk_get_size (dev->disk) == GRUB_DISK_SIZE_UNKNOWN)
grub_printf (_(" - Total size unknown"),
grub_disk_get_size (dev->disk));
else
grub_printf (_(" - Total size %u sectors"),
grub_disk_get_size (dev->disk));
grub_device_close (dev);
}

View file

@ -657,7 +657,7 @@ put_glyphs_terminal (const struct grub_unicode_glyph *visual,
>= (grub_ssize_t) grub_term_height (term) - 2)
{
state->backlog_glyphs = visual_ptr + 1;
state->backlog_len = visual_len - (visual - visual_ptr) - 1;
state->backlog_len = visual_len - (visual_ptr - visual) - 1;
return 1;
}
@ -688,6 +688,7 @@ print_backlog (struct grub_term_output *term,
grub_free (state->free);
state->free = NULL;
state->backlog_len = 0;
state->backlog_ucs4 = 0;
}
return ret;
}
@ -703,6 +704,7 @@ print_backlog (struct grub_term_output *term,
grub_free (state->free);
state->free = NULL;
state->backlog_len = 0;
state->backlog_glyphs = 0;
}
return ret;
}

View file

@ -87,36 +87,23 @@ sun_partition_map_iterate (grub_disk_t disk,
int (*hook) (grub_disk_t disk,
const grub_partition_t partition))
{
grub_partition_t p;
struct grub_partition p;
struct grub_sun_block block;
int partnum;
grub_err_t err;
p = (grub_partition_t) grub_zalloc (sizeof (struct grub_partition));
if (! p)
return grub_errno;
p->partmap = &grub_sun_partition_map;
p.partmap = &grub_sun_partition_map;
err = grub_disk_read (disk, 0, 0, sizeof (struct grub_sun_block),
&block);
if (err)
{
grub_free (p);
return err;
}
return err;
if (GRUB_PARTMAP_SUN_MAGIC != grub_be_to_cpu16 (block.magic))
{
grub_free (p);
return grub_error (GRUB_ERR_BAD_PART_TABLE, "not a sun partition table");
}
return grub_error (GRUB_ERR_BAD_PART_TABLE, "not a sun partition table");
if (! grub_sun_is_valid (&block))
{
grub_free (p);
return grub_error (GRUB_ERR_BAD_PART_TABLE, "invalid checksum");
}
/* Maybe another error value would be better, because partition
table _is_ recognized but invalid. */
for (partnum = 0; partnum < GRUB_PARTMAP_SUN_MAX_PARTS; partnum++)
@ -128,20 +115,18 @@ sun_partition_map_iterate (grub_disk_t disk,
continue;
desc = &block.partitions[partnum];
p->start = ((grub_uint64_t) grub_be_to_cpu32 (desc->start_cylinder)
p.start = ((grub_uint64_t) grub_be_to_cpu32 (desc->start_cylinder)
* grub_be_to_cpu16 (block.ntrks)
* grub_be_to_cpu16 (block.nsect));
p->len = grub_be_to_cpu32 (desc->num_sectors);
p->number = p->index = partnum;
if (p->len)
p.len = grub_be_to_cpu32 (desc->num_sectors);
p.number = p.index = partnum;
if (p.len)
{
if (hook (disk, p))
if (hook (disk, &p))
partnum = GRUB_PARTMAP_SUN_MAX_PARTS;
}
}
grub_free (p);
return grub_errno;
}

View file

@ -1207,8 +1207,7 @@ GRUB_MOD_INIT(gfxterm)
grub_term_register_output ("gfxterm", &grub_video_term);
background_image_cmd_handle =
grub_register_extcmd ("background_image",
grub_gfxterm_background_image_cmd,
GRUB_COMMAND_FLAG_BOTH,
grub_gfxterm_background_image_cmd, 0,
N_("[-m (stretch|normal)] FILE"),
N_("Load background image for active terminal."),
background_image_cmd_options);

View file

@ -341,8 +341,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(serial)
{
cmd = grub_register_extcmd ("serial", grub_cmd_serial,
GRUB_COMMAND_FLAG_BOTH,
cmd = grub_register_extcmd ("serial", grub_cmd_serial, 0,
N_("[OPTIONS...]"),
N_("Configure serial port."), options);
#ifndef GRUB_MACHINE_EMU

View file

@ -37,8 +37,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT (functional_test)
{
cmd = grub_register_extcmd ("functional_test", grub_functional_test,
GRUB_COMMAND_FLAG_CMDLINE, 0,
cmd = grub_register_extcmd ("functional_test", grub_functional_test, 0, 0,
"Run all functional tests.", 0);
}

View file

@ -40,7 +40,7 @@ static grub_extcmd_t cmd;
GRUB_MOD_INIT(test_blockarg)
{
cmd = grub_register_extcmd ("test_blockarg", test_blockarg,
GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_BLOCKS,
GRUB_COMMAND_FLAG_BLOCKS,
N_("BLOCK"),
N_("Print and execute block argument."), 0);
}

View file

@ -127,9 +127,11 @@ grub_video_gop_get_bitmask (grub_uint32_t mask, unsigned int *mask_size,
}
static grub_err_t
grub_video_gop_fill_mode_info (struct grub_efi_gop_mode_info *in,
grub_video_gop_fill_mode_info (unsigned mode,
struct grub_efi_gop_mode_info *in,
struct grub_video_mode_info *out)
{
out->mode_number = mode;
out->number_of_colors = 256;
out->width = in->width;
out->height = in->height;
@ -183,9 +185,43 @@ grub_video_gop_fill_mode_info (struct grub_efi_gop_mode_info *in,
return GRUB_ERR_NONE;
}
static int
grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info))
{
unsigned mode;
for (mode = 0; mode < gop->mode->max_mode; mode++)
{
grub_efi_uintn_t size;
grub_efi_status_t status;
struct grub_efi_gop_mode_info *info = NULL;
grub_err_t err;
struct grub_video_mode_info mode_info;
status = efi_call_4 (gop->query_mode, gop, mode, &size, &info);
if (status)
{
info = 0;
continue;
}
err = grub_video_gop_fill_mode_info (mode, info, &mode_info);
if (err)
{
grub_errno = GRUB_ERR_NONE;
continue;
}
if (hook (&mode_info))
return 1;
}
return 0;
}
static grub_err_t
grub_video_gop_setup (unsigned int width, unsigned int height,
unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused)))
unsigned int mode_type,
unsigned int mode_mask __attribute__ ((unused)))
{
unsigned int depth;
struct grub_efi_gop_mode_info *info = NULL;
@ -226,7 +262,7 @@ grub_video_gop_setup (unsigned int width, unsigned int height,
if (status)
{
info = 0;
break;
continue;
}
grub_dprintf ("video", "GOP: mode %d: %dx%d\n", mode, info->width,
@ -281,7 +317,8 @@ grub_video_gop_setup (unsigned int width, unsigned int height,
info = gop->mode->info;
err = grub_video_gop_fill_mode_info (info, &framebuffer.mode_info);
err = grub_video_gop_fill_mode_info (gop->mode->mode, info,
&framebuffer.mode_info);
if (err)
{
grub_dprintf ("video", "GOP: couldn't fill mode info\n");
@ -379,6 +416,7 @@ static struct grub_video_adapter grub_video_gop_adapter =
.delete_render_target = grub_video_fb_delete_render_target,
.set_active_render_target = grub_video_gop_set_active_render_target,
.get_active_render_target = grub_video_fb_get_active_render_target,
.iterate = grub_video_gop_iterate,
.next = 0
};

View file

@ -198,7 +198,8 @@ grub_video_uga_fini (void)
static grub_err_t
grub_video_uga_setup (unsigned int width, unsigned int height,
unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused)))
unsigned int mode_type,
unsigned int mode_mask __attribute__ ((unused)))
{
unsigned int depth;
int found = 0;

View file

@ -33,7 +33,6 @@
static int vbe_detected = -1;
static struct grub_vbe_info_block controller_info;
static struct grub_vbe_mode_info_block active_vbe_mode_info;
/* Track last mode to support cards which fail on get_mode. */
static grub_uint32_t last_set_mode = 3;
@ -42,11 +41,7 @@ static struct
{
struct grub_video_mode_info mode_info;
unsigned int bytes_per_scan_line;
unsigned int bytes_per_pixel;
grub_uint32_t active_vbe_mode;
grub_uint8_t *ptr;
int index_color_mode;
} framebuffer;
static grub_uint32_t initial_vbe_mode;
@ -332,21 +327,12 @@ grub_vbe_set_video_mode (grub_uint32_t vbe_mode,
vbe_mode |= 1 << 14;
/* Determine frame buffer pixel format. */
switch (new_vbe_mode_info.memory_model)
{
case GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL:
framebuffer.index_color_mode = 1;
break;
case GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR:
framebuffer.index_color_mode = 0;
break;
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"unsupported pixel format 0x%x",
new_vbe_mode_info.memory_model);
}
if (new_vbe_mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL
&& new_vbe_mode_info.memory_model
!= GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"unsupported pixel format 0x%x",
new_vbe_mode_info.memory_model);
}
/* Get current mode. */
@ -360,24 +346,14 @@ grub_vbe_set_video_mode (grub_uint32_t vbe_mode,
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot set VBE mode %x", vbe_mode);
last_set_mode = vbe_mode;
/* Save information for later usage. */
framebuffer.active_vbe_mode = vbe_mode;
grub_memcpy (&active_vbe_mode_info, &new_vbe_mode_info, sizeof (active_vbe_mode_info));
if (vbe_mode < 0x100)
{
/* If this is not a VESA mode, guess address. */
framebuffer.ptr = (grub_uint8_t *) GRUB_MEMORY_MACHINE_VGA_ADDR;
framebuffer.index_color_mode = 1;
}
else
{
framebuffer.ptr = (grub_uint8_t *) new_vbe_mode_info.phys_base_addr;
if (controller_info.version >= 0x300)
framebuffer.bytes_per_scan_line = new_vbe_mode_info.lin_bytes_per_scan_line;
else
framebuffer.bytes_per_scan_line = new_vbe_mode_info.bytes_per_scan_line;
}
/* Check whether mode is text mode or graphics mode. */
@ -392,25 +368,9 @@ grub_vbe_set_video_mode (grub_uint32_t vbe_mode,
{
/* Graphics mode. */
/* Calculate bytes_per_pixel value. */
switch(new_vbe_mode_info.bits_per_pixel)
{
case 32: framebuffer.bytes_per_pixel = 4; break;
case 24: framebuffer.bytes_per_pixel = 3; break;
case 16: framebuffer.bytes_per_pixel = 2; break;
case 15: framebuffer.bytes_per_pixel = 2; break;
case 8: framebuffer.bytes_per_pixel = 1; break;
default:
grub_vbe_bios_set_mode (old_vbe_mode, 0);
last_set_mode = old_vbe_mode;
return grub_error (GRUB_ERR_BAD_DEVICE,
"cannot set VBE mode %x",
vbe_mode);
break;
}
/* If video mode is in indexed color, setup default VGA palette. */
if (framebuffer.index_color_mode)
if (vbe_mode < 0x100 || new_vbe_mode_info.memory_model
== GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL)
{
struct grub_vbe_palette_data *palette
= (struct grub_vbe_palette_data *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
@ -548,10 +508,13 @@ grub_video_vbe_fini (void)
grub_err_t err;
/* Restore old video mode. */
status = grub_vbe_bios_set_mode (initial_vbe_mode, 0);
if (status != GRUB_VBE_STATUS_OK)
/* TODO: Decide, is this something we want to do. */
return grub_errno;
if (last_set_mode != initial_vbe_mode)
{
status = grub_vbe_bios_set_mode (initial_vbe_mode, 0);
if (status != GRUB_VBE_STATUS_OK)
/* TODO: Decide, is this something we want to do. */
return grub_errno;
}
last_set_mode = initial_vbe_mode;
/* TODO: Free any resources allocated by driver. */
@ -583,6 +546,120 @@ doublebuf_pageflipping_set_page (int page)
return 0;
}
static void
vbe2videoinfo (grub_uint32_t mode,
const struct grub_vbe_mode_info_block *vbeinfo,
struct grub_video_mode_info *mode_info)
{
mode_info->mode_number = mode;
mode_info->width = vbeinfo->x_resolution;
mode_info->height = vbeinfo->y_resolution;
mode_info->mode_type = 0;
switch (vbeinfo->memory_model)
{
case GRUB_VBE_MEMORY_MODEL_TEXT:
mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_PURE_TEXT;
break;
/* CGA is basically 4-bit packed pixel. */
case GRUB_VBE_MEMORY_MODEL_CGA:
mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_CGA;
case GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL:
mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_INDEX_COLOR;
break;
case GRUB_VBE_MEMORY_MODEL_HERCULES:
mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_HERCULES
| GRUB_VIDEO_MODE_TYPE_1BIT_BITMAP;
break;
/* Non chain 4 is a special case of planar. */
case GRUB_VBE_MEMORY_MODEL_NONCHAIN4_256:
mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_NONCHAIN4;
case GRUB_VBE_MEMORY_MODEL_PLANAR:
mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_PLANAR
| GRUB_VIDEO_MODE_TYPE_INDEX_COLOR;
break;
case GRUB_VBE_MEMORY_MODEL_YUV:
mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_YUV;
break;
case GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR:
mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_RGB;
break;
default:
mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_UNKNOWN;
break;
}
mode_info->bpp = vbeinfo->bits_per_pixel;
/* Calculate bytes_per_pixel value. */
switch(vbeinfo->bits_per_pixel)
{
case 32:
mode_info->bytes_per_pixel = 4;
break;
case 24:
mode_info->bytes_per_pixel = 3;
break;
case 16:
mode_info->bytes_per_pixel = 2;
break;
case 15:
mode_info->bytes_per_pixel = 2;
break;
case 8:
mode_info->bytes_per_pixel = 1;
break;
case 4:
mode_info->bytes_per_pixel = 0;
break;
}
if (controller_info.version >= 0x300)
mode_info->pitch = vbeinfo->lin_bytes_per_scan_line;
else
mode_info->pitch = vbeinfo->bytes_per_scan_line;
mode_info->number_of_colors = 256; /* TODO: fix me. */
mode_info->red_mask_size = vbeinfo->red_mask_size;
mode_info->red_field_pos = vbeinfo->red_field_position;
mode_info->green_mask_size = vbeinfo->green_mask_size;
mode_info->green_field_pos = vbeinfo->green_field_position;
mode_info->blue_mask_size = vbeinfo->blue_mask_size;
mode_info->blue_field_pos = vbeinfo->blue_field_position;
mode_info->reserved_mask_size = vbeinfo->rsvd_mask_size;
mode_info->reserved_field_pos = vbeinfo->rsvd_field_position;
mode_info->blit_format = grub_video_get_blit_format (mode_info);
}
static int
grub_video_vbe_iterate (int (*hook) (const struct grub_video_mode_info *info))
{
grub_uint16_t *p;
struct grub_vbe_mode_info_block vbe_mode_info;
struct grub_video_mode_info mode_info;
for (p = vbe_mode_list; *p != 0xFFFF; p++)
{
grub_vbe_get_video_mode_info (*p, &vbe_mode_info);
if (grub_errno != GRUB_ERR_NONE)
{
/* Could not retrieve mode info, retreat. */
grub_errno = GRUB_ERR_NONE;
break;
}
vbe2videoinfo (*p, &vbe_mode_info, &mode_info);
if (hook (&mode_info))
return 1;
}
return 0;
}
static grub_err_t
grub_video_vbe_setup (unsigned int width, unsigned int height,
unsigned int mode_type, unsigned int mode_mask)
@ -631,6 +708,14 @@ grub_video_vbe_setup (unsigned int width, unsigned int height,
/* Not compatible memory model. */
continue;
if (vbe_mode_info.bits_per_pixel != 8
&& vbe_mode_info.bits_per_pixel != 15
&& vbe_mode_info.bits_per_pixel != 16
&& vbe_mode_info.bits_per_pixel != 24
&& vbe_mode_info.bits_per_pixel != 32)
/* Unsupported bitdepth . */
continue;
if (((vbe_mode_info.x_resolution != width)
|| (vbe_mode_info.y_resolution != height)) && width != 0 && height != 0)
/* Non matching resolution. */
@ -676,36 +761,16 @@ grub_video_vbe_setup (unsigned int width, unsigned int height,
if (best_vbe_mode != 0)
{
grub_err_t err;
static struct grub_vbe_mode_info_block active_vbe_mode_info;
/* If this fails, then we have mode selection heuristics problem,
or adapter failure. */
/* grub_vbe_set_video_mode already sets active_vbe_mode_info. */
grub_vbe_set_video_mode (best_vbe_mode, NULL);
grub_vbe_set_video_mode (best_vbe_mode, &active_vbe_mode_info);
if (grub_errno != GRUB_ERR_NONE)
return grub_errno;
/* Fill mode info details. */
framebuffer.mode_info.width = active_vbe_mode_info.x_resolution;
framebuffer.mode_info.height = active_vbe_mode_info.y_resolution;
if (framebuffer.index_color_mode)
framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR;
else
framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_RGB;
framebuffer.mode_info.bpp = active_vbe_mode_info.bits_per_pixel;
framebuffer.mode_info.bytes_per_pixel = framebuffer.bytes_per_pixel;
framebuffer.mode_info.pitch = framebuffer.bytes_per_scan_line;
framebuffer.mode_info.number_of_colors = 256; /* TODO: fix me. */
framebuffer.mode_info.red_mask_size = active_vbe_mode_info.red_mask_size;
framebuffer.mode_info.red_field_pos = active_vbe_mode_info.red_field_position;
framebuffer.mode_info.green_mask_size = active_vbe_mode_info.green_mask_size;
framebuffer.mode_info.green_field_pos = active_vbe_mode_info.green_field_position;
framebuffer.mode_info.blue_mask_size = active_vbe_mode_info.blue_mask_size;
framebuffer.mode_info.blue_field_pos = active_vbe_mode_info.blue_field_position;
framebuffer.mode_info.reserved_mask_size = active_vbe_mode_info.rsvd_mask_size;
framebuffer.mode_info.reserved_field_pos = active_vbe_mode_info.rsvd_field_position;
framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info);
vbe2videoinfo (best_vbe_mode, &active_vbe_mode_info,
&framebuffer.mode_info);
{
/* Get video RAM size in bytes. */
@ -740,7 +805,7 @@ static grub_err_t
grub_video_vbe_set_palette (unsigned int start, unsigned int count,
struct grub_video_palette_data *palette_data)
{
if (framebuffer.index_color_mode)
if (framebuffer.mode_info.mode_type == GRUB_VIDEO_MODE_TYPE_INDEX_COLOR)
{
/* TODO: Implement setting indexed color mode palette to hardware. */
//status = grub_vbe_bios_set_palette_data (sizeof (vga_colors)
@ -764,6 +829,20 @@ grub_video_vbe_get_info_and_fini (struct grub_video_mode_info *mode_info,
return grub_video_fb_get_info_and_fini (mode_info, framebuf);
}
static void
grub_video_vbe_print_adapter_specific_info (void)
{
grub_printf (" VBE info: version: %d.%d OEM software rev: %d.%d\n",
controller_info.version >> 8,
controller_info.version & 0xFF,
controller_info.oem_software_rev >> 8,
controller_info.oem_software_rev & 0xFF);
/* The total_memory field is in 64 KiB units. */
grub_printf (" total memory: %d KiB\n",
(controller_info.total_memory << 16) / 1024);
}
static struct grub_video_adapter grub_video_vbe_adapter =
{
.name = "VESA BIOS Extension Video Driver",
@ -793,6 +872,8 @@ static struct grub_video_adapter grub_video_vbe_adapter =
.delete_render_target = grub_video_fb_delete_render_target,
.set_active_render_target = grub_video_fb_set_active_render_target,
.get_active_render_target = grub_video_fb_get_active_render_target,
.iterate = grub_video_vbe_iterate,
.print_adapter_specific_info = grub_video_vbe_print_adapter_specific_info,
.next = 0
};

Some files were not shown because too many files have changed in this diff Show more