xtensa-tdep.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* Target-dependent code for the Xtensa port of GDB, the GNU debugger.
  2. Copyright (C) 2003-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 XTENSA_TDEP_H
  15. #define XTENSA_TDEP_H
  16. #include "arch/xtensa.h"
  17. #include "gdbarch.h"
  18. #include "xtensa-config.h"
  19. /* XTENSA_TDEP_VERSION can/should be changed along with XTENSA_CONFIG_VERSION
  20. whenever the "tdep" structure changes in an incompatible way. */
  21. #define XTENSA_TDEP_VERSION 0x60
  22. /* Xtensa register type. */
  23. typedef enum
  24. {
  25. xtRegisterTypeArRegfile = 1, /* Register File ar0..arXX. */
  26. xtRegisterTypeSpecialReg, /* CPU states, such as PS, Booleans, (rsr). */
  27. xtRegisterTypeUserReg, /* User defined registers (rur). */
  28. xtRegisterTypeTieRegfile, /* User define register files. */
  29. xtRegisterTypeTieState, /* TIE States (mapped on user regs). */
  30. xtRegisterTypeMapped, /* Mapped on Special Registers. */
  31. xtRegisterTypeUnmapped, /* Special case of masked registers. */
  32. xtRegisterTypeWindow, /* Live window registers (a0..a15). */
  33. xtRegisterTypeVirtual, /* PC, FP. */
  34. xtRegisterTypeUnknown
  35. } xtensa_register_type_t;
  36. /* Xtensa register group. */
  37. #define XTENSA_MAX_COPROCESSOR 0x10 /* Number of Xtensa coprocessors. */
  38. typedef enum
  39. {
  40. xtRegisterGroupUnknown = 0,
  41. xtRegisterGroupRegFile = 0x0001, /* Register files without ARx. */
  42. xtRegisterGroupAddrReg = 0x0002, /* ARx. */
  43. xtRegisterGroupSpecialReg = 0x0004, /* SRxx. */
  44. xtRegisterGroupUserReg = 0x0008, /* URxx. */
  45. xtRegisterGroupState = 0x0010, /* States. */
  46. xtRegisterGroupGeneral = 0x0100, /* General registers, Ax, SR. */
  47. xtRegisterGroupUser = 0x0200, /* User registers. */
  48. xtRegisterGroupFloat = 0x0400, /* Floating Point. */
  49. xtRegisterGroupVectra = 0x0800, /* Vectra. */
  50. xtRegisterGroupSystem = 0x1000, /* System. */
  51. xtRegisterGroupNCP = 0x00800000, /* Non-CP non-base opt/custom. */
  52. xtRegisterGroupCP0 = 0x01000000, /* CP0. */
  53. xtRegisterGroupCP1 = 0x02000000, /* CP1. */
  54. xtRegisterGroupCP2 = 0x04000000, /* CP2. */
  55. xtRegisterGroupCP3 = 0x08000000, /* CP3. */
  56. xtRegisterGroupCP4 = 0x10000000, /* CP4. */
  57. xtRegisterGroupCP5 = 0x20000000, /* CP5. */
  58. xtRegisterGroupCP6 = 0x40000000, /* CP6. */
  59. xtRegisterGroupCP7 = 0x80000000, /* CP7. */
  60. } xtensa_register_group_t;
  61. /* Xtensa target flags. */
  62. typedef enum
  63. {
  64. xtTargetFlagsNonVisibleRegs = 0x0001,
  65. xtTargetFlagsUseFetchStore = 0x0002,
  66. } xtensa_target_flags_t;
  67. /* Mask. */
  68. typedef struct
  69. {
  70. int reg_num;
  71. int bit_start;
  72. int bit_size;
  73. } xtensa_reg_mask_t;
  74. typedef struct
  75. {
  76. int count;
  77. xtensa_reg_mask_t *mask;
  78. } xtensa_mask_t;
  79. /* Xtensa register representation. */
  80. typedef struct
  81. {
  82. const char *name; /* Register name. */
  83. int offset; /* Offset. */
  84. xtensa_register_type_t type; /* Register type. */
  85. xtensa_register_group_t group;/* Register group. */
  86. struct type* ctype; /* C-type. */
  87. int bit_size; /* The actual bit size in the target. */
  88. int byte_size; /* Actual space allocated in registers[]. */
  89. int align; /* Alignment for this register. */
  90. unsigned int target_number; /* Register target number. */
  91. int flags; /* Flags. */
  92. int coprocessor; /* Coprocessor num, -1 for non-CP, else -2. */
  93. const xtensa_mask_t *mask; /* Register is a compilation of other regs. */
  94. const char *fetch; /* Instruction sequence to fetch register. */
  95. const char *store; /* Instruction sequence to store register. */
  96. } xtensa_register_t;
  97. /* For xtensa-config.c to expand to the structure above. */
  98. #define XTREG(index,ofs,bsz,sz,al,tnum,flg,cp,ty,gr,name,fet,sto,mas,ct,x,y) \
  99. {#name, ofs, (xtensa_register_type_t) (ty), \
  100. ((xtensa_register_group_t) \
  101. ((gr) | ((xtRegisterGroupNCP >> 2) << (cp + 2)))), \
  102. ct, bsz, sz, al, tnum, flg, cp, mas, fet, sto},
  103. #define XTREG_END \
  104. {0, 0, (xtensa_register_type_t) 0, (xtensa_register_group_t) 0, \
  105. 0, 0, 0, 0, (unsigned) -1, 0, 0, 0, 0, 0},
  106. #define XTENSA_REGISTER_FLAGS_PRIVILEGED 0x0001
  107. #define XTENSA_REGISTER_FLAGS_READABLE 0x0002
  108. #define XTENSA_REGISTER_FLAGS_WRITABLE 0x0004
  109. #define XTENSA_REGISTER_FLAGS_VOLATILE 0x0008
  110. /* Call-ABI for stack frame. */
  111. typedef enum
  112. {
  113. CallAbiDefault = 0, /* Any 'callX' instructions; default stack. */
  114. CallAbiCall0Only, /* Only 'call0' instructions; flat stack. */
  115. } call_abi_t;
  116. struct ctype_cache
  117. {
  118. struct ctype_cache *next;
  119. int size;
  120. struct type *virtual_type;
  121. };
  122. #ifndef XCHAL_NUM_CONTEXTS
  123. # define XCHAL_NUM_CONTEXTS 0
  124. #endif
  125. #ifndef XCHAL_HAVE_EXCEPTIONS
  126. # define XCHAL_HAVE_EXCEPTIONS 1
  127. #endif
  128. /* Xtensa-specific target dependencies. */
  129. struct xtensa_gdbarch_tdep : gdbarch_tdep
  130. {
  131. xtensa_gdbarch_tdep (xtensa_register_t *regmap)
  132. : regmap (regmap)
  133. {}
  134. unsigned int target_flags = 0;
  135. /* Spill location for TIE register files under ocd. */
  136. unsigned int spill_location = (unsigned int) -1;
  137. unsigned int spill_size = 0;
  138. char *unused = nullptr; /* Placeholder for compatibility. */
  139. /* Calling convention. */
  140. call_abi_t call_abi = (XSHAL_ABI == XTHAL_ABI_CALL0
  141. ? CallAbiCall0Only : CallAbiDefault);
  142. /* CPU configuration. */
  143. unsigned int debug_interrupt_level = XCHAL_DEBUGLEVEL;
  144. unsigned int icache_line_bytes = XCHAL_ICACHE_LINESIZE;
  145. unsigned int dcache_line_bytes = XCHAL_DCACHE_LINESIZE;
  146. unsigned int dcache_writeback = XCHAL_DCACHE_IS_WRITEBACK;
  147. unsigned int isa_use_windowed_registers = XSHAL_ABI != XTHAL_ABI_CALL0;
  148. unsigned int isa_use_density_instructions = XCHAL_HAVE_DENSITY;
  149. unsigned int isa_use_exceptions = XCHAL_HAVE_EXCEPTIONS;
  150. unsigned int isa_use_ext_l32r = XSHAL_USE_ABSOLUTE_LITERALS;
  151. unsigned int isa_max_insn_size = XCHAL_MAX_INSTRUCTION_SIZE; /* Maximum instruction length. */
  152. unsigned int debug_num_ibreaks = XCHAL_NUM_IBREAK; /* Number of IBREAKs. */
  153. unsigned int debug_num_dbreaks = XCHAL_NUM_DBREAK;
  154. /* Register map. */
  155. xtensa_register_t *regmap;
  156. unsigned int num_regs = 0; /* Number of registers in register map. */
  157. unsigned int num_nopriv_regs = 0; /* Number of non-privileged registers. */
  158. unsigned int num_pseudo_regs = 0; /* Number of pseudo registers. */
  159. unsigned int num_aregs = XCHAL_NUM_AREGS; /* Size of register file. */
  160. unsigned int num_contexts = XCHAL_NUM_CONTEXTS;
  161. int ar_base = -1; /* Register number for AR0. */
  162. int a0_base = -1; /* Register number for A0 (pseudo). */
  163. int wb_regnum = -1; /* Register number for WB. */
  164. int ws_regnum = -1; /* Register number for WS. */
  165. int pc_regnum = -1; /* Register number for PC. */
  166. int ps_regnum = -1; /* Register number for PS. */
  167. int lbeg_regnum = -1; /* Register numbers for count regs. */
  168. int lend_regnum = -1;
  169. int lcount_regnum = -1;
  170. int sar_regnum = -1; /* Register number of SAR. */
  171. int litbase_regnum = -1; /* Register number of LITBASE. */
  172. int threadptr_regnum = -1; /* Register number of THREADPTR. */
  173. int interrupt_regnum = -1; /* Register number for interrupt. */
  174. int interrupt2_regnum = -1; /* Register number for interrupt2. */
  175. int cpenable_regnum = -1; /* Register number for cpenable. */
  176. int debugcause_regnum = -1; /* Register number for debugcause. */
  177. int exccause_regnum = -1; /* Register number for exccause. */
  178. int excvaddr_regnum = -1; /* Register number for excvaddr. */
  179. int max_register_raw_size = 0;
  180. int max_register_virtual_size = 0;
  181. unsigned long *fp_layout = nullptr; /* Layout of custom/TIE regs in 'FP' area. */
  182. unsigned int fp_layout_bytes = 0; /* Size of layout information (in bytes). */
  183. unsigned long *gregmap = nullptr;
  184. /* Cached register types. */
  185. struct ctype_cache *type_entries = nullptr;
  186. };
  187. #define WB_SHIFT 2
  188. /* We assign fixed numbers to the registers of the "current" window
  189. (i.e., relative to WB). The registers get remapped via the reg_map
  190. data structure to their corresponding register in the AR register
  191. file (see xtensa-tdep.c). */
  192. #endif /* XTENSA_TDEP_H */