From d92078525630fcb3f83352febf3f56811db82f4c Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 22 Mar 2024 12:58:38 +0200 Subject: [PATCH] Kernel: RDRAND on i386 is called twice with 32 bit register --- kernel/kernel/Random.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kernel/kernel/Random.cpp b/kernel/kernel/Random.cpp index 1990635d1b..447019ed3d 100644 --- a/kernel/kernel/Random.cpp +++ b/kernel/kernel/Random.cpp @@ -20,7 +20,19 @@ namespace Kernel if (ecx & CPUID::ECX_RDRND) { - asm volatile("rdrand %0" : "=a"(s_rand_seed)); +#if ARCH(x86_64) + asm volatile("rdrand %0" : "=r"(s_rand_seed)); +#elif ARCH(i386) + uint32_t lo, hi; + asm volatile( + "rdrand %[lo];" + "rdrand %[hi];" + : [lo]"=r"(lo), [hi]"=r"(hi) + ); + s_rand_seed = ((uint64_t)hi << 32) | lo; +#else + #error +#endif dprintln("RNG seeded by RDRAND"); } else