GDB (xrefs)
/tmp/gdb-7.10/gdb/iq2000-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for the IQ2000 architecture, for GDB, the GNU
2  Debugger.
3 
4  Copyright (C) 2000-2015 Free Software Foundation, Inc.
5 
6  Contributed by Red Hat.
7 
8  This file is part of GDB.
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 3 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 
23 #include "defs.h"
24 #include "frame.h"
25 #include "frame-base.h"
26 #include "frame-unwind.h"
27 #include "dwarf2-frame.h"
28 #include "gdbtypes.h"
29 #include "value.h"
30 #include "dis-asm.h"
31 #include "arch-utils.h"
32 #include "regcache.h"
33 #include "osabi.h"
34 #include "gdbcore.h"
35 
37 {
47  E_LR_REGNUM = E_R31_REGNUM, /* Link register. */
48  E_SP_REGNUM = E_R29_REGNUM, /* Stack pointer. */
49  E_FP_REGNUM = E_R27_REGNUM, /* Frame pointer. */
50  E_FN_RETURN_REGNUM = E_R2_REGNUM, /* Function return value register. */
51  E_1ST_ARGREG = E_R4_REGNUM, /* 1st function arg register. */
52  E_LAST_ARGREG = E_R11_REGNUM, /* Last function arg register. */
54 };
55 
56 /* Use an invalid address value as 'not available' marker. */
57 enum { REG_UNAVAIL = (CORE_ADDR) -1 };
58 
60 {
61  /* Base address. */
65  int using_fp;
68 };
69 
70 /* Harvard methods: */
71 
72 static CORE_ADDR
73 insn_ptr_from_addr (CORE_ADDR addr) /* CORE_ADDR to target pointer. */
74 {
75  return addr & 0x7fffffffL;
76 }
77 
78 static CORE_ADDR
79 insn_addr_from_ptr (CORE_ADDR ptr) /* target_pointer to CORE_ADDR. */
80 {
81  return (ptr & 0x7fffffffL) | 0x80000000L;
82 }
83 
84 /* Function: pointer_to_address
85  Convert a target pointer to an address in host (CORE_ADDR) format. */
86 
87 static CORE_ADDR
88 iq2000_pointer_to_address (struct gdbarch *gdbarch,
89  struct type * type, const gdb_byte * buf)
90 {
91  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
92  enum type_code target = TYPE_CODE (TYPE_TARGET_TYPE (type));
93  CORE_ADDR addr
94  = extract_unsigned_integer (buf, TYPE_LENGTH (type), byte_order);
95 
96  if (target == TYPE_CODE_FUNC
97  || target == TYPE_CODE_METHOD
99  addr = insn_addr_from_ptr (addr);
100 
101  return addr;
102 }
103 
104 /* Function: address_to_pointer
105  Convert a host-format address (CORE_ADDR) into a target pointer. */
106 
107 static void
108 iq2000_address_to_pointer (struct gdbarch *gdbarch,
109  struct type *type, gdb_byte *buf, CORE_ADDR addr)
110 {
111  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
112  enum type_code target = TYPE_CODE (TYPE_TARGET_TYPE (type));
113 
114  if (target == TYPE_CODE_FUNC || target == TYPE_CODE_METHOD)
115  addr = insn_ptr_from_addr (addr);
116  store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order, addr);
117 }
118 
119 /* Real register methods: */
120 
121 /* Function: register_name
122  Returns the name of the iq2000 register number N. */
123 
124 static const char *
125 iq2000_register_name (struct gdbarch *gdbarch, int regnum)
126 {
127  static const char * names[E_NUM_REGS] =
128  {
129  "r0", "r1", "r2", "r3", "r4",
130  "r5", "r6", "r7", "r8", "r9",
131  "r10", "r11", "r12", "r13", "r14",
132  "r15", "r16", "r17", "r18", "r19",
133  "r20", "r21", "r22", "r23", "r24",
134  "r25", "r26", "r27", "r28", "r29",
135  "r30", "r31",
136  "pc"
137  };
138  if (regnum < 0 || regnum >= E_NUM_REGS)
139  return NULL;
140  return names[regnum];
141 }
142 
143 /* Prologue analysis methods: */
144 
145 /* ADDIU insn (001001 rs(5) rt(5) imm(16)). */
146 #define INSN_IS_ADDIU(X) (((X) & 0xfc000000) == 0x24000000)
147 #define ADDIU_REG_SRC(X) (((X) & 0x03e00000) >> 21)
148 #define ADDIU_REG_TGT(X) (((X) & 0x001f0000) >> 16)
149 #define ADDIU_IMMEDIATE(X) ((signed short) ((X) & 0x0000ffff))
150 
151 /* "MOVE" (OR) insn (000000 rs(5) rt(5) rd(5) 00000 100101). */
152 #define INSN_IS_MOVE(X) (((X) & 0xffe007ff) == 0x00000025)
153 #define MOVE_REG_SRC(X) (((X) & 0x001f0000) >> 16)
154 #define MOVE_REG_TGT(X) (((X) & 0x0000f800) >> 11)
155 
156 /* STORE WORD insn (101011 rs(5) rt(5) offset(16)). */
157 #define INSN_IS_STORE_WORD(X) (((X) & 0xfc000000) == 0xac000000)
158 #define SW_REG_INDEX(X) (((X) & 0x03e00000) >> 21)
159 #define SW_REG_SRC(X) (((X) & 0x001f0000) >> 16)
160 #define SW_OFFSET(X) ((signed short) ((X) & 0x0000ffff))
161 
162 /* Function: find_last_line_symbol
163 
164  Given an address range, first find a line symbol corresponding to
165  the starting address. Then find the last line symbol within the
166  range that has a line number less than or equal to the first line.
167 
168  For optimized code with code motion, this finds the last address
169  for the lowest-numbered line within the address range. */
170 
171 static struct symtab_and_line
173 {
174  struct symtab_and_line sal = find_pc_line (start, notcurrent);
175  struct symtab_and_line best_sal = sal;
176 
177  if (sal.pc == 0 || sal.line == 0 || sal.end == 0)
178  return sal;
179 
180  do
181  {
182  if (sal.line && sal.line <= best_sal.line)
183  best_sal = sal;
184  sal = find_pc_line (sal.end, notcurrent);
185  }
186  while (sal.pc && sal.pc < end);
187 
188  return best_sal;
189 }
190 
191 /* Function: scan_prologue
192  Decode the instructions within the given address range.
193  Decide when we must have reached the end of the function prologue.
194  If a frame_info pointer is provided, fill in its prologue information.
195 
196  Returns the address of the first instruction after the prologue. */
197 
198 static CORE_ADDR
199 iq2000_scan_prologue (struct gdbarch *gdbarch,
200  CORE_ADDR scan_start,
201  CORE_ADDR scan_end,
202  struct frame_info *fi,
203  struct iq2000_frame_cache *cache)
204 {
205  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
206  struct symtab_and_line sal;
207  CORE_ADDR pc;
208  CORE_ADDR loop_end;
209  int found_store_lr = 0;
210  int found_decr_sp = 0;
211  int srcreg;
212  int tgtreg;
213  signed short offset;
214 
215  if (scan_end == (CORE_ADDR) 0)
216  {
217  loop_end = scan_start + 100;
218  sal.end = sal.pc = 0;
219  }
220  else
221  {
222  loop_end = scan_end;
223  if (fi)
224  sal = find_last_line_symbol (scan_start, scan_end, 0);
225  else
226  sal.end = 0; /* Avoid GCC false warning. */
227  }
228 
229  /* Saved registers:
230  We first have to save the saved register's offset, and
231  only later do we compute its actual address. Since the
232  offset can be zero, we must first initialize all the
233  saved regs to minus one (so we can later distinguish
234  between one that's not saved, and one that's saved at zero). */
235  for (srcreg = 0; srcreg < E_NUM_REGS; srcreg ++)
236  cache->saved_regs[srcreg] = -1;
237  cache->using_fp = 0;
238  cache->framesize = 0;
239 
240  for (pc = scan_start; pc < loop_end; pc += 4)
241  {
242  LONGEST insn = read_memory_unsigned_integer (pc, 4, byte_order);
243  /* Skip any instructions writing to (sp) or decrementing the
244  SP. */
245  if ((insn & 0xffe00000) == 0xac200000)
246  {
247  /* sw using SP/%1 as base. */
248  /* LEGACY -- from assembly-only port. */
249  tgtreg = ((insn >> 16) & 0x1f);
250  if (tgtreg >= 0 && tgtreg < E_NUM_REGS)
251  cache->saved_regs[tgtreg] = -((signed short) (insn & 0xffff));
252 
253  if (tgtreg == E_LR_REGNUM)
254  found_store_lr = 1;
255  continue;
256  }
257 
258  if ((insn & 0xffff8000) == 0x20218000)
259  {
260  /* addi %1, %1, -N == addi %sp, %sp, -N */
261  /* LEGACY -- from assembly-only port. */
262  found_decr_sp = 1;
263  cache->framesize = -((signed short) (insn & 0xffff));
264  continue;
265  }
266 
267  if (INSN_IS_ADDIU (insn))
268  {
269  srcreg = ADDIU_REG_SRC (insn);
270  tgtreg = ADDIU_REG_TGT (insn);
271  offset = ADDIU_IMMEDIATE (insn);
272  if (srcreg == E_SP_REGNUM && tgtreg == E_SP_REGNUM)
273  cache->framesize = -offset;
274  continue;
275  }
276 
277  if (INSN_IS_STORE_WORD (insn))
278  {
279  srcreg = SW_REG_SRC (insn);
280  tgtreg = SW_REG_INDEX (insn);
281  offset = SW_OFFSET (insn);
282 
283  if (tgtreg == E_SP_REGNUM || tgtreg == E_FP_REGNUM)
284  {
285  /* "push" to stack (via SP or FP reg). */
286  if (cache->saved_regs[srcreg] == -1) /* Don't save twice. */
287  cache->saved_regs[srcreg] = offset;
288  continue;
289  }
290  }
291 
292  if (INSN_IS_MOVE (insn))
293  {
294  srcreg = MOVE_REG_SRC (insn);
295  tgtreg = MOVE_REG_TGT (insn);
296 
297  if (srcreg == E_SP_REGNUM && tgtreg == E_FP_REGNUM)
298  {
299  /* Copy sp to fp. */
300  cache->using_fp = 1;
301  continue;
302  }
303  }
304 
305  /* Unknown instruction encountered in frame. Bail out?
306  1) If we have a subsequent line symbol, we can keep going.
307  2) If not, we need to bail out and quit scanning instructions. */
308 
309  if (fi && sal.end && (pc < sal.end)) /* Keep scanning. */
310  continue;
311  else /* bail */
312  break;
313  }
314 
315  return pc;
316 }
317 
318 static void
320 {
321  int i;
322 
323  cache->base = 0;
324  cache->framesize = 0;
325  cache->using_fp = 0;
326  cache->saved_sp = 0;
327  for (i = 0; i < E_NUM_REGS; i++)
328  cache->saved_regs[i] = -1;
329 }
330 
331 /* Function: iq2000_skip_prologue
332  If the input address is in a function prologue,
333  returns the address of the end of the prologue;
334  else returns the input address.
335 
336  Note: the input address is likely to be the function start,
337  since this function is mainly used for advancing a breakpoint
338  to the first line, or stepping to the first line when we have
339  stepped into a function call. */
340 
341 static CORE_ADDR
342 iq2000_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
343 {
344  CORE_ADDR func_addr = 0 , func_end = 0;
345 
346  if (find_pc_partial_function (pc, NULL, & func_addr, & func_end))
347  {
348  struct symtab_and_line sal;
349  struct iq2000_frame_cache cache;
350 
351  /* Found a function. */
352  sal = find_pc_line (func_addr, 0);
353  if (sal.end && sal.end < func_end)
354  /* Found a line number, use it as end of prologue. */
355  return sal.end;
356 
357  /* No useable line symbol. Use prologue parsing method. */
358  iq2000_init_frame_cache (&cache);
359  return iq2000_scan_prologue (gdbarch, func_addr, func_end, NULL, &cache);
360  }
361 
362  /* No function symbol -- just return the PC. */
363  return (CORE_ADDR) pc;
364 }
365 
366 static struct iq2000_frame_cache *
367 iq2000_frame_cache (struct frame_info *this_frame, void **this_cache)
368 {
369  struct gdbarch *gdbarch = get_frame_arch (this_frame);
370  struct iq2000_frame_cache *cache;
371  CORE_ADDR current_pc;
372  int i;
373 
374  if (*this_cache)
375  return *this_cache;
376 
377  cache = FRAME_OBSTACK_ZALLOC (struct iq2000_frame_cache);
378  iq2000_init_frame_cache (cache);
379  *this_cache = cache;
380 
381  cache->base = get_frame_register_unsigned (this_frame, E_FP_REGNUM);
382 
383  current_pc = get_frame_pc (this_frame);
384  find_pc_partial_function (current_pc, NULL, &cache->pc, NULL);
385  if (cache->pc != 0)
386  iq2000_scan_prologue (gdbarch, cache->pc, current_pc, this_frame, cache);
387  if (!cache->using_fp)
388  cache->base = get_frame_register_unsigned (this_frame, E_SP_REGNUM);
389 
390  cache->saved_sp = cache->base + cache->framesize;
391 
392  for (i = 0; i < E_NUM_REGS; i++)
393  if (cache->saved_regs[i] != -1)
394  cache->saved_regs[i] += cache->base;
395 
396  return cache;
397 }
398 
399 static struct value *
400 iq2000_frame_prev_register (struct frame_info *this_frame, void **this_cache,
401  int regnum)
402 {
403  struct iq2000_frame_cache *cache = iq2000_frame_cache (this_frame,
404  this_cache);
405 
406  if (regnum == E_SP_REGNUM && cache->saved_sp)
407  return frame_unwind_got_constant (this_frame, regnum, cache->saved_sp);
408 
409  if (regnum == E_PC_REGNUM)
410  regnum = E_LR_REGNUM;
411 
412  if (regnum < E_NUM_REGS && cache->saved_regs[regnum] != -1)
413  return frame_unwind_got_memory (this_frame, regnum,
414  cache->saved_regs[regnum]);
415 
416  return frame_unwind_got_register (this_frame, regnum, regnum);
417 }
418 
419 static void
420 iq2000_frame_this_id (struct frame_info *this_frame, void **this_cache,
421  struct frame_id *this_id)
422 {
423  struct iq2000_frame_cache *cache = iq2000_frame_cache (this_frame,
424  this_cache);
425 
426  /* This marks the outermost frame. */
427  if (cache->base == 0)
428  return;
429 
430  *this_id = frame_id_build (cache->saved_sp, cache->pc);
431 }
432 
433 static const struct frame_unwind iq2000_frame_unwind = {
434  NORMAL_FRAME,
438  NULL,
440 };
441 
442 static CORE_ADDR
443 iq2000_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
444 {
445  return frame_unwind_register_unsigned (next_frame, E_SP_REGNUM);
446 }
447 
448 static CORE_ADDR
449 iq2000_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
450 {
451  return frame_unwind_register_unsigned (next_frame, E_PC_REGNUM);
452 }
453 
454 static struct frame_id
455 iq2000_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
456 {
458  return frame_id_build (sp, get_frame_pc (this_frame));
459 }
460 
461 static CORE_ADDR
462 iq2000_frame_base_address (struct frame_info *this_frame, void **this_cache)
463 {
464  struct iq2000_frame_cache *cache = iq2000_frame_cache (this_frame,
465  this_cache);
466 
467  return cache->base;
468 }
469 
470 static const struct frame_base iq2000_frame_base = {
474  iq2000_frame_base_address
475 };
476 
477 static const unsigned char *
478 iq2000_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
479  int *lenptr)
480 {
481  static const unsigned char big_breakpoint[] = { 0x00, 0x00, 0x00, 0x0d };
482  static const unsigned char little_breakpoint[] = { 0x0d, 0x00, 0x00, 0x00 };
483 
484  if ((*pcptr & 3) != 0)
485  error (_("breakpoint_from_pc: invalid breakpoint address 0x%lx"),
486  (long) *pcptr);
487 
488  *lenptr = 4;
489  return (gdbarch_byte_order (gdbarch)
490  == BFD_ENDIAN_BIG) ? big_breakpoint : little_breakpoint;
491 }
492 
493 /* Target function return value methods: */
494 
495 /* Function: store_return_value
496  Copy the function return value from VALBUF into the
497  proper location for a function return. */
498 
499 static void
501  const void *valbuf)
502 {
503  int len = TYPE_LENGTH (type);
504  int regno = E_FN_RETURN_REGNUM;
505 
506  while (len > 0)
507  {
508  gdb_byte buf[4];
509  int size = len % 4 ?: 4;
510 
511  memset (buf, 0, 4);
512  memcpy (buf + 4 - size, valbuf, size);
513  regcache_raw_write (regcache, regno++, buf);
514  len -= size;
515  valbuf = ((char *) valbuf) + size;
516  }
517 }
518 
519 /* Function: use_struct_convention
520  Returns non-zero if the given struct type will be returned using
521  a special convention, rather than the normal function return method. */
522 
523 static int
525 {
526  return ((TYPE_CODE (type) == TYPE_CODE_STRUCT)
527  || (TYPE_CODE (type) == TYPE_CODE_UNION))
528  && TYPE_LENGTH (type) > 8;
529 }
530 
531 /* Function: extract_return_value
532  Copy the function's return value into VALBUF.
533  This function is called only in the context of "target function calls",
534  ie. when the debugger forces a function to be called in the child, and
535  when the debugger forces a function to return prematurely via the
536  "return" command. */
537 
538 static void
540  void *valbuf)
541 {
542  struct gdbarch *gdbarch = get_regcache_arch (regcache);
543  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
544 
545  /* If the function's return value is 8 bytes or less, it is
546  returned in a register, and if larger than 8 bytes, it is
547  returned in a stack location which is pointed to by the same
548  register. */
549  int len = TYPE_LENGTH (type);
550 
551  if (len <= (2 * 4))
552  {
553  int regno = E_FN_RETURN_REGNUM;
554 
555  /* Return values of <= 8 bytes are returned in
556  FN_RETURN_REGNUM. */
557  while (len > 0)
558  {
559  ULONGEST tmp;
560  int size = len % 4 ?: 4;
561 
562  /* By using store_unsigned_integer we avoid having to
563  do anything special for small big-endian values. */
564  regcache_cooked_read_unsigned (regcache, regno++, &tmp);
565  store_unsigned_integer (valbuf, size, byte_order, tmp);
566  len -= size;
567  valbuf = ((char *) valbuf) + size;
568  }
569  }
570  else
571  {
572  /* Return values > 8 bytes are returned in memory,
573  pointed to by FN_RETURN_REGNUM. */
574  ULONGEST return_buffer;
576  &return_buffer);
577  read_memory (return_buffer, valbuf, TYPE_LENGTH (type));
578  }
579 }
580 
581 static enum return_value_convention
582 iq2000_return_value (struct gdbarch *gdbarch, struct value *function,
583  struct type *type, struct regcache *regcache,
584  gdb_byte *readbuf, const gdb_byte *writebuf)
585 {
586  if (iq2000_use_struct_convention (type))
588  if (writebuf)
589  iq2000_store_return_value (type, regcache, writebuf);
590  else if (readbuf)
591  iq2000_extract_return_value (type, regcache, readbuf);
593 }
594 
595 /* Function: register_virtual_type
596  Returns the default type for register N. */
597 
598 static struct type *
599 iq2000_register_type (struct gdbarch *gdbarch, int regnum)
600 {
601  return builtin_type (gdbarch)->builtin_int32;
602 }
603 
604 static CORE_ADDR
605 iq2000_frame_align (struct gdbarch *ignore, CORE_ADDR sp)
606 {
607  /* This is the same frame alignment used by gcc. */
608  return ((sp + 7) & ~7);
609 }
610 
611 /* Convenience function to check 8-byte types for being a scalar type
612  or a struct with only one long long or double member. */
613 static int
615 {
616  struct type *ftype;
617 
618  /* Skip typedefs. */
619  while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
620  type = TYPE_TARGET_TYPE (type);
621  /* Non-struct and non-union types are always passed by value. */
622  if (TYPE_CODE (type) != TYPE_CODE_STRUCT
623  && TYPE_CODE (type) != TYPE_CODE_UNION)
624  return 0;
625  /* Structs with more than 1 field are always passed by address. */
626  if (TYPE_NFIELDS (type) != 1)
627  return 1;
628  /* Get field type. */
629  ftype = (TYPE_FIELDS (type))[0].type;
630  /* The field type must have size 8, otherwise pass by address. */
631  if (TYPE_LENGTH (ftype) != 8)
632  return 1;
633  /* Skip typedefs of field type. */
634  while (TYPE_CODE (ftype) == TYPE_CODE_TYPEDEF)
635  ftype = TYPE_TARGET_TYPE (ftype);
636  /* If field is int or float, pass by value. */
637  if (TYPE_CODE (ftype) == TYPE_CODE_FLT
638  || TYPE_CODE (ftype) == TYPE_CODE_INT)
639  return 0;
640  /* Everything else, pass by address. */
641  return 1;
642 }
643 
644 static CORE_ADDR
645 iq2000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
646  struct regcache *regcache, CORE_ADDR bp_addr,
647  int nargs, struct value **args, CORE_ADDR sp,
648  int struct_return, CORE_ADDR struct_addr)
649 {
650  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
651  const bfd_byte *val;
652  bfd_byte buf[4];
653  struct type *type;
654  int i, argreg, typelen, slacklen;
655  int stackspace = 0;
656  /* Used to copy struct arguments into the stack. */
657  CORE_ADDR struct_ptr;
658 
659  /* First determine how much stack space we will need. */
660  for (i = 0, argreg = E_1ST_ARGREG + (struct_return != 0); i < nargs; i++)
661  {
662  type = value_type (args[i]);
663  typelen = TYPE_LENGTH (type);
664  if (typelen <= 4)
665  {
666  /* Scalars of up to 4 bytes,
667  structs of up to 4 bytes, and
668  pointers. */
669  if (argreg <= E_LAST_ARGREG)
670  argreg++;
671  else
672  stackspace += 4;
673  }
674  else if (typelen == 8 && !iq2000_pass_8bytetype_by_address (type))
675  {
676  /* long long,
677  double, and possibly
678  structs with a single field of long long or double. */
679  if (argreg <= E_LAST_ARGREG - 1)
680  {
681  /* 8-byte arg goes into a register pair
682  (must start with an even-numbered reg). */
683  if (((argreg - E_1ST_ARGREG) % 2) != 0)
684  argreg ++;
685  argreg += 2;
686  }
687  else
688  {
689  argreg = E_LAST_ARGREG + 1; /* no more argregs. */
690  /* 8-byte arg goes on stack, must be 8-byte aligned. */
691  stackspace = ((stackspace + 7) & ~7);
692  stackspace += 8;
693  }
694  }
695  else
696  {
697  /* Structs are passed as pointer to a copy of the struct.
698  So we need room on the stack for a copy of the struct
699  plus for the argument pointer. */
700  if (argreg <= E_LAST_ARGREG)
701  argreg++;
702  else
703  stackspace += 4;
704  /* Care for 8-byte alignment of structs saved on stack. */
705  stackspace += ((typelen + 7) & ~7);
706  }
707  }
708 
709  /* Now copy params, in ascending order, into their assigned location
710  (either in a register or on the stack). */
711 
712  sp -= (sp % 8); /* align */
713  struct_ptr = sp;
714  sp -= stackspace;
715  sp -= (sp % 8); /* align again */
716  stackspace = 0;
717 
718  argreg = E_1ST_ARGREG;
719  if (struct_return)
720  {
721  /* A function that returns a struct will consume one argreg to do so.
722  */
723  regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
724  }
725 
726  for (i = 0; i < nargs; i++)
727  {
728  type = value_type (args[i]);
729  typelen = TYPE_LENGTH (type);
730  val = value_contents (args[i]);
731  if (typelen <= 4)
732  {
733  /* Char, short, int, float, pointer, and structs <= four bytes. */
734  slacklen = (4 - (typelen % 4)) % 4;
735  memset (buf, 0, sizeof (buf));
736  memcpy (buf + slacklen, val, typelen);
737  if (argreg <= E_LAST_ARGREG)
738  {
739  /* Passed in a register. */
740  regcache_raw_write (regcache, argreg++, buf);
741  }
742  else
743  {
744  /* Passed on the stack. */
745  write_memory (sp + stackspace, buf, 4);
746  stackspace += 4;
747  }
748  }
749  else if (typelen == 8 && !iq2000_pass_8bytetype_by_address (type))
750  {
751  /* (long long), (double), or struct consisting of
752  a single (long long) or (double). */
753  if (argreg <= E_LAST_ARGREG - 1)
754  {
755  /* 8-byte arg goes into a register pair
756  (must start with an even-numbered reg). */
757  if (((argreg - E_1ST_ARGREG) % 2) != 0)
758  argreg++;
759  regcache_raw_write (regcache, argreg++, val);
760  regcache_raw_write (regcache, argreg++, val + 4);
761  }
762  else
763  {
764  /* 8-byte arg goes on stack, must be 8-byte aligned. */
765  argreg = E_LAST_ARGREG + 1; /* no more argregs. */
766  stackspace = ((stackspace + 7) & ~7);
767  write_memory (sp + stackspace, val, typelen);
768  stackspace += 8;
769  }
770  }
771  else
772  {
773  /* Store struct beginning at the upper end of the previously
774  computed stack space. Then store the address of the struct
775  using the usual rules for a 4 byte value. */
776  struct_ptr -= ((typelen + 7) & ~7);
777  write_memory (struct_ptr, val, typelen);
778  if (argreg <= E_LAST_ARGREG)
779  regcache_cooked_write_unsigned (regcache, argreg++, struct_ptr);
780  else
781  {
782  store_unsigned_integer (buf, 4, byte_order, struct_ptr);
783  write_memory (sp + stackspace, buf, 4);
784  stackspace += 4;
785  }
786  }
787  }
788 
789  /* Store return address. */
790  regcache_cooked_write_unsigned (regcache, E_LR_REGNUM, bp_addr);
791 
792  /* Update stack pointer. */
794 
795  /* And that should do it. Return the new stack pointer. */
796  return sp;
797 }
798 
799 /* Function: gdbarch_init
800  Initializer function for the iq2000 gdbarch vector.
801  Called by gdbarch. Sets up the gdbarch vector(s) for this target. */
802 
803 static struct gdbarch *
804 iq2000_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
805 {
806  struct gdbarch *gdbarch;
807 
808  /* Look up list for candidates - only one. */
809  arches = gdbarch_list_lookup_by_info (arches, &info);
810  if (arches != NULL)
811  return arches->gdbarch;
812 
813  gdbarch = gdbarch_alloc (&info, NULL);
814 
815  set_gdbarch_num_regs (gdbarch, E_NUM_REGS);
816  set_gdbarch_num_pseudo_regs (gdbarch, 0);
822  set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
823  set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);
824  set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
825  set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT);
827  set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT);
835  set_gdbarch_frame_args_skip (gdbarch, 0);
838  set_gdbarch_print_insn (gdbarch, print_insn_iq2000);
844  frame_base_set_default (gdbarch, &iq2000_frame_base);
846 
847  gdbarch_init_osabi (info, gdbarch);
848 
849  dwarf2_append_unwinders (gdbarch);
850  frame_unwind_append_unwinder (gdbarch, &iq2000_frame_unwind);
851 
852  return gdbarch;
853 }
854 
855 /* Function: _initialize_iq2000_tdep
856  Initializer function for the iq2000 module.
857  Called by gdb at start-up. */
858 
859 /* Provide a prototype to silence -Wmissing-prototypes. */
861 
862 void
864 {
865  register_gdbarch_init (bfd_arch_iq2000, iq2000_gdbarch_init);
866 }
void set_gdbarch_num_regs(struct gdbarch *gdbarch, int num_regs)
Definition: gdbarch.c:1909
void set_gdbarch_double_bit(struct gdbarch *gdbarch, int double_bit)
Definition: gdbarch.c:1634
void set_gdbarch_frame_align(struct gdbarch *gdbarch, gdbarch_frame_align_ftype frame_align)
Definition: gdbarch.c:2935
static CORE_ADDR iq2000_unwind_pc(struct gdbarch *gdbarch, struct frame_info *next_frame)
Definition: iq2000-tdep.c:449
void set_gdbarch_float_format(struct gdbarch *gdbarch, const struct floatformat **float_format)
Definition: gdbarch.c:1617
static int iq2000_pass_8bytetype_by_address(struct type *type)
Definition: iq2000-tdep.c:614
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
Definition: findvar.c:84
static int iq2000_use_struct_convention(struct type *type)
Definition: iq2000-tdep.c:524
type_code
Definition: gdbtypes.h:85
static struct symtab_and_line find_last_line_symbol(CORE_ADDR start, CORE_ADDR end, int notcurrent)
Definition: iq2000-tdep.c:172
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:554
void set_gdbarch_float_bit(struct gdbarch *gdbarch, int float_bit)
Definition: gdbarch.c:1601
CORE_ADDR get_frame_pc(struct frame_info *frame)
Definition: frame.c:2217
static struct type * iq2000_register_type(struct gdbarch *gdbarch, int regnum)
Definition: iq2000-tdep.c:599
static struct frame_id iq2000_dummy_id(struct gdbarch *gdbarch, struct frame_info *this_frame)
Definition: iq2000-tdep.c:455
bfd_vma CORE_ADDR
Definition: common-types.h:41
void gdbarch_init_osabi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition: osabi.c:341
const struct floatformat * floatformats_ieee_double[BFD_ENDIAN_UNKNOWN]
Definition: gdbtypes.c:74
#define INSN_IS_STORE_WORD(X)
Definition: iq2000-tdep.c:157
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
Definition: regcache.c:297
struct value * frame_unwind_got_memory(struct frame_info *frame, int regnum, CORE_ADDR addr)
Definition: frame-unwind.c:228
CORE_ADDR end
Definition: symtab.h:1377
ULONGEST frame_unwind_register_unsigned(struct frame_info *frame, int regnum)
Definition: frame.c:1182
void set_gdbarch_short_bit(struct gdbarch *gdbarch, int short_bit)
Definition: gdbarch.c:1483
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
Definition: gdbtypes.c:4766
static const char * iq2000_register_name(struct gdbarch *gdbarch, int regnum)
Definition: iq2000-tdep.c:125
return_value_convention
Definition: defs.h:206
static struct value * iq2000_frame_prev_register(struct frame_info *this_frame, void **this_cache, int regnum)
Definition: iq2000-tdep.c:400
static CORE_ADDR iq2000_frame_align(struct gdbarch *ignore, CORE_ADDR sp)
Definition: iq2000-tdep.c:605
struct gdbarch_list * gdbarch_list_lookup_by_info(struct gdbarch_list *arches, const struct gdbarch_info *info)
Definition: gdbarch.c:4985
#define _(String)
Definition: gdb_locale.h:40
static CORE_ADDR iq2000_frame_base_address(struct frame_info *this_frame, void **this_cache)
Definition: iq2000-tdep.c:462
static CORE_ADDR iq2000_pointer_to_address(struct gdbarch *gdbarch, struct type *type, const gdb_byte *buf)
Definition: iq2000-tdep.c:88
static CORE_ADDR iq2000_scan_prologue(struct gdbarch *gdbarch, CORE_ADDR scan_start, CORE_ADDR scan_end, struct frame_info *fi, struct iq2000_frame_cache *cache)
Definition: iq2000-tdep.c:199
CORE_ADDR saved_regs[E_NUM_REGS]
Definition: iq2000-tdep.c:67
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
Definition: frame-unwind.c:78
struct type * builtin_int32
Definition: gdbtypes.h:1518
static const unsigned char * iq2000_breakpoint_from_pc(struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
Definition: iq2000-tdep.c:478
#define FRAME_OBSTACK_ZALLOC(TYPE)
Definition: frame.h:660
void store_unsigned_integer(gdb_byte *, int, enum bfd_endian, ULONGEST)
Definition: findvar.c:212
#define TYPE_CODE_SPACE(t)
Definition: gdbtypes.h:384
struct value * frame_unwind_got_constant(struct frame_info *frame, int regnum, ULONGEST val)
Definition: frame-unwind.c:241
static CORE_ADDR iq2000_skip_prologue(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: iq2000-tdep.c:342
void frame_base_set_default(struct gdbarch *gdbarch, const struct frame_base *default_base)
Definition: frame-base.c:94
void set_gdbarch_register_type(struct gdbarch *gdbarch, gdbarch_register_type_ftype register_type)
Definition: gdbarch.c:2151
const gdb_byte * value_contents(struct value *value)
Definition: value.c:1329
void initialize_file_ftype(void)
Definition: defs.h:281
struct symtab_and_line find_pc_line(CORE_ADDR pc, int notcurrent)
Definition: symtab.c:3315
enum register_status regcache_cooked_read_unsigned(struct regcache *regcache, int regnum, ULONGEST *val)
Definition: regcache.c:837
void set_gdbarch_sp_regnum(struct gdbarch *gdbarch, int sp_regnum)
Definition: gdbarch.c:1991
void set_gdbarch_dummy_id(struct gdbarch *gdbarch, gdbarch_dummy_id_ftype dummy_id)
Definition: gdbarch.c:2175
struct_return
Definition: arm-tdep.h:148
void set_gdbarch_address_to_pointer(struct gdbarch *gdbarch, gdbarch_address_to_pointer_ftype address_to_pointer)
Definition: gdbarch.c:2508
#define INSN_IS_ADDIU(X)
Definition: iq2000-tdep.c:146
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
static enum return_value_convention iq2000_return_value(struct gdbarch *gdbarch, struct value *function, struct type *type, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
Definition: iq2000-tdep.c:582
static CORE_ADDR insn_ptr_from_addr(CORE_ADDR addr)
Definition: iq2000-tdep.c:73
#define SW_REG_INDEX(X)
Definition: iq2000-tdep.c:158
#define TARGET_CHAR_BIT
Definition: host-defs.h:29
Definition: gdbtypes.h:749
int find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr)
Definition: blockframe.c:321
void set_gdbarch_unwind_pc(struct gdbarch *gdbarch, gdbarch_unwind_pc_ftype unwind_pc)
Definition: gdbarch.c:2863
void set_gdbarch_breakpoint_from_pc(struct gdbarch *gdbarch, gdbarch_breakpoint_from_pc_ftype breakpoint_from_pc)
Definition: gdbarch.c:2672
int default_frame_sniffer(const struct frame_unwind *self, struct frame_info *this_frame, void **this_prologue_cache)
Definition: frame-unwind.c:170
static const char * type
Definition: language.c:103
void set_gdbarch_pointer_to_address(struct gdbarch *gdbarch, gdbarch_pointer_to_address_ftype pointer_to_address)
Definition: gdbarch.c:2491
static CORE_ADDR iq2000_unwind_sp(struct gdbarch *gdbarch, struct frame_info *next_frame)
Definition: iq2000-tdep.c:443
void set_gdbarch_unwind_sp(struct gdbarch *gdbarch, gdbarch_unwind_sp_ftype unwind_sp)
Definition: gdbarch.c:2887
static CORE_ADDR insn_addr_from_ptr(CORE_ADDR ptr)
Definition: iq2000-tdep.c:79
static struct iq2000_frame_cache * iq2000_frame_cache(struct frame_info *this_frame, void **this_cache)
Definition: iq2000-tdep.c:367
struct gdbarch * gdbarch
Definition: gdbarch.h:1542
int regnum
Definition: aarch64-tdep.c:69
#define TYPE_FIELDS(thistype)
Definition: gdbtypes.h:1242
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:244
#define SW_OFFSET(X)
Definition: iq2000-tdep.c:160
ULONGEST get_frame_register_unsigned(struct frame_info *frame, int regnum)
Definition: frame.c:1194
gdb_regnum
Definition: arm-tdep.h:29
void set_gdbarch_frame_args_skip(struct gdbarch *gdbarch, CORE_ADDR frame_args_skip)
Definition: gdbarch.c:2839
void set_gdbarch_long_long_bit(struct gdbarch *gdbarch, int long_long_bit)
Definition: gdbarch.c:1534
static void iq2000_init_frame_cache(struct iq2000_frame_cache *cache)
Definition: iq2000-tdep.c:319
Definition: value.c:172
static void iq2000_address_to_pointer(struct gdbarch *gdbarch, struct type *type, gdb_byte *buf, CORE_ADDR addr)
Definition: iq2000-tdep.c:108
const struct floatformat * floatformats_ieee_single[BFD_ENDIAN_UNKNOWN]
Definition: gdbtypes.c:70
#define INSN_IS_MOVE(X)
Definition: iq2000-tdep.c:152
static void iq2000_extract_return_value(struct type *type, struct regcache *regcache, void *valbuf)
Definition: iq2000-tdep.c:539
#define MOVE_REG_TGT(X)
Definition: iq2000-tdep.c:154
const char const char int
Definition: command.h:229
int core_addr_lessthan(CORE_ADDR lhs, CORE_ADDR rhs)
Definition: arch-utils.c:138
bfd_byte gdb_byte
Definition: common-types.h:38
#define TYPE_TARGET_TYPE(thistype)
Definition: gdbtypes.h:1229
static struct gdbarch * iq2000_gdbarch_init(struct gdbarch_info info, struct gdbarch_list *arches)
Definition: iq2000-tdep.c:804
static void iq2000_frame_this_id(struct frame_info *this_frame, void **this_cache, struct frame_id *this_id)
Definition: iq2000-tdep.c:420
#define TYPE_CODE(thistype)
Definition: gdbtypes.h:1240
void regcache_cooked_write_unsigned(struct regcache *regcache, int regnum, ULONGEST val)
Definition: regcache.c:871
struct value * frame_unwind_got_register(struct frame_info *frame, int regnum, int new_regnum)
Definition: frame-unwind.c:218
void set_gdbarch_int_bit(struct gdbarch *gdbarch, int int_bit)
Definition: gdbarch.c:1500
static const struct frame_unwind iq2000_frame_unwind
Definition: iq2000-tdep.c:433
int offset
Definition: agent.c:65
CORE_ADDR saved_sp
Definition: iq2000-tdep.c:66
#define TYPE_NFIELDS(thistype)
Definition: gdbtypes.h:1241
void set_gdbarch_num_pseudo_regs(struct gdbarch *gdbarch, int num_pseudo_regs)
Definition: gdbarch.c:1926
#define SW_REG_SRC(X)
Definition: iq2000-tdep.c:159
void dwarf2_append_unwinders(struct gdbarch *gdbarch)
CORE_ADDR pc
Definition: symtab.h:1376
void set_gdbarch_double_format(struct gdbarch *gdbarch, const struct floatformat **double_format)
Definition: gdbarch.c:1650
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:180
static void iq2000_store_return_value(struct type *type, struct regcache *regcache, const void *valbuf)
Definition: iq2000-tdep.c:500
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
Definition: corelow.c:917
#define ADDIU_REG_TGT(X)
Definition: iq2000-tdep.c:148
void set_gdbarch_long_double_bit(struct gdbarch *gdbarch, int long_double_bit)
Definition: gdbarch.c:1667
struct type * value_type(const struct value *value)
Definition: value.c:1021
void set_gdbarch_long_bit(struct gdbarch *gdbarch, int long_bit)
Definition: gdbarch.c:1517
Definition: ia64-tdep.c:84
void set_gdbarch_return_value(struct gdbarch *gdbarch, gdbarch_return_value_ftype return_value)
Definition: gdbarch.c:2556
void set_gdbarch_long_double_format(struct gdbarch *gdbarch, const struct floatformat **long_double_format)
Definition: gdbarch.c:1683
#define MOVE_REG_SRC(X)
Definition: iq2000-tdep.c:153
#define ADDIU_IMMEDIATE(X)
Definition: iq2000-tdep.c:149
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1237
void set_gdbarch_ptr_bit(struct gdbarch *gdbarch, int ptr_bit)
Definition: gdbarch.c:1700
initialize_file_ftype _initialize_iq2000_tdep
void set_gdbarch_push_dummy_call(struct gdbarch *gdbarch, gdbarch_push_dummy_call_ftype push_dummy_call)
Definition: gdbarch.c:2216
ULONGEST read_memory_unsigned_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition: corefile.c:321
#define ADDIU_REG_SRC(X)
Definition: iq2000-tdep.c:147
void register_gdbarch_init(enum bfd_architecture bfd_architecture, gdbarch_init_ftype *init)
Definition: gdbarch.c:4975
void write_memory(CORE_ADDR memaddr, const bfd_byte *myaddr, ssize_t len)
Definition: corefile.c:389
void set_gdbarch_skip_prologue(struct gdbarch *gdbarch, gdbarch_skip_prologue_ftype skip_prologue)
Definition: gdbarch.c:2590
static CORE_ADDR iq2000_push_dummy_call(struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr)
Definition: iq2000-tdep.c:645
enum bfd_endian byte_order
Definition: gdbarch.c:128
void set_gdbarch_pc_regnum(struct gdbarch *gdbarch, int pc_regnum)
Definition: gdbarch.c:2008
void set_gdbarch_register_name(struct gdbarch *gdbarch, gdbarch_register_name_ftype register_name)
Definition: gdbarch.c:2127
void error(const char *fmt,...)
Definition: errors.c:38
size_t size
Definition: go32-nat.c:242
struct gdbarch * gdbarch_alloc(const struct gdbarch_info *info, struct gdbarch_tdep *tdep)
Definition: gdbarch.c:339
void set_gdbarch_inner_than(struct gdbarch *gdbarch, gdbarch_inner_than_ftype inner_than)
Definition: gdbarch.c:2655
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2535
long long LONGEST
Definition: common-types.h:52
void set_gdbarch_print_insn(struct gdbarch *gdbarch, gdbarch_print_insn_ftype print_insn)
Definition: gdbarch.c:3067
void regcache_raw_write(struct regcache *regcache, int regnum, const gdb_byte *buf)
Definition: regcache.c:885
const ULONGEST const LONGEST len
Definition: target.h:309