blob: c0d40f671ecd6145cc31ed238b806e2ac671136f [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 Mundta7aa92d1b492007-11-20 15:38:50 +090026#include <linux/io.h>
Paul Mundtfa439722008-09-04 18:53:58 +090027#include <asm/syscalls.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
Paul Mundtfbb82b02010-01-20 16:42:52 +090035void show_regs(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
37 unsigned long long ah, al, bh, bl, ch, cl;
38
39 printk("\n");
40
41 ah = (regs->pc) >> 32;
42 al = (regs->pc) & 0xffffffff;
43 bh = (regs->regs[18]) >> 32;
44 bl = (regs->regs[18]) & 0xffffffff;
45 ch = (regs->regs[15]) >> 32;
46 cl = (regs->regs[15]) & 0xffffffff;
47 printk("PC : %08Lx%08Lx LINK: %08Lx%08Lx SP : %08Lx%08Lx\n",
48 ah, al, bh, bl, ch, cl);
49
50 ah = (regs->sr) >> 32;
51 al = (regs->sr) & 0xffffffff;
52 asm volatile ("getcon " __TEA ", %0" : "=r" (bh));
53 asm volatile ("getcon " __TEA ", %0" : "=r" (bl));
54 bh = (bh) >> 32;
55 bl = (bl) & 0xffffffff;
56 asm volatile ("getcon " __KCR0 ", %0" : "=r" (ch));
57 asm volatile ("getcon " __KCR0 ", %0" : "=r" (cl));
58 ch = (ch) >> 32;
59 cl = (cl) & 0xffffffff;
60 printk("SR : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n",
61 ah, al, bh, bl, ch, cl);
62
63 ah = (regs->regs[0]) >> 32;
64 al = (regs->regs[0]) & 0xffffffff;
65 bh = (regs->regs[1]) >> 32;
66 bl = (regs->regs[1]) & 0xffffffff;
67 ch = (regs->regs[2]) >> 32;
68 cl = (regs->regs[2]) & 0xffffffff;
69 printk("R0 : %08Lx%08Lx R1 : %08Lx%08Lx R2 : %08Lx%08Lx\n",
70 ah, al, bh, bl, ch, cl);
71
72 ah = (regs->regs[3]) >> 32;
73 al = (regs->regs[3]) & 0xffffffff;
74 bh = (regs->regs[4]) >> 32;
75 bl = (regs->regs[4]) & 0xffffffff;
76 ch = (regs->regs[5]) >> 32;
77 cl = (regs->regs[5]) & 0xffffffff;
78 printk("R3 : %08Lx%08Lx R4 : %08Lx%08Lx R5 : %08Lx%08Lx\n",
79 ah, al, bh, bl, ch, cl);
80
81 ah = (regs->regs[6]) >> 32;
82 al = (regs->regs[6]) & 0xffffffff;
83 bh = (regs->regs[7]) >> 32;
84 bl = (regs->regs[7]) & 0xffffffff;
85 ch = (regs->regs[8]) >> 32;
86 cl = (regs->regs[8]) & 0xffffffff;
87 printk("R6 : %08Lx%08Lx R7 : %08Lx%08Lx R8 : %08Lx%08Lx\n",
88 ah, al, bh, bl, ch, cl);
89
90 ah = (regs->regs[9]) >> 32;
91 al = (regs->regs[9]) & 0xffffffff;
92 bh = (regs->regs[10]) >> 32;
93 bl = (regs->regs[10]) & 0xffffffff;
94 ch = (regs->regs[11]) >> 32;
95 cl = (regs->regs[11]) & 0xffffffff;
96 printk("R9 : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n",
97 ah, al, bh, bl, ch, cl);
98
99 ah = (regs->regs[12]) >> 32;
100 al = (regs->regs[12]) & 0xffffffff;
101 bh = (regs->regs[13]) >> 32;
102 bl = (regs->regs[13]) & 0xffffffff;
103 ch = (regs->regs[14]) >> 32;
104 cl = (regs->regs[14]) & 0xffffffff;
105 printk("R12 : %08Lx%08Lx R13 : %08Lx%08Lx R14 : %08Lx%08Lx\n",
106 ah, al, bh, bl, ch, cl);
107
108 ah = (regs->regs[16]) >> 32;
109 al = (regs->regs[16]) & 0xffffffff;
110 bh = (regs->regs[17]) >> 32;
111 bl = (regs->regs[17]) & 0xffffffff;
112 ch = (regs->regs[19]) >> 32;
113 cl = (regs->regs[19]) & 0xffffffff;
114 printk("R16 : %08Lx%08Lx R17 : %08Lx%08Lx R19 : %08Lx%08Lx\n",
115 ah, al, bh, bl, ch, cl);
116
117 ah = (regs->regs[20]) >> 32;
118 al = (regs->regs[20]) & 0xffffffff;
119 bh = (regs->regs[21]) >> 32;
120 bl = (regs->regs[21]) & 0xffffffff;
121 ch = (regs->regs[22]) >> 32;
122 cl = (regs->regs[22]) & 0xffffffff;
123 printk("R20 : %08Lx%08Lx R21 : %08Lx%08Lx R22 : %08Lx%08Lx\n",
124 ah, al, bh, bl, ch, cl);
125
126 ah = (regs->regs[23]) >> 32;
127 al = (regs->regs[23]) & 0xffffffff;
128 bh = (regs->regs[24]) >> 32;
129 bl = (regs->regs[24]) & 0xffffffff;
130 ch = (regs->regs[25]) >> 32;
131 cl = (regs->regs[25]) & 0xffffffff;
132 printk("R23 : %08Lx%08Lx R24 : %08Lx%08Lx R25 : %08Lx%08Lx\n",
133 ah, al, bh, bl, ch, cl);
134
135 ah = (regs->regs[26]) >> 32;
136 al = (regs->regs[26]) & 0xffffffff;
137 bh = (regs->regs[27]) >> 32;
138 bl = (regs->regs[27]) & 0xffffffff;
139 ch = (regs->regs[28]) >> 32;
140 cl = (regs->regs[28]) & 0xffffffff;
141 printk("R26 : %08Lx%08Lx R27 : %08Lx%08Lx R28 : %08Lx%08Lx\n",
142 ah, al, bh, bl, ch, cl);
143
144 ah = (regs->regs[29]) >> 32;
145 al = (regs->regs[29]) & 0xffffffff;
146 bh = (regs->regs[30]) >> 32;
147 bl = (regs->regs[30]) & 0xffffffff;
148 ch = (regs->regs[31]) >> 32;
149 cl = (regs->regs[31]) & 0xffffffff;
150 printk("R29 : %08Lx%08Lx R30 : %08Lx%08Lx R31 : %08Lx%08Lx\n",
151 ah, al, bh, bl, ch, cl);
152
153 ah = (regs->regs[32]) >> 32;
154 al = (regs->regs[32]) & 0xffffffff;
155 bh = (regs->regs[33]) >> 32;
156 bl = (regs->regs[33]) & 0xffffffff;
157 ch = (regs->regs[34]) >> 32;
158 cl = (regs->regs[34]) & 0xffffffff;
159 printk("R32 : %08Lx%08Lx R33 : %08Lx%08Lx R34 : %08Lx%08Lx\n",
160 ah, al, bh, bl, ch, cl);
161
162 ah = (regs->regs[35]) >> 32;
163 al = (regs->regs[35]) & 0xffffffff;
164 bh = (regs->regs[36]) >> 32;
165 bl = (regs->regs[36]) & 0xffffffff;
166 ch = (regs->regs[37]) >> 32;
167 cl = (regs->regs[37]) & 0xffffffff;
168 printk("R35 : %08Lx%08Lx R36 : %08Lx%08Lx R37 : %08Lx%08Lx\n",
169 ah, al, bh, bl, ch, cl);
170
171 ah = (regs->regs[38]) >> 32;
172 al = (regs->regs[38]) & 0xffffffff;
173 bh = (regs->regs[39]) >> 32;
174 bl = (regs->regs[39]) & 0xffffffff;
175 ch = (regs->regs[40]) >> 32;
176 cl = (regs->regs[40]) & 0xffffffff;
177 printk("R38 : %08Lx%08Lx R39 : %08Lx%08Lx R40 : %08Lx%08Lx\n",
178 ah, al, bh, bl, ch, cl);
179
180 ah = (regs->regs[41]) >> 32;
181 al = (regs->regs[41]) & 0xffffffff;
182 bh = (regs->regs[42]) >> 32;
183 bl = (regs->regs[42]) & 0xffffffff;
184 ch = (regs->regs[43]) >> 32;
185 cl = (regs->regs[43]) & 0xffffffff;
186 printk("R41 : %08Lx%08Lx R42 : %08Lx%08Lx R43 : %08Lx%08Lx\n",
187 ah, al, bh, bl, ch, cl);
188
189 ah = (regs->regs[44]) >> 32;
190 al = (regs->regs[44]) & 0xffffffff;
191 bh = (regs->regs[45]) >> 32;
192 bl = (regs->regs[45]) & 0xffffffff;
193 ch = (regs->regs[46]) >> 32;
194 cl = (regs->regs[46]) & 0xffffffff;
195 printk("R44 : %08Lx%08Lx R45 : %08Lx%08Lx R46 : %08Lx%08Lx\n",
196 ah, al, bh, bl, ch, cl);
197
198 ah = (regs->regs[47]) >> 32;
199 al = (regs->regs[47]) & 0xffffffff;
200 bh = (regs->regs[48]) >> 32;
201 bl = (regs->regs[48]) & 0xffffffff;
202 ch = (regs->regs[49]) >> 32;
203 cl = (regs->regs[49]) & 0xffffffff;
204 printk("R47 : %08Lx%08Lx R48 : %08Lx%08Lx R49 : %08Lx%08Lx\n",
205 ah, al, bh, bl, ch, cl);
206
207 ah = (regs->regs[50]) >> 32;
208 al = (regs->regs[50]) & 0xffffffff;
209 bh = (regs->regs[51]) >> 32;
210 bl = (regs->regs[51]) & 0xffffffff;
211 ch = (regs->regs[52]) >> 32;
212 cl = (regs->regs[52]) & 0xffffffff;
213 printk("R50 : %08Lx%08Lx R51 : %08Lx%08Lx R52 : %08Lx%08Lx\n",
214 ah, al, bh, bl, ch, cl);
215
216 ah = (regs->regs[53]) >> 32;
217 al = (regs->regs[53]) & 0xffffffff;
218 bh = (regs->regs[54]) >> 32;
219 bl = (regs->regs[54]) & 0xffffffff;
220 ch = (regs->regs[55]) >> 32;
221 cl = (regs->regs[55]) & 0xffffffff;
222 printk("R53 : %08Lx%08Lx R54 : %08Lx%08Lx R55 : %08Lx%08Lx\n",
223 ah, al, bh, bl, ch, cl);
224
225 ah = (regs->regs[56]) >> 32;
226 al = (regs->regs[56]) & 0xffffffff;
227 bh = (regs->regs[57]) >> 32;
228 bl = (regs->regs[57]) & 0xffffffff;
229 ch = (regs->regs[58]) >> 32;
230 cl = (regs->regs[58]) & 0xffffffff;
231 printk("R56 : %08Lx%08Lx R57 : %08Lx%08Lx R58 : %08Lx%08Lx\n",
232 ah, al, bh, bl, ch, cl);
233
234 ah = (regs->regs[59]) >> 32;
235 al = (regs->regs[59]) & 0xffffffff;
236 bh = (regs->regs[60]) >> 32;
237 bl = (regs->regs[60]) & 0xffffffff;
238 ch = (regs->regs[61]) >> 32;
239 cl = (regs->regs[61]) & 0xffffffff;
240 printk("R59 : %08Lx%08Lx R60 : %08Lx%08Lx R61 : %08Lx%08Lx\n",
241 ah, al, bh, bl, ch, cl);
242
243 ah = (regs->regs[62]) >> 32;
244 al = (regs->regs[62]) & 0xffffffff;
245 bh = (regs->tregs[0]) >> 32;
246 bl = (regs->tregs[0]) & 0xffffffff;
247 ch = (regs->tregs[1]) >> 32;
248 cl = (regs->tregs[1]) & 0xffffffff;
249 printk("R62 : %08Lx%08Lx T0 : %08Lx%08Lx T1 : %08Lx%08Lx\n",
250 ah, al, bh, bl, ch, cl);
251
252 ah = (regs->tregs[2]) >> 32;
253 al = (regs->tregs[2]) & 0xffffffff;
254 bh = (regs->tregs[3]) >> 32;
255 bl = (regs->tregs[3]) & 0xffffffff;
256 ch = (regs->tregs[4]) >> 32;
257 cl = (regs->tregs[4]) & 0xffffffff;
258 printk("T2 : %08Lx%08Lx T3 : %08Lx%08Lx T4 : %08Lx%08Lx\n",
259 ah, al, bh, bl, ch, cl);
260
261 ah = (regs->tregs[5]) >> 32;
262 al = (regs->tregs[5]) & 0xffffffff;
263 bh = (regs->tregs[6]) >> 32;
264 bl = (regs->tregs[6]) & 0xffffffff;
265 ch = (regs->tregs[7]) >> 32;
266 cl = (regs->tregs[7]) & 0xffffffff;
267 printk("T5 : %08Lx%08Lx T6 : %08Lx%08Lx T7 : %08Lx%08Lx\n",
268 ah, al, bh, bl, ch, cl);
269
270 /*
271 * If we're in kernel mode, dump the stack too..
272 */
273 if (!user_mode(regs)) {
274 void show_stack(struct task_struct *tsk, unsigned long *sp);
275 unsigned long sp = regs->regs[15] & 0xffffffff;
276 struct task_struct *tsk = get_current();
277
278 tsk->thread.kregs = regs;
279
280 show_stack(tsk, (unsigned long *)sp);
281 }
282}
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284/*
285 * Create a kernel thread
286 */
Arnd Bergmann821278a2006-10-02 02:18:41 -0700287ATTRIB_NORET void kernel_thread_helper(void *arg, int (*fn)(void *))
288{
289 do_exit(fn(arg));
290}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292/*
293 * This is the mechanism for creating a new kernel thread.
294 *
295 * NOTE! Only a kernel-only process(ie the swapper or direct descendants
296 * who haven't done an "execve()") should use this: it will work within
297 * a system call from a "real" process, but the process memory space will
Simon Arlott0a354772007-05-14 08:25:48 +0900298 * not be freed until both the parent and the child have exited.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 */
300int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
301{
Arnd Bergmann821278a2006-10-02 02:18:41 -0700302 struct pt_regs regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Arnd Bergmann821278a2006-10-02 02:18:41 -0700304 memset(&regs, 0, sizeof(regs));
305 regs.regs[2] = (unsigned long)arg;
306 regs.regs[3] = (unsigned long)fn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Arnd Bergmann821278a2006-10-02 02:18:41 -0700308 regs.pc = (unsigned long)kernel_thread_helper;
309 regs.sr = (1 << 30);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Paul Mundt3d586952008-09-21 13:56:39 +0900311 /* Ok, create the new process.. */
Christoph Hellwig4505ffd2009-06-18 13:38:26 +0900312 return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
Paul Mundt3d586952008-09-21 13:56:39 +0900313 &regs, 0, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314}
Paul Mundt4c978ca2009-10-27 11:51:19 +0900315EXPORT_SYMBOL(kernel_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317/*
318 * Free current thread data structures etc..
319 */
320void exit_thread(void)
321{
Paul Mundta23ba432007-11-28 20:19:38 +0900322 /*
323 * See arch/sparc/kernel/process.c for the precedent for doing
324 * this -- RPC.
325 *
326 * The SH-5 FPU save/restore approach relies on
327 * last_task_used_math pointing to a live task_struct. When
328 * another task tries to use the FPU for the 1st time, the FPUDIS
329 * trap handling (see arch/sh/kernel/cpu/sh5/fpu.c) will save the
330 * existing FPU state to the FP regs field within
331 * last_task_used_math before re-loading the new task's FPU state
332 * (or initialising it if the FPU has been used before). So if
333 * last_task_used_math is stale, and its page has already been
334 * re-allocated for another use, the consequences are rather
335 * grim. Unless we null it here, there is no other path through
336 * which it would get safely nulled.
337 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338#ifdef CONFIG_SH_FPU
339 if (last_task_used_math == current) {
340 last_task_used_math = NULL;
341 }
342#endif
343}
344
345void flush_thread(void)
346{
347
Linus Torvalds221af7f2010-01-28 22:14:42 -0800348 /* Called by fs/exec.c (setup_new_exec) to remove traces of a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 * previously running executable. */
350#ifdef CONFIG_SH_FPU
351 if (last_task_used_math == current) {
352 last_task_used_math = NULL;
353 }
354 /* Force FPU state to be reinitialised after exec */
355 clear_used_math();
356#endif
357
358 /* if we are a kernel thread, about to change to user thread,
359 * update kreg
360 */
361 if(current->thread.kregs==&fake_swapper_regs) {
362 current->thread.kregs =
363 ((struct pt_regs *)(THREAD_SIZE + (unsigned long) current) - 1);
364 current->thread.uregs = current->thread.kregs;
365 }
366}
367
368void release_thread(struct task_struct *dead_task)
369{
370 /* do nothing */
371}
372
373/* Fill in the fpu structure for a core dump.. */
374int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
375{
376#ifdef CONFIG_SH_FPU
377 int fpvalid;
378 struct task_struct *tsk = current;
379
380 fpvalid = !!tsk_used_math(tsk);
381 if (fpvalid) {
382 if (current == last_task_used_math) {
Paul Mundt600ee242007-11-19 19:13:38 +0900383 enable_fpu();
Matt Fleming61cc7b02009-12-14 20:12:04 +0000384 save_fpu(tsk);
Paul Mundt600ee242007-11-19 19:13:38 +0900385 disable_fpu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 last_task_used_math = 0;
387 regs->sr |= SR_FD;
388 }
389
Paul Mundt3ef29322010-01-19 15:40:03 +0900390 memcpy(fpu, &tsk->thread.xstate->hardfpu, sizeof(*fpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 }
392
393 return fpvalid;
394#else
395 return 0; /* Task didn't use the fpu at all. */
396#endif
397}
Paul Mundt4c978ca2009-10-27 11:51:19 +0900398EXPORT_SYMBOL(dump_fpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400asmlinkage void ret_from_fork(void);
401
Alexey Dobriyan6f2c55b2009-04-02 16:56:59 -0700402int copy_thread(unsigned long clone_flags, unsigned long usp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 unsigned long unused,
404 struct task_struct *p, struct pt_regs *regs)
405{
406 struct pt_regs *childregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408#ifdef CONFIG_SH_FPU
409 if(last_task_used_math == current) {
Paul Mundt600ee242007-11-19 19:13:38 +0900410 enable_fpu();
Matt Fleming61cc7b02009-12-14 20:12:04 +0000411 save_fpu(current);
Paul Mundt600ee242007-11-19 19:13:38 +0900412 disable_fpu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 last_task_used_math = NULL;
414 regs->sr |= SR_FD;
415 }
416#endif
417 /* Copy from sh version */
Al Viroee8c1dd2006-01-12 01:06:01 -0800418 childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 *childregs = *regs;
421
Paul Mundtc7914832009-08-04 17:14:39 +0900422 /*
423 * Sign extend the edited stack.
424 * Note that thread.pc and thread.pc will stay
425 * 32-bit wide and context switch must take care
426 * of NEFF sign extension.
427 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 if (user_mode(regs)) {
Paul Mundtc7914832009-08-04 17:14:39 +0900429 childregs->regs[15] = neff_sign_extend(usp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 p->thread.uregs = childregs;
431 } else {
Paul Mundtc7914832009-08-04 17:14:39 +0900432 childregs->regs[15] =
433 neff_sign_extend((unsigned long)task_stack_page(p) +
434 THREAD_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 }
436
437 childregs->regs[9] = 0; /* Set return value for child */
438 childregs->sr |= SR_FD; /* Invalidate FPU flag */
439
440 p->thread.sp = (unsigned long) childregs;
441 p->thread.pc = (unsigned long) ret_from_fork;
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return 0;
444}
445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446asmlinkage int sys_fork(unsigned long r2, unsigned long r3,
447 unsigned long r4, unsigned long r5,
448 unsigned long r6, unsigned long r7,
449 struct pt_regs *pregs)
450{
451 return do_fork(SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
452}
453
454asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
455 unsigned long r4, unsigned long r5,
456 unsigned long r6, unsigned long r7,
457 struct pt_regs *pregs)
458{
459 if (!newsp)
460 newsp = pregs->regs[15];
461 return do_fork(clone_flags, newsp, pregs, 0, 0, 0);
462}
463
464/*
465 * This is trivial, and on the face of it looks like it
466 * could equally well be done in user mode.
467 *
468 * Not so, for quite unobvious reasons - register pressure.
469 * In user mode vfork() cannot have a stack frame, and if
470 * done by calling the "clone()" system call directly, you
471 * do not have enough call-clobbered registers to hold all
472 * the information you need.
473 */
474asmlinkage int sys_vfork(unsigned long r2, unsigned long r3,
475 unsigned long r4, unsigned long r5,
476 unsigned long r6, unsigned long r7,
477 struct pt_regs *pregs)
478{
479 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
480}
481
482/*
483 * sys_execve() executes a new program.
484 */
485asmlinkage int sys_execve(char *ufilename, char **uargv,
486 char **uenvp, unsigned long r5,
487 unsigned long r6, unsigned long r7,
488 struct pt_regs *pregs)
489{
490 int error;
491 char *filename;
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 filename = getname((char __user *)ufilename);
494 error = PTR_ERR(filename);
495 if (IS_ERR(filename))
496 goto out;
497
498 error = do_execve(filename,
499 (char __user * __user *)uargv,
500 (char __user * __user *)uenvp,
501 pregs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 putname(filename);
503out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 return error;
505}
506
Paul Mundt43081e12008-02-12 17:02:08 +0900507#ifdef CONFIG_FRAME_POINTER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508static int in_sh64_switch_to(unsigned long pc)
509{
510 extern char __sh64_switch_to_end;
511 /* For a sleeping task, the PC is somewhere in the middle of the function,
512 so we don't have to worry about masking the LSB off */
513 return (pc >= (unsigned long) sh64_switch_to) &&
514 (pc < (unsigned long) &__sh64_switch_to_end);
515}
Paul Mundt43081e12008-02-12 17:02:08 +0900516#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518unsigned long get_wchan(struct task_struct *p)
519{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 unsigned long pc;
521
522 if (!p || p == current || p->state == TASK_RUNNING)
523 return 0;
524
525 /*
526 * The same comment as on the Alpha applies here, too ...
527 */
528 pc = thread_saved_pc(p);
529
530#ifdef CONFIG_FRAME_POINTER
531 if (in_sh64_switch_to(pc)) {
Paul Mundt43081e12008-02-12 17:02:08 +0900532 unsigned long schedule_fp;
533 unsigned long sh64_switch_to_fp;
534 unsigned long schedule_caller_pc;
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 sh64_switch_to_fp = (long) p->thread.sp;
537 /* r14 is saved at offset 4 in the sh64_switch_to frame */
538 schedule_fp = *(unsigned long *) (long)(sh64_switch_to_fp + 4);
539
540 /* and the caller of 'schedule' is (currently!) saved at offset 24
541 in the frame of schedule (from disasm) */
542 schedule_caller_pc = *(unsigned long *) (long)(schedule_fp + 24);
543 return schedule_caller_pc;
544 }
545#endif
546 return pc;
547}