patches/linux/2.6.8/140-linux-2.6.8-m68k-kludge.patch
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Sep 23 17:08:09 2007 +0000 (2007-09-23)
changeset 402 197e1b49586e
permissions -rw-r--r--
Renamed all patches file names so that locales are now irrelevant to sort the files.
Removed the locale check as it is now irrelevant.
Removed the experimental binutils 2.17.50.0.xx: 2.18 is here now.
yann@402
     1
[ This patch not accepted into kernel for now - it touches the core too much -
yann@402
     2
  but it's ok for crosstool since we just want to check whether toolchain is ok,
yann@402
     3
  I think.    I had to rediff the sched.h changes with -U5 to get them to
yann@402
     4
  apply properly -- patch got confused with just three lines of context?!  -dank ]
yann@402
     5
yann@402
     6
Date: Sun, 5 Sep 2004 12:41:08 +0200 (CEST)
yann@402
     7
From: Geert Uytterhoeven <geert@linux-m68k.org>
yann@402
     8
Sender: geert@linux-m68k.org
yann@402
     9
To: Dan Kegel <dank@kegel.com>
yann@402
    10
cc: Roman Zippel <zippel@linux-m68k.org>,
yann@402
    11
  Matthias Urlichs <smurf@smurf.noris.de>,
yann@402
    12
  Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
yann@402
    13
  Linux/m68k <linux-m68k@lists.linux-m68k.org>
yann@402
    14
Subject: Re: Getting kernel.org kernel to build for m68k?
yann@402
    15
In-Reply-To: <Pine.GSO.4.58.0409011029390.15681@waterleaf.sonytel.be>
yann@402
    16
Message-ID: <Pine.LNX.4.58.0409051224020.30282@anakin>
yann@402
    17
yann@402
    18
On Wed, 1 Sep 2004, Geert Uytterhoeven wrote:
yann@402
    19
> On Tue, 31 Aug 2004, Dan Kegel wrote:
yann@402
    20
> > I noticed today that Linus's m68k kernel can't be built (at least with gcc-3.4.1).
yann@402
    21
> >
yann@402
    22
> > The first problem I ran into,
yann@402
    23
> >    CC      arch/m68k/kernel/asm-offsets.s
yann@402
    24
> >    In file included from include/linux/spinlock.h:12,
yann@402
    25
> >                   from include/linux/capability.h:45,
yann@402
    26
> >                   from include/linux/sched.h:7,
yann@402
    27
> >                   from arch/m68k/kernel/asm-offsets.c:12:
yann@402
    28
> >    include/linux/thread_info.h:30: error: parse error before '{' token
yann@402
    29
> > is solved already in the m68k tree.
yann@402
    30
> > (In particular,
yann@402
    31
> > the #ifndef __HAVE_THREAD_FUNCTIONS ... #endif in
yann@402
    32
> > http://linux-m68k-cvs.apia.dhs.org/c/cvsweb/linux/include/linux/thread_info.h?rev=1.5;content-type=text%2Fplain
yann@402
    33
> > probably solves it.)
yann@402
    34
> > There are other problems after that.
yann@402
    35
>
yann@402
    36
> Roman Zippel changed the threading stuff on m68k. Since it would affect other
yann@402
    37
> architectures, I never submitted it on my own.
yann@402
    38
>
yann@402
    39
> In short, we never really compile this code, since the m68k tree doesn't use it
yann@402
    40
> anymore. And yes, it even fails with older compiler versions, like 2.95.2.
yann@402
    41
yann@402
    42
The second part doesn't seem to be true: the code is used. And it does compile
yann@402
    43
after applying the fixes below, even with gcc 3.4.1.
yann@402
    44
yann@402
    45
> > Any chance you could spend a bit of time sending Linus enough
yann@402
    46
> > patches for his kernel to build for m68k, if not run?
yann@402
    47
>
yann@402
    48
> I'll make sure a plain kernel.org kernel can build an m68k kernel.
yann@402
    49
yann@402
    50
The patch below makes the plain kernel.org 2.6.8.1 compile for m68k,
yann@402
    51
using gcc 2.95.2 or 3.3.3 (3.4.1 needs a few more changes in random
yann@402
    52
places). The resulting kernel (I booted the gcc 2.95.2 case) works fine on my
yann@402
    53
Amiga.
yann@402
    54
yann@402
    55
It's more or less the patch created by Matthias Urlichs last year, so
yann@402
    56
the credits are his:
yann@402
    57
yann@402
    58
| This change implements a reasonable compromise between the task_info->flags
yann@402
    59
| variable in other ports, which is too much work in the syscall path on m68k,
yann@402
    60
| and moving the whole structure to thread_struct, which is way too intrusive
yann@402
    61
| on other ports.
yann@402
    62
yann@402
    63
