Skip to content

Commit e698b96

Browse files
paulusmackozbenh
authored andcommitted
powerpc: Fix bugs in emulate_step()
This fixes some bugs in emulate_step(). First, the setting of the carry bit for the arithmetic right-shift instructions was not correct on 64-bit machines because we were masking with a mask of type int rather than unsigned long. Secondly, the sld (shift left doubleword) instruction was using the wrong instruction field for the register containing the shift count. Signed-off-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent bd6ba35 commit e698b96

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

arch/powerpc/lib/sstep.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
11981198
sh = regs->gpr[rb] & 0x3f;
11991199
ival = (signed int) regs->gpr[rd];
12001200
regs->gpr[ra] = ival >> (sh < 32 ? sh : 31);
1201-
if (ival < 0 && (sh >= 32 || (ival & ((1 << sh) - 1)) != 0))
1201+
if (ival < 0 && (sh >= 32 || (ival & ((1ul << sh) - 1)) != 0))
12021202
regs->xer |= XER_CA;
12031203
else
12041204
regs->xer &= ~XER_CA;
@@ -1208,15 +1208,15 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
12081208
sh = rb;
12091209
ival = (signed int) regs->gpr[rd];
12101210
regs->gpr[ra] = ival >> sh;
1211-
if (ival < 0 && (ival & ((1 << sh) - 1)) != 0)
1211+
if (ival < 0 && (ival & ((1ul << sh) - 1)) != 0)
12121212
regs->xer |= XER_CA;
12131213
else
12141214
regs->xer &= ~XER_CA;
12151215
goto logical_done;
12161216

12171217
#ifdef __powerpc64__
12181218
case 27: /* sld */
1219-
sh = regs->gpr[rd] & 0x7f;
1219+
sh = regs->gpr[rb] & 0x7f;
12201220
if (sh < 64)
12211221
regs->gpr[ra] = regs->gpr[rd] << sh;
12221222
else
@@ -1235,7 +1235,7 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
12351235
sh = regs->gpr[rb] & 0x7f;
12361236
ival = (signed long int) regs->gpr[rd];
12371237
regs->gpr[ra] = ival >> (sh < 64 ? sh : 63);
1238-
if (ival < 0 && (sh >= 64 || (ival & ((1 << sh) - 1)) != 0))
1238+
if (ival < 0 && (sh >= 64 || (ival & ((1ul << sh) - 1)) != 0))
12391239
regs->xer |= XER_CA;
12401240
else
12411241
regs->xer &= ~XER_CA;
@@ -1246,7 +1246,7 @@ int __kprobes emulate_step(struct pt_regs *regs, unsigned int instr)
12461246
sh = rb | ((instr & 2) << 4);
12471247
ival = (signed long int) regs->gpr[rd];
12481248
regs->gpr[ra] = ival >> sh;
1249-
if (ival < 0 && (ival & ((1 << sh) - 1)) != 0)
1249+
if (ival < 0 && (ival & ((1ul << sh) - 1)) != 0)
12501250
regs->xer |= XER_CA;
12511251
else
12521252
regs->xer &= ~XER_CA;

0 commit comments

Comments
 (0)