Files
xemu/include/exec/cpu_ldst_template.h
T

194 lines
5.0 KiB
C
Raw Normal View History

/*
* Software MMU support
*
2011-09-21 20:00:18 +00:00
* Generate inline load/store functions for one MMU mode and data
* size.
*
* Generate a store function as well as signed and unsigned loads. For
* 32 and 64 bit cases, also generate floating point functions with
* the same size.
*
* Not used directly but included from cpu_ldst.h.
2011-09-21 20:00:18 +00:00
*
* Copyright (c) 2003 Fabrice Bellard
*
* 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
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#if DATA_SIZE == 8
#define SUFFIX q
2003-10-27 21:22:23 +00:00
#define USUFFIX q
#define DATA_TYPE uint64_t
#elif DATA_SIZE == 4
#define SUFFIX l
2003-10-27 21:22:23 +00:00
#define USUFFIX l
#define DATA_TYPE uint32_t
#elif DATA_SIZE == 2
#define SUFFIX w
2003-10-27 21:22:23 +00:00
#define USUFFIX uw
#define DATA_TYPE uint16_t
#define DATA_STYPE int16_t
#elif DATA_SIZE == 1
#define SUFFIX b
2003-10-27 21:22:23 +00:00
#define USUFFIX ub
#define DATA_TYPE uint8_t
#define DATA_STYPE int8_t
#else
#error unsupported data size
#endif
#if DATA_SIZE == 8
#define RES_TYPE uint64_t
#else
2010-06-02 00:12:32 +04:00
#define RES_TYPE uint32_t
#endif
#ifdef SOFTMMU_CODE_ACCESS
2005-11-28 21:19:04 +00:00
#define ADDR_READ addr_code
#define MMUSUFFIX _cmmu
2005-11-28 21:19:04 +00:00
#else
#define ADDR_READ addr_read
#define MMUSUFFIX _mmu
2005-11-28 21:19:04 +00:00
#endif
2004-01-04 18:15:29 +00:00
/* generic load/store macros */
static inline RES_TYPE
glue(glue(cpu_ld, USUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr)
{
2008-05-10 10:14:22 +00:00
int page_index;
RES_TYPE res;
2005-01-03 23:35:10 +00:00
target_ulong addr;
int mmu_idx;
2003-10-27 21:22:23 +00:00
2005-01-03 23:35:10 +00:00
addr = ptr;
2008-05-10 10:14:22 +00:00
page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
mmu_idx = CPU_MMU_INDEX;
if (unlikely(env->tlb_table[mmu_idx][page_index].ADDR_READ !=
(addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
res = glue(glue(helper_ld, SUFFIX), MMUSUFFIX)(env, addr, mmu_idx);
} else {
uintptr_t hostaddr = addr + env->tlb_table[mmu_idx][page_index].addend;
2012-04-12 14:14:51 +02:00
res = glue(glue(ld, USUFFIX), _raw)(hostaddr);
}
return res;
}
#if DATA_SIZE <= 2
static inline int
glue(glue(cpu_lds, SUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr)
{
2008-05-10 10:14:22 +00:00
int res, page_index;
2005-01-03 23:35:10 +00:00
target_ulong addr;
int mmu_idx;
2003-10-27 21:22:23 +00:00
2005-01-03 23:35:10 +00:00
addr = ptr;
2008-05-10 10:14:22 +00:00
page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
mmu_idx = CPU_MMU_INDEX;
if (unlikely(env->tlb_table[mmu_idx][page_index].ADDR_READ !=
(addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
res = (DATA_STYPE)glue(glue(helper_ld, SUFFIX),
MMUSUFFIX)(env, addr, mmu_idx);
} else {
uintptr_t hostaddr = addr + env->tlb_table[mmu_idx][page_index].addend;
2012-04-12 14:14:51 +02:00
res = glue(glue(lds, SUFFIX), _raw)(hostaddr);
}
return res;
}
#endif
#ifndef SOFTMMU_CODE_ACCESS
2005-11-28 21:19:04 +00:00
2004-01-04 18:15:29 +00:00
/* generic store macro */
static inline void
glue(glue(cpu_st, SUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr,
RES_TYPE v)
{
2008-05-10 10:14:22 +00:00
int page_index;
2005-01-03 23:35:10 +00:00
target_ulong addr;
int mmu_idx;
2003-10-27 21:22:23 +00:00
2005-01-03 23:35:10 +00:00
addr = ptr;
2008-05-10 10:14:22 +00:00
page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
mmu_idx = CPU_MMU_INDEX;
if (unlikely(env->tlb_table[mmu_idx][page_index].addr_write !=
(addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
glue(glue(helper_st, SUFFIX), MMUSUFFIX)(env, addr, v, mmu_idx);
} else {
uintptr_t hostaddr = addr + env->tlb_table[mmu_idx][page_index].addend;
2012-04-12 14:14:51 +02:00
glue(glue(st, SUFFIX), _raw)(hostaddr, v);
}
}
2005-11-28 21:19:04 +00:00
2004-01-04 18:15:29 +00:00
2004-01-04 23:56:24 +00:00
#if DATA_SIZE == 8
static inline float64 glue(cpu_ldfq, MEMSUFFIX)(CPUArchState *env,
target_ulong ptr)
2004-01-04 23:56:24 +00:00
{
union {
float64 d;
2004-01-04 23:56:24 +00:00
uint64_t i;
} u;
u.i = glue(cpu_ldq, MEMSUFFIX)(env, ptr);
2004-01-04 23:56:24 +00:00
return u.d;
}
static inline void glue(cpu_stfq, MEMSUFFIX)(CPUArchState *env,
target_ulong ptr, float64 v)
2004-01-04 23:56:24 +00:00
{
union {
float64 d;
2004-01-04 23:56:24 +00:00
uint64_t i;
} u;
u.d = v;
glue(cpu_stq, MEMSUFFIX)(env, ptr, u.i);
2004-01-04 23:56:24 +00:00
}
#endif /* DATA_SIZE == 8 */
#if DATA_SIZE == 4
static inline float32 glue(cpu_ldfl, MEMSUFFIX)(CPUArchState *env,
target_ulong ptr)
2004-01-04 23:56:24 +00:00
{
union {
float32 f;
2004-01-04 23:56:24 +00:00
uint32_t i;
} u;
u.i = glue(cpu_ldl, MEMSUFFIX)(env, ptr);
2004-01-04 23:56:24 +00:00
return u.f;
}
static inline void glue(cpu_stfl, MEMSUFFIX)(CPUArchState *env,
target_ulong ptr, float32 v)
2004-01-04 23:56:24 +00:00
{
union {
float32 f;
2004-01-04 23:56:24 +00:00
uint32_t i;
} u;
u.f = v;
glue(cpu_stl, MEMSUFFIX)(env, ptr, u.i);
2004-01-04 23:56:24 +00:00
}
#endif /* DATA_SIZE == 4 */
#endif /* !SOFTMMU_CODE_ACCESS */
2005-11-28 21:19:04 +00:00
#undef RES_TYPE
#undef DATA_TYPE
#undef DATA_STYPE
#undef SUFFIX
2003-10-27 21:22:23 +00:00
#undef USUFFIX
#undef DATA_SIZE
2003-10-27 21:22:23 +00:00
#undef MMUSUFFIX
2005-11-28 21:19:04 +00:00
#undef ADDR_READ