summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
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;