1 |
/* |
2 |
* Copyright (C) 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_malta.c,v 1.2 2005/06/22 00:39:45 debug Exp $ |
29 |
* |
30 |
* Malta (evbmips) interrupt controller. |
31 |
* |
32 |
* TODO: This is basically a dummy device so far. |
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 "devices.h" |
42 |
#include "emul.h" |
43 |
#include "machine.h" |
44 |
#include "memory.h" |
45 |
#include "misc.h" |
46 |
|
47 |
|
48 |
/* |
49 |
* dev_malta_hi_access(): |
50 |
*/ |
51 |
int dev_malta_hi_access(struct cpu *cpu, struct memory *mem, |
52 |
uint64_t relative_addr, unsigned char *data, size_t len, |
53 |
int writeflag, void *extra) |
54 |
{ |
55 |
struct malta_data *d = (struct malta_data *) extra; |
56 |
uint64_t idata = 0, odata = 0; |
57 |
int i; |
58 |
|
59 |
idata = memory_readmax64(cpu, data, len); |
60 |
|
61 |
switch (relative_addr) { |
62 |
case 0: if (writeflag == MEM_READ) { |
63 |
odata = 0; |
64 |
for (i=0; i<7; i++) |
65 |
if (d->assert_hi & (1<<i)) |
66 |
odata = i; |
67 |
if (odata) |
68 |
odata |= 0x80; |
69 |
d->assert_hi = 0; |
70 |
cpu_interrupt_ack(cpu, 8 + 2); |
71 |
} else { |
72 |
/* TODO */ |
73 |
} |
74 |
break; |
75 |
default:if (writeflag == MEM_WRITE) { |
76 |
fatal("[ malta: hi unimplemented write to " |
77 |
"offset 0x%x: data=0x%02x ]\n", (int) |
78 |
relative_addr, (int)idata); |
79 |
} else { |
80 |
fatal("[ malta: hi unimplemented read from " |
81 |
"offset 0x%x ]\n", (int)relative_addr); |
82 |
} |
83 |
} |
84 |
|
85 |
if (writeflag == MEM_READ) |
86 |
memory_writemax64(cpu, data, len, odata); |
87 |
|
88 |
return 1; |
89 |
} |
90 |
|
91 |
|
92 |
/* |
93 |
* dev_malta_access(): |
94 |
*/ |
95 |
int dev_malta_access(struct cpu *cpu, struct memory *mem, |
96 |
uint64_t relative_addr, unsigned char *data, size_t len, |
97 |
int writeflag, void *extra) |
98 |
{ |
99 |
struct malta_data *d = (struct malta_data *) extra; |
100 |
uint64_t idata = 0, odata = 0; |
101 |
int i; |
102 |
|
103 |
idata = memory_readmax64(cpu, data, len); |
104 |
|
105 |
switch (relative_addr) { |
106 |
case 0: if (writeflag == MEM_READ) { |
107 |
odata = 0; |
108 |
for (i=0; i<7; i++) |
109 |
if (d->assert_lo & (1<<i)) |
110 |
odata = i; |
111 |
if (odata) |
112 |
odata |= 0x80; |
113 |
d->assert_lo = 0; |
114 |
cpu_interrupt_ack(cpu, 8 + 16); |
115 |
} else { |
116 |
/* TODO */ |
117 |
} |
118 |
break; |
119 |
default:if (writeflag == MEM_WRITE) { |
120 |
fatal("[ malta: unimplemented write to " |
121 |
"offset 0x%x: data=0x%02x ]\n", (int) |
122 |
relative_addr, (int)idata); |
123 |
} else { |
124 |
fatal("[ malta: 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 |
* devinit_malta(): |
138 |
*/ |
139 |
int devinit_malta(struct devinit *devinit) |
140 |
{ |
141 |
struct malta_data *d = malloc(sizeof(struct malta_data)); |
142 |
|
143 |
if (d == NULL) { |
144 |
fprintf(stderr, "out of memory\n"); |
145 |
exit(1); |
146 |
} |
147 |
memset(d, 0, sizeof(struct malta_data)); |
148 |
|
149 |
memory_device_register(devinit->machine->memory, devinit->name, |
150 |
devinit->addr, 1, |
151 |
dev_malta_access, (void *)d, MEM_DEFAULT, NULL); |
152 |
memory_device_register(devinit->machine->memory, devinit->name, |
153 |
devinit->addr + 0x80, 1, |
154 |
dev_malta_hi_access, (void *)d, MEM_DEFAULT, NULL); |
155 |
|
156 |
devinit->return_ptr = d; |
157 |
|
158 |
return 1; |
159 |
} |
160 |
|