sched/headers: Prepare for new header dependencies before moving code to <linux/sched...
[platform/kernel/linux-exynos.git] / arch / cris / arch-v32 / kernel / process.c
1 /*
2  *  Copyright (C) 2000-2003  Axis Communications AB
3  *
4  *  Authors:   Bjorn Wesen (bjornw@axis.com)
5  *             Mikael Starvik (starvik@axis.com)
6  *             Tobias Anderberg (tobiasa@axis.com), CRISv32 port.
7  *
8  * This file handles the architecture-dependent parts of process handling..
9  */
10
11 #include <linux/sched.h>
12 #include <linux/sched/debug.h>
13 #include <linux/sched/task.h>
14 #include <linux/slab.h>
15 #include <linux/err.h>
16 #include <linux/fs.h>
17 #include <hwregs/reg_rdwr.h>
18 #include <hwregs/reg_map.h>
19 #include <hwregs/timer_defs.h>
20 #include <hwregs/intr_vect_defs.h>
21 #include <linux/ptrace.h>
22
23 extern void stop_watchdog(void);
24
25 /* We use this if we don't have any better idle routine. */
26 void default_idle(void)
27 {
28         local_irq_enable();
29         /* Halt until exception. */
30         __asm__ volatile("halt");
31 }
32
33 /*
34  * Free current thread data structures etc..
35  */
36
37 extern void deconfigure_bp(long pid);
38 void exit_thread(struct task_struct *tsk)
39 {
40         deconfigure_bp(tsk->pid);
41 }
42
43 /*
44  * If the watchdog is enabled, disable interrupts and enter an infinite loop.
45  * The watchdog will reset the CPU after 0.1s. If the watchdog isn't enabled
46  * then enable it and wait.
47  */
48 extern void arch_enable_nmi(void);
49
50 void
51 hard_reset_now(void)
52 {
53         /*
54          * Don't declare this variable elsewhere.  We don't want any other
55          * code to know about it than the watchdog handler in entry.S and
56          * this code, implementing hard reset through the watchdog.
57          */
58 #if defined(CONFIG_ETRAX_WATCHDOG)
59         extern int cause_of_death;
60 #endif
61
62         printk("*** HARD RESET ***\n");
63         local_irq_disable();
64
65 #if defined(CONFIG_ETRAX_WATCHDOG)
66         cause_of_death = 0xbedead;
67 #else
68 {
69         reg_timer_rw_wd_ctrl wd_ctrl = {0};
70
71         stop_watchdog();
72
73         wd_ctrl.key = 16;       /* Arbitrary key. */
74         wd_ctrl.cnt = 1;        /* Minimum time. */
75         wd_ctrl.cmd = regk_timer_start;
76
77         arch_enable_nmi();
78         REG_WR(timer, regi_timer0, rw_wd_ctrl, wd_ctrl);
79 }
80 #endif
81
82         while (1)
83                 ; /* Wait for reset. */
84 }
85
86 /*
87  * Return saved PC of a blocked thread.
88  */
89 unsigned long thread_saved_pc(struct task_struct *t)
90 {
91         return task_pt_regs(t)->erp;
92 }
93
94 /*
95  * Setup the child's kernel stack with a pt_regs and call switch_stack() on it.
96  * It will be unnested during _resume and _ret_from_sys_call when the new thread
97  * is scheduled.
98  *
99  * Also setup the thread switching structure which is used to keep
100  * thread-specific data during _resumes.
101  */
102
103 extern asmlinkage void ret_from_fork(void);
104 extern asmlinkage void ret_from_kernel_thread(void);
105
106 int
107 copy_thread(unsigned long clone_flags, unsigned long usp,
108         unsigned long arg, struct task_struct *p)
109 {
110         struct pt_regs *childregs = task_pt_regs(p);
111         struct switch_stack *swstack = ((struct switch_stack *) childregs) - 1;
112
113         /*
114          * Put the pt_regs structure at the end of the new kernel stack page and
115          * fix it up. Note: the task_struct doubles as the kernel stack for the
116          * task.
117          */
118         if (unlikely(p->flags & PF_KTHREAD)) {
119                 memset(swstack, 0,
120                         sizeof(struct switch_stack) + sizeof(struct pt_regs));
121                 swstack->r1 = usp;
122                 swstack->r2 = arg;
123                 childregs->ccs = 1 << (I_CCS_BITNR + CCS_SHIFT);
124                 swstack->return_ip = (unsigned long) ret_from_kernel_thread;
125                 p->thread.ksp = (unsigned long) swstack;
126                 p->thread.usp = 0;
127                 return 0;
128         }
129         *childregs = *current_pt_regs();        /* Struct copy of pt_regs. */
130         childregs->r10 = 0;     /* Child returns 0 after a fork/clone. */
131
132         /* Set a new TLS ?
133          * The TLS is in $mof because it is the 5th argument to sys_clone.
134          */
135         if (p->mm && (clone_flags & CLONE_SETTLS)) {
136                 task_thread_info(p)->tls = childregs->mof;
137         }
138
139         /* Put the switch stack right below the pt_regs. */
140
141         /* Parameter to ret_from_sys_call. 0 is don't restart the syscall. */
142         swstack->r9 = 0;
143
144         /*
145          * We want to return into ret_from_sys_call after the _resume.
146          * ret_from_fork will call ret_from_sys_call.
147          */
148         swstack->return_ip = (unsigned long) ret_from_fork;
149
150         /* Fix the user-mode and kernel-mode stackpointer. */
151         p->thread.usp = usp ?: rdusp();
152         p->thread.ksp = (unsigned long) swstack;
153
154         return 0;
155 }
156
157 unsigned long
158 get_wchan(struct task_struct *p)
159 {
160         /* TODO */
161         return 0;
162 }
163 #undef last_sched
164 #undef first_sched
165
166 void show_regs(struct pt_regs * regs)
167 {
168         unsigned long usp = rdusp();
169
170         show_regs_print_info(KERN_DEFAULT);
171
172         printk("ERP: %08lx SRP: %08lx  CCS: %08lx USP: %08lx MOF: %08lx\n",
173                 regs->erp, regs->srp, regs->ccs, usp, regs->mof);
174
175         printk(" r0: %08lx  r1: %08lx   r2: %08lx  r3: %08lx\n",
176                 regs->r0, regs->r1, regs->r2, regs->r3);
177
178         printk(" r4: %08lx  r5: %08lx   r6: %08lx  r7: %08lx\n",
179                 regs->r4, regs->r5, regs->r6, regs->r7);
180
181         printk(" r8: %08lx  r9: %08lx  r10: %08lx r11: %08lx\n",
182                 regs->r8, regs->r9, regs->r10, regs->r11);
183
184         printk("r12: %08lx r13: %08lx oR10: %08lx\n",
185                 regs->r12, regs->r13, regs->orig_r10);
186 }