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 if (reg_nr
>= gdbarch_num_regs (gdbarch
))
664 return csky_pseudo_register_name (gdbarch
, reg_nr
);
666 if (tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
667 return tdesc_register_name (gdbarch
, reg_nr
);
669 return csky_register_names
[reg_nr
];
672 /* Construct vector type for vrx registers. */
675 csky_vector_type (struct gdbarch
*gdbarch
)
677 const struct builtin_type
*bt
= builtin_type (gdbarch
);
681 t
= arch_composite_type (gdbarch
, "__gdb_builtin_type_vec128i",
684 append_composite_type_field (t
, "u32",
685 init_vector_type (bt
->builtin_int32
, 4));
686 append_composite_type_field (t
, "u16",
687 init_vector_type (bt
->builtin_int16
, 8));
688 append_composite_type_field (t
, "u8",
689 init_vector_type (bt
->builtin_int8
, 16));
691 t
->set_is_vector (true);
692 t
->set_name ("builtin_type_vec128i");
697 /* Return the GDB type object for the "standard" data type
698 of data in register N. */
701 csky_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
703 int num_regs
= gdbarch_num_regs (gdbarch
);
704 csky_gdbarch_tdep
*tdep
705 = gdbarch_tdep
<csky_gdbarch_tdep
> (gdbarch
);
707 if (tdep
->fv_pseudo_registers_count
)
709 if ((reg_nr
>= num_regs
)
710 && (reg_nr
< (num_regs
+ tdep
->fv_pseudo_registers_count
)))
711 return builtin_type (gdbarch
)->builtin_int32
;
714 /* Vector register has 128 bits, and only in ck810. Just return
715 csky_vector_type(), not check tdesc_has_registers(), is in case
716 of some GDB stub does not describe type for Vector resgisters
717 in the target-description-xml. */
718 if ((reg_nr
>= CSKY_VR0_REGNUM
) && (reg_nr
<= CSKY_VR0_REGNUM
+ 15))
719 return csky_vector_type (gdbarch
);
721 /* If type has been described in tdesc-xml, use it. */
722 if (tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
724 struct type
*tdesc_t
= tdesc_register_type (gdbarch
, reg_nr
);
729 /* PC, EPC, FPC is a text pointer. */
730 if ((reg_nr
== CSKY_PC_REGNUM
) || (reg_nr
== CSKY_EPC_REGNUM
)
731 || (reg_nr
== CSKY_FPC_REGNUM
))
732 return builtin_type (gdbarch
)->builtin_func_ptr
;
734 /* VBR is a data pointer. */
735 if (reg_nr
== CSKY_VBR_REGNUM
)
736 return builtin_type (gdbarch
)->builtin_data_ptr
;
738 /* Float register has 64 bits, and only in ck810. */
739 if ((reg_nr
>=CSKY_FR0_REGNUM
) && (reg_nr
<= CSKY_FR0_REGNUM
+ 15))
740 return arch_float_type (gdbarch
, 64, "builtin_type_csky_ext",
741 floatformats_ieee_double
);
743 /* Profiling general register has 48 bits, we use 64bit. */
744 if ((reg_nr
>= CSKY_PROFGR_REGNUM
) && (reg_nr
<= CSKY_PROFGR_REGNUM
+ 44))
745 return builtin_type (gdbarch
)->builtin_uint64
;
747 if (reg_nr
== CSKY_SP_REGNUM
)
748 return builtin_type (gdbarch
)->builtin_data_ptr
;
750 /* Others are 32 bits. */
751 return builtin_type (gdbarch
)->builtin_int32
;
754 /* Data structure to marshall items in a dummy stack frame when
755 calling a function in the inferior. */
757 struct csky_stack_item
759 csky_stack_item (int len_
, const gdb_byte
*data_
)
760 : len (len_
), data (data_
)
764 const gdb_byte
*data
;
767 /* Implement the push_dummy_call gdbarch method. */
770 csky_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
771 struct regcache
*regcache
, CORE_ADDR bp_addr
,
772 int nargs
, struct value
**args
, CORE_ADDR sp
,
773 function_call_return_method return_method
,
774 CORE_ADDR struct_addr
)
777 int argreg
= CSKY_ABI_A0_REGNUM
;
778 int last_arg_regnum
= CSKY_ABI_LAST_ARG_REGNUM
;
779 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
780 std::vector
<csky_stack_item
> stack_items
;
782 /* Set the return address. For CSKY, the return breakpoint is
783 always at BP_ADDR. */
784 regcache_cooked_write_unsigned (regcache
, CSKY_LR_REGNUM
, bp_addr
);
786 /* The struct_return pointer occupies the first parameter
788 if (return_method
== return_method_struct
)
792 gdb_printf (gdb_stdlog
,
793 "csky: struct return in %s = %s\n",
794 gdbarch_register_name (gdbarch
, argreg
),
795 paddress (gdbarch
, struct_addr
));
797 regcache_cooked_write_unsigned (regcache
, argreg
, struct_addr
);
801 /* Put parameters into argument registers in REGCACHE.
802 In ABI argument registers are r0 through r3. */
803 for (argnum
= 0; argnum
< nargs
; argnum
++)
806 struct type
*arg_type
;
809 arg_type
= check_typedef (value_type (args
[argnum
]));
810 len
= arg_type
->length ();
811 val
= value_contents (args
[argnum
]).data ();
813 /* Copy the argument to argument registers or the dummy stack.
814 Large arguments are split between registers and stack.
816 If len < 4, there is no need to worry about endianness since
817 the arguments will always be stored in the low address. */
821 = extract_unsigned_integer (val
, len
, byte_order
);
822 regcache_cooked_write_unsigned (regcache
, argreg
, regval
);
829 int partial_len
= len
< 4 ? len
: 4;
830 if (argreg
<= last_arg_regnum
)
832 /* The argument is passed in an argument register. */
834 = extract_unsigned_integer (val
, partial_len
,
836 if (byte_order
== BFD_ENDIAN_BIG
)
837 regval
<<= (4 - partial_len
) * 8;
839 /* Put regval into register in REGCACHE. */
840 regcache_cooked_write_unsigned (regcache
, argreg
,
846 /* The argument should be pushed onto the dummy stack. */
847 stack_items
.emplace_back (4, val
);
855 /* Transfer the dummy stack frame to the target. */
856 std::vector
<csky_stack_item
>::reverse_iterator iter
;
857 for (iter
= stack_items
.rbegin (); iter
!= stack_items
.rend (); ++iter
)
860 write_memory (sp
, iter
->data
, iter
->len
);
863 /* Finally, update the SP register. */
864 regcache_cooked_write_unsigned (regcache
, CSKY_SP_REGNUM
, sp
);
868 /* Implement the return_value gdbarch method. */
870 static enum return_value_convention
871 csky_return_value (struct gdbarch
*gdbarch
, struct value
*function
,
872 struct type
*valtype
, struct regcache
*regcache
,
873 gdb_byte
*readbuf
, const gdb_byte
*writebuf
)
876 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
877 int len
= valtype
->length ();
878 unsigned int ret_regnum
= CSKY_RET_REGNUM
;
880 /* Csky abi specifies that return values larger than 8 bytes
881 are put on the stack. */
883 return RETURN_VALUE_STRUCT_CONVENTION
;
889 /* By using store_unsigned_integer we avoid having to do
890 anything special for small big-endian values. */
891 regcache
->cooked_read (ret_regnum
, &tmp
);
892 store_unsigned_integer (readbuf
, (len
> 4 ? 4 : len
),
896 regcache
->cooked_read (ret_regnum
+ 1, &tmp
);
897 store_unsigned_integer (readbuf
+ 4, 4, byte_order
, tmp
);
900 if (writebuf
!= NULL
)
902 regval
= extract_unsigned_integer (writebuf
, len
> 4 ? 4 : len
,
904 regcache_cooked_write_unsigned (regcache
, ret_regnum
, regval
);
907 regval
= extract_unsigned_integer ((gdb_byte
*) writebuf
+ 4,
909 regcache_cooked_write_unsigned (regcache
, ret_regnum
+ 1,
914 return RETURN_VALUE_REGISTER_CONVENTION
;
918 /* Implement the frame_align gdbarch method.
920 Adjust the address downward (direction of stack growth) so that it
921 is correctly aligned for a new stack frame. */
924 csky_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
926 return align_down (addr
, 4);
929 /* Unwind cache used for gdbarch fallback unwinder. */
931 struct csky_unwind_cache
933 /* The stack pointer at the time this frame was created; i.e. the
934 caller's stack pointer when this function was called. It is used
935 to identify this frame. */
938 /* The frame base for this frame is just prev_sp - frame size.
939 FRAMESIZE is the distance from the frame pointer to the
940 initial stack pointer. */
943 /* The register used to hold the frame pointer for this frame. */
946 /* Saved register offsets. */
947 trad_frame_saved_reg
*saved_regs
;
950 /* Do prologue analysis, returning the PC of the first instruction
951 after the function prologue. */
954 csky_analyze_prologue (struct gdbarch
*gdbarch
,
958 frame_info_ptr this_frame
,
959 struct csky_unwind_cache
*this_cache
,
963 unsigned int insn
, rn
;
966 int register_offsets
[CSKY_NUM_GREGS_SAVED_GREGS
];
968 /* For adjusting fp. */
972 /* REGISTER_OFFSETS will contain offsets from the top of the frame
973 (NOT the frame pointer) for the various saved registers, or -1
974 if the register is not saved. */
975 for (rn
= 0; rn
< CSKY_NUM_GREGS_SAVED_GREGS
; rn
++)
976 register_offsets
[rn
] = -1;
978 /* Analyze the prologue. Things we determine from analyzing the
979 prologue include the size of the frame and which registers are
980 saved (and where). */
983 gdb_printf (gdb_stdlog
,
984 "csky: Scanning prologue: start_pc = 0x%x,"
985 "limit_pc = 0x%x\n", (unsigned int) start_pc
,
986 (unsigned int) limit_pc
);
989 /* Default to 16 bit instruction. */
992 for (addr
= start_pc
; addr
< limit_pc
; addr
+= insn_len
)
995 insn_len
= csky_get_insn (gdbarch
, addr
, &insn
);
997 /* Check if 32 bit. */
1000 /* subi32 sp,sp oimm12. */
1001 if (CSKY_32_IS_SUBI0 (insn
))
1004 int offset
= CSKY_32_SUBI_IMM (insn
);
1007 gdb_printf (gdb_stdlog
,
1008 "csky: got subi sp,%d; continuing\n",
1011 stacksize
+= offset
;
1014 /* stm32 ry-rz,(sp). */
1015 else if (CSKY_32_IS_STMx0 (insn
))
1017 /* Spill register(s). */
1022 /* BIG WARNING! The CKCore ABI does not restrict functions
1023 to taking only one stack allocation. Therefore, when
1024 we save a register, we record the offset of where it was
1025 saved relative to the current stacksize. This will
1026 then give an offset from the SP upon entry to our
1027 function. Remember, stacksize is NOT constant until
1028 we're done scanning the prologue. */
1029 start_register
= CSKY_32_STM_VAL_REGNUM (insn
);
1030 reg_count
= CSKY_32_STM_SIZE (insn
);
1033 gdb_printf (gdb_stdlog
,
1034 "csky: got stm r%d-r%d,(sp)\n",
1036 start_register
+ reg_count
);
1039 for (rn
= start_register
, offset
= 0;
1040 rn
<= start_register
+ reg_count
;
1043 register_offsets
[rn
] = stacksize
- offset
;
1046 gdb_printf (gdb_stdlog
,
1047 "csky: r%d saved at 0x%x"
1049 rn
, register_offsets
[rn
],
1054 gdb_printf (gdb_stdlog
, "csky: continuing\n");
1057 /* stw ry,(sp,disp). */
1058 else if (CSKY_32_IS_STWx0 (insn
))
1060 /* Spill register: see note for IS_STM above. */
1063 rn
= CSKY_32_ST_VAL_REGNUM (insn
);
1064 disp
= CSKY_32_ST_OFFSET (insn
);
1065 register_offsets
[rn
] = stacksize
- disp
;
1067 print_savedreg_msg (rn
, register_offsets
, true);
1070 else if (CSKY_32_IS_MOV_FP_SP (insn
))
1072 /* SP is saved to FP reg, means code afer prologue may
1075 adjust_fp
= stacksize
;
1078 else if (CSKY_32_IS_MFCR_EPSR (insn
))
1082 int mfcr_regnum
= insn
& 0x1f;
1083 insn_len
= csky_get_insn (gdbarch
, addr
, &insn2
);
1086 int stw_regnum
= (insn2
>> 5) & 0x7;
1087 if (CSKY_16_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1091 /* CSKY_EPSR_REGNUM. */
1092 rn
= CSKY_NUM_GREGS
;
1093 offset
= CSKY_16_STWx0_OFFSET (insn2
);
1094 register_offsets
[rn
] = stacksize
- offset
;
1096 print_savedreg_msg (rn
, register_offsets
, true);
1103 /* INSN_LEN == 4. */
1104 int stw_regnum
= (insn2
>> 21) & 0x1f;
1105 if (CSKY_32_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1109 /* CSKY_EPSR_REGNUM. */
1110 rn
= CSKY_NUM_GREGS
;
1111 offset
= CSKY_32_ST_OFFSET (insn2
);
1112 register_offsets
[rn
] = framesize
- offset
;
1114 print_savedreg_msg (rn
, register_offsets
, true);
1120 else if (CSKY_32_IS_MFCR_FPSR (insn
))
1124 int mfcr_regnum
= insn
& 0x1f;
1125 insn_len
= csky_get_insn (gdbarch
, addr
, &insn2
);
1128 int stw_regnum
= (insn2
>> 5) & 0x7;
1129 if (CSKY_16_IS_STWx0 (insn2
) && (mfcr_regnum
1134 /* CSKY_FPSR_REGNUM. */
1135 rn
= CSKY_NUM_GREGS
+ 1;
1136 offset
= CSKY_16_STWx0_OFFSET (insn2
);
1137 register_offsets
[rn
] = stacksize
- offset
;
1139 print_savedreg_msg (rn
, register_offsets
, true);
1146 /* INSN_LEN == 4. */
1147 int stw_regnum
= (insn2
>> 21) & 0x1f;
1148 if (CSKY_32_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1152 /* CSKY_FPSR_REGNUM. */
1153 rn
= CSKY_NUM_GREGS
+ 1;
1154 offset
= CSKY_32_ST_OFFSET (insn2
);
1155 register_offsets
[rn
] = framesize
- offset
;
1157 print_savedreg_msg (rn
, register_offsets
, true);
1163 else if (CSKY_32_IS_MFCR_EPC (insn
))
1167 int mfcr_regnum
= insn
& 0x1f;
1168 insn_len
= csky_get_insn (gdbarch
, addr
, &insn2
);
1171 int stw_regnum
= (insn2
>> 5) & 0x7;
1172 if (CSKY_16_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1176 /* CSKY_EPC_REGNUM. */
1177 rn
= CSKY_NUM_GREGS
+ 2;
1178 offset
= CSKY_16_STWx0_OFFSET (insn2
);
1179 register_offsets
[rn
] = stacksize
- offset
;
1181 print_savedreg_msg (rn
, register_offsets
, true);
1188 /* INSN_LEN == 4. */
1189 int stw_regnum
= (insn2
>> 21) & 0x1f;
1190 if (CSKY_32_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1194 /* CSKY_EPC_REGNUM. */
1195 rn
= CSKY_NUM_GREGS
+ 2;
1196 offset
= CSKY_32_ST_OFFSET (insn2
);
1197 register_offsets
[rn
] = framesize
- offset
;
1199 print_savedreg_msg (rn
, register_offsets
, true);
1205 else if (CSKY_32_IS_MFCR_FPC (insn
))
1209 int mfcr_regnum
= insn
& 0x1f;
1210 insn_len
= csky_get_insn (gdbarch
, addr
, &insn2
);
1213 int stw_regnum
= (insn2
>> 5) & 0x7;
1214 if (CSKY_16_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1218 /* CSKY_FPC_REGNUM. */
1219 rn
= CSKY_NUM_GREGS
+ 3;
1220 offset
= CSKY_16_STWx0_OFFSET (insn2
);
1221 register_offsets
[rn
] = stacksize
- offset
;
1223 print_savedreg_msg (rn
, register_offsets
, true);
1230 /* INSN_LEN == 4. */
1231 int stw_regnum
= (insn2
>> 21) & 0x1f;
1232 if (CSKY_32_IS_STWx0 (insn2
) && (mfcr_regnum
== stw_regnum
))
1236 /* CSKY_FPC_REGNUM. */
1237 rn
= CSKY_NUM_GREGS
+ 3;
1238 offset
= CSKY_32_ST_OFFSET (insn2
);
1239 register_offsets
[rn
] = framesize
- offset
;
1241 print_savedreg_msg (rn
, register_offsets
, true);
1247 else if (CSKY_32_IS_PUSH (insn
))
1249 /* Push for 32_bit. */
1250 if (CSKY_32_IS_PUSH_R29 (insn
))
1253 register_offsets
[29] = stacksize
;
1255 print_savedreg_msg (29, register_offsets
, false);
1257 if (CSKY_32_PUSH_LIST2 (insn
))
1259 int num
= CSKY_32_PUSH_LIST2 (insn
);
1261 stacksize
+= num
* 4;
1264 gdb_printf (gdb_stdlog
,
1265 "csky: push regs_array: r16-r%d\n",
1268 for (rn
= 16; rn
<= 16 + num
- 1; rn
++)
1270 register_offsets
[rn
] = stacksize
- tmp
;
1273 gdb_printf (gdb_stdlog
,
1274 "csky: r%d saved at 0x%x"
1275 " (offset %d)\n", rn
,
1276 register_offsets
[rn
], tmp
);
1281 if (CSKY_32_IS_PUSH_R15 (insn
))
1284 register_offsets
[15] = stacksize
;
1286 print_savedreg_msg (15, register_offsets
, false);
1288 if (CSKY_32_PUSH_LIST1 (insn
))
1290 int num
= CSKY_32_PUSH_LIST1 (insn
);
1292 stacksize
+= num
* 4;
1295 gdb_printf (gdb_stdlog
,
1296 "csky: push regs_array: r4-r%d\n",
1299 for (rn
= 4; rn
<= 4 + num
- 1; rn
++)
1301 register_offsets
[rn
] = stacksize
- tmp
;
1304 gdb_printf (gdb_stdlog
,
1305 "csky: r%d saved at 0x%x"
1306 " (offset %d)\n", rn
,
1307 register_offsets
[rn
], tmp
);
1313 framesize
= stacksize
;
1315 gdb_printf (gdb_stdlog
, "csky: continuing\n");
1318 else if (CSKY_32_IS_LRW4 (insn
) || CSKY_32_IS_MOVI4 (insn
)
1319 || CSKY_32_IS_MOVIH4 (insn
) || CSKY_32_IS_BMASKI4 (insn
))
1327 gdb_printf (gdb_stdlog
,
1328 "csky: looking at large frame\n");
1330 if (CSKY_32_IS_LRW4 (insn
))
1332 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1333 int literal_addr
= (addr
+ ((insn
& 0xffff) << 2))
1335 adjust
= read_memory_unsigned_integer (literal_addr
, 4,
1338 else if (CSKY_32_IS_MOVI4 (insn
))
1339 adjust
= (insn
& 0xffff);
1340 else if (CSKY_32_IS_MOVIH4 (insn
))
1341 adjust
= (insn
& 0xffff) << 16;
1344 /* CSKY_32_IS_BMASKI4 (insn). */
1345 adjust
= (1 << (((insn
& 0x3e00000) >> 21) + 1)) - 1;
1350 gdb_printf (gdb_stdlog
,
1351 "csky: base stacksize=0x%x\n", adjust
);
1353 /* May have zero or more insns which modify r4. */
1354 gdb_printf (gdb_stdlog
,
1355 "csky: looking for r4 adjusters...\n");
1359 insn_len
= csky_get_insn (gdbarch
, addr
+ offset
, &insn2
);
1360 while (CSKY_IS_R4_ADJUSTER (insn2
))
1362 if (CSKY_32_IS_ADDI4 (insn2
))
1364 int imm
= (insn2
& 0xfff) + 1;
1368 gdb_printf (gdb_stdlog
,
1369 "csky: addi r4,%d\n", imm
);
1372 else if (CSKY_32_IS_SUBI4 (insn2
))
1374 int imm
= (insn2
& 0xfff) + 1;
1378 gdb_printf (gdb_stdlog
,
1379 "csky: subi r4,%d\n", imm
);
1382 else if (CSKY_32_IS_NOR4 (insn2
))
1387 gdb_printf (gdb_stdlog
,
1388 "csky: nor r4,r4,r4\n");
1391 else if (CSKY_32_IS_ROTLI4 (insn2
))
1393 int imm
= ((insn2
>> 21) & 0x1f);
1394 int temp
= adjust
>> (32 - imm
);
1399 gdb_printf (gdb_stdlog
,
1400 "csky: rotli r4,r4,%d\n", imm
);
1403 else if (CSKY_32_IS_LISI4 (insn2
))
1405 int imm
= ((insn2
>> 21) & 0x1f);
1409 gdb_printf (gdb_stdlog
,
1410 "csky: lsli r4,r4,%d\n", imm
);
1413 else if (CSKY_32_IS_BSETI4 (insn2
))
1415 int imm
= ((insn2
>> 21) & 0x1f);
1416 adjust
|= (1 << imm
);
1419 gdb_printf (gdb_stdlog
,
1420 "csky: bseti r4,r4 %d\n", imm
);
1423 else if (CSKY_32_IS_BCLRI4 (insn2
))
1425 int imm
= ((insn2
>> 21) & 0x1f);
1426 adjust
&= ~(1 << imm
);
1429 gdb_printf (gdb_stdlog
,
1430 "csky: bclri r4,r4 %d\n", imm
);
1433 else if (CSKY_32_IS_IXH4 (insn2
))
1438 gdb_printf (gdb_stdlog
,
1439 "csky: ixh r4,r4,r4\n");
1442 else if (CSKY_32_IS_IXW4 (insn2
))
1447 gdb_printf (gdb_stdlog
,
1448 "csky: ixw r4,r4,r4\n");
1451 else if (CSKY_16_IS_ADDI4 (insn2
))
1453 int imm
= (insn2
& 0xff) + 1;
1457 gdb_printf (gdb_stdlog
,
1458 "csky: addi r4,%d\n", imm
);
1461 else if (CSKY_16_IS_SUBI4 (insn2
))
1463 int imm
= (insn2
& 0xff) + 1;
1467 gdb_printf (gdb_stdlog
,
1468 "csky: subi r4,%d\n", imm
);
1471 else if (CSKY_16_IS_NOR4 (insn2
))
1476 gdb_printf (gdb_stdlog
,
1477 "csky: nor r4,r4\n");
1480 else if (CSKY_16_IS_BSETI4 (insn2
))
1482 int imm
= (insn2
& 0x1f);
1483 adjust
|= (1 << imm
);
1486 gdb_printf (gdb_stdlog
,
1487 "csky: bseti r4, %d\n", imm
);
1490 else if (CSKY_16_IS_BCLRI4 (insn2
))
1492 int imm
= (insn2
& 0x1f);
1493 adjust
&= ~(1 << imm
);
1496 gdb_printf (gdb_stdlog
,
1497 "csky: bclri r4, %d\n", imm
);
1500 else if (CSKY_16_IS_LSLI4 (insn2
))
1502 int imm
= (insn2
& 0x1f);
1506 gdb_printf (gdb_stdlog
,
1507 "csky: lsli r4,r4, %d\n", imm
);
1512 insn_len
= csky_get_insn (gdbarch
, addr
+ offset
, &insn2
);
1517 gdb_printf (gdb_stdlog
, "csky: done looking for"
1521 /* If the next insn adjusts the stack pointer, we keep
1522 everything; if not, we scrap it and we've found the
1523 end of the prologue. */
1524 if (CSKY_IS_SUBU4 (insn2
))
1527 stacksize
+= adjust
;
1530 gdb_printf (gdb_stdlog
,
1531 "csky: found stack adjustment of"
1532 " 0x%x bytes.\n", adjust
);
1533 gdb_printf (gdb_stdlog
,
1534 "csky: skipping to new address %s\n",
1535 core_addr_to_string_nz (addr
));
1536 gdb_printf (gdb_stdlog
,
1537 "csky: continuing\n");
1542 /* None of these instructions are prologue, so don't touch
1546 gdb_printf (gdb_stdlog
,
1547 "csky: no subu sp,sp,r4; NOT altering"
1555 /* insn_len != 4. */
1557 /* subi.sp sp,disp. */
1558 if (CSKY_16_IS_SUBI0 (insn
))
1560 int offset
= CSKY_16_SUBI_IMM (insn
);
1563 gdb_printf (gdb_stdlog
,
1564 "csky: got subi r0,%d; continuing\n",
1567 stacksize
+= offset
;
1570 /* stw.16 rz,(sp,disp). */
1571 else if (CSKY_16_IS_STWx0 (insn
))
1573 /* Spill register: see note for IS_STM above. */
1576 rn
= CSKY_16_ST_VAL_REGNUM (insn
);
1577 disp
= CSKY_16_ST_OFFSET (insn
);
1578 register_offsets
[rn
] = stacksize
- disp
;
1580 print_savedreg_msg (rn
, register_offsets
, true);
1583 else if (CSKY_16_IS_MOV_FP_SP (insn
))
1585 /* SP is saved to FP reg, means prologue may modify SP. */
1587 adjust_fp
= stacksize
;
1590 else if (CSKY_16_IS_PUSH (insn
))
1592 /* Push for 16_bit. */
1594 if (CSKY_16_IS_PUSH_R15 (insn
))
1597 register_offsets
[15] = stacksize
;
1599 print_savedreg_msg (15, register_offsets
, false);
1602 if (CSKY_16_PUSH_LIST1 (insn
))
1604 int num
= CSKY_16_PUSH_LIST1 (insn
);
1606 stacksize
+= num
* 4;
1610 gdb_printf (gdb_stdlog
,
1611 "csky: push regs_array: r4-r%d\n",
1614 for (rn
= 4; rn
<= 4 + num
- 1; rn
++)
1616 register_offsets
[rn
] = stacksize
- tmp
;
1619 gdb_printf (gdb_stdlog
,
1620 "csky: r%d saved at 0x%x"
1621 " (offset %d)\n", rn
,
1622 register_offsets
[rn
], offset
);
1628 framesize
= stacksize
;
1630 gdb_printf (gdb_stdlog
, "csky: continuing\n");
1633 else if (CSKY_16_IS_LRW4 (insn
) || CSKY_16_IS_MOVI4 (insn
))
1640 gdb_printf (gdb_stdlog
,
1641 "csky: looking at large frame\n");
1643 if (CSKY_16_IS_LRW4 (insn
))
1645 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1646 int offset
= ((insn
& 0x300) >> 3) | (insn
& 0x1f);
1647 int literal_addr
= (addr
+ ( offset
<< 2)) & 0xfffffffc;
1648 adjust
= read_memory_unsigned_integer (literal_addr
, 4,
1653 /* CSKY_16_IS_MOVI4 (insn). */
1654 adjust
= (insn
& 0xff);
1659 gdb_printf (gdb_stdlog
,
1660 "csky: base stacksize=0x%x\n", adjust
);
1663 /* May have zero or more instructions which modify r4. */
1666 gdb_printf (gdb_stdlog
,
1667 "csky: looking for r4 adjusters...\n");
1670 insn_len
= csky_get_insn (gdbarch
, addr
+ offset
, &insn2
);
1671 while (CSKY_IS_R4_ADJUSTER (insn2
))
1673 if (CSKY_32_IS_ADDI4 (insn2
))
1675 int imm
= (insn2
& 0xfff) + 1;
1679 gdb_printf (gdb_stdlog
,
1680 "csky: addi r4,%d\n", imm
);
1683 else if (CSKY_32_IS_SUBI4 (insn2
))
1685 int imm
= (insn2
& 0xfff) + 1;
1689 gdb_printf (gdb_stdlog
,
1690 "csky: subi r4,%d\n", imm
);
1693 else if (CSKY_32_IS_NOR4 (insn2
))
1698 gdb_printf (gdb_stdlog
,
1699 "csky: nor r4,r4,r4\n");
1702 else if (CSKY_32_IS_ROTLI4 (insn2
))
1704 int imm
= ((insn2
>> 21) & 0x1f);
1705 int temp
= adjust
>> (32 - imm
);
1710 gdb_printf (gdb_stdlog
,
1711 "csky: rotli r4,r4,%d\n", imm
);
1714 else if (CSKY_32_IS_LISI4 (insn2
))
1716 int imm
= ((insn2
>> 21) & 0x1f);
1720 gdb_printf (gdb_stdlog
,
1721 "csky: lsli r4,r4,%d\n", imm
);
1724 else if (CSKY_32_IS_BSETI4 (insn2
))
1726 int imm
= ((insn2
>> 21) & 0x1f);
1727 adjust
|= (1 << imm
);
1730 gdb_printf (gdb_stdlog
,
1731 "csky: bseti r4,r4 %d\n", imm
);
1734 else if (CSKY_32_IS_BCLRI4 (insn2
))
1736 int imm
= ((insn2
>> 21) & 0x1f);
1737 adjust
&= ~(1 << imm
);
1740 gdb_printf (gdb_stdlog
,
1741 "csky: bclri r4,r4 %d\n", imm
);
1744 else if (CSKY_32_IS_IXH4 (insn2
))
1749 gdb_printf (gdb_stdlog
,
1750 "csky: ixh r4,r4,r4\n");
1753 else if (CSKY_32_IS_IXW4 (insn2
))
1758 gdb_printf (gdb_stdlog
,
1759 "csky: ixw r4,r4,r4\n");
1762 else if (CSKY_16_IS_ADDI4 (insn2
))
1764 int imm
= (insn2
& 0xff) + 1;
1768 gdb_printf (gdb_stdlog
,
1769 "csky: addi r4,%d\n", imm
);
1772 else if (CSKY_16_IS_SUBI4 (insn2
))
1774 int imm
= (insn2
& 0xff) + 1;
1778 gdb_printf (gdb_stdlog
,
1779 "csky: subi r4,%d\n", imm
);
1782 else if (CSKY_16_IS_NOR4 (insn2
))
1787 gdb_printf (gdb_stdlog
,
1788 "csky: nor r4,r4\n");
1791 else if (CSKY_16_IS_BSETI4 (insn2
))
1793 int imm
= (insn2
& 0x1f);
1794 adjust
|= (1 << imm
);
1797 gdb_printf (gdb_stdlog
,
1798 "csky: bseti r4, %d\n", imm
);
1801 else if (CSKY_16_IS_BCLRI4 (insn2
))
1803 int imm
= (insn2
& 0x1f);
1804 adjust
&= ~(1 << imm
);
1807 gdb_printf (gdb_stdlog
,
1808 "csky: bclri r4, %d\n", imm
);
1811 else if (CSKY_16_IS_LSLI4 (insn2
))
1813 int imm
= (insn2
& 0x1f);
1817 gdb_printf (gdb_stdlog
,
1818 "csky: lsli r4,r4, %d\n", imm
);
1823 insn_len
= csky_get_insn (gdbarch
, addr
+ offset
, &insn2
);
1828 gdb_printf (gdb_stdlog
, "csky: "
1829 "done looking for r4 adjusters\n");
1832 /* If the next instruction adjusts the stack pointer, we keep
1833 everything; if not, we scrap it and we've found the end
1835 if (CSKY_IS_SUBU4 (insn2
))
1838 stacksize
+= adjust
;
1841 gdb_printf (gdb_stdlog
, "csky: "
1842 "found stack adjustment of 0x%x"
1843 " bytes.\n", adjust
);
1844 gdb_printf (gdb_stdlog
, "csky: "
1845 "skipping to new address %s\n",
1846 core_addr_to_string_nz (addr
));
1847 gdb_printf (gdb_stdlog
, "csky: continuing\n");
1852 /* None of these instructions are prologue, so don't touch
1856 gdb_printf (gdb_stdlog
, "csky: no subu sp,r4; "
1857 "NOT altering stacksize.\n");
1863 /* This is not a prologue instruction, so stop here. */
1866 gdb_printf (gdb_stdlog
, "csky: insn is not a prologue"
1867 " insn -- ending scan\n");
1874 CORE_ADDR unwound_fp
;
1875 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1876 this_cache
->framesize
= framesize
;
1880 this_cache
->framereg
= CSKY_FP_REGNUM
;
1881 unwound_fp
= get_frame_register_unsigned (this_frame
,
1882 this_cache
->framereg
);
1883 this_cache
->prev_sp
= unwound_fp
+ adjust_fp
;
1887 this_cache
->framereg
= CSKY_SP_REGNUM
;
1888 unwound_fp
= get_frame_register_unsigned (this_frame
,
1889 this_cache
->framereg
);
1890 this_cache
->prev_sp
= unwound_fp
+ stacksize
;
1893 /* Note where saved registers are stored. The offsets in
1894 REGISTER_OFFSETS are computed relative to the top of the frame. */
1895 for (rn
= 0; rn
< CSKY_NUM_GREGS
; rn
++)
1897 if (register_offsets
[rn
] >= 0)
1899 this_cache
->saved_regs
[rn
].set_addr (this_cache
->prev_sp
1900 - register_offsets
[rn
]);
1903 CORE_ADDR rn_value
= read_memory_unsigned_integer (
1904 this_cache
->saved_regs
[rn
].addr (), 4, byte_order
);
1905 gdb_printf (gdb_stdlog
, "Saved register %s "
1906 "stored at 0x%08lx, value=0x%08lx\n",
1907 csky_register_names
[rn
],
1909 this_cache
->saved_regs
[rn
].addr (),
1910 (unsigned long) rn_value
);
1914 if (lr_type
== LR_TYPE_EPC
)
1917 this_cache
->saved_regs
[CSKY_PC_REGNUM
]
1918 = this_cache
->saved_regs
[CSKY_EPC_REGNUM
];
1920 else if (lr_type
== LR_TYPE_FPC
)
1923 this_cache
->saved_regs
[CSKY_PC_REGNUM
]
1924 = this_cache
->saved_regs
[CSKY_FPC_REGNUM
];
1928 this_cache
->saved_regs
[CSKY_PC_REGNUM
]
1929 = this_cache
->saved_regs
[CSKY_LR_REGNUM
];
1936 /* Detect whether PC is at a point where the stack frame has been
1940 csky_stack_frame_destroyed_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1944 CORE_ADDR func_start
, func_end
;
1946 if (!find_pc_partial_function (pc
, NULL
, &func_start
, &func_end
))
1949 bool fp_saved
= false;
1951 for (addr
= func_start
; addr
< func_end
; addr
+= insn_len
)
1953 /* Get next insn. */
1954 insn_len
= csky_get_insn (gdbarch
, addr
, &insn
);
1958 /* Is sp is saved to fp. */
1959 if (CSKY_16_IS_MOV_FP_SP (insn
))
1961 /* If sp was saved to fp and now being restored from
1962 fp then it indicates the start of epilog. */
1963 else if (fp_saved
&& CSKY_16_IS_MOV_SP_FP (insn
))
1970 /* Implement the skip_prologue gdbarch hook. */
1973 csky_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1975 CORE_ADDR func_addr
, func_end
;
1976 const int default_search_limit
= 128;
1978 /* See if we can find the end of the prologue using the symbol table. */
1979 if (find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
1981 CORE_ADDR post_prologue_pc
1982 = skip_prologue_using_sal (gdbarch
, func_addr
);
1984 if (post_prologue_pc
!= 0)
1985 return std::max (pc
, post_prologue_pc
);
1988 func_end
= pc
+ default_search_limit
;
1990 /* Find the end of prologue. Default lr_type. */
1991 return csky_analyze_prologue (gdbarch
, pc
, func_end
, func_end
,
1992 NULL
, NULL
, LR_TYPE_R15
);
1995 /* Implement the breakpoint_kind_from_pc gdbarch method. */
1998 csky_breakpoint_kind_from_pc (struct gdbarch
*gdbarch
, CORE_ADDR
*pcptr
)
2000 if (csky_pc_is_csky16 (gdbarch
, *pcptr
))
2001 return CSKY_INSN_SIZE16
;
2003 return CSKY_INSN_SIZE32
;
2006 /* Implement the sw_breakpoint_from_kind gdbarch method. */
2008 static const gdb_byte
*
2009 csky_sw_breakpoint_from_kind (struct gdbarch
*gdbarch
, int kind
, int *size
)
2012 if (kind
== CSKY_INSN_SIZE16
)
2014 static gdb_byte csky_16_breakpoint
[] = { 0, 0 };
2015 return csky_16_breakpoint
;
2019 static gdb_byte csky_32_breakpoint
[] = { 0, 0, 0, 0 };
2020 return csky_32_breakpoint
;
2024 /* Determine link register type. */
2027 csky_analyze_lr_type (struct gdbarch
*gdbarch
,
2028 CORE_ADDR start_pc
, CORE_ADDR end_pc
)
2031 unsigned int insn
, insn_len
;
2034 for (addr
= start_pc
; addr
< end_pc
; addr
+= insn_len
)
2036 insn_len
= csky_get_insn (gdbarch
, addr
, &insn
);
2039 if (CSKY_32_IS_MFCR_EPSR (insn
) || CSKY_32_IS_MFCR_EPC (insn
)
2040 || CSKY_32_IS_RTE (insn
))
2043 else if (CSKY_32_IS_MFCR_FPSR (insn
) || CSKY_32_IS_MFCR_FPC (insn
)
2044 || CSKY_32_IS_RFI (insn
))
2046 else if (CSKY_32_IS_JMP (insn
) || CSKY_32_IS_BR (insn
)
2047 || CSKY_32_IS_JMPIX (insn
) || CSKY_32_IS_JMPI (insn
))
2051 /* 16 bit instruction. */
2052 if (CSKY_16_IS_JMP (insn
) || CSKY_16_IS_BR (insn
)
2053 || CSKY_16_IS_JMPIX (insn
))
2060 /* Heuristic unwinder. */
2062 static struct csky_unwind_cache
*
2063 csky_frame_unwind_cache (frame_info_ptr this_frame
)
2065 CORE_ADDR prologue_start
, prologue_end
, func_end
, prev_pc
, block_addr
;
2066 struct csky_unwind_cache
*cache
;
2067 const struct block
*bl
;
2068 unsigned long func_size
= 0;
2069 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
2070 unsigned int sp_regnum
= CSKY_SP_REGNUM
;
2072 /* Default lr type is r15. */
2073 lr_type_t lr_type
= LR_TYPE_R15
;
2075 cache
= FRAME_OBSTACK_ZALLOC (struct csky_unwind_cache
);
2076 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2078 /* Assume there is no frame until proven otherwise. */
2079 cache
->framereg
= sp_regnum
;
2081 cache
->framesize
= 0;
2083 prev_pc
= get_frame_pc (this_frame
);
2084 block_addr
= get_frame_address_in_block (this_frame
);
2085 if (find_pc_partial_function (block_addr
, NULL
, &prologue_start
,
2087 /* We couldn't find a function containing block_addr, so bail out
2088 and hope for the best. */
2091 /* Get the (function) symbol matching prologue_start. */
2092 bl
= block_for_pc (prologue_start
);
2094 func_size
= bl
->end () - bl
->start ();
2097 struct bound_minimal_symbol msymbol
2098 = lookup_minimal_symbol_by_pc (prologue_start
);
2099 if (msymbol
.minsym
!= NULL
)
2100 func_size
= msymbol
.minsym
->size ();
2103 /* If FUNC_SIZE is 0 we may have a special-case use of lr
2104 e.g. exception or interrupt. */
2106 lr_type
= csky_analyze_lr_type (gdbarch
, prologue_start
, func_end
);
2108 prologue_end
= std::min (func_end
, prev_pc
);
2110 /* Analyze the function prologue. */
2111 csky_analyze_prologue (gdbarch
, prologue_start
, prologue_end
,
2112 func_end
, this_frame
, cache
, lr_type
);
2114 /* gdbarch_sp_regnum contains the value and not the address. */
2115 cache
->saved_regs
[sp_regnum
].set_value (cache
->prev_sp
);
2119 /* Implement the this_id function for the normal unwinder. */
2122 csky_frame_this_id (frame_info_ptr this_frame
,
2123 void **this_prologue_cache
, struct frame_id
*this_id
)
2125 struct csky_unwind_cache
*cache
;
2128 if (*this_prologue_cache
== NULL
)
2129 *this_prologue_cache
= csky_frame_unwind_cache (this_frame
);
2130 cache
= (struct csky_unwind_cache
*) *this_prologue_cache
;
2132 /* This marks the outermost frame. */
2133 if (cache
->prev_sp
== 0)
2136 id
= frame_id_build (cache
->prev_sp
, get_frame_func (this_frame
));
2140 /* Implement the prev_register function for the normal unwinder. */
2142 static struct value
*
2143 csky_frame_prev_register (frame_info_ptr this_frame
,
2144 void **this_prologue_cache
, int regnum
)
2146 struct csky_unwind_cache
*cache
;
2148 if (*this_prologue_cache
== NULL
)
2149 *this_prologue_cache
= csky_frame_unwind_cache (this_frame
);
2150 cache
= (struct csky_unwind_cache
*) *this_prologue_cache
;
2152 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
,
2156 /* Data structures for the normal prologue-analysis-based
2159 static const struct frame_unwind csky_unwind_cache
= {
2162 default_frame_unwind_stop_reason
,
2164 csky_frame_prev_register
,
2166 default_frame_sniffer
,
2172 csky_check_long_branch (frame_info_ptr frame
, CORE_ADDR pc
)
2175 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2176 enum bfd_endian byte_order_for_code
2177 = gdbarch_byte_order_for_code (gdbarch
);
2179 if (target_read_memory (pc
, buf
, 8) == 0)
2182 = extract_unsigned_integer (buf
, 4, byte_order_for_code
);
2184 = extract_unsigned_integer (buf
+ 4, 4, byte_order_for_code
);
2186 /* Case: jmpi [pc+4] : 0xeac00001
2188 if (data0
== CSKY_JMPI_PC_4
)
2191 /* Case: lrw t1, [pc+8] : 0xea8d0002
2195 if ((data0
== CSKY_LRW_T1_PC_8
) && (data1
== CSKY_JMP_T1_VS_NOP
))
2197 if (target_read_memory (pc
+ 8, buf
, 4) == 0)
2198 return extract_unsigned_integer (buf
, 4, byte_order_for_code
);
2208 csky_stub_unwind_sniffer (const struct frame_unwind
*self
,
2209 frame_info_ptr this_frame
,
2210 void **this_prologue_cache
)
2212 CORE_ADDR addr_in_block
, pc
;
2215 CORE_ADDR start_addr
;
2218 addr_in_block
= get_frame_address_in_block (this_frame
);
2219 pc
= get_frame_pc (this_frame
);
2221 if (in_plt_section (addr_in_block
)
2222 || target_read_memory (pc
, dummy
, 4) != 0)
2225 /* Find the starting address and name of the function containing the PC. */
2226 if (find_pc_partial_function (pc
, &name
, &start_addr
, NULL
) == 0)
2228 start_addr
= csky_check_long_branch (this_frame
, pc
);
2229 /* if not long branch, return 0. */
2230 if (start_addr
!= 0)
2239 static struct csky_unwind_cache
*
2240 csky_make_stub_cache (frame_info_ptr this_frame
)
2242 struct csky_unwind_cache
*cache
;
2244 cache
= FRAME_OBSTACK_ZALLOC (struct csky_unwind_cache
);
2245 cache
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
2246 cache
->prev_sp
= get_frame_register_unsigned (this_frame
, CSKY_SP_REGNUM
);
2252 csky_stub_this_id (frame_info_ptr this_frame
,
2254 struct frame_id
*this_id
)
2256 struct csky_unwind_cache
*cache
;
2258 if (*this_cache
== NULL
)
2259 *this_cache
= csky_make_stub_cache (this_frame
);
2260 cache
= (struct csky_unwind_cache
*) *this_cache
;
2262 /* Our frame ID for a stub frame is the current SP and LR. */
2263 *this_id
= frame_id_build (cache
->prev_sp
, get_frame_pc (this_frame
));
2266 static struct value
*
2267 csky_stub_prev_register (frame_info_ptr this_frame
,
2271 struct csky_unwind_cache
*cache
;
2273 if (*this_cache
== NULL
)
2274 *this_cache
= csky_make_stub_cache (this_frame
);
2275 cache
= (struct csky_unwind_cache
*) *this_cache
;
2277 /* If we are asked to unwind the PC, then return the LR. */
2278 if (prev_regnum
== CSKY_PC_REGNUM
)
2282 lr
= frame_unwind_register_unsigned (this_frame
, CSKY_LR_REGNUM
);
2283 return frame_unwind_got_constant (this_frame
, prev_regnum
, lr
);
2286 if (prev_regnum
== CSKY_SP_REGNUM
)
2287 return frame_unwind_got_constant (this_frame
, prev_regnum
, cache
->prev_sp
);
2289 return trad_frame_get_prev_register (this_frame
, cache
->saved_regs
,
2293 static frame_unwind csky_stub_unwind
= {
2296 default_frame_unwind_stop_reason
,
2298 csky_stub_prev_register
,
2300 csky_stub_unwind_sniffer
2303 /* Implement the this_base, this_locals, and this_args hooks
2304 for the normal unwinder. */
2307 csky_frame_base_address (frame_info_ptr this_frame
, void **this_cache
)
2309 struct csky_unwind_cache
*cache
;
2311 if (*this_cache
== NULL
)
2312 *this_cache
= csky_frame_unwind_cache (this_frame
);
2313 cache
= (struct csky_unwind_cache
*) *this_cache
;
2315 return cache
->prev_sp
- cache
->framesize
;
2318 static const struct frame_base csky_frame_base
= {
2320 csky_frame_base_address
,
2321 csky_frame_base_address
,
2322 csky_frame_base_address
2325 /* Initialize register access method. */
2328 csky_dwarf2_frame_init_reg (struct gdbarch
*gdbarch
, int regnum
,
2329 struct dwarf2_frame_state_reg
*reg
,
2330 frame_info_ptr this_frame
)
2332 if (regnum
== gdbarch_pc_regnum (gdbarch
))
2333 reg
->how
= DWARF2_FRAME_REG_RA
;
2334 else if (regnum
== gdbarch_sp_regnum (gdbarch
))
2335 reg
->how
= DWARF2_FRAME_REG_CFA
;
2338 /* Create csky register groups. */
2341 csky_init_reggroup ()
2343 cr_reggroup
= reggroup_new ("cr", USER_REGGROUP
);
2344 fr_reggroup
= reggroup_new ("fr", USER_REGGROUP
);
2345 vr_reggroup
= reggroup_new ("vr", USER_REGGROUP
);
2346 mmu_reggroup
= reggroup_new ("mmu", USER_REGGROUP
);
2347 prof_reggroup
= reggroup_new ("profiling", USER_REGGROUP
);
2350 /* Add register groups into reggroup list. */
2353 csky_add_reggroups (struct gdbarch
*gdbarch
)
2355 reggroup_add (gdbarch
, cr_reggroup
);
2356 reggroup_add (gdbarch
, fr_reggroup
);
2357 reggroup_add (gdbarch
, vr_reggroup
);
2358 reggroup_add (gdbarch
, mmu_reggroup
);
2359 reggroup_add (gdbarch
, prof_reggroup
);
2362 /* Return the groups that a CSKY register can be categorised into. */
2365 csky_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
2366 const struct reggroup
*reggroup
)
2370 if (gdbarch_register_name (gdbarch
, regnum
)[0] == '\0')
2373 if (reggroup
== all_reggroup
)
2376 raw_p
= regnum
< gdbarch_num_regs (gdbarch
);
2377 if (reggroup
== save_reggroup
|| reggroup
== restore_reggroup
)
2380 if ((((regnum
>= CSKY_R0_REGNUM
) && (regnum
<= CSKY_R0_REGNUM
+ 31))
2381 || (regnum
== CSKY_PC_REGNUM
)
2382 || (regnum
== CSKY_EPC_REGNUM
)
2383 || (regnum
== CSKY_CR0_REGNUM
)
2384 || (regnum
== CSKY_EPSR_REGNUM
))
2385 && (reggroup
== general_reggroup
))
2388 if (((regnum
== CSKY_PC_REGNUM
)
2389 || ((regnum
>= CSKY_CR0_REGNUM
)
2390 && (regnum
<= CSKY_CR0_REGNUM
+ 30)))
2391 && (reggroup
== cr_reggroup
))
2394 if ((((regnum
>= CSKY_VR0_REGNUM
) && (regnum
<= CSKY_VR0_REGNUM
+ 15))
2395 || ((regnum
>= CSKY_FCR_REGNUM
)
2396 && (regnum
<= CSKY_FCR_REGNUM
+ 2)))
2397 && (reggroup
== vr_reggroup
))
2400 if (((regnum
>= CSKY_MMU_REGNUM
) && (regnum
<= CSKY_MMU_REGNUM
+ 8))
2401 && (reggroup
== mmu_reggroup
))
2404 if (((regnum
>= CSKY_PROFCR_REGNUM
)
2405 && (regnum
<= CSKY_PROFCR_REGNUM
+ 48))
2406 && (reggroup
== prof_reggroup
))
2409 if ((((regnum
>= CSKY_FR0_REGNUM
) && (regnum
<= CSKY_FR0_REGNUM
+ 15))
2410 || ((regnum
>= CSKY_FCR_REGNUM
) && (regnum
<= CSKY_FCR_REGNUM
+ 2)))
2411 && (reggroup
== fr_reggroup
))
2414 if (tdesc_has_registers (gdbarch_target_desc (gdbarch
)))
2416 if (tdesc_register_in_reggroup_p (gdbarch
, regnum
, reggroup
) > 0)
2423 /* Implement the dwarf2_reg_to_regnum gdbarch method. */
2426 csky_dwarf_reg_to_regnum (struct gdbarch
*gdbarch
, int dw_reg
)
2429 if (dw_reg
>= CSKY_R0_REGNUM
&& dw_reg
<= CSKY_R0_REGNUM
+ 31)
2432 /* For Hi, Lo, PC. */
2433 if (dw_reg
== CSKY_HI_REGNUM
|| dw_reg
== CSKY_LO_REGNUM
2434 || dw_reg
== CSKY_PC_REGNUM
)
2437 /* For Float and Vector pseudo registers. */
2438 if (dw_reg
>= FV_PSEUDO_REGNO_FIRST
&& dw_reg
<= FV_PSEUDO_REGNO_LAST
)
2442 xsnprintf (name_buf
, sizeof (name_buf
), "s%d",
2443 dw_reg
- FV_PSEUDO_REGNO_FIRST
);
2444 return user_reg_map_name_to_regnum (gdbarch
, name_buf
,
2448 /* Others, unknown. */
2452 /* Check whether xml has discribled the essential regs. */
2455 csky_essential_reg_check (const struct csky_supported_tdesc_register
*reg
)
2457 if ((strcmp (reg
->name
, "pc") == 0)
2458 && (reg
->num
== CSKY_PC_REGNUM
))
2459 return CSKY_TDESC_REGS_PC_NUMBERED
;
2460 else if ((strcmp (reg
->name
, "r14") == 0)
2461 && (reg
->num
== CSKY_SP_REGNUM
))
2462 return CSKY_TDESC_REGS_SP_NUMBERED
;
2463 else if ((strcmp (reg
->name
, "r15") == 0)
2464 && (reg
->num
== CSKY_LR_REGNUM
))
2465 return CSKY_TDESC_REGS_LR_NUMBERED
;
2470 /* Check whether xml has discribled the fr0~fr15 regs. */
2473 csky_fr0_fr15_reg_check (const struct csky_supported_tdesc_register
*reg
) {
2475 for (i
= 0; i
< 16; i
++)
2477 if ((strcmp (reg
->name
, csky_supported_fpu_regs
[i
].name
) == 0)
2478 && (csky_supported_fpu_regs
[i
].num
== reg
->num
))
2485 /* Check whether xml has discribled the fr16~fr31 regs. */
2488 csky_fr16_fr31_reg_check (const struct csky_supported_tdesc_register
*reg
) {
2490 for (i
= 0; i
< 16; i
++)
2492 if ((strcmp (reg
->name
, csky_supported_fpu_regs
[i
+ 16].name
) == 0)
2493 && (csky_supported_fpu_regs
[i
+ 16].num
== reg
->num
))
2500 /* Check whether xml has discribled the vr0~vr15 regs. */
2503 csky_vr0_vr15_reg_check (const struct csky_supported_tdesc_register
*reg
) {
2505 for (i
= 0; i
< 16; i
++)
2507 if ((strcmp (reg
->name
, csky_supported_fpu_regs
[i
+ 32].name
) == 0)
2508 && (csky_supported_fpu_regs
[i
+ 32].num
== reg
->num
))
2515 /* Return pseudo reg's name. */
2518 csky_pseudo_register_name (struct gdbarch
*gdbarch
, int regno
)
2520 int num_regs
= gdbarch_num_regs (gdbarch
);
2521 csky_gdbarch_tdep
*tdep
2522 = gdbarch_tdep
<csky_gdbarch_tdep
> (gdbarch
);
2526 if (tdep
->fv_pseudo_registers_count
)
2528 static const char *const fv_pseudo_names
[] = {
2529 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
2530 "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15",
2531 "s16", "s17", "s18", "s19", "s20", "s21", "s22", "s23",
2532 "s24", "s25", "s26", "s27", "s28", "s29", "s30", "s31",
2533 "s32", "s33", "s34", "s35", "s36", "s37", "s38", "s39",
2534 "s40", "s41", "s42", "s43", "s44", "s45", "s46", "s47",
2535 "s48", "s49", "s50", "s51", "s52", "s53", "s54", "s55",
2536 "s56", "s57", "s58", "s59", "s60", "s61", "s62", "s63",
2537 "s64", "s65", "s66", "s67", "s68", "s69", "s70", "s71",
2538 "s72", "s73", "s74", "s75", "s76", "s77", "s78", "s79",
2539 "s80", "s81", "s82", "s83", "s84", "s85", "s86", "s87",
2540 "s88", "s89", "s90", "s91", "s92", "s93", "s94", "s95",
2541 "s96", "s97", "s98", "s99", "s100", "s101", "s102", "s103",
2542 "s104", "s105", "s106", "s107", "s108", "s109", "s110", "s111",
2543 "s112", "s113", "s114", "s115", "s116", "s117", "s118", "s119",
2544 "s120", "s121", "s122", "s123", "s124", "s125", "s126", "s127",
2547 if (regno
< tdep
->fv_pseudo_registers_count
)
2549 if ((regno
< 64) && ((regno
% 4) >= 2) && !tdep
->has_vr0
)
2551 else if ((regno
>= 64) && ((regno
% 4) >= 2))
2554 return fv_pseudo_names
[regno
];
2561 /* Read for csky pseudo regs. */
2563 static enum register_status
2564 csky_pseudo_register_read (struct gdbarch
*gdbarch
,
2565 struct readable_regcache
*regcache
,
2566 int regnum
, gdb_byte
*buf
)
2568 int num_regs
= gdbarch_num_regs (gdbarch
);
2569 csky_gdbarch_tdep
*tdep
2570 = gdbarch_tdep
<csky_gdbarch_tdep
> (gdbarch
);
2574 if (regnum
< tdep
->fv_pseudo_registers_count
)
2576 enum register_status status
;
2579 gdb_byte reg_buf
[16];
2581 /* Ensure getting s0~s63 from vrx if tdep->has_vr0 is ture. */
2586 gdb_regnum
= CSKY_VR0_REGNUM
+ (regnum
/ 4);
2587 offset
= (regnum
% 4) * 4;
2591 gdb_regnum
= CSKY_FR16_REGNUM
+ ((regnum
- 64) / 4);
2592 if ((regnum
% 4) >= 2)
2593 return REG_UNAVAILABLE
;
2594 offset
= (regnum
% 2) * 4;
2599 gdb_regnum
= CSKY_FR0_REGNUM
+ (regnum
/ 4);
2600 if ((regnum
% 4) >= 2)
2601 return REG_UNAVAILABLE
;
2602 offset
= (regnum
% 2) * 4;
2605 status
= regcache
->raw_read (gdb_regnum
, reg_buf
);
2606 if (status
== REG_VALID
)
2607 memcpy (buf
, reg_buf
+ offset
, 4);
2614 /* Write for csky pseudo regs. */
2617 csky_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
2618 int regnum
, const gdb_byte
*buf
)
2620 int num_regs
= gdbarch_num_regs (gdbarch
);
2621 csky_gdbarch_tdep
*tdep
2622 = gdbarch_tdep
<csky_gdbarch_tdep
> (gdbarch
);
2626 if (regnum
< tdep
->fv_pseudo_registers_count
)
2628 gdb_byte reg_buf
[16];
2636 gdb_regnum
= CSKY_VR0_REGNUM
+ (regnum
/ 4);
2637 offset
= (regnum
% 4) * 4;
2641 gdb_regnum
= CSKY_FR16_REGNUM
+ ((regnum
- 64) / 4);
2642 if ((regnum
% 4) >= 2)
2644 offset
= (regnum
% 2) * 4;
2649 gdb_regnum
= CSKY_FR0_REGNUM
+ (regnum
/ 4);
2650 if ((regnum
% 4) >= 2)
2652 offset
= (regnum
% 2) * 4;
2655 regcache
->raw_read (gdb_regnum
, reg_buf
);
2656 memcpy (reg_buf
+ offset
, buf
, 4);
2657 regcache
->raw_write (gdb_regnum
, reg_buf
);
2664 /* Initialize the current architecture based on INFO. If possible,
2665 re-use an architecture from ARCHES, which is a list of
2666 architectures already created during this debugging session.
2668 Called at program startup, when reading a core file, and when
2669 reading a binary file. */
2671 static struct gdbarch
*
2672 csky_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
2674 struct gdbarch
*gdbarch
;
2675 /* Analyze info.abfd. */
2676 unsigned int fpu_abi
= 0;
2677 unsigned int vdsp_version
= 0;
2678 unsigned int fpu_hardfp
= 0;
2679 /* Analyze info.target_desc */
2684 tdesc_arch_data_up tdesc_data
;
2686 if (tdesc_has_registers (info
.target_desc
))
2692 int feature_names_count
= ARRAY_SIZE (csky_supported_tdesc_feature_names
);
2693 int support_tdesc_regs_count
2694 = csky_get_supported_tdesc_registers_count();
2695 const struct csky_supported_tdesc_register
*tdesc_reg
;
2696 const struct tdesc_feature
*feature
;
2698 tdesc_data
= tdesc_data_alloc ();
2699 for (index
= 0; index
< feature_names_count
; index
++)
2701 feature
= tdesc_find_feature (info
.target_desc
,
2702 csky_supported_tdesc_feature_names
[index
]);
2703 if (feature
!= NULL
)
2705 for (i
= 0; i
< support_tdesc_regs_count
; i
++)
2707 tdesc_reg
= csky_get_supported_register_by_index (i
);
2710 numbered
= tdesc_numbered_register (feature
, tdesc_data
.get(),
2714 valid_p
|= csky_essential_reg_check (tdesc_reg
);
2715 has_fr0
|= csky_fr0_fr15_reg_check (tdesc_reg
);
2716 has_fr16
|= csky_fr16_fr31_reg_check (tdesc_reg
);
2717 has_vr0
|= csky_vr0_vr15_reg_check (tdesc_reg
);
2718 if (num_regs
< tdesc_reg
->num
)
2719 num_regs
= tdesc_reg
->num
;
2724 if (valid_p
!= CSKY_TDESC_REGS_ESSENTIAL_VALUE
)
2728 /* When the type of bfd file is srec(or any files are not elf),
2729 the E_FLAGS will be not credible. */
2730 if (info
.abfd
!= NULL
&& bfd_get_flavour (info
.abfd
) == bfd_target_elf_flavour
)
2732 /* Get FPU, VDSP build options. */
2733 fpu_abi
= bfd_elf_get_obj_attr_int (info
.abfd
,
2736 vdsp_version
= bfd_elf_get_obj_attr_int (info
.abfd
,
2738 Tag_CSKY_VDSP_VERSION
);
2739 fpu_hardfp
= bfd_elf_get_obj_attr_int (info
.abfd
,
2741 Tag_CSKY_FPU_HARDFP
);
2744 /* Find a candidate among the list of pre-declared architectures. */
2745 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
2747 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
2749 csky_gdbarch_tdep
*tdep
2750 = gdbarch_tdep
<csky_gdbarch_tdep
> (arches
->gdbarch
);
2751 if (fpu_abi
!= tdep
->fpu_abi
)
2753 if (vdsp_version
!= tdep
->vdsp_version
)
2755 if (fpu_hardfp
!= tdep
->fpu_hardfp
)
2758 /* Found a match. */
2759 return arches
->gdbarch
;
2762 /* None found, create a new architecture from the information
2764 csky_gdbarch_tdep
*tdep
= new csky_gdbarch_tdep
;
2765 gdbarch
= gdbarch_alloc (&info
, tdep
);
2766 tdep
->fpu_abi
= fpu_abi
;
2767 tdep
->vdsp_version
= vdsp_version
;
2768 tdep
->fpu_hardfp
= fpu_hardfp
;
2770 if (tdesc_data
!= NULL
)
2772 if ((has_vr0
== CSKY_FULL16_ONEHOT_VALUE
)
2773 && (has_fr16
== CSKY_FULL16_ONEHOT_VALUE
))
2776 tdep
->fv_pseudo_registers_count
= 128;
2778 else if ((has_vr0
== CSKY_FULL16_ONEHOT_VALUE
)
2779 && (has_fr16
!= CSKY_FULL16_ONEHOT_VALUE
))
2782 tdep
->fv_pseudo_registers_count
= 64;
2784 else if ((has_fr0
== CSKY_FULL16_ONEHOT_VALUE
)
2785 && (has_vr0
!= CSKY_FULL16_ONEHOT_VALUE
))
2788 tdep
->fv_pseudo_registers_count
= 64;
2793 tdep
->fv_pseudo_registers_count
= 0;
2799 tdep
->fv_pseudo_registers_count
= 64;
2802 /* Target data types. */
2803 set_gdbarch_ptr_bit (gdbarch
, 32);
2804 set_gdbarch_addr_bit (gdbarch
, 32);
2805 set_gdbarch_short_bit (gdbarch
, 16);
2806 set_gdbarch_int_bit (gdbarch
, 32);
2807 set_gdbarch_long_bit (gdbarch
, 32);
2808 set_gdbarch_long_long_bit (gdbarch
, 64);
2809 set_gdbarch_float_bit (gdbarch
, 32);
2810 set_gdbarch_double_bit (gdbarch
, 64);
2811 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
2812 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
2814 /* Information about the target architecture. */
2815 set_gdbarch_return_value (gdbarch
, csky_return_value
);
2816 set_gdbarch_breakpoint_kind_from_pc (gdbarch
, csky_breakpoint_kind_from_pc
);
2817 set_gdbarch_sw_breakpoint_from_kind (gdbarch
, csky_sw_breakpoint_from_kind
);
2819 /* Register architecture. */
2820 set_gdbarch_num_regs (gdbarch
, CSKY_NUM_REGS
);
2821 set_gdbarch_pc_regnum (gdbarch
, CSKY_PC_REGNUM
);
2822 set_gdbarch_sp_regnum (gdbarch
, CSKY_SP_REGNUM
);
2823 set_gdbarch_register_name (gdbarch
, csky_register_name
);
2824 set_gdbarch_register_type (gdbarch
, csky_register_type
);
2825 set_gdbarch_read_pc (gdbarch
, csky_read_pc
);
2826 set_gdbarch_write_pc (gdbarch
, csky_write_pc
);
2827 csky_add_reggroups (gdbarch
);
2828 set_gdbarch_register_reggroup_p (gdbarch
, csky_register_reggroup_p
);
2829 set_gdbarch_stab_reg_to_regnum (gdbarch
, csky_dwarf_reg_to_regnum
);
2830 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, csky_dwarf_reg_to_regnum
);
2831 dwarf2_frame_set_init_reg (gdbarch
, csky_dwarf2_frame_init_reg
);
2833 /* Functions to analyze frames. */
2834 frame_base_set_default (gdbarch
, &csky_frame_base
);
2835 set_gdbarch_skip_prologue (gdbarch
, csky_skip_prologue
);
2836 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
2837 set_gdbarch_frame_align (gdbarch
, csky_frame_align
);
2838 set_gdbarch_stack_frame_destroyed_p (gdbarch
, csky_stack_frame_destroyed_p
);
2840 /* Functions handling dummy frames. */
2841 set_gdbarch_push_dummy_call (gdbarch
, csky_push_dummy_call
);
2843 /* Frame unwinders. Use DWARF debug info if available,
2844 otherwise use our own unwinder. */
2845 dwarf2_append_unwinders (gdbarch
);
2846 frame_unwind_append_unwinder (gdbarch
, &csky_stub_unwind
);
2847 frame_unwind_append_unwinder (gdbarch
, &csky_unwind_cache
);
2849 /* Hook in ABI-specific overrides, if they have been registered. */
2850 gdbarch_init_osabi (info
, gdbarch
);
2852 /* Support simple overlay manager. */
2853 set_gdbarch_overlay_update (gdbarch
, simple_overlay_update
);
2854 set_gdbarch_char_signed (gdbarch
, 0);
2856 if (tdesc_data
!= nullptr)
2858 set_gdbarch_num_regs (gdbarch
, (num_regs
+ 1));
2859 tdesc_use_registers (gdbarch
, info
.target_desc
, std::move (tdesc_data
));
2860 set_gdbarch_register_type (gdbarch
, csky_register_type
);
2861 set_gdbarch_register_reggroup_p (gdbarch
,
2862 csky_register_reggroup_p
);
2865 if (tdep
->fv_pseudo_registers_count
)
2867 set_gdbarch_num_pseudo_regs (gdbarch
,
2868 tdep
->fv_pseudo_registers_count
);
2869 set_gdbarch_pseudo_register_read (gdbarch
,
2870 csky_pseudo_register_read
);
2871 set_gdbarch_pseudo_register_write (gdbarch
,
2872 csky_pseudo_register_write
);
2873 set_tdesc_pseudo_register_name (gdbarch
, csky_pseudo_register_name
);
2879 void _initialize_csky_tdep ();
2881 _initialize_csky_tdep ()
2884 gdbarch_register (bfd_arch_csky
, csky_gdbarch_init
);
2886 csky_init_reggroup ();
2888 /* Allow debugging this file's internals. */
2889 add_setshow_boolean_cmd ("csky", class_maintenance
, &csky_debug
,
2890 _("Set C-Sky debugging."),
2891 _("Show C-Sky debugging."),
2892 _("When on, C-Sky specific debugging is enabled."),
2895 &setdebuglist
, &showdebuglist
);