simulate-insn.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. #ifndef _RISCV_KERNEL_PROBES_SIMULATE_INSN_H
  3. #define _RISCV_KERNEL_PROBES_SIMULATE_INSN_H
  4. #define __RISCV_INSN_FUNCS(name, mask, val) \
  5. static __always_inline bool riscv_insn_is_##name(probe_opcode_t code) \
  6. { \
  7. BUILD_BUG_ON(~(mask) & (val)); \
  8. return (code & (mask)) == (val); \
  9. } \
  10. bool simulate_##name(u32 opcode, unsigned long addr, \
  11. struct pt_regs *regs)
  12. #define RISCV_INSN_REJECTED(name, code) \
  13. do { \
  14. if (riscv_insn_is_##name(code)) { \
  15. return INSN_REJECTED; \
  16. } \
  17. } while (0)
  18. __RISCV_INSN_FUNCS(system, 0x7f, 0x73);
  19. __RISCV_INSN_FUNCS(fence, 0x7f, 0x0f);
  20. #define RISCV_INSN_SET_SIMULATE(name, code) \
  21. do { \
  22. if (riscv_insn_is_##name(code)) { \
  23. api->handler = simulate_##name; \
  24. return INSN_GOOD_NO_SLOT; \
  25. } \
  26. } while (0)
  27. __RISCV_INSN_FUNCS(c_j, 0xe003, 0xa001);
  28. __RISCV_INSN_FUNCS(c_jr, 0xf07f, 0x8002);
  29. __RISCV_INSN_FUNCS(c_jal, 0xe003, 0x2001);
  30. __RISCV_INSN_FUNCS(c_jalr, 0xf07f, 0x9002);
  31. __RISCV_INSN_FUNCS(c_beqz, 0xe003, 0xc001);
  32. __RISCV_INSN_FUNCS(c_bnez, 0xe003, 0xe001);
  33. __RISCV_INSN_FUNCS(c_ebreak, 0xffff, 0x9002);
  34. __RISCV_INSN_FUNCS(auipc, 0x7f, 0x17);
  35. __RISCV_INSN_FUNCS(branch, 0x7f, 0x63);
  36. __RISCV_INSN_FUNCS(jal, 0x7f, 0x6f);
  37. __RISCV_INSN_FUNCS(jalr, 0x707f, 0x67);
  38. #endif /* _RISCV_KERNEL_PROBES_SIMULATE_INSN_H */