1 |
/* |
/* |
2 |
* Copyright (C) 2004-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2004-2007 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_random.c,v 1.2 2005/11/13 00:14:09 debug Exp $ |
* $Id: dev_random.c,v 1.9 2007/06/15 20:11:27 debug Exp $ |
29 |
* |
* |
30 |
* A simple device which returns random data for all reads, and discards all |
* COMMENT: A device which returns random data for reads, discards all writes |
|
* writes. |
|
31 |
*/ |
*/ |
32 |
|
|
33 |
#include <stdio.h> |
#include <stdio.h> |
40 |
#include "misc.h" |
#include "misc.h" |
41 |
|
|
42 |
|
|
43 |
/* |
DEVICE_ACCESS(random) |
|
* dev_random_access(): |
|
|
* |
|
|
* Returns 1 if ok, 0 on error. |
|
|
*/ |
|
|
int dev_random_access(struct cpu *cpu, struct memory *mem, |
|
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
44 |
{ |
{ |
45 |
if (writeflag == MEM_READ) { |
if (writeflag == MEM_READ) { |
46 |
int i; |
size_t i; |
47 |
for (i=0; i<len; i++) |
for (i=0; i<len; i++) |
48 |
data[i] = random(); |
data[i] = random(); |
49 |
} |
} |
52 |
} |
} |
53 |
|
|
54 |
|
|
55 |
/* |
DEVINIT(random) |
|
* devinit_random(): |
|
|
*/ |
|
|
int devinit_random(struct devinit *devinit) |
|
56 |
{ |
{ |
57 |
memory_device_register(devinit->machine->memory, |
memory_device_register(devinit->machine->memory, |
58 |
devinit->name, devinit->addr, devinit->len, |
devinit->name, devinit->addr, devinit->len, |