csky-tdep.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /* Target-dependent code for the CSKY architecture, for GDB.
  2. Copyright (C) 2010-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 CSKY_TDEP_H
  15. #define CSKY_TDEP_H
  16. #include "gdbarch.h"
  17. /* How to interpret the contents of the link register. */
  18. enum lr_type_t
  19. {
  20. LR_TYPE_R15,
  21. LR_TYPE_EPC,
  22. LR_TYPE_FPC
  23. };
  24. /* Target-dependent structure in gdbarch. */
  25. struct csky_gdbarch_tdep : gdbarch_tdep
  26. {
  27. /* This is Unused. */
  28. };
  29. /* Instruction sizes. */
  30. enum csky_insn_size_t
  31. {
  32. CSKY_INSN_SIZE16 = 2,
  33. CSKY_INSN_SIZE32 = 4
  34. };
  35. /* CSKY register numbers. */
  36. enum csky_regnum
  37. {
  38. CSKY_R0_REGNUM = 0, /* General registers. */
  39. CSKY_R15_REGNUM = 15,
  40. CSKY_PC_REGNUM = 72,
  41. CSKY_HI_REGNUM = 20,
  42. CSKY_LO_REGNUM = 21,
  43. CSKY_CR0_REGNUM = 89,
  44. CSKY_VBR_REGNUM = CSKY_CR0_REGNUM + 1,
  45. CSKY_EPSR_REGNUM = CSKY_CR0_REGNUM + 2,
  46. CSKY_FPSR_REGNUM = CSKY_CR0_REGNUM + 3,
  47. CSKY_EPC_REGNUM = CSKY_CR0_REGNUM + 4,
  48. CSKY_FPC_REGNUM = CSKY_CR0_REGNUM + 5,
  49. /* Float register 0. */
  50. CSKY_FR0_REGNUM = 40,
  51. CSKY_VCR0_REGNUM = 121,
  52. CSKY_MMU_REGNUM = 128,
  53. CSKY_PROFCR_REGNUM = 140,
  54. CSKY_PROFGR_REGNUM = 144,
  55. CSKY_FP_REGNUM = 8,
  56. /* Vector register 0. */
  57. CSKY_VR0_REGNUM = 56,
  58. /* m32r calling convention. */
  59. CSKY_SP_REGNUM = CSKY_R0_REGNUM + 14,
  60. CSKY_RET_REGNUM = CSKY_R0_REGNUM,
  61. /* Argument registers. */
  62. CSKY_ABI_A0_REGNUM = 0,
  63. CSKY_ABI_LAST_ARG_REGNUM = 3,
  64. /* Link register, r15. */
  65. CSKY_LR_REGNUM = CSKY_R15_REGNUM,
  66. /* Processor status register, cr0. */
  67. CSKY_PSR_REGNUM = CSKY_CR0_REGNUM,
  68. CSKY_MAX_REGISTER_SIZE = 16,
  69. CSKY_MAX_REGS = 253
  70. };
  71. /* ICE registers. */
  72. #define CSKY_CRBANK_NUM_REGS 32
  73. /* Number of processor registers w/o ICE registers. */
  74. #define CSKY_NUM_REGS (CSKY_MAX_REGS - CSKY_CRBANK_NUM_REGS)
  75. /* size. */
  76. #define CSKY_16_ST_SIZE(insn) (1 << ((insn & 0x1800) >> 11))
  77. /* rx. */
  78. #define CSKY_16_ST_ADDR_REGNUM(insn) ((insn & 0x700) >> 8)
  79. /* disp. */
  80. #define CSKY_16_ST_OFFSET(insn) ((insn & 0x1f) << ((insn & 0x1800) >> 11))
  81. /* ry. */
  82. #define CSKY_16_ST_VAL_REGNUM(insn) ((insn & 0xe0) >> 5)
  83. /* st16.w rz, (sp, disp). */
  84. #define CSKY_16_IS_STWx0(insn) ((insn & 0xf800) == 0xb800)
  85. #define CSKY_16_STWx0_VAL_REGNUM(insn) CSKY_16_ST_ADDR_REGNUM (insn)
  86. /* disp. */
  87. #define CSKY_16_STWx0_OFFSET(insn) \
  88. ((((insn & 0x700) >> 3) + (insn & 0x1f)) << 2)
  89. /* Check ld16 but not ld16 sp. */
  90. #define CSKY_16_IS_LD(insn) \
  91. (((insn & 0xe000) == 0x8000) && (insn & 0x1800) != 0x1800)
  92. /* size. */
  93. #define CSKY_16_LD_SIZE(insn) CSKY_16_ST_SIZE (insn)
  94. /* rx. */
  95. #define CSKY_16_LD_ADDR_REGNUM(insn) CSKY_16_ST_ADDR_REGNUM (insn)
  96. /* disp. */
  97. #define CSKY_16_LD_OFFSET(insn) CSKY_16_ST_OFFSET (insn)
  98. /* ld16.w rz,(sp,disp). */
  99. #define CSKY_16_IS_LDWx0(insn) ((insn & 0xf800) == 0x9800)
  100. /*disp. */
  101. #define CSKY_16_LDWx0_OFFSET(insn) CSKY_16_STWx0_OFFSET (insn)
  102. /* st32.b/h/w/d. */
  103. #define CSKY_32_IS_ST(insn) ((insn & 0xfc00c000) == 0xdc000000)
  104. /* size: b/h/w/d. */
  105. #define CSKY_32_ST_SIZE(insn) (1 << ((insn & 0x3000) >> 12))
  106. /* rx. */
  107. #define CSKY_32_ST_ADDR_REGNUM(insn) ((insn & 0x001f0000) >> 16)
  108. /* disp. */
  109. #define CSKY_32_ST_OFFSET(insn) ((insn & 0xfff) << ((insn & 0x3000) >> 12))
  110. /* ry. */
  111. #define CSKY_32_ST_VAL_REGNUM(insn) ((insn & 0x03e00000) >> 21)
  112. /* stw ry, (sp, disp). */
  113. #define CSKY_32_IS_STWx0(insn) ((insn & 0xfc1ff000) == 0xdc0e2000)
  114. /* stm32 ry-rz, (rx). */
  115. #define CSKY_32_IS_STM(insn) ((insn & 0xfc00ffe0) == 0xd4001c20)
  116. /* rx. */
  117. #define CSKY_32_STM_ADDR_REGNUM(insn) CSKY_32_ST_ADDR_REGNUM (insn)
  118. /* Count of registers. */
  119. #define CSKY_32_STM_SIZE(insn) (insn & 0x1f)
  120. /* ry. */
  121. #define CSKY_32_STM_VAL_REGNUM(insn) ((insn & 0x03e00000) >> 21)
  122. /* stm32 ry-rz, (sp). */
  123. #define CSKY_32_IS_STMx0(insn) ((insn & 0xfc1fffe0) == 0xd40e1c20)
  124. /* str32.b/h/w rz, (rx, ry << offset). */
  125. #define CSKY_32_IS_STR(insn) \
  126. (((insn & 0xfc000000) == 0xd4000000) && !(CSKY_32_IS_STM (insn)))
  127. /* rx. */
  128. #define CSKY_32_STR_X_REGNUM(insn) CSKY_32_ST_ADDR_REGNUM (insn)
  129. /* ry. */
  130. #define CSKY_32_STR_Y_REGNUM(insn) ((insn >> 21) & 0x1f)
  131. /* size: b/h/w. */
  132. #define CSKY_32_STR_SIZE(insn) (1 << ((insn & 0x0c00) >> 10))
  133. /* imm (for rx + ry * imm). */
  134. #define CSKY_32_STR_OFFSET(insn) ((insn & 0x000003e0) >> 5)
  135. /* stex32.w rz, (rx, disp). */
  136. #define CSKY_32_IS_STEX(insn) ((insn & 0xfc00f000) == 0xdc007000)
  137. /* rx. */
  138. #define CSKY_32_STEX_ADDR_REGNUM(insn) ((insn & 0x1f0000) >> 16)
  139. /* disp. */
  140. #define CSKY_32_STEX_OFFSET(insn) ((insn & 0x0fff) << 2)
  141. /* ld.b/h/w. */
  142. #define CSKY_32_IS_LD(insn) ((insn & 0xfc00c000) == 0xd8000000)
  143. /* size. */
  144. #define CSKY_32_LD_SIZE(insn) CSKY_32_ST_SIZE (insn)
  145. /* rx. */
  146. #define CSKY_32_LD_ADDR_REGNUM(insn) CSKY_32_ST_ADDR_REGNUM (insn)
  147. /* disp. */
  148. #define CSKY_32_LD_OFFSET(insn) CSKY_32_ST_OFFSET (insn)
  149. #define CSKY_32_IS_LDM(insn) ((insn & 0xfc00ffe0) == 0xd0001c20)
  150. /* rx. */
  151. #define CSKY_32_LDM_ADDR_REGNUM(insn) CSKY_32_STM_ADDR_REGNUM (insn)
  152. /* Count of registers. */
  153. #define CSKY_32_LDM_SIZE(insn) CSKY_32_STM_SIZE (insn)
  154. /* ldr32.b/h/w rz, (rx, ry << offset). */
  155. #define CSKY_32_IS_LDR(insn) \
  156. (((insn & 0xfc00fe00) == 0xd0000000) && !(CSKY_32_IS_LDM (insn)))
  157. /* rx. */
  158. #define CSKY_32_LDR_X_REGNUM(insn) CSKY_32_STR_X_REGNUM (insn)
  159. /* ry. */
  160. #define CSKY_32_LDR_Y_REGNUM(insn) CSKY_32_STR_Y_REGNUM (insn)
  161. /* size: b/h/w. */
  162. #define CSKY_32_LDR_SIZE(insn) CSKY_32_STR_SIZE (insn)
  163. /* imm (for rx + ry*imm). */
  164. #define CSKY_32_LDR_OFFSET(insn) CSKY_32_STR_OFFSET (insn)
  165. #define CSKY_32_IS_LDEX(insn) ((insn & 0xfc00f000) == 0xd8007000)
  166. /* rx. */
  167. #define CSKY_32_LDEX_ADDR_REGNUM(insn) CSKY_32_STEX_ADDR_REGNUM (insn)
  168. /* disp. */
  169. #define CSKY_32_LDEX_OFFSET(insn) CSKY_32_STEX_OFFSET (insn)
  170. /* subi.sp sp, disp. */
  171. #define CSKY_16_IS_SUBI0(insn) ((insn & 0xfce0) == 0x1420)
  172. /* disp. */
  173. #define CSKY_16_SUBI_IMM(insn) ((((insn & 0x300) >> 3) + (insn & 0x1f)) << 2)
  174. /* subi32 sp,sp,oimm12. */
  175. #define CSKY_32_IS_SUBI0(insn) ((insn & 0xfffff000) == 0xe5ce1000)
  176. /* oimm12. */
  177. #define CSKY_32_SUBI_IMM(insn) ((insn & 0xfff) + 1)
  178. /* push16. */
  179. #define CSKY_16_IS_PUSH(insn) ((insn & 0xffe0) == 0x14c0)
  180. #define CSKY_16_IS_PUSH_R15(insn) ((insn & 0x10) == 0x10)
  181. #define CSKY_16_PUSH_LIST1(insn) (insn & 0xf) /* r4 - r11. */
  182. /* pop16. */
  183. #define CSKY_16_IS_POP(insn) ((insn & 0xffe0) == 0x1480)
  184. #define CSKY_16_IS_POP_R15(insn) CSKY_16_IS_PUSH_R15 (insn)
  185. #define CSKY_16_POP_LIST1(insn) CSKY_16_PUSH_LIST1 (insn) /* r4 - r11. */
  186. /* push32. */
  187. #define CSKY_32_IS_PUSH(insn) ((insn & 0xfffffe00) == 0xebe00000)
  188. #define CSKY_32_IS_PUSH_R29(insn) ((insn & 0x100) == 0x100)
  189. #define CSKY_32_IS_PUSH_R15(insn) ((insn & 0x10) == 0x10)
  190. #define CSKY_32_PUSH_LIST1(insn) (insn & 0xf) /* r4 - r11. */
  191. #define CSKY_32_PUSH_LIST2(insn) ((insn & 0xe0) >> 5) /* r16 - r17. */
  192. /* pop32. */
  193. #define CSKY_32_IS_POP(insn) ((insn & 0xfffffe00) == 0xebc00000)
  194. #define CSKY_32_IS_POP_R29(insn) CSKY_32_IS_PUSH_R29 (insn)
  195. #define CSKY_32_IS_POP_R15(insn) CSKY_32_IS_PUSH_R15 (insn)
  196. #define CSKY_32_POP_LIST1(insn) CSKY_32_PUSH_LIST1 (insn) /* r4 - r11. */
  197. #define CSKY_32_POP_LIST2(insn) CSKY_32_PUSH_LIST2 (insn) /* r16 - r17. */
  198. /* Adjust sp by r4(l0). */
  199. /* lrw r4, literal. */
  200. #define CSKY_16_IS_LRW4(x) (((x) &0xfce0) == 0x1080)
  201. /* movi r4, imm8. */
  202. #define CSKY_16_IS_MOVI4(x) (((x) &0xff00) == 0x3400)
  203. /* addi r4, oimm8. */
  204. #define CSKY_16_IS_ADDI4(x) (((x) &0xff00) == 0x2400)
  205. /* subi r4, oimm8. */
  206. #define CSKY_16_IS_SUBI4(x) (((x) &0xff00) == 0x2c00)
  207. /* nor16 r4, r4. */
  208. #define CSKY_16_IS_NOR4(x) ((x) == 0x6d12)
  209. /* lsli r4, r4, imm5. */
  210. #define CSKY_16_IS_LSLI4(x) (((x) &0xffe0) == 0x4480)
  211. /* bseti r4, imm5. */
  212. #define CSKY_16_IS_BSETI4(x) (((x) &0xffe0) == 0x3ca0)
  213. /* bclri r4, imm5. */
  214. #define CSKY_16_IS_BCLRI4(x) (((x) &0xffe0) == 0x3c80)
  215. /* subu sp, r4. */
  216. #define CSKY_16_IS_SUBU4(x) ((x) == 0x6392)
  217. #define CSKY_16_IS_R4_ADJUSTER(x) \
  218. (CSKY_16_IS_ADDI4 (x) || CSKY_16_IS_SUBI4 (x) || CSKY_16_IS_BSETI4 (x) \
  219. || CSKY_16_IS_BCLRI4 (x) || CSKY_16_IS_NOR4 (x) || CSKY_16_IS_LSLI4 (x))
  220. /* lrw r4, literal. */
  221. #define CSKY_32_IS_LRW4(x) (((x) &0xffff0000) == 0xea840000)
  222. /* movi r4, imm16. */
  223. #define CSKY_32_IS_MOVI4(x) (((x) &0xffff0000) == 0xea040000)
  224. /* movih r4, imm16. */
  225. #define CSKY_32_IS_MOVIH4(x) (((x) &0xffff0000) == 0xea240000)
  226. /* bmaski r4, oimm5. */
  227. #define CSKY_32_IS_BMASKI4(x) (((x) &0xfc1fffff) == 0xc4005024)
  228. /* addi r4, r4, oimm12. */
  229. #define CSKY_32_IS_ADDI4(x) (((x) &0xfffff000) == 0xe4840000)
  230. /* subi r4, r4, oimm12. */
  231. #define CSKY_32_IS_SUBI4(x) (((x) &0xfffff000) == 0xe4810000)
  232. /* nor32 r4, r4, r4. */
  233. #define CSKY_32_IS_NOR4(x) ((x) == 0xc4842484)
  234. /* rotli r4, r4, imm5. */
  235. #define CSKY_32_IS_ROTLI4(x) (((x) &0xfc1fffff) == 0xc4044904)
  236. /* lsli r4, r4, imm5. */
  237. #define CSKY_32_IS_LISI4(x) (((x) &0xfc1fffff) == 0xc4044824)
  238. /* bseti32 r4, r4, imm5. */
  239. #define CSKY_32_IS_BSETI4(x) (((x) &0xfc1fffff) == 0xc4042844)
  240. /* bclri32 r4, r4, imm5. */
  241. #define CSKY_32_IS_BCLRI4(x) (((x) &0xfc1fffff) == 0xc4042824)
  242. /* ixh r4, r4, r4. */
  243. #define CSKY_32_IS_IXH4(x) ((x) == 0xc4840824)
  244. /* ixw r4, r4, r4. */
  245. #define CSKY_32_IS_IXW4(x) ((x) == 0xc4840844)
  246. /* subu32 sp, sp, r4. */
  247. #define CSKY_32_IS_SUBU4(x) ((x) == 0xc48e008e)
  248. #define CSKY_32_IS_R4_ADJUSTER(x) \
  249. (CSKY_32_IS_ADDI4 (x) || CSKY_32_IS_SUBI4 (x) || CSKY_32_IS_ROTLI4 (x) \
  250. || CSKY_32_IS_IXH4 (x) || CSKY_32_IS_IXW4 (x) || CSKY_32_IS_NOR4 (x) \
  251. || CSKY_32_IS_BSETI4 (x) || CSKY_32_IS_BCLRI4 (x) || CSKY_32_IS_LISI4 (x))
  252. #define CSKY_IS_R4_ADJUSTER(x) \
  253. (CSKY_32_IS_R4_ADJUSTER (x) || CSKY_16_IS_R4_ADJUSTER (x))
  254. #define CSKY_IS_SUBU4(x) (CSKY_32_IS_SUBU4 (x) || CSKY_16_IS_SUBU4 (x))
  255. /* mfcr rz, epsr. */
  256. #define CSKY_32_IS_MFCR_EPSR(insn) ((insn & 0xffffffe0) == 0xc0026020)
  257. /* mfcr rz, fpsr. */
  258. #define CSKY_32_IS_MFCR_FPSR(insn) ((insn & 0xffffffe0) == 0xc0036020)
  259. /* mfcr rz, epc. */
  260. #define CSKY_32_IS_MFCR_EPC(insn) ((insn & 0xffffffe0) == 0xc0046020)
  261. /* mfcr rz, fpc. */
  262. #define CSKY_32_IS_MFCR_FPC(insn) ((insn & 0xffffffe0) == 0xc0056020)
  263. #define CSKY_32_IS_RTE(insn) (insn == 0xc0004020)
  264. #define CSKY_32_IS_RFI(insn) (insn == 0xc0004420)
  265. #define CSKY_32_IS_JMP(insn) ((insn & 0xffe0ffff) == 0xe8c00000)
  266. #define CSKY_16_IS_JMP(insn) ((insn & 0xffc3) == 0x7800)
  267. #define CSKY_32_IS_JMPI(insn) ((insn & 0xffff0000) == 0xeac00000)
  268. #define CSKY_32_IS_JMPIX(insn) ((insn & 0xffe0fffc) == 0xe9e00000)
  269. #define CSKY_16_IS_JMPIX(insn) ((insn & 0xf8fc) == 0x38e0)
  270. #define CSKY_16_IS_BR(insn) ((insn & 0xfc00) == 0x0400)
  271. #define CSKY_32_IS_BR(insn) ((insn & 0xffff0000) == 0xe8000000)
  272. #define CSKY_16_IS_MOV_FP_SP(insn) (insn == 0x6e3b) /* mov r8, r14. */
  273. #define CSKY_32_IS_MOV_FP_SP(insn) (insn == 0xc40e4828) /* mov r8, r14. */
  274. #define CSKY_16_IS_MOV_SP_FP(insn) (insn == 0x6fa3) /* mov r14, r8. */
  275. #define CSKY_32_INSN_MASK 0xc000
  276. #define CSKY_BKPT_INSN 0x0
  277. #define CSKY_NUM_GREGS 32
  278. /* 32 general regs + 4. */
  279. #define CSKY_NUM_GREGS_SAVED_GREGS (CSKY_NUM_GREGS + 4)
  280. /* CSKY software bkpt write-mode. */
  281. #define CSKY_WR_BKPT_MODE 4
  282. /* Define insns for parse rt_sigframe. */
  283. /* There are three words(sig, pinfo, puc) before siginfo. */
  284. #define CSKY_SIGINFO_OFFSET 0xc
  285. /* Size of struct siginfo. */
  286. #define CSKY_SIGINFO_SIZE 0x80
  287. /* There are five words(uc_flags, uc_link, and three for uc_stack)
  288. in struct ucontext before sigcontext. */
  289. #define CSKY_UCONTEXT_SIGCONTEXT 0x14
  290. /* There is a word(sc_mask) before sc_usp. */
  291. #define CSKY_SIGCONTEXT_SC_USP 0x4
  292. /* There is a word(sc_usp) before sc_a0. */
  293. #define CSKY_SIGCONTEXT_SC_A0 0x4
  294. #define CSKY_MOVI_R7_173 0x00adea07
  295. #define CSKY_TRAP_0 0x2020c000
  296. #endif