Skip to content

Commit ff38bbb

Browse files
committed
x86/efi/mixed: Factor out and clean up long mode entry
Entering long mode involves setting the EFER_LME and CR4.PAE bits before enabling paging by setting CR0.PG bit. It also involves disabling interrupts, given that the firmware's 32-bit IDT becomes invalid as soon as the CPU transitions into long mode. Reloading the CR3 register is not necessary at boot time, given that the EFI firmware as well as the kernel's EFI stub use a 1:1 mapping of the 32-bit addressable memory in the system. Break out this code into a separate helper for clarity, and so that it can be reused in a subsequent patch. Acked-by: Ingo Molnar <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent eaed895 commit ff38bbb

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

arch/x86/boot/compressed/efi_mixed.S

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ SYM_FUNC_START_LOCAL(efi_enter32)
170170
movl %edx, %gs
171171
movl %edx, %ss
172172

173-
/* Reload pgtables */
174-
movl %cr3, %eax
175-
movl %eax, %cr3
176-
177173
/* Disable paging */
178174
movl %cr0, %eax
179175
btrl $X86_CR0_PG_BIT, %eax
@@ -199,30 +195,35 @@ SYM_FUNC_START_LOCAL(efi_enter32)
199195
lidtl 16(%ebx)
200196
lgdtl (%ebx)
201197

198+
xorl %eax, %eax
199+
lldt %ax
200+
201+
call efi32_enable_long_mode
202+
203+
pushl $__KERNEL_CS
204+
pushl %ebp
205+
lret
206+
SYM_FUNC_END(efi_enter32)
207+
208+
SYM_FUNC_START_LOCAL(efi32_enable_long_mode)
202209
movl %cr4, %eax
203210
btsl $(X86_CR4_PAE_BIT), %eax
204211
movl %eax, %cr4
205212

206-
movl %cr3, %eax
207-
movl %eax, %cr3
208-
209213
movl $MSR_EFER, %ecx
210214
rdmsr
211215
btsl $_EFER_LME, %eax
212216
wrmsr
213217

214-
xorl %eax, %eax
215-
lldt %ax
216-
217-
pushl $__KERNEL_CS
218-
pushl %ebp
218+
/* Disable interrupts - the firmware's IDT does not work in long mode */
219+
cli
219220

220221
/* Enable paging */
221222
movl %cr0, %eax
222223
btsl $X86_CR0_PG_BIT, %eax
223224
movl %eax, %cr0
224-
lret
225-
SYM_FUNC_END(efi_enter32)
225+
ret
226+
SYM_FUNC_END(efi32_enable_long_mode)
226227

227228
/*
228229
* This is the common EFI stub entry point for mixed mode.

0 commit comments

Comments
 (0)