Skip to contentSkip to conversation

Enable grub_cpu_idle for i386 to halt the CPU

PATCH In review David Fries 3 participants 8 messages Aug 12, 2008 – Aug 17, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Enable grub_cpu_idle for i386 to halt the CPU

Enable grub_cpu_idle for i386 to halt the CPU and modify the menu code to make use of it. This will save power when booting.
Or maybe I should say it will keep the CPU from running so hot when the timer is counting down.

It isn't safe to call halt in protected mode as interrupts are disabled. I assume it is becaus the interrupts handlers aren't setup to work in protected mode. But interrupts are enabled in real mode, and the timer is running, so the only two things of interest in the menu countdown is time has elapsed or a key is pressed, which both produce interrupts and are checked. I assume any other call to grub_cpu_idle will have an interrupt or the timer to wake it up.

As grub_cpu_idle is exported instead of inline, some of the utility programs failed to compile because the symbol wasn't defined. I created util/user-stub.c for common stub functions instead of adding it to multiple utility program source files.

Signature · 316 lines
David Fries <[email protected]>
http://fries.net/~david/ (PGP encryption key available)


Index: conf/common.rmk
===================================================================
--- conf/common.rmk	(revision 1798)
+++ conf/common.rmk	(working copy)
@@ -5,6 +5,7 @@
 util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
 grub_probe_SOURCES = util/grub-probe.c	\
 	util/biosdisk.c	util/misc.c util/getroot.c		\
+	util/user-stub.c					\
 	kern/device.c kern/disk.c kern/err.c kern/misc.c	\
 	kern/parser.c kern/partition.c kern/file.c		\
 	\
@@ -96,7 +97,9 @@
 
 # for grub-editenv
 bin_UTILITIES += grub-editenv
-grub_editenv_SOURCES = util/grub-editenv.c lib/envblk.c util/misc.c kern/misc.c kern/err.c
+grub_editenv_SOURCES = util/grub-editenv.c lib/envblk.c util/misc.c \
+	util/user-stub.c \
+	kern/misc.c kern/err.c
 CLEANFILES += grub-editenv
 
 # for grub-pe2elf
Index: conf/i386-pc.rmk
===================================================================
--- conf/i386-pc.rmk	(revision 1798)
+++ conf/i386-pc.rmk	(working copy)
@@ -91,7 +91,8 @@
 # For grub-setup.
 util/i386/pc/grub-setup.c_DEPENDENCIES = grub_setup_init.h
 grub_setup_SOURCES = util/i386/pc/grub-setup.c util/biosdisk.c	\
-	util/misc.c util/getroot.c kern/device.c kern/disk.c	\
+	util/misc.c util/getroot.c util/user-stub.c 		\
+	kern/device.c kern/disk.c				\
 	kern/err.c kern/misc.c kern/parser.c kern/partition.c	\
 	kern/file.c kern/fs.c kern/env.c fs/fshelp.c		\
 	\
Index: conf/common.mk
===================================================================
--- conf/common.mk	(revision 1798)
+++ conf/common.mk	(working copy)
@@ -6,6 +6,7 @@
 util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
 grub_probe_SOURCES = util/grub-probe.c	\
 	util/biosdisk.c	util/misc.c util/getroot.c		\
+	util/user-stub.c					\
 	kern/device.c kern/disk.c kern/err.c kern/misc.c	\
 	kern/parser.c kern/partition.c kern/file.c		\
 	\
@@ -17,11 +18,11 @@
 	partmap/pc.c partmap/apple.c partmap/gpt.c 		\
 	kern/fs.c kern/env.c fs/fshelp.c			\
 	disk/lvm.c disk/raid.c grub_probe_init.c
-CLEANFILES += grub-probe$(EXEEXT) grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o
-MOSTLYCLEANFILES += grub_probe-util_grub_probe.d grub_probe-util_biosdisk.d grub_probe-util_misc.d grub_probe-util_getroot.d grub_probe-kern_device.d grub_probe-kern_disk.d grub_probe-kern_err.d grub_probe-kern_misc.d grub_probe-kern_parser.d grub_probe-kern_partition.d grub_probe-kern_file.d grub_probe-fs_affs.d grub_probe-fs_cpio.d grub_probe-fs_ext2.d grub_probe-fs_fat.d grub_probe-fs_hfs.d grub_probe-fs_hfsplus.d grub_probe-fs_iso9660.d grub_probe-fs_udf.d grub_probe-fs_jfs.d grub_probe-fs_minix.d grub_probe-fs_ntfs.d grub_probe-fs_ntfscomp.d grub_probe-fs_reiserfs.d grub_probe-fs_sfs.d grub_probe-fs_ufs.d grub_probe-fs_xfs.d grub_probe-fs_afs.d grub_probe-partmap_pc.d grub_probe-partmap_apple.d grub_probe-partmap_gpt.d grub_probe-kern_fs.d grub_probe-kern_env.d grub_probe-fs_fshelp.d grub_probe-disk_lvm.d grub_probe-disk_raid.d grub_probe-grub_probe_init.d
+CLEANFILES += grub-probe$(EXEEXT) grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-util_user_stub.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o
+MOSTLYCLEANFILES += grub_probe-util_grub_probe.d grub_probe-util_biosdisk.d grub_probe-util_misc.d grub_probe-util_getroot.d grub_probe-util_user_stub.d grub_probe-kern_device.d grub_probe-kern_disk.d grub_probe-kern_err.d grub_probe-kern_misc.d grub_probe-kern_parser.d grub_probe-kern_partition.d grub_probe-kern_file.d grub_probe-fs_affs.d grub_probe-fs_cpio.d grub_probe-fs_ext2.d grub_probe-fs_fat.d grub_probe-fs_hfs.d grub_probe-fs_hfsplus.d grub_probe-fs_iso9660.d grub_probe-fs_udf.d grub_probe-fs_jfs.d grub_probe-fs_minix.d grub_probe-fs_ntfs.d grub_probe-fs_ntfscomp.d grub_probe-fs_reiserfs.d grub_probe-fs_sfs.d grub_probe-fs_ufs.d grub_probe-fs_xfs.d grub_probe-fs_afs.d grub_probe-partmap_pc.d grub_probe-partmap_apple.d grub_probe-partmap_gpt.d grub_probe-kern_fs.d grub_probe-kern_env.d grub_probe-fs_fshelp.d grub_probe-disk_lvm.d grub_probe-disk_raid.d grub_probe-grub_probe_init.d
 
