WIP FPC-III support
[linux/fpc-iii.git] / arch / powerpc / include / asm / inst.h
blobcc73c12675721c3e699dcc4056db785a5a04d6eb
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _ASM_POWERPC_INST_H
3 #define _ASM_POWERPC_INST_H
5 #include <asm/ppc-opcode.h>
7 /*
8 * Instruction data type for POWER
9 */
11 struct ppc_inst {
12 u32 val;
13 #ifdef CONFIG_PPC64
14 u32 suffix;
15 #endif
16 } __packed;
18 static inline u32 ppc_inst_val(struct ppc_inst x)
20 return x.val;
23 static inline int ppc_inst_primary_opcode(struct ppc_inst x)
25 return ppc_inst_val(x) >> 26;
28 #ifdef CONFIG_PPC64
29 #define ppc_inst(x) ((struct ppc_inst){ .val = (x), .suffix = 0xff })
31 #define ppc_inst_prefix(x, y) ((struct ppc_inst){ .val = (x), .suffix = (y) })
33 static inline u32 ppc_inst_suffix(struct ppc_inst x)
35 return x.suffix;
38 static inline bool ppc_inst_prefixed(struct ppc_inst x)
40 return (ppc_inst_primary_opcode(x) == 1) && ppc_inst_suffix(x) != 0xff;
43 static inline struct ppc_inst ppc_inst_swab(struct ppc_inst x)
45 return ppc_inst_prefix(swab32(ppc_inst_val(x)),
46 swab32(ppc_inst_suffix(x)));
49 static inline struct ppc_inst ppc_inst_read(const struct ppc_inst *ptr)
51 u32 val, suffix;
53 val = *(u32 *)ptr;
54 if ((val >> 26) == OP_PREFIX) {
55 suffix = *((u32 *)ptr + 1);
56 return ppc_inst_prefix(val, suffix);
57 } else {
58 return ppc_inst(val);
62 static inline bool ppc_inst_equal(struct ppc_inst x, struct ppc_inst y)
64 return *(u64 *)&x == *(u64 *)&y;
67 #else
69 #define ppc_inst(x) ((struct ppc_inst){ .val = x })
71 static inline bool ppc_inst_prefixed(struct ppc_inst x)
73 return false;
76 static inline u32 ppc_inst_suffix(struct ppc_inst x)
78 return 0;
81 static inline struct ppc_inst ppc_inst_swab(struct ppc_inst x)
83 return ppc_inst(swab32(ppc_inst_val(x)));
86 static inline struct ppc_inst ppc_inst_read(const struct ppc_inst *ptr)
88 return *ptr;
91 static inline bool ppc_inst_equal(struct ppc_inst x, struct ppc_inst y)
93 return ppc_inst_val(x) == ppc_inst_val(y);
96 #endif /* CONFIG_PPC64 */
98 static inline int ppc_inst_len(struct ppc_inst x)
100 return ppc_inst_prefixed(x) ? 8 : 4;
104 * Return the address of the next instruction, if the instruction @value was
105 * located at @location.
107 static inline struct ppc_inst *ppc_inst_next(void *location, struct ppc_inst *value)
109 struct ppc_inst tmp;
111 tmp = ppc_inst_read(value);
113 return location + ppc_inst_len(tmp);
116 static inline u64 ppc_inst_as_u64(struct ppc_inst x)
118 #ifdef CONFIG_CPU_LITTLE_ENDIAN
119 return (u64)ppc_inst_suffix(x) << 32 | ppc_inst_val(x);
120 #else
121 return (u64)ppc_inst_val(x) << 32 | ppc_inst_suffix(x);
122 #endif
125 #define PPC_INST_STR_LEN sizeof("00000000 00000000")
127 static inline char *__ppc_inst_as_str(char str[PPC_INST_STR_LEN], struct ppc_inst x)
129 if (ppc_inst_prefixed(x))
130 sprintf(str, "%08x %08x", ppc_inst_val(x), ppc_inst_suffix(x));
131 else
132 sprintf(str, "%08x", ppc_inst_val(x));
134 return str;
137 #define ppc_inst_as_str(x) \
138 ({ \
139 char __str[PPC_INST_STR_LEN]; \
140 __ppc_inst_as_str(__str, x); \
141 __str; \
144 int probe_user_read_inst(struct ppc_inst *inst,
145 struct ppc_inst __user *nip);
147 int probe_kernel_read_inst(struct ppc_inst *inst,
148 struct ppc_inst *src);
150 #endif /* _ASM_POWERPC_INST_H */