Statistics
| Branch: | Revision:

root / hw / sh7750.c @ f3e3aa8c

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