Skip to content

Commit 255461c

Browse files
author
Al Viro
committed
mn10300: split ret_from_fork, simplify kernel_thread()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 49ed339 commit 255461c

5 files changed

Lines changed: 27 additions & 71 deletions

File tree

‎arch/mn10300/kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fpu-obj-y := fpu-nofpu.o fpu-nofpu-low.o
77
fpu-obj-$(CONFIG_FPU) := fpu.o fpu-low.o
88

99
obj-y := process.o signal.o entry.o traps.o irq.o \
10-
ptrace.o setup.o time.o sys_mn10300.o io.o kthread.o \
10+
ptrace.o setup.o time.o sys_mn10300.o io.o \
1111
switch_to.o mn10300_ksyms.o kernel_execve.o $(fpu-obj-y) \
1212
csrc-mn10300.o cevt-mn10300.o
1313

‎arch/mn10300/kernel/entry.S‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ ENTRY(ret_from_fork)
5555
mov d0,(REG_D0,fp)
5656
jmp syscall_exit
5757

58+
ENTRY(ret_from_kernel_thread)
59+
call schedule_tail[],0
60+
mov (REG_D0,fp),d0
61+
mov (REG_A0,fp),a0
62+
calls (a0)
63+
jmp sys_exit
64+
5865
###############################################################################
5966
#
6067
# system call handler

‎arch/mn10300/kernel/internal.h‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@
1414
struct clocksource;
1515
struct clock_event_device;
1616

17-
/*
18-
* kthread.S
19-
*/
20-
extern int kernel_thread_helper(int);
21-
2217
/*
2318
* entry.S
2419
*/
2520
extern void ret_from_fork(struct task_struct *) __attribute__((noreturn));
21+
extern void ret_from_kernel_thread(struct task_struct *) __attribute__((noreturn));
2622

2723
/*
2824
* smp-low.S

‎arch/mn10300/kernel/kthread.S‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎arch/mn10300/kernel/process.c‎

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,18 @@ void show_regs(struct pt_regs *regs)
166166
*/
167167
int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
168168
{
169-
struct pt_regs regs;
169+
struct pt_regs regs = {
170+
.a0 = (unsigned long) fn;
171+
.d0 = (unsigned long) arg;
172+
};
170173

171-
memset(&regs, 0, sizeof(regs));
172-
173-
regs.a2 = (unsigned long) fn;
174-
regs.d2 = (unsigned long) arg;
175-
regs.pc = (unsigned long) kernel_thread_helper;
176174
local_save_flags(regs.epsw);
177175
regs.epsw |= EPSW_IE | EPSW_IM_7;
178176

179177
/* Ok, create the new process.. */
180178
return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0,
181179
NULL, NULL);
182180
}
183-
EXPORT_SYMBOL(kernel_thread);
184181

185182
/*
186183
* free current thread data structures etc..
@@ -227,49 +224,36 @@ int copy_thread(unsigned long clone_flags,
227224
struct task_struct *p, struct pt_regs *kregs)
228225
{
229226
struct thread_info *ti = task_thread_info(p);
230-
struct pt_regs *c_uregs, *c_kregs, *uregs;
227+
struct pt_regs *c_regs;
231228
unsigned long c_ksp;
232229

233-
uregs = current->thread.uregs;
234-
235230
c_ksp = (unsigned long) task_stack_page(p) + THREAD_SIZE;
236231

237232
/* allocate the userspace exception frame and set it up */
238233
c_ksp -= sizeof(struct pt_regs);
239-
c_uregs = (struct pt_regs *) c_ksp;
234+
c_regs = (struct pt_regs *) c_ksp;
240235

241-
p->thread.uregs = c_uregs;
242-
*c_uregs = *uregs;
243-
c_uregs->sp = c_usp;
244-
c_uregs->epsw &= ~EPSW_FE; /* my FPU */
236+
p->thread.uregs = c_regs;
237+
*c_regs = *kregs;
238+
c_regs->sp = c_usp;
239+
c_regs->epsw &= ~EPSW_FE; /* my FPU */
245240

246241
c_ksp -= 12; /* allocate function call ABI slack */
247242

248243
/* the new TLS pointer is passed in as arg #5 to sys_clone() */
249244
if (clone_flags & CLONE_SETTLS)
250-
c_uregs->e2 = current_frame()->d3;
251-
252-
/* set up the return kernel frame if called from kernel_thread() */
253-
c_kregs = c_uregs;
254-
if (kregs != uregs) {
255-
c_ksp -= sizeof(struct pt_regs);
256-
c_kregs = (struct pt_regs *) c_ksp;
257-
*c_kregs = *kregs;
258-
c_kregs->sp = c_usp;
259-
c_kregs->next = c_uregs;
260-
#ifdef CONFIG_MN10300_CURRENT_IN_E2
261-
c_kregs->e2 = (unsigned long) p; /* current */
262-
#endif
245+
c_regs->e2 = current_frame()->d3;
263246

264-
c_ksp -= 12; /* allocate function call ABI slack */
265-
}
247+
if (unlikely(!user_mode(kregs)))
248+
p->thread.pc = (unsigned long) ret_from_kernel_thread;
249+
else
250+
p->thread.pc = (unsigned long) ret_from_fork;
266251

267252
/* set up things up so the scheduler can start the new task */
268-
ti->frame = c_kregs;
269-
p->thread.a3 = (unsigned long) c_kregs;
253+
ti->frame = c_regs;
254+
p->thread.a3 = (unsigned long) c_regs;
270255
p->thread.sp = c_ksp;
271-
p->thread.pc = (unsigned long) ret_from_fork;
272-
p->thread.wchan = (unsigned long) ret_from_fork;
256+
p->thread.wchan = p->thread.pc;
273257
p->thread.usp = c_usp;
274258

275259
return 0;

0 commit comments

Comments
 (0)