2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * arch/sh64/kernel/process.c
8 * Copyright (C) 2000, 2001 Paolo Alberelli
9 * Copyright (C) 2003 Paul Mundt
10 * Copyright (C) 2003, 2004 Richard Curnow
12 * Started from SH3/4 version:
13 * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
15 * In turn started from i386 version:
16 * Copyright (C) 1995 Linus Torvalds
21 * This file handles the architecture-dependent parts of process handling..
24 /* Temporary flags/tests. All to be removed/undefined. BEGIN */
26 #define VM_SHOW_TABLES
28 #define VM_TEST_RTLBMISS
29 #define VM_TEST_WTLBMISS
33 /* Temporary flags/tests. All to be removed/undefined. END */
35 #define __KERNEL_SYSCALLS__
38 #include <linux/config.h>
39 #include <linux/kernel.h>
40 #include <linux/rwsem.h>
42 #include <linux/smp.h>
43 #include <linux/smp_lock.h>
44 #include <linux/ptrace.h>
45 #include <linux/slab.h>
46 #include <linux/vmalloc.h>
47 #include <linux/user.h>
48 #include <linux/a.out.h>
49 #include <linux/interrupt.h>
50 #include <linux/unistd.h>
51 #include <linux/delay.h>
52 #include <linux/reboot.h>
53 #include <linux/init.h>
55 #include <asm/uaccess.h>
56 #include <asm/pgtable.h>
57 #include <asm/system.h>
59 #include <asm/processor.h> /* includes also <asm/registers.h> */
60 #include <asm/mmu_context.h>
64 #include <linux/irq.h>
66 struct task_struct *last_task_used_math = NULL;
71 static void print_PTE(long base)
74 long long x, y, *p = (long long *) base;
76 for (i=0; i< 512; i++, p++){
85 y = (*p) & 0xffffffff;
86 printk("%08Lx%08Lx ", x, y);
87 if (!((i+1)&0x3)) printk("\n");
93 static void print_DIR(long base)
96 long *p = (long *) base;
98 for (i=0; i< 512; i++, p++){
106 printk("%08lx ", *p);
107 if (!((i+1)&0x7)) printk("\n");
113 static void print_vmalloc_first_tables(void)
116 #define PRESENT 0x800 /* Bit 11 */
119 * Do it really dirty by looking at raw addresses,
120 * raw offsets, no types. If we used pgtable/pgalloc
121 * macros/definitions we could hide potential bugs.
123 * Note that pointers are 32-bit for CDC.
125 long pgdt, pmdt, ptet;
127 pgdt = (long) &swapper_pg_dir;
128 printk("-->PGD (0x%08lx):\n", pgdt);
132 /* VMALLOC pool is mapped at 0xc0000000, second (pointer) entry in PGD */
134 pmdt = (long) (* (long *) pgdt);
135 if (!(pmdt & PRESENT)) {
138 } else pmdt &= 0xfffff000;
140 printk("-->PMD (0x%08lx):\n", pmdt);
144 /* Get the pmdt displacement for 0xc0000000 */
147 /* just look at first two address ranges ... */
148 /* ... 0xc0000000 ... */
149 ptet = (long) (* (long *) pmdt);
150 if (!(ptet & PRESENT)) {
153 } else ptet &= 0xfffff000;
155 printk("-->PTE0 (0x%08lx):\n", ptet);
159 /* ... 0xc0001000 ... */
161 if (!(ptet & PRESENT)) {
164 } else ptet &= 0xfffff000;
165 printk("-->PTE1 (0x%08lx):\n", ptet);
170 #define print_vmalloc_first_tables()
171 #endif /* VM_SHOW_TABLES */
173 static void test_VM(void)
177 #ifdef VM_SHOW_TABLES
178 printk("Initial PGD/PMD/PTE\n");
180 print_vmalloc_first_tables();
182 printk("Allocating 2 bytes\n");
184 print_vmalloc_first_tables();
186 printk("Allocating 4100 bytes\n");
188 print_vmalloc_first_tables();
190 printk("Allocating 20234 bytes\n");
192 print_vmalloc_first_tables();
195 /* Here you may want to fault ! */
197 #ifdef VM_TEST_RTLBMISS
198 printk("Ready to fault upon read.\n");
200 printk("RTLBMISSed on area a !\n");
202 printk("RTLBMISSed on area a !\n");
205 #ifdef VM_TEST_WTLBMISS
206 printk("Ready to fault upon write.\n");
208 printk("WTLBMISSed on area b !\n");
211 #endif /* VM_TEST_FAULT */
213 printk("Deallocating the 4100 byte chunk\n");
215 print_vmalloc_first_tables();
217 printk("Deallocating the 2 byte chunk\n");
219 print_vmalloc_first_tables();
221 printk("Deallocating the last chunk\n");
223 print_vmalloc_first_tables();
226 extern unsigned long volatile jiffies;
228 unsigned long old_jiffies;
229 int pid = -1, pgid = -1;
231 void idle_trace(void)
234 _syscall0(int, getpid)
235 _syscall1(int, getpgid, int, pid)
238 /* VM allocation/deallocation simple test */
242 printk("Got all through to Idle !!\n");
243 printk("I'm now going to loop forever ...\n");
244 printk("Any ! below is a timer tick.\n");
245 printk("Any . below is a getpgid system call from pid = %d.\n", pid);
248 old_jiffies = jiffies;
252 if (old_jiffies != jiffies) {
253 old_jiffies = jiffies - old_jiffies;
254 switch (old_jiffies) {
268 printk("(%d!)", (int) old_jiffies);
270 old_jiffies = jiffies;
276 #define idle_trace() do { } while (0)
277 #endif /* IDLE_TRACE */
279 static int hlt_counter = 1;
281 #define HARD_IDLE_TIMEOUT (HZ / 3)
283 void disable_hlt(void)
288 void enable_hlt(void)
293 static int __init nohlt_setup(char *__unused)
299 static int __init hlt_setup(char *__unused)
305 __setup("nohlt", nohlt_setup);
306 __setup("hlt", hlt_setup);
308 static inline void hlt(void)
313 __asm__ __volatile__ ("sleep" : : : "memory");
317 * The idle loop on a uniprocessor SH..
319 void default_idle(void)
321 /* endless idle loop with no priority at all */
329 while (!need_resched()) {
337 preempt_enable_no_resched();
348 void machine_restart(char * __unused)
350 extern void phys_stext(void);
355 void machine_halt(void)
360 void machine_power_off(void)
362 extern void enter_deep_standby(void);
364 enter_deep_standby();
367 void show_regs(struct pt_regs * regs)
369 unsigned long long ah, al, bh, bl, ch, cl;
373 ah = (regs->pc) >> 32;
374 al = (regs->pc) & 0xffffffff;
375 bh = (regs->regs[18]) >> 32;
376 bl = (regs->regs[18]) & 0xffffffff;
377 ch = (regs->regs[15]) >> 32;
378 cl = (regs->regs[15]) & 0xffffffff;
379 printk("PC : %08Lx%08Lx LINK: %08Lx%08Lx SP : %08Lx%08Lx\n",
380 ah, al, bh, bl, ch, cl);
382 ah = (regs->sr) >> 32;
383 al = (regs->sr) & 0xffffffff;
384 asm volatile ("getcon " __TEA ", %0" : "=r" (bh));
385 asm volatile ("getcon " __TEA ", %0" : "=r" (bl));
387 bl = (bl) & 0xffffffff;
388 asm volatile ("getcon " __KCR0 ", %0" : "=r" (ch));
389 asm volatile ("getcon " __KCR0 ", %0" : "=r" (cl));
391 cl = (cl) & 0xffffffff;
392 printk("SR : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n",
393 ah, al, bh, bl, ch, cl);
395 ah = (regs->regs[0]) >> 32;
396 al = (regs->regs[0]) & 0xffffffff;
397 bh = (regs->regs[1]) >> 32;
398 bl = (regs->regs[1]) & 0xffffffff;
399 ch = (regs->regs[2]) >> 32;
400 cl = (regs->regs[2]) & 0xffffffff;
401 printk("R0 : %08Lx%08Lx R1 : %08Lx%08Lx R2 : %08Lx%08Lx\n",
402 ah, al, bh, bl, ch, cl);
404 ah = (regs->regs[3]) >> 32;
405 al = (regs->regs[3]) & 0xffffffff;
406 bh = (regs->regs[4]) >> 32;
407 bl = (regs->regs[4]) & 0xffffffff;
408 ch = (regs->regs[5]) >> 32;
409 cl = (regs->regs[5]) & 0xffffffff;
410 printk("R3 : %08Lx%08Lx R4 : %08Lx%08Lx R5 : %08Lx%08Lx\n",
411 ah, al, bh, bl, ch, cl);
413 ah = (regs->regs[6]) >> 32;
414 al = (regs->regs[6]) & 0xffffffff;
415 bh = (regs->regs[7]) >> 32;
416 bl = (regs->regs[7]) & 0xffffffff;
417 ch = (regs->regs[8]) >> 32;
418 cl = (regs->regs[8]) & 0xffffffff;
419 printk("R6 : %08Lx%08Lx R7 : %08Lx%08Lx R8 : %08Lx%08Lx\n",
420 ah, al, bh, bl, ch, cl);
422 ah = (regs->regs[9]) >> 32;
423 al = (regs->regs[9]) & 0xffffffff;
424 bh = (regs->regs[10]) >> 32;
425 bl = (regs->regs[10]) & 0xffffffff;
426 ch = (regs->regs[11]) >> 32;
427 cl = (regs->regs[11]) & 0xffffffff;
428 printk("R9 : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n",
429 ah, al, bh, bl, ch, cl);
431 ah = (regs->regs[12]) >> 32;
432 al = (regs->regs[12]) & 0xffffffff;
433 bh = (regs->regs[13]) >> 32;
434 bl = (regs->regs[13]) & 0xffffffff;
435 ch = (regs->regs[14]) >> 32;
436 cl = (regs->regs[14]) & 0xffffffff;
437 printk("R12 : %08Lx%08Lx R13 : %08Lx%08Lx R14 : %08Lx%08Lx\n",
438 ah, al, bh, bl, ch, cl);
440 ah = (regs->regs[16]) >> 32;
441 al = (regs->regs[16]) & 0xffffffff;
442 bh = (regs->regs[17]) >> 32;
443 bl = (regs->regs[17]) & 0xffffffff;
444 ch = (regs->regs[19]) >> 32;
445 cl = (regs->regs[19]) & 0xffffffff;
446 printk("R16 : %08Lx%08Lx R17 : %08Lx%08Lx R19 : %08Lx%08Lx\n",
447 ah, al, bh, bl, ch, cl);
449 ah = (regs->regs[20]) >> 32;
450 al = (regs->regs[20]) & 0xffffffff;
451 bh = (regs->regs[21]) >> 32;
452 bl = (regs->regs[21]) & 0xffffffff;
453 ch = (regs->regs[22]) >> 32;
454 cl = (regs->regs[22]) & 0xffffffff;
455 printk("R20 : %08Lx%08Lx R21 : %08Lx%08Lx R22 : %08Lx%08Lx\n",
456 ah, al, bh, bl, ch, cl);
458 ah = (regs->regs[23]) >> 32;
459 al = (regs->regs[23]) & 0xffffffff;
460 bh = (regs->regs[24]) >> 32;
461 bl = (regs->regs[24]) & 0xffffffff;
462 ch = (regs->regs[25]) >> 32;
463 cl = (regs->regs[25]) & 0xffffffff;
464 printk("R23 : %08Lx%08Lx R24 : %08Lx%08Lx R25 : %08Lx%08Lx\n",
465 ah, al, bh, bl, ch, cl);
467 ah = (regs->regs[26]) >> 32;
468 al = (regs->regs[26]) & 0xffffffff;
469 bh = (regs->regs[27]) >> 32;
470 bl = (regs->regs[27]) & 0xffffffff;
471 ch = (regs->regs[28]) >> 32;
472 cl = (regs->regs[28]) & 0xffffffff;
473 printk("R26 : %08Lx%08Lx R27 : %08Lx%08Lx R28 : %08Lx%08Lx\n",
474 ah, al, bh, bl, ch, cl);
476 ah = (regs->regs[29]) >> 32;
477 al = (regs->regs[29]) & 0xffffffff;
478 bh = (regs->regs[30]) >> 32;
479 bl = (regs->regs[30]) & 0xffffffff;
480 ch = (regs->regs[31]) >> 32;
481 cl = (regs->regs[31]) & 0xffffffff;
482 printk("R29 : %08Lx%08Lx R30 : %08Lx%08Lx R31 : %08Lx%08Lx\n",
483 ah, al, bh, bl, ch, cl);
485 ah = (regs->regs[32]) >> 32;
486 al = (regs->regs[32]) & 0xffffffff;
487 bh = (regs->regs[33]) >> 32;
488 bl = (regs->regs[33]) & 0xffffffff;
489 ch = (regs->regs[34]) >> 32;
490 cl = (regs->regs[34]) & 0xffffffff;
491 printk("R32 : %08Lx%08Lx R33 : %08Lx%08Lx R34 : %08Lx%08Lx\n",
492 ah, al, bh, bl, ch, cl);
494 ah = (regs->regs[35]) >> 32;
495 al = (regs->regs[35]) & 0xffffffff;
496 bh = (regs->regs[36]) >> 32;
497 bl = (regs->regs[36]) & 0xffffffff;
498 ch = (regs->regs[37]) >> 32;
499 cl = (regs->regs[37]) & 0xffffffff;
500 printk("R35 : %08Lx%08Lx R36 : %08Lx%08Lx R37 : %08Lx%08Lx\n",
501 ah, al, bh, bl, ch, cl);
503 ah = (regs->regs[38]) >> 32;
504 al = (regs->regs[38]) & 0xffffffff;
505 bh = (regs->regs[39]) >> 32;
506 bl = (regs->regs[39]) & 0xffffffff;
507 ch = (regs->regs[40]) >> 32;
508 cl = (regs->regs[40]) & 0xffffffff;
509 printk("R38 : %08Lx%08Lx R39 : %08Lx%08Lx R40 : %08Lx%08Lx\n",
510 ah, al, bh, bl, ch, cl);
512 ah = (regs->regs[41]) >> 32;
513 al = (regs->regs[41]) & 0xffffffff;
514 bh = (regs->regs[42]) >> 32;
515 bl = (regs->regs[42]) & 0xffffffff;
516 ch = (regs->regs[43]) >> 32;
517 cl = (regs->regs[43]) & 0xffffffff;
518 printk("R41 : %08Lx%08Lx R42 : %08Lx%08Lx R43 : %08Lx%08Lx\n",
519 ah, al, bh, bl, ch, cl);
521 ah = (regs->regs[44]) >> 32;
522 al = (regs->regs[44]) & 0xffffffff;
523 bh = (regs->regs[45]) >> 32;
524 bl = (regs->regs[45]) & 0xffffffff;
525 ch = (regs->regs[46]) >> 32;
526 cl = (regs->regs[46]) & 0xffffffff;
527 printk("R44 : %08Lx%08Lx R45 : %08Lx%08Lx R46 : %08Lx%08Lx\n",
528 ah, al, bh, bl, ch, cl);
530 ah = (regs->regs[47]) >> 32;
531 al = (regs->regs[47]) & 0xffffffff;
532 bh = (regs->regs[48]) >> 32;
533 bl = (regs->regs[48]) & 0xffffffff;
534 ch = (regs->regs[49]) >> 32;
535 cl = (regs->regs[49]) & 0xffffffff;
536 printk("R47 : %08Lx%08Lx R48 : %08Lx%08Lx R49 : %08Lx%08Lx\n",
537 ah, al, bh, bl, ch, cl);
539 ah = (regs->regs[50]) >> 32;
540 al = (regs->regs[50]) & 0xffffffff;
541 bh = (regs->regs[51]) >> 32;
542 bl = (regs->regs[51]) & 0xffffffff;
543 ch = (regs->regs[52]) >> 32;
544 cl = (regs->regs[52]) & 0xffffffff;
545 printk("R50 : %08Lx%08Lx R51 : %08Lx%08Lx R52 : %08Lx%08Lx\n",
546 ah, al, bh, bl, ch, cl);
548 ah = (regs->regs[53]) >> 32;
549 al = (regs->regs[53]) & 0xffffffff;
550 bh = (regs->regs[54]) >> 32;
551 bl = (regs->regs[54]) & 0xffffffff;
552 ch = (regs->regs[55]) >> 32;
553 cl = (regs->regs[55]) & 0xffffffff;
554 printk("R53 : %08Lx%08Lx R54 : %08Lx%08Lx R55 : %08Lx%08Lx\n",
555 ah, al, bh, bl, ch, cl);
557 ah = (regs->regs[56]) >> 32;
558 al = (regs->regs[56]) & 0xffffffff;
559 bh = (regs->regs[57]) >> 32;
560 bl = (regs->regs[57]) & 0xffffffff;
561 ch = (regs->regs[58]) >> 32;
562 cl = (regs->regs[58]) & 0xffffffff;
563 printk("R56 : %08Lx%08Lx R57 : %08Lx%08Lx R58 : %08Lx%08Lx\n",
564 ah, al, bh, bl, ch, cl);
566 ah = (regs->regs[59]) >> 32;
567 al = (regs->regs[59]) & 0xffffffff;
568 bh = (regs->regs[60]) >> 32;
569 bl = (regs->regs[60]) & 0xffffffff;
570 ch = (regs->regs[61]) >> 32;
571 cl = (regs->regs[61]) & 0xffffffff;
572 printk("R59 : %08Lx%08Lx R60 : %08Lx%08Lx R61 : %08Lx%08Lx\n",
573 ah, al, bh, bl, ch, cl);
575 ah = (regs->regs[62]) >> 32;
576 al = (regs->regs[62]) & 0xffffffff;
577 bh = (regs->tregs[0]) >> 32;
578 bl = (regs->tregs[0]) & 0xffffffff;
579 ch = (regs->tregs[1]) >> 32;
580 cl = (regs->tregs[1]) & 0xffffffff;
581 printk("R62 : %08Lx%08Lx T0 : %08Lx%08Lx T1 : %08Lx%08Lx\n",
582 ah, al, bh, bl, ch, cl);
584 ah = (regs->tregs[2]) >> 32;
585 al = (regs->tregs[2]) & 0xffffffff;
586 bh = (regs->tregs[3]) >> 32;
587 bl = (regs->tregs[3]) & 0xffffffff;
588 ch = (regs->tregs[4]) >> 32;
589 cl = (regs->tregs[4]) & 0xffffffff;
590 printk("T2 : %08Lx%08Lx T3 : %08Lx%08Lx T4 : %08Lx%08Lx\n",
591 ah, al, bh, bl, ch, cl);
593 ah = (regs->tregs[5]) >> 32;
594 al = (regs->tregs[5]) & 0xffffffff;
595 bh = (regs->tregs[6]) >> 32;
596 bl = (regs->tregs[6]) & 0xffffffff;
597 ch = (regs->tregs[7]) >> 32;
598 cl = (regs->tregs[7]) & 0xffffffff;
599 printk("T5 : %08Lx%08Lx T6 : %08Lx%08Lx T7 : %08Lx%08Lx\n",
600 ah, al, bh, bl, ch, cl);
603 * If we're in kernel mode, dump the stack too..
605 if (!user_mode(regs)) {
606 void show_stack(struct task_struct *tsk, unsigned long *sp);
607 unsigned long sp = regs->regs[15] & 0xffffffff;
608 struct task_struct *tsk = get_current();
610 tsk->thread.kregs = regs;
612 show_stack(tsk, (unsigned long *)sp);
616 struct task_struct * alloc_task_struct(void)
618 /* Get task descriptor pages */
619 return (struct task_struct *)
620 __get_free_pages(GFP_KERNEL, get_order(THREAD_SIZE));
623 void free_task_struct(struct task_struct *p)
625 free_pages((unsigned long) p, get_order(THREAD_SIZE));
629 * Create a kernel thread
633 * This is the mechanism for creating a new kernel thread.
635 * NOTE! Only a kernel-only process(ie the swapper or direct descendants
636 * who haven't done an "execve()") should use this: it will work within
637 * a system call from a "real" process, but the process memory space will
638 * not be free'd until both the parent and the child have exited.
640 int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
642 /* A bit less processor dependent than older sh ... */
645 static __inline__ _syscall2(int,clone,unsigned long,flags,unsigned long,newsp)
646 static __inline__ _syscall1(int,exit,int,ret)
648 reply = clone(flags | CLONE_VM, 0);
651 reply = exit(fn(arg));
658 * Free current thread data structures etc..
660 void exit_thread(void)
662 /* See arch/sparc/kernel/process.c for the precedent for doing this -- RPC.
664 The SH-5 FPU save/restore approach relies on last_task_used_math
665 pointing to a live task_struct. When another task tries to use the
666 FPU for the 1st time, the FPUDIS trap handling (see
667 arch/sh64/kernel/fpu.c) will save the existing FPU state to the
668 FP regs field within last_task_used_math before re-loading the new
669 task's FPU state (or initialising it if the FPU has been used
670 before). So if last_task_used_math is stale, and its page has already been
671 re-allocated for another use, the consequences are rather grim. Unless we
672 null it here, there is no other path through which it would get safely
676 if (last_task_used_math == current) {
677 last_task_used_math = NULL;
682 void flush_thread(void)
685 /* Called by fs/exec.c (flush_old_exec) to remove traces of a
686 * previously running executable. */
688 if (last_task_used_math == current) {
689 last_task_used_math = NULL;
691 /* Force FPU state to be reinitialised after exec */
695 /* if we are a kernel thread, about to change to user thread,
698 if(current->thread.kregs==&fake_swapper_regs) {
699 current->thread.kregs =
700 ((struct pt_regs *)(THREAD_SIZE + (unsigned long) current) - 1);
701 current->thread.uregs = current->thread.kregs;
705 void release_thread(struct task_struct *dead_task)
710 /* Fill in the fpu structure for a core dump.. */
711 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
715 struct task_struct *tsk = current;
717 fpvalid = !!tsk_used_math(tsk);
719 if (current == last_task_used_math) {
721 fpsave(&tsk->thread.fpu.hard);
723 last_task_used_math = 0;
727 memcpy(fpu, &tsk->thread.fpu.hard, sizeof(*fpu));
732 return 0; /* Task didn't use the fpu at all. */
736 asmlinkage void ret_from_fork(void);
738 int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
739 unsigned long unused,
740 struct task_struct *p, struct pt_regs *regs)
742 struct pt_regs *childregs;
743 unsigned long long se; /* Sign extension */
746 if(last_task_used_math == current) {
748 fpsave(¤t->thread.fpu.hard);
750 last_task_used_math = NULL;
754 /* Copy from sh version */
755 childregs = ((struct pt_regs *)(THREAD_SIZE + (unsigned long) p->thread_info )) - 1;
759 if (user_mode(regs)) {
760 childregs->regs[15] = usp;
761 p->thread.uregs = childregs;
763 childregs->regs[15] = (unsigned long)p->thread_info + THREAD_SIZE;
766 childregs->regs[9] = 0; /* Set return value for child */
767 childregs->sr |= SR_FD; /* Invalidate FPU flag */
769 p->thread.sp = (unsigned long) childregs;
770 p->thread.pc = (unsigned long) ret_from_fork;
773 * Sign extend the edited stack.
774 * Note that thread.pc and thread.pc will stay
775 * 32-bit wide and context switch must take care
776 * of NEFF sign extension.
779 se = childregs->regs[15];
780 se = (se & NEFF_SIGN) ? (se | NEFF_MASK) : se;
781 childregs->regs[15] = se;
787 * fill in the user structure for a core dump..
789 void dump_thread(struct pt_regs * regs, struct user * dump)
791 dump->magic = CMAGIC;
792 dump->start_code = current->mm->start_code;
793 dump->start_data = current->mm->start_data;
794 dump->start_stack = regs->regs[15] & ~(PAGE_SIZE - 1);
795 dump->u_tsize = (current->mm->end_code - dump->start_code) >> PAGE_SHIFT;
796 dump->u_dsize = (current->mm->brk + (PAGE_SIZE-1) - dump->start_data) >> PAGE_SHIFT;
797 dump->u_ssize = (current->mm->start_stack - dump->start_stack +
798 PAGE_SIZE - 1) >> PAGE_SHIFT;
799 /* Debug registers will come here. */
803 dump->u_fpvalid = dump_fpu(regs, &dump->fpu);
806 asmlinkage int sys_fork(unsigned long r2, unsigned long r3,
807 unsigned long r4, unsigned long r5,
808 unsigned long r6, unsigned long r7,
809 struct pt_regs *pregs)
811 return do_fork(SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
814 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
815 unsigned long r4, unsigned long r5,
816 unsigned long r6, unsigned long r7,
817 struct pt_regs *pregs)
820 newsp = pregs->regs[15];
821 return do_fork(clone_flags, newsp, pregs, 0, 0, 0);
825 * This is trivial, and on the face of it looks like it
826 * could equally well be done in user mode.
828 * Not so, for quite unobvious reasons - register pressure.
829 * In user mode vfork() cannot have a stack frame, and if
830 * done by calling the "clone()" system call directly, you
831 * do not have enough call-clobbered registers to hold all
832 * the information you need.
834 asmlinkage int sys_vfork(unsigned long r2, unsigned long r3,
835 unsigned long r4, unsigned long r5,
836 unsigned long r6, unsigned long r7,
837 struct pt_regs *pregs)
839 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
843 * sys_execve() executes a new program.
845 asmlinkage int sys_execve(char *ufilename, char **uargv,
846 char **uenvp, unsigned long r5,
847 unsigned long r6, unsigned long r7,
848 struct pt_regs *pregs)
854 filename = getname((char __user *)ufilename);
855 error = PTR_ERR(filename);
856 if (IS_ERR(filename))
859 error = do_execve(filename,
860 (char __user * __user *)uargv,
861 (char __user * __user *)uenvp,
865 current->ptrace &= ~PT_DTRACE;
866 task_unlock(current);
875 * These bracket the sleeping functions..
877 extern void interruptible_sleep_on(wait_queue_head_t *q);
879 #define mid_sched ((unsigned long) interruptible_sleep_on)
881 static int in_sh64_switch_to(unsigned long pc)
883 extern char __sh64_switch_to_end;
884 /* For a sleeping task, the PC is somewhere in the middle of the function,
885 so we don't have to worry about masking the LSB off */
886 return (pc >= (unsigned long) sh64_switch_to) &&
887 (pc < (unsigned long) &__sh64_switch_to_end);
890 unsigned long get_wchan(struct task_struct *p)
892 unsigned long schedule_fp;
893 unsigned long sh64_switch_to_fp;
894 unsigned long schedule_caller_pc;
897 if (!p || p == current || p->state == TASK_RUNNING)
901 * The same comment as on the Alpha applies here, too ...
903 pc = thread_saved_pc(p);
905 #ifdef CONFIG_FRAME_POINTER
906 if (in_sh64_switch_to(pc)) {
907 sh64_switch_to_fp = (long) p->thread.sp;
908 /* r14 is saved at offset 4 in the sh64_switch_to frame */
909 schedule_fp = *(unsigned long *) (long)(sh64_switch_to_fp + 4);
911 /* and the caller of 'schedule' is (currently!) saved at offset 24
912 in the frame of schedule (from disasm) */
913 schedule_caller_pc = *(unsigned long *) (long)(schedule_fp + 24);
914 return schedule_caller_pc;
920 /* Provide a /proc/asids file that lists out the
921 ASIDs currently associated with the processes. (If the DM.PC register is
922 examined through the debug link, this shows ASID + PC. To make use of this,
923 the PID->ASID relationship needs to be known. This is primarily for
927 #if defined(CONFIG_SH64_PROC_ASIDS)
928 #include <linux/init.h>
929 #include <linux/proc_fs.h>
932 asids_proc_info(char *buf, char **start, off_t fpos, int length, int *eof, void *data)
935 struct task_struct *p;
936 read_lock(&tasklist_lock);
937 for_each_process(p) {
939 struct mm_struct *mm;
943 unsigned long asid, context;
944 context = mm->context;
945 asid = (context & 0xff);
946 len += sprintf(buf+len, "%5d : %02lx\n", pid, asid);
948 len += sprintf(buf+len, "%5d : (none)\n", pid);
951 read_unlock(&tasklist_lock);
956 static int __init register_proc_asids(void)
958 create_proc_read_entry("asids", 0, NULL, asids_proc_info, NULL);
962 __initcall(register_proc_asids);