Skip to contentSkip to conversation

Efiemu

PATCH phcoder 2 participants 5 messages Feb 28, 2009 – Mar 20, 2009

lore
Share & tools
lore

phcoder

author
#0 lore raw

Hello here is a new version of efiemu. Now with 64-bit, virtual and clock support. Additionally I added a lot of comments and changelog. Remaining drawbacks:
- No wakeup support
- Can't hide bios
- No way to provide non-volatility for variables
- No reset function
These problems can't be addressed in bios environment (and are trivially fixed with coreboot) I consider this work conceptually complete on bios. Usage cases:
-look how OS works in EFI environments. Debugging. Debugging ACPI
-launch darwin on non-EFI machine without usage of unmaintained buggy kernel patches (I already have xnu loading, it works but I have to fix few things) -future port of coreboot to mac without losing ability to launch Mac OS X
Usage:
First compile grub2 with this patch and efiemu runtime (in archive)
Then on grub prompt
efiemu_loadcore <efiemu runtime>
efiemu_pnvram <variables file>
efiemu_acpi [-x <tables to delete>] <tables to add if any>
efiemu_prepare
linux_efiemu <normal linux>
initrd_efiemu <initrd>
Soon I'll also submit xnu patch which uses efiemu on non-EFI platforms
Programming note:
To keep compact I use defered allocation of all objects

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
i386-pc.rmk +5 -1
Index: conf/i386-pc.rmk
===================================================================
@@ -146,7 +147,11 @@
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
-	grub_emu_init.c
+	grub_emu_init.c efiemu/main.c efiemu/loadcore64.c 		\
+	efiemu/loadcore32.c efiemu/loadcore_common.c efiemu/mm.c	\
+	efiemu/modules/pnvram.c efiemu/i386/loadcore32.c 		\
+	efiemu/i386/loadcore64.c efiemu/symbols.c efiemu/prepare32.c	\
+	efiemu/prepare64.c lib/crc.c 	\
 
 grub_emu_LDFLAGS = $(LIBCURSES) 
 
@@ -172,3 +180,3 @@
 	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 \

- usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod
+ usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod \
+ efiemu.mod efiemu_acpi.mod efiemu_pnvram.mod _linux_efi.mod linux_efi.mod

+# For efiemu.mod.
+efiemu_mod_SOURCES = efiemu/main.c efiemu/i386/loadcore32.c efiemu/i386/loadcore64.c efiemu/i386/pc/cfgtables.c efiemu/mm.c efiemu/loadcore_common.c efiemu/symbols.c efiemu/loadcore32.c efiemu/loadcore64.c efiemu/prepare32.c efiemu/prepare64.c lib/i386/pc/acpi.c +efiemu_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall
+efiemu_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+efiemu_acpi_mod_SOURCES = efiemu/modules/acpi.c
+efiemu_acpi_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall
+efiemu_acpi_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+efiemu_pnvram_mod_SOURCES = efiemu/modules/pnvram.c
+efiemu_pnvram_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall
+efiemu_pnvram_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
# For biosdisk.mod.
biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
biosdisk_mod_CFLAGS = $(COMMON_CFLAGS)
@@ -200,6 +228,16 @@
linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS)

+# For _linux.mod.
+_linux_efi_mod_SOURCES = loader/i386/efi/linux.c +_linux_efi_mod_CFLAGS = $(COMMON_CFLAGS) +_linux_efi_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For linux.mod.
+linux_efi_mod_SOURCES = loader/linux_normal_efiemu.c +linux_efi_mod_CFLAGS = $(COMMON_CFLAGS) +linux_efi_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
#
# Only arch dependant part of normal.mod will be here. Common part for

 # all architecures of normal.mod is at start and should be kept at sync
@@ -380,5 +423,19 @@
 hdparm_mod_CFLAGS = $(COMMON_CFLAGS)
 hdparm_mod_LDFLAGS = $(COMMON_LDFLAGS)

+efiemu32.o: efiemu/runtime/efiemu.c
+ $(CC) -c -m32 -DELF32 -o $@ -Wall -Werror efiemu/runtime/efiemu.c -nostdlib -O2 -Iefiemu/runtime -Iinclude
+efiemu64_c.o: efiemu/runtime/efiemu.c
+ $(CC) -c -m64 -DELF64 -o $@ -Wall -Werror efiemu/runtime/efiemu.c -nostdlib -mcmodel=large -O2 -Iefiemu/runtime -Iinclude
+
+efiemu64_s.o: efiemu/runtime/efiemu.S
+ $(CC) -c -m64 -DELF64 -o $@ -Wall -Werror efiemu/runtime/efiemu.S -nostdlib -mcmodel=large -O2 -Iefiemu/runtime -Iinclude
+
+efiemu64.o: efiemu64_c.o efiemu64_s.o
+ ld -o $@ -r efiemu64_c.o efiemu64_s.o -nostdlib
+
+CLEANFILES += efiemu32.o efiemu64.o efiemu64_c.o efiemu64_S.o +lib_DATA += efiemu32.o efiemu64.o
+
include $(srcdir)/conf/i386.mk
include $(srcdir)/conf/common.mk

i386/pc/acpi.c +59 -0

59 lines not on this page · raw message

Property changes on: lib/i386/pc/acpi.c
___________________________________________________________________
Added: svn:mergeinfo

linux_normal_efiemu.c +64 -0

64 lines not on this page · raw message

i386/efi/linux.c +47 -14

176 lines not on this page · raw message

