Skip to contentSkip to conversation

multiboot on EFI

PATCH phcoder 4 participants 15 messages Mar 23, 2009 – Apr 4, 2009

lore
Share & tools
lore

phcoder

author
#0 lore raw

Hello. Here is an initial version of patch for booting multiboot kernels on i386-efi. No Changelog yet because it's not for inclusion yet.

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
conf/common.rmk +7 -0
index 100fae7..e64a1a4 100644
@@ -507,3 +507,10 @@ gzio_mod_LDFLAGS = $(COMMON_LDFLAGS)
 bufio_mod_SOURCES = io/bufio.c
 bufio_mod_CFLAGS = $(COMMON_CFLAGS)
 bufio_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+pkglib_MODULES += lsmmap.mod
+
+# For lsmmap.mod
+lsmmap_mod_SOURCES = commands/lsmmap.c
+lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
+lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
conf/i386-coreboot.rmk +1 -7
index 6f4e8f3..1304eb3 100644
@@ -102,8 +102,7 @@ pkglib_MODULES = _linux.mod linux.mod normal.mod	\
 	_multiboot.mod multiboot.mod aout.mod		\
 	play.mod serial.mod ata.mod			\
 	memdisk.mod pci.mod lspci.mod reboot.mod	\
-	halt.mod datetime.mod date.mod datehook.mod	\
-	lsmmap.mod
+	halt.mod datetime.mod date.mod datehook.mod	
 
 # For _linux.mod.
 _linux_mod_SOURCES = loader/i386/linux.c
@@ -211,10 +210,5 @@ datehook_mod_SOURCES = hook/datehook.c
 datehook_mod_CFLAGS = $(COMMON_CFLAGS)
 datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
-# For lsmmap.mod
-lsmmap_mod_SOURCES = commands/lsmmap.c
-lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
-lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
 include $(srcdir)/conf/i386.mk
 include $(srcdir)/conf/common.mk
conf/i386-efi.rmk +16 -3
index a2454d9..4303b1c 100644
@@ -80,7 +80,20 @@ grub_install_SOURCES = util/i386/efi/grub-install.in
 # Modules.
 pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \
 	_linux.mod linux.mod halt.mod reboot.mod pci.mod lspci.mod \
-	datetime.mod date.mod datehook.mod
+	datetime.mod date.mod datehook.mod _multiboot.mod multiboot.mod
+
+# For _multiboot.mod.
+_multiboot_mod_SOURCES = loader/i386/multiboot.c \
+			 loader/i386/multiboot_helper.S \
+                         loader/multiboot_loader.c
+_multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
+_multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+_multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS)
+
+# For multiboot.mod.
+multiboot_mod_SOURCES = loader/multiboot_loader_normal.c 
+multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
+multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For kernel.mod.
 kernel_mod_EXPORTS = no
@@ -90,14 +103,14 @@ kernel_mod_SOURCES = kern/i386/efi/startup.S kern/main.c kern/device.c \
 	kern/i386/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \
 	kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \
 	term/efi/console.c disk/efi/efidisk.c \
-	kern/time.c kern/list.c kern/handler.c \
+	kern/efi/mmap.c kern/time.c kern/list.c kern/handler.c \
 	kern/i386/tsc.c kern/i386/pit.c \
 	kern/generic/rtc_get_time_ms.c \
 	kern/generic/millisleep.c
 kernel_mod_HEADERS = arg.h boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
 	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
 	partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
-	efi/efi.h efi/time.h efi/disk.h list.h handler.h
+	efi/efi.h efi/time.h efi/disk.h efi/memory.h list.h handler.h
 kernel_mod_CFLAGS = $(COMMON_CFLAGS)
 kernel_mod_ASFLAGS = $(COMMON_ASFLAGS)
 kernel_mod_LDFLAGS = $(COMMON_LDFLAGS)
conf/i386-ieee1275.rmk +1 -6
index 305b31d..460dfdd 100644
@@ -102,7 +102,7 @@ grub_install_SOURCES = util/ieee1275/grub-install.in
 pkglib_MODULES = normal.mod halt.mod reboot.mod suspend.mod		\
 	multiboot.mod _multiboot.mod aout.mod serial.mod linux.mod	\
 	_linux.mod nand.mod memdisk.mod pci.mod lspci.mod datetime.mod	\
-	date.mod datehook.mod lsmmap.mod
+	date.mod datehook.mod
 
 #
 # Only arch dependant part of normal.mod will be here. Common part for
@@ -209,10 +209,5 @@ datehook_mod_SOURCES = hook/datehook.c
 datehook_mod_CFLAGS = $(COMMON_CFLAGS)
 datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
-# For lsmmap.mod
-lsmmap_mod_SOURCES = commands/lsmmap.c
-lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
-lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
 include $(srcdir)/conf/i386.mk
 include $(srcdir)/conf/common.mk
conf/i386-pc.rmk +2 -22
index e1ed9aa..0be2729 100644
@@ -178,8 +178,8 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.mod \
 	_multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod	\
 	vbe.mod vbetest.mod vbeinfo.mod play.mod serial.mod	\
 	ata.mod vga.mod memdisk.mod pci.mod lspci.mod \
-	aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \
-	datehook.mod lsmmap.mod ata_pthru.mod hdparm.mod \
+	pxe.mod pxecmd.mod datetime.mod date.mod \
+	datehook.mod ata_pthru.mod hdparm.mod \
 	usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod \
 	efiemu.mod efiemu_acpi.mod efiemu_pnvram.mod
 
@@ -318,21 +318,6 @@ lspci_mod_SOURCES = commands/lspci.c
 lspci_mod_CFLAGS = $(COMMON_CFLAGS)
 lspci_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
-# For aout.mod
-aout_mod_SOURCES = loader/aout.c
-aout_mod_CFLAGS = $(COMMON_CFLAGS)
-aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
-# For _bsd.mod
-_bsd_mod_SOURCES = loader/i386/bsd.c
-_bsd_mod_CFLAGS = $(COMMON_CFLAGS)
-_bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
-# For bsd.mod
-bsd_mod_SOURCES = loader/i386/bsd_normal.c
-bsd_mod_CFLAGS = $(COMMON_CFLAGS)
-bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
 # For usb.mod
 usb_mod_SOURCES = bus/usb/usb.c bus/usb/usbtrans.c bus/usb/usbhub.c
 usb_mod_CFLAGS = $(COMMON_CFLAGS)
@@ -388,11 +373,6 @@ datehook_mod_SOURCES = hook/datehook.c
 datehook_mod_CFLAGS = $(COMMON_CFLAGS)
 datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
-# For lsmmap.mod
-lsmmap_mod_SOURCES = commands/lsmmap.c
-lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
-lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
 # For ata_pthru.mod.
 ata_pthru_mod_SOURCES = disk/ata_pthru.c
 ata_pthru_mod_CFLAGS = $(COMMON_CFLAGS)
conf/i386.rmk +18 -0
index 4e86ed8..5338457 100644
@@ -19,3 +19,21 @@ pkglib_MODULES += uppermem.mod
 uppermem_mod_SOURCES = lib/i386/uppermem.c
 uppermem_mod_CFLAGS = $(COMMON_CFLAGS)
 uppermem_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+pkglib_MODULES += aout.mod _bsd.mod bsd.mod 
+# For aout.mod
+aout_mod_SOURCES = loader/aout.c
+aout_mod_CFLAGS = $(COMMON_CFLAGS)
+aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For _bsd.mod
+_bsd_mod_SOURCES = loader/i386/bsd.c loader/i386/bsd_helper.S
+_bsd_mod_CFLAGS = $(COMMON_CFLAGS) -Werror
+_bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
+_bsd_mod_ASFLAGS = $(COMMON_ASFLAGS)
+
+# For bsd.mod
+bsd_mod_SOURCES = loader/i386/bsd_normal.c
+bsd_mod_CFLAGS = $(COMMON_CFLAGS)
+bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
conf/powerpc-ieee1275.rmk +1 -7
index 66d1d58..c9e185a 100644
@@ -112,8 +112,7 @@ pkglib_MODULES = halt.mod \
 	suspend.mod \
         _multiboot.mod \
         multiboot.mod \
-	memdisk.mod \
-	lsmmap.mod
+	memdisk.mod 
 
 # For _linux.mod.
 _linux_mod_SOURCES = loader/powerpc/ieee1275/linux.c
@@ -178,10 +177,5 @@ memdisk_mod_SOURCES = disk/memdisk.c
 memdisk_mod_CFLAGS = $(COMMON_CFLAGS)
 memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
-# For lsmmap.mod
-lsmmap_mod_SOURCES = commands/lsmmap.c
-lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
-lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
 include $(srcdir)/conf/common.mk
 
include/grub/efi/efi.h +2 -0
index 8c277c0..137a437 100644
@@ -54,6 +54,8 @@ char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp);
 grub_efi_device_path_t *
 EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);
 int EXPORT_FUNC(grub_efi_exit_boot_services) (grub_efi_uintn_t map_key);
+int EXPORT_FUNC(grub_efi_finish_boot_services) (void);
+
 void EXPORT_FUNC (grub_reboot) (void);
 void EXPORT_FUNC (grub_halt) (void);
 
