⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m88k-tdep.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
	frame_sp - sp_offset, sp_offset);  fsr->regs[SP_REGNUM] = frame_sp - sp_offset;  return (ip);}/* Given an ip value corresponding to the start of a function,   return the ip of the first instruction after the function    prologue.  */CORE_ADDRskip_prologue (ip)     CORE_ADDR (ip);{  struct frame_saved_regs saved_regs_dummy;  struct symtab_and_line sal;  CORE_ADDR limit;  sal = find_pc_line (ip, 0);  limit = (sal.end) ? sal.end : 0xffffffff;  return (examine_prologue (ip, limit, (FRAME_ADDR) 0, &saved_regs_dummy,			    (struct frame_info *)0 ));}/* Put here the code to store, into a struct frame_saved_regs,   the addresses of the saved registers of frame described by FRAME_INFO.   This includes special registers such as pc and fp saved in special   ways in the stack frame.  sp is even more special:   the address we return for it IS the sp for the next frame.   We cache the result of doing this in the frame_cache_obstack, since   it is fairly expensive.  */voidframe_find_saved_regs (fi, fsr)     struct frame_info *fi;     struct frame_saved_regs *fsr;{  register CORE_ADDR next_addr;  register CORE_ADDR *saved_regs;  register int regnum;  register struct frame_saved_regs *cache_fsr;  extern struct obstack frame_cache_obstack;  CORE_ADDR ip;  struct symtab_and_line sal;  CORE_ADDR limit;  if (!fi->fsr)    {      cache_fsr = (struct frame_saved_regs *)		  obstack_alloc (&frame_cache_obstack,				 sizeof (struct frame_saved_regs));      bzero (cache_fsr, sizeof (struct frame_saved_regs));      fi->fsr = cache_fsr;      /* Find the start and end of the function prologue.  If the PC	 is in the function prologue, we only consider the part that	 has executed already.  */               ip = get_pc_function_start (fi->pc);      sal = find_pc_line (ip, 0);      limit = (sal.end && sal.end < fi->pc) ? sal.end: fi->pc;      /* This will fill in fields in *fi as well as in cache_fsr.  */      examine_prologue (ip, limit, fi->frame, cache_fsr, fi);    }  if (fsr)    *fsr = *fi->fsr;}/* Return the address of the locals block for the frame   described by FI.  Returns 0 if the address is unknown.   NOTE!  Frame locals are referred to by negative offsets from the   argument pointer, so this is the same as frame_args_address().  */CORE_ADDRframe_locals_address (fi)     struct frame_info *fi;{  register FRAME frame;  struct frame_saved_regs fsr;  CORE_ADDR ap;  if (fi->args_pointer)	/* Cached value is likely there.  */    return fi->args_pointer;  /* Nope, generate it.  */  get_frame_saved_regs (fi, &fsr);  return fi->args_pointer;}/* Return the address of the argument block for the frame   described by FI.  Returns 0 if the address is unknown.  */CORE_ADDRframe_args_address (fi)     struct frame_info *fi;{  register FRAME frame;  struct frame_saved_regs fsr;  CORE_ADDR ap;  if (fi->args_pointer)		/* Cached value is likely there.  */    return fi->args_pointer;  /* Nope, generate it.  */  get_frame_saved_regs (fi, &fsr);  return fi->args_pointer;}/* Return the saved PC from this frame.   If the frame has a memory copy of SRP_REGNUM, use that.  If not,   just use the register SRP_REGNUM itself.  */CORE_ADDRframe_saved_pc (frame)     FRAME frame;{  return read_next_frame_reg(frame, SRP_REGNUM);}#if TARGET_BYTE_ORDER != HOST_BYTE_ORDERyou lose#else /* Host and target byte order the same.  */#define SINGLE_EXP_BITS  8#define DOUBLE_EXP_BITS 11intIEEE_isNAN(fp, len)     int *fp, len;     /* fp points to a single precision OR double precision      * floating point value; len is the number of bytes, either 4 or 8.      * Returns 1 iff fp points to a valid IEEE floating point number.      * Returns 0 if fp points to a denormalized number or a NaN      */{  int exponent;  if (len == 4)    {      exponent = *fp;      exponent = exponent << 1 >> (32 - SINGLE_EXP_BITS - 1);      return ((exponent == -1) || (! exponent && *fp));    }  else if (len == 8)    {      exponent = *(fp+1);      exponent = exponent << 1 >> (32 - DOUBLE_EXP_BITS - 1);      return ((exponent == -1) || (! exponent && *fp * *(fp+1)));    }  else return 1;}#endif /* Host and target byte order the same.  */static intpushed_size (prev_words, v)     int prev_words;     struct value *v;{  switch (TYPE_CODE (VALUE_TYPE (v)))    {      case TYPE_CODE_VOID:		/* Void type (values zero length) */	return 0;	/* That was easy! */      case TYPE_CODE_PTR:		/* Pointer type */      case TYPE_CODE_ENUM:		/* Enumeration type */      case TYPE_CODE_INT:		/* Integer type */      case TYPE_CODE_REF:		/* C++ Reference types */      case TYPE_CODE_ARRAY:		/* Array type, lower bound zero */	return 1;      case TYPE_CODE_FLT:		/* Floating type */	if (TYPE_LENGTH (VALUE_TYPE (v)) == 4)	  return 1;	else	  /* Assume that it must be a double.  */	  if (prev_words & 1)		/* at an odd-word boundary */	    return 3;			/* round to 8-byte boundary */	  else	    return 2;      case TYPE_CODE_STRUCT:		/* C struct or Pascal record */      case TYPE_CODE_UNION:		/* C union or Pascal variant part */	return (((TYPE_LENGTH (VALUE_TYPE (v)) + 3) / 4) * 4);      case TYPE_CODE_FUNC:		/* Function type */      case TYPE_CODE_SET:		/* Pascal sets */      case TYPE_CODE_RANGE:		/* Range (integers within bounds) */      case TYPE_CODE_PASCAL_ARRAY:	/* Array with explicit type of index */      case TYPE_CODE_MEMBER:		/* Member type */      case TYPE_CODE_METHOD:		/* Method type */	/* Don't know how to pass these yet.  */      case TYPE_CODE_UNDEF:		/* Not used; catches errors */      default:	abort ();    }}static voidstore_parm_word (address, val)     CORE_ADDR address;     int val;{  write_memory (address, &val, 4);}static intstore_parm (prev_words, left_parm_addr, v)     unsigned int prev_words;     CORE_ADDR left_parm_addr;     struct value *v;{  CORE_ADDR start = left_parm_addr + (prev_words * 4);  int *val_addr = (int *)VALUE_CONTENTS(v);  switch (TYPE_CODE (VALUE_TYPE (v)))    {      case TYPE_CODE_VOID:		/* Void type (values zero length) */	return 0;      case TYPE_CODE_PTR:		/* Pointer type */      case TYPE_CODE_ENUM:		/* Enumeration type */      case TYPE_CODE_INT:		/* Integer type */      case TYPE_CODE_ARRAY:		/* Array type, lower bound zero */      case TYPE_CODE_REF:		/* C++ Reference types */	store_parm_word (start, *val_addr);	return 1;      case TYPE_CODE_FLT:		/* Floating type */	if (TYPE_LENGTH (VALUE_TYPE (v)) == 4)	  {	    store_parm_word (start, *val_addr);	    return 1;	  }	else	  {	    store_parm_word (start + ((prev_words & 1) * 4), val_addr[0]);	    store_parm_word (start + ((prev_words & 1) * 4) + 4, val_addr[1]);	    return 2 + (prev_words & 1);	  }      case TYPE_CODE_STRUCT:		/* C struct or Pascal record */      case TYPE_CODE_UNION:		/* C union or Pascal variant part */	{	  unsigned int words = (((TYPE_LENGTH (VALUE_TYPE (v)) + 3) / 4) * 4);	  unsigned int word;	  for (word = 0; word < words; word++)	    store_parm_word (start + (word * 4), val_addr[word]);	  return words;	}      default:	abort ();    }} /* This routine sets up all of the parameter values needed to make a pseudo    call.  The name "push_parameters" is a misnomer on some archs,    because (on the m88k) most parameters generally end up being passed in    registers rather than on the stack.  In this routine however, we do    end up storing *all* parameter values onto the stack (even if we will    realize later that some of these stores were unnecessary).  */#define	FIRST_PARM_REGNUM	2voidpush_parameters (return_type, struct_conv, nargs, args)      struct type *return_type;       int struct_conv;      int nargs;      value *args;{   int parm_num;   unsigned int p_words = 0;   CORE_ADDR left_parm_addr;    /* Start out by creating a space for the return value (if need be).  We      only need to do this if the return value is a struct or union.  If we      do make a space for a struct or union return value, then we must also      arrange for the base address of that space to go into r12, which is the      standard place to pass the address of the return value area to the      callee.  Note that only structs and unions are returned in this fashion.      Ints, enums, pointers, and floats are returned into r2.  Doubles are      returned into the register pair {r2,r3}.  Note also that the space      reserved for a struct or union return value only has to be word aligned      (not double-word) but it is double-word aligned here anyway (just in      case that becomes important someday).  */    switch (TYPE_CODE (return_type))     {       case TYPE_CODE_STRUCT:       case TYPE_CODE_UNION:         {           int return_bytes = ((TYPE_LENGTH (return_type) + 7) / 8) * 8;           CORE_ADDR rv_addr;            rv_addr = read_register (SP_REGNUM) - return_bytes;            write_register (SP_REGNUM, rv_addr); /* push space onto the stack */           write_register (SRA_REGNUM, rv_addr);/* set return value register */         }     }    /* Here we make a pre-pass on the whole parameter list to figure out exactly      how many words worth of stuff we are going to pass.  */    for (p_words = 0, parm_num = 0; parm_num < nargs; parm_num++)     p_words += pushed_size (p_words, value_arg_coerce (args[parm_num]));    /* Now, check to see if we have to round up the number of parameter words      to get up to the next 8-bytes boundary.  This may be necessary because      of the software convention to always keep the stack aligned on an 8-byte      boundary.  */    if (p_words & 1)     p_words++;		/* round to 8-byte boundary */    /* Now figure out the absolute address of the leftmost parameter, and update      the stack pointer to point at that address.  */    left_parm_addr = read_register (SP_REGNUM) - (p_words * 4);   write_register (SP_REGNUM, left_parm_addr);    /* Now we can go through all of the parameters (in left-to-right order)      and write them to their parameter stack slots.  Note that we are not      really "pushing" the parameter values.  The stack space for these values      was already allocated above.  Now we are just filling it up.  */    for (p_words = 0, parm_num = 0; parm_num < nargs; parm_num++)     p_words +=       store_parm (p_words, left_parm_addr, value_arg_coerce (args[parm_num]));    /* Now that we are all done storing the parameter values into the stack, we      must go back and load up the parameter registers with the values from the      corresponding stack slots.  Note that in the two cases of (a) gaps in the      parameter word sequence causes by (otherwise) misaligned doubles, and (b)      slots correcponding to structs or unions, the work we do here in loading      some parameter registers may be unnecessary, but who cares?  */    for (p_words = 0; p_words < 8; p_words++)     {       write_register (FIRST_PARM_REGNUM + p_words,         read_memory_integer (left_parm_addr + (p_words * 4), 4));     }}voidpop_frame (){  error ("Feature not implemented for the m88k yet.");  return;}voidcollect_returned_value (rval, value_type, struct_return, nargs, args)     value *rval;     struct type *value_type;     int struct_return;     int nargs;     value *args;{  char retbuf[REGISTER_BYTES];  bcopy (registers, retbuf, REGISTER_BYTES);  *rval = value_being_returned (value_type, retbuf, struct_return);  return;}#if 0/* Now handled in a machine independent way with CALL_DUMMY_LOCATION.  */ /* Stuff a breakpoint instruction onto the stack (or elsewhere if the stack    is not a good place for it).  Return the address at which the instruction    got stuffed, or zero if we were unable to stuff it anywhere.  */  CORE_ADDRpush_breakpoint (){  static char breakpoint_insn[] = BREAKPOINT;  extern CORE_ADDR text_end;	/* of inferior */  static char readback_buffer[] = BREAKPOINT;  int i;   /* With a little bit of luck, we can just stash the breakpoint instruction     in the word just beyond the end of normal text space.  For systems on     which the hardware will not allow us to execute out of the stack segment,     we have to hope that we *are* at least allowed to effectively extend the     text segment by one word.  If the actual end of user's the text segment     happens to fall right at a page boundary this trick may fail.  Note that     we check for this by reading after writing, and comparing in order to     be sure that the write worked.  */  write_memory (text_end, &breakpoint_insn, 4);  /* Fill the readback buffer with some garbage which is certain to be     unequal to the breakpoint insn.  That way we can tell if the     following read doesn't actually succeed.  */  for (i = 0; i < sizeof (readback_buffer); i++)    readback_buffer[i] = ~ readback_buffer[i];	/* Invert the bits */  /* Now check that the breakpoint insn was successfully installed.  */  read_memory (text_end, readback_buffer, sizeof (readback_buffer));  for (i = 0; i < sizeof (readback_buffer); i++)    if (readback_buffer[i] != breakpoint_insn[i])      return 0;		/* Failed to install! */  return text_end;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -