1 /* Copyright (C) 1988, 1990 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include <sys/types.h>
30 #include <sys/param.h>
35 #ifndef USER /* added to support BCS ptrace_user */
37 #define USER ptrace_user
39 #include <sys/ioctl.h>
53 tdesc_error_function (environment
, continuable
, message
)
54 dc_word_t environment
;
55 dc_boolean_t continuable
;
58 if (stack_error
) longjmp (stack_jmp
, 1);
61 printf("%s\n",message
);
68 tdesc_read_function (environment
, memory
, length
, buffer
)
69 dc_word_t environment
;
78 /* This is a no-op! It sets buffer, but doesn't do anything to
79 what buffer points to. What does this function do anyway?
80 And this is wrong for cross-debugging. */
81 buffer
= ptrace (3, inferior_pid
, memory
, 0);
86 read_memory (memory
, buffer
, length
);
89 /* Map function for tdesc */
91 tdesc_map_function (map_env
, loc
, map_info_in
, map_info_out
)
94 dc_map_info_in_t map_info_in
;
95 dc_map_info_out_t
*map_info_out
;
97 int map_flags
= DC_MIO_ENTRY_POINT
| DC_MIO_IMPLICIT_PROLOGUE_END
;
98 int entry_point
= get_pc_function_start(loc
);
99 map_info_out
->flags
= map_flags
;
100 map_info_out
->entry_point
= entry_point
;
103 dc_handle_t tdesc_handle
;
105 extern int debug_info
;
110 tdesc_handle
= dc_initiate (debug_info
, tdesc_error_function
,
111 0,tdesc_read_function
,0,0,0,0,0,tdesc_map_function
,0);
113 dc_dcontext_t current_context
;
115 /* setup current context, called from wait_for_inferior */
120 dc_word_t reg_info
[DC_NUM_REG
];
121 dc_word_t reg_flags
[2] = {0,-1};
122 dc_word_t aux_info
[DC_NUM_AUX
];
123 dc_word_t aux_flags
[2] = {0,-1};
124 dc_exactness_t loc_exact
= DC_NO
;
126 dc_boolean_t psr_ind
= 0;
127 dc_word_t psr_flags
[2] = {0,-1};
129 bcopy (®isters
, reg_info
, DC_NUM_REG
* 4);
130 aux_info
[DC_AUX_LOC
] = read_register(SXIP_REGNUM
);
131 aux_info
[DC_AUX_SXIP
] = read_register(SXIP_REGNUM
);
132 aux_info
[DC_AUX_SNIP
] = read_register(SNIP_REGNUM
);
133 aux_info
[DC_AUX_SFIP
] = read_register(SFIP_REGNUM
);
134 aux_info
[DC_AUX_FPSR
] = read_register(FPSR_REGNUM
);
135 aux_info
[DC_AUX_FPCR
] = read_register(FPCR_REGNUM
);
137 psr_info
= read_register(PSR_REGNUM
);
139 return dc_make_dcontext (tdesc_handle
, reg_info
, reg_flags
, aux_info
,
140 aux_flags
, loc_exact
, psr_info
, psr_ind
, psr_flags
);
145 get_prev_context (context
)
146 dc_dcontext_t context
;
148 return current_context
= dc_previous_dcontext (context
);
154 /* Determine frame base for this file's frames. This will be either
155 the CFA or the old style FP_REGNUM; the symtab for the current pc's
156 file has the information */
162 struct symtab
*this_file
= find_pc_symtab(pc
);
163 int coffsem_frame_position
;
165 /* If this_file is null, there's a good chance the file was compiled
166 without -g. If that's the case, use CFA (canonical frame addr)
167 as the default frame pointer. */
171 coffsem_frame_position
= this_file
->coffsem
& 3;
172 if (coffsem_frame_position
== 1)
173 return (CORE_ADDR
) dc_general_register (current_context
, FP_REGNUM
);
175 /* default is CFA, as well as if coffsem==2 */
176 return (CORE_ADDR
) dc_frame_address (current_context
);
179 return (CORE_ADDR
) dc_frame_address (current_context
);
182 #if TARGET_BYTE_ORDER != HOST_BYTE_ORDER
184 #else /* Host and target byte order the same. */
185 #define SINGLE_EXP_BITS 8
186 #define DOUBLE_EXP_BITS 11
190 /* fp points to a single precision OR double precision
191 * floating point value; len is the number of bytes, either 4 or 8.
192 * Returns 1 iff fp points to a valid IEEE floating point number.
193 * Returns 0 if fp points to a denormalized number or a NaN
200 exponent
= exponent
<< 1 >> (32 - SINGLE_EXP_BITS
- 1);
201 return ((exponent
== -1) || (! exponent
&& *fp
));
206 exponent
= exponent
<< 1 >> (32 - DOUBLE_EXP_BITS
- 1);
207 return ((exponent
== -1) || (! exponent
&& *fp
* *(fp
+1)));
211 #endif /* Host and target byte order the same. */
213 #define FIRST_PRESERVED_REGNUM 14
214 #define LAST_PRESERVED_REGNUM 25
215 #define FIRST_PARM_REGNUM 2
216 #define LAST_PARM_REGNUM 9
218 #define MAX_REG_PARMS (LAST_PARM_REGNUM - FIRST_PARM_REGNUM + 1)
221 frame_find_saved_regs (fi
, fsr
)
222 struct frame_info
*fi
;
223 struct frame_saved_regs
*fsr
;
227 error ("Feature not implemented for the 88k yet.");
231 for (regnum
= FIRST_PARM_REGNUM
; regnum
<= LAST_PARM_REGNUM
; regnum
++)
233 = (unsigned) fi
->frame
- ((regnum
- FIRST_PARM_REGNUM
) * 4);
235 fsr
->regs
[SP_REGNUM
] = 0; /* SP not saved in frames */
236 fsr
->regs
[FP_REGNUM
] = fi
->frame
;
237 fsr
->regs
[PC_REGNUM
] = fi
->frame
+ 4;
242 pushed_size (prev_words
, v
)
246 switch (TYPE_CODE (VALUE_TYPE (v
)))
248 case TYPE_CODE_VOID
: /* Void type (values zero length) */
250 return 0; /* That was easy! */
252 case TYPE_CODE_PTR
: /* Pointer type */
253 case TYPE_CODE_ENUM
: /* Enumeration type */
254 case TYPE_CODE_INT
: /* Integer type */
255 case TYPE_CODE_REF
: /* C++ Reference types */
256 case TYPE_CODE_ARRAY
: /* Array type, lower bound zero */
260 case TYPE_CODE_FLT
: /* Floating type */
262 if (TYPE_LENGTH (VALUE_TYPE (v
)) == 4)
265 /* Assume that it must be a double. */
266 if (prev_words
& 1) /* at an odd-word boundary */
267 return 3; /* round to 8-byte boundary */
271 case TYPE_CODE_STRUCT
: /* C struct or Pascal record */
272 case TYPE_CODE_UNION
: /* C union or Pascal variant part */
274 return (((TYPE_LENGTH (VALUE_TYPE (v
)) + 3) / 4) * 4);
276 case TYPE_CODE_FUNC
: /* Function type */
277 case TYPE_CODE_SET
: /* Pascal sets */
278 case TYPE_CODE_RANGE
: /* Range (integers within bounds) */
279 case TYPE_CODE_PASCAL_ARRAY
: /* Array with explicit type of index */
280 case TYPE_CODE_MEMBER
: /* Member type */
281 case TYPE_CODE_METHOD
: /* Method type */
282 /* Don't know how to pass these yet. */
284 case TYPE_CODE_UNDEF
: /* Not used; catches errors */
291 store_parm_word (address
, val
)
295 write_memory (address
, &val
, 4);
299 store_parm (prev_words
, left_parm_addr
, v
)
300 unsigned int prev_words
;
301 CORE_ADDR left_parm_addr
;
304 CORE_ADDR start
= left_parm_addr
+ (prev_words
* 4);
305 int *val_addr
= (int *)VALUE_CONTENTS(v
);
307 switch (TYPE_CODE (VALUE_TYPE (v
)))
309 case TYPE_CODE_VOID
: /* Void type (values zero length) */
313 case TYPE_CODE_PTR
: /* Pointer type */
314 case TYPE_CODE_ENUM
: /* Enumeration type */
315 case TYPE_CODE_INT
: /* Integer type */
316 case TYPE_CODE_ARRAY
: /* Array type, lower bound zero */
317 case TYPE_CODE_REF
: /* C++ Reference types */
319 store_parm_word (start
, *val_addr
);
322 case TYPE_CODE_FLT
: /* Floating type */
324 if (TYPE_LENGTH (VALUE_TYPE (v
)) == 4)
326 store_parm_word (start
, *val_addr
);
331 store_parm_word (start
+ ((prev_words
& 1) * 4), val_addr
[0]);
332 store_parm_word (start
+ ((prev_words
& 1) * 4) + 4, val_addr
[1]);
333 return 2 + (prev_words
& 1);
336 case TYPE_CODE_STRUCT
: /* C struct or Pascal record */
337 case TYPE_CODE_UNION
: /* C union or Pascal variant part */
340 unsigned int words
= (((TYPE_LENGTH (VALUE_TYPE (v
)) + 3) / 4) * 4);
343 for (word
= 0; word
< words
; word
++)
344 store_parm_word (start
+ (word
* 4), val_addr
[word
]);
353 /* This routine sets up all of the parameter values needed to make a pseudo
354 call. The name "push_parameters" is a misnomer on some archs,
355 because (on the m88k) most parameters generally end up being passed in
356 registers rather than on the stack. In this routine however, we do
357 end up storing *all* parameter values onto the stack (even if we will
358 realize later that some of these stores were unnecessary). */
361 push_parameters (return_type
, struct_conv
, nargs
, args
)
362 struct type
*return_type
;
368 unsigned int p_words
= 0;
369 CORE_ADDR left_parm_addr
;
371 /* Start out by creating a space for the return value (if need be). We
372 only need to do this if the return value is a struct or union. If we
373 do make a space for a struct or union return value, then we must also
374 arrange for the base address of that space to go into r12, which is the
375 standard place to pass the address of the return value area to the
376 callee. Note that only structs and unions are returned in this fashion.
377 Ints, enums, pointers, and floats are returned into r2. Doubles are
378 returned into the register pair {r2,r3}. Note also that the space
379 reserved for a struct or union return value only has to be word aligned
380 (not double-word) but it is double-word aligned here anyway (just in
381 case that becomes important someday). */
383 switch (TYPE_CODE (return_type
))
385 case TYPE_CODE_STRUCT
:
386 case TYPE_CODE_UNION
:
388 int return_bytes
= ((TYPE_LENGTH (return_type
) + 7) / 8) * 8;
391 rv_addr
= read_register (SP_REGNUM
) - return_bytes
;
393 write_register (SP_REGNUM
, rv_addr
); /* push space onto the stack */
394 write_register (SRA_REGNUM
, rv_addr
);/* set return value register */
398 /* Here we make a pre-pass on the whole parameter list to figure out exactly
399 how many words worth of stuff we are going to pass. */
401 for (p_words
= 0, parm_num
= 0; parm_num
< nargs
; parm_num
++)
402 p_words
+= pushed_size (p_words
, value_arg_coerce (args
[parm_num
]));
404 /* Now, check to see if we have to round up the number of parameter words
405 to get up to the next 8-bytes boundary. This may be necessary because
406 of the software convention to always keep the stack aligned on an 8-byte
410 p_words
++; /* round to 8-byte boundary */
412 /* Now figure out the absolute address of the leftmost parameter, and update
413 the stack pointer to point at that address. */
415 left_parm_addr
= read_register (SP_REGNUM
) - (p_words
* 4);
416 write_register (SP_REGNUM
, left_parm_addr
);
418 /* Now we can go through all of the parameters (in left-to-right order)
419 and write them to their parameter stack slots. Note that we are not
420 really "pushing" the parameter values. The stack space for these values
421 was already allocated above. Now we are just filling it up. */
423 for (p_words
= 0, parm_num
= 0; parm_num
< nargs
; parm_num
++)
425 store_parm (p_words
, left_parm_addr
, value_arg_coerce (args
[parm_num
]));
427 /* Now that we are all done storing the parameter values into the stack, we
428 must go back and load up the parameter registers with the values from the
429 corresponding stack slots. Note that in the two cases of (a) gaps in the
430 parameter word sequence causes by (otherwise) misaligned doubles, and (b)
431 slots correcponding to structs or unions, the work we do here in loading
432 some parameter registers may be unnecessary, but who cares? */
434 for (p_words
= 0; p_words
< 8; p_words
++)
436 write_register (FIRST_PARM_REGNUM
+ p_words
,
437 read_memory_integer (left_parm_addr
+ (p_words
* 4), 4));
444 error ("Feature not implemented for the m88k yet.");
449 collect_returned_value (rval
, value_type
, struct_return
, nargs
, args
)
451 struct type
*value_type
;
456 char retbuf
[REGISTER_BYTES
];
458 bcopy (registers
, retbuf
, REGISTER_BYTES
);
459 *rval
= value_being_returned (value_type
, retbuf
, struct_return
);
464 /* Now handled in a machine independent way with CALL_DUMMY_LOCATION. */
465 /* Stuff a breakpoint instruction onto the stack (or elsewhere if the stack
466 is not a good place for it). Return the address at which the instruction
467 got stuffed, or zero if we were unable to stuff it anywhere. */
472 static char breakpoint_insn
[] = BREAKPOINT
;
473 extern CORE_ADDR text_end
; /* of inferior */
474 static char readback_buffer
[] = BREAKPOINT
;
477 /* With a little bit of luck, we can just stash the breakpoint instruction
478 in the word just beyond the end of normal text space. For systems on
479 which the hardware will not allow us to execute out of the stack segment,
480 we have to hope that we *are* at least allowed to effectively extend the
481 text segment by one word. If the actual end of user's the text segment
482 happens to fall right at a page boundary this trick may fail. Note that
483 we check for this by reading after writing, and comparing in order to
484 be sure that the write worked. */
486 write_memory (text_end
, &breakpoint_insn
, 4);
488 /* Fill the readback buffer with some garbage which is certain to be
489 unequal to the breakpoint insn. That way we can tell if the
490 following read doesn't actually succeed. */
492 for (i
= 0; i
< sizeof (readback_buffer
); i
++)
493 readback_buffer
[i
] = ~ readback_buffer
[i
]; /* Invert the bits */
495 /* Now check that the breakpoint insn was successfully installed. */
497 read_memory (text_end
, readback_buffer
, sizeof (readback_buffer
));
498 for (i
= 0; i
< sizeof (readback_buffer
); i
++)
499 if (readback_buffer
[i
] != breakpoint_insn
[i
])
500 return 0; /* Failed to install! */
506 /* Like dc_psr_register but takes an extra int arg. */
508 psr_register (context
, dummy
)
509 dc_dcontext_t context
;
512 return dc_psr_register (context
);
515 /* Same functionality as get_saved_register in findvar.c, but implemented
518 get_saved_register (raw_buffer
, optim
, addrp
, frame
, regnum
, lvalp
)
524 enum lval_type
*lvalp
;
526 struct frame_info
*fi
= get_frame_info (frame
);
528 /* Functions to say whether a register is optimized out, and
529 if not, to get the value. Take as args a context and the
530 value of get_reg_arg. */
531 int (*get_reg_state
) ();
532 dc_word_t (*get_reg
) ();
535 /* Because tdesc doesn't tell us whether it got it from a register
536 or memory, always say we don't have an address for it. */
540 if (regnum
< DC_NUM_REG
)
542 get_reg_state
= dc_general_register_state
;
543 get_reg
= dc_general_register
;
544 get_reg_arg
= regnum
;
548 get_reg_state
= dc_auxiliary_register_state
;
549 get_reg
= dc_auxiliary_register
;
553 get_reg_arg
= DC_AUX_SXIP
;
556 get_reg_arg
= DC_AUX_SNIP
;
559 get_reg_arg
= DC_AUX_FPSR
;
562 get_reg_arg
= DC_AUX_FPCR
;
565 get_reg_state
= dc_psr_register_bit_state
;
566 get_reg
= psr_register
;
576 if ((*get_reg_state
) (fi
->frame_context
, get_reg_arg
))
578 if (raw_buffer
!= NULL
)
579 *(int *)raw_buffer
= (*get_reg
) (fi
->frame_context
, get_reg_arg
);
591 /* Well, the caller can't treat it as a register or memory... */