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>
42 #ifdef COFF_ENCAPSULATE
43 #include "a.out.encap.h"
59 tdesc_error_function (environment, continuable, message)
60 dc_word_t environment;
61 dc_boolean_t continuable;
64 if (stack_error) longjmp (stack_jmp, 1);
67 printf("%s\n",message);
74 tdesc_read_function (environment, memory, length, buffer)
75 dc_word_t environment;
84 /* This is a no-op! It sets buffer, but doesn't do anything to
85 what buffer points to. What does this function do anyway?
86 And this is wrong for cross-debugging. */
87 buffer = ptrace (3, inferior_pid, memory, 0);
92 read_memory (memory, buffer, length);
95 /* Map function for tdesc */
97 tdesc_map_function (map_env, loc, map_info_in, map_info_out)
100 dc_map_info_in_t map_info_in;
101 dc_map_info_out_t *map_info_out;
103 int map_flags = DC_MIO_ENTRY_POINT | DC_MIO_IMPLICIT_PROLOGUE_END;
104 int entry_point = get_pc_function_start(loc);
105 map_info_out->flags = map_flags;
106 map_info_out->entry_point = entry_point;
109 dc_handle_t tdesc_handle;
111 extern int debug_info;
116 tdesc_handle = dc_initiate (debug_info, tdesc_error_function,
117 0,tdesc_read_function,0,0,0,0,0,tdesc_map_function,0);
119 dc_dcontext_t current_context;
121 /* setup current context, called from wait_for_inferior */
126 dc_word_t reg_info[DC_NUM_REG];
127 dc_word_t reg_flags[2] = {0,-1};
128 dc_word_t aux_info[DC_NUM_AUX];
129 dc_word_t aux_flags[2] = {0,-1};
130 dc_exactness_t loc_exact = DC_NO;
132 dc_boolean_t psr_ind = 0;
133 dc_word_t psr_flags[2] = {0,-1};
135 bcopy (®isters, reg_info, DC_NUM_REG * 4);
136 aux_info[DC_AUX_LOC] = read_register(SXIP_REGNUM);
137 aux_info[DC_AUX_SXIP] = read_register(SXIP_REGNUM);
138 aux_info[DC_AUX_SNIP] = read_register(SNIP_REGNUM);
139 aux_info[DC_AUX_SFIP] = read_register(SFIP_REGNUM);
140 aux_info[DC_AUX_FPSR] = read_register(FPSR_REGNUM);
141 aux_info[DC_AUX_FPCR] = read_register(FPCR_REGNUM);
143 psr_info = read_register(PSR_REGNUM);
145 return dc_make_dcontext (tdesc_handle, reg_info, reg_flags, aux_info,
146 aux_flags, loc_exact, psr_info, psr_ind, psr_flags);
151 get_prev_context (context)
152 dc_dcontext_t context;
154 return current_context = dc_previous_dcontext (context);
160 /* Determine frame base for this file's frames. This will be either
161 the CFA or the old style FP_REGNUM; the symtab for the current pc's
162 file has the information */
168 struct symtab *this_file = find_pc_symtab(pc);
169 int coffsem_frame_position;
171 /* If this_file is null, there's a good chance the file was compiled
172 without -g. If that's the case, use CFA (canonical frame addr)
173 as the default frame pointer. */
177 coffsem_frame_position = this_file->coffsem & 3;
178 if (coffsem_frame_position == 1)
179 return (CORE_ADDR) dc_general_register (current_context, FP_REGNUM);
181 /* default is CFA, as well as if coffsem==2 */
182 return (CORE_ADDR) dc_frame_address (current_context);
185 return (CORE_ADDR) dc_frame_address (current_context);
188 #if TARGET_BYTE_ORDER != HOST_BYTE_ORDER
190 #else /* Host and target byte order the same. */
191 #define SINGLE_EXP_BITS 8
192 #define DOUBLE_EXP_BITS 11
196 /* fp points to a single precision OR double precision
197 * floating point value; len is the number of bytes, either 4 or 8.
198 * Returns 1 iff fp points to a valid IEEE floating point number.
199 * Returns 0 if fp points to a denormalized number or a NaN
206 exponent = exponent << 1 >> (32 - SINGLE_EXP_BITS - 1);
207 return ((exponent == -1) || (! exponent && *fp));
212 exponent = exponent << 1 >> (32 - DOUBLE_EXP_BITS - 1);
213 return ((exponent == -1) || (! exponent && *fp * *(fp+1)));
217 #endif /* Host and target byte order the same. */
219 #define FIRST_PRESERVED_REGNUM 14
220 #define LAST_PRESERVED_REGNUM 25
221 #define FIRST_PARM_REGNUM 2
222 #define LAST_PARM_REGNUM 9
224 #define MAX_REG_PARMS (LAST_PARM_REGNUM - FIRST_PARM_REGNUM + 1)
227 frame_find_saved_regs (fi, fsr)
228 struct frame_info *fi;
229 struct frame_saved_regs *fsr;
233 error ("Feature not implemented for the 88k yet.");
237 for (regnum = FIRST_PARM_REGNUM; regnum <= LAST_PARM_REGNUM; regnum++)
239 = (unsigned) fi->frame - ((regnum - FIRST_PARM_REGNUM) * 4);
241 fsr->regs[SP_REGNUM] = 0; /* SP not saved in frames */
242 fsr->regs[FP_REGNUM] = fi->frame;
243 fsr->regs[PC_REGNUM] = fi->frame + 4;
248 pushed_size (prev_words, v)
252 switch (TYPE_CODE (VALUE_TYPE (v)))
254 case TYPE_CODE_VOID: /* Void type (values zero length) */
256 return 0; /* That was easy! */
258 case TYPE_CODE_PTR: /* Pointer type */
259 case TYPE_CODE_ENUM: /* Enumeration type */
260 case TYPE_CODE_INT: /* Integer type */
261 case TYPE_CODE_REF: /* C++ Reference types */
262 case TYPE_CODE_ARRAY: /* Array type, lower bound zero */
266 case TYPE_CODE_FLT: /* Floating type */
268 if (TYPE_LENGTH (VALUE_TYPE (v)) == 4)
271 /* Assume that it must be a double. */
272 if (prev_words & 1) /* at an odd-word boundary */
273 return 3; /* round to 8-byte boundary */
277 case TYPE_CODE_STRUCT: /* C struct or Pascal record */
278 case TYPE_CODE_UNION: /* C union or Pascal variant part */
280 return (((TYPE_LENGTH (VALUE_TYPE (v)) + 3) / 4) * 4);
282 case TYPE_CODE_FUNC: /* Function type */
283 case TYPE_CODE_SET: /* Pascal sets */
284 case TYPE_CODE_RANGE: /* Range (integers within bounds) */
285 case TYPE_CODE_PASCAL_ARRAY: /* Array with explicit type of index */
286 case TYPE_CODE_MEMBER: /* Member type */
287 case TYPE_CODE_METHOD: /* Method type */
288 /* Don't know how to pass these yet. */
290 case TYPE_CODE_UNDEF: /* Not used; catches errors */
297 store_parm_word (address, val)
301 write_memory (address, &val, 4);
305 store_parm (prev_words, left_parm_addr, v)
306 unsigned int prev_words;
307 CORE_ADDR left_parm_addr;
310 CORE_ADDR start = left_parm_addr + (prev_words * 4);
311 int *val_addr = (int *)VALUE_CONTENTS(v);
313 switch (TYPE_CODE (VALUE_TYPE (v)))
315 case TYPE_CODE_VOID: /* Void type (values zero length) */
319 case TYPE_CODE_PTR: /* Pointer type */
320 case TYPE_CODE_ENUM: /* Enumeration type */
321 case TYPE_CODE_INT: /* Integer type */
322 case TYPE_CODE_ARRAY: /* Array type, lower bound zero */
323 case TYPE_CODE_REF: /* C++ Reference types */
325 store_parm_word (start, *val_addr);
328 case TYPE_CODE_FLT: /* Floating type */
330 if (TYPE_LENGTH (VALUE_TYPE (v)) == 4)
332 store_parm_word (start, *val_addr);
337 store_parm_word (start + ((prev_words & 1) * 4), val_addr[0]);
338 store_parm_word (start + ((prev_words & 1) * 4) + 4, val_addr[1]);
339 return 2 + (prev_words & 1);
342 case TYPE_CODE_STRUCT: /* C struct or Pascal record */
343 case TYPE_CODE_UNION: /* C union or Pascal variant part */
346 unsigned int words = (((TYPE_LENGTH (VALUE_TYPE (v)) + 3) / 4) * 4);
349 for (word = 0; word < words; word++)
350 store_parm_word (start + (word * 4), val_addr[word]);
359 /* This routine sets up all of the parameter values needed to make a pseudo
360 call. The name "push_parameters" is a misnomer on some archs,
361 because (on the m88k) most parameters generally end up being passed in
362 registers rather than on the stack. In this routine however, we do
363 end up storing *all* parameter values onto the stack (even if we will
364 realize later that some of these stores were unnecessary). */
367 push_parameters (return_type, struct_conv, nargs, args)
368 struct type *return_type;
374 unsigned int p_words = 0;
375 CORE_ADDR left_parm_addr;
377 /* Start out by creating a space for the return value (if need be). We
378 only need to do this if the return value is a struct or union. If we
379 do make a space for a struct or union return value, then we must also
380 arrange for the base address of that space to go into r12, which is the
381 standard place to pass the address of the return value area to the
382 callee. Note that only structs and unions are returned in this fashion.
383 Ints, enums, pointers, and floats are returned into r2. Doubles are
384 returned into the register pair {r2,r3}. Note also that the space
385 reserved for a struct or union return value only has to be word aligned
386 (not double-word) but it is double-word aligned here anyway (just in
387 case that becomes important someday). */
389 switch (TYPE_CODE (return_type))
391 case TYPE_CODE_STRUCT:
392 case TYPE_CODE_UNION:
394 int return_bytes = ((TYPE_LENGTH (return_type) + 7) / 8) * 8;
397 rv_addr = read_register (SP_REGNUM) - return_bytes;
399 write_register (SP_REGNUM, rv_addr); /* push space onto the stack */
400 write_register (SRA_REGNUM, rv_addr);/* set return value register */
404 /* Here we make a pre-pass on the whole parameter list to figure out exactly
405 how many words worth of stuff we are going to pass. */
407 for (p_words = 0, parm_num = 0; parm_num < nargs; parm_num++)
408 p_words += pushed_size (p_words, value_arg_coerce (args[parm_num]));
410 /* Now, check to see if we have to round up the number of parameter words
411 to get up to the next 8-bytes boundary. This may be necessary because
412 of the software convention to always keep the stack aligned on an 8-byte
416 p_words++; /* round to 8-byte boundary */
418 /* Now figure out the absolute address of the leftmost parameter, and update
419 the stack pointer to point at that address. */
421 left_parm_addr = read_register (SP_REGNUM) - (p_words * 4);
422 write_register (SP_REGNUM, left_parm_addr);
424 /* Now we can go through all of the parameters (in left-to-right order)
425 and write them to their parameter stack slots. Note that we are not
426 really "pushing" the parameter values. The stack space for these values
427 was already allocated above. Now we are just filling it up. */
429 for (p_words = 0, parm_num = 0; parm_num < nargs; parm_num++)
431 store_parm (p_words, left_parm_addr, value_arg_coerce (args[parm_num]));
433 /* Now that we are all done storing the parameter values into the stack, we
434 must go back and load up the parameter registers with the values from the
435 corresponding stack slots. Note that in the two cases of (a) gaps in the
436 parameter word sequence causes by (otherwise) misaligned doubles, and (b)
437 slots correcponding to structs or unions, the work we do here in loading
438 some parameter registers may be unnecessary, but who cares? */
440 for (p_words = 0; p_words < 8; p_words++)
442 write_register (FIRST_PARM_REGNUM + p_words,
443 read_memory_integer (left_parm_addr + (p_words * 4), 4));
450 error ("Feature not implemented for the m88k yet.");
455 collect_returned_value (rval, value_type, struct_return, nargs, args)
457 struct type *value_type;
462 char retbuf[REGISTER_BYTES];
464 bcopy (registers, retbuf, REGISTER_BYTES);
465 *rval = value_being_returned (value_type, retbuf, struct_return);
470 /* Now handled in a machine independent way with CALL_DUMMY_LOCATION. */
471 /* Stuff a breakpoint instruction onto the stack (or elsewhere if the stack
472 is not a good place for it). Return the address at which the instruction
473 got stuffed, or zero if we were unable to stuff it anywhere. */
478 static char breakpoint_insn[] = BREAKPOINT;
479 extern CORE_ADDR text_end; /* of inferior */
480 static char readback_buffer[] = BREAKPOINT;
483 /* With a little bit of luck, we can just stash the breakpoint instruction
484 in the word just beyond the end of normal text space. For systems on
485 which the hardware will not allow us to execute out of the stack segment,
486 we have to hope that we *are* at least allowed to effectively extend the
487 text segment by one word. If the actual end of user's the text segment
488 happens to fall right at a page boundary this trick may fail. Note that
489 we check for this by reading after writing, and comparing in order to
490 be sure that the write worked. */
492 write_memory (text_end, &breakpoint_insn, 4);
494 /* Fill the readback buffer with some garbage which is certain to be
495 unequal to the breakpoint insn. That way we can tell if the
496 following read doesn't actually succeed. */
498 for (i = 0; i < sizeof (readback_buffer); i++)
499 readback_buffer[i] = ~ readback_buffer[i]; /* Invert the bits */
501 /* Now check that the breakpoint insn was successfully installed. */
503 read_memory (text_end, readback_buffer, sizeof (readback_buffer));
504 for (i = 0; i < sizeof (readback_buffer); i++)
505 if (readback_buffer[i] != breakpoint_insn[i])
506 return 0; /* Failed to install! */
512 /* Like dc_psr_register but takes an extra int arg. */
514 psr_register (context, dummy)
515 dc_dcontext_t context;
518 return dc_psr_register (context);
521 /* Same functionality as get_saved_register in findvar.c, but implemented
524 get_saved_register (raw_buffer, optim, addrp, frame, regnum, lvalp)
530 enum lval_type *lvalp;
532 struct frame_info *fi = get_frame_info (frame);
534 /* Functions to say whether a register is optimized out, and
535 if not, to get the value. Take as args a context and the
536 value of get_reg_arg. */
537 int (*get_reg_state) ();
538 dc_word_t (*get_reg) ();
541 /* Because tdesc doesn't tell us whether it got it from a register
542 or memory, always say we don't have an address for it. */
546 if (regnum < DC_NUM_REG)
548 get_reg_state = dc_general_register_state;
549 get_reg = dc_general_register;
550 get_reg_arg = regnum;
554 get_reg_state = dc_auxiliary_register_state;
555 get_reg = dc_auxiliary_register;
559 get_reg_arg = DC_AUX_SXIP;
562 get_reg_arg = DC_AUX_SNIP;
565 get_reg_arg = DC_AUX_FPSR;
568 get_reg_arg = DC_AUX_FPCR;
571 get_reg_state = dc_psr_register_bit_state;
572 get_reg = psr_register;
582 if ((*get_reg_state) (fi->frame_context, get_reg_arg))
584 if (raw_buffer != NULL)
585 *(int *)raw_buffer = (*get_reg) (fi->frame_context, get_reg_arg);
597 /* Well, the caller can't treat it as a register or memory... */