@@ -84,6 +84,7 @@ void __noreturn cpu_idle(void)
8484}
8585
8686asmlinkage void ret_from_fork (void );
87+ asmlinkage void ret_from_kernel_thread (void );
8788
8889void start_thread (struct pt_regs * regs , unsigned long pc , unsigned long sp )
8990{
@@ -113,7 +114,7 @@ void flush_thread(void)
113114}
114115
115116int copy_thread (unsigned long clone_flags , unsigned long usp ,
116- unsigned long unused , struct task_struct * p , struct pt_regs * regs )
117+ unsigned long arg , struct task_struct * p , struct pt_regs * regs )
117118{
118119 struct thread_info * ti = task_thread_info (p );
119120 struct pt_regs * childregs ;
@@ -136,27 +137,37 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
136137 childregs = (struct pt_regs * ) childksp - 1 ;
137138 /* Put the stack after the struct pt_regs. */
138139 childksp = (unsigned long ) childregs ;
140+ p -> thread .cp0_status = read_c0_status () & ~(ST0_CU2 |ST0_CU1 );
141+ if (unlikely (p -> flags & PF_KTHREAD )) {
142+ unsigned long status = p -> thread .cp0_status ;
143+ memset (childregs , 0 , sizeof (struct pt_regs ));
144+ ti -> addr_limit = KERNEL_DS ;
145+ p -> thread .reg16 = usp ; /* fn */
146+ p -> thread .reg17 = arg ;
147+ p -> thread .reg29 = childksp ;
148+ p -> thread .reg31 = (unsigned long ) ret_from_kernel_thread ;
149+ #if defined(CONFIG_CPU_R3000 ) || defined(CONFIG_CPU_TX39XX )
150+ status = (status & ~(ST0_KUP | ST0_IEP | ST0_IEC )) |
151+ ((status & (ST0_KUC | ST0_IEC )) << 2 );
152+ #else
153+ status |= ST0_EXL ;
154+ #endif
155+ childregs -> cp0_status = status ;
156+ return 0 ;
157+ }
139158 * childregs = * regs ;
140159 childregs -> regs [7 ] = 0 ; /* Clear error flag */
141-
142160 childregs -> regs [2 ] = 0 ; /* Child gets zero as return value */
161+ childregs -> regs [29 ] = usp ;
162+ ti -> addr_limit = USER_DS ;
143163
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- }
152164 p -> thread .reg29 = (unsigned long ) childregs ;
153165 p -> thread .reg31 = (unsigned long ) ret_from_fork ;
154166
155167 /*
156168 * New tasks lose permission to use the fpu. This accelerates context
157169 * switching for most programs since they don't use the fpu.
158170 */
159- p -> thread .cp0_status = read_c0_status () & ~(ST0_CU2 |ST0_CU1 );
160171 childregs -> cp0_status &= ~(ST0_CU2 |ST0_CU1 );
161172
162173#ifdef CONFIG_MIPS_MT_SMTC
@@ -221,35 +232,6 @@ int dump_task_fpu(struct task_struct *t, elf_fpregset_t *fpr)
221232 return 1 ;
222233}
223234
224- /*
225- * Create a kernel thread
226- */
227- static void __noreturn kernel_thread_helper (void * arg , int (* fn )(void * ))
228- {
229- do_exit (fn (arg ));
230- }
231-
232- long 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-
253235/*
254236 *
255237 */
0 commit comments