The patch does affect generic code a bit, but the collateral damage is
yann@402
    64
kept to a minimum.
yann@402
    65
yann@402
    66
We can still keep Roman's thread info abstractions[*] in Linux/m68k CVS, but
yann@402
    67
I'd really like the plain kernel.org kernel to be in a working state as well.
yann@402
    68
That way more people may do cross-compile tests for m68k.
yann@402
    69
yann@402
    70
Hence if no one objects, I'll submit the patch to Andrew and Linus.
yann@402
    71
yann@402
    72
All comments are welcome!
yann@402
    73
yann@402
    74
--- linux-2.6.8.1/arch/m68k/kernel/asm-offsets.c	2004-04-28 15:48:59.000000000 +0200
yann@402
    75
+++ linux-m68k-2.6.8.1/arch/m68k/kernel/asm-offsets.c	2004-09-05 12:04:00.000000000 +0200
yann@402
    76
@@ -31,6 +31,7 @@ int main(void)
yann@402
    77
 	DEFINE(TASK_SIGPENDING, offsetof(struct task_struct, thread.work.sigpending));
yann@402
    78
 	DEFINE(TASK_NOTIFY_RESUME, offsetof(struct task_struct, thread.work.notify_resume));
yann@402
    79
 	DEFINE(TASK_THREAD, offsetof(struct task_struct, thread));
yann@402
    80
+	DEFINE(TASK_TINFO, offsetof(struct task_struct, thread_info));
yann@402
    81
 	DEFINE(TASK_MM, offsetof(struct task_struct, mm));
yann@402
    82
 	DEFINE(TASK_ACTIVE_MM, offsetof(struct task_struct, active_mm));
yann@402
    83
yann@402
    84
@@ -45,6 +46,9 @@ int main(void)
yann@402
    85
 	DEFINE(THREAD_FPCNTL, offsetof(struct thread_struct, fpcntl));
yann@402
    86
 	DEFINE(THREAD_FPSTATE, offsetof(struct thread_struct, fpstate));
yann@402
    87
yann@402
    88
+	/* offsets into the thread_info struct */
yann@402
    89
+	DEFINE(TINFO_PREEMPT, offsetof(struct thread_info, preempt_count));
yann@402
    90
+
yann@402
    91
 	/* offsets into the pt_regs */
yann@402
    92
 	DEFINE(PT_D0, offsetof(struct pt_regs, d0));
yann@402
    93
 	DEFINE(PT_ORIG_D0, offsetof(struct pt_regs, orig_d0));
yann@402
    94
--- linux-2.6.8.1/arch/m68k/kernel/entry.S	2004-05-24 11:13:22.000000000 +0200
yann@402
    95
+++ linux-m68k-2.6.8.1/arch/m68k/kernel/entry.S	2004-09-02 20:13:12.000000000 +0200
yann@402
    96
@@ -134,13 +134,13 @@ ENTRY(system_call)
yann@402
    97
yann@402
    98
 syscall_exit_work:
yann@402
    99
 	btst	#5,%sp@(PT_SR)		| check if returning to kernel
yann@402
   100
-	bnes	1b			| if so, skip resched, signals
yann@402
   101
+	bnes	1b			| if so, skip everything
yann@402
   102
 	tstw	%d0
yann@402
   103
-	jeq	do_signal_return
yann@402
   104
+	jeq	do_signal_return | jump if only sig_pending or notify_resume
yann@402
   105
 	tstb	%d0
yann@402
   106
-	jne	do_delayed_trace
yann@402
   107
+	jne	do_delayed_trace | jump if delayed_trace
yann@402
   108
yann@402
   109
-	pea	resume_userspace
yann@402
   110
+	pea	resume_userspace | need_resched is set
yann@402
   111
 	jmp	schedule
yann@402
   112
yann@402
   113
 ret_from_exception:
yann@402
   114
@@ -223,10 +223,14 @@ ENTRY(nmi_handler)
yann@402
   115
 */
yann@402
   116
 inthandler:
yann@402
   117
 	SAVE_ALL_INT
yann@402
   118
-	GET_CURRENT(%d0)
yann@402
   119
-	addqb	#1,%curptr@(TASK_INFO+TINFO_PREEMPT+2)
yann@402
   120
-					|  put exception # in d0
yann@402
   121
