1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/patches/linux/2.6.8/linux-2.6.8-m68k-kludge.patch Sun May 20 09:27:05 2007 +0000
1.3 @@ -0,0 +1,285 @@
1.4 +[ This patch not accepted into kernel for now - it touches the core too much -
1.5 + but it's ok for crosstool since we just want to check whether toolchain is ok,
1.6 + I think. I had to rediff the sched.h changes with -U5 to get them to
1.7 + apply properly -- patch got confused with just three lines of context?! -dank ]
1.8 +
1.9 +Date: Sun, 5 Sep 2004 12:41:08 +0200 (CEST)
1.10 +From: Geert Uytterhoeven <geert@linux-m68k.org>
1.11 +Sender: geert@linux-m68k.org
1.12 +To: Dan Kegel <dank@kegel.com>
1.13 +cc: Roman Zippel <zippel@linux-m68k.org>,
1.14 + Matthias Urlichs <smurf@smurf.noris.de>,
1.15 + Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
1.16 + Linux/m68k <linux-m68k@lists.linux-m68k.org>
1.17 +Subject: Re: Getting kernel.org kernel to build for m68k?
1.18 +In-Reply-To: <Pine.GSO.4.58.0409011029390.15681@waterleaf.sonytel.be>
1.19 +Message-ID: <Pine.LNX.4.58.0409051224020.30282@anakin>
1.20 +
1.21 +On Wed, 1 Sep 2004, Geert Uytterhoeven wrote:
1.22 +> On Tue, 31 Aug 2004, Dan Kegel wrote:
1.23 +> > I noticed today that Linus's m68k kernel can't be built (at least with gcc-3.4.1).
1.24 +> >
1.25 +> > The first problem I ran into,
1.26 +> > CC arch/m68k/kernel/asm-offsets.s
1.27 +> > In file included from include/linux/spinlock.h:12,
1.28 +> > from include/linux/capability.h:45,
1.29 +> > from include/linux/sched.h:7,
1.30 +> > from arch/m68k/kernel/asm-offsets.c:12:
1.31 +> > include/linux/thread_info.h:30: error: parse error before '{' token
1.32 +> > is solved already in the m68k tree.
1.33 +> > (In particular,
1.34 +> > the #ifndef __HAVE_THREAD_FUNCTIONS ... #endif in
1.35 +> > http://linux-m68k-cvs.apia.dhs.org/c/cvsweb/linux/include/linux/thread_info.h?rev=1.5;content-type=text%2Fplain
1.36 +> > probably solves it.)
1.37 +> > There are other problems after that.
1.38 +>
1.39 +> Roman Zippel changed the threading stuff on m68k. Since it would affect other
1.40 +> architectures, I never submitted it on my own.
1.41 +>
1.42 +> In short, we never really compile this code, since the m68k tree doesn't use it
1.43 +> anymore. And yes, it even fails with older compiler versions, like 2.95.2.
1.44 +
1.45 +The second part doesn't seem to be true: the code is used. And it does compile
1.46 +after applying the fixes below, even with gcc 3.4.1.
1.47 +
1.48 +> > Any chance you could spend a bit of time sending Linus enough
1.49 +> > patches for his kernel to build for m68k, if not run?
1.50 +>
1.51 +> I'll make sure a plain kernel.org kernel can build an m68k kernel.
1.52 +
1.53 +The patch below makes the plain kernel.org 2.6.8.1 compile for m68k,
1.54 +using gcc 2.95.2 or 3.3.3 (3.4.1 needs a few more changes in random
1.55 +places). The resulting kernel (I booted the gcc 2.95.2 case) works fine on my
1.56 +Amiga.
1.57 +
1.58 +It's more or less the patch created by Matthias Urlichs last year, so
1.59 +the credits are his:
1.60 +
1.61 +| This change implements a reasonable compromise between the task_info->flags
1.62 +| variable in other ports, which is too much work in the syscall path on m68k,
1.63 +| and moving the whole structure to thread_struct, which is way too intrusive
1.64 +| on other ports.
1.65 +
1.66 +The patch does affect generic code a bit, but the collateral damage is
1.67 +kept to a minimum.
1.68 +
1.69 +We can still keep Roman's thread info abstractions[*] in Linux/m68k CVS, but
1.70 +I'd really like the plain kernel.org kernel to be in a working state as well.
1.71 +That way more people may do cross-compile tests for m68k.
1.72 +
1.73 +Hence if no one objects, I'll submit the patch to Andrew and Linus.
1.74 +
1.75 +All comments are welcome!
1.76 +
1.77 +--- linux-2.6.8.1/arch/m68k/kernel/asm-offsets.c 2004-04-28 15:48:59.000000000 +0200
1.78 ++++ linux-m68k-2.6.8.1/arch/m68k/kernel/asm-offsets.c 2004-09-05 12:04:00.000000000 +0200
1.79 +@@ -31,6 +31,7 @@ int main(void)
1.80 + DEFINE(TASK_SIGPENDING, offsetof(struct task_struct, thread.work.sigpending));
1.81 + DEFINE(TASK_NOTIFY_RESUME, offsetof(struct task_struct, thread.work.notify_resume));
1.82 + DEFINE(TASK_THREAD, offsetof(struct task_struct, thread));
1.83 ++ DEFINE(TASK_TINFO, offsetof(struct task_struct, thread_info));
1.84 + DEFINE(TASK_MM, offsetof(struct task_struct, mm));
1.85 + DEFINE(TASK_ACTIVE_MM, offsetof(struct task_struct, active_mm));
1.86 +
1.87 +@@ -45,6 +46,9 @@ int main(void)
1.88 + DEFINE(THREAD_FPCNTL, offsetof(struct thread_struct, fpcntl));
1.89 + DEFINE(THREAD_FPSTATE, offsetof(struct thread_struct, fpstate));
1.90 +
1.91 ++ /* offsets into the thread_info struct */
1.92 ++ DEFINE(TINFO_PREEMPT, offsetof(struct thread_info, preempt_count));
1.93 ++
1.94 + /* offsets into the pt_regs */
1.95 + DEFINE(PT_D0, offsetof(struct pt_regs, d0));
1.96 + DEFINE(PT_ORIG_D0, offsetof(struct pt_regs, orig_d0));
1.97 +--- linux-2.6.8.1/arch/m68k/kernel/entry.S 2004-05-24 11:13:22.000000000 +0200
1.98 ++++ linux-m68k-2.6.8.1/arch/m68k/kernel/entry.S 2004-09-02 20:13:12.000000000 +0200
1.99 +@@ -134,13 +134,13 @@ ENTRY(system_call)
1.100 +
1.101 + syscall_exit_work:
1.102 + btst #5,%sp@(PT_SR) | check if returning to kernel
1.103 +- bnes 1b | if so, skip resched, signals
1.104 ++ bnes 1b | if so, skip everything
1.105 + tstw %d0
1.106 +- jeq do_signal_return
1.107 ++ jeq do_signal_return | jump if only sig_pending or notify_resume
1.108 + tstb %d0
1.109 +- jne do_delayed_trace
1.110 ++ jne do_delayed_trace | jump if delayed_trace
1.111 +
1.112 +- pea resume_userspace
1.113 ++ pea resume_userspace | need_resched is set
1.114 + jmp schedule
1.115 +
1.116 + ret_from_exception:
1.117 +@@ -223,10 +223,14 @@ ENTRY(nmi_handler)
1.118 + */
1.119 + inthandler:
1.120 + SAVE_ALL_INT
1.121 +- GET_CURRENT(%d0)
1.122 +- addqb #1,%curptr@(TASK_INFO+TINFO_PREEMPT+2)
1.123 +- | put exception # in d0
1.124 +- bfextu %sp@(PT_VECTOR){#4,#10},%d0
1.125 ++ /* GET_CURRENT(%d0) */
1.126 ++ movel %sp,%d0
1.127 ++ andw #-THREAD_SIZE,%d0
1.128 ++ movel %d0,%a1
1.129 ++ addqb #1,%a1@(TINFO_PREEMPT+2)
1.130 ++ movel %a1@,%curptr
1.131 ++
1.132 ++ bfextu %sp@(PT_VECTOR){#4,#10},%d0 | put exception # in d0
1.133 +
1.134 + movel %sp,%sp@-
1.135 + movel %d0,%sp@- | put vector # on stack
1.136 +@@ -243,7 +247,8 @@ inthandler:
1.137 + 3: addql #8,%sp | pop parameters off stack
1.138 +
1.139 + ret_from_interrupt:
1.140 +- subqb #1,%curptr@(TASK_INFO+TINFO_PREEMPT+2)
1.141 ++ movel %curptr@(TASK_TINFO),%a1
1.142 ++ subqb #1,%a1@(TINFO_PREEMPT+2)
1.143 + jeq 1f
1.144 + 2:
1.145 + RESTORE_ALL
1.146 +--- linux-2.6.8.1/include/asm-m68k/processor.h 2004-04-28 15:49:03.000000000 +0200
1.147 ++++ linux-m68k-2.6.8.1/include/asm-m68k/processor.h 2004-09-02 20:29:32.000000000 +0200
1.148 +@@ -84,7 +84,6 @@ struct thread_struct {
1.149 + ksp: sizeof(init_stack) + (unsigned long) init_stack, \
1.150 + sr: PS_S, \
1.151 + fs: __KERNEL_DS, \
1.152 +- info: INIT_THREAD_INFO(init_task) \
1.153 + }
1.154 +
1.155 + /*
1.156 +--- linux-2.6.8.1/include/asm-m68k/thread_info.h 2004-05-24 11:13:53.000000000 +0200
1.157 ++++ linux-m68k-2.6.8.1/include/asm-m68k/thread_info.h 2004-09-05 12:19:47.000000000 +0200
1.158 +@@ -6,7 +6,7 @@
1.159 + #include <asm/page.h>
1.160 +
1.161 + struct thread_info {
1.162 +- struct task_struct *task; /* main task structure */
1.163 ++ struct task_struct *task; /* main task structure, must be first! */
1.164 + struct exec_domain *exec_domain; /* execution domain */
1.165 + __s32 preempt_count; /* 0 => preemptable, <0 => BUG */
1.166 + __u32 cpu; /* should always be 0 on m68k */
1.167 +@@ -21,7 +21,8 @@ struct thread_info {
1.168 + { \
1.169 + .task = &tsk, \
1.170 + .exec_domain = &default_exec_domain, \
1.171 +- .restart_block = { \
1.172 ++ .preempt_count = 1, \
1.173 ++ .restart_block = { \
1.174 + .fn = do_no_restart_syscall, \
1.175 + }, \
1.176 + }
1.177 +@@ -35,10 +36,11 @@ struct thread_info {
1.178 + #define free_thread_info(ti) free_pages((unsigned long)(ti),1)
1.179 + #endif /* PAGE_SHIFT == 13 */
1.180 +
1.181 +-//#define init_thread_info (init_task.thread.info)
1.182 ++#define init_thread_info (init_thread_union.thread_info)
1.183 + #define init_stack (init_thread_union.stack)
1.184 +
1.185 +-#define current_thread_info() (current->thread_info)
1.186 ++register __u32 current_thread_info_reg asm("sp");
1.187 ++#define current_thread_info() ((struct thread_info *)(current_thread_info_reg & ~0x1fff))
1.188 +
1.189 +
1.190 + #define __HAVE_THREAD_FUNCTIONS
1.191 +@@ -91,8 +93,12 @@ extern int thread_flag_fixme(void);
1.192 + })
1.193 +
1.194 + #define __get_set_tsk_thread_flag(tsk, flag, val) ({ \
1.195 +- int __res = __get_tsk_thread_flag(tsk, flag); \
1.196 ++ int __res; \
1.197 ++ unsigned long __flags; \
1.198 ++ local_irq_save(__flags); \
1.199 ++ __res = __get_tsk_thread_flag(tsk, flag); \
1.200 + __set_tsk_thread_flag(tsk, flag, val); \
1.201 ++ local_irq_restore(__flags); \
1.202 + __res; \
1.203 + })
1.204 +
1.205 +@@ -105,7 +111,4 @@ extern int thread_flag_fixme(void);
1.206 + #define clear_thread_flag(flag) clear_tsk_thread_flag(current, flag)
1.207 + #define test_thread_flag(flag) test_tsk_thread_flag(current, flag)
1.208 +
1.209 +-#define set_need_resched() set_thread_flag(TIF_NEED_RESCHED)
1.210 +-#define clear_need_resched() clear_thread_flag(TIF_NEED_RESCHED)
1.211 +-
1.212 + #endif /* _ASM_M68K_THREAD_INFO_H */
1.213 +--- linux-2.6.8/include/linux/sched.h.old 2004-09-13 21:48:58.000000000 -0700
1.214 ++++ linux-2.6.8/include/linux/sched.h 2004-09-13 21:50:26.000000000 -0700
1.215 +@@ -975,10 +975,11 @@
1.216 + task_unlock(task);
1.217 +
1.218 + return mm;
1.219 + }
1.220 +
1.221 ++#ifndef __HAVE_THREAD_FUNCTIONS
1.222 +
1.223 + /* set thread flags in other task's structures
1.224 + * - see asm/thread_info.h for TIF_xxxx flags available
1.225 + */
1.226 + static inline void set_tsk_thread_flag(struct task_struct *tsk, int flag)
1.227 +@@ -1004,10 +1005,12 @@
1.228 + static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)
1.229 + {
1.230 + return test_ti_thread_flag(tsk->thread_info,flag);
1.231 + }
1.232 +
1.233 ++#endif /* __HAVE_THREAD_FUNCTIONS */
1.234 ++
1.235 + static inline void set_tsk_need_resched(struct task_struct *tsk)
1.236 + {
1.237 + set_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
1.238 + }
1.239 +
1.240 +--- linux-2.6.8.1/include/linux/thread_info.h 2004-04-27 20:42:22.000000000 +0200
1.241 ++++ linux-m68k-2.6.8.1/include/linux/thread_info.h 2004-09-04 21:24:36.000000000 +0200
1.242 +@@ -21,6 +21,7 @@ extern long do_no_restart_syscall(struct
1.243 + #include <asm/thread_info.h>
1.244 +
1.245 + #ifdef __KERNEL__
1.246 ++#ifndef __HAVE_THREAD_FUNCTIONS
1.247 +
1.248 + /*
1.249 + * flag set/clear/test wrappers
1.250 +@@ -77,16 +78,11 @@ static inline int test_ti_thread_flag(st
1.251 + return test_bit(flag,&ti->flags);
1.252 + }
1.253 +
1.254 +-static inline void set_need_resched(void)
1.255 +-{
1.256 +- set_thread_flag(TIF_NEED_RESCHED);
1.257 +-}
1.258 ++#endif /* __HAVE_THREAD_FUNCTIONS */
1.259 +
1.260 +-static inline void clear_need_resched(void)
1.261 +-{
1.262 +- clear_thread_flag(TIF_NEED_RESCHED);
1.263 +-}
1.264 ++#define set_need_resched() set_thread_flag(TIF_NEED_RESCHED)
1.265 ++#define clear_need_resched(void) clear_thread_flag(TIF_NEED_RESCHED)
1.266 +
1.267 +-#endif
1.268 ++#endif /* __KERNEL__ */
1.269 +
1.270 + #endif /* _LINUX_THREAD_INFO_H */
1.271 +
1.272 +Gr{oetje,eeting}s,
1.273 +
1.274 + Geert
1.275 +
1.276 +[*] For reference:
1.277 +
1.278 + http://linux-m68k-cvs.ubb.ca/~geert/linux-m68k-2.6.x-merging/POSTPONED/156-thread_info.diff
1.279 +
1.280 +--
1.281 +Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
1.282 +
1.283 +In personal conversations with technical people, I call myself a hacker. But
1.284 +when I'm talking to journalists I just say "programmer" or something like that.
1.285 + -- Linus Torvalds
1.286 +
1.287 +
1.288 +