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