2 * Copyright (C) 2003, 2004 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/config.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/system.h>
22 static inline void align_mod(const int align
, const int mod
)
33 : "n" (align
), "n" (mod
));
36 static inline void mult_sh_align_mod(long *v1
, long *v2
, long *w
,
37 const int align
, const int mod
)
41 long p
, s
, lv1
, lv2
, lw
;
44 * We want the multiply and the shift to be isolated from the
45 * rest of the code to disable gcc optimizations. Hence the
46 * asm statements that execute nothing, but make gcc not know
47 * what the values of m1, m2 and s are and what lv2 and p are
51 local_irq_save(flags
);
53 * The following code leads to a wrong result of the first
54 * dsll32 when executed on R4000 rev. 2.2 or 3.0 (PRId
55 * 00000422 or 00000430, respectively).
57 * See "MIPS R4000PC/SC Errata, Processor Revision 2.2 and
58 * 3.0" by MIPS Technologies, Inc., errata #16 and #28 for
59 * details. I got no permission to duplicate them here,
64 : "=r" (m1
), "=r" (m2
), "=r" (s
)
65 : "0" (5), "1" (8), "2" (5));
66 align_mod(align
, mod
);
68 * The trailing nop is needed to fullfill the two-instruction
69 * requirement between reading hi/lo and staring a mult/div.
70 * Leaving it out may cause gas insert a nop itself breaking
71 * the desired alignment of the next chunk.
79 "dsll32 %0, %4, %5\n\t"
81 "dsll32 %1, %4, %5\n\t"
84 : "=&r" (lv1
), "=r" (lw
)
85 : "r" (m1
), "r" (m2
), "r" (s
), "I" (0)
86 : "hi", "lo", GCC_REG_ACCUM
);
87 /* We have to use single integers for m1 and m2 and a double
88 * one for p to be sure the mulsidi3 gcc's RTL multiplication
89 * instruction has the workaround applied. Older versions of
90 * gcc have correct umulsi3 and mulsi3, but other
91 * multiplication variants lack the workaround.
95 : "=r" (m1
), "=r" (m2
), "=r" (s
)
96 : "0" (m1
), "1" (m2
), "2" (s
));
97 align_mod(align
, mod
);
103 : "0" (lv2
), "r" (p
));
104 local_irq_restore(flags
);
111 static inline void check_mult_sh(void)
113 long v1
[8], v2
[8], w
[8];
116 printk("Checking for the multiply/shift bug... ");
119 * Testing discovered false negatives for certain code offsets
120 * into cache lines. Hence we test all possible offsets for
121 * the worst assumption of an R4000 I-cache line width of 32
124 * We can't use a loop as alignment directives need to be
127 mult_sh_align_mod(&v1
[0], &v2
[0], &w
[0], 32, 0);
128 mult_sh_align_mod(&v1
[1], &v2
[1], &w
[1], 32, 1);
129 mult_sh_align_mod(&v1
[2], &v2
[2], &w
[2], 32, 2);
130 mult_sh_align_mod(&v1
[3], &v2
[3], &w
[3], 32, 3);
131 mult_sh_align_mod(&v1
[4], &v2
[4], &w
[4], 32, 4);
132 mult_sh_align_mod(&v1
[5], &v2
[5], &w
[5], 32, 5);
133 mult_sh_align_mod(&v1
[6], &v2
[6], &w
[6], 32, 6);
134 mult_sh_align_mod(&v1
[7], &v2
[7], &w
[7], 32, 7);
137 for (i
= 0; i
< 8; i
++)
146 printk("yes, workaround... ");
149 for (i
= 0; i
< 8; i
++)
159 panic("Reliable operation impossible!\n"
160 #ifndef CONFIG_CPU_R4000
161 "Configure for R4000 to enable the workaround."
163 "Please report to <linux-mips@linux-mips.org>."
168 static volatile int daddi_ov __initdata
= 0;
170 asmlinkage
void __init
do_daddi_ov(struct pt_regs
*regs
)
176 static inline void check_daddi(void)
178 extern asmlinkage
void handle_daddi_ov(void);
183 printk("Checking for the daddi bug... ");
185 local_irq_save(flags
);
186 handler
= set_except_vector(12, handle_daddi_ov
);
188 * The following code fails to trigger an overflow exception
189 * when executed on R4000 rev. 2.2 or 3.0 (PRId 00000422 or
190 * 00000430, respectively).
192 * See "MIPS R4000PC/SC Errata, Processor Revision 2.2 and
193 * 3.0" by MIPS Technologies, Inc., erratum #23 for details.
194 * I got no permission to duplicate it here, sigh... --macro
201 "addiu %1, $0, %2\n\t"
203 #ifdef HAVE_AS_SET_DADDI
206 "daddi %0, %1, %3\n\t"
208 : "=r" (v
), "=&r" (tmp
)
209 : "I" (0xffffffffffffdb9a), "I" (0x1234));
210 set_except_vector(12, handler
);
211 local_irq_restore(flags
);
218 printk("yes, workaround... ");
220 local_irq_save(flags
);
221 handler
= set_except_vector(12, handle_daddi_ov
);
223 "addiu %1, $0, %2\n\t"
226 : "=r" (v
), "=&r" (tmp
)
227 : "I" (0xffffffffffffdb9a), "I" (0x1234));
228 set_except_vector(12, handler
);
229 local_irq_restore(flags
);
237 panic("Reliable operation impossible!\n"
238 #if !defined(CONFIG_CPU_R4000) && !defined(CONFIG_CPU_R4400)
239 "Configure for R4000 or R4400 to enable the workaround."
241 "Please report to <linux-mips@linux-mips.org>."
246 static inline void check_daddiu(void)
250 printk("Checking for the daddiu bug... ");
253 * The following code leads to a wrong result of daddiu when
254 * executed on R4400 rev. 1.0 (PRId 00000440).
256 * See "MIPS R4400PC/SC Errata, Processor Revision 1.0" by
257 * MIPS Technologies, Inc., erratum #7 for details.
259 * According to "MIPS R4000PC/SC Errata, Processor Revision
260 * 2.2 and 3.0" by MIPS Technologies, Inc., erratum #41 this
261 * problem affects R4000 rev. 2.2 and 3.0 (PRId 00000422 and
262 * 00000430, respectively), too. Testing failed to trigger it
265 * I got no permission to duplicate the errata here, sigh...
273 "addiu %2, $0, %3\n\t"
275 #ifdef HAVE_AS_SET_DADDI
278 "daddiu %0, %2, %4\n\t"
279 "addiu %1, $0, %4\n\t"
282 : "=&r" (v
), "=&r" (w
), "=&r" (tmp
)
283 : "I" (0xffffffffffffdb9a), "I" (0x1234));
290 printk("yes, workaround... ");
293 "addiu %2, $0, %3\n\t"
295 "daddiu %0, %2, %4\n\t"
296 "addiu %1, $0, %4\n\t"
298 : "=&r" (v
), "=&r" (w
), "=&r" (tmp
)
299 : "I" (0xffffffffffffdb9a), "I" (0x1234));
307 panic("Reliable operation impossible!\n"
308 #if !defined(CONFIG_CPU_R4000) && !defined(CONFIG_CPU_R4400)
309 "Configure for R4000 or R4400 to enable the workaround."
311 "Please report to <linux-mips@linux-mips.org>."
316 void __init
check_bugs64(void)