arm-bsd-tdep.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Target-dependent code for ARM BSD's.
  2. Copyright (C) 2006-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "osabi.h"
  16. #include "regcache.h"
  17. #include "regset.h"
  18. #include "arm-tdep.h"
  19. /* Core file support. */
  20. /* Sizeof `struct reg' in <machine/reg.h>. */
  21. #define ARMBSD_SIZEOF_GREGS (17 * 4)
  22. /* Sizeof `struct fpreg' in <machine/reg.h. */
  23. #define ARMBSD_SIZEOF_FPREGS ((1 + (8 * 3)) * 4)
  24. static int
  25. armbsd_fpreg_offset (int regnum)
  26. {
  27. if (regnum == ARM_FPS_REGNUM)
  28. return 0;
  29. return 4 + (regnum - ARM_F0_REGNUM) * 12;
  30. }
  31. /* Supply register REGNUM from the buffer specified by FPREGS and LEN
  32. in the floating-point register set REGSET to register cache
  33. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  34. static void
  35. armbsd_supply_fpregset (const struct regset *regset,
  36. struct regcache *regcache,
  37. int regnum, const void *fpregs, size_t len)
  38. {
  39. const gdb_byte *regs = (const gdb_byte *) fpregs;
  40. int i;
  41. gdb_assert (len >= ARMBSD_SIZEOF_FPREGS);
  42. for (i = ARM_F0_REGNUM; i <= ARM_FPS_REGNUM; i++)
  43. {
  44. if (regnum == i || regnum == -1)
  45. regcache->raw_supply (i, regs + armbsd_fpreg_offset (i));
  46. }
  47. }
  48. /* Supply register REGNUM from the buffer specified by GREGS and LEN
  49. in the general-purpose register set REGSET to register cache
  50. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  51. static void
  52. armbsd_supply_gregset (const struct regset *regset,
  53. struct regcache *regcache,
  54. int regnum, const void *gregs, size_t len)
  55. {
  56. const gdb_byte *regs = (const gdb_byte *) gregs;
  57. int i;
  58. gdb_assert (len >= ARMBSD_SIZEOF_GREGS);
  59. for (i = ARM_A1_REGNUM; i <= ARM_PC_REGNUM; i++)
  60. {
  61. if (regnum == i || regnum == -1)
  62. regcache->raw_supply (i, regs + i * 4);
  63. }
  64. if (regnum == ARM_PS_REGNUM || regnum == -1)
  65. regcache->raw_supply (i, regs + 16 * 4);
  66. if (len >= ARMBSD_SIZEOF_GREGS + ARMBSD_SIZEOF_FPREGS)
  67. {
  68. regs += ARMBSD_SIZEOF_GREGS;
  69. len -= ARMBSD_SIZEOF_GREGS;
  70. armbsd_supply_fpregset (regset, regcache, regnum, regs, len);
  71. }
  72. }
  73. /* ARM register sets. */
  74. static const struct regset armbsd_gregset =
  75. {
  76. NULL,
  77. armbsd_supply_gregset,
  78. NULL,
  79. REGSET_VARIABLE_SIZE
  80. };
  81. static const struct regset armbsd_fpregset =
  82. {
  83. NULL,
  84. armbsd_supply_fpregset
  85. };
  86. /* Iterate over supported core file register note sections. */
  87. void
  88. armbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
  89. iterate_over_regset_sections_cb *cb,
  90. void *cb_data,
  91. const struct regcache *regcache)
  92. {
  93. cb (".reg", ARMBSD_SIZEOF_GREGS, ARMBSD_SIZEOF_GREGS, &armbsd_gregset, NULL,
  94. cb_data);
  95. cb (".reg2", ARMBSD_SIZEOF_FPREGS, ARMBSD_SIZEOF_FPREGS, &armbsd_fpregset,
  96. NULL, cb_data);
  97. }