12159047fSniklas /* Disassemble from a buffer, for GNU.
2b55d4692Sfgsch Copyright 1993, 1994, 1996, 1997, 1998, 1999, 2000
3b55d4692Sfgsch Free Software Foundation, Inc.
42159047fSniklas
52159047fSniklas This program is free software; you can redistribute it and/or modify
62159047fSniklas it under the terms of the GNU General Public License as published by
72159047fSniklas the Free Software Foundation; either version 2 of the License, or
82159047fSniklas (at your option) any later version.
92159047fSniklas
102159047fSniklas This program is distributed in the hope that it will be useful,
112159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
122159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
132159047fSniklas GNU General Public License for more details.
142159047fSniklas
152159047fSniklas You should have received a copy of the GNU General Public License
162159047fSniklas along with this program; if not, write to the Free Software
172159047fSniklas Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
182159047fSniklas
192159047fSniklas #include "sysdep.h"
20c88b1d6cSniklas #include "dis-asm.h"
212159047fSniklas #include <errno.h>
22b305b0f1Sespie #include "opintl.h"
232159047fSniklas
242159047fSniklas /* Get LENGTH bytes from info's buffer, at target address memaddr.
252159047fSniklas Transfer them to myaddr. */
262159047fSniklas int
buffer_read_memory(memaddr,myaddr,length,info)272159047fSniklas buffer_read_memory (memaddr, myaddr, length, info)
282159047fSniklas bfd_vma memaddr;
292159047fSniklas bfd_byte *myaddr;
30b305b0f1Sespie unsigned int length;
312159047fSniklas struct disassemble_info *info;
322159047fSniklas {
33b305b0f1Sespie unsigned int opb = info->octets_per_byte;
34b305b0f1Sespie unsigned int end_addr_offset = length / opb;
35b305b0f1Sespie unsigned int max_addr_offset = info->buffer_length / opb;
36b305b0f1Sespie unsigned int octets = (memaddr - info->buffer_vma) * opb;
37b305b0f1Sespie
382159047fSniklas if (memaddr < info->buffer_vma
39b305b0f1Sespie || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset)
402159047fSniklas /* Out of bounds. Use EIO because GDB uses it. */
412159047fSniklas return EIO;
42b305b0f1Sespie memcpy (myaddr, info->buffer + octets, length);
43b305b0f1Sespie
442159047fSniklas return 0;
452159047fSniklas }
462159047fSniklas
472159047fSniklas /* Print an error message. We can assume that this is in response to
482159047fSniklas an error return from buffer_read_memory. */
492159047fSniklas void
perror_memory(status,memaddr,info)502159047fSniklas perror_memory (status, memaddr, info)
512159047fSniklas int status;
522159047fSniklas bfd_vma memaddr;
532159047fSniklas struct disassemble_info *info;
542159047fSniklas {
552159047fSniklas if (status != EIO)
562159047fSniklas /* Can't happen. */
57b305b0f1Sespie info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
582159047fSniklas else
592159047fSniklas /* Actually, address between memaddr and memaddr + len was
602159047fSniklas out of bounds. */
61b305b0f1Sespie info->fprintf_func (info->stream,
62b305b0f1Sespie _("Address 0x%x is out of bounds.\n"), memaddr);
632159047fSniklas }
642159047fSniklas
652159047fSniklas /* This could be in a separate file, to save miniscule amounts of space
662159047fSniklas in statically linked executables. */
672159047fSniklas
682159047fSniklas /* Just print the address is hex. This is included for completeness even
692159047fSniklas though both GDB and objdump provide their own (to print symbolic
702159047fSniklas addresses). */
712159047fSniklas
722159047fSniklas void
generic_print_address(addr,info)732159047fSniklas generic_print_address (addr, info)
742159047fSniklas bfd_vma addr;
752159047fSniklas struct disassemble_info *info;
762159047fSniklas {
77b305b0f1Sespie char buf[30];
78b305b0f1Sespie
79b305b0f1Sespie sprintf_vma (buf, addr);
80b305b0f1Sespie (*info->fprintf_func) (info->stream, "0x%s", buf);
81b305b0f1Sespie }
82b305b0f1Sespie
83c074d1c9Sdrahn #if 0
84b305b0f1Sespie /* Just concatenate the address as hex. This is included for
85b305b0f1Sespie completeness even though both GDB and objdump provide their own (to
86b305b0f1Sespie print symbolic addresses). */
87b305b0f1Sespie
88c074d1c9Sdrahn void generic_strcat_address PARAMS ((bfd_vma, char *, int));
89c074d1c9Sdrahn
90b305b0f1Sespie void
91b305b0f1Sespie generic_strcat_address (addr, buf, len)
92b305b0f1Sespie bfd_vma addr;
93b305b0f1Sespie char *buf;
94b305b0f1Sespie int len;
95b305b0f1Sespie {
96b305b0f1Sespie if (buf != (char *)NULL && len > 0)
97b305b0f1Sespie {
98b305b0f1Sespie char tmpBuf[30];
99b305b0f1Sespie
100b305b0f1Sespie sprintf_vma (tmpBuf, addr);
101b305b0f1Sespie if ((strlen (buf) + strlen (tmpBuf)) <= (unsigned int) len)
102b305b0f1Sespie strcat (buf, tmpBuf);
103b305b0f1Sespie else
104b305b0f1Sespie strncat (buf, tmpBuf, (len - strlen(buf)));
105b305b0f1Sespie }
106b305b0f1Sespie return;
107b305b0f1Sespie }
108c074d1c9Sdrahn #endif
109b305b0f1Sespie
110*007c2a45Smiod /* Just return true. */
111b305b0f1Sespie
112b305b0f1Sespie int
generic_symbol_at_address(addr,info)113b305b0f1Sespie generic_symbol_at_address (addr, info)
114b305b0f1Sespie bfd_vma addr ATTRIBUTE_UNUSED;
115b305b0f1Sespie struct disassemble_info *info ATTRIBUTE_UNUSED;
116b305b0f1Sespie {
117b305b0f1Sespie return 1;
1182159047fSniklas }
119*007c2a45Smiod
120*007c2a45Smiod /* Just return TRUE. */
121*007c2a45Smiod
122*007c2a45Smiod bfd_boolean
generic_symbol_is_valid(asymbol * sym ATTRIBUTE_UNUSED,struct disassemble_info * info ATTRIBUTE_UNUSED)123*007c2a45Smiod generic_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED,
124*007c2a45Smiod struct disassemble_info *info ATTRIBUTE_UNUSED)
125*007c2a45Smiod {
126*007c2a45Smiod return TRUE;
127*007c2a45Smiod }
128