Debian Codegraph @

contrib/m68k_instruction_tbl_gen/M68KInstructionTblGen.c

raw symbols SCIP
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdint.h>
5
6 /* This code is used to build the static lookup table used inside the M68KDisassembler.c code
7 * To run this use the Makefile in the same directory
8 */
9
10 typedef struct {
11 const char *name; /* handler function name */
12 uint16_t mask; /* mask on opcode */
13 uint16_t match; /* what to match after masking */
14 uint16_t ea_mask; /* what ea modes are allowed */
15 uint16_t mask2; /* mask the 2nd word */
16 uint16_t match2; /* what to match after masking */
17 } opcode_struct;
18
19 /* ======================================================================== */
20 /* ======================= INSTRUCTION TABLE BUILDER ====================== */
21 /* ======================================================================== */
22
23 /* EA Masks:
24 800 = data register direct
25 400 = address register direct
26 200 = address register indirect
27 100 = ARI postincrement
28 80 = ARI pre-decrement
29 40 = ARI displacement
30 20 = ARI index
31 10 = absolute short
32 8 = absolute long
33 4 = immediate / sr
34 2 = pc displacement
35 1 = pc idx
36 */
37
38 static opcode_struct g_opcode_info[] = {
39 /* opcode handler mask match ea_mask mask2 match2*/
40 {"d68000_1010" , 0xf000, 0xa000, 0x000},
41 {"d68000_1111" , 0xf000, 0xf000, 0x000},
42 {"d68000_abcd_rr" , 0xf1f8, 0xc100, 0x000},
43 {"d68000_abcd_mm" , 0xf1f8, 0xc108, 0x000},
44 {"d68000_add_er_8" , 0xf1c0, 0xd000, 0xbff},
45 {"d68000_add_er_16" , 0xf1c0, 0xd040, 0xfff},
46 {"d68000_add_er_32" , 0xf1c0, 0xd080, 0xfff},
47 {"d68000_add_re_8" , 0xf1c0, 0xd100, 0x3f8},
48 {"d68000_add_re_16" , 0xf1c0, 0xd140, 0x3f8},
49 {"d68000_add_re_32" , 0xf1c0, 0xd180, 0x3f8},
50 {"d68000_adda_16" , 0xf1c0, 0xd0c0, 0xfff},
51 {"d68000_adda_32" , 0xf1c0, 0xd1c0, 0xfff},
52 {"d68000_addi_8" , 0xffc0, 0x0600, 0xbf8},
53 {"d68000_addi_16" , 0xffc0, 0x0640, 0xbf8},
54 {"d68000_addi_32" , 0xffc0, 0x0680, 0xbf8},
55 {"d68000_addq_8" , 0xf1c0, 0x5000, 0xbf8},
56 {"d68000_addq_16" , 0xf1c0, 0x5040, 0xff8},
57 {"d68000_addq_32" , 0xf1c0, 0x5080, 0xff8},
58 {"d68000_addx_rr_8" , 0xf1f8, 0xd100, 0x000},
59 {"d68000_addx_rr_16" , 0xf1f8, 0xd140, 0x000},
60 {"d68000_addx_rr_32" , 0xf1f8, 0xd180, 0x000},
61 {"d68000_addx_mm_8" , 0xf1f8, 0xd108, 0x000},
62 {"d68000_addx_mm_16" , 0xf1f8, 0xd148, 0x000},
63 {"d68000_addx_mm_32" , 0xf1f8, 0xd188, 0x000},
64 {"d68000_and_er_8" , 0xf1c0, 0xc000, 0xbff},
65 {"d68000_and_er_16" , 0xf1c0, 0xc040, 0xbff},
66 {"d68000_and_er_32" , 0xf1c0, 0xc080, 0xbff},
67 {"d68000_and_re_8" , 0xf1c0, 0xc100, 0x3f8},
68 {"d68000_and_re_16" , 0xf1c0, 0xc140, 0x3f8},
69 {"d68000_and_re_32" , 0xf1c0, 0xc180, 0x3f8},
70 {"d68000_andi_to_ccr" , 0xffff, 0x023c, 0x000, 0xff00, 0x0000},
71 {"d68000_andi_to_sr" , 0xffff, 0x027c, 0x000},
72 {"d68000_andi_8" , 0xffc0, 0x0200, 0xbf8},
73 {"d68000_andi_16" , 0xffc0, 0x0240, 0xbf8},
74 {"d68000_andi_32" , 0xffc0, 0x0280, 0xbf8},
75 {"d68000_asr_s_8" , 0xf1f8, 0xe000, 0x000},
76 {"d68000_asr_s_16" , 0xf1f8, 0xe040, 0x000},
77 {"d68000_asr_s_32" , 0xf1f8, 0xe080, 0x000},
78 {"d68000_asr_r_8" , 0xf1f8, 0xe020, 0x000},
79 {"d68000_asr_r_16" , 0xf1f8, 0xe060, 0x000},
80 {"d68000_asr_r_32" , 0xf1f8, 0xe0a0, 0x000},
81 {"d68000_asr_ea" , 0xffc0, 0xe0c0, 0x3f8},
82 {"d68000_asl_s_8" , 0xf1f8, 0xe100, 0x000},
83 {"d68000_asl_s_16" , 0xf1f8, 0xe140, 0x000},
84 {"d68000_asl_s_32" , 0xf1f8, 0xe180, 0x000},
85 {"d68000_asl_r_8" , 0xf1f8, 0xe120, 0x000},
86 {"d68000_asl_r_16" , 0xf1f8, 0xe160, 0x000},
87 {"d68000_asl_r_32" , 0xf1f8, 0xe1a0, 0x000},
88 {"d68000_asl_ea" , 0xffc0, 0xe1c0, 0x3f8},
89 {"d68000_bcc_8" , 0xf000, 0x6000, 0x000},
90 {"d68000_bcc_16" , 0xf0ff, 0x6000, 0x000},
91 {"d68020_bcc_32" , 0xf0ff, 0x60ff, 0x000},
92 {"d68000_bchg_r" , 0xf1c0, 0x0140, 0xbf8},
93 {"d68000_bchg_s" , 0xffc0, 0x0840, 0xbf8, 0xff00, 0x0000},
94 {"d68000_bclr_r" , 0xf1c0, 0x0180, 0xbf8},
95 {"d68000_bclr_s" , 0xffc0, 0x0880, 0xbf8, 0xff00, 0x0000},
96 {"d68020_bfchg" , 0xffc0, 0xeac0, 0xa78, 0xf000, 0x0000},
97 {"d68020_bfclr" , 0xffc0, 0xecc0, 0xa78, 0xf000, 0x0000},
98 {"d68020_bfexts" , 0xffc0, 0xebc0, 0xa7b, 0x8000, 0x0000},
99 {"d68020_bfextu" , 0xffc0, 0xe9c0, 0xa7b, 0x8000, 0x0000},
100 {"d68020_bfffo" , 0xffc0, 0xedc0, 0xa7b, 0x8000, 0x0000},
101 {"d68020_bfins" , 0xffc0, 0xefc0, 0xa78, 0x8000, 0x0000},
102 {"d68020_bfset" , 0xffc0, 0xeec0, 0xa78, 0xf000, 0x0000},
103 {"d68020_bftst" , 0xffc0, 0xe8c0, 0xa7b, 0xf000, 0x0000},
104 {"d68010_bkpt" , 0xfff8, 0x4848, 0x000},
105 {"d68000_bra_8" , 0xff00, 0x6000, 0x000},
106 {"d68000_bra_16" , 0xffff, 0x6000, 0x000},
107 {"d68020_bra_32" , 0xffff, 0x60ff, 0x000},
108 {"d68000_bset_r" , 0xf1c0, 0x01c0, 0xbf8},
109 {"d68000_bset_s" , 0xffc0, 0x08c0, 0xbf8, 0xfe00, 0x0000 },
110 {"d68000_bsr_8" , 0xff00, 0x6100, 0x000},
111 {"d68000_bsr_16" , 0xffff, 0x6100, 0x000},
112 {"d68020_bsr_32" , 0xffff, 0x61ff, 0x000},
113 {"d68000_btst_r" , 0xf1c0, 0x0100, 0xbff},
114 {"d68000_btst_s" , 0xffc0, 0x0800, 0xbfb, 0xff00, 0x0000},
115 {"d68020_callm" , 0xffc0, 0x06c0, 0x27b, 0xff00, 0x0000},
116 {"d68020_cas_8" , 0xffc0, 0x0ac0, 0x3f8, 0xfe38, 0x0000},
117 {"d68020_cas_16" , 0xffc0, 0x0cc0, 0x3f8, 0xfe38, 0x0000},
118 {"d68020_cas_32" , 0xffc0, 0x0ec0, 0x3f8, 0xfe38, 0x0000},
119 {"d68020_cas2_16" , 0xffff, 0x0cfc, 0x000, 0x0e38, 0x0000/*, 0x0e38, 0x0000 */},
120 {"d68020_cas2_32" , 0xffff, 0x0efc, 0x000, 0x0e38, 0x0000/*, 0x0e38, 0x0000 */},
121 {"d68000_chk_16" , 0xf1c0, 0x4180, 0xbff},
122 {"d68020_chk_32" , 0xf1c0, 0x4100, 0xbff},
123 {"d68020_chk2_cmp2_8" , 0xffc0, 0x00c0, 0x27b, 0x07ff, 0x0000},
124 {"d68020_chk2_cmp2_16" , 0xffc0, 0x02c0, 0x27b, 0x07ff, 0x0000},
125 {"d68020_chk2_cmp2_32" , 0xffc0, 0x04c0, 0x27b, 0x07ff, 0x0000},
126 {"d68040_cinv" , 0xff20, 0xf400, 0x000},
127 {"d68000_clr_8" , 0xffc0, 0x4200, 0xbf8},
128 {"d68000_clr_16" , 0xffc0, 0x4240, 0xbf8},
129 {"d68000_clr_32" , 0xffc0, 0x4280, 0xbf8},
130 {"d68000_cmp_8" , 0xf1c0, 0xb000, 0xbff},
131 {"d68000_cmp_16" , 0xf1c0, 0xb040, 0xfff},
132 {"d68000_cmp_32" , 0xf1c0, 0xb080, 0xfff},
133 {"d68000_cmpa_16" , 0xf1c0, 0xb0c0, 0xfff},
134 {"d68000_cmpa_32" , 0xf1c0, 0xb1c0, 0xfff},
135 {"d68000_cmpi_8" , 0xffc0, 0x0c00, 0xbf8},
136 {"d68020_cmpi_pcdi_8" , 0xffff, 0x0c3a, 0x000},
137 {"d68020_cmpi_pcix_8" , 0xffff, 0x0c3b, 0x000},
138 {"d68000_cmpi_16" , 0xffc0, 0x0c40, 0xbf8},
139 {"d68020_cmpi_pcdi_16" , 0xffff, 0x0c7a, 0x000},
140 {"d68020_cmpi_pcix_16" , 0xffff, 0x0c7b, 0x000},
141 {"d68000_cmpi_32" , 0xffc0, 0x0c80, 0xbf8},
142 {"d68020_cmpi_pcdi_32" , 0xffff, 0x0cba, 0x000},
143 {"d68020_cmpi_pcix_32" , 0xffff, 0x0cbb, 0x000},
144 {"d68000_cmpm_8" , 0xf1f8, 0xb108, 0x000},
145 {"d68000_cmpm_16" , 0xf1f8, 0xb148, 0x000},
146 {"d68000_cmpm_32" , 0xf1f8, 0xb188, 0x000},
147 {"d68020_cpbcc_16" , 0xf1c0, 0xf080, 0x000},
148 {"d68020_cpbcc_32" , 0xf1c0, 0xf0c0, 0x000},
149 {"d68020_cpdbcc" , 0xf1f8, 0xf048, 0x000},
150 {"d68020_cpgen" , 0xf1c0, 0xf000, 0x000},
151 {"d68020_cprestore" , 0xf1c0, 0xf140, 0x37f},
152 {"d68020_cpsave" , 0xf1c0, 0xf100, 0x2f8},
153 {"d68020_cpscc" , 0xf1c0, 0xf040, 0xbf8},
154 {"d68020_cptrapcc_0" , 0xf1ff, 0xf07c, 0x000},
155 {"d68020_cptrapcc_16" , 0xf1ff, 0xf07a, 0x000},
156 {"d68020_cptrapcc_32" , 0xf1ff, 0xf07b, 0x000},
157 {"d68040_cpush" , 0xff20, 0xf420, 0x000},
158 {"d68000_dbcc" , 0xf0f8, 0x50c8, 0x000},
159 {"d68000_dbra" , 0xfff8, 0x51c8, 0x000},
160 {"d68000_divs" , 0xf1c0, 0x81c0, 0xbff},
161 {"d68000_divu" , 0xf1c0, 0x80c0, 0xbff},
162 {"d68020_divl" , 0xff80, 0x4c00, 0xbff, 0x83f8, 0x0000},
163 {"d68000_eor_8" , 0xf1c0, 0xb100, 0xbf8},
164 {"d68000_eor_16" , 0xf1c0, 0xb140, 0xbf8},
165 {"d68000_eor_32" , 0xf1c0, 0xb180, 0xbf8},
166 {"d68000_eori_to_ccr" , 0xffff, 0x0a3c, 0x000, 0xff00, 0x0000},
167 {"d68000_eori_to_sr" , 0xffff, 0x0a7c, 0x000},
168 {"d68000_eori_8" , 0xffc0, 0x0a00, 0xbf8},
169 {"d68000_eori_16" , 0xffc0, 0x0a40, 0xbf8},
170 {"d68000_eori_32" , 0xffc0, 0x0a80, 0xbf8},
171 {"d68000_exg_dd" , 0xf1f8, 0xc140, 0x000},
172 {"d68000_exg_aa" , 0xf1f8, 0xc148, 0x000},
173 {"d68000_exg_da" , 0xf1f8, 0xc188, 0x000},
174 {"d68020_extb_32" , 0xfff8, 0x49c0, 0x000},
175 {"d68000_ext_16" , 0xfff8, 0x4880, 0x000},
176 {"d68000_ext_32" , 0xfff8, 0x48c0, 0x000},
177 {"d68000_illegal" , 0xffff, 0x4afc, 0x000},
178 {"d68000_jmp" , 0xffc0, 0x4ec0, 0x27b},
179 {"d68000_jsr" , 0xffc0, 0x4e80, 0x27b},
180 {"d68000_lea" , 0xf1c0, 0x41c0, 0x27b},
181 {"d68000_link_16" , 0xfff8, 0x4e50, 0x000},
182 {"d68020_link_32" , 0xfff8, 0x4808, 0x000},
183 {"d68000_lsr_s_8" , 0xf1f8, 0xe008, 0x000},
184 {"d68000_lsr_s_16" , 0xf1f8, 0xe048, 0x000},
185 {"d68000_lsr_s_32" , 0xf1f8, 0xe088, 0x000},
186 {"d68000_lsr_r_8" , 0xf1f8, 0xe028, 0x000},
187 {"d68000_lsr_r_16" , 0xf1f8, 0xe068, 0x000},
188 {"d68000_lsr_r_32" , 0xf1f8, 0xe0a8, 0x000},
189 {"d68000_lsr_ea" , 0xffc0, 0xe2c0, 0x3f8},
190 {"d68000_lsl_s_8" , 0xf1f8, 0xe108, 0x000},
191 {"d68000_lsl_s_16" , 0xf1f8, 0xe148, 0x000},
192 {"d68000_lsl_s_32" , 0xf1f8, 0xe188, 0x000},
193 {"d68000_lsl_r_8" , 0xf1f8, 0xe128, 0x000},
194 {"d68000_lsl_r_16" , 0xf1f8, 0xe168, 0x000},
195 {"d68000_lsl_r_32" , 0xf1f8, 0xe1a8, 0x000},
196 {"d68000_lsl_ea" , 0xffc0, 0xe3c0, 0x3f8},
197 {"d68000_move_8" , 0xf000, 0x1000, 0xbff},
198 {"d68000_move_16" , 0xf000, 0x3000, 0xfff},
199 {"d68000_move_32" , 0xf000, 0x2000, 0xfff},
200 {"d68000_movea_16" , 0xf1c0, 0x3040, 0xfff},
201 {"d68000_movea_32" , 0xf1c0, 0x2040, 0xfff},
202 {"d68000_move_to_ccr" , 0xffc0, 0x44c0, 0xbff},
203 {"d68010_move_fr_ccr" , 0xffc0, 0x42c0, 0xbf8},
204 {"d68000_move_to_sr" , 0xffc0, 0x46c0, 0xbff},
205 {"d68000_move_fr_sr" , 0xffc0, 0x40c0, 0xbf8},
206 {"d68000_move_to_usp" , 0xfff8, 0x4e60, 0x000},
207 {"d68000_move_fr_usp" , 0xfff8, 0x4e68, 0x000},
208 {"d68010_movec" , 0xfffe, 0x4e7a, 0x000},
209 {"d68000_movem_pd_16" , 0xfff8, 0x48a0, 0x000},
210 {"d68000_movem_pd_32" , 0xfff8, 0x48e0, 0x000},
211 {"d68000_movem_re_16" , 0xffc0, 0x4880, 0x2f8},
212 {"d68000_movem_re_32" , 0xffc0, 0x48c0, 0x2f8},
213 {"d68000_movem_er_16" , 0xffc0, 0x4c80, 0x37b},
214 {"d68000_movem_er_32" , 0xffc0, 0x4cc0, 0x37b},
215 {"d68000_movep_er_16" , 0xf1f8, 0x0108, 0x000},
216 {"d68000_movep_er_32" , 0xf1f8, 0x0148, 0x000},
217 {"d68000_movep_re_16" , 0xf1f8, 0x0188, 0x000},
218 {"d68000_movep_re_32" , 0xf1f8, 0x01c8, 0x000},
219 {"d68010_moves_8" , 0xffc0, 0x0e00, 0x3f8, 0x07ff, 0x0000},
220 {"d68010_moves_16" , 0xffc0, 0x0e40, 0x3f8, 0x07ff, 0x0000},
221 {"d68010_moves_32" , 0xffc0, 0x0e80, 0x3f8, 0x07ff, 0x0000},
222 {"d68000_moveq" , 0xf100, 0x7000, 0x000},
223 {"d68040_move16_pi_pi" , 0xfff8, 0xf620, 0x000, 0x8fff, 0x8000},
224 {"d68040_move16_pi_al" , 0xfff8, 0xf600, 0x000},
225 {"d68040_move16_al_pi" , 0xfff8, 0xf608, 0x000},
226 {"d68040_move16_ai_al" , 0xfff8, 0xf610, 0x000},
227 {"d68040_move16_al_ai" , 0xfff8, 0xf618, 0x000},
228 {"d68000_muls" , 0xf1c0, 0xc1c0, 0xbff},
229 {"d68000_mulu" , 0xf1c0, 0xc0c0, 0xbff},
230 {"d68020_mull" , 0xffc0, 0x4c00, 0xbff, 0x83f8, 0x0000},
231 {"d68000_nbcd" , 0xffc0, 0x4800, 0xbf8},
232 {"d68000_neg_8" , 0xffc0, 0x4400, 0xbf8},
233 {"d68000_neg_16" , 0xffc0, 0x4440, 0xbf8},
234 {"d68000_neg_32" , 0xffc0, 0x4480, 0xbf8},
235 {"d68000_negx_8" , 0xffc0, 0x4000, 0xbf8},
236 {"d68000_negx_16" , 0xffc0, 0x4040, 0xbf8},
237 {"d68000_negx_32" , 0xffc0, 0x4080, 0xbf8},
238 {"d68000_nop" , 0xffff, 0x4e71, 0x000},
239 {"d68000_not_8" , 0xffc0, 0x4600, 0xbf8},
240 {"d68000_not_16" , 0xffc0, 0x4640, 0xbf8},
241 {"d68000_not_32" , 0xffc0, 0x4680, 0xbf8},
242 {"d68000_or_er_8" , 0xf1c0, 0x8000, 0xbff},
243 {"d68000_or_er_16" , 0xf1c0, 0x8040, 0xbff},
244 {"d68000_or_er_32" , 0xf1c0, 0x8080, 0xbff},
245 {"d68000_or_re_8" , 0xf1c0, 0x8100, 0x3f8},
246 {"d68000_or_re_16" , 0xf1c0, 0x8140, 0x3f8},
247 {"d68000_or_re_32" , 0xf1c0, 0x8180, 0x3f8},
248 {"d68000_ori_to_ccr" , 0xffff, 0x003c, 0x000, 0xff00, 0x0000},
249 {"d68000_ori_to_sr" , 0xffff, 0x007c, 0x000},
250 {"d68000_ori_8" , 0xffc0, 0x0000, 0xbf8},
251 {"d68000_ori_16" , 0xffc0, 0x0040, 0xbf8},
252 {"d68000_ori_32" , 0xffc0, 0x0080, 0xbf8},
253 {"d68020_pack_rr" , 0xf1f8, 0x8140, 0x000},
254 {"d68020_pack_mm" , 0xf1f8, 0x8148, 0x000},
255 {"d68000_pea" , 0xffc0, 0x4840, 0x27b},
256 {"d68000_reset" , 0xffff, 0x4e70, 0x000},
257 {"d68000_ror_s_8" , 0xf1f8, 0xe018, 0x000},
258 {"d68000_ror_s_16" , 0xf1f8, 0xe058, 0x000},
259 {"d68000_ror_s_32" , 0xf1f8, 0xe098, 0x000},
260 {"d68000_ror_r_8" , 0xf1f8, 0xe038, 0x000},
261 {"d68000_ror_r_16" , 0xf1f8, 0xe078, 0x000},
262 {"d68000_ror_r_32" , 0xf1f8, 0xe0b8, 0x000},
263 {"d68000_ror_ea" , 0xffc0, 0xe6c0, 0x3f8},
264 {"d68000_rol_s_8" , 0xf1f8, 0xe118, 0x000},
265 {"d68000_rol_s_16" , 0xf1f8, 0xe158, 0x000},
266 {"d68000_rol_s_32" , 0xf1f8, 0xe198, 0x000},
267 {"d68000_rol_r_8" , 0xf1f8, 0xe138, 0x000},
268 {"d68000_rol_r_16" , 0xf1f8, 0xe178, 0x000},
269 {"d68000_rol_r_32" , 0xf1f8, 0xe1b8, 0x000},
270 {"d68000_rol_ea" , 0xffc0, 0xe7c0, 0x3f8},
271 {"d68000_roxr_s_8" , 0xf1f8, 0xe010, 0x000},
272 {"d68000_roxr_s_16" , 0xf1f8, 0xe050, 0x000},
273 {"d68000_roxr_s_32" , 0xf1f8, 0xe090, 0x000},
274 {"d68000_roxr_r_8" , 0xf1f8, 0xe030, 0x000},
275 {"d68000_roxr_r_16" , 0xf1f8, 0xe070, 0x000},
276 {"d68000_roxr_r_32" , 0xf1f8, 0xe0b0, 0x000},
277 {"d68000_roxr_ea" , 0xffc0, 0xe4c0, 0x3f8},
278 {"d68000_roxl_s_8" , 0xf1f8, 0xe110, 0x000},
279 {"d68000_roxl_s_16" , 0xf1f8, 0xe150, 0x000},
280 {"d68000_roxl_s_32" , 0xf1f8, 0xe190, 0x000},
281 {"d68000_roxl_r_8" , 0xf1f8, 0xe130, 0x000},
282 {"d68000_roxl_r_16" , 0xf1f8, 0xe170, 0x000},
283 {"d68000_roxl_r_32" , 0xf1f8, 0xe1b0, 0x000},
284 {"d68000_roxl_ea" , 0xffc0, 0xe5c0, 0x3f8},
285 {"d68010_rtd" , 0xffff, 0x4e74, 0x000},
286 {"d68000_rte" , 0xffff, 0x4e73, 0x000},
287 {"d68020_rtm" , 0xfff0, 0x06c0, 0x000},
288 {"d68000_rtr" , 0xffff, 0x4e77, 0x000},
289 {"d68000_rts" , 0xffff, 0x4e75, 0x000},
290 {"d68000_sbcd_rr" , 0xf1f8, 0x8100, 0x000},
291 {"d68000_sbcd_mm" , 0xf1f8, 0x8108, 0x000},
292 {"d68000_scc" , 0xf0c0, 0x50c0, 0xbf8},
293 {"d68000_stop" , 0xffff, 0x4e72, 0x000},
294 {"d68000_sub_er_8" , 0xf1c0, 0x9000, 0xbff},
295 {"d68000_sub_er_16" , 0xf1c0, 0x9040, 0xfff},
296 {"d68000_sub_er_32" , 0xf1c0, 0x9080, 0xfff},
297 {"d68000_sub_re_8" , 0xf1c0, 0x9100, 0x3f8},
298 {"d68000_sub_re_16" , 0xf1c0, 0x9140, 0x3f8},
299 {"d68000_sub_re_32" , 0xf1c0, 0x9180, 0x3f8},
300 {"d68000_suba_16" , 0xf1c0, 0x90c0, 0xfff},
301 {"d68000_suba_32" , 0xf1c0, 0x91c0, 0xfff},
302 {"d68000_subi_8" , 0xffc0, 0x0400, 0xbf8},
303 {"d68000_subi_16" , 0xffc0, 0x0440, 0xbf8},
304 {"d68000_subi_32" , 0xffc0, 0x0480, 0xbf8},
305 {"d68000_subq_8" , 0xf1c0, 0x5100, 0xbf8},
306 {"d68000_subq_16" , 0xf1c0, 0x5140, 0xff8},
307 {"d68000_subq_32" , 0xf1c0, 0x5180, 0xff8},
308 {"d68000_subx_rr_8" , 0xf1f8, 0x9100, 0x000},
309 {"d68000_subx_rr_16" , 0xf1f8, 0x9140, 0x000},
310 {"d68000_subx_rr_32" , 0xf1f8, 0x9180, 0x000},
311 {"d68000_subx_mm_8" , 0xf1f8, 0x9108, 0x000},
312 {"d68000_subx_mm_16" , 0xf1f8, 0x9148, 0x000},
313 {"d68000_subx_mm_32" , 0xf1f8, 0x9188, 0x000},
314 {"d68000_swap" , 0xfff8, 0x4840, 0x000},
315 {"d68000_tas" , 0xffc0, 0x4ac0, 0xbf8},
316 {"d68000_trap" , 0xfff0, 0x4e40, 0x000},
317 {"d68020_trapcc_0" , 0xf0ff, 0x50fc, 0x000},
318 {"d68020_trapcc_16" , 0xf0ff, 0x50fa, 0x000},
319 {"d68020_trapcc_32" , 0xf0ff, 0x50fb, 0x000},
320 {"d68000_trapv" , 0xffff, 0x4e76, 0x000},
321 {"d68000_tst_8" , 0xffc0, 0x4a00, 0xbf8},
322 {"d68020_tst_pcdi_8" , 0xffff, 0x4a3a, 0x000},
323 {"d68020_tst_pcix_8" , 0xffff, 0x4a3b, 0x000},
324 {"d68020_tst_i_8" , 0xffff, 0x4a3c, 0x000},
325 {"d68000_tst_16" , 0xffc0, 0x4a40, 0xbf8},
326 {"d68020_tst_a_16" , 0xfff8, 0x4a48, 0x000},
327 {"d68020_tst_pcdi_16" , 0xffff, 0x4a7a, 0x000},
328 {"d68020_tst_pcix_16" , 0xffff, 0x4a7b, 0x000},
329 {"d68020_tst_i_16" , 0xffff, 0x4a7c, 0x000},
330 {"d68000_tst_32" , 0xffc0, 0x4a80, 0xbf8},
331 {"d68020_tst_a_32" , 0xfff8, 0x4a88, 0x000},
332 {"d68020_tst_pcdi_32" , 0xffff, 0x4aba, 0x000},
333 {"d68020_tst_pcix_32" , 0xffff, 0x4abb, 0x000},
334 {"d68020_tst_i_32" , 0xffff, 0x4abc, 0x000},
335 {"d68000_unlk" , 0xfff8, 0x4e58, 0x000},
336 {"d68020_unpk_rr" , 0xf1f8, 0x8180, 0x000},
337 {"d68020_unpk_mm" , 0xf1f8, 0x8188, 0x000},
338 {0, 0, 0, 0}
339 };
340
341 /* Check if opcode is using a valid ea mode */
342 static int valid_ea(unsigned int opcode, unsigned int mask)
343 {
344 if (mask == 0)
345 return 1;
346
347 switch(opcode & 0x3f) {
348 case 0x00: case 0x01: case 0x02: case 0x03:
349 case 0x04: case 0x05: case 0x06: case 0x07:
350 return (mask & 0x800) != 0;
351 case 0x08: case 0x09: case 0x0a: case 0x0b:
352 case 0x0c: case 0x0d: case 0x0e: case 0x0f:
353 return (mask & 0x400) != 0;
354 case 0x10: case 0x11: case 0x12: case 0x13:
355 case 0x14: case 0x15: case 0x16: case 0x17:
356 return (mask & 0x200) != 0;
357 case 0x18: case 0x19: case 0x1a: case 0x1b:
358 case 0x1c: case 0x1d: case 0x1e: case 0x1f:
359 return (mask & 0x100) != 0;
360 case 0x20: case 0x21: case 0x22: case 0x23:
361 case 0x24: case 0x25: case 0x26: case 0x27:
362 return (mask & 0x080) != 0;
363 case 0x28: case 0x29: case 0x2a: case 0x2b:
364 case 0x2c: case 0x2d: case 0x2e: case 0x2f:
365 return (mask & 0x040) != 0;
366 case 0x30: case 0x31: case 0x32: case 0x33:
367 case 0x34: case 0x35: case 0x36: case 0x37:
368 return (mask & 0x020) != 0;
369 case 0x38:
370 return (mask & 0x010) != 0;
371 case 0x39:
372 return (mask & 0x008) != 0;
373 case 0x3a:
374 return (mask & 0x002) != 0;
375 case 0x3b:
376 return (mask & 0x001) != 0;
377 case 0x3c:
378 return (mask & 0x004) != 0;
379 }
380 return 0;
381
382 }
383
384 #ifndef DECL_SPEC
385 #ifdef _MSC_VER
386 #define DECL_SPEC __cdecl
387 #else
388 #define DECL_SPEC
389 #endif // _MSC_VER
390 #endif // DECL_SPEC
391
392 /* Used by qsort */
393 static int DECL_SPEC compare_nof_true_bits(const void *aptr, const void *bptr)
394 {
395 unsigned int a = ((const opcode_struct*)aptr)->mask;
396 unsigned int b = ((const opcode_struct*)bptr)->mask;
397
398 a = ((a & 0xAAAA) >> 1) + (a & 0x5555);
399 a = ((a & 0xCCCC) >> 2) + (a & 0x3333);
400 a = ((a & 0xF0F0) >> 4) + (a & 0x0F0F);
401 a = ((a & 0xFF00) >> 8) + (a & 0x00FF);
402
403 b = ((b & 0xAAAA) >> 1) + (b & 0x5555);
404 b = ((b & 0xCCCC) >> 2) + (b & 0x3333);
405 b = ((b & 0xF0F0) >> 4) + (b & 0x0F0F);
406 b = ((b & 0xFF00) >> 8) + (b & 0x00FF);
407
408 return b - a; /* reversed to get greatest to least sorting */
409 }
410
411 /* build the opcode handler jump table */
412 static void build_opcode_table(void)
413 {
414 unsigned int i;
415 unsigned int opcode;
416 opcode_struct* ostruct;
417 unsigned int opcode_info_length = 0;
418 const unsigned int total_count = 0x10000;
419
420 for(ostruct = g_opcode_info;ostruct->name != 0;ostruct++)
421 opcode_info_length++;
422
423 qsort((void *)g_opcode_info, opcode_info_length, sizeof(g_opcode_info[0]), compare_nof_true_bits);
424
425 printf("/* This table is auto-generated. DO NOT MANUALLY EDIT! Look in M68KInstructionTblGen.c for more info */\n");
426 printf("static const instruction_struct g_instruction_table[] = {\n");
427
428 for(i=0;i<0x10000;i++) {
429 const char *name = "d68000_invalid";
430 uint16_t word2_mask = 0;
431 uint16_t word2_match = 0;
432 opcode = i;
433 /* search through opcode info for a match */
434 for(ostruct = g_opcode_info;ostruct->name != 0;ostruct++) {
435 /* match opcode mask and allowed ea modes */
436 if ((opcode & ostruct->mask) == ostruct->match) {
437 /* Handle destination ea for move instructions */
438 if ((!strcmp(ostruct->name, "d68000_move_8") ||
439 !strcmp(ostruct->name, "d68000_move_16") ||
440 !strcmp(ostruct->name, "d68000_move_32")) &&
441 !valid_ea(((opcode>>9)&7) | ((opcode>>3)&0x38), 0xbf8))
442 continue;
443 if (valid_ea(opcode, ostruct->ea_mask)) {
444 name = ostruct->name;
445 word2_mask = ostruct->mask2;
446 word2_match = ostruct->match2;
447 break;
448 }
449 }
450 }
451
452 // Handle so the last entry won't have a , at the end
453 if (i != total_count - 1) {
454 printf("\t{ %s, 0x%x, 0x%x },\n", name, word2_mask, word2_match);
455 } else {
456 printf("\t{ %s, 0x%x, 0x%x }\n", name, word2_mask, word2_match);
457 }
458 }
459
460 printf("};\n\n");
461 }
462
463 int main() {
464 build_opcode_table();
465 return 0;
466 }
467
468