Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Target-dependent code for Mitsubishi D10V, for GDB. |
2 | Copyright (C) 1996, 1997 Free Software Foundation, Inc. | |
3 | ||
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
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. | |
c906108c | 10 | |
c5aa993b JM |
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. | |
c906108c | 15 | |
c5aa993b JM |
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. */ | |
c906108c SS |
20 | |
21 | /* Contributed by Martin Hunt, hunt@cygnus.com */ | |
22 | ||
23 | #include "defs.h" | |
24 | #include "frame.h" | |
25 | #include "obstack.h" | |
26 | #include "symtab.h" | |
27 | #include "gdbtypes.h" | |
28 | #include "gdbcmd.h" | |
29 | #include "gdbcore.h" | |
30 | #include "gdb_string.h" | |
31 | #include "value.h" | |
32 | #include "inferior.h" | |
c5aa993b | 33 | #include "dis-asm.h" |
c906108c SS |
34 | #include "symfile.h" |
35 | #include "objfiles.h" | |
104c1213 | 36 | #include "language.h" |
c906108c | 37 | |
cce74817 | 38 | struct frame_extra_info |
c5aa993b JM |
39 | { |
40 | CORE_ADDR return_pc; | |
41 | int frameless; | |
42 | int size; | |
43 | }; | |
cce74817 JM |
44 | |
45 | /* these are the addresses the D10V-EVA board maps data */ | |
46 | /* and instruction memory to. */ | |
47 | ||
cff3e48b | 48 | #define DMEM_START 0x2000000 |
cce74817 JM |
49 | #define IMEM_START 0x1000000 |
50 | #define STACK_START 0x0007ffe | |
51 | ||
52 | /* d10v register naming conventions */ | |
53 | ||
54 | #define ARG1_REGNUM R0_REGNUM | |
55 | #define ARGN_REGNUM 3 | |
56 | #define RET1_REGNUM R0_REGNUM | |
57 | ||
392a587b JM |
58 | /* Local functions */ |
59 | ||
60 | extern void _initialize_d10v_tdep PARAMS ((void)); | |
61 | ||
62 | static void d10v_eva_prepare_to_trace PARAMS ((void)); | |
63 | ||
64 | static void d10v_eva_get_trace_data PARAMS ((void)); | |
c906108c | 65 | |
c5aa993b | 66 | static int prologue_find_regs PARAMS ((unsigned short op, struct frame_info * fi, CORE_ADDR addr)); |
cce74817 JM |
67 | |
68 | extern void d10v_frame_init_saved_regs PARAMS ((struct frame_info *)); | |
69 | ||
c5aa993b | 70 | static void do_d10v_pop_frame PARAMS ((struct frame_info * fi)); |
cce74817 JM |
71 | |
72 | /* FIXME */ | |
c5aa993b | 73 | extern void remote_d10v_translate_xfer_address PARAMS ((CORE_ADDR gdb_addr, int gdb_len, CORE_ADDR * rem_addr, int *rem_len)); |
cce74817 | 74 | |
c906108c SS |
75 | int |
76 | d10v_frame_chain_valid (chain, frame) | |
77 | CORE_ADDR chain; | |
c5aa993b | 78 | struct frame_info *frame; /* not used here */ |
c906108c SS |
79 | { |
80 | return ((chain) != 0 && (frame) != 0 && (frame)->pc > IMEM_START); | |
81 | } | |
82 | ||
83 | ||
84 | /* Should we use EXTRACT_STRUCT_VALUE_ADDRESS instead of | |
85 | EXTRACT_RETURN_VALUE? GCC_P is true if compiled with gcc | |
86 | and TYPE is the type (which is known to be struct, union or array). | |
87 | ||
88 | The d10v returns anything less than 8 bytes in size in | |
89 | registers. */ | |
90 | ||
91 | int | |
92 | d10v_use_struct_convention (gcc_p, type) | |
93 | int gcc_p; | |
94 | struct type *type; | |
95 | { | |
96 | return (TYPE_LENGTH (type) > 8); | |
97 | } | |
98 | ||
99 | ||
392a587b JM |
100 | unsigned char * |
101 | d10v_breakpoint_from_pc (pcptr, lenptr) | |
102 | CORE_ADDR *pcptr; | |
103 | int *lenptr; | |
104 | { | |
c5aa993b JM |
105 | static unsigned char breakpoint[] = |
106 | {0x2f, 0x90, 0x5e, 0x00}; | |
392a587b JM |
107 | *lenptr = sizeof (breakpoint); |
108 | return breakpoint; | |
109 | } | |
110 | ||
111 | char * | |
112 | d10v_register_name (reg_nr) | |
113 | int reg_nr; | |
114 | { | |
c5aa993b JM |
115 | static char *register_names[] = |
116 | { | |
117 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
118 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
119 | "psw", "bpsw", "pc", "bpc", "cr4", "cr5", "cr6", "rpt_c", | |
120 | "rpt_s", "rpt_e", "mod_s", "mod_e", "cr12", "cr13", "iba", "cr15", | |
121 | "imap0", "imap1", "dmap", "a0", "a1" | |
392a587b JM |
122 | }; |
123 | if (reg_nr < 0) | |
124 | return NULL; | |
125 | if (reg_nr >= (sizeof (register_names) / sizeof (*register_names))) | |
126 | return NULL; | |
c5aa993b | 127 | return register_names[reg_nr]; |
392a587b JM |
128 | } |
129 | ||
130 | ||
131 | /* Index within `registers' of the first byte of the space for | |
132 | register REG_NR. */ | |
133 | ||
134 | int | |
135 | d10v_register_byte (reg_nr) | |
136 | int reg_nr; | |
137 | { | |
138 | if (reg_nr > A0_REGNUM) | |
139 | return ((reg_nr - A0_REGNUM) * 8 + (A0_REGNUM * 2)); | |
140 | else | |
141 | return (reg_nr * 2); | |
142 | } | |
143 | ||
144 | /* Number of bytes of storage in the actual machine representation for | |
145 | register REG_NR. */ | |
146 | ||
147 | int | |
148 | d10v_register_raw_size (reg_nr) | |
149 | int reg_nr; | |
150 | { | |
151 | if (reg_nr >= A0_REGNUM) | |
152 | return 8; | |
153 | else | |
154 | return 2; | |
155 | } | |
156 | ||
157 | /* Number of bytes of storage in the program's representation | |
158 | for register N. */ | |
159 | ||
160 | int | |
161 | d10v_register_virtual_size (reg_nr) | |
162 | int reg_nr; | |
163 | { | |
164 | if (reg_nr >= A0_REGNUM) | |
165 | return 8; | |
166 | else if (reg_nr == PC_REGNUM || reg_nr == SP_REGNUM) | |
167 | return 4; | |
168 | else | |
169 | return 2; | |
170 | } | |
171 | ||
172 | /* Return the GDB type object for the "standard" data type | |
173 | of data in register N. */ | |
174 | ||
175 | struct type * | |
176 | d10v_register_virtual_type (reg_nr) | |
177 | int reg_nr; | |
178 | { | |
179 | if (reg_nr >= A0_REGNUM) | |
180 | return builtin_type_long_long; | |
181 | else if (reg_nr == PC_REGNUM || reg_nr == SP_REGNUM) | |
182 | return builtin_type_long; | |
183 | else | |
184 | return builtin_type_short; | |
185 | } | |
186 | ||
392a587b | 187 | /* convert $pc and $sp to/from virtual addresses */ |
ac9a91a7 JM |
188 | int |
189 | d10v_register_convertible (nr) | |
190 | int nr; | |
191 | { | |
192 | return ((nr) == PC_REGNUM || (nr) == SP_REGNUM); | |
193 | } | |
194 | ||
195 | void | |
196 | d10v_register_convert_to_virtual (regnum, type, from, to) | |
197 | int regnum; | |
198 | struct type *type; | |
199 | char *from; | |
200 | char *to; | |
201 | { | |
202 | ULONGEST x = extract_unsigned_integer (from, REGISTER_RAW_SIZE (regnum)); | |
203 | if (regnum == PC_REGNUM) | |
204 | x = (x << 2) | IMEM_START; | |
205 | else | |
206 | x |= DMEM_START; | |
207 | store_unsigned_integer (to, TYPE_LENGTH (type), x); | |
392a587b | 208 | } |
ac9a91a7 JM |
209 | |
210 | void | |
211 | d10v_register_convert_to_raw (type, regnum, from, to) | |
212 | struct type *type; | |
213 | int regnum; | |
214 | char *from; | |
215 | char *to; | |
216 | { | |
217 | ULONGEST x = extract_unsigned_integer (from, TYPE_LENGTH (type)); | |
218 | x &= 0x3ffff; | |
219 | if (regnum == PC_REGNUM) | |
220 | x >>= 2; | |
221 | store_unsigned_integer (to, 2, x); | |
392a587b | 222 | } |
ac9a91a7 | 223 | |
392a587b JM |
224 | |
225 | CORE_ADDR | |
226 | d10v_make_daddr (x) | |
227 | CORE_ADDR x; | |
228 | { | |
229 | return ((x) | DMEM_START); | |
230 | } | |
231 | ||
232 | CORE_ADDR | |
233 | d10v_make_iaddr (x) | |
234 | CORE_ADDR x; | |
235 | { | |
236 | return (((x) << 2) | IMEM_START); | |
237 | } | |
238 | ||
239 | int | |
240 | d10v_daddr_p (x) | |
241 | CORE_ADDR x; | |
242 | { | |
243 | return (((x) & 0x3000000) == DMEM_START); | |
244 | } | |
245 | ||
246 | int | |
247 | d10v_iaddr_p (x) | |
248 | CORE_ADDR x; | |
249 | { | |
250 | return (((x) & 0x3000000) == IMEM_START); | |
251 | } | |
252 | ||
253 | ||
254 | CORE_ADDR | |
255 | d10v_convert_iaddr_to_raw (x) | |
256 | CORE_ADDR x; | |
257 | { | |
258 | return (((x) >> 2) & 0xffff); | |
259 | } | |
260 | ||
261 | CORE_ADDR | |
c5aa993b | 262 | d10v_convert_daddr_to_raw (x) |
392a587b JM |
263 | CORE_ADDR x; |
264 | { | |
265 | return ((x) & 0xffff); | |
266 | } | |
267 | ||
268 | /* Store the address of the place in which to copy the structure the | |
269 | subroutine will return. This is called from call_function. | |
270 | ||
271 | We store structs through a pointer passed in the first Argument | |
272 | register. */ | |
273 | ||
274 | void | |
275 | d10v_store_struct_return (addr, sp) | |
276 | CORE_ADDR addr; | |
277 | CORE_ADDR sp; | |
278 | { | |
279 | write_register (ARG1_REGNUM, (addr)); | |
280 | } | |
281 | ||
282 | /* Write into appropriate registers a function return value | |
283 | of type TYPE, given in virtual format. | |
284 | ||
285 | Things always get returned in RET1_REGNUM, RET2_REGNUM, ... */ | |
286 | ||
287 | void | |
c5aa993b | 288 | d10v_store_return_value (type, valbuf) |
392a587b JM |
289 | struct type *type; |
290 | char *valbuf; | |
291 | { | |
292 | write_register_bytes (REGISTER_BYTE (RET1_REGNUM), | |
293 | valbuf, | |
294 | TYPE_LENGTH (type)); | |
295 | } | |
296 | ||
297 | /* Extract from an array REGBUF containing the (raw) register state | |
298 | the address in which a function should return its structure value, | |
299 | as a CORE_ADDR (or an expression that can be used as one). */ | |
300 | ||
301 | CORE_ADDR | |
302 | d10v_extract_struct_value_address (regbuf) | |
303 | char *regbuf; | |
304 | { | |
305 | return (extract_address ((regbuf) + REGISTER_BYTE (ARG1_REGNUM), | |
306 | REGISTER_RAW_SIZE (ARG1_REGNUM)) | |
307 | | DMEM_START); | |
308 | } | |
309 | ||
310 | CORE_ADDR | |
311 | d10v_frame_saved_pc (frame) | |
312 | struct frame_info *frame; | |
313 | { | |
cce74817 | 314 | return ((frame)->extra_info->return_pc); |
392a587b JM |
315 | } |
316 | ||
317 | CORE_ADDR | |
318 | d10v_frame_args_address (fi) | |
319 | struct frame_info *fi; | |
320 | { | |
321 | return (fi)->frame; | |
322 | } | |
323 | ||
324 | CORE_ADDR | |
325 | d10v_frame_locals_address (fi) | |
326 | struct frame_info *fi; | |
327 | { | |
328 | return (fi)->frame; | |
329 | } | |
330 | ||
331 | /* Immediately after a function call, return the saved pc. We can't | |
332 | use frame->return_pc beause that is determined by reading R13 off | |
333 | the stack and that may not be written yet. */ | |
334 | ||
335 | CORE_ADDR | |
336 | d10v_saved_pc_after_call (frame) | |
337 | struct frame_info *frame; | |
338 | { | |
c5aa993b | 339 | return ((read_register (LR_REGNUM) << 2) |
392a587b JM |
340 | | IMEM_START); |
341 | } | |
342 | ||
c906108c SS |
343 | /* Discard from the stack the innermost frame, restoring all saved |
344 | registers. */ | |
345 | ||
346 | void | |
cce74817 JM |
347 | d10v_pop_frame () |
348 | { | |
349 | generic_pop_current_frame (do_d10v_pop_frame); | |
350 | } | |
351 | ||
352 | static void | |
353 | do_d10v_pop_frame (fi) | |
354 | struct frame_info *fi; | |
c906108c SS |
355 | { |
356 | CORE_ADDR fp; | |
357 | int regnum; | |
c906108c SS |
358 | char raw_buffer[8]; |
359 | ||
cce74817 | 360 | fp = FRAME_FP (fi); |
c906108c SS |
361 | /* fill out fsr with the address of where each */ |
362 | /* register was stored in the frame */ | |
cce74817 | 363 | d10v_frame_init_saved_regs (fi); |
c5aa993b | 364 | |
c906108c | 365 | /* now update the current registers with the old values */ |
c5aa993b | 366 | for (regnum = A0_REGNUM; regnum < A0_REGNUM + 2; regnum++) |
c906108c | 367 | { |
cce74817 | 368 | if (fi->saved_regs[regnum]) |
c906108c | 369 | { |
c5aa993b JM |
370 | read_memory (fi->saved_regs[regnum], raw_buffer, REGISTER_RAW_SIZE (regnum)); |
371 | write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, REGISTER_RAW_SIZE (regnum)); | |
c906108c SS |
372 | } |
373 | } | |
374 | for (regnum = 0; regnum < SP_REGNUM; regnum++) | |
375 | { | |
cce74817 | 376 | if (fi->saved_regs[regnum]) |
c906108c | 377 | { |
c5aa993b | 378 | write_register (regnum, read_memory_unsigned_integer (fi->saved_regs[regnum], REGISTER_RAW_SIZE (regnum))); |
c906108c SS |
379 | } |
380 | } | |
cce74817 | 381 | if (fi->saved_regs[PSW_REGNUM]) |
c906108c | 382 | { |
c5aa993b | 383 | write_register (PSW_REGNUM, read_memory_unsigned_integer (fi->saved_regs[PSW_REGNUM], REGISTER_RAW_SIZE (PSW_REGNUM))); |
c906108c SS |
384 | } |
385 | ||
386 | write_register (PC_REGNUM, read_register (LR_REGNUM)); | |
cce74817 | 387 | write_register (SP_REGNUM, fp + fi->extra_info->size); |
c906108c SS |
388 | target_store_registers (-1); |
389 | flush_cached_frames (); | |
390 | } | |
391 | ||
c5aa993b | 392 | static int |
c906108c SS |
393 | check_prologue (op) |
394 | unsigned short op; | |
395 | { | |
396 | /* st rn, @-sp */ | |
397 | if ((op & 0x7E1F) == 0x6C1F) | |
398 | return 1; | |
399 | ||
400 | /* st2w rn, @-sp */ | |
401 | if ((op & 0x7E3F) == 0x6E1F) | |
402 | return 1; | |
403 | ||
404 | /* subi sp, n */ | |
405 | if ((op & 0x7FE1) == 0x01E1) | |
406 | return 1; | |
407 | ||
408 | /* mv r11, sp */ | |
409 | if (op == 0x417E) | |
410 | return 1; | |
411 | ||
412 | /* nop */ | |
413 | if (op == 0x5E00) | |
414 | return 1; | |
415 | ||
416 | /* st rn, @sp */ | |
417 | if ((op & 0x7E1F) == 0x681E) | |
418 | return 1; | |
419 | ||
420 | /* st2w rn, @sp */ | |
c5aa993b JM |
421 | if ((op & 0x7E3F) == 0x3A1E) |
422 | return 1; | |
c906108c SS |
423 | |
424 | return 0; | |
425 | } | |
426 | ||
427 | CORE_ADDR | |
428 | d10v_skip_prologue (pc) | |
429 | CORE_ADDR pc; | |
430 | { | |
431 | unsigned long op; | |
432 | unsigned short op1, op2; | |
433 | CORE_ADDR func_addr, func_end; | |
434 | struct symtab_and_line sal; | |
435 | ||
436 | /* If we have line debugging information, then the end of the */ | |
437 | /* prologue should the first assembly instruction of the first source line */ | |
438 | if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
439 | { | |
440 | sal = find_pc_line (func_addr, 0); | |
c5aa993b | 441 | if (sal.end && sal.end < func_end) |
c906108c SS |
442 | return sal.end; |
443 | } | |
c5aa993b JM |
444 | |
445 | if (target_read_memory (pc, (char *) &op, 4)) | |
c906108c SS |
446 | return pc; /* Can't access it -- assume no prologue. */ |
447 | ||
448 | while (1) | |
449 | { | |
c5aa993b | 450 | op = (unsigned long) read_memory_integer (pc, 4); |
c906108c SS |
451 | if ((op & 0xC0000000) == 0xC0000000) |
452 | { | |
453 | /* long instruction */ | |
c5aa993b JM |
454 | if (((op & 0x3FFF0000) != 0x01FF0000) && /* add3 sp,sp,n */ |
455 | ((op & 0x3F0F0000) != 0x340F0000) && /* st rn, @(offset,sp) */ | |
456 | ((op & 0x3F1F0000) != 0x350F0000)) /* st2w rn, @(offset,sp) */ | |
c906108c SS |
457 | break; |
458 | } | |
459 | else | |
460 | { | |
461 | /* short instructions */ | |
462 | if ((op & 0xC0000000) == 0x80000000) | |
463 | { | |
464 | op2 = (op & 0x3FFF8000) >> 15; | |
465 | op1 = op & 0x7FFF; | |
c5aa993b JM |
466 | } |
467 | else | |
c906108c SS |
468 | { |
469 | op1 = (op & 0x3FFF8000) >> 15; | |
470 | op2 = op & 0x7FFF; | |
471 | } | |
c5aa993b | 472 | if (check_prologue (op1)) |
c906108c | 473 | { |
c5aa993b | 474 | if (!check_prologue (op2)) |
c906108c SS |
475 | { |
476 | /* if the previous opcode was really part of the prologue */ | |
477 | /* and not just a NOP, then we want to break after both instructions */ | |
478 | if (op1 != 0x5E00) | |
479 | pc += 4; | |
480 | break; | |
481 | } | |
482 | } | |
483 | else | |
484 | break; | |
485 | } | |
486 | pc += 4; | |
487 | } | |
488 | return pc; | |
489 | } | |
490 | ||
491 | /* Given a GDB frame, determine the address of the calling function's frame. | |
492 | This will be used to create a new GDB frame struct, and then | |
493 | INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC will be called for the new frame. | |
c5aa993b | 494 | */ |
c906108c SS |
495 | |
496 | CORE_ADDR | |
cce74817 JM |
497 | d10v_frame_chain (fi) |
498 | struct frame_info *fi; | |
c906108c | 499 | { |
cce74817 | 500 | d10v_frame_init_saved_regs (fi); |
c906108c | 501 | |
cce74817 JM |
502 | if (fi->extra_info->return_pc == IMEM_START |
503 | || inside_entry_file (fi->extra_info->return_pc)) | |
c5aa993b | 504 | return (CORE_ADDR) 0; |
c906108c | 505 | |
cce74817 | 506 | if (!fi->saved_regs[FP_REGNUM]) |
c906108c | 507 | { |
cce74817 JM |
508 | if (!fi->saved_regs[SP_REGNUM] |
509 | || fi->saved_regs[SP_REGNUM] == STACK_START) | |
c5aa993b JM |
510 | return (CORE_ADDR) 0; |
511 | ||
cce74817 | 512 | return fi->saved_regs[SP_REGNUM]; |
c906108c SS |
513 | } |
514 | ||
c5aa993b JM |
515 | if (!read_memory_unsigned_integer (fi->saved_regs[FP_REGNUM], |
516 | REGISTER_RAW_SIZE (FP_REGNUM))) | |
517 | return (CORE_ADDR) 0; | |
c906108c | 518 | |
cce74817 | 519 | return D10V_MAKE_DADDR (read_memory_unsigned_integer (fi->saved_regs[FP_REGNUM], |
c5aa993b JM |
520 | REGISTER_RAW_SIZE (FP_REGNUM))); |
521 | } | |
c906108c SS |
522 | |
523 | static int next_addr, uses_frame; | |
524 | ||
c5aa993b | 525 | static int |
cce74817 | 526 | prologue_find_regs (op, fi, addr) |
c906108c | 527 | unsigned short op; |
cce74817 | 528 | struct frame_info *fi; |
c906108c SS |
529 | CORE_ADDR addr; |
530 | { | |
531 | int n; | |
532 | ||
533 | /* st rn, @-sp */ | |
534 | if ((op & 0x7E1F) == 0x6C1F) | |
535 | { | |
536 | n = (op & 0x1E0) >> 5; | |
537 | next_addr -= 2; | |
cce74817 | 538 | fi->saved_regs[n] = next_addr; |
c906108c SS |
539 | return 1; |
540 | } | |
541 | ||
542 | /* st2w rn, @-sp */ | |
543 | else if ((op & 0x7E3F) == 0x6E1F) | |
544 | { | |
545 | n = (op & 0x1E0) >> 5; | |
546 | next_addr -= 4; | |
cce74817 | 547 | fi->saved_regs[n] = next_addr; |
c5aa993b | 548 | fi->saved_regs[n + 1] = next_addr + 2; |
c906108c SS |
549 | return 1; |
550 | } | |
551 | ||
552 | /* subi sp, n */ | |
553 | if ((op & 0x7FE1) == 0x01E1) | |
554 | { | |
555 | n = (op & 0x1E) >> 1; | |
556 | if (n == 0) | |
557 | n = 16; | |
558 | next_addr -= n; | |
559 | return 1; | |
560 | } | |
561 | ||
562 | /* mv r11, sp */ | |
563 | if (op == 0x417E) | |
564 | { | |
565 | uses_frame = 1; | |
566 | return 1; | |
567 | } | |
568 | ||
569 | /* nop */ | |
570 | if (op == 0x5E00) | |
571 | return 1; | |
572 | ||
573 | /* st rn, @sp */ | |
574 | if ((op & 0x7E1F) == 0x681E) | |
575 | { | |
576 | n = (op & 0x1E0) >> 5; | |
cce74817 | 577 | fi->saved_regs[n] = next_addr; |
c906108c SS |
578 | return 1; |
579 | } | |
580 | ||
581 | /* st2w rn, @sp */ | |
582 | if ((op & 0x7E3F) == 0x3A1E) | |
583 | { | |
584 | n = (op & 0x1E0) >> 5; | |
cce74817 | 585 | fi->saved_regs[n] = next_addr; |
c5aa993b | 586 | fi->saved_regs[n + 1] = next_addr + 2; |
c906108c SS |
587 | return 1; |
588 | } | |
589 | ||
590 | return 0; | |
591 | } | |
592 | ||
cce74817 JM |
593 | /* Put here the code to store, into fi->saved_regs, the addresses of |
594 | the saved registers of frame described by FRAME_INFO. This | |
595 | includes special registers such as pc and fp saved in special ways | |
596 | in the stack frame. sp is even more special: the address we return | |
597 | for it IS the sp for the next frame. */ | |
598 | ||
c906108c | 599 | void |
cce74817 | 600 | d10v_frame_init_saved_regs (fi) |
c906108c | 601 | struct frame_info *fi; |
c906108c SS |
602 | { |
603 | CORE_ADDR fp, pc; | |
604 | unsigned long op; | |
605 | unsigned short op1, op2; | |
606 | int i; | |
607 | ||
608 | fp = fi->frame; | |
cce74817 | 609 | memset (fi->saved_regs, 0, SIZEOF_FRAME_SAVED_REGS); |
c906108c SS |
610 | next_addr = 0; |
611 | ||
612 | pc = get_pc_function_start (fi->pc); | |
613 | ||
614 | uses_frame = 0; | |
615 | while (1) | |
616 | { | |
c5aa993b | 617 | op = (unsigned long) read_memory_integer (pc, 4); |
c906108c SS |
618 | if ((op & 0xC0000000) == 0xC0000000) |
619 | { | |
620 | /* long instruction */ | |
621 | if ((op & 0x3FFF0000) == 0x01FF0000) | |
622 | { | |
623 | /* add3 sp,sp,n */ | |
624 | short n = op & 0xFFFF; | |
625 | next_addr += n; | |
626 | } | |
627 | else if ((op & 0x3F0F0000) == 0x340F0000) | |
628 | { | |
629 | /* st rn, @(offset,sp) */ | |
630 | short offset = op & 0xFFFF; | |
631 | short n = (op >> 20) & 0xF; | |
cce74817 | 632 | fi->saved_regs[n] = next_addr + offset; |
c906108c SS |
633 | } |
634 | else if ((op & 0x3F1F0000) == 0x350F0000) | |
635 | { | |
636 | /* st2w rn, @(offset,sp) */ | |
637 | short offset = op & 0xFFFF; | |
638 | short n = (op >> 20) & 0xF; | |
cce74817 | 639 | fi->saved_regs[n] = next_addr + offset; |
c5aa993b | 640 | fi->saved_regs[n + 1] = next_addr + offset + 2; |
c906108c SS |
641 | } |
642 | else | |
643 | break; | |
644 | } | |
645 | else | |
646 | { | |
647 | /* short instructions */ | |
648 | if ((op & 0xC0000000) == 0x80000000) | |
649 | { | |
650 | op2 = (op & 0x3FFF8000) >> 15; | |
651 | op1 = op & 0x7FFF; | |
c5aa993b JM |
652 | } |
653 | else | |
c906108c SS |
654 | { |
655 | op1 = (op & 0x3FFF8000) >> 15; | |
656 | op2 = op & 0x7FFF; | |
657 | } | |
c5aa993b | 658 | if (!prologue_find_regs (op1, fi, pc) || !prologue_find_regs (op2, fi, pc)) |
c906108c SS |
659 | break; |
660 | } | |
661 | pc += 4; | |
662 | } | |
c5aa993b | 663 | |
cce74817 | 664 | fi->extra_info->size = -next_addr; |
c906108c SS |
665 | |
666 | if (!(fp & 0xffff)) | |
c5aa993b | 667 | fp = D10V_MAKE_DADDR (read_register (SP_REGNUM)); |
c906108c | 668 | |
c5aa993b | 669 | for (i = 0; i < NUM_REGS - 1; i++) |
cce74817 | 670 | if (fi->saved_regs[i]) |
c906108c | 671 | { |
c5aa993b | 672 | fi->saved_regs[i] = fp - (next_addr - fi->saved_regs[i]); |
c906108c SS |
673 | } |
674 | ||
cce74817 | 675 | if (fi->saved_regs[LR_REGNUM]) |
c906108c | 676 | { |
cce74817 JM |
677 | CORE_ADDR return_pc = read_memory_unsigned_integer (fi->saved_regs[LR_REGNUM], REGISTER_RAW_SIZE (LR_REGNUM)); |
678 | fi->extra_info->return_pc = D10V_MAKE_IADDR (return_pc); | |
c906108c SS |
679 | } |
680 | else | |
681 | { | |
c5aa993b | 682 | fi->extra_info->return_pc = D10V_MAKE_IADDR (read_register (LR_REGNUM)); |
c906108c | 683 | } |
c5aa993b | 684 | |
c906108c | 685 | /* th SP is not normally (ever?) saved, but check anyway */ |
cce74817 | 686 | if (!fi->saved_regs[SP_REGNUM]) |
c906108c SS |
687 | { |
688 | /* if the FP was saved, that means the current FP is valid, */ | |
689 | /* otherwise, it isn't being used, so we use the SP instead */ | |
690 | if (uses_frame) | |
c5aa993b | 691 | fi->saved_regs[SP_REGNUM] = read_register (FP_REGNUM) + fi->extra_info->size; |
c906108c SS |
692 | else |
693 | { | |
cce74817 JM |
694 | fi->saved_regs[SP_REGNUM] = fp + fi->extra_info->size; |
695 | fi->extra_info->frameless = 1; | |
696 | fi->saved_regs[FP_REGNUM] = 0; | |
c906108c SS |
697 | } |
698 | } | |
699 | } | |
700 | ||
701 | void | |
702 | d10v_init_extra_frame_info (fromleaf, fi) | |
703 | int fromleaf; | |
704 | struct frame_info *fi; | |
705 | { | |
cce74817 JM |
706 | fi->extra_info = (struct frame_extra_info *) |
707 | frame_obstack_alloc (sizeof (struct frame_extra_info)); | |
708 | frame_saved_regs_zalloc (fi); | |
709 | ||
710 | fi->extra_info->frameless = 0; | |
711 | fi->extra_info->size = 0; | |
712 | fi->extra_info->return_pc = 0; | |
c906108c SS |
713 | |
714 | /* The call dummy doesn't save any registers on the stack, so we can | |
715 | return now. */ | |
716 | if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame)) | |
717 | { | |
718 | return; | |
719 | } | |
720 | else | |
721 | { | |
cce74817 | 722 | d10v_frame_init_saved_regs (fi); |
c906108c SS |
723 | } |
724 | } | |
725 | ||
726 | static void | |
727 | show_regs (args, from_tty) | |
728 | char *args; | |
729 | int from_tty; | |
730 | { | |
731 | int a; | |
d4f3574e SS |
732 | printf_filtered ("PC=%04lx (0x%lx) PSW=%04lx RPT_S=%04lx RPT_E=%04lx RPT_C=%04lx\n", |
733 | (long) read_register (PC_REGNUM), | |
734 | (long) D10V_MAKE_IADDR (read_register (PC_REGNUM)), | |
735 | (long) read_register (PSW_REGNUM), | |
736 | (long) read_register (24), | |
737 | (long) read_register (25), | |
738 | (long) read_register (23)); | |
739 | printf_filtered ("R0-R7 %04lx %04lx %04lx %04lx %04lx %04lx %04lx %04lx\n", | |
740 | (long) read_register (0), | |
741 | (long) read_register (1), | |
742 | (long) read_register (2), | |
743 | (long) read_register (3), | |
744 | (long) read_register (4), | |
745 | (long) read_register (5), | |
746 | (long) read_register (6), | |
747 | (long) read_register (7)); | |
748 | printf_filtered ("R8-R15 %04lx %04lx %04lx %04lx %04lx %04lx %04lx %04lx\n", | |
749 | (long) read_register (8), | |
750 | (long) read_register (9), | |
751 | (long) read_register (10), | |
752 | (long) read_register (11), | |
753 | (long) read_register (12), | |
754 | (long) read_register (13), | |
755 | (long) read_register (14), | |
756 | (long) read_register (15)); | |
757 | printf_filtered ("IMAP0 %04lx IMAP1 %04lx DMAP %04lx\n", | |
758 | (long) read_register (IMAP0_REGNUM), | |
759 | (long) read_register (IMAP1_REGNUM), | |
760 | (long) read_register (DMAP_REGNUM)); | |
c906108c SS |
761 | printf_filtered ("A0-A1"); |
762 | for (a = A0_REGNUM; a <= A0_REGNUM + 1; a++) | |
763 | { | |
764 | char num[MAX_REGISTER_RAW_SIZE]; | |
765 | int i; | |
766 | printf_filtered (" "); | |
c5aa993b | 767 | read_register_gen (a, (char *) &num); |
c906108c SS |
768 | for (i = 0; i < MAX_REGISTER_RAW_SIZE; i++) |
769 | { | |
770 | printf_filtered ("%02x", (num[i] & 0xff)); | |
771 | } | |
772 | } | |
773 | printf_filtered ("\n"); | |
774 | } | |
775 | ||
776 | CORE_ADDR | |
777 | d10v_read_pc (pid) | |
778 | int pid; | |
779 | { | |
780 | int save_pid; | |
781 | CORE_ADDR pc; | |
782 | CORE_ADDR retval; | |
783 | ||
784 | save_pid = inferior_pid; | |
785 | inferior_pid = pid; | |
786 | pc = (int) read_register (PC_REGNUM); | |
787 | inferior_pid = save_pid; | |
788 | retval = D10V_MAKE_IADDR (pc); | |
789 | return retval; | |
790 | } | |
791 | ||
792 | void | |
793 | d10v_write_pc (val, pid) | |
794 | CORE_ADDR val; | |
795 | int pid; | |
796 | { | |
797 | int save_pid; | |
798 | ||
799 | save_pid = inferior_pid; | |
800 | inferior_pid = pid; | |
801 | write_register (PC_REGNUM, D10V_CONVERT_IADDR_TO_RAW (val)); | |
802 | inferior_pid = save_pid; | |
803 | } | |
804 | ||
805 | CORE_ADDR | |
806 | d10v_read_sp () | |
807 | { | |
808 | return (D10V_MAKE_DADDR (read_register (SP_REGNUM))); | |
809 | } | |
810 | ||
811 | void | |
812 | d10v_write_sp (val) | |
813 | CORE_ADDR val; | |
814 | { | |
815 | write_register (SP_REGNUM, D10V_CONVERT_DADDR_TO_RAW (val)); | |
816 | } | |
817 | ||
818 | void | |
819 | d10v_write_fp (val) | |
820 | CORE_ADDR val; | |
821 | { | |
822 | write_register (FP_REGNUM, D10V_CONVERT_DADDR_TO_RAW (val)); | |
823 | } | |
824 | ||
825 | CORE_ADDR | |
826 | d10v_read_fp () | |
827 | { | |
c5aa993b | 828 | return (D10V_MAKE_DADDR (read_register (FP_REGNUM))); |
c906108c SS |
829 | } |
830 | ||
831 | /* Function: push_return_address (pc) | |
832 | Set up the return address for the inferior function call. | |
833 | Needed for targets where we don't actually execute a JSR/BSR instruction */ | |
c5aa993b | 834 | |
c906108c SS |
835 | CORE_ADDR |
836 | d10v_push_return_address (pc, sp) | |
837 | CORE_ADDR pc; | |
838 | CORE_ADDR sp; | |
839 | { | |
840 | write_register (LR_REGNUM, D10V_CONVERT_IADDR_TO_RAW (CALL_DUMMY_ADDRESS ())); | |
841 | return sp; | |
842 | } | |
c5aa993b | 843 | |
c906108c | 844 | |
7a292a7a SS |
845 | /* When arguments must be pushed onto the stack, they go on in reverse |
846 | order. The below implements a FILO (stack) to do this. */ | |
847 | ||
848 | struct stack_item | |
849 | { | |
850 | int len; | |
851 | struct stack_item *prev; | |
852 | void *data; | |
853 | }; | |
854 | ||
c5aa993b | 855 | static struct stack_item *push_stack_item PARAMS ((struct stack_item * prev, void *contents, int len)); |
7a292a7a SS |
856 | static struct stack_item * |
857 | push_stack_item (prev, contents, len) | |
858 | struct stack_item *prev; | |
859 | void *contents; | |
860 | int len; | |
861 | { | |
862 | struct stack_item *si; | |
863 | si = xmalloc (sizeof (struct stack_item)); | |
864 | si->data = xmalloc (len); | |
865 | si->len = len; | |
866 | si->prev = prev; | |
867 | memcpy (si->data, contents, len); | |
868 | return si; | |
869 | } | |
870 | ||
c5aa993b | 871 | static struct stack_item *pop_stack_item PARAMS ((struct stack_item * si)); |
7a292a7a SS |
872 | static struct stack_item * |
873 | pop_stack_item (si) | |
874 | struct stack_item *si; | |
875 | { | |
876 | struct stack_item *dead = si; | |
877 | si = si->prev; | |
878 | free (dead->data); | |
879 | free (dead); | |
880 | return si; | |
881 | } | |
882 | ||
883 | ||
c906108c SS |
884 | CORE_ADDR |
885 | d10v_push_arguments (nargs, args, sp, struct_return, struct_addr) | |
886 | int nargs; | |
887 | value_ptr *args; | |
888 | CORE_ADDR sp; | |
889 | int struct_return; | |
890 | CORE_ADDR struct_addr; | |
891 | { | |
892 | int i; | |
893 | int regnum = ARG1_REGNUM; | |
7a292a7a | 894 | struct stack_item *si = NULL; |
c5aa993b | 895 | |
c906108c SS |
896 | /* Fill in registers and arg lists */ |
897 | for (i = 0; i < nargs; i++) | |
898 | { | |
899 | value_ptr arg = args[i]; | |
900 | struct type *type = check_typedef (VALUE_TYPE (arg)); | |
901 | char *contents = VALUE_CONTENTS (arg); | |
902 | int len = TYPE_LENGTH (type); | |
903 | /* printf ("push: type=%d len=%d\n", type->code, len); */ | |
904 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
905 | { | |
906 | /* pointers require special handling - first convert and | |
907 | then store */ | |
908 | long val = extract_signed_integer (contents, len); | |
909 | len = 2; | |
910 | if (TYPE_TARGET_TYPE (type) | |
911 | && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC)) | |
912 | { | |
913 | /* function pointer */ | |
914 | val = D10V_CONVERT_IADDR_TO_RAW (val); | |
915 | } | |
916 | else if (D10V_IADDR_P (val)) | |
917 | { | |
918 | /* also function pointer! */ | |
919 | val = D10V_CONVERT_DADDR_TO_RAW (val); | |
920 | } | |
921 | else | |
922 | { | |
923 | /* data pointer */ | |
924 | val &= 0xFFFF; | |
925 | } | |
926 | if (regnum <= ARGN_REGNUM) | |
927 | write_register (regnum++, val & 0xffff); | |
928 | else | |
929 | { | |
930 | char ptr[2]; | |
7a292a7a | 931 | /* arg will go onto stack */ |
0f71a2f6 | 932 | store_address (ptr, 2, val & 0xffff); |
7a292a7a | 933 | si = push_stack_item (si, ptr, 2); |
c906108c SS |
934 | } |
935 | } | |
936 | else | |
937 | { | |
938 | int aligned_regnum = (regnum + 1) & ~1; | |
939 | if (len <= 2 && regnum <= ARGN_REGNUM) | |
940 | /* fits in a single register, do not align */ | |
941 | { | |
942 | long val = extract_unsigned_integer (contents, len); | |
943 | write_register (regnum++, val); | |
944 | } | |
945 | else if (len <= (ARGN_REGNUM - aligned_regnum + 1) * 2) | |
946 | /* value fits in remaining registers, store keeping left | |
c5aa993b | 947 | aligned */ |
c906108c SS |
948 | { |
949 | int b; | |
950 | regnum = aligned_regnum; | |
951 | for (b = 0; b < (len & ~1); b += 2) | |
952 | { | |
953 | long val = extract_unsigned_integer (&contents[b], 2); | |
954 | write_register (regnum++, val); | |
955 | } | |
956 | if (b < len) | |
957 | { | |
958 | long val = extract_unsigned_integer (&contents[b], 1); | |
959 | write_register (regnum++, (val << 8)); | |
960 | } | |
961 | } | |
962 | else | |
963 | { | |
7a292a7a | 964 | /* arg will go onto stack */ |
c5aa993b | 965 | regnum = ARGN_REGNUM + 1; |
7a292a7a | 966 | si = push_stack_item (si, contents, len); |
c906108c SS |
967 | } |
968 | } | |
969 | } | |
7a292a7a SS |
970 | |
971 | while (si) | |
972 | { | |
973 | sp = (sp - si->len) & ~1; | |
974 | write_memory (sp, si->data, si->len); | |
975 | si = pop_stack_item (si); | |
976 | } | |
c5aa993b | 977 | |
c906108c SS |
978 | return sp; |
979 | } | |
980 | ||
981 | ||
982 | /* Given a return value in `regbuf' with a type `valtype', | |
983 | extract and copy its value into `valbuf'. */ | |
984 | ||
985 | void | |
986 | d10v_extract_return_value (type, regbuf, valbuf) | |
987 | struct type *type; | |
988 | char regbuf[REGISTER_BYTES]; | |
989 | char *valbuf; | |
990 | { | |
991 | int len; | |
992 | /* printf("RET: TYPE=%d len=%d r%d=0x%x\n",type->code, TYPE_LENGTH (type), RET1_REGNUM - R0_REGNUM, (int) extract_unsigned_integer (regbuf + REGISTER_BYTE(RET1_REGNUM), REGISTER_RAW_SIZE (RET1_REGNUM))); */ | |
993 | if (TYPE_CODE (type) == TYPE_CODE_PTR | |
994 | && TYPE_TARGET_TYPE (type) | |
995 | && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC)) | |
996 | { | |
997 | /* pointer to function */ | |
998 | int num; | |
999 | short snum; | |
1000 | snum = extract_address (regbuf + REGISTER_BYTE (RET1_REGNUM), REGISTER_RAW_SIZE (RET1_REGNUM)); | |
c5aa993b | 1001 | store_address (valbuf, 4, D10V_MAKE_IADDR (snum)); |
c906108c | 1002 | } |
c5aa993b | 1003 | else if (TYPE_CODE (type) == TYPE_CODE_PTR) |
c906108c SS |
1004 | { |
1005 | /* pointer to data */ | |
1006 | int num; | |
1007 | short snum; | |
1008 | snum = extract_address (regbuf + REGISTER_BYTE (RET1_REGNUM), REGISTER_RAW_SIZE (RET1_REGNUM)); | |
c5aa993b | 1009 | store_address (valbuf, 4, D10V_MAKE_DADDR (snum)); |
c906108c SS |
1010 | } |
1011 | else | |
1012 | { | |
1013 | len = TYPE_LENGTH (type); | |
1014 | if (len == 1) | |
1015 | { | |
1016 | unsigned short c = extract_unsigned_integer (regbuf + REGISTER_BYTE (RET1_REGNUM), REGISTER_RAW_SIZE (RET1_REGNUM)); | |
1017 | store_unsigned_integer (valbuf, 1, c); | |
1018 | } | |
1019 | else if ((len & 1) == 0) | |
1020 | memcpy (valbuf, regbuf + REGISTER_BYTE (RET1_REGNUM), len); | |
1021 | else | |
1022 | { | |
1023 | /* For return values of odd size, the first byte is in the | |
c5aa993b JM |
1024 | least significant part of the first register. The |
1025 | remaining bytes in remaining registers. Interestingly, | |
1026 | when such values are passed in, the last byte is in the | |
1027 | most significant byte of that same register - wierd. */ | |
c906108c SS |
1028 | memcpy (valbuf, regbuf + REGISTER_BYTE (RET1_REGNUM) + 1, len); |
1029 | } | |
1030 | } | |
1031 | } | |
1032 | ||
c2c6d25f JM |
1033 | /* Translate a GDB virtual ADDR/LEN into a format the remote target |
1034 | understands. Returns number of bytes that can be transfered | |
1035 | starting at taddr, ZERO if no bytes can be transfered. */ | |
1036 | ||
1037 | void | |
1038 | remote_d10v_translate_xfer_address (CORE_ADDR memaddr, int nr_bytes, | |
1039 | CORE_ADDR *targ_addr, int *targ_len) | |
1040 | { | |
1041 | CORE_ADDR phys; | |
1042 | CORE_ADDR seg; | |
1043 | CORE_ADDR off; | |
1044 | char *from = "unknown"; | |
1045 | char *to = "unknown"; | |
1046 | ||
1047 | /* GDB interprets addresses as: | |
1048 | ||
1049 | 0x00xxxxxx: Physical unified memory segment (Unified memory) | |
1050 | 0x01xxxxxx: Physical instruction memory segment (On-chip insn memory) | |
1051 | 0x02xxxxxx: Physical data memory segment (On-chip data memory) | |
1052 | 0x10xxxxxx: Logical data address segment (DMAP translated memory) | |
1053 | 0x11xxxxxx: Logical instruction address segment (IMAP translated memory) | |
1054 | ||
1055 | The remote d10v board interprets addresses as: | |
1056 | ||
1057 | 0x00xxxxxx: Physical unified memory segment (Unified memory) | |
1058 | 0x01xxxxxx: Physical instruction memory segment (On-chip insn memory) | |
1059 | 0x02xxxxxx: Physical data memory segment (On-chip data memory) | |
1060 | ||
1061 | Translate according to current IMAP/dmap registers */ | |
1062 | ||
1063 | enum | |
1064 | { | |
1065 | targ_unified = 0x00000000, | |
1066 | targ_insn = 0x01000000, | |
1067 | targ_data = 0x02000000, | |
1068 | }; | |
1069 | ||
1070 | seg = (memaddr >> 24); | |
1071 | off = (memaddr & 0xffffffL); | |
1072 | ||
1073 | switch (seg) | |
1074 | { | |
1075 | case 0x00: /* Physical unified memory */ | |
1076 | from = "phys-unified"; | |
1077 | phys = targ_unified | off; | |
1078 | to = "unified"; | |
1079 | break; | |
1080 | ||
1081 | case 0x01: /* Physical instruction memory */ | |
1082 | from = "phys-insn"; | |
1083 | phys = targ_insn | off; | |
1084 | to = "chip-insn"; | |
1085 | break; | |
1086 | ||
1087 | case 0x02: /* Physical data memory segment */ | |
1088 | from = "phys-data"; | |
1089 | phys = targ_data | off; | |
1090 | to = "chip-data"; | |
1091 | break; | |
1092 | ||
1093 | case 0x10: /* in logical data address segment */ | |
1094 | { | |
1095 | from = "logical-data"; | |
1096 | if (off <= 0x7fffL) | |
1097 | { | |
1098 | /* On chip data */ | |
1099 | phys = targ_data + off; | |
1100 | if (off + nr_bytes > 0x7fffL) | |
1101 | /* don't cross VM boundary */ | |
1102 | nr_bytes = 0x7fffL - off + 1; | |
1103 | to = "chip-data"; | |
1104 | } | |
1105 | else if (off <= 0xbfffL) | |
1106 | { | |
1107 | unsigned short dmap = read_register (DMAP_REGNUM); | |
1108 | short map = dmap; | |
1109 | ||
1110 | if (map & 0x1000) | |
1111 | { | |
1112 | /* Instruction memory */ | |
1113 | phys = targ_insn | ((map & 0xf) << 14) | (off & 0x3fff); | |
1114 | to = "chip-insn"; | |
1115 | } | |
1116 | else | |
1117 | { | |
1118 | /* Unified memory */ | |
1119 | phys = targ_unified | ((map & 0x3ff) << 14) | (off & 0x3fff); | |
1120 | to = "unified"; | |
1121 | } | |
1122 | if (off + nr_bytes > 0xbfffL) | |
1123 | /* don't cross VM boundary */ | |
1124 | nr_bytes = (0xbfffL - off + 1); | |
1125 | } | |
1126 | else | |
1127 | { | |
1128 | /* Logical address out side of data segments, not supported */ | |
1129 | *targ_len = 0; | |
1130 | return; | |
1131 | } | |
1132 | break; | |
1133 | } | |
1134 | ||
1135 | case 0x11: /* in logical instruction address segment */ | |
1136 | { | |
1137 | short map; | |
1138 | unsigned short imap0 = read_register (IMAP0_REGNUM); | |
1139 | unsigned short imap1 = read_register (IMAP1_REGNUM); | |
1140 | ||
1141 | from = "logical-insn"; | |
1142 | if (off <= 0x1ffffL) | |
1143 | { | |
1144 | map = imap0; | |
1145 | } | |
1146 | else if (off <= 0x3ffffL) | |
1147 | { | |
1148 | map = imap1; | |
1149 | } | |
1150 | else | |
1151 | { | |
1152 | /* Logical address outside of IMAP[01] segment, not | |
1153 | supported */ | |
1154 | *targ_len = 0; | |
1155 | return; | |
1156 | } | |
1157 | if ((off & 0x1ffff) + nr_bytes > 0x1ffffL) | |
1158 | { | |
1159 | /* don't cross VM boundary */ | |
1160 | nr_bytes = 0x1ffffL - (off & 0x1ffffL) + 1; | |
1161 | } | |
1162 | if (map & 0x1000) | |
1163 | /* Instruction memory */ | |
1164 | { | |
1165 | phys = targ_insn | off; | |
1166 | to = "chip-insn"; | |
1167 | } | |
1168 | else | |
1169 | { | |
1170 | phys = ((map & 0x7fL) << 17) + (off & 0x1ffffL); | |
1171 | if (phys > 0xffffffL) | |
1172 | { | |
1173 | /* Address outside of unified address segment */ | |
1174 | *targ_len = 0; | |
1175 | return; | |
1176 | } | |
1177 | phys |= targ_unified; | |
1178 | to = "unified"; | |
1179 | } | |
1180 | break; | |
1181 | } | |
1182 | ||
1183 | default: | |
1184 | *targ_len = 0; | |
1185 | return; | |
1186 | } | |
1187 | ||
1188 | *targ_addr = phys; | |
1189 | *targ_len = nr_bytes; | |
1190 | } | |
1191 | ||
c906108c SS |
1192 | /* The following code implements access to, and display of, the D10V's |
1193 | instruction trace buffer. The buffer consists of 64K or more | |
1194 | 4-byte words of data, of which each words includes an 8-bit count, | |
1195 | an 8-bit segment number, and a 16-bit instruction address. | |
1196 | ||
1197 | In theory, the trace buffer is continuously capturing instruction | |
1198 | data that the CPU presents on its "debug bus", but in practice, the | |
1199 | ROMified GDB stub only enables tracing when it continues or steps | |
1200 | the program, and stops tracing when the program stops; so it | |
1201 | actually works for GDB to read the buffer counter out of memory and | |
1202 | then read each trace word. The counter records where the tracing | |
1203 | stops, but there is no record of where it started, so we remember | |
1204 | the PC when we resumed and then search backwards in the trace | |
1205 | buffer for a word that includes that address. This is not perfect, | |
1206 | because you will miss trace data if the resumption PC is the target | |
1207 | of a branch. (The value of the buffer counter is semi-random, any | |
1208 | trace data from a previous program stop is gone.) */ | |
1209 | ||
1210 | /* The address of the last word recorded in the trace buffer. */ | |
1211 | ||
1212 | #define DBBC_ADDR (0xd80000) | |
1213 | ||
1214 | /* The base of the trace buffer, at least for the "Board_0". */ | |
1215 | ||
1216 | #define TRACE_BUFFER_BASE (0xf40000) | |
1217 | ||
1218 | static void trace_command PARAMS ((char *, int)); | |
1219 | ||
1220 | static void untrace_command PARAMS ((char *, int)); | |
1221 | ||
1222 | static void trace_info PARAMS ((char *, int)); | |
1223 | ||
1224 | static void tdisassemble_command PARAMS ((char *, int)); | |
1225 | ||
1226 | static void display_trace PARAMS ((int, int)); | |
1227 | ||
1228 | /* True when instruction traces are being collected. */ | |
1229 | ||
1230 | static int tracing; | |
1231 | ||
1232 | /* Remembered PC. */ | |
1233 | ||
1234 | static CORE_ADDR last_pc; | |
1235 | ||
1236 | /* True when trace output should be displayed whenever program stops. */ | |
1237 | ||
1238 | static int trace_display; | |
1239 | ||
1240 | /* True when trace listing should include source lines. */ | |
1241 | ||
1242 | static int default_trace_show_source = 1; | |
1243 | ||
c5aa993b JM |
1244 | struct trace_buffer |
1245 | { | |
1246 | int size; | |
1247 | short *counts; | |
1248 | CORE_ADDR *addrs; | |
1249 | } | |
1250 | trace_data; | |
c906108c SS |
1251 | |
1252 | static void | |
1253 | trace_command (args, from_tty) | |
1254 | char *args; | |
1255 | int from_tty; | |
1256 | { | |
1257 | /* Clear the host-side trace buffer, allocating space if needed. */ | |
1258 | trace_data.size = 0; | |
1259 | if (trace_data.counts == NULL) | |
c5aa993b | 1260 | trace_data.counts = (short *) xmalloc (65536 * sizeof (short)); |
c906108c | 1261 | if (trace_data.addrs == NULL) |
c5aa993b | 1262 | trace_data.addrs = (CORE_ADDR *) xmalloc (65536 * sizeof (CORE_ADDR)); |
c906108c SS |
1263 | |
1264 | tracing = 1; | |
1265 | ||
1266 | printf_filtered ("Tracing is now on.\n"); | |
1267 | } | |
1268 | ||
1269 | static void | |
1270 | untrace_command (args, from_tty) | |
1271 | char *args; | |
1272 | int from_tty; | |
1273 | { | |
1274 | tracing = 0; | |
1275 | ||
1276 | printf_filtered ("Tracing is now off.\n"); | |
1277 | } | |
1278 | ||
1279 | static void | |
1280 | trace_info (args, from_tty) | |
1281 | char *args; | |
1282 | int from_tty; | |
1283 | { | |
1284 | int i; | |
1285 | ||
1286 | if (trace_data.size) | |
1287 | { | |
1288 | printf_filtered ("%d entries in trace buffer:\n", trace_data.size); | |
1289 | ||
1290 | for (i = 0; i < trace_data.size; ++i) | |
1291 | { | |
d4f3574e SS |
1292 | printf_filtered ("%d: %d instruction%s at 0x%s\n", |
1293 | i, | |
1294 | trace_data.counts[i], | |
c906108c | 1295 | (trace_data.counts[i] == 1 ? "" : "s"), |
d4f3574e | 1296 | paddr_nz (trace_data.addrs[i])); |
c906108c SS |
1297 | } |
1298 | } | |
1299 | else | |
1300 | printf_filtered ("No entries in trace buffer.\n"); | |
1301 | ||
1302 | printf_filtered ("Tracing is currently %s.\n", (tracing ? "on" : "off")); | |
1303 | } | |
1304 | ||
1305 | /* Print the instruction at address MEMADDR in debugged memory, | |
1306 | on STREAM. Returns length of the instruction, in bytes. */ | |
1307 | ||
1308 | static int | |
1309 | print_insn (memaddr, stream) | |
1310 | CORE_ADDR memaddr; | |
1311 | GDB_FILE *stream; | |
1312 | { | |
1313 | /* If there's no disassembler, something is very wrong. */ | |
1314 | if (tm_print_insn == NULL) | |
1315 | abort (); | |
1316 | ||
1317 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) | |
1318 | tm_print_insn_info.endian = BFD_ENDIAN_BIG; | |
1319 | else | |
1320 | tm_print_insn_info.endian = BFD_ENDIAN_LITTLE; | |
1321 | return (*tm_print_insn) (memaddr, &tm_print_insn_info); | |
1322 | } | |
1323 | ||
392a587b | 1324 | static void |
c906108c SS |
1325 | d10v_eva_prepare_to_trace () |
1326 | { | |
1327 | if (!tracing) | |
1328 | return; | |
1329 | ||
1330 | last_pc = read_register (PC_REGNUM); | |
1331 | } | |
1332 | ||
1333 | /* Collect trace data from the target board and format it into a form | |
1334 | more useful for display. */ | |
1335 | ||
392a587b | 1336 | static void |
c906108c SS |
1337 | d10v_eva_get_trace_data () |
1338 | { | |
1339 | int count, i, j, oldsize; | |
1340 | int trace_addr, trace_seg, trace_cnt, next_cnt; | |
1341 | unsigned int last_trace, trace_word, next_word; | |
1342 | unsigned int *tmpspace; | |
1343 | ||
1344 | if (!tracing) | |
1345 | return; | |
1346 | ||
c5aa993b | 1347 | tmpspace = xmalloc (65536 * sizeof (unsigned int)); |
c906108c SS |
1348 | |
1349 | last_trace = read_memory_unsigned_integer (DBBC_ADDR, 2) << 2; | |
1350 | ||
1351 | /* Collect buffer contents from the target, stopping when we reach | |
1352 | the word recorded when execution resumed. */ | |
1353 | ||
1354 | count = 0; | |
1355 | while (last_trace > 0) | |
1356 | { | |
1357 | QUIT; | |
1358 | trace_word = | |
1359 | read_memory_unsigned_integer (TRACE_BUFFER_BASE + last_trace, 4); | |
1360 | trace_addr = trace_word & 0xffff; | |
1361 | last_trace -= 4; | |
1362 | /* Ignore an apparently nonsensical entry. */ | |
1363 | if (trace_addr == 0xffd5) | |
1364 | continue; | |
1365 | tmpspace[count++] = trace_word; | |
1366 | if (trace_addr == last_pc) | |
1367 | break; | |
1368 | if (count > 65535) | |
1369 | break; | |
1370 | } | |
1371 | ||
1372 | /* Move the data to the host-side trace buffer, adjusting counts to | |
1373 | include the last instruction executed and transforming the address | |
1374 | into something that GDB likes. */ | |
1375 | ||
1376 | for (i = 0; i < count; ++i) | |
1377 | { | |
1378 | trace_word = tmpspace[i]; | |
1379 | next_word = ((i == 0) ? 0 : tmpspace[i - 1]); | |
1380 | trace_addr = trace_word & 0xffff; | |
1381 | next_cnt = (next_word >> 24) & 0xff; | |
1382 | j = trace_data.size + count - i - 1; | |
1383 | trace_data.addrs[j] = (trace_addr << 2) + 0x1000000; | |
1384 | trace_data.counts[j] = next_cnt + 1; | |
1385 | } | |
1386 | ||
1387 | oldsize = trace_data.size; | |
1388 | trace_data.size += count; | |
1389 | ||
1390 | free (tmpspace); | |
1391 | ||
1392 | if (trace_display) | |
1393 | display_trace (oldsize, trace_data.size); | |
1394 | } | |
1395 | ||
1396 | static void | |
1397 | tdisassemble_command (arg, from_tty) | |
1398 | char *arg; | |
1399 | int from_tty; | |
1400 | { | |
1401 | int i, count; | |
1402 | CORE_ADDR low, high; | |
1403 | char *space_index; | |
1404 | ||
1405 | if (!arg) | |
1406 | { | |
1407 | low = 0; | |
1408 | high = trace_data.size; | |
1409 | } | |
1410 | else if (!(space_index = (char *) strchr (arg, ' '))) | |
1411 | { | |
1412 | low = parse_and_eval_address (arg); | |
1413 | high = low + 5; | |
1414 | } | |
1415 | else | |
1416 | { | |
1417 | /* Two arguments. */ | |
1418 | *space_index = '\0'; | |
1419 | low = parse_and_eval_address (arg); | |
1420 | high = parse_and_eval_address (space_index + 1); | |
1421 | if (high < low) | |
1422 | high = low; | |
1423 | } | |
1424 | ||
d4f3574e | 1425 | printf_filtered ("Dump of trace from %s to %s:\n", paddr_u (low), paddr_u (high)); |
c906108c SS |
1426 | |
1427 | display_trace (low, high); | |
1428 | ||
1429 | printf_filtered ("End of trace dump.\n"); | |
1430 | gdb_flush (gdb_stdout); | |
1431 | } | |
1432 | ||
1433 | static void | |
1434 | display_trace (low, high) | |
1435 | int low, high; | |
1436 | { | |
1437 | int i, count, trace_show_source, first, suppress; | |
1438 | CORE_ADDR next_address; | |
1439 | ||
1440 | trace_show_source = default_trace_show_source; | |
c5aa993b | 1441 | if (!have_full_symbols () && !have_partial_symbols ()) |
c906108c SS |
1442 | { |
1443 | trace_show_source = 0; | |
1444 | printf_filtered ("No symbol table is loaded. Use the \"file\" command.\n"); | |
1445 | printf_filtered ("Trace will not display any source.\n"); | |
1446 | } | |
1447 | ||
1448 | first = 1; | |
1449 | suppress = 0; | |
1450 | for (i = low; i < high; ++i) | |
1451 | { | |
1452 | next_address = trace_data.addrs[i]; | |
c5aa993b | 1453 | count = trace_data.counts[i]; |
c906108c SS |
1454 | while (count-- > 0) |
1455 | { | |
1456 | QUIT; | |
1457 | if (trace_show_source) | |
1458 | { | |
1459 | struct symtab_and_line sal, sal_prev; | |
1460 | ||
1461 | sal_prev = find_pc_line (next_address - 4, 0); | |
1462 | sal = find_pc_line (next_address, 0); | |
1463 | ||
1464 | if (sal.symtab) | |
1465 | { | |
1466 | if (first || sal.line != sal_prev.line) | |
1467 | print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); | |
1468 | suppress = 0; | |
1469 | } | |
1470 | else | |
1471 | { | |
1472 | if (!suppress) | |
1473 | /* FIXME-32x64--assumes sal.pc fits in long. */ | |
1474 | printf_filtered ("No source file for address %s.\n", | |
c5aa993b | 1475 | local_hex_string ((unsigned long) sal.pc)); |
c906108c SS |
1476 | suppress = 1; |
1477 | } | |
1478 | } | |
1479 | first = 0; | |
1480 | print_address (next_address, gdb_stdout); | |
1481 | printf_filtered (":"); | |
1482 | printf_filtered ("\t"); | |
1483 | wrap_here (" "); | |
1484 | next_address = next_address + print_insn (next_address, gdb_stdout); | |
1485 | printf_filtered ("\n"); | |
1486 | gdb_flush (gdb_stdout); | |
1487 | } | |
1488 | } | |
1489 | } | |
1490 | ||
ac9a91a7 | 1491 | |
0f71a2f6 JM |
1492 | static gdbarch_init_ftype d10v_gdbarch_init; |
1493 | static struct gdbarch * | |
1494 | d10v_gdbarch_init (info, arches) | |
1495 | struct gdbarch_info info; | |
1496 | struct gdbarch_list *arches; | |
1497 | { | |
c5aa993b JM |
1498 | static LONGEST d10v_call_dummy_words[] = |
1499 | {0}; | |
0f71a2f6 JM |
1500 | struct gdbarch *gdbarch; |
1501 | int d10v_num_regs = 37; | |
1502 | ||
1503 | /* there is only one d10v architecture */ | |
1504 | if (arches != NULL) | |
1505 | return arches->gdbarch; | |
1506 | gdbarch = gdbarch_alloc (&info, NULL); | |
1507 | ||
1508 | set_gdbarch_read_pc (gdbarch, d10v_read_pc); | |
1509 | set_gdbarch_write_pc (gdbarch, d10v_write_pc); | |
1510 | set_gdbarch_read_fp (gdbarch, d10v_read_fp); | |
1511 | set_gdbarch_write_fp (gdbarch, d10v_write_fp); | |
1512 | set_gdbarch_read_sp (gdbarch, d10v_read_sp); | |
1513 | set_gdbarch_write_sp (gdbarch, d10v_write_sp); | |
1514 | ||
1515 | set_gdbarch_num_regs (gdbarch, d10v_num_regs); | |
1516 | set_gdbarch_sp_regnum (gdbarch, 15); | |
1517 | set_gdbarch_fp_regnum (gdbarch, 11); | |
1518 | set_gdbarch_pc_regnum (gdbarch, 18); | |
1519 | set_gdbarch_register_name (gdbarch, d10v_register_name); | |
1520 | set_gdbarch_register_size (gdbarch, 2); | |
1521 | set_gdbarch_register_bytes (gdbarch, (d10v_num_regs - 2) * 2 + 16); | |
1522 | set_gdbarch_register_byte (gdbarch, d10v_register_byte); | |
1523 | set_gdbarch_register_raw_size (gdbarch, d10v_register_raw_size); | |
1524 | set_gdbarch_max_register_raw_size (gdbarch, 8); | |
1525 | set_gdbarch_register_virtual_size (gdbarch, d10v_register_virtual_size); | |
1526 | set_gdbarch_max_register_virtual_size (gdbarch, 8); | |
1527 | set_gdbarch_register_virtual_type (gdbarch, d10v_register_virtual_type); | |
1528 | ||
1529 | set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
1530 | set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT); | |
1531 | set_gdbarch_int_bit (gdbarch, 2 * TARGET_CHAR_BIT); | |
1532 | set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
1533 | set_gdbarch_long_long_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
1534 | set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
1535 | set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
1536 | set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); | |
1537 | ||
1538 | set_gdbarch_use_generic_dummy_frames (gdbarch, 1); | |
1539 | set_gdbarch_call_dummy_length (gdbarch, 0); | |
1540 | set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT); | |
1541 | set_gdbarch_call_dummy_address (gdbarch, entry_point_address); | |
1542 | set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1); | |
1543 | set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0); | |
1544 | set_gdbarch_call_dummy_start_offset (gdbarch, 0); | |
1545 | set_gdbarch_pc_in_call_dummy (gdbarch, generic_pc_in_call_dummy); | |
1546 | set_gdbarch_call_dummy_words (gdbarch, d10v_call_dummy_words); | |
1547 | set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (d10v_call_dummy_words)); | |
1548 | set_gdbarch_call_dummy_p (gdbarch, 1); | |
1549 | set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0); | |
1550 | set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register); | |
1551 | set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy); | |
1552 | ||
1553 | set_gdbarch_register_convertible (gdbarch, d10v_register_convertible); | |
1554 | set_gdbarch_register_convert_to_virtual (gdbarch, d10v_register_convert_to_virtual); | |
1555 | set_gdbarch_register_convert_to_raw (gdbarch, d10v_register_convert_to_raw); | |
1556 | ||
1557 | set_gdbarch_extract_return_value (gdbarch, d10v_extract_return_value); | |
1558 | set_gdbarch_push_arguments (gdbarch, d10v_push_arguments); | |
1559 | set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame); | |
1560 | set_gdbarch_push_return_address (gdbarch, d10v_push_return_address); | |
1561 | ||
1562 | set_gdbarch_d10v_make_daddr (gdbarch, d10v_make_daddr); | |
1563 | set_gdbarch_d10v_make_iaddr (gdbarch, d10v_make_iaddr); | |
1564 | set_gdbarch_d10v_daddr_p (gdbarch, d10v_daddr_p); | |
1565 | set_gdbarch_d10v_iaddr_p (gdbarch, d10v_iaddr_p); | |
1566 | set_gdbarch_d10v_convert_daddr_to_raw (gdbarch, d10v_convert_daddr_to_raw); | |
1567 | set_gdbarch_d10v_convert_iaddr_to_raw (gdbarch, d10v_convert_iaddr_to_raw); | |
1568 | ||
1569 | set_gdbarch_store_struct_return (gdbarch, d10v_store_struct_return); | |
1570 | set_gdbarch_store_return_value (gdbarch, d10v_store_return_value); | |
1571 | set_gdbarch_extract_struct_value_address (gdbarch, d10v_extract_struct_value_address); | |
1572 | set_gdbarch_use_struct_convention (gdbarch, d10v_use_struct_convention); | |
1573 | ||
1574 | set_gdbarch_frame_init_saved_regs (gdbarch, d10v_frame_init_saved_regs); | |
1575 | set_gdbarch_init_extra_frame_info (gdbarch, d10v_init_extra_frame_info); | |
1576 | ||
1577 | set_gdbarch_pop_frame (gdbarch, d10v_pop_frame); | |
1578 | ||
1579 | set_gdbarch_skip_prologue (gdbarch, d10v_skip_prologue); | |
1580 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
1581 | set_gdbarch_decr_pc_after_break (gdbarch, 4); | |
1582 | set_gdbarch_function_start_offset (gdbarch, 0); | |
1583 | set_gdbarch_breakpoint_from_pc (gdbarch, d10v_breakpoint_from_pc); | |
1584 | ||
1585 | set_gdbarch_remote_translate_xfer_address (gdbarch, remote_d10v_translate_xfer_address); | |
1586 | ||
1587 | set_gdbarch_frame_args_skip (gdbarch, 0); | |
1588 | set_gdbarch_frameless_function_invocation (gdbarch, frameless_look_for_prologue); | |
1589 | set_gdbarch_frame_chain (gdbarch, d10v_frame_chain); | |
1590 | set_gdbarch_frame_chain_valid (gdbarch, d10v_frame_chain_valid); | |
1591 | set_gdbarch_frame_saved_pc (gdbarch, d10v_frame_saved_pc); | |
1592 | set_gdbarch_frame_args_address (gdbarch, d10v_frame_args_address); | |
1593 | set_gdbarch_frame_locals_address (gdbarch, d10v_frame_locals_address); | |
1594 | set_gdbarch_saved_pc_after_call (gdbarch, d10v_saved_pc_after_call); | |
1595 | set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown); | |
1596 | ||
1597 | return gdbarch; | |
1598 | } | |
1599 | ||
1600 | ||
c906108c SS |
1601 | extern void (*target_resume_hook) PARAMS ((void)); |
1602 | extern void (*target_wait_loop_hook) PARAMS ((void)); | |
1603 | ||
1604 | void | |
1605 | _initialize_d10v_tdep () | |
1606 | { | |
0f71a2f6 JM |
1607 | register_gdbarch_init (bfd_arch_d10v, d10v_gdbarch_init); |
1608 | ||
c906108c SS |
1609 | tm_print_insn = print_insn_d10v; |
1610 | ||
1611 | target_resume_hook = d10v_eva_prepare_to_trace; | |
1612 | target_wait_loop_hook = d10v_eva_get_trace_data; | |
1613 | ||
1614 | add_com ("regs", class_vars, show_regs, "Print all registers"); | |
1615 | ||
cff3e48b | 1616 | add_com ("itrace", class_support, trace_command, |
c906108c SS |
1617 | "Enable tracing of instruction execution."); |
1618 | ||
cff3e48b | 1619 | add_com ("iuntrace", class_support, untrace_command, |
c906108c SS |
1620 | "Disable tracing of instruction execution."); |
1621 | ||
cff3e48b | 1622 | add_com ("itdisassemble", class_vars, tdisassemble_command, |
c906108c SS |
1623 | "Disassemble the trace buffer.\n\ |
1624 | Two optional arguments specify a range of trace buffer entries\n\ | |
1625 | as reported by info trace (NOT addresses!)."); | |
1626 | ||
cff3e48b | 1627 | add_info ("itrace", trace_info, |
c906108c SS |
1628 | "Display info about the trace data buffer."); |
1629 | ||
cff3e48b | 1630 | add_show_from_set (add_set_cmd ("itracedisplay", no_class, |
c5aa993b JM |
1631 | var_integer, (char *) &trace_display, |
1632 | "Set automatic display of trace.\n", &setlist), | |
c906108c | 1633 | &showlist); |
cff3e48b | 1634 | add_show_from_set (add_set_cmd ("itracesource", no_class, |
c5aa993b JM |
1635 | var_integer, (char *) &default_trace_show_source, |
1636 | "Set display of source code with trace.\n", &setlist), | |
c906108c SS |
1637 | &showlist); |
1638 | ||
c5aa993b | 1639 | } |