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