include/grub/efi/memory.h new file +15 -0
new file mode 100644
index 0000000..9000642
@@ -0,0 +1,15 @@
+#ifndef GRUB_MEMORY_MACHINE_HEADER
+#define GRUB_MEMORY_MACHINE_HEADER	1
+
+#include <grub/err.h>
+#include <grub/types.h>
+
+#define GRUB_MACHINE_MEMORY_AVAILABLE	1
+#define GRUB_MACHINE_MEMORY_RESERVED	2
+#define GRUB_MACHINE_MEMORY_ACPI	3
+#define GRUB_MACHINE_MEMORY_NVS         4
+#define GRUB_MACHINE_MEMORY_CODE         5
+
+grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate) 
+(int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
+#endif /* ! GRUB_MEMORY_MACHINE_HEADER */
include/grub/i386/bsd.h +5 -0
index 00296c9..e8bed00 100644
@@ -148,6 +148,8 @@ struct grub_openbsd_bios_mmap
 {
   grub_uint64_t addr;
   grub_uint64_t len;
+#define	OPENBSD_MMAP_AVAILABLE	1
+#define	OPENBSD_MMAP_RESERVED 2
   grub_uint32_t type;
 };
 
@@ -229,4 +231,7 @@ void grub_rescue_cmd_netbsd (int argc, char *argv[]);
 void grub_rescue_cmd_freebsd_loadenv (int argc, char *argv[]);
 void grub_rescue_cmd_freebsd_module (int argc, char *argv[]);
 
+void grub_unix_real_boot (grub_addr_t entry, ...)
+  __attribute__ ((cdecl,noreturn));
+
 #endif /* ! GRUB_BSD_CPU_HEADER */
include/grub/i386/efi/memory.h new file +1 -0
new file mode 100644
index 0000000..c9a61bb
@@ -0,0 +1 @@
+#include <grub/efi/memory.h>
include/grub/i386/loader.h +0 -3
index f858c0a..cb2f918 100644
@@ -32,9 +32,6 @@ extern grub_size_t EXPORT_VAR(grub_os_area_size);
 
 grub_err_t EXPORT_FUNC(grub_linux_boot) (void);
 
-void EXPORT_FUNC(grub_unix_real_boot) (grub_addr_t entry, ...)
-     __attribute__ ((cdecl,noreturn));
-
 /* It is necessary to export these functions, because normal mode commands
    reuse rescue mode commands.  */
 void grub_rescue_cmd_linux (int argc, char *argv[]);
include/grub/i386/multiboot.h +1 -1
index ea68640..85405dc 100644
@@ -22,7 +22,7 @@
 /* The asm part of the multiboot loader.  */
 void grub_multiboot_real_boot (grub_addr_t entry,
 			       struct grub_multiboot_info *mbi)
-     __attribute__ ((noreturn));
+  __attribute__ ((noreturn,regparm (3)));
 void grub_multiboot2_real_boot (grub_addr_t entry,
 				struct grub_multiboot_info *mbi)
      __attribute__ ((noreturn));
include/grub/i386/pc/memory.h +2 -0
index 08e92a9..e69ff77 100644
@@ -92,6 +92,8 @@ struct grub_machine_mmap_entry
   grub_uint64_t len;
 #define GRUB_MACHINE_MEMORY_AVAILABLE	1
 #define GRUB_MACHINE_MEMORY_RESERVED	2
+#define GRUB_MACHINE_MEMORY_ACPI	3
+#define GRUB_MACHINE_MEMORY_NVS 	4
   grub_uint32_t type;
 } __attribute__((packed));
 
include/grub/x86_64/efi/memory.h new file +1 -0
new file mode 100644
index 0000000..c9a61bb
@@ -0,0 +1 @@
+#include <grub/efi/memory.h>
kern/efi/efi.c +22 -0
index 9c9a400..754f82c 100644
@@ -187,6 +187,28 @@ grub_efi_exit_boot_services (grub_efi_uintn_t map_key)
   return status == GRUB_EFI_SUCCESS;
 }
 
