All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Thierry <jthierry@redhat.com>
To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: jpoimboe@redhat.com, peterz@infradead.org, raphael.gault@arm.com,
	catalin.marinas@arm.com, will@kernel.org,
	Julien Thierry <jthierry@redhat.com>
Subject: [RFC v5 19/57] objtool: arm64: Add required implementation for supporting the aarch64 architecture in objtool.
Date: Thu,  9 Jan 2020 16:02:22 +0000	[thread overview]
Message-ID: <20200109160300.26150-20-jthierry@redhat.com> (raw)
In-Reply-To: <20200109160300.26150-1-jthierry@redhat.com>

From: Raphael Gault <raphael.gault@arm.com>

Provide implementation for the arch-dependent functions that are called by
the main check function of objtool.

Provide an empty squeleton for the aarch64 decoder that shall be
completed in later patches.

Signed-off-by: Raphael Gault <raphael.gault@arm.com>
[J.T.: Use enum for instruction type,
       Remove orc functions,
       Remove x86 feature macros from arm64 header,
       Split decoder over multiple patches,
       Use SPDX identifiers]
Signed-off-by: Julien Thierry <jthierry@redhat.com>
---
 tools/objtool/arch/arm64/Build                |   5 +
 tools/objtool/arch/arm64/arch_special.c       |  15 +++
 tools/objtool/arch/arm64/bit_operations.c     |  69 ++++++++++
 tools/objtool/arch/arm64/decode.c             | 127 ++++++++++++++++++
 .../objtool/arch/arm64/include/arch_special.h |  21 +++
 .../arch/arm64/include/bit_operations.h       |  31 +++++
 tools/objtool/arch/arm64/include/cfi_regs.h   |  44 ++++++
 .../objtool/arch/arm64/include/insn_decode.h  |  15 +++
 8 files changed, 327 insertions(+)
 create mode 100644 tools/objtool/arch/arm64/Build
 create mode 100644 tools/objtool/arch/arm64/arch_special.c
 create mode 100644 tools/objtool/arch/arm64/bit_operations.c
 create mode 100644 tools/objtool/arch/arm64/decode.c
 create mode 100644 tools/objtool/arch/arm64/include/arch_special.h
 create mode 100644 tools/objtool/arch/arm64/include/bit_operations.h
 create mode 100644 tools/objtool/arch/arm64/include/cfi_regs.h
 create mode 100644 tools/objtool/arch/arm64/include/insn_decode.h

