From a9764dabeeedf8c6cb89affcbf4fab76fd3d76dc Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Mon, 21 Mar 2022 22:59:07 +0200 Subject: [PATCH] Kernel: Add helpers for rdrand and rdseed --- Kernel/Arch/x86/ASM_wrapper.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Kernel/Arch/x86/ASM_wrapper.h b/Kernel/Arch/x86/ASM_wrapper.h index 63733f1790..9fce75e875 100644 --- a/Kernel/Arch/x86/ASM_wrapper.h +++ b/Kernel/Arch/x86/ASM_wrapper.h @@ -160,6 +160,28 @@ ALWAYS_INLINE u64 read_tsc() return ((u64)msw << 32) | lsw; } +ALWAYS_INLINE u32 rdrand() +{ + u32 value; + asm volatile( + "1:\n" + "rdrand %0\n" + "jnc 1b\n" + : "=r"(value)::"cc"); + return value; +} + +ALWAYS_INLINE u32 rdseed() +{ + u32 value; + asm volatile( + "1:\n" + "rdseed %0\n" + "jnc 1b\n" + : "=r"(value)::"cc"); + return value; +} + void stac(); void clac();