riscv.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Common target-dependent functionality for RISC-V
  2. Copyright (C) 2018-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. #ifndef ARCH_RISCV_H
  15. #define ARCH_RISCV_H
  16. #include "gdbsupport/tdesc.h"
  17. /* The set of RISC-V architectural features that we track that impact how
  18. we configure the actual gdbarch instance. We hold one of these in the
  19. gdbarch_tdep structure, and use it to distinguish between different
  20. RISC-V gdbarch instances.
  21. The information in here ideally comes from the target description,
  22. however, if the target doesn't provide a target description then we will
  23. create a default target description by first populating one of these
  24. based on what we know about the binary being executed, and using that to
  25. drive default target description creation. */
  26. struct riscv_gdbarch_features
  27. {
  28. /* The size of the x-registers in bytes. This is either 4 (RV32), 8
  29. (RV64), or 16 (RV128). No other value is valid. Initialise to the
  30. invalid 0 value so we can spot if one of these is used
  31. uninitialised. */
  32. int xlen = 0;
  33. /* The size of the f-registers in bytes. This is either 4 (RV32), 8
  34. (RV64), or 16 (RV128). This can also hold the value 0 to indicate
  35. that there are no f-registers. No other value is valid. */
  36. int flen = 0;
  37. /* The size of the v-registers in bytes. The value 0 indicates a target
  38. with no vector registers. The minimum value for a standard compliant
  39. target should be 16, but GDB doesn't currently mind, and will accept
  40. any vector size. */
  41. int vlen = 0;
  42. /* When true this target is RV32E. */
  43. bool embedded = false;
  44. /* Equality operator. */
  45. bool operator== (const struct riscv_gdbarch_features &rhs) const
  46. {
  47. return (xlen == rhs.xlen && flen == rhs.flen
  48. && embedded == rhs.embedded && vlen == rhs.vlen);
  49. }
  50. /* Inequality operator. */
  51. bool operator!= (const struct riscv_gdbarch_features &rhs) const
  52. {
  53. return !((*this) == rhs);
  54. }
  55. /* Used by std::unordered_map to hash feature sets. */
  56. std::size_t hash () const noexcept
  57. {
  58. std::size_t val = ((embedded ? 1 : 0) << 10
  59. | (xlen & 0x1f) << 5
  60. | (flen & 0x1f) << 0
  61. | (vlen & 0xfff) << 11);
  62. return val;
  63. }
  64. };
  65. #ifdef GDBSERVER
  66. /* Create and return a target description that is compatible with FEATURES.
  67. This is only used directly from the gdbserver where the created target
  68. description is modified after it is return. */
  69. target_desc_up riscv_create_target_description
  70. (const struct riscv_gdbarch_features features);
  71. #else
  72. /* Lookup an already existing target description matching FEATURES, or
  73. create a new target description if this is the first time we have seen
  74. FEATURES. For the same FEATURES the same target_desc is always
  75. returned. This is important when trying to lookup gdbarch objects as
  76. GDBARCH_LIST_LOOKUP_BY_INFO performs a pointer comparison on target
  77. descriptions to find candidate gdbarch objects. */
  78. const target_desc *riscv_lookup_target_description
  79. (const struct riscv_gdbarch_features features);
  80. #endif /* GDBSERVER */
  81. #endif /* ARCH_RISCV_H */