opcodes.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * arch/arm/include/asm/opcodes.h
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef __ASM_ARM_OPCODES_H
  9. #define __ASM_ARM_OPCODES_H
  10. #ifndef __ASSEMBLY__
  11. extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr);
  12. #endif
  13. #define ARM_OPCODE_CONDTEST_FAIL 0
  14. #define ARM_OPCODE_CONDTEST_PASS 1
  15. #define ARM_OPCODE_CONDTEST_UNCOND 2
  16. /*
  17. * Opcode byteswap helpers
  18. *
  19. * These macros help with converting instructions between a canonical integer
  20. * format and in-memory representation, in an endianness-agnostic manner.
  21. *
  22. * __mem_to_opcode_*() convert from in-memory representation to canonical form.
  23. * __opcode_to_mem_*() convert from canonical form to in-memory representation.
  24. *
  25. *
  26. * Canonical instruction representation:
  27. *
  28. * ARM: 0xKKLLMMNN
  29. * Thumb 16-bit: 0x0000KKLL, where KK < 0xE8
  30. * Thumb 32-bit: 0xKKLLMMNN, where KK >= 0xE8
  31. *
  32. * There is no way to distinguish an ARM instruction in canonical representation
  33. * from a Thumb instruction (just as these cannot be distinguished in memory).
  34. * Where this distinction is important, it needs to be tracked separately.
  35. *
  36. * Note that values in the range 0x0000E800..0xE7FFFFFF intentionally do not
  37. * represent any valid Thumb-2 instruction. For this range,
  38. * __opcode_is_thumb32() and __opcode_is_thumb16() will both be false.
  39. */
  40. #ifndef __ASSEMBLY__
  41. #include <linux/types.h>
  42. #include <linux/swab.h>
  43. #ifdef CONFIG_CPU_ENDIAN_BE8
  44. #define __opcode_to_mem_arm(x) swab32(x)
  45. #define __opcode_to_mem_thumb16(x) swab16(x)
  46. #define __opcode_to_mem_thumb32(x) swahb32(x)
  47. #else
  48. #define __opcode_to_mem_arm(x) ((u32)(x))
  49. #define __opcode_to_mem_thumb16(x) ((u16)(x))
  50. #define __opcode_to_mem_thumb32(x) swahw32(x)
  51. #endif
  52. #define __mem_to_opcode_arm(x) __opcode_to_mem_arm(x)
  53. #define __mem_to_opcode_thumb16(x) __opcode_to_mem_thumb16(x)
  54. #define __mem_to_opcode_thumb32(x) __opcode_to_mem_thumb32(x)
  55. /* Operations specific to Thumb opcodes */
  56. /* Instruction size checks: */
  57. #define __opcode_is_thumb32(x) ((u32)(x) >= 0xE8000000UL)
  58. #define __opcode_is_thumb16(x) ((u32)(x) < 0xE800UL)
  59. /* Operations to construct or split 32-bit Thumb instructions: */
  60. #define __opcode_thumb32_first(x) ((u16)((x) >> 16))
  61. #define __opcode_thumb32_second(x) ((u16)(x))
  62. #define __opcode_thumb32_compose(first, second) \
  63. (((u32)(u16)(first) << 16) | (u32)(u16)(second))
  64. #endif /* __ASSEMBLY__ */
  65. #endif /* __ASM_ARM_OPCODES_H */