-grub-probe: $(grub_probe_DEPENDENCIES) grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o
-	$(CC) -o $@ grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o $(LDFLAGS) $(grub_probe_LDFLAGS)
+grub-probe: $(grub_probe_DEPENDENCIES) grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-util_user_stub.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o
+	$(CC) -o $@ grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-util_user_stub.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o $(LDFLAGS) $(grub_probe_LDFLAGS)
 
 grub_probe-util_grub_probe.o: util/grub-probe.c $(util/grub-probe.c_DEPENDENCIES)
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_probe_CFLAGS) -MD -c -o $@ $<
@@ -39,6 +40,10 @@
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_probe_CFLAGS) -MD -c -o $@ $<
 -include grub_probe-util_getroot.d
 
+grub_probe-util_user_stub.o: util/user-stub.c $(util/user-stub.c_DEPENDENCIES)
+	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_probe_CFLAGS) -MD -c -o $@ $<
+-include grub_probe-util_user_stub.d
+
 grub_probe-kern_device.o: kern/device.c $(kern/device.c_DEPENDENCIES)
 	$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_probe_CFLAGS) -MD -c -o $@ $<
 -include grub_probe-kern_device.d
@@ -429,12 +434,14 @@
 
 # for grub-editenv
 bin_UTILITIES += grub-editenv
-grub_editenv_SOURCES = util/grub-editenv.c lib/envblk.c util/misc.c kern/misc.c kern/err.c
-CLEANFILES += grub-editenv$(EXEEXT) grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-kern_misc.o grub_editenv-kern_err.o
-MOSTLYCLEANFILES += grub_editenv-util_grub_editenv.d grub_editenv-lib_envblk.d grub_editenv-util_misc.d grub_editenv-kern_misc.d grub_editenv-kern_err.d
+grub_editenv_SOURCES = util/grub-editenv.c lib/envblk.c util/misc.c \
+	util/user-stub.c \
+	kern/misc.c kern/err.c
+CLEANFILES += grub-editenv$(EXEEXT) grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-util_user_stub.o grub_editenv-kern_misc.o grub_editenv-kern_err.o
+MOSTLYCLEANFILES += grub_editenv-util_grub_editenv.d grub_editenv-lib_envblk.d grub_editenv-util_misc.d grub_editenv-util_user_stub.d grub_editenv-kern_misc.d grub_editenv-kern_err.d
 
-grub-editenv: $(grub_editenv_DEPENDENCIES) grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-kern_misc.o grub_editenv-kern_err.o
-	$(CC) -o $@ grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-kern_misc.o grub_editenv-kern_err.o $(LDFLAGS) $(grub_editenv_LDFLAGS)
+grub-editenv: $(grub_editenv_DEPENDENCIES) grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-util_user_stub.o grub_editenv-kern_misc.o grub_editenv-kern_err.o
+	$(CC) -o $@ grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-util_user_stub.o grub_editenv-kern_misc.o grub_editenv-kern_err.o $(LDFLAGS) $(grub_editenv_LDFLAGS)
 
 grub_editenv-util_grub_editenv.o: util/grub-editenv.c $(util/grub-editenv.c_DEPENDENCIES)
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_editenv_CFLAGS) -MD -c -o $@ $<
@@ -448,6 +455,10 @@
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_editenv_CFLAGS) -MD -c -o $@ $<
 -include grub_editenv-util_misc.d
 
+grub_editenv-util_user_stub.o: util/user-stub.c $(util/user-stub.c_DEPENDENCIES)
+	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_editenv_CFLAGS) -MD -c -o $@ $<
+-include grub_editenv-util_user_stub.d
+
 grub_editenv-kern_misc.o: kern/misc.c $(kern/misc.c_DEPENDENCIES)
 	$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_editenv_CFLAGS) -MD -c -o $@ $<
 -include grub_editenv-kern_misc.d
Index: conf/i386-pc.mk
===================================================================
--- conf/i386-pc.mk	(revision 1798)
+++ conf/i386-pc.mk	(working copy)
@@ -310,7 +310,8 @@
 # For grub-setup.
 util/i386/pc/grub-setup.c_DEPENDENCIES = grub_setup_init.h
 grub_setup_SOURCES = util/i386/pc/grub-setup.c util/biosdisk.c	\
-	util/misc.c util/getroot.c kern/device.c kern/disk.c	\
+	util/misc.c util/getroot.c util/user-stub.c 		\
+	kern/device.c kern/disk.c				\
 	kern/err.c kern/misc.c kern/parser.c kern/partition.c	\
 	kern/file.c kern/fs.c kern/env.c fs/fshelp.c		\
 	\
@@ -324,11 +325,11 @@
 	disk/raid.c disk/lvm.c					\
 	util/raid.c util/lvm.c					\
 	grub_setup_init.c
