instructions.c 1.2 KB

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