+int
+grub_efi_finish_boot_services (void)
+{
+  grub_efi_uintn_t mmap_size = 0;
+  grub_efi_uintn_t map_key;
+  grub_efi_uintn_t desc_size;
+  grub_efi_uint32_t desc_version;
+  void *mmap_buf;
+
+  if (grub_efi_get_memory_map (&mmap_size, mmap_buf, &map_key,
+			       &desc_size, &desc_version) < 0)
+    return 0;
+
+  mmap_buf = grub_malloc (mmap_size);
+  
+  if (grub_efi_get_memory_map (&mmap_size, mmap_buf, &map_key,
+			       &desc_size, &desc_version) <= 0)
+    return 0;
+
+  return  grub_efi_exit_boot_services (map_key);
+}
+
 grub_uint32_t
 grub_get_rtc (void)
 {
kern/efi/mm.c +1 -1
index 35b12ab..4635776 100644
@@ -47,7 +47,7 @@ static struct allocated_page *allocated_pages = 0;
 
 /* The minimum and maximum heap size for GRUB itself.  */
 #define MIN_HEAP_SIZE	0x100000
-#define MAX_HEAP_SIZE	(16 * 0x100000)
+#define MAX_HEAP_SIZE	(1600 * 0x100000)
 
 
 /* Allocate pages. Return the pointer to the first of allocated pages.  */
kern/efi/mmap.c new file +158 -0

158 lines not on this page · raw message

kern/i386/loader.S +0 -24
index fc27b86..f1b6c18 100644
@@ -117,27 +117,3 @@ bzimage:
 linux_setup_seg:
 	.word	0
 	.code32
-
-/*
- * Use cdecl calling convention for *BSD kernels.
- */
-
-FUNCTION(grub_unix_real_boot)
-
-        call    EXT_C(grub_dl_unload_all)
-        call    EXT_C(grub_stop_floppy)
-
-	/* Interrupts should be disabled.  */
-        cli
-
-	/* Discard `grub_unix_real_boot' return address.  */
-        popl    %eax
-
-        /* Fetch `entry' address ...  */
-        popl	%eax
-
-        /*
-         * ... and put our return address in its place. The kernel will
-         * ignore it, but it expects %esp to point to it.
-         */
-        call	*%eax
loader/i386/bsd.c +75 -26

189 lines not on this page · raw message

loader/i386/bsd_helper.S new file +65 -0

65 lines not on this page · raw message

loader/i386/multiboot.c +36 -8

99 lines not on this page · raw message

loader/i386/multiboot_helper.S +2 -2
index 1e71120..cd07246 100644
@@ -52,7 +52,7 @@ VARIABLE(grub_multiboot_forward_relocator)
 	cld
 	rep
 	movsb
-
+	
 	jmp	*%edx
 VARIABLE(grub_multiboot_forward_relocator_end)
 
@@ -91,7 +91,7 @@ FUNCTION(grub_multiboot_real_boot)
 
 	/* Move the magic value into eax.  */
 	movl	$MULTIBOOT_MAGIC2, %eax
-				
+
 	/* Jump to the relocator.  */
 	popl	%ebp
 	jmp 	*%ebp
loader/i386/xnu_helper.S +5 -2
index 901be68..a83bd9a 100644
@@ -15,6 +15,9 @@ FUNCTION(grub_xnu_launch)
 	jmp cont1
 cont1:
 	lgdt gdtdesc
+
+	jmp cont2
+cont2:
 	
 	.code32
 	
@@ -28,8 +31,8 @@ cont1:
 	and $0xffffffef, %eax
 	wrmsr
 
-	jmp cont2
-cont2:	
+	jmp cont3
+cont3:	
 #endif
 
 	.code32
loader/multiboot_loader.c +6 -2
index abcad9b..8abce88 100644
@@ -140,7 +140,7 @@ grub_rescue_cmd_multiboot_loader (int argc, char *argv[])
 
    /* XXX Find a better way to identify this. 
       This is for i386-pc */
-#if defined(GRUB_MACHINE_PCBIOS) || defined(GRUB_MACHINE_LINUXBIOS)
+#if defined(GRUB_MACHINE_PCBIOS) || defined(GRUB_MACHINE_LINUXBIOS) || defined (GRUB_MACHINE_EFI)
   if (header_multi_ver_found == 1)
     {
       grub_dprintf ("multiboot_loader",
@@ -153,7 +153,9 @@ grub_rescue_cmd_multiboot_loader (int argc, char *argv[])
     {
       grub_dprintf ("multiboot_loader",
            "Launching multiboot 2 grub_multiboot2() function\n");
+#ifndef GRUB_MACHINE_EFI
       grub_multiboot2 (argc, argv);
+#endif
       module_version_status = 2;
     }
 
@@ -170,7 +172,7 @@ void
 grub_rescue_cmd_module_loader (int argc, char *argv[])
 {
 
-#if defined(GRUB_MACHINE_PCBIOS) || defined(GRUB_MACHINE_LINUXBIOS)
+#if defined(GRUB_MACHINE_PCBIOS) || defined(GRUB_MACHINE_LINUXBIOS) || defined(GRUB_MACHINE_EFI)
   if (module_version_status == 1)
     {
       grub_dprintf("multiboot_loader",
@@ -182,7 +184,9 @@ grub_rescue_cmd_module_loader (int argc, char *argv[])
     {
       grub_dprintf("multiboot_loader",
           "Launching multiboot 2 grub_module2() function\n");
+#ifndef GRUB_MACHINE_EFI
       grub_module2 (argc, argv);
+#endif
     }
 }
 
conf/i386.rmk +5 -0
index 93f84ce..5338457 100644
@@ -14,3 +14,8 @@ pkglib_MODULES += vga_text.mod
 vga_text_mod_SOURCES = term/i386/pc/vga_text.c term/i386/vga_common.c
 vga_text_mod_CFLAGS = $(COMMON_CFLAGS)
 vga_text_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+pkglib_MODULES += uppermem.mod
+uppermem_mod_SOURCES = lib/i386/uppermem.c
+uppermem_mod_CFLAGS = $(COMMON_CFLAGS)
+uppermem_mod_LDFLAGS = $(COMMON_LDFLAGS)
lib/i386/uppermem.c new file +127 -0

127 lines not on this page · raw message

#1 lore raw

Vladimir,

First of all I'd like to say thank you for a quick feedback and development.

I tried to apply your patches and test it on my Apple Xserve Intel 32 bit. I've done following;

# svn co svn://svn.sv.gnu.org/grub/trunk/grub2
# cd ./grub2
# patch -b -p1 < ./uppermem.diff
patching file conf/i386.rmk
patching file lib/i386/uppermem.c
 --- it's Ok
 --- Than
#  patch -b -p1 < ./efiboot.diff
patching file conf/common.rmk
Hunk #1 succeeded at 503 (offset -4 lines).
patching file conf/i386-coreboot.rmk
Hunk #1 succeeded at 99 with fuzz 2 (offset -3 lines).
Hunk #2 succeeded at 200 (offset -10 lines).
patching file conf/i386-efi.rmk
Hunk #1 FAILED at 80.
Hunk #2 FAILED at 103.
...
etc.

I would like to ask you for what revision of grub2 this patches where done? Do I have to checkout any specific branch of grub2?

Thank you in advance.

2009/3/23 phcoder <[email protected]>:

Quoted 13 lines

Hello. Here is an initial version of patch for booting multiboot kernels on i386-efi. No Changelog yet because it's not for inclusion yet. --

Regards
Vladimir 'phcoder' Serbinenko

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

author
#2 lore raw

Try with 2030. Actually it's diffed against 2030+some of my posted and unposted patches. If it still doesn't apply please report I'll update and rediff it against HEAD. I'm interested in behaviour of this code on real EFI however doesn't expect this version to be able to work completely.
x86_64-efi isn't supported by this patch yet
Also if xen uses any bios interrupts it will probably triple fault. On IRC we discussed a possibility of loading seabios and it's probably feasible but will take more time

Quoted 52 lines · uzer cheg

Vladimir,

First of all I'd like to say thank you for a quick feedback and development.

I tried to apply your patches and test it on my Apple Xserve Intel 32 bit. I've done following;

# svn co svn://svn.sv.gnu.org/grub/trunk/grub2
# cd ./grub2
# patch -b -p1 < ./uppermem.diff
patching file conf/i386.rmk
patching file lib/i386/uppermem.c
 --- it's Ok
 --- Than
#  patch -b -p1 < ./efiboot.diff
patching file conf/common.rmk
Hunk #1 succeeded at 503 (offset -4 lines).
patching file conf/i386-coreboot.rmk
Hunk #1 succeeded at 99 with fuzz 2 (offset -3 lines).
Hunk #2 succeeded at 200 (offset -10 lines).
patching file conf/i386-efi.rmk
Hunk #1 FAILED at 80.
Hunk #2 FAILED at 103.
...
etc.

I would like to ask you for what revision of grub2 this patches where done? Do I have to checkout any specific branch of grub2?

Thank you in advance.

2009/3/23 phcoder <[email protected]>:

Quoted 4 lines

Hello. Here is an initial version of patch for booting multiboot kernels on i386-efi. No Changelog yet because it's not for inclusion yet. --

Quoted 9 lines

Regards
Vladimir 'phcoder' Serbinenko

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

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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
author
#3 lore raw

You may also need my elf bugfix patch (was applied as rev 2037)

Quoted 59 lines · phcoder

Try with 2030. Actually it's diffed against 2030+some of my posted and unposted patches. If it still doesn't apply please report I'll update and rediff it against HEAD. I'm interested in behaviour of this code on real EFI however doesn't expect this version to be able to work completely.
x86_64-efi isn't supported by this patch yet
Also if xen uses any bios interrupts it will probably triple fault. On IRC we discussed a possibility of loading seabios and it's probably feasible but will take more time

Quoted 52 lines · uzer cheg

Vladimir,

First of all I'd like to say thank you for a quick feedback and development.

I tried to apply your patches and test it on my Apple Xserve Intel 32 bit. I've done following;

# svn co svn://svn.sv.gnu.org/grub/trunk/grub2
# cd ./grub2
# patch -b -p1 < ./uppermem.diff
patching file conf/i386.rmk
patching file lib/i386/uppermem.c
 --- it's Ok
 --- Than
#  patch -b -p1 < ./efiboot.diff
patching file conf/common.rmk
Hunk #1 succeeded at 503 (offset -4 lines).
patching file conf/i386-coreboot.rmk
Hunk #1 succeeded at 99 with fuzz 2 (offset -3 lines).
Hunk #2 succeeded at 200 (offset -10 lines).
patching file conf/i386-efi.rmk
Hunk #1 FAILED at 80.
Hunk #2 FAILED at 103.
...
etc.

I would like to ask you for what revision of grub2 this patches where done? Do I have to checkout any specific branch of grub2?

Thank you in advance.

2009/3/23 phcoder <[email protected]>:

Quoted 13 lines

Hello. Here is an initial version of patch for booting multiboot kernels on i386-efi. No Changelog yet because it's not for inclusion yet.

Signature · 7 lines
Regards
Vladimir 'phcoder' Serbinenko

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

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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#4 lore raw
In reply to phcoder

Dear Vladimir,
I tried rev 2030 and 2037.
And I also had few errors on patching stage.

I think it is a good idea to commit your code to head branch. I will wait for it and try it asap.

Thank you.

Quoted 81 lines · phcoder

Try with 2030. Actually it's diffed against 2030+some of my posted and unposted patches. If it still doesn't apply please report I'll update and rediff it against HEAD.
I'm interested in behaviour of this code on real EFI however doesn't expect this version to be able to work completely.
x86_64-efi isn't supported by this patch yet
Also if xen uses any bios interrupts it will probably triple fault. On IRC we discussed a possibility of loading seabios and it's probably feasible but will take more time

Quoted 54 lines · uzer cheg

Vladimir,

First of all I'd like to say thank you for a quick feedback and development.

I  tried to apply your patches and test it on my Apple Xserve Intel 32 bit.
I've done following;

# svn co svn://svn.sv.gnu.org/grub/trunk/grub2
# cd ./grub2
# patch -b -p1 < ./uppermem.diff
patching file conf/i386.rmk
patching file lib/i386/uppermem.c
 --- it's Ok
 --- Than
#  patch -b -p1 < ./efiboot.diff
patching file conf/common.rmk
Hunk #1 succeeded at 503 (offset -4 lines).
patching file conf/i386-coreboot.rmk
Hunk #1 succeeded at 99 with fuzz 2 (offset -3 lines).
Hunk #2 succeeded at 200 (offset -10 lines).
patching file conf/i386-efi.rmk
Hunk #1 FAILED at 80.
Hunk #2 FAILED at 103.
...
etc.

I would like to ask you for what revision of grub2 this patches where done?
Do I have to checkout any specific branch of grub2?

Thank you in advance.

2009/3/23 phcoder <[email protected]>:

Quoted 6 lines

Hello. Here is an initial version of patch for booting multiboot kernels on
i386-efi. No Changelog yet because it's not for inclusion yet. --

Quoted 9 lines

Regards
Vladimir 'phcoder' Serbinenko

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

Quoted 4 lines

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

--

Regards
Vladimir 'phcoder' Serbinenko

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

author
#5 lore raw

Hello. I have to write rights to svn. And even if I had I would never commit a code in such stage (not reviewed, tested only on qemu, still in developement) However I'll rediff the code against HEAD when I'll have time

Quoted 93 lines · uzer cheg

Dear Vladimir,
I tried rev 2030 and 2037.
And I also had few errors on patching stage.

I think it is a good idea to commit your code to head branch. I will wait for it and try it asap.

Thank you.

Quoted 68 lines · phcoder

Try with 2030. Actually it's diffed against 2030+some of my posted and unposted patches. If it still doesn't apply please report I'll update and rediff it against HEAD.
I'm interested in behaviour of this code on real EFI however doesn't expect this version to be able to work completely.
x86_64-efi isn't supported by this patch yet
Also if xen uses any bios interrupts it will probably triple fault. On IRC we discussed a possibility of loading seabios and it's probably feasible but will take more time

Quoted 51 lines · uzer cheg

Vladimir,

First of all I'd like to say thank you for a quick feedback and development.

I tried to apply your patches and test it on my Apple Xserve Intel 32 bit.
I've done following;

# svn co svn://svn.sv.gnu.org/grub/trunk/grub2
# cd ./grub2
# patch -b -p1 < ./uppermem.diff
patching file conf/i386.rmk
patching file lib/i386/uppermem.c
 --- it's Ok
 --- Than
#  patch -b -p1 < ./efiboot.diff
patching file conf/common.rmk
Hunk #1 succeeded at 503 (offset -4 lines).
patching file conf/i386-coreboot.rmk
Hunk #1 succeeded at 99 with fuzz 2 (offset -3 lines).
Hunk #2 succeeded at 200 (offset -10 lines).
patching file conf/i386-efi.rmk
Hunk #1 FAILED at 80.
Hunk #2 FAILED at 103.
...
etc.

I would like to ask you for what revision of grub2 this patches where done?
Do I have to checkout any specific branch of grub2?

Thank you in advance.

2009/3/23 phcoder <[email protected]>:

Quoted 5 lines

Hello. Here is an initial version of patch for booting multiboot kernels on
i386-efi. No Changelog yet because it's not for inclusion yet. --

Quoted 9 lines

Regards
Vladimir 'phcoder' Serbinenko

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

Quoted 4 lines

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

--

Quoted 9 lines

Regards
Vladimir 'phcoder' Serbinenko

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

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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#6 lore raw

Ok. I see.

So I will wait for rediffed patches and number of revision.

Thank you in advance.

Quoted 120 lines · phcoder

Hello. I have to write rights to svn. And even if I had I would never commit a code in such stage (not reviewed, tested only on qemu, still in developement)
However I'll rediff the code against HEAD when I'll have time

Quoted 97 lines · uzer cheg

Dear Vladimir,
I tried rev 2030 and 2037.
And I also had few errors on patching stage.

I think it is a good idea to commit your code to head branch. I will wait for it and try it asap.

Thank you.

Quoted 75 lines · phcoder

Try with 2030. Actually it's diffed against 2030+some of my posted and unposted patches. If it still doesn't apply please report I'll update and rediff it against HEAD.
I'm interested in behaviour of this code on real EFI however doesn't expect
this version to be able to work completely.
x86_64-efi isn't supported by this patch yet
Also if xen uses any bios interrupts it will probably triple fault. On IRC
we discussed a possibility of loading seabios and it's probably feasible but
will take more time

Quoted 54 lines · uzer cheg

Vladimir,

First of all I'd like to say thank you for a quick feedback and development.

I  tried to apply your patches and test it on my Apple Xserve Intel 32 bit.
I've done following;

# svn co svn://svn.sv.gnu.org/grub/trunk/grub2
# cd ./grub2
# patch -b -p1 < ./uppermem.diff
patching file conf/i386.rmk
patching file lib/i386/uppermem.c
 --- it's Ok
 --- Than
#  patch -b -p1 < ./efiboot.diff
patching file conf/common.rmk
Hunk #1 succeeded at 503 (offset -4 lines).
patching file conf/i386-coreboot.rmk
Hunk #1 succeeded at 99 with fuzz 2 (offset -3 lines).
Hunk #2 succeeded at 200 (offset -10 lines).
patching file conf/i386-efi.rmk
Hunk #1 FAILED at 80.
Hunk #2 FAILED at 103.
...
etc.

I would like to ask you for what revision of grub2 this patches where done?
Do I have to checkout any specific branch of grub2?

Thank you in advance.

2009/3/23 phcoder <[email protected]>:

Quoted 7 lines

Hello. Here is an initial version of patch for booting multiboot kernels
on
i386-efi. No Changelog yet because it's not for inclusion yet. --

Quoted 9 lines

Regards
Vladimir 'phcoder' Serbinenko

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

Quoted 4 lines

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

--

Quoted 9 lines

Regards
Vladimir 'phcoder' Serbinenko

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

Quoted 4 lines

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

--

Regards
Vladimir 'phcoder' Serbinenko

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

#7 lore raw

Hello. Unfortunately my laptop broke down. I have a copy of all my data but no system suitable for developement. So I'll take a break (about a week probably) from grub2 developement.
BTW I have also some initial work on i386/linux and i386/efi/linux unification.

Quoted 137 lines · uzer cheg

Ok. I see.

So I will wait for rediffed patches and number of revision.

Thank you in advance.

Quoted 1 line · phcoder

Hello. I have to write rights to svn. And even if I had I would never

commit

Quoted 4 lines

a code in such stage (not reviewed, tested only on qemu, still in developement)
However I'll rediff the code against HEAD when I'll have time

Quoted 15 lines
Quoted 14 lines · uzer cheg

Dear Vladimir,
I tried rev 2030 and 2037.
And I also had few errors on patching stage.

I think it is a good idea to commit your code to head branch. I will wait for it and try it asap.

Thank you.

Quoted 3 lines · phcoder

Try with 2030. Actually it's diffed against 2030+some of my posted and unposted patches. If it still doesn't apply please report I'll update

and

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

rediff it against HEAD.
I'm interested in behaviour of this code on real EFI however doesn't expect
this version to be able to work completely.
x86_64-efi isn't supported by this patch yet
Also if xen uses any bios interrupts it will probably triple fault. On IRC
we discussed a possibility of loading seabios and it's probably

feasible

Quoted 83 lines
Quoted 75 lines
Quoted 64 lines

but
will take more time

Quoted 54 lines · uzer cheg

Vladimir,

First of all I'd like to say thank you for a quick feedback and development.

I tried to apply your patches and test it on my Apple Xserve Intel 32 bit.
I've done following;

# svn co svn://svn.sv.gnu.org/grub/trunk/grub2
# cd ./grub2
# patch -b -p1 < ./uppermem.diff
patching file conf/i386.rmk
patching file lib/i386/uppermem.c
 --- it's Ok
 --- Than
#  patch -b -p1 < ./efiboot.diff
patching file conf/common.rmk
Hunk #1 succeeded at 503 (offset -4 lines).
patching file conf/i386-coreboot.rmk
Hunk #1 succeeded at 99 with fuzz 2 (offset -3 lines).
Hunk #2 succeeded at 200 (offset -10 lines).
patching file conf/i386-efi.rmk
Hunk #1 FAILED at 80.
Hunk #2 FAILED at 103.
...
etc.

I would like to ask you for what revision of grub2 this patches where done?
Do I have to checkout any specific branch of grub2?

Thank you in advance.

2009/3/23 phcoder <[email protected]>:

Quoted 7 lines

Hello. Here is an initial version of patch for booting multiboot kernels
on
i386-efi. No Changelog yet because it's not for inclusion yet. --

Quoted 9 lines

Regards
Vladimir 'phcoder' Serbinenko

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

Quoted 4 lines

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

--

Quoted 9 lines

Regards
Vladimir 'phcoder' Serbinenko

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

Quoted 4 lines

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

--

Quoted 9 lines

Regards
Vladimir 'phcoder' Serbinenko

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

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

#8 lore raw
In reply to phcoder
Quoted 2 lines · phcoder

Hello. Here is an initial version of patch for booting multiboot kernels on i386-efi. No Changelog yet because it's not for inclusion yet.

Very nice!

Would it be hard to split the patch and make it more granular? I see it implements base mmap / lsmmap support on efi, then ports the *BSD loaders and the Multiboot loader too, and the uppermem facility.

conf/i386-efi.rmk grub_install_SOURCES = util/i386/efi/grub-install.in · line 91

Quoted 12 lines

pkglib_MODULES = kernel.mod normal.mod _chain.mod chain.mod appleldr.mod \

conf/i386-efi.rmk +9 -1
 	_linux.mod linux.mod halt.mod reboot.mod pci.mod lspci.mod \
-	datetime.mod date.mod datehook.mod
+	datetime.mod date.mod datehook.mod _multiboot.mod multiboot.mod
+
+# For _multiboot.mod.
+_multiboot_mod_SOURCES = loader/i386/multiboot.c \
+			 loader/i386/multiboot_helper.S \
+                         loader/multiboot_loader.c
+_multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
+_multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+_multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS)

If everybody's fine with it, I'd like to suggest adding stuff to pkglib_MODULES in the same place as its corresponding variables. I've done this already a few times, and I think it makes the build system a bit more maintainable. What do you all think about this?

include/grub/i386/pc/memory.h struct grub_machine_mmap_entry · line 98

Quoted 12 lines
include/grub/i386/pc/memory.h +2 -0
index 08e92a9..e69ff77 100644
@@ -92,6 +92,8 @@ struct grub_machine_mmap_entry
   grub_uint64_t len;
 #define GRUB_MACHINE_MEMORY_AVAILABLE	1
 #define GRUB_MACHINE_MEMORY_RESERVED	2
+#define GRUB_MACHINE_MEMORY_ACPI	3
+#define GRUB_MACHINE_MEMORY_NVS 	4
   grub_uint32_t type;
 } __attribute__((packed));

Do we need specific knowledge of these two on i386-pc ?

include/grub/i386/pc/memory.h

Quoted 4 lines
include/grub/i386/pc/memory.h +0 -0
 /* The minimum and maximum heap size for GRUB itself.  */

#define MIN_HEAP_SIZE 0x100000

include/grub/i386/pc/memory.h +1 -1
-#define MAX_HEAP_SIZE	(16 * 0x100000)
+#define MAX_HEAP_SIZE	(1600 * 0x100000)

Is 1600 MB what we want, or to remove the limit?

include/grub/i386/pc/memory.h

Quoted 13 lines
include/grub/i386/pc/memory.h +13 -0
+  /* Bubble-sort the memory map */
+  while (done)
+    {
+      done = 0;
+      for (i = 0; i < count - 1; i++)
+	if (regions[i].start > regions[i + 1].start)
+	  {
+	    done = 1;
+	    t = regions[i];
+	    regions[i] = regions[i + 1];
+	    regions[i + 1] = t;
+	  }
+    }

Do we need the memory map to be sorted? AFAIK loadees can cope with unsorted maps fine; is there an exception?

include/grub/i386/pc/memory.h

Quoted 3 lines
include/grub/i386/pc/memory.h +3 -0
+#ifdef GRUB_MACHINE_PCBIOS
+  grub_stop_floppy ();
+#endif

grub_stop_floppy() doesn't do any BIOS-specific stuff. Wouldn't __i386__ be more appropiate?

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."
#9 lore raw
Quoted 2 lines · On Saturday 28 March 2009 22:13:06 Robert Millan wrote:

Do we need the memory map to be sorted? AFAIK loadees can cope with unsorted maps fine; is there an exception?

As I wrote in the draft, a boot loader should sort the memory map. An OS image must deal with an unsorted memory map, because the wording is "should", but it is still user-friendly (especially for debugging).

Quoted 6 lines

loader/i386/bsd.c grub_freebsd_boot (void) · line 312

Quoted 3 lines
loader/i386/bsd.c +3 -0
+#ifdef GRUB_MACHINE_PCBIOS
+  grub_stop_floppy ();
+#endif

grub_stop_floppy() doesn't do any BIOS-specific stuff. Wouldn't __i386__ be more appropiate?

This should be moved to an arch-specific finalization function. Honestly, I prefer that this is done by disk drivers automatically when unloading, but some people seem to like giving up unloading modules.

Regards,
Okuji

#10 lore raw
Quoted 7 lines · Yoshinori K. Okuji
Quoted 2 lines · On Saturday 28 March 2009 22:13:06 Robert Millan wrote:

Do we need the memory map to be sorted? AFAIK loadees can cope with unsorted maps fine; is there an exception?

As I wrote in the draft, a boot loader should sort the memory map. An OS image must deal with an unsorted memory map, because the wording is "should", but it is still user-friendly (especially for debugging).

You mean the multiboot 2 draft? Since this change is backward-compatible, is there any reason we want this in multiboot 2 but not in multiboot 1?

I don't like that the two diverge so much, it makes the implementation so much harder to maintain. Right now the multiboot 2 loader is a complete bitrot.

Can we merge this and similar backward-compatible changes into multiboot 1?

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."
#11 lore raw
Quoted 11 lines · On Wednesday 01 April 2009 21:57:55 Robert Millan wrote:
Quoted 7 lines · Yoshinori K. Okuji
Quoted 2 lines · On Saturday 28 March 2009 22:13:06 Robert Millan wrote:

Do we need the memory map to be sorted? AFAIK loadees can cope with unsorted maps fine; is there an exception?

As I wrote in the draft, a boot loader should sort the memory map. An OS image must deal with an unsorted memory map, because the wording is "should", but it is still user-friendly (especially for debugging).

You mean the multiboot 2 draft? Since this change is backward-compatible, is there any reason we want this in multiboot 2 but not in multiboot 1?

No.

Quoted 5 lines

I don't like that the two diverge so much, it makes the implementation so much harder to maintain. Right now the multiboot 2 loader is a complete bitrot.

Can we merge this and similar backward-compatible changes into multiboot 1?

I agree.

Regards,
Okuji

author
#12 lore raw
In reply to Robert Millan
Quoted 3 lines · Robert Millan

Would it be hard to split the patch and make it more granular? I see it implements base mmap / lsmmap support on efi, then ports the *BSD loaders and the Multiboot loader too, and the uppermem facility.

The only reason why it's not splitted is that it's totally "preview". When it'll be more ready I'll split it

Quoted 4 lines

If everybody's fine with it, I'd like to suggest adding stuff to pkglib_MODULES in the same place as its corresponding variables. I've done this already a few times, and I think it makes the build system a bit more maintainable. What do you all think about this?

I also agree with this but I temporarily kept this in architecture-specific file because of some minor problems with multiboot2. I'll fix this too

Quoted 16 lines

include/grub/i386/pc/memory.h struct grub_machine_mmap_entry · line 98

Quoted 13 lines
include/grub/i386/pc/memory.h +2 -0
index 08e92a9..e69ff77 100644
@@ -92,6 +92,8 @@ struct grub_machine_mmap_entry
   grub_uint64_t len;
 #define GRUB_MACHINE_MEMORY_AVAILABLE	1
 #define GRUB_MACHINE_MEMORY_RESERVED	2
+#define GRUB_MACHINE_MEMORY_ACPI	3
+#define GRUB_MACHINE_MEMORY_NVS 	4
   grub_uint32_t type;
 } __attribute__((packed));

Do we need specific knowledge of these two on i386-pc ?

This one is because some loaders just copy e820 map types and I don't want to modify what OS gets on i386-pc

Quoted 7 lines

include/grub/i386/pc/memory.h

Quoted 4 lines
include/grub/i386/pc/memory.h +0 -0
 /* The minimum and maximum heap size for GRUB itself.  */

#define MIN_HEAP_SIZE 0x100000

include/grub/i386/pc/memory.h +1 -1
-#define MAX_HEAP_SIZE	(16 * 0x100000)
+#define MAX_HEAP_SIZE	(1600 * 0x100000)

Is 1600 MB what we want, or to remove the limit?

I would suggest to remove the limit altogether

Quoted 8 lines
Quoted 8 lines
include/grub/i386/pc/memory.h +8 -0
+  /* Bubble-sort the memory map */
+  while (done)
+    {
+      done = 0;
+      for (i = 0; i < count - 1; i++)
+	if (regions[i].start > regions[i + 1].start)
+	  {
+	    done = 1;
Quoted 9 lines

include/grub/i386/pc/memory.h

Quoted 5 lines
include/grub/i386/pc/memory.h +5 -0
+	    t = regions[i];
+	    regions[i] = regions[i + 1];
+	    regions[i + 1] = t;
+	  }
+    }

Do we need the memory map to be sorted? AFAIK loadees can cope with unsorted maps fine; is there an exception?

I prefer to sort. Even as just a precaution. Actually even sorted EFI map may break a lot of OS because it usually has more entries (the runtime code isn't guaranteed to be contiguous and if it isn't it results in mmap having a lot of entries) and sometimes the first N kilobytes are defined as unusable (it's the case with qemu-tianocore) which under current definition means that low_memory=0

Quoted 7 lines

include/grub/i386/pc/memory.h

Quoted 3 lines
include/grub/i386/pc/memory.h +3 -0
+#ifdef GRUB_MACHINE_PCBIOS
+  grub_stop_floppy ();
+#endif

grub_stop_floppy() doesn't do any BIOS-specific stuff. Wouldn't __i386__ be more appropiate?

I've already moved it to machine_fini just because my computer died I couldn't send the new patch

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
author
#13 lore raw

For those interested in testing: here is a rediff and some updates. Soon I'll split it into components

Quoted 64 lines · phcoder
Quoted 3 lines · Robert Millan

Would it be hard to split the patch and make it more granular? I see it implements base mmap / lsmmap support on efi, then ports the *BSD loaders and the Multiboot loader too, and the uppermem facility.

The only reason why it's not splitted is that it's totally "preview". When it'll be more ready I'll split it

Quoted 4 lines

If everybody's fine with it, I'd like to suggest adding stuff to pkglib_MODULES in the same place as its corresponding variables. I've done this already a few times, and I think it makes the build system a bit more maintainable. What do you all think about this?

I also agree with this but I temporarily kept this in architecture-specific file because of some minor problems with multiboot2. I'll fix this too

Quoted 16 lines

include/grub/i386/pc/memory.h struct grub_machine_mmap_entry · line 98

Quoted 13 lines
include/grub/i386/pc/memory.h +2 -0
index 08e92a9..e69ff77 100644
@@ -92,6 +92,8 @@ struct grub_machine_mmap_entry
   grub_uint64_t len;
 #define GRUB_MACHINE_MEMORY_AVAILABLE    1
 #define GRUB_MACHINE_MEMORY_RESERVED    2
+#define GRUB_MACHINE_MEMORY_ACPI    3
+#define GRUB_MACHINE_MEMORY_NVS     4
   grub_uint32_t type;
 } __attribute__((packed));

Do we need specific knowledge of these two on i386-pc ?

This one is because some loaders just copy e820 map types and I don't want to modify what OS gets on i386-pc

Quoted 7 lines

include/grub/i386/pc/memory.h

Quoted 4 lines
include/grub/i386/pc/memory.h +0 -0
 /* The minimum and maximum heap size for GRUB itself.  */

#define MIN_HEAP_SIZE 0x100000

include/grub/i386/pc/memory.h +1 -1
-#define MAX_HEAP_SIZE    (16 * 0x100000)
+#define MAX_HEAP_SIZE    (1600 * 0x100000)

Is 1600 MB what we want, or to remove the limit?

I would suggest to remove the limit altogether

Quoted 14 lines

include/grub/i386/pc/memory.h

Quoted 13 lines
include/grub/i386/pc/memory.h +13 -0
+  /* Bubble-sort the memory map */
+  while (done)
+    {
+      done = 0;
+      for (i = 0; i < count - 1; i++)
+    if (regions[i].start > regions[i + 1].start)
+      {
+        done = 1;
+        t = regions[i];
+        regions[i] = regions[i + 1];
+        regions[i + 1] = t;
+      }
+    }
Quoted 3 lines

Do we need the memory map to be sorted? AFAIK loadees can cope with unsorted maps fine; is there an exception?

I prefer to sort. Even as just a precaution. Actually even sorted EFI map may break a lot of OS because it usually has more entries (the runtime code isn't guaranteed to be contiguous and if it isn't it results in mmap having a lot of entries) and sometimes the first N kilobytes are defined as unusable (it's the case with qemu-tianocore) which under current definition means that low_memory=0

Quoted 7 lines

include/grub/i386/pc/memory.h

Quoted 3 lines
include/grub/i386/pc/memory.h +3 -0
+#ifdef GRUB_MACHINE_PCBIOS
+  grub_stop_floppy ();
+#endif

grub_stop_floppy() doesn't do any BIOS-specific stuff. Wouldn't __i386__ be more appropiate?

I've already moved it to machine_fini just because my computer died I couldn't send the new patch

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
author
#14 lore raw

File was empty. Sorry

Quoted 68 lines · phcoder

For those interested in testing: here is a rediff and some updates. Soon I'll split it into components

Quoted 64 lines · phcoder
Quoted 3 lines · Robert Millan

Would it be hard to split the patch and make it more granular? I see it implements base mmap / lsmmap support on efi, then ports the *BSD loaders and the Multiboot loader too, and the uppermem facility.

The only reason why it's not splitted is that it's totally "preview". When it'll be more ready I'll split it

Quoted 4 lines

If everybody's fine with it, I'd like to suggest adding stuff to pkglib_MODULES in the same place as its corresponding variables. I've done this already a few times, and I think it makes the build system a bit more maintainable. What do you all think about this?

I also agree with this but I temporarily kept this in architecture-specific file because of some minor problems with multiboot2. I'll fix this too

Quoted 16 lines

include/grub/i386/pc/memory.h struct grub_machine_mmap_entry · line 98

Quoted 13 lines
include/grub/i386/pc/memory.h +2 -0
index 08e92a9..e69ff77 100644
@@ -92,6 +92,8 @@ struct grub_machine_mmap_entry
   grub_uint64_t len;
 #define GRUB_MACHINE_MEMORY_AVAILABLE    1
 #define GRUB_MACHINE_MEMORY_RESERVED    2
+#define GRUB_MACHINE_MEMORY_ACPI    3
+#define GRUB_MACHINE_MEMORY_NVS     4
   grub_uint32_t type;
 } __attribute__((packed));

Do we need specific knowledge of these two on i386-pc ?

This one is because some loaders just copy e820 map types and I don't want to modify what OS gets on i386-pc

Quoted 7 lines

include/grub/i386/pc/memory.h

Quoted 4 lines
include/grub/i386/pc/memory.h +0 -0
 /* The minimum and maximum heap size for GRUB itself.  */

#define MIN_HEAP_SIZE 0x100000

include/grub/i386/pc/memory.h +1 -1
-#define MAX_HEAP_SIZE    (16 * 0x100000)
+#define MAX_HEAP_SIZE    (1600 * 0x100000)

Is 1600 MB what we want, or to remove the limit?

I would suggest to remove the limit altogether

Quoted 14 lines

include/grub/i386/pc/memory.h

Quoted 13 lines
include/grub/i386/pc/memory.h +13 -0
+  /* Bubble-sort the memory map */
+  while (done)
+    {
+      done = 0;
+      for (i = 0; i < count - 1; i++)
+    if (regions[i].start > regions[i + 1].start)
+      {
+        done = 1;
+        t = regions[i];
+        regions[i] = regions[i + 1];
+        regions[i + 1] = t;
+      }
+    }
Quoted 3 lines

Do we need the memory map to be sorted? AFAIK loadees can cope with unsorted maps fine; is there an exception?

I prefer to sort. Even as just a precaution. Actually even sorted EFI map may break a lot of OS because it usually has more entries (the runtime code isn't guaranteed to be contiguous and if it isn't it results in mmap having a lot of entries) and sometimes the first N kilobytes are defined as unusable (it's the case with qemu-tianocore) which under current definition means that low_memory=0

Quoted 7 lines

include/grub/i386/pc/memory.h

Quoted 3 lines
include/grub/i386/pc/memory.h +3 -0
+#ifdef GRUB_MACHINE_PCBIOS
+  grub_stop_floppy ();
+#endif

grub_stop_floppy() doesn't do any BIOS-specific stuff. Wouldn't __i386__ be more appropiate?

I've already moved it to machine_fini just because my computer died I couldn't send the new patch

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
conf/common.rmk +7 -0
index 43bc683..b812d8b 100644
@@ -503,3 +503,10 @@ gzio_mod_LDFLAGS = $(COMMON_LDFLAGS)
 bufio_mod_SOURCES = io/bufio.c
 bufio_mod_CFLAGS = $(COMMON_CFLAGS)
 bufio_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+pkglib_MODULES += lsmmap.mod
+
+# For lsmmap.mod
+lsmmap_mod_SOURCES = commands/lsmmap.c
+lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
+lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
conf/i386-coreboot.rmk +1 -7
index 53595de..ab4dc4f 100644
@@ -99,8 +99,7 @@ grub_install_SOURCES = util/i386/pc/grub-install.in
 pkglib_MODULES = linux.mod normal.mod multiboot.mod 	\
 	aout.mod play.mod serial.mod ata.mod		\
 	memdisk.mod pci.mod lspci.mod reboot.mod	\
-	halt.mod datetime.mod date.mod datehook.mod	\
-	lsmmap.mod
+	halt.mod datetime.mod date.mod datehook.mod	
 
 # For linux.mod.
 linux_mod_SOURCES = loader/i386/linux.c
@@ -198,10 +197,5 @@ datehook_mod_SOURCES = hook/datehook.c
 datehook_mod_CFLAGS = $(COMMON_CFLAGS)
 datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
-# For lsmmap.mod
-lsmmap_mod_SOURCES = commands/lsmmap.c
-lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
-lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
 include $(srcdir)/conf/i386.mk
 include $(srcdir)/conf/common.mk
conf/i386-efi.rmk +14 -3
index 18a99df..6de450e 100644
@@ -79,7 +79,18 @@ grub_install_SOURCES = util/i386/efi/grub-install.in
 # Modules.
 pkglib_MODULES = kernel.mod normal.mod chain.mod appleldr.mod \
 	linux.mod halt.mod reboot.mod pci.mod lspci.mod \
-	datetime.mod date.mod datehook.mod
+	datetime.mod date.mod datehook.mod multiboot.mod
+
+# For multiboot.mod.
+multiboot_mod_SOURCES = loader/i386/multiboot.c \
+			 loader/i386/multiboot_helper.S \
+                         loader/multiboot2.c \
+                         loader/efi/multiboot2.c \
+                         loader/multiboot_loader.c
+multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
+multiboot_mod_LDFLAGS = $(COMMON_LDFLAGS)
+multiboot_mod_ASFLAGS = $(COMMON_ASFLAGS)
+
 
 # For kernel.mod.
 kernel_mod_EXPORTS = no
@@ -89,14 +100,14 @@ kernel_mod_SOURCES = kern/i386/efi/startup.S kern/main.c kern/device.c \
 	kern/i386/dl.c kern/i386/efi/init.c kern/parser.c kern/partition.c \
 	kern/env.c symlist.c kern/efi/efi.c kern/efi/init.c kern/efi/mm.c \
 	term/efi/console.c disk/efi/efidisk.c \
-	kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \
+	kern/efi/mmap.c kern/time.c kern/list.c kern/handler.c kern/command.c kern/corecmd.c \
 	kern/i386/tsc.c kern/i386/pit.c \
 	kern/generic/rtc_get_time_ms.c \
 	kern/generic/millisleep.c
 kernel_mod_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
 	env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
 	partition.h pc_partition.h rescue.h symbol.h term.h time.h types.h \
-	efi/efi.h efi/time.h efi/disk.h list.h handler.h command.h
+	efi/efi.h efi/time.h efi/disk.h efi/memory.h list.h handler.h command.h
 kernel_mod_CFLAGS = $(COMMON_CFLAGS)
 kernel_mod_ASFLAGS = $(COMMON_ASFLAGS)
 kernel_mod_LDFLAGS = $(COMMON_LDFLAGS)
conf/i386-ieee1275.rmk +2 -6
index a84b5aa..a06f97d 100644
@@ -102,7 +102,7 @@ grub_install_SOURCES = util/ieee1275/grub-install.in
 pkglib_MODULES = normal.mod halt.mod reboot.mod suspend.mod		\
 	multiboot.mod aout.mod serial.mod linux.mod	\
 	nand.mod memdisk.mod pci.mod lspci.mod datetime.mod	\
-	date.mod datehook.mod lsmmap.mod
+	date.mod datehook.mod
 
 #
 # Only arch dependant part of normal.mod will be here. Common part for
@@ -127,6 +127,7 @@ normal_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For multiboot.mod.
 multiboot_mod_SOURCES = loader/ieee1275/multiboot2.c \
+			loader/i386/multiboot.c \
 			loader/i386/multiboot_helper.S \
 			 loader/multiboot2.c \
 			 loader/multiboot_loader.c
@@ -199,10 +200,5 @@ datehook_mod_SOURCES = hook/datehook.c
 datehook_mod_CFLAGS = $(COMMON_CFLAGS)
 datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
-# For lsmmap.mod
-lsmmap_mod_SOURCES = commands/lsmmap.c
-lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
-lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
 include $(srcdir)/conf/i386.mk
 include $(srcdir)/conf/common.mk
conf/i386-pc.rmk +0 -15
index 7fa1975..405048f 100644
@@ -287,16 +287,6 @@ lspci_mod_SOURCES = commands/lspci.c
 lspci_mod_CFLAGS = $(COMMON_CFLAGS)
 lspci_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
-# For aout.mod
-aout_mod_SOURCES = loader/aout.c
-aout_mod_CFLAGS = $(COMMON_CFLAGS)
-aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
-# For bsd.mod
-bsd_mod_SOURCES = loader/i386/bsd.c
-bsd_mod_CFLAGS = $(COMMON_CFLAGS)
-bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
 # For usb.mod
 usb_mod_SOURCES = bus/usb/usb.c bus/usb/usbtrans.c bus/usb/usbhub.c
 usb_mod_CFLAGS = $(COMMON_CFLAGS)
@@ -352,11 +342,6 @@ datehook_mod_SOURCES = hook/datehook.c
 datehook_mod_CFLAGS = $(COMMON_CFLAGS)
 datehook_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
-# For lsmmap.mod
-lsmmap_mod_SOURCES = commands/lsmmap.c
-lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
-lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
 # For ata_pthru.mod.
 ata_pthru_mod_SOURCES = disk/ata_pthru.c
 ata_pthru_mod_CFLAGS = $(COMMON_CFLAGS)
conf/i386.rmk +18 -0
index 93f84ce..ddf7118 100644
@@ -14,3 +14,21 @@ pkglib_MODULES += vga_text.mod
 vga_text_mod_SOURCES = term/i386/pc/vga_text.c term/i386/vga_common.c
 vga_text_mod_CFLAGS = $(COMMON_CFLAGS)
 vga_text_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+pkglib_MODULES += uppermem.mod
+uppermem_mod_SOURCES = lib/i386/uppermem.c
+uppermem_mod_CFLAGS = $(COMMON_CFLAGS)
+uppermem_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+pkglib_MODULES += aout.mod bsd.mod 
+# For aout.mod
+aout_mod_SOURCES = loader/aout.c
+aout_mod_CFLAGS = $(COMMON_CFLAGS)
+aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For bsd.mod
+bsd_mod_SOURCES = loader/i386/bsd.c loader/i386/bsd_helper.S
+bsd_mod_CFLAGS = $(COMMON_CFLAGS) -Werror
+bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
+bsd_mod_ASFLAGS = $(COMMON_ASFLAGS)
+
conf/powerpc-ieee1275.rmk +1 -7
index 9ba2981..bcb2e76 100644
@@ -110,8 +110,7 @@ pkglib_MODULES = halt.mod \
 	reboot.mod \
 	suspend.mod \
         multiboot.mod \
-	memdisk.mod \
-	lsmmap.mod
+	memdisk.mod 
 
 # For linux.mod.
 linux_mod_SOURCES = loader/powerpc/ieee1275/linux.c
@@ -166,10 +165,5 @@ memdisk_mod_SOURCES = disk/memdisk.c
 memdisk_mod_CFLAGS = $(COMMON_CFLAGS)
 memdisk_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
-# For lsmmap.mod
-lsmmap_mod_SOURCES = commands/lsmmap.c
-lsmmap_mod_CFLAGS = $(COMMON_CFLAGS)
-lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS)
-
 include $(srcdir)/conf/common.mk
 
include/grub/efi/efi.h +2 -0
index 8c277c0..137a437 100644
@@ -54,6 +54,8 @@ char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp);
 grub_efi_device_path_t *
 EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);
 int EXPORT_FUNC(grub_efi_exit_boot_services) (grub_efi_uintn_t map_key);