-CLEANFILES += grub-setup$(EXEEXT) grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o
-MOSTLYCLEANFILES += grub_setup-util_i386_pc_grub_setup.d grub_setup-util_biosdisk.d grub_setup-util_misc.d grub_setup-util_getroot.d grub_setup-kern_device.d grub_setup-kern_disk.d grub_setup-kern_err.d grub_setup-kern_misc.d grub_setup-kern_parser.d grub_setup-kern_partition.d grub_setup-kern_file.d grub_setup-kern_fs.d grub_setup-kern_env.d grub_setup-fs_fshelp.d grub_setup-fs_affs.d grub_setup-fs_cpio.d grub_setup-fs_ext2.d grub_setup-fs_fat.d grub_setup-fs_hfs.d grub_setup-fs_hfsplus.d grub_setup-fs_iso9660.d grub_setup-fs_udf.d grub_setup-fs_jfs.d grub_setup-fs_minix.d grub_setup-fs_ntfs.d grub_setup-fs_ntfscomp.d grub_setup-fs_reiserfs.d grub_setup-fs_sfs.d grub_setup-fs_ufs.d grub_setup-fs_xfs.d grub_setup-fs_afs.d grub_setup-partmap_pc.d grub_setup-partmap_gpt.d grub_setup-disk_raid.d grub_setup-disk_lvm.d grub_setup-util_raid.d grub_setup-util_lvm.d grub_setup-grub_setup_init.d
+CLEANFILES += grub-setup$(EXEEXT) grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-util_user_stub.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o
+MOSTLYCLEANFILES += grub_setup-util_i386_pc_grub_setup.d grub_setup-util_biosdisk.d grub_setup-util_misc.d grub_setup-util_getroot.d grub_setup-util_user_stub.d grub_setup-kern_device.d grub_setup-kern_disk.d grub_setup-kern_err.d grub_setup-kern_misc.d grub_setup-kern_parser.d grub_setup-kern_partition.d grub_setup-kern_file.d grub_setup-kern_fs.d grub_setup-kern_env.d grub_setup-fs_fshelp.d grub_setup-fs_affs.d grub_setup-fs_cpio.d grub_setup-fs_ext2.d grub_setup-fs_fat.d grub_setup-fs_hfs.d grub_setup-fs_hfsplus.d grub_setup-fs_iso9660.d grub_setup-fs_udf.d grub_setup-fs_jfs.d grub_setup-fs_minix.d grub_setup-fs_ntfs.d grub_setup-fs_ntfscomp.d grub_setup-fs_reiserfs.d grub_setup-fs_sfs.d grub_setup-fs_ufs.d grub_setup-fs_xfs.d grub_setup-fs_afs.d grub_setup-partmap_pc.d grub_setup-partmap_gpt.d grub_setup-disk_raid.d grub_setup-disk_lvm.d grub_setup-util_raid.d grub_setup-util_lvm.d grub_setup-grub_setup_init.d
 
-grub-setup: $(grub_setup_DEPENDENCIES) grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o
-	$(CC) -o $@ grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o $(LDFLAGS) $(grub_setup_LDFLAGS)
+grub-setup: $(grub_setup_DEPENDENCIES) grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-util_user_stub.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o
+	$(CC) -o $@ grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-util_user_stub.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o $(LDFLAGS) $(grub_setup_LDFLAGS)
 
 grub_setup-util_i386_pc_grub_setup.o: util/i386/pc/grub-setup.c $(util/i386/pc/grub-setup.c_DEPENDENCIES)
 	$(CC) -Iutil/i386/pc -I$(srcdir)/util/i386/pc $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_setup_CFLAGS) -MD -c -o $@ $<
@@ -346,6 +347,10 @@
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_setup_CFLAGS) -MD -c -o $@ $<
 -include grub_setup-util_getroot.d
 
+grub_setup-util_user_stub.o: util/user-stub.c $(util/user-stub.c_DEPENDENCIES)
+	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_setup_CFLAGS) -MD -c -o $@ $<
+-include grub_setup-util_user_stub.d
+
 grub_setup-kern_device.o: kern/device.c $(kern/device.c_DEPENDENCIES)
 	$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_setup_CFLAGS) -MD -c -o $@ $<
 -include grub_setup-kern_device.d
Index: kern/i386/pc/startup.S
===================================================================
--- kern/i386/pc/startup.S	(revision 1798)
+++ kern/i386/pc/startup.S	(working copy)
@@ -1502,8 +1502,28 @@
 	popl	%ebx
 	popl	%ebp
 	ret
-		
+
+
 /*
+ * void grub_cpu_idle (void)
+ * Change to real mode to enable interrupts and hlt until the next interrupt.
+ */
+FUNCTION(grub_cpu_idle)
+	pushl	%ebp
+
+	call	prot_to_real	/* enter real mode */
+	.code16
+
+	hlt
+
+	DATA32	call	real_to_prot
+	.code32
+
+	popl	%ebp
+	ret
+
+
+/*
  * grub_getrtsecs()
  *	if a seconds value can be read, read it and return it (BCD),
  *      otherwise return 0xFF
Index: NEWS
===================================================================
--- NEWS	(revision 1798)
+++ NEWS	(working copy)
@@ -1,5 +1,8 @@
 New in 1.97 - :
 
+* Enable grub_cpu_idle for i386 to halt the CPU and modify the menu code
+  to make use of it.  This will save power when booting.
+
 * When booting from PXE, PXE can be used to load files.
 
 * High resolution timer support.
Index: include/grub/i386/time.h
===================================================================
--- include/grub/i386/time.h	(revision 1798)
+++ include/grub/i386/time.h	(working copy)
@@ -19,11 +19,9 @@
 #ifndef KERNEL_CPU_TIME_HEADER
 #define KERNEL_CPU_TIME_HEADER	1
 
-static __inline void
-grub_cpu_idle (void)
-{
-  /* FIXME: this can't work until we handle interrupts.  */
-/*  __asm__ __volatile__ ("hlt"); */
-}
+/* Call into assembly to change to real mode and enable interrupts so it
+   can halt until the next interrupt is received. */
+void
+EXPORT_FUNC(grub_cpu_idle) (void);
 
 #endif /* ! KERNEL_CPU_TIME_HEADER */
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 1798)
+++ ChangeLog	(working copy)
@@ -1,3 +1,18 @@
+2008-08-10  David Fries <[email protected]>
+
+	Enable hlt in grub_cpu_idle so it can be idle when called.
+	* kern/i386/pc/startup.S: grub_cpu_idle, halt with interrupts
+	* include/grub/i386/time.h: export function grub_cpu_idle.
+	* normal/menu.c: Sleep in halt (if supported), until a second elapsed
+	or a key is pressed.
+	* util/user-stub.c: New file.  The utilities link against part of the
+	kernel.  This new file is intended to be a dumping place for functions
+	that are requierd by parts of the kernel included, but not found in
+	those places.
+	* conf/common.rmk: Make use of user-stub.c in grub_probe and
+	grub-editenv.
+	* conf/i386-pc.rmk: Make use of user-stub.c in grub-setup.
+
 2008-08-09  Christian Franke  <[email protected]>
 
 	* Makefile.in: Add `target_os' and `enable_grub_pe2elf'.
Index: normal/menu.c
===================================================================
--- normal/menu.c	(revision 1798)
+++ normal/menu.c	(working copy)
@@ -24,6 +24,7 @@
 #include <grub/time.h>
 #include <grub/env.h>
 #include <grub/script.h>
+#include <grub/cpu/time.h>
 
 static grub_uint8_t grub_color_menu_normal;
 static grub_uint8_t grub_color_menu_highlight;
