1 |
/* |
/* |
2 |
* Copyright (C) 2003-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-2006 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_mp.c,v 1.30 2005/11/13 00:14:09 debug Exp $ |
* $Id: dev_mp.c,v 1.34 2006/02/09 20:02:59 debug Exp $ |
29 |
* |
* |
30 |
* This is a fake multiprocessor (MP) device. It can be useful for |
* This is a fake multiprocessor (MP) device. It can be useful for |
31 |
* theoretical experiments, but probably bares no resemblance to any |
* theoretical experiments, but probably bares no resemblance to any |
63 |
/* |
/* |
64 |
* dev_mp_access(): |
* dev_mp_access(): |
65 |
*/ |
*/ |
66 |
int dev_mp_access(struct cpu *cpu, struct memory *mem, uint64_t relative_addr, |
DEVICE_ACCESS(mp) |
|
unsigned char *data, size_t len, int writeflag, void *extra) |
|
67 |
{ |
{ |
68 |
struct mp_data *d = extra; |
struct mp_data *d = extra; |
69 |
int i, which_cpu; |
int i, which_cpu; |
124 |
which_cpu = idata; |
which_cpu = idata; |
125 |
|
|
126 |
for (i=0; i<cpu->machine->ncpus; i++) |
for (i=0; i<cpu->machine->ncpus; i++) |
127 |
if (i!=which_cpu) |
if (i != which_cpu) |
128 |
d->cpus[i]->running = 0; |
d->cpus[i]->running = 0; |
129 |
break; |
break; |
130 |
|
|
131 |
case DEV_MP_UNPAUSE_CPU: |
case DEV_MP_UNPAUSE_CPU: |
132 |
/* Unpause all cpus except our selves: */ |
/* Unpause a specific CPU: */ |
133 |
which_cpu = idata; |
which_cpu = idata; |
134 |
for (i=0; i<cpu->machine->ncpus; i++) |
|
135 |
if (i!=which_cpu) |
if (which_cpu >= 0 && which_cpu <cpu->machine->ncpus) |
136 |
d->cpus[i]->running = 1; |
d->cpus[which_cpu]->running = 1; |
137 |
break; |
break; |
138 |
|
|
139 |
case DEV_MP_STARTUPSTACK: |
case DEV_MP_STARTUPSTACK: |
143 |
break; |
break; |
144 |
|
|
145 |
case DEV_MP_HARDWARE_RANDOM: |
case DEV_MP_HARDWARE_RANDOM: |
146 |
/* Return (up to) 64 bits of "hardware random": */ |
/* |
147 |
|
* Return (up to) 64 bits of "hardware random": |
148 |
|
* |
149 |
|
* NOTE: Remember that random() is (usually) 31 bits of |
150 |
|
* random data, _NOT_ 32, hence this construction. |
151 |
|
*/ |
152 |
odata = random(); |
odata = random(); |
153 |
odata = (odata << 31) ^ random(); |
odata = (odata << 31) ^ random(); |
154 |
odata = (odata << 31) ^ random(); |
odata = (odata << 31) ^ random(); |
247 |
} |
} |
248 |
|
|
249 |
|
|
250 |
/* |
DEVINIT(mp) |
|
* devinit_mp(): |
|
|
*/ |
|
|
int devinit_mp(struct devinit *devinit) |
|
251 |
{ |
{ |
252 |
struct mp_data *d; |
struct mp_data *d; |
253 |
int n; |
int n; |