Skip to content

Commit d545e18

Browse files
committed
x86/efi/mixed: Set up 1:1 mapping of lower 4GiB in the stub
In preparation for dropping the dependency on startup_32 entirely in the next patch, add the code that sets up the 1:1 mapping of the lower 4 GiB of system RAM to the mixed mode stub. The reload of CR3 after the long mode switch will be removed in a subsequent patch, when it is no longer needed. Acked-by: Ingo Molnar <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent ff38bbb commit d545e18

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

arch/x86/boot/compressed/efi_mixed.S

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <asm/asm-offsets.h>
1919
#include <asm/msr.h>
2020
#include <asm/page_types.h>
21+
#include <asm/pgtable_types.h>
2122
#include <asm/processor-flags.h>
2223
#include <asm/segment.h>
2324
#include <asm/setup.h>
@@ -52,6 +53,9 @@ SYM_FUNC_START(startup_64_mixed_mode)
5253
mov 0(%rdx), %edi
5354
mov 4(%rdx), %esi
5455

56+
leaq (pte + 5 * PAGE_SIZE)(%rip), %rax
57+
movq %rax, %cr3 // reload after startup_32
58+
5559
/* Switch to the firmware's stack */
5660
movl efi32_boot_sp(%rip), %esp
5761
andl $~7, %esp
@@ -267,11 +271,32 @@ SYM_FUNC_START_LOCAL(efi32_entry)
267271
movl $_end - 1b, BP_init_size(%esi)
268272
subl $startup_32 - 1b, BP_init_size(%esi)
269273

274+
call 1f
275+
1: pop %edi
276+
270277
/* Disable paging */
271278
movl %cr0, %eax
272279
btrl $X86_CR0_PG_BIT, %eax
273280
movl %eax, %cr0
274281

282+
/* Set up 1:1 mapping */
283+
leal (pte - 1b)(%edi), %eax
284+
movl $_PAGE_PRESENT | _PAGE_RW | _PAGE_PSE, %ecx
285+
leal (_PAGE_PRESENT | _PAGE_RW)(%eax), %edx
286+
2: movl %ecx, (%eax)
287+
addl $8, %eax
288+
addl $PMD_SIZE, %ecx
289+
jnc 2b
290+
291+
movl $PAGE_SIZE, %ecx
292+
.irpc l, 0123
293+
movl %edx, \l * 8(%eax)
294+
addl %ecx, %edx
295+
.endr
296+
addl %ecx, %eax
297+
movl %edx, (%eax)
298+
movl %eax, %cr3
299+
275300
jmp startup_32
276301
SYM_FUNC_END(efi32_entry)
277302

@@ -322,3 +347,7 @@ SYM_DATA_LOCAL(efi32_boot_ds, .word 0)
322347
SYM_DATA_LOCAL(efi32_boot_sp, .long 0)
323348
SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0, 0)
324349
SYM_DATA(efi_is64, .byte 1)
350+
351+
.bss
352+
.balign PAGE_SIZE
353+
SYM_DATA_LOCAL(pte, .fill 6 * PAGE_SIZE, 1, 0)

0 commit comments

Comments
 (0)