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