sstep.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2004 Paul Mackerras <[email protected]>, IBM
  4. */
  5. #include <asm/inst.h>
  6. struct pt_regs;
  7. /*
  8. * We don't allow single-stepping an mtmsrd that would clear
  9. * MSR_RI, since that would make the exception unrecoverable.
  10. * Since we need to single-step to proceed from a breakpoint,
  11. * we don't allow putting a breakpoint on an mtmsrd instruction.
  12. * Similarly we don't allow breakpoints on rfid instructions.
  13. * These macros tell us if an instruction is a mtmsrd or rfid.
  14. * Note that these return true for both mtmsr/rfi (32-bit)
  15. * and mtmsrd/rfid (64-bit).
  16. */
  17. #define IS_MTMSRD(instr) ((ppc_inst_val(instr) & 0xfc0007be) == 0x7c000124)
  18. #define IS_RFID(instr) ((ppc_inst_val(instr) & 0xfc0007be) == 0x4c000024)
  19. enum instruction_type {
  20. COMPUTE, /* arith/logical/CR op, etc. */
  21. LOAD, /* load and store types need to be contiguous */
  22. LOAD_MULTI,
  23. LOAD_FP,
  24. LOAD_VMX,
  25. LOAD_VSX,
  26. STORE,
  27. STORE_MULTI,
  28. STORE_FP,
  29. STORE_VMX,
  30. STORE_VSX,
  31. LARX,
  32. STCX,
  33. BRANCH,
  34. MFSPR,
  35. MTSPR,
  36. CACHEOP,
  37. BARRIER,
  38. SYSCALL,
  39. SYSCALL_VECTORED_0,
  40. MFMSR,
  41. MTMSR,
  42. RFI,
  43. INTERRUPT,
  44. UNKNOWN
  45. };
  46. #define INSTR_TYPE_MASK 0x1f
  47. #define OP_IS_LOAD(type) ((LOAD <= (type) && (type) <= LOAD_VSX) || (type) == LARX)
  48. #define OP_IS_STORE(type) ((STORE <= (type) && (type) <= STORE_VSX) || (type) == STCX)
  49. #define OP_IS_LOAD_STORE(type) (LOAD <= (type) && (type) <= STCX)
  50. /* Compute flags, ORed in with type */
  51. #define SETREG 0x20
  52. #define SETCC 0x40
  53. #define SETXER 0x80
  54. /* Branch flags, ORed in with type */
  55. #define SETLK 0x20
  56. #define BRTAKEN 0x40
  57. #define DECCTR 0x80
  58. /* Load/store flags, ORed in with type */
  59. #define SIGNEXT 0x20
  60. #define UPDATE 0x40 /* matches bit in opcode 31 instructions */
  61. #define BYTEREV 0x80
  62. #define FPCONV 0x100
  63. /* Barrier type field, ORed in with type */
  64. #define BARRIER_MASK 0xe0
  65. #define BARRIER_SYNC 0x00
  66. #define BARRIER_ISYNC 0x20
  67. #define BARRIER_EIEIO 0x40
  68. #define BARRIER_LWSYNC 0x60
  69. #define BARRIER_PTESYNC 0x80
  70. /* Cacheop values, ORed in with type */
  71. #define CACHEOP_MASK 0x700
  72. #define DCBST 0
  73. #define DCBF 0x100
  74. #define DCBTST 0x200
  75. #define DCBT 0x300
  76. #define ICBI 0x400
  77. #define DCBZ 0x500
  78. /* VSX flags values */
  79. #define VSX_FPCONV 1 /* do floating point SP/DP conversion */
  80. #define VSX_SPLAT 2 /* store loaded value into all elements */
  81. #define VSX_LDLEFT 4 /* load VSX register from left */
  82. #define VSX_CHECK_VEC 8 /* check MSR_VEC not MSR_VSX for reg >= 32 */
  83. /* Prefixed flag, ORed in with type */
  84. #define PREFIXED 0x800
  85. /* Size field in type word */
  86. #define SIZE(n) ((n) << 12)
  87. #define GETSIZE(w) ((w) >> 12)
  88. #define GETTYPE(t) ((t) & INSTR_TYPE_MASK)
  89. #define GETLENGTH(t) (((t) & PREFIXED) ? 8 : 4)
  90. #define MKOP(t, f, s) ((t) | (f) | SIZE(s))
  91. /* Prefix instruction operands */
  92. #define GET_PREFIX_RA(i) (((i) >> 16) & 0x1f)
  93. #define GET_PREFIX_R(i) ((i) & (1ul << 20))
  94. extern s32 patch__exec_instr;
  95. struct instruction_op {
  96. int type;
  97. int reg;
  98. unsigned long val;
  99. /* For LOAD/STORE/LARX/STCX */
  100. unsigned long ea;
  101. int update_reg;
  102. /* For MFSPR */
  103. int spr;
  104. u32 ccval;
  105. u32 xerval;
  106. u8 element_size; /* for VSX/VMX loads/stores */
  107. u8 vsx_flags;
  108. };
  109. union vsx_reg {
  110. u8 b[16];
  111. u16 h[8];
  112. u32 w[4];
  113. unsigned long d[2];
  114. float fp[4];
  115. double dp[2];
  116. __vector128 v;
  117. };
  118. /*
  119. * Decode an instruction, and return information about it in *op
  120. * without changing *regs.
  121. *
  122. * Return value is 1 if the instruction can be emulated just by
  123. * updating *regs with the information in *op, -1 if we need the
  124. * GPRs but *regs doesn't contain the full register set, or 0
  125. * otherwise.
  126. */
  127. extern int analyse_instr(struct instruction_op *op, const struct pt_regs *regs,
  128. ppc_inst_t instr);
  129. /*
  130. * Emulate an instruction that can be executed just by updating
  131. * fields in *regs.
  132. */
  133. void emulate_update_regs(struct pt_regs *reg, struct instruction_op *op);
  134. /*
  135. * Emulate instructions that cause a transfer of control,
  136. * arithmetic/logical instructions, loads and stores,
  137. * cache operations and barriers.
  138. *
  139. * Returns 1 if the instruction was emulated successfully,
  140. * 0 if it could not be emulated, or -1 for an instruction that
  141. * should not be emulated (rfid, mtmsrd clearing MSR_RI, etc.).
  142. */
  143. int emulate_step(struct pt_regs *regs, ppc_inst_t instr);
  144. /*
  145. * Emulate a load or store instruction by reading/writing the
  146. * memory of the current process. FP/VMX/VSX registers are assumed
  147. * to hold live values if the appropriate enable bit in regs->msr is
  148. * set; otherwise this will use the saved values in the thread struct
  149. * for user-mode accesses.
  150. */
  151. extern int emulate_loadstore(struct pt_regs *regs, struct instruction_op *op);
  152. extern void emulate_vsx_load(struct instruction_op *op, union vsx_reg *reg,
  153. const void *mem, bool cross_endian);
  154. extern void emulate_vsx_store(struct instruction_op *op,
  155. const union vsx_reg *reg, void *mem,
  156. bool cross_endian);
  157. extern int emulate_dcbz(unsigned long ea, struct pt_regs *regs);