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