Subversion Repositories Kolibri OS

Rev

Rev 5221 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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