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>
8 * Instruction data type for POWER
18 static inline u32 ppc_inst_val(struct ppc_inst x)
23 static inline int ppc_inst_primary_opcode(struct ppc_inst x)
25 return ppc_inst_val(x) >> 26;
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)
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)
54 if ((val >> 26) == OP_PREFIX) {
55 suffix = *((u32 *)ptr + 1);
56 return ppc_inst_prefix(val, suffix);
62 static inline bool ppc_inst_equal(struct ppc_inst x, struct ppc_inst y)
64 return *(u64 *)&x == *(u64 *)&y;
69 #define ppc_inst(x) ((struct ppc_inst){ .val = x })
71 static inline bool ppc_inst_prefixed(struct ppc_inst x)
76 static inline u32 ppc_inst_suffix(struct ppc_inst x)
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)
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)
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);
121 return (u64)ppc_inst_val(x) << 32 | ppc_inst_suffix(x);
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));
132 sprintf(str, "%08x", ppc_inst_val(x));
137 #define ppc_inst_as_str(x) \
139 char __str[PPC_INST_STR_LEN]; \
140 __ppc_inst_as_str(__str, x); \
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 */