GDB (xrefs)
/tmp/gdb-7.10/gdb/score-tdep.c
Go to the documentation of this file.
1 /* Target-dependent code for the S+core architecture, for GDB,
2  the GNU Debugger.
3 
4  Copyright (C) 2006-2015 Free Software Foundation, Inc.
5 
6  Contributed by Qinwei (qinwei@sunnorth.com.cn)
7  Contributed by Ching-Peng Lin (cplin@sunplus.com)
8 
9  This file is part of GDB.
10 
11  This program is free software; you can redistribute it and/or modify
12  it under the terms of the GNU General Public License as published by
13  the Free Software Foundation; either version 3 of the License, or
14  (at your option) any later version.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 
24 #include "defs.h"
25 #include "inferior.h"
26 #include "symtab.h"
27 #include "objfiles.h"
28 #include "gdbcore.h"
29 #include "target.h"
30 #include "arch-utils.h"
31 #include "regcache.h"
32 #include "regset.h"
33 #include "dis-asm.h"
34 #include "frame-unwind.h"
35 #include "frame-base.h"
36 #include "trad-frame.h"
37 #include "dwarf2-frame.h"
38 #include "score-tdep.h"
39 
40 #define G_FLD(_i,_ms,_ls) \
41  ((unsigned)((_i) << (31 - (_ms))) >> (31 - (_ms) + (_ls)))
42 
43 typedef struct{
44  unsigned long long v;
45  unsigned long long raw;
46  unsigned int len;
47 }inst_t;
48 
50 {
54 };
55 
56 static int target_mach = bfd_mach_score7;
57 
58 static struct type *
59 score_register_type (struct gdbarch *gdbarch, int regnum)
60 {
61  gdb_assert (regnum >= 0
62  && regnum < ((target_mach == bfd_mach_score7)
64  return builtin_type (gdbarch)->builtin_uint32;
65 }
66 
67 static CORE_ADDR
68 score_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
69 {
71 }
72 
73 static CORE_ADDR
74 score_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
75 {
77 }
78 
79 static const char *
80 score7_register_name (struct gdbarch *gdbarch, int regnum)
81 {
82  const char *score_register_names[] = {
83  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
84  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
85  "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
86  "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
87 
88  "PSR", "COND", "ECR", "EXCPVEC", "CCR",
89  "EPC", "EMA", "TLBLOCK", "TLBPT", "PEADDR",
90  "TLBRPT", "PEVN", "PECTX", "LIMPFN", "LDMPFN",
91  "PREV", "DREG", "PC", "DSAVE", "COUNTER",
92  "LDCR", "STCR", "CEH", "CEL",
93  };
94 
95  gdb_assert (regnum >= 0 && regnum < SCORE7_NUM_REGS);
96  return score_register_names[regnum];
97 }
98 
99 static const char *
100 score3_register_name (struct gdbarch *gdbarch, int regnum)
101 {
102  const char *score_register_names[] = {
103  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
104  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
105  "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
106  "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
107 
108  "PSR", "COND", "ECR", "EXCPVEC", "CCR",
109  "EPC", "EMA", "PREV", "DREG", "DSAVE",
110  "COUNTER", "LDCR", "STCR", "CEH", "CEL",
111  "", "", "PC",
112  };
113 
114  gdb_assert (regnum >= 0 && regnum < SCORE3_NUM_REGS);
115  return score_register_names[regnum];
116 }
117 
118 #if WITH_SIM
119 static int
120 score_register_sim_regno (struct gdbarch *gdbarch, int regnum)
121 {
122  gdb_assert (regnum >= 0
123  && regnum < ((target_mach == bfd_mach_score7)
125  return regnum;
126 }
127 #endif
128 
129 static int
130 score_print_insn (bfd_vma memaddr, struct disassemble_info *info)
131 {
132  if (info->endian == BFD_ENDIAN_BIG)
133  return print_insn_big_score (memaddr, info);
134  else
135  return print_insn_little_score (memaddr, info);
136 }
137 
138 static inst_t *
139 score7_fetch_inst (struct gdbarch *gdbarch, CORE_ADDR addr, gdb_byte *memblock)
140 {
141  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
142  static inst_t inst = { 0, 0, 0 };
143  gdb_byte buf[SCORE_INSTLEN] = { 0 };
144  int big;
145  int ret;
146 
147  if (target_has_execution && memblock != NULL)
148  {
149  /* Fetch instruction from local MEMBLOCK. */
150  memcpy (buf, memblock, SCORE_INSTLEN);
151  }
152  else
153  {
154  /* Fetch instruction from target. */
155  ret = target_read_memory (addr & ~0x3, buf, SCORE_INSTLEN);
156  if (ret)
157  {
158  error (_("Error: target_read_memory in file:%s, line:%d!"),
159  __FILE__, __LINE__);
160  return 0;
161  }
162  }
163 
164  inst.raw = extract_unsigned_integer (buf, SCORE_INSTLEN, byte_order);
165  inst.len = (inst.raw & 0x80008000) ? 4 : 2;
166  inst.v = ((inst.raw >> 16 & 0x7FFF) << 15) | (inst.raw & 0x7FFF);
167  big = (byte_order == BFD_ENDIAN_BIG);
168  if (inst.len == 2)
169  {
170  if (big ^ ((addr & 0x2) == 2))
171  inst.v = G_FLD (inst.v, 29, 15);
172  else
173  inst.v = G_FLD (inst.v, 14, 0);
174  }
175  return &inst;
176 }
177 
178 static inst_t *
180  enum bfd_endian byte_order)
181 {
182  static inst_t inst = { 0, 0, 0 };
183 
184  struct breakplace
185  {
186  int break_offset;
187  int inst_len;
188  };
189  /* raw table 1 (column 2, 3, 4)
190  * 0 1 0 * # 2
191  * 0 1 1 0 # 3
192  0 1 1 0 * # 6
193  table 2 (column 1, 2, 3)
194  * 0 0 * * # 0, 4
195  0 1 0 * * # 2
196  1 1 0 * * # 6
197  */
198 
199  static const struct breakplace bk_table[16] =
200  {
201  /* table 1 */
202  {0, 0},
203  {0, 0},
204  {0, 4},
205  {0, 6},
206  {0, 0},
207  {0, 0},
208  {-2, 6},
209  {0, 0},
210  /* table 2 */
211  {0, 2},
212  {0, 0},
213  {-2, 4},
214  {0, 0},
215  {0, 2},
216  {0, 0},
217  {-4, 6},
218  {0, 0}
219  };
220 
221 #define EXTRACT_LEN 2
222  CORE_ADDR adjust_pc = *pcptr & ~0x1;
223  gdb_byte buf[5][EXTRACT_LEN] =
224  {
225  {'\0', '\0'},
226  {'\0', '\0'},
227  {'\0', '\0'},
228  {'\0', '\0'},
229  {'\0', '\0'}
230  };
231  int ret;
232  unsigned int raw;
233  unsigned int cbits = 0;
234  int bk_index;
235  int i, count;
236 
237  inst.v = 0;
238  inst.raw = 0;
239  inst.len = 0;
240 
241  adjust_pc -= 4;
242  for (i = 0; i < 5; i++)
243  {
244  ret = target_read_memory (adjust_pc + 2 * i, buf[i], EXTRACT_LEN);
245  if (ret != 0)
246  {
247  buf[i][0] = '\0';
248  buf[i][1] = '\0';
249  if (i == 2)
250  error (_("Error: target_read_memory in file:%s, line:%d!"),
251  __FILE__, __LINE__);
252  }
253 
254  raw = extract_unsigned_integer (buf[i], EXTRACT_LEN, byte_order);
255  cbits = (cbits << 1) | (raw >> 15);
256  }
257  adjust_pc += 4;
258 
259  if (cbits & 0x4)
260  {
261  /* table 1 */
262  cbits = (cbits >> 1) & 0x7;
263  bk_index = cbits;
264  }
265  else
266  {
267  /* table 2 */
268  cbits = (cbits >> 2) & 0x7;
269  bk_index = cbits + 8;
270  }
271 
272  gdb_assert (!((bk_table[bk_index].break_offset == 0)
273  && (bk_table[bk_index].inst_len == 0)));
274 
275  inst.len = bk_table[bk_index].inst_len;
276 
277  i = (bk_table[bk_index].break_offset + 4) / 2;
278  count = inst.len / 2;
279  for (; count > 0; i++, count--)
280  {
281  inst.raw = (inst.raw << 16)
282  | extract_unsigned_integer (buf[i], EXTRACT_LEN, byte_order);
283  }
284 
285  switch (inst.len)
286  {
287  case 2:
288  inst.v = inst.raw & 0x7FFF;
289  break;
290  case 4:
291  inst.v = ((inst.raw >> 16 & 0x7FFF) << 15) | (inst.raw & 0x7FFF);
292  break;
293  case 6:
294  inst.v = ((inst.raw >> 32 & 0x7FFF) << 30)
295  | ((inst.raw >> 16 & 0x7FFF) << 15) | (inst.raw & 0x7FFF);
296  break;
297  }
298 
299  if (pcptr)
300  *pcptr = adjust_pc + bk_table[bk_index].break_offset;
301  if (lenptr)
302  *lenptr = bk_table[bk_index].inst_len;
303 
304 #undef EXTRACT_LEN
305 
306  return &inst;
307 }
308 
309 static const gdb_byte *
310 score7_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
311  int *lenptr)
312 {
313  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
314  gdb_byte buf[SCORE_INSTLEN] = { 0 };
315  int ret;
316  unsigned int raw;
317 
318  if ((ret = target_read_memory (*pcptr & ~0x3, buf, SCORE_INSTLEN)) != 0)
319  {
320  error (_("Error: target_read_memory in file:%s, line:%d!"),
321  __FILE__, __LINE__);
322  }
323  raw = extract_unsigned_integer (buf, SCORE_INSTLEN, byte_order);
324 
325  if (byte_order == BFD_ENDIAN_BIG)
326  {
327  if (!(raw & 0x80008000))
328  {
329  /* 16bits instruction. */
330  static gdb_byte big_breakpoint16[] = { 0x60, 0x02 };
331  *pcptr &= ~0x1;
332  *lenptr = sizeof (big_breakpoint16);
333  return big_breakpoint16;
334  }
335  else
336  {
337  /* 32bits instruction. */
338  static gdb_byte big_breakpoint32[] = { 0x80, 0x00, 0x80, 0x06 };
339  *pcptr &= ~0x3;
340  *lenptr = sizeof (big_breakpoint32);
341  return big_breakpoint32;
342  }
343  }
344  else
345  {
346  if (!(raw & 0x80008000))
347  {
348  /* 16bits instruction. */
349  static gdb_byte little_breakpoint16[] = { 0x02, 0x60 };
350  *pcptr &= ~0x1;
351  *lenptr = sizeof (little_breakpoint16);
352  return little_breakpoint16;
353  }
354  else
355  {
356  /* 32bits instruction. */
357  static gdb_byte little_breakpoint32[] = { 0x06, 0x80, 0x00, 0x80 };
358  *pcptr &= ~0x3;
359  *lenptr = sizeof (little_breakpoint32);
360  return little_breakpoint32;
361  }
362  }
363 }
364 
365 static const gdb_byte *
366 score3_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
367  int *lenptr)
368 {
369  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
370  CORE_ADDR adjust_pc = *pcptr;
371  int len;
372  static gdb_byte score_break_insns[6][6] = {
373  /* The following three instructions are big endian. */
374  { 0x00, 0x20 },
375  { 0x80, 0x00, 0x00, 0x06 },
376  { 0x80, 0x00, 0x80, 0x00, 0x00, 0x00 },
377  /* The following three instructions are little endian. */
378  { 0x20, 0x00 },
379  { 0x00, 0x80, 0x06, 0x00 },
380  { 0x00, 0x80, 0x00, 0x80, 0x00, 0x00 }};
381 
382  gdb_byte *p = NULL;
383  int index = 0;
384 
385  score3_adjust_pc_and_fetch_inst (&adjust_pc, &len, byte_order);
386 
387  index = ((byte_order == BFD_ENDIAN_BIG) ? 0 : 3) + (len / 2 - 1);
388  p = score_break_insns[index];
389 
390  *pcptr = adjust_pc;
391  *lenptr = len;
392 
393  return p;
394 }
395 
396 static CORE_ADDR
397 score_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
398 {
399  CORE_ADDR adjust_pc = bpaddr;
400 
401  if (target_mach == bfd_mach_score3)
402  score3_adjust_pc_and_fetch_inst (&adjust_pc, NULL,
403  gdbarch_byte_order (gdbarch));
404  else
405  adjust_pc = align_down (adjust_pc, 2);
406 
407  return adjust_pc;
408 }
409 
410 static CORE_ADDR
411 score_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
412 {
413  return align_down (addr, 16);
414 }
415 
416 static void
417 score_xfer_register (struct regcache *regcache, int regnum, int length,
418  enum bfd_endian endian, gdb_byte *readbuf,
419  const gdb_byte *writebuf, int buf_offset)
420 {
421  int reg_offset = 0;
422  gdb_assert (regnum >= 0
423  && regnum < ((target_mach == bfd_mach_score7)
425 
426  switch (endian)
427  {
428  case BFD_ENDIAN_BIG:
429  reg_offset = SCORE_REGSIZE - length;
430  break;
431  case BFD_ENDIAN_LITTLE:
432  reg_offset = 0;
433  break;
434  case BFD_ENDIAN_UNKNOWN:
435  reg_offset = 0;
436  break;
437  default:
438  error (_("Error: score_xfer_register in file:%s, line:%d!"),
439  __FILE__, __LINE__);
440  }
441 
442  if (readbuf != NULL)
443  regcache_cooked_read_part (regcache, regnum, reg_offset, length,
444  readbuf + buf_offset);
445  if (writebuf != NULL)
446  regcache_cooked_write_part (regcache, regnum, reg_offset, length,
447  writebuf + buf_offset);
448 }
449 
450 static enum return_value_convention
451 score_return_value (struct gdbarch *gdbarch, struct value *function,
452  struct type *type, struct regcache *regcache,
453  gdb_byte * readbuf, const gdb_byte * writebuf)
454 {
455  if (TYPE_CODE (type) == TYPE_CODE_STRUCT
456  || TYPE_CODE (type) == TYPE_CODE_UNION
457  || TYPE_CODE (type) == TYPE_CODE_ARRAY)
459  else
460  {
461  int offset;
462  int regnum;
463  for (offset = 0, regnum = SCORE_A0_REGNUM;
464  offset < TYPE_LENGTH (type);
465  offset += SCORE_REGSIZE, regnum++)
466  {
467  int xfer = SCORE_REGSIZE;
468 
469  if (offset + xfer > TYPE_LENGTH (type))
470  xfer = TYPE_LENGTH (type) - offset;
471  score_xfer_register (regcache, regnum, xfer,
472  gdbarch_byte_order(gdbarch),
473  readbuf, writebuf, offset);
474  }
476  }
477 }
478 
479 static struct frame_id
480 score_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
481 {
482  return frame_id_build (get_frame_register_unsigned (this_frame,
484  get_frame_pc (this_frame));
485 }
486 
487 static int
489 {
490  enum type_code typecode = TYPE_CODE (type);
491 
492  if ((typecode == TYPE_CODE_INT && TYPE_LENGTH (type) == 8)
493  || (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8))
494  return 1;
495  else if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
496  {
497  int i, n;
498 
499  n = TYPE_NFIELDS (type);
500  for (i = 0; i < n; i++)
502  return 1;
503  return 0;
504  }
505  return 0;
506 }
507 
508 static CORE_ADDR
509 score_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
510  struct regcache *regcache, CORE_ADDR bp_addr,
511  int nargs, struct value **args, CORE_ADDR sp,
512  int struct_return, CORE_ADDR struct_addr)
513 {
514  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
515  int argnum;
516  int argreg;
517  int arglen = 0;
518  CORE_ADDR stack_offset = 0;
519  CORE_ADDR addr = 0;
520 
521  /* Step 1, Save RA. */
522  regcache_cooked_write_unsigned (regcache, SCORE_RA_REGNUM, bp_addr);
523 
524  /* Step 2, Make space on the stack for the args. */
525  struct_addr = align_down (struct_addr, 16);
526  sp = align_down (sp, 16);
527  for (argnum = 0; argnum < nargs; argnum++)
528  arglen += align_up (TYPE_LENGTH (value_type (args[argnum])),
529  SCORE_REGSIZE);
530  sp -= align_up (arglen, 16);
531 
532  argreg = SCORE_BEGIN_ARG_REGNUM;
533 
534  /* Step 3, Check if struct return then save the struct address to
535  r4 and increase the stack_offset by 4. */
536  if (struct_return)
537  {
538  regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
539  stack_offset += SCORE_REGSIZE;
540  }
541 
542  /* Step 4, Load arguments:
543  If arg length is too long (> 4 bytes), then split the arg and
544  save every parts. */
545  for (argnum = 0; argnum < nargs; argnum++)
546  {
547  struct value *arg = args[argnum];
548  struct type *arg_type = check_typedef (value_type (arg));
549  enum type_code typecode = TYPE_CODE (arg_type);
550  const gdb_byte *val = value_contents (arg);
551  int downward_offset = 0;
552  int odd_sized_struct_p;
553  int arg_last_part_p = 0;
554 
555  arglen = TYPE_LENGTH (arg_type);
556  odd_sized_struct_p = (arglen > SCORE_REGSIZE
557  && arglen % SCORE_REGSIZE != 0);
558 
559  /* If a arg should be aligned to 8 bytes (long long or double),
560  the value should be put to even register numbers. */
561  if (score_type_needs_double_align (arg_type))
562  {
563  if (argreg & 1)
564  argreg++;
565  }
566 
567  /* If sizeof a block < SCORE_REGSIZE, then Score GCC will chose
568  the default "downward"/"upward" method:
569 
570  Example:
571 
572  struct struc
573  {
574  char a; char b; char c;
575  } s = {'a', 'b', 'c'};
576 
577  Big endian: s = {X, 'a', 'b', 'c'}
578  Little endian: s = {'a', 'b', 'c', X}
579 
580  Where X is a hole. */
581 
582  if (gdbarch_byte_order(gdbarch) == BFD_ENDIAN_BIG
583  && (typecode == TYPE_CODE_STRUCT
584  || typecode == TYPE_CODE_UNION)
585  && argreg > SCORE_LAST_ARG_REGNUM
586  && arglen < SCORE_REGSIZE)
587  downward_offset += (SCORE_REGSIZE - arglen);
588 
589  while (arglen > 0)
590  {
591  int partial_len = arglen < SCORE_REGSIZE ? arglen : SCORE_REGSIZE;
592  ULONGEST regval = extract_unsigned_integer (val, partial_len,
593  byte_order);
594 
595  /* The last part of a arg should shift left when
596  gdbarch_byte_order is BFD_ENDIAN_BIG. */
597  if (byte_order == BFD_ENDIAN_BIG
598  && arg_last_part_p == 1
599  && (typecode == TYPE_CODE_STRUCT
600  || typecode == TYPE_CODE_UNION))
601  regval <<= ((SCORE_REGSIZE - partial_len) * TARGET_CHAR_BIT);
602 
603  /* Always increase the stack_offset and save args to stack. */
604  addr = sp + stack_offset + downward_offset;
605  write_memory (addr, val, partial_len);
606 
607  if (argreg <= SCORE_LAST_ARG_REGNUM)
608  {
609  regcache_cooked_write_unsigned (regcache, argreg++, regval);
610  if (arglen > SCORE_REGSIZE && arglen < SCORE_REGSIZE * 2)
611  arg_last_part_p = 1;
612  }
613 
614  val += partial_len;
615  arglen -= partial_len;
616  stack_offset += align_up (partial_len, SCORE_REGSIZE);
617  }
618  }
619 
620  /* Step 5, Save SP. */
622 
623  return sp;
624 }
625 
626 static CORE_ADDR
627 score7_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
628 {
629  CORE_ADDR cpc = pc;
630  int iscan = 32, stack_sub = 0;
631  while (iscan-- > 0)
632  {
633  inst_t *inst = score7_fetch_inst (gdbarch, cpc, NULL);
634  if (!inst)
635  break;
636  if ((inst->len == 4) && !stack_sub
637  && (G_FLD (inst->v, 29, 25) == 0x1
638  && G_FLD (inst->v, 24, 20) == 0x0))
639  {
640  /* addi r0, offset */
641  stack_sub = cpc + SCORE_INSTLEN;
642  pc = cpc + SCORE_INSTLEN;
643  }
644  else if ((inst->len == 4)
645  && (G_FLD (inst->v, 29, 25) == 0x0)
646  && (G_FLD (inst->v, 24, 20) == 0x2)
647  && (G_FLD (inst->v, 19, 15) == 0x0)
648  && (G_FLD (inst->v, 14, 10) == 0xF)
649  && (G_FLD (inst->v, 9, 0) == 0x56))
650  {
651  /* mv r2, r0 */
652  pc = cpc + SCORE_INSTLEN;
653  break;
654  }
655  else if ((inst->len == 2)
656  && (G_FLD (inst->v, 14, 12) == 0x0)
657  && (G_FLD (inst->v, 11, 8) == 0x2)
658  && (G_FLD (inst->v, 7, 4) == 0x0)
659  && (G_FLD (inst->v, 3, 0) == 0x3))
660  {
661  /* mv! r2, r0 */
662  pc = cpc + SCORE16_INSTLEN;
663  break;
664  }
665  else if ((inst->len == 2)
666  && ((G_FLD (inst->v, 14, 12) == 3) /* j15 form */
667  || (G_FLD (inst->v, 14, 12) == 4) /* b15 form */
668  || (G_FLD (inst->v, 14, 12) == 0x0
669  && G_FLD (inst->v, 3, 0) == 0x4))) /* br! */
670  break;
671  else if ((inst->len == 4)
672  && ((G_FLD (inst->v, 29, 25) == 2) /* j32 form */
673  || (G_FLD (inst->v, 29, 25) == 4) /* b32 form */
674  || (G_FLD (inst->v, 29, 25) == 0x0
675  && G_FLD (inst->v, 6, 1) == 0x4))) /* br */
676  break;
677 
678  cpc += (inst->len == 2) ? SCORE16_INSTLEN : SCORE_INSTLEN;
679  }
680  return pc;
681 }
682 
683 static CORE_ADDR
684 score3_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
685 {
686  CORE_ADDR cpc = pc;
687  int iscan = 32, stack_sub = 0;
688  while (iscan-- > 0)
689  {
690  inst_t *inst
691  = score3_adjust_pc_and_fetch_inst (&cpc, NULL,
692  gdbarch_byte_order (gdbarch));
693 
694  if (!inst)
695  break;
696  if (inst->len == 4 && !stack_sub
697  && (G_FLD (inst->v, 29, 25) == 0x1)
698  && (G_FLD (inst->v, 19, 17) == 0x0)
699  && (G_FLD (inst->v, 24, 20) == 0x0))
700  {
701  /* addi r0, offset */
702  stack_sub = cpc + inst->len;
703  pc = cpc + inst->len;
704  }
705  else if (inst->len == 4
706  && (G_FLD (inst->v, 29, 25) == 0x0)
707  && (G_FLD (inst->v, 24, 20) == 0x2)
708  && (G_FLD (inst->v, 19, 15) == 0x0)
709  && (G_FLD (inst->v, 14, 10) == 0xF)
710  && (G_FLD (inst->v, 9, 0) == 0x56))
711  {
712  /* mv r2, r0 */
713  pc = cpc + inst->len;
714  break;
715  }
716  else if ((inst->len == 2)
717  && (G_FLD (inst->v, 14, 10) == 0x10)
718  && (G_FLD (inst->v, 9, 5) == 0x2)
719  && (G_FLD (inst->v, 4, 0) == 0x0))
720  {
721  /* mv! r2, r0 */
722  pc = cpc + inst->len;
723  break;
724  }
725  else if (inst->len == 2
726  && ((G_FLD (inst->v, 14, 12) == 3) /* b15 form */
727  || (G_FLD (inst->v, 14, 12) == 0x0
728  && G_FLD (inst->v, 11, 5) == 0x4))) /* br! */
729  break;
730  else if (inst->len == 4
731  && ((G_FLD (inst->v, 29, 25) == 2) /* j32 form */
732  || (G_FLD (inst->v, 29, 25) == 4))) /* b32 form */
733  break;
734 
735  cpc += inst->len;
736  }
737  return pc;
738 }
739 
740 /* Implement the stack_frame_destroyed_p gdbarch method. */
741 
742 static int
743 score7_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR cur_pc)
744 {
745  inst_t *inst = score7_fetch_inst (gdbarch, cur_pc, NULL);
746 
747  if (inst->v == 0x23)
748  return 1; /* mv! r0, r2 */
749  else if (G_FLD (inst->v, 14, 12) == 0x2
750  && G_FLD (inst->v, 3, 0) == 0xa)
751  return 1; /* pop! */
752  else if (G_FLD (inst->v, 14, 12) == 0x0
753  && G_FLD (inst->v, 7, 0) == 0x34)
754  return 1; /* br! r3 */
755  else if (G_FLD (inst->v, 29, 15) == 0x2
756  && G_FLD (inst->v, 6, 1) == 0x2b)
757  return 1; /* mv r0, r2 */
758  else if (G_FLD (inst->v, 29, 25) == 0x0
759  && G_FLD (inst->v, 6, 1) == 0x4
760  && G_FLD (inst->v, 19, 15) == 0x3)
761  return 1; /* br r3 */
762  else
763  return 0;
764 }
765 
766 /* Implement the stack_frame_destroyed_p gdbarch method. */
767 
768 static int
769 score3_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR cur_pc)
770 {
771  CORE_ADDR pc = cur_pc;
772  inst_t *inst
773  = score3_adjust_pc_and_fetch_inst (&pc, NULL,
774  gdbarch_byte_order (gdbarch));
775 
776  if (inst->len == 2
777  && (G_FLD (inst->v, 14, 10) == 0x10)
778  && (G_FLD (inst->v, 9, 5) == 0x0)
779  && (G_FLD (inst->v, 4, 0) == 0x2))
780  return 1; /* mv! r0, r2 */
781  else if (inst->len == 4
782  && (G_FLD (inst->v, 29, 25) == 0x0)
783  && (G_FLD (inst->v, 24, 20) == 0x2)
784  && (G_FLD (inst->v, 19, 15) == 0x0)
785  && (G_FLD (inst->v, 14, 10) == 0xF)
786  && (G_FLD (inst->v, 9, 0) == 0x56))
787  return 1; /* mv r0, r2 */
788  else if (inst->len == 2
789  && (G_FLD (inst->v, 14, 12) == 0x0)
790  && (G_FLD (inst->v, 11, 5) == 0x2))
791  return 1; /* pop! */
792  else if (inst->len == 2
793  && (G_FLD (inst->v, 14, 12) == 0x0)
794  && (G_FLD (inst->v, 11, 7) == 0x0)
795  && (G_FLD (inst->v, 6, 5) == 0x2))
796  return 1; /* rpop! */
797  else if (inst->len == 2
798  && (G_FLD (inst->v, 14, 12) == 0x0)
799  && (G_FLD (inst->v, 11, 5) == 0x4)
800  && (G_FLD (inst->v, 4, 0) == 0x3))
801  return 1; /* br! r3 */
802  else if (inst->len == 4
803  && (G_FLD (inst->v, 29, 25) == 0x0)
804  && (G_FLD (inst->v, 24, 20) == 0x0)
805  && (G_FLD (inst->v, 19, 15) == 0x3)
806  && (G_FLD (inst->v, 14, 10) == 0xF)
807  && (G_FLD (inst->v, 9, 0) == 0x8))
808  return 1; /* br r3 */
809  else
810  return 0;
811 }
812 
813 static gdb_byte *
815 {
816  int ret;
817  gdb_byte *memblock = NULL;
818 
819  if (size < 0)
820  {
821  error (_("Error: malloc size < 0 in file:%s, line:%d!"),
822  __FILE__, __LINE__);
823  return NULL;
824  }
825  else if (size == 0)
826  return NULL;
827 
828  memblock = xmalloc (size);
829  memset (memblock, 0, size);
830  ret = target_read_memory (addr & ~0x3, memblock, size);
831  if (ret)
832  {
833  error (_("Error: target_read_memory in file:%s, line:%d!"),
834  __FILE__, __LINE__);
835  return NULL;
836  }
837  return memblock;
838 }
839 
840 static void
842 {
843  xfree (memblock);
844 }
845 
846 static void
848  CORE_ADDR cur_pc)
849 {
850  if (prev_pc == -1)
851  {
852  /* First time call this function, do nothing. */
853  }
854  else if (cur_pc - prev_pc == 2 && (cur_pc & 0x3) == 0)
855  {
856  /* First 16-bit instruction, then 32-bit instruction. */
857  *memblock += SCORE_INSTLEN;
858  }
859  else if (cur_pc - prev_pc == 4)
860  {
861  /* Is 32-bit instruction, increase MEMBLOCK by 4. */
862  *memblock += SCORE_INSTLEN;
863  }
864 }
865 
866 static void
868  struct frame_info *this_frame,
869  struct score_frame_cache *this_cache)
870 {
871  struct gdbarch *gdbarch = get_frame_arch (this_frame);
872  CORE_ADDR sp;
873  CORE_ADDR fp;
874  CORE_ADDR cur_pc = startaddr;
875 
876  int sp_offset = 0;
877  int ra_offset = 0;
878  int fp_offset = 0;
879  int ra_offset_p = 0;
880  int fp_offset_p = 0;
881  int inst_len = 0;
882 
883  gdb_byte *memblock = NULL;
884  gdb_byte *memblock_ptr = NULL;
885  CORE_ADDR prev_pc = -1;
886 
887  /* Allocate MEMBLOCK if PC - STARTADDR > 0. */
888  memblock_ptr = memblock =
889  score7_malloc_and_get_memblock (startaddr, pc - startaddr);
890 
891  sp = get_frame_register_unsigned (this_frame, SCORE_SP_REGNUM);
892  fp = get_frame_register_unsigned (this_frame, SCORE_FP_REGNUM);
893 
894  for (; cur_pc < pc; prev_pc = cur_pc, cur_pc += inst_len)
895  {
896  inst_t *inst = NULL;
897  if (memblock != NULL)
898  {
899  /* Reading memory block from target succefully and got all
900  the instructions(from STARTADDR to PC) needed. */
901  score7_adjust_memblock_ptr (&memblock, prev_pc, cur_pc);
902  inst = score7_fetch_inst (gdbarch, cur_pc, memblock);
903  }
904  else
905  {
906  /* Otherwise, we fetch 4 bytes from target, and GDB also
907  work correctly. */
908  inst = score7_fetch_inst (gdbarch, cur_pc, NULL);
909  }
910 
911  /* FIXME: make a full-power prologue analyzer. */
912  if (inst->len == 2)
913  {
914  inst_len = SCORE16_INSTLEN;
915 
916  if (G_FLD (inst->v, 14, 12) == 0x2
917  && G_FLD (inst->v, 3, 0) == 0xe)
918  {
919  /* push! */
920  sp_offset += 4;
921 
922  if (G_FLD (inst->v, 11, 7) == 0x6
923  && ra_offset_p == 0)
924  {
925  /* push! r3, [r0] */
926  ra_offset = sp_offset;
927  ra_offset_p = 1;
928  }
929  else if (G_FLD (inst->v, 11, 7) == 0x4
930  && fp_offset_p == 0)
931  {
932  /* push! r2, [r0] */
933  fp_offset = sp_offset;
934  fp_offset_p = 1;
935  }
936  }
937  else if (G_FLD (inst->v, 14, 12) == 0x2
938  && G_FLD (inst->v, 3, 0) == 0xa)
939  {
940  /* pop! */
941  sp_offset -= 4;
942  }
943  else if (G_FLD (inst->v, 14, 7) == 0xc1
944  && G_FLD (inst->v, 2, 0) == 0x0)
945  {
946  /* subei! r0, n */
947  sp_offset += (int) pow (2, G_FLD (inst->v, 6, 3));
948  }
949  else if (G_FLD (inst->v, 14, 7) == 0xc0
950  && G_FLD (inst->v, 2, 0) == 0x0)
951  {
952  /* addei! r0, n */
953  sp_offset -= (int) pow (2, G_FLD (inst->v, 6, 3));
954  }
955  }
956  else
957  {
958  inst_len = SCORE_INSTLEN;
959 
960  if (G_FLD(inst->v, 29, 25) == 0x3
961  && G_FLD(inst->v, 2, 0) == 0x4
962  && G_FLD(inst->v, 19, 15) == 0)
963  {
964  /* sw rD, [r0, offset]+ */
965  sp_offset += SCORE_INSTLEN;
966 
967  if (G_FLD(inst->v, 24, 20) == 0x3)
968  {
969  /* rD = r3 */
970  if (ra_offset_p == 0)
971  {
972  ra_offset = sp_offset;
973  ra_offset_p = 1;
974  }
975  }
976  else if (G_FLD(inst->v, 24, 20) == 0x2)
977  {
978  /* rD = r2 */
979  if (fp_offset_p == 0)
980  {
981  fp_offset = sp_offset;
982  fp_offset_p = 1;
983  }
984  }
985  }
986  else if (G_FLD(inst->v, 29, 25) == 0x14
987  && G_FLD(inst->v, 19,15) == 0)
988  {
989  /* sw rD, [r0, offset] */
990  if (G_FLD(inst->v, 24, 20) == 0x3)
991  {
992  /* rD = r3 */
993  ra_offset = sp_offset - G_FLD(inst->v, 14, 0);
994  ra_offset_p = 1;
995  }
996  else if (G_FLD(inst->v, 24, 20) == 0x2)
997  {
998  /* rD = r2 */
999  fp_offset = sp_offset - G_FLD(inst->v, 14, 0);
1000  fp_offset_p = 1;
1001  }
1002  }
1003  else if (G_FLD (inst->v, 29, 15) == 0x1c60
1004  && G_FLD (inst->v, 2, 0) == 0x0)
1005  {
1006  /* lw r3, [r0]+, 4 */
1007  sp_offset -= SCORE_INSTLEN;
1008  ra_offset_p = 1;
1009  }
1010  else if (G_FLD (inst->v, 29, 15) == 0x1c40
1011  && G_FLD (inst->v, 2, 0) == 0x0)
1012  {
1013  /* lw r2, [r0]+, 4 */
1014  sp_offset -= SCORE_INSTLEN;
1015  fp_offset_p = 1;
1016  }
1017 
1018  else if (G_FLD (inst->v, 29, 17) == 0x100
1019  && G_FLD (inst->v, 0, 0) == 0x0)
1020  {
1021  /* addi r0, -offset */
1022  sp_offset += 65536 - G_FLD (inst->v, 16, 1);
1023  }
1024  else if (G_FLD (inst->v, 29, 17) == 0x110
1025  && G_FLD (inst->v, 0, 0) == 0x0)
1026  {
1027  /* addi r2, offset */
1028  if (pc - cur_pc > 4)
1029  {
1030  unsigned int save_v = inst->v;
1031  inst_t *inst2 =
1032  score7_fetch_inst (gdbarch, cur_pc + SCORE_INSTLEN, NULL);
1033  if (inst2->v == 0x23)
1034  {
1035  /* mv! r0, r2 */
1036  sp_offset -= G_FLD (save_v, 16, 1);
1037  }
1038  }
1039  }
1040  }
1041  }
1042 
1043  /* Save RA. */
1044  if (ra_offset_p == 1)
1045  {
1046  if (this_cache->saved_regs[SCORE_PC_REGNUM].addr == -1)
1047  this_cache->saved_regs[SCORE_PC_REGNUM].addr =
1048  sp + sp_offset - ra_offset;
1049  }
1050  else
1051  {
1052  this_cache->saved_regs[SCORE_PC_REGNUM] =
1053  this_cache->saved_regs[SCORE_RA_REGNUM];
1054  }
1055 
1056  /* Save FP. */
1057  if (fp_offset_p == 1)
1058  {
1059  if (this_cache->saved_regs[SCORE_FP_REGNUM].addr == -1)
1060  this_cache->saved_regs[SCORE_FP_REGNUM].addr =
1061  sp + sp_offset - fp_offset;
1062  }
1063 
1064  /* Save SP and FP. */
1065  this_cache->base = sp + sp_offset;
1066  this_cache->fp = fp;
1067 
1068  /* Don't forget to free MEMBLOCK if we allocated it. */
1069  if (memblock_ptr != NULL)
1070  score7_free_memblock (memblock_ptr);
1071 }
1072 
1073 static void
1075  struct frame_info *this_frame,
1076  struct score_frame_cache *this_cache)
1077 {
1078  CORE_ADDR sp;
1079  CORE_ADDR fp;
1080  CORE_ADDR cur_pc = startaddr;
1081  enum bfd_endian byte_order
1082  = gdbarch_byte_order (get_frame_arch (this_frame));
1083 
1084  int sp_offset = 0;
1085  int ra_offset = 0;
1086  int fp_offset = 0;
1087  int ra_offset_p = 0;
1088  int fp_offset_p = 0;
1089  int inst_len = 0;
1090 
1091  CORE_ADDR prev_pc = -1;
1092 
1093  sp = get_frame_register_unsigned (this_frame, SCORE_SP_REGNUM);
1094  fp = get_frame_register_unsigned (this_frame, SCORE_FP_REGNUM);
1095 
1096  for (; cur_pc < pc; prev_pc = cur_pc, cur_pc += inst_len)
1097  {
1098  inst_t *inst = NULL;
1099 
1100  inst = score3_adjust_pc_and_fetch_inst (&cur_pc, &inst_len, byte_order);
1101 
1102  /* FIXME: make a full-power prologue analyzer. */
1103  if (inst->len == 2)
1104  {
1105  if (G_FLD (inst->v, 14, 12) == 0x0
1106  && G_FLD (inst->v, 11, 7) == 0x0
1107  && G_FLD (inst->v, 6, 5) == 0x3)
1108  {
1109  /* push! */
1110  sp_offset += 4;
1111 
1112  if (G_FLD (inst->v, 4, 0) == 0x3
1113  && ra_offset_p == 0)
1114  {
1115  /* push! r3, [r0] */
1116  ra_offset = sp_offset;
1117  ra_offset_p = 1;
1118  }
1119  else if (G_FLD (inst->v, 4, 0) == 0x2
1120  && fp_offset_p == 0)
1121  {
1122  /* push! r2, [r0] */
1123  fp_offset = sp_offset;
1124  fp_offset_p = 1;
1125  }
1126  }
1127  else if (G_FLD (inst->v, 14, 12) == 0x6
1128  && G_FLD (inst->v, 11, 10) == 0x3)
1129  {
1130  /* rpush! */
1131  int start_r = G_FLD (inst->v, 9, 5);
1132  int cnt = G_FLD (inst->v, 4, 0);
1133 
1134  if ((ra_offset_p == 0)
1135  && (start_r <= SCORE_RA_REGNUM)
1136  && (SCORE_RA_REGNUM < start_r + cnt))
1137  {
1138  /* rpush! contains r3 */
1139  ra_offset_p = 1;
1140  ra_offset = sp_offset + 4 * (SCORE_RA_REGNUM - start_r) + 4;
1141  }
1142 
1143  if ((fp_offset_p == 0)
1144  && (start_r <= SCORE_FP_REGNUM)
1145  && (SCORE_FP_REGNUM < start_r + cnt))
1146  {
1147  /* rpush! contains r2 */
1148  fp_offset_p = 1;
1149  fp_offset = sp_offset + 4 * (SCORE_FP_REGNUM - start_r) + 4;
1150  }
1151 
1152  sp_offset += 4 * cnt;
1153  }
1154  else if (G_FLD (inst->v, 14, 12) == 0x0
1155  && G_FLD (inst->v, 11, 7) == 0x0
1156  && G_FLD (inst->v, 6, 5) == 0x2)
1157  {
1158  /* pop! */
1159  sp_offset -= 4;
1160  }
1161  else if (G_FLD (inst->v, 14, 12) == 0x6
1162  && G_FLD (inst->v, 11, 10) == 0x2)
1163  {
1164  /* rpop! */
1165  sp_offset -= 4 * G_FLD (inst->v, 4, 0);
1166  }
1167  else if (G_FLD (inst->v, 14, 12) == 0x5
1168  && G_FLD (inst->v, 11, 10) == 0x3
1169  && G_FLD (inst->v, 9, 6) == 0x0)
1170  {
1171  /* addi! r0, -offset */
1172  int imm = G_FLD (inst->v, 5, 0);
1173  if (imm >> 5)
1174  imm = -(0x3F - imm + 1);
1175  sp_offset -= imm;
1176  }
1177  else if (G_FLD (inst->v, 14, 12) == 0x5
1178  && G_FLD (inst->v, 11, 10) == 0x3
1179  && G_FLD (inst->v, 9, 6) == 0x2)
1180  {
1181  /* addi! r2, offset */
1182  if (pc - cur_pc >= 2)
1183  {
1184  unsigned int save_v = inst->v;
1185  inst_t *inst2;
1186 
1187  cur_pc += inst->len;
1188  inst2 = score3_adjust_pc_and_fetch_inst (&cur_pc, NULL,
1189  byte_order);
1190 
1191  if (inst2->len == 2
1192  && G_FLD (inst2->v, 14, 10) == 0x10
1193  && G_FLD (inst2->v, 9, 5) == 0x0
1194  && G_FLD (inst2->v, 4, 0) == 0x2)
1195  {
1196  /* mv! r0, r2 */
1197  int imm = G_FLD (inst->v, 5, 0);
1198  if (imm >> 5)
1199  imm = -(0x3F - imm + 1);
1200  sp_offset -= imm;
1201  }
1202  }
1203  }
1204  }
1205  else if (inst->len == 4)
1206  {
1207  if (G_FLD (inst->v, 29, 25) == 0x3
1208  && G_FLD (inst->v, 2, 0) == 0x4
1209  && G_FLD (inst->v, 24, 20) == 0x3
1210  && G_FLD (inst->v, 19, 15) == 0x0)
1211  {
1212  /* sw r3, [r0, offset]+ */
1213  sp_offset += inst->len;
1214  if (ra_offset_p == 0)
1215  {
1216  ra_offset = sp_offset;
1217  ra_offset_p = 1;
1218  }
1219  }
1220  else if (G_FLD (inst->v, 29, 25) == 0x3
1221  && G_FLD (inst->v, 2, 0) == 0x4
1222  && G_FLD (inst->v, 24, 20) == 0x2
1223  && G_FLD (inst->v, 19, 15) == 0x0)
1224  {
1225  /* sw r2, [r0, offset]+ */
1226  sp_offset += inst->len;
1227  if (fp_offset_p == 0)
1228  {
1229  fp_offset = sp_offset;
1230  fp_offset_p = 1;
1231  }
1232  }
1233  else if (G_FLD (inst->v, 29, 25) == 0x7
1234  && G_FLD (inst->v, 2, 0) == 0x0
1235  && G_FLD (inst->v, 24, 20) == 0x3
1236  && G_FLD (inst->v, 19, 15) == 0x0)
1237  {
1238  /* lw r3, [r0]+, 4 */
1239  sp_offset -= inst->len;
1240  ra_offset_p = 1;
1241  }
1242  else if (G_FLD (inst->v, 29, 25) == 0x7
1243  && G_FLD (inst->v, 2, 0) == 0x0
1244  && G_FLD (inst->v, 24, 20) == 0x2
1245  && G_FLD (inst->v, 19, 15) == 0x0)
1246  {
1247  /* lw r2, [r0]+, 4 */
1248  sp_offset -= inst->len;
1249  fp_offset_p = 1;
1250  }
1251  else if (G_FLD (inst->v, 29, 25) == 0x1
1252  && G_FLD (inst->v, 19, 17) == 0x0
1253  && G_FLD (inst->v, 24, 20) == 0x0
1254  && G_FLD (inst->v, 0, 0) == 0x0)
1255  {
1256  /* addi r0, -offset */
1257  int imm = G_FLD (inst->v, 16, 1);
1258  if (imm >> 15)
1259  imm = -(0xFFFF - imm + 1);
1260  sp_offset -= imm;
1261  }
1262  else if (G_FLD (inst->v, 29, 25) == 0x1
1263  && G_FLD (inst->v, 19, 17) == 0x0
1264  && G_FLD (inst->v, 24, 20) == 0x2
1265  && G_FLD (inst->v, 0, 0) == 0x0)
1266  {
1267  /* addi r2, offset */
1268  if (pc - cur_pc >= 2)
1269  {
1270  unsigned int save_v = inst->v;
1271  inst_t *inst2;
1272 
1273  cur_pc += inst->len;
1274  inst2 = score3_adjust_pc_and_fetch_inst (&cur_pc, NULL,
1275  byte_order);
1276 
1277  if (inst2->len == 2
1278  && G_FLD (inst2->v, 14, 10) == 0x10
1279  && G_FLD (inst2->v, 9, 5) == 0x0
1280  && G_FLD (inst2->v, 4, 0) == 0x2)
1281  {
1282  /* mv! r0, r2 */
1283  int imm = G_FLD (inst->v, 16, 1);
1284  if (imm >> 15)
1285  imm = -(0xFFFF - imm + 1);
1286  sp_offset -= imm;
1287  }
1288  }
1289  }
1290  }
1291  }
1292 
1293  /* Save RA. */
1294  if (ra_offset_p == 1)
1295  {
1296  if (this_cache->saved_regs[SCORE_PC_REGNUM].addr == -1)
1297  this_cache->saved_regs[SCORE_PC_REGNUM].addr =
1298  sp + sp_offset - ra_offset;
1299  }
1300  else
1301  {
1302  this_cache->saved_regs[SCORE_PC_REGNUM] =
1303  this_cache->saved_regs[SCORE_RA_REGNUM];
1304  }
1305 
1306  /* Save FP. */
1307  if (fp_offset_p == 1)
1308  {
1309  if (this_cache->saved_regs[SCORE_FP_REGNUM].addr == -1)
1310  this_cache->saved_regs[SCORE_FP_REGNUM].addr =
1311  sp + sp_offset - fp_offset;
1312  }
1313 
1314  /* Save SP and FP. */
1315  this_cache->base = sp + sp_offset;
1316  this_cache->fp = fp;
1317 }
1318 
1319 static struct score_frame_cache *
1320 score_make_prologue_cache (struct frame_info *this_frame, void **this_cache)
1321 {
1322  struct score_frame_cache *cache;
1323 
1324  if ((*this_cache) != NULL)
1325  return (*this_cache);
1326 
1327  cache = FRAME_OBSTACK_ZALLOC (struct score_frame_cache);
1328  (*this_cache) = cache;
1329  cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
1330 
1331  /* Analyze the prologue. */
1332  {
1333  const CORE_ADDR pc = get_frame_pc (this_frame);
1334  CORE_ADDR start_addr;
1335 
1336  find_pc_partial_function (pc, NULL, &start_addr, NULL);
1337  if (start_addr == 0)
1338  return cache;
1339 
1340  if (target_mach == bfd_mach_score3)
1341  score3_analyze_prologue (start_addr, pc, this_frame, *this_cache);
1342  else
1343  score7_analyze_prologue (start_addr, pc, this_frame, *this_cache);
1344  }
1345 
1346  /* Save SP. */
1348 
1349  return (*this_cache);
1350 }
1351 
1352 static void
1353 score_prologue_this_id (struct frame_info *this_frame, void **this_cache,
1354  struct frame_id *this_id)
1355 {
1356  struct score_frame_cache *info = score_make_prologue_cache (this_frame,
1357  this_cache);
1358  (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
1359 }
1360 
1361 static struct value *
1363  void **this_cache, int regnum)
1364 {
1365  struct score_frame_cache *info = score_make_prologue_cache (this_frame,
1366  this_cache);
1367  return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
1368 }
1369 
1370 static const struct frame_unwind score_prologue_unwind =
1371 {
1372  NORMAL_FRAME,
1376  NULL,
1378  NULL
1379 };
1380 
1381 static CORE_ADDR
1383  void **this_cache)
1384 {
1385  struct score_frame_cache *info =
1386  score_make_prologue_cache (this_frame, this_cache);
1387  return info->fp;
1388 }
1389 
1390 static const struct frame_base score_prologue_frame_base =
1391 {
1396 };
1397 
1398 static const struct frame_base *
1400 {
1401  return &score_prologue_frame_base;
1402 }
1403 
1404 /* Core file support. */
1405 
1406 static const struct regcache_map_entry score7_linux_gregmap[] =
1407  {
1408  /* FIXME: According to the current Linux kernel, r0 is preceded by
1409  9 rather than 7 words. */
1410  { 7, REGCACHE_MAP_SKIP, 4 },
1411  { 32, 0, 4 }, /* r0 ... r31 */
1412  { 1, 55, 4 }, /* CEL */
1413  { 1, 54, 4 }, /* CEH */
1414  { 1, 53, 4 }, /* sr0, i.e. cnt or COUNTER */
1415  { 1, 52, 4 }, /* sr1, i.e. lcr or LDCR */
1416  { 1, 51, 4 }, /* sr2, i.e. scr or STCR */
1417  { 1, 49, 4 }, /* PC (same slot as EPC) */
1418  { 1, 38, 4 }, /* EMA */
1419  { 1, 32, 4 }, /* PSR */
1420  { 1, 34, 4 }, /* ECR */
1421  { 1, 33, 4 }, /* COND */
1422  { 0 }
1423  };
1424 
1425 #define SCORE7_LINUX_EPC_OFFSET (44 * 4)
1426 #define SCORE7_LINUX_SIZEOF_GREGSET (49 * 4)
1427 
1428 static void
1430  struct regcache *regcache,
1431  int regnum, const void *buf,
1432  size_t size)
1433 {
1434  regcache_supply_regset (regset, regcache, regnum, buf, size);
1435 
1436  /* Supply the EPC from the same slot as the PC. Note that the
1437  collect function will store the PC in that slot. */
1438  if ((regnum == -1 || regnum == SCORE_EPC_REGNUM)
1439  && size >= SCORE7_LINUX_EPC_OFFSET + 4)
1441  (const gdb_byte *) buf
1443 }
1444 
1445 static const struct regset score7_linux_gregset =
1446  {
1450  };
1451 
1452 /* Iterate over core file register note sections. */
1453 
1454 static void
1457  void *cb_data,
1458  const struct regcache *regcache)
1459 {
1460  cb (".reg", SCORE7_LINUX_SIZEOF_GREGSET, &score7_linux_gregset,
1461  NULL, cb_data);
1462 }
1463 
1464 static struct gdbarch *
1465 score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1466 {
1467  struct gdbarch *gdbarch;
1468  target_mach = info.bfd_arch_info->mach;
1469 
1470  arches = gdbarch_list_lookup_by_info (arches, &info);
1471  if (arches != NULL)
1472  {
1473  return (arches->gdbarch);
1474  }
1475  gdbarch = gdbarch_alloc (&info, NULL);
1476 
1477  set_gdbarch_short_bit (gdbarch, 16);
1478  set_gdbarch_int_bit (gdbarch, 32);
1479  set_gdbarch_float_bit (gdbarch, 32);
1480  set_gdbarch_double_bit (gdbarch, 64);
1481  set_gdbarch_long_double_bit (gdbarch, 64);
1482 #if WITH_SIM
1483  set_gdbarch_register_sim_regno (gdbarch, score_register_sim_regno);
1484 #endif
1495 
1496  switch (target_mach)
1497  {
1498  case bfd_mach_score7:
1505  /* Core file support. */
1508  break;
1509 
1510  case bfd_mach_score3:
1517  break;
1518  }
1519 
1520  /* Watchpoint hooks. */
1522 
1523  /* Dummy frame hooks. */
1528 
1529  /* Normal frame hooks. */
1530  dwarf2_append_unwinders (gdbarch);
1532  frame_unwind_append_unwinder (gdbarch, &score_prologue_unwind);
1534 
1535  return gdbarch;
1536 }
1537 
1539 
1540 void
1542 {
1543  gdbarch_register (bfd_arch_score, score_gdbarch_init, NULL);
1544 }
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
void set_gdbarch_have_nonsteppable_watchpoint(struct gdbarch *gdbarch, int have_nonsteppable_watchpoint)
Definition: gdbarch.c:3261
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
Definition: findvar.c:84
type_code
Definition: gdbtypes.h:85
static CORE_ADDR score7_skip_prologue(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: score-tdep.c:627
static const gdb_byte * score3_breakpoint_from_pc(struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
Definition: score-tdep.c:366
static int score3_stack_frame_destroyed_p(struct gdbarch *gdbarch, CORE_ADDR cur_pc)
Definition: score-tdep.c:769
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition: frame.c:554
static int score_type_needs_double_align(struct type *type)
Definition: score-tdep.c:488
struct trad_frame_saved_reg * saved_regs
Definition: score-tdep.c:53
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
bfd_vma CORE_ADDR
Definition: common-types.h:41
struct value * trad_frame_get_prev_register(struct frame_info *this_frame, struct trad_frame_saved_reg this_saved_regs[], int regnum)
Definition: trad-frame.c:135
void xfree(void *)
Definition: common-utils.c:97
void trad_frame_set_value(struct trad_frame_saved_reg this_saved_regs[], int regnum, LONGEST val)
Definition: trad-frame.c:92
ULONGEST align_down(ULONGEST v, int n)
Definition: utils.c:2971
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
return_value_convention
Definition: defs.h:206
void regcache_supply_regset(const struct regset *regset, struct regcache *regcache, int regnum, const void *buf, size_t size)
Definition: regcache.c:1149
static int reg_offset[]
Definition: i386gnu-nat.c:42
static void score7_linux_iterate_over_regset_sections(struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache)
Definition: score-tdep.c:1455
static struct frame_id score_dummy_id(struct gdbarch *gdbarch, struct frame_info *this_frame)
Definition: score-tdep.c:480
void regcache_cooked_write_part(struct regcache *regcache, int regnum, int offset, int len, const gdb_byte *buf)
Definition: regcache.c:1028
struct gdbarch_list * gdbarch_list_lookup_by_info(struct gdbarch_list *arches, const struct gdbarch_info *info)
Definition: gdbarch.c:4985
static int target_mach
Definition: score-tdep.c:56
static struct gdbarch * score_gdbarch_init(struct gdbarch_info info, struct gdbarch_list *arches)
Definition: score-tdep.c:1465
#define SCORE7_LINUX_EPC_OFFSET
Definition: score-tdep.c:1425
#define _(String)
Definition: gdb_locale.h:40
const struct bfd_arch_info * bfd_arch_info
Definition: gdbarch.h:1549
static CORE_ADDR score3_skip_prologue(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: score-tdep.c:684
#define TYPE_FIELD_TYPE(thistype, n)
Definition: gdbtypes.h:1368
unsigned long long raw
Definition: score-tdep.c:45
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
Definition: frame-unwind.c:78
static const gdb_byte * score7_breakpoint_from_pc(struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *lenptr)
Definition: score-tdep.c:310
#define SCORE_BEGIN_ARG_REGNUM
Definition: score-tdep.h:44
#define FRAME_OBSTACK_ZALLOC(TYPE)
Definition: frame.h:660
void gdbarch_register(enum bfd_architecture bfd_architecture, gdbarch_init_ftype *init, gdbarch_dump_tdep_ftype *dump_tdep)
Definition: gdbarch.c:4933
Definition: regset.h:34
static const struct frame_base * score_prologue_frame_base_sniffer(struct frame_info *this_frame)
Definition: score-tdep.c:1399
static gdb_byte * score7_malloc_and_get_memblock(CORE_ADDR addr, CORE_ADDR size)
Definition: score-tdep.c:814
static CORE_ADDR score_unwind_pc(struct gdbarch *gdbarch, struct frame_info *next_frame)
Definition: score-tdep.c:74
#define SCORE_LAST_ARG_REGNUM
Definition: score-tdep.h:45
#define AT_ENTRY_POINT
Definition: inferior.h:259
void set_gdbarch_register_type(struct gdbarch *gdbarch, gdbarch_register_type_ftype register_type)
Definition: gdbarch.c:2151
struct type * check_typedef(struct type *type)
Definition: gdbtypes.c:2217
const struct frame_base * dwarf2_frame_base_sniffer(struct frame_info *this_frame)
const gdb_byte * value_contents(struct value *value)
Definition: value.c:1329
#define EXTRACT_LEN
void initialize_file_ftype(void)
Definition: defs.h:281
static const struct frame_base score_prologue_frame_base
Definition: score-tdep.c:1390
static const char * score3_register_name(struct gdbarch *gdbarch, int regnum)
Definition: score-tdep.c:100
void set_gdbarch_stack_frame_destroyed_p(struct gdbarch *gdbarch, gdbarch_stack_frame_destroyed_p_ftype stack_frame_destroyed_p)
Definition: gdbarch.c:3135
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
static struct value * score_prologue_prev_register(struct frame_info *this_frame, void **this_cache, int regnum)
Definition: score-tdep.c:1362
struct_return
Definition: arm-tdep.h:148
void set_gdbarch_adjust_breakpoint_address(struct gdbarch *gdbarch, gdbarch_adjust_breakpoint_address_ftype adjust_breakpoint_address)
Definition: gdbarch.c:2713
#define SCORE_REGSIZE
Definition: score-tdep.h:41
static void score_prologue_this_id(struct frame_info *this_frame, void **this_cache, struct frame_id *this_id)
Definition: score-tdep.c:1353
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
static CORE_ADDR score_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: score-tdep.c:509
void set_gdbarch_register_sim_regno(struct gdbarch *gdbarch, gdbarch_register_sim_regno_ftype register_sim_regno)
Definition: gdbarch.c:2332
#define SCORE16_INSTLEN
Definition: score-tdep.h:48
static void score3_analyze_prologue(CORE_ADDR startaddr, CORE_ADDR pc, struct frame_info *this_frame, struct score_frame_cache *this_cache)
Definition: score-tdep.c:1074
#define TARGET_CHAR_BIT
Definition: host-defs.h:29
#define SCORE7_LINUX_SIZEOF_GREGSET
Definition: score-tdep.c:1426
CORE_ADDR fp
Definition: score-tdep.c:52
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 regcache_collect_regset(const struct regset *regset, const struct regcache *regcache, int regnum, void *buf, size_t size)
Definition: regcache.c:1162
void set_gdbarch_unwind_pc(struct gdbarch *gdbarch, gdbarch_unwind_pc_ftype unwind_pc)
Definition: gdbarch.c:2863
static void score_xfer_register(struct regcache *regcache, int regnum, int length, enum bfd_endian endian, gdb_byte *readbuf, const gdb_byte *writebuf, int buf_offset)
Definition: score-tdep.c:417
void set_gdbarch_breakpoint_from_pc(struct gdbarch *gdbarch, gdbarch_breakpoint_from_pc_ftype breakpoint_from_pc)
Definition: gdbarch.c:2672
struct type * builtin_uint32
Definition: gdbtypes.h:1519
int default_frame_sniffer(const struct frame_unwind *self, struct frame_info *this_frame, void **this_prologue_cache)
Definition: frame-unwind.c:170
static int score_print_insn(bfd_vma memaddr, struct disassemble_info *info)
Definition: score-tdep.c:130
#define gdb_assert(expr)
Definition: gdb_assert.h:33
unsigned int len
Definition: score-tdep.c:46
void set_gdbarch_unwind_sp(struct gdbarch *gdbarch, gdbarch_unwind_sp_ftype unwind_sp)
Definition: gdbarch.c:2887
#define target_has_execution
Definition: target.h:1726
static const struct regcache_map_entry score7_linux_gregmap[]
Definition: score-tdep.c:1406
#define SCORE7_NUM_REGS
Definition: score-tdep.h:42
struct gdbarch * gdbarch
Definition: gdbarch.h:1542
int regnum
Definition: aarch64-tdep.c:69
static CORE_ADDR score_frame_align(struct gdbarch *gdbarch, CORE_ADDR addr)
Definition: score-tdep.c:411
void( iterate_over_regset_sections_cb)(const char *sect_name, int size, const struct regset *regset, const char *human_name, void *cb_data)
Definition: gdbarch.h:98
static void score7_free_memblock(gdb_byte *memblock)
Definition: score-tdep.c:841
ULONGEST get_frame_register_unsigned(struct frame_info *frame, int regnum)
Definition: frame.c:1194
void * xmalloc(YYSIZE_T)
#define SCORE3_NUM_REGS
Definition: score-tdep.h:43
Definition: value.c:172
static struct score_frame_cache * score_make_prologue_cache(struct frame_info *this_frame, void **this_cache)
Definition: score-tdep.c:1320
static CORE_ADDR score_prologue_frame_base_address(struct frame_info *this_frame, void **this_cache)
Definition: score-tdep.c:1382
static const char * score7_register_name(struct gdbarch *gdbarch, int regnum)
Definition: score-tdep.c:80
struct trad_frame_saved_reg * trad_frame_alloc_saved_regs(struct frame_info *this_frame)
Definition: trad-frame.c:52
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
ULONGEST align_up(ULONGEST v, int n)
Definition: utils.c:2963
static CORE_ADDR score_unwind_sp(struct gdbarch *gdbarch, struct frame_info *next_frame)
Definition: score-tdep.c:68
#define SCORE_INSTLEN
Definition: score-tdep.h:47
#define TYPE_CODE(thistype)
Definition: gdbtypes.h:1240
static struct type * score_register_type(struct gdbarch *gdbarch, int regnum)
Definition: score-tdep.c:59
static int score7_stack_frame_destroyed_p(struct gdbarch *gdbarch, CORE_ADDR cur_pc)
Definition: score-tdep.c:743
void regcache_cooked_write_unsigned(struct regcache *regcache, int regnum, ULONGEST val)
Definition: regcache.c:871
static const struct frame_unwind score_prologue_unwind
Definition: score-tdep.c:1370
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: target.c:1393
void set_gdbarch_int_bit(struct gdbarch *gdbarch, int int_bit)
Definition: gdbarch.c:1500
int offset
Definition: agent.c:65
initialize_file_ftype _initialize_score_tdep
#define TYPE_NFIELDS(thistype)
Definition: gdbtypes.h:1241
void dwarf2_append_unwinders(struct gdbarch *gdbarch)
static CORE_ADDR score_adjust_breakpoint_address(struct gdbarch *gdbarch, CORE_ADDR bpaddr)
Definition: score-tdep.c:397
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1041
void frame_base_append_sniffer(struct gdbarch *gdbarch, frame_base_sniffer_ftype *sniffer)
Definition: frame-base.c:82
void set_gdbarch_call_dummy_location(struct gdbarch *gdbarch, int call_dummy_location)
Definition: gdbarch.c:2233
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
void set_gdbarch_long_double_bit(struct gdbarch *gdbarch, int long_double_bit)
Definition: gdbarch.c:1667
unsigned long long v
Definition: score-tdep.c:44
#define G_FLD(_i, _ms, _ls)
Definition: score-tdep.c:40
struct type * value_type(const struct value *value)
Definition: value.c:1021
CORE_ADDR addr
Definition: frame.c:119
enum register_status regcache_cooked_read_part(struct regcache *regcache, int regnum, int offset, int len, gdb_byte *buf)
Definition: regcache.c:1017
void set_gdbarch_return_value(struct gdbarch *gdbarch, gdbarch_return_value_ftype return_value)
Definition: gdbarch.c:2556
#define TYPE_LENGTH(thistype)
Definition: gdbtypes.h:1237
void set_gdbarch_push_dummy_call(struct gdbarch *gdbarch, gdbarch_push_dummy_call_ftype push_dummy_call)
Definition: gdbarch.c:2216
static inst_t * score3_adjust_pc_and_fetch_inst(CORE_ADDR *pcptr, int *lenptr, enum bfd_endian byte_order)
Definition: score-tdep.c:179
void set_gdbarch_iterate_over_regset_sections(struct gdbarch *gdbarch, gdbarch_iterate_over_regset_sections_ftype iterate_over_regset_sections)
Definition: gdbarch.c:3398
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 void score7_adjust_memblock_ptr(gdb_byte **memblock, CORE_ADDR prev_pc, CORE_ADDR cur_pc)
Definition: score-tdep.c:847
CORE_ADDR base
Definition: score-tdep.c:51
static enum return_value_convention score_return_value(struct gdbarch *gdbarch, struct value *function, struct type *type, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
Definition: score-tdep.c:451
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
CORE_ADDR get_frame_func(struct frame_info *this_frame)
Definition: frame.c:920
static void score7_linux_supply_gregset(const struct regset *regset, struct regcache *regcache, int regnum, const void *buf, size_t size)
Definition: score-tdep.c:1429
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
static void score7_analyze_prologue(CORE_ADDR startaddr, CORE_ADDR pc, struct frame_info *this_frame, struct score_frame_cache *this_cache)
Definition: score-tdep.c:867
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
Definition: frame.c:2535
Definition: regcache.h:167
void set_gdbarch_print_insn(struct gdbarch *gdbarch, gdbarch_print_insn_ftype print_insn)
Definition: gdbarch.c:3067
static inst_t * score7_fetch_inst(struct gdbarch *gdbarch, CORE_ADDR addr, gdb_byte *memblock)
Definition: score-tdep.c:139
const ULONGEST const LONGEST len
Definition: target.h:309