1 |
/* Hitachi SH64-specific support for 32-bit ELF |
/* SuperH SH64-specific support for 32-bit ELF |
2 |
Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. |
Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of BFD, the Binary File Descriptor library. |
This file is part of BFD, the Binary File Descriptor library. |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
7 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
8 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
9 |
(at your option) any later version. |
(at your option) any later version. |
10 |
|
|
11 |
This program is distributed in the hope that it will be useful, |
This program is distributed in the hope that it will be useful, |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
GNU General Public License for more details. |
15 |
|
|
16 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
17 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
18 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
24 |
#include "libbfd.h" |
#include "libbfd.h" |
25 |
#include "elf-bfd.h" |
#include "elf-bfd.h" |
26 |
#include "elf/sh.h" |
#include "elf/sh.h" |
27 |
|
#include "elf32-sh64.h" |
28 |
#include "../opcodes/sh64-opc.h" |
#include "../opcodes/sh64-opc.h" |
29 |
|
|
30 |
static boolean sh64_address_in_cranges |
static bfd_boolean sh64_address_in_cranges |
31 |
PARAMS ((asection *cranges, bfd_vma, sh64_elf_crange *)); |
(asection *cranges, bfd_vma, sh64_elf_crange *); |
32 |
|
|
33 |
/* Ordering functions of a crange, for the qsort and bsearch calls and for |
/* Ordering functions of a crange, for the qsort and bsearch calls and for |
34 |
different endianness. */ |
different endianness. */ |
35 |
|
|
36 |
int |
int |
37 |
_bfd_sh64_crange_qsort_cmpb (p1, p2) |
_bfd_sh64_crange_qsort_cmpb (const void *p1, const void *p2) |
|
const PTR p1; |
|
|
const PTR p2; |
|
38 |
{ |
{ |
39 |
bfd_vma a1 = bfd_getb32 (p1); |
bfd_vma a1 = bfd_getb32 (p1); |
40 |
bfd_vma a2 = bfd_getb32 (p2); |
bfd_vma a2 = bfd_getb32 (p2); |
47 |
} |
} |
48 |
|
|
49 |
int |
int |
50 |
_bfd_sh64_crange_qsort_cmpl (p1, p2) |
_bfd_sh64_crange_qsort_cmpl (const void *p1, const void *p2) |
|
const PTR p1; |
|
|
const PTR p2; |
|
51 |
{ |
{ |
52 |
bfd_vma a1 = (bfd_vma) bfd_getl32 (p1); |
bfd_vma a1 = (bfd_vma) bfd_getl32 (p1); |
53 |
bfd_vma a2 = (bfd_vma) bfd_getl32 (p2); |
bfd_vma a2 = (bfd_vma) bfd_getl32 (p2); |
60 |
} |
} |
61 |
|
|
62 |
int |
int |
63 |
_bfd_sh64_crange_bsearch_cmpb (p1, p2) |
_bfd_sh64_crange_bsearch_cmpb (const void *p1, const void *p2) |
|
const PTR p1; |
|
|
const PTR p2; |
|
64 |
{ |
{ |
65 |
bfd_vma a1 = *(bfd_vma *) p1; |
bfd_vma a1 = *(bfd_vma *) p1; |
66 |
bfd_vma a2 = (bfd_vma) bfd_getb32 (p2); |
bfd_vma a2 = (bfd_vma) bfd_getb32 (p2); |
75 |
} |
} |
76 |
|
|
77 |
int |
int |
78 |
_bfd_sh64_crange_bsearch_cmpl (p1, p2) |
_bfd_sh64_crange_bsearch_cmpl (const void *p1, const void *p2) |
|
const PTR p1; |
|
|
const PTR p2; |
|
79 |
{ |
{ |
80 |
bfd_vma a1 = *(bfd_vma *) p1; |
bfd_vma a1 = *(bfd_vma *) p1; |
81 |
bfd_vma a2 = (bfd_vma) bfd_getl32 (p2); |
bfd_vma a2 = (bfd_vma) bfd_getl32 (p2); |
93 |
section. Return FALSE if not found, and TRUE if found, and the region |
section. Return FALSE if not found, and TRUE if found, and the region |
94 |
filled into RANGEP if non-NULL. */ |
filled into RANGEP if non-NULL. */ |
95 |
|
|
96 |
static boolean |
static bfd_boolean |
97 |
sh64_address_in_cranges (cranges, addr, rangep) |
sh64_address_in_cranges (asection *cranges, bfd_vma addr, |
98 |
asection *cranges; |
sh64_elf_crange *rangep) |
|
bfd_vma addr; |
|
|
sh64_elf_crange *rangep; |
|
99 |
{ |
{ |
100 |
bfd_byte *cranges_contents; |
bfd_byte *cranges_contents; |
101 |
bfd_byte *found_rangep; |
bfd_byte *found_rangep; |
102 |
bfd_size_type cranges_size = bfd_section_size (cranges->owner, cranges); |
bfd_size_type cranges_size = cranges->size; |
103 |
|
|
104 |
/* If the size is not a multiple of the cranges entry size, then |
/* If the size is not a multiple of the cranges entry size, then |
105 |
something is badly wrong. */ |
something is badly wrong. */ |
106 |
if ((cranges_size % SH64_CRANGE_SIZE) != 0) |
if ((cranges_size % SH64_CRANGE_SIZE) != 0) |
107 |
return false; |
return FALSE; |
108 |
|
|
109 |
/* If this section has relocations, then we can't do anything sane. */ |
/* If this section has relocations, then we can't do anything sane. */ |
110 |
if (bfd_get_section_flags (cranges->owner, cranges) & SEC_RELOC) |
if (bfd_get_section_flags (cranges->owner, cranges) & SEC_RELOC) |
111 |
return false; |
return FALSE; |
112 |
|
|
113 |
/* Has some kind soul (or previous call) left processed, sorted contents |
/* Has some kind soul (or previous call) left processed, sorted contents |
114 |
for us? */ |
for us? */ |
117 |
cranges_contents = cranges->contents; |
cranges_contents = cranges->contents; |
118 |
else |
else |
119 |
{ |
{ |
120 |
cranges_contents |
if (!bfd_malloc_and_get_section (cranges->owner, cranges, |
121 |
= bfd_malloc (cranges->_cooked_size == 0 |
&cranges_contents)) |
|
? cranges->_cooked_size : cranges->_raw_size); |
|
|
if (cranges_contents == NULL) |
|
|
return false; |
|
|
|
|
|
if (! bfd_get_section_contents (cranges->owner, cranges, |
|
|
cranges_contents, (file_ptr) 0, |
|
|
cranges_size)) |
|
122 |
goto error_return; |
goto error_return; |
123 |
|
|
124 |
/* Is it sorted? */ |
/* Is it sorted? */ |
167 |
rangep->cr_size = cr_size; |
rangep->cr_size = cr_size; |
168 |
rangep->cr_type = cr_type; |
rangep->cr_type = cr_type; |
169 |
|
|
170 |
return true; |
return TRUE; |
171 |
} |
} |
172 |
|
|
173 |
/* There is a .cranges section, but it does not have a descriptor |
/* There is a .cranges section, but it does not have a descriptor |
174 |
matching this address. */ |
matching this address. */ |
175 |
return false; |
return FALSE; |
176 |
|
|
177 |
error_return: |
error_return: |
178 |
free (cranges_contents); |
if (cranges_contents != NULL) |
179 |
return false; |
free (cranges_contents); |
180 |
|
return FALSE; |
181 |
} |
} |
182 |
|
|
183 |
/* Determine what ADDR points to in SEC, and fill in a range descriptor in |
/* Determine what ADDR points to in SEC, and fill in a range descriptor in |
184 |
*RANGEP if it's non-NULL. */ |
*RANGEP if it's non-NULL. */ |
185 |
|
|
186 |
enum sh64_elf_cr_type |
enum sh64_elf_cr_type |
187 |
sh64_get_contents_type (sec, addr, rangep) |
sh64_get_contents_type (asection *sec, bfd_vma addr, sh64_elf_crange *rangep) |
|
asection *sec; |
|
|
bfd_vma addr; |
|
|
sh64_elf_crange *rangep; |
|
188 |
{ |
{ |
189 |
asection *cranges; |
asection *cranges; |
190 |
|
|
193 |
&& elf_elfheader (sec->owner)->e_type == ET_EXEC) |
&& elf_elfheader (sec->owner)->e_type == ET_EXEC) |
194 |
{ |
{ |
195 |
rangep->cr_addr = bfd_get_section_vma (sec->owner, sec); |
rangep->cr_addr = bfd_get_section_vma (sec->owner, sec); |
196 |
rangep->cr_size = bfd_section_size (sec->owner, sec); |
rangep->cr_size = sec->size; |
197 |
rangep->cr_type = CRT_NONE; |
rangep->cr_type = CRT_NONE; |
198 |
} |
} |
199 |
else |
else |
200 |
return false; |
return FALSE; |
201 |
|
|
202 |
/* If none of the pertinent bits are set, then it's a SHcompact (or at |
/* If none of the pertinent bits are set, then it's a SHcompact (or at |
203 |
least not SHmedia). */ |
least not SHmedia). */ |
236 |
|
|
237 |
/* This is a simpler exported interface for the benefit of gdb et al. */ |
/* This is a simpler exported interface for the benefit of gdb et al. */ |
238 |
|
|
239 |
boolean |
bfd_boolean |
240 |
sh64_address_is_shmedia (sec, addr) |
sh64_address_is_shmedia (asection *sec, bfd_vma addr) |
|
asection *sec; |
|
|
bfd_vma addr; |
|
241 |
{ |
{ |
242 |
sh64_elf_crange dummy; |
sh64_elf_crange dummy; |
243 |
return sh64_get_contents_type (sec, addr, &dummy) == CRT_SH5_ISA32; |
return sh64_get_contents_type (sec, addr, &dummy) == CRT_SH5_ISA32; |