/*1* Copyright (C) 2004, 2007 Maciej W. Rozycki2*3* This file is subject to the terms and conditions of the GNU General Public4* License. See the file "COPYING" in the main directory of this archive5* for more details.6*/7#ifndef _ASM_COMPILER_H8#define _ASM_COMPILER_H910/*11* With GCC 4.5 onwards we can use __builtin_unreachable to indicate to the12* compiler that a particular code path will never be hit. This allows it to be13* optimised out of the generated binary.14*15* Unfortunately at least GCC 4.6.3 through 7.3.0 inclusive suffer from a bug16* that can lead to instructions from beyond an unreachable statement being17* incorrectly reordered into earlier delay slots if the unreachable statement18* is the only content of a case in a switch statement. This can lead to19* seemingly random behaviour, such as invalid memory accesses from incorrectly20* reordered loads or stores. See this potential GCC fix for details:21*22* https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00360.html23*24* It is unclear whether GCC 8 onwards suffer from the same issue - nothing25* relevant is mentioned in GCC 8 release notes and nothing obviously relevant26* stands out in GCC commit logs, but these newer GCC versions generate very27* different code for the testcase which doesn't exhibit the bug.28*29* GCC also handles stack allocation suboptimally when calling noreturn30* functions or calling __builtin_unreachable():31*32* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=8236533*34* We work around both of these issues by placing a volatile asm statement,35* which GCC is prevented from reordering past, prior to __builtin_unreachable36* calls.37*38* The .insn statement is required to ensure that any branches to the39* statement, which sadly must be kept due to the asm statement, are known to40* be branches to code and satisfy linker requirements for microMIPS kernels.41*/42#undef barrier_before_unreachable43#define barrier_before_unreachable() asm volatile(".insn")4445#define GCC_OFF_SMALL_ASM() "ZC"4647#ifdef CONFIG_CPU_MIPSR648#define MIPS_ISA_LEVEL "mips64r6"49#define MIPS_ISA_ARCH_LEVEL MIPS_ISA_LEVEL50#define MIPS_ISA_LEVEL_RAW mips64r651#define MIPS_ISA_ARCH_LEVEL_RAW MIPS_ISA_LEVEL_RAW52#elif defined(CONFIG_CPU_MIPSR5)53#define MIPS_ISA_LEVEL "mips64r5"54#define MIPS_ISA_ARCH_LEVEL MIPS_ISA_LEVEL55#define MIPS_ISA_LEVEL_RAW mips64r556#define MIPS_ISA_ARCH_LEVEL_RAW MIPS_ISA_LEVEL_RAW57#else58/* MIPS64 is a superset of MIPS32 */59#define MIPS_ISA_LEVEL "mips64r2"60#define MIPS_ISA_ARCH_LEVEL "arch=r4000"61#define MIPS_ISA_LEVEL_RAW mips64r262#define MIPS_ISA_ARCH_LEVEL_RAW MIPS_ISA_LEVEL_RAW63#endif /* CONFIG_CPU_MIPSR6 */6465#endif /* _ASM_COMPILER_H */666768