2 * Port on Texas Instruments TMS320C6x architecture
4 * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
7 * Updated for 2.6.34: Mark Salter <msalter@redhat.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/uaccess.h>
16 #include <linux/syscalls.h>
17 #include <linux/tracehook.h>
19 #include <asm/ucontext.h>
20 #include <asm/cacheflush.h>
23 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
26 * Do a signal return, undo the signal stack.
29 #define RETCODE_SIZE (9 << 2) /* 9 instructions = 36 bytes */
32 struct siginfo __user *pinfo;
36 unsigned long retcode[RETCODE_SIZE >> 2];
39 static int restore_sigcontext(struct pt_regs *regs,
40 struct sigcontext __user *sc)
44 /* The access_ok check was done by caller, so use __get_user here */
45 #define COPY(x) (err |= __get_user(regs->x, &sc->sc_##x))
47 COPY(sp); COPY(a4); COPY(b4); COPY(a6); COPY(b6); COPY(a8); COPY(b8);
48 COPY(a0); COPY(a1); COPY(a2); COPY(a3); COPY(a5); COPY(a7); COPY(a9);
49 COPY(b0); COPY(b1); COPY(b2); COPY(b3); COPY(b5); COPY(b7); COPY(b9);
51 COPY(a16); COPY(a17); COPY(a18); COPY(a19);
52 COPY(a20); COPY(a21); COPY(a22); COPY(a23);
53 COPY(a24); COPY(a25); COPY(a26); COPY(a27);
54 COPY(a28); COPY(a29); COPY(a30); COPY(a31);
55 COPY(b16); COPY(b17); COPY(b18); COPY(b19);
56 COPY(b20); COPY(b21); COPY(b22); COPY(b23);
57 COPY(b24); COPY(b25); COPY(b26); COPY(b27);
58 COPY(b28); COPY(b29); COPY(b30); COPY(b31);
67 asmlinkage int do_rt_sigreturn(struct pt_regs *regs)
69 struct rt_sigframe __user *frame;
72 /* Always make any pending restarted system calls return -EINTR */
73 current_thread_info()->restart_block.fn = do_no_restart_syscall;
76 * Since we stacked the signal on a dword boundary,
77 * 'sp' should be dword aligned here. If it's
78 * not, then the user is trying to mess with us.
83 frame = (struct rt_sigframe __user *) ((unsigned long) regs->sp + 8);
85 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
87 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
90 sigdelsetmask(&set, ~_BLOCKABLE);
91 set_current_blocked(&set);
93 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
99 force_sig(SIGSEGV, current);
103 static int setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
108 err |= __put_user(mask, &sc->sc_mask);
110 /* The access_ok check was done by caller, so use __put_user here */
111 #define COPY(x) (err |= __put_user(regs->x, &sc->sc_##x))
113 COPY(sp); COPY(a4); COPY(b4); COPY(a6); COPY(b6); COPY(a8); COPY(b8);
114 COPY(a0); COPY(a1); COPY(a2); COPY(a3); COPY(a5); COPY(a7); COPY(a9);
115 COPY(b0); COPY(b1); COPY(b2); COPY(b3); COPY(b5); COPY(b7); COPY(b9);
117 COPY(a16); COPY(a17); COPY(a18); COPY(a19);
118 COPY(a20); COPY(a21); COPY(a22); COPY(a23);
119 COPY(a24); COPY(a25); COPY(a26); COPY(a27);
120 COPY(a28); COPY(a29); COPY(a30); COPY(a31);
121 COPY(b16); COPY(b17); COPY(b18); COPY(b19);
122 COPY(b20); COPY(b21); COPY(b22); COPY(b23);
123 COPY(b24); COPY(b25); COPY(b26); COPY(b27);
124 COPY(b28); COPY(b29); COPY(b30); COPY(b31);
133 static inline void __user *get_sigframe(struct k_sigaction *ka,
134 struct pt_regs *regs,
135 unsigned long framesize)
137 unsigned long sp = regs->sp;
140 * This is the X/Open sanctioned signal stack switching.
142 if ((ka->sa.sa_flags & SA_ONSTACK) && sas_ss_flags(sp) == 0)
143 sp = current->sas_ss_sp + current->sas_ss_size;
146 * No matter what happens, 'sp' must be dword
147 * aligned. Otherwise, nasty things will happen
149 return (void __user *)((sp - framesize) & ~7);
152 static int setup_rt_frame(int signr, struct k_sigaction *ka, siginfo_t *info,
153 sigset_t *set, struct pt_regs *regs)
155 struct rt_sigframe __user *frame;
156 unsigned long __user *retcode;
159 frame = get_sigframe(ka, regs, sizeof(*frame));
161 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
164 err |= __put_user(&frame->info, &frame->pinfo);
165 err |= __put_user(&frame->uc, &frame->puc);
166 err |= copy_siginfo_to_user(&frame->info, info);
168 /* Clear all the bits of the ucontext we don't use. */
169 err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));
171 err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0]);
172 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
174 /* Set up to return from userspace */
175 retcode = (unsigned long __user *) &frame->retcode;
177 /* The access_ok check was done above, so use __put_user here */
178 #define COPY(x) (err |= __put_user(x, retcode++))
180 COPY(0x0000002AUL | (__NR_rt_sigreturn << 7));
181 /* MVK __NR_rt_sigreturn,B0 */
182 COPY(0x10000000UL); /* SWE */
183 COPY(0x00006000UL); /* NOP 4 */
184 COPY(0x00006000UL); /* NOP 4 */
185 COPY(0x00006000UL); /* NOP 4 */
186 COPY(0x00006000UL); /* NOP 4 */
187 COPY(0x00006000UL); /* NOP 4 */
188 COPY(0x00006000UL); /* NOP 4 */
189 COPY(0x00006000UL); /* NOP 4 */
196 flush_icache_range((unsigned long) &frame->retcode,
197 (unsigned long) &frame->retcode + RETCODE_SIZE);
199 retcode = (unsigned long __user *) &frame->retcode;
201 /* Change user context to branch to signal handler */
202 regs->sp = (unsigned long) frame - 8;
203 regs->b3 = (unsigned long) retcode;
204 regs->pc = (unsigned long) ka->sa.sa_handler;
206 /* Give the signal number to the handler */
210 * For realtime signals we must also set the second and third
211 * arguments for the signal handler.
212 * -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
214 regs->b4 = (unsigned long)&frame->info;
215 regs->a6 = (unsigned long)&frame->uc;
220 force_sigsegv(signr, current);
225 handle_restart(struct pt_regs *regs, struct k_sigaction *ka, int has_handler)
228 case -ERESTARTNOHAND:
235 if (has_handler && !(ka->sa.sa_flags & SA_RESTART)) {
240 case -ERESTARTNOINTR:
242 regs->a4 = regs->orig_a4;
249 * handle the actual delivery of a signal to userspace
251 static void handle_signal(int sig,
252 siginfo_t *info, struct k_sigaction *ka,
253 struct pt_regs *regs, int syscall)
257 /* Are we from a system call? */
259 /* If so, check system call restarting.. */
261 case -ERESTART_RESTARTBLOCK:
262 case -ERESTARTNOHAND:
267 if (!(ka->sa.sa_flags & SA_RESTART)) {
273 case -ERESTARTNOINTR:
274 regs->a4 = regs->orig_a4;
279 /* Set up the stack frame */
280 if (setup_rt_frame(sig, ka, info, sigmask_to_save(), regs) < 0)
282 block_sigmask(ka, sig);
283 tracehook_signal_handler(sig, info, ka, regs, 0);
287 * handle a potential signal
289 static void do_signal(struct pt_regs *regs, int syscall)
291 struct k_sigaction ka;
295 /* we want the common case to go fast, which is why we may in certain
296 * cases get here from kernel mode */
297 if (!user_mode(regs))
300 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
302 handle_signal(signr, &info, &ka, regs, syscall);
306 /* did we come from a system call? */
308 /* restart the system call - no handlers present */
310 case -ERESTARTNOHAND:
312 case -ERESTARTNOINTR:
313 regs->a4 = regs->orig_a4;
317 case -ERESTART_RESTARTBLOCK:
318 regs->a4 = regs->orig_a4;
319 regs->b0 = __NR_restart_syscall;
325 /* if there's no signal to deliver, we just put the saved sigmask
327 restore_saved_sigmask();
331 * notification of userspace execution resumption
332 * - triggered by current->work.notify_resume
334 asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags,
337 /* deal with pending signal delivery */
338 if (thread_info_flags & (1 << TIF_SIGPENDING))
339 do_signal(regs, syscall);
341 if (thread_info_flags & (1 << TIF_NOTIFY_RESUME)) {
342 clear_thread_flag(TIF_NOTIFY_RESUME);
343 tracehook_notify_resume(regs);