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
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
31 #include <linux/sched.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/extable.h>
46 #include <linux/tracehook.h>
48 #include <asm/setup.h>
49 #include <linux/uaccess.h>
50 #include <asm/traps.h>
51 #include <asm/ucontext.h>
52 #include <asm/cacheflush.h>
57 * Handle the slight differences in classic 68k and ColdFire trap frames.
59 #ifdef CONFIG_COLDFIRE
64 #define FMT4SIZE sizeof_field(struct frame, un.fmt4)
67 static const int frame_size_change
[16] = {
68 [1] = -1, /* sizeof_field(struct frame, un.fmt1), */
69 [2] = sizeof_field(struct frame
, un
.fmt2
),
70 [3] = sizeof_field(struct frame
, un
.fmt3
),
72 [5] = -1, /* sizeof_field(struct frame, un.fmt5), */
73 [6] = -1, /* sizeof_field(struct frame, un.fmt6), */
74 [7] = sizeof_field(struct frame
, un
.fmt7
),
75 [8] = -1, /* sizeof_field(struct frame, un.fmt8), */
76 [9] = sizeof_field(struct frame
, un
.fmt9
),
77 [10] = sizeof_field(struct frame
, un
.fmta
),
78 [11] = sizeof_field(struct frame
, un
.fmtb
),
79 [12] = -1, /* sizeof_field(struct frame, un.fmtc), */
80 [13] = -1, /* sizeof_field(struct frame, un.fmtd), */
81 [14] = -1, /* sizeof_field(struct frame, un.fmte), */
82 [15] = -1, /* sizeof_field(struct frame, un.fmtf), */
85 static inline int frame_extra_sizes(int f
)
87 return frame_size_change
[f
];
90 int fixup_exception(struct pt_regs
*regs
)
92 const struct exception_table_entry
*fixup
;
93 struct pt_regs
*tregs
;
95 /* Are we prepared to handle this kernel fault? */
96 fixup
= search_exception_tables(regs
->pc
);
100 /* Create a new four word stack frame, discarding the old one. */
101 regs
->stkadj
= frame_extra_sizes(regs
->format
);
102 tregs
= (struct pt_regs
*)((long)regs
+ regs
->stkadj
);
103 tregs
->vector
= regs
->vector
;
104 tregs
->format
= FORMAT
;
105 tregs
->pc
= fixup
->fixup
;
106 tregs
->sr
= regs
->sr
;
111 static inline void push_cache (unsigned long vaddr
)
114 * Using the old cache_push_v() was really a big waste.
116 * What we are trying to do is to flush 8 bytes to ram.
117 * Flushing 2 cache lines of 16 bytes is much cheaper than
118 * flushing 1 or 2 pages, as previously done in
125 __asm__
__volatile__ (".chip 68040\n\t"
128 "movec %%mmusr,%0\n\t"
134 temp
|= vaddr
& ~PAGE_MASK
;
136 __asm__
__volatile__ (".chip 68040\n\t"
138 "cpushl %%bc,(%0)\n\t"
142 else if (CPU_IS_060
) {
144 __asm__
__volatile__ (".chip 68060\n\t"
149 __asm__
__volatile__ (".chip 68060\n\t"
150 "cpushl %%bc,(%0)\n\t"
153 } else if (!CPU_IS_COLDFIRE
) {
155 * 68030/68020 have no writeback cache;
156 * still need to clear icache.
157 * Note that vaddr is guaranteed to be long word aligned.
160 asm volatile ("movec %%cacr,%0" : "=r" (temp
));
162 asm volatile ("movec %0,%%caar\n\t"
164 : : "r" (vaddr
), "r" (temp
));
165 asm volatile ("movec %0,%%caar\n\t"
167 : : "r" (vaddr
+ 4), "r" (temp
));
169 /* CPU_IS_COLDFIRE */
170 #if defined(CONFIG_CACHE_COPYBACK)
171 flush_cf_dcache(0, DCACHE_MAX_ADDR
);
173 /* Invalidate instruction cache for the pushed bytes */
174 clear_cf_icache(vaddr
, vaddr
+ 8);
178 static inline void adjustformat(struct pt_regs
*regs
)
182 static inline void save_a5_state(struct sigcontext
*sc
, struct pt_regs
*regs
)
186 #else /* CONFIG_MMU */
188 void ret_from_user_signal(void);
189 void ret_from_user_rt_signal(void);
191 static inline int frame_extra_sizes(int f
)
193 /* No frame size adjustments required on non-MMU CPUs */
197 static inline void adjustformat(struct pt_regs
*regs
)
200 * set format byte to make stack appear modulo 4, which it will
201 * be when doing the rte
206 static inline void save_a5_state(struct sigcontext
*sc
, struct pt_regs
*regs
)
208 sc
->sc_a5
= ((struct switch_stack
*)regs
- 1)->a5
;
211 static inline void push_cache(unsigned long vaddr
)
215 #endif /* CONFIG_MMU */
218 * Do a signal return; undo the signal stack.
220 * Keep the return code on the stack quadword aligned!
221 * That makes the cache flush below easier.
226 char __user
*pretcode
;
229 struct sigcontext __user
*psc
;
231 unsigned long extramask
[_NSIG_WORDS
-1];
232 struct sigcontext sc
;
237 char __user
*pretcode
;
239 struct siginfo __user
*pinfo
;
246 #define FPCONTEXT_SIZE 216
247 #define uc_fpstate uc_filler[0]
248 #define uc_formatvec uc_filler[FPCONTEXT_SIZE/4]
249 #define uc_extra uc_filler[FPCONTEXT_SIZE/4+1]
253 static unsigned char fpu_version
; /* version number of fpu, set by setup_frame */
255 static inline int restore_fpu_state(struct sigcontext
*sc
)
260 /* restore registers */
261 memcpy(current
->thread
.fpcntl
, sc
->sc_fpcntl
, 12);
262 memcpy(current
->thread
.fp
, sc
->sc_fpregs
, 24);
266 if (CPU_IS_060
? sc
->sc_fpstate
[2] : sc
->sc_fpstate
[0]) {
267 /* Verify the frame format. */
268 if (!(CPU_IS_060
|| CPU_IS_COLDFIRE
) &&
269 (sc
->sc_fpstate
[0] != fpu_version
))
271 if (CPU_IS_020_OR_030
) {
272 if (m68k_fputype
& FPU_68881
&&
273 !(sc
->sc_fpstate
[1] == 0x18 || sc
->sc_fpstate
[1] == 0xb4))
275 if (m68k_fputype
& FPU_68882
&&
276 !(sc
->sc_fpstate
[1] == 0x38 || sc
->sc_fpstate
[1] == 0xd4))
278 } else if (CPU_IS_040
) {
279 if (!(sc
->sc_fpstate
[1] == 0x00 ||
280 sc
->sc_fpstate
[1] == 0x28 ||
281 sc
->sc_fpstate
[1] == 0x60))
283 } else if (CPU_IS_060
) {
284 if (!(sc
->sc_fpstate
[3] == 0x00 ||
285 sc
->sc_fpstate
[3] == 0x60 ||
286 sc
->sc_fpstate
[3] == 0xe0))
288 } else if (CPU_IS_COLDFIRE
) {
289 if (!(sc
->sc_fpstate
[0] == 0x00 ||
290 sc
->sc_fpstate
[0] == 0x05 ||
291 sc
->sc_fpstate
[0] == 0xe5))
296 if (CPU_IS_COLDFIRE
) {
297 __asm__
volatile ("fmovemd %0,%%fp0-%%fp1\n\t"
298 "fmovel %1,%%fpcr\n\t"
299 "fmovel %2,%%fpsr\n\t"
302 : "m" (sc
->sc_fpregs
[0]),
303 "m" (sc
->sc_fpcntl
[0]),
304 "m" (sc
->sc_fpcntl
[1]),
305 "m" (sc
->sc_fpcntl
[2]));
307 __asm__
volatile (".chip 68k/68881\n\t"
308 "fmovemx %0,%%fp0-%%fp1\n\t"
309 "fmoveml %1,%%fpcr/%%fpsr/%%fpiar\n\t"
312 : "m" (*sc
->sc_fpregs
),
313 "m" (*sc
->sc_fpcntl
));
317 if (CPU_IS_COLDFIRE
) {
318 __asm__
volatile ("frestore %0" : : "m" (*sc
->sc_fpstate
));
320 __asm__
volatile (".chip 68k/68881\n\t"
323 : : "m" (*sc
->sc_fpstate
));
331 static inline int rt_restore_fpu_state(struct ucontext __user
*uc
)
333 unsigned char fpstate
[FPCONTEXT_SIZE
];
334 int context_size
= CPU_IS_060
? 8 : (CPU_IS_COLDFIRE
? 12 : 0);
339 /* restore fpu control register */
340 if (__copy_from_user(current
->thread
.fpcntl
,
341 uc
->uc_mcontext
.fpregs
.f_fpcntl
, 12))
343 /* restore all other fpu register */
344 if (__copy_from_user(current
->thread
.fp
,
345 uc
->uc_mcontext
.fpregs
.f_fpregs
, 96))
350 if (__get_user(*(long *)fpstate
, (long __user
*)&uc
->uc_fpstate
))
352 if (CPU_IS_060
? fpstate
[2] : fpstate
[0]) {
353 if (!(CPU_IS_060
|| CPU_IS_COLDFIRE
))
354 context_size
= fpstate
[1];
355 /* Verify the frame format. */
356 if (!(CPU_IS_060
|| CPU_IS_COLDFIRE
) &&
357 (fpstate
[0] != fpu_version
))
359 if (CPU_IS_020_OR_030
) {
360 if (m68k_fputype
& FPU_68881
&&
361 !(context_size
== 0x18 || context_size
== 0xb4))
363 if (m68k_fputype
& FPU_68882
&&
364 !(context_size
== 0x38 || context_size
== 0xd4))
366 } else if (CPU_IS_040
) {
367 if (!(context_size
== 0x00 ||
368 context_size
== 0x28 ||
369 context_size
== 0x60))
371 } else if (CPU_IS_060
) {
372 if (!(fpstate
[3] == 0x00 ||
373 fpstate
[3] == 0x60 ||
376 } else if (CPU_IS_COLDFIRE
) {
377 if (!(fpstate
[3] == 0x00 ||
378 fpstate
[3] == 0x05 ||
383 if (__copy_from_user(&fpregs
, &uc
->uc_mcontext
.fpregs
,
387 if (CPU_IS_COLDFIRE
) {
388 __asm__
volatile ("fmovemd %0,%%fp0-%%fp7\n\t"
389 "fmovel %1,%%fpcr\n\t"
390 "fmovel %2,%%fpsr\n\t"
393 : "m" (fpregs
.f_fpregs
[0]),
394 "m" (fpregs
.f_fpcntl
[0]),
395 "m" (fpregs
.f_fpcntl
[1]),
396 "m" (fpregs
.f_fpcntl
[2]));
398 __asm__
volatile (".chip 68k/68881\n\t"
399 "fmovemx %0,%%fp0-%%fp7\n\t"
400 "fmoveml %1,%%fpcr/%%fpsr/%%fpiar\n\t"
403 : "m" (*fpregs
.f_fpregs
),
404 "m" (*fpregs
.f_fpcntl
));
408 __copy_from_user(fpstate
+ 4, (long __user
*)&uc
->uc_fpstate
+ 1,
412 if (CPU_IS_COLDFIRE
) {
413 __asm__
volatile ("frestore %0" : : "m" (*fpstate
));
415 __asm__
volatile (".chip 68k/68881\n\t"
427 * Set up a signal frame.
429 static inline void save_fpu_state(struct sigcontext
*sc
, struct pt_regs
*regs
)
433 memcpy(sc
->sc_fpcntl
, current
->thread
.fpcntl
, 12);
434 memcpy(sc
->sc_fpregs
, current
->thread
.fp
, 24);
438 if (CPU_IS_COLDFIRE
) {
439 __asm__
volatile ("fsave %0"
440 : : "m" (*sc
->sc_fpstate
) : "memory");
442 __asm__
volatile (".chip 68k/68881\n\t"
445 : : "m" (*sc
->sc_fpstate
) : "memory");
448 if (CPU_IS_060
? sc
->sc_fpstate
[2] : sc
->sc_fpstate
[0]) {
449 fpu_version
= sc
->sc_fpstate
[0];
450 if (CPU_IS_020_OR_030
&&
451 regs
->vector
>= (VEC_FPBRUC
* 4) &&
452 regs
->vector
<= (VEC_FPNAN
* 4)) {
453 /* Clear pending exception in 68882 idle frame */
454 if (*(unsigned short *) sc
->sc_fpstate
== 0x1f38)
455 sc
->sc_fpstate
[0x38] |= 1 << 3;
458 if (CPU_IS_COLDFIRE
) {
459 __asm__
volatile ("fmovemd %%fp0-%%fp1,%0\n\t"
460 "fmovel %%fpcr,%1\n\t"
461 "fmovel %%fpsr,%2\n\t"
463 : "=m" (sc
->sc_fpregs
[0]),
464 "=m" (sc
->sc_fpcntl
[0]),
465 "=m" (sc
->sc_fpcntl
[1]),
466 "=m" (sc
->sc_fpcntl
[2])
470 __asm__
volatile (".chip 68k/68881\n\t"
471 "fmovemx %%fp0-%%fp1,%0\n\t"
472 "fmoveml %%fpcr/%%fpsr/%%fpiar,%1\n\t"
474 : "=m" (*sc
->sc_fpregs
),
475 "=m" (*sc
->sc_fpcntl
)
482 static inline int rt_save_fpu_state(struct ucontext __user
*uc
, struct pt_regs
*regs
)
484 unsigned char fpstate
[FPCONTEXT_SIZE
];
485 int context_size
= CPU_IS_060
? 8 : (CPU_IS_COLDFIRE
? 12 : 0);
489 /* save fpu control register */
490 err
|= copy_to_user(uc
->uc_mcontext
.fpregs
.f_fpcntl
,
491 current
->thread
.fpcntl
, 12);
492 /* save all other fpu register */
493 err
|= copy_to_user(uc
->uc_mcontext
.fpregs
.f_fpregs
,
494 current
->thread
.fp
, 96);
498 if (CPU_IS_COLDFIRE
) {
499 __asm__
volatile ("fsave %0" : : "m" (*fpstate
) : "memory");
501 __asm__
volatile (".chip 68k/68881\n\t"
504 : : "m" (*fpstate
) : "memory");
507 err
|= __put_user(*(long *)fpstate
, (long __user
*)&uc
->uc_fpstate
);
508 if (CPU_IS_060
? fpstate
[2] : fpstate
[0]) {
510 if (!(CPU_IS_060
|| CPU_IS_COLDFIRE
))
511 context_size
= fpstate
[1];
512 fpu_version
= fpstate
[0];
513 if (CPU_IS_020_OR_030
&&
514 regs
->vector
>= (VEC_FPBRUC
* 4) &&
515 regs
->vector
<= (VEC_FPNAN
* 4)) {
516 /* Clear pending exception in 68882 idle frame */
517 if (*(unsigned short *) fpstate
== 0x1f38)
518 fpstate
[0x38] |= 1 << 3;
520 if (CPU_IS_COLDFIRE
) {
521 __asm__
volatile ("fmovemd %%fp0-%%fp7,%0\n\t"
522 "fmovel %%fpcr,%1\n\t"
523 "fmovel %%fpsr,%2\n\t"
525 : "=m" (fpregs
.f_fpregs
[0]),
526 "=m" (fpregs
.f_fpcntl
[0]),
527 "=m" (fpregs
.f_fpcntl
[1]),
528 "=m" (fpregs
.f_fpcntl
[2])
532 __asm__
volatile (".chip 68k/68881\n\t"
533 "fmovemx %%fp0-%%fp7,%0\n\t"
534 "fmoveml %%fpcr/%%fpsr/%%fpiar,%1\n\t"
536 : "=m" (*fpregs
.f_fpregs
),
537 "=m" (*fpregs
.f_fpcntl
)
541 err
|= copy_to_user(&uc
->uc_mcontext
.fpregs
, &fpregs
,
545 err
|= copy_to_user((long __user
*)&uc
->uc_fpstate
+ 1, fpstate
+ 4,
550 #else /* CONFIG_FPU */
553 * For the case with no FPU configured these all do nothing.
555 static inline int restore_fpu_state(struct sigcontext
*sc
)
560 static inline int rt_restore_fpu_state(struct ucontext __user
*uc
)
565 static inline void save_fpu_state(struct sigcontext
*sc
, struct pt_regs
*regs
)
569 static inline int rt_save_fpu_state(struct ucontext __user
*uc
, struct pt_regs
*regs
)
574 #endif /* CONFIG_FPU */
576 static inline void siginfo_build_tests(void)
579 * This needs to be tested on m68k as it has a lesser
580 * alignment requirement than x86 and that can cause surprises.
583 /* This is part of the ABI and can never change in size: */
584 BUILD_BUG_ON(sizeof(siginfo_t
) != 128);
586 /* Ensure the known fields never change in location */
587 BUILD_BUG_ON(offsetof(siginfo_t
, si_signo
) != 0);
588 BUILD_BUG_ON(offsetof(siginfo_t
, si_errno
) != 4);
589 BUILD_BUG_ON(offsetof(siginfo_t
, si_code
) != 8);
592 BUILD_BUG_ON(offsetof(siginfo_t
, si_pid
) != 0x0c);
593 BUILD_BUG_ON(offsetof(siginfo_t
, si_uid
) != 0x10);
596 BUILD_BUG_ON(offsetof(siginfo_t
, si_tid
) != 0x0c);
597 BUILD_BUG_ON(offsetof(siginfo_t
, si_overrun
) != 0x10);
598 BUILD_BUG_ON(offsetof(siginfo_t
, si_value
) != 0x14);
601 BUILD_BUG_ON(offsetof(siginfo_t
, si_pid
) != 0x0c);
602 BUILD_BUG_ON(offsetof(siginfo_t
, si_uid
) != 0x10);
603 BUILD_BUG_ON(offsetof(siginfo_t
, si_value
) != 0x14);
606 BUILD_BUG_ON(offsetof(siginfo_t
, si_pid
) != 0x0c);
607 BUILD_BUG_ON(offsetof(siginfo_t
, si_uid
) != 0x10);
608 BUILD_BUG_ON(offsetof(siginfo_t
, si_status
) != 0x14);
609 BUILD_BUG_ON(offsetof(siginfo_t
, si_utime
) != 0x18);
610 BUILD_BUG_ON(offsetof(siginfo_t
, si_stime
) != 0x1c);
613 BUILD_BUG_ON(offsetof(siginfo_t
, si_addr
) != 0x0c);
615 /* _sigfault._mcerr */
616 BUILD_BUG_ON(offsetof(siginfo_t
, si_addr_lsb
) != 0x10);
618 /* _sigfault._addr_bnd */
619 BUILD_BUG_ON(offsetof(siginfo_t
, si_lower
) != 0x12);
620 BUILD_BUG_ON(offsetof(siginfo_t
, si_upper
) != 0x16);
622 /* _sigfault._addr_pkey */
623 BUILD_BUG_ON(offsetof(siginfo_t
, si_pkey
) != 0x12);
626 BUILD_BUG_ON(offsetof(siginfo_t
, si_band
) != 0x0c);
627 BUILD_BUG_ON(offsetof(siginfo_t
, si_fd
) != 0x10);
630 BUILD_BUG_ON(offsetof(siginfo_t
, si_call_addr
) != 0x0c);
631 BUILD_BUG_ON(offsetof(siginfo_t
, si_syscall
) != 0x10);
632 BUILD_BUG_ON(offsetof(siginfo_t
, si_arch
) != 0x14);
634 /* any new si_fields should be added here */
637 static int mangle_kernel_stack(struct pt_regs
*regs
, int formatvec
,
640 int fsize
= frame_extra_sizes(formatvec
>> 12);
643 * user process trying to return with weird frame format
645 pr_debug("user process returning with weird frame format\n");
649 regs
->format
= formatvec
>> 12;
650 regs
->vector
= formatvec
& 0xfff;
652 struct switch_stack
*sw
= (struct switch_stack
*)regs
- 1;
653 /* yes, twice as much as max(sizeof(frame.un.fmt<x>)) */
654 unsigned long buf
[sizeof_field(struct frame
, un
) / 2];
656 /* that'll make sure that expansion won't crap over data */
657 if (copy_from_user(buf
+ fsize
/ 4, fp
, fsize
))
660 /* point of no return */
661 regs
->format
= formatvec
>> 12;
662 regs
->vector
= formatvec
& 0xfff;
663 #define frame_offset (sizeof(struct pt_regs)+sizeof(struct switch_stack))
664 __asm__
__volatile__ (
665 #ifdef CONFIG_COLDFIRE
667 " bra ret_from_signal\n"
670 " subl %1,%/a0\n\t" /* make room on stack */
671 " movel %/a0,%/sp\n\t" /* set stack pointer */
672 /* move switch_stack and pt_regs */
673 "1: movel %0@+,%/a0@+\n\t"
675 " lea %/sp@(%c3),%/a0\n\t" /* add offset of fmt */
678 /* copy to the gap we'd made */
679 "2: movel %4@+,%/a0@+\n\t"
681 " bral ret_from_signal\n"
683 : /* no outputs, it doesn't ever return */
684 : "a" (sw
), "d" (fsize
), "d" (frame_offset
/4-1),
685 "n" (frame_offset
), "a" (buf
+ fsize
/4)
693 restore_sigcontext(struct pt_regs
*regs
, struct sigcontext __user
*usc
, void __user
*fp
)
696 struct sigcontext context
;
699 siginfo_build_tests();
701 /* Always make any pending restarted system calls return -EINTR */
702 current
->restart_block
.fn
= do_no_restart_syscall
;
704 /* get previous context */
705 if (copy_from_user(&context
, usc
, sizeof(context
)))
708 /* restore passed registers */
709 regs
->d0
= context
.sc_d0
;
710 regs
->d1
= context
.sc_d1
;
711 regs
->a0
= context
.sc_a0
;
712 regs
->a1
= context
.sc_a1
;
713 regs
->sr
= (regs
->sr
& 0xff00) | (context
.sc_sr
& 0xff);
714 regs
->pc
= context
.sc_pc
;
715 regs
->orig_d0
= -1; /* disable syscall checks */
716 wrusp(context
.sc_usp
);
717 formatvec
= context
.sc_formatvec
;
719 err
= restore_fpu_state(&context
);
721 if (err
|| mangle_kernel_stack(regs
, formatvec
, fp
))
731 rt_restore_ucontext(struct pt_regs
*regs
, struct switch_stack
*sw
,
732 struct ucontext __user
*uc
)
735 greg_t __user
*gregs
= uc
->uc_mcontext
.gregs
;
739 /* Always make any pending restarted system calls return -EINTR */
740 current
->restart_block
.fn
= do_no_restart_syscall
;
742 err
= __get_user(temp
, &uc
->uc_mcontext
.version
);
743 if (temp
!= MCONTEXT_VERSION
)
745 /* restore passed registers */
746 err
|= __get_user(regs
->d0
, &gregs
[0]);
747 err
|= __get_user(regs
->d1
, &gregs
[1]);
748 err
|= __get_user(regs
->d2
, &gregs
[2]);
749 err
|= __get_user(regs
->d3
, &gregs
[3]);
750 err
|= __get_user(regs
->d4
, &gregs
[4]);
751 err
|= __get_user(regs
->d5
, &gregs
[5]);
752 err
|= __get_user(sw
->d6
, &gregs
[6]);
753 err
|= __get_user(sw
->d7
, &gregs
[7]);
754 err
|= __get_user(regs
->a0
, &gregs
[8]);
755 err
|= __get_user(regs
->a1
, &gregs
[9]);
756 err
|= __get_user(regs
->a2
, &gregs
[10]);
757 err
|= __get_user(sw
->a3
, &gregs
[11]);
758 err
|= __get_user(sw
->a4
, &gregs
[12]);
759 err
|= __get_user(sw
->a5
, &gregs
[13]);
760 err
|= __get_user(sw
->a6
, &gregs
[14]);
761 err
|= __get_user(usp
, &gregs
[15]);
763 err
|= __get_user(regs
->pc
, &gregs
[16]);
764 err
|= __get_user(temp
, &gregs
[17]);
765 regs
->sr
= (regs
->sr
& 0xff00) | (temp
& 0xff);
766 regs
->orig_d0
= -1; /* disable syscall checks */
767 err
|= __get_user(temp
, &uc
->uc_formatvec
);
769 err
|= rt_restore_fpu_state(uc
);
770 err
|= restore_altstack(&uc
->uc_stack
);
775 if (mangle_kernel_stack(regs
, temp
, &uc
->uc_extra
))
784 asmlinkage
int do_sigreturn(struct pt_regs
*regs
, struct switch_stack
*sw
)
786 unsigned long usp
= rdusp();
787 struct sigframe __user
*frame
= (struct sigframe __user
*)(usp
- 4);
790 if (!access_ok(frame
, sizeof(*frame
)))
792 if (__get_user(set
.sig
[0], &frame
->sc
.sc_mask
) ||
794 __copy_from_user(&set
.sig
[1], &frame
->extramask
,
795 sizeof(frame
->extramask
))))
798 set_current_blocked(&set
);
800 if (restore_sigcontext(regs
, &frame
->sc
, frame
+ 1))
809 asmlinkage
int do_rt_sigreturn(struct pt_regs
*regs
, struct switch_stack
*sw
)
811 unsigned long usp
= rdusp();
812 struct rt_sigframe __user
*frame
= (struct rt_sigframe __user
*)(usp
- 4);
815 if (!access_ok(frame
, sizeof(*frame
)))
817 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
820 set_current_blocked(&set
);
822 if (rt_restore_ucontext(regs
, sw
, &frame
->uc
))
831 static void setup_sigcontext(struct sigcontext
*sc
, struct pt_regs
*regs
,
835 sc
->sc_usp
= rdusp();
836 sc
->sc_d0
= regs
->d0
;
837 sc
->sc_d1
= regs
->d1
;
838 sc
->sc_a0
= regs
->a0
;
839 sc
->sc_a1
= regs
->a1
;
840 sc
->sc_sr
= regs
->sr
;
841 sc
->sc_pc
= regs
->pc
;
842 sc
->sc_formatvec
= regs
->format
<< 12 | regs
->vector
;
843 save_a5_state(sc
, regs
);
844 save_fpu_state(sc
, regs
);
847 static inline int rt_setup_ucontext(struct ucontext __user
*uc
, struct pt_regs
*regs
)
849 struct switch_stack
*sw
= (struct switch_stack
*)regs
- 1;
850 greg_t __user
*gregs
= uc
->uc_mcontext
.gregs
;
853 err
|= __put_user(MCONTEXT_VERSION
, &uc
->uc_mcontext
.version
);
854 err
|= __put_user(regs
->d0
, &gregs
[0]);
855 err
|= __put_user(regs
->d1
, &gregs
[1]);
856 err
|= __put_user(regs
->d2
, &gregs
[2]);
857 err
|= __put_user(regs
->d3
, &gregs
[3]);
858 err
|= __put_user(regs
->d4
, &gregs
[4]);
859 err
|= __put_user(regs
->d5
, &gregs
[5]);
860 err
|= __put_user(sw
->d6
, &gregs
[6]);
861 err
|= __put_user(sw
->d7
, &gregs
[7]);
862 err
|= __put_user(regs
->a0
, &gregs
[8]);
863 err
|= __put_user(regs
->a1
, &gregs
[9]);
864 err
|= __put_user(regs
->a2
, &gregs
[10]);
865 err
|= __put_user(sw
->a3
, &gregs
[11]);
866 err
|= __put_user(sw
->a4
, &gregs
[12]);
867 err
|= __put_user(sw
->a5
, &gregs
[13]);
868 err
|= __put_user(sw
->a6
, &gregs
[14]);
869 err
|= __put_user(rdusp(), &gregs
[15]);
870 err
|= __put_user(regs
->pc
, &gregs
[16]);
871 err
|= __put_user(regs
->sr
, &gregs
[17]);
872 err
|= __put_user((regs
->format
<< 12) | regs
->vector
, &uc
->uc_formatvec
);
873 err
|= rt_save_fpu_state(uc
, regs
);
877 static inline void __user
*
878 get_sigframe(struct ksignal
*ksig
, size_t frame_size
)
880 unsigned long usp
= sigsp(rdusp(), ksig
);
882 return (void __user
*)((usp
- frame_size
) & -8UL);
885 static int setup_frame(struct ksignal
*ksig
, sigset_t
*set
,
886 struct pt_regs
*regs
)
888 struct sigframe __user
*frame
;
889 int fsize
= frame_extra_sizes(regs
->format
);
890 struct sigcontext context
;
891 int err
= 0, sig
= ksig
->sig
;
894 pr_debug("setup_frame: Unknown frame format %#x\n",
899 frame
= get_sigframe(ksig
, sizeof(*frame
) + fsize
);
902 err
|= copy_to_user (frame
+ 1, regs
+ 1, fsize
);
904 err
|= __put_user(sig
, &frame
->sig
);
906 err
|= __put_user(regs
->vector
, &frame
->code
);
907 err
|= __put_user(&frame
->sc
, &frame
->psc
);
910 err
|= copy_to_user(frame
->extramask
, &set
->sig
[1],
911 sizeof(frame
->extramask
));
913 setup_sigcontext(&context
, regs
, set
->sig
[0]);
914 err
|= copy_to_user (&frame
->sc
, &context
, sizeof(context
));
916 /* Set up to return from userspace. */
918 err
|= __put_user(frame
->retcode
, &frame
->pretcode
);
919 /* moveq #,d0; trap #0 */
920 err
|= __put_user(0x70004e40 + (__NR_sigreturn
<< 16),
921 (long __user
*)(frame
->retcode
));
923 err
|= __put_user((long) ret_from_user_signal
,
924 (long __user
*) &frame
->pretcode
);
930 push_cache ((unsigned long) &frame
->retcode
);
933 * Set up registers for signal handler. All the state we are about
934 * to destroy is successfully copied to sigframe.
936 wrusp ((unsigned long) frame
);
937 regs
->pc
= (unsigned long) ksig
->ka
.sa
.sa_handler
;
941 * This is subtle; if we build more than one sigframe, all but the
942 * first one will see frame format 0 and have fsize == 0, so we won't
946 regs
->stkadj
= fsize
;
948 /* Prepare to skip over the extra stuff in the exception frame. */
950 struct pt_regs
*tregs
=
951 (struct pt_regs
*)((ulong
)regs
+ regs
->stkadj
);
952 pr_debug("Performing stackadjust=%04lx\n", regs
->stkadj
);
953 /* This must be copied with decreasing addresses to
957 tregs
->pc
= regs
->pc
;
958 tregs
->sr
= regs
->sr
;
963 static int setup_rt_frame(struct ksignal
*ksig
, sigset_t
*set
,
964 struct pt_regs
*regs
)
966 struct rt_sigframe __user
*frame
;
967 int fsize
= frame_extra_sizes(regs
->format
);
968 int err
= 0, sig
= ksig
->sig
;
971 pr_debug("setup_frame: Unknown frame format %#x\n",
976 frame
= get_sigframe(ksig
, sizeof(*frame
));
979 err
|= copy_to_user (&frame
->uc
.uc_extra
, regs
+ 1, fsize
);
981 err
|= __put_user(sig
, &frame
->sig
);
982 err
|= __put_user(&frame
->info
, &frame
->pinfo
);
983 err
|= __put_user(&frame
->uc
, &frame
->puc
);
984 err
|= copy_siginfo_to_user(&frame
->info
, &ksig
->info
);
986 /* Create the ucontext. */
987 err
|= __put_user(0, &frame
->uc
.uc_flags
);
988 err
|= __put_user(NULL
, &frame
->uc
.uc_link
);
989 err
|= __save_altstack(&frame
->uc
.uc_stack
, rdusp());
990 err
|= rt_setup_ucontext(&frame
->uc
, regs
);
991 err
|= copy_to_user (&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
993 /* Set up to return from userspace. */
995 err
|= __put_user(frame
->retcode
, &frame
->pretcode
);
997 /* movel #__NR_rt_sigreturn,d0; trap #0 */
998 err
|= __put_user(0x203c0000, (long __user
*)(frame
->retcode
+ 0));
999 err
|= __put_user(0x00004e40 + (__NR_rt_sigreturn
<< 16),
1000 (long __user
*)(frame
->retcode
+ 4));
1002 /* moveq #,d0; notb d0; trap #0 */
1003 err
|= __put_user(0x70004600 + ((__NR_rt_sigreturn
^ 0xff) << 16),
1004 (long __user
*)(frame
->retcode
+ 0));
1005 err
|= __put_user(0x4e40, (short __user
*)(frame
->retcode
+ 4));
1008 err
|= __put_user((long) ret_from_user_rt_signal
,
1009 (long __user
*) &frame
->pretcode
);
1010 #endif /* CONFIG_MMU */
1015 push_cache ((unsigned long) &frame
->retcode
);
1018 * Set up registers for signal handler. All the state we are about
1019 * to destroy is successfully copied to sigframe.
1021 wrusp ((unsigned long) frame
);
1022 regs
->pc
= (unsigned long) ksig
->ka
.sa
.sa_handler
;
1026 * This is subtle; if we build more than one sigframe, all but the
1027 * first one will see frame format 0 and have fsize == 0, so we won't
1031 regs
->stkadj
= fsize
;
1033 /* Prepare to skip over the extra stuff in the exception frame. */
1035 struct pt_regs
*tregs
=
1036 (struct pt_regs
*)((ulong
)regs
+ regs
->stkadj
);
1037 pr_debug("Performing stackadjust=%04lx\n", regs
->stkadj
);
1038 /* This must be copied with decreasing addresses to
1042 tregs
->pc
= regs
->pc
;
1043 tregs
->sr
= regs
->sr
;
1049 handle_restart(struct pt_regs
*regs
, struct k_sigaction
*ka
, int has_handler
)
1052 case -ERESTARTNOHAND
:
1058 case -ERESTART_RESTARTBLOCK
:
1060 regs
->d0
= __NR_restart_syscall
;
1068 if (has_handler
&& !(ka
->sa
.sa_flags
& SA_RESTART
)) {
1073 case -ERESTARTNOINTR
:
1075 regs
->d0
= regs
->orig_d0
;
1082 * OK, we're invoking a handler
1085 handle_signal(struct ksignal
*ksig
, struct pt_regs
*regs
)
1087 sigset_t
*oldset
= sigmask_to_save();
1089 /* are we from a system call? */
1090 if (regs
->orig_d0
>= 0)
1091 /* If so, check system call restarting.. */
1092 handle_restart(regs
, &ksig
->ka
, 1);
1094 /* set up the stack frame */
1095 if (ksig
->ka
.sa
.sa_flags
& SA_SIGINFO
)
1096 err
= setup_rt_frame(ksig
, oldset
, regs
);
1098 err
= setup_frame(ksig
, oldset
, regs
);
1100 signal_setup_done(err
, ksig
, 0);
1102 if (test_thread_flag(TIF_DELAYED_TRACE
)) {
1103 regs
->sr
&= ~0x8000;
1104 send_sig(SIGTRAP
, current
, 1);
1109 * Note that 'init' is a special process: it doesn't get signals it doesn't
1110 * want to handle. Thus you cannot kill init even with a SIGKILL even by
1113 static void do_signal(struct pt_regs
*regs
)
1115 struct ksignal ksig
;
1117 current
->thread
.esp0
= (unsigned long) regs
;
1119 if (get_signal(&ksig
)) {
1120 /* Whee! Actually deliver the signal. */
1121 handle_signal(&ksig
, regs
);
1125 /* Did we come from a system call? */
1126 if (regs
->orig_d0
>= 0)
1127 /* Restart the system call - no handlers present */
1128 handle_restart(regs
, NULL
, 0);
1130 /* If there's no signal to deliver, we just restore the saved mask. */
1131 restore_saved_sigmask();
1134 void do_notify_resume(struct pt_regs
*regs
)
1136 if (test_thread_flag(TIF_NOTIFY_SIGNAL
) ||
1137 test_thread_flag(TIF_SIGPENDING
))
1140 if (test_thread_flag(TIF_NOTIFY_RESUME
))
1141 tracehook_notify_resume(regs
);