Skip to content

Commit 8f54bca

Browse files
author
Al Viro
committed
mips: switch to generic kernel_thread()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent ddffeb8 commit 8f54bca

5 files changed

Lines changed: 30 additions & 44 deletions

File tree

‎arch/mips/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ config MIPS
4040
select HAVE_MOD_ARCH_SPECIFIC
4141
select MODULES_USE_ELF_REL
4242
select MODULES_USE_ELF_RELA if 64BIT
43+
select GENERIC_KERNEL_THREAD
4344

4445
menu "Machine selection"
4546

‎arch/mips/include/asm/processor.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ struct task_struct;
310310
/* Free all resources held by a thread. */
311311
#define release_thread(thread) do { } while(0)
312312

313-
extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
314-
315313
extern unsigned long thread_saved_pc(struct task_struct *tsk);
316314

317315
/*

‎arch/mips/kernel/entry.S‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ need_resched:
6565
b need_resched
6666
#endif
6767

68+
FEXPORT(ret_from_kernel_thread)
69+
jal schedule_tail # a0 = struct task_struct *prev
70+
move a0, s1
71+
jal s0
72+
li a0, 0
73+
j sys_exit
74+
6875
FEXPORT(ret_from_fork)
6976
jal schedule_tail # a0 = struct task_struct *prev
7077

‎arch/mips/kernel/mips_ksyms.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ EXPORT_SYMBOL(memset);
3232
EXPORT_SYMBOL(memcpy);
3333
EXPORT_SYMBOL(memmove);
3434

35-
EXPORT_SYMBOL(kernel_thread);
36-
3735
/*
3836
* Functions that operate on entire pages. Mostly used by memory management.
3937
*/

‎arch/mips/kernel/process.c‎

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ void __noreturn cpu_idle(void)
8484
}
8585

8686
asmlinkage void ret_from_fork(void);
87+
asmlinkage void ret_from_kernel_thread(void);
8788

8889
void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp)
8990
{
@@ -113,7 +114,7 @@ void flush_thread(void)
113114
}
114115

115116
int 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

Comments
 (0)