summaryrefslogtreecommitdiff
path: root/i386
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2024-02-05 23:22:00 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2024-02-05 23:22:00 +0100
commit429762dca4d313140067d14e1c448ee68d1644d2 (patch)
treeb91e1abc297e58440894855007f80023b8f385ef /i386
parente211bdce3388a3c9e3dafab903dd53374f6d9759 (diff)
apboot: avoid self-modifying code
self-modifying code is generally frowned upon, Intel largely says the support is model-dependent. We can as well just relocate from the C code like we did for the temporary gdt.
Diffstat (limited to 'i386')
-rw-r--r--i386/i386/cpuboot.S18
-rw-r--r--i386/i386at/model_dep.c7
2 files changed, 10 insertions, 15 deletions
diff --git a/i386/i386/cpuboot.S b/i386/i386/cpuboot.S
index b2f9e520..3e4d5420 100644
--- a/i386/i386/cpuboot.S
+++ b/i386/i386/cpuboot.S
@@ -100,7 +100,7 @@ apboot_percpu_med:
apboot_percpu_high:
.byte 0
-.globl apboot, apbootend, gdt_descr_tmp
+.globl apboot, apbootend, gdt_descr_tmp, apboot_jmp_offset
.align 16
.code16
@@ -128,21 +128,11 @@ _apboot:
orl $CR0_SET_FLAGS, %eax
movl %eax, %cr0
- xorl %eax, %eax
- mov %cs, %ax
- shll $4, %eax
- addl $M(0f), %eax
- movl %eax, M(ljmp_offset32)
-
- /* Flush cached instruction queue */
- jmp 1f
-1:
-
- /* ljmpl with relocation */
+ /* ljmpl with relocation from machine_init */
.byte 0x66
.byte 0xea
-ljmp_offset32:
- .long 0xffffffff
+apboot_jmp_offset:
+ .long M(0f)
.word BOOT_CS
0:
diff --git a/i386/i386at/model_dep.c b/i386/i386at/model_dep.c
index e0995c96..173b99f5 100644
--- a/i386/i386at/model_dep.c
+++ b/i386/i386at/model_dep.c
@@ -129,6 +129,9 @@ extern char version[];
/* Realmode temporary GDT */
extern struct pseudo_descriptor gdt_descr_tmp;
+/* Realmode relocated jmp */
+extern uint32_t apboot_jmp_offset;
+
/* If set, reboot the system on ctrl-alt-delete. */
boolean_t rebootflag = FALSE; /* exported to kdintr */
@@ -221,9 +224,11 @@ void machine_init(void)
assert (apboot_addr < 0x100000);
/*
- * Patch the realmode gdt with the correct offset
+ * Patch the realmode gdt with the correct offset and the first jmp to
+ * protected mode with the correct target.
*/
gdt_descr_tmp.linear_base += apboot_addr;
+ apboot_jmp_offset += apboot_addr;
#endif
}