Kernel: Use existing assembly snippets for x86-64 RDSEED & RDRAND calls

This commit is contained in:
konrad 2023-01-08 05:23:54 +01:00 committed by Jelle Raaijmakers
parent cb4cbe3ae8
commit d7d233ab04
Notes: sideshowbarker 2024-07-19 16:57:59 +09:00

View File

@ -29,27 +29,17 @@ KernelRng& KernelRng::the()
UNMAP_AFTER_INIT KernelRng::KernelRng()
{
#if ARCH(X86_64)
bool supports_rdseed = Processor::current().has_feature(CPUFeature::RDSEED);
bool supports_rdrand = Processor::current().has_feature(CPUFeature::RDRAND);
if (supports_rdseed || supports_rdrand) {
dmesgln("KernelRng: Using RDSEED or RDRAND as entropy source");
for (size_t i = 0; i < pool_count * reseed_threshold; ++i) {
u32 value = 0;
if (supports_rdseed) {
asm volatile(
"1:\n"
"rdseed %0\n"
"jnc 1b\n"
: "=r"(value));
} else {
asm volatile(
"1:\n"
"rdrand %0\n"
"jnc 1b\n"
: "=r"(value));
}
if (Processor::current().has_feature(CPUFeature::RDSEED)) {
dmesgln("KernelRng: Using RDSEED as entropy source");
add_random_event(value, i % 32);
for (size_t i = 0; i < pool_count * reseed_threshold; ++i) {
add_random_event(Kernel::rdseed(), i % 32);
}
} else if (Processor::current().has_feature(CPUFeature::RDRAND)) {
dmesgln("KernelRng: Using RDRAND as entropy source");
for (size_t i = 0; i < pool_count * reseed_threshold; ++i) {
add_random_event(Kernel::rdrand(), i % 32);
}
} else if (TimeManagement::the().can_query_precise_time()) {
// Add HPET as entropy source if we don't have anything better.