From a6c4a4d2fc5bcdf861545d8d83654498c7268d7a Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 23 Jul 2021 14:11:28 +0200 Subject: [PATCH] Kernel: Make some of the assembly code position-independent on x86_64 --- Kernel/Arch/x86/x86_64/Boot/ap_setup.S | 6 +++--- Kernel/Arch/x86/x86_64/Processor.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Kernel/Arch/x86/x86_64/Boot/ap_setup.S b/Kernel/Arch/x86/x86_64/Boot/ap_setup.S index 3b2eec0845..d34fa9b9ee 100644 --- a/Kernel/Arch/x86/x86_64/Boot/ap_setup.S +++ b/Kernel/Arch/x86/x86_64/Boot/ap_setup.S @@ -141,7 +141,7 @@ apic_ap_start64: /* push the Processor pointer this CPU is going to use */ movq (ap_cpu_init_processor_info_array - apic_ap_start)(%ebp), %rax - movabsq $(kernel_base), %r8 + leaq kernel_base(%rip), %r8 movq (%r8), %r8 addq %r8, %rax movq 0(%rax, %rsi, 4), %rax @@ -157,9 +157,9 @@ apic_ap_start64: /* We are in identity mapped P0x8000 and the BSP will unload this code once all APs are initialized, so call init_ap but return to our infinite loop */ - movabs $loop, %rax + leaq loop(%rip), %rax pushq %rax - movabs $init_ap, %rax + leaq init_ap(%rip), %rax jmp *(%rax) loop: diff --git a/Kernel/Arch/x86/x86_64/Processor.cpp b/Kernel/Arch/x86/x86_64/Processor.cpp index 298bfde154..2eaf7f4be5 100644 --- a/Kernel/Arch/x86/x86_64/Processor.cpp +++ b/Kernel/Arch/x86/x86_64/Processor.cpp @@ -47,7 +47,7 @@ NAKED void do_assume_context(Thread*, u32) " movq %r12, %rsi \n" // from_thread " pushq %r12 \n" // to_thread (for thread_context_first_enter) " pushq %r12 \n" // from_thread (for thread_context_first_enter) - " movabs $thread_context_first_enter, %r12 \n" // should be same as regs.rip + " leaq thread_context_first_enter(%rip), %r12 \n" // should be same as regs.rip " pushq %r12 \n" " jmp enter_thread_context \n"); // clang-format on @@ -191,7 +191,7 @@ void Processor::switch_context(Thread*& from_thread, Thread*& to_thread) "pushq %%r14 \n" "pushq %%r15 \n" "movq %%rsp, %[from_rsp] \n" - "movabs $1f, %%rbx \n" + "leaq 1f(%%rip), %%rbx \n" "movq %%rbx, %[from_rip] \n" "movq %[to_rsp0], %%rbx \n" "movl %%ebx, %[tss_rsp0l] \n"