Search
lxdream.org :: lxdream/src/x86dasm/dis-buf.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/x86dasm/dis-buf.c
changeset 362:dc40e2064dc4
next755:ab873907b00e
author nkeynes
date Mon Jan 28 02:38:09 2008 +0000 (16 years ago)
permissions -rw-r--r--
last change Bug #49: Joystick support work in progress
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/x86dasm/dis-buf.c Mon Jan 28 02:38:09 2008 +0000
1.3 @@ -0,0 +1,132 @@
1.4 +/* Disassemble from a buffer, for GNU.
1.5 + Copyright 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2005
1.6 + Free Software Foundation, Inc.
1.7 +
1.8 +This program is free software; you can redistribute it and/or modify
1.9 +it under the terms of the GNU General Public License as published by
1.10 +the Free Software Foundation; either version 2 of the License, or
1.11 +(at your option) any later version.
1.12 +
1.13 +This program is distributed in the hope that it will be useful,
1.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
1.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.16 +GNU General Public License for more details.
1.17 +
1.18 +You should have received a copy of the GNU General Public License
1.19 +along with this program; if not, write to the Free Software
1.20 +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
1.21 +
1.22 +#include "sysdep.h"
1.23 +#include "dis-asm.h"
1.24 +#include <errno.h>
1.25 +#include "opintl.h"
1.26 +
1.27 +/* Get LENGTH bytes from info's buffer, at target address memaddr.
1.28 + Transfer them to myaddr. */
1.29 +int
1.30 +buffer_read_memory (memaddr, myaddr, length, info)
1.31 + bfd_vma memaddr;
1.32 + bfd_byte *myaddr;
1.33 + unsigned int length;
1.34 + struct disassemble_info *info;
1.35 +{
1.36 + unsigned int opb = info->octets_per_byte;
1.37 + unsigned int end_addr_offset = length / opb;
1.38 + unsigned int max_addr_offset = info->buffer_length / opb;
1.39 + unsigned int octets = (memaddr - info->buffer_vma) * opb;
1.40 +
1.41 + if (memaddr < info->buffer_vma
1.42 + || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset)
1.43 + /* Out of bounds. Use EIO because GDB uses it. */
1.44 + return EIO;
1.45 + memcpy (myaddr, info->buffer + octets, length);
1.46 +
1.47 + return 0;
1.48 +}
1.49 +
1.50 +/* Print an error message. We can assume that this is in response to
1.51 + an error return from buffer_read_memory. */
1.52 +void
1.53 +perror_memory (status, memaddr, info)
1.54 + int status;
1.55 + bfd_vma memaddr;
1.56 + struct disassemble_info *info;
1.57 +{
1.58 + if (status != EIO)
1.59 + /* Can't happen. */
1.60 + info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
1.61 + else
1.62 + {
1.63 + char buf[30];
1.64 +
1.65 + /* Actually, address between memaddr and memaddr + len was
1.66 + out of bounds. */
1.67 + sprintf_vma (buf, memaddr);
1.68 + info->fprintf_func (info->stream,
1.69 + _("Address 0x%s is out of bounds.\n"), buf);
1.70 + }
1.71 +}
1.72 +
1.73 +/* This could be in a separate file, to save miniscule amounts of space
1.74 + in statically linked executables. */
1.75 +
1.76 +/* Just print the address is hex. This is included for completeness even
1.77 + though both GDB and objdump provide their own (to print symbolic
1.78 + addresses). */
1.79 +
1.80 +void
1.81 +generic_print_address (addr, info)
1.82 + bfd_vma addr;
1.83 + struct disassemble_info *info;
1.84 +{
1.85 + char buf[30];
1.86 +
1.87 + sprintf_vma (buf, addr);
1.88 + (*info->fprintf_func) (info->stream, "0x%s", buf);
1.89 +}
1.90 +
1.91 +#if 0
1.92 +/* Just concatenate the address as hex. This is included for
1.93 + completeness even though both GDB and objdump provide their own (to
1.94 + print symbolic addresses). */
1.95 +
1.96 +void generic_strcat_address PARAMS ((bfd_vma, char *, int));
1.97 +
1.98 +void
1.99 +generic_strcat_address (addr, buf, len)
1.100 + bfd_vma addr;
1.101 + char *buf;
1.102 + int len;
1.103 +{
1.104 + if (buf != (char *)NULL && len > 0)
1.105 + {
1.106 + char tmpBuf[30];
1.107 +
1.108 + sprintf_vma (tmpBuf, addr);
1.109 + if ((strlen (buf) + strlen (tmpBuf)) <= (unsigned int) len)
1.110 + strcat (buf, tmpBuf);
1.111 + else
1.112 + strncat (buf, tmpBuf, (len - strlen(buf)));
1.113 + }
1.114 + return;
1.115 +}
1.116 +#endif
1.117 +
1.118 +/* Just return true. */
1.119 +
1.120 +int
1.121 +generic_symbol_at_address (addr, info)
1.122 + bfd_vma addr ATTRIBUTE_UNUSED;
1.123 + struct disassemble_info *info ATTRIBUTE_UNUSED;
1.124 +{
1.125 + return 1;
1.126 +}
1.127 +
1.128 +/* Just return TRUE. */
1.129 +
1.130 +bfd_boolean
1.131 +generic_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED,
1.132 + struct disassemble_info *info ATTRIBUTE_UNUSED)
1.133 +{
1.134 + return TRUE;
1.135 +}
.