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