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.27 2005/06/11 20:51:41 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; |
70 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
71 |
|
|
72 |
idata = memory_readmax64(cpu, data, len); |
if (writeflag == MEM_WRITE) |
73 |
|
idata = memory_readmax64(cpu, data, len); |
74 |
|
|
75 |
/* |
/* |
76 |
* NOTE: It is up to the user of this device to read or write |
* NOTE: It is up to the user of this device to read or write |
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(); |
226 |
cpu_interrupt_ack(d->cpus[cpu->cpu_id], MIPS_IPI_INT); |
cpu_interrupt_ack(d->cpus[cpu->cpu_id], MIPS_IPI_INT); |
227 |
break; |
break; |
228 |
|
|
229 |
|
case DEV_MP_NCYCLES: |
230 |
|
/* |
231 |
|
* Return approximately the number of cycles executed |
232 |
|
* in this machine. (This value is not updated for each |
233 |
|
* instruction.) |
234 |
|
*/ |
235 |
|
odata = cpu->machine->ncycles; |
236 |
|
break; |
237 |
|
|
238 |
default: |
default: |
239 |
fatal("[ dev_mp: unimplemented relative addr 0x%x ]\n", |
fatal("[ dev_mp: unimplemented relative addr 0x%x ]\n", |
240 |
relative_addr); |
relative_addr); |
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; |
273 |
memset(d->ipi, 0, sizeof(int *) * n); |
memset(d->ipi, 0, sizeof(int *) * n); |
274 |
|
|
275 |
memory_device_register(devinit->machine->memory, devinit->name, |
memory_device_register(devinit->machine->memory, devinit->name, |
276 |
devinit->addr, DEV_MP_LENGTH, dev_mp_access, d, MEM_DEFAULT, NULL); |
devinit->addr, DEV_MP_LENGTH, dev_mp_access, d, DM_DEFAULT, NULL); |
277 |
|
|
278 |
return 1; |
return 1; |
279 |
} |
} |