Commit | Line | Data |
---|---|---|
dbbb1059 AB |
1 | /* Target-dependent code for the RISC-V architecture, for GDB. |
2 | ||
3 | Copyright (C) 2018 Free Software Foundation, Inc. | |
4 | ||
dbbb1059 AB |
5 | This file is part of GDB. |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "frame.h" | |
22 | #include "inferior.h" | |
23 | #include "symtab.h" | |
24 | #include "value.h" | |
25 | #include "gdbcmd.h" | |
26 | #include "language.h" | |
27 | #include "gdbcore.h" | |
28 | #include "symfile.h" | |
29 | #include "objfiles.h" | |
30 | #include "gdbtypes.h" | |
31 | #include "target.h" | |
32 | #include "arch-utils.h" | |
33 | #include "regcache.h" | |
34 | #include "osabi.h" | |
35 | #include "riscv-tdep.h" | |
36 | #include "block.h" | |
37 | #include "reggroups.h" | |
38 | #include "opcode/riscv.h" | |
39 | #include "elf/riscv.h" | |
40 | #include "elf-bfd.h" | |
41 | #include "symcat.h" | |
42 | #include "dis-asm.h" | |
43 | #include "frame-unwind.h" | |
44 | #include "frame-base.h" | |
45 | #include "trad-frame.h" | |
46 | #include "infcall.h" | |
47 | #include "floatformat.h" | |
48 | #include "remote.h" | |
49 | #include "target-descriptions.h" | |
50 | #include "dwarf2-frame.h" | |
51 | #include "user-regs.h" | |
52 | #include "valprint.h" | |
53 | #include "common-defs.h" | |
54 | #include "opcode/riscv-opc.h" | |
55 | #include "cli/cli-decode.h" | |
76727919 | 56 | #include "observable.h" |
dbbb1059 AB |
57 | |
58 | /* The stack must be 16-byte aligned. */ | |
59 | #define SP_ALIGNMENT 16 | |
60 | ||
61 | /* Forward declarations. */ | |
62 | static bool riscv_has_feature (struct gdbarch *gdbarch, char feature); | |
63 | struct riscv_inferior_data; | |
64 | struct riscv_inferior_data * riscv_inferior_data (struct inferior *const inf); | |
65 | ||
66 | /* Define a series of is_XXX_insn functions to check if the value INSN | |
67 | is an instance of instruction XXX. */ | |
68 | #define DECLARE_INSN(INSN_NAME, INSN_MATCH, INSN_MASK) \ | |
69 | static inline bool is_ ## INSN_NAME ## _insn (long insn) \ | |
70 | { \ | |
71 | return (insn & INSN_MASK) == INSN_MATCH; \ | |
72 | } | |
73 | #include "opcode/riscv-opc.h" | |
74 | #undef DECLARE_INSN | |
75 | ||
76 | /* Per inferior information for RiscV. */ | |
77 | ||
78 | struct riscv_inferior_data | |
79 | { | |
80 | /* True when MISA_VALUE is valid, otherwise false. */ | |
81 | bool misa_read; | |
82 | ||
83 | /* If MISA_READ is true then MISA_VALUE holds the value of the MISA | |
84 | register read from the target. */ | |
85 | uint32_t misa_value; | |
86 | }; | |
87 | ||
88 | /* Key created when the RiscV per-inferior data is registered. */ | |
89 | ||
90 | static const struct inferior_data *riscv_inferior_data_reg; | |
91 | ||
92 | /* Architectural name for core registers. */ | |
93 | ||
94 | static const char * const riscv_gdb_reg_names[RISCV_LAST_FP_REGNUM + 1] = | |
95 | { | |
96 | "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", | |
97 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", | |
98 | "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", | |
99 | "x24", "x25", "x26", "x27", "x28", "x29", "x30", "x31", | |
100 | "pc", | |
101 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
102 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
103 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
104 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", | |
105 | }; | |
106 | ||
107 | /* Maps "pretty" register names onto their GDB register number. */ | |
108 | ||
109 | struct register_alias | |
110 | { | |
111 | /* The register alias. Usually more descriptive than the | |
112 | architectural name of the register. */ | |
113 | const char *name; | |
114 | ||
115 | /* The GDB register number. */ | |
116 | int regnum; | |
117 | }; | |
118 | ||
119 | /* Table of register aliases. */ | |
120 | ||
121 | static const struct register_alias riscv_register_aliases[] = | |
122 | { | |
123 | { "zero", 0 }, | |
124 | { "ra", 1 }, | |
125 | { "sp", 2 }, | |
126 | { "gp", 3 }, | |
127 | { "tp", 4 }, | |
128 | { "t0", 5 }, | |
129 | { "t1", 6 }, | |
130 | { "t2", 7 }, | |
dbbb1059 | 131 | { "s0", 8 }, |
41823f29 | 132 | { "fp", 8 }, |
dbbb1059 AB |
133 | { "s1", 9 }, |
134 | { "a0", 10 }, | |
135 | { "a1", 11 }, | |
136 | { "a2", 12 }, | |
137 | { "a3", 13 }, | |
138 | { "a4", 14 }, | |
139 | { "a5", 15 }, | |
140 | { "a6", 16 }, | |
141 | { "a7", 17 }, | |
142 | { "s2", 18 }, | |
143 | { "s3", 19 }, | |
144 | { "s4", 20 }, | |
145 | { "s5", 21 }, | |
146 | { "s6", 22 }, | |
147 | { "s7", 23 }, | |
148 | { "s8", 24 }, | |
149 | { "s9", 25 }, | |
150 | { "s10", 26 }, | |
151 | { "s11", 27 }, | |
152 | { "t3", 28 }, | |
153 | { "t4", 29 }, | |
154 | { "t5", 30 }, | |
155 | { "t6", 31 }, | |
156 | /* pc is 32. */ | |
157 | { "ft0", 33 }, | |
158 | { "ft1", 34 }, | |
159 | { "ft2", 35 }, | |
160 | { "ft3", 36 }, | |
161 | { "ft4", 37 }, | |
162 | { "ft5", 38 }, | |
163 | { "ft6", 39 }, | |
164 | { "ft7", 40 }, | |
165 | { "fs0", 41 }, | |
166 | { "fs1", 42 }, | |
167 | { "fa0", 43 }, | |
168 | { "fa1", 44 }, | |
169 | { "fa2", 45 }, | |
170 | { "fa3", 46 }, | |
171 | { "fa4", 47 }, | |
172 | { "fa5", 48 }, | |
173 | { "fa6", 49 }, | |
174 | { "fa7", 50 }, | |
175 | { "fs2", 51 }, | |
176 | { "fs3", 52 }, | |
177 | { "fs4", 53 }, | |
178 | { "fs5", 54 }, | |
179 | { "fs6", 55 }, | |
180 | { "fs7", 56 }, | |
181 | { "fs8", 57 }, | |
182 | { "fs9", 58 }, | |
183 | { "fs10", 59 }, | |
184 | { "fs11", 60 }, | |
185 | { "ft8", 61 }, | |
186 | { "ft9", 62 }, | |
187 | { "ft10", 63 }, | |
188 | { "ft11", 64 }, | |
189 | #define DECLARE_CSR(name, num) { #name, (num) + 65 }, | |
190 | #include "opcode/riscv-opc.h" | |
191 | #undef DECLARE_CSR | |
192 | }; | |
193 | ||
194 | /* Controls whether we place compressed breakpoints or not. When in auto | |
195 | mode GDB tries to determine if the target supports compressed | |
196 | breakpoints, and uses them if it does. */ | |
197 | ||
198 | static enum auto_boolean use_compressed_breakpoints; | |
199 | ||
200 | /* The show callback for 'show riscv use-compressed-breakpoints'. */ | |
201 | ||
202 | static void | |
203 | show_use_compressed_breakpoints (struct ui_file *file, int from_tty, | |
204 | struct cmd_list_element *c, | |
205 | const char *value) | |
206 | { | |
207 | const char *additional_info; | |
208 | struct gdbarch *gdbarch = target_gdbarch (); | |
209 | ||
210 | if (use_compressed_breakpoints == AUTO_BOOLEAN_AUTO) | |
211 | if (riscv_has_feature (gdbarch, 'C')) | |
212 | additional_info = _(" (currently on)"); | |
213 | else | |
214 | additional_info = _(" (currently off)"); | |
215 | else | |
216 | additional_info = ""; | |
217 | ||
218 | fprintf_filtered (file, | |
219 | _("Debugger's use of compressed breakpoints is set " | |
220 | "to %s%s.\n"), value, additional_info); | |
221 | } | |
222 | ||
223 | /* The set and show lists for 'set riscv' and 'show riscv' prefixes. */ | |
224 | ||
225 | static struct cmd_list_element *setriscvcmdlist = NULL; | |
226 | static struct cmd_list_element *showriscvcmdlist = NULL; | |
227 | ||
228 | /* The show callback for the 'show riscv' prefix command. */ | |
229 | ||
230 | static void | |
231 | show_riscv_command (const char *args, int from_tty) | |
232 | { | |
233 | help_list (showriscvcmdlist, "show riscv ", all_commands, gdb_stdout); | |
234 | } | |
235 | ||
236 | /* The set callback for the 'set riscv' prefix command. */ | |
237 | ||
238 | static void | |
239 | set_riscv_command (const char *args, int from_tty) | |
240 | { | |
241 | printf_unfiltered | |
242 | (_("\"set riscv\" must be followed by an appropriate subcommand.\n")); | |
243 | help_list (setriscvcmdlist, "set riscv ", all_commands, gdb_stdout); | |
244 | } | |
245 | ||
246 | /* The set and show lists for 'set riscv' and 'show riscv' prefixes. */ | |
247 | ||
248 | static struct cmd_list_element *setdebugriscvcmdlist = NULL; | |
249 | static struct cmd_list_element *showdebugriscvcmdlist = NULL; | |
250 | ||
251 | /* The show callback for the 'show debug riscv' prefix command. */ | |
252 | ||
253 | static void | |
254 | show_debug_riscv_command (const char *args, int from_tty) | |
255 | { | |
256 | help_list (showdebugriscvcmdlist, "show debug riscv ", all_commands, gdb_stdout); | |
257 | } | |
258 | ||
259 | /* The set callback for the 'set debug riscv' prefix command. */ | |
260 | ||
261 | static void | |
262 | set_debug_riscv_command (const char *args, int from_tty) | |
263 | { | |
264 | printf_unfiltered | |
265 | (_("\"set debug riscv\" must be followed by an appropriate subcommand.\n")); | |
266 | help_list (setdebugriscvcmdlist, "set debug riscv ", all_commands, gdb_stdout); | |
267 | } | |
268 | ||
269 | /* The show callback for all 'show debug riscv VARNAME' variables. */ | |
270 | ||
271 | static void | |
272 | show_riscv_debug_variable (struct ui_file *file, int from_tty, | |
273 | struct cmd_list_element *c, | |
274 | const char *value) | |
275 | { | |
276 | fprintf_filtered (file, | |
277 | _("RiscV debug variable `%s' is set to: %s\n"), | |
278 | c->name, value); | |
279 | } | |
280 | ||
281 | /* When this is set to non-zero debugging information about inferior calls | |
282 | will be printed. */ | |
283 | ||
284 | static unsigned int riscv_debug_infcall = 0; | |
285 | ||
286 | /* Read the MISA register from the target. The register will only be read | |
287 | once, and the value read will be cached. If the register can't be read | |
288 | from the target then a default value (0) will be returned. If the | |
289 | pointer READ_P is not null, then the bool pointed to is updated to | |
290 | indicate if the value returned was read from the target (true) or is the | |
291 | default (false). */ | |
292 | ||
293 | static uint32_t | |
294 | riscv_read_misa_reg (bool *read_p) | |
295 | { | |
296 | struct riscv_inferior_data *inf_data | |
297 | = riscv_inferior_data (current_inferior ()); | |
298 | ||
299 | if (!inf_data->misa_read && target_has_registers) | |
300 | { | |
301 | uint32_t value = 0; | |
302 | struct frame_info *frame = get_current_frame (); | |
303 | ||
304 | TRY | |
305 | { | |
306 | value = get_frame_register_unsigned (frame, RISCV_CSR_MISA_REGNUM); | |
307 | } | |
308 | CATCH (ex, RETURN_MASK_ERROR) | |
309 | { | |
310 | /* Old cores might have MISA located at a different offset. */ | |
311 | value = get_frame_register_unsigned (frame, | |
312 | RISCV_CSR_LEGACY_MISA_REGNUM); | |
313 | } | |
314 | END_CATCH | |
315 | ||
316 | inf_data->misa_read = true; | |
317 | inf_data->misa_value = value; | |
318 | } | |
319 | ||
320 | if (read_p != nullptr) | |
321 | *read_p = inf_data->misa_read; | |
322 | ||
323 | return inf_data->misa_value; | |
324 | } | |
325 | ||
326 | /* Return true if FEATURE is available for the architecture GDBARCH. The | |
327 | FEATURE should be one of the single character feature codes described in | |
328 | the RiscV ISA manual, these are between 'A' and 'Z'. */ | |
329 | ||
330 | static bool | |
331 | riscv_has_feature (struct gdbarch *gdbarch, char feature) | |
332 | { | |
333 | bool have_read_misa = false; | |
334 | uint32_t misa; | |
335 | ||
336 | gdb_assert (feature >= 'A' && feature <= 'Z'); | |
337 | ||
338 | /* It would be nice to always check with the real target where possible, | |
339 | however, for compressed instructions this is a bad idea. | |
340 | ||
341 | The call to `set_gdbarch_decr_pc_after_break' is made just once per | |
342 | GDBARCH and we decide at that point if we should decrement by 2 or 4 | |
343 | bytes based on whether the BFD has compressed instruction support or | |
344 | not. | |
345 | ||
346 | If the BFD was not compiled with compressed instruction support, but we | |
347 | are running on a target with compressed instructions then we might | |
348 | place a 4-byte breakpoint, then decrement the $pc by 2 bytes leading to | |
349 | confusion. | |
350 | ||
351 | It's safer if we just make decisions about compressed instruction | |
352 | support based on the BFD. */ | |
353 | if (feature != 'C') | |
354 | misa = riscv_read_misa_reg (&have_read_misa); | |
355 | if (!have_read_misa || misa == 0) | |
356 | misa = gdbarch_tdep (gdbarch)->core_features; | |
357 | ||
358 | return (misa & (1 << (feature - 'A'))) != 0; | |
359 | } | |
360 | ||
361 | /* Return the width in bytes of the general purpose registers for GDBARCH. | |
362 | Possible return values are 4, 8, or 16 for RiscV variants RV32, RV64, or | |
363 | RV128. */ | |
364 | ||
365 | static int | |
366 | riscv_isa_xlen (struct gdbarch *gdbarch) | |
367 | { | |
368 | switch (gdbarch_tdep (gdbarch)->abi.fields.base_len) | |
369 | { | |
370 | default: | |
371 | warning (_("unknown xlen size, assuming 4 bytes")); | |
565e0eda | 372 | /* Fall through. */ |
dbbb1059 AB |
373 | case 1: |
374 | return 4; | |
375 | case 2: | |
376 | return 8; | |
377 | case 3: | |
378 | return 16; | |
379 | } | |
380 | } | |
381 | ||
382 | /* Return the width in bytes of the floating point registers for GDBARCH. | |
383 | If this architecture has no floating point registers, then return 0. | |
384 | Possible values are 4, 8, or 16 for depending on which of single, double | |
385 | or quad floating point support is available. */ | |
386 | ||
387 | static int | |
388 | riscv_isa_flen (struct gdbarch *gdbarch) | |
389 | { | |
390 | if (riscv_has_feature (gdbarch, 'Q')) | |
391 | return 16; | |
392 | else if (riscv_has_feature (gdbarch, 'D')) | |
393 | return 8; | |
394 | else if (riscv_has_feature (gdbarch, 'F')) | |
395 | return 4; | |
396 | ||
397 | return 0; | |
398 | } | |
399 | ||
400 | /* Return true if the target for GDBARCH has floating point hardware. */ | |
401 | ||
402 | static bool | |
403 | riscv_has_fp_regs (struct gdbarch *gdbarch) | |
404 | { | |
405 | return (riscv_isa_flen (gdbarch) > 0); | |
406 | } | |
407 | ||
408 | /* Return true if GDBARCH is using any of the floating point hardware ABIs. */ | |
409 | ||
410 | static bool | |
411 | riscv_has_fp_abi (struct gdbarch *gdbarch) | |
412 | { | |
413 | return (gdbarch_tdep (gdbarch)->abi.fields.float_abi != 0); | |
414 | } | |
415 | ||
8c49aa89 AB |
416 | /* Return true if REGNO is a floating pointer register. */ |
417 | ||
418 | static bool | |
419 | riscv_is_fp_regno_p (int regno) | |
420 | { | |
421 | return (regno >= RISCV_FIRST_FP_REGNUM | |
422 | && regno <= RISCV_LAST_FP_REGNUM); | |
423 | } | |
424 | ||
dbbb1059 AB |
425 | /* Implement the breakpoint_kind_from_pc gdbarch method. */ |
426 | ||
427 | static int | |
428 | riscv_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) | |
429 | { | |
430 | if (use_compressed_breakpoints == AUTO_BOOLEAN_AUTO) | |
431 | { | |
432 | if (riscv_has_feature (gdbarch, 'C')) | |
433 | return 2; | |
434 | else | |
435 | return 4; | |
436 | } | |
437 | else if (use_compressed_breakpoints == AUTO_BOOLEAN_TRUE) | |
438 | return 2; | |
439 | else | |
440 | return 4; | |
441 | } | |
442 | ||
443 | /* Implement the sw_breakpoint_from_kind gdbarch method. */ | |
444 | ||
445 | static const gdb_byte * | |
446 | riscv_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size) | |
447 | { | |
448 | static const gdb_byte ebreak[] = { 0x73, 0x00, 0x10, 0x00, }; | |
449 | static const gdb_byte c_ebreak[] = { 0x02, 0x90 }; | |
450 | ||
451 | *size = kind; | |
452 | switch (kind) | |
453 | { | |
454 | case 2: | |
455 | return c_ebreak; | |
456 | case 4: | |
457 | return ebreak; | |
458 | default: | |
89a3b63e | 459 | gdb_assert_not_reached (_("unhandled breakpoint kind")); |
dbbb1059 AB |
460 | } |
461 | } | |
462 | ||
463 | /* Callback function for user_reg_add. */ | |
464 | ||
465 | static struct value * | |
466 | value_of_riscv_user_reg (struct frame_info *frame, const void *baton) | |
467 | { | |
468 | const int *reg_p = (const int *) baton; | |
469 | return value_of_register (*reg_p, frame); | |
470 | } | |
471 | ||
472 | /* Implement the register_name gdbarch method. */ | |
473 | ||
474 | static const char * | |
475 | riscv_register_name (struct gdbarch *gdbarch, int regnum) | |
476 | { | |
dbbb1059 AB |
477 | /* Prefer to use the alias. */ |
478 | if (regnum >= RISCV_ZERO_REGNUM && regnum <= RISCV_LAST_REGNUM) | |
479 | { | |
480 | int i; | |
481 | ||
482 | for (i = 0; i < ARRAY_SIZE (riscv_register_aliases); ++i) | |
483 | if (regnum == riscv_register_aliases[i].regnum) | |
484 | return riscv_register_aliases[i].name; | |
485 | } | |
486 | ||
487 | if (regnum >= RISCV_ZERO_REGNUM && regnum <= RISCV_LAST_FP_REGNUM) | |
488 | return riscv_gdb_reg_names[regnum]; | |
489 | ||
490 | if (regnum >= RISCV_FIRST_CSR_REGNUM && regnum <= RISCV_LAST_CSR_REGNUM) | |
491 | { | |
492 | static char buf[20]; | |
493 | ||
89a3b63e AB |
494 | xsnprintf (buf, sizeof (buf), "csr%d", |
495 | regnum - RISCV_FIRST_CSR_REGNUM); | |
dbbb1059 AB |
496 | return buf; |
497 | } | |
498 | ||
499 | if (regnum == RISCV_PRIV_REGNUM) | |
500 | return "priv"; | |
501 | ||
502 | return NULL; | |
503 | } | |
504 | ||
dbbb1059 AB |
505 | /* Implement the register_type gdbarch method. */ |
506 | ||
507 | static struct type * | |
508 | riscv_register_type (struct gdbarch *gdbarch, int regnum) | |
509 | { | |
510 | int regsize; | |
511 | ||
512 | if (regnum < RISCV_FIRST_FP_REGNUM) | |
513 | { | |
514 | if (regnum == gdbarch_pc_regnum (gdbarch) | |
515 | || regnum == RISCV_RA_REGNUM) | |
516 | return builtin_type (gdbarch)->builtin_func_ptr; | |
517 | ||
518 | if (regnum == RISCV_FP_REGNUM | |
519 | || regnum == RISCV_SP_REGNUM | |
520 | || regnum == RISCV_GP_REGNUM | |
521 | || regnum == RISCV_TP_REGNUM) | |
522 | return builtin_type (gdbarch)->builtin_data_ptr; | |
523 | ||
524 | /* Remaining GPRs vary in size based on the current ISA. */ | |
525 | regsize = riscv_isa_xlen (gdbarch); | |
526 | switch (regsize) | |
527 | { | |
528 | case 4: | |
529 | return builtin_type (gdbarch)->builtin_uint32; | |
530 | case 8: | |
531 | return builtin_type (gdbarch)->builtin_uint64; | |
532 | case 16: | |
533 | return builtin_type (gdbarch)->builtin_uint128; | |
534 | default: | |
535 | internal_error (__FILE__, __LINE__, | |
536 | _("unknown isa regsize %i"), regsize); | |
537 | } | |
538 | } | |
539 | else if (regnum <= RISCV_LAST_FP_REGNUM) | |
540 | { | |
541 | regsize = riscv_isa_xlen (gdbarch); | |
542 | switch (regsize) | |
543 | { | |
544 | case 4: | |
545 | return builtin_type (gdbarch)->builtin_float; | |
546 | case 8: | |
547 | return builtin_type (gdbarch)->builtin_double; | |
548 | case 16: | |
549 | return builtin_type (gdbarch)->builtin_long_double; | |
550 | default: | |
551 | internal_error (__FILE__, __LINE__, | |
552 | _("unknown isa regsize %i"), regsize); | |
553 | } | |
554 | } | |
555 | else if (regnum == RISCV_PRIV_REGNUM) | |
556 | return builtin_type (gdbarch)->builtin_int8; | |
557 | else | |
558 | { | |
559 | if (regnum == RISCV_CSR_FFLAGS_REGNUM | |
560 | || regnum == RISCV_CSR_FRM_REGNUM | |
561 | || regnum == RISCV_CSR_FCSR_REGNUM) | |
562 | return builtin_type (gdbarch)->builtin_int32; | |
563 | ||
564 | regsize = riscv_isa_xlen (gdbarch); | |
565 | switch (regsize) | |
566 | { | |
567 | case 4: | |
568 | return builtin_type (gdbarch)->builtin_int32; | |
569 | case 8: | |
570 | return builtin_type (gdbarch)->builtin_int64; | |
571 | case 16: | |
572 | return builtin_type (gdbarch)->builtin_int128; | |
573 | default: | |
574 | internal_error (__FILE__, __LINE__, | |
575 | _("unknown isa regsize %i"), regsize); | |
576 | } | |
577 | } | |
578 | } | |
579 | ||
580 | /* Helper for riscv_print_registers_info, prints info for a single register | |
581 | REGNUM. */ | |
582 | ||
583 | static void | |
584 | riscv_print_one_register_info (struct gdbarch *gdbarch, | |
585 | struct ui_file *file, | |
586 | struct frame_info *frame, | |
587 | int regnum) | |
588 | { | |
589 | const char *name = gdbarch_register_name (gdbarch, regnum); | |
590 | struct value *val = value_of_register (regnum, frame); | |
591 | struct type *regtype = value_type (val); | |
592 | int print_raw_format; | |
593 | enum tab_stops { value_column_1 = 15 }; | |
594 | ||
595 | fputs_filtered (name, file); | |
596 | print_spaces_filtered (value_column_1 - strlen (name), file); | |
597 | ||
598 | print_raw_format = (value_entirely_available (val) | |
599 | && !value_optimized_out (val)); | |
600 | ||
601 | if (TYPE_CODE (regtype) == TYPE_CODE_FLT) | |
602 | { | |
603 | struct value_print_options opts; | |
604 | const gdb_byte *valaddr = value_contents_for_printing (val); | |
605 | enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (regtype)); | |
606 | ||
607 | get_user_print_options (&opts); | |
608 | opts.deref_ref = 1; | |
609 | ||
610 | val_print (regtype, | |
611 | value_embedded_offset (val), 0, | |
612 | file, 0, val, &opts, current_language); | |
613 | ||
614 | if (print_raw_format) | |
615 | { | |
616 | fprintf_filtered (file, "\t(raw "); | |
617 | print_hex_chars (file, valaddr, TYPE_LENGTH (regtype), byte_order, | |
618 | true); | |
619 | fprintf_filtered (file, ")"); | |
620 | } | |
621 | } | |
622 | else | |
623 | { | |
624 | struct value_print_options opts; | |
625 | ||
626 | /* Print the register in hex. */ | |
627 | get_formatted_print_options (&opts, 'x'); | |
628 | opts.deref_ref = 1; | |
629 | val_print (regtype, | |
630 | value_embedded_offset (val), 0, | |
631 | file, 0, val, &opts, current_language); | |
632 | ||
633 | if (print_raw_format) | |
634 | { | |
635 | if (regnum == RISCV_CSR_MSTATUS_REGNUM) | |
636 | { | |
637 | LONGEST d; | |
638 | int size = register_size (gdbarch, regnum); | |
639 | unsigned xlen; | |
640 | ||
641 | d = value_as_long (val); | |
642 | xlen = size * 4; | |
643 | fprintf_filtered (file, | |
644 | "\tSD:%X VM:%02X MXR:%X PUM:%X MPRV:%X XS:%X " | |
645 | "FS:%X MPP:%x HPP:%X SPP:%X MPIE:%X HPIE:%X " | |
646 | "SPIE:%X UPIE:%X MIE:%X HIE:%X SIE:%X UIE:%X", | |
647 | (int) ((d >> (xlen - 1)) & 0x1), | |
648 | (int) ((d >> 24) & 0x1f), | |
649 | (int) ((d >> 19) & 0x1), | |
650 | (int) ((d >> 18) & 0x1), | |
651 | (int) ((d >> 17) & 0x1), | |
652 | (int) ((d >> 15) & 0x3), | |
653 | (int) ((d >> 13) & 0x3), | |
654 | (int) ((d >> 11) & 0x3), | |
655 | (int) ((d >> 9) & 0x3), | |
656 | (int) ((d >> 8) & 0x1), | |
657 | (int) ((d >> 7) & 0x1), | |
658 | (int) ((d >> 6) & 0x1), | |
659 | (int) ((d >> 5) & 0x1), | |
660 | (int) ((d >> 4) & 0x1), | |
661 | (int) ((d >> 3) & 0x1), | |
662 | (int) ((d >> 2) & 0x1), | |
663 | (int) ((d >> 1) & 0x1), | |
664 | (int) ((d >> 0) & 0x1)); | |
665 | } | |
666 | else if (regnum == RISCV_CSR_MISA_REGNUM) | |
667 | { | |
668 | int base; | |
669 | unsigned xlen, i; | |
670 | LONGEST d; | |
671 | ||
672 | d = value_as_long (val); | |
673 | base = d >> 30; | |
674 | xlen = 16; | |
675 | ||
676 | for (; base > 0; base--) | |
677 | xlen *= 2; | |
678 | fprintf_filtered (file, "\tRV%d", xlen); | |
679 | ||
680 | for (i = 0; i < 26; i++) | |
681 | { | |
682 | if (d & (1 << i)) | |
683 | fprintf_filtered (file, "%c", 'A' + i); | |
684 | } | |
685 | } | |
686 | else if (regnum == RISCV_CSR_FCSR_REGNUM | |
687 | || regnum == RISCV_CSR_FFLAGS_REGNUM | |
688 | || regnum == RISCV_CSR_FRM_REGNUM) | |
689 | { | |
690 | LONGEST d; | |
691 | ||
692 | d = value_as_long (val); | |
693 | ||
694 | fprintf_filtered (file, "\t"); | |
695 | if (regnum != RISCV_CSR_FRM_REGNUM) | |
696 | fprintf_filtered (file, | |
697 | "RD:%01X NV:%d DZ:%d OF:%d UF:%d NX:%d", | |
698 | (int) ((d >> 5) & 0x7), | |
699 | (int) ((d >> 4) & 0x1), | |
700 | (int) ((d >> 3) & 0x1), | |
701 | (int) ((d >> 2) & 0x1), | |
702 | (int) ((d >> 1) & 0x1), | |
703 | (int) ((d >> 0) & 0x1)); | |
704 | ||
705 | if (regnum != RISCV_CSR_FFLAGS_REGNUM) | |
706 | { | |
707 | static const char * const sfrm[] = | |
708 | { | |
709 | "RNE (round to nearest; ties to even)", | |
710 | "RTZ (Round towards zero)", | |
711 | "RDN (Round down towards -INF)", | |
712 | "RUP (Round up towards +INF)", | |
713 | "RMM (Round to nearest; ties to max magnitude)", | |
714 | "INVALID[5]", | |
715 | "INVALID[6]", | |
716 | "dynamic rounding mode", | |
717 | }; | |
718 | int frm = ((regnum == RISCV_CSR_FCSR_REGNUM) | |
719 | ? (d >> 5) : d) & 0x3; | |
720 | ||
721 | fprintf_filtered (file, "%sFRM:%i [%s]", | |
722 | (regnum == RISCV_CSR_FCSR_REGNUM | |
723 | ? " " : ""), | |
724 | frm, sfrm[frm]); | |
725 | } | |
726 | } | |
727 | else if (regnum == RISCV_PRIV_REGNUM) | |
728 | { | |
729 | LONGEST d; | |
730 | uint8_t priv; | |
731 | ||
732 | d = value_as_long (val); | |
733 | priv = d & 0xff; | |
734 | ||
735 | if (priv < 4) | |
736 | { | |
737 | static const char * const sprv[] = | |
738 | { | |
739 | "User/Application", | |
740 | "Supervisor", | |
741 | "Hypervisor", | |
742 | "Machine" | |
743 | }; | |
744 | fprintf_filtered (file, "\tprv:%d [%s]", | |
745 | priv, sprv[priv]); | |
746 | } | |
747 | else | |
748 | fprintf_filtered (file, "\tprv:%d [INVALID]", priv); | |
749 | } | |
750 | else | |
751 | { | |
752 | /* If not a vector register, print it also according to its | |
753 | natural format. */ | |
754 | if (TYPE_VECTOR (regtype) == 0) | |
755 | { | |
756 | get_user_print_options (&opts); | |
757 | opts.deref_ref = 1; | |
758 | fprintf_filtered (file, "\t"); | |
759 | val_print (regtype, | |
760 | value_embedded_offset (val), 0, | |
761 | file, 0, val, &opts, current_language); | |
762 | } | |
763 | } | |
764 | } | |
765 | } | |
766 | fprintf_filtered (file, "\n"); | |
767 | } | |
768 | ||
769 | /* Implement the register_reggroup_p gdbarch method. Is REGNUM a member | |
770 | of REGGROUP? */ | |
771 | ||
772 | static int | |
773 | riscv_register_reggroup_p (struct gdbarch *gdbarch, int regnum, | |
774 | struct reggroup *reggroup) | |
775 | { | |
776 | int float_p; | |
777 | int raw_p; | |
778 | unsigned int i; | |
779 | ||
780 | /* Used by 'info registers' and 'info registers <groupname>'. */ | |
781 | ||
782 | if (gdbarch_register_name (gdbarch, regnum) == NULL | |
783 | || gdbarch_register_name (gdbarch, regnum)[0] == '\0') | |
784 | return 0; | |
785 | ||
786 | if (reggroup == all_reggroup) | |
787 | { | |
788 | if (regnum < RISCV_FIRST_CSR_REGNUM || regnum == RISCV_PRIV_REGNUM) | |
789 | return 1; | |
790 | /* Only include CSRs that have aliases. */ | |
791 | for (i = 0; i < ARRAY_SIZE (riscv_register_aliases); ++i) | |
792 | { | |
793 | if (regnum == riscv_register_aliases[i].regnum) | |
794 | return 1; | |
795 | } | |
796 | return 0; | |
797 | } | |
798 | else if (reggroup == float_reggroup) | |
8c49aa89 AB |
799 | return (riscv_is_fp_regno_p (regnum) |
800 | || regnum == RISCV_CSR_FCSR_REGNUM | |
801 | || regnum == RISCV_CSR_FFLAGS_REGNUM | |
802 | || regnum == RISCV_CSR_FRM_REGNUM); | |
dbbb1059 AB |
803 | else if (reggroup == general_reggroup) |
804 | return regnum < RISCV_FIRST_FP_REGNUM; | |
805 | else if (reggroup == restore_reggroup || reggroup == save_reggroup) | |
806 | { | |
807 | if (riscv_has_fp_regs (gdbarch)) | |
808 | return regnum <= RISCV_LAST_FP_REGNUM; | |
809 | else | |
810 | return regnum < RISCV_FIRST_FP_REGNUM; | |
811 | } | |
812 | else if (reggroup == system_reggroup) | |
813 | { | |
814 | if (regnum == RISCV_PRIV_REGNUM) | |
815 | return 1; | |
816 | if (regnum < RISCV_FIRST_CSR_REGNUM || regnum > RISCV_LAST_CSR_REGNUM) | |
817 | return 0; | |
818 | /* Only include CSRs that have aliases. */ | |
819 | for (i = 0; i < ARRAY_SIZE (riscv_register_aliases); ++i) | |
820 | { | |
821 | if (regnum == riscv_register_aliases[i].regnum) | |
822 | return 1; | |
823 | } | |
824 | return 0; | |
825 | } | |
826 | else if (reggroup == vector_reggroup) | |
827 | return 0; | |
828 | else | |
829 | return 0; | |
830 | } | |
831 | ||
832 | /* Implement the print_registers_info gdbarch method. This is used by | |
833 | 'info registers' and 'info all-registers'. */ | |
834 | ||
835 | static void | |
836 | riscv_print_registers_info (struct gdbarch *gdbarch, | |
837 | struct ui_file *file, | |
838 | struct frame_info *frame, | |
839 | int regnum, int print_all) | |
840 | { | |
841 | if (regnum != -1) | |
842 | { | |
843 | /* Print one specified register. */ | |
844 | gdb_assert (regnum <= RISCV_LAST_REGNUM); | |
845 | if (gdbarch_register_name (gdbarch, regnum) == NULL | |
846 | || *(gdbarch_register_name (gdbarch, regnum)) == '\0') | |
847 | error (_("Not a valid register for the current processor type")); | |
848 | riscv_print_one_register_info (gdbarch, file, frame, regnum); | |
849 | } | |
850 | else | |
851 | { | |
852 | struct reggroup *reggroup; | |
853 | ||
854 | if (print_all) | |
855 | reggroup = all_reggroup; | |
856 | else | |
857 | reggroup = general_reggroup; | |
858 | ||
859 | for (regnum = 0; regnum <= RISCV_LAST_REGNUM; ++regnum) | |
860 | { | |
861 | /* Zero never changes, so might as well hide by default. */ | |
862 | if (regnum == RISCV_ZERO_REGNUM && !print_all) | |
863 | continue; | |
864 | ||
865 | /* Registers with no name are not valid on this ISA. */ | |
866 | if (gdbarch_register_name (gdbarch, regnum) == NULL | |
867 | || *(gdbarch_register_name (gdbarch, regnum)) == '\0') | |
868 | continue; | |
869 | ||
870 | /* Is the register in the group we're interested in? */ | |
871 | if (!riscv_register_reggroup_p (gdbarch, regnum, reggroup)) | |
872 | continue; | |
873 | ||
874 | riscv_print_one_register_info (gdbarch, file, frame, regnum); | |
875 | } | |
876 | } | |
877 | } | |
878 | ||
879 | /* Class that handles one decoded RiscV instruction. */ | |
880 | ||
881 | class riscv_insn | |
882 | { | |
883 | public: | |
884 | ||
885 | /* Enum of all the opcodes that GDB cares about during the prologue scan. */ | |
886 | enum opcode | |
887 | { | |
888 | /* Unknown value is used at initialisation time. */ | |
889 | UNKNOWN = 0, | |
890 | ||
891 | /* These instructions are all the ones we are interested in during the | |
892 | prologue scan. */ | |
893 | ADD, | |
894 | ADDI, | |
895 | ADDIW, | |
896 | ADDW, | |
897 | AUIPC, | |
898 | LUI, | |
899 | SD, | |
900 | SW, | |
901 | ||
902 | /* Other instructions are not interesting during the prologue scan, and | |
903 | are ignored. */ | |
904 | OTHER | |
905 | }; | |
906 | ||
907 | riscv_insn () | |
908 | : m_length (0), | |
909 | m_opcode (OTHER), | |
910 | m_rd (0), | |
911 | m_rs1 (0), | |
912 | m_rs2 (0) | |
913 | { | |
914 | /* Nothing. */ | |
915 | } | |
916 | ||
917 | void decode (struct gdbarch *gdbarch, CORE_ADDR pc); | |
918 | ||
919 | /* Get the length of the instruction in bytes. */ | |
920 | int length () const | |
921 | { return m_length; } | |
922 | ||
923 | /* Get the opcode for this instruction. */ | |
924 | enum opcode opcode () const | |
925 | { return m_opcode; } | |
926 | ||
927 | /* Get destination register field for this instruction. This is only | |
928 | valid if the OPCODE implies there is such a field for this | |
929 | instruction. */ | |
930 | int rd () const | |
931 | { return m_rd; } | |
932 | ||
933 | /* Get the RS1 register field for this instruction. This is only valid | |
934 | if the OPCODE implies there is such a field for this instruction. */ | |
935 | int rs1 () const | |
936 | { return m_rs1; } | |
937 | ||
938 | /* Get the RS2 register field for this instruction. This is only valid | |
939 | if the OPCODE implies there is such a field for this instruction. */ | |
940 | int rs2 () const | |
941 | { return m_rs2; } | |
942 | ||
943 | /* Get the immediate for this instruction in signed form. This is only | |
944 | valid if the OPCODE implies there is such a field for this | |
945 | instruction. */ | |
946 | int imm_signed () const | |
947 | { return m_imm.s; } | |
948 | ||
949 | private: | |
950 | ||
951 | /* Extract 5 bit register field at OFFSET from instruction OPCODE. */ | |
952 | int decode_register_index (unsigned long opcode, int offset) | |
953 | { | |
954 | return (opcode >> offset) & 0x1F; | |
955 | } | |
956 | ||
957 | /* Helper for DECODE, decode 32-bit R-type instruction. */ | |
958 | void decode_r_type_insn (enum opcode opcode, ULONGEST ival) | |
959 | { | |
960 | m_opcode = opcode; | |
961 | m_rd = decode_register_index (ival, OP_SH_RD); | |
962 | m_rs1 = decode_register_index (ival, OP_SH_RS1); | |
963 | m_rs2 = decode_register_index (ival, OP_SH_RS2); | |
964 | } | |
965 | ||
966 | /* Helper for DECODE, decode 16-bit compressed R-type instruction. */ | |
967 | void decode_cr_type_insn (enum opcode opcode, ULONGEST ival) | |
968 | { | |
969 | m_opcode = opcode; | |
970 | m_rd = m_rs1 = decode_register_index (ival, OP_SH_CRS1S); | |
971 | m_rs2 = decode_register_index (ival, OP_SH_CRS2); | |
972 | } | |
973 | ||
974 | /* Helper for DECODE, decode 32-bit I-type instruction. */ | |
975 | void decode_i_type_insn (enum opcode opcode, ULONGEST ival) | |
976 | { | |
977 | m_opcode = opcode; | |
978 | m_rd = decode_register_index (ival, OP_SH_RD); | |
979 | m_rs1 = decode_register_index (ival, OP_SH_RS1); | |
980 | m_imm.s = EXTRACT_ITYPE_IMM (ival); | |
981 | } | |
982 | ||
983 | /* Helper for DECODE, decode 16-bit compressed I-type instruction. */ | |
984 | void decode_ci_type_insn (enum opcode opcode, ULONGEST ival) | |
985 | { | |
986 | m_opcode = opcode; | |
987 | m_rd = m_rs1 = decode_register_index (ival, OP_SH_CRS1S); | |
988 | m_imm.s = EXTRACT_RVC_IMM (ival); | |
989 | } | |
990 | ||
991 | /* Helper for DECODE, decode 32-bit S-type instruction. */ | |
992 | void decode_s_type_insn (enum opcode opcode, ULONGEST ival) | |
993 | { | |
994 | m_opcode = opcode; | |
995 | m_rs1 = decode_register_index (ival, OP_SH_RS1); | |
996 | m_rs2 = decode_register_index (ival, OP_SH_RS2); | |
997 | m_imm.s = EXTRACT_STYPE_IMM (ival); | |
998 | } | |
999 | ||
1000 | /* Helper for DECODE, decode 32-bit U-type instruction. */ | |
1001 | void decode_u_type_insn (enum opcode opcode, ULONGEST ival) | |
1002 | { | |
1003 | m_opcode = opcode; | |
1004 | m_rd = decode_register_index (ival, OP_SH_RD); | |
1005 | m_imm.s = EXTRACT_UTYPE_IMM (ival); | |
1006 | } | |
1007 | ||
1008 | /* Fetch instruction from target memory at ADDR, return the content of | |
1009 | the instruction, and update LEN with the instruction length. */ | |
1010 | static ULONGEST fetch_instruction (struct gdbarch *gdbarch, | |
1011 | CORE_ADDR addr, int *len); | |
1012 | ||
1013 | /* The length of the instruction in bytes. Should be 2 or 4. */ | |
1014 | int m_length; | |
1015 | ||
1016 | /* The instruction opcode. */ | |
1017 | enum opcode m_opcode; | |
1018 | ||
1019 | /* The three possible registers an instruction might reference. Not | |
1020 | every instruction fills in all of these registers. Which fields are | |
1021 | valid depends on the opcode. The naming of these fields matches the | |
1022 | naming in the riscv isa manual. */ | |
1023 | int m_rd; | |
1024 | int m_rs1; | |
1025 | int m_rs2; | |
1026 | ||
1027 | /* Possible instruction immediate. This is only valid if the instruction | |
1028 | format contains an immediate, not all instruction, whether this is | |
1029 | valid depends on the opcode. Despite only having one format for now | |
1030 | the immediate is packed into a union, later instructions might require | |
1031 | an unsigned formatted immediate, having the union in place now will | |
1032 | reduce the need for code churn later. */ | |
1033 | union riscv_insn_immediate | |
1034 | { | |
1035 | riscv_insn_immediate () | |
1036 | : s (0) | |
1037 | { | |
1038 | /* Nothing. */ | |
1039 | } | |
1040 | ||
1041 | int s; | |
1042 | } m_imm; | |
1043 | }; | |
1044 | ||
1045 | /* Fetch instruction from target memory at ADDR, return the content of the | |
1046 | instruction, and update LEN with the instruction length. */ | |
1047 | ||
1048 | ULONGEST | |
1049 | riscv_insn::fetch_instruction (struct gdbarch *gdbarch, | |
1050 | CORE_ADDR addr, int *len) | |
1051 | { | |
1052 | enum bfd_endian byte_order = gdbarch_byte_order_for_code (gdbarch); | |
1053 | gdb_byte buf[8]; | |
1054 | int instlen, status; | |
1055 | ||
1056 | /* All insns are at least 16 bits. */ | |
1057 | status = target_read_memory (addr, buf, 2); | |
1058 | if (status) | |
1059 | memory_error (TARGET_XFER_E_IO, addr); | |
1060 | ||
1061 | /* If we need more, grab it now. */ | |
1062 | instlen = riscv_insn_length (buf[0]); | |
89a3b63e | 1063 | gdb_assert (instlen <= sizeof (buf)); |
dbbb1059 | 1064 | *len = instlen; |
89a3b63e AB |
1065 | |
1066 | if (instlen > 2) | |
dbbb1059 AB |
1067 | { |
1068 | status = target_read_memory (addr + 2, buf + 2, instlen - 2); | |
1069 | if (status) | |
1070 | memory_error (TARGET_XFER_E_IO, addr + 2); | |
1071 | } | |
1072 | ||
1073 | return extract_unsigned_integer (buf, instlen, byte_order); | |
1074 | } | |
1075 | ||
1076 | /* Fetch from target memory an instruction at PC and decode it. */ | |
1077 | ||
1078 | void | |
1079 | riscv_insn::decode (struct gdbarch *gdbarch, CORE_ADDR pc) | |
1080 | { | |
1081 | ULONGEST ival; | |
1082 | ||
1083 | /* Fetch the instruction, and the instructions length. */ | |
1084 | ival = fetch_instruction (gdbarch, pc, &m_length); | |
1085 | ||
1086 | if (m_length == 4) | |
1087 | { | |
1088 | if (is_add_insn (ival)) | |
1089 | decode_r_type_insn (ADD, ival); | |
1090 | else if (is_addw_insn (ival)) | |
1091 | decode_r_type_insn (ADDW, ival); | |
1092 | else if (is_addi_insn (ival)) | |
1093 | decode_i_type_insn (ADDI, ival); | |
1094 | else if (is_addiw_insn (ival)) | |
1095 | decode_i_type_insn (ADDIW, ival); | |
1096 | else if (is_auipc_insn (ival)) | |
1097 | decode_u_type_insn (AUIPC, ival); | |
1098 | else if (is_lui_insn (ival)) | |
1099 | decode_u_type_insn (LUI, ival); | |
1100 | else if (is_sd_insn (ival)) | |
1101 | decode_s_type_insn (SD, ival); | |
1102 | else if (is_sw_insn (ival)) | |
1103 | decode_s_type_insn (SW, ival); | |
1104 | else | |
1105 | /* None of the other fields are valid in this case. */ | |
1106 | m_opcode = OTHER; | |
1107 | } | |
1108 | else if (m_length == 2) | |
1109 | { | |
1110 | if (is_c_add_insn (ival)) | |
1111 | decode_cr_type_insn (ADD, ival); | |
1112 | else if (is_c_addw_insn (ival)) | |
1113 | decode_cr_type_insn (ADDW, ival); | |
1114 | else if (is_c_addi_insn (ival)) | |
1115 | decode_ci_type_insn (ADDI, ival); | |
1116 | else if (is_c_addiw_insn (ival)) | |
1117 | decode_ci_type_insn (ADDIW, ival); | |
1118 | else if (is_c_addi16sp_insn (ival)) | |
1119 | { | |
1120 | m_opcode = ADDI; | |
1121 | m_rd = m_rs1 = decode_register_index (ival, OP_SH_RD); | |
1122 | m_imm.s = EXTRACT_RVC_ADDI16SP_IMM (ival); | |
1123 | } | |
1124 | else if (is_lui_insn (ival)) | |
1125 | m_opcode = OTHER; | |
1126 | else if (is_c_sd_insn (ival)) | |
1127 | m_opcode = OTHER; | |
1128 | else if (is_sw_insn (ival)) | |
1129 | m_opcode = OTHER; | |
1130 | else | |
1131 | /* None of the other fields of INSN are valid in this case. */ | |
1132 | m_opcode = OTHER; | |
1133 | } | |
1134 | else | |
1135 | internal_error (__FILE__, __LINE__, | |
1136 | _("unable to decode %d byte instructions in " | |
1137 | "prologue at %s"), m_length, | |
1138 | core_addr_to_string (pc)); | |
1139 | } | |
1140 | ||
1141 | /* The prologue scanner. This is currently only used for skipping the | |
1142 | prologue of a function when the DWARF information is not sufficient. | |
1143 | However, it is written with filling of the frame cache in mind, which | |
1144 | is why different groups of stack setup instructions are split apart | |
1145 | during the core of the inner loop. In the future, the intention is to | |
1146 | extend this function to fully support building up a frame cache that | |
1147 | can unwind register values when there is no DWARF information. */ | |
1148 | ||
1149 | static CORE_ADDR | |
1150 | riscv_scan_prologue (struct gdbarch *gdbarch, | |
1151 | CORE_ADDR start_pc, CORE_ADDR limit_pc) | |
1152 | { | |
1153 | CORE_ADDR cur_pc, next_pc; | |
1154 | long frame_offset = 0; | |
1155 | CORE_ADDR end_prologue_addr = 0; | |
1156 | ||
1157 | if (limit_pc > start_pc + 200) | |
1158 | limit_pc = start_pc + 200; | |
1159 | ||
1160 | for (next_pc = cur_pc = start_pc; cur_pc < limit_pc; cur_pc = next_pc) | |
1161 | { | |
1162 | struct riscv_insn insn; | |
1163 | ||
1164 | /* Decode the current instruction, and decide where the next | |
1165 | instruction lives based on the size of this instruction. */ | |
1166 | insn.decode (gdbarch, cur_pc); | |
1167 | gdb_assert (insn.length () > 0); | |
1168 | next_pc = cur_pc + insn.length (); | |
1169 | ||
1170 | /* Look for common stack adjustment insns. */ | |
1171 | if ((insn.opcode () == riscv_insn::ADDI | |
1172 | || insn.opcode () == riscv_insn::ADDIW) | |
1173 | && insn.rd () == RISCV_SP_REGNUM | |
1174 | && insn.rs1 () == RISCV_SP_REGNUM) | |
1175 | { | |
1176 | /* Handle: addi sp, sp, -i | |
1177 | or: addiw sp, sp, -i */ | |
1178 | if (insn.imm_signed () < 0) | |
1179 | frame_offset += insn.imm_signed (); | |
1180 | else | |
1181 | break; | |
1182 | } | |
1183 | else if ((insn.opcode () == riscv_insn::SW | |
1184 | || insn.opcode () == riscv_insn::SD) | |
1185 | && (insn.rs1 () == RISCV_SP_REGNUM | |
1186 | || insn.rs1 () == RISCV_FP_REGNUM)) | |
1187 | { | |
1188 | /* Handle: sw reg, offset(sp) | |
1189 | or: sd reg, offset(sp) | |
1190 | or: sw reg, offset(s0) | |
1191 | or: sd reg, offset(s0) */ | |
1192 | /* Instruction storing a register onto the stack. */ | |
1193 | } | |
1194 | else if (insn.opcode () == riscv_insn::ADDI | |
1195 | && insn.rd () == RISCV_FP_REGNUM | |
1196 | && insn.rs1 () == RISCV_SP_REGNUM) | |
1197 | { | |
1198 | /* Handle: addi s0, sp, size */ | |
1199 | /* Instructions setting up the frame pointer. */ | |
1200 | } | |
1201 | else if ((insn.opcode () == riscv_insn::ADD | |
1202 | || insn.opcode () == riscv_insn::ADDW) | |
1203 | && insn.rd () == RISCV_FP_REGNUM | |
1204 | && insn.rs1 () == RISCV_SP_REGNUM | |
1205 | && insn.rs2 () == RISCV_ZERO_REGNUM) | |
1206 | { | |
1207 | /* Handle: add s0, sp, 0 | |
1208 | or: addw s0, sp, 0 */ | |
1209 | /* Instructions setting up the frame pointer. */ | |
1210 | } | |
1211 | else if ((insn.rd () == RISCV_GP_REGNUM | |
1212 | && (insn.opcode () == riscv_insn::AUIPC | |
1213 | || insn.opcode () == riscv_insn::LUI | |
1214 | || (insn.opcode () == riscv_insn::ADDI | |
1215 | && insn.rs1 () == RISCV_GP_REGNUM) | |
1216 | || (insn.opcode () == riscv_insn::ADD | |
1217 | && (insn.rs1 () == RISCV_GP_REGNUM | |
1218 | || insn.rs2 () == RISCV_GP_REGNUM)))) | |
1219 | || (insn.opcode () == riscv_insn::ADDI | |
1220 | && insn.rd () == RISCV_ZERO_REGNUM | |
1221 | && insn.rs1 () == RISCV_ZERO_REGNUM | |
1222 | && insn.imm_signed () == 0)) | |
1223 | { | |
1224 | /* Handle: auipc gp, n | |
1225 | or: addi gp, gp, n | |
1226 | or: add gp, gp, reg | |
1227 | or: add gp, reg, gp | |
1228 | or: lui gp, n | |
1229 | or: add x0, x0, 0 (NOP) */ | |
1230 | /* These instructions are part of the prologue, but we don't need | |
1231 | to do anything special to handle them. */ | |
1232 | } | |
1233 | else | |
1234 | { | |
1235 | if (end_prologue_addr == 0) | |
1236 | end_prologue_addr = cur_pc; | |
1237 | } | |
1238 | } | |
1239 | ||
1240 | if (end_prologue_addr == 0) | |
1241 | end_prologue_addr = cur_pc; | |
1242 | ||
1243 | return end_prologue_addr; | |
1244 | } | |
1245 | ||
1246 | /* Implement the riscv_skip_prologue gdbarch method. */ | |
1247 | ||
1248 | static CORE_ADDR | |
1249 | riscv_skip_prologue (struct gdbarch *gdbarch, | |
1250 | CORE_ADDR pc) | |
1251 | { | |
1252 | CORE_ADDR limit_pc; | |
1253 | CORE_ADDR func_addr; | |
1254 | ||
1255 | /* See if we can determine the end of the prologue via the symbol | |
1256 | table. If so, then return either PC, or the PC after the | |
1257 | prologue, whichever is greater. */ | |
1258 | if (find_pc_partial_function (pc, NULL, &func_addr, NULL)) | |
1259 | { | |
1260 | CORE_ADDR post_prologue_pc | |
1261 | = skip_prologue_using_sal (gdbarch, func_addr); | |
1262 | ||
1263 | if (post_prologue_pc != 0) | |
1264 | return std::max (pc, post_prologue_pc); | |
1265 | } | |
1266 | ||
1267 | /* Can't determine prologue from the symbol table, need to examine | |
1268 | instructions. */ | |
1269 | ||
1270 | /* Find an upper limit on the function prologue using the debug | |
1271 | information. If the debug information could not be used to provide | |
1272 | that bound, then use an arbitrary large number as the upper bound. */ | |
1273 | limit_pc = skip_prologue_using_sal (gdbarch, pc); | |
1274 | if (limit_pc == 0) | |
1275 | limit_pc = pc + 100; /* MAGIC! */ | |
1276 | ||
1277 | return riscv_scan_prologue (gdbarch, pc, limit_pc); | |
1278 | } | |
1279 | ||
1280 | /* Implement the gdbarch push dummy code callback. */ | |
1281 | ||
1282 | static CORE_ADDR | |
1283 | riscv_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, | |
1284 | CORE_ADDR funaddr, struct value **args, int nargs, | |
1285 | struct type *value_type, CORE_ADDR *real_pc, | |
1286 | CORE_ADDR *bp_addr, struct regcache *regcache) | |
1287 | { | |
1288 | /* Allocate space for a breakpoint, and keep the stack correctly | |
1289 | aligned. */ | |
1290 | sp -= 16; | |
1291 | *bp_addr = sp; | |
1292 | *real_pc = funaddr; | |
1293 | return sp; | |
1294 | } | |
1295 | ||
1296 | /* Compute the alignment of the type T. Used while setting up the | |
1297 | arguments for a dummy call. */ | |
1298 | ||
1299 | static int | |
1300 | riscv_type_alignment (struct type *t) | |
1301 | { | |
1302 | t = check_typedef (t); | |
1303 | switch (TYPE_CODE (t)) | |
1304 | { | |
1305 | default: | |
1306 | error (_("Could not compute alignment of type")); | |
1307 | ||
1308 | case TYPE_CODE_RVALUE_REF: | |
1309 | case TYPE_CODE_PTR: | |
1310 | case TYPE_CODE_ENUM: | |
1311 | case TYPE_CODE_INT: | |
1312 | case TYPE_CODE_FLT: | |
1313 | case TYPE_CODE_REF: | |
1314 | case TYPE_CODE_CHAR: | |
1315 | case TYPE_CODE_BOOL: | |
1316 | return TYPE_LENGTH (t); | |
1317 | ||
1318 | case TYPE_CODE_ARRAY: | |
1319 | case TYPE_CODE_COMPLEX: | |
1320 | return riscv_type_alignment (TYPE_TARGET_TYPE (t)); | |
1321 | ||
1322 | case TYPE_CODE_STRUCT: | |
1323 | case TYPE_CODE_UNION: | |
1324 | { | |
1325 | int i; | |
1326 | int align = 1; | |
1327 | ||
1328 | for (i = 0; i < TYPE_NFIELDS (t); ++i) | |
1329 | { | |
1330 | if (TYPE_FIELD_LOC_KIND (t, i) == FIELD_LOC_KIND_BITPOS) | |
1331 | { | |
1332 | int a = riscv_type_alignment (TYPE_FIELD_TYPE (t, i)); | |
1333 | if (a > align) | |
1334 | align = a; | |
1335 | } | |
1336 | } | |
1337 | return align; | |
1338 | } | |
1339 | } | |
1340 | } | |
1341 | ||
1342 | /* Holds information about a single argument either being passed to an | |
1343 | inferior function, or returned from an inferior function. This includes | |
1344 | information about the size, type, etc of the argument, and also | |
1345 | information about how the argument will be passed (or returned). */ | |
1346 | ||
1347 | struct riscv_arg_info | |
1348 | { | |
1349 | /* Contents of the argument. */ | |
1350 | const gdb_byte *contents; | |
1351 | ||
1352 | /* Length of argument. */ | |
1353 | int length; | |
1354 | ||
1355 | /* Alignment required for an argument of this type. */ | |
1356 | int align; | |
1357 | ||
1358 | /* The type for this argument. */ | |
1359 | struct type *type; | |
1360 | ||
1361 | /* Each argument can have either 1 or 2 locations assigned to it. Each | |
1362 | location describes where part of the argument will be placed. The | |
1363 | second location is valid based on the LOC_TYPE and C_LENGTH fields | |
1364 | of the first location (which is always valid). */ | |
1365 | struct location | |
1366 | { | |
1367 | /* What type of location this is. */ | |
1368 | enum location_type | |
1369 | { | |
1370 | /* Argument passed in a register. */ | |
1371 | in_reg, | |
1372 | ||
1373 | /* Argument passed as an on stack argument. */ | |
1374 | on_stack, | |
1375 | ||
1376 | /* Argument passed by reference. The second location is always | |
1377 | valid for a BY_REF argument, and describes where the address | |
1378 | of the BY_REF argument should be placed. */ | |
1379 | by_ref | |
1380 | } loc_type; | |
1381 | ||
1382 | /* Information that depends on the location type. */ | |
1383 | union | |
1384 | { | |
1385 | /* Which register number to use. */ | |
1386 | int regno; | |
1387 | ||
1388 | /* The offset into the stack region. */ | |
1389 | int offset; | |
1390 | } loc_data; | |
1391 | ||
1392 | /* The length of contents covered by this location. If this is less | |
1393 | than the total length of the argument, then the second location | |
1394 | will be valid, and will describe where the rest of the argument | |
1395 | will go. */ | |
1396 | int c_length; | |
1397 | ||
1398 | /* The offset within CONTENTS for this part of the argument. Will | |
1399 | always be 0 for the first part. For the second part of the | |
1400 | argument, this might be the C_LENGTH value of the first part, | |
1401 | however, if we are passing a structure in two registers, and there's | |
1402 | is padding between the first and second field, then this offset | |
1403 | might be greater than the length of the first argument part. When | |
1404 | the second argument location is not holding part of the argument | |
1405 | value, but is instead holding the address of a reference argument, | |
1406 | then this offset will be set to 0. */ | |
1407 | int c_offset; | |
1408 | } argloc[2]; | |
1409 | }; | |
1410 | ||
1411 | /* Information about a set of registers being used for passing arguments as | |
1412 | part of a function call. The register set must be numerically | |
1413 | sequential from NEXT_REGNUM to LAST_REGNUM. The register set can be | |
1414 | disabled from use by setting NEXT_REGNUM greater than LAST_REGNUM. */ | |
1415 | ||
1416 | struct riscv_arg_reg | |
1417 | { | |
1418 | riscv_arg_reg (int first, int last) | |
1419 | : next_regnum (first), | |
1420 | last_regnum (last) | |
1421 | { | |
1422 | /* Nothing. */ | |
1423 | } | |
1424 | ||
1425 | /* The GDB register number to use in this set. */ | |
1426 | int next_regnum; | |
1427 | ||
1428 | /* The last GDB register number to use in this set. */ | |
1429 | int last_regnum; | |
1430 | }; | |
1431 | ||
1432 | /* Arguments can be passed as on stack arguments, or by reference. The | |
1433 | on stack arguments must be in a continuous region starting from $sp, | |
1434 | while the by reference arguments can be anywhere, but we'll put them | |
1435 | on the stack after (at higher address) the on stack arguments. | |
1436 | ||
1437 | This might not be the right approach to take. The ABI is clear that | |
1438 | an argument passed by reference can be modified by the callee, which | |
1439 | us placing the argument (temporarily) onto the stack will not achieve | |
1440 | (changes will be lost). There's also the possibility that very large | |
1441 | arguments could overflow the stack. | |
1442 | ||
1443 | This struct is used to track offset into these two areas for where | |
1444 | arguments are to be placed. */ | |
1445 | struct riscv_memory_offsets | |
1446 | { | |
1447 | riscv_memory_offsets () | |
1448 | : arg_offset (0), | |
1449 | ref_offset (0) | |
1450 | { | |
1451 | /* Nothing. */ | |
1452 | } | |
1453 | ||
1454 | /* Offset into on stack argument area. */ | |
1455 | int arg_offset; | |
1456 | ||
1457 | /* Offset into the pass by reference area. */ | |
1458 | int ref_offset; | |
1459 | }; | |
1460 | ||
1461 | /* Holds information about where arguments to a call will be placed. This | |
1462 | is updated as arguments are added onto the call, and can be used to | |
1463 | figure out where the next argument should be placed. */ | |
1464 | ||
1465 | struct riscv_call_info | |
1466 | { | |
1467 | riscv_call_info (struct gdbarch *gdbarch) | |
1468 | : int_regs (RISCV_A0_REGNUM, RISCV_A0_REGNUM + 7), | |
1469 | float_regs (RISCV_FA0_REGNUM, RISCV_FA0_REGNUM + 7) | |
1470 | { | |
1471 | xlen = riscv_isa_xlen (gdbarch); | |
1472 | flen = riscv_isa_flen (gdbarch); | |
1473 | ||
1474 | /* Disable use of floating point registers if needed. */ | |
1475 | if (!riscv_has_fp_abi (gdbarch)) | |
1476 | float_regs.next_regnum = float_regs.last_regnum + 1; | |
1477 | } | |
1478 | ||
1479 | /* Track the memory areas used for holding in-memory arguments to a | |
1480 | call. */ | |
1481 | struct riscv_memory_offsets memory; | |
1482 | ||
1483 | /* Holds information about the next integer register to use for passing | |
1484 | an argument. */ | |
1485 | struct riscv_arg_reg int_regs; | |
1486 | ||
1487 | /* Holds information about the next floating point register to use for | |
1488 | passing an argument. */ | |
1489 | struct riscv_arg_reg float_regs; | |
1490 | ||
1491 | /* The XLEN and FLEN are copied in to this structure for convenience, and | |
1492 | are just the results of calling RISCV_ISA_XLEN and RISCV_ISA_FLEN. */ | |
1493 | int xlen; | |
1494 | int flen; | |
1495 | }; | |
1496 | ||
1497 | /* Return the number of registers available for use as parameters in the | |
1498 | register set REG. Returned value can be 0 or more. */ | |
1499 | ||
1500 | static int | |
1501 | riscv_arg_regs_available (struct riscv_arg_reg *reg) | |
1502 | { | |
1503 | if (reg->next_regnum > reg->last_regnum) | |
1504 | return 0; | |
1505 | ||
1506 | return (reg->last_regnum - reg->next_regnum + 1); | |
1507 | } | |
1508 | ||
1509 | /* If there is at least one register available in the register set REG then | |
1510 | the next register from REG is assigned to LOC and the length field of | |
1511 | LOC is updated to LENGTH. The register set REG is updated to indicate | |
1512 | that the assigned register is no longer available and the function | |
1513 | returns true. | |
1514 | ||
1515 | If there are no registers available in REG then the function returns | |
1516 | false, and LOC and REG are unchanged. */ | |
1517 | ||
1518 | static bool | |
1519 | riscv_assign_reg_location (struct riscv_arg_info::location *loc, | |
1520 | struct riscv_arg_reg *reg, | |
1521 | int length, int offset) | |
1522 | { | |
1523 | if (reg->next_regnum <= reg->last_regnum) | |
1524 | { | |
1525 | loc->loc_type = riscv_arg_info::location::in_reg; | |
1526 | loc->loc_data.regno = reg->next_regnum; | |
1527 | reg->next_regnum++; | |
1528 | loc->c_length = length; | |
1529 | loc->c_offset = offset; | |
1530 | return true; | |
1531 | } | |
1532 | ||
1533 | return false; | |
1534 | } | |
1535 | ||
1536 | /* Assign LOC a location as the next stack parameter, and update MEMORY to | |
1537 | record that an area of stack has been used to hold the parameter | |
1538 | described by LOC. | |
1539 | ||
1540 | The length field of LOC is updated to LENGTH, the length of the | |
1541 | parameter being stored, and ALIGN is the alignment required by the | |
1542 | parameter, which will affect how memory is allocated out of MEMORY. */ | |
1543 | ||
1544 | static void | |
1545 | riscv_assign_stack_location (struct riscv_arg_info::location *loc, | |
1546 | struct riscv_memory_offsets *memory, | |
1547 | int length, int align) | |
1548 | { | |
1549 | loc->loc_type = riscv_arg_info::location::on_stack; | |
1550 | memory->arg_offset | |
1551 | = align_up (memory->arg_offset, align); | |
1552 | loc->loc_data.offset = memory->arg_offset; | |
1553 | memory->arg_offset += length; | |
1554 | loc->c_length = length; | |
1555 | ||
1556 | /* Offset is always 0, either we're the first location part, in which | |
1557 | case we're reading content from the start of the argument, or we're | |
1558 | passing the address of a reference argument, so 0. */ | |
1559 | loc->c_offset = 0; | |
1560 | } | |
1561 | ||
1562 | /* Update AINFO, which describes an argument that should be passed or | |
1563 | returned using the integer ABI. The argloc fields within AINFO are | |
1564 | updated to describe the location in which the argument will be passed to | |
1565 | a function, or returned from a function. | |
1566 | ||
1567 | The CINFO structure contains the ongoing call information, the holds | |
1568 | information such as which argument registers are remaining to be | |
1569 | assigned to parameter, and how much memory has been used by parameters | |
1570 | so far. | |
1571 | ||
1572 | By examining the state of CINFO a suitable location can be selected, | |
1573 | and assigned to AINFO. */ | |
1574 | ||
1575 | static void | |
1576 | riscv_call_arg_scalar_int (struct riscv_arg_info *ainfo, | |
1577 | struct riscv_call_info *cinfo) | |
1578 | { | |
1579 | if (ainfo->length > (2 * cinfo->xlen)) | |
1580 | { | |
1581 | /* Argument is going to be passed by reference. */ | |
1582 | ainfo->argloc[0].loc_type | |
1583 | = riscv_arg_info::location::by_ref; | |
1584 | cinfo->memory.ref_offset | |
1585 | = align_up (cinfo->memory.ref_offset, ainfo->align); | |
1586 | ainfo->argloc[0].loc_data.offset = cinfo->memory.ref_offset; | |
1587 | cinfo->memory.ref_offset += ainfo->length; | |
1588 | ainfo->argloc[0].c_length = ainfo->length; | |
1589 | ||
1590 | /* The second location for this argument is given over to holding the | |
1591 | address of the by-reference data. Pass 0 for the offset as this | |
1592 | is not part of the actual argument value. */ | |
1593 | if (!riscv_assign_reg_location (&ainfo->argloc[1], | |
1594 | &cinfo->int_regs, | |
1595 | cinfo->xlen, 0)) | |
1596 | riscv_assign_stack_location (&ainfo->argloc[1], | |
1597 | &cinfo->memory, cinfo->xlen, | |
1598 | cinfo->xlen); | |
1599 | } | |
1600 | else | |
1601 | { | |
1602 | int len = (ainfo->length > cinfo->xlen) ? cinfo->xlen : ainfo->length; | |
1603 | ||
1604 | if (!riscv_assign_reg_location (&ainfo->argloc[0], | |
1605 | &cinfo->int_regs, len, 0)) | |
1606 | riscv_assign_stack_location (&ainfo->argloc[0], | |
1607 | &cinfo->memory, len, ainfo->align); | |
1608 | ||
1609 | if (len < ainfo->length) | |
1610 | { | |
1611 | len = ainfo->length - len; | |
1612 | if (!riscv_assign_reg_location (&ainfo->argloc[1], | |
1613 | &cinfo->int_regs, len, | |
1614 | cinfo->xlen)) | |
1615 | riscv_assign_stack_location (&ainfo->argloc[1], | |
1616 | &cinfo->memory, len, cinfo->xlen); | |
1617 | } | |
1618 | } | |
1619 | } | |
1620 | ||
1621 | /* Like RISCV_CALL_ARG_SCALAR_INT, except the argument described by AINFO | |
1622 | is being passed with the floating point ABI. */ | |
1623 | ||
1624 | static void | |
1625 | riscv_call_arg_scalar_float (struct riscv_arg_info *ainfo, | |
1626 | struct riscv_call_info *cinfo) | |
1627 | { | |
1628 | if (ainfo->length > cinfo->flen) | |
1629 | return riscv_call_arg_scalar_int (ainfo, cinfo); | |
1630 | else | |
1631 | { | |
1632 | if (!riscv_assign_reg_location (&ainfo->argloc[0], | |
1633 | &cinfo->float_regs, | |
1634 | ainfo->length, 0)) | |
1635 | return riscv_call_arg_scalar_int (ainfo, cinfo); | |
1636 | } | |
1637 | } | |
1638 | ||
1639 | /* Like RISCV_CALL_ARG_SCALAR_INT, except the argument described by AINFO | |
1640 | is a complex floating point argument, and is therefore handled | |
1641 | differently to other argument types. */ | |
1642 | ||
1643 | static void | |
1644 | riscv_call_arg_complex_float (struct riscv_arg_info *ainfo, | |
1645 | struct riscv_call_info *cinfo) | |
1646 | { | |
1647 | if (ainfo->length <= (2 * cinfo->flen) | |
1648 | && riscv_arg_regs_available (&cinfo->float_regs) >= 2) | |
1649 | { | |
1650 | bool result; | |
1651 | int len = ainfo->length / 2; | |
1652 | ||
1653 | result = riscv_assign_reg_location (&ainfo->argloc[0], | |
1654 | &cinfo->float_regs, len, len); | |
1655 | gdb_assert (result); | |
1656 | ||
1657 | result = riscv_assign_reg_location (&ainfo->argloc[1], | |
1658 | &cinfo->float_regs, len, len); | |
1659 | gdb_assert (result); | |
1660 | } | |
1661 | else | |
1662 | return riscv_call_arg_scalar_int (ainfo, cinfo); | |
1663 | } | |
1664 | ||
1665 | /* A structure used for holding information about a structure type within | |
1666 | the inferior program. The RiscV ABI has special rules for handling some | |
1667 | structures with a single field or with two fields. The counting of | |
1668 | fields here is done after flattening out all nested structures. */ | |
1669 | ||
1670 | class riscv_struct_info | |
1671 | { | |
1672 | public: | |
1673 | riscv_struct_info () | |
1674 | : m_number_of_fields (0), | |
1675 | m_types { nullptr, nullptr } | |
1676 | { | |
1677 | /* Nothing. */ | |
1678 | } | |
1679 | ||
1680 | /* Analyse TYPE descending into nested structures, count the number of | |
1681 | scalar fields and record the types of the first two fields found. */ | |
1682 | void analyse (struct type *type); | |
1683 | ||
1684 | /* The number of scalar fields found in the analysed type. This is | |
1685 | currently only accurate if the value returned is 0, 1, or 2 as the | |
1686 | analysis stops counting when the number of fields is 3. This is | |
1687 | because the RiscV ABI only has special cases for 1 or 2 fields, | |
1688 | anything else we just don't care about. */ | |
1689 | int number_of_fields () const | |
1690 | { return m_number_of_fields; } | |
1691 | ||
1692 | /* Return the type for scalar field INDEX within the analysed type. Will | |
1693 | return nullptr if there is no field at that index. Only INDEX values | |
1694 | 0 and 1 can be requested as the RiscV ABI only has special cases for | |
1695 | structures with 1 or 2 fields. */ | |
1696 | struct type *field_type (int index) const | |
1697 | { | |
1698 | gdb_assert (index < (sizeof (m_types) / sizeof (m_types[0]))); | |
1699 | return m_types[index]; | |
1700 | } | |
1701 | ||
1702 | private: | |
1703 | /* The number of scalar fields found within the structure after recursing | |
1704 | into nested structures. */ | |
1705 | int m_number_of_fields; | |
1706 | ||
1707 | /* The types of the first two scalar fields found within the structure | |
1708 | after recursing into nested structures. */ | |
1709 | struct type *m_types[2]; | |
1710 | }; | |
1711 | ||
1712 | /* Analyse TYPE descending into nested structures, count the number of | |
1713 | scalar fields and record the types of the first two fields found. */ | |
1714 | ||
1715 | void | |
1716 | riscv_struct_info::analyse (struct type *type) | |
1717 | { | |
1718 | unsigned int count = TYPE_NFIELDS (type); | |
1719 | unsigned int i; | |
1720 | ||
1721 | for (i = 0; i < count; ++i) | |
1722 | { | |
1723 | if (TYPE_FIELD_LOC_KIND (type, i) != FIELD_LOC_KIND_BITPOS) | |
1724 | continue; | |
1725 | ||
1726 | struct type *field_type = TYPE_FIELD_TYPE (type, i); | |
1727 | field_type = check_typedef (field_type); | |
1728 | ||
1729 | switch (TYPE_CODE (field_type)) | |
1730 | { | |
1731 | case TYPE_CODE_STRUCT: | |
1732 | analyse (field_type); | |
1733 | break; | |
1734 | ||
1735 | default: | |
1736 | /* RiscV only flattens out structures. Anything else does not | |
1737 | need to be flattened, we just record the type, and when we | |
1738 | look at the analysis results we'll realise this is not a | |
1739 | structure we can special case, and pass the structure in | |
1740 | memory. */ | |
1741 | if (m_number_of_fields < 2) | |
1742 | m_types[m_number_of_fields] = field_type; | |
1743 | m_number_of_fields++; | |
1744 | break; | |
1745 | } | |
1746 | ||
1747 | /* RiscV only has special handling for structures with 1 or 2 scalar | |
1748 | fields, any more than that and the structure is just passed in | |
1749 | memory. We can safely drop out early when we find 3 or more | |
1750 | fields then. */ | |
1751 | ||
1752 | if (m_number_of_fields > 2) | |
1753 | return; | |
1754 | } | |
1755 | } | |
1756 | ||
1757 | /* Like RISCV_CALL_ARG_SCALAR_INT, except the argument described by AINFO | |
1758 | is a structure. Small structures on RiscV have some special case | |
1759 | handling in order that the structure might be passed in register. | |
1760 | Larger structures are passed in memory. After assigning location | |
1761 | information to AINFO, CINFO will have been updated. */ | |
1762 | ||
1763 | static void | |
1764 | riscv_call_arg_struct (struct riscv_arg_info *ainfo, | |
1765 | struct riscv_call_info *cinfo) | |
1766 | { | |
1767 | if (riscv_arg_regs_available (&cinfo->float_regs) >= 1) | |
1768 | { | |
1769 | struct riscv_struct_info sinfo; | |
1770 | ||
1771 | sinfo.analyse (ainfo->type); | |
1772 | if (sinfo.number_of_fields () == 1 | |
1773 | && TYPE_CODE (sinfo.field_type (0)) == TYPE_CODE_COMPLEX) | |
1774 | { | |
1775 | gdb_assert (TYPE_LENGTH (ainfo->type) | |
1776 | == TYPE_LENGTH (sinfo.field_type (0))); | |
1777 | return riscv_call_arg_complex_float (ainfo, cinfo); | |
1778 | } | |
1779 | ||
1780 | if (sinfo.number_of_fields () == 1 | |
1781 | && TYPE_CODE (sinfo.field_type (0)) == TYPE_CODE_FLT) | |
1782 | { | |
1783 | gdb_assert (TYPE_LENGTH (ainfo->type) | |
1784 | == TYPE_LENGTH (sinfo.field_type (0))); | |
1785 | return riscv_call_arg_scalar_float (ainfo, cinfo); | |
1786 | } | |
1787 | ||
1788 | if (sinfo.number_of_fields () == 2 | |
1789 | && TYPE_CODE (sinfo.field_type (0)) == TYPE_CODE_FLT | |
1790 | && TYPE_LENGTH (sinfo.field_type (0)) <= cinfo->flen | |
1791 | && TYPE_CODE (sinfo.field_type (1)) == TYPE_CODE_FLT | |
1792 | && TYPE_LENGTH (sinfo.field_type (1)) <= cinfo->flen | |
1793 | && riscv_arg_regs_available (&cinfo->float_regs) >= 2) | |
1794 | { | |
1795 | int len0, len1, offset; | |
1796 | ||
1797 | gdb_assert (TYPE_LENGTH (ainfo->type) <= (2 * cinfo->flen)); | |
1798 | ||
1799 | len0 = TYPE_LENGTH (sinfo.field_type (0)); | |
1800 | if (!riscv_assign_reg_location (&ainfo->argloc[0], | |
1801 | &cinfo->float_regs, len0, 0)) | |
1802 | error (_("failed during argument setup")); | |
1803 | ||
1804 | len1 = TYPE_LENGTH (sinfo.field_type (1)); | |
1805 | offset = align_up (len0, riscv_type_alignment (sinfo.field_type (1))); | |
1806 | gdb_assert (len1 <= (TYPE_LENGTH (ainfo->type) | |
1807 | - TYPE_LENGTH (sinfo.field_type (0)))); | |
1808 | ||
1809 | if (!riscv_assign_reg_location (&ainfo->argloc[1], | |
1810 | &cinfo->float_regs, | |
1811 | len1, offset)) | |
1812 | error (_("failed during argument setup")); | |
1813 | return; | |
1814 | } | |
1815 | ||
1816 | if (sinfo.number_of_fields () == 2 | |
1817 | && riscv_arg_regs_available (&cinfo->int_regs) >= 1 | |
1818 | && (TYPE_CODE (sinfo.field_type (0)) == TYPE_CODE_FLT | |
1819 | && TYPE_LENGTH (sinfo.field_type (0)) <= cinfo->flen | |
1820 | && is_integral_type (sinfo.field_type (1)) | |
1821 | && TYPE_LENGTH (sinfo.field_type (1)) <= cinfo->xlen)) | |
1822 | { | |
1823 | int len0, len1, offset; | |
1824 | ||
1825 | gdb_assert (TYPE_LENGTH (ainfo->type) | |
1826 | <= (cinfo->flen + cinfo->xlen)); | |
1827 | ||
1828 | len0 = TYPE_LENGTH (sinfo.field_type (0)); | |
1829 | if (!riscv_assign_reg_location (&ainfo->argloc[0], | |
1830 | &cinfo->float_regs, len0, 0)) | |
1831 | error (_("failed during argument setup")); | |
1832 | ||
1833 | len1 = TYPE_LENGTH (sinfo.field_type (1)); | |
1834 | offset = align_up (len0, riscv_type_alignment (sinfo.field_type (1))); | |
1835 | gdb_assert (len1 <= cinfo->xlen); | |
1836 | if (!riscv_assign_reg_location (&ainfo->argloc[1], | |
1837 | &cinfo->int_regs, len1, offset)) | |
1838 | error (_("failed during argument setup")); | |
1839 | return; | |
1840 | } | |
1841 | ||
1842 | if (sinfo.number_of_fields () == 2 | |
1843 | && riscv_arg_regs_available (&cinfo->int_regs) >= 1 | |
1844 | && (is_integral_type (sinfo.field_type (0)) | |
1845 | && TYPE_LENGTH (sinfo.field_type (0)) <= cinfo->xlen | |
1846 | && TYPE_CODE (sinfo.field_type (1)) == TYPE_CODE_FLT | |
1847 | && TYPE_LENGTH (sinfo.field_type (1)) <= cinfo->flen)) | |
1848 | { | |
1849 | int len0, len1, offset; | |
1850 | ||
1851 | gdb_assert (TYPE_LENGTH (ainfo->type) | |
1852 | <= (cinfo->flen + cinfo->xlen)); | |
1853 | ||
1854 | len0 = TYPE_LENGTH (sinfo.field_type (0)); | |
1855 | len1 = TYPE_LENGTH (sinfo.field_type (1)); | |
1856 | offset = align_up (len0, riscv_type_alignment (sinfo.field_type (1))); | |
1857 | ||
1858 | gdb_assert (len0 <= cinfo->xlen); | |
1859 | gdb_assert (len1 <= cinfo->flen); | |
1860 | ||
1861 | if (!riscv_assign_reg_location (&ainfo->argloc[0], | |
1862 | &cinfo->int_regs, len0, 0)) | |
1863 | error (_("failed during argument setup")); | |
1864 | ||
1865 | if (!riscv_assign_reg_location (&ainfo->argloc[1], | |
1866 | &cinfo->float_regs, | |
1867 | len1, offset)) | |
1868 | error (_("failed during argument setup")); | |
1869 | ||
1870 | return; | |
1871 | } | |
1872 | } | |
1873 | ||
1874 | /* Non of the structure flattening cases apply, so we just pass using | |
1875 | the integer ABI. */ | |
1876 | ainfo->length = align_up (ainfo->length, cinfo->xlen); | |
1877 | riscv_call_arg_scalar_int (ainfo, cinfo); | |
1878 | } | |
1879 | ||
1880 | /* Assign a location to call (or return) argument AINFO, the location is | |
1881 | selected from CINFO which holds information about what call argument | |
1882 | locations are available for use next. The TYPE is the type of the | |
1883 | argument being passed, this information is recorded into AINFO (along | |
1884 | with some additional information derived from the type). | |
1885 | ||
1886 | After assigning a location to AINFO, CINFO will have been updated. */ | |
1887 | ||
1888 | static void | |
1889 | riscv_arg_location (struct gdbarch *gdbarch, | |
1890 | struct riscv_arg_info *ainfo, | |
1891 | struct riscv_call_info *cinfo, | |
1892 | struct type *type) | |
1893 | { | |
1894 | ainfo->type = type; | |
1895 | ainfo->length = TYPE_LENGTH (ainfo->type); | |
1896 | ainfo->align = riscv_type_alignment (ainfo->type); | |
1897 | ainfo->contents = nullptr; | |
1898 | ||
1899 | switch (TYPE_CODE (ainfo->type)) | |
1900 | { | |
1901 | case TYPE_CODE_INT: | |
1902 | case TYPE_CODE_BOOL: | |
1903 | case TYPE_CODE_CHAR: | |
1904 | case TYPE_CODE_RANGE: | |
1905 | case TYPE_CODE_ENUM: | |
1906 | case TYPE_CODE_PTR: | |
1907 | if (ainfo->length <= cinfo->xlen) | |
1908 | { | |
1909 | ainfo->type = builtin_type (gdbarch)->builtin_long; | |
1910 | ainfo->length = cinfo->xlen; | |
1911 | } | |
1912 | else if (ainfo->length <= (2 * cinfo->xlen)) | |
1913 | { | |
1914 | ainfo->type = builtin_type (gdbarch)->builtin_long_long; | |
1915 | ainfo->length = 2 * cinfo->xlen; | |
1916 | } | |
1917 | ||
1918 | /* Recalculate the alignment requirement. */ | |
1919 | ainfo->align = riscv_type_alignment (ainfo->type); | |
1920 | riscv_call_arg_scalar_int (ainfo, cinfo); | |
1921 | break; | |
1922 | ||
1923 | case TYPE_CODE_FLT: | |
1924 | riscv_call_arg_scalar_float (ainfo, cinfo); | |
1925 | break; | |
1926 | ||
1927 | case TYPE_CODE_COMPLEX: | |
1928 | riscv_call_arg_complex_float (ainfo, cinfo); | |
1929 | break; | |
1930 | ||
1931 | case TYPE_CODE_STRUCT: | |
1932 | riscv_call_arg_struct (ainfo, cinfo); | |
1933 | break; | |
1934 | ||
1935 | default: | |
1936 | riscv_call_arg_scalar_int (ainfo, cinfo); | |
1937 | break; | |
1938 | } | |
1939 | } | |
1940 | ||
cab5bb9d AB |
1941 | /* Used for printing debug information about the call argument location in |
1942 | INFO to STREAM. The addresses in SP_REFS and SP_ARGS are the base | |
1943 | addresses for the location of pass-by-reference and | |
1944 | arguments-on-the-stack memory areas. */ | |
1945 | ||
dbbb1059 | 1946 | static void |
cab5bb9d | 1947 | riscv_print_arg_location (ui_file *stream, struct gdbarch *gdbarch, |
dbbb1059 AB |
1948 | struct riscv_arg_info *info, |
1949 | CORE_ADDR sp_refs, CORE_ADDR sp_args) | |
1950 | { | |
cab5bb9d | 1951 | fprintf_unfiltered (stream, "type: '%s', length: 0x%x, alignment: 0x%x", |
42ecac17 | 1952 | TYPE_SAFE_NAME (info->type), info->length, info->align); |
dbbb1059 AB |
1953 | switch (info->argloc[0].loc_type) |
1954 | { | |
1955 | case riscv_arg_info::location::in_reg: | |
cab5bb9d AB |
1956 | fprintf_unfiltered |
1957 | (stream, ", register %s", | |
1958 | gdbarch_register_name (gdbarch, info->argloc[0].loc_data.regno)); | |
dbbb1059 AB |
1959 | if (info->argloc[0].c_length < info->length) |
1960 | { | |
1961 | switch (info->argloc[1].loc_type) | |
1962 | { | |
1963 | case riscv_arg_info::location::in_reg: | |
cab5bb9d AB |
1964 | fprintf_unfiltered |
1965 | (stream, ", register %s", | |
1966 | gdbarch_register_name (gdbarch, | |
1967 | info->argloc[1].loc_data.regno)); | |
dbbb1059 AB |
1968 | break; |
1969 | ||
1970 | case riscv_arg_info::location::on_stack: | |
cab5bb9d AB |
1971 | fprintf_unfiltered (stream, ", on stack at offset 0x%x", |
1972 | info->argloc[1].loc_data.offset); | |
dbbb1059 AB |
1973 | break; |
1974 | ||
1975 | case riscv_arg_info::location::by_ref: | |
1976 | default: | |
1977 | /* The second location should never be a reference, any | |
1978 | argument being passed by reference just places its address | |
1979 | in the first location and is done. */ | |
1980 | error (_("invalid argument location")); | |
1981 | break; | |
1982 | } | |
1983 | ||
1984 | if (info->argloc[1].c_offset > info->argloc[0].c_length) | |
cab5bb9d AB |
1985 | fprintf_unfiltered (stream, " (offset 0x%x)", |
1986 | info->argloc[1].c_offset); | |
dbbb1059 AB |
1987 | } |
1988 | break; | |
1989 | ||
1990 | case riscv_arg_info::location::on_stack: | |
cab5bb9d AB |
1991 | fprintf_unfiltered (stream, ", on stack at offset 0x%x", |
1992 | info->argloc[0].loc_data.offset); | |
dbbb1059 AB |
1993 | break; |
1994 | ||
1995 | case riscv_arg_info::location::by_ref: | |
cab5bb9d AB |
1996 | fprintf_unfiltered |
1997 | (stream, ", by reference, data at offset 0x%x (%s)", | |
1998 | info->argloc[0].loc_data.offset, | |
1999 | core_addr_to_string (sp_refs + info->argloc[0].loc_data.offset)); | |
dbbb1059 AB |
2000 | if (info->argloc[1].loc_type |
2001 | == riscv_arg_info::location::in_reg) | |
cab5bb9d AB |
2002 | fprintf_unfiltered |
2003 | (stream, ", address in register %s", | |
2004 | gdbarch_register_name (gdbarch, info->argloc[1].loc_data.regno)); | |
dbbb1059 AB |
2005 | else |
2006 | { | |
2007 | gdb_assert (info->argloc[1].loc_type | |
2008 | == riscv_arg_info::location::on_stack); | |
cab5bb9d AB |
2009 | fprintf_unfiltered |
2010 | (stream, ", address on stack at offset 0x%x (%s)", | |
2011 | info->argloc[1].loc_data.offset, | |
2012 | core_addr_to_string (sp_args + info->argloc[1].loc_data.offset)); | |
dbbb1059 AB |
2013 | } |
2014 | break; | |
2015 | ||
2016 | default: | |
89a3b63e | 2017 | gdb_assert_not_reached (_("unknown argument location type")); |
dbbb1059 AB |
2018 | } |
2019 | } | |
2020 | ||
2021 | /* Implement the push dummy call gdbarch callback. */ | |
2022 | ||
2023 | static CORE_ADDR | |
2024 | riscv_push_dummy_call (struct gdbarch *gdbarch, | |
2025 | struct value *function, | |
2026 | struct regcache *regcache, | |
2027 | CORE_ADDR bp_addr, | |
2028 | int nargs, | |
2029 | struct value **args, | |
2030 | CORE_ADDR sp, | |
2031 | int struct_return, | |
2032 | CORE_ADDR struct_addr) | |
2033 | { | |
2034 | int i; | |
2035 | CORE_ADDR sp_args, sp_refs; | |
2036 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
2037 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
2038 | ||
2039 | struct riscv_arg_info *arg_info = | |
2040 | (struct riscv_arg_info *) alloca (nargs * sizeof (struct riscv_arg_info)); | |
2041 | struct riscv_arg_info *info; | |
2042 | ||
2043 | struct riscv_call_info call_info (gdbarch); | |
2044 | ||
2045 | CORE_ADDR osp = sp; | |
2046 | ||
2047 | /* We'll use register $a0 if we're returning a struct. */ | |
2048 | if (struct_return) | |
2049 | ++call_info.int_regs.next_regnum; | |
2050 | ||
2051 | for (i = 0, info = &arg_info[0]; | |
2052 | i < nargs; | |
2053 | ++i, ++info) | |
2054 | { | |
2055 | struct value *arg_value; | |
2056 | struct type *arg_type; | |
2057 | ||
2058 | arg_value = args[i]; | |
2059 | arg_type = check_typedef (value_type (arg_value)); | |
2060 | ||
2061 | riscv_arg_location (gdbarch, info, &call_info, arg_type); | |
2062 | ||
2063 | if (info->type != arg_type) | |
2064 | arg_value = value_cast (info->type, arg_value); | |
2065 | info->contents = value_contents (arg_value); | |
2066 | } | |
2067 | ||
2068 | /* Adjust the stack pointer and align it. */ | |
2069 | sp = sp_refs = align_down (sp - call_info.memory.ref_offset, SP_ALIGNMENT); | |
2070 | sp = sp_args = align_down (sp - call_info.memory.arg_offset, SP_ALIGNMENT); | |
2071 | ||
2072 | if (riscv_debug_infcall > 0) | |
2073 | { | |
2074 | fprintf_unfiltered (gdb_stdlog, "dummy call args:\n"); | |
2075 | fprintf_unfiltered (gdb_stdlog, ": floating point ABI %s in use\n", | |
2076 | (riscv_has_fp_abi (gdbarch) ? "is" : "is not")); | |
2077 | fprintf_unfiltered (gdb_stdlog, ": xlen: %d\n: flen: %d\n", | |
2078 | call_info.xlen, call_info.flen); | |
2079 | if (struct_return) | |
2080 | fprintf_unfiltered (gdb_stdlog, | |
2081 | "[*] struct return pointer in register $A0\n"); | |
2082 | for (i = 0; i < nargs; ++i) | |
2083 | { | |
2084 | struct riscv_arg_info *info = &arg_info [i]; | |
2085 | ||
2086 | fprintf_unfiltered (gdb_stdlog, "[%2d] ", i); | |
cab5bb9d | 2087 | riscv_print_arg_location (gdb_stdlog, gdbarch, info, sp_refs, sp_args); |
dbbb1059 AB |
2088 | fprintf_unfiltered (gdb_stdlog, "\n"); |
2089 | } | |
2090 | if (call_info.memory.arg_offset > 0 | |
2091 | || call_info.memory.ref_offset > 0) | |
2092 | { | |
cab5bb9d AB |
2093 | fprintf_unfiltered (gdb_stdlog, " Original sp: %s\n", |
2094 | core_addr_to_string (osp)); | |
dbbb1059 | 2095 | fprintf_unfiltered (gdb_stdlog, "Stack required (for args): 0x%x\n", |
cab5bb9d | 2096 | call_info.memory.arg_offset); |
dbbb1059 | 2097 | fprintf_unfiltered (gdb_stdlog, "Stack required (for refs): 0x%x\n", |
cab5bb9d | 2098 | call_info.memory.ref_offset); |
fb294655 AB |
2099 | fprintf_unfiltered (gdb_stdlog, " Stack allocated: %s\n", |
2100 | core_addr_to_string_nz (osp - sp)); | |
dbbb1059 AB |
2101 | } |
2102 | } | |
2103 | ||
2104 | /* Now load the argument into registers, or onto the stack. */ | |
2105 | ||
2106 | if (struct_return) | |
2107 | { | |
2108 | gdb_byte buf[sizeof (LONGEST)]; | |
2109 | ||
2110 | store_unsigned_integer (buf, call_info.xlen, byte_order, struct_addr); | |
b66f5587 | 2111 | regcache->cooked_write (RISCV_A0_REGNUM, buf); |
dbbb1059 AB |
2112 | } |
2113 | ||
2114 | for (i = 0; i < nargs; ++i) | |
2115 | { | |
2116 | CORE_ADDR dst; | |
2117 | int second_arg_length = 0; | |
2118 | const gdb_byte *second_arg_data; | |
2119 | struct riscv_arg_info *info = &arg_info [i]; | |
2120 | ||
2121 | gdb_assert (info->length > 0); | |
2122 | ||
2123 | switch (info->argloc[0].loc_type) | |
2124 | { | |
2125 | case riscv_arg_info::location::in_reg: | |
2126 | { | |
2127 | gdb_byte tmp [sizeof (ULONGEST)]; | |
2128 | ||
2129 | gdb_assert (info->argloc[0].c_length <= info->length); | |
2130 | memset (tmp, 0, sizeof (tmp)); | |
2131 | memcpy (tmp, info->contents, info->argloc[0].c_length); | |
b66f5587 | 2132 | regcache->cooked_write (info->argloc[0].loc_data.regno, tmp); |
dbbb1059 AB |
2133 | second_arg_length = |
2134 | ((info->argloc[0].c_length < info->length) | |
2135 | ? info->argloc[1].c_length : 0); | |
2136 | second_arg_data = info->contents + info->argloc[1].c_offset; | |
2137 | } | |
2138 | break; | |
2139 | ||
2140 | case riscv_arg_info::location::on_stack: | |
2141 | dst = sp_args + info->argloc[0].loc_data.offset; | |
2142 | write_memory (dst, info->contents, info->length); | |
2143 | second_arg_length = 0; | |
2144 | break; | |
2145 | ||
2146 | case riscv_arg_info::location::by_ref: | |
2147 | dst = sp_refs + info->argloc[0].loc_data.offset; | |
2148 | write_memory (dst, info->contents, info->length); | |
2149 | ||
2150 | second_arg_length = call_info.xlen; | |
2151 | second_arg_data = (gdb_byte *) &dst; | |
2152 | break; | |
2153 | ||
2154 | default: | |
89a3b63e | 2155 | gdb_assert_not_reached (_("unknown argument location type")); |
dbbb1059 AB |
2156 | } |
2157 | ||
2158 | if (second_arg_length > 0) | |
2159 | { | |
2160 | switch (info->argloc[1].loc_type) | |
2161 | { | |
2162 | case riscv_arg_info::location::in_reg: | |
2163 | { | |
2164 | gdb_byte tmp [sizeof (ULONGEST)]; | |
2165 | ||
8c49aa89 AB |
2166 | gdb_assert ((riscv_is_fp_regno_p (info->argloc[1].loc_data.regno) |
2167 | && second_arg_length <= call_info.flen) | |
2168 | || second_arg_length <= call_info.xlen); | |
dbbb1059 AB |
2169 | memset (tmp, 0, sizeof (tmp)); |
2170 | memcpy (tmp, second_arg_data, second_arg_length); | |
b66f5587 | 2171 | regcache->cooked_write (info->argloc[1].loc_data.regno, tmp); |
dbbb1059 AB |
2172 | } |
2173 | break; | |
2174 | ||
2175 | case riscv_arg_info::location::on_stack: | |
2176 | { | |
2177 | CORE_ADDR arg_addr; | |
2178 | ||
2179 | arg_addr = sp_args + info->argloc[1].loc_data.offset; | |
2180 | write_memory (arg_addr, second_arg_data, second_arg_length); | |
2181 | break; | |
2182 | } | |
2183 | ||
2184 | case riscv_arg_info::location::by_ref: | |
2185 | default: | |
2186 | /* The second location should never be a reference, any | |
2187 | argument being passed by reference just places its address | |
2188 | in the first location and is done. */ | |
2189 | error (_("invalid argument location")); | |
2190 | break; | |
2191 | } | |
2192 | } | |
2193 | } | |
2194 | ||
2195 | /* Set the dummy return value to bp_addr. | |
2196 | A dummy breakpoint will be setup to execute the call. */ | |
2197 | ||
2198 | if (riscv_debug_infcall > 0) | |
cab5bb9d AB |
2199 | fprintf_unfiltered (gdb_stdlog, ": writing $ra = %s\n", |
2200 | core_addr_to_string (bp_addr)); | |
dbbb1059 AB |
2201 | regcache_cooked_write_unsigned (regcache, RISCV_RA_REGNUM, bp_addr); |
2202 | ||
2203 | /* Finally, update the stack pointer. */ | |
2204 | ||
2205 | if (riscv_debug_infcall > 0) | |
cab5bb9d AB |
2206 | fprintf_unfiltered (gdb_stdlog, ": writing $sp = %s\n", |
2207 | core_addr_to_string (sp)); | |
dbbb1059 AB |
2208 | regcache_cooked_write_unsigned (regcache, RISCV_SP_REGNUM, sp); |
2209 | ||
2210 | return sp; | |
2211 | } | |
2212 | ||
2213 | /* Implement the return_value gdbarch method. */ | |
2214 | ||
2215 | static enum return_value_convention | |
2216 | riscv_return_value (struct gdbarch *gdbarch, | |
2217 | struct value *function, | |
2218 | struct type *type, | |
2219 | struct regcache *regcache, | |
2220 | gdb_byte *readbuf, | |
2221 | const gdb_byte *writebuf) | |
2222 | { | |
2223 | enum type_code rv_type = TYPE_CODE (type); | |
2224 | unsigned int rv_size = TYPE_LENGTH (type); | |
2225 | int fp, regnum, flen; | |
2226 | ULONGEST tmp; | |
2227 | struct riscv_call_info call_info (gdbarch); | |
2228 | struct riscv_arg_info info; | |
2229 | struct type *arg_type; | |
2230 | ||
2231 | arg_type = check_typedef (type); | |
2232 | riscv_arg_location (gdbarch, &info, &call_info, arg_type); | |
2233 | ||
2234 | if (riscv_debug_infcall > 0) | |
2235 | { | |
2236 | fprintf_unfiltered (gdb_stdlog, "riscv return value:\n"); | |
2237 | fprintf_unfiltered (gdb_stdlog, "[R] "); | |
cab5bb9d | 2238 | riscv_print_arg_location (gdb_stdlog, gdbarch, &info, 0, 0); |
dbbb1059 AB |
2239 | fprintf_unfiltered (gdb_stdlog, "\n"); |
2240 | } | |
2241 | ||
2242 | if (readbuf != nullptr || writebuf != nullptr) | |
2243 | { | |
2244 | int regnum; | |
2245 | ||
2246 | switch (info.argloc[0].loc_type) | |
2247 | { | |
2248 | /* Return value in register(s). */ | |
2249 | case riscv_arg_info::location::in_reg: | |
2250 | { | |
2251 | regnum = info.argloc[0].loc_data.regno; | |
2252 | ||
2253 | if (readbuf) | |
dca08e1f | 2254 | regcache->cooked_read (regnum, readbuf); |
dbbb1059 AB |
2255 | |
2256 | if (writebuf) | |
b66f5587 | 2257 | regcache->cooked_write (regnum, writebuf); |
dbbb1059 AB |
2258 | |
2259 | /* A return value in register can have a second part in a | |
2260 | second register. */ | |
2261 | if (info.argloc[0].c_length < info.length) | |
2262 | { | |
2263 | switch (info.argloc[1].loc_type) | |
2264 | { | |
2265 | case riscv_arg_info::location::in_reg: | |
2266 | regnum = info.argloc[1].loc_data.regno; | |
2267 | ||
2268 | if (readbuf) | |
2269 | { | |
2270 | readbuf += info.argloc[1].c_offset; | |
dca08e1f | 2271 | regcache->cooked_read (regnum, readbuf); |
dbbb1059 AB |
2272 | } |
2273 | ||
2274 | if (writebuf) | |
2275 | { | |
2276 | writebuf += info.argloc[1].c_offset; | |
b66f5587 | 2277 | regcache->cooked_write (regnum, writebuf); |
dbbb1059 AB |
2278 | } |
2279 | break; | |
2280 | ||
2281 | case riscv_arg_info::location::by_ref: | |
2282 | case riscv_arg_info::location::on_stack: | |
2283 | default: | |
2284 | error (_("invalid argument location")); | |
2285 | break; | |
2286 | } | |
2287 | } | |
2288 | } | |
2289 | break; | |
2290 | ||
2291 | /* Return value by reference will have its address in A0. */ | |
2292 | case riscv_arg_info::location::by_ref: | |
2293 | { | |
b2970c23 | 2294 | ULONGEST addr; |
dbbb1059 AB |
2295 | |
2296 | regcache_cooked_read_unsigned (regcache, RISCV_A0_REGNUM, | |
2297 | &addr); | |
2298 | if (readbuf != nullptr) | |
2299 | read_memory (addr, readbuf, info.length); | |
2300 | if (writebuf != nullptr) | |
2301 | write_memory (addr, writebuf, info.length); | |
2302 | } | |
2303 | break; | |
2304 | ||
2305 | case riscv_arg_info::location::on_stack: | |
2306 | default: | |
2307 | error (_("invalid argument location")); | |
2308 | break; | |
2309 | } | |
2310 | } | |
2311 | ||
2312 | switch (info.argloc[0].loc_type) | |
2313 | { | |
2314 | case riscv_arg_info::location::in_reg: | |
2315 | return RETURN_VALUE_REGISTER_CONVENTION; | |
2316 | case riscv_arg_info::location::by_ref: | |
2317 | return RETURN_VALUE_ABI_RETURNS_ADDRESS; | |
2318 | case riscv_arg_info::location::on_stack: | |
2319 | default: | |
2320 | error (_("invalid argument location")); | |
2321 | } | |
2322 | } | |
2323 | ||
2324 | /* Implement the frame_align gdbarch method. */ | |
2325 | ||
2326 | static CORE_ADDR | |
2327 | riscv_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) | |
2328 | { | |
2329 | return align_down (addr, 16); | |
2330 | } | |
2331 | ||
2332 | /* Implement the unwind_pc gdbarch method. */ | |
2333 | ||
2334 | static CORE_ADDR | |
2335 | riscv_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
2336 | { | |
2337 | return frame_unwind_register_unsigned (next_frame, RISCV_PC_REGNUM); | |
2338 | } | |
2339 | ||
2340 | /* Implement the unwind_sp gdbarch method. */ | |
2341 | ||
2342 | static CORE_ADDR | |
2343 | riscv_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
2344 | { | |
2345 | return frame_unwind_register_unsigned (next_frame, RISCV_SP_REGNUM); | |
2346 | } | |
2347 | ||
2348 | /* Implement the dummy_id gdbarch method. */ | |
2349 | ||
2350 | static struct frame_id | |
2351 | riscv_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame) | |
2352 | { | |
2353 | return frame_id_build (get_frame_register_signed (this_frame, RISCV_SP_REGNUM), | |
2354 | get_frame_pc (this_frame)); | |
2355 | } | |
2356 | ||
2357 | /* Generate, or return the cached frame cache for the RiscV frame | |
2358 | unwinder. */ | |
2359 | ||
2360 | static struct trad_frame_cache * | |
2361 | riscv_frame_cache (struct frame_info *this_frame, void **this_cache) | |
2362 | { | |
2363 | CORE_ADDR pc; | |
2364 | CORE_ADDR start_addr; | |
2365 | CORE_ADDR stack_addr; | |
2366 | struct trad_frame_cache *this_trad_cache; | |
2367 | struct gdbarch *gdbarch = get_frame_arch (this_frame); | |
2368 | ||
2369 | if ((*this_cache) != NULL) | |
2370 | return (struct trad_frame_cache *) *this_cache; | |
2371 | this_trad_cache = trad_frame_cache_zalloc (this_frame); | |
2372 | (*this_cache) = this_trad_cache; | |
2373 | ||
2374 | trad_frame_set_reg_realreg (this_trad_cache, gdbarch_pc_regnum (gdbarch), | |
2375 | RISCV_RA_REGNUM); | |
2376 | ||
2377 | pc = get_frame_pc (this_frame); | |
2378 | find_pc_partial_function (pc, NULL, &start_addr, NULL); | |
2379 | stack_addr = get_frame_register_signed (this_frame, RISCV_SP_REGNUM); | |
2380 | trad_frame_set_id (this_trad_cache, frame_id_build (stack_addr, start_addr)); | |
2381 | ||
2382 | trad_frame_set_this_base (this_trad_cache, stack_addr); | |
2383 | ||
2384 | return this_trad_cache; | |
2385 | } | |
2386 | ||
2387 | /* Implement the this_id callback for RiscV frame unwinder. */ | |
2388 | ||
2389 | static void | |
2390 | riscv_frame_this_id (struct frame_info *this_frame, | |
2391 | void **prologue_cache, | |
2392 | struct frame_id *this_id) | |
2393 | { | |
2394 | struct trad_frame_cache *info; | |
2395 | ||
2396 | info = riscv_frame_cache (this_frame, prologue_cache); | |
2397 | trad_frame_get_id (info, this_id); | |
2398 | } | |
2399 | ||
2400 | /* Implement the prev_register callback for RiscV frame unwinder. */ | |
2401 | ||
2402 | static struct value * | |
2403 | riscv_frame_prev_register (struct frame_info *this_frame, | |
2404 | void **prologue_cache, | |
2405 | int regnum) | |
2406 | { | |
2407 | struct trad_frame_cache *info; | |
2408 | ||
2409 | info = riscv_frame_cache (this_frame, prologue_cache); | |
2410 | return trad_frame_get_register (info, this_frame, regnum); | |
2411 | } | |
2412 | ||
2413 | /* Structure defining the RiscV normal frame unwind functions. Since we | |
2414 | are the fallback unwinder (DWARF unwinder is used first), we use the | |
2415 | default frame sniffer, which always accepts the frame. */ | |
2416 | ||
2417 | static const struct frame_unwind riscv_frame_unwind = | |
2418 | { | |
2419 | /*.type =*/ NORMAL_FRAME, | |
2420 | /*.stop_reason =*/ default_frame_unwind_stop_reason, | |
2421 | /*.this_id =*/ riscv_frame_this_id, | |
2422 | /*.prev_register =*/ riscv_frame_prev_register, | |
2423 | /*.unwind_data =*/ NULL, | |
2424 | /*.sniffer =*/ default_frame_sniffer, | |
2425 | /*.dealloc_cache =*/ NULL, | |
2426 | /*.prev_arch =*/ NULL, | |
2427 | }; | |
2428 | ||
2429 | /* Initialize the current architecture based on INFO. If possible, | |
2430 | re-use an architecture from ARCHES, which is a list of | |
2431 | architectures already created during this debugging session. | |
2432 | ||
2433 | Called e.g. at program startup, when reading a core file, and when | |
2434 | reading a binary file. */ | |
2435 | ||
2436 | static struct gdbarch * | |
2437 | riscv_gdbarch_init (struct gdbarch_info info, | |
2438 | struct gdbarch_list *arches) | |
2439 | { | |
2440 | struct gdbarch *gdbarch; | |
2441 | struct gdbarch_tdep *tdep; | |
2442 | struct gdbarch_tdep tmp_tdep; | |
2443 | bool has_compressed_isa = false; | |
2444 | int i; | |
2445 | ||
2446 | /* Ideally, we'd like to get as much information from the target for | |
2447 | things like register size, and whether the target has floating point | |
2448 | hardware. However, there are some things that the target can't tell | |
2449 | us, like, what ABI is being used. | |
2450 | ||
2451 | So, for now, we take as much information as possible from the ELF, | |
2452 | including things like register size, and FP hardware support, along | |
2453 | with information about the ABI. | |
2454 | ||
2455 | Information about this target is built up in TMP_TDEP, and then we | |
2456 | look for an existing gdbarch in ARCHES that matches TMP_TDEP. If no | |
2457 | match is found we'll create a new gdbarch and copy TMP_TDEP over. */ | |
2458 | memset (&tmp_tdep, 0, sizeof (tmp_tdep)); | |
2459 | ||
2460 | if (info.abfd != NULL | |
2461 | && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour) | |
2462 | { | |
2463 | unsigned char eclass = elf_elfheader (info.abfd)->e_ident[EI_CLASS]; | |
2464 | int e_flags = elf_elfheader (info.abfd)->e_flags; | |
2465 | ||
2466 | if (eclass == ELFCLASS32) | |
2467 | tmp_tdep.abi.fields.base_len = 1; | |
2468 | else if (eclass == ELFCLASS64) | |
2469 | tmp_tdep.abi.fields.base_len = 2; | |
2470 | else | |
2471 | internal_error (__FILE__, __LINE__, | |
2472 | _("unknown ELF header class %d"), eclass); | |
2473 | ||
2474 | if (e_flags & EF_RISCV_RVC) | |
2475 | { | |
2476 | has_compressed_isa = true; | |
2477 | tmp_tdep.core_features |= (1 << ('C' - 'A')); | |
2478 | } | |
2479 | ||
2480 | if (e_flags & EF_RISCV_FLOAT_ABI_DOUBLE) | |
2481 | { | |
2482 | tmp_tdep.abi.fields.float_abi = 2; | |
2483 | tmp_tdep.core_features |= (1 << ('D' - 'A')); | |
2484 | tmp_tdep.core_features |= (1 << ('F' - 'A')); | |
2485 | } | |
2486 | else if (e_flags & EF_RISCV_FLOAT_ABI_SINGLE) | |
2487 | { | |
2488 | tmp_tdep.abi.fields.float_abi = 1; | |
2489 | tmp_tdep.core_features |= (1 << ('F' - 'A')); | |
2490 | } | |
2491 | } | |
2492 | else | |
2493 | { | |
2494 | const struct bfd_arch_info *binfo = info.bfd_arch_info; | |
2495 | ||
2496 | if (binfo->bits_per_word == 32) | |
2497 | tmp_tdep.abi.fields.base_len = 1; | |
2498 | else if (binfo->bits_per_word == 64) | |
2499 | tmp_tdep.abi.fields.base_len = 2; | |
2500 | else | |
2501 | internal_error (__FILE__, __LINE__, _("unknown bits_per_word %d"), | |
2502 | binfo->bits_per_word); | |
2503 | } | |
2504 | ||
2505 | /* Find a candidate among the list of pre-declared architectures. */ | |
2506 | for (arches = gdbarch_list_lookup_by_info (arches, &info); | |
2507 | arches != NULL; | |
2508 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) | |
2509 | if (gdbarch_tdep (arches->gdbarch)->abi.value == tmp_tdep.abi.value) | |
2510 | return arches->gdbarch; | |
2511 | ||
2512 | /* None found, so create a new architecture from the information provided. */ | |
2513 | tdep = (struct gdbarch_tdep *) xmalloc (sizeof *tdep); | |
2514 | gdbarch = gdbarch_alloc (&info, tdep); | |
2515 | memcpy (tdep, &tmp_tdep, sizeof (tmp_tdep)); | |
2516 | ||
2517 | /* Target data types. */ | |
2518 | set_gdbarch_short_bit (gdbarch, 16); | |
2519 | set_gdbarch_int_bit (gdbarch, 32); | |
2520 | set_gdbarch_long_bit (gdbarch, riscv_isa_xlen (gdbarch) * 8); | |
2521 | set_gdbarch_long_long_bit (gdbarch, 64); | |
2522 | set_gdbarch_float_bit (gdbarch, 32); | |
2523 | set_gdbarch_double_bit (gdbarch, 64); | |
2524 | set_gdbarch_long_double_bit (gdbarch, 128); | |
2525 | set_gdbarch_long_double_format (gdbarch, floatformats_ia64_quad); | |
2526 | set_gdbarch_ptr_bit (gdbarch, riscv_isa_xlen (gdbarch) * 8); | |
2527 | set_gdbarch_char_signed (gdbarch, 0); | |
2528 | ||
2529 | /* Information about the target architecture. */ | |
2530 | set_gdbarch_return_value (gdbarch, riscv_return_value); | |
2531 | set_gdbarch_breakpoint_kind_from_pc (gdbarch, riscv_breakpoint_kind_from_pc); | |
2532 | set_gdbarch_sw_breakpoint_from_kind (gdbarch, riscv_sw_breakpoint_from_kind); | |
2533 | ||
2534 | /* Register architecture. */ | |
dbbb1059 | 2535 | set_gdbarch_num_regs (gdbarch, RISCV_LAST_REGNUM + 1); |
dbbb1059 AB |
2536 | set_gdbarch_sp_regnum (gdbarch, RISCV_SP_REGNUM); |
2537 | set_gdbarch_pc_regnum (gdbarch, RISCV_PC_REGNUM); | |
2538 | set_gdbarch_ps_regnum (gdbarch, RISCV_FP_REGNUM); | |
2539 | set_gdbarch_deprecated_fp_regnum (gdbarch, RISCV_FP_REGNUM); | |
2540 | ||
2541 | /* Functions to supply register information. */ | |
2542 | set_gdbarch_register_name (gdbarch, riscv_register_name); | |
2543 | set_gdbarch_register_type (gdbarch, riscv_register_type); | |
2544 | set_gdbarch_print_registers_info (gdbarch, riscv_print_registers_info); | |
2545 | set_gdbarch_register_reggroup_p (gdbarch, riscv_register_reggroup_p); | |
2546 | ||
2547 | /* Functions to analyze frames. */ | |
2548 | set_gdbarch_decr_pc_after_break (gdbarch, (has_compressed_isa ? 2 : 4)); | |
2549 | set_gdbarch_skip_prologue (gdbarch, riscv_skip_prologue); | |
2550 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
2551 | set_gdbarch_frame_align (gdbarch, riscv_frame_align); | |
2552 | ||
2553 | /* Functions to access frame data. */ | |
2554 | set_gdbarch_unwind_pc (gdbarch, riscv_unwind_pc); | |
2555 | set_gdbarch_unwind_sp (gdbarch, riscv_unwind_sp); | |
2556 | ||
2557 | /* Functions handling dummy frames. */ | |
2558 | set_gdbarch_call_dummy_location (gdbarch, ON_STACK); | |
2559 | set_gdbarch_push_dummy_code (gdbarch, riscv_push_dummy_code); | |
2560 | set_gdbarch_push_dummy_call (gdbarch, riscv_push_dummy_call); | |
2561 | set_gdbarch_dummy_id (gdbarch, riscv_dummy_id); | |
2562 | ||
2563 | /* Frame unwinders. Use DWARF debug info if available, otherwise use our own | |
2564 | unwinder. */ | |
2565 | dwarf2_append_unwinders (gdbarch); | |
2566 | frame_unwind_append_unwinder (gdbarch, &riscv_frame_unwind); | |
2567 | ||
dbbb1059 AB |
2568 | for (i = 0; i < ARRAY_SIZE (riscv_register_aliases); ++i) |
2569 | user_reg_add (gdbarch, riscv_register_aliases[i].name, | |
2570 | value_of_riscv_user_reg, &riscv_register_aliases[i].regnum); | |
2571 | ||
2572 | return gdbarch; | |
2573 | } | |
2574 | ||
2575 | ||
2576 | /* Allocate new riscv_inferior_data object. */ | |
2577 | ||
2578 | static struct riscv_inferior_data * | |
2579 | riscv_new_inferior_data (void) | |
2580 | { | |
2581 | struct riscv_inferior_data *inf_data | |
2582 | = new (struct riscv_inferior_data); | |
2583 | inf_data->misa_read = false; | |
2584 | return inf_data; | |
2585 | } | |
2586 | ||
2587 | /* Free inferior data. */ | |
2588 | ||
2589 | static void | |
2590 | riscv_inferior_data_cleanup (struct inferior *inf, void *data) | |
2591 | { | |
2592 | struct riscv_inferior_data *inf_data = | |
2593 | static_cast <struct riscv_inferior_data *> (data); | |
2594 | delete (inf_data); | |
2595 | } | |
2596 | ||
2597 | /* Return riscv_inferior_data for the given INFERIOR. If not yet created, | |
2598 | construct it. */ | |
2599 | ||
2600 | struct riscv_inferior_data * | |
2601 | riscv_inferior_data (struct inferior *const inf) | |
2602 | { | |
2603 | struct riscv_inferior_data *inf_data; | |
2604 | ||
2605 | gdb_assert (inf != NULL); | |
2606 | ||
2607 | inf_data | |
2608 | = (struct riscv_inferior_data *) inferior_data (inf, riscv_inferior_data_reg); | |
2609 | if (inf_data == NULL) | |
2610 | { | |
2611 | inf_data = riscv_new_inferior_data (); | |
2612 | set_inferior_data (inf, riscv_inferior_data_reg, inf_data); | |
2613 | } | |
2614 | ||
2615 | return inf_data; | |
2616 | } | |
2617 | ||
2618 | /* Free the inferior data when an inferior exits. */ | |
2619 | ||
2620 | static void | |
2621 | riscv_invalidate_inferior_data (struct inferior *inf) | |
2622 | { | |
2623 | struct riscv_inferior_data *inf_data; | |
2624 | ||
2625 | gdb_assert (inf != NULL); | |
2626 | ||
2627 | /* Don't call RISCV_INFERIOR_DATA as we don't want to create the data if | |
2628 | we've not already created it by this point. */ | |
2629 | inf_data | |
2630 | = (struct riscv_inferior_data *) inferior_data (inf, riscv_inferior_data_reg); | |
2631 | if (inf_data != NULL) | |
2632 | { | |
2633 | delete (inf_data); | |
2634 | set_inferior_data (inf, riscv_inferior_data_reg, NULL); | |
2635 | } | |
2636 | } | |
2637 | ||
2638 | void | |
2639 | _initialize_riscv_tdep (void) | |
2640 | { | |
2641 | gdbarch_register (bfd_arch_riscv, riscv_gdbarch_init, NULL); | |
2642 | ||
2643 | /* Register per-inferior data. */ | |
2644 | riscv_inferior_data_reg | |
2645 | = register_inferior_data_with_cleanup (NULL, riscv_inferior_data_cleanup); | |
2646 | ||
2647 | /* Observers used to invalidate the inferior data when needed. */ | |
76727919 TT |
2648 | gdb::observers::inferior_exit.attach (riscv_invalidate_inferior_data); |
2649 | gdb::observers::inferior_appeared.attach (riscv_invalidate_inferior_data); | |
dbbb1059 AB |
2650 | |
2651 | /* Add root prefix command for all "set debug riscv" and "show debug | |
2652 | riscv" commands. */ | |
2653 | add_prefix_cmd ("riscv", no_class, set_debug_riscv_command, | |
2654 | _("RISC-V specific debug commands."), | |
2655 | &setdebugriscvcmdlist, "set debug riscv ", 0, | |
2656 | &setdebuglist); | |
2657 | ||
2658 | add_prefix_cmd ("riscv", no_class, show_debug_riscv_command, | |
2659 | _("RISC-V specific debug commands."), | |
2660 | &showdebugriscvcmdlist, "show debug riscv ", 0, | |
2661 | &showdebuglist); | |
2662 | ||
2663 | add_setshow_zuinteger_cmd ("infcall", class_maintenance, | |
2664 | &riscv_debug_infcall, _("\ | |
2665 | Set riscv inferior call debugging."), _("\ | |
2666 | Show riscv inferior call debugging."), _("\ | |
2667 | When non-zero, print debugging information for the riscv specific parts\n\ | |
2668 | of the inferior call mechanism."), | |
2669 | NULL, | |
2670 | show_riscv_debug_variable, | |
2671 | &setdebugriscvcmdlist, &showdebugriscvcmdlist); | |
2672 | ||
2673 | /* Add root prefix command for all "set riscv" and "show riscv" commands. */ | |
2674 | add_prefix_cmd ("riscv", no_class, set_riscv_command, | |
2675 | _("RISC-V specific commands."), | |
2676 | &setriscvcmdlist, "set riscv ", 0, &setlist); | |
2677 | ||
2678 | add_prefix_cmd ("riscv", no_class, show_riscv_command, | |
2679 | _("RISC-V specific commands."), | |
2680 | &showriscvcmdlist, "show riscv ", 0, &showlist); | |
2681 | ||
2682 | ||
2683 | use_compressed_breakpoints = AUTO_BOOLEAN_AUTO; | |
2684 | add_setshow_auto_boolean_cmd ("use-compressed-breakpoints", no_class, | |
2685 | &use_compressed_breakpoints, | |
2686 | _("\ | |
2687 | Set debugger's use of compressed breakpoints."), _(" \ | |
2688 | Show debugger's use of compressed breakpoints."), _("\ | |
2689 | Debugging compressed code requires compressed breakpoints to be used. If\n \ | |
2690 | left to 'auto' then gdb will use them if $misa indicates the C extension\n \ | |
2691 | is supported. If that doesn't give the correct behavior, then this option\n\ | |
2692 | can be used."), | |
2693 | NULL, | |
2694 | show_use_compressed_breakpoints, | |
2695 | &setriscvcmdlist, | |
2696 | &showriscvcmdlist); | |
2697 | } |