@@ -381,6 +382,12 @@
 	      saved_time = current_time;
 	      print_timeout (timeout, offset, 1);
 	    }
+          /* Sleep until a second has passed or a key is pressed. */
+          do
+            {
+              grub_cpu_idle ();
+            }while (grub_get_rtc () - saved_time < GRUB_TICKS_PER_SECOND &&
+              grub_checkkey () == -1);
 	}
 
       if (timeout == 0)
Index: DISTLIST
===================================================================
--- DISTLIST	(revision 1798)
+++ DISTLIST	(working copy)
@@ -358,6 +358,7 @@
 util/raid.c
 util/resolve.c
 util/unifont2pff.rb
+util/user-stub.c
 util/update-grub.in
 util/update-grub_lib.in
 video/bitmap.c
Index: util/user-stub.c
===================================================================
--- util/user-stub.c	(revision 0)
+++ util/user-stub.c	(revision 0)
@@ -0,0 +1,32 @@
+/*
+ *  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/>.
+ */
+
+/* Provide user space stubs for the utility programs to compile against.
+   They are not included in the pieces of the kernel linked in to the
+   utility programs, but are unresolved symbols for the parts that are. */
+
+#include <config.h>
+#include <stdio.h>
+#include <time.h>
+
+void
+grub_cpu_idle ()
+{
+  struct timespec req={0,1};
+  nanosleep (&req, NULL);
+}
#1 lore raw
Quoted 13 lines · David Fries

Enable grub_cpu_idle for i386 to halt the CPU and modify the menu code to make use of it. This will save power when booting.
Or maybe I should say it will keep the CPU from running so hot when the timer is counting down.

It isn't safe to call halt in protected mode as interrupts are disabled. I assume it is becaus the interrupts handlers aren't setup to work in protected mode. But interrupts are enabled in real mode, and the timer is running, so the only two things of interest in the menu countdown is time has elapsed or a key is pressed, which both produce interrupts and are checked. I assume any other call to grub_cpu_idle will have an interrupt or the timer to wake it up.

Quoted 4 lines

As grub_cpu_idle is exported instead of inline, some of the utility programs failed to compile because the symbol wasn't defined. I created util/user-stub.c for common stub functions instead of adding it to multiple utility program source files.

Hi David,

I'm sorry that you already went on to provide a patch, but the problem is not that.

The problem is that on some platforms (like coreboot), the firmware won't setup any IDT for us, and so we need to do this ourselves before we use hlt.

So the solution is to initialize the IDT (so that we won't get a cpu fault), and enable IRQ0 (so that hlt won't stall).

Would you be willing to provide a patch that does that?

Review

Quoted 6 lines
(quoted diff) +6 -0
+void
+grub_cpu_idle ()
+{
+  struct timespec req={0,1};
+  nanosleep (&req, NULL);
+}

grub_cpu_idle is intended to be a (cpu-independant) primitive, not a stub for nanosleep.

We already have code for sleeping, but it doesn't put the CPU to rest, these are two different things.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#2 lore raw
Quoted 9 lines · Robert Millan

Review

Quoted 6 lines
(quoted diff) +6 -0
+void
+grub_cpu_idle ()
+{
+  struct timespec req={0,1};
+  nanosleep (&req, NULL);
+}

grub_cpu_idle is intended to be a (cpu-independant) primitive, not a stub for nanosleep.

Ah, sorry. I notice you're writing user code here.

This would be best kept as an inline in the same file that defines grub_cpu_idle for real GRUB, something like:

#ifdef GRUB_UTIL
use nanosleep
#else
use hlt
#endif

In include/grub/i386/time.h.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#3 lore raw
In reply to Robert Millan
Quoted 6 lines · Robert Millan

Hi David,

I'm sorry that you already went on to provide a patch, but the problem is not that.

Quoted 7 lines

The problem is that on some platforms (like coreboot), the firmware won't setup any IDT for us, and so we need to do this ourselves before we use hlt.

So the solution is to initialize the IDT (so that we won't get a cpu fault), and enable IRQ0 (so that hlt won't stall).

Would you be willing to provide a patch that does that?

Actually I have a computer in my car that I would really like to speed up booting on. It would be a great application for coreboot, except it's a 486 and I don't see coreboot supporting it. Until I have an application for it, I'll have to let someone else implement support for grub_cpu_idle.

I have the second version of the patch out, and this time I did compile coreboot. It won't be improved or harmed, the patch just helps the i386/pc platform.

Signature · 2 lines
David Fries <[email protected]>
http://fries.net/~david/ (PGP encryption key available)
#4 lore raw
Quoted 3 lines · David Fries

[...]. Until I have an
application for it, I'll have to let someone else implement support for grub_cpu_idle.

We have 4 ports on i386. A proper implementation of grub_cpu_idle should work fine on all of them. When I say "proper" I mean that 'hlt' instruction should be usable without doing strange gimmicks.

Your patch simply works around the fact that 'hlt' is broken on 32-bit by going back to i8086 mode in order to use it.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#5 lore raw
Quoted 8 lines · Robert Millan
Quoted 3 lines · David Fries

[...]. Until I have an
application for it, I'll have to let someone else implement support for grub_cpu_idle.

We have 4 ports on i386. A proper implementation of grub_cpu_idle should work fine on all of them. When I say "proper" I mean that 'hlt' instruction should be usable without doing strange gimmicks.

<sarcasm>
Gasp, grub_biosdisk_rw calls grub_biosdisk_rw_int13_extensions which for i386/pc call prot_to_real and back. There's like 40 other calls doing this strange gimmick of going to real mode for various things. </sarcasm>

Quoted 2 lines

Your patch simply works around the fact that 'hlt' is broken on 32-bit by going back to i8086 mode in order to use it.

Pavel Roskin didn't like an earlier patch of mine to add a whole 10 assembly instructions to the core.mod. This is the first time I've dealt with the uglieness of BIOS, but I don't see why anyone would trade a straight forward 6 instruction grub_cpu_idle to make use of the BIOS facilities, for reimplementing an interrupt stack and drivers to acknowledge those interrupts, when grub heavily depends on BIOS to be there and working.

I believe that's what one calls platform specific. i386/pc provides the support required for hlt to work, coreboot doesn't, it's coreboot that would need interrupts setup, a different platform, a different solution, and very much independent.

