Statistics
| Branch: | Revision:

root / hw / sh7750.c @ 5c16736a

History | View | Annotate | Download (20.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 06afe2c8 aurel32
#include "exec-all.h"
34 29e179bc aurel32
#include "cpu.h"
35 27c7ca7e bellard
36 27c7ca7e bellard
#define NB_DEVICES 4
37 27c7ca7e bellard
38 27c7ca7e bellard
typedef struct SH7750State {
39 27c7ca7e bellard
    /* CPU */
40 27c7ca7e bellard
    CPUSH4State *cpu;
41 27c7ca7e bellard
    /* Peripheral frequency in Hz */
42 27c7ca7e bellard
    uint32_t periph_freq;
43 27c7ca7e bellard
    /* SDRAM controller */
44 c2f01775 balrog
    uint32_t bcr1;
45 c2f01775 balrog
    uint32_t bcr2;
46 27c7ca7e bellard
    uint16_t rfcr;
47 27c7ca7e bellard
    /* IO ports */
48 27c7ca7e bellard
    uint16_t gpioic;
49 27c7ca7e bellard
    uint32_t pctra;
50 27c7ca7e bellard
    uint32_t pctrb;
51 27c7ca7e bellard
    uint16_t portdira;                /* Cached */
52 27c7ca7e bellard
    uint16_t portpullupa;        /* Cached */
53 27c7ca7e bellard
    uint16_t portdirb;                /* Cached */
54 27c7ca7e bellard
    uint16_t portpullupb;        /* Cached */
55 27c7ca7e bellard
    uint16_t pdtra;
56 27c7ca7e bellard
    uint16_t pdtrb;
57 27c7ca7e bellard
    uint16_t periph_pdtra;        /* Imposed by the peripherals */
58 27c7ca7e bellard
    uint16_t periph_portdira;        /* Direction seen from the peripherals */
59 27c7ca7e bellard
    uint16_t periph_pdtrb;        /* Imposed by the peripherals */
60 27c7ca7e bellard
    uint16_t periph_portdirb;        /* Direction seen from the peripherals */
61 27c7ca7e bellard
    sh7750_io_device *devices[NB_DEVICES];        /* External peripherals */
62 3464c589 ths
63 27c7ca7e bellard
    /* Cache */
64 27c7ca7e bellard
    uint32_t ccr;
65 27c7ca7e bellard
66 80f515e6 balrog
    struct intc_desc intc;
67 cd1a3f68 ths
} SH7750State;
68 27c7ca7e bellard
69 27c7ca7e bellard
70 27c7ca7e bellard
/**********************************************************************
71 27c7ca7e bellard
 I/O ports
72 27c7ca7e bellard
**********************************************************************/
73 27c7ca7e bellard
74 27c7ca7e bellard
int sh7750_register_io_device(SH7750State * s, sh7750_io_device * device)
75 27c7ca7e bellard
{
76 27c7ca7e bellard
    int i;
77 27c7ca7e bellard
78 27c7ca7e bellard
    for (i = 0; i < NB_DEVICES; i++) {
79 27c7ca7e bellard
        if (s->devices[i] == NULL) {
80 27c7ca7e bellard
            s->devices[i] = device;
81 27c7ca7e bellard
            return 0;
82 27c7ca7e bellard
        }
83 27c7ca7e bellard
    }
84 27c7ca7e bellard
    return -1;
85 27c7ca7e bellard
}
86 27c7ca7e bellard
87 27c7ca7e bellard
static uint16_t portdir(uint32_t v)
88 27c7ca7e bellard
{
89 27c7ca7e bellard
#define EVENPORTMASK(n) ((v & (1<<((n)<<1))) >> (n))
90 27c7ca7e bellard
    return
91 27c7ca7e bellard
        EVENPORTMASK(15) | EVENPORTMASK(14) | EVENPORTMASK(13) |
92 27c7ca7e bellard
        EVENPORTMASK(12) | EVENPORTMASK(11) | EVENPORTMASK(10) |
93 27c7ca7e bellard
        EVENPORTMASK(9) | EVENPORTMASK(8) | EVENPORTMASK(7) |
94 27c7ca7e bellard
        EVENPORTMASK(6) | EVENPORTMASK(5) | EVENPORTMASK(4) |
95 27c7ca7e bellard
        EVENPORTMASK(3) | EVENPORTMASK(2) | EVENPORTMASK(1) |
96 27c7ca7e bellard
        EVENPORTMASK(0);
97 27c7ca7e bellard
}
98 27c7ca7e bellard
99 27c7ca7e bellard
static uint16_t portpullup(uint32_t v)
100 27c7ca7e bellard
{
101 27c7ca7e bellard
#define ODDPORTMASK(n) ((v & (1<<(((n)<<1)+1))) >> (n))
102 27c7ca7e bellard
    return
103 27c7ca7e bellard
        ODDPORTMASK(15) | ODDPORTMASK(14) | ODDPORTMASK(13) |
104 27c7ca7e bellard
        ODDPORTMASK(12) | ODDPORTMASK(11) | ODDPORTMASK(10) |
105 27c7ca7e bellard
        ODDPORTMASK(9) | ODDPORTMASK(8) | ODDPORTMASK(7) | ODDPORTMASK(6) |
106 27c7ca7e bellard
        ODDPORTMASK(5) | ODDPORTMASK(4) | ODDPORTMASK(3) | ODDPORTMASK(2) |
107 27c7ca7e bellard
        ODDPORTMASK(1) | ODDPORTMASK(0);
108 27c7ca7e bellard
}
109 27c7ca7e bellard
110 27c7ca7e bellard
static uint16_t porta_lines(SH7750State * s)
111 27c7ca7e bellard
{
112 27c7ca7e bellard
    return (s->portdira & s->pdtra) |        /* CPU */
113 27c7ca7e bellard
        (s->periph_portdira & s->periph_pdtra) |        /* Peripherals */
114 27c7ca7e bellard
        (~(s->portdira | s->periph_portdira) & s->portpullupa);        /* Pullups */
115 27c7ca7e bellard
}
116 27c7ca7e bellard
117 27c7ca7e bellard
static uint16_t portb_lines(SH7750State * s)
118 27c7ca7e bellard
{
119 27c7ca7e bellard
    return (s->portdirb & s->pdtrb) |        /* CPU */
120 27c7ca7e bellard
        (s->periph_portdirb & s->periph_pdtrb) |        /* Peripherals */
121 27c7ca7e bellard
        (~(s->portdirb | s->periph_portdirb) & s->portpullupb);        /* Pullups */
122 27c7ca7e bellard
}
123 27c7ca7e bellard
124 27c7ca7e bellard
static void gen_port_interrupts(SH7750State * s)
125 27c7ca7e bellard
{
126 27c7ca7e bellard
    /* XXXXX interrupts not generated */
127 27c7ca7e bellard
}
128 27c7ca7e bellard
129 27c7ca7e bellard
static void porta_changed(SH7750State * s, uint16_t prev)
130 27c7ca7e bellard
{
131 27c7ca7e bellard
    uint16_t currenta, changes;
132 27c7ca7e bellard
    int i, r = 0;
133 27c7ca7e bellard
134 27c7ca7e bellard
#if 0
135 27c7ca7e bellard
    fprintf(stderr, "porta changed from 0x%04x to 0x%04x\n",
136 27c7ca7e bellard
            prev, porta_lines(s));
137 27c7ca7e bellard
    fprintf(stderr, "pdtra=0x%04x, pctra=0x%08x\n", s->pdtra, s->pctra);
138 27c7ca7e bellard
#endif
139 27c7ca7e bellard
    currenta = porta_lines(s);
140 27c7ca7e bellard
    if (currenta == prev)
141 27c7ca7e bellard
        return;
142 27c7ca7e bellard
    changes = currenta ^ prev;
143 27c7ca7e bellard
144 27c7ca7e bellard
    for (i = 0; i < NB_DEVICES; i++) {
145 27c7ca7e bellard
        if (s->devices[i] && (s->devices[i]->portamask_trigger & changes)) {
146 27c7ca7e bellard
            r |= s->devices[i]->port_change_cb(currenta, portb_lines(s),
147 27c7ca7e bellard
                                               &s->periph_pdtra,
148 27c7ca7e bellard
                                               &s->periph_portdira,
149 27c7ca7e bellard
                                               &s->periph_pdtrb,
150 27c7ca7e bellard
                                               &s->periph_portdirb);
151 27c7ca7e bellard
        }
152 27c7ca7e bellard
    }
153 27c7ca7e bellard
154 27c7ca7e bellard
    if (r)
155 27c7ca7e bellard
        gen_port_interrupts(s);
156 27c7ca7e bellard
}
157 27c7ca7e bellard
158 27c7ca7e bellard
static void portb_changed(SH7750State * s, uint16_t prev)
159 27c7ca7e bellard
{
160 27c7ca7e bellard
    uint16_t currentb, changes;
161 27c7ca7e bellard
    int i, r = 0;
162 27c7ca7e bellard
163 27c7ca7e bellard
    currentb = portb_lines(s);
164 27c7ca7e bellard
    if (currentb == prev)
165 27c7ca7e bellard
        return;
166 27c7ca7e bellard
    changes = currentb ^ prev;
167 27c7ca7e bellard
168 27c7ca7e bellard
    for (i = 0; i < NB_DEVICES; i++) {
169 27c7ca7e bellard
        if (s->devices[i] && (s->devices[i]->portbmask_trigger & changes)) {
170 27c7ca7e bellard
            r |= s->devices[i]->port_change_cb(portb_lines(s), currentb,
171 27c7ca7e bellard
                                               &s->periph_pdtra,
172 27c7ca7e bellard
                                               &s->periph_portdira,
173 27c7ca7e bellard
                                               &s->periph_pdtrb,
174 27c7ca7e bellard
                                               &s->periph_portdirb);
175 27c7ca7e bellard
        }
176 27c7ca7e bellard
    }
177 27c7ca7e bellard
178 27c7ca7e bellard
    if (r)
179 27c7ca7e bellard
        gen_port_interrupts(s);
180 27c7ca7e bellard
}
181 27c7ca7e bellard
182 27c7ca7e bellard
/**********************************************************************
183 27c7ca7e bellard
 Memory
184 27c7ca7e bellard
**********************************************************************/
185 27c7ca7e bellard
186 27c7ca7e bellard
static void error_access(const char *kind, target_phys_addr_t addr)
187 27c7ca7e bellard
{
188 526ccb7a balrog
    fprintf(stderr, "%s to %s (0x" TARGET_FMT_plx ") not supported\n",
189 27c7ca7e bellard
            kind, regname(addr), addr);
190 27c7ca7e bellard
}
191 27c7ca7e bellard
192 27c7ca7e bellard
static void ignore_access(const char *kind, target_phys_addr_t addr)
193 27c7ca7e bellard
{
194 526ccb7a balrog
    fprintf(stderr, "%s to %s (0x" TARGET_FMT_plx ") ignored\n",
195 27c7ca7e bellard
            kind, regname(addr), addr);
196 27c7ca7e bellard
}
197 27c7ca7e bellard
198 27c7ca7e bellard
static uint32_t sh7750_mem_readb(void *opaque, target_phys_addr_t addr)
199 27c7ca7e bellard
{
200 27c7ca7e bellard
    switch (addr) {
201 27c7ca7e bellard
    default:
202 27c7ca7e bellard
        error_access("byte read", addr);
203 27c7ca7e bellard
        assert(0);
204 27c7ca7e bellard
    }
205 27c7ca7e bellard
}
206 27c7ca7e bellard
207 27c7ca7e bellard
static uint32_t sh7750_mem_readw(void *opaque, target_phys_addr_t addr)
208 27c7ca7e bellard
{
209 27c7ca7e bellard
    SH7750State *s = opaque;
210 27c7ca7e bellard
211 27c7ca7e bellard
    switch (addr) {
212 c2f01775 balrog
    case SH7750_BCR2_A7:
213 c2f01775 balrog
        return s->bcr2;
214 ed8e0a4d ths
    case SH7750_FRQCR_A7:
215 ed8e0a4d ths
        return 0;
216 27c7ca7e bellard
    case SH7750_RFCR_A7:
217 27c7ca7e bellard
        fprintf(stderr,
218 27c7ca7e bellard
                "Read access to refresh count register, incrementing\n");
219 27c7ca7e bellard
        return s->rfcr++;
220 27c7ca7e bellard
    case SH7750_PDTRA_A7:
221 27c7ca7e bellard
        return porta_lines(s);
222 27c7ca7e bellard
    case SH7750_PDTRB_A7:
223 27c7ca7e bellard
        return portb_lines(s);
224 27c7ca7e bellard
    default:
225 27c7ca7e bellard
        error_access("word read", addr);
226 27c7ca7e bellard
        assert(0);
227 27c7ca7e bellard
    }
228 27c7ca7e bellard
}
229 27c7ca7e bellard
230 27c7ca7e bellard
static uint32_t sh7750_mem_readl(void *opaque, target_phys_addr_t addr)
231 27c7ca7e bellard
{
232 27c7ca7e bellard
    SH7750State *s = opaque;
233 27c7ca7e bellard
234 27c7ca7e bellard
    switch (addr) {
235 c2f01775 balrog
    case SH7750_BCR1_A7:
236 c2f01775 balrog
        return s->bcr1;
237 c2f01775 balrog
    case SH7750_BCR4_A7:
238 c2f01775 balrog
    case SH7750_WCR1_A7:
239 c2f01775 balrog
    case SH7750_WCR2_A7:
240 c2f01775 balrog
    case SH7750_WCR3_A7:
241 c2f01775 balrog
    case SH7750_MCR_A7:
242 c2f01775 balrog
        ignore_access("long read", addr);
243 c2f01775 balrog
        return 0;
244 27c7ca7e bellard
    case SH7750_MMUCR_A7:
245 27c7ca7e bellard
        return s->cpu->mmucr;
246 27c7ca7e bellard
    case SH7750_PTEH_A7:
247 27c7ca7e bellard
        return s->cpu->pteh;
248 27c7ca7e bellard
    case SH7750_PTEL_A7:
249 27c7ca7e bellard
        return s->cpu->ptel;
250 27c7ca7e bellard
    case SH7750_TTB_A7:
251 27c7ca7e bellard
        return s->cpu->ttb;
252 27c7ca7e bellard
    case SH7750_TEA_A7:
253 27c7ca7e bellard
        return s->cpu->tea;
254 27c7ca7e bellard
    case SH7750_TRA_A7:
255 27c7ca7e bellard
        return s->cpu->tra;
256 27c7ca7e bellard
    case SH7750_EXPEVT_A7:
257 27c7ca7e bellard
        return s->cpu->expevt;
258 27c7ca7e bellard
    case SH7750_INTEVT_A7:
259 27c7ca7e bellard
        return s->cpu->intevt;
260 27c7ca7e bellard
    case SH7750_CCR_A7:
261 27c7ca7e bellard
        return s->ccr;
262 0fd3ca30 aurel32
    case 0x1f000030:                /* Processor version */
263 0fd3ca30 aurel32
        return s->cpu->pvr;
264 0fd3ca30 aurel32
    case 0x1f000040:                /* Cache version */
265 0fd3ca30 aurel32
        return s->cpu->cvr;
266 0fd3ca30 aurel32
    case 0x1f000044:                /* Processor revision */
267 0fd3ca30 aurel32
        return s->cpu->prr;
268 27c7ca7e bellard
    default:
269 27c7ca7e bellard
        error_access("long read", addr);
270 27c7ca7e bellard
        assert(0);
271 27c7ca7e bellard
    }
272 27c7ca7e bellard
}
273 27c7ca7e bellard
274 27c7ca7e bellard
static void sh7750_mem_writeb(void *opaque, target_phys_addr_t addr,
275 27c7ca7e bellard
                              uint32_t mem_value)
276 27c7ca7e bellard
{
277 27c7ca7e bellard
    switch (addr) {
278 27c7ca7e bellard
        /* PRECHARGE ? XXXXX */
279 27c7ca7e bellard
    case SH7750_PRECHARGE0_A7:
280 27c7ca7e bellard
    case SH7750_PRECHARGE1_A7:
281 27c7ca7e bellard
        ignore_access("byte write", addr);
282 27c7ca7e bellard
        return;
283 27c7ca7e bellard
    default:
284 27c7ca7e bellard
        error_access("byte write", addr);
285 27c7ca7e bellard
        assert(0);
286 27c7ca7e bellard
    }
287 27c7ca7e bellard
}
288 27c7ca7e bellard
289 27c7ca7e bellard
static void sh7750_mem_writew(void *opaque, target_phys_addr_t addr,
290 27c7ca7e bellard
                              uint32_t mem_value)
291 27c7ca7e bellard
{
292 27c7ca7e bellard
    SH7750State *s = opaque;
293 27c7ca7e bellard
    uint16_t temp;
294 27c7ca7e bellard
295 27c7ca7e bellard
    switch (addr) {
296 27c7ca7e bellard
        /* SDRAM controller */
297 27c7ca7e bellard
    case SH7750_BCR2_A7:
298 c2f01775 balrog
        s->bcr2 = mem_value;
299 c2f01775 balrog
        return;
300 27c7ca7e bellard
    case SH7750_BCR3_A7:
301 27c7ca7e bellard
    case SH7750_RTCOR_A7:
302 27c7ca7e bellard
    case SH7750_RTCNT_A7:
303 27c7ca7e bellard
    case SH7750_RTCSR_A7:
304 27c7ca7e bellard
        ignore_access("word write", addr);
305 27c7ca7e bellard
        return;
306 27c7ca7e bellard
        /* IO ports */
307 27c7ca7e bellard
    case SH7750_PDTRA_A7:
308 27c7ca7e bellard
        temp = porta_lines(s);
309 27c7ca7e bellard
        s->pdtra = mem_value;
310 27c7ca7e bellard
        porta_changed(s, temp);
311 27c7ca7e bellard
        return;
312 27c7ca7e bellard
    case SH7750_PDTRB_A7:
313 27c7ca7e bellard
        temp = portb_lines(s);
314 27c7ca7e bellard
        s->pdtrb = mem_value;
315 27c7ca7e bellard
        portb_changed(s, temp);
316 27c7ca7e bellard
        return;
317 27c7ca7e bellard
    case SH7750_RFCR_A7:
318 27c7ca7e bellard
        fprintf(stderr, "Write access to refresh count register\n");
319 27c7ca7e bellard
        s->rfcr = mem_value;
320 27c7ca7e bellard
        return;
321 27c7ca7e bellard
    case SH7750_GPIOIC_A7:
322 27c7ca7e bellard
        s->gpioic = mem_value;
323 27c7ca7e bellard
        if (mem_value != 0) {
324 27c7ca7e bellard
            fprintf(stderr, "I/O interrupts not implemented\n");
325 27c7ca7e bellard
            assert(0);
326 27c7ca7e bellard
        }
327 27c7ca7e bellard
        return;
328 27c7ca7e bellard
    default:
329 27c7ca7e bellard
        error_access("word write", addr);
330 27c7ca7e bellard
        assert(0);
331 27c7ca7e bellard
    }
332 27c7ca7e bellard
}
333 27c7ca7e bellard
334 27c7ca7e bellard
static void sh7750_mem_writel(void *opaque, target_phys_addr_t addr,
335 27c7ca7e bellard
                              uint32_t mem_value)
336 27c7ca7e bellard
{
337 27c7ca7e bellard
    SH7750State *s = opaque;
338 27c7ca7e bellard
    uint16_t temp;
339 27c7ca7e bellard
340 27c7ca7e bellard
    switch (addr) {
341 27c7ca7e bellard
        /* SDRAM controller */
342 27c7ca7e bellard
    case SH7750_BCR1_A7:
343 c2f01775 balrog
        s->bcr1 = mem_value;
344 c2f01775 balrog
        return;
345 27c7ca7e bellard
    case SH7750_BCR4_A7:
346 27c7ca7e bellard
    case SH7750_WCR1_A7:
347 27c7ca7e bellard
    case SH7750_WCR2_A7:
348 27c7ca7e bellard
    case SH7750_WCR3_A7:
349 27c7ca7e bellard
    case SH7750_MCR_A7:
350 27c7ca7e bellard
        ignore_access("long write", addr);
351 27c7ca7e bellard
        return;
352 27c7ca7e bellard
        /* IO ports */
353 27c7ca7e bellard
    case SH7750_PCTRA_A7:
354 27c7ca7e bellard
        temp = porta_lines(s);
355 27c7ca7e bellard
        s->pctra = mem_value;
356 27c7ca7e bellard
        s->portdira = portdir(mem_value);
357 27c7ca7e bellard
        s->portpullupa = portpullup(mem_value);
358 27c7ca7e bellard
        porta_changed(s, temp);
359 27c7ca7e bellard
        return;
360 27c7ca7e bellard
    case SH7750_PCTRB_A7:
361 27c7ca7e bellard
        temp = portb_lines(s);
362 27c7ca7e bellard
        s->pctrb = mem_value;
363 27c7ca7e bellard
        s->portdirb = portdir(mem_value);
364 27c7ca7e bellard
        s->portpullupb = portpullup(mem_value);
365 27c7ca7e bellard
        portb_changed(s, temp);
366 27c7ca7e bellard
        return;
367 27c7ca7e bellard
    case SH7750_MMUCR_A7:
368 27c7ca7e bellard
        s->cpu->mmucr = mem_value;
369 27c7ca7e bellard
        return;
370 27c7ca7e bellard
    case SH7750_PTEH_A7:
371 06afe2c8 aurel32
        /* If asid changes, clear all registered tlb entries. */
372 06afe2c8 aurel32
        if ((s->cpu->pteh & 0xff) != (mem_value & 0xff))
373 06afe2c8 aurel32
            tlb_flush(s->cpu, 1);
374 27c7ca7e bellard
        s->cpu->pteh = mem_value;
375 27c7ca7e bellard
        return;
376 27c7ca7e bellard
    case SH7750_PTEL_A7:
377 27c7ca7e bellard
        s->cpu->ptel = mem_value;
378 27c7ca7e bellard
        return;
379 ea2b542a aurel32
    case SH7750_PTEA_A7:
380 ea2b542a aurel32
        s->cpu->ptea = mem_value & 0x0000000f;
381 ea2b542a aurel32
        return;
382 27c7ca7e bellard
    case SH7750_TTB_A7:
383 27c7ca7e bellard
        s->cpu->ttb = mem_value;
384 27c7ca7e bellard
        return;
385 27c7ca7e bellard
    case SH7750_TEA_A7:
386 27c7ca7e bellard
        s->cpu->tea = mem_value;
387 27c7ca7e bellard
        return;
388 27c7ca7e bellard
    case SH7750_TRA_A7:
389 27c7ca7e bellard
        s->cpu->tra = mem_value & 0x000007ff;
390 27c7ca7e bellard
        return;
391 27c7ca7e bellard
    case SH7750_EXPEVT_A7:
392 27c7ca7e bellard
        s->cpu->expevt = mem_value & 0x000007ff;
393 27c7ca7e bellard
        return;
394 27c7ca7e bellard
    case SH7750_INTEVT_A7:
395 27c7ca7e bellard
        s->cpu->intevt = mem_value & 0x000007ff;
396 27c7ca7e bellard
        return;
397 27c7ca7e bellard
    case SH7750_CCR_A7:
398 27c7ca7e bellard
        s->ccr = mem_value;
399 27c7ca7e bellard
        return;
400 27c7ca7e bellard
    default:
401 27c7ca7e bellard
        error_access("long write", addr);
402 27c7ca7e bellard
        assert(0);
403 27c7ca7e bellard
    }
404 27c7ca7e bellard
}
405 27c7ca7e bellard
406 27c7ca7e bellard
static CPUReadMemoryFunc *sh7750_mem_read[] = {
407 27c7ca7e bellard
    sh7750_mem_readb,
408 27c7ca7e bellard
    sh7750_mem_readw,
409 27c7ca7e bellard
    sh7750_mem_readl
410 27c7ca7e bellard
};
411 27c7ca7e bellard
412 27c7ca7e bellard
static CPUWriteMemoryFunc *sh7750_mem_write[] = {
413 27c7ca7e bellard
    sh7750_mem_writeb,
414 27c7ca7e bellard
    sh7750_mem_writew,
415 27c7ca7e bellard
    sh7750_mem_writel
416 27c7ca7e bellard
};
417 27c7ca7e bellard
418 80f515e6 balrog
/* sh775x interrupt controller tables for sh_intc.c
419 80f515e6 balrog
 * stolen from linux/arch/sh/kernel/cpu/sh4/setup-sh7750.c
420 80f515e6 balrog
 */
421 80f515e6 balrog
422 80f515e6 balrog
enum {
423 80f515e6 balrog
        UNUSED = 0,
424 80f515e6 balrog
425 80f515e6 balrog
        /* interrupt sources */
426 c6d86a33 balrog
        IRL_0, IRL_1, IRL_2, IRL_3, IRL_4, IRL_5, IRL_6, IRL_7,
427 c6d86a33 balrog
        IRL_8, IRL_9, IRL_A, IRL_B, IRL_C, IRL_D, IRL_E,
428 c6d86a33 balrog
        IRL0, IRL1, IRL2, IRL3,
429 80f515e6 balrog
        HUDI, GPIOI,
430 80f515e6 balrog
        DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2, DMAC_DMTE3,
431 80f515e6 balrog
        DMAC_DMTE4, DMAC_DMTE5, DMAC_DMTE6, DMAC_DMTE7,
432 80f515e6 balrog
        DMAC_DMAE,
433 80f515e6 balrog
        PCIC0_PCISERR, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
434 80f515e6 balrog
        PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3,
435 80f515e6 balrog
        TMU3, TMU4, TMU0, TMU1, TMU2_TUNI, TMU2_TICPI,
436 80f515e6 balrog
        RTC_ATI, RTC_PRI, RTC_CUI,
437 80f515e6 balrog
        SCI1_ERI, SCI1_RXI, SCI1_TXI, SCI1_TEI,
438 80f515e6 balrog
        SCIF_ERI, SCIF_RXI, SCIF_BRI, SCIF_TXI,
439 80f515e6 balrog
        WDT,
440 80f515e6 balrog
        REF_RCMI, REF_ROVI,
441 80f515e6 balrog
442 80f515e6 balrog
        /* interrupt groups */
443 80f515e6 balrog
        DMAC, PCIC1, TMU2, RTC, SCI1, SCIF, REF,
444 c6d86a33 balrog
        /* irl bundle */
445 c6d86a33 balrog
        IRL,
446 80f515e6 balrog
447 80f515e6 balrog
        NR_SOURCES,
448 80f515e6 balrog
};
449 80f515e6 balrog
450 80f515e6 balrog
static struct intc_vect vectors[] = {
451 80f515e6 balrog
        INTC_VECT(HUDI, 0x600), INTC_VECT(GPIOI, 0x620),
452 80f515e6 balrog
        INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
453 80f515e6 balrog
        INTC_VECT(TMU2_TUNI, 0x440), INTC_VECT(TMU2_TICPI, 0x460),
454 80f515e6 balrog
        INTC_VECT(RTC_ATI, 0x480), INTC_VECT(RTC_PRI, 0x4a0),
455 80f515e6 balrog
        INTC_VECT(RTC_CUI, 0x4c0),
456 80f515e6 balrog
        INTC_VECT(SCI1_ERI, 0x4e0), INTC_VECT(SCI1_RXI, 0x500),
457 80f515e6 balrog
        INTC_VECT(SCI1_TXI, 0x520), INTC_VECT(SCI1_TEI, 0x540),
458 80f515e6 balrog
        INTC_VECT(SCIF_ERI, 0x700), INTC_VECT(SCIF_RXI, 0x720),
459 80f515e6 balrog
        INTC_VECT(SCIF_BRI, 0x740), INTC_VECT(SCIF_TXI, 0x760),
460 80f515e6 balrog
        INTC_VECT(WDT, 0x560),
461 80f515e6 balrog
        INTC_VECT(REF_RCMI, 0x580), INTC_VECT(REF_ROVI, 0x5a0),
462 80f515e6 balrog
};
463 80f515e6 balrog
464 80f515e6 balrog
static struct intc_group groups[] = {
465 80f515e6 balrog
        INTC_GROUP(TMU2, TMU2_TUNI, TMU2_TICPI),
466 80f515e6 balrog
        INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI),
467 80f515e6 balrog
        INTC_GROUP(SCI1, SCI1_ERI, SCI1_RXI, SCI1_TXI, SCI1_TEI),
468 80f515e6 balrog
        INTC_GROUP(SCIF, SCIF_ERI, SCIF_RXI, SCIF_BRI, SCIF_TXI),
469 80f515e6 balrog
        INTC_GROUP(REF, REF_RCMI, REF_ROVI),
470 80f515e6 balrog
};
471 80f515e6 balrog
472 80f515e6 balrog
static struct intc_prio_reg prio_registers[] = {
473 80f515e6 balrog
        { 0xffd00004, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
474 80f515e6 balrog
        { 0xffd00008, 0, 16, 4, /* IPRB */ { WDT, REF, SCI1, 0 } },
475 80f515e6 balrog
        { 0xffd0000c, 0, 16, 4, /* IPRC */ { GPIOI, DMAC, SCIF, HUDI } },
476 80f515e6 balrog
        { 0xffd00010, 0, 16, 4, /* IPRD */ { IRL0, IRL1, IRL2, IRL3 } },
477 80f515e6 balrog
        { 0xfe080000, 0, 32, 4, /* INTPRI00 */ { 0, 0, 0, 0,
478 80f515e6 balrog
                                                 TMU4, TMU3,
479 80f515e6 balrog
                                                 PCIC1, PCIC0_PCISERR } },
480 80f515e6 balrog
};
481 80f515e6 balrog
482 80f515e6 balrog
/* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */
483 80f515e6 balrog
484 80f515e6 balrog
static struct intc_vect vectors_dma4[] = {
485 80f515e6 balrog
        INTC_VECT(DMAC_DMTE0, 0x640), INTC_VECT(DMAC_DMTE1, 0x660),
486 80f515e6 balrog
        INTC_VECT(DMAC_DMTE2, 0x680), INTC_VECT(DMAC_DMTE3, 0x6a0),
487 80f515e6 balrog
        INTC_VECT(DMAC_DMAE, 0x6c0),
488 80f515e6 balrog
};
489 80f515e6 balrog
490 80f515e6 balrog
static struct intc_group groups_dma4[] = {
491 80f515e6 balrog
        INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2,
492 80f515e6 balrog
                   DMAC_DMTE3, DMAC_DMAE),
493 80f515e6 balrog
};
494 80f515e6 balrog
495 80f515e6 balrog
/* SH7750R and SH7751R both have 8-channel DMA controllers */
496 80f515e6 balrog
497 80f515e6 balrog
static struct intc_vect vectors_dma8[] = {
498 80f515e6 balrog
        INTC_VECT(DMAC_DMTE0, 0x640), INTC_VECT(DMAC_DMTE1, 0x660),
499 80f515e6 balrog
        INTC_VECT(DMAC_DMTE2, 0x680), INTC_VECT(DMAC_DMTE3, 0x6a0),
500 80f515e6 balrog
        INTC_VECT(DMAC_DMTE4, 0x780), INTC_VECT(DMAC_DMTE5, 0x7a0),
501 80f515e6 balrog
        INTC_VECT(DMAC_DMTE6, 0x7c0), INTC_VECT(DMAC_DMTE7, 0x7e0),
502 80f515e6 balrog
        INTC_VECT(DMAC_DMAE, 0x6c0),
503 80f515e6 balrog
};
504 80f515e6 balrog
505 80f515e6 balrog
static struct intc_group groups_dma8[] = {
506 80f515e6 balrog
        INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2,
507 80f515e6 balrog
                   DMAC_DMTE3, DMAC_DMTE4, DMAC_DMTE5,
508 80f515e6 balrog
                   DMAC_DMTE6, DMAC_DMTE7, DMAC_DMAE),
