Statistics
| Branch: | Revision:

root / hw / sh7750.c @ 7cef3f4f

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