GDB (xrefs)
/tmp/gdb-8.1/gdb/moxie-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for Moxie.
2 
3  Copyright (C) 2009-2018 Free Software Foundation, Inc.
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 "frame.h"
22 #include "frame-unwind.h"
23 #include "frame-base.h"
24 #include "symtab.h"
25 #include "gdbtypes.h"
26 #include "gdbcmd.h"
27 #include "gdbcore.h"
28 #include "value.h"
29 #include "inferior.h"
30 #include "symfile.h"
31 #include "objfiles.h"
32 #include "osabi.h"
33 #include "language.h"
34 #include "arch-utils.h"
35 #include "regcache.h"
36 #include "trad-frame.h"
37 #include "dis-asm.h"
38 #include "record.h"
39 #include "record-full.h"
40 
41 #include "moxie-tdep.h"
42 #include <algorithm>
43 
44 /* Use an invalid address value as 'not available' marker. */
45 enum { REG_UNAVAIL = (CORE_ADDR) -1 };
46 
48 {
49  /* Base address. */
55 };
56 
57 /* Implement the "frame_align" gdbarch method. */
58 
59 static CORE_ADDR
61 {
62  /* Align to the size of an instruction (so that they can safely be
63  pushed onto the stack. */
64  return sp & ~1;
65 }
66 
67 constexpr gdb_byte moxie_break_insn[] = { 0x35, 0x00 };
68 
69 typedef BP_MANIPULATION (moxie_break_insn) moxie_breakpoint;
70 
71 /* Moxie register names. */
72 
73 static const char *moxie_register_names[] = {
74  "$fp", "$sp", "$r0", "$r1", "$r2",
75  "$r3", "$r4", "$r5", "$r6", "$r7",
76  "$r8", "$r9", "$r10", "$r11", "$r12",
77  "$r13", "$pc", "$cc" };
78 
79 /* Implement the "register_name" gdbarch method. */
80 
81 static const char *
82 moxie_register_name (struct gdbarch *gdbarch, int reg_nr)
83 {
84  if (reg_nr < 0)
85  return NULL;
86  if (reg_nr >= MOXIE_NUM_REGS)
87  return NULL;
88  return moxie_register_names[reg_nr];
89 }
90 
91 /* Implement the "register_type" gdbarch method. */
92 
93 static struct type *
94 moxie_register_type (struct gdbarch *gdbarch, int reg_nr)
95 {
96  if (reg_nr == MOXIE_PC_REGNUM)
98  else if (reg_nr == MOXIE_SP_REGNUM || reg_nr == MOXIE_FP_REGNUM)
100  else
102 }
103 
104 /* Write into appropriate registers a function return value
105  of type TYPE, given in virtual format. */
106 
107 static void
109  const gdb_byte *valbuf)
110 {
111  struct gdbarch *gdbarch = regcache->arch ();
112  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
113  CORE_ADDR regval;
114  int len = TYPE_LENGTH (type);
115 
116  /* Things always get returned in RET1_REGNUM, RET2_REGNUM. */
117  regval = extract_unsigned_integer (valbuf, len > 4 ? 4 : len, byte_order);
119  if (len > 4)
120  {
121  regval = extract_unsigned_integer (valbuf + 4, len - 4, byte_order);
123  }
124 }
125 
126 /* Decode the instructions within the given address range. Decide
127  when we must have reached the end of the function prologue. If a
128  frame_info pointer is provided, fill in its saved_regs etc.
129 
130  Returns the address of the first instruction after the prologue. */
131 
132 static CORE_ADDR
134  struct moxie_frame_cache *cache,
135  struct gdbarch *gdbarch)
136 {
137  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
138  CORE_ADDR next_addr;
139  ULONGEST inst, inst2;
140  LONGEST offset;
141  int regnum;
142 
143  /* Record where the jsra instruction saves the PC and FP. */
144  cache->saved_regs[MOXIE_PC_REGNUM] = -4;
145  cache->saved_regs[MOXIE_FP_REGNUM] = 0;
146  cache->framesize = 0;
147 
148  if (start_addr >= end_addr)
149  return end_addr;
150 
151  for (next_addr = start_addr; next_addr < end_addr; )
152  {
153  inst = read_memory_unsigned_integer (next_addr, 2, byte_order);
154 
155  /* Match "push $sp $rN" where N is between 0 and 13 inclusive. */
156  if (inst >= 0x0612 && inst <= 0x061f)
157  {
158  regnum = inst & 0x000f;
159  cache->framesize += 4;
160  cache->saved_regs[regnum] = cache->framesize;
161  next_addr += 2;
162  }
163  else
164  break;
165  }
166 
167  inst = read_memory_unsigned_integer (next_addr, 2, byte_order);
168 
169  /* Optional stack allocation for args and local vars <= 4
170  byte. */
171  if (inst == 0x01e0) /* ldi.l $r12, X */
172  {
173  offset = read_memory_integer (next_addr + 2, 4, byte_order);
174  inst2 = read_memory_unsigned_integer (next_addr + 6, 2, byte_order);
175 
176  if (inst2 == 0x291e) /* sub.l $sp, $r12 */
177  {
178  cache->framesize += offset;
179  }
180 
181  return (next_addr + 8);
182  }
183  else if ((inst & 0xff00) == 0x9100) /* dec $sp, X */
184  {
185  cache->framesize += (inst & 0x00ff);
186  next_addr += 2;
187 
188  while (next_addr < end_addr)
189  {
190  inst = read_memory_unsigned_integer (next_addr, 2, byte_order);
191  if ((inst & 0xff00) != 0x9100) /* no more dec $sp, X */
192  break;
193  cache->framesize += (inst & 0x00ff);
194  next_addr += 2;
195  }
196  }
197 
198  return next_addr;
199 }
200 
201 /* Find the end of function prologue. */
202 
203 static CORE_ADDR
205 {
206  CORE_ADDR func_addr = 0, func_end = 0;
207  const char *func_name;
208 
209  /* See if we can determine the end of the prologue via the symbol table.
210  If so, then return either PC, or the PC after the prologue, whichever
211  is greater. */
212  if (find_pc_partial_function (pc, &func_name, &func_addr, &func_end))
213  {
214  CORE_ADDR post_prologue_pc
215  = skip_prologue_using_sal (gdbarch, func_addr);
216  if (post_prologue_pc != 0)
217  return std::max (pc, post_prologue_pc);
218  else
219  {
220  /* Can't determine prologue from the symbol table, need to examine
221  instructions. */
222  struct symtab_and_line sal;
223  struct symbol *sym;
224  struct moxie_frame_cache cache;
225  CORE_ADDR plg_end;
226 
227  memset (&cache, 0, sizeof cache);
228 
229  plg_end = moxie_analyze_prologue (func_addr,
230  func_end, &cache, gdbarch);
231  /* Found a function. */
232  sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL).symbol;
233  /* Don't use line number debug info for assembly source
234  files. */
235  if (sym && SYMBOL_LANGUAGE (sym) != language_asm)
236  {
237  sal = find_pc_line (func_addr, 0);
238  if (sal.end && sal.end < func_end)
239  {
240  /* Found a line number, use it as end of
241  prologue. */
242  return sal.end;
243  }
244  }
245  /* No useable line symbol. Use result of prologue parsing
246  method. */
247  return plg_end;
248  }
249  }
250 
251  /* No function symbol -- just return the PC. */
252  return (CORE_ADDR) pc;
253 }
254 
256 {
257  /* The previous frame's inner most stack address. Used as this
258  frame ID's stack_addr. */
260  /* The frame's base, optionally used by the high-level debug info. */
262  int size;
263  /* How far the SP and r13 (FP) have been offset from the start of
264  the stack frame (as defined by the previous frame's stack
265  pointer). */
269  /* Table indicating the location of each and every register. */
271 };
272 
273 /* Read an unsigned integer from the inferior, and adjust
274  endianess. */
275 static ULONGEST
277  int length, enum bfd_endian byte_order)
278 {
279  if (target_read_memory (addr, buf, length))
280  {
281  if (record_debug)
282  printf_unfiltered (_("Process record: error reading memory at "
283  "addr 0x%s len = %d.\n"),
284  paddress (target_gdbarch (), addr), length);
285  return -1;
286  }
287 
288  return extract_unsigned_integer (buf, length, byte_order);
289 }
290 
291 
292 /* Helper macro to extract the signed 10-bit offset from a 16-bit
293  branch instruction. */
294 #define INST2OFFSET(o) ((((signed short)((o & ((1<<10)-1))<<6))>>6)<<1)
295 
296 /* Insert a single step breakpoint. */
297 
298 static std::vector<CORE_ADDR>
300 {
301  struct gdbarch *gdbarch = regcache->arch ();
302  CORE_ADDR addr;
303  gdb_byte buf[4];
304  uint16_t inst;
305  uint32_t tmpu32;
306  ULONGEST fp;
307  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
308  std::vector<CORE_ADDR> next_pcs;
309 
310  addr = regcache_read_pc (regcache);
311 
312  inst = (uint16_t) moxie_process_readu (addr, buf, 2, byte_order);
313 
314  /* Decode instruction. */
315  if (inst & (1 << 15))
316  {
317  if (inst & (1 << 14))
318  {
319  /* This is a Form 3 instruction. */
320  int opcode = (inst >> 10 & 0xf);
321 
322  switch (opcode)
323  {
324  case 0x00: /* beq */
325  case 0x01: /* bne */
326  case 0x02: /* blt */
327  case 0x03: /* bgt */
328  case 0x04: /* bltu */
329  case 0x05: /* bgtu */
330  case 0x06: /* bge */
331  case 0x07: /* ble */
332  case 0x08: /* bgeu */
333  case 0x09: /* bleu */
334  /* Insert breaks on both branches, because we can't currently tell
335  which way things will go. */
336  next_pcs.push_back (addr + 2);
337  next_pcs.push_back (addr + 2 + INST2OFFSET(inst));
338  break;
339  default:
340  {
341  /* Do nothing. */
342  break;
343  }
344  }
345  }
346  else
347  {
348  /* This is a Form 2 instruction. They are all 16 bits. */
349  next_pcs.push_back (addr + 2);
350  }
351  }
352  else
353  {
354  /* This is a Form 1 instruction. */
355  int opcode = inst >> 8;
356 
357  switch (opcode)
358  {
359  /* 16-bit instructions. */
360  case 0x00: /* bad */
361  case 0x02: /* mov (register-to-register) */
362  case 0x05: /* add.l */
363  case 0x06: /* push */
364  case 0x07: /* pop */
365  case 0x0a: /* ld.l (register indirect) */
366  case 0x0b: /* st.l */
367  case 0x0e: /* cmp */
368  case 0x0f: /* nop */
369  case 0x10: /* sex.b */
370  case 0x11: /* sex.s */
371  case 0x12: /* zex.b */
372  case 0x13: /* zex.s */
373  case 0x14: /* umul.x */
374  case 0x15: /* mul.x */
375  case 0x16:
376  case 0x17:
377  case 0x18:
378  case 0x1c: /* ld.b (register indirect) */
379  case 0x1e: /* st.b */
380  case 0x21: /* ld.s (register indirect) */
381  case 0x23: /* st.s */
382  case 0x26: /* and */
383  case 0x27: /* lshr */
384  case 0x28: /* ashl */
385  case 0x29: /* sub.l */
386  case 0x2a: /* neg */
387  case 0x2b: /* or */
388  case 0x2c: /* not */
389  case 0x2d: /* ashr */
390  case 0x2e: /* xor */
391  case 0x2f: /* mul.l */
392  case 0x31: /* div.l */
393  case 0x32: /* udiv.l */
394  case 0x33: /* mod.l */
395  case 0x34: /* umod.l */
396  next_pcs.push_back (addr + 2);
397  break;
398 
399  /* 32-bit instructions. */
400  case 0x0c: /* ldo.l */
401  case 0x0d: /* sto.l */
402  case 0x36: /* ldo.b */
403  case 0x37: /* sto.b */
404  case 0x38: /* ldo.s */
405  case 0x39: /* sto.s */
406  next_pcs.push_back (addr + 4);
407  break;
408 
409  /* 48-bit instructions. */
410  case 0x01: /* ldi.l (immediate) */
411  case 0x08: /* lda.l */
412  case 0x09: /* sta.l */
413  case 0x1b: /* ldi.b (immediate) */
414  case 0x1d: /* lda.b */
415  case 0x1f: /* sta.b */
416  case 0x20: /* ldi.s (immediate) */
417  case 0x22: /* lda.s */
418  case 0x24: /* sta.s */
419  next_pcs.push_back (addr + 6);
420  break;
421 
422  /* Control flow instructions. */
423  case 0x03: /* jsra */
424  case 0x1a: /* jmpa */
425  next_pcs.push_back (moxie_process_readu (addr + 2, buf, 4,
426  byte_order));
427  break;
428 
429  case 0x04: /* ret */
431  next_pcs.push_back (moxie_process_readu (fp + 4, buf, 4, byte_order));
432  break;
433 
434  case 0x19: /* jsr */
435  case 0x25: /* jmp */
437  (inst >> 4) & 0xf, (gdb_byte *) & tmpu32);
438  next_pcs.push_back (tmpu32);
439  break;
440 
441  case 0x30: /* swi */
442  case 0x35: /* brk */
443  /* Unsupported, for now. */
444  break;
445  }
446  }
447 
448  return next_pcs;
449 }
450 
451 /* Implement the "read_pc" gdbarch method. */
452 
453 static CORE_ADDR
455 {
456  ULONGEST pc;
457 
459  return pc;
460 }
461 
462 /* Implement the "write_pc" gdbarch method. */
463 
464 static void
466 {
468 }
469 
470 /* Implement the "unwind_sp" gdbarch method. */
471 
472 static CORE_ADDR
473 moxie_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
474 {
475  return frame_unwind_register_unsigned (next_frame, MOXIE_SP_REGNUM);
476 }
477 
478 /* Given a return value in `regbuf' with a type `valtype',
479  extract and copy its value into `valbuf'. */
480 
481 static void
483  gdb_byte *dst)
484 {
485  struct gdbarch *gdbarch = regcache->arch ();
486  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
487  int len = TYPE_LENGTH (type);
488  ULONGEST tmp;
489 
490  /* By using store_unsigned_integer we avoid having to do
491  anything special for small big-endian values. */
493  store_unsigned_integer (dst, (len > 4 ? len - 4 : len), byte_order, tmp);
494 
495  /* Ignore return values more than 8 bytes in size because the moxie
496  returns anything more than 8 bytes in the stack. */
497  if (len > 4)
498  {
500  store_unsigned_integer (dst + len - 4, 4, byte_order, tmp);
501  }
502 }
503 
504 /* Implement the "return_value" gdbarch method. */
505 
506 static enum return_value_convention
507 moxie_return_value (struct gdbarch *gdbarch, struct value *function,
508  struct type *valtype, struct regcache *regcache,
509  gdb_byte *readbuf, const gdb_byte *writebuf)
510 {
511  if (TYPE_LENGTH (valtype) > 8)
513  else
514  {
515  if (readbuf != NULL)
516  moxie_extract_return_value (valtype, regcache, readbuf);
517  if (writebuf != NULL)
518  moxie_store_return_value (valtype, regcache, writebuf);
520  }
521 }
522 
523 /* Allocate and initialize a moxie_frame_cache object. */
524 
525 static struct moxie_frame_cache *
527 {
528  struct moxie_frame_cache *cache;
529  int i;
530 
531  cache = FRAME_OBSTACK_ZALLOC (struct moxie_frame_cache);
532 
533  cache->base = 0;
534  cache->saved_sp = 0;
535  cache->pc = 0;
536  cache->framesize = 0;
537  for (i = 0; i < MOXIE_NUM_REGS; ++i)
538  cache->saved_regs[i] = REG_UNAVAIL;
539 
540  return cache;
541 }
542 
543 /* Populate a moxie_frame_cache object for this_frame. */
544 
545 static struct moxie_frame_cache *
546 moxie_frame_cache (struct frame_info *this_frame, void **this_cache)
547 {
548  struct moxie_frame_cache *cache;
549  CORE_ADDR current_pc;
550  int i;
551 
552  if (*this_cache)
553  return (struct moxie_frame_cache *) *this_cache;
554 
555  cache = moxie_alloc_frame_cache ();
556  *this_cache = cache;
557 
558  cache->base = get_frame_register_unsigned (this_frame, MOXIE_FP_REGNUM);
559  if (cache->base == 0)
560  return cache;
561 
562  cache->pc = get_frame_func (this_frame);
563  current_pc = get_frame_pc (this_frame);
564  if (cache->pc)
565  {
566  struct gdbarch *gdbarch = get_frame_arch (this_frame);
567  moxie_analyze_prologue (cache->pc, current_pc, cache, gdbarch);
568  }
569 
570  cache->saved_sp = cache->base - cache->framesize;
571 
572  for (i = 0; i < MOXIE_NUM_REGS; ++i)
573  if (cache->saved_regs[i] != REG_UNAVAIL)
574  cache->saved_regs[i] = cache->base - cache->saved_regs[i];
575 
576  return cache;
577 }
578 
579 /* Implement the "unwind_pc" gdbarch method. */
580 
581 static CORE_ADDR
582 moxie_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
583 {
584  return frame_unwind_register_unsigned (next_frame, MOXIE_PC_REGNUM);
585 }
586 
587 /* Given a GDB frame, determine the address of the calling function's
588  frame. This will be used to create a new GDB frame struct. */
589 
590 static void
591 moxie_frame_this_id (struct frame_info *this_frame,
592  void **this_prologue_cache, struct frame_id *this_id)
593 {
594  struct moxie_frame_cache *cache = moxie_frame_cache (this_frame,
595  this_prologue_cache);
596 
597  /* This marks the outermost frame. */
598  if (cache->base == 0)
599  return;
600 
601  *this_id = frame_id_build (cache->saved_sp, cache->pc);
602 }
603 
604 /* Get the value of register regnum in the previous stack frame. */
605 
606 static struct value *
608  void **this_prologue_cache, int regnum)
609 {
610  struct moxie_frame_cache *cache = moxie_frame_cache (this_frame,
611  this_prologue_cache);
612 
613  gdb_assert (regnum >= 0);
614 
615  if (regnum == MOXIE_SP_REGNUM && cache->saved_sp)
616  return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
617 
618  if (regnum < MOXIE_NUM_REGS && cache->saved_regs[regnum] != REG_UNAVAIL)
619  return frame_unwind_got_memory (this_frame, regnum,
620  cache->saved_regs[regnum]);
621 
622  return frame_unwind_got_register (this_frame, regnum, regnum);
623 }
624 
625 static const struct frame_unwind moxie_frame_unwind = {
626  NORMAL_FRAME,
630  NULL,
632 };
633 
634 /* Return the base address of this_frame. */
635 
636 static CORE_ADDR
637 moxie_frame_base_address (struct frame_info *this_frame, void **this_cache)
638 {
639  struct moxie_frame_cache *cache = moxie_frame_cache (this_frame,
640  this_cache);
641 
642  return cache->base;
643 }
644 
645 static const struct frame_base moxie_frame_base = {
650 };
651 
652 static struct frame_id
653 moxie_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
654 {
656 
657  return frame_id_build (sp, get_frame_pc (this_frame));
658 }
659 
660 /* Parse the current instruction and record the values of the registers and
661  memory that will be changed in current instruction to "record_arch_list".
662  Return -1 if something wrong. */
663 
664 static int
666  CORE_ADDR addr)
667 {
668  gdb_byte buf[4];
669  uint16_t inst;
670  uint32_t tmpu32;
671  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
672 
673  if (record_debug > 1)
674  fprintf_unfiltered (gdb_stdlog, "Process record: moxie_process_record "
675  "addr = 0x%s\n",
677 
678  inst = (uint16_t) moxie_process_readu (addr, buf, 2, byte_order);
679 
680  /* Decode instruction. */
681  if (inst & (1 << 15))
682  {
683  if (inst & (1 << 14))
684  {
685  /* This is a Form 3 instruction. */
686  int opcode = (inst >> 10 & 0xf);
687 
688  switch (opcode)
689  {
690  case 0x00: /* beq */
691  case 0x01: /* bne */
692  case 0x02: /* blt */
693  case 0x03: /* bgt */
694  case 0x04: /* bltu */
695  case 0x05: /* bgtu */
696  case 0x06: /* bge */
697  case 0x07: /* ble */
698  case 0x08: /* bgeu */
699  case 0x09: /* bleu */
700  /* Do nothing. */
701  break;
702  default:
703  {
704  /* Do nothing. */
705  break;
706  }
707  }
708  }
709  else
710  {
711  /* This is a Form 2 instruction. */
712  int opcode = (inst >> 12 & 0x3);
713  switch (opcode)
714  {
715  case 0x00: /* inc */
716  case 0x01: /* dec */
717  case 0x02: /* gsr */
718  {
719  int reg = (inst >> 8) & 0xf;
721  return -1;
722  }
723  break;
724  case 0x03: /* ssr */
725  {
726  /* Do nothing until GDB learns about moxie's special
727  registers. */
728  }
729  break;
730  default:
731  /* Do nothing. */
732  break;
733  }
734  }
735  }
736  else
737  {
738  /* This is a Form 1 instruction. */
739  int opcode = inst >> 8;
740 
741  switch (opcode)
742  {
743  case 0x00: /* nop */
744  /* Do nothing. */
745  break;
746  case 0x01: /* ldi.l (immediate) */
747  case 0x02: /* mov (register-to-register) */
748  {
749  int reg = (inst >> 4) & 0xf;
751  return -1;
752  }
753  break;
754  case 0x03: /* jsra */
755  {
757  MOXIE_SP_REGNUM, (gdb_byte *) & tmpu32);
758  tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
759  4, byte_order);
763  || record_full_arch_list_add_mem (tmpu32 - 12, 12))
764  return -1;
765  }
766  break;
767  case 0x04: /* ret */
768  {
771  MOXIE_SP_REGNUM)))
772  return -1;
773  }
774  break;
775  case 0x05: /* add.l */
776  {
777  int reg = (inst >> 4) & 0xf;
779  return -1;
780  }
781  break;
782  case 0x06: /* push */
783  {
784  int reg = (inst >> 4) & 0xf;
785  regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
786  tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
787  4, byte_order);
789  || record_full_arch_list_add_mem (tmpu32 - 4, 4))
790  return -1;
791  }
792  break;
793  case 0x07: /* pop */
794  {
795  int a = (inst >> 4) & 0xf;
796  int b = inst & 0xf;
799  return -1;
800  }
801  break;
802  case 0x08: /* lda.l */
803  {
804  int reg = (inst >> 4) & 0xf;
806  return -1;
807  }
808  break;
809  case 0x09: /* sta.l */
810  {
811  tmpu32 = (uint32_t) moxie_process_readu (addr+2, buf,
812  4, byte_order);
813  if (record_full_arch_list_add_mem (tmpu32, 4))
814  return -1;
815  }
816  break;
817  case 0x0a: /* ld.l (register indirect) */
818  {
819  int reg = (inst >> 4) & 0xf;
821  return -1;
822  }
823  break;
824  case 0x0b: /* st.l */
825  {
826  int reg = (inst >> 4) & 0xf;
827  regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
828  tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
829  4, byte_order);
830  if (record_full_arch_list_add_mem (tmpu32, 4))
831  return -1;
832  }
833  break;
834  case 0x0c: /* ldo.l */
835  {
836  int reg = (inst >> 4) & 0xf;
838  return -1;
839  }
840  break;
841  case 0x0d: /* sto.l */
842  {
843  int reg = (inst >> 4) & 0xf;
844  uint32_t offset = (((int16_t) moxie_process_readu (addr+2, buf, 2,
845  byte_order)) << 16 ) >> 16;
846  regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
847  tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
848  4, byte_order);
849  tmpu32 += offset;
850  if (record_full_arch_list_add_mem (tmpu32, 4))
851  return -1;
852  }
853  break;
854  case 0x0e: /* cmp */
855  {
857  return -1;
858  }
859  break;
860  case 0x0f: /* nop */
861  {
862  /* Do nothing. */
863  break;
864  }
865  case 0x10: /* sex.b */
866  case 0x11: /* sex.s */
867  case 0x12: /* zex.b */
868  case 0x13: /* zex.s */
869  case 0x14: /* umul.x */
870  case 0x15: /* mul.x */
871  {
872  int reg = (inst >> 4) & 0xf;
874  return -1;
875  }
876  break;
877  case 0x16:
878  case 0x17:
879  case 0x18:
880  {
881  /* Do nothing. */
882  break;
883  }
884  case 0x19: /* jsr */
885  {
887  MOXIE_SP_REGNUM, (gdb_byte *) & tmpu32);
888  tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
889  4, byte_order);
893  || record_full_arch_list_add_mem (tmpu32 - 12, 12))
894  return -1;
895  }
896  break;
897  case 0x1a: /* jmpa */
898  {
899  /* Do nothing. */
900  }
901  break;
902  case 0x1b: /* ldi.b (immediate) */
903  case 0x1c: /* ld.b (register indirect) */
904  case 0x1d: /* lda.b */
905  {
906  int reg = (inst >> 4) & 0xf;
908  return -1;
909  }
910  break;
911  case 0x1e: /* st.b */
912  {
913  int reg = (inst >> 4) & 0xf;
914  regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
915  tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
916  4, byte_order);
917  if (record_full_arch_list_add_mem (tmpu32, 1))
918  return -1;
919  }
920  break;
921  case 0x1f: /* sta.b */
922  {
923  tmpu32 = moxie_process_readu (addr+2, buf, 4, byte_order);
924  if (record_full_arch_list_add_mem (tmpu32, 1))
925  return -1;
926  }
927  break;
928  case 0x20: /* ldi.s (immediate) */
929  case 0x21: /* ld.s (register indirect) */
930  case 0x22: /* lda.s */
931  {
932  int reg = (inst >> 4) & 0xf;
934  return -1;
935  }
936  break;
937  case 0x23: /* st.s */
938  {
939  int reg = (inst >> 4) & 0xf;
940  regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
941  tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
942  4, byte_order);
943  if (record_full_arch_list_add_mem (tmpu32, 2))
944  return -1;
945  }
946  break;
947  case 0x24: /* sta.s */
948  {
949  tmpu32 = moxie_process_readu (addr+2, buf, 4, byte_order);
950  if (record_full_arch_list_add_mem (tmpu32, 2))
951  return -1;
952  }
953  break;
954  case 0x25: /* jmp */
955  {
956  /* Do nothing. */
957  }
958  break;
959  case 0x26: /* and */
960  case 0x27: /* lshr */
961  case 0x28: /* ashl */
962  case 0x29: /* sub */
963  case 0x2a: /* neg */
964  case 0x2b: /* or */
965  case 0x2c: /* not */
966  case 0x2d: /* ashr */
967  case 0x2e: /* xor */
968  case 0x2f: /* mul */
969  {
970  int reg = (inst >> 4) & 0xf;
972  return -1;
973  }
974  break;
975  case 0x30: /* swi */
976  {
977  /* We currently implement support for libgloss'
978  system calls. */
979 
980  int inum = moxie_process_readu (addr+2, buf, 4, byte_order);
981 
982  switch (inum)
983  {
984  case 0x1: /* SYS_exit */
985  {
986  /* Do nothing. */
987  }
988  break;
989  case 0x2: /* SYS_open */
990  {
992  return -1;
993  }
994  break;
995  case 0x4: /* SYS_read */
996  {
997  uint32_t length, ptr;
998 
999  /* Read buffer pointer is in $r1. */
1000  regcache_raw_read (regcache, 3, (gdb_byte *) & ptr);
1001  ptr = extract_unsigned_integer ((gdb_byte *) & ptr,
1002  4, byte_order);
1003 
1004  /* String length is at 0x12($fp). */
1006  MOXIE_FP_REGNUM, (gdb_byte *) & tmpu32);
1007  tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
1008  4, byte_order);
1009  length = moxie_process_readu (tmpu32+20, buf, 4, byte_order);
1010 
1011  if (record_full_arch_list_add_mem (ptr, length))
1012  return -1;
1013  }
1014  break;
1015  case 0x5: /* SYS_write */
1016  {
1018  return -1;
1019  }
1020  break;
1021  default:
1022  break;
1023  }
1024  }
1025  break;
1026  case 0x31: /* div.l */
1027  case 0x32: /* udiv.l */
1028  case 0x33: /* mod.l */
1029  case 0x34: /* umod.l */
1030  {
1031  int reg = (inst >> 4) & 0xf;
1033  return -1;
1034  }
1035  break;
1036  case 0x35: /* brk */
1037  /* Do nothing. */
1038  break;
1039  case 0x36: /* ldo.b */
1040  {
1041  int reg = (inst >> 4) & 0xf;
1043  return -1;
1044  }
1045  break;
1046  case 0x37: /* sto.b */
1047  {
1048  int reg = (inst >> 4) & 0xf;
1049  uint32_t offset = (((int16_t) moxie_process_readu (addr+2, buf, 2,
1050  byte_order)) << 16 ) >> 16;
1051  regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
1052  tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
1053  4, byte_order);
1054  tmpu32 += offset;
1055  if (record_full_arch_list_add_mem (tmpu32, 1))
1056  return -1;
1057  }
1058  break;
1059  case 0x38: /* ldo.s */
1060  {
1061  int reg = (inst >> 4) & 0xf;
1063  return -1;
1064  }
1065  break;
1066  case 0x39: /* sto.s */
1067  {
1068  int reg = (inst >> 4) & 0xf;
1069  uint32_t offset = (((int16_t) moxie_process_readu (addr+2, buf, 2,
1070  byte_order)) << 16 ) >> 16;
1071  regcache_raw_read (regcache, reg, (gdb_byte *) & tmpu32);
1072  tmpu32 = extract_unsigned_integer ((gdb_byte *) & tmpu32,
1073  4, byte_order);
1074  tmpu32 += offset;
1075  if (record_full_arch_list_add_mem (tmpu32, 2))
1076  return -1;
1077  }
1078  break;
1079  default:
1080  /* Do nothing. */
1081  break;
1082  }
1083  }
1084 
1086  return -1;
1088  return -1;
1089  return 0;
1090 }
1091 
1092 /* Allocate and initialize the moxie gdbarch object. */
1093 
1094 static struct gdbarch *
1095 moxie_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1096 {
1097  struct gdbarch *gdbarch;
1098  struct gdbarch_tdep *tdep;
1099 
1100  /* If there is already a candidate, use it. */
1101  arches = gdbarch_list_lookup_by_info (arches, &info);
1102  if (arches != NULL)
1103  return arches->gdbarch;
1104 
1105  /* Allocate space for the new architecture. */
1106  tdep = XCNEW (struct gdbarch_tdep);
1107  gdbarch = gdbarch_alloc (&info, tdep);
1108 
1111 
1115 
1121 
1123 
1127  moxie_breakpoint::kind_from_pc);
1129  moxie_breakpoint::bp_from_kind);
1131 
1133 
1134  /* Methods for saving / extracting a dummy frame's ID. The ID's
1135  stack address must match the SP value returned by
1136  PUSH_DUMMY_CALL, and saved by generic_save_dummy_frame_tos. */
1138 
1140 
1141  /* Hook in ABI-specific overrides, if they have been registered. */
1142  gdbarch_init_osabi (info, gdbarch);
1143 
1144  /* Hook in the default unwinders. */
1146 
1147  /* Single stepping. */
1149 
1150  /* Support simple overlay manager. */
1152 
1153  /* Support reverse debugging. */
1155 
1156  return gdbarch;
1157 }
1158 
1159 /* Register this machine's init routine. */
1160 
1161 void
1163 {
1164  register_gdbarch_init (bfd_arch_moxie, moxie_gdbarch_init);
1165 }
struct gdbarch * target_gdbarch(void)
Definition: gdbarch.c:5467
void set_gdbarch_num_regs(struct gdbarch *gdbarch, int num_regs)
Definition: gdbarch.c:2050
void set_gdbarch_frame_align(struct gdbarch *gdbarch, gdbarch_frame_align_ftype frame_align)
Definition: gdbarch.c:3151
CORE_ADDR saved_regs[MOXIE_NUM_REGS]
Definition: moxie-tdep.c:53
static struct frame_id moxie_dummy_id(struct gdbarch *gdbarch, struct frame_info *this_frame)
Definition: moxie-tdep.c:653
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:624
static CORE_ADDR moxie_read_pc(struct regcache *regcache)
Definition: moxie-tdep.c:454
struct type * builtin_func_ptr
Definition: gdbtypes.h:1565
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2376
static CORE_ADDR moxie_skip_prologue(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: moxie-tdep.c:204
bfd_vma CORE_ADDR
Definition: common-types.h:41
void gdbarch_init_osabi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: osabi.c:334
static CORE_ADDR moxie_unwind_sp(struct gdbarch *gdbarch, struct frame_info *next_frame)
Definition: moxie-tdep.c:473
void set_gdbarch_wchar_bit(struct gdbarch *gdbarch, int wchar_bit)
Definition: gdbarch.c:1789
int record_full_arch_list_add_reg(struct regcache *regcache, int regnum)
Definition: record-full.c:468
struct value * frame_unwind_got_memory(struct frame_info *frame, int regnum, CORE_ADDR addr)
Definition: frame-unwind.c:233
static const struct frame_base moxie_frame_base
Definition: moxie-tdep.c:645
CORE_ADDR end
Definition: symtab.h:1760
void set_gdbarch_overlay_update(struct gdbarch *gdbarch, gdbarch_overlay_update_ftype overlay_update)
Definition: gdbarch.c:4048
void set_gdbarch_write_pc(struct gdbarch *gdbarch, gdbarch_write_pc_ftype write_pc)
Definition: gdbarch.c:1943
CORE_ADDR saved_sp
Definition: moxie-tdep.c:54
static void moxie_frame_this_id(struct frame_info *this_frame, void **this_prologue_cache, struct frame_id *this_id)
Definition: moxie-tdep.c:591
static CORE_ADDR moxie_frame_align(struct gdbarch *gdbarch, CORE_ADDR sp)
Definition: moxie-tdep.c:60
ULONGEST frame_unwind_register_unsigned(struct frame_info *frame, int regnum)
Definition: frame.c:1279
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition: gdbtypes.c:5217
void * memset(T *s, int c, size_t n)=delete
unsigned int record_debug
Definition: record.c:33
return_value_convention
Definition: defs.h:247
static CORE_ADDR moxie_unwind_pc(struct gdbarch *gdbarch, struct frame_info *next_frame)
Definition: moxie-tdep.c:582
CORE_ADDR base
Definition: moxie-tdep.c:50
static enum return_value_convention moxie_return_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
Definition: moxie-tdep.c:507
struct gdbarch_list * gdbarch_list_lookup_by_info(struct gdbarch_list *arches, const struct gdbarch_info *info)
Definition: gdbarch.c:5309
CORE_ADDR skip_prologue_using_sal(struct gdbarch *gdbarch, CORE_ADDR func_addr)
Definition: symtab.c:3854
struct block_symbol lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
Definition: symtab.c:1893
#define _(String)
Definition: gdb_locale.h:35
static const char * moxie_register_name(struct gdbarch *gdbarch, int reg_nr)
Definition: moxie-tdep.c:82
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
Definition: frame-unwind.c:79
void set_gdbarch_process_record(struct gdbarch *gdbarch, gdbarch_process_record_ftype process_record)
Definition: gdbarch.c:4137
struct type * builtin_int32
Definition: gdbtypes.h:1538
void set_gdbarch_wchar_signed(struct gdbarch *gdbarch, int wchar_signed)
Definition: gdbarch.c:1807
#define FRAME_OBSTACK_ZALLOC(TYPE)
Definition: frame.h:678
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: utils.c:2745
struct value * frame_unwind_got_constant(struct frame_info *frame, int regnum, ULONGEST val)
Definition: frame-unwind.c:246
static std::vector< CORE_ADDR > moxie_software_single_step(struct regcache *regcache)
Definition: moxie-tdep.c:299
void frame_base_set_default(struct gdbarch *gdbarch, const struct frame_base *default_base)
Definition: frame-base.c:95
void set_gdbarch_register_type(struct gdbarch *gdbarch, gdbarch_register_type_ftype register_type)
Definition: gdbarch.c:2316
LONGEST read_memory_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition: corefile.c:316
struct symtab_and_line find_pc_line(CORE_ADDR pc, int notcurrent)
Definition: symtab.c:3288
static int moxie_process_record(struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR addr)
Definition: moxie-tdep.c:665
static const struct frame_unwind moxie_frame_unwind
Definition: moxie-tdep.c:625
static ULONGEST extract_unsigned_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
Definition: defs.h:577
enum register_status regcache_cooked_read_unsigned(struct regcache *regcache, int regnum, ULONGEST *val)
Definition: regcache.c:777
void set_gdbarch_sp_regnum(struct gdbarch *gdbarch, int sp_regnum)
Definition: gdbarch.c:2156
void set_gdbarch_dummy_id(struct gdbarch *gdbarch, gdbarch_dummy_id_ftype dummy_id)
Definition: gdbarch.c:2340
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
Definition: utils.c:2018
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1509
static struct value * moxie_frame_prev_register(struct frame_info *this_frame, void **this_prologue_cache, int regnum)
Definition: moxie-tdep.c:607
Definition: gdbtypes.h:749
int find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr)
Definition: blockframe.c:320
void set_gdbarch_unwind_pc(struct gdbarch *gdbarch, gdbarch_unwind_pc_ftype unwind_pc)
Definition: gdbarch.c:3079
int default_frame_sniffer(const struct frame_unwind *self, struct frame_info *this_frame, void **this_prologue_cache)
Definition: frame-unwind.c:174
static CORE_ADDR moxie_frame_base_address(struct frame_info *this_frame, void **this_cache)
Definition: moxie-tdep.c:637
void set_gdbarch_read_pc(struct gdbarch *gdbarch, gdbarch_read_pc_ftype read_pc)
Definition: gdbarch.c:1919
void simple_overlay_update(struct obj_section *osect)
Definition: symfile.c:3559
void set_gdbarch_unwind_sp(struct gdbarch *gdbarch, gdbarch_unwind_sp_ftype unwind_sp)
Definition: gdbarch.c:3103
static struct moxie_frame_cache * moxie_frame_cache(struct frame_info *this_frame, void **this_cache)
Definition: moxie-tdep.c:546
struct gdbarch * gdbarch
Definition: gdbarch.h:1622
int regnum
Definition: aarch64-tdep.c:77
void printf_unfiltered(const char *format,...)
Definition: utils.c:2056
static struct gdbarch * moxie_gdbarch_init(struct gdbarch_info info, struct gdbarch_list *arches)
Definition: moxie-tdep.c:1095
typedef BP_MANIPULATION(moxie_break_insn)
Definition: moxie-tdep.c:69
ULONGEST get_frame_register_unsigned(struct frame_info *frame, int regnum)
Definition: frame.c:1308
static void moxie_extract_return_value(struct type *type, struct regcache *regcache, gdb_byte *dst)
Definition: moxie-tdep.c:482
static struct type * moxie_register_type(struct gdbarch *gdbarch, int reg_nr)
Definition: moxie-tdep.c:94
void set_gdbarch_breakpoint_kind_from_pc(struct gdbarch *gdbarch, gdbarch_breakpoint_kind_from_pc_ftype breakpoint_kind_from_pc)
Definition: gdbarch.c:2871
struct symbol * symbol
Definition: symtab.h:1136
Definition: regdef.h:22
int record_full_arch_list_add_mem(CORE_ADDR addr, int len)
Definition: record-full.c:491
#define gdb_assert(expr)
Definition: gdb_assert.h:32
Definition: value.c:169
void set_gdbarch_software_single_step(struct gdbarch *gdbarch, gdbarch_software_single_step_ftype software_single_step)
Definition: gdbarch.c:3258
static CORE_ADDR moxie_analyze_prologue(CORE_ADDR start_addr, CORE_ADDR end_addr, struct moxie_frame_cache *cache, struct gdbarch *gdbarch)
Definition: moxie-tdep.c:133
int core_addr_lessthan(CORE_ADDR lhs, CORE_ADDR rhs)
Definition: arch-utils.c:117
bfd_byte gdb_byte
Definition: common-types.h:38
#define XCNEW(T)
Definition: poison.h:121
LONGEST framesize
Definition: moxie-tdep.c:52
enum register_status regcache_raw_read(struct regcache *regcache, int regnum, gdb_byte *buf)
Definition: regcache.c:565
struct value * frame_unwind_got_register(struct frame_info *frame, int regnum, int new_regnum)
Definition: frame-unwind.c:223
void regcache_cooked_write_unsigned(struct regcache *regcache, int regnum, ULONGEST val)
Definition: regcache.c:806
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: target.c:1370
CORE_ADDR regcache_read_pc(struct regcache *regcache)
Definition: regcache.c:1229
struct type * builtin_data_ptr
Definition: gdbtypes.h:1554
#define INST2OFFSET(o)
Definition: moxie-tdep.c:294
constexpr gdb_byte moxie_break_insn[]
Definition: moxie-tdep.c:67
int offset
Definition: agent.c:65
gdbarch * arch() const
Definition: regcache.c:221
#define SYMBOL_LANGUAGE(symbol)
Definition: symtab.h:469
unsigned long long ULONGEST
Definition: common-types.h:53
enum unwind_stop_reason default_frame_unwind_stop_reason(struct frame_info *this_frame, void **this_cache)
Definition: frame-unwind.c:184
struct trad_frame_saved_reg * saved_regs
Definition: moxie-tdep.c:270
void _initialize_moxie_tdep(void)
Definition: moxie-tdep.c:1162
#define gdb_stdlog
Definition: utils.h:349
CORE_ADDR addr
Definition: frame.c:128
void set_gdbarch_return_value(struct gdbarch *gdbarch, gdbarch_return_value_ftype return_value)
Definition: gdbarch.c:2738
static struct moxie_frame_cache * moxie_alloc_frame_cache(void)
Definition: moxie-tdep.c:526
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1235
ULONGEST read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition: corefile.c:326
CORE_ADDR prev_sp
Definition: moxie-tdep.c:259
void set_gdbarch_sw_breakpoint_from_kind(struct gdbarch *gdbarch, gdbarch_sw_breakpoint_from_kind_ftype sw_breakpoint_from_kind)
Definition: gdbarch.c:2888
void register_gdbarch_init(enum bfd_architecture bfd_architecture, gdbarch_init_ftype *init)
Definition: gdbarch.c:5299
void set_gdbarch_skip_prologue(struct gdbarch *gdbarch, gdbarch_skip_prologue_ftype skip_prologue)
Definition: gdbarch.c:2772
static void moxie_store_return_value(struct type *type, struct regcache *regcache, const gdb_byte *valbuf)
Definition: moxie-tdep.c:108
enum bfd_endian byte_order
Definition: gdbarch.c:137
void set_gdbarch_pc_regnum(struct gdbarch *gdbarch, int pc_regnum)
Definition: gdbarch.c:2173
int record_full_arch_list_add_end(void)
Definition: record-full.c:522
CORE_ADDR pc
Definition: moxie-tdep.c:51
void set_gdbarch_register_name(struct gdbarch *gdbarch, gdbarch_register_name_ftype register_name)
Definition: gdbarch.c:2292
CORE_ADDR get_frame_func(struct frame_info *this_frame)
Definition: frame.c:1001
struct gdbarch * gdbarch_alloc(const struct gdbarch_info *info, struct gdbarch_tdep *tdep)
Definition: gdbarch.c:361
void set_gdbarch_inner_than(struct gdbarch *gdbarch, gdbarch_inner_than_ftype inner_than)
Definition: gdbarch.c:2837
static ULONGEST moxie_process_readu(CORE_ADDR addr, gdb_byte *buf, int length, enum bfd_endian byte_order)
Definition: moxie-tdep.c:276
static void moxie_write_pc(struct regcache *regcache, CORE_ADDR val)
Definition: moxie-tdep.c:465
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2691
long long LONGEST
Definition: common-types.h:52
#define MOXIE_NUM_REGS
Definition: moxie-tdep.h:41
static void store_unsigned_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, ULONGEST val)
Definition: defs.h:604