Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdb / microblaze-tdep.c
CommitLineData
2d1c1221
ME
1/* Target-dependent code for Xilinx MicroBlaze.
2
3666a048 3 Copyright (C) 2009-2021 Free Software Foundation, Inc.
2d1c1221
ME
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "defs.h"
21#include "arch-utils.h"
22#include "dis-asm.h"
23#include "frame.h"
24#include "trad-frame.h"
25#include "symtab.h"
26#include "value.h"
27#include "gdbcmd.h"
28#include "breakpoint.h"
29#include "inferior.h"
30#include "regcache.h"
31#include "target.h"
2d1c1221
ME
32#include "frame-base.h"
33#include "frame-unwind.h"
82ca8957 34#include "dwarf2/frame.h"
2d1c1221 35#include "osabi.h"
2d1c1221 36#include "target-descriptions.h"
f16f7b7c
TT
37#include "opcodes/microblaze-opcm.h"
38#include "opcodes/microblaze-dis.h"
2d1c1221 39#include "microblaze-tdep.h"
164224e9
ME
40#include "remote.h"
41
42#include "features/microblaze-with-stack-protect.c"
43#include "features/microblaze.c"
2d1c1221
ME
44\f
45/* Instruction macros used for analyzing the prologue. */
46/* This set of instruction macros need to be changed whenever the
47 prologue generated by the compiler could have more instructions or
48 different type of instructions.
49 This set also needs to be verified if it is complete. */
50#define IS_RETURN(op) (op == rtsd || op == rtid)
51#define IS_UPDATE_SP(op, rd, ra) \
025bb325 52 ((op == addik || op == addi) && rd == REG_SP && ra == REG_SP)
2d1c1221 53#define IS_SPILL_SP(op, rd, ra) \
025bb325 54 ((op == swi || op == sw) && rd == REG_SP && ra == REG_SP)
2d1c1221 55#define IS_SPILL_REG(op, rd, ra) \
025bb325 56 ((op == swi || op == sw) && rd != REG_SP && ra == REG_SP)
2d1c1221 57#define IS_ALSO_SPILL_REG(op, rd, ra, rb) \
025bb325 58 ((op == swi || op == sw) && rd != REG_SP && ra == 0 && rb == REG_SP)
2d1c1221 59#define IS_SETUP_FP(op, ra, rb) \
025bb325 60 ((op == add || op == addik || op == addk) && ra == REG_SP && rb == 0)
2d1c1221 61#define IS_SPILL_REG_FP(op, rd, ra, fpregnum) \
025bb325 62 ((op == swi || op == sw) && rd != REG_SP && ra == fpregnum && ra != 0)
2d1c1221 63#define IS_SAVE_HIDDEN_PTR(op, rd, ra, rb) \
025bb325 64 ((op == add || op == addik) && ra == MICROBLAZE_FIRST_ARGREG && rb == 0)
2d1c1221 65
2d1c1221
ME
66/* The registers of the Xilinx microblaze processor. */
67
27087b7f 68static const char * const microblaze_register_names[] =
2d1c1221
ME
69{
70 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
71 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
72 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
73 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
74 "rpc", "rmsr", "rear", "resr", "rfsr", "rbtr",
75 "rpvr0", "rpvr1", "rpvr2", "rpvr3", "rpvr4", "rpvr5", "rpvr6",
76 "rpvr7", "rpvr8", "rpvr9", "rpvr10", "rpvr11",
164224e9
ME
77 "redr", "rpid", "rzpr", "rtlbx", "rtlbsx", "rtlblo", "rtlbhi",
78 "rslr", "rshr"
2d1c1221
ME
79};
80
81#define MICROBLAZE_NUM_REGS ARRAY_SIZE (microblaze_register_names)
82\f
ccce17b0 83static unsigned int microblaze_debug_flag = 0;
2d1c1221 84
ebe48ba0 85static void ATTRIBUTE_PRINTF (1, 2)
2d1c1221
ME
86microblaze_debug (const char *fmt, ...)
87{
88 if (microblaze_debug_flag)
89 {
90 va_list args;
91
92 va_start (args, fmt);
93 printf_unfiltered ("MICROBLAZE: ");
94 vprintf_unfiltered (fmt, args);
95 va_end (args);
96 }
97}
98\f
99/* Return the name of register REGNUM. */
100
101static const char *
102microblaze_register_name (struct gdbarch *gdbarch, int regnum)
103{
104 if (regnum >= 0 && regnum < MICROBLAZE_NUM_REGS)
105 return microblaze_register_names[regnum];
106 return NULL;
107}
108
109static struct type *
110microblaze_register_type (struct gdbarch *gdbarch, int regnum)
111{
112 if (regnum == MICROBLAZE_SP_REGNUM)
113 return builtin_type (gdbarch)->builtin_data_ptr;
114
115 if (regnum == MICROBLAZE_PC_REGNUM)
116 return builtin_type (gdbarch)->builtin_func_ptr;
117
118 return builtin_type (gdbarch)->builtin_int;
119}
120
121\f
122/* Fetch the instruction at PC. */
123
693be288 124static unsigned long
2d1c1221
ME
125microblaze_fetch_instruction (CORE_ADDR pc)
126{
f5656ead 127 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
2d1c1221
ME
128 gdb_byte buf[4];
129
130 /* If we can't read the instruction at PC, return zero. */
34211963 131 if (target_read_code (pc, buf, sizeof (buf)))
2d1c1221
ME
132 return 0;
133
134 return extract_unsigned_integer (buf, 4, byte_order);
135}
136\f
04180708 137constexpr gdb_byte microblaze_break_insn[] = MICROBLAZE_BREAKPOINT;
598cc9dc 138
04180708 139typedef BP_MANIPULATION (microblaze_break_insn) microblaze_breakpoint;
2d1c1221 140
2d1c1221
ME
141\f
142/* Allocate and initialize a frame cache. */
143
144static struct microblaze_frame_cache *
145microblaze_alloc_frame_cache (void)
146{
147 struct microblaze_frame_cache *cache;
2d1c1221
ME
148
149 cache = FRAME_OBSTACK_ZALLOC (struct microblaze_frame_cache);
150
151 /* Base address. */
152 cache->base = 0;
153 cache->pc = 0;
154
155 /* Frameless until proven otherwise. */
156 cache->frameless_p = 1;
157
158 return cache;
159}
160
161/* The base of the current frame is actually in the stack pointer.
162 This happens when there is no frame pointer (microblaze ABI does not
163 require a frame pointer) or when we're stopped in the prologue or
164 epilogue itself. In these cases, microblaze_analyze_prologue will need
165 to update fi->frame before returning or analyzing the register
166 save instructions. */
167#define MICROBLAZE_MY_FRAME_IN_SP 0x1
168
169/* The base of the current frame is in a frame pointer register.
170 This register is noted in frame_extra_info->fp_regnum.
171
172 Note that the existance of an FP might also indicate that the
173 function has called alloca. */
174#define MICROBLAZE_MY_FRAME_IN_FP 0x2
175
176/* Function prologues on the Xilinx microblaze processors consist of:
177
178 - adjustments to the stack pointer (r1) (addi r1, r1, imm)
179 - making a copy of r1 into another register (a "frame" pointer)
180 (add r?, r1, r0)
181 - store word/multiples that use r1 or the frame pointer as the
182 base address (swi r?, r1, imm OR swi r?, fp, imm)
183
184 Note that microblaze really doesn't have a real frame pointer.
185 Instead, the compiler may copy the SP into a register (usually
186 r19) to act as an arg pointer. For our target-dependent purposes,
187 the frame info's "frame" member will be the beginning of the
188 frame. The SP could, in fact, point below this.
189
190 The prologue ends when an instruction fails to meet either of
191 these criteria. */
192
193/* Analyze the prologue to determine where registers are saved,
194 the end of the prologue, etc. Return the address of the first line
025bb325 195 of "real" code (i.e., the end of the prologue). */
2d1c1221
ME
196
197static CORE_ADDR
198microblaze_analyze_prologue (struct gdbarch *gdbarch, CORE_ADDR pc,
199 CORE_ADDR current_pc,
200 struct microblaze_frame_cache *cache)
201{
2c02bd72 202 const char *name;
2d1c1221
ME
203 CORE_ADDR func_addr, func_end, addr, stop, prologue_end_addr = 0;
204 unsigned long insn;
22e048c9 205 int rd, ra, rb, imm;
2d1c1221
ME
206 enum microblaze_instr op;
207 int flags = 0;
208 int save_hidden_pointer_found = 0;
209 int non_stack_instruction_found = 0;
210
025bb325 211 /* Find the start of this function. */
2d1c1221
ME
212 find_pc_partial_function (pc, &name, &func_addr, &func_end);
213 if (func_addr < pc)
214 pc = func_addr;
215
216 if (current_pc < pc)
217 return current_pc;
218
219 /* Initialize info about frame. */
220 cache->framesize = 0;
221 cache->fp_regnum = MICROBLAZE_SP_REGNUM;
222 cache->frameless_p = 1;
223
224 /* Start decoding the prologue. We start by checking two special cases:
225
226 1. We're about to return
227 2. We're at the first insn of the prologue.
228
229 If we're about to return, our frame has already been deallocated.
230 If we are stopped at the first instruction of a prologue,
025bb325 231 then our frame has not yet been set up. */
2d1c1221
ME
232
233 /* Get the first insn from memory. */
234
235 insn = microblaze_fetch_instruction (pc);
236 op = microblaze_decode_insn (insn, &rd, &ra, &rb, &imm);
237
238 if (IS_RETURN(op))
239 return pc;
240
241 /* Start at beginning of function and analyze until we get to the
242 current pc, or the end of the function, whichever is first. */
243 stop = (current_pc < func_end ? current_pc : func_end);
244
245 microblaze_debug ("Scanning prologue: name=%s, func_addr=%s, stop=%s\n",
246 name, paddress (gdbarch, func_addr),
247 paddress (gdbarch, stop));
248
249 for (addr = func_addr; addr < stop; addr += INST_WORD_SIZE)
250 {
251 insn = microblaze_fetch_instruction (addr);
252 op = microblaze_decode_insn (insn, &rd, &ra, &rb, &imm);
253 microblaze_debug ("%s %08lx\n", paddress (gdbarch, pc), insn);
254
255 /* This code is very sensitive to what functions are present in the
256 prologue. It assumes that the (addi, addik, swi, sw) can be the
257 only instructions in the prologue. */
258 if (IS_UPDATE_SP(op, rd, ra))
259 {
260 microblaze_debug ("got addi r1,r1,%d; contnuing\n", imm);
261 if (cache->framesize)
262 break; /* break if framesize already computed. */
263 cache->framesize = -imm; /* stack grows towards low memory. */
264 cache->frameless_p = 0; /* Frame found. */
265 save_hidden_pointer_found = 0;
266 non_stack_instruction_found = 0;
267 continue;
268 }
269 else if (IS_SPILL_SP(op, rd, ra))
270 {
271 /* Spill stack pointer. */
272 cache->register_offsets[rd] = imm; /* SP spilled before updating. */
273
274 microblaze_debug ("swi r1 r1 %d, continuing\n", imm);
275 save_hidden_pointer_found = 0;
276 if (!cache->framesize)
277 non_stack_instruction_found = 0;
278 continue;
279 }
280 else if (IS_SPILL_REG(op, rd, ra))
281 {
282 /* Spill register. */
283 cache->register_offsets[rd] = imm - cache->framesize;
284
285 microblaze_debug ("swi %d r1 %d, continuing\n", rd, imm);
286 save_hidden_pointer_found = 0;
287 if (!cache->framesize)
288 non_stack_instruction_found = 0;
289 continue;
290 }
291 else if (IS_ALSO_SPILL_REG(op, rd, ra, rb))
292 {
293 /* Spill register. */
294 cache->register_offsets[rd] = 0 - cache->framesize;
295
296 microblaze_debug ("sw %d r0 r1, continuing\n", rd);
297 save_hidden_pointer_found = 0;
298 if (!cache->framesize)
299 non_stack_instruction_found = 0;
300 continue;
301 }
302 else if (IS_SETUP_FP(op, ra, rb))
303 {
304 /* We have a frame pointer. Note the register which is
dda83cd7 305 acting as the frame pointer. */
2d1c1221
ME
306 flags |= MICROBLAZE_MY_FRAME_IN_FP;
307 flags &= ~MICROBLAZE_MY_FRAME_IN_SP;
308 cache->fp_regnum = rd;
309 microblaze_debug ("Found a frame pointer: r%d\n", cache->fp_regnum);
310 save_hidden_pointer_found = 0;
311 if (!cache->framesize)
312 non_stack_instruction_found = 0;
313 continue;
314 }
315 else if (IS_SPILL_REG_FP(op, rd, ra, cache->fp_regnum))
316 {
317 /* reg spilled after updating. */
318 cache->register_offsets[rd] = imm - cache->framesize;
319
320 microblaze_debug ("swi %d %d %d, continuing\n", rd, ra, imm);
321 save_hidden_pointer_found = 0;
322 if (!cache->framesize)
323 non_stack_instruction_found = 0;
324 continue;
325 }
326 else if (IS_SAVE_HIDDEN_PTR(op, rd, ra, rb))
327 {
328 /* If the first argument is a hidden pointer to the area where the
329 return structure is to be saved, then it is saved as part of the
330 prologue. */
331
332 microblaze_debug ("add %d %d %d, continuing\n", rd, ra, rb);
333 save_hidden_pointer_found = 1;
334 if (!cache->framesize)
335 non_stack_instruction_found = 0;
336 continue;
337 }
338
339 /* As a result of the modification in the next step where we continue
340 to analyze the prologue till we reach a control flow instruction,
341 we need another variable to store when exactly a non-stack
342 instruction was encountered, which is the current definition
343 of a prologue. */
344 if (!non_stack_instruction_found)
345 prologue_end_addr = addr;
346 non_stack_instruction_found = 1;
347
348 /* When optimizations are enabled, it is not guaranteed that prologue
349 instructions are not mixed in with other instructions from the
025bb325 350 program. Some programs show this behavior at -O2. This can be
2d1c1221
ME
351 avoided by adding -fno-schedule-insns2 switch as of now (edk 8.1)
352 In such cases, we scan the function until we see the first control
353 instruction. */
354
355 {
b926417a 356 unsigned ctrl_op = (unsigned)insn >> 26;
2d1c1221
ME
357
358 /* continue if not control flow (branch, return). */
b926417a
TT
359 if (ctrl_op != 0x26 && ctrl_op != 0x27 && ctrl_op != 0x2d
360 && ctrl_op != 0x2e && ctrl_op != 0x2f)
2d1c1221 361 continue;
b926417a 362 else if (ctrl_op == 0x2c)
2d1c1221
ME
363 continue; /* continue if imm. */
364 }
365
025bb325 366 /* This is not a prologue insn, so stop here. */
2d1c1221
ME
367 microblaze_debug ("insn is not a prologue insn -- ending scan\n");
368 break;
369 }
370
371 microblaze_debug ("done analyzing prologue\n");
372 microblaze_debug ("prologue end = 0x%x\n", (int) addr);
373
374 /* If the last instruction was an add rd, r5, r0 then don't count it as
375 part of the prologue. */
376 if (save_hidden_pointer_found)
377 prologue_end_addr -= INST_WORD_SIZE;
378
379 return prologue_end_addr;
380}
381
382static CORE_ADDR
383microblaze_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
384{
385 gdb_byte buf[4];
386 CORE_ADDR pc;
387
388 frame_unwind_register (next_frame, MICROBLAZE_PC_REGNUM, buf);
389 pc = extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
390 /* For sentinel frame, return address is actual PC. For other frames,
391 return address is pc+8. This is a workaround because gcc does not
392 generate correct return address in CIE. */
393 if (frame_relative_level (next_frame) >= 0)
394 pc += 8;
395 return pc;
396}
397
398/* Return PC of first real instruction of the function starting at
399 START_PC. */
400
693be288 401static CORE_ADDR
2d1c1221
ME
402microblaze_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
403{
404 struct symtab_and_line sal;
405 CORE_ADDR func_start, func_end, ostart_pc;
406 struct microblaze_frame_cache cache;
407
408 /* This is the preferred method, find the end of the prologue by
409 using the debugging information. Debugging info does not always
410 give the right answer since parameters are stored on stack after this.
411 Always analyze the prologue. */
412 if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end))
413 {
414 sal = find_pc_line (func_start, 0);
415
416 if (sal.end < func_end
417 && start_pc <= sal.end)
418 start_pc = sal.end;
419 }
420
421 ostart_pc = microblaze_analyze_prologue (gdbarch, func_start, 0xffffffffUL,
422 &cache);
423
424 if (ostart_pc > start_pc)
425 return ostart_pc;
426 return start_pc;
427}
428
429/* Normal frames. */
430
693be288 431static struct microblaze_frame_cache *
2d1c1221
ME
432microblaze_frame_cache (struct frame_info *next_frame, void **this_cache)
433{
434 struct microblaze_frame_cache *cache;
435 struct gdbarch *gdbarch = get_frame_arch (next_frame);
2d1c1221
ME
436 int rn;
437
438 if (*this_cache)
19ba03f4 439 return (struct microblaze_frame_cache *) *this_cache;
2d1c1221
ME
440
441 cache = microblaze_alloc_frame_cache ();
442 *this_cache = cache;
443 cache->saved_regs = trad_frame_alloc_saved_regs (next_frame);
444
445 /* Clear offsets to saved regs in frame. */
446 for (rn = 0; rn < gdbarch_num_regs (gdbarch); rn++)
447 cache->register_offsets[rn] = -1;
448
ac298888
TT
449 /* Call for side effects. */
450 get_frame_func (next_frame);
2d1c1221
ME
451
452 cache->pc = get_frame_address_in_block (next_frame);
453
454 return cache;
455}
456
457static void
458microblaze_frame_this_id (struct frame_info *next_frame, void **this_cache,
459 struct frame_id *this_id)
460{
461 struct microblaze_frame_cache *cache =
462 microblaze_frame_cache (next_frame, this_cache);
463
464 /* This marks the outermost frame. */
465 if (cache->base == 0)
466 return;
467
468 (*this_id) = frame_id_build (cache->base, cache->pc);
469}
470
471static struct value *
472microblaze_frame_prev_register (struct frame_info *this_frame,
473 void **this_cache, int regnum)
474{
475 struct microblaze_frame_cache *cache =
476 microblaze_frame_cache (this_frame, this_cache);
477
478 if (cache->frameless_p)
479 {
480 if (regnum == MICROBLAZE_PC_REGNUM)
dda83cd7 481 regnum = 15;
2d1c1221 482 if (regnum == MICROBLAZE_SP_REGNUM)
dda83cd7 483 regnum = 1;
025bb325
MS
484 return trad_frame_get_prev_register (this_frame,
485 cache->saved_regs, regnum);
2d1c1221
ME
486 }
487 else
488 return trad_frame_get_prev_register (this_frame, cache->saved_regs,
489 regnum);
490
491}
492
493static const struct frame_unwind microblaze_frame_unwind =
494{
a154d838 495 "microblaze prologue",
2d1c1221 496 NORMAL_FRAME,
8fbca658 497 default_frame_unwind_stop_reason,
2d1c1221
ME
498 microblaze_frame_this_id,
499 microblaze_frame_prev_register,
500 NULL,
501 default_frame_sniffer
502};
503\f
504static CORE_ADDR
025bb325
MS
505microblaze_frame_base_address (struct frame_info *next_frame,
506 void **this_cache)
2d1c1221
ME
507{
508 struct microblaze_frame_cache *cache =
509 microblaze_frame_cache (next_frame, this_cache);
510
511 return cache->base;
512}
513
514static const struct frame_base microblaze_frame_base =
515{
516 &microblaze_frame_unwind,
517 microblaze_frame_base_address,
518 microblaze_frame_base_address,
519 microblaze_frame_base_address
520};
521\f
522/* Extract from an array REGBUF containing the (raw) register state, a
523 function return value of TYPE, and copy that into VALBUF. */
524static void
525microblaze_extract_return_value (struct type *type, struct regcache *regcache,
526 gdb_byte *valbuf)
527{
528 gdb_byte buf[8];
529
530 /* Copy the return value (starting) in RETVAL_REGNUM to VALBUF. */
531 switch (TYPE_LENGTH (type))
532 {
533 case 1: /* return last byte in the register. */
dca08e1f 534 regcache->cooked_read (MICROBLAZE_RETVAL_REGNUM, buf);
2d1c1221
ME
535 memcpy(valbuf, buf + MICROBLAZE_REGISTER_SIZE - 1, 1);
536 return;
537 case 2: /* return last 2 bytes in register. */
dca08e1f 538 regcache->cooked_read (MICROBLAZE_RETVAL_REGNUM, buf);
2d1c1221
ME
539 memcpy(valbuf, buf + MICROBLAZE_REGISTER_SIZE - 2, 2);
540 return;
541 case 4: /* for sizes 4 or 8, copy the required length. */
542 case 8:
dca08e1f
SM
543 regcache->cooked_read (MICROBLAZE_RETVAL_REGNUM, buf);
544 regcache->cooked_read (MICROBLAZE_RETVAL_REGNUM + 1, buf+4);
2d1c1221
ME
545 memcpy (valbuf, buf, TYPE_LENGTH (type));
546 return;
547 default:
548 internal_error (__FILE__, __LINE__,
549 _("Unsupported return value size requested"));
550 }
551}
552
553/* Store the return value in VALBUF (of type TYPE) where the caller
554 expects to see it.
555
556 Integers up to four bytes are stored in r3.
557
558 Longs are stored in r3 (most significant word) and r4 (least
559 significant word).
560
025bb325 561 Small structures are always returned on stack. */
2d1c1221
ME
562
563static void
564microblaze_store_return_value (struct type *type, struct regcache *regcache,
565 const gdb_byte *valbuf)
566{
bad43aa5 567 int len = TYPE_LENGTH (type);
2d1c1221
ME
568 gdb_byte buf[8];
569
570 memset (buf, 0, sizeof(buf));
571
572 /* Integral and pointer return values. */
573
bad43aa5 574 if (len > 4)
2d1c1221 575 {
bad43aa5 576 gdb_assert (len == 8);
2d1c1221 577 memcpy (buf, valbuf, 8);
b66f5587 578 regcache->cooked_write (MICROBLAZE_RETVAL_REGNUM+1, buf + 4);
2d1c1221
ME
579 }
580 else
581 /* ??? Do we need to do any sign-extension here? */
bad43aa5 582 memcpy (buf + 4 - len, valbuf, len);
2d1c1221 583
b66f5587 584 regcache->cooked_write (MICROBLAZE_RETVAL_REGNUM, buf);
2d1c1221
ME
585}
586
587static enum return_value_convention
6a3a010b 588microblaze_return_value (struct gdbarch *gdbarch, struct value *function,
2d1c1221
ME
589 struct type *type, struct regcache *regcache,
590 gdb_byte *readbuf, const gdb_byte *writebuf)
591{
592 if (readbuf)
593 microblaze_extract_return_value (type, regcache, readbuf);
594 if (writebuf)
595 microblaze_store_return_value (type, regcache, writebuf);
596
597 return RETURN_VALUE_REGISTER_CONVENTION;
598}
599
600static int
601microblaze_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
602{
603 return (TYPE_LENGTH (type) == 16);
604}
605
2d1c1221
ME
606\f
607static int dwarf2_to_reg_map[78] =
608{ 0 /* r0 */, 1 /* r1 */, 2 /* r2 */, 3 /* r3 */, /* 0- 3 */
609 4 /* r4 */, 5 /* r5 */, 6 /* r6 */, 7 /* r7 */, /* 4- 7 */
610 8 /* r8 */, 9 /* r9 */, 10 /* r10 */, 11 /* r11 */, /* 8-11 */
611 12 /* r12 */, 13 /* r13 */, 14 /* r14 */, 15 /* r15 */, /* 12-15 */
612 16 /* r16 */, 17 /* r17 */, 18 /* r18 */, 19 /* r19 */, /* 16-19 */
613 20 /* r20 */, 21 /* r21 */, 22 /* r22 */, 23 /* r23 */, /* 20-23 */
614 24 /* r24 */, 25 /* r25 */, 26 /* r26 */, 27 /* r27 */, /* 24-25 */
615 28 /* r28 */, 29 /* r29 */, 30 /* r30 */, 31 /* r31 */, /* 28-31 */
616 -1 /* $f0 */, -1 /* $f1 */, -1 /* $f2 */, -1 /* $f3 */, /* 32-35 */
617 -1 /* $f4 */, -1 /* $f5 */, -1 /* $f6 */, -1 /* $f7 */, /* 36-39 */
618 -1 /* $f8 */, -1 /* $f9 */, -1 /* $f10 */, -1 /* $f11 */, /* 40-43 */
619 -1 /* $f12 */, -1 /* $f13 */, -1 /* $f14 */, -1 /* $f15 */, /* 44-47 */
620 -1 /* $f16 */, -1 /* $f17 */, -1 /* $f18 */, -1 /* $f19 */, /* 48-51 */
621 -1 /* $f20 */, -1 /* $f21 */, -1 /* $f22 */, -1 /* $f23 */, /* 52-55 */
622 -1 /* $f24 */, -1 /* $f25 */, -1 /* $f26 */, -1 /* $f27 */, /* 56-59 */
623 -1 /* $f28 */, -1 /* $f29 */, -1 /* $f30 */, -1 /* $f31 */, /* 60-63 */
624 -1 /* hi */, -1 /* lo */, -1 /* accum*/, 33 /* rmsr */, /* 64-67 */
625 -1 /* $fcc1*/, -1 /* $fcc2*/, -1 /* $fcc3*/, -1 /* $fcc4*/, /* 68-71 */
626 -1 /* $fcc5*/, -1 /* $fcc6*/, -1 /* $fcc7*/, -1 /* $ap */, /* 72-75 */
627 -1 /* $rap */, -1 /* $frp */ /* 76-77 */
628};
629
630static int
631microblaze_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg)
632{
0fde2c53
DE
633 if (reg >= 0 && reg < sizeof (dwarf2_to_reg_map))
634 return dwarf2_to_reg_map[reg];
635 return -1;
2d1c1221
ME
636}
637
164224e9
ME
638static void
639microblaze_register_g_packet_guesses (struct gdbarch *gdbarch)
640{
641 register_remote_g_packet_guess (gdbarch,
dda83cd7
SM
642 4 * MICROBLAZE_NUM_CORE_REGS,
643 tdesc_microblaze);
164224e9
ME
644
645 register_remote_g_packet_guess (gdbarch,
dda83cd7
SM
646 4 * MICROBLAZE_NUM_REGS,
647 tdesc_microblaze_with_stack_protect);
164224e9
ME
648}
649
2d1c1221
ME
650static struct gdbarch *
651microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
652{
653 struct gdbarch_tdep *tdep;
654 struct gdbarch *gdbarch;
c1e1314d 655 tdesc_arch_data_up tdesc_data;
164224e9 656 const struct target_desc *tdesc = info.target_desc;
2d1c1221
ME
657
658 /* If there is already a candidate, use it. */
659 arches = gdbarch_list_lookup_by_info (arches, &info);
660 if (arches != NULL)
661 return arches->gdbarch;
164224e9
ME
662 if (tdesc == NULL)
663 tdesc = tdesc_microblaze;
664
665 /* Check any target description for validity. */
666 if (tdesc_has_registers (tdesc))
667 {
668 const struct tdesc_feature *feature;
669 int valid_p;
670 int i;
671
672 feature = tdesc_find_feature (tdesc,
dda83cd7 673 "org.gnu.gdb.microblaze.core");
164224e9 674 if (feature == NULL)
dda83cd7 675 return NULL;
164224e9
ME
676 tdesc_data = tdesc_data_alloc ();
677
678 valid_p = 1;
679 for (i = 0; i < MICROBLAZE_NUM_CORE_REGS; i++)
dda83cd7
SM
680 valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), i,
681 microblaze_register_names[i]);
164224e9 682 feature = tdesc_find_feature (tdesc,
dda83cd7 683 "org.gnu.gdb.microblaze.stack-protect");
164224e9 684 if (feature != NULL)
dda83cd7
SM
685 {
686 valid_p = 1;
687 valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
688 MICROBLAZE_SLR_REGNUM,
689 "rslr");
690 valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
691 MICROBLAZE_SHR_REGNUM,
692 "rshr");
693 }
cc3afae2
AKA
694
695 if (!valid_p)
c1e1314d 696 return NULL;
cc3afae2 697 }
2d1c1221
ME
698
699 /* Allocate space for the new architecture. */
cdd238da 700 tdep = XCNEW (struct gdbarch_tdep);
2d1c1221
ME
701 gdbarch = gdbarch_alloc (&info, tdep);
702
703 set_gdbarch_long_double_bit (gdbarch, 128);
704
705 set_gdbarch_num_regs (gdbarch, MICROBLAZE_NUM_REGS);
706 set_gdbarch_register_name (gdbarch, microblaze_register_name);
707 set_gdbarch_register_type (gdbarch, microblaze_register_type);
708
709 /* Register numbers of various important registers. */
710 set_gdbarch_sp_regnum (gdbarch, MICROBLAZE_SP_REGNUM);
711 set_gdbarch_pc_regnum (gdbarch, MICROBLAZE_PC_REGNUM);
712
713 /* Map Dwarf2 registers to GDB registers. */
714 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, microblaze_dwarf2_reg_to_regnum);
715
716 /* Call dummy code. */
717 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
2d1c1221
ME
718
719 set_gdbarch_return_value (gdbarch, microblaze_return_value);
720 set_gdbarch_stabs_argument_has_addr
721 (gdbarch, microblaze_stabs_argument_has_addr);
722
723 set_gdbarch_skip_prologue (gdbarch, microblaze_skip_prologue);
724
725 /* Stack grows downward. */
726 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
727
04180708
YQ
728 set_gdbarch_breakpoint_kind_from_pc (gdbarch,
729 microblaze_breakpoint::kind_from_pc);
730 set_gdbarch_sw_breakpoint_from_kind (gdbarch,
731 microblaze_breakpoint::bp_from_kind);
2d1c1221
ME
732
733 set_gdbarch_frame_args_skip (gdbarch, 8);
734
2d1c1221
ME
735 set_gdbarch_unwind_pc (gdbarch, microblaze_unwind_pc);
736
164224e9
ME
737 microblaze_register_g_packet_guesses (gdbarch);
738
2d1c1221
ME
739 frame_base_set_default (gdbarch, &microblaze_frame_base);
740
741 /* Hook in ABI-specific overrides, if they have been registered. */
742 gdbarch_init_osabi (info, gdbarch);
743
025bb325 744 /* Unwind the frame. */
2d1c1221
ME
745 dwarf2_append_unwinders (gdbarch);
746 frame_unwind_append_unwinder (gdbarch, &microblaze_frame_unwind);
747 frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
164224e9 748 if (tdesc_data != NULL)
c1e1314d 749 tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data));
2d1c1221
ME
750
751 return gdbarch;
752}
753
6c265988 754void _initialize_microblaze_tdep ();
2d1c1221 755void
6c265988 756_initialize_microblaze_tdep ()
2d1c1221
ME
757{
758 register_gdbarch_init (bfd_arch_microblaze, microblaze_gdbarch_init);
759
164224e9
ME
760 initialize_tdesc_microblaze_with_stack_protect ();
761 initialize_tdesc_microblaze ();
2d1c1221 762 /* Debug this files internals. */
ccce17b0
YQ
763 add_setshow_zuinteger_cmd ("microblaze", class_maintenance,
764 &microblaze_debug_flag, _("\
2d1c1221
ME
765Set microblaze debugging."), _("\
766Show microblaze debugging."), _("\
767When non-zero, microblaze specific debugging is enabled."),
ccce17b0
YQ
768 NULL,
769 NULL,
770 &setdebuglist, &showdebuglist);
2d1c1221
ME
771
772}
This page took 1.332814 seconds and 4 git commands to generate.