aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/kernel/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/kernel/process.c')
-rw-r--r--arch/mips/kernel/process.c68
1 files changed, 24 insertions, 44 deletions
diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index e9a5fd7277f4..a11c6f9fdd5e 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -72,9 +72,7 @@ void __noreturn cpu_idle(void)
72 } 72 }
73 } 73 }
74#ifdef CONFIG_HOTPLUG_CPU 74#ifdef CONFIG_HOTPLUG_CPU
75 if (!cpu_online(cpu) && !cpu_isset(cpu, cpu_callin_map) && 75 if (!cpu_online(cpu) && !cpu_isset(cpu, cpu_callin_map))
76 (system_state == SYSTEM_RUNNING ||
77 system_state == SYSTEM_BOOTING))
78 play_dead(); 76 play_dead();
79#endif 77#endif
80 rcu_idle_exit(); 78 rcu_idle_exit();
@@ -84,6 +82,7 @@ void __noreturn cpu_idle(void)
84} 82}
85 83
86asmlinkage void ret_from_fork(void); 84asmlinkage void ret_from_fork(void);
85asmlinkage void ret_from_kernel_thread(void);
87 86
88void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp) 87void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp)
89{ 88{
@@ -113,10 +112,10 @@ void flush_thread(void)
113} 112}
114 113
115int copy_thread(unsigned long clone_flags, unsigned long usp, 114int copy_thread(unsigned long clone_flags, unsigned long usp,
116 unsigned long unused, struct task_struct *p, struct pt_regs *regs) 115 unsigned long arg, struct task_struct *p)
117{ 116{
118 struct thread_info *ti = task_thread_info(p); 117 struct thread_info *ti = task_thread_info(p);
119 struct pt_regs *childregs; 118 struct pt_regs *childregs, *regs = current_pt_regs();
120 unsigned long childksp; 119 unsigned long childksp;
121 p->set_child_tid = p->clear_child_tid = NULL; 120 p->set_child_tid = p->clear_child_tid = NULL;
122 121
@@ -136,19 +135,30 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
136 childregs = (struct pt_regs *) childksp - 1; 135 childregs = (struct pt_regs *) childksp - 1;
137 /* Put the stack after the struct pt_regs. */ 136 /* Put the stack after the struct pt_regs. */
138 childksp = (unsigned long) childregs; 137 childksp = (unsigned long) childregs;
138 p->thread.cp0_status = read_c0_status() & ~(ST0_CU2|ST0_CU1);
139 if (unlikely(p->flags & PF_KTHREAD)) {
140 unsigned long status = p->thread.cp0_status;
141 memset(childregs, 0, sizeof(struct pt_regs));
142 ti->addr_limit = KERNEL_DS;
143 p->thread.reg16 = usp; /* fn */
144 p->thread.reg17 = arg;
145 p->thread.reg29 = childksp;
146 p->thread.reg31 = (unsigned long) ret_from_kernel_thread;
147#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
148 status = (status & ~(ST0_KUP | ST0_IEP | ST0_IEC)) |
149 ((status & (ST0_KUC | ST0_IEC)) << 2);
150#else
151 status |= ST0_EXL;
152#endif
153 childregs->cp0_status = status;
154 return 0;
155 }
139 *childregs = *regs; 156 *childregs = *regs;
140 childregs->regs[7] = 0; /* Clear error flag */ 157 childregs->regs[7] = 0; /* Clear error flag */
141
142 childregs->regs[2] = 0; /* Child gets zero as return value */ 158 childregs->regs[2] = 0; /* Child gets zero as return value */
159 childregs->regs[29] = usp;
160 ti->addr_limit = USER_DS;
143 161
144 if (childregs->cp0_status & ST0_CU0) {
145 childregs->regs[28] = (unsigned long) ti;
146 childregs->regs[29] = childksp;
147 ti->addr_limit = KERNEL_DS;
148 } else {
149 childregs->regs[29] = usp;
150 ti->addr_limit = USER_DS;
151 }
152 p->thread.reg29 = (unsigned long) childregs; 162 p->thread.reg29 = (unsigned long) childregs;
153 p->thread.reg31 = (unsigned long) ret_from_fork; 163 p->thread.reg31 = (unsigned long) ret_from_fork;
154 164
@@ -156,7 +166,6 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
156 * New tasks lose permission to use the fpu. This accelerates context 166 * New tasks lose permission to use the fpu. This accelerates context
157 * switching for most programs since they don't use the fpu. 167 * switching for most programs since they don't use the fpu.
158 */ 168 */
159 p->thread.cp0_status = read_c0_status() & ~(ST0_CU2|ST0_CU1);
160 childregs->cp0_status &= ~(ST0_CU2|ST0_CU1); 169 childregs->cp0_status &= ~(ST0_CU2|ST0_CU1);
161 170
162#ifdef CONFIG_MIPS_MT_SMTC 171#ifdef CONFIG_MIPS_MT_SMTC
@@ -222,35 +231,6 @@ int dump_task_fpu(struct task_struct *t, elf_fpregset_t *fpr)
222} 231}
223 232
224/* 233/*
225 * Create a kernel thread
226 */
227static void __noreturn kernel_thread_helper(void *arg, int (*fn)(void *))
228{
229 do_exit(fn(arg));
230}
231
232long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
233{
234 struct pt_regs regs;
235
236 memset(&regs, 0, sizeof(regs));
237
238 regs.regs[4] = (unsigned long) arg;
239 regs.regs[5] = (unsigned long) fn;
240 regs.cp0_epc = (unsigned long) kernel_thread_helper;
241 regs.cp0_status = read_c0_status();
242#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
243 regs.cp0_status = (regs.cp0_status & ~(ST0_KUP | ST0_IEP | ST0_IEC)) |
244 ((regs.cp0_status & (ST0_KUC | ST0_IEC)) << 2);
245#else
246 regs.cp0_status |= ST0_EXL;
247#endif
248
249 /* Ok, create the new process.. */
250 return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
251}
252
253/*
254 * 234 *
255 */ 235 */
256struct mips_frame_info { 236struct mips_frame_info {