2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1991, 1992 Linus Torvalds
7 * Copyright (C) 1994 - 2000 Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
13 setup_sigcontext(struct pt_regs
*regs
, struct sigcontext __user
*sc
)
17 err
|= __put_user(regs
->cp0_epc
, &sc
->sc_pc
);
19 #define save_gp_reg(i) do { \
20 err |= __put_user(regs->regs[i], &sc->sc_regs[i]); \
22 __put_user(0, &sc
->sc_regs
[0]); save_gp_reg(1); save_gp_reg(2);
23 save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6);
24 save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10);
25 save_gp_reg(11); save_gp_reg(12); save_gp_reg(13); save_gp_reg(14);
26 save_gp_reg(15); save_gp_reg(16); save_gp_reg(17); save_gp_reg(18);
27 save_gp_reg(19); save_gp_reg(20); save_gp_reg(21); save_gp_reg(22);
28 save_gp_reg(23); save_gp_reg(24); save_gp_reg(25); save_gp_reg(26);
29 save_gp_reg(27); save_gp_reg(28); save_gp_reg(29); save_gp_reg(30);
33 err
|= __put_user(regs
->hi
, &sc
->sc_mdhi
);
34 err
|= __put_user(regs
->lo
, &sc
->sc_mdlo
);
36 err
|= __put_user(mfhi1(), &sc
->sc_hi1
);
37 err
|= __put_user(mflo1(), &sc
->sc_lo1
);
38 err
|= __put_user(mfhi2(), &sc
->sc_hi2
);
39 err
|= __put_user(mflo2(), &sc
->sc_lo2
);
40 err
|= __put_user(mfhi3(), &sc
->sc_hi3
);
41 err
|= __put_user(mflo3(), &sc
->sc_lo3
);
42 err
|= __put_user(rddsp(DSP_MASK
), &sc
->sc_dsp
);
45 err
|= __put_user(!!used_math(), &sc
->sc_used_math
);
51 * Save FPU state to signal context. Signal handler will "inherit"
56 if (!is_fpu_owner()) {
60 err
|= save_fp_context(sc
);
69 restore_sigcontext(struct pt_regs
*regs
, struct sigcontext __user
*sc
)
71 unsigned int used_math
;
75 /* Always make any pending restarted system calls return -EINTR */
76 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
78 err
|= __get_user(regs
->cp0_epc
, &sc
->sc_pc
);
79 err
|= __get_user(regs
->hi
, &sc
->sc_mdhi
);
80 err
|= __get_user(regs
->lo
, &sc
->sc_mdlo
);
82 err
|= __get_user(treg
, &sc
->sc_hi1
); mthi1(treg
);
83 err
|= __get_user(treg
, &sc
->sc_lo1
); mtlo1(treg
);
84 err
|= __get_user(treg
, &sc
->sc_hi2
); mthi2(treg
);
85 err
|= __get_user(treg
, &sc
->sc_lo2
); mtlo2(treg
);
86 err
|= __get_user(treg
, &sc
->sc_hi3
); mthi3(treg
);
87 err
|= __get_user(treg
, &sc
->sc_lo3
); mtlo3(treg
);
88 err
|= __get_user(treg
, &sc
->sc_dsp
); wrdsp(treg
, DSP_MASK
);
91 #define restore_gp_reg(i) do { \
92 err |= __get_user(regs->regs[i], &sc->sc_regs[i]); \
94 restore_gp_reg( 1); restore_gp_reg( 2); restore_gp_reg( 3);
95 restore_gp_reg( 4); restore_gp_reg( 5); restore_gp_reg( 6);
96 restore_gp_reg( 7); restore_gp_reg( 8); restore_gp_reg( 9);
97 restore_gp_reg(10); restore_gp_reg(11); restore_gp_reg(12);
98 restore_gp_reg(13); restore_gp_reg(14); restore_gp_reg(15);
99 restore_gp_reg(16); restore_gp_reg(17); restore_gp_reg(18);
100 restore_gp_reg(19); restore_gp_reg(20); restore_gp_reg(21);
101 restore_gp_reg(22); restore_gp_reg(23); restore_gp_reg(24);
102 restore_gp_reg(25); restore_gp_reg(26); restore_gp_reg(27);
103 restore_gp_reg(28); restore_gp_reg(29); restore_gp_reg(30);
105 #undef restore_gp_reg
107 err
|= __get_user(used_math
, &sc
->sc_used_math
);
108 conditional_used_math(used_math
);
113 /* restore fpu context if we have used it before */
115 err
|= restore_fp_context(sc
);
117 /* signal handler may have used FPU. Give it up. */
127 * Determine which stack to use..
129 static inline void __user
*
130 get_sigframe(struct k_sigaction
*ka
, struct pt_regs
*regs
, size_t frame_size
)
134 /* Default to using normal stack */
138 * FPU emulator may have it's own trampoline active just
139 * above the user stack, 16-bytes before the next lowest
140 * 16 byte boundary. Try to avoid trashing it.
144 /* This is the X/Open sanctioned signal stack switching. */
145 if ((ka
->sa
.sa_flags
& SA_ONSTACK
) && (sas_ss_flags (sp
) == 0))
146 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
148 return (void __user
*)((sp
- frame_size
) & (ICACHE_REFILLS_WORKAROUND_WAR
? ~(cpu_icache_line_size()-1) : ALMASK
));
151 static inline int install_sigtramp(unsigned int __user
*tramp
,
152 unsigned int syscall
)
157 * Set up the return code ...
159 * li v0, __NR__foo_sigreturn
163 err
= __put_user(0x24020000 + syscall
, tramp
+ 0);
164 err
|= __put_user(0x0000000c , tramp
+ 1);
165 if (ICACHE_REFILLS_WORKAROUND_WAR
) {
166 err
|= __put_user(0, tramp
+ 2);
167 err
|= __put_user(0, tramp
+ 3);
168 err
|= __put_user(0, tramp
+ 4);
169 err
|= __put_user(0, tramp
+ 5);
170 err
|= __put_user(0, tramp
+ 6);
171 err
|= __put_user(0, tramp
+ 7);
173 flush_cache_sigtramp((unsigned long) tramp
);