]>
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 ([email protected],[email protected]) | |
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" |
5769d3cd AC |
39 | |
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", | |
152 | "gpr0", "gpr1", "gpr2", "gpr3", "gpr4", "gpr5", "gpr6", "gpr7", | |
153 | "gpr8", "gpr9", "gpr10", "gpr11", "gpr12", "gpr13", "gpr14", "gpr15", | |
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", | |
159 | "fpr0", "fpr1", "fpr2", "fpr3", "fpr4", "fpr5", "fpr6", "fpr7", | |
160 | "fpr8", "fpr9", "fpr10", "fpr11", "fpr12", "fpr13", "fpr14", "fpr15" | |
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; | |
211 | int save_link_regidx, subtract_sp_regidx; | |
8ac0e65a | 212 | int const_pool_state, save_link_state; |
5769d3cd AC |
213 | int frame_pointer_found, varargs_state; |
214 | int loop_cnt, gdb_gpr_store, gdb_fpr_store; | |
215 | int frame_pointer_regidx = 0xf; | |
216 | int offset, expected_offset; | |
217 | int err = 0; | |
218 | disassemble_info info; | |
8ac0e65a JB |
219 | |
220 | /* What we've seen so far regarding r12 --- the GOT (Global Offset | |
221 | Table) pointer. We expect to see `l %r12, N(%r13)', which loads | |
222 | r12 with the offset from the constant pool to the GOT, and then | |
223 | an `ar %r12, %r13', which adds the constant pool address, | |
224 | yielding the GOT's address. Here's what got_state means: | |
225 | 0 -- seen nothing | |
226 | 1 -- seen `l %r12, N(%r13)', but no `ar' | |
227 | 2 -- seen load and add, so GOT pointer is totally initialized | |
228 | When got_state is 1, then got_load_addr is the address of the | |
229 | load instruction, and got_load_len is the length of that | |
230 | instruction. */ | |
231 | int got_state; | |
232 | CORE_ADDR got_load_addr, got_load_len; | |
233 | ||
5769d3cd AC |
234 | const_pool_state = save_link_state = got_state = varargs_state = 0; |
235 | frame_pointer_found = 0; | |
236 | memset (gprs_saved, 0, sizeof (gprs_saved)); | |
237 | memset (fprs_saved, 0, sizeof (fprs_saved)); | |
238 | info.read_memory_func = dis_asm_read_memory; | |
239 | ||
240 | save_link_regidx = subtract_sp_regidx = 0; | |
241 | if (fextra_info) | |
242 | { | |
243 | if (fi && fi->frame) | |
244 | { | |
245 | orig_sp = fi->frame + fextra_info->stack_bought; | |
246 | saved_regs = fi->saved_regs; | |
247 | } | |
248 | if (init_extra_info || !fextra_info->initialised) | |
249 | { | |
250 | s390_memset_extra_info (fextra_info); | |
251 | fextra_info->function_start = pc; | |
252 | fextra_info->initialised = 1; | |
253 | } | |
254 | } | |
255 | instrlen = 0; | |
256 | do | |
257 | { | |
258 | valid_prologue = 0; | |
259 | test_pc += instrlen; | |
260 | /* add the previous instruction len */ | |
261 | instrlen = s390_readinstruction (instr, test_pc, &info); | |
262 | if (instrlen < 0) | |
263 | { | |
264 | good_prologue = 0; | |
265 | err = -1; | |
266 | break; | |
267 | } | |
268 | /* We probably are in a glibc syscall */ | |
269 | if (instr[0] == S390_SYSCALL_OPCODE && test_pc == pc) | |
270 | { | |
271 | good_prologue = 1; | |
272 | if (saved_regs && fextra_info && fi->next && fi->next->extra_info | |
273 | && fi->next->extra_info->sigcontext) | |
274 | { | |
275 | /* We are backtracing from a signal handler */ | |
276 | save_reg_addr = fi->next->extra_info->sigcontext + | |
277 | REGISTER_BYTE (S390_GP0_REGNUM); | |
278 | for (regidx = 0; regidx < S390_NUM_GPRS; regidx++) | |
279 | { | |
280 | saved_regs[S390_GP0_REGNUM + regidx] = save_reg_addr; | |
281 | save_reg_addr += S390_GPR_SIZE; | |
282 | } | |
283 | save_reg_addr = fi->next->extra_info->sigcontext + | |
284 | (GDB_TARGET_IS_ESAME ? S390X_SIGREGS_FP0_OFFSET : | |
285 | S390_SIGREGS_FP0_OFFSET); | |
286 | for (regidx = 0; regidx < S390_NUM_FPRS; regidx++) | |
287 | { | |
288 | saved_regs[S390_FP0_REGNUM + regidx] = save_reg_addr; | |
289 | save_reg_addr += S390_FPR_SIZE; | |
290 | } | |
291 | } | |
292 | break; | |
293 | } | |
294 | if (save_link_state == 0) | |
295 | { | |
296 | /* check for a stack relative STMG or STM */ | |
297 | if (((GDB_TARGET_IS_ESAME && | |
298 | ((instr[0] == 0xeb) && (instr[5] == 0x24))) || | |
299 | (instr[0] == 0x90)) && ((instr[2] >> 4) == 0xf)) | |
300 | { | |
301 | regidx = (instr[1] >> 4); | |
302 | if (regidx < 6) | |
303 | varargs_state = 1; | |
304 | offset = ((instr[2] & 0xf) << 8) + instr[3]; | |
305 | expected_offset = | |
306 | S390_GPR6_STACK_OFFSET + (S390_GPR_SIZE * (regidx - 6)); | |
307 | if (offset != expected_offset) | |
308 | { | |
309 | good_prologue = 0; | |
310 | break; | |
311 | } | |
312 | if (saved_regs) | |
313 | save_reg_addr = orig_sp + offset; | |
314 | for (; regidx <= (instr[1] & 0xf); regidx++) | |
315 | { | |
316 | if (gprs_saved[regidx]) | |
317 | { | |
318 | good_prologue = 0; | |
319 | break; | |
320 | } | |
321 | good_prologue = 1; | |
322 | gprs_saved[regidx] = 1; | |
323 | if (saved_regs) | |
324 | { | |
325 | saved_regs[S390_GP0_REGNUM + regidx] = save_reg_addr; | |
326 | save_reg_addr += S390_GPR_SIZE; | |
327 | } | |
328 | } | |
329 | valid_prologue = 1; | |
330 | continue; | |
331 | } | |
332 | } | |
333 | /* check for a stack relative STG or ST */ | |
334 | if ((save_link_state == 0 || save_link_state == 3) && | |
335 | ((GDB_TARGET_IS_ESAME && | |
336 | ((instr[0] == 0xe3) && (instr[5] == 0x24))) || | |
337 | (instr[0] == 0x50)) && ((instr[2] >> 4) == 0xf)) | |
338 | { | |
339 | regidx = instr[1] >> 4; | |
340 | offset = ((instr[2] & 0xf) << 8) + instr[3]; | |
341 | if (offset == 0) | |
342 | { | |
343 | if (save_link_state == 3 && regidx == save_link_regidx) | |
344 | { | |
345 | save_link_state = 4; | |
346 | valid_prologue = 1; | |
347 | continue; | |
348 | } | |
349 | else | |
350 | break; | |
351 | } | |
352 | if (regidx < 6) | |
353 | varargs_state = 1; | |
354 | expected_offset = | |
355 | S390_GPR6_STACK_OFFSET + (S390_GPR_SIZE * (regidx - 6)); | |
356 | if (offset != expected_offset) | |
357 | { | |
358 | good_prologue = 0; | |
359 | break; | |
360 | } | |
361 | if (gprs_saved[regidx]) | |
362 | { | |
363 | good_prologue = 0; | |
364 | break; | |
365 | } | |
366 | good_prologue = 1; | |
367 | gprs_saved[regidx] = 1; | |
368 | if (saved_regs) | |
369 | { | |
370 | save_reg_addr = orig_sp + offset; | |
371 | saved_regs[S390_GP0_REGNUM + regidx] = save_reg_addr; | |
372 | } | |
373 | valid_prologue = 1; | |
374 | continue; | |
375 | } | |
376 | ||
377 | /* check for STD */ | |
378 | if (instr[0] == 0x60 && (instr[2] >> 4) == 0xf) | |
379 | { | |
380 | regidx = instr[1] >> 4; | |
381 | if (regidx == 0 || regidx == 2) | |
382 | varargs_state = 1; | |
383 | if (fprs_saved[regidx]) | |
384 | { | |
385 | good_prologue = 0; | |
386 | break; | |
387 | } | |
388 | fprs_saved[regidx] = 1; | |
389 | if (saved_regs) | |
390 | { | |
391 | save_reg_addr = orig_sp + (((instr[2] & 0xf) << 8) + instr[3]); | |
392 | saved_regs[S390_FP0_REGNUM + regidx] = save_reg_addr; | |
393 | } | |
394 | valid_prologue = 1; | |
395 | continue; | |
396 | } | |
397 | ||
398 | ||
399 | if (const_pool_state == 0) | |
400 | { | |
401 | ||
402 | if (GDB_TARGET_IS_ESAME) | |
403 | { | |
404 | /* Check for larl CONST_POOL_REGIDX,offset on ESAME */ | |
405 | if ((instr[0] == 0xc0) | |
406 | && (instr[1] == (CONST_POOL_REGIDX << 4))) | |
407 | { | |
408 | const_pool_state = 2; | |
409 | valid_prologue = 1; | |
410 | continue; | |
411 | } | |
412 | } | |
413 | else | |
414 | { | |
415 | /* Check for BASR gpr13,gpr0 used to load constant pool pointer to r13 in old compiler */ | |
416 | if (instr[0] == 0xd && (instr[1] & 0xf) == 0 | |
417 | && ((instr[1] >> 4) == CONST_POOL_REGIDX)) | |
418 | { | |
419 | const_pool_state = 1; | |
420 | valid_prologue = 1; | |
421 | continue; | |
422 | } | |
423 | } | |
424 | /* Check for new fangled bras %r13,newpc to load new constant pool */ | |
425 | /* embedded in code, older pre abi compilers also emitted this stuff. */ | |
426 | if ((instr[0] == 0xa7) && ((instr[1] & 0xf) == 0x5) && | |
427 | ((instr[1] >> 4) == CONST_POOL_REGIDX) | |
428 | && ((instr[2] & 0x80) == 0)) | |
429 | { | |
430 | const_pool_state = 2; | |
431 | test_pc += | |
432 | (((((instr[2] & 0xf) << 8) + instr[3]) << 1) - instrlen); | |
433 | valid_prologue = 1; | |
434 | continue; | |
435 | } | |
436 | } | |
437 | /* Check for AGHI or AHI CONST_POOL_REGIDX,val */ | |
438 | if (const_pool_state == 1 && (instr[0] == 0xa7) && | |
439 | ((GDB_TARGET_IS_ESAME && | |
440 | (instr[1] == ((CONST_POOL_REGIDX << 4) | 0xb))) || | |
441 | (instr[1] == ((CONST_POOL_REGIDX << 4) | 0xa)))) | |
442 | { | |
443 | const_pool_state = 2; | |
444 | valid_prologue = 1; | |
445 | continue; | |
446 | } | |
447 | /* Check for LGR or LR gprx,15 */ | |
448 | if ((GDB_TARGET_IS_ESAME && | |
449 | instr[0] == 0xb9 && instr[1] == 0x04 && (instr[3] & 0xf) == 0xf) || | |
450 | (instr[0] == 0x18 && (instr[1] & 0xf) == 0xf)) | |
451 | { | |
452 | if (GDB_TARGET_IS_ESAME) | |
453 | regidx = instr[3] >> 4; | |
454 | else | |
455 | regidx = instr[1] >> 4; | |
456 | if (save_link_state == 0 && regidx != 0xb) | |
457 | { | |
458 | /* Almost defintely code for | |
459 | decrementing the stack pointer | |
460 | ( i.e. a non leaf function | |
461 | or else leaf with locals ) */ | |
462 | save_link_regidx = regidx; | |
463 | save_link_state = 1; | |
464 | valid_prologue = 1; | |
465 | continue; | |
466 | } | |
467 | /* We use this frame pointer for alloca | |
468 | unfortunately we need to assume its gpr11 | |
469 | otherwise we would need a smarter prologue | |
470 | walker. */ | |
471 | if (!frame_pointer_found && regidx == 0xb) | |
472 | { | |
473 | frame_pointer_regidx = 0xb; | |
474 | frame_pointer_found = 1; | |
475 | if (fextra_info) | |
476 | fextra_info->frame_pointer_saved_pc = test_pc; | |
477 | valid_prologue = 1; | |
478 | continue; | |
479 | } | |
480 | } | |
481 | /* Check for AHI or AGHI gpr15,val */ | |
482 | if (save_link_state == 1 && (instr[0] == 0xa7) && | |
483 | ((GDB_TARGET_IS_ESAME && (instr[1] == 0xfb)) || (instr[1] == 0xfa))) | |
484 | { | |
485 | if (fextra_info) | |
486 | fextra_info->stack_bought = | |
487 | -extract_signed_integer (&instr[2], 2); | |
488 | save_link_state = 3; | |
489 | valid_prologue = 1; | |
490 | continue; | |
491 | } | |
492 | /* Alternatively check for the complex construction for | |
493 | buying more than 32k of stack | |
494 | BRAS gprx,.+8 | |
495 | long vals %r15,0(%gprx) gprx currently r1 */ | |
496 | if ((save_link_state == 1) && (instr[0] == 0xa7) | |
497 | && ((instr[1] & 0xf) == 0x5) && (instr[2] == 0) | |
498 | && (instr[3] == 0x4) && ((instr[1] >> 4) != CONST_POOL_REGIDX)) | |
499 | { | |
500 | subtract_sp_regidx = instr[1] >> 4; | |
501 | save_link_state = 2; | |
502 | if (fextra_info) | |
503 | target_read_memory (test_pc + instrlen, | |
504 | (char *) &fextra_info->stack_bought, | |
505 | sizeof (fextra_info->stack_bought)); | |
506 | test_pc += 4; | |
507 | valid_prologue = 1; | |
508 | continue; | |
509 | } | |
510 | if (save_link_state == 2 && instr[0] == 0x5b | |
511 | && instr[1] == 0xf0 && | |
512 | instr[2] == (subtract_sp_regidx << 4) && instr[3] == 0) | |
513 | { | |
514 | save_link_state = 3; | |
515 | valid_prologue = 1; | |
516 | continue; | |
517 | } | |
518 | /* check for LA gprx,offset(15) used for varargs */ | |
519 | if ((instr[0] == 0x41) && ((instr[2] >> 4) == 0xf) && | |
520 | ((instr[1] & 0xf) == 0)) | |
521 | { | |
522 | /* some code uses gpr7 to point to outgoing args */ | |
523 | if (((instr[1] >> 4) == 7) && (save_link_state == 0) && | |
524 | ((instr[2] & 0xf) == 0) | |
525 | && (instr[3] == S390_STACK_FRAME_OVERHEAD)) | |
526 | { | |
527 | valid_prologue = 1; | |
528 | continue; | |
529 | } | |
530 | if (varargs_state == 1) | |
531 | { | |
532 | varargs_state = 2; | |
533 | valid_prologue = 1; | |
534 | continue; | |
535 | } | |
536 | } | |
537 | /* Check for a GOT load */ | |
538 | ||
539 | if (GDB_TARGET_IS_ESAME) | |
540 | { | |
541 | /* Check for larl GOT_REGIDX, on ESAME */ | |
542 | if ((got_state == 0) && (instr[0] == 0xc0) | |
543 | && (instr[1] == (GOT_REGIDX << 4))) | |
544 | { | |
545 | got_state = 2; | |
546 | valid_prologue = 1; | |
547 | continue; | |
548 | } | |
549 | } | |
550 | else | |
551 | { | |
552 | /* check for l GOT_REGIDX,x(CONST_POOL_REGIDX) */ | |
553 | if (got_state == 0 && const_pool_state == 2 && instr[0] == 0x58 | |
554 | && (instr[2] == (CONST_POOL_REGIDX << 4)) | |
555 | && ((instr[1] >> 4) == GOT_REGIDX)) | |
556 | { | |
8ac0e65a JB |
557 | got_state = 1; |
558 | got_load_addr = test_pc; | |
559 | got_load_len = instrlen; | |
5769d3cd AC |
560 | valid_prologue = 1; |
561 | continue; | |
562 | } | |
563 | /* Check for subsequent ar got_regidx,basr_regidx */ | |
564 | if (got_state == 1 && instr[0] == 0x1a && | |
565 | instr[1] == ((GOT_REGIDX << 4) | CONST_POOL_REGIDX)) | |
566 | { | |
567 | got_state = 2; | |
568 | valid_prologue = 1; | |
569 | continue; | |
570 | } | |
571 | } | |
572 | } | |
573 | while (valid_prologue && good_prologue); | |
574 | if (good_prologue) | |
575 | { | |
8ac0e65a JB |
576 | /* If this function doesn't reference the global offset table, |
577 | then the compiler may use r12 for other things. If the last | |
578 | instruction we saw was a load of r12 from the constant pool, | |
579 | with no subsequent add to make the address PC-relative, then | |
580 | the load was probably a genuine body instruction; don't treat | |
581 | it as part of the prologue. */ | |
582 | if (got_state == 1 | |
583 | && got_load_addr + got_load_len == test_pc) | |
584 | { | |
585 | test_pc = got_load_addr; | |
586 | instrlen = got_load_len; | |
587 | } | |
588 | ||
589 | good_prologue = (((const_pool_state == 0) || (const_pool_state == 2)) && | |
5769d3cd AC |
590 | ((save_link_state == 0) || (save_link_state == 4)) && |
591 | ((varargs_state == 0) || (varargs_state == 2))); | |
592 | } | |
593 | if (fextra_info) | |
594 | { | |
595 | fextra_info->good_prologue = good_prologue; | |
596 | fextra_info->skip_prologue_function_start = | |
597 | (good_prologue ? test_pc : pc); | |
598 | } | |
599 | return err; | |
600 | } | |
601 | ||
602 | ||
603 | int | |
604 | s390_check_function_end (CORE_ADDR pc) | |
605 | { | |
606 | bfd_byte instr[S390_MAX_INSTR_SIZE]; | |
607 | disassemble_info info; | |
608 | int regidx, instrlen; | |
609 | ||
610 | info.read_memory_func = dis_asm_read_memory; | |
611 | instrlen = s390_readinstruction (instr, pc, &info); | |
612 | if (instrlen < 0) | |
613 | return -1; | |
614 | /* check for BR */ | |
615 | if (instrlen != 2 || instr[0] != 07 || (instr[1] >> 4) != 0xf) | |
616 | return 0; | |
617 | regidx = instr[1] & 0xf; | |
618 | /* Check for LMG or LG */ | |
619 | instrlen = | |
620 | s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 6 : 4), &info); | |
621 | if (instrlen < 0) | |
622 | return -1; | |
623 | if (GDB_TARGET_IS_ESAME) | |
624 | { | |
625 | ||
626 | if (instrlen != 6 || instr[0] != 0xeb || instr[5] != 0x4) | |
627 | return 0; | |
628 | } | |
629 | else if (instrlen != 4 || instr[0] != 0x98) | |
630 | { | |
631 | return 0; | |
632 | } | |
633 | if ((instr[2] >> 4) != 0xf) | |
634 | return 0; | |
635 | if (regidx == 14) | |
636 | return 1; | |
637 | instrlen = s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 12 : 8), | |
638 | &info); | |
639 | if (instrlen < 0) | |
640 | return -1; | |
641 | if (GDB_TARGET_IS_ESAME) | |
642 | { | |
643 | /* Check for LG */ | |
644 | if (instrlen != 6 || instr[0] != 0xe3 || instr[5] != 0x4) | |
645 | return 0; | |
646 | } | |
647 | else | |
648 | { | |
649 | /* Check for L */ | |
650 | if (instrlen != 4 || instr[0] != 0x58) | |
651 | return 0; | |
652 | } | |
653 | if (instr[2] >> 4 != 0xf) | |
654 | return 0; | |
655 | if (instr[1] >> 4 != regidx) | |
656 | return 0; | |
657 | return 1; | |
658 | } | |
659 | ||
660 | static CORE_ADDR | |
661 | s390_sniff_pc_function_start (CORE_ADDR pc, struct frame_info *fi) | |
662 | { | |
663 | CORE_ADDR function_start, test_function_start; | |
664 | int loop_cnt, err, function_end; | |
665 | struct frame_extra_info fextra_info; | |
666 | function_start = get_pc_function_start (pc); | |
667 | ||
668 | if (function_start == 0) | |
669 | { | |
670 | test_function_start = pc; | |
671 | if (test_function_start & 1) | |
672 | return 0; /* This has to be bogus */ | |
673 | loop_cnt = 0; | |
674 | do | |
675 | { | |
676 | ||
677 | err = | |
678 | s390_get_frame_info (test_function_start, &fextra_info, fi, 1); | |
679 | loop_cnt++; | |
680 | test_function_start -= 2; | |
681 | function_end = s390_check_function_end (test_function_start); | |
682 | } | |
683 | while (!(function_end == 1 || err || loop_cnt >= 4096 || | |
684 | (fextra_info.good_prologue))); | |
685 | if (fextra_info.good_prologue) | |
686 | function_start = fextra_info.function_start; | |
687 | else if (function_end == 1) | |
688 | function_start = test_function_start; | |
689 | } | |
690 | return function_start; | |
691 | } | |
692 | ||
693 | ||
694 | ||
695 | CORE_ADDR | |
696 | s390_function_start (struct frame_info *fi) | |
697 | { | |
698 | CORE_ADDR function_start = 0; | |
699 | ||
700 | if (fi->extra_info && fi->extra_info->initialised) | |
701 | function_start = fi->extra_info->function_start; | |
702 | else if (fi->pc) | |
703 | function_start = get_pc_function_start (fi->pc); | |
704 | return function_start; | |
705 | } | |
706 | ||
707 | ||
708 | ||
709 | ||
710 | int | |
711 | s390_frameless_function_invocation (struct frame_info *fi) | |
712 | { | |
713 | struct frame_extra_info fextra_info, *fextra_info_ptr; | |
714 | int frameless = 0; | |
715 | ||
716 | if (fi->next == NULL) /* no may be frameless */ | |
717 | { | |
718 | if (fi->extra_info) | |
719 | fextra_info_ptr = fi->extra_info; | |
720 | else | |
721 | { | |
722 | fextra_info_ptr = &fextra_info; | |
723 | s390_get_frame_info (s390_sniff_pc_function_start (fi->pc, fi), | |
724 | fextra_info_ptr, fi, 1); | |
725 | } | |
726 | frameless = ((fextra_info_ptr->stack_bought == 0)); | |
727 | } | |
728 | return frameless; | |
729 | ||
730 | } | |
731 | ||
732 | ||
733 | static int | |
734 | s390_is_sigreturn (CORE_ADDR pc, struct frame_info *sighandler_fi, | |
735 | CORE_ADDR *sregs, CORE_ADDR *sigcaller_pc) | |
736 | { | |
737 | bfd_byte instr[S390_MAX_INSTR_SIZE]; | |
738 | disassemble_info info; | |
739 | int instrlen; | |
740 | CORE_ADDR scontext; | |
741 | int retval = 0; | |
742 | CORE_ADDR orig_sp; | |
743 | CORE_ADDR temp_sregs; | |
744 | ||
745 | scontext = temp_sregs = 0; | |
746 | ||
747 | info.read_memory_func = dis_asm_read_memory; | |
748 | instrlen = s390_readinstruction (instr, pc, &info); | |
749 | if (sigcaller_pc) | |
750 | *sigcaller_pc = 0; | |
751 | if (((instrlen == S390_SYSCALL_SIZE) && | |
752 | (instr[0] == S390_SYSCALL_OPCODE)) && | |
753 | ((instr[1] == s390_NR_sigreturn) || (instr[1] == s390_NR_rt_sigreturn))) | |
754 | { | |
755 | if (sighandler_fi) | |
756 | { | |
757 | if (s390_frameless_function_invocation (sighandler_fi)) | |
758 | orig_sp = sighandler_fi->frame; | |
759 | else | |
760 | orig_sp = ADDR_BITS_REMOVE ((CORE_ADDR) | |
761 | read_memory_integer (sighandler_fi-> | |
762 | frame, | |
763 | S390_GPR_SIZE)); | |
764 | if (orig_sp && sigcaller_pc) | |
765 | { | |
766 | scontext = orig_sp + S390_SIGNAL_FRAMESIZE; | |
767 | if (pc == scontext && instr[1] == s390_NR_rt_sigreturn) | |
768 | { | |
769 | /* We got a new style rt_signal */ | |
770 | /* get address of read ucontext->uc_mcontext */ | |
771 | temp_sregs = orig_sp + (GDB_TARGET_IS_ESAME ? | |
772 | S390X_UC_MCONTEXT_OFFSET : | |
773 | S390_UC_MCONTEXT_OFFSET); | |
774 | } | |
775 | else | |
776 | { | |
777 | /* read sigcontext->sregs */ | |
778 | temp_sregs = ADDR_BITS_REMOVE ((CORE_ADDR) | |
779 | read_memory_integer (scontext | |
780 | + | |
781 | (GDB_TARGET_IS_ESAME | |
782 | ? | |
783 | S390X_SIGCONTEXT_SREGS_OFFSET | |
784 | : | |
785 | S390_SIGCONTEXT_SREGS_OFFSET), | |
786 | S390_GPR_SIZE)); | |
787 | ||
788 | } | |
789 | /* read sigregs->psw.addr */ | |
790 | *sigcaller_pc = | |
791 | ADDR_BITS_REMOVE ((CORE_ADDR) | |
792 | read_memory_integer (temp_sregs + | |
793 | REGISTER_BYTE | |
794 | (S390_PC_REGNUM), | |
795 | S390_PSW_ADDR_SIZE)); | |
796 | } | |
797 | } | |
798 | retval = 1; | |
799 | } | |
800 | if (sregs) | |
801 | *sregs = temp_sregs; | |
802 | return retval; | |
803 | } | |
804 | ||
805 | /* | |
806 | We need to do something better here but this will keep us out of trouble | |
807 | for the moment. | |
808 | For some reason the blockframe.c calls us with fi->next->fromleaf | |
809 | so this seems of little use to us. */ | |
810 | void | |
811 | s390_init_frame_pc_first (int next_fromleaf, struct frame_info *fi) | |
812 | { | |
813 | CORE_ADDR sigcaller_pc; | |
814 | ||
815 | fi->pc = 0; | |
816 | if (next_fromleaf) | |
817 | { | |
818 | fi->pc = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM)); | |
819 | /* fix signal handlers */ | |
820 | } | |
821 | else if (fi->next && fi->next->pc) | |
822 | fi->pc = s390_frame_saved_pc_nofix (fi->next); | |
823 | if (fi->pc && fi->next && fi->next->frame && | |
824 | s390_is_sigreturn (fi->pc, fi->next, NULL, &sigcaller_pc)) | |
825 | { | |
826 | fi->pc = sigcaller_pc; | |
827 | } | |
828 | ||
829 | } | |
830 | ||
831 | void | |
832 | s390_init_extra_frame_info (int fromleaf, struct frame_info *fi) | |
833 | { | |
834 | fi->extra_info = frame_obstack_alloc (sizeof (struct frame_extra_info)); | |
835 | if (fi->pc) | |
836 | s390_get_frame_info (s390_sniff_pc_function_start (fi->pc, fi), | |
837 | fi->extra_info, fi, 1); | |
838 | else | |
839 | s390_memset_extra_info (fi->extra_info); | |
840 | } | |
841 | ||
842 | /* If saved registers of frame FI are not known yet, read and cache them. | |
843 | &FEXTRA_INFOP contains struct frame_extra_info; TDATAP can be NULL, | |
844 | in which case the framedata are read. */ | |
845 | ||
846 | void | |
847 | s390_frame_init_saved_regs (struct frame_info *fi) | |
848 | { | |
849 | ||
850 | int quick; | |
851 | ||
852 | if (fi->saved_regs == NULL) | |
853 | { | |
854 | /* zalloc memsets the saved regs */ | |
855 | frame_saved_regs_zalloc (fi); | |
856 | if (fi->pc) | |
857 | { | |
858 | quick = (fi->extra_info && fi->extra_info->initialised | |
859 | && fi->extra_info->good_prologue); | |
860 | s390_get_frame_info (quick ? fi->extra_info->function_start : | |
861 | s390_sniff_pc_function_start (fi->pc, fi), | |
862 | fi->extra_info, fi, !quick); | |
863 | } | |
864 | } | |
865 | } | |
866 | ||
867 | ||
868 | ||
869 | CORE_ADDR | |
870 | s390_frame_args_address (struct frame_info *fi) | |
871 | { | |
872 | ||
873 | /* Apparently gdb already knows gdb_args_offset itself */ | |
874 | return fi->frame; | |
875 | } | |
876 | ||
877 | ||
878 | static CORE_ADDR | |
879 | s390_frame_saved_pc_nofix (struct frame_info *fi) | |
880 | { | |
881 | if (fi->extra_info && fi->extra_info->saved_pc_valid) | |
882 | return fi->extra_info->saved_pc; | |
883 | s390_frame_init_saved_regs (fi); | |
884 | if (fi->extra_info) | |
885 | { | |
886 | fi->extra_info->saved_pc_valid = 1; | |
887 | if (fi->extra_info->good_prologue) | |
888 | { | |
889 | if (fi->saved_regs[S390_RETADDR_REGNUM]) | |
890 | { | |
891 | return (fi->extra_info->saved_pc = | |
892 | ADDR_BITS_REMOVE (read_memory_integer | |
893 | (fi->saved_regs[S390_RETADDR_REGNUM], | |
894 | S390_GPR_SIZE))); | |
895 | } | |
896 | } | |
897 | } | |
898 | return 0; | |
899 | } | |
900 | ||
901 | CORE_ADDR | |
902 | s390_frame_saved_pc (struct frame_info *fi) | |
903 | { | |
904 | CORE_ADDR saved_pc = 0, sig_pc; | |
905 | ||
906 | if (fi->extra_info && fi->extra_info->sig_fixed_saved_pc_valid) | |
907 | return fi->extra_info->sig_fixed_saved_pc; | |
908 | saved_pc = s390_frame_saved_pc_nofix (fi); | |
909 | ||
910 | if (fi->extra_info) | |
911 | { | |
912 | fi->extra_info->sig_fixed_saved_pc_valid = 1; | |
913 | if (saved_pc) | |
914 | { | |
915 | if (s390_is_sigreturn (saved_pc, fi, NULL, &sig_pc)) | |
916 | saved_pc = sig_pc; | |
917 | } | |
918 | fi->extra_info->sig_fixed_saved_pc = saved_pc; | |
919 | } | |
920 | return saved_pc; | |
921 | } | |
922 | ||
923 | ||
924 | ||
925 | ||
926 | /* We want backtraces out of signal handlers so we don't | |
927 | set thisframe->signal_handler_caller to 1 */ | |
928 | ||
929 | CORE_ADDR | |
930 | s390_frame_chain (struct frame_info *thisframe) | |
931 | { | |
932 | CORE_ADDR prev_fp = 0; | |
933 | ||
934 | if (thisframe->prev && thisframe->prev->frame) | |
935 | prev_fp = thisframe->prev->frame; | |
936 | else | |
937 | { | |
938 | int sigreturn = 0; | |
939 | CORE_ADDR sregs = 0; | |
940 | struct frame_extra_info prev_fextra_info; | |
941 | ||
942 | memset (&prev_fextra_info, 0, sizeof (prev_fextra_info)); | |
943 | if (thisframe->pc) | |
944 | { | |
945 | CORE_ADDR saved_pc, sig_pc; | |
946 | ||
947 | saved_pc = s390_frame_saved_pc_nofix (thisframe); | |
948 | if (saved_pc) | |
949 | { | |
950 | if ((sigreturn = | |
951 | s390_is_sigreturn (saved_pc, thisframe, &sregs, &sig_pc))) | |
952 | saved_pc = sig_pc; | |
953 | s390_get_frame_info (s390_sniff_pc_function_start | |
954 | (saved_pc, NULL), &prev_fextra_info, NULL, | |
955 | 1); | |
956 | } | |
957 | } | |
958 | if (sigreturn) | |
959 | { | |
960 | /* read sigregs,regs.gprs[11 or 15] */ | |
961 | prev_fp = read_memory_integer (sregs + | |
962 | REGISTER_BYTE (S390_GP0_REGNUM + | |
963 | (prev_fextra_info. | |
964 | frame_pointer_saved_pc | |
965 | ? 11 : 15)), | |
966 | S390_GPR_SIZE); | |
967 | thisframe->extra_info->sigcontext = sregs; | |
968 | } | |
969 | else | |
970 | { | |
971 | if (thisframe->saved_regs) | |
972 | { | |
973 | ||
974 | int regno; | |
975 | ||
976 | regno = | |
977 | ((prev_fextra_info.frame_pointer_saved_pc | |
978 | && thisframe-> | |
979 | saved_regs[S390_FRAME_REGNUM]) ? S390_FRAME_REGNUM : | |
980 | S390_SP_REGNUM); | |
981 | if (thisframe->saved_regs[regno]) | |
982 | prev_fp = | |
983 | read_memory_integer (thisframe->saved_regs[regno], | |
984 | S390_GPR_SIZE); | |
985 | } | |
986 | } | |
987 | } | |
988 | return ADDR_BITS_REMOVE (prev_fp); | |
989 | } | |
990 | ||
991 | /* | |
992 | Whether struct frame_extra_info is actually needed I'll have to figure | |
993 | out as our frames are similar to rs6000 there is a possibility | |
994 | i386 dosen't need it. */ | |
995 | ||
996 | ||
997 | ||
998 | /* a given return value in `regbuf' with a type `valtype', extract and copy its | |
999 | value into `valbuf' */ | |
1000 | void | |
1001 | s390_extract_return_value (struct type *valtype, char *regbuf, char *valbuf) | |
1002 | { | |
1003 | /* floats and doubles are returned in fpr0. fpr's have a size of 8 bytes. | |
1004 | We need to truncate the return value into float size (4 byte) if | |
1005 | necessary. */ | |
1006 | int len = TYPE_LENGTH (valtype); | |
1007 | ||
1008 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
1009 | { | |
1010 | if (len > (TARGET_FLOAT_BIT >> 3)) | |
1011 | memcpy (valbuf, ®buf[REGISTER_BYTE (S390_FP0_REGNUM)], len); | |
1012 | else | |
1013 | { | |
1014 | /* float */ | |
1015 | DOUBLEST val; | |
1016 | ||
1017 | floatformat_to_doublest (&floatformat_ieee_double_big, | |
1018 | ®buf[REGISTER_BYTE (S390_FP0_REGNUM)], | |
1019 | &val); | |
1020 | store_floating (valbuf, len, val); | |
1021 | } | |
1022 | } | |
1023 | else | |
1024 | { | |
1025 | int offset = 0; | |
1026 | /* return value is copied starting from r2. */ | |
1027 | if (TYPE_LENGTH (valtype) < S390_GPR_SIZE) | |
1028 | offset = S390_GPR_SIZE - TYPE_LENGTH (valtype); | |
1029 | memcpy (valbuf, | |
1030 | regbuf + REGISTER_BYTE (S390_GP0_REGNUM + 2) + offset, | |
1031 | TYPE_LENGTH (valtype)); | |
1032 | } | |
1033 | } | |
1034 | ||
1035 | ||
1036 | static char * | |
1037 | s390_promote_integer_argument (struct type *valtype, char *valbuf, | |
1038 | char *reg_buff, int *arglen) | |
1039 | { | |
1040 | char *value = valbuf; | |
1041 | int len = TYPE_LENGTH (valtype); | |
1042 | ||
1043 | if (len < S390_GPR_SIZE) | |
1044 | { | |
1045 | /* We need to upgrade this value to a register to pass it correctly */ | |
1046 | int idx, diff = S390_GPR_SIZE - len, negative = | |
1047 | (!TYPE_UNSIGNED (valtype) && value[0] & 0x80); | |
1048 | for (idx = 0; idx < S390_GPR_SIZE; idx++) | |
1049 | { | |
1050 | reg_buff[idx] = (idx < diff ? (negative ? 0xff : 0x0) : | |
1051 | value[idx - diff]); | |
1052 | } | |
1053 | value = reg_buff; | |
1054 | *arglen = S390_GPR_SIZE; | |
1055 | } | |
1056 | else | |
1057 | { | |
1058 | if (len & (S390_GPR_SIZE - 1)) | |
1059 | { | |
1060 | fprintf_unfiltered (gdb_stderr, | |
1061 | "s390_promote_integer_argument detected an argument not " | |
1062 | "a multiple of S390_GPR_SIZE & greater than S390_GPR_SIZE " | |
1063 | "we might not deal with this correctly.\n"); | |
1064 | } | |
1065 | *arglen = len; | |
1066 | } | |
1067 | ||
1068 | return (value); | |
1069 | } | |
1070 | ||
1071 | void | |
1072 | s390_store_return_value (struct type *valtype, char *valbuf) | |
1073 | { | |
1074 | int arglen; | |
1075 | char *reg_buff = alloca (max (S390_FPR_SIZE, REGISTER_SIZE)), *value; | |
1076 | ||
1077 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
1078 | { | |
1079 | DOUBLEST tempfloat = extract_floating (valbuf, TYPE_LENGTH (valtype)); | |
1080 | ||
1081 | floatformat_from_doublest (&floatformat_ieee_double_big, &tempfloat, | |
1082 | reg_buff); | |
1083 | write_register_bytes (REGISTER_BYTE (S390_FP0_REGNUM), reg_buff, | |
1084 | S390_FPR_SIZE); | |
1085 | } | |
1086 | else | |
1087 | { | |
1088 | value = | |
1089 | s390_promote_integer_argument (valtype, valbuf, reg_buff, &arglen); | |
1090 | /* Everything else is returned in GPR2 and up. */ | |
1091 | write_register_bytes (REGISTER_BYTE (S390_GP0_REGNUM + 2), value, | |
1092 | arglen); | |
1093 | } | |
1094 | } | |
1095 | static int | |
1096 | gdb_print_insn_s390 (bfd_vma memaddr, disassemble_info * info) | |
1097 | { | |
1098 | bfd_byte instrbuff[S390_MAX_INSTR_SIZE]; | |
1099 | int instrlen, cnt; | |
1100 | ||
1101 | instrlen = s390_readinstruction (instrbuff, (CORE_ADDR) memaddr, info); | |
1102 | if (instrlen < 0) | |
1103 | { | |
1104 | (*info->memory_error_func) (instrlen, memaddr, info); | |
1105 | return -1; | |
1106 | } | |
1107 | for (cnt = 0; cnt < instrlen; cnt++) | |
1108 | info->fprintf_func (info->stream, "%02X ", instrbuff[cnt]); | |
1109 | for (cnt = instrlen; cnt < S390_MAX_INSTR_SIZE; cnt++) | |
1110 | info->fprintf_func (info->stream, " "); | |
1111 | instrlen = print_insn_s390 (memaddr, info); | |
1112 | return instrlen; | |
1113 | } | |
1114 | ||
1115 | ||
1116 | ||
1117 | /* Not the most efficent code in the world */ | |
1118 | int | |
1119 | s390_fp_regnum () | |
1120 | { | |
1121 | int regno = S390_SP_REGNUM; | |
1122 | struct frame_extra_info fextra_info; | |
1123 | ||
1124 | CORE_ADDR pc = ADDR_BITS_REMOVE (read_register (S390_PC_REGNUM)); | |
1125 | ||
1126 | s390_get_frame_info (s390_sniff_pc_function_start (pc, NULL), &fextra_info, | |
1127 | NULL, 1); | |
1128 | if (fextra_info.frame_pointer_saved_pc) | |
1129 | regno = S390_FRAME_REGNUM; | |
1130 | return regno; | |
1131 | } | |
1132 | ||
1133 | CORE_ADDR | |
1134 | s390_read_fp () | |
1135 | { | |
1136 | return read_register (s390_fp_regnum ()); | |
1137 | } | |
1138 | ||
1139 | ||
1140 | void | |
1141 | s390_write_fp (CORE_ADDR val) | |
1142 | { | |
1143 | write_register (s390_fp_regnum (), val); | |
1144 | } | |
1145 | ||
1146 | ||
1147 | void | |
1148 | s390_push_dummy_frame () | |
1149 | { | |
1150 | CORE_ADDR orig_sp = read_register (S390_SP_REGNUM), new_sp; | |
1151 | void *saved_regs = alloca (REGISTER_BYTES); | |
1152 | ||
1153 | new_sp = (orig_sp - (REGISTER_BYTES + S390_GPR_SIZE)); | |
1154 | read_register_bytes (0, (char *) saved_regs, REGISTER_BYTES); | |
1155 | /* Use saved copy instead of orig_sp as this will have the correct endianness */ | |
1156 | write_memory (new_sp, (char *) saved_regs + REGISTER_BYTE (S390_SP_REGNUM), | |
1157 | S390_GPR_SIZE); | |
1158 | write_memory (new_sp + S390_GPR_SIZE, (char *) &saved_regs, REGISTER_BYTES); | |
1159 | write_register (S390_SP_REGNUM, new_sp); | |
1160 | } | |
1161 | ||
1162 | /* pop the innermost frame, go back to the caller. | |
1163 | Used in `call_function_by_hand' to remove an artificial stack | |
1164 | frame. */ | |
1165 | void | |
1166 | s390_pop_frame () | |
1167 | { | |
1168 | CORE_ADDR new_sp = read_register (S390_SP_REGNUM), orig_sp; | |
1169 | void *saved_regs = alloca (REGISTER_BYTES); | |
1170 | ||
1171 | ||
1172 | read_memory (new_sp + S390_GPR_SIZE, (char *) saved_regs, REGISTER_BYTES); | |
1173 | write_register_bytes (0, (char *) &saved_regs, REGISTER_BYTES); | |
1174 | } | |
1175 | ||
1176 | /* used by call function by hand | |
1177 | struct_return indicates that this function returns a structure & | |
1178 | therefore gpr2 stores a pointer to the structure to be returned as | |
1179 | opposed to the first argument. | |
1180 | Currently I haven't seen a TYPE_CODE_INT whose size wasn't 2^n or less | |
1181 | than S390_GPR_SIZE this is good because I don't seem to have to worry | |
1182 | about sign extending pushed arguments (i.e. a signed char currently | |
1183 | comes into this code with a size of 4 ). */ | |
1184 | ||
1185 | CORE_ADDR | |
d45fc520 | 1186 | s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp, |
5769d3cd AC |
1187 | int struct_return, CORE_ADDR struct_addr) |
1188 | { | |
1189 | int num_float_args, num_gpr_args, orig_num_gpr_args, argno; | |
1190 | int second_pass, len, arglen, gprs_required; | |
1191 | CORE_ADDR outgoing_args_ptr, outgoing_args_space; | |
d45fc520 | 1192 | struct value *arg; |
5769d3cd AC |
1193 | struct type *type; |
1194 | int max_num_gpr_args = 5 - (struct_return ? 1 : 0); | |
1195 | int arg0_regnum = S390_GP0_REGNUM + 2 + (struct_return ? 1 : 0); | |
1196 | char *reg_buff = alloca (max (S390_FPR_SIZE, REGISTER_SIZE)), *value; | |
1197 | ||
1198 | for (second_pass = 0; second_pass <= 1; second_pass++) | |
1199 | { | |
1200 | if (second_pass) | |
1201 | outgoing_args_ptr = sp + S390_STACK_FRAME_OVERHEAD; | |
1202 | else | |
1203 | outgoing_args_ptr = 0; | |
1204 | num_float_args = 0; | |
1205 | num_gpr_args = 0; | |
1206 | for (argno = 0; argno < nargs; argno++) | |
1207 | { | |
1208 | arg = args[argno]; | |
1209 | type = check_typedef (VALUE_TYPE (arg)); | |
1210 | len = TYPE_LENGTH (type); | |
1211 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
1212 | { | |
1213 | int all_float_registers_used = | |
1214 | num_float_args > (GDB_TARGET_IS_ESAME ? 3 : 1); | |
1215 | ||
1216 | if (second_pass) | |
1217 | { | |
1218 | DOUBLEST tempfloat = | |
1219 | extract_floating (VALUE_CONTENTS (arg), len); | |
1220 | ||
1221 | ||
1222 | floatformat_from_doublest (all_float_registers_used && | |
1223 | len == (TARGET_FLOAT_BIT >> 3) | |
1224 | ? &floatformat_ieee_single_big | |
1225 | : &floatformat_ieee_double_big, | |
1226 | &tempfloat, reg_buff); | |
1227 | if (all_float_registers_used) | |
1228 | write_memory (outgoing_args_ptr, reg_buff, len); | |
1229 | else | |
1230 | write_register_bytes (REGISTER_BYTE ((S390_FP0_REGNUM) | |
1231 | + | |
1232 | (2 * | |
1233 | num_float_args)), | |
1234 | reg_buff, S390_FPR_SIZE); | |
1235 | } | |
1236 | if (all_float_registers_used) | |
1237 | outgoing_args_ptr += len; | |
1238 | num_float_args++; | |
1239 | } | |
1240 | else | |
1241 | { | |
1242 | gprs_required = ((len + (S390_GPR_SIZE - 1)) / S390_GPR_SIZE); | |
1243 | ||
1244 | value = | |
1245 | s390_promote_integer_argument (type, VALUE_CONTENTS (arg), | |
1246 | reg_buff, &arglen); | |
1247 | ||
1248 | orig_num_gpr_args = num_gpr_args; | |
1249 | num_gpr_args += gprs_required; | |
1250 | if (num_gpr_args > max_num_gpr_args) | |
1251 | { | |
1252 | if (second_pass) | |
1253 | write_memory (outgoing_args_ptr, value, arglen); | |
1254 | outgoing_args_ptr += arglen; | |
1255 | } | |
1256 | else | |
1257 | { | |
1258 | if (second_pass) | |
1259 | write_register_bytes (REGISTER_BYTE (arg0_regnum) | |
1260 | + | |
1261 | (orig_num_gpr_args * S390_GPR_SIZE), | |
1262 | value, arglen); | |
1263 | } | |
1264 | } | |
1265 | } | |
1266 | if (!second_pass) | |
1267 | { | |
1268 | outgoing_args_space = outgoing_args_ptr; | |
1269 | /* Align to 16 bytes because because I like alignment & | |
1270 | some of the kernel code requires 8 byte stack alignment at least. */ | |
1271 | sp = (sp - (S390_STACK_FRAME_OVERHEAD + outgoing_args_ptr)) & (-16); | |
1272 | } | |
1273 | ||
1274 | } | |
1275 | return sp; | |
1276 | ||
1277 | } | |
1278 | ||
1279 | void | |
1280 | s390_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs, | |
1281 | struct value **args, struct type *value_type, | |
1282 | int using_gcc) | |
1283 | { | |
1284 | store_unsigned_integer (dummy + 4, REGISTER_SIZE, fun); | |
1285 | } | |
1286 | ||
1287 | ||
1288 | /* Return the GDB type object for the "standard" data type | |
1289 | of data in register N. */ | |
1290 | struct type * | |
1291 | s390_register_virtual_type (int regno) | |
1292 | { | |
1293 | return ((unsigned) regno - S390_FPC_REGNUM) < | |
1294 | S390_NUM_FPRS ? builtin_type_double : builtin_type_int; | |
1295 | } | |
1296 | ||
1297 | ||
1298 | struct type * | |
1299 | s390x_register_virtual_type (int regno) | |
1300 | { | |
1301 | return (regno == S390_FPC_REGNUM) || | |
1302 | (regno >= S390_FIRST_ACR && regno <= S390_LAST_ACR) ? builtin_type_int : | |
1303 | (regno >= S390_FP0_REGNUM) ? builtin_type_double : builtin_type_long; | |
1304 | } | |
1305 | ||
1306 | ||
1307 | ||
1308 | void | |
1309 | s390_store_struct_return (CORE_ADDR addr, CORE_ADDR sp) | |
1310 | { | |
1311 | write_register (S390_GP0_REGNUM + 2, addr); | |
1312 | } | |
1313 | ||
1314 | ||
1315 | ||
1316 | static unsigned char * | |
1317 | s390_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) | |
1318 | { | |
1319 | static unsigned char breakpoint[] = { 0x0, 0x1 }; | |
1320 | ||
1321 | *lenptr = sizeof (breakpoint); | |
1322 | return breakpoint; | |
1323 | } | |
1324 | ||
1325 | /* Advance PC across any function entry prologue instructions to reach some | |
1326 | "real" code. */ | |
1327 | CORE_ADDR | |
1328 | s390_skip_prologue (CORE_ADDR pc) | |
1329 | { | |
1330 | struct frame_extra_info fextra_info; | |
1331 | ||
1332 | s390_get_frame_info (pc, &fextra_info, NULL, 1); | |
1333 | return fextra_info.skip_prologue_function_start; | |
1334 | } | |
1335 | ||
1336 | /* pc_in_call_dummy_on stack may work for us must test this */ | |
1337 | int | |
1338 | s390_pc_in_call_dummy (CORE_ADDR pc, CORE_ADDR sp, CORE_ADDR frame_address) | |
1339 | { | |
1340 | return pc > sp && pc < (sp + 4096); | |
1341 | } | |
1342 | ||
1343 | /* Immediately after a function call, return the saved pc. | |
1344 | Can't go through the frames for this because on some machines | |
1345 | the new frame is not set up until the new function executes | |
1346 | some instructions. */ | |
1347 | CORE_ADDR | |
1348 | s390_saved_pc_after_call (struct frame_info *frame) | |
1349 | { | |
1350 | return ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM)); | |
1351 | } | |
1352 | ||
1353 | static CORE_ADDR | |
1354 | s390_addr_bits_remove (CORE_ADDR addr) | |
1355 | { | |
1356 | return (addr) & 0x7fffffff; | |
1357 | } | |
1358 | ||
1359 | ||
1360 | static CORE_ADDR | |
1361 | s390_push_return_address (CORE_ADDR pc, CORE_ADDR sp) | |
1362 | { | |
1363 | return sp; | |
1364 | } | |
1365 | ||
1366 | struct gdbarch * | |
1367 | s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
1368 | { | |
1369 | ||
1370 | /* instruction sequence for s390 call dummy is as follows | |
1371 | bras %r1,.+8 ; 0xA7150004 | |
1372 | long basraddr ; 0x00000000 | |
1373 | l %r1,0(%r1) ; 0x58101000 | |
1374 | basr %r14,%r1 ; 0x0DE1 | |
1375 | breakpoint ; 0x0001 */ | |
1376 | static LONGEST s390_call_dummy_words[] = { 0xA7150004, 0x00000000, | |
1377 | 0x58101000, 0x0DE10001 | |
1378 | }; | |
1379 | /* instruction sequence for esame call dummy is as follows | |
1380 | bras %r1,.+12 ; 0xA7150006 | |
1381 | long basraddr ; 0x0000000000000000 | |
1382 | lg %r1,0(%r1) ; 0xE31010000004 | |
1383 | basr %r14,%r1 ; 0x0DE1 | |
1384 | breakpoint ; 0x0001 */ | |
1385 | static LONGEST s390x_call_dummy_words[] = { 0xA715000600000000, | |
1386 | 0x00000000E3101000, | |
1387 | 0x00040DE100010000 | |
1388 | }; | |
1389 | struct gdbarch *gdbarch; | |
1390 | struct gdbarch_tdep *tdep; | |
1391 | int elf_flags; | |
1392 | ||
1393 | /* First see if there is already a gdbarch that can satisfy the request. */ | |
1394 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
1395 | if (arches != NULL) | |
1396 | return arches->gdbarch; | |
1397 | ||
1398 | /* None found: is the request for a s390 architecture? */ | |
1399 | if (info.bfd_arch_info->arch != bfd_arch_s390) | |
1400 | return NULL; /* No; then it's not for us. */ | |
1401 | ||
1402 | /* Yes: create a new gdbarch for the specified machine type. */ | |
1403 | gdbarch = gdbarch_alloc (&info, NULL); | |
1404 | ||
1405 | set_gdbarch_believe_pcc_promotion (gdbarch, 0); | |
1406 | ||
1407 | /* We don't define set_gdbarch_call_dummy_breakpoint_offset | |
1408 | as we already have a breakpoint inserted. */ | |
1409 | set_gdbarch_use_generic_dummy_frames (gdbarch, 0); | |
1410 | ||
1411 | set_gdbarch_call_dummy_location (gdbarch, ON_STACK); | |
1412 | set_gdbarch_call_dummy_start_offset (gdbarch, 0); | |
1413 | set_gdbarch_pc_in_call_dummy (gdbarch, s390_pc_in_call_dummy); | |
1414 | set_gdbarch_frame_args_skip (gdbarch, 0); | |
1415 | set_gdbarch_frame_args_address (gdbarch, s390_frame_args_address); | |
1416 | set_gdbarch_frame_chain (gdbarch, s390_frame_chain); | |
1417 | set_gdbarch_frame_init_saved_regs (gdbarch, s390_frame_init_saved_regs); | |
1418 | set_gdbarch_frame_locals_address (gdbarch, s390_frame_args_address); | |
1419 | /* We can't do this */ | |
1420 | set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown); | |
1421 | set_gdbarch_store_struct_return (gdbarch, s390_store_struct_return); | |
1422 | set_gdbarch_extract_return_value (gdbarch, s390_extract_return_value); | |
1423 | set_gdbarch_store_return_value (gdbarch, s390_store_return_value); | |
1424 | /* Amount PC must be decremented by after a breakpoint. | |
1425 | This is often the number of bytes in BREAKPOINT | |
1426 | but not always. */ | |
1427 | set_gdbarch_decr_pc_after_break (gdbarch, 2); | |
1428 | set_gdbarch_pop_frame (gdbarch, s390_pop_frame); | |
1429 | set_gdbarch_push_dummy_frame (gdbarch, s390_push_dummy_frame); | |
1430 | set_gdbarch_push_arguments (gdbarch, s390_push_arguments); | |
1431 | set_gdbarch_ieee_float (gdbarch, 1); | |
1432 | /* Stack grows downward. */ | |
1433 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
1434 | /* Offset from address of function to start of its code. | |
1435 | Zero on most machines. */ | |
1436 | set_gdbarch_function_start_offset (gdbarch, 0); | |
1437 | set_gdbarch_max_register_raw_size (gdbarch, 8); | |
1438 | set_gdbarch_max_register_virtual_size (gdbarch, 8); | |
1439 | set_gdbarch_breakpoint_from_pc (gdbarch, s390_breakpoint_from_pc); | |
1440 | set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue); | |
1441 | set_gdbarch_init_extra_frame_info (gdbarch, s390_init_extra_frame_info); | |
1442 | set_gdbarch_init_frame_pc_first (gdbarch, s390_init_frame_pc_first); | |
1443 | set_gdbarch_read_fp (gdbarch, s390_read_fp); | |
1444 | set_gdbarch_write_fp (gdbarch, s390_write_fp); | |
1445 | /* This function that tells us whether the function invocation represented | |
1446 | by FI does not have a frame on the stack associated with it. If it | |
1447 | does not, FRAMELESS is set to 1, else 0. */ | |
1448 | set_gdbarch_frameless_function_invocation (gdbarch, | |
1449 | s390_frameless_function_invocation); | |
1450 | /* Return saved PC from a frame */ | |
1451 | set_gdbarch_frame_saved_pc (gdbarch, s390_frame_saved_pc); | |
1452 | /* FRAME_CHAIN takes a frame's nominal address | |
1453 | and produces the frame's chain-pointer. */ | |
1454 | set_gdbarch_frame_chain (gdbarch, s390_frame_chain); | |
1455 | set_gdbarch_saved_pc_after_call (gdbarch, s390_saved_pc_after_call); | |
1456 | set_gdbarch_register_byte (gdbarch, s390_register_byte); | |
1457 | set_gdbarch_pc_regnum (gdbarch, S390_PC_REGNUM); | |
1458 | set_gdbarch_sp_regnum (gdbarch, S390_SP_REGNUM); | |
1459 | set_gdbarch_fp_regnum (gdbarch, S390_FP_REGNUM); | |
1460 | set_gdbarch_fp0_regnum (gdbarch, S390_FP0_REGNUM); | |
1461 | set_gdbarch_num_regs (gdbarch, S390_NUM_REGS); | |
1462 | set_gdbarch_cannot_fetch_register (gdbarch, s390_cannot_fetch_register); | |
1463 | set_gdbarch_cannot_store_register (gdbarch, s390_cannot_fetch_register); | |
1464 | set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register); | |
1465 | set_gdbarch_use_struct_convention (gdbarch, generic_use_struct_convention); | |
8001d1e4 | 1466 | set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); |
5769d3cd AC |
1467 | set_gdbarch_register_name (gdbarch, s390_register_name); |
1468 | set_gdbarch_stab_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
1469 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
1470 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
5769d3cd AC |
1471 | |
1472 | /* Stuff below here wouldn't be required if gdbarch.sh was a little */ | |
1473 | /* more intelligent */ | |
1474 | set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 0); | |
1475 | set_gdbarch_call_dummy_p (gdbarch, 1); | |
1476 | set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0); | |
1477 | set_gdbarch_extract_struct_value_address (gdbarch, 0); | |
1478 | set_gdbarch_fix_call_dummy (gdbarch, s390_fix_call_dummy); | |
5769d3cd AC |
1479 | set_gdbarch_push_return_address (gdbarch, s390_push_return_address); |
1480 | ||
1481 | switch (info.bfd_arch_info->mach) | |
1482 | { | |
1483 | case bfd_mach_s390_esa: | |
1484 | set_gdbarch_register_size (gdbarch, 4); | |
1485 | set_gdbarch_call_dummy_length (gdbarch, 16); | |
1486 | set_gdbarch_register_raw_size (gdbarch, s390_register_raw_size); | |
1487 | set_gdbarch_register_virtual_size (gdbarch, s390_register_raw_size); | |
1488 | set_gdbarch_register_virtual_type (gdbarch, s390_register_virtual_type); | |
1489 | ||
1490 | set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove); | |
1491 | ||
1492 | set_gdbarch_sizeof_call_dummy_words (gdbarch, | |
1493 | sizeof (s390_call_dummy_words)); | |
1494 | set_gdbarch_call_dummy_words (gdbarch, s390_call_dummy_words); | |
1495 | set_gdbarch_register_bytes (gdbarch, S390_REGISTER_BYTES); | |
1496 | break; | |
1497 | case bfd_mach_s390_esame: | |
1498 | set_gdbarch_register_size (gdbarch, 8); | |
1499 | set_gdbarch_call_dummy_length (gdbarch, 22); | |
1500 | set_gdbarch_register_raw_size (gdbarch, s390x_register_raw_size); | |
1501 | set_gdbarch_register_virtual_size (gdbarch, s390x_register_raw_size); | |
1502 | set_gdbarch_register_virtual_type (gdbarch, | |
1503 | s390x_register_virtual_type); | |
1504 | ||
1505 | set_gdbarch_long_bit (gdbarch, 64); | |
1506 | set_gdbarch_long_long_bit (gdbarch, 64); | |
1507 | set_gdbarch_ptr_bit (gdbarch, 64); | |
1508 | set_gdbarch_sizeof_call_dummy_words (gdbarch, | |
1509 | sizeof (s390x_call_dummy_words)); | |
1510 | set_gdbarch_call_dummy_words (gdbarch, s390x_call_dummy_words); | |
1511 | set_gdbarch_register_bytes (gdbarch, S390X_REGISTER_BYTES); | |
1512 | break; | |
1513 | } | |
1514 | ||
1515 | return gdbarch; | |
1516 | } | |
1517 | ||
1518 | ||
1519 | ||
1520 | void | |
1521 | _initialize_s390_tdep () | |
1522 | { | |
1523 | ||
1524 | /* Hook us into the gdbarch mechanism. */ | |
1525 | register_gdbarch_init (bfd_arch_s390, s390_gdbarch_init); | |
1526 | if (!tm_print_insn) /* Someone may have already set it */ | |
1527 | tm_print_insn = gdb_print_insn_s390; | |
1528 | } | |
1529 | ||
1530 | #endif /* GDBSERVER */ |