Skip to contentSkip to conversation

Single-stepping emulated instructions

PATCH New Paul Mackerras 1 participant 1 message Jun 8, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Single-stepping emulated instructions

Occasionally the ppc64 kernel emulates a usermode instruction, for example in the alignment exception handler. Kumar Gala pointed out (in the context of the ppc32 kernel) that if the instruction was being single-stepped, and we end up emulating the instruction, we should then send the process a SIGTRAP as if it had not been emulated and the process had then taken a single-step exception. This patch implements this for ppc64.

arch/ppc64/kernel/traps.c +13 -3
diff -urN linux-2.5/arch/ppc64/kernel/traps.c b/arch/ppc64/kernel/traps.c
@@ -500,6 +500,18 @@
 	_exception(SIGTRAP, &info, regs);	
 }
 
+/*
+ * After we have successfully emulated an instruction, we have to
+ * check if the instruction was being single-stepped, and if so,
+ * pretend we got a single-step exception.  This was pointed out
+ * by Kumar Gala.  -- paulus
+ */
+static inline void emulate_single_step(struct pt_regs *regs)
+{
+	if (regs->msr & MSR_SE)
+		SingleStepException(regs);
+}
+
 static void dummy_perf(struct pt_regs *regs)
 {
 }
@@ -521,10 +533,8 @@
 	fixed = fix_alignment(regs);
 
 	if (fixed == 1) {
-		if (!user_mode(regs))
-			PPCDBG(PPCDBG_ALIGNFIXUP, "fix alignment at %lx\n",
-			       regs->nip);
 		regs->nip += 4;	/* skip over emulated instruction */
+		emulate_single_step(regs);
 		return;
 	}