1 |
/* |
/* |
2 |
* Copyright (C) 2003-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2003-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_dec5800.c,v 1.15 2005/02/22 06:26:10 debug Exp $ |
* $Id: dev_dec5800.c,v 1.21 2007/01/28 00:41:16 debug Exp $ |
29 |
* |
* |
30 |
* Emulation of devices found in a DECsystem 58x0, where x is the number |
* Emulation of devices found in a DECsystem 58x0, where x is the number |
31 |
* of CPUs in the system. (The CPU board is called KN5800 by Ultrix.) |
* of CPUs in the system. (The CPU board is called KN5800 by Ultrix.) |
45 |
|
|
46 |
#include "console.h" |
#include "console.h" |
47 |
#include "cpu.h" |
#include "cpu.h" |
48 |
|
#include "device.h" |
49 |
#include "devices.h" |
#include "devices.h" |
50 |
|
#include "interrupt.h" |
51 |
#include "machine.h" |
#include "machine.h" |
52 |
#include "memory.h" |
#include "memory.h" |
53 |
#include "misc.h" |
#include "misc.h" |
54 |
|
|
55 |
|
|
56 |
/* |
#define DEV_DEC5800_LENGTH 0x1000 /* TODO */ |
57 |
* dev_dec5800_tick(): |
|
58 |
*/ |
struct dec5800_data { |
59 |
void dev_dec5800_tick(struct cpu *cpu, void *extra) |
uint32_t csr; |
60 |
|
struct interrupt cpu_irq; |
61 |
|
|
62 |
|
uint32_t vector_0x50; |
63 |
|
|
64 |
|
struct interrupt timer_irq; |
65 |
|
}; |
66 |
|
|
67 |
|
|
68 |
|
void dec5800_interrupt_assert(struct interrupt *interrupt) |
69 |
|
{ |
70 |
|
struct dec5800_data *d = interrupt->extra; |
71 |
|
d->csr |= (1 << interrupt->line); |
72 |
|
if (d->csr & 0x10000000) |
73 |
|
INTERRUPT_ASSERT(d->cpu_irq); |
74 |
|
} |
75 |
|
void dec5800_interrupt_deassert(struct interrupt *interrupt) |
76 |
|
{ |
77 |
|
struct dec5800_data *d = interrupt->extra; |
78 |
|
d->csr &= ~(1 << interrupt->line); |
79 |
|
if (!(d->csr & 0x10000000)) |
80 |
|
INTERRUPT_DEASSERT(d->cpu_irq); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
DEVICE_TICK(dec5800) |
85 |
{ |
{ |
86 |
struct dec5800_data *d = extra; |
struct dec5800_data *d = extra; |
87 |
|
|
92 |
/* Set timer interrupt pending bit: */ |
/* Set timer interrupt pending bit: */ |
93 |
d->csr |= 0x20000000; |
d->csr |= 0x20000000; |
94 |
|
|
95 |
cpu_interrupt(cpu, 3); |
INTERRUPT_ASSERT(d->timer_irq); |
96 |
} |
} |
97 |
} |
} |
98 |
|
|
99 |
|
|
100 |
/* |
DEVICE_ACCESS(dec5800_vectors) |
|
* dev_dec5800_vectors_access(): |
|
|
*/ |
|
|
int dev_dec5800_vectors_access(struct cpu *cpu, struct memory *mem, |
|
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
101 |
{ |
{ |
102 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
103 |
struct dec5800_data *d = extra; |
struct dec5800_data *d = extra; |
104 |
|
|
105 |
idata = memory_readmax64(cpu, data, len); |
if (writeflag == MEM_WRITE) |
106 |
|
idata = memory_readmax64(cpu, data, len); |
107 |
|
|
108 |
if (writeflag == MEM_READ) { |
if (writeflag == MEM_READ) { |
109 |
/* TODO */ |
/* TODO */ |
126 |
} |
} |
127 |
|
|
128 |
|
|
129 |
/* |
DEVICE_ACCESS(dec5800) |
|
* dev_dec5800_access(): |
|
|
*/ |
|
|
int dev_dec5800_access(struct cpu *cpu, struct memory *mem, |
|
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
130 |
{ |
{ |
131 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
132 |
struct dec5800_data *d = extra; |
struct dec5800_data *d = extra; |
133 |
|
|
134 |
idata = memory_readmax64(cpu, data, len); |
if (writeflag == MEM_WRITE) |
135 |
|
idata = memory_readmax64(cpu, data, len); |
136 |
|
|
137 |
/* Lowest 4 bits of csr contain cpu id: */ |
/* Lowest 4 bits of csr contain cpu id: */ |
138 |
d->csr = (d->csr & ~0xf) | (cpu->cpu_id & 0xf); |
d->csr = (d->csr & ~0xf) | (cpu->cpu_id & 0xf); |
149 |
|
|
150 |
/* Ack. timer interrupts: */ |
/* Ack. timer interrupts: */ |
151 |
d->csr &= ~0x20000000; |
d->csr &= ~0x20000000; |
152 |
cpu_interrupt_ack(cpu, 3); |
INTERRUPT_DEASSERT(d->timer_irq); |
153 |
|
|
154 |
debug("[ dec5800: write to csr: 0x%08x ]\n", |
debug("[ dec5800: write to csr: 0x%08x ]\n", |
155 |
(int)idata); |
(int)idata); |
172 |
} |
} |
173 |
|
|
174 |
|
|
175 |
/* |
DEVINIT(dec5800) |
|
* dev_dec5800_init(): |
|
|
*/ |
|
|
struct dec5800_data *dev_dec5800_init(struct machine *machine, |
|
|
struct memory *mem, uint64_t baseaddr) |
|
176 |
{ |
{ |
177 |
struct dec5800_data *d; |
struct dec5800_data *d; |
178 |
|
char tmpstr[200]; |
179 |
|
int i; |
180 |
|
|
181 |
d = malloc(sizeof(struct dec5800_data)); |
d = malloc(sizeof(struct dec5800_data)); |
182 |
if (d == NULL) { |
if (d == NULL) { |
185 |
} |
} |
186 |
memset(d, 0, sizeof(struct dec5800_data)); |
memset(d, 0, sizeof(struct dec5800_data)); |
187 |
|
|
188 |
memory_device_register(mem, "dec5800", baseaddr, |
snprintf(tmpstr, sizeof(tmpstr), "%s.2", devinit->interrupt_path); |
189 |
DEV_DEC5800_LENGTH, dev_dec5800_access, d, MEM_DEFAULT, NULL); |
INTERRUPT_CONNECT(tmpstr, d->cpu_irq); |
|
memory_device_register(mem, "dec5800_vectors", |
|
|
baseaddr + 0x30000000, 0x100, dev_dec5800_vectors_access, |
|
|
d, MEM_DEFAULT, NULL); |
|
|
machine_add_tickfunction(machine, dev_dec5800_tick, d, 14); |
|
190 |
|
|
191 |
return d; |
snprintf(tmpstr, sizeof(tmpstr), "%s.3", devinit->interrupt_path); |
192 |
|
INTERRUPT_CONNECT(tmpstr, d->timer_irq); |
193 |
|
|
194 |
|
/* Register 32 CSR interrupts, corresponding to bits in the CSR: */ |
195 |
|
for (i=0; i<32; i++) { |
196 |
|
char n[200]; |
197 |
|
struct interrupt template; |
198 |
|
snprintf(n, sizeof(n), "%s.dec5800.%i", |
199 |
|
devinit->interrupt_path, i); |
200 |
|
memset(&template, 0, sizeof(template)); |
201 |
|
template.line = i; |
202 |
|
template.name = n; |
203 |
|
template.extra = d; |
204 |
|
template.interrupt_assert = dec5800_interrupt_assert; |
205 |
|
template.interrupt_deassert = dec5800_interrupt_deassert; |
206 |
|
interrupt_handler_register(&template); |
207 |
|
} |
208 |
|
|
209 |
|
memory_device_register(devinit->machine->memory, "dec5800", |
210 |
|
devinit->addr, DEV_DEC5800_LENGTH, dev_dec5800_access, |
211 |
|
d, DM_DEFAULT, NULL); |
212 |
|
memory_device_register(devinit->machine->memory, "dec5800_vectors", |
213 |
|
devinit->addr + 0x30000000, 0x100, dev_dec5800_vectors_access, |
214 |
|
d, DM_DEFAULT, NULL); |
215 |
|
machine_add_tickfunction(devinit->machine, dev_dec5800_tick, |
216 |
|
d, 14, 0.0); |
217 |
|
|
218 |
|
return 1; |
219 |
} |
} |
220 |
|
|
221 |
|
|
224 |
|
|
225 |
#include "bireg.h" |
#include "bireg.h" |
226 |
|
|
227 |
|
/* 16 slots, 0x2000 bytes each */ |
228 |
|
#define DEV_DECBI_LENGTH 0x20000 |
229 |
|
|
230 |
struct decbi_data { |
struct decbi_data { |
231 |
int csr[NNODEBI]; |
int csr[NNODEBI]; |
232 |
}; |
}; |
233 |
|
|
234 |
|
|
235 |
/* |
DEVICE_ACCESS(decbi) |
|
* dev_decbi_access(): |
|
|
*/ |
|
|
int dev_decbi_access(struct cpu *cpu, struct memory *mem, |
|
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
236 |
{ |
{ |
237 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
238 |
int node_nr; |
int node_nr; |
239 |
struct decbi_data *d = extra; |
struct decbi_data *d = extra; |
240 |
|
|
241 |
idata = memory_readmax64(cpu, data, len); |
if (writeflag == MEM_WRITE) |
242 |
|
idata = memory_readmax64(cpu, data, len); |
243 |
|
|
244 |
relative_addr += BI_NODESIZE; /* HACK */ |
relative_addr += BI_NODESIZE; /* HACK */ |
245 |
|
|
314 |
} |
} |
315 |
|
|
316 |
|
|
317 |
/* |
DEVINIT(decbi) |
|
* dev_decbi_init(): |
|
|
*/ |
|
|
void dev_decbi_init(struct memory *mem, uint64_t baseaddr) |
|
318 |
{ |
{ |
319 |
struct decbi_data *d; |
struct decbi_data *d; |
320 |
|
|
325 |
} |
} |
326 |
memset(d, 0, sizeof(struct decbi_data)); |
memset(d, 0, sizeof(struct decbi_data)); |
327 |
|
|
328 |
memory_device_register(mem, "decbi", baseaddr + 0x2000, |
memory_device_register(devinit->machine->memory, "decbi", |
329 |
DEV_DECBI_LENGTH - 0x2000, dev_decbi_access, d, MEM_DEFAULT, NULL); |
devinit->addr + 0x2000, DEV_DECBI_LENGTH - 0x2000, |
330 |
|
dev_decbi_access, d, DM_DEFAULT, NULL); |
331 |
|
|
332 |
|
return 1; |
333 |
} |
} |
334 |
|
|
335 |
|
|
345 |
}; |
}; |
346 |
|
|
347 |
|
|
348 |
/* |
DEVICE_ACCESS(deccca) |
|
* dev_deccca_access(): |
|
|
*/ |
|
|
int dev_deccca_access(struct cpu *cpu, struct memory *mem, |
|
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
349 |
{ |
{ |
350 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
351 |
/* struct deccca_data *d = extra; */ |
/* struct deccca_data *d = extra; */ |
352 |
|
|
353 |
idata = memory_readmax64(cpu, data, len); |
if (writeflag == MEM_WRITE) |
354 |
|
idata = memory_readmax64(cpu, data, len); |
355 |
|
|
356 |
switch (relative_addr) { |
switch (relative_addr) { |
357 |
case 6: |
case 6: |
406 |
memset(d, 0, sizeof(struct deccca_data)); |
memset(d, 0, sizeof(struct deccca_data)); |
407 |
|
|
408 |
memory_device_register(mem, "deccca", baseaddr, DEV_DECCCA_LENGTH, |
memory_device_register(mem, "deccca", baseaddr, DEV_DECCCA_LENGTH, |
409 |
dev_deccca_access, d, MEM_DEFAULT, NULL); |
dev_deccca_access, d, DM_DEFAULT, NULL); |
410 |
} |
} |
411 |
|
|
412 |
|
|
427 |
/* |
/* |
428 |
* dev_decxmi_access(): |
* dev_decxmi_access(): |
429 |
*/ |
*/ |
430 |
int dev_decxmi_access(struct cpu *cpu, struct memory *mem, |
DEVICE_ACCESS(decxmi) |
|
uint64_t relative_addr, unsigned char *data, size_t len, |
|
|
int writeflag, void *extra) |
|
431 |
{ |
{ |
432 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
433 |
int node_nr; |
int node_nr; |
434 |
struct decxmi_data *d = extra; |
struct decxmi_data *d = extra; |
435 |
|
|
436 |
idata = memory_readmax64(cpu, data, len); |
if (writeflag == MEM_WRITE) |
437 |
|
idata = memory_readmax64(cpu, data, len); |
438 |
|
|
439 |
node_nr = relative_addr / XMI_NODESIZE; |
node_nr = relative_addr / XMI_NODESIZE; |
440 |
relative_addr &= (XMI_NODESIZE - 1); |
relative_addr &= (XMI_NODESIZE - 1); |
522 |
memset(d, 0, sizeof(struct decxmi_data)); |
memset(d, 0, sizeof(struct decxmi_data)); |
523 |
|
|
524 |
memory_device_register(mem, "decxmi", baseaddr, DEV_DECXMI_LENGTH, |
memory_device_register(mem, "decxmi", baseaddr, DEV_DECXMI_LENGTH, |
525 |
dev_decxmi_access, d, MEM_DEFAULT, NULL); |
dev_decxmi_access, d, DM_DEFAULT, NULL); |
526 |
} |
} |
527 |
|
|