133965Sjdp/* Disassemble from a buffer, for GNU. 2218822Sdim Copyright 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2005 378828Sobrien Free Software Foundation, Inc. 433965Sjdp 5218822Sdim This program is free software; you can redistribute it and/or modify 6218822Sdim it under the terms of the GNU General Public License as published by 7218822Sdim the Free Software Foundation; either version 2 of the License, or 8218822Sdim (at your option) any later version. 933965Sjdp 10218822Sdim This program is distributed in the hope that it will be useful, 11218822Sdim but WITHOUT ANY WARRANTY; without even the implied warranty of 12218822Sdim MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13218822Sdim GNU General Public License for more details. 1433965Sjdp 15218822Sdim You should have received a copy of the GNU General Public License 16218822Sdim along with this program; if not, write to the Free Software 17218822Sdim Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 18218822Sdim MA 02110-1301, USA. */ 1933965Sjdp 2033965Sjdp#include "sysdep.h" 2133965Sjdp#include "dis-asm.h" 2233965Sjdp#include <errno.h> 2360484Sobrien#include "opintl.h" 2433965Sjdp 2533965Sjdp/* Get LENGTH bytes from info's buffer, at target address memaddr. 2633965Sjdp Transfer them to myaddr. */ 2733965Sjdpint 28218822Sdimbuffer_read_memory (bfd_vma memaddr, 29218822Sdim bfd_byte *myaddr, 30218822Sdim unsigned int length, 31218822Sdim struct disassemble_info *info) 3233965Sjdp{ 3360484Sobrien unsigned int opb = info->octets_per_byte; 3460484Sobrien unsigned int end_addr_offset = length / opb; 3560484Sobrien unsigned int max_addr_offset = info->buffer_length / opb; 3660484Sobrien unsigned int octets = (memaddr - info->buffer_vma) * opb; 3760484Sobrien 3833965Sjdp if (memaddr < info->buffer_vma 3960484Sobrien || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset) 4033965Sjdp /* Out of bounds. Use EIO because GDB uses it. */ 4133965Sjdp return EIO; 4260484Sobrien memcpy (myaddr, info->buffer + octets, length); 4360484Sobrien 4433965Sjdp return 0; 4533965Sjdp} 4633965Sjdp 4733965Sjdp/* Print an error message. We can assume that this is in response to 4833965Sjdp an error return from buffer_read_memory. */ 49218822Sdim 5033965Sjdpvoid 51218822Sdimperror_memory (int status, 52218822Sdim bfd_vma memaddr, 53218822Sdim struct disassemble_info *info) 5433965Sjdp{ 5533965Sjdp if (status != EIO) 5633965Sjdp /* Can't happen. */ 5760484Sobrien info->fprintf_func (info->stream, _("Unknown error %d\n"), status); 5833965Sjdp else 59218822Sdim { 60218822Sdim char buf[30]; 61218822Sdim 62218822Sdim /* Actually, address between memaddr and memaddr + len was 63218822Sdim out of bounds. */ 64218822Sdim sprintf_vma (buf, memaddr); 65218822Sdim info->fprintf_func (info->stream, 66218822Sdim _("Address 0x%s is out of bounds.\n"), buf); 67218822Sdim } 6833965Sjdp} 6933965Sjdp 7033965Sjdp/* This could be in a separate file, to save miniscule amounts of space 7133965Sjdp in statically linked executables. */ 7233965Sjdp 7333965Sjdp/* Just print the address is hex. This is included for completeness even 7433965Sjdp though both GDB and objdump provide their own (to print symbolic 7533965Sjdp addresses). */ 7633965Sjdp 7733965Sjdpvoid 78218822Sdimgeneric_print_address (bfd_vma addr, struct disassemble_info *info) 7933965Sjdp{ 8060484Sobrien char buf[30]; 8160484Sobrien 8260484Sobrien sprintf_vma (buf, addr); 8360484Sobrien (*info->fprintf_func) (info->stream, "0x%s", buf); 8433965Sjdp} 8538889Sjdp 86130561Sobrien/* Just return true. */ 8738889Sjdp 8838889Sjdpint 89218822Sdimgeneric_symbol_at_address (bfd_vma addr ATTRIBUTE_UNUSED, 90218822Sdim struct disassemble_info *info ATTRIBUTE_UNUSED) 9138889Sjdp{ 9238889Sjdp return 1; 9338889Sjdp} 94130561Sobrien 95130561Sobrien/* Just return TRUE. */ 96130561Sobrien 97130561Sobrienbfd_boolean 98130561Sobriengeneric_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED, 99130561Sobrien struct disassemble_info *info ATTRIBUTE_UNUSED) 100130561Sobrien{ 101130561Sobrien return TRUE; 102130561Sobrien} 103