2004-01-05 06:58:38 +08:00
|
|
|
/*
|
2012-05-30 12:23:40 +08:00
|
|
|
* PowerPC memory access emulation helpers for QEMU.
|
2007-09-17 05:08:06 +08:00
|
|
|
*
|
2007-03-07 16:32:30 +08:00
|
|
|
* Copyright (c) 2003-2007 Jocelyn Mayer
|
2004-01-05 06:58:38 +08:00
|
|
|
*
|
|
|
|
* 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/>.
|
2004-01-05 06:58:38 +08:00
|
|
|
*/
|
Include qemu/main-loop.h less
In my "build everything" tree, changing qemu/main-loop.h triggers a
recompile of some 5600 out of 6600 objects (not counting tests and
objects that don't depend on qemu/osdep.h). It includes block/aio.h,
which in turn includes qemu/event_notifier.h, qemu/notify.h,
qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
qemu/thread.h, qemu/timer.h, and a few more.
Include qemu/main-loop.h only where it's needed. Touching it now
recompiles only some 1700 objects. For block/aio.h and
qemu/event_notifier.h, these numbers drop from 5600 to 2800. For the
others, they shrink only slightly.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190812052359.30071-21-armbru@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-08-12 13:23:50 +08:00
|
|
|
|
2016-01-27 02:16:58 +08:00
|
|
|
#include "qemu/osdep.h"
|
2011-07-13 20:44:15 +08:00
|
|
|
#include "cpu.h"
|
2016-03-15 20:18:37 +08:00
|
|
|
#include "exec/exec-all.h"
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/host-utils.h"
|
Include qemu/main-loop.h less
In my "build everything" tree, changing qemu/main-loop.h triggers a
recompile of some 5600 out of 6600 objects (not counting tests and
objects that don't depend on qemu/osdep.h). It includes block/aio.h,
which in turn includes qemu/event_notifier.h, qemu/notify.h,
qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
qemu/thread.h, qemu/timer.h, and a few more.
Include qemu/main-loop.h only where it's needed. Touching it now
recompiles only some 1700 objects. For block/aio.h and
qemu/event_notifier.h, these numbers drop from 5600 to 2800. For the
others, they shrink only slightly.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190812052359.30071-21-armbru@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-08-12 13:23:50 +08:00
|
|
|
#include "qemu/main-loop.h"
|
2014-04-08 13:31:41 +08:00
|
|
|
#include "exec/helper-proto.h"
|
2007-10-26 05:35:50 +08:00
|
|
|
#include "helper_regs.h"
|
2014-03-29 02:42:10 +08:00
|
|
|
#include "exec/cpu_ldst.h"
|
2020-01-01 19:23:00 +08:00
|
|
|
#include "tcg/tcg.h"
|
2016-12-09 20:17:20 +08:00
|
|
|
#include "internal.h"
|
2018-08-16 08:35:14 +08:00
|
|
|
#include "qemu/atomic128.h"
|
2011-07-13 20:44:15 +08:00
|
|
|
|
2019-03-21 19:22:13 +08:00
|
|
|
/* #define DEBUG_OP */
|
2009-01-16 05:48:06 +08:00
|
|
|
|
2014-05-29 22:12:20 +08:00
|
|
|
static inline bool needs_byteswap(const CPUPPCState *env)
|
|
|
|
{
|
|
|
|
#if defined(TARGET_WORDS_BIGENDIAN)
|
|
|
|
return msr_le;
|
|
|
|
#else
|
|
|
|
return !msr_le;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-12-01 00:23:56 +08:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Memory load and stores */
|
|
|
|
|
2012-05-30 12:23:40 +08:00
|
|
|
static inline target_ulong addr_add(CPUPPCState *env, target_ulong addr,
|
|
|
|
target_long arg)
|
2008-12-01 00:23:56 +08:00
|
|
|
{
|
|
|
|
#if defined(TARGET_PPC64)
|
2012-06-21 03:20:29 +08:00
|
|
|
if (!msr_is_64bit(env, env->msr)) {
|
2012-05-30 12:23:21 +08:00
|
|
|
return (uint32_t)(addr + arg);
|
|
|
|
} else
|
2008-12-01 00:23:56 +08:00
|
|
|
#endif
|
2012-05-30 12:23:21 +08:00
|
|
|
{
|
|
|
|
return addr + arg;
|
|
|
|
}
|
2008-12-01 00:23:56 +08:00
|
|
|
}
|
|
|
|
|
2020-01-30 07:50:37 +08:00
|
|
|
static void *probe_contiguous(CPUPPCState *env, target_ulong addr, uint32_t nb,
|
|
|
|
MMUAccessType access_type, int mmu_idx,
|
|
|
|
uintptr_t raddr)
|
|
|
|
{
|
|
|
|
void *host1, *host2;
|
|
|
|
uint32_t nb_pg1, nb_pg2;
|
|
|
|
|
|
|
|
nb_pg1 = -(addr | TARGET_PAGE_MASK);
|
|
|
|
if (likely(nb <= nb_pg1)) {
|
|
|
|
/* The entire operation is on a single page. */
|
|
|
|
return probe_access(env, addr, nb, access_type, mmu_idx, raddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The operation spans two pages. */
|
|
|
|
nb_pg2 = nb - nb_pg1;
|
|
|
|
host1 = probe_access(env, addr, nb_pg1, access_type, mmu_idx, raddr);
|
|
|
|
addr = addr_add(env, addr, nb_pg1);
|
|
|
|
host2 = probe_access(env, addr, nb_pg2, access_type, mmu_idx, raddr);
|
|
|
|
|
|
|
|
/* If the two host pages are contiguous, optimize. */
|
|
|
|
if (host2 == host1 + nb_pg1) {
|
|
|
|
return host1;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:40 +08:00
|
|
|
void helper_lmw(CPUPPCState *env, target_ulong addr, uint32_t reg)
|
2008-12-01 00:23:56 +08:00
|
|
|
{
|
2020-01-30 07:50:38 +08:00
|
|
|
uintptr_t raddr = GETPC();
|
|
|
|
int mmu_idx = cpu_mmu_index(env, false);
|
|
|
|
void *host = probe_contiguous(env, addr, (32 - reg) * 4,
|
|
|
|
MMU_DATA_LOAD, mmu_idx, raddr);
|
|
|
|
|
|
|
|
if (likely(host)) {
|
|
|
|
/* Fast path -- the entire operation is in RAM at host. */
|
|
|
|
for (; reg < 32; reg++) {
|
|
|
|
env->gpr[reg] = (uint32_t)ldl_be_p(host);
|
|
|
|
host += 4;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Slow path -- at least some of the operation requires i/o. */
|
|
|
|
for (; reg < 32; reg++) {
|
|
|
|
env->gpr[reg] = cpu_ldl_mmuidx_ra(env, addr, mmu_idx, raddr);
|
|
|
|
addr = addr_add(env, addr, 4);
|
2012-05-30 12:23:21 +08:00
|
|
|
}
|
2008-12-01 00:23:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:40 +08:00
|
|
|
void helper_stmw(CPUPPCState *env, target_ulong addr, uint32_t reg)
|
2008-12-01 00:23:56 +08:00
|
|
|
{
|
2020-01-30 07:50:38 +08:00
|
|
|
uintptr_t raddr = GETPC();
|
|
|
|
int mmu_idx = cpu_mmu_index(env, false);
|
|
|
|
void *host = probe_contiguous(env, addr, (32 - reg) * 4,
|
|
|
|
MMU_DATA_STORE, mmu_idx, raddr);
|
|
|
|
|
|
|
|
if (likely(host)) {
|
|
|
|
/* Fast path -- the entire operation is in RAM at host. */
|
|
|
|
for (; reg < 32; reg++) {
|
|
|
|
stl_be_p(host, env->gpr[reg]);
|
|
|
|
host += 4;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Slow path -- at least some of the operation requires i/o. */
|
|
|
|
for (; reg < 32; reg++) {
|
|
|
|
cpu_stl_mmuidx_ra(env, addr, env->gpr[reg], mmu_idx, raddr);
|
|
|
|
addr = addr_add(env, addr, 4);
|
2012-05-30 12:23:21 +08:00
|
|
|
}
|
2008-12-01 00:23:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:56:30 +08:00
|
|
|
static void do_lsw(CPUPPCState *env, target_ulong addr, uint32_t nb,
|
|
|
|
uint32_t reg, uintptr_t raddr)
|
2008-12-01 00:24:21 +08:00
|
|
|
{
|
2020-01-30 07:50:37 +08:00
|
|
|
int mmu_idx;
|
|
|
|
void *host;
|
|
|
|
uint32_t val;
|
2012-05-30 12:23:21 +08:00
|
|
|
|
2020-01-30 07:50:37 +08:00
|
|
|
if (unlikely(nb == 0)) {
|
|
|
|
return;
|
2008-12-01 00:24:21 +08:00
|
|
|
}
|
2020-01-30 07:50:37 +08:00
|
|
|
|
|
|
|
mmu_idx = cpu_mmu_index(env, false);
|
|
|
|
host = probe_contiguous(env, addr, nb, MMU_DATA_LOAD, mmu_idx, raddr);
|
|
|
|
|
|
|
|
if (likely(host)) {
|
|
|
|
/* Fast path -- the entire operation is in RAM at host. */
|
|
|
|
for (; nb > 3; nb -= 4) {
|
|
|
|
env->gpr[reg] = (uint32_t)ldl_be_p(host);
|
|
|
|
reg = (reg + 1) % 32;
|
|
|
|
host += 4;
|
|
|
|
}
|
|
|
|
switch (nb) {
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
val = ldub_p(host) << 24;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
val = lduw_be_p(host) << 16;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
val = (lduw_be_p(host) << 16) | (ldub_p(host + 2) << 8);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Slow path -- at least some of the operation requires i/o. */
|
|
|
|
for (; nb > 3; nb -= 4) {
|
|
|
|
env->gpr[reg] = cpu_ldl_mmuidx_ra(env, addr, mmu_idx, raddr);
|
|
|
|
reg = (reg + 1) % 32;
|
|
|
|
addr = addr_add(env, addr, 4);
|
|
|
|
}
|
|
|
|
switch (nb) {
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
val = cpu_ldub_mmuidx_ra(env, addr, mmu_idx, raddr) << 24;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
val = cpu_lduw_mmuidx_ra(env, addr, mmu_idx, raddr) << 16;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
val = cpu_lduw_mmuidx_ra(env, addr, mmu_idx, raddr) << 16;
|
|
|
|
addr = addr_add(env, addr, 2);
|
|
|
|
val |= cpu_ldub_mmuidx_ra(env, addr, mmu_idx, raddr) << 8;
|
|
|
|
break;
|
2008-12-01 00:24:21 +08:00
|
|
|
}
|
|
|
|
}
|
2020-01-30 07:50:37 +08:00
|
|
|
env->gpr[reg] = val;
|
2008-12-01 00:24:21 +08:00
|
|
|
}
|
2016-07-27 14:56:30 +08:00
|
|
|
|
2020-01-30 07:50:37 +08:00
|
|
|
void helper_lsw(CPUPPCState *env, target_ulong addr,
|
|
|
|
uint32_t nb, uint32_t reg)
|
2016-07-27 14:56:30 +08:00
|
|
|
{
|
|
|
|
do_lsw(env, addr, nb, reg, GETPC());
|
|
|
|
}
|
|
|
|
|
2019-03-21 19:22:13 +08:00
|
|
|
/*
|
|
|
|
* PPC32 specification says we must generate an exception if rA is in
|
|
|
|
* the range of registers to be loaded. In an other hand, IBM says
|
|
|
|
* this is valid, but rA won't be loaded. For now, I'll follow the
|
|
|
|
* spec...
|
2008-12-01 00:24:21 +08:00
|
|
|
*/
|
2012-05-30 12:23:40 +08:00
|
|
|
void helper_lswx(CPUPPCState *env, target_ulong addr, uint32_t reg,
|
|
|
|
uint32_t ra, uint32_t rb)
|
2008-12-01 00:24:21 +08:00
|
|
|
{
|
|
|
|
if (likely(xer_bc != 0)) {
|
2017-06-22 19:04:16 +08:00
|
|
|
int num_used_regs = DIV_ROUND_UP(xer_bc, 4);
|
2016-04-14 23:14:53 +08:00
|
|
|
if (unlikely((ra != 0 && lsw_reg_in_range(reg, num_used_regs, ra)) ||
|
|
|
|
lsw_reg_in_range(reg, num_used_regs, rb))) {
|
2016-07-27 14:56:30 +08:00
|
|
|
raise_exception_err_ra(env, POWERPC_EXCP_PROGRAM,
|
|
|
|
POWERPC_EXCP_INVAL |
|
|
|
|
POWERPC_EXCP_INVAL_LSWX, GETPC());
|
2008-12-01 00:24:21 +08:00
|
|
|
} else {
|
2016-07-27 14:56:30 +08:00
|
|
|
do_lsw(env, addr, xer_bc, reg, GETPC());
|
2008-12-01 00:24:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:40 +08:00
|
|
|
void helper_stsw(CPUPPCState *env, target_ulong addr, uint32_t nb,
|
|
|
|
uint32_t reg)
|
2008-12-01 00:24:21 +08:00
|
|
|
{
|
2020-01-30 07:50:37 +08:00
|
|
|
uintptr_t raddr = GETPC();
|
|
|
|
int mmu_idx;
|
|
|
|
void *host;
|
|
|
|
uint32_t val;
|
2012-05-30 12:23:21 +08:00
|
|
|
|
2020-01-30 07:50:37 +08:00
|
|
|
if (unlikely(nb == 0)) {
|
|
|
|
return;
|
2008-12-01 00:24:21 +08:00
|
|
|
}
|
2020-01-30 07:50:37 +08:00
|
|
|
|
|
|
|
mmu_idx = cpu_mmu_index(env, false);
|
|
|
|
host = probe_contiguous(env, addr, nb, MMU_DATA_STORE, mmu_idx, raddr);
|
|
|
|
|
|
|
|
if (likely(host)) {
|
|
|
|
/* Fast path -- the entire operation is in RAM at host. */
|
|
|
|
for (; nb > 3; nb -= 4) {
|
|
|
|
stl_be_p(host, env->gpr[reg]);
|
|
|
|
reg = (reg + 1) % 32;
|
|
|
|
host += 4;
|
|
|
|
}
|
|
|
|
val = env->gpr[reg];
|
|
|
|
switch (nb) {
|
|
|
|
case 1:
|
|
|
|
stb_p(host, val >> 24);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
stw_be_p(host, val >> 16);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
stw_be_p(host, val >> 16);
|
|
|
|
stb_p(host + 2, val >> 8);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (; nb > 3; nb -= 4) {
|
|
|
|
cpu_stl_mmuidx_ra(env, addr, env->gpr[reg], mmu_idx, raddr);
|
|
|
|
reg = (reg + 1) % 32;
|
|
|
|
addr = addr_add(env, addr, 4);
|
|
|
|
}
|
|
|
|
val = env->gpr[reg];
|
|
|
|
switch (nb) {
|
|
|
|
case 1:
|
|
|
|
cpu_stb_mmuidx_ra(env, addr, val >> 24, mmu_idx, raddr);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
cpu_stw_mmuidx_ra(env, addr, val >> 16, mmu_idx, raddr);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
cpu_stw_mmuidx_ra(env, addr, val >> 16, mmu_idx, raddr);
|
|
|
|
addr = addr_add(env, addr, 2);
|
|
|
|
cpu_stb_mmuidx_ra(env, addr, val >> 8, mmu_idx, raddr);
|
|
|
|
break;
|
2008-12-29 17:46:58 +08:00
|
|
|
}
|
2008-12-01 00:24:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-21 14:59:07 +08:00
|
|
|
static void dcbz_common(CPUPPCState *env, target_ulong addr,
|
|
|
|
uint32_t opcode, bool epid, uintptr_t retaddr)
|
2008-12-01 00:24:05 +08:00
|
|
|
{
|
2016-07-27 14:56:43 +08:00
|
|
|
target_ulong mask, dcbz_size = env->dcache_line_size;
|
|
|
|
uint32_t i;
|
|
|
|
void *haddr;
|
2018-09-21 14:59:07 +08:00
|
|
|
int mmu_idx = epid ? PPC_TLB_EPID_STORE : env->dmmu_idx;
|
2008-12-01 00:24:05 +08:00
|
|
|
|
2013-04-26 15:18:58 +08:00
|
|
|
#if defined(TARGET_PPC64)
|
2016-07-27 14:56:43 +08:00
|
|
|
/* Check for dcbz vs dcbzl on 970 */
|
|
|
|
if (env->excp_model == POWERPC_EXCP_970 &&
|
|
|
|
!(opcode & 0x00200000) && ((env->spr[SPR_970_HID5] >> 7) & 0x3) == 1) {
|
2013-01-29 20:36:02 +08:00
|
|
|
dcbz_size = 32;
|
2012-05-30 12:23:21 +08:00
|
|
|
}
|
2013-01-29 20:36:02 +08:00
|
|
|
#endif
|
|
|
|
|
2016-07-27 14:56:43 +08:00
|
|
|
/* Align address */
|
|
|
|
mask = ~(dcbz_size - 1);
|
|
|
|
addr &= mask;
|
|
|
|
|
|
|
|
/* Check reservation */
|
|
|
|
if ((env->reserve_addr & mask) == (addr & mask)) {
|
|
|
|
env->reserve_addr = (target_ulong)-1ULL;
|
|
|
|
}
|
2013-01-29 20:36:02 +08:00
|
|
|
|
2016-07-27 14:56:43 +08:00
|
|
|
/* Try fast path translate */
|
2018-09-21 14:59:07 +08:00
|
|
|
haddr = tlb_vaddr_to_host(env, addr, MMU_DATA_STORE, mmu_idx);
|
2016-07-27 14:56:43 +08:00
|
|
|
if (haddr) {
|
|
|
|
memset(haddr, 0, dcbz_size);
|
|
|
|
} else {
|
|
|
|
/* Slow path */
|
|
|
|
for (i = 0; i < dcbz_size; i += 8) {
|
2019-12-11 04:27:21 +08:00
|
|
|
cpu_stq_mmuidx_ra(env, addr + i, 0, mmu_idx, retaddr);
|
2016-07-27 14:56:43 +08:00
|
|
|
}
|
|
|
|
}
|
2008-12-01 00:24:05 +08:00
|
|
|
}
|
|
|
|
|
2018-09-21 14:59:07 +08:00
|
|
|
void helper_dcbz(CPUPPCState *env, target_ulong addr, uint32_t opcode)
|
|
|
|
{
|
|
|
|
dcbz_common(env, addr, opcode, false, GETPC());
|
|
|
|
}
|
|
|
|
|
|
|
|
void helper_dcbzep(CPUPPCState *env, target_ulong addr, uint32_t opcode)
|
|
|
|
{
|
|
|
|
dcbz_common(env, addr, opcode, true, GETPC());
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:40 +08:00
|
|
|
void helper_icbi(CPUPPCState *env, target_ulong addr)
|
2008-12-01 00:24:13 +08:00
|
|
|
{
|
2008-12-09 02:11:21 +08:00
|
|
|
addr &= ~(env->dcache_line_size - 1);
|
2019-03-21 19:22:13 +08:00
|
|
|
/*
|
|
|
|
* Invalidate one cache line :
|
2008-12-01 00:24:13 +08:00
|
|
|
* PowerPC specification says this is to be treated like a load
|
|
|
|
* (not a fetch) by the MMU. To be sure it will be so,
|
|
|
|
* do the load "by hand".
|
|
|
|
*/
|
2016-07-27 14:56:31 +08:00
|
|
|
cpu_ldl_data_ra(env, addr, GETPC());
|
2008-12-01 00:24:13 +08:00
|
|
|
}
|
|
|
|
|
2018-09-21 14:59:07 +08:00
|
|
|
void helper_icbiep(CPUPPCState *env, target_ulong addr)
|
|
|
|
{
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
/* See comments above */
|
|
|
|
addr &= ~(env->dcache_line_size - 1);
|
2019-12-11 04:27:21 +08:00
|
|
|
cpu_ldl_mmuidx_ra(env, addr, PPC_TLB_EPID_LOAD, GETPC());
|
2018-09-21 14:59:07 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:23:21 +08:00
|
|
|
/* XXX: to be tested */
|
2012-05-30 12:23:40 +08:00
|
|
|
target_ulong helper_lscbx(CPUPPCState *env, target_ulong addr, uint32_t reg,
|
|
|
|
uint32_t ra, uint32_t rb)
|
2008-12-01 00:24:30 +08:00
|
|
|
{
|
|
|
|
int i, c, d;
|
2012-05-30 12:23:21 +08:00
|
|
|
|
2008-12-01 00:24:30 +08:00
|
|
|
d = 24;
|
|
|
|
for (i = 0; i < xer_bc; i++) {
|
2016-07-27 14:56:40 +08:00
|
|
|
c = cpu_ldub_data_ra(env, addr, GETPC());
|
2012-05-30 12:23:40 +08:00
|
|
|
addr = addr_add(env, addr, 1);
|
2008-12-01 00:24:30 +08:00
|
|
|
/* ra (if not 0) and rb are never modified */
|
|
|
|
if (likely(reg != rb && (ra == 0 || reg != ra))) {
|
|
|
|
env->gpr[reg] = (env->gpr[reg] & ~(0xFF << d)) | (c << d);
|
|
|
|
}
|
2012-05-30 12:23:21 +08:00
|
|
|
if (unlikely(c == xer_cmp)) {
|
2008-12-01 00:24:30 +08:00
|
|
|
break;
|
2012-05-30 12:23:21 +08:00
|
|
|
}
|
2008-12-01 00:24:30 +08:00
|
|
|
if (likely(d != 0)) {
|
|
|
|
d -= 8;
|
|
|
|
} else {
|
|
|
|
d = 24;
|
|
|
|
reg++;
|
|
|
|
reg = reg & 0x1F;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2018-08-16 08:35:14 +08:00
|
|
|
#ifdef TARGET_PPC64
|
2018-06-27 00:19:10 +08:00
|
|
|
uint64_t helper_lq_le_parallel(CPUPPCState *env, target_ulong addr,
|
|
|
|
uint32_t opidx)
|
|
|
|
{
|
2018-08-16 08:35:14 +08:00
|
|
|
Int128 ret;
|
|
|
|
|
|
|
|
/* We will have raised EXCP_ATOMIC from the translator. */
|
|
|
|
assert(HAVE_ATOMIC128);
|
|
|
|
ret = helper_atomic_ldo_le_mmu(env, addr, opidx, GETPC());
|
2018-06-27 00:19:10 +08:00
|
|
|
env->retxh = int128_gethi(ret);
|
|
|
|
return int128_getlo(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t helper_lq_be_parallel(CPUPPCState *env, target_ulong addr,
|
|
|
|
uint32_t opidx)
|
|
|
|
{
|
2018-08-16 08:35:14 +08:00
|
|
|
Int128 ret;
|
|
|
|
|
|
|
|
/* We will have raised EXCP_ATOMIC from the translator. */
|
|
|
|
assert(HAVE_ATOMIC128);
|
|
|
|
ret = helper_atomic_ldo_be_mmu(env, addr, opidx, GETPC());
|
2018-06-27 00:19:10 +08:00
|
|
|
env->retxh = int128_gethi(ret);
|
|
|
|
return int128_getlo(ret);
|
|
|
|
}
|
2018-06-27 00:19:11 +08:00
|
|
|
|
|
|
|
void helper_stq_le_parallel(CPUPPCState *env, target_ulong addr,
|
|
|
|
uint64_t lo, uint64_t hi, uint32_t opidx)
|
|
|
|
{
|
2018-08-16 08:35:14 +08:00
|
|
|
Int128 val;
|
|
|
|
|
|
|
|
/* We will have raised EXCP_ATOMIC from the translator. */
|
|
|
|
assert(HAVE_ATOMIC128);
|
|
|
|
val = int128_make128(lo, hi);
|
2018-06-27 00:19:11 +08:00
|
|
|
helper_atomic_sto_le_mmu(env, addr, val, opidx, GETPC());
|
|
|
|
}
|
|
|
|
|
|
|
|
void helper_stq_be_parallel(CPUPPCState *env, target_ulong addr,
|
|
|
|
uint64_t lo, uint64_t hi, uint32_t opidx)
|
|
|
|
{
|
2018-08-16 08:35:14 +08:00
|
|
|
Int128 val;
|
|
|
|
|
|
|
|
/* We will have raised EXCP_ATOMIC from the translator. */
|
|
|
|
assert(HAVE_ATOMIC128);
|
|
|
|
val = int128_make128(lo, hi);
|
2018-06-27 00:19:11 +08:00
|
|
|
helper_atomic_sto_be_mmu(env, addr, val, opidx, GETPC());
|
|
|
|
}
|
2018-06-27 00:19:12 +08:00
|
|
|
|
|
|
|
uint32_t helper_stqcx_le_parallel(CPUPPCState *env, target_ulong addr,
|
|
|
|
uint64_t new_lo, uint64_t new_hi,
|
|
|
|
uint32_t opidx)
|
|
|
|
{
|
|
|
|
bool success = false;
|
|
|
|
|
2018-08-16 08:35:14 +08:00
|
|
|
/* We will have raised EXCP_ATOMIC from the translator. */
|
|
|
|
assert(HAVE_CMPXCHG128);
|
|
|
|
|
2018-06-27 00:19:12 +08:00
|
|
|
if (likely(addr == env->reserve_addr)) {
|
|
|
|
Int128 oldv, cmpv, newv;
|
|
|
|
|
|
|
|
cmpv = int128_make128(env->reserve_val2, env->reserve_val);
|
|
|
|
newv = int128_make128(new_lo, new_hi);
|
|
|
|
oldv = helper_atomic_cmpxchgo_le_mmu(env, addr, cmpv, newv,
|
|
|
|
opidx, GETPC());
|
|
|
|
success = int128_eq(oldv, cmpv);
|
|
|
|
}
|
|
|
|
env->reserve_addr = -1;
|
|
|
|
return env->so + success * CRF_EQ_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t helper_stqcx_be_parallel(CPUPPCState *env, target_ulong addr,
|
|
|
|
uint64_t new_lo, uint64_t new_hi,
|
|
|
|
uint32_t opidx)
|
|
|
|
{
|
|
|
|
bool success = false;
|
|
|
|
|
2018-08-16 08:35:14 +08:00
|
|
|
/* We will have raised EXCP_ATOMIC from the translator. */
|
|
|
|
assert(HAVE_CMPXCHG128);
|
|
|
|
|
2018-06-27 00:19:12 +08:00
|
|
|
if (likely(addr == env->reserve_addr)) {
|
|
|
|
Int128 oldv, cmpv, newv;
|
|
|
|
|
|
|
|
cmpv = int128_make128(env->reserve_val2, env->reserve_val);
|
|
|
|
newv = int128_make128(new_lo, new_hi);
|
|
|
|
oldv = helper_atomic_cmpxchgo_be_mmu(env, addr, cmpv, newv,
|
|
|
|
opidx, GETPC());
|
|
|
|
success = int128_eq(oldv, cmpv);
|
|
|
|
}
|
|
|
|
env->reserve_addr = -1;
|
|
|
|
return env->so + success * CRF_EQ_BIT;
|
|
|
|
}
|
2018-06-27 00:19:10 +08:00
|
|
|
#endif
|
|
|
|
|
2009-01-03 21:31:19 +08:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Altivec extension helpers */
|
2009-07-27 22:13:06 +08:00
|
|
|
#if defined(HOST_WORDS_BIGENDIAN)
|
2009-01-03 21:31:19 +08:00
|
|
|
#define HI_IDX 0
|
|
|
|
#define LO_IDX 1
|
|
|
|
#else
|
|
|
|
#define HI_IDX 1
|
|
|
|
#define LO_IDX 0
|
|
|
|
#endif
|
|
|
|
|
2019-03-21 19:22:13 +08:00
|
|
|
/*
|
|
|
|
* We use msr_le to determine index ordering in a vector. However,
|
|
|
|
* byteswapping is not simply controlled by msr_le. We also need to
|
|
|
|
* take into account endianness of the target. This is done for the
|
|
|
|
* little-endian PPC64 user-mode target.
|
|
|
|
*/
|
2014-05-29 22:12:20 +08:00
|
|
|
|
2009-01-05 06:13:10 +08:00
|
|
|
#define LVE(name, access, swap, element) \
|
2012-05-30 12:23:40 +08:00
|
|
|
void helper_##name(CPUPPCState *env, ppc_avr_t *r, \
|
|
|
|
target_ulong addr) \
|
2009-01-05 06:13:10 +08:00
|
|
|
{ \
|
|
|
|
size_t n_elems = ARRAY_SIZE(r->element); \
|
2019-03-21 19:22:13 +08:00
|
|
|
int adjust = HI_IDX * (n_elems - 1); \
|
2009-01-05 06:13:10 +08:00
|
|
|
int sh = sizeof(r->element[0]) >> 1; \
|
|
|
|
int index = (addr & 0xf) >> sh; \
|
2012-05-30 12:23:21 +08:00
|
|
|
if (msr_le) { \
|
2013-09-25 15:42:46 +08:00
|
|
|
index = n_elems - index - 1; \
|
2014-05-29 22:12:20 +08:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
if (needs_byteswap(env)) { \
|
2012-05-30 12:23:21 +08:00
|
|
|
r->element[LO_IDX ? index : (adjust - index)] = \
|
2016-07-27 06:20:55 +08:00
|
|
|
swap(access(env, addr, GETPC())); \
|
2012-05-30 12:23:21 +08:00
|
|
|
} else { \
|
|
|
|
r->element[LO_IDX ? index : (adjust - index)] = \
|
2016-07-27 06:20:55 +08:00
|
|
|
access(env, addr, GETPC()); \
|
2012-05-30 12:23:21 +08:00
|
|
|
} \
|
2009-01-05 06:13:10 +08:00
|
|
|
}
|
|
|
|
#define I(x) (x)
|
2016-07-27 06:20:55 +08:00
|
|
|
LVE(lvebx, cpu_ldub_data_ra, I, u8)
|
|
|
|
LVE(lvehx, cpu_lduw_data_ra, bswap16, u16)
|
|
|
|
LVE(lvewx, cpu_ldl_data_ra, bswap32, u32)
|
2009-01-05 06:13:10 +08:00
|
|
|
#undef I
|
|
|
|
#undef LVE
|
|
|
|
|
2012-05-30 12:23:21 +08:00
|
|
|
#define STVE(name, access, swap, element) \
|
2012-05-30 12:23:40 +08:00
|
|
|
void helper_##name(CPUPPCState *env, ppc_avr_t *r, \
|
|
|
|
target_ulong addr) \
|
2012-05-30 12:23:21 +08:00
|
|
|
{ \
|
|
|
|
size_t n_elems = ARRAY_SIZE(r->element); \
|
|
|
|
int adjust = HI_IDX * (n_elems - 1); \
|
|
|
|
int sh = sizeof(r->element[0]) >> 1; \
|
|
|
|
int index = (addr & 0xf) >> sh; \
|
|
|
|
if (msr_le) { \
|
2013-09-25 15:42:46 +08:00
|
|
|
index = n_elems - index - 1; \
|
2014-05-29 22:12:20 +08:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
if (needs_byteswap(env)) { \
|
2012-05-30 12:23:40 +08:00
|
|
|
access(env, addr, swap(r->element[LO_IDX ? index : \
|
2016-07-27 06:20:55 +08:00
|
|
|
(adjust - index)]), \
|
|
|
|
GETPC()); \
|
2009-01-05 06:13:10 +08:00
|
|
|
} else { \
|
2012-05-30 12:23:40 +08:00
|
|
|
access(env, addr, r->element[LO_IDX ? index : \
|
2016-07-27 06:20:55 +08:00
|
|
|
(adjust - index)], GETPC()); \
|
2009-01-05 06:13:10 +08:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define I(x) (x)
|
2016-07-27 06:20:55 +08:00
|
|
|
STVE(stvebx, cpu_stb_data_ra, I, u8)
|
|
|
|
STVE(stvehx, cpu_stw_data_ra, bswap16, u16)
|
|
|
|
STVE(stvewx, cpu_stl_data_ra, bswap32, u32)
|
2009-01-05 06:13:10 +08:00
|
|
|
#undef I
|
|
|
|
#undef LVE
|
|
|
|
|
2016-12-09 20:17:20 +08:00
|
|
|
#ifdef TARGET_PPC64
|
|
|
|
#define GET_NB(rb) ((rb >> 56) & 0xFF)
|
|
|
|
|
|
|
|
#define VSX_LXVL(name, lj) \
|
|
|
|
void helper_##name(CPUPPCState *env, target_ulong addr, \
|
2019-06-16 20:37:49 +08:00
|
|
|
ppc_vsr_t *xt, target_ulong rb) \
|
2016-12-09 20:17:20 +08:00
|
|
|
{ \
|
2019-06-16 20:37:38 +08:00
|
|
|
ppc_vsr_t t; \
|
2016-12-09 20:17:20 +08:00
|
|
|
uint64_t nb = GET_NB(rb); \
|
2019-06-16 20:37:38 +08:00
|
|
|
int i; \
|
2016-12-09 20:17:20 +08:00
|
|
|
\
|
2019-06-16 20:37:38 +08:00
|
|
|
t.s128 = int128_zero(); \
|
2016-12-09 20:17:20 +08:00
|
|
|
if (nb) { \
|
|
|
|
nb = (nb >= 16) ? 16 : nb; \
|
|
|
|
if (msr_le && !lj) { \
|
|
|
|
for (i = 16; i > 16 - nb; i--) { \
|
2019-06-16 20:37:38 +08:00
|
|
|
t.VsrB(i - 1) = cpu_ldub_data_ra(env, addr, GETPC()); \
|
2016-12-09 20:17:20 +08:00
|
|
|
addr = addr_add(env, addr, 1); \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
for (i = 0; i < nb; i++) { \
|
2019-06-16 20:37:38 +08:00
|
|
|
t.VsrB(i) = cpu_ldub_data_ra(env, addr, GETPC()); \
|
2016-12-09 20:17:20 +08:00
|
|
|
addr = addr_add(env, addr, 1); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
2019-06-16 20:37:38 +08:00
|
|
|
*xt = t; \
|
2016-12-09 20:17:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
VSX_LXVL(lxvl, 0)
|
2016-12-09 20:17:21 +08:00
|
|
|
VSX_LXVL(lxvll, 1)
|
2016-12-09 20:17:20 +08:00
|
|
|
#undef VSX_LXVL
|
2016-12-09 20:17:22 +08:00
|
|
|
|
|
|
|
#define VSX_STXVL(name, lj) \
|
|
|
|
void helper_##name(CPUPPCState *env, target_ulong addr, \
|
2019-06-16 20:37:49 +08:00
|
|
|
ppc_vsr_t *xt, target_ulong rb) \
|
2016-12-09 20:17:22 +08:00
|
|
|
{ \
|
|
|
|
target_ulong nb = GET_NB(rb); \
|
2019-06-16 20:37:38 +08:00
|
|
|
int i; \
|
2016-12-09 20:17:22 +08:00
|
|
|
\
|
|
|
|
if (!nb) { \
|
|
|
|
return; \
|
|
|
|
} \
|
2019-06-16 20:37:38 +08:00
|
|
|
\
|
2016-12-09 20:17:22 +08:00
|
|
|
nb = (nb >= 16) ? 16 : nb; \
|
|
|
|
if (msr_le && !lj) { \
|
|
|
|
for (i = 16; i > 16 - nb; i--) { \
|
2019-06-16 20:37:38 +08:00
|
|
|
cpu_stb_data_ra(env, addr, xt->VsrB(i - 1), GETPC()); \
|
2016-12-09 20:17:22 +08:00
|
|
|
addr = addr_add(env, addr, 1); \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
for (i = 0; i < nb; i++) { \
|
2019-06-16 20:37:38 +08:00
|
|
|
cpu_stb_data_ra(env, addr, xt->VsrB(i), GETPC()); \
|
2016-12-09 20:17:22 +08:00
|
|
|
addr = addr_add(env, addr, 1); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
VSX_STXVL(stxvl, 0)
|
2016-12-09 20:17:23 +08:00
|
|
|
VSX_STXVL(stxvll, 1)
|
2016-12-09 20:17:22 +08:00
|
|
|
#undef VSX_STXVL
|
2016-12-09 20:17:20 +08:00
|
|
|
#undef GET_NB
|
|
|
|
#endif /* TARGET_PPC64 */
|
|
|
|
|
2009-01-03 21:31:19 +08:00
|
|
|
#undef HI_IDX
|
|
|
|
#undef LO_IDX
|
2014-12-19 00:34:34 +08:00
|
|
|
|
|
|
|
void helper_tbegin(CPUPPCState *env)
|
|
|
|
{
|
2019-03-21 19:22:13 +08:00
|
|
|
/*
|
|
|
|
* As a degenerate implementation, always fail tbegin. The reason
|
2014-12-19 00:34:34 +08:00
|
|
|
* given is "Nesting overflow". The "persistent" bit is set,
|
|
|
|
* providing a hint to the error handler to not retry. The TFIAR
|
|
|
|
* captures the address of the failure, which is this tbegin
|
2019-03-21 19:22:13 +08:00
|
|
|
* instruction. Instruction execution will continue with the next
|
|
|
|
* instruction in memory, which is precisely what we want.
|
2014-12-19 00:34:34 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
env->spr[SPR_TEXASR] =
|
|
|
|
(1ULL << TEXASR_FAILURE_PERSISTENT) |
|
|
|
|
(1ULL << TEXASR_NESTING_OVERFLOW) |
|
|
|
|
(msr_hv << TEXASR_PRIVILEGE_HV) |
|
|
|
|
(msr_pr << TEXASR_PRIVILEGE_PR) |
|
|
|
|
(1ULL << TEXASR_FAILURE_SUMMARY) |
|
|
|
|
(1ULL << TEXASR_TFIAR_EXACT);
|
|
|
|
env->spr[SPR_TFIAR] = env->nip | (msr_hv << 1) | msr_pr;
|
|
|
|
env->spr[SPR_TFHAR] = env->nip + 4;
|
|
|
|
env->crf[0] = 0xB; /* 0b1010 = transaction failure */
|
|
|
|
}
|