/[gxemul]/upstream/0.4.6/src/devices/dev_kn02.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.4.6/src/devices/dev_kn02.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 43 - (show annotations)
Mon Oct 8 16:22:43 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 5503 byte(s)
0.4.6
1 /*
2 * Copyright (C) 2003-2007 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.28 2007/06/15 19:11:15 debug Exp $
29 *
30 * COMMENT: DEC KN02 mainbus (TurboChannel interrupt controller)
31 *
32 * Used in DECstation type 2 ("3MAX"). See include/dec_kn02.h for more info.
33 */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include "cpu.h"
40 #include "device.h"
41 #include "interrupt.h"
42 #include "machine.h"
43 #include "memory.h"
44 #include "misc.h"
45
46
47 #include "dec_kn02.h"
48
49 #define DEV_KN02_LENGTH 0x1000
50
51
52 struct kn02_data {
53 uint8_t csr[sizeof(uint32_t)];
54
55 /* Dummy fill bytes, so dyntrans can be used: */
56 uint8_t filler[DEV_KN02_LENGTH - sizeof(uint32_t)];
57
58 struct interrupt irq;
59 int int_asserted;
60 };
61
62
63 /*
64 * kn02_interrupt_assert(), kn02_interrupt_deassert():
65 *
66 * Called whenever a KN02 (TurboChannel) interrupt is asserted/deasserted.
67 */
68 void kn02_interrupt_assert(struct interrupt *interrupt)
69 {
70 struct kn02_data *d = interrupt->extra;
71 d->csr[0] |= interrupt->line;
72 if (d->csr[0] & d->csr[2] && !d->int_asserted) {
73 d->int_asserted = 1;
74 INTERRUPT_ASSERT(d->irq);
75 }
76 }
77 void kn02_interrupt_deassert(struct interrupt *interrupt)
78 {
79 struct kn02_data *d = interrupt->extra;
80 d->csr[0] &= ~interrupt->line;
81 if (!(d->csr[0] & d->csr[2]) && d->int_asserted) {
82 d->int_asserted = 0;
83 INTERRUPT_DEASSERT(d->irq);
84 }
85 }
86
87
88 DEVICE_ACCESS(kn02)
89 {
90 struct kn02_data *d = extra;
91 uint64_t idata = 0, odata = 0;
92
93 if (writeflag == MEM_WRITE)
94 idata = memory_readmax64(cpu, data, len);
95
96 switch (relative_addr) {
97 case 0:
98 if (writeflag==MEM_READ) {
99 odata = d->csr[0] + (d->csr[1] << 8) +
100 (d->csr[2] << 16) + (d->csr[3] << 24);
101
102 /* debug("[ kn02: read from CSR: 0x%08x ]\n", odata); */
103 } else {
104 /*
105 * Only bits 23..8 are considered writable. The
106 * lowest 8 bits are actually writable, but don't
107 * affect the interrupt I/O bits; the low 8 bits
108 * on write turn on and off LEDs. (There are no
109 * LEDs in the emulator, so those bits are just
110 * ignored.)
111 */
112 int old_assert = (d->csr[0] & d->csr[2])? 1 : 0;
113 int new_assert;
114 /* fatal("[ kn02: write to CSR: 0x%08x ]\n", idata); */
115
116 d->csr[1] = (idata >> 8) & 255;
117 d->csr[2] = (idata >> 16) & 255;
118
119 /* Recalculate interrupt assertions: */
120 new_assert = (d->csr[0] & d->csr[2])? 1 : 0;
121 if (new_assert != old_assert) {
122 if (new_assert) {
123 INTERRUPT_ASSERT(d->irq);
124 d->int_asserted = 1;
125 } else {
126 INTERRUPT_DEASSERT(d->irq);
127 d->int_asserted = 0;
128 }
129 }
130 }
131 break;
132 default:
133 if (writeflag==MEM_READ) {
134 debug("[ kn02: read from 0x%08lx ]\n",
135 (long)relative_addr);
136 } else {
137 debug("[ kn02: write to 0x%08lx: 0x%08x ]\n",
138 (long)relative_addr, (int)idata);
139 }
140 }
141
142 if (writeflag == MEM_READ)
143 memory_writemax64(cpu, data, len, odata);
144
145 return 1;
146 }
147
148
149 DEVINIT(kn02)
150 {
151 struct kn02_data *d;
152 uint32_t csr;
153 int i;
154
155 CHECK_ALLOCATION(d = malloc(sizeof(struct kn02_data)));
156 memset(d, 0, sizeof(struct kn02_data));
157
158 /* Connect the KN02 to a specific MIPS CPU interrupt line: */
159 INTERRUPT_CONNECT(devinit->interrupt_path, d->irq);
160
161 /* Register the 8 possible TurboChannel interrupts: */
162 for (i=0; i<8; i++) {
163 struct interrupt template;
164 char tmpstr[300];
165 snprintf(tmpstr, sizeof(tmpstr), "%s.kn02.%i",
166 devinit->interrupt_path, i);
167 memset(&template, 0, sizeof(template));
168 template.line = 1 << i;
169 template.name = tmpstr;
170 template.extra = d;
171 template.interrupt_assert = kn02_interrupt_assert;
172 template.interrupt_deassert = kn02_interrupt_deassert;
173 interrupt_handler_register(&template);
174 }
175
176 /*
177 * Set initial value of the CSR. Note: If the KN02_CSR_NRMMOD bit
178 * is not set, the 5000/200 PROM image loops forever.
179 */
180 csr = KN02_CSR_NRMMOD;
181 d->csr[0] = csr;
182 d->csr[1] = csr >> 8;
183 d->csr[2] = csr >> 16;
184 d->csr[3] = csr >> 24;
185
186 memory_device_register(devinit->machine->memory, devinit->name,
187 devinit->addr, DEV_KN02_LENGTH, dev_kn02_access, d,
188 DM_DYNTRANS_OK, &d->csr[0]);
189
190 return 1;
191 }
192

  ViewVC Help
Powered by ViewVC 1.1.26