decode-insn.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <linux/kernel.h>
  3. #include <linux/kprobes.h>
  4. #include <linux/module.h>
  5. #include <linux/kallsyms.h>
  6. #include <asm/sections.h>
  7. #include "decode-insn.h"
  8. #include "simulate-insn.h"
  9. /* Return:
  10. * INSN_REJECTED If instruction is one not allowed to kprobe,
  11. * INSN_GOOD_NO_SLOT If instruction is supported but doesn't use its slot.
  12. */
  13. enum probe_insn __kprobes
  14. riscv_probe_decode_insn(probe_opcode_t *addr, struct arch_probe_insn *api)
  15. {
  16. probe_opcode_t insn = le32_to_cpu(*addr);
  17. /*
  18. * Reject instructions list:
  19. */
  20. RISCV_INSN_REJECTED(system, insn);
  21. RISCV_INSN_REJECTED(fence, insn);
  22. /*
  23. * Simulate instructions list:
  24. * TODO: the REJECTED ones below need to be implemented
  25. */
  26. #ifdef CONFIG_RISCV_ISA_C
  27. RISCV_INSN_REJECTED(c_j, insn);
  28. RISCV_INSN_REJECTED(c_jr, insn);
  29. RISCV_INSN_REJECTED(c_jal, insn);
  30. RISCV_INSN_REJECTED(c_jalr, insn);
  31. RISCV_INSN_REJECTED(c_beqz, insn);
  32. RISCV_INSN_REJECTED(c_bnez, insn);
  33. RISCV_INSN_REJECTED(c_ebreak, insn);
  34. #endif
  35. RISCV_INSN_REJECTED(auipc, insn);
  36. RISCV_INSN_REJECTED(branch, insn);
  37. RISCV_INSN_SET_SIMULATE(jal, insn);
  38. RISCV_INSN_SET_SIMULATE(jalr, insn);
  39. return INSN_GOOD;
  40. }