blob: 2ff0cf4060a517f988a5712439ea02164f50a2be [file] [log] [blame]
bellardfdf9b3e2006-04-27 21:07:38 +00001/*
2 * SH4 emulation
ths5fafdf22007-09-16 21:08:06 +00003 *
bellardfdf9b3e2006-04-27 21:07:38 +00004 * Copyright (c) 2005 Samuel Tardieu
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU Lesser General Public
Blue Swirl8167ee82009-07-16 20:47:01 +000017 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
bellardfdf9b3e2006-04-27 21:07:38 +000018 */
Peter Maydell9d4c9942016-01-26 18:17:20 +000019#include "qemu/osdep.h"
bellardfdf9b3e2006-04-27 21:07:38 +000020
21#include "cpu.h"
Paolo Bonzini63c91552016-03-15 13:18:37 +010022#include "exec/exec-all.h"
Paolo Bonzini508127e2016-01-07 16:55:28 +030023#include "exec/log.h"
Aurelien Jarno73479c52017-05-17 00:48:18 +020024#include "sysemu/sysemu.h"
Benoît Canetb279e5e2011-11-17 14:23:01 +010025
26#if !defined(CONFIG_USER_ONLY)
Paolo Bonzini0d09e412013-02-05 17:06:20 +010027#include "hw/sh4/sh_intc.h"
Benoît Canetb279e5e2011-11-17 14:23:01 +010028#endif
bellardfdf9b3e2006-04-27 21:07:38 +000029
pbrook355fb232006-06-17 19:58:25 +000030#if defined(CONFIG_USER_ONLY)
31
Andreas Färber97a8ea52013-02-02 10:57:51 +010032void superh_cpu_do_interrupt(CPUState *cs)
pbrook355fb232006-06-17 19:58:25 +000033{
Andreas Färber27103422013-08-26 08:31:06 +020034 cs->exception_index = -1;
pbrook355fb232006-06-17 19:58:25 +000035}
36
Laurent Vivier98670d42018-01-18 20:38:40 +010037int superh_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw,
Andreas Färber75104542013-08-26 03:01:33 +020038 int mmu_idx)
pbrook355fb232006-06-17 19:58:25 +000039{
Andreas Färber75104542013-08-26 03:01:33 +020040 SuperHCPU *cpu = SUPERH_CPU(cs);
41 CPUSH4State *env = &cpu->env;
42
pbrook355fb232006-06-17 19:58:25 +000043 env->tea = address;
Andreas Färber27103422013-08-26 08:31:06 +020044 cs->exception_index = -1;
pbrook355fb232006-06-17 19:58:25 +000045 switch (rw) {
46 case 0:
Andreas Färber27103422013-08-26 08:31:06 +020047 cs->exception_index = 0x0a0;
pbrook355fb232006-06-17 19:58:25 +000048 break;
49 case 1:
Andreas Färber27103422013-08-26 08:31:06 +020050 cs->exception_index = 0x0c0;
pbrook355fb232006-06-17 19:58:25 +000051 break;
aurel32cf7055b2008-11-21 22:33:15 +000052 case 2:
Andreas Färber27103422013-08-26 08:31:06 +020053 cs->exception_index = 0x0a0;
aurel32cf7055b2008-11-21 22:33:15 +000054 break;
pbrook355fb232006-06-17 19:58:25 +000055 }
56 return 1;
57}
58
edgar_igl3c1adf12009-04-03 07:29:38 +000059int cpu_sh4_is_cached(CPUSH4State * env, target_ulong addr)
60{
Veres Lajos67cc32e2015-09-08 22:45:14 +010061 /* For user mode, only U0 area is cacheable. */
edgar_igl679dee32009-04-03 07:33:24 +000062 return !(addr & 0x80000000);
edgar_igl3c1adf12009-04-03 07:29:38 +000063}
64
pbrook355fb232006-06-17 19:58:25 +000065#else /* !CONFIG_USER_ONLY */
66
bellardfdf9b3e2006-04-27 21:07:38 +000067#define MMU_OK 0
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)
aurel32cf7055b2008-11-21 22:33:15 +000078#define MMU_IADDR_ERROR (-11)
79#define MMU_DADDR_ERROR_READ (-12)
80#define MMU_DADDR_ERROR_WRITE (-13)
bellardfdf9b3e2006-04-27 21:07:38 +000081
Andreas Färber97a8ea52013-02-02 10:57:51 +010082void superh_cpu_do_interrupt(CPUState *cs)
bellardfdf9b3e2006-04-27 21:07:38 +000083{
Andreas Färber97a8ea52013-02-02 10:57:51 +010084 SuperHCPU *cpu = SUPERH_CPU(cs);
85 CPUSH4State *env = &cpu->env;
Andreas Färber259186a2013-01-17 18:51:17 +010086 int do_irq = cs->interrupt_request & CPU_INTERRUPT_HARD;
Andreas Färber27103422013-08-26 08:31:06 +020087 int do_exp, irq_vector = cs->exception_index;
thse96e2042007-12-02 06:18:24 +000088
89 /* prioritize exceptions over interrupts */
90
Andreas Färber27103422013-08-26 08:31:06 +020091 do_exp = cs->exception_index != -1;
92 do_irq = do_irq && (cs->exception_index == -1);
thse96e2042007-12-02 06:18:24 +000093
Aurelien Jarno5ed9a252015-05-25 01:28:56 +020094 if (env->sr & (1u << SR_BL)) {
Andreas Färber27103422013-08-26 08:31:06 +020095 if (do_exp && cs->exception_index != 0x1e0) {
Aurelien Jarno73479c52017-05-17 00:48:18 +020096 /* 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);
103 return;
thse96e2042007-12-02 06:18:24 +0000104 }
Aurelien Jarnoefac4152011-02-24 12:31:41 +0100105 if (do_irq && !env->in_sleep) {
thse96e2042007-12-02 06:18:24 +0000106 return; /* masked */
107 }
108 }
Aurelien Jarnoefac4152011-02-24 12:31:41 +0100109 env->in_sleep = 0;
thse96e2042007-12-02 06:18:24 +0000110
111 if (do_irq) {
112 irq_vector = sh_intc_get_pending_vector(env->intc_handle,
113 (env->sr >> 4) & 0xf);
114 if (irq_vector == -1) {
115 return; /* masked */
116 }
117 }
118
aliguori8fec2b82009-01-15 22:36:53 +0000119 if (qemu_loglevel_mask(CPU_LOG_INT)) {
bellardfdf9b3e2006-04-27 21:07:38 +0000120 const char *expname;
Andreas Färber27103422013-08-26 08:31:06 +0200121 switch (cs->exception_index) {
bellardfdf9b3e2006-04-27 21:07:38 +0000122 case 0x0e0:
123 expname = "addr_error";
124 break;
125 case 0x040:
126 expname = "tlb_miss";
127 break;
128 case 0x0a0:
129 expname = "tlb_violation";
130 break;
131 case 0x180:
132 expname = "illegal_instruction";
133 break;
134 case 0x1a0:
135 expname = "slot_illegal_instruction";
136 break;
137 case 0x800:
138 expname = "fpu_disable";
139 break;
140 case 0x820:
141 expname = "slot_fpu";
142 break;
143 case 0x100:
144 expname = "data_write";
145 break;
146 case 0x060:
147 expname = "dtlb_miss_write";
148 break;
149 case 0x0c0:
150 expname = "dtlb_violation_write";
151 break;
152 case 0x120:
153 expname = "fpu_exception";
154 break;
155 case 0x080:
156 expname = "initial_page_write";
157 break;
158 case 0x160:
159 expname = "trapa";
160 break;
161 default:
thse96e2042007-12-02 06:18:24 +0000162 expname = do_irq ? "interrupt" : "???";
163 break;
bellardfdf9b3e2006-04-27 21:07:38 +0000164 }
aliguori93fcfe32009-01-15 22:34:14 +0000165 qemu_log("exception 0x%03x [%s] raised\n",
166 irq_vector, expname);
Andreas Färbera0762852013-06-16 07:28:50 +0200167 log_cpu_state(cs, 0);
bellardfdf9b3e2006-04-27 21:07:38 +0000168 }
169
Aurelien Jarno34086942015-05-25 01:28:56 +0200170 env->ssr = cpu_read_sr(env);
thse96e2042007-12-02 06:18:24 +0000171 env->spc = env->pc;
bellardfdf9b3e2006-04-27 21:07:38 +0000172 env->sgr = env->gregs[15];
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200173 env->sr |= (1u << SR_BL) | (1u << SR_MD) | (1u << SR_RB);
Richard Hendersonf85da302017-09-07 11:50:53 -0700174 env->lock_addr = -1;
bellardfdf9b3e2006-04-27 21:07:38 +0000175
Aurelien Jarno9a562ae2017-05-17 00:48:18 +0200176 if (env->flags & DELAY_SLOT_MASK) {
aurel32274a9e72008-08-22 08:57:35 +0000177 /* Branch instruction should be executed again before delay slot. */
178 env->spc -= 2;
179 /* Clear flags for exception/interrupt routine. */
Aurelien Jarno9a562ae2017-05-17 00:48:18 +0200180 env->flags &= ~DELAY_SLOT_MASK;
aurel32274a9e72008-08-22 08:57:35 +0000181 }
aurel32274a9e72008-08-22 08:57:35 +0000182
thse96e2042007-12-02 06:18:24 +0000183 if (do_exp) {
Andreas Färber27103422013-08-26 08:31:06 +0200184 env->expevt = cs->exception_index;
185 switch (cs->exception_index) {
thse96e2042007-12-02 06:18:24 +0000186 case 0x000:
187 case 0x020:
188 case 0x140:
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200189 env->sr &= ~(1u << SR_FD);
thse96e2042007-12-02 06:18:24 +0000190 env->sr |= 0xf << 4; /* IMASK */
191 env->pc = 0xa0000000;
192 break;
193 case 0x040:
194 case 0x060:
195 env->pc = env->vbr + 0x400;
196 break;
197 case 0x160:
198 env->spc += 2; /* special case for TRAPA */
199 /* fall through */
200 default:
201 env->pc = env->vbr + 0x100;
202 break;
203 }
204 return;
205 }
206
207 if (do_irq) {
208 env->intevt = irq_vector;
209 env->pc = env->vbr + 0x600;
210 return;
bellardfdf9b3e2006-04-27 21:07:38 +0000211 }
212}
213
Andreas Färber73e57162012-03-14 01:38:22 +0100214static void update_itlb_use(CPUSH4State * env, int itlbnb)
bellardfdf9b3e2006-04-27 21:07:38 +0000215{
216 uint8_t or_mask = 0, and_mask = (uint8_t) - 1;
217
218 switch (itlbnb) {
219 case 0:
aurel32ea2b5422008-05-09 18:45:55 +0000220 and_mask = 0x1f;
bellardfdf9b3e2006-04-27 21:07:38 +0000221 break;
222 case 1:
223 and_mask = 0xe7;
224 or_mask = 0x80;
225 break;
226 case 2:
227 and_mask = 0xfb;
228 or_mask = 0x50;
229 break;
230 case 3:
231 or_mask = 0x2c;
232 break;
233 }
234
aurel32ea2b5422008-05-09 18:45:55 +0000235 env->mmucr &= (and_mask << 24) | 0x00ffffff;
bellardfdf9b3e2006-04-27 21:07:38 +0000236 env->mmucr |= (or_mask << 24);
237}
238
Andreas Färber73e57162012-03-14 01:38:22 +0100239static int itlb_replacement(CPUSH4State * env)
bellardfdf9b3e2006-04-27 21:07:38 +0000240{
Andreas Färbera47dddd2013-09-03 17:38:47 +0200241 SuperHCPU *cpu = sh_env_get_cpu(env);
242
243 if ((env->mmucr & 0xe0000000) == 0xe0000000) {
bellardfdf9b3e2006-04-27 21:07:38 +0000244 return 0;
Andreas Färbera47dddd2013-09-03 17:38:47 +0200245 }
246 if ((env->mmucr & 0x98000000) == 0x18000000) {
bellardfdf9b3e2006-04-27 21:07:38 +0000247 return 1;
Andreas Färbera47dddd2013-09-03 17:38:47 +0200248 }
249 if ((env->mmucr & 0x54000000) == 0x04000000) {
bellardfdf9b3e2006-04-27 21:07:38 +0000250 return 2;
Andreas Färbera47dddd2013-09-03 17:38:47 +0200251 }
252 if ((env->mmucr & 0x2c000000) == 0x00000000) {
bellardfdf9b3e2006-04-27 21:07:38 +0000253 return 3;
Andreas Färbera47dddd2013-09-03 17:38:47 +0200254 }
255 cpu_abort(CPU(cpu), "Unhandled itlb_replacement");
bellardfdf9b3e2006-04-27 21:07:38 +0000256}
257
258/* Find the corresponding entry in the right TLB
259 Return entry, MMU_DTLB_MISS or MMU_DTLB_MULTIPLE
260*/
Andreas Färber73e57162012-03-14 01:38:22 +0100261static int find_tlb_entry(CPUSH4State * env, target_ulong address,
bellardfdf9b3e2006-04-27 21:07:38 +0000262 tlb_t * entries, uint8_t nbtlb, int use_asid)
263{
264 int match = MMU_DTLB_MISS;
265 uint32_t start, end;
266 uint8_t asid;
267 int i;
268
269 asid = env->pteh & 0xff;
270
271 for (i = 0; i < nbtlb; i++) {
272 if (!entries[i].v)
273 continue; /* Invalid entry */
aurel32eeda6772008-12-10 17:31:51 +0000274 if (!entries[i].sh && use_asid && entries[i].asid != asid)
bellardfdf9b3e2006-04-27 21:07:38 +0000275 continue; /* Bad ASID */
bellardfdf9b3e2006-04-27 21:07:38 +0000276 start = (entries[i].vpn << 10) & ~(entries[i].size - 1);
277 end = start + entries[i].size - 1;
278 if (address >= start && address <= end) { /* Match */
aurel32ea2b5422008-05-09 18:45:55 +0000279 if (match != MMU_DTLB_MISS)
bellardfdf9b3e2006-04-27 21:07:38 +0000280 return MMU_DTLB_MULTIPLE; /* Multiple match */
281 match = i;
282 }
283 }
284 return match;
285}
286
Andreas Färber73e57162012-03-14 01:38:22 +0100287static void increment_urc(CPUSH4State * env)
aurel3229e179b2008-08-22 08:57:43 +0000288{
289 uint8_t urb, urc;
290
291 /* Increment URC */
292 urb = ((env->mmucr) >> 18) & 0x3f;
293 urc = ((env->mmucr) >> 10) & 0x3f;
294 urc++;
aurel32927e3a42009-03-03 09:14:01 +0000295 if ((urb > 0 && urc > urb) || urc > (UTLB_SIZE - 1))
aurel3229e179b2008-08-22 08:57:43 +0000296 urc = 0;
297 env->mmucr = (env->mmucr & 0xffff03ff) | (urc << 10);
298}
299
Aurelien Jarno829a4922011-01-09 23:53:45 +0100300/* Copy and utlb entry into itlb
301 Return entry
302*/
Andreas Färber73e57162012-03-14 01:38:22 +0100303static int copy_utlb_entry_itlb(CPUSH4State *env, int utlb)
Aurelien Jarno829a4922011-01-09 23:53:45 +0100304{
305 int itlb;
306
307 tlb_t * ientry;
308 itlb = itlb_replacement(env);
309 ientry = &env->itlb[itlb];
310 if (ientry->v) {
Andreas Färber31b030d2013-09-04 01:29:02 +0200311 tlb_flush_page(CPU(sh_env_get_cpu(env)), ientry->vpn << 10);
Aurelien Jarno829a4922011-01-09 23:53:45 +0100312 }
313 *ientry = env->utlb[utlb];
314 update_itlb_use(env, itlb);
315 return itlb;
316}
317
318/* Find itlb entry
bellardfdf9b3e2006-04-27 21:07:38 +0000319 Return entry, MMU_ITLB_MISS, MMU_ITLB_MULTIPLE or MMU_DTLB_MULTIPLE
bellardfdf9b3e2006-04-27 21:07:38 +0000320*/
Andreas Färber73e57162012-03-14 01:38:22 +0100321static int find_itlb_entry(CPUSH4State * env, target_ulong address,
Aurelien Jarno829a4922011-01-09 23:53:45 +0100322 int use_asid)
bellardfdf9b3e2006-04-27 21:07:38 +0000323{
Aurelien Jarno829a4922011-01-09 23:53:45 +0100324 int e;
bellardfdf9b3e2006-04-27 21:07:38 +0000325
326 e = find_tlb_entry(env, address, env->itlb, ITLB_SIZE, use_asid);
Aurelien Jarno829a4922011-01-09 23:53:45 +0100327 if (e == MMU_DTLB_MULTIPLE) {
bellardfdf9b3e2006-04-27 21:07:38 +0000328 e = MMU_ITLB_MULTIPLE;
Aurelien Jarno829a4922011-01-09 23:53:45 +0100329 } else if (e == MMU_DTLB_MISS) {
aurel32ea2b5422008-05-09 18:45:55 +0000330 e = MMU_ITLB_MISS;
Aurelien Jarno829a4922011-01-09 23:53:45 +0100331 } else if (e >= 0) {
bellardfdf9b3e2006-04-27 21:07:38 +0000332 update_itlb_use(env, e);
Aurelien Jarno829a4922011-01-09 23:53:45 +0100333 }
bellardfdf9b3e2006-04-27 21:07:38 +0000334 return e;
335}
336
337/* Find utlb entry
338 Return entry, MMU_DTLB_MISS, MMU_DTLB_MULTIPLE */
Andreas Färber73e57162012-03-14 01:38:22 +0100339static int find_utlb_entry(CPUSH4State * env, target_ulong address, int use_asid)
bellardfdf9b3e2006-04-27 21:07:38 +0000340{
aurel3229e179b2008-08-22 08:57:43 +0000341 /* per utlb access */
342 increment_urc(env);
bellardfdf9b3e2006-04-27 21:07:38 +0000343
344 /* Return entry */
345 return find_tlb_entry(env, address, env->utlb, UTLB_SIZE, use_asid);
346}
347
348/* Match address against MMU
349 Return MMU_OK, MMU_DTLB_MISS_READ, MMU_DTLB_MISS_WRITE,
350 MMU_DTLB_INITIAL_WRITE, MMU_DTLB_VIOLATION_READ,
351 MMU_DTLB_VIOLATION_WRITE, MMU_ITLB_MISS,
aurel32cf7055b2008-11-21 22:33:15 +0000352 MMU_ITLB_MULTIPLE, MMU_ITLB_VIOLATION,
353 MMU_IADDR_ERROR, MMU_DADDR_ERROR_READ, MMU_DADDR_ERROR_WRITE.
bellardfdf9b3e2006-04-27 21:07:38 +0000354*/
Andreas Färber73e57162012-03-14 01:38:22 +0100355static int get_mmu_address(CPUSH4State * env, target_ulong * physical,
bellardfdf9b3e2006-04-27 21:07:38 +0000356 int *prot, target_ulong address,
357 int rw, int access_type)
358{
aurel32cf7055b2008-11-21 22:33:15 +0000359 int use_asid, n;
bellardfdf9b3e2006-04-27 21:07:38 +0000360 tlb_t *matching = NULL;
361
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200362 use_asid = !(env->mmucr & MMUCR_SV) || !(env->sr & (1u << SR_MD));
bellardfdf9b3e2006-04-27 21:07:38 +0000363
aurel32cf7055b2008-11-21 22:33:15 +0000364 if (rw == 2) {
Aurelien Jarno829a4922011-01-09 23:53:45 +0100365 n = find_itlb_entry(env, address, use_asid);
bellardfdf9b3e2006-04-27 21:07:38 +0000366 if (n >= 0) {
367 matching = &env->itlb[n];
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200368 if (!(env->sr & (1u << SR_MD)) && !(matching->pr & 2)) {
bellardfdf9b3e2006-04-27 21:07:38 +0000369 n = MMU_ITLB_VIOLATION;
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200370 } else {
Aurelien Jarno5a25cc22010-02-02 22:32:14 +0100371 *prot = PAGE_EXEC;
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200372 }
Aurelien Jarno829a4922011-01-09 23:53:45 +0100373 } else {
374 n = find_utlb_entry(env, address, use_asid);
375 if (n >= 0) {
376 n = copy_utlb_entry_itlb(env, n);
377 matching = &env->itlb[n];
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200378 if (!(env->sr & (1u << SR_MD)) && !(matching->pr & 2)) {
379 n = MMU_ITLB_VIOLATION;
Aurelien Jarno829a4922011-01-09 23:53:45 +0100380 } else {
381 *prot = PAGE_READ | PAGE_EXEC;
382 if ((matching->pr & 1) && matching->d) {
383 *prot |= PAGE_WRITE;
384 }
385 }
386 } else if (n == MMU_DTLB_MULTIPLE) {
387 n = MMU_ITLB_MULTIPLE;
388 } else if (n == MMU_DTLB_MISS) {
389 n = MMU_ITLB_MISS;
390 }
bellardfdf9b3e2006-04-27 21:07:38 +0000391 }
392 } else {
393 n = find_utlb_entry(env, address, use_asid);
394 if (n >= 0) {
395 matching = &env->utlb[n];
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200396 if (!(env->sr & (1u << SR_MD)) && !(matching->pr & 2)) {
Aurelien Jarno628b61a2010-02-02 19:50:51 +0100397 n = (rw == 1) ? MMU_DTLB_VIOLATION_WRITE :
398 MMU_DTLB_VIOLATION_READ;
399 } else if ((rw == 1) && !(matching->pr & 1)) {
400 n = MMU_DTLB_VIOLATION_WRITE;
Aurelien Jarno0c16e712011-01-15 13:50:38 +0100401 } else if ((rw == 1) && !matching->d) {
Aurelien Jarno628b61a2010-02-02 19:50:51 +0100402 n = MMU_DTLB_INITIAL_WRITE;
403 } else {
404 *prot = PAGE_READ;
405 if ((matching->pr & 1) && matching->d) {
406 *prot |= PAGE_WRITE;
407 }
408 }
bellardfdf9b3e2006-04-27 21:07:38 +0000409 } else if (n == MMU_DTLB_MISS) {
aurel32cf7055b2008-11-21 22:33:15 +0000410 n = (rw == 1) ? MMU_DTLB_MISS_WRITE :
bellardfdf9b3e2006-04-27 21:07:38 +0000411 MMU_DTLB_MISS_READ;
412 }
413 }
414 if (n >= 0) {
Aurelien Jarno628b61a2010-02-02 19:50:51 +0100415 n = MMU_OK;
bellardfdf9b3e2006-04-27 21:07:38 +0000416 *physical = ((matching->ppn << 10) & ~(matching->size - 1)) |
417 (address & (matching->size - 1));
bellardfdf9b3e2006-04-27 21:07:38 +0000418 }
419 return n;
420}
421
Andreas Färber73e57162012-03-14 01:38:22 +0100422static int get_physical_address(CPUSH4State * env, target_ulong * physical,
aurel32ef7ec1c2009-03-03 06:12:03 +0000423 int *prot, target_ulong address,
424 int rw, int access_type)
bellardfdf9b3e2006-04-27 21:07:38 +0000425{
426 /* P1, P2 and P4 areas do not use translation */
427 if ((address >= 0x80000000 && address < 0xc0000000) ||
428 address >= 0xe0000000) {
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200429 if (!(env->sr & (1u << SR_MD))
Aurelien Jarno03e3b612010-02-03 18:02:55 +0100430 && (address < 0xe0000000 || address >= 0xe4000000)) {
bellardfdf9b3e2006-04-27 21:07:38 +0000431 /* Unauthorized access in user mode (only store queues are available) */
Aurelien Jarno324189b2017-05-17 00:48:18 +0200432 qemu_log_mask(LOG_GUEST_ERROR, "Unauthorized access\n");
aurel32cf7055b2008-11-21 22:33:15 +0000433 if (rw == 0)
434 return MMU_DADDR_ERROR_READ;
435 else if (rw == 1)
436 return MMU_DADDR_ERROR_WRITE;
437 else
438 return MMU_IADDR_ERROR;
bellardfdf9b3e2006-04-27 21:07:38 +0000439 }
aurel3229e179b2008-08-22 08:57:43 +0000440 if (address >= 0x80000000 && address < 0xc0000000) {
441 /* Mask upper 3 bits for P1 and P2 areas */
442 *physical = address & 0x1fffffff;
aurel3229e179b2008-08-22 08:57:43 +0000443 } else {
aurel3229e179b2008-08-22 08:57:43 +0000444 *physical = address;
445 }
Aurelien Jarno5a25cc22010-02-02 22:32:14 +0100446 *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
bellardfdf9b3e2006-04-27 21:07:38 +0000447 return MMU_OK;
448 }
449
450 /* If MMU is disabled, return the corresponding physical page */
Aurelien Jarno0c16e712011-01-15 13:50:38 +0100451 if (!(env->mmucr & MMUCR_AT)) {
bellardfdf9b3e2006-04-27 21:07:38 +0000452 *physical = address & 0x1FFFFFFF;
Aurelien Jarno5a25cc22010-02-02 22:32:14 +0100453 *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
bellardfdf9b3e2006-04-27 21:07:38 +0000454 return MMU_OK;
455 }
456
457 /* We need to resort to the MMU */
458 return get_mmu_address(env, physical, prot, address, rw, access_type);
459}
460
Laurent Vivier98670d42018-01-18 20:38:40 +0100461int superh_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int size, int rw,
Andreas Färber75104542013-08-26 03:01:33 +0200462 int mmu_idx)
bellardfdf9b3e2006-04-27 21:07:38 +0000463{
Andreas Färber75104542013-08-26 03:01:33 +0200464 SuperHCPU *cpu = SUPERH_CPU(cs);
465 CPUSH4State *env = &cpu->env;
Aurelien Jarno0f3f1ec2010-02-01 20:02:23 +0100466 target_ulong physical;
bellardfdf9b3e2006-04-27 21:07:38 +0000467 int prot, ret, access_type;
468
bellardfdf9b3e2006-04-27 21:07:38 +0000469 access_type = ACCESS_INT;
470 ret =
471 get_physical_address(env, &physical, &prot, address, rw,
472 access_type);
473
474 if (ret != MMU_OK) {
475 env->tea = address;
Alexandre Courbote3f114f2011-01-26 11:57:53 +0900476 if (ret != MMU_DTLB_MULTIPLE && ret != MMU_ITLB_MULTIPLE) {
477 env->pteh = (env->pteh & PTEH_ASID_MASK) |
478 (address & PTEH_VPN_MASK);
479 }
bellardfdf9b3e2006-04-27 21:07:38 +0000480 switch (ret) {
481 case MMU_ITLB_MISS:
482 case MMU_DTLB_MISS_READ:
Andreas Färber27103422013-08-26 08:31:06 +0200483 cs->exception_index = 0x040;
bellardfdf9b3e2006-04-27 21:07:38 +0000484 break;
485 case MMU_DTLB_MULTIPLE:
486 case MMU_ITLB_MULTIPLE:
Andreas Färber27103422013-08-26 08:31:06 +0200487 cs->exception_index = 0x140;
bellardfdf9b3e2006-04-27 21:07:38 +0000488 break;
489 case MMU_ITLB_VIOLATION:
Andreas Färber27103422013-08-26 08:31:06 +0200490 cs->exception_index = 0x0a0;
bellardfdf9b3e2006-04-27 21:07:38 +0000491 break;
492 case MMU_DTLB_MISS_WRITE:
Andreas Färber27103422013-08-26 08:31:06 +0200493 cs->exception_index = 0x060;
bellardfdf9b3e2006-04-27 21:07:38 +0000494 break;
495 case MMU_DTLB_INITIAL_WRITE:
Andreas Färber27103422013-08-26 08:31:06 +0200496 cs->exception_index = 0x080;
bellardfdf9b3e2006-04-27 21:07:38 +0000497 break;
498 case MMU_DTLB_VIOLATION_READ:
Andreas Färber27103422013-08-26 08:31:06 +0200499 cs->exception_index = 0x0a0;
bellardfdf9b3e2006-04-27 21:07:38 +0000500 break;
501 case MMU_DTLB_VIOLATION_WRITE:
Andreas Färber27103422013-08-26 08:31:06 +0200502 cs->exception_index = 0x0c0;
bellardfdf9b3e2006-04-27 21:07:38 +0000503 break;
aurel32cf7055b2008-11-21 22:33:15 +0000504 case MMU_IADDR_ERROR:
505 case MMU_DADDR_ERROR_READ:
Andreas Färber27103422013-08-26 08:31:06 +0200506 cs->exception_index = 0x0e0;
aurel32cf7055b2008-11-21 22:33:15 +0000507 break;
508 case MMU_DADDR_ERROR_WRITE:
Andreas Färber27103422013-08-26 08:31:06 +0200509 cs->exception_index = 0x100;
aurel32cf7055b2008-11-21 22:33:15 +0000510 break;
bellardfdf9b3e2006-04-27 21:07:38 +0000511 default:
Andreas Färbera47dddd2013-09-03 17:38:47 +0200512 cpu_abort(cs, "Unhandled MMU fault");
bellardfdf9b3e2006-04-27 21:07:38 +0000513 }
514 return 1;
515 }
516
Aurelien Jarno0f3f1ec2010-02-01 20:02:23 +0100517 address &= TARGET_PAGE_MASK;
518 physical &= TARGET_PAGE_MASK;
bellardfdf9b3e2006-04-27 21:07:38 +0000519
Andreas Färber0c591eb2013-09-03 13:59:37 +0200520 tlb_set_page(cs, address, physical, prot, mmu_idx, TARGET_PAGE_SIZE);
Paul Brookd4c430a2010-03-17 02:14:28 +0000521 return 0;
bellardfdf9b3e2006-04-27 21:07:38 +0000522}
pbrook355fb232006-06-17 19:58:25 +0000523
Andreas Färber00b941e2013-06-29 18:55:54 +0200524hwaddr superh_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
pbrook355fb232006-06-17 19:58:25 +0000525{
Andreas Färber00b941e2013-06-29 18:55:54 +0200526 SuperHCPU *cpu = SUPERH_CPU(cs);
pbrook355fb232006-06-17 19:58:25 +0000527 target_ulong physical;
528 int prot;
529
Andreas Färber00b941e2013-06-29 18:55:54 +0200530 get_physical_address(&cpu->env, &physical, &prot, addr, 0, 0);
pbrook355fb232006-06-17 19:58:25 +0000531 return physical;
532}
533
aurel32ef7ec1c2009-03-03 06:12:03 +0000534void cpu_load_tlb(CPUSH4State * env)
aurel32ea2b5422008-05-09 18:45:55 +0000535{
Andreas Färbera47dddd2013-09-03 17:38:47 +0200536 SuperHCPU *cpu = sh_env_get_cpu(env);
aurel32ea2b5422008-05-09 18:45:55 +0000537 int n = cpu_mmucr_urc(env->mmucr);
538 tlb_t * entry = &env->utlb[n];
539
aurel3206afe2c2008-08-22 08:57:52 +0000540 if (entry->v) {
541 /* Overwriting valid entry in utlb. */
542 target_ulong address = entry->vpn << 10;
Andreas Färber31b030d2013-09-04 01:29:02 +0200543 tlb_flush_page(CPU(cpu), address);
aurel3206afe2c2008-08-22 08:57:52 +0000544 }
545
aurel32ea2b5422008-05-09 18:45:55 +0000546 /* Take values into cpu status from registers. */
547 entry->asid = (uint8_t)cpu_pteh_asid(env->pteh);
548 entry->vpn = cpu_pteh_vpn(env->pteh);
549 entry->v = (uint8_t)cpu_ptel_v(env->ptel);
550 entry->ppn = cpu_ptel_ppn(env->ptel);
551 entry->sz = (uint8_t)cpu_ptel_sz(env->ptel);
552 switch (entry->sz) {
553 case 0: /* 00 */
554 entry->size = 1024; /* 1K */
555 break;
556 case 1: /* 01 */
557 entry->size = 1024 * 4; /* 4K */
558 break;
559 case 2: /* 10 */
560 entry->size = 1024 * 64; /* 64K */
561 break;
562 case 3: /* 11 */
563 entry->size = 1024 * 1024; /* 1M */
564 break;
565 default:
Andreas Färbera47dddd2013-09-03 17:38:47 +0200566 cpu_abort(CPU(cpu), "Unhandled load_tlb");
aurel32ea2b5422008-05-09 18:45:55 +0000567 break;
568 }
569 entry->sh = (uint8_t)cpu_ptel_sh(env->ptel);
570 entry->c = (uint8_t)cpu_ptel_c(env->ptel);
571 entry->pr = (uint8_t)cpu_ptel_pr(env->ptel);
572 entry->d = (uint8_t)cpu_ptel_d(env->ptel);
573 entry->wt = (uint8_t)cpu_ptel_wt(env->ptel);
574 entry->sa = (uint8_t)cpu_ptea_sa(env->ptea);
575 entry->tc = (uint8_t)cpu_ptea_tc(env->ptea);
576}
577
Aurelien Jarnoe0bcb9c2010-02-02 19:39:11 +0100578 void cpu_sh4_invalidate_tlb(CPUSH4State *s)
579{
580 int i;
581
582 /* UTLB */
583 for (i = 0; i < UTLB_SIZE; i++) {
584 tlb_t * entry = &s->utlb[i];
585 entry->v = 0;
586 }
587 /* ITLB */
Alexandre Courbote40a67b2011-01-25 15:32:01 +0900588 for (i = 0; i < ITLB_SIZE; i++) {
589 tlb_t * entry = &s->itlb[i];
Aurelien Jarnoe0bcb9c2010-02-02 19:39:11 +0100590 entry->v = 0;
591 }
592
Alex Bennéed10eb082016-11-14 14:17:28 +0000593 tlb_flush(CPU(sh_env_get_cpu(s)));
Aurelien Jarnoe0bcb9c2010-02-02 19:39:11 +0100594}
595
Aurelien Jarnobc656a22011-01-26 02:16:39 +0100596uint32_t cpu_sh4_read_mmaped_itlb_addr(CPUSH4State *s,
Avi Kivitya8170e52012-10-23 12:30:10 +0200597 hwaddr addr)
Aurelien Jarnobc656a22011-01-26 02:16:39 +0100598{
599 int index = (addr & 0x00000300) >> 8;
600 tlb_t * entry = &s->itlb[index];
601
602 return (entry->vpn << 10) |
603 (entry->v << 8) |
604 (entry->asid);
605}
606
Avi Kivitya8170e52012-10-23 12:30:10 +0200607void cpu_sh4_write_mmaped_itlb_addr(CPUSH4State *s, hwaddr addr,
Aurelien Jarnoc0f809c2011-01-09 23:53:45 +0100608 uint32_t mem_value)
609{
610 uint32_t vpn = (mem_value & 0xfffffc00) >> 10;
611 uint8_t v = (uint8_t)((mem_value & 0x00000100) >> 8);
612 uint8_t asid = (uint8_t)(mem_value & 0x000000ff);
613
Aurelien Jarno9f973092011-01-26 02:07:50 +0100614 int index = (addr & 0x00000300) >> 8;
Aurelien Jarnoc0f809c2011-01-09 23:53:45 +0100615 tlb_t * entry = &s->itlb[index];
616 if (entry->v) {
617 /* Overwriting valid entry in itlb. */
618 target_ulong address = entry->vpn << 10;
Andreas Färber31b030d2013-09-04 01:29:02 +0200619 tlb_flush_page(CPU(sh_env_get_cpu(s)), address);
Aurelien Jarnoc0f809c2011-01-09 23:53:45 +0100620 }
621 entry->asid = asid;
622 entry->vpn = vpn;
623 entry->v = v;
624}
625
Aurelien Jarnobc656a22011-01-26 02:16:39 +0100626uint32_t cpu_sh4_read_mmaped_itlb_data(CPUSH4State *s,
Avi Kivitya8170e52012-10-23 12:30:10 +0200627 hwaddr addr)
Aurelien Jarnobc656a22011-01-26 02:16:39 +0100628{
629 int array = (addr & 0x00800000) >> 23;
630 int index = (addr & 0x00000300) >> 8;
631 tlb_t * entry = &s->itlb[index];
632
633 if (array == 0) {
634 /* ITLB Data Array 1 */
635 return (entry->ppn << 10) |
636 (entry->v << 8) |
637 (entry->pr << 5) |
638 ((entry->sz & 1) << 6) |
639 ((entry->sz & 2) << 4) |
640 (entry->c << 3) |
641 (entry->sh << 1);
642 } else {
643 /* ITLB Data Array 2 */
644 return (entry->tc << 1) |
645 (entry->sa);
646 }
647}
648
Avi Kivitya8170e52012-10-23 12:30:10 +0200649void cpu_sh4_write_mmaped_itlb_data(CPUSH4State *s, hwaddr addr,
Aurelien Jarno9f973092011-01-26 02:07:50 +0100650 uint32_t mem_value)
651{
652 int array = (addr & 0x00800000) >> 23;
653 int index = (addr & 0x00000300) >> 8;
654 tlb_t * entry = &s->itlb[index];
655
656 if (array == 0) {
657 /* ITLB Data Array 1 */
658 if (entry->v) {
659 /* Overwriting valid entry in utlb. */
660 target_ulong address = entry->vpn << 10;
Andreas Färber31b030d2013-09-04 01:29:02 +0200661 tlb_flush_page(CPU(sh_env_get_cpu(s)), address);
Aurelien Jarno9f973092011-01-26 02:07:50 +0100662 }
663 entry->ppn = (mem_value & 0x1ffffc00) >> 10;
664 entry->v = (mem_value & 0x00000100) >> 8;
665 entry->sz = (mem_value & 0x00000080) >> 6 |
666 (mem_value & 0x00000010) >> 4;
667 entry->pr = (mem_value & 0x00000040) >> 5;
668 entry->c = (mem_value & 0x00000008) >> 3;
669 entry->sh = (mem_value & 0x00000002) >> 1;
670 } else {
671 /* ITLB Data Array 2 */
672 entry->tc = (mem_value & 0x00000008) >> 3;
673 entry->sa = (mem_value & 0x00000007);
674 }
675}
676
Aurelien Jarnobc656a22011-01-26 02:16:39 +0100677uint32_t cpu_sh4_read_mmaped_utlb_addr(CPUSH4State *s,
Avi Kivitya8170e52012-10-23 12:30:10 +0200678 hwaddr addr)
Aurelien Jarnobc656a22011-01-26 02:16:39 +0100679{
680 int index = (addr & 0x00003f00) >> 8;
681 tlb_t * entry = &s->utlb[index];
682
683 increment_urc(s); /* per utlb access */
684
685 return (entry->vpn << 10) |
686 (entry->v << 8) |
687 (entry->asid);
688}
689
Avi Kivitya8170e52012-10-23 12:30:10 +0200690void cpu_sh4_write_mmaped_utlb_addr(CPUSH4State *s, hwaddr addr,
aurel3229e179b2008-08-22 08:57:43 +0000691 uint32_t mem_value)
692{
693 int associate = addr & 0x0000080;
694 uint32_t vpn = (mem_value & 0xfffffc00) >> 10;
695 uint8_t d = (uint8_t)((mem_value & 0x00000200) >> 9);
696 uint8_t v = (uint8_t)((mem_value & 0x00000100) >> 8);
697 uint8_t asid = (uint8_t)(mem_value & 0x000000ff);
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200698 int use_asid = !(s->mmucr & MMUCR_SV) || !(s->sr & (1u << SR_MD));
aurel3229e179b2008-08-22 08:57:43 +0000699
700 if (associate) {
701 int i;
702 tlb_t * utlb_match_entry = NULL;
703 int needs_tlb_flush = 0;
704
705 /* search UTLB */
706 for (i = 0; i < UTLB_SIZE; i++) {
707 tlb_t * entry = &s->utlb[i];
708 if (!entry->v)
709 continue;
710
aurel32eeda6772008-12-10 17:31:51 +0000711 if (entry->vpn == vpn
712 && (!use_asid || entry->asid == asid || entry->sh)) {
aurel3229e179b2008-08-22 08:57:43 +0000713 if (utlb_match_entry) {
Andreas Färber27103422013-08-26 08:31:06 +0200714 CPUState *cs = CPU(sh_env_get_cpu(s));
715
aurel3229e179b2008-08-22 08:57:43 +0000716 /* Multiple TLB Exception */
Andreas Färber27103422013-08-26 08:31:06 +0200717 cs->exception_index = 0x140;
aurel3229e179b2008-08-22 08:57:43 +0000718 s->tea = addr;
719 break;
720 }
721 if (entry->v && !v)
722 needs_tlb_flush = 1;
723 entry->v = v;
724 entry->d = d;
725 utlb_match_entry = entry;
726 }
727 increment_urc(s); /* per utlb access */
728 }
729
730 /* search ITLB */
731 for (i = 0; i < ITLB_SIZE; i++) {
732 tlb_t * entry = &s->itlb[i];
aurel32eeda6772008-12-10 17:31:51 +0000733 if (entry->vpn == vpn
734 && (!use_asid || entry->asid == asid || entry->sh)) {
aurel3229e179b2008-08-22 08:57:43 +0000735 if (entry->v && !v)
736 needs_tlb_flush = 1;
737 if (utlb_match_entry)
738 *entry = *utlb_match_entry;
739 else
740 entry->v = v;
741 break;
742 }
743 }
744
Andreas Färber31b030d2013-09-04 01:29:02 +0200745 if (needs_tlb_flush) {
746 tlb_flush_page(CPU(sh_env_get_cpu(s)), vpn << 10);
747 }
aurel3229e179b2008-08-22 08:57:43 +0000748
749 } else {
750 int index = (addr & 0x00003f00) >> 8;
751 tlb_t * entry = &s->utlb[index];
752 if (entry->v) {
Andreas Färber31b030d2013-09-04 01:29:02 +0200753 CPUState *cs = CPU(sh_env_get_cpu(s));
754
aurel3229e179b2008-08-22 08:57:43 +0000755 /* Overwriting valid entry in utlb. */
756 target_ulong address = entry->vpn << 10;
Andreas Färber31b030d2013-09-04 01:29:02 +0200757 tlb_flush_page(cs, address);
aurel3229e179b2008-08-22 08:57:43 +0000758 }
759 entry->asid = asid;
760 entry->vpn = vpn;
761 entry->d = d;
762 entry->v = v;
763 increment_urc(s);
764 }
765}
766
Aurelien Jarnobc656a22011-01-26 02:16:39 +0100767uint32_t cpu_sh4_read_mmaped_utlb_data(CPUSH4State *s,
Avi Kivitya8170e52012-10-23 12:30:10 +0200768 hwaddr addr)
Aurelien Jarnobc656a22011-01-26 02:16:39 +0100769{
770 int array = (addr & 0x00800000) >> 23;
771 int index = (addr & 0x00003f00) >> 8;
772 tlb_t * entry = &s->utlb[index];
773
774 increment_urc(s); /* per utlb access */
775
776 if (array == 0) {
777 /* ITLB Data Array 1 */
778 return (entry->ppn << 10) |
779 (entry->v << 8) |
780 (entry->pr << 5) |
781 ((entry->sz & 1) << 6) |
782 ((entry->sz & 2) << 4) |
783 (entry->c << 3) |
784 (entry->d << 2) |
785 (entry->sh << 1) |
786 (entry->wt);
787 } else {
788 /* ITLB Data Array 2 */
789 return (entry->tc << 1) |
790 (entry->sa);
791 }
792}
793
Avi Kivitya8170e52012-10-23 12:30:10 +0200794void cpu_sh4_write_mmaped_utlb_data(CPUSH4State *s, hwaddr addr,
Aurelien Jarno9f973092011-01-26 02:07:50 +0100795 uint32_t mem_value)
796{
797 int array = (addr & 0x00800000) >> 23;
798 int index = (addr & 0x00003f00) >> 8;
799 tlb_t * entry = &s->utlb[index];
800
801 increment_urc(s); /* per utlb access */
802
803 if (array == 0) {
804 /* UTLB Data Array 1 */
805 if (entry->v) {
806 /* Overwriting valid entry in utlb. */
807 target_ulong address = entry->vpn << 10;
Andreas Färber31b030d2013-09-04 01:29:02 +0200808 tlb_flush_page(CPU(sh_env_get_cpu(s)), address);
Aurelien Jarno9f973092011-01-26 02:07:50 +0100809 }
810 entry->ppn = (mem_value & 0x1ffffc00) >> 10;
811 entry->v = (mem_value & 0x00000100) >> 8;
812 entry->sz = (mem_value & 0x00000080) >> 6 |
813 (mem_value & 0x00000010) >> 4;
814 entry->pr = (mem_value & 0x00000060) >> 5;
815 entry->c = (mem_value & 0x00000008) >> 3;
816 entry->d = (mem_value & 0x00000004) >> 2;
817 entry->sh = (mem_value & 0x00000002) >> 1;
818 entry->wt = (mem_value & 0x00000001);
819 } else {
820 /* UTLB Data Array 2 */
821 entry->tc = (mem_value & 0x00000008) >> 3;
822 entry->sa = (mem_value & 0x00000007);
823 }
824}
825
edgar_igl852d4812009-04-01 23:10:46 +0000826int cpu_sh4_is_cached(CPUSH4State * env, target_ulong addr)
827{
828 int n;
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200829 int use_asid = !(env->mmucr & MMUCR_SV) || !(env->sr & (1u << SR_MD));
edgar_igl852d4812009-04-01 23:10:46 +0000830
831 /* check area */
Aurelien Jarno5ed9a252015-05-25 01:28:56 +0200832 if (env->sr & (1u << SR_MD)) {
Veres Lajos67cc32e2015-09-08 22:45:14 +0100833 /* For privileged mode, P2 and P4 area is not cacheable. */
edgar_igl852d4812009-04-01 23:10:46 +0000834 if ((0xA0000000 <= addr && addr < 0xC0000000) || 0xE0000000 <= addr)
835 return 0;
836 } else {
Veres Lajos67cc32e2015-09-08 22:45:14 +0100837 /* For user mode, only U0 area is cacheable. */
edgar_igl852d4812009-04-01 23:10:46 +0000838 if (0x80000000 <= addr)
839 return 0;
840 }
841
842 /*
843 * TODO : Evaluate CCR and check if the cache is on or off.
844 * Now CCR is not in CPUSH4State, but in SH7750State.
Dong Xu Wang4abf79a2011-11-22 18:06:21 +0800845 * When you move the ccr into CPUSH4State, the code will be
edgar_igl852d4812009-04-01 23:10:46 +0000846 * as follows.
847 */
848#if 0
849 /* check if operand cache is enabled or not. */
850 if (!(env->ccr & 1))
851 return 0;
852#endif
853
854 /* if MMU is off, no check for TLB. */
855 if (env->mmucr & MMUCR_AT)
856 return 1;
857
858 /* check TLB */
859 n = find_tlb_entry(env, addr, env->itlb, ITLB_SIZE, use_asid);
860 if (n >= 0)
861 return env->itlb[n].c;
862
863 n = find_tlb_entry(env, addr, env->utlb, UTLB_SIZE, use_asid);
864 if (n >= 0)
865 return env->utlb[n].c;
866
867 return 0;
868}
869
pbrook355fb232006-06-17 19:58:25 +0000870#endif
Richard Hendersonf47ede12014-09-13 09:45:23 -0700871
872bool superh_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
873{
874 if (interrupt_request & CPU_INTERRUPT_HARD) {
Aurelien Jarno5c6f3eb2017-05-17 00:48:18 +0200875 SuperHCPU *cpu = SUPERH_CPU(cs);
876 CPUSH4State *env = &cpu->env;
877
878 /* Delay slots are indivisible, ignore interrupts */
879 if (env->flags & DELAY_SLOT_MASK) {
880 return false;
881 } else {
882 superh_cpu_do_interrupt(cs);
883 return true;
884 }
Richard Hendersonf47ede12014-09-13 09:45:23 -0700885 }
886 return false;
887}