Skip to contentSkip to conversation

PPC: sstep.c: Add modsw, moduw instruction emulation

PATCH Superseded PrasannaKumar Muralidharan 2 participants 8 messages Dec 4, 2016 – Dec 6, 2016 PowerPC

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PPC: sstep.c: Add modsw, moduw instruction emulation

Add modsw and moduw instruction emulation support to analyse_instr.

---
 arch/powerpc/lib/sstep.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/powerpc/lib/sstep.c +9 -0
index 9c78a9c..5acef72 100644
@@ -1148,6 +1148,15 @@ int __kprobes analyse_instr(struct instruction_op *op, struct pt_regs *regs,
 				(int) regs->gpr[rb];
 			goto arith_done;
 
+		case 779:	/* modsw */
+			regs->gpr[rd] = (int) regs->gpr[ra] %
+				(int) regs->gpr[rb];
+			goto arith_done;
+
+		case 267:	/* moduw */
+			regs->gpr[rd] = (unsigned int) regs->gpr[ra] %
+				(unsigned int) regs->gpr[rb];
+			goto arith_done;
 
 /*
  * Logical instructions
Signature · 1 line
2.9.3
#1 lore raw
Quoted 3 lines · PrasannaKumar Muralidharan

Add modsw and moduw instruction emulation support to analyse_instr.

Hi Prasanna,
Thanks for the patch! A few minor comments below...

Quoted 9 lines
---
 arch/powerpc/lib/sstep.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/powerpc/lib/sstep.c +0 -0
index 9c78a9c..5acef72 100644

arch/powerpc/lib/sstep.c int __kprobes analyse_instr(struct instruction_op *op, struct pt_regs *regs, · line 1154

Quoted 7 lines
arch/powerpc/lib/sstep.c +4 -0
@@ -1148,6 +1148,15 @@ int __kprobes analyse_instr(struct instruction_op *op, struct pt_regs *regs,
 				(int) regs->gpr[rb];
 			goto arith_done;
 
+		case 779:	/* modsw */
+			regs->gpr[rd] = (int) regs->gpr[ra] %
+				(int) regs->gpr[rb];
+			goto arith_done;

Since these instructions don't update CR, you can directly goto instr_done.

arch/powerpc/lib/sstep.c int __kprobes analyse_instr(struct instruction_op *op, struct pt_regs *regs, · line 1156

Quoted 2 lines
arch/powerpc/lib/sstep.c +2 -0
+
+		case 267:	/* moduw */

Please move this case further up so that the extended opcodes are in numerical order.

- Naveen

#2 lore raw

Hi Naveen,

Thanks for the review.

Quoted 12 lines
Quoted 12 lines
---
 arch/powerpc/lib/sstep.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/powerpc/lib/sstep.c +0 -0
index 9c78a9c..5acef72 100644
@@ -1148,6 +1148,15 @@ int __kprobes analyse_instr(struct instruction_op *op, struct pt_regs *regs,
                              (int) regs->gpr[rb];
                      goto arith_done;
 
Quoted 7 lines

arch/powerpc/lib/sstep.c int __kprobes analyse_instr(struct instruction_op *op, struct pt_regs *regs, · line 1154

Quoted 4 lines
arch/powerpc/lib/sstep.c +4 -0
+             case 779:       /* modsw */
+                     regs->gpr[rd] = (int) regs->gpr[ra] %
+                             (int) regs->gpr[rb];
+                     goto arith_done;

Since these instructions don't update CR, you can directly goto instr_done.

Sure. Will use that.

Quoted 5 lines

arch/powerpc/lib/sstep.c int __kprobes analyse_instr(struct instruction_op *op, struct pt_regs *regs, · line 1156

Quoted 2 lines
arch/powerpc/lib/sstep.c +2 -0
+
+             case 267:       /* moduw */

Please move this case further up so that the extended opcodes are in numerical order.

Placed it after divide instruction as it appeared logical. Also placed 267 below 779 as it is the order in which the instructions are documented in the ISA book. This may help in finding related instructions together. If this style is not preferred I can arrange it in numerical order.

Regards,
PrasannaKumar

#3 lore raw
Quoted 11 lines · PrasannaKumar Muralidharan
Quoted 5 lines

arch/powerpc/lib/sstep.c int __kprobes analyse_instr(struct instruction_op *op, struct pt_regs *regs, · line 1156

Quoted 2 lines
arch/powerpc/lib/sstep.c +2 -0
+
+             case 267:       /* moduw */

Please move this case further up so that the extended opcodes are in numerical order.

Placed it after divide instruction as it appeared logical. Also placed 267 below 779 as it is the order in which the instructions are documented in the ISA book. This may help in finding related instructions together. If this style is not preferred I can arrange it in numerical order.

I guessed as much, but if you look at the existing function, you'll see that things have been arranged in numerical order. As such, it's best to stick to that convention.

- Naveen

#5 lore raw
In reply to PrasannaKumar Muralidharan

By the way, I missed mentioning previously: please use 'powerpc: ' prefix for the subject, rather than PPC.

Quoted 1 line · PrasannaKumar Muralidharan

Add modsw and moduw instruction emulation support to analyse_instr.

And, it will be better if you can briefly describe what these functions do for the benefit of others.

- Naveen

#4 lore raw
In reply to Naveen N. Rao
Quoted 3 lines

I guessed as much, but if you look at the existing function, you'll see that things have been arranged in numerical order. As such, it's best to stick to that convention.

Makes sense. Will do.

#6 lore raw
In reply to Naveen N. Rao
Quoted 2 lines

By the way, I missed mentioning previously: please use 'powerpc: ' prefix for the subject, rather than PPC.

I will change it. Wondering how they are different.

Quoted 4 lines
Quoted 1 line

Add modsw and moduw instruction emulation support to analyse_instr.

And, it will be better if you can briefly describe what these functions do for the benefit of others.

Sure. I will add description.

#7 lore raw
Quoted 4 lines · PrasannaKumar Muralidharan
Quoted 2 lines

By the way, I missed mentioning previously: please use 'powerpc: ' prefix for the subject, rather than PPC.

I will change it. Wondering how they are different.

It's by convention. Maintainers are picky ;)

- Naveen