1 /* Target-dependent code for the NEC V850 for GDB, the GNU debugger.
2 Copyright 1996, 1998, 1999, 2000, 2001, 2002 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"
37 /* gdbarch target dependent data here. Currently unused for v850. */
40 /* Extra info which is saved in each frame_info. */
41 struct frame_extra_info
48 E_R2_REGNUM, E_SAVE1_START_REGNUM = E_R2_REGNUM, E_SAVE1_END_REGNUM = E_R2_REGNUM,
49 E_R3_REGNUM, E_SP_REGNUM = E_R3_REGNUM,
52 E_R6_REGNUM, E_ARG0_REGNUM = E_R6_REGNUM,
55 E_R9_REGNUM, E_ARGLAST_REGNUM = E_R9_REGNUM,
56 E_R10_REGNUM, E_V0_REGNUM = E_R10_REGNUM,
57 E_R11_REGNUM, E_V1_REGNUM = E_R11_REGNUM,
66 E_R20_REGNUM, E_SAVE2_START_REGNUM = E_R20_REGNUM,
75 E_R29_REGNUM, E_SAVE2_END_REGNUM = E_R29_REGNUM, E_FP_RAW_REGNUM = E_R29_REGNUM,
76 E_R30_REGNUM, E_EP_REGNUM = E_R30_REGNUM,
77 E_R31_REGNUM, E_SAVE3_START_REGNUM = E_R31_REGNUM, E_SAVE3_END_REGNUM = E_R31_REGNUM, E_RP_REGNUM = E_R31_REGNUM,
78 E_R32_REGNUM, E_SR0_REGNUM = E_R32_REGNUM,
83 E_R37_REGNUM, E_PS_REGNUM = E_R37_REGNUM,
98 E_R52_REGNUM, E_CTBP_REGNUM = E_R52_REGNUM,
110 E_R64_REGNUM, E_PC_REGNUM = E_R64_REGNUM,
111 E_R65_REGNUM, E_FP_REGNUM = E_R65_REGNUM,
120 /* Size of all registers as a whole. */
123 E_ALL_REGS_SIZE = (E_NUM_REGS) * v850_reg_size
126 static LONGEST call_dummy_nil[] = {0};
128 static char *v850_generic_reg_names[] =
129 { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
130 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
131 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
132 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
133 "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "sr6", "sr7",
134 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15",
135 "sr16", "sr17", "sr18", "sr19", "sr20", "sr21", "sr22", "sr23",
136 "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31",
140 static char *v850e_reg_names[] =
142 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
143 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
144 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
145 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
146 "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "sr6", "sr7",
147 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15",
148 "ctpc", "ctpsw", "dbpc", "dbpsw", "ctbp", "sr21", "sr22", "sr23",
149 "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31",
153 char **v850_register_names = v850_generic_reg_names;
160 v850_processor_type_table[] =
163 v850_generic_reg_names, bfd_mach_v850
167 v850e_reg_names, bfd_mach_v850e
171 v850e_reg_names, bfd_mach_v850ea
179 /* Info gleaned from scanning a function's prologue. */
181 struct pifsr /* Info about one saved reg */
183 int framereg; /* Frame reg (SP or FP) */
184 int offset; /* Offset from framereg */
185 int cur_frameoffset; /* Current frameoffset */
186 int reg; /* Saved register number */
194 struct pifsr *pifsrs;
197 static CORE_ADDR v850_scan_prologue (CORE_ADDR pc, struct prologue_info *fs);
199 /* Function: v850_register_name
200 Returns the name of the v850/v850e register N. */
203 v850_register_name (int regnum)
205 if (regnum < 0 || regnum >= E_NUM_REGS)
206 internal_error (__FILE__, __LINE__,
207 "v850_register_name: illegal register number %d",
210 return v850_register_names[regnum];
214 /* Function: v850_register_byte
215 Returns the byte position in the register cache for register N. */
218 v850_register_byte (int regnum)
220 if (regnum < 0 || regnum >= E_NUM_REGS)
221 internal_error (__FILE__, __LINE__,
222 "v850_register_byte: illegal register number %d",
225 return regnum * v850_reg_size;
228 /* Function: v850_register_raw_size
229 Returns the number of bytes occupied by the register on the target. */
232 v850_register_raw_size (int regnum)
234 if (regnum < 0 || regnum >= E_NUM_REGS)
235 internal_error (__FILE__, __LINE__,
236 "v850_register_raw_size: illegal register number %d",
238 /* Only the PC has 4 Byte, all other registers 2 Byte. */
240 return v850_reg_size;
243 /* Function: v850_register_virtual_size
244 Returns the number of bytes occupied by the register as represented
245 internally by gdb. */
248 v850_register_virtual_size (int regnum)
250 return v850_register_raw_size (regnum);
253 /* Function: v850_reg_virtual_type
254 Returns the default type for register N. */
257 v850_reg_virtual_type (int regnum)
259 if (regnum < 0 || regnum >= E_NUM_REGS)
260 internal_error (__FILE__, __LINE__,
261 "v850_register_virtual_type: illegal register number %d",
263 else if (regnum == E_PC_REGNUM)
264 return builtin_type_uint32;
266 return builtin_type_int32;
269 /* Should call_function allocate stack space for a struct return? */
271 v850_use_struct_convention (int gcc_p, struct type *type)
273 return (TYPE_NFIELDS (type) > 1 || TYPE_LENGTH (type) > 4);
278 /* Structure for mapping bits in register lists to register numbers. */
285 /* Helper function for v850_scan_prologue to handle prepare instruction. */
288 handle_prepare (int insn, int insn2, CORE_ADDR * current_pc_ptr,
289 struct prologue_info *pi, struct pifsr **pifsr_ptr)
291 CORE_ADDR current_pc = *current_pc_ptr;
292 struct pifsr *pifsr = *pifsr_ptr;
293 long next = insn2 & 0xffff;
294 long list12 = ((insn & 1) << 16) + (next & 0xffe0);
295 long offset = (insn & 0x3e) << 1;
296 static struct reg_list reg_table[] =
298 {0x00800, 20}, /* r20 */
299 {0x00400, 21}, /* r21 */
300 {0x00200, 22}, /* r22 */
301 {0x00100, 23}, /* r23 */
302 {0x08000, 24}, /* r24 */
303 {0x04000, 25}, /* r25 */
304 {0x02000, 26}, /* r26 */
305 {0x01000, 27}, /* r27 */
306 {0x00080, 28}, /* r28 */
307 {0x00040, 29}, /* r29 */
308 {0x10000, 30}, /* ep */
309 {0x00020, 31}, /* lp */
310 {0, 0} /* end of table */
314 if ((next & 0x1f) == 0x0b) /* skip imm16 argument */
316 else if ((next & 0x1f) == 0x13) /* skip imm16 argument */
318 else if ((next & 0x1f) == 0x1b) /* skip imm32 argument */
321 /* Calculate the total size of the saved registers, and add it
322 it to the immediate value used to adjust SP. */
323 for (i = 0; reg_table[i].mask != 0; i++)
324 if (list12 & reg_table[i].mask)
325 offset += v850_register_raw_size (reg_table[i].regno);
326 pi->frameoffset -= offset;
328 /* Calculate the offsets of the registers relative to the value
329 the SP will have after the registers have been pushed and the
330 imm5 value has been subtracted from it. */
333 for (i = 0; reg_table[i].mask != 0; i++)
335 if (list12 & reg_table[i].mask)
337 int reg = reg_table[i].regno;
338 offset -= v850_register_raw_size (reg);
340 pifsr->offset = offset;
341 pifsr->cur_frameoffset = pi->frameoffset;
343 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
350 printf_filtered ("\tfound ctret after regsave func");
353 /* Set result parameters. */
354 *current_pc_ptr = current_pc;
359 /* Helper function for v850_scan_prologue to handle pushm/pushl instructions.
360 FIXME: the SR bit of the register list is not supported; must check
361 that the compiler does not ever generate this bit. */
364 handle_pushm (int insn, int insn2, struct prologue_info *pi,
365 struct pifsr **pifsr_ptr)
367 struct pifsr *pifsr = *pifsr_ptr;
368 long list12 = ((insn & 0x0f) << 16) + (insn2 & 0xfff0);
370 static struct reg_list pushml_reg_table[] =
372 {0x80000, E_PS_REGNUM}, /* PSW */
373 {0x40000, 1}, /* r1 */
374 {0x20000, 2}, /* r2 */
375 {0x10000, 3}, /* r3 */
376 {0x00800, 4}, /* r4 */
377 {0x00400, 5}, /* r5 */
378 {0x00200, 6}, /* r6 */
379 {0x00100, 7}, /* r7 */
380 {0x08000, 8}, /* r8 */
381 {0x04000, 9}, /* r9 */
382 {0x02000, 10}, /* r10 */
383 {0x01000, 11}, /* r11 */
384 {0x00080, 12}, /* r12 */
385 {0x00040, 13}, /* r13 */
386 {0x00020, 14}, /* r14 */
387 {0x00010, 15}, /* r15 */
388 {0, 0} /* end of table */
390 static struct reg_list pushmh_reg_table[] =
392 {0x80000, 16}, /* r16 */
393 {0x40000, 17}, /* r17 */
394 {0x20000, 18}, /* r18 */
395 {0x10000, 19}, /* r19 */
396 {0x00800, 20}, /* r20 */
397 {0x00400, 21}, /* r21 */
398 {0x00200, 22}, /* r22 */
399 {0x00100, 23}, /* r23 */
400 {0x08000, 24}, /* r24 */
401 {0x04000, 25}, /* r25 */
402 {0x02000, 26}, /* r26 */
403 {0x01000, 27}, /* r27 */
404 {0x00080, 28}, /* r28 */
405 {0x00040, 29}, /* r29 */
406 {0x00010, 30}, /* r30 */
407 {0x00020, 31}, /* r31 */
408 {0, 0} /* end of table */
410 struct reg_list *reg_table;
413 /* Is this a pushml or a pushmh? */
414 if ((insn2 & 7) == 1)
415 reg_table = pushml_reg_table;
417 reg_table = pushmh_reg_table;
419 /* Calculate the total size of the saved registers, and add it
420 it to the immediate value used to adjust SP. */
421 for (i = 0; reg_table[i].mask != 0; i++)
422 if (list12 & reg_table[i].mask)
423 offset += v850_register_raw_size (reg_table[i].regno);
424 pi->frameoffset -= offset;
426 /* Calculate the offsets of the registers relative to the value
427 the SP will have after the registers have been pushed and the
428 imm5 value is subtracted from it. */
431 for (i = 0; reg_table[i].mask != 0; i++)
433 if (list12 & reg_table[i].mask)
435 int reg = reg_table[i].regno;
436 offset -= v850_register_raw_size (reg);
438 pifsr->offset = offset;
439 pifsr->cur_frameoffset = pi->frameoffset;
441 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
448 printf_filtered ("\tfound ctret after regsave func");
451 /* Set result parameters. */
458 /* Function: scan_prologue
459 Scan the prologue of the function that contains PC, and record what
460 we find in PI. Returns the pc after the prologue. Note that the
461 addresses saved in frame->saved_regs are just frame relative (negative
462 offsets from the frame pointer). This is because we don't know the
463 actual value of the frame pointer yet. In some circumstances, the
464 frame pointer can't be determined till after we have scanned the
468 v850_scan_prologue (CORE_ADDR pc, struct prologue_info *pi)
470 CORE_ADDR func_addr, prologue_end, current_pc;
471 struct pifsr *pifsr, *pifsr_tmp;
475 CORE_ADDR save_pc, save_end;
479 /* First, figure out the bounds of the prologue so that we can limit the
480 search to something reasonable. */
482 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
484 struct symtab_and_line sal;
486 sal = find_pc_line (func_addr, 0);
488 if (func_addr == entry_point_address ())
489 pi->start_function = 1;
491 pi->start_function = 0;
497 prologue_end = sal.end;
503 { /* We're in the boondocks */
504 func_addr = pc - 100;
508 prologue_end = min (prologue_end, pc);
510 /* Now, search the prologue looking for instructions that setup fp, save
511 rp, adjust sp and such. We also record the frame offset of any saved
515 pi->framereg = E_SP_REGNUM;
525 printf_filtered ("Current_pc = 0x%.8lx, prologue_end = 0x%.8lx\n",
526 (long) func_addr, (long) prologue_end);
529 for (current_pc = func_addr; current_pc < prologue_end;)
532 int insn2 = -1; /* dummy value */
535 printf_filtered ("0x%.8lx ", (long) current_pc);
536 TARGET_PRINT_INSN (current_pc, &tm_print_insn_info);
539 insn = read_memory_unsigned_integer (current_pc, 2);
541 if ((insn & 0x0780) >= 0x0600) /* Four byte instruction? */
543 insn2 = read_memory_unsigned_integer (current_pc, 2);
547 if ((insn & 0xffc0) == ((10 << 11) | 0x0780) && !regsave_func_p)
548 { /* jarl <func>,10 */
549 long low_disp = insn2 & ~(long) 1;
550 long disp = (((((insn & 0x3f) << 16) + low_disp)
551 & ~(long) 1) ^ 0x00200000) - 0x00200000;
553 save_pc = current_pc;
554 save_end = prologue_end;
556 current_pc += disp - 4;
557 prologue_end = (current_pc
558 + (2 * 3) /* moves to/from ep */
559 + 4 /* addi <const>,sp,sp */
561 + (2 * 12) /* sst.w to save r2, r20-r29, r31 */
562 + 20); /* slop area */
565 printf_filtered ("\tfound jarl <func>,r10, disp = %ld, low_disp = %ld, new pc = 0x%.8lx\n",
566 disp, low_disp, (long) current_pc + 2);
570 else if ((insn & 0xffc0) == 0x0200 && !regsave_func_p)
572 long ctbp = read_register (E_CTBP_REGNUM);
573 long adr = ctbp + ((insn & 0x3f) << 1);
575 save_pc = current_pc;
576 save_end = prologue_end;
578 current_pc = ctbp + (read_memory_unsigned_integer (adr, 2) & 0xffff);
579 prologue_end = (current_pc
580 + (2 * 3) /* prepare list2,imm5,sp/imm */
582 + 20); /* slop area */
585 printf_filtered ("\tfound callt, ctbp = 0x%.8lx, adr = %.8lx, new pc = 0x%.8lx\n",
586 ctbp, adr, (long) current_pc);
590 else if ((insn & 0xffc0) == 0x0780) /* prepare list2,imm5 */
592 handle_prepare (insn, insn2, ¤t_pc, pi, &pifsr);
595 else if (insn == 0x07e0 && regsave_func_p && insn2 == 0x0144)
596 { /* ctret after processing register save function */
597 current_pc = save_pc;
598 prologue_end = save_end;
601 printf_filtered ("\tfound ctret after regsave func");
605 else if ((insn & 0xfff0) == 0x07e0 && (insn2 & 5) == 1)
606 { /* pushml, pushmh */
607 handle_pushm (insn, insn2, pi, &pifsr);
610 else if ((insn & 0xffe0) == 0x0060 && regsave_func_p)
611 { /* jmp after processing register save function */
612 current_pc = save_pc;
613 prologue_end = save_end;
616 printf_filtered ("\tfound jmp after regsave func");
620 else if ((insn & 0x07c0) == 0x0780 /* jarl or jr */
621 || (insn & 0xffe0) == 0x0060 /* jmp */
622 || (insn & 0x0780) == 0x0580) /* branch */
625 printf_filtered ("\n");
627 break; /* Ran into end of prologue */
630 else if ((insn & 0xffe0) == ((E_SP_REGNUM << 11) | 0x0240)) /* add <imm>,sp */
631 pi->frameoffset += ((insn & 0x1f) ^ 0x10) - 0x10;
632 else if (insn == ((E_SP_REGNUM << 11) | 0x0600 | E_SP_REGNUM)) /* addi <imm>,sp,sp */
633 pi->frameoffset += insn2;
634 else if (insn == ((E_FP_RAW_REGNUM << 11) | 0x0000 | E_SP_REGNUM)) /* mov sp,fp */
637 pi->framereg = E_FP_RAW_REGNUM;
640 else if (insn == ((E_R12_REGNUM << 11) | 0x0640 | E_R0_REGNUM)) /* movhi hi(const),r0,r12 */
641 r12_tmp = insn2 << 16;
642 else if (insn == ((E_R12_REGNUM << 11) | 0x0620 | E_R12_REGNUM)) /* movea lo(const),r12,r12 */
644 else if (insn == ((E_SP_REGNUM << 11) | 0x01c0 | E_R12_REGNUM) && r12_tmp) /* add r12,sp */
645 pi->frameoffset = r12_tmp;
646 else if (insn == ((E_EP_REGNUM << 11) | 0x0000 | E_SP_REGNUM)) /* mov sp,ep */
648 else if (insn == ((E_EP_REGNUM << 11) | 0x0000 | E_R1_REGNUM)) /* mov r1,ep */
650 else if (((insn & 0x07ff) == (0x0760 | E_SP_REGNUM) /* st.w <reg>,<offset>[sp] */
652 && (insn & 0x07ff) == (0x0760 | E_FP_RAW_REGNUM))) /* st.w <reg>,<offset>[fp] */
654 && (((reg = (insn >> 11) & 0x1f) >= E_SAVE1_START_REGNUM && reg <= E_SAVE1_END_REGNUM)
655 || (reg >= E_SAVE2_START_REGNUM && reg <= E_SAVE2_END_REGNUM)
656 || (reg >= E_SAVE3_START_REGNUM && reg <= E_SAVE3_END_REGNUM)))
659 pifsr->offset = insn2 & ~1;
660 pifsr->cur_frameoffset = pi->frameoffset;
662 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
667 else if (ep_used /* sst.w <reg>,<offset>[ep] */
668 && ((insn & 0x0781) == 0x0501)
670 && (((reg = (insn >> 11) & 0x1f) >= E_SAVE1_START_REGNUM && reg <= E_SAVE1_END_REGNUM)
671 || (reg >= E_SAVE2_START_REGNUM && reg <= E_SAVE2_END_REGNUM)
672 || (reg >= E_SAVE3_START_REGNUM && reg <= E_SAVE3_END_REGNUM)))
675 pifsr->offset = (insn & 0x007e) << 1;
676 pifsr->cur_frameoffset = pi->frameoffset;
678 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
684 printf_filtered ("\n");
689 pifsr->framereg = 0; /* Tie off last entry */
691 /* Fix up any offsets to the final offset. If a frame pointer was created, use it
692 instead of the stack pointer. */
693 for (pifsr_tmp = pi->pifsrs; pifsr_tmp && pifsr_tmp != pifsr; pifsr_tmp++)
695 pifsr_tmp->offset -= pi->frameoffset - pifsr_tmp->cur_frameoffset;
696 pifsr_tmp->framereg = pi->framereg;
699 printf_filtered ("Saved register r%d, offset = %d, framereg = r%d\n",
700 pifsr_tmp->reg, pifsr_tmp->offset, pifsr_tmp->framereg);
705 printf_filtered ("Framereg = r%d, frameoffset = %d\n", pi->framereg, pi->frameoffset);
711 /* Function: find_callers_reg
712 Find REGNUM on the stack. Otherwise, it's in an active register.
713 One thing we might want to do here is to check REGNUM against the
714 clobber mask, and somehow flag it as invalid if it isn't saved on
715 the stack somewhere. This would provide a graceful failure mode
716 when trying to get the value of caller-saves registers for an inner
720 v850_find_callers_reg (struct frame_info *fi, int regnum)
722 for (; fi; fi = fi->next)
723 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
724 return generic_read_register_dummy (fi->pc, fi->frame, regnum);
725 else if (fi->saved_regs[regnum] != 0)
726 return read_memory_unsigned_integer (fi->saved_regs[regnum],
727 v850_register_raw_size (regnum));
729 return read_register (regnum);
732 /* Function: frame_chain
733 Figure out the frame prior to FI. Unfortunately, this involves
734 scanning the prologue of the caller, which will also be done
735 shortly by v850_init_extra_frame_info. For the dummy frame, we
736 just return the stack pointer that was in use at the time the
737 function call was made. */
740 v850_frame_chain (struct frame_info *fi)
742 struct prologue_info pi;
743 CORE_ADDR callers_pc, fp;
745 /* First, find out who called us */
746 callers_pc = FRAME_SAVED_PC (fi);
747 /* If caller is a call-dummy, then our FP bears no relation to his FP! */
748 fp = v850_find_callers_reg (fi, E_FP_RAW_REGNUM);
749 if (PC_IN_CALL_DUMMY (callers_pc, fp, fp))
750 return fp; /* caller is call-dummy: return oldest value of FP */
752 /* Caller is NOT a call-dummy, so everything else should just work.
753 Even if THIS frame is a call-dummy! */
756 v850_scan_prologue (callers_pc, &pi);
758 if (pi.start_function)
759 return 0; /* Don't chain beyond the start function */
761 if (pi.framereg == E_FP_RAW_REGNUM)
762 return v850_find_callers_reg (fi, pi.framereg);
764 return fi->frame - pi.frameoffset;
767 /* Function: skip_prologue
768 Return the address of the first code past the prologue of the function. */
771 v850_skip_prologue (CORE_ADDR pc)
773 CORE_ADDR func_addr, func_end;
775 /* See what the symbol table says */
777 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
779 struct symtab_and_line sal;
781 sal = find_pc_line (func_addr, 0);
783 if (sal.line != 0 && sal.end < func_end)
786 /* Either there's no line info, or the line after the prologue is after
787 the end of the function. In this case, there probably isn't a
792 /* We can't find the start of this function, so there's nothing we can do. */
796 /* Function: pop_frame
797 This routine gets called when either the user uses the `return'
798 command, or the call dummy breakpoint gets hit. */
801 v850_pop_frame (void)
803 struct frame_info *frame = get_current_frame ();
806 if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
807 generic_pop_dummy_frame ();
810 write_register (E_PC_REGNUM, FRAME_SAVED_PC (frame));
812 for (regnum = 0; regnum < E_NUM_REGS; regnum++)
813 if (frame->saved_regs[regnum] != 0)
814 write_register (regnum,
815 read_memory_unsigned_integer (frame->saved_regs[regnum],
816 v850_register_raw_size (regnum)));
818 write_register (E_SP_REGNUM, FRAME_FP (frame));
821 flush_cached_frames ();
824 /* Function: push_arguments
825 Setup arguments and RP for a call to the target. First four args
826 go in R6->R9, subsequent args go into sp + 16 -> sp + ... Structs
827 are passed by reference. 64 bit quantities (doubles and long
828 longs) may be split between the regs and the stack. When calling a
829 function that returns a struct, a pointer to the struct is passed
830 in as a secret first argument (always in R6).
832 Stack space for the args has NOT been allocated: that job is up to us.
836 v850_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
837 int struct_return, CORE_ADDR struct_addr)
844 /* First, just for safety, make sure stack is aligned */
847 /* Now make space on the stack for the args. */
848 for (argnum = 0; argnum < nargs; argnum++)
849 len += ((TYPE_LENGTH (VALUE_TYPE (args[argnum])) + 3) & ~3);
850 sp -= len; /* possibly over-allocating, but it works... */
851 /* (you might think we could allocate 16 bytes */
852 /* less, but the ABI seems to use it all! ) */
853 argreg = E_ARG0_REGNUM;
855 /* the struct_return pointer occupies the first parameter-passing reg */
857 write_register (argreg++, struct_addr);
860 /* The offset onto the stack at which we will start copying parameters
861 (after the registers are used up) begins at 16 rather than at zero.
862 I don't really know why, that's just the way it seems to work. */
864 /* Now load as many as possible of the first arguments into
865 registers, and push the rest onto the stack. There are 16 bytes
866 in four registers available. Loop thru args from first to last. */
867 for (argnum = 0; argnum < nargs; argnum++)
871 char valbuf[v850_register_raw_size (E_ARG0_REGNUM)];
873 if (TYPE_CODE (VALUE_TYPE (*args)) == TYPE_CODE_STRUCT
874 && TYPE_LENGTH (VALUE_TYPE (*args)) > 8)
876 store_address (valbuf, 4, VALUE_ADDRESS (*args));
882 len = TYPE_LENGTH (VALUE_TYPE (*args));
883 val = (char *) VALUE_CONTENTS (*args);
887 if (argreg <= E_ARGLAST_REGNUM)
891 regval = extract_address (val, v850_register_raw_size (argreg));
892 write_register (argreg, regval);
894 len -= v850_register_raw_size (argreg);
895 val += v850_register_raw_size (argreg);
900 write_memory (sp + stack_offset, val, 4);
911 /* Function: push_return_address (pc)
912 Set up the return address for the inferior function call.
913 Needed for targets where we don't actually execute a JSR/BSR instruction */
916 v850_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
918 write_register (E_RP_REGNUM, CALL_DUMMY_ADDRESS ());
922 /* Function: frame_saved_pc
923 Find the caller of this frame. We do this by seeing if E_RP_REGNUM
924 is saved in the stack anywhere, otherwise we get it from the
925 registers. If the inner frame is a dummy frame, return its PC
926 instead of RP, because that's where "caller" of the dummy-frame
930 v850_frame_saved_pc (struct frame_info *fi)
932 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
933 return generic_read_register_dummy (fi->pc, fi->frame, E_PC_REGNUM);
935 return v850_find_callers_reg (fi, E_RP_REGNUM);
939 /* Function: fix_call_dummy
940 Pokes the callee function's address into the CALL_DUMMY assembly stub.
941 Assumes that the CALL_DUMMY looks like this:
947 v850_fix_call_dummy (char *dummy, CORE_ADDR sp, CORE_ADDR fun, int nargs,
948 struct value **args, struct type *type, int gcc_p)
952 offset24 = (long) fun - (long) entry_point_address ();
953 offset24 &= 0x3fffff;
954 offset24 |= 0xff800000; /* jarl <offset24>, r31 */
956 store_unsigned_integer ((unsigned int *) &dummy[2], 2, offset24 & 0xffff);
957 store_unsigned_integer ((unsigned int *) &dummy[0], 2, offset24 >> 16);
961 v850_saved_pc_after_call (struct frame_info *ignore)
963 return read_register (E_RP_REGNUM);
967 v850_extract_return_value (struct type *type, char *regbuf, char *valbuf)
969 memcpy (valbuf, regbuf + v850_register_byte (E_V0_REGNUM),
973 const static unsigned char *
974 v850_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
976 static unsigned char breakpoint[] = { 0x85, 0x05 };
977 *lenptr = sizeof (breakpoint);
982 v850_extract_struct_value_address (char *regbuf)
984 return extract_address (regbuf + v850_register_byte (E_V0_REGNUM),
985 v850_register_raw_size (E_V0_REGNUM));
989 v850_store_return_value (struct type *type, char *valbuf)
991 write_register_bytes(v850_register_byte (E_V0_REGNUM), valbuf,
996 v850_frame_init_saved_regs (struct frame_info *fi)
998 struct prologue_info pi;
999 struct pifsr pifsrs[E_NUM_REGS + 1], *pifsr;
1000 CORE_ADDR func_addr, func_end;
1002 if (!fi->saved_regs)
1004 frame_saved_regs_zalloc (fi);
1006 /* The call dummy doesn't save any registers on the stack, so we
1008 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1011 /* Find the beginning of this function, so we can analyze its
1013 if (find_pc_partial_function (fi->pc, NULL, &func_addr, &func_end))
1017 v850_scan_prologue (fi->pc, &pi);
1019 if (!fi->next && pi.framereg == E_SP_REGNUM)
1020 fi->frame = read_register (pi.framereg) - pi.frameoffset;
1022 for (pifsr = pifsrs; pifsr->framereg; pifsr++)
1024 fi->saved_regs[pifsr->reg] = pifsr->offset + fi->frame;
1026 if (pifsr->framereg == E_SP_REGNUM)
1027 fi->saved_regs[pifsr->reg] += pi.frameoffset;
1030 /* Else we're out of luck (can't debug completely stripped code).
1035 /* Function: init_extra_frame_info
1036 Setup the frame's frame pointer, pc, and frame addresses for saved
1037 registers. Most of the work is done in scan_prologue().
1039 Note that when we are called for the last frame (currently active frame),
1040 that fi->pc and fi->frame will already be setup. However, fi->frame will
1041 be valid only if this routine uses FP. For previous frames, fi-frame will
1042 always be correct (since that is derived from v850_frame_chain ()).
1044 We can be called with the PC in the call dummy under two circumstances.
1045 First, during normal backtracing, second, while figuring out the frame
1046 pointer just prior to calling the target function (see run_stack_dummy). */
1049 v850_init_extra_frame_info (int fromleaf, struct frame_info *fi)
1051 struct prologue_info pi;
1054 fi->pc = FRAME_SAVED_PC (fi->next);
1056 v850_frame_init_saved_regs (fi);
1060 v850_store_struct_return (CORE_ADDR a, CORE_ADDR b)
1065 v850_target_read_fp (void)
1067 return read_register (E_FP_RAW_REGNUM);
1070 static struct gdbarch *
1071 v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1073 static LONGEST call_dummy_words[1] = { 0 };
1074 struct gdbarch_tdep *tdep = NULL;
1075 struct gdbarch *gdbarch;
1078 /* find a candidate among the list of pre-declared architectures. */
1079 arches = gdbarch_list_lookup_by_info (arches, &info);
1081 return (arches->gdbarch);
1084 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
1087 /* Change the register names based on the current machine type. */
1088 if (info.bfd_arch_info->arch != bfd_arch_v850)
1091 gdbarch = gdbarch_alloc (&info, 0);
1093 for (i = 0; v850_processor_type_table[i].regnames != NULL; i++)
1095 if (v850_processor_type_table[i].mach == info.bfd_arch_info->mach)
1097 v850_register_names = v850_processor_type_table[i].regnames;
1098 tm_print_insn_info.mach = info.bfd_arch_info->mach;
1104 * Basic register fields and methods.
1106 set_gdbarch_num_regs (gdbarch, E_NUM_REGS);
1107 set_gdbarch_num_pseudo_regs (gdbarch, 0);
1108 set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM);
1109 set_gdbarch_fp_regnum (gdbarch, E_FP_REGNUM);
1110 set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM);
1111 set_gdbarch_register_name (gdbarch, v850_register_name);
1112 set_gdbarch_register_size (gdbarch, v850_reg_size);
1113 set_gdbarch_register_bytes (gdbarch, E_ALL_REGS_SIZE);
1114 set_gdbarch_register_byte (gdbarch, v850_register_byte);
1115 set_gdbarch_register_raw_size (gdbarch, v850_register_raw_size);
1116 set_gdbarch_max_register_raw_size (gdbarch, v850_reg_size);
1117 set_gdbarch_register_virtual_size (gdbarch, v850_register_raw_size);
1118 set_gdbarch_max_register_virtual_size (gdbarch, v850_reg_size);
1119 set_gdbarch_register_virtual_type (gdbarch, v850_reg_virtual_type);
1121 set_gdbarch_read_fp (gdbarch, v850_target_read_fp);
1126 set_gdbarch_init_extra_frame_info (gdbarch, v850_init_extra_frame_info);
1127 set_gdbarch_frame_init_saved_regs (gdbarch, v850_frame_init_saved_regs);
1128 set_gdbarch_frame_chain (gdbarch, v850_frame_chain);
1129 set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register);
1130 set_gdbarch_saved_pc_after_call (gdbarch, v850_saved_pc_after_call);
1131 set_gdbarch_frame_saved_pc (gdbarch, v850_frame_saved_pc);
1132 set_gdbarch_skip_prologue (gdbarch, v850_skip_prologue);
1133 set_gdbarch_frame_chain_valid (gdbarch, generic_file_frame_chain_valid);
1134 set_gdbarch_frame_args_address (gdbarch, default_frame_address);
1135 set_gdbarch_frame_locals_address (gdbarch, default_frame_address);
1140 /* Stack grows up. */
1141 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1142 /* PC stops zero byte after a trap instruction
1143 (which means: exactly on trap instruction). */
1144 set_gdbarch_decr_pc_after_break (gdbarch, 0);
1145 /* This value is almost never non-zero... */
1146 set_gdbarch_function_start_offset (gdbarch, 0);
1147 /* This value is almost never non-zero... */
1148 set_gdbarch_frame_args_skip (gdbarch, 0);
1149 /* OK to default this value to 'unknown'. */
1150 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
1151 /* W/o prototype, coerce float args to double. */
1152 set_gdbarch_coerce_float_to_double (gdbarch, standard_coerce_float_to_double);
1157 * These values and methods are used when gdb calls a target function. */
1158 set_gdbarch_use_generic_dummy_frames (gdbarch, 1);
1159 set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
1160 set_gdbarch_push_return_address (gdbarch, v850_push_return_address);
1161 set_gdbarch_extract_return_value (gdbarch, v850_extract_return_value);
1162 set_gdbarch_push_arguments (gdbarch, v850_push_arguments);
1163 set_gdbarch_pop_frame (gdbarch, v850_pop_frame);
1164 set_gdbarch_store_struct_return (gdbarch, v850_store_struct_return);
1165 set_gdbarch_store_return_value (gdbarch, v850_store_return_value);
1166 set_gdbarch_extract_struct_value_address (gdbarch, v850_extract_struct_value_address);
1167 set_gdbarch_use_struct_convention (gdbarch, v850_use_struct_convention);
1168 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
1169 set_gdbarch_call_dummy_address (gdbarch, entry_point_address);
1170 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
1171 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
1172 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
1173 set_gdbarch_call_dummy_length (gdbarch, 0);
1174 set_gdbarch_pc_in_call_dummy (gdbarch, generic_pc_in_call_dummy);
1175 set_gdbarch_call_dummy_p (gdbarch, 1);
1176 set_gdbarch_call_dummy_words (gdbarch, call_dummy_nil);
1177 set_gdbarch_sizeof_call_dummy_words (gdbarch, 0);
1178 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
1179 /* set_gdbarch_call_dummy_stack_adjust */
1180 set_gdbarch_fix_call_dummy (gdbarch, v850_fix_call_dummy);
1181 set_gdbarch_breakpoint_from_pc (gdbarch, v850_breakpoint_from_pc);
1183 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1184 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1185 set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1186 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
1188 set_gdbarch_extra_stack_alignment_needed (gdbarch, 0);
1194 _initialize_v850_tdep (void)
1196 tm_print_insn = print_insn_v850;
1197 register_gdbarch_init (bfd_arch_v850, v850_gdbarch_init);