blob: 3444fbc5968f8b85af172b982d9ba1e3c923efd4 [file] [log] [blame]
Lluís Vilanovadcdaadb2016-06-09 19:31:47 +02001/*
2 * Helper functions for guest memory tracing
3 *
4 * Copyright (C) 2016 Lluís Vilanova <vilanova@ac.upc.edu>
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
9
10#ifndef TRACE__MEM_INTERNAL_H
11#define TRACE__MEM_INTERNAL_H
12
Emilio G. Cota706485d2018-05-22 18:26:50 -040013#define TRACE_MEM_SZ_SHIFT_MASK 0x7 /* size shift mask */
14#define TRACE_MEM_SE (1ULL << 3) /* sign extended (y/n) */
15#define TRACE_MEM_BE (1ULL << 4) /* big endian (y/n) */
16#define TRACE_MEM_ST (1ULL << 5) /* store (y/n) */
Emilio G. Cota3d69b952018-05-22 18:26:49 -040017
18static inline uint8_t trace_mem_build_info(
Tony Nguyen14776ab2019-08-24 04:10:58 +100019 int size_shift, bool sign_extend, MemOp endianness, bool store)
Lluís Vilanovadcdaadb2016-06-09 19:31:47 +020020{
Emilio G. Cota3d69b952018-05-22 18:26:49 -040021 uint8_t res;
Lluís Vilanovadcdaadb2016-06-09 19:31:47 +020022
Emilio G. Cota3d69b952018-05-22 18:26:49 -040023 res = size_shift & TRACE_MEM_SZ_SHIFT_MASK;
24 if (sign_extend) {
25 res |= TRACE_MEM_SE;
Lluís Vilanovadcdaadb2016-06-09 19:31:47 +020026 }
Emilio G. Cota3d69b952018-05-22 18:26:49 -040027 if (endianness == MO_BE) {
28 res |= TRACE_MEM_BE;
29 }
Lluís Vilanovadcdaadb2016-06-09 19:31:47 +020030 if (store) {
Emilio G. Cota3d69b952018-05-22 18:26:49 -040031 res |= TRACE_MEM_ST;
Lluís Vilanovadcdaadb2016-06-09 19:31:47 +020032 }
Lluís Vilanovadcdaadb2016-06-09 19:31:47 +020033 return res;
34}
35
Tony Nguyen14776ab2019-08-24 04:10:58 +100036static inline uint8_t trace_mem_get_info(MemOp op, bool store)
Lluís Vilanovadcdaadb2016-06-09 19:31:47 +020037{
Emilio G. Cota3d69b952018-05-22 18:26:49 -040038 return trace_mem_build_info(op & MO_SIZE, !!(op & MO_SIGN),
39 op & MO_BSWAP, store);
Lluís Vilanovadcdaadb2016-06-09 19:31:47 +020040}
41
Emilio G. Cotaf9b47992018-05-22 18:26:51 -040042static inline
43uint8_t trace_mem_build_info_no_se_be(int size_shift, bool store)
44{
45 return trace_mem_build_info(size_shift, false, MO_BE, store);
46}
47
48static inline
49uint8_t trace_mem_build_info_no_se_le(int size_shift, bool store)
50{
51 return trace_mem_build_info(size_shift, false, MO_LE, store);
52}
53
Markus Armbruster175de522016-06-29 15:29:06 +020054#endif /* TRACE__MEM_INTERNAL_H */