Maybe I should mention that hlt is already being used in real mode. Protected mode interrupts would cause that to break.

Signature · 2 lines
David Fries <[email protected]>
http://fries.net/~david/ (PGP encryption key available)
#6 lore raw
Quoted 8 lines · David Fries
Quoted 4 lines · Robert Millan

We have 4 ports on i386. A proper implementation of grub_cpu_idle should work fine on all of them. When I say "proper" I mean that 'hlt' instruction should be usable without doing strange gimmicks.

<sarcasm>
</sarcasm>

Please try to use proper tone if you want us to have a reasonable discussion.

Quoted 6 lines
Quoted 2 lines

Your patch simply works around the fact that 'hlt' is broken on 32-bit by going back to i8086 mode in order to use it.

Pavel Roskin didn't like an earlier patch of mine to add a whole 10 assembly instructions to the core.mod. This is the first time I've dealt with the uglieness of BIOS,

Your patch doesn't deal with the BIOS in any way. It simply takes advantage that interrupts are setup in i8086 mode to use hlt there.

It is a trivial workaround, and I'd have done that myself when implementing grub_cpu_idle if it wasn't because it's an ugly hack.

Quoted 2 lines

for reimplementing an interrupt stack and drivers
to acknowledge those interrupts,

Interrupt stack and drivers? The only thing you need for hlt to work is install a dummy stub in idt[0], disable all other IRQs and set the interrupt flag.

Quoted 2 lines

when grub heavily depends on BIOS to
be there and working.

GRUB is a multiplatform bootloader. When writing multiplatform code, it is IMHO very important to make the code as generic as reasonably possible.

Use of 'hlt' instruction depends on a particular setup of the CPU, and has nothing to do with firmware facilities.

Quoted 2 lines

Maybe I should mention that hlt is already being used in real mode. Protected mode interrupts would cause that to break.

Can you ellaborate on that?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#7 lore raw
In reply to David Fries
Quoted 13 lines · David Fries

Enable grub_cpu_idle for i386 to halt the CPU and modify the menu code to make use of it. This will save power when booting.
Or maybe I should say it will keep the CPU from running so hot when the timer is counting down.

It isn't safe to call halt in protected mode as interrupts are disabled. I assume it is becaus the interrupts handlers aren't setup to work in protected mode. But interrupts are enabled in real mode, and the timer is running, so the only two things of interest in the menu countdown is time has elapsed or a key is pressed, which both produce interrupts and are checked. I assume any other call to grub_cpu_idle will have an interrupt or the timer to wake it up.

Quoted 4 lines

As grub_cpu_idle is exported instead of inline, some of the utility programs failed to compile because the symbol wasn't defined. I created util/user-stub.c for common stub functions instead of adding it to multiple utility program source files.

Why didn't you use util/misc.c?

Quoted 42 lines
Signature · 6 lines
David Fries <[email protected]>
http://fries.net/~david/ (PGP encryption key available)


Index: conf/common.rmk
===================================================================
common.rmk +4 -1
@@ -5,6 +5,7 @@
 util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
 grub_probe_SOURCES = util/grub-probe.c	\
 	util/biosdisk.c	util/misc.c util/getroot.c		\
+	util/user-stub.c					\
 	kern/device.c kern/disk.c kern/err.c kern/misc.c	\
 	kern/parser.c kern/partition.c kern/file.c		\
 	\
@@ -96,7 +97,9 @@
 
 # for grub-editenv
 bin_UTILITIES += grub-editenv
-grub_editenv_SOURCES = util/grub-editenv.c lib/envblk.c util/misc.c kern/misc.c kern/err.c
+grub_editenv_SOURCES = util/grub-editenv.c lib/envblk.c util/misc.c \
+	util/user-stub.c \
+	kern/misc.c kern/err.c
 CLEANFILES += grub-editenv
 
 # for grub-pe2elf

Index: conf/i386-pc.rmk
===================================================================

i386-pc.rmk +2 -1
@@ -91,7 +91,8 @@
 # For grub-setup.
 util/i386/pc/grub-setup.c_DEPENDENCIES = grub_setup_init.h
 grub_setup_SOURCES = util/i386/pc/grub-setup.c util/biosdisk.c	\
-	util/misc.c util/getroot.c kern/device.c kern/disk.c	\
+	util/misc.c util/getroot.c util/user-stub.c 		\
+	kern/device.c kern/disk.c				\
 	kern/err.c kern/misc.c kern/parser.c kern/partition.c	\
 	kern/file.c kern/fs.c kern/env.c fs/fshelp.c		\
 	\
Quoted 1 line

Index: conf/common.mk

Please do not add .mk changes in a patch, it is a generated file :-)

Quoted 186 lines

===================================================================

common.mk +20 -9
@@ -6,6 +6,7 @@
 util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
 grub_probe_SOURCES = util/grub-probe.c	\
 	util/biosdisk.c	util/misc.c util/getroot.c		\
+	util/user-stub.c					\
 	kern/device.c kern/disk.c kern/err.c kern/misc.c	\
 	kern/parser.c kern/partition.c kern/file.c		\
 	\
@@ -17,11 +18,11 @@
 	partmap/pc.c partmap/apple.c partmap/gpt.c 		\
 	kern/fs.c kern/env.c fs/fshelp.c			\
 	disk/lvm.c disk/raid.c grub_probe_init.c
