Merge remote-tracking branches 'asoc/topic/cs4271', 'asoc/topic/cs53l30', 'asoc/topic...
[sfrench/cifs-2.6.git] / arch / cris / arch-v10 / kernel / process.c
1 /*
2  *  linux/arch/cris/kernel/process.c
3  *
4  *  Copyright (C) 1995  Linus Torvalds
5  *  Copyright (C) 2000-2002  Axis Communications AB
6  *
7  *  Authors:   Bjorn Wesen (bjornw@axis.com)
8  *             Mikael Starvik (starvik@axis.com)
9  *
10  * This file handles the architecture-dependent parts of process handling..
11  */
12
13 #include <linux/sched.h>
14 #include <linux/sched/debug.h>
15 #include <linux/sched/task.h>
16 #include <linux/sched/task_stack.h>
17 #include <linux/slab.h>
18 #include <linux/err.h>
19 #include <linux/fs.h>
20 #include <arch/svinto.h>
21 #include <linux/init.h>
22 #include <arch/system.h>
23 #include <linux/ptrace.h>
24
25 #ifdef CONFIG_ETRAX_GPIO
26 void etrax_gpio_wake_up_check(void); /* drivers/gpio.c */
27 #endif
28
29 /*
30  * We use this if we don't have any better
31  * idle routine..
32  */
33 void default_idle(void)
34 {
35 #ifdef CONFIG_ETRAX_GPIO
36         etrax_gpio_wake_up_check();
37 #endif
38         local_irq_enable();
39 }
40
41 /* if the watchdog is enabled, we can simply disable interrupts and go
42  * into an eternal loop, and the watchdog will reset the CPU after 0.1s
43  * if on the other hand the watchdog wasn't enabled, we just enable it and wait
44  */
45
46 void hard_reset_now (void)
47 {
48         /*
49          * Don't declare this variable elsewhere.  We don't want any other
50          * code to know about it than the watchdog handler in entry.S and
51          * this code, implementing hard reset through the watchdog.
52          */
53 #if defined(CONFIG_ETRAX_WATCHDOG)
54         extern int cause_of_death;
55 #endif
56
57         printk("*** HARD RESET ***\n");
58         local_irq_disable();
59
60 #if defined(CONFIG_ETRAX_WATCHDOG)
61         cause_of_death = 0xbedead;
62 #else
63         /* Since we dont plan to keep on resetting the watchdog,
64            the key can be arbitrary hence three */
65         *R_WATCHDOG = IO_FIELD(R_WATCHDOG, key, 3) |
66                 IO_STATE(R_WATCHDOG, enable, start);
67 #endif
68
69         while(1) /* waiting for RETRIBUTION! */ ;
70 }
71
72 /* setup the child's kernel stack with a pt_regs and switch_stack on it.
73  * it will be un-nested during _resume and _ret_from_sys_call when the
74  * new thread is scheduled.
75  *
76  * also setup the thread switching structure which is used to keep
77  * thread-specific data during _resumes.
78  *
79  */
80 asmlinkage void ret_from_fork(void);
81 asmlinkage void ret_from_kernel_thread(void);
82
83 int copy_thread(unsigned long clone_flags, unsigned long usp,
84                 unsigned long arg, struct task_struct *p)
85 {
86         struct pt_regs *childregs = task_pt_regs(p);
87         struct switch_stack *swstack = ((struct switch_stack *)childregs) - 1;
88         
89         /* put the pt_regs structure at the end of the new kernel stack page and fix it up
90          * remember that the task_struct doubles as the kernel stack for the task
91          */
92
93         if (unlikely(p->flags & PF_KTHREAD)) {
94                 memset(swstack, 0,
95                         sizeof(struct switch_stack) + sizeof(struct pt_regs));
96                 swstack->r1 = usp;
97                 swstack->r2 = arg;
98                 childregs->dccr = 1 << I_DCCR_BITNR;
99                 swstack->return_ip = (unsigned long) ret_from_kernel_thread;
100                 p->thread.ksp = (unsigned long) swstack;
101                 p->thread.usp = 0;
102                 return 0;
103         }
104         *childregs = *current_pt_regs();  /* struct copy of pt_regs */
105
106         childregs->r10 = 0;  /* child returns 0 after a fork/clone */
107
108         /* put the switch stack right below the pt_regs */
109
110         swstack->r9 = 0; /* parameter to ret_from_sys_call, 0 == dont restart the syscall */
111
112         /* we want to return into ret_from_sys_call after the _resume */
113
114         swstack->return_ip = (unsigned long) ret_from_fork; /* Will call ret_from_sys_call */
115         
116         /* fix the user-mode stackpointer */
117
118         p->thread.usp = usp ?: rdusp();
119
120         /* and the kernel-mode one */
121
122         p->thread.ksp = (unsigned long) swstack;
123
124 #ifdef DEBUG
125         printk("copy_thread: new regs at 0x%p, as shown below:\n", childregs);
126         show_registers(childregs);
127 #endif
128
129         return 0;
130 }
131
132 unsigned long get_wchan(struct task_struct *p)
133 {
134 #if 0
135         /* YURGH. TODO. */
136
137         unsigned long ebp, esp, eip;
138         unsigned long stack_page;
139         int count = 0;
140         if (!p || p == current || p->state == TASK_RUNNING)
141                 return 0;
142         stack_page = (unsigned long)p;
143         esp = p->thread.esp;
144         if (!stack_page || esp < stack_page || esp > 8188+stack_page)
145                 return 0;
146         /* include/asm-i386/system.h:switch_to() pushes ebp last. */
147         ebp = *(unsigned long *) esp;
148         do {
149                 if (ebp < stack_page || ebp > 8184+stack_page)
150                         return 0;
151                 eip = *(unsigned long *) (ebp+4);
152                 if (!in_sched_functions(eip))
153                         return eip;
154                 ebp = *(unsigned long *) ebp;
155         } while (count++ < 16);
156 #endif
157         return 0;
158 }
159 #undef last_sched
160 #undef first_sched
161
162 void show_regs(struct pt_regs * regs)
163 {
164         unsigned long usp = rdusp();
165
166         show_regs_print_info(KERN_DEFAULT);
167
168         printk("IRP: %08lx SRP: %08lx DCCR: %08lx USP: %08lx MOF: %08lx\n",
169                regs->irp, regs->srp, regs->dccr, usp, regs->mof );
170         printk(" r0: %08lx  r1: %08lx   r2: %08lx  r3: %08lx\n",
171                regs->r0, regs->r1, regs->r2, regs->r3);
172         printk(" r4: %08lx  r5: %08lx   r6: %08lx  r7: %08lx\n",
173                regs->r4, regs->r5, regs->r6, regs->r7);
174         printk(" r8: %08lx  r9: %08lx  r10: %08lx r11: %08lx\n",
175                regs->r8, regs->r9, regs->r10, regs->r11);
176         printk("r12: %08lx r13: %08lx oR10: %08lx\n",
177                regs->r12, regs->r13, regs->orig_r10);
178 }
179