2 * linux/arch/cris/kernel/process.c
4 * Copyright (C) 1995 Linus Torvalds
5 * Copyright (C) 2000-2002 Axis Communications AB
7 * Authors: Bjorn Wesen (bjornw@axis.com)
8 * Mikael Starvik (starvik@axis.com)
10 * This file handles the architecture-dependent parts of process handling..
13 #include <linux/sched.h>
14 #include <linux/slab.h>
15 #include <linux/err.h>
17 #include <arch/svinto.h>
18 #include <linux/init.h>
19 #include <arch/system.h>
20 #include <linux/ptrace.h>
22 #ifdef CONFIG_ETRAX_GPIO
23 void etrax_gpio_wake_up_check(void); /* drivers/gpio.c */
27 * We use this if we don't have any better
30 void default_idle(void)
32 #ifdef CONFIG_ETRAX_GPIO
33 etrax_gpio_wake_up_check();
39 * Free current thread data structures etc..
42 void exit_thread(void)
44 /* Nothing needs to be done. */
47 /* if the watchdog is enabled, we can simply disable interrupts and go
48 * into an eternal loop, and the watchdog will reset the CPU after 0.1s
49 * if on the other hand the watchdog wasn't enabled, we just enable it and wait
52 void hard_reset_now (void)
55 * Don't declare this variable elsewhere. We don't want any other
56 * code to know about it than the watchdog handler in entry.S and
57 * this code, implementing hard reset through the watchdog.
59 #if defined(CONFIG_ETRAX_WATCHDOG)
60 extern int cause_of_death
;
63 printk("*** HARD RESET ***\n");
66 #if defined(CONFIG_ETRAX_WATCHDOG)
67 cause_of_death
= 0xbedead;
69 /* Since we dont plan to keep on resetting the watchdog,
70 the key can be arbitrary hence three */
71 *R_WATCHDOG
= IO_FIELD(R_WATCHDOG
, key
, 3) |
72 IO_STATE(R_WATCHDOG
, enable
, start
);
75 while(1) /* waiting for RETRIBUTION! */ ;
79 * Return saved PC of a blocked thread.
81 unsigned long thread_saved_pc(struct task_struct
*t
)
83 return task_pt_regs(t
)->irp
;
86 /* setup the child's kernel stack with a pt_regs and switch_stack on it.
87 * it will be un-nested during _resume and _ret_from_sys_call when the
88 * new thread is scheduled.
90 * also setup the thread switching structure which is used to keep
91 * thread-specific data during _resumes.
94 asmlinkage
void ret_from_fork(void);
95 asmlinkage
void ret_from_kernel_thread(void);
97 int copy_thread(unsigned long clone_flags
, unsigned long usp
,
98 unsigned long arg
, struct task_struct
*p
)
100 struct pt_regs
*childregs
= task_pt_regs(p
);
101 struct switch_stack
*swstack
= ((struct switch_stack
*)childregs
) - 1;
103 /* put the pt_regs structure at the end of the new kernel stack page and fix it up
104 * remember that the task_struct doubles as the kernel stack for the task
107 if (unlikely(p
->flags
& PF_KTHREAD
)) {
109 sizeof(struct switch_stack
) + sizeof(struct pt_regs
));
112 childregs
->dccr
= 1 << I_DCCR_BITNR
;
113 swstack
->return_ip
= (unsigned long) ret_from_kernel_thread
;
114 p
->thread
.ksp
= (unsigned long) swstack
;
118 *childregs
= *current_pt_regs(); /* struct copy of pt_regs */
120 childregs
->r10
= 0; /* child returns 0 after a fork/clone */
122 /* put the switch stack right below the pt_regs */
124 swstack
->r9
= 0; /* parameter to ret_from_sys_call, 0 == dont restart the syscall */
126 /* we want to return into ret_from_sys_call after the _resume */
128 swstack
->return_ip
= (unsigned long) ret_from_fork
; /* Will call ret_from_sys_call */
130 /* fix the user-mode stackpointer */
132 p
->thread
.usp
= usp
?: rdusp();
134 /* and the kernel-mode one */
136 p
->thread
.ksp
= (unsigned long) swstack
;
139 printk("copy_thread: new regs at 0x%p, as shown below:\n", childregs
);
140 show_registers(childregs
);
146 unsigned long get_wchan(struct task_struct
*p
)
151 unsigned long ebp
, esp
, eip
;
152 unsigned long stack_page
;
154 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
156 stack_page
= (unsigned long)p
;
158 if (!stack_page
|| esp
< stack_page
|| esp
> 8188+stack_page
)
160 /* include/asm-i386/system.h:switch_to() pushes ebp last. */
161 ebp
= *(unsigned long *) esp
;
163 if (ebp
< stack_page
|| ebp
> 8184+stack_page
)
165 eip
= *(unsigned long *) (ebp
+4);
166 if (!in_sched_functions(eip
))
168 ebp
= *(unsigned long *) ebp
;
169 } while (count
++ < 16);
176 void show_regs(struct pt_regs
* regs
)
178 unsigned long usp
= rdusp();
180 show_regs_print_info(KERN_DEFAULT
);
182 printk("IRP: %08lx SRP: %08lx DCCR: %08lx USP: %08lx MOF: %08lx\n",
183 regs
->irp
, regs
->srp
, regs
->dccr
, usp
, regs
->mof
);
184 printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n",
185 regs
->r0
, regs
->r1
, regs
->r2
, regs
->r3
);
186 printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
187 regs
->r4
, regs
->r5
, regs
->r6
, regs
->r7
);
188 printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
189 regs
->r8
, regs
->r9
, regs
->r10
, regs
->r11
);
190 printk("r12: %08lx r13: %08lx oR10: %08lx\n",
191 regs
->r12
, regs
->r13
, regs
->orig_r10
);