aboutsummaryrefslogtreecommitdiff
path: root/gdb/arch
diff options
context:
space:
mode:
authorLuis Machado <luis.machado@linaro.org>2020-06-19 17:33:13 -0300
committerLuis Machado <luis.machado@linaro.org>2021-03-24 14:53:56 -0300
commit4601818e8c06bb8a5bf4b63fa527c69d3f81c6f0 (patch)
treea8650e0d1beb52fdf709a0198be63a61d29f4b49 /gdb/arch
parent3f3bd8b8c14d844533b70b25c7f1a8cbdbac2639 (diff)
downloadgdb-4601818e8c06bb8a5bf4b63fa527c69d3f81c6f0.zip
gdb-4601818e8c06bb8a5bf4b63fa527c69d3f81c6f0.tar.gz
gdb-4601818e8c06bb8a5bf4b63fa527c69d3f81c6f0.tar.bz2
AArch64: Implement memory tagging target methods for AArch64
The patch implements the memory tagging target hooks for AArch64, so we can handle MTE. gdb/ChangeLog: 2021-03-24 Luis Machado <luis.machado@linaro.org> * Makefile.in (ALL_64_TARGET_OBS): Add arch/aarch64-mte-linux.o. (HFILES_NO_SRCDIR): Add arch/aarch64-mte-linux.h and nat/aarch64-mte-linux-ptrace.h. * aarch64-linux-nat.c: Include nat/aarch64-mte-linux-ptrace.h. (aarch64_linux_nat_target) <supports_memory_tagging>: New method override. <fetch_memtags>: New method override. <store_memtags>: New method override. (aarch64_linux_nat_target::supports_memory_tagging): New method. (aarch64_linux_nat_target::fetch_memtags): New method. (aarch64_linux_nat_target::store_memtags): New method. * arch/aarch64-mte-linux.c: New file. * arch/aarch64-mte-linux.h: Include gdbsupport/common-defs.h. (AARCH64_MTE_GRANULE_SIZE): Define. (aarch64_memtag_type): New enum. (aarch64_mte_get_tag_granules): New prototype. * configure.nat (NATDEPFILES): Add nat/aarch64-mte-linux-ptrace.o. * configure.tgt (aarch64*-*-linux*): Add arch/aarch64-mte-linux.o. * nat/aarch64-mte-linux-ptrace.c: New file. * nat/aarch64-mte-linux-ptrace.h: New file.
Diffstat (limited to 'gdb/arch')
-rw-r--r--gdb/arch/aarch64-mte-linux.c38
-rw-r--r--gdb/arch/aarch64-mte-linux.h19
2 files changed, 57 insertions, 0 deletions
diff --git a/gdb/arch/aarch64-mte-linux.c b/gdb/arch/aarch64-mte-linux.c
new file mode 100644
index 0000000..3d72b8d
--- /dev/null
+++ b/gdb/arch/aarch64-mte-linux.c
@@ -0,0 +1,38 @@
+/* Common Linux target-dependent functionality for AArch64 MTE
+
+ Copyright (C) 2021 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "arch/aarch64-mte-linux.h"
+
+/* See arch/aarch64-mte-linux.h */
+
+size_t
+aarch64_mte_get_tag_granules (CORE_ADDR addr, size_t len, size_t granule_size)
+{
+ /* An empty range has 0 tag granules. */
+ if (len == 0)
+ return 0;
+
+ /* Start address */
+ CORE_ADDR s_addr = align_down (addr, granule_size);
+ /* End address */
+ CORE_ADDR e_addr = align_down (addr + len, granule_size);
+
+ /* We always have at least 1 granule. */
+ return 1 + (e_addr - s_addr) / granule_size;
+}
diff --git a/gdb/arch/aarch64-mte-linux.h b/gdb/arch/aarch64-mte-linux.h
index 7c259b8..88bd8d0 100644
--- a/gdb/arch/aarch64-mte-linux.h
+++ b/gdb/arch/aarch64-mte-linux.h
@@ -20,6 +20,8 @@
#ifndef ARCH_AARCH64_LINUX_H
#define ARCH_AARCH64_LINUX_H
+#include "gdbsupport/common-defs.h"
+
/* Feature check for Memory Tagging Extension. */
#ifndef HWCAP2_MTE
#define HWCAP2_MTE (1 << 18)
@@ -28,4 +30,21 @@
/* The MTE regset consists of a single 64-bit register. */
#define AARCH64_LINUX_SIZEOF_MTE 8
+/* We have one tag per 16 bytes of memory. */
+#define AARCH64_MTE_GRANULE_SIZE 16
+
+/* Memory tag types for AArch64. */
+enum class aarch64_memtag_type
+{
+ /* MTE logical tag contained in pointers. */
+ mte_logical = 0,
+ /* MTE allocation tag stored in memory tag granules. */
+ mte_allocation
+};
+
+/* Return the number of tag granules in the memory range
+ [ADDR, ADDR + LEN) given GRANULE_SIZE. */
+extern size_t aarch64_mte_get_tag_granules (CORE_ADDR addr, size_t len,
+ size_t granule_size);
+
#endif /* ARCH_AARCH64_LINUX_H */