instructions.c 1.4 KB

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