Statistics
| Branch: | Revision:

root / hw / sh7750.c @ 8c5e95d8

History | View | Annotate | Download (16.9 kB)

1 27c7ca7e bellard
/*
2 27c7ca7e bellard
 * SH7750 device
3 5fafdf24 ths
 *
4 80f515e6 balrog
 * Copyright (c) 2007 Magnus Damm
5 27c7ca7e bellard
 * Copyright (c) 2005 Samuel Tardieu
6 5fafdf24 ths
 *
7 27c7ca7e bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 27c7ca7e bellard
 * of this software and associated documentation files (the "Software"), to deal
9 27c7ca7e bellard
 * in the Software without restriction, including without limitation the rights
10 27c7ca7e bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 27c7ca7e bellard
 * copies of the Software, and to permit persons to whom the Software is
12 27c7ca7e bellard
 * furnished to do so, subject to the following conditions:
13 27c7ca7e bellard
 *
14 27c7ca7e bellard
 * The above copyright notice and this permission notice shall be included in
15 27c7ca7e bellard
 * all copies or substantial portions of the Software.
16 27c7ca7e bellard
 *
17 27c7ca7e bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 27c7ca7e bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 27c7ca7e bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 27c7ca7e bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 27c7ca7e bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 27c7ca7e bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 27c7ca7e bellard
 * THE SOFTWARE.
24 27c7ca7e bellard
 */