+int EXPORT_FUNC(grub_efi_finish_boot_services) (void);
+
 void EXPORT_FUNC (grub_reboot) (void);
 void EXPORT_FUNC (grub_halt) (void);
 
include/grub/efi/memory.h new file +15 -0
new file mode 100644
index 0000000..9000642
@@ -0,0 +1,15 @@
+#ifndef GRUB_MEMORY_MACHINE_HEADER
+#define GRUB_MEMORY_MACHINE_HEADER	1
+
+#include <grub/err.h>
+#include <grub/types.h>
+
+#define GRUB_MACHINE_MEMORY_AVAILABLE	1
+#define GRUB_MACHINE_MEMORY_RESERVED	2
+#define GRUB_MACHINE_MEMORY_ACPI	3
+#define GRUB_MACHINE_MEMORY_NVS         4
+#define GRUB_MACHINE_MEMORY_CODE         5
+
+grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate) 
+(int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
+#endif /* ! GRUB_MEMORY_MACHINE_HEADER */
include/grub/i386/bsd.h +5 -0
index f50f18e..723dff5 100644
@@ -148,6 +148,8 @@ struct grub_openbsd_bios_mmap
 {
   grub_uint64_t addr;
   grub_uint64_t len;
+#define	OPENBSD_MMAP_AVAILABLE	1
+#define	OPENBSD_MMAP_RESERVED 2
   grub_uint32_t type;
 };
 
@@ -222,4 +224,7 @@ struct grub_netbsd_btinfo_bootdisk
   int partition;
 };
 