-	bfextu %sp@(PT_VECTOR){#4,#10},%d0
yann@402
   122
+	/* GET_CURRENT(%d0) */
yann@402
   123
+	movel	%sp,%d0
yann@402
   124
+	andw	#-THREAD_SIZE,%d0
yann@402
   125
+	movel	%d0,%a1
yann@402
   126
+	addqb	#1,%a1@(TINFO_PREEMPT+2)
yann@402
   127
+	movel	%a1@,%curptr
yann@402
   128
+
yann@402
   129
+	bfextu	%sp@(PT_VECTOR){#4,#10},%d0 |  put exception # in d0
yann@402
   130
yann@402
   131
 	movel	%sp,%sp@-
yann@402
   132
 	movel	%d0,%sp@-		|  put vector # on stack
yann@402
   133
@@ -243,7 +247,8 @@ inthandler:
yann@402
   134
 3:	addql	#8,%sp			|  pop parameters off stack
yann@402
   135
yann@402
   136
 ret_from_interrupt:
yann@402
   137
-	subqb	#1,%curptr@(TASK_INFO+TINFO_PREEMPT+2)
yann@402
   138
+	movel	%curptr@(TASK_TINFO),%a1
yann@402
   139
+	subqb	#1,%a1@(TINFO_PREEMPT+2)
yann@402
   140
 	jeq	1f
yann@402
   141
 2:
yann@402
   142
 	RESTORE_ALL
yann@402
   143
--- linux-2.6.8.1/include/asm-m68k/processor.h	2004-04-28 15:49:03.000000000 +0200
yann@402
   144
+++ linux-m68k-2.6.8.1/include/asm-m68k/processor.h	2004-09-02 20:29:32.000000000 +0200
yann@402
   145
@@ -84,7 +84,6 @@ struct thread_struct {
yann@402
   146
 	ksp:	sizeof(init_stack) + (unsigned long) init_stack,	\
yann@402
   147
 	sr:	PS_S,							\
yann@402
   148
 	fs:	__KERNEL_DS,						\
yann@402
   149
-	info:	INIT_THREAD_INFO(init_task)				\
yann@402
   150
 }
yann@402
   151
yann@402
   152
 /*
yann@402
   153
--- linux-2.6.8.1/include/asm-m68k/thread_info.h	2004-05-24 11:13:53.000000000 +0200
yann@402
   154
+++ linux-m68k-2.6.8.1/include/asm-m68k/thread_info.h	2004-09-05 12:19:47.000000000 +0200
yann@402
   155
@@ -6,7 +6,7 @@
yann@402
   156
 #include <asm/page.h>
yann@402
   157
yann@402
   158
 struct thread_info {
yann@402
   159
-	struct task_struct	*task;		/* main task structure */
yann@402
   160
+	struct task_struct	*task;		/* main task structure, must be first! */
yann@402
   161
 	struct exec_domain	*exec_domain;	/* execution domain */
yann@402
   162
 	__s32			preempt_count; /* 0 => preemptable, <0 => BUG */
yann@402
   163
 	__u32 cpu; /* should always be 0 on m68k */
yann@402
   164
@@ -21,7 +21,8 @@ struct thread_info {
yann@402
   165
 {						\
yann@402
   166
 	.task		= &tsk,			\
yann@402
   167
 	.exec_domain	= &default_exec_domain,	\
yann@402
   168
-	.restart_block = {			\
yann@402
   169
+	.preempt_count	= 1,			\
yann@402
   170
+	.restart_block	= {			\
yann@402
   171
 		.fn = do_no_restart_syscall,	\
yann@402
   172
 	},					\
yann@402
   173
 }
yann@402
   174
@@ -35,10 +36,11 @@ struct thread_info {
yann@402
   175
 #define free_thread_info(ti)  free_pages((unsigned long)(ti),1)
yann@402
   176
 #endif /* PAGE_SHIFT == 13 */
yann@402
   177
yann@402
   178
-//#define init_thread_info	(init_task.thread.info)
yann@402
   179
+#define init_thread_info	(init_thread_union.thread_info)
yann@402
   180
 #define init_stack		(init_thread_union.stack)
yann@402
   181
yann@402
   182
-#define current_thread_info()	(current->thread_info)
yann@402
   183
+register __u32 current_thread_info_reg asm("sp");
yann@402
   184
+#define current_thread_info()	((struct thread_info *)(current_thread_info_reg & ~0x1fff))
yann@402
   185
yann@402
   186
yann@402
   187
 #define __HAVE_THREAD_FUNCTIONS
yann@402
   188
@@ -91,8 +93,12 @@ extern int thread_flag_fixme(void);
yann@402
   189
 })
yann@402
   190
yann@402
   191
 #define __get_set_tsk_thread_flag(tsk, flag, val) ({	\
yann@402
   192
-	int __res = __get_tsk_thread_flag(tsk, flag);	\
yann@402
   193
+	int __res;					\
yann@402
   194
+	unsigned long __flags; \
yann@402
   195
+	local_irq_save(__flags);  \
yann@402
   196
+	__res = __get_tsk_thread_flag(tsk, flag);	\
yann@402
   197
 	__set_tsk_thread_flag(tsk, flag, val);		\
yann@402
   198
+	local_irq_restore(__flags);  \
yann@402
   199
 	__res;						\
yann@402
   200
 })
yann@402
   201
yann@402
   202
@@ -105,7 +111,4 @@ extern int thread_flag_fixme(void);
yann@402
   203
 #define clear_thread_flag(flag) clear_tsk_thread_flag(current, flag)
yann@402
   204
 #define test_thread_flag(flag) test_tsk_thread_flag(current, flag)
yann@402
   205
yann@402
   206
-#define set_need_resched() set_thread_flag(TIF_NEED_RESCHED)
yann@402
   207
-#define clear_need_resched() clear_thread_flag(TIF_NEED_RESCHED)
yann@402
   208
-
yann@402
   209
 #endif	/* _ASM_M68K_THREAD_INFO_H */
yann@402
   210
--- linux-2.6.8/include/linux/sched.h.old	2004-09-13 21:48:58.000000000 -0700
yann@402
   211
+++ linux-2.6.8/include/linux/sched.h	2004-09-13 21:50:26.000000000 -0700
yann@402
   212
@@ -975,10 +975,11 @@
yann@402
   213
 	task_unlock(task);
yann@402
   214
 
yann@402
   215
 	return mm;
yann@402
   216
 }