25 27c7ca7e bellard
#include <stdio.h>
26 27c7ca7e bellard
#include <assert.h>
27 87ecb68b pbrook
#include "hw.h"
28 87ecb68b pbrook
#include "sh.h"
29 87ecb68b pbrook
#include "sysemu.h"
30 27c7ca7e bellard
#include "sh7750_regs.h"
31 27c7ca7e bellard
#include "sh7750_regnames.h"
32 80f515e6 balrog
#include "sh_intc.h"
33 27c7ca7e bellard
34 27c7ca7e bellard
#define NB_DEVICES 4
35 27c7ca7e bellard
36 27c7ca7e bellard
typedef struct SH7750State {
37 27c7ca7e bellard
    /* CPU */
38 27c7ca7e bellard
    CPUSH4State *cpu;
39 27c7ca7e bellard
    /* Peripheral frequency in Hz */
40 27c7ca7e bellard
    uint32_t periph_freq;
41 27c7ca7e bellard
    /* SDRAM controller */
42 27c7ca7e bellard
    uint16_t rfcr;
43 27c7ca7e bellard
    /* IO ports */
44 27c7ca7e bellard
    uint16_t gpioic;
45 27c7ca7e bellard
    uint32_t pctra;
46 27c7ca7e bellard
    uint32_t pctrb;
47 27c7ca7e bellard
    uint16_t portdira;                /* Cached */
48 27c7ca7e bellard
    uint16_t portpullupa;        /* Cached */
49 27c7ca7e bellard
    uint16_t portdirb;                /* Cached */
50 27c7ca7e bellard
    uint16_t portpullupb;        /* Cached */
51 27c7ca7e bellard
    uint16_t pdtra;
52 27c7ca7e bellard
    uint16_t pdtrb;
53 27c7ca7e bellard
    uint16_t periph_pdtra;        /* Imposed by the peripherals */
54 27c7ca7e bellard
    uint16_t periph_portdira;        /* Direction seen from the peripherals */
55 27c7ca7e bellard
    uint16_t periph_pdtrb;        /* Imposed by the peripherals */
56 27c7ca7e bellard
    uint16_t periph_portdirb;        /* Direction seen from the peripherals */
57 27c7ca7e bellard
    sh7750_io_device *devices[NB_DEVICES];        /* External peripherals */
58 3464c589 ths
59 3464c589 ths
    uint16_t icr;
60 27c7ca7e bellard
    /* Cache */
61 27c7ca7e bellard
    uint32_t ccr;
62 27c7ca7e bellard
63 80f515e6 balrog
    struct intc_desc intc;
64 cd1a3f68 ths
} SH7750State;
65 27c7ca7e bellard
66 27c7ca7e bellard
67 27c7ca7e bellard
/**********************************************************************
68 27c7ca7e bellard
 I/O ports
69 27c7ca7e bellard
**********************************************************************/
70 27c7ca7e bellard
71 27c7ca7e bellard
int sh7750_register_io_device(SH7750State * s, sh7750_io_device * device)
72 27c7ca7e bellard
{
73 27c7ca7e bellard
    int i;
74 27c7ca7e bellard
75 27c7ca7e bellard
    for (i = 0; i < NB_DEVICES; i++) {
76 27c7ca7e bellard
        if (s->devices[i] == NULL) {
77 27c7ca7e bellard
            s->devices[i] = device;
78 27c7ca7e bellard
            return 0;
79 27c7ca7e bellard
        }
80 27c7ca7e bellard
    }
81 27c7ca7e bellard
    return -1;
82 27c7ca7e bellard
}
83 27c7ca7e bellard
84 27c7ca7e bellard
static uint16_t portdir(uint32_t v)
85 27c7ca7e bellard
{
86 27c7ca7e bellard
#define EVENPORTMASK(n) ((v & (1<<((n)<<1))) >> (n))
87 27c7ca7e bellard
    return
88 27c7ca7e bellard
        EVENPORTMASK(15) | EVENPORTMASK(14) | EVENPORTMASK(13) |
89 27c7ca7e bellard
        EVENPORTMASK(12) | EVENPORTMASK(11) | EVENPORTMASK(10) |
90 27c7ca7e bellard
        EVENPORTMASK(9) | EVENPORTMASK(8) | EVENPORTMASK(7) |
91 27c7ca7e bellard
        EVENPORTMASK(6) | EVENPORTMASK(5) | EVENPORTMASK(4) |
92 27c7ca7e bellard
        EVENPORTMASK(3) | EVENPORTMASK(2) | EVENPORTMASK(1) |
93 27c7ca7e bellard
        EVENPORTMASK(0);
94 27c7ca7e bellard
}
95 27c7ca7e bellard
96 27c7ca7e bellard
static uint16_t portpullup(uint32_t v)
97 27c7ca7e bellard
{
98 27c7ca7e bellard
#define ODDPORTMASK(n) ((v & (1<<(((n)<<1)+1))) >> (n))
99 27c7ca7e bellard
    return
100 27c7ca7e bellard
        ODDPORTMASK(15) | ODDPORTMASK(14) | ODDPORTMASK(13) |
101 27c7ca7e bellard
        ODDPORTMASK(12) | ODDPORTMASK(11) | ODDPORTMASK(10) |
102 27c7ca7e bellard
        ODDPORTMASK(9) | ODDPORTMASK(8) | ODDPORTMASK(7) | ODDPORTMASK(6) |
103 27c7ca7e bellard
        ODDPORTMASK(5) | ODDPORTMASK(4) | ODDPORTMASK(3) | ODDPORTMASK(2) |
104 27c7ca7e bellard
        ODDPORTMASK(1) | ODDPORTMASK(0);
105 27c7ca7e bellard
}
106 27c7ca7e bellard
107 27c7ca7e bellard
static uint16_t porta_lines(SH7750State * s)
108 27c7ca7e bellard
{
109 27c7ca7e bellard
    return (s->portdira & s->pdtra) |        /* CPU */
110 27c7ca7e bellard
        (s->periph_portdira & s->periph_pdtra) |        /* Peripherals */
111 27c7ca7e bellard
        (~(s->portdira | s->periph_portdira) & s->portpullupa);        /* Pullups */
112 27c7ca7e bellard
}
113 27c7ca7e bellard
114 27c7ca7e bellard
static uint16_t portb_lines(SH7750State * s)
115 27c7ca7e bellard
{
116 27c7ca7e bellard
    return (s->portdirb & s->pdtrb) |        /* CPU */
117 27c7ca7e bellard
        (s->periph_portdirb & s->periph_pdtrb) |        /* Peripherals */
118 27c7ca7e bellard
        (~(s->portdirb | s->periph_portdirb) & s->portpullupb);        /* Pullups */
119 27c7ca7e bellard
}
120 27c7ca7e bellard
121 27c7ca7e bellard
static void gen_port_interrupts(SH7750State * s)
122 27c7ca7e bellard
{
123 27c7ca7e bellard
    /* XXXXX interrupts not generated */
124 27c7ca7e bellard
}
125 27c7ca7e bellard
126 27c7ca7e bellard
static void porta_changed(SH7750State * s, uint16_t prev)
127 27c7ca7e bellard
{
128 27c7ca7e bellard
    uint16_t currenta, changes;
129 27c7ca7e bellard
    int i, r = 0;
130 27c7ca7e bellard
131 27c7ca7e bellard
#if 0
132 27c7ca7e bellard
    fprintf(stderr, "porta changed from 0x%04x to 0x%04x\n",
133 27c7ca7e bellard
            prev, porta_lines(s));
134 27c7ca7e bellard
    fprintf(stderr, "pdtra=0x%04x, pctra=0x%08x\n", s->pdtra, s->pctra);
135 27c7ca7e bellard
#endif
136 27c7ca7e bellard
    currenta = porta_lines(s);
137 27c7ca7e bellard
    if (currenta == prev)
138 27c7ca7e bellard
        return;
139 27c7ca7e bellard
    changes = currenta ^ prev;
140 27c7ca7e bellard
141 27c7ca7e bellard
    for (i = 0; i < NB_DEVICES; i++) {
142 27c7ca7e bellard
        if (s->devices[i] && (s->devices[i]->portamask_trigger & changes)) {
143 27c7ca7e bellard
            r |= s->devices[i]->port_change_cb(currenta, portb_lines(s),
144 27c7ca7e bellard
                                               &s->periph_pdtra,
145 27c7ca7e bellard
                                               &s->periph_portdira,
146 27c7ca7e bellard
                                               &s->periph_pdtrb,
147 27c7ca7e bellard
                                               &s->periph_portdirb);
148 27c7ca7e bellard
        }
149 27c7ca7e bellard
    }
150 27c7ca7e bellard
151 27c7ca7e bellard
    if (r)
152 27c7ca7e bellard
        gen_port_interrupts(s);
153 27c7ca7e bellard
}
154 27c7ca7e bellard
155 27c7ca7e bellard
static void portb_changed(SH7750State * s, uint16_t prev)
156 27c7ca7e bellard
{
157 27c7ca7e bellard
    uint16_t currentb, changes;
158 27c7ca7e bellard
    int i, r = 0;
159 27c7ca7e bellard
160 27c7ca7e bellard
    currentb = portb_lines(s);
161 27c7ca7e bellard
    if (currentb == prev)
162 27c7ca7e bellard
        return;
163 27c7ca7e bellard
    changes = currentb ^ prev;
164 27c7ca7e bellard
165 27c7ca7e bellard
    for (i = 0; i < NB_DEVICES; i++) {
166 27c7ca7e bellard
        if (s->devices[i] && (s->devices[i]->portbmask_trigger & changes)) {
167 27c7ca7e bellard
            r |= s->devices[i]->port_change_cb(portb_lines(s), currentb,
168 27c7ca7e bellard
                                               &s->periph_pdtra,
169 27c7ca7e bellard
                                               &s->periph_portdira,
170 27c7ca7e bellard
                                               &s->periph_pdtrb,
171 27c7ca7e bellard
                                               &s->periph_portdirb);
172 27c7ca7e bellard
        }
173 27c7ca7e bellard
    }
174 27c7ca7e bellard
175 27c7ca7e bellard
    if (r)
176 27c7ca7e bellard
        gen_port_interrupts(s);
177 27c7ca7e bellard
}
178 27c7ca7e bellard
179 27c7ca7e bellard
/**********************************************************************
180 27c7ca7e bellard
 Memory
181 27c7ca7e bellard
**********************************************************************/
182 27c7ca7e bellard
183 27c7ca7e bellard
static void error_access(const char *kind, target_phys_addr_t addr)
184 27c7ca7e bellard
{
185 27c7ca7e bellard
    fprintf(stderr, "%s to %s (0x%08x) not supported\n",
186 27c7ca7e bellard
            kind, regname(addr), addr);
187 27c7ca7e bellard
}
188 27c7ca7e bellard
189 27c7ca7e bellard
static void ignore_access(const char *kind, target_phys_addr_t addr)
190 27c7ca7e bellard
{
191 27c7ca7e bellard
    fprintf(stderr, "%s to %s (0x%08x) ignored\n",
192 27c7ca7e bellard
            kind, regname(addr), addr);
193 27c7ca7e bellard
}
194 27c7ca7e bellard
195 27c7ca7e bellard
static uint32_t sh7750_mem_readb(void *opaque, target_phys_addr_t addr)
196 27c7ca7e bellard
{
197 27c7ca7e bellard
    switch (addr) {
198 27c7ca7e bellard
    default:
199 27c7ca7e bellard
        error_access("byte read", addr);
200 27c7ca7e bellard
        assert(0);
201 27c7ca7e bellard
    }
202 27c7ca7e bellard
}
203 27c7ca7e bellard
204 27c7ca7e bellard
static uint32_t sh7750_mem_readw(void *opaque, target_phys_addr_t addr)
205 27c7ca7e bellard
{
206 27c7ca7e bellard
    SH7750State *s = opaque;
207 27c7ca7e bellard
208 27c7ca7e bellard
    switch (addr) {
209 ed8e0a4d ths
    case SH7750_FRQCR_A7:
210 ed8e0a4d ths
        return 0;
211 27c7ca7e bellard
    case SH7750_RFCR_A7:
212 27c7ca7e bellard
        fprintf(stderr,
213 27c7ca7e bellard
                "Read access to refresh count register, incrementing\n");
214 27c7ca7e bellard
        return s->rfcr++;
215 27c7ca7e bellard
    case SH7750_PDTRA_A7:
216 27c7ca7e bellard
        return porta_lines(s);
217 27c7ca7e bellard
    case SH7750_PDTRB_A7:
218 27c7ca7e bellard
        return portb_lines(s);
219 3464c589 ths
    case 0x1fd00000:
220 3464c589 ths
        return s->icr;
221 27c7ca7e bellard
    default:
222 27c7ca7e bellard
        error_access("word read", addr);
223 27c7ca7e bellard
        assert(0);
224 27c7ca7e bellard
    }
225 27c7ca7e bellard
}
226 27c7ca7e bellard
227 27c7ca7e bellard
static uint32_t sh7750_mem_readl(void *opaque, target_phys_addr_t addr)
228 27c7ca7e bellard
{
229 27c7ca7e bellard
    SH7750State *s = opaque;
230 27c7ca7e bellard
231 27c7ca7e bellard
    switch (addr) {
232 27c7ca7e bellard
    case SH7750_MMUCR_A7:
233 27c7ca7e bellard
        return s->cpu->mmucr;
234 27c7ca7e bellard
    case SH7750_PTEH_A7:
235 27c7ca7e bellard
        return s->cpu->pteh;
236 27c7ca7e bellard
    case SH7750_PTEL_A7:
237 27c7ca7e bellard
        return s->cpu->ptel;
238 27c7ca7e bellard
    case SH7750_TTB_A7:
239 27c7ca7e bellard
        return s->cpu->ttb;
240 27c7ca7e bellard
    case SH7750_TEA_A7:
241 27c7ca7e bellard
        return s->cpu->tea;
242 27c7ca7e bellard
    case SH7750_TRA_A7:
243 27c7ca7e bellard
        return s->cpu->tra;
244 27c7ca7e bellard
    case SH7750_EXPEVT_A7:
245 27c7ca7e bellard
        return s->cpu->expevt;
246 27c7ca7e bellard
    case SH7750_INTEVT_A7:
247 27c7ca7e bellard
        return s->cpu->intevt;
248 27c7ca7e bellard
    case SH7750_CCR_A7:
249 27c7ca7e bellard
        return s->ccr;
250 27c7ca7e bellard
    case 0x1f000030:                /* Processor version PVR */
251 27c7ca7e bellard
        return 0x00050000;        /* SH7750R */
252 27c7ca7e bellard
    case 0x1f000040:                /* Processor version CVR */
253 27c7ca7e bellard
        return 0x00110000;        /* Minimum caches */
254 27c7ca7e bellard
    case 0x1f000044:                /* Processor version PRR */
255 27c7ca7e bellard
        return 0x00000100;        /* SH7750R */
256 27c7ca7e bellard
    default:
257 27c7ca7e bellard
        error_access("long read", addr);
258 27c7ca7e bellard
        assert(0);
259 27c7ca7e bellard
    }
260 27c7ca7e bellard
}
261 27c7ca7e bellard
262 27c7ca7e bellard
static void sh7750_mem_writeb(void *opaque, target_phys_addr_t addr,
263 27c7ca7e bellard
                              uint32_t mem_value)
