Skip to content

Commit 8094892

Browse files
iamjpnmpe
authored andcommitted
powerpc: Use a function for getting the instruction op code
In preparation for using a data type for instructions that can not be directly used with the '>>' operator use a function for getting the op code of an instruction. Signed-off-by: Jordan Niethe <jniethe5@gmail.com> Reviewed-by: Alistair Popple <alistair@popple.id.au> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20200506034050.24806-9-jniethe5@gmail.com
1 parent 777e26f commit 8094892

6 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎arch/powerpc/include/asm/inst.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ static inline u32 ppc_inst_val(u32 x)
1313
return x;
1414
}
1515

16+
static inline int ppc_inst_primary_opcode(u32 x)
17+
{
18+
return ppc_inst_val(x) >> 26;
19+
}
20+
1621
#endif /* _ASM_POWERPC_INST_H */

‎arch/powerpc/kernel/align.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ int fix_alignment(struct pt_regs *regs)
314314
}
315315

316316
#ifdef CONFIG_SPE
317-
if ((ppc_inst_val(instr) >> 26) == 0x4) {
317+
if (ppc_inst_primary_opcode(instr) == 0x4) {
318318
int reg = (ppc_inst_val(instr) >> 21) & 0x1f;
319319
PPC_WARN_ALIGNMENT(spe, regs);
320320
return emulate_spe(regs, reg, instr);

‎arch/powerpc/kernel/vecemu.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <asm/processor.h>
1111
#include <asm/switch_to.h>
1212
#include <linux/uaccess.h>
13+
#include <asm/inst.h>
1314

1415
/* Functions in vector.S */
1516
extern void vaddfp(vector128 *dst, vector128 *a, vector128 *b);
@@ -268,7 +269,7 @@ int emulate_altivec(struct pt_regs *regs)
268269
return -EFAULT;
269270

270271
word = ppc_inst_val(instr);
271-
if ((word >> 26) != 4)
272+
if (ppc_inst_primary_opcode(instr) != 4)
272273
return -EINVAL; /* not an altivec instruction */
273274
vd = (word >> 21) & 0x1f;
274275
va = (word >> 16) & 0x1f;

‎arch/powerpc/lib/code-patching.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ bool is_offset_in_branch_range(long offset)
231231
*/
232232
bool is_conditional_branch(unsigned int instr)
233233
{
234-
unsigned int opcode = instr >> 26;
234+
unsigned int opcode = ppc_inst_primary_opcode(instr);
235235

236236
if (opcode == 16) /* bc, bca, bcl, bcla */
237237
return true;
@@ -289,7 +289,7 @@ int create_cond_branch(unsigned int *instr, const unsigned int *addr,
289289

290290
static unsigned int branch_opcode(unsigned int instr)
291291
{
292-
return (instr >> 26) & 0x3F;
292+
return ppc_inst_primary_opcode(instr) & 0x3F;
293293
}
294294

295295
static int instr_is_branch_iform(unsigned int instr)

‎arch/powerpc/lib/sstep.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ int analyse_instr(struct instruction_op *op, const struct pt_regs *regs,
11751175
word = ppc_inst_val(instr);
11761176
op->type = COMPUTE;
11771177

1178-
opcode = instr >> 26;
1178+
opcode = ppc_inst_primary_opcode(instr);
11791179
switch (opcode) {
11801180
case 16: /* bc */
11811181
op->type = BRANCH;

‎arch/powerpc/mm/fault.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <asm/siginfo.h>
4242
#include <asm/debug.h>
4343
#include <asm/kup.h>
44+
#include <asm/inst.h>
4445

4546
/*
4647
* Check whether the instruction inst is a store using
@@ -52,7 +53,7 @@ static bool store_updates_sp(unsigned int inst)
5253
if (((ppc_inst_val(inst) >> 16) & 0x1f) != 1)
5354
return false;
5455
/* check major opcode */
55-
switch (inst >> 26) {
56+
switch (ppc_inst_primary_opcode(inst)) {
5657
case OP_STWU:
5758
case OP_STBU:
5859
case OP_STHU:

0 commit comments

Comments
 (0)