OSDN Git Service

*** empty log message ***
[drdeamon64/drdeamon64.git] / libintel64asm / drd64_intel64_db.c
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11  1. Redistributions of source code must retain the above copyright notice,
12     this list of conditions and the following disclaimer.
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_intel64_db.c
33 Function: INTEL64 Assembler DataBase 
34 Comment: none
35 ----------------------------------------------------------------------*/
36
37 #include"drd64_intel64.h"
38 #include"drd64_intel64_dbtype.h"
39 #include"drd64_intel64_db.h"
40 #include"drd64_intel64_dbfile.h"
41 #include"drd64_intel64_asm.h"
42 #include"drd64_intel64_disasm.h"
43 #include"drd64_intel64_dbcommon.h"
44
45 /* Make Hash Table */
46 /* Access & Search Function */
47 #define DRD64_INTEL64DB_FILENAME        "drd64_intel64db.bin"
48
49 static  Drd64_Intel64db_Record  *p_db64rec;
50 static  int                                             i_db64datanum;
51 static  void                                    *p_db64_bytetable[2][256];
52 static  Drd64_Intel64db_Record  *p_db64_hashtable[DRD64_INTEL64DB_HASH_RADIX];
53
54 /*-----------------------------------------------------------------------
55 Word
56         Drd64_Intel64db_GetRegisterCode(
57                 : Get Register Code form Register String
58
59                 char    *pstr_operand) : [src] Register String
60 -----------------------------------------------------------------------*/
61 Word
62         Drd64_Intel64db_GetRegisterCode(
63                 char    *pstr_operand) 
64 {
65         Word    w_regcode;
66         w_regcode       = OPTYPE_REG_INVAILD;
67
68         if( !strncmp( pstr_operand, OPTYPE_REG_RAX_STR ,MAX_OPERAND))
69                 { w_regcode     = OPTYPE_REG_RAX; }
70         else if( !strncmp( pstr_operand, OPTYPE_REG_EAX_STR ,MAX_OPERAND))
71                 { w_regcode     = OPTYPE_REG_EAX; }
72         else if( !strncmp( pstr_operand, OPTYPE_REG_AX_STR ,MAX_OPERAND))
73                 { w_regcode     = OPTYPE_REG_AX; }
74         else if( !strncmp( pstr_operand, OPTYPE_REG_AH_STR ,MAX_OPERAND))
75                 { w_regcode     = OPTYPE_REG_AH; }
76         else if( !strncmp( pstr_operand, OPTYPE_REG_AL_STR ,MAX_OPERAND))
77                 { w_regcode     = OPTYPE_REG_AL; }
78
79         else if( !strncmp( pstr_operand, OPTYPE_REG_RCX_STR ,MAX_OPERAND))
80                 { w_regcode     = OPTYPE_REG_RCX; }
81         else if( !strncmp( pstr_operand, OPTYPE_REG_ECX_STR ,MAX_OPERAND))
82                 { w_regcode     = OPTYPE_REG_ECX; }
83         else if( !strncmp( pstr_operand, OPTYPE_REG_CX_STR ,MAX_OPERAND))
84                 { w_regcode     = OPTYPE_REG_CX; }
85         else if( !strncmp( pstr_operand, OPTYPE_REG_CH_STR ,MAX_OPERAND))
86                 { w_regcode     = OPTYPE_REG_CH; }
87         else if( !strncmp( pstr_operand, OPTYPE_REG_CL_STR ,MAX_OPERAND))
88                 { w_regcode     = OPTYPE_REG_CL; }
89
90         else if( !strncmp( pstr_operand, OPTYPE_REG_RDX_STR ,MAX_OPERAND))
91                 { w_regcode     = OPTYPE_REG_RDX; }
92         else if( !strncmp( pstr_operand, OPTYPE_REG_EDX_STR ,MAX_OPERAND))
93                 { w_regcode     = OPTYPE_REG_EDX; }
94         else if( !strncmp( pstr_operand, OPTYPE_REG_DX_STR ,MAX_OPERAND))
95                 { w_regcode     = OPTYPE_REG_DX; }
96         else if( !strncmp( pstr_operand, OPTYPE_REG_DH_STR ,MAX_OPERAND))
97                 { w_regcode     = OPTYPE_REG_DH; }
98         else if( !strncmp( pstr_operand, OPTYPE_REG_DL_STR ,MAX_OPERAND))
99                 { w_regcode     = OPTYPE_REG_DL; }
100
101         else if( !strncmp( pstr_operand, OPTYPE_REG_RBX_STR ,MAX_OPERAND))
102                 { w_regcode     = OPTYPE_REG_RBX; }
103         else if( !strncmp( pstr_operand, OPTYPE_REG_EBX_STR ,MAX_OPERAND))
104                 { w_regcode     = OPTYPE_REG_EBX; }
105         else if( !strncmp( pstr_operand, OPTYPE_REG_BX_STR ,MAX_OPERAND))
106                 { w_regcode     = OPTYPE_REG_BX; }
107         else if( !strncmp( pstr_operand, OPTYPE_REG_BH_STR ,MAX_OPERAND))
108                 { w_regcode     = OPTYPE_REG_BH; }
109         else if( !strncmp( pstr_operand, OPTYPE_REG_BL_STR ,MAX_OPERAND))
110                 { w_regcode     = OPTYPE_REG_BL; }
111
112         else if( !strncmp( pstr_operand, OPTYPE_REG_RSP_STR ,MAX_OPERAND))
113                 { w_regcode     = OPTYPE_REG_RSP; }
114         else if( !strncmp( pstr_operand, OPTYPE_REG_ESP_STR ,MAX_OPERAND))
115                 { w_regcode     = OPTYPE_REG_ESP; }
116         else if( !strncmp( pstr_operand, OPTYPE_REG_SP_STR ,MAX_OPERAND))
117                 { w_regcode     = OPTYPE_REG_SP; }
118
119         else if( !strncmp( pstr_operand, OPTYPE_REG_RBP_STR ,MAX_OPERAND))
120                 { w_regcode     = OPTYPE_REG_RBP; }
121         else if( !strncmp( pstr_operand, OPTYPE_REG_EBP_STR ,MAX_OPERAND))
122                 { w_regcode     = OPTYPE_REG_EBP; }
123         else if( !strncmp( pstr_operand, OPTYPE_REG_BP_STR ,MAX_OPERAND))
124                 { w_regcode     = OPTYPE_REG_BP; }
125
126         else if( !strncmp( pstr_operand, OPTYPE_REG_RSI_STR ,MAX_OPERAND))
127                 { w_regcode     = OPTYPE_REG_RSI; }
128         else if( !strncmp( pstr_operand, OPTYPE_REG_ESI_STR ,MAX_OPERAND))
129                 { w_regcode     = OPTYPE_REG_ESI; }
130         else if( !strncmp( pstr_operand, OPTYPE_REG_SI_STR ,MAX_OPERAND))
131                 { w_regcode     = OPTYPE_REG_SI; }
132
133         else if( !strncmp( pstr_operand, OPTYPE_REG_RDI_STR ,MAX_OPERAND))
134                 { w_regcode     = OPTYPE_REG_RDI; }
135         else if( !strncmp( pstr_operand, OPTYPE_REG_EDI_STR ,MAX_OPERAND))
136                 { w_regcode     = OPTYPE_REG_EDI; }
137         else if( !strncmp( pstr_operand, OPTYPE_REG_DI_STR ,MAX_OPERAND))
138                 { w_regcode     = OPTYPE_REG_DI; }
139
140         else if( !strncmp( pstr_operand, OPTYPE_REG_R8B_STR ,MAX_OPERAND))
141                 { w_regcode     = OPTYPE_REG_R8B; }
142         else if( !strncmp( pstr_operand, OPTYPE_REG_R8W_STR ,MAX_OPERAND))
143                 { w_regcode     = OPTYPE_REG_R8W; }
144         else if( !strncmp( pstr_operand, OPTYPE_REG_R8D_STR ,MAX_OPERAND))
145                 { w_regcode     = OPTYPE_REG_R8D; }
146         else if( !strncmp( pstr_operand, OPTYPE_REG_R8_STR ,MAX_OPERAND))
147                 { w_regcode     = OPTYPE_REG_R8; }
148
149         else if( !strncmp( pstr_operand, OPTYPE_REG_R9B_STR ,MAX_OPERAND))
150                 { w_regcode     = OPTYPE_REG_R9B; }
151         else if( !strncmp( pstr_operand, OPTYPE_REG_R9W_STR ,MAX_OPERAND))
152                 { w_regcode     = OPTYPE_REG_R9W; }
153         else if( !strncmp( pstr_operand, OPTYPE_REG_R9D_STR ,MAX_OPERAND))
154                 { w_regcode     = OPTYPE_REG_R9D; }
155         else if( !strncmp( pstr_operand, OPTYPE_REG_R9_STR ,MAX_OPERAND))
156                 { w_regcode     = OPTYPE_REG_R9; }
157
158         else if( !strncmp( pstr_operand, OPTYPE_REG_R10B_STR ,MAX_OPERAND))
159                 { w_regcode     = OPTYPE_REG_R10B; }
160         else if( !strncmp( pstr_operand, OPTYPE_REG_R10W_STR ,MAX_OPERAND))
161                 { w_regcode     = OPTYPE_REG_R10W; }
162         else if( !strncmp( pstr_operand, OPTYPE_REG_R10D_STR ,MAX_OPERAND))
163                 { w_regcode     = OPTYPE_REG_R10D; }
164         else if( !strncmp( pstr_operand, OPTYPE_REG_R10_STR ,MAX_OPERAND))
165                 { w_regcode     = OPTYPE_REG_R10; }
166
167         else if( !strncmp( pstr_operand, OPTYPE_REG_R11B_STR ,MAX_OPERAND))
168                 { w_regcode     = OPTYPE_REG_R11B; }
169         else if( !strncmp( pstr_operand, OPTYPE_REG_R11W_STR ,MAX_OPERAND))
170                 { w_regcode     = OPTYPE_REG_R11W; }
171         else if( !strncmp( pstr_operand, OPTYPE_REG_R11D_STR ,MAX_OPERAND))
172                 { w_regcode     = OPTYPE_REG_R11D; }
173         else if( !strncmp( pstr_operand, OPTYPE_REG_R11_STR ,MAX_OPERAND))
174                 { w_regcode     = OPTYPE_REG_R11; }
175
176         else if( !strncmp( pstr_operand, OPTYPE_REG_R12B_STR ,MAX_OPERAND))
177                 { w_regcode     = OPTYPE_REG_R12B; }
178         else if( !strncmp( pstr_operand, OPTYPE_REG_R12W_STR ,MAX_OPERAND))
179                 { w_regcode     = OPTYPE_REG_R12W; }
180         else if( !strncmp( pstr_operand, OPTYPE_REG_R12D_STR ,MAX_OPERAND))
181                 { w_regcode     = OPTYPE_REG_R12D; }
182         else if( !strncmp( pstr_operand, OPTYPE_REG_R12_STR ,MAX_OPERAND))
183                 { w_regcode     = OPTYPE_REG_R12; }
184
185         else if( !strncmp( pstr_operand, OPTYPE_REG_R13B_STR ,MAX_OPERAND))
186                 { w_regcode     = OPTYPE_REG_R13B; }
187         else if( !strncmp( pstr_operand, OPTYPE_REG_R13W_STR ,MAX_OPERAND))
188                 { w_regcode     = OPTYPE_REG_R13W; }
189         else if( !strncmp( pstr_operand, OPTYPE_REG_R13D_STR ,MAX_OPERAND))
190                 { w_regcode     = OPTYPE_REG_R13D; }
191         else if( !strncmp( pstr_operand, OPTYPE_REG_R13_STR ,MAX_OPERAND))
192                 { w_regcode     = OPTYPE_REG_R13; }
193
194         else if( !strncmp( pstr_operand, OPTYPE_REG_R14B_STR ,MAX_OPERAND))
195                 { w_regcode     = OPTYPE_REG_R14B; }
196         else if( !strncmp( pstr_operand, OPTYPE_REG_R14W_STR ,MAX_OPERAND))
197                 { w_regcode     = OPTYPE_REG_R14W; }
198         else if( !strncmp( pstr_operand, OPTYPE_REG_R14D_STR ,MAX_OPERAND))
199                 { w_regcode     = OPTYPE_REG_R14D; }
200         else if( !strncmp( pstr_operand, OPTYPE_REG_R14_STR ,MAX_OPERAND))
201                 { w_regcode     = OPTYPE_REG_R14; }
202
203         else if( !strncmp( pstr_operand, OPTYPE_REG_R15B_STR ,MAX_OPERAND))
204                 { w_regcode     = OPTYPE_REG_R15B; }
205         else if( !strncmp( pstr_operand, OPTYPE_REG_R15W_STR ,MAX_OPERAND))
206                 { w_regcode     = OPTYPE_REG_R15W; }
207         else if( !strncmp( pstr_operand, OPTYPE_REG_R15D_STR ,MAX_OPERAND))
208                 { w_regcode     = OPTYPE_REG_R15D; }
209         else if( !strncmp( pstr_operand, OPTYPE_REG_R15_STR ,MAX_OPERAND))
210                 { w_regcode     = OPTYPE_REG_R15; }
211
212         else if( !strncmp( pstr_operand, OPTYPE_REG_ES_STR ,MAX_OPERAND))
213                 { w_regcode     = OPTYPE_REG_ES; }
214         else if( !strncmp( pstr_operand, OPTYPE_REG_CS_STR ,MAX_OPERAND))
215                 { w_regcode     = OPTYPE_REG_CS; }
216         else if( !strncmp( pstr_operand, OPTYPE_REG_SS_STR ,MAX_OPERAND))
217                 { w_regcode     = OPTYPE_REG_SS; }
218         else if( !strncmp( pstr_operand, OPTYPE_REG_DS_STR ,MAX_OPERAND))
219                 { w_regcode     = OPTYPE_REG_DS; }
220         else if( !strncmp( pstr_operand, OPTYPE_REG_FS_STR ,MAX_OPERAND))
221                 { w_regcode     = OPTYPE_REG_FS; }
222         else if( !strncmp( pstr_operand, OPTYPE_REG_GS_STR ,MAX_OPERAND))
223                 { w_regcode     = OPTYPE_REG_GS; }
224
225         else if( !strncmp( pstr_operand, OPTYPE_REG_FPU_ST0_STR ,MAX_OPERAND))
226                 { w_regcode     = OPTYPE_REG_FPU_ST0; }
227         else if( !strncmp( pstr_operand, OPTYPE_REG_FPU_ST1_STR ,MAX_OPERAND))
228                 { w_regcode     = OPTYPE_REG_FPU_ST1; }
229         else if( !strncmp( pstr_operand, OPTYPE_REG_FPU_ST2_STR ,MAX_OPERAND))
230                 { w_regcode     = OPTYPE_REG_FPU_ST2; }
231         else if( !strncmp( pstr_operand, OPTYPE_REG_FPU_ST3_STR ,MAX_OPERAND))
232                 { w_regcode     = OPTYPE_REG_FPU_ST3; }
233         else if( !strncmp( pstr_operand, OPTYPE_REG_FPU_ST4_STR ,MAX_OPERAND))
234                 { w_regcode     = OPTYPE_REG_FPU_ST4; }
235         else if( !strncmp( pstr_operand, OPTYPE_REG_FPU_ST5_STR ,MAX_OPERAND))
236                 { w_regcode     = OPTYPE_REG_FPU_ST5; }
237         else if( !strncmp( pstr_operand, OPTYPE_REG_FPU_ST6_STR ,MAX_OPERAND))
238                 { w_regcode     = OPTYPE_REG_FPU_ST6; }
239         else if( !strncmp( pstr_operand, OPTYPE_REG_FPU_ST7_STR ,MAX_OPERAND))
240                 { w_regcode     = OPTYPE_REG_FPU_ST7; }
241
242         else if( !strncmp( pstr_operand, OPTYPE_REG_CR0_STR ,MAX_OPERAND))
243                 { w_regcode     = OPTYPE_REG_CR0; }
244         else if( !strncmp( pstr_operand, OPTYPE_REG_CR1_STR ,MAX_OPERAND))
245                 { w_regcode     = OPTYPE_REG_CR1; }
246         else if( !strncmp( pstr_operand, OPTYPE_REG_CR2_STR ,MAX_OPERAND))
247                 { w_regcode     = OPTYPE_REG_CR2; }
248         else if( !strncmp( pstr_operand, OPTYPE_REG_CR3_STR ,MAX_OPERAND))
249                 { w_regcode     = OPTYPE_REG_CR3; }
250         else if( !strncmp( pstr_operand, OPTYPE_REG_CR4_STR ,MAX_OPERAND))
251                 { w_regcode     = OPTYPE_REG_CR4; }
252         else if( !strncmp( pstr_operand, OPTYPE_REG_CR5_STR ,MAX_OPERAND))
253                 { w_regcode     = OPTYPE_REG_CR5; }
254         else if( !strncmp( pstr_operand, OPTYPE_REG_CR6_STR ,MAX_OPERAND))
255                 { w_regcode     = OPTYPE_REG_CR6; }
256         else if( !strncmp( pstr_operand, OPTYPE_REG_CR7_STR ,MAX_OPERAND))
257                 { w_regcode     = OPTYPE_REG_CR7; }
258         else if( !strncmp( pstr_operand, OPTYPE_REG_CR8_STR ,MAX_OPERAND))
259                 { w_regcode     = OPTYPE_REG_CR8; }
260         else if( !strncmp( pstr_operand, OPTYPE_REG_CR9_STR ,MAX_OPERAND))
261                 { w_regcode     = OPTYPE_REG_CR9; }
262         else if( !strncmp( pstr_operand, OPTYPE_REG_CR10_STR ,MAX_OPERAND))
263                 { w_regcode     = OPTYPE_REG_CR10; }
264         else if( !strncmp( pstr_operand, OPTYPE_REG_CR11_STR ,MAX_OPERAND))
265                 { w_regcode     = OPTYPE_REG_CR11; }
266         else if( !strncmp( pstr_operand, OPTYPE_REG_CR12_STR ,MAX_OPERAND))
267                 { w_regcode     = OPTYPE_REG_CR12; }
268         else if( !strncmp( pstr_operand, OPTYPE_REG_CR13_STR ,MAX_OPERAND))
269                 { w_regcode     = OPTYPE_REG_CR13; }
270         else if( !strncmp( pstr_operand, OPTYPE_REG_CR14_STR ,MAX_OPERAND))
271                 { w_regcode     = OPTYPE_REG_CR14; }
272         else if( !strncmp( pstr_operand, OPTYPE_REG_CR15_STR ,MAX_OPERAND))
273                 { w_regcode     = OPTYPE_REG_CR15; }
274
275         else if( !strncmp( pstr_operand, OPTYPE_REG_DR0_STR ,MAX_OPERAND))
276                 { w_regcode     = OPTYPE_REG_DR0; }
277         else if( !strncmp( pstr_operand, OPTYPE_REG_DR1_STR ,MAX_OPERAND))
278                 { w_regcode     = OPTYPE_REG_DR1; }
279         else if( !strncmp( pstr_operand, OPTYPE_REG_DR2_STR ,MAX_OPERAND))
280                 { w_regcode     = OPTYPE_REG_DR2; }
281         else if( !strncmp( pstr_operand, OPTYPE_REG_DR3_STR ,MAX_OPERAND))
282                 { w_regcode     = OPTYPE_REG_DR3; }
283         else if( !strncmp( pstr_operand, OPTYPE_REG_DR4_STR ,MAX_OPERAND))
284                 { w_regcode     = OPTYPE_REG_DR4; }
285         else if( !strncmp( pstr_operand, OPTYPE_REG_DR5_STR ,MAX_OPERAND))
286                 { w_regcode     = OPTYPE_REG_DR5; }
287         else if( !strncmp( pstr_operand, OPTYPE_REG_DR6_STR ,MAX_OPERAND))
288                 { w_regcode     = OPTYPE_REG_DR6; }
289         else if( !strncmp( pstr_operand, OPTYPE_REG_DR7_STR ,MAX_OPERAND))
290                 { w_regcode     = OPTYPE_REG_DR7; }
291         else if( !strncmp( pstr_operand, OPTYPE_REG_DR8_STR ,MAX_OPERAND))
292                 { w_regcode     = OPTYPE_REG_DR8; }
293         else if( !strncmp( pstr_operand, OPTYPE_REG_DR9_STR ,MAX_OPERAND))
294                 { w_regcode     = OPTYPE_REG_DR9; }
295         else if( !strncmp( pstr_operand, OPTYPE_REG_DR10_STR ,MAX_OPERAND))
296                 { w_regcode     = OPTYPE_REG_DR10; }
297         else if( !strncmp( pstr_operand, OPTYPE_REG_DR11_STR ,MAX_OPERAND))
298                 { w_regcode     = OPTYPE_REG_DR11; }
299         else if( !strncmp( pstr_operand, OPTYPE_REG_DR12_STR ,MAX_OPERAND))
300                 { w_regcode     = OPTYPE_REG_DR12; }
301         else if( !strncmp( pstr_operand, OPTYPE_REG_DR13_STR ,MAX_OPERAND))
302                 { w_regcode     = OPTYPE_REG_DR13; }
303         else if( !strncmp( pstr_operand, OPTYPE_REG_DR14_STR ,MAX_OPERAND))
304                 { w_regcode     = OPTYPE_REG_DR14; }
305         else if( !strncmp( pstr_operand, OPTYPE_REG_DR15_STR ,MAX_OPERAND))
306                 { w_regcode     = OPTYPE_REG_DR15; }
307
308         else if( !strncmp( pstr_operand, OPTYPE_REG_MMX0_STR ,MAX_OPERAND))
309                 { w_regcode     = OPTYPE_REG_MMX0; }
310         else if( !strncmp( pstr_operand, OPTYPE_REG_MMX1_STR ,MAX_OPERAND))
311                 { w_regcode     = OPTYPE_REG_MMX1; }
312         else if( !strncmp( pstr_operand, OPTYPE_REG_MMX2_STR ,MAX_OPERAND))
313                 { w_regcode     = OPTYPE_REG_MMX2; }
314         else if( !strncmp( pstr_operand, OPTYPE_REG_MMX3_STR ,MAX_OPERAND))
315                 { w_regcode     = OPTYPE_REG_MMX3; }
316         else if( !strncmp( pstr_operand, OPTYPE_REG_MMX4_STR ,MAX_OPERAND))
317                 { w_regcode     = OPTYPE_REG_MMX4; }
318         else if( !strncmp( pstr_operand, OPTYPE_REG_MMX5_STR ,MAX_OPERAND))
319                 { w_regcode     = OPTYPE_REG_MMX5; }
320         else if( !strncmp( pstr_operand, OPTYPE_REG_MMX6_STR ,MAX_OPERAND))
321                 { w_regcode     = OPTYPE_REG_MMX6; }
322         else if( !strncmp( pstr_operand, OPTYPE_REG_MMX7_STR ,MAX_OPERAND))
323                 { w_regcode     = OPTYPE_REG_MMX7; }
324
325         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE0_STR ,MAX_OPERAND))
326                 { w_regcode     = OPTYPE_REG_SSE0; }
327         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE1_STR ,MAX_OPERAND))
328                 { w_regcode     = OPTYPE_REG_SSE1; }
329         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE2_STR ,MAX_OPERAND))
330                 { w_regcode     = OPTYPE_REG_SSE2; }
331         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE3_STR ,MAX_OPERAND))
332                 { w_regcode     = OPTYPE_REG_SSE3; }
333         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE4_STR ,MAX_OPERAND))
334                 { w_regcode     = OPTYPE_REG_SSE4; }
335         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE5_STR ,MAX_OPERAND))
336                 { w_regcode     = OPTYPE_REG_SSE5; }
337         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE6_STR ,MAX_OPERAND))
338                 { w_regcode     = OPTYPE_REG_SSE6; }
339         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE7_STR ,MAX_OPERAND))
340                 { w_regcode     = OPTYPE_REG_SSE7; }
341         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE8_STR ,MAX_OPERAND))
342                 { w_regcode     = OPTYPE_REG_SSE8; }
343         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE9_STR ,MAX_OPERAND))
344                 { w_regcode     = OPTYPE_REG_SSE9; }
345         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE10_STR ,MAX_OPERAND))
346                 { w_regcode     = OPTYPE_REG_SSE10; }
347         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE11_STR ,MAX_OPERAND))
348                 { w_regcode     = OPTYPE_REG_SSE11; }
349         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE12_STR ,MAX_OPERAND))
350                 { w_regcode     = OPTYPE_REG_SSE12; }
351         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE13_STR ,MAX_OPERAND))
352                 { w_regcode     = OPTYPE_REG_SSE13; }
353         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE14_STR ,MAX_OPERAND))
354                 { w_regcode     = OPTYPE_REG_SSE14; }
355         else if( !strncmp( pstr_operand, OPTYPE_REG_SSE15_STR ,MAX_OPERAND))
356                 { w_regcode     = OPTYPE_REG_SSE15; }
357
358         else if( !strncmp( pstr_operand, OPTYPE_REG_RIP_STR ,MAX_OPERAND))
359                 { w_regcode     = OPTYPE_REG_RIP; }
360
361         return w_regcode;
362 }
363
364
365 /*-----------------------------------------------------------------------
366 int
367         Drd64_Intel64db_GetRegisterString(
368                 : Convert Reg.ID to Reg. String
369
370                 Byte *p_regstr,         : Dest. Register String
371                 Word w_regid,           : Src. Register ID
372                 int i_maxstr )          : Dest. Buf. Max Size
373
374 -----------------------------------------------------------------------*/
375 int
376         Drd64_Intel64db_GetRegisterString(
377                 Byte *p_regstr,
378                 Word w_regid,
379                 int i_maxstr )
380 {
381         char    *p_srcstr       = NULL;
382
383         switch( w_regid )       {
384                 case OPTYPE_REG_RAX:    p_srcstr = OPTYPE_REG_RAX_STR;  break;
385                 case OPTYPE_REG_EAX:    p_srcstr = OPTYPE_REG_EAX_STR;  break;
386                 case OPTYPE_REG_AX:             p_srcstr = OPTYPE_REG_AX_STR;   break;
387                 case OPTYPE_REG_AH:             p_srcstr = OPTYPE_REG_AH_STR;   break;
388                 case OPTYPE_REG_AL:             p_srcstr = OPTYPE_REG_AL_STR;   break;
389                 case OPTYPE_REG_RCX:    p_srcstr = OPTYPE_REG_RCX_STR;  break;
390                 case OPTYPE_REG_ECX:    p_srcstr = OPTYPE_REG_ECX_STR;  break;
391                 case OPTYPE_REG_CX:             p_srcstr = OPTYPE_REG_CX_STR;   break;
392                 case OPTYPE_REG_CH:             p_srcstr = OPTYPE_REG_CH_STR;   break;
393                 case OPTYPE_REG_CL:             p_srcstr = OPTYPE_REG_CL_STR;   break;
394                 case OPTYPE_REG_RDX:    p_srcstr = OPTYPE_REG_RDX_STR;  break;
395                 case OPTYPE_REG_EDX:    p_srcstr = OPTYPE_REG_EDX_STR;  break;
396                 case OPTYPE_REG_DX:             p_srcstr = OPTYPE_REG_DX_STR;   break;
397                 case OPTYPE_REG_DH:             p_srcstr = OPTYPE_REG_DH_STR;   break;
398                 case OPTYPE_REG_DL:             p_srcstr = OPTYPE_REG_DL_STR;   break;
399                 case OPTYPE_REG_RBX:    p_srcstr = OPTYPE_REG_RBX_STR;  break;
400                 case OPTYPE_REG_EBX:    p_srcstr = OPTYPE_REG_EBX_STR;  break;
401                 case OPTYPE_REG_BX:             p_srcstr = OPTYPE_REG_BX_STR;   break;
402                 case OPTYPE_REG_BH:             p_srcstr = OPTYPE_REG_BH_STR;   break;
403                 case OPTYPE_REG_BL:             p_srcstr = OPTYPE_REG_BL_STR;   break;
404                 case OPTYPE_REG_RSP:    p_srcstr = OPTYPE_REG_RSP_STR;  break;
405                 case OPTYPE_REG_ESP:    p_srcstr = OPTYPE_REG_ESP_STR;  break;
406                 case OPTYPE_REG_SP:             p_srcstr = OPTYPE_REG_SP_STR;   break;
407                 case OPTYPE_REG_RBP:    p_srcstr = OPTYPE_REG_RBP_STR;  break;
408                 case OPTYPE_REG_EBP:    p_srcstr = OPTYPE_REG_EBP_STR;  break;
409                 case OPTYPE_REG_BP:             p_srcstr = OPTYPE_REG_BP_STR;   break;
410                 case OPTYPE_REG_RSI:    p_srcstr = OPTYPE_REG_RSI_STR;  break;
411                 case OPTYPE_REG_ESI:    p_srcstr = OPTYPE_REG_ESI_STR;  break;
412                 case OPTYPE_REG_SI:             p_srcstr = OPTYPE_REG_SI_STR;   break;
413                 case OPTYPE_REG_RDI:    p_srcstr = OPTYPE_REG_RDI_STR;  break;
414                 case OPTYPE_REG_EDI:    p_srcstr = OPTYPE_REG_EDI_STR;  break;
415                 case OPTYPE_REG_DI:             p_srcstr = OPTYPE_REG_DI_STR;   break;
416                 case OPTYPE_REG_R8B:    p_srcstr = OPTYPE_REG_R8B_STR;  break;
417                 case OPTYPE_REG_R8W:    p_srcstr = OPTYPE_REG_R8W_STR;  break;
418                 case OPTYPE_REG_R8D:    p_srcstr = OPTYPE_REG_R8D_STR;  break;
419                 case OPTYPE_REG_R8:             p_srcstr = OPTYPE_REG_R8_STR;   break;
420                 case OPTYPE_REG_R9B:    p_srcstr = OPTYPE_REG_R9B_STR;  break;
421                 case OPTYPE_REG_R9W:    p_srcstr = OPTYPE_REG_R9W_STR;  break;
422                 case OPTYPE_REG_R9D:    p_srcstr = OPTYPE_REG_R9D_STR;  break;
423                 case OPTYPE_REG_R9:             p_srcstr = OPTYPE_REG_R9_STR;   break;
424                 case OPTYPE_REG_R10B:   p_srcstr = OPTYPE_REG_R10B_STR; break;
425                 case OPTYPE_REG_R10W:   p_srcstr = OPTYPE_REG_R10W_STR; break;
426                 case OPTYPE_REG_R10D:   p_srcstr = OPTYPE_REG_R10D_STR; break;
427                 case OPTYPE_REG_R10:    p_srcstr = OPTYPE_REG_R10_STR;  break;
428                 case OPTYPE_REG_R11B:   p_srcstr = OPTYPE_REG_R11B_STR; break;
429                 case OPTYPE_REG_R11W:   p_srcstr = OPTYPE_REG_R11W_STR; break;
430                 case OPTYPE_REG_R11D:   p_srcstr = OPTYPE_REG_R11D_STR; break;
431                 case OPTYPE_REG_R11:    p_srcstr = OPTYPE_REG_R11_STR;  break;
432                 case OPTYPE_REG_R12B:   p_srcstr = OPTYPE_REG_R12B_STR; break;
433                 case OPTYPE_REG_R12W:   p_srcstr = OPTYPE_REG_R12W_STR; break;
434                 case OPTYPE_REG_R12D:   p_srcstr = OPTYPE_REG_R12D_STR; break;
435                 case OPTYPE_REG_R12:    p_srcstr = OPTYPE_REG_R12_STR;  break;
436                 case OPTYPE_REG_R13B:   p_srcstr = OPTYPE_REG_R13B_STR; break;
437                 case OPTYPE_REG_R13W:   p_srcstr = OPTYPE_REG_R13W_STR; break;
438                 case OPTYPE_REG_R13D:   p_srcstr = OPTYPE_REG_R13D_STR; break;
439                 case OPTYPE_REG_R13:    p_srcstr = OPTYPE_REG_R13_STR;  break;
440                 case OPTYPE_REG_R14B:   p_srcstr = OPTYPE_REG_R14B_STR; break;
441                 case OPTYPE_REG_R14W:   p_srcstr = OPTYPE_REG_R14W_STR; break;
442                 case OPTYPE_REG_R14D:   p_srcstr = OPTYPE_REG_R14D_STR; break;
443                 case OPTYPE_REG_R14:    p_srcstr = OPTYPE_REG_R14_STR;  break;
444                 case OPTYPE_REG_R15B:   p_srcstr = OPTYPE_REG_R15B_STR; break;
445                 case OPTYPE_REG_R15W:   p_srcstr = OPTYPE_REG_R15W_STR; break;
446                 case OPTYPE_REG_R15D:   p_srcstr = OPTYPE_REG_R15D_STR; break;
447                 case OPTYPE_REG_R15:    p_srcstr = OPTYPE_REG_R15_STR;  break;
448                 case OPTYPE_REG_ES:             p_srcstr = OPTYPE_REG_ES_STR;   break;
449                 case OPTYPE_REG_CS:             p_srcstr = OPTYPE_REG_CS_STR;   break;
450                 case OPTYPE_REG_SS:             p_srcstr = OPTYPE_REG_SS_STR;   break;
451                 case OPTYPE_REG_DS:             p_srcstr = OPTYPE_REG_DS_STR;   break;
452                 case OPTYPE_REG_FS:             p_srcstr = OPTYPE_REG_FS_STR;   break;
453                 case OPTYPE_REG_GS:             p_srcstr = OPTYPE_REG_GS_STR;   break;
454                 /* FPU Register */
455                 case OPTYPE_REG_FPU_ST0:        p_srcstr = OPTYPE_REG_FPU_ST0_STR;      break;
456                 case OPTYPE_REG_FPU_ST1:        p_srcstr = OPTYPE_REG_FPU_ST1_STR;      break;
457                 case OPTYPE_REG_FPU_ST2:        p_srcstr = OPTYPE_REG_FPU_ST2_STR;      break;
458                 case OPTYPE_REG_FPU_ST3:        p_srcstr = OPTYPE_REG_FPU_ST3_STR;      break;
459                 case OPTYPE_REG_FPU_ST4:        p_srcstr = OPTYPE_REG_FPU_ST4_STR;      break;
460                 case OPTYPE_REG_FPU_ST5:        p_srcstr = OPTYPE_REG_FPU_ST5_STR;      break;
461                 case OPTYPE_REG_FPU_ST6:        p_srcstr = OPTYPE_REG_FPU_ST6_STR;      break;
462                 case OPTYPE_REG_FPU_ST7:        p_srcstr = OPTYPE_REG_FPU_ST7_STR;      break;
463                 /* Control Register */
464                 case OPTYPE_REG_CR0:    p_srcstr = OPTYPE_REG_CR0_STR; break;
465                 case OPTYPE_REG_CR1:    p_srcstr = OPTYPE_REG_CR1_STR; break;
466                 case OPTYPE_REG_CR2:    p_srcstr = OPTYPE_REG_CR2_STR; break;
467                 case OPTYPE_REG_CR3:    p_srcstr = OPTYPE_REG_CR3_STR; break;
468                 case OPTYPE_REG_CR4:    p_srcstr = OPTYPE_REG_CR4_STR; break;
469                 case OPTYPE_REG_CR5:    p_srcstr = OPTYPE_REG_CR5_STR; break;
470                 case OPTYPE_REG_CR6:    p_srcstr = OPTYPE_REG_CR6_STR; break;
471                 case OPTYPE_REG_CR7:    p_srcstr = OPTYPE_REG_CR7_STR; break;
472                 case OPTYPE_REG_CR8:    p_srcstr = OPTYPE_REG_CR8_STR; break;
473                 case OPTYPE_REG_CR9:    p_srcstr = OPTYPE_REG_CR9_STR; break;
474                 case OPTYPE_REG_CR10:   p_srcstr = OPTYPE_REG_CR10_STR; break;
475                 case OPTYPE_REG_CR11:   p_srcstr = OPTYPE_REG_CR11_STR; break;
476                 case OPTYPE_REG_CR12:   p_srcstr = OPTYPE_REG_CR12_STR; break;
477                 case OPTYPE_REG_CR13:   p_srcstr = OPTYPE_REG_CR13_STR; break;
478                 case OPTYPE_REG_CR14:   p_srcstr = OPTYPE_REG_CR14_STR; break;
479                 case OPTYPE_REG_CR15:   p_srcstr = OPTYPE_REG_CR15_STR; break;
480                 /* Debug Register */
481                 case OPTYPE_REG_DR0:    p_srcstr = OPTYPE_REG_DR0_STR; break;
482                 case OPTYPE_REG_DR1:    p_srcstr = OPTYPE_REG_DR1_STR; break;
483                 case OPTYPE_REG_DR2:    p_srcstr = OPTYPE_REG_DR2_STR; break;
484                 case OPTYPE_REG_DR3:    p_srcstr = OPTYPE_REG_DR3_STR; break;
485                 case OPTYPE_REG_DR4:    p_srcstr = OPTYPE_REG_DR4_STR; break;
486                 case OPTYPE_REG_DR5:    p_srcstr = OPTYPE_REG_DR5_STR; break;
487                 case OPTYPE_REG_DR6:    p_srcstr = OPTYPE_REG_DR6_STR; break;
488                 case OPTYPE_REG_DR7:    p_srcstr = OPTYPE_REG_DR7_STR; break;
489                 case OPTYPE_REG_DR8:    p_srcstr = OPTYPE_REG_DR8_STR; break;
490                 case OPTYPE_REG_DR9:    p_srcstr = OPTYPE_REG_DR9_STR; break;
491                 case OPTYPE_REG_DR10:   p_srcstr = OPTYPE_REG_DR10_STR; break;
492                 case OPTYPE_REG_DR11:   p_srcstr = OPTYPE_REG_DR11_STR; break;
493                 case OPTYPE_REG_DR12:   p_srcstr = OPTYPE_REG_DR12_STR; break;
494                 case OPTYPE_REG_DR13:   p_srcstr = OPTYPE_REG_DR13_STR; break;
495                 case OPTYPE_REG_DR14:   p_srcstr = OPTYPE_REG_DR14_STR; break;
496                 case OPTYPE_REG_DR15:   p_srcstr = OPTYPE_REG_DR15_STR; break;
497                 /* MMX Register */
498                 case OPTYPE_REG_MMX0:   p_srcstr = OPTYPE_REG_MMX0_STR; break;
499                 case OPTYPE_REG_MMX1:   p_srcstr = OPTYPE_REG_MMX1_STR; break;
500                 case OPTYPE_REG_MMX2:   p_srcstr = OPTYPE_REG_MMX2_STR; break;
501                 case OPTYPE_REG_MMX3:   p_srcstr = OPTYPE_REG_MMX3_STR; break;
502                 case OPTYPE_REG_MMX4:   p_srcstr = OPTYPE_REG_MMX4_STR; break;
503                 case OPTYPE_REG_MMX5:   p_srcstr = OPTYPE_REG_MMX5_STR; break;
504                 case OPTYPE_REG_MMX6:   p_srcstr = OPTYPE_REG_MMX6_STR; break;
505                 case OPTYPE_REG_MMX7:   p_srcstr = OPTYPE_REG_MMX7_STR; break;
506                 /* SSE Register */
507                 case OPTYPE_REG_SSE0:   p_srcstr = OPTYPE_REG_SSE0_STR; break;
508                 case OPTYPE_REG_SSE1:   p_srcstr = OPTYPE_REG_SSE1_STR; break;
509                 case OPTYPE_REG_SSE2:   p_srcstr = OPTYPE_REG_SSE2_STR; break;
510                 case OPTYPE_REG_SSE3:   p_srcstr = OPTYPE_REG_SSE3_STR; break;
511                 case OPTYPE_REG_SSE4:   p_srcstr = OPTYPE_REG_SSE4_STR; break;
512                 case OPTYPE_REG_SSE5:   p_srcstr = OPTYPE_REG_SSE5_STR; break;
513                 case OPTYPE_REG_SSE6:   p_srcstr = OPTYPE_REG_SSE6_STR; break;
514                 case OPTYPE_REG_SSE7:   p_srcstr = OPTYPE_REG_SSE7_STR; break;
515                 case OPTYPE_REG_SSE8:   p_srcstr = OPTYPE_REG_SSE8_STR; break;
516                 case OPTYPE_REG_SSE9:   p_srcstr = OPTYPE_REG_SSE9_STR; break;
517                 case OPTYPE_REG_SSE10:  p_srcstr = OPTYPE_REG_SSE10_STR; break;
518                 case OPTYPE_REG_SSE11:  p_srcstr = OPTYPE_REG_SSE11_STR; break;
519                 case OPTYPE_REG_SSE12:  p_srcstr = OPTYPE_REG_SSE12_STR; break;
520                 case OPTYPE_REG_SSE13:  p_srcstr = OPTYPE_REG_SSE13_STR; break;
521                 case OPTYPE_REG_SSE14:  p_srcstr = OPTYPE_REG_SSE14_STR; break;
522                 case OPTYPE_REG_SSE15:  p_srcstr = OPTYPE_REG_SSE15_STR; break;
523                 default: break;
524         }
525
526         if( NULL != p_srcstr )  {
527                 strncpy( p_regstr, p_srcstr, i_maxstr ); 
528         }
529
530         return 0x00;
531 }
532
533
534 /*----------------------------------------------------------------------
535 ----------------------------------------------------------------------*/
536 int
537         Drd64_Intel64db_JudgeDB_AssemblePacket_OperandType(
538                 Drd64_Intel64_OperandNode       *p_operand,
539                 Word w_dbid)
540 {
541         int             i_ret;
542         Word    w_typeid;
543
544         w_typeid        = p_operand->w_typeid;  
545         i_ret           = 0xff;
546
547         /* C : [ModR/M:reg] Control Reg.  */
548         if( OPTYPE_DATA_METHOD_C == w_dbid )    {
549                 if( isRegType( w_typeid, OPTYPE_BASE_REG_CONTROL ) )
550                         { i_ret = 0x00; }
551         }
552         /* D : [ModR/M:reg] Debug Reg. */
553         else if( OPTYPE_DATA_METHOD_D == w_dbid )               {
554                 if( isRegType( w_typeid, OPTYPE_BASE_REG_DEBUG ) )
555                         { i_ret = 0x00; }
556         }
557         /* G : [ModR/M:reg] General Reg. */
558         else if( OPTYPE_DATA_METHOD_G == w_dbid )               {
559                 if( isRegType( w_typeid, OPTYPE_BASE_REG_GENERIC ) )
560                         { i_ret = 0x00; }
561         }
562         /* P : [ModR/M:reg] Packed-QuadWord MMX Reg. */
563         /* N : [ModR/M:R/M] Packed-QuadWord MMX Reg. */
564         else if(( OPTYPE_DATA_METHOD_P == w_dbid ) ||
565                         ( OPTYPE_DATA_METHOD_N == w_dbid ))     {
566                 if( isRegType( w_typeid, OPTYPE_BASE_REG_MMX ) )
567                         { i_ret = 0x00; }
568         }
569         /* V : [ModR/M:reg] 128bit XMM Reg. */
570         /* U : [ModR/M:R/M] 128bit XMM Reg. */
571         else if(( OPTYPE_DATA_METHOD_V == w_dbid ) ||
572                         ( OPTYPE_DATA_METHOD_U == w_dbid ))             {
573                 if( isRegType( w_typeid, OPTYPE_BASE_REG_SSE ) )
574                         { i_ret = 0x00; }
575         }
576         /* R : [ModR/M:R/M] refer to General Reg by R/M Field */
577         else if( OPTYPE_DATA_METHOD_R == w_dbid )               {
578                 if( isRegType( w_typeid, OPTYPE_BASE_REG_GENERIC ) )
579                         { i_ret = 0x00; }
580         }
581         /* E : [ModR/M] Memory & Reg. */
582         else if( OPTYPE_DATA_METHOD_E == w_dbid )               {
583                 if( isRegType( w_typeid, OPTYPE_BASE_REG_GENERIC ) )
584                         { i_ret = 0x00; }
585                 else if( isBitFlag( w_typeid, OPTYPE_BASE_DATA_IMMEDIATE_MEMSIZE ))     
586                         { i_ret = 0x00; }
587         }
588         /* S : [ModR/M:reg] Segment Reg. */
589         else if( OPTYPE_DATA_METHOD_S == w_dbid )               {
590                 if( isRegType( w_typeid, OPTYPE_BASE_REG_SEGMENT ) )
591                         { i_ret = 0x00; }
592         }
593         /* W : [ModR/M] 128bit XMM Reg. or Memory Address 
594         ( Memory Address calculated by Seg.Reg. BaseReg. IndexReg. 
595             ScalingFactor, Displacement */
596         else if( OPTYPE_DATA_METHOD_W == w_dbid )               {
597                 if( isRegType( w_typeid, OPTYPE_BASE_REG_SSE ) )
598                         { i_ret = 0x00; }
599                 else if( isBitFlag( w_typeid, OPTYPE_BASE_DATA_IMMEDIATE_MEMSIZE ))     
600                         { i_ret = 0x00; }
601         }
602         /* Q : [ModR/M] MMX reg. or Memory Address 
603         ( Memory Address calced by Seg.Reg, BaseReg. IndexReg. 
604             ScalingFactor, Displacement */
605         else if( OPTYPE_DATA_METHOD_Q == w_dbid )               {
606                 if( isRegType( w_typeid, OPTYPE_BASE_REG_MMX ) )
607                         { i_ret = 0x00; }
608                 else if( isBitFlag( w_typeid, OPTYPE_BASE_DATA_IMMEDIATE_MEMSIZE ))     
609                         { i_ret = 0x00; }
610         }
611         /* M : Memory Access (by ModR/M) (NO!!: Reg. Indicate by ModR/M) */
612         else if( OPTYPE_DATA_METHOD_M == w_dbid )               {
613                 if( isBitFlag( w_typeid, OPTYPE_BASE_DATA_IMMEDIATE_MEMSIZE ))  
614                         { i_ret = 0x00; }
615         }
616         /* I : Immediate Data (NO!!: ModR/M) */
617         /* J : IP relative Address (NO!!: ModR/M) */
618         else if(( OPTYPE_DATA_METHOD_I == w_dbid ) ||
619                         ( OPTYPE_DATA_METHOD_J == w_dbid ))             {
620                 if( isBitFlag( w_typeid, OPTYPE_BASE_DATA_IMMEDIATE_IMM ))      
621                         { i_ret = 0x00; }
622         }
623         /* O : XXX Word of DWord Data
624                 (NO!!: ModR/M, BaseReg. IndexReg, ScalingFactor */
625         /*else if( OPTYPE_DATA_METHOD_O == w_dbid )             {
626                 if( isBitFlag( w_typeid, OPTYPE_BASE_DATA_IMMEDIATE_IMM ))      
627                         { i_ret = 0x00; }
628         }*/
629         /* F : EFLAGS / RFLAGS Reg. (NO!!: ModR/M)  */
630         /* X : DS:rSI (Memory Address) */
631         /* Y : ES:rDI (Memory Address) */
632         else if(( OPTYPE_DATA_METHOD_F == w_dbid ) ||
633                         ( OPTYPE_DATA_METHOD_X == w_dbid ) ||   
634                         ( OPTYPE_DATA_METHOD_Y == w_dbid ))             {
635                 if( NULL == p_operand ) 
636                         { i_ret = 0x00; }
637         }
638         /* 1 : 0x01 Data (Immediate Data) */
639         else if( OPTYPE_DATA_METHOD_1 == w_dbid )               {
640                 if( isBitFlag( w_typeid, OPTYPE_BASE_DATA_IMMEDIATE_IMM ))      {
641                         if( 1 == p_operand->v_val.val.val64 )           
642                                 { i_ret = 0x00; }
643                 }
644         }
645         else if( isRegType( w_dbid, OPTYPE_BASE_REG_GENERIC ) ) {
646                 if(((unsigned int)w_dbid & OPTYPE_BASE_REG_GENERIC_IDMASK)
647                                 == ((unsigned int)w_typeid & OPTYPE_BASE_REG_GENERIC_IDMASK))
648                         { i_ret = 0x00; }
649         }
650         else if( isRegType( w_dbid, OPTYPE_BASE_REG_SEGMENT ) ) {
651                 if( w_dbid == w_typeid )        {
652                         i_ret   = 0x00;
653                 }
654         }
655         else if( isRegType( w_dbid, OPTYPE_BASE_REG_FPU ) )     {
656                 if( w_dbid == w_typeid )        {
657                         i_ret   = 0x00;
658                 }
659         }
660         /* - : Illegal Instruction by DrDeamon64 Assembler System */
661         /*else  {       OPTYPE_DATA_METHOD_ILLEGAL
662         } */
663         /* Method Type T = No Impliment 
664         else if( OPTYPE_DATA_METHOD_S == w_typeid )     { } */
665         /* A : Direct Address
666                 (NO!!: ModR/M, BaseReg, IndexReg, ScalingFactor)
667         else if( OPTYPE_DATA_METHOD_A == w_dbid )       { } */
668         
669         return i_ret;
670 }
671
672
673 /*----------------------------------------------------------------------
674 ----------------------------------------------------------------------*/
675 int
676         Drd64_Intel64db_JudgeDB_AssemblePacket_OperandSize(
677                 int             *pi_operandsize,
678                 Drd64_Intel64_OperandNode       *p_operand,
679                 Word w_dbsizeid)
680 {
681         int             i_ret;
682         int             i_size;
683
684         i_ret   = 0xff;
685
686         if( 0 == p_operand->i_operandsize )
687                 { return i_ret; }
688
689         if( OPSIZE_B == w_dbsizeid )    {
690                 if( 1 == p_operand->i_operandsize )     
691                         { i_ret = 0x00; }
692         }
693         else if( OPSIZE_W == w_dbsizeid )       {
694                 if( 2 == p_operand->i_operandsize )     
695                         { i_ret = 0x00; }
696                 else if(( isBitFlag( p_operand->w_typeid,
697                                         OPTYPE_BASE_DATA_IMMEDIATE_IMM ))
698                                 && ( 2 >= p_operand->i_operandsize))
699                         { i_ret = 0x00; }
700         }
701         else if( OPSIZE_D == w_dbsizeid )       {
702                 if( 4 == p_operand->i_operandsize )     
703                         { i_ret = 0x00; }
704                 else if(( isBitFlag( p_operand->w_typeid,
705                                         OPTYPE_BASE_DATA_IMMEDIATE_IMM ))
706                                 && ( 4 >= p_operand->i_operandsize))
707                         { i_ret = 0x00; }
708         }
709         else if( OPSIZE_Q == w_dbsizeid )       {
710                 if( 8 == p_operand->i_operandsize )     
711                         { i_ret = 0x00; }
712                 else if(( isBitFlag( p_operand->w_typeid,
713                                         OPTYPE_BASE_DATA_IMMEDIATE_IMM ))
714                                 && ( 8 >= p_operand->i_operandsize))
715                         { i_ret = 0x00; }
716         }
717         else if(( OPSIZE_DQ == w_dbsizeid ) ||
718                         ( OPSIZE_PD == w_dbsizeid )     ||
719                         ( OPSIZE_PS == w_dbsizeid )     ||
720                         ( OPSIZE_SD == w_dbsizeid )     ||
721                         ( OPSIZE_SS == w_dbsizeid ))    {       
722                 if( 16 == p_operand->i_operandsize )    
723                         { i_ret = 0x00; }
724         }
725         /* XXX */
726         else if( OPSIZE_H == w_dbsizeid )       {
727                 if( 8 == p_operand->i_operandsize )     
728                         { i_ret = 0x00; }
729         }
730         /* XXX */
731         else if( OPSIZE_S == w_dbsizeid )       {
732
733         }
734         else if(( OPSIZE_V == w_dbsizeid ) ||
735                         ( OPSIZE_P == w_dbsizeid ))     {
736                 if(( 8 == p_operand->i_operandsize ) ||
737                                 ( 4 == p_operand->i_operandsize ) ||
738                                 ( 2 == p_operand->i_operandsize ))       {
739                         i_ret   = 0x00;
740                         *pi_operandsize = p_operand->i_operandsize;
741                 }
742                 else if(( isBitFlag( p_operand->w_typeid,
743                                         OPTYPE_BASE_DATA_IMMEDIATE_IMM ))
744                                 && ( 8 >= p_operand->i_operandsize)) {
745                         i_ret   = 0x00;
746                 }
747         }
748         else if( OPSIZE_Z == w_dbsizeid )       {
749                 if( 0 == *pi_operandsize )      {
750                         if(( 4 == p_operand->i_operandsize ) ||
751                                         ( 2 == p_operand->i_operandsize ))       {
752                                 i_ret   = 0x00;
753                                 *pi_operandsize = p_operand->i_operandsize;
754                         }
755                         else if(( isBitFlag( p_operand->w_typeid,
756                                                 OPTYPE_BASE_DATA_IMMEDIATE_IMM ))
757                                         && ( 4 >= p_operand->i_operandsize)) {
758                                 i_ret   = 0x00;
759                         }
760                 }
761                 else    {
762                         if( 2 == *pi_operandsize )      {
763                                 if( 2 == p_operand->i_operandsize )
764                                         { i_ret = 0x00; }
765                                 else if(( isBitFlag( p_operand->w_typeid,
766                                                         OPTYPE_BASE_DATA_IMMEDIATE_IMM ))
767                                                 && ( 2 >= p_operand->i_operandsize)) {
768                                         i_ret   = 0x00;
769                                 }
770                         }
771                         else    {
772                                 if( 4 == p_operand->i_operandsize )     {
773                                         i_ret   = 0x00;
774                                 }
775                                 else if(( isBitFlag( p_operand->w_typeid,
776                                                         OPTYPE_BASE_DATA_IMMEDIATE_IMM ))
777                                                 && ( 4 >= p_operand->i_operandsize)) {
778                                         i_ret   = 0x00;
779                                 }
780                         }
781                 }
782         }
783         /*else if( OPSIZE_A == w_dbsizeid )     { } */
784         else if( ((Word)OPSIZE_ILLEGAL) == w_dbsizeid )         {
785                 if( !isBitFlag( p_operand->w_typeid, OPTYPE_BASE_DATA ) )       {
786                         if( (( 0 < *pi_operandsize ) &&
787                                         ( p_operand->i_operandsize == *pi_operandsize)) ||
788                                         ( 0 == *pi_operandsize ))
789                         { i_ret = 0x00; }
790                 }
791                 else if( ((Word)p_operand->w_typeid) == OPTYPE_DATA_METHOD_1 )
792                         { i_ret = 0x00; } 
793         }
794
795         return i_ret;
796 }
797
798
799 /*----------------------------------------------------------------------
800 ----------------------------------------------------------------------*/
801 int
802         Drd64_Intel64db_JudgeDB_AssemblePacket_Operand(
803                 int             *pi_operandsize,
804                 Drd64_Intel64_OperandNode       *p_operand,
805                 Word    w_dbtypeid,
806                 Word    w_dbsizeid)
807 {
808         int             i_err;
809
810         i_err   = Drd64_Intel64db_JudgeDB_AssemblePacket_OperandType(
811                 p_operand, w_dbtypeid);
812         if( 0x00 != i_err )
813                 { return i_err; }
814
815         i_err   = Drd64_Intel64db_JudgeDB_AssemblePacket_OperandSize(
816                 pi_operandsize, p_operand, w_dbsizeid);
817         if( 0x00 != i_err )
818                 { return i_err; }
819         
820         return 0x00;
821 }
822
823
824 /*----------------------------------------------------------------------
825 ----------------------------------------------------------------------*/
826 int
827         Drd64_Intel64db_SetAnalyzePacket_fromDB(
828                 Drd64_Intel64_AnalyzePacket *p_analyze,
829                 Drd64_Intel64db_Record *p_db64rec_now)
830 {
831
832         if( 0x00 != p_db64rec_now->b_prefix )   {
833                 p_analyze->b_prefix[0]  = p_db64rec_now->b_prefix;
834                 p_analyze->i_prefixes   = 1;
835         }
836
837         p_analyze->rex.b_rex    = p_db64rec_now->b_rex;
838         p_analyze->b_codetype   = p_db64rec_now->b_option;
839         p_analyze->i_opcodes    = p_db64rec_now->i_opcodes;
840
841         if( 0x07 == p_db64rec_now->b_option ) 
842                 { p_analyze->i_opcodes  = 1; }
843         else if( 0x08 == p_db64rec_now->b_option ) 
844                 { p_analyze->i_opcodes  = 2; }
845
846         p_analyze->b_opcode[0]  = p_db64rec_now->b_opcode[0];
847         if( 0x00 != p_db64rec_now->b_fpu )      {
848                 p_analyze->b_opcode[1]  = p_db64rec_now->b_fpu;
849         } else  {
850                 p_analyze->b_opcode[1]  = p_db64rec_now->b_opcode[1];
851                 p_analyze->b_opcode[2]  = p_db64rec_now->b_opcode[2];
852         }
853
854         p_analyze->b_modtype    = p_db64rec_now->b_mod;
855         p_analyze->b_regtype    = p_db64rec_now->b_reg;
856         p_analyze->b_rmtype             = p_db64rec_now->b_rm;
857         p_analyze->b_bits               = p_db64rec_now->b_bits;
858         p_analyze->i_operands   = p_db64rec_now->i_operands;
859         p_analyze->w_desttype   = p_db64rec_now->w_desttype;
860         p_analyze->w_destsize   = p_db64rec_now->w_destsize;
861         p_analyze->w_srctype    = p_db64rec_now->w_srctype;
862         p_analyze->w_srcsize    = p_db64rec_now->w_srcsize;
863         p_analyze->w_optiontype = p_db64rec_now->w_optiontype;
864         p_analyze->w_optionsize = p_db64rec_now->w_optionsize;
865
866         return 0x00;
867 }
868                 
869
870 /*----------------------------------------------------------------------
871 ----------------------------------------------------------------------*/
872 int
873         Drd64_Intel64db_SearchInstruction(
874                 Drd64_Intel64_AnalyzePacket *p_analyze,
875                 Drd64_Intel64_AssemblePacket *p_assemble)
876 {
877         Drd64_Intel64db_Record  *p_db64rec_now;
878         int             i_operandsize;
879         int             i_err;
880         int             i_hash;
881         
882         i_err                   = 0xff;
883         p_db64rec_now   = p_db64rec;
884
885
886         /* Calc. Instruction Hash */
887         i_hash  = Drd64_Intel64_DBCommon_CalcHashValue(
888                                                         p_assemble->str_instruction );
889         p_db64rec_now   = p_db64_hashtable[ i_hash ];
890
891
892         /* Search Instruction */
893         do      {
894                 
895                 if( !strncmp( p_assemble->str_instruction, 
896                                                 p_db64rec_now->str_instruction,
897                                                 MAX_INSTRUCTION ))
898                         { break; }
899
900                 p_db64rec_now   = p_db64rec_now->p_dbrec_search;
901         }while( p_db64rec_now != NULL );
902         
903         if( NULL == p_db64rec_now )      { return 0x01; }
904
905         /* Search Operand */
906         do      {
907                 
908                 i_err   = 0x00;
909
910                 if( 32 == p_db64rec_now->b_bits )
911                         { i_err = 0x01; }
912
913                 i_operandsize   = 0;
914                 if( NULL != p_assemble->p_desttree )    {
915                         i_err += Drd64_Intel64db_JudgeDB_AssemblePacket_Operand(
916                                                 &i_operandsize, 
917                                                 p_assemble->p_desttree, 
918                                                 p_db64rec_now->w_desttype,
919                                                 p_db64rec_now->w_destsize);
920                 }
921                 else    {
922                         if( 0 < p_db64rec_now->i_operands )     {
923                                 i_err   += 0x01;
924                         }
925                 }
926
927                 if( NULL != p_assemble->p_srctree )     {
928                         i_err += Drd64_Intel64db_JudgeDB_AssemblePacket_Operand(
929                                                 &i_operandsize, 
930                                                 p_assemble->p_srctree, 
931                                                 p_db64rec_now->w_srctype,
932                                                 p_db64rec_now->w_srcsize);
933                 }
934                 else    {
935                         if( 1 < p_db64rec_now->i_operands )     {
936                                 i_err   += 0x01;
937                         }
938                 }
939
940                 if( NULL != p_assemble->p_optiontree )  {
941                         i_err += Drd64_Intel64db_JudgeDB_AssemblePacket_Operand(
942                                                 &i_operandsize, 
943                                                 p_assemble->p_optiontree, 
944                                                 p_db64rec_now->w_optiontype,
945                                                 p_db64rec_now->w_optionsize);
946                 }
947                 else    {
948                         if( 2 < p_db64rec_now->i_operands )     {
949                                 i_err   += 0x01;
950                         }
951                 }
952
953                 if( 0x00 == i_err )     {
954                         Drd64_Intel64db_SetAnalyzePacket_fromDB( p_analyze, p_db64rec_now );
955                         break;
956                 }
957
958                 p_db64rec_now   = p_db64rec_now->p_dbrec_link;  
959
960         }while( NULL != p_db64rec_now );
961
962         return i_err;
963 }
964
965
966 /*-----------------------------------------------------------------------
967
968 -----------------------------------------------------------------------*/
969 static int
970         Drd64_Intel64db_JudgeDB_AnalyzePacket( 
971                 Drd64_Intel64_AnalyzePacket *p_analyze,
972                 Drd64_Intel64db_Record *p_db64, Byte b_bits )
973 {
974
975         /* Judge Instruction - Bits */
976         if( INTEL64_BITFREE != p_db64->b_bits ) {
977                 if( b_bits != p_db64->b_bits )
978                         { return 0xff; }
979         }
980
981         /* Judge Opecode */
982         if( p_analyze->i_opcodes > 0 )  {
983                 if( p_db64->b_opcode[0] != p_analyze->b_opcode[0] )
984                         { return 0x01; }
985         }
986
987         if( p_analyze->i_opcodes > 1 )  {
988                 if( p_db64->i_opcodes < 2 )
989                         { return 0x21; }
990                 if( p_db64->b_opcode[1] != p_analyze->b_opcode[1] ) {
991                         if( 0x00 != p_db64->b_fpu )     {
992                                 if( p_db64->b_fpu != p_analyze->b_opcode[1] )
993                                         { return 0x22; }
994                         } else  {
995                                 return 0x23;
996                         }
997                 }
998         }
999
1000         if( p_analyze->i_opcodes > 2 )  {
1001                 if( p_db64->i_opcodes < 3 )
1002                         { return 0x03; }
1003                 if( p_db64->b_opcode[2] != p_analyze->b_opcode[2] )
1004                         { return 0x03; }
1005         }
1006         
1007         /* Judge REX prefix */
1008         if( 0x00 != p_db64->b_rex )     {
1009                 if( p_db64->b_rex != p_analyze->rex.b_rex )
1010                         { return 0x04; }
1011         }
1012
1013         /* Judge Prefix */
1014         if( 0x00 != p_db64->b_prefix )  {
1015                 if( 0 == p_analyze->i_prefixes )                        {
1016                         return 0x51;
1017                 } else if( 1 == p_analyze->i_prefixes )         {
1018                         if( p_analyze->b_prefix[0] != p_db64->b_prefix )
1019                                 { return 0x52;  }
1020                 } else if( 2 == p_analyze->i_prefixes )         {
1021                         if(( p_analyze->b_prefix[0] != p_db64->b_prefix )
1022                                         && ( p_analyze->b_prefix[1] != p_db64->b_prefix ))      
1023                                 { return 0x53;  }
1024                 } else if( 3 == p_analyze->i_prefixes )         {
1025                         if(( p_analyze->b_prefix[0] != p_db64->b_prefix )
1026                                         && ( p_analyze->b_prefix[1] != p_db64->b_prefix )
1027                                         && ( p_analyze->b_prefix[2] != p_db64->b_prefix ))      
1028                                 { return 0x54;  }
1029                 } else if( 4 == p_analyze->i_prefixes )         {
1030                         if(( p_analyze->b_prefix[0] != p_db64->b_prefix )
1031                                         && ( p_analyze->b_prefix[1] != p_db64->b_prefix )
1032                                         && ( p_analyze->b_prefix[2] != p_db64->b_prefix )
1033                                         && ( p_analyze->b_prefix[3] != p_db64->b_prefix ))      
1034                                 { return 0x55;  }
1035                 }
1036
1037                 /* XXX :
1038                 if( (( 0 < p_analyze->i_prefixes )
1039                                  && ( p_analyze->b_prefix[0] != p_db64->b_prefix ))
1040                         || (( 1 < p_analyze->i_prefixes )
1041                                  && ( p_analyze->b_prefix[1] != p_db64->b_prefix ))
1042                         || (( 2 < p_analyze->i_prefixes )
1043                                  && ( p_analyze->b_prefix[2] != p_db64->b_prefix ))
1044                         || (( 3 < p_analyze->i_prefixes )
1045                                  && ( p_analyze->b_prefix[3] != p_db64->b_prefix )) )
1046                                 { return 0x52; }
1047                 */
1048
1049         }
1050         /* Judge ModR/M */
1051         if( 0 < p_analyze->i_modrm_bytes )      {
1052                 if( INTEL64_MODTYPE_REG == p_db64->b_mod )      {
1053                         if( 0x03 != p_analyze->modrm.modrm.mod)
1054                                 { return 0x61; }
1055                         if( ( 0x08 > p_db64->b_reg)
1056                                         && ( p_analyze->modrm.modrm.reg != p_db64->b_reg ))
1057                                 { return 0x62; } 
1058                         if( ( 0x08 > p_db64->b_rm)
1059                                         && ( p_analyze->modrm.modrm.rm != p_db64->b_rm ))
1060                                 { return 0x63; } 
1061                 }
1062                 else if( INTEL64_MODTYPE_MEMREG == p_db64->b_mod )      {
1063                         if( ( 0x08 > p_db64->b_reg)
1064                                         && ( p_analyze->modrm.modrm.reg != p_db64->b_reg ))
1065                                 { return 0x71; } 
1066                         if( ( 0x08 > p_db64->b_rm)
1067                                         && ( p_analyze->modrm.modrm.rm != p_db64->b_rm ))
1068                                 { return 0x72; } 
1069
1070                 } 
1071                 else if( INTEL64_MODTYPE_MEM == p_db64->b_mod ) {
1072                         if( 0x03 == p_analyze->modrm.modrm.mod)
1073                                 { return 0x81; }
1074                         if( ( 0x08 > p_db64->b_reg)
1075                                         && ( p_analyze->modrm.modrm.reg != p_db64->b_reg ))
1076                                 { return 0x82; } 
1077                         if( ( 0x08 > p_db64->b_rm)
1078                                         && ( p_analyze->modrm.modrm.rm != p_db64->b_rm ))
1079                                 { return 0x83; } 
1080
1081                 } 
1082
1083                 else if( INTEL64_MODTYPE_FPU == p_db64->b_mod ) {
1084                         if( 0xbf < p_analyze->modrm.b_modrm )
1085                                 { return 0x91;  }
1086                         if(( 0x08 > p_db64->b_reg )
1087                                         && ( p_analyze->modrm.modrm.reg != p_db64->b_reg))
1088                                 { return 0x92;  }
1089
1090                 }
1091
1092                 if( INTEL64_MODTYPE_FPU == p_analyze->b_modtype )       {
1093                         if( INTEL64_MODTYPE_ESCAPE == p_db64->b_mod )
1094                                 { return 0xa0;  }
1095                 }
1096                 
1097         }
1098         return 0x00;
1099 }
1100
1101
1102 /*-----------------------------------------------------------------------
1103 Byte
1104         Drd64_Intel64db_GetByteCodeType(
1105                 : Get ByteCode Tyep from Intel 64 DataBase 
1106         
1107                 Drd64_Intel64_AnalyzePacket *p_analyze) 
1108                         : [Dest][Src] Analyze Packet
1109 -----------------------------------------------------------------------*/
1110 Byte
1111         Drd64_Intel64db_GetByteCodeType(
1112                 Drd64_Intel64_AnalyzePacket *p_analyze)
1113 {
1114         Byte    b_ret   = INTEL64_CODETYPE_NOINSTRUCTION;
1115         Drd64_Intel64db_Record  *p_db64rec_now;
1116         void                                    **p_ext_bytetable;
1117         int             i_judge;
1118
1119         if( 1 < p_analyze->i_opcodes )          {
1120                 p_ext_bytetable = p_db64_bytetable[1][ p_analyze->b_opcode[0] ];
1121                 if( NULL == p_ext_bytetable )   {
1122                         return INTEL64_CODETYPE_ERROR;
1123                 }
1124                 p_db64rec_now   = *(p_ext_bytetable + p_analyze->b_opcode[1] );
1125         } else  {
1126                 p_db64rec_now   = p_db64_bytetable[0][ p_analyze->b_opcode[0] ];
1127         }
1128
1129         if( NULL == p_db64rec_now )     {
1130                 return INTEL64_CODETYPE_ERROR;
1131         }
1132
1133         do      {
1134                 i_judge = Drd64_Intel64db_JudgeDB_AnalyzePacket(
1135                                                 p_analyze, p_db64rec_now, INTEL64_BIT64ONLY );
1136                 if( 0x00 == i_judge )   {
1137                         b_ret   = p_db64rec_now->b_option;
1138                         p_analyze->b_codetype   = p_db64rec_now->b_option;
1139                         p_analyze->b_modtype    = p_db64rec_now->b_mod;
1140                         p_analyze->b_regtype    = p_db64rec_now->b_reg;
1141                         p_analyze->b_rmtype             = p_db64rec_now->b_rm;
1142                         strncpy( p_analyze->str_instruction,
1143                                 p_db64rec_now->str_instruction, MAX_INSTRUCTION );
1144                         
1145                         p_analyze->w_desttype   = p_db64rec_now->w_desttype;
1146                         p_analyze->w_destsize   = p_db64rec_now->w_destsize;
1147                         p_analyze->w_srctype    = p_db64rec_now->w_srctype;
1148                         p_analyze->w_srcsize    = p_db64rec_now->w_srcsize;
1149                         p_analyze->w_optiontype = p_db64rec_now->w_optiontype;
1150                         p_analyze->w_optionsize = p_db64rec_now->w_optionsize;
1151                         break;  
1152                 }
1153                 p_db64rec_now++;        
1154         } while( p_db64rec_now->i_num < i_db64datanum );
1155
1156         return b_ret;
1157 }
1158
1159
1160 /*-----------------------------------------------------------------------
1161 Byte
1162         Drd64_Intel64db_GetBytePrefixType(
1163                 : Get ByteCode Type is Prefix Or None
1164
1165                 Byte b_code,    : [src] ByteCode 
1166                 Byte b_bits)    : [opt] Judge Bit Mode (32/64)
1167
1168 -----------------------------------------------------------------------*/
1169 Byte
1170         Drd64_Intel64db_GetBytePrefixType(
1171                 Byte b_code,
1172                 Byte b_bits)
1173 {
1174         Byte    b_ret   = 0x00;
1175         Drd64_Intel64db_Record  *p_db64rec_now;
1176
1177         p_db64rec_now   = p_db64_bytetable[0][b_code];
1178         do      {
1179                 if(( INTEL64_BITFREE == p_db64rec_now->b_bits )
1180                         || ((INTEL64_BIT64ONLY == b_bits )
1181                                 && ( INTEL64_BIT64ONLY == p_db64rec_now->b_bits ))) {
1182                         b_ret   = p_db64rec_now->b_option;
1183                         break;  
1184                 }
1185                 p_db64rec_now++;        
1186         } while( p_db64rec_now->i_num < i_db64datanum );
1187         
1188         return b_ret;
1189 }
1190
1191
1192 /*-----------------------------------------------------------------------
1193 static int
1194         Drd64_Intel64db_FreeByteTable(void)
1195                 : Free Intel 64 Database Byte Table for High-speed Access
1196 -----------------------------------------------------------------------*/
1197 static int
1198         Drd64_Intel64db_FreeByteTable(void)
1199 {
1200         int             i_cnt;
1201
1202         for( i_cnt=0; i_cnt<256; i_cnt++ )      {
1203                 if( NULL != p_db64_bytetable[1][ i_cnt ] )      {
1204                         free( p_db64_bytetable[1][ i_cnt ] );
1205                         p_db64_bytetable[1][ i_cnt ]    = NULL; 
1206                 }
1207                 p_db64_bytetable[0][ i_cnt ]    = NULL; 
1208         }
1209         
1210         return 0x00;
1211 }
1212
1213
1214 /*-----------------------------------------------------------------------
1215 static int
1216         Drd64_Intel64db_GenerateByteTable(void)
1217                 : Generate Intel 64 Database Byte Table for High-speed Access
1218 -----------------------------------------------------------------------*/
1219 static int
1220         Drd64_Intel64db_GenerateByteTable(void)
1221 {
1222         int                                             i_cnt;
1223         Drd64_Intel64db_Record  *p_db64rec_now;
1224         void                                    **p_ext_bytetable;
1225         Byte                                    b_opcode[2];
1226
1227         /* Initialize Byte Table */
1228         memset( p_db64_bytetable, 0x00, sizeof(void *) * 256 * 2);
1229
1230         for( i_cnt=i_db64datanum; i_cnt>=0; i_cnt-- )   {
1231                 p_db64rec_now   = p_db64rec + i_cnt;
1232                 b_opcode[0]             = p_db64rec_now->b_opcode[0];
1233         
1234                 if( 1 < p_db64rec_now->i_opcodes )      {
1235                         if( NULL == p_db64_bytetable[1][ b_opcode[0] ] )        {
1236                                 p_ext_bytetable = malloc( 256 * sizeof(void *));
1237                                 if( NULL == p_ext_bytetable )   {
1238                                         return 0x01;
1239                                 }
1240                                 p_db64_bytetable[1][ b_opcode[0] ] = p_ext_bytetable;
1241                         }
1242                         
1243                         if( 4 == p_db64rec_now->i_opcodes ) 
1244                                 { b_opcode[1]   = p_db64rec_now->b_fpu; }
1245                         else
1246                                 { b_opcode[1]   = p_db64rec_now->b_opcode[1]; }
1247                                         
1248                         p_ext_bytetable = p_db64_bytetable[1][ b_opcode[0] ];
1249                         *(p_ext_bytetable + b_opcode[1]) = p_db64rec_now;
1250                 } else  {
1251                         p_db64_bytetable[0][ b_opcode[0] ] = p_db64rec_now;
1252                 }
1253         }
1254
1255         return 0x00;
1256 }
1257
1258
1259 /*-----------------------------------------------------------------------
1260 static int
1261         Drd64_Intel64db_GenerateByteTable(void)
1262                 : Generate Intel 64 Database Byte Table for High-speed Access
1263 -----------------------------------------------------------------------*/
1264 static int
1265         Drd64_Intel64db_GenerateHashTable(
1266                 FILE    *fp_db )
1267 {
1268         int             i_cnt;
1269         int             i_hashtable[DRD64_INTEL64DB_HASH_RADIX];
1270
1271         if( 1 != fread( &i_hashtable, sizeof(int) * DRD64_INTEL64DB_HASH_RADIX,
1272                                                 1, fp_db))      {
1273                 puts("Error 005");
1274                 return 0x05;
1275         }
1276
1277         for( i_cnt = 0; i_cnt < DRD64_INTEL64DB_HASH_RADIX; i_cnt++ )   {
1278                 if( 0 > i_hashtable[i_cnt] )    {       
1279                         p_db64_hashtable[i_cnt] = NULL;
1280                 } else  {
1281                         p_db64_hashtable[i_cnt] = (p_db64rec + i_hashtable[i_cnt]);
1282                 }
1283         }
1284
1285         return 0x00;
1286 }
1287
1288
1289 /*-----------------------------------------------------------------------
1290 static Drd64_Intel64db_Record *
1291         Drd64_Intel64db_AllocMemory(void)
1292                 : Alloc Intel 64 Database Memory 
1293 -----------------------------------------------------------------------*/
1294 static Drd64_Intel64db_Record *
1295         Drd64_Intel64db_AllocMemory(void)
1296 {
1297         Drd64_Intel64db_Record  *p_db64rec_ret;
1298
1299         p_db64rec_ret   = NULL;
1300         p_db64rec_ret = (Drd64_Intel64db_Record *)malloc(sizeof(Drd64_Intel64db_Record) * i_db64datanum);
1301         if( NULL == p_db64rec_ret )     {
1302                 return p_db64rec_ret;
1303         }
1304
1305         memset( p_db64rec_ret, 0x00,
1306                         sizeof(Drd64_Intel64db_Record) * i_db64datanum );
1307
1308         return p_db64rec_ret;
1309 }
1310
1311
1312 /*-----------------------------------------------------------------------
1313 static int
1314         Drd64_Intel64db_LoadRecord(FILE *)
1315                 : Load Intel 64 DataBase from binary-File
1316 -----------------------------------------------------------------------*/
1317 static int
1318         Drd64_Intel64db_LoadRecord(
1319                 FILE    *fp_db )
1320 {
1321         int             i_cnt;
1322         Drd64_Intel64db_FileRecord      db64_filerecord;
1323         Drd64_Intel64db_Record          *p_db64rec_now;
1324
1325         p_db64rec_now   = p_db64rec;
1326         for( i_cnt=0; i_cnt<i_db64datanum; i_cnt++ )    {
1327                 /* Read Record */
1328                 memset( &db64_filerecord, 0x00, sizeof(Drd64_Intel64db_FileRecord));
1329                 if( 1 != fread( &db64_filerecord, sizeof(Drd64_Intel64db_FileRecord), 1, fp_db))        {
1330                         puts("Error 004");
1331                         return 0x04;
1332                 }
1333
1334                 /* Copy PackData to MemoryData */
1335                 p_db64rec_now->i_num            = db64_filerecord.i_num;
1336                 p_db64rec_now->b_prefix         = db64_filerecord.b_prefix;
1337                 p_db64rec_now->b_rex            = db64_filerecord.b_rex;
1338                 p_db64rec_now->i_opcodes        = db64_filerecord.i_opcodes;
1339                 p_db64rec_now->b_opcode[0]      = db64_filerecord.b_opcode[0];
1340                 p_db64rec_now->b_opcode[1]      = db64_filerecord.b_opcode[1];
1341                 p_db64rec_now->b_opcode[2]      = db64_filerecord.b_opcode[2];
1342                 p_db64rec_now->b_mod            = db64_filerecord.b_mod;
1343                 p_db64rec_now->b_reg            = db64_filerecord.b_reg;
1344                 p_db64rec_now->b_rm                     = db64_filerecord.b_rm;
1345                 p_db64rec_now->b_fpu            = db64_filerecord.b_fpu;
1346                 p_db64rec_now->b_bits           = db64_filerecord.b_bits;
1347                 strncpy( p_db64rec_now->str_instruction,
1348                                         db64_filerecord.str_instruction, MAX_INSTRUCTION );
1349                 p_db64rec_now->b_option         = db64_filerecord.b_option;
1350                 p_db64rec_now->i_operands       = db64_filerecord.i_operands;
1351                 p_db64rec_now->w_desttype       = db64_filerecord.w_desttype;
1352                 p_db64rec_now->w_destsize       = db64_filerecord.w_destsize;
1353                 p_db64rec_now->w_srctype        = db64_filerecord.w_srctype;
1354                 p_db64rec_now->w_srcsize        = db64_filerecord.w_srcsize;
1355                 p_db64rec_now->w_optiontype     = db64_filerecord.w_optiontype;
1356                 p_db64rec_now->w_optionsize     = db64_filerecord.w_optionsize;
1357                 p_db64rec_now->b_duplicationflag        = db64_filerecord.b_duplicationflag;
1358                 p_db64rec_now->i_priority       = db64_filerecord.i_priority;
1359                 p_db64rec_now->w_restrict       = db64_filerecord.w_restrict;
1360                 p_db64rec_now->b_hash           = db64_filerecord.b_hash;
1361                 
1362                 if( 0 > db64_filerecord.i_link )        {
1363                         p_db64rec_now->p_dbrec_link     = NULL;
1364                 } else  {
1365                         p_db64rec_now->p_dbrec_link     
1366                                         = (p_db64rec + db64_filerecord.i_link);
1367                 }
1368
1369                 if( 0 > db64_filerecord.i_search )      {
1370                         p_db64rec_now->p_dbrec_search   = NULL;
1371                 } else  {
1372                         p_db64rec_now->p_dbrec_search   
1373                                         = (p_db64rec + db64_filerecord.i_search);
1374                 }
1375
1376                 p_db64rec_now++;
1377         }
1378
1379         return 0x00;
1380 }
1381
1382
1383 /*-----------------------------------------------------------------------
1384 [extern] int
1385         Drd64_Intel64db_Initialize(void)
1386                 : Initialize Intel 64 DataBase Before Use. 
1387 -----------------------------------------------------------------------*/
1388 int
1389         Drd64_Intel64_DB_Initialize(
1390                 void)
1391 {
1392         int             i_cnt;
1393         FILE    *fp_db;
1394         Drd64_Intel64db_FileHeader      db64_fileheader;
1395
1396         fp_db   = NULL;
1397         i_db64datanum   = 0;
1398         
1399         /* Load DB file */
1400         fp_db   = fopen(DRD64_INTEL64DB_FILENAME, "rb");
1401         if( NULL == fp_db )             { return 0x01; }
1402
1403         /* DB header Load */
1404         if( 1 != fread(&db64_fileheader,
1405                                 sizeof(Drd64_Intel64db_FileHeader), 1, fp_db))
1406                 { return 0x02;  }
1407         
1408         /* Check DB Header */
1409
1410
1411         /* Set Header Data */
1412         i_db64datanum   = (int)db64_fileheader.w_lines;
1413
1414         /* Alloc Memory */
1415         p_db64rec = Drd64_Intel64db_AllocMemory();
1416         if( NULL == p_db64rec )         { return 0x03; }
1417
1418         /* Load */
1419         if( 0x00 != Drd64_Intel64db_LoadRecord(fp_db) )
1420                         { return 0x04; }
1421
1422         /* Make Byte Table */
1423         Drd64_Intel64db_GenerateByteTable();
1424
1425         /* Make Hash Table */
1426         Drd64_Intel64db_GenerateHashTable( fp_db );
1427         
1428         fclose(fp_db);
1429
1430         return 0x00;
1431 }
1432
1433
1434 /*-----------------------------------------------------------------------
1435 [extern] int
1436         Drd64_Intel64db_Terminate(void)
1437                 : Terminate Intel64 DataBase Use
1438 -----------------------------------------------------------------------*/
1439 int
1440         Drd64_Intel64_DB_Terminate(
1441                 void)
1442 {
1443         Drd64_Intel64db_FreeByteTable();
1444
1445         if( NULL != p_db64rec ) {
1446                 free( p_db64rec );
1447         }
1448
1449         return 0x00;
1450 }
1451
1452
1453 /* EOF of drd64_intel64_db.c ----------------------------------- */