mem-internal.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  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. #ifndef TRACE__MEM_INTERNAL_H
  10. #define TRACE__MEM_INTERNAL_H
  11. #define TRACE_MEM_SZ_SHIFT_MASK 0xf /* size shift mask */
  12. #define TRACE_MEM_SE (1ULL << 4) /* sign extended (y/n) */
  13. #define TRACE_MEM_BE (1ULL << 5) /* big endian (y/n) */
  14. #define TRACE_MEM_ST (1ULL << 6) /* store (y/n) */
  15. #define TRACE_MEM_MMU_SHIFT 8 /* mmu idx */
  16. static inline uint16_t trace_mem_build_info(
  17. int size_shift, bool sign_extend, MemOp endianness,
  18. bool store, unsigned int mmu_idx)
  19. {
  20. uint16_t res;
  21. res = size_shift & TRACE_MEM_SZ_SHIFT_MASK;
  22. if (sign_extend) {
  23. res |= TRACE_MEM_SE;
  24. }
  25. if (endianness == MO_BE) {
  26. res |= TRACE_MEM_BE;
  27. }
  28. if (store) {
  29. res |= TRACE_MEM_ST;
  30. }
  31. #ifdef CONFIG_SOFTMMU
  32. res |= mmu_idx << TRACE_MEM_MMU_SHIFT;
  33. #endif
  34. return res;
  35. }
  36. static inline uint16_t trace_mem_get_info(MemOp op,
  37. unsigned int mmu_idx,
  38. bool store)
  39. {
  40. return trace_mem_build_info(op & MO_SIZE, !!(op & MO_SIGN),
  41. op & MO_BSWAP, store,
  42. mmu_idx);
  43. }
  44. /* Used by the atomic helpers */
  45. static inline
  46. uint16_t trace_mem_build_info_no_se_be(int size_shift, bool store,
  47. TCGMemOpIdx oi)
  48. {
  49. return trace_mem_build_info(size_shift, false, MO_BE, store,
  50. get_mmuidx(oi));
  51. }
  52. static inline
  53. uint16_t trace_mem_build_info_no_se_le(int size_shift, bool store,
  54. TCGMemOpIdx oi)
  55. {
  56. return trace_mem_build_info(size_shift, false, MO_LE, store,
  57. get_mmuidx(oi));
  58. }
  59. #endif /* TRACE__MEM_INTERNAL_H */