1 /* CGEN generic disassembler support code.
3 Copyright (C) 1996, 1997 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. */
30 #include "libiberty.h"
32 #include "opcode/cgen.h"
34 /* This is not published as part of the public interface so we don't
35 declare this in cgen.h. */
36 extern CGEN_OPCODE_DATA
*cgen_current_opcode_data
;
38 /* Disassembler instruction hash table. */
39 static CGEN_INSN_LIST
**dis_hash_table
;
46 free (dis_hash_table
);
47 dis_hash_table
= NULL
;
51 /* Build the disassembler instruction hash table. */
54 build_dis_hash_table ()
57 int big_p
= cgen_current_endian
== CGEN_ENDIAN_BIG
;
61 int count
= cgen_insn_count ();
62 CGEN_OPCODE_DATA
*data
= cgen_current_opcode_data
;
63 CGEN_INSN_TABLE
*insn_table
= data
->insn_table
;
64 unsigned int hash_size
= insn_table
->dis_hash_table_size
;
65 const CGEN_INSN
*insn
;
66 CGEN_INSN_LIST
*insn_lists
,*new_insns
;
68 /* The space allocated for the hash table consists of two parts:
69 the hash table and the hash lists. */
71 dis_hash_table
= (CGEN_INSN_LIST
**)
72 xmalloc (hash_size
* sizeof (CGEN_INSN_LIST
*)
73 + count
* sizeof (CGEN_INSN_LIST
));
74 memset (dis_hash_table
, 0,
75 hash_size
* sizeof (CGEN_INSN_LIST
*)
76 + count
* sizeof (CGEN_INSN_LIST
));
77 insn_lists
= (CGEN_INSN_LIST
*) (dis_hash_table
+ hash_size
);
79 /* Add compiled in insns.
80 The table is scanned backwards as later additions are inserted in
81 front of earlier ones and we want earlier ones to be prefered.
82 We stop at the first one as it is a reserved entry. */
84 for (insn
= insn_table
->init_entries
+ insn_table
->num_init_entries
- 1;
85 insn
> insn_table
->init_entries
;
88 /* We don't know whether the target uses the buffer or the base insn
89 to hash on, so set both up. */
90 value
= insn
->syntax
.value
;
91 switch (CGEN_INSN_BITSIZE (insn
))
98 bfd_putb16 ((bfd_vma
) value
, buf
);
100 bfd_putl16 ((bfd_vma
) value
, buf
);
104 bfd_putb32 ((bfd_vma
) value
, buf
);
106 bfd_putl32 ((bfd_vma
) value
, buf
);
111 hash
= (*insn_table
->dis_hash
) (buf
, value
);
112 insn_lists
->next
= dis_hash_table
[hash
];
113 insn_lists
->insn
= insn
;
114 dis_hash_table
[hash
] = insn_lists
;
117 /* Add runtime added insns.
118 ??? Currently later added insns will be prefered over earlier ones.
119 Not sure this is a bug or not. */
120 for (new_insns
= insn_table
->new_entries
;
122 new_insns
= new_insns
->next
, ++insn_lists
)
124 /* We don't know whether the target uses the buffer or the base insn
125 to hash on, so set both up. */
126 value
= new_insns
->insn
->syntax
.value
;
127 switch (CGEN_INSN_BITSIZE (new_insns
->insn
))
134 bfd_putb16 ((bfd_vma
) value
, buf
);
136 bfd_putl16 ((bfd_vma
) value
, buf
);
140 bfd_putb32 ((bfd_vma
) value
, buf
);
142 bfd_putl32 ((bfd_vma
) value
, buf
);
147 hash
= (*insn_table
->dis_hash
) (buf
, value
);
148 insn_lists
->next
= dis_hash_table
[hash
];
149 insn_lists
->insn
= new_insns
->insn
;
150 dis_hash_table
[hash
] = insn_lists
;
154 /* Return the first entry in the hash list for INSN. */
157 cgen_dis_lookup_insn (buf
, value
)
163 if (dis_hash_table
== NULL
)
164 build_dis_hash_table ();
166 hash
= (*cgen_current_opcode_data
->insn_table
->dis_hash
) (buf
, value
);
167 return dis_hash_table
[hash
];
This page took 0.03186 seconds and 4 git commands to generate.