* [PATCH] Emulate more instructions in software
@ 2007-04-18 5:56 Ananth N Mavinakayanahalli
2007-04-18 6:11 ` Kumar Gala
0 siblings, 1 reply; 6+ messages in thread
From: Ananth N Mavinakayanahalli @ 2007-04-18 5:56 UTC (permalink / raw)
To: Paul Mackerras; +Cc: linuxppc-dev
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>
---
arch/powerpc/lib/sstep.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 44 insertions(+), 1 deletion(-)
Index: linux-2.6.21-rc7/arch/powerpc/lib/sstep.c
===================================================================
--- linux-2.6.21-rc7.orig/arch/powerpc/lib/sstep.c
+++ linux-2.6.21-rc7/arch/powerpc/lib/sstep.c
@@ -54,7 +54,7 @@ static int __kprobes branch_taken(unsign
*/
int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
{
- unsigned int opcode, rd;
+ unsigned int opcode, rs, rb, rd, spr;
unsigned long int imm;
opcode = instr >> 26;
@@ -152,6 +152,49 @@ int __kprobes emulate_step(struct pt_reg
regs->nip &= 0xffffffffUL;
return 1;
#endif
+ case 0x26: /* mfcr */
+ regs->gpr[rd] = regs->ccr;
+ regs->gpr[rd] &= 0xffffffffUL;
+ goto mtspr_out;
+ case 0x2a6: /* mfspr */
+ spr = (instr >> 11) & 0x3ff;
+ switch (spr) {
+ case 0x20: /* mfxer */
+ regs->gpr[rd] = regs->xer;
+ regs->gpr[rd] &= 0xffffffffUL;
+ goto mtspr_out;
+ case 0x100: /* mflr */
+ regs->gpr[rd] = regs->link;
+ goto mtspr_out;
+ case 0x120: /* mfctr */
+ regs->gpr[rd] = regs->ctr;
+ goto mtspr_out;
+ }
+ break;
+ case 0x378: /* orx */
+ rs = (instr >> 21) & 0x1f;
+ rb = (instr >> 11) & 0x1f;
+ if (rs == rb) { /* mr */
+ rd = (instr >> 16) & 0x1f;
+ regs->gpr[rd] = regs->gpr[rs];
+ goto mtspr_out;
+ }
+ break;
+ case 0x3a6: /* mtspr */
+ spr = (instr >> 11) & 0x3ff;
+ switch (spr) {
+ case 0x20: /* mtxer */
+ regs->xer = (regs->gpr[rd] & 0xffffffffUL);
+ goto mtspr_out;
+ case 0x100: /* mtlr */
+ regs->link = regs->gpr[rd];
+ goto mtspr_out;
+ case 0x120: /* mtctr */
+ regs->ctr = regs->gpr[rd];
+mtspr_out:
+ regs->nip += 4;
+ return 1;
+ }
}
}
return 0;
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] Emulate more instructions in software
2007-04-18 5:56 [PATCH] Emulate more instructions in software Ananth N Mavinakayanahalli
@ 2007-04-18 6:11 ` Kumar Gala
2007-04-18 7:13 ` Ananth N Mavinakayanahalli
0 siblings, 1 reply; 6+ messages in thread
From: Kumar Gala @ 2007-04-18 6:11 UTC (permalink / raw)
To: ananth; +Cc: linuxppc-dev, Paul Mackerras
On Apr 18, 2007, at 12:56 AM, Ananth N Mavinakayanahalli wrote:
> 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>
When do we actually need to emulate any of these instructions? I
don't see why single stepping would effect the ability to execute
these instructions.
- k
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Emulate more instructions in software
2007-04-18 6:11 ` Kumar Gala
@ 2007-04-18 7:13 ` Ananth N Mavinakayanahalli
2007-04-18 16:23 ` Kumar Gala
0 siblings, 1 reply; 6+ messages in thread
From: Ananth N Mavinakayanahalli @ 2007-04-18 7:13 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev, Paul Mackerras
On Wed, Apr 18, 2007 at 01:11:00AM -0500, Kumar Gala wrote:
>
> On Apr 18, 2007, at 12:56 AM, Ananth N Mavinakayanahalli wrote:
>
> > 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>
>
> When do we actually need to emulate any of these instructions? I
> don't see why single stepping would effect the ability to execute
> these instructions.
In cases when these instructions are kprobed, it'd be possible to
eliminate the single step exception as we can emulate them.
Most usecases of kprobes are at function entry and in most cases, the
instruction at function entry is mflr r0, which can be emulated. So you
can get rid of one exception and get a nice speedup too. My other patch
did just this.
Ananth
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Emulate more instructions in software
2007-04-18 7:13 ` Ananth N Mavinakayanahalli
@ 2007-04-18 16:23 ` Kumar Gala
2007-04-18 16:25 ` Kumar Gala
0 siblings, 1 reply; 6+ messages in thread
From: Kumar Gala @ 2007-04-18 16:23 UTC (permalink / raw)
To: ananth; +Cc: linuxppc-dev, Paul Mackerras
On Apr 18, 2007, at 2:13 AM, Ananth N Mavinakayanahalli wrote:
> On Wed, Apr 18, 2007 at 01:11:00AM -0500, Kumar Gala wrote:
>>
>> On Apr 18, 2007, at 12:56 AM, Ananth N Mavinakayanahalli wrote:
>>
>>> 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>
>>
>> When do we actually need to emulate any of these instructions? I
>> don't see why single stepping would effect the ability to execute
>> these instructions.
>
> In cases when these instructions are kprobed, it'd be possible to
> eliminate the single step exception as we can emulate them.
>
> Most usecases of kprobes are at function entry and in most cases, the
> instruction at function entry is mflr r0, which can be emulated. So
> you
> can get rid of one exception and get a nice speedup too. My other
> patch
> did just this.
Makes sense, how about wrapping the emulation of those instructions
in a #if defined(CONFIG_KPROBES) || defined(CONFIG_XMON). Plus
adding a comment about these instructions just be emulated for
singlestepping performance and not because they are missing on some
platform.
Also, do you really see that many mfxer/mtxer. I'd expect them to be
rare.
- k
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Emulate more instructions in software
2007-04-18 16:23 ` Kumar Gala
@ 2007-04-18 16:25 ` Kumar Gala
2007-04-19 4:17 ` Ananth N Mavinakayanahalli
0 siblings, 1 reply; 6+ messages in thread
From: Kumar Gala @ 2007-04-18 16:25 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev, Paul Mackerras
On Apr 18, 2007, at 11:23 AM, Kumar Gala wrote:
>
> On Apr 18, 2007, at 2:13 AM, Ananth N Mavinakayanahalli wrote:
>
>> On Wed, Apr 18, 2007 at 01:11:00AM -0500, Kumar Gala wrote:
>>>
>>> On Apr 18, 2007, at 12:56 AM, Ananth N Mavinakayanahalli wrote:
>>>
>>>> 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>
>>>
>>> When do we actually need to emulate any of these instructions? I
>>> don't see why single stepping would effect the ability to execute
>>> these instructions.
>>
>> In cases when these instructions are kprobed, it'd be possible to
>> eliminate the single step exception as we can emulate them.
>>
>> Most usecases of kprobes are at function entry and in most cases, the
>> instruction at function entry is mflr r0, which can be emulated. So
>> you
>> can get rid of one exception and get a nice speedup too. My other
>> patch
>> did just this.
>
> Makes sense, how about wrapping the emulation of those instructions
> in a #if defined(CONFIG_KPROBES) || defined(CONFIG_XMON). Plus
> adding a comment about these instructions just be emulated for
> singlestepping performance and not because they are missing on some
> platform.
Ignore this, I see this code is in lib/sstep.c not the main emulation
path.
> Also, do you really see that many mfxer/mtxer. I'd expect them to be
> rare.
>
> - k
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Emulate more instructions in software
2007-04-18 16:25 ` Kumar Gala
@ 2007-04-19 4:17 ` Ananth N Mavinakayanahalli
0 siblings, 0 replies; 6+ messages in thread
From: Ananth N Mavinakayanahalli @ 2007-04-19 4:17 UTC (permalink / raw)
To: Kumar Gala; +Cc: linuxppc-dev, Paul Mackerras
On Wed, Apr 18, 2007 at 11:25:55AM -0500, Kumar Gala wrote:
>
> On Apr 18, 2007, at 11:23 AM, Kumar Gala wrote:
>
> >
> >On Apr 18, 2007, at 2:13 AM, Ananth N Mavinakayanahalli wrote:
> >
> >>On Wed, Apr 18, 2007 at 01:11:00AM -0500, Kumar Gala wrote:
> >>>
> >>>On Apr 18, 2007, at 12:56 AM, Ananth N Mavinakayanahalli wrote:
> >>>
> >>>>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>
> >>>
> >>>When do we actually need to emulate any of these instructions? I
> >>>don't see why single stepping would effect the ability to execute
> >>>these instructions.
> >>
> >>In cases when these instructions are kprobed, it'd be possible to
> >>eliminate the single step exception as we can emulate them.
> >>
> >>Most usecases of kprobes are at function entry and in most cases, the
> >>instruction at function entry is mflr r0, which can be emulated. So
> >>you
> >>can get rid of one exception and get a nice speedup too. My other
> >>patch
> >>did just this.
> >
> >Makes sense, how about wrapping the emulation of those instructions
> >in a #if defined(CONFIG_KPROBES) || defined(CONFIG_XMON). Plus
> >adding a comment about these instructions just be emulated for
> >singlestepping performance and not because they are missing on some
> >platform.
>
> Ignore this, I see this code is in lib/sstep.c not the main emulation
> path.
>
> >Also, do you really see that many mfxer/mtxer. I'd expect them to be
> >rare.
Right. In fact, there were none in the .o files I checked. I put the
code for it for completeness wrt registers exposed by pt_regs.
Ananth
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-04-19 4:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-18 5:56 [PATCH] Emulate more instructions in software Ananth N Mavinakayanahalli
2007-04-18 6:11 ` Kumar Gala
2007-04-18 7:13 ` Ananth N Mavinakayanahalli
2007-04-18 16:23 ` Kumar Gala
2007-04-18 16:25 ` Kumar Gala
2007-04-19 4:17 ` Ananth N Mavinakayanahalli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).