instructions.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/compiler.h>
  3. #include <sys/types.h>
  4. #include <regex.h>
  5. struct arm_annotate {
  6. regex_t call_insn,
  7. jump_insn;
  8. };
  9. static struct ins_ops *arm__associate_instruction_ops(struct arch *arch, const char *name)
  10. {
  11. struct arm_annotate *arm = arch->priv;
  12. struct ins_ops *ops;
  13. regmatch_t match[2];
  14. if (!regexec(&arm->call_insn, name, 2, match, 0))
  15. ops = &call_ops;
  16. else if (!regexec(&arm->jump_insn, name, 2, match, 0))
  17. ops = &jump_ops;
  18. else
  19. return NULL;
  20. arch__associate_ins_ops(arch, name, ops);
  21. return ops;
  22. }
  23. static int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused)
  24. {
  25. struct arm_annotate *arm;
  26. int err;
  27. if (arch->initialized)
  28. return 0;
  29. arm = zalloc(sizeof(*arm));
  30. if (!arm)
  31. return -1;
  32. #define ARM_CONDS "(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl|vc|vs)"
  33. err = regcomp(&arm->call_insn, "^blx?" ARM_CONDS "?$", REG_EXTENDED);
  34. if (err)
  35. goto out_free_arm;
  36. err = regcomp(&arm->jump_insn, "^bx?" ARM_CONDS "?$", REG_EXTENDED);
  37. if (err)
  38. goto out_free_call;
  39. #undef ARM_CONDS
  40. arch->initialized = true;
  41. arch->priv = arm;
  42. arch->associate_instruction_ops = arm__associate_instruction_ops;
  43. arch->objdump.comment_char = ';';
  44. arch->objdump.skip_functions_char = '+';
  45. return 0;
  46. out_free_call:
  47. regfree(&arm->call_insn);
  48. out_free_arm:
  49. free(arm);
  50. return -1;
  51. }