Index: /trunk/src/VBox/Devices/EFI/Firmware/OvmfPkg/ResetVector/Ia32/PageTables64.asm
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/OvmfPkg/ResetVector/Ia32/PageTables64.asm	(revision 58802)
+++ /trunk/src/VBox/Devices/EFI/Firmware/OvmfPkg/ResetVector/Ia32/PageTables64.asm	(revision 58803)
@@ -45,5 +45,11 @@
 
     ;
+%ifdef VBOX
+    ; For OVMF, build some initial page tables at 0x2000000-0x2006000.
+    ; Required because we had to relocate MEMFD where the page table resides 
+    ; from 0x800000 to not interfere with certain OS X bootloaders.
+%else
     ; For OVMF, build some initial page tables at 0x800000-0x806000.
+%endif
     ;
     ; This range should match with PcdOvmfSecPageTablesBase and
@@ -57,5 +63,9 @@
     xor     eax, eax
 clearPageTablesMemoryLoop:
+%ifdef VBOX
+    mov     dword[ecx * 4 + 0x2000000 - 4], eax
+%else
     mov     dword[ecx * 4 + 0x800000 - 4], eax
+%endif
     loop    clearPageTablesMemoryLoop
 
@@ -63,13 +73,24 @@
     ; Top level Page Directory Pointers (1 * 512GB entry)
     ;
+%ifdef VBOX
+    mov     dword[0x2000000], 0x2001000 + PAGE_PDP_ATTR
+%else
     mov     dword[0x800000], 0x801000 + PAGE_PDP_ATTR
+%endif
 
     ;
     ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
     ;
+%ifdef VBOX
+    mov     dword[0x2001000], 0x2002000 + PAGE_PDP_ATTR
+    mov     dword[0x2001008], 0x2003000 + PAGE_PDP_ATTR
+    mov     dword[0x2001010], 0x2004000 + PAGE_PDP_ATTR
+    mov     dword[0x2001018], 0x2005000 + PAGE_PDP_ATTR
+%else
     mov     dword[0x801000], 0x802000 + PAGE_PDP_ATTR
     mov     dword[0x801008], 0x803000 + PAGE_PDP_ATTR
     mov     dword[0x801010], 0x804000 + PAGE_PDP_ATTR
     mov     dword[0x801018], 0x805000 + PAGE_PDP_ATTR
+%endif
 
     ;
@@ -82,5 +103,9 @@
     shl     eax, 21
     add     eax, PAGE_2M_PDE_ATTR
+%ifdef VBOX
+    mov     [ecx * 8 + 0x2002000 - 8], eax
+%else
     mov     [ecx * 8 + 0x802000 - 8], eax
+%endif
     loop    pageTableEntriesLoop
 
@@ -88,5 +113,9 @@
     ; Set CR3 now that the paging structures are available
     ;
+%ifdef VBOX
+    mov     eax, 0x2000000
+%else
     mov     eax, 0x800000
+%endif
     mov     cr3, eax
 
Index: /trunk/src/VBox/Devices/EFI/Firmware/UefiCpuPkg/ResetVector/Vtf0/Ia32/Flat32ToFlat64.asm
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/UefiCpuPkg/ResetVector/Vtf0/Ia32/Flat32ToFlat64.asm	(revision 58802)
+++ /trunk/src/VBox/Devices/EFI/Firmware/UefiCpuPkg/ResetVector/Vtf0/Ia32/Flat32ToFlat64.asm	(revision 58803)
@@ -14,90 +14,11 @@
 ;------------------------------------------------------------------------------
 
