/[gxemul]/trunk/src/devices/dev_turbochannel.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 /trunk/src/devices/dev_turbochannel.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 42 - (show annotations)
Mon Oct 8 16:22:32 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 11096 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1613 2007/06/15 20:11:26 debug Exp $
20070501	Continuing a little on m88k disassembly (control registers,
		more instructions).
		Adding a dummy mvme88k machine mode.
20070502	Re-adding MIPS load/store alignment exceptions.
20070503	Implementing more of the M88K disassembly code.
20070504	Adding disassembly of some more M88K load/store instructions.
		Implementing some relatively simple M88K instructions (br.n,
		xor[.u] imm, and[.u] imm).
20070505	Implementing M88K three-register and, or, xor, and jmp[.n],
		bsr[.n] including function call trace stuff.
		Applying a patch from Bruce M. Simpson which implements the
		SYSCON_BOARD_CPU_CLOCK_FREQ_ID object of the syscon call in
		the yamon PROM emulation.
20070506	Implementing M88K bb0[.n] and bb1[.n], and skeletons for
		ldcr and stcr (although no control regs are implemented yet).
20070509	Found and fixed the bug which caused Linux for QEMU_MIPS to
		stop working in 0.4.5.1: It was a faulty change to the MIPS
		'sc' and 'scd' instructions I made while going through gcc -W
		warnings on 20070428.
20070510	Updating the Linux/QEMU_MIPS section in guestoses.html to
		use mips-test-0.2.tar.gz instead of 0.1.
		A big thank you to Miod Vallat for sending me M88K manuals.
		Implementing more M88K instructions (addu, subu, div[u], mulu,
		ext[u], clr, set, cmp).
20070511	Fixing bugs in the M88K "and" and "and.u" instructions (found
		by comparing against the manual).
		Implementing more M88K instructions (mask[.u], mak, bcnd (auto-
		generated)) and some more control register details.
		Cleanup: Removing the experimental AVR emulation mode and
		corresponding devices; AVR emulation wasn't really meaningful.
		Implementing autogeneration of most M88K loads/stores. The
		rectangle drawing demo (with -O0) for M88K runs :-)
		Beginning on M88K exception handling.
		More M88K instructions: tb0, tb1, rte, sub, jsr[.n].
		Adding some skeleton MVME PROM ("BUG") emulation.
20070512	Fixing a bug in the M88K cmp instruction.
		Adding the M88K lda (scaled register) instruction.
		Fixing bugs in 64-bit (32-bit pairs) M88K loads/stores.
		Removing the unused tick_hz stuff from the machine struct.
		Implementing the M88K xmem instruction. OpenBSD/mvme88k gets
		far enough to display the Copyright banner :-)
		Implementing subu.co (guess), addu.co, addu.ci, ff0, and ff1.
		Adding a dev_mvme187, for MVME187-specific devices/registers.
		OpenBSD/mvme88k prints more boot messages. :)
20070515	Continuing on MVME187 emulation (adding more devices, beginning
		on the CMMUs, etc).
		Adding the M88K and.c, xor.c, and or.c instructions, and making
		sure that mul, div, etc cause exceptions if executed when SFD1
		is disabled.
20070517	Continuing on M88K and MVME187 emulation in general; moving
		the CMMU registers to the CPU struct, separating dev_pcc2 from
		dev_mvme187, and beginning on memory_m88k.c (BATC and PATC).
		Fixing a bug in 64-bit (32-bit pairs) M88K fast stores.
		Implementing the clock part of dev_mk48txx.
		Implementing the M88K fstcr and xcr instructions.
		Implementing m88k_cpu_tlbdump().
		Beginning on the implementation of a separate address space
		for M88K .usr loads/stores.
20070520	Removing the non-working (skeleton) Sandpoint, SonyNEWS, SHARK
		Dnard, and Zaurus machine modes.
		Experimenting with dyntrans to_be_translated read-ahead. It
		seems to give a very small performance increase for MIPS
		emulation, but a large performance degradation for SuperH. Hm.
20070522	Disabling correct SuperH ITLB emulation; it does not seem to be
		necessary in order to let SH4 guest OSes run, and it slows down
		userspace code.
		Implementing "samepage" branches for SuperH emulation, and some
		other minor speed hacks.
20070525	Continuing on M88K memory-related stuff: exceptions, memory
		transaction register contents, etc.
		Implementing the M88K subu.ci instruction.
		Removing the non-working (skeleton) Iyonix machine mode.
		OpenBSD/mvme88k reaches userland :-), starts executing
		/sbin/init's instructions, and issues a few syscalls, before
		crashing.
