]>
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" |
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", | |
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; | |
64f9bb98 | 232 | CORE_ADDR got_load_addr = 0, got_load_len = 0; |
8ac0e65a | 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 | } | |
09025237 JB |
599 | if (saved_regs) |
600 | /* The SP's element of the saved_regs array holds the old SP, | |
601 | not the address at which it is saved. */ | |
602 | saved_regs[S390_SP_REGNUM] = orig_sp; | |
5769d3cd AC |
603 | return err; |
604 | } | |
605 | ||
606 | ||
607 | int | |
608 | s390_check_function_end (CORE_ADDR pc) | |
609 | { | |
610 | bfd_byte instr[S390_MAX_INSTR_SIZE]; | |
611 | disassemble_info info; | |
612 | int regidx, instrlen; | |
613 | ||
614 | info.read_memory_func = dis_asm_read_memory; | |
615 | instrlen = s390_readinstruction (instr, pc, &info); | |
616 | if (instrlen < 0) | |
617 | return -1; | |
618 | /* check for BR */ | |
619 | if (instrlen != 2 || instr[0] != 07 || (instr[1] >> 4) != 0xf) | |
620 | return 0; | |
621 | regidx = instr[1] & 0xf; | |
622 | /* Check for LMG or LG */ | |
623 | instrlen = | |
624 | s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 6 : 4), &info); | |
625 | if (instrlen < 0) | |
626 | return -1; | |
627 | if (GDB_TARGET_IS_ESAME) | |
628 | { | |
629 | ||
630 | if (instrlen != 6 || instr[0] != 0xeb || instr[5] != 0x4) | |
631 | return 0; | |
632 | } | |
633 | else if (instrlen != 4 || instr[0] != 0x98) | |
634 | { | |
635 | return 0; | |
636 | } | |
637 | if ((instr[2] >> 4) != 0xf) | |
638 | return 0; | |
639 | if (regidx == 14) | |
640 | return 1; | |
641 | instrlen = s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 12 : 8), | |
642 | &info); | |
643 | if (instrlen < 0) | |
644 | return -1; | |
645 | if (GDB_TARGET_IS_ESAME) | |
646 | { | |
647 | /* Check for LG */ | |
648 | if (instrlen != 6 || instr[0] != 0xe3 || instr[5] != 0x4) | |
649 | return 0; | |
650 | } | |
651 | else | |
652 | { | |
653 | /* Check for L */ | |
654 | if (instrlen != 4 || instr[0] != 0x58) | |
655 | return 0; | |
656 | } | |
657 | if (instr[2] >> 4 != 0xf) | |
658 | return 0; | |
659 | if (instr[1] >> 4 != regidx) | |
660 | return 0; | |
661 | return 1; | |
662 | } | |
663 | ||
664 | static CORE_ADDR | |
665 | s390_sniff_pc_function_start (CORE_ADDR pc, struct frame_info *fi) | |
666 | { | |
667 | CORE_ADDR function_start, test_function_start; | |
668 | int loop_cnt, err, function_end; | |
669 | struct frame_extra_info fextra_info; | |
670 | function_start = get_pc_function_start (pc); | |
671 | ||
672 | if (function_start == 0) | |
673 | { | |
674 | test_function_start = pc; | |
675 | if (test_function_start & 1) | |
676 | return 0; /* This has to be bogus */ | |
677 | loop_cnt = 0; | |
678 | do | |
679 | { | |
680 | ||
681 | err = | |
682 | s390_get_frame_info (test_function_start, &fextra_info, fi, 1); | |
683 | loop_cnt++; | |
684 | test_function_start -= 2; | |
685 | function_end = s390_check_function_end (test_function_start); | |
686 | } | |
687 | while (!(function_end == 1 || err || loop_cnt >= 4096 || | |
688 | (fextra_info.good_prologue))); | |
689 | if (fextra_info.good_prologue) | |
690 | function_start = fextra_info.function_start; | |
691 | else if (function_end == 1) | |
692 | function_start = test_function_start; | |
693 | } | |
694 | return function_start; | |
695 | } | |
696 | ||
697 | ||
698 | ||
699 | CORE_ADDR | |
700 | s390_function_start (struct frame_info *fi) | |
701 | { | |
702 | CORE_ADDR function_start = 0; | |
703 | ||
704 | if (fi->extra_info && fi->extra_info->initialised) | |
705 | function_start = fi->extra_info->function_start; | |
706 | else if (fi->pc) | |
707 | function_start = get_pc_function_start (fi->pc); | |
708 | return function_start; | |
709 | } | |
710 | ||
711 | ||
712 | ||
713 | ||
714 | int | |
715 | s390_frameless_function_invocation (struct frame_info *fi) | |
716 | { | |
717 | struct frame_extra_info fextra_info, *fextra_info_ptr; | |
718 | int frameless = 0; | |
719 | ||
720 | if (fi->next == NULL) /* no may be frameless */ | |
721 | { | |
722 | if (fi->extra_info) | |
723 | fextra_info_ptr = fi->extra_info; | |
724 | else | |
725 | { | |
726 | fextra_info_ptr = &fextra_info; | |
727 | s390_get_frame_info (s390_sniff_pc_function_start (fi->pc, fi), | |
728 | fextra_info_ptr, fi, 1); | |
729 | } | |
730 | frameless = ((fextra_info_ptr->stack_bought == 0)); | |
731 | } | |
732 | return frameless; | |
733 | ||
734 | } | |
735 | ||
736 | ||
737 | static int | |
738 | s390_is_sigreturn (CORE_ADDR pc, struct frame_info *sighandler_fi, | |
739 | CORE_ADDR *sregs, CORE_ADDR *sigcaller_pc) | |
740 | { | |
741 | bfd_byte instr[S390_MAX_INSTR_SIZE]; | |
742 | disassemble_info info; | |
743 | int instrlen; | |
744 | CORE_ADDR scontext; | |
745 | int retval = 0; | |
746 | CORE_ADDR orig_sp; | |
747 | CORE_ADDR temp_sregs; | |
748 | ||
749 | scontext = temp_sregs = 0; | |
750 | ||
751 | info.read_memory_func = dis_asm_read_memory; | |
752 | instrlen = s390_readinstruction (instr, pc, &info); | |
753 | if (sigcaller_pc) | |
754 | *sigcaller_pc = 0; | |
755 | if (((instrlen == S390_SYSCALL_SIZE) && | |
756 | (instr[0] == S390_SYSCALL_OPCODE)) && | |
757 | ((instr[1] == s390_NR_sigreturn) || (instr[1] == s390_NR_rt_sigreturn))) | |
758 | { | |
759 | if (sighandler_fi) | |
760 | { | |
761 | if (s390_frameless_function_invocation (sighandler_fi)) | |
762 | orig_sp = sighandler_fi->frame; | |
763 | else | |
764 | orig_sp = ADDR_BITS_REMOVE ((CORE_ADDR) | |
765 | read_memory_integer (sighandler_fi-> | |
766 | frame, | |
767 | S390_GPR_SIZE)); | |
768 | if (orig_sp && sigcaller_pc) | |
769 | { | |
770 | scontext = orig_sp + S390_SIGNAL_FRAMESIZE; | |
771 | if (pc == scontext && instr[1] == s390_NR_rt_sigreturn) | |
772 | { | |
773 | /* We got a new style rt_signal */ | |
774 | /* get address of read ucontext->uc_mcontext */ | |
775 | temp_sregs = orig_sp + (GDB_TARGET_IS_ESAME ? | |
776 | S390X_UC_MCONTEXT_OFFSET : | |
777 | S390_UC_MCONTEXT_OFFSET); | |
778 | } | |
779 | else | |
780 | { | |
781 | /* read sigcontext->sregs */ | |
782 | temp_sregs = ADDR_BITS_REMOVE ((CORE_ADDR) | |
783 | read_memory_integer (scontext | |
784 | + | |
785 | (GDB_TARGET_IS_ESAME | |
786 | ? | |
787 | S390X_SIGCONTEXT_SREGS_OFFSET | |
788 | : | |
789 | S390_SIGCONTEXT_SREGS_OFFSET), | |
790 | S390_GPR_SIZE)); | |
791 | ||
792 | } | |
793 | /* read sigregs->psw.addr */ | |
794 | *sigcaller_pc = | |
795 | ADDR_BITS_REMOVE ((CORE_ADDR) | |
796 | read_memory_integer (temp_sregs + | |
797 | REGISTER_BYTE | |
798 | (S390_PC_REGNUM), | |
799 | S390_PSW_ADDR_SIZE)); | |
800 | } | |
801 | } | |
802 | retval = 1; | |
803 | } | |
804 | if (sregs) | |
805 | *sregs = temp_sregs; | |
806 | return retval; | |
807 | } | |
808 | ||
809 | /* | |
810 | We need to do something better here but this will keep us out of trouble | |
811 | for the moment. | |
812 | For some reason the blockframe.c calls us with fi->next->fromleaf | |
813 | so this seems of little use to us. */ | |
814 | void | |
815 | s390_init_frame_pc_first (int next_fromleaf, struct frame_info *fi) | |
816 | { | |
817 | CORE_ADDR sigcaller_pc; | |
818 | ||
819 | fi->pc = 0; | |
820 | if (next_fromleaf) | |
821 | { | |
822 | fi->pc = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM)); | |
823 | /* fix signal handlers */ | |
824 | } | |
825 | else if (fi->next && fi->next->pc) | |
826 | fi->pc = s390_frame_saved_pc_nofix (fi->next); | |
827 | if (fi->pc && fi->next && fi->next->frame && | |
828 | s390_is_sigreturn (fi->pc, fi->next, NULL, &sigcaller_pc)) | |
829 | { | |
830 | fi->pc = sigcaller_pc; | |
831 | } | |
832 | ||
833 | } | |
834 | ||
835 | void | |
836 | s390_init_extra_frame_info (int fromleaf, struct frame_info *fi) | |
837 | { | |
838 | fi->extra_info = frame_obstack_alloc (sizeof (struct frame_extra_info)); | |
839 | if (fi->pc) | |
840 | s390_get_frame_info (s390_sniff_pc_function_start (fi->pc, fi), | |
841 | fi->extra_info, fi, 1); | |
842 | else | |
843 | s390_memset_extra_info (fi->extra_info); | |
844 | } | |
845 | ||
846 | /* If saved registers of frame FI are not known yet, read and cache them. | |
847 | &FEXTRA_INFOP contains struct frame_extra_info; TDATAP can be NULL, | |
848 | in which case the framedata are read. */ | |
849 | ||
850 | void | |
851 | s390_frame_init_saved_regs (struct frame_info *fi) | |
852 | { | |
853 | ||
854 | int quick; | |
855 | ||
856 | if (fi->saved_regs == NULL) | |
857 | { | |
858 | /* zalloc memsets the saved regs */ | |
859 | frame_saved_regs_zalloc (fi); | |
860 | if (fi->pc) | |
861 | { | |
862 | quick = (fi->extra_info && fi->extra_info->initialised | |
863 | && fi->extra_info->good_prologue); | |
864 | s390_get_frame_info (quick ? fi->extra_info->function_start : | |
865 | s390_sniff_pc_function_start (fi->pc, fi), | |
866 | fi->extra_info, fi, !quick); | |
867 | } | |
868 | } | |
869 | } | |
870 | ||
871 | ||
872 | ||
873 | CORE_ADDR | |
874 | s390_frame_args_address (struct frame_info *fi) | |
875 | { | |
876 | ||
877 | /* Apparently gdb already knows gdb_args_offset itself */ | |
878 | return fi->frame; | |
879 | } | |
880 | ||
881 | ||
882 | static CORE_ADDR | |
883 | s390_frame_saved_pc_nofix (struct frame_info *fi) | |
884 | { | |
885 | if (fi->extra_info && fi->extra_info->saved_pc_valid) | |
886 | return fi->extra_info->saved_pc; | |
887 | s390_frame_init_saved_regs (fi); | |
888 | if (fi->extra_info) | |
889 | { | |
890 | fi->extra_info->saved_pc_valid = 1; | |
891 | if (fi->extra_info->good_prologue) | |
892 | { | |
893 | if (fi->saved_regs[S390_RETADDR_REGNUM]) | |
894 | { | |
895 | return (fi->extra_info->saved_pc = | |
896 | ADDR_BITS_REMOVE (read_memory_integer | |
897 | (fi->saved_regs[S390_RETADDR_REGNUM], | |
898 | S390_GPR_SIZE))); | |
899 | } | |
900 | } | |
901 | } | |
902 | return 0; | |
903 | } | |
904 | ||
905 | CORE_ADDR | |
906 | s390_frame_saved_pc (struct frame_info *fi) | |
907 | { | |
908 | CORE_ADDR saved_pc = 0, sig_pc; | |
909 | ||
910 | if (fi->extra_info && fi->extra_info->sig_fixed_saved_pc_valid) | |
911 | return fi->extra_info->sig_fixed_saved_pc; | |
912 | saved_pc = s390_frame_saved_pc_nofix (fi); | |
913 | ||
914 | if (fi->extra_info) | |
915 | { | |
916 | fi->extra_info->sig_fixed_saved_pc_valid = 1; | |
917 | if (saved_pc) | |
918 | { | |
919 | if (s390_is_sigreturn (saved_pc, fi, NULL, &sig_pc)) | |
920 | saved_pc = sig_pc; | |
921 | } | |
922 | fi->extra_info->sig_fixed_saved_pc = saved_pc; | |
923 | } | |
924 | return saved_pc; | |
925 | } | |
926 | ||
927 | ||
928 | ||
929 | ||
930 | /* We want backtraces out of signal handlers so we don't | |
931 | set thisframe->signal_handler_caller to 1 */ | |
932 | ||
933 | CORE_ADDR | |
934 | s390_frame_chain (struct frame_info *thisframe) | |
935 | { | |
936 | CORE_ADDR prev_fp = 0; | |
937 | ||
938 | if (thisframe->prev && thisframe->prev->frame) | |
939 | prev_fp = thisframe->prev->frame; | |
940 | else | |
941 | { | |
942 | int sigreturn = 0; | |
943 | CORE_ADDR sregs = 0; | |
944 | struct frame_extra_info prev_fextra_info; | |
945 | ||
946 | memset (&prev_fextra_info, 0, sizeof (prev_fextra_info)); | |
947 | if (thisframe->pc) | |
948 | { | |
949 | CORE_ADDR saved_pc, sig_pc; | |
950 | ||
951 | saved_pc = s390_frame_saved_pc_nofix (thisframe); | |
952 | if (saved_pc) | |
953 | { | |
954 | if ((sigreturn = | |
955 | s390_is_sigreturn (saved_pc, thisframe, &sregs, &sig_pc))) | |
956 | saved_pc = sig_pc; | |
957 | s390_get_frame_info (s390_sniff_pc_function_start | |
958 | (saved_pc, NULL), &prev_fextra_info, NULL, | |
959 | 1); | |
960 | } | |
961 | } | |
962 | if (sigreturn) | |
963 | { | |
964 | /* read sigregs,regs.gprs[11 or 15] */ | |
965 | prev_fp = read_memory_integer (sregs + | |
966 | REGISTER_BYTE (S390_GP0_REGNUM + | |
967 | (prev_fextra_info. | |
968 | frame_pointer_saved_pc | |
969 | ? 11 : 15)), | |
970 | S390_GPR_SIZE); | |
971 | thisframe->extra_info->sigcontext = sregs; | |
972 | } | |
973 | else | |
974 | { | |
975 | if (thisframe->saved_regs) | |
976 | { | |
977 | ||
978 | int regno; | |
979 | ||
980 | regno = | |
981 | ((prev_fextra_info.frame_pointer_saved_pc | |
982 | && thisframe-> | |
983 | saved_regs[S390_FRAME_REGNUM]) ? S390_FRAME_REGNUM : | |
984 | S390_SP_REGNUM); | |
985 | if (thisframe->saved_regs[regno]) | |
986 | prev_fp = | |
987 | read_memory_integer (thisframe->saved_regs[regno], | |
988 | S390_GPR_SIZE); | |
989 | } | |
990 | } | |
991 | } | |
992 | return ADDR_BITS_REMOVE (prev_fp); | |
993 | } | |
994 | ||
995 | /* | |
996 | Whether struct frame_extra_info is actually needed I'll have to figure | |
997 | out as our frames are similar to rs6000 there is a possibility | |
998 | i386 dosen't need it. */ | |
999 | ||
1000 | ||
1001 | ||
1002 | /* a given return value in `regbuf' with a type `valtype', extract and copy its | |
1003 | value into `valbuf' */ | |
1004 | void | |
1005 | s390_extract_return_value (struct type *valtype, char *regbuf, char *valbuf) | |
1006 | { | |
1007 | /* floats and doubles are returned in fpr0. fpr's have a size of 8 bytes. | |
1008 | We need to truncate the return value into float size (4 byte) if | |
1009 | necessary. */ | |
1010 | int len = TYPE_LENGTH (valtype); | |
1011 | ||
1012 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
f2c6cfba | 1013 | memcpy (valbuf, ®buf[REGISTER_BYTE (S390_FP0_REGNUM)], len); |
5769d3cd AC |
1014 | else |
1015 | { | |
1016 | int offset = 0; | |
1017 | /* return value is copied starting from r2. */ | |
1018 | if (TYPE_LENGTH (valtype) < S390_GPR_SIZE) | |
1019 | offset = S390_GPR_SIZE - TYPE_LENGTH (valtype); | |
1020 | memcpy (valbuf, | |
1021 | regbuf + REGISTER_BYTE (S390_GP0_REGNUM + 2) + offset, | |
1022 | TYPE_LENGTH (valtype)); | |
1023 | } | |
1024 | } | |
1025 | ||
1026 | ||
1027 | static char * | |
1028 | s390_promote_integer_argument (struct type *valtype, char *valbuf, | |
1029 | char *reg_buff, int *arglen) | |
1030 | { | |
1031 | char *value = valbuf; | |
1032 | int len = TYPE_LENGTH (valtype); | |
1033 | ||
1034 | if (len < S390_GPR_SIZE) | |
1035 | { | |
1036 | /* We need to upgrade this value to a register to pass it correctly */ | |
1037 | int idx, diff = S390_GPR_SIZE - len, negative = | |
1038 | (!TYPE_UNSIGNED (valtype) && value[0] & 0x80); | |
1039 | for (idx = 0; idx < S390_GPR_SIZE; idx++) | |
1040 | { | |
1041 | reg_buff[idx] = (idx < diff ? (negative ? 0xff : 0x0) : | |
1042 | value[idx - diff]); | |
1043 | } | |
1044 | value = reg_buff; | |
1045 | *arglen = S390_GPR_SIZE; | |
1046 | } | |
1047 | else | |
1048 | { | |
1049 | if (len & (S390_GPR_SIZE - 1)) | |
1050 | { | |
1051 | fprintf_unfiltered (gdb_stderr, | |
1052 | "s390_promote_integer_argument detected an argument not " | |
1053 | "a multiple of S390_GPR_SIZE & greater than S390_GPR_SIZE " | |
1054 | "we might not deal with this correctly.\n"); | |
1055 | } | |
1056 | *arglen = len; | |
1057 | } | |
1058 | ||
1059 | return (value); | |
1060 | } | |
1061 | ||
1062 | void | |
1063 | s390_store_return_value (struct type *valtype, char *valbuf) | |
1064 | { | |
1065 | int arglen; | |
1066 | char *reg_buff = alloca (max (S390_FPR_SIZE, REGISTER_SIZE)), *value; | |
1067 | ||
1068 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
1069 | { | |
1070 | DOUBLEST tempfloat = extract_floating (valbuf, TYPE_LENGTH (valtype)); | |
1071 | ||
1072 | floatformat_from_doublest (&floatformat_ieee_double_big, &tempfloat, | |
1073 | reg_buff); | |
1074 | write_register_bytes (REGISTER_BYTE (S390_FP0_REGNUM), reg_buff, | |
1075 | S390_FPR_SIZE); | |
1076 | } | |
1077 | else | |
1078 | { | |
1079 | value = | |
1080 | s390_promote_integer_argument (valtype, valbuf, reg_buff, &arglen); | |
1081 | /* Everything else is returned in GPR2 and up. */ | |
1082 | write_register_bytes (REGISTER_BYTE (S390_GP0_REGNUM + 2), value, | |
1083 | arglen); | |
1084 | } | |
1085 | } | |
1086 | static int | |
1087 | gdb_print_insn_s390 (bfd_vma memaddr, disassemble_info * info) | |
1088 | { | |
1089 | bfd_byte instrbuff[S390_MAX_INSTR_SIZE]; | |
1090 | int instrlen, cnt; | |
1091 | ||
1092 | instrlen = s390_readinstruction (instrbuff, (CORE_ADDR) memaddr, info); | |
1093 | if (instrlen < 0) | |
1094 | { | |
1095 | (*info->memory_error_func) (instrlen, memaddr, info); | |
1096 | return -1; | |
1097 | } | |
1098 | for (cnt = 0; cnt < instrlen; cnt++) | |
1099 | info->fprintf_func (info->stream, "%02X ", instrbuff[cnt]); | |
1100 | for (cnt = instrlen; cnt < S390_MAX_INSTR_SIZE; cnt++) | |
1101 | info->fprintf_func (info->stream, " "); | |
1102 | instrlen = print_insn_s390 (memaddr, info); | |
1103 | return instrlen; | |
1104 | } | |
1105 | ||
1106 | ||
1107 | ||
1108 | /* Not the most efficent code in the world */ | |
1109 | int | |
1110 | s390_fp_regnum () | |
1111 | { | |
1112 | int regno = S390_SP_REGNUM; | |
1113 | struct frame_extra_info fextra_info; | |
1114 | ||
1115 | CORE_ADDR pc = ADDR_BITS_REMOVE (read_register (S390_PC_REGNUM)); | |
1116 | ||
1117 | s390_get_frame_info (s390_sniff_pc_function_start (pc, NULL), &fextra_info, | |
1118 | NULL, 1); | |
1119 | if (fextra_info.frame_pointer_saved_pc) | |
1120 | regno = S390_FRAME_REGNUM; | |
1121 | return regno; | |
1122 | } | |
1123 | ||
1124 | CORE_ADDR | |
1125 | s390_read_fp () | |
1126 | { | |
1127 | return read_register (s390_fp_regnum ()); | |
1128 | } | |
1129 | ||
1130 | ||
1131 | void | |
1132 | s390_write_fp (CORE_ADDR val) | |
1133 | { | |
1134 | write_register (s390_fp_regnum (), val); | |
1135 | } | |
1136 | ||
1137 | ||
1138 | void | |
1139 | s390_push_dummy_frame () | |
1140 | { | |
1141 | CORE_ADDR orig_sp = read_register (S390_SP_REGNUM), new_sp; | |
1142 | void *saved_regs = alloca (REGISTER_BYTES); | |
1143 | ||
1144 | new_sp = (orig_sp - (REGISTER_BYTES + S390_GPR_SIZE)); | |
1145 | read_register_bytes (0, (char *) saved_regs, REGISTER_BYTES); | |
1146 | /* Use saved copy instead of orig_sp as this will have the correct endianness */ | |
1147 | write_memory (new_sp, (char *) saved_regs + REGISTER_BYTE (S390_SP_REGNUM), | |
1148 | S390_GPR_SIZE); | |
1149 | write_memory (new_sp + S390_GPR_SIZE, (char *) &saved_regs, REGISTER_BYTES); | |
1150 | write_register (S390_SP_REGNUM, new_sp); | |
1151 | } | |
1152 | ||
4c8287ac JB |
1153 | |
1154 | static void | |
1155 | s390_pop_frame_regular (struct frame_info *frame) | |
5769d3cd | 1156 | { |
4c8287ac JB |
1157 | int regnum; |
1158 | ||
1159 | write_register (S390_PC_REGNUM, FRAME_SAVED_PC (frame)); | |
1160 | ||
1161 | /* Restore any saved registers. */ | |
1162 | for (regnum = 0; regnum < NUM_REGS; regnum++) | |
1163 | if (frame->saved_regs[regnum] != 0) | |
1164 | { | |
1165 | ULONGEST value; | |
1166 | ||
1167 | value = read_memory_unsigned_integer (frame->saved_regs[regnum], | |
1168 | REGISTER_RAW_SIZE (regnum)); | |
1169 | write_register (regnum, value); | |
1170 | } | |
5769d3cd | 1171 | |
9a1befc9 JB |
1172 | /* Actually cut back the stack. Remember that the SP's element of |
1173 | saved_regs is the old SP itself, not the address at which it is | |
1174 | saved. */ | |
1175 | write_register (S390_SP_REGNUM, frame->saved_regs[S390_SP_REGNUM]); | |
5769d3cd | 1176 | |
4c8287ac JB |
1177 | /* Throw away any cached frame information. */ |
1178 | flush_cached_frames (); | |
5769d3cd AC |
1179 | } |
1180 | ||
4c8287ac JB |
1181 | |
1182 | /* Destroy the innermost (Top-Of-Stack) stack frame, restoring the | |
1183 | machine state that was in effect before the frame was created. | |
1184 | Used in the contexts of the "return" command, and of | |
1185 | target function calls from the debugger. */ | |
1186 | void | |
1187 | s390_pop_frame () | |
1188 | { | |
1189 | /* This function checks for and handles generic dummy frames, and | |
1190 | calls back to our function for ordinary frames. */ | |
1191 | generic_pop_current_frame (s390_pop_frame_regular); | |
1192 | } | |
1193 | ||
1194 | ||
78f8b424 JB |
1195 | /* Return non-zero if TYPE is an integer-like type, zero otherwise. |
1196 | "Integer-like" types are those that should be passed the way | |
1197 | integers are: integers, enums, ranges, characters, and booleans. */ | |
1198 | static int | |
1199 | is_integer_like (struct type *type) | |
1200 | { | |
1201 | enum type_code code = TYPE_CODE (type); | |
1202 | ||
1203 | return (code == TYPE_CODE_INT | |
1204 | || code == TYPE_CODE_ENUM | |
1205 | || code == TYPE_CODE_RANGE | |
1206 | || code == TYPE_CODE_CHAR | |
1207 | || code == TYPE_CODE_BOOL); | |
1208 | } | |
1209 | ||
1210 | ||
1211 | /* Return non-zero if TYPE is a pointer-like type, zero otherwise. | |
1212 | "Pointer-like" types are those that should be passed the way | |
1213 | pointers are: pointers and references. */ | |
1214 | static int | |
1215 | is_pointer_like (struct type *type) | |
1216 | { | |
1217 | enum type_code code = TYPE_CODE (type); | |
1218 | ||
1219 | return (code == TYPE_CODE_PTR | |
1220 | || code == TYPE_CODE_REF); | |
1221 | } | |
1222 | ||
1223 | ||
1224 | /* Return non-zero if TYPE is considered a `DOUBLE_OR_FLOAT', as | |
1225 | defined by the parameter passing conventions described in the | |
1226 | "Linux for S/390 ELF Application Binary Interface Supplement". | |
1227 | Otherwise, return zero. */ | |
1228 | static int | |
1229 | is_double_or_float (struct type *type) | |
1230 | { | |
1231 | return (TYPE_CODE (type) == TYPE_CODE_FLT | |
1232 | && (TYPE_LENGTH (type) == 4 | |
1233 | || TYPE_LENGTH (type) == 8)); | |
1234 | } | |
1235 | ||
5769d3cd | 1236 | |
78f8b424 JB |
1237 | /* Return non-zero if TYPE is considered a `SIMPLE_ARG', as defined by |
1238 | the parameter passing conventions described in the "Linux for S/390 | |
1239 | ELF Application Binary Interface Supplement". Return zero otherwise. */ | |
1240 | static int | |
1241 | is_simple_arg (struct type *type) | |
1242 | { | |
1243 | enum type_code code = TYPE_CODE (type); | |
1244 | unsigned length = TYPE_LENGTH (type); | |
1245 | ||
1246 | return ((is_integer_like (type) && length <= 4) | |
1247 | || is_pointer_like (type) | |
1248 | || code == TYPE_CODE_STRUCT | |
1249 | || code == TYPE_CODE_UNION | |
1250 | || (code == TYPE_CODE_FLT && length == 16)); | |
1251 | } | |
1252 | ||
1253 | ||
1254 | /* Return non-zero if TYPE should be passed as a pointer to a copy, | |
1255 | zero otherwise. TYPE must be a SIMPLE_ARG, as recognized by | |
1256 | `is_simple_arg'. */ | |
1257 | static int | |
1258 | pass_by_copy_ref (struct type *type) | |
1259 | { | |
1260 | enum type_code code = TYPE_CODE (type); | |
1261 | unsigned length = TYPE_LENGTH (type); | |
1262 | ||
1263 | return (((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION) | |
1264 | && length != 1 && length != 2 && length != 4) | |
1265 | || (code == TYPE_CODE_FLT && length == 16)); | |
1266 | } | |
1267 | ||
1268 | ||
1269 | /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full | |
1270 | word as required for the ABI. */ | |
1271 | static LONGEST | |
1272 | extend_simple_arg (struct value *arg) | |
1273 | { | |
1274 | struct type *type = VALUE_TYPE (arg); | |
1275 | ||
1276 | /* Even structs get passed in the least significant bits of the | |
1277 | register / memory word. It's not really right to extract them as | |
1278 | an integer, but it does take care of the extension. */ | |
1279 | if (TYPE_UNSIGNED (type)) | |
1280 | return extract_unsigned_integer (VALUE_CONTENTS (arg), | |
1281 | TYPE_LENGTH (type)); | |
1282 | else | |
1283 | return extract_signed_integer (VALUE_CONTENTS (arg), | |
1284 | TYPE_LENGTH (type)); | |
1285 | } | |
1286 | ||
1287 | ||
1288 | /* Return non-zero if TYPE is a `DOUBLE_ARG', as defined by the | |
1289 | parameter passing conventions described in the "Linux for S/390 ELF | |
1290 | Application Binary Interface Supplement". Return zero otherwise. */ | |
1291 | static int | |
1292 | is_double_arg (struct type *type) | |
1293 | { | |
1294 | enum type_code code = TYPE_CODE (type); | |
1295 | unsigned length = TYPE_LENGTH (type); | |
1296 | ||
1297 | return ((is_integer_like (type) | |
1298 | || code == TYPE_CODE_STRUCT | |
1299 | || code == TYPE_CODE_UNION) | |
1300 | && length == 8); | |
1301 | } | |
1302 | ||
1303 | ||
1304 | /* Round ADDR up to the next N-byte boundary. N must be a power of | |
1305 | two. */ | |
1306 | static CORE_ADDR | |
1307 | round_up (CORE_ADDR addr, int n) | |
1308 | { | |
1309 | /* Check that N is really a power of two. */ | |
1310 | gdb_assert (n && (n & (n-1)) == 0); | |
1311 | return ((addr + n - 1) & -n); | |
1312 | } | |
1313 | ||
1314 | ||
1315 | /* Round ADDR down to the next N-byte boundary. N must be a power of | |
1316 | two. */ | |
1317 | static CORE_ADDR | |
1318 | round_down (CORE_ADDR addr, int n) | |
1319 | { | |
1320 | /* Check that N is really a power of two. */ | |
1321 | gdb_assert (n && (n & (n-1)) == 0); | |
1322 | return (addr & -n); | |
1323 | } | |
1324 | ||
1325 | ||
1326 | /* Return the alignment required by TYPE. */ | |
1327 | static int | |
1328 | alignment_of (struct type *type) | |
1329 | { | |
1330 | int alignment; | |
1331 | ||
1332 | if (is_integer_like (type) | |
1333 | || is_pointer_like (type) | |
1334 | || TYPE_CODE (type) == TYPE_CODE_FLT) | |
1335 | alignment = TYPE_LENGTH (type); | |
1336 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1337 | || TYPE_CODE (type) == TYPE_CODE_UNION) | |
1338 | { | |
1339 | int i; | |
1340 | ||
1341 | alignment = 1; | |
1342 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
1343 | { | |
1344 | int field_alignment = alignment_of (TYPE_FIELD_TYPE (type, i)); | |
1345 | ||
1346 | if (field_alignment > alignment) | |
1347 | alignment = field_alignment; | |
1348 | } | |
1349 | } | |
1350 | else | |
1351 | alignment = 1; | |
1352 | ||
1353 | /* Check that everything we ever return is a power of two. Lots of | |
1354 | code doesn't want to deal with aligning things to arbitrary | |
1355 | boundaries. */ | |
1356 | gdb_assert ((alignment & (alignment - 1)) == 0); | |
1357 | ||
1358 | return alignment; | |
1359 | } | |
1360 | ||
1361 | ||
1362 | /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in | |
1363 | place to be passed to a function, as specified by the "Linux for | |
1364 | S/390 ELF Application Binary Interface Supplement". | |
1365 | ||
1366 | SP is the current stack pointer. We must put arguments, links, | |
1367 | padding, etc. whereever they belong, and return the new stack | |
1368 | pointer value. | |
1369 | ||
1370 | If STRUCT_RETURN is non-zero, then the function we're calling is | |
1371 | going to return a structure by value; STRUCT_ADDR is the address of | |
1372 | a block we've allocated for it on the stack. | |
1373 | ||
1374 | Our caller has taken care of any type promotions needed to satisfy | |
1375 | prototypes or the old K&R argument-passing rules. */ | |
5769d3cd | 1376 | CORE_ADDR |
d45fc520 | 1377 | s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp, |
5769d3cd AC |
1378 | int struct_return, CORE_ADDR struct_addr) |
1379 | { | |
78f8b424 JB |
1380 | int i; |
1381 | int pointer_size = (TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
5769d3cd | 1382 | |
78f8b424 JB |
1383 | /* The number of arguments passed by reference-to-copy. */ |
1384 | int num_copies; | |
5769d3cd | 1385 | |
78f8b424 JB |
1386 | /* If the i'th argument is passed as a reference to a copy, then |
1387 | copy_addr[i] is the address of the copy we made. */ | |
1388 | CORE_ADDR *copy_addr = alloca (nargs * sizeof (CORE_ADDR)); | |
5769d3cd | 1389 | |
78f8b424 JB |
1390 | /* Build the reference-to-copy area. */ |
1391 | num_copies = 0; | |
1392 | for (i = 0; i < nargs; i++) | |
1393 | { | |
1394 | struct value *arg = args[i]; | |
1395 | struct type *type = VALUE_TYPE (arg); | |
1396 | unsigned length = TYPE_LENGTH (type); | |
5769d3cd | 1397 | |
78f8b424 JB |
1398 | if (is_simple_arg (type) |
1399 | && pass_by_copy_ref (type)) | |
01c464e9 | 1400 | { |
78f8b424 JB |
1401 | sp -= length; |
1402 | sp = round_down (sp, alignment_of (type)); | |
1403 | write_memory (sp, VALUE_CONTENTS (arg), length); | |
1404 | copy_addr[i] = sp; | |
1405 | num_copies++; | |
01c464e9 | 1406 | } |
5769d3cd | 1407 | } |
5769d3cd | 1408 | |
78f8b424 JB |
1409 | /* Reserve space for the parameter area. As a conservative |
1410 | simplification, we assume that everything will be passed on the | |
1411 | stack. */ | |
1412 | { | |
1413 | int i; | |
1414 | ||
1415 | for (i = 0; i < nargs; i++) | |
1416 | { | |
1417 | struct value *arg = args[i]; | |
1418 | struct type *type = VALUE_TYPE (arg); | |
1419 | int length = TYPE_LENGTH (type); | |
1420 | ||
1421 | sp = round_down (sp, alignment_of (type)); | |
1422 | ||
1423 | /* SIMPLE_ARG values get extended to 32 bits. Assume every | |
1424 | argument is. */ | |
1425 | if (length < 4) length = 4; | |
1426 | sp -= length; | |
1427 | } | |
1428 | } | |
1429 | ||
1430 | /* Include space for any reference-to-copy pointers. */ | |
1431 | sp = round_down (sp, pointer_size); | |
1432 | sp -= num_copies * pointer_size; | |
1433 | ||
1434 | /* After all that, make sure it's still aligned on an eight-byte | |
1435 | boundary. */ | |
1436 | sp = round_down (sp, 8); | |
1437 | ||
1438 | /* Finally, place the actual parameters, working from SP towards | |
1439 | higher addresses. The code above is supposed to reserve enough | |
1440 | space for this. */ | |
1441 | { | |
1442 | int fr = 0; | |
1443 | int gr = 2; | |
1444 | CORE_ADDR starg = sp; | |
1445 | ||
1446 | for (i = 0; i < nargs; i++) | |
1447 | { | |
1448 | struct value *arg = args[i]; | |
1449 | struct type *type = VALUE_TYPE (arg); | |
1450 | ||
1451 | if (is_double_or_float (type) | |
1452 | && fr <= 2) | |
1453 | { | |
1454 | /* When we store a single-precision value in an FP register, | |
1455 | it occupies the leftmost bits. */ | |
1456 | write_register_bytes (REGISTER_BYTE (S390_FP0_REGNUM + fr), | |
1457 | VALUE_CONTENTS (arg), | |
1458 | TYPE_LENGTH (type)); | |
1459 | fr += 2; | |
1460 | } | |
1461 | else if (is_simple_arg (type) | |
1462 | && gr <= 6) | |
1463 | { | |
1464 | /* Do we need to pass a pointer to our copy of this | |
1465 | argument? */ | |
1466 | if (pass_by_copy_ref (type)) | |
1467 | write_register (S390_GP0_REGNUM + gr, copy_addr[i]); | |
1468 | else | |
1469 | write_register (S390_GP0_REGNUM + gr, extend_simple_arg (arg)); | |
1470 | ||
1471 | gr++; | |
1472 | } | |
1473 | else if (is_double_arg (type) | |
1474 | && gr <= 5) | |
1475 | { | |
1476 | write_register_gen (S390_GP0_REGNUM + gr, | |
1477 | VALUE_CONTENTS (arg)); | |
1478 | write_register_gen (S390_GP0_REGNUM + gr + 1, | |
1479 | VALUE_CONTENTS (arg) + 4); | |
1480 | gr += 2; | |
1481 | } | |
1482 | else | |
1483 | { | |
1484 | /* The `OTHER' case. */ | |
1485 | enum type_code code = TYPE_CODE (type); | |
1486 | unsigned length = TYPE_LENGTH (type); | |
1487 | ||
1488 | /* If we skipped r6 because we couldn't fit a DOUBLE_ARG | |
1489 | in it, then don't go back and use it again later. */ | |
1490 | if (is_double_arg (type) && gr == 6) | |
1491 | gr = 7; | |
1492 | ||
1493 | if (is_simple_arg (type)) | |
1494 | { | |
1495 | /* Simple args are always either extended to 32 bits, | |
1496 | or pointers. */ | |
1497 | starg = round_up (starg, 4); | |
1498 | ||
1499 | /* Do we need to pass a pointer to our copy of this | |
1500 | argument? */ | |
1501 | if (pass_by_copy_ref (type)) | |
1502 | write_memory_signed_integer (starg, pointer_size, | |
1503 | copy_addr[i]); | |
1504 | else | |
1505 | /* Simple args are always extended to 32 bits. */ | |
1506 | write_memory_signed_integer (starg, 4, | |
1507 | extend_simple_arg (arg)); | |
1508 | starg += 4; | |
1509 | } | |
1510 | else | |
1511 | { | |
1512 | starg = round_up (starg, alignment_of (type)); | |
1513 | write_memory (starg, VALUE_CONTENTS (arg), length); | |
1514 | starg += length; | |
1515 | } | |
1516 | } | |
1517 | } | |
1518 | } | |
1519 | ||
1520 | /* Allocate the standard frame areas: the register save area, the | |
1521 | word reserved for the compiler (which seems kind of meaningless), | |
1522 | and the back chain pointer. */ | |
1523 | sp -= 96; | |
1524 | ||
1525 | /* Write the back chain pointer into the first word of the stack | |
1526 | frame. This will help us get backtraces from within functions | |
1527 | called from GDB. */ | |
1528 | write_memory_unsigned_integer (sp, (TARGET_PTR_BIT / TARGET_CHAR_BIT), | |
1529 | read_fp ()); | |
1530 | ||
1531 | return sp; | |
5769d3cd AC |
1532 | } |
1533 | ||
5769d3cd AC |
1534 | /* Return the GDB type object for the "standard" data type |
1535 | of data in register N. */ | |
1536 | struct type * | |
1537 | s390_register_virtual_type (int regno) | |
1538 | { | |
1539 | return ((unsigned) regno - S390_FPC_REGNUM) < | |
1540 | S390_NUM_FPRS ? builtin_type_double : builtin_type_int; | |
1541 | } | |
1542 | ||
1543 | ||
1544 | struct type * | |
1545 | s390x_register_virtual_type (int regno) | |
1546 | { | |
1547 | return (regno == S390_FPC_REGNUM) || | |
1548 | (regno >= S390_FIRST_ACR && regno <= S390_LAST_ACR) ? builtin_type_int : | |
1549 | (regno >= S390_FP0_REGNUM) ? builtin_type_double : builtin_type_long; | |
1550 | } | |
1551 | ||
1552 | ||
1553 | ||
1554 | void | |
1555 | s390_store_struct_return (CORE_ADDR addr, CORE_ADDR sp) | |
1556 | { | |
1557 | write_register (S390_GP0_REGNUM + 2, addr); | |
1558 | } | |
1559 | ||
1560 | ||
1561 | ||
1562 | static unsigned char * | |
1563 | s390_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) | |
1564 | { | |
1565 | static unsigned char breakpoint[] = { 0x0, 0x1 }; | |
1566 | ||
1567 | *lenptr = sizeof (breakpoint); | |
1568 | return breakpoint; | |
1569 | } | |
1570 | ||
1571 | /* Advance PC across any function entry prologue instructions to reach some | |
1572 | "real" code. */ | |
1573 | CORE_ADDR | |
1574 | s390_skip_prologue (CORE_ADDR pc) | |
1575 | { | |
1576 | struct frame_extra_info fextra_info; | |
1577 | ||
1578 | s390_get_frame_info (pc, &fextra_info, NULL, 1); | |
1579 | return fextra_info.skip_prologue_function_start; | |
1580 | } | |
1581 | ||
5769d3cd AC |
1582 | /* Immediately after a function call, return the saved pc. |
1583 | Can't go through the frames for this because on some machines | |
1584 | the new frame is not set up until the new function executes | |
1585 | some instructions. */ | |
1586 | CORE_ADDR | |
1587 | s390_saved_pc_after_call (struct frame_info *frame) | |
1588 | { | |
1589 | return ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM)); | |
1590 | } | |
1591 | ||
1592 | static CORE_ADDR | |
1593 | s390_addr_bits_remove (CORE_ADDR addr) | |
1594 | { | |
1595 | return (addr) & 0x7fffffff; | |
1596 | } | |
1597 | ||
1598 | ||
1599 | static CORE_ADDR | |
1600 | s390_push_return_address (CORE_ADDR pc, CORE_ADDR sp) | |
1601 | { | |
d4d0c21e | 1602 | write_register (S390_RETADDR_REGNUM, CALL_DUMMY_ADDRESS ()); |
5769d3cd AC |
1603 | return sp; |
1604 | } | |
1605 | ||
1606 | struct gdbarch * | |
1607 | s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
1608 | { | |
d4d0c21e | 1609 | static LONGEST s390_call_dummy_words[] = { 0 }; |
5769d3cd AC |
1610 | struct gdbarch *gdbarch; |
1611 | struct gdbarch_tdep *tdep; | |
1612 | int elf_flags; | |
1613 | ||
1614 | /* First see if there is already a gdbarch that can satisfy the request. */ | |
1615 | arches = gdbarch_list_lookup_by_info (arches, &info); | |
1616 | if (arches != NULL) | |
1617 | return arches->gdbarch; | |
1618 | ||
1619 | /* None found: is the request for a s390 architecture? */ | |
1620 | if (info.bfd_arch_info->arch != bfd_arch_s390) | |
1621 | return NULL; /* No; then it's not for us. */ | |
1622 | ||
1623 | /* Yes: create a new gdbarch for the specified machine type. */ | |
1624 | gdbarch = gdbarch_alloc (&info, NULL); | |
1625 | ||
1626 | set_gdbarch_believe_pcc_promotion (gdbarch, 0); | |
1627 | ||
5769d3cd AC |
1628 | set_gdbarch_frame_args_skip (gdbarch, 0); |
1629 | set_gdbarch_frame_args_address (gdbarch, s390_frame_args_address); | |
1630 | set_gdbarch_frame_chain (gdbarch, s390_frame_chain); | |
1631 | set_gdbarch_frame_init_saved_regs (gdbarch, s390_frame_init_saved_regs); | |
1632 | set_gdbarch_frame_locals_address (gdbarch, s390_frame_args_address); | |
1633 | /* We can't do this */ | |
1634 | set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown); | |
1635 | set_gdbarch_store_struct_return (gdbarch, s390_store_struct_return); | |
1636 | set_gdbarch_extract_return_value (gdbarch, s390_extract_return_value); | |
1637 | set_gdbarch_store_return_value (gdbarch, s390_store_return_value); | |
1638 | /* Amount PC must be decremented by after a breakpoint. | |
1639 | This is often the number of bytes in BREAKPOINT | |
1640 | but not always. */ | |
1641 | set_gdbarch_decr_pc_after_break (gdbarch, 2); | |
1642 | set_gdbarch_pop_frame (gdbarch, s390_pop_frame); | |
5769d3cd AC |
1643 | set_gdbarch_ieee_float (gdbarch, 1); |
1644 | /* Stack grows downward. */ | |
1645 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
1646 | /* Offset from address of function to start of its code. | |
1647 | Zero on most machines. */ | |
1648 | set_gdbarch_function_start_offset (gdbarch, 0); | |
1649 | set_gdbarch_max_register_raw_size (gdbarch, 8); | |
1650 | set_gdbarch_max_register_virtual_size (gdbarch, 8); | |
1651 | set_gdbarch_breakpoint_from_pc (gdbarch, s390_breakpoint_from_pc); | |
1652 | set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue); | |
1653 | set_gdbarch_init_extra_frame_info (gdbarch, s390_init_extra_frame_info); | |
1654 | set_gdbarch_init_frame_pc_first (gdbarch, s390_init_frame_pc_first); | |
1655 | set_gdbarch_read_fp (gdbarch, s390_read_fp); | |
1656 | set_gdbarch_write_fp (gdbarch, s390_write_fp); | |
1657 | /* This function that tells us whether the function invocation represented | |
1658 | by FI does not have a frame on the stack associated with it. If it | |
1659 | does not, FRAMELESS is set to 1, else 0. */ | |
1660 | set_gdbarch_frameless_function_invocation (gdbarch, | |
1661 | s390_frameless_function_invocation); | |
1662 | /* Return saved PC from a frame */ | |
1663 | set_gdbarch_frame_saved_pc (gdbarch, s390_frame_saved_pc); | |
1664 | /* FRAME_CHAIN takes a frame's nominal address | |
1665 | and produces the frame's chain-pointer. */ | |
1666 | set_gdbarch_frame_chain (gdbarch, s390_frame_chain); | |
1667 | set_gdbarch_saved_pc_after_call (gdbarch, s390_saved_pc_after_call); | |
1668 | set_gdbarch_register_byte (gdbarch, s390_register_byte); | |
1669 | set_gdbarch_pc_regnum (gdbarch, S390_PC_REGNUM); | |
1670 | set_gdbarch_sp_regnum (gdbarch, S390_SP_REGNUM); | |
1671 | set_gdbarch_fp_regnum (gdbarch, S390_FP_REGNUM); | |
1672 | set_gdbarch_fp0_regnum (gdbarch, S390_FP0_REGNUM); | |
1673 | set_gdbarch_num_regs (gdbarch, S390_NUM_REGS); | |
1674 | set_gdbarch_cannot_fetch_register (gdbarch, s390_cannot_fetch_register); | |
1675 | set_gdbarch_cannot_store_register (gdbarch, s390_cannot_fetch_register); | |
1676 | set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register); | |
1677 | set_gdbarch_use_struct_convention (gdbarch, generic_use_struct_convention); | |
8001d1e4 | 1678 | set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); |
5769d3cd AC |
1679 | set_gdbarch_register_name (gdbarch, s390_register_name); |
1680 | set_gdbarch_stab_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
1681 | set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
1682 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); | |
5769d3cd | 1683 | |
d4d0c21e | 1684 | /* Parameters for inferior function calls. */ |
5769d3cd | 1685 | set_gdbarch_call_dummy_p (gdbarch, 1); |
d4d0c21e JB |
1686 | set_gdbarch_use_generic_dummy_frames (gdbarch, 1); |
1687 | set_gdbarch_call_dummy_length (gdbarch, 0); | |
1688 | set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT); | |
1689 | set_gdbarch_call_dummy_address (gdbarch, entry_point_address); | |
1690 | set_gdbarch_call_dummy_start_offset (gdbarch, 0); | |
1691 | set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_at_entry_point); | |
1692 | set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame); | |
1693 | set_gdbarch_push_arguments (gdbarch, s390_push_arguments); | |
1694 | set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1); | |
1695 | set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0); | |
5769d3cd AC |
1696 | set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0); |
1697 | set_gdbarch_extract_struct_value_address (gdbarch, 0); | |
d4d0c21e | 1698 | set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy); |
5769d3cd | 1699 | set_gdbarch_push_return_address (gdbarch, s390_push_return_address); |
d4d0c21e JB |
1700 | set_gdbarch_sizeof_call_dummy_words (gdbarch, |
1701 | sizeof (s390_call_dummy_words)); | |
1702 | set_gdbarch_call_dummy_words (gdbarch, s390_call_dummy_words); | |
0adb2aba JB |
1703 | set_gdbarch_coerce_float_to_double (gdbarch, |
1704 | standard_coerce_float_to_double); | |
5769d3cd AC |
1705 | |
1706 | switch (info.bfd_arch_info->mach) | |
1707 | { | |
1708 | case bfd_mach_s390_esa: | |
1709 | set_gdbarch_register_size (gdbarch, 4); | |
5769d3cd AC |
1710 | set_gdbarch_register_raw_size (gdbarch, s390_register_raw_size); |
1711 | set_gdbarch_register_virtual_size (gdbarch, s390_register_raw_size); | |
1712 | set_gdbarch_register_virtual_type (gdbarch, s390_register_virtual_type); | |
1713 | ||
1714 | set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove); | |
5769d3cd AC |
1715 | set_gdbarch_register_bytes (gdbarch, S390_REGISTER_BYTES); |
1716 | break; | |
1717 | case bfd_mach_s390_esame: | |
1718 | set_gdbarch_register_size (gdbarch, 8); | |
5769d3cd AC |
1719 | set_gdbarch_register_raw_size (gdbarch, s390x_register_raw_size); |
1720 | set_gdbarch_register_virtual_size (gdbarch, s390x_register_raw_size); | |
1721 | set_gdbarch_register_virtual_type (gdbarch, | |
1722 | s390x_register_virtual_type); | |
1723 | ||
1724 | set_gdbarch_long_bit (gdbarch, 64); | |
1725 | set_gdbarch_long_long_bit (gdbarch, 64); | |
1726 | set_gdbarch_ptr_bit (gdbarch, 64); | |
5769d3cd AC |
1727 | set_gdbarch_register_bytes (gdbarch, S390X_REGISTER_BYTES); |
1728 | break; | |
1729 | } | |
1730 | ||
1731 | return gdbarch; | |
1732 | } | |
1733 | ||
1734 | ||
1735 | ||
1736 | void | |
1737 | _initialize_s390_tdep () | |
1738 | { | |
1739 | ||
1740 | /* Hook us into the gdbarch mechanism. */ | |
1741 | register_gdbarch_init (bfd_arch_s390, s390_gdbarch_init); | |
1742 | if (!tm_print_insn) /* Someone may have already set it */ | |
1743 | tm_print_insn = gdb_print_insn_s390; | |
1744 | } | |
1745 | ||
1746 | #endif /* GDBSERVER */ |