Home | History | Annotate | Line # | Download | only in opcodes
      1       1.1     skrll /* Disassemble from a buffer, for GNU.
      2  1.1.1.10  christos    Copyright (C) 1993-2026 Free Software Foundation, Inc.
      3       1.1     skrll 
      4       1.1     skrll    This file is part of the GNU opcodes library.
      5       1.1     skrll 
      6       1.1     skrll    This library is free software; you can redistribute it and/or modify
      7       1.1     skrll    it under the terms of the GNU General Public License as published by
      8       1.1     skrll    the Free Software Foundation; either version 3, or (at your option)
      9       1.1     skrll    any later version.
     10       1.1     skrll 
     11       1.1     skrll    It is distributed in the hope that it will be useful, but WITHOUT
     12       1.1     skrll    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     13       1.1     skrll    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
     14       1.1     skrll    License for more details.
     15       1.1     skrll 
     16       1.1     skrll    You should have received a copy of the GNU General Public License
     17       1.1     skrll    along with this program; if not, write to the Free Software
     18       1.1     skrll    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     19       1.1     skrll    MA 02110-1301, USA.  */
     20       1.1     skrll 
     21       1.1     skrll #include "sysdep.h"
     22       1.1     skrll #include "dis-asm.h"
     23       1.1     skrll #include <errno.h>
     24       1.1     skrll #include "opintl.h"
     25       1.1     skrll 
     26       1.1     skrll /* Get LENGTH bytes from info's buffer, at target address memaddr.
     27       1.1     skrll    Transfer them to myaddr.  */
     28       1.1     skrll int
     29       1.1     skrll buffer_read_memory (bfd_vma memaddr,
     30       1.1     skrll 		    bfd_byte *myaddr,
     31       1.1     skrll 		    unsigned int length,
     32       1.1     skrll 		    struct disassemble_info *info)
     33       1.1     skrll {
     34       1.1     skrll   unsigned int opb = info->octets_per_byte;
     35   1.1.1.5  christos   size_t end_addr_offset = length / opb;
     36   1.1.1.5  christos   size_t max_addr_offset = info->buffer_length / opb;
     37   1.1.1.5  christos   size_t octets = (memaddr - info->buffer_vma) * opb;
     38       1.1     skrll 
     39       1.1     skrll   if (memaddr < info->buffer_vma
     40   1.1.1.2  christos       || memaddr - info->buffer_vma > max_addr_offset
     41   1.1.1.3  christos       || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset
     42   1.1.1.3  christos       || (info->stop_vma && (memaddr >= info->stop_vma
     43   1.1.1.3  christos 			     || memaddr + end_addr_offset > info->stop_vma)))
     44       1.1     skrll     /* Out of bounds.  Use EIO because GDB uses it.  */
     45       1.1     skrll     return EIO;
     46       1.1     skrll   memcpy (myaddr, info->buffer + octets, length);
     47       1.1     skrll 
     48       1.1     skrll   return 0;
     49       1.1     skrll }
     50       1.1     skrll 
     51       1.1     skrll /* Print an error message.  We can assume that this is in response to
     52       1.1     skrll    an error return from buffer_read_memory.  */
     53       1.1     skrll 
     54       1.1     skrll void
     55       1.1     skrll perror_memory (int status,
     56       1.1     skrll 	       bfd_vma memaddr,
     57       1.1     skrll 	       struct disassemble_info *info)
     58       1.1     skrll {
     59       1.1     skrll   if (status != EIO)
     60       1.1     skrll     /* Can't happen.  */
     61       1.1     skrll     info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
     62       1.1     skrll   else
     63       1.1     skrll     {
     64       1.1     skrll       /* Actually, address between memaddr and memaddr + len was
     65       1.1     skrll 	 out of bounds.  */
     66       1.1     skrll       info->fprintf_func (info->stream,
     67   1.1.1.8  christos 			  _("Address 0x%" PRIx64 " is out of bounds.\n"),
     68   1.1.1.8  christos 			  (uint64_t) memaddr);
     69       1.1     skrll     }
     70       1.1     skrll }
     71       1.1     skrll 
     72       1.1     skrll /* This could be in a separate file, to save miniscule amounts of space
     73       1.1     skrll    in statically linked executables.  */
     74       1.1     skrll 
     75       1.1     skrll /* Just print the address is hex.  This is included for completeness even
     76       1.1     skrll    though both GDB and objdump provide their own (to print symbolic
     77       1.1     skrll    addresses).  */
     78       1.1     skrll 
     79       1.1     skrll void
     80       1.1     skrll generic_print_address (bfd_vma addr, struct disassemble_info *info)
     81       1.1     skrll {
     82   1.1.1.8  christos   (*info->fprintf_func) (info->stream, "0x%08" PRIx64, (uint64_t) addr);
     83       1.1     skrll }
     84       1.1     skrll 
     85   1.1.1.7  christos /* Just return NULL.  */
     86       1.1     skrll 
     87   1.1.1.7  christos asymbol *
     88       1.1     skrll generic_symbol_at_address (bfd_vma addr ATTRIBUTE_UNUSED,
     89       1.1     skrll 			   struct disassemble_info *info ATTRIBUTE_UNUSED)
     90       1.1     skrll {
     91   1.1.1.7  christos   return NULL;
     92       1.1     skrll }
     93       1.1     skrll 
     94       1.1     skrll /* Just return TRUE.  */
     95       1.1     skrll 
     96   1.1.1.7  christos bool
     97       1.1     skrll generic_symbol_is_valid (asymbol * sym ATTRIBUTE_UNUSED,
     98       1.1     skrll 			 struct disassemble_info *info ATTRIBUTE_UNUSED)
     99       1.1     skrll {
    100   1.1.1.7  christos   return true;
    101       1.1     skrll }
    102