diff options
author | Ian Moffett <ian@osmora.org> | 2025-09-16 23:18:03 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-09-16 23:19:30 -0400 |
commit | 8ae23738c78f58bea882dba11080d7052453e71d (patch) | |
tree | 93268fc5e4f8ca1025f882795c5badc0a56ec181 /src/sys | |
parent | c5ada50b5e897683c2317591331fa94f3ec1a2b1 (diff) |
kern/amd64: cpu: Make GDT per-cpu to match TSS
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/arch/amd64/boot/boot_chip.c | 4 | ||||
-rw-r--r-- | src/sys/arch/amd64/boot/boot_gdt.c | 5 | ||||
-rw-r--r-- | src/sys/arch/amd64/cpu/cpu_conf.c | 15 | ||||
-rw-r--r-- | src/sys/include/arch/amd64/gdt.h | 4 | ||||
-rw-r--r-- | src/sys/include/arch/amd64/mdcpu.h | 3 |
5 files changed, 22 insertions, 9 deletions
diff --git a/src/sys/arch/amd64/boot/boot_chip.c b/src/sys/arch/amd64/boot/boot_chip.c index 2ff122c..76753d5 100644 --- a/src/sys/arch/amd64/boot/boot_chip.c +++ b/src/sys/arch/amd64/boot/boot_chip.c @@ -61,8 +61,10 @@ static void init_tss(struct pcore *pcore) { struct tss_desc *desc; + struct mdcore *mdcore; - desc = (struct tss_desc *)&g_gdt_data[GDT_TSS_INDEX]; + mdcore = &pcore->md; + desc = (struct tss_desc *)&mdcore->gdt[GDT_TSS_INDEX]; write_tss(pcore, desc); tss_load(); } diff --git a/src/sys/arch/amd64/boot/boot_gdt.c b/src/sys/arch/amd64/boot/boot_gdt.c index 2c1ada6..64b3f2b 100644 --- a/src/sys/arch/amd64/boot/boot_gdt.c +++ b/src/sys/arch/amd64/boot/boot_gdt.c @@ -91,8 +91,3 @@ struct gdt_entry g_gdt_data[GDT_ENTRY_COUNT] = { /* Verify that the GDT is of the correct size */ __static_assert(sizeof(g_gdt_data) == (8 * GDT_ENTRY_COUNT)); - -const struct gdtr g_gdtr = { - .limit = sizeof(g_gdt_data) - 1, - .offset = (uintptr_t)&g_gdt_data[0] -}; diff --git a/src/sys/arch/amd64/cpu/cpu_conf.c b/src/sys/arch/amd64/cpu/cpu_conf.c index 5eb1cbe..e462ef3 100644 --- a/src/sys/arch/amd64/cpu/cpu_conf.c +++ b/src/sys/arch/amd64/cpu/cpu_conf.c @@ -34,6 +34,7 @@ #include <machine/trap.h> #include <machine/lapic.h> #include <machine/gdt.h> +#include <string.h> /* * Initialize interrupt vectors @@ -58,8 +59,20 @@ init_vectors(void) void cpu_conf(struct pcore *pcore) { + struct mdcore *mdcore; + struct gdtr *gdtr; + + /* Copy the template GDT */ + mdcore = &pcore->md; + memcpy(mdcore->gdt, &g_gdt_data, sizeof(g_gdt_data)); + + /* Set up the GDTR */ + gdtr = &mdcore->gdtr; + gdtr->offset = (uintptr_t)&mdcore->gdt[0]; + gdtr->limit = sizeof(g_gdt_data) - 1; + /* We use %GS to store the processor */ - gdt_load(); + gdt_load(&mdcore->gdtr); pcore->self = pcore; wrmsr(IA32_GS_BASE, (uintptr_t)pcore); diff --git a/src/sys/include/arch/amd64/gdt.h b/src/sys/include/arch/amd64/gdt.h index ee52065..0a22b37 100644 --- a/src/sys/include/arch/amd64/gdt.h +++ b/src/sys/include/arch/amd64/gdt.h @@ -87,7 +87,7 @@ extern struct gdt_entry g_gdt_data[GDT_ENTRY_COUNT]; extern const struct gdtr g_gdtr; __always_inline static inline void -gdt_load(void) +gdt_load(struct gdtr *gdtr) { __ASMV("lgdt %0\n" "push %1\n" /* Push code segment selector */ @@ -102,7 +102,7 @@ gdt_load(void) " mov %%ax, %%gs\n" " mov %%ax, %%ss\n" : - : "m" (g_gdtr), "i"(KERNEL_CS), "i"(KERNEL_DS) + : "m" (*gdtr), "i"(KERNEL_CS), "i"(KERNEL_DS) : "rax", "memory" ); } diff --git a/src/sys/include/arch/amd64/mdcpu.h b/src/sys/include/arch/amd64/mdcpu.h index 3fccc42..d72836a 100644 --- a/src/sys/include/arch/amd64/mdcpu.h +++ b/src/sys/include/arch/amd64/mdcpu.h @@ -33,6 +33,7 @@ #include <sys/types.h> #include <sys/cdefs.h> #include <machine/tss.h> +#include <machine/gdt.h> #define md_spinwait() __ASMV("pause") #define md_intoff() __ASMV("cli") @@ -57,6 +58,8 @@ struct mdcore { uint8_t x2apic : 1; struct tss_entry tss; size_t lapic_tmr_freq; + struct gdt_entry gdt[GDT_ENTRY_COUNT]; + struct gdtr gdtr; }; #endif /* !_MACHINE_MDCPU_H_ */ |