1 /* Target-dependent code for Mitsubishi D30V, for GDB.
2 Copyright (C) 1996, 1997 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, Boston, MA 02111-1307, USA. */
20 /* Contributed by Martin Hunt, hunt@cygnus.com */
29 #include "gdb_string.h"
36 void d30v_frame_find_saved_regs PARAMS ((struct frame_info *fi,
37 struct frame_saved_regs *fsr));
38 void d30v_frame_find_saved_regs_offsets PARAMS ((struct frame_info *fi,
39 struct frame_saved_regs *fsr));
40 static void d30v_pop_dummy_frame PARAMS ((struct frame_info *fi));
41 static void d30v_print_flags PARAMS ((void));
42 static void print_flags_command PARAMS ((char *, int));
44 /* the following defines assume:
45 fp is r61, lr is r62, sp is r63, and ?? is r22
46 if that changes, they will need to be updated */
48 #define OP_MASK_ALL_BUT_RA 0x0ffc0fff /* throw away Ra, keep the rest */
50 #define OP_STW_SPM 0x054c0fc0 /* stw Ra, @(sp-) */
51 #define OP_STW_SP_R0 0x05400fc0 /* stw Ra, @(sp,r0) */
52 #define OP_STW_SP_IMM0 0x05480fc0 /* st Ra, @(sp, 0x0) */
53 #define OP_STW_R22P_R0 0x05440580 /* stw Ra, @(r22+,r0) */
55 #define OP_ST2W_SPM 0x056c0fc0 /* st2w Ra, @(sp-) */
56 #define OP_ST2W_SP_R0 0x05600fc0 /* st2w Ra, @(sp, r0) */
57 #define OP_ST2W_SP_IMM0 0x05680fc0 /* st2w Ra, @(sp, 0x0) */
58 #define OP_ST2W_R22P_R0 0x05640580 /* st2w Ra, @(r22+, r0) */
60 #define OP_MASK_OPCODE 0x0ffc0000 /* just the opcode, ign operands */
61 #define OP_NOP 0x00f00000 /* nop */
63 #define OP_MASK_ALL_BUT_IMM 0x0fffffc0 /* throw away imm, keep the rest */
64 #define OP_SUB_SP_IMM 0x082bffc0 /* sub sp,sp,imm */
65 #define OP_ADD_SP_IMM 0x080bffc0 /* add sp,sp,imm */
66 #define OP_ADD_R22_SP_IMM 0x08096fc0 /* add r22,sp,imm */
67 #define OP_STW_FP_SP_IMM 0x054bdfc0 /* stw fp,@(sp,imm) */
68 #define OP_OR_SP_R0_IMM 0x03abf000 /* or sp,r0,imm */
71 #define OP_OR_FP_R0_SP 0x03a3d03f /* or fp,r0,sp */
72 #define OP_OR_FP_SP_R0 0x03a3dfc0 /* or fp,sp,r0 */
73 #define OP_OR_FP_IMM0_SP 0x03abd03f /* or fp,0x0,sp */
74 #define OP_STW_FP_R22P_R0 0x0547d580 /* stw fp,@(r22+,r0) */
75 #define OP_STW_LR_R22P_R0 0x0547e580 /* stw lr,@(r22+,r0) */
77 #define OP_MASK_OP_AND_RB 0x0ff80fc0 /* keep op and rb,throw away rest */
78 #define OP_STW_SP_IMM 0x05480fc0 /* stw Ra,@(sp,imm) */
79 #define OP_ST2W_SP_IMM 0x05680fc0 /* st2w Ra,@(sp,imm) */
80 #define OP_STW_FP_IMM 0x05480f40 /* stw Ra,@(fp,imm) */
81 #define OP_STW_FP_R0 0x05400f40 /* stw Ra,@(fp,r0) */
83 #define OP_MASK_FM_BIT 0x80000000
84 #define OP_MASK_CC_BITS 0x70000000
85 #define OP_MASK_SUB_INST 0x0fffffff
87 #define EXTRACT_RA(op) (((op) >> 12) & 0x3f)
88 #define EXTRACT_RB(op) (((op) >> 6) & 0x3f)
89 #define EXTRACT_RC(op) (((op) & 0x3f)
90 #define EXTRACT_UIMM6(op) ((op) & 0x3f)
91 #define EXTRACT_IMM6(op) ((((int)EXTRACT_UIMM6(op)) << 26) >> 26)
92 #define EXTRACT_IMM26(op) ((((op)&0x0ff00000) >> 2) | ((op)&0x0003ffff))
93 #define EXTRACT_IMM32(opl, opr) ((EXTRACT_UIMM6(opl) << 26)|EXTRACT_IMM26(opr))
97 d30v_frame_chain_valid (chain, fi)
99 struct frame_info *fi; /* not used here */
102 return ((chain) != 0 && (fi) != 0 && (fi)->return_pc != 0);
104 return ((chain) != 0 && (fi) != 0 && (fi)->frame <= chain);
108 /* Discard from the stack the innermost frame, restoring all saved
114 struct frame_info *frame = get_current_frame ();
117 struct frame_saved_regs fsr;
120 fp = FRAME_FP (frame);
123 d30v_pop_dummy_frame(frame);
127 /* fill out fsr with the address of where each */
128 /* register was stored in the frame */
129 get_frame_saved_regs (frame, &fsr);
131 /* now update the current registers with the old values */
132 for (regnum = A0_REGNUM; regnum < A0_REGNUM+2 ; regnum++)
134 if (fsr.regs[regnum])
136 read_memory (fsr.regs[regnum], raw_buffer, 8);
137 write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, 8);
140 for (regnum = 0; regnum < SP_REGNUM; regnum++)
142 if (fsr.regs[regnum])
144 write_register (regnum, read_memory_unsigned_integer (fsr.regs[regnum], 4));
147 if (fsr.regs[PSW_REGNUM])
149 write_register (PSW_REGNUM, read_memory_unsigned_integer (fsr.regs[PSW_REGNUM], 4));
152 write_register (PC_REGNUM, read_register(LR_REGNUM));
153 write_register (SP_REGNUM, fp + frame->size);
154 target_store_registers (-1);
155 flush_cached_frames ();
162 /* add sp,sp,imm -- observed */
163 if ((op & OP_MASK_ALL_BUT_IMM) == OP_ADD_SP_IMM)
166 /* add r22,sp,imm -- observed */
167 if ((op & OP_MASK_ALL_BUT_IMM) == OP_ADD_R22_SP_IMM)
170 /* or fp,r0,sp -- observed */
171 if (op == OP_OR_FP_R0_SP)
175 if ((op & OP_MASK_OPCODE) == OP_NOP)
178 /* stw Ra,@(sp,r0) */
179 if ((op & OP_MASK_ALL_BUT_RA) == OP_STW_SP_R0)
182 /* stw Ra,@(sp,0x0) */
183 if ((op & OP_MASK_ALL_BUT_RA) == OP_STW_SP_IMM0)
186 /* st2w Ra,@(sp,r0) */
187 if ((op & OP_MASK_ALL_BUT_RA) == OP_ST2W_SP_R0)
190 /* st2w Ra,@(sp,0x0) */
191 if ((op & OP_MASK_ALL_BUT_RA) == OP_ST2W_SP_IMM0)
194 /* stw fp, @(r22+,r0) -- observed */
195 if (op == OP_STW_FP_R22P_R0)
198 /* stw r62, @(r22+,r0) -- observed */
199 if (op == OP_STW_LR_R22P_R0)
202 /* stw Ra, @(fp,r0) -- observed */
203 if ((op & OP_MASK_ALL_BUT_RA) == OP_STW_FP_R0)
204 return 1; /* first arg */
206 /* stw Ra, @(fp,imm) -- observed */
207 if ((op & OP_MASK_OP_AND_RB) == OP_STW_FP_IMM)
208 return 1; /* second and subsequent args */
210 /* stw fp,@(sp,imm) -- observed */
211 if ((op & OP_MASK_ALL_BUT_IMM) == OP_STW_FP_SP_IMM)
214 /* st2w Ra,@(r22+,r0) */
215 if ((op & OP_MASK_ALL_BUT_RA) == OP_ST2W_R22P_R0)
219 if ((op & OP_MASK_ALL_BUT_RA) == OP_STW_SPM)
222 /* st2w Ra, @(sp-) */
223 if ((op & OP_MASK_ALL_BUT_RA) == OP_ST2W_SPM)
226 /* sub.? sp,sp,imm */
227 if ((op & OP_MASK_ALL_BUT_IMM) == OP_SUB_SP_IMM)
234 d30v_skip_prologue (pc)
238 unsigned long opl, opr; /* left / right sub operations */
239 unsigned long fm0, fm1; /* left / right mode bits */
240 unsigned long cc0, cc1;
241 unsigned long op1, op2;
242 CORE_ADDR func_addr, func_end;
243 struct symtab_and_line sal;
245 /* If we have line debugging information, then the end of the */
246 /* prologue should the first assembly instruction of the first source line */
247 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
249 sal = find_pc_line (func_addr, 0);
250 if ( sal.end && sal.end < func_end)
254 if (target_read_memory (pc, (char *)&op[0], 8))
255 return pc; /* Can't access it -- assume no prologue. */
259 opl = (unsigned long)read_memory_integer (pc, 4);
260 opr = (unsigned long)read_memory_integer (pc+4, 4);
262 fm0 = (opl & OP_MASK_FM_BIT);
263 fm1 = (opr & OP_MASK_FM_BIT);
265 cc0 = (opl & OP_MASK_CC_BITS);
266 cc1 = (opr & OP_MASK_CC_BITS);
268 opl = (opl & OP_MASK_SUB_INST);
269 opr = (opr & OP_MASK_SUB_INST);
273 /* long instruction (opl contains the opcode) */
274 if (((opl & OP_MASK_ALL_BUT_IMM) != OP_ADD_SP_IMM) && /* add sp,sp,imm */
275 ((opl & OP_MASK_ALL_BUT_IMM) != OP_ADD_R22_SP_IMM) && /* add r22,sp,imm */
276 ((opl & OP_MASK_OP_AND_RB) != OP_STW_SP_IMM) && /* stw Ra, @(sp,imm) */
277 ((opl & OP_MASK_OP_AND_RB) != OP_ST2W_SP_IMM)) /* st2w Ra, @(sp,imm) */
282 /* short instructions */
293 if (check_prologue(op1))
295 if (!check_prologue(op2))
297 /* if the previous opcode was really part of the prologue */
298 /* and not just a NOP, then we want to break after both instructions */
299 if ((op1 & OP_MASK_OPCODE) != OP_NOP)
312 static int end_of_stack;
314 /* Given a GDB frame, determine the address of the calling function's frame.
315 This will be used to create a new GDB frame struct, and then
316 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
320 d30v_frame_chain (frame)
321 struct frame_info *frame;
323 struct frame_saved_regs fsr;
325 d30v_frame_find_saved_regs (frame, &fsr);
330 if (frame->return_pc == IMEM_START)
333 if (!fsr.regs[FP_REGNUM])
335 if (!fsr.regs[SP_REGNUM] || fsr.regs[SP_REGNUM] == STACK_START)
338 return fsr.regs[SP_REGNUM];
341 if (!read_memory_unsigned_integer(fsr.regs[FP_REGNUM],4))
344 return read_memory_unsigned_integer(fsr.regs[FP_REGNUM],4);
347 static int next_addr, uses_frame;
348 static int frame_size;
351 prologue_find_regs (op, fsr, addr)
353 struct frame_saved_regs *fsr;
359 /* add sp,sp,imm -- observed */
360 if ((op & OP_MASK_ALL_BUT_IMM) == OP_ADD_SP_IMM)
362 offset = EXTRACT_IMM6(op);
363 /*next_addr += offset;*/
364 frame_size += -offset;
368 /* add r22,sp,imm -- observed */
369 if ((op & OP_MASK_ALL_BUT_IMM) == OP_ADD_R22_SP_IMM)
371 offset = EXTRACT_IMM6(op);
372 next_addr = (offset - frame_size);
376 /* stw Ra, @(fp, offset) -- observed */
377 if ((op & OP_MASK_OP_AND_RB) == OP_STW_FP_IMM)
380 offset = EXTRACT_IMM6(op);
381 fsr->regs[n] = (offset - frame_size);
385 /* stw Ra, @(fp, r0) -- observed */
386 if ((op & OP_MASK_ALL_BUT_RA) == OP_STW_FP_R0)
389 fsr->regs[n] = (- frame_size);
393 /* or fp,0,sp -- observed */
394 if ((op == OP_OR_FP_R0_SP) ||
395 (op == OP_OR_FP_SP_R0) ||
396 (op == OP_OR_FP_IMM0_SP))
403 if ((op & OP_MASK_OPCODE) == OP_NOP)
406 /* stw Ra,@(r22+,r0) -- observed */
407 if ((op & OP_MASK_ALL_BUT_RA) == OP_STW_R22P_R0)
410 fsr->regs[n] = next_addr;
414 #if 0 /* subsumed in pattern above */
415 /* stw fp,@(r22+,r0) -- observed */
416 if (op == OP_STW_FP_R22P_R0)
418 fsr->regs[FP_REGNUM] = next_addr; /* XXX */
423 /* stw r62,@(r22+,r0) -- observed */
424 if (op == OP_STW_LR_R22P_R0)
426 fsr->regs[LR_REGNUM] = next_addr;
431 /* st2w Ra,@(r22+,r0) -- observed */
432 if ((op & OP_MASK_ALL_BUT_RA) == OP_ST2W_R22P_R0)
435 fsr->regs[n] = next_addr;
436 fsr->regs[n+1] = next_addr + 4;
442 if ((op & OP_MASK_ALL_BUT_RA) == OP_STW_SPM)
445 fsr->regs[n] = next_addr;
450 /* st2w Ra, @(sp-) */
451 else if ((op & OP_MASK_ALL_BUT_RA) == OP_ST2W_SPM)
454 fsr->regs[n] = next_addr;
455 fsr->regs[n+1] = next_addr+4;
461 if ((op & OP_MASK_ALL_BUT_IMM) == OP_SUB_SP_IMM)
463 offset = EXTRACT_IMM6(op);
464 frame_size += -offset;
468 /* st rn, @(sp,0) -- observed */
469 if (((op & OP_MASK_ALL_BUT_RA) == OP_STW_SP_R0) ||
470 ((op & OP_MASK_ALL_BUT_RA) == OP_STW_SP_IMM0))
473 fsr->regs[n] = (- frame_size);
477 /* st2w rn, @(sp,0) */
478 if (((op & OP_MASK_ALL_BUT_RA) == OP_ST2W_SP_R0) ||
479 ((op & OP_MASK_ALL_BUT_RA) == OP_ST2W_SP_IMM0))
482 fsr->regs[n] = (- frame_size);
483 fsr->regs[n+1] = (- frame_size) + 4;
487 /* stw fp,@(sp,imm) -- observed */
488 if ((op & OP_MASK_ALL_BUT_IMM) == OP_STW_FP_SP_IMM)
490 offset = EXTRACT_IMM6(op);
491 fsr->regs[FP_REGNUM] = (offset - frame_size);
497 /* Put here the code to store, into a struct frame_saved_regs, the
498 addresses of the saved registers of frame described by FRAME_INFO.
499 This includes special registers such as pc and fp saved in special
500 ways in the stack frame. sp is even more special: the address we
501 return for it IS the sp for the next frame. */
503 d30v_frame_find_saved_regs (fi, fsr)
504 struct frame_info *fi;
505 struct frame_saved_regs *fsr;
508 unsigned long opl, opr;
509 unsigned long op1, op2;
510 unsigned long fm0, fm1;
514 memset (fsr, 0, sizeof (*fsr));
521 d30v_frame_find_saved_regs_offsets (fi, fsr);
523 fi->size = frame_size;
526 fp = read_register(SP_REGNUM);
528 for (i=0; i<NUM_REGS-1; i++)
531 fsr->regs[i] = fsr->regs[i] + fp + frame_size;
534 if (fsr->regs[LR_REGNUM])
535 fi->return_pc = read_memory_unsigned_integer(fsr->regs[LR_REGNUM],4);
537 fi->return_pc = read_register(LR_REGNUM);
539 /* the SP is not normally (ever?) saved, but check anyway */
540 if (!fsr->regs[SP_REGNUM])
542 /* if the FP was saved, that means the current FP is valid, */
543 /* otherwise, it isn't being used, so we use the SP instead */
545 fsr->regs[SP_REGNUM] = read_register(FP_REGNUM) + fi->size;
548 fsr->regs[SP_REGNUM] = fp + fi->size;
550 fsr->regs[FP_REGNUM] = 0;
556 d30v_frame_find_saved_regs_offsets (fi, fsr)
557 struct frame_info *fi;
558 struct frame_saved_regs *fsr;
561 unsigned long opl, opr;
562 unsigned long op1, op2;
563 unsigned long fm0, fm1;
567 memset (fsr, 0, sizeof (*fsr));
572 pc = get_pc_function_start (fi->pc);
577 opl = (unsigned long)read_memory_integer (pc, 4);
578 opr = (unsigned long)read_memory_integer (pc+4, 4);
580 fm0 = (opl & OP_MASK_FM_BIT);
581 fm1 = (opr & OP_MASK_FM_BIT);
583 opl = (opl & OP_MASK_SUB_INST);
584 opr = (opr & OP_MASK_SUB_INST);
588 /* long instruction */
589 if ((opl & OP_MASK_ALL_BUT_IMM) == OP_ADD_SP_IMM)
592 long offset = EXTRACT_IMM32(opl, opr);
593 frame_size += -offset;
595 else if ((opl & OP_MASK_ALL_BUT_IMM) == OP_ADD_R22_SP_IMM)
597 /* add r22,sp,offset */
598 long offset = EXTRACT_IMM32(opl,opr);
599 next_addr = (offset - frame_size);
601 else if ((opl & OP_MASK_OP_AND_RB) == OP_STW_SP_IMM)
603 /* st Ra, @(sp,imm) */
604 long offset = EXTRACT_IMM32(opl, opr);
605 short n = EXTRACT_RA(opl);
606 fsr->regs[n] = (offset - frame_size);
608 else if ((opl & OP_MASK_OP_AND_RB) == OP_ST2W_SP_IMM)
610 /* st2w Ra, @(sp,offset) */
611 long offset = EXTRACT_IMM32(opl, opr);
612 short n = EXTRACT_RA(opl);
613 fsr->regs[n] = (offset - frame_size);
614 fsr->regs[n+1] = (offset - frame_size) + 4;
616 else if ((opl & OP_MASK_ALL_BUT_IMM) == OP_OR_SP_R0_IMM)
625 /* short instructions */
636 if (!prologue_find_regs(op1,fsr,pc) || !prologue_find_regs(op2,fsr,pc))
643 fi->size = frame_size;
646 fp = read_register(SP_REGNUM);
648 for (i=0; i<NUM_REGS-1; i++)
651 fsr->regs[i] = fsr->regs[i] + fp + frame_size;
654 if (fsr->regs[LR_REGNUM])
655 fi->return_pc = read_memory_unsigned_integer(fsr->regs[LR_REGNUM],4);
657 fi->return_pc = read_register(LR_REGNUM);
659 /* the SP is not normally (ever?) saved, but check anyway */
660 if (!fsr->regs[SP_REGNUM])
662 /* if the FP was saved, that means the current FP is valid, */
663 /* otherwise, it isn't being used, so we use the SP instead */
665 fsr->regs[SP_REGNUM] = read_register(FP_REGNUM) + fi->size;
668 fsr->regs[SP_REGNUM] = fp + fi->size;
670 fsr->regs[FP_REGNUM] = 0;
677 d30v_init_extra_frame_info (fromleaf, fi)
679 struct frame_info *fi;
681 struct frame_saved_regs dummy;
683 if (fi->next && (fi->pc == 0))
684 fi->pc = fi->next->return_pc;
686 d30v_frame_find_saved_regs_offsets (fi, &dummy);
693 if ((fi->next == 0) && (uses_frame == 0))
694 /* innermost frame and it's "frameless",
695 so the fi->frame field is wrong, fix it! */
696 fi->frame = read_sp ();
698 if (dummy.regs[LR_REGNUM])
700 /* it was saved, grab it! */
701 dummy.regs[LR_REGNUM] += (fi->frame + frame_size);
702 fi->return_pc = read_memory_unsigned_integer(dummy.regs[LR_REGNUM],4);
705 fi->return_pc = read_register(LR_REGNUM);
709 d30v_init_frame_pc (fromleaf, prev)
711 struct frame_info *prev;
713 /* default value, put here so we can breakpoint on it and
714 see if the default value is really the right thing to use */
715 prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : \
716 prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
719 static void d30v_print_register PARAMS ((int regnum, int tabular));
722 d30v_print_register (regnum, tabular)
726 if (regnum < A0_REGNUM)
729 printf_filtered ("%08x", read_register (regnum));
731 printf_filtered ("0x%x %d", read_register (regnum),
732 read_register (regnum));
736 char regbuf[MAX_REGISTER_RAW_SIZE];
738 read_relative_register_raw_bytes (regnum, regbuf);
740 val_print (REGISTER_VIRTUAL_TYPE (regnum), regbuf, 0, 0,
741 gdb_stdout, 'x', 1, 0, Val_pretty_default);
745 printf_filtered (" ");
746 val_print (REGISTER_VIRTUAL_TYPE (regnum), regbuf, 0, 0,
747 gdb_stdout, 'd', 1, 0, Val_pretty_default);
755 long psw = read_register (PSW_REGNUM);
756 printf_filtered ("flags #1");
757 printf_filtered (" (sm) %d", (psw & PSW_SM) != 0);
758 printf_filtered (" (ea) %d", (psw & PSW_EA) != 0);
759 printf_filtered (" (db) %d", (psw & PSW_DB) != 0);
760 printf_filtered (" (ds) %d", (psw & PSW_DS) != 0);
761 printf_filtered (" (ie) %d", (psw & PSW_IE) != 0);
762 printf_filtered (" (rp) %d", (psw & PSW_RP) != 0);
763 printf_filtered (" (md) %d\n", (psw & PSW_MD) != 0);
765 printf_filtered ("flags #2");
766 printf_filtered (" (f0) %d", (psw & PSW_F0) != 0);
767 printf_filtered (" (f1) %d", (psw & PSW_F1) != 0);
768 printf_filtered (" (f2) %d", (psw & PSW_F2) != 0);
769 printf_filtered (" (f3) %d", (psw & PSW_F3) != 0);
770 printf_filtered (" (s) %d", (psw & PSW_S) != 0);
771 printf_filtered (" (v) %d", (psw & PSW_V) != 0);
772 printf_filtered (" (va) %d", (psw & PSW_VA) != 0);
773 printf_filtered (" (c) %d\n", (psw & PSW_C) != 0);
777 print_flags_command (args, from_tty)
785 d30v_do_registers_info (regnum, fpregs)
789 long long num1, num2;
794 if (REGISTER_NAME (0) == NULL || REGISTER_NAME (0)[0] == '\000')
797 printf_filtered ("%s ", REGISTER_NAME (regnum));
798 d30v_print_register (regnum, 0);
800 printf_filtered ("\n");
804 /* Have to print all the registers. Format them nicely. */
806 printf_filtered ("PC=");
807 print_address (read_pc (), gdb_stdout);
809 printf_filtered (" PSW=");
810 d30v_print_register (PSW_REGNUM, 1);
812 printf_filtered (" BPC=");
813 print_address (read_register (BPC_REGNUM), gdb_stdout);
815 printf_filtered (" BPSW=");
816 d30v_print_register (BPSW_REGNUM, 1);
817 printf_filtered ("\n");
819 printf_filtered ("DPC=");
820 print_address (read_register (DPC_REGNUM), gdb_stdout);
822 printf_filtered (" DPSW=");
823 d30v_print_register (DPSW_REGNUM, 1);
825 printf_filtered (" IBA=");
826 print_address (read_register (IBA_REGNUM), gdb_stdout);
827 printf_filtered ("\n");
829 printf_filtered ("RPT_C=");
830 d30v_print_register (RPT_C_REGNUM, 1);
832 printf_filtered (" RPT_S=");
833 print_address (read_register (RPT_S_REGNUM), gdb_stdout);
835 printf_filtered (" RPT_E=");
836 print_address (read_register (RPT_E_REGNUM), gdb_stdout);
837 printf_filtered ("\n");
839 printf_filtered ("MOD_S=");
840 print_address (read_register (MOD_S_REGNUM), gdb_stdout);
842 printf_filtered (" MOD_E=");
843 print_address (read_register (MOD_E_REGNUM), gdb_stdout);
844 printf_filtered ("\n");
846 printf_filtered ("EIT_VB=");
847 print_address (read_register (EIT_VB_REGNUM), gdb_stdout);
849 printf_filtered (" INT_S=");
850 d30v_print_register (INT_S_REGNUM, 1);
852 printf_filtered (" INT_M=");
853 d30v_print_register (INT_M_REGNUM, 1);
854 printf_filtered ("\n");
857 for (regnum = 0; regnum <= 63;)
861 printf_filtered ("R%d-R%d ", regnum, regnum + 7);
863 printf_filtered (" ");
865 printf_filtered (" ");
867 for (i = 0; i < 8; i++)
869 printf_filtered (" ");
870 d30v_print_register (regnum++, 1);
873 printf_filtered ("\n");
876 printf_filtered ("A0-A1 ");
878 d30v_print_register (A0_REGNUM, 1);
879 printf_filtered (" ");
880 d30v_print_register (A1_REGNUM, 1);
881 printf_filtered ("\n");
885 d30v_fix_call_dummy (dummyname, start_sp, fun, nargs, args, type, gcc_p)
896 char buffer[MAX_REGISTER_RAW_SIZE];
897 struct frame_info *frame = get_current_frame ();
898 frame->dummy = start_sp;
899 /*start_sp |= DMEM_START;*/
902 for (regnum = 0; regnum < NUM_REGS; regnum++)
904 sp -= REGISTER_RAW_SIZE(regnum);
905 store_address (buffer, REGISTER_RAW_SIZE(regnum), read_register(regnum));
906 write_memory (sp, buffer, REGISTER_RAW_SIZE(regnum));
908 write_register (SP_REGNUM, (LONGEST)sp);
909 /* now we need to load LR with the return address */
910 write_register (LR_REGNUM, (LONGEST)d30v_call_dummy_address());
915 d30v_pop_dummy_frame (fi)
916 struct frame_info *fi;
918 CORE_ADDR sp = fi->dummy;
921 for (regnum = 0; regnum < NUM_REGS; regnum++)
923 sp -= REGISTER_RAW_SIZE(regnum);
924 write_register(regnum, read_memory_unsigned_integer (sp, REGISTER_RAW_SIZE(regnum)));
926 flush_cached_frames (); /* needed? */
931 d30v_push_arguments (nargs, args, sp, struct_return, struct_addr)
936 CORE_ADDR struct_addr;
938 int i, len, index=0, regnum=2;
939 char buffer[4], *contents;
944 /* Pass 1. Put all large args on stack */
945 for (i = 0; i < nargs; i++)
947 value_ptr arg = args[i];
948 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
949 len = TYPE_LENGTH (arg_type);
950 contents = VALUE_CONTENTS(arg);
951 val = extract_signed_integer (contents, len);
954 /* put on stack and pass pointers */
956 write_memory (sp, contents, len);
963 for (i = 0; i < nargs; i++)
965 value_ptr arg = args[i];
966 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
967 len = TYPE_LENGTH (arg_type);
968 contents = VALUE_CONTENTS(arg);
971 /* we need multiple registers */
974 for (ndx = 0; len > 0; ndx += 8, len -= 8)
977 regnum++; /* all args > 4 bytes start in even register */
981 val = extract_signed_integer (&contents[ndx], 4);
982 write_register (regnum++, val);
985 val = extract_signed_integer (&contents[ndx+4], 4);
987 val = extract_signed_integer (&contents[ndx+4], len-4);
988 write_register (regnum++, val);
992 /* no more registers available. put it on the stack */
994 /* all args > 4 bytes are padded to a multiple of 8 bytes
995 and start on an 8 byte boundary */
997 sp -= (sp & 7); /* align it */
999 sp -= ((len + 7) & ~7); /* allocate space */
1000 write_memory (sp, &contents[ndx], len);
1009 val = extract_signed_integer (contents, len);
1010 write_register (regnum++, val);
1014 /* all args are padded to a multiple of 4 bytes (at least) */
1015 sp -= ((len + 3) & ~3);
1016 write_memory (sp, contents, len);
1021 /* stack pointer is not on an 8 byte boundary -- align it */
1027 /* pick an out-of-the-way place to set the return value */
1028 /* for an inferior function call. The link register is set to this */
1029 /* value and a momentary breakpoint is set there. When the breakpoint */
1030 /* is hit, the dummy frame is popped and the previous environment is */
1034 d30v_call_dummy_address ()
1037 struct minimal_symbol *sym;
1039 entry = entry_point_address ();
1044 sym = lookup_minimal_symbol ("_start", NULL, symfile_objfile);
1046 if (!sym || MSYMBOL_TYPE (sym) != mst_text)
1049 return SYMBOL_VALUE_ADDRESS (sym);
1052 /* Given a return value in `regbuf' with a type `valtype',
1053 extract and copy its value into `valbuf'. */
1056 d30v_extract_return_value (valtype, regbuf, valbuf)
1057 struct type *valtype;
1058 char regbuf[REGISTER_BYTES];
1061 memcpy (valbuf, regbuf + REGISTER_BYTE (2), TYPE_LENGTH (valtype));
1064 /* The following code implements access to, and display of, the D30V's
1065 instruction trace buffer. The buffer consists of 64K or more
1066 4-byte words of data, of which each words includes an 8-bit count,
1067 an 8-bit segment number, and a 16-bit instruction address.
1069 In theory, the trace buffer is continuously capturing instruction
1070 data that the CPU presents on its "debug bus", but in practice, the
1071 ROMified GDB stub only enables tracing when it continues or steps
1072 the program, and stops tracing when the program stops; so it
1073 actually works for GDB to read the buffer counter out of memory and
1074 then read each trace word. The counter records where the tracing
1075 stops, but there is no record of where it started, so we remember
1076 the PC when we resumed and then search backwards in the trace
1077 buffer for a word that includes that address. This is not perfect,
1078 because you will miss trace data if the resumption PC is the target
1079 of a branch. (The value of the buffer counter is semi-random, any
1080 trace data from a previous program stop is gone.) */
1082 /* The address of the last word recorded in the trace buffer. */
1084 #define DBBC_ADDR (0xd80000)
1086 /* The base of the trace buffer, at least for the "Board_0". */
1088 #define TRACE_BUFFER_BASE (0xf40000)
1090 static void trace_command PARAMS ((char *, int));
1092 static void untrace_command PARAMS ((char *, int));
1094 static void trace_info PARAMS ((char *, int));
1096 static void tdisassemble_command PARAMS ((char *, int));
1098 static void display_trace PARAMS ((int, int));
1100 /* True when instruction traces are being collected. */
1104 /* Remembered PC. */
1106 static CORE_ADDR last_pc;
1108 /* True when trace output should be displayed whenever program stops. */
1110 static int trace_display;
1112 /* True when trace listing should include source lines. */
1114 static int default_trace_show_source = 1;
1116 struct trace_buffer {
1123 trace_command (args, from_tty)
1127 /* Clear the host-side trace buffer, allocating space if needed. */
1128 trace_data.size = 0;
1129 if (trace_data.counts == NULL)
1130 trace_data.counts = (short *) xmalloc (65536 * sizeof(short));
1131 if (trace_data.addrs == NULL)
1132 trace_data.addrs = (CORE_ADDR *) xmalloc (65536 * sizeof(CORE_ADDR));
1136 printf_filtered ("Tracing is now on.\n");
1140 untrace_command (args, from_tty)
1146 printf_filtered ("Tracing is now off.\n");
1150 trace_info (args, from_tty)
1156 if (trace_data.size)
1158 printf_filtered ("%d entries in trace buffer:\n", trace_data.size);
1160 for (i = 0; i < trace_data.size; ++i)
1162 printf_filtered ("%d: %d instruction%s at 0x%x\n",
1163 i, trace_data.counts[i],
1164 (trace_data.counts[i] == 1 ? "" : "s"),
1165 trace_data.addrs[i]);
1169 printf_filtered ("No entries in trace buffer.\n");
1171 printf_filtered ("Tracing is currently %s.\n", (tracing ? "on" : "off"));
1174 /* Print the instruction at address MEMADDR in debugged memory,
1175 on STREAM. Returns length of the instruction, in bytes. */
1178 print_insn (memaddr, stream)
1182 /* If there's no disassembler, something is very wrong. */
1183 if (tm_print_insn == NULL)
1186 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1187 tm_print_insn_info.endian = BFD_ENDIAN_BIG;
1189 tm_print_insn_info.endian = BFD_ENDIAN_LITTLE;
1190 return (*tm_print_insn) (memaddr, &tm_print_insn_info);
1194 d30v_eva_prepare_to_trace ()
1199 last_pc = read_register (PC_REGNUM);
1202 /* Collect trace data from the target board and format it into a form
1203 more useful for display. */
1206 d30v_eva_get_trace_data ()
1208 int count, i, j, oldsize;
1209 int trace_addr, trace_seg, trace_cnt, next_cnt;
1210 unsigned int last_trace, trace_word, next_word;
1211 unsigned int *tmpspace;
1216 tmpspace = xmalloc (65536 * sizeof(unsigned int));
1218 last_trace = read_memory_unsigned_integer (DBBC_ADDR, 2) << 2;
1220 /* Collect buffer contents from the target, stopping when we reach
1221 the word recorded when execution resumed. */
1224 while (last_trace > 0)
1228 read_memory_unsigned_integer (TRACE_BUFFER_BASE + last_trace, 4);
1229 trace_addr = trace_word & 0xffff;
1231 /* Ignore an apparently nonsensical entry. */
1232 if (trace_addr == 0xffd5)
1234 tmpspace[count++] = trace_word;
1235 if (trace_addr == last_pc)
1241 /* Move the data to the host-side trace buffer, adjusting counts to
1242 include the last instruction executed and transforming the address
1243 into something that GDB likes. */
1245 for (i = 0; i < count; ++i)
1247 trace_word = tmpspace[i];
1248 next_word = ((i == 0) ? 0 : tmpspace[i - 1]);
1249 trace_addr = trace_word & 0xffff;
1250 next_cnt = (next_word >> 24) & 0xff;
1251 j = trace_data.size + count - i - 1;
1252 trace_data.addrs[j] = (trace_addr << 2) + 0x1000000;
1253 trace_data.counts[j] = next_cnt + 1;
1256 oldsize = trace_data.size;
1257 trace_data.size += count;
1262 display_trace (oldsize, trace_data.size);
1266 tdisassemble_command (arg, from_tty)
1271 CORE_ADDR low, high;
1277 high = trace_data.size;
1279 else if (!(space_index = (char *) strchr (arg, ' ')))
1281 low = parse_and_eval_address (arg);
1286 /* Two arguments. */
1287 *space_index = '\0';
1288 low = parse_and_eval_address (arg);
1289 high = parse_and_eval_address (space_index + 1);
1294 printf_filtered ("Dump of trace from %d to %d:\n", low, high);
1296 display_trace (low, high);
1298 printf_filtered ("End of trace dump.\n");
1299 gdb_flush (gdb_stdout);
1303 display_trace (low, high)
1306 int i, count, trace_show_source, first, suppress;
1307 CORE_ADDR next_address;
1309 trace_show_source = default_trace_show_source;
1310 if (!have_full_symbols () && !have_partial_symbols())
1312 trace_show_source = 0;
1313 printf_filtered ("No symbol table is loaded. Use the \"file\" command.\n");
1314 printf_filtered ("Trace will not display any source.\n");
1319 for (i = low; i < high; ++i)
1321 next_address = trace_data.addrs[i];
1322 count = trace_data.counts[i];
1326 if (trace_show_source)
1328 struct symtab_and_line sal, sal_prev;
1330 sal_prev = find_pc_line (next_address - 4, 0);
1331 sal = find_pc_line (next_address, 0);
1335 if (first || sal.line != sal_prev.line)
1336 print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
1342 /* FIXME-32x64--assumes sal.pc fits in long. */
1343 printf_filtered ("No source file for address %s.\n",
1344 local_hex_string((unsigned long) sal.pc));
1349 print_address (next_address, gdb_stdout);
1350 printf_filtered (":");
1351 printf_filtered ("\t");
1353 next_address = next_address + print_insn (next_address, gdb_stdout);
1354 printf_filtered ("\n");
1355 gdb_flush (gdb_stdout);
1360 extern void (*target_resume_hook) PARAMS ((void));
1361 extern void (*target_wait_loop_hook) PARAMS ((void));
1364 _initialize_d30v_tdep ()
1366 tm_print_insn = print_insn_d30v;
1368 target_resume_hook = d30v_eva_prepare_to_trace;
1369 target_wait_loop_hook = d30v_eva_get_trace_data;
1371 add_info ("flags", print_flags_command, "Print d30v flags.");
1373 add_com ("trace", class_support, trace_command,
1374 "Enable tracing of instruction execution.");
1376 add_com ("untrace", class_support, untrace_command,
1377 "Disable tracing of instruction execution.");
1379 add_com ("tdisassemble", class_vars, tdisassemble_command,
1380 "Disassemble the trace buffer.\n\
1381 Two optional arguments specify a range of trace buffer entries\n\
1382 as reported by info trace (NOT addresses!).");
1384 add_info ("trace", trace_info,
1385 "Display info about the trace data buffer.");
1387 add_show_from_set (add_set_cmd ("tracedisplay", no_class,
1388 var_integer, (char *)&trace_display,
1389 "Set automatic display of trace.\n", &setlist),
1391 add_show_from_set (add_set_cmd ("tracesource", no_class,
1392 var_integer, (char *)&default_trace_show_source,
1393 "Set display of source code with trace.\n", &setlist),