summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-05 01:03:23 +0000
committerIan Moffett <ian@osmora.org>2025-07-05 01:03:23 +0000
commit627c047d1ce71c9882cefac41a0d0b3c9d379c5b (patch)
tree951a98b4421e943e5d2c7f34131cab1796650254 /sys
parent6856d7533b4cec8d35639578b02578f28f3699bc (diff)
kernel/amd64: Add 'feat' field in cpu_info
Keep track of per-cpu features by using a 'feat' field which contains the results of various CPUIDs. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/amd64/amd64/machdep.c16
-rw-r--r--sys/include/arch/amd64/cpu.h5
2 files changed, 21 insertions, 0 deletions
diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c
index 8258f8e..408ac95 100644
--- a/sys/arch/amd64/amd64/machdep.c
+++ b/sys/arch/amd64/amd64/machdep.c
@@ -178,6 +178,19 @@ enable_simd(void)
}
}
+static void
+cpu_check_feat(struct cpu_info *ci)
+{
+ uint32_t unused, ebx;
+
+ /* Extended features */
+ CPUID(0x07, unused, ebx, unused, unused);
+ if (ISSET(ebx, BIT(7)))
+ ci->feat |= CPU_FEAT_SMEP;
+ if (ISSET(ebx, BIT(20)))
+ ci->feat |= CPU_FEAT_SMAP;
+}
+
void
cpu_shootdown_tlb(vaddr_t va)
{
@@ -304,6 +317,7 @@ void
cpu_startup(struct cpu_info *ci)
{
ci->self = ci;
+ ci->feat = 0;
gdt_load();
idt_load();
@@ -313,6 +327,8 @@ cpu_startup(struct cpu_info *ci)
init_tss(ci);
try_mitigate_spectre();
+ cpu_check_feat(ci);
+
enable_simd();
lapic_init();
diff --git a/sys/include/arch/amd64/cpu.h b/sys/include/arch/amd64/cpu.h
index 2d08d6e..fe8fc8a 100644
--- a/sys/include/arch/amd64/cpu.h
+++ b/sys/include/arch/amd64/cpu.h
@@ -38,8 +38,13 @@
#define CPU_IRQ(IRQ_N) (BIT((IRQ_N)) & 0xFF)
+/* Feature bits */
+#define CPU_FEAT_SMAP BIT(0)
+#define CPU_FEAT_SMEP BIT(1)
+
struct cpu_info {
uint32_t apicid;
+ uint32_t feat;
uint8_t has_x2apic : 1;
uint8_t tlb_shootdown : 1;
uint8_t ipl;