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.
12 setup_sigcontext(struct pt_regs
*regs
, struct sigcontext
*sc
)
16 err
|= __put_user(regs
->cp0_epc
, &sc
->sc_pc
);
17 err
|= __put_user(regs
->cp0_status
, &sc
->sc_status
);
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
);
35 err
|= __put_user(regs
->cp0_cause
, &sc
->sc_cause
);
36 err
|= __put_user(regs
->cp0_badvaddr
, &sc
->sc_badvaddr
);
38 err
|= __put_user(!!used_math(), &sc
->sc_used_math
);
44 * Save FPU state to signal context. Signal handler will "inherit"
49 if (!is_fpu_owner()) {
53 err
|= save_fp_context(sc
);
62 restore_sigcontext(struct pt_regs
*regs
, struct sigcontext
*sc
)
65 unsigned int used_math
;
67 /* Always make any pending restarted system calls return -EINTR */
68 current_thread_info()->restart_block
.fn
= do_no_restart_syscall
;
70 err
|= __get_user(regs
->cp0_epc
, &sc
->sc_pc
);
71 err
|= __get_user(regs
->hi
, &sc
->sc_mdhi
);
72 err
|= __get_user(regs
->lo
, &sc
->sc_mdlo
);
74 #define restore_gp_reg(i) do { \
75 err |= __get_user(regs->regs[i], &sc->sc_regs[i]); \
77 restore_gp_reg( 1); restore_gp_reg( 2); restore_gp_reg( 3);
78 restore_gp_reg( 4); restore_gp_reg( 5); restore_gp_reg( 6);
79 restore_gp_reg( 7); restore_gp_reg( 8); restore_gp_reg( 9);
80 restore_gp_reg(10); restore_gp_reg(11); restore_gp_reg(12);
81 restore_gp_reg(13); restore_gp_reg(14); restore_gp_reg(15);
82 restore_gp_reg(16); restore_gp_reg(17); restore_gp_reg(18);
83 restore_gp_reg(19); restore_gp_reg(20); restore_gp_reg(21);
84 restore_gp_reg(22); restore_gp_reg(23); restore_gp_reg(24);
85 restore_gp_reg(25); restore_gp_reg(26); restore_gp_reg(27);
86 restore_gp_reg(28); restore_gp_reg(29); restore_gp_reg(30);
90 err
|= __get_user(used_math
, &sc
->sc_used_math
);
91 conditional_used_math(used_math
);
96 /* restore fpu context if we have used it before */
98 err
|= restore_fp_context(sc
);
100 /* signal handler may have used FPU. Give it up. */
110 * Determine which stack to use..
113 get_sigframe(struct k_sigaction
*ka
, struct pt_regs
*regs
, size_t frame_size
)
115 unsigned long sp
, almask
;
117 /* Default to using normal stack */
121 * FPU emulator may have it's own trampoline active just
122 * above the user stack, 16-bytes before the next lowest
123 * 16 byte boundary. Try to avoid trashing it.
127 /* This is the X/Open sanctioned signal stack switching. */
128 if ((ka
->sa
.sa_flags
& SA_ONSTACK
) && (sas_ss_flags (sp
) == 0))
129 sp
= current
->sas_ss_sp
+ current
->sas_ss_size
;
131 if (PLAT_TRAMPOLINE_STUFF_LINE
)
132 almask
= ~(PLAT_TRAMPOLINE_STUFF_LINE
- 1);
136 return (void *)((sp
- frame_size
) & almask
);