20070526	Fixing bugs in dev_mk48txx, so that OpenBSD/mvme88k detects
		the correct time-of-day.
		Implementing a generic IRQ controller for the test machines
		(dev_irqc), similar to a proposed patch from Petr Stepan.
		Experimenting some more with translation read-ahead.
		Adding an "expect" script for automated OpenBSD/landisk
		install regression/performance tests.
20070527	Adding a dummy mmEye (SH3) machine mode skeleton.
		FINALLY found the strange M88K bug I have been hunting: I had
		not emulated the SNIP value for exceptions occurring in
		branch delay slots correctly.
		Implementing correct exceptions for 64-bit M88K loads/stores.
		Address to symbol lookups are now disabled when M88K is
		running in usermode (because usermode addresses don't have
		anything to do with supervisor addresses).
20070531	Removing the mmEye machine mode skeleton.
20070604	Some minor code cleanup.
20070605	Moving src/useremul.c into a subdir (src/useremul/), and
		cleaning up some more legacy constructs.
		Adding -Wstrict-aliasing and -fstrict-aliasing detection to
		the configure script.
20070606	Adding a check for broken GCC on Solaris to the configure
		script. (GCC 3.4.3 on Solaris cannot handle static variables
		which are initialized to 0 or NULL. :-/)
		Removing the old (non-working) ARC emulation modes: NEC RD94,
		R94, R96, and R98, and the last traces of Olivetti M700 and
		Deskstation Tyne.
		Removing the non-working skeleton WDSC device (dev_wdsc).
20070607	Thinking about how to use the host's cc + ld at runtime to
		generate native code. (See experiments/native_cc_ld_test.i
		for an example.)
20070608	Adding a program counter sampling timer, which could be useful
		for native code generation experiments.
		The KN02_CSR_NRMMOD bit in the DECstation 5000/200 (KN02) CSR
		should always be set, to allow a 5000/200 PROM to boot.
20070609	Moving out breakpoint details from the machine struct into
		a helper struct, and removing the limit on max nr of
		breakpoints.
20070610	Moving out tick functions into a helper struct as well (which
		also gets rid of the max limit).
20070612	FINALLY figured out why Debian/DECstation stopped working when
		translation read-ahead was enabled: in src/memory_rw.c, the
		call to invalidate_code_translation was made also if the
		memory access was an instruction load (if the page was mapped
		as writable); it shouldn't be called in that case.
20070613	Implementing some more MIPS32/64 revision 2 instructions: di,
		ei, ext, dext, dextm, dextu, and ins.
20070614	Implementing an instruction combination for the NetBSD/arm
		idle loop (making the host not use any cpu if NetBSD/arm
		inside the emulator is not using any cpu).
		Increasing the nr of ARM VPH entries from 128 to 384.
20070615	Removing the ENABLE_arch stuff from the configure script, so
		that all included architectures are included in both release
		and development builds.
		Moving memory related helper functions from misc.c to memory.c.
		Adding preliminary instructions for netbooting NetBSD/pmppc to
		guestoses.html; it doesn't work yet, there are weird timeouts.
		Beginning a total rewrite of the userland emulation modes
		(removing all emulation modes, beginning from scratch with
		NetBSD/MIPS and FreeBSD/Alpha only).
20070616	After fixing a bug in the DEC21143 NIC (the TDSTAT_OWN bit was
		only cleared for the last segment when transmitting, not all
		segments), NetBSD/pmppc boots with root-on-nfs without the
		timeouts. Updating guestoses.html.
		Removing the skeleton PSP (Playstation Portable) mode.
		Moving X11-related stuff in the machine struct into a helper
		struct.
		Cleanup of out-of-memory checks, to use a new CHECK_ALLOCATION
		macro (which prints a meaningful error message).
		Adding a COMMENT to each machine and device (for automagic
		.index comment generation).
		Doing regression testing for the next release.

