Skip to contentSkip to conversation

RFC: reverse-endian softmmu memory accessors

Qemu-devel J. Mayer 3 participants 12 messages Oct 13, 2007 – Oct 15, 2007

lore
Share & tools
lore

J. Mayer

author
#0 lore raw

The problem:
some CPU architectures, namely PowerPC and maybe others, offers facilities to access the memory or I/O in the reverse endianness, ie little-endian instead of big-endian for PowerPC, or provide instruction to make memory accesses in the "reverse-endian". This is implemented as a global flag on some CPU. This case is already handled by the PowerPC emulation but is is far from being optimal. Some other implementations allow the OS to store an "reverse-endian" flag in the TLB or the segment descriptors, thus providing per-page or per-segment endianness control. This is mostly used to ease driver migration from a PC platform to PowerPC without taking any care of the device endianness in the driver code (yes, this is bad...).

Proposal:
here's a patch that implement "reverse-endian" low-level memory accessors. It also provide an IO_MEM_REVERSE flag for TLBs. This flag is handled in the I/O case of softmmu low-level routines which means that it does not slowdown "native-endian" memory accesses and only add a one-bit test on the "native-endian" I/O access, which should not be a problem as I/O accesses are already slower, being handled via a callback. As a side effect this patch allows me to delete large parts of the target-ppc/op_mem.h and target-ppc/op_helper_mem.h as it makes little-endian memory accessors directly available. And the translated code for all little-endian access also becomes smaller, which has even a visible effect on the mean translated block size (as reported by the "info jit" monitor command) as lwbrx and lhbrx, which does memory accesses with byteswap, are widely used in PowerPC code.

