Commit | Line | Data |
---|---|---|
5769d3cd | 1 | /* Target-dependent code for GDB, the GNU debugger. |
ca557f44 | 2 | |
1e698235 | 3 | Copyright 2001, 2002, 2003 Free Software Foundation, Inc. |
ca557f44 | 4 | |
5769d3cd AC |
5 | Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) |
6 | for IBM Deutschland Entwicklung GmbH, IBM Corporation. | |
7 | ||
8 | This file is part of GDB. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with this program; if not, write to the Free Software | |
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
23 | 02111-1307, USA. */ | |
24 | ||
25 | #define S390_TDEP /* for special macros in tm-s390.h */ | |
26 | #include <defs.h> | |
27 | #include "arch-utils.h" | |
28 | #include "frame.h" | |
29 | #include "inferior.h" | |
30 | #include "symtab.h" | |
31 | #include "target.h" | |
32 | #include "gdbcore.h" | |
33 | #include "gdbcmd.h" | |
34 | #include "symfile.h" | |
35 | #include "objfiles.h" | |
36 | #include "tm.h" | |
37 | #include "../bfd/bfd.h" | |
38 | #include "floatformat.h" | |
39 | #include "regcache.h" | |
fd0407d6 | 40 | #include "value.h" |
78f8b424 | 41 | #include "gdb_assert.h" |
5769d3cd AC |
42 | |
43 | ||
44 | ||
60e6cc42 | 45 | |
5769d3cd | 46 | /* Number of bytes of storage in the actual machine representation |
23b7362f | 47 | for register N. */ |
a78f21af | 48 | static int |
5769d3cd AC |
49 | s390_register_raw_size (int reg_nr) |
50 | { | |
23b7362f JB |
51 | if (S390_FP0_REGNUM <= reg_nr |
52 | && reg_nr < S390_FP0_REGNUM + S390_NUM_FPRS) | |
53 | return S390_FPR_SIZE; | |
54 | else | |
55 | return 4; | |
5769d3cd AC |
56 | } |
57 | ||
a78f21af | 58 | static int |
5769d3cd AC |
59 | s390x_register_raw_size (int reg_nr) |
60 | { | |
61 | return (reg_nr == S390_FPC_REGNUM) | |
62 | || (reg_nr >= S390_FIRST_ACR && reg_nr <= S390_LAST_ACR) ? 4 : 8; | |
63 | } | |
64 | ||
a78f21af | 65 | static int |
5769d3cd AC |
66 | s390_cannot_fetch_register (int regno) |
67 | { | |
68 | return (regno >= S390_FIRST_CR && regno < (S390_FIRST_CR + 9)) || | |
69 | (regno >= (S390_FIRST_CR + 12) && regno <= S390_LAST_CR); | |
70 | } | |
71 | ||
a78f21af | 72 | static int |
5769d3cd AC |
73 | s390_register_byte (int reg_nr) |
74 | { | |
75 | if (reg_nr <= S390_GP_LAST_REGNUM) | |
76 | return reg_nr * S390_GPR_SIZE; | |
77 | if (reg_nr <= S390_LAST_ACR) | |
78 | return S390_ACR0_OFFSET + (((reg_nr) - S390_FIRST_ACR) * S390_ACR_SIZE); | |
79 | if (reg_nr <= S390_LAST_CR) | |
80 | return S390_CR0_OFFSET + (((reg_nr) - S390_FIRST_CR) * S390_CR_SIZE); | |
81 | if (reg_nr == S390_FPC_REGNUM) | |
82 | return S390_FPC_OFFSET; | |
83 | else | |
84 | return S390_FP0_OFFSET + (((reg_nr) - S390_FP0_REGNUM) * S390_FPR_SIZE); | |
85 | } | |
86 | ||
5769d3cd AC |
87 | #define S390_MAX_INSTR_SIZE (6) |
88 | #define S390_SYSCALL_OPCODE (0x0a) | |
89 | #define S390_SYSCALL_SIZE (2) | |
90 | #define S390_SIGCONTEXT_SREGS_OFFSET (8) | |
91 | #define S390X_SIGCONTEXT_SREGS_OFFSET (8) | |
92 | #define S390_SIGREGS_FP0_OFFSET (144) | |
93 | #define S390X_SIGREGS_FP0_OFFSET (216) | |
94 | #define S390_UC_MCONTEXT_OFFSET (256) | |
95 | #define S390X_UC_MCONTEXT_OFFSET (344) | |
4d819d0e JB |
96 | #define S390_STACK_FRAME_OVERHEAD 16*DEPRECATED_REGISTER_SIZE+32 |
97 | #define S390_STACK_PARAMETER_ALIGNMENT DEPRECATED_REGISTER_SIZE | |
98 | #define S390_NUM_FP_PARAMETER_REGISTERS (GDB_TARGET_IS_ESAME ? 4:2) | |
5769d3cd AC |
99 | #define S390_SIGNAL_FRAMESIZE (GDB_TARGET_IS_ESAME ? 160:96) |
100 | #define s390_NR_sigreturn 119 | |
101 | #define s390_NR_rt_sigreturn 173 | |
102 | ||
103 | ||
104 | ||
105 | struct frame_extra_info | |
106 | { | |
107 | int initialised; | |
108 | int good_prologue; | |
109 | CORE_ADDR function_start; | |
110 | CORE_ADDR skip_prologue_function_start; | |
111 | CORE_ADDR saved_pc_valid; | |
112 | CORE_ADDR saved_pc; | |
113 | CORE_ADDR sig_fixed_saved_pc_valid; | |
114 | CORE_ADDR sig_fixed_saved_pc; | |
115 | CORE_ADDR frame_pointer_saved_pc; /* frame pointer needed for alloca */ | |
a9dd42f1 | 116 | CORE_ADDR stack_bought_valid; |
5769d3cd AC |
117 | CORE_ADDR stack_bought; /* amount we decrement the stack pointer by */ |
118 | CORE_ADDR sigcontext; | |
119 | }; | |
120 | ||
121 | ||
122 | static CORE_ADDR s390_frame_saved_pc_nofix (struct frame_info *fi); | |
123 | ||
a78f21af | 124 | static int |
5769d3cd AC |
125 | s390_readinstruction (bfd_byte instr[], CORE_ADDR at, |
126 | struct disassemble_info *info) | |
127 | { | |
128 | int instrlen; | |
129 | ||
130 | static int s390_instrlen[] = { | |
131 | 2, | |
132 | 4, | |
133 | 4, | |
134 | 6 | |
135 | }; | |
136 | if ((*info->read_memory_func) (at, &instr[0], 2, info)) | |
137 | return -1; | |
138 | instrlen = s390_instrlen[instr[0] >> 6]; | |
c5e243bb JB |
139 | if (instrlen > 2) |
140 | { | |
141 | if ((*info->read_memory_func) (at + 2, &instr[2], instrlen - 2, info)) | |
142 | return -1; | |
143 | } | |
5769d3cd AC |
144 | return instrlen; |
145 | } | |
146 | ||
147 | static void | |
148 | s390_memset_extra_info (struct frame_extra_info *fextra_info) | |
149 | { | |
150 | memset (fextra_info, 0, sizeof (struct frame_extra_info)); | |
151 | } | |
152 | ||
153 | ||
154 | ||
a78f21af | 155 | static const char * |
5769d3cd AC |
156 | s390_register_name (int reg_nr) |
157 | { | |
158 | static char *register_names[] = { | |
159 | "pswm", "pswa", | |
4ed90530 JB |
160 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
161 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
5769d3cd AC |
162 | "acr0", "acr1", "acr2", "acr3", "acr4", "acr5", "acr6", "acr7", |
163 | "acr8", "acr9", "acr10", "acr11", "acr12", "acr13", "acr14", "acr15", | |
164 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
165 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
166 | "fpc", | |
4ed90530 JB |
167 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
168 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15" | |
5769d3cd AC |
169 | }; |
170 | ||
b09677dc JB |
171 | if (reg_nr <= S390_LAST_REGNUM) |
172 | return register_names[reg_nr]; | |
173 | else | |
5769d3cd | 174 | return NULL; |
5769d3cd AC |
175 | } |
176 | ||
177 | ||
178 | ||
179 | ||
a78f21af | 180 | static int |
5769d3cd AC |
181 | s390_stab_reg_to_regnum (int regno) |
182 | { | |
183 | return regno >= 64 ? S390_PSWM_REGNUM - 64 : | |
184 | regno >= 48 ? S390_FIRST_ACR - 48 : | |
185 | regno >= 32 ? S390_FIRST_CR - 32 : | |
186 | regno <= 15 ? (regno + 2) : | |
187 | S390_FP0_REGNUM + ((regno - 16) & 8) + (((regno - 16) & 3) << 1) + | |
188 | (((regno - 16) & 4) >> 2); | |
189 | } | |
190 | ||
191 | ||
4bc8c588 JB |
192 | /* Prologue analysis. */ |
193 | ||
194 | /* When we analyze a prologue, we're really doing 'abstract | |
195 | interpretation' or 'pseudo-evaluation': running the function's code | |
196 | in simulation, but using conservative approximations of the values | |
197 | it would have when it actually runs. For example, if our function | |
198 | starts with the instruction: | |
199 | ||
200 | ahi r1, 42 # add halfword immediate 42 to r1 | |
201 | ||
202 | we don't know exactly what value will be in r1 after executing this | |
203 | instruction, but we do know it'll be 42 greater than its original | |
204 | value. | |
205 | ||
206 | If we then see an instruction like: | |
207 | ||
208 | ahi r1, 22 # add halfword immediate 22 to r1 | |
209 | ||
210 | we still don't know what r1's value is, but again, we can say it is | |
211 | now 64 greater than its original value. | |
212 | ||
213 | If the next instruction were: | |
214 | ||
215 | lr r2, r1 # set r2 to r1's value | |
216 | ||
217 | then we can say that r2's value is now the original value of r1 | |
218 | plus 64. And so on. | |
219 | ||
220 | Of course, this can only go so far before it gets unreasonable. If | |
221 | we wanted to be able to say anything about the value of r1 after | |
222 | the instruction: | |
223 | ||
224 | xr r1, r3 # exclusive-or r1 and r3, place result in r1 | |
225 | ||
226 | then things would get pretty complex. But remember, we're just | |
227 | doing a conservative approximation; if exclusive-or instructions | |
228 | aren't relevant to prologues, we can just say r1's value is now | |
229 | 'unknown'. We can ignore things that are too complex, if that loss | |
230 | of information is acceptable for our application. | |
231 | ||
232 | Once you've reached an instruction that you don't know how to | |
233 | simulate, you stop. Now you examine the state of the registers and | |
234 | stack slots you've kept track of. For example: | |
235 | ||
236 | - To see how large your stack frame is, just check the value of sp; | |
237 | if it's the original value of sp minus a constant, then that | |
238 | constant is the stack frame's size. If the sp's value has been | |
239 | marked as 'unknown', then that means the prologue has done | |
240 | something too complex for us to track, and we don't know the | |
241 | frame size. | |
242 | ||
243 | - To see whether we've saved the SP in the current frame's back | |
244 | chain slot, we just check whether the current value of the back | |
245 | chain stack slot is the original value of the sp. | |
246 | ||
247 | Sure, this takes some work. But prologue analyzers aren't | |
248 | quick-and-simple pattern patching to recognize a few fixed prologue | |
249 | forms any more; they're big, hairy functions. Along with inferior | |
250 | function calls, prologue analysis accounts for a substantial | |
251 | portion of the time needed to stabilize a GDB port. So I think | |
252 | it's worthwhile to look for an approach that will be easier to | |
253 | understand and maintain. In the approach used here: | |
254 | ||
255 | - It's easier to see that the analyzer is correct: you just see | |
256 | whether the analyzer properly (albiet conservatively) simulates | |
257 | the effect of each instruction. | |
258 | ||
259 | - It's easier to extend the analyzer: you can add support for new | |
260 | instructions, and know that you haven't broken anything that | |
261 | wasn't already broken before. | |
262 | ||
263 | - It's orthogonal: to gather new information, you don't need to | |
264 | complicate the code for each instruction. As long as your domain | |
265 | of conservative values is already detailed enough to tell you | |
266 | what you need, then all the existing instruction simulations are | |
267 | already gathering the right data for you. | |
268 | ||
269 | A 'struct prologue_value' is a conservative approximation of the | |
270 | real value the register or stack slot will have. */ | |
271 | ||
272 | struct prologue_value { | |
273 | ||
274 | /* What sort of value is this? This determines the interpretation | |
275 | of subsequent fields. */ | |
276 | enum { | |
277 | ||
278 | /* We don't know anything about the value. This is also used for | |
279 | values we could have kept track of, when doing so would have | |
280 | been too complex and we don't want to bother. The bottom of | |
281 | our lattice. */ | |
282 | pv_unknown, | |
283 | ||
284 | /* A known constant. K is its value. */ | |
285 | pv_constant, | |
286 | ||
287 | /* The value that register REG originally had *UPON ENTRY TO THE | |
288 | FUNCTION*, plus K. If K is zero, this means, obviously, just | |
289 | the value REG had upon entry to the function. REG is a GDB | |
290 | register number. Before we start interpreting, we initialize | |
291 | every register R to { pv_register, R, 0 }. */ | |
292 | pv_register, | |
293 | ||
294 | } kind; | |
295 | ||
296 | /* The meanings of the following fields depend on 'kind'; see the | |
297 | comments for the specific 'kind' values. */ | |
298 | int reg; | |
299 | CORE_ADDR k; | |
300 | }; | |
301 | ||
302 | ||
303 | /* Set V to be unknown. */ | |
304 | static void | |
305 | pv_set_to_unknown (struct prologue_value *v) | |
306 | { | |
307 | v->kind = pv_unknown; | |
308 | } | |
309 | ||
310 | ||
311 | /* Set V to the constant K. */ | |
312 | static void | |
313 | pv_set_to_constant (struct prologue_value *v, CORE_ADDR k) | |
314 | { | |
315 | v->kind = pv_constant; | |
316 | v->k = k; | |
317 | } | |
318 | ||
319 | ||
320 | /* Set V to the original value of register REG, plus K. */ | |
321 | static void | |
322 | pv_set_to_register (struct prologue_value *v, int reg, CORE_ADDR k) | |
323 | { | |
324 | v->kind = pv_register; | |
325 | v->reg = reg; | |
326 | v->k = k; | |
327 | } | |
328 | ||
329 | ||
330 | /* If one of *A and *B is a constant, and the other isn't, swap the | |
331 | pointers as necessary to ensure that *B points to the constant. | |
332 | This can reduce the number of cases we need to analyze in the | |
333 | functions below. */ | |
334 | static void | |
335 | pv_constant_last (struct prologue_value **a, | |
336 | struct prologue_value **b) | |
337 | { | |
338 | if ((*a)->kind == pv_constant | |
339 | && (*b)->kind != pv_constant) | |
340 | { | |
341 | struct prologue_value *temp = *a; | |
342 | *a = *b; | |
343 | *b = temp; | |
344 | } | |
345 | } | |
346 | ||
347 | ||
348 | /* Set SUM to the sum of A and B. SUM, A, and B may point to the same | |
349 | 'struct prologue_value' object. */ | |
350 | static void | |
351 | pv_add (struct prologue_value *sum, | |
352 | struct prologue_value *a, | |
353 | struct prologue_value *b) | |
354 | { | |
355 | pv_constant_last (&a, &b); | |
356 | ||
357 | /* We can handle adding constants to registers, and other constants. */ | |
358 | if (b->kind == pv_constant | |
359 | && (a->kind == pv_register | |
360 | || a->kind == pv_constant)) | |
361 | { | |
362 | sum->kind = a->kind; | |
363 | sum->reg = a->reg; /* not meaningful if a is pv_constant, but | |
364 | harmless */ | |
365 | sum->k = a->k + b->k; | |
366 | } | |
367 | ||
368 | /* Anything else we don't know how to add. We don't have a | |
369 | representation for, say, the sum of two registers, or a multiple | |
370 | of a register's value (adding a register to itself). */ | |
371 | else | |
372 | sum->kind = pv_unknown; | |
373 | } | |
374 | ||
375 | ||
376 | /* Add the constant K to V. */ | |
377 | static void | |
378 | pv_add_constant (struct prologue_value *v, CORE_ADDR k) | |
379 | { | |
380 | struct prologue_value pv_k; | |
381 | ||
382 | /* Rather than thinking of all the cases we can and can't handle, | |
383 | we'll just let pv_add take care of that for us. */ | |
384 | pv_set_to_constant (&pv_k, k); | |
385 | pv_add (v, v, &pv_k); | |
386 | } | |
387 | ||
388 | ||
389 | /* Subtract B from A, and put the result in DIFF. | |
390 | ||
391 | This isn't quite the same as negating B and adding it to A, since | |
392 | we don't have a representation for the negation of anything but a | |
393 | constant. For example, we can't negate { pv_register, R1, 10 }, | |
394 | but we do know that { pv_register, R1, 10 } minus { pv_register, | |
395 | R1, 5 } is { pv_constant, <ignored>, 5 }. | |
396 | ||
397 | This means, for example, that we can subtract two stack addresses; | |
398 | they're both relative to the original SP. Since the frame pointer | |
399 | is set based on the SP, its value will be the original SP plus some | |
400 | constant (probably zero), so we can use its value just fine. */ | |
401 | static void | |
402 | pv_subtract (struct prologue_value *diff, | |
403 | struct prologue_value *a, | |
404 | struct prologue_value *b) | |
405 | { | |
406 | pv_constant_last (&a, &b); | |
407 | ||
408 | /* We can subtract a constant from another constant, or from a | |
409 | register. */ | |
410 | if (b->kind == pv_constant | |
411 | && (a->kind == pv_register | |
412 | || a->kind == pv_constant)) | |
413 | { | |
414 | diff->kind = a->kind; | |
415 | diff->reg = a->reg; /* not always meaningful, but harmless */ | |
416 | diff->k = a->k - b->k; | |
417 | } | |
418 | ||
419 | /* We can subtract a register from itself, yielding a constant. */ | |
420 | else if (a->kind == pv_register | |
421 | && b->kind == pv_register | |
422 | && a->reg == b->reg) | |
423 | { | |
424 | diff->kind = pv_constant; | |
425 | diff->k = a->k - b->k; | |
426 | } | |
427 | ||
428 | /* We don't know how to subtract anything else. */ | |
429 | else | |
430 | diff->kind = pv_unknown; | |
431 | } | |
432 | ||
433 | ||
434 | /* Set AND to the logical and of A and B. */ | |
435 | static void | |
436 | pv_logical_and (struct prologue_value *and, | |
437 | struct prologue_value *a, | |
438 | struct prologue_value *b) | |
439 | { | |
440 | pv_constant_last (&a, &b); | |
441 | ||
442 | /* We can 'and' two constants. */ | |
443 | if (a->kind == pv_constant | |
444 | && b->kind == pv_constant) | |
445 | { | |
446 | and->kind = pv_constant; | |
447 | and->k = a->k & b->k; | |
448 | } | |
449 | ||
450 | /* We can 'and' anything with the constant zero. */ | |
451 | else if (b->kind == pv_constant | |
452 | && b->k == 0) | |
453 | { | |
454 | and->kind = pv_constant; | |
455 | and->k = 0; | |
456 | } | |
457 | ||
458 | /* We can 'and' anything with ~0. */ | |
459 | else if (b->kind == pv_constant | |
460 | && b->k == ~ (CORE_ADDR) 0) | |
461 | *and = *a; | |
462 | ||
463 | /* We can 'and' a register with itself. */ | |
464 | else if (a->kind == pv_register | |
465 | && b->kind == pv_register | |
466 | && a->reg == b->reg | |
467 | && a->k == b->k) | |
468 | *and = *a; | |
469 | ||
470 | /* Otherwise, we don't know. */ | |
471 | else | |
472 | pv_set_to_unknown (and); | |
473 | } | |
474 | ||
475 | ||
476 | /* Return non-zero iff A and B are identical expressions. | |
477 | ||
478 | This is not the same as asking if the two values are equal; the | |
479 | result of such a comparison would have to be a pv_boolean, and | |
480 | asking whether two 'unknown' values were equal would give you | |
481 | pv_maybe. Same for comparing, say, { pv_register, R1, 0 } and { | |
482 | pv_register, R2, 0}. Instead, this is asking whether the two | |
483 | representations are the same. */ | |
12bffad7 | 484 | static int |
4bc8c588 JB |
485 | pv_is_identical (struct prologue_value *a, |
486 | struct prologue_value *b) | |
12bffad7 | 487 | { |
4bc8c588 JB |
488 | if (a->kind != b->kind) |
489 | return 0; | |
490 | ||
491 | switch (a->kind) | |
492 | { | |
493 | case pv_unknown: | |
494 | return 1; | |
495 | case pv_constant: | |
496 | return (a->k == b->k); | |
497 | case pv_register: | |
498 | return (a->reg == b->reg && a->k == b->k); | |
499 | default: | |
500 | gdb_assert (0); | |
501 | } | |
12bffad7 JB |
502 | } |
503 | ||
5769d3cd | 504 | |
4bc8c588 JB |
505 | /* Return non-zero if A is the original value of register number R |
506 | plus K, zero otherwise. */ | |
507 | static int | |
508 | pv_is_register (struct prologue_value *a, int r, CORE_ADDR k) | |
509 | { | |
510 | return (a->kind == pv_register | |
511 | && a->reg == r | |
512 | && a->k == k); | |
513 | } | |
5769d3cd | 514 | |
5769d3cd | 515 | |
4bc8c588 JB |
516 | /* A prologue-value-esque boolean type, including "maybe", when we |
517 | can't figure out whether something is true or not. */ | |
518 | enum pv_boolean { | |
519 | pv_maybe, | |
520 | pv_definite_yes, | |
521 | pv_definite_no, | |
522 | }; | |
523 | ||
524 | ||
525 | /* Decide whether a reference to SIZE bytes at ADDR refers exactly to | |
526 | an element of an array. The array starts at ARRAY_ADDR, and has | |
527 | ARRAY_LEN values of ELT_SIZE bytes each. If ADDR definitely does | |
528 | refer to an array element, set *I to the index of the referenced | |
529 | element in the array, and return pv_definite_yes. If it definitely | |
530 | doesn't, return pv_definite_no. If we can't tell, return pv_maybe. | |
531 | ||
532 | If the reference does touch the array, but doesn't fall exactly on | |
533 | an element boundary, or doesn't refer to the whole element, return | |
534 | pv_maybe. */ | |
535 | static enum pv_boolean | |
536 | pv_is_array_ref (struct prologue_value *addr, | |
537 | CORE_ADDR size, | |
538 | struct prologue_value *array_addr, | |
539 | CORE_ADDR array_len, | |
540 | CORE_ADDR elt_size, | |
541 | int *i) | |
542 | { | |
543 | struct prologue_value offset; | |
5769d3cd | 544 | |
4bc8c588 JB |
545 | /* Note that, since ->k is a CORE_ADDR, and CORE_ADDR is unsigned, |
546 | if addr is *before* the start of the array, then this isn't going | |
547 | to be negative... */ | |
548 | pv_subtract (&offset, addr, array_addr); | |
549 | ||
550 | if (offset.kind == pv_constant) | |
551 | { | |
552 | /* This is a rather odd test. We want to know if the SIZE bytes | |
553 | at ADDR don't overlap the array at all, so you'd expect it to | |
554 | be an || expression: "if we're completely before || we're | |
555 | completely after". But with unsigned arithmetic, things are | |
556 | different: since it's a number circle, not a number line, the | |
557 | right values for offset.k are actually one contiguous range. */ | |
558 | if (offset.k <= -size | |
559 | && offset.k >= array_len * elt_size) | |
560 | return pv_definite_no; | |
561 | else if (offset.k % elt_size != 0 | |
562 | || size != elt_size) | |
563 | return pv_maybe; | |
564 | else | |
565 | { | |
566 | *i = offset.k / elt_size; | |
567 | return pv_definite_yes; | |
568 | } | |
569 | } | |
570 | else | |
571 | return pv_maybe; | |
572 | } | |
573 | ||
574 | ||
575 | ||
576 | /* Decoding S/390 instructions. */ | |
577 | ||
578 | /* Named opcode values for the S/390 instructions we recognize. Some | |
579 | instructions have their opcode split across two fields; those are the | |
580 | op1_* and op2_* enums. */ | |
581 | enum | |
582 | { | |
583 | op1_aghi = 0xa7, op2_aghi = 0xb, | |
584 | op1_ahi = 0xa7, op2_ahi = 0xa, | |
585 | op_ar = 0x1a, | |
586 | op_basr = 0x0d, | |
587 | op1_bras = 0xa7, op2_bras = 0x5, | |
588 | op_l = 0x58, | |
589 | op_la = 0x41, | |
590 | op1_larl = 0xc0, op2_larl = 0x0, | |
591 | op_lgr = 0xb904, | |
592 | op1_lghi = 0xa7, op2_lghi = 0x9, | |
593 | op1_lhi = 0xa7, op2_lhi = 0x8, | |
594 | op_lr = 0x18, | |
595 | op_nr = 0x14, | |
596 | op_ngr = 0xb980, | |
597 | op_s = 0x5b, | |
598 | op_st = 0x50, | |
599 | op_std = 0x60, | |
600 | op1_stg = 0xe3, op2_stg = 0x24, | |
601 | op_stm = 0x90, | |
602 | op1_stmg = 0xeb, op2_stmg = 0x24, | |
603 | op_svc = 0x0a, | |
604 | }; | |
605 | ||
606 | ||
607 | /* The functions below are for recognizing and decoding S/390 | |
608 | instructions of various formats. Each of them checks whether INSN | |
609 | is an instruction of the given format, with the specified opcodes. | |
610 | If it is, it sets the remaining arguments to the values of the | |
611 | instruction's fields, and returns a non-zero value; otherwise, it | |
612 | returns zero. | |
613 | ||
614 | These functions' arguments appear in the order they appear in the | |
615 | instruction, not in the machine-language form. So, opcodes always | |
616 | come first, even though they're sometimes scattered around the | |
617 | instructions. And displacements appear before base and extension | |
618 | registers, as they do in the assembly syntax, not at the end, as | |
619 | they do in the machine language. */ | |
a78f21af | 620 | static int |
4bc8c588 JB |
621 | is_ri (bfd_byte *insn, int op1, int op2, unsigned int *r1, int *i2) |
622 | { | |
623 | if (insn[0] == op1 && (insn[1] & 0xf) == op2) | |
624 | { | |
625 | *r1 = (insn[1] >> 4) & 0xf; | |
626 | /* i2 is a 16-bit signed quantity. */ | |
627 | *i2 = (((insn[2] << 8) | insn[3]) ^ 0x8000) - 0x8000; | |
628 | return 1; | |
629 | } | |
630 | else | |
631 | return 0; | |
632 | } | |
8ac0e65a | 633 | |
5769d3cd | 634 | |
4bc8c588 JB |
635 | static int |
636 | is_ril (bfd_byte *insn, int op1, int op2, | |
637 | unsigned int *r1, int *i2) | |
638 | { | |
639 | if (insn[0] == op1 && (insn[1] & 0xf) == op2) | |
640 | { | |
641 | *r1 = (insn[1] >> 4) & 0xf; | |
642 | /* i2 is a signed quantity. If the host 'int' is 32 bits long, | |
643 | no sign extension is necessary, but we don't want to assume | |
644 | that. */ | |
645 | *i2 = (((insn[2] << 24) | |
646 | | (insn[3] << 16) | |
647 | | (insn[4] << 8) | |
648 | | (insn[5])) ^ 0x80000000) - 0x80000000; | |
649 | return 1; | |
650 | } | |
651 | else | |
652 | return 0; | |
653 | } | |
654 | ||
655 | ||
656 | static int | |
657 | is_rr (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2) | |
658 | { | |
659 | if (insn[0] == op) | |
660 | { | |
661 | *r1 = (insn[1] >> 4) & 0xf; | |
662 | *r2 = insn[1] & 0xf; | |
663 | return 1; | |
664 | } | |
665 | else | |
666 | return 0; | |
667 | } | |
668 | ||
669 | ||
670 | static int | |
671 | is_rre (bfd_byte *insn, int op, unsigned int *r1, unsigned int *r2) | |
672 | { | |
673 | if (((insn[0] << 8) | insn[1]) == op) | |
674 | { | |
675 | /* Yes, insn[3]. insn[2] is unused in RRE format. */ | |
676 | *r1 = (insn[3] >> 4) & 0xf; | |
677 | *r2 = insn[3] & 0xf; | |
678 | return 1; | |
679 | } | |
680 | else | |
681 | return 0; | |
682 | } | |
683 | ||
684 | ||
685 | static int | |
686 | is_rs (bfd_byte *insn, int op, | |
687 | unsigned int *r1, unsigned int *r3, unsigned int *d2, unsigned int *b2) | |
688 | { | |
689 | if (insn[0] == op) | |
690 | { | |
691 | *r1 = (insn[1] >> 4) & 0xf; | |
692 | *r3 = insn[1] & 0xf; | |
693 | *b2 = (insn[2] >> 4) & 0xf; | |
694 | *d2 = ((insn[2] & 0xf) << 8) | insn[3]; | |
695 | return 1; | |
696 | } | |
697 | else | |
698 | return 0; | |
699 | } | |
700 | ||
701 | ||
702 | static int | |
703 | is_rse (bfd_byte *insn, int op1, int op2, | |
704 | unsigned int *r1, unsigned int *r3, unsigned int *d2, unsigned int *b2) | |
705 | { | |
706 | if (insn[0] == op1 | |
707 | /* Yes, insn[5]. insn[4] is unused. */ | |
708 | && insn[5] == op2) | |
709 | { | |
710 | *r1 = (insn[1] >> 4) & 0xf; | |
711 | *r3 = insn[1] & 0xf; | |
712 | *b2 = (insn[2] >> 4) & 0xf; | |
713 | *d2 = ((insn[2] & 0xf) << 8) | insn[3]; | |
714 | return 1; | |
715 | } | |
716 | else | |
717 | return 0; | |
718 | } | |
719 | ||
720 | ||
721 | static int | |
722 | is_rx (bfd_byte *insn, int op, | |
723 | unsigned int *r1, unsigned int *d2, unsigned int *x2, unsigned int *b2) | |
724 | { | |
725 | if (insn[0] == op) | |
726 | { | |
727 | *r1 = (insn[1] >> 4) & 0xf; | |
728 | *x2 = insn[1] & 0xf; | |
729 | *b2 = (insn[2] >> 4) & 0xf; | |
730 | *d2 = ((insn[2] & 0xf) << 8) | insn[3]; | |
731 | return 1; | |
732 | } | |
733 | else | |
734 | return 0; | |
735 | } | |
736 | ||
737 | ||
738 | static int | |
739 | is_rxe (bfd_byte *insn, int op1, int op2, | |
740 | unsigned int *r1, unsigned int *d2, unsigned int *x2, unsigned int *b2) | |
741 | { | |
742 | if (insn[0] == op1 | |
743 | /* Yes, insn[5]. insn[4] is unused. */ | |
744 | && insn[5] == op2) | |
745 | { | |
746 | *r1 = (insn[1] >> 4) & 0xf; | |
747 | *x2 = insn[1] & 0xf; | |
748 | *b2 = (insn[2] >> 4) & 0xf; | |
749 | *d2 = ((insn[2] & 0xf) << 8) | insn[3]; | |
750 | return 1; | |
751 | } | |
752 | else | |
753 | return 0; | |
754 | } | |
755 | ||
756 | ||
757 | /* Set ADDR to the effective address for an X-style instruction, like: | |
758 | ||
759 | L R1, D2(X2, B2) | |
760 | ||
761 | Here, X2 and B2 are registers, and D2 is an unsigned 12-bit | |
762 | constant; the effective address is the sum of all three. If either | |
763 | X2 or B2 are zero, then it doesn't contribute to the sum --- this | |
764 | means that r0 can't be used as either X2 or B2. | |
765 | ||
766 | GPR is an array of general register values, indexed by GPR number, | |
767 | not GDB register number. */ | |
768 | static void | |
769 | compute_x_addr (struct prologue_value *addr, | |
770 | struct prologue_value *gpr, | |
771 | unsigned int d2, unsigned int x2, unsigned int b2) | |
772 | { | |
773 | /* We can't just add stuff directly in addr; it might alias some of | |
774 | the registers we need to read. */ | |
775 | struct prologue_value result; | |
776 | ||
777 | pv_set_to_constant (&result, d2); | |
778 | if (x2) | |
779 | pv_add (&result, &result, &gpr[x2]); | |
780 | if (b2) | |
781 | pv_add (&result, &result, &gpr[b2]); | |
782 | ||
783 | *addr = result; | |
784 | } | |
785 | ||
786 | ||
787 | /* The number of GPR and FPR spill slots in an S/390 stack frame. We | |
788 | track general-purpose registers r2 -- r15, and floating-point | |
789 | registers f0, f2, f4, and f6. */ | |
790 | #define S390_NUM_SPILL_SLOTS (14 + 4) | |
791 | ||
792 | ||
793 | /* If the SIZE bytes at ADDR are a stack slot we're actually tracking, | |
794 | return pv_definite_yes and set *STACK to point to the slot. If | |
795 | we're sure that they are not any of our stack slots, then return | |
796 | pv_definite_no. Otherwise, return pv_maybe. | |
797 | - GPR is an array indexed by GPR number giving the current values | |
798 | of the general-purpose registers. | |
799 | - SPILL is an array tracking the spill area of the caller's frame; | |
800 | SPILL[i] is the i'th spill slot. The spill slots are designated | |
801 | for r2 -- r15, and then f0, f2, f4, and f6. | |
802 | - BACK_CHAIN is the value of the back chain slot; it's only valid | |
803 | when the current frame actually has some space for a back chain | |
804 | slot --- that is, when the current value of the stack pointer | |
805 | (according to GPR) is at least S390_STACK_FRAME_OVERHEAD bytes | |
806 | less than its original value. */ | |
807 | static enum pv_boolean | |
808 | s390_on_stack (struct prologue_value *addr, | |
809 | CORE_ADDR size, | |
810 | struct prologue_value *gpr, | |
811 | struct prologue_value *spill, | |
812 | struct prologue_value *back_chain, | |
813 | struct prologue_value **stack) | |
814 | { | |
815 | struct prologue_value gpr_spill_addr; | |
816 | struct prologue_value fpr_spill_addr; | |
817 | struct prologue_value back_chain_addr; | |
818 | int i; | |
819 | enum pv_boolean b; | |
820 | ||
821 | /* Construct the addresses of the spill arrays and the back chain. */ | |
822 | pv_set_to_register (&gpr_spill_addr, S390_SP_REGNUM, 2 * S390_GPR_SIZE); | |
823 | pv_set_to_register (&fpr_spill_addr, S390_SP_REGNUM, 16 * S390_GPR_SIZE); | |
824 | back_chain_addr = gpr[S390_SP_REGNUM - S390_GP0_REGNUM]; | |
825 | ||
826 | /* We have to check for GPR and FPR references using two separate | |
827 | calls to pv_is_array_ref, since the GPR and FPR spill slots are | |
828 | different sizes. (SPILL is an array, but the thing it tracks | |
829 | isn't really an array.) */ | |
830 | ||
831 | /* Was it a reference to the GPR spill array? */ | |
832 | b = pv_is_array_ref (addr, size, &gpr_spill_addr, 14, S390_GPR_SIZE, &i); | |
833 | if (b == pv_definite_yes) | |
834 | { | |
835 | *stack = &spill[i]; | |
836 | return pv_definite_yes; | |
837 | } | |
838 | if (b == pv_maybe) | |
839 | return pv_maybe; | |
840 | ||
841 | /* Was it a reference to the FPR spill array? */ | |
842 | b = pv_is_array_ref (addr, size, &fpr_spill_addr, 4, S390_FPR_SIZE, &i); | |
843 | if (b == pv_definite_yes) | |
5769d3cd | 844 | { |
4bc8c588 JB |
845 | *stack = &spill[14 + i]; |
846 | return pv_definite_yes; | |
5769d3cd | 847 | } |
4bc8c588 JB |
848 | if (b == pv_maybe) |
849 | return pv_maybe; | |
850 | ||
851 | /* Was it a reference to the back chain? | |
852 | This isn't quite right. We ought to check whether we have | |
853 | actually allocated any new frame at all. */ | |
854 | b = pv_is_array_ref (addr, size, &back_chain_addr, 1, S390_GPR_SIZE, &i); | |
855 | if (b == pv_definite_yes) | |
5769d3cd | 856 | { |
4bc8c588 JB |
857 | *stack = back_chain; |
858 | return pv_definite_yes; | |
859 | } | |
860 | if (b == pv_maybe) | |
861 | return pv_maybe; | |
862 | ||
863 | /* All the above queries returned definite 'no's. */ | |
864 | return pv_definite_no; | |
865 | } | |
866 | ||
867 | ||
868 | /* Do a SIZE-byte store of VALUE to ADDR. GPR, SPILL, and BACK_CHAIN, | |
869 | and the return value are as described for s390_on_stack, above. | |
870 | Note that, when this returns pv_maybe, we have to assume that all | |
871 | of our memory now contains unknown values. */ | |
872 | static enum pv_boolean | |
873 | s390_store (struct prologue_value *addr, | |
874 | CORE_ADDR size, | |
875 | struct prologue_value *value, | |
876 | struct prologue_value *gpr, | |
877 | struct prologue_value *spill, | |
878 | struct prologue_value *back_chain) | |
879 | { | |
880 | struct prologue_value *stack; | |
881 | enum pv_boolean on_stack | |
882 | = s390_on_stack (addr, size, gpr, spill, back_chain, &stack); | |
883 | ||
884 | if (on_stack == pv_definite_yes) | |
885 | *stack = *value; | |
886 | ||
887 | return on_stack; | |
888 | } | |
889 | ||
890 | ||
891 | /* The current frame looks like a signal delivery frame: the first | |
892 | instruction is an 'svc' opcode. If the next frame is a signal | |
893 | handler's frame, set FI's saved register map to point into the | |
894 | signal context structure. */ | |
895 | static void | |
896 | s390_get_signal_frame_info (struct frame_info *fi) | |
897 | { | |
898 | struct frame_info *next_frame = get_next_frame (fi); | |
899 | ||
900 | if (next_frame | |
901 | && get_frame_extra_info (next_frame) | |
902 | && get_frame_extra_info (next_frame)->sigcontext) | |
903 | { | |
904 | /* We're definitely backtracing from a signal handler. */ | |
905 | CORE_ADDR *saved_regs = get_frame_saved_regs (fi); | |
906 | CORE_ADDR save_reg_addr = (get_frame_extra_info (next_frame)->sigcontext | |
907 | + REGISTER_BYTE (S390_GP0_REGNUM)); | |
908 | int reg; | |
909 | ||
910 | for (reg = 0; reg < S390_NUM_GPRS; reg++) | |
7666f43c | 911 | { |
4bc8c588 JB |
912 | saved_regs[S390_GP0_REGNUM + reg] = save_reg_addr; |
913 | save_reg_addr += S390_GPR_SIZE; | |
7666f43c JB |
914 | } |
915 | ||
4bc8c588 JB |
916 | save_reg_addr = (get_frame_extra_info (next_frame)->sigcontext |
917 | + (GDB_TARGET_IS_ESAME ? S390X_SIGREGS_FP0_OFFSET : | |
918 | S390_SIGREGS_FP0_OFFSET)); | |
919 | for (reg = 0; reg < S390_NUM_FPRS; reg++) | |
920 | { | |
921 | saved_regs[S390_FP0_REGNUM + reg] = save_reg_addr; | |
922 | save_reg_addr += S390_FPR_SIZE; | |
923 | } | |
5769d3cd | 924 | } |
4bc8c588 JB |
925 | } |
926 | ||
927 | ||
928 | static int | |
929 | s390_get_frame_info (CORE_ADDR start_pc, | |
930 | struct frame_extra_info *fextra_info, | |
931 | struct frame_info *fi, | |
932 | int init_extra_info) | |
933 | { | |
934 | /* Our return value: | |
935 | zero if we were able to read all the instructions we wanted, or | |
936 | -1 if we got an error trying to read memory. */ | |
937 | int result = 0; | |
938 | ||
939 | /* We just use this for reading instructions. */ | |
940 | disassemble_info info; | |
941 | ||
942 | /* The current PC for our abstract interpretation. */ | |
943 | CORE_ADDR pc; | |
944 | ||
945 | /* The address of the next instruction after that. */ | |
946 | CORE_ADDR next_pc; | |
947 | ||
948 | /* The general-purpose registers. */ | |
949 | struct prologue_value gpr[S390_NUM_GPRS]; | |
950 | ||
951 | /* The floating-point registers. */ | |
952 | struct prologue_value fpr[S390_NUM_FPRS]; | |
953 | ||
954 | /* The register spill stack slots in the caller's frame --- | |
955 | general-purpose registers r2 through r15, and floating-point | |
956 | registers. spill[i] is where gpr i+2 gets spilled; | |
957 | spill[(14, 15, 16, 17)] is where (f0, f2, f4, f6) get spilled. */ | |
958 | struct prologue_value spill[S390_NUM_SPILL_SLOTS]; | |
959 | ||
960 | /* The value of the back chain slot. This is only valid if the stack | |
961 | pointer is known to be less than its original value --- that is, | |
962 | if we have indeed allocated space on the stack. */ | |
963 | struct prologue_value back_chain; | |
964 | ||
965 | /* The address of the instruction after the last one that changed | |
966 | the SP, FP, or back chain. */ | |
967 | CORE_ADDR after_last_frame_setup_insn = start_pc; | |
968 | ||
969 | info.read_memory_func = deprecated_tm_print_insn_info.read_memory_func; | |
970 | ||
971 | /* Set up everything's initial value. */ | |
972 | { | |
973 | int i; | |
974 | ||
975 | for (i = 0; i < S390_NUM_GPRS; i++) | |
976 | pv_set_to_register (&gpr[i], S390_GP0_REGNUM + i, 0); | |
977 | ||
978 | for (i = 0; i < S390_NUM_FPRS; i++) | |
979 | pv_set_to_register (&fpr[i], S390_FP0_REGNUM + i, 0); | |
980 | ||
981 | for (i = 0; i < S390_NUM_SPILL_SLOTS; i++) | |
982 | pv_set_to_unknown (&spill[i]); | |
983 | ||
984 | pv_set_to_unknown (&back_chain); | |
985 | } | |
986 | ||
987 | /* Start interpreting instructions, until we hit something we don't | |
988 | know how to interpret. (Ideally, we should stop at the frame's | |
989 | real current PC, but at the moment, our callers don't give us | |
990 | that info.) */ | |
991 | for (pc = start_pc; ; pc = next_pc) | |
5769d3cd | 992 | { |
4bc8c588 JB |
993 | bfd_byte insn[S390_MAX_INSTR_SIZE]; |
994 | int insn_len = s390_readinstruction (insn, pc, &info); | |
995 | ||
996 | /* Fields for various kinds of instructions. */ | |
997 | unsigned int b2, r1, r2, d2, x2, r3; | |
998 | int i2; | |
999 | ||
1000 | /* The values of SP, FP, and back chain before this instruction, | |
1001 | for detecting instructions that change them. */ | |
1002 | struct prologue_value pre_insn_sp, pre_insn_fp, pre_insn_back_chain; | |
1003 | ||
1004 | /* If we got an error trying to read the instruction, report it. */ | |
1005 | if (insn_len < 0) | |
8ac0e65a | 1006 | { |
4bc8c588 JB |
1007 | result = -1; |
1008 | break; | |
1009 | } | |
1010 | ||
1011 | next_pc = pc + insn_len; | |
1012 | ||
1013 | pre_insn_sp = gpr[S390_SP_REGNUM - S390_GP0_REGNUM]; | |
1014 | pre_insn_fp = gpr[S390_FRAME_REGNUM - S390_GP0_REGNUM]; | |
1015 | pre_insn_back_chain = back_chain; | |
1016 | ||
1017 | /* A special case, first --- only recognized as the very first | |
1018 | instruction of the function, for signal delivery frames: | |
1019 | SVC i --- system call */ | |
1020 | if (pc == start_pc | |
1021 | && is_rr (insn, op_svc, &r1, &r2)) | |
1022 | { | |
1023 | if (fi) | |
1024 | s390_get_signal_frame_info (fi); | |
1025 | break; | |
8ac0e65a JB |
1026 | } |
1027 | ||
4bc8c588 JB |
1028 | /* AHI r1, i2 --- add halfword immediate */ |
1029 | else if (is_ri (insn, op1_ahi, op2_ahi, &r1, &i2)) | |
1030 | pv_add_constant (&gpr[r1], i2); | |
1031 | ||
1032 | ||
1033 | /* AGHI r1, i2 --- add halfword immediate (64-bit version) */ | |
1034 | else if (GDB_TARGET_IS_ESAME | |
1035 | && is_ri (insn, op1_aghi, op2_aghi, &r1, &i2)) | |
1036 | pv_add_constant (&gpr[r1], i2); | |
1037 | ||
1038 | /* AR r1, r2 -- add register */ | |
1039 | else if (is_rr (insn, op_ar, &r1, &r2)) | |
1040 | pv_add (&gpr[r1], &gpr[r1], &gpr[r2]); | |
1041 | ||
1042 | /* BASR r1, 0 --- branch and save | |
1043 | Since r2 is zero, this saves the PC in r1, but doesn't branch. */ | |
1044 | else if (is_rr (insn, op_basr, &r1, &r2) | |
1045 | && r2 == 0) | |
1046 | pv_set_to_constant (&gpr[r1], next_pc); | |
1047 | ||
1048 | /* BRAS r1, i2 --- branch relative and save */ | |
1049 | else if (is_ri (insn, op1_bras, op2_bras, &r1, &i2)) | |
1050 | { | |
1051 | pv_set_to_constant (&gpr[r1], next_pc); | |
1052 | next_pc = pc + i2 * 2; | |
1053 | ||
1054 | /* We'd better not interpret any backward branches. We'll | |
1055 | never terminate. */ | |
1056 | if (next_pc <= pc) | |
1057 | break; | |
1058 | } | |
1059 | ||
1060 | /* L r1, d2(x2, b2) --- load */ | |
1061 | else if (is_rx (insn, op_l, &r1, &d2, &x2, &b2)) | |
1062 | { | |
1063 | struct prologue_value addr; | |
1064 | struct prologue_value *stack; | |
1065 | ||
1066 | compute_x_addr (&addr, gpr, d2, x2, b2); | |
1067 | ||
1068 | /* If it's a load from an in-line constant pool, then we can | |
1069 | simulate that, under the assumption that the code isn't | |
1070 | going to change between the time the processor actually | |
1071 | executed it creating the current frame, and the time when | |
1072 | we're analyzing the code to unwind past that frame. */ | |
1073 | if (addr.kind == pv_constant | |
1074 | && start_pc <= addr.k | |
1075 | && addr.k < next_pc) | |
1076 | pv_set_to_constant (&gpr[r1], | |
1077 | read_memory_integer (addr.k, 4)); | |
1078 | ||
1079 | /* If it's definitely a reference to something on the stack, | |
1080 | we can do that. */ | |
1081 | else if (s390_on_stack (&addr, 4, gpr, spill, &back_chain, &stack) | |
1082 | == pv_definite_yes) | |
1083 | gpr[r1] = *stack; | |
1084 | ||
1085 | /* Otherwise, we don't know the value. */ | |
1086 | else | |
1087 | pv_set_to_unknown (&gpr[r1]); | |
1088 | } | |
1089 | ||
1090 | /* LA r1, d2(x2, b2) --- load address */ | |
1091 | else if (is_rx (insn, op_la, &r1, &d2, &x2, &b2)) | |
1092 | compute_x_addr (&gpr[r1], gpr, d2, x2, b2); | |
1093 | ||
1094 | /* LARL r1, i2 --- load address relative long */ | |
1095 | else if (GDB_TARGET_IS_ESAME | |
1096 | && is_ril (insn, op1_larl, op2_larl, &r1, &i2)) | |
1097 | pv_set_to_constant (&gpr[r1], pc + i2 * 2); | |
1098 | ||
1099 | /* LGR r1, r2 --- load from register */ | |
1100 | else if (GDB_TARGET_IS_ESAME | |
1101 | && is_rre (insn, op_lgr, &r1, &r2)) | |
1102 | gpr[r1] = gpr[r2]; | |
1103 | ||
1104 | /* LHI r1, i2 --- load halfword immediate */ | |
1105 | else if (is_ri (insn, op1_lhi, op2_lhi, &r1, &i2)) | |
1106 | pv_set_to_constant (&gpr[r1], i2); | |
1107 | ||
1108 | /* LGHI r1, i2 --- load halfword immediate --- 64-bit version */ | |
1109 | else if (is_ri (insn, op1_lghi, op2_lghi, &r1, &i2)) | |
1110 | pv_set_to_constant (&gpr[r1], i2); | |
1111 | ||
1112 | /* LR r1, r2 --- load from register */ | |
1113 | else if (is_rr (insn, op_lr, &r1, &r2)) | |
1114 | gpr[r1] = gpr[r2]; | |
1115 | ||
1116 | /* NGR r1, r2 --- logical and --- 64-bit version */ | |
1117 | else if (GDB_TARGET_IS_ESAME | |
1118 | && is_rre (insn, op_ngr, &r1, &r2)) | |
1119 | pv_logical_and (&gpr[r1], &gpr[r1], &gpr[r2]); | |
1120 | ||
1121 | /* NR r1, r2 --- logical and */ | |
1122 | else if (is_rr (insn, op_nr, &r1, &r2)) | |
1123 | pv_logical_and (&gpr[r1], &gpr[r1], &gpr[r2]); | |
1124 | ||
1125 | /* NGR r1, r2 --- logical and --- 64-bit version */ | |
1126 | else if (GDB_TARGET_IS_ESAME | |
1127 | && is_rre (insn, op_ngr, &r1, &r2)) | |
1128 | pv_logical_and (&gpr[r1], &gpr[r1], &gpr[r2]); | |
1129 | ||
1130 | /* NR r1, r2 --- logical and */ | |
1131 | else if (is_rr (insn, op_nr, &r1, &r2)) | |
1132 | pv_logical_and (&gpr[r1], &gpr[r1], &gpr[r2]); | |
1133 | ||
1134 | /* S r1, d2(x2, b2) --- subtract from memory */ | |
1135 | else if (is_rx (insn, op_s, &r1, &d2, &x2, &b2)) | |
1136 | { | |
1137 | struct prologue_value addr; | |
1138 | struct prologue_value value; | |
1139 | struct prologue_value *stack; | |
1140 | ||
1141 | compute_x_addr (&addr, gpr, d2, x2, b2); | |
1142 | ||
1143 | /* If it's a load from an in-line constant pool, then we can | |
1144 | simulate that, under the assumption that the code isn't | |
1145 | going to change between the time the processor actually | |
1146 | executed it and the time when we're analyzing it. */ | |
1147 | if (addr.kind == pv_constant | |
1148 | && start_pc <= addr.k | |
1149 | && addr.k < pc) | |
1150 | pv_set_to_constant (&value, read_memory_integer (addr.k, 4)); | |
1151 | ||
1152 | /* If it's definitely a reference to something on the stack, | |
1153 | we could do that. */ | |
1154 | else if (s390_on_stack (&addr, 4, gpr, spill, &back_chain, &stack) | |
1155 | == pv_definite_yes) | |
1156 | value = *stack; | |
1157 | ||
1158 | /* Otherwise, we don't know the value. */ | |
1159 | else | |
1160 | pv_set_to_unknown (&value); | |
1161 | ||
1162 | pv_subtract (&gpr[r1], &gpr[r1], &value); | |
1163 | } | |
1164 | ||
1165 | /* ST r1, d2(x2, b2) --- store */ | |
1166 | else if (is_rx (insn, op_st, &r1, &d2, &x2, &b2)) | |
1167 | { | |
1168 | struct prologue_value addr; | |
1169 | ||
1170 | compute_x_addr (&addr, gpr, d2, x2, b2); | |
1171 | ||
1172 | /* The below really should be '4', not 'S390_GPR_SIZE'; this | |
1173 | instruction always stores 32 bits, regardless of the full | |
1174 | size of the GPR. */ | |
1175 | if (s390_store (&addr, 4, &gpr[r1], gpr, spill, &back_chain) | |
1176 | == pv_maybe) | |
1177 | /* If we can't be sure that it's *not* a store to | |
1178 | something we're tracing, then we would have to mark all | |
1179 | our memory as unknown --- after all, it *could* be a | |
1180 | store to any of them --- so we might as well just stop | |
1181 | interpreting. */ | |
1182 | break; | |
1183 | } | |
1184 | ||
1185 | /* STD r1, d2(x2,b2) --- store floating-point register */ | |
1186 | else if (is_rx (insn, op_std, &r1, &d2, &x2, &b2)) | |
1187 | { | |
1188 | struct prologue_value addr; | |
1189 | ||
1190 | compute_x_addr (&addr, gpr, d2, x2, b2); | |
1191 | ||
1192 | if (s390_store (&addr, 8, &fpr[r1], gpr, spill, &back_chain) | |
1193 | == pv_maybe) | |
1194 | /* If we can't be sure that it's *not* a store to | |
1195 | something we're tracing, then we would have to mark all | |
1196 | our memory as unknown --- after all, it *could* be a | |
1197 | store to any of them --- so we might as well just stop | |
1198 | interpreting. */ | |
1199 | break; | |
1200 | } | |
1201 | ||
1202 | /* STG r1, d2(x2, b2) --- 64-bit store */ | |
1203 | else if (GDB_TARGET_IS_ESAME | |
1204 | && is_rxe (insn, op1_stg, op2_stg, &r1, &d2, &x2, &b2)) | |
1205 | { | |
1206 | struct prologue_value addr; | |
1207 | ||
1208 | compute_x_addr (&addr, gpr, d2, x2, b2); | |
1209 | ||
1210 | /* The below really should be '8', not 'S390_GPR_SIZE'; this | |
1211 | instruction always stores 64 bits, regardless of the full | |
1212 | size of the GPR. */ | |
1213 | if (s390_store (&addr, 8, &gpr[r1], gpr, spill, &back_chain) | |
1214 | == pv_maybe) | |
1215 | /* If we can't be sure that it's *not* a store to | |
1216 | something we're tracing, then we would have to mark all | |
1217 | our memory as unknown --- after all, it *could* be a | |
1218 | store to any of them --- so we might as well just stop | |
1219 | interpreting. */ | |
1220 | break; | |
1221 | } | |
1222 | ||
1223 | /* STM r1, r3, d2(b2) --- store multiple */ | |
1224 | else if (is_rs (insn, op_stm, &r1, &r3, &d2, &b2)) | |
1225 | { | |
1226 | int regnum; | |
1227 | int offset; | |
1228 | struct prologue_value addr; | |
1229 | ||
1230 | for (regnum = r1, offset = 0; | |
1231 | regnum <= r3; | |
1232 | regnum++, offset += 4) | |
1233 | { | |
1234 | compute_x_addr (&addr, gpr, d2 + offset, 0, b2); | |
1235 | ||
1236 | if (s390_store (&addr, 4, &gpr[regnum], gpr, spill, &back_chain) | |
1237 | == pv_maybe) | |
1238 | /* If we can't be sure that it's *not* a store to | |
1239 | something we're tracing, then we would have to mark all | |
1240 | our memory as unknown --- after all, it *could* be a | |
1241 | store to any of them --- so we might as well just stop | |
1242 | interpreting. */ | |
1243 | break; | |
1244 | } | |
1245 | ||
1246 | /* If we left the loop early, we should stop interpreting | |
1247 | altogether. */ | |
1248 | if (regnum <= r3) | |
1249 | break; | |
1250 | } | |
1251 | ||
1252 | /* STMG r1, r3, d2(b2) --- store multiple, 64-bit */ | |
1253 | else if (GDB_TARGET_IS_ESAME | |
1254 | && is_rse (insn, op1_stmg, op2_stmg, &r1, &r3, &d2, &b2)) | |
1255 | { | |
1256 | int regnum; | |
1257 | int offset; | |
1258 | struct prologue_value addr; | |
1259 | ||
1260 | for (regnum = r1, offset = 0; | |
1261 | regnum <= r3; | |
1262 | regnum++, offset += 8) | |
1263 | { | |
1264 | compute_x_addr (&addr, gpr, d2 + offset, 0, b2); | |
1265 | ||
1266 | if (s390_store (&addr, 8, &gpr[regnum], gpr, spill, &back_chain) | |
1267 | == pv_maybe) | |
1268 | /* If we can't be sure that it's *not* a store to | |
1269 | something we're tracing, then we would have to mark all | |
1270 | our memory as unknown --- after all, it *could* be a | |
1271 | store to any of them --- so we might as well just stop | |
1272 | interpreting. */ | |
1273 | break; | |
1274 | } | |
1275 | ||
1276 | /* If we left the loop early, we should stop interpreting | |
1277 | altogether. */ | |
1278 | if (regnum <= r3) | |
1279 | break; | |
1280 | } | |
1281 | ||
1282 | else | |
1283 | /* An instruction we don't know how to simulate. The only | |
1284 | safe thing to do would be to set every value we're tracking | |
1285 | to 'unknown'. Instead, we'll be optimistic: we just stop | |
1286 | interpreting, and assume that the machine state we've got | |
1287 | now is good enough for unwinding the stack. */ | |
1288 | break; | |
1289 | ||
1290 | /* Record the address after the last instruction that changed | |
1291 | the FP, SP, or backlink. Ignore instructions that changed | |
1292 | them back to their original values --- those are probably | |
1293 | restore instructions. (The back chain is never restored, | |
1294 | just popped.) */ | |
1295 | { | |
1296 | struct prologue_value *sp = &gpr[S390_SP_REGNUM - S390_GP0_REGNUM]; | |
1297 | struct prologue_value *fp = &gpr[S390_FRAME_REGNUM - S390_GP0_REGNUM]; | |
1298 | ||
1299 | if ((! pv_is_identical (&pre_insn_sp, sp) | |
1300 | && ! pv_is_register (sp, S390_SP_REGNUM, 0)) | |
1301 | || (! pv_is_identical (&pre_insn_fp, fp) | |
1302 | && ! pv_is_register (fp, S390_FRAME_REGNUM, 0)) | |
1303 | || ! pv_is_identical (&pre_insn_back_chain, &back_chain)) | |
1304 | after_last_frame_setup_insn = next_pc; | |
1305 | } | |
5769d3cd | 1306 | } |
4bc8c588 JB |
1307 | |
1308 | /* Okay, now gpr[], fpr[], spill[], and back_chain reflect the state | |
1309 | of the machine as of the first instruction we couldn't interpret | |
1310 | (hopefully the first non-prologue instruction). */ | |
1311 | { | |
1312 | /* The size of the frame, or (CORE_ADDR) -1 if we couldn't figure | |
1313 | that out. */ | |
1314 | CORE_ADDR frame_size = -1; | |
1315 | ||
1316 | /* The value the SP had upon entry to the function, or | |
1317 | (CORE_ADDR) -1 if we can't figure that out. */ | |
1318 | CORE_ADDR original_sp = -1; | |
1319 | ||
1320 | /* Are we using S390_FRAME_REGNUM as a frame pointer register? */ | |
1321 | int using_frame_pointer = 0; | |
1322 | ||
1323 | /* If S390_FRAME_REGNUM is some constant offset from the SP, then | |
1324 | that strongly suggests that we're going to use that as our | |
1325 | frame pointer register, not the SP. */ | |
5769d3cd | 1326 | { |
4bc8c588 JB |
1327 | struct prologue_value *fp = &gpr[S390_FRAME_REGNUM - S390_GP0_REGNUM]; |
1328 | ||
1329 | if (fp->kind == pv_register | |
1330 | && fp->reg == S390_SP_REGNUM) | |
1331 | using_frame_pointer = 1; | |
5769d3cd | 1332 | } |
4bc8c588 JB |
1333 | |
1334 | /* If we were given a frame_info structure, we may be able to use | |
1335 | the frame's base address to figure out the actual value of the | |
1336 | original SP. */ | |
1337 | if (fi && get_frame_base (fi)) | |
1338 | { | |
1339 | int frame_base_regno; | |
1340 | struct prologue_value *frame_base; | |
1341 | ||
1342 | /* The meaning of the frame base depends on whether the | |
1343 | function uses a frame pointer register other than the SP or | |
1344 | not (see s390_read_fp): | |
1345 | - If the function does use a frame pointer register other | |
1346 | than the SP, then the frame base is that register's | |
1347 | value. | |
1348 | - If the function doesn't use a frame pointer, then the | |
1349 | frame base is the SP itself. | |
1350 | We're duplicating some of the logic of s390_fp_regnum here, | |
1351 | but we don't want to call that, because it would just do | |
1352 | exactly the same analysis we've already done above. */ | |
1353 | if (using_frame_pointer) | |
1354 | frame_base_regno = S390_FRAME_REGNUM; | |
1355 | else | |
1356 | frame_base_regno = S390_SP_REGNUM; | |
1357 | ||
1358 | frame_base = &gpr[frame_base_regno - S390_GP0_REGNUM]; | |
1359 | ||
1360 | /* We know the frame base address; if the value of whatever | |
1361 | register it came from is a constant offset from the | |
1362 | original SP, then we can reconstruct the original SP just | |
1363 | by subtracting off that constant. */ | |
1364 | if (frame_base->kind == pv_register | |
1365 | && frame_base->reg == S390_SP_REGNUM) | |
1366 | original_sp = get_frame_base (fi) - frame_base->k; | |
1367 | } | |
1368 | ||
1369 | /* If the analysis said that the current SP value is the original | |
1370 | value less some constant, then that constant is the frame size. */ | |
1371 | { | |
1372 | struct prologue_value *sp = &gpr[S390_SP_REGNUM - S390_GP0_REGNUM]; | |
1373 | ||
1374 | if (sp->kind == pv_register | |
1375 | && sp->reg == S390_SP_REGNUM) | |
1376 | frame_size = -sp->k; | |
1377 | } | |
1378 | ||
1379 | /* If we knew other registers' current values, we could check if | |
1380 | the analysis said any of those were related to the original SP | |
1381 | value, too. But for now, we'll just punt. */ | |
1382 | ||
1383 | /* If the caller passed in an 'extra info' structure, fill in the | |
1384 | parts we can. */ | |
1385 | if (fextra_info) | |
1386 | { | |
1387 | if (init_extra_info || ! fextra_info->initialised) | |
1388 | { | |
1389 | s390_memset_extra_info (fextra_info); | |
1390 | fextra_info->function_start = start_pc; | |
1391 | fextra_info->initialised = 1; | |
1392 | } | |
1393 | ||
1394 | if (frame_size != -1) | |
1395 | { | |
a9dd42f1 | 1396 | fextra_info->stack_bought_valid = 1; |
4bc8c588 JB |
1397 | fextra_info->stack_bought = frame_size; |
1398 | } | |
1399 | ||
1400 | /* Assume everything was okay, and indicate otherwise when we | |
1401 | find something amiss. */ | |
1402 | fextra_info->good_prologue = 1; | |
1403 | ||
1404 | if (using_frame_pointer) | |
1405 | /* Actually, nobody cares about the exact PC, so any | |
1406 | non-zero value will do here. */ | |
1407 | fextra_info->frame_pointer_saved_pc = 1; | |
1408 | ||
1409 | /* If we weren't able to find the size of the frame, or find | |
1410 | the original sp based on actual current register values, | |
1411 | then we're not going to be able to unwind this frame. | |
1412 | ||
1413 | (If we're just doing prologue analysis to set a breakpoint, | |
1414 | then frame_size might be known, but original_sp unknown; if | |
1415 | we're analyzing a real frame which uses alloca, then | |
1416 | original_sp might be known (from the frame pointer | |
1417 | register), but the frame size might be unknown.) */ | |
1418 | if (original_sp == -1 && frame_size == -1) | |
1419 | fextra_info->good_prologue = 0; | |
1420 | ||
1421 | if (fextra_info->good_prologue) | |
1422 | fextra_info->skip_prologue_function_start | |
1423 | = after_last_frame_setup_insn; | |
1424 | else | |
1425 | /* If the prologue was too complex for us to make sense of, | |
1426 | then perhaps it's better to just not skip anything at | |
1427 | all. */ | |
1428 | fextra_info->skip_prologue_function_start = start_pc; | |
1429 | } | |
1430 | ||
1431 | /* Indicate where registers were saved on the stack, if: | |
1432 | - the caller seems to want to know, | |
1433 | - the caller provided an actual SP, and | |
1434 | - the analysis gave us enough information to actually figure it | |
1435 | out. */ | |
1436 | if (fi | |
1437 | && get_frame_saved_regs (fi) | |
1438 | && original_sp != -1) | |
1439 | { | |
1440 | int slot_num; | |
1441 | CORE_ADDR slot_addr; | |
1442 | CORE_ADDR *saved_regs = get_frame_saved_regs (fi); | |
1443 | ||
1444 | /* Scan the spill array; if a spill slot says it holds the | |
1445 | original value of some register, then record that slot's | |
1446 | address as the place that register was saved. | |
1447 | ||
1448 | Just for kicks, note that, even if registers aren't saved | |
1449 | in their officially-sanctioned slots, this will still work | |
1450 | --- we know what really got put where. */ | |
1451 | ||
1452 | /* First, the slots for r2 -- r15. */ | |
1453 | for (slot_num = 0, slot_addr = original_sp + 2 * S390_GPR_SIZE; | |
1454 | slot_num < 14; | |
1455 | slot_num++, slot_addr += S390_GPR_SIZE) | |
1456 | { | |
1457 | struct prologue_value *slot = &spill[slot_num]; | |
1458 | ||
1459 | if (slot->kind == pv_register | |
1460 | && slot->k == 0) | |
1461 | saved_regs[slot->reg] = slot_addr; | |
1462 | } | |
1463 | ||
1464 | /* Then, the slots for f0, f2, f4, and f6. They're a | |
1465 | different size. */ | |
1466 | for (slot_num = 14, slot_addr = original_sp + 16 * S390_GPR_SIZE; | |
1467 | slot_num < S390_NUM_SPILL_SLOTS; | |
1468 | slot_num++, slot_addr += S390_FPR_SIZE) | |
1469 | { | |
1470 | struct prologue_value *slot = &spill[slot_num]; | |
1471 | ||
1472 | if (slot->kind == pv_register | |
1473 | && slot->k == 0) | |
1474 | saved_regs[slot->reg] = slot_addr; | |
1475 | } | |
1476 | ||
1477 | /* The stack pointer's element of saved_regs[] is special. */ | |
1478 | saved_regs[S390_SP_REGNUM] = original_sp; | |
1479 | } | |
1480 | } | |
1481 | ||
1482 | return result; | |
5769d3cd AC |
1483 | } |
1484 | ||
1485 | ||
a78f21af | 1486 | static int |
5769d3cd AC |
1487 | s390_check_function_end (CORE_ADDR pc) |
1488 | { | |
1489 | bfd_byte instr[S390_MAX_INSTR_SIZE]; | |
1490 | disassemble_info info; | |
1491 | int regidx, instrlen; | |
1492 | ||
810ecf9f | 1493 | info.read_memory_func = deprecated_tm_print_insn_info.read_memory_func; |
5769d3cd AC |
1494 | instrlen = s390_readinstruction (instr, pc, &info); |
1495 | if (instrlen < 0) | |
1496 | return -1; | |
1497 | /* check for BR */ | |
1498 | if (instrlen != 2 || instr[0] != 07 || (instr[1] >> 4) != 0xf) | |
1499 | return 0; | |
1500 | regidx = instr[1] & 0xf; | |
1501 | /* Check for LMG or LG */ | |
1502 | instrlen = | |
1503 | s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 6 : 4), &info); | |
1504 | if (instrlen < 0) | |
1505 | return -1; | |
1506 | if (GDB_TARGET_IS_ESAME) | |
1507 | { | |
1508 | ||
1509 | if (instrlen != 6 || instr[0] != 0xeb || instr[5] != 0x4) | |
1510 | return 0; | |
1511 | } | |
1512 | else if (instrlen != 4 || instr[0] != 0x98) | |
1513 | { | |
1514 | return 0; | |
1515 | } | |
1516 | if ((instr[2] >> 4) != 0xf) | |
1517 | return 0; | |
1518 | if (regidx == 14) | |
1519 | return 1; | |
1520 | instrlen = s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 12 : 8), | |
1521 | &info); | |
1522 | if (instrlen < 0) | |
1523 | return -1; | |
1524 | if (GDB_TARGET_IS_ESAME) | |
1525 | { | |
1526 | /* Check for LG */ | |
1527 | if (instrlen != 6 || instr[0] != 0xe3 || instr[5] != 0x4) | |
1528 | return 0; | |
1529 | } | |
1530 | else | |
1531 | { | |
1532 | /* Check for L */ | |
1533 | if (instrlen != 4 || instr[0] != 0x58) | |
1534 | return 0; | |
1535 | } | |
1536 | if (instr[2] >> 4 != 0xf) | |
1537 | return 0; | |
1538 | if (instr[1] >> 4 != regidx) | |
1539 | return 0; | |
1540 | return 1; | |
1541 | } | |
1542 | ||
1543 | static CORE_ADDR | |
1544 | s390_sniff_pc_function_start (CORE_ADDR pc, struct frame_info *fi) | |
1545 | { | |
1546 | CORE_ADDR function_start, test_function_start; | |
1547 | int loop_cnt, err, function_end; | |
1548 | struct frame_extra_info fextra_info; | |
1549 | function_start = get_pc_function_start (pc); | |
1550 | ||
1551 | if (function_start == 0) | |
1552 | { | |
1553 | test_function_start = pc; | |
1554 | if (test_function_start & 1) | |
1555 | return 0; /* This has to be bogus */ | |
1556 | loop_cnt = 0; | |
1557 | do | |
1558 | { | |
1559 | ||
1560 | err = | |
1561 | s390_get_frame_info (test_function_start, &fextra_info, fi, 1); | |
1562 | loop_cnt++; | |
1563 | test_function_start -= 2; | |
1564 | function_end = s390_check_function_end (test_function_start); | |
1565 | } | |
1566 | while (!(function_end == 1 || err || loop_cnt >= 4096 || | |
1567 | (fextra_info.good_prologue))); | |
1568 | if (fextra_info.good_prologue) | |
1569 | function_start = fextra_info.function_start; | |
1570 | else if (function_end == 1) | |
1571 | function_start = test_function_start; | |
1572 | } | |
1573 | return function_start; | |
1574 | } | |
1575 | ||
1576 | ||
1577 | ||
a78f21af | 1578 | static CORE_ADDR |
5769d3cd AC |
1579 | s390_function_start (struct frame_info *fi) |
1580 | { | |
1581 | CORE_ADDR function_start = 0; | |
1582 | ||
da50a4b7 AC |
1583 | if (get_frame_extra_info (fi) && get_frame_extra_info (fi)->initialised) |
1584 | function_start = get_frame_extra_info (fi)->function_start; | |
50abf9e5 | 1585 | else if (get_frame_pc (fi)) |
be41e9f4 | 1586 | function_start = get_frame_func (fi); |
5769d3cd AC |
1587 | return function_start; |
1588 | } | |
1589 | ||
1590 | ||
1591 | ||
1592 | ||
a78f21af | 1593 | static int |
5769d3cd AC |
1594 | s390_frameless_function_invocation (struct frame_info *fi) |
1595 | { | |
1596 | struct frame_extra_info fextra_info, *fextra_info_ptr; | |
1597 | int frameless = 0; | |
1598 | ||
11c02a10 | 1599 | if (get_next_frame (fi) == NULL) /* no may be frameless */ |
5769d3cd | 1600 | { |
da50a4b7 AC |
1601 | if (get_frame_extra_info (fi)) |
1602 | fextra_info_ptr = get_frame_extra_info (fi); | |
5769d3cd AC |
1603 | else |
1604 | { | |
1605 | fextra_info_ptr = &fextra_info; | |
50abf9e5 | 1606 | s390_get_frame_info (s390_sniff_pc_function_start (get_frame_pc (fi), fi), |
5769d3cd AC |
1607 | fextra_info_ptr, fi, 1); |
1608 | } | |
a9dd42f1 JB |
1609 | frameless = (fextra_info_ptr->stack_bought_valid |
1610 | && fextra_info_ptr->stack_bought == 0); | |
5769d3cd AC |
1611 | } |
1612 | return frameless; | |
1613 | ||
1614 | } | |
1615 | ||
1616 | ||
1617 | static int | |
1618 | s390_is_sigreturn (CORE_ADDR pc, struct frame_info *sighandler_fi, | |
1619 | CORE_ADDR *sregs, CORE_ADDR *sigcaller_pc) | |
1620 | { | |
1621 | bfd_byte instr[S390_MAX_INSTR_SIZE]; | |
1622 | disassemble_info info; | |
1623 | int instrlen; | |
1624 | CORE_ADDR scontext; | |
1625 | int retval = 0; | |
1626 | CORE_ADDR orig_sp; | |
1627 | CORE_ADDR temp_sregs; | |
1628 | ||
1629 | scontext = temp_sregs = 0; | |
1630 | ||
810ecf9f | 1631 | info.read_memory_func = deprecated_tm_print_insn_info.read_memory_func; |
5769d3cd AC |
1632 | instrlen = s390_readinstruction (instr, pc, &info); |
1633 | if (sigcaller_pc) | |
1634 | *sigcaller_pc = 0; | |
1635 | if (((instrlen == S390_SYSCALL_SIZE) && | |
1636 | (instr[0] == S390_SYSCALL_OPCODE)) && | |
1637 | ((instr[1] == s390_NR_sigreturn) || (instr[1] == s390_NR_rt_sigreturn))) | |
1638 | { | |
1639 | if (sighandler_fi) | |
1640 | { | |
1641 | if (s390_frameless_function_invocation (sighandler_fi)) | |
1e2330ba | 1642 | orig_sp = get_frame_base (sighandler_fi); |
5769d3cd AC |
1643 | else |
1644 | orig_sp = ADDR_BITS_REMOVE ((CORE_ADDR) | |
1e2330ba | 1645 | read_memory_integer (get_frame_base (sighandler_fi), |
5769d3cd AC |
1646 | S390_GPR_SIZE)); |
1647 | if (orig_sp && sigcaller_pc) | |
1648 | { | |
1649 | scontext = orig_sp + S390_SIGNAL_FRAMESIZE; | |
1650 | if (pc == scontext && instr[1] == s390_NR_rt_sigreturn) | |
1651 | { | |
1652 | /* We got a new style rt_signal */ | |
1653 | /* get address of read ucontext->uc_mcontext */ | |
1654 | temp_sregs = orig_sp + (GDB_TARGET_IS_ESAME ? | |
1655 | S390X_UC_MCONTEXT_OFFSET : | |
1656 | S390_UC_MCONTEXT_OFFSET); | |
1657 | } | |
1658 | else | |
1659 | { | |
1660 | /* read sigcontext->sregs */ | |
1661 | temp_sregs = ADDR_BITS_REMOVE ((CORE_ADDR) | |
1662 | read_memory_integer (scontext | |
1663 | + | |
1664 | (GDB_TARGET_IS_ESAME | |
1665 | ? | |
1666 | S390X_SIGCONTEXT_SREGS_OFFSET | |
1667 | : | |
1668 | S390_SIGCONTEXT_SREGS_OFFSET), | |
1669 | S390_GPR_SIZE)); | |
1670 | ||
1671 | } | |
1672 | /* read sigregs->psw.addr */ | |
1673 | *sigcaller_pc = | |
1674 | ADDR_BITS_REMOVE ((CORE_ADDR) | |
1675 | read_memory_integer (temp_sregs + | |
1676 | REGISTER_BYTE | |
1677 | (S390_PC_REGNUM), | |
1678 | S390_PSW_ADDR_SIZE)); | |
1679 | } | |
1680 | } | |
1681 | retval = 1; | |
1682 | } | |
1683 | if (sregs) | |
1684 | *sregs = temp_sregs; | |
1685 | return retval; | |
1686 | } | |
1687 | ||
1688 | /* | |
1689 | We need to do something better here but this will keep us out of trouble | |
1690 | for the moment. | |
1691 | For some reason the blockframe.c calls us with fi->next->fromleaf | |
1692 | so this seems of little use to us. */ | |
a78f21af | 1693 | static CORE_ADDR |
5769d3cd AC |
1694 | s390_init_frame_pc_first (int next_fromleaf, struct frame_info *fi) |
1695 | { | |
1696 | CORE_ADDR sigcaller_pc; | |
97f46953 | 1697 | CORE_ADDR pc = 0; |
5769d3cd AC |
1698 | if (next_fromleaf) |
1699 | { | |
97f46953 | 1700 | pc = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM)); |
5769d3cd AC |
1701 | /* fix signal handlers */ |
1702 | } | |
97f46953 AC |
1703 | else if (get_next_frame (fi) && get_frame_pc (get_next_frame (fi))) |
1704 | pc = s390_frame_saved_pc_nofix (get_next_frame (fi)); | |
1705 | if (pc && get_next_frame (fi) && get_frame_base (get_next_frame (fi)) | |
1706 | && s390_is_sigreturn (pc, get_next_frame (fi), NULL, &sigcaller_pc)) | |
5769d3cd | 1707 | { |
97f46953 | 1708 | pc = sigcaller_pc; |
5769d3cd | 1709 | } |
97f46953 | 1710 | return pc; |
5769d3cd AC |
1711 | } |
1712 | ||
a78f21af | 1713 | static void |
5769d3cd AC |
1714 | s390_init_extra_frame_info (int fromleaf, struct frame_info *fi) |
1715 | { | |
a00a19e9 | 1716 | frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info)); |
50abf9e5 AC |
1717 | if (get_frame_pc (fi)) |
1718 | s390_get_frame_info (s390_sniff_pc_function_start (get_frame_pc (fi), fi), | |
da50a4b7 | 1719 | get_frame_extra_info (fi), fi, 1); |
5769d3cd | 1720 | else |
da50a4b7 | 1721 | s390_memset_extra_info (get_frame_extra_info (fi)); |
5769d3cd AC |
1722 | } |
1723 | ||
1724 | /* If saved registers of frame FI are not known yet, read and cache them. | |
1725 | &FEXTRA_INFOP contains struct frame_extra_info; TDATAP can be NULL, | |
1726 | in which case the framedata are read. */ | |
1727 | ||
a78f21af | 1728 | static void |
5769d3cd AC |
1729 | s390_frame_init_saved_regs (struct frame_info *fi) |
1730 | { | |
1731 | ||
1732 | int quick; | |
1733 | ||
b2fb4676 | 1734 | if (get_frame_saved_regs (fi) == NULL) |
5769d3cd AC |
1735 | { |
1736 | /* zalloc memsets the saved regs */ | |
1737 | frame_saved_regs_zalloc (fi); | |
50abf9e5 | 1738 | if (get_frame_pc (fi)) |
5769d3cd | 1739 | { |
da50a4b7 AC |
1740 | quick = (get_frame_extra_info (fi) |
1741 | && get_frame_extra_info (fi)->initialised | |
1742 | && get_frame_extra_info (fi)->good_prologue); | |
1743 | s390_get_frame_info (quick | |
1744 | ? get_frame_extra_info (fi)->function_start | |
1745 | : s390_sniff_pc_function_start (get_frame_pc (fi), fi), | |
1746 | get_frame_extra_info (fi), fi, !quick); | |
5769d3cd AC |
1747 | } |
1748 | } | |
1749 | } | |
1750 | ||
1751 | ||
1752 | ||
5769d3cd AC |
1753 | static CORE_ADDR |
1754 | s390_frame_saved_pc_nofix (struct frame_info *fi) | |
1755 | { | |
da50a4b7 AC |
1756 | if (get_frame_extra_info (fi) && get_frame_extra_info (fi)->saved_pc_valid) |
1757 | return get_frame_extra_info (fi)->saved_pc; | |
5c3cf190 | 1758 | |
1e2330ba AC |
1759 | if (deprecated_generic_find_dummy_frame (get_frame_pc (fi), |
1760 | get_frame_base (fi))) | |
1761 | return deprecated_read_register_dummy (get_frame_pc (fi), | |
1762 | get_frame_base (fi), S390_PC_REGNUM); | |
5c3cf190 | 1763 | |
5769d3cd | 1764 | s390_frame_init_saved_regs (fi); |
da50a4b7 | 1765 | if (get_frame_extra_info (fi)) |
5769d3cd | 1766 | { |
da50a4b7 AC |
1767 | get_frame_extra_info (fi)->saved_pc_valid = 1; |
1768 | if (get_frame_extra_info (fi)->good_prologue | |
b2fb4676 | 1769 | && get_frame_saved_regs (fi)[S390_RETADDR_REGNUM]) |
da50a4b7 | 1770 | get_frame_extra_info (fi)->saved_pc |
529765f4 | 1771 | = ADDR_BITS_REMOVE (read_memory_integer |
b2fb4676 | 1772 | (get_frame_saved_regs (fi)[S390_RETADDR_REGNUM], |
529765f4 JB |
1773 | S390_GPR_SIZE)); |
1774 | else | |
da50a4b7 | 1775 | get_frame_extra_info (fi)->saved_pc |
529765f4 | 1776 | = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM)); |
da50a4b7 | 1777 | return get_frame_extra_info (fi)->saved_pc; |
5769d3cd AC |
1778 | } |
1779 | return 0; | |
1780 | } | |
1781 | ||
a78f21af | 1782 | static CORE_ADDR |
5769d3cd AC |
1783 | s390_frame_saved_pc (struct frame_info *fi) |
1784 | { | |
1785 | CORE_ADDR saved_pc = 0, sig_pc; | |
1786 | ||
da50a4b7 AC |
1787 | if (get_frame_extra_info (fi) |
1788 | && get_frame_extra_info (fi)->sig_fixed_saved_pc_valid) | |
1789 | return get_frame_extra_info (fi)->sig_fixed_saved_pc; | |
5769d3cd AC |
1790 | saved_pc = s390_frame_saved_pc_nofix (fi); |
1791 | ||
da50a4b7 | 1792 | if (get_frame_extra_info (fi)) |
5769d3cd | 1793 | { |
da50a4b7 | 1794 | get_frame_extra_info (fi)->sig_fixed_saved_pc_valid = 1; |
5769d3cd AC |
1795 | if (saved_pc) |
1796 | { | |
1797 | if (s390_is_sigreturn (saved_pc, fi, NULL, &sig_pc)) | |
1798 | saved_pc = sig_pc; | |
1799 | } | |
da50a4b7 | 1800 | get_frame_extra_info (fi)->sig_fixed_saved_pc = saved_pc; |
5769d3cd AC |
1801 | } |
1802 | return saved_pc; | |
1803 | } | |
1804 | ||
1805 | ||
1806 | ||
1807 | ||
5a203e44 AC |
1808 | /* We want backtraces out of signal handlers so we don't set |
1809 | (get_frame_type (thisframe) == SIGTRAMP_FRAME) to 1 */ | |
5769d3cd | 1810 | |
a78f21af | 1811 | static CORE_ADDR |
5769d3cd AC |
1812 | s390_frame_chain (struct frame_info *thisframe) |
1813 | { | |
1814 | CORE_ADDR prev_fp = 0; | |
1815 | ||
1e2330ba AC |
1816 | if (deprecated_generic_find_dummy_frame (get_frame_pc (thisframe), |
1817 | get_frame_base (thisframe))) | |
1818 | return deprecated_read_register_dummy (get_frame_pc (thisframe), | |
1819 | get_frame_base (thisframe), | |
135c175f | 1820 | S390_SP_REGNUM); |
5769d3cd AC |
1821 | else |
1822 | { | |
1823 | int sigreturn = 0; | |
1824 | CORE_ADDR sregs = 0; | |
1825 | struct frame_extra_info prev_fextra_info; | |
1826 | ||
1827 | memset (&prev_fextra_info, 0, sizeof (prev_fextra_info)); | |
50abf9e5 | 1828 | if (get_frame_pc (thisframe)) |
5769d3cd AC |
1829 | { |
1830 | CORE_ADDR saved_pc, sig_pc; | |
1831 | ||
1832 | saved_pc = s390_frame_saved_pc_nofix (thisframe); | |
1833 | if (saved_pc) | |
1834 | { | |
1835 | if ((sigreturn = | |
1836 | s390_is_sigreturn (saved_pc, thisframe, &sregs, &sig_pc))) | |
1837 | saved_pc = sig_pc; | |
1838 | s390_get_frame_info (s390_sniff_pc_function_start | |
1839 | (saved_pc, NULL), &prev_fextra_info, NULL, | |
1840 | 1); | |
1841 | } | |
1842 | } | |
1843 | if (sigreturn) | |
1844 | { | |
1845 | /* read sigregs,regs.gprs[11 or 15] */ | |
1846 | prev_fp = read_memory_integer (sregs + | |
1847 | REGISTER_BYTE (S390_GP0_REGNUM + | |
1848 | (prev_fextra_info. | |
1849 | frame_pointer_saved_pc | |
1850 | ? 11 : 15)), | |
1851 | S390_GPR_SIZE); | |
da50a4b7 | 1852 | get_frame_extra_info (thisframe)->sigcontext = sregs; |
5769d3cd AC |
1853 | } |
1854 | else | |
1855 | { | |
b2fb4676 | 1856 | if (get_frame_saved_regs (thisframe)) |
5769d3cd | 1857 | { |
5769d3cd AC |
1858 | int regno; |
1859 | ||
31c4d430 | 1860 | if (prev_fextra_info.frame_pointer_saved_pc |
b2fb4676 | 1861 | && get_frame_saved_regs (thisframe)[S390_FRAME_REGNUM]) |
31c4d430 JB |
1862 | regno = S390_FRAME_REGNUM; |
1863 | else | |
1864 | regno = S390_SP_REGNUM; | |
1865 | ||
b2fb4676 | 1866 | if (get_frame_saved_regs (thisframe)[regno]) |
31c4d430 JB |
1867 | { |
1868 | /* The SP's entry of `saved_regs' is special. */ | |
1869 | if (regno == S390_SP_REGNUM) | |
b2fb4676 | 1870 | prev_fp = get_frame_saved_regs (thisframe)[regno]; |
31c4d430 JB |
1871 | else |
1872 | prev_fp = | |
b2fb4676 | 1873 | read_memory_integer (get_frame_saved_regs (thisframe)[regno], |
31c4d430 JB |
1874 | S390_GPR_SIZE); |
1875 | } | |
5769d3cd AC |
1876 | } |
1877 | } | |
1878 | } | |
1879 | return ADDR_BITS_REMOVE (prev_fp); | |
1880 | } | |
1881 | ||
1882 | /* | |
1883 | Whether struct frame_extra_info is actually needed I'll have to figure | |
1884 | out as our frames are similar to rs6000 there is a possibility | |
1885 | i386 dosen't need it. */ | |
1886 | ||
1887 | ||
1888 | ||
1889 | /* a given return value in `regbuf' with a type `valtype', extract and copy its | |
1890 | value into `valbuf' */ | |
a78f21af | 1891 | static void |
5769d3cd AC |
1892 | s390_extract_return_value (struct type *valtype, char *regbuf, char *valbuf) |
1893 | { | |
1894 | /* floats and doubles are returned in fpr0. fpr's have a size of 8 bytes. | |
1895 | We need to truncate the return value into float size (4 byte) if | |
1896 | necessary. */ | |
1897 | int len = TYPE_LENGTH (valtype); | |
1898 | ||
1899 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
f2c6cfba | 1900 | memcpy (valbuf, ®buf[REGISTER_BYTE (S390_FP0_REGNUM)], len); |
5769d3cd AC |
1901 | else |
1902 | { | |
1903 | int offset = 0; | |
1904 | /* return value is copied starting from r2. */ | |
1905 | if (TYPE_LENGTH (valtype) < S390_GPR_SIZE) | |
1906 | offset = S390_GPR_SIZE - TYPE_LENGTH (valtype); | |
1907 | memcpy (valbuf, | |
1908 | regbuf + REGISTER_BYTE (S390_GP0_REGNUM + 2) + offset, | |
1909 | TYPE_LENGTH (valtype)); | |
1910 | } | |
1911 | } | |
1912 | ||
1913 | ||
1914 | static char * | |
1915 | s390_promote_integer_argument (struct type *valtype, char *valbuf, | |
1916 | char *reg_buff, int *arglen) | |
1917 | { | |
1918 | char *value = valbuf; | |
1919 | int len = TYPE_LENGTH (valtype); | |
1920 | ||
1921 | if (len < S390_GPR_SIZE) | |
1922 | { | |
1923 | /* We need to upgrade this value to a register to pass it correctly */ | |
1924 | int idx, diff = S390_GPR_SIZE - len, negative = | |
1925 | (!TYPE_UNSIGNED (valtype) && value[0] & 0x80); | |
1926 | for (idx = 0; idx < S390_GPR_SIZE; idx++) | |
1927 | { | |
1928 | reg_buff[idx] = (idx < diff ? (negative ? 0xff : 0x0) : | |
1929 | value[idx - diff]); | |
1930 | } | |
1931 | value = reg_buff; | |
1932 | *arglen = S390_GPR_SIZE; | |
1933 | } | |
1934 | else | |
1935 | { | |
1936 | if (len & (S390_GPR_SIZE - 1)) | |
1937 | { | |
1938 | fprintf_unfiltered (gdb_stderr, | |
1939 | "s390_promote_integer_argument detected an argument not " | |
1940 | "a multiple of S390_GPR_SIZE & greater than S390_GPR_SIZE " | |
1941 | "we might not deal with this correctly.\n"); | |
1942 | } | |
1943 | *arglen = len; | |
1944 | } | |
1945 | ||
1946 | return (value); | |
1947 | } | |
1948 | ||
a78f21af | 1949 | static void |
5769d3cd AC |
1950 | s390_store_return_value (struct type *valtype, char *valbuf) |
1951 | { | |
1952 | int arglen; | |
b1e29e33 | 1953 | char *reg_buff = alloca (max (S390_FPR_SIZE, DEPRECATED_REGISTER_SIZE)), *value; |
5769d3cd AC |
1954 | |
1955 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
1956 | { | |
03a013f4 JB |
1957 | if (TYPE_LENGTH (valtype) == 4 |
1958 | || TYPE_LENGTH (valtype) == 8) | |
73937e03 AC |
1959 | deprecated_write_register_bytes (REGISTER_BYTE (S390_FP0_REGNUM), |
1960 | valbuf, TYPE_LENGTH (valtype)); | |
03a013f4 JB |
1961 | else |
1962 | error ("GDB is unable to return `long double' values " | |
1963 | "on this architecture."); | |
5769d3cd AC |
1964 | } |
1965 | else | |
1966 | { | |
1967 | value = | |
1968 | s390_promote_integer_argument (valtype, valbuf, reg_buff, &arglen); | |
1969 | /* Everything else is returned in GPR2 and up. */ | |
73937e03 AC |
1970 | deprecated_write_register_bytes (REGISTER_BYTE (S390_GP0_REGNUM + 2), |
1971 | value, arglen); | |
5769d3cd AC |
1972 | } |
1973 | } | |
1974 | static int | |
1975 | gdb_print_insn_s390 (bfd_vma memaddr, disassemble_info * info) | |
1976 | { | |
1977 | bfd_byte instrbuff[S390_MAX_INSTR_SIZE]; | |
1978 | int instrlen, cnt; | |
1979 | ||
1980 | instrlen = s390_readinstruction (instrbuff, (CORE_ADDR) memaddr, info); | |
1981 | if (instrlen < 0) | |
1982 | { | |
1983 | (*info->memory_error_func) (instrlen, memaddr, info); | |
1984 | return -1; | |
1985 | } | |
1986 | for (cnt = 0; cnt < instrlen; cnt++) | |
1987 | info->fprintf_func (info->stream, "%02X ", instrbuff[cnt]); | |
1988 | for (cnt = instrlen; cnt < S390_MAX_INSTR_SIZE; cnt++) | |
1989 | info->fprintf_func (info->stream, " "); | |
1990 | instrlen = print_insn_s390 (memaddr, info); | |
1991 | return instrlen; | |
1992 | } | |
1993 | ||
1994 | ||
1995 | ||
1996 | /* Not the most efficent code in the world */ | |
a78f21af | 1997 | static int |
5ae5f592 | 1998 | s390_fp_regnum (void) |
5769d3cd AC |
1999 | { |
2000 | int regno = S390_SP_REGNUM; | |
2001 | struct frame_extra_info fextra_info; | |
2002 | ||
2003 | CORE_ADDR pc = ADDR_BITS_REMOVE (read_register (S390_PC_REGNUM)); | |
2004 | ||
2005 | s390_get_frame_info (s390_sniff_pc_function_start (pc, NULL), &fextra_info, | |
2006 | NULL, 1); | |
2007 | if (fextra_info.frame_pointer_saved_pc) | |
2008 | regno = S390_FRAME_REGNUM; | |
2009 | return regno; | |
2010 | } | |
2011 | ||
a78f21af | 2012 | static CORE_ADDR |
5ae5f592 | 2013 | s390_read_fp (void) |
5769d3cd AC |
2014 | { |
2015 | return read_register (s390_fp_regnum ()); | |
2016 | } | |
2017 | ||
2018 | ||
4c8287ac JB |
2019 | static void |
2020 | s390_pop_frame_regular (struct frame_info *frame) | |
5769d3cd | 2021 | { |
4c8287ac JB |
2022 | int regnum; |
2023 | ||
8bedc050 | 2024 | write_register (S390_PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame)); |
4c8287ac JB |
2025 | |
2026 | /* Restore any saved registers. */ | |
b2fb4676 | 2027 | if (get_frame_saved_regs (frame)) |
1a889ea5 JB |
2028 | { |
2029 | for (regnum = 0; regnum < NUM_REGS; regnum++) | |
b2fb4676 | 2030 | if (get_frame_saved_regs (frame)[regnum] != 0) |
1a889ea5 JB |
2031 | { |
2032 | ULONGEST value; | |
2033 | ||
b2fb4676 | 2034 | value = read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum], |
1a889ea5 JB |
2035 | REGISTER_RAW_SIZE (regnum)); |
2036 | write_register (regnum, value); | |
2037 | } | |
2038 | ||
2039 | /* Actually cut back the stack. Remember that the SP's element of | |
2040 | saved_regs is the old SP itself, not the address at which it is | |
2041 | saved. */ | |
b2fb4676 | 2042 | write_register (S390_SP_REGNUM, get_frame_saved_regs (frame)[S390_SP_REGNUM]); |
1a889ea5 | 2043 | } |
5769d3cd | 2044 | |
4c8287ac JB |
2045 | /* Throw away any cached frame information. */ |
2046 | flush_cached_frames (); | |
5769d3cd AC |
2047 | } |
2048 | ||
4c8287ac JB |
2049 | |
2050 | /* Destroy the innermost (Top-Of-Stack) stack frame, restoring the | |
2051 | machine state that was in effect before the frame was created. | |
2052 | Used in the contexts of the "return" command, and of | |
2053 | target function calls from the debugger. */ | |
a78f21af | 2054 | static void |
5ae5f592 | 2055 | s390_pop_frame (void) |
4c8287ac JB |
2056 | { |
2057 | /* This function checks for and handles generic dummy frames, and | |
2058 | calls back to our function for ordinary frames. */ | |
2059 | generic_pop_current_frame (s390_pop_frame_regular); | |
2060 | } | |
2061 | ||
2062 | ||
78f8b424 JB |
2063 | /* Return non-zero if TYPE is an integer-like type, zero otherwise. |
2064 | "Integer-like" types are those that should be passed the way | |
2065 | integers are: integers, enums, ranges, characters, and booleans. */ | |
2066 | static int | |
2067 | is_integer_like (struct type *type) | |
2068 | { | |
2069 | enum type_code code = TYPE_CODE (type); | |
2070 | ||
2071 | return (code == TYPE_CODE_INT | |
2072 | || code == TYPE_CODE_ENUM | |
2073 | || code == TYPE_CODE_RANGE | |
2074 | || code == TYPE_CODE_CHAR | |
2075 | || code == TYPE_CODE_BOOL); | |
2076 | } | |
2077 | ||
2078 | ||
2079 | /* Return non-zero if TYPE is a pointer-like type, zero otherwise. | |
2080 | "Pointer-like" types are those that should be passed the way | |
2081 | pointers are: pointers and references. */ | |
2082 | static int | |
2083 | is_pointer_like (struct type *type) | |
2084 | { | |
2085 | enum type_code code = TYPE_CODE (type); | |
2086 | ||
2087 | return (code == TYPE_CODE_PTR | |
2088 | || code == TYPE_CODE_REF); | |
2089 | } | |
2090 | ||
2091 | ||
20a940cc JB |
2092 | /* Return non-zero if TYPE is a `float singleton' or `double |
2093 | singleton', zero otherwise. | |
2094 | ||
2095 | A `T singleton' is a struct type with one member, whose type is | |
2096 | either T or a `T singleton'. So, the following are all float | |
2097 | singletons: | |
2098 | ||
2099 | struct { float x }; | |
2100 | struct { struct { float x; } x; }; | |
2101 | struct { struct { struct { float x; } x; } x; }; | |
2102 | ||
2103 | ... and so on. | |
2104 | ||
2105 | WHY THE HECK DO WE CARE ABOUT THIS??? Well, it turns out that GCC | |
2106 | passes all float singletons and double singletons as if they were | |
2107 | simply floats or doubles. This is *not* what the ABI says it | |
2108 | should do. */ | |
2109 | static int | |
2110 | is_float_singleton (struct type *type) | |
2111 | { | |
2112 | return (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
2113 | && TYPE_NFIELDS (type) == 1 | |
2114 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_FLT | |
2115 | || is_float_singleton (TYPE_FIELD_TYPE (type, 0)))); | |
2116 | } | |
2117 | ||
2118 | ||
2119 | /* Return non-zero if TYPE is a struct-like type, zero otherwise. | |
2120 | "Struct-like" types are those that should be passed as structs are: | |
2121 | structs and unions. | |
2122 | ||
2123 | As an odd quirk, not mentioned in the ABI, GCC passes float and | |
2124 | double singletons as if they were a plain float, double, etc. (The | |
2125 | corresponding union types are handled normally.) So we exclude | |
2126 | those types here. *shrug* */ | |
2127 | static int | |
2128 | is_struct_like (struct type *type) | |
2129 | { | |
2130 | enum type_code code = TYPE_CODE (type); | |
2131 | ||
2132 | return (code == TYPE_CODE_UNION | |
2133 | || (code == TYPE_CODE_STRUCT && ! is_float_singleton (type))); | |
2134 | } | |
2135 | ||
2136 | ||
2137 | /* Return non-zero if TYPE is a float-like type, zero otherwise. | |
2138 | "Float-like" types are those that should be passed as | |
2139 | floating-point values are. | |
2140 | ||
2141 | You'd think this would just be floats, doubles, long doubles, etc. | |
2142 | But as an odd quirk, not mentioned in the ABI, GCC passes float and | |
2143 | double singletons as if they were a plain float, double, etc. (The | |
4d819d0e | 2144 | corresponding union types are handled normally.) So we include |
20a940cc JB |
2145 | those types here. *shrug* */ |
2146 | static int | |
2147 | is_float_like (struct type *type) | |
2148 | { | |
2149 | return (TYPE_CODE (type) == TYPE_CODE_FLT | |
2150 | || is_float_singleton (type)); | |
2151 | } | |
2152 | ||
2153 | ||
78f8b424 JB |
2154 | /* Return non-zero if TYPE is considered a `DOUBLE_OR_FLOAT', as |
2155 | defined by the parameter passing conventions described in the | |
ca557f44 | 2156 | "GNU/Linux for S/390 ELF Application Binary Interface Supplement". |
78f8b424 JB |
2157 | Otherwise, return zero. */ |
2158 | static int | |
2159 | is_double_or_float (struct type *type) | |
2160 | { | |
20a940cc | 2161 | return (is_float_like (type) |
78f8b424 JB |
2162 | && (TYPE_LENGTH (type) == 4 |
2163 | || TYPE_LENGTH (type) == 8)); | |
2164 | } | |
2165 | ||
5769d3cd | 2166 | |
4d819d0e JB |
2167 | /* Return non-zero if TYPE is a `DOUBLE_ARG', as defined by the |
2168 | parameter passing conventions described in the "GNU/Linux for S/390 | |
2169 | ELF Application Binary Interface Supplement". Return zero | |
2170 | otherwise. */ | |
2171 | static int | |
2172 | is_double_arg (struct type *type) | |
2173 | { | |
2174 | unsigned length = TYPE_LENGTH (type); | |
2175 | ||
2176 | /* The s390x ABI doesn't handle DOUBLE_ARGS specially. */ | |
2177 | if (GDB_TARGET_IS_ESAME) | |
2178 | return 0; | |
2179 | ||
2180 | return ((is_integer_like (type) | |
2181 | || is_struct_like (type)) | |
2182 | && length == 8); | |
2183 | } | |
2184 | ||
2185 | ||
78f8b424 | 2186 | /* Return non-zero if TYPE is considered a `SIMPLE_ARG', as defined by |
ca557f44 AC |
2187 | the parameter passing conventions described in the "GNU/Linux for |
2188 | S/390 ELF Application Binary Interface Supplement". Return zero | |
2189 | otherwise. */ | |
78f8b424 JB |
2190 | static int |
2191 | is_simple_arg (struct type *type) | |
2192 | { | |
78f8b424 JB |
2193 | unsigned length = TYPE_LENGTH (type); |
2194 | ||
a1677dfb JB |
2195 | /* This is almost a direct translation of the ABI's language, except |
2196 | that we have to exclude 8-byte structs; those are DOUBLE_ARGs. */ | |
4d819d0e | 2197 | return ((is_integer_like (type) && length <= DEPRECATED_REGISTER_SIZE) |
78f8b424 | 2198 | || is_pointer_like (type) |
4d819d0e | 2199 | || (is_struct_like (type) && !is_double_arg (type))); |
78f8b424 JB |
2200 | } |
2201 | ||
2202 | ||
4d819d0e JB |
2203 | static int |
2204 | is_power_of_two (unsigned int n) | |
2205 | { | |
2206 | return ((n & (n - 1)) == 0); | |
2207 | } | |
2208 | ||
78f8b424 JB |
2209 | /* Return non-zero if TYPE should be passed as a pointer to a copy, |
2210 | zero otherwise. TYPE must be a SIMPLE_ARG, as recognized by | |
2211 | `is_simple_arg'. */ | |
2212 | static int | |
2213 | pass_by_copy_ref (struct type *type) | |
2214 | { | |
78f8b424 JB |
2215 | unsigned length = TYPE_LENGTH (type); |
2216 | ||
4d819d0e JB |
2217 | return (is_struct_like (type) |
2218 | && !(is_power_of_two (length) && length <= DEPRECATED_REGISTER_SIZE)); | |
78f8b424 JB |
2219 | } |
2220 | ||
2221 | ||
2222 | /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full | |
2223 | word as required for the ABI. */ | |
2224 | static LONGEST | |
2225 | extend_simple_arg (struct value *arg) | |
2226 | { | |
2227 | struct type *type = VALUE_TYPE (arg); | |
2228 | ||
2229 | /* Even structs get passed in the least significant bits of the | |
2230 | register / memory word. It's not really right to extract them as | |
2231 | an integer, but it does take care of the extension. */ | |
2232 | if (TYPE_UNSIGNED (type)) | |
2233 | return extract_unsigned_integer (VALUE_CONTENTS (arg), | |
2234 | TYPE_LENGTH (type)); | |
2235 | else | |
2236 | return extract_signed_integer (VALUE_CONTENTS (arg), | |
2237 | TYPE_LENGTH (type)); | |
2238 | } | |
2239 | ||
2240 | ||
78f8b424 JB |
2241 | /* Round ADDR up to the next N-byte boundary. N must be a power of |
2242 | two. */ | |
2243 | static CORE_ADDR | |
2244 | round_up (CORE_ADDR addr, int n) | |
2245 | { | |
2246 | /* Check that N is really a power of two. */ | |
2247 | gdb_assert (n && (n & (n-1)) == 0); | |
2248 | return ((addr + n - 1) & -n); | |
2249 | } | |
2250 | ||
2251 | ||
2252 | /* Round ADDR down to the next N-byte boundary. N must be a power of | |
2253 | two. */ | |
2254 | static CORE_ADDR | |
2255 | round_down (CORE_ADDR addr, int n) | |
2256 | { | |
2257 | /* Check that N is really a power of two. */ | |
2258 | gdb_assert (n && (n & (n-1)) == 0); | |
2259 | return (addr & -n); | |
2260 | } | |
2261 | ||
2262 | ||
2263 | /* Return the alignment required by TYPE. */ | |
2264 | static int | |
2265 | alignment_of (struct type *type) | |
2266 | { | |
2267 | int alignment; | |
2268 | ||
2269 | if (is_integer_like (type) | |
2270 | || is_pointer_like (type) | |
2271 | || TYPE_CODE (type) == TYPE_CODE_FLT) | |
2272 | alignment = TYPE_LENGTH (type); | |
2273 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
2274 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
2275 | { | |
2276 | int i; | |
2277 | ||
2278 | alignment = 1; | |
2279 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
2280 | { | |
2281 | int field_alignment = alignment_of (TYPE_FIELD_TYPE (type, i)); | |
2282 | ||
2283 | if (field_alignment > alignment) | |
2284 | alignment = field_alignment; | |
2285 | } | |
2286 | } | |
2287 | else | |
2288 | alignment = 1; | |
2289 | ||
2290 | /* Check that everything we ever return is a power of two. Lots of | |
2291 | code doesn't want to deal with aligning things to arbitrary | |
2292 | boundaries. */ | |
2293 | gdb_assert ((alignment & (alignment - 1)) == 0); | |
2294 | ||
2295 | return alignment; | |
2296 | } | |
2297 | ||
2298 | ||
2299 | /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in | |
ca557f44 AC |
2300 | place to be passed to a function, as specified by the "GNU/Linux |
2301 | for S/390 ELF Application Binary Interface Supplement". | |
78f8b424 JB |
2302 | |
2303 | SP is the current stack pointer. We must put arguments, links, | |
2304 | padding, etc. whereever they belong, and return the new stack | |
2305 | pointer value. | |
2306 | ||
2307 | If STRUCT_RETURN is non-zero, then the function we're calling is | |
2308 | going to return a structure by value; STRUCT_ADDR is the address of | |
2309 | a block we've allocated for it on the stack. | |
2310 | ||
2311 | Our caller has taken care of any type promotions needed to satisfy | |
2312 | prototypes or the old K&R argument-passing rules. */ | |
a78f21af | 2313 | static CORE_ADDR |
d45fc520 | 2314 | s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp, |
5769d3cd AC |
2315 | int struct_return, CORE_ADDR struct_addr) |
2316 | { | |
78f8b424 JB |
2317 | int i; |
2318 | int pointer_size = (TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
5769d3cd | 2319 | |
78f8b424 JB |
2320 | /* The number of arguments passed by reference-to-copy. */ |
2321 | int num_copies; | |
5769d3cd | 2322 | |
78f8b424 JB |
2323 | /* If the i'th argument is passed as a reference to a copy, then |
2324 | copy_addr[i] is the address of the copy we made. */ | |
2325 | CORE_ADDR *copy_addr = alloca (nargs * sizeof (CORE_ADDR)); | |
5769d3cd | 2326 | |
78f8b424 JB |
2327 | /* Build the reference-to-copy area. */ |
2328 | num_copies = 0; | |
2329 | for (i = 0; i < nargs; i++) | |
2330 | { | |
2331 | struct value *arg = args[i]; | |
2332 | struct type *type = VALUE_TYPE (arg); | |
2333 | unsigned length = TYPE_LENGTH (type); | |
5769d3cd | 2334 | |
78f8b424 JB |
2335 | if (is_simple_arg (type) |
2336 | && pass_by_copy_ref (type)) | |
01c464e9 | 2337 | { |
78f8b424 JB |
2338 | sp -= length; |
2339 | sp = round_down (sp, alignment_of (type)); | |
2340 | write_memory (sp, VALUE_CONTENTS (arg), length); | |
2341 | copy_addr[i] = sp; | |
2342 | num_copies++; | |
01c464e9 | 2343 | } |
5769d3cd | 2344 | } |
5769d3cd | 2345 | |
78f8b424 JB |
2346 | /* Reserve space for the parameter area. As a conservative |
2347 | simplification, we assume that everything will be passed on the | |
2348 | stack. */ | |
2349 | { | |
2350 | int i; | |
2351 | ||
2352 | for (i = 0; i < nargs; i++) | |
2353 | { | |
2354 | struct value *arg = args[i]; | |
2355 | struct type *type = VALUE_TYPE (arg); | |
2356 | int length = TYPE_LENGTH (type); | |
2357 | ||
2358 | sp = round_down (sp, alignment_of (type)); | |
2359 | ||
4d819d0e JB |
2360 | /* SIMPLE_ARG values get extended to DEPRECATED_REGISTER_SIZE bytes. |
2361 | Assume every argument is. */ | |
2362 | if (length < DEPRECATED_REGISTER_SIZE) length = DEPRECATED_REGISTER_SIZE; | |
78f8b424 JB |
2363 | sp -= length; |
2364 | } | |
2365 | } | |
2366 | ||
2367 | /* Include space for any reference-to-copy pointers. */ | |
2368 | sp = round_down (sp, pointer_size); | |
2369 | sp -= num_copies * pointer_size; | |
2370 | ||
2371 | /* After all that, make sure it's still aligned on an eight-byte | |
2372 | boundary. */ | |
2373 | sp = round_down (sp, 8); | |
2374 | ||
2375 | /* Finally, place the actual parameters, working from SP towards | |
2376 | higher addresses. The code above is supposed to reserve enough | |
2377 | space for this. */ | |
2378 | { | |
2379 | int fr = 0; | |
2380 | int gr = 2; | |
2381 | CORE_ADDR starg = sp; | |
2382 | ||
4d819d0e JB |
2383 | /* A struct is returned using general register 2 */ |
2384 | if (struct_return) | |
2385 | gr++; | |
2386 | ||
78f8b424 JB |
2387 | for (i = 0; i < nargs; i++) |
2388 | { | |
2389 | struct value *arg = args[i]; | |
2390 | struct type *type = VALUE_TYPE (arg); | |
2391 | ||
2392 | if (is_double_or_float (type) | |
4d819d0e | 2393 | && fr <= S390_NUM_FP_PARAMETER_REGISTERS * 2 - 2) |
78f8b424 JB |
2394 | { |
2395 | /* When we store a single-precision value in an FP register, | |
2396 | it occupies the leftmost bits. */ | |
73937e03 AC |
2397 | deprecated_write_register_bytes (REGISTER_BYTE (S390_FP0_REGNUM + fr), |
2398 | VALUE_CONTENTS (arg), | |
2399 | TYPE_LENGTH (type)); | |
78f8b424 JB |
2400 | fr += 2; |
2401 | } | |
2402 | else if (is_simple_arg (type) | |
2403 | && gr <= 6) | |
2404 | { | |
2405 | /* Do we need to pass a pointer to our copy of this | |
2406 | argument? */ | |
2407 | if (pass_by_copy_ref (type)) | |
2408 | write_register (S390_GP0_REGNUM + gr, copy_addr[i]); | |
2409 | else | |
2410 | write_register (S390_GP0_REGNUM + gr, extend_simple_arg (arg)); | |
2411 | ||
2412 | gr++; | |
2413 | } | |
2414 | else if (is_double_arg (type) | |
2415 | && gr <= 5) | |
2416 | { | |
4caf0990 AC |
2417 | deprecated_write_register_gen (S390_GP0_REGNUM + gr, |
2418 | VALUE_CONTENTS (arg)); | |
2419 | deprecated_write_register_gen (S390_GP0_REGNUM + gr + 1, | |
4d819d0e | 2420 | VALUE_CONTENTS (arg) + DEPRECATED_REGISTER_SIZE); |
78f8b424 JB |
2421 | gr += 2; |
2422 | } | |
2423 | else | |
2424 | { | |
2425 | /* The `OTHER' case. */ | |
2426 | enum type_code code = TYPE_CODE (type); | |
2427 | unsigned length = TYPE_LENGTH (type); | |
2428 | ||
2429 | /* If we skipped r6 because we couldn't fit a DOUBLE_ARG | |
2430 | in it, then don't go back and use it again later. */ | |
2431 | if (is_double_arg (type) && gr == 6) | |
2432 | gr = 7; | |
2433 | ||
2434 | if (is_simple_arg (type)) | |
2435 | { | |
4d819d0e JB |
2436 | /* Simple args are always extended to |
2437 | DEPRECATED_REGISTER_SIZE bytes. */ | |
2438 | starg = round_up (starg, DEPRECATED_REGISTER_SIZE); | |
78f8b424 JB |
2439 | |
2440 | /* Do we need to pass a pointer to our copy of this | |
2441 | argument? */ | |
2442 | if (pass_by_copy_ref (type)) | |
2443 | write_memory_signed_integer (starg, pointer_size, | |
2444 | copy_addr[i]); | |
2445 | else | |
4d819d0e JB |
2446 | /* Simple args are always extended to |
2447 | DEPRECATED_REGISTER_SIZE bytes. */ | |
2448 | write_memory_signed_integer (starg, DEPRECATED_REGISTER_SIZE, | |
78f8b424 | 2449 | extend_simple_arg (arg)); |
4d819d0e | 2450 | starg += DEPRECATED_REGISTER_SIZE; |
78f8b424 JB |
2451 | } |
2452 | else | |
2453 | { | |
20a940cc JB |
2454 | /* You'd think we should say: |
2455 | starg = round_up (starg, alignment_of (type)); | |
2456 | Unfortunately, GCC seems to simply align the stack on | |
4d819d0e JB |
2457 | a four/eight-byte boundary, even when passing doubles. */ |
2458 | starg = round_up (starg, S390_STACK_PARAMETER_ALIGNMENT); | |
78f8b424 JB |
2459 | write_memory (starg, VALUE_CONTENTS (arg), length); |
2460 | starg += length; | |
2461 | } | |
2462 | } | |
2463 | } | |
2464 | } | |
2465 | ||
2466 | /* Allocate the standard frame areas: the register save area, the | |
2467 | word reserved for the compiler (which seems kind of meaningless), | |
2468 | and the back chain pointer. */ | |
4d819d0e | 2469 | sp -= S390_STACK_FRAME_OVERHEAD; |
78f8b424 JB |
2470 | |
2471 | /* Write the back chain pointer into the first word of the stack | |
2472 | frame. This will help us get backtraces from within functions | |
2473 | called from GDB. */ | |
2474 | write_memory_unsigned_integer (sp, (TARGET_PTR_BIT / TARGET_CHAR_BIT), | |
0ba6dca9 | 2475 | deprecated_read_fp ()); |
78f8b424 JB |
2476 | |
2477 | return sp; | |
5769d3cd AC |
2478 | } |
2479 | ||
c8f9d51c | 2480 | |
4074e13c JB |
2481 | static CORE_ADDR |
2482 | s390_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) | |
2483 | { | |
2484 | /* Both the 32- and 64-bit ABI's say that the stack pointer should | |
2485 | always be aligned on an eight-byte boundary. */ | |
2486 | return (addr & -8); | |
2487 | } | |
2488 | ||
2489 | ||
c8f9d51c JB |
2490 | static int |
2491 | s390_use_struct_convention (int gcc_p, struct type *value_type) | |
2492 | { | |
2493 | enum type_code code = TYPE_CODE (value_type); | |
2494 | ||
2495 | return (code == TYPE_CODE_STRUCT | |
2496 | || code == TYPE_CODE_UNION); | |
2497 | } | |
2498 | ||
2499 | ||
5769d3cd AC |
2500 | /* Return the GDB type object for the "standard" data type |
2501 | of data in register N. */ | |
a78f21af | 2502 | static struct type * |
5769d3cd AC |
2503 | s390_register_virtual_type (int regno) |
2504 | { | |
b09677dc JB |
2505 | if (S390_FP0_REGNUM <= regno && regno < S390_FP0_REGNUM + S390_NUM_FPRS) |
2506 | return builtin_type_double; | |
2507 | else | |
2508 | return builtin_type_int; | |
5769d3cd AC |
2509 | } |
2510 | ||
2511 | ||
a78f21af | 2512 | static struct type * |
5769d3cd AC |
2513 | s390x_register_virtual_type (int regno) |
2514 | { | |
2515 | return (regno == S390_FPC_REGNUM) || | |
2516 | (regno >= S390_FIRST_ACR && regno <= S390_LAST_ACR) ? builtin_type_int : | |
2517 | (regno >= S390_FP0_REGNUM) ? builtin_type_double : builtin_type_long; | |
2518 | } | |
2519 | ||
2520 | ||
2521 | ||
a78f21af | 2522 | static void |
5769d3cd AC |
2523 | s390_store_struct_return (CORE_ADDR addr, CORE_ADDR sp) |
2524 | { | |
2525 | write_register (S390_GP0_REGNUM + 2, addr); | |
2526 | } | |
2527 | ||
2528 | ||
2529 | ||
a78f21af | 2530 | static const unsigned char * |
5769d3cd AC |
2531 | s390_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) |
2532 | { | |
2533 | static unsigned char breakpoint[] = { 0x0, 0x1 }; | |
2534 | ||
2535 | *lenptr = sizeof (breakpoint); | |
2536 | return breakpoint; | |
2537 | } | |
2538 | ||
2539 | /* Advance PC across any function entry prologue instructions to reach some | |
2540 | "real" code. */ | |
a78f21af | 2541 | static CORE_ADDR |
5769d3cd AC |
2542 | s390_skip_prologue (CORE_ADDR pc) |
2543 | { | |
2544 | struct frame_extra_info fextra_info; | |
2545 | ||
2546 | s390_get_frame_info (pc, &fextra_info, NULL, 1); | |
2547 | return fextra_info.skip_prologue_function_start; | |
2548 | } | |
2549 | ||
5769d3cd AC |
2550 | /* Immediately after a function call, return the saved pc. |
2551 | Can't go through the frames for this because on some machines | |
2552 | the new frame is not set up until the new function executes | |
2553 | some instructions. */ | |
a78f21af | 2554 | static CORE_ADDR |
5769d3cd AC |
2555 | s390_saved_pc_after_call (struct frame_info *frame) |
2556 | { | |
2557 | return ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM)); | |
2558 | } | |
2559 | ||
2560 | static CORE_ADDR | |
2561 | s390_addr_bits_remove (CORE_ADDR addr) | |
2562 | { | |
2563 | return (addr) & 0x7fffffff; | |
2564 | } | |
2565 | ||
2566 | ||
2567 | static CORE_ADDR | |
2568 | s390_push_return_address (CORE_ADDR pc, CORE_ADDR sp) | |
2569 | { | |
d4d0c21e | 2570 | write_register (S390_RETADDR_REGNUM, CALL_DUMMY_ADDRESS ()); |
5769d3cd AC |
2571 | return sp; |
2572 | } | |
2573 | ||
ffc65945 KB |
2574 | static int |
2575 | s390_address_class_type_flags (int byte_size, int dwarf2_addr_class) | |
2576 | { | |
2577 | if (byte_size == 4) | |
2578 | return TYPE_FLAG_ADDRESS_CLASS_1; | |
2579 | else | |
2580 | return 0; | |
2581 | } | |
2582 | ||
2583 | static const char * | |
2584 | s390_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags) | |
2585 | { | |
2586 | if (type_flags & TYPE_FLAG_ADDRESS_CLASS_1) | |
2587 | return "mode32"; | |
2588 | else | |
2589 | return NULL; | |
2590 | } | |
2591 | ||
a78f21af | 2592 | static int |
ffc65945 KB |
2593 | s390_address_class_name_to_type_flags (struct gdbarch *gdbarch, const char *name, |
2594 | int *type_flags_ptr) | |
2595 | { | |
2596 | if (strcmp (name, "mode32") == 0) | |
2597 | { | |
2598 | *type_flags_ptr = TYPE_FLAG_ADDRESS_CLASS_1; | |
2599 | return 1; | |
2600 | } | |
2601 | else | |
2602 | return 0; | |
2603 | } | |
2604 | ||
a78f21af | 2605 | static struct gdbarch * |
5769d3cd AC |
2606 | s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) |
2607 | { | |
d4d0c21e | 2608 | static LONGEST s390_call_dummy_words[] = { 0 }; |
5769d3cd AC |
2609 | struct gdbarch *gdbarch; |
2610 | struct gdbarch_tdep *tdep; | |
2611 | int elf_flags; | |
2612 | ||
2613 | /* First see if there is already a gdbarch that can satisfy the request. */ | |
2614 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
2615 | if (arches != NULL) | |
2616 | return arches->gdbarch; | |
2617 | ||
2618 | /* None found: is the request for a s390 architecture? */ | |
2619 | if (info.bfd_arch_info->arch != bfd_arch_s390) | |
2620 | return NULL; /* No; then it's not for us. */ | |
2621 | ||
2622 | /* Yes: create a new gdbarch for the specified machine type. */ | |
2623 | gdbarch = gdbarch_alloc (&info, NULL); | |
2624 | ||
a5afb99f AC |
2625 | /* NOTE: cagney/2002-12-06: This can be deleted when this arch is |
2626 | ready to unwind the PC first (see frame.c:get_prev_frame()). */ | |
2627 | set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_default); | |
2628 | ||
5769d3cd | 2629 | set_gdbarch_believe_pcc_promotion (gdbarch, 0); |
4e409299 | 2630 | set_gdbarch_char_signed (gdbarch, 0); |
5769d3cd | 2631 | |
5769d3cd | 2632 | set_gdbarch_frame_args_skip (gdbarch, 0); |
618ce49f | 2633 | set_gdbarch_deprecated_frame_chain (gdbarch, s390_frame_chain); |
f30ee0bc | 2634 | set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, s390_frame_init_saved_regs); |
4183d812 | 2635 | set_gdbarch_deprecated_store_struct_return (gdbarch, s390_store_struct_return); |
26e9b323 | 2636 | set_gdbarch_deprecated_extract_return_value (gdbarch, s390_extract_return_value); |
ebba8386 | 2637 | set_gdbarch_deprecated_store_return_value (gdbarch, s390_store_return_value); |
aaab4dba AC |
2638 | /* Amount PC must be decremented by after a breakpoint. This is |
2639 | often the number of bytes returned by BREAKPOINT_FROM_PC but not | |
2640 | always. */ | |
5769d3cd | 2641 | set_gdbarch_decr_pc_after_break (gdbarch, 2); |
749b82f6 | 2642 | set_gdbarch_deprecated_pop_frame (gdbarch, s390_pop_frame); |
5769d3cd AC |
2643 | /* Stack grows downward. */ |
2644 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
2645 | /* Offset from address of function to start of its code. | |
2646 | Zero on most machines. */ | |
2647 | set_gdbarch_function_start_offset (gdbarch, 0); | |
a0ed5532 AC |
2648 | set_gdbarch_deprecated_max_register_raw_size (gdbarch, 8); |
2649 | set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 8); | |
5769d3cd AC |
2650 | set_gdbarch_breakpoint_from_pc (gdbarch, s390_breakpoint_from_pc); |
2651 | set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue); | |
e9582e71 | 2652 | set_gdbarch_deprecated_init_extra_frame_info (gdbarch, s390_init_extra_frame_info); |
2ca6c561 | 2653 | set_gdbarch_deprecated_init_frame_pc_first (gdbarch, s390_init_frame_pc_first); |
0ba6dca9 | 2654 | set_gdbarch_deprecated_target_read_fp (gdbarch, s390_read_fp); |
5769d3cd AC |
2655 | /* This function that tells us whether the function invocation represented |
2656 | by FI does not have a frame on the stack associated with it. If it | |
2657 | does not, FRAMELESS is set to 1, else 0. */ | |
2658 | set_gdbarch_frameless_function_invocation (gdbarch, | |
2659 | s390_frameless_function_invocation); | |
2660 | /* Return saved PC from a frame */ | |
8bedc050 | 2661 | set_gdbarch_deprecated_frame_saved_pc (gdbarch, s390_frame_saved_pc); |
618ce49f AC |
2662 | /* DEPRECATED_FRAME_CHAIN takes a frame's nominal address and |
2663 | produces the frame's chain-pointer. */ | |
2664 | set_gdbarch_deprecated_frame_chain (gdbarch, s390_frame_chain); | |
6913c89a | 2665 | set_gdbarch_deprecated_saved_pc_after_call (gdbarch, s390_saved_pc_after_call); |
9c04cab7 | 2666 | set_gdbarch_deprecated_register_byte (gdbarch, s390_register_byte); |
5769d3cd AC |
2667 | set_gdbarch_pc_regnum (gdbarch, S390_PC_REGNUM); |
2668 | set_gdbarch_sp_regnum (gdbarch, S390_SP_REGNUM); | |
0ba6dca9 | 2669 | set_gdbarch_deprecated_fp_regnum (gdbarch, S390_FP_REGNUM); |
5769d3cd AC |
2670 | set_gdbarch_fp0_regnum (gdbarch, S390_FP0_REGNUM); |
2671 | set_gdbarch_num_regs (gdbarch, S390_NUM_REGS); | |
2672 | set_gdbarch_cannot_fetch_register (gdbarch, s390_cannot_fetch_register); | |
2673 | set_gdbarch_cannot_store_register (gdbarch, s390_cannot_fetch_register); | |
c8f9d51c | 2674 | set_gdbarch_use_struct_convention (gdbarch, s390_use_struct_convention); |
5769d3cd AC |
2675 | set_gdbarch_register_name (gdbarch, s390_register_name); |
2676 | set_gdbarch_stab_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
2677 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
2678 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
26e9b323 | 2679 | set_gdbarch_deprecated_extract_struct_value_address |
c8f9d51c | 2680 | (gdbarch, generic_cannot_extract_struct_value_address); |
5769d3cd | 2681 | |
d4d0c21e | 2682 | /* Parameters for inferior function calls. */ |
ae45cd16 | 2683 | set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_at_entry_point); |
4074e13c | 2684 | set_gdbarch_frame_align (gdbarch, s390_frame_align); |
b81774d8 | 2685 | set_gdbarch_deprecated_push_arguments (gdbarch, s390_push_arguments); |
a59fe496 | 2686 | set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos); |
6e691f7a JB |
2687 | set_gdbarch_deprecated_push_return_address (gdbarch, |
2688 | s390_push_return_address); | |
b1e29e33 AC |
2689 | set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, sizeof (s390_call_dummy_words)); |
2690 | set_gdbarch_deprecated_call_dummy_words (gdbarch, s390_call_dummy_words); | |
5769d3cd AC |
2691 | |
2692 | switch (info.bfd_arch_info->mach) | |
2693 | { | |
b8b8b047 | 2694 | case bfd_mach_s390_31: |
b1e29e33 | 2695 | set_gdbarch_deprecated_register_size (gdbarch, 4); |
9c04cab7 AC |
2696 | set_gdbarch_deprecated_register_raw_size (gdbarch, s390_register_raw_size); |
2697 | set_gdbarch_deprecated_register_virtual_size (gdbarch, s390_register_raw_size); | |
2698 | set_gdbarch_deprecated_register_virtual_type (gdbarch, s390_register_virtual_type); | |
5769d3cd AC |
2699 | |
2700 | set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove); | |
b8b527c5 | 2701 | set_gdbarch_deprecated_register_bytes (gdbarch, S390_REGISTER_BYTES); |
5769d3cd | 2702 | break; |
b8b8b047 | 2703 | case bfd_mach_s390_64: |
b1e29e33 | 2704 | set_gdbarch_deprecated_register_size (gdbarch, 8); |
9c04cab7 AC |
2705 | set_gdbarch_deprecated_register_raw_size (gdbarch, s390x_register_raw_size); |
2706 | set_gdbarch_deprecated_register_virtual_size (gdbarch, s390x_register_raw_size); | |
2707 | set_gdbarch_deprecated_register_virtual_type (gdbarch, s390x_register_virtual_type); | |
5769d3cd AC |
2708 | |
2709 | set_gdbarch_long_bit (gdbarch, 64); | |
2710 | set_gdbarch_long_long_bit (gdbarch, 64); | |
2711 | set_gdbarch_ptr_bit (gdbarch, 64); | |
b8b527c5 | 2712 | set_gdbarch_deprecated_register_bytes (gdbarch, S390X_REGISTER_BYTES); |
ffc65945 KB |
2713 | set_gdbarch_address_class_type_flags (gdbarch, |
2714 | s390_address_class_type_flags); | |
2715 | set_gdbarch_address_class_type_flags_to_name (gdbarch, | |
2716 | s390_address_class_type_flags_to_name); | |
2717 | set_gdbarch_address_class_name_to_type_flags (gdbarch, | |
2718 | s390_address_class_name_to_type_flags); | |
5769d3cd AC |
2719 | break; |
2720 | } | |
2721 | ||
6c0e89ed | 2722 | /* Should be using push_dummy_call. */ |
b46e02f6 | 2723 | set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp); |
6c0e89ed | 2724 | |
5769d3cd AC |
2725 | return gdbarch; |
2726 | } | |
2727 | ||
2728 | ||
2729 | ||
a78f21af AC |
2730 | extern initialize_file_ftype _initialize_s390_tdep; /* -Wmissing-prototypes */ |
2731 | ||
5769d3cd | 2732 | void |
5ae5f592 | 2733 | _initialize_s390_tdep (void) |
5769d3cd AC |
2734 | { |
2735 | ||
2736 | /* Hook us into the gdbarch mechanism. */ | |
2737 | register_gdbarch_init (bfd_arch_s390, s390_gdbarch_init); | |
d7a27068 AC |
2738 | if (!deprecated_tm_print_insn) /* Someone may have already set it */ |
2739 | deprecated_tm_print_insn = gdb_print_insn_s390; | |
5769d3cd | 2740 | } |