509 80f515e6 balrog
};
510 80f515e6 balrog
511 80f515e6 balrog
/* SH7750R, SH7751 and SH7751R all have two extra timer channels */
512 80f515e6 balrog
513 80f515e6 balrog
static struct intc_vect vectors_tmu34[] = {
514 80f515e6 balrog
        INTC_VECT(TMU3, 0xb00), INTC_VECT(TMU4, 0xb80),
515 80f515e6 balrog
};
516 80f515e6 balrog
517 80f515e6 balrog
static struct intc_mask_reg mask_registers[] = {
518 80f515e6 balrog
        { 0xfe080040, 0xfe080060, 32, /* INTMSK00 / INTMSKCLR00 */
519 80f515e6 balrog
          { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
520 80f515e6 balrog
            0, 0, 0, 0, 0, 0, TMU4, TMU3,
521 80f515e6 balrog
            PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
522 80f515e6 balrog
            PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2,
523 80f515e6 balrog
            PCIC1_PCIDMA3, PCIC0_PCISERR } },
524 80f515e6 balrog
};
525 80f515e6 balrog
526 80f515e6 balrog
/* SH7750S, SH7750R, SH7751 and SH7751R all have IRLM priority registers */
527 80f515e6 balrog
528 80f515e6 balrog
static struct intc_vect vectors_irlm[] = {
529 80f515e6 balrog
        INTC_VECT(IRL0, 0x240), INTC_VECT(IRL1, 0x2a0),
530 80f515e6 balrog
        INTC_VECT(IRL2, 0x300), INTC_VECT(IRL3, 0x360),
531 80f515e6 balrog
};
532 80f515e6 balrog
533 80f515e6 balrog
/* SH7751 and SH7751R both have PCI */
534 80f515e6 balrog
535 80f515e6 balrog
static struct intc_vect vectors_pci[] = {
536 80f515e6 balrog
        INTC_VECT(PCIC0_PCISERR, 0xa00), INTC_VECT(PCIC1_PCIERR, 0xae0),
537 80f515e6 balrog
        INTC_VECT(PCIC1_PCIPWDWN, 0xac0), INTC_VECT(PCIC1_PCIPWON, 0xaa0),
538 80f515e6 balrog
        INTC_VECT(PCIC1_PCIDMA0, 0xa80), INTC_VECT(PCIC1_PCIDMA1, 0xa60),
539 80f515e6 balrog
        INTC_VECT(PCIC1_PCIDMA2, 0xa40), INTC_VECT(PCIC1_PCIDMA3, 0xa20),
540 80f515e6 balrog
};
541 80f515e6 balrog
542 80f515e6 balrog
static struct intc_group groups_pci[] = {
543 80f515e6 balrog
        INTC_GROUP(PCIC1, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
544 80f515e6 balrog
                   PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3),
545 80f515e6 balrog
};
546 80f515e6 balrog
547 c6d86a33 balrog
static struct intc_vect vectors_irl[] = {
548 c6d86a33 balrog
        INTC_VECT(IRL_0, 0x200),
549 c6d86a33 balrog
        INTC_VECT(IRL_1, 0x220),
550 c6d86a33 balrog
        INTC_VECT(IRL_2, 0x240),
551 c6d86a33 balrog
        INTC_VECT(IRL_3, 0x260),
552 c6d86a33 balrog
        INTC_VECT(IRL_4, 0x280),
553 c6d86a33 balrog
        INTC_VECT(IRL_5, 0x2a0),
554 c6d86a33 balrog
        INTC_VECT(IRL_6, 0x2c0),
555 c6d86a33 balrog
        INTC_VECT(IRL_7, 0x2e0),
556 c6d86a33 balrog
        INTC_VECT(IRL_8, 0x300),
557 c6d86a33 balrog
        INTC_VECT(IRL_9, 0x320),
558 c6d86a33 balrog
        INTC_VECT(IRL_A, 0x340),
559 c6d86a33 balrog
        INTC_VECT(IRL_B, 0x360),
560 c6d86a33 balrog
        INTC_VECT(IRL_C, 0x380),
561 c6d86a33 balrog
        INTC_VECT(IRL_D, 0x3a0),
562 c6d86a33 balrog
        INTC_VECT(IRL_E, 0x3c0),
563 c6d86a33 balrog
};
564 c6d86a33 balrog
565 c6d86a33 balrog
static struct intc_group groups_irl[] = {
566 c6d86a33 balrog
        INTC_GROUP(IRL, IRL_0, IRL_1, IRL_2, IRL_3, IRL_4, IRL_5, IRL_6,
567 c6d86a33 balrog
                IRL_7, IRL_8, IRL_9, IRL_A, IRL_B, IRL_C, IRL_D, IRL_E),
568 c6d86a33 balrog
};
569 c6d86a33 balrog
570 29e179bc aurel32
/**********************************************************************
571 29e179bc aurel32
 Memory mapped cache and TLB
572 29e179bc aurel32
**********************************************************************/
573 29e179bc aurel32
574 29e179bc aurel32
#define MM_REGION_MASK   0x07000000
575 29e179bc aurel32
#define MM_ICACHE_ADDR   (0)
576 29e179bc aurel32
#define MM_ICACHE_DATA   (1)
577 29e179bc aurel32
#define MM_ITLB_ADDR     (2)
578 29e179bc aurel32
#define MM_ITLB_DATA     (3)
579 29e179bc aurel32
#define MM_OCACHE_ADDR   (4)
580 29e179bc aurel32
#define MM_OCACHE_DATA   (5)
581 29e179bc aurel32
#define MM_UTLB_ADDR     (6)
582 29e179bc aurel32
#define MM_UTLB_DATA     (7)
583 29e179bc aurel32
#define MM_REGION_TYPE(addr)  ((addr & MM_REGION_MASK) >> 24)
584 29e179bc aurel32
585 29e179bc aurel32
static uint32_t invalid_read(void *opaque, target_phys_addr_t addr)
586 29e179bc aurel32
{
587 29e179bc aurel32
    assert(0);
588 29e179bc aurel32
589 29e179bc aurel32
    return 0;
590 29e179bc aurel32
}
591 29e179bc aurel32
592 29e179bc aurel32
static uint32_t sh7750_mmct_readl(void *opaque, target_phys_addr_t addr)
593 29e179bc aurel32
{
594 29e179bc aurel32
    uint32_t ret = 0;
595 29e179bc aurel32
596 29e179bc aurel32
    switch (MM_REGION_TYPE(addr)) {
597 29e179bc aurel32
    case MM_ICACHE_ADDR:
598 29e179bc aurel32
    case MM_ICACHE_DATA:
599 29e179bc aurel32
        /* do nothing */
600 29e179bc aurel32
        break;
601 29e179bc aurel32
    case MM_ITLB_ADDR:
602 29e179bc aurel32
    case MM_ITLB_DATA:
603 29e179bc aurel32
        /* XXXXX */
604 29e179bc aurel32
        assert(0);
605 29e179bc aurel32
        break;
606 29e179bc aurel32
    case MM_OCACHE_ADDR:
607 29e179bc aurel32
    case MM_OCACHE_DATA:
608 29e179bc aurel32
        /* do nothing */
609 29e179bc aurel32
        break;
610 29e179bc aurel32
    case MM_UTLB_ADDR:
611 29e179bc aurel32
    case MM_UTLB_DATA:
612 29e179bc aurel32
        /* XXXXX */
613 29e179bc aurel32
        assert(0);
614 29e179bc aurel32
        break;
615 29e179bc aurel32
    default:
616 29e179bc aurel32
        assert(0);
617 29e179bc aurel32
    }
618 29e179bc aurel32
619 29e179bc aurel32
    return ret;
620 29e179bc aurel32
}
621 29e179bc aurel32
622 29e179bc aurel32
static void invalid_write(void *opaque, target_phys_addr_t addr,
623 29e179bc aurel32
                          uint32_t mem_value)
