1
0

debug_print.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Definition for kernel virtual machines on s390x
  4. *
  5. * Copyright IBM Corp. 2024
  6. *
  7. * Authors:
  8. * Christoph Schlameuss <schlameuss@linux.ibm.com>
  9. */
  10. #ifndef SELFTEST_KVM_DEBUG_PRINT_H
  11. #define SELFTEST_KVM_DEBUG_PRINT_H
  12. #include "asm/ptrace.h"
  13. #include "kvm_util.h"
  14. #include "sie.h"
  15. static inline void print_hex_bytes(const char *name, u64 addr, size_t len)
  16. {
  17. u64 pos;
  18. pr_debug("%s (%p)\n", name, (void *)addr);
  19. pr_debug(" 0/0x00---------|");
  20. if (len > 8)
  21. pr_debug(" 8/0x08---------|");
  22. if (len > 16)
  23. pr_debug(" 16/0x10--------|");
  24. if (len > 24)
  25. pr_debug(" 24/0x18--------|");
  26. for (pos = 0; pos < len; pos += 8) {
  27. if ((pos % 32) == 0)
  28. pr_debug("\n %3lu 0x%.3lx ", pos, pos);
  29. pr_debug(" %16lx", *((u64 *)(addr + pos)));
  30. }
  31. pr_debug("\n");
  32. }
  33. static inline void print_hex(const char *name, u64 addr)
  34. {
  35. print_hex_bytes(name, addr, 512);
  36. }
  37. static inline void print_psw(struct kvm_run *run, struct kvm_s390_sie_block *sie_block)
  38. {
  39. pr_debug("flags:0x%x psw:0x%.16llx:0x%.16llx exit:%u %s\n",
  40. run->flags,
  41. run->psw_mask, run->psw_addr,
  42. run->exit_reason, exit_reason_str(run->exit_reason));
  43. pr_debug("sie_block psw:0x%.16llx:0x%.16llx\n",
  44. sie_block->psw_mask, sie_block->psw_addr);
  45. }
  46. static inline void print_run(struct kvm_run *run, struct kvm_s390_sie_block *sie_block)
  47. {
  48. print_hex_bytes("run", (u64)run, 0x150);
  49. print_hex("sie_block", (u64)sie_block);
  50. print_psw(run, sie_block);
  51. }
  52. static inline void print_regs(struct kvm_run *run)
  53. {
  54. struct kvm_sync_regs *sync_regs = &run->s.regs;
  55. print_hex_bytes("GPRS", (u64)sync_regs->gprs, 8 * NUM_GPRS);
  56. print_hex_bytes("ACRS", (u64)sync_regs->acrs, 4 * NUM_ACRS);
  57. print_hex_bytes("CRS", (u64)sync_regs->crs, 8 * NUM_CRS);
  58. }
  59. #endif /* SELFTEST_KVM_DEBUG_PRINT_H */