1 /* CGEN generic disassembler support code.
3 Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
5 This file is part of the GNU Binutils and GDB, the GNU debugger.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "libiberty.h"
27 #include "opcode/cgen.h"
29 /* Subroutine of build_dis_hash_table to add INSNS to the hash table.
31 COUNT is the number of elements in INSNS.
32 ENTSIZE is sizeof (CGEN_IBASE) for the target.
33 ??? No longer used but leave in for now.
34 HTABLE points to the hash table.
35 HENTBUF is a pointer to sufficiently large buffer of hash entries.
36 The result is a pointer to the next entry to use.
38 The table is scanned backwards as additions are made to the front of the
39 list and we want earlier ones to be prefered. */
41 static CGEN_INSN_LIST
*
42 hash_insn_array (cd
, insns
, count
, entsize
, htable
, hentbuf
)
44 const CGEN_INSN
* insns
;
46 int entsize ATTRIBUTE_UNUSED
;
47 CGEN_INSN_LIST
** htable
;
48 CGEN_INSN_LIST
* hentbuf
;
50 int big_p
= CGEN_CPU_ENDIAN (cd
) == CGEN_ENDIAN_BIG
;
53 for (i
= count
- 1; i
>= 0; --i
, ++hentbuf
)
58 const CGEN_INSN
*insn
= &insns
[i
];
60 if (! (* cd
->dis_hash_p
) (insn
))
63 /* We don't know whether the target uses the buffer or the base insn
64 to hash on, so set both up. */
66 value
= CGEN_INSN_BASE_VALUE (insn
);
67 bfd_put_bits ((bfd_vma
) value
,
69 CGEN_INSN_MASK_BITSIZE (insn
),
71 hash
= (* cd
->dis_hash
) (buf
, value
);
72 hentbuf
->next
= htable
[hash
];
74 htable
[hash
] = hentbuf
;
80 /* Subroutine of build_dis_hash_table to add INSNS to the hash table.
81 This function is identical to hash_insn_array except the insns are
84 static CGEN_INSN_LIST
*
85 hash_insn_list (cd
, insns
, htable
, hentbuf
)
87 const CGEN_INSN_LIST
*insns
;
88 CGEN_INSN_LIST
**htable
;
89 CGEN_INSN_LIST
*hentbuf
;
91 int big_p
= CGEN_CPU_ENDIAN (cd
) == CGEN_ENDIAN_BIG
;
92 const CGEN_INSN_LIST
*ilist
;
94 for (ilist
= insns
; ilist
!= NULL
; ilist
= ilist
->next
, ++ hentbuf
)
100 if (! (* cd
->dis_hash_p
) (ilist
->insn
))
103 /* We don't know whether the target uses the buffer or the base insn
104 to hash on, so set both up. */
106 value
= CGEN_INSN_BASE_VALUE (ilist
->insn
);
107 bfd_put_bits((bfd_vma
) value
,
109 CGEN_INSN_MASK_BITSIZE (ilist
->insn
),
111 hash
= (* cd
->dis_hash
) (buf
, value
);
112 hentbuf
->next
= htable
[hash
];
113 hentbuf
->insn
= ilist
->insn
;
114 htable
[hash
] = hentbuf
;
120 /* Build the disassembler instruction hash table. */
123 build_dis_hash_table (cd
)
126 int count
= cgen_insn_count (cd
) + cgen_macro_insn_count (cd
);
127 CGEN_INSN_TABLE
*insn_table
= & cd
->insn_table
;
128 CGEN_INSN_TABLE
*macro_insn_table
= & cd
->macro_insn_table
;
129 unsigned int hash_size
= cd
->dis_hash_size
;
130 CGEN_INSN_LIST
*hash_entry_buf
;
131 CGEN_INSN_LIST
**dis_hash_table
;
132 CGEN_INSN_LIST
*dis_hash_table_entries
;
134 /* The space allocated for the hash table consists of two parts:
135 the hash table and the hash lists. */
137 dis_hash_table
= (CGEN_INSN_LIST
**)
138 xmalloc (hash_size
* sizeof (CGEN_INSN_LIST
*));
139 memset (dis_hash_table
, 0, hash_size
* sizeof (CGEN_INSN_LIST
*));
140 dis_hash_table_entries
= hash_entry_buf
= (CGEN_INSN_LIST
*)
141 xmalloc (count
* sizeof (CGEN_INSN_LIST
));
143 /* Add compiled in insns.
144 Don't include the first one as it is a reserved entry. */
145 /* ??? It was the end of all hash chains, and also the special
146 "invalid insn" marker. May be able to do it differently now. */
148 hash_entry_buf
= hash_insn_array (cd
,
149 insn_table
->init_entries
+ 1,
150 insn_table
->num_init_entries
- 1,
151 insn_table
->entry_size
,
152 dis_hash_table
, hash_entry_buf
);
154 /* Add compiled in macro-insns. */
156 hash_entry_buf
= hash_insn_array (cd
, macro_insn_table
->init_entries
,
157 macro_insn_table
->num_init_entries
,
158 macro_insn_table
->entry_size
,
159 dis_hash_table
, hash_entry_buf
);
161 /* Add runtime added insns.
162 Later added insns will be prefered over earlier ones. */
164 hash_entry_buf
= hash_insn_list (cd
, insn_table
->new_entries
,
165 dis_hash_table
, hash_entry_buf
);
167 /* Add runtime added macro-insns. */
169 hash_insn_list (cd
, macro_insn_table
->new_entries
,
170 dis_hash_table
, hash_entry_buf
);
172 cd
->dis_hash_table
= dis_hash_table
;
173 cd
->dis_hash_table_entries
= dis_hash_table_entries
;
176 /* Return the first entry in the hash list for INSN. */
179 cgen_dis_lookup_insn (cd
, buf
, value
)
186 if (cd
->dis_hash_table
== NULL
)
187 build_dis_hash_table (cd
);
189 hash
= (* cd
->dis_hash
) (buf
, value
);
191 return cd
->dis_hash_table
[hash
];
This page took 0.032207 seconds and 4 git commands to generate.