+void grub_unix_real_boot (grub_addr_t entry, ...)
+  __attribute__ ((cdecl,noreturn));
+
 #endif /* ! GRUB_BSD_CPU_HEADER */
include/grub/i386/efi/memory.h new file +1 -0
new file mode 100644
index 0000000..c9a61bb
@@ -0,0 +1 @@
+#include <grub/efi/memory.h>
include/grub/i386/loader.h +6 -4
index afd3eb9..685c2e0 100644
@@ -27,12 +27,14 @@ extern grub_uint32_t EXPORT_VAR(grub_linux_prot_size);
 extern char *EXPORT_VAR(grub_linux_tmp_addr);
 extern char *EXPORT_VAR(grub_linux_real_addr);
 extern grub_int32_t EXPORT_VAR(grub_linux_is_bzimage);
-extern grub_addr_t EXPORT_VAR(grub_os_area_addr);
-extern grub_size_t EXPORT_VAR(grub_os_area_size);
 
 grub_err_t EXPORT_FUNC(grub_linux16_boot) (void);
 
-void EXPORT_FUNC(grub_unix_real_boot) (grub_addr_t entry, ...)
-     __attribute__ ((cdecl,noreturn));
+/* It is necessary to export these functions, because normal mode commands
+   reuse rescue mode commands.  */
+void grub_rescue_cmd_linux (int argc, char *argv[]);
+void grub_rescue_cmd_initrd (int argc, char *argv[]);
+
+void EXPORT_FUNC(grub_stop_floppy) (void);
 
 #endif /* ! GRUB_LOADER_CPU_HEADER */
