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