1 /* Target-dependent code for the CSKY architecture, for GDB.
3 Copyright (C) 2010-2022 Free Software Foundation, Inc.
5 Contributed by C-SKY Microsystems and Mentor Graphics.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "gdbsupport/gdb_assert.h"
35 #include "arch-utils.h"
39 #include "reggroups.h"
43 #include "sim-regno.h"
45 #include "frame-unwind.h"
46 #include "frame-base.h"
47 #include "trad-frame.h"
49 #include "floatformat.h"
51 #include "target-descriptions.h"
52 #include "dwarf2/frame.h"
53 #include "user-regs.h"
55 #include "csky-tdep.h"
57 #include "opcode/csky.h"
61 /* Control debugging information emitted in this file. */
63 static bool csky_debug
= false;
65 static const reggroup
*cr_reggroup
;
66 static const reggroup
*fr_reggroup
;
67 static const reggroup
*vr_reggroup
;
68 static const reggroup
*mmu_reggroup
;
69 static const reggroup
*prof_reggroup
;
71 static const char *csky_supported_tdesc_feature_names
[] = {
72 (const char *)"org.gnu.csky.abiv2.gpr",
73 (const char *)"org.gnu.csky.abiv2.fpu",
74 (const char *)"org.gnu.csky.abiv2.cr",
75 (const char *)"org.gnu.csky.abiv2.fvcr",
76 (const char *)"org.gnu.csky.abiv2.mmu",
77 (const char *)"org.gnu.csky.abiv2.tee",
78 (const char *)"org.gnu.csky.abiv2.fpu2",
79 (const char *)"org.gnu.csky.abiv2.bank0",
80 (const char *)"org.gnu.csky.abiv2.bank1",
81 (const char *)"org.gnu.csky.abiv2.bank2",
82 (const char *)"org.gnu.csky.abiv2.bank3",
83 (const char *)"org.gnu.csky.abiv2.bank4",
84 (const char *)"org.gnu.csky.abiv2.bank5",
85 (const char *)"org.gnu.csky.abiv2.bank6",
86 (const char *)"org.gnu.csky.abiv2.bank7",
87 (const char *)"org.gnu.csky.abiv2.bank8",
88 (const char *)"org.gnu.csky.abiv2.bank9",
89 (const char *)"org.gnu.csky.abiv2.bank10",
90 (const char *)"org.gnu.csky.abiv2.bank11",
91 (const char *)"org.gnu.csky.abiv2.bank12",
92 (const char *)"org.gnu.csky.abiv2.bank13",
93 (const char *)"org.gnu.csky.abiv2.bank14",
94 (const char *)"org.gnu.csky.abiv2.bank15",
95 (const char *)"org.gnu.csky.abiv2.bank16",
96 (const char *)"org.gnu.csky.abiv2.bank17",
97 (const char *)"org.gnu.csky.abiv2.bank18",
98 (const char *)"org.gnu.csky.abiv2.bank19",
99 (const char *)"org.gnu.csky.abiv2.bank20",
100 (const char *)"org.gnu.csky.abiv2.bank21",
101 (const char *)"org.gnu.csky.abiv2.bank22",
102 (const char *)"org.gnu.csky.abiv2.bank23",
103 (const char *)"org.gnu.csky.abiv2.bank24",
104 (const char *)"org.gnu.csky.abiv2.bank25",
105 (const char *)"org.gnu.csky.abiv2.bank26",
106 (const char *)"org.gnu.csky.abiv2.bank27",
107 (const char *)"org.gnu.csky.abiv2.bank28",
108 (const char *)"org.gnu.csky.abiv2.bank29",
109 (const char *)"org.gnu.csky.abiv2.bank30",
110 (const char *)"org.gnu.csky.abiv2.bank31"
113 struct csky_supported_tdesc_register
119 static const struct csky_supported_tdesc_register csky_supported_gpr_regs
[] = {
153 {"hi", CSKY_HI_REGNUM
},
154 {"lo", CSKY_LO_REGNUM
},
155 {"pc", CSKY_PC_REGNUM
}
158 static const struct csky_supported_tdesc_register csky_supported_fpu_regs
[] = {
160 {"fr0", CSKY_FR0_REGNUM
+ 0},
161 {"fr1", CSKY_FR0_REGNUM
+ 1},
162 {"fr2", CSKY_FR0_REGNUM
+ 2},
163 {"fr3", CSKY_FR0_REGNUM
+ 3},
164 {"fr4", CSKY_FR0_REGNUM
+ 4},
165 {"fr5", CSKY_FR0_REGNUM
+ 5},
166 {"fr6", CSKY_FR0_REGNUM
+ 6},
167 {"fr7", CSKY_FR0_REGNUM
+ 7},
168 {"fr8", CSKY_FR0_REGNUM
+ 8},
169 {"fr9", CSKY_FR0_REGNUM
+ 9},
170 {"fr10", CSKY_FR0_REGNUM
+ 10},
171 {"fr11", CSKY_FR0_REGNUM
+ 11},
172 {"fr12", CSKY_FR0_REGNUM
+ 12},
173 {"fr13", CSKY_FR0_REGNUM
+ 13},
174 {"fr14", CSKY_FR0_REGNUM
+ 14},
175 {"fr15", CSKY_FR0_REGNUM
+ 15},
177 {"fr16", CSKY_FR16_REGNUM
+ 0},
178 {"fr17", CSKY_FR16_REGNUM
+ 1},
179 {"fr18", CSKY_FR16_REGNUM
+ 2},
180 {"fr19", CSKY_FR16_REGNUM
+ 3},
181 {"fr20", CSKY_FR16_REGNUM
+ 4},
182 {"fr21", CSKY_FR16_REGNUM
+ 5},
183 {"fr22", CSKY_FR16_REGNUM
+ 6},
184 {"fr23", CSKY_FR16_REGNUM
+ 7},
185 {"fr24", CSKY_FR16_REGNUM
+ 8},
186 {"fr25", CSKY_FR16_REGNUM
+ 9},
187 {"fr26", CSKY_FR16_REGNUM
+ 10},
188 {"fr27", CSKY_FR16_REGNUM
+ 11},
189 {"fr28", CSKY_FR16_REGNUM
+ 12},
190 {"fr29", CSKY_FR16_REGNUM
+ 13},
191 {"fr30", CSKY_FR16_REGNUM
+ 14},
192 {"fr31", CSKY_FR16_REGNUM
+ 15},
194 {"vr0", CSKY_VR0_REGNUM
+ 0},
195 {"vr1", CSKY_VR0_REGNUM
+ 1},
196 {"vr2", CSKY_VR0_REGNUM
+ 2},
197 {"vr3", CSKY_VR0_REGNUM
+ 3},
198 {"vr4", CSKY_VR0_REGNUM
+ 4},
199 {"vr5", CSKY_VR0_REGNUM
+ 5},
200 {"vr6", CSKY_VR0_REGNUM
+ 6},
201 {"vr7", CSKY_VR0_REGNUM
+ 7},
202 {"vr8", CSKY_VR0_REGNUM
+ 8},
203 {"vr9", CSKY_VR0_REGNUM
+ 9},
204 {"vr10", CSKY_VR0_REGNUM
+ 10},
205 {"vr11", CSKY_VR0_REGNUM
+ 11},
206 {"vr12", CSKY_VR0_REGNUM
+ 12},
207 {"vr13", CSKY_VR0_REGNUM
+ 13},
208 {"vr14", CSKY_VR0_REGNUM
+ 14},
209 {"vr15", CSKY_VR0_REGNUM
+ 15},
210 /* fpu control registers. */
211 {"fcr", CSKY_FCR_REGNUM
+ 0},
212 {"fid", CSKY_FCR_REGNUM
+ 1},
213 {"fesr", CSKY_FCR_REGNUM
+ 2},
216 static const struct csky_supported_tdesc_register csky_supported_ar_regs
[] = {
217 {"ar0", CSKY_AR0_REGNUM
+ 0},
218 {"ar1", CSKY_AR0_REGNUM
+ 1},
219 {"ar2", CSKY_AR0_REGNUM
+ 2},
220 {"ar3", CSKY_AR0_REGNUM
+ 3},
221 {"ar4", CSKY_AR0_REGNUM
+ 4},
222 {"ar5", CSKY_AR0_REGNUM
+ 5},
223 {"ar6", CSKY_AR0_REGNUM
+ 6},
224 {"ar7", CSKY_AR0_REGNUM
+ 7},
225 {"ar8", CSKY_AR0_REGNUM
+ 8},
226 {"ar9", CSKY_AR0_REGNUM
+ 9},
227 {"ar10", CSKY_AR0_REGNUM
+ 10},
228 {"ar11", CSKY_AR0_REGNUM
+ 11},
229 {"ar12", CSKY_AR0_REGNUM
+ 12},
230 {"ar13", CSKY_AR0_REGNUM
+ 13},
231 {"ar14", CSKY_AR0_REGNUM
+ 14},
232 {"ar15", CSKY_AR0_REGNUM
+ 15},
235 static const struct csky_supported_tdesc_register csky_supported_bank0_regs
[] = {
236 {"cr0", CSKY_CR0_REGNUM
+ 0},
237 {"cr1", CSKY_CR0_REGNUM
+ 1},
238 {"cr2", CSKY_CR0_REGNUM
+ 2},
239 {"cr3", CSKY_CR0_REGNUM
+ 3},
240 {"cr4", CSKY_CR0_REGNUM
+ 4},
241 {"cr5", CSKY_CR0_REGNUM
+ 5},
242 {"cr6", CSKY_CR0_REGNUM
+ 6},
243 {"cr7", CSKY_CR0_REGNUM
+ 7},
244 {"cr8", CSKY_CR0_REGNUM
+ 8},
245 {"cr9", CSKY_CR0_REGNUM
+ 9},
246 {"cr10", CSKY_CR0_REGNUM
+ 10},
247 {"cr11", CSKY_CR0_REGNUM
+ 11},
248 {"cr12", CSKY_CR0_REGNUM
+ 12},
249 {"cr13", CSKY_CR0_REGNUM
+ 13},
250 {"cr14", CSKY_CR0_REGNUM
+ 14},
251 {"cr15", CSKY_CR0_REGNUM
+ 15},
252 {"cr16", CSKY_CR0_REGNUM
+ 16},
253 {"cr17", CSKY_CR0_REGNUM
+ 17},
254 {"cr18", CSKY_CR0_REGNUM
+ 18},
255 {"cr19", CSKY_CR0_REGNUM
+ 19},
256 {"cr20", CSKY_CR0_REGNUM
+ 20},
257 {"cr21", CSKY_CR0_REGNUM
+ 21},
258 {"cr22", CSKY_CR0_REGNUM
+ 22},
259 {"cr23", CSKY_CR0_REGNUM
+ 23},
260 {"cr24", CSKY_CR0_REGNUM
+ 24},
261 {"cr25", CSKY_CR0_REGNUM
+ 25},
262 {"cr26", CSKY_CR0_REGNUM
+ 26},
263 {"cr27", CSKY_CR0_REGNUM
+ 27},
264 {"cr28", CSKY_CR0_REGNUM
+ 28},
265 {"cr29", CSKY_CR0_REGNUM
+ 29},
266 {"cr30", CSKY_CR0_REGNUM
+ 30},
267 {"cr31", CSKY_CR0_REGNUM
+ 31}
270 static const struct csky_supported_tdesc_register csky_supported_mmu_regs
[] = {
282 static const struct csky_supported_tdesc_register csky_supported_bank15_regs
[] = {
308 static const struct csky_supported_tdesc_register csky_supported_alias_regs
[] = {
309 /* Alias register names for Bank0. */
310 {"psr", CSKY_CR0_REGNUM
+ 0},
311 {"vbr", CSKY_CR0_REGNUM
+ 1},
312 {"epsr", CSKY_CR0_REGNUM
+ 2},
313 {"fpsr", CSKY_CR0_REGNUM
+ 3},
314 {"epc", CSKY_CR0_REGNUM
+ 4},
315 {"fpc", CSKY_CR0_REGNUM
+ 5},
316 {"ss0", CSKY_CR0_REGNUM
+ 6},
317 {"ss1", CSKY_CR0_REGNUM
+ 7},
318 {"ss2", CSKY_CR0_REGNUM
+ 8},
319 {"ss3", CSKY_CR0_REGNUM
+ 9},
320 {"ss4", CSKY_CR0_REGNUM
+ 10},
321 {"gcr", CSKY_CR0_REGNUM
+ 11},
322 {"gsr", CSKY_CR0_REGNUM
+ 12},
323 {"cpuid", CSKY_CR0_REGNUM
+ 13},
324 {"ccr", CSKY_CR0_REGNUM
+ 18},
325 {"capr", CSKY_CR0_REGNUM
+ 19},
326 {"pacr", CSKY_CR0_REGNUM
+ 20},
327 {"prsr", CSKY_CR0_REGNUM
+ 21},
328 {"chr", CSKY_CR0_REGNUM
+ 31},
329 /* Alias register names for MMU. */
339 /* Alias register names for Bank1. */
354 /* Alias register names for Bank3. */
367 /* Functions declaration. */
370 csky_pseudo_register_name (struct gdbarch
*gdbarch
, int regno
);
372 /* Get csky supported registers's count for tdesc xml. */
375 csky_get_supported_tdesc_registers_count()
378 count
+= ARRAY_SIZE (csky_supported_gpr_regs
);
379 count
+= ARRAY_SIZE (csky_supported_fpu_regs
);
380 count
+= ARRAY_SIZE (csky_supported_ar_regs
);
381 count
+= ARRAY_SIZE (csky_supported_bank0_regs
);
382 count
+= ARRAY_SIZE (csky_supported_mmu_regs
);
383 count
+= ARRAY_SIZE (csky_supported_bank15_regs
);
384 count
+= ARRAY_SIZE (csky_supported_alias_regs
);
385 /* Bank1~Bank14, Bank16~Bank31. */
386 count
+= 32 * (14 + 16);
390 /* Return a supported register according to index. */
392 static const struct csky_supported_tdesc_register
*
393 csky_get_supported_register_by_index (int index
)
395 static struct csky_supported_tdesc_register tdesc_reg
;
398 int count_gpr
= ARRAY_SIZE (csky_supported_gpr_regs
);
399 int count_fpu
= ARRAY_SIZE (csky_supported_fpu_regs
);
400 int count_ar
= ARRAY_SIZE (csky_supported_ar_regs
);
401 int count_bank0
= ARRAY_SIZE (csky_supported_bank0_regs
);
402 int count_mmu
= ARRAY_SIZE (csky_supported_mmu_regs
);
403 int count_bank15
= ARRAY_SIZE (csky_supported_bank15_regs
);
404 int count_alias
= ARRAY_SIZE (csky_supported_alias_regs
);
408 return &csky_supported_gpr_regs
[index
];
409 if (index
< (count
+ count_fpu
))
410 return &csky_supported_fpu_regs
[index
- count
];
412 if (index
< (count
+ count_ar
))
413 return &csky_supported_ar_regs
[index
- count
];
415 if (index
< (count
+ count_bank0
))
416 return &csky_supported_bank0_regs
[index
- count
];
417 count
+= count_bank0
;
418 if (index
< (count
+ count_mmu
))
419 return &csky_supported_mmu_regs
[index
- count
];
421 if (index
< (count
+ count_bank15
))
422 return &csky_supported_bank15_regs
[index
- count
];
423 count
+= count_bank15
;
424 if (index
< (count
+ count_alias
))
425 return &csky_supported_alias_regs
[index
- count
];
426 count
+= count_alias
;
434 sprintf (tdesc_reg
.name
, "cp1cr%d", remain
);
435 tdesc_reg
.num
= 189 + remain
;
440 sprintf (tdesc_reg
.name
, "cp2cr%d", remain
);
441 tdesc_reg
.num
= 276 + remain
;
446 sprintf (tdesc_reg
.name
, "cp3cr%d", remain
);
447 tdesc_reg
.num
= 221 + remain
;
456 case 9: /* Bank10. */
457 case 10: /* Bank11. */
458 case 11: /* Bank12. */
459 case 12: /* Bank13. */
460 case 13: /* Bank14. */
462 /* Regitsers in Bank4~14 have continuous regno with start 308. */
463 sprintf (tdesc_reg
.name
, "cp%dcr%d", (multi
+ 1), remain
);
464 tdesc_reg
.num
= 308 + ((multi
- 3) * 32) + remain
;
467 case 14: /* Bank16. */
468 case 15: /* Bank17. */
469 case 16: /* Bank18. */
470 case 17: /* Bank19. */
471 case 18: /* Bank20. */
472 case 19: /* Bank21. */
473 case 20: /* Bank22. */
474 case 21: /* Bank23. */
475 case 22: /* Bank24. */
476 case 23: /* Bank25. */
477 case 24: /* Bank26. */
478 case 25: /* Bank27. */
479 case 26: /* Bank28. */
480 case 27: /* Bank29. */
481 case 28: /* Bank30. */
482 case 29: /* Bank31. */
484 /* Regitsers in Bank16~31 have continuous regno with start 660. */
485 sprintf (tdesc_reg
.name
, "cp%dcr%d", (multi
+ 2), remain
);
486 tdesc_reg
.num
= 660 + ((multi
- 14) * 32) + remain
;
495 /* Convenience function to print debug messages in prologue analysis. */
498 print_savedreg_msg (int regno
, int offsets
[], bool print_continuing
)
500 gdb_printf (gdb_stdlog
, "csky: r%d saved at offset 0x%x\n",
501 regno
, offsets
[regno
]);
502 if (print_continuing
)
503 gdb_printf (gdb_stdlog
, "csky: continuing\n");
506 /* Check whether the instruction at ADDR is 16-bit or not. */
509 csky_pc_is_csky16 (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
511 gdb_byte target_mem
[2];
515 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
517 status
= target_read_memory (addr
, target_mem
, 2);
518 /* Assume a 16-bit instruction if we can't read memory. */
522 /* Get instruction from memory. */
523 insn
= extract_unsigned_integer (target_mem
, 2, byte_order
);
524 if ((insn
& CSKY_32_INSN_MASK
) == CSKY_32_INSN_MASK
)
526 else if (insn
== CSKY_BKPT_INSN
)
528 /* Check for 32-bit bkpt instruction which is all 0. */
529 status
= target_read_memory (addr
+ 2, target_mem
, 2);
533 insn
= extract_unsigned_integer (target_mem
, 2, byte_order
);
534 if (insn
== CSKY_BKPT_INSN
)
540 /* Get one instruction at ADDR and store it in INSN. Return 2 for
541 a 16-bit instruction or 4 for a 32-bit instruction. */
544 csky_get_insn (struct gdbarch
*gdbarch
, CORE_ADDR addr
, unsigned int *insn
)
546 gdb_byte target_mem
[2];
547 unsigned int insn_type
;
550 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
552 status
= target_read_memory (addr
, target_mem
, 2);
554 memory_error (TARGET_XFER_E_IO
, addr
);
556 insn_type
= extract_unsigned_integer (target_mem
, 2, byte_order
);
557 if (CSKY_32_INSN_MASK
== (insn_type
& CSKY_32_INSN_MASK
))
559 status
= target_read_memory (addr
+ 2, target_mem
, 2);
561 memory_error (TARGET_XFER_E_IO
, addr
);
562 insn_type
= ((insn_type
<< 16)
563 | extract_unsigned_integer (target_mem
, 2, byte_order
));
570 /* Implement the read_pc gdbarch method. */
573 csky_read_pc (readable_regcache
*regcache
)
576 regcache
->cooked_read (CSKY_PC_REGNUM
, &pc
);
580 /* Implement the write_pc gdbarch method. */
583 csky_write_pc (regcache
*regcache
, CORE_ADDR val
)
585 regcache_cooked_write_unsigned (regcache
, CSKY_PC_REGNUM
, val
);
588 /* C-Sky ABI register names. */
590 static const char * const csky_register_names
[] =
592 /* General registers 0 - 31. */
593 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
594 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
595 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
596 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
598 /* DSP hilo registers 36 and 37. */
599 "", "", "", "", "hi", "lo", "", "",
601 /* FPU/VPU general registers 40 - 71. */
602 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7",
603 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15",
604 "vr0", "vr1", "vr2", "vr3", "vr4", "vr5", "vr6", "vr7",
605 "vr8", "vr9", "vr10", "vr11", "vr12", "vr13", "vr14", "vr15",
607 /* Program counter 72. */
610 /* Optional registers (ar) 73 - 88. */
611 "ar0", "ar1", "ar2", "ar3", "ar4", "ar5", "ar6", "ar7",
612 "ar8", "ar9", "ar10", "ar11", "ar12", "ar13", "ar14", "ar15",
614 /* Control registers (cr) 89 - 119. */
615 "psr", "vbr", "epsr", "fpsr", "epc", "fpc", "ss0", "ss1",
616 "ss2", "ss3", "ss4", "gcr", "gsr", "cr13", "cr14", "cr15",
617 "cr16", "cr17", "cr18", "cr19", "cr20", "cr21", "cr22", "cr23",
618 "cr24", "cr25", "cr26", "cr27", "cr28", "cr29", "cr30", "cr31",
620 /* FPU/VPU control registers 121 ~ 123. */
622 "fid", "fcr", "fesr", "", "", "", "usp",
624 /* MMU control registers: 128 - 136. */
625 "mcr0", "mcr2", "mcr3", "mcr4", "mcr6", "mcr8", "mcr29", "mcr30",
628 /* Profiling control registers 140 - 143. */
629 /* Profiling software general registers 144 - 157. */
630 "profcr0", "profcr1", "profcr2", "profcr3", "profsgr0", "profsgr1",
631 "profsgr2", "profsgr3", "profsgr4", "profsgr5", "profsgr6", "profsgr7",
632 "profsgr8", "profsgr9", "profsgr10","profsgr11","profsgr12", "profsgr13",
635 /* Profiling architecture general registers 160 - 174. */
636 "profagr0", "profagr1", "profagr2", "profagr3", "profagr4", "profagr5",
637 "profagr6", "profagr7", "profagr8", "profagr9", "profagr10","profagr11",
638 "profagr12","profagr13","profagr14", "",
640 /* Profiling extension general registers 176 - 188. */
641 "profxgr0", "profxgr1", "profxgr2", "profxgr3", "profxgr4", "profxgr5",
642 "profxgr6", "profxgr7", "profxgr8", "profxgr9", "profxgr10","profxgr11",
645 /* Control registers in bank1. */
646 "", "", "", "", "", "", "", "",
647 "", "", "", "", "", "", "", "",
648 "cp1cr16", "cp1cr17", "cp1cr18", "cp1cr19", "cp1cr20", "", "", "",
649 "", "", "", "", "", "", "", "",
651 /* Control registers in bank3 (ICE). */
652 "sepsr", "sevbr", "seepsr", "", "seepc", "", "nsssp", "seusp",
653 "sedcr", "", "", "", "", "", "", "",
654 "", "", "", "", "", "", "", "",
655 "", "", "", "", "", "", "", ""
658 /* Implement the register_name gdbarch method. */
661 csky_register_name (struct gdbarch
*gdbarch
, int reg_nr
)
663 int num_regs
= gdbarch_num_regs (gdbarch
);
664 int num_pseudo_regs
= gdbarch_num_pseudo_regs (gdbarch
);
666 if ((reg_nr
>= num_regs
) && (reg_nr
< (num_regs
+ num_pseudo_regs
)))
667 return csky_pseudo_register_name (gdbarch
, reg_nr
);
669 if (tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
670 return tdesc_register_name (gdbarch
, reg_nr
);
675 if (reg_nr
>= gdbarch_num_regs (gdbarch
))
678 return csky_register_names
[reg_nr
];
681 /* Construct vector type for vrx registers. */
684 csky_vector_type (struct gdbarch
*gdbarch
)
686 const struct builtin_type
*bt
= builtin_type (gdbarch
);
690 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vec128i",
693 append_composite_type_field (t
, "u32",
694 init_vector_type (bt
->builtin_int32
, 4));
695 append_composite_type_field (t
, "u16",
696 init_vector_type (bt
->builtin_int16
, 8));
697 append_composite_type_field (t
, "u8",
698 init_vector_type (bt
->builtin_int8
, 16));
700 t
->set_is_vector (true);
701 t
->set_name ("builtin_type_vec128i");
706 /* Return the GDB type object for the "standard" data type
707 of data in register N. */
710 csky_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
712 /* If type has been described in tdesc-xml, use it. */
713 if (tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
715 struct type
*tdesc_t
= tdesc_register_type (gdbarch
, reg_nr
);
720 /* PC, EPC, FPC is a text pointer. */
721 if ((reg_nr
== CSKY_PC_REGNUM
) || (reg_nr
== CSKY_EPC_REGNUM
)
722 || (reg_nr
== CSKY_FPC_REGNUM
))
723 return builtin_type (gdbarch
)->builtin_func_ptr
;
725 /* VBR is a data pointer. */
726 if (reg_nr
== CSKY_VBR_REGNUM
)
727 return builtin_type (gdbarch
)->builtin_data_ptr
;
729 /* Float register has 64 bits, and only in ck810. */
730 if ((reg_nr
>=CSKY_FR0_REGNUM
) && (reg_nr
<= CSKY_FR0_REGNUM
+ 15))
731 return arch_float_type (gdbarch
, 64, "builtin_type_csky_ext",
732 floatformats_ieee_double
);
734 /* Vector register has 128 bits, and only in ck810. */
735 if ((reg_nr
>= CSKY_VR0_REGNUM
) && (reg_nr
<= CSKY_VR0_REGNUM
+ 15))
736 return csky_vector_type (gdbarch
);
738 /* Profiling general register has 48 bits, we use 64bit. */
739 if ((reg_nr
>= CSKY_PROFGR_REGNUM
) && (reg_nr
<= CSKY_PROFGR_REGNUM
+ 44))
740 return builtin_type (gdbarch
)->builtin_uint64
;
742 if (reg_nr
== CSKY_SP_REGNUM
)
743 return builtin_type (gdbarch
)->builtin_data_ptr
;
745 /* Others are 32 bits. */
746 return builtin_type (gdbarch
)->builtin_int32
;
749 /* Data structure to marshall items in a dummy stack frame when
750 calling a function in the inferior. */
752 struct csky_stack_item
754 csky_stack_item (int len_
, const gdb_byte
*data_
)
755 : len (len_
), data (data_
)
759 const gdb_byte
*data
;
762 /* Implement the push_dummy_call gdbarch method. */
765 csky_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
766 struct regcache
*regcache
, CORE_ADDR bp_addr
,
767 int nargs
, struct value
**args
, CORE_ADDR sp
,
768 function_call_return_method return_method
,
769 CORE_ADDR struct_addr
)
772 int argreg
= CSKY_ABI_A0_REGNUM
;
773 int last_arg_regnum
= CSKY_ABI_LAST_ARG_REGNUM
;
774 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
775 std::vector
<csky_stack_item
> stack_items
;
777 /* Set the return address. For CSKY, the return breakpoint is
778 always at BP_ADDR. */
779 regcache_cooked_write_unsigned (regcache
, CSKY_LR_REGNUM
, bp_addr
);
781 /* The struct_return pointer occupies the first parameter
783 if (return_method
== return_method_struct
)
787 gdb_printf (gdb_stdlog
,
788 "csky: struct return in %s = %s\n",
789 gdbarch_register_name (gdbarch
, argreg
),
790 paddress (gdbarch
, struct_addr
));
792 regcache_cooked_write_unsigned (regcache
, argreg
, struct_addr
);
796 /* Put parameters into argument registers in REGCACHE.
797 In ABI argument registers are r0 through r3. */
798 for (argnum
= 0; argnum
< nargs
; argnum
++)
801 struct type
*arg_type
;
804 arg_type
= check_typedef (value_type (args
[argnum
]));
805 len
= arg_type
->length ();
806 val
= value_contents (args
[argnum
]).data ();
808 /* Copy the argument to argument registers or the dummy stack.
809 Large arguments are split between registers and stack.
811 If len < 4, there is no need to worry about endianness since
812 the arguments will always be stored in the low address. */
816 = extract_unsigned_integer (val
, len
, byte_order
);
817 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
824 int partial_len
= len
< 4 ? len
: 4;
825 if (argreg
<= last_arg_regnum
)
827 /* The argument is passed in an argument register. */
829 = extract_unsigned_integer (val
, partial_len
,
831 if (byte_order
== BFD_ENDIAN_BIG
)
832 regval
<<= (4 - partial_len
) * 8;
834 /* Put regval into register in REGCACHE. */
835 regcache_cooked_write_unsigned (regcache
, argreg
,
841 /* The argument should be pushed onto the dummy stack. */
842 stack_items
.emplace_back (4, val
);
850 /* Transfer the dummy stack frame to the target. */
851 std::vector
<csky_stack_item
>::reverse_iterator iter
;
852 for (iter
= stack_items
.rbegin (); iter
!= stack_items
.rend (); ++iter
)
855 write_memory (sp
, iter
->data
, iter
->len
);
858 /* Finally, update the SP register. */
859 regcache_cooked_write_unsigned (regcache
, CSKY_SP_REGNUM
, sp
);
863 /* Implement the return_value gdbarch method. */
865 static enum return_value_convention
866 csky_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
867 struct type
*valtype
, struct regcache
*regcache
,
868 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
871 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
872 int len
= valtype
->length ();
873 unsigned int ret_regnum
= CSKY_RET_REGNUM
;
875 /* Csky abi specifies that return values larger than 8 bytes
876 are put on the stack. */
878 return RETURN_VALUE_STRUCT_CONVENTION
;
884 /* By using store_unsigned_integer we avoid having to do
885 anything special for small big-endian values. */
886 regcache
->cooked_read (ret_regnum
, &tmp
);
887 store_unsigned_integer (readbuf
, (len
> 4 ? 4 : len
),
891 regcache
->cooked_read (ret_regnum
+ 1, &tmp
);
892 store_unsigned_integer (readbuf
+ 4, 4, byte_order
, tmp
);
895 if (writebuf
!= NULL
)
897 regval
= extract_unsigned_integer (writebuf
, len
> 4 ? 4 : len
,
899 regcache_cooked_write_unsigned (regcache
, ret_regnum
, regval
);
902 regval
= extract_unsigned_integer ((gdb_byte
*) writebuf
+ 4,
904 regcache_cooked_write_unsigned (regcache
, ret_regnum
+ 1,
909 return RETURN_VALUE_REGISTER_CONVENTION
;
913 /* Implement the frame_align gdbarch method.
915 Adjust the address downward (direction of stack growth) so that it
916 is correctly aligned for a new stack frame. */
919 csky_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
921 return align_down (addr
, 4);
924 /* Unwind cache used for gdbarch fallback unwinder. */
926 struct csky_unwind_cache
928 /* The stack pointer at the time this frame was created; i.e. the
929 caller's stack pointer when this function was called. It is used
930 to identify this frame. */
933 /* The frame base for this frame is just prev_sp - frame size.
934 FRAMESIZE is the distance from the frame pointer to the
935 initial stack pointer. */
938 /* The register used to hold the frame pointer for this frame. */
941 /* Saved register offsets. */
942 trad_frame_saved_reg
*saved_regs
;
945 /* Do prologue analysis, returning the PC of the first instruction
946 after the function prologue. */
949 csky_analyze_prologue (struct gdbarch
*gdbarch
,
953 struct frame_info
*this_frame
,
954 struct csky_unwind_cache
*this_cache
,
958 unsigned int insn
, rn
;
961 int register_offsets
[CSKY_NUM_GREGS_SAVED_GREGS
];
963 /* For adjusting fp. */
967 /* REGISTER_OFFSETS will contain offsets from the top of the frame
968 (NOT the frame pointer) for the various saved registers, or -1
969 if the register is not saved. */
970 for (rn
= 0; rn
< CSKY_NUM_GREGS_SAVED_GREGS
; rn
++)
971 register_offsets
[rn
] = -1;
973 /* Analyze the prologue. Things we determine from analyzing the
974 prologue include the size of the frame and which registers are
975 saved (and where). */
978 gdb_printf (gdb_stdlog
,
979 "csky: Scanning prologue: start_pc = 0x%x,"
980 "limit_pc = 0x%x\n", (unsigned int) start_pc
,
981 (unsigned int) limit_pc
);
984 /* Default to 16 bit instruction. */
987 for (addr
= start_pc
; addr
< limit_pc
; addr
+= insn_len
)
990 insn_len
= csky_get_insn (gdbarch
, addr
, &insn
);
992 /* Check if 32 bit. */
995 /* subi32 sp,sp oimm12. */
996 if (CSKY_32_IS_SUBI0 (insn
))
999 int offset
= CSKY_32_SUBI_IMM (insn
);
1002 gdb_printf (gdb_stdlog
,
1003 "csky: got subi sp,%d; continuing\n",
1006 stacksize
+= offset
;
1009 /* stm32 ry-rz,(sp). */
1010 else if (CSKY_32_IS_STMx0 (insn
))
1012 /* Spill register(s). */
1017 /* BIG WARNING! The CKCore ABI does not restrict functions
1018 to taking only one stack allocation. Therefore, when
1019 we save a register, we record the offset of where it was
1020 saved relative to the current stacksize. This will
1021 then give an offset from the SP upon entry to our
1022 function. Remember, stacksize is NOT constant until
1023 we're done scanning the prologue. */
1024 start_register
= CSKY_32_STM_VAL_REGNUM (insn
);
1025 reg_count
= CSKY_32_STM_SIZE (insn
);
1028 gdb_printf (gdb_stdlog
,
1029 "csky: got stm r%d-r%d,(sp)\n",
1031 start_register
+ reg_count
);
1034 for (rn
= start_register
, offset
= 0;
1035 rn
<= start_register
+ reg_count
;
1038 register_offsets
[rn
] = stacksize
- offset
;
1041 gdb_printf (gdb_stdlog
,
1042 "csky: r%d saved at 0x%x"
1044 rn
, register_offsets
[rn
],
1049 gdb_printf (gdb_stdlog
, "csky: continuing\n");
1052 /* stw ry,(sp,disp). */
1053 else if (CSKY_32_IS_STWx0 (insn
))
1055 /* Spill register: see note for IS_STM above. */
1058 rn
= CSKY_32_ST_VAL_REGNUM (insn
);
1059 disp
= CSKY_32_ST_OFFSET (insn
);
1060 register_offsets
[rn
] = stacksize
- disp
;
1062 print_savedreg_msg (rn
, register_offsets
, true);
1065 else if (CSKY_32_IS_MOV_FP_SP (insn
))
1067 /* SP is saved to FP reg, means code afer prologue may
1070 adjust_fp
= stacksize
;
1073 else if (CSKY_32_IS_MFCR_EPSR (insn
))
1077 int mfcr_regnum
= insn
& 0x1f;
1078 insn_len
= csky_get_insn (gdbarch
, addr
, &insn2
);
1081 int stw_regnum
= (insn2
>> 5) & 0x7;
1082 if (CSKY_16_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1086 /* CSKY_EPSR_REGNUM. */
1087 rn
= CSKY_NUM_GREGS
;
1088 offset
= CSKY_16_STWx0_OFFSET (insn2
);
1089 register_offsets
[rn
] = stacksize
- offset
;
1091 print_savedreg_msg (rn
, register_offsets
, true);
1098 /* INSN_LEN == 4. */
1099 int stw_regnum
= (insn2
>> 21) & 0x1f;
1100 if (CSKY_32_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1104 /* CSKY_EPSR_REGNUM. */
1105 rn
= CSKY_NUM_GREGS
;
1106 offset
= CSKY_32_ST_OFFSET (insn2
);
1107 register_offsets
[rn
] = framesize
- offset
;
1109 print_savedreg_msg (rn
, register_offsets
, true);
1115 else if (CSKY_32_IS_MFCR_FPSR (insn
))
1119 int mfcr_regnum
= insn
& 0x1f;
1120 insn_len
= csky_get_insn (gdbarch
, addr
, &insn2
);
1123 int stw_regnum
= (insn2
>> 5) & 0x7;
1124 if (CSKY_16_IS_STWx0 (insn2
) && (mfcr_regnum
1129 /* CSKY_FPSR_REGNUM. */
1130 rn
= CSKY_NUM_GREGS
+ 1;
1131 offset
= CSKY_16_STWx0_OFFSET (insn2
);
1132 register_offsets
[rn
] = stacksize
- offset
;
1134 print_savedreg_msg (rn
, register_offsets
, true);
1141 /* INSN_LEN == 4. */
1142 int stw_regnum
= (insn2
>> 21) & 0x1f;
1143 if (CSKY_32_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1147 /* CSKY_FPSR_REGNUM. */
1148 rn
= CSKY_NUM_GREGS
+ 1;
1149 offset
= CSKY_32_ST_OFFSET (insn2
);
1150 register_offsets
[rn
] = framesize
- offset
;
1152 print_savedreg_msg (rn
, register_offsets
, true);
1158 else if (CSKY_32_IS_MFCR_EPC (insn
))
1162 int mfcr_regnum
= insn
& 0x1f;
1163 insn_len
= csky_get_insn (gdbarch
, addr
, &insn2
);
1166 int stw_regnum
= (insn2
>> 5) & 0x7;
1167 if (CSKY_16_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1171 /* CSKY_EPC_REGNUM. */
1172 rn
= CSKY_NUM_GREGS
+ 2;
1173 offset
= CSKY_16_STWx0_OFFSET (insn2
);
1174 register_offsets
[rn
] = stacksize
- offset
;
1176 print_savedreg_msg (rn
, register_offsets
, true);
1183 /* INSN_LEN == 4. */
1184 int stw_regnum
= (insn2
>> 21) & 0x1f;
1185 if (CSKY_32_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1189 /* CSKY_EPC_REGNUM. */
1190 rn
= CSKY_NUM_GREGS
+ 2;
1191 offset
= CSKY_32_ST_OFFSET (insn2
);
1192 register_offsets
[rn
] = framesize
- offset
;
1194 print_savedreg_msg (rn
, register_offsets
, true);
1200 else if (CSKY_32_IS_MFCR_FPC (insn
))
1204 int mfcr_regnum
= insn
& 0x1f;
1205 insn_len
= csky_get_insn (gdbarch
, addr
, &insn2
);
1208 int stw_regnum
= (insn2
>> 5) & 0x7;
1209 if (CSKY_16_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1213 /* CSKY_FPC_REGNUM. */
1214 rn
= CSKY_NUM_GREGS
+ 3;
1215 offset
= CSKY_16_STWx0_OFFSET (insn2
);
1216 register_offsets
[rn
] = stacksize
- offset
;
1218 print_savedreg_msg (rn
, register_offsets
, true);
1225 /* INSN_LEN == 4. */
1226 int stw_regnum
= (insn2
>> 21) & 0x1f;
1227 if (CSKY_32_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1231 /* CSKY_FPC_REGNUM. */
1232 rn
= CSKY_NUM_GREGS
+ 3;
1233 offset
= CSKY_32_ST_OFFSET (insn2
);
1234 register_offsets
[rn
] = framesize
- offset
;
1236 print_savedreg_msg (rn
, register_offsets
, true);
1242 else if (CSKY_32_IS_PUSH (insn
))
1244 /* Push for 32_bit. */
1245 if (CSKY_32_IS_PUSH_R29 (insn
))
1248 register_offsets
[29] = stacksize
;
1250 print_savedreg_msg (29, register_offsets
, false);
1252 if (CSKY_32_PUSH_LIST2 (insn
))
1254 int num
= CSKY_32_PUSH_LIST2 (insn
);
1256 stacksize
+= num
* 4;
1259 gdb_printf (gdb_stdlog
,
1260 "csky: push regs_array: r16-r%d\n",
1263 for (rn
= 16; rn
<= 16 + num
- 1; rn
++)
1265 register_offsets
[rn
] = stacksize
- tmp
;
1268 gdb_printf (gdb_stdlog
,
1269 "csky: r%d saved at 0x%x"
1270 " (offset %d)\n", rn
,
1271 register_offsets
[rn
], tmp
);
1276 if (CSKY_32_IS_PUSH_R15 (insn
))
1279 register_offsets
[15] = stacksize
;
1281 print_savedreg_msg (15, register_offsets
, false);
1283 if (CSKY_32_PUSH_LIST1 (insn
))
1285 int num
= CSKY_32_PUSH_LIST1 (insn
);
1287 stacksize
+= num
* 4;
1290 gdb_printf (gdb_stdlog
,
1291 "csky: push regs_array: r4-r%d\n",
1294 for (rn
= 4; rn
<= 4 + num
- 1; rn
++)
1296 register_offsets
[rn
] = stacksize
- tmp
;
1299 gdb_printf (gdb_stdlog
,
1300 "csky: r%d saved at 0x%x"
1301 " (offset %d)\n", rn
,
1302 register_offsets
[rn
], tmp
);
1308 framesize
= stacksize
;
1310 gdb_printf (gdb_stdlog
, "csky: continuing\n");
1313 else if (CSKY_32_IS_LRW4 (insn
) || CSKY_32_IS_MOVI4 (insn
)
1314 || CSKY_32_IS_MOVIH4 (insn
) || CSKY_32_IS_BMASKI4 (insn
))
1322 gdb_printf (gdb_stdlog
,
1323 "csky: looking at large frame\n");
1325 if (CSKY_32_IS_LRW4 (insn
))
1327 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1328 int literal_addr
= (addr
+ ((insn
& 0xffff) << 2))
1330 adjust
= read_memory_unsigned_integer (literal_addr
, 4,
1333 else if (CSKY_32_IS_MOVI4 (insn
))
1334 adjust
= (insn
& 0xffff);
1335 else if (CSKY_32_IS_MOVIH4 (insn
))
1336 adjust
= (insn
& 0xffff) << 16;
1339 /* CSKY_32_IS_BMASKI4 (insn). */
1340 adjust
= (1 << (((insn
& 0x3e00000) >> 21) + 1)) - 1;
1345 gdb_printf (gdb_stdlog
,
1346 "csky: base stacksize=0x%x\n", adjust
);
1348 /* May have zero or more insns which modify r4. */
1349 gdb_printf (gdb_stdlog
,
1350 "csky: looking for r4 adjusters...\n");
1354 insn_len
= csky_get_insn (gdbarch
, addr
+ offset
, &insn2
);
1355 while (CSKY_IS_R4_ADJUSTER (insn2
))
1357 if (CSKY_32_IS_ADDI4 (insn2
))
1359 int imm
= (insn2
& 0xfff) + 1;
1363 gdb_printf (gdb_stdlog
,
1364 "csky: addi r4,%d\n", imm
);
1367 else if (CSKY_32_IS_SUBI4 (insn2
))
1369 int imm
= (insn2
& 0xfff) + 1;
1373 gdb_printf (gdb_stdlog
,
1374 "csky: subi r4,%d\n", imm
);
1377 else if (CSKY_32_IS_NOR4 (insn2
))
1382 gdb_printf (gdb_stdlog
,
1383 "csky: nor r4,r4,r4\n");
1386 else if (CSKY_32_IS_ROTLI4 (insn2
))
1388 int imm
= ((insn2
>> 21) & 0x1f);
1389 int temp
= adjust
>> (32 - imm
);
1394 gdb_printf (gdb_stdlog
,
1395 "csky: rotli r4,r4,%d\n", imm
);
1398 else if (CSKY_32_IS_LISI4 (insn2
))
1400 int imm
= ((insn2
>> 21) & 0x1f);
1404 gdb_printf (gdb_stdlog
,
1405 "csky: lsli r4,r4,%d\n", imm
);
1408 else if (CSKY_32_IS_BSETI4 (insn2
))
1410 int imm
= ((insn2
>> 21) & 0x1f);
1411 adjust
|= (1 << imm
);
1414 gdb_printf (gdb_stdlog
,
1415 "csky: bseti r4,r4 %d\n", imm
);
1418 else if (CSKY_32_IS_BCLRI4 (insn2
))
1420 int imm
= ((insn2
>> 21) & 0x1f);
1421 adjust
&= ~(1 << imm
);
1424 gdb_printf (gdb_stdlog
,
1425 "csky: bclri r4,r4 %d\n", imm
);
1428 else if (CSKY_32_IS_IXH4 (insn2
))
1433 gdb_printf (gdb_stdlog
,
1434 "csky: ixh r4,r4,r4\n");
1437 else if (CSKY_32_IS_IXW4 (insn2
))
1442 gdb_printf (gdb_stdlog
,
1443 "csky: ixw r4,r4,r4\n");
1446 else if (CSKY_16_IS_ADDI4 (insn2
))
1448 int imm
= (insn2
& 0xff) + 1;
1452 gdb_printf (gdb_stdlog
,
1453 "csky: addi r4,%d\n", imm
);
1456 else if (CSKY_16_IS_SUBI4 (insn2
))
1458 int imm
= (insn2
& 0xff) + 1;
1462 gdb_printf (gdb_stdlog
,
1463 "csky: subi r4,%d\n", imm
);
1466 else if (CSKY_16_IS_NOR4 (insn2
))
1471 gdb_printf (gdb_stdlog
,
1472 "csky: nor r4,r4\n");
1475 else if (CSKY_16_IS_BSETI4 (insn2
))
1477 int imm
= (insn2
& 0x1f);
1478 adjust
|= (1 << imm
);
1481 gdb_printf (gdb_stdlog
,
1482 "csky: bseti r4, %d\n", imm
);
1485 else if (CSKY_16_IS_BCLRI4 (insn2
))
1487 int imm
= (insn2
& 0x1f);
1488 adjust
&= ~(1 << imm
);
1491 gdb_printf (gdb_stdlog
,
1492 "csky: bclri r4, %d\n", imm
);
1495 else if (CSKY_16_IS_LSLI4 (insn2
))
1497 int imm
= (insn2
& 0x1f);
1501 gdb_printf (gdb_stdlog
,
1502 "csky: lsli r4,r4, %d\n", imm
);
1507 insn_len
= csky_get_insn (gdbarch
, addr
+ offset
, &insn2
);
1512 gdb_printf (gdb_stdlog
, "csky: done looking for"
1516 /* If the next insn adjusts the stack pointer, we keep
1517 everything; if not, we scrap it and we've found the
1518 end of the prologue. */
1519 if (CSKY_IS_SUBU4 (insn2
))
1522 stacksize
+= adjust
;
1525 gdb_printf (gdb_stdlog
,
1526 "csky: found stack adjustment of"
1527 " 0x%x bytes.\n", adjust
);
1528 gdb_printf (gdb_stdlog
,
1529 "csky: skipping to new address %s\n",
1530 core_addr_to_string_nz (addr
));
1531 gdb_printf (gdb_stdlog
,
1532 "csky: continuing\n");
1537 /* None of these instructions are prologue, so don't touch
1541 gdb_printf (gdb_stdlog
,
1542 "csky: no subu sp,sp,r4; NOT altering"
1550 /* insn_len != 4. */
1552 /* subi.sp sp,disp. */
1553 if (CSKY_16_IS_SUBI0 (insn
))
1555 int offset
= CSKY_16_SUBI_IMM (insn
);
1558 gdb_printf (gdb_stdlog
,
1559 "csky: got subi r0,%d; continuing\n",
1562 stacksize
+= offset
;
1565 /* stw.16 rz,(sp,disp). */
1566 else if (CSKY_16_IS_STWx0 (insn
))
1568 /* Spill register: see note for IS_STM above. */
1571 rn
= CSKY_16_ST_VAL_REGNUM (insn
);
1572 disp
= CSKY_16_ST_OFFSET (insn
);
1573 register_offsets
[rn
] = stacksize
- disp
;
1575 print_savedreg_msg (rn
, register_offsets
, true);
1578 else if (CSKY_16_IS_MOV_FP_SP (insn
))
1580 /* SP is saved to FP reg, means prologue may modify SP. */
1582 adjust_fp
= stacksize
;
1585 else if (CSKY_16_IS_PUSH (insn
))
1587 /* Push for 16_bit. */
1589 if (CSKY_16_IS_PUSH_R15 (insn
))
1592 register_offsets
[15] = stacksize
;
1594 print_savedreg_msg (15, register_offsets
, false);
1597 if (CSKY_16_PUSH_LIST1 (insn
))
1599 int num
= CSKY_16_PUSH_LIST1 (insn
);
1601 stacksize
+= num
* 4;
1605 gdb_printf (gdb_stdlog
,
1606 "csky: push regs_array: r4-r%d\n",
1609 for (rn
= 4; rn
<= 4 + num
- 1; rn
++)
1611 register_offsets
[rn
] = stacksize
- tmp
;
1614 gdb_printf (gdb_stdlog
,
1615 "csky: r%d saved at 0x%x"
1616 " (offset %d)\n", rn
,
1617 register_offsets
[rn
], offset
);
1623 framesize
= stacksize
;
1625 gdb_printf (gdb_stdlog
, "csky: continuing\n");
1628 else if (CSKY_16_IS_LRW4 (insn
) || CSKY_16_IS_MOVI4 (insn
))
1635 gdb_printf (gdb_stdlog
,
1636 "csky: looking at large frame\n");
1638 if (CSKY_16_IS_LRW4 (insn
))
1640 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1641 int offset
= ((insn
& 0x300) >> 3) | (insn
& 0x1f);
1642 int literal_addr
= (addr
+ ( offset
<< 2)) & 0xfffffffc;
1643 adjust
= read_memory_unsigned_integer (literal_addr
, 4,
1648 /* CSKY_16_IS_MOVI4 (insn). */
1649 adjust
= (insn
& 0xff);
1654 gdb_printf (gdb_stdlog
,
1655 "csky: base stacksize=0x%x\n", adjust
);
1658 /* May have zero or more instructions which modify r4. */
1661 gdb_printf (gdb_stdlog
,
1662 "csky: looking for r4 adjusters...\n");
1665 insn_len
= csky_get_insn (gdbarch
, addr
+ offset
, &insn2
);
1666 while (CSKY_IS_R4_ADJUSTER (insn2
))
1668 if (CSKY_32_IS_ADDI4 (insn2
))
1670 int imm
= (insn2
& 0xfff) + 1;
1674 gdb_printf (gdb_stdlog
,
1675 "csky: addi r4,%d\n", imm
);
1678 else if (CSKY_32_IS_SUBI4 (insn2
))
1680 int imm
= (insn2
& 0xfff) + 1;
1684 gdb_printf (gdb_stdlog
,
1685 "csky: subi r4,%d\n", imm
);
1688 else if (CSKY_32_IS_NOR4 (insn2
))
1693 gdb_printf (gdb_stdlog
,
1694 "csky: nor r4,r4,r4\n");
1697 else if (CSKY_32_IS_ROTLI4 (insn2
))
1699 int imm
= ((insn2
>> 21) & 0x1f);
1700 int temp
= adjust
>> (32 - imm
);
1705 gdb_printf (gdb_stdlog
,
1706 "csky: rotli r4,r4,%d\n", imm
);
1709 else if (CSKY_32_IS_LISI4 (insn2
))
1711 int imm
= ((insn2
>> 21) & 0x1f);
1715 gdb_printf (gdb_stdlog
,
1716 "csky: lsli r4,r4,%d\n", imm
);
1719 else if (CSKY_32_IS_BSETI4 (insn2
))
1721 int imm
= ((insn2
>> 21) & 0x1f);
1722 adjust
|= (1 << imm
);
1725 gdb_printf (gdb_stdlog
,
1726 "csky: bseti r4,r4 %d\n", imm
);
1729 else if (CSKY_32_IS_BCLRI4 (insn2
))
1731 int imm
= ((insn2
>> 21) & 0x1f);
1732 adjust
&= ~(1 << imm
);
1735 gdb_printf (gdb_stdlog
,
1736 "csky: bclri r4,r4 %d\n", imm
);
1739 else if (CSKY_32_IS_IXH4 (insn2
))
1744 gdb_printf (gdb_stdlog
,
1745 "csky: ixh r4,r4,r4\n");
1748 else if (CSKY_32_IS_IXW4 (insn2
))
1753 gdb_printf (gdb_stdlog
,
1754 "csky: ixw r4,r4,r4\n");
1757 else if (CSKY_16_IS_ADDI4 (insn2
))
1759 int imm
= (insn2
& 0xff) + 1;
1763 gdb_printf (gdb_stdlog
,
1764 "csky: addi r4,%d\n", imm
);
1767 else if (CSKY_16_IS_SUBI4 (insn2
))
1769 int imm
= (insn2
& 0xff) + 1;
1773 gdb_printf (gdb_stdlog
,
1774 "csky: subi r4,%d\n", imm
);
1777 else if (CSKY_16_IS_NOR4 (insn2
))
1782 gdb_printf (gdb_stdlog
,
1783 "csky: nor r4,r4\n");
1786 else if (CSKY_16_IS_BSETI4 (insn2
))
1788 int imm
= (insn2
& 0x1f);
1789 adjust
|= (1 << imm
);
1792 gdb_printf (gdb_stdlog
,
1793 "csky: bseti r4, %d\n", imm
);
1796 else if (CSKY_16_IS_BCLRI4 (insn2
))
1798 int imm
= (insn2
& 0x1f);
1799 adjust
&= ~(1 << imm
);
1802 gdb_printf (gdb_stdlog
,
1803 "csky: bclri r4, %d\n", imm
);
1806 else if (CSKY_16_IS_LSLI4 (insn2
))
1808 int imm
= (insn2
& 0x1f);
1812 gdb_printf (gdb_stdlog
,
1813 "csky: lsli r4,r4, %d\n", imm
);
1818 insn_len
= csky_get_insn (gdbarch
, addr
+ offset
, &insn2
);
1823 gdb_printf (gdb_stdlog
, "csky: "
1824 "done looking for r4 adjusters\n");
1827 /* If the next instruction adjusts the stack pointer, we keep
1828 everything; if not, we scrap it and we've found the end
1830 if (CSKY_IS_SUBU4 (insn2
))
1833 stacksize
+= adjust
;
1836 gdb_printf (gdb_stdlog
, "csky: "
1837 "found stack adjustment of 0x%x"
1838 " bytes.\n", adjust
);
1839 gdb_printf (gdb_stdlog
, "csky: "
1840 "skipping to new address %s\n",
1841 core_addr_to_string_nz (addr
));
1842 gdb_printf (gdb_stdlog
, "csky: continuing\n");
1847 /* None of these instructions are prologue, so don't touch
1851 gdb_printf (gdb_stdlog
, "csky: no subu sp,r4; "
1852 "NOT altering stacksize.\n");
1858 /* This is not a prologue instruction, so stop here. */
1861 gdb_printf (gdb_stdlog
, "csky: insn is not a prologue"
1862 " insn -- ending scan\n");
1869 CORE_ADDR unwound_fp
;
1870 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1871 this_cache
->framesize
= framesize
;
1875 this_cache
->framereg
= CSKY_FP_REGNUM
;
1876 unwound_fp
= get_frame_register_unsigned (this_frame
,
1877 this_cache
->framereg
);
1878 this_cache
->prev_sp
= unwound_fp
+ adjust_fp
;
1882 this_cache
->framereg
= CSKY_SP_REGNUM
;
1883 unwound_fp
= get_frame_register_unsigned (this_frame
,
1884 this_cache
->framereg
);
1885 this_cache
->prev_sp
= unwound_fp
+ stacksize
;
1888 /* Note where saved registers are stored. The offsets in
1889 REGISTER_OFFSETS are computed relative to the top of the frame. */
1890 for (rn
= 0; rn
< CSKY_NUM_GREGS
; rn
++)
1892 if (register_offsets
[rn
] >= 0)
1894 this_cache
->saved_regs
[rn
].set_addr (this_cache
->prev_sp
1895 - register_offsets
[rn
]);
1898 CORE_ADDR rn_value
= read_memory_unsigned_integer (
1899 this_cache
->saved_regs
[rn
].addr (), 4, byte_order
);
1900 gdb_printf (gdb_stdlog
, "Saved register %s "
1901 "stored at 0x%08lx, value=0x%08lx\n",
1902 csky_register_names
[rn
],
1904 this_cache
->saved_regs
[rn
].addr (),
1905 (unsigned long) rn_value
);
1909 if (lr_type
== LR_TYPE_EPC
)
1912 this_cache
->saved_regs
[CSKY_PC_REGNUM
]
1913 = this_cache
->saved_regs
[CSKY_EPC_REGNUM
];
1915 else if (lr_type
== LR_TYPE_FPC
)
1918 this_cache
->saved_regs
[CSKY_PC_REGNUM
]
1919 = this_cache
->saved_regs
[CSKY_FPC_REGNUM
];
1923 this_cache
->saved_regs
[CSKY_PC_REGNUM
]
1924 = this_cache
->saved_regs
[CSKY_LR_REGNUM
];
1931 /* Detect whether PC is at a point where the stack frame has been
1935 csky_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1939 CORE_ADDR func_start
, func_end
;
1941 if (!find_pc_partial_function (pc
, NULL
, &func_start
, &func_end
))
1944 bool fp_saved
= false;
1946 for (addr
= func_start
; addr
< func_end
; addr
+= insn_len
)
1948 /* Get next insn. */
1949 insn_len
= csky_get_insn (gdbarch
, addr
, &insn
);
1953 /* Is sp is saved to fp. */
1954 if (CSKY_16_IS_MOV_FP_SP (insn
))
1956 /* If sp was saved to fp and now being restored from
1957 fp then it indicates the start of epilog. */
1958 else if (fp_saved
&& CSKY_16_IS_MOV_SP_FP (insn
))
1965 /* Implement the skip_prologue gdbarch hook. */
1968 csky_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1970 CORE_ADDR func_addr
, func_end
;
1971 const int default_search_limit
= 128;
1973 /* See if we can find the end of the prologue using the symbol table. */
1974 if (find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
1976 CORE_ADDR post_prologue_pc
1977 = skip_prologue_using_sal (gdbarch
, func_addr
);
1979 if (post_prologue_pc
!= 0)
1980 return std::max (pc
, post_prologue_pc
);
1983 func_end
= pc
+ default_search_limit
;
1985 /* Find the end of prologue. Default lr_type. */
1986 return csky_analyze_prologue (gdbarch
, pc
, func_end
, func_end
,
1987 NULL
, NULL
, LR_TYPE_R15
);
1990 /* Implement the breakpoint_kind_from_pc gdbarch method. */
1993 csky_breakpoint_kind_from_pc (struct gdbarch
*gdbarch
, CORE_ADDR
*pcptr
)
1995 if (csky_pc_is_csky16 (gdbarch
, *pcptr
))
1996 return CSKY_INSN_SIZE16
;
1998 return CSKY_INSN_SIZE32
;
2001 /* Implement the sw_breakpoint_from_kind gdbarch method. */
2003 static const gdb_byte
*
2004 csky_sw_breakpoint_from_kind (struct gdbarch
*gdbarch
, int kind
, int *size
)
2007 if (kind
== CSKY_INSN_SIZE16
)
2009 static gdb_byte csky_16_breakpoint
[] = { 0, 0 };
2010 return csky_16_breakpoint
;
2014 static gdb_byte csky_32_breakpoint
[] = { 0, 0, 0, 0 };
2015 return csky_32_breakpoint
;
2019 /* Determine link register type. */
2022 csky_analyze_lr_type (struct gdbarch
*gdbarch
,
2023 CORE_ADDR start_pc
, CORE_ADDR end_pc
)
2026 unsigned int insn
, insn_len
;
2029 for (addr
= start_pc
; addr
< end_pc
; addr
+= insn_len
)
2031 insn_len
= csky_get_insn (gdbarch
, addr
, &insn
);
2034 if (CSKY_32_IS_MFCR_EPSR (insn
) || CSKY_32_IS_MFCR_EPC (insn
)
2035 || CSKY_32_IS_RTE (insn
))
2038 else if (CSKY_32_IS_MFCR_FPSR (insn
) || CSKY_32_IS_MFCR_FPC (insn
)
2039 || CSKY_32_IS_RFI (insn
))
2041 else if (CSKY_32_IS_JMP (insn
) || CSKY_32_IS_BR (insn
)
2042 || CSKY_32_IS_JMPIX (insn
) || CSKY_32_IS_JMPI (insn
))
2046 /* 16 bit instruction. */
2047 if (CSKY_16_IS_JMP (insn
) || CSKY_16_IS_BR (insn
)
2048 || CSKY_16_IS_JMPIX (insn
))
2055 /* Heuristic unwinder. */
2057 static struct csky_unwind_cache
*
2058 csky_frame_unwind_cache (struct frame_info
*this_frame
)
2060 CORE_ADDR prologue_start
, prologue_end
, func_end
, prev_pc
, block_addr
;
2061 struct csky_unwind_cache
*cache
;
2062 const struct block
*bl
;
2063 unsigned long func_size
= 0;
2064 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2065 unsigned int sp_regnum
= CSKY_SP_REGNUM
;
2067 /* Default lr type is r15. */
2068 lr_type_t lr_type
= LR_TYPE_R15
;
2070 cache
= FRAME_OBSTACK_ZALLOC (struct csky_unwind_cache
);
2071 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2073 /* Assume there is no frame until proven otherwise. */
2074 cache
->framereg
= sp_regnum
;
2076 cache
->framesize
= 0;
2078 prev_pc
= get_frame_pc (this_frame
);
2079 block_addr
= get_frame_address_in_block (this_frame
);
2080 if (find_pc_partial_function (block_addr
, NULL
, &prologue_start
,
2082 /* We couldn't find a function containing block_addr, so bail out
2083 and hope for the best. */
2086 /* Get the (function) symbol matching prologue_start. */
2087 bl
= block_for_pc (prologue_start
);
2089 func_size
= bl
->end () - bl
->start ();
2092 struct bound_minimal_symbol msymbol
2093 = lookup_minimal_symbol_by_pc (prologue_start
);
2094 if (msymbol
.minsym
!= NULL
)
2095 func_size
= msymbol
.minsym
->size ();
2098 /* If FUNC_SIZE is 0 we may have a special-case use of lr
2099 e.g. exception or interrupt. */
2101 lr_type
= csky_analyze_lr_type (gdbarch
, prologue_start
, func_end
);
2103 prologue_end
= std::min (func_end
, prev_pc
);
2105 /* Analyze the function prologue. */
2106 csky_analyze_prologue (gdbarch
, prologue_start
, prologue_end
,
2107 func_end
, this_frame
, cache
, lr_type
);
2109 /* gdbarch_sp_regnum contains the value and not the address. */
2110 cache
->saved_regs
[sp_regnum
].set_value (cache
->prev_sp
);
2114 /* Implement the this_id function for the normal unwinder. */
2117 csky_frame_this_id (struct frame_info
*this_frame
,
2118 void **this_prologue_cache
, struct frame_id
*this_id
)
2120 struct csky_unwind_cache
*cache
;
2123 if (*this_prologue_cache
== NULL
)
2124 *this_prologue_cache
= csky_frame_unwind_cache (this_frame
);
2125 cache
= (struct csky_unwind_cache
*) *this_prologue_cache
;
2127 /* This marks the outermost frame. */
2128 if (cache
->prev_sp
== 0)
2131 id
= frame_id_build (cache
->prev_sp
, get_frame_func (this_frame
));
2135 /* Implement the prev_register function for the normal unwinder. */
2137 static struct value
*
2138 csky_frame_prev_register (struct frame_info
*this_frame
,
2139 void **this_prologue_cache
, int regnum
)
2141 struct csky_unwind_cache
*cache
;
2143 if (*this_prologue_cache
== NULL
)
2144 *this_prologue_cache
= csky_frame_unwind_cache (this_frame
);
2145 cache
= (struct csky_unwind_cache
*) *this_prologue_cache
;
2147 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
,
2151 /* Data structures for the normal prologue-analysis-based
2154 static const struct frame_unwind csky_unwind_cache
= {
2157 default_frame_unwind_stop_reason
,
2159 csky_frame_prev_register
,
2161 default_frame_sniffer
,
2167 csky_check_long_branch (struct frame_info
*frame
, CORE_ADDR pc
)
2170 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2171 enum bfd_endian byte_order_for_code
2172 = gdbarch_byte_order_for_code (gdbarch
);
2174 if (target_read_memory (pc
, buf
, 8) == 0)
2177 = extract_unsigned_integer (buf
, 4, byte_order_for_code
);
2179 = extract_unsigned_integer (buf
+ 4, 4, byte_order_for_code
);
2181 /* Case: jmpi [pc+4] : 0xeac00001
2183 if (data0
== CSKY_JMPI_PC_4
)
2186 /* Case: lrw t1, [pc+8] : 0xea8d0002
2190 if ((data0
== CSKY_LRW_T1_PC_8
) && (data1
== CSKY_JMP_T1_VS_NOP
))
2192 if (target_read_memory (pc
+ 8, buf
, 4) == 0)
2193 return extract_unsigned_integer (buf
, 4, byte_order_for_code
);
2203 csky_stub_unwind_sniffer (const struct frame_unwind
*self
,
2204 struct frame_info
*this_frame
,
2205 void **this_prologue_cache
)
2207 CORE_ADDR addr_in_block
, pc
;
2210 CORE_ADDR start_addr
;
2213 addr_in_block
= get_frame_address_in_block (this_frame
);
2214 pc
= get_frame_pc (this_frame
);
2216 if (in_plt_section (addr_in_block
)
2217 || target_read_memory (pc
, dummy
, 4) != 0)
2220 /* Find the starting address and name of the function containing the PC. */
2221 if (find_pc_partial_function (pc
, &name
, &start_addr
, NULL
) == 0)
2223 start_addr
= csky_check_long_branch (this_frame
, pc
);
2224 /* if not long branch, return 0. */
2225 if (start_addr
!= 0)
2234 static struct csky_unwind_cache
*
2235 csky_make_stub_cache (struct frame_info
*this_frame
)
2237 struct csky_unwind_cache
*cache
;
2239 cache
= FRAME_OBSTACK_ZALLOC (struct csky_unwind_cache
);
2240 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2241 cache
->prev_sp
= get_frame_register_unsigned (this_frame
, CSKY_SP_REGNUM
);
2247 csky_stub_this_id (struct frame_info
*this_frame
,
2249 struct frame_id
*this_id
)
2251 struct csky_unwind_cache
*cache
;
2253 if (*this_cache
== NULL
)
2254 *this_cache
= csky_make_stub_cache (this_frame
);
2255 cache
= (struct csky_unwind_cache
*) *this_cache
;
2257 /* Our frame ID for a stub frame is the current SP and LR. */
2258 *this_id
= frame_id_build (cache
->prev_sp
, get_frame_pc (this_frame
));
2261 static struct value
*
2262 csky_stub_prev_register (struct frame_info
*this_frame
,
2266 struct csky_unwind_cache
*cache
;
2268 if (*this_cache
== NULL
)
2269 *this_cache
= csky_make_stub_cache (this_frame
);
2270 cache
= (struct csky_unwind_cache
*) *this_cache
;
2272 /* If we are asked to unwind the PC, then return the LR. */
2273 if (prev_regnum
== CSKY_PC_REGNUM
)
2277 lr
= frame_unwind_register_unsigned (this_frame
, CSKY_LR_REGNUM
);
2278 return frame_unwind_got_constant (this_frame
, prev_regnum
, lr
);
2281 if (prev_regnum
== CSKY_SP_REGNUM
)
2282 return frame_unwind_got_constant (this_frame
, prev_regnum
, cache
->prev_sp
);
2284 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
,
2288 static frame_unwind csky_stub_unwind
= {
2291 default_frame_unwind_stop_reason
,
2293 csky_stub_prev_register
,
2295 csky_stub_unwind_sniffer
2298 /* Implement the this_base, this_locals, and this_args hooks
2299 for the normal unwinder. */
2302 csky_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
2304 struct csky_unwind_cache
*cache
;
2306 if (*this_cache
== NULL
)
2307 *this_cache
= csky_frame_unwind_cache (this_frame
);
2308 cache
= (struct csky_unwind_cache
*) *this_cache
;
2310 return cache
->prev_sp
- cache
->framesize
;
2313 static const struct frame_base csky_frame_base
= {
2315 csky_frame_base_address
,
2316 csky_frame_base_address
,
2317 csky_frame_base_address
2320 /* Initialize register access method. */
2323 csky_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
2324 struct dwarf2_frame_state_reg
*reg
,
2325 struct frame_info
*this_frame
)
2327 if (regnum
== gdbarch_pc_regnum (gdbarch
))
2328 reg
->how
= DWARF2_FRAME_REG_RA
;
2329 else if (regnum
== gdbarch_sp_regnum (gdbarch
))
2330 reg
->how
= DWARF2_FRAME_REG_CFA
;
2333 /* Create csky register groups. */
2336 csky_init_reggroup ()
2338 cr_reggroup
= reggroup_new ("cr", USER_REGGROUP
);
2339 fr_reggroup
= reggroup_new ("fr", USER_REGGROUP
);
2340 vr_reggroup
= reggroup_new ("vr", USER_REGGROUP
);
2341 mmu_reggroup
= reggroup_new ("mmu", USER_REGGROUP
);
2342 prof_reggroup
= reggroup_new ("profiling", USER_REGGROUP
);
2345 /* Add register groups into reggroup list. */
2348 csky_add_reggroups (struct gdbarch
*gdbarch
)
2350 reggroup_add (gdbarch
, cr_reggroup
);
2351 reggroup_add (gdbarch
, fr_reggroup
);
2352 reggroup_add (gdbarch
, vr_reggroup
);
2353 reggroup_add (gdbarch
, mmu_reggroup
);
2354 reggroup_add (gdbarch
, prof_reggroup
);
2357 /* Return the groups that a CSKY register can be categorised into. */
2360 csky_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
2361 const struct reggroup
*reggroup
)
2365 if (gdbarch_register_name (gdbarch
, regnum
) == NULL
2366 || gdbarch_register_name (gdbarch
, regnum
)[0] == '\0')
2369 if (reggroup
== all_reggroup
)
2372 raw_p
= regnum
< gdbarch_num_regs (gdbarch
);
2373 if (reggroup
== save_reggroup
|| reggroup
== restore_reggroup
)
2376 if ((((regnum
>= CSKY_R0_REGNUM
) && (regnum
<= CSKY_R0_REGNUM
+ 31))
2377 || (regnum
== CSKY_PC_REGNUM
)
2378 || (regnum
== CSKY_EPC_REGNUM
)
2379 || (regnum
== CSKY_CR0_REGNUM
)
2380 || (regnum
== CSKY_EPSR_REGNUM
))
2381 && (reggroup
== general_reggroup
))
2384 if (((regnum
== CSKY_PC_REGNUM
)
2385 || ((regnum
>= CSKY_CR0_REGNUM
)
2386 && (regnum
<= CSKY_CR0_REGNUM
+ 30)))
2387 && (reggroup
== cr_reggroup
))
2390 if ((((regnum
>= CSKY_VR0_REGNUM
) && (regnum
<= CSKY_VR0_REGNUM
+ 15))
2391 || ((regnum
>= CSKY_FCR_REGNUM
)
2392 && (regnum
<= CSKY_FCR_REGNUM
+ 2)))
2393 && (reggroup
== vr_reggroup
))
2396 if (((regnum
>= CSKY_MMU_REGNUM
) && (regnum
<= CSKY_MMU_REGNUM
+ 8))
2397 && (reggroup
== mmu_reggroup
))
2400 if (((regnum
>= CSKY_PROFCR_REGNUM
)
2401 && (regnum
<= CSKY_PROFCR_REGNUM
+ 48))
2402 && (reggroup
== prof_reggroup
))
2405 if ((((regnum
>= CSKY_FR0_REGNUM
) && (regnum
<= CSKY_FR0_REGNUM
+ 15))
2406 || ((regnum
>= CSKY_FCR_REGNUM
) && (regnum
<= CSKY_FCR_REGNUM
+ 2)))
2407 && (reggroup
== fr_reggroup
))
2410 if (tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
2412 if (tdesc_register_in_reggroup_p (gdbarch
, regnum
, reggroup
) > 0)
2419 /* Implement the dwarf2_reg_to_regnum gdbarch method. */
2422 csky_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int dw_reg
)
2425 if (dw_reg
>= CSKY_R0_REGNUM
&& dw_reg
<= CSKY_R0_REGNUM
+ 31)
2428 /* For Hi, Lo, PC. */
2429 if (dw_reg
== CSKY_HI_REGNUM
|| dw_reg
== CSKY_LO_REGNUM
2430 || dw_reg
== CSKY_PC_REGNUM
)
2433 /* For Float and Vector pseudo registers. */
2434 if (dw_reg
>= FV_PSEUDO_REGNO_FIRST
&& dw_reg
<= FV_PSEUDO_REGNO_LAST
)
2438 xsnprintf (name_buf
, sizeof (name_buf
), "s%d",
2439 dw_reg
- FV_PSEUDO_REGNO_FIRST
);
2440 return user_reg_map_name_to_regnum (gdbarch
, name_buf
,
2444 /* Others, unknown. */
2448 /* Check whether xml has discribled the essential regs. */
2451 csky_essential_reg_check (const struct csky_supported_tdesc_register
*reg
)
2453 if ((strcmp (reg
->name
, "pc") == 0)
2454 && (reg
->num
== CSKY_PC_REGNUM
))
2455 return CSKY_TDESC_REGS_PC_NUMBERED
;
2456 else if ((strcmp (reg
->name
, "r14") == 0)
2457 && (reg
->num
== CSKY_SP_REGNUM
))
2458 return CSKY_TDESC_REGS_SP_NUMBERED
;
2459 else if ((strcmp (reg
->name
, "r15") == 0)
2460 && (reg
->num
== CSKY_LR_REGNUM
))
2461 return CSKY_TDESC_REGS_LR_NUMBERED
;
2466 /* Check whether xml has discribled the fr0~fr15 regs. */
2469 csky_fr0_fr15_reg_check (const struct csky_supported_tdesc_register
*reg
) {
2471 for (i
= 0; i
< 16; i
++)
2473 if ((strcmp (reg
->name
, csky_supported_fpu_regs
[i
].name
) == 0)
2474 && (csky_supported_fpu_regs
[i
].num
== reg
->num
))
2481 /* Check whether xml has discribled the fr16~fr31 regs. */
2484 csky_fr16_fr31_reg_check (const struct csky_supported_tdesc_register
*reg
) {
2486 for (i
= 0; i
< 16; i
++)
2488 if ((strcmp (reg
->name
, csky_supported_fpu_regs
[i
+ 16].name
) == 0)
2489 && (csky_supported_fpu_regs
[i
+ 16].num
== reg
->num
))
2496 /* Check whether xml has discribled the vr0~vr15 regs. */
2499 csky_vr0_vr15_reg_check (const struct csky_supported_tdesc_register
*reg
) {
2501 for (i
= 0; i
< 16; i
++)
2503 if ((strcmp (reg
->name
, csky_supported_fpu_regs
[i
+ 32].name
) == 0)
2504 && (csky_supported_fpu_regs
[i
+ 32].num
== reg
->num
))
2511 /* Return pseudo reg's name. */
2514 csky_pseudo_register_name (struct gdbarch
*gdbarch
, int regno
)
2516 int num_regs
= gdbarch_num_regs (gdbarch
);
2517 csky_gdbarch_tdep
*tdep
2518 = gdbarch_tdep
<csky_gdbarch_tdep
> (gdbarch
);
2522 if (tdep
->fv_pseudo_registers_count
)
2524 static const char *const fv_pseudo_names
[] = {
2525 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
2526 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
2527 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
2528 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
2529 "s32", "s33", "s34", "s35", "s36", "s37", "s38", "s39",
2530 "s40", "s41", "s42", "s43", "s44", "s45", "s46", "s47",
2531 "s48", "s49", "s50", "s51", "s52", "s53", "s54", "s55",
2532 "s56", "s57", "s58", "s59", "s60", "s61", "s62", "s63",
2533 "s64", "s65", "s66", "s67", "s68", "s69", "s70", "s71",
2534 "s72", "s73", "s74", "s75", "s76", "s77", "s78", "s79",
2535 "s80", "s81", "s82", "s83", "s84", "s85", "s86", "s87",
2536 "s88", "s89", "s90", "s91", "s92", "s93", "s94", "s95",
2537 "s96", "s97", "s98", "s99", "s100", "s101", "s102", "s103",
2538 "s104", "s105", "s106", "s107", "s108", "s109", "s110", "s111",
2539 "s112", "s113", "s114", "s115", "s116", "s117", "s118", "s119",
2540 "s120", "s121", "s122", "s123", "s124", "s125", "s126", "s127",
2543 if (regno
< tdep
->fv_pseudo_registers_count
)
2545 if ((regno
< 64) && ((regno
% 4) >= 2) && !tdep
->has_vr0
)
2547 else if ((regno
>= 64) && ((regno
% 4) >= 2))
2550 return fv_pseudo_names
[regno
];
2557 /* Read for csky pseudo regs. */
2559 static enum register_status
2560 csky_pseudo_register_read (struct gdbarch
*gdbarch
,
2561 struct readable_regcache
*regcache
,
2562 int regnum
, gdb_byte
*buf
)
2564 int num_regs
= gdbarch_num_regs (gdbarch
);
2565 csky_gdbarch_tdep
*tdep
2566 = gdbarch_tdep
<csky_gdbarch_tdep
> (gdbarch
);
2570 if (regnum
< tdep
->fv_pseudo_registers_count
)
2572 enum register_status status
;
2575 gdb_byte reg_buf
[16];
2577 /* Ensure getting s0~s63 from vrx if tdep->has_vr0 is ture. */
2582 gdb_regnum
= CSKY_VR0_REGNUM
+ (regnum
/ 4);
2583 offset
= (regnum
% 4) * 4;
2587 gdb_regnum
= CSKY_FR16_REGNUM
+ ((regnum
- 64) / 4);
2588 if ((regnum
% 4) >= 2)
2589 return REG_UNAVAILABLE
;
2590 offset
= (regnum
% 2) * 4;
2595 gdb_regnum
= CSKY_FR0_REGNUM
+ (regnum
/ 4);
2596 if ((regnum
% 4) >= 2)
2597 return REG_UNAVAILABLE
;
2598 offset
= (regnum
% 2) * 4;
2601 status
= regcache
->raw_read (gdb_regnum
, reg_buf
);
2602 if (status
== REG_VALID
)
2603 memcpy (buf
, reg_buf
+ offset
, 4);
2610 /* Write for csky pseudo regs. */
2613 csky_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
2614 int regnum
, const gdb_byte
*buf
)
2616 int num_regs
= gdbarch_num_regs (gdbarch
);
2617 csky_gdbarch_tdep
*tdep
2618 = gdbarch_tdep
<csky_gdbarch_tdep
> (gdbarch
);
2622 if (regnum
< tdep
->fv_pseudo_registers_count
)
2624 gdb_byte reg_buf
[16];
2632 gdb_regnum
= CSKY_VR0_REGNUM
+ (regnum
/ 4);
2633 offset
= (regnum
% 4) * 4;
2637 gdb_regnum
= CSKY_FR16_REGNUM
+ ((regnum
- 64) / 4);
2638 if ((regnum
% 4) >= 2)
2640 offset
= (regnum
% 2) * 4;
2645 gdb_regnum
= CSKY_FR0_REGNUM
+ (regnum
/ 4);
2646 if ((regnum
% 4) >= 2)
2648 offset
= (regnum
% 2) * 4;
2651 regcache
->raw_read (gdb_regnum
, reg_buf
);
2652 memcpy (reg_buf
+ offset
, buf
, 4);
2653 regcache
->raw_write (gdb_regnum
, reg_buf
);
2660 /* Initialize the current architecture based on INFO. If possible,
2661 re-use an architecture from ARCHES, which is a list of
2662 architectures already created during this debugging session.
2664 Called at program startup, when reading a core file, and when
2665 reading a binary file. */
2667 static struct gdbarch
*
2668 csky_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
2670 struct gdbarch
*gdbarch
;
2671 /* Analyze info.abfd. */
2672 unsigned int fpu_abi
= 0;
2673 unsigned int vdsp_version
= 0;
2674 unsigned int fpu_hardfp
= 0;
2675 /* Analyze info.target_desc */
2680 tdesc_arch_data_up tdesc_data
;
2682 if (tdesc_has_registers (info
.target_desc
))
2688 int feature_names_count
= ARRAY_SIZE (csky_supported_tdesc_feature_names
);
2689 int support_tdesc_regs_count
2690 = csky_get_supported_tdesc_registers_count();
2691 const struct csky_supported_tdesc_register
*tdesc_reg
;
2692 const struct tdesc_feature
*feature
;
2694 tdesc_data
= tdesc_data_alloc ();
2695 for (index
= 0; index
< feature_names_count
; index
++)
2697 feature
= tdesc_find_feature (info
.target_desc
,
2698 csky_supported_tdesc_feature_names
[index
]);
2699 if (feature
!= NULL
)
2701 for (i
= 0; i
< support_tdesc_regs_count
; i
++)
2703 tdesc_reg
= csky_get_supported_register_by_index (i
);
2706 numbered
= tdesc_numbered_register (feature
, tdesc_data
.get(),
2710 valid_p
|= csky_essential_reg_check (tdesc_reg
);
2711 has_fr0
|= csky_fr0_fr15_reg_check (tdesc_reg
);
2712 has_fr16
|= csky_fr16_fr31_reg_check (tdesc_reg
);
2713 has_vr0
|= csky_vr0_vr15_reg_check (tdesc_reg
);
2714 if (num_regs
< tdesc_reg
->num
)
2715 num_regs
= tdesc_reg
->num
;
2720 if (valid_p
!= CSKY_TDESC_REGS_ESSENTIAL_VALUE
)
2724 /* When the type of bfd file is srec(or any files are not elf),
2725 the E_FLAGS will be not credible. */
2726 if (info
.abfd
!= NULL
&& bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
2728 /* Get FPU, VDSP build options. */
2729 fpu_abi
= bfd_elf_get_obj_attr_int (info
.abfd
,
2732 vdsp_version
= bfd_elf_get_obj_attr_int (info
.abfd
,
2734 Tag_CSKY_VDSP_VERSION
);
2735 fpu_hardfp
= bfd_elf_get_obj_attr_int (info
.abfd
,
2737 Tag_CSKY_FPU_HARDFP
);
2740 /* Find a candidate among the list of pre-declared architectures. */
2741 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
2743 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
2745 csky_gdbarch_tdep
*tdep
2746 = gdbarch_tdep
<csky_gdbarch_tdep
> (arches
->gdbarch
);
2747 if (fpu_abi
!= tdep
->fpu_abi
)
2749 if (vdsp_version
!= tdep
->vdsp_version
)
2751 if (fpu_hardfp
!= tdep
->fpu_hardfp
)
2754 /* Found a match. */
2755 return arches
->gdbarch
;
2758 /* None found, create a new architecture from the information
2760 csky_gdbarch_tdep
*tdep
= new csky_gdbarch_tdep
;
2761 gdbarch
= gdbarch_alloc (&info
, tdep
);
2762 tdep
->fpu_abi
= fpu_abi
;
2763 tdep
->vdsp_version
= vdsp_version
;
2764 tdep
->fpu_hardfp
= fpu_hardfp
;
2766 if (tdesc_data
!= NULL
)
2768 if ((has_vr0
== CSKY_FULL16_ONEHOT_VALUE
)
2769 && (has_fr16
== CSKY_FULL16_ONEHOT_VALUE
))
2772 tdep
->fv_pseudo_registers_count
= 128;
2774 else if ((has_vr0
== CSKY_FULL16_ONEHOT_VALUE
)
2775 && (has_fr16
!= CSKY_FULL16_ONEHOT_VALUE
))
2778 tdep
->fv_pseudo_registers_count
= 64;
2780 else if ((has_fr0
== CSKY_FULL16_ONEHOT_VALUE
)
2781 && (has_vr0
!= CSKY_FULL16_ONEHOT_VALUE
))
2784 tdep
->fv_pseudo_registers_count
= 64;
2789 tdep
->fv_pseudo_registers_count
= 0;
2795 tdep
->fv_pseudo_registers_count
= 64;
2798 /* Target data types. */
2799 set_gdbarch_ptr_bit (gdbarch
, 32);
2800 set_gdbarch_addr_bit (gdbarch
, 32);
2801 set_gdbarch_short_bit (gdbarch
, 16);
2802 set_gdbarch_int_bit (gdbarch
, 32);
2803 set_gdbarch_long_bit (gdbarch
, 32);
2804 set_gdbarch_long_long_bit (gdbarch
, 64);
2805 set_gdbarch_float_bit (gdbarch
, 32);
2806 set_gdbarch_double_bit (gdbarch
, 64);
2807 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
2808 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
2810 /* Information about the target architecture. */
2811 set_gdbarch_return_value (gdbarch
, csky_return_value
);
2812 set_gdbarch_breakpoint_kind_from_pc (gdbarch
, csky_breakpoint_kind_from_pc
);
2813 set_gdbarch_sw_breakpoint_from_kind (gdbarch
, csky_sw_breakpoint_from_kind
);
2815 /* Register architecture. */
2816 set_gdbarch_num_regs (gdbarch
, CSKY_NUM_REGS
);
2817 set_gdbarch_pc_regnum (gdbarch
, CSKY_PC_REGNUM
);
2818 set_gdbarch_sp_regnum (gdbarch
, CSKY_SP_REGNUM
);
2819 set_gdbarch_register_name (gdbarch
, csky_register_name
);
2820 set_gdbarch_register_type (gdbarch
, csky_register_type
);
2821 set_gdbarch_read_pc (gdbarch
, csky_read_pc
);
2822 set_gdbarch_write_pc (gdbarch
, csky_write_pc
);
2823 csky_add_reggroups (gdbarch
);
2824 set_gdbarch_register_reggroup_p (gdbarch
, csky_register_reggroup_p
);
2825 set_gdbarch_stab_reg_to_regnum (gdbarch
, csky_dwarf_reg_to_regnum
);
2826 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, csky_dwarf_reg_to_regnum
);
2827 dwarf2_frame_set_init_reg (gdbarch
, csky_dwarf2_frame_init_reg
);
2829 /* Functions to analyze frames. */
2830 frame_base_set_default (gdbarch
, &csky_frame_base
);
2831 set_gdbarch_skip_prologue (gdbarch
, csky_skip_prologue
);
2832 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
2833 set_gdbarch_frame_align (gdbarch
, csky_frame_align
);
2834 set_gdbarch_stack_frame_destroyed_p (gdbarch
, csky_stack_frame_destroyed_p
);
2836 /* Functions handling dummy frames. */
2837 set_gdbarch_push_dummy_call (gdbarch
, csky_push_dummy_call
);
2839 /* Frame unwinders. Use DWARF debug info if available,
2840 otherwise use our own unwinder. */
2841 dwarf2_append_unwinders (gdbarch
);
2842 frame_unwind_append_unwinder (gdbarch
, &csky_stub_unwind
);
2843 frame_unwind_append_unwinder (gdbarch
, &csky_unwind_cache
);
2845 /* Hook in ABI-specific overrides, if they have been registered. */
2846 gdbarch_init_osabi (info
, gdbarch
);
2848 /* Support simple overlay manager. */
2849 set_gdbarch_overlay_update (gdbarch
, simple_overlay_update
);
2850 set_gdbarch_char_signed (gdbarch
, 0);
2852 if (tdesc_data
!= nullptr)
2854 set_gdbarch_num_regs (gdbarch
, (num_regs
+ 1));
2855 tdesc_use_registers (gdbarch
, info
.target_desc
, std::move (tdesc_data
));
2856 set_gdbarch_register_type (gdbarch
, csky_register_type
);
2857 set_gdbarch_register_reggroup_p (gdbarch
,
2858 csky_register_reggroup_p
);
2861 if (tdep
->fv_pseudo_registers_count
)
2863 set_gdbarch_num_pseudo_regs (gdbarch
,
2864 tdep
->fv_pseudo_registers_count
);
2865 set_gdbarch_pseudo_register_read (gdbarch
,
2866 csky_pseudo_register_read
);
2867 set_gdbarch_pseudo_register_write (gdbarch
,
2868 csky_pseudo_register_write
);
2869 set_tdesc_pseudo_register_name (gdbarch
, csky_pseudo_register_name
);
2875 void _initialize_csky_tdep ();
2877 _initialize_csky_tdep ()
2880 gdbarch_register (bfd_arch_csky
, csky_gdbarch_init
);
2882 csky_init_reggroup ();
2884 /* Allow debugging this file's internals. */
2885 add_setshow_boolean_cmd ("csky", class_maintenance
, &csky_debug
,
2886 _("Set C-Sky debugging."),
2887 _("Show C-Sky debugging."),
2888 _("When on, C-Sky specific debugging is enabled."),
2891 &setdebuglist
, &showdebuglist
);