Skip to content

Commit

Permalink
head: don't use self-modifying code to switch to 64b mode
Browse files Browse the repository at this point in the history
Far return is used, so segment selector and relocated instruction
pointer are build on the stack, instead of modifying the code.

Signed-off-by: Krystian Hebel <[email protected]>
  • Loading branch information
krystian-hebel committed Apr 10, 2024
1 parent 5a0379f commit 67853db
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions head.S
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ GLOBAL(_entry)
rep stosl

#ifdef __x86_64__
/* Relocate 64bit ljmp offset and build pagetables. */
/* FIXME: self-modifying code can't be self-measuring! */
add %ebp, 1 + .Ljump64(%ebp)

/*
* Pagetables are located in .bss that was just cleared, and we are
* loaded to <4GB memory, so we don't have to bother with writing to
Expand Down Expand Up @@ -182,9 +178,11 @@ GLOBAL(_entry)
or $CR0_PG | CR0_NE | CR0_TS | CR0_MP, %eax
mov %eax, %cr0

/* Now in IA-32e compatibility mode, ljmp to 64b mode */
.Ljump64:
ljmp $CS_SEL64, $1f /* Offset - dynamically relocated. */
/* Now in IA-32e compatibility mode, use lret to jump to 64b mode */
lea 1f(%ebp), %ecx
push $CS_SEL64
push %ecx
lret

.code64

Expand Down

0 comments on commit 67853db

Please sign in to comment.