/[gxemul]/upstream/0.4.2/src/devices/dev_gc.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.2/src/devices/dev_gc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations)
Mon Oct 8 16:20:48 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 4336 byte(s)
0.4.2
1 /*
2 * Copyright (C) 2005-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 * $Id: dev_gc.c,v 1.8 2006/02/27 05:32:26 debug Exp $
28 *
29 * Grand Central Interrupt controller (used by MacPPC).
30 */
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include "cpu.h"
37 #include "device.h"
38 #include "devices.h"
39 #include "machine.h"
40 #include "memory.h"
41 #include "misc.h"
42
43
44 DEVICE_ACCESS(gc)
45 {
46 struct gc_data *d = extra;
47 uint64_t idata = 0, odata = 0;
48
49 if (writeflag == MEM_WRITE)
50 idata = memory_readmax64(cpu, data, len);
51
52 switch (relative_addr) {
53
54 #if 0
55 #define INT_STATE_REG_H (interrupt_reg + 0x00)
56 #define INT_ENABLE_REG_H (interrupt_reg + 0x04)
57 #define INT_CLEAR_REG_H (interrupt_reg + 0x08)
58 #define INT_LEVEL_REG_H (interrupt_reg + 0x0c)
59 #define INT_STATE_REG_L (interrupt_reg + 0x10)
60 #define INT_ENABLE_REG_L (interrupt_reg + 0x14)
61 #define INT_CLEAR_REG_L (interrupt_reg + 0x18)
62 #define INT_LEVEL_REG_L (interrupt_reg + 0x1c)
63 #endif
64
65 case 0x10:
66 if (writeflag == MEM_READ)
67 odata = d->status_hi & d->enable_hi;
68 break;
69
70 case 0x14:
71 if (writeflag == MEM_READ)
72 odata = d->enable_hi;
73 else {
74 uint32_t old_enable_hi = d->enable_hi;
75 d->enable_hi = idata;
76 if (d->enable_hi != old_enable_hi)
77 cpu_interrupt(cpu, d->reassert_irq);
78 }
79 break;
80
81 case 0x18:
82 if (writeflag == MEM_WRITE) {
83 uint32_t old_status_hi = d->status_hi;
84 d->status_hi &= ~idata;
85 if (d->status_hi != old_status_hi)
86 cpu_interrupt(cpu, d->reassert_irq);
87 }
88 break;
89
90 case 0x20:
91 if (writeflag == MEM_READ)
92 odata = d->status_lo & d->enable_lo;
93 break;
94
95 case 0x24:
96 if (writeflag == MEM_READ)
97 odata = d->enable_lo;
98 else {
99 uint32_t old_enable_lo = d->enable_lo;
100 d->enable_lo = idata;
101 if (d->enable_lo != old_enable_lo)
102 cpu_interrupt(cpu, d->reassert_irq);
103 }
104 break;
105
106 case 0x28:
107 if (writeflag == MEM_WRITE) {
108 uint32_t old_status_lo = d->status_lo;
109 d->status_lo &= ~idata;
110 if (d->status_lo != old_status_lo)
111 cpu_interrupt(cpu, d->reassert_irq);
112 }
113 break;
114
115 case 0x2c:
116 /* Avoir a debug message. */
117 break;
118
119 default:if (writeflag == MEM_WRITE) {
120 fatal("[ gc: unimplemented write to "
121 "offset 0x%x: data=0x%x ]\n", (int)
122 relative_addr, (int)idata);
123 } else {
124 fatal("[ gc: unimplemented read from "
125 "offset 0x%x ]\n", (int)relative_addr);
126 }
127 }
128
129 if (writeflag == MEM_READ)
130 memory_writemax64(cpu, data, len, odata);
131
132 return 1;
133 }
134
135
136 /*
137 * dev_gc_init():
138 */
139 struct gc_data *dev_gc_init(struct machine *machine, struct memory *mem,
140 uint64_t addr, int reassert_irq)
141 {
142 struct gc_data *d;
143
144 d = malloc(sizeof(struct gc_data));
145 if (d == NULL) {
146 fprintf(stderr, "out of memory\n");
147 exit(1);
148 }
149 memset(d, 0, sizeof(struct gc_data));
150 d->reassert_irq = reassert_irq;
151
152 memory_device_register(mem, "gc", addr, 0x100,
153 dev_gc_access, d, DM_DEFAULT, NULL);
154
155 return d;
156 }
157

  ViewVC Help
Powered by ViewVC 1.1.26