Add linux-next specific files for 20110831
[linux-2.6/next.git] / arch / m68k / kernel / signal_mm.c
blob74ba0cff1ad92562180036540594d9bee51ceb88
1 /*
2 * linux/arch/m68k/kernel/signal.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 */
12 * Linux/m68k support by Hamish Macdonald
14 * 68060 fixes by Jesper Skov
16 * 1997-12-01 Modified for POSIX.1b signals by Andreas Schwab
18 * mathemu support by Roman Zippel
19 * (Note: fpstate in the signal context is completely ignored for the emulator
20 * and the internal floating point format is put on stack)
24 * ++roman (07/09/96): implemented signal stacks (specially for tosemu on
25 * Atari :-) Current limitation: Only one sigstack can be active at one time.
26 * If a second signal with SA_ONSTACK set arrives while working on a sigstack,
27 * SA_ONSTACK is ignored. This behaviour avoids lots of trouble with nested
28 * signal handlers!
31 #include <linux/sched.h>
32 #include <linux/mm.h>
33 #include <linux/kernel.h>
34 #include <linux/signal.h>
35 #include <linux/syscalls.h>
36 #include <linux/errno.h>
37 #include <linux/wait.h>
38 #include <linux/ptrace.h>
39 #include <linux/unistd.h>
40 #include <linux/stddef.h>
41 #include <linux/highuid.h>
42 #include <linux/personality.h>
43 #include <linux/tty.h>
44 #include <linux/binfmts.h>
45 #include <linux/module.h>
47 #include <asm/setup.h>
48 #include <asm/uaccess.h>
49 #include <asm/pgtable.h>
50 #include <asm/traps.h>
51 #include <asm/ucontext.h>
53 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
55 static const int frame_extra_sizes[16] = {
56 [1] = -1, /* sizeof(((struct frame *)0)->un.fmt1), */
57 [2] = sizeof(((struct frame *)0)->un.fmt2),
58 [3] = sizeof(((struct frame *)0)->un.fmt3),
59 [4] = sizeof(((struct frame *)0)->un.fmt4),
60 [5] = -1, /* sizeof(((struct frame *)0)->un.fmt5), */
61 [6] = -1, /* sizeof(((struct frame *)0)->un.fmt6), */
62 [7] = sizeof(((struct frame *)0)->un.fmt7),
63 [8] = -1, /* sizeof(((struct frame *)0)->un.fmt8), */
64 [9] = sizeof(((struct frame *)0)->un.fmt9),
65 [10] = sizeof(((struct frame *)0)->un.fmta),
66 [11] = sizeof(((struct frame *)0)->un.fmtb),
67 [12] = -1, /* sizeof(((struct frame *)0)->un.fmtc), */
68 [13] = -1, /* sizeof(((struct frame *)0)->un.fmtd), */
69 [14] = -1, /* sizeof(((struct frame *)0)->un.fmte), */
70 [15] = -1, /* sizeof(((struct frame *)0)->un.fmtf), */
73 int handle_kernel_fault(struct pt_regs *regs)
75 const struct exception_table_entry *fixup;
76 struct pt_regs *tregs;
78 /* Are we prepared to handle this kernel fault? */
79 fixup = search_exception_tables(regs->pc);
80 if (!fixup)
81 return 0;
83 /* Create a new four word stack frame, discarding the old one. */
84 regs->stkadj = frame_extra_sizes[regs->format];
85 tregs = (struct pt_regs *)((long)regs + regs->stkadj);
86 tregs->vector = regs->vector;
87 tregs->format = 0;
88 tregs->pc = fixup->fixup;
89 tregs->sr = regs->sr;
91 return 1;
95 * Atomically swap in the new signal mask, and wait for a signal.
97 asmlinkage int
98 sys_sigsuspend(int unused0, int unused1, old_sigset_t mask)
100 sigset_t blocked;
102 current->saved_sigmask = current->blocked;
104 mask &= _BLOCKABLE;
105 siginitset(&blocked, mask);
106 set_current_blocked(&blocked);
108 current->state = TASK_INTERRUPTIBLE;
109 schedule();
110 set_restore_sigmask();
112 return -ERESTARTNOHAND;
115 asmlinkage int
116 sys_sigaction(int sig, const struct old_sigaction __user *act,
117 struct old_sigaction __user *oact)
119 struct k_sigaction new_ka, old_ka;
120 int ret;
122 if (act) {
123 old_sigset_t mask;
124 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
125 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
126 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
127 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
128 __get_user(mask, &act->sa_mask))
129 return -EFAULT;
130 siginitset(&new_ka.sa.sa_mask, mask);
133 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
135 if (!ret && oact) {
136 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
137 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
138 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
139 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
140 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
141 return -EFAULT;
144 return ret;
147 asmlinkage int
148 sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
150 return do_sigaltstack(uss, uoss, rdusp());
155 * Do a signal return; undo the signal stack.
157 * Keep the return code on the stack quadword aligned!
158 * That makes the cache flush below easier.
161 struct sigframe
163 char __user *pretcode;
164 int sig;
165 int code;
166 struct sigcontext __user *psc;
167 char retcode[8];
168 unsigned long extramask[_NSIG_WORDS-1];
169 struct sigcontext sc;
172 struct rt_sigframe
174 char __user *pretcode;
175 int sig;
176 struct siginfo __user *pinfo;
177 void __user *puc;
178 char retcode[8];
179 struct siginfo info;
180 struct ucontext uc;
184 static unsigned char fpu_version; /* version number of fpu, set by setup_frame */
186 static inline int restore_fpu_state(struct sigcontext *sc)
188 int err = 1;
190 if (FPU_IS_EMU) {
191 /* restore registers */
192 memcpy(current->thread.fpcntl, sc->sc_fpcntl, 12);
193 memcpy(current->thread.fp, sc->sc_fpregs, 24);
194 return 0;
197 if (CPU_IS_060 ? sc->sc_fpstate[2] : sc->sc_fpstate[0]) {
198 /* Verify the frame format. */
199 if (!CPU_IS_060 && (sc->sc_fpstate[0] != fpu_version))
200 goto out;
201 if (CPU_IS_020_OR_030) {
202 if (m68k_fputype & FPU_68881 &&
203 !(sc->sc_fpstate[1] == 0x18 || sc->sc_fpstate[1] == 0xb4))
204 goto out;
205 if (m68k_fputype & FPU_68882 &&
206 !(sc->sc_fpstate[1] == 0x38 || sc->sc_fpstate[1] == 0xd4))
207 goto out;
208 } else if (CPU_IS_040) {
209 if (!(sc->sc_fpstate[1] == 0x00 ||
210 sc->sc_fpstate[1] == 0x28 ||
211 sc->sc_fpstate[1] == 0x60))
212 goto out;
213 } else if (CPU_IS_060) {
214 if (!(sc->sc_fpstate[3] == 0x00 ||
215 sc->sc_fpstate[3] == 0x60 ||
216 sc->sc_fpstate[3] == 0xe0))
217 goto out;
218 } else
219 goto out;
221 __asm__ volatile (".chip 68k/68881\n\t"
222 "fmovemx %0,%%fp0-%%fp1\n\t"
223 "fmoveml %1,%%fpcr/%%fpsr/%%fpiar\n\t"
224 ".chip 68k"
225 : /* no outputs */
226 : "m" (*sc->sc_fpregs), "m" (*sc->sc_fpcntl));
228 __asm__ volatile (".chip 68k/68881\n\t"
229 "frestore %0\n\t"
230 ".chip 68k" : : "m" (*sc->sc_fpstate));
231 err = 0;
233 out:
234 return err;
237 #define FPCONTEXT_SIZE 216
238 #define uc_fpstate uc_filler[0]
239 #define uc_formatvec uc_filler[FPCONTEXT_SIZE/4]
240 #define uc_extra uc_filler[FPCONTEXT_SIZE/4+1]
242 static inline int rt_restore_fpu_state(struct ucontext __user *uc)
244 unsigned char fpstate[FPCONTEXT_SIZE];
245 int context_size = CPU_IS_060 ? 8 : 0;
246 fpregset_t fpregs;
247 int err = 1;
249 if (FPU_IS_EMU) {
250 /* restore fpu control register */
251 if (__copy_from_user(current->thread.fpcntl,
252 uc->uc_mcontext.fpregs.f_fpcntl, 12))
253 goto out;
254 /* restore all other fpu register */
255 if (__copy_from_user(current->thread.fp,
256 uc->uc_mcontext.fpregs.f_fpregs, 96))
257 goto out;
258 return 0;
261 if (__get_user(*(long *)fpstate, (long __user *)&uc->uc_fpstate))
262 goto out;
263 if (CPU_IS_060 ? fpstate[2] : fpstate[0]) {
264 if (!CPU_IS_060)
265 context_size = fpstate[1];
266 /* Verify the frame format. */
267 if (!CPU_IS_060 && (fpstate[0] != fpu_version))
268 goto out;
269 if (CPU_IS_020_OR_030) {
270 if (m68k_fputype & FPU_68881 &&
271 !(context_size == 0x18 || context_size == 0xb4))
272 goto out;
273 if (m68k_fputype & FPU_68882 &&
274 !(context_size == 0x38 || context_size == 0xd4))
275 goto out;
276 } else if (CPU_IS_040) {
277 if (!(context_size == 0x00 ||
278 context_size == 0x28 ||
279 context_size == 0x60))
280 goto out;
281 } else if (CPU_IS_060) {
282 if (!(fpstate[3] == 0x00 ||
283 fpstate[3] == 0x60 ||
284 fpstate[3] == 0xe0))
285 goto out;
286 } else
287 goto out;
288 if (__copy_from_user(&fpregs, &uc->uc_mcontext.fpregs,
289 sizeof(fpregs)))
290 goto out;
291 __asm__ volatile (".chip 68k/68881\n\t"
292 "fmovemx %0,%%fp0-%%fp7\n\t"
293 "fmoveml %1,%%fpcr/%%fpsr/%%fpiar\n\t"
294 ".chip 68k"
295 : /* no outputs */
296 : "m" (*fpregs.f_fpregs),
297 "m" (*fpregs.f_fpcntl));
299 if (context_size &&
300 __copy_from_user(fpstate + 4, (long __user *)&uc->uc_fpstate + 1,
301 context_size))
302 goto out;
303 __asm__ volatile (".chip 68k/68881\n\t"
304 "frestore %0\n\t"
305 ".chip 68k" : : "m" (*fpstate));
306 err = 0;
308 out:
309 return err;
312 static int mangle_kernel_stack(struct pt_regs *regs, int formatvec,
313 void __user *fp)
315 int fsize = frame_extra_sizes[formatvec >> 12];
316 if (fsize < 0) {
318 * user process trying to return with weird frame format
320 #ifdef DEBUG
321 printk("user process returning with weird frame format\n");
322 #endif
323 return 1;
325 if (!fsize) {
326 regs->format = formatvec >> 12;
327 regs->vector = formatvec & 0xfff;
328 } else {
329 struct switch_stack *sw = (struct switch_stack *)regs - 1;
330 unsigned long buf[fsize / 2]; /* yes, twice as much */
332 /* that'll make sure that expansion won't crap over data */
333 if (copy_from_user(buf + fsize / 4, fp, fsize))
334 return 1;
336 /* point of no return */
337 regs->format = formatvec >> 12;
338 regs->vector = formatvec & 0xfff;
339 #define frame_offset (sizeof(struct pt_regs)+sizeof(struct switch_stack))
340 __asm__ __volatile__
341 (" movel %0,%/a0\n\t"
342 " subl %1,%/a0\n\t" /* make room on stack */
343 " movel %/a0,%/sp\n\t" /* set stack pointer */
344 /* move switch_stack and pt_regs */
345 "1: movel %0@+,%/a0@+\n\t"
346 " dbra %2,1b\n\t"
347 " lea %/sp@(%c3),%/a0\n\t" /* add offset of fmt */
348 " lsrl #2,%1\n\t"
349 " subql #1,%1\n\t"
350 /* copy to the gap we'd made */
351 "2: movel %4@+,%/a0@+\n\t"
352 " dbra %1,2b\n\t"
353 " bral ret_from_signal\n"
354 : /* no outputs, it doesn't ever return */
355 : "a" (sw), "d" (fsize), "d" (frame_offset/4-1),
356 "n" (frame_offset), "a" (buf + fsize/4)
357 : "a0");
358 #undef frame_offset
360 return 0;
363 static inline int
364 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *usc, void __user *fp)
366 int formatvec;
367 struct sigcontext context;
368 int err;
370 /* Always make any pending restarted system calls return -EINTR */
371 current_thread_info()->restart_block.fn = do_no_restart_syscall;
373 /* get previous context */
374 if (copy_from_user(&context, usc, sizeof(context)))
375 goto badframe;
377 /* restore passed registers */
378 regs->d0 = context.sc_d0;
379 regs->d1 = context.sc_d1;
380 regs->a0 = context.sc_a0;
381 regs->a1 = context.sc_a1;
382 regs->sr = (regs->sr & 0xff00) | (context.sc_sr & 0xff);
383 regs->pc = context.sc_pc;
384 regs->orig_d0 = -1; /* disable syscall checks */
385 wrusp(context.sc_usp);
386 formatvec = context.sc_formatvec;
388 err = restore_fpu_state(&context);
390 if (err || mangle_kernel_stack(regs, formatvec, fp))
391 goto badframe;
393 return 0;
395 badframe:
396 return 1;
399 static inline int
400 rt_restore_ucontext(struct pt_regs *regs, struct switch_stack *sw,
401 struct ucontext __user *uc)
403 int temp;
404 greg_t __user *gregs = uc->uc_mcontext.gregs;
405 unsigned long usp;
406 int err;
408 /* Always make any pending restarted system calls return -EINTR */
409 current_thread_info()->restart_block.fn = do_no_restart_syscall;
411 err = __get_user(temp, &uc->uc_mcontext.version);
412 if (temp != MCONTEXT_VERSION)
413 goto badframe;
414 /* restore passed registers */
415 err |= __get_user(regs->d0, &gregs[0]);
416 err |= __get_user(regs->d1, &gregs[1]);
417 err |= __get_user(regs->d2, &gregs[2]);
418 err |= __get_user(regs->d3, &gregs[3]);
419 err |= __get_user(regs->d4, &gregs[4]);
420 err |= __get_user(regs->d5, &gregs[5]);
421 err |= __get_user(sw->d6, &gregs[6]);
422 err |= __get_user(sw->d7, &gregs[7]);
423 err |= __get_user(regs->a0, &gregs[8]);
424 err |= __get_user(regs->a1, &gregs[9]);
425 err |= __get_user(regs->a2, &gregs[10]);
426 err |= __get_user(sw->a3, &gregs[11]);
427 err |= __get_user(sw->a4, &gregs[12]);
428 err |= __get_user(sw->a5, &gregs[13]);
429 err |= __get_user(sw->a6, &gregs[14]);
430 err |= __get_user(usp, &gregs[15]);
431 wrusp(usp);
432 err |= __get_user(regs->pc, &gregs[16]);
433 err |= __get_user(temp, &gregs[17]);
434 regs->sr = (regs->sr & 0xff00) | (temp & 0xff);
435 regs->orig_d0 = -1; /* disable syscall checks */
436 err |= __get_user(temp, &uc->uc_formatvec);
438 err |= rt_restore_fpu_state(uc);
440 if (err || do_sigaltstack(&uc->uc_stack, NULL, usp) == -EFAULT)
441 goto badframe;
443 if (mangle_kernel_stack(regs, temp, &uc->uc_extra))
444 goto badframe;
446 return 0;
448 badframe:
449 return 1;
452 asmlinkage int do_sigreturn(unsigned long __unused)
454 struct switch_stack *sw = (struct switch_stack *) &__unused;
455 struct pt_regs *regs = (struct pt_regs *) (sw + 1);
456 unsigned long usp = rdusp();
457 struct sigframe __user *frame = (struct sigframe __user *)(usp - 4);
458 sigset_t set;
460 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
461 goto badframe;
462 if (__get_user(set.sig[0], &frame->sc.sc_mask) ||
463 (_NSIG_WORDS > 1 &&
464 __copy_from_user(&set.sig[1], &frame->extramask,
465 sizeof(frame->extramask))))
466 goto badframe;
468 sigdelsetmask(&set, ~_BLOCKABLE);
469 set_current_blocked(&set);
471 if (restore_sigcontext(regs, &frame->sc, frame + 1))
472 goto badframe;
473 return regs->d0;
475 badframe:
476 force_sig(SIGSEGV, current);
477 return 0;
480 asmlinkage int do_rt_sigreturn(unsigned long __unused)
482 struct switch_stack *sw = (struct switch_stack *) &__unused;
483 struct pt_regs *regs = (struct pt_regs *) (sw + 1);
484 unsigned long usp = rdusp();
485 struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(usp - 4);
486 sigset_t set;
488 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
489 goto badframe;
490 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
491 goto badframe;
493 sigdelsetmask(&set, ~_BLOCKABLE);
494 set_current_blocked(&set);
496 if (rt_restore_ucontext(regs, sw, &frame->uc))
497 goto badframe;
498 return regs->d0;
500 badframe:
501 force_sig(SIGSEGV, current);
502 return 0;
506 * Set up a signal frame.
509 static inline void save_fpu_state(struct sigcontext *sc, struct pt_regs *regs)
511 if (FPU_IS_EMU) {
512 /* save registers */
513 memcpy(sc->sc_fpcntl, current->thread.fpcntl, 12);
514 memcpy(sc->sc_fpregs, current->thread.fp, 24);
515 return;
518 __asm__ volatile (".chip 68k/68881\n\t"
519 "fsave %0\n\t"
520 ".chip 68k"
521 : : "m" (*sc->sc_fpstate) : "memory");
523 if (CPU_IS_060 ? sc->sc_fpstate[2] : sc->sc_fpstate[0]) {
524 fpu_version = sc->sc_fpstate[0];
525 if (CPU_IS_020_OR_030 &&
526 regs->vector >= (VEC_FPBRUC * 4) &&
527 regs->vector <= (VEC_FPNAN * 4)) {
528 /* Clear pending exception in 68882 idle frame */
529 if (*(unsigned short *) sc->sc_fpstate == 0x1f38)
530 sc->sc_fpstate[0x38] |= 1 << 3;
532 __asm__ volatile (".chip 68k/68881\n\t"
533 "fmovemx %%fp0-%%fp1,%0\n\t"
534 "fmoveml %%fpcr/%%fpsr/%%fpiar,%1\n\t"
535 ".chip 68k"
536 : "=m" (*sc->sc_fpregs),
537 "=m" (*sc->sc_fpcntl)
538 : /* no inputs */
539 : "memory");
543 static inline int rt_save_fpu_state(struct ucontext __user *uc, struct pt_regs *regs)
545 unsigned char fpstate[FPCONTEXT_SIZE];
546 int context_size = CPU_IS_060 ? 8 : 0;
547 int err = 0;
549 if (FPU_IS_EMU) {
550 /* save fpu control register */
551 err |= copy_to_user(uc->uc_mcontext.fpregs.f_fpcntl,
552 current->thread.fpcntl, 12);
553 /* save all other fpu register */
554 err |= copy_to_user(uc->uc_mcontext.fpregs.f_fpregs,
555 current->thread.fp, 96);
556 return err;
559 __asm__ volatile (".chip 68k/68881\n\t"
560 "fsave %0\n\t"
561 ".chip 68k"
562 : : "m" (*fpstate) : "memory");
564 err |= __put_user(*(long *)fpstate, (long __user *)&uc->uc_fpstate);
565 if (CPU_IS_060 ? fpstate[2] : fpstate[0]) {
566 fpregset_t fpregs;
567 if (!CPU_IS_060)
568 context_size = fpstate[1];
569 fpu_version = fpstate[0];
570 if (CPU_IS_020_OR_030 &&
571 regs->vector >= (VEC_FPBRUC * 4) &&
572 regs->vector <= (VEC_FPNAN * 4)) {
573 /* Clear pending exception in 68882 idle frame */
574 if (*(unsigned short *) fpstate == 0x1f38)
575 fpstate[0x38] |= 1 << 3;
577 __asm__ volatile (".chip 68k/68881\n\t"
578 "fmovemx %%fp0-%%fp7,%0\n\t"
579 "fmoveml %%fpcr/%%fpsr/%%fpiar,%1\n\t"
580 ".chip 68k"
581 : "=m" (*fpregs.f_fpregs),
582 "=m" (*fpregs.f_fpcntl)
583 : /* no inputs */
584 : "memory");
585 err |= copy_to_user(&uc->uc_mcontext.fpregs, &fpregs,
586 sizeof(fpregs));
588 if (context_size)
589 err |= copy_to_user((long __user *)&uc->uc_fpstate + 1, fpstate + 4,
590 context_size);
591 return err;
594 static void setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs,
595 unsigned long mask)
597 sc->sc_mask = mask;
598 sc->sc_usp = rdusp();
599 sc->sc_d0 = regs->d0;
600 sc->sc_d1 = regs->d1;
601 sc->sc_a0 = regs->a0;
602 sc->sc_a1 = regs->a1;
603 sc->sc_sr = regs->sr;
604 sc->sc_pc = regs->pc;
605 sc->sc_formatvec = regs->format << 12 | regs->vector;
606 save_fpu_state(sc, regs);
609 static inline int rt_setup_ucontext(struct ucontext __user *uc, struct pt_regs *regs)
611 struct switch_stack *sw = (struct switch_stack *)regs - 1;
612 greg_t __user *gregs = uc->uc_mcontext.gregs;
613 int err = 0;
615 err |= __put_user(MCONTEXT_VERSION, &uc->uc_mcontext.version);
616 err |= __put_user(regs->d0, &gregs[0]);
617 err |= __put_user(regs->d1, &gregs[1]);
618 err |= __put_user(regs->d2, &gregs[2]);
619 err |= __put_user(regs->d3, &gregs[3]);
620 err |= __put_user(regs->d4, &gregs[4]);
621 err |= __put_user(regs->d5, &gregs[5]);
622 err |= __put_user(sw->d6, &gregs[6]);
623 err |= __put_user(sw->d7, &gregs[7]);
624 err |= __put_user(regs->a0, &gregs[8]);
625 err |= __put_user(regs->a1, &gregs[9]);
626 err |= __put_user(regs->a2, &gregs[10]);
627 err |= __put_user(sw->a3, &gregs[11]);
628 err |= __put_user(sw->a4, &gregs[12]);
629 err |= __put_user(sw->a5, &gregs[13]);
630 err |= __put_user(sw->a6, &gregs[14]);
631 err |= __put_user(rdusp(), &gregs[15]);
632 err |= __put_user(regs->pc, &gregs[16]);
633 err |= __put_user(regs->sr, &gregs[17]);
634 err |= __put_user((regs->format << 12) | regs->vector, &uc->uc_formatvec);
635 err |= rt_save_fpu_state(uc, regs);
636 return err;
639 static inline void push_cache (unsigned long vaddr)
642 * Using the old cache_push_v() was really a big waste.
644 * What we are trying to do is to flush 8 bytes to ram.
645 * Flushing 2 cache lines of 16 bytes is much cheaper than
646 * flushing 1 or 2 pages, as previously done in
647 * cache_push_v().
648 * Jes
650 if (CPU_IS_040) {
651 unsigned long temp;
653 __asm__ __volatile__ (".chip 68040\n\t"
654 "nop\n\t"
655 "ptestr (%1)\n\t"
656 "movec %%mmusr,%0\n\t"
657 ".chip 68k"
658 : "=r" (temp)
659 : "a" (vaddr));
661 temp &= PAGE_MASK;
662 temp |= vaddr & ~PAGE_MASK;
664 __asm__ __volatile__ (".chip 68040\n\t"
665 "nop\n\t"
666 "cpushl %%bc,(%0)\n\t"
667 ".chip 68k"
668 : : "a" (temp));
670 else if (CPU_IS_060) {
671 unsigned long temp;
672 __asm__ __volatile__ (".chip 68060\n\t"
673 "plpar (%0)\n\t"
674 ".chip 68k"
675 : "=a" (temp)
676 : "0" (vaddr));
677 __asm__ __volatile__ (".chip 68060\n\t"
678 "cpushl %%bc,(%0)\n\t"
679 ".chip 68k"
680 : : "a" (temp));
682 else {
684 * 68030/68020 have no writeback cache;
685 * still need to clear icache.
686 * Note that vaddr is guaranteed to be long word aligned.
688 unsigned long temp;
689 asm volatile ("movec %%cacr,%0" : "=r" (temp));
690 temp += 4;
691 asm volatile ("movec %0,%%caar\n\t"
692 "movec %1,%%cacr"
693 : : "r" (vaddr), "r" (temp));
694 asm volatile ("movec %0,%%caar\n\t"
695 "movec %1,%%cacr"
696 : : "r" (vaddr + 4), "r" (temp));
700 static inline void __user *
701 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
703 unsigned long usp;
705 /* Default to using normal stack. */
706 usp = rdusp();
708 /* This is the X/Open sanctioned signal stack switching. */
709 if (ka->sa.sa_flags & SA_ONSTACK) {
710 if (!sas_ss_flags(usp))
711 usp = current->sas_ss_sp + current->sas_ss_size;
713 return (void __user *)((usp - frame_size) & -8UL);
716 static int setup_frame (int sig, struct k_sigaction *ka,
717 sigset_t *set, struct pt_regs *regs)
719 struct sigframe __user *frame;
720 int fsize = frame_extra_sizes[regs->format];
721 struct sigcontext context;
722 int err = 0;
724 if (fsize < 0) {
725 #ifdef DEBUG
726 printk ("setup_frame: Unknown frame format %#x\n",
727 regs->format);
728 #endif
729 goto give_sigsegv;
732 frame = get_sigframe(ka, regs, sizeof(*frame) + fsize);
734 if (fsize)
735 err |= copy_to_user (frame + 1, regs + 1, fsize);
737 err |= __put_user((current_thread_info()->exec_domain
738 && current_thread_info()->exec_domain->signal_invmap
739 && sig < 32
740 ? current_thread_info()->exec_domain->signal_invmap[sig]
741 : sig),
742 &frame->sig);
744 err |= __put_user(regs->vector, &frame->code);
745 err |= __put_user(&frame->sc, &frame->psc);
747 if (_NSIG_WORDS > 1)
748 err |= copy_to_user(frame->extramask, &set->sig[1],
749 sizeof(frame->extramask));
751 setup_sigcontext(&context, regs, set->sig[0]);
752 err |= copy_to_user (&frame->sc, &context, sizeof(context));
754 /* Set up to return from userspace. */
755 err |= __put_user(frame->retcode, &frame->pretcode);
756 /* moveq #,d0; trap #0 */
757 err |= __put_user(0x70004e40 + (__NR_sigreturn << 16),
758 (long __user *)(frame->retcode));
760 if (err)
761 goto give_sigsegv;
763 push_cache ((unsigned long) &frame->retcode);
766 * Set up registers for signal handler. All the state we are about
767 * to destroy is successfully copied to sigframe.
769 wrusp ((unsigned long) frame);
770 regs->pc = (unsigned long) ka->sa.sa_handler;
773 * This is subtle; if we build more than one sigframe, all but the
774 * first one will see frame format 0 and have fsize == 0, so we won't
775 * screw stkadj.
777 if (fsize)
778 regs->stkadj = fsize;
780 /* Prepare to skip over the extra stuff in the exception frame. */
781 if (regs->stkadj) {
782 struct pt_regs *tregs =
783 (struct pt_regs *)((ulong)regs + regs->stkadj);
784 #ifdef DEBUG
785 printk("Performing stackadjust=%04x\n", regs->stkadj);
786 #endif
787 /* This must be copied with decreasing addresses to
788 handle overlaps. */
789 tregs->vector = 0;
790 tregs->format = 0;
791 tregs->pc = regs->pc;
792 tregs->sr = regs->sr;
794 return 0;
796 give_sigsegv:
797 force_sigsegv(sig, current);
798 return err;
801 static int setup_rt_frame (int sig, struct k_sigaction *ka, siginfo_t *info,
802 sigset_t *set, struct pt_regs *regs)
804 struct rt_sigframe __user *frame;
805 int fsize = frame_extra_sizes[regs->format];
806 int err = 0;
808 if (fsize < 0) {
809 #ifdef DEBUG
810 printk ("setup_frame: Unknown frame format %#x\n",
811 regs->format);
812 #endif
813 goto give_sigsegv;
816 frame = get_sigframe(ka, regs, sizeof(*frame));
818 if (fsize)
819 err |= copy_to_user (&frame->uc.uc_extra, regs + 1, fsize);
821 err |= __put_user((current_thread_info()->exec_domain
822 && current_thread_info()->exec_domain->signal_invmap
823 && sig < 32
824 ? current_thread_info()->exec_domain->signal_invmap[sig]
825 : sig),
826 &frame->sig);
827 err |= __put_user(&frame->info, &frame->pinfo);
828 err |= __put_user(&frame->uc, &frame->puc);
829 err |= copy_siginfo_to_user(&frame->info, info);
831 /* Create the ucontext. */
832 err |= __put_user(0, &frame->uc.uc_flags);
833 err |= __put_user(NULL, &frame->uc.uc_link);
834 err |= __put_user((void __user *)current->sas_ss_sp,
835 &frame->uc.uc_stack.ss_sp);
836 err |= __put_user(sas_ss_flags(rdusp()),
837 &frame->uc.uc_stack.ss_flags);
838 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
839 err |= rt_setup_ucontext(&frame->uc, regs);
840 err |= copy_to_user (&frame->uc.uc_sigmask, set, sizeof(*set));
842 /* Set up to return from userspace. */
843 err |= __put_user(frame->retcode, &frame->pretcode);
844 #ifdef __mcoldfire__
845 /* movel #__NR_rt_sigreturn,d0; trap #0 */
846 err |= __put_user(0x203c0000, (long __user *)(frame->retcode + 0));
847 err |= __put_user(0x00004e40 + (__NR_rt_sigreturn << 16),
848 (long __user *)(frame->retcode + 4));
849 #else
850 /* moveq #,d0; notb d0; trap #0 */
851 err |= __put_user(0x70004600 + ((__NR_rt_sigreturn ^ 0xff) << 16),
852 (long __user *)(frame->retcode + 0));
853 err |= __put_user(0x4e40, (short __user *)(frame->retcode + 4));
854 #endif
856 if (err)
857 goto give_sigsegv;
859 push_cache ((unsigned long) &frame->retcode);
862 * Set up registers for signal handler. All the state we are about
863 * to destroy is successfully copied to sigframe.
865 wrusp ((unsigned long) frame);
866 regs->pc = (unsigned long) ka->sa.sa_handler;
869 * This is subtle; if we build more than one sigframe, all but the
870 * first one will see frame format 0 and have fsize == 0, so we won't
871 * screw stkadj.
873 if (fsize)
874 regs->stkadj = fsize;
876 /* Prepare to skip over the extra stuff in the exception frame. */
877 if (regs->stkadj) {
878 struct pt_regs *tregs =
879 (struct pt_regs *)((ulong)regs + regs->stkadj);
880 #ifdef DEBUG
881 printk("Performing stackadjust=%04x\n", regs->stkadj);
882 #endif
883 /* This must be copied with decreasing addresses to
884 handle overlaps. */
885 tregs->vector = 0;
886 tregs->format = 0;
887 tregs->pc = regs->pc;
888 tregs->sr = regs->sr;
890 return 0;
892 give_sigsegv:
893 force_sigsegv(sig, current);
894 return err;
897 static inline void
898 handle_restart(struct pt_regs *regs, struct k_sigaction *ka, int has_handler)
900 switch (regs->d0) {
901 case -ERESTARTNOHAND:
902 if (!has_handler)
903 goto do_restart;
904 regs->d0 = -EINTR;
905 break;
907 case -ERESTART_RESTARTBLOCK:
908 if (!has_handler) {
909 regs->d0 = __NR_restart_syscall;
910 regs->pc -= 2;
911 break;
913 regs->d0 = -EINTR;
914 break;
916 case -ERESTARTSYS:
917 if (has_handler && !(ka->sa.sa_flags & SA_RESTART)) {
918 regs->d0 = -EINTR;
919 break;
921 /* fallthrough */
922 case -ERESTARTNOINTR:
923 do_restart:
924 regs->d0 = regs->orig_d0;
925 regs->pc -= 2;
926 break;
930 void ptrace_signal_deliver(struct pt_regs *regs, void *cookie)
932 if (regs->orig_d0 < 0)
933 return;
934 switch (regs->d0) {
935 case -ERESTARTNOHAND:
936 case -ERESTARTSYS:
937 case -ERESTARTNOINTR:
938 regs->d0 = regs->orig_d0;
939 regs->orig_d0 = -1;
940 regs->pc -= 2;
941 break;
946 * OK, we're invoking a handler
948 static void
949 handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
950 sigset_t *oldset, struct pt_regs *regs)
952 int err;
953 /* are we from a system call? */
954 if (regs->orig_d0 >= 0)
955 /* If so, check system call restarting.. */
956 handle_restart(regs, ka, 1);
958 /* set up the stack frame */
959 if (ka->sa.sa_flags & SA_SIGINFO)
960 err = setup_rt_frame(sig, ka, info, oldset, regs);
961 else
962 err = setup_frame(sig, ka, oldset, regs);
964 if (err)
965 return;
967 block_sigmask(ka, sig);
969 if (test_thread_flag(TIF_DELAYED_TRACE)) {
970 regs->sr &= ~0x8000;
971 send_sig(SIGTRAP, current, 1);
974 clear_thread_flag(TIF_RESTORE_SIGMASK);
978 * Note that 'init' is a special process: it doesn't get signals it doesn't
979 * want to handle. Thus you cannot kill init even with a SIGKILL even by
980 * mistake.
982 asmlinkage void do_signal(struct pt_regs *regs)
984 siginfo_t info;
985 struct k_sigaction ka;
986 int signr;
987 sigset_t *oldset;
989 current->thread.esp0 = (unsigned long) regs;
991 if (test_thread_flag(TIF_RESTORE_SIGMASK))
992 oldset = &current->saved_sigmask;
993 else
994 oldset = &current->blocked;
996 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
997 if (signr > 0) {
998 /* Whee! Actually deliver the signal. */
999 handle_signal(signr, &ka, &info, oldset, regs);
1000 return;
1003 /* Did we come from a system call? */
1004 if (regs->orig_d0 >= 0)
1005 /* Restart the system call - no handlers present */
1006 handle_restart(regs, NULL, 0);
1008 /* If there's no signal to deliver, we just restore the saved mask. */
1009 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
1010 clear_thread_flag(TIF_RESTORE_SIGMASK);
1011 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);