Commit | Line | Data |
---|---|---|
5769d3cd AC |
1 | /* Target-dependent code for GDB, the GNU debugger. |
2 | Copyright 2001 Free Software Foundation, Inc. | |
3 | Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) | |
4 | for IBM Deutschland Entwicklung GmbH, IBM Corporation. | |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
21 | 02111-1307, USA. */ | |
22 | ||
23 | #define S390_TDEP /* for special macros in tm-s390.h */ | |
24 | #include <defs.h> | |
25 | #include "arch-utils.h" | |
26 | #include "frame.h" | |
27 | #include "inferior.h" | |
28 | #include "symtab.h" | |
29 | #include "target.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "symfile.h" | |
33 | #include "objfiles.h" | |
34 | #include "tm.h" | |
35 | #include "../bfd/bfd.h" | |
36 | #include "floatformat.h" | |
37 | #include "regcache.h" | |
fd0407d6 | 38 | #include "value.h" |
78f8b424 | 39 | #include "gdb_assert.h" |
5769d3cd AC |
40 | |
41 | ||
42 | ||
60e6cc42 | 43 | |
5769d3cd AC |
44 | /* Number of bytes of storage in the actual machine representation |
45 | for register N. | |
46 | Note that the unsigned cast here forces the result of the | |
47 | subtraction to very high positive values if N < S390_FP0_REGNUM */ | |
48 | int | |
49 | s390_register_raw_size (int reg_nr) | |
50 | { | |
51 | return ((unsigned) reg_nr - S390_FP0_REGNUM) < | |
52 | S390_NUM_FPRS ? S390_FPR_SIZE : 4; | |
53 | } | |
54 | ||
55 | int | |
56 | s390x_register_raw_size (int reg_nr) | |
57 | { | |
58 | return (reg_nr == S390_FPC_REGNUM) | |
59 | || (reg_nr >= S390_FIRST_ACR && reg_nr <= S390_LAST_ACR) ? 4 : 8; | |
60 | } | |
61 | ||
62 | int | |
63 | s390_cannot_fetch_register (int regno) | |
64 | { | |
65 | return (regno >= S390_FIRST_CR && regno < (S390_FIRST_CR + 9)) || | |
66 | (regno >= (S390_FIRST_CR + 12) && regno <= S390_LAST_CR); | |
67 | } | |
68 | ||
69 | int | |
70 | s390_register_byte (int reg_nr) | |
71 | { | |
72 | if (reg_nr <= S390_GP_LAST_REGNUM) | |
73 | return reg_nr * S390_GPR_SIZE; | |
74 | if (reg_nr <= S390_LAST_ACR) | |
75 | return S390_ACR0_OFFSET + (((reg_nr) - S390_FIRST_ACR) * S390_ACR_SIZE); | |
76 | if (reg_nr <= S390_LAST_CR) | |
77 | return S390_CR0_OFFSET + (((reg_nr) - S390_FIRST_CR) * S390_CR_SIZE); | |
78 | if (reg_nr == S390_FPC_REGNUM) | |
79 | return S390_FPC_OFFSET; | |
80 | else | |
81 | return S390_FP0_OFFSET + (((reg_nr) - S390_FP0_REGNUM) * S390_FPR_SIZE); | |
82 | } | |
83 | ||
84 | #ifndef GDBSERVER | |
85 | #define S390_MAX_INSTR_SIZE (6) | |
86 | #define S390_SYSCALL_OPCODE (0x0a) | |
87 | #define S390_SYSCALL_SIZE (2) | |
88 | #define S390_SIGCONTEXT_SREGS_OFFSET (8) | |
89 | #define S390X_SIGCONTEXT_SREGS_OFFSET (8) | |
90 | #define S390_SIGREGS_FP0_OFFSET (144) | |
91 | #define S390X_SIGREGS_FP0_OFFSET (216) | |
92 | #define S390_UC_MCONTEXT_OFFSET (256) | |
93 | #define S390X_UC_MCONTEXT_OFFSET (344) | |
94 | #define S390_STACK_FRAME_OVERHEAD (GDB_TARGET_IS_ESAME ? 160:96) | |
95 | #define S390_SIGNAL_FRAMESIZE (GDB_TARGET_IS_ESAME ? 160:96) | |
96 | #define s390_NR_sigreturn 119 | |
97 | #define s390_NR_rt_sigreturn 173 | |
98 | ||
99 | ||
100 | ||
101 | struct frame_extra_info | |
102 | { | |
103 | int initialised; | |
104 | int good_prologue; | |
105 | CORE_ADDR function_start; | |
106 | CORE_ADDR skip_prologue_function_start; | |
107 | CORE_ADDR saved_pc_valid; | |
108 | CORE_ADDR saved_pc; | |
109 | CORE_ADDR sig_fixed_saved_pc_valid; | |
110 | CORE_ADDR sig_fixed_saved_pc; | |
111 | CORE_ADDR frame_pointer_saved_pc; /* frame pointer needed for alloca */ | |
112 | CORE_ADDR stack_bought; /* amount we decrement the stack pointer by */ | |
113 | CORE_ADDR sigcontext; | |
114 | }; | |
115 | ||
116 | ||
117 | static CORE_ADDR s390_frame_saved_pc_nofix (struct frame_info *fi); | |
118 | ||
119 | int | |
120 | s390_readinstruction (bfd_byte instr[], CORE_ADDR at, | |
121 | struct disassemble_info *info) | |
122 | { | |
123 | int instrlen; | |
124 | ||
125 | static int s390_instrlen[] = { | |
126 | 2, | |
127 | 4, | |
128 | 4, | |
129 | 6 | |
130 | }; | |
131 | if ((*info->read_memory_func) (at, &instr[0], 2, info)) | |
132 | return -1; | |
133 | instrlen = s390_instrlen[instr[0] >> 6]; | |
134 | if ((*info->read_memory_func) (at + 2, &instr[2], instrlen - 2, info)) | |
135 | return -1; | |
136 | return instrlen; | |
137 | } | |
138 | ||
139 | static void | |
140 | s390_memset_extra_info (struct frame_extra_info *fextra_info) | |
141 | { | |
142 | memset (fextra_info, 0, sizeof (struct frame_extra_info)); | |
143 | } | |
144 | ||
145 | ||
146 | ||
147 | char * | |
148 | s390_register_name (int reg_nr) | |
149 | { | |
150 | static char *register_names[] = { | |
151 | "pswm", "pswa", | |
4ed90530 JB |
152 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", |
153 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", | |
5769d3cd AC |
154 | "acr0", "acr1", "acr2", "acr3", "acr4", "acr5", "acr6", "acr7", |
155 | "acr8", "acr9", "acr10", "acr11", "acr12", "acr13", "acr14", "acr15", | |
156 | "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", | |
157 | "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15", | |
158 | "fpc", | |
4ed90530 JB |
159 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", |
160 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15" | |
5769d3cd AC |
161 | }; |
162 | ||
163 | if (reg_nr >= S390_LAST_REGNUM) | |
164 | return NULL; | |
165 | return register_names[reg_nr]; | |
166 | } | |
167 | ||
168 | ||
169 | ||
170 | ||
171 | int | |
172 | s390_stab_reg_to_regnum (int regno) | |
173 | { | |
174 | return regno >= 64 ? S390_PSWM_REGNUM - 64 : | |
175 | regno >= 48 ? S390_FIRST_ACR - 48 : | |
176 | regno >= 32 ? S390_FIRST_CR - 32 : | |
177 | regno <= 15 ? (regno + 2) : | |
178 | S390_FP0_REGNUM + ((regno - 16) & 8) + (((regno - 16) & 3) << 1) + | |
179 | (((regno - 16) & 4) >> 2); | |
180 | } | |
181 | ||
182 | ||
183 | ||
184 | /* s390_get_frame_info based on Hartmuts | |
185 | prologue definition in | |
186 | gcc-2.8.1/config/l390/linux.c | |
187 | ||
188 | It reads one instruction at a time & based on whether | |
189 | it looks like prologue code or not it makes a decision on | |
190 | whether the prologue is over, there are various state machines | |
191 | in the code to determine if the prologue code is possilby valid. | |
192 | ||
193 | This is done to hopefully allow the code survive minor revs of | |
194 | calling conventions. | |
195 | ||
196 | */ | |
197 | ||
198 | int | |
199 | s390_get_frame_info (CORE_ADDR pc, struct frame_extra_info *fextra_info, | |
200 | struct frame_info *fi, int init_extra_info) | |
201 | { | |
202 | #define CONST_POOL_REGIDX 13 | |
203 | #define GOT_REGIDX 12 | |
204 | bfd_byte instr[S390_MAX_INSTR_SIZE]; | |
205 | CORE_ADDR test_pc = pc, test_pc2; | |
206 | CORE_ADDR orig_sp = 0, save_reg_addr = 0, *saved_regs = NULL; | |
207 | int valid_prologue, good_prologue = 0; | |
208 | int gprs_saved[S390_NUM_GPRS]; | |
209 | int fprs_saved[S390_NUM_FPRS]; | |
210 | int regidx, instrlen; | |
6df29de2 | 211 | int const_pool_state; |
5769d3cd AC |
212 | int frame_pointer_found, varargs_state; |
213 | int loop_cnt, gdb_gpr_store, gdb_fpr_store; | |
214 | int frame_pointer_regidx = 0xf; | |
215 | int offset, expected_offset; | |
216 | int err = 0; | |
217 | disassemble_info info; | |
8ac0e65a | 218 | |
6df29de2 JB |
219 | /* What we've seen so far regarding saving the back chain link: |
220 | 0 -- nothing yet; sp still has the same value it had at the entry | |
221 | point. Since not all functions allocate frames, this is a | |
222 | valid state for the prologue to finish in. | |
223 | 1 -- We've saved the original sp in some register other than the | |
224 | frame pointer (hard-coded to be %r11, yuck). | |
225 | save_link_regidx is the register we saved it in. | |
226 | 2 -- We've seen the initial `bras' instruction of the sequence for | |
227 | reserving more than 32k of stack: | |
228 | bras %rX, .+8 | |
229 | .long N | |
230 | s %r15, 0(%rX) | |
231 | where %rX is not the constant pool register. | |
232 | subtract_sp_regidx is %rX, and fextra_info->stack_bought is N. | |
233 | 3 -- We've reserved space for a new stack frame. This means we | |
234 | either saw a simple `ahi %r15,-N' in state 1, or the final | |
235 | `s %r15, ...' in state 2. | |
236 | 4 -- The frame and link are now fully initialized. We've | |
237 | reserved space for the new stack frame, and stored the old | |
238 | stack pointer captured in the back chain pointer field. */ | |
239 | int save_link_state; | |
240 | int save_link_regidx, subtract_sp_regidx; | |
241 | ||
8ac0e65a JB |
242 | /* What we've seen so far regarding r12 --- the GOT (Global Offset |
243 | Table) pointer. We expect to see `l %r12, N(%r13)', which loads | |
244 | r12 with the offset from the constant pool to the GOT, and then | |
245 | an `ar %r12, %r13', which adds the constant pool address, | |
246 | yielding the GOT's address. Here's what got_state means: | |
247 | 0 -- seen nothing | |
248 | 1 -- seen `l %r12, N(%r13)', but no `ar' | |
249 | 2 -- seen load and add, so GOT pointer is totally initialized | |
250 | When got_state is 1, then got_load_addr is the address of the | |
251 | load instruction, and got_load_len is the length of that | |
252 | instruction. */ | |
253 | int got_state; | |
64f9bb98 | 254 | CORE_ADDR got_load_addr = 0, got_load_len = 0; |
8ac0e65a | 255 | |
5769d3cd AC |
256 | const_pool_state = save_link_state = got_state = varargs_state = 0; |
257 | frame_pointer_found = 0; | |
258 | memset (gprs_saved, 0, sizeof (gprs_saved)); | |
259 | memset (fprs_saved, 0, sizeof (fprs_saved)); | |
260 | info.read_memory_func = dis_asm_read_memory; | |
261 | ||
262 | save_link_regidx = subtract_sp_regidx = 0; | |
263 | if (fextra_info) | |
264 | { | |
265 | if (fi && fi->frame) | |
266 | { | |
386e4208 JB |
267 | if (! init_extra_info && fextra_info->initialised) |
268 | orig_sp = fi->frame + fextra_info->stack_bought; | |
5769d3cd AC |
269 | saved_regs = fi->saved_regs; |
270 | } | |
271 | if (init_extra_info || !fextra_info->initialised) | |
272 | { | |
273 | s390_memset_extra_info (fextra_info); | |
274 | fextra_info->function_start = pc; | |
275 | fextra_info->initialised = 1; | |
276 | } | |
277 | } | |
278 | instrlen = 0; | |
279 | do | |
280 | { | |
281 | valid_prologue = 0; | |
282 | test_pc += instrlen; | |
283 | /* add the previous instruction len */ | |
284 | instrlen = s390_readinstruction (instr, test_pc, &info); | |
285 | if (instrlen < 0) | |
286 | { | |
287 | good_prologue = 0; | |
288 | err = -1; | |
289 | break; | |
290 | } | |
291 | /* We probably are in a glibc syscall */ | |
292 | if (instr[0] == S390_SYSCALL_OPCODE && test_pc == pc) | |
293 | { | |
294 | good_prologue = 1; | |
295 | if (saved_regs && fextra_info && fi->next && fi->next->extra_info | |
296 | && fi->next->extra_info->sigcontext) | |
297 | { | |
298 | /* We are backtracing from a signal handler */ | |
299 | save_reg_addr = fi->next->extra_info->sigcontext + | |
300 | REGISTER_BYTE (S390_GP0_REGNUM); | |
301 | for (regidx = 0; regidx < S390_NUM_GPRS; regidx++) | |
302 | { | |
303 | saved_regs[S390_GP0_REGNUM + regidx] = save_reg_addr; | |
304 | save_reg_addr += S390_GPR_SIZE; | |
305 | } | |
306 | save_reg_addr = fi->next->extra_info->sigcontext + | |
307 | (GDB_TARGET_IS_ESAME ? S390X_SIGREGS_FP0_OFFSET : | |
308 | S390_SIGREGS_FP0_OFFSET); | |
309 | for (regidx = 0; regidx < S390_NUM_FPRS; regidx++) | |
310 | { | |
311 | saved_regs[S390_FP0_REGNUM + regidx] = save_reg_addr; | |
312 | save_reg_addr += S390_FPR_SIZE; | |
313 | } | |
314 | } | |
315 | break; | |
316 | } | |
317 | if (save_link_state == 0) | |
318 | { | |
319 | /* check for a stack relative STMG or STM */ | |
320 | if (((GDB_TARGET_IS_ESAME && | |
321 | ((instr[0] == 0xeb) && (instr[5] == 0x24))) || | |
322 | (instr[0] == 0x90)) && ((instr[2] >> 4) == 0xf)) | |
323 | { | |
324 | regidx = (instr[1] >> 4); | |
325 | if (regidx < 6) | |
326 | varargs_state = 1; | |
327 | offset = ((instr[2] & 0xf) << 8) + instr[3]; | |
328 | expected_offset = | |
329 | S390_GPR6_STACK_OFFSET + (S390_GPR_SIZE * (regidx - 6)); | |
330 | if (offset != expected_offset) | |
331 | { | |
332 | good_prologue = 0; | |
333 | break; | |
334 | } | |
335 | if (saved_regs) | |
336 | save_reg_addr = orig_sp + offset; | |
337 | for (; regidx <= (instr[1] & 0xf); regidx++) | |
338 | { | |
339 | if (gprs_saved[regidx]) | |
340 | { | |
341 | good_prologue = 0; | |
342 | break; | |
343 | } | |
344 | good_prologue = 1; | |
345 | gprs_saved[regidx] = 1; | |
346 | if (saved_regs) | |
347 | { | |
348 | saved_regs[S390_GP0_REGNUM + regidx] = save_reg_addr; | |
349 | save_reg_addr += S390_GPR_SIZE; | |
350 | } | |
351 | } | |
352 | valid_prologue = 1; | |
353 | continue; | |
354 | } | |
355 | } | |
356 | /* check for a stack relative STG or ST */ | |
357 | if ((save_link_state == 0 || save_link_state == 3) && | |
358 | ((GDB_TARGET_IS_ESAME && | |
359 | ((instr[0] == 0xe3) && (instr[5] == 0x24))) || | |
360 | (instr[0] == 0x50)) && ((instr[2] >> 4) == 0xf)) | |
361 | { | |
362 | regidx = instr[1] >> 4; | |
363 | offset = ((instr[2] & 0xf) << 8) + instr[3]; | |
364 | if (offset == 0) | |
365 | { | |
366 | if (save_link_state == 3 && regidx == save_link_regidx) | |
367 | { | |
368 | save_link_state = 4; | |
369 | valid_prologue = 1; | |
370 | continue; | |
371 | } | |
372 | else | |
373 | break; | |
374 | } | |
375 | if (regidx < 6) | |
376 | varargs_state = 1; | |
377 | expected_offset = | |
378 | S390_GPR6_STACK_OFFSET + (S390_GPR_SIZE * (regidx - 6)); | |
379 | if (offset != expected_offset) | |
380 | { | |
381 | good_prologue = 0; | |
382 | break; | |
383 | } | |
384 | if (gprs_saved[regidx]) | |
385 | { | |
386 | good_prologue = 0; | |
387 | break; | |
388 | } | |
389 | good_prologue = 1; | |
390 | gprs_saved[regidx] = 1; | |
391 | if (saved_regs) | |
392 | { | |
393 | save_reg_addr = orig_sp + offset; | |
394 | saved_regs[S390_GP0_REGNUM + regidx] = save_reg_addr; | |
395 | } | |
396 | valid_prologue = 1; | |
397 | continue; | |
398 | } | |
399 | ||
400 | /* check for STD */ | |
401 | if (instr[0] == 0x60 && (instr[2] >> 4) == 0xf) | |
402 | { | |
403 | regidx = instr[1] >> 4; | |
404 | if (regidx == 0 || regidx == 2) | |
405 | varargs_state = 1; | |
406 | if (fprs_saved[regidx]) | |
407 | { | |
408 | good_prologue = 0; | |
409 | break; | |
410 | } | |
411 | fprs_saved[regidx] = 1; | |
412 | if (saved_regs) | |
413 | { | |
414 | save_reg_addr = orig_sp + (((instr[2] & 0xf) << 8) + instr[3]); | |
415 | saved_regs[S390_FP0_REGNUM + regidx] = save_reg_addr; | |
416 | } | |
417 | valid_prologue = 1; | |
418 | continue; | |
419 | } | |
420 | ||
421 | ||
422 | if (const_pool_state == 0) | |
423 | { | |
424 | ||
425 | if (GDB_TARGET_IS_ESAME) | |
426 | { | |
427 | /* Check for larl CONST_POOL_REGIDX,offset on ESAME */ | |
428 | if ((instr[0] == 0xc0) | |
429 | && (instr[1] == (CONST_POOL_REGIDX << 4))) | |
430 | { | |
431 | const_pool_state = 2; | |
432 | valid_prologue = 1; | |
433 | continue; | |
434 | } | |
435 | } | |
436 | else | |
437 | { | |
438 | /* Check for BASR gpr13,gpr0 used to load constant pool pointer to r13 in old compiler */ | |
439 | if (instr[0] == 0xd && (instr[1] & 0xf) == 0 | |
440 | && ((instr[1] >> 4) == CONST_POOL_REGIDX)) | |
441 | { | |
442 | const_pool_state = 1; | |
443 | valid_prologue = 1; | |
444 | continue; | |
445 | } | |
446 | } | |
447 | /* Check for new fangled bras %r13,newpc to load new constant pool */ | |
448 | /* embedded in code, older pre abi compilers also emitted this stuff. */ | |
449 | if ((instr[0] == 0xa7) && ((instr[1] & 0xf) == 0x5) && | |
450 | ((instr[1] >> 4) == CONST_POOL_REGIDX) | |
451 | && ((instr[2] & 0x80) == 0)) | |
452 | { | |
453 | const_pool_state = 2; | |
454 | test_pc += | |
455 | (((((instr[2] & 0xf) << 8) + instr[3]) << 1) - instrlen); | |
456 | valid_prologue = 1; | |
457 | continue; | |
458 | } | |
459 | } | |
460 | /* Check for AGHI or AHI CONST_POOL_REGIDX,val */ | |
461 | if (const_pool_state == 1 && (instr[0] == 0xa7) && | |
462 | ((GDB_TARGET_IS_ESAME && | |
463 | (instr[1] == ((CONST_POOL_REGIDX << 4) | 0xb))) || | |
464 | (instr[1] == ((CONST_POOL_REGIDX << 4) | 0xa)))) | |
465 | { | |
466 | const_pool_state = 2; | |
467 | valid_prologue = 1; | |
468 | continue; | |
469 | } | |
470 | /* Check for LGR or LR gprx,15 */ | |
471 | if ((GDB_TARGET_IS_ESAME && | |
472 | instr[0] == 0xb9 && instr[1] == 0x04 && (instr[3] & 0xf) == 0xf) || | |
473 | (instr[0] == 0x18 && (instr[1] & 0xf) == 0xf)) | |
474 | { | |
475 | if (GDB_TARGET_IS_ESAME) | |
476 | regidx = instr[3] >> 4; | |
477 | else | |
478 | regidx = instr[1] >> 4; | |
479 | if (save_link_state == 0 && regidx != 0xb) | |
480 | { | |
481 | /* Almost defintely code for | |
482 | decrementing the stack pointer | |
483 | ( i.e. a non leaf function | |
484 | or else leaf with locals ) */ | |
485 | save_link_regidx = regidx; | |
486 | save_link_state = 1; | |
487 | valid_prologue = 1; | |
488 | continue; | |
489 | } | |
490 | /* We use this frame pointer for alloca | |
491 | unfortunately we need to assume its gpr11 | |
492 | otherwise we would need a smarter prologue | |
493 | walker. */ | |
494 | if (!frame_pointer_found && regidx == 0xb) | |
495 | { | |
496 | frame_pointer_regidx = 0xb; | |
497 | frame_pointer_found = 1; | |
498 | if (fextra_info) | |
499 | fextra_info->frame_pointer_saved_pc = test_pc; | |
500 | valid_prologue = 1; | |
501 | continue; | |
502 | } | |
503 | } | |
504 | /* Check for AHI or AGHI gpr15,val */ | |
505 | if (save_link_state == 1 && (instr[0] == 0xa7) && | |
506 | ((GDB_TARGET_IS_ESAME && (instr[1] == 0xfb)) || (instr[1] == 0xfa))) | |
507 | { | |
508 | if (fextra_info) | |
509 | fextra_info->stack_bought = | |
510 | -extract_signed_integer (&instr[2], 2); | |
511 | save_link_state = 3; | |
512 | valid_prologue = 1; | |
513 | continue; | |
514 | } | |
515 | /* Alternatively check for the complex construction for | |
516 | buying more than 32k of stack | |
517 | BRAS gprx,.+8 | |
6df29de2 JB |
518 | long val |
519 | s %r15,0(%gprx) gprx currently r1 */ | |
5769d3cd AC |
520 | if ((save_link_state == 1) && (instr[0] == 0xa7) |
521 | && ((instr[1] & 0xf) == 0x5) && (instr[2] == 0) | |
522 | && (instr[3] == 0x4) && ((instr[1] >> 4) != CONST_POOL_REGIDX)) | |
523 | { | |
524 | subtract_sp_regidx = instr[1] >> 4; | |
525 | save_link_state = 2; | |
526 | if (fextra_info) | |
527 | target_read_memory (test_pc + instrlen, | |
528 | (char *) &fextra_info->stack_bought, | |
529 | sizeof (fextra_info->stack_bought)); | |
530 | test_pc += 4; | |
531 | valid_prologue = 1; | |
532 | continue; | |
533 | } | |
534 | if (save_link_state == 2 && instr[0] == 0x5b | |
535 | && instr[1] == 0xf0 && | |
536 | instr[2] == (subtract_sp_regidx << 4) && instr[3] == 0) | |
537 | { | |
538 | save_link_state = 3; | |
539 | valid_prologue = 1; | |
540 | continue; | |
541 | } | |
542 | /* check for LA gprx,offset(15) used for varargs */ | |
543 | if ((instr[0] == 0x41) && ((instr[2] >> 4) == 0xf) && | |
544 | ((instr[1] & 0xf) == 0)) | |
545 | { | |
546 | /* some code uses gpr7 to point to outgoing args */ | |
547 | if (((instr[1] >> 4) == 7) && (save_link_state == 0) && | |
548 | ((instr[2] & 0xf) == 0) | |
549 | && (instr[3] == S390_STACK_FRAME_OVERHEAD)) | |
550 | { | |
551 | valid_prologue = 1; | |
552 | continue; | |
553 | } | |
554 | if (varargs_state == 1) | |
555 | { | |
556 | varargs_state = 2; | |
557 | valid_prologue = 1; | |
558 | continue; | |
559 | } | |
560 | } | |
561 | /* Check for a GOT load */ | |
562 | ||
563 | if (GDB_TARGET_IS_ESAME) | |
564 | { | |
565 | /* Check for larl GOT_REGIDX, on ESAME */ | |
566 | if ((got_state == 0) && (instr[0] == 0xc0) | |
567 | && (instr[1] == (GOT_REGIDX << 4))) | |
568 | { | |
569 | got_state = 2; | |
570 | valid_prologue = 1; | |
571 | continue; | |
572 | } | |
573 | } | |
574 | else | |
575 | { | |
576 | /* check for l GOT_REGIDX,x(CONST_POOL_REGIDX) */ | |
577 | if (got_state == 0 && const_pool_state == 2 && instr[0] == 0x58 | |
578 | && (instr[2] == (CONST_POOL_REGIDX << 4)) | |
579 | && ((instr[1] >> 4) == GOT_REGIDX)) | |
580 | { | |
8ac0e65a JB |
581 | got_state = 1; |
582 | got_load_addr = test_pc; | |
583 | got_load_len = instrlen; | |
5769d3cd AC |
584 | valid_prologue = 1; |
585 | continue; | |
586 | } | |
587 | /* Check for subsequent ar got_regidx,basr_regidx */ | |
588 | if (got_state == 1 && instr[0] == 0x1a && | |
589 | instr[1] == ((GOT_REGIDX << 4) | CONST_POOL_REGIDX)) | |
590 | { | |
591 | got_state = 2; | |
592 | valid_prologue = 1; | |
593 | continue; | |
594 | } | |
595 | } | |
596 | } | |
597 | while (valid_prologue && good_prologue); | |
598 | if (good_prologue) | |
599 | { | |
8ac0e65a JB |
600 | /* If this function doesn't reference the global offset table, |
601 | then the compiler may use r12 for other things. If the last | |
602 | instruction we saw was a load of r12 from the constant pool, | |
603 | with no subsequent add to make the address PC-relative, then | |
604 | the load was probably a genuine body instruction; don't treat | |
605 | it as part of the prologue. */ | |
606 | if (got_state == 1 | |
607 | && got_load_addr + got_load_len == test_pc) | |
608 | { | |
609 | test_pc = got_load_addr; | |
610 | instrlen = got_load_len; | |
611 | } | |
612 | ||
613 | good_prologue = (((const_pool_state == 0) || (const_pool_state == 2)) && | |
5769d3cd AC |
614 | ((save_link_state == 0) || (save_link_state == 4)) && |
615 | ((varargs_state == 0) || (varargs_state == 2))); | |
616 | } | |
617 | if (fextra_info) | |
618 | { | |
619 | fextra_info->good_prologue = good_prologue; | |
620 | fextra_info->skip_prologue_function_start = | |
621 | (good_prologue ? test_pc : pc); | |
622 | } | |
09025237 JB |
623 | if (saved_regs) |
624 | /* The SP's element of the saved_regs array holds the old SP, | |
625 | not the address at which it is saved. */ | |
626 | saved_regs[S390_SP_REGNUM] = orig_sp; | |
5769d3cd AC |
627 | return err; |
628 | } | |
629 | ||
630 | ||
631 | int | |
632 | s390_check_function_end (CORE_ADDR pc) | |
633 | { | |
634 | bfd_byte instr[S390_MAX_INSTR_SIZE]; | |
635 | disassemble_info info; | |
636 | int regidx, instrlen; | |
637 | ||
638 | info.read_memory_func = dis_asm_read_memory; | |
639 | instrlen = s390_readinstruction (instr, pc, &info); | |
640 | if (instrlen < 0) | |
641 | return -1; | |
642 | /* check for BR */ | |
643 | if (instrlen != 2 || instr[0] != 07 || (instr[1] >> 4) != 0xf) | |
644 | return 0; | |
645 | regidx = instr[1] & 0xf; | |
646 | /* Check for LMG or LG */ | |
647 | instrlen = | |
648 | s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 6 : 4), &info); | |
649 | if (instrlen < 0) | |
650 | return -1; | |
651 | if (GDB_TARGET_IS_ESAME) | |
652 | { | |
653 | ||
654 | if (instrlen != 6 || instr[0] != 0xeb || instr[5] != 0x4) | |
655 | return 0; | |
656 | } | |
657 | else if (instrlen != 4 || instr[0] != 0x98) | |
658 | { | |
659 | return 0; | |
660 | } | |
661 | if ((instr[2] >> 4) != 0xf) | |
662 | return 0; | |
663 | if (regidx == 14) | |
664 | return 1; | |
665 | instrlen = s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 12 : 8), | |
666 | &info); | |
667 | if (instrlen < 0) | |
668 | return -1; | |
669 | if (GDB_TARGET_IS_ESAME) | |
670 | { | |
671 | /* Check for LG */ | |
672 | if (instrlen != 6 || instr[0] != 0xe3 || instr[5] != 0x4) | |
673 | return 0; | |
674 | } | |
675 | else | |
676 | { | |
677 | /* Check for L */ | |
678 | if (instrlen != 4 || instr[0] != 0x58) | |
679 | return 0; | |
680 | } | |
681 | if (instr[2] >> 4 != 0xf) | |
682 | return 0; | |
683 | if (instr[1] >> 4 != regidx) | |
684 | return 0; | |
685 | return 1; | |
686 | } | |
687 | ||
688 | static CORE_ADDR | |
689 | s390_sniff_pc_function_start (CORE_ADDR pc, struct frame_info *fi) | |
690 | { | |
691 | CORE_ADDR function_start, test_function_start; | |
692 | int loop_cnt, err, function_end; | |
693 | struct frame_extra_info fextra_info; | |
694 | function_start = get_pc_function_start (pc); | |
695 | ||
696 | if (function_start == 0) | |
697 | { | |
698 | test_function_start = pc; | |
699 | if (test_function_start & 1) | |
700 | return 0; /* This has to be bogus */ | |
701 | loop_cnt = 0; | |
702 | do | |
703 | { | |
704 | ||
705 | err = | |
706 | s390_get_frame_info (test_function_start, &fextra_info, fi, 1); | |
707 | loop_cnt++; | |
708 | test_function_start -= 2; | |
709 | function_end = s390_check_function_end (test_function_start); | |
710 | } | |
711 | while (!(function_end == 1 || err || loop_cnt >= 4096 || | |
712 | (fextra_info.good_prologue))); | |
713 | if (fextra_info.good_prologue) | |
714 | function_start = fextra_info.function_start; | |
715 | else if (function_end == 1) | |
716 | function_start = test_function_start; | |
717 | } | |
718 | return function_start; | |
719 | } | |
720 | ||
721 | ||
722 | ||
723 | CORE_ADDR | |
724 | s390_function_start (struct frame_info *fi) | |
725 | { | |
726 | CORE_ADDR function_start = 0; | |
727 | ||
728 | if (fi->extra_info && fi->extra_info->initialised) | |
729 | function_start = fi->extra_info->function_start; | |
730 | else if (fi->pc) | |
731 | function_start = get_pc_function_start (fi->pc); | |
732 | return function_start; | |
733 | } | |
734 | ||
735 | ||
736 | ||
737 | ||
738 | int | |
739 | s390_frameless_function_invocation (struct frame_info *fi) | |
740 | { | |
741 | struct frame_extra_info fextra_info, *fextra_info_ptr; | |
742 | int frameless = 0; | |
743 | ||
744 | if (fi->next == NULL) /* no may be frameless */ | |
745 | { | |
746 | if (fi->extra_info) | |
747 | fextra_info_ptr = fi->extra_info; | |
748 | else | |
749 | { | |
750 | fextra_info_ptr = &fextra_info; | |
751 | s390_get_frame_info (s390_sniff_pc_function_start (fi->pc, fi), | |
752 | fextra_info_ptr, fi, 1); | |
753 | } | |
754 | frameless = ((fextra_info_ptr->stack_bought == 0)); | |
755 | } | |
756 | return frameless; | |
757 | ||
758 | } | |
759 | ||
760 | ||
761 | static int | |
762 | s390_is_sigreturn (CORE_ADDR pc, struct frame_info *sighandler_fi, | |
763 | CORE_ADDR *sregs, CORE_ADDR *sigcaller_pc) | |
764 | { | |
765 | bfd_byte instr[S390_MAX_INSTR_SIZE]; | |
766 | disassemble_info info; | |
767 | int instrlen; | |
768 | CORE_ADDR scontext; | |
769 | int retval = 0; | |
770 | CORE_ADDR orig_sp; | |
771 | CORE_ADDR temp_sregs; | |
772 | ||
773 | scontext = temp_sregs = 0; | |
774 | ||
775 | info.read_memory_func = dis_asm_read_memory; | |
776 | instrlen = s390_readinstruction (instr, pc, &info); | |
777 | if (sigcaller_pc) | |
778 | *sigcaller_pc = 0; | |
779 | if (((instrlen == S390_SYSCALL_SIZE) && | |
780 | (instr[0] == S390_SYSCALL_OPCODE)) && | |
781 | ((instr[1] == s390_NR_sigreturn) || (instr[1] == s390_NR_rt_sigreturn))) | |
782 | { | |
783 | if (sighandler_fi) | |
784 | { | |
785 | if (s390_frameless_function_invocation (sighandler_fi)) | |
786 | orig_sp = sighandler_fi->frame; | |
787 | else | |
788 | orig_sp = ADDR_BITS_REMOVE ((CORE_ADDR) | |
789 | read_memory_integer (sighandler_fi-> | |
790 | frame, | |
791 | S390_GPR_SIZE)); | |
792 | if (orig_sp && sigcaller_pc) | |
793 | { | |
794 | scontext = orig_sp + S390_SIGNAL_FRAMESIZE; | |
795 | if (pc == scontext && instr[1] == s390_NR_rt_sigreturn) | |
796 | { | |
797 | /* We got a new style rt_signal */ | |
798 | /* get address of read ucontext->uc_mcontext */ | |
799 | temp_sregs = orig_sp + (GDB_TARGET_IS_ESAME ? | |
800 | S390X_UC_MCONTEXT_OFFSET : | |
801 | S390_UC_MCONTEXT_OFFSET); | |
802 | } | |
803 | else | |
804 | { | |
805 | /* read sigcontext->sregs */ | |
806 | temp_sregs = ADDR_BITS_REMOVE ((CORE_ADDR) | |
807 | read_memory_integer (scontext | |
808 | + | |
809 | (GDB_TARGET_IS_ESAME | |
810 | ? | |
811 | S390X_SIGCONTEXT_SREGS_OFFSET | |
812 | : | |
813 | S390_SIGCONTEXT_SREGS_OFFSET), | |
814 | S390_GPR_SIZE)); | |
815 | ||
816 | } | |
817 | /* read sigregs->psw.addr */ | |
818 | *sigcaller_pc = | |
819 | ADDR_BITS_REMOVE ((CORE_ADDR) | |
820 | read_memory_integer (temp_sregs + | |
821 | REGISTER_BYTE | |
822 | (S390_PC_REGNUM), | |
823 | S390_PSW_ADDR_SIZE)); | |
824 | } | |
825 | } | |
826 | retval = 1; | |
827 | } | |
828 | if (sregs) | |
829 | *sregs = temp_sregs; | |
830 | return retval; | |
831 | } | |
832 | ||
833 | /* | |
834 | We need to do something better here but this will keep us out of trouble | |
835 | for the moment. | |
836 | For some reason the blockframe.c calls us with fi->next->fromleaf | |
837 | so this seems of little use to us. */ | |
838 | void | |
839 | s390_init_frame_pc_first (int next_fromleaf, struct frame_info *fi) | |
840 | { | |
841 | CORE_ADDR sigcaller_pc; | |
842 | ||
843 | fi->pc = 0; | |
844 | if (next_fromleaf) | |
845 | { | |
846 | fi->pc = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM)); | |
847 | /* fix signal handlers */ | |
848 | } | |
849 | else if (fi->next && fi->next->pc) | |
850 | fi->pc = s390_frame_saved_pc_nofix (fi->next); | |
851 | if (fi->pc && fi->next && fi->next->frame && | |
852 | s390_is_sigreturn (fi->pc, fi->next, NULL, &sigcaller_pc)) | |
853 | { | |
854 | fi->pc = sigcaller_pc; | |
855 | } | |
856 | ||
857 | } | |
858 | ||
859 | void | |
860 | s390_init_extra_frame_info (int fromleaf, struct frame_info *fi) | |
861 | { | |
862 | fi->extra_info = frame_obstack_alloc (sizeof (struct frame_extra_info)); | |
863 | if (fi->pc) | |
864 | s390_get_frame_info (s390_sniff_pc_function_start (fi->pc, fi), | |
865 | fi->extra_info, fi, 1); | |
866 | else | |
867 | s390_memset_extra_info (fi->extra_info); | |
868 | } | |
869 | ||
870 | /* If saved registers of frame FI are not known yet, read and cache them. | |
871 | &FEXTRA_INFOP contains struct frame_extra_info; TDATAP can be NULL, | |
872 | in which case the framedata are read. */ | |
873 | ||
874 | void | |
875 | s390_frame_init_saved_regs (struct frame_info *fi) | |
876 | { | |
877 | ||
878 | int quick; | |
879 | ||
880 | if (fi->saved_regs == NULL) | |
881 | { | |
882 | /* zalloc memsets the saved regs */ | |
883 | frame_saved_regs_zalloc (fi); | |
884 | if (fi->pc) | |
885 | { | |
886 | quick = (fi->extra_info && fi->extra_info->initialised | |
887 | && fi->extra_info->good_prologue); | |
888 | s390_get_frame_info (quick ? fi->extra_info->function_start : | |
889 | s390_sniff_pc_function_start (fi->pc, fi), | |
890 | fi->extra_info, fi, !quick); | |
891 | } | |
892 | } | |
893 | } | |
894 | ||
895 | ||
896 | ||
897 | CORE_ADDR | |
898 | s390_frame_args_address (struct frame_info *fi) | |
899 | { | |
900 | ||
901 | /* Apparently gdb already knows gdb_args_offset itself */ | |
902 | return fi->frame; | |
903 | } | |
904 | ||
905 | ||
906 | static CORE_ADDR | |
907 | s390_frame_saved_pc_nofix (struct frame_info *fi) | |
908 | { | |
909 | if (fi->extra_info && fi->extra_info->saved_pc_valid) | |
910 | return fi->extra_info->saved_pc; | |
5c3cf190 JB |
911 | |
912 | if (generic_find_dummy_frame (fi->pc, fi->frame)) | |
913 | return generic_read_register_dummy (fi->pc, fi->frame, S390_PC_REGNUM); | |
914 | ||
5769d3cd AC |
915 | s390_frame_init_saved_regs (fi); |
916 | if (fi->extra_info) | |
917 | { | |
918 | fi->extra_info->saved_pc_valid = 1; | |
919 | if (fi->extra_info->good_prologue) | |
920 | { | |
921 | if (fi->saved_regs[S390_RETADDR_REGNUM]) | |
922 | { | |
923 | return (fi->extra_info->saved_pc = | |
924 | ADDR_BITS_REMOVE (read_memory_integer | |
925 | (fi->saved_regs[S390_RETADDR_REGNUM], | |
926 | S390_GPR_SIZE))); | |
927 | } | |
d0ad30c9 JB |
928 | else |
929 | return read_register (S390_RETADDR_REGNUM); | |
5769d3cd AC |
930 | } |
931 | } | |
932 | return 0; | |
933 | } | |
934 | ||
935 | CORE_ADDR | |
936 | s390_frame_saved_pc (struct frame_info *fi) | |
937 | { | |
938 | CORE_ADDR saved_pc = 0, sig_pc; | |
939 | ||
940 | if (fi->extra_info && fi->extra_info->sig_fixed_saved_pc_valid) | |
941 | return fi->extra_info->sig_fixed_saved_pc; | |
942 | saved_pc = s390_frame_saved_pc_nofix (fi); | |
943 | ||
944 | if (fi->extra_info) | |
945 | { | |
946 | fi->extra_info->sig_fixed_saved_pc_valid = 1; | |
947 | if (saved_pc) | |
948 | { | |
949 | if (s390_is_sigreturn (saved_pc, fi, NULL, &sig_pc)) | |
950 | saved_pc = sig_pc; | |
951 | } | |
952 | fi->extra_info->sig_fixed_saved_pc = saved_pc; | |
953 | } | |
954 | return saved_pc; | |
955 | } | |
956 | ||
957 | ||
958 | ||
959 | ||
960 | /* We want backtraces out of signal handlers so we don't | |
961 | set thisframe->signal_handler_caller to 1 */ | |
962 | ||
963 | CORE_ADDR | |
964 | s390_frame_chain (struct frame_info *thisframe) | |
965 | { | |
966 | CORE_ADDR prev_fp = 0; | |
967 | ||
968 | if (thisframe->prev && thisframe->prev->frame) | |
969 | prev_fp = thisframe->prev->frame; | |
5c3cf190 JB |
970 | else if (generic_find_dummy_frame (thisframe->pc, thisframe->frame)) |
971 | return generic_read_register_dummy (thisframe->pc, thisframe->frame, | |
972 | S390_SP_REGNUM); | |
5769d3cd AC |
973 | else |
974 | { | |
975 | int sigreturn = 0; | |
976 | CORE_ADDR sregs = 0; | |
977 | struct frame_extra_info prev_fextra_info; | |
978 | ||
979 | memset (&prev_fextra_info, 0, sizeof (prev_fextra_info)); | |
980 | if (thisframe->pc) | |
981 | { | |
982 | CORE_ADDR saved_pc, sig_pc; | |
983 | ||
984 | saved_pc = s390_frame_saved_pc_nofix (thisframe); | |
985 | if (saved_pc) | |
986 | { | |
987 | if ((sigreturn = | |
988 | s390_is_sigreturn (saved_pc, thisframe, &sregs, &sig_pc))) | |
989 | saved_pc = sig_pc; | |
990 | s390_get_frame_info (s390_sniff_pc_function_start | |
991 | (saved_pc, NULL), &prev_fextra_info, NULL, | |
992 | 1); | |
993 | } | |
994 | } | |
995 | if (sigreturn) | |
996 | { | |
997 | /* read sigregs,regs.gprs[11 or 15] */ | |
998 | prev_fp = read_memory_integer (sregs + | |
999 | REGISTER_BYTE (S390_GP0_REGNUM + | |
1000 | (prev_fextra_info. | |
1001 | frame_pointer_saved_pc | |
1002 | ? 11 : 15)), | |
1003 | S390_GPR_SIZE); | |
1004 | thisframe->extra_info->sigcontext = sregs; | |
1005 | } | |
1006 | else | |
1007 | { | |
1008 | if (thisframe->saved_regs) | |
1009 | { | |
5769d3cd AC |
1010 | int regno; |
1011 | ||
31c4d430 JB |
1012 | if (prev_fextra_info.frame_pointer_saved_pc |
1013 | && thisframe->saved_regs[S390_FRAME_REGNUM]) | |
1014 | regno = S390_FRAME_REGNUM; | |
1015 | else | |
1016 | regno = S390_SP_REGNUM; | |
1017 | ||
5769d3cd | 1018 | if (thisframe->saved_regs[regno]) |
31c4d430 JB |
1019 | { |
1020 | /* The SP's entry of `saved_regs' is special. */ | |
1021 | if (regno == S390_SP_REGNUM) | |
1022 | prev_fp = thisframe->saved_regs[regno]; | |
1023 | else | |
1024 | prev_fp = | |
1025 | read_memory_integer (thisframe->saved_regs[regno], | |
1026 | S390_GPR_SIZE); | |
1027 | } | |
5769d3cd AC |
1028 | } |
1029 | } | |
1030 | } | |
1031 | return ADDR_BITS_REMOVE (prev_fp); | |
1032 | } | |
1033 | ||
1034 | /* | |
1035 | Whether struct frame_extra_info is actually needed I'll have to figure | |
1036 | out as our frames are similar to rs6000 there is a possibility | |
1037 | i386 dosen't need it. */ | |
1038 | ||
1039 | ||
1040 | ||
1041 | /* a given return value in `regbuf' with a type `valtype', extract and copy its | |
1042 | value into `valbuf' */ | |
1043 | void | |
1044 | s390_extract_return_value (struct type *valtype, char *regbuf, char *valbuf) | |
1045 | { | |
1046 | /* floats and doubles are returned in fpr0. fpr's have a size of 8 bytes. | |
1047 | We need to truncate the return value into float size (4 byte) if | |
1048 | necessary. */ | |
1049 | int len = TYPE_LENGTH (valtype); | |
1050 | ||
1051 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
f2c6cfba | 1052 | memcpy (valbuf, ®buf[REGISTER_BYTE (S390_FP0_REGNUM)], len); |
5769d3cd AC |
1053 | else |
1054 | { | |
1055 | int offset = 0; | |
1056 | /* return value is copied starting from r2. */ | |
1057 | if (TYPE_LENGTH (valtype) < S390_GPR_SIZE) | |
1058 | offset = S390_GPR_SIZE - TYPE_LENGTH (valtype); | |
1059 | memcpy (valbuf, | |
1060 | regbuf + REGISTER_BYTE (S390_GP0_REGNUM + 2) + offset, | |
1061 | TYPE_LENGTH (valtype)); | |
1062 | } | |
1063 | } | |
1064 | ||
1065 | ||
1066 | static char * | |
1067 | s390_promote_integer_argument (struct type *valtype, char *valbuf, | |
1068 | char *reg_buff, int *arglen) | |
1069 | { | |
1070 | char *value = valbuf; | |
1071 | int len = TYPE_LENGTH (valtype); | |
1072 | ||
1073 | if (len < S390_GPR_SIZE) | |
1074 | { | |
1075 | /* We need to upgrade this value to a register to pass it correctly */ | |
1076 | int idx, diff = S390_GPR_SIZE - len, negative = | |
1077 | (!TYPE_UNSIGNED (valtype) && value[0] & 0x80); | |
1078 | for (idx = 0; idx < S390_GPR_SIZE; idx++) | |
1079 | { | |
1080 | reg_buff[idx] = (idx < diff ? (negative ? 0xff : 0x0) : | |
1081 | value[idx - diff]); | |
1082 | } | |
1083 | value = reg_buff; | |
1084 | *arglen = S390_GPR_SIZE; | |
1085 | } | |
1086 | else | |
1087 | { | |
1088 | if (len & (S390_GPR_SIZE - 1)) | |
1089 | { | |
1090 | fprintf_unfiltered (gdb_stderr, | |
1091 | "s390_promote_integer_argument detected an argument not " | |
1092 | "a multiple of S390_GPR_SIZE & greater than S390_GPR_SIZE " | |
1093 | "we might not deal with this correctly.\n"); | |
1094 | } | |
1095 | *arglen = len; | |
1096 | } | |
1097 | ||
1098 | return (value); | |
1099 | } | |
1100 | ||
1101 | void | |
1102 | s390_store_return_value (struct type *valtype, char *valbuf) | |
1103 | { | |
1104 | int arglen; | |
1105 | char *reg_buff = alloca (max (S390_FPR_SIZE, REGISTER_SIZE)), *value; | |
1106 | ||
1107 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
1108 | { | |
1109 | DOUBLEST tempfloat = extract_floating (valbuf, TYPE_LENGTH (valtype)); | |
1110 | ||
1111 | floatformat_from_doublest (&floatformat_ieee_double_big, &tempfloat, | |
1112 | reg_buff); | |
1113 | write_register_bytes (REGISTER_BYTE (S390_FP0_REGNUM), reg_buff, | |
1114 | S390_FPR_SIZE); | |
1115 | } | |
1116 | else | |
1117 | { | |
1118 | value = | |
1119 | s390_promote_integer_argument (valtype, valbuf, reg_buff, &arglen); | |
1120 | /* Everything else is returned in GPR2 and up. */ | |
1121 | write_register_bytes (REGISTER_BYTE (S390_GP0_REGNUM + 2), value, | |
1122 | arglen); | |
1123 | } | |
1124 | } | |
1125 | static int | |
1126 | gdb_print_insn_s390 (bfd_vma memaddr, disassemble_info * info) | |
1127 | { | |
1128 | bfd_byte instrbuff[S390_MAX_INSTR_SIZE]; | |
1129 | int instrlen, cnt; | |
1130 | ||
1131 | instrlen = s390_readinstruction (instrbuff, (CORE_ADDR) memaddr, info); | |
1132 | if (instrlen < 0) | |
1133 | { | |
1134 | (*info->memory_error_func) (instrlen, memaddr, info); | |
1135 | return -1; | |
1136 | } | |
1137 | for (cnt = 0; cnt < instrlen; cnt++) | |
1138 | info->fprintf_func (info->stream, "%02X ", instrbuff[cnt]); | |
1139 | for (cnt = instrlen; cnt < S390_MAX_INSTR_SIZE; cnt++) | |
1140 | info->fprintf_func (info->stream, " "); | |
1141 | instrlen = print_insn_s390 (memaddr, info); | |
1142 | return instrlen; | |
1143 | } | |
1144 | ||
1145 | ||
1146 | ||
1147 | /* Not the most efficent code in the world */ | |
1148 | int | |
1149 | s390_fp_regnum () | |
1150 | { | |
1151 | int regno = S390_SP_REGNUM; | |
1152 | struct frame_extra_info fextra_info; | |
1153 | ||
1154 | CORE_ADDR pc = ADDR_BITS_REMOVE (read_register (S390_PC_REGNUM)); | |
1155 | ||
1156 | s390_get_frame_info (s390_sniff_pc_function_start (pc, NULL), &fextra_info, | |
1157 | NULL, 1); | |
1158 | if (fextra_info.frame_pointer_saved_pc) | |
1159 | regno = S390_FRAME_REGNUM; | |
1160 | return regno; | |
1161 | } | |
1162 | ||
1163 | CORE_ADDR | |
1164 | s390_read_fp () | |
1165 | { | |
1166 | return read_register (s390_fp_regnum ()); | |
1167 | } | |
1168 | ||
1169 | ||
1170 | void | |
1171 | s390_write_fp (CORE_ADDR val) | |
1172 | { | |
1173 | write_register (s390_fp_regnum (), val); | |
1174 | } | |
1175 | ||
1176 | ||
4c8287ac JB |
1177 | static void |
1178 | s390_pop_frame_regular (struct frame_info *frame) | |
5769d3cd | 1179 | { |
4c8287ac JB |
1180 | int regnum; |
1181 | ||
1182 | write_register (S390_PC_REGNUM, FRAME_SAVED_PC (frame)); | |
1183 | ||
1184 | /* Restore any saved registers. */ | |
1185 | for (regnum = 0; regnum < NUM_REGS; regnum++) | |
1186 | if (frame->saved_regs[regnum] != 0) | |
1187 | { | |
1188 | ULONGEST value; | |
1189 | ||
1190 | value = read_memory_unsigned_integer (frame->saved_regs[regnum], | |
1191 | REGISTER_RAW_SIZE (regnum)); | |
1192 | write_register (regnum, value); | |
1193 | } | |
5769d3cd | 1194 | |
9a1befc9 JB |
1195 | /* Actually cut back the stack. Remember that the SP's element of |
1196 | saved_regs is the old SP itself, not the address at which it is | |
1197 | saved. */ | |
1198 | write_register (S390_SP_REGNUM, frame->saved_regs[S390_SP_REGNUM]); | |
5769d3cd | 1199 | |
4c8287ac JB |
1200 | /* Throw away any cached frame information. */ |
1201 | flush_cached_frames (); | |
5769d3cd AC |
1202 | } |
1203 | ||
4c8287ac JB |
1204 | |
1205 | /* Destroy the innermost (Top-Of-Stack) stack frame, restoring the | |
1206 | machine state that was in effect before the frame was created. | |
1207 | Used in the contexts of the "return" command, and of | |
1208 | target function calls from the debugger. */ | |
1209 | void | |
1210 | s390_pop_frame () | |
1211 | { | |
1212 | /* This function checks for and handles generic dummy frames, and | |
1213 | calls back to our function for ordinary frames. */ | |
1214 | generic_pop_current_frame (s390_pop_frame_regular); | |
1215 | } | |
1216 | ||
1217 | ||
78f8b424 JB |
1218 | /* Return non-zero if TYPE is an integer-like type, zero otherwise. |
1219 | "Integer-like" types are those that should be passed the way | |
1220 | integers are: integers, enums, ranges, characters, and booleans. */ | |
1221 | static int | |
1222 | is_integer_like (struct type *type) | |
1223 | { | |
1224 | enum type_code code = TYPE_CODE (type); | |
1225 | ||
1226 | return (code == TYPE_CODE_INT | |
1227 | || code == TYPE_CODE_ENUM | |
1228 | || code == TYPE_CODE_RANGE | |
1229 | || code == TYPE_CODE_CHAR | |
1230 | || code == TYPE_CODE_BOOL); | |
1231 | } | |
1232 | ||
1233 | ||
1234 | /* Return non-zero if TYPE is a pointer-like type, zero otherwise. | |
1235 | "Pointer-like" types are those that should be passed the way | |
1236 | pointers are: pointers and references. */ | |
1237 | static int | |
1238 | is_pointer_like (struct type *type) | |
1239 | { | |
1240 | enum type_code code = TYPE_CODE (type); | |
1241 | ||
1242 | return (code == TYPE_CODE_PTR | |
1243 | || code == TYPE_CODE_REF); | |
1244 | } | |
1245 | ||
1246 | ||
20a940cc JB |
1247 | /* Return non-zero if TYPE is a `float singleton' or `double |
1248 | singleton', zero otherwise. | |
1249 | ||
1250 | A `T singleton' is a struct type with one member, whose type is | |
1251 | either T or a `T singleton'. So, the following are all float | |
1252 | singletons: | |
1253 | ||
1254 | struct { float x }; | |
1255 | struct { struct { float x; } x; }; | |
1256 | struct { struct { struct { float x; } x; } x; }; | |
1257 | ||
1258 | ... and so on. | |
1259 | ||
1260 | WHY THE HECK DO WE CARE ABOUT THIS??? Well, it turns out that GCC | |
1261 | passes all float singletons and double singletons as if they were | |
1262 | simply floats or doubles. This is *not* what the ABI says it | |
1263 | should do. */ | |
1264 | static int | |
1265 | is_float_singleton (struct type *type) | |
1266 | { | |
1267 | return (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1268 | && TYPE_NFIELDS (type) == 1 | |
1269 | && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_FLT | |
1270 | || is_float_singleton (TYPE_FIELD_TYPE (type, 0)))); | |
1271 | } | |
1272 | ||
1273 | ||
1274 | /* Return non-zero if TYPE is a struct-like type, zero otherwise. | |
1275 | "Struct-like" types are those that should be passed as structs are: | |
1276 | structs and unions. | |
1277 | ||
1278 | As an odd quirk, not mentioned in the ABI, GCC passes float and | |
1279 | double singletons as if they were a plain float, double, etc. (The | |
1280 | corresponding union types are handled normally.) So we exclude | |
1281 | those types here. *shrug* */ | |
1282 | static int | |
1283 | is_struct_like (struct type *type) | |
1284 | { | |
1285 | enum type_code code = TYPE_CODE (type); | |
1286 | ||
1287 | return (code == TYPE_CODE_UNION | |
1288 | || (code == TYPE_CODE_STRUCT && ! is_float_singleton (type))); | |
1289 | } | |
1290 | ||
1291 | ||
1292 | /* Return non-zero if TYPE is a float-like type, zero otherwise. | |
1293 | "Float-like" types are those that should be passed as | |
1294 | floating-point values are. | |
1295 | ||
1296 | You'd think this would just be floats, doubles, long doubles, etc. | |
1297 | But as an odd quirk, not mentioned in the ABI, GCC passes float and | |
1298 | double singletons as if they were a plain float, double, etc. (The | |
1299 | corresponding union types are handled normally.) So we exclude | |
1300 | those types here. *shrug* */ | |
1301 | static int | |
1302 | is_float_like (struct type *type) | |
1303 | { | |
1304 | return (TYPE_CODE (type) == TYPE_CODE_FLT | |
1305 | || is_float_singleton (type)); | |
1306 | } | |
1307 | ||
1308 | ||
78f8b424 JB |
1309 | /* Return non-zero if TYPE is considered a `DOUBLE_OR_FLOAT', as |
1310 | defined by the parameter passing conventions described in the | |
1311 | "Linux for S/390 ELF Application Binary Interface Supplement". | |
1312 | Otherwise, return zero. */ | |
1313 | static int | |
1314 | is_double_or_float (struct type *type) | |
1315 | { | |
20a940cc | 1316 | return (is_float_like (type) |
78f8b424 JB |
1317 | && (TYPE_LENGTH (type) == 4 |
1318 | || TYPE_LENGTH (type) == 8)); | |
1319 | } | |
1320 | ||
5769d3cd | 1321 | |
78f8b424 JB |
1322 | /* Return non-zero if TYPE is considered a `SIMPLE_ARG', as defined by |
1323 | the parameter passing conventions described in the "Linux for S/390 | |
1324 | ELF Application Binary Interface Supplement". Return zero otherwise. */ | |
1325 | static int | |
1326 | is_simple_arg (struct type *type) | |
1327 | { | |
78f8b424 JB |
1328 | unsigned length = TYPE_LENGTH (type); |
1329 | ||
a1677dfb JB |
1330 | /* This is almost a direct translation of the ABI's language, except |
1331 | that we have to exclude 8-byte structs; those are DOUBLE_ARGs. */ | |
78f8b424 JB |
1332 | return ((is_integer_like (type) && length <= 4) |
1333 | || is_pointer_like (type) | |
20a940cc JB |
1334 | || (is_struct_like (type) && length != 8) |
1335 | || (is_float_like (type) && length == 16)); | |
78f8b424 JB |
1336 | } |
1337 | ||
1338 | ||
1339 | /* Return non-zero if TYPE should be passed as a pointer to a copy, | |
1340 | zero otherwise. TYPE must be a SIMPLE_ARG, as recognized by | |
1341 | `is_simple_arg'. */ | |
1342 | static int | |
1343 | pass_by_copy_ref (struct type *type) | |
1344 | { | |
78f8b424 JB |
1345 | unsigned length = TYPE_LENGTH (type); |
1346 | ||
20a940cc JB |
1347 | return ((is_struct_like (type) && length != 1 && length != 2 && length != 4) |
1348 | || (is_float_like (type) && length == 16)); | |
78f8b424 JB |
1349 | } |
1350 | ||
1351 | ||
1352 | /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full | |
1353 | word as required for the ABI. */ | |
1354 | static LONGEST | |
1355 | extend_simple_arg (struct value *arg) | |
1356 | { | |
1357 | struct type *type = VALUE_TYPE (arg); | |
1358 | ||
1359 | /* Even structs get passed in the least significant bits of the | |
1360 | register / memory word. It's not really right to extract them as | |
1361 | an integer, but it does take care of the extension. */ | |
1362 | if (TYPE_UNSIGNED (type)) | |
1363 | return extract_unsigned_integer (VALUE_CONTENTS (arg), | |
1364 | TYPE_LENGTH (type)); | |
1365 | else | |
1366 | return extract_signed_integer (VALUE_CONTENTS (arg), | |
1367 | TYPE_LENGTH (type)); | |
1368 | } | |
1369 | ||
1370 | ||
1371 | /* Return non-zero if TYPE is a `DOUBLE_ARG', as defined by the | |
1372 | parameter passing conventions described in the "Linux for S/390 ELF | |
1373 | Application Binary Interface Supplement". Return zero otherwise. */ | |
1374 | static int | |
1375 | is_double_arg (struct type *type) | |
1376 | { | |
78f8b424 JB |
1377 | unsigned length = TYPE_LENGTH (type); |
1378 | ||
1379 | return ((is_integer_like (type) | |
20a940cc | 1380 | || is_struct_like (type)) |
78f8b424 JB |
1381 | && length == 8); |
1382 | } | |
1383 | ||
1384 | ||
1385 | /* Round ADDR up to the next N-byte boundary. N must be a power of | |
1386 | two. */ | |
1387 | static CORE_ADDR | |
1388 | round_up (CORE_ADDR addr, int n) | |
1389 | { | |
1390 | /* Check that N is really a power of two. */ | |
1391 | gdb_assert (n && (n & (n-1)) == 0); | |
1392 | return ((addr + n - 1) & -n); | |
1393 | } | |
1394 | ||
1395 | ||
1396 | /* Round ADDR down to the next N-byte boundary. N must be a power of | |
1397 | two. */ | |
1398 | static CORE_ADDR | |
1399 | round_down (CORE_ADDR addr, int n) | |
1400 | { | |
1401 | /* Check that N is really a power of two. */ | |
1402 | gdb_assert (n && (n & (n-1)) == 0); | |
1403 | return (addr & -n); | |
1404 | } | |
1405 | ||
1406 | ||
1407 | /* Return the alignment required by TYPE. */ | |
1408 | static int | |
1409 | alignment_of (struct type *type) | |
1410 | { | |
1411 | int alignment; | |
1412 | ||
1413 | if (is_integer_like (type) | |
1414 | || is_pointer_like (type) | |
1415 | || TYPE_CODE (type) == TYPE_CODE_FLT) | |
1416 | alignment = TYPE_LENGTH (type); | |
1417 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1418 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
1419 | { | |
1420 | int i; | |
1421 | ||
1422 | alignment = 1; | |
1423 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
1424 | { | |
1425 | int field_alignment = alignment_of (TYPE_FIELD_TYPE (type, i)); | |
1426 | ||
1427 | if (field_alignment > alignment) | |
1428 | alignment = field_alignment; | |
1429 | } | |
1430 | } | |
1431 | else | |
1432 | alignment = 1; | |
1433 | ||
1434 | /* Check that everything we ever return is a power of two. Lots of | |
1435 | code doesn't want to deal with aligning things to arbitrary | |
1436 | boundaries. */ | |
1437 | gdb_assert ((alignment & (alignment - 1)) == 0); | |
1438 | ||
1439 | return alignment; | |
1440 | } | |
1441 | ||
1442 | ||
1443 | /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in | |
1444 | place to be passed to a function, as specified by the "Linux for | |
1445 | S/390 ELF Application Binary Interface Supplement". | |
1446 | ||
1447 | SP is the current stack pointer. We must put arguments, links, | |
1448 | padding, etc. whereever they belong, and return the new stack | |
1449 | pointer value. | |
1450 | ||
1451 | If STRUCT_RETURN is non-zero, then the function we're calling is | |
1452 | going to return a structure by value; STRUCT_ADDR is the address of | |
1453 | a block we've allocated for it on the stack. | |
1454 | ||
1455 | Our caller has taken care of any type promotions needed to satisfy | |
1456 | prototypes or the old K&R argument-passing rules. */ | |
5769d3cd | 1457 | CORE_ADDR |
d45fc520 | 1458 | s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp, |
5769d3cd AC |
1459 | int struct_return, CORE_ADDR struct_addr) |
1460 | { | |
78f8b424 JB |
1461 | int i; |
1462 | int pointer_size = (TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
5769d3cd | 1463 | |
78f8b424 JB |
1464 | /* The number of arguments passed by reference-to-copy. */ |
1465 | int num_copies; | |
5769d3cd | 1466 | |
78f8b424 JB |
1467 | /* If the i'th argument is passed as a reference to a copy, then |
1468 | copy_addr[i] is the address of the copy we made. */ | |
1469 | CORE_ADDR *copy_addr = alloca (nargs * sizeof (CORE_ADDR)); | |
5769d3cd | 1470 | |
78f8b424 JB |
1471 | /* Build the reference-to-copy area. */ |
1472 | num_copies = 0; | |
1473 | for (i = 0; i < nargs; i++) | |
1474 | { | |
1475 | struct value *arg = args[i]; | |
1476 | struct type *type = VALUE_TYPE (arg); | |
1477 | unsigned length = TYPE_LENGTH (type); | |
5769d3cd | 1478 | |
78f8b424 JB |
1479 | if (is_simple_arg (type) |
1480 | && pass_by_copy_ref (type)) | |
01c464e9 | 1481 | { |
78f8b424 JB |
1482 | sp -= length; |
1483 | sp = round_down (sp, alignment_of (type)); | |
1484 | write_memory (sp, VALUE_CONTENTS (arg), length); | |
1485 | copy_addr[i] = sp; | |
1486 | num_copies++; | |
01c464e9 | 1487 | } |
5769d3cd | 1488 | } |
5769d3cd | 1489 | |
78f8b424 JB |
1490 | /* Reserve space for the parameter area. As a conservative |
1491 | simplification, we assume that everything will be passed on the | |
1492 | stack. */ | |
1493 | { | |
1494 | int i; | |
1495 | ||
1496 | for (i = 0; i < nargs; i++) | |
1497 | { | |
1498 | struct value *arg = args[i]; | |
1499 | struct type *type = VALUE_TYPE (arg); | |
1500 | int length = TYPE_LENGTH (type); | |
1501 | ||
1502 | sp = round_down (sp, alignment_of (type)); | |
1503 | ||
1504 | /* SIMPLE_ARG values get extended to 32 bits. Assume every | |
1505 | argument is. */ | |
1506 | if (length < 4) length = 4; | |
1507 | sp -= length; | |
1508 | } | |
1509 | } | |
1510 | ||
1511 | /* Include space for any reference-to-copy pointers. */ | |
1512 | sp = round_down (sp, pointer_size); | |
1513 | sp -= num_copies * pointer_size; | |
1514 | ||
1515 | /* After all that, make sure it's still aligned on an eight-byte | |
1516 | boundary. */ | |
1517 | sp = round_down (sp, 8); | |
1518 | ||
1519 | /* Finally, place the actual parameters, working from SP towards | |
1520 | higher addresses. The code above is supposed to reserve enough | |
1521 | space for this. */ | |
1522 | { | |
1523 | int fr = 0; | |
1524 | int gr = 2; | |
1525 | CORE_ADDR starg = sp; | |
1526 | ||
1527 | for (i = 0; i < nargs; i++) | |
1528 | { | |
1529 | struct value *arg = args[i]; | |
1530 | struct type *type = VALUE_TYPE (arg); | |
1531 | ||
1532 | if (is_double_or_float (type) | |
1533 | && fr <= 2) | |
1534 | { | |
1535 | /* When we store a single-precision value in an FP register, | |
1536 | it occupies the leftmost bits. */ | |
1537 | write_register_bytes (REGISTER_BYTE (S390_FP0_REGNUM + fr), | |
1538 | VALUE_CONTENTS (arg), | |
1539 | TYPE_LENGTH (type)); | |
1540 | fr += 2; | |
1541 | } | |
1542 | else if (is_simple_arg (type) | |
1543 | && gr <= 6) | |
1544 | { | |
1545 | /* Do we need to pass a pointer to our copy of this | |
1546 | argument? */ | |
1547 | if (pass_by_copy_ref (type)) | |
1548 | write_register (S390_GP0_REGNUM + gr, copy_addr[i]); | |
1549 | else | |
1550 | write_register (S390_GP0_REGNUM + gr, extend_simple_arg (arg)); | |
1551 | ||
1552 | gr++; | |
1553 | } | |
1554 | else if (is_double_arg (type) | |
1555 | && gr <= 5) | |
1556 | { | |
1557 | write_register_gen (S390_GP0_REGNUM + gr, | |
1558 | VALUE_CONTENTS (arg)); | |
1559 | write_register_gen (S390_GP0_REGNUM + gr + 1, | |
1560 | VALUE_CONTENTS (arg) + 4); | |
1561 | gr += 2; | |
1562 | } | |
1563 | else | |
1564 | { | |
1565 | /* The `OTHER' case. */ | |
1566 | enum type_code code = TYPE_CODE (type); | |
1567 | unsigned length = TYPE_LENGTH (type); | |
1568 | ||
1569 | /* If we skipped r6 because we couldn't fit a DOUBLE_ARG | |
1570 | in it, then don't go back and use it again later. */ | |
1571 | if (is_double_arg (type) && gr == 6) | |
1572 | gr = 7; | |
1573 | ||
1574 | if (is_simple_arg (type)) | |
1575 | { | |
1576 | /* Simple args are always either extended to 32 bits, | |
1577 | or pointers. */ | |
1578 | starg = round_up (starg, 4); | |
1579 | ||
1580 | /* Do we need to pass a pointer to our copy of this | |
1581 | argument? */ | |
1582 | if (pass_by_copy_ref (type)) | |
1583 | write_memory_signed_integer (starg, pointer_size, | |
1584 | copy_addr[i]); | |
1585 | else | |
1586 | /* Simple args are always extended to 32 bits. */ | |
1587 | write_memory_signed_integer (starg, 4, | |
1588 | extend_simple_arg (arg)); | |
1589 | starg += 4; | |
1590 | } | |
1591 | else | |
1592 | { | |
20a940cc JB |
1593 | /* You'd think we should say: |
1594 | starg = round_up (starg, alignment_of (type)); | |
1595 | Unfortunately, GCC seems to simply align the stack on | |
1596 | a four-byte boundary, even when passing doubles. */ | |
1597 | starg = round_up (starg, 4); | |
78f8b424 JB |
1598 | write_memory (starg, VALUE_CONTENTS (arg), length); |
1599 | starg += length; | |
1600 | } | |
1601 | } | |
1602 | } | |
1603 | } | |
1604 | ||
1605 | /* Allocate the standard frame areas: the register save area, the | |
1606 | word reserved for the compiler (which seems kind of meaningless), | |
1607 | and the back chain pointer. */ | |
1608 | sp -= 96; | |
1609 | ||
1610 | /* Write the back chain pointer into the first word of the stack | |
1611 | frame. This will help us get backtraces from within functions | |
1612 | called from GDB. */ | |
1613 | write_memory_unsigned_integer (sp, (TARGET_PTR_BIT / TARGET_CHAR_BIT), | |
1614 | read_fp ()); | |
1615 | ||
1616 | return sp; | |
5769d3cd AC |
1617 | } |
1618 | ||
c8f9d51c JB |
1619 | |
1620 | static int | |
1621 | s390_use_struct_convention (int gcc_p, struct type *value_type) | |
1622 | { | |
1623 | enum type_code code = TYPE_CODE (value_type); | |
1624 | ||
1625 | return (code == TYPE_CODE_STRUCT | |
1626 | || code == TYPE_CODE_UNION); | |
1627 | } | |
1628 | ||
1629 | ||
5769d3cd AC |
1630 | /* Return the GDB type object for the "standard" data type |
1631 | of data in register N. */ | |
1632 | struct type * | |
1633 | s390_register_virtual_type (int regno) | |
1634 | { | |
1635 | return ((unsigned) regno - S390_FPC_REGNUM) < | |
1636 | S390_NUM_FPRS ? builtin_type_double : builtin_type_int; | |
1637 | } | |
1638 | ||
1639 | ||
1640 | struct type * | |
1641 | s390x_register_virtual_type (int regno) | |
1642 | { | |
1643 | return (regno == S390_FPC_REGNUM) || | |
1644 | (regno >= S390_FIRST_ACR && regno <= S390_LAST_ACR) ? builtin_type_int : | |
1645 | (regno >= S390_FP0_REGNUM) ? builtin_type_double : builtin_type_long; | |
1646 | } | |
1647 | ||
1648 | ||
1649 | ||
1650 | void | |
1651 | s390_store_struct_return (CORE_ADDR addr, CORE_ADDR sp) | |
1652 | { | |
1653 | write_register (S390_GP0_REGNUM + 2, addr); | |
1654 | } | |
1655 | ||
1656 | ||
1657 | ||
1658 | static unsigned char * | |
1659 | s390_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) | |
1660 | { | |
1661 | static unsigned char breakpoint[] = { 0x0, 0x1 }; | |
1662 | ||
1663 | *lenptr = sizeof (breakpoint); | |
1664 | return breakpoint; | |
1665 | } | |
1666 | ||
1667 | /* Advance PC across any function entry prologue instructions to reach some | |
1668 | "real" code. */ | |
1669 | CORE_ADDR | |
1670 | s390_skip_prologue (CORE_ADDR pc) | |
1671 | { | |
1672 | struct frame_extra_info fextra_info; | |
1673 | ||
1674 | s390_get_frame_info (pc, &fextra_info, NULL, 1); | |
1675 | return fextra_info.skip_prologue_function_start; | |
1676 | } | |
1677 | ||
5769d3cd AC |
1678 | /* Immediately after a function call, return the saved pc. |
1679 | Can't go through the frames for this because on some machines | |
1680 | the new frame is not set up until the new function executes | |
1681 | some instructions. */ | |
1682 | CORE_ADDR | |
1683 | s390_saved_pc_after_call (struct frame_info *frame) | |
1684 | { | |
1685 | return ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM)); | |
1686 | } | |
1687 | ||
1688 | static CORE_ADDR | |
1689 | s390_addr_bits_remove (CORE_ADDR addr) | |
1690 | { | |
1691 | return (addr) & 0x7fffffff; | |
1692 | } | |
1693 | ||
1694 | ||
1695 | static CORE_ADDR | |
1696 | s390_push_return_address (CORE_ADDR pc, CORE_ADDR sp) | |
1697 | { | |
d4d0c21e | 1698 | write_register (S390_RETADDR_REGNUM, CALL_DUMMY_ADDRESS ()); |
5769d3cd AC |
1699 | return sp; |
1700 | } | |
1701 | ||
1702 | struct gdbarch * | |
1703 | s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
1704 | { | |
d4d0c21e | 1705 | static LONGEST s390_call_dummy_words[] = { 0 }; |
5769d3cd AC |
1706 | struct gdbarch *gdbarch; |
1707 | struct gdbarch_tdep *tdep; | |
1708 | int elf_flags; | |
1709 | ||
1710 | /* First see if there is already a gdbarch that can satisfy the request. */ | |
1711 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
1712 | if (arches != NULL) | |
1713 | return arches->gdbarch; | |
1714 | ||
1715 | /* None found: is the request for a s390 architecture? */ | |
1716 | if (info.bfd_arch_info->arch != bfd_arch_s390) | |
1717 | return NULL; /* No; then it's not for us. */ | |
1718 | ||
1719 | /* Yes: create a new gdbarch for the specified machine type. */ | |
1720 | gdbarch = gdbarch_alloc (&info, NULL); | |
1721 | ||
1722 | set_gdbarch_believe_pcc_promotion (gdbarch, 0); | |
1723 | ||
5769d3cd AC |
1724 | set_gdbarch_frame_args_skip (gdbarch, 0); |
1725 | set_gdbarch_frame_args_address (gdbarch, s390_frame_args_address); | |
1726 | set_gdbarch_frame_chain (gdbarch, s390_frame_chain); | |
1727 | set_gdbarch_frame_init_saved_regs (gdbarch, s390_frame_init_saved_regs); | |
1728 | set_gdbarch_frame_locals_address (gdbarch, s390_frame_args_address); | |
1729 | /* We can't do this */ | |
1730 | set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown); | |
1731 | set_gdbarch_store_struct_return (gdbarch, s390_store_struct_return); | |
1732 | set_gdbarch_extract_return_value (gdbarch, s390_extract_return_value); | |
1733 | set_gdbarch_store_return_value (gdbarch, s390_store_return_value); | |
1734 | /* Amount PC must be decremented by after a breakpoint. | |
1735 | This is often the number of bytes in BREAKPOINT | |
1736 | but not always. */ | |
1737 | set_gdbarch_decr_pc_after_break (gdbarch, 2); | |
1738 | set_gdbarch_pop_frame (gdbarch, s390_pop_frame); | |
5769d3cd AC |
1739 | set_gdbarch_ieee_float (gdbarch, 1); |
1740 | /* Stack grows downward. */ | |
1741 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
1742 | /* Offset from address of function to start of its code. | |
1743 | Zero on most machines. */ | |
1744 | set_gdbarch_function_start_offset (gdbarch, 0); | |
1745 | set_gdbarch_max_register_raw_size (gdbarch, 8); | |
1746 | set_gdbarch_max_register_virtual_size (gdbarch, 8); | |
1747 | set_gdbarch_breakpoint_from_pc (gdbarch, s390_breakpoint_from_pc); | |
1748 | set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue); | |
1749 | set_gdbarch_init_extra_frame_info (gdbarch, s390_init_extra_frame_info); | |
1750 | set_gdbarch_init_frame_pc_first (gdbarch, s390_init_frame_pc_first); | |
1751 | set_gdbarch_read_fp (gdbarch, s390_read_fp); | |
1752 | set_gdbarch_write_fp (gdbarch, s390_write_fp); | |
1753 | /* This function that tells us whether the function invocation represented | |
1754 | by FI does not have a frame on the stack associated with it. If it | |
1755 | does not, FRAMELESS is set to 1, else 0. */ | |
1756 | set_gdbarch_frameless_function_invocation (gdbarch, | |
1757 | s390_frameless_function_invocation); | |
1758 | /* Return saved PC from a frame */ | |
1759 | set_gdbarch_frame_saved_pc (gdbarch, s390_frame_saved_pc); | |
1760 | /* FRAME_CHAIN takes a frame's nominal address | |
1761 | and produces the frame's chain-pointer. */ | |
1762 | set_gdbarch_frame_chain (gdbarch, s390_frame_chain); | |
1763 | set_gdbarch_saved_pc_after_call (gdbarch, s390_saved_pc_after_call); | |
1764 | set_gdbarch_register_byte (gdbarch, s390_register_byte); | |
1765 | set_gdbarch_pc_regnum (gdbarch, S390_PC_REGNUM); | |
1766 | set_gdbarch_sp_regnum (gdbarch, S390_SP_REGNUM); | |
1767 | set_gdbarch_fp_regnum (gdbarch, S390_FP_REGNUM); | |
1768 | set_gdbarch_fp0_regnum (gdbarch, S390_FP0_REGNUM); | |
1769 | set_gdbarch_num_regs (gdbarch, S390_NUM_REGS); | |
1770 | set_gdbarch_cannot_fetch_register (gdbarch, s390_cannot_fetch_register); | |
1771 | set_gdbarch_cannot_store_register (gdbarch, s390_cannot_fetch_register); | |
1772 | set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register); | |
c8f9d51c | 1773 | set_gdbarch_use_struct_convention (gdbarch, s390_use_struct_convention); |
8001d1e4 | 1774 | set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); |
5769d3cd AC |
1775 | set_gdbarch_register_name (gdbarch, s390_register_name); |
1776 | set_gdbarch_stab_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
1777 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
1778 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
c8f9d51c JB |
1779 | set_gdbarch_extract_struct_value_address |
1780 | (gdbarch, generic_cannot_extract_struct_value_address); | |
5769d3cd | 1781 | |
d4d0c21e | 1782 | /* Parameters for inferior function calls. */ |
5769d3cd | 1783 | set_gdbarch_call_dummy_p (gdbarch, 1); |
d4d0c21e JB |
1784 | set_gdbarch_use_generic_dummy_frames (gdbarch, 1); |
1785 | set_gdbarch_call_dummy_length (gdbarch, 0); | |
1786 | set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT); | |
1787 | set_gdbarch_call_dummy_address (gdbarch, entry_point_address); | |
1788 | set_gdbarch_call_dummy_start_offset (gdbarch, 0); | |
1789 | set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_at_entry_point); | |
1790 | set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame); | |
1791 | set_gdbarch_push_arguments (gdbarch, s390_push_arguments); | |
5c3cf190 | 1792 | set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos); |
d4d0c21e JB |
1793 | set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1); |
1794 | set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0); | |
5769d3cd | 1795 | set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0); |
d4d0c21e | 1796 | set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy); |
5769d3cd | 1797 | set_gdbarch_push_return_address (gdbarch, s390_push_return_address); |
d4d0c21e JB |
1798 | set_gdbarch_sizeof_call_dummy_words (gdbarch, |
1799 | sizeof (s390_call_dummy_words)); | |
1800 | set_gdbarch_call_dummy_words (gdbarch, s390_call_dummy_words); | |
0adb2aba JB |
1801 | set_gdbarch_coerce_float_to_double (gdbarch, |
1802 | standard_coerce_float_to_double); | |
5769d3cd AC |
1803 | |
1804 | switch (info.bfd_arch_info->mach) | |
1805 | { | |
1806 | case bfd_mach_s390_esa: | |
1807 | set_gdbarch_register_size (gdbarch, 4); | |
5769d3cd AC |
1808 | set_gdbarch_register_raw_size (gdbarch, s390_register_raw_size); |
1809 | set_gdbarch_register_virtual_size (gdbarch, s390_register_raw_size); | |
1810 | set_gdbarch_register_virtual_type (gdbarch, s390_register_virtual_type); | |
1811 | ||
1812 | set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove); | |
5769d3cd AC |
1813 | set_gdbarch_register_bytes (gdbarch, S390_REGISTER_BYTES); |
1814 | break; | |
1815 | case bfd_mach_s390_esame: | |
1816 | set_gdbarch_register_size (gdbarch, 8); | |
5769d3cd AC |
1817 | set_gdbarch_register_raw_size (gdbarch, s390x_register_raw_size); |
1818 | set_gdbarch_register_virtual_size (gdbarch, s390x_register_raw_size); | |
1819 | set_gdbarch_register_virtual_type (gdbarch, | |
1820 | s390x_register_virtual_type); | |
1821 | ||
1822 | set_gdbarch_long_bit (gdbarch, 64); | |
1823 | set_gdbarch_long_long_bit (gdbarch, 64); | |
1824 | set_gdbarch_ptr_bit (gdbarch, 64); | |
5769d3cd AC |
1825 | set_gdbarch_register_bytes (gdbarch, S390X_REGISTER_BYTES); |
1826 | break; | |
1827 | } | |
1828 | ||
1829 | return gdbarch; | |
1830 | } | |
1831 | ||
1832 | ||
1833 | ||
1834 | void | |
1835 | _initialize_s390_tdep () | |
1836 | { | |
1837 | ||
1838 | /* Hook us into the gdbarch mechanism. */ | |
1839 | register_gdbarch_init (bfd_arch_s390, s390_gdbarch_init); | |
1840 | if (!tm_print_insn) /* Someone may have already set it */ | |
1841 | tm_print_insn = gdb_print_insn_s390; | |
1842 | } | |
1843 | ||
1844 | #endif /* GDBSERVER */ |