diff options
author | kib <kib@FreeBSD.org> | 2014-11-07 20:10:09 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2014-11-07 20:10:09 +0000 |
commit | 8055eb245481474d30b1ceaaff1b52555e06c327 (patch) | |
tree | 8f6f2617d454b337d638d24de544316525a505cd /sys/dev/random | |
parent | 40cb08cd5b951bd634aa029b10c32035fac91c10 (diff) | |
download | FreeBSD-src-8055eb245481474d30b1ceaaff1b52555e06c327.zip FreeBSD-src-8055eb245481474d30b1ceaaff1b52555e06c327.tar.gz |
Simplify assembler in ivy.c. Move the copying of the random bits into
buffer from asm to C, which reduces amount of arguments for inline asm
and simplifies constraints. Use unsigned types consistently.
Submitted by: bde
Approved by: secteam (delphij)
Reviewed by: markm
MFC after: 1 week
Diffstat (limited to 'sys/dev/random')
-rw-r--r-- | sys/dev/random/ivy.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/sys/dev/random/ivy.c b/sys/dev/random/ivy.c index 724e7aa..c098b87 100644 --- a/sys/dev/random/ivy.c +++ b/sys/dev/random/ivy.c @@ -61,42 +61,41 @@ static struct live_entropy_source random_ivy = { }; static inline int -ivy_rng_store(long *buf) +ivy_rng_store(u_long *buf) { #ifdef __GNUCLIKE_ASM - long tmp; + u_long rndval; int retry; retry = RETRY_COUNT; __asm __volatile( "1:\n\t" - "rdrand %2\n\t" /* read randomness into tmp */ - "jb 2f\n\t" /* CF is set on success, exit retry loop */ + "rdrand %1\n\t" /* read randomness into tmp */ + "jc 2f\n\t" /* CF is set on success, exit retry loop */ "dec %0\n\t" /* otherwise, retry-- */ "jne 1b\n\t" /* and loop if retries are not exhausted */ - "jmp 3f\n" /* failure, retry is 0, used as return value */ - "2:\n\t" - "mov %2,%1\n\t" /* *buf = tmp */ - "3:" - : "+q" (retry), "=m" (*buf), "+q" (tmp) : : "cc"); + "2:" + : "+r" (retry), "=r" (rndval) : : "cc"); + *buf = rndval; return (retry); #else /* __GNUCLIKE_ASM */ return (0); #endif } -/* It is specifically allowed that buf is a multiple of sizeof(long) */ +/* It is required that buf length is a multiple of sizeof(u_long). */ static u_int random_ivy_read(void *buf, u_int c) { - long *b; + u_long *b, rndval; u_int count; KASSERT(c % sizeof(*b) == 0, ("partial read %d", c)); b = buf; for (count = c; count > 0; count -= sizeof(*b)) { - if (ivy_rng_store(b++) == 0) + if (ivy_rng_store(&rndval) == 0) break; + *b++ = rndval; } return (c - count); } |