264 27c7ca7e bellard
{
265 27c7ca7e bellard
    switch (addr) {
266 27c7ca7e bellard
        /* PRECHARGE ? XXXXX */
267 27c7ca7e bellard
    case SH7750_PRECHARGE0_A7:
268 27c7ca7e bellard
    case SH7750_PRECHARGE1_A7:
269 27c7ca7e bellard
        ignore_access("byte write", addr);
270 27c7ca7e bellard
        return;
271 27c7ca7e bellard
    default:
272 27c7ca7e bellard
        error_access("byte write", addr);
273 27c7ca7e bellard
        assert(0);
274 27c7ca7e bellard
    }
275 27c7ca7e bellard
}
276 27c7ca7e bellard
277 27c7ca7e bellard
static void sh7750_mem_writew(void *opaque, target_phys_addr_t addr,
278 27c7ca7e bellard
                              uint32_t mem_value)
279 27c7ca7e bellard
{
280 27c7ca7e bellard
    SH7750State *s = opaque;
281 27c7ca7e bellard
    uint16_t temp;
282 27c7ca7e bellard
283 27c7ca7e bellard
    switch (addr) {
284 27c7ca7e bellard
        /* SDRAM controller */
285 27c7ca7e bellard
    case SH7750_BCR2_A7:
286 27c7ca7e bellard
    case SH7750_BCR3_A7:
287 27c7ca7e bellard
    case SH7750_RTCOR_A7:
288 27c7ca7e bellard
    case SH7750_RTCNT_A7:
289 27c7ca7e bellard
    case SH7750_RTCSR_A7:
290 27c7ca7e bellard
        ignore_access("word write", addr);
291 27c7ca7e bellard
        return;
292 27c7ca7e bellard
        /* IO ports */
293 27c7ca7e bellard
    case SH7750_PDTRA_A7:
294 27c7ca7e bellard
        temp = porta_lines(s);
295 27c7ca7e bellard
        s->pdtra = mem_value;
296 27c7ca7e bellard
        porta_changed(s, temp);
297 27c7ca7e bellard
        return;
298 27c7ca7e bellard
    case SH7750_PDTRB_A7:
299 27c7ca7e bellard
        temp = portb_lines(s);
300 27c7ca7e bellard
        s->pdtrb = mem_value;
301 27c7ca7e bellard
        portb_changed(s, temp);
302 27c7ca7e bellard
        return;
303 27c7ca7e bellard
    case SH7750_RFCR_A7:
304 27c7ca7e bellard
        fprintf(stderr, "Write access to refresh count register\n");
305 27c7ca7e bellard
        s->rfcr = mem_value;
306 27c7ca7e bellard
        return;
307 27c7ca7e bellard
    case SH7750_GPIOIC_A7:
308 27c7ca7e bellard
        s->gpioic = mem_value;
309 27c7ca7e bellard
        if (mem_value != 0) {
310 27c7ca7e bellard
            fprintf(stderr, "I/O interrupts not implemented\n");
311 27c7ca7e bellard
            assert(0);
312 27c7ca7e bellard
        }
313 27c7ca7e bellard
        return;
314 3464c589 ths
    case 0x1fd00000:
315 3464c589 ths
        s->icr = mem_value;
316 3464c589 ths
        return;
317 27c7ca7e bellard
    default:
318 27c7ca7e bellard
        error_access("word write", addr);
319 27c7ca7e bellard
        assert(0);
320 27c7ca7e bellard
    }
321 27c7ca7e bellard
}
322 27c7ca7e bellard
323 27c7ca7e bellard
static void sh7750_mem_writel(void *opaque, target_phys_addr_t addr,
324 27c7ca7e bellard
                              uint32_t mem_value)
