Search
lxdream.org :: lxdream/src/x86dasm/dis-buf.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/x86dasm/dis-buf.c
changeset 1092:7c4ffe27e7b5
prev755:ab873907b00e
author nkeynes
date Sun Dec 20 21:01:03 2009 +1000 (11 years ago)
permissions -rw-r--r--
last change Fix 64-bit x86 disassembly
Add crash-report hook to SIGILL and SIGBUS
file annotate diff log raw
nkeynes@362
     1
/* Disassemble from a buffer, for GNU.
nkeynes@362
     2
   Copyright 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2005
nkeynes@362
     3
   Free Software Foundation, Inc.
nkeynes@362
     4
nkeynes@362
     5
This program is free software; you can redistribute it and/or modify
nkeynes@362
     6
it under the terms of the GNU General Public License as published by
nkeynes@362
     7
the Free Software Foundation; either version 2 of the License, or
nkeynes@362
     8
(at your option) any later version.
nkeynes@362
     9
nkeynes@362
    10
This program is distributed in the hope that it will be useful,
nkeynes@362
    11
but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@362
    12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@362
    13
GNU General Public License for more details.
nkeynes@362
    14
nkeynes@362
    15
You should have received a copy of the GNU General Public License
nkeynes@362
    16
along with this program; if not, write to the Free Software
nkeynes@362
    17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
nkeynes@362
    18
nkeynes@755
    19
#include "x86dasm/sysdep.h"
nkeynes@755
    20
#include "x86dasm/dis-asm.h"
nkeynes@362
    21
#include <errno.h>
nkeynes@755
    22
#include "gettext.h"
nkeynes@362
    23
nkeynes@362
    24
/* Get LENGTH bytes from info's buffer, at target address memaddr.
nkeynes@362
    25
   Transfer them to myaddr.  */
nkeynes@362
    26
int
nkeynes@362
    27
buffer_read_memory (memaddr, myaddr, length, info)
nkeynes@362
    28
     bfd_vma memaddr;
nkeynes@362
    29
     bfd_byte *myaddr;
nkeynes@362
    30
     unsigned int length;
nkeynes@362
    31
     struct disassemble_info *info;
nkeynes@362
    32
{
nkeynes@362
    33
  unsigned int opb = info->octets_per_byte;
nkeynes@1092
    34
  uintptr_t octets = memaddr * opb;
nkeynes@362
    35
nkeynes@362
    36
  memcpy (myaddr, info->buffer + octets, length);
nkeynes@362
    37
nkeynes@362
    38
  return 0;
nkeynes@362
    39
}
nkeynes@362
    40
nkeynes@362
    41
/* Print an error message.  We can assume that this is in response to
nkeynes@362
    42
   an error return from buffer_read_memory.  */
nkeynes@362
    43
void
nkeynes@362
    44
perror_memory (status, memaddr, info)
nkeynes@362
    45
     int status;
nkeynes@362
    46
     bfd_vma memaddr;
nkeynes@362
    47
     struct disassemble_info *info;
nkeynes@362
    48
{
nkeynes@362
    49
  if (status != EIO)
nkeynes@362
    50
    /* Can't happen.  */
nkeynes@362
    51
    info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
nkeynes@362
    52
  else
nkeynes@362
    53
    {
nkeynes@362
    54
      char buf[30];
nkeynes@362
    55
nkeynes@362
    56
      /* Actually, address between memaddr and memaddr + len was
nkeynes@362
    57
	 out of bounds.  */
nkeynes@362
    58
      sprintf_vma (buf, memaddr);
nkeynes@362
    59
      info->fprintf_func (info->stream,
nkeynes@362
    60
			  _("Address 0x%s is out of bounds.\n"), buf);
nkeynes@362
    61
    }
nkeynes@362
    62
}
nkeynes@362
    63
nkeynes@362
    64
/* This could be in a separate file, to save miniscule amounts of space
nkeynes@362
    65
   in statically linked executables.  */
nkeynes@362
    66
nkeynes@362
    67
/* Just print the address is hex.  This is included for completeness even
nkeynes@362
    68
   though both GDB and objdump provide their own (to print symbolic
nkeynes@362
    69
   addresses).  */
nkeynes@362
    70
nkeynes@362
    71
void
nkeynes@362
    72
generic_print_address (addr, info)
nkeynes@362
    73
     bfd_vma addr;
nkeynes@362
    74
     struct disassemble_info *info;
nkeynes@362
    75
{
nkeynes@362
    76
  char buf[30];
nkeynes@362
    77
nkeynes@362
    78
  sprintf_vma (buf, addr);
nkeynes@362
    79
  (*info->fprintf_func) (info->stream, "0x%s", buf);
nkeynes@362
    80
}
nkeynes@362
    81
nkeynes@362
    82
#if 0
nkeynes@362
    83
/* Just concatenate the address as hex.  This is included for
nkeynes@362
    84
   completeness even though both GDB and objdump provide their own (to
nkeynes@362
    85
   print symbolic addresses).  */
nkeynes@362
    86
nkeynes@362
    87
void generic_strcat_address PARAMS ((bfd_vma, char *, int));
nkeynes@362
    88
nkeynes@362
    89
void
nkeynes@362
    90
generic_strcat_address (addr, buf, len)
nkeynes@362
    91
     bfd_vma addr;
nkeynes@362
    92
     char *buf;
nkeynes@362
    93
     int len;
nkeynes@362
    94
{
nkeynes@362
    95
  if (buf != (char *)NULL && len > 0)
nkeynes@362
    96
    {
nkeynes@362
    97
      char tmpBuf[30];
nkeynes@362
    98
nkeynes@362
    99
      sprintf_vma (tmpBuf, addr);
nkeynes@362
   100
      if ((strlen (buf) + strlen (tmpBuf)) <= (unsigned int) len)
nkeynes@362
   101
	strcat (buf, tmpBuf);
nkeynes@362
   102
      else
nkeynes@362
   103
	strncat (buf, tmpBuf, (len - strlen(buf)));
nkeynes@362
   104
    }
nkeynes@362
   105
  return;
nkeynes@362
   106
}
nkeynes@362
   107
#endif
nkeynes@362
   108
nkeynes@362
   109
/* Just return true.  */
nkeynes@362
   110
nkeynes@362
   111
int
nkeynes@362
   112
generic_symbol_at_address (addr, info)
nkeynes@362
   113
     bfd_vma addr ATTRIBUTE_UNUSED;
nkeynes@362
   114
     struct disassemble_info *info ATTRIBUTE_UNUSED;
nkeynes@362
   115
{
nkeynes@362
   116
  return 1;
nkeynes@362
   117
}
nkeynes@362
   118
nkeynes@362
   119
/* Just return TRUE.  */
nkeynes@362
   120
nkeynes@362
   121
bfd_boolean
nkeynes@362
   122
generic_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED,
nkeynes@362
   123
			 struct disassemble_info *info ATTRIBUTE_UNUSED)
nkeynes@362
   124
{
nkeynes@362
   125
  return TRUE;
nkeynes@362
   126
}
.