2 * Constants for memory operations
5 * Richard Henderson <rth@twiddle.net>
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
15 #include "qemu/host-utils.h"
26 MO_SIZE
= 0x07, /* Mask for the above. */
28 MO_SIGN
= 0x08, /* Sign-extended, otherwise zero-extended. */
30 MO_BSWAP
= 0x10, /* Host reverse endian. */
47 * MO_UNALN accesses are never checked for alignment.
48 * MO_ALIGN accesses will result in a call to the CPU's
49 * do_unaligned_access hook if the guest address is not aligned.
50 * The default depends on whether the target CPU defines
51 * TARGET_ALIGNED_ONLY.
53 * Some architectures (e.g. ARMv8) need the address which is aligned
54 * to a size more than the size of the memory access.
55 * Some architectures (e.g. SPARCv9) need an address which is aligned,
56 * but less strictly than the natural alignment.
58 * MO_ALIGN supposes the alignment size is the size of a memory access.
60 * There are three options:
61 * - unaligned access permitted (MO_UNALN).
62 * - an alignment to the size of an access (MO_ALIGN);
63 * - an alignment to a specified size, which may be more or less than
64 * the access size (MO_ALIGN_x where 'x' is a size in bytes);
67 MO_AMASK
= 0x7 << MO_ASHIFT
,
69 #ifdef TARGET_ALIGNED_ONLY
77 MO_ALIGN_2
= 1 << MO_ASHIFT
,
78 MO_ALIGN_4
= 2 << MO_ASHIFT
,
79 MO_ALIGN_8
= 3 << MO_ASHIFT
,
80 MO_ALIGN_16
= 4 << MO_ASHIFT
,
81 MO_ALIGN_32
= 5 << MO_ASHIFT
,
82 MO_ALIGN_64
= 6 << MO_ASHIFT
,
84 /* Combinations of the above, for ease of use. */
90 MO_SB
= MO_SIGN
| MO_8
,
91 MO_SW
= MO_SIGN
| MO_16
,
92 MO_SL
= MO_SIGN
| MO_32
,
93 MO_SQ
= MO_SIGN
| MO_64
,
94 MO_SO
= MO_SIGN
| MO_128
,
96 MO_LEUW
= MO_LE
| MO_UW
,
97 MO_LEUL
= MO_LE
| MO_UL
,
98 MO_LEUQ
= MO_LE
| MO_UQ
,
99 MO_LESW
= MO_LE
| MO_SW
,
100 MO_LESL
= MO_LE
| MO_SL
,
101 MO_LESQ
= MO_LE
| MO_SQ
,
103 MO_BEUW
= MO_BE
| MO_UW
,
104 MO_BEUL
= MO_BE
| MO_UL
,
105 MO_BEUQ
= MO_BE
| MO_UQ
,
106 MO_BESW
= MO_BE
| MO_SW
,
107 MO_BESL
= MO_BE
| MO_SL
,
108 MO_BESQ
= MO_BE
| MO_SQ
,
111 MO_TEUW
= MO_TE
| MO_UW
,
112 MO_TEUL
= MO_TE
| MO_UL
,
113 MO_TEUQ
= MO_TE
| MO_UQ
,
114 MO_TEUO
= MO_TE
| MO_UO
,
115 MO_TESW
= MO_TE
| MO_SW
,
116 MO_TESL
= MO_TE
| MO_SL
,
117 MO_TESQ
= MO_TE
| MO_SQ
,
120 MO_SSIZE
= MO_SIZE
| MO_SIGN
,
123 /* MemOp to size in bytes. */
124 static inline unsigned memop_size(MemOp op
)
126 return 1 << (op
& MO_SIZE
);
129 /* Size in bytes to MemOp. */
130 static inline MemOp
size_memop(unsigned size
)
132 #ifdef CONFIG_DEBUG_TCG
133 /* Power of 2 up to 8. */
134 assert((size
& (size
- 1)) == 0 && size
>= 1 && size
<= 8);
139 /* Big endianness from MemOp. */
140 static inline bool memop_big_endian(MemOp op
)
142 return (op
& MO_BSWAP
) == MO_BE
;