Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/amd64/stand/prekern Mmh, should check cpuid_level f...



details:   https://anonhg.NetBSD.org/src/rev/199f01410d0b
branches:  trunk
changeset: 933185:199f01410d0b
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu May 21 08:20:25 2020 +0000

description:
Mmh, should check cpuid_level first.

diffstat:

 sys/arch/amd64/stand/prekern/prng.c |  17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diffs (40 lines):

diff -r e5b560286a5c -r 199f01410d0b sys/arch/amd64/stand/prekern/prng.c
--- a/sys/arch/amd64/stand/prekern/prng.c       Thu May 21 07:43:23 2020 +0000
+++ b/sys/arch/amd64/stand/prekern/prng.c       Thu May 21 08:20:25 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: prng.c,v 1.2 2017/11/26 11:08:34 maxv Exp $    */
+/*     $NetBSD: prng.c,v 1.3 2020/05/21 08:20:25 maxv Exp $    */
 
 /*
- * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
+ * Copyright (c) 2017-2020 The NetBSD Foundation, Inc. All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
  * by Maxime Villard.
@@ -148,6 +148,7 @@
 void
 prng_init(void)
 {
+       extern int cpuid_level;
        uint8_t digest[SHA512_DIGEST_LENGTH];
        SHA512_CTX ctx;
        u_int descs[4];
@@ -155,10 +156,14 @@
        memset(&rng, 0, sizeof(rng));
 
        /* detect cpu features */
-       cpuid(0x07, 0x00, descs);
-       has_rdseed = (descs[1] & CPUID_SEF_RDSEED) != 0;
-       cpuid(0x01, 0x00, descs);
-       has_rdrand = (descs[2] & CPUID2_RDRAND) != 0;
+       if (cpuid_level >= 0x07) {
+               cpuid(0x07, 0x00, descs);
+               has_rdseed = (descs[1] & CPUID_SEF_RDSEED) != 0;
+       }
+       if (cpuid_level >= 0x01) {
+               cpuid(0x01, 0x00, descs);
+               has_rdrand = (descs[2] & CPUID2_RDRAND) != 0;
+       }
 
        SHA512_Init(&ctx);
        prng_get_entropy_file(&ctx);



Home | Main Index | Thread Index | Old Index