Skip to contentSkip to conversation

Fix stack dsp offset

RFC PATCH New Michael Trimarchi 1 participant 1 message Mar 24, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Fix stack dsp offset

Compute correcly the offset of the registers on the stack when the CONFIG_SH_DSP is enabled. It add a thread depend information in the thread_struct. It was tested in the migor sh4a using a gdbserver application for a non dsp application.

---

arch/sh/include/asm/processor_32.h +3 -0
index efdd78a..46e73b2 100644
@@ -96,6 +96,9 @@ struct thread_struct {
 
 	/* floating point info */
 	union sh_fpu_union fpu;
+
+	/* Dsp status information */
+	long dsp_status;
 };
 
 /* Count of active tasks with UBC settings */
arch/sh/include/asm/ptrace.h +12 -4
index 81c6568..3504f2d 100644
@@ -120,11 +120,19 @@ extern void user_enable_single_step(struct task_struct *);
 extern void user_disable_single_step(struct task_struct *);
 
 #ifdef CONFIG_SH_DSP
-#define task_pt_regs(task) \
-	((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE \
-		 - sizeof(struct pt_dspregs)) - 1)
+extern int is_dsp_enabled(struct task_struct *);
+
 #define task_pt_dspregs(task) \
-	((struct pt_dspregs *) (task_stack_page(task) + THREAD_SIZE) - 1)
+	((struct pt_dspregs *) (task_stack_page(task) + THREAD_SIZE \
+		 - sizeof(unsigned long)) - 1)
+
+#define task_pt_regs(task) \
+        (is_dsp_enabled(task) ? \
+		((struct pt_regs *) (task_stack_page(task) + \
+			THREAD_SIZE - sizeof(struct pt_dspregs) - \
+			sizeof(unsigned long)) - 1): \
+		((struct pt_regs *) (task_stack_page(task) + \
+			THREAD_SIZE - sizeof(unsigned long)) - 1))
 #else
 #define task_pt_regs(task) \
 	((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1)
arch/sh/kernel/ptrace_32.c +6 -0
index 29ca09d..4560637 100644
@@ -195,6 +195,12 @@ static int fpregs_active(struct task_struct *target,
 #endif
 
 #ifdef CONFIG_SH_DSP
+
+int is_dsp_enabled(struct task_struct *task)
+{
+	return !!(task->thread.dsp_status & SR_DSP);
+}
+
 static int dspregs_get(struct task_struct *target,
 		       const struct user_regset *regset,
 		       unsigned int pos, unsigned int count,
arch/sh/kernel/traps_32.c +2 -0
index 60dcf87..d97886d 100644
@@ -664,6 +664,8 @@ asmlinkage void do_reserved_inst(unsigned long r4, unsigned long r5,
 	if (is_dsp_inst(regs)) {
 		/* Enable DSP mode, and restart instruction. */
 		regs->sr |= SR_DSP;
+		/* Save DSP mode */
+		tsk->thread.dsp_status |= SR_DSP;
 		return;
 	}
 #endif