From 602004f3fab90a9502d60ef7b0ccae528c20b30f Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Fri, 23 Feb 2024 13:04:24 +0100 Subject: [PATCH] head: don't use self-modifying code to switch to 64b mode 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 --- head.S | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/head.S b/head.S index 8e13197..35db874 100644 --- a/head.S +++ b/head.S @@ -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 @@ -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