diff options
Diffstat (limited to 'arch/openrisc')
-rw-r--r-- | arch/openrisc/Kconfig | 2 | ||||
-rw-r--r-- | arch/openrisc/include/uapi/asm/unistd.h | 2 | ||||
-rw-r--r-- | arch/openrisc/kernel/entry.S | 43 | ||||
-rw-r--r-- | arch/openrisc/kernel/process.c | 163 | ||||
-rw-r--r-- | arch/openrisc/kernel/signal.c | 6 |
5 files changed, 79 insertions, 137 deletions
diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig index 05f2ba41ff1a..e7f1a2993f78 100644 --- a/arch/openrisc/Kconfig +++ b/arch/openrisc/Kconfig | |||
@@ -22,6 +22,8 @@ config OPENRISC | |||
22 | select GENERIC_STRNCPY_FROM_USER | 22 | select GENERIC_STRNCPY_FROM_USER |
23 | select GENERIC_STRNLEN_USER | 23 | select GENERIC_STRNLEN_USER |
24 | select MODULES_USE_ELF_RELA | 24 | select MODULES_USE_ELF_RELA |
25 | select GENERIC_KERNEL_THREAD | ||
26 | select GENERIC_KERNEL_EXECVE | ||
25 | 27 | ||
26 | config MMU | 28 | config MMU |
27 | def_bool y | 29 | def_bool y |
diff --git a/arch/openrisc/include/uapi/asm/unistd.h b/arch/openrisc/include/uapi/asm/unistd.h index 437bdbb61b14..5db7bc0fa5a7 100644 --- a/arch/openrisc/include/uapi/asm/unistd.h +++ b/arch/openrisc/include/uapi/asm/unistd.h | |||
@@ -20,6 +20,8 @@ | |||
20 | 20 | ||
21 | #define sys_mmap2 sys_mmap_pgoff | 21 | #define sys_mmap2 sys_mmap_pgoff |
22 | 22 | ||
23 | #define __ARCH_WANT_SYS_EXECVE | ||
24 | |||
23 | #include <asm-generic/unistd.h> | 25 | #include <asm-generic/unistd.h> |
24 | 26 | ||
25 | #define __NR_or1k_atomic __NR_arch_specific_syscall | 27 | #define __NR_or1k_atomic __NR_arch_specific_syscall |
diff --git a/arch/openrisc/kernel/entry.S b/arch/openrisc/kernel/entry.S index ddfcaa828b0e..c60a09df323f 100644 --- a/arch/openrisc/kernel/entry.S +++ b/arch/openrisc/kernel/entry.S | |||
@@ -894,6 +894,16 @@ ENTRY(ret_from_fork) | |||
894 | l.jal schedule_tail | 894 | l.jal schedule_tail |
895 | l.nop | 895 | l.nop |
896 | 896 | ||
897 | /* Check if we are a kernel thread */ | ||
898 | l.sfeqi r20,0 | ||
899 | l.bf 1f | ||
900 | l.nop | ||
901 | |||
902 | /* ...we are a kernel thread so invoke the requested callback */ | ||
903 | l.jalr r20 | ||
904 | l.or r3,r22,r0 | ||
905 | |||
906 | 1: | ||
897 | /* _syscall_returns expect r11 to contain return value */ | 907 | /* _syscall_returns expect r11 to contain return value */ |
898 | l.lwz r11,PT_GPR11(r1) | 908 | l.lwz r11,PT_GPR11(r1) |
899 | 909 | ||
@@ -915,26 +925,6 @@ ENTRY(ret_from_fork) | |||
915 | l.j _syscall_return | 925 | l.j _syscall_return |
916 | l.nop | 926 | l.nop |
917 | 927 | ||
918 | /* Since syscalls don't save call-clobbered registers, the args to | ||
919 | * kernel_thread_helper will need to be passed through callee-saved | ||
920 | * registers and copied to the parameter registers when the thread | ||
921 | * begins running. | ||
922 | * | ||
923 | * See arch/openrisc/kernel/process.c: | ||
924 | * The args are passed as follows: | ||
925 | * arg1 (r3) : passed in r20 | ||
926 | * arg2 (r4) : passed in r22 | ||
927 | */ | ||
928 | |||
929 | ENTRY(_kernel_thread_helper) | ||
930 | l.or r3,r20,r0 | ||
931 | l.or r4,r22,r0 | ||
932 | l.movhi r31,hi(kernel_thread_helper) | ||
933 | l.ori r31,r31,lo(kernel_thread_helper) | ||
934 | l.jr r31 | ||
935 | l.nop | ||
936 | |||
937 | |||
938 | /* ========================================================[ switch ] === */ | 928 | /* ========================================================[ switch ] === */ |
939 | 929 | ||
940 | /* | 930 | /* |
@@ -1044,8 +1034,13 @@ ENTRY(_switch) | |||
1044 | /* Unwind stack to pre-switch state */ | 1034 | /* Unwind stack to pre-switch state */ |
1045 | l.addi r1,r1,(INT_FRAME_SIZE) | 1035 | l.addi r1,r1,(INT_FRAME_SIZE) |
1046 | 1036 | ||
1047 | /* Return via the link-register back to where we 'came from', where that can be | 1037 | /* Return via the link-register back to where we 'came from', where |
1048 | * either schedule() or return_from_fork()... */ | 1038 | * that may be either schedule(), ret_from_fork(), or |
1039 | * ret_from_kernel_thread(). If we are returning to a new thread, | ||
1040 | * we are expected to have set up the arg to schedule_tail already, | ||
1041 | * hence we do so here unconditionally: | ||
1042 | */ | ||
1043 | l.lwz r3,TI_STACK(r3) /* Load 'prev' as schedule_tail arg */ | ||
1049 | l.jr r9 | 1044 | l.jr r9 |
1050 | l.nop | 1045 | l.nop |
1051 | 1046 | ||
@@ -1088,10 +1083,6 @@ ENTRY(sys_fork) | |||
1088 | l.j _fork_save_extra_regs_and_call | 1083 | l.j _fork_save_extra_regs_and_call |
1089 | l.addi r3,r1,0 | 1084 | l.addi r3,r1,0 |
1090 | 1085 | ||
1091 | ENTRY(sys_execve) | ||
1092 | l.j _sys_execve | ||
1093 | l.addi r6,r1,0 | ||
1094 | |||
1095 | ENTRY(sys_sigaltstack) | 1086 | ENTRY(sys_sigaltstack) |
1096 | l.j _sys_sigaltstack | 1087 | l.j _sys_sigaltstack |
1097 | l.addi r5,r1,0 | 1088 | l.addi r5,r1,0 |
diff --git a/arch/openrisc/kernel/process.c b/arch/openrisc/kernel/process.c index c35f3ab1a8d3..e0874b8e09e4 100644 --- a/arch/openrisc/kernel/process.c +++ b/arch/openrisc/kernel/process.c | |||
@@ -109,66 +109,82 @@ void release_thread(struct task_struct *dead_task) | |||
109 | */ | 109 | */ |
110 | extern asmlinkage void ret_from_fork(void); | 110 | extern asmlinkage void ret_from_fork(void); |
111 | 111 | ||
112 | /* | ||
113 | * copy_thread | ||
114 | * @clone_flags: flags | ||
115 | * @usp: user stack pointer or fn for kernel thread | ||
116 | * @arg: arg to fn for kernel thread; always NULL for userspace thread | ||
117 | * @p: the newly created task | ||
118 | * @regs: CPU context to copy for userspace thread; always NULL for kthread | ||
119 | * | ||
120 | * At the top of a newly initialized kernel stack are two stacked pt_reg | ||
121 | * structures. The first (topmost) is the userspace context of the thread. | ||
122 | * The second is the kernelspace context of the thread. | ||
123 | * | ||
124 | * A kernel thread will not be returning to userspace, so the topmost pt_regs | ||
125 | * struct can be uninitialized; it _does_ need to exist, though, because | ||
126 | * a kernel thread can become a userspace thread by doing a kernel_execve, in | ||
127 | * which case the topmost context will be initialized and used for 'returning' | ||
128 | * to userspace. | ||
129 | * | ||
130 | * The second pt_reg struct needs to be initialized to 'return' to | ||
131 | * ret_from_fork. A kernel thread will need to set r20 to the address of | ||
132 | * a function to call into (with arg in r22); userspace threads need to set | ||
133 | * r20 to NULL in which case ret_from_fork will just continue a return to | ||
134 | * userspace. | ||
135 | * | ||
136 | * A kernel thread 'fn' may return; this is effectively what happens when | ||
137 | * kernel_execve is called. In that case, the userspace pt_regs must have | ||
138 | * been initialized (which kernel_execve takes care of, see start_thread | ||
139 | * below); ret_from_fork will then continue its execution causing the | ||
140 | * 'kernel thread' to return to userspace as a userspace thread. | ||
141 | */ | ||
142 | |||
112 | int | 143 | int |
113 | copy_thread(unsigned long clone_flags, unsigned long usp, | 144 | copy_thread(unsigned long clone_flags, unsigned long usp, |
114 | unsigned long unused, struct task_struct *p, struct pt_regs *regs) | 145 | unsigned long arg, struct task_struct *p, struct pt_regs *regs) |
115 | { | 146 | { |
116 | struct pt_regs *childregs; | 147 | struct pt_regs *userregs; |
117 | struct pt_regs *kregs; | 148 | struct pt_regs *kregs; |
118 | unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE; | 149 | unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE; |
119 | struct thread_info *ti; | ||
120 | unsigned long top_of_kernel_stack; | 150 | unsigned long top_of_kernel_stack; |
121 | 151 | ||
122 | top_of_kernel_stack = sp; | 152 | top_of_kernel_stack = sp; |
123 | 153 | ||
124 | p->set_child_tid = p->clear_child_tid = NULL; | 154 | p->set_child_tid = p->clear_child_tid = NULL; |
125 | 155 | ||
126 | /* Copy registers */ | 156 | /* Locate userspace context on stack... */ |
127 | /* redzone */ | 157 | sp -= STACK_FRAME_OVERHEAD; /* redzone */ |
128 | sp -= STACK_FRAME_OVERHEAD; | ||
129 | sp -= sizeof(struct pt_regs); | 158 | sp -= sizeof(struct pt_regs); |
130 | childregs = (struct pt_regs *)sp; | 159 | userregs = (struct pt_regs *) sp; |
131 | 160 | ||
132 | /* Copy parent registers */ | 161 | /* ...and kernel context */ |
133 | *childregs = *regs; | 162 | sp -= STACK_FRAME_OVERHEAD; /* redzone */ |
163 | sp -= sizeof(struct pt_regs); | ||
164 | kregs = (struct pt_regs *)sp; | ||
134 | 165 | ||
135 | if ((childregs->sr & SPR_SR_SM) == 1) { | 166 | if (unlikely(p->flags & PF_KTHREAD)) { |
136 | /* for kernel thread, set `current_thread_info' | 167 | memset(kregs, 0, sizeof(struct pt_regs)); |
137 | * and stackptr in new task | 168 | kregs->gpr[20] = usp; /* fn, kernel thread */ |
138 | */ | 169 | kregs->gpr[22] = arg; |
139 | childregs->sp = (unsigned long)task_stack_page(p) + THREAD_SIZE; | ||
140 | childregs->gpr[10] = (unsigned long)task_thread_info(p); | ||
141 | } else { | 170 | } else { |
142 | childregs->sp = usp; | 171 | *userregs = *regs; |
143 | } | ||
144 | |||
145 | childregs->gpr[11] = 0; /* Result from fork() */ | ||
146 | 172 | ||
147 | /* | 173 | userregs->sp = usp; |
148 | * The way this works is that at some point in the future | 174 | userregs->gpr[11] = 0; /* Result from fork() */ |
149 | * some task will call _switch to switch to the new task. | ||
150 | * That will pop off the stack frame created below and start | ||
151 | * the new task running at ret_from_fork. The new task will | ||
152 | * do some house keeping and then return from the fork or clone | ||
153 | * system call, using the stack frame created above. | ||
154 | */ | ||
155 | /* redzone */ | ||
156 | sp -= STACK_FRAME_OVERHEAD; | ||
157 | sp -= sizeof(struct pt_regs); | ||
158 | kregs = (struct pt_regs *)sp; | ||
159 | 175 | ||
160 | ti = task_thread_info(p); | 176 | kregs->gpr[20] = 0; /* Userspace thread */ |
161 | ti->ksp = sp; | 177 | } |
162 | 178 | ||
163 | /* kregs->sp must store the location of the 'pre-switch' kernel stack | 179 | /* |
164 | * pointer... for a newly forked process, this is simply the top of | 180 | * _switch wants the kernel stack page in pt_regs->sp so that it |
165 | * the kernel stack. | 181 | * can restore it to thread_info->ksp... see _switch for details. |
166 | */ | 182 | */ |
167 | kregs->sp = top_of_kernel_stack; | 183 | kregs->sp = top_of_kernel_stack; |
168 | kregs->gpr[3] = (unsigned long)current; /* arg to schedule_tail */ | ||
169 | kregs->gpr[10] = (unsigned long)task_thread_info(p); | ||
170 | kregs->gpr[9] = (unsigned long)ret_from_fork; | 184 | kregs->gpr[9] = (unsigned long)ret_from_fork; |
171 | 185 | ||
186 | task_thread_info(p)->ksp = (unsigned long)kregs; | ||
187 | |||
172 | return 0; | 188 | return 0; |
173 | } | 189 | } |
174 | 190 | ||
@@ -177,16 +193,14 @@ copy_thread(unsigned long clone_flags, unsigned long usp, | |||
177 | */ | 193 | */ |
178 | void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp) | 194 | void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp) |
179 | { | 195 | { |
180 | unsigned long sr = regs->sr & ~SPR_SR_SM; | 196 | unsigned long sr = mfspr(SPR_SR) & ~SPR_SR_SM; |
181 | 197 | ||
182 | set_fs(USER_DS); | 198 | set_fs(USER_DS); |
183 | memset(regs->gpr, 0, sizeof(regs->gpr)); | 199 | memset(regs, 0, sizeof(struct pt_regs)); |
184 | 200 | ||
185 | regs->pc = pc; | 201 | regs->pc = pc; |
186 | regs->sr = sr; | 202 | regs->sr = sr; |
187 | regs->sp = sp; | 203 | regs->sp = sp; |
188 | |||
189 | /* printk("start thread, ksp = %lx\n", current_thread_info()->ksp);*/ | ||
190 | } | 204 | } |
191 | 205 | ||
192 | /* Fill in the fpu structure for a core dump. */ | 206 | /* Fill in the fpu structure for a core dump. */ |
@@ -237,74 +251,9 @@ void dump_elf_thread(elf_greg_t *dest, struct pt_regs* regs) | |||
237 | dest[35] = 0; | 251 | dest[35] = 0; |
238 | } | 252 | } |
239 | 253 | ||
240 | extern void _kernel_thread_helper(void); | ||
241 | |||
242 | void __noreturn kernel_thread_helper(int (*fn) (void *), void *arg) | ||
243 | { | ||
244 | do_exit(fn(arg)); | ||
245 | } | ||
246 | |||
247 | /* | ||
248 | * Create a kernel thread. | ||
249 | */ | ||
250 | int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags) | ||
251 | { | ||
252 | struct pt_regs regs; | ||
253 | |||
254 | memset(®s, 0, sizeof(regs)); | ||
255 | |||
256 | regs.gpr[20] = (unsigned long)fn; | ||
257 | regs.gpr[22] = (unsigned long)arg; | ||
258 | regs.sr = mfspr(SPR_SR); | ||
259 | regs.pc = (unsigned long)_kernel_thread_helper; | ||
260 | |||
261 | return do_fork(flags | CLONE_VM | CLONE_UNTRACED, | ||
262 | 0, ®s, 0, NULL, NULL); | ||
263 | } | ||
264 | |||
265 | /* | ||
266 | * sys_execve() executes a new program. | ||
267 | */ | ||
268 | asmlinkage long _sys_execve(const char __user *name, | ||
269 | const char __user * const __user *argv, | ||
270 | const char __user * const __user *envp, | ||
271 | struct pt_regs *regs) | ||
272 | { | ||
273 | int error; | ||
274 | struct filename *filename; | ||
275 | |||
276 | filename = getname(name); | ||
277 | error = PTR_ERR(filename); | ||
278 | |||
279 | if (IS_ERR(filename)) | ||
280 | goto out; | ||
281 | |||
282 | error = do_execve(filename->name, argv, envp, regs); | ||
283 | putname(filename); | ||
284 | |||
285 | out: | ||
286 | return error; | ||
287 | } | ||
288 | |||
289 | unsigned long get_wchan(struct task_struct *p) | 254 | unsigned long get_wchan(struct task_struct *p) |
290 | { | 255 | { |
291 | /* TODO */ | 256 | /* TODO */ |
292 | 257 | ||
293 | return 0; | 258 | return 0; |
294 | } | 259 | } |
295 | |||
296 | int kernel_execve(const char *filename, char *const argv[], char *const envp[]) | ||
297 | { | ||
298 | register long __res asm("r11") = __NR_execve; | ||
299 | register long __a asm("r3") = (long)(filename); | ||
300 | register long __b asm("r4") = (long)(argv); | ||
301 | register long __c asm("r5") = (long)(envp); | ||
302 | __asm__ volatile ("l.sys 1" | ||
303 | : "=r" (__res), "=r"(__a), "=r"(__b), "=r"(__c) | ||
304 | : "0"(__res), "1"(__a), "2"(__b), "3"(__c) | ||
305 | : "r6", "r7", "r8", "r12", "r13", "r15", | ||
306 | "r17", "r19", "r21", "r23", "r25", "r27", | ||
307 | "r29", "r31"); | ||
308 | __asm__ volatile ("l.nop"); | ||
309 | return __res; | ||
310 | } | ||
diff --git a/arch/openrisc/kernel/signal.c b/arch/openrisc/kernel/signal.c index 30110297f4f9..ddedc8a77861 100644 --- a/arch/openrisc/kernel/signal.c +++ b/arch/openrisc/kernel/signal.c | |||
@@ -84,7 +84,6 @@ asmlinkage long _sys_rt_sigreturn(struct pt_regs *regs) | |||
84 | { | 84 | { |
85 | struct rt_sigframe *frame = (struct rt_sigframe __user *)regs->sp; | 85 | struct rt_sigframe *frame = (struct rt_sigframe __user *)regs->sp; |
86 | sigset_t set; | 86 | sigset_t set; |
87 | stack_t st; | ||
88 | 87 | ||
89 | /* | 88 | /* |
90 | * Since we stacked the signal on a dword boundary, | 89 | * Since we stacked the signal on a dword boundary, |
@@ -104,11 +103,10 @@ asmlinkage long _sys_rt_sigreturn(struct pt_regs *regs) | |||
104 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) | 103 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) |
105 | goto badframe; | 104 | goto badframe; |
106 | 105 | ||
107 | if (__copy_from_user(&st, &frame->uc.uc_stack, sizeof(st))) | ||
108 | goto badframe; | ||
109 | /* It is more difficult to avoid calling this function than to | 106 | /* It is more difficult to avoid calling this function than to |
110 | call it and ignore errors. */ | 107 | call it and ignore errors. */ |
111 | do_sigaltstack(&st, NULL, regs->sp); | 108 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT) |
109 | goto badframe; | ||
112 | 110 | ||
113 | return regs->gpr[11]; | 111 | return regs->gpr[11]; |
114 | 112 | ||