decode.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <objtool/check.h>
  5. #include <objtool/elf.h>
  6. #include <objtool/arch.h>
  7. #include <objtool/warn.h>
  8. #include <objtool/builtin.h>
  9. #include <objtool/endianness.h>
  10. int arch_ftrace_match(char *name)
  11. {
  12. return !strcmp(name, "_mcount");
  13. }
  14. unsigned long arch_dest_reloc_offset(int addend)
  15. {
  16. return addend;
  17. }
  18. bool arch_callee_saved_reg(unsigned char reg)
  19. {
  20. return false;
  21. }
  22. int arch_decode_hint_reg(u8 sp_reg, int *base)
  23. {
  24. exit(-1);
  25. }
  26. const char *arch_nop_insn(int len)
  27. {
  28. exit(-1);
  29. }
  30. const char *arch_ret_insn(int len)
  31. {
  32. exit(-1);
  33. }
  34. int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
  35. unsigned long offset, unsigned int maxlen,
  36. struct instruction *insn)
  37. {
  38. unsigned int opcode;
  39. enum insn_type typ;
  40. unsigned long imm;
  41. u32 ins;
  42. ins = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset));
  43. opcode = ins >> 26;
  44. typ = INSN_OTHER;
  45. imm = 0;
  46. switch (opcode) {
  47. case 18: /* b[l][a] */
  48. if ((ins & 3) == 1) /* bl */
  49. typ = INSN_CALL;
  50. imm = ins & 0x3fffffc;
  51. if (imm & 0x2000000)
  52. imm -= 0x4000000;
  53. break;
  54. }
  55. if (opcode == 1)
  56. insn->len = 8;
  57. else
  58. insn->len = 4;
  59. insn->type = typ;
  60. insn->immediate = imm;
  61. return 0;
  62. }
  63. unsigned long arch_jump_destination(struct instruction *insn)
  64. {
  65. return insn->offset + insn->immediate;
  66. }
  67. bool arch_pc_relative_reloc(struct reloc *reloc)
  68. {
  69. /*
  70. * The powerpc build only allows certain relocation types, see
  71. * relocs_check.sh, and none of those accepted are PC relative.
  72. */
  73. return false;
  74. }
  75. void arch_initial_func_cfi_state(struct cfi_init_state *state)
  76. {
  77. int i;
  78. for (i = 0; i < CFI_NUM_REGS; i++) {
  79. state->regs[i].base = CFI_UNDEFINED;
  80. state->regs[i].offset = 0;
  81. }
  82. /* initial CFA (call frame address) */
  83. state->cfa.base = CFI_SP;
  84. state->cfa.offset = 0;
  85. /* initial LR (return address) */
  86. state->regs[CFI_RA].base = CFI_CFA;
  87. state->regs[CFI_RA].offset = 0;
  88. }