2017-01-19 01:01:41 +03:00
|
|
|
/*
|
|
|
|
* Altera Nios II helper routines.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Chris Wulff <crwulff@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.1 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
|
|
|
|
* License along with this library; if not, see
|
|
|
|
* <http://www.gnu.org/licenses/lgpl-2.1.html>
|
|
|
|
*/
|
|
|
|
|
2017-10-17 19:44:01 +03:00
|
|
|
#include "qemu/osdep.h"
|
2017-01-19 01:01:41 +03:00
|
|
|
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "qemu/host-utils.h"
|
|
|
|
#include "exec/exec-all.h"
|
2019-04-03 22:53:05 +03:00
|
|
|
#include "exec/cpu_ldst.h"
|
2017-01-19 01:01:41 +03:00
|
|
|
#include "exec/log.h"
|
|
|
|
#include "exec/helper-proto.h"
|
2021-03-05 16:54:49 +03:00
|
|
|
#include "semihosting/semihost.h"
|
2017-01-19 01:01:41 +03:00
|
|
|
|
2022-04-21 18:16:42 +03:00
|
|
|
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
static void do_exception(Nios2CPU *cpu, uint32_t exception_addr,
|
|
|
|
uint32_t tlbmisc_set, bool is_break)
|
2022-04-21 18:17:03 +03:00
|
|
|
{
|
|
|
|
CPUNios2State *env = &cpu->env;
|
|
|
|
CPUState *cs = CPU(cpu);
|
|
|
|
uint32_t old_status = env->ctrl[CR_STATUS];
|
|
|
|
uint32_t new_status = old_status;
|
|
|
|
|
|
|
|
if ((old_status & CR_STATUS_EH) == 0) {
|
|
|
|
int r_ea = R_EA, cr_es = CR_ESTATUS;
|
|
|
|
|
|
|
|
if (is_break) {
|
|
|
|
r_ea = R_BA;
|
|
|
|
cr_es = CR_BSTATUS;
|
|
|
|
}
|
|
|
|
env->ctrl[cr_es] = old_status;
|
|
|
|
env->regs[r_ea] = env->pc + 4;
|
|
|
|
|
|
|
|
if (cpu->mmu_present) {
|
|
|
|
new_status |= CR_STATUS_EH;
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There are 4 bits that are always written.
|
|
|
|
* Explicitly clear them, to be set via the argument.
|
|
|
|
*/
|
|
|
|
env->ctrl[CR_TLBMISC] &= ~(CR_TLBMISC_D |
|
|
|
|
CR_TLBMISC_PERM |
|
|
|
|
CR_TLBMISC_BAD |
|
|
|
|
CR_TLBMISC_DBL);
|
|
|
|
env->ctrl[CR_TLBMISC] |= tlbmisc_set;
|
2022-04-21 18:17:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new_status &= ~(CR_STATUS_PIE | CR_STATUS_U);
|
|
|
|
|
|
|
|
env->ctrl[CR_STATUS] = new_status;
|
2022-04-21 18:17:06 +03:00
|
|
|
if (!is_break) {
|
|
|
|
env->ctrl[CR_EXCEPTION] = FIELD_DP32(0, CR_EXCEPTION, CAUSE,
|
|
|
|
cs->exception_index);
|
|
|
|
}
|
2022-04-21 18:17:03 +03:00
|
|
|
env->pc = exception_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_iic_irq(Nios2CPU *cpu)
|
|
|
|
{
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
do_exception(cpu, cpu->exception_addr, 0, false);
|
2022-04-21 18:17:03 +03:00
|
|
|
}
|
|
|
|
|
2017-01-19 01:01:41 +03:00
|
|
|
void nios2_cpu_do_interrupt(CPUState *cs)
|
|
|
|
{
|
|
|
|
Nios2CPU *cpu = NIOS2_CPU(cs);
|
|
|
|
CPUNios2State *env = &cpu->env;
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
uint32_t tlbmisc_set = 0;
|
2017-01-19 01:01:41 +03:00
|
|
|
|
2022-04-21 18:17:04 +03:00
|
|
|
if (qemu_loglevel_mask(CPU_LOG_INT)) {
|
|
|
|
const char *name = NULL;
|
|
|
|
|
|
|
|
switch (cs->exception_index) {
|
|
|
|
case EXCP_IRQ:
|
|
|
|
name = "interrupt";
|
|
|
|
break;
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
case EXCP_TLB_X:
|
|
|
|
case EXCP_TLB_D:
|
2022-04-21 18:17:04 +03:00
|
|
|
if (env->ctrl[CR_STATUS] & CR_STATUS_EH) {
|
|
|
|
name = "TLB MISS (double)";
|
|
|
|
} else {
|
|
|
|
name = "TLB MISS (fast)";
|
|
|
|
}
|
|
|
|
break;
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
case EXCP_PERM_R:
|
|
|
|
case EXCP_PERM_W:
|
|
|
|
case EXCP_PERM_X:
|
2022-04-21 18:17:04 +03:00
|
|
|
name = "TLB PERM";
|
|
|
|
break;
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
case EXCP_SUPERA_X:
|
|
|
|
case EXCP_SUPERA_D:
|
2022-04-21 18:17:04 +03:00
|
|
|
name = "SUPERVISOR (address)";
|
|
|
|
break;
|
|
|
|
case EXCP_SUPERI:
|
|
|
|
name = "SUPERVISOR (insn)";
|
|
|
|
break;
|
|
|
|
case EXCP_ILLEGAL:
|
|
|
|
name = "ILLEGAL insn";
|
|
|
|
break;
|
2022-04-21 18:17:05 +03:00
|
|
|
case EXCP_UNALIGN:
|
|
|
|
name = "Misaligned (data)";
|
|
|
|
break;
|
|
|
|
case EXCP_UNALIGND:
|
|
|
|
name = "Misaligned (destination)";
|
|
|
|
break;
|
2022-04-21 18:17:12 +03:00
|
|
|
case EXCP_DIV:
|
|
|
|
name = "DIV error";
|
|
|
|
break;
|
2022-04-21 18:17:04 +03:00
|
|
|
case EXCP_TRAP:
|
|
|
|
name = "TRAP insn";
|
|
|
|
break;
|
|
|
|
case EXCP_BREAK:
|
|
|
|
name = "BREAK insn";
|
|
|
|
break;
|
|
|
|
case EXCP_SEMIHOST:
|
|
|
|
name = "SEMIHOST insn";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (name) {
|
|
|
|
qemu_log("%s at pc=0x%08x\n", name, env->pc);
|
|
|
|
} else {
|
|
|
|
qemu_log("Unknown exception %d at pc=0x%08x\n",
|
|
|
|
cs->exception_index, env->pc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 01:01:41 +03:00
|
|
|
switch (cs->exception_index) {
|
|
|
|
case EXCP_IRQ:
|
2022-04-21 18:17:03 +03:00
|
|
|
do_iic_irq(cpu);
|
2017-01-19 01:01:41 +03:00
|
|
|
break;
|
|
|
|
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
case EXCP_TLB_D:
|
|
|
|
tlbmisc_set = CR_TLBMISC_D;
|
|
|
|
/* fall through */
|
|
|
|
case EXCP_TLB_X:
|
|
|
|
if (env->ctrl[CR_STATUS] & CR_STATUS_EH) {
|
|
|
|
tlbmisc_set |= CR_TLBMISC_DBL;
|
|
|
|
/*
|
|
|
|
* Normally, we don't write to tlbmisc unless !EH,
|
|
|
|
* so do it manually for the double-tlb miss exception.
|
|
|
|
*/
|
|
|
|
env->ctrl[CR_TLBMISC] &= ~(CR_TLBMISC_D |
|
|
|
|
CR_TLBMISC_PERM |
|
|
|
|
CR_TLBMISC_BAD);
|
|
|
|
env->ctrl[CR_TLBMISC] |= tlbmisc_set;
|
|
|
|
do_exception(cpu, cpu->exception_addr, 0, false);
|
2017-01-19 01:01:41 +03:00
|
|
|
} else {
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
tlbmisc_set |= CR_TLBMISC_WE;
|
|
|
|
do_exception(cpu, cpu->fast_tlb_miss_addr, tlbmisc_set, false);
|
2017-01-19 01:01:41 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
case EXCP_PERM_R:
|
|
|
|
case EXCP_PERM_W:
|
|
|
|
tlbmisc_set = CR_TLBMISC_D;
|
|
|
|
/* fall through */
|
|
|
|
case EXCP_PERM_X:
|
|
|
|
tlbmisc_set |= CR_TLBMISC_PERM;
|
|
|
|
if (!(env->ctrl[CR_STATUS] & CR_STATUS_EH)) {
|
|
|
|
tlbmisc_set |= CR_TLBMISC_WE;
|
2017-01-19 01:01:41 +03:00
|
|
|
}
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
do_exception(cpu, cpu->exception_addr, tlbmisc_set, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EXCP_SUPERA_D:
|
|
|
|
case EXCP_UNALIGN:
|
|
|
|
tlbmisc_set = CR_TLBMISC_D;
|
|
|
|
/* fall through */
|
|
|
|
case EXCP_SUPERA_X:
|
|
|
|
case EXCP_UNALIGND:
|
|
|
|
tlbmisc_set |= CR_TLBMISC_BAD;
|
|
|
|
do_exception(cpu, cpu->exception_addr, tlbmisc_set, false);
|
2017-01-19 01:01:41 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EXCP_SUPERI:
|
|
|
|
case EXCP_ILLEGAL:
|
2022-04-21 18:17:12 +03:00
|
|
|
case EXCP_DIV:
|
2017-01-19 01:01:41 +03:00
|
|
|
case EXCP_TRAP:
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
do_exception(cpu, cpu->exception_addr, 0, false);
|
2017-01-19 01:01:41 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EXCP_BREAK:
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
do_exception(cpu, cpu->exception_addr, 0, true);
|
2017-01-19 01:01:41 +03:00
|
|
|
break;
|
|
|
|
|
2022-04-21 18:17:02 +03:00
|
|
|
case EXCP_SEMIHOST:
|
|
|
|
env->pc += 4;
|
|
|
|
do_nios2_semihosting(env);
|
|
|
|
break;
|
|
|
|
|
2017-01-19 01:01:41 +03:00
|
|
|
default:
|
2022-04-21 18:17:03 +03:00
|
|
|
cpu_abort(cs, "unhandled exception type=%d\n", cs->exception_index);
|
2017-01-19 01:01:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hwaddr nios2_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
|
|
|
|
{
|
|
|
|
Nios2CPU *cpu = NIOS2_CPU(cs);
|
|
|
|
CPUNios2State *env = &cpu->env;
|
|
|
|
target_ulong vaddr, paddr = 0;
|
|
|
|
Nios2MMULookup lu;
|
|
|
|
unsigned int hit;
|
|
|
|
|
|
|
|
if (cpu->mmu_present && (addr < 0xC0000000)) {
|
|
|
|
hit = mmu_translate(env, &lu, addr, 0, 0);
|
|
|
|
if (hit) {
|
|
|
|
vaddr = addr & TARGET_PAGE_MASK;
|
|
|
|
paddr = lu.paddr + vaddr - lu.vaddr;
|
|
|
|
} else {
|
|
|
|
paddr = -1;
|
|
|
|
qemu_log("cpu_get_phys_page debug MISS: %#" PRIx64 "\n", addr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
paddr = addr & TARGET_PAGE_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return paddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nios2_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
|
|
|
|
MMUAccessType access_type,
|
|
|
|
int mmu_idx, uintptr_t retaddr)
|
|
|
|
{
|
|
|
|
Nios2CPU *cpu = NIOS2_CPU(cs);
|
|
|
|
CPUNios2State *env = &cpu->env;
|
|
|
|
|
2022-04-21 18:16:53 +03:00
|
|
|
env->ctrl[CR_BADADDR] = addr;
|
2022-04-21 18:16:56 +03:00
|
|
|
env->ctrl[CR_EXCEPTION] = FIELD_DP32(0, CR_EXCEPTION, CAUSE, EXCP_UNALIGN);
|
2017-01-19 01:01:41 +03:00
|
|
|
helper_raise_exception(env, EXCP_UNALIGN);
|
|
|
|
}
|
2019-04-02 12:47:37 +03:00
|
|
|
|
|
|
|
bool nios2_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
|
|
|
|
MMUAccessType access_type, int mmu_idx,
|
|
|
|
bool probe, uintptr_t retaddr)
|
|
|
|
{
|
|
|
|
Nios2CPU *cpu = NIOS2_CPU(cs);
|
|
|
|
CPUNios2State *env = &cpu->env;
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
unsigned int excp;
|
2019-04-02 12:47:37 +03:00
|
|
|
target_ulong vaddr, paddr;
|
|
|
|
Nios2MMULookup lu;
|
|
|
|
unsigned int hit;
|
|
|
|
|
|
|
|
if (!cpu->mmu_present) {
|
|
|
|
/* No MMU */
|
|
|
|
address &= TARGET_PAGE_MASK;
|
|
|
|
tlb_set_page(cs, address, address, PAGE_BITS,
|
|
|
|
mmu_idx, TARGET_PAGE_SIZE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MMU_SUPERVISOR_IDX == mmu_idx) {
|
|
|
|
if (address >= 0xC0000000) {
|
|
|
|
/* Kernel physical page - TLB bypassed */
|
|
|
|
address &= TARGET_PAGE_MASK;
|
|
|
|
tlb_set_page(cs, address, address, PAGE_BITS,
|
|
|
|
mmu_idx, TARGET_PAGE_SIZE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (address >= 0x80000000) {
|
|
|
|
/* Illegal access from user mode */
|
|
|
|
if (probe) {
|
|
|
|
return false;
|
|
|
|
}
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
cs->exception_index = (access_type == MMU_INST_FETCH
|
|
|
|
? EXCP_SUPERA_X : EXCP_SUPERA_D);
|
2022-04-21 18:16:53 +03:00
|
|
|
env->ctrl[CR_BADADDR] = address;
|
2019-04-02 12:47:37 +03:00
|
|
|
cpu_loop_exit_restore(cs, retaddr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Virtual page. */
|
|
|
|
hit = mmu_translate(env, &lu, address, access_type, mmu_idx);
|
|
|
|
if (hit) {
|
|
|
|
vaddr = address & TARGET_PAGE_MASK;
|
|
|
|
paddr = lu.paddr + vaddr - lu.vaddr;
|
|
|
|
|
|
|
|
if (((access_type == MMU_DATA_LOAD) && (lu.prot & PAGE_READ)) ||
|
|
|
|
((access_type == MMU_DATA_STORE) && (lu.prot & PAGE_WRITE)) ||
|
|
|
|
((access_type == MMU_INST_FETCH) && (lu.prot & PAGE_EXEC))) {
|
|
|
|
tlb_set_page(cs, vaddr, paddr, lu.prot,
|
|
|
|
mmu_idx, TARGET_PAGE_SIZE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Permission violation */
|
target/nios2: Clean up handling of tlbmisc in do_exception
The 4 lower bits, D, PERM, BAD, DBL, are unconditionally set on any
exception with EH=0, or so says Table 42 (Processor Status After
Taking Exception).
We currently do not set PERM or BAD at all, and only set/clear
DBL for tlb miss, and do not clear DBL for any other exception.
It is a bit confusing to set D in tlb_fill and the rest during
do_interrupt, so move the setting of D to do_interrupt as well.
To do this, split EXP_TLBD into two cases, EXCP_TLB_X and EXCP_TLB_D,
which allows us to distinguish them during do_interrupt. Choose
a value for EXCP_TLB_D such that when truncated it produces the
correct value for exception.CAUSE.
Rename EXCP_TLB[RWX] to EXCP_PERM_[RWX], to emphasize that the
exception is permissions related. Rename EXCP_SUPER[AD] to
EXCP_SUPERA_[DX] to emphasize that they are both "supervisor
address" exceptions, data and execute.
Retain the setting of tlbmisc.WE for the fast-tlb-miss path, as it
is being relied upon, but remove it from the permission path.
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-37-richard.henderson@linaro.org>
2022-04-21 18:17:07 +03:00
|
|
|
excp = (access_type == MMU_DATA_LOAD ? EXCP_PERM_R :
|
|
|
|
access_type == MMU_DATA_STORE ? EXCP_PERM_W : EXCP_PERM_X);
|
|
|
|
} else {
|
|
|
|
excp = (access_type == MMU_INST_FETCH ? EXCP_TLB_X: EXCP_TLB_D);
|
2019-04-02 12:47:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (probe) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-21 18:17:00 +03:00
|
|
|
env->ctrl[CR_TLBMISC] = FIELD_DP32(env->ctrl[CR_TLBMISC], CR_TLBMISC, D,
|
|
|
|
access_type != MMU_INST_FETCH);
|
2022-04-21 18:16:57 +03:00
|
|
|
env->ctrl[CR_PTEADDR] = FIELD_DP32(env->ctrl[CR_PTEADDR], CR_PTEADDR, VPN,
|
|
|
|
address >> TARGET_PAGE_BITS);
|
2022-04-21 18:16:53 +03:00
|
|
|
env->mmu.pteaddr_wr = env->ctrl[CR_PTEADDR];
|
2019-04-02 12:47:37 +03:00
|
|
|
|
|
|
|
cs->exception_index = excp;
|
2022-04-21 18:16:53 +03:00
|
|
|
env->ctrl[CR_BADADDR] = address;
|
2019-04-02 12:47:37 +03:00
|
|
|
cpu_loop_exit_restore(cs, retaddr);
|
|
|
|
}
|