2007-10-08 21:04:02 +08:00
|
|
|
/*
|
|
|
|
* CRIS helper routines
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 AXIS Communications
|
|
|
|
* Written by Edgar E. Iglesias
|
|
|
|
*
|
|
|
|
* 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 04:47:01 +08:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2007-10-08 21:04:02 +08:00
|
|
|
*/
|
|
|
|
|
2011-07-13 20:44:15 +08:00
|
|
|
#include "cpu.h"
|
2008-03-14 09:08:09 +08:00
|
|
|
#include "mmu.h"
|
2014-04-08 13:31:41 +08:00
|
|
|
#include "exec/helper-proto.h"
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/host-utils.h"
|
2014-03-29 02:42:10 +08:00
|
|
|
#include "exec/cpu_ldst.h"
|
2007-10-08 21:04:02 +08:00
|
|
|
|
2009-01-16 05:48:06 +08:00
|
|
|
//#define CRIS_OP_HELPER_DEBUG
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CRIS_OP_HELPER_DEBUG
|
|
|
|
#define D(x) x
|
2013-01-24 17:51:47 +08:00
|
|
|
#define D_LOG(...) qemu_log(__VA_ARGS__)
|
2009-01-16 05:48:06 +08:00
|
|
|
#else
|
2008-06-08 09:09:01 +08:00
|
|
|
#define D(x)
|
2009-01-16 05:48:06 +08:00
|
|
|
#define D_LOG(...) do { } while (0)
|
|
|
|
#endif
|
2008-06-08 09:09:01 +08:00
|
|
|
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2007-10-08 21:04:02 +08: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) */
|
2013-08-27 06:28:06 +08:00
|
|
|
void tlb_fill(CPUState *cs, target_ulong addr, int is_write, int mmu_idx,
|
2012-04-09 22:20:20 +08:00
|
|
|
uintptr_t retaddr)
|
2007-10-08 21:04:02 +08:00
|
|
|
{
|
2013-08-27 06:28:06 +08:00
|
|
|
CRISCPU *cpu = CRIS_CPU(cs);
|
|
|
|
CPUCRISState *env = &cpu->env;
|
2007-10-08 21:04:02 +08:00
|
|
|
int ret;
|
|
|
|
|
2012-04-09 22:20:20 +08:00
|
|
|
D_LOG("%s pc=%x tpc=%x ra=%p\n", __func__,
|
2013-01-27 14:26:05 +08:00
|
|
|
env->pc, env->pregs[PR_EDA], (void *)retaddr);
|
2013-08-27 06:28:06 +08:00
|
|
|
ret = cris_cpu_handle_mmu_fault(cs, addr, is_write, mmu_idx);
|
2008-07-04 01:57:36 +08:00
|
|
|
if (unlikely(ret)) {
|
2007-10-08 21:04:02 +08:00
|
|
|
if (retaddr) {
|
|
|
|
/* now we have a real cpu fault */
|
2013-09-01 22:51:34 +08:00
|
|
|
if (cpu_restore_state(cs, retaddr)) {
|
2008-05-28 05:10:56 +08:00
|
|
|
/* Evaluate flags after retranslation. */
|
2012-08-30 22:56:39 +08:00
|
|
|
helper_top_evaluate_flags(env);
|
2007-10-08 21:04:02 +08:00
|
|
|
}
|
|
|
|
}
|
2013-08-27 23:52:12 +08:00
|
|
|
cpu_loop_exit(cs);
|
2007-10-08 21:04:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-08 09:09:01 +08:00
|
|
|
#endif
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
void helper_raise_exception(CPUCRISState *env, uint32_t index)
|
2008-03-14 09:08:09 +08:00
|
|
|
{
|
2013-08-26 14:31:06 +08:00
|
|
|
CPUState *cs = CPU(cris_env_get_cpu(env));
|
|
|
|
|
|
|
|
cs->exception_index = index;
|
2013-08-27 23:52:12 +08:00
|
|
|
cpu_loop_exit(cs);
|
2008-03-14 09:08:09 +08:00
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
void helper_tlb_flush_pid(CPUCRISState *env, uint32_t pid)
|
2008-05-13 18:59:14 +08:00
|
|
|
{
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2008-09-23 04:51:28 +08:00
|
|
|
pid &= 0xff;
|
|
|
|
if (pid != (env->pregs[PR_PID] & 0xff))
|
|
|
|
cris_mmu_flush_pid(env, env->pregs[PR_PID]);
|
2008-05-13 18:59:14 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
void helper_spc_write(CPUCRISState *env, uint32_t new_spc)
|
2008-10-08 06:48:41 +08:00
|
|
|
{
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2013-09-04 07:29:02 +08:00
|
|
|
CRISCPU *cpu = cris_env_get_cpu(env);
|
|
|
|
CPUState *cs = CPU(cpu);
|
|
|
|
|
|
|
|
tlb_flush_page(cs, env->pregs[PR_SPC]);
|
|
|
|
tlb_flush_page(cs, new_spc);
|
2008-10-08 06:48:41 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-05-28 05:10:56 +08:00
|
|
|
void helper_dump(uint32_t a0, uint32_t a1, uint32_t a2)
|
2008-05-03 06:16:17 +08:00
|
|
|
{
|
2009-01-16 06:34:14 +08:00
|
|
|
qemu_log("%s: a0=%x a1=%x\n", __func__, a0, a1);
|
2008-05-03 06:16:17 +08:00
|
|
|
}
|
|
|
|
|
2008-05-13 18:59:14 +08:00
|
|
|
/* Used by the tlb decoder. */
|
|
|
|
#define EXTRACT_FIELD(src, start, end) \
|
|
|
|
(((src) >> start) & ((1 << (end - start + 1)) - 1))
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
void helper_movl_sreg_reg(CPUCRISState *env, uint32_t sreg, uint32_t reg)
|
2008-05-07 23:24:53 +08:00
|
|
|
{
|
2013-09-04 07:29:02 +08:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
CRISCPU *cpu = cris_env_get_cpu(env);
|
|
|
|
#endif
|
2008-05-07 23:24:53 +08:00
|
|
|
uint32_t srs;
|
|
|
|
srs = env->pregs[PR_SRS];
|
|
|
|
srs &= 3;
|
|
|
|
env->sregs[srs][sreg] = env->regs[reg];
|
|
|
|
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
if (srs == 1 || srs == 2) {
|
|
|
|
if (sreg == 6) {
|
|
|
|
/* Writes to tlb-hi write to mm_cause as a side
|
|
|
|
effect. */
|
2008-06-30 23:27:47 +08:00
|
|
|
env->sregs[SFR_RW_MM_TLB_HI] = env->regs[reg];
|
|
|
|
env->sregs[SFR_R_MM_CAUSE] = env->regs[reg];
|
2008-05-07 23:24:53 +08:00
|
|
|
}
|
|
|
|
else if (sreg == 5) {
|
|
|
|
uint32_t set;
|
|
|
|
uint32_t idx;
|
|
|
|
uint32_t lo, hi;
|
|
|
|
uint32_t vaddr;
|
2008-05-13 18:59:14 +08:00
|
|
|
int tlb_v;
|
2008-05-07 23:24:53 +08:00
|
|
|
|
|
|
|
idx = set = env->sregs[SFR_RW_MM_TLB_SEL];
|
|
|
|
set >>= 4;
|
|
|
|
set &= 3;
|
|
|
|
|
|
|
|
idx &= 15;
|
|
|
|
/* We've just made a write to tlb_lo. */
|
|
|
|
lo = env->sregs[SFR_RW_MM_TLB_LO];
|
|
|
|
/* Writes are done via r_mm_cause. */
|
|
|
|
hi = env->sregs[SFR_R_MM_CAUSE];
|
2008-05-13 18:59:14 +08:00
|
|
|
|
|
|
|
vaddr = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].hi,
|
|
|
|
13, 31);
|
|
|
|
vaddr <<= TARGET_PAGE_BITS;
|
|
|
|
tlb_v = EXTRACT_FIELD(env->tlbsets[srs-1][set][idx].lo,
|
|
|
|
3, 3);
|
2008-05-07 23:24:53 +08:00
|
|
|
env->tlbsets[srs - 1][set][idx].lo = lo;
|
|
|
|
env->tlbsets[srs - 1][set][idx].hi = hi;
|
2008-05-13 18:59:14 +08:00
|
|
|
|
2009-01-16 05:48:06 +08:00
|
|
|
D_LOG("tlb flush vaddr=%x v=%d pc=%x\n",
|
|
|
|
vaddr, tlb_v, env->pc);
|
2010-10-08 03:20:52 +08:00
|
|
|
if (tlb_v) {
|
2013-09-04 07:29:02 +08:00
|
|
|
tlb_flush_page(CPU(cpu), vaddr);
|
2010-10-08 03:20:52 +08:00
|
|
|
}
|
2008-05-07 23:24:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
void helper_movl_reg_sreg(CPUCRISState *env, uint32_t reg, uint32_t sreg)
|
2008-05-07 23:24:53 +08:00
|
|
|
{
|
|
|
|
uint32_t srs;
|
|
|
|
env->pregs[PR_SRS] &= 3;
|
|
|
|
srs = env->pregs[PR_SRS];
|
|
|
|
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
if (srs == 1 || srs == 2)
|
|
|
|
{
|
|
|
|
uint32_t set;
|
|
|
|
uint32_t idx;
|
|
|
|
uint32_t lo, hi;
|
|
|
|
|
|
|
|
idx = set = env->sregs[SFR_RW_MM_TLB_SEL];
|
|
|
|
set >>= 4;
|
|
|
|
set &= 3;
|
|
|
|
idx &= 15;
|
|
|
|
|
|
|
|
/* Update the mirror regs. */
|
|
|
|
hi = env->tlbsets[srs - 1][set][idx].hi;
|
|
|
|
lo = env->tlbsets[srs - 1][set][idx].lo;
|
|
|
|
env->sregs[SFR_RW_MM_TLB_HI] = hi;
|
|
|
|
env->sregs[SFR_RW_MM_TLB_LO] = lo;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
env->regs[reg] = env->sregs[srs][sreg];
|
|
|
|
}
|
|
|
|
|
2012-03-14 08:38:21 +08:00
|
|
|
static void cris_ccs_rshift(CPUCRISState *env)
|
2008-05-07 23:24:53 +08:00
|
|
|
{
|
|
|
|
uint32_t ccs;
|
|
|
|
|
|
|
|
/* Apply the ccs shift. */
|
|
|
|
ccs = env->pregs[PR_CCS];
|
|
|
|
ccs = (ccs & 0xc0000000) | ((ccs & 0x0fffffff) >> 10);
|
|
|
|
if (ccs & U_FLAG)
|
|
|
|
{
|
|
|
|
/* Enter user mode. */
|
|
|
|
env->ksp = env->regs[R_SP];
|
|
|
|
env->regs[R_SP] = env->pregs[PR_USP];
|
|
|
|
}
|
|
|
|
|
|
|
|
env->pregs[PR_CCS] = ccs;
|
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
void helper_rfe(CPUCRISState *env)
|
2008-05-03 06:16:17 +08:00
|
|
|
{
|
2008-06-06 19:17:17 +08:00
|
|
|
int rflag = env->pregs[PR_CCS] & R_FLAG;
|
|
|
|
|
2009-01-16 05:48:06 +08:00
|
|
|
D_LOG("rfe: erp=%x pid=%x ccs=%x btarget=%x\n",
|
2008-05-03 06:16:17 +08:00
|
|
|
env->pregs[PR_ERP], env->pregs[PR_PID],
|
|
|
|
env->pregs[PR_CCS],
|
2009-01-16 05:48:06 +08:00
|
|
|
env->btarget);
|
2008-05-07 23:24:53 +08:00
|
|
|
|
|
|
|
cris_ccs_rshift(env);
|
|
|
|
|
|
|
|
/* RFE sets the P_FLAG only if the R_FLAG is not set. */
|
2008-06-06 19:17:17 +08:00
|
|
|
if (!rflag)
|
2008-05-07 23:24:53 +08:00
|
|
|
env->pregs[PR_CCS] |= P_FLAG;
|
2008-05-03 06:16:17 +08:00
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
void helper_rfn(CPUCRISState *env)
|
2008-06-10 07:07:50 +08:00
|
|
|
{
|
|
|
|
int rflag = env->pregs[PR_CCS] & R_FLAG;
|
|
|
|
|
2009-01-16 05:48:06 +08:00
|
|
|
D_LOG("rfn: erp=%x pid=%x ccs=%x btarget=%x\n",
|
2008-06-10 07:07:50 +08:00
|
|
|
env->pregs[PR_ERP], env->pregs[PR_PID],
|
|
|
|
env->pregs[PR_CCS],
|
2009-01-16 05:48:06 +08:00
|
|
|
env->btarget);
|
2008-06-10 07:07:50 +08:00
|
|
|
|
|
|
|
cris_ccs_rshift(env);
|
|
|
|
|
|
|
|
/* Set the P_FLAG only if the R_FLAG is not set. */
|
|
|
|
if (!rflag)
|
|
|
|
env->pregs[PR_CCS] |= P_FLAG;
|
|
|
|
|
2012-06-14 22:23:55 +08:00
|
|
|
/* Always set the M flag. */
|
|
|
|
env->pregs[PR_CCS] |= M_FLAG_V32;
|
2008-06-10 07:07:50 +08:00
|
|
|
}
|
|
|
|
|
2009-01-07 21:19:21 +08:00
|
|
|
uint32_t helper_lz(uint32_t t0)
|
|
|
|
{
|
|
|
|
return clz32(t0);
|
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
uint32_t helper_btst(CPUCRISState *env, uint32_t t0, uint32_t t1, uint32_t ccs)
|
2009-01-07 21:11:22 +08:00
|
|
|
{
|
|
|
|
/* FIXME: clean this up. */
|
|
|
|
|
|
|
|
/* des ref:
|
|
|
|
The N flag is set according to the selected bit in the dest reg.
|
|
|
|
The Z flag is set if the selected bit and all bits to the right are
|
|
|
|
zero.
|
|
|
|
The X flag is cleared.
|
|
|
|
Other flags are left untouched.
|
|
|
|
The destination reg is not affected.*/
|
|
|
|
unsigned int fz, sbit, bset, mask, masked_t0;
|
|
|
|
|
|
|
|
sbit = t1 & 31;
|
|
|
|
bset = !!(t0 & (1 << sbit));
|
|
|
|
mask = sbit == 31 ? -1 : (1 << (sbit + 1)) - 1;
|
|
|
|
masked_t0 = t0 & mask;
|
|
|
|
fz = !(masked_t0 | bset);
|
|
|
|
|
|
|
|
/* Clear the X, N and Z flags. */
|
|
|
|
ccs = ccs & ~(X_FLAG | N_FLAG | Z_FLAG);
|
2010-02-15 18:20:30 +08:00
|
|
|
if (env->pregs[PR_VR] < 32)
|
|
|
|
ccs &= ~(V_FLAG | C_FLAG);
|
2009-01-07 21:11:22 +08:00
|
|
|
/* Set the N and Z flags accordingly. */
|
|
|
|
ccs |= (bset << 3) | (fz << 2);
|
|
|
|
return ccs;
|
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
static inline uint32_t evaluate_flags_writeback(CPUCRISState *env,
|
|
|
|
uint32_t flags, uint32_t ccs)
|
2008-05-03 06:16:17 +08:00
|
|
|
{
|
2009-01-07 20:25:15 +08:00
|
|
|
unsigned int x, z, mask;
|
2008-05-03 06:16:17 +08:00
|
|
|
|
|
|
|
/* Extended arithmetics, leave the z flag alone. */
|
2008-05-28 05:10:56 +08:00
|
|
|
x = env->cc_x;
|
2009-01-07 20:25:15 +08:00
|
|
|
mask = env->cc_mask | X_FLAG;
|
|
|
|
if (x) {
|
|
|
|
z = flags & Z_FLAG;
|
|
|
|
mask = mask & ~z;
|
|
|
|
}
|
|
|
|
flags &= mask;
|
2008-05-03 06:16:17 +08:00
|
|
|
|
|
|
|
/* all insn clear the x-flag except setf or clrf. */
|
2009-01-08 07:38:41 +08:00
|
|
|
ccs &= ~mask;
|
|
|
|
ccs |= flags;
|
|
|
|
return ccs;
|
2008-05-03 06:16:17 +08:00
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
uint32_t helper_evaluate_flags_muls(CPUCRISState *env,
|
|
|
|
uint32_t ccs, uint32_t res, uint32_t mof)
|
2008-05-03 06:16:17 +08:00
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
2008-05-07 23:24:53 +08:00
|
|
|
int64_t tmp;
|
2008-05-03 06:16:17 +08:00
|
|
|
int dneg;
|
|
|
|
|
|
|
|
dneg = ((int32_t)res) < 0;
|
|
|
|
|
2008-05-07 23:24:53 +08:00
|
|
|
tmp = mof;
|
|
|
|
tmp <<= 32;
|
|
|
|
tmp |= res;
|
2008-05-03 06:16:17 +08:00
|
|
|
if (tmp == 0)
|
|
|
|
flags |= Z_FLAG;
|
|
|
|
else if (tmp < 0)
|
|
|
|
flags |= N_FLAG;
|
|
|
|
if ((dneg && mof != -1)
|
|
|
|
|| (!dneg && mof != 0))
|
|
|
|
flags |= V_FLAG;
|
2012-08-30 22:56:39 +08:00
|
|
|
return evaluate_flags_writeback(env, flags, ccs);
|
2008-05-03 06:16:17 +08:00
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
uint32_t helper_evaluate_flags_mulu(CPUCRISState *env,
|
|
|
|
uint32_t ccs, uint32_t res, uint32_t mof)
|
2008-05-03 06:16:17 +08:00
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
2008-05-07 23:24:53 +08:00
|
|
|
uint64_t tmp;
|
2008-05-03 06:16:17 +08:00
|
|
|
|
2008-05-07 23:24:53 +08:00
|
|
|
tmp = mof;
|
|
|
|
tmp <<= 32;
|
|
|
|
tmp |= res;
|
2008-05-03 06:16:17 +08:00
|
|
|
if (tmp == 0)
|
|
|
|
flags |= Z_FLAG;
|
|
|
|
else if (tmp >> 63)
|
|
|
|
flags |= N_FLAG;
|
|
|
|
if (mof)
|
|
|
|
flags |= V_FLAG;
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
return evaluate_flags_writeback(env, flags, ccs);
|
2008-05-03 06:16:17 +08:00
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
uint32_t helper_evaluate_flags_mcp(CPUCRISState *env, uint32_t ccs,
|
2009-01-08 07:38:41 +08:00
|
|
|
uint32_t src, uint32_t dst, uint32_t res)
|
2008-05-03 06:16:17 +08:00
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
|
|
|
|
2009-01-08 07:38:41 +08:00
|
|
|
src = src & 0x80000000;
|
|
|
|
dst = dst & 0x80000000;
|
2008-05-03 06:16:17 +08:00
|
|
|
|
|
|
|
if ((res & 0x80000000L) != 0L)
|
|
|
|
{
|
|
|
|
flags |= N_FLAG;
|
2009-01-07 20:25:15 +08:00
|
|
|
if (!src && !dst)
|
2008-05-03 06:16:17 +08:00
|
|
|
flags |= V_FLAG;
|
2009-01-07 20:25:15 +08:00
|
|
|
else if (src & dst)
|
2008-05-03 06:16:17 +08:00
|
|
|
flags |= R_FLAG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (res == 0L)
|
|
|
|
flags |= Z_FLAG;
|
2009-01-07 20:25:15 +08:00
|
|
|
if (src & dst)
|
2008-05-03 06:16:17 +08:00
|
|
|
flags |= V_FLAG;
|
2009-01-07 20:25:15 +08:00
|
|
|
if (dst | src)
|
2008-05-03 06:16:17 +08:00
|
|
|
flags |= R_FLAG;
|
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
return evaluate_flags_writeback(env, flags, ccs);
|
2008-05-03 06:16:17 +08:00
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
uint32_t helper_evaluate_flags_alu_4(CPUCRISState *env, uint32_t ccs,
|
2009-01-08 07:38:41 +08:00
|
|
|
uint32_t src, uint32_t dst, uint32_t res)
|
2008-05-03 06:16:17 +08:00
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
|
|
|
|
2009-01-08 07:38:41 +08:00
|
|
|
src = src & 0x80000000;
|
|
|
|
dst = dst & 0x80000000;
|
2008-05-28 05:10:56 +08:00
|
|
|
|
2009-01-07 20:25:15 +08:00
|
|
|
if ((res & 0x80000000L) != 0L)
|
2008-05-28 05:10:56 +08:00
|
|
|
{
|
2009-01-07 20:25:15 +08:00
|
|
|
flags |= N_FLAG;
|
|
|
|
if (!src && !dst)
|
|
|
|
flags |= V_FLAG;
|
|
|
|
else if (src & dst)
|
|
|
|
flags |= C_FLAG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (res == 0L)
|
|
|
|
flags |= Z_FLAG;
|
|
|
|
if (src & dst)
|
|
|
|
flags |= V_FLAG;
|
|
|
|
if (dst | src)
|
|
|
|
flags |= C_FLAG;
|
2008-05-28 05:10:56 +08:00
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
return evaluate_flags_writeback(env, flags, ccs);
|
2009-01-07 20:25:15 +08:00
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
uint32_t helper_evaluate_flags_sub_4(CPUCRISState *env, uint32_t ccs,
|
2009-01-08 07:38:41 +08:00
|
|
|
uint32_t src, uint32_t dst, uint32_t res)
|
2009-01-07 20:25:15 +08:00
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
|
|
|
|
2009-01-08 07:38:41 +08:00
|
|
|
src = (~src) & 0x80000000;
|
|
|
|
dst = dst & 0x80000000;
|
2008-05-03 06:16:17 +08:00
|
|
|
|
|
|
|
if ((res & 0x80000000L) != 0L)
|
|
|
|
{
|
|
|
|
flags |= N_FLAG;
|
2009-01-07 20:25:15 +08:00
|
|
|
if (!src && !dst)
|
2008-05-03 06:16:17 +08:00
|
|
|
flags |= V_FLAG;
|
2009-01-07 20:25:15 +08:00
|
|
|
else if (src & dst)
|
2008-05-03 06:16:17 +08:00
|
|
|
flags |= C_FLAG;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (res == 0L)
|
|
|
|
flags |= Z_FLAG;
|
2009-01-07 20:25:15 +08:00
|
|
|
if (src & dst)
|
2008-05-03 06:16:17 +08:00
|
|
|
flags |= V_FLAG;
|
2009-01-07 20:25:15 +08:00
|
|
|
if (dst | src)
|
2008-05-03 06:16:17 +08:00
|
|
|
flags |= C_FLAG;
|
|
|
|
}
|
|
|
|
|
2009-01-07 20:25:15 +08:00
|
|
|
flags ^= C_FLAG;
|
2012-08-30 22:56:39 +08:00
|
|
|
return evaluate_flags_writeback(env, flags, ccs);
|
2008-05-03 06:16:17 +08:00
|
|
|
}
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
uint32_t helper_evaluate_flags_move_4(CPUCRISState *env,
|
|
|
|
uint32_t ccs, uint32_t res)
|
2008-05-03 06:16:17 +08:00
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
|
|
|
|
|
|
|
if ((int32_t)res < 0)
|
|
|
|
flags |= N_FLAG;
|
|
|
|
else if (res == 0L)
|
|
|
|
flags |= Z_FLAG;
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
return evaluate_flags_writeback(env, flags, ccs);
|
2008-05-03 06:16:17 +08:00
|
|
|
}
|
2012-08-30 22:56:39 +08:00
|
|
|
uint32_t helper_evaluate_flags_move_2(CPUCRISState *env,
|
|
|
|
uint32_t ccs, uint32_t res)
|
2008-05-03 06:16:17 +08:00
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
|
|
|
|
|
|
|
if ((int16_t)res < 0L)
|
|
|
|
flags |= N_FLAG;
|
|
|
|
else if (res == 0)
|
|
|
|
flags |= Z_FLAG;
|
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
return evaluate_flags_writeback(env, flags, ccs);
|
2008-05-03 06:16:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: This is expensive. We could split things up and only evaluate part of
|
|
|
|
CCR on a need to know basis. For now, we simply re-evaluate everything. */
|
2012-08-30 22:56:39 +08:00
|
|
|
void helper_evaluate_flags(CPUCRISState *env)
|
2008-05-03 06:16:17 +08:00
|
|
|
{
|
2009-01-08 07:38:41 +08:00
|
|
|
uint32_t src, dst, res;
|
2008-05-03 06:16:17 +08:00
|
|
|
uint32_t flags = 0;
|
|
|
|
|
|
|
|
src = env->cc_src;
|
|
|
|
dst = env->cc_dest;
|
|
|
|
res = env->cc_result;
|
|
|
|
|
2008-05-28 05:10:56 +08:00
|
|
|
if (env->cc_op == CC_OP_SUB || env->cc_op == CC_OP_CMP)
|
|
|
|
src = ~src;
|
2008-05-03 06:16:17 +08:00
|
|
|
|
|
|
|
/* Now, evaluate the flags. This stuff is based on
|
|
|
|
Per Zander's CRISv10 simulator. */
|
|
|
|
switch (env->cc_size)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
if ((res & 0x80L) != 0L)
|
|
|
|
{
|
|
|
|
flags |= N_FLAG;
|
|
|
|
if (((src & 0x80L) == 0L)
|
|
|
|
&& ((dst & 0x80L) == 0L))
|
|
|
|
{
|
|
|
|
flags |= V_FLAG;
|
|
|
|
}
|
|
|
|
else if (((src & 0x80L) != 0L)
|
|
|
|
&& ((dst & 0x80L) != 0L))
|
|
|
|
{
|
|
|
|
flags |= C_FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((res & 0xFFL) == 0L)
|
|
|
|
{
|
|
|
|
flags |= Z_FLAG;
|
|
|
|
}
|
|
|
|
if (((src & 0x80L) != 0L)
|
|
|
|
&& ((dst & 0x80L) != 0L))
|
|
|
|
{
|
|
|
|
flags |= V_FLAG;
|
|
|
|
}
|
|
|
|
if ((dst & 0x80L) != 0L
|
|
|
|
|| (src & 0x80L) != 0L)
|
|
|
|
{
|
|
|
|
flags |= C_FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if ((res & 0x8000L) != 0L)
|
|
|
|
{
|
|
|
|
flags |= N_FLAG;
|
|
|
|
if (((src & 0x8000L) == 0L)
|
|
|
|
&& ((dst & 0x8000L) == 0L))
|
|
|
|
{
|
|
|
|
flags |= V_FLAG;
|
|
|
|
}
|
|
|
|
else if (((src & 0x8000L) != 0L)
|
|
|
|
&& ((dst & 0x8000L) != 0L))
|
|
|
|
{
|
|
|
|
flags |= C_FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((res & 0xFFFFL) == 0L)
|
|
|
|
{
|
|
|
|
flags |= Z_FLAG;
|
|
|
|
}
|
|
|
|
if (((src & 0x8000L) != 0L)
|
|
|
|
&& ((dst & 0x8000L) != 0L))
|
|
|
|
{
|
|
|
|
flags |= V_FLAG;
|
|
|
|
}
|
|
|
|
if ((dst & 0x8000L) != 0L
|
|
|
|
|| (src & 0x8000L) != 0L)
|
|
|
|
{
|
|
|
|
flags |= C_FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if ((res & 0x80000000L) != 0L)
|
|
|
|
{
|
|
|
|
flags |= N_FLAG;
|
|
|
|
if (((src & 0x80000000L) == 0L)
|
|
|
|
&& ((dst & 0x80000000L) == 0L))
|
|
|
|
{
|
|
|
|
flags |= V_FLAG;
|
|
|
|
}
|
|
|
|
else if (((src & 0x80000000L) != 0L) &&
|
|
|
|
((dst & 0x80000000L) != 0L))
|
|
|
|
{
|
|
|
|
flags |= C_FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (res == 0L)
|
|
|
|
flags |= Z_FLAG;
|
|
|
|
if (((src & 0x80000000L) != 0L)
|
|
|
|
&& ((dst & 0x80000000L) != 0L))
|
|
|
|
flags |= V_FLAG;
|
|
|
|
if ((dst & 0x80000000L) != 0L
|
|
|
|
|| (src & 0x80000000L) != 0L)
|
|
|
|
flags |= C_FLAG;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-08 07:38:41 +08:00
|
|
|
if (env->cc_op == CC_OP_SUB || env->cc_op == CC_OP_CMP)
|
2008-05-03 06:16:17 +08:00
|
|
|
flags ^= C_FLAG;
|
2009-01-08 07:38:41 +08:00
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
env->pregs[PR_CCS] = evaluate_flags_writeback(env, flags,
|
|
|
|
env->pregs[PR_CCS]);
|
2008-05-03 06:16:17 +08:00
|
|
|
}
|
2008-05-28 05:10:56 +08:00
|
|
|
|
2012-08-30 22:56:39 +08:00
|
|
|
void helper_top_evaluate_flags(CPUCRISState *env)
|
2008-05-28 05:10:56 +08:00
|
|
|
{
|
|
|
|
switch (env->cc_op)
|
|
|
|
{
|
|
|
|
case CC_OP_MCP:
|
2012-08-30 22:56:39 +08:00
|
|
|
env->pregs[PR_CCS] = helper_evaluate_flags_mcp(env,
|
2009-01-08 07:38:41 +08:00
|
|
|
env->pregs[PR_CCS], env->cc_src,
|
|
|
|
env->cc_dest, env->cc_result);
|
2008-05-28 05:10:56 +08:00
|
|
|
break;
|
|
|
|
case CC_OP_MULS:
|
2012-08-30 22:56:39 +08:00
|
|
|
env->pregs[PR_CCS] = helper_evaluate_flags_muls(env,
|
2009-01-08 07:38:41 +08:00
|
|
|
env->pregs[PR_CCS], env->cc_result,
|
|
|
|
env->pregs[PR_MOF]);
|
2008-05-28 05:10:56 +08:00
|
|
|
break;
|
|
|
|
case CC_OP_MULU:
|
2012-08-30 22:56:39 +08:00
|
|
|
env->pregs[PR_CCS] = helper_evaluate_flags_mulu(env,
|
2009-01-08 07:38:41 +08:00
|
|
|
env->pregs[PR_CCS], env->cc_result,
|
|
|
|
env->pregs[PR_MOF]);
|
2008-05-28 05:10:56 +08:00
|
|
|
break;
|
|
|
|
case CC_OP_MOVE:
|
|
|
|
case CC_OP_AND:
|
|
|
|
case CC_OP_OR:
|
|
|
|
case CC_OP_XOR:
|
|
|
|
case CC_OP_ASR:
|
|
|
|
case CC_OP_LSR:
|
|
|
|
case CC_OP_LSL:
|
2009-01-08 07:38:41 +08:00
|
|
|
switch (env->cc_size)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
env->pregs[PR_CCS] =
|
2012-08-30 22:56:39 +08:00
|
|
|
helper_evaluate_flags_move_4(env,
|
2009-01-08 07:38:41 +08:00
|
|
|
env->pregs[PR_CCS],
|
|
|
|
env->cc_result);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
env->pregs[PR_CCS] =
|
2012-08-30 22:56:39 +08:00
|
|
|
helper_evaluate_flags_move_2(env,
|
2009-01-08 07:38:41 +08:00
|
|
|
env->pregs[PR_CCS],
|
|
|
|
env->cc_result);
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-30 22:56:39 +08:00
|
|
|
helper_evaluate_flags(env);
|
2009-01-08 07:38:41 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2008-05-28 05:10:56 +08:00
|
|
|
case CC_OP_FLAGS:
|
|
|
|
/* live. */
|
|
|
|
break;
|
2009-01-07 20:25:15 +08:00
|
|
|
case CC_OP_SUB:
|
|
|
|
case CC_OP_CMP:
|
|
|
|
if (env->cc_size == 4)
|
2009-01-08 07:38:41 +08:00
|
|
|
env->pregs[PR_CCS] =
|
2012-08-30 22:56:39 +08:00
|
|
|
helper_evaluate_flags_sub_4(env,
|
2009-01-08 07:38:41 +08:00
|
|
|
env->pregs[PR_CCS],
|
|
|
|
env->cc_src, env->cc_dest,
|
|
|
|
env->cc_result);
|
2009-01-07 20:25:15 +08:00
|
|
|
else
|
2012-08-30 22:56:39 +08:00
|
|
|
helper_evaluate_flags(env);
|
2009-01-07 20:25:15 +08:00
|
|
|
break;
|
2008-05-28 05:10:56 +08:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
switch (env->cc_size)
|
|
|
|
{
|
2009-01-08 07:38:41 +08:00
|
|
|
case 4:
|
|
|
|
env->pregs[PR_CCS] =
|
2012-08-30 22:56:39 +08:00
|
|
|
helper_evaluate_flags_alu_4(env,
|
2009-01-08 07:38:41 +08:00
|
|
|
env->pregs[PR_CCS],
|
|
|
|
env->cc_src, env->cc_dest,
|
|
|
|
env->cc_result);
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-30 22:56:39 +08:00
|
|
|
helper_evaluate_flags(env);
|
2009-01-08 07:38:41 +08:00
|
|
|
break;
|
2008-05-28 05:10:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|