1 /*  $Id: process.c,v 1.158 2001/11/26 23:45:00 davem Exp $
2  *  linux/arch/sparc/kernel/process.c
3  *
4  *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5  *  Copyright (C) 1996 Eddie C. Dost   (ecd@skynet.be)
6  */
7 
8 /*
9  * This file handles the architecture-dependent parts of process handling..
10  */
11 
12 #define __KERNEL_SYSCALLS__
13 #include <stdarg.h>
14 
15 #include <linux/errno.h>
16 #include <linux/sched.h>
17 #include <linux/kernel.h>
18 #include <linux/mm.h>
19 #include <linux/stddef.h>
20 #include <linux/unistd.h>
21 #include <linux/ptrace.h>
22 #include <linux/slab.h>
23 #include <linux/user.h>
24 #include <linux/a.out.h>
25 #include <linux/config.h>
26 #include <linux/smp.h>
27 #include <linux/smp_lock.h>
28 #include <linux/reboot.h>
29 #include <linux/delay.h>
30 #include <linux/pm.h>
31 
32 #include <asm/auxio.h>
33 #include <asm/oplib.h>
34 #include <asm/uaccess.h>
35 #include <asm/system.h>
36 #include <asm/page.h>
37 #include <asm/pgalloc.h>
38 #include <asm/pgtable.h>
39 #include <asm/delay.h>
40 #include <asm/processor.h>
41 #include <asm/psr.h>
42 #include <asm/elf.h>
43 
44 /*
45  * Power management idle function
46  * Set in pm platform drivers
47  */
48 void (*pm_idle)(void);
49 
50 /*
51  * Power-off handler instantiation for pm.h compliance
52  * This is done via auxio, but could be used as a fallback
53  * handler when auxio is not present-- unused for now...
54  */
55 void (*pm_power_off)(void);
56 
57 /*
58  * sysctl - toggle power-off restriction for serial console
59  * systems in machine_power_off()
60  */
61 int scons_pwroff = 1;
62 
63 extern void fpsave(unsigned long *, unsigned long *, void *, unsigned long *);
64 
65 struct task_struct *last_task_used_math = NULL;
66 struct task_struct *current_set[NR_CPUS] = {&init_task, };
67 
68 #ifndef CONFIG_SMP
69 
70 #define SUN4C_FAULT_HIGH 100
71 
72 /*
73  * the idle loop on a Sparc... ;)
74  */
cpu_idle(void)75 int cpu_idle(void)
76 {
77 	int ret = -EPERM;
78 
79 	if (current->pid != 0)
80 		goto out;
81 
82 	/* endless idle loop with no priority at all */
83 	current->nice = 20;
84 	current->counter = -100;
85 	init_idle();
86 
87 	for (;;) {
88 		if (ARCH_SUN4C_SUN4) {
89 			static int count = HZ;
90 			static unsigned long last_jiffies;
91 			static unsigned long last_faults;
92 			static unsigned long fps;
93 			unsigned long now;
94 			unsigned long faults;
95 			unsigned long flags;
96 
97 			extern unsigned long sun4c_kernel_faults;
98 			extern void sun4c_grow_kernel_ring(void);
99 
100 			save_and_cli(flags);
101 			now = jiffies;
102 			count -= (now - last_jiffies);
103 			last_jiffies = now;
104 			if (count < 0) {
105 				count += HZ;
106 				faults = sun4c_kernel_faults;
107 				fps = (fps + (faults - last_faults)) >> 1;
108 				last_faults = faults;
109 #if 0
110 				printk("kernel faults / second = %ld\n", fps);
111 #endif
112 				if (fps >= SUN4C_FAULT_HIGH) {
113 					sun4c_grow_kernel_ring();
114 				}
115 			}
116 			restore_flags(flags);
117 		}
118 
119 		while((!current->need_resched) && pm_idle) {
120 				(*pm_idle)();
121 		}
122 
123 		schedule();
124 		check_pgt_cache();
125 	}
126 	ret = 0;
127 out:
128 	return ret;
129 }
130 
131 #else
132 
133 /* This is being executed in task 0 'user space'. */
cpu_idle(void)134 int cpu_idle(void)
135 {
136 	/* endless idle loop with no priority at all */
137 	current->nice = 20;
138 	current->counter = -100;
139 	init_idle();
140 
141 	while(1) {
142 		if(current->need_resched) {
143 			schedule();
144 			check_pgt_cache();
145 		}
146 		barrier(); /* or else gcc optimizes... */
147 	}
148 }
149 
150 #endif
151 
152 extern char reboot_command [];
153 
154 extern int serial_console;
155 
156 #ifdef CONFIG_SUN_CONSOLE
157 extern void (*prom_palette)(int);
158 #endif
159 
machine_halt(void)160 void machine_halt(void)
161 {
162 	sti();
163 	mdelay(8);
164 	cli();
165 #ifdef CONFIG_SUN_CONSOLE
166 	if (!serial_console && prom_palette)
167 		prom_palette (1);
168 #endif
169 	prom_halt();
170 	panic("Halt failed!");
171 }
172 
machine_restart(char * cmd)173 void machine_restart(char * cmd)
174 {
175 	char *p;
176 
177 	sti();
178 	mdelay(8);
179 	cli();
180 
181 	p = strchr (reboot_command, '\n');
182 	if (p) *p = 0;
183 #ifdef CONFIG_SUN_CONSOLE
184 	if (!serial_console && prom_palette)
185 		prom_palette (1);
186 #endif
187 	if (cmd)
188 		prom_reboot(cmd);
189 	if (*reboot_command)
190 		prom_reboot(reboot_command);
191 	prom_feval ("reset");
192 	panic("Reboot failed!");
193 }
194 
machine_power_off(void)195 void machine_power_off(void)
196 {
197 #ifdef CONFIG_SUN_AUXIO
198 	if (auxio_power_register && (!serial_console || scons_pwroff))
199 		*auxio_power_register |= AUXIO_POWER_OFF;
200 #endif
201 	machine_halt();
202 }
203 
show_regwindow(struct reg_window * rw)204 void show_regwindow(struct reg_window *rw)
205 {
206 	printk("l0: %08lx l1: %08lx l2: %08lx l3: %08lx "
207 	       "l4: %08lx l5: %08lx l6: %08lx l7: %08lx\n",
208 	       rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
209 	       rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
210 	printk("i0: %08lx i1: %08lx i2: %08lx i3: %08lx "
211 	       "i4: %08lx i5: %08lx fp: %08lx i7: %08lx\n",
212 	       rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
213 	       rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
214 }
215 
216 static spinlock_t sparc_backtrace_lock = SPIN_LOCK_UNLOCKED;
217 
__show_backtrace(unsigned long fp)218 void __show_backtrace(unsigned long fp)
219 {
220 	struct reg_window *rw;
221 	unsigned long flags;
222 	int cpu = smp_processor_id();
223 
224 	spin_lock_irqsave(&sparc_backtrace_lock, flags);
225 
226 	rw = (struct reg_window *)fp;
227         while(rw && (((unsigned long) rw) >= PAGE_OFFSET) &&
228             !(((unsigned long) rw) & 0x7)) {
229 		printk("CPU[%d]: ARGS[%08lx,%08lx,%08lx,%08lx,%08lx,%08lx] "
230 		       "FP[%08lx] CALLER[%08lx]\n", cpu,
231 		       rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
232 		       rw->ins[4], rw->ins[5],
233 		       rw->ins[6],
234 		       rw->ins[7]);
235 		rw = (struct reg_window *) rw->ins[6];
236 	}
237 	spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
238 }
239 
240 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
241 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
242 #define __GET_FP(fp) __asm__ __volatile__("mov %%i6, %0" : "=r" (fp))
243 
show_backtrace(void)244 void show_backtrace(void)
245 {
246 	unsigned long fp;
247 
248 	__SAVE; __SAVE; __SAVE; __SAVE;
249 	__SAVE; __SAVE; __SAVE; __SAVE;
250 	__RESTORE; __RESTORE; __RESTORE; __RESTORE;
251 	__RESTORE; __RESTORE; __RESTORE; __RESTORE;
252 
253 	__GET_FP(fp);
254 
255 	__show_backtrace(fp);
256 }
257 
258 #ifdef CONFIG_SMP
smp_show_backtrace_all_cpus(void)259 void smp_show_backtrace_all_cpus(void)
260 {
261 	xc0((smpfunc_t) show_backtrace);
262 	show_backtrace();
263 }
264 #endif
265 
show_stackframe(struct sparc_stackf * sf)266 void show_stackframe(struct sparc_stackf *sf)
267 {
268 	unsigned long size;
269 	unsigned long *stk;
270 	int i;
271 
272 	printk("l0: %08lx l1: %08lx l2: %08lx l3: %08lx "
273 	       "l4: %08lx l5: %08lx l6: %08lx l7: %08lx\n",
274 	       sf->locals[0], sf->locals[1], sf->locals[2], sf->locals[3],
275 	       sf->locals[4], sf->locals[5], sf->locals[6], sf->locals[7]);
276 	printk("i0: %08lx i1: %08lx i2: %08lx i3: %08lx "
277 	       "i4: %08lx i5: %08lx fp: %08lx i7: %08lx\n",
278 	       sf->ins[0], sf->ins[1], sf->ins[2], sf->ins[3],
279 	       sf->ins[4], sf->ins[5], (unsigned long)sf->fp, sf->callers_pc);
280 	printk("sp: %08lx x0: %08lx x1: %08lx x2: %08lx "
281 	       "x3: %08lx x4: %08lx x5: %08lx xx: %08lx\n",
282 	       (unsigned long)sf->structptr, sf->xargs[0], sf->xargs[1],
283 	       sf->xargs[2], sf->xargs[3], sf->xargs[4], sf->xargs[5],
284 	       sf->xxargs[0]);
285 	size = ((unsigned long)sf->fp) - ((unsigned long)sf);
286 	size -= STACKFRAME_SZ;
287 	stk = (unsigned long *)((unsigned long)sf + STACKFRAME_SZ);
288 	i = 0;
289 	do {
290 		printk("s%d: %08lx\n", i++, *stk++);
291 	} while ((size -= sizeof(unsigned long)));
292 }
293 
show_regs(struct pt_regs * regs)294 void show_regs(struct pt_regs * regs)
295 {
296         printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx    %s\n", regs->psr,
297 	       regs->pc, regs->npc, regs->y, print_tainted());
298 	printk("g0: %08lx g1: %08lx g2: %08lx g3: %08lx ",
299 	       regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
300 	       regs->u_regs[3]);
301 	printk("g4: %08lx g5: %08lx g6: %08lx g7: %08lx\n",
302 	       regs->u_regs[4], regs->u_regs[5], regs->u_regs[6],
303 	       regs->u_regs[7]);
304 	printk("o0: %08lx o1: %08lx o2: %08lx o3: %08lx ",
305 	       regs->u_regs[8], regs->u_regs[9], regs->u_regs[10],
306 	       regs->u_regs[11]);
307 	printk("o4: %08lx o5: %08lx sp: %08lx o7: %08lx\n",
308 	       regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
309 	       regs->u_regs[15]);
310 	show_regwindow((struct reg_window *)regs->u_regs[14]);
311 }
312 
show_trace_task(struct task_struct * tsk)313 void show_trace_task(struct task_struct *tsk)
314 {
315 	unsigned long pc, fp;
316 	unsigned long task_base = (unsigned long) tsk;
317 	struct reg_window *rw;
318 	int count = 0;
319 
320 	if (!tsk)
321 		return;
322 
323 	fp = tsk->thread.ksp;
324 	do {
325 		/* Bogus frame pointer? */
326 		if (fp < (task_base + sizeof(struct task_struct)) ||
327 		    fp >= (task_base + (PAGE_SIZE << 1)))
328 			break;
329 		rw = (struct reg_window *) fp;
330 		pc = rw->ins[7];
331 		printk("[%08lx] ", pc);
332 		fp = rw->ins[6];
333 	} while (++count < 16);
334 	printk("\n");
335 }
336 
337 /*
338  * Free current thread data structures etc..
339  */
exit_thread(void)340 void exit_thread(void)
341 {
342 #ifndef CONFIG_SMP
343 	if(last_task_used_math == current) {
344 #else
345 	if(current->flags & PF_USEDFPU) {
346 #endif
347 		/* Keep process from leaving FPU in a bogon state. */
348 		put_psr(get_psr() | PSR_EF);
349 		fpsave(&current->thread.float_regs[0], &current->thread.fsr,
350 		       &current->thread.fpqueue[0], &current->thread.fpqdepth);
351 #ifndef CONFIG_SMP
352 		last_task_used_math = NULL;
353 #else
354 		current->flags &= ~PF_USEDFPU;
355 #endif
356 	}
357 }
358 
359 void flush_thread(void)
360 {
361 	current->thread.w_saved = 0;
362 
363 	/* No new signal delivery by default */
364 	current->thread.new_signal = 0;
365 #ifndef CONFIG_SMP
366 	if(last_task_used_math == current) {
367 #else
368 	if(current->flags & PF_USEDFPU) {
369 #endif
370 		/* Clean the fpu. */
371 		put_psr(get_psr() | PSR_EF);
372 		fpsave(&current->thread.float_regs[0], &current->thread.fsr,
373 		       &current->thread.fpqueue[0], &current->thread.fpqdepth);
374 #ifndef CONFIG_SMP
375 		last_task_used_math = NULL;
376 #else
377 		current->flags &= ~PF_USEDFPU;
378 #endif
379 	}
380 
381 	/* Now, this task is no longer a kernel thread. */
382 	current->thread.current_ds = USER_DS;
383 	if (current->thread.flags & SPARC_FLAG_KTHREAD) {
384 		current->thread.flags &= ~SPARC_FLAG_KTHREAD;
385 
386 		/* We must fixup kregs as well. */
387 		current->thread.kregs = (struct pt_regs *)
388 			(((unsigned long)current) +
389 			 (TASK_UNION_SIZE - TRACEREG_SZ));
390 	}
391 }
392 
393 static __inline__ struct sparc_stackf *
394 clone_stackframe(struct sparc_stackf *dst, struct sparc_stackf *src)
395 {
396 	unsigned long size;
397 	struct sparc_stackf *sp;
398 
399 	size = ((unsigned long)src->fp) - ((unsigned long)src);
400 	sp = (struct sparc_stackf *)(((unsigned long)dst) - size);
401 
402 	/* do_fork() grabs the parent semaphore, we must release it
403 	 * temporarily so we can build the child clone stack frame
404 	 * without deadlocking.
405 	 */
406 	if (copy_to_user(sp, src, size))
407 		sp = (struct sparc_stackf *) 0;
408 	else if (put_user(dst, &sp->fp))
409 		sp = (struct sparc_stackf *) 0;
410 
411 	return sp;
412 }
413 
414 
415 /* Copy a Sparc thread.  The fork() return value conventions
416  * under SunOS are nothing short of bletcherous:
417  * Parent -->  %o0 == childs  pid, %o1 == 0
418  * Child  -->  %o0 == parents pid, %o1 == 1
419  *
420  * NOTE: We have a separate fork kpsr/kwim because
421  *       the parent could change these values between
422  *       sys_fork invocation and when we reach here
423  *       if the parent should sleep while trying to
424  *       allocate the task_struct and kernel stack in
425  *       do_fork().
426  */
427 extern void ret_from_fork(void);
428 
429 int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
430 		unsigned long unused,
431 		struct task_struct *p, struct pt_regs *regs)
432 {
433 	struct pt_regs *childregs;
434 	char *new_stack;
435 
436 #ifndef CONFIG_SMP
437 	if(last_task_used_math == current) {
438 #else
439 	if(current->flags & PF_USEDFPU) {
440 #endif
441 		put_psr(get_psr() | PSR_EF);
442 		fpsave(&p->thread.float_regs[0], &p->thread.fsr,
443 		       &p->thread.fpqueue[0], &p->thread.fpqdepth);
444 #ifdef CONFIG_SMP
445 		current->flags &= ~PF_USEDFPU;
446 #endif
447 	}
448 
449 	/*
450 	 *  p                      new_stack   childregs
451 	 *  !                      !           !             {if(PSR_PS) }
452 	 *  V                      V (stk.fr.) V  (pt_regs)  { (stk.fr.) }
453 	 *  +----- - - - - - ------+===========+============={+==========}+
454 	 */
455 	new_stack = (char*)p + TASK_UNION_SIZE;
456 	if (regs->psr & PSR_PS)
457 		new_stack -= STACKFRAME_SZ;
458 	new_stack -= STACKFRAME_SZ + TRACEREG_SZ;
459 	memcpy(new_stack, (char *)regs - STACKFRAME_SZ, STACKFRAME_SZ + TRACEREG_SZ);
460 	childregs = (struct pt_regs *) (new_stack + STACKFRAME_SZ);
461 
462 	p->thread.ksp = (unsigned long) new_stack;
463 	p->thread.kpc = (((unsigned long) ret_from_fork) - 0x8);
464 	p->thread.kpsr = current->thread.fork_kpsr;
465 	p->thread.kwim = current->thread.fork_kwim;
466 
467 	/* This is used for sun4c only */
468 	atomic_set(&p->thread.refcount, 1);
469 
470 	if(regs->psr & PSR_PS) {
471 		extern struct pt_regs fake_swapper_regs;
472 
473 		p->thread.kregs = &fake_swapper_regs;
474 		new_stack += STACKFRAME_SZ + TRACEREG_SZ;
475 		childregs->u_regs[UREG_FP] = (unsigned long) new_stack;
476 		p->thread.flags |= SPARC_FLAG_KTHREAD;
477 		p->thread.current_ds = KERNEL_DS;
478 		memcpy(new_stack, (void *)regs->u_regs[UREG_FP], STACKFRAME_SZ);
479 		childregs->u_regs[UREG_G6] = (unsigned long) p;
480 	} else {
481 		p->thread.kregs = childregs;
482 		childregs->u_regs[UREG_FP] = sp;
483 		p->thread.flags &= ~SPARC_FLAG_KTHREAD;
484 		p->thread.current_ds = USER_DS;
485 
486 		if (sp != regs->u_regs[UREG_FP]) {
487 			struct sparc_stackf *childstack;
488 			struct sparc_stackf *parentstack;
489 
490 			/*
491 			 * This is a clone() call with supplied user stack.
492 			 * Set some valid stack frames to give to the child.
493 			 */
494 			childstack = (struct sparc_stackf *) (sp & ~0x7UL);
495 			parentstack = (struct sparc_stackf *) regs->u_regs[UREG_FP];
496 
497 #if 0
498 			printk("clone: parent stack:\n");
499 			show_stackframe(parentstack);
500 #endif
501 
502 			childstack = clone_stackframe(childstack, parentstack);
503 			if (!childstack)
504 				return -EFAULT;
505 
506 #if 0
507 			printk("clone: child stack:\n");
508 			show_stackframe(childstack);
509 #endif
510 
511 			childregs->u_regs[UREG_FP] = (unsigned long)childstack;
512 		}
513 	}
514 
515 #ifdef CONFIG_SMP
516 	/* FPU must be disabled on SMP. */
517 	childregs->psr &= ~PSR_EF;
518 #endif
519 
520 	/* Set the return value for the child. */
521 	childregs->u_regs[UREG_I0] = current->pid;
522 	childregs->u_regs[UREG_I1] = 1;
523 
524 	/* Set the return value for the parent. */
525 	regs->u_regs[UREG_I1] = 0;
526 
527 	return 0;
528 }
529 
530 /*
531  * fill in the user structure for a core dump..
532  */
533 void dump_thread(struct pt_regs * regs, struct user * dump)
534 {
535 	unsigned long first_stack_page;
536 
537 	dump->magic = SUNOS_CORE_MAGIC;
538 	dump->len = sizeof(struct user);
539 	dump->regs.psr = regs->psr;
540 	dump->regs.pc = regs->pc;
541 	dump->regs.npc = regs->npc;
542 	dump->regs.y = regs->y;
543 	/* fuck me plenty */
544 	memcpy(&dump->regs.regs[0], &regs->u_regs[1], (sizeof(unsigned long) * 15));
545 	dump->uexec = current->thread.core_exec;
546 	dump->u_tsize = (((unsigned long) current->mm->end_code) -
547 		((unsigned long) current->mm->start_code)) & ~(PAGE_SIZE - 1);
548 	dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1)));
549 	dump->u_dsize -= dump->u_tsize;
550 	dump->u_dsize &= ~(PAGE_SIZE - 1);
551 	first_stack_page = (regs->u_regs[UREG_FP] & ~(PAGE_SIZE - 1));
552 	dump->u_ssize = (TASK_SIZE - first_stack_page) & ~(PAGE_SIZE - 1);
553 	memcpy(&dump->fpu.fpstatus.fregs.regs[0], &current->thread.float_regs[0], (sizeof(unsigned long) * 32));
554 	dump->fpu.fpstatus.fsr = current->thread.fsr;
555 	dump->fpu.fpstatus.flags = dump->fpu.fpstatus.extra = 0;
556 	dump->fpu.fpstatus.fpq_count = current->thread.fpqdepth;
557 	memcpy(&dump->fpu.fpstatus.fpq[0], &current->thread.fpqueue[0],
558 	       ((sizeof(unsigned long) * 2) * 16));
559 	dump->sigcode = 0;
560 }
561 
562 /*
563  * fill in the fpu structure for a core dump.
564  */
565 int dump_fpu (struct pt_regs * regs, elf_fpregset_t * fpregs)
566 {
567 	if (current->used_math == 0) {
568 		memset(fpregs, 0, sizeof(*fpregs));
569 		fpregs->pr_q_entrysize = 8;
570 		return 1;
571 	}
572 #ifdef CONFIG_SMP
573 	if (current->flags & PF_USEDFPU) {
574 		put_psr(get_psr() | PSR_EF);
575 		fpsave(&current->thread.float_regs[0], &current->thread.fsr,
576 		       &current->thread.fpqueue[0], &current->thread.fpqdepth);
577 		regs->psr &= ~(PSR_EF);
578 		current->flags &= ~(PF_USEDFPU);
579 	}
580 #else
581 	if (current == last_task_used_math) {
582 		put_psr(get_psr() | PSR_EF);
583 		fpsave(&current->thread.float_regs[0], &current->thread.fsr,
584 		       &current->thread.fpqueue[0], &current->thread.fpqdepth);
585 		last_task_used_math = 0;
586 		regs->psr &= ~(PSR_EF);
587 	}
588 #endif
589 	memcpy(&fpregs->pr_fr.pr_regs[0],
590 	       &current->thread.float_regs[0],
591 	       (sizeof(unsigned long) * 32));
592 	fpregs->pr_fsr = current->thread.fsr;
593 	fpregs->pr_qcnt = current->thread.fpqdepth;
594 	fpregs->pr_q_entrysize = 8;
595 	fpregs->pr_en = 1;
596 	if(fpregs->pr_qcnt != 0) {
597 		memcpy(&fpregs->pr_q[0],
598 		       &current->thread.fpqueue[0],
599 		       sizeof(struct fpq) * fpregs->pr_qcnt);
600 	}
601 	/* Zero out the rest. */
602 	memset(&fpregs->pr_q[fpregs->pr_qcnt], 0,
603 	       sizeof(struct fpq) * (32 - fpregs->pr_qcnt));
604 	return 1;
605 }
606 
607 /*
608  * sparc_execve() executes a new program after the asm stub has set
609  * things up for us.  This should basically do what I want it to.
610  */
611 asmlinkage int sparc_execve(struct pt_regs *regs)
612 {
613 	int error, base = 0;
614 	char *filename;
615 
616 	/* Check for indirect call. */
617 	if(regs->u_regs[UREG_G1] == 0)
618 		base = 1;
619 
620 	filename = getname((char *)regs->u_regs[base + UREG_I0]);
621 	error = PTR_ERR(filename);
622 	if(IS_ERR(filename))
623 		goto out;
624 	error = do_execve(filename, (char **) regs->u_regs[base + UREG_I1],
625 			  (char **) regs->u_regs[base + UREG_I2], regs);
626 	putname(filename);
627 out:
628 	return error;
629 }
630 
631 /*
632  * This is the mechanism for creating a new kernel thread.
633  *
634  * NOTE! Only a kernel-only process(ie the swapper or direct descendants
635  * who haven't done an "execve()") should use this: it will work within
636  * a system call from a "real" process, but the process memory space will
637  * not be free'd until both the parent and the child have exited.
638  */
639 pid_t arch_kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
640 {
641 	long retval;
642 
643 	__asm__ __volatile("mov %4, %%g2\n\t"    /* Set aside fn ptr... */
644 			   "mov %5, %%g3\n\t"    /* and arg. */
645 			   "mov %1, %%g1\n\t"
646 			   "mov %2, %%o0\n\t"    /* Clone flags. */
647 			   "mov 0, %%o1\n\t"     /* usp arg == 0 */
648 			   "t 0x10\n\t"          /* Linux/Sparc clone(). */
649 			   "cmp %%o1, 0\n\t"
650 			   "be 1f\n\t"           /* The parent, just return. */
651 			   " nop\n\t"            /* Delay slot. */
652 			   "jmpl %%g2, %%o7\n\t" /* Call the function. */
653 			   " mov %%g3, %%o0\n\t" /* Get back the arg in delay. */
654 			   "mov %3, %%g1\n\t"
655 			   "t 0x10\n\t"          /* Linux/Sparc exit(). */
656 			   /* Notreached by child. */
657 			   "1: mov %%o0, %0\n\t" :
658 			   "=r" (retval) :
659 			   "i" (__NR_clone), "r" (flags | CLONE_VM),
660 			   "i" (__NR_exit),  "r" (fn), "r" (arg) :
661 			   "g1", "g2", "g3", "o0", "o1", "memory", "cc");
662 	return retval;
663 }
664