Skip to content

Commit 6888199

Browse files
Ananth N Mavinakayanahallipaulusmack
authored andcommitted
[POWERPC] Emulate more instructions in software
Emulate a few more instructions in software - especially useful during singlestepping (xmon/kprobes). Instructions emulated with this patch are mfcr/mtcr rX, mfxer/mtxer rX, mflr/mtlr rX, mfctr/mtctr rX and mr rA,rB. Signed-off-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent 5cc5133 commit 6888199

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

arch/powerpc/lib/sstep.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static int __kprobes branch_taken(unsigned int instr, struct pt_regs *regs)
5454
*/
5555
int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
5656
{
57-
unsigned int opcode, rd;
57+
unsigned int opcode, rs, rb, rd, spr;
5858
unsigned long int imm;
5959

6060
opcode = instr >> 26;
@@ -152,6 +152,49 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
152152
regs->nip &= 0xffffffffUL;
153153
return 1;
154154
#endif
155+
case 0x26: /* mfcr */
156+
regs->gpr[rd] = regs->ccr;
157+
regs->gpr[rd] &= 0xffffffffUL;
158+
goto mtspr_out;
159+
case 0x2a6: /* mfspr */
160+
spr = (instr >> 11) & 0x3ff;
161+
switch (spr) {
162+
case 0x20: /* mfxer */
163+
regs->gpr[rd] = regs->xer;
164+
regs->gpr[rd] &= 0xffffffffUL;
165+
goto mtspr_out;
166+
case 0x100: /* mflr */
167+
regs->gpr[rd] = regs->link;
168+
goto mtspr_out;
169+
case 0x120: /* mfctr */
170+
regs->gpr[rd] = regs->ctr;
171+
goto mtspr_out;
172+
}
173+
break;
174+
case 0x378: /* orx */
175+
rs = (instr >> 21) & 0x1f;
176+
rb = (instr >> 11) & 0x1f;
177+
if (rs == rb) { /* mr */
178+
rd = (instr >> 16) & 0x1f;
179+
regs->gpr[rd] = regs->gpr[rs];
180+
goto mtspr_out;
181+
}
182+
break;
183+
case 0x3a6: /* mtspr */
184+
spr = (instr >> 11) & 0x3ff;
185+
switch (spr) {
186+
case 0x20: /* mtxer */
187+
regs->xer = (regs->gpr[rd] & 0xffffffffUL);
188+
goto mtspr_out;
189+
case 0x100: /* mtlr */
190+
regs->link = regs->gpr[rd];
191+
goto mtspr_out;
192+
case 0x120: /* mtctr */
193+
regs->ctr = regs->gpr[rd];
194+
mtspr_out:
195+
regs->nip += 4;
196+
return 1;
197+
}
155198
}
156199
}
157200
return 0;

0 commit comments

Comments
 (0)