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