]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-dependent code for Mitsubishi D10V, for GDB. |
349c5d5f | 2 | |
51603483 | 3 | Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software |
349c5d5f | 4 | Foundation, Inc. |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b JM |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
22 | |
23 | /* Contributed by Martin Hunt, [email protected] */ | |
24 | ||
25 | #include "defs.h" | |
26 | #include "frame.h" | |
7f6104a9 | 27 | #include "frame-unwind.h" |
c906108c SS |
28 | #include "symtab.h" |
29 | #include "gdbtypes.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "gdbcore.h" | |
32 | #include "gdb_string.h" | |
33 | #include "value.h" | |
34 | #include "inferior.h" | |
c5aa993b | 35 | #include "dis-asm.h" |
c906108c SS |
36 | #include "symfile.h" |
37 | #include "objfiles.h" | |
104c1213 | 38 | #include "language.h" |
28d069e6 | 39 | #include "arch-utils.h" |
4e052eda | 40 | #include "regcache.h" |
c906108c | 41 | |
f0d4cc9e | 42 | #include "floatformat.h" |
b91b96f4 | 43 | #include "gdb/sim-d10v.h" |
8238d0bf | 44 | #include "sim-regno.h" |
4ce44c66 | 45 | |
fa1fd571 AC |
46 | #include "gdb_assert.h" |
47 | ||
4ce44c66 JM |
48 | struct gdbarch_tdep |
49 | { | |
50 | int a0_regnum; | |
51 | int nr_dmap_regs; | |
52 | unsigned long (*dmap_register) (int nr); | |
53 | unsigned long (*imap_register) (int nr); | |
4ce44c66 JM |
54 | }; |
55 | ||
56 | /* These are the addresses the D10V-EVA board maps data and | |
57 | instruction memory to. */ | |
cce74817 | 58 | |
78eac43e MS |
59 | enum memspace { |
60 | DMEM_START = 0x2000000, | |
61 | IMEM_START = 0x1000000, | |
62 | STACK_START = 0x200bffe | |
63 | }; | |
cce74817 | 64 | |
4ce44c66 JM |
65 | /* d10v register names. */ |
66 | ||
67 | enum | |
68 | { | |
69 | R0_REGNUM = 0, | |
78eac43e MS |
70 | R3_REGNUM = 3, |
71 | _FP_REGNUM = 11, | |
4ce44c66 | 72 | LR_REGNUM = 13, |
78eac43e | 73 | _SP_REGNUM = 15, |
4ce44c66 | 74 | PSW_REGNUM = 16, |
78eac43e | 75 | _PC_REGNUM = 18, |
4ce44c66 | 76 | NR_IMAP_REGS = 2, |
78eac43e MS |
77 | NR_A_REGS = 2, |
78 | TS2_NUM_REGS = 37, | |
79 | TS3_NUM_REGS = 42, | |
80 | /* d10v calling convention. */ | |
81 | ARG1_REGNUM = R0_REGNUM, | |
82 | ARGN_REGNUM = R3_REGNUM, | |
83 | RET1_REGNUM = R0_REGNUM, | |
4ce44c66 | 84 | }; |
78eac43e | 85 | |
4ce44c66 JM |
86 | #define NR_DMAP_REGS (gdbarch_tdep (current_gdbarch)->nr_dmap_regs) |
87 | #define A0_REGNUM (gdbarch_tdep (current_gdbarch)->a0_regnum) | |
88 | ||
392a587b JM |
89 | /* Local functions */ |
90 | ||
a14ed312 | 91 | extern void _initialize_d10v_tdep (void); |
392a587b | 92 | |
095a4c96 EZ |
93 | static CORE_ADDR d10v_read_sp (void); |
94 | ||
95 | static CORE_ADDR d10v_read_fp (void); | |
96 | ||
a14ed312 | 97 | static void d10v_eva_prepare_to_trace (void); |
392a587b | 98 | |
a14ed312 | 99 | static void d10v_eva_get_trace_data (void); |
c906108c | 100 | |
23964bcd | 101 | static CORE_ADDR |
489137c0 AC |
102 | d10v_stack_align (CORE_ADDR len) |
103 | { | |
104 | return (len + 1) & ~1; | |
105 | } | |
c906108c SS |
106 | |
107 | /* Should we use EXTRACT_STRUCT_VALUE_ADDRESS instead of | |
108 | EXTRACT_RETURN_VALUE? GCC_P is true if compiled with gcc | |
109 | and TYPE is the type (which is known to be struct, union or array). | |
110 | ||
111 | The d10v returns anything less than 8 bytes in size in | |
112 | registers. */ | |
113 | ||
f5e1cf12 | 114 | static int |
fba45db2 | 115 | d10v_use_struct_convention (int gcc_p, struct type *type) |
c906108c | 116 | { |
02da6206 JSC |
117 | long alignment; |
118 | int i; | |
119 | /* The d10v only passes a struct in a register when that structure | |
120 | has an alignment that matches the size of a register. */ | |
121 | /* If the structure doesn't fit in 4 registers, put it on the | |
122 | stack. */ | |
123 | if (TYPE_LENGTH (type) > 8) | |
124 | return 1; | |
125 | /* If the struct contains only one field, don't put it on the stack | |
126 | - gcc can fit it in one or more registers. */ | |
127 | if (TYPE_NFIELDS (type) == 1) | |
128 | return 0; | |
129 | alignment = TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)); | |
130 | for (i = 1; i < TYPE_NFIELDS (type); i++) | |
131 | { | |
132 | /* If the alignment changes, just assume it goes on the | |
133 | stack. */ | |
134 | if (TYPE_LENGTH (TYPE_FIELD_TYPE (type, i)) != alignment) | |
135 | return 1; | |
136 | } | |
137 | /* If the alignment is suitable for the d10v's 16 bit registers, | |
138 | don't put it on the stack. */ | |
139 | if (alignment == 2 || alignment == 4) | |
140 | return 0; | |
141 | return 1; | |
c906108c SS |
142 | } |
143 | ||
144 | ||
f4f9705a | 145 | static const unsigned char * |
fba45db2 | 146 | d10v_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) |
392a587b | 147 | { |
c5aa993b JM |
148 | static unsigned char breakpoint[] = |
149 | {0x2f, 0x90, 0x5e, 0x00}; | |
392a587b JM |
150 | *lenptr = sizeof (breakpoint); |
151 | return breakpoint; | |
152 | } | |
153 | ||
4ce44c66 JM |
154 | /* Map the REG_NR onto an ascii name. Return NULL or an empty string |
155 | when the reg_nr isn't valid. */ | |
156 | ||
157 | enum ts2_regnums | |
158 | { | |
159 | TS2_IMAP0_REGNUM = 32, | |
160 | TS2_DMAP_REGNUM = 34, | |
161 | TS2_NR_DMAP_REGS = 1, | |
162 | TS2_A0_REGNUM = 35 | |
163 | }; | |
164 | ||
fa88f677 | 165 | static const char * |
4ce44c66 | 166 | d10v_ts2_register_name (int reg_nr) |
392a587b | 167 | { |
c5aa993b JM |
168 | static char *register_names[] = |
169 | { | |
170 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
171 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
172 | "psw", "bpsw", "pc", "bpc", "cr4", "cr5", "cr6", "rpt_c", | |
173 | "rpt_s", "rpt_e", "mod_s", "mod_e", "cr12", "cr13", "iba", "cr15", | |
174 | "imap0", "imap1", "dmap", "a0", "a1" | |
392a587b JM |
175 | }; |
176 | if (reg_nr < 0) | |
177 | return NULL; | |
178 | if (reg_nr >= (sizeof (register_names) / sizeof (*register_names))) | |
179 | return NULL; | |
c5aa993b | 180 | return register_names[reg_nr]; |
392a587b JM |
181 | } |
182 | ||
4ce44c66 JM |
183 | enum ts3_regnums |
184 | { | |
185 | TS3_IMAP0_REGNUM = 36, | |
186 | TS3_DMAP0_REGNUM = 38, | |
187 | TS3_NR_DMAP_REGS = 4, | |
188 | TS3_A0_REGNUM = 32 | |
189 | }; | |
190 | ||
fa88f677 | 191 | static const char * |
4ce44c66 JM |
192 | d10v_ts3_register_name (int reg_nr) |
193 | { | |
194 | static char *register_names[] = | |
195 | { | |
196 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | |
197 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
198 | "psw", "bpsw", "pc", "bpc", "cr4", "cr5", "cr6", "rpt_c", | |
199 | "rpt_s", "rpt_e", "mod_s", "mod_e", "cr12", "cr13", "iba", "cr15", | |
200 | "a0", "a1", | |
201 | "spi", "spu", | |
202 | "imap0", "imap1", | |
203 | "dmap0", "dmap1", "dmap2", "dmap3" | |
204 | }; | |
205 | if (reg_nr < 0) | |
206 | return NULL; | |
207 | if (reg_nr >= (sizeof (register_names) / sizeof (*register_names))) | |
208 | return NULL; | |
209 | return register_names[reg_nr]; | |
210 | } | |
211 | ||
bf93dfed JB |
212 | /* Access the DMAP/IMAP registers in a target independent way. |
213 | ||
214 | Divide the D10V's 64k data space into four 16k segments: | |
215 | 0x0000 -- 0x3fff, 0x4000 -- 0x7fff, 0x8000 -- 0xbfff, and | |
216 | 0xc000 -- 0xffff. | |
217 | ||
218 | On the TS2, the first two segments (0x0000 -- 0x3fff, 0x4000 -- | |
219 | 0x7fff) always map to the on-chip data RAM, and the fourth always | |
220 | maps to I/O space. The third (0x8000 - 0xbfff) can be mapped into | |
221 | unified memory or instruction memory, under the control of the | |
222 | single DMAP register. | |
223 | ||
224 | On the TS3, there are four DMAP registers, each of which controls | |
225 | one of the segments. */ | |
4ce44c66 JM |
226 | |
227 | static unsigned long | |
228 | d10v_ts2_dmap_register (int reg_nr) | |
229 | { | |
230 | switch (reg_nr) | |
231 | { | |
232 | case 0: | |
233 | case 1: | |
234 | return 0x2000; | |
235 | case 2: | |
236 | return read_register (TS2_DMAP_REGNUM); | |
237 | default: | |
238 | return 0; | |
239 | } | |
240 | } | |
241 | ||
242 | static unsigned long | |
243 | d10v_ts3_dmap_register (int reg_nr) | |
244 | { | |
245 | return read_register (TS3_DMAP0_REGNUM + reg_nr); | |
246 | } | |
247 | ||
248 | static unsigned long | |
249 | d10v_dmap_register (int reg_nr) | |
250 | { | |
251 | return gdbarch_tdep (current_gdbarch)->dmap_register (reg_nr); | |
252 | } | |
253 | ||
254 | static unsigned long | |
255 | d10v_ts2_imap_register (int reg_nr) | |
256 | { | |
257 | return read_register (TS2_IMAP0_REGNUM + reg_nr); | |
258 | } | |
259 | ||
260 | static unsigned long | |
261 | d10v_ts3_imap_register (int reg_nr) | |
262 | { | |
263 | return read_register (TS3_IMAP0_REGNUM + reg_nr); | |
264 | } | |
265 | ||
266 | static unsigned long | |
267 | d10v_imap_register (int reg_nr) | |
268 | { | |
269 | return gdbarch_tdep (current_gdbarch)->imap_register (reg_nr); | |
270 | } | |
271 | ||
272 | /* MAP GDB's internal register numbering (determined by the layout fo | |
273 | the REGISTER_BYTE array) onto the simulator's register | |
274 | numbering. */ | |
275 | ||
276 | static int | |
277 | d10v_ts2_register_sim_regno (int nr) | |
278 | { | |
8238d0bf AC |
279 | if (legacy_register_sim_regno (nr) < 0) |
280 | return legacy_register_sim_regno (nr); | |
4ce44c66 JM |
281 | if (nr >= TS2_IMAP0_REGNUM |
282 | && nr < TS2_IMAP0_REGNUM + NR_IMAP_REGS) | |
283 | return nr - TS2_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM; | |
284 | if (nr == TS2_DMAP_REGNUM) | |
285 | return nr - TS2_DMAP_REGNUM + SIM_D10V_TS2_DMAP_REGNUM; | |
286 | if (nr >= TS2_A0_REGNUM | |
287 | && nr < TS2_A0_REGNUM + NR_A_REGS) | |
288 | return nr - TS2_A0_REGNUM + SIM_D10V_A0_REGNUM; | |
289 | return nr; | |
290 | } | |
291 | ||
292 | static int | |
293 | d10v_ts3_register_sim_regno (int nr) | |
294 | { | |
8238d0bf AC |
295 | if (legacy_register_sim_regno (nr) < 0) |
296 | return legacy_register_sim_regno (nr); | |
4ce44c66 JM |
297 | if (nr >= TS3_IMAP0_REGNUM |
298 | && nr < TS3_IMAP0_REGNUM + NR_IMAP_REGS) | |
299 | return nr - TS3_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM; | |
300 | if (nr >= TS3_DMAP0_REGNUM | |
301 | && nr < TS3_DMAP0_REGNUM + TS3_NR_DMAP_REGS) | |
302 | return nr - TS3_DMAP0_REGNUM + SIM_D10V_DMAP0_REGNUM; | |
303 | if (nr >= TS3_A0_REGNUM | |
304 | && nr < TS3_A0_REGNUM + NR_A_REGS) | |
305 | return nr - TS3_A0_REGNUM + SIM_D10V_A0_REGNUM; | |
306 | return nr; | |
307 | } | |
308 | ||
392a587b JM |
309 | /* Index within `registers' of the first byte of the space for |
310 | register REG_NR. */ | |
311 | ||
f5e1cf12 | 312 | static int |
fba45db2 | 313 | d10v_register_byte (int reg_nr) |
392a587b | 314 | { |
4ce44c66 | 315 | if (reg_nr < A0_REGNUM) |
392a587b | 316 | return (reg_nr * 2); |
4ce44c66 JM |
317 | else if (reg_nr < (A0_REGNUM + NR_A_REGS)) |
318 | return (A0_REGNUM * 2 | |
319 | + (reg_nr - A0_REGNUM) * 8); | |
320 | else | |
321 | return (A0_REGNUM * 2 | |
322 | + NR_A_REGS * 8 | |
323 | + (reg_nr - A0_REGNUM - NR_A_REGS) * 2); | |
392a587b JM |
324 | } |
325 | ||
326 | /* Number of bytes of storage in the actual machine representation for | |
327 | register REG_NR. */ | |
328 | ||
f5e1cf12 | 329 | static int |
fba45db2 | 330 | d10v_register_raw_size (int reg_nr) |
392a587b | 331 | { |
4ce44c66 JM |
332 | if (reg_nr < A0_REGNUM) |
333 | return 2; | |
334 | else if (reg_nr < (A0_REGNUM + NR_A_REGS)) | |
392a587b JM |
335 | return 8; |
336 | else | |
337 | return 2; | |
338 | } | |
339 | ||
392a587b JM |
340 | /* Return the GDB type object for the "standard" data type |
341 | of data in register N. */ | |
342 | ||
f5e1cf12 | 343 | static struct type * |
35cac7cf | 344 | d10v_register_type (struct gdbarch *gdbarch, int reg_nr) |
392a587b | 345 | { |
75af7f68 JB |
346 | if (reg_nr == PC_REGNUM) |
347 | return builtin_type_void_func_ptr; | |
095a4c96 EZ |
348 | if (reg_nr == _SP_REGNUM || reg_nr == _FP_REGNUM) |
349 | return builtin_type_void_data_ptr; | |
75af7f68 | 350 | else if (reg_nr >= A0_REGNUM |
4ce44c66 JM |
351 | && reg_nr < (A0_REGNUM + NR_A_REGS)) |
352 | return builtin_type_int64; | |
392a587b | 353 | else |
4ce44c66 | 354 | return builtin_type_int16; |
392a587b JM |
355 | } |
356 | ||
f5e1cf12 | 357 | static int |
fba45db2 | 358 | d10v_daddr_p (CORE_ADDR x) |
392a587b JM |
359 | { |
360 | return (((x) & 0x3000000) == DMEM_START); | |
361 | } | |
362 | ||
f5e1cf12 | 363 | static int |
fba45db2 | 364 | d10v_iaddr_p (CORE_ADDR x) |
392a587b JM |
365 | { |
366 | return (((x) & 0x3000000) == IMEM_START); | |
367 | } | |
368 | ||
169a7369 MS |
369 | static CORE_ADDR |
370 | d10v_make_daddr (CORE_ADDR x) | |
371 | { | |
372 | return ((x) | DMEM_START); | |
373 | } | |
374 | ||
375 | static CORE_ADDR | |
376 | d10v_make_iaddr (CORE_ADDR x) | |
377 | { | |
378 | if (d10v_iaddr_p (x)) | |
379 | return x; /* Idempotency -- x is already in the IMEM space. */ | |
380 | else | |
381 | return (((x) << 2) | IMEM_START); | |
382 | } | |
392a587b | 383 | |
f5e1cf12 | 384 | static CORE_ADDR |
fba45db2 | 385 | d10v_convert_iaddr_to_raw (CORE_ADDR x) |
392a587b JM |
386 | { |
387 | return (((x) >> 2) & 0xffff); | |
388 | } | |
389 | ||
f5e1cf12 | 390 | static CORE_ADDR |
fba45db2 | 391 | d10v_convert_daddr_to_raw (CORE_ADDR x) |
392a587b JM |
392 | { |
393 | return ((x) & 0xffff); | |
394 | } | |
395 | ||
75af7f68 JB |
396 | static void |
397 | d10v_address_to_pointer (struct type *type, void *buf, CORE_ADDR addr) | |
398 | { | |
399 | /* Is it a code address? */ | |
400 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC | |
401 | || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD) | |
402 | { | |
75af7f68 JB |
403 | store_unsigned_integer (buf, TYPE_LENGTH (type), |
404 | d10v_convert_iaddr_to_raw (addr)); | |
405 | } | |
406 | else | |
407 | { | |
408 | /* Strip off any upper segment bits. */ | |
409 | store_unsigned_integer (buf, TYPE_LENGTH (type), | |
410 | d10v_convert_daddr_to_raw (addr)); | |
411 | } | |
412 | } | |
413 | ||
414 | static CORE_ADDR | |
66140c26 | 415 | d10v_pointer_to_address (struct type *type, const void *buf) |
75af7f68 JB |
416 | { |
417 | CORE_ADDR addr = extract_address (buf, TYPE_LENGTH (type)); | |
418 | ||
419 | /* Is it a code address? */ | |
420 | if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_FUNC | |
74a9bb82 FF |
421 | || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD |
422 | || TYPE_CODE_SPACE (TYPE_TARGET_TYPE (type))) | |
75af7f68 JB |
423 | return d10v_make_iaddr (addr); |
424 | else | |
425 | return d10v_make_daddr (addr); | |
426 | } | |
427 | ||
095a4c96 EZ |
428 | /* Don't do anything if we have an integer, this way users can type 'x |
429 | <addr>' w/o having gdb outsmart them. The internal gdb conversions | |
430 | to the correct space are taken care of in the pointer_to_address | |
431 | function. If we don't do this, 'x $fp' wouldn't work. */ | |
fc0c74b1 AC |
432 | static CORE_ADDR |
433 | d10v_integer_to_address (struct type *type, void *buf) | |
434 | { | |
435 | LONGEST val; | |
436 | val = unpack_long (type, buf); | |
095a4c96 | 437 | return val; |
fc0c74b1 | 438 | } |
75af7f68 | 439 | |
392a587b JM |
440 | /* Store the address of the place in which to copy the structure the |
441 | subroutine will return. This is called from call_function. | |
442 | ||
443 | We store structs through a pointer passed in the first Argument | |
444 | register. */ | |
445 | ||
f5e1cf12 | 446 | static void |
fba45db2 | 447 | d10v_store_struct_return (CORE_ADDR addr, CORE_ADDR sp) |
392a587b JM |
448 | { |
449 | write_register (ARG1_REGNUM, (addr)); | |
450 | } | |
451 | ||
452 | /* Write into appropriate registers a function return value | |
453 | of type TYPE, given in virtual format. | |
454 | ||
455 | Things always get returned in RET1_REGNUM, RET2_REGNUM, ... */ | |
456 | ||
f5e1cf12 | 457 | static void |
fa1fd571 AC |
458 | d10v_store_return_value (struct type *type, struct regcache *regcache, |
459 | const void *valbuf) | |
392a587b | 460 | { |
fa1fd571 AC |
461 | /* Only char return values need to be shifted right within the first |
462 | regnum. */ | |
3d79a47c MS |
463 | if (TYPE_LENGTH (type) == 1 |
464 | && TYPE_CODE (type) == TYPE_CODE_INT) | |
465 | { | |
fa1fd571 AC |
466 | bfd_byte tmp[2]; |
467 | tmp[1] = *(bfd_byte *)valbuf; | |
468 | regcache_cooked_write (regcache, RET1_REGNUM, tmp); | |
3d79a47c MS |
469 | } |
470 | else | |
fa1fd571 AC |
471 | { |
472 | int reg; | |
473 | /* A structure is never more than 8 bytes long. See | |
474 | use_struct_convention(). */ | |
475 | gdb_assert (TYPE_LENGTH (type) <= 8); | |
476 | /* Write out most registers, stop loop before trying to write | |
477 | out any dangling byte at the end of the buffer. */ | |
478 | for (reg = 0; (reg * 2) + 1 < TYPE_LENGTH (type); reg++) | |
479 | { | |
480 | regcache_cooked_write (regcache, RET1_REGNUM + reg, | |
481 | (bfd_byte *) valbuf + reg * 2); | |
482 | } | |
483 | /* Write out any dangling byte at the end of the buffer. */ | |
484 | if ((reg * 2) + 1 == TYPE_LENGTH (type)) | |
485 | regcache_cooked_write_part (regcache, reg, 0, 1, | |
486 | (bfd_byte *) valbuf + reg * 2); | |
487 | } | |
392a587b JM |
488 | } |
489 | ||
490 | /* Extract from an array REGBUF containing the (raw) register state | |
491 | the address in which a function should return its structure value, | |
492 | as a CORE_ADDR (or an expression that can be used as one). */ | |
493 | ||
f5e1cf12 | 494 | static CORE_ADDR |
fa1fd571 | 495 | d10v_extract_struct_value_address (struct regcache *regcache) |
392a587b | 496 | { |
fa1fd571 AC |
497 | ULONGEST addr; |
498 | regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &addr); | |
499 | return (addr | DMEM_START); | |
392a587b JM |
500 | } |
501 | ||
392a587b JM |
502 | /* Immediately after a function call, return the saved pc. We can't |
503 | use frame->return_pc beause that is determined by reading R13 off | |
504 | the stack and that may not be written yet. */ | |
505 | ||
f5e1cf12 | 506 | static CORE_ADDR |
fba45db2 | 507 | d10v_saved_pc_after_call (struct frame_info *frame) |
392a587b | 508 | { |
c5aa993b | 509 | return ((read_register (LR_REGNUM) << 2) |
392a587b JM |
510 | | IMEM_START); |
511 | } | |
512 | ||
c5aa993b | 513 | static int |
fba45db2 | 514 | check_prologue (unsigned short op) |
c906108c SS |
515 | { |
516 | /* st rn, @-sp */ | |
517 | if ((op & 0x7E1F) == 0x6C1F) | |
518 | return 1; | |
519 | ||
520 | /* st2w rn, @-sp */ | |
521 | if ((op & 0x7E3F) == 0x6E1F) | |
522 | return 1; | |
523 | ||
524 | /* subi sp, n */ | |
525 | if ((op & 0x7FE1) == 0x01E1) | |
526 | return 1; | |
527 | ||
528 | /* mv r11, sp */ | |
529 | if (op == 0x417E) | |
530 | return 1; | |
531 | ||
532 | /* nop */ | |
533 | if (op == 0x5E00) | |
534 | return 1; | |
535 | ||
536 | /* st rn, @sp */ | |
537 | if ((op & 0x7E1F) == 0x681E) | |
538 | return 1; | |
539 | ||
540 | /* st2w rn, @sp */ | |
c5aa993b JM |
541 | if ((op & 0x7E3F) == 0x3A1E) |
542 | return 1; | |
c906108c SS |
543 | |
544 | return 0; | |
545 | } | |
546 | ||
f5e1cf12 | 547 | static CORE_ADDR |
fba45db2 | 548 | d10v_skip_prologue (CORE_ADDR pc) |
c906108c SS |
549 | { |
550 | unsigned long op; | |
551 | unsigned short op1, op2; | |
552 | CORE_ADDR func_addr, func_end; | |
553 | struct symtab_and_line sal; | |
554 | ||
555 | /* If we have line debugging information, then the end of the */ | |
556 | /* prologue should the first assembly instruction of the first source line */ | |
557 | if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
558 | { | |
559 | sal = find_pc_line (func_addr, 0); | |
c5aa993b | 560 | if (sal.end && sal.end < func_end) |
c906108c SS |
561 | return sal.end; |
562 | } | |
c5aa993b JM |
563 | |
564 | if (target_read_memory (pc, (char *) &op, 4)) | |
c906108c SS |
565 | return pc; /* Can't access it -- assume no prologue. */ |
566 | ||
567 | while (1) | |
568 | { | |
c5aa993b | 569 | op = (unsigned long) read_memory_integer (pc, 4); |
c906108c SS |
570 | if ((op & 0xC0000000) == 0xC0000000) |
571 | { | |
572 | /* long instruction */ | |
c5aa993b JM |
573 | if (((op & 0x3FFF0000) != 0x01FF0000) && /* add3 sp,sp,n */ |
574 | ((op & 0x3F0F0000) != 0x340F0000) && /* st rn, @(offset,sp) */ | |
575 | ((op & 0x3F1F0000) != 0x350F0000)) /* st2w rn, @(offset,sp) */ | |
c906108c SS |
576 | break; |
577 | } | |
578 | else | |
579 | { | |
580 | /* short instructions */ | |
581 | if ((op & 0xC0000000) == 0x80000000) | |
582 | { | |
583 | op2 = (op & 0x3FFF8000) >> 15; | |
584 | op1 = op & 0x7FFF; | |
c5aa993b JM |
585 | } |
586 | else | |
c906108c SS |
587 | { |
588 | op1 = (op & 0x3FFF8000) >> 15; | |
589 | op2 = op & 0x7FFF; | |
590 | } | |
c5aa993b | 591 | if (check_prologue (op1)) |
c906108c | 592 | { |
c5aa993b | 593 | if (!check_prologue (op2)) |
c906108c SS |
594 | { |
595 | /* if the previous opcode was really part of the prologue */ | |
596 | /* and not just a NOP, then we want to break after both instructions */ | |
597 | if (op1 != 0x5E00) | |
598 | pc += 4; | |
599 | break; | |
600 | } | |
601 | } | |
602 | else | |
603 | break; | |
604 | } | |
605 | pc += 4; | |
606 | } | |
607 | return pc; | |
608 | } | |
609 | ||
7f6104a9 | 610 | struct d10v_unwind_cache |
c906108c | 611 | { |
7f6104a9 | 612 | CORE_ADDR return_pc; |
ceea5145 AC |
613 | /* The frame's base. Used when constructing a frame ID. */ |
614 | CORE_ADDR base; | |
7f6104a9 AC |
615 | int size; |
616 | CORE_ADDR *saved_regs; | |
0d843116 AC |
617 | /* How far the SP and r11 (FP) have been offset from the start of |
618 | the stack frame (as defined by the previous frame's stack | |
619 | pointer). */ | |
620 | LONGEST sp_offset; | |
621 | LONGEST r11_offset; | |
7f6104a9 AC |
622 | int uses_frame; |
623 | void **regs; | |
624 | }; | |
c906108c | 625 | |
c5aa993b | 626 | static int |
7f6104a9 AC |
627 | prologue_find_regs (struct d10v_unwind_cache *info, unsigned short op, |
628 | CORE_ADDR addr) | |
c906108c SS |
629 | { |
630 | int n; | |
631 | ||
632 | /* st rn, @-sp */ | |
633 | if ((op & 0x7E1F) == 0x6C1F) | |
634 | { | |
635 | n = (op & 0x1E0) >> 5; | |
0d843116 AC |
636 | info->sp_offset -= 2; |
637 | info->saved_regs[n] = info->sp_offset; | |
c906108c SS |
638 | return 1; |
639 | } | |
640 | ||
641 | /* st2w rn, @-sp */ | |
642 | else if ((op & 0x7E3F) == 0x6E1F) | |
643 | { | |
644 | n = (op & 0x1E0) >> 5; | |
0d843116 AC |
645 | info->sp_offset -= 4; |
646 | info->saved_regs[n] = info->sp_offset; | |
647 | info->saved_regs[n + 1] = info->sp_offset + 2; | |
c906108c SS |
648 | return 1; |
649 | } | |
650 | ||
651 | /* subi sp, n */ | |
652 | if ((op & 0x7FE1) == 0x01E1) | |
653 | { | |
654 | n = (op & 0x1E) >> 1; | |
655 | if (n == 0) | |
656 | n = 16; | |
0d843116 | 657 | info->sp_offset -= n; |
c906108c SS |
658 | return 1; |
659 | } | |
660 | ||
661 | /* mv r11, sp */ | |
662 | if (op == 0x417E) | |
663 | { | |
7f6104a9 | 664 | info->uses_frame = 1; |
0d843116 AC |
665 | info->r11_offset = info->sp_offset; |
666 | return 1; | |
667 | } | |
668 | ||
669 | /* st rn, @r11 */ | |
670 | if ((op & 0x7E1F) == 0x6816) | |
671 | { | |
672 | n = (op & 0x1E0) >> 5; | |
673 | info->saved_regs[n] = info->r11_offset; | |
c906108c SS |
674 | return 1; |
675 | } | |
676 | ||
677 | /* nop */ | |
678 | if (op == 0x5E00) | |
679 | return 1; | |
680 | ||
681 | /* st rn, @sp */ | |
682 | if ((op & 0x7E1F) == 0x681E) | |
683 | { | |
684 | n = (op & 0x1E0) >> 5; | |
0d843116 | 685 | info->saved_regs[n] = info->sp_offset; |
c906108c SS |
686 | return 1; |
687 | } | |
688 | ||
689 | /* st2w rn, @sp */ | |
690 | if ((op & 0x7E3F) == 0x3A1E) | |
691 | { | |
692 | n = (op & 0x1E0) >> 5; | |
0d843116 AC |
693 | info->saved_regs[n] = info->sp_offset; |
694 | info->saved_regs[n + 1] = info->sp_offset + 2; | |
c906108c SS |
695 | return 1; |
696 | } | |
697 | ||
698 | return 0; | |
699 | } | |
700 | ||
cce74817 JM |
701 | /* Put here the code to store, into fi->saved_regs, the addresses of |
702 | the saved registers of frame described by FRAME_INFO. This | |
703 | includes special registers such as pc and fp saved in special ways | |
704 | in the stack frame. sp is even more special: the address we return | |
705 | for it IS the sp for the next frame. */ | |
706 | ||
7f6104a9 | 707 | struct d10v_unwind_cache * |
6dc42492 AC |
708 | d10v_frame_unwind_cache (struct frame_info *next_frame, |
709 | void **this_prologue_cache) | |
c906108c | 710 | { |
ceea5145 AC |
711 | CORE_ADDR pc; |
712 | ULONGEST prev_sp; | |
713 | ULONGEST this_base; | |
c906108c SS |
714 | unsigned long op; |
715 | unsigned short op1, op2; | |
716 | int i; | |
7f6104a9 AC |
717 | struct d10v_unwind_cache *info; |
718 | ||
6dc42492 AC |
719 | if ((*this_prologue_cache)) |
720 | return (*this_prologue_cache); | |
7f6104a9 AC |
721 | |
722 | info = FRAME_OBSTACK_ZALLOC (struct d10v_unwind_cache); | |
6dc42492 | 723 | (*this_prologue_cache) = info; |
7f6104a9 AC |
724 | info->saved_regs = frame_obstack_zalloc (SIZEOF_FRAME_SAVED_REGS); |
725 | ||
7f6104a9 AC |
726 | info->size = 0; |
727 | info->return_pc = 0; | |
0d843116 | 728 | info->sp_offset = 0; |
c906108c | 729 | |
6dc42492 | 730 | pc = get_pc_function_start (frame_pc_unwind (next_frame)); |
c906108c | 731 | |
7f6104a9 | 732 | info->uses_frame = 0; |
c906108c SS |
733 | while (1) |
734 | { | |
c5aa993b | 735 | op = (unsigned long) read_memory_integer (pc, 4); |
c906108c SS |
736 | if ((op & 0xC0000000) == 0xC0000000) |
737 | { | |
738 | /* long instruction */ | |
739 | if ((op & 0x3FFF0000) == 0x01FF0000) | |
740 | { | |
741 | /* add3 sp,sp,n */ | |
742 | short n = op & 0xFFFF; | |
0d843116 | 743 | info->sp_offset += n; |
c906108c SS |
744 | } |
745 | else if ((op & 0x3F0F0000) == 0x340F0000) | |
746 | { | |
747 | /* st rn, @(offset,sp) */ | |
748 | short offset = op & 0xFFFF; | |
749 | short n = (op >> 20) & 0xF; | |
0d843116 | 750 | info->saved_regs[n] = info->sp_offset + offset; |
c906108c SS |
751 | } |
752 | else if ((op & 0x3F1F0000) == 0x350F0000) | |
753 | { | |
754 | /* st2w rn, @(offset,sp) */ | |
755 | short offset = op & 0xFFFF; | |
756 | short n = (op >> 20) & 0xF; | |
0d843116 AC |
757 | info->saved_regs[n] = info->sp_offset + offset; |
758 | info->saved_regs[n + 1] = info->sp_offset + offset + 2; | |
c906108c SS |
759 | } |
760 | else | |
761 | break; | |
762 | } | |
763 | else | |
764 | { | |
765 | /* short instructions */ | |
766 | if ((op & 0xC0000000) == 0x80000000) | |
767 | { | |
768 | op2 = (op & 0x3FFF8000) >> 15; | |
769 | op1 = op & 0x7FFF; | |
c5aa993b JM |
770 | } |
771 | else | |
c906108c SS |
772 | { |
773 | op1 = (op & 0x3FFF8000) >> 15; | |
774 | op2 = op & 0x7FFF; | |
775 | } | |
7f6104a9 AC |
776 | if (!prologue_find_regs (info, op1, pc) |
777 | || !prologue_find_regs (info, op2, pc)) | |
c906108c SS |
778 | break; |
779 | } | |
780 | pc += 4; | |
781 | } | |
c5aa993b | 782 | |
0d843116 | 783 | info->size = -info->sp_offset; |
c906108c | 784 | |
ceea5145 AC |
785 | /* Compute the frame's base, and the previous frame's SP. */ |
786 | if (info->uses_frame) | |
787 | { | |
788 | /* The SP was moved to the FP. This indicates that a new frame | |
789 | was created. Get THIS frame's FP value by unwinding it from | |
790 | the next frame. */ | |
6dc42492 | 791 | frame_unwind_unsigned_register (next_frame, FP_REGNUM, &this_base); |
ceea5145 AC |
792 | /* The FP points at the last saved register. Adjust the FP back |
793 | to before the first saved register giving the SP. */ | |
794 | prev_sp = this_base + info->size; | |
795 | } | |
796 | else if (info->saved_regs[SP_REGNUM]) | |
797 | { | |
798 | /* The SP was saved (which is very unusual), the frame base is | |
799 | just the PREV's frame's TOP-OF-STACK. */ | |
800 | this_base = read_memory_unsigned_integer (info->saved_regs[SP_REGNUM], | |
801 | register_size (current_gdbarch, | |
802 | SP_REGNUM)); | |
803 | prev_sp = this_base; | |
804 | } | |
805 | else | |
806 | { | |
807 | /* Assume that the FP is this frame's SP but with that pushed | |
808 | stack space added back. */ | |
6dc42492 | 809 | frame_unwind_unsigned_register (next_frame, SP_REGNUM, &this_base); |
ceea5145 AC |
810 | prev_sp = this_base + info->size; |
811 | } | |
812 | ||
813 | info->base = d10v_make_daddr (this_base); | |
814 | prev_sp = d10v_make_daddr (prev_sp); | |
c906108c | 815 | |
ceea5145 AC |
816 | /* Adjust all the saved registers so that they contain addresses and |
817 | not offsets. */ | |
c5aa993b | 818 | for (i = 0; i < NUM_REGS - 1; i++) |
7f6104a9 | 819 | if (info->saved_regs[i]) |
c906108c | 820 | { |
ceea5145 | 821 | info->saved_regs[i] = (prev_sp + info->saved_regs[i]); |
c906108c SS |
822 | } |
823 | ||
7f6104a9 | 824 | if (info->saved_regs[LR_REGNUM]) |
c906108c | 825 | { |
78eac43e | 826 | CORE_ADDR return_pc |
7f6104a9 | 827 | = read_memory_unsigned_integer (info->saved_regs[LR_REGNUM], |
08a617da | 828 | register_size (current_gdbarch, LR_REGNUM)); |
7f6104a9 | 829 | info->return_pc = d10v_make_iaddr (return_pc); |
c906108c SS |
830 | } |
831 | else | |
832 | { | |
7f6104a9 | 833 | ULONGEST return_pc; |
6dc42492 | 834 | frame_unwind_unsigned_register (next_frame, LR_REGNUM, &return_pc); |
7f6104a9 | 835 | info->return_pc = d10v_make_iaddr (return_pc); |
c906108c | 836 | } |
c5aa993b | 837 | |
ceea5145 AC |
838 | /* The SP_REGNUM is special. Instead of the address of the SP, the |
839 | previous frame's SP value is saved. */ | |
840 | info->saved_regs[SP_REGNUM] = prev_sp; | |
c906108c | 841 | |
7f6104a9 | 842 | return info; |
c906108c SS |
843 | } |
844 | ||
845 | static void | |
5f601589 AC |
846 | d10v_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file, |
847 | struct frame_info *frame, int regnum, int all) | |
c906108c | 848 | { |
5f601589 | 849 | if (regnum >= 0) |
4ce44c66 | 850 | { |
5f601589 AC |
851 | default_print_registers_info (gdbarch, file, frame, regnum, all); |
852 | return; | |
4ce44c66 | 853 | } |
5f601589 AC |
854 | |
855 | { | |
856 | ULONGEST pc, psw, rpt_s, rpt_e, rpt_c; | |
857 | frame_read_unsigned_register (frame, PC_REGNUM, &pc); | |
858 | frame_read_unsigned_register (frame, PSW_REGNUM, &psw); | |
859 | frame_read_unsigned_register (frame, frame_map_name_to_regnum ("rpt_s", -1), &rpt_s); | |
860 | frame_read_unsigned_register (frame, frame_map_name_to_regnum ("rpt_e", -1), &rpt_e); | |
861 | frame_read_unsigned_register (frame, frame_map_name_to_regnum ("rpt_c", -1), &rpt_c); | |
862 | fprintf_filtered (file, "PC=%04lx (0x%lx) PSW=%04lx RPT_S=%04lx RPT_E=%04lx RPT_C=%04lx\n", | |
863 | (long) pc, (long) d10v_make_iaddr (pc), (long) psw, | |
864 | (long) rpt_s, (long) rpt_e, (long) rpt_c); | |
865 | } | |
866 | ||
867 | { | |
868 | int group; | |
869 | for (group = 0; group < 16; group += 8) | |
870 | { | |
871 | int r; | |
872 | fprintf_filtered (file, "R%d-R%-2d", group, group + 7); | |
873 | for (r = group; r < group + 8; r++) | |
874 | { | |
875 | ULONGEST tmp; | |
876 | frame_read_unsigned_register (frame, r, &tmp); | |
877 | fprintf_filtered (file, " %04lx", (long) tmp); | |
878 | } | |
879 | fprintf_filtered (file, "\n"); | |
880 | } | |
881 | } | |
882 | ||
883 | /* Note: The IMAP/DMAP registers don't participate in function | |
884 | calls. Don't bother trying to unwind them. */ | |
885 | ||
6789195b | 886 | { |
5f601589 AC |
887 | int a; |
888 | for (a = 0; a < NR_IMAP_REGS; a++) | |
889 | { | |
890 | if (a > 0) | |
891 | fprintf_filtered (file, " "); | |
892 | fprintf_filtered (file, "IMAP%d %04lx", a, d10v_imap_register (a)); | |
893 | } | |
894 | if (NR_DMAP_REGS == 1) | |
895 | /* Registers DMAP0 and DMAP1 are constant. Just return dmap2. */ | |
896 | fprintf_filtered (file, " DMAP %04lx\n", d10v_dmap_register (2)); | |
897 | else | |
898 | { | |
899 | for (a = 0; a < NR_DMAP_REGS; a++) | |
900 | { | |
901 | fprintf_filtered (file, " DMAP%d %04lx", a, d10v_dmap_register (a)); | |
902 | } | |
903 | fprintf_filtered (file, "\n"); | |
904 | } | |
905 | } | |
906 | ||
907 | { | |
908 | char *num = alloca (max_register_size (gdbarch)); | |
909 | int a; | |
910 | fprintf_filtered (file, "A0-A%d", NR_A_REGS - 1); | |
6789195b AC |
911 | for (a = A0_REGNUM; a < A0_REGNUM + NR_A_REGS; a++) |
912 | { | |
913 | int i; | |
5f601589 AC |
914 | fprintf_filtered (file, " "); |
915 | frame_register_read (frame, a, num); | |
08a617da | 916 | for (i = 0; i < max_register_size (current_gdbarch); i++) |
6789195b | 917 | { |
5f601589 | 918 | fprintf_filtered (file, "%02x", (num[i] & 0xff)); |
6789195b AC |
919 | } |
920 | } | |
921 | } | |
5f601589 AC |
922 | fprintf_filtered (file, "\n"); |
923 | } | |
924 | ||
925 | static void | |
926 | show_regs (char *args, int from_tty) | |
927 | { | |
928 | d10v_print_registers_info (current_gdbarch, gdb_stdout, | |
929 | get_current_frame (), -1, 1); | |
c906108c SS |
930 | } |
931 | ||
f5e1cf12 | 932 | static CORE_ADDR |
39f77062 | 933 | d10v_read_pc (ptid_t ptid) |
c906108c | 934 | { |
39f77062 | 935 | ptid_t save_ptid; |
c906108c SS |
936 | CORE_ADDR pc; |
937 | CORE_ADDR retval; | |
938 | ||
39f77062 KB |
939 | save_ptid = inferior_ptid; |
940 | inferior_ptid = ptid; | |
c906108c | 941 | pc = (int) read_register (PC_REGNUM); |
39f77062 | 942 | inferior_ptid = save_ptid; |
7b570125 | 943 | retval = d10v_make_iaddr (pc); |
c906108c SS |
944 | return retval; |
945 | } | |
946 | ||
f5e1cf12 | 947 | static void |
39f77062 | 948 | d10v_write_pc (CORE_ADDR val, ptid_t ptid) |
c906108c | 949 | { |
39f77062 | 950 | ptid_t save_ptid; |
c906108c | 951 | |
39f77062 KB |
952 | save_ptid = inferior_ptid; |
953 | inferior_ptid = ptid; | |
7b570125 | 954 | write_register (PC_REGNUM, d10v_convert_iaddr_to_raw (val)); |
39f77062 | 955 | inferior_ptid = save_ptid; |
c906108c SS |
956 | } |
957 | ||
f5e1cf12 | 958 | static CORE_ADDR |
fba45db2 | 959 | d10v_read_sp (void) |
c906108c | 960 | { |
7b570125 | 961 | return (d10v_make_daddr (read_register (SP_REGNUM))); |
c906108c SS |
962 | } |
963 | ||
f5e1cf12 | 964 | static void |
fba45db2 | 965 | d10v_write_sp (CORE_ADDR val) |
c906108c | 966 | { |
7b570125 | 967 | write_register (SP_REGNUM, d10v_convert_daddr_to_raw (val)); |
c906108c SS |
968 | } |
969 | ||
f5e1cf12 | 970 | static CORE_ADDR |
fba45db2 | 971 | d10v_read_fp (void) |
c906108c | 972 | { |
7b570125 | 973 | return (d10v_make_daddr (read_register (FP_REGNUM))); |
c906108c SS |
974 | } |
975 | ||
976 | /* Function: push_return_address (pc) | |
977 | Set up the return address for the inferior function call. | |
978 | Needed for targets where we don't actually execute a JSR/BSR instruction */ | |
c5aa993b | 979 | |
f5e1cf12 | 980 | static CORE_ADDR |
fba45db2 | 981 | d10v_push_return_address (CORE_ADDR pc, CORE_ADDR sp) |
c906108c | 982 | { |
7b570125 | 983 | write_register (LR_REGNUM, d10v_convert_iaddr_to_raw (CALL_DUMMY_ADDRESS ())); |
c906108c SS |
984 | return sp; |
985 | } | |
c5aa993b | 986 | |
c906108c | 987 | |
7a292a7a SS |
988 | /* When arguments must be pushed onto the stack, they go on in reverse |
989 | order. The below implements a FILO (stack) to do this. */ | |
990 | ||
991 | struct stack_item | |
992 | { | |
993 | int len; | |
994 | struct stack_item *prev; | |
995 | void *data; | |
996 | }; | |
997 | ||
a14ed312 KB |
998 | static struct stack_item *push_stack_item (struct stack_item *prev, |
999 | void *contents, int len); | |
7a292a7a | 1000 | static struct stack_item * |
fba45db2 | 1001 | push_stack_item (struct stack_item *prev, void *contents, int len) |
7a292a7a SS |
1002 | { |
1003 | struct stack_item *si; | |
1004 | si = xmalloc (sizeof (struct stack_item)); | |
1005 | si->data = xmalloc (len); | |
1006 | si->len = len; | |
1007 | si->prev = prev; | |
1008 | memcpy (si->data, contents, len); | |
1009 | return si; | |
1010 | } | |
1011 | ||
a14ed312 | 1012 | static struct stack_item *pop_stack_item (struct stack_item *si); |
7a292a7a | 1013 | static struct stack_item * |
fba45db2 | 1014 | pop_stack_item (struct stack_item *si) |
7a292a7a SS |
1015 | { |
1016 | struct stack_item *dead = si; | |
1017 | si = si->prev; | |
b8c9b27d KB |
1018 | xfree (dead->data); |
1019 | xfree (dead); | |
7a292a7a SS |
1020 | return si; |
1021 | } | |
1022 | ||
1023 | ||
f5e1cf12 | 1024 | static CORE_ADDR |
ea7c478f | 1025 | d10v_push_arguments (int nargs, struct value **args, CORE_ADDR sp, |
fba45db2 | 1026 | int struct_return, CORE_ADDR struct_addr) |
c906108c SS |
1027 | { |
1028 | int i; | |
1029 | int regnum = ARG1_REGNUM; | |
7a292a7a | 1030 | struct stack_item *si = NULL; |
7bd91a28 MS |
1031 | long val; |
1032 | ||
1033 | /* If struct_return is true, then the struct return address will | |
1034 | consume one argument-passing register. No need to actually | |
1035 | write the value to the register -- that's done by | |
1036 | d10v_store_struct_return(). */ | |
1037 | ||
1038 | if (struct_return) | |
1039 | regnum++; | |
c5aa993b | 1040 | |
c906108c SS |
1041 | /* Fill in registers and arg lists */ |
1042 | for (i = 0; i < nargs; i++) | |
1043 | { | |
ea7c478f | 1044 | struct value *arg = args[i]; |
c906108c SS |
1045 | struct type *type = check_typedef (VALUE_TYPE (arg)); |
1046 | char *contents = VALUE_CONTENTS (arg); | |
1047 | int len = TYPE_LENGTH (type); | |
7bd91a28 MS |
1048 | int aligned_regnum = (regnum + 1) & ~1; |
1049 | ||
8b279e7a | 1050 | /* printf ("push: type=%d len=%d\n", TYPE_CODE (type), len); */ |
7bd91a28 MS |
1051 | if (len <= 2 && regnum <= ARGN_REGNUM) |
1052 | /* fits in a single register, do not align */ | |
1053 | { | |
1054 | val = extract_unsigned_integer (contents, len); | |
1055 | write_register (regnum++, val); | |
1056 | } | |
1057 | else if (len <= (ARGN_REGNUM - aligned_regnum + 1) * 2) | |
1058 | /* value fits in remaining registers, store keeping left | |
1059 | aligned */ | |
c906108c | 1060 | { |
7bd91a28 MS |
1061 | int b; |
1062 | regnum = aligned_regnum; | |
1063 | for (b = 0; b < (len & ~1); b += 2) | |
c906108c | 1064 | { |
7bd91a28 | 1065 | val = extract_unsigned_integer (&contents[b], 2); |
c906108c SS |
1066 | write_register (regnum++, val); |
1067 | } | |
7bd91a28 | 1068 | if (b < len) |
c906108c | 1069 | { |
7bd91a28 MS |
1070 | val = extract_unsigned_integer (&contents[b], 1); |
1071 | write_register (regnum++, (val << 8)); | |
c906108c SS |
1072 | } |
1073 | } | |
7bd91a28 MS |
1074 | else |
1075 | { | |
1076 | /* arg will go onto stack */ | |
1077 | regnum = ARGN_REGNUM + 1; | |
1078 | si = push_stack_item (si, contents, len); | |
1079 | } | |
c906108c | 1080 | } |
7a292a7a SS |
1081 | |
1082 | while (si) | |
1083 | { | |
1084 | sp = (sp - si->len) & ~1; | |
1085 | write_memory (sp, si->data, si->len); | |
1086 | si = pop_stack_item (si); | |
1087 | } | |
c5aa993b | 1088 | |
c906108c SS |
1089 | return sp; |
1090 | } | |
1091 | ||
1092 | ||
1093 | /* Given a return value in `regbuf' with a type `valtype', | |
1094 | extract and copy its value into `valbuf'. */ | |
1095 | ||
f5e1cf12 | 1096 | static void |
fa1fd571 AC |
1097 | d10v_extract_return_value (struct type *type, struct regcache *regcache, |
1098 | void *valbuf) | |
c906108c SS |
1099 | { |
1100 | int len; | |
3d79a47c MS |
1101 | #if 0 |
1102 | printf("RET: TYPE=%d len=%d r%d=0x%x\n", TYPE_CODE (type), | |
1103 | TYPE_LENGTH (type), RET1_REGNUM - R0_REGNUM, | |
1104 | (int) extract_unsigned_integer (regbuf + REGISTER_BYTE(RET1_REGNUM), | |
08a617da | 1105 | register_size (current_gdbarch, RET1_REGNUM))); |
3d79a47c | 1106 | #endif |
fa1fd571 | 1107 | if (TYPE_LENGTH (type) == 1) |
c906108c | 1108 | { |
fa1fd571 AC |
1109 | ULONGEST c; |
1110 | regcache_cooked_read_unsigned (regcache, RET1_REGNUM, &c); | |
3d79a47c MS |
1111 | store_unsigned_integer (valbuf, 1, c); |
1112 | } | |
3d79a47c MS |
1113 | else |
1114 | { | |
1115 | /* For return values of odd size, the first byte is in the | |
1116 | least significant part of the first register. The | |
fa1fd571 AC |
1117 | remaining bytes in remaining registers. Interestingly, when |
1118 | such values are passed in, the last byte is in the most | |
1119 | significant byte of that same register - wierd. */ | |
1120 | int reg = RET1_REGNUM; | |
1121 | int off = 0; | |
1122 | if (TYPE_LENGTH (type) & 1) | |
1123 | { | |
1124 | regcache_cooked_read_part (regcache, RET1_REGNUM, 1, 1, | |
1125 | (bfd_byte *)valbuf + off); | |
1126 | off++; | |
1127 | reg++; | |
1128 | } | |
1129 | /* Transfer the remaining registers. */ | |
1130 | for (; off < TYPE_LENGTH (type); reg++, off += 2) | |
1131 | { | |
1132 | regcache_cooked_read (regcache, RET1_REGNUM + reg, | |
1133 | (bfd_byte *) valbuf + off); | |
1134 | } | |
c906108c SS |
1135 | } |
1136 | } | |
1137 | ||
c2c6d25f JM |
1138 | /* Translate a GDB virtual ADDR/LEN into a format the remote target |
1139 | understands. Returns number of bytes that can be transfered | |
4ce44c66 JM |
1140 | starting at TARG_ADDR. Return ZERO if no bytes can be transfered |
1141 | (segmentation fault). Since the simulator knows all about how the | |
1142 | VM system works, we just call that to do the translation. */ | |
c2c6d25f | 1143 | |
4ce44c66 | 1144 | static void |
c2c6d25f JM |
1145 | remote_d10v_translate_xfer_address (CORE_ADDR memaddr, int nr_bytes, |
1146 | CORE_ADDR *targ_addr, int *targ_len) | |
1147 | { | |
4ce44c66 JM |
1148 | long out_addr; |
1149 | long out_len; | |
1150 | out_len = sim_d10v_translate_addr (memaddr, nr_bytes, | |
1151 | &out_addr, | |
1152 | d10v_dmap_register, | |
1153 | d10v_imap_register); | |
1154 | *targ_addr = out_addr; | |
1155 | *targ_len = out_len; | |
c2c6d25f JM |
1156 | } |
1157 | ||
4ce44c66 | 1158 | |
c906108c SS |
1159 | /* The following code implements access to, and display of, the D10V's |
1160 | instruction trace buffer. The buffer consists of 64K or more | |
1161 | 4-byte words of data, of which each words includes an 8-bit count, | |
1162 | an 8-bit segment number, and a 16-bit instruction address. | |
1163 | ||
1164 | In theory, the trace buffer is continuously capturing instruction | |
1165 | data that the CPU presents on its "debug bus", but in practice, the | |
1166 | ROMified GDB stub only enables tracing when it continues or steps | |
1167 | the program, and stops tracing when the program stops; so it | |
1168 | actually works for GDB to read the buffer counter out of memory and | |
1169 | then read each trace word. The counter records where the tracing | |
1170 | stops, but there is no record of where it started, so we remember | |
1171 | the PC when we resumed and then search backwards in the trace | |
1172 | buffer for a word that includes that address. This is not perfect, | |
1173 | because you will miss trace data if the resumption PC is the target | |
1174 | of a branch. (The value of the buffer counter is semi-random, any | |
1175 | trace data from a previous program stop is gone.) */ | |
1176 | ||
1177 | /* The address of the last word recorded in the trace buffer. */ | |
1178 | ||
1179 | #define DBBC_ADDR (0xd80000) | |
1180 | ||
1181 | /* The base of the trace buffer, at least for the "Board_0". */ | |
1182 | ||
1183 | #define TRACE_BUFFER_BASE (0xf40000) | |
1184 | ||
a14ed312 | 1185 | static void trace_command (char *, int); |
c906108c | 1186 | |
a14ed312 | 1187 | static void untrace_command (char *, int); |
c906108c | 1188 | |
a14ed312 | 1189 | static void trace_info (char *, int); |
c906108c | 1190 | |
a14ed312 | 1191 | static void tdisassemble_command (char *, int); |
c906108c | 1192 | |
a14ed312 | 1193 | static void display_trace (int, int); |
c906108c SS |
1194 | |
1195 | /* True when instruction traces are being collected. */ | |
1196 | ||
1197 | static int tracing; | |
1198 | ||
1199 | /* Remembered PC. */ | |
1200 | ||
1201 | static CORE_ADDR last_pc; | |
1202 | ||
1203 | /* True when trace output should be displayed whenever program stops. */ | |
1204 | ||
1205 | static int trace_display; | |
1206 | ||
1207 | /* True when trace listing should include source lines. */ | |
1208 | ||
1209 | static int default_trace_show_source = 1; | |
1210 | ||
c5aa993b JM |
1211 | struct trace_buffer |
1212 | { | |
1213 | int size; | |
1214 | short *counts; | |
1215 | CORE_ADDR *addrs; | |
1216 | } | |
1217 | trace_data; | |
c906108c SS |
1218 | |
1219 | static void | |
fba45db2 | 1220 | trace_command (char *args, int from_tty) |
c906108c SS |
1221 | { |
1222 | /* Clear the host-side trace buffer, allocating space if needed. */ | |
1223 | trace_data.size = 0; | |
1224 | if (trace_data.counts == NULL) | |
c5aa993b | 1225 | trace_data.counts = (short *) xmalloc (65536 * sizeof (short)); |
c906108c | 1226 | if (trace_data.addrs == NULL) |
c5aa993b | 1227 | trace_data.addrs = (CORE_ADDR *) xmalloc (65536 * sizeof (CORE_ADDR)); |
c906108c SS |
1228 | |
1229 | tracing = 1; | |
1230 | ||
1231 | printf_filtered ("Tracing is now on.\n"); | |
1232 | } | |
1233 | ||
1234 | static void | |
fba45db2 | 1235 | untrace_command (char *args, int from_tty) |
c906108c SS |
1236 | { |
1237 | tracing = 0; | |
1238 | ||
1239 | printf_filtered ("Tracing is now off.\n"); | |
1240 | } | |
1241 | ||
1242 | static void | |
fba45db2 | 1243 | trace_info (char *args, int from_tty) |
c906108c SS |
1244 | { |
1245 | int i; | |
1246 | ||
1247 | if (trace_data.size) | |
1248 | { | |
1249 | printf_filtered ("%d entries in trace buffer:\n", trace_data.size); | |
1250 | ||
1251 | for (i = 0; i < trace_data.size; ++i) | |
1252 | { | |
d4f3574e SS |
1253 | printf_filtered ("%d: %d instruction%s at 0x%s\n", |
1254 | i, | |
1255 | trace_data.counts[i], | |
c906108c | 1256 | (trace_data.counts[i] == 1 ? "" : "s"), |
d4f3574e | 1257 | paddr_nz (trace_data.addrs[i])); |
c906108c SS |
1258 | } |
1259 | } | |
1260 | else | |
1261 | printf_filtered ("No entries in trace buffer.\n"); | |
1262 | ||
1263 | printf_filtered ("Tracing is currently %s.\n", (tracing ? "on" : "off")); | |
1264 | } | |
1265 | ||
1266 | /* Print the instruction at address MEMADDR in debugged memory, | |
1267 | on STREAM. Returns length of the instruction, in bytes. */ | |
1268 | ||
1269 | static int | |
fba45db2 | 1270 | print_insn (CORE_ADDR memaddr, struct ui_file *stream) |
c906108c SS |
1271 | { |
1272 | /* If there's no disassembler, something is very wrong. */ | |
1273 | if (tm_print_insn == NULL) | |
8e65ff28 AC |
1274 | internal_error (__FILE__, __LINE__, |
1275 | "print_insn: no disassembler"); | |
c906108c | 1276 | |
d7449b42 | 1277 | if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) |
c906108c SS |
1278 | tm_print_insn_info.endian = BFD_ENDIAN_BIG; |
1279 | else | |
1280 | tm_print_insn_info.endian = BFD_ENDIAN_LITTLE; | |
2bf0cb65 | 1281 | return TARGET_PRINT_INSN (memaddr, &tm_print_insn_info); |
c906108c SS |
1282 | } |
1283 | ||
392a587b | 1284 | static void |
fba45db2 | 1285 | d10v_eva_prepare_to_trace (void) |
c906108c SS |
1286 | { |
1287 | if (!tracing) | |
1288 | return; | |
1289 | ||
1290 | last_pc = read_register (PC_REGNUM); | |
1291 | } | |
1292 | ||
1293 | /* Collect trace data from the target board and format it into a form | |
1294 | more useful for display. */ | |
1295 | ||
392a587b | 1296 | static void |
fba45db2 | 1297 | d10v_eva_get_trace_data (void) |
c906108c SS |
1298 | { |
1299 | int count, i, j, oldsize; | |
1300 | int trace_addr, trace_seg, trace_cnt, next_cnt; | |
1301 | unsigned int last_trace, trace_word, next_word; | |
1302 | unsigned int *tmpspace; | |
1303 | ||
1304 | if (!tracing) | |
1305 | return; | |
1306 | ||
c5aa993b | 1307 | tmpspace = xmalloc (65536 * sizeof (unsigned int)); |
c906108c SS |
1308 | |
1309 | last_trace = read_memory_unsigned_integer (DBBC_ADDR, 2) << 2; | |
1310 | ||
1311 | /* Collect buffer contents from the target, stopping when we reach | |
1312 | the word recorded when execution resumed. */ | |
1313 | ||
1314 | count = 0; | |
1315 | while (last_trace > 0) | |
1316 | { | |
1317 | QUIT; | |
1318 | trace_word = | |
1319 | read_memory_unsigned_integer (TRACE_BUFFER_BASE + last_trace, 4); | |
1320 | trace_addr = trace_word & 0xffff; | |
1321 | last_trace -= 4; | |
1322 | /* Ignore an apparently nonsensical entry. */ | |
1323 | if (trace_addr == 0xffd5) | |
1324 | continue; | |
1325 | tmpspace[count++] = trace_word; | |
1326 | if (trace_addr == last_pc) | |
1327 | break; | |
1328 | if (count > 65535) | |
1329 | break; | |
1330 | } | |
1331 | ||
1332 | /* Move the data to the host-side trace buffer, adjusting counts to | |
1333 | include the last instruction executed and transforming the address | |
1334 | into something that GDB likes. */ | |
1335 | ||
1336 | for (i = 0; i < count; ++i) | |
1337 | { | |
1338 | trace_word = tmpspace[i]; | |
1339 | next_word = ((i == 0) ? 0 : tmpspace[i - 1]); | |
1340 | trace_addr = trace_word & 0xffff; | |
1341 | next_cnt = (next_word >> 24) & 0xff; | |
1342 | j = trace_data.size + count - i - 1; | |
1343 | trace_data.addrs[j] = (trace_addr << 2) + 0x1000000; | |
1344 | trace_data.counts[j] = next_cnt + 1; | |
1345 | } | |
1346 | ||
1347 | oldsize = trace_data.size; | |
1348 | trace_data.size += count; | |
1349 | ||
b8c9b27d | 1350 | xfree (tmpspace); |
c906108c SS |
1351 | |
1352 | if (trace_display) | |
1353 | display_trace (oldsize, trace_data.size); | |
1354 | } | |
1355 | ||
1356 | static void | |
fba45db2 | 1357 | tdisassemble_command (char *arg, int from_tty) |
c906108c SS |
1358 | { |
1359 | int i, count; | |
1360 | CORE_ADDR low, high; | |
1361 | char *space_index; | |
1362 | ||
1363 | if (!arg) | |
1364 | { | |
1365 | low = 0; | |
1366 | high = trace_data.size; | |
1367 | } | |
1368 | else if (!(space_index = (char *) strchr (arg, ' '))) | |
1369 | { | |
1370 | low = parse_and_eval_address (arg); | |
1371 | high = low + 5; | |
1372 | } | |
1373 | else | |
1374 | { | |
1375 | /* Two arguments. */ | |
1376 | *space_index = '\0'; | |
1377 | low = parse_and_eval_address (arg); | |
1378 | high = parse_and_eval_address (space_index + 1); | |
1379 | if (high < low) | |
1380 | high = low; | |
1381 | } | |
1382 | ||
d4f3574e | 1383 | printf_filtered ("Dump of trace from %s to %s:\n", paddr_u (low), paddr_u (high)); |
c906108c SS |
1384 | |
1385 | display_trace (low, high); | |
1386 | ||
1387 | printf_filtered ("End of trace dump.\n"); | |
1388 | gdb_flush (gdb_stdout); | |
1389 | } | |
1390 | ||
1391 | static void | |
fba45db2 | 1392 | display_trace (int low, int high) |
c906108c SS |
1393 | { |
1394 | int i, count, trace_show_source, first, suppress; | |
1395 | CORE_ADDR next_address; | |
1396 | ||
1397 | trace_show_source = default_trace_show_source; | |
c5aa993b | 1398 | if (!have_full_symbols () && !have_partial_symbols ()) |
c906108c SS |
1399 | { |
1400 | trace_show_source = 0; | |
1401 | printf_filtered ("No symbol table is loaded. Use the \"file\" command.\n"); | |
1402 | printf_filtered ("Trace will not display any source.\n"); | |
1403 | } | |
1404 | ||
1405 | first = 1; | |
1406 | suppress = 0; | |
1407 | for (i = low; i < high; ++i) | |
1408 | { | |
1409 | next_address = trace_data.addrs[i]; | |
c5aa993b | 1410 | count = trace_data.counts[i]; |
c906108c SS |
1411 | while (count-- > 0) |
1412 | { | |
1413 | QUIT; | |
1414 | if (trace_show_source) | |
1415 | { | |
1416 | struct symtab_and_line sal, sal_prev; | |
1417 | ||
1418 | sal_prev = find_pc_line (next_address - 4, 0); | |
1419 | sal = find_pc_line (next_address, 0); | |
1420 | ||
1421 | if (sal.symtab) | |
1422 | { | |
1423 | if (first || sal.line != sal_prev.line) | |
1424 | print_source_lines (sal.symtab, sal.line, sal.line + 1, 0); | |
1425 | suppress = 0; | |
1426 | } | |
1427 | else | |
1428 | { | |
1429 | if (!suppress) | |
1430 | /* FIXME-32x64--assumes sal.pc fits in long. */ | |
1431 | printf_filtered ("No source file for address %s.\n", | |
c5aa993b | 1432 | local_hex_string ((unsigned long) sal.pc)); |
c906108c SS |
1433 | suppress = 1; |
1434 | } | |
1435 | } | |
1436 | first = 0; | |
1437 | print_address (next_address, gdb_stdout); | |
1438 | printf_filtered (":"); | |
1439 | printf_filtered ("\t"); | |
1440 | wrap_here (" "); | |
1441 | next_address = next_address + print_insn (next_address, gdb_stdout); | |
1442 | printf_filtered ("\n"); | |
1443 | gdb_flush (gdb_stdout); | |
1444 | } | |
1445 | } | |
1446 | } | |
1447 | ||
7f6104a9 | 1448 | static CORE_ADDR |
12cc2063 | 1449 | d10v_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) |
7f6104a9 | 1450 | { |
12cc2063 AC |
1451 | ULONGEST pc; |
1452 | frame_unwind_unsigned_register (next_frame, PC_REGNUM, &pc); | |
1453 | return d10v_make_iaddr (pc); | |
7f6104a9 AC |
1454 | } |
1455 | ||
1456 | /* Given a GDB frame, determine the address of the calling function's | |
1457 | frame. This will be used to create a new GDB frame struct. */ | |
1458 | ||
1459 | static void | |
6dc42492 AC |
1460 | d10v_frame_this_id (struct frame_info *next_frame, |
1461 | void **this_prologue_cache, | |
1462 | struct frame_id *this_id) | |
7f6104a9 | 1463 | { |
6dc42492 AC |
1464 | struct d10v_unwind_cache *info |
1465 | = d10v_frame_unwind_cache (next_frame, this_prologue_cache); | |
1466 | CORE_ADDR base; | |
1467 | CORE_ADDR pc; | |
7f6104a9 AC |
1468 | |
1469 | /* Start with a NULL frame ID. */ | |
6dc42492 | 1470 | (*this_id) = null_frame_id; |
7f6104a9 | 1471 | |
6dc42492 AC |
1472 | /* The PC is easy. */ |
1473 | pc = frame_pc_unwind (next_frame); | |
7f6104a9 | 1474 | |
6dc42492 AC |
1475 | /* This is meant to halt the backtrace at "_start". Make sure we |
1476 | don't halt it at a generic dummy frame. */ | |
1477 | if (pc == IMEM_START || pc <= IMEM_START || inside_entry_file (pc)) | |
1478 | return; | |
7f6104a9 | 1479 | |
6dc42492 AC |
1480 | /* Hopefully the prologue analysis either correctly determined the |
1481 | frame's base (which is the SP from the previous frame), or set | |
1482 | that base to "NULL". */ | |
1483 | base = info->base; | |
1484 | if (base == STACK_START || base == 0) | |
1485 | return; | |
7f6104a9 | 1486 | |
6dc42492 AC |
1487 | /* Check that we're not going round in circles with the same frame |
1488 | ID (but avoid applying the test to sentinel frames which do go | |
1489 | round in circles). Can't use frame_id_eq() as that doesn't yet | |
1490 | compare the frame's PC value. */ | |
1491 | if (frame_relative_level (next_frame) >= 0 | |
1492 | && get_frame_type (next_frame) != DUMMY_FRAME | |
1493 | && get_frame_id (next_frame).pc == pc | |
1494 | && get_frame_id (next_frame).base == base) | |
7f6104a9 AC |
1495 | return; |
1496 | ||
6dc42492 AC |
1497 | this_id->base = base; |
1498 | this_id->pc = pc; | |
7f6104a9 AC |
1499 | } |
1500 | ||
1501 | static void | |
6dc42492 AC |
1502 | saved_regs_unwinder (struct frame_info *next_frame, |
1503 | CORE_ADDR *this_saved_regs, | |
7f6104a9 AC |
1504 | int regnum, int *optimizedp, |
1505 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
1506 | int *realnump, void *bufferp) | |
1507 | { | |
6dc42492 | 1508 | if (this_saved_regs[regnum] != 0) |
7f6104a9 AC |
1509 | { |
1510 | if (regnum == SP_REGNUM) | |
1511 | { | |
1512 | /* SP register treated specially. */ | |
1513 | *optimizedp = 0; | |
1514 | *lvalp = not_lval; | |
1515 | *addrp = 0; | |
1516 | *realnump = -1; | |
1517 | if (bufferp != NULL) | |
08a617da | 1518 | store_address (bufferp, register_size (current_gdbarch, regnum), |
6dc42492 | 1519 | this_saved_regs[regnum]); |
7f6104a9 AC |
1520 | } |
1521 | else | |
1522 | { | |
1523 | /* Any other register is saved in memory, fetch it but cache | |
1524 | a local copy of its value. */ | |
1525 | *optimizedp = 0; | |
1526 | *lvalp = lval_memory; | |
6dc42492 | 1527 | *addrp = this_saved_regs[regnum]; |
7f6104a9 AC |
1528 | *realnump = -1; |
1529 | if (bufferp != NULL) | |
1530 | { | |
1531 | /* Read the value in from memory. */ | |
6dc42492 | 1532 | read_memory (this_saved_regs[regnum], bufferp, |
08a617da | 1533 | register_size (current_gdbarch, regnum)); |
7f6104a9 AC |
1534 | } |
1535 | } | |
1536 | return; | |
1537 | } | |
1538 | ||
1539 | /* No luck, assume this and the next frame have the same register | |
1540 | value. If a value is needed, pass the request on down the chain; | |
1541 | otherwise just return an indication that the value is in the same | |
1542 | register as the next frame. */ | |
6dc42492 AC |
1543 | frame_register_unwind (next_frame, regnum, optimizedp, lvalp, addrp, |
1544 | realnump, bufferp); | |
7f6104a9 AC |
1545 | } |
1546 | ||
1547 | ||
1548 | static void | |
6dc42492 AC |
1549 | d10v_frame_prev_register (struct frame_info *next_frame, |
1550 | void **this_prologue_cache, | |
1551 | int regnum, int *optimizedp, | |
1552 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
1553 | int *realnump, void *bufferp) | |
7f6104a9 | 1554 | { |
6dc42492 AC |
1555 | struct d10v_unwind_cache *info |
1556 | = d10v_frame_unwind_cache (next_frame, this_prologue_cache); | |
ef840a37 AC |
1557 | if (regnum == PC_REGNUM) |
1558 | { | |
1559 | /* The call instruction saves the caller's PC in LR. The | |
1560 | function prologue of the callee may then save the LR on the | |
1561 | stack. Find that possibly saved LR value and return it. */ | |
6dc42492 | 1562 | saved_regs_unwinder (next_frame, info->saved_regs, LR_REGNUM, optimizedp, |
ef840a37 AC |
1563 | lvalp, addrp, realnump, bufferp); |
1564 | } | |
1565 | else | |
1566 | { | |
6dc42492 | 1567 | saved_regs_unwinder (next_frame, info->saved_regs, regnum, optimizedp, |
ef840a37 AC |
1568 | lvalp, addrp, realnump, bufferp); |
1569 | } | |
7f6104a9 AC |
1570 | } |
1571 | ||
1572 | ||
7f6104a9 | 1573 | static struct frame_unwind d10v_frame_unwind = { |
6dc42492 AC |
1574 | d10v_frame_this_id, |
1575 | d10v_frame_prev_register | |
7f6104a9 AC |
1576 | }; |
1577 | ||
1578 | const struct frame_unwind * | |
1579 | d10v_frame_p (CORE_ADDR pc) | |
1580 | { | |
1581 | return &d10v_frame_unwind; | |
1582 | } | |
1583 | ||
6314f104 AC |
1584 | /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that |
1585 | dummy frame. The frame ID's base needs to match the TOS value | |
1586 | saved by save_dummy_frame_tos(), and the PC match the dummy frame's | |
1587 | breakpoint. */ | |
1588 | ||
1589 | static struct frame_id | |
1590 | d10v_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame) | |
1591 | { | |
1592 | ULONGEST base; | |
1593 | struct frame_id id; | |
1594 | id.pc = frame_pc_unwind (next_frame); | |
1595 | frame_unwind_unsigned_register (next_frame, SP_REGNUM, &base); | |
1596 | id.base = d10v_make_daddr (base); | |
1597 | return id; | |
1598 | } | |
1599 | ||
0f71a2f6 | 1600 | static gdbarch_init_ftype d10v_gdbarch_init; |
4ce44c66 | 1601 | |
0f71a2f6 | 1602 | static struct gdbarch * |
fba45db2 | 1603 | d10v_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
0f71a2f6 | 1604 | { |
c5aa993b JM |
1605 | static LONGEST d10v_call_dummy_words[] = |
1606 | {0}; | |
0f71a2f6 | 1607 | struct gdbarch *gdbarch; |
4ce44c66 JM |
1608 | int d10v_num_regs; |
1609 | struct gdbarch_tdep *tdep; | |
1610 | gdbarch_register_name_ftype *d10v_register_name; | |
7c7651b2 | 1611 | gdbarch_register_sim_regno_ftype *d10v_register_sim_regno; |
0f71a2f6 | 1612 | |
4ce44c66 JM |
1613 | /* Find a candidate among the list of pre-declared architectures. */ |
1614 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
0f71a2f6 JM |
1615 | if (arches != NULL) |
1616 | return arches->gdbarch; | |
4ce44c66 JM |
1617 | |
1618 | /* None found, create a new architecture from the information | |
1619 | provided. */ | |
1620 | tdep = XMALLOC (struct gdbarch_tdep); | |
1621 | gdbarch = gdbarch_alloc (&info, tdep); | |
1622 | ||
1623 | switch (info.bfd_arch_info->mach) | |
1624 | { | |
1625 | case bfd_mach_d10v_ts2: | |
1626 | d10v_num_regs = 37; | |
1627 | d10v_register_name = d10v_ts2_register_name; | |
7c7651b2 | 1628 | d10v_register_sim_regno = d10v_ts2_register_sim_regno; |
4ce44c66 JM |
1629 | tdep->a0_regnum = TS2_A0_REGNUM; |
1630 | tdep->nr_dmap_regs = TS2_NR_DMAP_REGS; | |
4ce44c66 JM |
1631 | tdep->dmap_register = d10v_ts2_dmap_register; |
1632 | tdep->imap_register = d10v_ts2_imap_register; | |
1633 | break; | |
1634 | default: | |
1635 | case bfd_mach_d10v_ts3: | |
1636 | d10v_num_regs = 42; | |
1637 | d10v_register_name = d10v_ts3_register_name; | |
7c7651b2 | 1638 | d10v_register_sim_regno = d10v_ts3_register_sim_regno; |
4ce44c66 JM |
1639 | tdep->a0_regnum = TS3_A0_REGNUM; |
1640 | tdep->nr_dmap_regs = TS3_NR_DMAP_REGS; | |
4ce44c66 JM |
1641 | tdep->dmap_register = d10v_ts3_dmap_register; |
1642 | tdep->imap_register = d10v_ts3_imap_register; | |
1643 | break; | |
1644 | } | |
0f71a2f6 JM |
1645 | |
1646 | set_gdbarch_read_pc (gdbarch, d10v_read_pc); | |
1647 | set_gdbarch_write_pc (gdbarch, d10v_write_pc); | |
1648 | set_gdbarch_read_fp (gdbarch, d10v_read_fp); | |
0f71a2f6 JM |
1649 | set_gdbarch_read_sp (gdbarch, d10v_read_sp); |
1650 | set_gdbarch_write_sp (gdbarch, d10v_write_sp); | |
1651 | ||
1652 | set_gdbarch_num_regs (gdbarch, d10v_num_regs); | |
1653 | set_gdbarch_sp_regnum (gdbarch, 15); | |
1654 | set_gdbarch_fp_regnum (gdbarch, 11); | |
1655 | set_gdbarch_pc_regnum (gdbarch, 18); | |
1656 | set_gdbarch_register_name (gdbarch, d10v_register_name); | |
1657 | set_gdbarch_register_size (gdbarch, 2); | |
1658 | set_gdbarch_register_bytes (gdbarch, (d10v_num_regs - 2) * 2 + 16); | |
1659 | set_gdbarch_register_byte (gdbarch, d10v_register_byte); | |
1660 | set_gdbarch_register_raw_size (gdbarch, d10v_register_raw_size); | |
8b279e7a | 1661 | set_gdbarch_register_virtual_size (gdbarch, generic_register_size); |
35cac7cf | 1662 | set_gdbarch_register_type (gdbarch, d10v_register_type); |
0f71a2f6 | 1663 | |
75af7f68 JB |
1664 | set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT); |
1665 | set_gdbarch_addr_bit (gdbarch, 32); | |
1666 | set_gdbarch_address_to_pointer (gdbarch, d10v_address_to_pointer); | |
1667 | set_gdbarch_pointer_to_address (gdbarch, d10v_pointer_to_address); | |
fc0c74b1 | 1668 | set_gdbarch_integer_to_address (gdbarch, d10v_integer_to_address); |
0f71a2f6 JM |
1669 | set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT); |
1670 | set_gdbarch_int_bit (gdbarch, 2 * TARGET_CHAR_BIT); | |
1671 | set_gdbarch_long_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
02da6206 | 1672 | set_gdbarch_long_long_bit (gdbarch, 8 * TARGET_CHAR_BIT); |
f0d4cc9e AC |
1673 | /* NOTE: The d10v as a 32 bit ``float'' and ``double''. ``long |
1674 | double'' is 64 bits. */ | |
0f71a2f6 JM |
1675 | set_gdbarch_float_bit (gdbarch, 4 * TARGET_CHAR_BIT); |
1676 | set_gdbarch_double_bit (gdbarch, 4 * TARGET_CHAR_BIT); | |
1677 | set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT); | |
f0d4cc9e AC |
1678 | switch (info.byte_order) |
1679 | { | |
d7449b42 | 1680 | case BFD_ENDIAN_BIG: |
f0d4cc9e AC |
1681 | set_gdbarch_float_format (gdbarch, &floatformat_ieee_single_big); |
1682 | set_gdbarch_double_format (gdbarch, &floatformat_ieee_single_big); | |
1683 | set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_big); | |
1684 | break; | |
778eb05e | 1685 | case BFD_ENDIAN_LITTLE: |
f0d4cc9e AC |
1686 | set_gdbarch_float_format (gdbarch, &floatformat_ieee_single_little); |
1687 | set_gdbarch_double_format (gdbarch, &floatformat_ieee_single_little); | |
1688 | set_gdbarch_long_double_format (gdbarch, &floatformat_ieee_double_little); | |
1689 | break; | |
1690 | default: | |
8e65ff28 AC |
1691 | internal_error (__FILE__, __LINE__, |
1692 | "d10v_gdbarch_init: bad byte order for float format"); | |
f0d4cc9e | 1693 | } |
0f71a2f6 | 1694 | |
0f71a2f6 | 1695 | set_gdbarch_call_dummy_length (gdbarch, 0); |
0f71a2f6 JM |
1696 | set_gdbarch_call_dummy_address (gdbarch, entry_point_address); |
1697 | set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1); | |
1698 | set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0); | |
1699 | set_gdbarch_call_dummy_start_offset (gdbarch, 0); | |
0f71a2f6 JM |
1700 | set_gdbarch_call_dummy_words (gdbarch, d10v_call_dummy_words); |
1701 | set_gdbarch_sizeof_call_dummy_words (gdbarch, sizeof (d10v_call_dummy_words)); | |
1702 | set_gdbarch_call_dummy_p (gdbarch, 1); | |
0f71a2f6 JM |
1703 | set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy); |
1704 | ||
fa1fd571 | 1705 | set_gdbarch_extract_return_value (gdbarch, d10v_extract_return_value); |
0f71a2f6 | 1706 | set_gdbarch_push_arguments (gdbarch, d10v_push_arguments); |
0f71a2f6 JM |
1707 | set_gdbarch_push_return_address (gdbarch, d10v_push_return_address); |
1708 | ||
0f71a2f6 | 1709 | set_gdbarch_store_struct_return (gdbarch, d10v_store_struct_return); |
fa1fd571 AC |
1710 | set_gdbarch_store_return_value (gdbarch, d10v_store_return_value); |
1711 | set_gdbarch_extract_struct_value_address (gdbarch, d10v_extract_struct_value_address); | |
0f71a2f6 JM |
1712 | set_gdbarch_use_struct_convention (gdbarch, d10v_use_struct_convention); |
1713 | ||
0f71a2f6 JM |
1714 | set_gdbarch_skip_prologue (gdbarch, d10v_skip_prologue); |
1715 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
1716 | set_gdbarch_decr_pc_after_break (gdbarch, 4); | |
1717 | set_gdbarch_function_start_offset (gdbarch, 0); | |
1718 | set_gdbarch_breakpoint_from_pc (gdbarch, d10v_breakpoint_from_pc); | |
1719 | ||
1720 | set_gdbarch_remote_translate_xfer_address (gdbarch, remote_d10v_translate_xfer_address); | |
1721 | ||
1722 | set_gdbarch_frame_args_skip (gdbarch, 0); | |
1723 | set_gdbarch_frameless_function_invocation (gdbarch, frameless_look_for_prologue); | |
f4ded5b1 | 1724 | |
0f71a2f6 JM |
1725 | set_gdbarch_saved_pc_after_call (gdbarch, d10v_saved_pc_after_call); |
1726 | set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown); | |
23964bcd | 1727 | set_gdbarch_stack_align (gdbarch, d10v_stack_align); |
0f71a2f6 | 1728 | |
7c7651b2 | 1729 | set_gdbarch_register_sim_regno (gdbarch, d10v_register_sim_regno); |
0a49d05e | 1730 | set_gdbarch_extra_stack_alignment_needed (gdbarch, 0); |
7c7651b2 | 1731 | |
5f601589 AC |
1732 | set_gdbarch_print_registers_info (gdbarch, d10v_print_registers_info); |
1733 | ||
7f6104a9 AC |
1734 | frame_unwind_append_predicate (gdbarch, d10v_frame_p); |
1735 | ||
6314f104 AC |
1736 | /* Methods for saving / extracting a dummy frame's ID. */ |
1737 | set_gdbarch_unwind_dummy_id (gdbarch, d10v_unwind_dummy_id); | |
1738 | set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos); | |
1739 | ||
12cc2063 AC |
1740 | /* Return the unwound PC value. */ |
1741 | set_gdbarch_unwind_pc (gdbarch, d10v_unwind_pc); | |
1742 | ||
0f71a2f6 JM |
1743 | return gdbarch; |
1744 | } | |
1745 | ||
1746 | ||
507f3c78 KB |
1747 | extern void (*target_resume_hook) (void); |
1748 | extern void (*target_wait_loop_hook) (void); | |
c906108c SS |
1749 | |
1750 | void | |
fba45db2 | 1751 | _initialize_d10v_tdep (void) |
c906108c | 1752 | { |
0f71a2f6 JM |
1753 | register_gdbarch_init (bfd_arch_d10v, d10v_gdbarch_init); |
1754 | ||
c906108c SS |
1755 | tm_print_insn = print_insn_d10v; |
1756 | ||
1757 | target_resume_hook = d10v_eva_prepare_to_trace; | |
1758 | target_wait_loop_hook = d10v_eva_get_trace_data; | |
1759 | ||
5f601589 AC |
1760 | deprecate_cmd (add_com ("regs", class_vars, show_regs, "Print all registers"), |
1761 | "info registers"); | |
c906108c | 1762 | |
cff3e48b | 1763 | add_com ("itrace", class_support, trace_command, |
c906108c SS |
1764 | "Enable tracing of instruction execution."); |
1765 | ||
cff3e48b | 1766 | add_com ("iuntrace", class_support, untrace_command, |
c906108c SS |
1767 | "Disable tracing of instruction execution."); |
1768 | ||
cff3e48b | 1769 | add_com ("itdisassemble", class_vars, tdisassemble_command, |
c906108c SS |
1770 | "Disassemble the trace buffer.\n\ |
1771 | Two optional arguments specify a range of trace buffer entries\n\ | |
1772 | as reported by info trace (NOT addresses!)."); | |
1773 | ||
cff3e48b | 1774 | add_info ("itrace", trace_info, |
c906108c SS |
1775 | "Display info about the trace data buffer."); |
1776 | ||
cff3e48b | 1777 | add_show_from_set (add_set_cmd ("itracedisplay", no_class, |
c5aa993b JM |
1778 | var_integer, (char *) &trace_display, |
1779 | "Set automatic display of trace.\n", &setlist), | |
c906108c | 1780 | &showlist); |
cff3e48b | 1781 | add_show_from_set (add_set_cmd ("itracesource", no_class, |
c5aa993b JM |
1782 | var_integer, (char *) &default_trace_show_source, |
1783 | "Set display of source code with trace.\n", &setlist), | |
c906108c SS |
1784 | &showlist); |
1785 | ||
c5aa993b | 1786 | } |