include/grub/i386/multiboot.h +2 -2
index 2dd7ec0..a6da360 100644
@@ -22,10 +22,10 @@
 /* The asm part of the multiboot loader.  */
 void grub_multiboot_real_boot (grub_addr_t entry,
 			       struct grub_multiboot_info *mbi)
-     __attribute__ ((noreturn));
+  __attribute__ ((noreturn,regparm (3)));
 void grub_multiboot2_real_boot (grub_addr_t entry,
 				struct grub_multiboot_info *mbi)
-     __attribute__ ((noreturn));
+     __attribute__ ((noreturn,regparm (3)));
 
 extern grub_addr_t grub_multiboot_payload_orig;
 extern grub_addr_t grub_multiboot_payload_dest;
include/grub/i386/pc/memory.h +2 -0
index 08e92a9..e69ff77 100644
@@ -92,6 +92,8 @@ struct grub_machine_mmap_entry
   grub_uint64_t len;
 #define GRUB_MACHINE_MEMORY_AVAILABLE	1
 #define GRUB_MACHINE_MEMORY_RESERVED	2
+#define GRUB_MACHINE_MEMORY_ACPI	3
+#define GRUB_MACHINE_MEMORY_NVS 	4
   grub_uint32_t type;
 } __attribute__((packed));
 
