Get rid of arch/mips64/kernel. 9116 lines of code gone.
[linux-2.6/linux-mips.git] / arch / mips / kernel / cpu-bugs64.c
blob402f5e8993542ea33065fcb9d3ca4c12ade54b6f
1 /*
2 * Copyright (C) 2003 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.
8 */
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/ptrace.h>
12 #include <linux/stddef.h>
14 #include <asm/bugs.h>
15 #include <asm/cpu.h>
16 #include <asm/fpu.h>
17 #include <asm/mipsregs.h>
18 #include <asm/system.h>
20 static inline void check_mult_sh(void)
22 unsigned long flags;
23 int m1, m2;
24 long p, s, v;
26 printk("Checking for the multiply/shift bug... ");
28 local_irq_save(flags);
30 * The following code leads to a wrong result of dsll32 when
31 * executed on R4000 rev. 2.2 or 3.0.
33 * See "MIPS R4000PC/SC Errata, Processor Revision 2.2 and
34 * 3.0" by MIPS Technologies, Inc., errata #16 and #28 for
35 * details. I got no permission to duplicate them here,
36 * sigh... --macro
38 asm volatile(
39 ".set push\n\t"
40 ".set noat\n\t"
41 ".set noreorder\n\t"
42 ".set nomacro\n\t"
43 "mult %1, %2\n\t"
44 "dsll32 %0, %3, %4\n\t"
45 "mflo $0\n\t"
46 ".set pop"
47 : "=r" (v)
48 : "r" (5), "r" (8), "r" (5), "I" (0)
49 : "hi", "lo", "accum");
50 local_irq_restore(flags);
52 if (v == 5L << 32) {
53 printk("no.\n");
54 return;
57 printk("yes, workaround... ");
58 local_irq_save(flags);
60 * We want the multiply and the shift to be isolated from the
61 * rest of the code to disable gcc optimizations. Hence the
62 * asm statements that execute nothing, but make gcc not know
63 * what the values of m1, m2 and s are and what v and p are
64 * used for.
66 * We have to use single integers for m1 and m2 and a double
67 * one for p to be sure the mulsidi3 gcc's RTL multiplication
68 * instruction has the workaround applied. Older versions of
69 * gcc have correct mulsi3, but other multiplication variants
70 * lack the workaround.
72 asm volatile(
74 : "=r" (m1), "=r" (m2), "=r" (s)
75 : "0" (5), "1" (8), "2" (5));
76 p = m1 * m2;
77 v = s << 32;
78 asm volatile(
80 : "=r" (v)
81 : "0" (v), "r" (p));
82 local_irq_restore(flags);
84 if (v == 5L << 32) {
85 printk("yes.\n");
86 return;
89 printk("no.\n");
90 panic("Reliable operation impossible!\n"
91 #ifndef CONFIG_CPU_R4000
92 "Configure for R4000 to enable the workaround."
93 #else
94 "Please report to <linux-mips@linux-mips.org>."
95 #endif
99 static volatile int daddi_ov __initdata = 0;
101 asmlinkage void __init do_daddi_ov(struct pt_regs *regs)
103 daddi_ov = 1;
104 regs->cp0_epc += 4;
107 static inline void check_daddi(void)
109 extern asmlinkage void handle_daddi_ov(void);
110 unsigned long flags;
111 void *handler;
112 long v;
114 printk("Checking for the daddi bug... ");
116 local_irq_save(flags);
117 handler = set_except_vector(12, handle_daddi_ov);
119 * The following code fails to trigger an overflow exception
120 * when executed on R4000 rev. 2.2 or 3.0.
122 * See "MIPS R4000PC/SC Errata, Processor Revision 2.2 and
123 * 3.0" by MIPS Technologies, Inc., erratum #23 for details.
124 * I got no permission to duplicate it here, sigh... --macro
126 asm volatile(
127 ".set push\n\t"
128 ".set noat\n\t"
129 ".set noreorder\n\t"
130 ".set nomacro\n\t"
131 #ifdef HAVE_AS_SET_DADDI
132 ".set daddi\n\t"
133 #endif
134 "daddi %0, %1, %2\n\t"
135 ".set pop"
136 : "=r" (v)
137 : "r" (0x7fffffffffffedcd), "I" (0x1234));
138 set_except_vector(12, handler);
139 local_irq_restore(flags);
141 if (daddi_ov) {
142 printk("no.\n");
143 return;
146 printk("yes, workaround... ");
148 local_irq_save(flags);
149 handler = set_except_vector(12, handle_daddi_ov);
150 asm volatile(
151 "daddi %0, %1, %2"
152 : "=r" (v)
153 : "r" (0x7fffffffffffedcd), "I" (0x1234));
154 set_except_vector(12, handler);
155 local_irq_restore(flags);
157 if (daddi_ov) {
158 printk("yes.\n");
159 return;
162 printk("no.\n");
163 panic("Reliable operation impossible!\n"
164 #if !defined(CONFIG_CPU_R4000) && !defined(CONFIG_CPU_R4400)
165 "Configure for R4000 or R4400 to enable the workaround."
166 #else
167 "Please report to <linux-mips@linux-mips.org>."
168 #endif
172 static inline void check_daddiu(void)
174 long v, w;
176 printk("Checking for the daddiu bug... ");
179 * The following code leads to a wrong result of daddiu when
180 * executed on R4400 rev. 1.0.
182 * See "MIPS R4400PC/SC Errata, Processor Revision 1.0" by
183 * MIPS Technologies, Inc., erratum #7 for details.
185 * According to "MIPS R4000PC/SC Errata, Processor Revision
186 * 2.2 and 3.0" by MIPS Technologies, Inc., erratum #41 this
187 * problem affects R4000 rev. 2.2 and 3.0, too. Testing
188 * failed to trigger it so far.
190 * I got no permission to duplicate the errata here, sigh...
191 * --macro
193 asm volatile(
194 ".set push\n\t"
195 ".set noat\n\t"
196 ".set noreorder\n\t"
197 ".set nomacro\n\t"
198 #ifdef HAVE_AS_SET_DADDI
199 ".set daddi\n\t"
200 #endif
201 "daddiu %0, %2, %3\n\t"
202 "addiu %1, $0, %3\n\t"
203 "daddu %1, %2\n\t"
204 ".set pop"
205 : "=&r" (v), "=&r" (w)
206 : "r" (0x7fffffffffffedcd), "I" (0x1234));
208 if (v == w) {
209 printk("no.\n");
210 return;
213 printk("yes, workaround... ");
215 asm volatile(
216 "daddiu %0, %2, %3\n\t"
217 "addiu %1, $0, %3\n\t"
218 "daddu %1, %2"
219 : "=&r" (v), "=&r" (w)
220 : "r" (0x7fffffffffffedcd), "I" (0x1234));
222 if (v == w) {
223 printk("yes.\n");
224 return;
227 printk("no.\n");
228 panic("Reliable operation impossible!\n"
229 #if !defined(CONFIG_CPU_R4000) && !defined(CONFIG_CPU_R4400)
230 "Configure for R4000 or R4400 to enable the workaround."
231 #else
232 "Please report to <linux-mips@linux-mips.org>."
233 #endif
237 void __init check_bugs64(void)
239 check_mult_sh();
240 check_daddi();
241 check_daddiu();