xref: /netbsd-src/external/gpl3/gdb/dist/gdbserver/linux-ia64-low.cc (revision 2be465b09aca4bf6e67814eb0e0f409087138d90)
18dffb485Schristos /* GNU/Linux/IA64 specific low level interface, for the remote server for GDB.
2*2be465b0Schristos    Copyright (C) 1995-2024 Free Software Foundation, Inc.
38dffb485Schristos 
48dffb485Schristos    This file is part of GDB.
58dffb485Schristos 
68dffb485Schristos    This program is free software; you can redistribute it and/or modify
78dffb485Schristos    it under the terms of the GNU General Public License as published by
88dffb485Schristos    the Free Software Foundation; either version 3 of the License, or
98dffb485Schristos    (at your option) any later version.
108dffb485Schristos 
118dffb485Schristos    This program is distributed in the hope that it will be useful,
128dffb485Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
138dffb485Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
148dffb485Schristos    GNU General Public License for more details.
158dffb485Schristos 
168dffb485Schristos    You should have received a copy of the GNU General Public License
178dffb485Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
188dffb485Schristos 
198dffb485Schristos #include "linux-low.h"
208dffb485Schristos 
218dffb485Schristos #ifdef HAVE_SYS_REG_H
228dffb485Schristos #include <sys/reg.h>
238dffb485Schristos #endif
248dffb485Schristos 
258dffb485Schristos /* Linux target op definitions for the IA64 architecture.  */
268dffb485Schristos 
278dffb485Schristos class ia64_target : public linux_process_target
288dffb485Schristos {
298dffb485Schristos public:
308dffb485Schristos 
318dffb485Schristos   const regs_info *get_regs_info () override;
328dffb485Schristos 
338dffb485Schristos   const gdb_byte *sw_breakpoint_from_kind (int kind, int *size) override;
348dffb485Schristos 
358dffb485Schristos protected:
368dffb485Schristos 
378dffb485Schristos   void low_arch_setup () override;
388dffb485Schristos 
398dffb485Schristos   bool low_cannot_fetch_register (int regno) override;
408dffb485Schristos 
418dffb485Schristos   bool low_cannot_store_register (int regno) override;
428dffb485Schristos 
438dffb485Schristos   bool low_fetch_register (regcache *regcache, int regno) override;
448dffb485Schristos 
458dffb485Schristos   bool low_breakpoint_at (CORE_ADDR pc) override;
468dffb485Schristos };
478dffb485Schristos 
488dffb485Schristos /* The singleton target ops object.  */
498dffb485Schristos 
508dffb485Schristos static ia64_target the_ia64_target;
518dffb485Schristos 
528dffb485Schristos const gdb_byte *
538dffb485Schristos ia64_target::sw_breakpoint_from_kind (int kind, int *size)
548dffb485Schristos {
558dffb485Schristos   gdb_assert_not_reached ("target op sw_breakpoint_from_kind is not "
568dffb485Schristos 			  "implemented by this target");
578dffb485Schristos }
588dffb485Schristos 
598dffb485Schristos bool
608dffb485Schristos ia64_target::low_breakpoint_at (CORE_ADDR pc)
618dffb485Schristos {
628dffb485Schristos   gdb_assert_not_reached ("linux target op low_breakpoint_at is not "
638dffb485Schristos 			  "implemented by this target");
648dffb485Schristos }
658dffb485Schristos 
668dffb485Schristos /* Defined in auto-generated file reg-ia64.c.  */
678dffb485Schristos void init_registers_ia64 (void);
688dffb485Schristos extern const struct target_desc *tdesc_ia64;
698dffb485Schristos 
708dffb485Schristos #define ia64_num_regs 462
718dffb485Schristos 
728dffb485Schristos #include <asm/ptrace_offsets.h>
738dffb485Schristos 
748dffb485Schristos static int ia64_regmap[] =
758dffb485Schristos   {
768dffb485Schristos     /* general registers */
778dffb485Schristos     -1,		/* gr0 not available; i.e, it's always zero */
788dffb485Schristos     PT_R1,
798dffb485Schristos     PT_R2,
808dffb485Schristos     PT_R3,
818dffb485Schristos     PT_R4,
828dffb485Schristos     PT_R5,
838dffb485Schristos     PT_R6,
848dffb485Schristos     PT_R7,
858dffb485Schristos     PT_R8,
868dffb485Schristos     PT_R9,
878dffb485Schristos     PT_R10,
888dffb485Schristos     PT_R11,
898dffb485Schristos     PT_R12,
908dffb485Schristos     PT_R13,
918dffb485Schristos     PT_R14,
928dffb485Schristos     PT_R15,
938dffb485Schristos     PT_R16,
948dffb485Schristos     PT_R17,
958dffb485Schristos     PT_R18,
968dffb485Schristos     PT_R19,
978dffb485Schristos     PT_R20,
988dffb485Schristos     PT_R21,
998dffb485Schristos     PT_R22,
1008dffb485Schristos     PT_R23,
1018dffb485Schristos     PT_R24,
1028dffb485Schristos     PT_R25,
1038dffb485Schristos     PT_R26,
1048dffb485Schristos     PT_R27,
1058dffb485Schristos     PT_R28,
1068dffb485Schristos     PT_R29,
1078dffb485Schristos     PT_R30,
1088dffb485Schristos     PT_R31,
1098dffb485Schristos     /* gr32 through gr127 not directly available via the ptrace interface */
1108dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1118dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1128dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1138dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1148dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1158dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1168dffb485Schristos     /* Floating point registers */
1178dffb485Schristos     -1, -1,	/* f0 and f1 not available (f0 is +0.0 and f1 is +1.0) */
1188dffb485Schristos     PT_F2,
1198dffb485Schristos     PT_F3,
1208dffb485Schristos     PT_F4,
1218dffb485Schristos     PT_F5,
1228dffb485Schristos     PT_F6,
1238dffb485Schristos     PT_F7,
1248dffb485Schristos     PT_F8,
1258dffb485Schristos     PT_F9,
1268dffb485Schristos     PT_F10,
1278dffb485Schristos     PT_F11,
1288dffb485Schristos     PT_F12,
1298dffb485Schristos     PT_F13,
1308dffb485Schristos     PT_F14,
1318dffb485Schristos     PT_F15,
1328dffb485Schristos     PT_F16,
1338dffb485Schristos     PT_F17,
1348dffb485Schristos     PT_F18,
1358dffb485Schristos     PT_F19,
1368dffb485Schristos     PT_F20,
1378dffb485Schristos     PT_F21,
1388dffb485Schristos     PT_F22,
1398dffb485Schristos     PT_F23,
1408dffb485Schristos     PT_F24,
1418dffb485Schristos     PT_F25,
1428dffb485Schristos     PT_F26,
1438dffb485Schristos     PT_F27,
1448dffb485Schristos     PT_F28,
1458dffb485Schristos     PT_F29,
1468dffb485Schristos     PT_F30,
1478dffb485Schristos     PT_F31,
1488dffb485Schristos     PT_F32,
1498dffb485Schristos     PT_F33,
1508dffb485Schristos     PT_F34,
1518dffb485Schristos     PT_F35,
1528dffb485Schristos     PT_F36,
1538dffb485Schristos     PT_F37,
1548dffb485Schristos     PT_F38,
1558dffb485Schristos     PT_F39,
1568dffb485Schristos     PT_F40,
1578dffb485Schristos     PT_F41,
1588dffb485Schristos     PT_F42,
1598dffb485Schristos     PT_F43,
1608dffb485Schristos     PT_F44,
1618dffb485Schristos     PT_F45,
1628dffb485Schristos     PT_F46,
1638dffb485Schristos     PT_F47,
1648dffb485Schristos     PT_F48,
1658dffb485Schristos     PT_F49,
1668dffb485Schristos     PT_F50,
1678dffb485Schristos     PT_F51,
1688dffb485Schristos     PT_F52,
1698dffb485Schristos     PT_F53,
1708dffb485Schristos     PT_F54,
1718dffb485Schristos     PT_F55,
1728dffb485Schristos     PT_F56,
1738dffb485Schristos     PT_F57,
1748dffb485Schristos     PT_F58,
1758dffb485Schristos     PT_F59,
1768dffb485Schristos     PT_F60,
1778dffb485Schristos     PT_F61,
1788dffb485Schristos     PT_F62,
1798dffb485Schristos     PT_F63,
1808dffb485Schristos     PT_F64,
1818dffb485Schristos     PT_F65,
1828dffb485Schristos     PT_F66,
1838dffb485Schristos     PT_F67,
1848dffb485Schristos     PT_F68,
1858dffb485Schristos     PT_F69,
1868dffb485Schristos     PT_F70,
1878dffb485Schristos     PT_F71,
1888dffb485Schristos     PT_F72,
1898dffb485Schristos     PT_F73,
1908dffb485Schristos     PT_F74,
1918dffb485Schristos     PT_F75,
1928dffb485Schristos     PT_F76,
1938dffb485Schristos     PT_F77,
1948dffb485Schristos     PT_F78,
1958dffb485Schristos     PT_F79,
1968dffb485Schristos     PT_F80,
1978dffb485Schristos     PT_F81,
1988dffb485Schristos     PT_F82,
1998dffb485Schristos     PT_F83,
2008dffb485Schristos     PT_F84,
2018dffb485Schristos     PT_F85,
2028dffb485Schristos     PT_F86,
2038dffb485Schristos     PT_F87,
2048dffb485Schristos     PT_F88,
2058dffb485Schristos     PT_F89,
2068dffb485Schristos     PT_F90,
2078dffb485Schristos     PT_F91,
2088dffb485Schristos     PT_F92,
2098dffb485Schristos     PT_F93,
2108dffb485Schristos     PT_F94,
2118dffb485Schristos     PT_F95,
2128dffb485Schristos     PT_F96,
2138dffb485Schristos     PT_F97,
2148dffb485Schristos     PT_F98,
2158dffb485Schristos     PT_F99,
2168dffb485Schristos     PT_F100,
2178dffb485Schristos     PT_F101,
2188dffb485Schristos     PT_F102,
2198dffb485Schristos     PT_F103,
2208dffb485Schristos     PT_F104,
2218dffb485Schristos     PT_F105,
2228dffb485Schristos     PT_F106,
2238dffb485Schristos     PT_F107,
2248dffb485Schristos     PT_F108,
2258dffb485Schristos     PT_F109,
2268dffb485Schristos     PT_F110,
2278dffb485Schristos     PT_F111,
2288dffb485Schristos     PT_F112,
2298dffb485Schristos     PT_F113,
2308dffb485Schristos     PT_F114,
2318dffb485Schristos     PT_F115,
2328dffb485Schristos     PT_F116,
2338dffb485Schristos     PT_F117,
2348dffb485Schristos     PT_F118,
2358dffb485Schristos     PT_F119,
2368dffb485Schristos     PT_F120,
2378dffb485Schristos     PT_F121,
2388dffb485Schristos     PT_F122,
2398dffb485Schristos     PT_F123,
2408dffb485Schristos     PT_F124,
2418dffb485Schristos     PT_F125,
2428dffb485Schristos     PT_F126,
2438dffb485Schristos     PT_F127,
2448dffb485Schristos     /* predicate registers - we don't fetch these individually */
2458dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1,
2468dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1,
2478dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1,
2488dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1,
2498dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1,
2508dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1,
2518dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1,
2528dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1,
2538dffb485Schristos     /* branch registers */
2548dffb485Schristos     PT_B0,
2558dffb485Schristos     PT_B1,
2568dffb485Schristos     PT_B2,
2578dffb485Schristos     PT_B3,
2588dffb485Schristos     PT_B4,
2598dffb485Schristos     PT_B5,
2608dffb485Schristos     PT_B6,
2618dffb485Schristos     PT_B7,
2628dffb485Schristos     /* virtual frame pointer and virtual return address pointer */
2638dffb485Schristos     -1, -1,
2648dffb485Schristos     /* other registers */
2658dffb485Schristos     PT_PR,
2668dffb485Schristos     PT_CR_IIP,	/* ip */
2678dffb485Schristos     PT_CR_IPSR, /* psr */
2688dffb485Schristos     PT_CFM,	/* cfm */
2698dffb485Schristos     /* kernel registers not visible via ptrace interface (?) */
2708dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1,
2718dffb485Schristos     /* hole */
2728dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1,
2738dffb485Schristos     PT_AR_RSC,
2748dffb485Schristos     PT_AR_BSP,
2758dffb485Schristos     PT_AR_BSPSTORE,
2768dffb485Schristos     PT_AR_RNAT,
2778dffb485Schristos     -1,
2788dffb485Schristos     -1,		/* Not available: FCR, IA32 floating control register */
2798dffb485Schristos     -1, -1,
2808dffb485Schristos     -1,		/* Not available: EFLAG */
2818dffb485Schristos     -1,		/* Not available: CSD */
2828dffb485Schristos     -1,		/* Not available: SSD */
2838dffb485Schristos     -1,		/* Not available: CFLG */
2848dffb485Schristos     -1,		/* Not available: FSR */
2858dffb485Schristos     -1,		/* Not available: FIR */
2868dffb485Schristos     -1,		/* Not available: FDR */
2878dffb485Schristos     -1,
2888dffb485Schristos     PT_AR_CCV,
2898dffb485Schristos     -1, -1, -1,
2908dffb485Schristos     PT_AR_UNAT,
2918dffb485Schristos     -1, -1, -1,
2928dffb485Schristos     PT_AR_FPSR,
2938dffb485Schristos     -1, -1, -1,
2948dffb485Schristos     -1,		/* Not available: ITC */
2958dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2968dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1,
2978dffb485Schristos     PT_AR_PFS,
2988dffb485Schristos     PT_AR_LC,
2998dffb485Schristos     PT_AR_EC,
3008dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3018dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3028dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3038dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3048dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3058dffb485Schristos     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3068dffb485Schristos     -1,
3078dffb485Schristos   };
3088dffb485Schristos 
3098dffb485Schristos bool
3108dffb485Schristos ia64_target::low_cannot_store_register (int regno)
3118dffb485Schristos {
3128dffb485Schristos   return false;
3138dffb485Schristos }
3148dffb485Schristos 
3158dffb485Schristos bool
3168dffb485Schristos ia64_target::low_cannot_fetch_register (int regno)
3178dffb485Schristos {
3188dffb485Schristos   return false;
3198dffb485Schristos }
3208dffb485Schristos 
3218dffb485Schristos /* GDB register numbers.  */
3228dffb485Schristos #define IA64_GR0_REGNUM		0
3238dffb485Schristos #define IA64_FR0_REGNUM		128
3248dffb485Schristos #define IA64_FR1_REGNUM		129
3258dffb485Schristos 
3268dffb485Schristos bool
3278dffb485Schristos ia64_target::low_fetch_register (regcache *regcache, int regnum)
3288dffb485Schristos {
3298dffb485Schristos   /* r0 cannot be fetched but is always zero.  */
3308dffb485Schristos   if (regnum == IA64_GR0_REGNUM)
3318dffb485Schristos     {
3328dffb485Schristos       const gdb_byte zero[8] = { 0 };
3338dffb485Schristos 
3348dffb485Schristos       gdb_assert (sizeof (zero) == register_size (regcache->tdesc, regnum));
3358dffb485Schristos       supply_register (regcache, regnum, zero);
3368dffb485Schristos       return true;
3378dffb485Schristos     }
3388dffb485Schristos 
3398dffb485Schristos   /* fr0 cannot be fetched but is always zero.  */
3408dffb485Schristos   if (regnum == IA64_FR0_REGNUM)
3418dffb485Schristos     {
3428dffb485Schristos       const gdb_byte f_zero[16] = { 0 };
3438dffb485Schristos 
3448dffb485Schristos       gdb_assert (sizeof (f_zero) == register_size (regcache->tdesc, regnum));
3458dffb485Schristos       supply_register (regcache, regnum, f_zero);
3468dffb485Schristos       return true;
3478dffb485Schristos     }
3488dffb485Schristos 
3498dffb485Schristos   /* fr1 cannot be fetched but is always one (1.0).  */
3508dffb485Schristos   if (regnum == IA64_FR1_REGNUM)
3518dffb485Schristos     {
3528dffb485Schristos       const gdb_byte f_one[16] =
3538dffb485Schristos 	{ 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0xff, 0, 0, 0, 0, 0, 0 };
3548dffb485Schristos 
3558dffb485Schristos       gdb_assert (sizeof (f_one) == register_size (regcache->tdesc, regnum));
3568dffb485Schristos       supply_register (regcache, regnum, f_one);
3578dffb485Schristos       return true;
3588dffb485Schristos     }
3598dffb485Schristos 
3608dffb485Schristos   return false;
3618dffb485Schristos }
3628dffb485Schristos 
3638dffb485Schristos static struct usrregs_info ia64_usrregs_info =
3648dffb485Schristos   {
3658dffb485Schristos     ia64_num_regs,
3668dffb485Schristos     ia64_regmap,
3678dffb485Schristos   };
3688dffb485Schristos 
3698dffb485Schristos static struct regs_info myregs_info =
3708dffb485Schristos   {
3718dffb485Schristos     NULL, /* regset_bitmap */
3728dffb485Schristos     &ia64_usrregs_info
3738dffb485Schristos   };
3748dffb485Schristos 
3758dffb485Schristos const regs_info *
3768dffb485Schristos ia64_target::get_regs_info ()
3778dffb485Schristos {
3788dffb485Schristos   return &myregs_info;
3798dffb485Schristos }
3808dffb485Schristos 
3818dffb485Schristos void
3828dffb485Schristos ia64_target::low_arch_setup ()
3838dffb485Schristos {
3848dffb485Schristos   current_process ()->tdesc = tdesc_ia64;
3858dffb485Schristos }
3868dffb485Schristos 
3878dffb485Schristos /* The linux target ops object.  */
3888dffb485Schristos 
3898dffb485Schristos linux_process_target *the_linux_target = &the_ia64_target;
3908dffb485Schristos 
3918dffb485Schristos void
3928dffb485Schristos initialize_low_arch (void)
3938dffb485Schristos {
3948dffb485Schristos   init_registers_ia64 ();
3958dffb485Schristos }
396