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