diff options
Diffstat (limited to 'arch/mips/kernel/signal-common.h')
-rw-r--r-- | arch/mips/kernel/signal-common.h | 194 |
1 files changed, 41 insertions, 153 deletions
diff --git a/arch/mips/kernel/signal-common.h b/arch/mips/kernel/signal-common.h index b1f09d54ebe6..9a8abd67ec5c 100644 --- a/arch/mips/kernel/signal-common.h +++ b/arch/mips/kernel/signal-common.h | |||
@@ -8,169 +8,57 @@ | |||
8 | * Copyright (C) 1999, 2000 Silicon Graphics, Inc. | 8 | * Copyright (C) 1999, 2000 Silicon Graphics, Inc. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #ifndef __SIGNAL_COMMON_H | ||
12 | #define __SIGNAL_COMMON_H | ||
11 | 13 | ||
12 | static inline int | 14 | /* #define DEBUG_SIG */ |
13 | setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc) | ||
14 | { | ||
15 | int err = 0; | ||
16 | 15 | ||
17 | err |= __put_user(regs->cp0_epc, &sc->sc_pc); | 16 | #ifdef DEBUG_SIG |
17 | # define DEBUGP(fmt, args...) printk("%s: " fmt, __FUNCTION__ , ##args) | ||
18 | #else | ||
19 | # define DEBUGP(fmt, args...) | ||
20 | #endif | ||
18 | 21 | ||
19 | #define save_gp_reg(i) do { \ | 22 | /* |
20 | err |= __put_user(regs->regs[i], &sc->sc_regs[i]); \ | 23 | * Horribly complicated - with the bloody RM9000 workarounds enabled |
21 | } while(0) | 24 | * the signal trampolines is moving to the end of the structure so we can |
22 | __put_user(0, &sc->sc_regs[0]); save_gp_reg(1); save_gp_reg(2); | 25 | * increase the alignment without breaking software compatibility. |
23 | save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6); | 26 | */ |
24 | save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10); | 27 | #if ICACHE_REFILLS_WORKAROUND_WAR == 0 |
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); | ||
30 | save_gp_reg(31); | ||
31 | #undef save_gp_reg | ||
32 | |||
33 | err |= __put_user(regs->hi, &sc->sc_mdhi); | ||
34 | err |= __put_user(regs->lo, &sc->sc_mdlo); | ||
35 | if (cpu_has_dsp) { | ||
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); | ||
43 | } | ||
44 | |||
45 | err |= __put_user(!!used_math(), &sc->sc_used_math); | ||
46 | |||
47 | if (!used_math()) | ||
48 | goto out; | ||
49 | |||
50 | /* | ||
51 | * Save FPU state to signal context. Signal handler will "inherit" | ||
52 | * current FPU state. | ||
53 | */ | ||
54 | preempt_disable(); | ||
55 | |||
56 | if (!is_fpu_owner()) { | ||
57 | own_fpu(); | ||
58 | restore_fp(current); | ||
59 | } | ||
60 | err |= save_fp_context(sc); | ||
61 | |||
62 | preempt_enable(); | ||
63 | |||
64 | out: | ||
65 | return err; | ||
66 | } | ||
67 | |||
68 | static inline int | ||
69 | restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc) | ||
70 | { | ||
71 | unsigned int used_math; | ||
72 | unsigned long treg; | ||
73 | int err = 0; | ||
74 | |||
75 | /* Always make any pending restarted system calls return -EINTR */ | ||
76 | current_thread_info()->restart_block.fn = do_no_restart_syscall; | ||
77 | |||
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); | ||
81 | if (cpu_has_dsp) { | ||
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); | ||
89 | } | ||
90 | |||
91 | #define restore_gp_reg(i) do { \ | ||
92 | err |= __get_user(regs->regs[i], &sc->sc_regs[i]); \ | ||
93 | } while(0) | ||
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); | ||
104 | restore_gp_reg(31); | ||
105 | #undef restore_gp_reg | ||
106 | 28 | ||
107 | err |= __get_user(used_math, &sc->sc_used_math); | 29 | struct sigframe { |
108 | conditional_used_math(used_math); | 30 | u32 sf_ass[4]; /* argument save space for o32 */ |
31 | u32 sf_code[2]; /* signal trampoline */ | ||
32 | struct sigcontext sf_sc; | ||
33 | sigset_t sf_mask; | ||
34 | }; | ||
109 | 35 | ||
110 | preempt_disable(); | 36 | #else /* ICACHE_REFILLS_WORKAROUND_WAR */ |
111 | 37 | ||
112 | if (used_math()) { | 38 | struct sigframe { |
113 | /* restore fpu context if we have used it before */ | 39 | u32 sf_ass[4]; /* argument save space for o32 */ |
114 | own_fpu(); | 40 | u32 sf_pad[2]; |
115 | err |= restore_fp_context(sc); | 41 | struct sigcontext sf_sc; /* hw context */ |
116 | } else { | 42 | sigset_t sf_mask; |
117 | /* signal handler may have used FPU. Give it up. */ | 43 | u32 sf_code[8] ____cacheline_aligned; /* signal trampoline */ |
118 | lose_fpu(); | 44 | }; |
119 | } | ||
120 | 45 | ||
121 | preempt_enable(); | 46 | #endif /* !ICACHE_REFILLS_WORKAROUND_WAR */ |
122 | 47 | ||
123 | return err; | 48 | /* |
124 | } | 49 | * handle hardware context |
50 | */ | ||
51 | extern int setup_sigcontext(struct pt_regs *, struct sigcontext __user *); | ||
52 | extern int restore_sigcontext(struct pt_regs *, struct sigcontext __user *); | ||
125 | 53 | ||
126 | /* | 54 | /* |
127 | * Determine which stack to use.. | 55 | * Determine which stack to use.. |
128 | */ | 56 | */ |
129 | static inline void __user * | 57 | extern void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, |
130 | get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size) | 58 | size_t frame_size); |
131 | { | 59 | /* |
132 | unsigned long sp; | 60 | * install trampoline code to get back from the sig handler |
133 | 61 | */ | |
134 | /* Default to using normal stack */ | 62 | extern int install_sigtramp(unsigned int __user *tramp, unsigned int syscall); |
135 | sp = regs->regs[29]; | ||
136 | |||
137 | /* | ||
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. | ||
141 | */ | ||
142 | sp -= 32; | ||
143 | |||
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; | ||
147 | |||
148 | return (void __user *)((sp - frame_size) & (ICACHE_REFILLS_WORKAROUND_WAR ? ~(cpu_icache_line_size()-1) : ALMASK)); | ||
149 | } | ||
150 | |||
151 | static inline int install_sigtramp(unsigned int __user *tramp, | ||
152 | unsigned int syscall) | ||
153 | { | ||
154 | int err; | ||
155 | |||
156 | /* | ||
157 | * Set up the return code ... | ||
158 | * | ||
159 | * li v0, __NR__foo_sigreturn | ||
160 | * syscall | ||
161 | */ | ||
162 | |||
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); | ||
172 | } | ||
173 | flush_cache_sigtramp((unsigned long) tramp); | ||
174 | 63 | ||
175 | return err; | 64 | #endif /* __SIGNAL_COMMON_H */ |
176 | } | ||