1 /* GNU/Linux/AArch64 specific low level interface, for the in-process
4 Copyright (C) 2015-2016 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"
29 /* Defined in auto-generated file aarch64.c. */
30 void init_registers_aarch64 (void);
31 extern const struct target_desc
*tdesc_aarch64
;
33 /* Each register saved by the jump pad is in a 16 byte cell. */
42 #define FT_CR_GPR(n) (FT_CR_X0 + (n))
43 #define FT_CR_FPR(n) (FT_CR_GPR (31) + (n))
45 /* Mapping between registers collected by the jump pad and GDB's register
46 array layout used by regcache.
48 See linux-aarch64-low.c (aarch64_install_fast_tracepoint_jump_pad) for
51 static const int aarch64_ft_collect_regmap
[] = {
124 #define AARCH64_NUM_FT_COLLECT_GREGS \
125 (sizeof (aarch64_ft_collect_regmap) / sizeof(aarch64_ft_collect_regmap[0]))
127 /* Fill in REGCACHE with registers saved by the jump pad in BUF. */
130 supply_fast_tracepoint_registers (struct regcache
*regcache
,
131 const unsigned char *buf
)
135 for (i
= 0; i
< AARCH64_NUM_FT_COLLECT_GREGS
; i
++)
136 supply_register (regcache
, i
,
138 + (aarch64_ft_collect_regmap
[i
] * FT_CR_SIZE
));
142 get_raw_reg (const unsigned char *raw_regs
, int regnum
)
144 if (regnum
>= AARCH64_NUM_FT_COLLECT_GREGS
)
147 return *(ULONGEST
*) (raw_regs
148 + aarch64_ft_collect_regmap
[regnum
] * FT_CR_SIZE
);
151 /* Return target_desc to use for IPA, given the tdesc index passed by
152 gdbserver. Index is ignored, since we have only one tdesc
155 const struct target_desc
*
156 get_ipa_tdesc (int idx
)
158 return tdesc_aarch64
;
161 /* Allocate buffer for the jump pads. The branch instruction has a reach
162 of +/- 128MiB, and the executable is loaded at 0x400000 (4MiB).
163 To maximize the area of executable that can use tracepoints, try
164 allocating at 0x400000 - size initially, decreasing until we hit
168 alloc_jump_pad_buffer (size_t size
)
171 uintptr_t exec_base
= getauxval (AT_PHDR
);
176 exec_base
= 0x400000;
178 pagesize
= sysconf (_SC_PAGE_SIZE
);
180 perror_with_name ("sysconf");
182 addr
= exec_base
- size
;
184 /* size should already be page-aligned, but this can't hurt. */
185 addr
&= ~(pagesize
- 1);
187 /* Search for a free area. If we hit 0, we're out of luck. */
188 for (; addr
; addr
-= pagesize
)
190 /* No MAP_FIXED - we don't want to zap someone's mapping. */
191 res
= mmap ((void *) addr
, size
,
192 PROT_READ
| PROT_WRITE
| PROT_EXEC
,
193 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
195 /* If we got what we wanted, return. */
196 if ((uintptr_t) res
== addr
)
199 /* If we got a mapping, but at a wrong address, undo it. */
200 if (res
!= MAP_FAILED
)
208 initialize_low_tracepoint (void)
210 init_registers_aarch64 ();