2006-04-28 01:07:38 +04:00
|
|
|
/*
|
|
|
|
* SH4 emulation
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2006-04-28 01:07:38 +04:00
|
|
|
* Copyright (c) 2005 Samuel Tardieu
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-07-17 00:47:01 +04:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2006-04-28 01:07:38 +04:00
|
|
|
*/
|
2016-01-26 21:17:20 +03:00
|
|
|
#include "qemu/osdep.h"
|
2006-04-28 01:07:38 +04:00
|
|
|
|
|
|
|
#include "cpu.h"
|
2016-03-15 15:18:37 +03:00
|
|
|
#include "exec/exec-all.h"
|
2016-01-07 16:55:28 +03:00
|
|
|
#include "exec/log.h"
|
2011-11-17 17:23:01 +04:00
|
|
|
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/sh4/sh_intc.h"
|
2011-11-17 17:23:01 +04:00
|
|
|
#endif
|
2006-04-28 01:07:38 +04:00
|
|
|
|
2006-06-17 23:58:25 +04:00
|
|
|
#if defined(CONFIG_USER_ONLY)
|
|
|
|
|
2013-02-02 13:57:51 +04:00
|
|
|
void superh_cpu_do_interrupt(CPUState *cs)
|
2006-06-17 23:58:25 +04:00
|
|
|
{
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = -1;
|
2006-06-17 23:58:25 +04:00
|
|
|
}
|
|
|
|
|
2013-08-26 05:01:33 +04:00
|
|
|
int superh_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
|
|
|
|
int mmu_idx)
|
2006-06-17 23:58:25 +04:00
|
|
|
{
|
2013-08-26 05:01:33 +04:00
|
|
|
SuperHCPU *cpu = SUPERH_CPU(cs);
|
|
|
|
CPUSH4State *env = &cpu->env;
|
|
|
|
|
2006-06-17 23:58:25 +04:00
|
|
|
env->tea = address;
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = -1;
|
2006-06-17 23:58:25 +04:00
|
|
|
switch (rw) {
|
|
|
|
case 0:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x0a0;
|
2006-06-17 23:58:25 +04:00
|
|
|
break;
|
|
|
|
case 1:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x0c0;
|
2006-06-17 23:58:25 +04:00
|
|
|
break;
|
2008-11-22 01:33:15 +03:00
|
|
|
case 2:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x0a0;
|
2008-11-22 01:33:15 +03:00
|
|
|
break;
|
2006-06-17 23:58:25 +04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-04-03 11:29:38 +04:00
|
|
|
int cpu_sh4_is_cached(CPUSH4State * env, target_ulong addr)
|
|
|
|
{
|
2015-09-09 00:45:14 +03:00
|
|
|
/* For user mode, only U0 area is cacheable. */
|
2009-04-03 11:33:24 +04:00
|
|
|
return !(addr & 0x80000000);
|
2009-04-03 11:29:38 +04:00
|
|
|
}
|
|
|
|
|
2006-06-17 23:58:25 +04:00
|
|
|
#else /* !CONFIG_USER_ONLY */
|
|
|
|
|
2006-04-28 01:07:38 +04:00
|
|
|
#define MMU_OK 0
|
|
|
|
#define MMU_ITLB_MISS (-1)
|
|
|
|
#define MMU_ITLB_MULTIPLE (-2)
|
|
|
|
#define MMU_ITLB_VIOLATION (-3)
|
|
|
|
#define MMU_DTLB_MISS_READ (-4)
|
|
|
|
#define MMU_DTLB_MISS_WRITE (-5)
|
|
|
|
#define MMU_DTLB_INITIAL_WRITE (-6)
|
|
|
|
#define MMU_DTLB_VIOLATION_READ (-7)
|
|
|
|
#define MMU_DTLB_VIOLATION_WRITE (-8)
|
|
|
|
#define MMU_DTLB_MULTIPLE (-9)
|
|
|
|
#define MMU_DTLB_MISS (-10)
|
2008-11-22 01:33:15 +03:00
|
|
|
#define MMU_IADDR_ERROR (-11)
|
|
|
|
#define MMU_DADDR_ERROR_READ (-12)
|
|
|
|
#define MMU_DADDR_ERROR_WRITE (-13)
|
2006-04-28 01:07:38 +04:00
|
|
|
|
2013-02-02 13:57:51 +04:00
|
|
|
void superh_cpu_do_interrupt(CPUState *cs)
|
2006-04-28 01:07:38 +04:00
|
|
|
{
|
2013-02-02 13:57:51 +04:00
|
|
|
SuperHCPU *cpu = SUPERH_CPU(cs);
|
|
|
|
CPUSH4State *env = &cpu->env;
|
2013-01-17 21:51:17 +04:00
|
|
|
int do_irq = cs->interrupt_request & CPU_INTERRUPT_HARD;
|
2013-08-26 10:31:06 +04:00
|
|
|
int do_exp, irq_vector = cs->exception_index;
|
2007-12-02 09:18:24 +03:00
|
|
|
|
|
|
|
/* prioritize exceptions over interrupts */
|
|
|
|
|
2013-08-26 10:31:06 +04:00
|
|
|
do_exp = cs->exception_index != -1;
|
|
|
|
do_irq = do_irq && (cs->exception_index == -1);
|
2007-12-02 09:18:24 +03:00
|
|
|
|
2015-05-25 02:28:56 +03:00
|
|
|
if (env->sr & (1u << SR_BL)) {
|
2013-08-26 10:31:06 +04:00
|
|
|
if (do_exp && cs->exception_index != 0x1e0) {
|
|
|
|
cs->exception_index = 0x000; /* masked exception -> reset */
|
2007-12-02 09:18:24 +03:00
|
|
|
}
|
2011-02-24 14:31:41 +03:00
|
|
|
if (do_irq && !env->in_sleep) {
|
2007-12-02 09:18:24 +03:00
|
|
|
return; /* masked */
|
|
|
|
}
|
|
|
|
}
|
2011-02-24 14:31:41 +03:00
|
|
|
env->in_sleep = 0;
|
2007-12-02 09:18:24 +03:00
|
|
|
|
|
|
|
if (do_irq) {
|
|
|
|
irq_vector = sh_intc_get_pending_vector(env->intc_handle,
|
|
|
|
(env->sr >> 4) & 0xf);
|
|
|
|
if (irq_vector == -1) {
|
|
|
|
return; /* masked */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-16 01:36:53 +03:00
|
|
|
if (qemu_loglevel_mask(CPU_LOG_INT)) {
|
2006-04-28 01:07:38 +04:00
|
|
|
const char *expname;
|
2013-08-26 10:31:06 +04:00
|
|
|
switch (cs->exception_index) {
|
2006-04-28 01:07:38 +04:00
|
|
|
case 0x0e0:
|
|
|
|
expname = "addr_error";
|
|
|
|
break;
|
|
|
|
case 0x040:
|
|
|
|
expname = "tlb_miss";
|
|
|
|
break;
|
|
|
|
case 0x0a0:
|
|
|
|
expname = "tlb_violation";
|
|
|
|
break;
|
|
|
|
case 0x180:
|
|
|
|
expname = "illegal_instruction";
|
|
|
|
break;
|
|
|
|
case 0x1a0:
|
|
|
|
expname = "slot_illegal_instruction";
|
|
|
|
break;
|
|
|
|
case 0x800:
|
|
|
|
expname = "fpu_disable";
|
|
|
|
break;
|
|
|
|
case 0x820:
|
|
|
|
expname = "slot_fpu";
|
|
|
|
break;
|
|
|
|
case 0x100:
|
|
|
|
expname = "data_write";
|
|
|
|
break;
|
|
|
|
case 0x060:
|
|
|
|
expname = "dtlb_miss_write";
|
|
|
|
break;
|
|
|
|
case 0x0c0:
|
|
|
|
expname = "dtlb_violation_write";
|
|
|
|
break;
|
|
|
|
case 0x120:
|
|
|
|
expname = "fpu_exception";
|
|
|
|
break;
|
|
|
|
case 0x080:
|
|
|
|
expname = "initial_page_write";
|
|
|
|
break;
|
|
|
|
case 0x160:
|
|
|
|
expname = "trapa";
|
|
|
|
break;
|
|
|
|
default:
|
2007-12-02 09:18:24 +03:00
|
|
|
expname = do_irq ? "interrupt" : "???";
|
|
|
|
break;
|
2006-04-28 01:07:38 +04:00
|
|
|
}
|
2009-01-16 01:34:14 +03:00
|
|
|
qemu_log("exception 0x%03x [%s] raised\n",
|
|
|
|
irq_vector, expname);
|
2013-06-16 09:28:50 +04:00
|
|
|
log_cpu_state(cs, 0);
|
2006-04-28 01:07:38 +04:00
|
|
|
}
|
|
|
|
|
2015-05-25 02:28:56 +03:00
|
|
|
env->ssr = cpu_read_sr(env);
|
2007-12-02 09:18:24 +03:00
|
|
|
env->spc = env->pc;
|
2006-04-28 01:07:38 +04:00
|
|
|
env->sgr = env->gregs[15];
|
2015-05-25 02:28:56 +03:00
|
|
|
env->sr |= (1u << SR_BL) | (1u << SR_MD) | (1u << SR_RB);
|
2006-04-28 01:07:38 +04:00
|
|
|
|
2008-08-22 12:57:35 +04:00
|
|
|
if (env->flags & (DELAY_SLOT | DELAY_SLOT_CONDITIONAL)) {
|
|
|
|
/* Branch instruction should be executed again before delay slot. */
|
|
|
|
env->spc -= 2;
|
|
|
|
/* Clear flags for exception/interrupt routine. */
|
|
|
|
env->flags &= ~(DELAY_SLOT | DELAY_SLOT_CONDITIONAL | DELAY_SLOT_TRUE);
|
|
|
|
}
|
|
|
|
if (env->flags & DELAY_SLOT_CLEARME)
|
|
|
|
env->flags = 0;
|
|
|
|
|
2007-12-02 09:18:24 +03:00
|
|
|
if (do_exp) {
|
2013-08-26 10:31:06 +04:00
|
|
|
env->expevt = cs->exception_index;
|
|
|
|
switch (cs->exception_index) {
|
2007-12-02 09:18:24 +03:00
|
|
|
case 0x000:
|
|
|
|
case 0x020:
|
|
|
|
case 0x140:
|
2015-05-25 02:28:56 +03:00
|
|
|
env->sr &= ~(1u << SR_FD);
|
2007-12-02 09:18:24 +03:00
|
|
|
env->sr |= 0xf << 4; /* IMASK */
|
|
|
|
env->pc = 0xa0000000;
|
|
|
|
break;
|
|
|
|
case 0x040:
|
|
|
|
case 0x060:
|
|
|
|
env->pc = env->vbr + 0x400;
|
|
|
|
break;
|
|
|
|
case 0x160:
|
|
|
|
env->spc += 2; /* special case for TRAPA */
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
env->pc = env->vbr + 0x100;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_irq) {
|
|
|
|
env->intevt = irq_vector;
|
|
|
|
env->pc = env->vbr + 0x600;
|
|
|
|
return;
|
2006-04-28 01:07:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
static void update_itlb_use(CPUSH4State * env, int itlbnb)
|
2006-04-28 01:07:38 +04:00
|
|
|
{
|
|
|
|
uint8_t or_mask = 0, and_mask = (uint8_t) - 1;
|
|
|
|
|
|
|
|
switch (itlbnb) {
|
|
|
|
case 0:
|
2008-05-09 22:45:55 +04:00
|
|
|
and_mask = 0x1f;
|
2006-04-28 01:07:38 +04:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
and_mask = 0xe7;
|
|
|
|
or_mask = 0x80;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
and_mask = 0xfb;
|
|
|
|
or_mask = 0x50;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
or_mask = 0x2c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-09 22:45:55 +04:00
|
|
|
env->mmucr &= (and_mask << 24) | 0x00ffffff;
|
2006-04-28 01:07:38 +04:00
|
|
|
env->mmucr |= (or_mask << 24);
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
static int itlb_replacement(CPUSH4State * env)
|
2006-04-28 01:07:38 +04:00
|
|
|
{
|
2013-09-03 19:38:47 +04:00
|
|
|
SuperHCPU *cpu = sh_env_get_cpu(env);
|
|
|
|
|
|
|
|
if ((env->mmucr & 0xe0000000) == 0xe0000000) {
|
2006-04-28 01:07:38 +04:00
|
|
|
return 0;
|
2013-09-03 19:38:47 +04:00
|
|
|
}
|
|
|
|
if ((env->mmucr & 0x98000000) == 0x18000000) {
|
2006-04-28 01:07:38 +04:00
|
|
|
return 1;
|
2013-09-03 19:38:47 +04:00
|
|
|
}
|
|
|
|
if ((env->mmucr & 0x54000000) == 0x04000000) {
|
2006-04-28 01:07:38 +04:00
|
|
|
return 2;
|
2013-09-03 19:38:47 +04:00
|
|
|
}
|
|
|
|
if ((env->mmucr & 0x2c000000) == 0x00000000) {
|
2006-04-28 01:07:38 +04:00
|
|
|
return 3;
|
2013-09-03 19:38:47 +04:00
|
|
|
}
|
|
|
|
cpu_abort(CPU(cpu), "Unhandled itlb_replacement");
|
2006-04-28 01:07:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the corresponding entry in the right TLB
|
|
|
|
Return entry, MMU_DTLB_MISS or MMU_DTLB_MULTIPLE
|
|
|
|
*/
|
2012-03-14 04:38:22 +04:00
|
|
|
static int find_tlb_entry(CPUSH4State * env, target_ulong address,
|
2006-04-28 01:07:38 +04:00
|
|
|
tlb_t * entries, uint8_t nbtlb, int use_asid)
|
|
|
|
{
|
|
|
|
int match = MMU_DTLB_MISS;
|
|
|
|
uint32_t start, end;
|
|
|
|
uint8_t asid;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
asid = env->pteh & 0xff;
|
|
|
|
|
|
|
|
for (i = 0; i < nbtlb; i++) {
|
|
|
|
if (!entries[i].v)
|
|
|
|
continue; /* Invalid entry */
|
2008-12-10 20:31:51 +03:00
|
|
|
if (!entries[i].sh && use_asid && entries[i].asid != asid)
|
2006-04-28 01:07:38 +04:00
|
|
|
continue; /* Bad ASID */
|
|
|
|
start = (entries[i].vpn << 10) & ~(entries[i].size - 1);
|
|
|
|
end = start + entries[i].size - 1;
|
|
|
|
if (address >= start && address <= end) { /* Match */
|
2008-05-09 22:45:55 +04:00
|
|
|
if (match != MMU_DTLB_MISS)
|
2006-04-28 01:07:38 +04:00
|
|
|
return MMU_DTLB_MULTIPLE; /* Multiple match */
|
|
|
|
match = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
static void increment_urc(CPUSH4State * env)
|
2008-08-22 12:57:43 +04:00
|
|
|
{
|
|
|
|
uint8_t urb, urc;
|
|
|
|
|
|
|
|
/* Increment URC */
|
|
|
|
urb = ((env->mmucr) >> 18) & 0x3f;
|
|
|
|
urc = ((env->mmucr) >> 10) & 0x3f;
|
|
|
|
urc++;
|
2009-03-03 12:14:01 +03:00
|
|
|
if ((urb > 0 && urc > urb) || urc > (UTLB_SIZE - 1))
|
2008-08-22 12:57:43 +04:00
|
|
|
urc = 0;
|
|
|
|
env->mmucr = (env->mmucr & 0xffff03ff) | (urc << 10);
|
|
|
|
}
|
|
|
|
|
2011-01-10 01:53:45 +03:00
|
|
|
/* Copy and utlb entry into itlb
|
|
|
|
Return entry
|
|
|
|
*/
|
2012-03-14 04:38:22 +04:00
|
|
|
static int copy_utlb_entry_itlb(CPUSH4State *env, int utlb)
|
2011-01-10 01:53:45 +03:00
|
|
|
{
|
|
|
|
int itlb;
|
|
|
|
|
|
|
|
tlb_t * ientry;
|
|
|
|
itlb = itlb_replacement(env);
|
|
|
|
ientry = &env->itlb[itlb];
|
|
|
|
if (ientry->v) {
|
2013-09-04 03:29:02 +04:00
|
|
|
tlb_flush_page(CPU(sh_env_get_cpu(env)), ientry->vpn << 10);
|
2011-01-10 01:53:45 +03:00
|
|
|
}
|
|
|
|
*ientry = env->utlb[utlb];
|
|
|
|
update_itlb_use(env, itlb);
|
|
|
|
return itlb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find itlb entry
|
2006-04-28 01:07:38 +04:00
|
|
|
Return entry, MMU_ITLB_MISS, MMU_ITLB_MULTIPLE or MMU_DTLB_MULTIPLE
|
|
|
|
*/
|
2012-03-14 04:38:22 +04:00
|
|
|
static int find_itlb_entry(CPUSH4State * env, target_ulong address,
|
2011-01-10 01:53:45 +03:00
|
|
|
int use_asid)
|
2006-04-28 01:07:38 +04:00
|
|
|
{
|
2011-01-10 01:53:45 +03:00
|
|
|
int e;
|
2006-04-28 01:07:38 +04:00
|
|
|
|
|
|
|
e = find_tlb_entry(env, address, env->itlb, ITLB_SIZE, use_asid);
|
2011-01-10 01:53:45 +03:00
|
|
|
if (e == MMU_DTLB_MULTIPLE) {
|
2006-04-28 01:07:38 +04:00
|
|
|
e = MMU_ITLB_MULTIPLE;
|
2011-01-10 01:53:45 +03:00
|
|
|
} else if (e == MMU_DTLB_MISS) {
|
2008-05-09 22:45:55 +04:00
|
|
|
e = MMU_ITLB_MISS;
|
2011-01-10 01:53:45 +03:00
|
|
|
} else if (e >= 0) {
|
2006-04-28 01:07:38 +04:00
|
|
|
update_itlb_use(env, e);
|
2011-01-10 01:53:45 +03:00
|
|
|
}
|
2006-04-28 01:07:38 +04:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find utlb entry
|
|
|
|
Return entry, MMU_DTLB_MISS, MMU_DTLB_MULTIPLE */
|
2012-03-14 04:38:22 +04:00
|
|
|
static int find_utlb_entry(CPUSH4State * env, target_ulong address, int use_asid)
|
2006-04-28 01:07:38 +04:00
|
|
|
{
|
2008-08-22 12:57:43 +04:00
|
|
|
/* per utlb access */
|
|
|
|
increment_urc(env);
|
2006-04-28 01:07:38 +04:00
|
|
|
|
|
|
|
/* Return entry */
|
|
|
|
return find_tlb_entry(env, address, env->utlb, UTLB_SIZE, use_asid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Match address against MMU
|
|
|
|
Return MMU_OK, MMU_DTLB_MISS_READ, MMU_DTLB_MISS_WRITE,
|
|
|
|
MMU_DTLB_INITIAL_WRITE, MMU_DTLB_VIOLATION_READ,
|
|
|
|
MMU_DTLB_VIOLATION_WRITE, MMU_ITLB_MISS,
|
2008-11-22 01:33:15 +03:00
|
|
|
MMU_ITLB_MULTIPLE, MMU_ITLB_VIOLATION,
|
|
|
|
MMU_IADDR_ERROR, MMU_DADDR_ERROR_READ, MMU_DADDR_ERROR_WRITE.
|
2006-04-28 01:07:38 +04:00
|
|
|
*/
|
2012-03-14 04:38:22 +04:00
|
|
|
static int get_mmu_address(CPUSH4State * env, target_ulong * physical,
|
2006-04-28 01:07:38 +04:00
|
|
|
int *prot, target_ulong address,
|
|
|
|
int rw, int access_type)
|
|
|
|
{
|
2008-11-22 01:33:15 +03:00
|
|
|
int use_asid, n;
|
2006-04-28 01:07:38 +04:00
|
|
|
tlb_t *matching = NULL;
|
|
|
|
|
2015-05-25 02:28:56 +03:00
|
|
|
use_asid = !(env->mmucr & MMUCR_SV) || !(env->sr & (1u << SR_MD));
|
2006-04-28 01:07:38 +04:00
|
|
|
|
2008-11-22 01:33:15 +03:00
|
|
|
if (rw == 2) {
|
2011-01-10 01:53:45 +03:00
|
|
|
n = find_itlb_entry(env, address, use_asid);
|
2006-04-28 01:07:38 +04:00
|
|
|
if (n >= 0) {
|
|
|
|
matching = &env->itlb[n];
|
2015-05-25 02:28:56 +03:00
|
|
|
if (!(env->sr & (1u << SR_MD)) && !(matching->pr & 2)) {
|
2006-04-28 01:07:38 +04:00
|
|
|
n = MMU_ITLB_VIOLATION;
|
2015-05-25 02:28:56 +03:00
|
|
|
} else {
|
2010-02-03 00:32:14 +03:00
|
|
|
*prot = PAGE_EXEC;
|
2015-05-25 02:28:56 +03:00
|
|
|
}
|
2011-01-10 01:53:45 +03:00
|
|
|
} else {
|
|
|
|
n = find_utlb_entry(env, address, use_asid);
|
|
|
|
if (n >= 0) {
|
|
|
|
n = copy_utlb_entry_itlb(env, n);
|
|
|
|
matching = &env->itlb[n];
|
2015-05-25 02:28:56 +03:00
|
|
|
if (!(env->sr & (1u << SR_MD)) && !(matching->pr & 2)) {
|
|
|
|
n = MMU_ITLB_VIOLATION;
|
2011-01-10 01:53:45 +03:00
|
|
|
} else {
|
|
|
|
*prot = PAGE_READ | PAGE_EXEC;
|
|
|
|
if ((matching->pr & 1) && matching->d) {
|
|
|
|
*prot |= PAGE_WRITE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (n == MMU_DTLB_MULTIPLE) {
|
|
|
|
n = MMU_ITLB_MULTIPLE;
|
|
|
|
} else if (n == MMU_DTLB_MISS) {
|
|
|
|
n = MMU_ITLB_MISS;
|
|
|
|
}
|
2006-04-28 01:07:38 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
n = find_utlb_entry(env, address, use_asid);
|
|
|
|
if (n >= 0) {
|
|
|
|
matching = &env->utlb[n];
|
2015-05-25 02:28:56 +03:00
|
|
|
if (!(env->sr & (1u << SR_MD)) && !(matching->pr & 2)) {
|
2010-02-02 21:50:51 +03:00
|
|
|
n = (rw == 1) ? MMU_DTLB_VIOLATION_WRITE :
|
|
|
|
MMU_DTLB_VIOLATION_READ;
|
|
|
|
} else if ((rw == 1) && !(matching->pr & 1)) {
|
|
|
|
n = MMU_DTLB_VIOLATION_WRITE;
|
2011-01-15 15:50:38 +03:00
|
|
|
} else if ((rw == 1) && !matching->d) {
|
2010-02-02 21:50:51 +03:00
|
|
|
n = MMU_DTLB_INITIAL_WRITE;
|
|
|
|
} else {
|
|
|
|
*prot = PAGE_READ;
|
|
|
|
if ((matching->pr & 1) && matching->d) {
|
|
|
|
*prot |= PAGE_WRITE;
|
|
|
|
}
|
|
|
|
}
|
2006-04-28 01:07:38 +04:00
|
|
|
} else if (n == MMU_DTLB_MISS) {
|
2008-11-22 01:33:15 +03:00
|
|
|
n = (rw == 1) ? MMU_DTLB_MISS_WRITE :
|
2006-04-28 01:07:38 +04:00
|
|
|
MMU_DTLB_MISS_READ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (n >= 0) {
|
2010-02-02 21:50:51 +03:00
|
|
|
n = MMU_OK;
|
2006-04-28 01:07:38 +04:00
|
|
|
*physical = ((matching->ppn << 10) & ~(matching->size - 1)) |
|
|
|
|
(address & (matching->size - 1));
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2012-03-14 04:38:22 +04:00
|
|
|
static int get_physical_address(CPUSH4State * env, target_ulong * physical,
|
2009-03-03 09:12:03 +03:00
|
|
|
int *prot, target_ulong address,
|
|
|
|
int rw, int access_type)
|
2006-04-28 01:07:38 +04:00
|
|
|
{
|
|
|
|
/* P1, P2 and P4 areas do not use translation */
|
|
|
|
if ((address >= 0x80000000 && address < 0xc0000000) ||
|
|
|
|
address >= 0xe0000000) {
|
2015-05-25 02:28:56 +03:00
|
|
|
if (!(env->sr & (1u << SR_MD))
|
2010-02-03 20:02:55 +03:00
|
|
|
&& (address < 0xe0000000 || address >= 0xe4000000)) {
|
2006-04-28 01:07:38 +04:00
|
|
|
/* Unauthorized access in user mode (only store queues are available) */
|
|
|
|
fprintf(stderr, "Unauthorized access\n");
|
2008-11-22 01:33:15 +03:00
|
|
|
if (rw == 0)
|
|
|
|
return MMU_DADDR_ERROR_READ;
|
|
|
|
else if (rw == 1)
|
|
|
|
return MMU_DADDR_ERROR_WRITE;
|
|
|
|
else
|
|
|
|
return MMU_IADDR_ERROR;
|
2006-04-28 01:07:38 +04:00
|
|
|
}
|
2008-08-22 12:57:43 +04:00
|
|
|
if (address >= 0x80000000 && address < 0xc0000000) {
|
|
|
|
/* Mask upper 3 bits for P1 and P2 areas */
|
|
|
|
*physical = address & 0x1fffffff;
|
|
|
|
} else {
|
|
|
|
*physical = address;
|
|
|
|
}
|
2010-02-03 00:32:14 +03:00
|
|
|
*prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
2006-04-28 01:07:38 +04:00
|
|
|
return MMU_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If MMU is disabled, return the corresponding physical page */
|
2011-01-15 15:50:38 +03:00
|
|
|
if (!(env->mmucr & MMUCR_AT)) {
|
2006-04-28 01:07:38 +04:00
|
|
|
*physical = address & 0x1FFFFFFF;
|
2010-02-03 00:32:14 +03:00
|
|
|
*prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
2006-04-28 01:07:38 +04:00
|
|
|
return MMU_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We need to resort to the MMU */
|
|
|
|
return get_mmu_address(env, physical, prot, address, rw, access_type);
|
|
|
|
}
|
|
|
|
|
2013-08-26 05:01:33 +04:00
|
|
|
int superh_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
|
|
|
|
int mmu_idx)
|
2006-04-28 01:07:38 +04:00
|
|
|
{
|
2013-08-26 05:01:33 +04:00
|
|
|
SuperHCPU *cpu = SUPERH_CPU(cs);
|
|
|
|
CPUSH4State *env = &cpu->env;
|
2010-02-01 22:02:23 +03:00
|
|
|
target_ulong physical;
|
2006-04-28 01:07:38 +04:00
|
|
|
int prot, ret, access_type;
|
|
|
|
|
|
|
|
access_type = ACCESS_INT;
|
|
|
|
ret =
|
|
|
|
get_physical_address(env, &physical, &prot, address, rw,
|
|
|
|
access_type);
|
|
|
|
|
|
|
|
if (ret != MMU_OK) {
|
|
|
|
env->tea = address;
|
2011-01-26 05:57:53 +03:00
|
|
|
if (ret != MMU_DTLB_MULTIPLE && ret != MMU_ITLB_MULTIPLE) {
|
|
|
|
env->pteh = (env->pteh & PTEH_ASID_MASK) |
|
|
|
|
(address & PTEH_VPN_MASK);
|
|
|
|
}
|
2006-04-28 01:07:38 +04:00
|
|
|
switch (ret) {
|
|
|
|
case MMU_ITLB_MISS:
|
|
|
|
case MMU_DTLB_MISS_READ:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x040;
|
2006-04-28 01:07:38 +04:00
|
|
|
break;
|
|
|
|
case MMU_DTLB_MULTIPLE:
|
|
|
|
case MMU_ITLB_MULTIPLE:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x140;
|
2006-04-28 01:07:38 +04:00
|
|
|
break;
|
|
|
|
case MMU_ITLB_VIOLATION:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x0a0;
|
2006-04-28 01:07:38 +04:00
|
|
|
break;
|
|
|
|
case MMU_DTLB_MISS_WRITE:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x060;
|
2006-04-28 01:07:38 +04:00
|
|
|
break;
|
|
|
|
case MMU_DTLB_INITIAL_WRITE:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x080;
|
2006-04-28 01:07:38 +04:00
|
|
|
break;
|
|
|
|
case MMU_DTLB_VIOLATION_READ:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x0a0;
|
2006-04-28 01:07:38 +04:00
|
|
|
break;
|
|
|
|
case MMU_DTLB_VIOLATION_WRITE:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x0c0;
|
2006-04-28 01:07:38 +04:00
|
|
|
break;
|
2008-11-22 01:33:15 +03:00
|
|
|
case MMU_IADDR_ERROR:
|
|
|
|
case MMU_DADDR_ERROR_READ:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x0e0;
|
2008-11-22 01:33:15 +03:00
|
|
|
break;
|
|
|
|
case MMU_DADDR_ERROR_WRITE:
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x100;
|
2008-11-22 01:33:15 +03:00
|
|
|
break;
|
2006-04-28 01:07:38 +04:00
|
|
|
default:
|
2013-09-03 19:38:47 +04:00
|
|
|
cpu_abort(cs, "Unhandled MMU fault");
|
2006-04-28 01:07:38 +04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-02-01 22:02:23 +03:00
|
|
|
address &= TARGET_PAGE_MASK;
|
|
|
|
physical &= TARGET_PAGE_MASK;
|
2006-04-28 01:07:38 +04:00
|
|
|
|
2013-09-03 15:59:37 +04:00
|
|
|
tlb_set_page(cs, address, physical, prot, mmu_idx, TARGET_PAGE_SIZE);
|
2010-03-17 05:14:28 +03:00
|
|
|
return 0;
|
2006-04-28 01:07:38 +04:00
|
|
|
}
|
2006-06-17 23:58:25 +04:00
|
|
|
|
2013-06-29 20:55:54 +04:00
|
|
|
hwaddr superh_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
|
2006-06-17 23:58:25 +04:00
|
|
|
{
|
2013-06-29 20:55:54 +04:00
|
|
|
SuperHCPU *cpu = SUPERH_CPU(cs);
|
2006-06-17 23:58:25 +04:00
|
|
|
target_ulong physical;
|
|
|
|
int prot;
|
|
|
|
|
2013-06-29 20:55:54 +04:00
|
|
|
get_physical_address(&cpu->env, &physical, &prot, addr, 0, 0);
|
2006-06-17 23:58:25 +04:00
|
|
|
return physical;
|
|
|
|
}
|
|
|
|
|
2009-03-03 09:12:03 +03:00
|
|
|
void cpu_load_tlb(CPUSH4State * env)
|
2008-05-09 22:45:55 +04:00
|
|
|
{
|
2013-09-03 19:38:47 +04:00
|
|
|
SuperHCPU *cpu = sh_env_get_cpu(env);
|
2008-05-09 22:45:55 +04:00
|
|
|
int n = cpu_mmucr_urc(env->mmucr);
|
|
|
|
tlb_t * entry = &env->utlb[n];
|
|
|
|
|
2008-08-22 12:57:52 +04:00
|
|
|
if (entry->v) {
|
|
|
|
/* Overwriting valid entry in utlb. */
|
|
|
|
target_ulong address = entry->vpn << 10;
|
2013-09-04 03:29:02 +04:00
|
|
|
tlb_flush_page(CPU(cpu), address);
|
2008-08-22 12:57:52 +04:00
|
|
|
}
|
|
|
|
|
2008-05-09 22:45:55 +04:00
|
|
|
/* Take values into cpu status from registers. */
|
|
|
|
entry->asid = (uint8_t)cpu_pteh_asid(env->pteh);
|
|
|
|
entry->vpn = cpu_pteh_vpn(env->pteh);
|
|
|
|
entry->v = (uint8_t)cpu_ptel_v(env->ptel);
|
|
|
|
entry->ppn = cpu_ptel_ppn(env->ptel);
|
|
|
|
entry->sz = (uint8_t)cpu_ptel_sz(env->ptel);
|
|
|
|
switch (entry->sz) {
|
|
|
|
case 0: /* 00 */
|
|
|
|
entry->size = 1024; /* 1K */
|
|
|
|
break;
|
|
|
|
case 1: /* 01 */
|
|
|
|
entry->size = 1024 * 4; /* 4K */
|
|
|
|
break;
|
|
|
|
case 2: /* 10 */
|
|
|
|
entry->size = 1024 * 64; /* 64K */
|
|
|
|
break;
|
|
|
|
case 3: /* 11 */
|
|
|
|
entry->size = 1024 * 1024; /* 1M */
|
|
|
|
break;
|
|
|
|
default:
|
2013-09-03 19:38:47 +04:00
|
|
|
cpu_abort(CPU(cpu), "Unhandled load_tlb");
|
2008-05-09 22:45:55 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
entry->sh = (uint8_t)cpu_ptel_sh(env->ptel);
|
|
|
|
entry->c = (uint8_t)cpu_ptel_c(env->ptel);
|
|
|
|
entry->pr = (uint8_t)cpu_ptel_pr(env->ptel);
|
|
|
|
entry->d = (uint8_t)cpu_ptel_d(env->ptel);
|
|
|
|
entry->wt = (uint8_t)cpu_ptel_wt(env->ptel);
|
|
|
|
entry->sa = (uint8_t)cpu_ptea_sa(env->ptea);
|
|
|
|
entry->tc = (uint8_t)cpu_ptea_tc(env->ptea);
|
|
|
|
}
|
|
|
|
|
2010-02-02 21:39:11 +03:00
|
|
|
void cpu_sh4_invalidate_tlb(CPUSH4State *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* UTLB */
|
|
|
|
for (i = 0; i < UTLB_SIZE; i++) {
|
|
|
|
tlb_t * entry = &s->utlb[i];
|
|
|
|
entry->v = 0;
|
|
|
|
}
|
|
|
|
/* ITLB */
|
2011-01-25 09:32:01 +03:00
|
|
|
for (i = 0; i < ITLB_SIZE; i++) {
|
|
|
|
tlb_t * entry = &s->itlb[i];
|
2010-02-02 21:39:11 +03:00
|
|
|
entry->v = 0;
|
|
|
|
}
|
|
|
|
|
2013-09-04 04:19:44 +04:00
|
|
|
tlb_flush(CPU(sh_env_get_cpu(s)), 1);
|
2010-02-02 21:39:11 +03:00
|
|
|
}
|
|
|
|
|
2011-01-26 04:16:39 +03:00
|
|
|
uint32_t cpu_sh4_read_mmaped_itlb_addr(CPUSH4State *s,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr)
|
2011-01-26 04:16:39 +03:00
|
|
|
{
|
|
|
|
int index = (addr & 0x00000300) >> 8;
|
|
|
|
tlb_t * entry = &s->itlb[index];
|
|
|
|
|
|
|
|
return (entry->vpn << 10) |
|
|
|
|
(entry->v << 8) |
|
|
|
|
(entry->asid);
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
void cpu_sh4_write_mmaped_itlb_addr(CPUSH4State *s, hwaddr addr,
|
2011-01-10 01:53:45 +03:00
|
|
|
uint32_t mem_value)
|
|
|
|
{
|
|
|
|
uint32_t vpn = (mem_value & 0xfffffc00) >> 10;
|
|
|
|
uint8_t v = (uint8_t)((mem_value & 0x00000100) >> 8);
|
|
|
|
uint8_t asid = (uint8_t)(mem_value & 0x000000ff);
|
|
|
|
|
2011-01-26 04:07:50 +03:00
|
|
|
int index = (addr & 0x00000300) >> 8;
|
2011-01-10 01:53:45 +03:00
|
|
|
tlb_t * entry = &s->itlb[index];
|
|
|
|
if (entry->v) {
|
|
|
|
/* Overwriting valid entry in itlb. */
|
|
|
|
target_ulong address = entry->vpn << 10;
|
2013-09-04 03:29:02 +04:00
|
|
|
tlb_flush_page(CPU(sh_env_get_cpu(s)), address);
|
2011-01-10 01:53:45 +03:00
|
|
|
}
|
|
|
|
entry->asid = asid;
|
|
|
|
entry->vpn = vpn;
|
|
|
|
entry->v = v;
|
|
|
|
}
|
|
|
|
|
2011-01-26 04:16:39 +03:00
|
|
|
uint32_t cpu_sh4_read_mmaped_itlb_data(CPUSH4State *s,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr)
|
2011-01-26 04:16:39 +03:00
|
|
|
{
|
|
|
|
int array = (addr & 0x00800000) >> 23;
|
|
|
|
int index = (addr & 0x00000300) >> 8;
|
|
|
|
tlb_t * entry = &s->itlb[index];
|
|
|
|
|
|
|
|
if (array == 0) {
|
|
|
|
/* ITLB Data Array 1 */
|
|
|
|
return (entry->ppn << 10) |
|
|
|
|
(entry->v << 8) |
|
|
|
|
(entry->pr << 5) |
|
|
|
|
((entry->sz & 1) << 6) |
|
|
|
|
((entry->sz & 2) << 4) |
|
|
|
|
(entry->c << 3) |
|
|
|
|
(entry->sh << 1);
|
|
|
|
} else {
|
|
|
|
/* ITLB Data Array 2 */
|
|
|
|
return (entry->tc << 1) |
|
|
|
|
(entry->sa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
void cpu_sh4_write_mmaped_itlb_data(CPUSH4State *s, hwaddr addr,
|
2011-01-26 04:07:50 +03:00
|
|
|
uint32_t mem_value)
|
|
|
|
{
|
|
|
|
int array = (addr & 0x00800000) >> 23;
|
|
|
|
int index = (addr & 0x00000300) >> 8;
|
|
|
|
tlb_t * entry = &s->itlb[index];
|
|
|
|
|
|
|
|
if (array == 0) {
|
|
|
|
/* ITLB Data Array 1 */
|
|
|
|
if (entry->v) {
|
|
|
|
/* Overwriting valid entry in utlb. */
|
|
|
|
target_ulong address = entry->vpn << 10;
|
2013-09-04 03:29:02 +04:00
|
|
|
tlb_flush_page(CPU(sh_env_get_cpu(s)), address);
|
2011-01-26 04:07:50 +03:00
|
|
|
}
|
|
|
|
entry->ppn = (mem_value & 0x1ffffc00) >> 10;
|
|
|
|
entry->v = (mem_value & 0x00000100) >> 8;
|
|
|
|
entry->sz = (mem_value & 0x00000080) >> 6 |
|
|
|
|
(mem_value & 0x00000010) >> 4;
|
|
|
|
entry->pr = (mem_value & 0x00000040) >> 5;
|
|
|
|
entry->c = (mem_value & 0x00000008) >> 3;
|
|
|
|
entry->sh = (mem_value & 0x00000002) >> 1;
|
|
|
|
} else {
|
|
|
|
/* ITLB Data Array 2 */
|
|
|
|
entry->tc = (mem_value & 0x00000008) >> 3;
|
|
|
|
entry->sa = (mem_value & 0x00000007);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-26 04:16:39 +03:00
|
|
|
uint32_t cpu_sh4_read_mmaped_utlb_addr(CPUSH4State *s,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr)
|
2011-01-26 04:16:39 +03:00
|
|
|
{
|
|
|
|
int index = (addr & 0x00003f00) >> 8;
|
|
|
|
tlb_t * entry = &s->utlb[index];
|
|
|
|
|
|
|
|
increment_urc(s); /* per utlb access */
|
|
|
|
|
|
|
|
return (entry->vpn << 10) |
|
|
|
|
(entry->v << 8) |
|
|
|
|
(entry->asid);
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
void cpu_sh4_write_mmaped_utlb_addr(CPUSH4State *s, hwaddr addr,
|
2008-08-22 12:57:43 +04:00
|
|
|
uint32_t mem_value)
|
|
|
|
{
|
|
|
|
int associate = addr & 0x0000080;
|
|
|
|
uint32_t vpn = (mem_value & 0xfffffc00) >> 10;
|
|
|
|
uint8_t d = (uint8_t)((mem_value & 0x00000200) >> 9);
|
|
|
|
uint8_t v = (uint8_t)((mem_value & 0x00000100) >> 8);
|
|
|
|
uint8_t asid = (uint8_t)(mem_value & 0x000000ff);
|
2015-05-25 02:28:56 +03:00
|
|
|
int use_asid = !(s->mmucr & MMUCR_SV) || !(s->sr & (1u << SR_MD));
|
2008-08-22 12:57:43 +04:00
|
|
|
|
|
|
|
if (associate) {
|
|
|
|
int i;
|
|
|
|
tlb_t * utlb_match_entry = NULL;
|
|
|
|
int needs_tlb_flush = 0;
|
|
|
|
|
|
|
|
/* search UTLB */
|
|
|
|
for (i = 0; i < UTLB_SIZE; i++) {
|
|
|
|
tlb_t * entry = &s->utlb[i];
|
|
|
|
if (!entry->v)
|
|
|
|
continue;
|
|
|
|
|
2008-12-10 20:31:51 +03:00
|
|
|
if (entry->vpn == vpn
|
|
|
|
&& (!use_asid || entry->asid == asid || entry->sh)) {
|
2008-08-22 12:57:43 +04:00
|
|
|
if (utlb_match_entry) {
|
2013-08-26 10:31:06 +04:00
|
|
|
CPUState *cs = CPU(sh_env_get_cpu(s));
|
|
|
|
|
2008-08-22 12:57:43 +04:00
|
|
|
/* Multiple TLB Exception */
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = 0x140;
|
2008-08-22 12:57:43 +04:00
|
|
|
s->tea = addr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (entry->v && !v)
|
|
|
|
needs_tlb_flush = 1;
|
|
|
|
entry->v = v;
|
|
|
|
entry->d = d;
|
|
|
|
utlb_match_entry = entry;
|
|
|
|
}
|
|
|
|
increment_urc(s); /* per utlb access */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search ITLB */
|
|
|
|
for (i = 0; i < ITLB_SIZE; i++) {
|
|
|
|
tlb_t * entry = &s->itlb[i];
|
2008-12-10 20:31:51 +03:00
|
|
|
if (entry->vpn == vpn
|
|
|
|
&& (!use_asid || entry->asid == asid || entry->sh)) {
|
2008-08-22 12:57:43 +04:00
|
|
|
if (entry->v && !v)
|
|
|
|
needs_tlb_flush = 1;
|
|
|
|
if (utlb_match_entry)
|
|
|
|
*entry = *utlb_match_entry;
|
|
|
|
else
|
|
|
|
entry->v = v;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-04 03:29:02 +04:00
|
|
|
if (needs_tlb_flush) {
|
|
|
|
tlb_flush_page(CPU(sh_env_get_cpu(s)), vpn << 10);
|
|
|
|
}
|
2008-08-22 12:57:43 +04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
int index = (addr & 0x00003f00) >> 8;
|
|
|
|
tlb_t * entry = &s->utlb[index];
|
|
|
|
if (entry->v) {
|
2013-09-04 03:29:02 +04:00
|
|
|
CPUState *cs = CPU(sh_env_get_cpu(s));
|
|
|
|
|
2008-08-22 12:57:43 +04:00
|
|
|
/* Overwriting valid entry in utlb. */
|
|
|
|
target_ulong address = entry->vpn << 10;
|
2013-09-04 03:29:02 +04:00
|
|
|
tlb_flush_page(cs, address);
|
2008-08-22 12:57:43 +04:00
|
|
|
}
|
|
|
|
entry->asid = asid;
|
|
|
|
entry->vpn = vpn;
|
|
|
|
entry->d = d;
|
|
|
|
entry->v = v;
|
|
|
|
increment_urc(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-26 04:16:39 +03:00
|
|
|
uint32_t cpu_sh4_read_mmaped_utlb_data(CPUSH4State *s,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr)
|
2011-01-26 04:16:39 +03:00
|
|
|
{
|
|
|
|
int array = (addr & 0x00800000) >> 23;
|
|
|
|
int index = (addr & 0x00003f00) >> 8;
|
|
|
|
tlb_t * entry = &s->utlb[index];
|
|
|
|
|
|
|
|
increment_urc(s); /* per utlb access */
|
|
|
|
|
|
|
|
if (array == 0) {
|
|
|
|
/* ITLB Data Array 1 */
|
|
|
|
return (entry->ppn << 10) |
|
|
|
|
(entry->v << 8) |
|
|
|
|
(entry->pr << 5) |
|
|
|
|
((entry->sz & 1) << 6) |
|
|
|
|
((entry->sz & 2) << 4) |
|
|
|
|
(entry->c << 3) |
|
|
|
|
(entry->d << 2) |
|
|
|
|
(entry->sh << 1) |
|
|
|
|
(entry->wt);
|
|
|
|
} else {
|
|
|
|
/* ITLB Data Array 2 */
|
|
|
|
return (entry->tc << 1) |
|
|
|
|
(entry->sa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
void cpu_sh4_write_mmaped_utlb_data(CPUSH4State *s, hwaddr addr,
|
2011-01-26 04:07:50 +03:00
|
|
|
uint32_t mem_value)
|
|
|
|
{
|
|
|
|
int array = (addr & 0x00800000) >> 23;
|
|
|
|
int index = (addr & 0x00003f00) >> 8;
|
|
|
|
tlb_t * entry = &s->utlb[index];
|
|
|
|
|
|
|
|
increment_urc(s); /* per utlb access */
|
|
|
|
|
|
|
|
if (array == 0) {
|
|
|
|
/* UTLB Data Array 1 */
|
|
|
|
if (entry->v) {
|
|
|
|
/* Overwriting valid entry in utlb. */
|
|
|
|
target_ulong address = entry->vpn << 10;
|
2013-09-04 03:29:02 +04:00
|
|
|
tlb_flush_page(CPU(sh_env_get_cpu(s)), address);
|
2011-01-26 04:07:50 +03:00
|
|
|
}
|
|
|
|
entry->ppn = (mem_value & 0x1ffffc00) >> 10;
|
|
|
|
entry->v = (mem_value & 0x00000100) >> 8;
|
|
|
|
entry->sz = (mem_value & 0x00000080) >> 6 |
|
|
|
|
(mem_value & 0x00000010) >> 4;
|
|
|
|
entry->pr = (mem_value & 0x00000060) >> 5;
|
|
|
|
entry->c = (mem_value & 0x00000008) >> 3;
|
|
|
|
entry->d = (mem_value & 0x00000004) >> 2;
|
|
|
|
entry->sh = (mem_value & 0x00000002) >> 1;
|
|
|
|
entry->wt = (mem_value & 0x00000001);
|
|
|
|
} else {
|
|
|
|
/* UTLB Data Array 2 */
|
|
|
|
entry->tc = (mem_value & 0x00000008) >> 3;
|
|
|
|
entry->sa = (mem_value & 0x00000007);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-02 03:10:46 +04:00
|
|
|
int cpu_sh4_is_cached(CPUSH4State * env, target_ulong addr)
|
|
|
|
{
|
|
|
|
int n;
|
2015-05-25 02:28:56 +03:00
|
|
|
int use_asid = !(env->mmucr & MMUCR_SV) || !(env->sr & (1u << SR_MD));
|
2009-04-02 03:10:46 +04:00
|
|
|
|
|
|
|
/* check area */
|
2015-05-25 02:28:56 +03:00
|
|
|
if (env->sr & (1u << SR_MD)) {
|
2015-09-09 00:45:14 +03:00
|
|
|
/* For privileged mode, P2 and P4 area is not cacheable. */
|
2009-04-02 03:10:46 +04:00
|
|
|
if ((0xA0000000 <= addr && addr < 0xC0000000) || 0xE0000000 <= addr)
|
|
|
|
return 0;
|
|
|
|
} else {
|
2015-09-09 00:45:14 +03:00
|
|
|
/* For user mode, only U0 area is cacheable. */
|
2009-04-02 03:10:46 +04:00
|
|
|
if (0x80000000 <= addr)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO : Evaluate CCR and check if the cache is on or off.
|
|
|
|
* Now CCR is not in CPUSH4State, but in SH7750State.
|
2011-11-22 14:06:21 +04:00
|
|
|
* When you move the ccr into CPUSH4State, the code will be
|
2009-04-02 03:10:46 +04:00
|
|
|
* as follows.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
/* check if operand cache is enabled or not. */
|
|
|
|
if (!(env->ccr & 1))
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* if MMU is off, no check for TLB. */
|
|
|
|
if (env->mmucr & MMUCR_AT)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* check TLB */
|
|
|
|
n = find_tlb_entry(env, addr, env->itlb, ITLB_SIZE, use_asid);
|
|
|
|
if (n >= 0)
|
|
|
|
return env->itlb[n].c;
|
|
|
|
|
|
|
|
n = find_tlb_entry(env, addr, env->utlb, UTLB_SIZE, use_asid);
|
|
|
|
if (n >= 0)
|
|
|
|
return env->utlb[n].c;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-17 23:58:25 +04:00
|
|
|
#endif
|
2014-09-13 20:45:23 +04:00
|
|
|
|
|
|
|
bool superh_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
|
|
|
|
{
|
|
|
|
if (interrupt_request & CPU_INTERRUPT_HARD) {
|
|
|
|
superh_cpu_do_interrupt(cs);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|