1 /* Target-dependent code for the S+core architecture, for GDB,
4 Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6 Contributed by Qinwei (qinwei@sunnorth.com.cn)
7 Contributed by Ching-Peng Lin (cplin@sunplus.com)
9 This file is part of GDB.
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.
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.
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/>. */
25 #include "gdb_assert.h"
31 #include "arch-utils.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"
40 #define G_FLD(_i,_ms,_ls) (((_i) << (31 - (_ms))) >> (31 - (_ms) + (_ls)))
41 #define RM_PBITS(_raw) ((G_FLD(_raw, 31, 16) << 15) | G_FLD(_raw, 14, 0))
49 struct score_frame_cache
53 struct trad_frame_saved_reg *saved_regs;
57 /* If S+core GCC will generate these instructions in the prologue:
63 then .pdr section is used. */
74 typedef struct frame_extra_info
77 unsigned int pdr[P_SIZE];
89 score_compare_pdr_entries (const void *a, const void *b)
91 CORE_ADDR lhs = bfd_get_32 (the_bfd, (bfd_byte *) a);
92 CORE_ADDR rhs = bfd_get_32 (the_bfd, (bfd_byte *) b);
102 score_analyze_pdr_section (CORE_ADDR startaddr, CORE_ADDR pc,
103 struct frame_info *this_frame,
104 struct score_frame_cache *this_cache)
107 struct obj_section *sec;
108 extra_info_t *fci_ext;
109 CORE_ADDR leaf_ra_stack_addr = -1;
111 gdb_assert (startaddr <= pc);
112 gdb_assert (this_cache != NULL);
114 fci_ext = frame_obstack_zalloc (sizeof (extra_info_t));
115 if ((sec = find_pc_section (pc)) == NULL)
117 error ("Error: Can't find section in file:%s, line:%d!",
122 /* Anylyze .pdr section and get coresponding fields. */
124 static struct obj_priv *priv = NULL;
129 priv = obstack_alloc (&sec->objfile->objfile_obstack,
130 sizeof (struct obj_priv));
131 if ((bfdsec = bfd_get_section_by_name (sec->objfile->obfd, ".pdr")))
133 priv->size = bfd_section_size (sec->objfile->obfd, bfdsec);
134 priv->contents = obstack_alloc (&sec->objfile->objfile_obstack,
136 bfd_get_section_contents (sec->objfile->obfd, bfdsec,
137 priv->contents, 0, priv->size);
138 the_bfd = sec->objfile->obfd;
139 qsort (priv->contents, priv->size / 32, 32,
140 score_compare_pdr_entries);
148 int low = 0, mid, high = priv->size / 32;
153 mid = (low + high) / 2;
154 ptr = priv->contents + mid * 32;
155 pdr_pc = bfd_get_signed_32 (sec->objfile->obfd, ptr);
156 pdr_pc += ANOFFSET (sec->objfile->section_offsets,
157 SECT_OFF_TEXT (sec->objfile));
158 if (pdr_pc == startaddr)
160 if (pdr_pc > startaddr)
169 gdb_assert (bfd_get_32 (sec->objfile->obfd, ptr) == startaddr);
170 #define EXT_PDR(_pi) bfd_get_32(sec->objfile->obfd, ptr+((_pi)<<2))
171 fci_ext->pdr[PI_SYM] = EXT_PDR (PI_SYM);
172 fci_ext->pdr[PI_R_MSK] = EXT_PDR (PI_R_MSK);
173 fci_ext->pdr[PI_R_OFF] = EXT_PDR (PI_R_OFF);
174 fci_ext->pdr[PI_R_LEF] = EXT_PDR (PI_R_LEF);
175 fci_ext->pdr[PI_F_OFF] = EXT_PDR (PI_F_OFF);
176 fci_ext->pdr[PI_F_REG] = EXT_PDR (PI_F_REG);
177 fci_ext->pdr[PI_RAREG] = EXT_PDR (PI_RAREG);
186 /* Open these functions if build with simulator. */
189 score_target_can_use_watch (int type, int cnt, int othertype)
191 if (strcmp (current_target.to_shortname, "sim") == 0)
193 return soc_gh_can_use_watch (type, cnt);
197 return (*current_target.to_can_use_hw_breakpoint) (type, cnt, othertype);
202 score_stopped_by_watch (void)
204 if (strcmp (current_target.to_shortname, "sim") == 0)
206 return soc_gh_stopped_by_watch ();
210 return (*current_target.to_stopped_by_watchpoint) ();
215 score_target_insert_watchpoint (CORE_ADDR addr, int len, int type)
217 if (strcmp (current_target.to_shortname, "sim") == 0)
219 return soc_gh_add_watch (addr, len, type);
223 return (*current_target.to_insert_watchpoint) (addr, len, type);
228 score_target_remove_watchpoint (CORE_ADDR addr, int len, int type)
230 if (strcmp (current_target.to_shortname, "sim") == 0)
232 return soc_gh_del_watch (addr, len, type);
236 return (*current_target.to_remove_watchpoint) (addr, len, type);
241 score_target_insert_hw_breakpoint (struct bp_target_info * bp_tgt)
243 if (strcmp (current_target.to_shortname, "sim") == 0)
245 return soc_gh_add_hardbp (bp_tgt->placed_address);
249 return (*current_target.to_insert_hw_breakpoint) (bp_tgt);
254 score_target_remove_hw_breakpoint (struct bp_target_info * bp_tgt)
256 if (strcmp (current_target.to_shortname, "sim") == 0)
258 return soc_gh_del_hardbp (bp_tgt->placed_address);
262 return (*current_target.to_remove_hw_breakpoint) (bp_tgt);
268 score_register_type (struct gdbarch *gdbarch, int regnum)
270 gdb_assert (regnum >= 0 && regnum < SCORE_NUM_REGS);
271 return builtin_type_uint32;
275 score_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
277 return frame_unwind_register_unsigned (next_frame, SCORE_PC_REGNUM);
281 score_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
283 return frame_unwind_register_unsigned (next_frame, SCORE_SP_REGNUM);
287 score_register_name (struct gdbarch *gdbarch, int regnum)
289 const char *score_register_names[] = {
290 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
291 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
292 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
293 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
295 "PSR", "COND", "ECR", "EXCPVEC",
296 "CCR", "EPC", "EMA", "TLBLOCK",
297 "TLBPT", "PEADDR", "TLBRPT", "PEVN",
298 "PECTX", "LIMPFN", "LDMPFN", "PREV",
299 "DREG", "PC", "DSAVE", "COUNTER",
300 "LDCR", "STCR", "CEH", "CEL",
303 gdb_assert (regnum >= 0 && regnum < SCORE_NUM_REGS);
304 return score_register_names[regnum];
308 score_register_sim_regno (struct gdbarch *gdbarch, int regnum)
310 gdb_assert (regnum >= 0 && regnum < SCORE_NUM_REGS);
315 score_print_insn (bfd_vma memaddr, struct disassemble_info *info)
317 if (info->endian == BFD_ENDIAN_BIG)
318 return print_insn_big_score (memaddr, info);
320 return print_insn_little_score (memaddr, info);
323 static const gdb_byte *
324 score_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr,
327 gdb_byte buf[SCORE_INSTLEN] = { 0 };
331 if ((ret = target_read_memory (*pcptr & ~0x3, buf, SCORE_INSTLEN)) != 0)
333 error ("Error: target_read_memory in file:%s, line:%d!",
336 raw = extract_unsigned_integer (buf, SCORE_INSTLEN);
338 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
340 if (!(raw & 0x80008000))
342 /* 16bits instruction. */
343 static gdb_byte big_breakpoint16[] = { 0x60, 0x02 };
345 *lenptr = sizeof (big_breakpoint16);
346 return big_breakpoint16;
350 /* 32bits instruction. */
351 static gdb_byte big_breakpoint32[] = { 0x80, 0x00, 0x80, 0x06 };
353 *lenptr = sizeof (big_breakpoint32);
354 return big_breakpoint32;
359 if (!(raw & 0x80008000))
361 /* 16bits instruction. */
362 static gdb_byte little_breakpoint16[] = { 0x02, 0x60 };
364 *lenptr = sizeof (little_breakpoint16);
365 return little_breakpoint16;
369 /* 32bits instruction. */
370 static gdb_byte little_breakpoint32[] = { 0x06, 0x80, 0x00, 0x80 };
372 *lenptr = sizeof (little_breakpoint32);
373 return little_breakpoint32;
379 score_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
381 return align_down (addr, 16);
385 score_xfer_register (struct regcache *regcache, int regnum, int length,
386 enum bfd_endian endian, gdb_byte *readbuf,
387 const gdb_byte *writebuf, int buf_offset)
390 gdb_assert (regnum >= 0 && regnum < SCORE_NUM_REGS);
395 reg_offset = SCORE_REGSIZE - length;
397 case BFD_ENDIAN_LITTLE:
400 case BFD_ENDIAN_UNKNOWN:
404 error ("Error: score_xfer_register in file:%s, line:%d!",
409 regcache_cooked_read_part (regcache, regnum, reg_offset, length,
410 readbuf + buf_offset);
411 if (writebuf != NULL)
412 regcache_cooked_write_part (regcache, regnum, reg_offset, length,
413 writebuf + buf_offset);
416 static enum return_value_convention
417 score_return_value (struct gdbarch *gdbarch, struct type *func_type,
418 struct type *type, struct regcache *regcache,
419 gdb_byte * readbuf, const gdb_byte * writebuf)
421 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
422 || TYPE_CODE (type) == TYPE_CODE_UNION
423 || TYPE_CODE (type) == TYPE_CODE_ARRAY)
424 return RETURN_VALUE_STRUCT_CONVENTION;
429 for (offset = 0, regnum = SCORE_A0_REGNUM;
430 offset < TYPE_LENGTH (type);
431 offset += SCORE_REGSIZE, regnum++)
433 int xfer = SCORE_REGSIZE;
434 if (offset + xfer > TYPE_LENGTH (type))
435 xfer = TYPE_LENGTH (type) - offset;
436 score_xfer_register (regcache, regnum, xfer,
437 gdbarch_byte_order (gdbarch),
438 readbuf, writebuf, offset);
440 return RETURN_VALUE_REGISTER_CONVENTION;
444 static struct frame_id
445 score_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
447 return frame_id_build (
448 get_frame_register_unsigned (this_frame, SCORE_SP_REGNUM),
449 get_frame_pc (this_frame));
453 score_type_needs_double_align (struct type *type)
455 enum type_code typecode = TYPE_CODE (type);
457 if ((typecode == TYPE_CODE_INT && TYPE_LENGTH (type) == 8)
458 || (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8))
460 else if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
464 n = TYPE_NFIELDS (type);
465 for (i = 0; i < n; i++)
466 if (score_type_needs_double_align (TYPE_FIELD_TYPE (type, i)))
474 score_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
475 struct regcache *regcache, CORE_ADDR bp_addr,
476 int nargs, struct value **args, CORE_ADDR sp,
477 int struct_return, CORE_ADDR struct_addr)
482 CORE_ADDR stack_offset = 0;
485 /* Step 1, Save RA. */
486 regcache_cooked_write_unsigned (regcache, SCORE_RA_REGNUM, bp_addr);
488 /* Step 2, Make space on the stack for the args. */
489 struct_addr = align_down (struct_addr, 16);
490 sp = align_down (sp, 16);
491 for (argnum = 0; argnum < nargs; argnum++)
492 arglen += align_up (TYPE_LENGTH (value_type (args[argnum])),
494 sp -= align_up (arglen, 16);
496 argreg = SCORE_BEGIN_ARG_REGNUM;
498 /* Step 3, Check if struct return then save the struct address to
499 r4 and increase the stack_offset by 4. */
502 regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
503 stack_offset += SCORE_REGSIZE;
506 /* Step 4, Load arguments:
507 If arg length is too long (> 4 bytes), then split the arg and
509 for (argnum = 0; argnum < nargs; argnum++)
511 struct value *arg = args[argnum];
512 struct type *arg_type = check_typedef (value_type (arg));
513 enum type_code typecode = TYPE_CODE (arg_type);
514 const gdb_byte *val = value_contents (arg);
515 int downward_offset = 0;
516 int odd_sized_struct_p;
517 int arg_last_part_p = 0;
519 arglen = TYPE_LENGTH (arg_type);
520 odd_sized_struct_p = (arglen > SCORE_REGSIZE
521 && arglen % SCORE_REGSIZE != 0);
523 /* If a arg should be aligned to 8 bytes (long long or double),
524 the value should be put to even register numbers. */
525 if (score_type_needs_double_align (arg_type))
531 /* If sizeof a block < SCORE_REGSIZE, then Score GCC will chose
532 the default "downward"/"upward" method:
538 char a; char b; char c;
539 } s = {'a', 'b', 'c'};
541 Big endian: s = {X, 'a', 'b', 'c'}
542 Little endian: s = {'a', 'b', 'c', X}
544 Where X is a hole. */
546 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
547 && (typecode == TYPE_CODE_STRUCT
548 || typecode == TYPE_CODE_UNION)
549 && argreg > SCORE_LAST_ARG_REGNUM
550 && arglen < SCORE_REGSIZE)
551 downward_offset += (SCORE_REGSIZE - arglen);
555 int partial_len = arglen < SCORE_REGSIZE ? arglen : SCORE_REGSIZE;
556 ULONGEST regval = extract_unsigned_integer (val, partial_len);
558 /* The last part of a arg should shift left when
559 gdbarch_byte_order is BFD_ENDIAN_BIG. */
560 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
561 && arg_last_part_p == 1
562 && (typecode == TYPE_CODE_STRUCT
563 || typecode == TYPE_CODE_UNION))
564 regval <<= ((SCORE_REGSIZE - partial_len) * TARGET_CHAR_BIT);
566 /* Always increase the stack_offset and save args to stack. */
567 addr = sp + stack_offset + downward_offset;
568 write_memory (addr, val, partial_len);
570 if (argreg <= SCORE_LAST_ARG_REGNUM)
572 regcache_cooked_write_unsigned (regcache, argreg++, regval);
573 if (arglen > SCORE_REGSIZE && arglen < SCORE_REGSIZE * 2)
578 arglen -= partial_len;
579 stack_offset += align_up (partial_len, SCORE_REGSIZE);
583 /* Step 5, Save SP. */
584 regcache_cooked_write_unsigned (regcache, SCORE_SP_REGNUM, sp);
590 score_malloc_and_get_memblock (CORE_ADDR addr, CORE_ADDR size)
593 char *memblock = NULL;
597 error ("Error: malloc size < 0 in file:%s, line:%d!",
604 memblock = (char *) xmalloc (size);
605 memset (memblock, 0, size);
606 ret = target_read_memory (addr & ~0x3, memblock, size);
609 error ("Error: target_read_memory in file:%s, line:%d!",
617 score_free_memblock (char *memblock)
623 score_adjust_memblock_ptr (char **memblock, CORE_ADDR prev_pc,
628 /* First time call this function, do nothing. */
630 else if (cur_pc - prev_pc == 2 && (cur_pc & 0x3) == 0)
632 /* First 16-bit instruction, then 32-bit instruction. */
633 *memblock += SCORE_INSTLEN;
635 else if (cur_pc - prev_pc == 4)
637 /* Is 32-bit instruction, increase MEMBLOCK by 4. */
638 *memblock += SCORE_INSTLEN;
643 score_fetch_inst (struct gdbarch *gdbarch, CORE_ADDR addr, char *memblock)
645 static inst_t inst = { 0, 0 };
646 char buf[SCORE_INSTLEN] = { 0 };
650 if (target_has_execution && memblock != NULL)
652 /* Fetch instruction from local MEMBLOCK. */
653 memcpy (buf, memblock, SCORE_INSTLEN);
657 /* Fetch instruction from target. */
658 ret = target_read_memory (addr & ~0x3, buf, SCORE_INSTLEN);
661 error ("Error: target_read_memory in file:%s, line:%d!",
667 inst.raw = extract_unsigned_integer (buf, SCORE_INSTLEN);
668 inst.is15 = !(inst.raw & 0x80008000);
669 inst.v = RM_PBITS (inst.raw);
670 big = (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG);
673 if (big ^ ((addr & 0x2) == 2))
674 inst.v = G_FLD (inst.v, 29, 15);
676 inst.v = G_FLD (inst.v, 14, 0);
682 score_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
685 int iscan = 32, stack_sub = 0;
688 inst_t *inst = score_fetch_inst (gdbarch, cpc, NULL);
691 if (!inst->is15 && !stack_sub
692 && (G_FLD (inst->v, 29, 25) == 0x1
693 && G_FLD (inst->v, 24, 20) == 0x0))
695 /* addi r0, offset */
696 pc = stack_sub = cpc + SCORE_INSTLEN;
699 && inst->v == RM_PBITS (0x8040bc56))
702 pc = cpc + SCORE_INSTLEN;
706 && inst->v == RM_PBITS (0x0203))
709 pc = cpc + SCORE16_INSTLEN;
713 && ((G_FLD (inst->v, 14, 12) == 3) /* j15 form */
714 || (G_FLD (inst->v, 14, 12) == 4) /* b15 form */
715 || (G_FLD (inst->v, 14, 12) == 0x0
716 && G_FLD (inst->v, 3, 0) == 0x4))) /* br! */
719 && ((G_FLD (inst->v, 29, 25) == 2) /* j32 form */
720 || (G_FLD (inst->v, 29, 25) == 4) /* b32 form */
721 || (G_FLD (inst->v, 29, 25) == 0x0
722 && G_FLD (inst->v, 6, 1) == 0x4))) /* br */
725 cpc += inst->is15 ? SCORE16_INSTLEN : SCORE_INSTLEN;
731 score_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR cur_pc)
733 inst_t *inst = score_fetch_inst (gdbarch, cur_pc, NULL);
736 return 1; /* mv! r0, r2 */
737 else if (G_FLD (inst->v, 14, 12) == 0x2
738 && G_FLD (inst->v, 3, 0) == 0xa)
740 else if (G_FLD (inst->v, 14, 12) == 0x0
741 && G_FLD (inst->v, 7, 0) == 0x34)
742 return 1; /* br! r3 */
743 else if (G_FLD (inst->v, 29, 15) == 0x2
744 && G_FLD (inst->v, 6, 1) == 0x2b)
745 return 1; /* mv r0, r2 */
746 else if (G_FLD (inst->v, 29, 25) == 0x0
747 && G_FLD (inst->v, 6, 1) == 0x4
748 && G_FLD (inst->v, 19, 15) == 0x3)
749 return 1; /* br r3 */
755 score_analyze_prologue (CORE_ADDR startaddr, CORE_ADDR pc,
756 struct frame_info *this_frame,
757 struct score_frame_cache *this_cache)
759 struct gdbarch *gdbarch = get_frame_arch (this_frame);
762 CORE_ADDR cur_pc = startaddr;
771 char *memblock = NULL;
772 char *memblock_ptr = NULL;
773 CORE_ADDR prev_pc = -1;
775 /* Allocate MEMBLOCK if PC - STARTADDR > 0. */
776 memblock_ptr = memblock =
777 score_malloc_and_get_memblock (startaddr, pc - startaddr);
779 sp = get_frame_register_unsigned (this_frame, SCORE_SP_REGNUM);
780 fp = get_frame_register_unsigned (this_frame, SCORE_FP_REGNUM);
782 for (; cur_pc < pc; prev_pc = cur_pc, cur_pc += inst_len)
785 if (memblock != NULL)
787 /* Reading memory block from target succefully and got all
788 the instructions(from STARTADDR to PC) needed. */
789 score_adjust_memblock_ptr (&memblock, prev_pc, cur_pc);
790 inst = score_fetch_inst (gdbarch, cur_pc, memblock);
794 /* Otherwise, we fetch 4 bytes from target, and GDB also
796 inst = score_fetch_inst (gdbarch, cur_pc, NULL);
801 inst_len = SCORE16_INSTLEN;
803 if (G_FLD (inst->v, 14, 12) == 0x2
804 && G_FLD (inst->v, 3, 0) == 0xe)
809 if (G_FLD (inst->v, 11, 7) == 0x6
813 ra_offset = sp_offset;
816 else if (G_FLD (inst->v, 11, 7) == 0x4
820 fp_offset = sp_offset;
824 else if (G_FLD (inst->v, 14, 12) == 0x2
825 && G_FLD (inst->v, 3, 0) == 0xa)
830 else if (G_FLD (inst->v, 14, 7) == 0xc1
831 && G_FLD (inst->v, 2, 0) == 0x0)
834 sp_offset += (int) pow (2, G_FLD (inst->v, 6, 3));
836 else if (G_FLD (inst->v, 14, 7) == 0xc0
837 && G_FLD (inst->v, 2, 0) == 0x0)
840 sp_offset -= (int) pow (2, G_FLD (inst->v, 6, 3));
845 inst_len = SCORE_INSTLEN;
847 if (G_FLD (inst->v, 29, 15) == 0xc60
848 && G_FLD (inst->v, 2, 0) == 0x4)
850 /* sw r3, [r0, offset]+ */
851 sp_offset += SCORE_INSTLEN;
852 if (ra_offset_p == 0)
854 ra_offset = sp_offset;
858 if (G_FLD (inst->v, 29, 15) == 0xc40
859 && G_FLD (inst->v, 2, 0) == 0x4)
861 /* sw r2, [r0, offset]+ */
862 sp_offset += SCORE_INSTLEN;
863 if (fp_offset_p == 0)
865 fp_offset = sp_offset;
869 else if (G_FLD (inst->v, 29, 15) == 0x1c60
870 && G_FLD (inst->v, 2, 0) == 0x0)
872 /* lw r3, [r0]+, 4 */
873 sp_offset -= SCORE_INSTLEN;
876 else if (G_FLD (inst->v, 29, 15) == 0x1c40
877 && G_FLD (inst->v, 2, 0) == 0x0)
879 /* lw r2, [r0]+, 4 */
880 sp_offset -= SCORE_INSTLEN;
884 else if (G_FLD (inst->v, 29, 17) == 0x100
885 && G_FLD (inst->v, 0, 0) == 0x0)
887 /* addi r0, -offset */
888 sp_offset += 65536 - G_FLD (inst->v, 16, 1);
890 else if (G_FLD (inst->v, 29, 17) == 0x110
891 && G_FLD (inst->v, 0, 0) == 0x0)
893 /* addi r2, offset */
896 unsigned int save_v = inst->v;
898 score_fetch_inst (gdbarch, cur_pc + SCORE_INSTLEN, NULL);
899 if (inst2->v == 0x23)
902 sp_offset -= G_FLD (save_v, 16, 1);
910 if (ra_offset_p == 1)
912 if (this_cache->saved_regs[SCORE_PC_REGNUM].addr == -1)
913 this_cache->saved_regs[SCORE_PC_REGNUM].addr =
914 sp + sp_offset - ra_offset;
918 this_cache->saved_regs[SCORE_PC_REGNUM] =
919 this_cache->saved_regs[SCORE_RA_REGNUM];
923 if (fp_offset_p == 1)
925 if (this_cache->saved_regs[SCORE_FP_REGNUM].addr == -1)
926 this_cache->saved_regs[SCORE_FP_REGNUM].addr =
927 sp + sp_offset - fp_offset;
930 /* Save SP and FP. */
931 this_cache->base = sp + sp_offset;
934 /* Don't forget to free MEMBLOCK if we allocated it. */
935 if (memblock_ptr != NULL)
936 score_free_memblock (memblock_ptr);
939 static struct score_frame_cache *
940 score_make_prologue_cache (struct frame_info *this_frame, void **this_cache)
942 struct score_frame_cache *cache;
944 if ((*this_cache) != NULL)
945 return (*this_cache);
947 cache = FRAME_OBSTACK_ZALLOC (struct score_frame_cache);
948 (*this_cache) = cache;
949 cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
951 /* Analyze the prologue. */
953 const CORE_ADDR pc = get_frame_pc (this_frame);
954 CORE_ADDR start_addr;
956 find_pc_partial_function (pc, NULL, &start_addr, NULL);
959 score_analyze_prologue (start_addr, pc, this_frame, *this_cache);
963 trad_frame_set_value (cache->saved_regs, SCORE_SP_REGNUM, cache->base);
965 return (*this_cache);
969 score_prologue_this_id (struct frame_info *this_frame, void **this_cache,
970 struct frame_id *this_id)
972 struct score_frame_cache *info = score_make_prologue_cache (this_frame,
974 (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
977 static struct value *
978 score_prologue_prev_register (struct frame_info *this_frame,
979 void **this_cache, int regnum)
981 struct score_frame_cache *info = score_make_prologue_cache (this_frame,
983 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
986 static const struct frame_unwind score_prologue_unwind =
989 score_prologue_this_id,
990 score_prologue_prev_register,
992 default_frame_sniffer
996 score_prologue_frame_base_address (struct frame_info *this_frame,
999 struct score_frame_cache *info =
1000 score_make_prologue_cache (this_frame, this_cache);
1004 static const struct frame_base score_prologue_frame_base =
1006 &score_prologue_unwind,
1007 score_prologue_frame_base_address,
1008 score_prologue_frame_base_address,
1009 score_prologue_frame_base_address,
1012 static const struct frame_base *
1013 score_prologue_frame_base_sniffer (struct frame_info *this_frame)
1015 return &score_prologue_frame_base;
1018 static struct gdbarch *
1019 score_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1021 struct gdbarch *gdbarch;
1023 arches = gdbarch_list_lookup_by_info (arches, &info);
1026 return (arches->gdbarch);
1028 gdbarch = gdbarch_alloc (&info, 0);
1030 set_gdbarch_short_bit (gdbarch, 16);
1031 set_gdbarch_int_bit (gdbarch, 32);
1032 set_gdbarch_float_bit (gdbarch, 32);
1033 set_gdbarch_double_bit (gdbarch, 64);
1034 set_gdbarch_long_double_bit (gdbarch, 64);
1035 set_gdbarch_register_sim_regno (gdbarch, score_register_sim_regno);
1036 set_gdbarch_pc_regnum (gdbarch, SCORE_PC_REGNUM);
1037 set_gdbarch_sp_regnum (gdbarch, SCORE_SP_REGNUM);
1038 set_gdbarch_num_regs (gdbarch, SCORE_NUM_REGS);
1039 set_gdbarch_register_name (gdbarch, score_register_name);
1040 set_gdbarch_breakpoint_from_pc (gdbarch, score_breakpoint_from_pc);
1041 set_gdbarch_register_type (gdbarch, score_register_type);
1042 set_gdbarch_frame_align (gdbarch, score_frame_align);
1043 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1044 set_gdbarch_unwind_pc (gdbarch, score_unwind_pc);
1045 set_gdbarch_unwind_sp (gdbarch, score_unwind_sp);
1046 set_gdbarch_print_insn (gdbarch, score_print_insn);
1047 set_gdbarch_skip_prologue (gdbarch, score_skip_prologue);
1048 set_gdbarch_in_function_epilogue_p (gdbarch, score_in_function_epilogue_p);
1050 /* Watchpoint hooks. */
1051 set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
1053 /* Dummy frame hooks. */
1054 set_gdbarch_return_value (gdbarch, score_return_value);
1055 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
1056 set_gdbarch_dummy_id (gdbarch, score_dummy_id);
1057 set_gdbarch_push_dummy_call (gdbarch, score_push_dummy_call);
1059 /* Normal frame hooks. */
1060 dwarf2_append_unwinders (gdbarch);
1061 frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
1062 frame_unwind_append_unwinder (gdbarch, &score_prologue_unwind);
1063 frame_base_append_sniffer (gdbarch, score_prologue_frame_base_sniffer);
1068 extern initialize_file_ftype _initialize_score_tdep;
1071 _initialize_score_tdep (void)
1073 gdbarch_register (bfd_arch_score, score_gdbarch_init, NULL);