diff --git a/tools/objtool/arch/arm64/Build b/tools/objtool/arch/arm64/Build
new file mode 100644
index 000000000000..2a554af43e96
--- /dev/null
+++ b/tools/objtool/arch/arm64/Build
@@ -0,0 +1,5 @@
+objtool-y += arch_special.o
+objtool-y += bit_operations.o
+objtool-y += decode.o
+
+CFLAGS_decode.o += -I$(OUTPUT)arch/arm64/lib
diff --git a/tools/objtool/arch/arm64/arch_special.c b/tools/objtool/arch/arm64/arch_special.c
new file mode 100644
index 000000000000..5239489c9c57
--- /dev/null
+++ b/tools/objtool/arch/arm64/arch_special.c
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "../../special.h"
+
+int arch_add_jump_table_dests(struct objtool_file *file,
+			      struct instruction *insn)
+{
+	return 0;
+}
+
+struct rela *arch_find_switch_table(struct objtool_file *file,
+				    struct instruction *insn)
+{
+	return NULL;
+}
diff --git a/tools/objtool/arch/arm64/bit_operations.c b/tools/objtool/arch/arm64/bit_operations.c
new file mode 100644
index 000000000000..cd44138956bb
--- /dev/null
+++ b/tools/objtool/arch/arm64/bit_operations.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "bit_operations.h"
+
+#include "../../warn.h"
+
+u64 replicate(u64 x, int size, int n)
+{
+	u64 ret = 0;
+
+	while (n >= 0) {
+		ret = (ret | x) << size;
+		n--;
+	}
+	return ret | x;
+}
+
+u64 ror(u64 x, int size, int shift)
+{
+	int m = shift % size;
+
+	if (shift == 0)
+		return x;
+	return ZERO_EXTEND((x >> m) | (x << (size - m)), size);
+}
+
+int highest_set_bit(u32 x)
+{
+	int i;
+
+	for (i = 31; i >= 0; i--, x <<= 1)
+		if (x & 0x80000000)
+			return i;
+	return 0;
+}
+
+/* imms and immr are both 6 bit long */
+__uint128_t decode_bit_masks(unsigned char N, unsigned char imms,
+			     unsigned char immr, bool immediate)
+{
+	u64 tmask, wmask;
+	u32 diff, S, R, esize, welem, telem;
+	unsigned char levels = 0, len = 0;
+
+	len = highest_set_bit((N << 6) | ((~imms) & ONES(6)));
+	levels = ZERO_EXTEND(ONES(len), 6);
+
+	if (immediate && ((imms & levels) == levels)) {
+		WARN("unknown instruction");
+		return -1;
+	}
+
+	S = imms & levels;
+	R = immr & levels;
+	diff = ZERO_EXTEND(S - R, 6);
+
+	esize = 1 << len;
+	diff = diff & ONES(len);
+
+	welem = ZERO_EXTEND(ONES(S + 1), esize);
+	telem = ZERO_EXTEND(ONES(diff + 1), esize);
+
+	wmask = replicate(ror(welem, esize, R), esize, 64 / esize);
+	tmask = replicate(telem, esize, 64 / esize);
+
+	return ((__uint128_t)wmask << 64) | tmask;
+}
diff --git a/tools/objtool/arch/arm64/decode.c b/tools/objtool/arch/arm64/decode.c
new file mode 100644
index 000000000000..4d0ab2acca27
--- /dev/null
+++ b/tools/objtool/arch/arm64/decode.c
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "insn_decode.h"
+#include "cfi_regs.h"
+#include "bit_operations.h"
+
+#include "../../check.h"
+#include "../../arch.h"
+#include "../../elf.h"
+#include "../../warn.h"
+
+bool arch_callee_saved_reg(unsigned char reg)
+{
+	switch (reg) {
+	case CFI_R19:
+	case CFI_R20:
+	case CFI_R21:
+	case CFI_R22:
+	case CFI_R23:
+	case CFI_R24:
+	case CFI_R25:
+	case CFI_R26:
+	case CFI_R27:
+	case CFI_R28:
+	case CFI_FP:
+	case CFI_R30:
+		return true;
+	default:
+		return false;
+	}
+}
+
+void arch_initial_func_cfi_state(struct cfi_state *state)
+{
+	int i;
+
+	for (i = 0; i < CFI_NUM_REGS; i++) {
+		state->regs[i].base = CFI_UNDEFINED;
+		state->regs[i].offset = 0;
+	}
+
+	/* initial CFA (call frame address) */
+	state->cfa.base = CFI_SP;
+	state->cfa.offset = 0;
+}
+
+unsigned long arch_dest_rela_offset(int addend)
+{
+	return addend;
+}
+
+unsigned long arch_jump_destination(struct instruction *insn)
+{
+	return insn->offset + insn->immediate;
+}
+
+static int is_arm64(struct elf *elf)
+{
+	switch (elf->ehdr.e_machine) {
+	case EM_AARCH64: //0xB7
+		return 1;
+	default:
+		WARN("unexpected ELF machine type %x",
+		     elf->ehdr.e_machine);
+		return 0;
+	}
+}
+
+/*
+ * static int (*arm_decode_class)(u32 instr,
+ *				 unsigned int *len,
+ *				 enum insn_type *type,
+ *				 unsigned long *immediate,
+ *				 struct list_head *ops_list);
+ */
+static arm_decode_class aarch64_insn_class_decode_table[NR_INSN_CLASS] = {
+	NULL,
+};
+
+/*
+ * Arm A64 Instruction set' decode groups (based on op0 bits[28:25]):
+ * Ob0000 - Reserved
+ * 0b0001/0b001x - Unallocated
+ * 0b100x - Data Processing -- Immediate
+ * 0b101x - Branch, Exception Gen., System Instructions.
+ * 0bx1x0 - Loads and Stores
+ * 0bx101 - Data Processing -- Registers
+ * 0bx111 - Data Processing -- Scalar Floating-Points, Advanced SIMD
+ */
+
+int arch_decode_instruction(struct elf *elf, struct section *sec,
+			    unsigned long offset, unsigned int maxlen,
+			    unsigned int *len, enum insn_type *type,
+			    unsigned long *immediate,
+			    struct list_head *ops_list)
+{
+	arm_decode_class decode_fun;
+	int arm64 = 0;
+	u32 insn = 0;
+	int res;
+
+	*len = 4;
+	*immediate = 0;
+
+	//test architucture (make sure it is arm64)
+	arm64 = is_arm64(elf);
+	if (arm64 != 1)
+		return -1;
+
+	//retrieve instruction (from sec->data->offset)
+	insn = *(u32 *)(sec->data->d_buf + offset);
+
+	//dispatch according to encoding classes
+	decode_fun = aarch64_insn_class_decode_table[INSN_CLASS(insn)];
+	if (decode_fun)
+		res = decode_fun(insn, type, immediate, ops_list);
+	else
+		res = -1;
+
+	if (res)
+		WARN_FUNC("Unsupported instruction", sec, offset);
+	return res;
+}
diff --git a/tools/objtool/arch/arm64/include/arch_special.h b/tools/objtool/arch/arm64/include/arch_special.h
new file mode 100644
index 000000000000..a82a9b3e51df
--- /dev/null
+++ b/tools/objtool/arch/arm64/include/arch_special.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _ARM64_ARCH_SPECIAL_H
+#define _ARM64_ARCH_SPECIAL_H
+
+#define EX_ENTRY_SIZE		8
+#define EX_ORIG_OFFSET		0
+#define EX_NEW_OFFSET		4
+
+#define JUMP_ENTRY_SIZE		16
+#define JUMP_ORIG_OFFSET	0
+#define JUMP_NEW_OFFSET		4
+
+#define ALT_ENTRY_SIZE		12
+#define ALT_ORIG_OFFSET		0
+#define ALT_NEW_OFFSET		4
+#define ALT_FEATURE_OFFSET	8
+#define ALT_ORIG_LEN_OFFSET	10
+#define ALT_NEW_LEN_OFFSET	11
+
+#endif /* _ARM64_ARCH_SPECIAL_H */
diff --git a/tools/objtool/arch/arm64/include/bit_operations.h b/tools/objtool/arch/arm64/include/bit_operations.h
new file mode 100644
index 000000000000..8554adb0df70
--- /dev/null
+++ b/tools/objtool/arch/arm64/include/bit_operations.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _BIT_OPERATIONS_H
+#define _BIT_OPERATIONS_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <linux/types.h>
+
+#define ONES(N)			(((__uint128_t)1 << (N)) - 1)
+#define ZERO_EXTEND(X, N)	((X) & ONES(N))
+#define EXTRACT_BIT(X, N)	(((X) >> (N)) & ONES(1))
+#define SIGN_EXTEND(X, N)	sign_extend((X), (N))
+
+static inline unsigned long sign_extend(unsigned long x, int nbits)
+{
+	return ((~0UL + (EXTRACT_BIT(x, nbits - 1) ^ 1)) << nbits) | x;
+}
+
+u64 replicate(u64 x, int size, int n);
+
+u64 ror(u64 x, int size, int shift);
+
+int highest_set_bit(u32 x);
+
+__uint128_t decode_bit_masks(unsigned char N,
+			     unsigned char imms,
+			     unsigned char immr,
+			     bool immediate);
+
+#endif /* _BIT_OPERATIONS_H */
diff --git a/tools/objtool/arch/arm64/include/cfi_regs.h b/tools/objtool/arch/arm64/include/cfi_regs.h
new file mode 100644
index 000000000000..d48f41e7890b
--- /dev/null
+++ b/tools/objtool/arch/arm64/include/cfi_regs.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _OBJTOOL_CFI_REGS_H
+#define _OBJTOOL_CFI_REGS_H
+
+#define CFI_R0			0
+#define CFI_R1			1
+#define CFI_R2			2
+#define CFI_R3			3
+#define CFI_R4			4
+#define CFI_R5			5
+#define CFI_R6			6
+#define CFI_R7			7
+#define CFI_R8			8
+#define CFI_R9			9
+#define CFI_R10			10
+#define CFI_R11			11
+#define CFI_R12			12
+#define CFI_R13			13
+#define CFI_R14			14
+#define CFI_R15			15
+#define CFI_R16			16
+#define CFI_R17			17
+#define CFI_R18			18
+#define CFI_R19			19
+#define CFI_R20			20
+#define CFI_R21			21
+#define CFI_R22			22
+#define CFI_R23			23
+#define CFI_R24			24
+#define CFI_R25			25
+#define CFI_R26			26
+#define CFI_R27			27
+#define CFI_R28			28
+#define CFI_R29			29
+#define CFI_FP			CFI_R29
+#define CFI_BP			CFI_FP
+#define CFI_R30			30
+#define CFI_LR			CFI_R30
+#define CFI_SP			31
+
+#define CFI_NUM_REGS		32
+
+#endif /* _OBJTOOL_CFI_REGS_H */
diff --git a/tools/objtool/arch/arm64/include/insn_decode.h b/tools/objtool/arch/arm64/include/insn_decode.h
new file mode 100644
index 000000000000..c56b72ac4633
--- /dev/null
+++ b/tools/objtool/arch/arm64/include/insn_decode.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _ARM_INSN_DECODE_H
+#define _ARM_INSN_DECODE_H
+
+#include "../../../arch.h"
+
+#define NR_INSN_CLASS	16
+#define INSN_CLASS(opcode)	(((opcode) >> 25) & (NR_INSN_CLASS - 1))
+
+typedef int (*arm_decode_class)(u32 instr, enum insn_type *type,
+				unsigned long *immediate,
+				struct list_head *ops_list);
+
+#endif /* _ARM_INSN_DECODE_H */
-- 
2.21.0


