2019-08-23 21:10:58 +03:00
|
|
|
/*
|
|
|
|
* Constants for memory operations
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Richard Henderson <rth@twiddle.net>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MEMOP_H
|
|
|
|
#define MEMOP_H
|
|
|
|
|
2019-08-23 21:36:48 +03:00
|
|
|
#include "qemu/host-utils.h"
|
|
|
|
|
2019-08-23 21:10:58 +03:00
|
|
|
typedef enum MemOp {
|
|
|
|
MO_8 = 0,
|
|
|
|
MO_16 = 1,
|
|
|
|
MO_32 = 2,
|
|
|
|
MO_64 = 3,
|
2021-07-26 23:32:17 +03:00
|
|
|
MO_128 = 4,
|
|
|
|
MO_256 = 5,
|
|
|
|
MO_512 = 6,
|
|
|
|
MO_1024 = 7,
|
|
|
|
MO_SIZE = 0x07, /* Mask for the above. */
|
2019-08-23 21:10:58 +03:00
|
|
|
|
2021-07-26 23:32:17 +03:00
|
|
|
MO_SIGN = 0x08, /* Sign-extended, otherwise zero-extended. */
|
2019-08-23 21:10:58 +03:00
|
|
|
|
2021-07-26 23:32:17 +03:00
|
|
|
MO_BSWAP = 0x10, /* Host reverse endian. */
|
2022-03-23 18:57:17 +03:00
|
|
|
#if HOST_BIG_ENDIAN
|
2019-08-23 21:10:58 +03:00
|
|
|
MO_LE = MO_BSWAP,
|
|
|
|
MO_BE = 0,
|
|
|
|
#else
|
|
|
|
MO_LE = 0,
|
|
|
|
MO_BE = MO_BSWAP,
|
|
|
|
#endif
|
2023-06-13 17:29:11 +03:00
|
|
|
#ifdef COMPILING_PER_TARGET
|
2022-03-23 18:57:18 +03:00
|
|
|
#if TARGET_BIG_ENDIAN
|
2019-08-23 21:10:58 +03:00
|
|
|
MO_TE = MO_BE,
|
|
|
|
#else
|
|
|
|
MO_TE = MO_LE,
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MO_UNALN accesses are never checked for alignment.
|
|
|
|
* MO_ALIGN accesses will result in a call to the CPU's
|
|
|
|
* do_unaligned_access hook if the guest address is not aligned.
|
|
|
|
*
|
|
|
|
* Some architectures (e.g. ARMv8) need the address which is aligned
|
|
|
|
* to a size more than the size of the memory access.
|
|
|
|
* Some architectures (e.g. SPARCv9) need an address which is aligned,
|
|
|
|
* but less strictly than the natural alignment.
|
|
|
|
*
|
|
|
|
* MO_ALIGN supposes the alignment size is the size of a memory access.
|
|
|
|
*
|
|
|
|
* There are three options:
|
|
|
|
* - unaligned access permitted (MO_UNALN).
|
|
|
|
* - an alignment to the size of an access (MO_ALIGN);
|
|
|
|
* - an alignment to a specified size, which may be more or less than
|
|
|
|
* the access size (MO_ALIGN_x where 'x' is a size in bytes);
|
|
|
|
*/
|
2021-07-26 23:32:17 +03:00
|
|
|
MO_ASHIFT = 5,
|
|
|
|
MO_AMASK = 0x7 << MO_ASHIFT,
|
2023-05-02 18:25:02 +03:00
|
|
|
MO_UNALN = 0,
|
2019-08-23 21:10:58 +03:00
|
|
|
MO_ALIGN_2 = 1 << MO_ASHIFT,
|
|
|
|
MO_ALIGN_4 = 2 << MO_ASHIFT,
|
|
|
|
MO_ALIGN_8 = 3 << MO_ASHIFT,
|
|
|
|
MO_ALIGN_16 = 4 << MO_ASHIFT,
|
|
|
|
MO_ALIGN_32 = 5 << MO_ASHIFT,
|
|
|
|
MO_ALIGN_64 = 6 << MO_ASHIFT,
|
2023-05-02 18:25:02 +03:00
|
|
|
MO_ALIGN = MO_AMASK,
|
2019-08-23 21:10:58 +03:00
|
|
|
|
2022-10-21 14:24:40 +03:00
|
|
|
/*
|
|
|
|
* MO_ATOM_* describes the atomicity requirements of the operation:
|
|
|
|
* MO_ATOM_IFALIGN: the operation must be single-copy atomic if it
|
|
|
|
* is aligned; if unaligned there is no atomicity.
|
|
|
|
* MO_ATOM_IFALIGN_PAIR: the entire operation may be considered to
|
|
|
|
* be a pair of half-sized operations which are packed together
|
|
|
|
* for convenience, with single-copy atomicity on each half if
|
|
|
|
* the half is aligned.
|
|
|
|
* This is the atomicity e.g. of Arm pre-FEAT_LSE2 LDP.
|
|
|
|
* MO_ATOM_WITHIN16: the operation is single-copy atomic, even if it
|
|
|
|
* is unaligned, so long as it does not cross a 16-byte boundary;
|
|
|
|
* if it crosses a 16-byte boundary there is no atomicity.
|
|
|
|
* This is the atomicity e.g. of Arm FEAT_LSE2 LDR.
|
|
|
|
* MO_ATOM_WITHIN16_PAIR: the entire operation is single-copy atomic,
|
|
|
|
* if it happens to be within a 16-byte boundary, otherwise it
|
|
|
|
* devolves to a pair of half-sized MO_ATOM_WITHIN16 operations.
|
|
|
|
* Depending on alignment, one or both will be single-copy atomic.
|
|
|
|
* This is the atomicity e.g. of Arm FEAT_LSE2 LDP.
|
|
|
|
* MO_ATOM_SUBALIGN: the operation is single-copy atomic by parts
|
|
|
|
* by the alignment. E.g. if the address is 0 mod 4, then each
|
|
|
|
* 4-byte subobject is single-copy atomic.
|
|
|
|
* This is the atomicity e.g. of IBM Power.
|
|
|
|
* MO_ATOM_NONE: the operation has no atomicity requirements.
|
|
|
|
*
|
|
|
|
* Note the default (i.e. 0) value is single-copy atomic to the
|
|
|
|
* size of the operation, if aligned. This retains the behaviour
|
|
|
|
* from before this field was introduced.
|
|
|
|
*/
|
|
|
|
MO_ATOM_SHIFT = 8,
|
|
|
|
MO_ATOM_IFALIGN = 0 << MO_ATOM_SHIFT,
|
|
|
|
MO_ATOM_IFALIGN_PAIR = 1 << MO_ATOM_SHIFT,
|
|
|
|
MO_ATOM_WITHIN16 = 2 << MO_ATOM_SHIFT,
|
|
|
|
MO_ATOM_WITHIN16_PAIR = 3 << MO_ATOM_SHIFT,
|
|
|
|
MO_ATOM_SUBALIGN = 4 << MO_ATOM_SHIFT,
|
|
|
|
MO_ATOM_NONE = 5 << MO_ATOM_SHIFT,
|
|
|
|
MO_ATOM_MASK = 7 << MO_ATOM_SHIFT,
|
|
|
|
|
2019-08-23 21:10:58 +03:00
|
|
|
/* Combinations of the above, for ease of use. */
|
|
|
|
MO_UB = MO_8,
|
|
|
|
MO_UW = MO_16,
|
|
|
|
MO_UL = MO_32,
|
2022-01-07 00:00:51 +03:00
|
|
|
MO_UQ = MO_64,
|
2022-01-07 00:00:52 +03:00
|
|
|
MO_UO = MO_128,
|
2019-08-23 21:10:58 +03:00
|
|
|
MO_SB = MO_SIGN | MO_8,
|
|
|
|
MO_SW = MO_SIGN | MO_16,
|
|
|
|
MO_SL = MO_SIGN | MO_32,
|
2022-01-07 00:00:52 +03:00
|
|
|
MO_SQ = MO_SIGN | MO_64,
|
|
|
|
MO_SO = MO_SIGN | MO_128,
|
2019-08-23 21:10:58 +03:00
|
|
|
|
|
|
|
MO_LEUW = MO_LE | MO_UW,
|
|
|
|
MO_LEUL = MO_LE | MO_UL,
|
2022-01-07 00:00:51 +03:00
|
|
|
MO_LEUQ = MO_LE | MO_UQ,
|
2019-08-23 21:10:58 +03:00
|
|
|
MO_LESW = MO_LE | MO_SW,
|
|
|
|
MO_LESL = MO_LE | MO_SL,
|
2022-01-07 00:00:52 +03:00
|
|
|
MO_LESQ = MO_LE | MO_SQ,
|
2019-08-23 21:10:58 +03:00
|
|
|
|
|
|
|
MO_BEUW = MO_BE | MO_UW,
|
|
|
|
MO_BEUL = MO_BE | MO_UL,
|
2022-01-07 00:00:51 +03:00
|
|
|
MO_BEUQ = MO_BE | MO_UQ,
|
2019-08-23 21:10:58 +03:00
|
|
|
MO_BESW = MO_BE | MO_SW,
|
|
|
|
MO_BESL = MO_BE | MO_SL,
|
2022-01-07 00:00:52 +03:00
|
|
|
MO_BESQ = MO_BE | MO_SQ,
|
2019-08-23 21:10:58 +03:00
|
|
|
|
2023-06-13 17:29:11 +03:00
|
|
|
#ifdef COMPILING_PER_TARGET
|
2019-08-23 21:10:58 +03:00
|
|
|
MO_TEUW = MO_TE | MO_UW,
|
|
|
|
MO_TEUL = MO_TE | MO_UL,
|
2022-01-07 00:00:51 +03:00
|
|
|
MO_TEUQ = MO_TE | MO_UQ,
|
2022-01-07 00:00:52 +03:00
|
|
|
MO_TEUO = MO_TE | MO_UO,
|
2019-08-23 21:10:58 +03:00
|
|
|
MO_TESW = MO_TE | MO_SW,
|
|
|
|
MO_TESL = MO_TE | MO_SL,
|
2022-01-07 00:00:52 +03:00
|
|
|
MO_TESQ = MO_TE | MO_SQ,
|
2019-08-23 21:10:58 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
MO_SSIZE = MO_SIZE | MO_SIGN,
|
|
|
|
} MemOp;
|
|
|
|
|
2019-08-23 21:36:48 +03:00
|
|
|
/* MemOp to size in bytes. */
|
|
|
|
static inline unsigned memop_size(MemOp op)
|
|
|
|
{
|
|
|
|
return 1 << (op & MO_SIZE);
|
|
|
|
}
|
|
|
|
|
2019-08-23 21:29:05 +03:00
|
|
|
/* Size in bytes to MemOp. */
|
2019-08-23 21:36:48 +03:00
|
|
|
static inline MemOp size_memop(unsigned size)
|
2019-08-23 21:29:05 +03:00
|
|
|
{
|
2019-08-23 21:36:48 +03:00
|
|
|
#ifdef CONFIG_DEBUG_TCG
|
|
|
|
/* Power of 2 up to 8. */
|
|
|
|
assert((size & (size - 1)) == 0 && size >= 1 && size <= 8);
|
|
|
|
#endif
|
2024-06-19 01:45:28 +03:00
|
|
|
return (MemOp)ctz32(size);
|
2019-08-23 21:29:05 +03:00
|
|
|
}
|
|
|
|
|
2019-08-23 21:36:53 +03:00
|
|
|
/* Big endianness from MemOp. */
|
|
|
|
static inline bool memop_big_endian(MemOp op)
|
|
|
|
{
|
|
|
|
return (op & MO_BSWAP) == MO_BE;
|
|
|
|
}
|
|
|
|
|
2019-08-23 21:10:58 +03:00
|
|
|
#endif
|