Statistics
| Branch: | Revision:

root / hw / sh7750.c @ 6059631c

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