==============  RELEASE 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_turbochannel.c,v 1.50 2007/06/15 19:57:34 debug Exp $
29 *
30 * COMMENT: TURBOchannel bus framework, used in DECstation machines
31 */
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37 #include "devices.h"
38 #include "machine.h"
39 #include "memory.h"
40 #include "misc.h"
41 #include "sfbreg.h"
42
43
44 #define DEVICE_MAX_NAMELEN 9
45 #define CARD_NAME_BUFLEN 9
46 #define CARD_FIRMWARE_BUFLEN 5
47
48 struct turbochannel_data {
49 int slot_nr;
50 uint64_t baseaddr;
51 uint64_t endaddr;
52
53 int rom_skip;
54
55 char device_name[DEVICE_MAX_NAMELEN]; /* NUL-terminated */
56
57 /* These should be terminated with spaces */
58 char card_firmware_version[CARD_NAME_BUFLEN];
59 char card_vendor_name[CARD_NAME_BUFLEN];
60 char card_module_name[CARD_NAME_BUFLEN];
61 char card_firmware_type[CARD_FIRMWARE_BUFLEN];
62 };
63
64
65 DEVICE_ACCESS(turbochannel)
66 {
67 struct turbochannel_data *d = extra;
68 uint64_t idata = 0, odata = 0;
69
70 if (writeflag == MEM_WRITE)
71 idata = memory_readmax64(cpu, data, len);
72
73 relative_addr += d->rom_skip;
74
75 if (writeflag == MEM_READ) {
76 debug("[ turbochannel: read from slot %i addr 0x%08lx (",
77 d->slot_nr, (long)relative_addr);
78
79 relative_addr &= 0x7fff;
80
81 switch (relative_addr) {
82 case 0x3e0:
83 odata = 0x00000001; debug("ROM width");
84 break;
85 case 0x3e4:
86 odata = 0x00000004; debug("ROM stride");
87 break;
88 case 0x3e8:
89 /* 8KB * romsize */
90 odata = 0x00000001; debug("ROM size");
91 break;
92 case 0x3ec:
93 /* 4MB * slotsize */
94 odata = 0x00000001; debug("slot size");
95 break;
96 case 0x3f0:
97 odata = 0x55555555; debug("ROM signature byte 0");
98 break;
99 case 0x3f4:
100 odata = 0x00000000; debug("ROM signature byte 1");
101 break;
102 case 0x3f8:
103 odata = 0xaaaaaaaa; debug("ROM signature byte 2");
104 break;
105 case 0x3fc:
106 odata = 0xffffffff; debug("ROM signature byte 3");
107 break;
108 case 0x470:
109 /* 0=nothing, 1=parity */
110 odata = 0x00000000; debug("flags"); break;
111 default:
112 if (relative_addr >= 0x400 && relative_addr < 0x420)
113 odata = d->card_firmware_version[
114 (relative_addr-0x400)/4];
115 else if (relative_addr >= 0x420 &&
116 relative_addr < 0x440)
117 odata = d->card_vendor_name[
118 (relative_addr-0x420)/4];
119 else if (relative_addr >= 0x440 &&
120 relative_addr < 0x460)
121 odata = d->card_module_name[
122 (relative_addr-0x440)/4];
123 else if (relative_addr >= 0x460 &&
124 relative_addr < 0x470)
125 odata = d->card_firmware_type[
126 (relative_addr-0x460)/4];
127 else {
128 debug("?");
129 }
130 }
131
132 /*
133 * If this slot is empty, return an error so that a DBE
134 * exception is caused. (This is the way DECstation operating
135 * systems have to detect the absence of cards in a
136 * TURBOchannel slot.)
137 *
138 * NOTE: The Sprite kernel reads from offsets 0x3e0..0x400
139 * without handling the DBE exception, and both Ultrix and
140 * NetBSD seem to detect the DBE exception using addresses
141 * around offset 0x0 or 0x3c0000. This code seems to work
142 * with all of the those OS kernels:
143 */
144 if (d->card_module_name[0] == ' ') {
145 /* Return no data for empty slot: */
146 odata = 0;
147
148 /* Return DBE exception in some cases: */
149 if (relative_addr < 0x3e0 || relative_addr >= 0x500)
150 return 0;
151 }
152
153 debug(") ]\n");
154 } else {
155 /* debug("[ turbochannel: write to 0x%08lx: 0x%08x ]\n",
156 (long)relative_addr, (int)idata); */
157 }
158
159 if (writeflag == MEM_READ)
160 memory_writemax64(cpu, data, len, odata);
161
162 return 1;
163 }
164
165
166 /*
167 * dev_turbochannel_init():
168 *
169 * This is a generic turbochannel card device. device_name should point
170 * to a string such as "PMAG-BA".
171 *
172 * TODO: When running for example dual-head, maybe the name of each
173 * framebuffer should include the card slot number?
174 */
175 void dev_turbochannel_init(struct machine *machine, struct memory *mem,
176 int slot_nr, uint64_t baseaddr, uint64_t endaddr,
177 char *device_name, char *irq_path)
178 {
179 struct vfb_data *fb;
180 struct turbochannel_data *d;
181 int rom_offset=0x3c0000, rom_length=DEV_TURBOCHANNEL_LEN, rom_skip=0;
182 char *name2;
183 size_t nlen;
184
185 if (device_name == NULL)
186 return;
187
188 if (strlen(device_name) > 8) {
189 fprintf(stderr, "dev_turbochannel_init(): bad device_name\n");
190 exit(1);
191 }
192
193 CHECK_ALLOCATION(d = malloc(sizeof(struct turbochannel_data)));
194 memset(d, 0, sizeof(struct turbochannel_data));
195
196 d->slot_nr = slot_nr;
197 d->baseaddr = baseaddr;
198 d->endaddr = endaddr;
199
200 strlcpy(d->device_name, device_name, DEVICE_MAX_NAMELEN);
201
202 strncpy(d->card_firmware_version, "V5.3a ", CARD_NAME_BUFLEN);
203 strncpy(d->card_vendor_name, "DEC ", CARD_NAME_BUFLEN);
204 strncpy(d->card_firmware_type, "TCF0", CARD_FIRMWARE_BUFLEN);
205
206 memset(d->card_module_name, ' ', 8);
207 memcpy(d->card_module_name, device_name, strlen(device_name));
208
209 /*
210 * According to NetBSD/pmax:
211 *
212 * PMAD-AA: le1 at tc0 slot 2 offset 0x0: address 00:00:00:00:00:00
213 * PMAG-AA: mfb0 at tc0 slot 2 offset 0x0: 1280x1024x8
214 * PMAG-BA: cfb0 at tc0 slot 2 offset 0x0cfb0: 1024x864x8
215 * PMAG-CA: px0 at tc0 slot 2 offset 0x0: 2D, 4x1 stamp, 8 plane
216 * (PMAG-DA,EA,FA,FB are also pixelstamps)
217 * PMAG-DV: xcfb0 at tc0 slot 2 offset 0x0: 1024x768x8
218 * PMAG-JA: "truecolor" in Ultrix
219 * PMAGB-BA: sfb0 at tc0 slot 0 offset 0x0: 0x0x8
220 * PMAGB-VA: sfb0 at tc0 slot 2 offset 0x0: 0x0x8
221 * PMAZ-AA: asc0 at tc0 slot 2 offset 0x0: NCR53C94, 25MHz, SCSI ID 7
222 *
223 * PMAF-FA: fta0 at tc0 slot 0 (fddi network, "DEC", "V1.0b")
224 */
225
226 if (strcmp(device_name, "PMAD-AA")==0) {
227 /* le in NetBSD, Lance ethernet */
228 dev_le_init(machine, mem, baseaddr, 0, 0,
229 irq_path, DEV_LE_LENGTH);
230 /* One ROM at 0x1c03e0, and one at 0x3c0000. */
231 rom_skip = 0x300;
232 rom_offset = 0x1c0000;
233 rom_length = 0x201000;
234 } else if (strcmp(device_name, "PMAZ-AA")==0) {
235 /* asc in NetBSD, SCSI */
236 dev_asc_init(machine, mem, baseaddr, irq_path, d,
237 DEV_ASC_DEC, NULL, NULL);
238 rom_offset = 0xc0000;
239 /* There is a copy at 0x0, at least that's where Linux
240 looks for the rom signature */
241 } else if (strcmp(device_name, "PMAG-AA")==0) {
242 /* mfb in NetBSD */
243 fb = dev_fb_init(machine, mem, baseaddr + VFB_MFB_VRAM,
244 VFB_GENERIC, 1280, 1024, 2048, 1024, 8, device_name);
245 /* bt455 = palette, bt431 = cursor */
246 dev_bt455_init(mem, baseaddr + VFB_MFB_BT455, fb);
247 dev_bt431_init(mem, baseaddr + VFB_MFB_BT431, fb, 8);
248 rom_offset = 0;
249 } else if (strcmp(device_name, "PMAG-BA")==0) {
250 /* cfb in NetBSD */
251 fb = dev_fb_init(machine, mem, baseaddr, VFB_GENERIC,
252 1024,864, 1024,1024,8, device_name);
253 dev_bt459_init(machine, mem, baseaddr + VFB_CFB_BT459,
254 baseaddr + 0x300000, fb, 8, irq_path, BT459_BA);
255 /* ROM at both 0x380000 and 0x3c0000? */
256 rom_offset = 0x380000;
257 rom_length = 0x080000;
258 } else if (strcmp(device_name, "PMAGB-BA")==0) {
259 /* sfb in NetBSD */
260 /* TODO: This is not working with Ultrix yet. */
261 fb = dev_fb_init(machine, mem, baseaddr + SFB_OFFSET_VRAM,
262 VFB_GENERIC, 1280,1024, 1280,1024,8, device_name);
263 dev_sfb_init(machine, mem, baseaddr + SFB_ASIC_OFFSET, fb);
264 /* TODO: the CLEAR doesn't get through, as the address
265 range is already in use by the asic */
266 dev_bt459_init(machine, mem, baseaddr + SFB_OFFSET_BT459,
267 baseaddr + SFB_CLEAR, fb, 8, irq_path, BT459_BBA);
268 rom_offset = 0x0; /* ? TODO */
269 } else if (strcmp(device_name, "PMAG-CA")==0) {
270 /* px in NetBSD */
271 dev_px_init(machine, mem, baseaddr, DEV_PX_TYPE_PX, irq_path);
272 rom_offset = 0x3c0000;
273 } else if (strcmp(device_name, "PMAG-DA")==0) {
274 /* pxg in NetBSD */
275 dev_px_init(machine, mem, baseaddr, DEV_PX_TYPE_PXG, irq_path);
276 rom_offset = 0x3c0000;
277 } else if (strcmp(device_name, "PMAG-EA")==0) {
278 /* pxg+ in NetBSD: TODO (not supported by the kernel
279 I've tried) */
280 fatal("TODO (see dev_turbochannel.c)\n");
281 rom_offset = 0x3c0000;
282 } else if (strcmp(device_name, "PMAG-FA")==0) {
283 /* "pxg+ Turbo" in NetBSD */
284 dev_px_init(machine, mem, baseaddr,
285 DEV_PX_TYPE_PXGPLUSTURBO, irq_path);
286 rom_offset = 0x3c0000;
287 } else if (strcmp(device_name, "PMAG-DV")==0) {
288 /* xcfb in NetBSD: TODO */
289 fb = dev_fb_init(machine, mem, baseaddr + 0x2000000,
290 VFB_DEC_MAXINE, 0, 0, 0, 0, 0, "PMAG-DV");
291 /* TODO: not yet usable, needs a IMS332 vdac */
292 rom_offset = 0x3c0000;
293 } else if (strcmp(device_name, "PMAG-JA")==0) {
294 /* "Truecolor", mixed 8- and 24-bit */
295 dev_pmagja_init(machine, mem, baseaddr, irq_path);
296 rom_offset = 0; /* NOTE: 0, not 0x3c0000 */
297 } else if (strcmp(device_name, "PMAG-RO")==0) {
298 /* This works at least B/W in Ultrix, so far. */
299 fb = dev_fb_init(machine, mem, baseaddr + 0x200000,
300 VFB_GENERIC, 1280,1024, 1280,1024, 8, "PMAG-RO");
301 /* TODO: bt463 at offset 0x040000, not bt459 */
302 dev_bt459_init(machine, mem, baseaddr + 0x40000, 0,
303 fb, 8, irq_path, 0); /* TODO: type */
304 dev_bt431_init(mem, baseaddr + 0x40010, fb, 8); /* cursor */
305 rom_offset = 0x3c0000;
306 } else if (device_name[0] == '\0') {
307 /* If this slot is empty, then occupy the entire
308 4MB slot address range: */
309 rom_offset = 0;
310 rom_length = 4*1048576;
311 } else {
312 fatal("warning: unknown TURBOchannel device name \"%s\"\n",
313 device_name);
314 }
315
316 d->rom_skip = rom_skip;
317
318 nlen = strlen(device_name) + 30;
319 CHECK_ALLOCATION(name2 = malloc(nlen));
320
321 if (*device_name)
322 snprintf(name2, nlen, "turbochannel [%s]", device_name);
323 else
324 snprintf(name2, nlen, "turbochannel");
325
326 memory_device_register(mem, name2, baseaddr + rom_offset + rom_skip,
327 rom_length-rom_skip, dev_turbochannel_access, d, DM_DEFAULT, NULL);
328 }
329

  ViewVC Help
Powered by ViewVC 1.1.26