nehemiah.c revision 128059
1128059Smarkm/*- 2128059Smarkm * Copyright (c) 2004 Mark R V Murray 3128059Smarkm * All rights reserved. 4128059Smarkm * 5128059Smarkm * Redistribution and use in source and binary forms, with or without 6128059Smarkm * modification, are permitted provided that the following conditions 7128059Smarkm * are met: 8128059Smarkm * 1. Redistributions of source code must retain the above copyright 9128059Smarkm * notice, this list of conditions and the following disclaimer 10128059Smarkm * in this position and unchanged. 11128059Smarkm * 2. Redistributions in binary form must reproduce the above copyright 12128059Smarkm * notice, this list of conditions and the following disclaimer in the 13128059Smarkm * documentation and/or other materials provided with the distribution. 14128059Smarkm * 15128059Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16128059Smarkm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17128059Smarkm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18128059Smarkm * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19128059Smarkm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20128059Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21128059Smarkm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22128059Smarkm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23128059Smarkm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24128059Smarkm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25128059Smarkm * 26128059Smarkm */ 27128059Smarkm 28128059Smarkm#include <sys/cdefs.h> 29128059Smarkm__FBSDID("$FreeBSD: head/sys/dev/random/nehemiah.c 128059 2004-04-09 15:47:10Z markm $"); 30128059Smarkm 31128059Smarkm#include <sys/types.h> 32128059Smarkm#include <sys/time.h> 33128059Smarkm#include <sys/lock.h> 34128059Smarkm#include <sys/mutex.h> 35128059Smarkm#include <sys/selinfo.h> 36128059Smarkm 37128059Smarkm#include <dev/random/randomdev.h> 38128059Smarkm 39128059Smarkmstatic int random_nehemiah_read(void *, int); 40128059Smarkm 41128059Smarkmstruct random_systat random_nehemiah = { 42128059Smarkm .ident = "Hardware, VIA Nehemiah", 43128059Smarkm .init = (random_init_func_t *)random_null_func, 44128059Smarkm .deinit = (random_deinit_func_t *)random_null_func, 45128059Smarkm .read = random_nehemiah_read, 46128059Smarkm .write = (random_write_func_t *)random_null_func, 47128059Smarkm .reseed = (random_reseed_func_t *)random_null_func, 48128059Smarkm .seeded = 1, 49128059Smarkm}; 50128059Smarkm 51128059Smarkm/* ARGSUSED */ 52128059Smarkmstatic int 53128059Smarkmrandom_nehemiah_read(void *buf, int c) 54128059Smarkm{ 55128059Smarkm#if (defined(__GNUC__) || defined(__INTEL_COMPILER)) && defined(__i386__) 56128059Smarkm int count = c; 57128059Smarkm int rate = 0; 58128059Smarkm 59128059Smarkm /* VIA C3 Nehemiah "rep; xstore" */ 60128059Smarkm __asm __volatile("rep; .byte 0x0f, 0xa7, 0xc0" 61128059Smarkm : "+D" (buf), "+c" (count), "=d" (rate) 62128059Smarkm : 63128059Smarkm : "memory"); 64128059Smarkm#endif 65128059Smarkm return (c); 66128059Smarkm} 67