yann@402
   217
  
yann@402
   218
+#ifndef __HAVE_THREAD_FUNCTIONS
yann@402
   219
  
yann@402
   220
 /* set thread flags in other task's structures
yann@402
   221
  * - see asm/thread_info.h for TIF_xxxx flags available
yann@402
   222
  */
yann@402
   223
 static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
yann@402
   224
@@ -1004,10 +1005,12 @@
yann@402
   225
 static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
yann@402
   226
 {
yann@402
   227
 	return test_ti_thread_flag(tsk->thread_info,flag);
yann@402
   228
 }
yann@402
   229
 
yann@402
   230
+#endif	/* __HAVE_THREAD_FUNCTIONS */
yann@402
   231
+
yann@402
   232
 static inline void set_tsk_need_resched(struct task_struct *tsk)
yann@402
   233
 {
yann@402
   234
 	set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
yann@402
   235
 }
yann@402
   236
 
yann@402
   237
--- linux-2.6.8.1/include/linux/thread_info.h	2004-04-27 20:42:22.000000000 +0200
yann@402
   238
+++ linux-m68k-2.6.8.1/include/linux/thread_info.h	2004-09-04 21:24:36.000000000 +0200
yann@402
   239
@@ -21,6 +21,7 @@ extern long do_no_restart_syscall(struct
yann@402
   240
 #include <asm/thread_info.h>
yann@402
   241
yann@402
   242
 #ifdef __KERNEL__
yann@402
   243
+#ifndef __HAVE_THREAD_FUNCTIONS
yann@402
   244
yann@402
   245
 /*
yann@402
   246
  * flag set/clear/test wrappers
yann@402
   247
@@ -77,16 +78,11 @@ static inline int test_ti_thread_flag(st
yann@402
   248
 	return test_bit(flag,&ti->flags);
yann@402
   249
 }
yann@402
   250
yann@402
   251
-static inline void set_need_resched(void)
yann@402
   252
-{
yann@402
   253
-	set_thread_flag(TIF_NEED_RESCHED);
yann@402
   254
-}
yann@402
   255
+#endif	/* __HAVE_THREAD_FUNCTIONS */
yann@402
   256
yann@402
   257
-static inline void clear_need_resched(void)
yann@402
   258
-{
yann@402
   259
-	clear_thread_flag(TIF_NEED_RESCHED);
yann@402
   260
-}
yann@402
   261
+#define set_need_resched() set_thread_flag(TIF_NEED_RESCHED)
yann@402
   262
+#define clear_need_resched(void) clear_thread_flag(TIF_NEED_RESCHED)
yann@402
   263
yann@402
   264
-#endif
yann@402
   265
+#endif	/* __KERNEL__ */
yann@402
   266
yann@402
   267
 #endif /* _LINUX_THREAD_INFO_H */
yann@402
   268
yann@402
   269
Gr{oetje,eeting}s,
yann@402
   270
yann@402
   271
						Geert
yann@402
   272
yann@402
   273
[*] For reference:
yann@402
   274
yann@402
   275
    http://linux-m68k-cvs.ubb.ca/~geert/linux-m68k-2.6.x-merging/POSTPONED/156-thread_info.diff
yann@402
   276
yann@402
   277
--
yann@402
   278
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
yann@402
   279
yann@402
   280
In personal conversations with technical people, I call myself a hacker. But
yann@402
   281
when I'm talking to journalists I just say "programmer" or something like that.
yann@402
   282
							    -- Linus Torvalds
yann@402
   283
yann@402
   284
yann@402
   285