xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/arch/aarch64.c (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1*6881a400Schristos /* Copyright (C) 2017-2023 Free Software Foundation, Inc.
27f2ac410Schristos 
37f2ac410Schristos    This file is part of GDB.
47f2ac410Schristos 
57f2ac410Schristos    This program is free software; you can redistribute it and/or modify
67f2ac410Schristos    it under the terms of the GNU General Public License as published by
77f2ac410Schristos    the Free Software Foundation; either version 3 of the License, or
87f2ac410Schristos    (at your option) any later version.
97f2ac410Schristos 
107f2ac410Schristos    This program is distributed in the hope that it will be useful,
117f2ac410Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
127f2ac410Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
137f2ac410Schristos    GNU General Public License for more details.
147f2ac410Schristos 
157f2ac410Schristos    You should have received a copy of the GNU General Public License
167f2ac410Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
177f2ac410Schristos 
187d62b00eSchristos #include "gdbsupport/common-defs.h"
197f2ac410Schristos #include "aarch64.h"
207f2ac410Schristos #include <stdlib.h>
217f2ac410Schristos 
227f2ac410Schristos #include "../features/aarch64-core.c"
237f2ac410Schristos #include "../features/aarch64-fpu.c"
247f2ac410Schristos #include "../features/aarch64-sve.c"
257d62b00eSchristos #include "../features/aarch64-pauth.c"
26*6881a400Schristos #include "../features/aarch64-mte.c"
27*6881a400Schristos #include "../features/aarch64-tls.c"
287f2ac410Schristos 
297f2ac410Schristos /* See arch/aarch64.h.  */
307f2ac410Schristos 
317f2ac410Schristos target_desc *
32*6881a400Schristos aarch64_create_target_description (const aarch64_features &features)
337f2ac410Schristos {
34*6881a400Schristos   target_desc_up tdesc = allocate_target_description ();
357f2ac410Schristos 
367f2ac410Schristos #ifndef IN_PROCESS_AGENT
37*6881a400Schristos   set_tdesc_architecture (tdesc.get (), "aarch64");
387f2ac410Schristos #endif
397f2ac410Schristos 
407f2ac410Schristos   long regnum = 0;
417f2ac410Schristos 
42*6881a400Schristos   regnum = create_feature_aarch64_core (tdesc.get (), regnum);
437f2ac410Schristos 
44*6881a400Schristos   if (features.vq == 0)
45*6881a400Schristos     regnum = create_feature_aarch64_fpu (tdesc.get (), regnum);
467f2ac410Schristos   else
47*6881a400Schristos     regnum = create_feature_aarch64_sve (tdesc.get (), regnum, features.vq);
487f2ac410Schristos 
49*6881a400Schristos   if (features.pauth)
50*6881a400Schristos     regnum = create_feature_aarch64_pauth (tdesc.get (), regnum);
517d62b00eSchristos 
52*6881a400Schristos   /* Memory tagging extension registers.  */
53*6881a400Schristos   if (features.mte)
54*6881a400Schristos     regnum = create_feature_aarch64_mte (tdesc.get (), regnum);
55*6881a400Schristos 
56*6881a400Schristos   /* TLS registers.  */
57*6881a400Schristos   if (features.tls > 0)
58*6881a400Schristos     regnum = create_feature_aarch64_tls (tdesc.get (), regnum, features.tls);
59*6881a400Schristos 
60*6881a400Schristos   return tdesc.release ();
61*6881a400Schristos }
62*6881a400Schristos 
63*6881a400Schristos /* See arch/aarch64.h.  */
64*6881a400Schristos 
65*6881a400Schristos CORE_ADDR
66*6881a400Schristos aarch64_remove_top_bits (CORE_ADDR pointer, CORE_ADDR mask)
67*6881a400Schristos {
68*6881a400Schristos   /* The VA range select bit is 55.  This bit tells us if we have a
69*6881a400Schristos      kernel-space address or a user-space address.  */
70*6881a400Schristos   bool kernel_address = (pointer & VA_RANGE_SELECT_BIT_MASK) != 0;
71*6881a400Schristos 
72*6881a400Schristos   /* Remove the top non-address bits.  */
73*6881a400Schristos   pointer &= ~mask;
74*6881a400Schristos 
75*6881a400Schristos   /* Sign-extend if we have a kernel-space address.  */
76*6881a400Schristos   if (kernel_address)
77*6881a400Schristos     pointer |= mask;
78*6881a400Schristos 
79*6881a400Schristos   return pointer;
80*6881a400Schristos }
81*6881a400Schristos 
82*6881a400Schristos /* See arch/aarch64.h.  */
83*6881a400Schristos 
84*6881a400Schristos CORE_ADDR
85*6881a400Schristos aarch64_mask_from_pac_registers (const CORE_ADDR cmask, const CORE_ADDR dmask)
86*6881a400Schristos {
87*6881a400Schristos   /* If the masks differ, default to using the one with the most coverage.  */
88*6881a400Schristos   if (dmask != cmask)
89*6881a400Schristos     return dmask > cmask ? dmask : cmask;
90*6881a400Schristos 
91*6881a400Schristos   return cmask;
927f2ac410Schristos }
93