WARNING: multiple messages have this Message-ID (diff)
From: Julien Thierry <jthierry@redhat.com>
To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: Julien Thierry <jthierry@redhat.com>,
	peterz@infradead.org, catalin.marinas@arm.com,
	raphael.gault@arm.com, jpoimboe@redhat.com, will@kernel.org
Subject: [RFC v5 19/57] objtool: arm64: Add required implementation for supporting the aarch64 architecture in objtool.
Date: Thu,  9 Jan 2020 16:02:22 +0000	[thread overview]
Message-ID: <20200109160300.26150-20-jthierry@redhat.com> (raw)
In-Reply-To: <20200109160300.26150-1-jthierry@redhat.com>

From: Raphael Gault <raphael.gault@arm.com>

Provide implementation for the arch-dependent functions that are called by
the main check function of objtool.

Provide an empty squeleton for the aarch64 decoder that shall be
completed in later patches.

Signed-off-by: Raphael Gault <raphael.gault@arm.com>
[J.T.: Use enum for instruction type,
       Remove orc functions,
       Remove x86 feature macros from arm64 header,
       Split decoder over multiple patches,
       Use SPDX identifiers]
Signed-off-by: Julien Thierry <jthierry@redhat.com>
---
 tools/objtool/arch/arm64/Build                |   5 +
 tools/objtool/arch/arm64/arch_special.c       |  15 +++
 tools/objtool/arch/arm64/bit_operations.c     |  69 ++++++++++
 tools/objtool/arch/arm64/decode.c             | 127 ++++++++++++++++++
 .../objtool/arch/arm64/include/arch_special.h |  21 +++
 .../arch/arm64/include/bit_operations.h       |  31 +++++
 tools/objtool/arch/arm64/include/cfi_regs.h   |  44 ++++++
 .../objtool/arch/arm64/include/insn_decode.h  |  15 +++
 8 files changed, 327 insertions(+)
 create mode 100644 tools/objtool/arch/arm64/Build
 create mode 100644 tools/objtool/arch/arm64/arch_special.c
 create mode 100644 tools/objtool/arch/arm64/bit_operations.c
 create mode 100644 tools/objtool/arch/arm64/decode.c
 create mode 100644 tools/objtool/arch/arm64/include/arch_special.h
 create mode 100644 tools/objtool/arch/arm64/include/bit_operations.h
 create mode 100644 tools/objtool/arch/arm64/include/cfi_regs.h
 create mode 100644 tools/objtool/arch/arm64/include/insn_decode.h

