Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc: Make single-stepping emulation (mostly) usable on 32-bit

The sc instruction emulation can't be done the same way on 32-bit
as 64-bit yet, but this should work OK.

Signed-off-by: Paul Mackerras <paulus@samba.org>

+28 -1
+17
arch/powerpc/lib/sstep.c
··· 10 10 */ 11 11 #include <linux/kernel.h> 12 12 #include <linux/ptrace.h> 13 + #include <linux/config.h> 13 14 #include <asm/sstep.h> 14 15 #include <asm/processor.h> 15 16 16 17 extern char system_call_common[]; 17 18 19 + #ifdef CONFIG_PPC64 18 20 /* Bits in SRR1 that are copied from MSR */ 19 21 #define MSR_MASK 0xffffffff87c0ffff 22 + #else 23 + #define MSR_MASK 0x87c0ffff 24 + #endif 20 25 21 26 /* 22 27 * Determine whether a conditional branch instruction would branch. ··· 71 66 if (branch_taken(instr, regs)) 72 67 regs->nip = imm; 73 68 return 1; 69 + #ifdef CONFIG_PPC64 74 70 case 17: /* sc */ 75 71 /* 76 72 * N.B. this uses knowledge about how the syscall ··· 85 79 regs->nip = (unsigned long) &system_call_common; 86 80 regs->msr = MSR_KERNEL; 87 81 return 1; 82 + #endif 88 83 case 18: /* b */ 89 84 imm = instr & 0x03fffffc; 90 85 if (imm & 0x02000000) ··· 128 121 if ((regs->msr & MSR_SF) == 0) 129 122 regs->nip &= 0xffffffffUL; 130 123 return 1; 124 + case 0x124: /* mtmsr */ 125 + imm = regs->gpr[rd]; 126 + if ((imm & MSR_RI) == 0) 127 + /* can't step mtmsr that would clear MSR_RI */ 128 + return -1; 129 + regs->msr = imm; 130 + regs->nip += 4; 131 + return 1; 132 + #ifdef CONFIG_PPC64 131 133 case 0x164: /* mtmsrd */ 132 134 /* only MSR_EE and MSR_RI get changed if bit 15 set */ 133 135 /* mtmsrd doesn't change MSR_HV and MSR_ME */ ··· 151 135 if ((imm & MSR_SF) == 0) 152 136 regs->nip &= 0xffffffffUL; 153 137 return 1; 138 + #endif 154 139 } 155 140 } 156 141 return 0;
+8
include/asm-powerpc/reg.h
··· 51 51 #define __MASK(X) (1UL<<(X)) 52 52 #endif 53 53 54 + #ifdef CONFIG_PPC64 54 55 #define MSR_SF __MASK(MSR_SF_LG) /* Enable 64 bit mode */ 55 56 #define MSR_ISF __MASK(MSR_ISF_LG) /* Interrupt 64b mode valid on 630 */ 56 57 #define MSR_HV __MASK(MSR_HV_LG) /* Hypervisor state */ 58 + #else 59 + /* so tests for these bits fail on 32-bit */ 60 + #define MSR_SF 0 61 + #define MSR_ISF 0 62 + #define MSR_HV 0 63 + #endif 64 + 57 65 #define MSR_VEC __MASK(MSR_VEC_LG) /* Enable AltiVec */ 58 66 #define MSR_POW __MASK(MSR_POW_LG) /* Enable Power Management */ 59 67 #define MSR_WE __MASK(MSR_WE_LG) /* Wait State Enable */
+3 -1
include/asm-ppc64/sstep.h include/asm-powerpc/sstep.h
··· 16 16 * we don't allow putting a breakpoint on an mtmsrd instruction. 17 17 * Similarly we don't allow breakpoints on rfid instructions. 18 18 * These macros tell us if an instruction is a mtmsrd or rfid. 19 + * Note that IS_MTMSRD returns true for both an mtmsr (32-bit) 20 + * and an mtmsrd (64-bit). 19 21 */ 20 - #define IS_MTMSRD(instr) (((instr) & 0xfc0007fe) == 0x7c000164) 22 + #define IS_MTMSRD(instr) (((instr) & 0xfc0007be) == 0x7c000124) 21 23 #define IS_RFID(instr) (((instr) & 0xfc0007fe) == 0x4c000024) 22 24 23 25 /* Emulate instructions that cause a transfer of control. */