aboutsummaryrefslogtreecommitdiffstats
path: root/arch/tile
diff options
context:
space:
mode:
Diffstat (limited to 'arch/tile')
-rw-r--r--arch/tile/Kconfig2
-rw-r--r--arch/tile/include/asm/compat.h15
-rw-r--r--arch/tile/include/asm/elf.h1
-rw-r--r--arch/tile/include/asm/processor.h6
-rw-r--r--arch/tile/include/asm/switch_to.h5
-rw-r--r--arch/tile/include/asm/syscalls.h13
-rw-r--r--arch/tile/include/asm/unistd.h2
-rw-r--r--arch/tile/kernel/compat.c4
-rw-r--r--arch/tile/kernel/compat_signal.c10
-rw-r--r--arch/tile/kernel/entry.S11
-rw-r--r--arch/tile/kernel/intvec_32.S29
-rw-r--r--arch/tile/kernel/intvec_64.S30
-rw-r--r--arch/tile/kernel/process.c171
-rw-r--r--arch/tile/kernel/signal.c9
-rw-r--r--arch/tile/kernel/sys.c8
-rw-r--r--arch/tile/mm/fault.c5
16 files changed, 116 insertions, 205 deletions
diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
index 875d008828b8..ea7f61e8bc9e 100644
--- a/arch/tile/Kconfig
+++ b/arch/tile/Kconfig
@@ -21,6 +21,8 @@ config TILE
21 select ARCH_HAVE_NMI_SAFE_CMPXCHG 21 select ARCH_HAVE_NMI_SAFE_CMPXCHG
22 select GENERIC_CLOCKEVENTS 22 select GENERIC_CLOCKEVENTS
23 select MODULES_USE_ELF_RELA 23 select MODULES_USE_ELF_RELA
24 select GENERIC_KERNEL_THREAD
25 select GENERIC_KERNEL_EXECVE
24 26
25# FIXME: investigate whether we need/want these options. 27# FIXME: investigate whether we need/want these options.
26# select HAVE_IOREMAP_PROT 28# select HAVE_IOREMAP_PROT
diff --git a/arch/tile/include/asm/compat.h b/arch/tile/include/asm/compat.h
index 3063e6fc8daa..ca61fb4296b3 100644
--- a/arch/tile/include/asm/compat.h
+++ b/arch/tile/include/asm/compat.h
@@ -275,18 +275,14 @@ extern int compat_setup_rt_frame(int sig, struct k_sigaction *ka,
275struct compat_sigaction; 275struct compat_sigaction;
276struct compat_siginfo; 276struct compat_siginfo;
277struct compat_sigaltstack; 277struct compat_sigaltstack;
278long compat_sys_execve(const char __user *path,
279 compat_uptr_t __user *argv,
280 compat_uptr_t __user *envp, struct pt_regs *);
281long compat_sys_rt_sigaction(int sig, struct compat_sigaction __user *act, 278long compat_sys_rt_sigaction(int sig, struct compat_sigaction __user *act,
282 struct compat_sigaction __user *oact, 279 struct compat_sigaction __user *oact,
283 size_t sigsetsize); 280 size_t sigsetsize);
284long compat_sys_rt_sigqueueinfo(int pid, int sig, 281long compat_sys_rt_sigqueueinfo(int pid, int sig,
285 struct compat_siginfo __user *uinfo); 282 struct compat_siginfo __user *uinfo);
286long compat_sys_rt_sigreturn(struct pt_regs *); 283long compat_sys_rt_sigreturn(void);
287long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr, 284long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr,
288 struct compat_sigaltstack __user *uoss_ptr, 285 struct compat_sigaltstack __user *uoss_ptr);
289 struct pt_regs *);
290long compat_sys_truncate64(char __user *filename, u32 dummy, u32 low, u32 high); 286long compat_sys_truncate64(char __user *filename, u32 dummy, u32 low, u32 high);
291long compat_sys_ftruncate64(unsigned int fd, u32 dummy, u32 low, u32 high); 287long compat_sys_ftruncate64(unsigned int fd, u32 dummy, u32 low, u32 high);
292long compat_sys_pread64(unsigned int fd, char __user *ubuf, size_t count, 288long compat_sys_pread64(unsigned int fd, char __user *ubuf, size_t count,
@@ -303,12 +299,7 @@ long compat_sys_fallocate(int fd, int mode,
303long compat_sys_sched_rr_get_interval(compat_pid_t pid, 299long compat_sys_sched_rr_get_interval(compat_pid_t pid,
304 struct compat_timespec __user *interval); 300 struct compat_timespec __user *interval);
305 301
306/* These are the intvec_64.S trampolines. */ 302/* Assembly trampoline to avoid clobbering r0. */
307long _compat_sys_execve(const char __user *path,
308 const compat_uptr_t __user *argv,
309 const compat_uptr_t __user *envp);
310long _compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr,
311 struct compat_sigaltstack __user *uoss_ptr);
312long _compat_sys_rt_sigreturn(void); 303long _compat_sys_rt_sigreturn(void);
313 304
314#endif /* _ASM_TILE_COMPAT_H */ 305#endif /* _ASM_TILE_COMPAT_H */
diff --git a/arch/tile/include/asm/elf.h b/arch/tile/include/asm/elf.h
index f8ccf08f6934..b73e1039c911 100644
--- a/arch/tile/include/asm/elf.h
+++ b/arch/tile/include/asm/elf.h
@@ -148,6 +148,7 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
148#define compat_start_thread(regs, ip, usp) do { \ 148#define compat_start_thread(regs, ip, usp) do { \
149 regs->pc = ptr_to_compat_reg((void *)(ip)); \ 149 regs->pc = ptr_to_compat_reg((void *)(ip)); \
150 regs->sp = ptr_to_compat_reg((void *)(usp)); \ 150 regs->sp = ptr_to_compat_reg((void *)(usp)); \
151 single_step_execve(); \
151 } while (0) 152 } while (0)
152 153
153/* 154/*
diff --git a/arch/tile/include/asm/processor.h b/arch/tile/include/asm/processor.h
index 8c4dd9ff91eb..2b70dfb1442e 100644
--- a/arch/tile/include/asm/processor.h
+++ b/arch/tile/include/asm/processor.h
@@ -211,6 +211,7 @@ static inline void start_thread(struct pt_regs *regs,
211{ 211{
212 regs->pc = pc; 212 regs->pc = pc;
213 regs->sp = usp; 213 regs->sp = usp;
214 single_step_execve();
214} 215}
215 216
216/* Free all resources held by a thread. */ 217/* Free all resources held by a thread. */
@@ -219,8 +220,6 @@ static inline void release_thread(struct task_struct *dead_task)
219 /* Nothing for now */ 220 /* Nothing for now */
220} 221}
221 222
222extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
223
224extern int do_work_pending(struct pt_regs *regs, u32 flags); 223extern int do_work_pending(struct pt_regs *regs, u32 flags);
225 224
226 225
@@ -239,6 +238,9 @@ unsigned long get_wchan(struct task_struct *p);
239#define KSTK_TOP(task) (task_ksp0(task) - STACK_TOP_DELTA) 238#define KSTK_TOP(task) (task_ksp0(task) - STACK_TOP_DELTA)
240#define task_pt_regs(task) \ 239#define task_pt_regs(task) \
241 ((struct pt_regs *)(task_ksp0(task) - KSTK_PTREGS_GAP) - 1) 240 ((struct pt_regs *)(task_ksp0(task) - KSTK_PTREGS_GAP) - 1)
241#define current_pt_regs() \
242 ((struct pt_regs *)((stack_pointer | (THREAD_SIZE - 1)) - \
243 (KSTK_PTREGS_GAP - 1)) - 1)
242#define task_sp(task) (task_pt_regs(task)->sp) 244#define task_sp(task) (task_pt_regs(task)->sp)
243#define task_pc(task) (task_pt_regs(task)->pc) 245#define task_pc(task) (task_pt_regs(task)->pc)
244/* Aliases for pc and sp (used in fs/proc/array.c) */ 246/* Aliases for pc and sp (used in fs/proc/array.c) */
diff --git a/arch/tile/include/asm/switch_to.h b/arch/tile/include/asm/switch_to.h
index 1d48c5fee8b7..b8f888cbe6b0 100644
--- a/arch/tile/include/asm/switch_to.h
+++ b/arch/tile/include/asm/switch_to.h
@@ -68,7 +68,10 @@ extern unsigned long get_switch_to_pc(void);
68/* Support function for forking a new task. */ 68/* Support function for forking a new task. */
69void ret_from_fork(void); 69void ret_from_fork(void);
70 70
71/* Called from ret_from_fork() when a new process starts up. */ 71/* Support function for forking a new kernel thread. */
72void ret_from_kernel_thread(void *fn, void *arg);
73
74/* Called from ret_from_xxx() when a new process starts up. */
72struct task_struct *sim_notify_fork(struct task_struct *prev); 75struct task_struct *sim_notify_fork(struct task_struct *prev);
73 76
74#endif /* !__ASSEMBLY__ */ 77#endif /* !__ASSEMBLY__ */
diff --git a/arch/tile/include/asm/syscalls.h b/arch/tile/include/asm/syscalls.h
index 06f0464cfed9..4c8462a62cb6 100644
--- a/arch/tile/include/asm/syscalls.h
+++ b/arch/tile/include/asm/syscalls.h
@@ -51,8 +51,7 @@ long sys_cacheflush(unsigned long addr, unsigned long len,
51 51
52#ifndef __tilegx__ 52#ifndef __tilegx__
53/* mm/fault.c */ 53/* mm/fault.c */
54long sys_cmpxchg_badaddr(unsigned long address, struct pt_regs *); 54long sys_cmpxchg_badaddr(unsigned long address);
55long _sys_cmpxchg_badaddr(unsigned long address);
56#endif 55#endif
57 56
58#ifdef CONFIG_COMPAT 57#ifdef CONFIG_COMPAT
@@ -63,14 +62,16 @@ long sys_truncate64(const char __user *path, loff_t length);
63long sys_ftruncate64(unsigned int fd, loff_t length); 62long sys_ftruncate64(unsigned int fd, loff_t length);
64#endif 63#endif
65 64
65/* Provide versions of standard syscalls that use current_pt_regs(). */
66long sys_rt_sigreturn(void);
67long sys_sigaltstack(const stack_t __user *, stack_t __user *);
68#define sys_rt_sigreturn sys_rt_sigreturn
69#define sys_sigaltstack sys_sigaltstack
70
66/* These are the intvec*.S trampolines. */ 71/* These are the intvec*.S trampolines. */
67long _sys_sigaltstack(const stack_t __user *, stack_t __user *);
68long _sys_rt_sigreturn(void); 72long _sys_rt_sigreturn(void);
69long _sys_clone(unsigned long clone_flags, unsigned long newsp, 73long _sys_clone(unsigned long clone_flags, unsigned long newsp,
70 void __user *parent_tid, void __user *child_tid); 74 void __user *parent_tid, void __user *child_tid);
71long _sys_execve(const char __user *filename,
72 const char __user *const __user *argv,
73 const char __user *const __user *envp);
74 75
75#include <asm-generic/syscalls.h> 76#include <asm-generic/syscalls.h>
76 77
diff --git a/arch/tile/include/asm/unistd.h b/arch/tile/include/asm/unistd.h
index 6e032a0a268e..b51c6ee3cd6c 100644
--- a/arch/tile/include/asm/unistd.h
+++ b/arch/tile/include/asm/unistd.h
@@ -16,4 +16,6 @@
16#define __ARCH_WANT_SYS_LLSEEK 16#define __ARCH_WANT_SYS_LLSEEK
17#endif 17#endif
18#define __ARCH_WANT_SYS_NEWFSTATAT 18#define __ARCH_WANT_SYS_NEWFSTATAT
19#define __ARCH_WANT_SYS_EXECVE
20#define __ARCH_WANT_SYS_CLONE
19#include <uapi/asm/unistd.h> 21#include <uapi/asm/unistd.h>
diff --git a/arch/tile/kernel/compat.c b/arch/tile/kernel/compat.c
index d67459b9ac2a..9cd7cb6041c0 100644
--- a/arch/tile/kernel/compat.c
+++ b/arch/tile/kernel/compat.c
@@ -102,9 +102,7 @@ long compat_sys_sched_rr_get_interval(compat_pid_t pid,
102#define compat_sys_fadvise64_64 sys32_fadvise64_64 102#define compat_sys_fadvise64_64 sys32_fadvise64_64
103#define compat_sys_readahead sys32_readahead 103#define compat_sys_readahead sys32_readahead
104 104
105/* Call the trampolines to manage pt_regs where necessary. */ 105/* Call the assembly trampolines where necessary. */
106#define compat_sys_execve _compat_sys_execve
107#define compat_sys_sigaltstack _compat_sys_sigaltstack
108#define compat_sys_rt_sigreturn _compat_sys_rt_sigreturn 106#define compat_sys_rt_sigreturn _compat_sys_rt_sigreturn
109#define sys_clone _sys_clone 107#define sys_clone _sys_clone
110 108
diff --git a/arch/tile/kernel/compat_signal.c b/arch/tile/kernel/compat_signal.c
index 08b4fe1717bb..2e4cc69224a6 100644
--- a/arch/tile/kernel/compat_signal.c
+++ b/arch/tile/kernel/compat_signal.c
@@ -197,8 +197,7 @@ int copy_siginfo_from_user32(siginfo_t *to, struct compat_siginfo __user *from)
197} 197}
198 198
199long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr, 199long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr,
200 struct compat_sigaltstack __user *uoss_ptr, 200 struct compat_sigaltstack __user *uoss_ptr)
201 struct pt_regs *regs)
202{ 201{
203 stack_t uss, uoss; 202 stack_t uss, uoss;
204 int ret; 203 int ret;
@@ -219,7 +218,7 @@ long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr,
219 set_fs(KERNEL_DS); 218 set_fs(KERNEL_DS);
220 ret = do_sigaltstack(uss_ptr ? (stack_t __user __force *)&uss : NULL, 219 ret = do_sigaltstack(uss_ptr ? (stack_t __user __force *)&uss : NULL,
221 (stack_t __user __force *)&uoss, 220 (stack_t __user __force *)&uoss,
222 (unsigned long)compat_ptr(regs->sp)); 221 (unsigned long)compat_ptr(current_pt_regs()->sp));
223 set_fs(seg); 222 set_fs(seg);
224 if (ret >= 0 && uoss_ptr) { 223 if (ret >= 0 && uoss_ptr) {
225 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(*uoss_ptr)) || 224 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(*uoss_ptr)) ||
@@ -232,8 +231,9 @@ long compat_sys_sigaltstack(const struct compat_sigaltstack __user *uss_ptr,
232} 231}
233 232
234/* The assembly shim for this function arranges to ignore the return value. */ 233/* The assembly shim for this function arranges to ignore the return value. */
235long compat_sys_rt_sigreturn(struct pt_regs *regs) 234long compat_sys_rt_sigreturn(void)
236{ 235{
236 struct pt_regs *regs = current_pt_regs();
237 struct compat_rt_sigframe __user *frame = 237 struct compat_rt_sigframe __user *frame =
238 (struct compat_rt_sigframe __user *) compat_ptr(regs->sp); 238 (struct compat_rt_sigframe __user *) compat_ptr(regs->sp);
239 sigset_t set; 239 sigset_t set;
@@ -248,7 +248,7 @@ long compat_sys_rt_sigreturn(struct pt_regs *regs)
248 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 248 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
249 goto badframe; 249 goto badframe;
250 250
251 if (compat_sys_sigaltstack(&frame->uc.uc_stack, NULL, regs) != 0) 251 if (compat_sys_sigaltstack(&frame->uc.uc_stack, NULL) == -EFAULT)
252 goto badframe; 252 goto badframe;
253 253
254 return 0; 254 return 0;
diff --git a/arch/tile/kernel/entry.S b/arch/tile/kernel/entry.S
index c31637baff28..f116cb0bce20 100644
--- a/arch/tile/kernel/entry.S
+++ b/arch/tile/kernel/entry.S
@@ -28,17 +28,6 @@ STD_ENTRY(current_text_addr)
28 STD_ENDPROC(current_text_addr) 28 STD_ENDPROC(current_text_addr)
29 29
30/* 30/*
31 * Implement execve(). The i386 code has a note that forking from kernel
32 * space results in no copy on write until the execve, so we should be
33 * careful not to write to the stack here.
34 */
35STD_ENTRY(kernel_execve)
36 moveli TREG_SYSCALL_NR_NAME, __NR_execve
37 swint1
38 jrp lr
39 STD_ENDPROC(kernel_execve)
40
41/*
42 * We don't run this function directly, but instead copy it to a page 31 * We don't run this function directly, but instead copy it to a page
43 * we map into every user process. See vdso_setup(). 32 * we map into every user process. See vdso_setup().
44 * 33 *
diff --git a/arch/tile/kernel/intvec_32.S b/arch/tile/kernel/intvec_32.S
index 6943515100f8..f212bf7cea86 100644
--- a/arch/tile/kernel/intvec_32.S
+++ b/arch/tile/kernel/intvec_32.S
@@ -1291,6 +1291,21 @@ STD_ENTRY(ret_from_fork)
1291 } 1291 }
1292 STD_ENDPROC(ret_from_fork) 1292 STD_ENDPROC(ret_from_fork)
1293 1293
1294STD_ENTRY(ret_from_kernel_thread)
1295 jal sim_notify_fork
1296 jal schedule_tail
1297 FEEDBACK_REENTER(ret_from_fork)
1298 {
1299 move r0, r31
1300 jalr r30
1301 }
1302 FEEDBACK_REENTER(ret_from_kernel_thread)
1303 {
1304 movei r30, 0 /* not an NMI */
1305 j .Lresume_userspace /* jump into middle of interrupt_return */
1306 }
1307 STD_ENDPROC(ret_from_kernel_thread)
1308
1294 /* 1309 /*
1295 * Code for ill interrupt. 1310 * Code for ill interrupt.
1296 */ 1311 */
@@ -1437,15 +1452,6 @@ STD_ENTRY_LOCAL(bad_intr)
1437 panic "Unhandled interrupt %#x: PC %#lx" 1452 panic "Unhandled interrupt %#x: PC %#lx"
1438 STD_ENDPROC(bad_intr) 1453 STD_ENDPROC(bad_intr)
1439 1454
1440/* Put address of pt_regs in reg and jump. */
1441#define PTREGS_SYSCALL(x, reg) \
1442 STD_ENTRY(_##x); \
1443 { \
1444 PTREGS_PTR(reg, PTREGS_OFFSET_BASE); \
1445 j x \
1446 }; \
1447 STD_ENDPROC(_##x)
1448
1449/* 1455/*
1450 * Special-case sigreturn to not write r0 to the stack on return. 1456 * Special-case sigreturn to not write r0 to the stack on return.
1451 * This is technically more efficient, but it also avoids difficulties 1457 * This is technically more efficient, but it also avoids difficulties
@@ -1461,12 +1467,9 @@ STD_ENTRY_LOCAL(bad_intr)
1461 }; \ 1467 }; \
1462 STD_ENDPROC(_##x) 1468 STD_ENDPROC(_##x)
1463 1469
1464PTREGS_SYSCALL(sys_execve, r3)
1465PTREGS_SYSCALL(sys_sigaltstack, r2)
1466PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0) 1470PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0)
1467PTREGS_SYSCALL(sys_cmpxchg_badaddr, r1)
1468 1471
1469/* Save additional callee-saves to pt_regs, put address in r4 and jump. */ 1472/* Save additional callee-saves to pt_regs and jump to standard function. */
1470STD_ENTRY(_sys_clone) 1473STD_ENTRY(_sys_clone)
1471 push_extra_callee_saves r4 1474 push_extra_callee_saves r4
1472 j sys_clone 1475 j sys_clone
diff --git a/arch/tile/kernel/intvec_64.S b/arch/tile/kernel/intvec_64.S
index 7c06d597ffd0..54bc9a6678e8 100644
--- a/arch/tile/kernel/intvec_64.S
+++ b/arch/tile/kernel/intvec_64.S
@@ -1150,6 +1150,21 @@ STD_ENTRY(ret_from_fork)
1150 } 1150 }
1151 STD_ENDPROC(ret_from_fork) 1151 STD_ENDPROC(ret_from_fork)
1152 1152
1153STD_ENTRY(ret_from_kernel_thread)
1154 jal sim_notify_fork
1155 jal schedule_tail
1156 FEEDBACK_REENTER(ret_from_fork)
1157 {
1158 move r0, r31
1159 jalr r30
1160 }
1161 FEEDBACK_REENTER(ret_from_kernel_thread)
1162 {
1163 movei r30, 0 /* not an NMI */
1164 j .Lresume_userspace /* jump into middle of interrupt_return */
1165 }
1166 STD_ENDPROC(ret_from_kernel_thread)
1167
1153/* Various stub interrupt handlers and syscall handlers */ 1168/* Various stub interrupt handlers and syscall handlers */
1154 1169
1155STD_ENTRY_LOCAL(_kernel_double_fault) 1170STD_ENTRY_LOCAL(_kernel_double_fault)
@@ -1166,15 +1181,6 @@ STD_ENTRY_LOCAL(bad_intr)
1166 panic "Unhandled interrupt %#x: PC %#lx" 1181 panic "Unhandled interrupt %#x: PC %#lx"
1167 STD_ENDPROC(bad_intr) 1182 STD_ENDPROC(bad_intr)
1168 1183
1169/* Put address of pt_regs in reg and jump. */
1170#define PTREGS_SYSCALL(x, reg) \
1171 STD_ENTRY(_##x); \
1172 { \
1173 PTREGS_PTR(reg, PTREGS_OFFSET_BASE); \
1174 j x \
1175 }; \
1176 STD_ENDPROC(_##x)
1177
1178/* 1184/*
1179 * Special-case sigreturn to not write r0 to the stack on return. 1185 * Special-case sigreturn to not write r0 to the stack on return.
1180 * This is technically more efficient, but it also avoids difficulties 1186 * This is technically more efficient, but it also avoids difficulties
@@ -1190,16 +1196,12 @@ STD_ENTRY_LOCAL(bad_intr)
1190 }; \ 1196 }; \
1191 STD_ENDPROC(_##x) 1197 STD_ENDPROC(_##x)
1192 1198
1193PTREGS_SYSCALL(sys_execve, r3)
1194PTREGS_SYSCALL(sys_sigaltstack, r2)
1195PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0) 1199PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0)
1196#ifdef CONFIG_COMPAT 1200#ifdef CONFIG_COMPAT
1197PTREGS_SYSCALL(compat_sys_execve, r3)
1198PTREGS_SYSCALL(compat_sys_sigaltstack, r2)
1199PTREGS_SYSCALL_SIGRETURN(compat_sys_rt_sigreturn, r0) 1201PTREGS_SYSCALL_SIGRETURN(compat_sys_rt_sigreturn, r0)
1200#endif 1202#endif
1201 1203
1202/* Save additional callee-saves to pt_regs, put address in r4 and jump. */ 1204/* Save additional callee-saves to pt_regs and jump to standard function. */
1203STD_ENTRY(_sys_clone) 1205STD_ENTRY(_sys_clone)
1204 push_extra_callee_saves r4 1206 push_extra_callee_saves r4
1205 j sys_clone 1207 j sys_clone
diff --git a/arch/tile/kernel/process.c b/arch/tile/kernel/process.c
index 307d010696c9..0e5661e7d00d 100644
--- a/arch/tile/kernel/process.c
+++ b/arch/tile/kernel/process.c
@@ -157,24 +157,43 @@ void arch_release_thread_info(struct thread_info *info)
157static void save_arch_state(struct thread_struct *t); 157static void save_arch_state(struct thread_struct *t);
158 158
159int copy_thread(unsigned long clone_flags, unsigned long sp, 159int copy_thread(unsigned long clone_flags, unsigned long sp,
160 unsigned long stack_size, 160 unsigned long arg, struct task_struct *p)
161 struct task_struct *p, struct pt_regs *regs)
162{ 161{
163 struct pt_regs *childregs; 162 struct pt_regs *childregs = task_pt_regs(p), *regs = current_pt_regs();
164 unsigned long ksp; 163 unsigned long ksp;
164 unsigned long *callee_regs;
165 165
166 /* 166 /*
167 * When creating a new kernel thread we pass sp as zero. 167 * Set up the stack and stack pointer appropriately for the
168 * Assign it to a reasonable value now that we have the stack. 168 * new child to find itself woken up in __switch_to().
169 * The callee-saved registers must be on the stack to be read;
170 * the new task will then jump to assembly support to handle
171 * calling schedule_tail(), etc., and (for userspace tasks)
172 * returning to the context set up in the pt_regs.
169 */ 173 */
170 if (sp == 0 && regs->ex1 == PL_ICS_EX1(KERNEL_PL, 0)) 174 ksp = (unsigned long) childregs;
171 sp = KSTK_TOP(p); 175 ksp -= C_ABI_SAVE_AREA_SIZE; /* interrupt-entry save area */
176 ((long *)ksp)[0] = ((long *)ksp)[1] = 0;
177 ksp -= CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long);
178 callee_regs = (unsigned long *)ksp;
179 ksp -= C_ABI_SAVE_AREA_SIZE; /* __switch_to() save area */
180 ((long *)ksp)[0] = ((long *)ksp)[1] = 0;
181 p->thread.ksp = ksp;
172 182
173 /* 183 /* Record the pid of the task that created this one. */
174 * Do not clone step state from the parent; each thread 184 p->thread.creator_pid = current->pid;
175 * must make its own lazily. 185
176 */ 186 if (unlikely(p->flags & PF_KTHREAD)) {
177 task_thread_info(p)->step_state = NULL; 187 /* kernel thread */
188 memset(childregs, 0, sizeof(struct pt_regs));
189 memset(&callee_regs[2], 0,
190 (CALLEE_SAVED_REGS_COUNT - 2) * sizeof(unsigned long));
191 callee_regs[0] = sp; /* r30 = function */
192 callee_regs[1] = arg; /* r31 = arg */
193 childregs->ex1 = PL_ICS_EX1(KERNEL_PL, 0);
194 p->thread.pc = (unsigned long) ret_from_kernel_thread;
195 return 0;
196 }
178 197
179 /* 198 /*
180 * Start new thread in ret_from_fork so it schedules properly 199 * Start new thread in ret_from_fork so it schedules properly
@@ -182,46 +201,33 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
182 */ 201 */
183 p->thread.pc = (unsigned long) ret_from_fork; 202 p->thread.pc = (unsigned long) ret_from_fork;
184 203
185 /* Save user stack top pointer so we can ID the stack vm area later. */ 204 /*
186 p->thread.usp0 = sp; 205 * Do not clone step state from the parent; each thread
187 206 * must make its own lazily.
188 /* Record the pid of the process that created this one. */ 207 */
189 p->thread.creator_pid = current->pid; 208 task_thread_info(p)->step_state = NULL;
190 209
191 /* 210 /*
192 * Copy the registers onto the kernel stack so the 211 * Copy the registers onto the kernel stack so the
193 * return-from-interrupt code will reload it into registers. 212 * return-from-interrupt code will reload it into registers.
194 */ 213 */
195 childregs = task_pt_regs(p); 214 *childregs = *current_pt_regs();
196 *childregs = *regs;
197 childregs->regs[0] = 0; /* return value is zero */ 215 childregs->regs[0] = 0; /* return value is zero */
198 childregs->sp = sp; /* override with new user stack pointer */ 216 if (sp)
217 childregs->sp = sp; /* override with new user stack pointer */
218 memcpy(callee_regs, &childregs->regs[CALLEE_SAVED_FIRST_REG],
219 CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long));
220
221 /* Save user stack top pointer so we can ID the stack vm area later. */
222 p->thread.usp0 = childregs->sp;
199 223
200 /* 224 /*
201 * If CLONE_SETTLS is set, set "tp" in the new task to "r4", 225 * If CLONE_SETTLS is set, set "tp" in the new task to "r4",
202 * which is passed in as arg #5 to sys_clone(). 226 * which is passed in as arg #5 to sys_clone().
203 */ 227 */
204 if (clone_flags & CLONE_SETTLS) 228 if (clone_flags & CLONE_SETTLS)
205 childregs->tp = regs->regs[4]; 229 childregs->tp = childregs->regs[4];
206 230
207 /*
208 * Copy the callee-saved registers from the passed pt_regs struct
209 * into the context-switch callee-saved registers area.
210 * This way when we start the interrupt-return sequence, the
211 * callee-save registers will be correctly in registers, which
212 * is how we assume the compiler leaves them as we start doing
213 * the normal return-from-interrupt path after calling C code.
214 * Zero out the C ABI save area to mark the top of the stack.
215 */
216 ksp = (unsigned long) childregs;
217 ksp -= C_ABI_SAVE_AREA_SIZE; /* interrupt-entry save area */
218 ((long *)ksp)[0] = ((long *)ksp)[1] = 0;
219 ksp -= CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long);
220 memcpy((void *)ksp, &regs->regs[CALLEE_SAVED_FIRST_REG],
221 CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long));
222 ksp -= C_ABI_SAVE_AREA_SIZE; /* __switch_to() save area */
223 ((long *)ksp)[0] = ((long *)ksp)[1] = 0;
224 p->thread.ksp = ksp;
225 231
226#if CHIP_HAS_TILE_DMA() 232#if CHIP_HAS_TILE_DMA()
227 /* 233 /*
@@ -577,62 +583,6 @@ int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
577 panic("work_pending: bad flags %#x\n", thread_info_flags); 583 panic("work_pending: bad flags %#x\n", thread_info_flags);
578} 584}
579 585
580/* Note there is an implicit fifth argument if (clone_flags & CLONE_SETTLS). */
581SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
582 void __user *, parent_tidptr, void __user *, child_tidptr,
583 struct pt_regs *, regs)
584{
585 if (!newsp)
586 newsp = regs->sp;
587 return do_fork(clone_flags, newsp, regs, 0,
588 parent_tidptr, child_tidptr);
589}
590
591/*
592 * sys_execve() executes a new program.
593 */
594SYSCALL_DEFINE4(execve, const char __user *, path,
595 const char __user *const __user *, argv,
596 const char __user *const __user *, envp,
597 struct pt_regs *, regs)
598{
599 long error;
600 struct filename *filename;
601
602 filename = getname(path);
603 error = PTR_ERR(filename);
604 if (IS_ERR(filename))
605 goto out;
606 error = do_execve(filename->name, argv, envp, regs);
607 putname(filename);
608 if (error == 0)
609 single_step_execve();
610out:
611 return error;
612}
613
614#ifdef CONFIG_COMPAT
615long compat_sys_execve(const char __user *path,
616 compat_uptr_t __user *argv,
617 compat_uptr_t __user *envp,
618 struct pt_regs *regs)
619{
620 long error;
621 struct filename *filename;
622
623 filename = getname(path);
624 error = PTR_ERR(filename);
625 if (IS_ERR(filename))
626 goto out;
627 error = compat_do_execve(filename->name, argv, envp, regs);
628 putname(filename);
629 if (error == 0)
630 single_step_execve();
631out:
632 return error;
633}
634#endif
635
636unsigned long get_wchan(struct task_struct *p) 586unsigned long get_wchan(struct task_struct *p)
637{ 587{
638 struct KBacktraceIterator kbt; 588 struct KBacktraceIterator kbt;
@@ -650,37 +600,6 @@ unsigned long get_wchan(struct task_struct *p)
650 return 0; 600 return 0;
651} 601}
652 602
653/*
654 * We pass in lr as zero (cleared in kernel_thread) and the caller
655 * part of the backtrace ABI on the stack also zeroed (in copy_thread)
656 * so that backtraces will stop with this function.
657 * Note that we don't use r0, since copy_thread() clears it.
658 */
659static void start_kernel_thread(int dummy, int (*fn)(int), int arg)
660{
661 do_exit(fn(arg));
662}
663
664/*
665 * Create a kernel thread
666 */
667int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
668{
669 struct pt_regs regs;
670
671 memset(&regs, 0, sizeof(regs));
672 regs.ex1 = PL_ICS_EX1(KERNEL_PL, 0); /* run at kernel PL, no ICS */
673 regs.pc = (long) start_kernel_thread;
674 regs.flags = PT_FLAGS_CALLER_SAVES; /* need to restore r1 and r2 */
675 regs.regs[1] = (long) fn; /* function pointer */
676 regs.regs[2] = (long) arg; /* parameter register */
677
678 /* Ok, create the new process.. */
679 return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs,
680 0, NULL, NULL);
681}
682EXPORT_SYMBOL(kernel_thread);
683
684/* Flush thread state. */ 603/* Flush thread state. */
685void flush_thread(void) 604void flush_thread(void)
686{ 605{
diff --git a/arch/tile/kernel/signal.c b/arch/tile/kernel/signal.c
index 67efb656d104..657a7ace4ab4 100644
--- a/arch/tile/kernel/signal.c
+++ b/arch/tile/kernel/signal.c
@@ -37,10 +37,10 @@
37 37
38#define DEBUG_SIG 0 38#define DEBUG_SIG 0
39 39
40SYSCALL_DEFINE3(sigaltstack, const stack_t __user *, uss, 40SYSCALL_DEFINE2(sigaltstack, const stack_t __user *, uss,
41 stack_t __user *, uoss, struct pt_regs *, regs) 41 stack_t __user *, uoss)
42{ 42{
43 return do_sigaltstack(uss, uoss, regs->sp); 43 return do_sigaltstack(uss, uoss, current_pt_regs()->sp);
44} 44}
45 45
46 46
@@ -83,8 +83,9 @@ void signal_fault(const char *type, struct pt_regs *regs,
83} 83}
84 84
85/* The assembly shim for this function arranges to ignore the return value. */ 85/* The assembly shim for this function arranges to ignore the return value. */
86SYSCALL_DEFINE1(rt_sigreturn, struct pt_regs *, regs) 86SYSCALL_DEFINE0(rt_sigreturn)
87{ 87{
88 struct pt_regs *regs = current_pt_regs();
88 struct rt_sigframe __user *frame = 89 struct rt_sigframe __user *frame =
89 (struct rt_sigframe __user *)(regs->sp); 90 (struct rt_sigframe __user *)(regs->sp);
90 sigset_t set; 91 sigset_t set;
diff --git a/arch/tile/kernel/sys.c b/arch/tile/kernel/sys.c
index b08095b402d6..b881a7be24bd 100644
--- a/arch/tile/kernel/sys.c
+++ b/arch/tile/kernel/sys.c
@@ -106,14 +106,10 @@ SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
106#define sys_readahead sys32_readahead 106#define sys_readahead sys32_readahead
107#endif 107#endif
108 108
109/* Call the trampolines to manage pt_regs where necessary. */ 109/* Call the assembly trampolines where necessary. */
110#define sys_execve _sys_execve 110#undef sys_rt_sigreturn
111#define sys_sigaltstack _sys_sigaltstack
112#define sys_rt_sigreturn _sys_rt_sigreturn 111#define sys_rt_sigreturn _sys_rt_sigreturn
113#define sys_clone _sys_clone 112#define sys_clone _sys_clone
114#ifndef __tilegx__
115#define sys_cmpxchg_badaddr _sys_cmpxchg_badaddr
116#endif
117 113
118/* 114/*
119 * Note that we can't include <linux/unistd.h> here since the header 115 * Note that we can't include <linux/unistd.h> here since the header
diff --git a/arch/tile/mm/fault.c b/arch/tile/mm/fault.c
index fe811fa5f1b9..3d2b81c163a6 100644
--- a/arch/tile/mm/fault.c
+++ b/arch/tile/mm/fault.c
@@ -70,9 +70,10 @@ static noinline void force_sig_info_fault(const char *type, int si_signo,
70 * Synthesize the fault a PL0 process would get by doing a word-load of 70 * Synthesize the fault a PL0 process would get by doing a word-load of
71 * an unaligned address or a high kernel address. 71 * an unaligned address or a high kernel address.
72 */ 72 */
73SYSCALL_DEFINE2(cmpxchg_badaddr, unsigned long, address, 73SYSCALL_DEFINE1(cmpxchg_badaddr, unsigned long, address)
74 struct pt_regs *, regs)
75{ 74{
75 struct pt_regs *regs = current_pt_regs();
76
76 if (address >= PAGE_OFFSET) 77 if (address >= PAGE_OFFSET)
77 force_sig_info_fault("atomic segfault", SIGSEGV, SEGV_MAPERR, 78 force_sig_info_fault("atomic segfault", SIGSEGV, SEGV_MAPERR,
78 address, INT_DTLB_MISS, current, regs); 79 address, INT_DTLB_MISS, current, regs);