-%ifdef VBOX
- %include "VBox/nasm.mac"
- %include "iprt/x86.mac"
-
- ;;
- ; Macro for filling in page table entries with EAX as base content.
- ;
- ; @param    %1  What to increment EAX with for each iteration.
- ; @param    %2  Start address.
- ; @param    %3  End address (exclusive).
- ; @uses     EAX, EBX, EFLAGS
- ;
- %macro FILL_ENTRIES 3
-     mov     ebx, %2
- %%myloop:
-     mov     [ebx], eax
-     mov     dword [ebx + 4], 0
-     add     eax, %1
-     add     ebx, 8
-     cmp     ebx, %3
-     jb      %%myloop
- %endmacro
-
- ;;
- ; Macro for filling in page table entries with zeros.
- ;
- ; @param    %1 Start address.
- ; @param    %2  End address (exclusive).
- ; @uses     EAX, EBX, EFLAGS
- ;
- %macro ZERO_ENTRIES 2
-     mov     ebx, %1
-     xor     eax, eax
- %%myloop:
-     mov     [ebx], eax
-     mov     dword [ebx + 4], eax
-     add     ebx, 8
-     cmp     ebx, %2
-     jb      %%myloop
- %endmacro
-
- ;;
- ; The address of the page tables.
- %define VBOX_PDPT_ADDR     (0x00800000 - 0x6000)
- %define VBOX_PDPTR_ADDR    (0x00800000 - 0x2000)
- %define VBOX_PML4_ADDR     (0x00800000 - 0x1000)
-
-%endif ; VBOX
-
-
 BITS    32
 
 ;
-%ifndef VBOX
 ; Modified:  EAX
-%else
-; Modified:  EAX, EBX
-%endif
 ;
 Transition32FlatTo64Flat:
 
-%ifndef VBOX
-    mov     eax, ((ADDR_OF_START_OF_RESET_CODE & ~0xfff) - 0x1000)
-%else ; !VBOX
-    ;
-    ; Produce our own page table that does not reside in ROM, since the PGM
-    ; pool code cannot quite cope with write monitoring ROM pages.
-    ;
-
-    ; First, set up page directories with 2MB pages for the first 4GB.
-    mov     eax, ( X86_PDE4M_P | X86_PDE4M_A | X86_PDE4M_PS | X86_PDE4M_PCD | X86_PDE4M_RW | X86_PDE4M_D )
-    FILL_ENTRIES X86_PAGE_2M_SIZE, VBOX_PDPT_ADDR, VBOX_PDPT_ADDR + 0x4000
-
-    ; Second, set up page a directory pointer table with 4 entries pointing to
-    ; the PTPDs we created above and the remainder as zeros.
-    mov     eax, ( X86_PDPE_P | X86_PDPE_RW | X86_PDPE_A | X86_PDPE_PCD ) + VBOX_PDPT_ADDR
-    FILL_ENTRIES X86_PAGE_4K_SIZE, VBOX_PDPTR_ADDR, VBOX_PDPTR_ADDR + 4*8
-    ZERO_ENTRIES VBOX_PDPTR_ADDR + 4*8, VBOX_PDPTR_ADDR + 0x1000
-
-    ; Third, set up a PML4 with the first entry pointing to the previous table.
-    mov     dword [VBOX_PML4_ADDR], ( X86_PML4E_P | X86_PML4E_PCD | X86_PML4E_A | X86_PML4E_RW ) + VBOX_PDPTR_ADDR
-    mov     dword [VBOX_PML4_ADDR + 4], 0
-    ZERO_ENTRIES VBOX_PML4_ADDR + 1*8, VBOX_PML4_ADDR + 0x1000
-
-    mov     eax, VBOX_PML4_ADDR
-%endif
     OneTimeCall SetCr3ForPageTables64
 
Index: /trunk/src/VBox/Devices/EFI/Firmware/vbox-tools_def.txt
===================================================================
--- /trunk/src/VBox/Devices/EFI/Firmware/vbox-tools_def.txt	(revision 58802)
+++ /trunk/src/VBox/Devices/EFI/Firmware/vbox-tools_def.txt	(revision 58803)
@@ -354,4 +354,4 @@
 *_*_*_NASM_PATH                = DEF(NASM_BIN)
 # NASMB uses NASM produce a .bin from a .nasmb NASM source file
-*_*_*_NASMB_FLAGS              = -f bin -D__YASM__ -DASM_FORMAT_BIN
-
+*_*_*_NASMB_FLAGS              = -f bin -D__YASM__ -DASM_FORMAT_BIN -DVBOX
+
