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