-CLEANFILES += grub-probe$(EXEEXT) grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o
-MOSTLYCLEANFILES += grub_probe-util_grub_probe.d grub_probe-util_biosdisk.d grub_probe-util_misc.d grub_probe-util_getroot.d grub_probe-kern_device.d grub_probe-kern_disk.d grub_probe-kern_err.d grub_probe-kern_misc.d grub_probe-kern_parser.d grub_probe-kern_partition.d grub_probe-kern_file.d grub_probe-fs_affs.d grub_probe-fs_cpio.d grub_probe-fs_ext2.d grub_probe-fs_fat.d grub_probe-fs_hfs.d grub_probe-fs_hfsplus.d grub_probe-fs_iso9660.d grub_probe-fs_udf.d grub_probe-fs_jfs.d grub_probe-fs_minix.d grub_probe-fs_ntfs.d grub_probe-fs_ntfscomp.d grub_probe-fs_reiserfs.d grub_probe-fs_sfs.d grub_probe-fs_ufs.d grub_probe-fs_xfs.d grub_probe-fs_afs.d grub_probe-partmap_pc.d grub_probe-partmap_apple.d grub_probe-partmap_gpt.d grub_probe-kern_fs.d grub_probe-kern_env.d grub_probe-fs_fshelp.d grub_probe-disk_lvm.d grub_probe-disk_raid.d grub_probe-grub_probe_init.d
+CLEANFILES += grub-probe$(EXEEXT) grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-util_user_stub.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o
+MOSTLYCLEANFILES += grub_probe-util_grub_probe.d grub_probe-util_biosdisk.d grub_probe-util_misc.d grub_probe-util_getroot.d grub_probe-util_user_stub.d grub_probe-kern_device.d grub_probe-kern_disk.d grub_probe-kern_err.d grub_probe-kern_misc.d grub_probe-kern_parser.d grub_probe-kern_partition.d grub_probe-kern_file.d grub_probe-fs_affs.d grub_probe-fs_cpio.d grub_probe-fs_ext2.d grub_probe-fs_fat.d grub_probe-fs_hfs.d grub_probe-fs_hfsplus.d grub_probe-fs_iso9660.d grub_probe-fs_udf.d grub_probe-fs_jfs.d grub_probe-fs_minix.d grub_probe-fs_ntfs.d grub_probe-fs_ntfscomp.d grub_probe-fs_reiserfs.d grub_probe-fs_sfs.d grub_probe-fs_ufs.d grub_probe-fs_xfs.d grub_probe-fs_afs.d grub_probe-partmap_pc.d grub_probe-partmap_apple.d grub_probe-partmap_gpt.d grub_probe-kern_fs.d grub_probe-kern_env.d grub_probe-fs_fshelp.d grub_probe-disk_lvm.d grub_probe-disk_raid.d grub_probe-grub_probe_init.d
 
-grub-probe: $(grub_probe_DEPENDENCIES) grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o
-	$(CC) -o $@ grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o $(LDFLAGS) $(grub_probe_LDFLAGS)
+grub-probe: $(grub_probe_DEPENDENCIES) grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-util_user_stub.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o
+	$(CC) -o $@ grub_probe-util_grub_probe.o grub_probe-util_biosdisk.o grub_probe-util_misc.o grub_probe-util_getroot.o grub_probe-util_user_stub.o grub_probe-kern_device.o grub_probe-kern_disk.o grub_probe-kern_err.o grub_probe-kern_misc.o grub_probe-kern_parser.o grub_probe-kern_partition.o grub_probe-kern_file.o grub_probe-fs_affs.o grub_probe-fs_cpio.o grub_probe-fs_ext2.o grub_probe-fs_fat.o grub_probe-fs_hfs.o grub_probe-fs_hfsplus.o grub_probe-fs_iso9660.o grub_probe-fs_udf.o grub_probe-fs_jfs.o grub_probe-fs_minix.o grub_probe-fs_ntfs.o grub_probe-fs_ntfscomp.o grub_probe-fs_reiserfs.o grub_probe-fs_sfs.o grub_probe-fs_ufs.o grub_probe-fs_xfs.o grub_probe-fs_afs.o grub_probe-partmap_pc.o grub_probe-partmap_apple.o grub_probe-partmap_gpt.o grub_probe-kern_fs.o grub_probe-kern_env.o grub_probe-fs_fshelp.o grub_probe-disk_lvm.o grub_probe-disk_raid.o grub_probe-grub_probe_init.o $(LDFLAGS) $(grub_probe_LDFLAGS)
 
 grub_probe-util_grub_probe.o: util/grub-probe.c $(util/grub-probe.c_DEPENDENCIES)
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_probe_CFLAGS) -MD -c -o $@ $<
@@ -39,6 +40,10 @@
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_probe_CFLAGS) -MD -c -o $@ $<
 -include grub_probe-util_getroot.d
 
+grub_probe-util_user_stub.o: util/user-stub.c $(util/user-stub.c_DEPENDENCIES)
+	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_probe_CFLAGS) -MD -c -o $@ $<
+-include grub_probe-util_user_stub.d
+
 grub_probe-kern_device.o: kern/device.c $(kern/device.c_DEPENDENCIES)
 	$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_probe_CFLAGS) -MD -c -o $@ $<
 -include grub_probe-kern_device.d
@@ -429,12 +434,14 @@
 
 # for grub-editenv
 bin_UTILITIES += grub-editenv
-grub_editenv_SOURCES = util/grub-editenv.c lib/envblk.c util/misc.c kern/misc.c kern/err.c
-CLEANFILES += grub-editenv$(EXEEXT) grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-kern_misc.o grub_editenv-kern_err.o
-MOSTLYCLEANFILES += grub_editenv-util_grub_editenv.d grub_editenv-lib_envblk.d grub_editenv-util_misc.d grub_editenv-kern_misc.d grub_editenv-kern_err.d
+grub_editenv_SOURCES = util/grub-editenv.c lib/envblk.c util/misc.c \
+	util/user-stub.c \
+	kern/misc.c kern/err.c
+CLEANFILES += grub-editenv$(EXEEXT) grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-util_user_stub.o grub_editenv-kern_misc.o grub_editenv-kern_err.o
+MOSTLYCLEANFILES += grub_editenv-util_grub_editenv.d grub_editenv-lib_envblk.d grub_editenv-util_misc.d grub_editenv-util_user_stub.d grub_editenv-kern_misc.d grub_editenv-kern_err.d
 
-grub-editenv: $(grub_editenv_DEPENDENCIES) grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-kern_misc.o grub_editenv-kern_err.o
-	$(CC) -o $@ grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-kern_misc.o grub_editenv-kern_err.o $(LDFLAGS) $(grub_editenv_LDFLAGS)
+grub-editenv: $(grub_editenv_DEPENDENCIES) grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-util_user_stub.o grub_editenv-kern_misc.o grub_editenv-kern_err.o
+	$(CC) -o $@ grub_editenv-util_grub_editenv.o grub_editenv-lib_envblk.o grub_editenv-util_misc.o grub_editenv-util_user_stub.o grub_editenv-kern_misc.o grub_editenv-kern_err.o $(LDFLAGS) $(grub_editenv_LDFLAGS)
 
 grub_editenv-util_grub_editenv.o: util/grub-editenv.c $(util/grub-editenv.c_DEPENDENCIES)
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_editenv_CFLAGS) -MD -c -o $@ $<
@@ -448,6 +455,10 @@
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_editenv_CFLAGS) -MD -c -o $@ $<
 -include grub_editenv-util_misc.d
 
