2005-07-02 18:58:51 +04:00
|
|
|
/*
|
|
|
|
* MIPS emulation helpers for qemu.
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2005-07-02 18:58:51 +04:00
|
|
|
* Copyright (c) 2004-2005 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-16 17:35:09 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2005-07-02 18:58:51 +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/>.
|
2020-02-03 18:57:22 +03:00
|
|
|
*
|
2005-07-02 18:58:51 +04:00
|
|
|
*/
|
2020-02-03 18:57:22 +03:00
|
|
|
|
2016-01-18 20:35:00 +03:00
|
|
|
#include "qemu/osdep.h"
|
2011-07-13 16:44:15 +04:00
|
|
|
#include "cpu.h"
|
2017-09-20 22:49:30 +03:00
|
|
|
#include "internal.h"
|
2014-04-08 09:31:41 +04:00
|
|
|
#include "exec/helper-proto.h"
|
2016-03-15 15:18:37 +03:00
|
|
|
#include "exec/exec-all.h"
|
2019-08-23 21:36:41 +03:00
|
|
|
#include "exec/memop.h"
|
2020-11-14 21:03:11 +03:00
|
|
|
#include "fpu_helper.h"
|
2020-02-03 18:57:22 +03:00
|
|
|
|
2014-06-27 11:49:05 +04:00
|
|
|
static inline target_ulong bitswap(target_ulong v)
|
|
|
|
{
|
2014-10-22 17:00:29 +04:00
|
|
|
v = ((v >> 1) & (target_ulong)0x5555555555555555ULL) |
|
|
|
|
((v & (target_ulong)0x5555555555555555ULL) << 1);
|
|
|
|
v = ((v >> 2) & (target_ulong)0x3333333333333333ULL) |
|
|
|
|
((v & (target_ulong)0x3333333333333333ULL) << 2);
|
|
|
|
v = ((v >> 4) & (target_ulong)0x0F0F0F0F0F0F0F0FULL) |
|
|
|
|
((v & (target_ulong)0x0F0F0F0F0F0F0F0FULL) << 4);
|
2014-06-27 11:49:05 +04:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TARGET_MIPS64
|
|
|
|
target_ulong helper_dbitswap(target_ulong rt)
|
|
|
|
{
|
|
|
|
return bitswap(rt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
target_ulong helper_bitswap(target_ulong rt)
|
|
|
|
{
|
|
|
|
return (int32_t)bitswap(rt);
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:16:20 +03:00
|
|
|
target_ulong helper_rotx(target_ulong rs, uint32_t shift, uint32_t shiftx,
|
|
|
|
uint32_t stripe)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint64_t tmp0 = ((uint64_t)rs) << 32 | ((uint64_t)rs & 0xffffffff);
|
|
|
|
uint64_t tmp1 = tmp0;
|
|
|
|
for (i = 0; i <= 46; i++) {
|
|
|
|
int s;
|
|
|
|
if (i & 0x8) {
|
|
|
|
s = shift;
|
|
|
|
} else {
|
|
|
|
s = shiftx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stripe != 0 && !(i & 0x4)) {
|
|
|
|
s = ~s;
|
|
|
|
}
|
|
|
|
if (s & 0x10) {
|
|
|
|
if (tmp0 & (1LL << (i + 16))) {
|
|
|
|
tmp1 |= 1LL << i;
|
|
|
|
} else {
|
|
|
|
tmp1 &= ~(1LL << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t tmp2 = tmp1;
|
|
|
|
for (i = 0; i <= 38; i++) {
|
|
|
|
int s;
|
|
|
|
if (i & 0x4) {
|
|
|
|
s = shift;
|
|
|
|
} else {
|
|
|
|
s = shiftx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s & 0x8) {
|
|
|
|
if (tmp1 & (1LL << (i + 8))) {
|
|
|
|
tmp2 |= 1LL << i;
|
|
|
|
} else {
|
|
|
|
tmp2 &= ~(1LL << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t tmp3 = tmp2;
|
|
|
|
for (i = 0; i <= 34; i++) {
|
|
|
|
int s;
|
|
|
|
if (i & 0x2) {
|
|
|
|
s = shift;
|
|
|
|
} else {
|
|
|
|
s = shiftx;
|
|
|
|
}
|
|
|
|
if (s & 0x4) {
|
|
|
|
if (tmp2 & (1LL << (i + 4))) {
|
|
|
|
tmp3 |= 1LL << i;
|
|
|
|
} else {
|
|
|
|
tmp3 &= ~(1LL << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t tmp4 = tmp3;
|
|
|
|
for (i = 0; i <= 32; i++) {
|
|
|
|
int s;
|
|
|
|
if (i & 0x1) {
|
|
|
|
s = shift;
|
|
|
|
} else {
|
|
|
|
s = shiftx;
|
|
|
|
}
|
|
|
|
if (s & 0x2) {
|
|
|
|
if (tmp3 & (1LL << (i + 2))) {
|
|
|
|
tmp4 |= 1LL << i;
|
|
|
|
} else {
|
|
|
|
tmp4 &= ~(1LL << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t tmp5 = tmp4;
|
|
|
|
for (i = 0; i <= 31; i++) {
|
|
|
|
int s;
|
|
|
|
s = shift;
|
|
|
|
if (s & 0x1) {
|
|
|
|
if (tmp4 & (1LL << (i + 1))) {
|
|
|
|
tmp5 |= 1LL << i;
|
|
|
|
} else {
|
|
|
|
tmp5 &= ~(1LL << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int64_t)(int32_t)(uint32_t)tmp5;
|
|
|
|
}
|
|
|
|
|
2020-02-03 18:57:22 +03:00
|
|
|
void helper_fork(target_ulong arg1, target_ulong arg2)
|
2011-08-30 01:07:40 +04:00
|
|
|
{
|
2019-10-23 13:23:35 +03:00
|
|
|
/*
|
2020-02-03 18:57:22 +03:00
|
|
|
* arg1 = rt, arg2 = rs
|
|
|
|
* TODO: store to TC register
|
2019-10-23 13:23:35 +03:00
|
|
|
*/
|
2008-06-09 11:13:38 +04:00
|
|
|
}
|
|
|
|
|
2020-02-03 18:57:22 +03:00
|
|
|
target_ulong helper_yield(CPUMIPSState *env, target_ulong arg)
|
2019-01-03 16:58:16 +03:00
|
|
|
{
|
2020-02-03 18:57:22 +03:00
|
|
|
target_long arg1 = arg;
|
2008-06-09 11:13:38 +04:00
|
|
|
|
2020-02-03 18:57:22 +03:00
|
|
|
if (arg1 < 0) {
|
|
|
|
/* No scheduling policy implemented. */
|
|
|
|
if (arg1 != -2) {
|
|
|
|
if (env->CP0_VPEControl & (1 << CP0VPECo_YSI) &&
|
|
|
|
env->active_tc.CP0_TCStatus & (1 << CP0TCSt_DT)) {
|
|
|
|
env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
|
|
|
|
env->CP0_VPEControl |= 4 << CP0VPECo_EXCPT;
|
|
|
|
do_raise_exception(env, EXCP_THREAD, GETPC());
|
|
|
|
}
|
2014-07-11 19:11:34 +04:00
|
|
|
}
|
2020-02-03 18:57:22 +03:00
|
|
|
} else if (arg1 == 0) {
|
|
|
|
if (0) {
|
|
|
|
/* TODO: TC underflow */
|
|
|
|
env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
|
|
|
|
do_raise_exception(env, EXCP_THREAD, GETPC());
|
|
|
|
} else {
|
|
|
|
/* TODO: Deallocate TC */
|
|
|
|
}
|
|
|
|
} else if (arg1 > 0) {
|
|
|
|
/* Yield qualifier inputs not implemented. */
|
|
|
|
env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
|
|
|
|
env->CP0_VPEControl |= 2 << CP0VPECo_EXCPT;
|
|
|
|
do_raise_exception(env, EXCP_THREAD, GETPC());
|
2008-06-09 11:13:38 +04:00
|
|
|
}
|
2008-06-23 16:57:09 +04:00
|
|
|
return env->CP0_YQMask;
|
2008-06-09 11:13:38 +04:00
|
|
|
}
|
|
|
|
|
2016-04-28 01:21:06 +03:00
|
|
|
static inline void check_hwrena(CPUMIPSState *env, int reg, uintptr_t pc)
|
2008-06-12 16:42:35 +04:00
|
|
|
{
|
2015-10-29 18:18:39 +03:00
|
|
|
if ((env->hflags & MIPS_HFLAG_CP0) || (env->CP0_HWREna & (1 << reg))) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-28 01:21:06 +03:00
|
|
|
do_raise_exception(env, EXCP_RI, pc);
|
2015-10-29 18:18:39 +03:00
|
|
|
}
|
2008-06-23 16:57:09 +04:00
|
|
|
|
2015-10-29 18:18:39 +03:00
|
|
|
target_ulong helper_rdhwr_cpunum(CPUMIPSState *env)
|
|
|
|
{
|
2016-04-28 01:21:06 +03:00
|
|
|
check_hwrena(env, 0, GETPC());
|
2015-10-29 18:18:39 +03:00
|
|
|
return env->CP0_EBase & 0x3ff;
|
2008-06-12 16:42:35 +04:00
|
|
|
}
|
|
|
|
|
2012-09-02 18:52:59 +04:00
|
|
|
target_ulong helper_rdhwr_synci_step(CPUMIPSState *env)
|
2008-06-12 16:42:35 +04:00
|
|
|
{
|
2016-04-28 01:21:06 +03:00
|
|
|
check_hwrena(env, 1, GETPC());
|
2015-10-29 18:18:39 +03:00
|
|
|
return env->SYNCI_Step;
|
2008-06-12 16:42:35 +04:00
|
|
|
}
|
|
|
|
|
2012-09-02 18:52:59 +04:00
|
|
|
target_ulong helper_rdhwr_cc(CPUMIPSState *env)
|
2008-06-12 16:42:35 +04:00
|
|
|
{
|
2016-04-28 01:21:06 +03:00
|
|
|
check_hwrena(env, 2, GETPC());
|
2015-09-08 13:34:11 +03:00
|
|
|
#ifdef CONFIG_USER_ONLY
|
2019-02-11 18:28:16 +03:00
|
|
|
return env->CP0_Count;
|
2015-09-08 13:34:11 +03:00
|
|
|
#else
|
2019-02-11 18:28:16 +03:00
|
|
|
return (int32_t)cpu_mips_get_count(env);
|
2015-09-08 13:34:11 +03:00
|
|
|
#endif
|
2008-06-12 16:42:35 +04:00
|
|
|
}
|
|
|
|
|
2012-09-02 18:52:59 +04:00
|
|
|
target_ulong helper_rdhwr_ccres(CPUMIPSState *env)
|
2008-06-12 16:42:35 +04:00
|
|
|
{
|
2016-04-28 01:21:06 +03:00
|
|
|
check_hwrena(env, 3, GETPC());
|
2015-10-29 18:18:39 +03:00
|
|
|
return env->CCRes;
|
|
|
|
}
|
2008-06-23 16:57:09 +04:00
|
|
|
|
2015-10-29 18:18:39 +03:00
|
|
|
target_ulong helper_rdhwr_performance(CPUMIPSState *env)
|
|
|
|
{
|
2016-04-28 01:21:06 +03:00
|
|
|
check_hwrena(env, 4, GETPC());
|
2015-10-29 18:18:39 +03:00
|
|
|
return env->CP0_Performance0;
|
|
|
|
}
|
|
|
|
|
|
|
|
target_ulong helper_rdhwr_xnp(CPUMIPSState *env)
|
|
|
|
{
|
2016-04-28 01:21:06 +03:00
|
|
|
check_hwrena(env, 5, GETPC());
|
2015-10-29 18:18:39 +03:00
|
|
|
return (env->CP0_Config5 >> CP0C5_XNP) & 1;
|
2008-06-12 16:42:35 +04:00
|
|
|
}
|
|
|
|
|
2012-09-02 18:52:59 +04:00
|
|
|
void helper_pmon(CPUMIPSState *env, int function)
|
2005-07-02 18:58:51 +04:00
|
|
|
{
|
|
|
|
function /= 2;
|
|
|
|
switch (function) {
|
|
|
|
case 2: /* TODO: char inbyte(int waitflag); */
|
2019-10-23 13:23:35 +03:00
|
|
|
if (env->active_tc.gpr[4] == 0) {
|
2008-06-27 14:02:35 +04:00
|
|
|
env->active_tc.gpr[2] = -1;
|
2019-10-23 13:23:35 +03:00
|
|
|
}
|
2005-07-02 18:58:51 +04:00
|
|
|
/* Fall through */
|
|
|
|
case 11: /* TODO: char inbyte (void); */
|
2008-06-27 14:02:35 +04:00
|
|
|
env->active_tc.gpr[2] = -1;
|
2005-07-02 18:58:51 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 12:
|
2008-06-27 14:02:35 +04:00
|
|
|
printf("%c", (char)(env->active_tc.gpr[4] & 0xFF));
|
2005-07-02 18:58:51 +04:00
|
|
|
break;
|
|
|
|
case 17:
|
|
|
|
break;
|
|
|
|
case 158:
|
|
|
|
{
|
2012-04-12 17:43:09 +04:00
|
|
|
unsigned char *fmt = (void *)(uintptr_t)env->active_tc.gpr[4];
|
2005-07-02 18:58:51 +04:00
|
|
|
printf("%s", fmt);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-07-05 02:17:33 +04:00
|
|
|
|
2007-09-17 01:08:06 +04:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2005-07-05 02:17:33 +04:00
|
|
|
|
2014-03-28 21:14:58 +04:00
|
|
|
void mips_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
|
2016-06-14 15:26:17 +03:00
|
|
|
MMUAccessType access_type,
|
|
|
|
int mmu_idx, uintptr_t retaddr)
|
2005-12-05 22:59:36 +03:00
|
|
|
{
|
2014-03-28 21:14:58 +04:00
|
|
|
MIPSCPU *cpu = MIPS_CPU(cs);
|
|
|
|
CPUMIPSState *env = &cpu->env;
|
2014-07-07 14:24:01 +04:00
|
|
|
int error_code = 0;
|
|
|
|
int excp;
|
2014-03-28 21:14:58 +04:00
|
|
|
|
2018-08-02 17:15:55 +03:00
|
|
|
if (!(env->hflags & MIPS_HFLAG_DM)) {
|
|
|
|
env->CP0_BadVAddr = addr;
|
|
|
|
}
|
2014-07-07 14:24:01 +04:00
|
|
|
|
|
|
|
if (access_type == MMU_DATA_STORE) {
|
|
|
|
excp = EXCP_AdES;
|
|
|
|
} else {
|
|
|
|
excp = EXCP_AdEL;
|
|
|
|
if (access_type == MMU_INST_FETCH) {
|
|
|
|
error_code |= EXCP_INST_NOTAVAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
do_raise_exception_err(env, excp, error_code, retaddr);
|
2005-12-05 22:59:36 +03:00
|
|
|
}
|
|
|
|
|
2019-08-02 19:04:57 +03:00
|
|
|
void mips_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
|
|
|
|
vaddr addr, unsigned size,
|
|
|
|
MMUAccessType access_type,
|
|
|
|
int mmu_idx, MemTxAttrs attrs,
|
|
|
|
MemTxResult response, uintptr_t retaddr)
|
2007-10-20 23:45:44 +04:00
|
|
|
{
|
2013-05-27 08:49:53 +04:00
|
|
|
MIPSCPU *cpu = MIPS_CPU(cs);
|
2021-02-27 23:44:00 +03:00
|
|
|
MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(cpu);
|
2013-05-27 08:49:53 +04:00
|
|
|
CPUMIPSState *env = &cpu->env;
|
|
|
|
|
2019-08-02 19:04:57 +03:00
|
|
|
if (access_type == MMU_INST_FETCH) {
|
|
|
|
do_raise_exception(env, EXCP_IBE, retaddr);
|
2021-02-27 23:44:00 +03:00
|
|
|
} else if (!mcc->no_data_aborts) {
|
2019-08-02 19:04:57 +03:00
|
|
|
do_raise_exception(env, EXCP_DBE, retaddr);
|
2013-05-27 08:49:53 +04:00
|
|
|
}
|
2007-10-20 23:45:44 +04:00
|
|
|
}
|
2008-06-09 11:13:38 +04:00
|
|
|
#endif /* !CONFIG_USER_ONLY */
|