2003-06-11 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / v850-tdep.c
CommitLineData
c906108c 1/* Target-dependent code for the NEC V850 for GDB, the GNU debugger.
1e698235
DJ
2 Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b
JM
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
c906108c
SS
21
22#include "defs.h"
23#include "frame.h"
24#include "inferior.h"
c906108c
SS
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 ,
c5aa993b
JM
176 {
177 NULL, 0
178 }
c906108c
SS
179};
180
181/* Info gleaned from scanning a function's prologue. */
182
183struct pifsr /* Info about one saved reg */
c5aa993b
JM
184 {
185 int framereg; /* Frame reg (SP or FP) */
186 int offset; /* Offset from framereg */
187 int cur_frameoffset; /* Current frameoffset */
188 int reg; /* Saved register number */
189 };
c906108c
SS
190
191struct prologue_info
c5aa993b
JM
192 {
193 int framereg;
194 int frameoffset;
195 int start_function;
196 struct pifsr *pifsrs;
197 };
c906108c 198
a14ed312 199static CORE_ADDR v850_scan_prologue (CORE_ADDR pc, struct prologue_info *fs);
c906108c 200
435e042a
CV
201/* Function: v850_register_name
202 Returns the name of the v850/v850e register N. */
203
fa88f677 204static const char *
435e042a
CV
205v850_register_name (int regnum)
206{
207 if (regnum < 0 || regnum >= E_NUM_REGS)
208 internal_error (__FILE__, __LINE__,
209 "v850_register_name: illegal register number %d",
210 regnum);
211 else
212 return v850_register_names[regnum];
213
214}
215
216/* Function: v850_register_byte
217 Returns the byte position in the register cache for register N. */
218
219static int
220v850_register_byte (int regnum)
221{
222 if (regnum < 0 || regnum >= E_NUM_REGS)
223 internal_error (__FILE__, __LINE__,
224 "v850_register_byte: illegal register number %d",
225 regnum);
226 else
227 return regnum * v850_reg_size;
228}
229
230/* Function: v850_register_raw_size
231 Returns the number of bytes occupied by the register on the target. */
232
233static int
234v850_register_raw_size (int regnum)
235{
236 if (regnum < 0 || regnum >= E_NUM_REGS)
237 internal_error (__FILE__, __LINE__,
238 "v850_register_raw_size: illegal register number %d",
239 regnum);
240 /* Only the PC has 4 Byte, all other registers 2 Byte. */
241 else
242 return v850_reg_size;
243}
244
245/* Function: v850_register_virtual_size
246 Returns the number of bytes occupied by the register as represented
247 internally by gdb. */
248
249static int
250v850_register_virtual_size (int regnum)
251{
252 return v850_register_raw_size (regnum);
253}
254
255/* Function: v850_reg_virtual_type
256 Returns the default type for register N. */
257
258static struct type *
259v850_reg_virtual_type (int regnum)
260{
261 if (regnum < 0 || regnum >= E_NUM_REGS)
262 internal_error (__FILE__, __LINE__,
263 "v850_register_virtual_type: illegal register number %d",
264 regnum);
265 else if (regnum == E_PC_REGNUM)
266 return builtin_type_uint32;
267 else
268 return builtin_type_int32;
269}
c906108c 270
70eb15a4
CV
271static int
272v850_type_is_scalar (struct type *t)
273{
274 return (TYPE_CODE (t) != TYPE_CODE_STRUCT
275 && TYPE_CODE (t) != TYPE_CODE_UNION
276 && TYPE_CODE (t) != TYPE_CODE_ARRAY);
277}
278
c906108c 279/* Should call_function allocate stack space for a struct return? */
70eb15a4 280static int
fba45db2 281v850_use_struct_convention (int gcc_p, struct type *type)
c906108c 282{
70eb15a4
CV
283 /* According to ABI:
284 * return TYPE_LENGTH (type) > 8);
285 */
286
287 /* Current implementation in gcc: */
288
289 int i;
290 struct type *fld_type, *tgt_type;
291
292 /* 1. The value is greater than 8 bytes -> returned by copying */
293 if (TYPE_LENGTH (type) > 8)
294 return 1;
295
296 /* 2. The value is a single basic type -> returned in register */
297 if (v850_type_is_scalar (type))
298 return 0;
299
300 /* The value is a structure or union with a single element
301 * and that element is either a single basic type or an array of
302 * a single basic type whoes size is greater than or equal to 4
303 * -> returned in register */
304 if ((TYPE_CODE (type) == TYPE_CODE_STRUCT
305 || TYPE_CODE (type) == TYPE_CODE_UNION)
306 && TYPE_NFIELDS (type) == 1)
307 {
308 fld_type = TYPE_FIELD_TYPE (type, 0);
309 if (v850_type_is_scalar (fld_type) && TYPE_LENGTH (fld_type) >= 4)
310 return 0;
311
312 if (TYPE_CODE (fld_type) == TYPE_CODE_ARRAY)
313 {
314 tgt_type = TYPE_TARGET_TYPE (fld_type);
315 if (v850_type_is_scalar (tgt_type) && TYPE_LENGTH (tgt_type) >= 4)
316 return 0;
317 }
318 }
319
320 /* The value is a structure whose first element is an integer or
321 * a float, and which contains no arrays of more than two elements
322 * -> returned in register */
323 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
324 && v850_type_is_scalar (TYPE_FIELD_TYPE (type, 0))
325 && TYPE_LENGTH (TYPE_FIELD_TYPE (type, 0)) == 4)
326 {
327 for (i = 1; i < TYPE_NFIELDS (type); ++i)
328 {
329 fld_type = TYPE_FIELD_TYPE (type, 0);
330 if (TYPE_CODE (fld_type) == TYPE_CODE_ARRAY)
331 {
332 tgt_type = TYPE_TARGET_TYPE (fld_type);
333 if (TYPE_LENGTH (fld_type) >= 0 && TYPE_LENGTH (tgt_type) >= 0
334 && TYPE_LENGTH (fld_type) / TYPE_LENGTH (tgt_type) > 2)
335 return 1;
336 }
337 }
338 return 0;
339 }
340
341 /* The value is a union which contains at least one field which
342 * would be returned in registers according to these rules
343 * -> returned in register */
344 if (TYPE_CODE (type) == TYPE_CODE_UNION)
345 {
346 for (i = 0; i < TYPE_NFIELDS (type); ++i)
347 {
348 fld_type = TYPE_FIELD_TYPE (type, 0);
349 if (!v850_use_struct_convention (0, fld_type))
350 return 0;
351 }
352 }
353
354 return 1;
c906108c 355}
c906108c
SS
356\f
357
c5aa993b 358
c906108c 359/* Structure for mapping bits in register lists to register numbers. */
c5aa993b 360struct reg_list
c906108c
SS
361{
362 long mask;
363 int regno;
364};
365
366/* Helper function for v850_scan_prologue to handle prepare instruction. */
367
368static void
c5aa993b 369handle_prepare (int insn, int insn2, CORE_ADDR * current_pc_ptr,
c906108c 370 struct prologue_info *pi, struct pifsr **pifsr_ptr)
c906108c
SS
371{
372 CORE_ADDR current_pc = *current_pc_ptr;
373 struct pifsr *pifsr = *pifsr_ptr;
374 long next = insn2 & 0xffff;
375 long list12 = ((insn & 1) << 16) + (next & 0xffe0);
376 long offset = (insn & 0x3e) << 1;
c5aa993b 377 static struct reg_list reg_table[] =
c906108c 378 {
c5aa993b
JM
379 {0x00800, 20}, /* r20 */
380 {0x00400, 21}, /* r21 */
381 {0x00200, 22}, /* r22 */
382 {0x00100, 23}, /* r23 */
383 {0x08000, 24}, /* r24 */
384 {0x04000, 25}, /* r25 */
385 {0x02000, 26}, /* r26 */
386 {0x01000, 27}, /* r27 */
387 {0x00080, 28}, /* r28 */
388 {0x00040, 29}, /* r29 */
389 {0x10000, 30}, /* ep */
390 {0x00020, 31}, /* lp */
391 {0, 0} /* end of table */
c906108c
SS
392 };
393 int i;
394
c5aa993b 395 if ((next & 0x1f) == 0x0b) /* skip imm16 argument */
c906108c
SS
396 current_pc += 2;
397 else if ((next & 0x1f) == 0x13) /* skip imm16 argument */
398 current_pc += 2;
399 else if ((next & 0x1f) == 0x1b) /* skip imm32 argument */
400 current_pc += 4;
401
402 /* Calculate the total size of the saved registers, and add it
403 it to the immediate value used to adjust SP. */
404 for (i = 0; reg_table[i].mask != 0; i++)
405 if (list12 & reg_table[i].mask)
435e042a 406 offset += v850_register_raw_size (reg_table[i].regno);
c906108c
SS
407 pi->frameoffset -= offset;
408
409 /* Calculate the offsets of the registers relative to the value
410 the SP will have after the registers have been pushed and the
411 imm5 value has been subtracted from it. */
412 if (pifsr)
413 {
414 for (i = 0; reg_table[i].mask != 0; i++)
415 {
416 if (list12 & reg_table[i].mask)
417 {
418 int reg = reg_table[i].regno;
435e042a 419 offset -= v850_register_raw_size (reg);
c906108c
SS
420 pifsr->reg = reg;
421 pifsr->offset = offset;
422 pifsr->cur_frameoffset = pi->frameoffset;
c5aa993b 423#ifdef DEBUG
c906108c 424 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
c5aa993b 425#endif
c906108c
SS
426 pifsr++;
427 }
428 }
429 }
430#ifdef DEBUG
431 printf_filtered ("\tfound ctret after regsave func");
432#endif
433
434 /* Set result parameters. */
435 *current_pc_ptr = current_pc;
436 *pifsr_ptr = pifsr;
437}
438
439
440/* Helper function for v850_scan_prologue to handle pushm/pushl instructions.
441 FIXME: the SR bit of the register list is not supported; must check
442 that the compiler does not ever generate this bit. */
443
444static void
445handle_pushm (int insn, int insn2, struct prologue_info *pi,
c5aa993b 446 struct pifsr **pifsr_ptr)
c906108c
SS
447{
448 struct pifsr *pifsr = *pifsr_ptr;
449 long list12 = ((insn & 0x0f) << 16) + (insn2 & 0xfff0);
450 long offset = 0;
c5aa993b 451 static struct reg_list pushml_reg_table[] =
c906108c 452 {
435e042a 453 {0x80000, E_PS_REGNUM}, /* PSW */
c5aa993b
JM
454 {0x40000, 1}, /* r1 */
455 {0x20000, 2}, /* r2 */
456 {0x10000, 3}, /* r3 */
457 {0x00800, 4}, /* r4 */
458 {0x00400, 5}, /* r5 */
459 {0x00200, 6}, /* r6 */
460 {0x00100, 7}, /* r7 */
461 {0x08000, 8}, /* r8 */
462 {0x04000, 9}, /* r9 */
463 {0x02000, 10}, /* r10 */
464 {0x01000, 11}, /* r11 */
465 {0x00080, 12}, /* r12 */
466 {0x00040, 13}, /* r13 */
467 {0x00020, 14}, /* r14 */
468 {0x00010, 15}, /* r15 */
469 {0, 0} /* end of table */
c906108c 470 };
c5aa993b 471 static struct reg_list pushmh_reg_table[] =
c906108c 472 {
c5aa993b
JM
473 {0x80000, 16}, /* r16 */
474 {0x40000, 17}, /* r17 */
475 {0x20000, 18}, /* r18 */
476 {0x10000, 19}, /* r19 */
477 {0x00800, 20}, /* r20 */
478 {0x00400, 21}, /* r21 */
479 {0x00200, 22}, /* r22 */
480 {0x00100, 23}, /* r23 */
481 {0x08000, 24}, /* r24 */
482 {0x04000, 25}, /* r25 */
483 {0x02000, 26}, /* r26 */
484 {0x01000, 27}, /* r27 */
485 {0x00080, 28}, /* r28 */
486 {0x00040, 29}, /* r29 */
487 {0x00010, 30}, /* r30 */
488 {0x00020, 31}, /* r31 */
489 {0, 0} /* end of table */
c906108c
SS
490 };
491 struct reg_list *reg_table;
492 int i;
493
494 /* Is this a pushml or a pushmh? */
495 if ((insn2 & 7) == 1)
496 reg_table = pushml_reg_table;
497 else
498 reg_table = pushmh_reg_table;
499
500 /* Calculate the total size of the saved registers, and add it
501 it to the immediate value used to adjust SP. */
502 for (i = 0; reg_table[i].mask != 0; i++)
503 if (list12 & reg_table[i].mask)
435e042a 504 offset += v850_register_raw_size (reg_table[i].regno);
c906108c
SS
505 pi->frameoffset -= offset;
506
507 /* Calculate the offsets of the registers relative to the value
508 the SP will have after the registers have been pushed and the
509 imm5 value is subtracted from it. */
510 if (pifsr)
511 {
512 for (i = 0; reg_table[i].mask != 0; i++)
513 {
514 if (list12 & reg_table[i].mask)
515 {
516 int reg = reg_table[i].regno;
435e042a 517 offset -= v850_register_raw_size (reg);
c906108c
SS
518 pifsr->reg = reg;
519 pifsr->offset = offset;
520 pifsr->cur_frameoffset = pi->frameoffset;
c5aa993b 521#ifdef DEBUG
c906108c 522 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
c5aa993b 523#endif
c906108c
SS
524 pifsr++;
525 }
526 }
527 }
528#ifdef DEBUG
529 printf_filtered ("\tfound ctret after regsave func");
530#endif
531
532 /* Set result parameters. */
533 *pifsr_ptr = pifsr;
534}
c5aa993b 535\f
c906108c
SS
536
537
538
c906108c
SS
539/* Function: scan_prologue
540 Scan the prologue of the function that contains PC, and record what
3a06899a
CV
541 we find in PI. Returns the pc after the prologue. Note that the
542 addresses saved in frame->saved_regs are just frame relative (negative
543 offsets from the frame pointer). This is because we don't know the
544 actual value of the frame pointer yet. In some circumstances, the
545 frame pointer can't be determined till after we have scanned the
546 prologue. */
c906108c
SS
547
548static CORE_ADDR
fba45db2 549v850_scan_prologue (CORE_ADDR pc, struct prologue_info *pi)
c906108c
SS
550{
551 CORE_ADDR func_addr, prologue_end, current_pc;
552 struct pifsr *pifsr, *pifsr_tmp;
553 int fp_used;
554 int ep_used;
555 int reg;
556 CORE_ADDR save_pc, save_end;
557 int regsave_func_p;
558 int r12_tmp;
559
560 /* First, figure out the bounds of the prologue so that we can limit the
561 search to something reasonable. */
562
563 if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
564 {
565 struct symtab_and_line sal;
566
567 sal = find_pc_line (func_addr, 0);
568
569 if (func_addr == entry_point_address ())
570 pi->start_function = 1;
571 else
572 pi->start_function = 0;
573
574#if 0
575 if (sal.line == 0)
576 prologue_end = pc;
577 else
578 prologue_end = sal.end;
579#else
580 prologue_end = pc;
581#endif
582 }
583 else
584 { /* We're in the boondocks */
585 func_addr = pc - 100;
586 prologue_end = pc;
587 }
588
589 prologue_end = min (prologue_end, pc);
590
591 /* Now, search the prologue looking for instructions that setup fp, save
592 rp, adjust sp and such. We also record the frame offset of any saved
c5aa993b 593 registers. */
c906108c
SS
594
595 pi->frameoffset = 0;
435e042a 596 pi->framereg = E_SP_REGNUM;
c906108c
SS
597 fp_used = 0;
598 ep_used = 0;
599 pifsr = pi->pifsrs;
600 regsave_func_p = 0;
601 save_pc = 0;
602 save_end = 0;
603 r12_tmp = 0;
604
605#ifdef DEBUG
606 printf_filtered ("Current_pc = 0x%.8lx, prologue_end = 0x%.8lx\n",
c5aa993b 607 (long) func_addr, (long) prologue_end);
c906108c
SS
608#endif
609
c5aa993b 610 for (current_pc = func_addr; current_pc < prologue_end;)
c906108c 611 {
93d56215
AC
612 int insn;
613 int insn2 = -1; /* dummy value */
c906108c
SS
614
615#ifdef DEBUG
92bf2b80
AC
616 fprintf_filtered (gdb_stdlog, "0x%.8lx ", (long) current_pc);
617 gdb_print_insn (current_pc, gdb_stdlog);
c906108c
SS
618#endif
619
620 insn = read_memory_unsigned_integer (current_pc, 2);
621 current_pc += 2;
c5aa993b 622 if ((insn & 0x0780) >= 0x0600) /* Four byte instruction? */
c906108c
SS
623 {
624 insn2 = read_memory_unsigned_integer (current_pc, 2);
625 current_pc += 2;
626 }
627
628 if ((insn & 0xffc0) == ((10 << 11) | 0x0780) && !regsave_func_p)
629 { /* jarl <func>,10 */
c5aa993b 630 long low_disp = insn2 & ~(long) 1;
c906108c 631 long disp = (((((insn & 0x3f) << 16) + low_disp)
c5aa993b 632 & ~(long) 1) ^ 0x00200000) - 0x00200000;
c906108c
SS
633
634 save_pc = current_pc;
635 save_end = prologue_end;
636 regsave_func_p = 1;
637 current_pc += disp - 4;
638 prologue_end = (current_pc
639 + (2 * 3) /* moves to/from ep */
c5aa993b
JM
640 + 4 /* addi <const>,sp,sp */
641 + 2 /* jmp [r10] */
c906108c
SS
642 + (2 * 12) /* sst.w to save r2, r20-r29, r31 */
643 + 20); /* slop area */
644
645#ifdef DEBUG
646 printf_filtered ("\tfound jarl <func>,r10, disp = %ld, low_disp = %ld, new pc = 0x%.8lx\n",
c5aa993b 647 disp, low_disp, (long) current_pc + 2);
c906108c
SS
648#endif
649 continue;
650 }
651 else if ((insn & 0xffc0) == 0x0200 && !regsave_func_p)
652 { /* callt <imm6> */
435e042a 653 long ctbp = read_register (E_CTBP_REGNUM);
c906108c
SS
654 long adr = ctbp + ((insn & 0x3f) << 1);
655
656 save_pc = current_pc;
657 save_end = prologue_end;
658 regsave_func_p = 1;
659 current_pc = ctbp + (read_memory_unsigned_integer (adr, 2) & 0xffff);
660 prologue_end = (current_pc
661 + (2 * 3) /* prepare list2,imm5,sp/imm */
c5aa993b 662 + 4 /* ctret */
c906108c
SS
663 + 20); /* slop area */
664
665#ifdef DEBUG
666 printf_filtered ("\tfound callt, ctbp = 0x%.8lx, adr = %.8lx, new pc = 0x%.8lx\n",
c5aa993b 667 ctbp, adr, (long) current_pc);
c906108c
SS
668#endif
669 continue;
670 }
671 else if ((insn & 0xffc0) == 0x0780) /* prepare list2,imm5 */
672 {
673 handle_prepare (insn, insn2, &current_pc, pi, &pifsr);
674 continue;
675 }
676 else if (insn == 0x07e0 && regsave_func_p && insn2 == 0x0144)
677 { /* ctret after processing register save function */
678 current_pc = save_pc;
679 prologue_end = save_end;
680 regsave_func_p = 0;
681#ifdef DEBUG
682 printf_filtered ("\tfound ctret after regsave func");
683#endif
684 continue;
685 }
686 else if ((insn & 0xfff0) == 0x07e0 && (insn2 & 5) == 1)
687 { /* pushml, pushmh */
688 handle_pushm (insn, insn2, pi, &pifsr);
689 continue;
690 }
691 else if ((insn & 0xffe0) == 0x0060 && regsave_func_p)
692 { /* jmp after processing register save function */
693 current_pc = save_pc;
694 prologue_end = save_end;
695 regsave_func_p = 0;
696#ifdef DEBUG
697 printf_filtered ("\tfound jmp after regsave func");
698#endif
699 continue;
700 }
701 else if ((insn & 0x07c0) == 0x0780 /* jarl or jr */
702 || (insn & 0xffe0) == 0x0060 /* jmp */
703 || (insn & 0x0780) == 0x0580) /* branch */
704 {
705#ifdef DEBUG
706 printf_filtered ("\n");
707#endif
c5aa993b 708 break; /* Ran into end of prologue */
c906108c
SS
709 }
710
435e042a 711 else if ((insn & 0xffe0) == ((E_SP_REGNUM << 11) | 0x0240)) /* add <imm>,sp */
c906108c 712 pi->frameoffset += ((insn & 0x1f) ^ 0x10) - 0x10;
435e042a 713 else if (insn == ((E_SP_REGNUM << 11) | 0x0600 | E_SP_REGNUM)) /* addi <imm>,sp,sp */
c906108c 714 pi->frameoffset += insn2;
435e042a 715 else if (insn == ((E_FP_RAW_REGNUM << 11) | 0x0000 | E_SP_REGNUM)) /* mov sp,fp */
c906108c
SS
716 {
717 fp_used = 1;
435e042a 718 pi->framereg = E_FP_RAW_REGNUM;
c906108c
SS
719 }
720
435e042a 721 else if (insn == ((E_R12_REGNUM << 11) | 0x0640 | E_R0_REGNUM)) /* movhi hi(const),r0,r12 */
c906108c 722 r12_tmp = insn2 << 16;
435e042a 723 else if (insn == ((E_R12_REGNUM << 11) | 0x0620 | E_R12_REGNUM)) /* movea lo(const),r12,r12 */
c906108c 724 r12_tmp += insn2;
435e042a 725 else if (insn == ((E_SP_REGNUM << 11) | 0x01c0 | E_R12_REGNUM) && r12_tmp) /* add r12,sp */
c906108c 726 pi->frameoffset = r12_tmp;
435e042a 727 else if (insn == ((E_EP_REGNUM << 11) | 0x0000 | E_SP_REGNUM)) /* mov sp,ep */
c906108c 728 ep_used = 1;
435e042a 729 else if (insn == ((E_EP_REGNUM << 11) | 0x0000 | E_R1_REGNUM)) /* mov r1,ep */
c906108c 730 ep_used = 0;
435e042a 731 else if (((insn & 0x07ff) == (0x0760 | E_SP_REGNUM) /* st.w <reg>,<offset>[sp] */
c906108c 732 || (fp_used
435e042a 733 && (insn & 0x07ff) == (0x0760 | E_FP_RAW_REGNUM))) /* st.w <reg>,<offset>[fp] */
c906108c 734 && pifsr
435e042a
CV
735 && (((reg = (insn >> 11) & 0x1f) >= E_SAVE1_START_REGNUM && reg <= E_SAVE1_END_REGNUM)
736 || (reg >= E_SAVE2_START_REGNUM && reg <= E_SAVE2_END_REGNUM)
737 || (reg >= E_SAVE3_START_REGNUM && reg <= E_SAVE3_END_REGNUM)))
c906108c
SS
738 {
739 pifsr->reg = reg;
740 pifsr->offset = insn2 & ~1;
741 pifsr->cur_frameoffset = pi->frameoffset;
742#ifdef DEBUG
743 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
744#endif
745 pifsr++;
746 }
747
c5aa993b 748 else if (ep_used /* sst.w <reg>,<offset>[ep] */
c906108c
SS
749 && ((insn & 0x0781) == 0x0501)
750 && pifsr
435e042a
CV
751 && (((reg = (insn >> 11) & 0x1f) >= E_SAVE1_START_REGNUM && reg <= E_SAVE1_END_REGNUM)
752 || (reg >= E_SAVE2_START_REGNUM && reg <= E_SAVE2_END_REGNUM)
753 || (reg >= E_SAVE3_START_REGNUM && reg <= E_SAVE3_END_REGNUM)))
c906108c
SS
754 {
755 pifsr->reg = reg;
756 pifsr->offset = (insn & 0x007e) << 1;
757 pifsr->cur_frameoffset = pi->frameoffset;
758#ifdef DEBUG
759 printf_filtered ("\tSaved register r%d, offset %d", reg, pifsr->offset);
760#endif
761 pifsr++;
762 }
763
764#ifdef DEBUG
765 printf_filtered ("\n");
766#endif
767 }
768
769 if (pifsr)
770 pifsr->framereg = 0; /* Tie off last entry */
771
772 /* Fix up any offsets to the final offset. If a frame pointer was created, use it
773 instead of the stack pointer. */
774 for (pifsr_tmp = pi->pifsrs; pifsr_tmp && pifsr_tmp != pifsr; pifsr_tmp++)
775 {
776 pifsr_tmp->offset -= pi->frameoffset - pifsr_tmp->cur_frameoffset;
777 pifsr_tmp->framereg = pi->framereg;
778
779#ifdef DEBUG
780 printf_filtered ("Saved register r%d, offset = %d, framereg = r%d\n",
c5aa993b 781 pifsr_tmp->reg, pifsr_tmp->offset, pifsr_tmp->framereg);
c906108c
SS
782#endif
783 }
784
785#ifdef DEBUG
786 printf_filtered ("Framereg = r%d, frameoffset = %d\n", pi->framereg, pi->frameoffset);
787#endif
788
789 return current_pc;
790}
791
435e042a
CV
792/* Function: find_callers_reg
793 Find REGNUM on the stack. Otherwise, it's in an active register.
794 One thing we might want to do here is to check REGNUM against the
795 clobber mask, and somehow flag it as invalid if it isn't saved on
796 the stack somewhere. This would provide a graceful failure mode
797 when trying to get the value of caller-saves registers for an inner
798 frame. */
c906108c 799
a78f21af 800static CORE_ADDR
435e042a 801v850_find_callers_reg (struct frame_info *fi, int regnum)
c906108c 802{
11c02a10 803 for (; fi; fi = get_next_frame (fi))
1e2330ba
AC
804 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), get_frame_base (fi),
805 get_frame_base (fi)))
806 return deprecated_read_register_dummy (get_frame_pc (fi),
807 get_frame_base (fi), regnum);
b2fb4676
AC
808 else if (get_frame_saved_regs (fi)[regnum] != 0)
809 return read_memory_unsigned_integer (get_frame_saved_regs (fi)[regnum],
435e042a 810 v850_register_raw_size (regnum));
c906108c 811
435e042a 812 return read_register (regnum);
c906108c
SS
813}
814
815/* Function: frame_chain
816 Figure out the frame prior to FI. Unfortunately, this involves
817 scanning the prologue of the caller, which will also be done
818 shortly by v850_init_extra_frame_info. For the dummy frame, we
819 just return the stack pointer that was in use at the time the
820 function call was made. */
821
a78f21af 822static CORE_ADDR
fba45db2 823v850_frame_chain (struct frame_info *fi)
c906108c
SS
824{
825 struct prologue_info pi;
826 CORE_ADDR callers_pc, fp;
827
828 /* First, find out who called us */
8bedc050 829 callers_pc = DEPRECATED_FRAME_SAVED_PC (fi);
c906108c 830 /* If caller is a call-dummy, then our FP bears no relation to his FP! */
435e042a 831 fp = v850_find_callers_reg (fi, E_FP_RAW_REGNUM);
ae45cd16 832 if (DEPRECATED_PC_IN_CALL_DUMMY (callers_pc, fp, fp))
c5aa993b 833 return fp; /* caller is call-dummy: return oldest value of FP */
c906108c
SS
834
835 /* Caller is NOT a call-dummy, so everything else should just work.
836 Even if THIS frame is a call-dummy! */
837 pi.pifsrs = NULL;
838
839 v850_scan_prologue (callers_pc, &pi);
840
841 if (pi.start_function)
842 return 0; /* Don't chain beyond the start function */
843
435e042a 844 if (pi.framereg == E_FP_RAW_REGNUM)
c906108c
SS
845 return v850_find_callers_reg (fi, pi.framereg);
846
1e2330ba 847 return get_frame_base (fi) - pi.frameoffset;
c906108c
SS
848}
849
c906108c
SS
850/* Function: skip_prologue
851 Return the address of the first code past the prologue of the function. */
852
a78f21af 853static CORE_ADDR
fba45db2 854v850_skip_prologue (CORE_ADDR pc)
c906108c
SS
855{
856 CORE_ADDR func_addr, func_end;
857
858 /* See what the symbol table says */
859
860 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
861 {
862 struct symtab_and_line sal;
863
864 sal = find_pc_line (func_addr, 0);
865
866 if (sal.line != 0 && sal.end < func_end)
867 return sal.end;
868 else
869 /* Either there's no line info, or the line after the prologue is after
870 the end of the function. In this case, there probably isn't a
871 prologue. */
872 return pc;
873 }
874
875/* We can't find the start of this function, so there's nothing we can do. */
876 return pc;
877}
878
879/* Function: pop_frame
880 This routine gets called when either the user uses the `return'
881 command, or the call dummy breakpoint gets hit. */
882
a78f21af 883static void
435e042a 884v850_pop_frame (void)
c906108c 885{
435e042a 886 struct frame_info *frame = get_current_frame ();
c906108c
SS
887 int regnum;
888
1e2330ba
AC
889 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (frame),
890 get_frame_base (frame),
891 get_frame_base (frame)))
c906108c
SS
892 generic_pop_dummy_frame ();
893 else
894 {
8bedc050 895 write_register (E_PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
c906108c 896
435e042a 897 for (regnum = 0; regnum < E_NUM_REGS; regnum++)
b2fb4676 898 if (get_frame_saved_regs (frame)[regnum] != 0)
c906108c 899 write_register (regnum,
b2fb4676 900 read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
435e042a 901 v850_register_raw_size (regnum)));
c906108c 902
c193f6ac 903 write_register (E_SP_REGNUM, get_frame_base (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 919
a78f21af 920static CORE_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 960 {
fbd9dcd3 961 store_unsigned_integer (valbuf, 4, VALUE_ADDRESS (*args));
c906108c
SS
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
7c0b4a20 976 regval = extract_unsigned_integer (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
a78f21af 1000static CORE_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
a78f21af 1014static CORE_ADDR
fba45db2 1015v850_frame_saved_pc (struct frame_info *fi)
c906108c 1016{
1e2330ba
AC
1017 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), get_frame_base (fi),
1018 get_frame_base (fi)))
1019 return deprecated_read_register_dummy (get_frame_pc (fi),
1020 get_frame_base (fi), E_PC_REGNUM);
c906108c 1021 else
435e042a 1022 return v850_find_callers_reg (fi, E_RP_REGNUM);
c906108c
SS
1023}
1024
c906108c
SS
1025
1026/* Function: fix_call_dummy
1027 Pokes the callee function's address into the CALL_DUMMY assembly stub.
1028 Assumes that the CALL_DUMMY looks like this:
c5aa993b
JM
1029 jarl <offset24>, r31
1030 trap
1031 */
c906108c 1032
a78f21af 1033static void
fba45db2 1034v850_fix_call_dummy (char *dummy, CORE_ADDR sp, CORE_ADDR fun, int nargs,
ea7c478f 1035 struct value **args, struct type *type, int gcc_p)
c906108c
SS
1036{
1037 long offset24;
1038
1039 offset24 = (long) fun - (long) entry_point_address ();
1040 offset24 &= 0x3fffff;
1041 offset24 |= 0xff800000; /* jarl <offset24>, r31 */
1042
c5aa993b
JM
1043 store_unsigned_integer ((unsigned int *) &dummy[2], 2, offset24 & 0xffff);
1044 store_unsigned_integer ((unsigned int *) &dummy[0], 2, offset24 >> 16);
435e042a
CV
1045}
1046
1047static CORE_ADDR
1048v850_saved_pc_after_call (struct frame_info *ignore)
1049{
1050 return read_register (E_RP_REGNUM);
1051}
1052
1053static void
1054v850_extract_return_value (struct type *type, char *regbuf, char *valbuf)
1055{
70eb15a4
CV
1056 CORE_ADDR return_buffer;
1057
1058 if (!v850_use_struct_convention (0, type))
1059 {
1060 /* Scalar return values of <= 8 bytes are returned in
1061 E_V0_REGNUM to E_V1_REGNUM. */
1062 memcpy (valbuf,
1063 &regbuf[REGISTER_BYTE (E_V0_REGNUM)],
1064 TYPE_LENGTH (type));
1065 }
1066 else
1067 {
1068 /* Aggregates and return values > 8 bytes are returned in memory,
1069 pointed to by R6. */
1070 return_buffer =
7c0b4a20
AC
1071 extract_unsigned_integer (regbuf + REGISTER_BYTE (E_V0_REGNUM),
1072 REGISTER_RAW_SIZE (E_V0_REGNUM));
70eb15a4
CV
1073
1074 read_memory (return_buffer, valbuf, TYPE_LENGTH (type));
1075 }
435e042a
CV
1076}
1077
1078const static unsigned char *
1079v850_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
1080{
1081 static unsigned char breakpoint[] = { 0x85, 0x05 };
1082 *lenptr = sizeof (breakpoint);
1083 return breakpoint;
1084}
1085
1086static CORE_ADDR
1087v850_extract_struct_value_address (char *regbuf)
1088{
7c0b4a20
AC
1089 return extract_unsigned_integer (regbuf + v850_register_byte (E_V0_REGNUM),
1090 v850_register_raw_size (E_V0_REGNUM));
435e042a
CV
1091}
1092
1093static void
1094v850_store_return_value (struct type *type, char *valbuf)
1095{
70eb15a4
CV
1096 CORE_ADDR return_buffer;
1097
1098 if (!v850_use_struct_convention (0, type))
73937e03
AC
1099 deprecated_write_register_bytes (REGISTER_BYTE (E_V0_REGNUM), valbuf,
1100 TYPE_LENGTH (type));
70eb15a4
CV
1101 else
1102 {
1103 return_buffer = read_register (E_V0_REGNUM);
1104 write_memory (return_buffer, valbuf, TYPE_LENGTH (type));
1105 }
435e042a
CV
1106}
1107
1108static void
1109v850_frame_init_saved_regs (struct frame_info *fi)
1110{
1111 struct prologue_info pi;
1112 struct pifsr pifsrs[E_NUM_REGS + 1], *pifsr;
1113 CORE_ADDR func_addr, func_end;
1114
b2fb4676 1115 if (!get_frame_saved_regs (fi))
435e042a
CV
1116 {
1117 frame_saved_regs_zalloc (fi);
1118
1119 /* The call dummy doesn't save any registers on the stack, so we
1120 can return now. */
1e2330ba
AC
1121 if (DEPRECATED_PC_IN_CALL_DUMMY (get_frame_pc (fi), get_frame_base (fi),
1122 get_frame_base (fi)))
435e042a
CV
1123 return;
1124
1125 /* Find the beginning of this function, so we can analyze its
1126 prologue. */
50abf9e5 1127 if (find_pc_partial_function (get_frame_pc (fi), NULL, &func_addr, &func_end))
435e042a
CV
1128 {
1129 pi.pifsrs = pifsrs;
1130
50abf9e5 1131 v850_scan_prologue (get_frame_pc (fi), &pi);
435e042a 1132
11c02a10 1133 if (!get_next_frame (fi) && pi.framereg == E_SP_REGNUM)
8ccd593b 1134 deprecated_update_frame_base_hack (fi, read_register (pi.framereg) - pi.frameoffset);
435e042a
CV
1135
1136 for (pifsr = pifsrs; pifsr->framereg; pifsr++)
1137 {
1e2330ba 1138 get_frame_saved_regs (fi)[pifsr->reg] = pifsr->offset + get_frame_base (fi);
435e042a
CV
1139
1140 if (pifsr->framereg == E_SP_REGNUM)
b2fb4676 1141 get_frame_saved_regs (fi)[pifsr->reg] += pi.frameoffset;
435e042a
CV
1142 }
1143 }
1144 /* Else we're out of luck (can't debug completely stripped code).
1145 FIXME. */
1146 }
1147}
1148
1149/* Function: init_extra_frame_info
1150 Setup the frame's frame pointer, pc, and frame addresses for saved
1151 registers. Most of the work is done in scan_prologue().
1152
1153 Note that when we are called for the last frame (currently active frame),
50abf9e5 1154 that get_frame_pc (fi) and fi->frame will already be setup. However, fi->frame will
435e042a
CV
1155 be valid only if this routine uses FP. For previous frames, fi-frame will
1156 always be correct (since that is derived from v850_frame_chain ()).
1157
04714b91
AC
1158 We can be called with the PC in the call dummy under two
1159 circumstances. First, during normal backtracing, second, while
1160 figuring out the frame pointer just prior to calling the target
1161 function (see call_function_by_hand). */
435e042a
CV
1162
1163static void
1164v850_init_extra_frame_info (int fromleaf, struct frame_info *fi)
1165{
1166 struct prologue_info pi;
1167
11c02a10 1168 if (get_next_frame (fi))
8bedc050 1169 deprecated_update_frame_pc_hack (fi, DEPRECATED_FRAME_SAVED_PC (get_next_frame (fi)));
435e042a
CV
1170
1171 v850_frame_init_saved_regs (fi);
1172}
1173
1174static void
70eb15a4 1175v850_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
435e042a 1176{
70eb15a4 1177 write_register (E_ARG0_REGNUM, addr);
435e042a
CV
1178}
1179
1180static CORE_ADDR
1181v850_target_read_fp (void)
1182{
1183 return read_register (E_FP_RAW_REGNUM);
c906108c
SS
1184}
1185
6ed14b0e
CV
1186static struct gdbarch *
1187v850_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
c906108c 1188{
435e042a 1189 static LONGEST call_dummy_words[1] = { 0 };
6ed14b0e
CV
1190 struct gdbarch_tdep *tdep = NULL;
1191 struct gdbarch *gdbarch;
1192 int i;
1193
1194 /* find a candidate among the list of pre-declared architectures. */
1195 arches = gdbarch_list_lookup_by_info (arches, &info);
1196 if (arches != NULL)
1197 return (arches->gdbarch);
c906108c 1198
6ed14b0e
CV
1199#if 0
1200 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
1201#endif
1202
435e042a 1203 /* Change the register names based on the current machine type. */
6ed14b0e 1204 if (info.bfd_arch_info->arch != bfd_arch_v850)
c906108c
SS
1205 return 0;
1206
6ed14b0e
CV
1207 gdbarch = gdbarch_alloc (&info, 0);
1208
a5afb99f
AC
1209 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
1210 ready to unwind the PC first (see frame.c:get_prev_frame()). */
1211 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_default);
1212
c906108c
SS
1213 for (i = 0; v850_processor_type_table[i].regnames != NULL; i++)
1214 {
6ed14b0e 1215 if (v850_processor_type_table[i].mach == info.bfd_arch_info->mach)
435e042a
CV
1216 {
1217 v850_register_names = v850_processor_type_table[i].regnames;
810ecf9f 1218 deprecated_tm_print_insn_info.mach = info.bfd_arch_info->mach;
435e042a
CV
1219 break;
1220 }
c906108c
SS
1221 }
1222
435e042a
CV
1223 /*
1224 * Basic register fields and methods.
1225 */
1226 set_gdbarch_num_regs (gdbarch, E_NUM_REGS);
1227 set_gdbarch_num_pseudo_regs (gdbarch, 0);
1228 set_gdbarch_sp_regnum (gdbarch, E_SP_REGNUM);
0ba6dca9 1229 set_gdbarch_deprecated_fp_regnum (gdbarch, E_FP_REGNUM);
435e042a
CV
1230 set_gdbarch_pc_regnum (gdbarch, E_PC_REGNUM);
1231 set_gdbarch_register_name (gdbarch, v850_register_name);
b1e29e33 1232 set_gdbarch_deprecated_register_size (gdbarch, v850_reg_size);
b8b527c5 1233 set_gdbarch_deprecated_register_bytes (gdbarch, E_ALL_REGS_SIZE);
435e042a
CV
1234 set_gdbarch_register_byte (gdbarch, v850_register_byte);
1235 set_gdbarch_register_raw_size (gdbarch, v850_register_raw_size);
a0ed5532 1236 set_gdbarch_deprecated_max_register_raw_size (gdbarch, v850_reg_size);
435e042a 1237 set_gdbarch_register_virtual_size (gdbarch, v850_register_raw_size);
a0ed5532 1238 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, v850_reg_size);
435e042a
CV
1239 set_gdbarch_register_virtual_type (gdbarch, v850_reg_virtual_type);
1240
0ba6dca9 1241 set_gdbarch_deprecated_target_read_fp (gdbarch, v850_target_read_fp);
435e042a
CV
1242
1243 /*
1244 * Frame Info
1245 */
f30ee0bc 1246 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, v850_frame_init_saved_regs);
e9582e71 1247 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, v850_init_extra_frame_info);
618ce49f 1248 set_gdbarch_deprecated_frame_chain (gdbarch, v850_frame_chain);
6913c89a 1249 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, v850_saved_pc_after_call);
8bedc050 1250 set_gdbarch_deprecated_frame_saved_pc (gdbarch, v850_frame_saved_pc);
435e042a 1251 set_gdbarch_skip_prologue (gdbarch, v850_skip_prologue);
435e042a
CV
1252
1253 /*
1254 * Miscelany
1255 */
1256 /* Stack grows up. */
1257 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1258 /* PC stops zero byte after a trap instruction
1259 (which means: exactly on trap instruction). */
1260 set_gdbarch_decr_pc_after_break (gdbarch, 0);
1261 /* This value is almost never non-zero... */
1262 set_gdbarch_function_start_offset (gdbarch, 0);
1263 /* This value is almost never non-zero... */
1264 set_gdbarch_frame_args_skip (gdbarch, 0);
435e042a
CV
1265
1266 /*
1267 * Call Dummies
1268 *
1269 * These values and methods are used when gdb calls a target function. */
28f617b3 1270 set_gdbarch_deprecated_push_return_address (gdbarch, v850_push_return_address);
26e9b323 1271 set_gdbarch_deprecated_extract_return_value (gdbarch, v850_extract_return_value);
b81774d8 1272 set_gdbarch_deprecated_push_arguments (gdbarch, v850_push_arguments);
749b82f6 1273 set_gdbarch_deprecated_pop_frame (gdbarch, v850_pop_frame);
4183d812 1274 set_gdbarch_deprecated_store_struct_return (gdbarch, v850_store_struct_return);
ebba8386 1275 set_gdbarch_deprecated_store_return_value (gdbarch, v850_store_return_value);
26e9b323 1276 set_gdbarch_deprecated_extract_struct_value_address (gdbarch, v850_extract_struct_value_address);
435e042a 1277 set_gdbarch_use_struct_convention (gdbarch, v850_use_struct_convention);
b1e29e33
AC
1278 set_gdbarch_deprecated_call_dummy_words (gdbarch, call_dummy_nil);
1279 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, 0);
1280 set_gdbarch_deprecated_fix_call_dummy (gdbarch, v850_fix_call_dummy);
435e042a
CV
1281 set_gdbarch_breakpoint_from_pc (gdbarch, v850_breakpoint_from_pc);
1282
1283 set_gdbarch_int_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1284 set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1285 set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
1286 set_gdbarch_long_double_bit (gdbarch, 8 * TARGET_CHAR_BIT);
1287
6c0e89ed 1288 /* Should be using push_dummy_call. */
b46e02f6 1289 set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp);
6c0e89ed 1290
6ed14b0e 1291 return gdbarch;
c906108c
SS
1292}
1293
a78f21af
AC
1294extern initialize_file_ftype _initialize_v850_tdep; /* -Wmissing-prototypes */
1295
c906108c 1296void
fba45db2 1297_initialize_v850_tdep (void)
c906108c 1298{
d7a27068 1299 deprecated_tm_print_insn = print_insn_v850;
6ed14b0e 1300 register_gdbarch_init (bfd_arch_v850, v850_gdbarch_init);
c906108c 1301}
This page took 0.449269 seconds and 4 git commands to generate.