25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_mp.c,v 1.25 2005/02/25 06:27:48 debug Exp $ |
* $Id: dev_mp.c,v 1.27 2005/06/11 20:51:41 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 |
50 |
uint64_t startup_addr; |
uint64_t startup_addr; |
51 |
uint64_t stack_addr; |
uint64_t stack_addr; |
52 |
uint64_t pause_addr; |
uint64_t pause_addr; |
53 |
|
|
54 |
|
/* Each CPU has an array of pending ipis. */ |
55 |
|
int *n_pending_ipis; |
56 |
|
int **ipi; |
57 |
}; |
}; |
58 |
|
|
59 |
|
|
60 |
|
extern int single_step; |
61 |
|
|
62 |
|
|
63 |
/* |
/* |
64 |
* dev_mp_access(): |
* dev_mp_access(): |
65 |
*/ |
*/ |
160 |
odata = cpu->machine->physical_ram_in_mb * 1048576; |
odata = cpu->machine->physical_ram_in_mb * 1048576; |
161 |
break; |
break; |
162 |
|
|
163 |
|
case DEV_MP_IPI_ONE: |
164 |
|
case DEV_MP_IPI_MANY: |
165 |
|
/* |
166 |
|
* idata should be of the form: |
167 |
|
* |
168 |
|
* (IPI_nr << 16) | cpu_id |
169 |
|
* |
170 |
|
* This will send an Inter-processor interrupt to a specific |
171 |
|
* CPU. (DEV_MP_IPI_MANY sends to all _except_ the specific |
172 |
|
* CPU.) |
173 |
|
* |
174 |
|
* Sending an IPI means adding the IPI last in the list of |
175 |
|
* pending IPIs, and asserting the IPI "pin". |
176 |
|
*/ |
177 |
|
which_cpu = (idata & 0xffff); |
178 |
|
for (i=0; i<cpu->machine->ncpus; i++) { |
179 |
|
int send_it = 0; |
180 |
|
if (relative_addr == DEV_MP_IPI_ONE && i == which_cpu) |
181 |
|
send_it = 1; |
182 |
|
if (relative_addr == DEV_MP_IPI_MANY && i != which_cpu) |
183 |
|
send_it = 1; |
184 |
|
if (send_it) { |
185 |
|
d->n_pending_ipis[i] ++; |
186 |
|
d->ipi[i] = realloc(d->ipi[i], |
187 |
|
d->n_pending_ipis[i] * sizeof(int)); |
188 |
|
if (d->ipi[i] == NULL) { |
189 |
|
fprintf(stderr, "out of memory\n"); |
190 |
|
exit(1); |
191 |
|
} |
192 |
|
/* Add the IPI last in the array: */ |
193 |
|
d->ipi[i][d->n_pending_ipis[i] - 1] = |
194 |
|
idata >> 16; |
195 |
|
cpu_interrupt(d->cpus[i], MIPS_IPI_INT); |
196 |
|
} |
197 |
|
} |
198 |
|
break; |
199 |
|
|
200 |
|
case DEV_MP_IPI_READ: |
201 |
|
/* |
202 |
|
* If the current CPU has any IPIs pending, accessing this |
203 |
|
* address reads the IPI value. (Writing to this address |
204 |
|
* discards _all_ pending IPIs.) If there is no pending |
205 |
|
* IPI, then 0 is returned. Usage of the value 0 for real |
206 |
|
* IPIs should thus be avoided. |
207 |
|
*/ |
208 |
|
if (writeflag == MEM_WRITE) { |
209 |
|
d->n_pending_ipis[cpu->cpu_id] = 0; |
210 |
|
} |
211 |
|
odata = 0; |
212 |
|
if (d->n_pending_ipis[cpu->cpu_id] > 0) { |
213 |
|
odata = d->ipi[cpu->cpu_id][0]; |
214 |
|
if (d->n_pending_ipis[cpu->cpu_id]-- > 1) |
215 |
|
memmove(&d->ipi[cpu->cpu_id][0], |
216 |
|
&d->ipi[cpu->cpu_id][1], |
217 |
|
d->n_pending_ipis[cpu->cpu_id]); |
218 |
|
} |
219 |
|
/* Deassert the interrupt, if there are no pending IPIs: */ |
220 |
|
if (d->n_pending_ipis[cpu->cpu_id] == 0) |
221 |
|
cpu_interrupt_ack(d->cpus[cpu->cpu_id], MIPS_IPI_INT); |
222 |
|
break; |
223 |
|
|
224 |
default: |
default: |
225 |
fatal("[ dev_mp: unimplemented relative addr 0x%x ]\n", |
fatal("[ dev_mp: unimplemented relative addr 0x%x ]\n", |
226 |
relative_addr); |
relative_addr); |
239 |
int devinit_mp(struct devinit *devinit) |
int devinit_mp(struct devinit *devinit) |
240 |
{ |
{ |
241 |
struct mp_data *d; |
struct mp_data *d; |
242 |
|
int n; |
243 |
|
|
244 |
d = malloc(sizeof(struct mp_data)); |
d = malloc(sizeof(struct mp_data)); |
245 |
if (d == NULL) { |
if (d == NULL) { |
246 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
251 |
d->startup_addr = INITIAL_PC; |
d->startup_addr = INITIAL_PC; |
252 |
d->stack_addr = INITIAL_STACK_POINTER; |
d->stack_addr = INITIAL_STACK_POINTER; |
253 |
|
|
254 |
memory_device_register(devinit->machine->memory, |
n = devinit->machine->ncpus; |
255 |
devinit->name, devinit->addr, DEV_MP_LENGTH, |
d->n_pending_ipis = malloc(n * sizeof(int)); |
256 |
dev_mp_access, d, MEM_DEFAULT, NULL); |
d->ipi = malloc(n * sizeof(int *)); |
257 |
|
if (d->ipi == NULL || d->n_pending_ipis == NULL) { |
258 |
|
fprintf(stderr, "out of memory\n"); |
259 |
|
exit(1); |
260 |
|
} |
261 |
|
memset(d->n_pending_ipis, 0, sizeof(int) * n); |
262 |
|
memset(d->ipi, 0, sizeof(int *) * n); |
263 |
|
|
264 |
|
memory_device_register(devinit->machine->memory, devinit->name, |
265 |
|
devinit->addr, DEV_MP_LENGTH, dev_mp_access, d, MEM_DEFAULT, NULL); |
266 |
|
|
267 |
return 1; |
return 1; |
268 |
} |
} |