Skip to content

Commit

Permalink
kernel: enable SMEP and UMIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mosmeh committed Nov 30, 2024
1 parent 51a91fa commit 9a033f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
16 changes: 8 additions & 8 deletions kernel/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,23 @@ static void init_cpu(struct cpu* cpu) {
cr0 |= X86_CR0_MP;
write_cr0(cr0);

uint32_t cr4 = read_cr4();
cr4 |= X86_CR4_OSFXSR | X86_CR4_OSXMMEXCPT;
write_cr4(cr4);
write_cr4(read_cr4() | X86_CR4_OSFXSR | X86_CR4_OSXMMEXCPT);
}

if (cpu_has_feature(cpu, X86_FEATURE_PGE)) {
uint32_t cr4 = read_cr4();
cr4 |= X86_CR4_PGE;
write_cr4(cr4);
}
if (cpu_has_feature(cpu, X86_FEATURE_PGE))
write_cr4(read_cr4() | X86_CR4_PGE);

if (cpu_has_feature(cpu, X86_FEATURE_PAT)) {
uint64_t pat = rdmsr(0x277);
pat &= ~((uint64_t)0x7 << 32); // Clear PAT4
pat |= (uint64_t)1 << 32; // Set write-combining
wrmsr(0x277, pat);
}

if (cpu_has_feature(cpu, X86_FEATURE_SMEP))
write_cr4(read_cr4() | X86_CR4_SMEP);
if (cpu_has_feature(cpu, X86_FEATURE_UMIP))
write_cr4(read_cr4() | X86_CR4_UMIP);
}

static struct cpu bsp;
Expand Down
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ QEMU_BIN="${QEMU_BINARY_PREFIX}qemu-system-i386${QEMU_BINARY_SUFFIX}"
-chardev stdio,mux=on,id=char0 \
-serial chardev:char0 \
-mon char0,mode=readline \
-cpu max \
-m 512M \
-smp "sockets=1,cores=${NUM_CPUS},threads=1" \
"${QEMU_VIRT_TECH_ARGS[@]}"
1 change: 1 addition & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set -e
-append 'panic=poweroff init=/bin/init-test console=ttyS0' \
-d guest_errors \
-no-reboot \
-cpu max \
-serial stdio \
-vga none -display none \
-m 512M \
Expand Down

0 comments on commit 9a033f9

Please sign in to comment.