* simops.c (trace_result): Fix printf formatting.
[deliverable/binutils-gdb.git] / gdb / v850-tdep.c
CommitLineData
c906108c 1/* Target-dependent code for the NEC V850 for GDB, the GNU debugger.
435e042a 2 Copyright 1996, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
c906108c 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#include "defs.h"
22#include "frame.h"
23#include "inferior.h"
24#include "obstack.h"
25#include "target.h"
26#include "value.h"
27#include "bfd.h"
28#include "gdb_string.h"
29#include "gdbcore.h"
30#include "symfile.h"
b4a20239 31#include "arch-utils.h"
4e052eda 32#include "regcache.h"
435e042a 33#include "symtab.h"
c906108c 34
435e042a
CV
35struct gdbarch_tdep
36{
37 /* gdbarch target dependent data here. Currently unused for v850. */
38};
39
40/* Extra info which is saved in each frame_info. */
41struct frame_extra_info
42{
43};
c906108c 44
435e042a
CV
45enum {
46 E_R0_REGNUM,
47 E_R1_REGNUM,
48 E_R2_REGNUM, E_SAVE1_START_REGNUM = E_R2_REGNUM, E_SAVE1_END_REGNUM = E_R2_REGNUM,
49 E_R3_REGNUM, E_SP_REGNUM = E_R3_REGNUM,
50 E_R4_REGNUM,
51 E_R5_REGNUM,
52 E_R6_REGNUM, E_ARG0_REGNUM = E_R6_REGNUM,
53 E_R7_REGNUM,
54 E_R8_REGNUM,
55 E_R9_REGNUM, E_ARGLAST_REGNUM = E_R9_REGNUM,
56 E_R10_REGNUM, E_V0_REGNUM = E_R10_REGNUM,
57 E_R11_REGNUM, E_V1_REGNUM = E_R11_REGNUM,
58 E_R12_REGNUM,
59 E_R13_REGNUM,
60 E_R14_REGNUM,
61 E_R15_REGNUM,
62 E_R16_REGNUM,
63 E_R17_REGNUM,
64 E_R18_REGNUM,
65 E_R19_REGNUM,
66 E_R20_REGNUM, E_SAVE2_START_REGNUM = E_R20_REGNUM,
67 E_R21_REGNUM,
68 E_R22_REGNUM,
69 E_R23_REGNUM,
70 E_R24_REGNUM,
71 E_R25_REGNUM,
72 E_R26_REGNUM,
73 E_R27_REGNUM,
74 E_R28_REGNUM,
75 E_R29_REGNUM, E_SAVE2_END_REGNUM = E_R29_REGNUM, E_FP_RAW_REGNUM = E_R29_REGNUM,
76 E_R30_REGNUM, E_EP_REGNUM = E_R30_REGNUM,
77 E_R31_REGNUM, E_SAVE3_START_REGNUM = E_R31_REGNUM, E_SAVE3_END_REGNUM = E_R31_REGNUM, E_RP_REGNUM = E_R31_REGNUM,
78 E_R32_REGNUM, E_SR0_REGNUM = E_R32_REGNUM,
79 E_R33_REGNUM,
80 E_R34_REGNUM,
81 E_R35_REGNUM,
82 E_R36_REGNUM,
83 E_R37_REGNUM, E_PS_REGNUM = E_R37_REGNUM,
84 E_R38_REGNUM,
85 E_R39_REGNUM,
86 E_R40_REGNUM,
87 E_R41_REGNUM,
88 E_R42_REGNUM,
89 E_R43_REGNUM,
90 E_R44_REGNUM,
91 E_R45_REGNUM,
92 E_R46_REGNUM,
93 E_R47_REGNUM,
94 E_R48_REGNUM,
95 E_R49_REGNUM,
96 E_R50_REGNUM,
97 E_R51_REGNUM,
98 E_R52_REGNUM, E_CTBP_REGNUM = E_R52_REGNUM,
99 E_R53_REGNUM,
100 E_R54_REGNUM,
101 E_R55_REGNUM,
102 E_R56_REGNUM,
103 E_R57_REGNUM,
104 E_R58_REGNUM,
105 E_R59_REGNUM,
106 E_R60_REGNUM,
107 E_R61_REGNUM,
108 E_R62_REGNUM,
109 E_R63_REGNUM,
110 E_R64_REGNUM, E_PC_REGNUM = E_R64_REGNUM,
111 E_R65_REGNUM, E_FP_REGNUM = E_R65_REGNUM,
112 E_NUM_REGS
113};
114
115enum
116{
117 v850_reg_size = 4
118};
119
120/* Size of all registers as a whole. */
121enum
122{
123 E_ALL_REGS_SIZE = (E_NUM_REGS) * v850_reg_size
124};
125
70eb15a4
CV
126/* Size of return datatype which fits into all return registers. */
127enum
128{
129 E_MAX_RETTYPE_SIZE_IN_REGS = 2 * v850_reg_size
130};
131
435e042a
CV
132static LONGEST call_dummy_nil[] = {0};
133
134static char *v850_generic_reg_names[] =
135{ "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
136 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
137 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
138 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
139 "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "sr6", "sr7",
140 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15",
141 "sr16", "sr17", "sr18", "sr19", "sr20", "sr21", "sr22", "sr23",
142 "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31",
143 "pc", "fp"
144};
c906108c
SS
145
146static char *v850e_reg_names[] =
147{
148 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
149 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
150 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
151 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
152 "eipc", "eipsw", "fepc", "fepsw", "ecr", "psw", "sr6", "sr7",
153 "sr8", "sr9", "sr10", "sr11", "sr12", "sr13", "sr14", "sr15",
154 "ctpc", "ctpsw", "dbpc", "dbpsw", "ctbp", "sr21", "sr22", "sr23",
155 "sr24", "sr25", "sr26", "sr27", "sr28", "sr29", "sr30", "sr31",
156 "pc", "fp"
157};
158
159char **v850_register_names = v850_generic_reg_names;
160
161struct
c5aa993b
JM
162 {
163 char **regnames;
164 int mach;
165 }
166v850_processor_type_table[] =
c906108c 167{
c5aa993b
JM
168 {
169 v850_generic_reg_names, bfd_mach_v850
170 }
171 ,
172 {
173 v850e_reg_names, bfd_mach_v850e
174 }
175 ,
176 {
177 v850e_reg_names, bfd_mach_v850ea
178 }
179 ,
180 {
181 NULL, 0
182 }
c906108c
SS
183};
184
185/* Info gleaned from scanning a function's prologue. */
186
187struct pifsr /* Info about one saved reg */
c5aa993b
JM
188 {
189 int framereg; /* Frame reg (SP or FP) */
190 int offset; /* Offset from framereg */
191 int cur_frameoffset; /* Current frameoffset */
192 int reg; /* Saved register number */
193 };
c906108c
SS
194
195struct prologue_info
c5aa993b
JM
196 {
197 int framereg;
198 int frameoffset;
199 int start_function;
200 struct pifsr *pifsrs;
201 };
c906108c 202
a14ed312 203static CORE_ADDR v850_scan_prologue (CORE_ADDR pc, struct prologue_info *fs);
c906108c 204
435e042a
CV
205/* Function: v850_register_name
206 Returns the name of the v850/v850e register N. */
207
208static char *
209v850_register_name (int regnum)
210{
211 if (regnum < 0 || regnum >= E_NUM_REGS)
212 internal_error (__FILE__, __LINE__,
213 "v850_register_name: illegal register number %d",
214 regnum);
215 else
216 return v850_register_names[regnum];
217
218}
219
220/* Function: v850_register_byte
221 Returns the byte position in the register cache for register N. */
222
223static int
224v850_register_byte (int regnum)
225{
226 if (regnum < 0 || regnum >= E_NUM_REGS)
227 internal_error (__FILE__, __LINE__,
228 "v850_register_byte: illegal register number %d",
229 regnum);
230 else
231 return regnum * v850_reg_size;
232}
233
234/* Function: v850_register_raw_size
235 Returns the number of bytes occupied by the register on the target. */
236
237static int
238v850_register_raw_size (int regnum)
239{
240 if (regnum < 0 || regnum >= E_NUM_REGS)
241 internal_error (__FILE__, __LINE__,
242 "v850_register_raw_size: illegal register number %d",
243 regnum);
244 /* Only the PC has 4 Byte, all other registers 2 Byte. */
245 else
246 return v850_reg_size;
247}
248
249/* Function: v850_register_virtual_size
250 Returns the number of bytes occupied by the register as represented
251 internally by gdb. */
252
253static int
254v850_register_virtual_size (int regnum)
255{
256 return v850_register_raw_size (regnum);
257}
258
259/* Function: v850_reg_virtual_type
260 Returns the default type for register N. */
261
262static struct type *
263v850_reg_virtual_type (int regnum)
264{
265 if (regnum < 0 || regnum >= E_NUM_REGS)
266 internal_error (__FILE__, __LINE__,
267 "v850_register_virtual_type: illegal register number %d",
268 regnum);
269 else if (regnum == E_PC_REGNUM)
270 return builtin_type_uint32;
271 else
272 return builtin_type_int32;
273}
c906108c 274
70eb15a4
CV
275static int
276v850_type_is_scalar (struct type *t)
277{
278 return (TYPE_CODE (t) != TYPE_CODE_STRUCT
279 && TYPE_CODE (t) != TYPE_CODE_UNION
280 && TYPE_CODE (t) != TYPE_CODE_ARRAY);
281}
282
c906108c 283/* Should call_function allocate stack space for a struct return? */
70eb15a4 284static int
fba45db2 285v850_use_struct_convention (int gcc_p, struct type *type)
c906108c 286{
70eb15a4
CV
287 /* According to ABI:
288 * return TYPE_LENGTH (type) > 8);
289 */
290
291 /* Current implementation in gcc: */
292
293 int i;
294 struct type *fld_type, *tgt_type;
295
296 /* 1. The value is greater than 8 bytes -> returned by copying */
297 if (TYPE_LENGTH (type) > 8)
298 return 1;
299
300 /* 2. The value is a single basic type -> returned in register */
301 if (v850_type_is_scalar (type))
302 return 0;
303
304 /* The value is a structure or union with a single element
305 * and that element is either a single basic type or an array of
306 * a single basic type whoes size is greater than or equal to 4
307 * -> returned in register */
308 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT
309 || TYPE_CODE (type) == TYPE_CODE_UNION)
310 && TYPE_NFIELDS (type) == 1)
311 {
312 fld_type = TYPE_FIELD_TYPE (type, 0);
313 if (v850_type_is_scalar (fld_type) && TYPE_LENGTH (fld_type) >= 4)
314 return 0;
315
316 if (TYPE_CODE (fld_type) == TYPE_CODE_ARRAY)
317 {
318 tgt_type = TYPE_TARGET_TYPE (fld_type);
319 if (v850_type_is_scalar (tgt_type) && TYPE_LENGTH (tgt_type) >= 4)
320 return 0;
321 }
322 }
323
324 /* The value is a structure whose first element is an integer or
325 * a float, and which contains no arrays of more than two elements
326 * -> returned in register */
327 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
328 && v850_type_is_scalar (TYPE_FIELD_TYPE (type, 0))
329 && TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) == 4)
330 {
331 for (i = 1; i < TYPE_NFIELDS (type); ++i)
332 {
333 fld_type = TYPE_FIELD_TYPE (type, 0);
334 if (TYPE_CODE (fld_type) == TYPE_CODE_ARRAY)
335 {
336 tgt_type = TYPE_TARGET_TYPE (fld_type);
337 if (TYPE_LENGTH (fld_type) >= 0 && TYPE_LENGTH (tgt_type) >= 0
338 && TYPE_LENGTH (fld_type) / TYPE_LENGTH (tgt_type) > 2)
339 return 1;
340 }
341 }
342 return 0;
343 }
344
345 /* The value is a union which contains at least one field which
346 * would be returned in registers according to these rules
347 * -> returned in register */
348 if (TYPE_CODE (type) == TYPE_CODE_UNION)
349 {
350 for (i = 0; i < TYPE_NFIELDS (type); ++i)
351 {
352 fld_type = TYPE_FIELD_TYPE (type, 0);
353 if (!v850_use_struct_convention (0, fld_type))
354 return 0;
355 }
356 }
357
358 return 1;
c906108c 359}
c906108c
SS
360\f
361
c5aa993b 362
c906108c 363/* Structure for mapping bits in register lists to register numbers. */
c5aa993b 364struct reg_list
c906108c
SS
365{
366 long mask;
367 int regno;
368};
369
370/* Helper function for v850_scan_prologue to handle prepare instruction. */
371
372static void
c5aa993b 373handle_prepare (int insn, int insn2, CORE_ADDR * current_pc_ptr,
c906108c 374 struct prologue_info *pi, struct pifsr **pifsr_ptr)
c906108c
SS
375{
376 CORE_ADDR current_pc = *current_pc_ptr;
377 struct pifsr *pifsr = *pifsr_ptr;
378 long next = insn2 & 0xffff;
379 long list12 = ((insn & 1) << 16) + (next & 0xffe0);
380 long offset = (insn & 0x3e) << 1;
c5aa993b 381 static struct reg_list reg_table[] =
c906108c 382 {
c5aa993b
JM
383 {0x00800, 20}, /* r20 */
384 {0x00400, 21}, /* r21 */
385 {0x00200, 22}, /* r22 */
386 {0x00100, 23}, /* r23 */
387 {0x08000, 24}, /* r24 */
388 {0x04000, 25}, /* r25 */
389 {0x02000, 26}, /* r26 */
390 {0x01000, 27}, /* r27 */
391 {0x00080, 28}, /* r28 */
392 {0x00040, 29}, /* r29 */
393 {0x10000, 30}, /* ep */
394 {0x00020, 31}, /* lp */
395 {0, 0} /* end of table */
c906108c
SS
396 };
397 int i;
398
c5aa993b 399 if ((next & 0x1f) == 0x0b) /* skip imm16 argument */
c906108c
SS
400 current_pc += 2;
401 else if ((next & 0x1f) == 0x13) /* skip imm16 argument */
402 current_pc += 2;
403 else if ((next & 0x1f) == 0x1b) /* skip imm32 argument */
404 current_pc += 4;
405
406 /* Calculate the total size of the saved registers, and add it
407 it to the immediate value used to adjust SP. */
408 for (i = 0; reg_table[i].mask != 0; i++)
409 if (list12 & reg_table[i].mask)
435e042a 410 offset += v850_register_raw_size (reg_table[i].regno);
c906108c
SS
411 pi->frameoffset -= offset;
412
413 /* Calculate the offsets of the registers relative to the value
414 the SP will have after the registers have been pushed and the
415 imm5 value has been subtracted from it. */
416 if (pifsr)
417 {
418 for (i = 0; reg_table[i].mask != 0; i++)
419 {
420 if (list12 & reg_table[i].mask)
421 {
422 int reg = reg_table[i].regno;
435e042a 423 offset -= v850_register_raw_size (reg);
c906108c
SS
424 pifsr->reg = reg;
425 pifsr->offset = offset;
426 pifsr->cur_frameoffset = pi->frameoffset;
c5aa993b 427#ifdef DEBUG
c906108c 428 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
c5aa993b 429#endif
c906108c
SS
430 pifsr++;
431 }
432 }
433 }
434#ifdef DEBUG
435 printf_filtered ("\tfound ctret after regsave func");
436#endif
437
438 /* Set result parameters. */
439 *current_pc_ptr = current_pc;
440 *pifsr_ptr = pifsr;
441}
442
443
444/* Helper function for v850_scan_prologue to handle pushm/pushl instructions.
445 FIXME: the SR bit of the register list is not supported; must check
446 that the compiler does not ever generate this bit. */
447
448static void
449handle_pushm (int insn, int insn2, struct prologue_info *pi,
c5aa993b 450 struct pifsr **pifsr_ptr)
c906108c
SS
451{
452 struct pifsr *pifsr = *pifsr_ptr;
453 long list12 = ((insn & 0x0f) << 16) + (insn2 & 0xfff0);
454 long offset = 0;
c5aa993b 455 static struct reg_list pushml_reg_table[] =
c906108c 456 {
435e042a 457 {0x80000, E_PS_REGNUM}, /* PSW */
c5aa993b
JM
458 {0x40000, 1}, /* r1 */
459 {0x20000, 2}, /* r2 */
460 {0x10000, 3}, /* r3 */
461 {0x00800, 4}, /* r4 */
462 {0x00400, 5}, /* r5 */
463 {0x00200, 6}, /* r6 */
464 {0x00100, 7}, /* r7 */
465 {0x08000, 8}, /* r8 */
466 {0x04000, 9}, /* r9 */
467 {0x02000, 10}, /* r10 */
468 {0x01000, 11}, /* r11 */
469 {0x00080, 12}, /* r12 */
470 {0x00040, 13}, /* r13 */
471 {0x00020, 14}, /* r14 */
472 {0x00010, 15}, /* r15 */
473 {0, 0} /* end of table */
c906108c 474 };
c5aa993b 475 static struct reg_list pushmh_reg_table[] =
c906108c 476 {
c5aa993b
JM
477 {0x80000, 16}, /* r16 */
478 {0x40000, 17}, /* r17 */
479 {0x20000, 18}, /* r18 */
480 {0x10000, 19}, /* r19 */
481 {0x00800, 20}, /* r20 */
482 {0x00400, 21}, /* r21 */
483 {0x00200, 22}, /* r22 */
484 {0x00100, 23}, /* r23 */
485 {0x08000, 24}, /* r24 */
486 {0x04000, 25}, /* r25 */
487 {0x02000, 26}, /* r26 */
488 {0x01000, 27}, /* r27 */
489 {0x00080, 28}, /* r28 */
490 {0x00040, 29}, /* r29 */
491 {0x00010, 30}, /* r30 */
492 {0x00020, 31}, /* r31 */
493 {0, 0} /* end of table */
c906108c
SS
494 };
495 struct reg_list *reg_table;
496 int i;
497
498 /* Is this a pushml or a pushmh? */
499 if ((insn2 & 7) == 1)
500 reg_table = pushml_reg_table;
501 else
502 reg_table = pushmh_reg_table;
503
504 /* Calculate the total size of the saved registers, and add it
505 it to the immediate value used to adjust SP. */
506 for (i = 0; reg_table[i].mask != 0; i++)
507 if (list12 & reg_table[i].mask)
435e042a 508 offset += v850_register_raw_size (reg_table[i].regno);
c906108c
SS
509 pi->frameoffset -= offset;
510
511 /* Calculate the offsets of the registers relative to the value
512 the SP will have after the registers have been pushed and the
513 imm5 value is subtracted from it. */
514 if (pifsr)
515 {
516 for (i = 0; reg_table[i].mask != 0; i++)
517 {
518 if (list12 & reg_table[i].mask)
519 {
520 int reg = reg_table[i].regno;
435e042a 521 offset -= v850_register_raw_size (reg);
c906108c
SS
522 pifsr->reg = reg;
523 pifsr->offset = offset;
524 pifsr->cur_frameoffset = pi->frameoffset;
c5aa993b 525#ifdef DEBUG
c906108c 526 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
c5aa993b 527#endif
c906108c
SS
528 pifsr++;
529 }
530 }
531 }
532#ifdef DEBUG
533 printf_filtered ("\tfound ctret after regsave func");
534#endif
535
536 /* Set result parameters. */
537 *pifsr_ptr = pifsr;
538}
c5aa993b 539\f
c906108c
SS
540
541
542
c906108c
SS
543/* Function: scan_prologue
544 Scan the prologue of the function that contains PC, and record what
3a06899a
CV
545 we find in PI. Returns the pc after the prologue. Note that the
546 addresses saved in frame->saved_regs are just frame relative (negative
547 offsets from the frame pointer). This is because we don't know the
548 actual value of the frame pointer yet. In some circumstances, the
549 frame pointer can't be determined till after we have scanned the
550 prologue. */
c906108c
SS
551
552static CORE_ADDR
fba45db2 553v850_scan_prologue (CORE_ADDR pc, struct prologue_info *pi)
c906108c
SS
554{
555 CORE_ADDR func_addr, prologue_end, current_pc;
556 struct pifsr *pifsr, *pifsr_tmp;
557 int fp_used;
558 int ep_used;
559 int reg;
560 CORE_ADDR save_pc, save_end;
561 int regsave_func_p;
562 int r12_tmp;
563
564 /* First, figure out the bounds of the prologue so that we can limit the
565 search to something reasonable. */
566
567 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
568 {
569 struct symtab_and_line sal;
570
571 sal = find_pc_line (func_addr, 0);
572
573 if (func_addr == entry_point_address ())
574 pi->start_function = 1;
575 else
576 pi->start_function = 0;
577
578#if 0
579 if (sal.line == 0)
580 prologue_end = pc;
581 else
582 prologue_end = sal.end;
583#else
584 prologue_end = pc;
585#endif
586 }
587 else
588 { /* We're in the boondocks */
589 func_addr = pc - 100;
590 prologue_end = pc;
591 }
592
593 prologue_end = min (prologue_end, pc);
594
595 /* Now, search the prologue looking for instructions that setup fp, save
596 rp, adjust sp and such. We also record the frame offset of any saved
c5aa993b 597 registers. */
c906108c
SS
598
599 pi->frameoffset = 0;
435e042a 600 pi->framereg = E_SP_REGNUM;
c906108c
SS
601 fp_used = 0;
602 ep_used = 0;
603 pifsr = pi->pifsrs;
604 regsave_func_p = 0;
605 save_pc = 0;
606 save_end = 0;
607 r12_tmp = 0;
608
609#ifdef DEBUG
610 printf_filtered ("Current_pc = 0x%.8lx, prologue_end = 0x%.8lx\n",
c5aa993b 611 (long) func_addr, (long) prologue_end);
c906108c
SS
612#endif
613
c5aa993b 614 for (current_pc = func_addr; current_pc < prologue_end;)
c906108c 615 {
93d56215
AC
616 int insn;
617 int insn2 = -1; /* dummy value */
c906108c
SS
618
619#ifdef DEBUG
c5aa993b 620 printf_filtered ("0x%.8lx ", (long) current_pc);
2bf0cb65 621 TARGET_PRINT_INSN (current_pc, &tm_print_insn_info);
c906108c
SS
622#endif
623
624 insn = read_memory_unsigned_integer (current_pc, 2);
625 current_pc += 2;
c5aa993b 626 if ((insn & 0x0780) >= 0x0600) /* Four byte instruction? */
c906108c
SS
627 {
628 insn2 = read_memory_unsigned_integer (current_pc, 2);
629 current_pc += 2;
630 }
631
632 if ((insn & 0xffc0) == ((10 << 11) | 0x0780) && !regsave_func_p)
633 { /* jarl <func>,10 */
c5aa993b 634 long low_disp = insn2 & ~(long) 1;
c906108c 635 long disp = (((((insn & 0x3f) << 16) + low_disp)
c5aa993b 636 & ~(long) 1) ^ 0x00200000) - 0x00200000;
c906108c
SS
637
638 save_pc = current_pc;
639 save_end = prologue_end;
640 regsave_func_p = 1;
641 current_pc += disp - 4;
642 prologue_end = (current_pc
643 + (2 * 3) /* moves to/from ep */
c5aa993b
JM
644 + 4 /* addi <const>,sp,sp */
645 + 2 /* jmp [r10] */
c906108c
SS
646 + (2 * 12) /* sst.w to save r2, r20-r29, r31 */
647 + 20); /* slop area */
648
649#ifdef DEBUG
650 printf_filtered ("\tfound jarl <func>,r10, disp = %ld, low_disp = %ld, new pc = 0x%.8lx\n",
c5aa993b 651 disp, low_disp, (long) current_pc + 2);
c906108c
SS
652#endif
653 continue;
654 }
655 else if ((insn & 0xffc0) == 0x0200 && !regsave_func_p)
656 { /* callt <imm6> */
435e042a 657 long ctbp = read_register (E_CTBP_REGNUM);
c906108c
SS
658 long adr = ctbp + ((insn & 0x3f) << 1);
659
660 save_pc = current_pc;
661 save_end = prologue_end;
662 regsave_func_p = 1;
663 current_pc = ctbp + (read_memory_unsigned_integer (adr, 2) & 0xffff);
664 prologue_end = (current_pc
665 + (2 * 3) /* prepare list2,imm5,sp/imm */
c5aa993b 666 + 4 /* ctret */
c906108c
SS
667 + 20); /* slop area */
668
669#ifdef DEBUG
670 printf_filtered ("\tfound callt, ctbp = 0x%.8lx, adr = %.8lx, new pc = 0x%.8lx\n",
c5aa993b 671 ctbp, adr, (long) current_pc);
c906108c
SS
672#endif
673 continue;
674 }
675 else if ((insn & 0xffc0) == 0x0780) /* prepare list2,imm5 */
676 {
677 handle_prepare (insn, insn2, &current_pc, pi, &pifsr);
678 continue;
679 }
680 else if (insn == 0x07e0 && regsave_func_p && insn2 == 0x0144)
681 { /* ctret after processing register save function */
682 current_pc = save_pc;
683 prologue_end = save_end;
684 regsave_func_p = 0;
685#ifdef DEBUG
686 printf_filtered ("\tfound ctret after regsave func");
687#endif
688 continue;
689 }
690 else if ((insn & 0xfff0) == 0x07e0 && (insn2 & 5) == 1)
691 { /* pushml, pushmh */
692 handle_pushm (insn, insn2, pi, &pifsr);
693 continue;
694 }
695 else if ((insn & 0xffe0) == 0x0060 && regsave_func_p)
696 { /* jmp after processing register save function */
697 current_pc = save_pc;
698 prologue_end = save_end;
699 regsave_func_p = 0;
700#ifdef DEBUG
701 printf_filtered ("\tfound jmp after regsave func");
702#endif
703 continue;
704 }
705 else if ((insn & 0x07c0) == 0x0780 /* jarl or jr */
706 || (insn & 0xffe0) == 0x0060 /* jmp */
707 || (insn & 0x0780) == 0x0580) /* branch */
708 {
709#ifdef DEBUG
710 printf_filtered ("\n");
711#endif
c5aa993b 712 break; /* Ran into end of prologue */
c906108c
SS
713 }
714
435e042a 715 else if ((insn & 0xffe0) == ((E_SP_REGNUM << 11) | 0x0240)) /* add <imm>,sp */
c906108c 716 pi->frameoffset += ((insn & 0x1f) ^ 0x10) - 0x10;
435e042a 717 else if (insn == ((E_SP_REGNUM << 11) | 0x0600 | E_SP_REGNUM)) /* addi <imm>,sp,sp */
c906108c 718 pi->frameoffset += insn2;
435e042a 719 else if (insn == ((E_FP_RAW_REGNUM << 11) | 0x0000 | E_SP_REGNUM)) /* mov sp,fp */
c906108c
SS
720 {
721 fp_used = 1;
435e042a 722 pi->framereg = E_FP_RAW_REGNUM;
c906108c
SS
723 }
724
435e042a 725 else if (insn == ((E_R12_REGNUM << 11) | 0x0640 | E_R0_REGNUM)) /* movhi hi(const),r0,r12 */
c906108c 726 r12_tmp = insn2 << 16;
435e042a 727 else if (insn == ((E_R12_REGNUM << 11) | 0x0620 | E_R12_REGNUM)) /* movea lo(const),r12,r12 */
c906108c 728 r12_tmp += insn2;
435e042a 729 else if (insn == ((E_SP_REGNUM << 11) | 0x01c0 | E_R12_REGNUM) && r12_tmp) /* add r12,sp */
c906108c 730 pi->frameoffset = r12_tmp;
435e042a 731 else if (insn == ((E_EP_REGNUM << 11) | 0x0000 | E_SP_REGNUM)) /* mov sp,ep */
c906108c 732 ep_used = 1;
435e042a 733 else if (insn == ((E_EP_REGNUM << 11) | 0x0000 | E_R1_REGNUM)) /* mov r1,ep */
c906108c 734 ep_used = 0;
435e042a 735 else if (((insn & 0x07ff) == (0x0760 | E_SP_REGNUM) /* st.w <reg>,<offset>[sp] */
c906108c 736 || (fp_used
435e042a 737 && (insn & 0x07ff) == (0x0760 | E_FP_RAW_REGNUM))) /* st.w <reg>,<offset>[fp] */
c906108c 738 && pifsr
435e042a
CV
739 && (((reg = (insn >> 11) & 0x1f) >= E_SAVE1_START_REGNUM && reg <= E_SAVE1_END_REGNUM)
740 || (reg >= E_SAVE2_START_REGNUM && reg <= E_SAVE2_END_REGNUM)
741 || (reg >= E_SAVE3_START_REGNUM && reg <= E_SAVE3_END_REGNUM)))
c906108c
SS
742 {
743 pifsr->reg = reg;
744 pifsr->offset = insn2 & ~1;
745 pifsr->cur_frameoffset = pi->frameoffset;
746#ifdef DEBUG
747 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
748#endif
749 pifsr++;
750 }
751
c5aa993b 752 else if (ep_used /* sst.w <reg>,<offset>[ep] */
c906108c
SS
753 && ((insn & 0x0781) == 0x0501)
754 && pifsr
435e042a
CV
755 && (((reg = (insn >> 11) & 0x1f) >= E_SAVE1_START_REGNUM && reg <= E_SAVE1_END_REGNUM)
756 || (reg >= E_SAVE2_START_REGNUM && reg <= E_SAVE2_END_REGNUM)
757 || (reg >= E_SAVE3_START_REGNUM && reg <= E_SAVE3_END_REGNUM)))
c906108c
SS
758 {
759 pifsr->reg = reg;
760 pifsr->offset = (insn & 0x007e) << 1;
761 pifsr->cur_frameoffset = pi->frameoffset;
762#ifdef DEBUG
763 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
764#endif
765 pifsr++;
766 }
767
768#ifdef DEBUG
769 printf_filtered ("\n");
770#endif
771 }
772
773 if (pifsr)
774 pifsr->framereg = 0; /* Tie off last entry */
775
776 /* Fix up any offsets to the final offset. If a frame pointer was created, use it
777 instead of the stack pointer. */
778 for (pifsr_tmp = pi->pifsrs; pifsr_tmp && pifsr_tmp != pifsr; pifsr_tmp++)
779 {
780 pifsr_tmp->offset -= pi->frameoffset - pifsr_tmp->cur_frameoffset;
781 pifsr_tmp->framereg = pi->framereg;
782
783#ifdef DEBUG
784 printf_filtered ("Saved register r%d, offset = %d, framereg = r%d\n",
c5aa993b 785 pifsr_tmp->reg, pifsr_tmp->offset, pifsr_tmp->framereg);
c906108c
SS
786#endif
787 }
788
789#ifdef DEBUG
790 printf_filtered ("Framereg = r%d, frameoffset = %d\n", pi->framereg, pi->frameoffset);
791#endif
792
793 return current_pc;
794}
795
435e042a
CV
796/* Function: find_callers_reg
797 Find REGNUM on the stack. Otherwise, it's in an active register.
798 One thing we might want to do here is to check REGNUM against the
799 clobber mask, and somehow flag it as invalid if it isn't saved on
800 the stack somewhere. This would provide a graceful failure mode
801 when trying to get the value of caller-saves registers for an inner
802 frame. */
c906108c 803
435e042a
CV
804CORE_ADDR
805v850_find_callers_reg (struct frame_info *fi, int regnum)
c906108c 806{
435e042a
CV
807 for (; fi; fi = fi->next)
808 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
809 return generic_read_register_dummy (fi->pc, fi->frame, regnum);
810 else if (fi->saved_regs[regnum] != 0)
811 return read_memory_unsigned_integer (fi->saved_regs[regnum],
812 v850_register_raw_size (regnum));
c906108c 813
435e042a 814 return read_register (regnum);
c906108c
SS
815}
816
817/* Function: frame_chain
818 Figure out the frame prior to FI. Unfortunately, this involves
819 scanning the prologue of the caller, which will also be done
820 shortly by v850_init_extra_frame_info. For the dummy frame, we
821 just return the stack pointer that was in use at the time the
822 function call was made. */
823
824CORE_ADDR
fba45db2 825v850_frame_chain (struct frame_info *fi)
c906108c
SS
826{
827 struct prologue_info pi;
828 CORE_ADDR callers_pc, fp;
829
830 /* First, find out who called us */
831 callers_pc = FRAME_SAVED_PC (fi);
832 /* If caller is a call-dummy, then our FP bears no relation to his FP! */
435e042a 833 fp = v850_find_callers_reg (fi, E_FP_RAW_REGNUM);
c5aa993b
JM
834 if (PC_IN_CALL_DUMMY (callers_pc, fp, fp))
835 return fp; /* caller is call-dummy: return oldest value of FP */
c906108c
SS
836
837 /* Caller is NOT a call-dummy, so everything else should just work.
838 Even if THIS frame is a call-dummy! */
839 pi.pifsrs = NULL;
840
841 v850_scan_prologue (callers_pc, &pi);
842
843 if (pi.start_function)
844 return 0; /* Don't chain beyond the start function */
845
435e042a 846 if (pi.framereg == E_FP_RAW_REGNUM)
c906108c
SS
847 return v850_find_callers_reg (fi, pi.framereg);
848
849 return fi->frame - pi.frameoffset;
850}
851
c906108c
SS
852/* Function: skip_prologue
853 Return the address of the first code past the prologue of the function. */
854
855CORE_ADDR
fba45db2 856v850_skip_prologue (CORE_ADDR pc)
c906108c
SS
857{
858 CORE_ADDR func_addr, func_end;
859
860 /* See what the symbol table says */
861
862 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
863 {
864 struct symtab_and_line sal;
865
866 sal = find_pc_line (func_addr, 0);
867
868 if (sal.line != 0 && sal.end < func_end)
869 return sal.end;
870 else
871 /* Either there's no line info, or the line after the prologue is after
872 the end of the function. In this case, there probably isn't a
873 prologue. */
874 return pc;
875 }
876
877/* We can't find the start of this function, so there's nothing we can do. */
878 return pc;
879}
880
881/* Function: pop_frame
882 This routine gets called when either the user uses the `return'
883 command, or the call dummy breakpoint gets hit. */
884
885void
435e042a 886v850_pop_frame (void)
c906108c 887{
435e042a 888 struct frame_info *frame = get_current_frame ();
c906108c
SS
889 int regnum;
890
c5aa993b 891 if (PC_IN_CALL_DUMMY (frame->pc, frame->frame, frame->frame))
c906108c
SS
892 generic_pop_dummy_frame ();
893 else
894 {
435e042a 895 write_register (E_PC_REGNUM, FRAME_SAVED_PC (frame));
c906108c 896
435e042a 897 for (regnum = 0; regnum < E_NUM_REGS; regnum++)
3a06899a 898 if (frame->saved_regs[regnum] != 0)
c906108c 899 write_register (regnum,
3a06899a 900 read_memory_unsigned_integer (frame->saved_regs[regnum],
435e042a 901 v850_register_raw_size (regnum)));
c906108c 902
435e042a 903 write_register (E_SP_REGNUM, FRAME_FP (frame));
c906108c
SS
904 }
905
906 flush_cached_frames ();
907}
908
909/* Function: push_arguments
910 Setup arguments and RP for a call to the target. First four args
911 go in R6->R9, subsequent args go into sp + 16 -> sp + ... Structs
912 are passed by reference. 64 bit quantities (doubles and long
913 longs) may be split between the regs and the stack. When calling a
914 function that returns a struct, a pointer to the struct is passed
915 in as a secret first argument (always in R6).
916
917 Stack space for the args has NOT been allocated: that job is up to us.
c5aa993b 918 */
c906108c
SS
919
920CORE_ADDR
ea7c478f 921v850_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
435e042a 922 int struct_return, CORE_ADDR struct_addr)
c906108c
SS
923{
924 int argreg;
925 int argnum;
926 int len = 0;
927 int stack_offset;
928
929 /* First, just for safety, make sure stack is aligned */
930 sp &= ~3;
931
70eb15a4
CV
932 /* The offset onto the stack at which we will start copying parameters
933 (after the registers are used up) begins at 16 rather than at zero.
934 I don't really know why, that's just the way it seems to work. */
935 stack_offset = 16;
936
c906108c
SS
937 /* Now make space on the stack for the args. */
938 for (argnum = 0; argnum < nargs; argnum++)
c5aa993b 939 len += ((TYPE_LENGTH (VALUE_TYPE (args[argnum])) + 3) & ~3);
70eb15a4 940 sp -= len + stack_offset; /* possibly over-allocating, but it works... */
c5aa993b
JM
941 /* (you might think we could allocate 16 bytes */
942 /* less, but the ABI seems to use it all! ) */
c906108c 943
70eb15a4 944 argreg = E_ARG0_REGNUM;
c906108c
SS
945 /* the struct_return pointer occupies the first parameter-passing reg */
946 if (struct_return)
70eb15a4 947 argreg++;
c906108c
SS
948
949 /* Now load as many as possible of the first arguments into
950 registers, and push the rest onto the stack. There are 16 bytes
951 in four registers available. Loop thru args from first to last. */
952 for (argnum = 0; argnum < nargs; argnum++)
953 {
954 int len;
955 char *val;
435e042a 956 char valbuf[v850_register_raw_size (E_ARG0_REGNUM)];
c906108c 957
70eb15a4
CV
958 if (!v850_type_is_scalar (VALUE_TYPE (*args))
959 && TYPE_LENGTH (VALUE_TYPE (*args)) > E_MAX_RETTYPE_SIZE_IN_REGS)
c906108c
SS
960 {
961 store_address (valbuf, 4, VALUE_ADDRESS (*args));
962 len = 4;
963 val = valbuf;
964 }
965 else
966 {
967 len = TYPE_LENGTH (VALUE_TYPE (*args));
c5aa993b 968 val = (char *) VALUE_CONTENTS (*args);
c906108c
SS
969 }
970
971 while (len > 0)
435e042a 972 if (argreg <= E_ARGLAST_REGNUM)
c906108c
SS
973 {
974 CORE_ADDR regval;
975
435e042a 976 regval = extract_address (val, v850_register_raw_size (argreg));
c906108c
SS
977 write_register (argreg, regval);
978
435e042a
CV
979 len -= v850_register_raw_size (argreg);
980 val += v850_register_raw_size (argreg);
c906108c
SS
981 argreg++;
982 }
983 else
984 {
985 write_memory (sp + stack_offset, val, 4);
986
987 len -= 4;
988 val += 4;
989 stack_offset += 4;
990 }
991 args++;
992 }
993 return sp;
994}
995
996/* Function: push_return_address (pc)
997 Set up the return address for the inferior function call.
998 Needed for targets where we don't actually execute a JSR/BSR instruction */
c5aa993b 999
c906108c 1000CORE_ADDR
fba45db2 1001v850_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
c906108c 1002{
435e042a 1003 write_register (E_RP_REGNUM, CALL_DUMMY_ADDRESS ());
c906108c
SS
1004 return sp;
1005}
c5aa993b 1006
c906108c 1007/* Function: frame_saved_pc
435e042a 1008 Find the caller of this frame. We do this by seeing if E_RP_REGNUM
c906108c
SS
1009 is saved in the stack anywhere, otherwise we get it from the
1010 registers. If the inner frame is a dummy frame, return its PC
1011 instead of RP, because that's where "caller" of the dummy-frame
1012 will be found. */
1013
1014CORE_ADDR
fba45db2 1015v850_frame_saved_pc (struct frame_info *fi)
c906108c 1016{
c5aa993b 1017 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
435e042a 1018 return generic_read_register_dummy (fi->pc, fi->frame, E_PC_REGNUM);
c906108c 1019 else
435e042a 1020 return v850_find_callers_reg (fi, E_RP_REGNUM);
c906108c
SS
1021}
1022
c906108c
SS
1023
1024/* Function: fix_call_dummy
1025 Pokes the callee function's address into the CALL_DUMMY assembly stub.
1026 Assumes that the CALL_DUMMY looks like this:
c5aa993b
JM
1027 jarl <offset24>, r31
1028 trap
1029 */
c906108c 1030
435e042a 1031void
fba45db2 1032v850_fix_call_dummy (char *dummy, CORE_ADDR sp, CORE_ADDR fun, int nargs,
ea7c478f 1033 struct value **args, struct type *type, int gcc_p)
c906108c
SS
1034{
1035 long offset24;
1036
1037 offset24 = (long) fun - (long) entry_point_address ();
1038 offset24 &= 0x3fffff;
1039 offset24 |= 0xff800000; /* jarl <offset24>, r31 */
1040
c5aa993b
JM
1041 store_unsigned_integer ((unsigned int *) &dummy[2], 2, offset24 & 0xffff);
1042 store_unsigned_integer ((unsigned int *) &dummy[0], 2, offset24 >> 16);
435e042a
CV
1043}
1044
1045static CORE_ADDR
1046v850_saved_pc_after_call (struct frame_info *ignore)
1047{
1048 return read_register (E_RP_REGNUM);
1049}
1050
1051static void
1052v850_extract_return_value (struct type *type, char *regbuf, char *valbuf)
1053{
70eb15a4
CV
1054 CORE_ADDR return_buffer;
1055
1056 if (!v850_use_struct_convention (0, type))
1057 {
1058 /* Scalar return values of <= 8 bytes are returned in
1059 E_V0_REGNUM to E_V1_REGNUM. */
1060 memcpy (valbuf,
1061 &regbuf[REGISTER_BYTE (E_V0_REGNUM)],
1062 TYPE_LENGTH (type));
1063 }
1064 else
1065 {
1066 /* Aggregates and return values > 8 bytes are returned in memory,
1067 pointed to by R6. */
1068 return_buffer =
1069 extract_address (regbuf + REGISTER_BYTE (E_V0_REGNUM),
1070 REGISTER_RAW_SIZE (E_V0_REGNUM));
1071
1072 read_memory (return_buffer, valbuf, TYPE_LENGTH (type));
1073 }
435e042a
CV
1074}
1075
1076const static unsigned char *
1077v850_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
1078{
1079 static unsigned char breakpoint[] = { 0x85, 0x05 };
1080 *lenptr = sizeof (breakpoint);
1081 return breakpoint;
1082}
1083
1084static CORE_ADDR
1085v850_extract_struct_value_address (char *regbuf)
1086{
1087 return extract_address (regbuf + v850_register_byte (E_V0_REGNUM),
1088 v850_register_raw_size (E_V0_REGNUM));
1089}
1090
1091static void
1092v850_store_return_value (struct type *type, char *valbuf)
1093{
70eb15a4
CV
1094 CORE_ADDR return_buffer;
1095
1096 if (!v850_use_struct_convention (0, type))
1097 write_register_bytes (REGISTER_BYTE (E_V0_REGNUM), valbuf,
1098 TYPE_LENGTH (type));
1099 else
1100 {
1101 return_buffer = read_register (E_V0_REGNUM);
1102 write_memory (return_buffer, valbuf, TYPE_LENGTH (type));
1103 }
435e042a
CV
1104}
1105
1106static void
1107v850_frame_init_saved_regs (struct frame_info *fi)
1108{
1109 struct prologue_info pi;
1110 struct pifsr pifsrs[E_NUM_REGS + 1], *pifsr;
1111 CORE_ADDR func_addr, func_end;
1112
1113 if (!fi->saved_regs)
1114 {
1115 frame_saved_regs_zalloc (fi);
1116
1117 /* The call dummy doesn't save any registers on the stack, so we
1118 can return now. */
1119 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1120 return;
1121
1122 /* Find the beginning of this function, so we can analyze its
1123 prologue. */
1124 if (find_pc_partial_function (fi->pc, NULL, &func_addr, &func_end))
1125 {
1126 pi.pifsrs = pifsrs;
1127
1128 v850_scan_prologue (fi->pc, &pi);
1129
1130 if (!fi->next && pi.framereg == E_SP_REGNUM)
1131 fi->frame = read_register (pi.framereg) - pi.frameoffset;
1132
1133 for (pifsr = pifsrs; pifsr->framereg; pifsr++)
1134 {
1135 fi->saved_regs[pifsr->reg] = pifsr->offset + fi->frame;
1136
1137 if (pifsr->framereg == E_SP_REGNUM)
1138 fi->saved_regs[pifsr->reg] += pi.frameoffset;
1139 }
1140 }
1141 /* Else we're out of luck (can't debug completely stripped code).
1142 FIXME. */
1143 }
1144}
1145
1146/* Function: init_extra_frame_info
1147 Setup the frame's frame pointer, pc, and frame addresses for saved
1148 registers. Most of the work is done in scan_prologue().
1149
1150 Note that when we are called for the last frame (currently active frame),
1151 that fi->pc and fi->frame will already be setup. However, fi->frame will
1152 be valid only if this routine uses FP. For previous frames, fi-frame will
1153 always be correct (since that is derived from v850_frame_chain ()).
1154
1155 We can be called with the PC in the call dummy under two circumstances.
1156 First, during normal backtracing, second, while figuring out the frame
1157 pointer just prior to calling the target function (see run_stack_dummy). */
1158
1159static void
1160v850_init_extra_frame_info (int fromleaf, struct frame_info *fi)
1161{
1162 struct prologue_info pi;
1163
1164 if (fi->next)
1165 fi->pc = FRAME_SAVED_PC (fi->next);
1166
1167 v850_frame_init_saved_regs (fi);
1168}
1169
1170static void
70eb15a4 1171v850_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
435e042a 1172{
70eb15a4 1173 write_register (E_ARG0_REGNUM, addr);
435e042a
CV
1174}
1175
1176static CORE_ADDR
1177v850_target_read_fp (void)
1178{
1179 return read_register (E_FP_RAW_REGNUM);
c906108c
SS
1180}
1181
6ed14b0e
CV
1182static struct gdbarch *
1183v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
c906108c 1184{
435e042a 1185 static LONGEST call_dummy_words[1] = { 0 };
6ed14b0e
CV
1186 struct gdbarch_tdep *tdep = NULL;
1187 struct gdbarch *gdbarch;
1188 int i;
1189
1190 /* find a candidate among the list of pre-declared architectures. */
1191 arches = gdbarch_list_lookup_by_info (arches, &info);
1192 if (arches != NULL)
1193 return (arches->gdbarch);
c906108c 1194
6ed14b0e
CV
1195#if 0
1196 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
1197#endif
1198
435e042a 1199 /* Change the register names based on the current machine type. */
6ed14b0e 1200 if (info.bfd_arch_info->arch != bfd_arch_v850)
c906108c
SS
1201 return 0;
1202
6ed14b0e
CV
1203 gdbarch = gdbarch_alloc (&info, 0);
1204
c906108c
SS
1205 for (i = 0; v850_processor_type_table[i].regnames != NULL; i++)
1206 {
6ed14b0e 1207 if (v850_processor_type_table[i].mach == info.bfd_arch_info->mach)
435e042a
CV
1208 {
1209 v850_register_names = v850_processor_type_table[i].regnames;
1210 tm_print_insn_info.mach = info.bfd_arch_info->mach;
1211 break;
1212 }
c906108c
SS
1213 }
1214
435e042a
CV
1215 /*
1216 * Basic register fields and methods.
1217 */
1218 set_gdbarch_num_regs (gdbarch, E_NUM_REGS);
1219 set_gdbarch_num_pseudo_regs (gdbarch, 0);
1220 set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM);
1221 set_gdbarch_fp_regnum (gdbarch, E_FP_REGNUM);
1222 set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM);
1223 set_gdbarch_register_name (gdbarch, v850_register_name);
1224 set_gdbarch_register_size (gdbarch, v850_reg_size);
1225 set_gdbarch_register_bytes (gdbarch, E_ALL_REGS_SIZE);
1226 set_gdbarch_register_byte (gdbarch, v850_register_byte);
1227 set_gdbarch_register_raw_size (gdbarch, v850_register_raw_size);
1228 set_gdbarch_max_register_raw_size (gdbarch, v850_reg_size);
1229 set_gdbarch_register_virtual_size (gdbarch, v850_register_raw_size);
1230 set_gdbarch_max_register_virtual_size (gdbarch, v850_reg_size);
1231 set_gdbarch_register_virtual_type (gdbarch, v850_reg_virtual_type);
1232
1233 set_gdbarch_read_fp (gdbarch, v850_target_read_fp);
1234
1235 /*
1236 * Frame Info
1237 */
1238 set_gdbarch_init_extra_frame_info (gdbarch, v850_init_extra_frame_info);
1239 set_gdbarch_frame_init_saved_regs (gdbarch, v850_frame_init_saved_regs);
1240 set_gdbarch_frame_chain (gdbarch, v850_frame_chain);
1241 set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register);
1242 set_gdbarch_saved_pc_after_call (gdbarch, v850_saved_pc_after_call);
1243 set_gdbarch_frame_saved_pc (gdbarch, v850_frame_saved_pc);
1244 set_gdbarch_skip_prologue (gdbarch, v850_skip_prologue);
1245 set_gdbarch_frame_chain_valid (gdbarch, generic_file_frame_chain_valid);
1246 set_gdbarch_frame_args_address (gdbarch, default_frame_address);
1247 set_gdbarch_frame_locals_address (gdbarch, default_frame_address);
1248
1249 /*
1250 * Miscelany
1251 */
1252 /* Stack grows up. */
1253 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1254 /* PC stops zero byte after a trap instruction
1255 (which means: exactly on trap instruction). */
1256 set_gdbarch_decr_pc_after_break (gdbarch, 0);
1257 /* This value is almost never non-zero... */
1258 set_gdbarch_function_start_offset (gdbarch, 0);
1259 /* This value is almost never non-zero... */
1260 set_gdbarch_frame_args_skip (gdbarch, 0);
1261 /* OK to default this value to 'unknown'. */
1262 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
1263 /* W/o prototype, coerce float args to double. */
1264 set_gdbarch_coerce_float_to_double (gdbarch, standard_coerce_float_to_double);
1265
1266 /*
1267 * Call Dummies
1268 *
1269 * These values and methods are used when gdb calls a target function. */
1270 set_gdbarch_use_generic_dummy_frames (gdbarch, 1);
1271 set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
1272 set_gdbarch_push_return_address (gdbarch, v850_push_return_address);
26e9b323 1273 set_gdbarch_deprecated_extract_return_value (gdbarch, v850_extract_return_value);
435e042a
CV
1274 set_gdbarch_push_arguments (gdbarch, v850_push_arguments);
1275 set_gdbarch_pop_frame (gdbarch, v850_pop_frame);
1276 set_gdbarch_store_struct_return (gdbarch, v850_store_struct_return);
1277 set_gdbarch_store_return_value (gdbarch, v850_store_return_value);
26e9b323 1278 set_gdbarch_deprecated_extract_struct_value_address (gdbarch, v850_extract_struct_value_address);
435e042a
CV
1279 set_gdbarch_use_struct_convention (gdbarch, v850_use_struct_convention);
1280 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
1281 set_gdbarch_call_dummy_address (gdbarch, entry_point_address);
1282 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
1283 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
1284 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
1285 set_gdbarch_call_dummy_length (gdbarch, 0);
1286 set_gdbarch_pc_in_call_dummy (gdbarch, generic_pc_in_call_dummy);
1287 set_gdbarch_call_dummy_p (gdbarch, 1);
1288 set_gdbarch_call_dummy_words (gdbarch, call_dummy_nil);
1289 set_gdbarch_sizeof_call_dummy_words (gdbarch, 0);
1290 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
1291 /* set_gdbarch_call_dummy_stack_adjust */
1292 set_gdbarch_fix_call_dummy (gdbarch, v850_fix_call_dummy);
1293 set_gdbarch_breakpoint_from_pc (gdbarch, v850_breakpoint_from_pc);
1294
1295 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1296 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1297 set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1298 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
1299
1300 set_gdbarch_extra_stack_alignment_needed (gdbarch, 0);
1301
6ed14b0e 1302 return gdbarch;
c906108c
SS
1303}
1304
1305void
fba45db2 1306_initialize_v850_tdep (void)
c906108c
SS
1307{
1308 tm_print_insn = print_insn_v850;
6ed14b0e 1309 register_gdbarch_init (bfd_arch_v850, v850_gdbarch_init);
c906108c 1310}
This page took 0.409315 seconds and 4 git commands to generate.