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)
18 err |= __put_user(regs->cp0_epc, &sc->sc_pc);
20 err |= __put_user(0, &sc->sc_regs[0]);
21 for (i = 1; i < 32; i++)
22 err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
24 err |= __put_user(regs->hi, &sc->sc_mdhi);
25 err |= __put_user(regs->lo, &sc->sc_mdlo);
27 err |= __put_user(mfhi1(), &sc->sc_hi1);
28 err |= __put_user(mflo1(), &sc->sc_lo1);
29 err |= __put_user(mfhi2(), &sc->sc_hi2);
30 err |= __put_user(mflo2(), &sc->sc_lo2);
31 err |= __put_user(mfhi3(), &sc->sc_hi3);
32 err |= __put_user(mflo3(), &sc->sc_lo3);
33 err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
36 err |= __put_user(!!used_math(), &sc->sc_used_math);
40 * Save FPU state to signal context. Signal handler
41 * will "inherit" current FPU state.
45 if (!is_fpu_owner()) {
49 err |= save_fp_context(sc);
57 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
59 unsigned int used_math;
64 /* Always make any pending restarted system calls return -EINTR */
65 current_thread_info()->restart_block.fn = do_no_restart_syscall;
67 err |= __get_user(regs->cp0_epc, &sc->sc_pc);
68 err |= __get_user(regs->hi, &sc->sc_mdhi);
69 err |= __get_user(regs->lo, &sc->sc_mdlo);
71 err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
72 err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
73 err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
74 err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
75 err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
76 err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
77 err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
80 for (i = 1; i < 32; i++)
81 err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
83 err |= __get_user(used_math, &sc->sc_used_math);
84 conditional_used_math(used_math);
89 /* restore fpu context if we have used it before */
91 err |= restore_fp_context(sc);
93 /* signal handler may have used FPU. Give it up. */
103 * Determine which stack to use..
105 static inline void __user *
106 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
110 /* Default to using normal stack */
114 * FPU emulator may have it's own trampoline active just
115 * above the user stack, 16-bytes before the next lowest
116 * 16 byte boundary. Try to avoid trashing it.
120 /* This is the X/Open sanctioned signal stack switching. */
121 if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
122 sp = current->sas_ss_sp + current->sas_ss_size;
124 return (void __user *)((sp - frame_size) & (ICACHE_REFILLS_WORKAROUND_WAR ? ~(cpu_icache_line_size()-1) : ALMASK));
127 static inline int install_sigtramp(unsigned int __user *tramp,
128 unsigned int syscall)
133 * Set up the return code ...
135 * li v0, __NR__foo_sigreturn
139 err = __put_user(0x24020000 + syscall, tramp + 0);
140 err |= __put_user(0x0000000c , tramp + 1);
141 if (ICACHE_REFILLS_WORKAROUND_WAR) {
142 err |= __put_user(0, tramp + 2);
143 err |= __put_user(0, tramp + 3);
144 err |= __put_user(0, tramp + 4);
145 err |= __put_user(0, tramp + 5);
146 err |= __put_user(0, tramp + 6);
147 err |= __put_user(0, tramp + 7);
149 flush_cache_sigtramp((unsigned long) tramp);