2007-04-05 06:58:33 +00:00
|
|
|
/*
|
2012-03-24 16:51:13 +00:00
|
|
|
* Helpers for loads and stores
|
2007-09-16 21:08:06 +00:00
|
|
|
*
|
2007-04-05 06:58:33 +00: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
|
|
|
|
* 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-16 20:47:01 +00:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2007-04-05 06:58:33 +00:00
|
|
|
*/
|
|
|
|
|
2016-01-26 18:17:04 +00:00
|
|
|
#include "qemu/osdep.h"
|
2011-07-13 12:44:15 +00:00
|
|
|
#include "cpu.h"
|
2014-04-08 05:31:41 +00:00
|
|
|
#include "exec/helper-proto.h"
|
2016-03-15 12:18:37 +00:00
|
|
|
#include "exec/exec-all.h"
|
2014-03-28 18:42:10 +00:00
|
|
|
#include "exec/cpu_ldst.h"
|
2007-04-05 06:58:33 +00:00
|
|
|
|
|
|
|
/* Softmmu support */
|
2012-03-24 16:51:13 +00:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
|
2013-11-15 13:46:38 +00:00
|
|
|
uint64_t helper_ldl_phys(CPUAlphaState *env, uint64_t p)
|
2008-09-30 06:45:44 +00:00
|
|
|
{
|
2014-03-09 17:58:57 +00:00
|
|
|
CPUState *cs = CPU(alpha_env_get_cpu(env));
|
2013-11-15 13:46:38 +00:00
|
|
|
return (int32_t)ldl_phys(cs->as, p);
|
2008-09-30 06:45:44 +00:00
|
|
|
}
|
|
|
|
|
2013-12-17 04:05:40 +00:00
|
|
|
uint64_t helper_ldq_phys(CPUAlphaState *env, uint64_t p)
|
2008-09-30 06:45:44 +00:00
|
|
|
{
|
2014-03-09 17:58:57 +00:00
|
|
|
CPUState *cs = CPU(alpha_env_get_cpu(env));
|
2013-12-17 04:05:40 +00:00
|
|
|
return ldq_phys(cs->as, p);
|
2008-09-30 06:45:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 16:51:13 +00:00
|
|
|
uint64_t helper_ldl_l_phys(CPUAlphaState *env, uint64_t p)
|
2008-09-30 06:45:44 +00:00
|
|
|
{
|
2014-03-09 17:58:57 +00:00
|
|
|
CPUState *cs = CPU(alpha_env_get_cpu(env));
|
2011-05-20 20:04:35 +00:00
|
|
|
env->lock_addr = p;
|
2013-11-15 13:46:38 +00:00
|
|
|
return env->lock_value = (int32_t)ldl_phys(cs->as, p);
|
2008-09-30 06:45:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 16:51:13 +00:00
|
|
|
uint64_t helper_ldq_l_phys(CPUAlphaState *env, uint64_t p)
|
2008-09-30 06:45:44 +00:00
|
|
|
{
|
2014-03-09 17:58:57 +00:00
|
|
|
CPUState *cs = CPU(alpha_env_get_cpu(env));
|
2011-05-20 20:04:35 +00:00
|
|
|
env->lock_addr = p;
|
2013-12-17 04:05:40 +00:00
|
|
|
return env->lock_value = ldq_phys(cs->as, p);
|
2008-09-30 06:45:44 +00:00
|
|
|
}
|
|
|
|
|
2013-12-17 05:07:29 +00:00
|
|
|
void helper_stl_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
|
2008-09-30 06:45:44 +00:00
|
|
|
{
|
2014-03-09 17:58:57 +00:00
|
|
|
CPUState *cs = CPU(alpha_env_get_cpu(env));
|
2013-12-17 05:07:29 +00:00
|
|
|
stl_phys(cs->as, p, v);
|
2008-09-30 06:45:44 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 23:11:44 +00:00
|
|
|
void helper_stq_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
|
2008-09-30 06:45:44 +00:00
|
|
|
{
|
2014-03-09 17:58:57 +00:00
|
|
|
CPUState *cs = CPU(alpha_env_get_cpu(env));
|
2013-11-27 23:11:44 +00:00
|
|
|
stq_phys(cs->as, p, v);
|
2008-09-30 06:45:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 16:51:13 +00:00
|
|
|
uint64_t helper_stl_c_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
|
2008-09-30 06:45:44 +00:00
|
|
|
{
|
2014-03-09 17:58:57 +00:00
|
|
|
CPUState *cs = CPU(alpha_env_get_cpu(env));
|
2011-05-20 20:04:35 +00:00
|
|
|
uint64_t ret = 0;
|
2008-09-30 06:45:44 +00:00
|
|
|
|
2011-05-20 20:04:35 +00:00
|
|
|
if (p == env->lock_addr) {
|
2013-11-15 13:46:38 +00:00
|
|
|
int32_t old = ldl_phys(cs->as, p);
|
2011-05-20 20:04:35 +00:00
|
|
|
if (old == (int32_t)env->lock_value) {
|
2013-12-17 05:07:29 +00:00
|
|
|
stl_phys(cs->as, p, v);
|
2011-05-20 20:04:35 +00:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
env->lock_addr = -1;
|
2008-09-30 06:45:44 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-03-24 16:51:13 +00:00
|
|
|
uint64_t helper_stq_c_phys(CPUAlphaState *env, uint64_t p, uint64_t v)
|
2008-09-30 06:45:44 +00:00
|
|
|
{
|
2014-03-09 17:58:57 +00:00
|
|
|
CPUState *cs = CPU(alpha_env_get_cpu(env));
|
2011-05-20 20:04:35 +00:00
|
|
|
uint64_t ret = 0;
|
2008-09-30 06:45:44 +00:00
|
|
|
|
2011-05-20 20:04:35 +00:00
|
|
|
if (p == env->lock_addr) {
|
2013-12-17 04:05:40 +00:00
|
|
|
uint64_t old = ldq_phys(cs->as, p);
|
2011-05-20 20:04:35 +00:00
|
|
|
if (old == env->lock_value) {
|
2013-11-27 23:11:44 +00:00
|
|
|
stq_phys(cs->as, p, v);
|
2011-05-20 20:04:35 +00:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
env->lock_addr = -1;
|
2008-09-30 06:45:44 +00:00
|
|
|
|
|
|
|
return ret;
|
2007-04-05 06:58:33 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 17:14:58 +00:00
|
|
|
void alpha_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
|
2016-06-14 12:26:17 +00:00
|
|
|
MMUAccessType access_type,
|
|
|
|
int mmu_idx, uintptr_t retaddr)
|
2011-04-18 23:13:12 +00:00
|
|
|
{
|
2014-03-28 17:14:58 +00:00
|
|
|
AlphaCPU *cpu = ALPHA_CPU(cs);
|
|
|
|
CPUAlphaState *env = &cpu->env;
|
2011-04-18 23:13:12 +00:00
|
|
|
uint64_t pc;
|
|
|
|
uint32_t insn;
|
|
|
|
|
2012-12-04 20:16:07 +00:00
|
|
|
if (retaddr) {
|
2013-09-01 14:51:34 +00:00
|
|
|
cpu_restore_state(cs, retaddr);
|
2012-12-04 20:16:07 +00:00
|
|
|
}
|
2011-04-18 23:13:12 +00:00
|
|
|
|
|
|
|
pc = env->pc;
|
2012-03-24 16:51:13 +00:00
|
|
|
insn = cpu_ldl_code(env, pc);
|
2011-04-18 23:13:12 +00:00
|
|
|
|
|
|
|
env->trap_arg0 = addr;
|
|
|
|
env->trap_arg1 = insn >> 26; /* opcode */
|
|
|
|
env->trap_arg2 = (insn >> 21) & 31; /* dest regno */
|
2013-08-26 06:31:06 +00:00
|
|
|
cs->exception_index = EXCP_UNALIGN;
|
2012-03-24 16:51:08 +00:00
|
|
|
env->error_code = 0;
|
2013-08-27 15:52:12 +00:00
|
|
|
cpu_loop_exit(cs);
|
2011-04-18 23:13:12 +00:00
|
|
|
}
|
|
|
|
|
2013-05-27 04:49:53 +00:00
|
|
|
void alpha_cpu_unassigned_access(CPUState *cs, hwaddr addr,
|
|
|
|
bool is_write, bool is_exec, int unused,
|
|
|
|
unsigned size)
|
2011-04-18 23:13:12 +00:00
|
|
|
{
|
2013-05-27 04:49:53 +00:00
|
|
|
AlphaCPU *cpu = ALPHA_CPU(cs);
|
|
|
|
CPUAlphaState *env = &cpu->env;
|
|
|
|
|
2011-04-18 23:13:12 +00:00
|
|
|
env->trap_arg0 = addr;
|
2013-05-27 04:49:53 +00:00
|
|
|
env->trap_arg1 = is_write ? 1 : 0;
|
2014-06-28 20:06:19 +00:00
|
|
|
cs->exception_index = EXCP_MCHK;
|
|
|
|
env->error_code = 0;
|
|
|
|
|
|
|
|
/* ??? We should cpu_restore_state to the faulting insn, but this hook
|
2015-09-08 21:45:14 +00:00
|
|
|
does not have access to the retaddr value from the original helper.
|
2014-06-28 20:06:19 +00:00
|
|
|
It's all moot until the QEMU PALcode grows an MCHK handler. */
|
|
|
|
|
|
|
|
cpu_loop_exit(cs);
|
2011-04-18 23:13:12 +00:00
|
|
|
}
|
|
|
|
|
2007-04-05 06:58:33 +00:00
|
|
|
/* try to fill the TLB and return an exception if error. If retaddr is
|
|
|
|
NULL, it means that the function was called in C code (i.e. not
|
|
|
|
from generated code or from helper.c) */
|
|
|
|
/* XXX: fix it to restore all registers */
|
2016-06-14 12:26:17 +00:00
|
|
|
void tlb_fill(CPUState *cs, target_ulong addr, MMUAccessType access_type,
|
2012-04-09 14:20:20 +00:00
|
|
|
int mmu_idx, uintptr_t retaddr)
|
2007-04-05 06:58:33 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2016-06-14 12:26:17 +00:00
|
|
|
ret = alpha_cpu_handle_mmu_fault(cs, addr, access_type, mmu_idx);
|
2011-04-25 19:20:27 +00:00
|
|
|
if (unlikely(ret != 0)) {
|
2012-12-04 20:16:07 +00:00
|
|
|
if (retaddr) {
|
2013-09-01 14:51:34 +00:00
|
|
|
cpu_restore_state(cs, retaddr);
|
2012-12-04 20:16:07 +00:00
|
|
|
}
|
2007-04-05 06:58:33 +00:00
|
|
|
/* Exception index and error code are already set */
|
2013-08-27 15:52:12 +00:00
|
|
|
cpu_loop_exit(cs);
|
2007-04-05 06:58:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 16:51:13 +00:00
|
|
|
#endif /* CONFIG_USER_ONLY */
|