diff --git a/tools/objtool/arch/arm64/Build b/tools/objtool/arch/arm64/Build
new file mode 100644
index 000000000000..2a554af43e96
--- /dev/null
+++ b/tools/objtool/arch/arm64/Build
@@ -0,0 +1,5 @@
+objtool-y += arch_special.o
+objtool-y += bit_operations.o
+objtool-y += decode.o
+
+CFLAGS_decode.o += -I$(OUTPUT)arch/arm64/lib
diff --git a/tools/objtool/arch/arm64/arch_special.c b/tools/objtool/arch/arm64/arch_special.c
new file mode 100644
index 000000000000..5239489c9c57
--- /dev/null
+++ b/tools/objtool/arch/arm64/arch_special.c
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "../../special.h"
+
+int arch_add_jump_table_dests(struct objtool_file *file,
+			      struct instruction *insn)
+{
+	return 0;
+}
+
+struct rela *arch_find_switch_table(struct objtool_file *file,
+				    struct instruction *insn)
+{
+	return NULL;
+}
diff --git a/tools/objtool/arch/arm64/bit_operations.c b/tools/objtool/arch/arm64/bit_operations.c
new file mode 100644
index 000000000000..cd44138956bb
--- /dev/null
+++ b/tools/objtool/arch/arm64/bit_operations.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "bit_operations.h"
+
+#include "../../warn.h"
+
+u64 replicate(u64 x, int size, int n)
+{
+	u64 ret = 0;
+
+	while (n >= 0) {
+		ret = (ret | x) << size;
+		n--;
+	}
+	return ret | x;
+}
+
+u64 ror(u64 x, int size, int shift)
+{
+	int m = shift % size;
+
+	if (shift == 0)
+		return x;
+	return ZERO_EXTEND((x >> m) | (x << (size - m)), size);
+}
+
+int highest_set_bit(u32 x)
+{
+	int i;
+
+	for (i = 31; i >= 0; i--, x <<= 1)
+		if (x & 0x80000000)
+			return i;
+	return 0;
+}
+
+/* imms and immr are both 6 bit long */
+__uint128_t decode_bit_masks(unsigned char N, unsigned char imms,
+			     unsigned char immr, bool immediate)
+{
+	u64 tmask, wmask;
+	u32 diff, S, R, esize, welem, telem;
+	unsigned char levels = 0, len = 0;
+
+	len = highest_set_bit((N << 6) | ((~imms) & ONES(6)));
+	levels = ZERO_EXTEND(ONES(len), 6);
+
+	if (immediate && ((imms & levels) == levels)) {
+		WARN("unknown instruction");
+		return -1;
+	}
+
+	S = imms & levels;
+	R = immr & levels;
+	diff = ZERO_EXTEND(S - R, 6);
+
+	esize = 1 << len;
+	diff = diff & ONES(len);
+
+	welem = ZERO_EXTEND(ONES(S + 1), esize);
+	telem = ZERO_EXTEND(ONES(diff + 1), esize);
+
+	wmask = replicate(ror(welem, esize, R), esize, 64 / esize);
+	tmask = replicate(telem, esize, 64 / esize);
+
+	return ((__uint128_t)wmask << 64) | tmask;
+}
diff --git a/tools/objtool/arch/arm64/decode.c b/tools/objtool/arch/arm64/decode.c
new file mode 100644
index 000000000000..4d0ab2acca27
--- /dev/null
+++ b/tools/objtool/arch/arm64/decode.c
@@ -0,0 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "insn_decode.h"
+#include "cfi_regs.h"
+#include "bit_operations.h"
+
+#include "../../check.h"
+#include "../../arch.h"
+#include "../../elf.h"
+#include "../../warn.h"
+
+bool arch_callee_saved_reg(unsigned char reg)
+{
+	switch (reg) {
+	case CFI_R19:
+	case CFI_R20:
+	case CFI_R21:
+	case CFI_R22:
+	case CFI_R23:
+	case CFI_R24:
+	case CFI_R25:
+	case CFI_R26:
+	case CFI_R27:
+	case CFI_R28:
+	case CFI_FP:
+	case CFI_R30:
+		return true;
+	default:
+		return false;
+	}
+}
+
+void arch_initial_func_cfi_state(struct cfi_state *state)
+{
+	int i;
+
+	for (i = 0; i < CFI_NUM_REGS; i++) {
+		state->regs[i].base = CFI_UNDEFINED;
+		state->regs[i].offset = 0;
+	}
+
+	/* initial CFA (call frame address) */
+	state->cfa.base = CFI_SP;
+	state->cfa.offset = 0;
+}
+
+unsigned long arch_dest_rela_offset(int addend)
+{
+	return addend;
+}
+
+unsigned long arch_jump_destination(struct instruction *insn)
+{
+	return insn->offset + insn->immediate;
+}
+
+static int is_arm64(struct elf *elf)
+{
+	switch (elf->ehdr.e_machine) {
+	case EM_AARCH64: //0xB7
+		return 1;
+	default:
+		WARN("unexpected ELF machine type %x",
+		     elf->ehdr.e_machine);
+		return 0;
+	}
+}
+
+/*
+ * static int (*arm_decode_class)(u32 instr,
+ *				 unsigned int *len,
+ *				 enum insn_type *type,
+ *				 unsigned long *immediate,
+ *				 struct list_head *ops_list);
+ */
+static arm_decode_class aarch64_insn_class_decode_table[NR_INSN_CLASS] = {
+	NULL,
+};
+
+/*
+ * Arm A64 Instruction set' decode groups (based on op0 bits[28:25]):
+ * Ob0000 - Reserved
+ * 0b0001/0b001x - Unallocated
+ * 0b100x - Data Processing -- Immediate
+ * 0b101x - Branch, Exception Gen., System Instructions.
+ * 0bx1x0 - Loads and Stores
+ * 0bx101 - Data Processing -- Registers
+ * 0bx111 - Data Processing -- Scalar Floating-Points, Advanced SIMD
+ */
+
+int arch_decode_instruction(struct elf *elf, struct section *sec,
+			    unsigned long offset, unsigned int maxlen,
+			    unsigned int *len, enum insn_type *type,
+			    unsigned long *immediate,
+			    struct list_head *ops_list)
+{
+	arm_decode_class decode_fun;
+	int arm64 = 0;
+	u32 insn = 0;
+	int res;
+
+	*len = 4;
+	*immediate = 0;
+
+	//test architucture (make sure it is arm64)
+	arm64 = is_arm64(elf);
+	if (arm64 != 1)
+		return -1;
+
+	//retrieve instruction (from sec->data->offset)
+	insn = *(u32 *)(sec->data->d_buf + offset);
+
+	//dispatch according to encoding classes
+	decode_fun = aarch64_insn_class_decode_table[INSN_CLASS(insn)];
+	if (decode_fun)
+		res = decode_fun(insn, type, immediate, ops_list);
+	else
+		res = -1;
+
+	if (res)
+		WARN_FUNC("Unsupported instruction", sec, offset);
+	return res;
+}
diff --git a/tools/objtool/arch/arm64/include/arch_special.h b/tools/objtool/arch/arm64/include/arch_special.h
new file mode 100644
index 000000000000..a82a9b3e51df
--- /dev/null
+++ b/tools/objtool/arch/arm64/include/arch_special.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _ARM64_ARCH_SPECIAL_H
+#define _ARM64_ARCH_SPECIAL_H
+
+#define EX_ENTRY_SIZE		8
+#define EX_ORIG_OFFSET		0
+#define EX_NEW_OFFSET		4
+
+#define JUMP_ENTRY_SIZE		16
+#define JUMP_ORIG_OFFSET	0
+#define JUMP_NEW_OFFSET		4
+
+#define ALT_ENTRY_SIZE		12
+#define ALT_ORIG_OFFSET		0
+#define ALT_NEW_OFFSET		4
+#define ALT_FEATURE_OFFSET	8
+#define ALT_ORIG_LEN_OFFSET	10
+#define ALT_NEW_LEN_OFFSET	11
+
+#endif /* _ARM64_ARCH_SPECIAL_H */
diff --git a/tools/objtool/arch/arm64/include/bit_operations.h b/tools/objtool/arch/arm64/include/bit_operations.h
new file mode 100644
index 000000000000..8554adb0df70
--- /dev/null
+++ b/tools/objtool/arch/arm64/include/bit_operations.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _BIT_OPERATIONS_H
+#define _BIT_OPERATIONS_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <linux/types.h>
+
+#define ONES(N)			(((__uint128_t)1 << (N)) - 1)
+#define ZERO_EXTEND(X, N)	((X) & ONES(N))
+#define EXTRACT_BIT(X, N)	(((X) >> (N)) & ONES(1))
+#define SIGN_EXTEND(X, N)	sign_extend((X), (N))
+
+static inline unsigned long sign_extend(unsigned long x, int nbits)
+{
+	return ((~0UL + (EXTRACT_BIT(x, nbits - 1) ^ 1)) << nbits) | x;
+}
+
+u64 replicate(u64 x, int size, int n);
+
+u64 ror(u64 x, int size, int shift);
+
+int highest_set_bit(u32 x);
+
+__uint128_t decode_bit_masks(unsigned char N,
+			     unsigned char imms,
+			     unsigned char immr,
+			     bool immediate);
+
+#endif /* _BIT_OPERATIONS_H */
diff --git a/tools/objtool/arch/arm64/include/cfi_regs.h b/tools/objtool/arch/arm64/include/cfi_regs.h
new file mode 100644
index 000000000000..d48f41e7890b
--- /dev/null
+++ b/tools/objtool/arch/arm64/include/cfi_regs.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _OBJTOOL_CFI_REGS_H
+#define _OBJTOOL_CFI_REGS_H
+
+#define CFI_R0			0
+#define CFI_R1			1
+#define CFI_R2			2
+#define CFI_R3			3
+#define CFI_R4			4
+#define CFI_R5			5
+#define CFI_R6			6
+#define CFI_R7			7
+#define CFI_R8			8
+#define CFI_R9			9
+#define CFI_R10			10
+#define CFI_R11			11
+#define CFI_R12			12
+#define CFI_R13			13
+#define CFI_R14			14
+#define CFI_R15			15
+#define CFI_R16			16
+#define CFI_R17			17
+#define CFI_R18			18
+#define CFI_R19			19
+#define CFI_R20			20
+#define CFI_R21			21
+#define CFI_R22			22
+#define CFI_R23			23
+#define CFI_R24			24
+#define CFI_R25			25
+#define CFI_R26			26
+#define CFI_R27			27
+#define CFI_R28			28
+#define CFI_R29			29
+#define CFI_FP			CFI_R29
+#define CFI_BP			CFI_FP
+#define CFI_R30			30
+#define CFI_LR			CFI_R30
+#define CFI_SP			31
+
+#define CFI_NUM_REGS		32
+
+#endif /* _OBJTOOL_CFI_REGS_H */
diff --git a/tools/objtool/arch/arm64/include/insn_decode.h b/tools/objtool/arch/arm64/include/insn_decode.h
new file mode 100644
index 000000000000..c56b72ac4633
--- /dev/null
+++ b/tools/objtool/arch/arm64/include/insn_decode.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _ARM_INSN_DECODE_H
+#define _ARM_INSN_DECODE_H
+
+#include "../../../arch.h"
+
+#define NR_INSN_CLASS	16
+#define INSN_CLASS(opcode)	(((opcode) >> 25) & (NR_INSN_CLASS - 1))
+
+typedef int (*arm_decode_class)(u32 instr, enum insn_type *type,
+				unsigned long *immediate,
+				struct list_head *ops_list);
+
+#endif /* _ARM_INSN_DECODE_H */
-- 
2.21.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2020-01-09 16:05 UTC|newest]