325 27c7ca7e bellard
{
326 27c7ca7e bellard
    SH7750State *s = opaque;
327 27c7ca7e bellard
    uint16_t temp;
328 27c7ca7e bellard
329 27c7ca7e bellard
    switch (addr) {
330 27c7ca7e bellard
        /* SDRAM controller */
331 27c7ca7e bellard
    case SH7750_BCR1_A7:
332 27c7ca7e bellard
    case SH7750_BCR4_A7:
333 27c7ca7e bellard
    case SH7750_WCR1_A7:
334 27c7ca7e bellard
    case SH7750_WCR2_A7:
335 27c7ca7e bellard
    case SH7750_WCR3_A7:
336 27c7ca7e bellard
    case SH7750_MCR_A7:
337 27c7ca7e bellard
        ignore_access("long write", addr);
338 27c7ca7e bellard
        return;
339 27c7ca7e bellard
        /* IO ports */
340 27c7ca7e bellard
    case SH7750_PCTRA_A7:
341 27c7ca7e bellard
        temp = porta_lines(s);
342 27c7ca7e bellard
        s->pctra = mem_value;
343 27c7ca7e bellard
        s->portdira = portdir(mem_value);
344 27c7ca7e bellard
        s->portpullupa = portpullup(mem_value);
345 27c7ca7e bellard
        porta_changed(s, temp);
346 27c7ca7e bellard
        return;
347 27c7ca7e bellard
    case SH7750_PCTRB_A7:
348 27c7ca7e bellard
        temp = portb_lines(s);
349 27c7ca7e bellard
        s->pctrb = mem_value;
350 27c7ca7e bellard
        s->portdirb = portdir(mem_value);
351 27c7ca7e bellard
        s->portpullupb = portpullup(mem_value);
352 27c7ca7e bellard
        portb_changed(s, temp);
353 27c7ca7e bellard
        return;
354 27c7ca7e bellard
    case SH7750_MMUCR_A7:
355 27c7ca7e bellard
        s->cpu->mmucr = mem_value;
356 27c7ca7e bellard
        return;
357 27c7ca7e bellard
    case SH7750_PTEH_A7:
358 27c7ca7e bellard
        s->cpu->pteh = mem_value;
359 27c7ca7e bellard
        return;
360 27c7ca7e bellard
    case SH7750_PTEL_A7:
361 27c7ca7e bellard
        s->cpu->ptel = mem_value;
362 27c7ca7e bellard
        return;
363 ea2b542a aurel32
    case SH7750_PTEA_A7:
364 ea2b542a aurel32
        s->cpu->ptea = mem_value & 0x0000000f;
365 ea2b542a aurel32
        return;
366 27c7ca7e bellard
    case SH7750_TTB_A7:
367 27c7ca7e bellard
        s->cpu->ttb = mem_value;
368 27c7ca7e bellard
        return;
369 27c7ca7e bellard
    case SH7750_TEA_A7:
370 27c7ca7e bellard
        s->cpu->tea = mem_value;
371 27c7ca7e bellard
        return;
372 27c7ca7e bellard
    case SH7750_TRA_A7:
373 27c7ca7e bellard
        s->cpu->tra = mem_value & 0x000007ff;
374 27c7ca7e bellard
        return;
375 27c7ca7e bellard
    case SH7750_EXPEVT_A7:
376 27c7ca7e bellard
        s->cpu->expevt = mem_value & 0x000007ff;
377 27c7ca7e bellard
        return;
378 27c7ca7e bellard
    case SH7750_INTEVT_A7:
379 27c7ca7e bellard
        s->cpu->intevt = mem_value & 0x000007ff;
380 27c7ca7e bellard
        return;
381 27c7ca7e bellard
    case SH7750_CCR_A7:
382 27c7ca7e bellard
        s->ccr = mem_value;
383 27c7ca7e bellard
        return;
384 27c7ca7e bellard
    default:
385 27c7ca7e bellard
        error_access("long write", addr);
386 27c7ca7e bellard
        assert(0);
387 27c7ca7e bellard
    }
388 27c7ca7e bellard
}
389 27c7ca7e bellard
390 27c7ca7e bellard
static CPUReadMemoryFunc *sh7750_mem_read[] = {
391 27c7ca7e bellard
    sh7750_mem_readb,
392 27c7ca7e bellard
    sh7750_mem_readw,
393 27c7ca7e bellard
    sh7750_mem_readl
394 27c7ca7e bellard
};
395 27c7ca7e bellard
396 27c7ca7e bellard
static CPUWriteMemoryFunc *sh7750_mem_write[] = {
397 27c7ca7e bellard
    sh7750_mem_writeb,
398 27c7ca7e bellard
    sh7750_mem_writew,
399 27c7ca7e bellard
    sh7750_mem_writel
400 27c7ca7e bellard
};
401 27c7ca7e bellard
402 80f515e6 balrog
/* sh775x interrupt controller tables for sh_intc.c
403 80f515e6 balrog
 * stolen from linux/arch/sh/kernel/cpu/sh4/setup-sh7750.c
404 80f515e6 balrog
 */
