2004-01-05 01:58:38 +03:00
|
|
|
/*
|
2012-05-30 08:23:40 +04:00
|
|
|
* PowerPC memory access emulation helpers for QEMU.
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2007-03-07 11:32:30 +03:00
|
|
|
* Copyright (c) 2003-2007 Jocelyn Mayer
|
2004-01-05 01:58:38 +03: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 00:47:01 +04:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2004-01-05 01:58:38 +03:00
|
|
|
*/
|
2011-07-13 16:44:15 +04:00
|
|
|
#include "cpu.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/host-utils.h"
|
2008-11-17 17:43:54 +03:00
|
|
|
#include "helper.h"
|
2004-01-05 01:58:38 +03:00
|
|
|
|
2007-10-26 01:35:50 +04:00
|
|
|
#include "helper_regs.h"
|
2007-03-21 01:11:31 +03:00
|
|
|
|
2011-07-13 16:44:15 +04:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/softmmu_exec.h"
|
2011-07-13 16:44:15 +04:00
|
|
|
#endif /* !defined(CONFIG_USER_ONLY) */
|
|
|
|
|
2005-07-05 02:17:05 +04:00
|
|
|
//#define DEBUG_OP
|
2009-01-16 00:48:06 +03:00
|
|
|
|
2008-11-30 19:23:56 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Memory load and stores */
|
|
|
|
|
2012-05-30 08:23:40 +04:00
|
|
|
static inline target_ulong addr_add(CPUPPCState *env, target_ulong addr,
|
|
|
|
target_long arg)
|
2008-11-30 19:23:56 +03:00
|
|
|
{
|
|
|
|
#if defined(TARGET_PPC64)
|
2012-06-20 23:20:29 +04:00
|
|
|
if (!msr_is_64bit(env, env->msr)) {
|
2012-05-30 08:23:21 +04:00
|
|
|
return (uint32_t)(addr + arg);
|
|
|
|
} else
|
2008-11-30 19:23:56 +03:00
|
|
|
#endif
|
2012-05-30 08:23:21 +04:00
|
|
|
{
|
|
|
|
return addr + arg;
|
|
|
|
}
|
2008-11-30 19:23:56 +03:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:40 +04:00
|
|
|
void helper_lmw(CPUPPCState *env, target_ulong addr, uint32_t reg)
|
2008-11-30 19:23:56 +03:00
|
|
|
{
|
2008-12-08 21:11:21 +03:00
|
|
|
for (; reg < 32; reg++) {
|
2012-05-30 08:23:21 +04:00
|
|
|
if (msr_le) {
|
2012-05-30 08:23:40 +04:00
|
|
|
env->gpr[reg] = bswap32(cpu_ldl_data(env, addr));
|
2012-05-30 08:23:21 +04:00
|
|
|
} else {
|
2012-05-30 08:23:40 +04:00
|
|
|
env->gpr[reg] = cpu_ldl_data(env, addr);
|
2012-05-30 08:23:21 +04:00
|
|
|
}
|
2012-05-30 08:23:40 +04:00
|
|
|
addr = addr_add(env, addr, 4);
|
2008-11-30 19:23:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:40 +04:00
|
|
|
void helper_stmw(CPUPPCState *env, target_ulong addr, uint32_t reg)
|
2008-11-30 19:23:56 +03:00
|
|
|
{
|
2008-12-08 21:11:21 +03:00
|
|
|
for (; reg < 32; reg++) {
|
2012-05-30 08:23:21 +04:00
|
|
|
if (msr_le) {
|
2012-05-30 08:23:40 +04:00
|
|
|
cpu_stl_data(env, addr, bswap32((uint32_t)env->gpr[reg]));
|
2012-05-30 08:23:21 +04:00
|
|
|
} else {
|
2012-05-30 08:23:40 +04:00
|
|
|
cpu_stl_data(env, addr, (uint32_t)env->gpr[reg]);
|
2012-05-30 08:23:21 +04:00
|
|
|
}
|
2012-05-30 08:23:40 +04:00
|
|
|
addr = addr_add(env, addr, 4);
|
2008-11-30 19:23:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:40 +04:00
|
|
|
void helper_lsw(CPUPPCState *env, target_ulong addr, uint32_t nb, uint32_t reg)
|
2008-11-30 19:24:21 +03:00
|
|
|
{
|
|
|
|
int sh;
|
2012-05-30 08:23:21 +04:00
|
|
|
|
2008-12-08 21:11:21 +03:00
|
|
|
for (; nb > 3; nb -= 4) {
|
2012-05-30 08:23:40 +04:00
|
|
|
env->gpr[reg] = cpu_ldl_data(env, addr);
|
2008-11-30 19:24:21 +03:00
|
|
|
reg = (reg + 1) % 32;
|
2012-05-30 08:23:40 +04:00
|
|
|
addr = addr_add(env, addr, 4);
|
2008-11-30 19:24:21 +03:00
|
|
|
}
|
|
|
|
if (unlikely(nb > 0)) {
|
|
|
|
env->gpr[reg] = 0;
|
2008-12-08 21:11:21 +03:00
|
|
|
for (sh = 24; nb > 0; nb--, sh -= 8) {
|
2012-05-30 08:23:40 +04:00
|
|
|
env->gpr[reg] |= cpu_ldub_data(env, addr) << sh;
|
|
|
|
addr = addr_add(env, addr, 1);
|
2008-11-30 19:24:21 +03: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...
|
|
|
|
*/
|
2012-05-30 08:23:40 +04:00
|
|
|
void helper_lswx(CPUPPCState *env, target_ulong addr, uint32_t reg,
|
|
|
|
uint32_t ra, uint32_t rb)
|
2008-11-30 19:24:21 +03:00
|
|
|
{
|
|
|
|
if (likely(xer_bc != 0)) {
|
|
|
|
if (unlikely((ra != 0 && reg < ra && (reg + xer_bc) > ra) ||
|
|
|
|
(reg < rb && (reg + xer_bc) > rb))) {
|
2012-05-30 08:23:23 +04:00
|
|
|
helper_raise_exception_err(env, POWERPC_EXCP_PROGRAM,
|
2008-12-12 01:42:14 +03:00
|
|
|
POWERPC_EXCP_INVAL |
|
|
|
|
POWERPC_EXCP_INVAL_LSWX);
|
2008-11-30 19:24:21 +03:00
|
|
|
} else {
|
2012-05-30 08:23:40 +04:00
|
|
|
helper_lsw(env, addr, xer_bc, reg);
|
2008-11-30 19:24:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:40 +04:00
|
|
|
void helper_stsw(CPUPPCState *env, target_ulong addr, uint32_t nb,
|
|
|
|
uint32_t reg)
|
2008-11-30 19:24:21 +03:00
|
|
|
{
|
|
|
|
int sh;
|
2012-05-30 08:23:21 +04:00
|
|
|
|
2008-12-08 21:11:21 +03:00
|
|
|
for (; nb > 3; nb -= 4) {
|
2012-05-30 08:23:40 +04:00
|
|
|
cpu_stl_data(env, addr, env->gpr[reg]);
|
2008-11-30 19:24:21 +03:00
|
|
|
reg = (reg + 1) % 32;
|
2012-05-30 08:23:40 +04:00
|
|
|
addr = addr_add(env, addr, 4);
|
2008-11-30 19:24:21 +03:00
|
|
|
}
|
|
|
|
if (unlikely(nb > 0)) {
|
2008-12-29 12:46:58 +03:00
|
|
|
for (sh = 24; nb > 0; nb--, sh -= 8) {
|
2012-05-30 08:23:40 +04:00
|
|
|
cpu_stb_data(env, addr, (env->gpr[reg] >> sh) & 0xFF);
|
|
|
|
addr = addr_add(env, addr, 1);
|
2008-12-29 12:46:58 +03:00
|
|
|
}
|
2008-11-30 19:24:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:40 +04:00
|
|
|
static void do_dcbz(CPUPPCState *env, target_ulong addr, int dcache_line_size)
|
2008-11-30 19:24:05 +03:00
|
|
|
{
|
|
|
|
int i;
|
2012-05-30 08:23:21 +04:00
|
|
|
|
|
|
|
addr &= ~(dcache_line_size - 1);
|
|
|
|
for (i = 0; i < dcache_line_size; i += 4) {
|
2012-05-30 08:23:40 +04:00
|
|
|
cpu_stl_data(env, addr + i, 0);
|
2008-11-30 19:24:05 +03:00
|
|
|
}
|
2012-05-30 08:23:21 +04:00
|
|
|
if (env->reserve_addr == addr) {
|
2009-08-03 19:43:25 +04:00
|
|
|
env->reserve_addr = (target_ulong)-1ULL;
|
2012-05-30 08:23:21 +04:00
|
|
|
}
|
2008-11-30 19:24:05 +03:00
|
|
|
}
|
|
|
|
|
2013-01-29 16:36:02 +04:00
|
|
|
void helper_dcbz(CPUPPCState *env, target_ulong addr, uint32_t is_dcbzl)
|
2008-11-30 19:24:05 +03:00
|
|
|
{
|
2013-01-29 16:36:02 +04:00
|
|
|
int dcbz_size = env->dcache_line_size;
|
2008-11-30 19:24:05 +03:00
|
|
|
|
2013-01-29 16:36:02 +04:00
|
|
|
#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
|
|
|
|
if (!is_dcbzl &&
|
|
|
|
(env->excp_model == POWERPC_EXCP_970) &&
|
|
|
|
((env->spr[SPR_970_HID5] >> 7) & 0x3) == 1) {
|
|
|
|
dcbz_size = 32;
|
2012-05-30 08:23:21 +04:00
|
|
|
}
|
2013-01-29 16:36:02 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* XXX add e500mc support */
|
|
|
|
|
|
|
|
do_dcbz(env, addr, dcbz_size);
|
2008-11-30 19:24:05 +03:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:40 +04:00
|
|
|
void helper_icbi(CPUPPCState *env, target_ulong addr)
|
2008-11-30 19:24:13 +03:00
|
|
|
{
|
2008-12-08 21:11:21 +03:00
|
|
|
addr &= ~(env->dcache_line_size - 1);
|
2008-11-30 19:24:13 +03:00
|
|
|
/* Invalidate one cache line :
|
|
|
|
* 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".
|
|
|
|
*/
|
2012-05-30 08:23:40 +04:00
|
|
|
cpu_ldl_data(env, addr);
|
2008-11-30 19:24:13 +03:00
|
|
|
}
|
|
|
|
|
2012-05-30 08:23:21 +04:00
|
|
|
/* XXX: to be tested */
|
2012-05-30 08:23:40 +04:00
|
|
|
target_ulong helper_lscbx(CPUPPCState *env, target_ulong addr, uint32_t reg,
|
|
|
|
uint32_t ra, uint32_t rb)
|
2008-11-30 19:24:30 +03:00
|
|
|
{
|
|
|
|
int i, c, d;
|
2012-05-30 08:23:21 +04:00
|
|
|
|
2008-11-30 19:24:30 +03:00
|
|
|
d = 24;
|
|
|
|
for (i = 0; i < xer_bc; i++) {
|
2012-05-30 08:23:40 +04:00
|
|
|
c = cpu_ldub_data(env, addr);
|
|
|
|
addr = addr_add(env, addr, 1);
|
2008-11-30 19:24:30 +03: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 08:23:21 +04:00
|
|
|
if (unlikely(c == xer_cmp)) {
|
2008-11-30 19:24:30 +03:00
|
|
|
break;
|
2012-05-30 08:23:21 +04:00
|
|
|
}
|
2008-11-30 19:24:30 +03:00
|
|
|
if (likely(d != 0)) {
|
|
|
|
d -= 8;
|
|
|
|
} else {
|
|
|
|
d = 24;
|
|
|
|
reg++;
|
|
|
|
reg = reg & 0x1F;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2009-01-03 16:31:19 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Altivec extension helpers */
|
2009-07-27 18:13:06 +04:00
|
|
|
#if defined(HOST_WORDS_BIGENDIAN)
|
2009-01-03 16:31:19 +03:00
|
|
|
#define HI_IDX 0
|
|
|
|
#define LO_IDX 1
|
|
|
|
#else
|
|
|
|
#define HI_IDX 1
|
|
|
|
#define LO_IDX 0
|
|
|
|
#endif
|
|
|
|
|
2009-01-05 01:13:10 +03:00
|
|
|
#define LVE(name, access, swap, element) \
|
2012-05-30 08:23:40 +04:00
|
|
|
void helper_##name(CPUPPCState *env, ppc_avr_t *r, \
|
|
|
|
target_ulong addr) \
|
2009-01-05 01:13:10 +03:00
|
|
|
{ \
|
|
|
|
size_t n_elems = ARRAY_SIZE(r->element); \
|
2012-05-30 08:23:21 +04:00
|
|
|
int adjust = HI_IDX*(n_elems - 1); \
|
2009-01-05 01:13:10 +03:00
|
|
|
int sh = sizeof(r->element[0]) >> 1; \
|
|
|
|
int index = (addr & 0xf) >> sh; \
|
2012-05-30 08:23:21 +04:00
|
|
|
\
|
|
|
|
if (msr_le) { \
|
|
|
|
r->element[LO_IDX ? index : (adjust - index)] = \
|
2012-05-30 08:23:40 +04:00
|
|
|
swap(access(env, addr)); \
|
2012-05-30 08:23:21 +04:00
|
|
|
} else { \
|
|
|
|
r->element[LO_IDX ? index : (adjust - index)] = \
|
2012-05-30 08:23:40 +04:00
|
|
|
access(env, addr); \
|
2012-05-30 08:23:21 +04:00
|
|
|
} \
|
2009-01-05 01:13:10 +03:00
|
|
|
}
|
|
|
|
#define I(x) (x)
|
2012-05-30 08:23:40 +04:00
|
|
|
LVE(lvebx, cpu_ldub_data, I, u8)
|
|
|
|
LVE(lvehx, cpu_lduw_data, bswap16, u16)
|
|
|
|
LVE(lvewx, cpu_ldl_data, bswap32, u32)
|
2009-01-05 01:13:10 +03:00
|
|
|
#undef I
|
|
|
|
#undef LVE
|
|
|
|
|
2012-05-30 08:23:21 +04:00
|
|
|
#define STVE(name, access, swap, element) \
|
2012-05-30 08:23:40 +04:00
|
|
|
void helper_##name(CPUPPCState *env, ppc_avr_t *r, \
|
|
|
|
target_ulong addr) \
|
2012-05-30 08:23:21 +04: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) { \
|
2012-05-30 08:23:40 +04:00
|
|
|
access(env, addr, swap(r->element[LO_IDX ? index : \
|
|
|
|
(adjust - index)])); \
|
2009-01-05 01:13:10 +03:00
|
|
|
} else { \
|
2012-05-30 08:23:40 +04:00
|
|
|
access(env, addr, r->element[LO_IDX ? index : \
|
|
|
|
(adjust - index)]); \
|
2009-01-05 01:13:10 +03:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define I(x) (x)
|
2012-05-30 08:23:40 +04:00
|
|
|
STVE(stvebx, cpu_stb_data, I, u8)
|
|
|
|
STVE(stvehx, cpu_stw_data, bswap16, u16)
|
|
|
|
STVE(stvewx, cpu_stl_data, bswap32, u32)
|
2009-01-05 01:13:10 +03:00
|
|
|
#undef I
|
|
|
|
#undef LVE
|
|
|
|
|
2009-01-03 16:31:19 +03:00
|
|
|
#undef HI_IDX
|
|
|
|
#undef LO_IDX
|