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) 2003, 2004 Ralf Baechle <ralf@linux-mips.org>
7 * Copyright (C) MIPS Technologies, Inc.
8 * written by Ralf Baechle <ralf@linux-mips.org>
10 #ifndef _ASM_HAZARDS_H
11 #define _ASM_HAZARDS_H
25 * RM9000 hazards. When the JTLB is updated by tlbwi or tlbwr, a subsequent
26 * use of the JTLB for instructions should not occur for 4 cpu cycles and use
27 * for data translations should not occur for 3 cpu cycles.
29 #ifdef CONFIG_CPU_RM9000
31 .macro mtc0_tlbw_hazard
34 _ssnop
; _ssnop
; _ssnop
; _ssnop
38 .macro tlbw_eret_hazard
41 _ssnop
; _ssnop
; _ssnop
; _ssnop
48 * The taken branch will result in a two cycle penalty for the two killed
49 * instructions on R4000 / R4400. Other processors only have a single cycle
50 * hazard so this is nice trick to have an optimal code for a range of
53 .macro mtc0_tlbw_hazard
57 .macro tlbw_eret_hazard
63 * The 24K has a 2 cycle mtc0/mfc0 execution hazard.
64 * It is a MIPS32R2 processor so ehb will clear the hazard.
67 #ifdef CONFIG_CPU_MIPSR2
69 * Use a macro for ehb unless explicit support for MIPSR2 is enabled
72 #define irq_enable_hazard \
75 #define irq_disable_hazard \
78 #elif defined(CONFIG_CPU_R10000) || defined(CONFIG_CPU_RM9000)
81 * R10000 rocks - all hazards handled in hardware, so this becomes a nobrainer.
84 #define irq_enable_hazard
86 #define irq_disable_hazard
91 * Classic MIPS needs 1 - 3 nops or ssnops
93 #define irq_enable_hazard
94 #define irq_disable_hazard \
95 _ssnop; _ssnop; _ssnop
99 #else /* __ASSEMBLY__ */
110 #ifdef CONFIG_CPU_RM9000
113 * RM9000 hazards. When the JTLB is updated by tlbwi or tlbwr, a subsequent
114 * use of the JTLB for instructions should not occur for 4 cpu cycles and use
115 * for data translations should not occur for 3 cpu cycles.
118 #define mtc0_tlbw_hazard() \
119 __asm__ __volatile__( \
127 #define tlbw_use_hazard() \
128 __asm__ __volatile__( \
139 * Overkill warning ...
141 #define mtc0_tlbw_hazard() \
142 __asm__ __volatile__( \
143 " .set noreorder \n" \
152 #define tlbw_use_hazard() \
153 __asm__ __volatile__( \
154 " .set noreorder \n" \
166 * Interrupt enable/disable hazards
167 * Some processors have hazards when modifying
168 * the status register to change the interrupt state
171 #ifdef CONFIG_CPU_MIPSR2
173 __asm__(" .macro irq_enable_hazard \n"
177 " .macro irq_disable_hazard \n"
181 #elif defined(CONFIG_CPU_R10000) || defined(CONFIG_CPU_RM9000)
184 * R10000 rocks - all hazards handled in hardware, so this becomes a nobrainer.
188 " .macro irq_enable_hazard \n"
191 " .macro irq_disable_hazard \n"
197 * Default for classic MIPS processors. Assume worst case hazards but don't
198 * care about the irq_enable_hazard - sooner or later the hardware will
199 * enable it and we don't care when exactly.
204 " # There is a hazard but we do not care \n"
206 " .macro\tirq_enable_hazard \n"
209 " .macro\tirq_disable_hazard \n"
217 #define irq_enable_hazard() \
218 __asm__ __volatile__("irq_enable_hazard")
219 #define irq_disable_hazard() \
220 __asm__ __volatile__("irq_disable_hazard")
224 * Back-to-back hazards -
226 * What is needed to separate a move to cp0 from a subsequent read from the
229 #ifdef CONFIG_CPU_MIPSR2
231 __asm__(" .macro back_to_back_c0_hazard \n"
235 #elif defined(CONFIG_CPU_R10000) || defined(CONFIG_CPU_RM9000) || \
236 defined(CONFIG_CPU_SB1)
238 __asm__(" .macro back_to_back_c0_hazard \n"
243 __asm__(" .macro back_to_back_c0_hazard \n"
253 #define back_to_back_c0_hazard() \
254 __asm__ __volatile__("back_to_back_c0_hazard")
258 * Instruction execution hazard
260 #ifdef CONFIG_CPU_MIPSR2
262 * gcc has a tradition of misscompiling the previous construct using the
263 * address of a label as argument to inline assembler. Gas otoh has the
264 * annoying difference between la and dla which are only usable for 32-bit
265 * rsp. 64-bit code, so can't be used without conditional compilation.
266 * The alterantive is switching the assembler to 64-bit code which happens
267 * to work right even for 32-bit code ...
269 #define instruction_hazard() \
273 __asm__ __volatile__( \
274 " .set mips64r2 \n" \
283 #define instruction_hazard() do { } while (0)
286 extern void mips_ihb(void);
288 #endif /* __ASSEMBLY__ */
290 #endif /* _ASM_HAZARDS_H */