4 * Copyright (c) 2005 Samuel Tardieu
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
22 #include "exec/exec-all.h"
24 #include "sysemu/sysemu.h"
26 #if !defined(CONFIG_USER_ONLY)
27 #include "hw/sh4/sh_intc.h"
30 #if defined(CONFIG_USER_ONLY)
32 void superh_cpu_do_interrupt(CPUState
*cs
)
34 cs
->exception_index
= -1;
37 int superh_cpu_handle_mmu_fault(CPUState
*cs
, vaddr address
, int rw
,
40 SuperHCPU
*cpu
= SUPERH_CPU(cs
);
41 CPUSH4State
*env
= &cpu
->env
;
44 cs
->exception_index
= -1;
47 cs
->exception_index
= 0x0a0;
50 cs
->exception_index
= 0x0c0;
53 cs
->exception_index
= 0x0a0;
59 int cpu_sh4_is_cached(CPUSH4State
* env
, target_ulong addr
)
61 /* For user mode, only U0 area is cacheable. */
62 return !(addr
& 0x80000000);
65 #else /* !CONFIG_USER_ONLY */
68 #define MMU_ITLB_MISS (-1)
69 #define MMU_ITLB_MULTIPLE (-2)
70 #define MMU_ITLB_VIOLATION (-3)
71 #define MMU_DTLB_MISS_READ (-4)
72 #define MMU_DTLB_MISS_WRITE (-5)
73 #define MMU_DTLB_INITIAL_WRITE (-6)
74 #define MMU_DTLB_VIOLATION_READ (-7)
75 #define MMU_DTLB_VIOLATION_WRITE (-8)
76 #define MMU_DTLB_MULTIPLE (-9)
77 #define MMU_DTLB_MISS (-10)
78 #define MMU_IADDR_ERROR (-11)
79 #define MMU_DADDR_ERROR_READ (-12)
80 #define MMU_DADDR_ERROR_WRITE (-13)
82 void superh_cpu_do_interrupt(CPUState
*cs
)
84 SuperHCPU
*cpu
= SUPERH_CPU(cs
);
85 CPUSH4State
*env
= &cpu
->env
;
86 int do_irq
= cs
->interrupt_request
& CPU_INTERRUPT_HARD
;
87 int do_exp
, irq_vector
= cs
->exception_index
;
89 /* prioritize exceptions over interrupts */
91 do_exp
= cs
->exception_index
!= -1;
92 do_irq
= do_irq
&& (cs
->exception_index
== -1);
94 if (env
->sr
& (1u << SR_BL
)) {
95 if (do_exp
&& cs
->exception_index
!= 0x1e0) {
96 /* In theory a masked exception generates a reset exception,
97 which in turn jumps to the reset vector. However this only
98 works when using a bootloader. When using a kernel and an
99 initrd, they need to be reloaded and the program counter
100 should be loaded with the kernel entry point.
101 qemu_system_reset_request takes care of that. */
102 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
105 if (do_irq
&& !env
->in_sleep
) {
112 irq_vector
= sh_intc_get_pending_vector(env
->intc_handle
,
113 (env
->sr
>> 4) & 0xf);
114 if (irq_vector
== -1) {
119 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
121 switch (cs
->exception_index
) {
123 expname
= "addr_error";
126 expname
= "tlb_miss";
129 expname
= "tlb_violation";
132 expname
= "illegal_instruction";
135 expname
= "slot_illegal_instruction";
138 expname
= "fpu_disable";
141 expname
= "slot_fpu";
144 expname
= "data_write";
147 expname
= "dtlb_miss_write";
150 expname
= "dtlb_violation_write";
153 expname
= "fpu_exception";
156 expname
= "initial_page_write";
162 expname
= do_irq
? "interrupt" : "???";
165 qemu_log("exception 0x%03x [%s] raised\n",
166 irq_vector
, expname
);
167 log_cpu_state(cs
, 0);
170 env
->ssr
= cpu_read_sr(env
);
172 env
->sgr
= env
->gregs
[15];
173 env
->sr
|= (1u << SR_BL
) | (1u << SR_MD
) | (1u << SR_RB
);
175 if (env
->flags
& DELAY_SLOT_MASK
) {
176 /* Branch instruction should be executed again before delay slot. */
178 /* Clear flags for exception/interrupt routine. */
179 env
->flags
&= ~DELAY_SLOT_MASK
;
183 env
->expevt
= cs
->exception_index
;
184 switch (cs
->exception_index
) {
188 env
->sr
&= ~(1u << SR_FD
);
189 env
->sr
|= 0xf << 4; /* IMASK */
190 env
->pc
= 0xa0000000;
194 env
->pc
= env
->vbr
+ 0x400;
197 env
->spc
+= 2; /* special case for TRAPA */
200 env
->pc
= env
->vbr
+ 0x100;
207 env
->intevt
= irq_vector
;
208 env
->pc
= env
->vbr
+ 0x600;
213 static void update_itlb_use(CPUSH4State
* env
, int itlbnb
)
215 uint8_t or_mask
= 0, and_mask
= (uint8_t) - 1;
234 env
->mmucr
&= (and_mask
<< 24) | 0x00ffffff;
235 env
->mmucr
|= (or_mask
<< 24);
238 static int itlb_replacement(CPUSH4State
* env
)
240 SuperHCPU
*cpu
= sh_env_get_cpu(env
);
242 if ((env
->mmucr
& 0xe0000000) == 0xe0000000) {
245 if ((env
->mmucr
& 0x98000000) == 0x18000000) {
248 if ((env
->mmucr
& 0x54000000) == 0x04000000) {
251 if ((env
->mmucr
& 0x2c000000) == 0x00000000) {
254 cpu_abort(CPU(cpu
), "Unhandled itlb_replacement");
257 /* Find the corresponding entry in the right TLB
258 Return entry, MMU_DTLB_MISS or MMU_DTLB_MULTIPLE
260 static int find_tlb_entry(CPUSH4State
* env
, target_ulong address
,
261 tlb_t
* entries
, uint8_t nbtlb
, int use_asid
)
263 int match
= MMU_DTLB_MISS
;
268 asid
= env
->pteh
& 0xff;
270 for (i
= 0; i
< nbtlb
; i
++) {
272 continue; /* Invalid entry */
273 if (!entries
[i
].sh
&& use_asid
&& entries
[i
].asid
!= asid
)
274 continue; /* Bad ASID */
275 start
= (entries
[i
].vpn
<< 10) & ~(entries
[i
].size
- 1);
276 end
= start
+ entries
[i
].size
- 1;
277 if (address
>= start
&& address
<= end
) { /* Match */
278 if (match
!= MMU_DTLB_MISS
)
279 return MMU_DTLB_MULTIPLE
; /* Multiple match */
286 static void increment_urc(CPUSH4State
* env
)
291 urb
= ((env
->mmucr
) >> 18) & 0x3f;
292 urc
= ((env
->mmucr
) >> 10) & 0x3f;
294 if ((urb
> 0 && urc
> urb
) || urc
> (UTLB_SIZE
- 1))
296 env
->mmucr
= (env
->mmucr
& 0xffff03ff) | (urc
<< 10);
299 /* Copy and utlb entry into itlb
302 static int copy_utlb_entry_itlb(CPUSH4State
*env
, int utlb
)
307 itlb
= itlb_replacement(env
);
308 ientry
= &env
->itlb
[itlb
];
310 tlb_flush_page(CPU(sh_env_get_cpu(env
)), ientry
->vpn
<< 10);
312 *ientry
= env
->utlb
[utlb
];
313 update_itlb_use(env
, itlb
);
318 Return entry, MMU_ITLB_MISS, MMU_ITLB_MULTIPLE or MMU_DTLB_MULTIPLE
320 static int find_itlb_entry(CPUSH4State
* env
, target_ulong address
,
325 e
= find_tlb_entry(env
, address
, env
->itlb
, ITLB_SIZE
, use_asid
);
326 if (e
== MMU_DTLB_MULTIPLE
) {
327 e
= MMU_ITLB_MULTIPLE
;
328 } else if (e
== MMU_DTLB_MISS
) {
331 update_itlb_use(env
, e
);
337 Return entry, MMU_DTLB_MISS, MMU_DTLB_MULTIPLE */
338 static int find_utlb_entry(CPUSH4State
* env
, target_ulong address
, int use_asid
)
340 /* per utlb access */
344 return find_tlb_entry(env
, address
, env
->utlb
, UTLB_SIZE
, use_asid
);
347 /* Match address against MMU
348 Return MMU_OK, MMU_DTLB_MISS_READ, MMU_DTLB_MISS_WRITE,
349 MMU_DTLB_INITIAL_WRITE, MMU_DTLB_VIOLATION_READ,
350 MMU_DTLB_VIOLATION_WRITE, MMU_ITLB_MISS,
351 MMU_ITLB_MULTIPLE, MMU_ITLB_VIOLATION,
352 MMU_IADDR_ERROR, MMU_DADDR_ERROR_READ, MMU_DADDR_ERROR_WRITE.
354 static int get_mmu_address(CPUSH4State
* env
, target_ulong
* physical
,
355 int *prot
, target_ulong address
,
356 int rw
, int access_type
)
359 tlb_t
*matching
= NULL
;
361 use_asid
= !(env
->mmucr
& MMUCR_SV
) || !(env
->sr
& (1u << SR_MD
));
364 n
= find_itlb_entry(env
, address
, use_asid
);
366 matching
= &env
->itlb
[n
];
367 if (!(env
->sr
& (1u << SR_MD
)) && !(matching
->pr
& 2)) {
368 n
= MMU_ITLB_VIOLATION
;
373 n
= find_utlb_entry(env
, address
, use_asid
);
375 n
= copy_utlb_entry_itlb(env
, n
);
376 matching
= &env
->itlb
[n
];
377 if (!(env
->sr
& (1u << SR_MD
)) && !(matching
->pr
& 2)) {
378 n
= MMU_ITLB_VIOLATION
;
380 *prot
= PAGE_READ
| PAGE_EXEC
;
381 if ((matching
->pr
& 1) && matching
->d
) {
385 } else if (n
== MMU_DTLB_MULTIPLE
) {
386 n
= MMU_ITLB_MULTIPLE
;
387 } else if (n
== MMU_DTLB_MISS
) {
392 n
= find_utlb_entry(env
, address
, use_asid
);
394 matching
= &env
->utlb
[n
];
395 if (!(env
->sr
& (1u << SR_MD
)) && !(matching
->pr
& 2)) {
396 n
= (rw
== 1) ? MMU_DTLB_VIOLATION_WRITE
:
397 MMU_DTLB_VIOLATION_READ
;
398 } else if ((rw
== 1) && !(matching
->pr
& 1)) {
399 n
= MMU_DTLB_VIOLATION_WRITE
;
400 } else if ((rw
== 1) && !matching
->d
) {
401 n
= MMU_DTLB_INITIAL_WRITE
;
404 if ((matching
->pr
& 1) && matching
->d
) {
408 } else if (n
== MMU_DTLB_MISS
) {
409 n
= (rw
== 1) ? MMU_DTLB_MISS_WRITE
:
415 *physical
= ((matching
->ppn
<< 10) & ~(matching
->size
- 1)) |
416 (address
& (matching
->size
- 1));
421 static int get_physical_address(CPUSH4State
* env
, target_ulong
* physical
,
422 int *prot
, target_ulong address
,
423 int rw
, int access_type
)
425 /* P1, P2 and P4 areas do not use translation */
426 if ((address
>= 0x80000000 && address
< 0xc0000000) ||
427 address
>= 0xe0000000) {
428 if (!(env
->sr
& (1u << SR_MD
))
429 && (address
< 0xe0000000 || address
>= 0xe4000000)) {
430 /* Unauthorized access in user mode (only store queues are available) */
431 qemu_log_mask(LOG_GUEST_ERROR
, "Unauthorized access\n");
433 return MMU_DADDR_ERROR_READ
;
435 return MMU_DADDR_ERROR_WRITE
;
437 return MMU_IADDR_ERROR
;
439 if (address
>= 0x80000000 && address
< 0xc0000000) {
440 /* Mask upper 3 bits for P1 and P2 areas */
441 *physical
= address
& 0x1fffffff;
445 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
449 /* If MMU is disabled, return the corresponding physical page */
450 if (!(env
->mmucr
& MMUCR_AT
)) {
451 *physical
= address
& 0x1FFFFFFF;
452 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
456 /* We need to resort to the MMU */
457 return get_mmu_address(env
, physical
, prot
, address
, rw
, access_type
);
460 int superh_cpu_handle_mmu_fault(CPUState
*cs
, vaddr address
, int rw
,
463 SuperHCPU
*cpu
= SUPERH_CPU(cs
);
464 CPUSH4State
*env
= &cpu
->env
;
465 target_ulong physical
;
466 int prot
, ret
, access_type
;
468 access_type
= ACCESS_INT
;
470 get_physical_address(env
, &physical
, &prot
, address
, rw
,
475 if (ret
!= MMU_DTLB_MULTIPLE
&& ret
!= MMU_ITLB_MULTIPLE
) {
476 env
->pteh
= (env
->pteh
& PTEH_ASID_MASK
) |
477 (address
& PTEH_VPN_MASK
);
481 case MMU_DTLB_MISS_READ
:
482 cs
->exception_index
= 0x040;
484 case MMU_DTLB_MULTIPLE
:
485 case MMU_ITLB_MULTIPLE
:
486 cs
->exception_index
= 0x140;
488 case MMU_ITLB_VIOLATION
:
489 cs
->exception_index
= 0x0a0;
491 case MMU_DTLB_MISS_WRITE
:
492 cs
->exception_index
= 0x060;
494 case MMU_DTLB_INITIAL_WRITE
:
495 cs
->exception_index
= 0x080;
497 case MMU_DTLB_VIOLATION_READ
:
498 cs
->exception_index
= 0x0a0;
500 case MMU_DTLB_VIOLATION_WRITE
:
501 cs
->exception_index
= 0x0c0;
503 case MMU_IADDR_ERROR
:
504 case MMU_DADDR_ERROR_READ
:
505 cs
->exception_index
= 0x0e0;
507 case MMU_DADDR_ERROR_WRITE
:
508 cs
->exception_index
= 0x100;
511 cpu_abort(cs
, "Unhandled MMU fault");
516 address
&= TARGET_PAGE_MASK
;
517 physical
&= TARGET_PAGE_MASK
;
519 tlb_set_page(cs
, address
, physical
, prot
, mmu_idx
, TARGET_PAGE_SIZE
);
523 hwaddr
superh_cpu_get_phys_page_debug(CPUState
*cs
, vaddr addr
)
525 SuperHCPU
*cpu
= SUPERH_CPU(cs
);
526 target_ulong physical
;
529 get_physical_address(&cpu
->env
, &physical
, &prot
, addr
, 0, 0);
533 void cpu_load_tlb(CPUSH4State
* env
)
535 SuperHCPU
*cpu
= sh_env_get_cpu(env
);
536 int n
= cpu_mmucr_urc(env
->mmucr
);
537 tlb_t
* entry
= &env
->utlb
[n
];
540 /* Overwriting valid entry in utlb. */
541 target_ulong address
= entry
->vpn
<< 10;
542 tlb_flush_page(CPU(cpu
), address
);
545 /* Take values into cpu status from registers. */
546 entry
->asid
= (uint8_t)cpu_pteh_asid(env
->pteh
);
547 entry
->vpn
= cpu_pteh_vpn(env
->pteh
);
548 entry
->v
= (uint8_t)cpu_ptel_v(env
->ptel
);
549 entry
->ppn
= cpu_ptel_ppn(env
->ptel
);
550 entry
->sz
= (uint8_t)cpu_ptel_sz(env
->ptel
);
553 entry
->size
= 1024; /* 1K */
556 entry
->size
= 1024 * 4; /* 4K */
559 entry
->size
= 1024 * 64; /* 64K */
562 entry
->size
= 1024 * 1024; /* 1M */
565 cpu_abort(CPU(cpu
), "Unhandled load_tlb");
568 entry
->sh
= (uint8_t)cpu_ptel_sh(env
->ptel
);
569 entry
->c
= (uint8_t)cpu_ptel_c(env
->ptel
);
570 entry
->pr
= (uint8_t)cpu_ptel_pr(env
->ptel
);
571 entry
->d
= (uint8_t)cpu_ptel_d(env
->ptel
);
572 entry
->wt
= (uint8_t)cpu_ptel_wt(env
->ptel
);
573 entry
->sa
= (uint8_t)cpu_ptea_sa(env
->ptea
);
574 entry
->tc
= (uint8_t)cpu_ptea_tc(env
->ptea
);
577 void cpu_sh4_invalidate_tlb(CPUSH4State
*s
)
582 for (i
= 0; i
< UTLB_SIZE
; i
++) {
583 tlb_t
* entry
= &s
->utlb
[i
];
587 for (i
= 0; i
< ITLB_SIZE
; i
++) {
588 tlb_t
* entry
= &s
->itlb
[i
];
592 tlb_flush(CPU(sh_env_get_cpu(s
)));
595 uint32_t cpu_sh4_read_mmaped_itlb_addr(CPUSH4State
*s
,
598 int index
= (addr
& 0x00000300) >> 8;
599 tlb_t
* entry
= &s
->itlb
[index
];
601 return (entry
->vpn
<< 10) |
606 void cpu_sh4_write_mmaped_itlb_addr(CPUSH4State
*s
, hwaddr addr
,
609 uint32_t vpn
= (mem_value
& 0xfffffc00) >> 10;
610 uint8_t v
= (uint8_t)((mem_value
& 0x00000100) >> 8);
611 uint8_t asid
= (uint8_t)(mem_value
& 0x000000ff);
613 int index
= (addr
& 0x00000300) >> 8;
614 tlb_t
* entry
= &s
->itlb
[index
];
616 /* Overwriting valid entry in itlb. */
617 target_ulong address
= entry
->vpn
<< 10;
618 tlb_flush_page(CPU(sh_env_get_cpu(s
)), address
);
625 uint32_t cpu_sh4_read_mmaped_itlb_data(CPUSH4State
*s
,
628 int array
= (addr
& 0x00800000) >> 23;
629 int index
= (addr
& 0x00000300) >> 8;
630 tlb_t
* entry
= &s
->itlb
[index
];
633 /* ITLB Data Array 1 */
634 return (entry
->ppn
<< 10) |
637 ((entry
->sz
& 1) << 6) |
638 ((entry
->sz
& 2) << 4) |
642 /* ITLB Data Array 2 */
643 return (entry
->tc
<< 1) |
648 void cpu_sh4_write_mmaped_itlb_data(CPUSH4State
*s
, hwaddr addr
,
651 int array
= (addr
& 0x00800000) >> 23;
652 int index
= (addr
& 0x00000300) >> 8;
653 tlb_t
* entry
= &s
->itlb
[index
];
656 /* ITLB Data Array 1 */
658 /* Overwriting valid entry in utlb. */
659 target_ulong address
= entry
->vpn
<< 10;
660 tlb_flush_page(CPU(sh_env_get_cpu(s
)), address
);
662 entry
->ppn
= (mem_value
& 0x1ffffc00) >> 10;
663 entry
->v
= (mem_value
& 0x00000100) >> 8;
664 entry
->sz
= (mem_value
& 0x00000080) >> 6 |
665 (mem_value
& 0x00000010) >> 4;
666 entry
->pr
= (mem_value
& 0x00000040) >> 5;
667 entry
->c
= (mem_value
& 0x00000008) >> 3;
668 entry
->sh
= (mem_value
& 0x00000002) >> 1;
670 /* ITLB Data Array 2 */
671 entry
->tc
= (mem_value
& 0x00000008) >> 3;
672 entry
->sa
= (mem_value
& 0x00000007);
676 uint32_t cpu_sh4_read_mmaped_utlb_addr(CPUSH4State
*s
,
679 int index
= (addr
& 0x00003f00) >> 8;
680 tlb_t
* entry
= &s
->utlb
[index
];
682 increment_urc(s
); /* per utlb access */
684 return (entry
->vpn
<< 10) |
689 void cpu_sh4_write_mmaped_utlb_addr(CPUSH4State
*s
, hwaddr addr
,
692 int associate
= addr
& 0x0000080;
693 uint32_t vpn
= (mem_value
& 0xfffffc00) >> 10;
694 uint8_t d
= (uint8_t)((mem_value
& 0x00000200) >> 9);
695 uint8_t v
= (uint8_t)((mem_value
& 0x00000100) >> 8);
696 uint8_t asid
= (uint8_t)(mem_value
& 0x000000ff);
697 int use_asid
= !(s
->mmucr
& MMUCR_SV
) || !(s
->sr
& (1u << SR_MD
));
701 tlb_t
* utlb_match_entry
= NULL
;
702 int needs_tlb_flush
= 0;
705 for (i
= 0; i
< UTLB_SIZE
; i
++) {
706 tlb_t
* entry
= &s
->utlb
[i
];
710 if (entry
->vpn
== vpn
711 && (!use_asid
|| entry
->asid
== asid
|| entry
->sh
)) {
712 if (utlb_match_entry
) {
713 CPUState
*cs
= CPU(sh_env_get_cpu(s
));
715 /* Multiple TLB Exception */
716 cs
->exception_index
= 0x140;
724 utlb_match_entry
= entry
;
726 increment_urc(s
); /* per utlb access */
730 for (i
= 0; i
< ITLB_SIZE
; i
++) {
731 tlb_t
* entry
= &s
->itlb
[i
];
732 if (entry
->vpn
== vpn
733 && (!use_asid
|| entry
->asid
== asid
|| entry
->sh
)) {
736 if (utlb_match_entry
)
737 *entry
= *utlb_match_entry
;
744 if (needs_tlb_flush
) {
745 tlb_flush_page(CPU(sh_env_get_cpu(s
)), vpn
<< 10);
749 int index
= (addr
& 0x00003f00) >> 8;
750 tlb_t
* entry
= &s
->utlb
[index
];
752 CPUState
*cs
= CPU(sh_env_get_cpu(s
));
754 /* Overwriting valid entry in utlb. */
755 target_ulong address
= entry
->vpn
<< 10;
756 tlb_flush_page(cs
, address
);
766 uint32_t cpu_sh4_read_mmaped_utlb_data(CPUSH4State
*s
,
769 int array
= (addr
& 0x00800000) >> 23;
770 int index
= (addr
& 0x00003f00) >> 8;
771 tlb_t
* entry
= &s
->utlb
[index
];
773 increment_urc(s
); /* per utlb access */
776 /* ITLB Data Array 1 */
777 return (entry
->ppn
<< 10) |
780 ((entry
->sz
& 1) << 6) |
781 ((entry
->sz
& 2) << 4) |
787 /* ITLB Data Array 2 */
788 return (entry
->tc
<< 1) |
793 void cpu_sh4_write_mmaped_utlb_data(CPUSH4State
*s
, hwaddr addr
,
796 int array
= (addr
& 0x00800000) >> 23;
797 int index
= (addr
& 0x00003f00) >> 8;
798 tlb_t
* entry
= &s
->utlb
[index
];
800 increment_urc(s
); /* per utlb access */
803 /* UTLB Data Array 1 */
805 /* Overwriting valid entry in utlb. */
806 target_ulong address
= entry
->vpn
<< 10;
807 tlb_flush_page(CPU(sh_env_get_cpu(s
)), address
);
809 entry
->ppn
= (mem_value
& 0x1ffffc00) >> 10;
810 entry
->v
= (mem_value
& 0x00000100) >> 8;
811 entry
->sz
= (mem_value
& 0x00000080) >> 6 |
812 (mem_value
& 0x00000010) >> 4;
813 entry
->pr
= (mem_value
& 0x00000060) >> 5;
814 entry
->c
= (mem_value
& 0x00000008) >> 3;
815 entry
->d
= (mem_value
& 0x00000004) >> 2;
816 entry
->sh
= (mem_value
& 0x00000002) >> 1;
817 entry
->wt
= (mem_value
& 0x00000001);
819 /* UTLB Data Array 2 */
820 entry
->tc
= (mem_value
& 0x00000008) >> 3;
821 entry
->sa
= (mem_value
& 0x00000007);
825 int cpu_sh4_is_cached(CPUSH4State
* env
, target_ulong addr
)
828 int use_asid
= !(env
->mmucr
& MMUCR_SV
) || !(env
->sr
& (1u << SR_MD
));
831 if (env
->sr
& (1u << SR_MD
)) {
832 /* For privileged mode, P2 and P4 area is not cacheable. */
833 if ((0xA0000000 <= addr
&& addr
< 0xC0000000) || 0xE0000000 <= addr
)
836 /* For user mode, only U0 area is cacheable. */
837 if (0x80000000 <= addr
)
842 * TODO : Evaluate CCR and check if the cache is on or off.
843 * Now CCR is not in CPUSH4State, but in SH7750State.
844 * When you move the ccr into CPUSH4State, the code will be
848 /* check if operand cache is enabled or not. */
853 /* if MMU is off, no check for TLB. */
854 if (env
->mmucr
& MMUCR_AT
)
858 n
= find_tlb_entry(env
, addr
, env
->itlb
, ITLB_SIZE
, use_asid
);
860 return env
->itlb
[n
].c
;
862 n
= find_tlb_entry(env
, addr
, env
->utlb
, UTLB_SIZE
, use_asid
);
864 return env
->utlb
[n
].c
;
871 bool superh_cpu_exec_interrupt(CPUState
*cs
, int interrupt_request
)
873 if (interrupt_request
& CPU_INTERRUPT_HARD
) {
874 SuperHCPU
*cpu
= SUPERH_CPU(cs
);
875 CPUSH4State
*env
= &cpu
->env
;
877 /* Delay slots are indivisible, ignore interrupts */
878 if (env
->flags
& DELAY_SLOT_MASK
) {
881 superh_cpu_do_interrupt(cs
);