2 * Signal support for Hexagon processor
4 * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include <linux/linkage.h>
22 #include <linux/syscalls.h>
23 #include <linux/tracehook.h>
24 #include <asm/registers.h>
25 #include <asm/thread_info.h>
26 #include <asm/unistd.h>
27 #include <asm/uaccess.h>
28 #include <asm/ucontext.h>
29 #include <asm/cacheflush.h>
30 #include <asm/signal.h>
34 unsigned long tramp[2];
39 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
42 unsigned long sp = regs->r29;
44 /* Switch to signal stack if appropriate */
45 if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags(sp) == 0))
46 sp = current->sas_ss_sp + current->sas_ss_size;
48 return (void __user *)((sp - frame_size) & ~(sizeof(long long) - 1));
51 static int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
56 err |= copy_to_user(&sc->sc_regs.r0, ®s->r00,
57 32*sizeof(unsigned long));
59 err |= __put_user(regs->sa0, &sc->sc_regs.sa0);
60 err |= __put_user(regs->lc0, &sc->sc_regs.lc0);
61 err |= __put_user(regs->sa1, &sc->sc_regs.sa1);
62 err |= __put_user(regs->lc1, &sc->sc_regs.lc1);
63 err |= __put_user(regs->m0, &sc->sc_regs.m0);
64 err |= __put_user(regs->m1, &sc->sc_regs.m1);
65 err |= __put_user(regs->usr, &sc->sc_regs.usr);
66 err |= __put_user(regs->preds, &sc->sc_regs.p3_0);
67 err |= __put_user(regs->gp, &sc->sc_regs.gp);
68 err |= __put_user(regs->ugp, &sc->sc_regs.ugp);
69 #if CONFIG_HEXAGON_ARCH_VERSION >= 4
70 err |= __put_user(regs->cs0, &sc->sc_regs.cs0);
71 err |= __put_user(regs->cs1, &sc->sc_regs.cs1);
73 tmp = pt_elr(regs); err |= __put_user(tmp, &sc->sc_regs.pc);
74 tmp = pt_cause(regs); err |= __put_user(tmp, &sc->sc_regs.cause);
75 tmp = pt_badva(regs); err |= __put_user(tmp, &sc->sc_regs.badva);
80 static int restore_sigcontext(struct pt_regs *regs,
81 struct sigcontext __user *sc)
86 err |= copy_from_user(®s->r00, &sc->sc_regs.r0,
87 32 * sizeof(unsigned long));
89 err |= __get_user(regs->sa0, &sc->sc_regs.sa0);
90 err |= __get_user(regs->lc0, &sc->sc_regs.lc0);
91 err |= __get_user(regs->sa1, &sc->sc_regs.sa1);
92 err |= __get_user(regs->lc1, &sc->sc_regs.lc1);
93 err |= __get_user(regs->m0, &sc->sc_regs.m0);
94 err |= __get_user(regs->m1, &sc->sc_regs.m1);
95 err |= __get_user(regs->usr, &sc->sc_regs.usr);
96 err |= __get_user(regs->preds, &sc->sc_regs.p3_0);
97 err |= __get_user(regs->gp, &sc->sc_regs.gp);
98 err |= __get_user(regs->ugp, &sc->sc_regs.ugp);
99 #if CONFIG_HEXAGON_ARCH_VERSION >= 4
100 err |= __get_user(regs->cs0, &sc->sc_regs.cs0);
101 err |= __get_user(regs->cs1, &sc->sc_regs.cs1);
103 err |= __get_user(tmp, &sc->sc_regs.pc); pt_set_elr(regs, tmp);
109 * Setup signal stack frame with siginfo structure
111 static int setup_rt_frame(int signr, struct k_sigaction *ka, siginfo_t *info,
112 sigset_t *set, struct pt_regs *regs)
115 struct rt_sigframe __user *frame;
116 struct hexagon_vdso *vdso = current->mm->context.vdso;
118 frame = get_sigframe(ka, regs, sizeof(struct rt_sigframe));
120 if (!access_ok(VERIFY_WRITE, frame, sizeof(struct rt_sigframe)))
123 if (copy_siginfo_to_user(&frame->info, info))
126 /* The on-stack signal trampoline is no longer executed;
127 * however, the libgcc signal frame unwinding code checks for
128 * the presence of these two numeric magic values.
130 err |= __put_user(0x7800d166, &frame->tramp[0]);
131 err |= __put_user(0x5400c004, &frame->tramp[1]);
132 err |= setup_sigcontext(regs, &frame->uc.uc_mcontext);
133 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
134 err |= __save_altstack(&frame->uc.uc_stack, user_stack_pointer(regs));
138 /* Load r0/r1 pair with signumber/siginfo pointer... */
139 regs->r0100 = ((unsigned long long)((unsigned long)&frame->info) << 32)
140 | (unsigned long long)signr;
141 regs->r02 = (unsigned long) &frame->uc;
142 regs->r31 = (unsigned long) vdso->rt_signal_trampoline;
143 pt_psp(regs) = (unsigned long) frame;
144 pt_set_elr(regs, (unsigned long)ka->sa.sa_handler);
149 force_sigsegv(signr, current);
154 * Setup invocation of signal handler
156 static void handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka,
157 struct pt_regs *regs)
160 * If we're handling a signal that aborted a system call,
161 * set up the error return value before adding the signal
162 * frame to the stack.
165 if (regs->syscall_nr >= 0) {
167 case -ERESTART_RESTARTBLOCK:
168 case -ERESTARTNOHAND:
172 if (!(ka->sa.sa_flags & SA_RESTART)) {
177 case -ERESTARTNOINTR:
178 regs->r06 = regs->syscall_nr;
179 pt_set_elr(regs, pt_elr(regs) - 4);
180 regs->r00 = regs->restart_r0;
188 * Set up the stack frame; not doing the SA_SIGINFO thing. We
189 * only set up the rt_frame flavor.
191 /* If there was an error on setup, no signal was delivered. */
192 if (setup_rt_frame(sig, ka, info, sigmask_to_save(), regs) < 0)
195 signal_delivered(sig, info, ka, regs,
196 test_thread_flag(TIF_SINGLESTEP));
200 * Called from return-from-event code.
202 void do_signal(struct pt_regs *regs)
204 struct k_sigaction sigact;
208 if (!user_mode(regs))
211 signo = get_signal_to_deliver(&info, &sigact, regs, NULL);
214 handle_signal(signo, &info, &sigact, regs);
219 * No (more) signals; if we came from a system call, handle the restart.
222 if (regs->syscall_nr >= 0) {
224 case -ERESTARTNOHAND:
226 case -ERESTARTNOINTR:
227 regs->r06 = regs->syscall_nr;
229 case -ERESTART_RESTARTBLOCK:
230 regs->r06 = __NR_restart_syscall;
235 pt_set_elr(regs, pt_elr(regs) - 4);
236 regs->r00 = regs->restart_r0;
240 /* If there's no signal to deliver, put the saved sigmask back */
241 restore_saved_sigmask();
245 * Architecture-specific wrappers for signal-related system calls
248 asmlinkage int sys_rt_sigreturn(void)
250 struct pt_regs *regs = current_pt_regs();
251 struct rt_sigframe __user *frame;
254 /* Always make any pending restarted system calls return -EINTR */
255 current_thread_info()->restart_block.fn = do_no_restart_syscall;
257 frame = (struct rt_sigframe __user *)pt_psp(regs);
258 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
260 if (__copy_from_user(&blocked, &frame->uc.uc_sigmask, sizeof(blocked)))
263 set_current_blocked(&blocked);
265 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
268 /* Restore the user's stack as well */
269 pt_psp(regs) = regs->r29;
271 regs->syscall_nr = -1;
273 if (restore_altstack(&frame->uc.uc_stack))
279 force_sig(SIGSEGV, current);