From 83da6494a3a6d1411aa25e9900a787e2a15b5724 Mon Sep 17 00:00:00 2001
From: Paul Mundt <paul.mundt@nokia.com>
Date: Mon, 18 Oct 2004 08:58:30 -0700
Subject: [PATCH] [PATCH] sh: Use asm-offsets

This basically follows the same change as for sh64 and adds asm-offsets to sh.
 Some hardcoded thread_info struct offsets get cleaned up by this.

Signed-off-by: Paul Mundt <paul.mundt@nokia.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
 arch/sh/kernel/asm-offsets.c | 32 ++++++++++++++++++++++++++++++++
 arch/sh/kernel/entry.S       |  1 +
 include/asm-sh/thread_info.h | 10 ----------
 3 files changed, 33 insertions(+), 10 deletions(-)
 create mode 100644 arch/sh/kernel/asm-offsets.c

diff --git a/arch/sh/kernel/asm-offsets.c b/arch/sh/kernel/asm-offsets.c
new file mode 100644
index 000000000000..dc6725c51a89
--- /dev/null
+++ b/arch/sh/kernel/asm-offsets.c
@@ -0,0 +1,32 @@
+/*
+ * This program is used to generate definitions needed by
+ * assembly language modules.
+ *
+ * We use the technique used in the OSF Mach kernel code:
+ * generate asm statements containing #defines,
+ * compile this file to assembler, and then extract the
+ * #defines from the assembly-language output.
+ */
+
+#include <linux/stddef.h>
+#include <linux/types.h>
+#include <linux/mm.h>
+#include <asm/thread_info.h>
+
+#define DEFINE(sym, val) \
+        asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+
+#define BLANK() asm volatile("\n->" : : )
+
+int main(void)
+{
+	/* offsets into the thread_info struct */
+	DEFINE(TI_TASK,		offsetof(struct thread_info, task));
+	DEFINE(TI_EXEC_DOMAIN,	offsetof(struct thread_info, exec_domain));
+	DEFINE(TI_FLAGS,	offsetof(struct thread_info, flags));
+	DEFINE(TI_CPU,		offsetof(struct thread_info, cpu));
+	DEFINE(TI_PRE_COUNT,	offsetof(struct thread_info, preempt_count));
+	DEFINE(TI_RESTART_BLOCK,offsetof(struct thread_info, restart_block));
+
+	return 0;
+}
diff --git a/arch/sh/kernel/entry.S b/arch/sh/kernel/entry.S
index 05dcc2e01fc1..bb451cb48386 100644
--- a/arch/sh/kernel/entry.S
+++ b/arch/sh/kernel/entry.S
@@ -14,6 +14,7 @@
 #include <linux/sys.h>
 #include <linux/linkage.h>
 #include <linux/config.h>
+#include <asm/asm-offsets.h>
 #include <asm/thread_info.h>
 #include <asm/unistd.h>
 
diff --git a/include/asm-sh/thread_info.h b/include/asm-sh/thread_info.h
index a4a70df910f0..3bac2a5a5656 100644
--- a/include/asm-sh/thread_info.h
+++ b/include/asm-sh/thread_info.h
@@ -25,16 +25,6 @@ struct thread_info {
 	__u8			supervisor_stack[0];
 };
 
-#else /* !__ASSEMBLY__ */
-
-/* offsets into the thread_info struct for assembly code access */
-#define TI_TASK		0x00000000
-#define TI_EXEC_DOMAIN	0x00000004
-#define TI_FLAGS	0x00000008
-#define TI_CPU		0x0000000c
-#define TI_PRE_COUNT	0x00000010
-#define TI_RESTART_BLOCK 0x00000014
-
 #endif
 
 #define PREEMPT_ACTIVE		0x4000000
-- 
2.30.9