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