1 /* Target-dependent code for the NEC V850 for GDB, the GNU debugger.
2 Copyright 1996, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
28 #include "gdb_string.h"
31 #include "arch-utils.h"
35 static char *v850_generic_reg_names[] = REGISTER_NAMES;
37 static char *v850e_reg_names[] =
39 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
40 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
41 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
42 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
43 "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "sr6", "sr7",
44 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15",
45 "ctpc", "ctpsw", "dbpc", "dbpsw", "ctbp", "sr21", "sr22", "sr23",
46 "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31",
50 char **v850_register_names = v850_generic_reg_names;
57 v850_processor_type_table[] =
60 v850_generic_reg_names, bfd_mach_v850
64 v850e_reg_names, bfd_mach_v850e
68 v850e_reg_names, bfd_mach_v850ea
76 /* Info gleaned from scanning a function's prologue. */
78 struct pifsr /* Info about one saved reg */
80 int framereg; /* Frame reg (SP or FP) */
81 int offset; /* Offset from framereg */
82 int cur_frameoffset; /* Current frameoffset */
83 int reg; /* Saved register number */
94 static CORE_ADDR v850_scan_prologue (CORE_ADDR pc, struct prologue_info *fs);
97 /* Should call_function allocate stack space for a struct return? */
99 v850_use_struct_convention (int gcc_p, struct type *type)
101 return (TYPE_NFIELDS (type) > 1 || TYPE_LENGTH (type) > 4);
106 /* Structure for mapping bits in register lists to register numbers. */
113 /* Helper function for v850_scan_prologue to handle prepare instruction. */
116 handle_prepare (int insn, int insn2, CORE_ADDR * current_pc_ptr,
117 struct prologue_info *pi, struct pifsr **pifsr_ptr)
119 CORE_ADDR current_pc = *current_pc_ptr;
120 struct pifsr *pifsr = *pifsr_ptr;
121 long next = insn2 & 0xffff;
122 long list12 = ((insn & 1) << 16) + (next & 0xffe0);
123 long offset = (insn & 0x3e) << 1;
124 static struct reg_list reg_table[] =
126 {0x00800, 20}, /* r20 */
127 {0x00400, 21}, /* r21 */
128 {0x00200, 22}, /* r22 */
129 {0x00100, 23}, /* r23 */
130 {0x08000, 24}, /* r24 */
131 {0x04000, 25}, /* r25 */
132 {0x02000, 26}, /* r26 */
133 {0x01000, 27}, /* r27 */
134 {0x00080, 28}, /* r28 */
135 {0x00040, 29}, /* r29 */
136 {0x10000, 30}, /* ep */
137 {0x00020, 31}, /* lp */
138 {0, 0} /* end of table */
142 if ((next & 0x1f) == 0x0b) /* skip imm16 argument */
144 else if ((next & 0x1f) == 0x13) /* skip imm16 argument */
146 else if ((next & 0x1f) == 0x1b) /* skip imm32 argument */
149 /* Calculate the total size of the saved registers, and add it
150 it to the immediate value used to adjust SP. */
151 for (i = 0; reg_table[i].mask != 0; i++)
152 if (list12 & reg_table[i].mask)
153 offset += REGISTER_RAW_SIZE (regtable[i].regno);
154 pi->frameoffset -= offset;
156 /* Calculate the offsets of the registers relative to the value
157 the SP will have after the registers have been pushed and the
158 imm5 value has been subtracted from it. */
161 for (i = 0; reg_table[i].mask != 0; i++)
163 if (list12 & reg_table[i].mask)
165 int reg = reg_table[i].regno;
166 offset -= REGISTER_RAW_SIZE (reg);
168 pifsr->offset = offset;
169 pifsr->cur_frameoffset = pi->frameoffset;
171 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
178 printf_filtered ("\tfound ctret after regsave func");
181 /* Set result parameters. */
182 *current_pc_ptr = current_pc;
187 /* Helper function for v850_scan_prologue to handle pushm/pushl instructions.
188 FIXME: the SR bit of the register list is not supported; must check
189 that the compiler does not ever generate this bit. */
192 handle_pushm (int insn, int insn2, struct prologue_info *pi,
193 struct pifsr **pifsr_ptr)
195 struct pifsr *pifsr = *pifsr_ptr;
196 long list12 = ((insn & 0x0f) << 16) + (insn2 & 0xfff0);
198 static struct reg_list pushml_reg_table[] =
200 {0x80000, PS_REGNUM}, /* PSW */
201 {0x40000, 1}, /* r1 */
202 {0x20000, 2}, /* r2 */
203 {0x10000, 3}, /* r3 */
204 {0x00800, 4}, /* r4 */
205 {0x00400, 5}, /* r5 */
206 {0x00200, 6}, /* r6 */
207 {0x00100, 7}, /* r7 */
208 {0x08000, 8}, /* r8 */
209 {0x04000, 9}, /* r9 */
210 {0x02000, 10}, /* r10 */
211 {0x01000, 11}, /* r11 */
212 {0x00080, 12}, /* r12 */
213 {0x00040, 13}, /* r13 */
214 {0x00020, 14}, /* r14 */
215 {0x00010, 15}, /* r15 */
216 {0, 0} /* end of table */
218 static struct reg_list pushmh_reg_table[] =
220 {0x80000, 16}, /* r16 */
221 {0x40000, 17}, /* r17 */
222 {0x20000, 18}, /* r18 */
223 {0x10000, 19}, /* r19 */
224 {0x00800, 20}, /* r20 */
225 {0x00400, 21}, /* r21 */
226 {0x00200, 22}, /* r22 */
227 {0x00100, 23}, /* r23 */
228 {0x08000, 24}, /* r24 */
229 {0x04000, 25}, /* r25 */
230 {0x02000, 26}, /* r26 */
231 {0x01000, 27}, /* r27 */
232 {0x00080, 28}, /* r28 */
233 {0x00040, 29}, /* r29 */
234 {0x00010, 30}, /* r30 */
235 {0x00020, 31}, /* r31 */
236 {0, 0} /* end of table */
238 struct reg_list *reg_table;
241 /* Is this a pushml or a pushmh? */
242 if ((insn2 & 7) == 1)
243 reg_table = pushml_reg_table;
245 reg_table = pushmh_reg_table;
247 /* Calculate the total size of the saved registers, and add it
248 it to the immediate value used to adjust SP. */
249 for (i = 0; reg_table[i].mask != 0; i++)
250 if (list12 & reg_table[i].mask)
251 offset += REGISTER_RAW_SIZE (regtable[i].regno);
252 pi->frameoffset -= offset;
254 /* Calculate the offsets of the registers relative to the value
255 the SP will have after the registers have been pushed and the
256 imm5 value is subtracted from it. */
259 for (i = 0; reg_table[i].mask != 0; i++)
261 if (list12 & reg_table[i].mask)
263 int reg = reg_table[i].regno;
264 offset -= REGISTER_RAW_SIZE (reg);
266 pifsr->offset = offset;
267 pifsr->cur_frameoffset = pi->frameoffset;
269 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
276 printf_filtered ("\tfound ctret after regsave func");
279 /* Set result parameters. */
286 /* Function: scan_prologue
287 Scan the prologue of the function that contains PC, and record what
288 we find in PI. Returns the pc after the prologue. Note that the
289 addresses saved in frame->saved_regs are just frame relative (negative
290 offsets from the frame pointer). This is because we don't know the
291 actual value of the frame pointer yet. In some circumstances, the
292 frame pointer can't be determined till after we have scanned the
296 v850_scan_prologue (CORE_ADDR pc, struct prologue_info *pi)
298 CORE_ADDR func_addr, prologue_end, current_pc;
299 struct pifsr *pifsr, *pifsr_tmp;
303 CORE_ADDR save_pc, save_end;
307 /* First, figure out the bounds of the prologue so that we can limit the
308 search to something reasonable. */
310 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
312 struct symtab_and_line sal;
314 sal = find_pc_line (func_addr, 0);
316 if (func_addr == entry_point_address ())
317 pi->start_function = 1;
319 pi->start_function = 0;
325 prologue_end = sal.end;
331 { /* We're in the boondocks */
332 func_addr = pc - 100;
336 prologue_end = min (prologue_end, pc);
338 /* Now, search the prologue looking for instructions that setup fp, save
339 rp, adjust sp and such. We also record the frame offset of any saved
343 pi->framereg = SP_REGNUM;
353 printf_filtered ("Current_pc = 0x%.8lx, prologue_end = 0x%.8lx\n",
354 (long) func_addr, (long) prologue_end);
357 for (current_pc = func_addr; current_pc < prologue_end;)
360 int insn2 = -1; /* dummy value */
363 printf_filtered ("0x%.8lx ", (long) current_pc);
364 TARGET_PRINT_INSN (current_pc, &tm_print_insn_info);
367 insn = read_memory_unsigned_integer (current_pc, 2);
369 if ((insn & 0x0780) >= 0x0600) /* Four byte instruction? */
371 insn2 = read_memory_unsigned_integer (current_pc, 2);
375 if ((insn & 0xffc0) == ((10 << 11) | 0x0780) && !regsave_func_p)
376 { /* jarl <func>,10 */
377 long low_disp = insn2 & ~(long) 1;
378 long disp = (((((insn & 0x3f) << 16) + low_disp)
379 & ~(long) 1) ^ 0x00200000) - 0x00200000;
381 save_pc = current_pc;
382 save_end = prologue_end;
384 current_pc += disp - 4;
385 prologue_end = (current_pc
386 + (2 * 3) /* moves to/from ep */
387 + 4 /* addi <const>,sp,sp */
389 + (2 * 12) /* sst.w to save r2, r20-r29, r31 */
390 + 20); /* slop area */
393 printf_filtered ("\tfound jarl <func>,r10, disp = %ld, low_disp = %ld, new pc = 0x%.8lx\n",
394 disp, low_disp, (long) current_pc + 2);
398 else if ((insn & 0xffc0) == 0x0200 && !regsave_func_p)
400 long ctbp = read_register (CTBP_REGNUM);
401 long adr = ctbp + ((insn & 0x3f) << 1);
403 save_pc = current_pc;
404 save_end = prologue_end;
406 current_pc = ctbp + (read_memory_unsigned_integer (adr, 2) & 0xffff);
407 prologue_end = (current_pc
408 + (2 * 3) /* prepare list2,imm5,sp/imm */
410 + 20); /* slop area */
413 printf_filtered ("\tfound callt, ctbp = 0x%.8lx, adr = %.8lx, new pc = 0x%.8lx\n",
414 ctbp, adr, (long) current_pc);
418 else if ((insn & 0xffc0) == 0x0780) /* prepare list2,imm5 */
420 handle_prepare (insn, insn2, ¤t_pc, pi, &pifsr);
423 else if (insn == 0x07e0 && regsave_func_p && insn2 == 0x0144)
424 { /* ctret after processing register save function */
425 current_pc = save_pc;
426 prologue_end = save_end;
429 printf_filtered ("\tfound ctret after regsave func");
433 else if ((insn & 0xfff0) == 0x07e0 && (insn2 & 5) == 1)
434 { /* pushml, pushmh */
435 handle_pushm (insn, insn2, pi, &pifsr);
438 else if ((insn & 0xffe0) == 0x0060 && regsave_func_p)
439 { /* jmp after processing register save function */
440 current_pc = save_pc;
441 prologue_end = save_end;
444 printf_filtered ("\tfound jmp after regsave func");
448 else if ((insn & 0x07c0) == 0x0780 /* jarl or jr */
449 || (insn & 0xffe0) == 0x0060 /* jmp */
450 || (insn & 0x0780) == 0x0580) /* branch */
453 printf_filtered ("\n");
455 break; /* Ran into end of prologue */
458 else if ((insn & 0xffe0) == ((SP_REGNUM << 11) | 0x0240)) /* add <imm>,sp */
459 pi->frameoffset += ((insn & 0x1f) ^ 0x10) - 0x10;
460 else if (insn == ((SP_REGNUM << 11) | 0x0600 | SP_REGNUM)) /* addi <imm>,sp,sp */
461 pi->frameoffset += insn2;
462 else if (insn == ((FP_RAW_REGNUM << 11) | 0x0000 | SP_REGNUM)) /* mov sp,fp */
465 pi->framereg = FP_RAW_REGNUM;
468 else if (insn == ((R12_REGNUM << 11) | 0x0640 | R0_REGNUM)) /* movhi hi(const),r0,r12 */
469 r12_tmp = insn2 << 16;
470 else if (insn == ((R12_REGNUM << 11) | 0x0620 | R12_REGNUM)) /* movea lo(const),r12,r12 */
472 else if (insn == ((SP_REGNUM << 11) | 0x01c0 | R12_REGNUM) && r12_tmp) /* add r12,sp */
473 pi->frameoffset = r12_tmp;
474 else if (insn == ((EP_REGNUM << 11) | 0x0000 | SP_REGNUM)) /* mov sp,ep */
476 else if (insn == ((EP_REGNUM << 11) | 0x0000 | R1_REGNUM)) /* mov r1,ep */
478 else if (((insn & 0x07ff) == (0x0760 | SP_REGNUM) /* st.w <reg>,<offset>[sp] */
480 && (insn & 0x07ff) == (0x0760 | FP_RAW_REGNUM))) /* st.w <reg>,<offset>[fp] */
482 && (((reg = (insn >> 11) & 0x1f) >= SAVE1_START_REGNUM && reg <= SAVE1_END_REGNUM)
483 || (reg >= SAVE2_START_REGNUM && reg <= SAVE2_END_REGNUM)
484 || (reg >= SAVE3_START_REGNUM && reg <= SAVE3_END_REGNUM)))
487 pifsr->offset = insn2 & ~1;
488 pifsr->cur_frameoffset = pi->frameoffset;
490 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
495 else if (ep_used /* sst.w <reg>,<offset>[ep] */
496 && ((insn & 0x0781) == 0x0501)
498 && (((reg = (insn >> 11) & 0x1f) >= SAVE1_START_REGNUM && reg <= SAVE1_END_REGNUM)
499 || (reg >= SAVE2_START_REGNUM && reg <= SAVE2_END_REGNUM)
500 || (reg >= SAVE3_START_REGNUM && reg <= SAVE3_END_REGNUM)))
503 pifsr->offset = (insn & 0x007e) << 1;
504 pifsr->cur_frameoffset = pi->frameoffset;
506 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
512 printf_filtered ("\n");
517 pifsr->framereg = 0; /* Tie off last entry */
519 /* Fix up any offsets to the final offset. If a frame pointer was created, use it
520 instead of the stack pointer. */
521 for (pifsr_tmp = pi->pifsrs; pifsr_tmp && pifsr_tmp != pifsr; pifsr_tmp++)
523 pifsr_tmp->offset -= pi->frameoffset - pifsr_tmp->cur_frameoffset;
524 pifsr_tmp->framereg = pi->framereg;
527 printf_filtered ("Saved register r%d, offset = %d, framereg = r%d\n",
528 pifsr_tmp->reg, pifsr_tmp->offset, pifsr_tmp->framereg);
533 printf_filtered ("Framereg = r%d, frameoffset = %d\n", pi->framereg, pi->frameoffset);
540 v850_frame_init_saved_regs (struct frame_info *fi)
542 struct prologue_info pi;
543 struct pifsr pifsrs[NUM_REGS + 1], *pifsr;
544 CORE_ADDR func_addr, func_end;
548 frame_saved_regs_zalloc (fi);
550 /* The call dummy doesn't save any registers on the stack, so we
552 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
555 /* Find the beginning of this function, so we can analyze its
557 if (find_pc_partial_function (fi->pc, NULL, &func_addr, &func_end))
561 v850_scan_prologue (fi->pc, &pi);
563 if (!fi->next && pi.framereg == SP_REGNUM)
564 fi->frame = read_register (pi.framereg) - pi.frameoffset;
566 for (pifsr = pifsrs; pifsr->framereg; pifsr++)
568 fi->saved_regs[pifsr->reg] = pifsr->offset + fi->frame;
570 if (pifsr->framereg == SP_REGNUM)
571 fi->saved_regs[pifsr->reg] += pi.frameoffset;
574 /* Else we're out of luck (can't debug completely stripped code).
579 /* Function: init_extra_frame_info
580 Setup the frame's frame pointer, pc, and frame addresses for saved
581 registers. Most of the work is done in scan_prologue().
583 Note that when we are called for the last frame (currently active frame),
584 that fi->pc and fi->frame will already be setup. However, fi->frame will
585 be valid only if this routine uses FP. For previous frames, fi-frame will
586 always be correct (since that is derived from v850_frame_chain ()).
588 We can be called with the PC in the call dummy under two circumstances.
589 First, during normal backtracing, second, while figuring out the frame
590 pointer just prior to calling the target function (see run_stack_dummy). */
593 v850_init_extra_frame_info (struct frame_info *fi)
595 struct prologue_info pi;
598 fi->pc = FRAME_SAVED_PC (fi->next);
600 v850_frame_init_saved_regs (fi);
603 /* Function: frame_chain
604 Figure out the frame prior to FI. Unfortunately, this involves
605 scanning the prologue of the caller, which will also be done
606 shortly by v850_init_extra_frame_info. For the dummy frame, we
607 just return the stack pointer that was in use at the time the
608 function call was made. */
611 v850_frame_chain (struct frame_info *fi)
613 struct prologue_info pi;
614 CORE_ADDR callers_pc, fp;
616 /* First, find out who called us */
617 callers_pc = FRAME_SAVED_PC (fi);
618 /* If caller is a call-dummy, then our FP bears no relation to his FP! */
619 fp = v850_find_callers_reg (fi, FP_RAW_REGNUM);
620 if (PC_IN_CALL_DUMMY (callers_pc, fp, fp))
621 return fp; /* caller is call-dummy: return oldest value of FP */
623 /* Caller is NOT a call-dummy, so everything else should just work.
624 Even if THIS frame is a call-dummy! */
627 v850_scan_prologue (callers_pc, &pi);
629 if (pi.start_function)
630 return 0; /* Don't chain beyond the start function */
632 if (pi.framereg == FP_RAW_REGNUM)
633 return v850_find_callers_reg (fi, pi.framereg);
635 return fi->frame - pi.frameoffset;
638 /* Function: find_callers_reg
639 Find REGNUM on the stack. Otherwise, it's in an active register.
640 One thing we might want to do here is to check REGNUM against the
641 clobber mask, and somehow flag it as invalid if it isn't saved on
642 the stack somewhere. This would provide a graceful failure mode
643 when trying to get the value of caller-saves registers for an inner
647 v850_find_callers_reg (struct frame_info *fi, int regnum)
649 for (; fi; fi = fi->next)
650 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
651 return generic_read_register_dummy (fi->pc, fi->frame, regnum);
652 else if (fi->saved_regs[regnum] != 0)
653 return read_memory_unsigned_integer (fi->saved_regs[regnum],
654 REGISTER_RAW_SIZE (regnum));
656 return read_register (regnum);
659 /* Function: skip_prologue
660 Return the address of the first code past the prologue of the function. */
663 v850_skip_prologue (CORE_ADDR pc)
665 CORE_ADDR func_addr, func_end;
667 /* See what the symbol table says */
669 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
671 struct symtab_and_line sal;
673 sal = find_pc_line (func_addr, 0);
675 if (sal.line != 0 && sal.end < func_end)
678 /* Either there's no line info, or the line after the prologue is after
679 the end of the function. In this case, there probably isn't a
684 /* We can't find the start of this function, so there's nothing we can do. */
688 /* Function: pop_frame
689 This routine gets called when either the user uses the `return'
690 command, or the call dummy breakpoint gets hit. */
693 v850_pop_frame (struct frame_info *frame)
697 if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
698 generic_pop_dummy_frame ();
701 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
703 for (regnum = 0; regnum < NUM_REGS; regnum++)
704 if (frame->saved_regs[regnum] != 0)
705 write_register (regnum,
706 read_memory_unsigned_integer (frame->saved_regs[regnum],
707 REGISTER_RAW_SIZE (regnum)));
709 write_register (SP_REGNUM, FRAME_FP (frame));
712 flush_cached_frames ();
715 /* Function: push_arguments
716 Setup arguments and RP for a call to the target. First four args
717 go in R6->R9, subsequent args go into sp + 16 -> sp + ... Structs
718 are passed by reference. 64 bit quantities (doubles and long
719 longs) may be split between the regs and the stack. When calling a
720 function that returns a struct, a pointer to the struct is passed
721 in as a secret first argument (always in R6).
723 Stack space for the args has NOT been allocated: that job is up to us.
727 v850_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
728 unsigned char struct_return, CORE_ADDR struct_addr)
735 /* First, just for safety, make sure stack is aligned */
738 /* Now make space on the stack for the args. */
739 for (argnum = 0; argnum < nargs; argnum++)
740 len += ((TYPE_LENGTH (VALUE_TYPE (args[argnum])) + 3) & ~3);
741 sp -= len; /* possibly over-allocating, but it works... */
742 /* (you might think we could allocate 16 bytes */
743 /* less, but the ABI seems to use it all! ) */
744 argreg = ARG0_REGNUM;
746 /* the struct_return pointer occupies the first parameter-passing reg */
748 write_register (argreg++, struct_addr);
751 /* The offset onto the stack at which we will start copying parameters
752 (after the registers are used up) begins at 16 rather than at zero.
753 I don't really know why, that's just the way it seems to work. */
755 /* Now load as many as possible of the first arguments into
756 registers, and push the rest onto the stack. There are 16 bytes
757 in four registers available. Loop thru args from first to last. */
758 for (argnum = 0; argnum < nargs; argnum++)
762 char valbuf[REGISTER_RAW_SIZE (ARG0_REGNUM)];
764 if (TYPE_CODE (VALUE_TYPE (*args)) == TYPE_CODE_STRUCT
765 && TYPE_LENGTH (VALUE_TYPE (*args)) > 8)
767 store_address (valbuf, 4, VALUE_ADDRESS (*args));
773 len = TYPE_LENGTH (VALUE_TYPE (*args));
774 val = (char *) VALUE_CONTENTS (*args);
778 if (argreg <= ARGLAST_REGNUM)
782 regval = extract_address (val, REGISTER_RAW_SIZE (argreg));
783 write_register (argreg, regval);
785 len -= REGISTER_RAW_SIZE (argreg);
786 val += REGISTER_RAW_SIZE (argreg);
791 write_memory (sp + stack_offset, val, 4);
802 /* Function: push_return_address (pc)
803 Set up the return address for the inferior function call.
804 Needed for targets where we don't actually execute a JSR/BSR instruction */
807 v850_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
809 write_register (RP_REGNUM, CALL_DUMMY_ADDRESS ());
813 /* Function: frame_saved_pc
814 Find the caller of this frame. We do this by seeing if RP_REGNUM
815 is saved in the stack anywhere, otherwise we get it from the
816 registers. If the inner frame is a dummy frame, return its PC
817 instead of RP, because that's where "caller" of the dummy-frame
821 v850_frame_saved_pc (struct frame_info *fi)
823 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
824 return generic_read_register_dummy (fi->pc, fi->frame, PC_REGNUM);
826 return v850_find_callers_reg (fi, RP_REGNUM);
830 /* Function: fix_call_dummy
831 Pokes the callee function's address into the CALL_DUMMY assembly stub.
832 Assumes that the CALL_DUMMY looks like this:
838 v850_fix_call_dummy (char *dummy, CORE_ADDR sp, CORE_ADDR fun, int nargs,
839 struct value **args, struct type *type, int gcc_p)
843 offset24 = (long) fun - (long) entry_point_address ();
844 offset24 &= 0x3fffff;
845 offset24 |= 0xff800000; /* jarl <offset24>, r31 */
847 store_unsigned_integer ((unsigned int *) &dummy[2], 2, offset24 & 0xffff);
848 store_unsigned_integer ((unsigned int *) &dummy[0], 2, offset24 >> 16);
852 static struct gdbarch *
853 v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
855 struct gdbarch_tdep *tdep = NULL;
856 struct gdbarch *gdbarch;
859 /* find a candidate among the list of pre-declared architectures. */
860 arches = gdbarch_list_lookup_by_info (arches, &info);
862 return (arches->gdbarch);
865 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
868 if (info.bfd_arch_info->arch != bfd_arch_v850)
871 gdbarch = gdbarch_alloc (&info, 0);
873 /* Change the register names based on the current machine type. */
874 for (i = 0; v850_processor_type_table[i].regnames != NULL; i++)
876 if (v850_processor_type_table[i].mach == info.bfd_arch_info->mach)
878 v850_register_names = v850_processor_type_table[i].regnames;
879 tm_print_insn_info.mach = info.bfd_arch_info->mach;
888 _initialize_v850_tdep (void)
890 tm_print_insn = print_insn_v850;
891 register_gdbarch_init (bfd_arch_v850, v850_gdbarch_init);