+grub_editenv-util_user_stub.o: util/user-stub.c $(util/user-stub.c_DEPENDENCIES)
+	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_editenv_CFLAGS) -MD -c -o $@ $<
+-include grub_editenv-util_user_stub.d
+
 grub_editenv-kern_misc.o: kern/misc.c $(kern/misc.c_DEPENDENCIES)
 	$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_editenv_CFLAGS) -MD -c -o $@ $<
 -include grub_editenv-kern_misc.d

Index: conf/i386-pc.mk
===================================================================

i386-pc.mk +10 -5
@@ -310,7 +310,8 @@
 # For grub-setup.
 util/i386/pc/grub-setup.c_DEPENDENCIES = grub_setup_init.h
 grub_setup_SOURCES = util/i386/pc/grub-setup.c util/biosdisk.c	\
-	util/misc.c util/getroot.c kern/device.c kern/disk.c	\
+	util/misc.c util/getroot.c util/user-stub.c 		\
+	kern/device.c kern/disk.c				\
 	kern/err.c kern/misc.c kern/parser.c kern/partition.c	\
 	kern/file.c kern/fs.c kern/env.c fs/fshelp.c		\
 	\
@@ -324,11 +325,11 @@
 	disk/raid.c disk/lvm.c					\
 	util/raid.c util/lvm.c					\
 	grub_setup_init.c
-CLEANFILES += grub-setup$(EXEEXT) grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o
-MOSTLYCLEANFILES += grub_setup-util_i386_pc_grub_setup.d grub_setup-util_biosdisk.d grub_setup-util_misc.d grub_setup-util_getroot.d grub_setup-kern_device.d grub_setup-kern_disk.d grub_setup-kern_err.d grub_setup-kern_misc.d grub_setup-kern_parser.d grub_setup-kern_partition.d grub_setup-kern_file.d grub_setup-kern_fs.d grub_setup-kern_env.d grub_setup-fs_fshelp.d grub_setup-fs_affs.d grub_setup-fs_cpio.d grub_setup-fs_ext2.d grub_setup-fs_fat.d grub_setup-fs_hfs.d grub_setup-fs_hfsplus.d grub_setup-fs_iso9660.d grub_setup-fs_udf.d grub_setup-fs_jfs.d grub_setup-fs_minix.d grub_setup-fs_ntfs.d grub_setup-fs_ntfscomp.d grub_setup-fs_reiserfs.d grub_setup-fs_sfs.d grub_setup-fs_ufs.d grub_setup-fs_xfs.d grub_setup-fs_afs.d grub_setup-partmap_pc.d grub_setup-partmap_gpt.d grub_setup-disk_raid.d grub_setup-disk_lvm.d grub_setup-util_raid.d grub_setup-util_lvm.d grub_setup-grub_setup_init.d
+CLEANFILES += grub-setup$(EXEEXT) grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-util_user_stub.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o
+MOSTLYCLEANFILES += grub_setup-util_i386_pc_grub_setup.d grub_setup-util_biosdisk.d grub_setup-util_misc.d grub_setup-util_getroot.d grub_setup-util_user_stub.d grub_setup-kern_device.d grub_setup-kern_disk.d grub_setup-kern_err.d grub_setup-kern_misc.d grub_setup-kern_parser.d grub_setup-kern_partition.d grub_setup-kern_file.d grub_setup-kern_fs.d grub_setup-kern_env.d grub_setup-fs_fshelp.d grub_setup-fs_affs.d grub_setup-fs_cpio.d grub_setup-fs_ext2.d grub_setup-fs_fat.d grub_setup-fs_hfs.d grub_setup-fs_hfsplus.d grub_setup-fs_iso9660.d grub_setup-fs_udf.d grub_setup-fs_jfs.d grub_setup-fs_minix.d grub_setup-fs_ntfs.d grub_setup-fs_ntfscomp.d grub_setup-fs_reiserfs.d grub_setup-fs_sfs.d grub_setup-fs_ufs.d grub_setup-fs_xfs.d grub_setup-fs_afs.d grub_setup-partmap_pc.d grub_setup-partmap_gpt.d grub_setup-disk_raid.d grub_setup-disk_lvm.d grub_setup-util_raid.d grub_setup-util_lvm.d grub_setup-grub_setup_init.d
 
-grub-setup: $(grub_setup_DEPENDENCIES) grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o
-	$(CC) -o $@ grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o $(LDFLAGS) $(grub_setup_LDFLAGS)
+grub-setup: $(grub_setup_DEPENDENCIES) grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-util_user_stub.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o
+	$(CC) -o $@ grub_setup-util_i386_pc_grub_setup.o grub_setup-util_biosdisk.o grub_setup-util_misc.o grub_setup-util_getroot.o grub_setup-util_user_stub.o grub_setup-kern_device.o grub_setup-kern_disk.o grub_setup-kern_err.o grub_setup-kern_misc.o grub_setup-kern_parser.o grub_setup-kern_partition.o grub_setup-kern_file.o grub_setup-kern_fs.o grub_setup-kern_env.o grub_setup-fs_fshelp.o grub_setup-fs_affs.o grub_setup-fs_cpio.o grub_setup-fs_ext2.o grub_setup-fs_fat.o grub_setup-fs_hfs.o grub_setup-fs_hfsplus.o grub_setup-fs_iso9660.o grub_setup-fs_udf.o grub_setup-fs_jfs.o grub_setup-fs_minix.o grub_setup-fs_ntfs.o grub_setup-fs_ntfscomp.o grub_setup-fs_reiserfs.o grub_setup-fs_sfs.o grub_setup-fs_ufs.o grub_setup-fs_xfs.o grub_setup-fs_afs.o grub_setup-partmap_pc.o grub_setup-partmap_gpt.o grub_setup-disk_raid.o grub_setup-disk_lvm.o grub_setup-util_raid.o grub_setup-util_lvm.o grub_setup-grub_setup_init.o $(LDFLAGS) $(grub_setup_LDFLAGS)
 
 grub_setup-util_i386_pc_grub_setup.o: util/i386/pc/grub-setup.c $(util/i386/pc/grub-setup.c_DEPENDENCIES)
 	$(CC) -Iutil/i386/pc -I$(srcdir)/util/i386/pc $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_setup_CFLAGS) -MD -c -o $@ $<