Warning:
this patch is to be taken as a proof of concept, for now. It works and does not bring any visible regression to the PowerPC emulation but may be bugged somewhere and generates conflicts if applied against the CPU_MMU_INDEX patch. It is very invasive in the PowerPC target code but needs just a few adds for other targets. It also brings quite a lot of changes in the softmmu headers but is supposed not to change the "native-endian" pathes (or it's a bug).
One will also notice that I also added "reverse-endian" byte access routines. Those are, in fact, not needed but I let them just for consistency.

Please comment.

Signature · 2 lines
J. Mayer <[email protected]>
Never organized

Index: cpu-all.h
===================================================================
RCS file: /sources/qemu/qemu/cpu-all.h,v
retrieving revision 1.76

cpu-all.h +85 -2
diff -u -d -d -p -r1.76 cpu-all.h
@@ -161,7 +161,7 @@ typedef union {
  *
  * endian is:
  * (empty): target cpu endianness or 8 bit access
- *   r    : reversed target cpu endianness (not implemented yet)
+ *   r    : reversed target cpu endianness
  *   be   : big endian (not implemented yet)
  *   le   : little endian (not implemented yet)
  *
@@ -557,6 +557,7 @@ static inline void stfq_be_p(void *ptr, 
 
 /* target CPU memory access functions */
 #if defined(TARGET_WORDS_BIGENDIAN)
+/* native-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)
@@ -568,7 +569,20 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_p(p, v) stq_be_p(p, v)
 #define stfl_p(p, v) stfl_be_p(p, v)
 #define stfq_p(p, v) stfq_be_p(p, v)
+/* reverse-endian */
+#define lduwr_p(p) lduw_le_p(p)
+#define ldswr_p(p) ldsw_le_p(p)
+#define ldlr_p(p) ldl_le_p(p)
+#define ldqr_p(p) ldq_le_p(p)
+#define ldflr_p(p) ldfl_le_p(p)
+#define ldfqr_p(p) ldfq_le_p(p)
+#define stwr_p(p, v) stw_le_p(p, v)
+#define stlr_p(p, v) stl_le_p(p, v)
+#define stqr_p(p, v) stq_le_p(p, v)
+#define stflr_p(p, v) stfl_le_p(p, v)
+#define stfqr_p(p, v) stfq_le_p(p, v)
 #else
+/* native-endian */
 #define lduw_p(p) lduw_le_p(p)
 #define ldsw_p(p) ldsw_le_p(p)
 #define ldl_p(p) ldl_le_p(p)
@@ -580,6 +594,18 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_p(p, v) stq_le_p(p, v)
 #define stfl_p(p, v) stfl_le_p(p, v)
 #define stfq_p(p, v) stfq_le_p(p, v)
+/* reverse-endian */
+#define lduwr_p(p) lduw_be_p(p)
+#define ldswr_p(p) ldsw_be_p(p)
+#define ldlr_p(p) ldl_be_p(p)
+#define ldqr_p(p) ldq_be_p(p)
+#define ldflr_p(p) ldfl_be_p(p)
+#define ldfqr_p(p) ldfq_be_p(p)
+#define stwr_p(p, v) stw_be_p(p, v)
+#define stlr_p(p, v) stl_be_p(p, v)
+#define stqr_p(p, v) stq_be_p(p, v)
+#define stflr_p(p, v) stfl_be_p(p, v)
+#define stfqr_p(p, v) stfq_be_p(p, v)
 #endif
 
 /* MMU memory access macros */
@@ -605,6 +631,7 @@ static inline void stfq_be_p(void *ptr, 
 #define laddr(x) (uint8_t *)(long)(x)
 #endif
 
+/* native-endian */
 #define ldub_raw(p) ldub_p(laddr((p)))
 #define ldsb_raw(p) ldsb_p(laddr((p)))
 #define lduw_raw(p) lduw_p(laddr((p)))
@@ -619,11 +646,26 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_raw(p, v) stq_p(saddr((p)), v)
 #define stfl_raw(p, v) stfl_p(saddr((p)), v)
 #define stfq_raw(p, v) stfq_p(saddr((p)), v)
-
+/* reverse endian */
+#define ldubr_raw(p) ldub_p(laddr((p)))
+#define ldsbr_raw(p) ldsb_p(laddr((p)))
+#define lduwr_raw(p) lduwr_p(laddr((p)))
+#define ldswr_raw(p) ldswr_p(laddr((p)))
+#define ldlr_raw(p) ldlr_p(laddr((p)))
+#define ldqr_raw(p) ldqr_p(laddr((p)))
+#define ldflr_raw(p) ldflr_p(laddr((p)))
+#define ldfqr_raw(p) ldfqr_p(laddr((p)))
+#define stbr_raw(p, v) stb_p(saddr((p)), v)
+#define stwr_raw(p, v) stwr_p(saddr((p)), v)
+#define stlr_raw(p, v) stlr_p(saddr((p)), v)
+#define stqr_raw(p, v) stqr_p(saddr((p)), v)
+#define stflr_raw(p, v) stflr_p(saddr((p)), v)
+#define stfqr_raw(p, v) stfqr_p(saddr((p)), v)
 
 #if defined(CONFIG_USER_ONLY)
 
 /* if user mode, no other memory access functions */
+/* native-endian */
 #define ldub(p) ldub_raw(p)
 #define ldsb(p) ldsb_raw(p)
 #define lduw(p) lduw_raw(p)
@@ -638,14 +680,38 @@ static inline void stfq_be_p(void *ptr, 
 #define stq(p, v) stq_raw(p, v)
 #define stfl(p, v) stfl_raw(p, v)
 #define stfq(p, v) stfq_raw(p, v)
+/* reverse-endian */
+#define ldubr(p) ldub_raw(p)
+#define ldsbr(p) ldsb_raw(p)
+#define lduwr(p) lduwr_raw(p)
+#define ldswr(p) ldswr_raw(p)
+#define ldlr(p) ldlr_raw(p)
+#define ldqr(p) ldqr_raw(p)
+#define ldflr(p) ldflr_raw(p)
+#define ldfqr(p) ldfqr_raw(p)
+#define stbr(p, v) stb_raw(p, v)
+#define stwr(p, v) stwr_raw(p, v)
+#define stlr(p, v) stlr_raw(p, v)
+#define stqr(p, v) stqr_raw(p, v)
+#define stflr(p, v) stflr_raw(p, v)
+#define stfqr(p, v) stfqr_raw(p, v)
 
+/* native-endian */
 #define ldub_code(p) ldub_raw(p)
 #define ldsb_code(p) ldsb_raw(p)
 #define lduw_code(p) lduw_raw(p)
 #define ldsw_code(p) ldsw_raw(p)
 #define ldl_code(p) ldl_raw(p)
 #define ldq_code(p) ldq_raw(p)
+/* reverse-endian */
+#define ldubr_code(p) ldub_raw(p)
+#define ldsbr_code(p) ldsb_raw(p)
+#define lduwr_code(p) lduwr_raw(p)
+#define ldswr_code(p) ldswr_raw(p)
+#define ldlr_code(p) ldlr_raw(p)
+#define ldqr_code(p) ldqr_raw(p)
 
+/* native-endian */
 #define ldub_kernel(p) ldub_raw(p)
 #define ldsb_kernel(p) ldsb_raw(p)
 #define lduw_kernel(p) lduw_raw(p)
@@ -660,6 +726,21 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_kernel(p, v) stq_raw(p, v)
 #define stfl_kernel(p, v) stfl_raw(p, v)
 #define stfq_kernel(p, vt) stfq_raw(p, v)
+/* reverse-endian */
+#define ldubr_kernel(p) ldub_raw(p)
+#define ldsbr_kernel(p) ldsb_raw(p)
+#define lduwr_kernel(p) lduwr_raw(p)
+#define ldswr_kernel(p) ldswr_raw(p)
+#define ldlr_kernel(p) ldlr_raw(p)
+#define ldqr_kernel(p) ldqr_raw(p)
+#define ldflr_kernel(p) ldflr_raw(p)
+#define ldfqr_kernel(p) ldfqr_raw(p)
+#define stbr_kernel(p, v) stbr_raw(p, v)
+#define stwr_kernel(p, v) stwr_raw(p, v)
+#define stlr_kernel(p, v) stlr_raw(p, v)
+#define stqr_kernel(p, v) stqr_raw(p, v)
+#define stflr_kernel(p, v) stflr_raw(p, v)
+#define stfqr_kernel(p, vt) stfqr_raw(p, v)
 
 #endif /* defined(CONFIG_USER_ONLY) */
 
@@ -790,6 +871,8 @@ extern uint8_t *phys_ram_dirty;
    the physical address */
 #define IO_MEM_ROMD        (1)
 #define IO_MEM_SUBPAGE     (2)
+/* On some target CPUs, endiannes is stored in page tables */
+#define IO_MEM_REVERSE     (3)
 
 typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
 typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr);

Index: exec-all.h
===================================================================
RCS file: /sources/qemu/qemu/exec-all.h,v
retrieving revision 1.67

exec-all.h +16 -0
diff -u -d -d -p -r1.67 exec-all.h
@@ -562,6 +567,7 @@ extern int tb_invalidated_flag;
 #define MEMSUFFIX _code
 #define env cpu_single_env
 
+/* native-endian */
 #define DATA_SIZE 1
 #include "softmmu_header.h"
 
@@ -581,6 +587,21 @@ void tlb_fill(target_ulong addr, int is_
 #define DATA_SIZE 8
 #include "softmmu_header.h"
 
+/* reverse-endian */
+#define REVERSE_ENDIAN
+#define DATA_SIZE 1
+#include "softmmu_header.h"
+
+#define DATA_SIZE 2
+#include "softmmu_header.h"
+
+#define DATA_SIZE 4
+#include "softmmu_header.h"
+
+#define DATA_SIZE 8
+#include "softmmu_header.h"
+#undef REVERSE_ENDIAN
+
 #undef ACCESS_TYPE
 #undef MEMSUFFIX
 #undef env

Index: exec.c
===================================================================
RCS file: /sources/qemu/qemu/exec.c,v
retrieving revision 1.108

exec.c +96 -35

169 lines not on this page · raw message

Index: softmmu_header.h
===================================================================
RCS file: /sources/qemu/qemu/softmmu_header.h,v
retrieving revision 1.17

softmmu_header.h +76 -0

102 lines not on this page · raw message

Index: softmmu_template.h
===================================================================
RCS file: /sources/qemu/qemu/softmmu_template.h,v
retrieving revision 1.18

softmmu_template.h +196 -28

309 lines not on this page · raw message

Index: target-alpha/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/exec.h,v retrieving revision 1.3

exec.h +3 -0
diff -u -d -d -p -r1.3 exec.h
@@ -62,6 +62,9 @@ register uint64_t T2 asm(AREG3);
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 static inline void env_to_regs(void)

Index: target-alpha/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/op_helper.c,v retrieving revision 1.2

op_helper.c +16 -0
diff -u -d -d -p -r1.2 op_helper.c
@@ -1207,6 +1207,21 @@ void helper_st_phys_to_virt (void)
 
 #define MMUSUFFIX _mmu
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -1218,6 +1233,7 @@ void helper_st_phys_to_virt (void)
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-arm/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-arm/exec.h,v
retrieving revision 1.13

exec.h +3 -0
diff -u -d -d -p -r1.13 exec.h
@@ -64,6 +64,9 @@ static inline int cpu_halted(CPUState *e
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 /* In op_helper.c */

Index: target-arm/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-arm/op_helper.c,v retrieving revision 1.6

op_helper.c +16 -0
diff -u -d -d -p -r1.6 op_helper.c
@@ -180,6 +180,21 @@ void do_vfp_get_fpscr(void)
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -191,6 +206,7 @@ void do_vfp_get_fpscr(void)
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-cris/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-cris/exec.h,v
retrieving revision 1.1

exec.h +3 -0
diff -u -d -d -p -r1.1 exec.h
@@ -45,6 +45,9 @@ static inline void regs_to_env(void)
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 void cpu_cris_flush_flags(CPUCRISState *env, int cc_op);

Index: target-cris/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-cris/op_helper.c,v retrieving revision 1.1

op_helper.c +16 -0
diff -u -d -d -p -r1.1 op_helper.c
@@ -25,6 +25,21 @@
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -36,6 +51,7 @@
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* Try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-i386/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-i386/exec.h,v
retrieving revision 1.37

exec.h +3 -0
diff -u -d -d -p -r1.37 exec.h
@@ -217,6 +217,9 @@ void check_iol_DX(void);
 #if !defined(CONFIG_USER_ONLY)
 
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 
 static inline double ldfq(target_ulong ptr)
 {

Index: target-i386/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/helper.c,v retrieving revision 1.89

helper.c +16 -0
diff -u -d -d -p -r1.89 helper.c
@@ -3867,6 +3867,21 @@ void update_fp_status(void)
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -3878,6 +3893,7 @@ void update_fp_status(void)
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 #endif
 

Index: target-m68k/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-m68k/exec.h,v
retrieving revision 1.4

exec.h +3 -0
diff -u -d -d -p -r1.4 exec.h
@@ -38,6 +38,9 @@ static inline void regs_to_env(void)
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 void cpu_m68k_flush_flags(CPUM68KState *env, int cc_op);

Index: target-m68k/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-m68k/op_helper.c,v retrieving revision 1.6

op_helper.c +16 -0
diff -u -d -d -p -r1.6 op_helper.c
@@ -33,6 +33,21 @@ extern int semihosting_enabled;
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -44,6 +59,7 @@ extern int semihosting_enabled;
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* Try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-mips/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-mips/exec.h,v
retrieving revision 1.38

exec.h +3 -0
diff -u -d -d -p -r1.38 exec.h
@@ -54,6 +54,9 @@ register target_ulong T2 asm(AREG3);
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)

Index: target-mips/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_helper.c,v retrieving revision 1.65

op_helper.c +16 -0
diff -u -d -d -p -r1.65 op_helper.c
@@ -544,6 +544,21 @@ static void do_unaligned_access (target_
 #define MMUSUFFIX _mmu
 #define ALIGNED_ONLY
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -555,6 +570,7 @@ static void do_unaligned_access (target_
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr)
 {

Index: target-ppc/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/exec.h,v
retrieving revision 1.28

exec.h +5 -0
diff -u -d -d -p -r1.28 exec.h
@@ -91,7 +91,12 @@ static always_inline target_ulong rotl64
 #endif
 
 #if !defined(CONFIG_USER_ONLY)
+
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
+
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 void do_raise_exception_err (uint32_t exception, int error_code);

Index: target-ppc/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper.c,v retrieving revision 1.49

op_helper.c +16 -0
diff -u -d -d -p -r1.49 op_helper.c
@@ -2291,6 +2301,7 @@ DO_SPE_OP1(fsctuf);
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -2303,6 +2314,21 @@ DO_SPE_OP1(fsctuf);
 #define SHIFT 3
 #include "softmmu_template.h"
 
+/* Reverse-endian */
+#define REVERSE_ENDIAN
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+#undef REVERSE_ENDIAN
+
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not
    from generated code or from helper.c) */

Index: target-ppc/op_helper.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper.h,v retrieving revision 1.21

op_helper.h +0 -13
diff -u -d -d -p -r1.21 op_helper.h
@@ -37,19 +37,6 @@ void glue(do_POWER2_lfq_le, MEMSUFFIX) (
 void glue(do_POWER2_stfq, MEMSUFFIX) (void);
 void glue(do_POWER2_stfq_le, MEMSUFFIX) (void);
 
-#if defined(TARGET_PPC64)
-void glue(do_lsw_64, MEMSUFFIX) (int dst);
-void glue(do_lsw_le_64, MEMSUFFIX) (int dst);
-void glue(do_stsw_64, MEMSUFFIX) (int src);
-void glue(do_stsw_le_64, MEMSUFFIX) (int src);
-void glue(do_lmw_64, MEMSUFFIX) (int dst);
-void glue(do_lmw_le_64, MEMSUFFIX) (int dst);
-void glue(do_stmw_64, MEMSUFFIX) (int src);
-void glue(do_stmw_le_64, MEMSUFFIX) (int src);
-void glue(do_icbi_64, MEMSUFFIX) (void);
-void glue(do_dcbz_64, MEMSUFFIX) (void);
-#endif
-
 #else
 
 void do_print_mem_EA (target_ulong EA);

Index: target-ppc/op_helper_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper_mem.h,v retrieving revision 1.14

op_helper_mem.h +47 -277

442 lines not on this page · raw message

Index: target-ppc/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_mem.h,v retrieving revision 1.22

op_mem.h +149 -266

778 lines not on this page · raw message

Index: target-sh4/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-sh4/exec.h,v
retrieving revision 1.5

exec.h +3 -0
diff -u -d -d -p -r1.5 exec.h
@@ -48,6 +48,9 @@ static inline int cpu_halted(CPUState *e
 
 #ifndef CONFIG_USER_ONLY
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 #define RETURN() __asm__ __volatile__("")

Index: target-sh4/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-sh4/op_helper.c,v retrieving revision 1.4

op_helper.c +16 -0
diff -u -d -d -p -r1.4 op_helper.c
@@ -30,6 +30,7 @@ void do_raise_exception(void)
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -42,6 +43,21 @@ void do_raise_exception(void)
 #define SHIFT 3
 #include "softmmu_template.h"
 
+/* Reverse-endian */
+#define REVERSE_ENDIAN
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+#undef REVERSE_ENDIAN
+
 void tlb_fill(target_ulong addr, int is_write, int is_user, void *retaddr)
 {
     TranslationBlock *tb;

Index: target-sparc/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/exec.h,v retrieving revision 1.21

exec.h +3 -0
diff -u -d -d -p -r1.21 exec.h
@@ -100,6 +100,9 @@ void do_rdpsr();
 /* XXX: move that to a generic header */
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 static inline void env_to_regs(void)

Index: target-sparc/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/op_helper.c,v retrieving revision 1.41

op_helper.c +16 -0
diff -u -d -d -p -r1.41 op_helper.c
@@ -1497,6 +1497,21 @@ static void do_unaligned_access(target_u
 #define ALIGNED_ONLY
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -1508,6 +1523,7 @@ static void do_unaligned_access(target_u
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
                                 void *retaddr)
#1 lore raw
Quoted 4 lines · J. Mayer

The problem:
some CPU architectures, namely PowerPC and maybe others, offers facilities to access the memory or I/O in the reverse endianness, ie little-endian instead of big-endian for PowerPC, or provide instruction

Quoted 8 lines

to make memory accesses in the "reverse-endian". This is implemented as a global flag on some CPU. This case is already handled by the PowerPC emulation but is is far from being optimal. Some other implementations allow the OS to store an "reverse-endian" flag in the TLB or the segment descriptors, thus providing per-page or per-segment endianness control. This is mostly used to ease driver migration from a PC platform to PowerPC without taking any care of the device endianness in the driver code (yes, this is bad...).

Nice, this may be useful for Sparc64. It has a global CPU flag for endianness, individual pages can be marked as reverse endian, and finally there are instructions that access memory in reverse endian. The end result is a XOR of all these reverses. Though I don't know if any of these features are used at all.

Other memory access functions could be merged too. Is the 32 bit load with sign extension to 64 bits used in other architectures?

author
#2 lore raw
Quoted 14 lines · Blue Swirl
Quoted 4 lines · J. Mayer

The problem:
some CPU architectures, namely PowerPC and maybe others, offers facilities to access the memory or I/O in the reverse endianness, ie little-endian instead of big-endian for PowerPC, or provide instruction

Quoted 8 lines

to make memory accesses in the "reverse-endian". This is implemented as a global flag on some CPU. This case is already handled by the PowerPC emulation but is is far from being optimal. Some other implementations allow the OS to store an "reverse-endian" flag in the TLB or the segment descriptors, thus providing per-page or per-segment endianness control. This is mostly used to ease driver migration from a PC platform to PowerPC without taking any care of the device endianness in the driver code (yes, this is bad...).

Quoted 5 lines

Nice, this may be useful for Sparc64. It has a global CPU flag for endianness, individual pages can be marked as reverse endian, and finally there are instructions that access memory in reverse endian. The end result is a XOR of all these reverses. Though I don't know if any of these features are used at all.

I realized that I/O accesses for reverse-endian pages were not correct in the softmmu_template.h header. This new version fixes this. It also remove duplicated code in the case of unaligned accesses in a reverse-endian page.

Quoted 2 lines

Other memory access functions could be merged too. Is the 32 bit load with sign extension to 64 bits used in other architectures?

It's used by PowerPC. You're right, this should be fixed too. I did not add this fix because it has less impact than the endian stuff, at least on PowerPC were you have explicit load/store with reverse-endian instruction which perform poorly with the current implementation and are well optimized using the reverse-endian patch: the current implementation does 2 bytes-swaps when loading little-endian data from memory on a little-endian machine instead of ... nothing.

Signature · 2 lines
J. Mayer <[email protected]>
Never organized

Index: cpu-all.h
===================================================================
RCS file: /sources/qemu/qemu/cpu-all.h,v
retrieving revision 1.76

cpu-all.h +85 -2
diff -u -d -d -p -r1.76 cpu-all.h
@@ -161,7 +161,7 @@ typedef union {
  *
  * endian is:
  * (empty): target cpu endianness or 8 bit access
- *   r    : reversed target cpu endianness (not implemented yet)
+ *   r    : reversed target cpu endianness
  *   be   : big endian (not implemented yet)
  *   le   : little endian (not implemented yet)
  *
@@ -557,6 +557,7 @@ static inline void stfq_be_p(void *ptr, 
 
 /* target CPU memory access functions */
 #if defined(TARGET_WORDS_BIGENDIAN)
+/* native-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)
@@ -568,7 +569,20 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_p(p, v) stq_be_p(p, v)
 #define stfl_p(p, v) stfl_be_p(p, v)
 #define stfq_p(p, v) stfq_be_p(p, v)
+/* reverse-endian */
+#define lduwr_p(p) lduw_le_p(p)
+#define ldswr_p(p) ldsw_le_p(p)
+#define ldlr_p(p) ldl_le_p(p)
+#define ldqr_p(p) ldq_le_p(p)
+#define ldflr_p(p) ldfl_le_p(p)
+#define ldfqr_p(p) ldfq_le_p(p)
+#define stwr_p(p, v) stw_le_p(p, v)
+#define stlr_p(p, v) stl_le_p(p, v)
+#define stqr_p(p, v) stq_le_p(p, v)
+#define stflr_p(p, v) stfl_le_p(p, v)
+#define stfqr_p(p, v) stfq_le_p(p, v)
 #else
+/* native-endian */
 #define lduw_p(p) lduw_le_p(p)
 #define ldsw_p(p) ldsw_le_p(p)
 #define ldl_p(p) ldl_le_p(p)
@@ -580,6 +594,18 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_p(p, v) stq_le_p(p, v)
 #define stfl_p(p, v) stfl_le_p(p, v)
 #define stfq_p(p, v) stfq_le_p(p, v)
+/* reverse-endian */
+#define lduwr_p(p) lduw_be_p(p)
+#define ldswr_p(p) ldsw_be_p(p)
+#define ldlr_p(p) ldl_be_p(p)
+#define ldqr_p(p) ldq_be_p(p)
+#define ldflr_p(p) ldfl_be_p(p)
+#define ldfqr_p(p) ldfq_be_p(p)
+#define stwr_p(p, v) stw_be_p(p, v)
+#define stlr_p(p, v) stl_be_p(p, v)
+#define stqr_p(p, v) stq_be_p(p, v)
+#define stflr_p(p, v) stfl_be_p(p, v)
+#define stfqr_p(p, v) stfq_be_p(p, v)
 #endif
 
 /* MMU memory access macros */
@@ -605,6 +631,7 @@ static inline void stfq_be_p(void *ptr, 
 #define laddr(x) (uint8_t *)(long)(x)
 #endif
 
+/* native-endian */
 #define ldub_raw(p) ldub_p(laddr((p)))
 #define ldsb_raw(p) ldsb_p(laddr((p)))
 #define lduw_raw(p) lduw_p(laddr((p)))
@@ -619,11 +646,26 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_raw(p, v) stq_p(saddr((p)), v)
 #define stfl_raw(p, v) stfl_p(saddr((p)), v)
 #define stfq_raw(p, v) stfq_p(saddr((p)), v)
-
+/* reverse endian */
+#define ldubr_raw(p) ldub_p(laddr((p)))
+#define ldsbr_raw(p) ldsb_p(laddr((p)))
+#define lduwr_raw(p) lduwr_p(laddr((p)))
+#define ldswr_raw(p) ldswr_p(laddr((p)))
+#define ldlr_raw(p) ldlr_p(laddr((p)))
+#define ldqr_raw(p) ldqr_p(laddr((p)))
+#define ldflr_raw(p) ldflr_p(laddr((p)))
+#define ldfqr_raw(p) ldfqr_p(laddr((p)))
+#define stbr_raw(p, v) stb_p(saddr((p)), v)
+#define stwr_raw(p, v) stwr_p(saddr((p)), v)
+#define stlr_raw(p, v) stlr_p(saddr((p)), v)
+#define stqr_raw(p, v) stqr_p(saddr((p)), v)
+#define stflr_raw(p, v) stflr_p(saddr((p)), v)
+#define stfqr_raw(p, v) stfqr_p(saddr((p)), v)
 
 #if defined(CONFIG_USER_ONLY)
 
 /* if user mode, no other memory access functions */
+/* native-endian */
 #define ldub(p) ldub_raw(p)
 #define ldsb(p) ldsb_raw(p)
 #define lduw(p) lduw_raw(p)
@@ -638,14 +680,38 @@ static inline void stfq_be_p(void *ptr, 
 #define stq(p, v) stq_raw(p, v)
 #define stfl(p, v) stfl_raw(p, v)
 #define stfq(p, v) stfq_raw(p, v)
+/* reverse-endian */
+#define ldubr(p) ldub_raw(p)
+#define ldsbr(p) ldsb_raw(p)
+#define lduwr(p) lduwr_raw(p)
+#define ldswr(p) ldswr_raw(p)
+#define ldlr(p) ldlr_raw(p)
+#define ldqr(p) ldqr_raw(p)
+#define ldflr(p) ldflr_raw(p)
+#define ldfqr(p) ldfqr_raw(p)
+#define stbr(p, v) stb_raw(p, v)
+#define stwr(p, v) stwr_raw(p, v)
+#define stlr(p, v) stlr_raw(p, v)
+#define stqr(p, v) stqr_raw(p, v)
+#define stflr(p, v) stflr_raw(p, v)
+#define stfqr(p, v) stfqr_raw(p, v)
 
+/* native-endian */
 #define ldub_code(p) ldub_raw(p)
 #define ldsb_code(p) ldsb_raw(p)
 #define lduw_code(p) lduw_raw(p)
 #define ldsw_code(p) ldsw_raw(p)
 #define ldl_code(p) ldl_raw(p)
 #define ldq_code(p) ldq_raw(p)
+/* reverse-endian */
+#define ldubr_code(p) ldub_raw(p)
+#define ldsbr_code(p) ldsb_raw(p)
+#define lduwr_code(p) lduwr_raw(p)
+#define ldswr_code(p) ldswr_raw(p)
+#define ldlr_code(p) ldlr_raw(p)
+#define ldqr_code(p) ldqr_raw(p)
 
+/* native-endian */
 #define ldub_kernel(p) ldub_raw(p)
 #define ldsb_kernel(p) ldsb_raw(p)
 #define lduw_kernel(p) lduw_raw(p)
@@ -660,6 +726,21 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_kernel(p, v) stq_raw(p, v)
 #define stfl_kernel(p, v) stfl_raw(p, v)
 #define stfq_kernel(p, vt) stfq_raw(p, v)
+/* reverse-endian */
+#define ldubr_kernel(p) ldub_raw(p)
+#define ldsbr_kernel(p) ldsb_raw(p)
+#define lduwr_kernel(p) lduwr_raw(p)
+#define ldswr_kernel(p) ldswr_raw(p)
+#define ldlr_kernel(p) ldlr_raw(p)
+#define ldqr_kernel(p) ldqr_raw(p)
+#define ldflr_kernel(p) ldflr_raw(p)
+#define ldfqr_kernel(p) ldfqr_raw(p)
+#define stbr_kernel(p, v) stbr_raw(p, v)
+#define stwr_kernel(p, v) stwr_raw(p, v)
+#define stlr_kernel(p, v) stlr_raw(p, v)
+#define stqr_kernel(p, v) stqr_raw(p, v)
+#define stflr_kernel(p, v) stflr_raw(p, v)
+#define stfqr_kernel(p, vt) stfqr_raw(p, v)
 
 #endif /* defined(CONFIG_USER_ONLY) */
 
@@ -790,6 +871,8 @@ extern uint8_t *phys_ram_dirty;
    the physical address */
 #define IO_MEM_ROMD        (1)
 #define IO_MEM_SUBPAGE     (2)
+/* On some target CPUs, endiannes is stored in page tables */
+#define IO_MEM_REVERSE     (3)
 
 typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
 typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr);

Index: exec-all.h
===================================================================
RCS file: /sources/qemu/qemu/exec-all.h,v
retrieving revision 1.67

exec-all.h +16 -0
diff -u -d -d -p -r1.67 exec-all.h
@@ -569,6 +569,21 @@ void tlb_fill(target_ulong addr, int is_
 #define MEMSUFFIX _code
 #define env cpu_single_env
 
+/* native-endian */
+#define DATA_SIZE 1
+#include "softmmu_header.h"
+
+#define DATA_SIZE 2
+#include "softmmu_header.h"
+
+#define DATA_SIZE 4
+#include "softmmu_header.h"
+
+#define DATA_SIZE 8
+#include "softmmu_header.h"
+
+/* reverse-endian */
+#define REVERSE_ENDIAN
 #define DATA_SIZE 1
 #include "softmmu_header.h"
 
@@ -580,6 +595,7 @@ void tlb_fill(target_ulong addr, int is_
 
 #define DATA_SIZE 8
 #include "softmmu_header.h"
+#undef REVERSE_ENDIAN
 
 #undef ACCESS_TYPE
 #undef MEMSUFFIX

Index: exec.c
===================================================================
RCS file: /sources/qemu/qemu/exec.c,v
retrieving revision 1.108

exec.c +96 -35

169 lines not on this page · raw message

Index: softmmu_header.h
===================================================================
RCS file: /sources/qemu/qemu/softmmu_header.h,v
retrieving revision 1.17

softmmu_header.h +76 -0

100 lines not on this page · raw message

Index: softmmu_template.h
===================================================================
RCS file: /sources/qemu/qemu/softmmu_template.h,v
retrieving revision 1.18

softmmu_template.h +248 -31

384 lines not on this page · raw message

Index: target-alpha/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/exec.h,v retrieving revision 1.3

exec.h +3 -0
diff -u -d -d -p -r1.3 exec.h
@@ -62,6 +62,9 @@ register uint64_t T2 asm(AREG3);
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 static inline void env_to_regs(void)

Index: target-alpha/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/op_helper.c,v retrieving revision 1.2

op_helper.c +16 -0
diff -u -d -d -p -r1.2 op_helper.c
@@ -1207,6 +1207,21 @@ void helper_st_phys_to_virt (void)
 
 #define MMUSUFFIX _mmu
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -1218,6 +1233,7 @@ void helper_st_phys_to_virt (void)
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-arm/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-arm/exec.h,v
retrieving revision 1.13

exec.h +3 -0
diff -u -d -d -p -r1.13 exec.h
@@ -64,6 +64,9 @@ static inline int cpu_halted(CPUState *e
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 /* In op_helper.c */

Index: target-arm/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-arm/op_helper.c,v retrieving revision 1.6

op_helper.c +16 -0
diff -u -d -d -p -r1.6 op_helper.c
@@ -180,6 +180,21 @@ void do_vfp_get_fpscr(void)
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -191,6 +206,7 @@ void do_vfp_get_fpscr(void)
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-cris/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-cris/exec.h,v
retrieving revision 1.1

exec.h +3 -0
diff -u -d -d -p -r1.1 exec.h
@@ -50,6 +50,9 @@ void tlb_fill (target_ulong addr, int is
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 void cpu_cris_flush_flags(CPUCRISState *env, int cc_op);

Index: target-cris/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-cris/op_helper.c,v retrieving revision 1.1

op_helper.c +16 -0
diff -u -d -d -p -r1.1 op_helper.c
@@ -25,6 +25,21 @@
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -36,6 +51,7 @@
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* Try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-i386/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-i386/exec.h,v
retrieving revision 1.37

exec.h +3 -0
diff -u -d -d -p -r1.37 exec.h
@@ -217,6 +217,9 @@ void check_iol_DX(void);
 #if !defined(CONFIG_USER_ONLY)
 
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 
 static inline double ldfq(target_ulong ptr)
 {

Index: target-i386/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/helper.c,v retrieving revision 1.89

helper.c +16 -0
diff -u -d -d -p -r1.89 helper.c
@@ -3867,6 +3867,21 @@ void update_fp_status(void)
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -3878,6 +3893,7 @@ void update_fp_status(void)
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 #endif
 

Index: target-m68k/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-m68k/exec.h,v
retrieving revision 1.4

exec.h +3 -0
diff -u -d -d -p -r1.4 exec.h
@@ -42,6 +42,9 @@ int cpu_m68k_handle_mmu_fault (CPUState 
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 void cpu_m68k_flush_flags(CPUM68KState *env, int cc_op);

Index: target-m68k/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-m68k/op_helper.c,v retrieving revision 1.6

op_helper.c +16 -0
diff -u -d -d -p -r1.6 op_helper.c
@@ -33,6 +33,21 @@ extern int semihosting_enabled;
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -44,6 +59,7 @@ extern int semihosting_enabled;
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* Try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-mips/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-mips/exec.h,v
retrieving revision 1.38

exec.h +3 -0
diff -u -d -d -p -r1.38 exec.h
@@ -54,6 +54,9 @@ register target_ulong T2 asm(AREG3);
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)

Index: target-mips/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_helper.c,v retrieving revision 1.65

op_helper.c +16 -0
diff -u -d -d -p -r1.65 op_helper.c
@@ -544,6 +544,21 @@ static void do_unaligned_access (target_
 #define MMUSUFFIX _mmu
 #define ALIGNED_ONLY
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -555,6 +570,7 @@ static void do_unaligned_access (target_
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr)
 {

Index: target-ppc/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/exec.h,v
retrieving revision 1.28

exec.h +5 -0
diff -u -d -d -p -r1.28 exec.h
@@ -91,7 +91,12 @@ static always_inline target_ulong rotl64
 #endif
 
 #if !defined(CONFIG_USER_ONLY)
+
+#include "softmmu_exec.h"
+#define REVERSE_ENDIAN
 #include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
+
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 void do_raise_exception_err (uint32_t exception, int error_code);

Index: target-ppc/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper.c,v retrieving revision 1.49

op_helper.c +16 -0
diff -u -d -d -p -r1.49 op_helper.c
@@ -2291,6 +2291,21 @@ DO_SPE_OP1(fsctuf);
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -2302,6 +2317,7 @@ DO_SPE_OP1(fsctuf);
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-ppc/op_helper.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper.h,v retrieving revision 1.21

op_helper.h +0 -13
diff -u -d -d -p -r1.21 op_helper.h
@@ -37,19 +37,6 @@ void glue(do_POWER2_lfq_le, MEMSUFFIX) (
 void glue(do_POWER2_stfq, MEMSUFFIX) (void);
 void glue(do_POWER2_stfq_le, MEMSUFFIX) (void);
 
-#if defined(TARGET_PPC64)
-void glue(do_lsw_64, MEMSUFFIX) (int dst);
-void glue(do_lsw_le_64, MEMSUFFIX) (int dst);
-void glue(do_stsw_64, MEMSUFFIX) (int src);
-void glue(do_stsw_le_64, MEMSUFFIX) (int src);
-void glue(do_lmw_64, MEMSUFFIX) (int dst);
-void glue(do_lmw_le_64, MEMSUFFIX) (int dst);
-void glue(do_stmw_64, MEMSUFFIX) (int src);
-void glue(do_stmw_le_64, MEMSUFFIX) (int src);
-void glue(do_icbi_64, MEMSUFFIX) (void);
-void glue(do_dcbz_64, MEMSUFFIX) (void);
-#endif
-
 #else
 
 void do_print_mem_EA (target_ulong EA);

Index: target-ppc/op_helper_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper_mem.h,v retrieving revision 1.14

op_helper_mem.h +47 -277

442 lines not on this page · raw message

Index: target-ppc/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_mem.h,v retrieving revision 1.22

op_mem.h +149 -266

778 lines not on this page · raw message

Index: target-sh4/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-sh4/exec.h,v
retrieving revision 1.5

exec.h +3 -0
diff -u -d -d -p -r1.5 exec.h
@@ -48,6 +48,9 @@ static inline int cpu_halted(CPUState *e
 
 #ifndef CONFIG_USER_ONLY
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 #define RETURN() __asm__ __volatile__("")

Index: target-sh4/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-sh4/op_helper.c,v retrieving revision 1.4

op_helper.c +16 -0
diff -u -d -d -p -r1.4 op_helper.c
@@ -30,6 +30,21 @@ void do_raise_exception(void)
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -41,6 +56,7 @@ void do_raise_exception(void)
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 void tlb_fill(target_ulong addr, int is_write, int is_user, void *retaddr)
 {

Index: target-sparc/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/exec.h,v retrieving revision 1.21

exec.h +3 -0
diff -u -d -d -p -r1.21 exec.h
@@ -100,6 +100,9 @@ void do_rdpsr();
 /* XXX: move that to a generic header */
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 static inline void env_to_regs(void)

Index: target-sparc/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/op_helper.c,v retrieving revision 1.41

op_helper.c +16 -0
diff -u -d -d -p -r1.41 op_helper.c
@@ -1497,6 +1497,21 @@ static void do_unaligned_access(target_u
 #define ALIGNED_ONLY
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -1508,6 +1523,7 @@ static void do_unaligned_access(target_u
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
                                 void *retaddr)
#11 lore raw
In reply to Blue Swirl
Quoted 14 lines · Blue Swirl
Quoted 4 lines · J. Mayer

The problem:
some CPU architectures, namely PowerPC and maybe others, offers facilities to access the memory or I/O in the reverse endianness, ie little-endian instead of big-endian for PowerPC, or provide instruction

Quoted 8 lines

to make memory accesses in the "reverse-endian". This is implemented as a global flag on some CPU. This case is already handled by the PowerPC emulation but is is far from being optimal. Some other implementations allow the OS to store an "reverse-endian" flag in the TLB or the segment descriptors, thus providing per-page or per-segment endianness control. This is mostly used to ease driver migration from a PC platform to PowerPC without taking any care of the device endianness in the driver code (yes, this is bad...).

Quoted 5 lines

Nice, this may be useful for Sparc64. It has a global CPU flag for endianness, individual pages can be marked as reverse endian, and finally there are instructions that access memory in reverse endian. The end result is a XOR of all these reverses. Though I don't know if any of these features are used at all.

Likewise for the MIPS reverse endianness global flag.

Quoted 2 lines

Other memory access functions could be merged too. Is the 32 bit load with sign extension to 64 bits used in other architectures?

Yes for MIPS.

Thiemo

#3 lore raw
In reply to J. Mayer
Quoted 21 lines · J. Mayer
Quoted 14 lines · Blue Swirl
Quoted 4 lines · J. Mayer

The problem:
some CPU architectures, namely PowerPC and maybe others, offers facilities to access the memory or I/O in the reverse endianness, ie little-endian instead of big-endian for PowerPC, or provide instruction

Quoted 8 lines

to make memory accesses in the "reverse-endian". This is implemented as a global flag on some CPU. This case is already handled by the PowerPC emulation but is is far from being optimal. Some other implementations allow the OS to store an "reverse-endian" flag in the TLB or the segment descriptors, thus providing per-page or per-segment endianness control. This is mostly used to ease driver migration from a PC platform to PowerPC without taking any care of the device endianness in the driver code (yes, this is bad...).

Quoted 5 lines

Nice, this may be useful for Sparc64. It has a global CPU flag for endianness, individual pages can be marked as reverse endian, and finally there are instructions that access memory in reverse endian. The end result is a XOR of all these reverses. Though I don't know if any of these features are used at all.

Quoted 4 lines

I realized that I/O accesses for reverse-endian pages were not correct in the softmmu_template.h header. This new version fixes this. It also remove duplicated code in the case of unaligned accesses in a reverse-endian page.

I think 64 bit access case is not handled correctly, but to solve that it would be nice to extend the current IO access system to 64 bits.

author
#4 lore raw
Quoted 22 lines · Blue Swirl
Quoted 21 lines · J. Mayer
Quoted 19 lines · Blue Swirl
Quoted 4 lines · J. Mayer

The problem:
some CPU architectures, namely PowerPC and maybe others, offers facilities to access the memory or I/O in the reverse endianness, ie little-endian instead of big-endian for PowerPC, or provide instruction

Quoted 8 lines

to make memory accesses in the "reverse-endian". This is implemented as a global flag on some CPU. This case is already handled by the PowerPC emulation but is is far from being optimal. Some other implementations allow the OS to store an "reverse-endian" flag in the TLB or the segment descriptors, thus providing per-page or per-segment endianness control. This is mostly used to ease driver migration from a PC platform to PowerPC without taking any care of the device endianness in the driver code (yes, this is bad...).

Nice, this may be useful for Sparc64. It has a global CPU flag for endianness, individual pages can be marked as reverse endian, and finally there are instructions that access memory in reverse endian. The end result is a XOR of all these reverses. Though I don't know if any of these features are used at all.

Quoted 7 lines
Quoted 4 lines

I realized that I/O accesses for reverse-endian pages were not correct in the softmmu_template.h header. This new version fixes this. It also remove duplicated code in the case of unaligned accesses in a reverse-endian page.

I think 64 bit access case is not handled correctly, but to solve that it would be nice to extend the current IO access system to 64 bits.

I think that if it was previously correct, it should still be, but... I don't know how much having 64 bits I/O accesses is interresting, as I don't know if there are real hw buses that have 64 bits data path...

Here's another version taking care of your remark about ldl memory accessors.
* I replaced all ldl occurences with ldul
* when TARGET_LONG_BITS == 64, I also added ldsl accessors. And I started using it in the PowerPC memory access micro-ops. Then the patch is really more invasive than the previous ones. This still does not break PowerPC or i386 target, as it seems.

Signature · 2 lines
J. Mayer <[email protected]>
Never organized

Index: cpu-all.h
===================================================================
RCS file: /sources/qemu/qemu/cpu-all.h,v
retrieving revision 1.76

cpu-all.h +224 -23
diff -u -d -d -p -r1.76 cpu-all.h
@@ -161,7 +161,7 @@ typedef union {
  *
  * endian is:
  * (empty): target cpu endianness or 8 bit access
- *   r    : reversed target cpu endianness (not implemented yet)
+ *   r    : reversed target cpu endianness
  *   be   : big endian (not implemented yet)
  *   le   : little endian (not implemented yet)
  *
@@ -215,7 +215,32 @@ static inline int ldsw_le_p(void *ptr)
 #endif
 }
 
-static inline int ldl_le_p(void *ptr)
+#if (TARGET_LONG_BITS == 64)
+static inline int64_t ldul_le_p(void *ptr)
+{
+#ifdef __powerpc__
+    int val;
+    __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (ptr));
+    return (uint32_t)val;
+#else
+    uint8_t *p = ptr;
+    return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
+#endif
+}
+
+static inline int64_t ldsl_le_p(void *ptr)
+{
+#ifdef __powerpc__
+    int val;
+    __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (ptr));
+    return (int32_t)val;
+#else
+    uint8_t *p = ptr;
+    return (int32_t)(p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24));
+#endif
+}
+#else
+static inline int ldul_le_p(void *ptr)
 {
 #ifdef __powerpc__
     int val;
@@ -226,13 +251,14 @@ static inline int ldl_le_p(void *ptr)
     return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
 #endif
 }
+#endif
 
 static inline uint64_t ldq_le_p(void *ptr)
 {
     uint8_t *p = ptr;
     uint32_t v1, v2;
-    v1 = ldl_le_p(p);
-    v2 = ldl_le_p(p + 4);
+    v1 = ldul_le_p(p);
+    v2 = ldul_le_p(p + 4);
     return v1 | ((uint64_t)v2 << 32);
 }
 
@@ -275,7 +301,7 @@ static inline float32 ldfl_le_p(void *pt
         float32 f;
         uint32_t i;
     } u;
-    u.i = ldl_le_p(ptr);
+    u.i = ldul_le_p(ptr);
     return u.f;
 }
 
@@ -292,8 +318,8 @@ static inline void stfl_le_p(void *ptr, 
 static inline float64 ldfq_le_p(void *ptr)
 {
     CPU_DoubleU u;
-    u.l.lower = ldl_le_p(ptr);
-    u.l.upper = ldl_le_p(ptr + 4);
+    u.l.lower = ldul_le_p(ptr);
+    u.l.upper = ldul_le_p(ptr + 4);
     return u.d;
 }
 
@@ -317,11 +343,23 @@ static inline int ldsw_le_p(void *ptr)
     return *(int16_t *)ptr;
 }
 
-static inline int ldl_le_p(void *ptr)
+#if (TARGET_LONG_BITS == 64)
+static inline int64_t ldul_le_p(void *ptr)
 {
     return *(uint32_t *)ptr;
 }
 
+static inline int64_t ldsl_le_p(void *ptr)
+{
+    return *(int32_t *)ptr;
+}
+#else
+static inline int ldul_le_p(void *ptr)
+{
+    return *(uint32_t *)ptr;
+}
+#endif
+
 static inline uint64_t ldq_le_p(void *ptr)
 {
     return *(uint64_t *)ptr;
@@ -397,7 +435,38 @@ static inline int ldsw_be_p(void *ptr)
 #endif
 }
 
-static inline int ldl_be_p(void *ptr)
+#if (TARGET_LONG_BITS == 64)
+static inline int64_t ldul_be_p(void *ptr)
+{
+#if defined(__i386__) || defined(__x86_64__)
+    int val;
+    asm volatile ("movl %1, %0\n"
+                  "bswap %0\n"
+                  : "=r" (val)
+                  : "m" (*(uint32_t *)ptr));
+    return (uint32_t)val;
+#else
+    uint8_t *b = (uint8_t *) ptr;
+    return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
+#endif
+}
+
+static inline int64_t ldsl_be_p(void *ptr)
+{
+#if defined(__i386__) || defined(__x86_64__)
+    int val;
+    asm volatile ("movl %1, %0\n"
+                  "bswap %0\n"
+                  : "=r" (val)
+                  : "m" (*(uint32_t *)ptr));
+    return (int32_t)val;
+#else
+    uint8_t *b = (uint8_t *) ptr;
+    return (int32_t)((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]);
+#endif
+}
+#else
+static inline int ldul_be_p(void *ptr)
 {
 #if defined(__i386__) || defined(__x86_64__)
     int val;
@@ -411,12 +480,13 @@ static inline int ldl_be_p(void *ptr)
     return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
 #endif
 }
+#endif
 
 static inline uint64_t ldq_be_p(void *ptr)
 {
     uint32_t a,b;
-    a = ldl_be_p(ptr);
-    b = ldl_be_p(ptr+4);
+    a = ldul_be_p(ptr);
+    b = ldul_be_p(ptr+4);
     return (((uint64_t)a<<32)|b);
 }
 
@@ -464,7 +534,7 @@ static inline float32 ldfl_be_p(void *pt
         float32 f;
         uint32_t i;
     } u;
-    u.i = ldl_be_p(ptr);
+    u.i = ldul_be_p(ptr);
     return u.f;
 }
 
@@ -481,8 +551,8 @@ static inline void stfl_be_p(void *ptr, 
 static inline float64 ldfq_be_p(void *ptr)
 {
     CPU_DoubleU u;
-    u.l.upper = ldl_be_p(ptr);
-    u.l.lower = ldl_be_p(ptr + 4);
+    u.l.upper = ldul_be_p(ptr);
+    u.l.lower = ldul_be_p(ptr + 4);
     return u.d;
 }
 
@@ -506,11 +576,23 @@ static inline int ldsw_be_p(void *ptr)
     return *(int16_t *)ptr;
 }
 
-static inline int ldl_be_p(void *ptr)
+#if (TARGET_LONG_BITS == 64)
+static inline int64_t ldul_be_p(void *ptr)
 {
     return *(uint32_t *)ptr;
 }
 
+static inline int64_t ldsl_be_p(void *ptr)
+{
+    return *(int32_t *)ptr;
+}
+#else
+static inline int ldul_be_p(void *ptr)
+{
+    return *(uint32_t *)ptr;
+}
+#endif
+
 static inline uint64_t ldq_be_p(void *ptr)
 {
     return *(uint64_t *)ptr;
@@ -557,9 +639,13 @@ static inline void stfq_be_p(void *ptr, 
 
 /* target CPU memory access functions */
 #if defined(TARGET_WORDS_BIGENDIAN)
+/* native-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 ldul_p(p) ldul_be_p(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_p(p) ldsl_be_p(p)
+#endif
 #define ldq_p(p) ldq_be_p(p)
 #define ldfl_p(p) ldfl_be_p(p)
 #define ldfq_p(p) ldfq_be_p(p)
@@ -568,10 +654,29 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_p(p, v) stq_be_p(p, v)
 #define stfl_p(p, v) stfl_be_p(p, v)
 #define stfq_p(p, v) stfq_be_p(p, v)
+/* reverse-endian */
+#define lduwr_p(p) lduw_le_p(p)
+#define ldswr_p(p) ldsw_le_p(p)
+#define ldulr_p(p) ldul_le_p(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldslr_p(p) ldsl_le_p(p)
+#endif
+#define ldqr_p(p) ldq_le_p(p)
+#define ldflr_p(p) ldfl_le_p(p)
+#define ldfqr_p(p) ldfq_le_p(p)
+#define stwr_p(p, v) stw_le_p(p, v)
+#define stlr_p(p, v) stl_le_p(p, v)
+#define stqr_p(p, v) stq_le_p(p, v)
+#define stflr_p(p, v) stfl_le_p(p, v)
+#define stfqr_p(p, v) stfq_le_p(p, v)
 #else
+/* native-endian */
 #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 ldul_p(p) ldul_le_p(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_p(p) ldsl_le_p(p)
+#endif
 #define ldq_p(p) ldq_le_p(p)
 #define ldfl_p(p) ldfl_le_p(p)
 #define ldfq_p(p) ldfq_le_p(p)
@@ -580,6 +685,21 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_p(p, v) stq_le_p(p, v)
 #define stfl_p(p, v) stfl_le_p(p, v)
 #define stfq_p(p, v) stfq_le_p(p, v)
+/* reverse-endian */
+#define lduwr_p(p) lduw_be_p(p)
+#define ldswr_p(p) ldsw_be_p(p)
+#define ldulr_p(p) ldul_be_p(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldslr_p(p) ldsl_be_p(p)
+#endif
+#define ldqr_p(p) ldq_be_p(p)
+#define ldflr_p(p) ldfl_be_p(p)
+#define ldfqr_p(p) ldfq_be_p(p)
+#define stwr_p(p, v) stw_be_p(p, v)
+#define stlr_p(p, v) stl_be_p(p, v)
+#define stqr_p(p, v) stq_be_p(p, v)
+#define stflr_p(p, v) stfl_be_p(p, v)
+#define stfqr_p(p, v) stfq_be_p(p, v)
 #endif
 
 /* MMU memory access macros */
@@ -605,11 +725,15 @@ static inline void stfq_be_p(void *ptr, 
 #define laddr(x) (uint8_t *)(long)(x)
 #endif
 
+/* native-endian */
 #define ldub_raw(p) ldub_p(laddr((p)))
 #define ldsb_raw(p) ldsb_p(laddr((p)))
 #define lduw_raw(p) lduw_p(laddr((p)))
 #define ldsw_raw(p) ldsw_p(laddr((p)))
-#define ldl_raw(p) ldl_p(laddr((p)))
+#define ldul_raw(p) ldul_p(laddr((p)))
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_raw(p) ldsl_p(laddr((p)))
+#endif
 #define ldq_raw(p) ldq_p(laddr((p)))
 #define ldfl_raw(p) ldfl_p(laddr((p)))
 #define ldfq_raw(p) ldfq_p(laddr((p)))
@@ -619,16 +743,37 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_raw(p, v) stq_p(saddr((p)), v)
 #define stfl_raw(p, v) stfl_p(saddr((p)), v)
 #define stfq_raw(p, v) stfq_p(saddr((p)), v)
-
+/* reverse endian */
+#define ldubr_raw(p) ldub_p(laddr((p)))
+#define ldsbr_raw(p) ldsb_p(laddr((p)))
+#define lduwr_raw(p) lduwr_p(laddr((p)))
+#define ldswr_raw(p) ldswr_p(laddr((p)))
+#define ldulr_raw(p) ldulr_p(laddr((p)))
+#if (TARGET_LONG_BITS == 64)
+#define ldslr_raw(p) ldslr_p(laddr((p)))
+#endif
+#define ldqr_raw(p) ldqr_p(laddr((p)))
+#define ldflr_raw(p) ldflr_p(laddr((p)))
+#define ldfqr_raw(p) ldfqr_p(laddr((p)))
+#define stbr_raw(p, v) stb_p(saddr((p)), v)
+#define stwr_raw(p, v) stwr_p(saddr((p)), v)
+#define stlr_raw(p, v) stlr_p(saddr((p)), v)
+#define stqr_raw(p, v) stqr_p(saddr((p)), v)
+#define stflr_raw(p, v) stflr_p(saddr((p)), v)
+#define stfqr_raw(p, v) stfqr_p(saddr((p)), v)
 
 #if defined(CONFIG_USER_ONLY)
 
 /* if user mode, no other memory access functions */
+/* native-endian */
 #define ldub(p) ldub_raw(p)
 #define ldsb(p) ldsb_raw(p)
 #define lduw(p) lduw_raw(p)
 #define ldsw(p) ldsw_raw(p)
-#define ldl(p) ldl_raw(p)
+#define ldul(p) ldul_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl(p) ldsl_raw(p)
+#endif
 #define ldq(p) ldq_raw(p)
 #define ldfl(p) ldfl_raw(p)
 #define ldfq(p) ldfq_raw(p)
@@ -638,19 +783,55 @@ static inline void stfq_be_p(void *ptr, 
 #define stq(p, v) stq_raw(p, v)
 #define stfl(p, v) stfl_raw(p, v)
 #define stfq(p, v) stfq_raw(p, v)
+/* reverse-endian */
+#define ldubr(p) ldub_raw(p)
+#define ldsbr(p) ldsb_raw(p)
+#define lduwr(p) lduwr_raw(p)
+#define ldswr(p) ldswr_raw(p)
+#define ldulr(p) ldulr_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldslr(p) ldslr_raw(p)
+#endif
+#define ldqr(p) ldqr_raw(p)
+#define ldflr(p) ldflr_raw(p)
+#define ldfqr(p) ldfqr_raw(p)
+#define stbr(p, v) stb_raw(p, v)
+#define stwr(p, v) stwr_raw(p, v)
+#define stlr(p, v) stlr_raw(p, v)
+#define stqr(p, v) stqr_raw(p, v)
+#define stflr(p, v) stflr_raw(p, v)
+#define stfqr(p, v) stfqr_raw(p, v)
 
+/* native-endian */
 #define ldub_code(p) ldub_raw(p)
 #define ldsb_code(p) ldsb_raw(p)
 #define lduw_code(p) lduw_raw(p)
 #define ldsw_code(p) ldsw_raw(p)
-#define ldl_code(p) ldl_raw(p)
+#define ldul_code(p) ldul_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_code(p) ldsl_raw(p)
+#endif
 #define ldq_code(p) ldq_raw(p)
+/* reverse-endian */
+#define ldubr_code(p) ldub_raw(p)
+#define ldsbr_code(p) ldsb_raw(p)
+#define lduwr_code(p) lduwr_raw(p)
+#define ldswr_code(p) ldswr_raw(p)
+#define ldulr_code(p) ldulr_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldslr_code(p) ldslr_raw(p)
+#endif
+#define ldqr_code(p) ldqr_raw(p)
 
+/* native-endian */
 #define ldub_kernel(p) ldub_raw(p)
 #define ldsb_kernel(p) ldsb_raw(p)
 #define lduw_kernel(p) lduw_raw(p)
 #define ldsw_kernel(p) ldsw_raw(p)
-#define ldl_kernel(p) ldl_raw(p)
+#define ldul_kernel(p) ldul_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_kernel(p) ldsl_raw(p)
+#endif
 #define ldq_kernel(p) ldq_raw(p)
 #define ldfl_kernel(p) ldfl_raw(p)
 #define ldfq_kernel(p) ldfq_raw(p)
@@ -660,6 +841,24 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_kernel(p, v) stq_raw(p, v)
 #define stfl_kernel(p, v) stfl_raw(p, v)
 #define stfq_kernel(p, vt) stfq_raw(p, v)
+/* reverse-endian */
+#define ldubr_kernel(p) ldub_raw(p)
+#define ldsbr_kernel(p) ldsb_raw(p)
+#define lduwr_kernel(p) lduwr_raw(p)
+#define ldswr_kernel(p) ldswr_raw(p)
+#define ldulr_kernel(p) ldulr_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldslr_kernel(p) ldslr_raw(p)
+#endif
+#define ldqr_kernel(p) ldqr_raw(p)
+#define ldflr_kernel(p) ldflr_raw(p)
+#define ldfqr_kernel(p) ldfqr_raw(p)
+#define stbr_kernel(p, v) stbr_raw(p, v)
+#define stwr_kernel(p, v) stwr_raw(p, v)
+#define stlr_kernel(p, v) stlr_raw(p, v)
+#define stqr_kernel(p, v) stqr_raw(p, v)
+#define stflr_kernel(p, v) stflr_raw(p, v)
+#define stfqr_kernel(p, vt) stfqr_raw(p, v)
 
 #endif /* defined(CONFIG_USER_ONLY) */
 
@@ -790,6 +989,8 @@ extern uint8_t *phys_ram_dirty;
    the physical address */
 #define IO_MEM_ROMD        (1)
 #define IO_MEM_SUBPAGE     (2)
+/* On some target CPUs, endiannes is stored in page tables */
+#define IO_MEM_REVERSE     (3)
 
 typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
 typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr);
@@ -821,7 +1022,7 @@ static inline void cpu_physical_memory_w
 }
 uint32_t ldub_phys(target_phys_addr_t addr);
 uint32_t lduw_phys(target_phys_addr_t addr);
-uint32_t ldl_phys(target_phys_addr_t addr);
+uint32_t ldul_phys(target_phys_addr_t addr);
 uint64_t ldq_phys(target_phys_addr_t addr);
 void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val);
 void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val);

Index: cpu-exec.c
===================================================================
RCS file: /sources/qemu/qemu/cpu-exec.c,v
retrieving revision 1.119

cpu-exec.c +2 -2
diff -u -d -d -p -r1.119 cpu-exec.c
@@ -436,12 +436,12 @@ int cpu_exec(CPUState *env1)
                          /* FIXME: this should respect TPR */
                          env->interrupt_request &= ~CPU_INTERRUPT_VIRQ;
                          svm_check_intercept(SVM_EXIT_VINTR);
-                         intno = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_vector));
+                         intno = ldul_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_vector));
                          if (loglevel & CPU_LOG_TB_IN_ASM)
                              fprintf(logfile, "Servicing virtual hardware INT=0x%02x\n", intno);
 	                 do_interrupt(intno, 0, 0, -1, 1);
                          stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl),
-                                  ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl)) & ~V_IRQ_MASK);
+                                  ldul_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl)) & ~V_IRQ_MASK);
 #if defined(__sparc__) && !defined(HOST_SOLARIS)
                          tmp_T0 = 0;
 #else

Index: exec-all.h
===================================================================
RCS file: /sources/qemu/qemu/exec-all.h,v
retrieving revision 1.67

exec-all.h +16 -0
diff -u -d -d -p -r1.67 exec-all.h
@@ -569,6 +569,21 @@ void tlb_fill(target_ulong addr, int is_
 #define MEMSUFFIX _code
 #define env cpu_single_env
 
+/* native-endian */
+#define DATA_SIZE 1
+#include "softmmu_header.h"
+
+#define DATA_SIZE 2
+#include "softmmu_header.h"
+
+#define DATA_SIZE 4
+#include "softmmu_header.h"
+
+#define DATA_SIZE 8
+#include "softmmu_header.h"
+
+/* reverse-endian */
+#define REVERSE_ENDIAN
 #define DATA_SIZE 1
 #include "softmmu_header.h"
 
@@ -580,6 +595,7 @@ void tlb_fill(target_ulong addr, int is_
 
 #define DATA_SIZE 8
 #include "softmmu_header.h"
+#undef REVERSE_ENDIAN
 
 #undef ACCESS_TYPE
 #undef MEMSUFFIX

Index: exec.c
===================================================================
RCS file: /sources/qemu/qemu/exec.c,v
retrieving revision 1.108

exec.c +99 -38

193 lines not on this page · raw message

Index: monitor.c
===================================================================
RCS file: /sources/qemu/qemu/monitor.c,v
retrieving revision 1.83

monitor.c +1 -1
diff -u -d -d -p -r1.83 monitor.c
@@ -595,7 +595,7 @@ static void memory_dump(int count, int f
                 v = lduw_raw(buf + i);
                 break;
             case 4:
-                v = (uint32_t)ldl_raw(buf + i);
+                v = (uint32_t)ldul_raw(buf + i);
                 break;
             case 8:
                 v = ldq_raw(buf + i);

Index: softmmu_exec.h
===================================================================
RCS file: /sources/qemu/qemu/softmmu_exec.h,v
retrieving revision 1.1

softmmu_exec.h +6 -3
diff -u -d -d -p -r1.1 softmmu_exec.h
@@ -1,7 +1,7 @@
 /* Common softmmu definitions and inline routines.  */
 
-#define ldul_user ldl_user
-#define ldul_kernel ldl_kernel
+#define lduq_user ldq_user
+#define lduq_kernel ldq_kernel
 
 #define ACCESS_TYPE 0
 #define MEMSUFFIX _kernel
@@ -56,7 +56,10 @@
 #define ldsb(p) ldsb_data(p)
 #define lduw(p) lduw_data(p)
 #define ldsw(p) ldsw_data(p)
-#define ldl(p) ldl_data(p)
+#define ldul(p) ldul_data(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl(p) ldsl_data(p)
+#endif
 #define ldq(p) ldq_data(p)
 
 #define stb(p, v) stb_data(p, v)

Index: softmmu_header.h
===================================================================
RCS file: /sources/qemu/qemu/softmmu_header.h,v
retrieving revision 1.17

softmmu_header.h +86 -4

138 lines not on this page · raw message

Index: softmmu_template.h
===================================================================
RCS file: /sources/qemu/qemu/softmmu_template.h,v
retrieving revision 1.18

softmmu_template.h +249 -32

385 lines not on this page · raw message

Index: hw/eepro100.c
===================================================================
RCS file: /sources/qemu/qemu/hw/eepro100.c,v
retrieving revision 1.6

eepro100.c +3 -3
diff -u -d -d -p -r1.6 eepro100.c
@@ -723,7 +723,7 @@ static void eepro100_cu_command(EEPRO100
             uint32_t tbd_address = cb_address + 0x10;
             assert(tcb_bytes <= sizeof(buf));
             while (size < tcb_bytes) {
-                uint32_t tx_buffer_address = ldl_phys(tbd_address);
+                uint32_t tx_buffer_address = ldul_phys(tbd_address);
                 uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
                 //~ uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
                 tbd_address += 8;
@@ -743,7 +743,7 @@ static void eepro100_cu_command(EEPRO100
                     /* Extended TCB. */
                     assert(tcb_bytes == 0);
                     for (; tbd_count < 2; tbd_count++) {
-                        uint32_t tx_buffer_address = ldl_phys(tbd_address);
+                        uint32_t tx_buffer_address = ldul_phys(tbd_address);
                         uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
                         uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
                         tbd_address += 8;
@@ -760,7 +760,7 @@ static void eepro100_cu_command(EEPRO100
                 }
                 tbd_address = tbd_array;
                 for (; tbd_count < tx.tbd_count; tbd_count++) {
-                    uint32_t tx_buffer_address = ldl_phys(tbd_address);
+                    uint32_t tx_buffer_address = ldul_phys(tbd_address);
                     uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
                     uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
                     tbd_address += 8;

Index: hw/pc.c
===================================================================
RCS file: /sources/qemu/qemu/hw/pc.c,v
retrieving revision 1.87

pc.c +3 -3
diff -u -d -d -p -r1.87 pc.c
@@ -477,8 +477,8 @@ static void load_linux(const char *kerne
     }
 
     /* kernel protocol version */
-    fprintf(stderr, "header magic: %#x\n", ldl_p(header+0x202));
-    if (ldl_p(header+0x202) == 0x53726448)
+    fprintf(stderr, "header magic: %#x\n", ldul_p(header+0x202));
+    if (ldul_p(header+0x202) == 0x53726448)
 	protocol = lduw_p(header+0x206);
     else
 	protocol = 0;
@@ -510,7 +510,7 @@ static void load_linux(const char *kerne
 
     /* highest address for loading the initrd */
     if (protocol >= 0x203)
-	initrd_max = ldl_p(header+0x22c);
+	initrd_max = ldul_p(header+0x22c);
     else
 	initrd_max = 0x37ffffff;
 

Index: hw/pl080.c
===================================================================
RCS file: /sources/qemu/qemu/hw/pl080.c,v
retrieving revision 1.5

pl080.c +4 -4
diff -u -d -d -p -r1.5 pl080.c
@@ -162,10 +162,10 @@ again:
             if (size == 0) {
                 /* Transfer complete.  */
                 if (ch->lli) {
-                    ch->src = ldl_phys(ch->lli);
-                    ch->dest = ldl_phys(ch->lli + 4);
-                    ch->ctrl = ldl_phys(ch->lli + 12);
-                    ch->lli = ldl_phys(ch->lli + 8);
+                    ch->src = ldul_phys(ch->lli);
+                    ch->dest = ldul_phys(ch->lli + 4);
+                    ch->ctrl = ldul_phys(ch->lli + 12);
+                    ch->lli = ldul_phys(ch->lli + 8);
                 } else {
                     ch->conf &= ~PL080_CCONF_E;
                 }

Index: hw/sun4m.c
===================================================================
RCS file: /sources/qemu/qemu/hw/sun4m.c,v
retrieving revision 1.55

sun4m.c +1 -1
diff -u -d -d -p -r1.55 sun4m.c
@@ -465,7 +465,7 @@ static void sun4m_load_kernel(long vram_
         }
         if (initrd_size > 0) {
             for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
-                if (ldl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i)
+                if (ldul_raw(phys_ram_base + KERNEL_LOAD_ADDR + i)
                     == 0x48647253) { // HdrS
                     stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
                     stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 20, initrd_size);

Index: hw/sun4u.c
===================================================================
RCS file: /sources/qemu/qemu/hw/sun4u.c,v
retrieving revision 1.22

sun4u.c +1 -1
diff -u -d -d -p -r1.22 sun4u.c
@@ -418,7 +418,7 @@ static void sun4u_init(int ram_size, int
         }
         if (initrd_size > 0) {
             for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
-                if (ldl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i)
+                if (ldul_raw(phys_ram_base + KERNEL_LOAD_ADDR + i)
                     == 0x48647253) { // HdrS
                     stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
                     stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 20, initrd_size);

Index: linux-user/elfload.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/elfload.c,v retrieving revision 1.51

elfload.c +1 -1
diff -u -d -d -p -r1.51 elfload.c
@@ -336,7 +336,7 @@ static inline void init_thread(struct ta
     pos += sizeof(target_ulong);
     _regs->gpr[4] = pos;
     for (tmp = 1; tmp != 0; pos += sizeof(target_ulong))
-        tmp = ldl(pos);
+        tmp = ldul(pos);
     _regs->gpr[5] = pos;
 }
 

Index: linux-user/qemu.h
===================================================================
RCS file: /sources/qemu/qemu/linux-user/qemu.h,v
retrieving revision 1.40

qemu.h +2 -2
diff -u -d -d -p -r1.40 qemu.h
@@ -313,7 +313,7 @@ static inline void *lock_user_string(tar
 #define tput8(addr, val) stb(addr, val)
 #define tget16(addr) lduw(addr)
 #define tput16(addr, val) stw(addr, val)
-#define tget32(addr) ldl(addr)
+#define tget32(addr) ldul(addr)
 #define tput32(addr, val) stl(addr, val)
 #define tget64(addr) ldq(addr)
 #define tput64(addr, val) stq(addr, val)
@@ -321,7 +321,7 @@ static inline void *lock_user_string(tar
 #define tgetl(addr) ldq(addr)
 #define tputl(addr, val) stq(addr, val)
 #else
-#define tgetl(addr) ldl(addr)
+#define tgetl(addr) ldul(addr)
 #define tputl(addr, val) stl(addr, val)
 #endif
 

Index: linux-user/signal.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/signal.c,v retrieving revision 1.45

signal.c +11 -11
diff -u -d -d -p -r1.45 signal.c
@@ -878,28 +878,28 @@ restore_sigcontext(CPUX86State *env, str
         cpu_x86_load_seg(env, R_ES, lduw(&sc->es));
         cpu_x86_load_seg(env, R_DS, lduw(&sc->ds));
 
-        env->regs[R_EDI] = ldl(&sc->edi);
-        env->regs[R_ESI] = ldl(&sc->esi);
-        env->regs[R_EBP] = ldl(&sc->ebp);
-        env->regs[R_ESP] = ldl(&sc->esp);
-        env->regs[R_EBX] = ldl(&sc->ebx);
-        env->regs[R_EDX] = ldl(&sc->edx);
-        env->regs[R_ECX] = ldl(&sc->ecx);
-        env->eip = ldl(&sc->eip);
+        env->regs[R_EDI] = ldul(&sc->edi);
+        env->regs[R_ESI] = ldul(&sc->esi);
+        env->regs[R_EBP] = ldul(&sc->ebp);
+        env->regs[R_ESP] = ldul(&sc->esp);
+        env->regs[R_EBX] = ldul(&sc->ebx);
+        env->regs[R_EDX] = ldul(&sc->edx);
+        env->regs[R_ECX] = ldul(&sc->ecx);
+        env->eip = ldul(&sc->eip);
 
         cpu_x86_load_seg(env, R_CS, lduw(&sc->cs) | 3);
         cpu_x86_load_seg(env, R_SS, lduw(&sc->ss) | 3);
 
 	{
 		unsigned int tmpflags;
-                tmpflags = ldl(&sc->eflags);
+                tmpflags = ldul(&sc->eflags);
 		env->eflags = (env->eflags & ~0x40DD5) | (tmpflags & 0x40DD5);
                 //		regs->orig_eax = -1;		/* disable syscall checks */
 	}
 
 	{
 		struct _fpstate * buf;
-                buf = (void *)ldl(&sc->fpstate);
+                buf = (void *)ldul(&sc->fpstate);
 		if (buf) {
 #if 0
 			if (verify_area(VERIFY_READ, buf, sizeof(*buf)))
@@ -909,7 +909,7 @@ restore_sigcontext(CPUX86State *env, str
 		}
 	}
 
-        *peax = ldl(&sc->eax);
+        *peax = ldul(&sc->eax);
 	return err;
 #if 0
 badframe:

Index: linux-user/vm86.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/vm86.c,v
retrieving revision 1.11

vm86.c +1 -1
diff -u -d -d -p -r1.11 vm86.c
@@ -56,7 +56,7 @@ static inline unsigned int vm_getw(uint8
 
 static inline unsigned int vm_getl(uint8_t *segptr, unsigned int reg16)
 {
-    return ldl(segptr + (reg16 & 0xffff));
+    return ldul(segptr + (reg16 & 0xffff));
 }
 
 void save_v86_state(CPUX86State *env)

Index: target-alpha/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/exec.h,v retrieving revision 1.3

exec.h +3 -0
diff -u -d -d -p -r1.3 exec.h
@@ -62,6 +62,9 @@ register uint64_t T2 asm(AREG3);
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 static inline void env_to_regs(void)

Index: target-alpha/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/helper.c,v retrieving revision 1.4

helper.c +1 -1
diff -u -d -d -p -r1.4 helper.c
@@ -69,7 +69,7 @@ int cpu_alpha_handle_mmu_fault (CPUState
             env->exception_index = EXCP_DTB_MISS_PAL;
         else
             env->exception_index = EXCP_DTB_MISS_NATIVE;
-        opc = (ldl_code(env->pc) >> 21) << 4;
+        opc = (ldul_code(env->pc) >> 21) << 4;
         if (rw) {
             opc |= 0x9;
         } else {

Index: target-alpha/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/op_helper.c,v retrieving revision 1.2

op_helper.c +16 -0
diff -u -d -d -p -r1.2 op_helper.c
@@ -1207,6 +1207,21 @@ void helper_st_phys_to_virt (void)
 
 #define MMUSUFFIX _mmu
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -1218,6 +1233,7 @@ void helper_st_phys_to_virt (void)
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-alpha/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/op_mem.h,v retrieving revision 1.2

op_mem.h +2 -2
diff -u -d -d -p -r1.2 op_mem.h
@@ -30,7 +30,7 @@ static inline uint32_t glue(ldl_l, MEMSU
 {
     env->lock = EA;
 
-    return glue(ldl, MEMSUFFIX)(EA);
+    return glue(ldul, MEMSUFFIX)(EA);
 }
 
 static inline uint32_t glue(ldq_l, MEMSUFFIX) (target_ulong EA)
@@ -82,7 +82,7 @@ ALPHA_LD_OP(bu, ldub);
 ALPHA_ST_OP(b, stb);
 ALPHA_LD_OP(wu, lduw);
 ALPHA_ST_OP(w, stw);
-ALPHA_LD_OP(l, ldl);
+ALPHA_LD_OP(l, ldul);
 ALPHA_ST_OP(l, stl);
 ALPHA_LD_OP(q, ldq);
 ALPHA_ST_OP(q, stq);

Index: target-alpha/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/translate.c,v retrieving revision 1.5

translate.c +1 -1
diff -u -d -d -p -r1.5 translate.c
@@ -2010,7 +2010,7 @@ int gen_intermediate_code_internal (CPUS
                     ctx.pc, ctx.mem_idx);
         }
 #endif
-        insn = ldl_code(ctx.pc);
+        insn = ldul_code(ctx.pc);
 #if defined ALPHA_DEBUG_DISAS
         insn_count++;
         if (logfile != NULL) {

Index: target-arm/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-arm/exec.h,v
retrieving revision 1.13

exec.h +3 -0
diff -u -d -d -p -r1.13 exec.h
@@ -64,6 +64,9 @@ static inline int cpu_halted(CPUState *e
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 /* In op_helper.c */

Index: target-arm/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-arm/helper.c,v retrieving revision 1.22

helper.c +3 -3
diff -u -d -d -p -r1.22 helper.c
@@ -297,7 +297,7 @@ void do_interrupt(CPUARMState *env)
             if (env->thumb) {
                 mask = lduw_code(env->regs[15] - 2) & 0xff;
             } else {
-                mask = ldl_code(env->regs[15] - 4) & 0xffffff;
+                mask = ldul_code(env->regs[15] - 4) & 0xffffff;
             }
             /* Only intercept calls from privileged modes, to provide some
                semblance of security.  */
@@ -473,7 +473,7 @@ static int get_phys_addr(CPUState *env, 
         /* Pagetable walk.  */
         /* Lookup l1 descriptor.  */
         table = (env->cp15.c2_base & 0xffffc000) | ((address >> 18) & 0x3ffc);
-        desc = ldl_phys(table);
+        desc = ldul_phys(table);
         type = (desc & 3);
         domain = (env->cp15.c3 >> ((desc >> 4) & 0x1e)) & 3;
         if (type == 0) {
@@ -502,7 +502,7 @@ static int get_phys_addr(CPUState *env, 
                 /* Fine pagetable.  */
                 table = (desc & 0xfffff000) | ((address >> 8) & 0xffc);
             }
-            desc = ldl_phys(table);
+            desc = ldul_phys(table);
             switch (desc & 3) {
             case 0: /* Page translation fault.  */
                 code = 7;

Index: target-arm/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-arm/op_helper.c,v retrieving revision 1.6

op_helper.c +16 -0
diff -u -d -d -p -r1.6 op_helper.c
@@ -180,6 +180,21 @@ void do_vfp_get_fpscr(void)
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -191,6 +206,7 @@ void do_vfp_get_fpscr(void)
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-arm/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-arm/op_mem.h,v retrieving revision 1.2

op_mem.h +9 -10
diff -u -d -d -p -r1.2 op_mem.h
@@ -1,18 +1,17 @@
 /* ARM memory operations.  */
 
-/* Load from address T1 into T0.  */
-#define MEM_LD_OP(name) \
+#define MEM_LD_OP(name, lname) \
 void OPPROTO glue(op_ld##name,MEMSUFFIX)(void) \
 { \
-    T0 = glue(ld##name,MEMSUFFIX)(T1); \
+    T0 = glue(ld##lname,MEMSUFFIX)(T1); \
     FORCE_RET(); \
 }
 
-MEM_LD_OP(ub)
-MEM_LD_OP(sb)
-MEM_LD_OP(uw)
-MEM_LD_OP(sw)
-MEM_LD_OP(l)
+MEM_LD_OP(ub,ub)
+MEM_LD_OP(sb,sb)
+MEM_LD_OP(uw,uw)
+MEM_LD_OP(sw,sw)
+MEM_LD_OP(l,ul)
 
 #undef MEM_LD_OP
 
@@ -45,7 +44,7 @@ void OPPROTO glue(op_swp##name,MEMSUFFIX
 }
 
 MEM_SWP_OP(b, ub)
-MEM_SWP_OP(l, l)
+MEM_SWP_OP(l, ul)
 
 #undef MEM_SWP_OP
 
@@ -82,7 +81,7 @@ void OPPROTO glue(op_iwmmxt_st##name,MEM
 
 MMX_MEM_OP(b, ub)
 MMX_MEM_OP(w, uw)
-MMX_MEM_OP(l, l)
+MMX_MEM_OP(l, ul)
 MMX_MEM_OP(q, q)
 
 #undef MMX_MEM_OP

Index: target-arm/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-arm/translate.c,v retrieving revision 1.57

translate.c +1 -1
diff -u -d -d -p -r1.57 translate.c
@@ -2206,7 +2206,7 @@ static void disas_arm_insn(CPUState * en
 {
     unsigned int cond, insn, val, op1, i, shift, rm, rs, rn, rd, sh;
 
-    insn = ldl_code(s->pc);
+    insn = ldul_code(s->pc);
     s->pc += 4;
 
     cond = insn >> 28;

Index: target-cris/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-cris/exec.h,v
retrieving revision 1.1

exec.h +3 -0
diff -u -d -d -p -r1.1 exec.h
@@ -50,6 +50,9 @@ void tlb_fill (target_ulong addr, int is
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 void cpu_cris_flush_flags(CPUCRISState *env, int cc_op);

Index: target-cris/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-cris/helper.c,v retrieving revision 1.1

helper.c +3 -3
diff -u -d -d -p -r1.1 helper.c
@@ -106,7 +106,7 @@ void do_interrupt(CPUState *env)
 //			printf ("BREAK! %d\n", env->trapnr);
 			irqnum = env->trapnr;
 			ebp = env->pregs[SR_EBP];
-			isr = ldl_code(ebp + irqnum * 4);
+			isr = ldul_code(ebp + irqnum * 4);
 			env->pregs[SR_ERP] = env->pc + 2;
 			env->pc = isr;
 
@@ -117,7 +117,7 @@ void do_interrupt(CPUState *env)
 //			printf ("MMU miss\n");
 			irqnum = 4;
 			ebp = env->pregs[SR_EBP];
-			isr = ldl_code(ebp + irqnum * 4);
+			isr = ldul_code(ebp + irqnum * 4);
 			env->pregs[SR_ERP] = env->pc;
 			env->pc = isr;
 			cris_shift_ccs(env);
@@ -138,7 +138,7 @@ void do_interrupt(CPUState *env)
 					__builtin_clz(env->pending_interrupts);
 				irqnum += 0x30;
 				ebp = env->pregs[SR_EBP];
-				isr = ldl_code(ebp + irqnum * 4);
+				isr = ldul_code(ebp + irqnum * 4);
 				env->pregs[SR_ERP] = env->pc;
 				env->pc = isr;
 

Index: target-cris/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-cris/op_helper.c,v retrieving revision 1.1

op_helper.c +16 -0
diff -u -d -d -p -r1.1 op_helper.c
@@ -25,6 +25,21 @@
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -36,6 +51,7 @@
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* Try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-cris/op_mem.c
===================================================================
RCS file: /sources/qemu/qemu/target-cris/op_mem.c,v retrieving revision 1.1

op_mem.c +1 -1
diff -u -d -d -p -r1.1 op_mem.c
@@ -49,7 +49,7 @@ void glue(op_stw_T0_T1, MEMSUFFIX) (void
 }
 
 void glue(op_ldl_T0_T0, MEMSUFFIX) (void) {
-    T0 = glue(ldl, MEMSUFFIX) (T0);
+    T0 = glue(ldul, MEMSUFFIX) (T0);
     RETURN();
 }
 

Index: target-cris/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-cris/translate.c,v retrieving revision 1.1

translate.c +8 -8
diff -u -d -d -p -r1.1 translate.c
@@ -828,7 +828,7 @@ static int dec_prep_alu_m(DisasContext *
 		if (memsize == 1)
 			insn_len++;
 
-		imm = ldl_code(dc->pc + 2);
+		imm = ldul_code(dc->pc + 2);
 		if (memsize != 4) {
 			if (s_ext) {
 				imm = sign_extend(imm, (memsize * 8) - 1);
@@ -1962,7 +1962,7 @@ static unsigned int dec_lapc_im(DisasCon
 	rd = dc->op2;
 
 	cris_cc_mask(dc, 0);
-	imm = ldl_code(dc->pc + 2);
+	imm = ldul_code(dc->pc + 2);
 	DIS(fprintf (logfile, "lapc 0x%x, $r%u\n", imm + dc->pc, dc->op2));
 	gen_op_movl_T0_im (dc->pc + imm);
 	gen_movl_reg_T0[rd] ();
@@ -1999,7 +1999,7 @@ static unsigned int dec_jas_im(DisasCont
 {
 	uint32_t imm;
 
-	imm = ldl_code(dc->pc + 2);
+	imm = ldul_code(dc->pc + 2);
 
 	DIS(fprintf (logfile, "jas 0x%x\n", imm));
 	cris_cc_mask(dc, 0);
@@ -2016,7 +2016,7 @@ static unsigned int dec_jasc_im(DisasCon
 {
 	uint32_t imm;
 
-	imm = ldl_code(dc->pc + 2);
+	imm = ldul_code(dc->pc + 2);
 
 	DIS(fprintf (logfile, "jasc 0x%x\n", imm));
 	cris_cc_mask(dc, 0);
@@ -2047,7 +2047,7 @@ static unsigned int dec_bcc_im(DisasCont
 	int32_t offset;
 	uint32_t cond = dc->op2;
 
-	offset = ldl_code(dc->pc + 2);
+	offset = ldul_code(dc->pc + 2);
 	offset = sign_extend(offset, 15);
 
 	DIS(fprintf (logfile, "b%s %d pc=%x dst=%x\n",
@@ -2065,7 +2065,7 @@ static unsigned int dec_bas_im(DisasCont
 	int32_t simm;
 
 
-	simm = ldl_code(dc->pc + 2);
+	simm = ldul_code(dc->pc + 2);
 
 	DIS(fprintf (logfile, "bas 0x%x, $p%u\n", dc->pc + simm, dc->op2));
 	cris_cc_mask(dc, 0);
@@ -2081,7 +2081,7 @@ static unsigned int dec_bas_im(DisasCont
 static unsigned int dec_basc_im(DisasContext *dc)
 {
 	int32_t simm;
-	simm = ldl_code(dc->pc + 2);
+	simm = ldul_code(dc->pc + 2);
 
 	DIS(fprintf (logfile, "basc 0x%x, $p%u\n", dc->pc + simm, dc->op2));
 	cris_cc_mask(dc, 0);
@@ -2259,7 +2259,7 @@ cris_decoder(DisasContext *dc)
 	int i;
 
 	/* Load a halfword onto the instruction register.  */
-	tmp = ldl_code(dc->pc);
+	tmp = ldul_code(dc->pc);
 	dc->ir = tmp & 0xffff;
 
 	/* Now decode it.  */

Index: target-i386/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-i386/exec.h,v
retrieving revision 1.37

exec.h +6 -3
diff -u -d -d -p -r1.37 exec.h
@@ -217,6 +217,9 @@ void check_iol_DX(void);
 #if !defined(CONFIG_USER_ONLY)
 
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 
 static inline double ldfq(target_ulong ptr)
 {
@@ -244,7 +247,7 @@ static inline float ldfl(target_ulong pt
         float f;
         uint32_t i;
     } u;
-    u.i = ldl(ptr);
+    u.i = ldul(ptr);
     return u.f;
 }
 
@@ -419,12 +422,12 @@ static inline void helper_fstt(CPU86_LDo
 
 static inline CPU86_LDouble helper_fldt(target_ulong ptr)
 {
-    return *(CPU86_LDouble *)ptr;
+    return *(CPU86_LDouble *)(unsigned long)ptr;
 }
 
 static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr)
 {
-    *(CPU86_LDouble *)ptr = f;
+    *(CPU86_LDouble *)(unsigned long)ptr = f;
 }
 
 #else

Index: target-i386/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/helper.c,v retrieving revision 1.89

helper.c +103 -87

398 lines not on this page · raw message

Index: target-i386/helper2.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/helper2.c,v retrieving revision 1.52

helper2.c +9 -9
diff -u -d -d -p -r1.52 helper2.c
@@ -771,7 +771,7 @@ int cpu_x86_handle_mmu_fault(CPUX86State
         /* page directory entry */
         pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) &
             env->a20_mask;
-        pde = ldl_phys(pde_addr);
+        pde = ldul_phys(pde_addr);
         if (!(pde & PG_PRESENT_MASK)) {
             error_code = 0;
             goto do_fault;
@@ -809,7 +809,7 @@ int cpu_x86_handle_mmu_fault(CPUX86State
             /* page directory entry */
             pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) &
                 env->a20_mask;
-            pte = ldl_phys(pte_addr);
+            pte = ldul_phys(pte_addr);
             if (!(pte & PG_PRESENT_MASK)) {
                 error_code = 0;
                 goto do_fault;
@@ -909,13 +909,13 @@ target_phys_addr_t cpu_get_phys_page_deb
 
             pml4e_addr = ((env->cr[3] & ~0xfff) + (((addr >> 39) & 0x1ff) << 3)) &
                 env->a20_mask;
-            pml4e = ldl_phys(pml4e_addr);
+            pml4e = ldul_phys(pml4e_addr);
             if (!(pml4e & PG_PRESENT_MASK))
                 return -1;
 
             pdpe_addr = ((pml4e & ~0xfff) + (((addr >> 30) & 0x1ff) << 3)) &
                 env->a20_mask;
-            pdpe = ldl_phys(pdpe_addr);
+            pdpe = ldul_phys(pdpe_addr);
             if (!(pdpe & PG_PRESENT_MASK))
                 return -1;
         } else
@@ -923,14 +923,14 @@ target_phys_addr_t cpu_get_phys_page_deb
         {
             pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) &
                 env->a20_mask;
-            pdpe = ldl_phys(pdpe_addr);
+            pdpe = ldul_phys(pdpe_addr);
             if (!(pdpe & PG_PRESENT_MASK))
                 return -1;
         }
 
         pde_addr = ((pdpe & ~0xfff) + (((addr >> 21) & 0x1ff) << 3)) &
             env->a20_mask;
-        pde = ldl_phys(pde_addr);
+        pde = ldul_phys(pde_addr);
         if (!(pde & PG_PRESENT_MASK)) {
             return -1;
         }
@@ -943,7 +943,7 @@ target_phys_addr_t cpu_get_phys_page_deb
             pte_addr = ((pde & ~0xfff) + (((addr >> 12) & 0x1ff) << 3)) &
                 env->a20_mask;
             page_size = 4096;
-            pte = ldl_phys(pte_addr);
+            pte = ldul_phys(pte_addr);
         }
     } else {
         if (!(env->cr[0] & CR0_PG_MASK)) {
@@ -952,7 +952,7 @@ target_phys_addr_t cpu_get_phys_page_deb
         } else {
             /* page directory entry */
             pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & env->a20_mask;
-            pde = ldl_phys(pde_addr);
+            pde = ldul_phys(pde_addr);
             if (!(pde & PG_PRESENT_MASK))
                 return -1;
             if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
@@ -961,7 +961,7 @@ target_phys_addr_t cpu_get_phys_page_deb
             } else {
                 /* page directory entry */
                 pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & env->a20_mask;
-                pte = ldl_phys(pte_addr);
+                pte = ldul_phys(pte_addr);
                 if (!(pte & PG_PRESENT_MASK))
                     return -1;
                 page_size = 4096;

Index: target-i386/op.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/op.c,v
retrieving revision 1.51

op.c +10 -12
diff -u -d -d -p -r1.51 op.c
@@ -716,8 +716,8 @@ void OPPROTO op_boundw(void)
 void OPPROTO op_boundl(void)
 {
     int low, high, v;
-    low = ldl(A0);
-    high = ldl(A0 + 4);
+    low = ldul(A0);
+    high = ldul(A0 + 4);
     v = T0;
     if (v < low || v > high) {
         raise_exception(EXCP05_BOUND);
@@ -747,8 +747,6 @@ void OPPROTO op_exit_tb(void)
 
 /* multiple size ops */
 
-#define ldul ldl
-
 #define SHIFT 0
 #include "ops_template.h"
 #undef SHIFT
@@ -1688,7 +1686,7 @@ CCTable cc_table[CC_OP_NB] = {
 void OPPROTO op_flds_FT0_A0(void)
 {
 #ifdef USE_FP_CONVERT
-    FP_CONVERT.i32 = ldl(A0);
+    FP_CONVERT.i32 = ldul(A0);
     FT0 = FP_CONVERT.f;
 #else
     FT0 = ldfl(A0);
@@ -1715,7 +1713,7 @@ void helper_fild_FT0_A0(void)
 
 void helper_fildl_FT0_A0(void)
 {
-    FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
+    FT0 = (CPU86_LDouble)((int32_t)ldul(A0));
 }
 
 void helper_fildll_FT0_A0(void)
@@ -1753,10 +1751,10 @@ void OPPROTO op_fild_FT0_A0(void)
 void OPPROTO op_fildl_FT0_A0(void)
 {
 #ifdef USE_FP_CONVERT
-    FP_CONVERT.i32 = (int32_t) ldl(A0);
+    FP_CONVERT.i32 = (int32_t) ldul(A0);
     FT0 = (CPU86_LDouble)FP_CONVERT.i32;
 #else
-    FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
+    FT0 = (CPU86_LDouble)((int32_t)ldul(A0));
 #endif
 }
 
@@ -1778,7 +1776,7 @@ void OPPROTO op_flds_ST0_A0(void)
     int new_fpstt;
     new_fpstt = (env->fpstt - 1) & 7;
 #ifdef USE_FP_CONVERT
-    FP_CONVERT.i32 = ldl(A0);
+    FP_CONVERT.i32 = ldul(A0);
     env->fpregs[new_fpstt].d = FP_CONVERT.f;
 #else
     env->fpregs[new_fpstt].d = ldfl(A0);
@@ -1822,7 +1820,7 @@ void helper_fildl_ST0_A0(void)
 {
     int new_fpstt;
     new_fpstt = (env->fpstt - 1) & 7;
-    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
+    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldul(A0));
     env->fpstt = new_fpstt;
     env->fptags[new_fpstt] = 0; /* validate stack entry */
 }
@@ -1872,10 +1870,10 @@ void OPPROTO op_fildl_ST0_A0(void)
     int new_fpstt;
     new_fpstt = (env->fpstt - 1) & 7;
 #ifdef USE_FP_CONVERT
-    FP_CONVERT.i32 = (int32_t) ldl(A0);
+    FP_CONVERT.i32 = (int32_t) ldul(A0);
     env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32;
 #else
-    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
+    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldul(A0));
 #endif
     env->fpstt = new_fpstt;
     env->fptags[new_fpstt] = 0; /* validate stack entry */

Index: target-i386/ops_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-i386/ops_mem.h,v retrieving revision 1.7

ops_mem.h +4 -4
diff -u -d -d -p -r1.7 ops_mem.h
@@ -20,7 +20,7 @@ void OPPROTO glue(glue(op_ldsw, MEMSUFFI
 
 void OPPROTO glue(glue(op_ldl, MEMSUFFIX), _T0_A0)(void)
 {
-    T0 = (uint32_t)glue(ldl, MEMSUFFIX)(A0);
+    T0 = (uint32_t)glue(ldul, MEMSUFFIX)(A0);
 }
 
 void OPPROTO glue(glue(op_ldub, MEMSUFFIX), _T1_A0)(void)
@@ -45,7 +45,7 @@ void OPPROTO glue(glue(op_ldsw, MEMSUFFI
 
 void OPPROTO glue(glue(op_ldl, MEMSUFFIX), _T1_A0)(void)
 {
-    T1 = (uint32_t)glue(ldl, MEMSUFFIX)(A0);
+    T1 = (uint32_t)glue(ldul, MEMSUFFIX)(A0);
 }
 
 void OPPROTO glue(glue(op_stb, MEMSUFFIX), _T0_A0)(void)
@@ -122,12 +122,12 @@ void OPPROTO glue(glue(op_sto, MEMSUFFIX
 #ifdef TARGET_X86_64
 void OPPROTO glue(glue(op_ldsl, MEMSUFFIX), _T0_A0)(void)
 {
-    T0 = (int32_t)glue(ldl, MEMSUFFIX)(A0);
+    T0 = glue(ldsl, MEMSUFFIX)(A0);
 }
 
 void OPPROTO glue(glue(op_ldsl, MEMSUFFIX), _T1_A0)(void)
 {
-    T1 = (int32_t)glue(ldl, MEMSUFFIX)(A0);
+    T1 = glue(ldsl, MEMSUFFIX)(A0);
 }
 
 void OPPROTO glue(glue(op_ldq, MEMSUFFIX), _T0_A0)(void)

Index: target-i386/svm.h
===================================================================
RCS file: /sources/qemu/qemu/target-i386/svm.h,v
retrieving revision 1.1

svm.h +3 -3
diff -u -d -d -p -r1.1 svm.h
@@ -340,13 +340,13 @@ static inline int svm_check_intercept(un
                     R_##seg_index, \
                     lduw_phys(addr + offsetof(struct vmcb, save.seg.selector)),\
                     ldq_phys(addr + offsetof(struct vmcb, save.seg.base)),\
-                    ldl_phys(addr + offsetof(struct vmcb, save.seg.limit)),\
-                    vmcb2cpu_attrib(lduw_phys(addr + offsetof(struct vmcb, save.seg.attrib)), ldq_phys(addr + offsetof(struct vmcb, save.seg.base)), ldl_phys(addr + offsetof(struct vmcb, save.seg.limit))))
+                    ldul_phys(addr + offsetof(struct vmcb, save.seg.limit)),\
+                    vmcb2cpu_attrib(lduw_phys(addr + offsetof(struct vmcb, save.seg.attrib)), ldq_phys(addr + offsetof(struct vmcb, save.seg.base)), ldul_phys(addr + offsetof(struct vmcb, save.seg.limit))))
 
 #define SVM_LOAD_SEG2(addr, seg_qemu, seg_vmcb) \
     env->seg_qemu.selector  = lduw_phys(addr + offsetof(struct vmcb, save.seg_vmcb.selector)); \
     env->seg_qemu.base      = ldq_phys(addr + offsetof(struct vmcb, save.seg_vmcb.base)); \
-    env->seg_qemu.limit     = ldl_phys(addr + offsetof(struct vmcb, save.seg_vmcb.limit)); \
+    env->seg_qemu.limit     = ldul_phys(addr + offsetof(struct vmcb, save.seg_vmcb.limit)); \
     env->seg_qemu.flags     = vmcb2cpu_attrib(lduw_phys(addr + offsetof(struct vmcb, save.seg_vmcb.attrib)), env->seg_qemu.base, env->seg_qemu.limit)
 
 #define SVM_SAVE_SEG(addr, seg_qemu, seg_vmcb) \

Index: target-i386/translate-copy.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/translate-copy.c,v retrieving revision 1.9

translate-copy.c +3 -3
diff -u -d -d -p -r1.9 translate-copy.c
@@ -207,7 +207,7 @@ static inline void gen_lea_modrm(DisasCo
         case 0:
             if (base == 5) {
                 base = -1;
-                disp = ldl_code(s->pc);
+                disp = ldul_code(s->pc);
                 s->pc += 4;
             } else {
                 disp = 0;
@@ -218,7 +218,7 @@ static inline void gen_lea_modrm(DisasCo
             break;
         default:
         case 2:
-            disp = ldl_code(s->pc);
+            disp = ldul_code(s->pc);
             s->pc += 4;
             break;
         }
@@ -266,7 +266,7 @@ static inline uint32_t insn_get(DisasCon
         break;
     default:
     case OT_LONG:
-        ret = ldl_code(s->pc);
+        ret = ldul_code(s->pc);
         s->pc += 4;
         break;
     }

Index: target-i386/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/translate.c,v retrieving revision 1.72

translate.c +3 -3
diff -u -d -d -p -r1.72 translate.c
@@ -1462,7 +1462,7 @@ static void gen_lea_modrm(DisasContext *
         case 0:
             if ((base & 7) == 5) {
                 base = -1;
-                disp = (int32_t)ldl_code(s->pc);
+                disp = (int32_t)ldul_code(s->pc);
                 s->pc += 4;
                 if (CODE64(s) && !havesib) {
                     disp += s->pc + s->rip_offset;
@@ -1476,7 +1476,7 @@ static void gen_lea_modrm(DisasContext *
             break;
         default:
         case 2:
-            disp = ldl_code(s->pc);
+            disp = ldul_code(s->pc);
             s->pc += 4;
             break;
         }
@@ -1736,7 +1736,7 @@ static inline uint32_t insn_get(DisasCon
         break;
     default:
     case OT_LONG:
-        ret = ldl_code(s->pc);
+        ret = ldul_code(s->pc);
         s->pc += 4;
         break;
     }

Index: target-m68k/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-m68k/exec.h,v
retrieving revision 1.4

exec.h +3 -0
diff -u -d -d -p -r1.4 exec.h
@@ -42,6 +42,9 @@ int cpu_m68k_handle_mmu_fault (CPUState 
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 void cpu_m68k_flush_flags(CPUM68KState *env, int cc_op);

Index: target-m68k/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-m68k/op_helper.c,v retrieving revision 1.6

op_helper.c +20 -4
diff -u -d -d -p -r1.6 op_helper.c
@@ -33,6 +33,21 @@ extern int semihosting_enabled;
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -44,6 +59,7 @@ extern int semihosting_enabled;
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* Try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not
@@ -83,8 +99,8 @@ static void do_rte(void)
     uint32_t fmt;
 
     sp = env->aregs[7];
-    fmt = ldl_kernel(sp);
-    env->pc = ldl_kernel(sp + 4);
+    fmt = ldul_kernel(sp);
+    env->pc = ldul_kernel(sp + 4);
     sp |= (fmt >> 28) & 3;
     env->sr = fmt & 0xffff;
     m68k_switch_sp(env);
@@ -112,7 +128,7 @@ void do_interrupt(int is_hw)
                     && (env->sr & SR_S) != 0
                     && (env->pc & 3) == 0
                     && lduw_code(env->pc - 4) == 0x4e71
-                    && ldl_code(env->pc) == 0x4e7bf000) {
+                    && ldul_code(env->pc) == 0x4e7bf000) {
                 env->pc += 4;
                 do_m68k_semihosting(env, env->dregs[0]);
                 return;
@@ -153,7 +169,7 @@ void do_interrupt(int is_hw)
     stl_kernel(sp, fmt);
     env->aregs[7] = sp;
     /* Jump to vector.  */
-    env->pc = ldl_kernel(env->vbr + vector);
+    env->pc = ldul_kernel(env->vbr + vector);
 }
 
 #endif

Index: target-m68k/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-m68k/op_mem.h,v retrieving revision 1.1

op_mem.h +1 -1
diff -u -d -d -p -r1.1 op_mem.h
@@ -11,7 +11,7 @@ MEM_LD_OP(8u32,ub)
 MEM_LD_OP(8s32,sb)
 MEM_LD_OP(16u32,uw)
 MEM_LD_OP(16s32,sw)
-MEM_LD_OP(32,l)
+MEM_LD_OP(32,ul)
 
 #undef MEM_LD_OP
 

Index: target-mips/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-mips/exec.h,v
retrieving revision 1.38

exec.h +3 -0
diff -u -d -d -p -r1.38 exec.h
@@ -54,6 +54,9 @@ register target_ulong T2 asm(AREG3);
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)

Index: target-mips/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_helper.c,v retrieving revision 1.65

op_helper.c +16 -0
diff -u -d -d -p -r1.65 op_helper.c
@@ -544,6 +544,21 @@ static void do_unaligned_access (target_
 #define MMUSUFFIX _mmu
 #define ALIGNED_ONLY
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -555,6 +570,7 @@ static void do_unaligned_access (target_
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr)
 {

Index: target-mips/op_mem.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_mem.c,v retrieving revision 1.14

op_mem.c +4 -4
diff -u -d -d -p -r1.14 op_mem.c
@@ -57,13 +57,13 @@ void glue(op_sh, MEMSUFFIX) (void)
 
 void glue(op_lw, MEMSUFFIX) (void)
 {
-    T0 = glue(ldl, MEMSUFFIX)(T0);
+    T0 = glue(ldul, MEMSUFFIX)(T0);
     RETURN();
 }
 
 void glue(op_lwu, MEMSUFFIX) (void)
 {
-    T0 = (uint32_t)glue(ldl, MEMSUFFIX)(T0);
+    T0 = (uint32_t)glue(ldul, MEMSUFFIX)(T0);
     RETURN();
 }
 
@@ -167,7 +167,7 @@ void glue(op_swr, MEMSUFFIX) (void)
 void glue(op_ll, MEMSUFFIX) (void)
 {
     T1 = T0;
-    T0 = glue(ldl, MEMSUFFIX)(T0);
+    T0 = glue(ldul, MEMSUFFIX)(T0);
     env->CP0_LLAddr = T1;
     RETURN();
 }
@@ -383,7 +383,7 @@ void glue(op_scd, MEMSUFFIX) (void)
 
 void glue(op_lwc1, MEMSUFFIX) (void)
 {
-    WT0 = glue(ldl, MEMSUFFIX)(T0);
+    WT0 = glue(ldul, MEMSUFFIX)(T0);
     RETURN();
 }
 void glue(op_swc1, MEMSUFFIX) (void)

Index: target-mips/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/translate.c,v retrieving revision 1.106

translate.c +1 -1
diff -u -d -d -p -r1.106 translate.c
@@ -6544,7 +6544,7 @@ gen_intermediate_code_internal (CPUState
             gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
             gen_opc_instr_start[lj] = 1;
         }
-        ctx.opcode = ldl_code(ctx.pc);
+        ctx.opcode = ldul_code(ctx.pc);
         decode_opc(env, &ctx);
         ctx.pc += 4;
 

Index: target-ppc/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/exec.h,v
retrieving revision 1.28

exec.h +5 -0
diff -u -d -d -p -r1.28 exec.h
@@ -91,7 +91,12 @@ static always_inline target_ulong rotl64
 #endif
 
 #if !defined(CONFIG_USER_ONLY)
+
+#include "softmmu_exec.h"
+#define REVERSE_ENDIAN
 #include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
+
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 void do_raise_exception_err (uint32_t exception, int error_code);

Index: target-ppc/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/helper.c,v retrieving revision 1.75

helper.c +9 -9
diff -u -d -d -p -r1.75 helper.c
@@ -514,8 +514,8 @@ static always_inline int _find_pte (mmu_
         } else
 #endif
         {
-            pte0 = ldl_phys(base + (i * 8));
-            pte1 =  ldl_phys(base + (i * 8) + 4);
+            pte0 = ldul_phys(base + (i * 8));
+            pte1 =  ldul_phys(base + (i * 8) + 4);
             r = pte32_check(ctx, pte0, pte1, h, rw);
 #if defined (DEBUG_MMU)
             if (loglevel != 0) {
@@ -623,7 +623,7 @@ static int slb_lookup (CPUPPCState *env,
     slb_nr = env->slb_nr;
     for (n = 0; n < slb_nr; n++) {
         tmp64 = ldq_phys(sr_base);
-        tmp = ldl_phys(sr_base + 8);
+        tmp = ldul_phys(sr_base + 8);
 #if defined(DEBUG_SLB)
         if (loglevel != 0) {
             fprintf(logfile, "%s: seg %d " PADDRX " %016" PRIx64 " %08"
@@ -671,7 +671,7 @@ target_ulong ppc_load_slb (CPUPPCState *
     sr_base = env->spr[SPR_ASR];
     sr_base += 12 * slb_nr;
     tmp64 = ldq_phys(sr_base);
-    tmp = ldl_phys(sr_base + 8);
+    tmp = ldul_phys(sr_base + 8);
     if (tmp64 & 0x0000000008000000ULL) {
         /* SLB entry is valid */
         /* Copy SLB bits 62:88 to Rt 37:63 (VSID 23:49) */
@@ -877,10 +877,10 @@ static int get_segment (CPUState *env, m
                         sdr, mask + 0x80);
                 for (curaddr = sdr; curaddr < (sdr + mask + 0x80);
                      curaddr += 16) {
-                    a0 = ldl_phys(curaddr);
-                    a1 = ldl_phys(curaddr + 4);
-                    a2 = ldl_phys(curaddr + 8);
-                    a3 = ldl_phys(curaddr + 12);
+                    a0 = ldul_phys(curaddr);
+                    a1 = ldul_phys(curaddr + 4);
+                    a2 = ldul_phys(curaddr + 8);
+                    a3 = ldul_phys(curaddr + 12);
                     if (a0 != 0 || a1 != 0 || a2 != 0 || a3 != 0) {
                         fprintf(logfile,
                                 PADDRX ": %08x %08x %08x %08x\n",
@@ -2219,7 +2219,7 @@ static always_inline void powerpc_excp (
 #endif
         /* XXX: this is false */
         /* Get rS/rD and rA from faulting opcode */
-        env->spr[SPR_DSISR] |= (ldl_code((env->nip - 4)) & 0x03FF0000) >> 16;
+        env->spr[SPR_DSISR] |= (ldul_code((env->nip - 4)) & 0x03FF0000) >> 16;
         goto store_current;
     case POWERPC_EXCP_PROGRAM:   /* Program exception                        */
         switch (env->error_code & ~0xF) {

Index: target-ppc/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper.c,v retrieving revision 1.49

op_helper.c +16 -0
diff -u -d -d -p -r1.49 op_helper.c
@@ -2291,6 +2291,21 @@ DO_SPE_OP1(fsctuf);
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -2302,6 +2317,7 @@ DO_SPE_OP1(fsctuf);
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-ppc/op_helper.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper.h,v retrieving revision 1.21

op_helper.h +0 -13
diff -u -d -d -p -r1.21 op_helper.h
@@ -37,19 +37,6 @@ void glue(do_POWER2_lfq_le, MEMSUFFIX) (
 void glue(do_POWER2_stfq, MEMSUFFIX) (void);
 void glue(do_POWER2_stfq_le, MEMSUFFIX) (void);
 
-#if defined(TARGET_PPC64)
-void glue(do_lsw_64, MEMSUFFIX) (int dst);
-void glue(do_lsw_le_64, MEMSUFFIX) (int dst);
-void glue(do_stsw_64, MEMSUFFIX) (int src);
-void glue(do_stsw_le_64, MEMSUFFIX) (int src);
-void glue(do_lmw_64, MEMSUFFIX) (int dst);
-void glue(do_lmw_le_64, MEMSUFFIX) (int dst);
-void glue(do_stmw_64, MEMSUFFIX) (int src);
-void glue(do_stmw_le_64, MEMSUFFIX) (int src);
-void glue(do_icbi_64, MEMSUFFIX) (void);
-void glue(do_dcbz_64, MEMSUFFIX) (void);
-#endif
-
 #else
 
 void do_print_mem_EA (target_ulong EA);

Index: target-ppc/op_helper_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper_mem.h,v retrieving revision 1.14

op_helper_mem.h +47 -277

418 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Index: target-ppc/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_mem.h,v retrieving revision 1.22

op_mem.h +158 -287

445 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Index: target-ppc/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/translate.c,v retrieving revision 1.92

translate.c +1 -1
diff -u -d -d -p -r1.92 translate.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sh4/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-sh4/exec.h,v
retrieving revision 1.5

exec.h +3 -0
diff -u -d -d -p -r1.5 exec.h

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sh4/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-sh4/op_helper.c,v retrieving revision 1.4

op_helper.c +16 -0
diff -u -d -d -p -r1.4 op_helper.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sh4/op_mem.c
===================================================================
RCS file: /sources/qemu/qemu/target-sh4/op_mem.c,v retrieving revision 1.3

op_mem.c +1 -1
diff -u -d -d -p -r1.3 op_mem.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sparc/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/exec.h,v retrieving revision 1.21

exec.h +3 -0
diff -u -d -d -p -r1.21 exec.h

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sparc/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/helper.c,v retrieving revision 1.27

helper.c +9 -9
diff -u -d -d -p -r1.27 helper.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sparc/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/op_helper.c,v retrieving revision 1.41

op_helper.c +38 -22

60 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Index: target-sparc/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/op_mem.h,v retrieving revision 1.10

op_mem.h +6 -6
diff -u -d -d -p -r1.10 op_mem.h

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sparc/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/translate.c,v retrieving revision 1.74

translate.c +1 -1
diff -u -d -d -p -r1.74 translate.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

author
#5 lore raw
Quoted 35 lines · J. Mayer
Quoted 22 lines · Blue Swirl
Quoted 21 lines · J. Mayer
Quoted 19 lines · Blue Swirl
Quoted 4 lines · J. Mayer

The problem:
some CPU architectures, namely PowerPC and maybe others, offers facilities to access the memory or I/O in the reverse endianness, ie little-endian instead of big-endian for PowerPC, or provide instruction

Quoted 8 lines

to make memory accesses in the "reverse-endian". This is implemented as a global flag on some CPU. This case is already handled by the PowerPC emulation but is is far from being optimal. Some other implementations allow the OS to store an "reverse-endian" flag in the TLB or the segment descriptors, thus providing per-page or per-segment endianness control. This is mostly used to ease driver migration from a PC platform to PowerPC without taking any care of the device endianness in the driver code (yes, this is bad...).

Nice, this may be useful for Sparc64. It has a global CPU flag for endianness, individual pages can be marked as reverse endian, and finally there are instructions that access memory in reverse endian. The end result is a XOR of all these reverses. Though I don't know if any of these features are used at all.

Quoted 7 lines
Quoted 4 lines

I realized that I/O accesses for reverse-endian pages were not correct in the softmmu_template.h header. This new version fixes this. It also remove duplicated code in the case of unaligned accesses in a reverse-endian page.

I think 64 bit access case is not handled correctly, but to solve that it would be nice to extend the current IO access system to 64 bits.

I think that if it was previously correct, it should still be, but... I don't know how much having 64 bits I/O accesses is interresting, as I don't know if there are real hw buses that have 64 bits data path...

Quoted 7 lines

Here's another version taking care of your remark about ldl memory accessors.
* I replaced all ldl occurences with ldul
* when TARGET_LONG_BITS == 64, I also added ldsl accessors. And I started using it in the PowerPC memory access micro-ops. Then the patch is really more invasive than the previous ones. This still does not break PowerPC or i386 target, as it seems.

Here's a new version. The only change is that, for consistency, I did add the big-endian and little-endian accessors that were documented in cpu-all.h as unimplemented. The implementation is quite trivial, having native and reverse-endian accessors available, and changes functionnally nothing to the previous version.

Signature · 2 lines
J. Mayer <[email protected]>
Never organized

Index: cpu-all.h
===================================================================
RCS file: /sources/qemu/qemu/cpu-all.h,v
retrieving revision 1.76

cpu-all.h +494 -25
diff -u -d -d -p -r1.76 cpu-all.h
@@ -161,9 +161,9 @@ typedef union {
  *
  * endian is:
  * (empty): target cpu endianness or 8 bit access
- *   r    : reversed target cpu endianness (not implemented yet)
- *   be   : big endian (not implemented yet)
- *   le   : little endian (not implemented yet)
+ *   r    : reversed target cpu endianness
+ *   be   : big endian
+ *   le   : little endian
  *
  * access_type is:
  *   raw    : host memory access
@@ -215,7 +215,32 @@ static inline int ldsw_le_p(void *ptr)
 #endif
 }
 
-static inline int ldl_le_p(void *ptr)
+#if (TARGET_LONG_BITS == 64)
+static inline int64_t ldul_le_p(void *ptr)
+{
+#ifdef __powerpc__
+    int val;
+    __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (ptr));
+    return (uint32_t)val;
+#else
+    uint8_t *p = ptr;
+    return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
+#endif
+}
+
+static inline int64_t ldsl_le_p(void *ptr)
+{
+#ifdef __powerpc__
+    int val;
+    __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (ptr));
+    return (int32_t)val;
+#else
+    uint8_t *p = ptr;
+    return (int32_t)(p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24));
+#endif
+}
+#else
+static inline int ldul_le_p(void *ptr)
 {
 #ifdef __powerpc__
     int val;
@@ -226,13 +251,14 @@ static inline int ldl_le_p(void *ptr)
     return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
 #endif
 }
+#endif
 
 static inline uint64_t ldq_le_p(void *ptr)
 {
     uint8_t *p = ptr;
     uint32_t v1, v2;
-    v1 = ldl_le_p(p);
-    v2 = ldl_le_p(p + 4);
+    v1 = ldul_le_p(p);
+    v2 = ldul_le_p(p + 4);
     return v1 | ((uint64_t)v2 << 32);
 }
 
@@ -275,7 +301,7 @@ static inline float32 ldfl_le_p(void *pt
         float32 f;
         uint32_t i;
     } u;
-    u.i = ldl_le_p(ptr);
+    u.i = ldul_le_p(ptr);
     return u.f;
 }
 
@@ -292,8 +318,8 @@ static inline void stfl_le_p(void *ptr, 
 static inline float64 ldfq_le_p(void *ptr)
 {
     CPU_DoubleU u;
-    u.l.lower = ldl_le_p(ptr);
-    u.l.upper = ldl_le_p(ptr + 4);
+    u.l.lower = ldul_le_p(ptr);
+    u.l.upper = ldul_le_p(ptr + 4);
     return u.d;
 }
 
@@ -317,10 +343,22 @@ static inline int ldsw_le_p(void *ptr)
     return *(int16_t *)ptr;
 }
 
-static inline int ldl_le_p(void *ptr)
+#if (TARGET_LONG_BITS == 64)
+static inline int64_t ldul_le_p(void *ptr)
+{
+    return *(uint32_t *)ptr;
+}
+
+static inline int64_t ldsl_le_p(void *ptr)
+{
+    return *(int32_t *)ptr;
+}
+#else
+static inline int ldul_le_p(void *ptr)
 {
     return *(uint32_t *)ptr;
 }
+#endif
 
 static inline uint64_t ldq_le_p(void *ptr)
 {
@@ -397,7 +435,38 @@ static inline int ldsw_be_p(void *ptr)
 #endif
 }
 
-static inline int ldl_be_p(void *ptr)
+#if (TARGET_LONG_BITS == 64)
+static inline int64_t ldul_be_p(void *ptr)
+{
+#if defined(__i386__) || defined(__x86_64__)
+    int val;
+    asm volatile ("movl %1, %0\n"
+                  "bswap %0\n"
+                  : "=r" (val)
+                  : "m" (*(uint32_t *)ptr));
+    return (uint32_t)val;
+#else
+    uint8_t *b = (uint8_t *) ptr;
+    return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
+#endif
+}
+
+static inline int64_t ldsl_be_p(void *ptr)
+{
+#if defined(__i386__) || defined(__x86_64__)
+    int val;
+    asm volatile ("movl %1, %0\n"
+                  "bswap %0\n"
+                  : "=r" (val)
+                  : "m" (*(uint32_t *)ptr));
+    return (int32_t)val;
+#else
+    uint8_t *b = (uint8_t *) ptr;
+    return (int32_t)((b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]);
+#endif
+}
+#else
+static inline int ldul_be_p(void *ptr)
 {
 #if defined(__i386__) || defined(__x86_64__)
     int val;
@@ -411,12 +480,13 @@ static inline int ldl_be_p(void *ptr)
     return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
 #endif
 }
+#endif
 
 static inline uint64_t ldq_be_p(void *ptr)
 {
     uint32_t a,b;
-    a = ldl_be_p(ptr);
-    b = ldl_be_p(ptr+4);
+    a = ldul_be_p(ptr);
+    b = ldul_be_p(ptr+4);
     return (((uint64_t)a<<32)|b);
 }
 
@@ -464,7 +534,7 @@ static inline float32 ldfl_be_p(void *pt
         float32 f;
         uint32_t i;
     } u;
-    u.i = ldl_be_p(ptr);
+    u.i = ldul_be_p(ptr);
     return u.f;
 }
 
@@ -481,8 +551,8 @@ static inline void stfl_be_p(void *ptr, 
 static inline float64 ldfq_be_p(void *ptr)
 {
     CPU_DoubleU u;
-    u.l.upper = ldl_be_p(ptr);
-    u.l.lower = ldl_be_p(ptr + 4);
+    u.l.upper = ldul_be_p(ptr);
+    u.l.lower = ldul_be_p(ptr + 4);
     return u.d;
 }
 
@@ -506,10 +576,22 @@ static inline int ldsw_be_p(void *ptr)
     return *(int16_t *)ptr;
 }
 
-static inline int ldl_be_p(void *ptr)
+#if (TARGET_LONG_BITS == 64)
+static inline int64_t ldul_be_p(void *ptr)
+{
+    return *(uint32_t *)ptr;
+}
+
+static inline int64_t ldsl_be_p(void *ptr)
+{
+    return *(int32_t *)ptr;
+}
+#else
+static inline int ldul_be_p(void *ptr)
 {
     return *(uint32_t *)ptr;
 }
+#endif
 
 static inline uint64_t ldq_be_p(void *ptr)
 {
@@ -557,9 +639,13 @@ static inline void stfq_be_p(void *ptr, 
 
 /* target CPU memory access functions */
 #if defined(TARGET_WORDS_BIGENDIAN)
+/* native-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 ldul_p(p) ldul_be_p(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_p(p) ldsl_be_p(p)
+#endif
 #define ldq_p(p) ldq_be_p(p)
 #define ldfl_p(p) ldfl_be_p(p)
 #define ldfq_p(p) ldfq_be_p(p)
@@ -568,10 +654,29 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_p(p, v) stq_be_p(p, v)
 #define stfl_p(p, v) stfl_be_p(p, v)
 #define stfq_p(p, v) stfq_be_p(p, v)
+/* reverse-endian */
+#define lduwr_p(p) lduw_le_p(p)
+#define ldswr_p(p) ldsw_le_p(p)
+#define ldulr_p(p) ldul_le_p(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldslr_p(p) ldsl_le_p(p)
+#endif
+#define ldqr_p(p) ldq_le_p(p)
+#define ldflr_p(p) ldfl_le_p(p)
+#define ldfqr_p(p) ldfq_le_p(p)
+#define stwr_p(p, v) stw_le_p(p, v)
+#define stlr_p(p, v) stl_le_p(p, v)
+#define stqr_p(p, v) stq_le_p(p, v)
+#define stflr_p(p, v) stfl_le_p(p, v)
+#define stfqr_p(p, v) stfq_le_p(p, v)
 #else
+/* native-endian */
 #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 ldul_p(p) ldul_le_p(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_p(p) ldsl_le_p(p)
+#endif
 #define ldq_p(p) ldq_le_p(p)
 #define ldfl_p(p) ldfl_le_p(p)
 #define ldfq_p(p) ldfq_le_p(p)
@@ -580,6 +685,21 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_p(p, v) stq_le_p(p, v)
 #define stfl_p(p, v) stfl_le_p(p, v)
 #define stfq_p(p, v) stfq_le_p(p, v)
+/* reverse-endian */
+#define lduwr_p(p) lduw_be_p(p)
+#define ldswr_p(p) ldsw_be_p(p)
+#define ldulr_p(p) ldul_be_p(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldslr_p(p) ldsl_be_p(p)
+#endif
+#define ldqr_p(p) ldq_be_p(p)
+#define ldflr_p(p) ldfl_be_p(p)
+#define ldfqr_p(p) ldfq_be_p(p)
+#define stwr_p(p, v) stw_be_p(p, v)
+#define stlr_p(p, v) stl_be_p(p, v)
+#define stqr_p(p, v) stq_be_p(p, v)
+#define stflr_p(p, v) stfl_be_p(p, v)
+#define stfqr_p(p, v) stfq_be_p(p, v)
 #endif
 
 /* MMU memory access macros */
@@ -605,11 +725,15 @@ static inline void stfq_be_p(void *ptr, 
 #define laddr(x) (uint8_t *)(long)(x)
 #endif
 
+/* native-endian */
 #define ldub_raw(p) ldub_p(laddr((p)))
 #define ldsb_raw(p) ldsb_p(laddr((p)))
 #define lduw_raw(p) lduw_p(laddr((p)))
 #define ldsw_raw(p) ldsw_p(laddr((p)))
-#define ldl_raw(p) ldl_p(laddr((p)))
+#define ldul_raw(p) ldul_p(laddr((p)))
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_raw(p) ldsl_p(laddr((p)))
+#endif
 #define ldq_raw(p) ldq_p(laddr((p)))
 #define ldfl_raw(p) ldfl_p(laddr((p)))
 #define ldfq_raw(p) ldfq_p(laddr((p)))
@@ -619,16 +743,112 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_raw(p, v) stq_p(saddr((p)), v)
 #define stfl_raw(p, v) stfl_p(saddr((p)), v)
 #define stfq_raw(p, v) stfq_p(saddr((p)), v)
-
+/* reverse endian */
+#define ldubr_raw(p) ldub_p(laddr((p)))
+#define ldsbr_raw(p) ldsb_p(laddr((p)))
+#define lduwr_raw(p) lduwr_p(laddr((p)))
+#define ldswr_raw(p) ldswr_p(laddr((p)))
+#define ldulr_raw(p) ldulr_p(laddr((p)))
+#if (TARGET_LONG_BITS == 64)
+#define ldslr_raw(p) ldslr_p(laddr((p)))
+#endif
+#define ldqr_raw(p) ldqr_p(laddr((p)))
+#define ldflr_raw(p) ldflr_p(laddr((p)))
+#define ldfqr_raw(p) ldfqr_p(laddr((p)))
+#define stbr_raw(p, v) stb_p(saddr((p)), v)
+#define stwr_raw(p, v) stwr_p(saddr((p)), v)
+#define stlr_raw(p, v) stlr_p(saddr((p)), v)
+#define stqr_raw(p, v) stqr_p(saddr((p)), v)
+#define stflr_raw(p, v) stflr_p(saddr((p)), v)
+#define stfqr_raw(p, v) stfqr_p(saddr((p)), v)
+#if defined(TARGET_WORDS_BIGENDIAN)
+/* big-endian */
+#define ldub_be_raw(p) ldub_raw(p)
+#define ldsb_be_raw(p) ldsb_raw(p)
+#define lduw_be_raw(p) lduw_raw(p)
+#define ldsw_be_raw(p) ldsw_raw(p)
+#define ldul_be_raw(p) ldul_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_be_raw(p) ldsl_raw(p)
+#endif
+#define ldq_be_raw(p) ldq_raw(p)
+#define ldfl_be_raw(p) ldfl_raw(p)
+#define ldfq_be_raw(p) ldfq_raw(p)
+#define stb_be_raw(p, v) stb_raw(p, v)
+#define stw_be_raw(p, v) stw_raw(p, v)
+#define stl_be_raw(p, v) stl_raw(p, v)
+#define stq_be_raw(p, v) stq_raw(p, v)
+#define stfl_be_raw(p, v) stfl_raw(p, v)
+#define stfq_be_raw(p, v) stfq_raw(p, v)
+/* little-endian */
+#define ldub_le_raw(p) ldubr_raw(p)
+#define ldsb_le_raw(p) ldsbr_raw(p)
+#define lduw_le_raw(p) lduwr_raw(p)
+#define ldsw_le_raw(p) ldswr_raw(p)
+#define ldul_le_raw(p) ldulr_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_le_raw(p) ldslr_raw(p)
+#endif
+#define ldq_le_raw(p) ldqr_raw(p)
+#define ldfl_le_raw(p) ldflr_raw(p)
+#define ldfq_le_raw(p) ldfqr_raw(p)
+#define stb_le_raw(p, v) stbr_raw(p, v)
+#define stw_le_raw(p, v) stwr_raw(p, v)
+#define stl_le_raw(p, v) stlr_raw(p, v)
+#define stq_le_raw(p, v) stqr_raw(p, v)
+#define stfl_le_raw(p, v) stflr_raw(p, v)
+#define stfq_le_raw(p, v) stfqr_raw(p, v)
+#else
+/* big-endian */
+#define ldub_be_raw(p) ldubr_raw(p)
+#define ldsb_be_raw(p) ldsbr_raw(p)
+#define lduw_be_raw(p) lduwr_raw(p)
+#define ldsw_be_raw(p) ldswr_raw(p)
+#define ldul_be_raw(p) ldulr_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_be_raw(p) ldslr_raw(p)
+#endif
+#define ldq_be_raw(p) ldqr_raw(p)
+#define ldfl_be_raw(p) ldflr_raw(p)
+#define ldfq_be_raw(p) ldfqr_raw(p)
+#define stb_be_raw(p, v) stbr_raw(p, v)
+#define stw_be_raw(p, v) stwr_raw(p, v)
+#define stl_be_raw(p, v) stlr_raw(p, v)
+#define stq_be_raw(p, v) stqr_raw(p, v)
+#define stfl_be_raw(p, v) stflr_raw(p, v)
+#define stfq_be_raw(p, v) stfqr_raw(p, v)
+/* little-endian */
+#define ldub_le_raw(p) ldub_raw(p)
+#define ldsb_le_raw(p) ldsb_raw(p)
+#define lduw_le_raw(p) lduw_raw(p)
+#define ldsw_le_raw(p) ldsw_raw(p)
+#define ldul_le_raw(p) ldul_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_le_raw(p) ldsl_raw(p)
+#endif
+#define ldq_le_raw(p) ldq_raw(p)
+#define ldfl_le_raw(p) ldfl_raw(p)
+#define ldfq_le_raw(p) ldfq_raw(p)
+#define stb_le_raw(p, v) stb_raw(p, v)
+#define stw_le_raw(p, v) stw_raw(p, v)
+#define stl_le_raw(p, v) stl_raw(p, v)
+#define stq_le_raw(p, v) stq_raw(p, v)
+#define stfl_le_raw(p, v) stfl_raw(p, v)
+#define stfq_le_raw(p, v) stfq_raw(p, v)
+#endif
 
 #if defined(CONFIG_USER_ONLY)
 
 /* if user mode, no other memory access functions */
+/* native-endian */
 #define ldub(p) ldub_raw(p)
 #define ldsb(p) ldsb_raw(p)
 #define lduw(p) lduw_raw(p)
 #define ldsw(p) ldsw_raw(p)
-#define ldl(p) ldl_raw(p)
+#define ldul(p) ldul_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl(p) ldsl_raw(p)
+#endif
 #define ldq(p) ldq_raw(p)
 #define ldfl(p) ldfl_raw(p)
 #define ldfq(p) ldfq_raw(p)
@@ -638,19 +858,173 @@ static inline void stfq_be_p(void *ptr, 
 #define stq(p, v) stq_raw(p, v)
 #define stfl(p, v) stfl_raw(p, v)
 #define stfq(p, v) stfq_raw(p, v)
+/* reverse-endian */
+#define ldubr(p) ldub_raw(p)
+#define ldsbr(p) ldsb_raw(p)
+#define lduwr(p) lduwr_raw(p)
+#define ldswr(p) ldswr_raw(p)
+#define ldulr(p) ldulr_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldslr(p) ldslr_raw(p)
+#endif
+#define ldqr(p) ldqr_raw(p)
+#define ldflr(p) ldflr_raw(p)
+#define ldfqr(p) ldfqr_raw(p)
+#define stbr(p, v) stb_raw(p, v)
+#define stwr(p, v) stwr_raw(p, v)
+#define stlr(p, v) stlr_raw(p, v)
+#define stqr(p, v) stqr_raw(p, v)
+#define stflr(p, v) stflr_raw(p, v)
+#define stfqr(p, v) stfqr_raw(p, v)
+#if defined(TARGET_WORDS_BIGENDIAN)
+/* big-endian */
+#define ldub_be(p) ldub(p)
+#define ldsb_be(p) ldsb(p)
+#define lduw_be(p) lduw(p)
+#define ldsw_be(p) ldsw(p)
+#define ldul_be(p) ldul(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_be(p) ldsl(p)
+#endif
+#define ldq_be(p) ldq(p)
+#define ldfl_be(p) ldfl(p)
+#define ldfq_be(p) ldfq(p)
+#define stb_be(p, v) stb(p, v)
+#define stw_be(p, v) stw(p, v)
+#define stl_be(p, v) stl(p, v)
+#define stq_be(p, v) stq(p, v)
+#define stfl_be(p, v) stfl(p, v)
+#define stfq_be(p, v) stfq(p, v)
+/* little-endian */
+#define ldub_le(p) ldubr(p)
+#define ldsb_le(p) ldsbr(p)
+#define lduw_le(p) lduwr(p)
+#define ldsw_le(p) ldswr(p)
+#define ldul_le(p) ldulr(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_le(p) ldslr(p)
+#endif
+#define ldq_le(p) ldqr(p)
+#define ldfl_le(p) ldflr(p)
+#define ldfq_le(p) ldfqr(p)
+#define stb_le(p, v) stbr(p, v)
+#define stw_le(p, v) stwr(p, v)
+#define stl_le(p, v) stlr(p, v)
+#define stq_le(p, v) stqr(p, v)
+#define stfl_le(p, v) stflr(p, v)
+#define stfq_le(p, v) stfqr(p, v)
+#else
+/* big-endian */
+#define ldub_be(p) ldubr(p)
+#define ldsb_be(p) ldsbr(p)
+#define lduw_be(p) lduwr(p)
+#define ldsw_be(p) ldswr(p)
+#define ldul_be(p) ldulr(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_be(p) ldslr(p)
+#endif
+#define ldq_be(p) ldqr(p)
+#define ldfl_be(p) ldflr(p)
+#define ldfq_be(p) ldfqr(p)
+#define stb_be(p, v) stbr(p, v)
+#define stw_be(p, v) stwr(p, v)
+#define stl_be(p, v) stlr(p, v)
+#define stq_be(p, v) stqr(p, v)
+#define stfl_be(p, v) stflr(p, v)
+#define stfq_be(p, v) stfqr(p, v)
+/* little-endian */
+#define ldub_le(p) ldub(p)
+#define ldsb_le(p) ldsb(p)
+#define lduw_le(p) lduw(p)
+#define ldsw_le(p) ldsw(p)
+#define ldul_le(p) ldul(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_le(p) ldsl(p)
+#endif
+#define ldq_le(p) ldq(p)
+#define ldfl_le(p) ldfl(p)
+#define ldfq_le(p) ldfq(p)
+#define stb_le(p, v) stb(p, v)
+#define stw_le(p, v) stw(p, v)
+#define stl_le(p, v) stl(p, v)
+#define stq_le(p, v) stq(p, v)
+#define stfl_le(p, v) stfl(p, v)
+#define stfq_le(p, v) stfq(p, v)
+#endif
 
+/* native-endian */
 #define ldub_code(p) ldub_raw(p)
 #define ldsb_code(p) ldsb_raw(p)
 #define lduw_code(p) lduw_raw(p)
 #define ldsw_code(p) ldsw_raw(p)
-#define ldl_code(p) ldl_raw(p)
+#define ldul_code(p) ldul_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_code(p) ldsl_raw(p)
+#endif
 #define ldq_code(p) ldq_raw(p)
+/* reverse-endian */
+#define ldubr_code(p) ldub_raw(p)
+#define ldsbr_code(p) ldsb_raw(p)
+#define lduwr_code(p) lduwr_raw(p)
+#define ldswr_code(p) ldswr_raw(p)
+#define ldulr_code(p) ldulr_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldslr_code(p) ldslr_raw(p)
+#endif
+#define ldqr_code(p) ldqr_raw(p)
+#if defined(TARGET_WORDS_BIGENDIAN)
+/* big-endian */
+#define ldub_be_code(p) ldub_code(p)
+#define ldsb_be_code(p) ldsb_code(p)
+#define lduw_be_code(p) lduw_code(p)
+#define ldsw_be_code(p) ldsw_code(p)
+#define ldul_be_code(p) ldul_code(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_be_code(p) ldsl_code(p)
+#endif
+#define ldq_be_code(p) ldq_code(p)
+/* little-endian */
+#define ldub_le_code(p) ldubr_code(p)
+#define ldsb_le_code(p) ldsbr_code(p)
+#define lduw_le_code(p) lduwr_code(p)
+#define ldsw_le_code(p) ldswr_code(p)
+#define ldul_le_code(p) ldulr_code(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_le_code(p) ldslr_code(p)
+#endif
+#define ldq_le_code(p) ldqr_code(p)
+#else
+/* big-endian */
+#define ldub_be_code(p) ldubr_code(p)
+#define ldsb_be_code(p) ldsbr_code(p)
+#define lduw_be_code(p) lduwr_code(p)
+#define ldsw_be_code(p) ldswr_code(p)
+#define ldul_be_code(p) ldulr_code(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_be_code(p) ldslr_code(p)
+#endif
+#define ldq_be_code(p) ldqr_code(p)
+/* little-endian */
+#define ldub_le_code(p) ldub_code(p)
+#define ldsb_le_code(p) ldsb_code(p)
+#define lduw_le_code(p) lduw_code(p)
+#define ldsw_le_code(p) ldsw_code(p)
+#define ldul_le_code(p) ldul_code(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_le_code(p) ldsl_code(p)
+#endif
+#define ldq_le_code(p) ldq_code(p)
+#endif
 
+/* native-endian */
 #define ldub_kernel(p) ldub_raw(p)
 #define ldsb_kernel(p) ldsb_raw(p)
 #define lduw_kernel(p) lduw_raw(p)
 #define ldsw_kernel(p) ldsw_raw(p)
-#define ldl_kernel(p) ldl_raw(p)
+#define ldul_kernel(p) ldul_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_kernel(p) ldsl_raw(p)
+#endif
 #define ldq_kernel(p) ldq_raw(p)
 #define ldfl_kernel(p) ldfl_raw(p)
 #define ldfq_kernel(p) ldfq_raw(p)
@@ -660,6 +1034,99 @@ static inline void stfq_be_p(void *ptr, 
 #define stq_kernel(p, v) stq_raw(p, v)
 #define stfl_kernel(p, v) stfl_raw(p, v)
 #define stfq_kernel(p, vt) stfq_raw(p, v)
+/* reverse-endian */
+#define ldubr_kernel(p) ldub_raw(p)
+#define ldsbr_kernel(p) ldsb_raw(p)
+#define lduwr_kernel(p) lduwr_raw(p)
+#define ldswr_kernel(p) ldswr_raw(p)
+#define ldulr_kernel(p) ldulr_raw(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldslr_kernel(p) ldslr_raw(p)
+#endif
+#define ldqr_kernel(p) ldqr_raw(p)
+#define ldflr_kernel(p) ldflr_raw(p)
+#define ldfqr_kernel(p) ldfqr_raw(p)
+#define stbr_kernel(p, v) stbr_raw(p, v)
+#define stwr_kernel(p, v) stwr_raw(p, v)
+#define stlr_kernel(p, v) stlr_raw(p, v)
+#define stqr_kernel(p, v) stqr_raw(p, v)
+#define stflr_kernel(p, v) stflr_raw(p, v)
+#define stfqr_kernel(p, vt) stfqr_raw(p, v)
+#if defined(TARGET_WORDS_BIGENDIAN)
+/* big-endian */
+#define ldub_be_kernel(p) ldub_kernel(p)
+#define ldsb_be_kernel(p) ldsb_kernel(p)
+#define lduw_be_kernel(p) lduw_kernel(p)
+#define ldsw_be_kernel(p) ldsw_kernel(p)
+#define ldul_be_kernel(p) ldul_kernel(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_be_kernel(p) ldsl_kernel(p)
+#endif
+#define ldq_be_kernel(p) ldq_kernel(p)
+#define ldfl_be_kernel(p) ldfl_kernel(p)
+#define ldfq_be_kernel(p) ldfq_kernel(p)
+#define stb_be_kernel(p, v) stb_kernel(p, v)
+#define stw_be_kernel(p, v) stw_kernel(p, v)
+#define stl_be_kernel(p, v) stl_kernel(p, v)
+#define stq_be_kernel(p, v) stq_kernel(p, v)
+#define stfl_be_kernel(p, v) stfl_kernel(p, v)
+#define stfq_be_kernel(p, vt) stfq_kernel(p, vt)
+/* little-endian */
+#define ldub_le_kernel(p) ldubr_kernel(p)
+#define ldsb_le_kernel(p) ldsbr_kernel(p)
+#define lduw_le_kernel(p) lduwr_kernel(p)
+#define ldsw_le_kernel(p) ldswr_kernel(p)
+#define ldul_le_kernel(p) ldulr_kernel(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_le_kernel(p) ldslr_kernel(p)
+#endif
+#define ldq_le_kernel(p) ldqr_kernel(p)
+#define ldfl_le_kernel(p) ldflr_kernel(p)
+#define ldfq_le_kernel(p) ldfqr_kernel(p)
+#define stb_le_kernel(p, v) stbr_kernel(p, v)
+#define stw_le_kernel(p, v) stwr_kernel(p, v)
+#define stl_le_kernel(p, v) stlr_kernel(p, v)
+#define stq_le_kernel(p, v) stqr_kernel(p, v)
+#define stfl_le_kernel(p, v) stflr_kernel(p, v)
+#define stfq_le_kernel(p, vt) stfqr_kernel(p, vt)
+#else
+/* big-endian */
+#define ldub_be_kernel(p) ldubr_kernel(p)
+#define ldsb_be_kernel(p) ldsbr_kernel(p)
+#define lduw_be_kernel(p) lduwr_kernel(p)
+#define ldsw_be_kernel(p) ldswr_kernel(p)
+#define ldul_be_kernel(p) ldulr_kernel(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_be_kernel(p) ldslr_kernel(p)
+#endif
+#define ldq_be_kernel(p) ldqr_kernel(p)
+#define ldfl_be_kernel(p) ldflr_kernel(p)
+#define ldfq_be_kernel(p) ldfqr_kernel(p)
+#define stb_be_kernel(p, v) stbr_kernel(p, v)
+#define stw_be_kernel(p, v) stwr_kernel(p, v)
+#define stl_be_kernel(p, v) stlr_kernel(p, v)
+#define stq_be_kernel(p, v) stqr_kernel(p, v)
+#define stfl_be_kernel(p, v) stflr_kernel(p, v)
+#define stfq_be_kernel(p, vt) stfqr_kernel(p, vt)
+/* little-endian */
+#define ldub_le_kernel(p) ldub_kernel(p)
+#define ldsb_le_kernel(p) ldsb_kernel(p)
+#define lduw_le_kernel(p) lduw_kernel(p)
+#define ldsw_le_kernel(p) ldsw_kernel(p)
+#define ldul_le_kernel(p) ldul_kernel(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl_le_kernel(p) ldsl_kernel(p)
+#endif
+#define ldq_le_kernel(p) ldq_kernel(p)
+#define ldfl_le_kernel(p) ldfl_kernel(p)
+#define ldfq_le_kernel(p) ldfq_kernel(p)
+#define stb_le_kernel(p, v) stb_kernel(p, v)
+#define stw_le_kernel(p, v) stw_kernel(p, v)
+#define stl_le_kernel(p, v) stl_kernel(p, v)
+#define stq_le_kernel(p, v) stq_kernel(p, v)
+#define stfl_le_kernel(p, v) stfl_kernel(p, v)
+#define stfq_le_kernel(p, vt) stfq_kernel(p, vt)
+#endif
 
 #endif /* defined(CONFIG_USER_ONLY) */
 
@@ -790,6 +1257,8 @@ extern uint8_t *phys_ram_dirty;
    the physical address */
 #define IO_MEM_ROMD        (1)
 #define IO_MEM_SUBPAGE     (2)
+/* On some target CPUs, endiannes is stored in page tables */
+#define IO_MEM_REVERSE     (3)
 
 typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
 typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr);
@@ -821,7 +1290,7 @@ static inline void cpu_physical_memory_w
 }
 uint32_t ldub_phys(target_phys_addr_t addr);
 uint32_t lduw_phys(target_phys_addr_t addr);
-uint32_t ldl_phys(target_phys_addr_t addr);
+uint32_t ldul_phys(target_phys_addr_t addr);
 uint64_t ldq_phys(target_phys_addr_t addr);
 void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val);
 void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val);

Index: cpu-exec.c
===================================================================
RCS file: /sources/qemu/qemu/cpu-exec.c,v
retrieving revision 1.119

cpu-exec.c +2 -2
diff -u -d -d -p -r1.119 cpu-exec.c
@@ -436,12 +436,12 @@ int cpu_exec(CPUState *env1)
                          /* FIXME: this should respect TPR */
                          env->interrupt_request &= ~CPU_INTERRUPT_VIRQ;
                          svm_check_intercept(SVM_EXIT_VINTR);
-                         intno = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_vector));
+                         intno = ldul_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_vector));
                          if (loglevel & CPU_LOG_TB_IN_ASM)
                              fprintf(logfile, "Servicing virtual hardware INT=0x%02x\n", intno);
 	                 do_interrupt(intno, 0, 0, -1, 1);
                          stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl),
-                                  ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl)) & ~V_IRQ_MASK);
+                                  ldul_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl)) & ~V_IRQ_MASK);
 #if defined(__sparc__) && !defined(HOST_SOLARIS)
                          tmp_T0 = 0;
 #else

Index: exec-all.h
===================================================================
RCS file: /sources/qemu/qemu/exec-all.h,v
retrieving revision 1.67

exec-all.h +16 -0
diff -u -d -d -p -r1.67 exec-all.h
@@ -569,6 +569,21 @@ void tlb_fill(target_ulong addr, int is_
 #define MEMSUFFIX _code
 #define env cpu_single_env
 
+/* native-endian */
+#define DATA_SIZE 1
+#include "softmmu_header.h"
+
+#define DATA_SIZE 2
+#include "softmmu_header.h"
+
+#define DATA_SIZE 4
+#include "softmmu_header.h"
+
+#define DATA_SIZE 8
+#include "softmmu_header.h"
+
+/* reverse-endian */
+#define REVERSE_ENDIAN
 #define DATA_SIZE 1
 #include "softmmu_header.h"
 
@@ -580,6 +595,7 @@ void tlb_fill(target_ulong addr, int is_
 
 #define DATA_SIZE 8
 #include "softmmu_header.h"
+#undef REVERSE_ENDIAN
 
 #undef ACCESS_TYPE
 #undef MEMSUFFIX

Index: exec.c
===================================================================
RCS file: /sources/qemu/qemu/exec.c,v
retrieving revision 1.108

exec.c +99 -38

193 lines not on this page · raw message

Index: monitor.c
===================================================================
RCS file: /sources/qemu/qemu/monitor.c,v
retrieving revision 1.83

monitor.c +1 -1
diff -u -d -d -p -r1.83 monitor.c
@@ -595,7 +595,7 @@ static void memory_dump(int count, int f
                 v = lduw_raw(buf + i);
                 break;
             case 4:
-                v = (uint32_t)ldl_raw(buf + i);
+                v = (uint32_t)ldul_raw(buf + i);
                 break;
             case 8:
                 v = ldq_raw(buf + i);

Index: softmmu_exec.h
===================================================================
RCS file: /sources/qemu/qemu/softmmu_exec.h,v
retrieving revision 1.1

softmmu_exec.h +6 -3
diff -u -d -d -p -r1.1 softmmu_exec.h
@@ -1,7 +1,7 @@
 /* Common softmmu definitions and inline routines.  */
 
-#define ldul_user ldl_user
-#define ldul_kernel ldl_kernel
+#define lduq_user ldq_user
+#define lduq_kernel ldq_kernel
 
 #define ACCESS_TYPE 0
 #define MEMSUFFIX _kernel
@@ -56,7 +56,10 @@
 #define ldsb(p) ldsb_data(p)
 #define lduw(p) lduw_data(p)
 #define ldsw(p) ldsw_data(p)
-#define ldl(p) ldl_data(p)
+#define ldul(p) ldul_data(p)
+#if (TARGET_LONG_BITS == 64)
+#define ldsl(p) ldsl_data(p)
+#endif
 #define ldq(p) ldq_data(p)
 
 #define stb(p, v) stb_data(p, v)

Index: softmmu_header.h
===================================================================
RCS file: /sources/qemu/qemu/softmmu_header.h,v
retrieving revision 1.17

softmmu_header.h +179 -4

265 lines not on this page · raw message

Index: softmmu_template.h
===================================================================
RCS file: /sources/qemu/qemu/softmmu_template.h,v
retrieving revision 1.18

softmmu_template.h +249 -32

385 lines not on this page · raw message

Index: hw/eepro100.c
===================================================================
RCS file: /sources/qemu/qemu/hw/eepro100.c,v
retrieving revision 1.6

eepro100.c +3 -3
diff -u -d -d -p -r1.6 eepro100.c
@@ -723,7 +723,7 @@ static void eepro100_cu_command(EEPRO100
             uint32_t tbd_address = cb_address + 0x10;
             assert(tcb_bytes <= sizeof(buf));
             while (size < tcb_bytes) {
-                uint32_t tx_buffer_address = ldl_phys(tbd_address);
+                uint32_t tx_buffer_address = ldul_phys(tbd_address);
                 uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
                 //~ uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
                 tbd_address += 8;
@@ -743,7 +743,7 @@ static void eepro100_cu_command(EEPRO100
                     /* Extended TCB. */
                     assert(tcb_bytes == 0);
                     for (; tbd_count < 2; tbd_count++) {
-                        uint32_t tx_buffer_address = ldl_phys(tbd_address);
+                        uint32_t tx_buffer_address = ldul_phys(tbd_address);
                         uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
                         uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
                         tbd_address += 8;
@@ -760,7 +760,7 @@ static void eepro100_cu_command(EEPRO100
                 }
                 tbd_address = tbd_array;
                 for (; tbd_count < tx.tbd_count; tbd_count++) {
-                    uint32_t tx_buffer_address = ldl_phys(tbd_address);
+                    uint32_t tx_buffer_address = ldul_phys(tbd_address);
                     uint16_t tx_buffer_size = lduw_phys(tbd_address + 4);
                     uint16_t tx_buffer_el = lduw_phys(tbd_address + 6);
                     tbd_address += 8;

Index: hw/pc.c
===================================================================
RCS file: /sources/qemu/qemu/hw/pc.c,v
retrieving revision 1.87

pc.c +3 -3
diff -u -d -d -p -r1.87 pc.c
@@ -477,8 +477,8 @@ static void load_linux(const char *kerne
     }
 
     /* kernel protocol version */
-    fprintf(stderr, "header magic: %#x\n", ldl_p(header+0x202));
-    if (ldl_p(header+0x202) == 0x53726448)
+    fprintf(stderr, "header magic: %#x\n", ldul_p(header+0x202));
+    if (ldul_p(header+0x202) == 0x53726448)
 	protocol = lduw_p(header+0x206);
     else
 	protocol = 0;
@@ -510,7 +510,7 @@ static void load_linux(const char *kerne
 
     /* highest address for loading the initrd */
     if (protocol >= 0x203)
-	initrd_max = ldl_p(header+0x22c);
+	initrd_max = ldul_p(header+0x22c);
     else
 	initrd_max = 0x37ffffff;
 

Index: hw/pl080.c
===================================================================
RCS file: /sources/qemu/qemu/hw/pl080.c,v
retrieving revision 1.5

pl080.c +4 -4
diff -u -d -d -p -r1.5 pl080.c
@@ -162,10 +162,10 @@ again:
             if (size == 0) {
                 /* Transfer complete.  */
                 if (ch->lli) {
-                    ch->src = ldl_phys(ch->lli);
-                    ch->dest = ldl_phys(ch->lli + 4);
-                    ch->ctrl = ldl_phys(ch->lli + 12);
-                    ch->lli = ldl_phys(ch->lli + 8);
+                    ch->src = ldul_phys(ch->lli);
+                    ch->dest = ldul_phys(ch->lli + 4);
+                    ch->ctrl = ldul_phys(ch->lli + 12);
+                    ch->lli = ldul_phys(ch->lli + 8);
                 } else {
                     ch->conf &= ~PL080_CCONF_E;
                 }

Index: hw/sun4m.c
===================================================================
RCS file: /sources/qemu/qemu/hw/sun4m.c,v
retrieving revision 1.55

sun4m.c +1 -1
diff -u -d -d -p -r1.55 sun4m.c
@@ -465,7 +465,7 @@ static void sun4m_load_kernel(long vram_
         }
         if (initrd_size > 0) {
             for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
-                if (ldl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i)
+                if (ldul_raw(phys_ram_base + KERNEL_LOAD_ADDR + i)
                     == 0x48647253) { // HdrS
                     stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
                     stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 20, initrd_size);

Index: hw/sun4u.c
===================================================================
RCS file: /sources/qemu/qemu/hw/sun4u.c,v
retrieving revision 1.22

sun4u.c +1 -1
diff -u -d -d -p -r1.22 sun4u.c
@@ -418,7 +418,7 @@ static void sun4u_init(int ram_size, int
         }
         if (initrd_size > 0) {
             for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
-                if (ldl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i)
+                if (ldul_raw(phys_ram_base + KERNEL_LOAD_ADDR + i)
                     == 0x48647253) { // HdrS
                     stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
                     stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 20, initrd_size);

Index: linux-user/elfload.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/elfload.c,v retrieving revision 1.51

elfload.c +1 -1
diff -u -d -d -p -r1.51 elfload.c
@@ -336,7 +336,7 @@ static inline void init_thread(struct ta
     pos += sizeof(target_ulong);
     _regs->gpr[4] = pos;
     for (tmp = 1; tmp != 0; pos += sizeof(target_ulong))
-        tmp = ldl(pos);
+        tmp = ldul(pos);
     _regs->gpr[5] = pos;
 }
 

Index: linux-user/qemu.h
===================================================================
RCS file: /sources/qemu/qemu/linux-user/qemu.h,v
retrieving revision 1.40

qemu.h +2 -2
diff -u -d -d -p -r1.40 qemu.h
@@ -313,7 +313,7 @@ static inline void *lock_user_string(tar
 #define tput8(addr, val) stb(addr, val)
 #define tget16(addr) lduw(addr)
 #define tput16(addr, val) stw(addr, val)
-#define tget32(addr) ldl(addr)
+#define tget32(addr) ldul(addr)
 #define tput32(addr, val) stl(addr, val)
 #define tget64(addr) ldq(addr)
 #define tput64(addr, val) stq(addr, val)
@@ -321,7 +321,7 @@ static inline void *lock_user_string(tar
 #define tgetl(addr) ldq(addr)
 #define tputl(addr, val) stq(addr, val)
 #else
-#define tgetl(addr) ldl(addr)
+#define tgetl(addr) ldul(addr)
 #define tputl(addr, val) stl(addr, val)
 #endif
 

Index: linux-user/signal.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/signal.c,v retrieving revision 1.45

signal.c +11 -11
diff -u -d -d -p -r1.45 signal.c
@@ -878,28 +878,28 @@ restore_sigcontext(CPUX86State *env, str
         cpu_x86_load_seg(env, R_ES, lduw(&sc->es));
         cpu_x86_load_seg(env, R_DS, lduw(&sc->ds));
 
-        env->regs[R_EDI] = ldl(&sc->edi);
-        env->regs[R_ESI] = ldl(&sc->esi);
-        env->regs[R_EBP] = ldl(&sc->ebp);
-        env->regs[R_ESP] = ldl(&sc->esp);
-        env->regs[R_EBX] = ldl(&sc->ebx);
-        env->regs[R_EDX] = ldl(&sc->edx);
-        env->regs[R_ECX] = ldl(&sc->ecx);
-        env->eip = ldl(&sc->eip);
+        env->regs[R_EDI] = ldul(&sc->edi);
+        env->regs[R_ESI] = ldul(&sc->esi);
+        env->regs[R_EBP] = ldul(&sc->ebp);
+        env->regs[R_ESP] = ldul(&sc->esp);
+        env->regs[R_EBX] = ldul(&sc->ebx);
+        env->regs[R_EDX] = ldul(&sc->edx);
+        env->regs[R_ECX] = ldul(&sc->ecx);
+        env->eip = ldul(&sc->eip);
 
         cpu_x86_load_seg(env, R_CS, lduw(&sc->cs) | 3);
         cpu_x86_load_seg(env, R_SS, lduw(&sc->ss) | 3);
 
 	{
 		unsigned int tmpflags;
-                tmpflags = ldl(&sc->eflags);
+                tmpflags = ldul(&sc->eflags);
 		env->eflags = (env->eflags & ~0x40DD5) | (tmpflags & 0x40DD5);
                 //		regs->orig_eax = -1;		/* disable syscall checks */
 	}
 
 	{
 		struct _fpstate * buf;
-                buf = (void *)ldl(&sc->fpstate);
+                buf = (void *)ldul(&sc->fpstate);
 		if (buf) {
 #if 0
 			if (verify_area(VERIFY_READ, buf, sizeof(*buf)))
@@ -909,7 +909,7 @@ restore_sigcontext(CPUX86State *env, str
 		}
 	}
 
-        *peax = ldl(&sc->eax);
+        *peax = ldul(&sc->eax);
 	return err;
 #if 0
 badframe:

Index: linux-user/vm86.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/vm86.c,v
retrieving revision 1.11

vm86.c +1 -1
diff -u -d -d -p -r1.11 vm86.c
@@ -56,7 +56,7 @@ static inline unsigned int vm_getw(uint8
 
 static inline unsigned int vm_getl(uint8_t *segptr, unsigned int reg16)
 {
-    return ldl(segptr + (reg16 & 0xffff));
+    return ldul(segptr + (reg16 & 0xffff));
 }
 
 void save_v86_state(CPUX86State *env)

Index: target-alpha/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/exec.h,v retrieving revision 1.3

exec.h +3 -0
diff -u -d -d -p -r1.3 exec.h
@@ -62,6 +62,9 @@ register uint64_t T2 asm(AREG3);
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 static inline void env_to_regs(void)

Index: target-alpha/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/helper.c,v retrieving revision 1.4

helper.c +1 -1
diff -u -d -d -p -r1.4 helper.c
@@ -69,7 +69,7 @@ int cpu_alpha_handle_mmu_fault (CPUState
             env->exception_index = EXCP_DTB_MISS_PAL;
         else
             env->exception_index = EXCP_DTB_MISS_NATIVE;
-        opc = (ldl_code(env->pc) >> 21) << 4;
+        opc = (ldul_code(env->pc) >> 21) << 4;
         if (rw) {
             opc |= 0x9;
         } else {

Index: target-alpha/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/op_helper.c,v retrieving revision 1.2

op_helper.c +16 -0
diff -u -d -d -p -r1.2 op_helper.c
@@ -1207,6 +1207,21 @@ void helper_st_phys_to_virt (void)
 
 #define MMUSUFFIX _mmu
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -1218,6 +1233,7 @@ void helper_st_phys_to_virt (void)
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-alpha/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/op_mem.h,v retrieving revision 1.2

op_mem.h +2 -2
diff -u -d -d -p -r1.2 op_mem.h
@@ -30,7 +30,7 @@ static inline uint32_t glue(ldl_l, MEMSU
 {
     env->lock = EA;
 
-    return glue(ldl, MEMSUFFIX)(EA);
+    return glue(ldul, MEMSUFFIX)(EA);
 }
 
 static inline uint32_t glue(ldq_l, MEMSUFFIX) (target_ulong EA)
@@ -82,7 +82,7 @@ ALPHA_LD_OP(bu, ldub);
 ALPHA_ST_OP(b, stb);
 ALPHA_LD_OP(wu, lduw);
 ALPHA_ST_OP(w, stw);
-ALPHA_LD_OP(l, ldl);
+ALPHA_LD_OP(l, ldul);
 ALPHA_ST_OP(l, stl);
 ALPHA_LD_OP(q, ldq);
 ALPHA_ST_OP(q, stq);

Index: target-alpha/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-alpha/translate.c,v retrieving revision 1.5

translate.c +1 -1
diff -u -d -d -p -r1.5 translate.c
@@ -2010,7 +2010,7 @@ int gen_intermediate_code_internal (CPUS
                     ctx.pc, ctx.mem_idx);
         }
 #endif
-        insn = ldl_code(ctx.pc);
+        insn = ldul_code(ctx.pc);
 #if defined ALPHA_DEBUG_DISAS
         insn_count++;
         if (logfile != NULL) {

Index: target-arm/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-arm/exec.h,v
retrieving revision 1.13

exec.h +3 -0
diff -u -d -d -p -r1.13 exec.h
@@ -64,6 +64,9 @@ static inline int cpu_halted(CPUState *e
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 /* In op_helper.c */

Index: target-arm/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-arm/helper.c,v retrieving revision 1.22

helper.c +3 -3
diff -u -d -d -p -r1.22 helper.c
@@ -297,7 +297,7 @@ void do_interrupt(CPUARMState *env)
             if (env->thumb) {
                 mask = lduw_code(env->regs[15] - 2) & 0xff;
             } else {
-                mask = ldl_code(env->regs[15] - 4) & 0xffffff;
+                mask = ldul_code(env->regs[15] - 4) & 0xffffff;
             }
             /* Only intercept calls from privileged modes, to provide some
                semblance of security.  */
@@ -473,7 +473,7 @@ static int get_phys_addr(CPUState *env, 
         /* Pagetable walk.  */
         /* Lookup l1 descriptor.  */
         table = (env->cp15.c2_base & 0xffffc000) | ((address >> 18) & 0x3ffc);
-        desc = ldl_phys(table);
+        desc = ldul_phys(table);
         type = (desc & 3);
         domain = (env->cp15.c3 >> ((desc >> 4) & 0x1e)) & 3;
         if (type == 0) {
@@ -502,7 +502,7 @@ static int get_phys_addr(CPUState *env, 
                 /* Fine pagetable.  */
                 table = (desc & 0xfffff000) | ((address >> 8) & 0xffc);
             }
-            desc = ldl_phys(table);
+            desc = ldul_phys(table);
             switch (desc & 3) {
             case 0: /* Page translation fault.  */
                 code = 7;

Index: target-arm/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-arm/op_helper.c,v retrieving revision 1.6

op_helper.c +16 -0
diff -u -d -d -p -r1.6 op_helper.c
@@ -180,6 +180,21 @@ void do_vfp_get_fpscr(void)
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -191,6 +206,7 @@ void do_vfp_get_fpscr(void)
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-arm/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-arm/op_mem.h,v retrieving revision 1.2

op_mem.h +9 -10
diff -u -d -d -p -r1.2 op_mem.h
@@ -1,18 +1,17 @@
 /* ARM memory operations.  */
 
-/* Load from address T1 into T0.  */
-#define MEM_LD_OP(name) \
+#define MEM_LD_OP(name, lname) \
 void OPPROTO glue(op_ld##name,MEMSUFFIX)(void) \
 { \
-    T0 = glue(ld##name,MEMSUFFIX)(T1); \
+    T0 = glue(ld##lname,MEMSUFFIX)(T1); \
     FORCE_RET(); \
 }
 
-MEM_LD_OP(ub)
-MEM_LD_OP(sb)
-MEM_LD_OP(uw)
-MEM_LD_OP(sw)
-MEM_LD_OP(l)
+MEM_LD_OP(ub,ub)
+MEM_LD_OP(sb,sb)
+MEM_LD_OP(uw,uw)
+MEM_LD_OP(sw,sw)
+MEM_LD_OP(l,ul)
 
 #undef MEM_LD_OP
 
@@ -45,7 +44,7 @@ void OPPROTO glue(op_swp##name,MEMSUFFIX
 }
 
 MEM_SWP_OP(b, ub)
-MEM_SWP_OP(l, l)
+MEM_SWP_OP(l, ul)
 
 #undef MEM_SWP_OP
 
@@ -82,7 +81,7 @@ void OPPROTO glue(op_iwmmxt_st##name,MEM
 
 MMX_MEM_OP(b, ub)
 MMX_MEM_OP(w, uw)
-MMX_MEM_OP(l, l)
+MMX_MEM_OP(l, ul)
 MMX_MEM_OP(q, q)
 
 #undef MMX_MEM_OP

Index: target-arm/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-arm/translate.c,v retrieving revision 1.57

translate.c +1 -1
diff -u -d -d -p -r1.57 translate.c
@@ -2206,7 +2206,7 @@ static void disas_arm_insn(CPUState * en
 {
     unsigned int cond, insn, val, op1, i, shift, rm, rs, rn, rd, sh;
 
-    insn = ldl_code(s->pc);
+    insn = ldul_code(s->pc);
     s->pc += 4;
 
     cond = insn >> 28;

Index: target-cris/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-cris/exec.h,v
retrieving revision 1.1

exec.h +3 -0
diff -u -d -d -p -r1.1 exec.h
@@ -50,6 +50,9 @@ void tlb_fill (target_ulong addr, int is
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 void cpu_cris_flush_flags(CPUCRISState *env, int cc_op);

Index: target-cris/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-cris/helper.c,v retrieving revision 1.1

helper.c +3 -3
diff -u -d -d -p -r1.1 helper.c
@@ -106,7 +106,7 @@ void do_interrupt(CPUState *env)
 //			printf ("BREAK! %d\n", env->trapnr);
 			irqnum = env->trapnr;
 			ebp = env->pregs[SR_EBP];
-			isr = ldl_code(ebp + irqnum * 4);
+			isr = ldul_code(ebp + irqnum * 4);
 			env->pregs[SR_ERP] = env->pc + 2;
 			env->pc = isr;
 
@@ -117,7 +117,7 @@ void do_interrupt(CPUState *env)
 //			printf ("MMU miss\n");
 			irqnum = 4;
 			ebp = env->pregs[SR_EBP];
-			isr = ldl_code(ebp + irqnum * 4);
+			isr = ldul_code(ebp + irqnum * 4);
 			env->pregs[SR_ERP] = env->pc;
 			env->pc = isr;
 			cris_shift_ccs(env);
@@ -138,7 +138,7 @@ void do_interrupt(CPUState *env)
 					__builtin_clz(env->pending_interrupts);
 				irqnum += 0x30;
 				ebp = env->pregs[SR_EBP];
-				isr = ldl_code(ebp + irqnum * 4);
+				isr = ldul_code(ebp + irqnum * 4);
 				env->pregs[SR_ERP] = env->pc;
 				env->pc = isr;
 

Index: target-cris/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-cris/op_helper.c,v retrieving revision 1.1

op_helper.c +16 -0
diff -u -d -d -p -r1.1 op_helper.c
@@ -25,6 +25,21 @@
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -36,6 +51,7 @@
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* Try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-cris/op_mem.c
===================================================================
RCS file: /sources/qemu/qemu/target-cris/op_mem.c,v retrieving revision 1.1

op_mem.c +1 -1
diff -u -d -d -p -r1.1 op_mem.c
@@ -49,7 +49,7 @@ void glue(op_stw_T0_T1, MEMSUFFIX) (void
 }
 
 void glue(op_ldl_T0_T0, MEMSUFFIX) (void) {
-    T0 = glue(ldl, MEMSUFFIX) (T0);
+    T0 = glue(ldul, MEMSUFFIX) (T0);
     RETURN();
 }
 

Index: target-cris/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-cris/translate.c,v retrieving revision 1.1

translate.c +8 -8
diff -u -d -d -p -r1.1 translate.c
@@ -828,7 +828,7 @@ static int dec_prep_alu_m(DisasContext *
 		if (memsize == 1)
 			insn_len++;
 
-		imm = ldl_code(dc->pc + 2);
+		imm = ldul_code(dc->pc + 2);
 		if (memsize != 4) {
 			if (s_ext) {
 				imm = sign_extend(imm, (memsize * 8) - 1);
@@ -1962,7 +1962,7 @@ static unsigned int dec_lapc_im(DisasCon
 	rd = dc->op2;
 
 	cris_cc_mask(dc, 0);
-	imm = ldl_code(dc->pc + 2);
+	imm = ldul_code(dc->pc + 2);
 	DIS(fprintf (logfile, "lapc 0x%x, $r%u\n", imm + dc->pc, dc->op2));
 	gen_op_movl_T0_im (dc->pc + imm);
 	gen_movl_reg_T0[rd] ();
@@ -1999,7 +1999,7 @@ static unsigned int dec_jas_im(DisasCont
 {
 	uint32_t imm;
 
-	imm = ldl_code(dc->pc + 2);
+	imm = ldul_code(dc->pc + 2);
 
 	DIS(fprintf (logfile, "jas 0x%x\n", imm));
 	cris_cc_mask(dc, 0);
@@ -2016,7 +2016,7 @@ static unsigned int dec_jasc_im(DisasCon
 {
 	uint32_t imm;
 
-	imm = ldl_code(dc->pc + 2);
+	imm = ldul_code(dc->pc + 2);
 
 	DIS(fprintf (logfile, "jasc 0x%x\n", imm));
 	cris_cc_mask(dc, 0);
@@ -2047,7 +2047,7 @@ static unsigned int dec_bcc_im(DisasCont
 	int32_t offset;
 	uint32_t cond = dc->op2;
 
-	offset = ldl_code(dc->pc + 2);
+	offset = ldul_code(dc->pc + 2);
 	offset = sign_extend(offset, 15);
 
 	DIS(fprintf (logfile, "b%s %d pc=%x dst=%x\n",
@@ -2065,7 +2065,7 @@ static unsigned int dec_bas_im(DisasCont
 	int32_t simm;
 
 
-	simm = ldl_code(dc->pc + 2);
+	simm = ldul_code(dc->pc + 2);
 
 	DIS(fprintf (logfile, "bas 0x%x, $p%u\n", dc->pc + simm, dc->op2));
 	cris_cc_mask(dc, 0);
@@ -2081,7 +2081,7 @@ static unsigned int dec_bas_im(DisasCont
 static unsigned int dec_basc_im(DisasContext *dc)
 {
 	int32_t simm;
-	simm = ldl_code(dc->pc + 2);
+	simm = ldul_code(dc->pc + 2);
 
 	DIS(fprintf (logfile, "basc 0x%x, $p%u\n", dc->pc + simm, dc->op2));
 	cris_cc_mask(dc, 0);
@@ -2259,7 +2259,7 @@ cris_decoder(DisasContext *dc)
 	int i;
 
 	/* Load a halfword onto the instruction register.  */
-	tmp = ldl_code(dc->pc);
+	tmp = ldul_code(dc->pc);
 	dc->ir = tmp & 0xffff;
 
 	/* Now decode it.  */

Index: target-i386/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-i386/exec.h,v
retrieving revision 1.37

exec.h +6 -3
diff -u -d -d -p -r1.37 exec.h
@@ -217,6 +217,9 @@ void check_iol_DX(void);
 #if !defined(CONFIG_USER_ONLY)
 
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 
 static inline double ldfq(target_ulong ptr)
 {
@@ -244,7 +247,7 @@ static inline float ldfl(target_ulong pt
         float f;
         uint32_t i;
     } u;
-    u.i = ldl(ptr);
+    u.i = ldul(ptr);
     return u.f;
 }
 
@@ -419,12 +422,12 @@ static inline void helper_fstt(CPU86_LDo
 
 static inline CPU86_LDouble helper_fldt(target_ulong ptr)
 {
-    return *(CPU86_LDouble *)ptr;
+    return *(CPU86_LDouble *)(unsigned long)ptr;
 }
 
 static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr)
 {
-    *(CPU86_LDouble *)ptr = f;
+    *(CPU86_LDouble *)(unsigned long)ptr = f;
 }
 
 #else

Index: target-i386/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/helper.c,v retrieving revision 1.89

helper.c +103 -87

398 lines not on this page · raw message

Index: target-i386/helper2.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/helper2.c,v retrieving revision 1.52

helper2.c +9 -9
diff -u -d -d -p -r1.52 helper2.c
@@ -771,7 +771,7 @@ int cpu_x86_handle_mmu_fault(CPUX86State
         /* page directory entry */
         pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) &
             env->a20_mask;
-        pde = ldl_phys(pde_addr);
+        pde = ldul_phys(pde_addr);
         if (!(pde & PG_PRESENT_MASK)) {
             error_code = 0;
             goto do_fault;
@@ -809,7 +809,7 @@ int cpu_x86_handle_mmu_fault(CPUX86State
             /* page directory entry */
             pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) &
                 env->a20_mask;
-            pte = ldl_phys(pte_addr);
+            pte = ldul_phys(pte_addr);
             if (!(pte & PG_PRESENT_MASK)) {
                 error_code = 0;
                 goto do_fault;
@@ -909,13 +909,13 @@ target_phys_addr_t cpu_get_phys_page_deb
 
             pml4e_addr = ((env->cr[3] & ~0xfff) + (((addr >> 39) & 0x1ff) << 3)) &
                 env->a20_mask;
-            pml4e = ldl_phys(pml4e_addr);
+            pml4e = ldul_phys(pml4e_addr);
             if (!(pml4e & PG_PRESENT_MASK))
                 return -1;
 
             pdpe_addr = ((pml4e & ~0xfff) + (((addr >> 30) & 0x1ff) << 3)) &
                 env->a20_mask;
-            pdpe = ldl_phys(pdpe_addr);
+            pdpe = ldul_phys(pdpe_addr);
             if (!(pdpe & PG_PRESENT_MASK))
                 return -1;
         } else
@@ -923,14 +923,14 @@ target_phys_addr_t cpu_get_phys_page_deb
         {
             pdpe_addr = ((env->cr[3] & ~0x1f) + ((addr >> 27) & 0x18)) &
                 env->a20_mask;
-            pdpe = ldl_phys(pdpe_addr);
+            pdpe = ldul_phys(pdpe_addr);
             if (!(pdpe & PG_PRESENT_MASK))
                 return -1;
         }
 
         pde_addr = ((pdpe & ~0xfff) + (((addr >> 21) & 0x1ff) << 3)) &
             env->a20_mask;
-        pde = ldl_phys(pde_addr);
+        pde = ldul_phys(pde_addr);
         if (!(pde & PG_PRESENT_MASK)) {
             return -1;
         }
@@ -943,7 +943,7 @@ target_phys_addr_t cpu_get_phys_page_deb
             pte_addr = ((pde & ~0xfff) + (((addr >> 12) & 0x1ff) << 3)) &
                 env->a20_mask;
             page_size = 4096;
-            pte = ldl_phys(pte_addr);
+            pte = ldul_phys(pte_addr);
         }
     } else {
         if (!(env->cr[0] & CR0_PG_MASK)) {
@@ -952,7 +952,7 @@ target_phys_addr_t cpu_get_phys_page_deb
         } else {
             /* page directory entry */
             pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & env->a20_mask;
-            pde = ldl_phys(pde_addr);
+            pde = ldul_phys(pde_addr);
             if (!(pde & PG_PRESENT_MASK))
                 return -1;
             if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
@@ -961,7 +961,7 @@ target_phys_addr_t cpu_get_phys_page_deb
             } else {
                 /* page directory entry */
                 pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & env->a20_mask;
-                pte = ldl_phys(pte_addr);
+                pte = ldul_phys(pte_addr);
                 if (!(pte & PG_PRESENT_MASK))
                     return -1;
                 page_size = 4096;

Index: target-i386/op.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/op.c,v
retrieving revision 1.51

op.c +10 -12
diff -u -d -d -p -r1.51 op.c
@@ -716,8 +716,8 @@ void OPPROTO op_boundw(void)
 void OPPROTO op_boundl(void)
 {
     int low, high, v;
-    low = ldl(A0);
-    high = ldl(A0 + 4);
+    low = ldul(A0);
+    high = ldul(A0 + 4);
     v = T0;
     if (v < low || v > high) {
         raise_exception(EXCP05_BOUND);
@@ -747,8 +747,6 @@ void OPPROTO op_exit_tb(void)
 
 /* multiple size ops */
 
-#define ldul ldl
-
 #define SHIFT 0
 #include "ops_template.h"
 #undef SHIFT
@@ -1688,7 +1686,7 @@ CCTable cc_table[CC_OP_NB] = {
 void OPPROTO op_flds_FT0_A0(void)
 {
 #ifdef USE_FP_CONVERT
-    FP_CONVERT.i32 = ldl(A0);
+    FP_CONVERT.i32 = ldul(A0);
     FT0 = FP_CONVERT.f;
 #else
     FT0 = ldfl(A0);
@@ -1715,7 +1713,7 @@ void helper_fild_FT0_A0(void)
 
 void helper_fildl_FT0_A0(void)
 {
-    FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
+    FT0 = (CPU86_LDouble)((int32_t)ldul(A0));
 }
 
 void helper_fildll_FT0_A0(void)
@@ -1753,10 +1751,10 @@ void OPPROTO op_fild_FT0_A0(void)
 void OPPROTO op_fildl_FT0_A0(void)
 {
 #ifdef USE_FP_CONVERT
-    FP_CONVERT.i32 = (int32_t) ldl(A0);
+    FP_CONVERT.i32 = (int32_t) ldul(A0);
     FT0 = (CPU86_LDouble)FP_CONVERT.i32;
 #else
-    FT0 = (CPU86_LDouble)((int32_t)ldl(A0));
+    FT0 = (CPU86_LDouble)((int32_t)ldul(A0));
 #endif
 }
 
@@ -1778,7 +1776,7 @@ void OPPROTO op_flds_ST0_A0(void)
     int new_fpstt;
     new_fpstt = (env->fpstt - 1) & 7;
 #ifdef USE_FP_CONVERT
-    FP_CONVERT.i32 = ldl(A0);
+    FP_CONVERT.i32 = ldul(A0);
     env->fpregs[new_fpstt].d = FP_CONVERT.f;
 #else
     env->fpregs[new_fpstt].d = ldfl(A0);
@@ -1822,7 +1820,7 @@ void helper_fildl_ST0_A0(void)
 {
     int new_fpstt;
     new_fpstt = (env->fpstt - 1) & 7;
-    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
+    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldul(A0));
     env->fpstt = new_fpstt;
     env->fptags[new_fpstt] = 0; /* validate stack entry */
 }
@@ -1872,10 +1870,10 @@ void OPPROTO op_fildl_ST0_A0(void)
     int new_fpstt;
     new_fpstt = (env->fpstt - 1) & 7;
 #ifdef USE_FP_CONVERT
-    FP_CONVERT.i32 = (int32_t) ldl(A0);
+    FP_CONVERT.i32 = (int32_t) ldul(A0);
     env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32;
 #else
-    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0));
+    env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldul(A0));
 #endif
     env->fpstt = new_fpstt;
     env->fptags[new_fpstt] = 0; /* validate stack entry */

Index: target-i386/ops_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-i386/ops_mem.h,v retrieving revision 1.7

ops_mem.h +4 -4
diff -u -d -d -p -r1.7 ops_mem.h
@@ -20,7 +20,7 @@ void OPPROTO glue(glue(op_ldsw, MEMSUFFI
 
 void OPPROTO glue(glue(op_ldl, MEMSUFFIX), _T0_A0)(void)
 {
-    T0 = (uint32_t)glue(ldl, MEMSUFFIX)(A0);
+    T0 = (uint32_t)glue(ldul, MEMSUFFIX)(A0);
 }
 
 void OPPROTO glue(glue(op_ldub, MEMSUFFIX), _T1_A0)(void)
@@ -45,7 +45,7 @@ void OPPROTO glue(glue(op_ldsw, MEMSUFFI
 
 void OPPROTO glue(glue(op_ldl, MEMSUFFIX), _T1_A0)(void)
 {
-    T1 = (uint32_t)glue(ldl, MEMSUFFIX)(A0);
+    T1 = (uint32_t)glue(ldul, MEMSUFFIX)(A0);
 }
 
 void OPPROTO glue(glue(op_stb, MEMSUFFIX), _T0_A0)(void)
@@ -122,12 +122,12 @@ void OPPROTO glue(glue(op_sto, MEMSUFFIX
 #ifdef TARGET_X86_64
 void OPPROTO glue(glue(op_ldsl, MEMSUFFIX), _T0_A0)(void)
 {
-    T0 = (int32_t)glue(ldl, MEMSUFFIX)(A0);
+    T0 = glue(ldsl, MEMSUFFIX)(A0);
 }
 
 void OPPROTO glue(glue(op_ldsl, MEMSUFFIX), _T1_A0)(void)
 {
-    T1 = (int32_t)glue(ldl, MEMSUFFIX)(A0);
+    T1 = glue(ldsl, MEMSUFFIX)(A0);
 }
 
 void OPPROTO glue(glue(op_ldq, MEMSUFFIX), _T0_A0)(void)

Index: target-i386/svm.h
===================================================================
RCS file: /sources/qemu/qemu/target-i386/svm.h,v
retrieving revision 1.1

svm.h +3 -3
diff -u -d -d -p -r1.1 svm.h
@@ -340,13 +340,13 @@ static inline int svm_check_intercept(un
                     R_##seg_index, \
                     lduw_phys(addr + offsetof(struct vmcb, save.seg.selector)),\
                     ldq_phys(addr + offsetof(struct vmcb, save.seg.base)),\
-                    ldl_phys(addr + offsetof(struct vmcb, save.seg.limit)),\
-                    vmcb2cpu_attrib(lduw_phys(addr + offsetof(struct vmcb, save.seg.attrib)), ldq_phys(addr + offsetof(struct vmcb, save.seg.base)), ldl_phys(addr + offsetof(struct vmcb, save.seg.limit))))
+                    ldul_phys(addr + offsetof(struct vmcb, save.seg.limit)),\
+                    vmcb2cpu_attrib(lduw_phys(addr + offsetof(struct vmcb, save.seg.attrib)), ldq_phys(addr + offsetof(struct vmcb, save.seg.base)), ldul_phys(addr + offsetof(struct vmcb, save.seg.limit))))
 
 #define SVM_LOAD_SEG2(addr, seg_qemu, seg_vmcb) \
     env->seg_qemu.selector  = lduw_phys(addr + offsetof(struct vmcb, save.seg_vmcb.selector)); \
     env->seg_qemu.base      = ldq_phys(addr + offsetof(struct vmcb, save.seg_vmcb.base)); \
-    env->seg_qemu.limit     = ldl_phys(addr + offsetof(struct vmcb, save.seg_vmcb.limit)); \
+    env->seg_qemu.limit     = ldul_phys(addr + offsetof(struct vmcb, save.seg_vmcb.limit)); \
     env->seg_qemu.flags     = vmcb2cpu_attrib(lduw_phys(addr + offsetof(struct vmcb, save.seg_vmcb.attrib)), env->seg_qemu.base, env->seg_qemu.limit)
 
 #define SVM_SAVE_SEG(addr, seg_qemu, seg_vmcb) \

Index: target-i386/translate-copy.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/translate-copy.c,v retrieving revision 1.9

translate-copy.c +3 -3
diff -u -d -d -p -r1.9 translate-copy.c
@@ -207,7 +207,7 @@ static inline void gen_lea_modrm(DisasCo
         case 0:
             if (base == 5) {
                 base = -1;
-                disp = ldl_code(s->pc);
+                disp = ldul_code(s->pc);
                 s->pc += 4;
             } else {
                 disp = 0;
@@ -218,7 +218,7 @@ static inline void gen_lea_modrm(DisasCo
             break;
         default:
         case 2:
-            disp = ldl_code(s->pc);
+            disp = ldul_code(s->pc);
             s->pc += 4;
             break;
         }
@@ -266,7 +266,7 @@ static inline uint32_t insn_get(DisasCon
         break;
     default:
     case OT_LONG:
-        ret = ldl_code(s->pc);
+        ret = ldul_code(s->pc);
         s->pc += 4;
         break;
     }

Index: target-i386/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-i386/translate.c,v retrieving revision 1.72

translate.c +3 -3
diff -u -d -d -p -r1.72 translate.c
@@ -1462,7 +1462,7 @@ static void gen_lea_modrm(DisasContext *
         case 0:
             if ((base & 7) == 5) {
                 base = -1;
-                disp = (int32_t)ldl_code(s->pc);
+                disp = (int32_t)ldul_code(s->pc);
                 s->pc += 4;
                 if (CODE64(s) && !havesib) {
                     disp += s->pc + s->rip_offset;
@@ -1476,7 +1476,7 @@ static void gen_lea_modrm(DisasContext *
             break;
         default:
         case 2:
-            disp = ldl_code(s->pc);
+            disp = ldul_code(s->pc);
             s->pc += 4;
             break;
         }
@@ -1736,7 +1736,7 @@ static inline uint32_t insn_get(DisasCon
         break;
     default:
     case OT_LONG:
-        ret = ldl_code(s->pc);
+        ret = ldul_code(s->pc);
         s->pc += 4;
         break;
     }

Index: target-m68k/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-m68k/exec.h,v
retrieving revision 1.4

exec.h +3 -0
diff -u -d -d -p -r1.4 exec.h
@@ -42,6 +42,9 @@ int cpu_m68k_handle_mmu_fault (CPUState 
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif
 
 void cpu_m68k_flush_flags(CPUM68KState *env, int cc_op);

Index: target-m68k/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-m68k/op_helper.c,v retrieving revision 1.6

op_helper.c +20 -4
diff -u -d -d -p -r1.6 op_helper.c
@@ -33,6 +33,21 @@ extern int semihosting_enabled;
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -44,6 +59,7 @@ extern int semihosting_enabled;
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* Try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not
@@ -83,8 +99,8 @@ static void do_rte(void)
     uint32_t fmt;
 
     sp = env->aregs[7];
-    fmt = ldl_kernel(sp);
-    env->pc = ldl_kernel(sp + 4);
+    fmt = ldul_kernel(sp);
+    env->pc = ldul_kernel(sp + 4);
     sp |= (fmt >> 28) & 3;
     env->sr = fmt & 0xffff;
     m68k_switch_sp(env);
@@ -112,7 +128,7 @@ void do_interrupt(int is_hw)
                     && (env->sr & SR_S) != 0
                     && (env->pc & 3) == 0
                     && lduw_code(env->pc - 4) == 0x4e71
-                    && ldl_code(env->pc) == 0x4e7bf000) {
+                    && ldul_code(env->pc) == 0x4e7bf000) {
                 env->pc += 4;
                 do_m68k_semihosting(env, env->dregs[0]);
                 return;
@@ -153,7 +169,7 @@ void do_interrupt(int is_hw)
     stl_kernel(sp, fmt);
     env->aregs[7] = sp;
     /* Jump to vector.  */
-    env->pc = ldl_kernel(env->vbr + vector);
+    env->pc = ldul_kernel(env->vbr + vector);
 }
 
 #endif

Index: target-m68k/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-m68k/op_mem.h,v retrieving revision 1.1

op_mem.h +1 -1
diff -u -d -d -p -r1.1 op_mem.h
@@ -11,7 +11,7 @@ MEM_LD_OP(8u32,ub)
 MEM_LD_OP(8s32,sb)
 MEM_LD_OP(16u32,uw)
 MEM_LD_OP(16s32,sw)
-MEM_LD_OP(32,l)
+MEM_LD_OP(32,ul)
 
 #undef MEM_LD_OP
 

Index: target-mips/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-mips/exec.h,v
retrieving revision 1.38

exec.h +3 -0
diff -u -d -d -p -r1.38 exec.h
@@ -54,6 +54,9 @@ register target_ulong T2 asm(AREG3);
 
 #if !defined(CONFIG_USER_ONLY)
 #include "softmmu_exec.h"
+#define REVERSE_ENDIAN
+#include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 #if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)

Index: target-mips/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_helper.c,v retrieving revision 1.65

op_helper.c +16 -0
diff -u -d -d -p -r1.65 op_helper.c
@@ -544,6 +544,21 @@ static void do_unaligned_access (target_
 #define MMUSUFFIX _mmu
 #define ALIGNED_ONLY
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -555,6 +570,7 @@ static void do_unaligned_access (target_
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr)
 {

Index: target-mips/op_mem.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_mem.c,v retrieving revision 1.14

op_mem.c +4 -4
diff -u -d -d -p -r1.14 op_mem.c
@@ -57,13 +57,13 @@ void glue(op_sh, MEMSUFFIX) (void)
 
 void glue(op_lw, MEMSUFFIX) (void)
 {
-    T0 = glue(ldl, MEMSUFFIX)(T0);
+    T0 = glue(ldul, MEMSUFFIX)(T0);
     RETURN();
 }
 
 void glue(op_lwu, MEMSUFFIX) (void)
 {
-    T0 = (uint32_t)glue(ldl, MEMSUFFIX)(T0);
+    T0 = (uint32_t)glue(ldul, MEMSUFFIX)(T0);
     RETURN();
 }
 
@@ -167,7 +167,7 @@ void glue(op_swr, MEMSUFFIX) (void)
 void glue(op_ll, MEMSUFFIX) (void)
 {
     T1 = T0;
-    T0 = glue(ldl, MEMSUFFIX)(T0);
+    T0 = glue(ldul, MEMSUFFIX)(T0);
     env->CP0_LLAddr = T1;
     RETURN();
 }
@@ -383,7 +383,7 @@ void glue(op_scd, MEMSUFFIX) (void)
 
 void glue(op_lwc1, MEMSUFFIX) (void)
 {
-    WT0 = glue(ldl, MEMSUFFIX)(T0);
+    WT0 = glue(ldul, MEMSUFFIX)(T0);
     RETURN();
 }
 void glue(op_swc1, MEMSUFFIX) (void)

Index: target-mips/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/translate.c,v retrieving revision 1.106

translate.c +1 -1
diff -u -d -d -p -r1.106 translate.c
@@ -6544,7 +6544,7 @@ gen_intermediate_code_internal (CPUState
             gen_opc_hflags[lj] = ctx.hflags & MIPS_HFLAG_BMASK;
             gen_opc_instr_start[lj] = 1;
         }
-        ctx.opcode = ldl_code(ctx.pc);
+        ctx.opcode = ldul_code(ctx.pc);
         decode_opc(env, &ctx);
         ctx.pc += 4;
 

Index: target-ppc/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/exec.h,v
retrieving revision 1.28

exec.h +5 -0
diff -u -d -d -p -r1.28 exec.h
@@ -91,7 +91,12 @@ static always_inline target_ulong rotl64
 #endif
 
 #if !defined(CONFIG_USER_ONLY)
+
+#include "softmmu_exec.h"
+#define REVERSE_ENDIAN
 #include "softmmu_exec.h"
+#undef REVERSE_ENDIAN
+
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 void do_raise_exception_err (uint32_t exception, int error_code);

Index: target-ppc/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/helper.c,v retrieving revision 1.75

helper.c +9 -9
diff -u -d -d -p -r1.75 helper.c
@@ -514,8 +514,8 @@ static always_inline int _find_pte (mmu_
         } else
 #endif
         {
-            pte0 = ldl_phys(base + (i * 8));
-            pte1 =  ldl_phys(base + (i * 8) + 4);
+            pte0 = ldul_phys(base + (i * 8));
+            pte1 =  ldul_phys(base + (i * 8) + 4);
             r = pte32_check(ctx, pte0, pte1, h, rw);
 #if defined (DEBUG_MMU)
             if (loglevel != 0) {
@@ -623,7 +623,7 @@ static int slb_lookup (CPUPPCState *env,
     slb_nr = env->slb_nr;
     for (n = 0; n < slb_nr; n++) {
         tmp64 = ldq_phys(sr_base);
-        tmp = ldl_phys(sr_base + 8);
+        tmp = ldul_phys(sr_base + 8);
 #if defined(DEBUG_SLB)
         if (loglevel != 0) {
             fprintf(logfile, "%s: seg %d " PADDRX " %016" PRIx64 " %08"
@@ -671,7 +671,7 @@ target_ulong ppc_load_slb (CPUPPCState *
     sr_base = env->spr[SPR_ASR];
     sr_base += 12 * slb_nr;
     tmp64 = ldq_phys(sr_base);
-    tmp = ldl_phys(sr_base + 8);
+    tmp = ldul_phys(sr_base + 8);
     if (tmp64 & 0x0000000008000000ULL) {
         /* SLB entry is valid */
         /* Copy SLB bits 62:88 to Rt 37:63 (VSID 23:49) */
@@ -877,10 +877,10 @@ static int get_segment (CPUState *env, m
                         sdr, mask + 0x80);
                 for (curaddr = sdr; curaddr < (sdr + mask + 0x80);
                      curaddr += 16) {
-                    a0 = ldl_phys(curaddr);
-                    a1 = ldl_phys(curaddr + 4);
-                    a2 = ldl_phys(curaddr + 8);
-                    a3 = ldl_phys(curaddr + 12);
+                    a0 = ldul_phys(curaddr);
+                    a1 = ldul_phys(curaddr + 4);
+                    a2 = ldul_phys(curaddr + 8);
+                    a3 = ldul_phys(curaddr + 12);
                     if (a0 != 0 || a1 != 0 || a2 != 0 || a3 != 0) {
                         fprintf(logfile,
                                 PADDRX ": %08x %08x %08x %08x\n",
@@ -2219,7 +2219,7 @@ static always_inline void powerpc_excp (
 #endif
         /* XXX: this is false */
         /* Get rS/rD and rA from faulting opcode */
-        env->spr[SPR_DSISR] |= (ldl_code((env->nip - 4)) & 0x03FF0000) >> 16;
+        env->spr[SPR_DSISR] |= (ldul_code((env->nip - 4)) & 0x03FF0000) >> 16;
         goto store_current;
     case POWERPC_EXCP_PROGRAM:   /* Program exception                        */
         switch (env->error_code & ~0xF) {

Index: target-ppc/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper.c,v retrieving revision 1.49

op_helper.c +16 -0
diff -u -d -d -p -r1.49 op_helper.c
@@ -2291,6 +2291,21 @@ DO_SPE_OP1(fsctuf);
 #define MMUSUFFIX _mmu
 #define GETPC() (__builtin_return_address(0))
 
+/* Native-endian */
+#define SHIFT 0
+#include "softmmu_template.h"
+
+#define SHIFT 1
+#include "softmmu_template.h"
+
+#define SHIFT 2
+#include "softmmu_template.h"
+
+#define SHIFT 3
+#include "softmmu_template.h"
+
+/* Reverse-endian */
+#define REVERSE_ENDIAN
 #define SHIFT 0
 #include "softmmu_template.h"
 
@@ -2302,6 +2317,7 @@ DO_SPE_OP1(fsctuf);
 
 #define SHIFT 3
 #include "softmmu_template.h"
+#undef REVERSE_ENDIAN
 
 /* try to fill the TLB and return an exception if error. If retaddr is
    NULL, it means that the function was called in C code (i.e. not

Index: target-ppc/op_helper.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper.h,v retrieving revision 1.21

op_helper.h +0 -13
diff -u -d -d -p -r1.21 op_helper.h
@@ -37,19 +37,6 @@ void glue(do_POWER2_lfq_le, MEMSUFFIX) (
 void glue(do_POWER2_stfq, MEMSUFFIX) (void);
 void glue(do_POWER2_stfq_le, MEMSUFFIX) (void);
 
-#if defined(TARGET_PPC64)
-void glue(do_lsw_64, MEMSUFFIX) (int dst);
-void glue(do_lsw_le_64, MEMSUFFIX) (int dst);
-void glue(do_stsw_64, MEMSUFFIX) (int src);
-void glue(do_stsw_le_64, MEMSUFFIX) (int src);
-void glue(do_lmw_64, MEMSUFFIX) (int dst);
-void glue(do_lmw_le_64, MEMSUFFIX) (int dst);
-void glue(do_stmw_64, MEMSUFFIX) (int src);
-void glue(do_stmw_le_64, MEMSUFFIX) (int src);
-void glue(do_icbi_64, MEMSUFFIX) (void);
-void glue(do_dcbz_64, MEMSUFFIX) (void);
-#endif
-
 #else
 
 void do_print_mem_EA (target_ulong EA);

Index: target-ppc/op_helper_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_helper_mem.h,v retrieving revision 1.14

op_helper_mem.h +47 -277

21 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Index: target-ppc/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/op_mem.h,v retrieving revision 1.22

op_mem.h +158 -287

445 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Index: target-ppc/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-ppc/translate.c,v retrieving revision 1.92

translate.c +1 -1
diff -u -d -d -p -r1.92 translate.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sh4/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-sh4/exec.h,v
retrieving revision 1.5

exec.h +3 -0
diff -u -d -d -p -r1.5 exec.h

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sh4/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-sh4/op_helper.c,v retrieving revision 1.4

op_helper.c +16 -0
diff -u -d -d -p -r1.4 op_helper.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sh4/op_mem.c
===================================================================
RCS file: /sources/qemu/qemu/target-sh4/op_mem.c,v retrieving revision 1.3

op_mem.c +1 -1
diff -u -d -d -p -r1.3 op_mem.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sparc/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/exec.h,v retrieving revision 1.21

exec.h +3 -0
diff -u -d -d -p -r1.21 exec.h

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sparc/helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/helper.c,v retrieving revision 1.27

helper.c +9 -9
diff -u -d -d -p -r1.27 helper.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sparc/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/op_helper.c,v retrieving revision 1.41

op_helper.c +38 -22

60 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Index: target-sparc/op_mem.h
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/op_mem.h,v retrieving revision 1.10

op_mem.h +6 -6
diff -u -d -d -p -r1.10 op_mem.h

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Index: target-sparc/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-sparc/translate.c,v retrieving revision 1.74

translate.c +1 -1
diff -u -d -d -p -r1.74 translate.c

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#6 lore raw
Quoted 44 lines · J. Mayer
Quoted 35 lines · J. Mayer
Quoted 22 lines · Blue Swirl
Quoted 21 lines · J. Mayer
Quoted 19 lines · Blue Swirl
Quoted 4 lines · J. Mayer

The problem:
some CPU architectures, namely PowerPC and maybe others, offers facilities to access the memory or I/O in the reverse endianness, ie little-endian instead of big-endian for PowerPC, or provide instruction

Quoted 8 lines

to make memory accesses in the "reverse-endian". This is implemented as a global flag on some CPU. This case is already handled by the PowerPC emulation but is is far from being optimal. Some other implementations allow the OS to store an "reverse-endian" flag in the TLB or the segment descriptors, thus providing per-page or per-segment endianness control. This is mostly used to ease driver migration from a PC platform to PowerPC without taking any care of the device endianness in the driver code (yes, this is bad...).

Nice, this may be useful for Sparc64. It has a global CPU flag for endianness, individual pages can be marked as reverse endian, and finally there are instructions that access memory in reverse endian. The end result is a XOR of all these reverses. Though I don't know if any of these features are used at all.

Quoted 7 lines
Quoted 4 lines

I realized that I/O accesses for reverse-endian pages were not correct in the softmmu_template.h header. This new version fixes this. It also remove duplicated code in the case of unaligned accesses in a reverse-endian page.

I think 64 bit access case is not handled correctly, but to solve that it would be nice to extend the current IO access system to 64 bits.

I think that if it was previously correct, it should still be, but... I don't know how much having 64 bits I/O accesses is interresting, as I don't know if there are real hw buses that have 64 bits data path...

Quoted 7 lines

Here's another version taking care of your remark about ldl memory accessors.
* I replaced all ldl occurences with ldul
* when TARGET_LONG_BITS == 64, I also added ldsl accessors. And I started using it in the PowerPC memory access micro-ops. Then the patch is really more invasive than the previous ones. This still does not break PowerPC or i386 target, as it seems.

Quoted 5 lines

Here's a new version. The only change is that, for consistency, I did add the big-endian and little-endian accessors that were documented in cpu-all.h as unimplemented. The implementation is quite trivial, having native and reverse-endian accessors available, and changes functionnally nothing to the previous version.

The previous version works fine here, FWIW.

Thiemo

#7 lore raw
In reply to J. Mayer
Quoted 44 lines · J. Mayer
Quoted 35 lines · J. Mayer
Quoted 22 lines · Blue Swirl
Quoted 21 lines · J. Mayer
Quoted 19 lines · Blue Swirl
Quoted 4 lines · J. Mayer

The problem:
some CPU architectures, namely PowerPC and maybe others, offers facilities to access the memory or I/O in the reverse endianness, ie little-endian instead of big-endian for PowerPC, or provide instruction

Quoted 8 lines

to make memory accesses in the "reverse-endian". This is implemented as a global flag on some CPU. This case is already handled by the PowerPC emulation but is is far from being optimal. Some other implementations allow the OS to store an "reverse-endian" flag in the TLB or the segment descriptors, thus providing per-page or per-segment endianness control. This is mostly used to ease driver migration from a PC platform to PowerPC without taking any care of the device endianness in the driver code (yes, this is bad...).

Nice, this may be useful for Sparc64. It has a global CPU flag for endianness, individual pages can be marked as reverse endian, and finally there are instructions that access memory in reverse endian. The end result is a XOR of all these reverses. Though I don't know if any of these features are used at all.

Quoted 7 lines
Quoted 4 lines

I realized that I/O accesses for reverse-endian pages were not correct in the softmmu_template.h header. This new version fixes this. It also remove duplicated code in the case of unaligned accesses in a reverse-endian page.

I think 64 bit access case is not handled correctly, but to solve that it would be nice to extend the current IO access system to 64 bits.

I think that if it was previously correct, it should still be, but... I don't know how much having 64 bits I/O accesses is interresting, as I don't know if there are real hw buses that have 64 bits data path...

Quoted 7 lines

Here's another version taking care of your remark about ldl memory accessors.
* I replaced all ldl occurences with ldul
* when TARGET_LONG_BITS == 64, I also added ldsl accessors. And I started using it in the PowerPC memory access micro-ops. Then the patch is really more invasive than the previous ones. This still does not break PowerPC or i386 target, as it seems.

Quoted 5 lines

Here's a new version. The only change is that, for consistency, I did add the big-endian and little-endian accessors that were documented in cpu-all.h as unimplemented. The implementation is quite trivial, having native and reverse-endian accessors available, and changes functionnally nothing to the previous version.

The patch does not apply anymore. The Sparc part looks OK.

The benefits from the patch can be gained by mapping Sparc64 lduw and ldsw in op_mem.h directly to ldul and ldsl using SPARC_LD_OP and replacing the ldl+bswap etc. for the LE cases with ldlr in op_helper.c. If you prefer, I can do this after you have applied the patch.

author
#8 lore raw
Quoted 51 lines · Blue Swirl
Quoted 44 lines · J. Mayer
Quoted 35 lines · J. Mayer
Quoted 22 lines · Blue Swirl
Quoted 21 lines · J. Mayer
Quoted 19 lines · Blue Swirl
Quoted 4 lines · J. Mayer

The problem:
some CPU architectures, namely PowerPC and maybe others, offers facilities to access the memory or I/O in the reverse endianness, ie little-endian instead of big-endian for PowerPC, or provide instruction

Quoted 8 lines

to make memory accesses in the "reverse-endian". This is implemented as a global flag on some CPU. This case is already handled by the PowerPC emulation but is is far from being optimal. Some other implementations allow the OS to store an "reverse-endian" flag in the TLB or the segment descriptors, thus providing per-page or per-segment endianness control. This is mostly used to ease driver migration from a PC platform to PowerPC without taking any care of the device endianness in the driver code (yes, this is bad...).

Nice, this may be useful for Sparc64. It has a global CPU flag for endianness, individual pages can be marked as reverse endian, and finally there are instructions that access memory in reverse endian. The end result is a XOR of all these reverses. Though I don't know if any of these features are used at all.

Quoted 7 lines
Quoted 4 lines

I realized that I/O accesses for reverse-endian pages were not correct in the softmmu_template.h header. This new version fixes this. It also remove duplicated code in the case of unaligned accesses in a reverse-endian page.

I think 64 bit access case is not handled correctly, but to solve that it would be nice to extend the current IO access system to 64 bits.

I think that if it was previously correct, it should still be, but... I don't know how much having 64 bits I/O accesses is interresting, as I don't know if there are real hw buses that have 64 bits data path...

Quoted 7 lines

Here's another version taking care of your remark about ldl memory accessors.
* I replaced all ldl occurences with ldul
* when TARGET_LONG_BITS == 64, I also added ldsl accessors. And I started using it in the PowerPC memory access micro-ops. Then the patch is really more invasive than the previous ones. This still does not break PowerPC or i386 target, as it seems.

Quoted 5 lines

Here's a new version. The only change is that, for consistency, I did add the big-endian and little-endian accessors that were documented in cpu-all.h as unimplemented. The implementation is quite trivial, having native and reverse-endian accessors available, and changes functionnally nothing to the previous version.

Quoted 7 lines

The patch does not apply anymore. The Sparc part looks OK.

The benefits from the patch can be gained by mapping Sparc64 lduw and ldsw in op_mem.h directly to ldul and ldsl using SPARC_LD_OP and replacing the ldl+bswap etc. for the LE cases with ldlr in op_helper.c. If you prefer, I can do this after you have applied the patch.

Yes, there are conflicts between this patch and the mmu_idx one I just commited. I will regenerate an updated diff in the hours to come, after I finished commiting the PowerPC fixes and improvments I got waiting in stock.
For the Sparc improvments, as I merged the PowerPC improvments in the patch, I think it can be a good idea to include it directly in the patch.
I'm also wondering if it would not be a good idea to define lduq/ldsq even if they in fact do exactly what ldq does now, just to have a fully consistent API.

Signature · 2 lines
J. Mayer <[email protected]>
Never organized
#9 lore raw

J. Mayer wrote:
[snip]

Quoted 14 lines
Quoted 6 lines
Quoted 5 lines

Here's a new version. The only change is that, for consistency, I did add the big-endian and little-endian accessors that were documented in cpu-all.h as unimplemented. The implementation is quite trivial, having native and reverse-endian accessors available, and changes functionnally nothing to the previous version.

Quoted 7 lines

The patch does not apply anymore. The Sparc part looks OK.

The benefits from the patch can be gained by mapping Sparc64 lduw and ldsw in op_mem.h directly to ldul and ldsl using SPARC_LD_OP and replacing the ldl+bswap etc. for the LE cases with ldlr in op_helper.c. If you prefer, I can do this after you have applied the patch.

Quoted 10 lines

Yes, there are conflicts between this patch and the mmu_idx one I just commited. I will regenerate an updated diff in the hours to come, after I finished commiting the PowerPC fixes and improvments I got waiting in stock.
For the Sparc improvments, as I merged the PowerPC improvments in the patch, I think it can be a good idea to include it directly in the patch.
I'm also wondering if it would not be a good idea to define lduq/ldsq even if they in fact do exactly what ldq does now, just to have a fully consistent API.

Some architecture specs mention the possibility of 128 bit integers, so this sounds like a good idea.

Thiemo

author
#10 lore raw
Quoted 27 lines · Thiemo Seufer

J. Mayer wrote:
[snip]

Quoted 14 lines
Quoted 6 lines
Quoted 5 lines

Here's a new version. The only change is that, for consistency, I did add the big-endian and little-endian accessors that were documented in cpu-all.h as unimplemented. The implementation is quite trivial, having native and reverse-endian accessors available, and changes functionnally nothing to the previous version.

Quoted 7 lines

The patch does not apply anymore. The Sparc part looks OK.

The benefits from the patch can be gained by mapping Sparc64 lduw and ldsw in op_mem.h directly to ldul and ldsl using SPARC_LD_OP and replacing the ldl+bswap etc. for the LE cases with ldlr in op_helper.c. If you prefer, I can do this after you have applied the patch.

Quoted 10 lines

Yes, there are conflicts between this patch and the mmu_idx one I just commited. I will regenerate an updated diff in the hours to come, after I finished commiting the PowerPC fixes and improvments I got waiting in stock.
For the Sparc improvments, as I merged the PowerPC improvments in the patch, I think it can be a good idea to include it directly in the patch.
I'm also wondering if it would not be a good idea to define lduq/ldsq even if they in fact do exactly what ldq does now, just to have a fully consistent API.

Quoted 2 lines

Some architecture specs mention the possibility of 128 bit integers, so this sounds like a good idea.

OK, then I'll add this.
And I guess we can avoid the #if (TARGET_LONG_BITS == 64) for ldsl / ldul changing the return type to target_ulong for those accessors.

Signature · 2 lines
J. Mayer <[email protected]>
Never organized