mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
exec/tswap: implement {ld,st}.*_p as functions instead of macros
Defining functions allows to use them from common code, by not depending on TARGET_BIG_ENDIAN. Remove previous macros from exec/cpu-all.h. By moving them out of cpu-all.h, we'll be able to break dependency on cpu.h for memory related functions coming in next commits. Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20250317183417.285700-3-pierrick.bouvier@linaro.org>
This commit is contained in:
committed by
Richard Henderson
parent
cfac5cdff5
commit
663310b05c
@@ -26,31 +26,6 @@
|
||||
#include "exec/tswap.h"
|
||||
#include "hw/core/cpu.h"
|
||||
|
||||
/* Target-endianness CPU memory access functions. These fit into the
|
||||
* {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h.
|
||||
*/
|
||||
#if TARGET_BIG_ENDIAN
|
||||
#define lduw_p(p) lduw_be_p(p)
|
||||
#define ldsw_p(p) ldsw_be_p(p)
|
||||
#define ldl_p(p) ldl_be_p(p)
|
||||
#define ldq_p(p) ldq_be_p(p)
|
||||
#define stw_p(p, v) stw_be_p(p, v)
|
||||
#define stl_p(p, v) stl_be_p(p, v)
|
||||
#define stq_p(p, v) stq_be_p(p, v)
|
||||
#define ldn_p(p, sz) ldn_be_p(p, sz)
|
||||
#define stn_p(p, sz, v) stn_be_p(p, sz, v)
|
||||
#else
|
||||
#define lduw_p(p) lduw_le_p(p)
|
||||
#define ldsw_p(p) ldsw_le_p(p)
|
||||
#define ldl_p(p) ldl_le_p(p)
|
||||
#define ldq_p(p) ldq_le_p(p)
|
||||
#define stw_p(p, v) stw_le_p(p, v)
|
||||
#define stl_p(p, v) stl_le_p(p, v)
|
||||
#define stq_p(p, v) stq_le_p(p, v)
|
||||
#define ldn_p(p, sz) ldn_le_p(p, sz)
|
||||
#define stn_p(p, sz, v) stn_le_p(p, sz, v)
|
||||
#endif
|
||||
|
||||
/* MMU memory access macros */
|
||||
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
|
||||
@@ -80,4 +80,74 @@ static inline void tswap64s(uint64_t *s)
|
||||
}
|
||||
}
|
||||
|
||||
/* Return ld{word}_{le,be}_p following target endianness. */
|
||||
#define LOAD_IMPL(word, args...) \
|
||||
do { \
|
||||
if (target_words_bigendian()) { \
|
||||
return glue(glue(ld, word), _be_p)(args); \
|
||||
} else { \
|
||||
return glue(glue(ld, word), _le_p)(args); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static inline int lduw_p(const void *ptr)
|
||||
{
|
||||
LOAD_IMPL(uw, ptr);
|
||||
}
|
||||
|
||||
static inline int ldsw_p(const void *ptr)
|
||||
{
|
||||
LOAD_IMPL(sw, ptr);
|
||||
}
|
||||
|
||||
static inline int ldl_p(const void *ptr)
|
||||
{
|
||||
LOAD_IMPL(l, ptr);
|
||||
}
|
||||
|
||||
static inline uint64_t ldq_p(const void *ptr)
|
||||
{
|
||||
LOAD_IMPL(q, ptr);
|
||||
}
|
||||
|
||||
static inline uint64_t ldn_p(const void *ptr, int sz)
|
||||
{
|
||||
LOAD_IMPL(n, ptr, sz);
|
||||
}
|
||||
|
||||
#undef LOAD_IMPL
|
||||
|
||||
/* Call st{word}_{le,be}_p following target endianness. */
|
||||
#define STORE_IMPL(word, args...) \
|
||||
do { \
|
||||
if (target_words_bigendian()) { \
|
||||
glue(glue(st, word), _be_p)(args); \
|
||||
} else { \
|
||||
glue(glue(st, word), _le_p)(args); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
static inline void stw_p(void *ptr, uint16_t v)
|
||||
{
|
||||
STORE_IMPL(w, ptr, v);
|
||||
}
|
||||
|
||||
static inline void stl_p(void *ptr, uint32_t v)
|
||||
{
|
||||
STORE_IMPL(l, ptr, v);
|
||||
}
|
||||
|
||||
static inline void stq_p(void *ptr, uint64_t v)
|
||||
{
|
||||
STORE_IMPL(q, ptr, v);
|
||||
}
|
||||
|
||||
static inline void stn_p(void *ptr, int sz, uint64_t v)
|
||||
{
|
||||
STORE_IMPL(n, ptr, sz, v);
|
||||
}
|
||||
|
||||
#undef STORE_IMPL
|
||||
|
||||
#endif /* TSWAP_H */
|
||||
|
||||
Reference in New Issue
Block a user