blob: 6bf54f9411a6609914be5a3d2022e9b7739b0a89 [file] [log] [blame]
Leif Lindholm0c9030d2011-12-12 19:31:55 +01001/*
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
9#ifndef __ASM_ARM_OPCODES_H
10#define __ASM_ARM_OPCODES_H
11
12#ifndef __ASSEMBLY__
13extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr);
14#endif
15
16#define ARM_OPCODE_CONDTEST_FAIL 0
17#define ARM_OPCODE_CONDTEST_PASS 1
18#define ARM_OPCODE_CONDTEST_UNCOND 2
19
Dave Martinf5f51952012-02-01 10:42:22 +010020
21/*
22 * Opcode byteswap helpers
23 *
24 * These macros help with converting instructions between a canonical integer
25 * format and in-memory representation, in an endianness-agnostic manner.
26 *
27 * __mem_to_opcode_*() convert from in-memory representation to canonical form.
28 * __opcode_to_mem_*() convert from canonical form to in-memory representation.
29 *
30 *
31 * Canonical instruction representation:
32 *
33 * ARM: 0xKKLLMMNN
34 * Thumb 16-bit: 0x0000KKLL, where KK < 0xE8
35 * Thumb 32-bit: 0xKKLLMMNN, where KK >= 0xE8
36 *
37 * There is no way to distinguish an ARM instruction in canonical representation
38 * from a Thumb instruction (just as these cannot be distinguished in memory).
39 * Where this distinction is important, it needs to be tracked separately.
40 *
41 * Note that values in the range 0x0000E800..0xE7FFFFFF intentionally do not
42 * represent any valid Thumb-2 instruction. For this range,
43 * __opcode_is_thumb32() and __opcode_is_thumb16() will both be false.
44 */
45
46#ifndef __ASSEMBLY__
47
48#include <linux/types.h>
49#include <linux/swab.h>
50
51#ifdef CONFIG_CPU_ENDIAN_BE8
Dave Martin57b9da32012-09-03 13:49:22 +010052
Dave Martinf5f51952012-02-01 10:42:22 +010053#define __opcode_to_mem_arm(x) swab32(x)
54#define __opcode_to_mem_thumb16(x) swab16(x)
55#define __opcode_to_mem_thumb32(x) swahb32(x)
Dave Martin57b9da32012-09-03 13:49:22 +010056
57#else /* ! CONFIG_CPU_ENDIAN_BE8 */
58
Dave Martinf5f51952012-02-01 10:42:22 +010059#define __opcode_to_mem_arm(x) ((u32)(x))
60#define __opcode_to_mem_thumb16(x) ((u16)(x))
Dave Martin57b9da32012-09-03 13:49:22 +010061#ifndef CONFIG_CPU_ENDIAN_BE32
62/*
63 * On BE32 systems, using 32-bit accesses to store Thumb instructions will not
64 * work in all cases, due to alignment constraints. For now, a correct
65 * version is not provided for BE32.
66 */
Dave Martinf5f51952012-02-01 10:42:22 +010067#define __opcode_to_mem_thumb32(x) swahw32(x)
68#endif
69
Dave Martin57b9da32012-09-03 13:49:22 +010070#endif /* ! CONFIG_CPU_ENDIAN_BE8 */
71
Dave Martinf5f51952012-02-01 10:42:22 +010072#define __mem_to_opcode_arm(x) __opcode_to_mem_arm(x)
73#define __mem_to_opcode_thumb16(x) __opcode_to_mem_thumb16(x)
Dave Martin57b9da32012-09-03 13:49:22 +010074#ifndef CONFIG_CPU_ENDIAN_BE32
Dave Martinf5f51952012-02-01 10:42:22 +010075#define __mem_to_opcode_thumb32(x) __opcode_to_mem_thumb32(x)
Dave Martin57b9da32012-09-03 13:49:22 +010076#endif
Dave Martinf5f51952012-02-01 10:42:22 +010077
78/* Operations specific to Thumb opcodes */
79
80/* Instruction size checks: */
81#define __opcode_is_thumb32(x) ((u32)(x) >= 0xE8000000UL)
82#define __opcode_is_thumb16(x) ((u32)(x) < 0xE800UL)
83
84/* Operations to construct or split 32-bit Thumb instructions: */
85#define __opcode_thumb32_first(x) ((u16)((x) >> 16))
86#define __opcode_thumb32_second(x) ((u16)(x))
87#define __opcode_thumb32_compose(first, second) \
88 (((u32)(u16)(first) << 16) | (u32)(u16)(second))
89
90#endif /* __ASSEMBLY__ */
91
Leif Lindholm0c9030d2011-12-12 19:31:55 +010092#endif /* __ASM_ARM_OPCODES_H */