[sim] Run spellcheck.sh in sim (part 2)
[binutils-gdb.git] / gdb / arc-tdep.c
blob9adf2959cf31d1a5b9bac73baa5ac8f313533c61
1 /* Target dependent code for ARC architecture, for GDB.
3 Copyright 2005-2024 Free Software Foundation, Inc.
4 Contributed by Synopsys Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* GDB header files. */
22 #include "arch-utils.h"
23 #include "elf-bfd.h"
24 #include "disasm.h"
25 #include "dwarf2/frame.h"
26 #include "extract-store-integer.h"
27 #include "frame-base.h"
28 #include "frame-unwind.h"
29 #include "gdbcore.h"
30 #include "inferior.h"
31 #include "reggroups.h"
32 #include "cli/cli-cmds.h"
33 #include "objfiles.h"
34 #include "osabi.h"
35 #include "prologue-value.h"
36 #include "target-descriptions.h"
37 #include "trad-frame.h"
39 /* ARC header files. */
40 #include "opcode/arc.h"
41 #include "opcodes/arc-dis.h"
42 #include "arc-tdep.h"
43 #include "arch/arc.h"
45 /* Standard headers. */
46 #include <algorithm>
47 #include <sstream>
49 /* The frame unwind cache for ARC. */
51 struct arc_frame_cache
53 /* The stack pointer at the time this frame was created; i.e. the caller's
54 stack pointer when this function was called. It is used to identify this
55 frame. */
56 CORE_ADDR prev_sp;
58 /* Register that is a base for this frame - FP for normal frame, SP for
59 non-FP frames. */
60 int frame_base_reg;
62 /* Offset from the previous SP to the current frame base. If GCC uses
63 `SUB SP,SP,offset` to allocate space for local variables, then it will be
64 done after setting up a frame pointer, but it still will be considered
65 part of prologue, therefore SP will be lesser than FP at the end of the
66 prologue analysis. In this case that would be an offset from old SP to a
67 new FP. But in case of non-FP frames, frame base is an SP and thus that
68 would be an offset from old SP to new SP. What is important is that this
69 is an offset from old SP to a known register, so it can be used to find
70 old SP.
72 Using FP is preferable, when possible, because SP can change in function
73 body after prologue due to alloca, variadic arguments or other shenanigans.
74 If that is the case in the caller frame, then PREV_SP will point to SP at
75 the moment of function call, but it will be different from SP value at the
76 end of the caller prologue. As a result it will not be possible to
77 reconstruct caller's frame and go past it in the backtrace. Those things
78 are unlikely to happen to FP - FP value at the moment of function call (as
79 stored on stack in callee prologue) is also an FP value at the end of the
80 caller's prologue. */
82 LONGEST frame_base_offset;
84 /* Store addresses for registers saved in prologue. During prologue analysis
85 GDB stores offsets relatively to "old SP", then after old SP is evaluated,
86 offsets are replaced with absolute addresses. */
87 trad_frame_saved_reg *saved_regs;
90 /* Global debug flag. */
92 bool arc_debug;
94 /* List of "maintenance print arc" commands. */
96 static struct cmd_list_element *maintenance_print_arc_list = NULL;
98 /* A set of registers that we expect to find in a tdesc_feature. These
99 are used in ARC_TDESC_INIT when processing the target description. */
101 struct arc_register_feature
103 /* Information for a single register. */
104 struct register_info
106 /* The GDB register number for this register. */
107 int regnum;
109 /* List of names for this register. The first name in this list is the
110 preferred name, the name GDB will use when describing this register. */
111 std::vector<const char *> names;
113 /* When true, this register must be present in this feature set. */
114 bool required_p;
117 /* The name for this feature. This is the name used to find this feature
118 within the target description. */
119 const char *name;
121 /* List of all the registers that we expect to encounter in this register
122 set. */
123 std::vector<struct register_info> registers;
126 /* Obsolete feature names for backward compatibility. */
127 static const char *ARC_CORE_V1_OBSOLETE_FEATURE_NAME
128 = "org.gnu.gdb.arc.core.arcompact";
129 static const char *ARC_CORE_V2_OBSOLETE_FEATURE_NAME
130 = "org.gnu.gdb.arc.core.v2";
131 static const char *ARC_CORE_V2_REDUCED_OBSOLETE_FEATURE_NAME
132 = "org.gnu.gdb.arc.core-reduced.v2";
133 static const char *ARC_AUX_OBSOLETE_FEATURE_NAME
134 = "org.gnu.gdb.arc.aux-minimal";
135 /* Modern feature names. */
136 static const char *ARC_CORE_FEATURE_NAME = "org.gnu.gdb.arc.core";
137 static const char *ARC_AUX_FEATURE_NAME = "org.gnu.gdb.arc.aux";
139 /* ARCv1 (ARC600, ARC601, ARC700) general core registers feature set.
140 See also arc_update_acc_reg_names() for "accl/acch" names. */
142 static struct arc_register_feature arc_v1_core_reg_feature =
144 ARC_CORE_FEATURE_NAME,
146 { ARC_R0_REGNUM + 0, { "r0" }, true },
147 { ARC_R0_REGNUM + 1, { "r1" }, true },
148 { ARC_R0_REGNUM + 2, { "r2" }, true },
149 { ARC_R0_REGNUM + 3, { "r3" }, true },
150 { ARC_R0_REGNUM + 4, { "r4" }, false },
151 { ARC_R0_REGNUM + 5, { "r5" }, false },
152 { ARC_R0_REGNUM + 6, { "r6" }, false },
153 { ARC_R0_REGNUM + 7, { "r7" }, false },
154 { ARC_R0_REGNUM + 8, { "r8" }, false },
155 { ARC_R0_REGNUM + 9, { "r9" }, false },
156 { ARC_R0_REGNUM + 10, { "r10" }, true },
157 { ARC_R0_REGNUM + 11, { "r11" }, true },
158 { ARC_R0_REGNUM + 12, { "r12" }, true },
159 { ARC_R0_REGNUM + 13, { "r13" }, true },
160 { ARC_R0_REGNUM + 14, { "r14" }, true },
161 { ARC_R0_REGNUM + 15, { "r15" }, true },
162 { ARC_R0_REGNUM + 16, { "r16" }, false },
163 { ARC_R0_REGNUM + 17, { "r17" }, false },
164 { ARC_R0_REGNUM + 18, { "r18" }, false },
165 { ARC_R0_REGNUM + 19, { "r19" }, false },
166 { ARC_R0_REGNUM + 20, { "r20" }, false },
167 { ARC_R0_REGNUM + 21, { "r21" }, false },
168 { ARC_R0_REGNUM + 22, { "r22" }, false },
169 { ARC_R0_REGNUM + 23, { "r23" }, false },
170 { ARC_R0_REGNUM + 24, { "r24" }, false },
171 { ARC_R0_REGNUM + 25, { "r25" }, false },
172 { ARC_R0_REGNUM + 26, { "gp" }, true },
173 { ARC_R0_REGNUM + 27, { "fp" }, true },
174 { ARC_R0_REGNUM + 28, { "sp" }, true },
175 { ARC_R0_REGNUM + 29, { "ilink1" }, false },
176 { ARC_R0_REGNUM + 30, { "ilink2" }, false },
177 { ARC_R0_REGNUM + 31, { "blink" }, true },
178 { ARC_R0_REGNUM + 32, { "r32" }, false },
179 { ARC_R0_REGNUM + 33, { "r33" }, false },
180 { ARC_R0_REGNUM + 34, { "r34" }, false },
181 { ARC_R0_REGNUM + 35, { "r35" }, false },
182 { ARC_R0_REGNUM + 36, { "r36" }, false },
183 { ARC_R0_REGNUM + 37, { "r37" }, false },
184 { ARC_R0_REGNUM + 38, { "r38" }, false },
185 { ARC_R0_REGNUM + 39, { "r39" }, false },
186 { ARC_R0_REGNUM + 40, { "r40" }, false },
187 { ARC_R0_REGNUM + 41, { "r41" }, false },
188 { ARC_R0_REGNUM + 42, { "r42" }, false },
189 { ARC_R0_REGNUM + 43, { "r43" }, false },
190 { ARC_R0_REGNUM + 44, { "r44" }, false },
191 { ARC_R0_REGNUM + 45, { "r45" }, false },
192 { ARC_R0_REGNUM + 46, { "r46" }, false },
193 { ARC_R0_REGNUM + 47, { "r47" }, false },
194 { ARC_R0_REGNUM + 48, { "r48" }, false },
195 { ARC_R0_REGNUM + 49, { "r49" }, false },
196 { ARC_R0_REGNUM + 50, { "r50" }, false },
197 { ARC_R0_REGNUM + 51, { "r51" }, false },
198 { ARC_R0_REGNUM + 52, { "r52" }, false },
199 { ARC_R0_REGNUM + 53, { "r53" }, false },
200 { ARC_R0_REGNUM + 54, { "r54" }, false },
201 { ARC_R0_REGNUM + 55, { "r55" }, false },
202 { ARC_R0_REGNUM + 56, { "r56" }, false },
203 { ARC_R0_REGNUM + 57, { "r57" }, false },
204 { ARC_R0_REGNUM + 58, { "r58", "accl" }, false },
205 { ARC_R0_REGNUM + 59, { "r59", "acch" }, false },
206 { ARC_R0_REGNUM + 60, { "lp_count" }, false },
207 { ARC_R0_REGNUM + 61, { "reserved" }, false },
208 { ARC_R0_REGNUM + 62, { "limm" }, false },
209 { ARC_R0_REGNUM + 63, { "pcl" }, true }
213 /* ARCv2 (ARCHS) general core registers feature set. See also
214 arc_update_acc_reg_names() for "accl/acch" names. */
216 static struct arc_register_feature arc_v2_core_reg_feature =
218 ARC_CORE_FEATURE_NAME,
220 { ARC_R0_REGNUM + 0, { "r0" }, true },
221 { ARC_R0_REGNUM + 1, { "r1" }, true },
222 { ARC_R0_REGNUM + 2, { "r2" }, true },
223 { ARC_R0_REGNUM + 3, { "r3" }, true },
224 { ARC_R0_REGNUM + 4, { "r4" }, false },
225 { ARC_R0_REGNUM + 5, { "r5" }, false },
226 { ARC_R0_REGNUM + 6, { "r6" }, false },
227 { ARC_R0_REGNUM + 7, { "r7" }, false },
228 { ARC_R0_REGNUM + 8, { "r8" }, false },
229 { ARC_R0_REGNUM + 9, { "r9" }, false },
230 { ARC_R0_REGNUM + 10, { "r10" }, true },
231 { ARC_R0_REGNUM + 11, { "r11" }, true },
232 { ARC_R0_REGNUM + 12, { "r12" }, true },
233 { ARC_R0_REGNUM + 13, { "r13" }, true },
234 { ARC_R0_REGNUM + 14, { "r14" }, true },
235 { ARC_R0_REGNUM + 15, { "r15" }, true },
236 { ARC_R0_REGNUM + 16, { "r16" }, false },
237 { ARC_R0_REGNUM + 17, { "r17" }, false },
238 { ARC_R0_REGNUM + 18, { "r18" }, false },
239 { ARC_R0_REGNUM + 19, { "r19" }, false },
240 { ARC_R0_REGNUM + 20, { "r20" }, false },
241 { ARC_R0_REGNUM + 21, { "r21" }, false },
242 { ARC_R0_REGNUM + 22, { "r22" }, false },
243 { ARC_R0_REGNUM + 23, { "r23" }, false },
244 { ARC_R0_REGNUM + 24, { "r24" }, false },
245 { ARC_R0_REGNUM + 25, { "r25" }, false },
246 { ARC_R0_REGNUM + 26, { "gp" }, true },
247 { ARC_R0_REGNUM + 27, { "fp" }, true },
248 { ARC_R0_REGNUM + 28, { "sp" }, true },
249 { ARC_R0_REGNUM + 29, { "ilink" }, false },
250 { ARC_R0_REGNUM + 30, { "r30" }, true },
251 { ARC_R0_REGNUM + 31, { "blink" }, true },
252 { ARC_R0_REGNUM + 32, { "r32" }, false },
253 { ARC_R0_REGNUM + 33, { "r33" }, false },
254 { ARC_R0_REGNUM + 34, { "r34" }, false },
255 { ARC_R0_REGNUM + 35, { "r35" }, false },
256 { ARC_R0_REGNUM + 36, { "r36" }, false },
257 { ARC_R0_REGNUM + 37, { "r37" }, false },
258 { ARC_R0_REGNUM + 38, { "r38" }, false },
259 { ARC_R0_REGNUM + 39, { "r39" }, false },
260 { ARC_R0_REGNUM + 40, { "r40" }, false },
261 { ARC_R0_REGNUM + 41, { "r41" }, false },
262 { ARC_R0_REGNUM + 42, { "r42" }, false },
263 { ARC_R0_REGNUM + 43, { "r43" }, false },
264 { ARC_R0_REGNUM + 44, { "r44" }, false },
265 { ARC_R0_REGNUM + 45, { "r45" }, false },
266 { ARC_R0_REGNUM + 46, { "r46" }, false },
267 { ARC_R0_REGNUM + 47, { "r47" }, false },
268 { ARC_R0_REGNUM + 48, { "r48" }, false },
269 { ARC_R0_REGNUM + 49, { "r49" }, false },
270 { ARC_R0_REGNUM + 50, { "r50" }, false },
271 { ARC_R0_REGNUM + 51, { "r51" }, false },
272 { ARC_R0_REGNUM + 52, { "r52" }, false },
273 { ARC_R0_REGNUM + 53, { "r53" }, false },
274 { ARC_R0_REGNUM + 54, { "r54" }, false },
275 { ARC_R0_REGNUM + 55, { "r55" }, false },
276 { ARC_R0_REGNUM + 56, { "r56" }, false },
277 { ARC_R0_REGNUM + 57, { "r57" }, false },
278 { ARC_R0_REGNUM + 58, { "r58", "accl" }, false },
279 { ARC_R0_REGNUM + 59, { "r59", "acch" }, false },
280 { ARC_R0_REGNUM + 60, { "lp_count" }, false },
281 { ARC_R0_REGNUM + 61, { "reserved" }, false },
282 { ARC_R0_REGNUM + 62, { "limm" }, false },
283 { ARC_R0_REGNUM + 63, { "pcl" }, true }
287 /* The common auxiliary registers feature set. The REGNUM field
288 must match the ARC_REGNUM enum in arc-tdep.h. */
290 static const struct arc_register_feature arc_common_aux_reg_feature =
292 ARC_AUX_FEATURE_NAME,
294 { ARC_FIRST_AUX_REGNUM + 0, { "pc" }, true },
295 { ARC_FIRST_AUX_REGNUM + 1, { "status32" }, true },
296 { ARC_FIRST_AUX_REGNUM + 2, { "lp_start" }, false },
297 { ARC_FIRST_AUX_REGNUM + 3, { "lp_end" }, false },
298 { ARC_FIRST_AUX_REGNUM + 4, { "bta" }, false }
302 static std::string arc_disassembler_options;
304 /* Functions are sorted in the order as they are used in the
305 _initialize_arc_tdep (), which uses the same order as gdbarch.h. Static
306 functions are defined before the first invocation. */
308 /* Returns an unsigned value of OPERAND_NUM in instruction INSN.
309 For relative branch instructions returned value is an offset, not an actual
310 branch target. */
312 static ULONGEST
313 arc_insn_get_operand_value (const struct arc_instruction &insn,
314 unsigned int operand_num)
316 switch (insn.operands[operand_num].kind)
318 case ARC_OPERAND_KIND_LIMM:
319 gdb_assert (insn.limm_p);
320 return insn.limm_value;
321 case ARC_OPERAND_KIND_SHIMM:
322 return insn.operands[operand_num].value;
323 default:
324 /* Value in instruction is a register number. */
325 regcache *regcache = get_thread_regcache (inferior_thread ());
326 ULONGEST value;
327 regcache_cooked_read_unsigned (regcache,
328 insn.operands[operand_num].value,
329 &value);
330 return value;
334 /* Like arc_insn_get_operand_value, but returns a signed value. */
336 static LONGEST
337 arc_insn_get_operand_value_signed (const struct arc_instruction &insn,
338 unsigned int operand_num)
340 switch (insn.operands[operand_num].kind)
342 case ARC_OPERAND_KIND_LIMM:
343 gdb_assert (insn.limm_p);
344 /* Convert unsigned raw value to signed one. This assumes 2's
345 complement arithmetic, but so is the LONG_MIN value from generic
346 defs.h and that assumption is true for ARC. */
347 static_assert (sizeof (insn.limm_value) == sizeof (int));
348 return (((LONGEST) insn.limm_value) ^ INT_MIN) - INT_MIN;
349 case ARC_OPERAND_KIND_SHIMM:
350 /* Sign conversion has been done by binutils. */
351 return insn.operands[operand_num].value;
352 default:
353 /* Value in instruction is a register number. */
354 regcache *regcache = get_thread_regcache (inferior_thread ());
355 LONGEST value;
356 regcache_cooked_read_signed (regcache,
357 insn.operands[operand_num].value,
358 &value);
359 return value;
363 /* Get register with base address of memory operation. */
365 static int
366 arc_insn_get_memory_base_reg (const struct arc_instruction &insn)
368 /* POP_S and PUSH_S have SP as an implicit argument in a disassembler. */
369 if (insn.insn_class == PUSH || insn.insn_class == POP)
370 return ARC_SP_REGNUM;
372 gdb_assert (insn.insn_class == LOAD || insn.insn_class == STORE);
374 /* Other instructions all have at least two operands: operand 0 is data,
375 operand 1 is address. Operand 2 is offset from address. However, see
376 comment to arc_instruction.operands - in some cases, third operand may be
377 missing, namely if it is 0. */
378 gdb_assert (insn.operands_count >= 2);
379 return insn.operands[1].value;
382 /* Get offset of a memory operation INSN. */
384 static CORE_ADDR
385 arc_insn_get_memory_offset (const struct arc_instruction &insn)
387 /* POP_S and PUSH_S have offset as an implicit argument in a
388 disassembler. */
389 if (insn.insn_class == POP)
390 return 4;
391 else if (insn.insn_class == PUSH)
392 return -4;
394 gdb_assert (insn.insn_class == LOAD || insn.insn_class == STORE);
396 /* Other instructions all have at least two operands: operand 0 is data,
397 operand 1 is address. Operand 2 is offset from address. However, see
398 comment to arc_instruction.operands - in some cases, third operand may be
399 missing, namely if it is 0. */
400 if (insn.operands_count < 3)
401 return 0;
403 CORE_ADDR value = arc_insn_get_operand_value (insn, 2);
404 /* Handle scaling. */
405 if (insn.writeback_mode == ARC_WRITEBACK_AS)
407 /* Byte data size is not valid for AS. Halfword means shift by 1 bit.
408 Word and double word means shift by 2 bits. */
409 gdb_assert (insn.data_size_mode != ARC_SCALING_B);
410 if (insn.data_size_mode == ARC_SCALING_H)
411 value <<= 1;
412 else
413 value <<= 2;
415 return value;
418 CORE_ADDR
419 arc_insn_get_branch_target (const struct arc_instruction &insn)
421 gdb_assert (insn.is_control_flow);
423 /* BI [c]: PC = nextPC + (c << 2). */
424 if (insn.insn_class == BI)
426 ULONGEST reg_value = arc_insn_get_operand_value (insn, 0);
427 return arc_insn_get_linear_next_pc (insn) + (reg_value << 2);
429 /* BIH [c]: PC = nextPC + (c << 1). */
430 else if (insn.insn_class == BIH)
432 ULONGEST reg_value = arc_insn_get_operand_value (insn, 0);
433 return arc_insn_get_linear_next_pc (insn) + (reg_value << 1);
435 /* JLI and EI. */
436 /* JLI and EI depend on optional AUX registers. Not supported right now. */
437 else if (insn.insn_class == JLI)
439 gdb_printf (gdb_stderr,
440 "JLI_S instruction is not supported by the GDB.");
441 return 0;
443 else if (insn.insn_class == EI)
445 gdb_printf (gdb_stderr,
446 "EI_S instruction is not supported by the GDB.");
447 return 0;
449 /* LEAVE_S: PC = BLINK. */
450 else if (insn.insn_class == LEAVE)
452 regcache *regcache = get_thread_regcache (inferior_thread ());
453 ULONGEST value;
454 regcache_cooked_read_unsigned (regcache, ARC_BLINK_REGNUM, &value);
455 return value;
457 /* BBIT0/1, BRcc: PC = currentPC + operand. */
458 else if (insn.insn_class == BBIT0 || insn.insn_class == BBIT1
459 || insn.insn_class == BRCC)
461 /* Most instructions has branch target as their sole argument. However
462 conditional brcc/bbit has it as a third operand. */
463 CORE_ADDR pcrel_addr = arc_insn_get_operand_value (insn, 2);
465 /* Offset is relative to the 4-byte aligned address of the current
466 instruction, hence last two bits should be truncated. */
467 return pcrel_addr + align_down (insn.address, 4);
469 /* DBNZ is the only branch instruction that keeps a branch address in
470 the second operand. It must be intercepted and treated differently. */
471 else if (insn.insn_class == DBNZ)
473 CORE_ADDR pcrel_addr = arc_insn_get_operand_value_signed (insn, 1);
475 /* Offset is relative to the 4-byte aligned address of the current
476 instruction, hence last two bits should be truncated. */
477 return pcrel_addr + align_down (insn.address, 4);
479 /* B, Bcc, BL, BLcc, LP, LPcc: PC = currentPC + operand. */
480 else if (insn.insn_class == BRANCH || insn.insn_class == LOOP)
482 CORE_ADDR pcrel_addr = arc_insn_get_operand_value (insn, 0);
484 /* Offset is relative to the 4-byte aligned address of the current
485 instruction, hence last two bits should be truncated. */
486 return pcrel_addr + align_down (insn.address, 4);
488 /* J, Jcc, JL, JLcc: PC = operand. */
489 else if (insn.insn_class == JUMP)
491 /* All jumps are single-operand. */
492 return arc_insn_get_operand_value (insn, 0);
495 /* This is some new and unknown instruction. */
496 gdb_assert_not_reached ("Unknown branch instruction.");
499 /* Dump INSN into gdb_stdlog. */
501 static void
502 arc_insn_dump (const struct arc_instruction &insn)
504 struct gdbarch *gdbarch = current_inferior ()->arch ();
506 arc_print ("Dumping arc_instruction at %s\n",
507 paddress (gdbarch, insn.address));
508 arc_print ("\tlength = %u\n", insn.length);
510 if (!insn.valid)
512 arc_print ("\tThis is not a valid ARC instruction.\n");
513 return;
516 arc_print ("\tlength_with_limm = %u\n", insn.length + (insn.limm_p ? 4 : 0));
517 arc_print ("\tcc = 0x%x\n", insn.condition_code);
518 arc_print ("\tinsn_class = %u\n", insn.insn_class);
519 arc_print ("\tis_control_flow = %i\n", insn.is_control_flow);
520 arc_print ("\thas_delay_slot = %i\n", insn.has_delay_slot);
522 CORE_ADDR next_pc = arc_insn_get_linear_next_pc (insn);
523 arc_print ("\tlinear_next_pc = %s\n", paddress (gdbarch, next_pc));
525 if (insn.is_control_flow)
527 CORE_ADDR t = arc_insn_get_branch_target (insn);
528 arc_print ("\tbranch_target = %s\n", paddress (gdbarch, t));
531 arc_print ("\tlimm_p = %i\n", insn.limm_p);
532 if (insn.limm_p)
533 arc_print ("\tlimm_value = 0x%08x\n", insn.limm_value);
535 if (insn.insn_class == STORE || insn.insn_class == LOAD
536 || insn.insn_class == PUSH || insn.insn_class == POP)
538 arc_print ("\twriteback_mode = %u\n", insn.writeback_mode);
539 arc_print ("\tdata_size_mode = %u\n", insn.data_size_mode);
540 arc_print ("\tmemory_base_register = %s\n",
541 gdbarch_register_name (gdbarch,
542 arc_insn_get_memory_base_reg (insn)));
543 /* get_memory_offset returns an unsigned CORE_ADDR, but treat it as a
544 LONGEST for a nicer representation. */
545 arc_print ("\taddr_offset = %s\n",
546 plongest (arc_insn_get_memory_offset (insn)));
549 arc_print ("\toperands_count = %u\n", insn.operands_count);
550 for (unsigned int i = 0; i < insn.operands_count; ++i)
552 int is_reg = (insn.operands[i].kind == ARC_OPERAND_KIND_REG);
554 arc_print ("\toperand[%u] = {\n", i);
555 arc_print ("\t\tis_reg = %i\n", is_reg);
556 if (is_reg)
557 arc_print ("\t\tregister = %s\n",
558 gdbarch_register_name (gdbarch, insn.operands[i].value));
559 /* Don't know if this value is signed or not, so print both
560 representations. This tends to look quite ugly, especially for big
561 numbers. */
562 arc_print ("\t\tunsigned value = %s\n",
563 pulongest (arc_insn_get_operand_value (insn, i)));
564 arc_print ("\t\tsigned value = %s\n",
565 plongest (arc_insn_get_operand_value_signed (insn, i)));
566 arc_print ("\t}\n");
570 CORE_ADDR
571 arc_insn_get_linear_next_pc (const struct arc_instruction &insn)
573 /* In ARC long immediate is always 4 bytes. */
574 return (insn.address + insn.length + (insn.limm_p ? 4 : 0));
577 /* Implement the "write_pc" gdbarch method.
579 In ARC PC register is a normal register so in most cases setting PC value
580 is a straightforward process: debugger just writes PC value. However it
581 gets trickier in case when current instruction is an instruction in delay
582 slot. In this case CPU will execute instruction at current PC value, then
583 will set PC to the current value of BTA register; also current instruction
584 cannot be branch/jump and some of the other instruction types. Thus if
585 debugger would try to just change PC value in this case, this instruction
586 will get executed, but then core will "jump" to the original branch target.
588 Whether current instruction is a delay-slot instruction or not is indicated
589 by DE bit in STATUS32 register indicates if current instruction is a delay
590 slot instruction. This bit is writable by debug host, which allows debug
591 host to prevent core from jumping after the delay slot instruction. It
592 also works in another direction: setting this bit will make core to treat
593 any current instructions as a delay slot instruction and to set PC to the
594 current value of BTA register.
596 To workaround issues with changing PC register while in delay slot
597 instruction, debugger should check for the STATUS32.DE bit and reset it if
598 it is set. No other change is required in this function. Most common
599 case, where this function might be required is calling inferior functions
600 from debugger. Generic GDB logic handles this pretty well: current values
601 of registers are stored, value of PC is changed (that is the job of this
602 function), and after inferior function is executed, GDB restores all
603 registers, include BTA and STATUS32, which also means that core is returned
604 to its original state of being halted on delay slot instructions.
606 This method is useless for ARC 600, because it doesn't have externally
607 exposed BTA register. In the case of ARC 600 it is impossible to restore
608 core to its state in all occasions thus core should never be halted (from
609 the perspective of debugger host) in the delay slot. */
611 static void
612 arc_write_pc (struct regcache *regcache, CORE_ADDR new_pc)
614 struct gdbarch *gdbarch = regcache->arch ();
616 arc_debug_printf ("Writing PC, new value=%s",
617 paddress (gdbarch, new_pc));
619 regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch),
620 new_pc);
622 ULONGEST status32;
623 regcache_cooked_read_unsigned (regcache, gdbarch_ps_regnum (gdbarch),
624 &status32);
626 if ((status32 & ARC_STATUS32_DE_MASK) != 0)
628 arc_debug_printf ("Changing PC while in delay slot. Will "
629 "reset STATUS32.DE bit to zero. Value of STATUS32 "
630 "register is 0x%s",
631 phex (status32, ARC_REGISTER_SIZE));
633 /* Reset bit and write to the cache. */
634 status32 &= ~0x40;
635 regcache_cooked_write_unsigned (regcache, gdbarch_ps_regnum (gdbarch),
636 status32);
640 /* Implement the "virtual_frame_pointer" gdbarch method.
642 According to ABI the FP (r27) is used to point to the middle of the current
643 stack frame, just below the saved FP and before local variables, register
644 spill area and outgoing args. However for optimization levels above O2 and
645 in any case in leaf functions, the frame pointer is usually not set at all.
646 The exception being when handling nested functions.
648 We use this function to return a "virtual" frame pointer, marking the start
649 of the current stack frame as a register-offset pair. If the FP is not
650 being used, then it should return SP, with an offset of the frame size.
652 The current implementation doesn't actually know the frame size, nor
653 whether the FP is actually being used, so for now we just return SP and an
654 offset of zero. This is no worse than other architectures, but is needed
655 to avoid assertion failures.
657 TODO: Can we determine the frame size to get a correct offset?
659 PC is a program counter where we need the virtual FP. REG_PTR is the base
660 register used for the virtual FP. OFFSET_PTR is the offset used for the
661 virtual FP. */
663 static void
664 arc_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
665 int *reg_ptr, LONGEST *offset_ptr)
667 *reg_ptr = gdbarch_sp_regnum (gdbarch);
668 *offset_ptr = 0;
671 /* Implement the "push_dummy_call" gdbarch method.
673 Stack Frame Layout
675 This shows the layout of the stack frame for the general case of a
676 function call; a given function might not have a variable number of
677 arguments or local variables, or might not save any registers, so it would
678 not have the corresponding frame areas. Additionally, a leaf function
679 (i.e. one which calls no other functions) does not need to save the
680 contents of the BLINK register (which holds its return address), and a
681 function might not have a frame pointer.
683 The stack grows downward, so SP points below FP in memory; SP always
684 points to the last used word on the stack, not the first one.
686 | | |
687 | arg word N | | caller's
688 | : | | frame
689 | arg word 10 | |
690 | arg word 9 | |
691 old SP ---> +-----------------------+ --+
692 | | |
693 | callee-saved | |
694 | registers | |
695 | including fp, blink | |
696 | | | callee's
697 new FP ---> +-----------------------+ | frame
698 | | |
699 | local | |
700 | variables | |
701 | | |
702 | register | |
703 | spill area | |
704 | | |
705 | outgoing args | |
706 | | |
707 new SP ---> +-----------------------+ --+
709 | unused |
714 downwards
716 The list of arguments to be passed to a function is considered to be a
717 sequence of _N_ words (as though all the parameters were stored in order in
718 memory with each parameter occupying an integral number of words). Words
719 1..8 are passed in registers 0..7; if the function has more than 8 words of
720 arguments then words 9..@em N are passed on the stack in the caller's frame.
722 If the function has a variable number of arguments, e.g. it has a form such
723 as `function (p1, p2, ...);' and _P_ words are required to hold the values
724 of the named parameters (which are passed in registers 0..@em P -1), then
725 the remaining 8 - _P_ words passed in registers _P_..7 are spilled into the
726 top of the frame so that the anonymous parameter words occupy a continuous
727 region.
729 Any arguments are already in target byte order. We just need to store
730 them!
732 BP_ADDR is the return address where breakpoint must be placed. NARGS is
733 the number of arguments to the function. ARGS is the arguments values (in
734 target byte order). SP is the Current value of SP register. STRUCT_RETURN
735 is TRUE if structures are returned by the function. STRUCT_ADDR is the
736 hidden address for returning a struct. Returns SP of a new frame. */
738 static CORE_ADDR
739 arc_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
740 struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
741 struct value **args, CORE_ADDR sp,
742 function_call_return_method return_method,
743 CORE_ADDR struct_addr)
745 arc_debug_printf ("nargs = %d", nargs);
747 int arg_reg = ARC_FIRST_ARG_REGNUM;
749 /* Push the return address. */
750 regcache_cooked_write_unsigned (regcache, ARC_BLINK_REGNUM, bp_addr);
752 /* Are we returning a value using a structure return instead of a normal
753 value return? If so, struct_addr is the address of the reserved space for
754 the return structure to be written on the stack, and that address is
755 passed to that function as a hidden first argument. */
756 if (return_method == return_method_struct)
758 /* Pass the return address in the first argument register. */
759 regcache_cooked_write_unsigned (regcache, arg_reg, struct_addr);
761 arc_debug_printf ("struct return address %s passed in R%d",
762 print_core_address (gdbarch, struct_addr), arg_reg);
764 arg_reg++;
767 if (nargs > 0)
769 unsigned int total_space = 0;
771 /* How much space do the arguments occupy in total? Must round each
772 argument's size up to an integral number of words. */
773 for (int i = 0; i < nargs; i++)
775 unsigned int len = args[i]->type ()->length ();
776 unsigned int space = align_up (len, 4);
778 total_space += space;
780 arc_debug_printf ("arg %d: %u bytes -> %u", i, len, space);
783 /* Allocate a buffer to hold a memory image of the arguments. */
784 gdb_byte *memory_image = XCNEWVEC (gdb_byte, total_space);
786 /* Now copy all of the arguments into the buffer, correctly aligned. */
787 gdb_byte *data = memory_image;
788 for (int i = 0; i < nargs; i++)
790 unsigned int len = args[i]->type ()->length ();
791 unsigned int space = align_up (len, 4);
793 memcpy (data, args[i]->contents ().data (), (size_t) len);
794 arc_debug_printf ("copying arg %d, val 0x%08x, len %d to mem",
795 i, *((int *) args[i]->contents ().data ()),
796 len);
798 data += space;
801 /* Now load as much as possible of the memory image into registers. */
802 data = memory_image;
803 while (arg_reg <= ARC_LAST_ARG_REGNUM)
805 arc_debug_printf ("passing 0x%02x%02x%02x%02x in register R%d",
806 data[0], data[1], data[2], data[3], arg_reg);
808 /* Note we don't use write_unsigned here, since that would convert
809 the byte order, but we are already in the correct byte order. */
810 regcache->cooked_write (arg_reg, data);
812 data += ARC_REGISTER_SIZE;
813 total_space -= ARC_REGISTER_SIZE;
815 /* All the data is now in registers. */
816 if (total_space == 0)
817 break;
819 arg_reg++;
822 /* If there is any data left, push it onto the stack (in a single write
823 operation). */
824 if (total_space > 0)
826 arc_debug_printf ("passing %d bytes on stack\n", total_space);
828 sp -= total_space;
829 write_memory (sp, data, (int) total_space);
832 xfree (memory_image);
835 /* Finally, update the SP register. */
836 regcache_cooked_write_unsigned (regcache, gdbarch_sp_regnum (gdbarch), sp);
838 return sp;
841 /* Implement the "push_dummy_code" gdbarch method.
843 We don't actually push any code. We just identify where a breakpoint can
844 be inserted to which we are can return and the resume address where we
845 should be called.
847 ARC does not necessarily have an executable stack, so we can't put the
848 return breakpoint there. Instead we put it at the entry point of the
849 function. This means the SP is unchanged.
851 SP is a current stack pointer FUNADDR is an address of the function to be
852 called. ARGS is arguments to pass. NARGS is a number of args to pass.
853 VALUE_TYPE is a type of value returned. REAL_PC is a resume address when
854 the function is called. BP_ADDR is an address where breakpoint should be
855 set. Returns the updated stack pointer. */
857 static CORE_ADDR
858 arc_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, CORE_ADDR funaddr,
859 struct value **args, int nargs, struct type *value_type,
860 CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
861 struct regcache *regcache)
863 *real_pc = funaddr;
864 *bp_addr = entry_point_address (current_program_space);
865 return sp;
868 /* Implement the "cannot_fetch_register" gdbarch method. */
870 static int
871 arc_cannot_fetch_register (struct gdbarch *gdbarch, int regnum)
873 /* Assume that register is readable if it is unknown. LIMM and RESERVED are
874 not real registers, but specific register numbers. They are available as
875 regnums to align architectural register numbers with GDB internal regnums,
876 but they shouldn't appear in target descriptions generated by
877 GDB-servers. */
878 switch (regnum)
880 case ARC_RESERVED_REGNUM:
881 case ARC_LIMM_REGNUM:
882 return true;
883 default:
884 return false;
888 /* Implement the "cannot_store_register" gdbarch method. */
890 static int
891 arc_cannot_store_register (struct gdbarch *gdbarch, int regnum)
893 /* Assume that register is writable if it is unknown. See comment in
894 arc_cannot_fetch_register about LIMM and RESERVED. */
895 switch (regnum)
897 case ARC_RESERVED_REGNUM:
898 case ARC_LIMM_REGNUM:
899 case ARC_PCL_REGNUM:
900 return true;
901 default:
902 return false;
906 /* Get the return value of a function from the registers/memory used to
907 return it, according to the convention used by the ABI - 4-bytes values are
908 in the R0, while 8-byte values are in the R0-R1.
910 TODO: This implementation ignores the case of "complex double", where
911 according to ABI, value is returned in the R0-R3 registers.
913 TYPE is a returned value's type. VALBUF is a buffer for the returned
914 value. */
916 static void
917 arc_extract_return_value (struct gdbarch *gdbarch, struct type *type,
918 struct regcache *regcache, gdb_byte *valbuf)
920 unsigned int len = type->length ();
922 arc_debug_printf ("called");
924 if (len <= ARC_REGISTER_SIZE)
926 ULONGEST val;
928 /* Get the return value from one register. */
929 regcache_cooked_read_unsigned (regcache, ARC_R0_REGNUM, &val);
930 store_unsigned_integer (valbuf, (int) len,
931 gdbarch_byte_order (gdbarch), val);
933 arc_debug_printf ("returning 0x%s", phex (val, ARC_REGISTER_SIZE));
935 else if (len <= ARC_REGISTER_SIZE * 2)
937 ULONGEST low, high;
939 /* Get the return value from two registers. */
940 regcache_cooked_read_unsigned (regcache, ARC_R0_REGNUM, &low);
941 regcache_cooked_read_unsigned (regcache, ARC_R1_REGNUM, &high);
943 store_unsigned_integer (valbuf, ARC_REGISTER_SIZE,
944 gdbarch_byte_order (gdbarch), low);
945 store_unsigned_integer (valbuf + ARC_REGISTER_SIZE,
946 (int) len - ARC_REGISTER_SIZE,
947 gdbarch_byte_order (gdbarch), high);
949 arc_debug_printf ("returning 0x%s%s",
950 phex (high, ARC_REGISTER_SIZE),
951 phex (low, ARC_REGISTER_SIZE));
953 else
954 error (_("arc: extract_return_value: type length %u too large"), len);
958 /* Store the return value of a function into the registers/memory used to
959 return it, according to the convention used by the ABI.
961 TODO: This implementation ignores the case of "complex double", where
962 according to ABI, value is returned in the R0-R3 registers.
964 TYPE is a returned value's type. VALBUF is a buffer with the value to
965 return. */
967 static void
968 arc_store_return_value (struct gdbarch *gdbarch, struct type *type,
969 struct regcache *regcache, const gdb_byte *valbuf)
971 unsigned int len = type->length ();
973 arc_debug_printf ("called");
975 if (len <= ARC_REGISTER_SIZE)
977 ULONGEST val;
979 /* Put the return value into one register. */
980 val = extract_unsigned_integer (valbuf, (int) len,
981 gdbarch_byte_order (gdbarch));
982 regcache_cooked_write_unsigned (regcache, ARC_R0_REGNUM, val);
984 arc_debug_printf ("storing 0x%s", phex (val, ARC_REGISTER_SIZE));
986 else if (len <= ARC_REGISTER_SIZE * 2)
988 ULONGEST low, high;
990 /* Put the return value into two registers. */
991 low = extract_unsigned_integer (valbuf, ARC_REGISTER_SIZE,
992 gdbarch_byte_order (gdbarch));
993 high = extract_unsigned_integer (valbuf + ARC_REGISTER_SIZE,
994 (int) len - ARC_REGISTER_SIZE,
995 gdbarch_byte_order (gdbarch));
997 regcache_cooked_write_unsigned (regcache, ARC_R0_REGNUM, low);
998 regcache_cooked_write_unsigned (regcache, ARC_R1_REGNUM, high);
1000 arc_debug_printf ("storing 0x%s%s",
1001 phex (high, ARC_REGISTER_SIZE),
1002 phex (low, ARC_REGISTER_SIZE));
1004 else
1005 error (_("arc_store_return_value: type length too large."));
1008 /* Implement the "get_longjmp_target" gdbarch method. */
1010 static int
1011 arc_get_longjmp_target (const frame_info_ptr &frame, CORE_ADDR *pc)
1013 arc_debug_printf ("called");
1015 struct gdbarch *gdbarch = get_frame_arch (frame);
1016 arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
1017 int pc_offset = tdep->jb_pc * ARC_REGISTER_SIZE;
1018 gdb_byte buf[ARC_REGISTER_SIZE];
1019 CORE_ADDR jb_addr = get_frame_register_unsigned (frame, ARC_FIRST_ARG_REGNUM);
1021 if (target_read_memory (jb_addr + pc_offset, buf, ARC_REGISTER_SIZE))
1022 return 0; /* Failed to read from memory. */
1024 *pc = extract_unsigned_integer (buf, ARC_REGISTER_SIZE,
1025 gdbarch_byte_order (gdbarch));
1026 return 1;
1029 /* Implement the "return_value" gdbarch method. */
1031 static enum return_value_convention
1032 arc_return_value (struct gdbarch *gdbarch, struct value *function,
1033 struct type *valtype, struct regcache *regcache,
1034 gdb_byte *readbuf, const gdb_byte *writebuf)
1036 /* If the return type is a struct, or a union, or would occupy more than two
1037 registers, the ABI uses the "struct return convention": the calling
1038 function passes a hidden first parameter to the callee (in R0). That
1039 parameter is the address at which the value being returned should be
1040 stored. Otherwise, the result is returned in registers. */
1041 int is_struct_return = (valtype->code () == TYPE_CODE_STRUCT
1042 || valtype->code () == TYPE_CODE_UNION
1043 || valtype->length () > 2 * ARC_REGISTER_SIZE);
1045 arc_debug_printf ("readbuf = %s, writebuf = %s",
1046 host_address_to_string (readbuf),
1047 host_address_to_string (writebuf));
1049 if (writebuf != NULL)
1051 /* Case 1. GDB should not ask us to set a struct return value: it
1052 should know the struct return location and write the value there
1053 itself. */
1054 gdb_assert (!is_struct_return);
1055 arc_store_return_value (gdbarch, valtype, regcache, writebuf);
1057 else if (readbuf != NULL)
1059 /* Case 2. GDB should not ask us to get a struct return value: it
1060 should know the struct return location and read the value from there
1061 itself. */
1062 gdb_assert (!is_struct_return);
1063 arc_extract_return_value (gdbarch, valtype, regcache, readbuf);
1066 return (is_struct_return
1067 ? RETURN_VALUE_STRUCT_CONVENTION
1068 : RETURN_VALUE_REGISTER_CONVENTION);
1071 /* Return the base address of the frame. For ARC, the base address is the
1072 frame pointer. */
1074 static CORE_ADDR
1075 arc_frame_base_address (const frame_info_ptr &this_frame, void **prologue_cache)
1077 return (CORE_ADDR) get_frame_register_unsigned (this_frame, ARC_FP_REGNUM);
1080 /* Helper function that returns valid pv_t for an instruction operand:
1081 either a register or a constant. */
1083 static pv_t
1084 arc_pv_get_operand (pv_t *regs, const struct arc_instruction &insn, int operand)
1086 if (insn.operands[operand].kind == ARC_OPERAND_KIND_REG)
1087 return regs[insn.operands[operand].value];
1088 else
1089 return pv_constant (arc_insn_get_operand_value (insn, operand));
1092 /* Determine whether the given disassembled instruction may be part of a
1093 function prologue. If it is, the information in the frame unwind cache will
1094 be updated. */
1096 static bool
1097 arc_is_in_prologue (struct gdbarch *gdbarch, const struct arc_instruction &insn,
1098 pv_t *regs, struct pv_area *stack)
1100 /* It might be that currently analyzed address doesn't contain an
1101 instruction, hence INSN is not valid. It likely means that address points
1102 to a data, non-initialized memory, or middle of a 32-bit instruction. In
1103 practice this may happen if GDB connects to a remote target that has
1104 non-zeroed memory. GDB would read PC value and would try to analyze
1105 prologue, but there is no guarantee that memory contents at the address
1106 specified in PC is address is a valid instruction. There is not much that
1107 that can be done about that. */
1108 if (!insn.valid)
1109 return false;
1111 /* Branch/jump or a predicated instruction. */
1112 if (insn.is_control_flow || insn.condition_code != ARC_CC_AL)
1113 return false;
1115 /* Store of some register. May or may not update base address register. */
1116 if (insn.insn_class == STORE || insn.insn_class == PUSH)
1118 /* There is definitely at least one operand - register/value being
1119 stored. */
1120 gdb_assert (insn.operands_count > 0);
1122 /* Store at some constant address. */
1123 if (insn.operands_count > 1
1124 && insn.operands[1].kind != ARC_OPERAND_KIND_REG)
1125 return false;
1127 /* Writeback modes:
1128 Mode Address used Writeback value
1129 --------------------------------------------------
1130 No reg + offset no
1131 A/AW reg + offset reg + offset
1132 AB reg reg + offset
1133 AS reg + (offset << scaling) no
1135 "PUSH reg" is an alias to "ST.AW reg, [SP, -4]" encoding. However
1136 16-bit PUSH_S is a distinct instruction encoding, where offset and
1137 base register are implied through opcode. */
1139 /* Register with base memory address. */
1140 int base_reg = arc_insn_get_memory_base_reg (insn);
1142 /* Address where to write. arc_insn_get_memory_offset returns scaled
1143 value for ARC_WRITEBACK_AS. */
1144 pv_t addr;
1145 if (insn.writeback_mode == ARC_WRITEBACK_AB)
1146 addr = regs[base_reg];
1147 else
1148 addr = pv_add_constant (regs[base_reg],
1149 arc_insn_get_memory_offset (insn));
1151 if (stack->store_would_trash (addr))
1152 return false;
1154 if (insn.data_size_mode != ARC_SCALING_D)
1156 /* Find the value being stored. */
1157 pv_t store_value = arc_pv_get_operand (regs, insn, 0);
1159 /* What is the size of a the stored value? */
1160 CORE_ADDR size;
1161 if (insn.data_size_mode == ARC_SCALING_B)
1162 size = 1;
1163 else if (insn.data_size_mode == ARC_SCALING_H)
1164 size = 2;
1165 else
1166 size = ARC_REGISTER_SIZE;
1168 stack->store (addr, size, store_value);
1170 else
1172 if (insn.operands[0].kind == ARC_OPERAND_KIND_REG)
1174 /* If this is a double store, than write N+1 register as well. */
1175 pv_t store_value1 = regs[insn.operands[0].value];
1176 pv_t store_value2 = regs[insn.operands[0].value + 1];
1177 stack->store (addr, ARC_REGISTER_SIZE, store_value1);
1178 stack->store (pv_add_constant (addr, ARC_REGISTER_SIZE),
1179 ARC_REGISTER_SIZE, store_value2);
1181 else
1183 pv_t store_value
1184 = pv_constant (arc_insn_get_operand_value (insn, 0));
1185 stack->store (addr, ARC_REGISTER_SIZE * 2, store_value);
1189 /* Is base register updated? */
1190 if (insn.writeback_mode == ARC_WRITEBACK_A
1191 || insn.writeback_mode == ARC_WRITEBACK_AB)
1192 regs[base_reg] = pv_add_constant (regs[base_reg],
1193 arc_insn_get_memory_offset (insn));
1195 return true;
1197 else if (insn.insn_class == MOVE)
1199 gdb_assert (insn.operands_count == 2);
1201 /* Destination argument can be "0", so nothing will happen. */
1202 if (insn.operands[0].kind == ARC_OPERAND_KIND_REG)
1204 int dst_regnum = insn.operands[0].value;
1205 regs[dst_regnum] = arc_pv_get_operand (regs, insn, 1);
1207 return true;
1209 else if (insn.insn_class == SUB)
1211 gdb_assert (insn.operands_count == 3);
1213 /* SUB 0,b,c. */
1214 if (insn.operands[0].kind != ARC_OPERAND_KIND_REG)
1215 return true;
1217 int dst_regnum = insn.operands[0].value;
1218 regs[dst_regnum] = pv_subtract (arc_pv_get_operand (regs, insn, 1),
1219 arc_pv_get_operand (regs, insn, 2));
1220 return true;
1222 else if (insn.insn_class == ENTER)
1224 /* ENTER_S is a prologue-in-instruction - it saves all callee-saved
1225 registers according to given arguments thus greatly reducing code
1226 size. Which registers will be actually saved depends on arguments.
1228 ENTER_S {R13-...,FP,BLINK} stores registers in following order:
1230 new SP ->
1231 BLINK
1237 old SP ->
1239 There are up to three arguments for this opcode, as presented by ARC
1240 disassembler:
1241 1) amount of general-purpose registers to be saved - this argument is
1242 always present even when it is 0;
1243 2) FP register number (27) if FP has to be stored, otherwise argument
1244 is not present;
1245 3) BLINK register number (31) if BLINK has to be stored, otherwise
1246 argument is not present. If both FP and BLINK are stored, then FP
1247 is present before BLINK in argument list. */
1248 gdb_assert (insn.operands_count > 0);
1250 int regs_saved = arc_insn_get_operand_value (insn, 0);
1252 bool is_fp_saved;
1253 if (insn.operands_count > 1)
1254 is_fp_saved = (insn.operands[1].value == ARC_FP_REGNUM);
1255 else
1256 is_fp_saved = false;
1258 bool is_blink_saved;
1259 if (insn.operands_count > 1)
1260 is_blink_saved = (insn.operands[insn.operands_count - 1].value
1261 == ARC_BLINK_REGNUM);
1262 else
1263 is_blink_saved = false;
1265 /* Amount of bytes to be allocated to store specified registers. */
1266 CORE_ADDR st_size = ((regs_saved + is_fp_saved + is_blink_saved)
1267 * ARC_REGISTER_SIZE);
1268 pv_t new_sp = pv_add_constant (regs[ARC_SP_REGNUM], -st_size);
1270 /* Assume that if the last register (closest to new SP) can be written,
1271 then it is possible to write all of them. */
1272 if (stack->store_would_trash (new_sp))
1273 return false;
1275 /* Current store address. */
1276 pv_t addr = regs[ARC_SP_REGNUM];
1278 if (is_fp_saved)
1280 addr = pv_add_constant (addr, -ARC_REGISTER_SIZE);
1281 stack->store (addr, ARC_REGISTER_SIZE, regs[ARC_FP_REGNUM]);
1284 /* Registers are stored in backward order: from GP (R26) to R13. */
1285 for (int i = ARC_R13_REGNUM + regs_saved - 1; i >= ARC_R13_REGNUM; i--)
1287 addr = pv_add_constant (addr, -ARC_REGISTER_SIZE);
1288 stack->store (addr, ARC_REGISTER_SIZE, regs[i]);
1291 if (is_blink_saved)
1293 addr = pv_add_constant (addr, -ARC_REGISTER_SIZE);
1294 stack->store (addr, ARC_REGISTER_SIZE,
1295 regs[ARC_BLINK_REGNUM]);
1298 gdb_assert (pv_is_identical (addr, new_sp));
1300 regs[ARC_SP_REGNUM] = new_sp;
1302 if (is_fp_saved)
1303 regs[ARC_FP_REGNUM] = regs[ARC_SP_REGNUM];
1305 return true;
1308 /* Some other architectures, like nds32 or arm, try to continue as far as
1309 possible when building a prologue cache (as opposed to when skipping
1310 prologue), so that cache will be as full as possible. However current
1311 code for ARC doesn't recognize some instructions that may modify SP, like
1312 ADD, AND, OR, etc, hence there is no way to guarantee that SP wasn't
1313 clobbered by the skipped instruction. Potential existence of extension
1314 instruction, which may do anything they want makes this even more complex,
1315 so it is just better to halt on a first unrecognized instruction. */
1317 return false;
1320 /* Analyze the prologue and update the corresponding frame cache for the frame
1321 unwinder for unwinding frames that doesn't have debug info. In such
1322 situation GDB attempts to parse instructions in the prologue to understand
1323 where each register is saved.
1325 If CACHE is not NULL, then it will be filled with information about saved
1326 registers.
1328 There are several variations of prologue which GDB may encounter. "Full"
1329 prologue looks like this:
1331 sub sp,sp,<imm> ; Space for variadic arguments.
1332 push blink ; Store return address.
1333 push r13 ; Store callee saved registers (up to R26/GP).
1334 push r14
1335 push fp ; Store frame pointer.
1336 mov fp,sp ; Update frame pointer.
1337 sub sp,sp,<imm> ; Create space for local vars on the stack.
1339 Depending on compiler options lots of things may change:
1341 1) BLINK is not saved in leaf functions.
1342 2) Frame pointer is not saved and updated if -fomit-frame-pointer is used.
1343 3) 16-bit versions of those instructions may be used.
1344 4) Instead of a sequence of several push'es, compiler may instead prefer to
1345 do one subtract on stack pointer and then store registers using normal
1346 store, that doesn't update SP. Like this:
1349 sub sp,sp,8 ; Create space for callee-saved registers.
1350 st r13,[sp,4] ; Store callee saved registers (up to R26/GP).
1351 st r14,[sp,0]
1353 5) ENTER_S instruction can encode most of prologue sequence in one
1354 instruction (except for those subtracts for variadic arguments and local
1355 variables).
1356 6) GCC may use "millicode" functions from libgcc to store callee-saved
1357 registers with minimal code-size requirements. This function currently
1358 doesn't support this.
1360 ENTRYPOINT is a function entry point where prologue starts.
1362 LIMIT_PC is a maximum possible end address of prologue (meaning address
1363 of first instruction after the prologue). It might also point to the middle
1364 of prologue if execution has been stopped by the breakpoint at this address
1365 - in this case debugger should analyze prologue only up to this address,
1366 because further instructions haven't been executed yet.
1368 Returns address of the first instruction after the prologue. */
1370 static CORE_ADDR
1371 arc_analyze_prologue (struct gdbarch *gdbarch, const CORE_ADDR entrypoint,
1372 const CORE_ADDR limit_pc, struct arc_frame_cache *cache)
1374 arc_debug_printf ("entrypoint=%s, limit_pc=%s",
1375 paddress (gdbarch, entrypoint),
1376 paddress (gdbarch, limit_pc));
1378 /* Prologue values. Only core registers can be stored. */
1379 pv_t regs[ARC_LAST_CORE_REGNUM + 1];
1380 for (int i = 0; i <= ARC_LAST_CORE_REGNUM; i++)
1381 regs[i] = pv_register (i, 0);
1382 pv_area stack (ARC_SP_REGNUM, gdbarch_addr_bit (gdbarch));
1384 CORE_ADDR current_prologue_end = entrypoint;
1386 /* Look at each instruction in the prologue. */
1387 while (current_prologue_end < limit_pc)
1389 struct arc_instruction insn;
1391 struct gdb_non_printing_memory_disassembler dis (gdbarch);
1392 arc_insn_decode (current_prologue_end, dis.disasm_info (),
1393 arc_delayed_print_insn, &insn);
1395 if (arc_debug)
1396 arc_insn_dump (insn);
1398 /* If this instruction is in the prologue, fields in the cache will be
1399 updated, and the saved registers mask may be updated. */
1400 if (!arc_is_in_prologue (gdbarch, insn, regs, &stack))
1402 /* Found an instruction that is not in the prologue. */
1403 arc_debug_printf ("End of prologue reached at address %s",
1404 paddress (gdbarch, insn.address));
1405 break;
1408 current_prologue_end = arc_insn_get_linear_next_pc (insn);
1411 if (cache != NULL)
1413 /* Figure out if it is a frame pointer or just a stack pointer. */
1414 if (pv_is_register (regs[ARC_FP_REGNUM], ARC_SP_REGNUM))
1416 cache->frame_base_reg = ARC_FP_REGNUM;
1417 cache->frame_base_offset = -regs[ARC_FP_REGNUM].k;
1419 else
1421 cache->frame_base_reg = ARC_SP_REGNUM;
1422 cache->frame_base_offset = -regs[ARC_SP_REGNUM].k;
1425 /* Assign offset from old SP to all saved registers. */
1426 for (int i = 0; i <= ARC_LAST_CORE_REGNUM; i++)
1428 CORE_ADDR offset;
1429 if (stack.find_reg (gdbarch, i, &offset))
1430 cache->saved_regs[i].set_addr (offset);
1434 return current_prologue_end;
1437 /* Estimated maximum prologue length in bytes. This should include:
1438 1) Store instruction for each callee-saved register (R25 - R13 + 1)
1439 2) Two instructions for FP
1440 3) One for BLINK
1441 4) Three subtract instructions for SP (for variadic args, for
1442 callee saved regs and for local vars) and assuming that those SUB use
1443 long-immediate (hence double length).
1444 5) Stores of arguments registers are considered part of prologue too
1445 (R7 - R1 + 1).
1446 This is quite an extreme case, because even with -O0 GCC will collapse first
1447 two SUBs into one and long immediate values are quite unlikely to appear in
1448 this case, but still better to overshoot a bit - prologue analysis will
1449 anyway stop at the first instruction that doesn't fit prologue, so this
1450 limit will be rarely reached. */
1452 const static int MAX_PROLOGUE_LENGTH
1453 = 4 * (ARC_R25_REGNUM - ARC_R13_REGNUM + 1 + 2 + 1 + 6
1454 + ARC_LAST_ARG_REGNUM - ARC_FIRST_ARG_REGNUM + 1);
1456 /* Implement the "skip_prologue" gdbarch method.
1458 Skip the prologue for the function at PC. This is done by checking from
1459 the line information read from the DWARF, if possible; otherwise, we scan
1460 the function prologue to find its end. */
1462 static CORE_ADDR
1463 arc_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
1465 arc_debug_printf ("pc = %s", paddress (gdbarch, pc));
1467 CORE_ADDR func_addr;
1468 const char *func_name;
1470 /* See what the symbol table says. */
1471 if (find_pc_partial_function (pc, &func_name, &func_addr, NULL))
1473 /* Found a function. */
1474 CORE_ADDR postprologue_pc
1475 = skip_prologue_using_sal (gdbarch, func_addr);
1477 if (postprologue_pc != 0)
1478 return std::max (pc, postprologue_pc);
1481 /* No prologue info in symbol table, have to analyze prologue. */
1483 /* Find an upper limit on the function prologue using the debug
1484 information. If there is no debug information about prologue end, then
1485 skip_prologue_using_sal will return 0. */
1486 CORE_ADDR limit_pc = skip_prologue_using_sal (gdbarch, pc);
1488 /* If there is no debug information at all, it is required to give some
1489 semi-arbitrary hard limit on amount of bytes to scan during prologue
1490 analysis. */
1491 if (limit_pc == 0)
1492 limit_pc = pc + MAX_PROLOGUE_LENGTH;
1494 /* Find the address of the first instruction after the prologue by scanning
1495 through it - no other information is needed, so pass NULL as a cache. */
1496 return arc_analyze_prologue (gdbarch, pc, limit_pc, NULL);
1499 /* Implement the "print_insn" gdbarch method.
1501 arc_get_disassembler () may return different functions depending on bfd
1502 type, so it is not possible to pass print_insn directly to
1503 set_gdbarch_print_insn (). Instead this wrapper function is used. It also
1504 may be used by other functions to get disassemble_info for address. It is
1505 important to note, that those print_insn from opcodes always print
1506 instruction to the stream specified in the INFO. If this is not desired,
1507 then either `print_insn` function in INFO should be set to some function
1508 that will not print, or `stream` should be different from standard
1509 gdb_stdlog. */
1512 arc_delayed_print_insn (bfd_vma addr, struct disassemble_info *info)
1514 /* Standard BFD "machine number" field allows libopcodes disassembler to
1515 distinguish ARC 600, 700 and v2 cores, however v2 encompasses both ARC EM
1516 and HS, which have some difference between. There are two ways to specify
1517 what is the target core:
1518 1) via the disassemble_info->disassembler_options;
1519 2) otherwise libopcodes will use private (architecture-specific) ELF
1520 header.
1522 Using disassembler_options is preferable, because it comes directly from
1523 GDBserver which scanned an actual ARC core identification info. However,
1524 not all GDBservers report core architecture, so as a fallback GDB still
1525 should support analysis of ELF header. The libopcodes disassembly code
1526 uses the section to find the BFD and the BFD to find the ELF header,
1527 therefore this function should set disassemble_info->section properly.
1529 disassembler_options was already set by non-target specific code with
1530 proper options obtained via gdbarch_disassembler_options ().
1532 This function might be called multiple times in a sequence, reusing same
1533 disassemble_info. */
1534 if ((info->disassembler_options == NULL) && (info->section == NULL))
1536 struct obj_section *s = find_pc_section (addr);
1537 if (s != NULL)
1538 info->section = s->the_bfd_section;
1541 return default_print_insn (addr, info);
1544 /* Baremetal breakpoint instructions.
1546 ARC supports both big- and little-endian. However, instructions for
1547 little-endian processors are encoded in the middle-endian: half-words are
1548 in big-endian, while bytes inside the half-words are in little-endian; data
1549 is represented in the "normal" little-endian. Big-endian processors treat
1550 data and code identically.
1552 Assuming the number 0x01020304, it will be presented this way:
1554 Address : N N+1 N+2 N+3
1555 little-endian : 0x04 0x03 0x02 0x01
1556 big-endian : 0x01 0x02 0x03 0x04
1557 ARC middle-endian : 0x02 0x01 0x04 0x03
1560 static const gdb_byte arc_brk_s_be[] = { 0x7f, 0xff };
1561 static const gdb_byte arc_brk_s_le[] = { 0xff, 0x7f };
1562 static const gdb_byte arc_brk_be[] = { 0x25, 0x6f, 0x00, 0x3f };
1563 static const gdb_byte arc_brk_le[] = { 0x6f, 0x25, 0x3f, 0x00 };
1565 /* For ARC ELF, breakpoint uses the 16-bit BRK_S instruction, which is 0x7fff
1566 (little endian) or 0xff7f (big endian). We used to insert BRK_S even
1567 instead of 32-bit instructions, which works mostly ok, unless breakpoint is
1568 inserted into delay slot instruction. In this case if branch is taken
1569 BLINK value will be set to address of instruction after delay slot, however
1570 if we replaced 32-bit instruction in delay slot with 16-bit long BRK_S,
1571 then BLINK value will have an invalid value - it will point to the address
1572 after the BRK_S (which was there at the moment of branch execution) while
1573 it should point to the address after the 32-bit long instruction. To avoid
1574 such issues this function disassembles instruction at target location and
1575 evaluates it value.
1577 ARC 600 supports only 16-bit BRK_S.
1579 NB: Baremetal GDB uses BRK[_S], while user-space GDB uses TRAP_S. BRK[_S]
1580 is much better because it doesn't commit unlike TRAP_S, so it can be set in
1581 delay slots; however it cannot be used in user-mode, hence usage of TRAP_S
1582 in GDB for user-space. */
1584 /* Implement the "breakpoint_kind_from_pc" gdbarch method. */
1586 static int
1587 arc_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
1589 size_t length_with_limm = gdb_insn_length (gdbarch, *pcptr);
1591 /* Replace 16-bit instruction with BRK_S, replace 32-bit instructions with
1592 BRK. LIMM is part of instruction length, so it can be either 4 or 8
1593 bytes for 32-bit instructions. */
1594 if ((length_with_limm == 4 || length_with_limm == 8)
1595 && !arc_mach_is_arc600 (gdbarch))
1596 return sizeof (arc_brk_le);
1597 else
1598 return sizeof (arc_brk_s_le);
1601 /* Implement the "sw_breakpoint_from_kind" gdbarch method. */
1603 static const gdb_byte *
1604 arc_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
1606 gdb_assert (kind == 2 || kind == 4);
1607 *size = kind;
1609 if (kind == sizeof (arc_brk_le))
1611 return ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1612 ? arc_brk_be
1613 : arc_brk_le);
1615 else
1617 return ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
1618 ? arc_brk_s_be
1619 : arc_brk_s_le);
1623 /* Implement the "frame_align" gdbarch method. */
1625 static CORE_ADDR
1626 arc_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
1628 return align_down (sp, 4);
1631 /* Dump the frame info. Used for internal debugging only. */
1633 static void
1634 arc_print_frame_cache (struct gdbarch *gdbarch, const char *message,
1635 struct arc_frame_cache *cache, int addresses_known)
1637 arc_debug_printf ("frame_info %s", message);
1638 arc_debug_printf ("prev_sp = %s", paddress (gdbarch, cache->prev_sp));
1639 arc_debug_printf ("frame_base_reg = %i", cache->frame_base_reg);
1640 arc_debug_printf ("frame_base_offset = %s",
1641 plongest (cache->frame_base_offset));
1643 for (int i = 0; i <= ARC_BLINK_REGNUM; i++)
1645 if (cache->saved_regs[i].is_addr ())
1646 arc_debug_printf ("saved register %s at %s %s",
1647 gdbarch_register_name (gdbarch, i),
1648 (addresses_known) ? "address" : "offset",
1649 paddress (gdbarch, cache->saved_regs[i].addr ()));
1653 /* Frame unwinder for normal frames. */
1655 static struct arc_frame_cache *
1656 arc_make_frame_cache (const frame_info_ptr &this_frame)
1658 arc_debug_printf ("called");
1660 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1662 CORE_ADDR block_addr = get_frame_address_in_block (this_frame);
1663 CORE_ADDR entrypoint, prologue_end;
1664 if (find_pc_partial_function (block_addr, NULL, &entrypoint, &prologue_end))
1666 struct symtab_and_line sal = find_pc_line (entrypoint, 0);
1667 CORE_ADDR prev_pc = get_frame_pc (this_frame);
1668 if (sal.line == 0)
1669 /* No line info so use current PC. */
1670 prologue_end = prev_pc;
1671 else if (sal.end < prologue_end)
1672 /* The next line begins after the function end. */
1673 prologue_end = sal.end;
1675 prologue_end = std::min (prologue_end, prev_pc);
1677 else
1679 /* If find_pc_partial_function returned nothing then there is no symbol
1680 information at all for this PC. Currently it is assumed in this case
1681 that current PC is entrypoint to function and try to construct the
1682 frame from that. This is, probably, suboptimal, for example ARM
1683 assumes in this case that program is inside the normal frame (with
1684 frame pointer). ARC, perhaps, should try to do the same. */
1685 entrypoint = get_frame_register_unsigned (this_frame,
1686 gdbarch_pc_regnum (gdbarch));
1687 prologue_end = entrypoint + MAX_PROLOGUE_LENGTH;
1690 /* Allocate new frame cache instance and space for saved register info.
1691 FRAME_OBSTACK_ZALLOC will initialize fields to zeroes. */
1692 struct arc_frame_cache *cache
1693 = FRAME_OBSTACK_ZALLOC (struct arc_frame_cache);
1694 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
1696 arc_analyze_prologue (gdbarch, entrypoint, prologue_end, cache);
1698 if (arc_debug)
1699 arc_print_frame_cache (gdbarch, "after prologue", cache, false);
1701 CORE_ADDR unwound_fb = get_frame_register_unsigned (this_frame,
1702 cache->frame_base_reg);
1703 if (unwound_fb == 0)
1704 return cache;
1705 cache->prev_sp = unwound_fb + cache->frame_base_offset;
1707 for (int i = 0; i <= ARC_LAST_CORE_REGNUM; i++)
1709 if (cache->saved_regs[i].is_addr ())
1710 cache->saved_regs[i].set_addr (cache->saved_regs[i].addr ()
1711 + cache->prev_sp);
1714 if (arc_debug)
1715 arc_print_frame_cache (gdbarch, "after previous SP found", cache, true);
1717 return cache;
1720 /* Implement the "this_id" frame_unwind method. */
1722 static void
1723 arc_frame_this_id (const frame_info_ptr &this_frame, void **this_cache,
1724 struct frame_id *this_id)
1726 arc_debug_printf ("called");
1728 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1730 if (*this_cache == NULL)
1731 *this_cache = arc_make_frame_cache (this_frame);
1732 struct arc_frame_cache *cache = (struct arc_frame_cache *) (*this_cache);
1734 CORE_ADDR stack_addr = cache->prev_sp;
1736 /* There are 4 possible situation which decide how frame_id->code_addr is
1737 evaluated:
1739 1) Function is compiled with option -g. Then frame_id will be created
1740 in dwarf_* function and not in this function. NB: even if target
1741 binary is compiled with -g, some std functions like __start and _init
1742 are not, so they still will follow one of the following choices.
1744 2) Function is compiled without -g and binary hasn't been stripped in
1745 any way. In this case GDB still has enough information to evaluate
1746 frame code_addr properly. This case is covered by call to
1747 get_frame_func ().
1749 3) Binary has been striped with option -g (strip debug symbols). In
1750 this case there is still enough symbols for get_frame_func () to work
1751 properly, so this case is also covered by it.
1753 4) Binary has been striped with option -s (strip all symbols). In this
1754 case GDB cannot get function start address properly, so we return current
1755 PC value instead.
1757 CORE_ADDR code_addr = get_frame_func (this_frame);
1758 if (code_addr == 0)
1759 code_addr = get_frame_register_unsigned (this_frame,
1760 gdbarch_pc_regnum (gdbarch));
1762 *this_id = frame_id_build (stack_addr, code_addr);
1765 /* Implement the "prev_register" frame_unwind method. */
1767 static struct value *
1768 arc_frame_prev_register (const frame_info_ptr &this_frame,
1769 void **this_cache, int regnum)
1771 if (*this_cache == NULL)
1772 *this_cache = arc_make_frame_cache (this_frame);
1773 struct arc_frame_cache *cache = (struct arc_frame_cache *) (*this_cache);
1775 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1777 /* If we are asked to unwind the PC, then we need to return BLINK instead:
1778 the saved value of PC points into this frame's function's prologue, not
1779 the next frame's function's resume location. */
1780 if (regnum == gdbarch_pc_regnum (gdbarch))
1781 regnum = ARC_BLINK_REGNUM;
1783 /* SP is a special case - we should return prev_sp, because
1784 trad_frame_get_prev_register will return _current_ SP value.
1785 Alternatively we could have stored cache->prev_sp in the cache->saved
1786 regs, but here we follow the lead of AArch64, ARM and Xtensa and will
1787 leave that logic in this function, instead of prologue analyzers. That I
1788 think is a bit more clear as `saved_regs` should contain saved regs, not
1789 computable.
1791 Because value has been computed, "got_constant" should be used, so that
1792 returned value will be a "not_lval" - immutable. */
1794 if (regnum == gdbarch_sp_regnum (gdbarch))
1795 return frame_unwind_got_constant (this_frame, regnum, cache->prev_sp);
1797 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
1800 /* Implement the "init_reg" dwarf2_frame method. */
1802 static void
1803 arc_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
1804 struct dwarf2_frame_state_reg *reg,
1805 const frame_info_ptr &info)
1807 if (regnum == gdbarch_pc_regnum (gdbarch))
1808 /* The return address column. */
1809 reg->how = DWARF2_FRAME_REG_RA;
1810 else if (regnum == gdbarch_sp_regnum (gdbarch))
1811 /* The call frame address. */
1812 reg->how = DWARF2_FRAME_REG_CFA;
1815 /* Signal trampoline frame unwinder. Allows frame unwinding to happen
1816 from within signal handlers. */
1818 static struct arc_frame_cache *
1819 arc_make_sigtramp_frame_cache (const frame_info_ptr &this_frame)
1821 arc_debug_printf ("called");
1823 gdbarch *arch = get_frame_arch (this_frame);
1824 arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
1826 /* Allocate new frame cache instance and space for saved register info. */
1827 struct arc_frame_cache *cache = FRAME_OBSTACK_ZALLOC (struct arc_frame_cache);
1828 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
1830 /* Get the stack pointer and use it as the frame base. */
1831 cache->prev_sp = arc_frame_base_address (this_frame, NULL);
1833 /* If the ARC-private target-dependent info doesn't have a table of
1834 offsets of saved register contents within an OS signal context
1835 structure, then there is nothing to analyze. */
1836 if (tdep->sc_reg_offset == NULL)
1837 return cache;
1839 /* Find the address of the sigcontext structure. */
1840 CORE_ADDR addr = tdep->sigcontext_addr (this_frame);
1842 /* For each register, if its contents have been saved within the
1843 sigcontext structure, determine the address of those contents. */
1844 gdb_assert (tdep->sc_num_regs <= (ARC_LAST_REGNUM + 1));
1845 for (int i = 0; i < tdep->sc_num_regs; i++)
1847 if (tdep->sc_reg_offset[i] != ARC_OFFSET_NO_REGISTER)
1848 cache->saved_regs[i].set_addr (addr + tdep->sc_reg_offset[i]);
1851 return cache;
1854 /* Implement the "this_id" frame_unwind method for signal trampoline
1855 frames. */
1857 static void
1858 arc_sigtramp_frame_this_id (const frame_info_ptr &this_frame,
1859 void **this_cache, struct frame_id *this_id)
1861 arc_debug_printf ("called");
1863 if (*this_cache == NULL)
1864 *this_cache = arc_make_sigtramp_frame_cache (this_frame);
1866 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1867 struct arc_frame_cache *cache = (struct arc_frame_cache *) *this_cache;
1868 CORE_ADDR stack_addr = cache->prev_sp;
1869 CORE_ADDR code_addr
1870 = get_frame_register_unsigned (this_frame, gdbarch_pc_regnum (gdbarch));
1871 *this_id = frame_id_build (stack_addr, code_addr);
1874 /* Get a register from a signal handler frame. */
1876 static struct value *
1877 arc_sigtramp_frame_prev_register (const frame_info_ptr &this_frame,
1878 void **this_cache, int regnum)
1880 arc_debug_printf ("regnum = %d", regnum);
1882 /* Make sure we've initialized the cache. */
1883 if (*this_cache == NULL)
1884 *this_cache = arc_make_sigtramp_frame_cache (this_frame);
1886 struct arc_frame_cache *cache = (struct arc_frame_cache *) *this_cache;
1887 return trad_frame_get_prev_register (this_frame, cache->saved_regs, regnum);
1890 /* Frame sniffer for signal handler frame. Only recognize a frame if we
1891 have a sigcontext_addr handler in the target dependency. */
1893 static int
1894 arc_sigtramp_frame_sniffer (const struct frame_unwind *self,
1895 const frame_info_ptr &this_frame,
1896 void **this_cache)
1898 arc_debug_printf ("called");
1900 gdbarch *arch = get_frame_arch (this_frame);
1901 arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (arch);
1903 /* If we have a sigcontext_addr handler, then just return 1 (same as the
1904 "default_frame_sniffer ()"). */
1905 return (tdep->sigcontext_addr != NULL && tdep->is_sigtramp != NULL
1906 && tdep->is_sigtramp (this_frame));
1909 /* Structure defining the ARC ordinary frame unwind functions. Since we are
1910 the fallback unwinder, we use the default frame sniffer, which always
1911 accepts the frame. */
1913 static const struct frame_unwind arc_frame_unwind = {
1914 "arc prologue",
1915 NORMAL_FRAME,
1916 default_frame_unwind_stop_reason,
1917 arc_frame_this_id,
1918 arc_frame_prev_register,
1919 NULL,
1920 default_frame_sniffer,
1921 NULL,
1922 NULL
1925 /* Structure defining the ARC signal frame unwind functions. Custom
1926 sniffer is used, because this frame must be accepted only in the right
1927 context. */
1929 static const struct frame_unwind arc_sigtramp_frame_unwind = {
1930 "arc sigtramp",
1931 SIGTRAMP_FRAME,
1932 default_frame_unwind_stop_reason,
1933 arc_sigtramp_frame_this_id,
1934 arc_sigtramp_frame_prev_register,
1935 NULL,
1936 arc_sigtramp_frame_sniffer,
1937 NULL,
1938 NULL
1942 static const struct frame_base arc_normal_base = {
1943 &arc_frame_unwind,
1944 arc_frame_base_address,
1945 arc_frame_base_address,
1946 arc_frame_base_address
1949 static enum arc_isa
1950 mach_type_to_arc_isa (const unsigned long mach)
1952 switch (mach)
1954 case bfd_mach_arc_arc600:
1955 case bfd_mach_arc_arc601:
1956 case bfd_mach_arc_arc700:
1957 return ARC_ISA_ARCV1;
1958 case bfd_mach_arc_arcv2:
1959 return ARC_ISA_ARCV2;
1960 default:
1961 internal_error (_("unknown machine id %lu"), mach);
1965 /* See arc-tdep.h. */
1967 arc_arch_features
1968 arc_arch_features_create (const bfd *abfd, const unsigned long mach)
1970 /* Use 4 as a fallback value. */
1971 int reg_size = 4;
1973 /* Try to guess the features parameters by looking at the binary to be
1974 executed. If the user is providing a binary that does not match the
1975 target, then tough luck. This is the last effort to makes sense of
1976 what's going on. */
1977 if (abfd != nullptr && bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1979 unsigned char eclass = elf_elfheader (abfd)->e_ident[EI_CLASS];
1981 if (eclass == ELFCLASS32)
1982 reg_size = 4;
1983 else if (eclass == ELFCLASS64)
1984 reg_size = 8;
1985 else
1986 internal_error (_("unknown ELF header class %d"), eclass);
1989 /* MACH from a bfd_arch_info struct is used here. It should be a safe
1990 bet, as it looks like the struct is always initialized even when we
1991 don't pass any elf file to GDB at all (it uses default arch in that
1992 case). */
1993 arc_isa isa = mach_type_to_arc_isa (mach);
1995 return arc_arch_features (reg_size, isa);
1998 /* Look for obsolete core feature names in TDESC. */
2000 static const struct tdesc_feature *
2001 find_obsolete_core_names (const struct target_desc *tdesc)
2003 const struct tdesc_feature *feat = nullptr;
2005 feat = tdesc_find_feature (tdesc, ARC_CORE_V1_OBSOLETE_FEATURE_NAME);
2007 if (feat == nullptr)
2008 feat = tdesc_find_feature (tdesc, ARC_CORE_V2_OBSOLETE_FEATURE_NAME);
2010 if (feat == nullptr)
2011 feat = tdesc_find_feature
2012 (tdesc, ARC_CORE_V2_REDUCED_OBSOLETE_FEATURE_NAME);
2014 return feat;
2017 /* Look for obsolete aux feature names in TDESC. */
2019 static const struct tdesc_feature *
2020 find_obsolete_aux_names (const struct target_desc *tdesc)
2022 return tdesc_find_feature (tdesc, ARC_AUX_OBSOLETE_FEATURE_NAME);
2025 /* Based on the MACH value, determines which core register features set
2026 must be used. */
2028 static arc_register_feature *
2029 determine_core_reg_feature_set (const unsigned long mach)
2031 switch (mach_type_to_arc_isa (mach))
2033 case ARC_ISA_ARCV1:
2034 return &arc_v1_core_reg_feature;
2035 case ARC_ISA_ARCV2:
2036 return &arc_v2_core_reg_feature;
2037 default:
2038 gdb_assert_not_reached
2039 ("Unknown machine type to determine the core feature set.");
2043 /* At the moment, there is only 1 auxiliary register features set.
2044 This is a place holder for future extendability. */
2046 static const arc_register_feature *
2047 determine_aux_reg_feature_set ()
2049 return &arc_common_aux_reg_feature;
2052 /* Update accumulator register names (ACCH/ACCL) for r58 and r59 in the
2053 register sets. The endianness determines the assignment:
2055 ,------.------.
2056 | acch | accl |
2057 ,----|------+------|
2058 | LE | r59 | r58 |
2059 | BE | r58 | r59 |
2060 `----^------^------' */
2062 static void
2063 arc_update_acc_reg_names (const int byte_order)
2065 const char *r58_alias
2066 = byte_order == BFD_ENDIAN_LITTLE ? "accl" : "acch";
2067 const char *r59_alias
2068 = byte_order == BFD_ENDIAN_LITTLE ? "acch" : "accl";
2070 /* Subscript 1 must be OK because those registers have 2 names. */
2071 arc_v1_core_reg_feature.registers[ARC_R58_REGNUM].names[1] = r58_alias;
2072 arc_v1_core_reg_feature.registers[ARC_R59_REGNUM].names[1] = r59_alias;
2073 arc_v2_core_reg_feature.registers[ARC_R58_REGNUM].names[1] = r58_alias;
2074 arc_v2_core_reg_feature.registers[ARC_R59_REGNUM].names[1] = r59_alias;
2077 /* Go through all the registers in REG_SET and check if they exist
2078 in FEATURE. The TDESC_DATA is updated with the register number
2079 in REG_SET if it is found in the feature. If a required register
2080 is not found, this function returns false. */
2082 static bool
2083 arc_check_tdesc_feature (struct tdesc_arch_data *tdesc_data,
2084 const struct tdesc_feature *feature,
2085 const struct arc_register_feature *reg_set)
2087 for (const auto &reg : reg_set->registers)
2089 bool found = false;
2091 for (const char *name : reg.names)
2093 found
2094 = tdesc_numbered_register (feature, tdesc_data, reg.regnum, name);
2096 if (found)
2097 break;
2100 if (!found && reg.required_p)
2102 std::ostringstream reg_names;
2103 for (std::size_t i = 0; i < reg.names.size(); ++i)
2105 if (i == 0)
2106 reg_names << "'" << reg.names[0] << "'";
2107 else
2108 reg_names << " or '" << reg.names[0] << "'";
2110 arc_print (_("Error: Cannot find required register(s) %s "
2111 "in feature '%s'.\n"), reg_names.str ().c_str (),
2112 feature->name.c_str ());
2113 return false;
2117 return true;
2120 /* Check for the existence of "lp_start" and "lp_end" in target description.
2121 If both are present, assume there is hardware loop support in the target.
2122 This can be improved by looking into "lpc_size" field of "isa_config"
2123 auxiliary register. */
2125 static bool
2126 arc_check_for_hw_loops (const struct target_desc *tdesc,
2127 struct tdesc_arch_data *data)
2129 const auto feature_aux = tdesc_find_feature (tdesc, ARC_AUX_FEATURE_NAME);
2130 const auto aux_regset = determine_aux_reg_feature_set ();
2132 if (feature_aux == nullptr)
2133 return false;
2135 bool hw_loop_p = false;
2136 const auto lp_start_name =
2137 aux_regset->registers[ARC_LP_START_REGNUM - ARC_FIRST_AUX_REGNUM].names[0];
2138 const auto lp_end_name =
2139 aux_regset->registers[ARC_LP_END_REGNUM - ARC_FIRST_AUX_REGNUM].names[0];
2141 hw_loop_p = tdesc_numbered_register (feature_aux, data,
2142 ARC_LP_START_REGNUM, lp_start_name);
2143 hw_loop_p &= tdesc_numbered_register (feature_aux, data,
2144 ARC_LP_END_REGNUM, lp_end_name);
2146 return hw_loop_p;
2149 /* Initialize target description for the ARC.
2151 Returns true if input TDESC was valid and in this case it will assign TDESC
2152 and TDESC_DATA output parameters. */
2154 static bool
2155 arc_tdesc_init (struct gdbarch_info info, const struct target_desc **tdesc,
2156 tdesc_arch_data_up *tdesc_data)
2158 const struct target_desc *tdesc_loc = info.target_desc;
2159 arc_debug_printf ("Target description initialization.");
2161 /* If target doesn't provide a description, use the default ones. */
2162 if (!tdesc_has_registers (tdesc_loc))
2164 arc_arch_features features
2165 = arc_arch_features_create (info.abfd,
2166 info.bfd_arch_info->mach);
2167 tdesc_loc = arc_lookup_target_description (features);
2169 gdb_assert (tdesc_loc != nullptr);
2171 arc_debug_printf ("Have got a target description");
2173 const struct tdesc_feature *feature_core
2174 = tdesc_find_feature (tdesc_loc, ARC_CORE_FEATURE_NAME);
2175 const struct tdesc_feature *feature_aux
2176 = tdesc_find_feature (tdesc_loc, ARC_AUX_FEATURE_NAME);
2178 /* Maybe there still is a chance to salvage the input. */
2179 if (feature_core == nullptr)
2180 feature_core = find_obsolete_core_names (tdesc_loc);
2181 if (feature_aux == nullptr)
2182 feature_aux = find_obsolete_aux_names (tdesc_loc);
2184 if (feature_core == nullptr)
2186 arc_print (_("Error: Cannot find required feature '%s' in supplied "
2187 "target description.\n"), ARC_CORE_FEATURE_NAME);
2188 return false;
2191 if (feature_aux == nullptr)
2193 arc_print (_("Error: Cannot find required feature '%s' in supplied "
2194 "target description.\n"), ARC_AUX_FEATURE_NAME);
2195 return false;
2198 const arc_register_feature *arc_core_reg_feature
2199 = determine_core_reg_feature_set (info.bfd_arch_info->mach);
2200 const arc_register_feature *arc_aux_reg_feature
2201 = determine_aux_reg_feature_set ();
2203 tdesc_arch_data_up tdesc_data_loc = tdesc_data_alloc ();
2205 arc_update_acc_reg_names (info.byte_order);
2207 bool valid_p = arc_check_tdesc_feature (tdesc_data_loc.get (),
2208 feature_core,
2209 arc_core_reg_feature);
2211 valid_p &= arc_check_tdesc_feature (tdesc_data_loc.get (),
2212 feature_aux,
2213 arc_aux_reg_feature);
2215 if (!valid_p)
2217 arc_debug_printf ("Target description is not valid");
2218 return false;
2221 *tdesc = tdesc_loc;
2222 *tdesc_data = std::move (tdesc_data_loc);
2224 return true;
2227 /* Implement the type_align gdbarch function. */
2229 static ULONGEST
2230 arc_type_align (struct gdbarch *gdbarch, struct type *type)
2232 switch (type->code ())
2234 case TYPE_CODE_PTR:
2235 case TYPE_CODE_FUNC:
2236 case TYPE_CODE_FLAGS:
2237 case TYPE_CODE_INT:
2238 case TYPE_CODE_RANGE:
2239 case TYPE_CODE_FLT:
2240 case TYPE_CODE_ENUM:
2241 case TYPE_CODE_REF:
2242 case TYPE_CODE_RVALUE_REF:
2243 case TYPE_CODE_CHAR:
2244 case TYPE_CODE_BOOL:
2245 case TYPE_CODE_DECFLOAT:
2246 case TYPE_CODE_METHODPTR:
2247 case TYPE_CODE_MEMBERPTR:
2248 type = check_typedef (type);
2249 return std::min<ULONGEST> (4, type->length ());
2250 default:
2251 return 0;
2255 /* Implement the "init" gdbarch method. */
2257 static struct gdbarch *
2258 arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2260 const struct target_desc *tdesc;
2261 tdesc_arch_data_up tdesc_data;
2263 arc_debug_printf ("Architecture initialization.");
2265 if (!arc_tdesc_init (info, &tdesc, &tdesc_data))
2266 return nullptr;
2268 /* Allocate the ARC-private target-dependent information structure, and the
2269 GDB target-independent information structure. */
2270 gdbarch *gdbarch
2271 = gdbarch_alloc (&info, gdbarch_tdep_up (new arc_gdbarch_tdep));
2272 arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
2273 tdep->jb_pc = -1; /* No longjmp support by default. */
2274 tdep->has_hw_loops = arc_check_for_hw_loops (tdesc, tdesc_data.get ());
2276 /* Data types. */
2277 set_gdbarch_short_bit (gdbarch, 16);
2278 set_gdbarch_int_bit (gdbarch, 32);
2279 set_gdbarch_long_bit (gdbarch, 32);
2280 set_gdbarch_long_long_bit (gdbarch, 64);
2281 set_gdbarch_type_align (gdbarch, arc_type_align);
2282 set_gdbarch_float_bit (gdbarch, 32);
2283 set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
2284 set_gdbarch_double_bit (gdbarch, 64);
2285 set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
2286 set_gdbarch_ptr_bit (gdbarch, 32);
2287 set_gdbarch_addr_bit (gdbarch, 32);
2288 set_gdbarch_char_signed (gdbarch, 0);
2290 set_gdbarch_write_pc (gdbarch, arc_write_pc);
2292 set_gdbarch_virtual_frame_pointer (gdbarch, arc_virtual_frame_pointer);
2294 /* tdesc_use_registers expects gdbarch_num_regs to return number of registers
2295 parsed by gdbarch_init, and then it will add all of the remaining
2296 registers and will increase number of registers. */
2297 set_gdbarch_num_regs (gdbarch, ARC_LAST_REGNUM + 1);
2298 set_gdbarch_num_pseudo_regs (gdbarch, 0);
2299 set_gdbarch_sp_regnum (gdbarch, ARC_SP_REGNUM);
2300 set_gdbarch_pc_regnum (gdbarch, ARC_PC_REGNUM);
2301 set_gdbarch_ps_regnum (gdbarch, ARC_STATUS32_REGNUM);
2302 set_gdbarch_fp0_regnum (gdbarch, -1); /* No FPU registers. */
2304 set_gdbarch_push_dummy_call (gdbarch, arc_push_dummy_call);
2305 set_gdbarch_push_dummy_code (gdbarch, arc_push_dummy_code);
2307 set_gdbarch_cannot_fetch_register (gdbarch, arc_cannot_fetch_register);
2308 set_gdbarch_cannot_store_register (gdbarch, arc_cannot_store_register);
2310 set_gdbarch_believe_pcc_promotion (gdbarch, 1);
2312 set_gdbarch_return_value (gdbarch, arc_return_value);
2314 set_gdbarch_skip_prologue (gdbarch, arc_skip_prologue);
2315 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
2317 set_gdbarch_breakpoint_kind_from_pc (gdbarch, arc_breakpoint_kind_from_pc);
2318 set_gdbarch_sw_breakpoint_from_kind (gdbarch, arc_sw_breakpoint_from_kind);
2320 /* On ARC 600 BRK_S instruction advances PC, unlike other ARC cores. */
2321 if (!arc_mach_is_arc600 (gdbarch))
2322 set_gdbarch_decr_pc_after_break (gdbarch, 0);
2323 else
2324 set_gdbarch_decr_pc_after_break (gdbarch, 2);
2326 set_gdbarch_frame_align (gdbarch, arc_frame_align);
2328 set_gdbarch_print_insn (gdbarch, arc_delayed_print_insn);
2330 set_gdbarch_cannot_step_breakpoint (gdbarch, 1);
2332 /* "nonsteppable" watchpoint means that watchpoint triggers before
2333 instruction is committed, therefore it is required to remove watchpoint
2334 to step though instruction that triggers it. ARC watchpoints trigger
2335 only after instruction is committed, thus there is no need to remove
2336 them. In fact on ARC watchpoint for memory writes may trigger with more
2337 significant delay, like one or two instructions, depending on type of
2338 memory where write is performed (CCM or external) and next instruction
2339 after the memory write. */
2340 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 0);
2342 /* This doesn't include possible long-immediate value. */
2343 set_gdbarch_max_insn_length (gdbarch, 4);
2345 /* Frame unwinders and sniffers. */
2346 dwarf2_frame_set_init_reg (gdbarch, arc_dwarf2_frame_init_reg);
2347 dwarf2_append_unwinders (gdbarch);
2348 frame_unwind_append_unwinder (gdbarch, &arc_sigtramp_frame_unwind);
2349 frame_unwind_append_unwinder (gdbarch, &arc_frame_unwind);
2350 frame_base_set_default (gdbarch, &arc_normal_base);
2352 /* Setup stuff specific to a particular environment (baremetal or Linux).
2353 It can override functions set earlier. */
2354 gdbarch_init_osabi (info, gdbarch);
2356 if (tdep->jb_pc >= 0)
2357 set_gdbarch_get_longjmp_target (gdbarch, arc_get_longjmp_target);
2359 /* Disassembler options. Enforce CPU if it was specified in XML target
2360 description, otherwise use default method of determining CPU (ELF private
2361 header). */
2362 if (info.target_desc != NULL)
2364 const struct bfd_arch_info *tdesc_arch
2365 = tdesc_architecture (info.target_desc);
2366 if (tdesc_arch != NULL)
2368 /* FIXME: It is not really good to change disassembler options
2369 behind the scene, because that might override options
2370 specified by the user. However as of now ARC doesn't support
2371 `set disassembler-options' hence this code is the only place
2372 where options are changed. It also changes options for all
2373 existing gdbarches, which also can be problematic, if
2374 arc_gdbarch_init will start reusing existing gdbarch
2375 instances. */
2376 /* Target description specifies a BFD architecture, which is
2377 different from ARC cpu, as accepted by disassembler (and most
2378 other ARC tools), because cpu values are much more fine grained -
2379 there can be multiple cpu values per single BFD architecture. As
2380 a result this code should translate architecture to some cpu
2381 value. Since there is no info on exact cpu configuration, it is
2382 best to use the most feature-rich CPU, so that disassembler will
2383 recognize all instructions available to the specified
2384 architecture. */
2385 switch (tdesc_arch->mach)
2387 case bfd_mach_arc_arc601:
2388 arc_disassembler_options = "cpu=arc601";
2389 break;
2390 case bfd_mach_arc_arc600:
2391 arc_disassembler_options = "cpu=arc600";
2392 break;
2393 case bfd_mach_arc_arc700:
2394 arc_disassembler_options = "cpu=arc700";
2395 break;
2396 case bfd_mach_arc_arcv2:
2397 /* Machine arcv2 has three arches: ARCv2, EM and HS; where ARCv2
2398 is treated as EM. */
2399 if (arc_arch_is_hs (tdesc_arch))
2400 arc_disassembler_options = "cpu=hs38_linux";
2401 else
2402 arc_disassembler_options = "cpu=em4_fpuda";
2403 break;
2404 default:
2405 arc_disassembler_options = "";
2406 break;
2411 set_gdbarch_disassembler_options (gdbarch, &arc_disassembler_options);
2412 set_gdbarch_valid_disassembler_options (gdbarch,
2413 disassembler_options_arc ());
2415 tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data));
2417 return gdbarch;
2420 /* Implement the "dump_tdep" gdbarch method. */
2422 static void
2423 arc_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
2425 arc_gdbarch_tdep *tdep = gdbarch_tdep<arc_gdbarch_tdep> (gdbarch);
2427 gdb_printf (file, "arc_dump_tdep: jb_pc = %i\n", tdep->jb_pc);
2429 gdb_printf (file, "arc_dump_tdep: is_sigtramp = <%s>\n",
2430 host_address_to_string (tdep->is_sigtramp));
2431 gdb_printf (file, "arc_dump_tdep: sigcontext_addr = <%s>\n",
2432 host_address_to_string (tdep->sigcontext_addr));
2433 gdb_printf (file, "arc_dump_tdep: sc_reg_offset = <%s>\n",
2434 host_address_to_string (tdep->sc_reg_offset));
2435 gdb_printf (file, "arc_dump_tdep: sc_num_regs = %d\n",
2436 tdep->sc_num_regs);
2439 /* This command accepts single argument - address of instruction to
2440 disassemble. */
2442 static void
2443 dump_arc_instruction_command (const char *args, int from_tty)
2445 struct value *val;
2446 if (args != NULL && strlen (args) > 0)
2447 val = parse_expression (args)->evaluate ();
2448 else
2449 val = access_value_history (0);
2450 val->record_latest ();
2452 CORE_ADDR address = value_as_address (val);
2453 struct arc_instruction insn;
2454 gdb_non_printing_memory_disassembler dis (current_inferior ()->arch ());
2455 arc_insn_decode (address, dis.disasm_info (), arc_delayed_print_insn, &insn);
2456 arc_insn_dump (insn);
2459 void _initialize_arc_tdep ();
2460 void
2461 _initialize_arc_tdep ()
2463 gdbarch_register (bfd_arch_arc, arc_gdbarch_init, arc_dump_tdep);
2465 /* Register ARC-specific commands with gdb. */
2467 /* Add root prefix command for "maintenance print arc" commands. */
2468 add_basic_prefix_cmd ("arc", class_maintenance,
2469 _("ARC-specific maintenance commands for printing GDB "
2470 "internal state."),
2471 &maintenance_print_arc_list,
2472 0, &maintenanceprintlist);
2474 add_cmd ("arc-instruction", class_maintenance,
2475 dump_arc_instruction_command,
2476 _("Dump arc_instruction structure for specified address."),
2477 &maintenance_print_arc_list);
2479 /* Debug internals for ARC GDB. */
2480 add_setshow_boolean_cmd ("arc", class_maintenance,
2481 &arc_debug,
2482 _("Set ARC specific debugging."),
2483 _("Show ARC specific debugging."),
2484 _("When set, ARC specific debugging is enabled."),
2485 NULL, NULL, &setdebuglist, &showdebuglist);