405 80f515e6 balrog
406 80f515e6 balrog
enum {
407 80f515e6 balrog
        UNUSED = 0,
408 80f515e6 balrog
409 80f515e6 balrog
        /* interrupt sources */
410 80f515e6 balrog
        IRL0, IRL1, IRL2, IRL3, /* only IRLM mode supported */
411 80f515e6 balrog
        HUDI, GPIOI,
412 80f515e6 balrog
        DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2, DMAC_DMTE3,
413 80f515e6 balrog
        DMAC_DMTE4, DMAC_DMTE5, DMAC_DMTE6, DMAC_DMTE7,
414 80f515e6 balrog
        DMAC_DMAE,
415 80f515e6 balrog
        PCIC0_PCISERR, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
416 80f515e6 balrog
        PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3,
417 80f515e6 balrog
        TMU3, TMU4, TMU0, TMU1, TMU2_TUNI, TMU2_TICPI,
418 80f515e6 balrog
        RTC_ATI, RTC_PRI, RTC_CUI,
419 80f515e6 balrog
        SCI1_ERI, SCI1_RXI, SCI1_TXI, SCI1_TEI,
420 80f515e6 balrog
        SCIF_ERI, SCIF_RXI, SCIF_BRI, SCIF_TXI,
421 80f515e6 balrog
        WDT,
422 80f515e6 balrog
        REF_RCMI, REF_ROVI,
423 80f515e6 balrog
424 80f515e6 balrog
        /* interrupt groups */
425 80f515e6 balrog
        DMAC, PCIC1, TMU2, RTC, SCI1, SCIF, REF,
426 80f515e6 balrog
427 80f515e6 balrog
        NR_SOURCES,
428 80f515e6 balrog
};
429 80f515e6 balrog
430 80f515e6 balrog
static struct intc_vect vectors[] = {
431 80f515e6 balrog
        INTC_VECT(HUDI, 0x600), INTC_VECT(GPIOI, 0x620),
432 80f515e6 balrog
        INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
433 80f515e6 balrog
        INTC_VECT(TMU2_TUNI, 0x440), INTC_VECT(TMU2_TICPI, 0x460),
434 80f515e6 balrog
        INTC_VECT(RTC_ATI, 0x480), INTC_VECT(RTC_PRI, 0x4a0),
435 80f515e6 balrog
        INTC_VECT(RTC_CUI, 0x4c0),
436 80f515e6 balrog
        INTC_VECT(SCI1_ERI, 0x4e0), INTC_VECT(SCI1_RXI, 0x500),
437 80f515e6 balrog
        INTC_VECT(SCI1_TXI, 0x520), INTC_VECT(SCI1_TEI, 0x540),
438 80f515e6 balrog
        INTC_VECT(SCIF_ERI, 0x700), INTC_VECT(SCIF_RXI, 0x720),
439 80f515e6 balrog
        INTC_VECT(SCIF_BRI, 0x740), INTC_VECT(SCIF_TXI, 0x760),
440 80f515e6 balrog
        INTC_VECT(WDT, 0x560),
441 80f515e6 balrog
        INTC_VECT(REF_RCMI, 0x580), INTC_VECT(REF_ROVI, 0x5a0),
442 80f515e6 balrog
};
443 80f515e6 balrog
444 80f515e6 balrog
static struct intc_group groups[] = {
445 80f515e6 balrog
        INTC_GROUP(TMU2, TMU2_TUNI, TMU2_TICPI),
446 80f515e6 balrog
        INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI),
