sstep.h 4.6 KB

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