Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit edbcf50e authored by Jean-Philippe Brucker's avatar Jean-Philippe Brucker Committed by Will Deacon
Browse files

arm64: insn: Add BUILD_BUG_ON() for invalid masks



Detect invalid instruction masks at build time. Some versions of GCC can
warn about the situation, but not all of them, it seems.

Suggested-by: default avatarWill Deacon <will.deacon@arm.com>
Signed-off-by: default avatarJean-Philippe Brucker <jean-philippe.brucker@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent c5e2edeb
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
 */
#ifndef	__ASM_INSN_H
#define	__ASM_INSN_H
#include <linux/build_bug.h>
#include <linux/types.h>

/* A64 instructions are always 32 bits. */
@@ -268,9 +269,14 @@ enum aarch64_insn_adr_type {

#define	__AARCH64_INSN_FUNCS(abbr, mask, val)				\
static __always_inline bool aarch64_insn_is_##abbr(u32 code)		\
{ return (code & (mask)) == (val); } \
{									\
	BUILD_BUG_ON(~(mask) & (val));					\
	return (code & (mask)) == (val);				\
}									\
static __always_inline u32 aarch64_insn_get_##abbr##_value(void)	\
{ return (val); }
{									\
	return (val);							\
}

__AARCH64_INSN_FUNCS(adr,	0x9F000000, 0x10000000)
__AARCH64_INSN_FUNCS(adrp,	0x9F000000, 0x90000000)