447 80f515e6 balrog
        INTC_GROUP(SCI1, SCI1_ERI, SCI1_RXI, SCI1_TXI, SCI1_TEI),
448 80f515e6 balrog
        INTC_GROUP(SCIF, SCIF_ERI, SCIF_RXI, SCIF_BRI, SCIF_TXI),
449 80f515e6 balrog
        INTC_GROUP(REF, REF_RCMI, REF_ROVI),
450 80f515e6 balrog
};
451 80f515e6 balrog
452 80f515e6 balrog
static struct intc_prio_reg prio_registers[] = {
453 80f515e6 balrog
        { 0xffd00004, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
454 80f515e6 balrog
        { 0xffd00008, 0, 16, 4, /* IPRB */ { WDT, REF, SCI1, 0 } },
455 80f515e6 balrog
        { 0xffd0000c, 0, 16, 4, /* IPRC */ { GPIOI, DMAC, SCIF, HUDI } },
456 80f515e6 balrog
        { 0xffd00010, 0, 16, 4, /* IPRD */ { IRL0, IRL1, IRL2, IRL3 } },
457 80f515e6 balrog
        { 0xfe080000, 0, 32, 4, /* INTPRI00 */ { 0, 0, 0, 0,
458 80f515e6 balrog
                                                 TMU4, TMU3,
459 80f515e6 balrog
                                                 PCIC1, PCIC0_PCISERR } },
460 80f515e6 balrog
};
461 80f515e6 balrog
462 80f515e6 balrog
/* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */
463 80f515e6 balrog
464 80f515e6 balrog
static struct intc_vect vectors_dma4[] = {
465 80f515e6 balrog
        INTC_VECT(DMAC_DMTE0, 0x640), INTC_VECT(DMAC_DMTE1, 0x660),
466 80f515e6 balrog
        INTC_VECT(DMAC_DMTE2, 0x680), INTC_VECT(DMAC_DMTE3, 0x6a0),
467 80f515e6 balrog
        INTC_VECT(DMAC_DMAE, 0x6c0),
468 80f515e6 balrog
};
469 80f515e6 balrog
470 80f515e6 balrog
static struct intc_group groups_dma4[] = {
471 80f515e6 balrog
        INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2,
472 80f515e6 balrog
                   DMAC_DMTE3, DMAC_DMAE),
473 80f515e6 balrog
};
474 80f515e6 balrog
475 80f515e6 balrog
/* SH7750R and SH7751R both have 8-channel DMA controllers */
476 80f515e6 balrog
477 80f515e6 balrog
static struct intc_vect vectors_dma8[] = {
478 80f515e6 balrog
        INTC_VECT(DMAC_DMTE0, 0x640), INTC_VECT(DMAC_DMTE1, 0x660),
479 80f515e6 balrog
        INTC_VECT(DMAC_DMTE2, 0x680), INTC_VECT(DMAC_DMTE3, 0x6a0),
480 80f515e6 balrog
        INTC_VECT(DMAC_DMTE4, 0x780), INTC_VECT(DMAC_DMTE5, 0x7a0),
481 80f515e6 balrog
        INTC_VECT(DMAC_DMTE6, 0x7c0), INTC_VECT(DMAC_DMTE7, 0x7e0),
482 80f515e6 balrog
        INTC_VECT(DMAC_DMAE, 0x6c0),
483 80f515e6 balrog
};
484 80f515e6 balrog
485 80f515e6 balrog
static struct intc_group groups_dma8[] = {
486 80f515e6 balrog
        INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2,
487 80f515e6 balrog
                   DMAC_DMTE3, DMAC_DMTE4, DMAC_DMTE5,
488 80f515e6 balrog
                   DMAC_DMTE6, DMAC_DMTE7, DMAC_DMAE),