include/grub/i386/uppermem.h new file +7 -0
new file mode 100644
index 0000000..bceed3e
@@ -0,0 +1,7 @@
+#ifndef GRUB_UPPERMEM_HEADER
+#define GRUB_UPPERMEM_HEADER
+
+grub_err_t
+grub_get_lower_upper_memory (grub_uint64_t *lower, grub_uint64_t *upper);
+
+#endif
include/grub/ieee1275/ieee1275.h +0 -1
index 628d888..448fed5 100644
@@ -169,7 +169,6 @@ grub_err_t EXPORT_FUNC(grub_children_iterate) (char *devpath,
      int (*hook) (struct grub_ieee1275_devalias *alias));
 grub_err_t EXPORT_FUNC(grub_machine_mmap_iterate)
      (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t));
-int EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size);
 
 char *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path);
 char *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path);
include/grub/loader.h +4 -0
index 1ae5fdd..544b2f5 100644
@@ -41,4 +41,8 @@ void EXPORT_FUNC(grub_loader_unset) (void);
    depending on the setting by grub_loader_set.  */
 grub_err_t EXPORT_FUNC(grub_loader_boot) (void);
 
+int EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size);
+
+void EXPORT_FUNC(grub_declaimmap) (grub_addr_t addr, grub_size_t size);
+
 #endif /* ! GRUB_LOADER_HEADER */
include/grub/multiboot2.h +0 -6
index bfbffcc..1e6701e 100644
@@ -39,12 +39,6 @@ void
 grub_mb2_arch_unload (struct multiboot_tag_header *tags);
 
 grub_err_t
-grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, grub_addr_t *addr);
-
-grub_err_t 
-grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, grub_addr_t *addr);
-
-grub_err_t
 grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr);
 
 grub_err_t
include/grub/types.h +10 -0
index 8d51b66..faf2257 100644
@@ -100,6 +100,16 @@ typedef grub_int32_t	grub_ssize_t;
 # define LONG_MAX 2147483647UL
 #endif
 
+#if GRUB_CPU_SIZEOF_VOID_P == 4
+#define UINT_TO_PTR(x) ((void*)(grub_uint32_t)(x))
+#define PTR_TO_UINT64(x) ((grub_uint64_t)(grub_uint32_t)(x))
+#define PTR_TO_UINT32(x) ((grub_uint32_t)(x))
+#else
+#define UINT_TO_PTR(x) ((void*)(grub_uint64_t)(x))
+#define PTR_TO_UINT64(x) ((grub_uint64_t)(x))
+#define PTR_TO_UINT32(x) ((grub_uint32_t)(grub_uint64_t)(x))
+#endif
+
 /* The type for representing a file offset.  */
 typedef grub_uint64_t	grub_off_t;
 
include/grub/x86_64/efi/memory.h new file +1 -0
new file mode 100644
index 0000000..c9a61bb
@@ -0,0 +1 @@
+#include <grub/efi/memory.h>
kern/efi/efi.c +22 -0
index 9c9a400..754f82c 100644
@@ -187,6 +187,28 @@ grub_efi_exit_boot_services (grub_efi_uintn_t map_key)
   return status == GRUB_EFI_SUCCESS;
 }
 
+int
+grub_efi_finish_boot_services (void)
+{
+  grub_efi_uintn_t mmap_size = 0;
+  grub_efi_uintn_t map_key;
+  grub_efi_uintn_t desc_size;
+  grub_efi_uint32_t desc_version;
+  void *mmap_buf;
+
+  if (grub_efi_get_memory_map (&mmap_size, mmap_buf, &map_key,
+			       &desc_size, &desc_version) < 0)
+    return 0;
+
+  mmap_buf = grub_malloc (mmap_size);
+  
+  if (grub_efi_get_memory_map (&mmap_size, mmap_buf, &map_key,
+			       &desc_size, &desc_version) <= 0)
+    return 0;
+
+  return  grub_efi_exit_boot_services (map_key);
+}
+
 grub_uint32_t
 grub_get_rtc (void)
 {
kern/efi/mm.c +1 -1
index 35b12ab..4635776 100644
@@ -47,7 +47,7 @@ static struct allocated_page *allocated_pages = 0;
 
 /* The minimum and maximum heap size for GRUB itself.  */
 #define MIN_HEAP_SIZE	0x100000
-#define MAX_HEAP_SIZE	(16 * 0x100000)
+#define MAX_HEAP_SIZE	(1600 * 0x100000)
 
 
 /* Allocate pages. Return the pointer to the first of allocated pages.  */
kern/efi/mmap.c new file +177 -0

177 lines not on this page · raw message

kern/i386/coreboot/init.c +15 -0
index 1348488..9c1aee0 100644
@@ -155,3 +155,18 @@ grub_arch_modules_addr (void)
 {
   return ALIGN_UP((grub_addr_t) _end, GRUB_MOD_ALIGN);
 }
+
+int
+grub_claimmap (grub_addr_t addr, grub_size_t size)
+{
+  if ((addr < grub_os_area_addr)
+      || (addr + size > grub_os_area_addr + grub_os_area_size))
+    return -1;
+  return 0;
+}
+
+void
+grub_declaimmap (grub_addr_t addr __attribute__ ((unused)), 
+		 grub_size_t size  __attribute__ ((unused)))
+{
+}
kern/i386/loader.S +0 -23
index bbd2187..d9b37bf 100644
@@ -117,26 +117,3 @@ bzimage:
 linux_setup_seg:
 	.word	0
 	.code32
-
-/*
- * Use cdecl calling convention for *BSD kernels.
- */
-
-FUNCTION(grub_unix_real_boot)
-
-        call    EXT_C(grub_dl_unload_all)
-
-	/* Interrupts should be disabled.  */
-        cli
-
-	/* Discard `grub_unix_real_boot' return address.  */
-        popl    %eax
-
-        /* Fetch `entry' address ...  */
-        popl	%eax
-
-        /*
-         * ... and put our return address in its place. The kernel will
-         * ignore it, but it expects %esp to point to it.
-         */
-        call	*%eax
kern/i386/pc/init.c +17 -2
index 6191412..17d5343 100644
@@ -43,8 +43,8 @@ struct mem_region
 static struct mem_region mem_regions[MAX_REGIONS];
 static int num_regions;
 
-grub_addr_t grub_os_area_addr;
-grub_size_t grub_os_area_size;
+static grub_addr_t grub_os_area_addr;
+static grub_size_t grub_os_area_size;
 grub_size_t grub_lower_mem, grub_upper_mem;
 
 void 
@@ -233,3 +233,18 @@ grub_arch_modules_addr (void)
   return GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR
     + (grub_kernel_image_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
 }
+
+int
+grub_claimmap (grub_addr_t addr, grub_size_t size)
+{
+  if ((addr < grub_os_area_addr)
+      || (addr + size > grub_os_area_addr + grub_os_area_size))
+    return -1;
+  return 0;
+}
+
+void
+grub_declaimmap (grub_addr_t addr __attribute__ ((unused)), 
+		 grub_size_t size  __attribute__ ((unused)))
+{
+}
kern/ieee1275/openfw.c +7 -0
index e88f3b3..27f8293 100644
@@ -194,6 +194,13 @@ grub_claimmap (grub_addr_t addr, grub_size_t size)
   return 0;
 }
 
