instructions.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. static struct ins_ops *powerpc__associate_instruction_ops(struct arch *arch, const char *name)
  2. {
  3. int i;
  4. struct ins_ops *ops;
  5. /*
  6. * - Interested only if instruction starts with 'b'.
  7. * - Few start with 'b', but aren't branch instructions.
  8. */
  9. if (name[0] != 'b' ||
  10. !strncmp(name, "bcd", 3) ||
  11. !strncmp(name, "brinc", 5) ||
  12. !strncmp(name, "bper", 4))
  13. return NULL;
  14. ops = &jump_ops;
  15. i = strlen(name) - 1;
  16. if (i < 0)
  17. return NULL;
  18. /* ignore optional hints at the end of the instructions */
  19. if (name[i] == '+' || name[i] == '-')
  20. i--;
  21. if (name[i] == 'l' || (name[i] == 'a' && name[i-1] == 'l')) {
  22. /*
  23. * if the instruction ends up with 'l' or 'la', then
  24. * those are considered 'calls' since they update LR.
  25. * ... except for 'bnl' which is branch if not less than
  26. * and the absolute form of the same.
  27. */
  28. if (strcmp(name, "bnl") && strcmp(name, "bnl+") &&
  29. strcmp(name, "bnl-") && strcmp(name, "bnla") &&
  30. strcmp(name, "bnla+") && strcmp(name, "bnla-"))
  31. ops = &call_ops;
  32. }
  33. if (name[i] == 'r' && name[i-1] == 'l')
  34. /*
  35. * instructions ending with 'lr' are considered to be
  36. * return instructions
  37. */
  38. ops = &ret_ops;
  39. arch__associate_ins_ops(arch, name, ops);
  40. return ops;
  41. }
  42. static int powerpc__annotate_init(struct arch *arch)
  43. {
  44. if (!arch->initialized) {
  45. arch->initialized = true;
  46. arch->associate_instruction_ops = powerpc__associate_instruction_ops;
  47. arch->objdump.comment_char = '#';
  48. }
  49. return 0;
  50. }