624 29e179bc aurel32
{
625 29e179bc aurel32
    assert(0);
626 29e179bc aurel32
}
627 29e179bc aurel32
628 29e179bc aurel32
static void sh7750_mmct_writel(void *opaque, target_phys_addr_t addr,
629 29e179bc aurel32
                                uint32_t mem_value)
630 29e179bc aurel32
{
631 29e179bc aurel32
    SH7750State *s = opaque;
632 29e179bc aurel32
633 29e179bc aurel32
    switch (MM_REGION_TYPE(addr)) {
634 29e179bc aurel32
    case MM_ICACHE_ADDR:
635 29e179bc aurel32
    case MM_ICACHE_DATA:
636 29e179bc aurel32
        /* do nothing */
637 29e179bc aurel32
        break;
638 29e179bc aurel32
    case MM_ITLB_ADDR:
639 29e179bc aurel32
    case MM_ITLB_DATA:
640 29e179bc aurel32
        /* XXXXX */
641 29e179bc aurel32
        assert(0);
642 29e179bc aurel32
        break;
643 29e179bc aurel32
    case MM_OCACHE_ADDR:
644 29e179bc aurel32
    case MM_OCACHE_DATA:
645 29e179bc aurel32
        /* do nothing */
646 29e179bc aurel32
        break;
647 29e179bc aurel32
    case MM_UTLB_ADDR:
648 29e179bc aurel32
        cpu_sh4_write_mmaped_utlb_addr(s->cpu, addr, mem_value);
649 29e179bc aurel32
        break;
650 29e179bc aurel32
    case MM_UTLB_DATA:
651 29e179bc aurel32
        /* XXXXX */
652 29e179bc aurel32
        assert(0);
653 29e179bc aurel32
        break;
654 29e179bc aurel32
    default:
655 29e179bc aurel32
        assert(0);
656 29e179bc aurel32
        break;
657 29e179bc aurel32
    }
658 29e179bc aurel32
}
659 29e179bc aurel32
660 29e179bc aurel32
static CPUReadMemoryFunc *sh7750_mmct_read[] = {
661 29e179bc aurel32
    invalid_read,
662 29e179bc aurel32
    invalid_read,
663 29e179bc aurel32
    sh7750_mmct_readl
664 29e179bc aurel32
};
665 29e179bc aurel32
666 29e179bc aurel32
static CPUWriteMemoryFunc *sh7750_mmct_write[] = {
667 29e179bc aurel32
    invalid_write,
668 29e179bc aurel32
    invalid_write,
669 29e179bc aurel32
    sh7750_mmct_writel
670 29e179bc aurel32
};
671 29e179bc aurel32
672 27c7ca7e bellard
SH7750State *sh7750_init(CPUSH4State * cpu)
673 27c7ca7e bellard
{
674 27c7ca7e bellard
    SH7750State *s;
675 27c7ca7e bellard
    int sh7750_io_memory;
676 29e179bc aurel32
    int sh7750_mm_cache_and_tlb; /* memory mapped cache and tlb */
677 27c7ca7e bellard
678 27c7ca7e bellard
    s = qemu_mallocz(sizeof(SH7750State));
679 27c7ca7e bellard
    s->cpu = cpu;
680 27c7ca7e bellard
    s->periph_freq = 60000000;        /* 60MHz */
681 27c7ca7e bellard
    sh7750_io_memory = cpu_register_io_memory(0,
682 27c7ca7e bellard
                                              sh7750_mem_read,
683 27c7ca7e bellard
                                              sh7750_mem_write, s);
684 486579de balrog
    cpu_register_physical_memory_offset(0x1f000000, 0x1000,
685 486579de balrog
                                        sh7750_io_memory, 0x1f000000);
686 5c16736a balrog
    cpu_register_physical_memory_offset(0xff000000, 0x1000,
687 5c16736a balrog
                                        sh7750_io_memory, 0x1f000000);
688 486579de balrog
    cpu_register_physical_memory_offset(0x1f800000, 0x1000,
689 486579de balrog
                                        sh7750_io_memory, 0x1f800000);
690 5c16736a balrog
    cpu_register_physical_memory_offset(0xff800000, 0x1000,
691 5c16736a balrog
                                        sh7750_io_memory, 0x1f800000);
692 486579de balrog
    cpu_register_physical_memory_offset(0x1fc00000, 0x1000,
693 486579de balrog
                                        sh7750_io_memory, 0x1fc00000);
694 5c16736a balrog
    cpu_register_physical_memory_offset(0xffc00000, 0x1000,
695 5c16736a balrog
                                        sh7750_io_memory, 0x1fc00000);
696 2f062c72 ths
697 29e179bc aurel32
    sh7750_mm_cache_and_tlb = cpu_register_io_memory(0,
698 29e179bc aurel32
                                                     sh7750_mmct_read,
699 29e179bc aurel32
                                                     sh7750_mmct_write, s);
700 29e179bc aurel32
    cpu_register_physical_memory(0xf0000000, 0x08000000,
701 29e179bc aurel32
                                 sh7750_mm_cache_and_tlb);
702 29e179bc aurel32
703 80f515e6 balrog
    sh_intc_init(&s->intc, NR_SOURCES,
704 80f515e6 balrog
                 _INTC_ARRAY(mask_registers),
705 80f515e6 balrog
                 _INTC_ARRAY(prio_registers));
706 80f515e6 balrog
707 0fd3ca30 aurel32
    sh_intc_register_sources(&s->intc,
708 80f515e6 balrog
                             _INTC_ARRAY(vectors),
709 80f515e6 balrog
                             _INTC_ARRAY(groups));
710 80f515e6 balrog
711 e96e2044 ths
    cpu->intc_handle = &s->intc;
712 e96e2044 ths
713 bf5b7423 aurel32
    sh_serial_init(0x1fe00000, 0, s->periph_freq, serial_hds[0],
714 4e7ed2d1 aurel32
                   s->intc.irqs[SCI1_ERI],
715 4e7ed2d1 aurel32
                   s->intc.irqs[SCI1_RXI],
716 4e7ed2d1 aurel32
                   s->intc.irqs[SCI1_TXI],
717 4e7ed2d1 aurel32
                   s->intc.irqs[SCI1_TEI],
718 bf5b7423 aurel32
                   NULL);
719 2f062c72 ths
    sh_serial_init(0x1fe80000, SH_SERIAL_FEAT_SCIF,
720 bf5b7423 aurel32
                   s->periph_freq, serial_hds[1],
721 4e7ed2d1 aurel32
                   s->intc.irqs[SCIF_ERI],
722 4e7ed2d1 aurel32
                   s->intc.irqs[SCIF_RXI],
723 4e7ed2d1 aurel32
                   s->intc.irqs[SCIF_TXI],
724 bf5b7423 aurel32
                   NULL,
725 4e7ed2d1 aurel32
                   s->intc.irqs[SCIF_BRI]);
726 cd1a3f68 ths
727 cd1a3f68 ths
    tmu012_init(0x1fd80000,
728 cd1a3f68 ths
                TMU012_FEAT_TOCR | TMU012_FEAT_3CHAN | TMU012_FEAT_EXTCLK,
729 703243a0 balrog
                s->periph_freq,
730 96e2fc41 aurel32
                s->intc.irqs[TMU0],
731 96e2fc41 aurel32
                s->intc.irqs[TMU1],
732 96e2fc41 aurel32
                s->intc.irqs[TMU2_TUNI],
733 96e2fc41 aurel32
                s->intc.irqs[TMU2_TICPI]);
734 80f515e6 balrog
735 0fd3ca30 aurel32
    if (cpu->id & (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7751)) {
736 0fd3ca30 aurel32
        sh_intc_register_sources(&s->intc,
737 80f515e6 balrog
                                 _INTC_ARRAY(vectors_dma4),
738 80f515e6 balrog
                                 _INTC_ARRAY(groups_dma4));
739 80f515e6 balrog
    }
740 80f515e6 balrog
741 0fd3ca30 aurel32
    if (cpu->id & (SH_CPU_SH7750R | SH_CPU_SH7751R)) {
742 0fd3ca30 aurel32
        sh_intc_register_sources(&s->intc,
743 80f515e6 balrog
                                 _INTC_ARRAY(vectors_dma8),
744 80f515e6 balrog
                                 _INTC_ARRAY(groups_dma8));
745 80f515e6 balrog
    }
746 80f515e6 balrog
747 0fd3ca30 aurel32
    if (cpu->id & (SH_CPU_SH7750R | SH_CPU_SH7751 | SH_CPU_SH7751R)) {
748 0fd3ca30 aurel32
        sh_intc_register_sources(&s->intc,
749 80f515e6 balrog
                                 _INTC_ARRAY(vectors_tmu34),
750 f26ae302 bellard
                                 NULL, 0);
751 703243a0 balrog
        tmu012_init(0x1e100000, 0, s->periph_freq,
752 96e2fc41 aurel32
                    s->intc.irqs[TMU3],
753 96e2fc41 aurel32
                    s->intc.irqs[TMU4],
754 703243a0 balrog
                    NULL, NULL);
755 80f515e6 balrog
    }
756 80f515e6 balrog
757 0fd3ca30 aurel32
    if (cpu->id & (SH_CPU_SH7751_ALL)) {
758 0fd3ca30 aurel32
        sh_intc_register_sources(&s->intc,
759 80f515e6 balrog
                                 _INTC_ARRAY(vectors_pci),
760 80f515e6 balrog
                                 _INTC_ARRAY(groups_pci));
761 80f515e6 balrog
    }
762 80f515e6 balrog
763 0fd3ca30 aurel32
    if (cpu->id & (SH_CPU_SH7750S | SH_CPU_SH7750R | SH_CPU_SH7751_ALL)) {
764 0fd3ca30 aurel32
        sh_intc_register_sources(&s->intc,
765 80f515e6 balrog
                                 _INTC_ARRAY(vectors_irlm),
766 f26ae302 bellard
                                 NULL, 0);
767 80f515e6 balrog
    }
768 80f515e6 balrog
769 c6d86a33 balrog
    sh_intc_register_sources(&s->intc,
770 c6d86a33 balrog
                                _INTC_ARRAY(vectors_irl),
771 c6d86a33 balrog
                                _INTC_ARRAY(groups_irl));
772 27c7ca7e bellard
    return s;
773 27c7ca7e bellard
}
774 c6d86a33 balrog
775 c6d86a33 balrog
qemu_irq sh7750_irl(SH7750State *s)
776 c6d86a33 balrog
{
777 c6d86a33 balrog
    sh_intc_toggle_source(sh_intc_source(&s->intc, IRL), 1, 0); /* enable */
778 c6d86a33 balrog
    return qemu_allocate_irqs(sh_intc_set_irl, sh_intc_source(&s->intc, IRL),
779 c6d86a33 balrog
                               1)[0];
780 c6d86a33 balrog
}