summaryrefslogtreecommitdiff
path: root/target/i386/int_helper.c
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2019-03-14 20:01:42 -0700
committerRichard Henderson <richard.henderson@linaro.org>2019-05-22 12:38:54 -0400
commit369fd5ca66810b2ddb16e23a497eabe59385eceb (patch)
tree1fb3bf56e7df2e7f8ef9ccf2d16cf891665efd6d /target/i386/int_helper.c
parent3f74b6322cec37d23351df8caccfdfd85dceff9b (diff)
downloadqemu-369fd5ca66810b2ddb16e23a497eabe59385eceb.zip
target/i386: Implement CPUID_EXT_RDRAND
We now have an interface for guest visible random numbers. Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'target/i386/int_helper.c')
-rw-r--r--target/i386/int_helper.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/target/i386/int_helper.c b/target/i386/int_helper.c
index 4dc5c65991..334469ca8c 100644
--- a/target/i386/int_helper.c
+++ b/target/i386/int_helper.c
@@ -22,6 +22,8 @@
#include "exec/exec-all.h"
#include "qemu/host-utils.h"
#include "exec/helper-proto.h"
+#include "qapi/error.h"
+#include "qemu/guest-random.h"
//#define DEBUG_MULDIV
@@ -470,3 +472,22 @@ void helper_cr4_testbit(CPUX86State *env, uint32_t bit)
raise_exception_ra(env, EXCP06_ILLOP, GETPC());
}
}
+
+target_ulong HELPER(rdrand)(CPUX86State *env)
+{
+ Error *err = NULL;
+ target_ulong ret;
+
+ if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) {
+ qemu_log_mask(LOG_UNIMP, "rdrand: Crypto failure: %s",
+ error_get_pretty(err));
+ error_free(err);
+ /* Failure clears CF and all other flags, and returns 0. */
+ env->cc_src = 0;
+ return 0;
+ }
+
+ /* Success sets CF and clears all others. */
+ env->cc_src = CC_C;
+ return ret;
+}