instructions.c 1.6 KB

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