arch.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef _ARCH_H
  18. #define _ARCH_H
  19. #include <stdbool.h>
  20. #include <linux/list.h>
  21. #include "elf.h"
  22. #include "cfi.h"
  23. #define INSN_JUMP_CONDITIONAL 1
  24. #define INSN_JUMP_UNCONDITIONAL 2
  25. #define INSN_JUMP_DYNAMIC 3
  26. #define INSN_CALL 4
  27. #define INSN_CALL_DYNAMIC 5
  28. #define INSN_RETURN 6
  29. #define INSN_CONTEXT_SWITCH 7
  30. #define INSN_STACK 8
  31. #define INSN_NOP 9
  32. #define INSN_OTHER 10
  33. #define INSN_LAST INSN_OTHER
  34. enum op_dest_type {
  35. OP_DEST_REG,
  36. OP_DEST_REG_INDIRECT,
  37. OP_DEST_MEM,
  38. OP_DEST_PUSH,
  39. OP_DEST_LEAVE,
  40. };
  41. struct op_dest {
  42. enum op_dest_type type;
  43. unsigned char reg;
  44. int offset;
  45. };
  46. enum op_src_type {
  47. OP_SRC_REG,
  48. OP_SRC_REG_INDIRECT,
  49. OP_SRC_CONST,
  50. OP_SRC_POP,
  51. OP_SRC_ADD,
  52. OP_SRC_AND,
  53. };
  54. struct op_src {
  55. enum op_src_type type;
  56. unsigned char reg;
  57. int offset;
  58. };
  59. struct stack_op {
  60. struct op_dest dest;
  61. struct op_src src;
  62. };
  63. void arch_initial_func_cfi_state(struct cfi_state *state);
  64. int arch_decode_instruction(struct elf *elf, struct section *sec,
  65. unsigned long offset, unsigned int maxlen,
  66. unsigned int *len, unsigned char *type,
  67. unsigned long *immediate, struct stack_op *op);
  68. bool arch_callee_saved_reg(unsigned char reg);
  69. #endif /* _ARCH_H */