2007-04-05 10:58:33 +04:00
|
|
|
/*
|
|
|
|
* Alpha emulation cpu helpers for qemu.
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2007-04-05 10:58:33 +04:00
|
|
|
* Copyright (c) 2007 Jocelyn Mayer
|
|
|
|
*
|
|
|
|
* 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
|
2020-10-23 15:33:53 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2007-04-05 10:58:33 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
2007-04-05 10:58:33 +04:00
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:04 +03:00
|
|
|
#include "qemu/osdep.h"
|
2007-04-05 10:58:33 +04:00
|
|
|
|
|
|
|
#include "cpu.h"
|
2016-03-15 15:18:37 +03:00
|
|
|
#include "exec/exec-all.h"
|
2019-08-08 19:30:35 +03:00
|
|
|
#include "fpu/softfloat-types.h"
|
2014-04-08 09:31:41 +04:00
|
|
|
#include "exec/helper-proto.h"
|
2019-04-17 22:18:02 +03:00
|
|
|
#include "qemu/qemu-print.h"
|
2009-12-10 02:56:29 +03:00
|
|
|
|
2009-12-31 23:41:07 +03:00
|
|
|
|
2014-08-09 02:17:07 +04:00
|
|
|
#define CONVERT_BIT(X, SRC, DST) \
|
|
|
|
(SRC > DST ? (X) / (SRC / DST) & (DST) : ((X) & SRC) * (DST / SRC))
|
2009-12-31 23:41:07 +03:00
|
|
|
|
2019-04-27 01:20:51 +03:00
|
|
|
uint64_t cpu_alpha_load_fpcr(CPUAlphaState *env)
|
2014-08-09 02:17:07 +04:00
|
|
|
{
|
|
|
|
return (uint64_t)env->fpcr << 32;
|
2009-12-10 02:56:29 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 01:20:51 +03:00
|
|
|
void cpu_alpha_store_fpcr(CPUAlphaState *env, uint64_t val)
|
2009-12-10 02:56:29 +03:00
|
|
|
{
|
2019-09-21 07:32:50 +03:00
|
|
|
static const uint8_t rm_map[] = {
|
|
|
|
[FPCR_DYN_NORMAL >> FPCR_DYN_SHIFT] = float_round_nearest_even,
|
|
|
|
[FPCR_DYN_CHOPPED >> FPCR_DYN_SHIFT] = float_round_to_zero,
|
|
|
|
[FPCR_DYN_MINUS >> FPCR_DYN_SHIFT] = float_round_down,
|
|
|
|
[FPCR_DYN_PLUS >> FPCR_DYN_SHIFT] = float_round_up,
|
|
|
|
};
|
|
|
|
|
2014-08-09 02:17:07 +04:00
|
|
|
uint32_t fpcr = val >> 32;
|
|
|
|
uint32_t t = 0;
|
2009-12-31 23:41:07 +03:00
|
|
|
|
2019-09-21 07:32:52 +03:00
|
|
|
/* Record the raw value before adjusting for linux-user. */
|
|
|
|
env->fpcr = fpcr;
|
|
|
|
|
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
/*
|
|
|
|
* Override some of these bits with the contents of ENV->SWCR.
|
|
|
|
* In system mode, some of these would trap to the kernel, at
|
|
|
|
* which point the kernel's handler would emulate and apply
|
|
|
|
* the software exception mask.
|
|
|
|
*/
|
|
|
|
uint32_t soft_fpcr = alpha_ieee_swcr_to_fpcr(env->swcr) >> 32;
|
2019-09-21 07:32:53 +03:00
|
|
|
fpcr |= soft_fpcr & (FPCR_STATUS_MASK | FPCR_DNZ);
|
2019-09-21 07:32:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The IOV exception is disabled by the kernel with SWCR_TRAP_ENABLE_INV,
|
|
|
|
* which got mapped by alpha_ieee_swcr_to_fpcr to FPCR_INVD.
|
|
|
|
* Add FPCR_IOV to fpcr_exc_enable so that it is handled identically.
|
|
|
|
*/
|
|
|
|
t |= CONVERT_BIT(soft_fpcr, FPCR_INVD, FPCR_IOV);
|
2019-09-21 07:32:52 +03:00
|
|
|
#endif
|
|
|
|
|
2014-08-09 02:17:07 +04:00
|
|
|
t |= CONVERT_BIT(fpcr, FPCR_INED, FPCR_INE);
|
|
|
|
t |= CONVERT_BIT(fpcr, FPCR_UNFD, FPCR_UNF);
|
|
|
|
t |= CONVERT_BIT(fpcr, FPCR_OVFD, FPCR_OVF);
|
|
|
|
t |= CONVERT_BIT(fpcr, FPCR_DZED, FPCR_DZE);
|
|
|
|
t |= CONVERT_BIT(fpcr, FPCR_INVD, FPCR_INV);
|
2009-12-31 23:41:07 +03:00
|
|
|
|
2014-08-09 02:17:07 +04:00
|
|
|
env->fpcr_exc_enable = ~t & FPCR_STATUS_MASK;
|
2009-12-31 23:41:07 +03:00
|
|
|
|
2019-09-21 07:32:50 +03:00
|
|
|
env->fpcr_dyn_round = rm_map[(fpcr & FPCR_DYN_MASK) >> FPCR_DYN_SHIFT];
|
2014-08-09 02:17:07 +04:00
|
|
|
env->fp_status.flush_inputs_to_zero = (fpcr & FPCR_DNZ) != 0;
|
2019-09-21 07:32:54 +03:00
|
|
|
|
|
|
|
t = (fpcr & FPCR_UNFD) && (fpcr & FPCR_UNDZ);
|
2019-04-27 01:20:51 +03:00
|
|
|
#ifdef CONFIG_USER_ONLY
|
2019-09-21 07:32:54 +03:00
|
|
|
t |= (env->swcr & SWCR_MAP_UMZ) != 0;
|
2019-04-27 01:20:51 +03:00
|
|
|
#endif
|
2019-09-21 07:32:54 +03:00
|
|
|
env->fpcr_flush_to_zero = t;
|
2009-12-10 02:56:29 +03:00
|
|
|
}
|
2007-04-05 10:58:33 +04:00
|
|
|
|
2012-03-24 20:51:10 +04:00
|
|
|
uint64_t helper_load_fpcr(CPUAlphaState *env)
|
|
|
|
{
|
|
|
|
return cpu_alpha_load_fpcr(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
void helper_store_fpcr(CPUAlphaState *env, uint64_t val)
|
|
|
|
{
|
|
|
|
cpu_alpha_store_fpcr(env, val);
|
|
|
|
}
|
|
|
|
|
2014-09-16 23:16:38 +04:00
|
|
|
static uint64_t *cpu_alpha_addr_gr(CPUAlphaState *env, unsigned reg)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
2017-07-06 22:45:07 +03:00
|
|
|
if (env->flags & ENV_FLAG_PAL_MODE) {
|
2014-09-16 23:16:38 +04:00
|
|
|
if (reg >= 8 && reg <= 14) {
|
|
|
|
return &env->shadow[reg - 8];
|
|
|
|
} else if (reg == 25) {
|
|
|
|
return &env->shadow[7];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return &env->ir[reg];
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t cpu_alpha_load_gr(CPUAlphaState *env, unsigned reg)
|
|
|
|
{
|
|
|
|
return *cpu_alpha_addr_gr(env, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cpu_alpha_store_gr(CPUAlphaState *env, unsigned reg, uint64_t val)
|
|
|
|
{
|
|
|
|
*cpu_alpha_addr_gr(env, reg) = val;
|
|
|
|
}
|
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
#if defined(CONFIG_USER_ONLY)
|
2019-04-02 10:51:11 +03:00
|
|
|
bool alpha_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
|
|
|
|
MMUAccessType access_type, int mmu_idx,
|
|
|
|
bool probe, uintptr_t retaddr)
|
2007-04-05 10:58:33 +04:00
|
|
|
{
|
2013-08-26 05:01:33 +04:00
|
|
|
AlphaCPU *cpu = ALPHA_CPU(cs);
|
|
|
|
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = EXCP_MMFAULT;
|
2013-08-26 05:01:33 +04:00
|
|
|
cpu->env.trap_arg0 = address;
|
2019-04-02 10:51:11 +03:00
|
|
|
cpu_loop_exit_restore(cs, retaddr);
|
2007-04-05 10:58:33 +04:00
|
|
|
}
|
|
|
|
#else
|
2011-04-19 02:59:21 +04:00
|
|
|
/* Returns the OSF/1 entMM failure indication, or -1 on success. */
|
2012-03-14 04:38:21 +04:00
|
|
|
static int get_physical_address(CPUAlphaState *env, target_ulong addr,
|
2011-04-19 02:59:21 +04:00
|
|
|
int prot_need, int mmu_idx,
|
|
|
|
target_ulong *pphys, int *pprot)
|
2007-04-05 10:58:33 +04:00
|
|
|
{
|
2019-03-23 03:26:58 +03:00
|
|
|
CPUState *cs = env_cpu(env);
|
2011-04-19 02:59:21 +04:00
|
|
|
target_long saddr = addr;
|
|
|
|
target_ulong phys = 0;
|
|
|
|
target_ulong L1pte, L2pte, L3pte;
|
|
|
|
target_ulong pt, index;
|
|
|
|
int prot = 0;
|
|
|
|
int ret = MM_K_ACV;
|
|
|
|
|
2016-09-03 21:32:35 +03:00
|
|
|
/* Handle physical accesses. */
|
|
|
|
if (mmu_idx == MMU_PHYS_IDX) {
|
|
|
|
phys = addr;
|
|
|
|
prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
|
|
|
ret = -1;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2011-04-19 02:59:21 +04:00
|
|
|
/* Ensure that the virtual address is properly sign-extended from
|
|
|
|
the last implemented virtual address bit. */
|
|
|
|
if (saddr >> TARGET_VIRT_ADDR_SPACE_BITS != saddr >> 63) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Translate the superpage. */
|
|
|
|
/* ??? When we do more than emulate Unix PALcode, we'll need to
|
2011-04-27 20:22:18 +04:00
|
|
|
determine which KSEG is actually active. */
|
|
|
|
if (saddr < 0 && ((saddr >> 41) & 3) == 2) {
|
|
|
|
/* User-space cannot access KSEG addresses. */
|
2011-04-19 02:59:21 +04:00
|
|
|
if (mmu_idx != MMU_KERNEL_IDX) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2011-04-27 20:22:18 +04:00
|
|
|
/* For the benefit of the Typhoon chipset, move bit 40 to bit 43.
|
|
|
|
We would not do this if the 48-bit KSEG is enabled. */
|
2011-04-19 02:59:21 +04:00
|
|
|
phys = saddr & ((1ull << 40) - 1);
|
2011-04-27 20:22:18 +04:00
|
|
|
phys |= (saddr & (1ull << 40)) << 3;
|
|
|
|
|
2011-04-19 02:59:21 +04:00
|
|
|
prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
|
|
|
ret = -1;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interpret the page table exactly like PALcode does. */
|
|
|
|
|
|
|
|
pt = env->ptbr;
|
|
|
|
|
2017-08-08 15:42:52 +03:00
|
|
|
/* TODO: rather than using ldq_phys() to read the page table we should
|
|
|
|
* use address_space_ldq() so that we can handle the case when
|
|
|
|
* the page table read gives a bus fault, rather than ignoring it.
|
|
|
|
* For the existing code the zero data that ldq_phys will return for
|
|
|
|
* an access to invalid memory will result in our treating the page
|
|
|
|
* table as invalid, which may even be the right behaviour.
|
|
|
|
*/
|
|
|
|
|
2011-04-19 02:59:21 +04:00
|
|
|
/* L1 page table read. */
|
|
|
|
index = (addr >> (TARGET_PAGE_BITS + 20)) & 0x3ff;
|
2013-12-17 08:05:40 +04:00
|
|
|
L1pte = ldq_phys(cs->as, pt + index*8);
|
2011-04-19 02:59:21 +04:00
|
|
|
|
|
|
|
if (unlikely((L1pte & PTE_VALID) == 0)) {
|
|
|
|
ret = MM_K_TNV;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (unlikely((L1pte & PTE_KRE) == 0)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
pt = L1pte >> 32 << TARGET_PAGE_BITS;
|
|
|
|
|
|
|
|
/* L2 page table read. */
|
|
|
|
index = (addr >> (TARGET_PAGE_BITS + 10)) & 0x3ff;
|
2013-12-17 08:05:40 +04:00
|
|
|
L2pte = ldq_phys(cs->as, pt + index*8);
|
2011-04-19 02:59:21 +04:00
|
|
|
|
|
|
|
if (unlikely((L2pte & PTE_VALID) == 0)) {
|
|
|
|
ret = MM_K_TNV;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
if (unlikely((L2pte & PTE_KRE) == 0)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
pt = L2pte >> 32 << TARGET_PAGE_BITS;
|
|
|
|
|
|
|
|
/* L3 page table read. */
|
|
|
|
index = (addr >> TARGET_PAGE_BITS) & 0x3ff;
|
2013-12-17 08:05:40 +04:00
|
|
|
L3pte = ldq_phys(cs->as, pt + index*8);
|
2011-04-19 02:59:21 +04:00
|
|
|
|
|
|
|
phys = L3pte >> 32 << TARGET_PAGE_BITS;
|
|
|
|
if (unlikely((L3pte & PTE_VALID) == 0)) {
|
|
|
|
ret = MM_K_TNV;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if PAGE_READ != 1 || PAGE_WRITE != 2 || PAGE_EXEC != 4
|
|
|
|
# error page bits out of date
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Check access violations. */
|
|
|
|
if (L3pte & (PTE_KRE << mmu_idx)) {
|
|
|
|
prot |= PAGE_READ | PAGE_EXEC;
|
|
|
|
}
|
|
|
|
if (L3pte & (PTE_KWE << mmu_idx)) {
|
|
|
|
prot |= PAGE_WRITE;
|
|
|
|
}
|
|
|
|
if (unlikely((prot & prot_need) == 0 && prot_need)) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check fault-on-operation violations. */
|
|
|
|
prot &= ~(L3pte >> 1);
|
|
|
|
ret = -1;
|
|
|
|
if (unlikely((prot & prot_need) == 0)) {
|
|
|
|
ret = (prot_need & PAGE_EXEC ? MM_K_FOE :
|
|
|
|
prot_need & PAGE_WRITE ? MM_K_FOW :
|
|
|
|
prot_need & PAGE_READ ? MM_K_FOR : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
*pphys = phys;
|
|
|
|
*pprot = prot;
|
|
|
|
return ret;
|
2007-04-05 10:58:33 +04:00
|
|
|
}
|
|
|
|
|
2013-06-29 20:55:54 +04:00
|
|
|
hwaddr alpha_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
|
2007-04-05 10:58:33 +04:00
|
|
|
{
|
2013-06-29 20:55:54 +04:00
|
|
|
AlphaCPU *cpu = ALPHA_CPU(cs);
|
2011-04-19 02:59:21 +04:00
|
|
|
target_ulong phys;
|
|
|
|
int prot, fail;
|
|
|
|
|
2013-06-29 20:55:54 +04:00
|
|
|
fail = get_physical_address(&cpu->env, addr, 0, 0, &phys, &prot);
|
2011-04-19 02:59:21 +04:00
|
|
|
return (fail >= 0 ? -1 : phys);
|
|
|
|
}
|
|
|
|
|
2019-04-02 10:51:11 +03:00
|
|
|
bool alpha_cpu_tlb_fill(CPUState *cs, vaddr addr, int size,
|
|
|
|
MMUAccessType access_type, int mmu_idx,
|
|
|
|
bool probe, uintptr_t retaddr)
|
2011-04-19 02:59:21 +04:00
|
|
|
{
|
2013-08-26 05:01:33 +04:00
|
|
|
AlphaCPU *cpu = ALPHA_CPU(cs);
|
|
|
|
CPUAlphaState *env = &cpu->env;
|
2011-04-19 02:59:21 +04:00
|
|
|
target_ulong phys;
|
|
|
|
int prot, fail;
|
|
|
|
|
2019-04-02 10:51:11 +03:00
|
|
|
fail = get_physical_address(env, addr, 1 << access_type,
|
|
|
|
mmu_idx, &phys, &prot);
|
2011-04-19 02:59:21 +04:00
|
|
|
if (unlikely(fail >= 0)) {
|
2019-04-02 10:51:11 +03:00
|
|
|
if (probe) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = EXCP_MMFAULT;
|
2011-04-19 02:59:21 +04:00
|
|
|
env->trap_arg0 = addr;
|
|
|
|
env->trap_arg1 = fail;
|
2019-08-22 20:45:14 +03:00
|
|
|
env->trap_arg2 = (access_type == MMU_DATA_LOAD ? 0ull :
|
|
|
|
access_type == MMU_DATA_STORE ? 1ull :
|
|
|
|
/* access_type == MMU_INST_FETCH */ -1ull);
|
2019-04-02 10:51:11 +03:00
|
|
|
cpu_loop_exit_restore(cs, retaddr);
|
2011-04-19 02:59:21 +04:00
|
|
|
}
|
|
|
|
|
2013-09-03 15:59:37 +04:00
|
|
|
tlb_set_page(cs, addr & TARGET_PAGE_MASK, phys & TARGET_PAGE_MASK,
|
2011-04-19 02:59:21 +04:00
|
|
|
prot, mmu_idx, TARGET_PAGE_SIZE);
|
2019-04-02 10:51:11 +03:00
|
|
|
return true;
|
|
|
|
}
|
2011-04-19 01:05:35 +04:00
|
|
|
#endif /* USER_ONLY */
|
2007-04-05 10:58:33 +04:00
|
|
|
|
2013-02-02 13:57:51 +04:00
|
|
|
void alpha_cpu_do_interrupt(CPUState *cs)
|
2007-04-05 10:58:33 +04:00
|
|
|
{
|
2013-02-02 13:57:51 +04:00
|
|
|
AlphaCPU *cpu = ALPHA_CPU(cs);
|
|
|
|
CPUAlphaState *env = &cpu->env;
|
2013-08-26 10:31:06 +04:00
|
|
|
int i = cs->exception_index;
|
2011-04-19 01:05:35 +04:00
|
|
|
|
|
|
|
if (qemu_loglevel_mask(CPU_LOG_INT)) {
|
|
|
|
static int count;
|
|
|
|
const char *name = "<unknown>";
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case EXCP_RESET:
|
|
|
|
name = "reset";
|
|
|
|
break;
|
|
|
|
case EXCP_MCHK:
|
|
|
|
name = "mchk";
|
|
|
|
break;
|
|
|
|
case EXCP_SMP_INTERRUPT:
|
|
|
|
name = "smp_interrupt";
|
|
|
|
break;
|
|
|
|
case EXCP_CLK_INTERRUPT:
|
|
|
|
name = "clk_interrupt";
|
|
|
|
break;
|
|
|
|
case EXCP_DEV_INTERRUPT:
|
|
|
|
name = "dev_interrupt";
|
|
|
|
break;
|
|
|
|
case EXCP_MMFAULT:
|
|
|
|
name = "mmfault";
|
|
|
|
break;
|
|
|
|
case EXCP_UNALIGN:
|
|
|
|
name = "unalign";
|
|
|
|
break;
|
|
|
|
case EXCP_OPCDEC:
|
|
|
|
name = "opcdec";
|
|
|
|
break;
|
|
|
|
case EXCP_ARITH:
|
|
|
|
name = "arith";
|
|
|
|
break;
|
|
|
|
case EXCP_FEN:
|
|
|
|
name = "fen";
|
|
|
|
break;
|
|
|
|
case EXCP_CALL_PAL:
|
|
|
|
name = "call_pal";
|
|
|
|
break;
|
|
|
|
}
|
2016-11-13 21:41:13 +03:00
|
|
|
qemu_log("INT %6d: %s(%#x) cpu=%d pc=%016"
|
|
|
|
PRIx64 " sp=%016" PRIx64 "\n",
|
|
|
|
++count, name, env->error_code, cs->cpu_index,
|
|
|
|
env->pc, env->ir[IR_SP]);
|
2011-04-19 01:05:35 +04:00
|
|
|
}
|
|
|
|
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = -1;
|
2011-04-19 01:05:35 +04:00
|
|
|
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
switch (i) {
|
|
|
|
case EXCP_RESET:
|
|
|
|
i = 0x0000;
|
|
|
|
break;
|
|
|
|
case EXCP_MCHK:
|
|
|
|
i = 0x0080;
|
|
|
|
break;
|
|
|
|
case EXCP_SMP_INTERRUPT:
|
|
|
|
i = 0x0100;
|
|
|
|
break;
|
|
|
|
case EXCP_CLK_INTERRUPT:
|
|
|
|
i = 0x0180;
|
|
|
|
break;
|
|
|
|
case EXCP_DEV_INTERRUPT:
|
|
|
|
i = 0x0200;
|
|
|
|
break;
|
|
|
|
case EXCP_MMFAULT:
|
|
|
|
i = 0x0280;
|
|
|
|
break;
|
|
|
|
case EXCP_UNALIGN:
|
|
|
|
i = 0x0300;
|
|
|
|
break;
|
|
|
|
case EXCP_OPCDEC:
|
|
|
|
i = 0x0380;
|
|
|
|
break;
|
|
|
|
case EXCP_ARITH:
|
|
|
|
i = 0x0400;
|
|
|
|
break;
|
|
|
|
case EXCP_FEN:
|
|
|
|
i = 0x0480;
|
|
|
|
break;
|
|
|
|
case EXCP_CALL_PAL:
|
|
|
|
i = env->error_code;
|
|
|
|
/* There are 64 entry points for both privileged and unprivileged,
|
|
|
|
with bit 0x80 indicating unprivileged. Each entry point gets
|
|
|
|
64 bytes to do its job. */
|
|
|
|
if (i & 0x80) {
|
|
|
|
i = 0x2000 + (i - 0x80) * 64;
|
|
|
|
} else {
|
|
|
|
i = 0x1000 + i * 64;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2013-09-03 19:38:47 +04:00
|
|
|
cpu_abort(cs, "Unhandled CPU exception");
|
2011-04-19 01:05:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remember where the exception happened. Emulate real hardware in
|
|
|
|
that the low bit of the PC indicates PALmode. */
|
2017-07-06 22:45:07 +03:00
|
|
|
env->exc_addr = env->pc | (env->flags & ENV_FLAG_PAL_MODE);
|
2011-04-19 01:05:35 +04:00
|
|
|
|
|
|
|
/* Continue execution at the PALcode entry point. */
|
|
|
|
env->pc = env->palbr + i;
|
|
|
|
|
|
|
|
/* Switch to PALmode. */
|
2017-07-06 22:45:07 +03:00
|
|
|
env->flags |= ENV_FLAG_PAL_MODE;
|
2011-04-19 01:05:35 +04:00
|
|
|
#endif /* !USER_ONLY */
|
2007-04-05 10:58:33 +04:00
|
|
|
}
|
|
|
|
|
2014-09-13 20:45:22 +04:00
|
|
|
bool alpha_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
|
|
|
|
{
|
|
|
|
AlphaCPU *cpu = ALPHA_CPU(cs);
|
|
|
|
CPUAlphaState *env = &cpu->env;
|
|
|
|
int idx = -1;
|
|
|
|
|
|
|
|
/* We never take interrupts while in PALmode. */
|
2017-07-06 22:45:07 +03:00
|
|
|
if (env->flags & ENV_FLAG_PAL_MODE) {
|
2014-09-13 20:45:22 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fall through the switch, collecting the highest priority
|
|
|
|
interrupt that isn't masked by the processor status IPL. */
|
|
|
|
/* ??? This hard-codes the OSF/1 interrupt levels. */
|
2017-07-06 22:45:07 +03:00
|
|
|
switch ((env->flags >> ENV_FLAG_PS_SHIFT) & PS_INT_MASK) {
|
2014-09-13 20:45:22 +04:00
|
|
|
case 0 ... 3:
|
|
|
|
if (interrupt_request & CPU_INTERRUPT_HARD) {
|
|
|
|
idx = EXCP_DEV_INTERRUPT;
|
|
|
|
}
|
|
|
|
/* FALLTHRU */
|
|
|
|
case 4:
|
|
|
|
if (interrupt_request & CPU_INTERRUPT_TIMER) {
|
|
|
|
idx = EXCP_CLK_INTERRUPT;
|
|
|
|
}
|
|
|
|
/* FALLTHRU */
|
|
|
|
case 5:
|
|
|
|
if (interrupt_request & CPU_INTERRUPT_SMP) {
|
|
|
|
idx = EXCP_SMP_INTERRUPT;
|
|
|
|
}
|
|
|
|
/* FALLTHRU */
|
|
|
|
case 6:
|
|
|
|
if (interrupt_request & CPU_INTERRUPT_MCHK) {
|
|
|
|
idx = EXCP_MCHK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (idx >= 0) {
|
|
|
|
cs->exception_index = idx;
|
|
|
|
env->error_code = 0;
|
|
|
|
alpha_cpu_do_interrupt(cs);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-17 22:18:02 +03:00
|
|
|
void alpha_cpu_dump_state(CPUState *cs, FILE *f, int flags)
|
2007-04-05 10:58:33 +04:00
|
|
|
{
|
2019-04-26 23:33:13 +03:00
|
|
|
static const char linux_reg_names[31][4] = {
|
|
|
|
"v0", "t0", "t1", "t2", "t3", "t4", "t5", "t6",
|
|
|
|
"t7", "s0", "s1", "s2", "s3", "s4", "s5", "fp",
|
|
|
|
"a0", "a1", "a2", "a3", "a4", "a5", "t8", "t9",
|
|
|
|
"t10", "t11", "ra", "t12", "at", "gp", "sp"
|
2007-04-05 10:58:33 +04:00
|
|
|
};
|
2013-05-27 03:33:50 +04:00
|
|
|
AlphaCPU *cpu = ALPHA_CPU(cs);
|
|
|
|
CPUAlphaState *env = &cpu->env;
|
2007-04-05 10:58:33 +04:00
|
|
|
int i;
|
|
|
|
|
2019-04-26 23:33:13 +03:00
|
|
|
qemu_fprintf(f, "PC " TARGET_FMT_lx " PS %02x\n",
|
2019-04-17 22:18:02 +03:00
|
|
|
env->pc, extract32(env->flags, ENV_FLAG_PS_SHIFT, 8));
|
2007-04-05 10:58:33 +04:00
|
|
|
for (i = 0; i < 31; i++) {
|
2019-04-26 23:33:13 +03:00
|
|
|
qemu_fprintf(f, "%-8s" TARGET_FMT_lx "%c",
|
2019-04-17 22:18:02 +03:00
|
|
|
linux_reg_names[i], cpu_alpha_load_gr(env, i),
|
|
|
|
(i % 3) == 2 ? '\n' : ' ');
|
2007-04-05 10:58:33 +04:00
|
|
|
}
|
2010-04-08 02:42:26 +04:00
|
|
|
|
2019-04-26 23:33:13 +03:00
|
|
|
qemu_fprintf(f, "lock_a " TARGET_FMT_lx " lock_v " TARGET_FMT_lx "\n",
|
2019-04-17 22:18:02 +03:00
|
|
|
env->lock_addr, env->lock_value);
|
2010-04-08 02:42:26 +04:00
|
|
|
|
2018-05-11 06:01:46 +03:00
|
|
|
if (flags & CPU_DUMP_FPU) {
|
|
|
|
for (i = 0; i < 31; i++) {
|
2019-04-26 23:33:13 +03:00
|
|
|
qemu_fprintf(f, "f%-7d%016" PRIx64 "%c", i, env->fir[i],
|
2019-04-17 22:18:02 +03:00
|
|
|
(i % 3) == 2 ? '\n' : ' ');
|
2018-05-11 06:01:46 +03:00
|
|
|
}
|
2019-04-26 23:33:13 +03:00
|
|
|
qemu_fprintf(f, "fpcr %016" PRIx64 "\n", cpu_alpha_load_fpcr(env));
|
2007-04-05 10:58:33 +04:00
|
|
|
}
|
2019-04-17 22:18:02 +03:00
|
|
|
qemu_fprintf(f, "\n");
|
2007-04-05 10:58:33 +04:00
|
|
|
}
|
2012-03-24 20:51:08 +04:00
|
|
|
|
|
|
|
/* This should only be called from translate, via gen_excp.
|
|
|
|
We expect that ENV->PC has already been updated. */
|
|
|
|
void QEMU_NORETURN helper_excp(CPUAlphaState *env, int excp, int error)
|
|
|
|
{
|
2019-03-23 03:26:58 +03:00
|
|
|
CPUState *cs = env_cpu(env);
|
2013-08-26 10:31:06 +04:00
|
|
|
|
|
|
|
cs->exception_index = excp;
|
2012-03-24 20:51:08 +04:00
|
|
|
env->error_code = error;
|
2013-08-27 19:52:12 +04:00
|
|
|
cpu_loop_exit(cs);
|
2012-03-24 20:51:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This may be called from any of the helpers to set up EXCEPTION_INDEX. */
|
2012-04-09 18:20:20 +04:00
|
|
|
void QEMU_NORETURN dynamic_excp(CPUAlphaState *env, uintptr_t retaddr,
|
2012-03-24 20:51:08 +04:00
|
|
|
int excp, int error)
|
|
|
|
{
|
2019-03-23 03:26:58 +03:00
|
|
|
CPUState *cs = env_cpu(env);
|
2013-08-26 10:31:06 +04:00
|
|
|
|
|
|
|
cs->exception_index = excp;
|
2012-03-24 20:51:08 +04:00
|
|
|
env->error_code = error;
|
2012-12-05 00:16:07 +04:00
|
|
|
if (retaddr) {
|
2018-04-09 12:13:20 +03:00
|
|
|
cpu_restore_state(cs, retaddr, true);
|
2014-06-29 00:06:19 +04:00
|
|
|
/* Floating-point exceptions (our only users) point to the next PC. */
|
|
|
|
env->pc += 4;
|
2012-12-05 00:16:07 +04:00
|
|
|
}
|
2013-08-27 19:52:12 +04:00
|
|
|
cpu_loop_exit(cs);
|
2012-03-24 20:51:08 +04:00
|
|
|
}
|
|
|
|
|
2012-04-09 18:20:20 +04:00
|
|
|
void QEMU_NORETURN arith_excp(CPUAlphaState *env, uintptr_t retaddr,
|
2012-03-24 20:51:08 +04:00
|
|
|
int exc, uint64_t mask)
|
|
|
|
{
|
|
|
|
env->trap_arg0 = exc;
|
|
|
|
env->trap_arg1 = mask;
|
|
|
|
dynamic_excp(env, retaddr, EXCP_ARITH, 0);
|
|
|
|
}
|