@@ -346,6 +347,10 @@
 	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_setup_CFLAGS) -MD -c -o $@ $<
 -include grub_setup-util_getroot.d
 
+grub_setup-util_user_stub.o: util/user-stub.c $(util/user-stub.c_DEPENDENCIES)
+	$(CC) -Iutil -I$(srcdir)/util $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_setup_CFLAGS) -MD -c -o $@ $<
+-include grub_setup-util_user_stub.d
+
 grub_setup-kern_device.o: kern/device.c $(kern/device.c_DEPENDENCIES)
 	$(CC) -Ikern -I$(srcdir)/kern $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(grub_setup_CFLAGS) -MD -c -o $@ $<
 -include grub_setup-kern_device.d

Index: kern/i386/pc/startup.S
===================================================================

i386/pc/startup.S +21 -1
@@ -1502,8 +1502,28 @@
 	popl	%ebx
 	popl	%ebp
 	ret
-		
+
+
 /*
+ * void grub_cpu_idle (void)
+ * Change to real mode to enable interrupts and hlt until the next interrupt.
+ */
+FUNCTION(grub_cpu_idle)
+	pushl	%ebp
+
+	call	prot_to_real	/* enter real mode */
+	.code16
+
+	hlt
+
+	DATA32	call	real_to_prot
+	.code32
+
+	popl	%ebp
+	ret
+
+
+/*
  * grub_getrtsecs()
  *	if a seconds value can be read, read it and return it (BCD),
  *      otherwise return 0xFF

Index: NEWS
===================================================================

NEWS +3 -0
@@ -1,5 +1,8 @@
 New in 1.97 - :
 
+* Enable grub_cpu_idle for i386 to halt the CPU and modify the menu code
+  to make use of it.  This will save power when booting.
+
 * When booting from PXE, PXE can be used to load files.
 
 * High resolution timer support.

Index: include/grub/i386/time.h
===================================================================

grub/i386/time.h +4 -6
@@ -19,11 +19,9 @@
 #ifndef KERNEL_CPU_TIME_HEADER
 #define KERNEL_CPU_TIME_HEADER	1
 
-static __inline void
-grub_cpu_idle (void)
-{
-  /* FIXME: this can't work until we handle interrupts.  */
-/*  __asm__ __volatile__ ("hlt"); */
-}
+/* Call into assembly to change to real mode and enable interrupts so it
+   can halt until the next interrupt is received. */
+void
+EXPORT_FUNC(grub_cpu_idle) (void);
 
 #endif /* ! KERNEL_CPU_TIME_HEADER */

Index: ChangeLog
===================================================================

ChangeLog +4 -0
@@ -1,3 +1,18 @@
+2008-08-10  David Fries <[email protected]>
+
+	Enable hlt in grub_cpu_idle so it can be idle when called.
+	* kern/i386/pc/startup.S: grub_cpu_idle, halt with interrupts

ChangeLog line 14

Quoted 10 lines
ChangeLog +10 -0
+	* include/grub/i386/time.h: export function grub_cpu_idle.
+	* normal/menu.c: Sleep in halt (if supported), until a second elapsed
+	or a key is pressed.
+	* util/user-stub.c: New file.  The utilities link against part of the
+	kernel.  This new file is intended to be a dumping place for functions
+	that are requierd by parts of the kernel included, but not found in
+	those places.
+	* conf/common.rmk: Make use of user-stub.c in grub_probe and
+	grub-editenv.
+	* conf/i386-pc.rmk: Make use of user-stub.c in grub-setup.

Our changelogs describe changes, not the effects. Please keep descriptions very short. I would like to refer you to:

http://www.gnu.org/prep/standards/html_node/Change-Logs.html

Furthermore, you can look at the current changelog to see how it works.

Quoted 16 lines
ChangeLog +0 -0
 2008-08-09  Christian Franke  <[email protected]>
 
 	* Makefile.in: Add `target_os' and `enable_grub_pe2elf'.

Index: normal/menu.c
===================================================================

menu.c +1 -0
@@ -24,6 +24,7 @@
 #include <grub/time.h>
 #include <grub/env.h>
 #include <grub/script.h>
+#include <grub/cpu/time.h>
 
 static grub_uint8_t grub_color_menu_normal;
 static grub_uint8_t grub_color_menu_highlight;

menu.c line 390

Quoted 9 lines
menu.c +6 -0
@@ -381,6 +382,12 @@
 	      saved_time = current_time;
 	      print_timeout (timeout, offset, 1);
 	    }
+          /* Sleep until a second has passed or a key is pressed. */
+          do
+            {
+              grub_cpu_idle ();
+            }while (grub_get_rtc () - saved_time < GRUB_TICKS_PER_SECOND &&
+              grub_checkkey () == -1);

This doesn't match our coding style. I would write something like:

while (grub_get_rtc () - saved_time < GRUB_TICKS_PER_SECOND

	 && grub_checkkey () == -1)
    grub_cpu_idle ();

(it's easier to format a while, I think)

Quoted 58 lines
menu.c +0 -0
 	}
 
       if (timeout == 0)

Index: DISTLIST
===================================================================

DISTLIST +1 -0
@@ -358,6 +358,7 @@
 util/raid.c
 util/resolve.c
 util/unifont2pff.rb
+util/user-stub.c
 util/update-grub.in
 util/update-grub_lib.in
 video/bitmap.c

Index: util/user-stub.c
===================================================================

user-stub.c +32 -0
@@ -0,0 +1,32 @@
+/*
+ *  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/>.
+ */
+
+/* Provide user space stubs for the utility programs to compile against.
+   They are not included in the pieces of the kernel linked in to the
+   utility programs, but are unresolved symbols for the parts that are. */
+
+#include <config.h>
+#include <stdio.h>
+#include <time.h>
+
+void
+grub_cpu_idle ()
+{
+  struct timespec req={0,1};
+  nanosleep (&req, NULL);
+}

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel