Skip to content

Commit

Permalink
Fix real mode transition
Browse files Browse the repository at this point in the history
Going into real mode would crash on the wrmsr that clears the EFER_LME
flag. This happened because paging was still enabled. And before
disabling paging, we must also set the %ds.

Signed-off-by: Johannes Wikner <[email protected]>
  • Loading branch information
sktt committed Aug 29, 2023
1 parent 0fbcdca commit 9903575
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions arch/x86/real_mode.S
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ END_FUNC(_prot_to_real)

.align 16
.Lfrom_long_mode:
/* Use protected mode data selector */
mov $__KERN_DS32, %eax
mov %eax, %ds

/* Disable paging to enter protected mode */
mov %cr0, %eax
and $~(X86_CR0_PG | X86_CR0_WP), %eax
mov %eax, %cr0

/* Disable LME in EFER */
movl $MSR_EFER, %ecx
rdmsr
Expand All @@ -151,15 +160,6 @@ END_FUNC(_prot_to_real)
lgdt rmode_gdt_ptr
lidt rmode_idt_ptr

/* Disable paging to enter protected mode */
mov %cr0, %eax
and $~(X86_CR0_PG | X86_CR0_WP), %eax
mov %eax, %cr0

/* Use protected mode data selector */
mov $__KERN_DS32, %eax
mov %eax, %ds

/* Use real mode accessible stack */
mov rmode_stack, %esp

Expand Down

0 comments on commit 9903575

Please sign in to comment.