Thread overview: 189+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-09 16:02 [RFC v5 00/57] objtool: Add support for arm64 Julien Thierry
2020-01-09 16:02 ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 01/57] objtool: check: Remove redundant checks on operand type Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 02/57] objtool: check: Clean instruction state before each function validation Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 03/57] objtool: check: Use arch specific values in restore_reg() Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 04/57] objtool: check: Ignore empty alternative groups Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-21 16:30   ` Josh Poimboeuf
2020-01-21 16:30     ` Josh Poimboeuf
2020-01-23 11:45     ` Julien Thierry
2020-01-23 11:45       ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 05/57] objtool: Add abstraction for computation of symbols offsets Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 06/57] objtool: Give ORC functions consistent name Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 07/57] objtool: orc: Refactor ORC API for other architectures to implement Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 08/57] objtool: Make ORC support optional Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-21 16:37   ` Josh Poimboeuf
2020-01-21 16:37     ` Josh Poimboeuf
2020-01-23 11:45     ` Julien Thierry
2020-01-23 11:45       ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 09/57] objtool: Move registers and control flow to arch-dependent code Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 10/57] objtool: Split generic and arch specific CFI definitions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 11/57] objtool: Abstract alternative special case handling Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-20 14:54   ` Peter Zijlstra
2020-01-20 14:54     ` Peter Zijlstra
2020-01-23 11:45     ` Julien Thierry
2020-01-23 11:45       ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 12/57] objtool: check: Allow jumps from an alternative group to itself Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-20 14:56   ` Peter Zijlstra
2020-01-20 14:56     ` Peter Zijlstra
2020-01-21 10:30     ` Will Deacon
2020-01-21 10:30       ` Will Deacon
2020-01-21 17:33   ` Josh Poimboeuf
2020-01-21 17:33     ` Josh Poimboeuf
2020-01-23 13:42     ` Julien Thierry
2020-01-23 13:42       ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 13/57] objtool: Refactor switch-tables code to support other architectures Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 14/57] objtool: Do not look for STT_NOTYPE symbols Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-11 18:49   ` kbuild test robot
2020-01-13 10:20   ` Julien Thierry
2020-01-13 10:20     ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 15/57] objtool: Support addition to set frame pointer Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 16/57] objtool: Support restoring BP from the stack without POP Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 17/57] objtool: Make stack validation more generic Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 18/57] objtool: Support multiple stack_op per instruction Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` Julien Thierry [this message]
2020-01-09 16:02   ` [RFC v5 19/57] objtool: arm64: Add required implementation for supporting the aarch64 architecture in objtool Julien Thierry
2020-01-09 16:02 ` [RFC v5 20/57] objtool: arm64: Decode unknown instructions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 21/57] objtool: arm64: Decode simple data processing instructions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 22/57] objtool: arm64: Decode add/sub immediate instructions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 23/57] objtool: arm64: Decode logical data processing instructions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 24/57] objtool: arm64: Decode system instructions not affecting the flow Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 25/57] objtool: arm64: Decode calls to higher EL Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 26/57] objtool: arm64: Decode brk instruction Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 27/57] objtool: arm64: Decode instruction triggering context switch Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 28/57] objtool: arm64: Decode branch instructions with PC relative immediates Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 29/57] objtool: arm64: Decode branch to register instruction Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 30/57] objtool: arm64: Decode basic load/stores Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 31/57] objtool: arm64: Decode load/store with register offset Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 32/57] objtool: arm64: Decode load/store register pair instructions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 33/57] objtool: arm64: Decode FP/SIMD load/store instructions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 34/57] objtool: arm64: Decode load/store exclusive Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 35/57] objtool: arm64: Decode atomic load/store Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 36/57] objtool: arm64: Decode pointer auth load instructions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 37/57] objtool: arm64: Decode load acquire/store release Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 38/57] objtool: arm64: Decode load/store with memory tag Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 39/57] objtool: arm64: Decode load literal Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 40/57] objtool: arm64: Decode register data processing instructions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 41/57] objtool: arm64: Decode FP/SIMD " Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 42/57] objtool: arm64: Decode SVE instructions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 43/57] gcc-plugins: objtool: Add plugin to detect switch table on arm64 Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 44/57] objtool: arm64: Implement functions to add switch tables alternatives Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-15 16:37   ` Raphael Gault
2020-01-15 16:37     ` Raphael Gault
2020-01-17  8:28     ` Julien Thierry
2020-01-17  8:28       ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 45/57] objtool: arm64: Enable stack validation for arm64 Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-11 14:42   ` kbuild test robot
2020-01-11 20:30   ` kbuild test robot
2020-01-09 16:02 ` [RFC v5 46/57] arm64: alternative: Mark .altinstr_replacement as containing executable instructions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-12 11:08   ` kbuild test robot
2020-01-13  3:38   ` kbuild test robot
2020-01-09 16:02 ` [RFC v5 47/57] arm64: assembler: Add macro to annotate asm function having non standard stack-frame Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-21 10:30   ` Will Deacon
2020-01-21 10:30     ` Will Deacon
2020-01-23 13:45     ` Julien Thierry
2020-01-23 13:45       ` Julien Thierry
2020-01-23 14:40       ` Will Deacon
2020-01-23 14:40         ` Will Deacon
2020-01-09 16:02 ` [RFC v5 48/57] arm64: sleep: Prevent stack frame warnings from objtool Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 49/57] arm64: kvm: Annotate non-standard stack frame functions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 50/57] arm64: kernel: Add exception on kuser32 to prevent stack analysis Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 51/57] arm64: crypto: Add exceptions for crypto object " Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 52/57] arm64: kernel: Annotate non-standard stack frame functions Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 53/57] arm64: Generate no-ops to pad executable section Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 54/57] arm64: Move constant to rodata Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 55/57] arm64: Mark sigreturn32.o as containing non standard code Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:02 ` [RFC v5 56/57] arm64: entry: Avoid empty alternatives entries Julien Thierry
2020-01-09 16:02   ` Julien Thierry
2020-01-09 16:51   ` Mark Rutland
2020-01-09 16:51     ` Mark Rutland
2020-01-21 10:30     ` Will Deacon
2020-01-21 10:30       ` Will Deacon
2020-01-09 16:03 ` [RFC v5 57/57] arm64: crypto: Remove redundant branch Julien Thierry
2020-01-09 16:03   ` Julien Thierry
2020-01-12  8:42 ` [RFC v5 00/57] objtool: Add support for arm64 Nathan Chancellor
2020-01-12  8:42   ` Nathan Chancellor
2020-01-13  7:57   ` Julien Thierry
2020-01-13  7:57     ` Julien Thierry
2020-01-21 10:31     ` Will Deacon
2020-01-21 10:31       ` Will Deacon
2020-01-21 17:08       ` Nick Desaulniers
2020-01-21 17:08         ` Nick Desaulniers
2020-01-21 18:06         ` Will Deacon
2020-01-21 18:06           ` Will Deacon
2020-01-21 18:30           ` Josh Poimboeuf
2020-01-21 18:30             ` Josh Poimboeuf
2020-01-22 14:47             ` Will Deacon
2020-01-22 14:47               ` Will Deacon
2020-01-13 17:18   ` Nick Desaulniers
2020-01-13 17:18     ` Nick Desaulniers
2020-01-20 15:07 ` Peter Zijlstra
2020-01-20 15:07   ` Peter Zijlstra
2020-01-21 17:50   ` Josh Poimboeuf
2020-01-21 17:50     ` Josh Poimboeuf
2020-01-23 13:56     ` Julien Thierry
2020-01-23 13:56       ` Julien Thierry
2020-01-21 10:30 ` Will Deacon
2020-01-21 10:30   ` Will Deacon
2020-01-23 13:52   ` Julien Thierry
2020-01-23 13:52     ` Julien Thierry
2020-01-23 14:35     ` Will Deacon
2020-01-23 14:35       ` Will Deacon
2020-01-23 15:11       ` Julien Thierry
2020-01-23 15:11         ` Julien Thierry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200109160300.26150-20-jthierry@redhat.com \
    --to=jthierry@redhat.com \
    --cc=catalin.marinas@arm.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=raphael.gault@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.