diff options
| author | cpplover0 <osdev555@yandex.com> | 2026-03-30 18:21:18 +0300 |
|---|---|---|
| committer | cpplover0 <osdev555@yandex.com> | 2026-03-30 18:21:18 +0300 |
| commit | 8844a7888ea94a11939b1c92915162f2e5acd378 (patch) | |
| tree | 1b4ef74fde17d6f8bb6e054f3266e9342b41c836 /kernel/src/arch/x86_64/assembly.hpp | |
| parent | be997311c240f49db247ccce05ecb8ea5d3bfc31 (diff) | |
Diffstat (limited to 'kernel/src/arch/x86_64/assembly.hpp')
| -rw-r--r-- | kernel/src/arch/x86_64/assembly.hpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/kernel/src/arch/x86_64/assembly.hpp b/kernel/src/arch/x86_64/assembly.hpp index e030e84..c1659fd 100644 --- a/kernel/src/arch/x86_64/assembly.hpp +++ b/kernel/src/arch/x86_64/assembly.hpp @@ -1,5 +1,6 @@ #pragma once #include <cstdint> +#include <klibc/string.hpp> namespace assembly { inline static std::uint64_t rdmsr(std::uint32_t msr) { @@ -28,4 +29,23 @@ namespace assembly { __asm__ volatile ("rdtsc" : "=a"(lo), "=d"(hi)); return ((uint64_t)hi << 32) | lo; } + + inline static bool is_qemu() { + uint32_t a,b,c,d; + + cpuid(0x40000000, 0, &a, &b, &c, &d); + + char hypervisorSignature[13]; + ((uint32_t *)hypervisorSignature)[0] = b; + ((uint32_t *)hypervisorSignature)[1] = c; + ((uint32_t *)hypervisorSignature)[2] = d; + hypervisorSignature[12] = '\0'; + + if (klibc::memcmp(hypervisorSignature, (void*)"TCGTCGTCGTCG", 12) == 0 || klibc::memcmp(hypervisorSignature, (void*)"KVMKVMKVM\0\0\0", 12) == 0) { + return true; + } + + return false; + } + };
\ No newline at end of file |
