/[gxemul]/upstream/0.3.8/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.3.8/src/devices/dev_kn02.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (show annotations)
Mon Oct 8 16:19:43 2007 UTC (16 years, 7 months ago) by dpavlin
File MIME type: text/plain
File size: 3524 byte(s)
0.3.8
1 /*
2 * Copyright (C) 2003-2006 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.21 2006/01/01 13:17:16 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 DEVICE_ACCESS(kn02)
50 {
51 struct kn02_csr *d = extra;
52 uint64_t idata = 0, odata = 0;
53
54 if (writeflag == MEM_WRITE)
55 idata = memory_readmax64(cpu, data, len);
56
57 switch (relative_addr) {
58 case 0:
59 if (writeflag==MEM_READ) {
60 odata = d->csr[0] + (d->csr[1] << 8) +
61 (d->csr[2] << 16) + (d->csr[3] << 24);
62 /* debug("[ kn02: read from CSR: 0x%08x ]\n", odata); */
63 } else {
64 /*
65 * Only bits 23..8 are considered writable. The
66 * lowest 8 bits are actually writable, but don't
67 * affect the interrupt I/O bits; the low 8 bits
68 * on write turn on and off LEDs. (There are no
69 * LEDs in the emulator, so those bits are just
70 * ignored.)
71 */
72 /* fatal("[ kn02: write to CSR: 0x%08x ]\n", idata); */
73
74 d->csr[1] = (idata >> 8) & 255;
75 d->csr[2] = (idata >> 16) & 255;
76
77 /* Recalculate interrupt assertions: */
78 cpu_interrupt(cpu, 8);
79 }
80 break;
81 default:
82 if (writeflag==MEM_READ) {
83 debug("[ kn02: read from 0x%08lx ]\n",
84 (long)relative_addr);
85 } else {
86 debug("[ kn02: write to 0x%08lx: 0x%08x ]\n",
87 (long)relative_addr, (int)idata);
88 }
89 }
90
91 if (writeflag == MEM_READ)
92 memory_writemax64(cpu, data, len, odata);
93
94 return 1;
95 }
96
97
98 /*
99 * dev_kn02_init():
100 */
101 struct kn02_csr *dev_kn02_init(struct cpu *cpu, struct memory *mem,
102 uint64_t baseaddr)
103 {
104 struct kn02_csr *d;
105
106 d = malloc(sizeof(struct kn02_csr));
107 if (d == NULL) {
108 fprintf(stderr, "out of memory\n");
109 exit(1);
110 }
111 memset(d, 0, sizeof(struct kn02_csr));
112
113 memory_device_register(mem, "kn02", baseaddr, DEV_KN02_LENGTH,
114 dev_kn02_access, d, DM_DYNTRANS_OK, &d->csr[0]);
115
116 return d;
117 }
118

  ViewVC Help
Powered by ViewVC 1.1.26