arch.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_BUG 9
  32. #define INSN_NOP 10
  33. #define INSN_OTHER 11
  34. #define INSN_LAST INSN_OTHER
  35. enum op_dest_type {
  36. OP_DEST_REG,
  37. OP_DEST_REG_INDIRECT,
  38. OP_DEST_MEM,
  39. OP_DEST_PUSH,
  40. OP_DEST_LEAVE,
  41. };
  42. struct op_dest {
  43. enum op_dest_type type;
  44. unsigned char reg;
  45. int offset;
  46. };
  47. enum op_src_type {
  48. OP_SRC_REG,
  49. OP_SRC_REG_INDIRECT,
  50. OP_SRC_CONST,
  51. OP_SRC_POP,
  52. OP_SRC_ADD,
  53. OP_SRC_AND,
  54. };
  55. struct op_src {
  56. enum op_src_type type;
  57. unsigned char reg;
  58. int offset;
  59. };
  60. struct stack_op {
  61. struct op_dest dest;
  62. struct op_src src;
  63. };
  64. void arch_initial_func_cfi_state(struct cfi_state *state);
  65. int arch_decode_instruction(struct elf *elf, struct section *sec,
  66. unsigned long offset, unsigned int maxlen,
  67. unsigned int *len, unsigned char *type,
  68. unsigned long *immediate, struct stack_op *op);
  69. bool arch_callee_saved_reg(unsigned char reg);
  70. #endif /* _ARCH_H */