+/* XXX Could someone with better OFW knowledge that me fill this? */
+void
+grub_declaimmap (grub_addr_t addr __attribute__ ((unused)), 
+		 grub_size_t size  __attribute__ ((unused)))
+{
+}
+
 /* Get the device arguments of the Open Firmware node name `path'.  */
 static char *
 grub_ieee1275_get_devargs (const char *path)
lib/i386/uppermem.c new file +127 -0

127 lines not on this page · raw message

loader/efi/multiboot2.c new file +75 -0

75 lines not on this page · raw message

loader/i386/bsd.c +73 -25

183 lines not on this page · raw message

loader/i386/bsd_helper.S new file +65 -0

65 lines not on this page · raw message

loader/i386/efi/linux.c +106 -165

424 lines not on this page · raw message

loader/i386/linux.c +56 -16

134 lines not on this page · raw message

loader/i386/multiboot.c +37 -7

99 lines not on this page · raw message

loader/i386/pc/linux.c +5 -7
index 8ff97f4..4823ddc 100644
@@ -71,11 +71,10 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
   if (! file)
     goto fail;
 
-  if ((grub_size_t) grub_file_size (file) > grub_os_area_size)
+  if (grub_claimmap (GRUB_LINUX_BZIMAGE_ADDR, grub_file_size (file)) < 0)
     {
-      grub_error (GRUB_ERR_OUT_OF_RANGE, "too big kernel (0x%x > 0x%x)",
-		  (grub_size_t) grub_file_size (file),
-		  grub_os_area_size);
+      grub_error (GRUB_ERR_OUT_OF_RANGE, "too big kernel (0x%x)",
+		  (grub_size_t) grub_file_size (file));
       goto fail;
     }
 
@@ -340,9 +339,6 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
      worse than that of Linux 2.3.xx, so avoid the last 64kb.  */
   addr_max -= 0x10000;
 
-  if (addr_max > grub_os_area_addr + grub_os_area_size)
-    addr_max = grub_os_area_addr + grub_os_area_size;
-
   addr_min = (grub_addr_t) grub_linux_tmp_addr + GRUB_LINUX_CL_END_OFFSET;
 
   file = grub_file_open (argv[0]);
@@ -353,6 +349,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
 
   /* Put the initrd as high as possible, 4KiB aligned.  */
   addr = (addr_max - size) & ~0xFFF;
+  while (addr >= addr_min && grub_claimmap (addr, size) < 0)
+    addr -= 0x1000;
 
   if (addr < addr_min)
     {
loader/i386/pc/multiboot2.c +1 -26
index d5fe8e3..b065fa7 100644
@@ -25,32 +25,6 @@
 #include <grub/mm.h>
 
 grub_err_t
-grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr)
-{
-  Elf32_Addr paddr = phdr->p_paddr;
-
-  if ((paddr < grub_os_area_addr)
-      || (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size))
-    return grub_error(GRUB_ERR_OUT_OF_RANGE,"Address 0x%x is out of range", 
-                      paddr);
-
-  return GRUB_ERR_NONE;
-}
-
-grub_err_t
-grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, UNUSED grub_addr_t *addr)
-{
-  Elf64_Addr paddr = phdr->p_paddr;
-
-  if ((paddr < grub_os_area_addr)
-      || (paddr + phdr->p_memsz > grub_os_area_addr + grub_os_area_size))
-    return grub_error (GRUB_ERR_OUT_OF_RANGE, "Address 0x%x is out of range",
-		       paddr);
-
-  return GRUB_ERR_NONE;
-}
-
-grub_err_t
 grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr)
 {
   grub_addr_t modaddr;
@@ -73,6 +47,7 @@ grub_mb2_arch_module_free (grub_addr_t addr, UNUSED grub_size_t size)
 void
 grub_mb2_arch_boot (grub_addr_t entry, void *tags)
 {
+  grub_stop_floppy ();
   grub_multiboot2_real_boot (entry, tags);
 }
 
loader/ieee1275/multiboot2.c +0 -35
index c253fc9..462135b 100644
@@ -31,41 +31,6 @@
 typedef void (*kernel_entry_t) (unsigned long, void *, int (void *),
                                 unsigned long, unsigned long);
 
-/* Claim the memory occupied by the multiboot kernel.  */
-grub_err_t
-grub_mb2_arch_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr)
-{
-  int rc;
-
-  rc = grub_claimmap (phdr->p_paddr, phdr->p_memsz);
-  if (rc)
-    return grub_error(GRUB_ERR_OUT_OF_MEMORY, "Couldn't claim %x - %x",
-		      phdr->p_paddr, phdr->p_paddr + phdr->p_memsz);
-
-  grub_dprintf ("loader", "Loading segment at 0x%x - 0x%x\n", phdr->p_paddr,
-		phdr->p_paddr + phdr->p_memsz);
-
-  return GRUB_ERR_NONE;
-}
-
-/* Claim the memory occupied by the multiboot kernel.  */
-grub_err_t
-grub_mb2_arch_elf64_hook (Elf64_Phdr *phdr, UNUSED grub_addr_t *addr)
-{
-  int rc;
-
-  rc = grub_claimmap (phdr->p_paddr, phdr->p_memsz);
-  if (rc)
-    return grub_error(GRUB_ERR_OUT_OF_MEMORY, "Couldn't claim 0x%lx - 0x%lx",
-		      phdr->p_paddr, phdr->p_paddr + phdr->p_memsz);
-
-  grub_dprintf ("loader", "Loading segment at 0x%lx - 0x%lx\n",
-		(unsigned long) phdr->p_paddr,
-		(unsigned long) (phdr->p_paddr + phdr->p_memsz));
-
-  return GRUB_ERR_NONE;
-}
-
 grub_err_t
 grub_mb2_arch_module_alloc (grub_size_t size, grub_addr_t *addr)
 {
loader/multiboot2.c +38 -2
index 2fb56bf..a6cee06 100644
@@ -38,6 +38,42 @@ static char *grub_mb2_tags_pos;
 static grub_size_t grub_mb2_tags_len;
 static int grub_mb2_tags_count;
 
+/* Claim the memory occupied by the multiboot kernel.  */
+static grub_err_t
+grub_mb2_elf32_hook (Elf32_Phdr *phdr, UNUSED grub_addr_t *addr)
+{
+  int rc;
+
+  rc = grub_claimmap (phdr->p_paddr, phdr->p_memsz);
+  if (rc)
+    return grub_error(GRUB_ERR_OUT_OF_MEMORY, "Couldn't claim %x - %x",
+		      phdr->p_paddr, phdr->p_paddr + phdr->p_memsz);
+
+  grub_dprintf ("loader", "Loading segment at 0x%x - 0x%x\n", phdr->p_paddr,
+		phdr->p_paddr + phdr->p_memsz);
+
+  return GRUB_ERR_NONE;
+}
+
+/* Claim the memory occupied by the multiboot kernel.  */
+static grub_err_t
+grub_mb2_elf64_hook (Elf64_Phdr *phdr, UNUSED grub_addr_t *addr)
+{
+  int rc;
+
+  rc = grub_claimmap (phdr->p_paddr, phdr->p_memsz);
+  if (rc)
+    return grub_error(GRUB_ERR_OUT_OF_MEMORY, "Couldn't claim 0x%lx - 0x%lx",
+		      phdr->p_paddr, phdr->p_paddr + phdr->p_memsz);
+
+  grub_dprintf ("loader", "Loading segment at 0x%lx - 0x%lx\n",
+		(unsigned long) phdr->p_paddr,
+		(unsigned long) (phdr->p_paddr + phdr->p_memsz));
+
+  return GRUB_ERR_NONE;
+}
+
+
 static void
 grub_mb2_tags_free (void)
 {
@@ -279,13 +315,13 @@ grub_mb2_load_elf (grub_elf_t elf, int argc, char *argv[])
   if (grub_elf_is_elf32 (elf))
     {
       entry = elf->ehdr.ehdr32.e_entry;
-      err = grub_elf32_load (elf, grub_mb2_arch_elf32_hook, &kern_base,
+      err = grub_elf32_load (elf, grub_mb2_elf32_hook, &kern_base,
 			     &kern_size);
     }
   else if (grub_elf_is_elf64 (elf))
     {
       entry = elf->ehdr.ehdr64.e_entry;
-      err = grub_elf64_load (elf, grub_mb2_arch_elf64_hook, &kern_base,
+      err = grub_elf64_load (elf, grub_mb2_elf64_hook, &kern_base,
 			     &kern_size);
     }
   else
loader/multiboot_loader.c +6 -4
index f4a3933..6c30d5a 100644
@@ -137,9 +137,7 @@ grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)),
 
    /* Launch multi boot with header */
 
-   /* XXX Find a better way to identify this. 
-      This is for i386-pc */
-#if defined(GRUB_MACHINE_PCBIOS) || defined(GRUB_MACHINE_LINUXBIOS)
+#if defined(__i386__)
   if (header_multi_ver_found == 1)
     {
       grub_dprintf ("multiboot_loader",
@@ -152,7 +150,9 @@ grub_cmd_multiboot_loader (grub_command_t cmd __attribute__ ((unused)),
     {
       grub_dprintf ("multiboot_loader",
            "Launching multiboot 2 grub_multiboot2() function\n");
+#ifndef GRUB_MACHINE_EFI
       grub_multiboot2 (argc, argv);
+#endif
       module_version_status = 2;
     }
 
@@ -172,7 +172,7 @@ grub_cmd_module_loader (grub_command_t cmd __attribute__ ((unused)),
 			int argc, char *argv[])
 {
 
-#if defined(GRUB_MACHINE_PCBIOS) || defined(GRUB_MACHINE_LINUXBIOS)
+#if defined(__i386__)
   if (module_version_status == 1)
     {
       grub_dprintf("multiboot_loader",
@@ -184,7 +184,9 @@ grub_cmd_module_loader (grub_command_t cmd __attribute__ ((unused)),
     {
       grub_dprintf("multiboot_loader",
           "Launching multiboot 2 grub_module2() function\n");
+#ifndef GRUB_MACHINE_EFI
       grub_module2 (argc, argv);
+#endif
     }
 
   return grub_errno;