489 80f515e6 balrog
};
490 80f515e6 balrog
491 80f515e6 balrog
/* SH7750R, SH7751 and SH7751R all have two extra timer channels */
492 80f515e6 balrog
493 80f515e6 balrog
static struct intc_vect vectors_tmu34[] = {
494 80f515e6 balrog
        INTC_VECT(TMU3, 0xb00), INTC_VECT(TMU4, 0xb80),
495 80f515e6 balrog
};
496 80f515e6 balrog
497 80f515e6 balrog
static struct intc_mask_reg mask_registers[] = {
498 80f515e6 balrog
        { 0xfe080040, 0xfe080060, 32, /* INTMSK00 / INTMSKCLR00 */
499 80f515e6 balrog
          { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
500 80f515e6 balrog
            0, 0, 0, 0, 0, 0, TMU4, TMU3,
501 80f515e6 balrog
            PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
502 80f515e6 balrog
            PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2,
503 80f515e6 balrog
            PCIC1_PCIDMA3, PCIC0_PCISERR } },
504 80f515e6 balrog
};
505 80f515e6 balrog
506 80f515e6 balrog
/* SH7750S, SH7750R, SH7751 and SH7751R all have IRLM priority registers */
507 80f515e6 balrog
508 80f515e6 balrog
static struct intc_vect vectors_irlm[] = {
509 80f515e6 balrog
        INTC_VECT(IRL0, 0x240), INTC_VECT(IRL1, 0x2a0),
510 80f515e6 balrog
        INTC_VECT(IRL2, 0x300), INTC_VECT(IRL3, 0x360),
511 80f515e6 balrog
};
512 80f515e6 balrog
513 80f515e6 balrog
/* SH7751 and SH7751R both have PCI */
514 80f515e6 balrog
515 80f515e6 balrog
static struct intc_vect vectors_pci[] = {
516 80f515e6 balrog
        INTC_VECT(PCIC0_PCISERR, 0xa00), INTC_VECT(PCIC1_PCIERR, 0xae0),
517 80f515e6 balrog
        INTC_VECT(PCIC1_PCIPWDWN, 0xac0), INTC_VECT(PCIC1_PCIPWON, 0xaa0),
518 80f515e6 balrog
        INTC_VECT(PCIC1_PCIDMA0, 0xa80), INTC_VECT(PCIC1_PCIDMA1, 0xa60),
519 80f515e6 balrog
        INTC_VECT(PCIC1_PCIDMA2, 0xa40), INTC_VECT(PCIC1_PCIDMA3, 0xa20),
520 80f515e6 balrog
};
521 80f515e6 balrog
522 80f515e6 balrog
static struct intc_group groups_pci[] = {
523 80f515e6 balrog
        INTC_GROUP(PCIC1, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
524 80f515e6 balrog
                   PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3),
525 80f515e6 balrog
};
526 80f515e6 balrog
527 80f515e6 balrog
#define SH_CPU_SH7750  (1 << 0)
528 80f515e6 balrog
#define SH_CPU_SH7750S (1 << 1)
529 80f515e6 balrog
#define SH_CPU_SH7750R (1 << 2)
530 80f515e6 balrog
#define SH_CPU_SH7751  (1 << 3)
531 80f515e6 balrog
#define SH_CPU_SH7751R (1 << 4)
532 80f515e6 balrog
#define SH_CPU_SH7750_ALL (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7750R)
533 80f515e6 balrog
#define SH_CPU_SH7751_ALL (SH_CPU_SH7751 | SH_CPU_SH7751R)
534 80f515e6 balrog
535 27c7ca7e bellard
SH7750State *sh7750_init(CPUSH4State * cpu)
536 27c7ca7e bellard
{
537 27c7ca7e bellard
    SH7750State *s;
538 27c7ca7e bellard
    int sh7750_io_memory;
539 80f515e6 balrog
    int cpu_model = SH_CPU_SH7751R; /* for now */
540 27c7ca7e bellard
541 27c7ca7e bellard
    s = qemu_mallocz(sizeof(SH7750State));
542 27c7ca7e bellard
    s->cpu = cpu;
543 27c7ca7e bellard
    s->periph_freq = 60000000;        /* 60MHz */
544 27c7ca7e bellard
    sh7750_io_memory = cpu_register_io_memory(0,
545 27c7ca7e bellard
                                              sh7750_mem_read,
546 27c7ca7e bellard
                                              sh7750_mem_write, s);
547 27c7ca7e bellard
    cpu_register_physical_memory(0x1c000000, 0x04000000, sh7750_io_memory);
548 2f062c72 ths
549 80f515e6 balrog
    sh_intc_init(&s->intc, NR_SOURCES,
550 80f515e6 balrog
                 _INTC_ARRAY(mask_registers),
551 80f515e6 balrog
                 _INTC_ARRAY(prio_registers));
552 80f515e6 balrog
553 80f515e6 balrog
    sh_intc_register_sources(&s->intc, 
554 80f515e6 balrog
                             _INTC_ARRAY(vectors),
555 80f515e6 balrog
                             _INTC_ARRAY(groups));
556 80f515e6 balrog
557 e96e2044 ths
    cpu->intc_handle = &s->intc;
558 e96e2044 ths
559 bf5b7423 aurel32
    sh_serial_init(0x1fe00000, 0, s->periph_freq, serial_hds[0],
560 bf5b7423 aurel32
                   sh_intc_source(&s->intc, SCI1_ERI),
561 bf5b7423 aurel32
                   sh_intc_source(&s->intc, SCI1_RXI),
562 bf5b7423 aurel32
                   sh_intc_source(&s->intc, SCI1_TXI),
563 bf5b7423 aurel32
                   sh_intc_source(&s->intc, SCI1_TEI),
564 bf5b7423 aurel32
                   NULL);
565 2f062c72 ths
    sh_serial_init(0x1fe80000, SH_SERIAL_FEAT_SCIF,
566 bf5b7423 aurel32
                   s->periph_freq, serial_hds[1],
567 bf5b7423 aurel32
                   sh_intc_source(&s->intc, SCIF_ERI),
568 bf5b7423 aurel32
                   sh_intc_source(&s->intc, SCIF_RXI),
569 bf5b7423 aurel32
                   sh_intc_source(&s->intc, SCIF_TXI),
570 bf5b7423 aurel32
                   NULL,
571 bf5b7423 aurel32
                   sh_intc_source(&s->intc, SCIF_BRI));
572 cd1a3f68 ths
573 cd1a3f68 ths
    tmu012_init(0x1fd80000,
574 cd1a3f68 ths
                TMU012_FEAT_TOCR | TMU012_FEAT_3CHAN | TMU012_FEAT_EXTCLK,
575 703243a0 balrog
                s->periph_freq,
576 703243a0 balrog
                sh_intc_source(&s->intc, TMU0),
577 703243a0 balrog
                sh_intc_source(&s->intc, TMU1),
578 703243a0 balrog
                sh_intc_source(&s->intc, TMU2_TUNI),
579 703243a0 balrog
                sh_intc_source(&s->intc, TMU2_TICPI));
580 80f515e6 balrog
581 80f515e6 balrog
    if (cpu_model & (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7751)) {
582 80f515e6 balrog
        sh_intc_register_sources(&s->intc, 
583 80f515e6 balrog
                                 _INTC_ARRAY(vectors_dma4),
584 80f515e6 balrog
                                 _INTC_ARRAY(groups_dma4));
585 80f515e6 balrog
    }
586 80f515e6 balrog
587 80f515e6 balrog
    if (cpu_model & (SH_CPU_SH7750R | SH_CPU_SH7751R)) {
588 80f515e6 balrog
        sh_intc_register_sources(&s->intc, 
589 80f515e6 balrog
                                 _INTC_ARRAY(vectors_dma8),
590 80f515e6 balrog
                                 _INTC_ARRAY(groups_dma8));
591 80f515e6 balrog
    }
592 80f515e6 balrog
593 80f515e6 balrog
    if (cpu_model & (SH_CPU_SH7750R | SH_CPU_SH7751 | SH_CPU_SH7751R)) {
594 80f515e6 balrog
        sh_intc_register_sources(&s->intc, 
595 80f515e6 balrog
                                 _INTC_ARRAY(vectors_tmu34),
596 f26ae302 bellard
                                 NULL, 0);
597 703243a0 balrog
        tmu012_init(0x1e100000, 0, s->periph_freq,
598 703243a0 balrog
                    sh_intc_source(&s->intc, TMU3),
599 703243a0 balrog
                    sh_intc_source(&s->intc, TMU4),
600 703243a0 balrog
                    NULL, NULL);
601 80f515e6 balrog
    }
602 80f515e6 balrog
603 80f515e6 balrog
    if (cpu_model & (SH_CPU_SH7751_ALL)) {
604 80f515e6 balrog
        sh_intc_register_sources(&s->intc, 
605 80f515e6 balrog
                                 _INTC_ARRAY(vectors_pci),
606 80f515e6 balrog
                                 _INTC_ARRAY(groups_pci));
607 80f515e6 balrog
    }
608 80f515e6 balrog
609 80f515e6 balrog
    if (cpu_model & (SH_CPU_SH7750S | SH_CPU_SH7750R | SH_CPU_SH7751_ALL)) {
610 80f515e6 balrog
        sh_intc_register_sources(&s->intc, 
611 80f515e6 balrog
                                 _INTC_ARRAY(vectors_irlm),
612 f26ae302 bellard
                                 NULL, 0);
613 80f515e6 balrog
    }
614 80f515e6 balrog
615 27c7ca7e bellard
    return s;
616 27c7ca7e bellard
}