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