aboutsummaryrefslogtreecommitdiffstats
path: root/arch/xtensa/kernel
diff options
context:
space:
mode:
authorMax Filippov <jcmvbkbc@gmail.com>2012-10-25 03:10:50 -0400
committerChris Zankel <chris@zankel.net>2012-10-25 18:00:03 -0400
commit3306a72669a2af23b324540b08e68e82ac5b7dab (patch)
tree0363c3f7120560ccf1750281a5ab366640734181 /arch/xtensa/kernel
parent6ebe7da25b7879194fdb5c43ea67b383dd9014d6 (diff)
xtensa: switch to generic kernel_thread()
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> Signed-off-by: Chris Zankel <chris@zankel.net>
Diffstat (limited to 'arch/xtensa/kernel')
-rw-r--r--arch/xtensa/kernel/entry.S41
-rw-r--r--arch/xtensa/kernel/process.c77
-rw-r--r--arch/xtensa/kernel/xtensa_ksyms.c1
3 files changed, 59 insertions, 60 deletions
diff --git a/arch/xtensa/kernel/entry.S b/arch/xtensa/kernel/entry.S
index 18453067c258..d4ec1381aebc 100644
--- a/arch/xtensa/kernel/entry.S
+++ b/arch/xtensa/kernel/entry.S
@@ -1833,34 +1833,6 @@ ENTRY(system_call)
1833 1833
1834 1834
1835/* 1835/*
1836 * Create a kernel thread
1837 *
1838 * int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
1839 * a2 a2 a3 a4
1840 */
1841
1842ENTRY(kernel_thread)
1843 entry a1, 16
1844
1845 mov a5, a2 # preserve fn over syscall
1846 mov a7, a3 # preserve args over syscall
1847
1848 movi a3, _CLONE_VM | _CLONE_UNTRACED
1849 movi a2, __NR_clone
1850 or a6, a4, a3 # arg0: flags
1851 mov a3, a1 # arg1: sp
1852 syscall
1853
1854 beq a3, a1, 1f # branch if parent
1855 mov a6, a7 # args
1856 callx4 a5 # fn(args)
1857
1858 movi a2, __NR_exit
1859 syscall # return value of fn(args) still in a6
1860
18611: retw
1862
1863/*
1864 * Do a system call from kernel instead of calling sys_execve, so we end up 1836 * Do a system call from kernel instead of calling sys_execve, so we end up
1865 * with proper pt_regs. 1837 * with proper pt_regs.
1866 * 1838 *
@@ -1958,3 +1930,16 @@ ENTRY(ret_from_fork)
1958 1930
1959 j common_exception_return 1931 j common_exception_return
1960 1932
1933/*
1934 * Kernel thread creation helper
1935 * On entry, set up by copy_thread: a2 = thread_fn, a3 = thread_fn arg
1936 * left from _switch_to: a6 = prev
1937 */
1938ENTRY(ret_from_kernel_thread)
1939
1940 call4 schedule_tail
1941 mov a6, a3
1942 callx4 a2
1943 call4 do_exit
1944
1945ENDPROC(ret_from_kernel_thread)
diff --git a/arch/xtensa/kernel/process.c b/arch/xtensa/kernel/process.c
index 341c151af919..be52fe437c1b 100644
--- a/arch/xtensa/kernel/process.c
+++ b/arch/xtensa/kernel/process.c
@@ -45,6 +45,7 @@
45#include <asm/regs.h> 45#include <asm/regs.h>
46 46
47extern void ret_from_fork(void); 47extern void ret_from_fork(void);
48extern void ret_from_kernel_thread(void);
48 49
49struct task_struct *current_set[NR_CPUS] = {&init_task, }; 50struct task_struct *current_set[NR_CPUS] = {&init_task, };
50 51
@@ -158,18 +159,30 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
158/* 159/*
159 * Copy thread. 160 * Copy thread.
160 * 161 *
162 * There are two modes in which this function is called:
163 * 1) Userspace thread creation,
164 * regs != NULL, usp_thread_fn is userspace stack pointer.
165 * It is expected to copy parent regs (in case CLONE_VM is not set
166 * in the clone_flags) and set up passed usp in the childregs.
167 * 2) Kernel thread creation,
168 * regs == NULL, usp_thread_fn is the function to run in the new thread
169 * and thread_fn_arg is its parameter.
170 * childregs are not used for the kernel threads.
171 *
161 * The stack layout for the new thread looks like this: 172 * The stack layout for the new thread looks like this:
162 * 173 *
163 * +------------------------+ <- sp in childregs (= tos) 174 * +------------------------+
164 * | childregs | 175 * | childregs |
165 * +------------------------+ <- thread.sp = sp in dummy-frame 176 * +------------------------+ <- thread.sp = sp in dummy-frame
166 * | dummy-frame | (saved in dummy-frame spill-area) 177 * | dummy-frame | (saved in dummy-frame spill-area)
167 * +------------------------+ 178 * +------------------------+
168 * 179 *
169 * We create a dummy frame to return to ret_from_fork: 180 * We create a dummy frame to return to either ret_from_fork or
170 * a0 points to ret_from_fork (simulating a call4) 181 * ret_from_kernel_thread:
182 * a0 points to ret_from_fork/ret_from_kernel_thread (simulating a call4)
171 * sp points to itself (thread.sp) 183 * sp points to itself (thread.sp)
172 * a2, a3 are unused. 184 * a2, a3 are unused for userspace threads,
185 * a2 points to thread_fn, a3 holds thread_fn arg for kernel threads.
173 * 186 *
174 * Note: This is a pristine frame, so we don't need any spill region on top of 187 * Note: This is a pristine frame, so we don't need any spill region on top of
175 * childregs. 188 * childregs.
@@ -185,41 +198,37 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
185 * involved. Much simpler to just not copy those live frames across. 198 * involved. Much simpler to just not copy those live frames across.
186 */ 199 */
187 200
188int copy_thread(unsigned long clone_flags, unsigned long usp, 201int copy_thread(unsigned long clone_flags, unsigned long usp_thread_fn,
189 unsigned long unused, 202 unsigned long thread_fn_arg,
190 struct task_struct * p, struct pt_regs * regs) 203 struct task_struct *p, struct pt_regs *unused)
191{ 204{
192 struct pt_regs *childregs; 205 struct pt_regs *childregs = task_pt_regs(p);
193 unsigned long tos;
194 int user_mode = user_mode(regs);
195 206
196#if (XTENSA_HAVE_COPROCESSORS || XTENSA_HAVE_IO_PORTS) 207#if (XTENSA_HAVE_COPROCESSORS || XTENSA_HAVE_IO_PORTS)
197 struct thread_info *ti; 208 struct thread_info *ti;
198#endif 209#endif
199 210
200 /* Set up new TSS. */
201 tos = (unsigned long)task_stack_page(p) + THREAD_SIZE;
202 if (user_mode)
203 childregs = (struct pt_regs*)(tos - PT_USER_SIZE);
204 else
205 childregs = (struct pt_regs*)tos - 1;
206
207 /* This does not copy all the regs. In a bout of brilliance or madness,
208 ARs beyond a0-a15 exist past the end of the struct. */
209 *childregs = *regs;
210
211 /* Create a call4 dummy-frame: a0 = 0, a1 = childregs. */ 211 /* Create a call4 dummy-frame: a0 = 0, a1 = childregs. */
212 *((int*)childregs - 3) = (unsigned long)childregs; 212 *((int*)childregs - 3) = (unsigned long)childregs;
213 *((int*)childregs - 4) = 0; 213 *((int*)childregs - 4) = 0;
214 214
215 childregs->areg[2] = 0;
216 p->set_child_tid = p->clear_child_tid = NULL;
217 p->thread.ra = MAKE_RA_FOR_CALL((unsigned long)ret_from_fork, 0x1);
218 p->thread.sp = (unsigned long)childregs; 215 p->thread.sp = (unsigned long)childregs;
219 216
220 if (user_mode(regs)) { 217 if (!(p->flags & PF_KTHREAD)) {
218 struct pt_regs *regs = current_pt_regs();
219 unsigned long usp = usp_thread_fn ?
220 usp_thread_fn : regs->areg[1];
221
222 p->thread.ra = MAKE_RA_FOR_CALL(
223 (unsigned long)ret_from_fork, 0x1);
221 224
225 /* This does not copy all the regs.
226 * In a bout of brilliance or madness,
227 * ARs beyond a0-a15 exist past the end of the struct.
228 */
229 *childregs = *regs;
222 childregs->areg[1] = usp; 230 childregs->areg[1] = usp;
231 childregs->areg[2] = 0;
223 232
224 /* When sharing memory with the parent thread, the child 233 /* When sharing memory with the parent thread, the child
225 usually starts on a pristine stack, so we have to reset 234 usually starts on a pristine stack, so we have to reset
@@ -254,11 +263,19 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
254// FIXME: we need to set THREADPTR in thread_info... 263// FIXME: we need to set THREADPTR in thread_info...
255 if (clone_flags & CLONE_SETTLS) 264 if (clone_flags & CLONE_SETTLS)
256 childregs->areg[2] = childregs->areg[6]; 265 childregs->areg[2] = childregs->areg[6];
257
258 } else { 266 } else {
259 /* In kernel space, we start a new thread with a new stack. */ 267 p->thread.ra = MAKE_RA_FOR_CALL(
260 childregs->wmask = 1; 268 (unsigned long)ret_from_kernel_thread, 1);
261 childregs->areg[1] = tos; 269
270 /* pass parameters to ret_from_kernel_thread:
271 * a2 = thread_fn, a3 = thread_fn arg
272 */
273 *((int *)childregs - 1) = thread_fn_arg;
274 *((int *)childregs - 2) = usp_thread_fn;
275
276 /* Childregs are only used when we're going to userspace
277 * in which case start_thread will set them up.
278 */
262 } 279 }
263 280
264#if (XTENSA_HAVE_COPROCESSORS || XTENSA_HAVE_IO_PORTS) 281#if (XTENSA_HAVE_COPROCESSORS || XTENSA_HAVE_IO_PORTS)
@@ -354,8 +371,6 @@ long xtensa_clone(unsigned long clone_flags, unsigned long newsp,
354 void __user *child_tid, long a5, 371 void __user *child_tid, long a5,
355 struct pt_regs *regs) 372 struct pt_regs *regs)
356{ 373{
357 if (!newsp)
358 newsp = regs->areg[1];
359 return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid); 374 return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
360} 375}
361 376
diff --git a/arch/xtensa/kernel/xtensa_ksyms.c b/arch/xtensa/kernel/xtensa_ksyms.c
index a8b9f1fd1e17..afe058b24e6e 100644
--- a/arch/xtensa/kernel/xtensa_ksyms.c
+++ b/arch/xtensa/kernel/xtensa_ksyms.c
@@ -43,7 +43,6 @@ EXPORT_SYMBOL(__strncpy_user);
43EXPORT_SYMBOL(clear_page); 43EXPORT_SYMBOL(clear_page);
44EXPORT_SYMBOL(copy_page); 44EXPORT_SYMBOL(copy_page);
45 45
46EXPORT_SYMBOL(kernel_thread);
47EXPORT_SYMBOL(empty_zero_page); 46EXPORT_SYMBOL(empty_zero_page);
48 47
49/* 48/*