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,
19 Boston, MA 02111-1307, USA. */
21 /* Contributed by Martin Hunt, hunt@cygnus.com */
30 #include "gdb_string.h"
37 void d30v_frame_find_saved_regs
PARAMS ((struct frame_info
* fi
,
38 struct frame_saved_regs
* fsr
));
39 void d30v_frame_find_saved_regs_offsets
PARAMS ((struct frame_info
* fi
,
40 struct frame_saved_regs
* fsr
));
41 static void d30v_pop_dummy_frame
PARAMS ((struct frame_info
* fi
));
42 static void d30v_print_flags
PARAMS ((void));
43 static void print_flags_command
PARAMS ((char *, int));
45 /* the following defines assume:
46 fp is r61, lr is r62, sp is r63, and ?? is r22
47 if that changes, they will need to be updated */
49 #define OP_MASK_ALL_BUT_RA 0x0ffc0fff /* throw away Ra, keep the rest */
51 #define OP_STW_SPM 0x054c0fc0 /* stw Ra, @(sp-) */
52 #define OP_STW_SP_R0 0x05400fc0 /* stw Ra, @(sp,r0) */
53 #define OP_STW_SP_IMM0 0x05480fc0 /* st Ra, @(sp, 0x0) */
54 #define OP_STW_R22P_R0 0x05440580 /* stw Ra, @(r22+,r0) */
56 #define OP_ST2W_SPM 0x056c0fc0 /* st2w Ra, @(sp-) */
57 #define OP_ST2W_SP_R0 0x05600fc0 /* st2w Ra, @(sp, r0) */
58 #define OP_ST2W_SP_IMM0 0x05680fc0 /* st2w Ra, @(sp, 0x0) */
59 #define OP_ST2W_R22P_R0 0x05640580 /* st2w Ra, @(r22+, r0) */
61 #define OP_MASK_OPCODE 0x0ffc0000 /* just the opcode, ign operands */
62 #define OP_NOP 0x00f00000 /* nop */
64 #define OP_MASK_ALL_BUT_IMM 0x0fffffc0 /* throw away imm, keep the rest */
65 #define OP_SUB_SP_IMM 0x082bffc0 /* sub sp,sp,imm */
66 #define OP_ADD_SP_IMM 0x080bffc0 /* add sp,sp,imm */
67 #define OP_ADD_R22_SP_IMM 0x08096fc0 /* add r22,sp,imm */
68 #define OP_STW_FP_SP_IMM 0x054bdfc0 /* stw fp,@(sp,imm) */
69 #define OP_OR_SP_R0_IMM 0x03abf000 /* or sp,r0,imm */
72 #define OP_OR_FP_R0_SP 0x03a3d03f /* or fp,r0,sp */
73 #define OP_OR_FP_SP_R0 0x03a3dfc0 /* or fp,sp,r0 */
74 #define OP_OR_FP_IMM0_SP 0x03abd03f /* or fp,0x0,sp */
75 #define OP_STW_FP_R22P_R0 0x0547d580 /* stw fp,@(r22+,r0) */
76 #define OP_STW_LR_R22P_R0 0x0547e580 /* stw lr,@(r22+,r0) */
78 #define OP_MASK_OP_AND_RB 0x0ff80fc0 /* keep op and rb,throw away rest */
79 #define OP_STW_SP_IMM 0x05480fc0 /* stw Ra,@(sp,imm) */
80 #define OP_ST2W_SP_IMM 0x05680fc0 /* st2w Ra,@(sp,imm) */
81 #define OP_STW_FP_IMM 0x05480f40 /* stw Ra,@(fp,imm) */
82 #define OP_STW_FP_R0 0x05400f40 /* stw Ra,@(fp,r0) */
84 #define OP_MASK_FM_BIT 0x80000000
85 #define OP_MASK_CC_BITS 0x70000000
86 #define OP_MASK_SUB_INST 0x0fffffff
88 #define EXTRACT_RA(op) (((op) >> 12) & 0x3f)
89 #define EXTRACT_RB(op) (((op) >> 6) & 0x3f)
90 #define EXTRACT_RC(op) (((op) & 0x3f)
91 #define EXTRACT_UIMM6(op) ((op) & 0x3f)
92 #define EXTRACT_IMM6(op) ((((int)EXTRACT_UIMM6(op)) << 26) >> 26)
93 #define EXTRACT_IMM26(op) ((((op)&0x0ff00000) >> 2) | ((op)&0x0003ffff))
94 #define EXTRACT_IMM32(opl, opr) ((EXTRACT_UIMM6(opl) << 26)|EXTRACT_IMM26(opr))
98 d30v_frame_chain_valid (chain
, fi
)
100 struct frame_info
*fi
; /* not used here */
103 return ((chain
) != 0 && (fi
) != 0 && (fi
)->return_pc
!= 0);
105 return ((chain
) != 0 && (fi
) != 0 && (fi
)->frame
<= chain
);
109 /* Discard from the stack the innermost frame, restoring all saved
115 struct frame_info
*frame
= get_current_frame ();
118 struct frame_saved_regs fsr
;
121 fp
= FRAME_FP (frame
);
124 d30v_pop_dummy_frame (frame
);
128 /* fill out fsr with the address of where each */
129 /* register was stored in the frame */
130 get_frame_saved_regs (frame
, &fsr
);
132 /* now update the current registers with the old values */
133 for (regnum
= A0_REGNUM
; regnum
< A0_REGNUM
+ 2; regnum
++)
135 if (fsr
.regs
[regnum
])
137 read_memory (fsr
.regs
[regnum
], raw_buffer
, 8);
138 write_register_bytes (REGISTER_BYTE (regnum
), raw_buffer
, 8);
141 for (regnum
= 0; regnum
< SP_REGNUM
; regnum
++)
143 if (fsr
.regs
[regnum
])
145 write_register (regnum
, read_memory_unsigned_integer (fsr
.regs
[regnum
], 4));
148 if (fsr
.regs
[PSW_REGNUM
])
150 write_register (PSW_REGNUM
, read_memory_unsigned_integer (fsr
.regs
[PSW_REGNUM
], 4));
153 write_register (PC_REGNUM
, read_register (LR_REGNUM
));
154 write_register (SP_REGNUM
, fp
+ frame
->size
);
155 target_store_registers (-1);
156 flush_cached_frames ();
163 /* add sp,sp,imm -- observed */
164 if ((op
& OP_MASK_ALL_BUT_IMM
) == OP_ADD_SP_IMM
)
167 /* add r22,sp,imm -- observed */
168 if ((op
& OP_MASK_ALL_BUT_IMM
) == OP_ADD_R22_SP_IMM
)
171 /* or fp,r0,sp -- observed */
172 if (op
== OP_OR_FP_R0_SP
)
176 if ((op
& OP_MASK_OPCODE
) == OP_NOP
)
179 /* stw Ra,@(sp,r0) */
180 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_STW_SP_R0
)
183 /* stw Ra,@(sp,0x0) */
184 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_STW_SP_IMM0
)
187 /* st2w Ra,@(sp,r0) */
188 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_ST2W_SP_R0
)
191 /* st2w Ra,@(sp,0x0) */
192 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_ST2W_SP_IMM0
)
195 /* stw fp, @(r22+,r0) -- observed */
196 if (op
== OP_STW_FP_R22P_R0
)
199 /* stw r62, @(r22+,r0) -- observed */
200 if (op
== OP_STW_LR_R22P_R0
)
203 /* stw Ra, @(fp,r0) -- observed */
204 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_STW_FP_R0
)
205 return 1; /* first arg */
207 /* stw Ra, @(fp,imm) -- observed */
208 if ((op
& OP_MASK_OP_AND_RB
) == OP_STW_FP_IMM
)
209 return 1; /* second and subsequent args */
211 /* stw fp,@(sp,imm) -- observed */
212 if ((op
& OP_MASK_ALL_BUT_IMM
) == OP_STW_FP_SP_IMM
)
215 /* st2w Ra,@(r22+,r0) */
216 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_ST2W_R22P_R0
)
220 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_STW_SPM
)
223 /* st2w Ra, @(sp-) */
224 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_ST2W_SPM
)
227 /* sub.? sp,sp,imm */
228 if ((op
& OP_MASK_ALL_BUT_IMM
) == OP_SUB_SP_IMM
)
235 d30v_skip_prologue (pc
)
239 unsigned long opl
, opr
; /* left / right sub operations */
240 unsigned long fm0
, fm1
; /* left / right mode bits */
241 unsigned long cc0
, cc1
;
242 unsigned long op1
, op2
;
243 CORE_ADDR func_addr
, func_end
;
244 struct symtab_and_line sal
;
246 /* If we have line debugging information, then the end of the */
247 /* prologue should the first assembly instruction of the first source line */
248 if (find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
250 sal
= find_pc_line (func_addr
, 0);
251 if (sal
.end
&& sal
.end
< func_end
)
255 if (target_read_memory (pc
, (char *) &op
[0], 8))
256 return pc
; /* Can't access it -- assume no prologue. */
260 opl
= (unsigned long) read_memory_integer (pc
, 4);
261 opr
= (unsigned long) read_memory_integer (pc
+ 4, 4);
263 fm0
= (opl
& OP_MASK_FM_BIT
);
264 fm1
= (opr
& OP_MASK_FM_BIT
);
266 cc0
= (opl
& OP_MASK_CC_BITS
);
267 cc1
= (opr
& OP_MASK_CC_BITS
);
269 opl
= (opl
& OP_MASK_SUB_INST
);
270 opr
= (opr
& OP_MASK_SUB_INST
);
274 /* long instruction (opl contains the opcode) */
275 if (((opl
& OP_MASK_ALL_BUT_IMM
) != OP_ADD_SP_IMM
) && /* add sp,sp,imm */
276 ((opl
& OP_MASK_ALL_BUT_IMM
) != OP_ADD_R22_SP_IMM
) && /* add r22,sp,imm */
277 ((opl
& OP_MASK_OP_AND_RB
) != OP_STW_SP_IMM
) && /* stw Ra, @(sp,imm) */
278 ((opl
& OP_MASK_OP_AND_RB
) != OP_ST2W_SP_IMM
)) /* st2w Ra, @(sp,imm) */
283 /* short instructions */
294 if (check_prologue (op1
))
296 if (!check_prologue (op2
))
298 /* if the previous opcode was really part of the prologue */
299 /* and not just a NOP, then we want to break after both instructions */
300 if ((op1
& OP_MASK_OPCODE
) != OP_NOP
)
313 static int end_of_stack
;
315 /* Given a GDB frame, determine the address of the calling function's frame.
316 This will be used to create a new GDB frame struct, and then
317 INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame.
321 d30v_frame_chain (frame
)
322 struct frame_info
*frame
;
324 struct frame_saved_regs fsr
;
326 d30v_frame_find_saved_regs (frame
, &fsr
);
329 return (CORE_ADDR
) 0;
331 if (frame
->return_pc
== IMEM_START
)
332 return (CORE_ADDR
) 0;
334 if (!fsr
.regs
[FP_REGNUM
])
336 if (!fsr
.regs
[SP_REGNUM
] || fsr
.regs
[SP_REGNUM
] == STACK_START
)
337 return (CORE_ADDR
) 0;
339 return fsr
.regs
[SP_REGNUM
];
342 if (!read_memory_unsigned_integer (fsr
.regs
[FP_REGNUM
], 4))
343 return (CORE_ADDR
) 0;
345 return read_memory_unsigned_integer (fsr
.regs
[FP_REGNUM
], 4);
348 static int next_addr
, uses_frame
;
349 static int frame_size
;
352 prologue_find_regs (op
, fsr
, addr
)
354 struct frame_saved_regs
*fsr
;
360 /* add sp,sp,imm -- observed */
361 if ((op
& OP_MASK_ALL_BUT_IMM
) == OP_ADD_SP_IMM
)
363 offset
= EXTRACT_IMM6 (op
);
364 /*next_addr += offset; */
365 frame_size
+= -offset
;
369 /* add r22,sp,imm -- observed */
370 if ((op
& OP_MASK_ALL_BUT_IMM
) == OP_ADD_R22_SP_IMM
)
372 offset
= EXTRACT_IMM6 (op
);
373 next_addr
= (offset
- frame_size
);
377 /* stw Ra, @(fp, offset) -- observed */
378 if ((op
& OP_MASK_OP_AND_RB
) == OP_STW_FP_IMM
)
381 offset
= EXTRACT_IMM6 (op
);
382 fsr
->regs
[n
] = (offset
- frame_size
);
386 /* stw Ra, @(fp, r0) -- observed */
387 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_STW_FP_R0
)
390 fsr
->regs
[n
] = (-frame_size
);
394 /* or fp,0,sp -- observed */
395 if ((op
== OP_OR_FP_R0_SP
) ||
396 (op
== OP_OR_FP_SP_R0
) ||
397 (op
== OP_OR_FP_IMM0_SP
))
404 if ((op
& OP_MASK_OPCODE
) == OP_NOP
)
407 /* stw Ra,@(r22+,r0) -- observed */
408 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_STW_R22P_R0
)
411 fsr
->regs
[n
] = next_addr
;
415 #if 0 /* subsumed in pattern above */
416 /* stw fp,@(r22+,r0) -- observed */
417 if (op
== OP_STW_FP_R22P_R0
)
419 fsr
->regs
[FP_REGNUM
] = next_addr
; /* XXX */
424 /* stw r62,@(r22+,r0) -- observed */
425 if (op
== OP_STW_LR_R22P_R0
)
427 fsr
->regs
[LR_REGNUM
] = next_addr
;
432 /* st2w Ra,@(r22+,r0) -- observed */
433 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_ST2W_R22P_R0
)
436 fsr
->regs
[n
] = next_addr
;
437 fsr
->regs
[n
+ 1] = next_addr
+ 4;
443 if ((op
& OP_MASK_ALL_BUT_RA
) == OP_STW_SPM
)
446 fsr
->regs
[n
] = next_addr
;
451 /* st2w Ra, @(sp-) */
452 else if ((op
& OP_MASK_ALL_BUT_RA
) == OP_ST2W_SPM
)
455 fsr
->regs
[n
] = next_addr
;
456 fsr
->regs
[n
+ 1] = next_addr
+ 4;
462 if ((op
& OP_MASK_ALL_BUT_IMM
) == OP_SUB_SP_IMM
)
464 offset
= EXTRACT_IMM6 (op
);
465 frame_size
+= -offset
;
469 /* st rn, @(sp,0) -- observed */
470 if (((op
& OP_MASK_ALL_BUT_RA
) == OP_STW_SP_R0
) ||
471 ((op
& OP_MASK_ALL_BUT_RA
) == OP_STW_SP_IMM0
))
474 fsr
->regs
[n
] = (-frame_size
);
478 /* st2w rn, @(sp,0) */
479 if (((op
& OP_MASK_ALL_BUT_RA
) == OP_ST2W_SP_R0
) ||
480 ((op
& OP_MASK_ALL_BUT_RA
) == OP_ST2W_SP_IMM0
))
483 fsr
->regs
[n
] = (-frame_size
);
484 fsr
->regs
[n
+ 1] = (-frame_size
) + 4;
488 /* stw fp,@(sp,imm) -- observed */
489 if ((op
& OP_MASK_ALL_BUT_IMM
) == OP_STW_FP_SP_IMM
)
491 offset
= EXTRACT_IMM6 (op
);
492 fsr
->regs
[FP_REGNUM
] = (offset
- frame_size
);
498 /* Put here the code to store, into a struct frame_saved_regs, the
499 addresses of the saved registers of frame described by FRAME_INFO.
500 This includes special registers such as pc and fp saved in special
501 ways in the stack frame. sp is even more special: the address we
502 return for it IS the sp for the next frame. */
504 d30v_frame_find_saved_regs (fi
, fsr
)
505 struct frame_info
*fi
;
506 struct frame_saved_regs
*fsr
;
509 unsigned long opl
, opr
;
510 unsigned long op1
, op2
;
511 unsigned long fm0
, fm1
;
515 memset (fsr
, 0, sizeof (*fsr
));
522 d30v_frame_find_saved_regs_offsets (fi
, fsr
);
524 fi
->size
= frame_size
;
527 fp
= read_register (SP_REGNUM
);
529 for (i
= 0; i
< NUM_REGS
- 1; i
++)
532 fsr
->regs
[i
] = fsr
->regs
[i
] + fp
+ frame_size
;
535 if (fsr
->regs
[LR_REGNUM
])
536 fi
->return_pc
= read_memory_unsigned_integer (fsr
->regs
[LR_REGNUM
], 4);
538 fi
->return_pc
= read_register (LR_REGNUM
);
540 /* the SP is not normally (ever?) saved, but check anyway */
541 if (!fsr
->regs
[SP_REGNUM
])
543 /* if the FP was saved, that means the current FP is valid, */
544 /* otherwise, it isn't being used, so we use the SP instead */
546 fsr
->regs
[SP_REGNUM
] = read_register (FP_REGNUM
) + fi
->size
;
549 fsr
->regs
[SP_REGNUM
] = fp
+ fi
->size
;
551 fsr
->regs
[FP_REGNUM
] = 0;
557 d30v_frame_find_saved_regs_offsets (fi
, fsr
)
558 struct frame_info
*fi
;
559 struct frame_saved_regs
*fsr
;
562 unsigned long opl
, opr
;
563 unsigned long op1
, op2
;
564 unsigned long fm0
, fm1
;
568 memset (fsr
, 0, sizeof (*fsr
));
573 pc
= get_pc_function_start (fi
->pc
);
578 opl
= (unsigned long) read_memory_integer (pc
, 4);
579 opr
= (unsigned long) read_memory_integer (pc
+ 4, 4);
581 fm0
= (opl
& OP_MASK_FM_BIT
);
582 fm1
= (opr
& OP_MASK_FM_BIT
);
584 opl
= (opl
& OP_MASK_SUB_INST
);
585 opr
= (opr
& OP_MASK_SUB_INST
);
589 /* long instruction */
590 if ((opl
& OP_MASK_ALL_BUT_IMM
) == OP_ADD_SP_IMM
)
593 long offset
= EXTRACT_IMM32 (opl
, opr
);
594 frame_size
+= -offset
;
596 else if ((opl
& OP_MASK_ALL_BUT_IMM
) == OP_ADD_R22_SP_IMM
)
598 /* add r22,sp,offset */
599 long offset
= EXTRACT_IMM32 (opl
, opr
);
600 next_addr
= (offset
- frame_size
);
602 else if ((opl
& OP_MASK_OP_AND_RB
) == OP_STW_SP_IMM
)
604 /* st Ra, @(sp,imm) */
605 long offset
= EXTRACT_IMM32 (opl
, opr
);
606 short n
= EXTRACT_RA (opl
);
607 fsr
->regs
[n
] = (offset
- frame_size
);
609 else if ((opl
& OP_MASK_OP_AND_RB
) == OP_ST2W_SP_IMM
)
611 /* st2w Ra, @(sp,offset) */
612 long offset
= EXTRACT_IMM32 (opl
, opr
);
613 short n
= EXTRACT_RA (opl
);
614 fsr
->regs
[n
] = (offset
- frame_size
);
615 fsr
->regs
[n
+ 1] = (offset
- frame_size
) + 4;
617 else if ((opl
& OP_MASK_ALL_BUT_IMM
) == OP_OR_SP_R0_IMM
)
626 /* short instructions */
637 if (!prologue_find_regs (op1
, fsr
, pc
) || !prologue_find_regs (op2
, fsr
, pc
))
644 fi
->size
= frame_size
;
647 fp
= read_register (SP_REGNUM
);
649 for (i
= 0; i
< NUM_REGS
- 1; i
++)
652 fsr
->regs
[i
] = fsr
->regs
[i
] + fp
+ frame_size
;
655 if (fsr
->regs
[LR_REGNUM
])
656 fi
->return_pc
= read_memory_unsigned_integer (fsr
->regs
[LR_REGNUM
], 4);
658 fi
->return_pc
= read_register (LR_REGNUM
);
660 /* the SP is not normally (ever?) saved, but check anyway */
661 if (!fsr
->regs
[SP_REGNUM
])
663 /* if the FP was saved, that means the current FP is valid, */
664 /* otherwise, it isn't being used, so we use the SP instead */
666 fsr
->regs
[SP_REGNUM
] = read_register (FP_REGNUM
) + fi
->size
;
669 fsr
->regs
[SP_REGNUM
] = fp
+ fi
->size
;
671 fsr
->regs
[FP_REGNUM
] = 0;
678 d30v_init_extra_frame_info (fromleaf
, fi
)
680 struct frame_info
*fi
;
682 struct frame_saved_regs dummy
;
684 if (fi
->next
&& (fi
->pc
== 0))
685 fi
->pc
= fi
->next
->return_pc
;
687 d30v_frame_find_saved_regs_offsets (fi
, &dummy
);
694 if ((fi
->next
== 0) && (uses_frame
== 0))
695 /* innermost frame and it's "frameless",
696 so the fi->frame field is wrong, fix it! */
697 fi
->frame
= read_sp ();
699 if (dummy
.regs
[LR_REGNUM
])
701 /* it was saved, grab it! */
702 dummy
.regs
[LR_REGNUM
] += (fi
->frame
+ frame_size
);
703 fi
->return_pc
= read_memory_unsigned_integer (dummy
.regs
[LR_REGNUM
], 4);
706 fi
->return_pc
= read_register (LR_REGNUM
);
710 d30v_init_frame_pc (fromleaf
, prev
)
712 struct frame_info
*prev
;
714 /* default value, put here so we can breakpoint on it and
715 see if the default value is really the right thing to use */
716 prev
->pc
= (fromleaf
? SAVED_PC_AFTER_CALL (prev
->next
) : \
717 prev
->next
? FRAME_SAVED_PC (prev
->next
) : read_pc ());
720 static void d30v_print_register
PARAMS ((int regnum
, int tabular
));
723 d30v_print_register (regnum
, tabular
)
727 if (regnum
< A0_REGNUM
)
730 printf_filtered ("%08x", read_register (regnum
));
732 printf_filtered ("0x%x %d", read_register (regnum
),
733 read_register (regnum
));
737 char regbuf
[MAX_REGISTER_RAW_SIZE
];
739 read_relative_register_raw_bytes (regnum
, regbuf
);
741 val_print (REGISTER_VIRTUAL_TYPE (regnum
), regbuf
, 0, 0,
742 gdb_stdout
, 'x', 1, 0, Val_pretty_default
);
746 printf_filtered (" ");
747 val_print (REGISTER_VIRTUAL_TYPE (regnum
), regbuf
, 0, 0,
748 gdb_stdout
, 'd', 1, 0, Val_pretty_default
);
756 long psw
= read_register (PSW_REGNUM
);
757 printf_filtered ("flags #1");
758 printf_filtered (" (sm) %d", (psw
& PSW_SM
) != 0);
759 printf_filtered (" (ea) %d", (psw
& PSW_EA
) != 0);
760 printf_filtered (" (db) %d", (psw
& PSW_DB
) != 0);
761 printf_filtered (" (ds) %d", (psw
& PSW_DS
) != 0);
762 printf_filtered (" (ie) %d", (psw
& PSW_IE
) != 0);
763 printf_filtered (" (rp) %d", (psw
& PSW_RP
) != 0);
764 printf_filtered (" (md) %d\n", (psw
& PSW_MD
) != 0);
766 printf_filtered ("flags #2");
767 printf_filtered (" (f0) %d", (psw
& PSW_F0
) != 0);
768 printf_filtered (" (f1) %d", (psw
& PSW_F1
) != 0);
769 printf_filtered (" (f2) %d", (psw
& PSW_F2
) != 0);
770 printf_filtered (" (f3) %d", (psw
& PSW_F3
) != 0);
771 printf_filtered (" (s) %d", (psw
& PSW_S
) != 0);
772 printf_filtered (" (v) %d", (psw
& PSW_V
) != 0);
773 printf_filtered (" (va) %d", (psw
& PSW_VA
) != 0);
774 printf_filtered (" (c) %d\n", (psw
& PSW_C
) != 0);
778 print_flags_command (args
, from_tty
)
786 d30v_do_registers_info (regnum
, fpregs
)
790 long long num1
, num2
;
795 if (REGISTER_NAME (0) == NULL
|| REGISTER_NAME (0)[0] == '\000')
798 printf_filtered ("%s ", REGISTER_NAME (regnum
));
799 d30v_print_register (regnum
, 0);
801 printf_filtered ("\n");
805 /* Have to print all the registers. Format them nicely. */
807 printf_filtered ("PC=");
808 print_address (read_pc (), gdb_stdout
);
810 printf_filtered (" PSW=");
811 d30v_print_register (PSW_REGNUM
, 1);
813 printf_filtered (" BPC=");
814 print_address (read_register (BPC_REGNUM
), gdb_stdout
);
816 printf_filtered (" BPSW=");
817 d30v_print_register (BPSW_REGNUM
, 1);
818 printf_filtered ("\n");
820 printf_filtered ("DPC=");
821 print_address (read_register (DPC_REGNUM
), gdb_stdout
);
823 printf_filtered (" DPSW=");
824 d30v_print_register (DPSW_REGNUM
, 1);
826 printf_filtered (" IBA=");
827 print_address (read_register (IBA_REGNUM
), gdb_stdout
);
828 printf_filtered ("\n");
830 printf_filtered ("RPT_C=");
831 d30v_print_register (RPT_C_REGNUM
, 1);
833 printf_filtered (" RPT_S=");
834 print_address (read_register (RPT_S_REGNUM
), gdb_stdout
);
836 printf_filtered (" RPT_E=");
837 print_address (read_register (RPT_E_REGNUM
), gdb_stdout
);
838 printf_filtered ("\n");
840 printf_filtered ("MOD_S=");
841 print_address (read_register (MOD_S_REGNUM
), gdb_stdout
);
843 printf_filtered (" MOD_E=");
844 print_address (read_register (MOD_E_REGNUM
), gdb_stdout
);
845 printf_filtered ("\n");
847 printf_filtered ("EIT_VB=");
848 print_address (read_register (EIT_VB_REGNUM
), gdb_stdout
);
850 printf_filtered (" INT_S=");
851 d30v_print_register (INT_S_REGNUM
, 1);
853 printf_filtered (" INT_M=");
854 d30v_print_register (INT_M_REGNUM
, 1);
855 printf_filtered ("\n");
858 for (regnum
= 0; regnum
<= 63;)
862 printf_filtered ("R%d-R%d ", regnum
, regnum
+ 7);
864 printf_filtered (" ");
866 printf_filtered (" ");
868 for (i
= 0; i
< 8; i
++)
870 printf_filtered (" ");
871 d30v_print_register (regnum
++, 1);
874 printf_filtered ("\n");
877 printf_filtered ("A0-A1 ");
879 d30v_print_register (A0_REGNUM
, 1);
880 printf_filtered (" ");
881 d30v_print_register (A1_REGNUM
, 1);
882 printf_filtered ("\n");
886 d30v_fix_call_dummy (dummyname
, start_sp
, fun
, nargs
, args
, type
, gcc_p
)
897 char buffer
[MAX_REGISTER_RAW_SIZE
];
898 struct frame_info
*frame
= get_current_frame ();
899 frame
->dummy
= start_sp
;
900 /*start_sp |= DMEM_START; */
903 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
905 sp
-= REGISTER_RAW_SIZE (regnum
);
906 store_address (buffer
, REGISTER_RAW_SIZE (regnum
), read_register (regnum
));
907 write_memory (sp
, buffer
, REGISTER_RAW_SIZE (regnum
));
909 write_register (SP_REGNUM
, (LONGEST
) sp
);
910 /* now we need to load LR with the return address */
911 write_register (LR_REGNUM
, (LONGEST
) d30v_call_dummy_address ());
916 d30v_pop_dummy_frame (fi
)
917 struct frame_info
*fi
;
919 CORE_ADDR sp
= fi
->dummy
;
922 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
924 sp
-= REGISTER_RAW_SIZE (regnum
);
925 write_register (regnum
, read_memory_unsigned_integer (sp
, REGISTER_RAW_SIZE (regnum
)));
927 flush_cached_frames (); /* needed? */
932 d30v_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
937 CORE_ADDR struct_addr
;
939 int i
, len
, index
= 0, regnum
= 2;
940 char buffer
[4], *contents
;
945 /* Pass 1. Put all large args on stack */
946 for (i
= 0; i
< nargs
; i
++)
948 value_ptr arg
= args
[i
];
949 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
950 len
= TYPE_LENGTH (arg_type
);
951 contents
= VALUE_CONTENTS (arg
);
952 val
= extract_signed_integer (contents
, len
);
955 /* put on stack and pass pointers */
957 write_memory (sp
, contents
, len
);
964 for (i
= 0; i
< nargs
; i
++)
966 value_ptr arg
= args
[i
];
967 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
968 len
= TYPE_LENGTH (arg_type
);
969 contents
= VALUE_CONTENTS (arg
);
972 /* we need multiple registers */
975 for (ndx
= 0; len
> 0; ndx
+= 8, len
-= 8)
978 regnum
++; /* all args > 4 bytes start in even register */
982 val
= extract_signed_integer (&contents
[ndx
], 4);
983 write_register (regnum
++, val
);
986 val
= extract_signed_integer (&contents
[ndx
+ 4], 4);
988 val
= extract_signed_integer (&contents
[ndx
+ 4], len
- 4);
989 write_register (regnum
++, val
);
993 /* no more registers available. put it on the stack */
995 /* all args > 4 bytes are padded to a multiple of 8 bytes
996 and start on an 8 byte boundary */
998 sp
-= (sp
& 7); /* align it */
1000 sp
-= ((len
+ 7) & ~7); /* allocate space */
1001 write_memory (sp
, &contents
[ndx
], len
);
1010 val
= extract_signed_integer (contents
, len
);
1011 write_register (regnum
++, val
);
1015 /* all args are padded to a multiple of 4 bytes (at least) */
1016 sp
-= ((len
+ 3) & ~3);
1017 write_memory (sp
, contents
, len
);
1022 /* stack pointer is not on an 8 byte boundary -- align it */
1028 /* pick an out-of-the-way place to set the return value */
1029 /* for an inferior function call. The link register is set to this */
1030 /* value and a momentary breakpoint is set there. When the breakpoint */
1031 /* is hit, the dummy frame is popped and the previous environment is */
1035 d30v_call_dummy_address ()
1038 struct minimal_symbol
*sym
;
1040 entry
= entry_point_address ();
1045 sym
= lookup_minimal_symbol ("_start", NULL
, symfile_objfile
);
1047 if (!sym
|| MSYMBOL_TYPE (sym
) != mst_text
)
1050 return SYMBOL_VALUE_ADDRESS (sym
);
1053 /* Given a return value in `regbuf' with a type `valtype',
1054 extract and copy its value into `valbuf'. */
1057 d30v_extract_return_value (valtype
, regbuf
, valbuf
)
1058 struct type
*valtype
;
1059 char regbuf
[REGISTER_BYTES
];
1062 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (2), TYPE_LENGTH (valtype
));
1065 /* The following code implements access to, and display of, the D30V's
1066 instruction trace buffer. The buffer consists of 64K or more
1067 4-byte words of data, of which each words includes an 8-bit count,
1068 an 8-bit segment number, and a 16-bit instruction address.
1070 In theory, the trace buffer is continuously capturing instruction
1071 data that the CPU presents on its "debug bus", but in practice, the
1072 ROMified GDB stub only enables tracing when it continues or steps
1073 the program, and stops tracing when the program stops; so it
1074 actually works for GDB to read the buffer counter out of memory and
1075 then read each trace word. The counter records where the tracing
1076 stops, but there is no record of where it started, so we remember
1077 the PC when we resumed and then search backwards in the trace
1078 buffer for a word that includes that address. This is not perfect,
1079 because you will miss trace data if the resumption PC is the target
1080 of a branch. (The value of the buffer counter is semi-random, any
1081 trace data from a previous program stop is gone.) */
1083 /* The address of the last word recorded in the trace buffer. */
1085 #define DBBC_ADDR (0xd80000)
1087 /* The base of the trace buffer, at least for the "Board_0". */
1089 #define TRACE_BUFFER_BASE (0xf40000)
1091 static void trace_command
PARAMS ((char *, int));
1093 static void untrace_command
PARAMS ((char *, int));
1095 static void trace_info
PARAMS ((char *, int));
1097 static void tdisassemble_command
PARAMS ((char *, int));
1099 static void display_trace
PARAMS ((int, int));
1101 /* True when instruction traces are being collected. */
1105 /* Remembered PC. */
1107 static CORE_ADDR last_pc
;
1109 /* True when trace output should be displayed whenever program stops. */
1111 static int trace_display
;
1113 /* True when trace listing should include source lines. */
1115 static int default_trace_show_source
= 1;
1126 trace_command (args
, from_tty
)
1130 /* Clear the host-side trace buffer, allocating space if needed. */
1131 trace_data
.size
= 0;
1132 if (trace_data
.counts
== NULL
)
1133 trace_data
.counts
= (short *) xmalloc (65536 * sizeof (short));
1134 if (trace_data
.addrs
== NULL
)
1135 trace_data
.addrs
= (CORE_ADDR
*) xmalloc (65536 * sizeof (CORE_ADDR
));
1139 printf_filtered ("Tracing is now on.\n");
1143 untrace_command (args
, from_tty
)
1149 printf_filtered ("Tracing is now off.\n");
1153 trace_info (args
, from_tty
)
1159 if (trace_data
.size
)
1161 printf_filtered ("%d entries in trace buffer:\n", trace_data
.size
);
1163 for (i
= 0; i
< trace_data
.size
; ++i
)
1165 printf_filtered ("%d: %d instruction%s at 0x%x\n",
1166 i
, trace_data
.counts
[i
],
1167 (trace_data
.counts
[i
] == 1 ? "" : "s"),
1168 trace_data
.addrs
[i
]);
1172 printf_filtered ("No entries in trace buffer.\n");
1174 printf_filtered ("Tracing is currently %s.\n", (tracing
? "on" : "off"));
1177 /* Print the instruction at address MEMADDR in debugged memory,
1178 on STREAM. Returns length of the instruction, in bytes. */
1181 print_insn (memaddr
, stream
)
1185 /* If there's no disassembler, something is very wrong. */
1186 if (tm_print_insn
== NULL
)
1189 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
1190 tm_print_insn_info
.endian
= BFD_ENDIAN_BIG
;
1192 tm_print_insn_info
.endian
= BFD_ENDIAN_LITTLE
;
1193 return (*tm_print_insn
) (memaddr
, &tm_print_insn_info
);
1197 d30v_eva_prepare_to_trace ()
1202 last_pc
= read_register (PC_REGNUM
);
1205 /* Collect trace data from the target board and format it into a form
1206 more useful for display. */
1209 d30v_eva_get_trace_data ()
1211 int count
, i
, j
, oldsize
;
1212 int trace_addr
, trace_seg
, trace_cnt
, next_cnt
;
1213 unsigned int last_trace
, trace_word
, next_word
;
1214 unsigned int *tmpspace
;
1219 tmpspace
= xmalloc (65536 * sizeof (unsigned int));
1221 last_trace
= read_memory_unsigned_integer (DBBC_ADDR
, 2) << 2;
1223 /* Collect buffer contents from the target, stopping when we reach
1224 the word recorded when execution resumed. */
1227 while (last_trace
> 0)
1231 read_memory_unsigned_integer (TRACE_BUFFER_BASE
+ last_trace
, 4);
1232 trace_addr
= trace_word
& 0xffff;
1234 /* Ignore an apparently nonsensical entry. */
1235 if (trace_addr
== 0xffd5)
1237 tmpspace
[count
++] = trace_word
;
1238 if (trace_addr
== last_pc
)
1244 /* Move the data to the host-side trace buffer, adjusting counts to
1245 include the last instruction executed and transforming the address
1246 into something that GDB likes. */
1248 for (i
= 0; i
< count
; ++i
)
1250 trace_word
= tmpspace
[i
];
1251 next_word
= ((i
== 0) ? 0 : tmpspace
[i
- 1]);
1252 trace_addr
= trace_word
& 0xffff;
1253 next_cnt
= (next_word
>> 24) & 0xff;
1254 j
= trace_data
.size
+ count
- i
- 1;
1255 trace_data
.addrs
[j
] = (trace_addr
<< 2) + 0x1000000;
1256 trace_data
.counts
[j
] = next_cnt
+ 1;
1259 oldsize
= trace_data
.size
;
1260 trace_data
.size
+= count
;
1265 display_trace (oldsize
, trace_data
.size
);
1269 tdisassemble_command (arg
, from_tty
)
1274 CORE_ADDR low
, high
;
1280 high
= trace_data
.size
;
1282 else if (!(space_index
= (char *) strchr (arg
, ' ')))
1284 low
= parse_and_eval_address (arg
);
1289 /* Two arguments. */
1290 *space_index
= '\0';
1291 low
= parse_and_eval_address (arg
);
1292 high
= parse_and_eval_address (space_index
+ 1);
1297 printf_filtered ("Dump of trace from %d to %d:\n", low
, high
);
1299 display_trace (low
, high
);
1301 printf_filtered ("End of trace dump.\n");
1302 gdb_flush (gdb_stdout
);
1306 display_trace (low
, high
)
1309 int i
, count
, trace_show_source
, first
, suppress
;
1310 CORE_ADDR next_address
;
1312 trace_show_source
= default_trace_show_source
;
1313 if (!have_full_symbols () && !have_partial_symbols ())
1315 trace_show_source
= 0;
1316 printf_filtered ("No symbol table is loaded. Use the \"file\" command.\n");
1317 printf_filtered ("Trace will not display any source.\n");
1322 for (i
= low
; i
< high
; ++i
)
1324 next_address
= trace_data
.addrs
[i
];
1325 count
= trace_data
.counts
[i
];
1329 if (trace_show_source
)
1331 struct symtab_and_line sal
, sal_prev
;
1333 sal_prev
= find_pc_line (next_address
- 4, 0);
1334 sal
= find_pc_line (next_address
, 0);
1338 if (first
|| sal
.line
!= sal_prev
.line
)
1339 print_source_lines (sal
.symtab
, sal
.line
, sal
.line
+ 1, 0);
1345 /* FIXME-32x64--assumes sal.pc fits in long. */
1346 printf_filtered ("No source file for address %s.\n",
1347 local_hex_string ((unsigned long) sal
.pc
));
1352 print_address (next_address
, gdb_stdout
);
1353 printf_filtered (":");
1354 printf_filtered ("\t");
1356 next_address
= next_address
+ print_insn (next_address
, gdb_stdout
);
1357 printf_filtered ("\n");
1358 gdb_flush (gdb_stdout
);
1363 extern void (*target_resume_hook
) PARAMS ((void));
1364 extern void (*target_wait_loop_hook
) PARAMS ((void));
1367 _initialize_d30v_tdep ()
1369 tm_print_insn
= print_insn_d30v
;
1371 target_resume_hook
= d30v_eva_prepare_to_trace
;
1372 target_wait_loop_hook
= d30v_eva_get_trace_data
;
1374 add_info ("flags", print_flags_command
, "Print d30v flags.");
1376 add_com ("trace", class_support
, trace_command
,
1377 "Enable tracing of instruction execution.");
1379 add_com ("untrace", class_support
, untrace_command
,
1380 "Disable tracing of instruction execution.");
1382 add_com ("tdisassemble", class_vars
, tdisassemble_command
,
1383 "Disassemble the trace buffer.\n\
1384 Two optional arguments specify a range of trace buffer entries\n\
1385 as reported by info trace (NOT addresses!).");
1387 add_info ("trace", trace_info
,
1388 "Display info about the trace data buffer.");
1390 add_show_from_set (add_set_cmd ("tracedisplay", no_class
,
1391 var_integer
, (char *) &trace_display
,
1392 "Set automatic display of trace.\n", &setlist
),
1394 add_show_from_set (add_set_cmd ("tracesource", no_class
,
1395 var_integer
, (char *) &default_trace_show_source
,
1396 "Set display of source code with trace.\n", &setlist
),