1 /* GNU/Linux/AArch64 specific low level interface, for the in-process
4 Copyright (C) 2015-2019 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "tracepoint.h"
28 #include "linux-aarch64-tdesc.h"
30 /* Each register saved by the jump pad is in a 16 byte cell. */
39 #define FT_CR_GPR(n) (FT_CR_X0 + (n))
40 #define FT_CR_FPR(n) (FT_CR_GPR (31) + (n))
42 /* Mapping between registers collected by the jump pad and GDB's register
43 array layout used by regcache.
45 See linux-aarch64-low.c (aarch64_install_fast_tracepoint_jump_pad) for
48 static const int aarch64_ft_collect_regmap[] = {
121 #define AARCH64_NUM_FT_COLLECT_GREGS \
122 (sizeof (aarch64_ft_collect_regmap) / sizeof(aarch64_ft_collect_regmap[0]))
124 /* Fill in REGCACHE with registers saved by the jump pad in BUF. */
127 supply_fast_tracepoint_registers (struct regcache *regcache,
128 const unsigned char *buf)
132 for (i = 0; i < AARCH64_NUM_FT_COLLECT_GREGS; i++)
133 supply_register (regcache, i,
135 + (aarch64_ft_collect_regmap[i] * FT_CR_SIZE));
139 get_raw_reg (const unsigned char *raw_regs, int regnum)
141 if (regnum >= AARCH64_NUM_FT_COLLECT_GREGS)
144 return *(ULONGEST *) (raw_regs
145 + aarch64_ft_collect_regmap[regnum] * FT_CR_SIZE);
148 /* Return target_desc to use for IPA, given the tdesc index passed by
149 gdbserver. Index is ignored, since we have only one tdesc
150 at the moment. SVE not yet supported. */
152 const struct target_desc *
153 get_ipa_tdesc (int idx)
155 return aarch64_linux_read_description (0);
158 /* Allocate buffer for the jump pads. The branch instruction has a reach
159 of +/- 128MiB, and the executable is loaded at 0x400000 (4MiB).
160 To maximize the area of executable that can use tracepoints, try
161 allocating at 0x400000 - size initially, decreasing until we hit
165 alloc_jump_pad_buffer (size_t size)
168 uintptr_t exec_base = getauxval (AT_PHDR);
173 exec_base = 0x400000;
175 pagesize = sysconf (_SC_PAGE_SIZE);
177 perror_with_name ("sysconf");
179 addr = exec_base - size;
181 /* size should already be page-aligned, but this can't hurt. */
182 addr &= ~(pagesize - 1);
184 /* Search for a free area. If we hit 0, we're out of luck. */
185 for (; addr; addr -= pagesize)
187 /* No MAP_FIXED - we don't want to zap someone's mapping. */
188 res = mmap ((void *) addr, size,
189 PROT_READ | PROT_WRITE | PROT_EXEC,
190 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
192 /* If we got what we wanted, return. */
193 if ((uintptr_t) res == addr)
196 /* If we got a mapping, but at a wrong address, undo it. */
197 if (res != MAP_FAILED)
205 initialize_low_tracepoint (void)
207 /* SVE not yet supported. */
208 aarch64_linux_read_description (0);