diff --git a/kernel/cpu.c b/kernel/cpu.c index 1e461919..930eaf56 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -268,16 +268,11 @@ 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); @@ -285,6 +280,11 @@ static void init_cpu(struct cpu* cpu) { 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; diff --git a/run.sh b/run.sh index 6fc86a45..0161a609 100755 --- a/run.sh +++ b/run.sh @@ -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[@]}" diff --git a/run_tests.sh b/run_tests.sh index adbf2b22..76d652be 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -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 \