Skip to content

Commit

Permalink
boot: simplify head.S
Browse files Browse the repository at this point in the history
Various minor cleanups:
- use 16bit source registers when assigning segment registers to have
  matching register sizes
- don't obfuscate CR0 initialization, make it plain obvious we're
  enabling protected mode
- do the same for CR4 initalization, make it obvious we're setting it
  to PSE|PAE
- drop the unneded CLD, as we've fully assigned RFLAGS already with the
  POPF

Signed-off-by: Mathias Krause <[email protected]>
  • Loading branch information
minipli-oss authored and 82marbag committed Oct 15, 2021
1 parent 84841e2 commit 2b9f827
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions arch/x86/boot/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,30 @@
SECTION(.text.init, "ax", 16)
GLOBAL(_start)
/* Save multiboot bootloader magic */
mov %eax, %edi
mov %ebx, %esi
mov %eax, %edi
mov %ebx, %esi

mov %cs, %ax
mov %ax, %ds

lgdt boot_gdt_ptr

xor %ax, %ax
inc %ax
lmsw %ax
mov $X86_CR0_PE, %eax
mov %eax, %cr0

ljmp $__KERN_CS32, $.Lprot_mode

.Lprot_mode:
mov $__KERN_DS32, %eax
mov %eax, %ds
mov %eax, %es
mov %eax, %gs
mov %eax, %fs
mov %eax, %ss
mov $__KERN_DS32, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %gs
mov %ax, %fs
mov %ax, %ss
mov $_boot_stack_top, %esp
mov %esp, %ebp

mov %cr4, %eax
or $(X86_CR4_PAE | X86_CR4_PSE), %eax
mov $(X86_CR4_PAE | X86_CR4_PSE), %eax
mov %eax, %cr4

mov $l4_pt_entries, %eax
Expand Down Expand Up @@ -100,17 +98,15 @@ END_FUNC(prot_to_real)

.code64
.Llong_mode:
xor %rax, %rax
mov %rax, %ds
mov %rax, %es
mov %rax, %fs
mov %rax, %gs
mov %rax, %ss

push $X86_EFLAGS_MBS
popf
xor %eax, %eax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
mov %ax, %ss

cld
pushq $X86_EFLAGS_MBS
popfq

jmp kernel_start

Expand Down

0 comments on commit 2b9f827

Please sign in to comment.