i386/pc/grub-install.in +2 -2
Index: util/i386/pc/grub-install.in
===================================================================
@@ -211,7 +211,7 @@
 fi
 
 # Copy the GRUB images to the GRUB directory.
-for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img; do
+for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img ${grubdir}/efiemu??.o; do
     if test -f $file && [ "`basename $file`" != menu.lst ]; then
 	rm -f $file || exit 1
     fi
@@ -295,7 +295,7 @@
     $grub_mkimage --output=${grubdir}/core.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
 
     # Now perform the installation.
-    $grub_setup ${setup_verbose} --directory=${grubdir} --device-map=${device_map} \
+    $grub_setup ${setup_verbose} --directory=${grubdir} --prefix=${relative_grubdir} --device-map=${device_map} \
         ${install_device} || exit 1
 else
     $grub_mkimage -d ${pkglibdir} --output=/boot/multiboot.img --prefix=${prefix_drive}${relative_grubdir} $modules || exit 1
grub/autoefi.h +46 -0

46 lines not on this page · raw message

grub/i386/efiemu.h +33 -0
Index: include/grub/i386/efiemu.h
===================================================================
@@ -0,0 +1,33 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_ARCH_EFI_EMU_HEADER
+#define GRUB_ARCH_EFI_EMU_HEADER	1
+
+grub_err_t
+grub_arch_efiemu_relocate_symbols32 (grub_efiemu_segment_t segs, 
+				     struct grub_efiemu_elf_sym *elfsyms,
+				     void *ehdr);
+grub_err_t
+grub_arch_efiemu_relocate_symbols64 (grub_efiemu_segment_t segs, 
+				     struct grub_efiemu_elf_sym *elfsyms,
+				     void *ehdr);
+
+int grub_arch_efiemu_check_header32 (void *ehdr);
+int grub_arch_efiemu_check_header64 (void *ehdr);
+#endif
grub/i386/pc/efiemu.h +24 -0
Index: include/grub/i386/pc/efiemu.h
===================================================================
@@ -0,0 +1,24 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_MACHINE_EFI_EMU_HEADER
+#define GRUB_MACHINE_EFI_EMU_HEADER	1
+
+grub_err_t grub_machine_efiemu_init_tables (void);
+
+#endif
grub/i386/pc/memory.h +2 -0
Index: include/grub/i386/pc/memory.h
===================================================================
@@ -92,6 +92,8 @@
   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));
 
grub/efi/api.h +24 -10
Index: include/grub/efi/api.h
===================================================================
@@ -40,15 +40,15 @@
 #define GRUB_EFI_TPL_NOTIFY		16
 #define GRUB_EFI_TPL_HIGH_LEVEL		31
 
-#define GRUB_EFI_MEMORY_UC	0x0000000000000001
-#define GRUB_EFI_MEMORY_WC	0x0000000000000002
-#define GRUB_EFI_MEMORY_WT	0x0000000000000004
-#define GRUB_EFI_MEMORY_WB	0x0000000000000008
-#define GRUB_EFI_MEMORY_UCE	0x0000000000000010
-#define GRUB_EFI_MEMORY_WP	0x0000000000001000
-#define GRUB_EFI_MEMORY_RP	0x0000000000002000
-#define GRUB_EFI_MEMORY_XP	0x0000000000004000
-#define GRUB_EFI_MEMORY_RUNTIME	0x8000000000000000
+#define GRUB_EFI_MEMORY_UC	0x0000000000000001LL
+#define GRUB_EFI_MEMORY_WC	0x0000000000000002LL
+#define GRUB_EFI_MEMORY_WT	0x0000000000000004LL
+#define GRUB_EFI_MEMORY_WB	0x0000000000000008LL
+#define GRUB_EFI_MEMORY_UCE	0x0000000000000010LL
+#define GRUB_EFI_MEMORY_WP	0x0000000000001000LL
+#define GRUB_EFI_MEMORY_RP	0x0000000000002000LL
+#define GRUB_EFI_MEMORY_XP	0x0000000000004000LL
+#define GRUB_EFI_MEMORY_RUNTIME	0x8000000000000000LL
 
 #define GRUB_EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL	0x00000001
 #define GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL		0x00000002
@@ -599,7 +599,7 @@
   grub_efi_int16_t time_zone;
   grub_efi_uint8_t daylight;
   grub_efi_uint8_t pad2;
-};
+} __attribute__ ((packed));
 typedef struct grub_efi_time grub_efi_time_t;
 
 struct grub_efi_time_capabilities
@@ -916,6 +916,20 @@
 };
 typedef struct grub_efi_configuration_table grub_efi_configuration_table_t;
 
