1 |
dpavlin |
4 |
/* |
2 |
|
|
* Copyright (C) 2003-2005 Anders Gavare. All rights reserved. |
3 |
|
|
* |
4 |
|
|
* Redistribution and use in source and binary forms, with or without |
5 |
|
|
* modification, are permitted provided that the following conditions are met: |
6 |
|
|
* |
7 |
|
|
* 1. Redistributions of source code must retain the above copyright |
8 |
|
|
* notice, this list of conditions and the following disclaimer. |
9 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
10 |
|
|
* notice, this list of conditions and the following disclaimer in the |
11 |
|
|
* documentation and/or other materials provided with the distribution. |
12 |
|
|
* 3. The name of the author may not be used to endorse or promote products |
13 |
|
|
* derived from this software without specific prior written permission. |
14 |
|
|
* |
15 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
|
|
* SUCH DAMAGE. |
26 |
|
|
* |
27 |
|
|
* |
28 |
|
|
* $Id: dev_kn02.c,v 1.17 2005/02/24 15:38:34 debug Exp $ |
29 |
|
|
* |
30 |
|
|
* KN02 stuff ("3MAX", DECstation type 2). See include/dec_kn02.h for more |
31 |
|
|
* details. |
32 |
|
|
*/ |
33 |
|
|
|
34 |
|
|
#include <stdio.h> |
35 |
|
|
#include <stdlib.h> |
36 |
|
|
#include <string.h> |
37 |
|
|
|
38 |
|
|
#include "cpu.h" |
39 |
|
|
#include "devices.h" |
40 |
|
|
#include "memory.h" |
41 |
|
|
#include "misc.h" |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
#define DEV_KN02_LENGTH 0x1000 |
45 |
|
|
|
46 |
|
|
/* |
47 |
|
|
* dev_kn02_access(): |
48 |
|
|
*/ |
49 |
|
|
int dev_kn02_access(struct cpu *cpu, struct memory *mem, |
50 |
|
|
uint64_t relative_addr, unsigned char *data, size_t len, |
51 |
|
|
int writeflag, void *extra) |
52 |
|
|
{ |
53 |
|
|
struct kn02_csr *d = extra; |
54 |
|
|
uint64_t idata = 0, odata = 0; |
55 |
|
|
|
56 |
|
|
idata = memory_readmax64(cpu, data, len); |
57 |
|
|
|
58 |
|
|
switch (relative_addr) { |
59 |
|
|
case 0: |
60 |
|
|
if (writeflag==MEM_READ) { |
61 |
|
|
odata = d->csr[0] + (d->csr[1] << 8) + |
62 |
|
|
(d->csr[2] << 16) + (d->csr[3] << 24); |
63 |
|
|
/* debug("[ kn02: read from CSR: 0x%08x ]\n", odata); */ |
64 |
|
|
} else { |
65 |
|
|
/* |
66 |
|
|
* Only bits 23..8 are considered writable. The |
67 |
|
|
* lowest 8 bits are actually writable, but don't |
68 |
|
|
* affect the interrupt I/O bits; the low 8 bits |
69 |
|
|
* on write turn on and off LEDs. (There are no |
70 |
|
|
* LEDs in the emulator, so those bits are just |
71 |
|
|
* ignored.) |
72 |
|
|
*/ |
73 |
|
|
/* fatal("[ kn02: write to CSR: 0x%08x ]\n", idata); */ |
74 |
|
|
|
75 |
|
|
d->csr[1] = (idata >> 8) & 255; |
76 |
|
|
d->csr[2] = (idata >> 16) & 255; |
77 |
|
|
|
78 |
|
|
/* Recalculate interrupt assertions: */ |
79 |
|
|
cpu_interrupt(cpu, 8); |
80 |
|
|
} |
81 |
|
|
break; |
82 |
|
|
default: |
83 |
|
|
if (writeflag==MEM_READ) { |
84 |
|
|
debug("[ kn02: read from 0x%08lx ]\n", |
85 |
|
|
(long)relative_addr); |
86 |
|
|
} else { |
87 |
|
|
debug("[ kn02: write to 0x%08lx: 0x%08x ]\n", |
88 |
|
|
(long)relative_addr, (int)idata); |
89 |
|
|
} |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
if (writeflag == MEM_READ) |
93 |
|
|
memory_writemax64(cpu, data, len, odata); |
94 |
|
|
|
95 |
|
|
return 1; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
|
99 |
|
|
/* |
100 |
|
|
* dev_kn02_init(): |
101 |
|
|
*/ |
102 |
|
|
struct kn02_csr *dev_kn02_init(struct cpu *cpu, struct memory *mem, |
103 |
|
|
uint64_t baseaddr) |
104 |
|
|
{ |
105 |
|
|
struct kn02_csr *d; |
106 |
|
|
|
107 |
|
|
d = malloc(sizeof(struct kn02_csr)); |
108 |
|
|
if (d == NULL) { |
109 |
|
|
fprintf(stderr, "out of memory\n"); |
110 |
|
|
exit(1); |
111 |
|
|
} |
112 |
|
|
memset(d, 0, sizeof(struct kn02_csr)); |
113 |
|
|
|
114 |
|
|
memory_device_register(mem, "kn02", baseaddr, DEV_KN02_LENGTH, |
115 |
|
|
dev_kn02_access, d, MEM_BINTRANS_OK, &d->csr[0]); |
116 |
|
|
|
117 |
|
|
return d; |
118 |
|
|
} |
119 |
|
|
|