mirror of https://github.com/xemu-project/xemu.git
Rewrite nios2 interrupt handling
-----BEGIN PGP SIGNATURE----- iQFRBAABCgA7FiEEekgeeIaLTbaoWgXAZN846K9+IV8FAmIhHIEdHHJpY2hhcmQu aGVuZGVyc29uQGxpbmFyby5vcmcACgkQZN846K9+IV+ofggAobPrjBUb5JtEwdpv jI1lRi+ZLt3lZKNAFwHVx3/ToONlyr3FMMWKsAyjvNIUNvj3sFRSJyo6PHBGA7sU loZJ47+zLJIeoQVM87tjRszmhbMQIhX/N5QJS7IwXUmZOiv90mJ7Tb5Oa/c1DFbY 2jcyANGVallkENA54Iidz+SW8iVuyCmMua4SZBB96CzLQLbVve4rZA4FNld+Ytoj ZTFdWDTyKDw0SvDpLwhTXkAlVolyi04s4Ap8fFht9u1eo+UVGn5bFVfCQCZphNy9 Jec9fpT1pbGaFLJ1sHWPzUGT8hVfSxzzi+7RDM4PDzpympv7156ItcuyNUkPOr3R c+IOQg== =QRwO -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/rth-gitlab/tags/pull-nios-20220303' into staging Rewrite nios2 interrupt handling # gpg: Signature made Thu 03 Mar 2022 19:52:33 GMT # gpg: using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F # gpg: issuer "richard.henderson@linaro.org" # gpg: Good signature from "Richard Henderson <richard.henderson@linaro.org>" [full] # Primary key fingerprint: 7A48 1E78 868B 4DB6 A85A 05C0 64DF 38E8 AF7E 215F * remotes/rth-gitlab/tags/pull-nios-20220303: target/nios2: Rewrite interrupt handling target/nios2: Special case ipending in rdctl and wrctl target/nios2: Split mmu_write target/nios2: Hoist R_ZERO check in rdctl target/nios2: Only build mmu.c for system mode target/nios2: Replace MMU_LOG with tracepoints target/nios2: Remove mmu_read_debug Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
4c1d764d58
|
@ -2705,6 +2705,7 @@ if have_system or have_user
|
||||||
'target/i386',
|
'target/i386',
|
||||||
'target/i386/kvm',
|
'target/i386/kvm',
|
||||||
'target/mips/tcg',
|
'target/mips/tcg',
|
||||||
|
'target/nios2',
|
||||||
'target/ppc',
|
'target/ppc',
|
||||||
'target/riscv',
|
'target/riscv',
|
||||||
'target/s390x',
|
'target/s390x',
|
||||||
|
|
|
@ -73,12 +73,9 @@ static void nios2_cpu_set_irq(void *opaque, int irq, int level)
|
||||||
|
|
||||||
env->regs[CR_IPENDING] = deposit32(env->regs[CR_IPENDING], irq, 1, !!level);
|
env->regs[CR_IPENDING] = deposit32(env->regs[CR_IPENDING], irq, 1, !!level);
|
||||||
|
|
||||||
env->irq_pending = env->regs[CR_IPENDING] & env->regs[CR_IENABLE];
|
if (env->regs[CR_IPENDING]) {
|
||||||
|
|
||||||
if (env->irq_pending && (env->regs[CR_STATUS] & CR_STATUS_PIE)) {
|
|
||||||
env->irq_pending = 0;
|
|
||||||
cpu_interrupt(cs, CPU_INTERRUPT_HARD);
|
cpu_interrupt(cs, CPU_INTERRUPT_HARD);
|
||||||
} else if (!env->irq_pending) {
|
} else {
|
||||||
cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
|
cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +131,8 @@ static bool nios2_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
|
||||||
CPUNios2State *env = &cpu->env;
|
CPUNios2State *env = &cpu->env;
|
||||||
|
|
||||||
if ((interrupt_request & CPU_INTERRUPT_HARD) &&
|
if ((interrupt_request & CPU_INTERRUPT_HARD) &&
|
||||||
(env->regs[CR_STATUS] & CR_STATUS_PIE)) {
|
(env->regs[CR_STATUS] & CR_STATUS_PIE) &&
|
||||||
|
(env->regs[CR_IPENDING] & env->regs[CR_IENABLE])) {
|
||||||
cs->exception_index = EXCP_IRQ;
|
cs->exception_index = EXCP_IRQ;
|
||||||
nios2_cpu_do_interrupt(cs);
|
nios2_cpu_do_interrupt(cs);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -160,7 +160,6 @@ struct CPUNios2State {
|
||||||
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
#if !defined(CONFIG_USER_ONLY)
|
||||||
Nios2MMU mmu;
|
Nios2MMU mmu;
|
||||||
uint32_t irq_pending;
|
|
||||||
#endif
|
#endif
|
||||||
int error_code;
|
int error_code;
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, i32)
|
DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, i32)
|
||||||
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
#if !defined(CONFIG_USER_ONLY)
|
||||||
DEF_HELPER_2(mmu_read_debug, void, env, i32)
|
DEF_HELPER_2(mmu_write_tlbacc, void, env, i32)
|
||||||
DEF_HELPER_3(mmu_write, void, env, i32, i32)
|
DEF_HELPER_2(mmu_write_tlbmisc, void, env, i32)
|
||||||
DEF_HELPER_1(check_interrupts, void, env)
|
DEF_HELPER_2(mmu_write_pteaddr, void, env, i32)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,14 +2,13 @@ nios2_ss = ss.source_set()
|
||||||
nios2_ss.add(files(
|
nios2_ss.add(files(
|
||||||
'cpu.c',
|
'cpu.c',
|
||||||
'helper.c',
|
'helper.c',
|
||||||
'mmu.c',
|
|
||||||
'nios2-semi.c',
|
'nios2-semi.c',
|
||||||
'op_helper.c',
|
'op_helper.c',
|
||||||
'translate.c',
|
'translate.c',
|
||||||
))
|
))
|
||||||
|
|
||||||
nios2_softmmu_ss = ss.source_set()
|
nios2_softmmu_ss = ss.source_set()
|
||||||
nios2_softmmu_ss.add(files('monitor.c'))
|
nios2_softmmu_ss.add(files('monitor.c', 'mmu.c'))
|
||||||
|
|
||||||
target_arch += {'nios2': nios2_ss}
|
target_arch += {'nios2': nios2_ss}
|
||||||
target_softmmu_arch += {'nios2': nios2_softmmu_ss}
|
target_softmmu_arch += {'nios2': nios2_softmmu_ss}
|
||||||
|
|
|
@ -23,37 +23,9 @@
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "exec/exec-all.h"
|
#include "exec/exec-all.h"
|
||||||
#include "mmu.h"
|
#include "mmu.h"
|
||||||
|
#include "exec/helper-proto.h"
|
||||||
|
#include "trace/trace-target_nios2.h"
|
||||||
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
|
||||||
|
|
||||||
/* Define this to enable MMU debug messages */
|
|
||||||
/* #define DEBUG_MMU */
|
|
||||||
|
|
||||||
#ifdef DEBUG_MMU
|
|
||||||
#define MMU_LOG(x) x
|
|
||||||
#else
|
|
||||||
#define MMU_LOG(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void mmu_read_debug(CPUNios2State *env, uint32_t rn)
|
|
||||||
{
|
|
||||||
switch (rn) {
|
|
||||||
case CR_TLBACC:
|
|
||||||
MMU_LOG(qemu_log("TLBACC READ %08X\n", env->regs[rn]));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CR_TLBMISC:
|
|
||||||
MMU_LOG(qemu_log("TLBMISC READ %08X\n", env->regs[rn]));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CR_PTEADDR:
|
|
||||||
MMU_LOG(qemu_log("PTEADDR READ %08X\n", env->regs[rn]));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* rw - 0 = read, 1 = write, 2 = fetch. */
|
/* rw - 0 = read, 1 = write, 2 = fetch. */
|
||||||
unsigned int mmu_translate(CPUNios2State *env,
|
unsigned int mmu_translate(CPUNios2State *env,
|
||||||
|
@ -63,37 +35,26 @@ unsigned int mmu_translate(CPUNios2State *env,
|
||||||
Nios2CPU *cpu = env_archcpu(env);
|
Nios2CPU *cpu = env_archcpu(env);
|
||||||
int pid = (env->mmu.tlbmisc_wr & CR_TLBMISC_PID_MASK) >> 4;
|
int pid = (env->mmu.tlbmisc_wr & CR_TLBMISC_PID_MASK) >> 4;
|
||||||
int vpn = vaddr >> 12;
|
int vpn = vaddr >> 12;
|
||||||
|
int way, n_ways = cpu->tlb_num_ways;
|
||||||
|
|
||||||
MMU_LOG(qemu_log("mmu_translate vaddr %08X, pid %08X, vpn %08X\n",
|
for (way = 0; way < n_ways; way++) {
|
||||||
vaddr, pid, vpn));
|
uint32_t index = (way * n_ways) + (vpn & env->mmu.tlb_entry_mask);
|
||||||
|
Nios2TLBEntry *entry = &env->mmu.tlb[index];
|
||||||
int way;
|
|
||||||
for (way = 0; way < cpu->tlb_num_ways; way++) {
|
|
||||||
|
|
||||||
Nios2TLBEntry *entry =
|
|
||||||
&env->mmu.tlb[(way * cpu->tlb_num_ways) +
|
|
||||||
(vpn & env->mmu.tlb_entry_mask)];
|
|
||||||
|
|
||||||
MMU_LOG(qemu_log("TLB[%d] TAG %08X, VPN %08X\n",
|
|
||||||
(way * cpu->tlb_num_ways) +
|
|
||||||
(vpn & env->mmu.tlb_entry_mask),
|
|
||||||
entry->tag, (entry->tag >> 12)));
|
|
||||||
|
|
||||||
if (((entry->tag >> 12) != vpn) ||
|
if (((entry->tag >> 12) != vpn) ||
|
||||||
(((entry->tag & (1 << 11)) == 0) &&
|
(((entry->tag & (1 << 11)) == 0) &&
|
||||||
((entry->tag & ((1 << cpu->pid_num_bits) - 1)) != pid))) {
|
((entry->tag & ((1 << cpu->pid_num_bits) - 1)) != pid))) {
|
||||||
|
trace_nios2_mmu_translate_miss(vaddr, pid, index, entry->tag);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
lu->vaddr = vaddr & TARGET_PAGE_MASK;
|
lu->vaddr = vaddr & TARGET_PAGE_MASK;
|
||||||
lu->paddr = (entry->data & CR_TLBACC_PFN_MASK) << TARGET_PAGE_BITS;
|
lu->paddr = (entry->data & CR_TLBACC_PFN_MASK) << TARGET_PAGE_BITS;
|
||||||
lu->prot = ((entry->data & CR_TLBACC_R) ? PAGE_READ : 0) |
|
lu->prot = ((entry->data & CR_TLBACC_R) ? PAGE_READ : 0) |
|
||||||
((entry->data & CR_TLBACC_W) ? PAGE_WRITE : 0) |
|
((entry->data & CR_TLBACC_W) ? PAGE_WRITE : 0) |
|
||||||
((entry->data & CR_TLBACC_X) ? PAGE_EXEC : 0);
|
((entry->data & CR_TLBACC_X) ? PAGE_EXEC : 0);
|
||||||
|
|
||||||
MMU_LOG(qemu_log("HIT TLB[%d] %08X %08X %08X\n",
|
trace_nios2_mmu_translate_hit(vaddr, pid, index, lu->paddr, lu->prot);
|
||||||
(way * cpu->tlb_num_ways) +
|
|
||||||
(vpn & env->mmu.tlb_entry_mask),
|
|
||||||
lu->vaddr, lu->paddr, lu->prot));
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -104,141 +65,119 @@ static void mmu_flush_pid(CPUNios2State *env, uint32_t pid)
|
||||||
CPUState *cs = env_cpu(env);
|
CPUState *cs = env_cpu(env);
|
||||||
Nios2CPU *cpu = env_archcpu(env);
|
Nios2CPU *cpu = env_archcpu(env);
|
||||||
int idx;
|
int idx;
|
||||||
MMU_LOG(qemu_log("TLB Flush PID %d\n", pid));
|
|
||||||
|
|
||||||
for (idx = 0; idx < cpu->tlb_num_entries; idx++) {
|
for (idx = 0; idx < cpu->tlb_num_entries; idx++) {
|
||||||
Nios2TLBEntry *entry = &env->mmu.tlb[idx];
|
Nios2TLBEntry *entry = &env->mmu.tlb[idx];
|
||||||
|
|
||||||
MMU_LOG(qemu_log("TLB[%d] => %08X %08X\n",
|
|
||||||
idx, entry->tag, entry->data));
|
|
||||||
|
|
||||||
if ((entry->tag & (1 << 10)) && (!(entry->tag & (1 << 11))) &&
|
if ((entry->tag & (1 << 10)) && (!(entry->tag & (1 << 11))) &&
|
||||||
((entry->tag & ((1 << cpu->pid_num_bits) - 1)) == pid)) {
|
((entry->tag & ((1 << cpu->pid_num_bits) - 1)) == pid)) {
|
||||||
uint32_t vaddr = entry->tag & TARGET_PAGE_MASK;
|
uint32_t vaddr = entry->tag & TARGET_PAGE_MASK;
|
||||||
|
|
||||||
MMU_LOG(qemu_log("TLB Flush Page %08X\n", vaddr));
|
trace_nios2_mmu_flush_pid_hit(pid, idx, vaddr);
|
||||||
|
|
||||||
tlb_flush_page(cs, vaddr);
|
tlb_flush_page(cs, vaddr);
|
||||||
|
} else {
|
||||||
|
trace_nios2_mmu_flush_pid_miss(pid, idx, entry->tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mmu_write(CPUNios2State *env, uint32_t rn, uint32_t v)
|
void helper_mmu_write_tlbacc(CPUNios2State *env, uint32_t v)
|
||||||
{
|
{
|
||||||
CPUState *cs = env_cpu(env);
|
CPUState *cs = env_cpu(env);
|
||||||
Nios2CPU *cpu = env_archcpu(env);
|
Nios2CPU *cpu = env_archcpu(env);
|
||||||
|
|
||||||
MMU_LOG(qemu_log("mmu_write %08X = %08X\n", rn, v));
|
trace_nios2_mmu_write_tlbacc(v >> CR_TLBACC_IGN_SHIFT,
|
||||||
|
(v & CR_TLBACC_C) ? 'C' : '.',
|
||||||
|
(v & CR_TLBACC_R) ? 'R' : '.',
|
||||||
|
(v & CR_TLBACC_W) ? 'W' : '.',
|
||||||
|
(v & CR_TLBACC_X) ? 'X' : '.',
|
||||||
|
(v & CR_TLBACC_G) ? 'G' : '.',
|
||||||
|
v & CR_TLBACC_PFN_MASK);
|
||||||
|
|
||||||
switch (rn) {
|
/* if tlbmisc.WE == 1 then trigger a TLB write on writes to TLBACC */
|
||||||
case CR_TLBACC:
|
if (env->regs[CR_TLBMISC] & CR_TLBMISC_WR) {
|
||||||
MMU_LOG(qemu_log("TLBACC: IG %02X, FLAGS %c%c%c%c%c, PFN %05X\n",
|
int way = (env->regs[CR_TLBMISC] >> CR_TLBMISC_WAY_SHIFT);
|
||||||
v >> CR_TLBACC_IGN_SHIFT,
|
int vpn = (env->mmu.pteaddr_wr & CR_PTEADDR_VPN_MASK) >> 2;
|
||||||
(v & CR_TLBACC_C) ? 'C' : '.',
|
int pid = (env->mmu.tlbmisc_wr & CR_TLBMISC_PID_MASK) >> 4;
|
||||||
(v & CR_TLBACC_R) ? 'R' : '.',
|
int g = (v & CR_TLBACC_G) ? 1 : 0;
|
||||||
(v & CR_TLBACC_W) ? 'W' : '.',
|
int valid = ((vpn & CR_TLBACC_PFN_MASK) < 0xC0000) ? 1 : 0;
|
||||||
(v & CR_TLBACC_X) ? 'X' : '.',
|
Nios2TLBEntry *entry =
|
||||||
(v & CR_TLBACC_G) ? 'G' : '.',
|
&env->mmu.tlb[(way * cpu->tlb_num_ways) +
|
||||||
v & CR_TLBACC_PFN_MASK));
|
(vpn & env->mmu.tlb_entry_mask)];
|
||||||
|
uint32_t newTag = (vpn << 12) | (g << 11) | (valid << 10) | pid;
|
||||||
|
uint32_t newData = v & (CR_TLBACC_C | CR_TLBACC_R | CR_TLBACC_W |
|
||||||
|
CR_TLBACC_X | CR_TLBACC_PFN_MASK);
|
||||||
|
|
||||||
/* if tlbmisc.WE == 1 then trigger a TLB write on writes to TLBACC */
|
if ((entry->tag != newTag) || (entry->data != newData)) {
|
||||||
if (env->regs[CR_TLBMISC] & CR_TLBMISC_WR) {
|
if (entry->tag & (1 << 10)) {
|
||||||
int way = (env->regs[CR_TLBMISC] >> CR_TLBMISC_WAY_SHIFT);
|
/* Flush existing entry */
|
||||||
int vpn = (env->mmu.pteaddr_wr & CR_PTEADDR_VPN_MASK) >> 2;
|
tlb_flush_page(cs, entry->tag & TARGET_PAGE_MASK);
|
||||||
int pid = (env->mmu.tlbmisc_wr & CR_TLBMISC_PID_MASK) >> 4;
|
|
||||||
int g = (v & CR_TLBACC_G) ? 1 : 0;
|
|
||||||
int valid = ((vpn & CR_TLBACC_PFN_MASK) < 0xC0000) ? 1 : 0;
|
|
||||||
Nios2TLBEntry *entry =
|
|
||||||
&env->mmu.tlb[(way * cpu->tlb_num_ways) +
|
|
||||||
(vpn & env->mmu.tlb_entry_mask)];
|
|
||||||
uint32_t newTag = (vpn << 12) | (g << 11) | (valid << 10) | pid;
|
|
||||||
uint32_t newData = v & (CR_TLBACC_C | CR_TLBACC_R | CR_TLBACC_W |
|
|
||||||
CR_TLBACC_X | CR_TLBACC_PFN_MASK);
|
|
||||||
|
|
||||||
if ((entry->tag != newTag) || (entry->data != newData)) {
|
|
||||||
if (entry->tag & (1 << 10)) {
|
|
||||||
/* Flush existing entry */
|
|
||||||
MMU_LOG(qemu_log("TLB Flush Page (OLD) %08X\n",
|
|
||||||
entry->tag & TARGET_PAGE_MASK));
|
|
||||||
tlb_flush_page(cs, entry->tag & TARGET_PAGE_MASK);
|
|
||||||
}
|
|
||||||
entry->tag = newTag;
|
|
||||||
entry->data = newData;
|
|
||||||
MMU_LOG(qemu_log("TLB[%d] = %08X %08X\n",
|
|
||||||
(way * cpu->tlb_num_ways) +
|
|
||||||
(vpn & env->mmu.tlb_entry_mask),
|
|
||||||
entry->tag, entry->data));
|
|
||||||
}
|
}
|
||||||
/* Auto-increment tlbmisc.WAY */
|
entry->tag = newTag;
|
||||||
env->regs[CR_TLBMISC] =
|
entry->data = newData;
|
||||||
(env->regs[CR_TLBMISC] & ~CR_TLBMISC_WAY_MASK) |
|
|
||||||
(((way + 1) & (cpu->tlb_num_ways - 1)) <<
|
|
||||||
CR_TLBMISC_WAY_SHIFT);
|
|
||||||
}
|
}
|
||||||
|
/* Auto-increment tlbmisc.WAY */
|
||||||
/* Writes to TLBACC don't change the read-back value */
|
env->regs[CR_TLBMISC] =
|
||||||
env->mmu.tlbacc_wr = v;
|
(env->regs[CR_TLBMISC] & ~CR_TLBMISC_WAY_MASK) |
|
||||||
break;
|
(((way + 1) & (cpu->tlb_num_ways - 1)) <<
|
||||||
|
CR_TLBMISC_WAY_SHIFT);
|
||||||
case CR_TLBMISC:
|
|
||||||
MMU_LOG(qemu_log("TLBMISC: WAY %X, FLAGS %c%c%c%c%c%c, PID %04X\n",
|
|
||||||
v >> CR_TLBMISC_WAY_SHIFT,
|
|
||||||
(v & CR_TLBMISC_RD) ? 'R' : '.',
|
|
||||||
(v & CR_TLBMISC_WR) ? 'W' : '.',
|
|
||||||
(v & CR_TLBMISC_DBL) ? '2' : '.',
|
|
||||||
(v & CR_TLBMISC_BAD) ? 'B' : '.',
|
|
||||||
(v & CR_TLBMISC_PERM) ? 'P' : '.',
|
|
||||||
(v & CR_TLBMISC_D) ? 'D' : '.',
|
|
||||||
(v & CR_TLBMISC_PID_MASK) >> 4));
|
|
||||||
|
|
||||||
if ((v & CR_TLBMISC_PID_MASK) !=
|
|
||||||
(env->mmu.tlbmisc_wr & CR_TLBMISC_PID_MASK)) {
|
|
||||||
mmu_flush_pid(env, (env->mmu.tlbmisc_wr & CR_TLBMISC_PID_MASK) >>
|
|
||||||
CR_TLBMISC_PID_SHIFT);
|
|
||||||
}
|
|
||||||
/* if tlbmisc.RD == 1 then trigger a TLB read on writes to TLBMISC */
|
|
||||||
if (v & CR_TLBMISC_RD) {
|
|
||||||
int way = (v >> CR_TLBMISC_WAY_SHIFT);
|
|
||||||
int vpn = (env->mmu.pteaddr_wr & CR_PTEADDR_VPN_MASK) >> 2;
|
|
||||||
Nios2TLBEntry *entry =
|
|
||||||
&env->mmu.tlb[(way * cpu->tlb_num_ways) +
|
|
||||||
(vpn & env->mmu.tlb_entry_mask)];
|
|
||||||
|
|
||||||
env->regs[CR_TLBACC] &= CR_TLBACC_IGN_MASK;
|
|
||||||
env->regs[CR_TLBACC] |= entry->data;
|
|
||||||
env->regs[CR_TLBACC] |= (entry->tag & (1 << 11)) ? CR_TLBACC_G : 0;
|
|
||||||
env->regs[CR_TLBMISC] =
|
|
||||||
(v & ~CR_TLBMISC_PID_MASK) |
|
|
||||||
((entry->tag & ((1 << cpu->pid_num_bits) - 1)) <<
|
|
||||||
CR_TLBMISC_PID_SHIFT);
|
|
||||||
env->regs[CR_PTEADDR] &= ~CR_PTEADDR_VPN_MASK;
|
|
||||||
env->regs[CR_PTEADDR] |= (entry->tag >> 12) << CR_PTEADDR_VPN_SHIFT;
|
|
||||||
MMU_LOG(qemu_log("TLB READ way %d, vpn %05X, tag %08X, data %08X, "
|
|
||||||
"tlbacc %08X, tlbmisc %08X, pteaddr %08X\n",
|
|
||||||
way, vpn, entry->tag, entry->data,
|
|
||||||
env->regs[CR_TLBACC], env->regs[CR_TLBMISC],
|
|
||||||
env->regs[CR_PTEADDR]));
|
|
||||||
} else {
|
|
||||||
env->regs[CR_TLBMISC] = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
env->mmu.tlbmisc_wr = v;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CR_PTEADDR:
|
|
||||||
MMU_LOG(qemu_log("PTEADDR: PTBASE %03X, VPN %05X\n",
|
|
||||||
v >> CR_PTEADDR_PTBASE_SHIFT,
|
|
||||||
(v & CR_PTEADDR_VPN_MASK) >> CR_PTEADDR_VPN_SHIFT));
|
|
||||||
|
|
||||||
/* Writes to PTEADDR don't change the read-back VPN value */
|
|
||||||
env->regs[CR_PTEADDR] = (v & ~CR_PTEADDR_VPN_MASK) |
|
|
||||||
(env->regs[CR_PTEADDR] & CR_PTEADDR_VPN_MASK);
|
|
||||||
env->mmu.pteaddr_wr = v;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Writes to TLBACC don't change the read-back value */
|
||||||
|
env->mmu.tlbacc_wr = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
void helper_mmu_write_tlbmisc(CPUNios2State *env, uint32_t v)
|
||||||
|
{
|
||||||
|
Nios2CPU *cpu = env_archcpu(env);
|
||||||
|
|
||||||
|
trace_nios2_mmu_write_tlbmisc(v >> CR_TLBMISC_WAY_SHIFT,
|
||||||
|
(v & CR_TLBMISC_RD) ? 'R' : '.',
|
||||||
|
(v & CR_TLBMISC_WR) ? 'W' : '.',
|
||||||
|
(v & CR_TLBMISC_DBL) ? '2' : '.',
|
||||||
|
(v & CR_TLBMISC_BAD) ? 'B' : '.',
|
||||||
|
(v & CR_TLBMISC_PERM) ? 'P' : '.',
|
||||||
|
(v & CR_TLBMISC_D) ? 'D' : '.',
|
||||||
|
(v & CR_TLBMISC_PID_MASK) >> 4);
|
||||||
|
|
||||||
|
if ((v & CR_TLBMISC_PID_MASK) !=
|
||||||
|
(env->mmu.tlbmisc_wr & CR_TLBMISC_PID_MASK)) {
|
||||||
|
mmu_flush_pid(env, (env->mmu.tlbmisc_wr & CR_TLBMISC_PID_MASK) >>
|
||||||
|
CR_TLBMISC_PID_SHIFT);
|
||||||
|
}
|
||||||
|
/* if tlbmisc.RD == 1 then trigger a TLB read on writes to TLBMISC */
|
||||||
|
if (v & CR_TLBMISC_RD) {
|
||||||
|
int way = (v >> CR_TLBMISC_WAY_SHIFT);
|
||||||
|
int vpn = (env->mmu.pteaddr_wr & CR_PTEADDR_VPN_MASK) >> 2;
|
||||||
|
Nios2TLBEntry *entry =
|
||||||
|
&env->mmu.tlb[(way * cpu->tlb_num_ways) +
|
||||||
|
(vpn & env->mmu.tlb_entry_mask)];
|
||||||
|
|
||||||
|
env->regs[CR_TLBACC] &= CR_TLBACC_IGN_MASK;
|
||||||
|
env->regs[CR_TLBACC] |= entry->data;
|
||||||
|
env->regs[CR_TLBACC] |= (entry->tag & (1 << 11)) ? CR_TLBACC_G : 0;
|
||||||
|
env->regs[CR_TLBMISC] =
|
||||||
|
(v & ~CR_TLBMISC_PID_MASK) |
|
||||||
|
((entry->tag & ((1 << cpu->pid_num_bits) - 1)) <<
|
||||||
|
CR_TLBMISC_PID_SHIFT);
|
||||||
|
env->regs[CR_PTEADDR] &= ~CR_PTEADDR_VPN_MASK;
|
||||||
|
env->regs[CR_PTEADDR] |= (entry->tag >> 12) << CR_PTEADDR_VPN_SHIFT;
|
||||||
|
} else {
|
||||||
|
env->regs[CR_TLBMISC] = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
env->mmu.tlbmisc_wr = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
void helper_mmu_write_pteaddr(CPUNios2State *env, uint32_t v)
|
||||||
|
{
|
||||||
|
trace_nios2_mmu_write_pteaddr(v >> CR_PTEADDR_PTBASE_SHIFT,
|
||||||
|
(v & CR_PTEADDR_VPN_MASK) >> CR_PTEADDR_VPN_SHIFT);
|
||||||
|
|
||||||
|
/* Writes to PTEADDR don't change the read-back VPN value */
|
||||||
|
env->regs[CR_PTEADDR] = (v & ~CR_PTEADDR_VPN_MASK) |
|
||||||
|
(env->regs[CR_PTEADDR] & CR_PTEADDR_VPN_MASK);
|
||||||
|
env->mmu.pteaddr_wr = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mmu_init(CPUNios2State *env)
|
void mmu_init(CPUNios2State *env)
|
||||||
|
@ -246,8 +185,6 @@ void mmu_init(CPUNios2State *env)
|
||||||
Nios2CPU *cpu = env_archcpu(env);
|
Nios2CPU *cpu = env_archcpu(env);
|
||||||
Nios2MMU *mmu = &env->mmu;
|
Nios2MMU *mmu = &env->mmu;
|
||||||
|
|
||||||
MMU_LOG(qemu_log("mmu_init\n"));
|
|
||||||
|
|
||||||
mmu->tlb_entry_mask = (cpu->tlb_num_entries / cpu->tlb_num_ways) - 1;
|
mmu->tlb_entry_mask = (cpu->tlb_num_entries / cpu->tlb_num_ways) - 1;
|
||||||
mmu->tlb = g_new0(Nios2TLBEntry, cpu->tlb_num_entries);
|
mmu->tlb = g_new0(Nios2TLBEntry, cpu->tlb_num_entries);
|
||||||
}
|
}
|
||||||
|
@ -277,5 +214,3 @@ void dump_mmu(CPUNios2State *env)
|
||||||
(entry->data & CR_TLBACC_X) ? 'X' : '-');
|
(entry->data & CR_TLBACC_X) ? 'X' : '-');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !CONFIG_USER_ONLY */
|
|
||||||
|
|
|
@ -44,7 +44,6 @@ void mmu_flip_um(CPUNios2State *env, unsigned int um);
|
||||||
unsigned int mmu_translate(CPUNios2State *env,
|
unsigned int mmu_translate(CPUNios2State *env,
|
||||||
Nios2MMULookup *lu,
|
Nios2MMULookup *lu,
|
||||||
target_ulong vaddr, int rw, int mmu_idx);
|
target_ulong vaddr, int rw, int mmu_idx);
|
||||||
void mmu_read_debug(CPUNios2State *env, uint32_t rn);
|
|
||||||
void mmu_write(CPUNios2State *env, uint32_t rn, uint32_t v);
|
void mmu_write(CPUNios2State *env, uint32_t rn, uint32_t v);
|
||||||
void mmu_init(CPUNios2State *env);
|
void mmu_init(CPUNios2State *env);
|
||||||
|
|
||||||
|
|
|
@ -21,38 +21,9 @@
|
||||||
#include "qemu/osdep.h"
|
#include "qemu/osdep.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "exec/helper-proto.h"
|
#include "exec/helper-proto.h"
|
||||||
#include "exec/cpu_ldst.h"
|
|
||||||
#include "exec/exec-all.h"
|
#include "exec/exec-all.h"
|
||||||
#include "qemu/main-loop.h"
|
#include "qemu/main-loop.h"
|
||||||
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
|
||||||
void helper_mmu_read_debug(CPUNios2State *env, uint32_t rn)
|
|
||||||
{
|
|
||||||
mmu_read_debug(env, rn);
|
|
||||||
}
|
|
||||||
|
|
||||||
void helper_mmu_write(CPUNios2State *env, uint32_t rn, uint32_t v)
|
|
||||||
{
|
|
||||||
mmu_write(env, rn, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void nios2_check_interrupts(CPUNios2State *env)
|
|
||||||
{
|
|
||||||
if (env->irq_pending &&
|
|
||||||
(env->regs[CR_STATUS] & CR_STATUS_PIE)) {
|
|
||||||
env->irq_pending = 0;
|
|
||||||
cpu_interrupt(env_cpu(env), CPU_INTERRUPT_HARD);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void helper_check_interrupts(CPUNios2State *env)
|
|
||||||
{
|
|
||||||
qemu_mutex_lock_iothread();
|
|
||||||
nios2_check_interrupts(env);
|
|
||||||
qemu_mutex_unlock_iothread();
|
|
||||||
}
|
|
||||||
#endif /* !CONFIG_USER_ONLY */
|
|
||||||
|
|
||||||
void helper_raise_exception(CPUNios2State *env, uint32_t index)
|
void helper_raise_exception(CPUNios2State *env, uint32_t index)
|
||||||
{
|
{
|
||||||
CPUState *cs = env_cpu(env);
|
CPUState *cs = env_cpu(env);
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
# mmu.c
|
||||||
|
nios2_mmu_translate_miss(uint32_t vaddr, uint32_t pid, uint32_t index, uint32_t tag) "mmu_translate: MISS vaddr=0x%08x pid=%u TLB[%u] tag=0x%08x"
|
||||||
|
nios2_mmu_translate_hit(uint32_t vaddr, uint32_t pid, uint32_t index, uint32_t paddr, uint32_t prot) "mmu_translate: HIT vaddr=0x%08x pid=%u TLB[%u] paddr=0x%08x prot=0x%x"
|
||||||
|
|
||||||
|
nios2_mmu_flush_pid_miss(uint32_t pid, uint32_t index, uint32_t vaddr) "mmu_flush: MISS pid=%u TLB[%u] tag=0x%08x"
|
||||||
|
nios2_mmu_flush_pid_hit(uint32_t pid, uint32_t index, uint32_t vaddr) "mmu_flush: HIT pid=%u TLB[%u] vaddr=0x%08x"
|
||||||
|
|
||||||
|
nios2_mmu_write_tlbacc(uint32_t ig, char c, char r, char w, char x, char g, uint32_t pfn) "mmu_write_tlbacc: ig=0x%02x flags=%c%c%c%c%c pfn=0x%08x"
|
||||||
|
nios2_mmu_write_tlbmisc(uint32_t way, char r, char w, char t, char b, char p, char d, uint32_t pid) "mmu_write_tlbmisc: way=0x%x flags=%c%c%c%c%c%c pid=%u"
|
||||||
|
nios2_mmu_write_pteaddr(uint32_t ptb, uint32_t vpn) "mmu_write_pteaddr: ptbase=0x%03x vpn=0x%05x"
|
|
@ -447,28 +447,24 @@ static void rdctl(DisasContext *dc, uint32_t code, uint32_t flags)
|
||||||
|
|
||||||
gen_check_supervisor(dc);
|
gen_check_supervisor(dc);
|
||||||
|
|
||||||
switch (instr.imm5 + CR_BASE) {
|
if (unlikely(instr.c == R_ZERO)) {
|
||||||
case CR_PTEADDR:
|
return;
|
||||||
case CR_TLBACC:
|
|
||||||
case CR_TLBMISC:
|
|
||||||
{
|
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
|
||||||
if (likely(instr.c != R_ZERO)) {
|
|
||||||
tcg_gen_mov_tl(cpu_R[instr.c], cpu_R[instr.imm5 + CR_BASE]);
|
|
||||||
#ifdef DEBUG_MMU
|
|
||||||
TCGv_i32 tmp = tcg_const_i32(instr.imm5 + CR_BASE);
|
|
||||||
gen_helper_mmu_read_debug(cpu_R[instr.c], cpu_env, tmp);
|
|
||||||
tcg_temp_free_i32(tmp);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (instr.imm5 + CR_BASE) {
|
||||||
|
case CR_IPENDING:
|
||||||
|
/*
|
||||||
|
* The value of the ipending register is synthetic.
|
||||||
|
* In hw, this is the AND of a set of hardware irq lines
|
||||||
|
* with the ienable register. In qemu, we re-use the space
|
||||||
|
* of CR_IPENDING to store the set of irq lines, and so we
|
||||||
|
* must perform the AND here, and anywhere else we need the
|
||||||
|
* guest value of ipending.
|
||||||
|
*/
|
||||||
|
tcg_gen_and_tl(cpu_R[instr.c], cpu_R[CR_IPENDING], cpu_R[CR_IENABLE]);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (likely(instr.c != R_ZERO)) {
|
tcg_gen_mov_tl(cpu_R[instr.c], cpu_R[instr.imm5 + CR_BASE]);
|
||||||
tcg_gen_mov_tl(cpu_R[instr.c], cpu_R[instr.imm5 + CR_BASE]);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -476,36 +472,33 @@ static void rdctl(DisasContext *dc, uint32_t code, uint32_t flags)
|
||||||
/* ctlN <- rA */
|
/* ctlN <- rA */
|
||||||
static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
|
static void wrctl(DisasContext *dc, uint32_t code, uint32_t flags)
|
||||||
{
|
{
|
||||||
R_TYPE(instr, code);
|
|
||||||
|
|
||||||
gen_check_supervisor(dc);
|
gen_check_supervisor(dc);
|
||||||
|
|
||||||
|
#ifndef CONFIG_USER_ONLY
|
||||||
|
R_TYPE(instr, code);
|
||||||
|
TCGv v = load_gpr(dc, instr.a);
|
||||||
|
|
||||||
switch (instr.imm5 + CR_BASE) {
|
switch (instr.imm5 + CR_BASE) {
|
||||||
case CR_PTEADDR:
|
case CR_PTEADDR:
|
||||||
|
gen_helper_mmu_write_pteaddr(cpu_env, v);
|
||||||
|
break;
|
||||||
case CR_TLBACC:
|
case CR_TLBACC:
|
||||||
|
gen_helper_mmu_write_tlbacc(cpu_env, v);
|
||||||
|
break;
|
||||||
case CR_TLBMISC:
|
case CR_TLBMISC:
|
||||||
{
|
gen_helper_mmu_write_tlbmisc(cpu_env, v);
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
|
||||||
TCGv_i32 tmp = tcg_const_i32(instr.imm5 + CR_BASE);
|
|
||||||
gen_helper_mmu_write(cpu_env, tmp, load_gpr(dc, instr.a));
|
|
||||||
tcg_temp_free_i32(tmp);
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
case CR_IPENDING:
|
||||||
|
/* ipending is read only, writes ignored. */
|
||||||
default:
|
|
||||||
tcg_gen_mov_tl(cpu_R[instr.imm5 + CR_BASE], load_gpr(dc, instr.a));
|
|
||||||
break;
|
break;
|
||||||
}
|
case CR_STATUS:
|
||||||
|
case CR_IENABLE:
|
||||||
/* If interrupts were enabled using WRCTL, trigger them. */
|
/* If interrupts were enabled using WRCTL, trigger them. */
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
|
||||||
if ((instr.imm5 + CR_BASE) == CR_STATUS) {
|
|
||||||
if (tb_cflags(dc->base.tb) & CF_USE_ICOUNT) {
|
|
||||||
gen_io_start();
|
|
||||||
}
|
|
||||||
gen_helper_check_interrupts(cpu_env);
|
|
||||||
dc->base.is_jmp = DISAS_UPDATE;
|
dc->base.is_jmp = DISAS_UPDATE;
|
||||||
|
/* fall through */
|
||||||
|
default:
|
||||||
|
tcg_gen_mov_tl(cpu_R[instr.imm5 + CR_BASE], v);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue