diff options
author | Paul Mundt <lethal@linux-sh.org> | 2007-11-09 02:57:04 -0500 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2008-01-27 23:18:42 -0500 |
commit | fe51bc9eaf45253bd437907ed04031a93640ca69 (patch) | |
tree | c7faf184450049e166b2dc14564aa5b008660e27 /arch/sh | |
parent | 5055235554804b39c613ada76d7598c14265a00b (diff) |
sh: Split out arch/sh/kernel/process.c for _32 and _64 variants.
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'arch/sh')
-rw-r--r-- | arch/sh/kernel/Makefile_32 | 4 | ||||
-rw-r--r-- | arch/sh/kernel/process_32.c (renamed from arch/sh/kernel/process.c) | 0 | ||||
-rw-r--r-- | arch/sh/kernel/process_64.c | 691 |
3 files changed, 693 insertions, 2 deletions
diff --git a/arch/sh/kernel/Makefile_32 b/arch/sh/kernel/Makefile_32 index 4b81d9c47b00..9864be64b226 100644 --- a/arch/sh/kernel/Makefile_32 +++ b/arch/sh/kernel/Makefile_32 | |||
@@ -4,8 +4,8 @@ | |||
4 | 4 | ||
5 | extra-y := head.o init_task.o vmlinux.lds | 5 | extra-y := head.o init_task.o vmlinux.lds |
6 | 6 | ||
7 | obj-y := debugtraps.o io.o io_generic.o irq.o machvec.o process.o ptrace.o \ | 7 | obj-y := debugtraps.o io.o io_generic.o irq.o machvec.o process_32.o \ |
8 | semaphore.o setup.o signal.o sys_sh.o syscalls.o \ | 8 | ptrace.o semaphore.o setup.o signal.o sys_sh.o syscalls.o \ |
9 | time.o topology.o traps.o | 9 | time.o topology.o traps.o |
10 | 10 | ||
11 | obj-y += cpu/ timers/ | 11 | obj-y += cpu/ timers/ |
diff --git a/arch/sh/kernel/process.c b/arch/sh/kernel/process_32.c index 6d7f2b07e491..6d7f2b07e491 100644 --- a/arch/sh/kernel/process.c +++ b/arch/sh/kernel/process_32.c | |||
diff --git a/arch/sh/kernel/process_64.c b/arch/sh/kernel/process_64.c new file mode 100644 index 000000000000..0761af4d2a42 --- /dev/null +++ b/arch/sh/kernel/process_64.c | |||
@@ -0,0 +1,691 @@ | |||
1 | /* | ||
2 | * This file is subject to the terms and conditions of the GNU General Public | ||
3 | * License. See the file "COPYING" in the main directory of this archive | ||
4 | * for more details. | ||
5 | * | ||
6 | * arch/sh64/kernel/process.c | ||
7 | * | ||
8 | * Copyright (C) 2000, 2001 Paolo Alberelli | ||
9 | * Copyright (C) 2003 Paul Mundt | ||
10 | * Copyright (C) 2003, 2004 Richard Curnow | ||
11 | * | ||
12 | * Started from SH3/4 version: | ||
13 | * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima | ||
14 | * | ||
15 | * In turn started from i386 version: | ||
16 | * Copyright (C) 1995 Linus Torvalds | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | /* | ||
21 | * This file handles the architecture-dependent parts of process handling.. | ||
22 | */ | ||
23 | #include <linux/mm.h> | ||
24 | #include <linux/fs.h> | ||
25 | #include <linux/ptrace.h> | ||
26 | #include <linux/reboot.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/proc_fs.h> | ||
30 | #include <asm/uaccess.h> | ||
31 | #include <asm/pgtable.h> | ||
32 | |||
33 | struct task_struct *last_task_used_math = NULL; | ||
34 | |||
35 | static int hlt_counter = 1; | ||
36 | |||
37 | #define HARD_IDLE_TIMEOUT (HZ / 3) | ||
38 | |||
39 | void disable_hlt(void) | ||
40 | { | ||
41 | hlt_counter++; | ||
42 | } | ||
43 | |||
44 | void enable_hlt(void) | ||
45 | { | ||
46 | hlt_counter--; | ||
47 | } | ||
48 | |||
49 | static int __init nohlt_setup(char *__unused) | ||
50 | { | ||
51 | hlt_counter = 1; | ||
52 | return 1; | ||
53 | } | ||
54 | |||
55 | static int __init hlt_setup(char *__unused) | ||
56 | { | ||
57 | hlt_counter = 0; | ||
58 | return 1; | ||
59 | } | ||
60 | |||
61 | __setup("nohlt", nohlt_setup); | ||
62 | __setup("hlt", hlt_setup); | ||
63 | |||
64 | static inline void hlt(void) | ||
65 | { | ||
66 | __asm__ __volatile__ ("sleep" : : : "memory"); | ||
67 | } | ||
68 | |||
69 | /* | ||
70 | * The idle loop on a uniprocessor SH.. | ||
71 | */ | ||
72 | void cpu_idle(void) | ||
73 | { | ||
74 | /* endless idle loop with no priority at all */ | ||
75 | while (1) { | ||
76 | if (hlt_counter) { | ||
77 | while (!need_resched()) | ||
78 | cpu_relax(); | ||
79 | } else { | ||
80 | local_irq_disable(); | ||
81 | while (!need_resched()) { | ||
82 | local_irq_enable(); | ||
83 | hlt(); | ||
84 | local_irq_disable(); | ||
85 | } | ||
86 | local_irq_enable(); | ||
87 | } | ||
88 | preempt_enable_no_resched(); | ||
89 | schedule(); | ||
90 | preempt_disable(); | ||
91 | } | ||
92 | |||
93 | } | ||
94 | |||
95 | void machine_restart(char * __unused) | ||
96 | { | ||
97 | extern void phys_stext(void); | ||
98 | |||
99 | phys_stext(); | ||
100 | } | ||
101 | |||
102 | void machine_halt(void) | ||
103 | { | ||
104 | for (;;); | ||
105 | } | ||
106 | |||
107 | void machine_power_off(void) | ||
108 | { | ||
109 | extern void enter_deep_standby(void); | ||
110 | |||
111 | enter_deep_standby(); | ||
112 | } | ||
113 | |||
114 | void (*pm_power_off)(void) = machine_power_off; | ||
115 | EXPORT_SYMBOL(pm_power_off); | ||
116 | |||
117 | void show_regs(struct pt_regs * regs) | ||
118 | { | ||
119 | unsigned long long ah, al, bh, bl, ch, cl; | ||
120 | |||
121 | printk("\n"); | ||
122 | |||
123 | ah = (regs->pc) >> 32; | ||
124 | al = (regs->pc) & 0xffffffff; | ||
125 | bh = (regs->regs[18]) >> 32; | ||
126 | bl = (regs->regs[18]) & 0xffffffff; | ||
127 | ch = (regs->regs[15]) >> 32; | ||
128 | cl = (regs->regs[15]) & 0xffffffff; | ||
129 | printk("PC : %08Lx%08Lx LINK: %08Lx%08Lx SP : %08Lx%08Lx\n", | ||
130 | ah, al, bh, bl, ch, cl); | ||
131 | |||
132 | ah = (regs->sr) >> 32; | ||
133 | al = (regs->sr) & 0xffffffff; | ||
134 | asm volatile ("getcon " __TEA ", %0" : "=r" (bh)); | ||
135 | asm volatile ("getcon " __TEA ", %0" : "=r" (bl)); | ||
136 | bh = (bh) >> 32; | ||
137 | bl = (bl) & 0xffffffff; | ||
138 | asm volatile ("getcon " __KCR0 ", %0" : "=r" (ch)); | ||
139 | asm volatile ("getcon " __KCR0 ", %0" : "=r" (cl)); | ||
140 | ch = (ch) >> 32; | ||
141 | cl = (cl) & 0xffffffff; | ||
142 | printk("SR : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n", | ||
143 | ah, al, bh, bl, ch, cl); | ||
144 | |||
145 | ah = (regs->regs[0]) >> 32; | ||
146 | al = (regs->regs[0]) & 0xffffffff; | ||
147 | bh = (regs->regs[1]) >> 32; | ||
148 | bl = (regs->regs[1]) & 0xffffffff; | ||
149 | ch = (regs->regs[2]) >> 32; | ||
150 | cl = (regs->regs[2]) & 0xffffffff; | ||
151 | printk("R0 : %08Lx%08Lx R1 : %08Lx%08Lx R2 : %08Lx%08Lx\n", | ||
152 | ah, al, bh, bl, ch, cl); | ||
153 | |||
154 | ah = (regs->regs[3]) >> 32; | ||
155 | al = (regs->regs[3]) & 0xffffffff; | ||
156 | bh = (regs->regs[4]) >> 32; | ||
157 | bl = (regs->regs[4]) & 0xffffffff; | ||
158 | ch = (regs->regs[5]) >> 32; | ||
159 | cl = (regs->regs[5]) & 0xffffffff; | ||
160 | printk("R3 : %08Lx%08Lx R4 : %08Lx%08Lx R5 : %08Lx%08Lx\n", | ||
161 | ah, al, bh, bl, ch, cl); | ||
162 | |||
163 | ah = (regs->regs[6]) >> 32; | ||
164 | al = (regs->regs[6]) & 0xffffffff; | ||
165 | bh = (regs->regs[7]) >> 32; | ||
166 | bl = (regs->regs[7]) & 0xffffffff; | ||
167 | ch = (regs->regs[8]) >> 32; | ||
168 | cl = (regs->regs[8]) & 0xffffffff; | ||
169 | printk("R6 : %08Lx%08Lx R7 : %08Lx%08Lx R8 : %08Lx%08Lx\n", | ||
170 | ah, al, bh, bl, ch, cl); | ||
171 | |||
172 | ah = (regs->regs[9]) >> 32; | ||
173 | al = (regs->regs[9]) & 0xffffffff; | ||
174 | bh = (regs->regs[10]) >> 32; | ||
175 | bl = (regs->regs[10]) & 0xffffffff; | ||
176 | ch = (regs->regs[11]) >> 32; | ||
177 | cl = (regs->regs[11]) & 0xffffffff; | ||
178 | printk("R9 : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n", | ||
179 | ah, al, bh, bl, ch, cl); | ||
180 | |||
181 | ah = (regs->regs[12]) >> 32; | ||
182 | al = (regs->regs[12]) & 0xffffffff; | ||
183 | bh = (regs->regs[13]) >> 32; | ||
184 | bl = (regs->regs[13]) & 0xffffffff; | ||
185 | ch = (regs->regs[14]) >> 32; | ||
186 | cl = (regs->regs[14]) & 0xffffffff; | ||
187 | printk("R12 : %08Lx%08Lx R13 : %08Lx%08Lx R14 : %08Lx%08Lx\n", | ||
188 | ah, al, bh, bl, ch, cl); | ||
189 | |||
190 | ah = (regs->regs[16]) >> 32; | ||
191 | al = (regs->regs[16]) & 0xffffffff; | ||
192 | bh = (regs->regs[17]) >> 32; | ||
193 | bl = (regs->regs[17]) & 0xffffffff; | ||
194 | ch = (regs->regs[19]) >> 32; | ||
195 | cl = (regs->regs[19]) & 0xffffffff; | ||
196 | printk("R16 : %08Lx%08Lx R17 : %08Lx%08Lx R19 : %08Lx%08Lx\n", | ||
197 | ah, al, bh, bl, ch, cl); | ||
198 | |||
199 | ah = (regs->regs[20]) >> 32; | ||
200 | al = (regs->regs[20]) & 0xffffffff; | ||
201 | bh = (regs->regs[21]) >> 32; | ||
202 | bl = (regs->regs[21]) & 0xffffffff; | ||
203 | ch = (regs->regs[22]) >> 32; | ||
204 | cl = (regs->regs[22]) & 0xffffffff; | ||
205 | printk("R20 : %08Lx%08Lx R21 : %08Lx%08Lx R22 : %08Lx%08Lx\n", | ||
206 | ah, al, bh, bl, ch, cl); | ||
207 | |||
208 | ah = (regs->regs[23]) >> 32; | ||
209 | al = (regs->regs[23]) & 0xffffffff; | ||
210 | bh = (regs->regs[24]) >> 32; | ||
211 | bl = (regs->regs[24]) & 0xffffffff; | ||
212 | ch = (regs->regs[25]) >> 32; | ||
213 | cl = (regs->regs[25]) & 0xffffffff; | ||
214 | printk("R23 : %08Lx%08Lx R24 : %08Lx%08Lx R25 : %08Lx%08Lx\n", | ||
215 | ah, al, bh, bl, ch, cl); | ||
216 | |||
217 | ah = (regs->regs[26]) >> 32; | ||
218 | al = (regs->regs[26]) & 0xffffffff; | ||
219 | bh = (regs->regs[27]) >> 32; | ||
220 | bl = (regs->regs[27]) & 0xffffffff; | ||
221 | ch = (regs->regs[28]) >> 32; | ||
222 | cl = (regs->regs[28]) & 0xffffffff; | ||
223 | printk("R26 : %08Lx%08Lx R27 : %08Lx%08Lx R28 : %08Lx%08Lx\n", | ||
224 | ah, al, bh, bl, ch, cl); | ||
225 | |||
226 | ah = (regs->regs[29]) >> 32; | ||
227 | al = (regs->regs[29]) & 0xffffffff; | ||
228 | bh = (regs->regs[30]) >> 32; | ||
229 | bl = (regs->regs[30]) & 0xffffffff; | ||
230 | ch = (regs->regs[31]) >> 32; | ||
231 | cl = (regs->regs[31]) & 0xffffffff; | ||
232 | printk("R29 : %08Lx%08Lx R30 : %08Lx%08Lx R31 : %08Lx%08Lx\n", | ||
233 | ah, al, bh, bl, ch, cl); | ||
234 | |||
235 | ah = (regs->regs[32]) >> 32; | ||
236 | al = (regs->regs[32]) & 0xffffffff; | ||
237 | bh = (regs->regs[33]) >> 32; | ||
238 | bl = (regs->regs[33]) & 0xffffffff; | ||
239 | ch = (regs->regs[34]) >> 32; | ||
240 | cl = (regs->regs[34]) & 0xffffffff; | ||
241 | printk("R32 : %08Lx%08Lx R33 : %08Lx%08Lx R34 : %08Lx%08Lx\n", | ||
242 | ah, al, bh, bl, ch, cl); | ||
243 | |||
244 | ah = (regs->regs[35]) >> 32; | ||
245 | al = (regs->regs[35]) & 0xffffffff; | ||
246 | bh = (regs->regs[36]) >> 32; | ||
247 | bl = (regs->regs[36]) & 0xffffffff; | ||
248 | ch = (regs->regs[37]) >> 32; | ||
249 | cl = (regs->regs[37]) & 0xffffffff; | ||
250 | printk("R35 : %08Lx%08Lx R36 : %08Lx%08Lx R37 : %08Lx%08Lx\n", | ||
251 | ah, al, bh, bl, ch, cl); | ||
252 | |||
253 | ah = (regs->regs[38]) >> 32; | ||
254 | al = (regs->regs[38]) & 0xffffffff; | ||
255 | bh = (regs->regs[39]) >> 32; | ||
256 | bl = (regs->regs[39]) & 0xffffffff; | ||
257 | ch = (regs->regs[40]) >> 32; | ||
258 | cl = (regs->regs[40]) & 0xffffffff; | ||
259 | printk("R38 : %08Lx%08Lx R39 : %08Lx%08Lx R40 : %08Lx%08Lx\n", | ||
260 | ah, al, bh, bl, ch, cl); | ||
261 | |||
262 | ah = (regs->regs[41]) >> 32; | ||
263 | al = (regs->regs[41]) & 0xffffffff; | ||
264 | bh = (regs->regs[42]) >> 32; | ||
265 | bl = (regs->regs[42]) & 0xffffffff; | ||
266 | ch = (regs->regs[43]) >> 32; | ||
267 | cl = (regs->regs[43]) & 0xffffffff; | ||
268 | printk("R41 : %08Lx%08Lx R42 : %08Lx%08Lx R43 : %08Lx%08Lx\n", | ||
269 | ah, al, bh, bl, ch, cl); | ||
270 | |||
271 | ah = (regs->regs[44]) >> 32; | ||
272 | al = (regs->regs[44]) & 0xffffffff; | ||
273 | bh = (regs->regs[45]) >> 32; | ||
274 | bl = (regs->regs[45]) & 0xffffffff; | ||
275 | ch = (regs->regs[46]) >> 32; | ||
276 | cl = (regs->regs[46]) & 0xffffffff; | ||
277 | printk("R44 : %08Lx%08Lx R45 : %08Lx%08Lx R46 : %08Lx%08Lx\n", | ||
278 | ah, al, bh, bl, ch, cl); | ||
279 | |||
280 | ah = (regs->regs[47]) >> 32; | ||
281 | al = (regs->regs[47]) & 0xffffffff; | ||
282 | bh = (regs->regs[48]) >> 32; | ||
283 | bl = (regs->regs[48]) & 0xffffffff; | ||
284 | ch = (regs->regs[49]) >> 32; | ||
285 | cl = (regs->regs[49]) & 0xffffffff; | ||
286 | printk("R47 : %08Lx%08Lx R48 : %08Lx%08Lx R49 : %08Lx%08Lx\n", | ||
287 | ah, al, bh, bl, ch, cl); | ||
288 | |||
289 | ah = (regs->regs[50]) >> 32; | ||
290 | al = (regs->regs[50]) & 0xffffffff; | ||
291 | bh = (regs->regs[51]) >> 32; | ||
292 | bl = (regs->regs[51]) & 0xffffffff; | ||
293 | ch = (regs->regs[52]) >> 32; | ||
294 | cl = (regs->regs[52]) & 0xffffffff; | ||
295 | printk("R50 : %08Lx%08Lx R51 : %08Lx%08Lx R52 : %08Lx%08Lx\n", | ||
296 | ah, al, bh, bl, ch, cl); | ||
297 | |||
298 | ah = (regs->regs[53]) >> 32; | ||
299 | al = (regs->regs[53]) & 0xffffffff; | ||
300 | bh = (regs->regs[54]) >> 32; | ||
301 | bl = (regs->regs[54]) & 0xffffffff; | ||
302 | ch = (regs->regs[55]) >> 32; | ||
303 | cl = (regs->regs[55]) & 0xffffffff; | ||
304 | printk("R53 : %08Lx%08Lx R54 : %08Lx%08Lx R55 : %08Lx%08Lx\n", | ||
305 | ah, al, bh, bl, ch, cl); | ||
306 | |||
307 | ah = (regs->regs[56]) >> 32; | ||
308 | al = (regs->regs[56]) & 0xffffffff; | ||
309 | bh = (regs->regs[57]) >> 32; | ||
310 | bl = (regs->regs[57]) & 0xffffffff; | ||
311 | ch = (regs->regs[58]) >> 32; | ||
312 | cl = (regs->regs[58]) & 0xffffffff; | ||
313 | printk("R56 : %08Lx%08Lx R57 : %08Lx%08Lx R58 : %08Lx%08Lx\n", | ||
314 | ah, al, bh, bl, ch, cl); | ||
315 | |||
316 | ah = (regs->regs[59]) >> 32; | ||
317 | al = (regs->regs[59]) & 0xffffffff; | ||
318 | bh = (regs->regs[60]) >> 32; | ||
319 | bl = (regs->regs[60]) & 0xffffffff; | ||
320 | ch = (regs->regs[61]) >> 32; | ||
321 | cl = (regs->regs[61]) & 0xffffffff; | ||
322 | printk("R59 : %08Lx%08Lx R60 : %08Lx%08Lx R61 : %08Lx%08Lx\n", | ||
323 | ah, al, bh, bl, ch, cl); | ||
324 | |||
325 | ah = (regs->regs[62]) >> 32; | ||
326 | al = (regs->regs[62]) & 0xffffffff; | ||
327 | bh = (regs->tregs[0]) >> 32; | ||
328 | bl = (regs->tregs[0]) & 0xffffffff; | ||
329 | ch = (regs->tregs[1]) >> 32; | ||
330 | cl = (regs->tregs[1]) & 0xffffffff; | ||
331 | printk("R62 : %08Lx%08Lx T0 : %08Lx%08Lx T1 : %08Lx%08Lx\n", | ||
332 | ah, al, bh, bl, ch, cl); | ||
333 | |||
334 | ah = (regs->tregs[2]) >> 32; | ||
335 | al = (regs->tregs[2]) & 0xffffffff; | ||
336 | bh = (regs->tregs[3]) >> 32; | ||
337 | bl = (regs->tregs[3]) & 0xffffffff; | ||
338 | ch = (regs->tregs[4]) >> 32; | ||
339 | cl = (regs->tregs[4]) & 0xffffffff; | ||
340 | printk("T2 : %08Lx%08Lx T3 : %08Lx%08Lx T4 : %08Lx%08Lx\n", | ||
341 | ah, al, bh, bl, ch, cl); | ||
342 | |||
343 | ah = (regs->tregs[5]) >> 32; | ||
344 | al = (regs->tregs[5]) & 0xffffffff; | ||
345 | bh = (regs->tregs[6]) >> 32; | ||
346 | bl = (regs->tregs[6]) & 0xffffffff; | ||
347 | ch = (regs->tregs[7]) >> 32; | ||
348 | cl = (regs->tregs[7]) & 0xffffffff; | ||
349 | printk("T5 : %08Lx%08Lx T6 : %08Lx%08Lx T7 : %08Lx%08Lx\n", | ||
350 | ah, al, bh, bl, ch, cl); | ||
351 | |||
352 | /* | ||
353 | * If we're in kernel mode, dump the stack too.. | ||
354 | */ | ||
355 | if (!user_mode(regs)) { | ||
356 | void show_stack(struct task_struct *tsk, unsigned long *sp); | ||
357 | unsigned long sp = regs->regs[15] & 0xffffffff; | ||
358 | struct task_struct *tsk = get_current(); | ||
359 | |||
360 | tsk->thread.kregs = regs; | ||
361 | |||
362 | show_stack(tsk, (unsigned long *)sp); | ||
363 | } | ||
364 | } | ||
365 | |||
366 | struct task_struct * alloc_task_struct(void) | ||
367 | { | ||
368 | /* Get task descriptor pages */ | ||
369 | return (struct task_struct *) | ||
370 | __get_free_pages(GFP_KERNEL, get_order(THREAD_SIZE)); | ||
371 | } | ||
372 | |||
373 | void free_task_struct(struct task_struct *p) | ||
374 | { | ||
375 | free_pages((unsigned long) p, get_order(THREAD_SIZE)); | ||
376 | } | ||
377 | |||
378 | /* | ||
379 | * Create a kernel thread | ||
380 | */ | ||
381 | ATTRIB_NORET void kernel_thread_helper(void *arg, int (*fn)(void *)) | ||
382 | { | ||
383 | do_exit(fn(arg)); | ||
384 | } | ||
385 | |||
386 | /* | ||
387 | * This is the mechanism for creating a new kernel thread. | ||
388 | * | ||
389 | * NOTE! Only a kernel-only process(ie the swapper or direct descendants | ||
390 | * who haven't done an "execve()") should use this: it will work within | ||
391 | * a system call from a "real" process, but the process memory space will | ||
392 | * not be freed until both the parent and the child have exited. | ||
393 | */ | ||
394 | int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) | ||
395 | { | ||
396 | struct pt_regs regs; | ||
397 | |||
398 | memset(®s, 0, sizeof(regs)); | ||
399 | regs.regs[2] = (unsigned long)arg; | ||
400 | regs.regs[3] = (unsigned long)fn; | ||
401 | |||
402 | regs.pc = (unsigned long)kernel_thread_helper; | ||
403 | regs.sr = (1 << 30); | ||
404 | |||
405 | return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, | ||
406 | ®s, 0, NULL, NULL); | ||
407 | } | ||
408 | |||
409 | /* | ||
410 | * Free current thread data structures etc.. | ||
411 | */ | ||
412 | void exit_thread(void) | ||
413 | { | ||
414 | /* See arch/sparc/kernel/process.c for the precedent for doing this -- RPC. | ||
415 | |||
416 | The SH-5 FPU save/restore approach relies on last_task_used_math | ||
417 | pointing to a live task_struct. When another task tries to use the | ||
418 | FPU for the 1st time, the FPUDIS trap handling (see | ||
419 | arch/sh64/kernel/fpu.c) will save the existing FPU state to the | ||
420 | FP regs field within last_task_used_math before re-loading the new | ||
421 | task's FPU state (or initialising it if the FPU has been used | ||
422 | before). So if last_task_used_math is stale, and its page has already been | ||
423 | re-allocated for another use, the consequences are rather grim. Unless we | ||
424 | null it here, there is no other path through which it would get safely | ||
425 | nulled. */ | ||
426 | |||
427 | #ifdef CONFIG_SH_FPU | ||
428 | if (last_task_used_math == current) { | ||
429 | last_task_used_math = NULL; | ||
430 | } | ||
431 | #endif | ||
432 | } | ||
433 | |||
434 | void flush_thread(void) | ||
435 | { | ||
436 | |||
437 | /* Called by fs/exec.c (flush_old_exec) to remove traces of a | ||
438 | * previously running executable. */ | ||
439 | #ifdef CONFIG_SH_FPU | ||
440 | if (last_task_used_math == current) { | ||
441 | last_task_used_math = NULL; | ||
442 | } | ||
443 | /* Force FPU state to be reinitialised after exec */ | ||
444 | clear_used_math(); | ||
445 | #endif | ||
446 | |||
447 | /* if we are a kernel thread, about to change to user thread, | ||
448 | * update kreg | ||
449 | */ | ||
450 | if(current->thread.kregs==&fake_swapper_regs) { | ||
451 | current->thread.kregs = | ||
452 | ((struct pt_regs *)(THREAD_SIZE + (unsigned long) current) - 1); | ||
453 | current->thread.uregs = current->thread.kregs; | ||
454 | } | ||
455 | } | ||
456 | |||
457 | void release_thread(struct task_struct *dead_task) | ||
458 | { | ||
459 | /* do nothing */ | ||
460 | } | ||
461 | |||
462 | /* Fill in the fpu structure for a core dump.. */ | ||
463 | int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu) | ||
464 | { | ||
465 | #ifdef CONFIG_SH_FPU | ||
466 | int fpvalid; | ||
467 | struct task_struct *tsk = current; | ||
468 | |||
469 | fpvalid = !!tsk_used_math(tsk); | ||
470 | if (fpvalid) { | ||
471 | if (current == last_task_used_math) { | ||
472 | grab_fpu(); | ||
473 | fpsave(&tsk->thread.fpu.hard); | ||
474 | release_fpu(); | ||
475 | last_task_used_math = 0; | ||
476 | regs->sr |= SR_FD; | ||
477 | } | ||
478 | |||
479 | memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu)); | ||
480 | } | ||
481 | |||
482 | return fpvalid; | ||
483 | #else | ||
484 | return 0; /* Task didn't use the fpu at all. */ | ||
485 | #endif | ||
486 | } | ||
487 | |||
488 | asmlinkage void ret_from_fork(void); | ||
489 | |||
490 | int copy_thread(int nr, unsigned long clone_flags, unsigned long usp, | ||
491 | unsigned long unused, | ||
492 | struct task_struct *p, struct pt_regs *regs) | ||
493 | { | ||
494 | struct pt_regs *childregs; | ||
495 | unsigned long long se; /* Sign extension */ | ||
496 | |||
497 | #ifdef CONFIG_SH_FPU | ||
498 | if(last_task_used_math == current) { | ||
499 | grab_fpu(); | ||
500 | fpsave(¤t->thread.fpu.hard); | ||
501 | release_fpu(); | ||
502 | last_task_used_math = NULL; | ||
503 | regs->sr |= SR_FD; | ||
504 | } | ||
505 | #endif | ||
506 | /* Copy from sh version */ | ||
507 | childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1; | ||
508 | |||
509 | *childregs = *regs; | ||
510 | |||
511 | if (user_mode(regs)) { | ||
512 | childregs->regs[15] = usp; | ||
513 | p->thread.uregs = childregs; | ||
514 | } else { | ||
515 | childregs->regs[15] = (unsigned long)task_stack_page(p) + THREAD_SIZE; | ||
516 | } | ||
517 | |||
518 | childregs->regs[9] = 0; /* Set return value for child */ | ||
519 | childregs->sr |= SR_FD; /* Invalidate FPU flag */ | ||
520 | |||
521 | p->thread.sp = (unsigned long) childregs; | ||
522 | p->thread.pc = (unsigned long) ret_from_fork; | ||
523 | |||
524 | /* | ||
525 | * Sign extend the edited stack. | ||
526 | * Note that thread.pc and thread.pc will stay | ||
527 | * 32-bit wide and context switch must take care | ||
528 | * of NEFF sign extension. | ||
529 | */ | ||
530 | |||
531 | se = childregs->regs[15]; | ||
532 | se = (se & NEFF_SIGN) ? (se | NEFF_MASK) : se; | ||
533 | childregs->regs[15] = se; | ||
534 | |||
535 | return 0; | ||
536 | } | ||
537 | |||
538 | asmlinkage int sys_fork(unsigned long r2, unsigned long r3, | ||
539 | unsigned long r4, unsigned long r5, | ||
540 | unsigned long r6, unsigned long r7, | ||
541 | struct pt_regs *pregs) | ||
542 | { | ||
543 | return do_fork(SIGCHLD, pregs->regs[15], pregs, 0, 0, 0); | ||
544 | } | ||
545 | |||
546 | asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp, | ||
547 | unsigned long r4, unsigned long r5, | ||
548 | unsigned long r6, unsigned long r7, | ||
549 | struct pt_regs *pregs) | ||
550 | { | ||
551 | if (!newsp) | ||
552 | newsp = pregs->regs[15]; | ||
553 | return do_fork(clone_flags, newsp, pregs, 0, 0, 0); | ||
554 | } | ||
555 | |||
556 | /* | ||
557 | * This is trivial, and on the face of it looks like it | ||
558 | * could equally well be done in user mode. | ||
559 | * | ||
560 | * Not so, for quite unobvious reasons - register pressure. | ||
561 | * In user mode vfork() cannot have a stack frame, and if | ||
562 | * done by calling the "clone()" system call directly, you | ||
563 | * do not have enough call-clobbered registers to hold all | ||
564 | * the information you need. | ||
565 | */ | ||
566 | asmlinkage int sys_vfork(unsigned long r2, unsigned long r3, | ||
567 | unsigned long r4, unsigned long r5, | ||
568 | unsigned long r6, unsigned long r7, | ||
569 | struct pt_regs *pregs) | ||
570 | { | ||
571 | return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, pregs->regs[15], pregs, 0, 0, 0); | ||
572 | } | ||
573 | |||
574 | /* | ||
575 | * sys_execve() executes a new program. | ||
576 | */ | ||
577 | asmlinkage int sys_execve(char *ufilename, char **uargv, | ||
578 | char **uenvp, unsigned long r5, | ||
579 | unsigned long r6, unsigned long r7, | ||
580 | struct pt_regs *pregs) | ||
581 | { | ||
582 | int error; | ||
583 | char *filename; | ||
584 | |||
585 | lock_kernel(); | ||
586 | filename = getname((char __user *)ufilename); | ||
587 | error = PTR_ERR(filename); | ||
588 | if (IS_ERR(filename)) | ||
589 | goto out; | ||
590 | |||
591 | error = do_execve(filename, | ||
592 | (char __user * __user *)uargv, | ||
593 | (char __user * __user *)uenvp, | ||
594 | pregs); | ||
595 | if (error == 0) { | ||
596 | task_lock(current); | ||
597 | current->ptrace &= ~PT_DTRACE; | ||
598 | task_unlock(current); | ||
599 | } | ||
600 | putname(filename); | ||
601 | out: | ||
602 | unlock_kernel(); | ||
603 | return error; | ||
604 | } | ||
605 | |||
606 | /* | ||
607 | * These bracket the sleeping functions.. | ||
608 | */ | ||
609 | extern void interruptible_sleep_on(wait_queue_head_t *q); | ||
610 | |||
611 | #define mid_sched ((unsigned long) interruptible_sleep_on) | ||
612 | |||
613 | static int in_sh64_switch_to(unsigned long pc) | ||
614 | { | ||
615 | extern char __sh64_switch_to_end; | ||
616 | /* For a sleeping task, the PC is somewhere in the middle of the function, | ||
617 | so we don't have to worry about masking the LSB off */ | ||
618 | return (pc >= (unsigned long) sh64_switch_to) && | ||
619 | (pc < (unsigned long) &__sh64_switch_to_end); | ||
620 | } | ||
621 | |||
622 | unsigned long get_wchan(struct task_struct *p) | ||
623 | { | ||
624 | unsigned long schedule_fp; | ||
625 | unsigned long sh64_switch_to_fp; | ||
626 | unsigned long schedule_caller_pc; | ||
627 | unsigned long pc; | ||
628 | |||
629 | if (!p || p == current || p->state == TASK_RUNNING) | ||
630 | return 0; | ||
631 | |||
632 | /* | ||
633 | * The same comment as on the Alpha applies here, too ... | ||
634 | */ | ||
635 | pc = thread_saved_pc(p); | ||
636 | |||
637 | #ifdef CONFIG_FRAME_POINTER | ||
638 | if (in_sh64_switch_to(pc)) { | ||
639 | sh64_switch_to_fp = (long) p->thread.sp; | ||
640 | /* r14 is saved at offset 4 in the sh64_switch_to frame */ | ||
641 | schedule_fp = *(unsigned long *) (long)(sh64_switch_to_fp + 4); | ||
642 | |||
643 | /* and the caller of 'schedule' is (currently!) saved at offset 24 | ||
644 | in the frame of schedule (from disasm) */ | ||
645 | schedule_caller_pc = *(unsigned long *) (long)(schedule_fp + 24); | ||
646 | return schedule_caller_pc; | ||
647 | } | ||
648 | #endif | ||
649 | return pc; | ||
650 | } | ||
651 | |||
652 | /* Provide a /proc/asids file that lists out the | ||
653 | ASIDs currently associated with the processes. (If the DM.PC register is | ||
654 | examined through the debug link, this shows ASID + PC. To make use of this, | ||
655 | the PID->ASID relationship needs to be known. This is primarily for | ||
656 | debugging.) | ||
657 | */ | ||
658 | |||
659 | #if defined(CONFIG_SH64_PROC_ASIDS) | ||
660 | static int | ||
661 | asids_proc_info(char *buf, char **start, off_t fpos, int length, int *eof, void *data) | ||
662 | { | ||
663 | int len=0; | ||
664 | struct task_struct *p; | ||
665 | read_lock(&tasklist_lock); | ||
666 | for_each_process(p) { | ||
667 | int pid = p->pid; | ||
668 | struct mm_struct *mm; | ||
669 | if (!pid) continue; | ||
670 | mm = p->mm; | ||
671 | if (mm) { | ||
672 | unsigned long asid, context; | ||
673 | context = mm->context; | ||
674 | asid = (context & 0xff); | ||
675 | len += sprintf(buf+len, "%5d : %02lx\n", pid, asid); | ||
676 | } else { | ||
677 | len += sprintf(buf+len, "%5d : (none)\n", pid); | ||
678 | } | ||
679 | } | ||
680 | read_unlock(&tasklist_lock); | ||
681 | *eof = 1; | ||
682 | return len; | ||
683 | } | ||
684 | |||
685 | static int __init register_proc_asids(void) | ||
686 | { | ||
687 | create_proc_read_entry("asids", 0, NULL, asids_proc_info, NULL); | ||
688 | return 0; | ||
689 | } | ||
690 | __initcall(register_proc_asids); | ||
691 | #endif | ||