+#define GRUB_EFIEMU_SYSTEM_TABLE_SIGNATURE 0x5453595320494249LL
+#define GRUB_EFIEMU_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552LL
+
+#define GRUB_EFI_ACPI_20_TABLE_GUID \
+  {0x8868e871,0xe4f1,0x11d3,{0xbc,0x22,0x0,0x80,0xc7,0x3c,0x88,0x81}}
+#define GRUB_EFI_ACPI_TABLE_GUID \
+  {0xeb9d2d30,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
+#define GRUB_EFI_SAL_SYSTEM_TABLE_GUID \
+  {0xeb9d2d32,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
+#define GRUB_EFI_SMBIOS_TABLE_GUID \
+  {0xeb9d2d31,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
+#define GRUB_EFI_MPS_TABLE_GUID \
+  {0xeb9d2d2f,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
+
 struct grub_efi_simple_input_interface
 {
   grub_efi_status_t
grub/types.h +10 -0
Index: include/grub/types.h
===================================================================
@@ -100,6 +100,16 @@
 # 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;
 
grub/acpi.h +64 -0

64 lines not on this page · raw message

Property changes on: include/grub/acpi.h
___________________________________________________________________
Added: svn:mergeinfo

grub/efiemu/efiemu.h +259 -0

259 lines not on this page · raw message

Property changes on: include/grub/efiemu/efiemu.h
___________________________________________________________________
Added: svn:mergeinfo

grub/efiemu/runtime.h +37 -0
Index: include/grub/efiemu/runtime.h
===================================================================
@@ -0,0 +1,37 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_EFI_EMU_RUNTIME_HEADER
+#define GRUB_EFI_EMU_RUNTIME_HEADER	1
+
+struct grub_efiemu_ptv_rel
+{
+  grub_uint64_t addr;
+  grub_efi_memory_type_t plustype;
+  grub_efi_memory_type_t minustype;
+  grub_uint32_t size;
+} __attribute__ ((packed));
+
+struct efi_variable
+{
+  grub_efi_guid_t guid;
+  grub_uint32_t namelen;
+  grub_uint32_t size;
+  grub_efi_uint32_t attributes;
+} __attribute__ ((packed));
+#endif /* ! GRUB_EFI_EMU_RUNTIME_HEADER */
prepare.c +127 -0

127 lines not on this page · raw message

loadcore_common.c +189 -0

189 lines not on this page · raw message

loadcore64.c +27 -0
Index: efiemu/loadcore64.c
===================================================================
@@ -0,0 +1,27 @@
+/* This file contains definitions so that loadcore.c compiles for 64-bit */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define SUFFIX(x) x ## 64
+#define Elf_Ehdr Elf64_Ehdr
+#define Elf_Shdr Elf64_Shdr
+#define Elf_Sym Elf64_Sym
+#define Elf_Word Elf64_Word
+#define ELF_ST_TYPE ELF64_ST_TYPE
+#define ELF_ST_BIND ELF64_ST_BIND
+#include "loadcore.c"
runtime/efiemu.sh +6 -0
Index: efiemu/runtime/efiemu.sh
===================================================================
@@ -0,0 +1,6 @@
+gcc -c -m32 -DELF32 -o efiemu32.o ./efiemu.c -Wall -Werror -nostdlib -O2 -I. -I../../include
+gcc -c -m64 -DELF64 -o efiemu64_c.o ./efiemu.c -Wall -Werror -mcmodel=large -O2 -I. -I../../include
+gcc -c -m64 -DELF64 -o efiemu64_s.o ./efiemu.S -Wall -Werror -mcmodel=large -O2 -I. -I../../include
+ld -o efiemu64.o -r efiemu64_s.o efiemu64_c.o -nostdlib 
+
+
runtime/efiemu.S +160 -0

160 lines not on this page · raw message

runtime/efiemu.c +623 -0

623 lines not on this page · raw message

runtime/config.h +35 -0
Index: efiemu/runtime/config.h
===================================================================
@@ -0,0 +1,35 @@
+/* This is a pseudo config.h so that types.h compiles nicely */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define GRUB_TYPES_CPU_HEADER	1
+
+#ifdef ELF32
+# define SIZEOF_VOID_P	4
+# define SIZEOF_LONG	4
+# define GRUB_TARGET_SIZEOF_VOID_P	4
+# define GRUB_TARGET_SIZEOF_LONG	4
+# define EFI_FUNC(x) x
+#else
+# define SIZEOF_VOID_P	8
+# define SIZEOF_LONG	8
+# define GRUB_TARGET_SIZEOF_VOID_P	8
+# define GRUB_TARGET_SIZEOF_LONG	8
+# define EFI_FUNC(x) x ## _real
+#endif
+
prepare32.c +23 -0
Index: efiemu/prepare32.c
===================================================================
@@ -0,0 +1,23 @@
+/* This file contains definitions so that prepare.c compiles for 32-bit */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2009  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define SUFFIX(x) x ## 32
+#define TYPE(x) x ## 32_t
+
+#include "prepare.c"
main.c +276 -0

276 lines not on this page · raw message

Property changes on: efiemu/main.c
___________________________________________________________________
Added: svn:mergeinfo

modules/pnvram.c +355 -0

355 lines not on this page · raw message

Property changes on: efiemu/modules/pnvram.c
___________________________________________________________________
Added: svn:mergeinfo

modules/acpi.c +592 -0

310 lines not on this page · raw message

i386/pc/cfgtables.c +46 -0

46 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Property changes on: efiemu/i386/pc/cfgtables.c
___________________________________________________________________
Added: svn:mergeinfo

i386/loadcore64.c +121 -0

121 lines not on this page · raw message

i386/loadcore32.c +113 -0

113 lines not on this page · raw message

prepare64.c +23 -0
Index: efiemu/prepare64.c
===================================================================

Lines of this file are not shown. View the raw message.

loadcore.c +370 -0

370 lines not on this page · raw message

symbols.c +187 -0

187 lines not on this page · raw message

mm.c +585 -0

585 lines not on this page · raw message

loadcore32.c +27 -0
Index: efiemu/loadcore32.c
===================================================================

Lines of this file are not shown. View the raw message.

ChangeLog +47 -0

47 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

author
#1 lore raw

Naming problem fixed

Quoted 2 lines

Usage:
First compile grub2 with this patch and efiemu runtime (in archive)

Now it's compiled by normal make

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
i386-pc.rmk +2 -1
Index: conf/i386-pc.rmk
===================================================================
@@ -146,7 +147,8 @@
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
-	grub_emu_init.c
+	grub_emu_init.c efiemu/main.c efiemu/loadcore.c efiemu/mm.c	\
+	efiemu/modules/pnvram.c efiemu/i386/loadcore.c 	lib/crc.c 	\
 
 grub_emu_LDFLAGS = $(LIBCURSES) 
 
@@ -172,3 +177,3 @@
 	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 \
	usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod

+ efiemu.mod efiemu_acpi.mod efiemu_pnvram.mod _linux_efi.mod linux_efi.mod

+# For efiemu.mod.
+efiemu_mod_SOURCES = efiemu/main.c efiemu/i386/loadcore.c efiemu/i386/pc/cfgtables.c efiemu/mm.c efiemu/loadcore.c +efiemu_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall
+efiemu_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+efiemu_acpi_mod_SOURCES = efiemu/modules/acpi.c efiemu/modules/i386/pc/acpi.c +efiemu_acpi_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall
+efiemu_acpi_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+efiemu_pnvram_mod_SOURCES = efiemu/modules/pnvram.c
+efiemu_pnvram_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall
+efiemu_pnvram_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
# For biosdisk.mod.
biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
biosdisk_mod_CFLAGS = $(COMMON_CFLAGS)
@@ -200,6 +225,16 @@
linux_mod_CFLAGS = $(COMMON_CFLAGS)
linux_mod_LDFLAGS = $(COMMON_LDFLAGS)

+# For _linux_efi.mod.
+_linux_efi_mod_SOURCES = loader/i386/efi/linux.c +_linux_efi_mod_CFLAGS = $(COMMON_CFLAGS) +_linux_efi_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For linux_efi.mod.
+linux_efi_mod_SOURCES = loader/linux_normal_efiemu.c +linux_efi_mod_CFLAGS = $(COMMON_CFLAGS) +linux_efi_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
#
# Only arch dependant part of normal.mod will be here. Common part for

 # all architecures of normal.mod is at start and should be kept at sync
Index: kern/i386/pc/init.c
===================================================================
--- kern/i386/pc/init.c	(revision 1998)
+++ kern/i386/pc/init.c	(working copy)
@@ -149,9 +149,9 @@
 #endif

/* Add the lower memory into free memory. */
- if (grub_lower_mem >= GRUB_MEMORY_MACHINE_RESERVED_END)
+ /* if (grub_lower_mem >= GRUB_MEMORY_MACHINE_RESERVED_END) add_mem_region (GRUB_MEMORY_MACHINE_RESERVED_END,
- grub_lower_mem - GRUB_MEMORY_MACHINE_RESERVED_END);
+ grub_lower_mem - GRUB_MEMORY_MACHINE_RESERVED_END);*/

auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t); int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)

main.c +363 -0

363 lines not on this page · raw message

Property changes on: efiemu/main.c
___________________________________________________________________
Added: svn:mergeinfo

modules/pnvram.c +282 -0

282 lines not on this page · raw message

Property changes on: efiemu/modules/pnvram.c
___________________________________________________________________
Added: svn:mergeinfo

modules/i386/pc/acpi.c +35 -0
Index: efiemu/modules/i386/pc/acpi.c
===================================================================
@@ -0,0 +1,35 @@
+#include <grub/normal.h>
+#include <grub/dl.h>
+#include <grub/arg.h>
+#include <grub/file.h>
+#include <grub/disk.h>
+#include <grub/term.h>
+#include <grub/misc.h>
+#include <grub/gzio.h>
+#include <grub/efiemu/efiemu.h>
+#include <grub/efiemu/acpi.h>
+
+struct grub_acpi_rsdp_v10 *
+grub_machine_efiemu_get_rsdp (void)
+{
+  int ebda_len;
+  grub_uint8_t *ptr;
+
+  grub_dprintf ("efiemu", "Looking for RSDP. Scanning EBDA\n");  
+
+  ebda_len = 1024 * (*((grub_uint8_t *)0x40e));
+  for (ptr = (grub_uint8_t *)0x410; ptr < (grub_uint8_t *)(0x410 + ebda_len);
+       ptr += 16)
+    if (!grub_memcmp (ptr, "RSD PTR ", 8) 
+	&& grub_efiemu_acpi_checksum (ptr, 
+				      sizeof (struct grub_acpi_rsdp_v10)) == 0)
+      return (struct grub_acpi_rsdp_v10 *) ptr;
+
+  grub_dprintf ("efiemu", "Looking for RSDP. Scanning BIOS\n");  
+  for (ptr=(grub_uint8_t *)0xe0000;ptr<(grub_uint8_t *)0x100000;ptr+=16)
+    if (!grub_memcmp (ptr, "RSD PTR ", 8)
+	&& grub_efiemu_acpi_checksum (ptr, 
+				      sizeof (struct grub_acpi_rsdp_v10)) == 0)
+      return (struct grub_acpi_rsdp_v10 *) ptr;
+  return 0;
+}
modules/acpi.c +514 -0

514 lines not on this page · raw message

loadcore.c +544 -0

544 lines not on this page · raw message

i386/pc/cfgtables.c +22 -0
Index: efiemu/i386/pc/cfgtables.c
===================================================================
@@ -0,0 +1,22 @@
+#include <grub/file.h>
+#include <grub/err.h>
+#include <grub/efiemu/efiemu.h>
+#include <grub/machine/efiemu.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+
+grub_err_t
+grub_machine_efiemu_init_tables ()
+{
+  grub_uint8_t *ptr;
+  grub_efi_guid_t smbios = GRUB_EFI_SMBIOS_TABLE_GUID;
+  grub_dprintf ("efiemu", "Registering SMBIOS\n");
+  for (ptr=(grub_uint8_t *)0xf0000;ptr<(grub_uint8_t *)0x100000;ptr+=16)
+    if (!grub_memcmp (ptr, "_SM_", 4))
+      break;
+  /* FIXME: checksum ! */
+  if (ptr < (grub_uint8_t *)0x100000)
+    grub_efiemu_register_configuration_table (smbios, 0, 0, ptr);
+
+  return GRUB_ERR_NONE;
+}

Property changes on: efiemu/i386/pc/cfgtables.c
___________________________________________________________________
Added: svn:mergeinfo

i386/loadcore.c +129 -0

129 lines not on this page · raw message

Property changes on: efiemu/i386/loadcore.c
___________________________________________________________________
Added: svn:mergeinfo

mm.c +463 -0

463 lines not on this page · raw message

grub/autoefi.h +22 -0
Index: include/grub/autoefi.h
===================================================================
@@ -0,0 +1,22 @@
+#include <grub/machine/machine.h>
+
+#ifdef GRUB_MACHINE_EFI
+#include <grub/efi/efi.h>
+#define GRUB_EFI(x) grub_efi_ ## x 
+#define SYSTEM_TABLE_SIZEOF GRUB_EFI_SYSTEM_TABLE_SIZEOF
+#define SYSTEM_TABLE_VAR GRUB_EFI_SYSTEM_TABLE_VAR
+#define SYSTEM_TABLE_PTR GRUB_EFI_SYSTEM_TABLE_PTR
+#define SIZEOF_OF_UINTN GRUB_EFI_SIZEOF_OF_UINTN 
+#define SYSTEM_TABLE GRUB_EFI_SYSTEM_TABLE 
+#else
+#include <grub/efiemu/efiemu.h>
+#include <grub/cpu/efiemu.h>
+#define GRUB_EFI(x) grub_efiemu_ ## x 
+#define SYSTEM_TABLE_SIZEOF GRUB_EFIEMU_SYSTEM_TABLE_SIZEOF
+#define SYSTEM_TABLE_VAR GRUB_EFIEMU_SYSTEM_TABLE_VAR
+#define SYSTEM_TABLE_PTR GRUB_EFIEMU_SYSTEM_TABLE_PTR
+#define SIZEOF_OF_UINTN GRUB_EFIEMU_SIZEOF_OF_UINTN 
+#define SYSTEM_TABLE GRUB_EFIEMU_SYSTEM_TABLE 
+#define grub_efi_allocate_pages(x,y) (x)
+#define grub_efi_free_pages(x,y) GRUB_EFI_SUCCESS
+#endif
grub/i386/efiemu.h +15 -0
Index: include/grub/i386/efiemu.h
===================================================================
@@ -0,0 +1,15 @@
+#ifndef GRUB_ARCH_EFI_EMU_HEADER
+#define GRUB_ARCH_EFI_EMU_HEADER	1
+
+typedef enum {GRUB_EFIEMU_NOTLOADED,
+	      GRUB_EFIEMU32, GRUB_EFIEMU64} grub_efiemu_mode_t;
+
+grub_err_t
+grub_arch_efiemu_relocate_symbols (grub_efiemu_segment_t segs, void *ehdr,
+				   grub_efiemu_mode_t mode);
+grub_err_t
+grub_arch_efiemu_check_header (void *ehdr, grub_efiemu_mode_t *mode);
+
+extern grub_efiemu_mode_t grub_efiemu_mode;
+
+#endif
grub/i386/pc/efiemu.h +6 -0
Index: include/grub/i386/pc/efiemu.h
===================================================================
@@ -0,0 +1,6 @@
+#ifndef GRUB_MACHINE_EFI_EMU_HEADER
+#define GRUB_MACHINE_EFI_EMU_HEADER	1
+
+grub_err_t grub_machine_efiemu_init_tables (void);
+
+#endif
grub/efi/api.h +23 -9
Index: include/grub/efi/api.h
===================================================================
@@ -40,15 +40,15 @@
 #define GRUB_EFI_TPL_NOTIFY		16
 #define GRUB_EFI_TPL_HIGH_LEVEL		31
 
-#define GRUB_EFI_MEMORY_UC	0x0000000000000001
-#define GRUB_EFI_MEMORY_WC	0x0000000000000002
-#define GRUB_EFI_MEMORY_WT	0x0000000000000004
-#define GRUB_EFI_MEMORY_WB	0x0000000000000008
-#define GRUB_EFI_MEMORY_UCE	0x0000000000000010
-#define GRUB_EFI_MEMORY_WP	0x0000000000001000
-#define GRUB_EFI_MEMORY_RP	0x0000000000002000
-#define GRUB_EFI_MEMORY_XP	0x0000000000004000
-#define GRUB_EFI_MEMORY_RUNTIME	0x8000000000000000
+#define GRUB_EFI_MEMORY_UC	0x0000000000000001LL
+#define GRUB_EFI_MEMORY_WC	0x0000000000000002LL
+#define GRUB_EFI_MEMORY_WT	0x0000000000000004LL
+#define GRUB_EFI_MEMORY_WB	0x0000000000000008LL
+#define GRUB_EFI_MEMORY_UCE	0x0000000000000010LL
+#define GRUB_EFI_MEMORY_WP	0x0000000000001000LL
+#define GRUB_EFI_MEMORY_RP	0x0000000000002000LL
+#define GRUB_EFI_MEMORY_XP	0x0000000000004000LL
+#define GRUB_EFI_MEMORY_RUNTIME	0x8000000000000000LL
 
 #define GRUB_EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL	0x00000001
 #define GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL		0x00000002
@@ -916,6 +916,20 @@
 };
 typedef struct grub_efi_configuration_table grub_efi_configuration_table_t;
 
+#define GRUB_EFIEMU_SYSTEM_TABLE_SIGNATURE 0x5453595320494249LL
+#define GRUB_EFIEMU_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552LL
+
+#define GRUB_EFI_ACPI_20_TABLE_GUID \
+  {0x8868e871,0xe4f1,0x11d3,{0xbc,0x22,0x0,0x80,0xc7,0x3c,0x88,0x81}}
+#define GRUB_EFI_ACPI_TABLE_GUID \
+  {0xeb9d2d30,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
+#define GRUB_EFI_SAL_SYSTEM_TABLE_GUID \
+  {0xeb9d2d32,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
+#define GRUB_EFI_SMBIOS_TABLE_GUID \
+  {0xeb9d2d31,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
+#define GRUB_EFI_MPS_TABLE_GUID \
+  {0xeb9d2d2f,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d}}
+
 struct grub_efi_simple_input_interface
 {
   grub_efi_status_t
grub/efi/efi.h +6 -0
Index: include/grub/efi/efi.h
===================================================================
@@ -24,6 +24,12 @@
 #include <grub/dl.h>
 #include <grub/efi/api.h>
 
+#define GRUB_EFI_SYSTEM_TABLE_SIZEOF(x) (sizeof(grub_efi_system_table->x))
+#define GRUB_EFI_SYSTEM_TABLE_VAR(x) ((void *)&(grub_efi_system_table->x))
+#define GRUB_EFI_SYSTEM_TABLE_PTR(x) ((void *)(grub_efi_system_table->x))
+#define GRUB_EFI_SIZEOF_OF_UINTN sizeof (grub_efi_uintn_t)
+#define GRUB_EFI_SYSTEM_TABLE(x) (grub_efi_system_table->x)
+
 /* Functions.  */
 void *EXPORT_FUNC(grub_efi_locate_protocol) (grub_efi_guid_t *protocol,
 					     void *registration);
grub/types.h +10 -0
Index: include/grub/types.h
===================================================================
@@ -100,6 +100,16 @@
 # 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;
 
grub/efiemu/efiemu.h +180 -0

180 lines not on this page · raw message

Property changes on: include/grub/efiemu/efiemu.h
___________________________________________________________________
Added: svn:mergeinfo

grub/efiemu/acpi.h +42 -0

42 lines not on this page · raw message

linux_normal_efiemu.c +64 -0

64 lines not on this page · raw message

i386/efi/linux.c +39 -12

155 lines not on this page · raw message

grub_rescue_cmd_linux, "load linux");
grub_rescue_register_command ("initrd",
grub_rescue_cmd_initrd, "load initrd");
+#endif
my_mod = mod;
}

GRUB_MOD_FINI(linux)
{
+#ifndef GRUB_MACHINE_EFI
+ grub_rescue_unregister_command ("linuxefi");
+ grub_rescue_unregister_command ("initrdefi");
+#else
grub_rescue_unregister_command ("linux");
grub_rescue_unregister_command ("initrd");
+#endif
}

#2 lore raw
Quoted 6 lines · phcoder

Naming problem fixed

Quoted 3 lines

Usage:
First compile grub2 with this patch and efiemu runtime (in archive)

Now it's compiled by normal make

Hi,

Thanks a lot for your effort, this could be the next major feature of grub2. The patch itself is quite large, I only skim over a bit. Here are some suggestion.

First, I notice some novel use of macro. For example, use GRUB_EFI to wrap around efi calls, which expands to different prefix in different environment. I'm not a big fan of macro, and this seems a little weird.

Also, perhaps you should just avoid linux_efiemu altogether. The efi linux loader contains some tricks that mostly make sense in apple efi firmware, and it might cause hazard in bios environment. Besides, if it's just for testing purpose, linux is not a very good efi citizen, it doesn't even have a efi loader of its own.

Signature · 1 line
Bean
author
#3 lore raw
Quoted 5 lines · Bean

First, I notice some novel use of macro. For example, use GRUB_EFI to wrap around efi calls, which expands to different prefix in different environment. I'm not a big fan of macro, and this seems a little weird.

It can't be done without at least some macros because it's able to load 64-bit efiemu from 32-bit mode and vice-versa. But GRUB_EFI can be replaced to a set of grub_autoefi_* aliases

Quoted 7 lines

Also, perhaps you should just avoid linux_efiemu altogether. The efi linux loader contains some tricks that mostly make sense in apple efi firmware, and it might cause hazard in bios environment. Besides, if it's just for testing purpose, linux is not a very good efi citizen, it doesn't even have a efi loader of its own.

I agree that for now this part of patch should probably be left out. At least until we merge all i386/*/linux.c to i386/linux.c by using Vesa's memory manager and video functions. However efiemu can help linux to get decent efi support in future.

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

update on patch

Quoted 17 lines · phcoder
Quoted 5 lines · Bean

First, I notice some novel use of macro. For example, use GRUB_EFI to wrap around efi calls, which expands to different prefix in different environment. I'm not a big fan of macro, and this seems a little weird.

It can't be done without at least some macros because it's able to load 64-bit efiemu from 32-bit mode and vice-versa. But GRUB_EFI can be replaced to a set of grub_autoefi_* aliases

Quoted 7 lines

Also, perhaps you should just avoid linux_efiemu altogether. The efi linux loader contains some tricks that mostly make sense in apple efi firmware, and it might cause hazard in bios environment. Besides, if it's just for testing purpose, linux is not a very good efi citizen, it doesn't even have a efi loader of its own.

I agree that for now this part of patch should probably be left out. At least until we merge all i386/*/linux.c to i386/linux.c by using Vesa's memory manager and video functions. However efiemu can help linux to get decent efi support in future.

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
ChangeLog +49 -0
index 12da2c9..e3ac3ac 100644
@@ -1,4 +1,53 @@
 2009-03-15  Vladimir Serbinenko  <[email protected]>
+ 
+	Efiemu
+ 
+	* conf/i386-pc.rmk: new modules efiemu, efiemu_acpi, efiemu_pnvram,
+ 	_linux_efi, linux_efi. 
+ 	new files in grub-emu 
+ 	new targets efiemu32.o and efiemu64.o
+ 	* lib/i386/pc/acpi.c: new file
+ 	* loader/linux_normal_efiemu.c: likewise
+ 	* loader/i386/efi/linux.c: added preliminary efiemu support
+ 	* util/i386/pc/grub-install.in: add efiemu??.o to the list of 
+ 	files to copy
+ 	* include/grub/autoefi.h: new file
+ 	* nclude/grub/i386/efiemu.h: likewise
+ 	* include/grub/i386/pc/efiemu.h: likewise
+ 	* include/grub/acpi.h: likewise
+ 	* include/grub/i386/pc/memory.h: 
+ 	(GRUB_MACHINE_MEMORY_ACPI): new definition
+ 	(GRUB_MACHINE_MEMORY_NVS): likewise
+ 	* include/grub/efi/api.h: add LL suffix when necessary
+ 	new definitions relating to tables
+ 	* include/grub/types.h: new definitions for pointer conversion
+ 	* include/grub/efiemu/efiemu.h: new file
+ 	* include/grub/efiemu/runtime.h: likewise
+ 	* efiemu/prepare.c: likewise
+ 	* efiemu/loadcore_common.c: likewise
+ 	* efiemu/loadcore64.c: likewise
+ 	* efiemu/runtime/efiemu.sh: likewise
+ 	* efiemu/runtime/efiemu.S: likewise
+ 	* efiemu/runtime/efiemu.c: likewise
+ 	* efiemu/runtime/config.h: likewise
+ 	* efiemu/prepare32.c: likewise
+ 	* efiemu/main.c: likewise
+ 	* efiemu/modules/pnvram.c: likewise
+ 	* efiemu/modules/i386: likewise
+ 	* efiemu/modules/i386/pc: likewise
+ 	* efiemu/modules/acpi.c: likewise
+ 	* efiemu/i386/pc/cfgtables.c: likewise
+ 	* efiemu/i386/loadcore64.c: likewise
+ 	* efiemu/i386/loadcore32.c: likewise
+ 	* efiemu/prepare64.c: likewise
+ 	* efiemu/loadcore.c: likewise
+ 	* efiemu/symbols.c: likewise
+ 	* efiemu/mm.c: likewise
+	* efiemu/loadcore32.c: likewise
+ 	* lib/i386/uppermem.c: likewise
+ 	* include/grub/i386/uppermem.h: likewise
+ 	
+2009-03-15  Vladimir Serbinenko  <[email protected]>
 
 	UFS improvements
 
conf/i386-pc.rmk +34 -1
index a2fca47..d5e1fab 100644
@@ -147,6 +147,11 @@ grub_emu_SOURCES = commands/boot.c commands/cat.c commands/cmp.c	\
 	\
 	disk/raid.c disk/raid5_recover.c disk/raid6_recover.c		\
 	disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c		\
+	efiemu/main.c efiemu/loadcore64.c 		\
+	efiemu/loadcore32.c efiemu/loadcore_common.c efiemu/mm.c	\
+	efiemu/modules/pnvram.c efiemu/i386/loadcore32.c 		\
+	efiemu/i386/loadcore64.c efiemu/symbols.c efiemu/prepare32.c	\
+	efiemu/prepare64.c efiemu/uppermem.c lib/crc.c 	\
 	grub_emu_init.c
 
 grub_emu_LDFLAGS = $(LIBCURSES) 
@@ -174,7 +179,21 @@ pkglib_MODULES = biosdisk.mod _chain.mod _linux.mod linux.mod normal.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 \
-	usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod
+	usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod usb_keyboard.mod \
+	efiemu.mod efiemu_acpi.mod efiemu_pnvram.mod
+
+# For efiemu.mod.
+efiemu_mod_SOURCES = efiemu/main.c efiemu/i386/loadcore32.c efiemu/i386/loadcore64.c efiemu/i386/pc/cfgtables.c efiemu/mm.c efiemu/loadcore_common.c efiemu/symbols.c efiemu/loadcore32.c efiemu/loadcore64.c efiemu/prepare32.c efiemu/prepare64.c lib/i386/pc/acpi.c efiemu/uppermem.c
+efiemu_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall
+efiemu_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+efiemu_acpi_mod_SOURCES = efiemu/modules/acpi.c
+efiemu_acpi_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall
+efiemu_acpi_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+efiemu_pnvram_mod_SOURCES = efiemu/modules/pnvram.c 
+efiemu_pnvram_mod_CFLAGS = $(COMMON_CFLAGS) -Werror -Wall
+efiemu_pnvram_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For biosdisk.mod.
 biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
@@ -381,5 +400,19 @@ hdparm_mod_SOURCES = commands/hdparm.c lib/hexdump.c
 hdparm_mod_CFLAGS = $(COMMON_CFLAGS)
 hdparm_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+efiemu32.o: efiemu/runtime/efiemu.c
+	$(CC) -c -m32 -DELF32 -o $@ -Wall -Werror efiemu/runtime/efiemu.c -nostdlib -O2 -Iefiemu/runtime -Iinclude 
+efiemu64_c.o: efiemu/runtime/efiemu.c
+	$(CC) -c -m64 -DELF64 -o $@ -Wall -Werror efiemu/runtime/efiemu.c -nostdlib  -mcmodel=large -O2 -Iefiemu/runtime -Iinclude 
+
+efiemu64_s.o: efiemu/runtime/efiemu.S
+	$(CC) -c -m64 -DELF64 -o $@ -Wall -Werror efiemu/runtime/efiemu.S -nostdlib  -mcmodel=large -O2 -Iefiemu/runtime -Iinclude 
+
+efiemu64.o: efiemu64_c.o efiemu64_s.o
+	ld -o $@ -r efiemu64_c.o efiemu64_s.o -nostdlib 
+
+CLEANFILES += efiemu32.o efiemu64.o efiemu64_c.o efiemu64_s.o
+lib_DATA += efiemu32.o efiemu64.o
+
 include $(srcdir)/conf/i386.mk
 include $(srcdir)/conf/common.mk
conf/i386.rmk +5 -0
index 93f84ce..4e86ed8 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)
include/grub/efi/api.h +13 -10
index a764b37..f359ed3 100644
@@ -40,15 +40,15 @@
 #define GRUB_EFI_TPL_NOTIFY		16
 #define GRUB_EFI_TPL_HIGH_LEVEL		31
 
-#define GRUB_EFI_MEMORY_UC	0x0000000000000001
-#define GRUB_EFI_MEMORY_WC	0x0000000000000002
-#define GRUB_EFI_MEMORY_WT	0x0000000000000004
-#define GRUB_EFI_MEMORY_WB	0x0000000000000008
-#define GRUB_EFI_MEMORY_UCE	0x0000000000000010
-#define GRUB_EFI_MEMORY_WP	0x0000000000001000
-#define GRUB_EFI_MEMORY_RP	0x0000000000002000
-#define GRUB_EFI_MEMORY_XP	0x0000000000004000
-#define GRUB_EFI_MEMORY_RUNTIME	0x8000000000000000
+#define GRUB_EFI_MEMORY_UC	0x0000000000000001LL
+#define GRUB_EFI_MEMORY_WC	0x0000000000000002LL
+#define GRUB_EFI_MEMORY_WT	0x0000000000000004LL
+#define GRUB_EFI_MEMORY_WB	0x0000000000000008LL
+#define GRUB_EFI_MEMORY_UCE	0x0000000000000010LL
+#define GRUB_EFI_MEMORY_WP	0x0000000000001000LL
+#define GRUB_EFI_MEMORY_RP	0x0000000000002000LL
+#define GRUB_EFI_MEMORY_XP	0x0000000000004000LL
+#define GRUB_EFI_MEMORY_RUNTIME	0x8000000000000000LL
 
 #define GRUB_EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL	0x00000001
 #define GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL		0x00000002
@@ -619,7 +619,7 @@ struct grub_efi_time
   grub_efi_int16_t time_zone;
   grub_efi_uint8_t daylight;
   grub_efi_uint8_t pad2;
-};
+} __attribute__ ((packed));
 typedef struct grub_efi_time grub_efi_time_t;
 
 struct grub_efi_time_capabilities
@@ -936,6 +936,9 @@ struct grub_efi_configuration_table
 };
 typedef struct grub_efi_configuration_table grub_efi_configuration_table_t;
 
+#define GRUB_EFIEMU_SYSTEM_TABLE_SIGNATURE 0x5453595320494249LL
+#define GRUB_EFIEMU_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552LL
+
 struct grub_efi_simple_input_interface
 {
   grub_efi_status_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;
 
util/i386/pc/grub-install.in +2 -2
index ff1ed1e..d1d8a40 100644
@@ -211,7 +211,7 @@ if test -n "$tmp"; then
 fi
 
 # Copy the GRUB images to the GRUB directory.
-for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img; do
+for file in ${grubdir}/*.mod ${grubdir}/*.lst ${grubdir}/*.img ${grubdir}/efiemu??.o; do
     if test -f $file && [ "`basename $file`" != menu.lst ]; then
 	rm -f $file || exit 1
     fi
@@ -220,7 +220,7 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
     cp -f $file ${grubdir} || exit 1
 done
 if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
-    for file in ${pkglibdir}/*.img; do
+    for file in ${pkglibdir}/*.img ${grubdir}/efiemu??.o; do
         cp -f $file ${grubdir} || exit 1
     done
 fi