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/resume_user_mode.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>
59 * Handle the slight differences in classic 68k and ColdFire trap frames.
61 #ifdef CONFIG_COLDFIRE
66 #define FMT4SIZE sizeof_field(struct frame, un.fmt4)
69 static const int frame_size_change
[16] = {
70 [1] = -1, /* sizeof_field(struct frame, un.fmt1), */
71 [2] = sizeof_field(struct frame
, un
.fmt2
),
72 [3] = sizeof_field(struct frame
, un
.fmt3
),
74 [5] = -1, /* sizeof_field(struct frame, un.fmt5), */
75 [6] = -1, /* sizeof_field(struct frame, un.fmt6), */
76 [7] = sizeof_field(struct frame
, un
.fmt7
),
77 [8] = -1, /* sizeof_field(struct frame, un.fmt8), */
78 [9] = sizeof_field(struct frame
, un
.fmt9
),
79 [10] = sizeof_field(struct frame
, un
.fmta
),
80 [11] = sizeof_field(struct frame
, un
.fmtb
),
81 [12] = -1, /* sizeof_field(struct frame, un.fmtc), */
82 [13] = -1, /* sizeof_field(struct frame, un.fmtd), */
83 [14] = -1, /* sizeof_field(struct frame, un.fmte), */
84 [15] = -1, /* sizeof_field(struct frame, un.fmtf), */
87 static inline int frame_extra_sizes(int f
)
89 return frame_size_change
[f
];
92 int fixup_exception(struct pt_regs
*regs
)
94 const struct exception_table_entry
*fixup
;
95 struct pt_regs
*tregs
;
97 /* Are we prepared to handle this kernel fault? */
98 fixup
= search_exception_tables(regs
->pc
);
102 /* Create a new four word stack frame, discarding the old one. */
103 regs
->stkadj
= frame_extra_sizes(regs
->format
);
104 tregs
= (struct pt_regs
*)((long)regs
+ regs
->stkadj
);
105 tregs
->vector
= regs
->vector
;
106 tregs
->format
= FORMAT
;
107 tregs
->pc
= fixup
->fixup
;
108 tregs
->sr
= regs
->sr
;
113 static inline void push_cache (unsigned long vaddr
)
116 * Using the old cache_push_v() was really a big waste.
118 * What we are trying to do is to flush 8 bytes to ram.
119 * Flushing 2 cache lines of 16 bytes is much cheaper than
120 * flushing 1 or 2 pages, as previously done in
127 __asm__
__volatile__ (".chip 68040\n\t"
130 "movec %%mmusr,%0\n\t"
136 temp
|= vaddr
& ~PAGE_MASK
;
138 __asm__
__volatile__ (".chip 68040\n\t"
140 "cpushl %%bc,(%0)\n\t"
144 else if (CPU_IS_060
) {
146 __asm__
__volatile__ (".chip 68060\n\t"
151 __asm__
__volatile__ (".chip 68060\n\t"
152 "cpushl %%bc,(%0)\n\t"
155 } else if (!CPU_IS_COLDFIRE
) {
157 * 68030/68020 have no writeback cache;
158 * still need to clear icache.
159 * Note that vaddr is guaranteed to be long word aligned.
162 asm volatile ("movec %%cacr,%0" : "=r" (temp
));
164 asm volatile ("movec %0,%%caar\n\t"
166 : : "r" (vaddr
), "r" (temp
));
167 asm volatile ("movec %0,%%caar\n\t"
169 : : "r" (vaddr
+ 4), "r" (temp
));
171 /* CPU_IS_COLDFIRE */
172 #if defined(CONFIG_CACHE_COPYBACK)
173 flush_cf_dcache(0, DCACHE_MAX_ADDR
);
175 /* Invalidate instruction cache for the pushed bytes */
176 clear_cf_icache(vaddr
, vaddr
+ 8);
180 static inline void adjustformat(struct pt_regs
*regs
)
184 static inline void save_a5_state(struct sigcontext
*sc
, struct pt_regs
*regs
)
188 #else /* CONFIG_MMU */
190 void ret_from_user_signal(void);
191 void ret_from_user_rt_signal(void);
193 static inline int frame_extra_sizes(int f
)
195 /* No frame size adjustments required on non-MMU CPUs */
199 static inline void adjustformat(struct pt_regs
*regs
)
202 * set format byte to make stack appear modulo 4, which it will
203 * be when doing the rte
208 static inline void save_a5_state(struct sigcontext
*sc
, struct pt_regs
*regs
)
210 sc
->sc_a5
= ((struct switch_stack
*)regs
- 1)->a5
;
213 static inline void push_cache(unsigned long vaddr
)
217 #endif /* CONFIG_MMU */
220 * Do a signal return; undo the signal stack.
222 * Keep the return code on the stack quadword aligned!
223 * That makes the cache flush below easier.
228 char __user
*pretcode
;
231 struct sigcontext __user
*psc
;
233 unsigned long extramask
[_NSIG_WORDS
-1];
234 struct sigcontext sc
;
239 char __user
*pretcode
;
241 struct siginfo __user
*pinfo
;
248 #define FPCONTEXT_SIZE 216
249 #define uc_fpstate uc_filler[0]
250 #define uc_formatvec uc_filler[FPCONTEXT_SIZE/4]
251 #define uc_extra uc_filler[FPCONTEXT_SIZE/4+1]
255 static unsigned char fpu_version
; /* version number of fpu, set by setup_frame */
257 static inline int restore_fpu_state(struct sigcontext
*sc
)
262 /* restore registers */
263 memcpy(current
->thread
.fpcntl
, sc
->sc_fpcntl
, 12);
264 memcpy(current
->thread
.fp
, sc
->sc_fpregs
, 24);
268 if (CPU_IS_060
? sc
->sc_fpstate
[2] : sc
->sc_fpstate
[0]) {
269 /* Verify the frame format. */
270 if (!(CPU_IS_060
|| CPU_IS_COLDFIRE
) &&
271 (sc
->sc_fpstate
[0] != fpu_version
))
273 if (CPU_IS_020_OR_030
) {
274 if (m68k_fputype
& FPU_68881
&&
275 !(sc
->sc_fpstate
[1] == 0x18 || sc
->sc_fpstate
[1] == 0xb4))
277 if (m68k_fputype
& FPU_68882
&&
278 !(sc
->sc_fpstate
[1] == 0x38 || sc
->sc_fpstate
[1] == 0xd4))
280 } else if (CPU_IS_040
) {
281 if (!(sc
->sc_fpstate
[1] == 0x00 ||
282 sc
->sc_fpstate
[1] == 0x28 ||
283 sc
->sc_fpstate
[1] == 0x60))
285 } else if (CPU_IS_060
) {
286 if (!(sc
->sc_fpstate
[3] == 0x00 ||
287 sc
->sc_fpstate
[3] == 0x60 ||
288 sc
->sc_fpstate
[3] == 0xe0))
290 } else if (CPU_IS_COLDFIRE
) {
291 if (!(sc
->sc_fpstate
[0] == 0x00 ||
292 sc
->sc_fpstate
[0] == 0x05 ||
293 sc
->sc_fpstate
[0] == 0xe5))
298 if (CPU_IS_COLDFIRE
) {
299 __asm__
volatile ("fmovemd %0,%%fp0-%%fp1\n\t"
300 "fmovel %1,%%fpcr\n\t"
301 "fmovel %2,%%fpsr\n\t"
304 : "m" (sc
->sc_fpregs
[0]),
305 "m" (sc
->sc_fpcntl
[0]),
306 "m" (sc
->sc_fpcntl
[1]),
307 "m" (sc
->sc_fpcntl
[2]));
309 __asm__
volatile (".chip 68k/68881\n\t"
310 "fmovemx %0,%%fp0-%%fp1\n\t"
311 "fmoveml %1,%%fpcr/%%fpsr/%%fpiar\n\t"
314 : "m" (*sc
->sc_fpregs
),
315 "m" (*sc
->sc_fpcntl
));
319 if (CPU_IS_COLDFIRE
) {
320 __asm__
volatile ("frestore %0" : : "m" (*sc
->sc_fpstate
));
322 __asm__
volatile (".chip 68k/68881\n\t"
325 : : "m" (*sc
->sc_fpstate
));
333 static inline int rt_restore_fpu_state(struct ucontext __user
*uc
)
335 unsigned char fpstate
[FPCONTEXT_SIZE
];
336 int context_size
= CPU_IS_060
? 8 : (CPU_IS_COLDFIRE
? 12 : 0);
341 /* restore fpu control register */
342 if (__copy_from_user(current
->thread
.fpcntl
,
343 uc
->uc_mcontext
.fpregs
.f_fpcntl
, 12))
345 /* restore all other fpu register */
346 if (__copy_from_user(current
->thread
.fp
,
347 uc
->uc_mcontext
.fpregs
.f_fpregs
, 96))
352 if (__get_user(*(long *)fpstate
, (long __user
*)&uc
->uc_fpstate
))
354 if (CPU_IS_060
? fpstate
[2] : fpstate
[0]) {
355 if (!(CPU_IS_060
|| CPU_IS_COLDFIRE
))
356 context_size
= fpstate
[1];
357 /* Verify the frame format. */
358 if (!(CPU_IS_060
|| CPU_IS_COLDFIRE
) &&
359 (fpstate
[0] != fpu_version
))
361 if (CPU_IS_020_OR_030
) {
362 if (m68k_fputype
& FPU_68881
&&
363 !(context_size
== 0x18 || context_size
== 0xb4))
365 if (m68k_fputype
& FPU_68882
&&
366 !(context_size
== 0x38 || context_size
== 0xd4))
368 } else if (CPU_IS_040
) {
369 if (!(context_size
== 0x00 ||
370 context_size
== 0x28 ||
371 context_size
== 0x60))
373 } else if (CPU_IS_060
) {
374 if (!(fpstate
[3] == 0x00 ||
375 fpstate
[3] == 0x60 ||
378 } else if (CPU_IS_COLDFIRE
) {
379 if (!(fpstate
[3] == 0x00 ||
380 fpstate
[3] == 0x05 ||
385 if (__copy_from_user(&fpregs
, &uc
->uc_mcontext
.fpregs
,
389 if (CPU_IS_COLDFIRE
) {
390 __asm__
volatile ("fmovemd %0,%%fp0-%%fp7\n\t"
391 "fmovel %1,%%fpcr\n\t"
392 "fmovel %2,%%fpsr\n\t"
395 : "m" (fpregs
.f_fpregs
[0]),
396 "m" (fpregs
.f_fpcntl
[0]),
397 "m" (fpregs
.f_fpcntl
[1]),
398 "m" (fpregs
.f_fpcntl
[2]));
400 __asm__
volatile (".chip 68k/68881\n\t"
401 "fmovemx %0,%%fp0-%%fp7\n\t"
402 "fmoveml %1,%%fpcr/%%fpsr/%%fpiar\n\t"
405 : "m" (*fpregs
.f_fpregs
),
406 "m" (*fpregs
.f_fpcntl
));
410 __copy_from_user(fpstate
+ 4, (long __user
*)&uc
->uc_fpstate
+ 1,
414 if (CPU_IS_COLDFIRE
) {
415 __asm__
volatile ("frestore %0" : : "m" (*fpstate
));
417 __asm__
volatile (".chip 68k/68881\n\t"
429 * Set up a signal frame.
431 static inline void save_fpu_state(struct sigcontext
*sc
, struct pt_regs
*regs
)
435 memcpy(sc
->sc_fpcntl
, current
->thread
.fpcntl
, 12);
436 memcpy(sc
->sc_fpregs
, current
->thread
.fp
, 24);
440 if (CPU_IS_COLDFIRE
) {
441 __asm__
volatile ("fsave %0"
442 : : "m" (*sc
->sc_fpstate
) : "memory");
444 __asm__
volatile (".chip 68k/68881\n\t"
447 : : "m" (*sc
->sc_fpstate
) : "memory");
450 if (CPU_IS_060
? sc
->sc_fpstate
[2] : sc
->sc_fpstate
[0]) {
451 fpu_version
= sc
->sc_fpstate
[0];
452 if (CPU_IS_020_OR_030
&& !regs
->stkadj
&&
453 regs
->vector
>= (VEC_FPBRUC
* 4) &&
454 regs
->vector
<= (VEC_FPNAN
* 4)) {
455 /* Clear pending exception in 68882 idle frame */
456 if (*(unsigned short *) sc
->sc_fpstate
== 0x1f38)
457 sc
->sc_fpstate
[0x38] |= 1 << 3;
460 if (CPU_IS_COLDFIRE
) {
461 __asm__
volatile ("fmovemd %%fp0-%%fp1,%0\n\t"
462 "fmovel %%fpcr,%1\n\t"
463 "fmovel %%fpsr,%2\n\t"
465 : "=m" (sc
->sc_fpregs
[0]),
466 "=m" (sc
->sc_fpcntl
[0]),
467 "=m" (sc
->sc_fpcntl
[1]),
468 "=m" (sc
->sc_fpcntl
[2])
472 __asm__
volatile (".chip 68k/68881\n\t"
473 "fmovemx %%fp0-%%fp1,%0\n\t"
474 "fmoveml %%fpcr/%%fpsr/%%fpiar,%1\n\t"
476 : "=m" (*sc
->sc_fpregs
),
477 "=m" (*sc
->sc_fpcntl
)
484 static inline int rt_save_fpu_state(struct ucontext __user
*uc
, struct pt_regs
*regs
)
486 unsigned char fpstate
[FPCONTEXT_SIZE
];
487 int context_size
= CPU_IS_060
? 8 : (CPU_IS_COLDFIRE
? 12 : 0);
491 /* save fpu control register */
492 err
|= copy_to_user(uc
->uc_mcontext
.fpregs
.f_fpcntl
,
493 current
->thread
.fpcntl
, 12);
494 /* save all other fpu register */
495 err
|= copy_to_user(uc
->uc_mcontext
.fpregs
.f_fpregs
,
496 current
->thread
.fp
, 96);
500 if (CPU_IS_COLDFIRE
) {
501 __asm__
volatile ("fsave %0" : : "m" (*fpstate
) : "memory");
503 __asm__
volatile (".chip 68k/68881\n\t"
506 : : "m" (*fpstate
) : "memory");
509 err
|= __put_user(*(long *)fpstate
, (long __user
*)&uc
->uc_fpstate
);
510 if (CPU_IS_060
? fpstate
[2] : fpstate
[0]) {
512 if (!(CPU_IS_060
|| CPU_IS_COLDFIRE
))
513 context_size
= fpstate
[1];
514 fpu_version
= fpstate
[0];
515 if (CPU_IS_020_OR_030
&& !regs
->stkadj
&&
516 regs
->vector
>= (VEC_FPBRUC
* 4) &&
517 regs
->vector
<= (VEC_FPNAN
* 4)) {
518 /* Clear pending exception in 68882 idle frame */
519 if (*(unsigned short *) fpstate
== 0x1f38)
520 fpstate
[0x38] |= 1 << 3;
522 if (CPU_IS_COLDFIRE
) {
523 __asm__
volatile ("fmovemd %%fp0-%%fp7,%0\n\t"
524 "fmovel %%fpcr,%1\n\t"
525 "fmovel %%fpsr,%2\n\t"
527 : "=m" (fpregs
.f_fpregs
[0]),
528 "=m" (fpregs
.f_fpcntl
[0]),
529 "=m" (fpregs
.f_fpcntl
[1]),
530 "=m" (fpregs
.f_fpcntl
[2])
534 __asm__
volatile (".chip 68k/68881\n\t"
535 "fmovemx %%fp0-%%fp7,%0\n\t"
536 "fmoveml %%fpcr/%%fpsr/%%fpiar,%1\n\t"
538 : "=m" (*fpregs
.f_fpregs
),
539 "=m" (*fpregs
.f_fpcntl
)
543 err
|= copy_to_user(&uc
->uc_mcontext
.fpregs
, &fpregs
,
547 err
|= copy_to_user((long __user
*)&uc
->uc_fpstate
+ 1, fpstate
+ 4,
552 #else /* CONFIG_FPU */
555 * For the case with no FPU configured these all do nothing.
557 static inline int restore_fpu_state(struct sigcontext
*sc
)
562 static inline int rt_restore_fpu_state(struct ucontext __user
*uc
)
567 static inline void save_fpu_state(struct sigcontext
*sc
, struct pt_regs
*regs
)
571 static inline int rt_save_fpu_state(struct ucontext __user
*uc
, struct pt_regs
*regs
)
576 #endif /* CONFIG_FPU */
578 static inline void siginfo_build_tests(void)
581 * This needs to be tested on m68k as it has a lesser
582 * alignment requirement than x86 and that can cause surprises.
585 /* This is part of the ABI and can never change in size: */
586 BUILD_BUG_ON(sizeof(siginfo_t
) != 128);
588 /* Ensure the known fields never change in location */
589 BUILD_BUG_ON(offsetof(siginfo_t
, si_signo
) != 0);
590 BUILD_BUG_ON(offsetof(siginfo_t
, si_errno
) != 4);
591 BUILD_BUG_ON(offsetof(siginfo_t
, si_code
) != 8);
594 BUILD_BUG_ON(offsetof(siginfo_t
, si_pid
) != 0x0c);
595 BUILD_BUG_ON(offsetof(siginfo_t
, si_uid
) != 0x10);
598 BUILD_BUG_ON(offsetof(siginfo_t
, si_tid
) != 0x0c);
599 BUILD_BUG_ON(offsetof(siginfo_t
, si_overrun
) != 0x10);
600 BUILD_BUG_ON(offsetof(siginfo_t
, si_value
) != 0x14);
603 BUILD_BUG_ON(offsetof(siginfo_t
, si_pid
) != 0x0c);
604 BUILD_BUG_ON(offsetof(siginfo_t
, si_uid
) != 0x10);
605 BUILD_BUG_ON(offsetof(siginfo_t
, si_value
) != 0x14);
608 BUILD_BUG_ON(offsetof(siginfo_t
, si_pid
) != 0x0c);
609 BUILD_BUG_ON(offsetof(siginfo_t
, si_uid
) != 0x10);
610 BUILD_BUG_ON(offsetof(siginfo_t
, si_status
) != 0x14);
611 BUILD_BUG_ON(offsetof(siginfo_t
, si_utime
) != 0x18);
612 BUILD_BUG_ON(offsetof(siginfo_t
, si_stime
) != 0x1c);
615 BUILD_BUG_ON(offsetof(siginfo_t
, si_addr
) != 0x0c);
617 /* _sigfault._mcerr */
618 BUILD_BUG_ON(offsetof(siginfo_t
, si_addr_lsb
) != 0x10);
620 /* _sigfault._addr_bnd */
621 BUILD_BUG_ON(offsetof(siginfo_t
, si_lower
) != 0x12);
622 BUILD_BUG_ON(offsetof(siginfo_t
, si_upper
) != 0x16);
624 /* _sigfault._addr_pkey */
625 BUILD_BUG_ON(offsetof(siginfo_t
, si_pkey
) != 0x12);
627 /* _sigfault._perf */
628 BUILD_BUG_ON(offsetof(siginfo_t
, si_perf_data
) != 0x10);
629 BUILD_BUG_ON(offsetof(siginfo_t
, si_perf_type
) != 0x14);
630 BUILD_BUG_ON(offsetof(siginfo_t
, si_perf_flags
) != 0x18);
633 BUILD_BUG_ON(offsetof(siginfo_t
, si_band
) != 0x0c);
634 BUILD_BUG_ON(offsetof(siginfo_t
, si_fd
) != 0x10);
637 BUILD_BUG_ON(offsetof(siginfo_t
, si_call_addr
) != 0x0c);
638 BUILD_BUG_ON(offsetof(siginfo_t
, si_syscall
) != 0x10);
639 BUILD_BUG_ON(offsetof(siginfo_t
, si_arch
) != 0x14);
641 /* any new si_fields should be added here */
644 static int mangle_kernel_stack(struct pt_regs
*regs
, int formatvec
,
647 int extra
= frame_extra_sizes(formatvec
>> 12);
648 char buf
[sizeof_field(struct frame
, un
)];
652 * user process trying to return with weird frame format
654 pr_debug("user process returning with weird frame format\n");
657 if (extra
&& copy_from_user(buf
, fp
, extra
))
659 regs
->format
= formatvec
>> 12;
660 regs
->vector
= formatvec
& 0xfff;
662 void *p
= (struct switch_stack
*)regs
- 1;
663 struct frame
*new = (void *)regs
- extra
;
664 int size
= sizeof(struct pt_regs
)+sizeof(struct switch_stack
);
666 memmove(p
- extra
, p
, size
);
667 memcpy(p
- extra
+ size
, buf
, extra
);
668 current
->thread
.esp0
= (unsigned long)&new->ptregs
;
670 /* on 68040 complete pending writebacks if any */
671 if (new->ptregs
.format
== 7) // bus error frame
672 berr_040cleanup(new);
679 restore_sigcontext(struct pt_regs
*regs
, struct sigcontext __user
*usc
, void __user
*fp
)
682 struct sigcontext context
;
684 siginfo_build_tests();
686 /* Always make any pending restarted system calls return -EINTR */
687 current
->restart_block
.fn
= do_no_restart_syscall
;
689 /* get previous context */
690 if (copy_from_user(&context
, usc
, sizeof(context
)))
693 /* restore passed registers */
694 regs
->d0
= context
.sc_d0
;
695 regs
->d1
= context
.sc_d1
;
696 regs
->a0
= context
.sc_a0
;
697 regs
->a1
= context
.sc_a1
;
698 regs
->sr
= (regs
->sr
& 0xff00) | (context
.sc_sr
& 0xff);
699 regs
->pc
= context
.sc_pc
;
700 regs
->orig_d0
= -1; /* disable syscall checks */
701 wrusp(context
.sc_usp
);
702 formatvec
= context
.sc_formatvec
;
704 if (restore_fpu_state(&context
))
707 return mangle_kernel_stack(regs
, formatvec
, fp
);
711 rt_restore_ucontext(struct pt_regs
*regs
, struct switch_stack
*sw
,
712 struct ucontext __user
*uc
)
715 greg_t __user
*gregs
= uc
->uc_mcontext
.gregs
;
719 /* Always make any pending restarted system calls return -EINTR */
720 current
->restart_block
.fn
= do_no_restart_syscall
;
722 err
= __get_user(temp
, &uc
->uc_mcontext
.version
);
723 if (temp
!= MCONTEXT_VERSION
)
725 /* restore passed registers */
726 err
|= __get_user(regs
->d0
, &gregs
[0]);
727 err
|= __get_user(regs
->d1
, &gregs
[1]);
728 err
|= __get_user(regs
->d2
, &gregs
[2]);
729 err
|= __get_user(regs
->d3
, &gregs
[3]);
730 err
|= __get_user(regs
->d4
, &gregs
[4]);
731 err
|= __get_user(regs
->d5
, &gregs
[5]);
732 err
|= __get_user(sw
->d6
, &gregs
[6]);
733 err
|= __get_user(sw
->d7
, &gregs
[7]);
734 err
|= __get_user(regs
->a0
, &gregs
[8]);
735 err
|= __get_user(regs
->a1
, &gregs
[9]);
736 err
|= __get_user(regs
->a2
, &gregs
[10]);
737 err
|= __get_user(sw
->a3
, &gregs
[11]);
738 err
|= __get_user(sw
->a4
, &gregs
[12]);
739 err
|= __get_user(sw
->a5
, &gregs
[13]);
740 err
|= __get_user(sw
->a6
, &gregs
[14]);
741 err
|= __get_user(usp
, &gregs
[15]);
743 err
|= __get_user(regs
->pc
, &gregs
[16]);
744 err
|= __get_user(temp
, &gregs
[17]);
745 regs
->sr
= (regs
->sr
& 0xff00) | (temp
& 0xff);
746 regs
->orig_d0
= -1; /* disable syscall checks */
747 err
|= __get_user(temp
, &uc
->uc_formatvec
);
749 err
|= rt_restore_fpu_state(uc
);
750 err
|= restore_altstack(&uc
->uc_stack
);
755 return mangle_kernel_stack(regs
, temp
, &uc
->uc_extra
);
758 asmlinkage
void *do_sigreturn(struct pt_regs
*regs
, struct switch_stack
*sw
)
760 unsigned long usp
= rdusp();
761 struct sigframe __user
*frame
= (struct sigframe __user
*)(usp
- 4);
765 if (!access_ok(frame
, sizeof(*frame
)))
767 if (__get_user(set
.sig
[0], &frame
->sc
.sc_mask
) ||
769 __copy_from_user(&set
.sig
[1], &frame
->extramask
,
770 sizeof(frame
->extramask
))))
773 set_current_blocked(&set
);
775 size
= restore_sigcontext(regs
, &frame
->sc
, frame
+ 1);
778 return (void *)sw
- size
;
785 asmlinkage
void *do_rt_sigreturn(struct pt_regs
*regs
, struct switch_stack
*sw
)
787 unsigned long usp
= rdusp();
788 struct rt_sigframe __user
*frame
= (struct rt_sigframe __user
*)(usp
- 4);
792 if (!access_ok(frame
, sizeof(*frame
)))
794 if (__copy_from_user(&set
, &frame
->uc
.uc_sigmask
, sizeof(set
)))
797 set_current_blocked(&set
);
799 size
= rt_restore_ucontext(regs
, sw
, &frame
->uc
);
802 return (void *)sw
- size
;
809 static inline struct pt_regs
*rte_regs(struct pt_regs
*regs
)
811 return (void *)regs
+ regs
->stkadj
;
814 static void setup_sigcontext(struct sigcontext
*sc
, struct pt_regs
*regs
,
817 struct pt_regs
*tregs
= rte_regs(regs
);
819 sc
->sc_usp
= rdusp();
820 sc
->sc_d0
= regs
->d0
;
821 sc
->sc_d1
= regs
->d1
;
822 sc
->sc_a0
= regs
->a0
;
823 sc
->sc_a1
= regs
->a1
;
824 sc
->sc_sr
= tregs
->sr
;
825 sc
->sc_pc
= tregs
->pc
;
826 sc
->sc_formatvec
= tregs
->format
<< 12 | tregs
->vector
;
827 save_a5_state(sc
, regs
);
828 save_fpu_state(sc
, regs
);
831 static inline int rt_setup_ucontext(struct ucontext __user
*uc
, struct pt_regs
*regs
)
833 struct switch_stack
*sw
= (struct switch_stack
*)regs
- 1;
834 struct pt_regs
*tregs
= rte_regs(regs
);
835 greg_t __user
*gregs
= uc
->uc_mcontext
.gregs
;
838 err
|= __put_user(MCONTEXT_VERSION
, &uc
->uc_mcontext
.version
);
839 err
|= __put_user(regs
->d0
, &gregs
[0]);
840 err
|= __put_user(regs
->d1
, &gregs
[1]);
841 err
|= __put_user(regs
->d2
, &gregs
[2]);
842 err
|= __put_user(regs
->d3
, &gregs
[3]);
843 err
|= __put_user(regs
->d4
, &gregs
[4]);
844 err
|= __put_user(regs
->d5
, &gregs
[5]);
845 err
|= __put_user(sw
->d6
, &gregs
[6]);
846 err
|= __put_user(sw
->d7
, &gregs
[7]);
847 err
|= __put_user(regs
->a0
, &gregs
[8]);
848 err
|= __put_user(regs
->a1
, &gregs
[9]);
849 err
|= __put_user(regs
->a2
, &gregs
[10]);
850 err
|= __put_user(sw
->a3
, &gregs
[11]);
851 err
|= __put_user(sw
->a4
, &gregs
[12]);
852 err
|= __put_user(sw
->a5
, &gregs
[13]);
853 err
|= __put_user(sw
->a6
, &gregs
[14]);
854 err
|= __put_user(rdusp(), &gregs
[15]);
855 err
|= __put_user(tregs
->pc
, &gregs
[16]);
856 err
|= __put_user(tregs
->sr
, &gregs
[17]);
857 err
|= __put_user((tregs
->format
<< 12) | tregs
->vector
, &uc
->uc_formatvec
);
858 err
|= rt_save_fpu_state(uc
, regs
);
862 static inline void __user
*
863 get_sigframe(struct ksignal
*ksig
, struct pt_regs
*tregs
, size_t frame_size
)
865 unsigned long usp
= sigsp(rdusp(), ksig
);
866 unsigned long gap
= 0;
868 if (CPU_IS_020_OR_030
&& tregs
->format
== 0xb) {
869 /* USP is unreliable so use worst-case value */
873 return (void __user
*)((usp
- gap
- frame_size
) & -8UL);
876 static int setup_frame(struct ksignal
*ksig
, sigset_t
*set
,
877 struct pt_regs
*regs
)
879 struct sigframe __user
*frame
;
880 struct pt_regs
*tregs
= rte_regs(regs
);
881 int fsize
= frame_extra_sizes(tregs
->format
);
882 struct sigcontext context
;
883 int err
= 0, sig
= ksig
->sig
;
886 pr_debug("setup_frame: Unknown frame format %#x\n",
891 frame
= get_sigframe(ksig
, tregs
, sizeof(*frame
) + fsize
);
894 err
|= copy_to_user (frame
+ 1, regs
+ 1, fsize
);
896 err
|= __put_user(sig
, &frame
->sig
);
898 err
|= __put_user(tregs
->vector
, &frame
->code
);
899 err
|= __put_user(&frame
->sc
, &frame
->psc
);
902 err
|= copy_to_user(frame
->extramask
, &set
->sig
[1],
903 sizeof(frame
->extramask
));
905 setup_sigcontext(&context
, regs
, set
->sig
[0]);
906 err
|= copy_to_user (&frame
->sc
, &context
, sizeof(context
));
908 /* Set up to return from userspace. */
910 err
|= __put_user(frame
->retcode
, &frame
->pretcode
);
911 /* moveq #,d0; trap #0 */
912 err
|= __put_user(0x70004e40 + (__NR_sigreturn
<< 16),
913 (long __user
*)(frame
->retcode
));
915 err
|= __put_user((long) ret_from_user_signal
,
916 (long __user
*) &frame
->pretcode
);
922 push_cache ((unsigned long) &frame
->retcode
);
925 * This is subtle; if we build more than one sigframe, all but the
926 * first one will see frame format 0 and have fsize == 0, so we won't
930 regs
->stkadj
= fsize
;
931 tregs
= rte_regs(regs
);
932 pr_debug("Performing stackadjust=%04lx\n", regs
->stkadj
);
935 tregs
->sr
= regs
->sr
;
939 * Set up registers for signal handler. All the state we are about
940 * to destroy is successfully copied to sigframe.
942 wrusp ((unsigned long) frame
);
943 tregs
->pc
= (unsigned long) ksig
->ka
.sa
.sa_handler
;
949 static int setup_rt_frame(struct ksignal
*ksig
, sigset_t
*set
,
950 struct pt_regs
*regs
)
952 struct rt_sigframe __user
*frame
;
953 struct pt_regs
*tregs
= rte_regs(regs
);
954 int fsize
= frame_extra_sizes(tregs
->format
);
955 int err
= 0, sig
= ksig
->sig
;
958 pr_debug("setup_frame: Unknown frame format %#x\n",
963 frame
= get_sigframe(ksig
, tregs
, sizeof(*frame
));
966 err
|= copy_to_user (&frame
->uc
.uc_extra
, regs
+ 1, fsize
);
968 err
|= __put_user(sig
, &frame
->sig
);
969 err
|= __put_user(&frame
->info
, &frame
->pinfo
);
970 err
|= __put_user(&frame
->uc
, &frame
->puc
);
971 err
|= copy_siginfo_to_user(&frame
->info
, &ksig
->info
);
973 /* Create the ucontext. */
974 err
|= __put_user(0, &frame
->uc
.uc_flags
);
975 err
|= __put_user(NULL
, &frame
->uc
.uc_link
);
976 err
|= __save_altstack(&frame
->uc
.uc_stack
, rdusp());
977 err
|= rt_setup_ucontext(&frame
->uc
, regs
);
978 err
|= copy_to_user (&frame
->uc
.uc_sigmask
, set
, sizeof(*set
));
980 /* Set up to return from userspace. */
982 err
|= __put_user(frame
->retcode
, &frame
->pretcode
);
984 /* movel #__NR_rt_sigreturn,d0; trap #0 */
985 err
|= __put_user(0x203c0000, (long __user
*)(frame
->retcode
+ 0));
986 err
|= __put_user(0x00004e40 + (__NR_rt_sigreturn
<< 16),
987 (long __user
*)(frame
->retcode
+ 4));
989 /* moveq #,d0; notb d0; trap #0 */
990 err
|= __put_user(0x70004600 + ((__NR_rt_sigreturn
^ 0xff) << 16),
991 (long __user
*)(frame
->retcode
+ 0));
992 err
|= __put_user(0x4e40, (short __user
*)(frame
->retcode
+ 4));
995 err
|= __put_user((long) ret_from_user_rt_signal
,
996 (long __user
*) &frame
->pretcode
);
997 #endif /* CONFIG_MMU */
1002 push_cache ((unsigned long) &frame
->retcode
);
1005 * This is subtle; if we build more than one sigframe, all but the
1006 * first one will see frame format 0 and have fsize == 0, so we won't
1010 regs
->stkadj
= fsize
;
1011 tregs
= rte_regs(regs
);
1012 pr_debug("Performing stackadjust=%04lx\n", regs
->stkadj
);
1015 tregs
->sr
= regs
->sr
;
1019 * Set up registers for signal handler. All the state we are about
1020 * to destroy is successfully copied to sigframe.
1022 wrusp ((unsigned long) frame
);
1023 tregs
->pc
= (unsigned long) ksig
->ka
.sa
.sa_handler
;
1029 handle_restart(struct pt_regs
*regs
, struct k_sigaction
*ka
, int has_handler
)
1032 case -ERESTARTNOHAND
:
1038 case -ERESTART_RESTARTBLOCK
:
1040 regs
->d0
= __NR_restart_syscall
;
1048 if (has_handler
&& !(ka
->sa
.sa_flags
& SA_RESTART
)) {
1053 case -ERESTARTNOINTR
:
1055 regs
->d0
= regs
->orig_d0
;
1062 * OK, we're invoking a handler
1065 handle_signal(struct ksignal
*ksig
, struct pt_regs
*regs
)
1067 sigset_t
*oldset
= sigmask_to_save();
1069 /* are we from a system call? */
1070 if (regs
->orig_d0
>= 0)
1071 /* If so, check system call restarting.. */
1072 handle_restart(regs
, &ksig
->ka
, 1);
1074 /* set up the stack frame */
1075 if (ksig
->ka
.sa
.sa_flags
& SA_SIGINFO
)
1076 err
= setup_rt_frame(ksig
, oldset
, regs
);
1078 err
= setup_frame(ksig
, oldset
, regs
);
1080 signal_setup_done(err
, ksig
, 0);
1082 if (test_thread_flag(TIF_DELAYED_TRACE
)) {
1083 regs
->sr
&= ~0x8000;
1084 send_sig(SIGTRAP
, current
, 1);
1089 * Note that 'init' is a special process: it doesn't get signals it doesn't
1090 * want to handle. Thus you cannot kill init even with a SIGKILL even by
1093 static void do_signal(struct pt_regs
*regs
)
1095 struct ksignal ksig
;
1097 current
->thread
.esp0
= (unsigned long) regs
;
1099 if (get_signal(&ksig
)) {
1100 /* Whee! Actually deliver the signal. */
1101 handle_signal(&ksig
, regs
);
1105 /* Did we come from a system call? */
1106 if (regs
->orig_d0
>= 0)
1107 /* Restart the system call - no handlers present */
1108 handle_restart(regs
, NULL
, 0);
1110 /* If there's no signal to deliver, we just restore the saved mask. */
1111 restore_saved_sigmask();
1114 asmlinkage
void do_notify_resume(struct pt_regs
*regs
)
1116 if (test_thread_flag(TIF_NOTIFY_SIGNAL
) ||
1117 test_thread_flag(TIF_SIGPENDING
))
1120 if (test_thread_flag(TIF_NOTIFY_RESUME
))
1121 resume_user_mode_work(regs
);