2 * Copyright (C) 2003, 2004, 2007 Maciej W. Rozycki
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 #include <linux/context_tracking.h>
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/ptrace.h>
13 #include <linux/stddef.h>
16 #include <asm/compiler.h>
19 #include <asm/mipsregs.h>
20 #include <asm/setup.h>
22 static char bug64hit
[] __initdata
=
23 "reliable operation impossible!\n%s";
24 static char nowar
[] __initdata
=
25 "Please report to <linux-mips@linux-mips.org>.";
26 static char r4kwar
[] __initdata
=
27 "Enable CPU_R4000_WORKAROUNDS to rectify.";
28 static char daddiwar
[] __initdata
=
29 "Enable CPU_DADDI_WORKAROUNDS to rectify.";
31 static inline void align_mod(const int align
, const int mod
)
42 : GCC_IMM_ASM() (align
), GCC_IMM_ASM() (mod
));
45 static inline void mult_sh_align_mod(long *v1
, long *v2
, long *w
,
46 const int align
, const int mod
)
50 long p
, s
, lv1
, lv2
, lw
;
53 * We want the multiply and the shift to be isolated from the
54 * rest of the code to disable gcc optimizations. Hence the
55 * asm statements that execute nothing, but make gcc not know
56 * what the values of m1, m2 and s are and what lv2 and p are
60 local_irq_save(flags
);
62 * The following code leads to a wrong result of the first
63 * dsll32 when executed on R4000 rev. 2.2 or 3.0 (PRId
64 * 00000422 or 00000430, respectively).
66 * See "MIPS R4000PC/SC Errata, Processor Revision 2.2 and
67 * 3.0" by MIPS Technologies, Inc., errata #16 and #28 for
68 * details. I got no permission to duplicate them here,
73 : "=r" (m1
), "=r" (m2
), "=r" (s
)
74 : "0" (5), "1" (8), "2" (5));
75 align_mod(align
, mod
);
77 * The trailing nop is needed to fulfill the two-instruction
78 * requirement between reading hi/lo and staring a mult/div.
79 * Leaving it out may cause gas insert a nop itself breaking
80 * the desired alignment of the next chunk.
88 "dsll32 %0, %4, %5\n\t"
90 "dsll32 %1, %4, %5\n\t"
93 : "=&r" (lv1
), "=r" (lw
)
94 : "r" (m1
), "r" (m2
), "r" (s
), "I" (0)
95 : "hi", "lo", GCC_REG_ACCUM
);
96 /* We have to use single integers for m1 and m2 and a double
97 * one for p to be sure the mulsidi3 gcc's RTL multiplication
98 * instruction has the workaround applied. Older versions of
99 * gcc have correct umulsi3 and mulsi3, but other
100 * multiplication variants lack the workaround.
104 : "=r" (m1
), "=r" (m2
), "=r" (s
)
105 : "0" (m1
), "1" (m2
), "2" (s
));
106 align_mod(align
, mod
);
112 : "0" (lv2
), "r" (p
));
113 local_irq_restore(flags
);
120 static inline void check_mult_sh(void)
122 long v1
[8], v2
[8], w
[8];
125 printk("Checking for the multiply/shift bug... ");
128 * Testing discovered false negatives for certain code offsets
129 * into cache lines. Hence we test all possible offsets for
130 * the worst assumption of an R4000 I-cache line width of 32
133 * We can't use a loop as alignment directives need to be
136 mult_sh_align_mod(&v1
[0], &v2
[0], &w
[0], 32, 0);
137 mult_sh_align_mod(&v1
[1], &v2
[1], &w
[1], 32, 1);
138 mult_sh_align_mod(&v1
[2], &v2
[2], &w
[2], 32, 2);
139 mult_sh_align_mod(&v1
[3], &v2
[3], &w
[3], 32, 3);
140 mult_sh_align_mod(&v1
[4], &v2
[4], &w
[4], 32, 4);
141 mult_sh_align_mod(&v1
[5], &v2
[5], &w
[5], 32, 5);
142 mult_sh_align_mod(&v1
[6], &v2
[6], &w
[6], 32, 6);
143 mult_sh_align_mod(&v1
[7], &v2
[7], &w
[7], 32, 7);
146 for (i
= 0; i
< 8; i
++)
155 printk("yes, workaround... ");
158 for (i
= 0; i
< 8; i
++)
168 panic(bug64hit
, !R4000_WAR
? r4kwar
: nowar
);
171 static volatile int daddi_ov
;
173 asmlinkage
void __init
do_daddi_ov(struct pt_regs
*regs
)
175 enum ctx_state prev_state
;
177 prev_state
= exception_enter();
180 exception_exit(prev_state
);
183 static inline void check_daddi(void)
185 extern asmlinkage
void handle_daddi_ov(void);
190 printk("Checking for the daddi bug... ");
192 local_irq_save(flags
);
193 handler
= set_except_vector(12, handle_daddi_ov
);
195 * The following code fails to trigger an overflow exception
196 * when executed on R4000 rev. 2.2 or 3.0 (PRId 00000422 or
197 * 00000430, respectively).
199 * See "MIPS R4000PC/SC Errata, Processor Revision 2.2 and
200 * 3.0" by MIPS Technologies, Inc., erratum #23 for details.
201 * I got no permission to duplicate it here, sigh... --macro
208 "addiu %1, $0, %2\n\t"
210 #ifdef HAVE_AS_SET_DADDI
213 "daddi %0, %1, %3\n\t"
215 : "=r" (v
), "=&r" (tmp
)
216 : "I" (0xffffffffffffdb9aUL
), "I" (0x1234));
217 set_except_vector(12, handler
);
218 local_irq_restore(flags
);
225 printk("yes, workaround... ");
227 local_irq_save(flags
);
228 handler
= set_except_vector(12, handle_daddi_ov
);
230 "addiu %1, $0, %2\n\t"
233 : "=r" (v
), "=&r" (tmp
)
234 : "I" (0xffffffffffffdb9aUL
), "I" (0x1234));
235 set_except_vector(12, handler
);
236 local_irq_restore(flags
);
244 panic(bug64hit
, !DADDI_WAR
? daddiwar
: nowar
);
249 static inline void check_daddiu(void)
253 printk("Checking for the daddiu bug... ");
256 * The following code leads to a wrong result of daddiu when
257 * executed on R4400 rev. 1.0 (PRId 00000440).
259 * See "MIPS R4400PC/SC Errata, Processor Revision 1.0" by
260 * MIPS Technologies, Inc., erratum #7 for details.
262 * According to "MIPS R4000PC/SC Errata, Processor Revision
263 * 2.2 and 3.0" by MIPS Technologies, Inc., erratum #41 this
264 * problem affects R4000 rev. 2.2 and 3.0 (PRId 00000422 and
265 * 00000430, respectively), too. Testing failed to trigger it
268 * I got no permission to duplicate the errata here, sigh...
276 "addiu %2, $0, %3\n\t"
278 #ifdef HAVE_AS_SET_DADDI
281 "daddiu %0, %2, %4\n\t"
282 "addiu %1, $0, %4\n\t"
285 : "=&r" (v
), "=&r" (w
), "=&r" (tmp
)
286 : "I" (0xffffffffffffdb9aUL
), "I" (0x1234));
295 printk("yes, workaround... ");
298 "addiu %2, $0, %3\n\t"
300 "daddiu %0, %2, %4\n\t"
301 "addiu %1, $0, %4\n\t"
303 : "=&r" (v
), "=&r" (w
), "=&r" (tmp
)
304 : "I" (0xffffffffffffdb9aUL
), "I" (0x1234));
312 panic(bug64hit
, !DADDI_WAR
? daddiwar
: nowar
);
315 void __init
check_bugs64_early(void)
321 void __init
check_bugs64(void)