1 |
cebix |
1.1 |
/* |
2 |
|
|
* UAE - The Un*x Amiga Emulator |
3 |
|
|
* |
4 |
|
|
* MC68000 emulation generator |
5 |
|
|
* |
6 |
|
|
* This is a fairly stupid program that generates a lot of case labels that |
7 |
|
|
* can be #included in a switch statement. |
8 |
|
|
* As an alternative, it can generate functions that handle specific |
9 |
|
|
* MC68000 instructions, plus a prototype header file and a function pointer |
10 |
|
|
* array to look up the function for an opcode. |
11 |
|
|
* Error checking is bad, an illegal table68k file will cause the program to |
12 |
|
|
* call abort(). |
13 |
|
|
* The generated code is sometimes sub-optimal, an optimizing compiler should |
14 |
|
|
* take care of this. |
15 |
|
|
* |
16 |
|
|
* Copyright 1995, 1996 Bernd Schmidt |
17 |
|
|
*/ |
18 |
|
|
|
19 |
|
|
#include <ctype.h> |
20 |
|
|
#include <stdio.h> |
21 |
|
|
#include <stdlib.h> |
22 |
|
|
#include <string.h> |
23 |
|
|
|
24 |
|
|
#include "sysdeps.h" |
25 |
|
|
#include "readcpu.h" |
26 |
|
|
|
27 |
|
|
#define BOOL_TYPE "int" |
28 |
|
|
|
29 |
|
|
static FILE *headerfile; |
30 |
|
|
static FILE *stblfile; |
31 |
|
|
|
32 |
|
|
static int using_prefetch; |
33 |
|
|
static int using_exception_3; |
34 |
|
|
static int cpu_level; |
35 |
|
|
|
36 |
|
|
/* For the current opcode, the next lower level that will have different code. |
37 |
|
|
* Initialized to -1 for each opcode. If it remains unchanged, indicates we |
38 |
|
|
* are done with that opcode. */ |
39 |
|
|
static int next_cpu_level; |
40 |
|
|
|
41 |
|
|
static int *opcode_map; |
42 |
|
|
static int *opcode_next_clev; |
43 |
|
|
static int *opcode_last_postfix; |
44 |
|
|
static unsigned long *counts; |
45 |
|
|
|
46 |
|
|
static void read_counts (void) |
47 |
|
|
{ |
48 |
|
|
FILE *file; |
49 |
|
|
unsigned long opcode, count, total; |
50 |
|
|
char name[20]; |
51 |
|
|
int nr = 0; |
52 |
|
|
memset (counts, 0, 65536 * sizeof *counts); |
53 |
|
|
|
54 |
|
|
file = fopen ("frequent.68k", "r"); |
55 |
|
|
if (file) { |
56 |
|
|
fscanf (file, "Total: %lu\n", &total); |
57 |
|
|
while (fscanf (file, "%lx: %lu %s\n", &opcode, &count, name) == 3) { |
58 |
|
|
opcode_next_clev[nr] = 3; |
59 |
|
|
opcode_last_postfix[nr] = -1; |
60 |
|
|
opcode_map[nr++] = opcode; |
61 |
|
|
counts[opcode] = count; |
62 |
|
|
} |
63 |
|
|
fclose (file); |
64 |
|
|
} |
65 |
|
|
if (nr == nr_cpuop_funcs) |
66 |
|
|
return; |
67 |
|
|
for (opcode = 0; opcode < 0x10000; opcode++) { |
68 |
|
|
if (table68k[opcode].handler == -1 && table68k[opcode].mnemo != i_ILLG |
69 |
|
|
&& counts[opcode] == 0) |
70 |
|
|
{ |
71 |
|
|
opcode_next_clev[nr] = 3; |
72 |
|
|
opcode_last_postfix[nr] = -1; |
73 |
|
|
opcode_map[nr++] = opcode; |
74 |
|
|
counts[opcode] = count; |
75 |
|
|
} |
76 |
|
|
} |
77 |
|
|
if (nr != nr_cpuop_funcs) |
78 |
|
|
abort (); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
static char endlabelstr[80]; |
82 |
|
|
static int endlabelno = 0; |
83 |
|
|
static int need_endlabel; |
84 |
|
|
|
85 |
|
|
static int n_braces = 0; |
86 |
|
|
static int m68k_pc_offset = 0; |
87 |
|
|
static int insn_n_cycles; |
88 |
|
|
|
89 |
|
|
static void start_brace (void) |
90 |
|
|
{ |
91 |
|
|
n_braces++; |
92 |
|
|
printf ("{"); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
static void close_brace (void) |
96 |
|
|
{ |
97 |
|
|
assert (n_braces > 0); |
98 |
|
|
n_braces--; |
99 |
|
|
printf ("}"); |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
static void finish_braces (void) |
103 |
|
|
{ |
104 |
|
|
while (n_braces > 0) |
105 |
|
|
close_brace (); |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
static void pop_braces (int to) |
109 |
|
|
{ |
110 |
|
|
while (n_braces > to) |
111 |
|
|
close_brace (); |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
static int bit_size (int size) |
115 |
|
|
{ |
116 |
|
|
switch (size) { |
117 |
|
|
case sz_byte: return 8; |
118 |
|
|
case sz_word: return 16; |
119 |
|
|
case sz_long: return 32; |
120 |
|
|
default: abort (); |
121 |
|
|
} |
122 |
|
|
return 0; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
static const char *bit_mask (int size) |
126 |
|
|
{ |
127 |
|
|
switch (size) { |
128 |
|
|
case sz_byte: return "0xff"; |
129 |
|
|
case sz_word: return "0xffff"; |
130 |
|
|
case sz_long: return "0xffffffff"; |
131 |
|
|
default: abort (); |
132 |
|
|
} |
133 |
|
|
return 0; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
static const char *gen_nextilong (void) |
137 |
|
|
{ |
138 |
|
|
static char buffer[80]; |
139 |
|
|
int r = m68k_pc_offset; |
140 |
|
|
m68k_pc_offset += 4; |
141 |
|
|
|
142 |
|
|
insn_n_cycles += 4; |
143 |
|
|
|
144 |
|
|
if (using_prefetch) |
145 |
|
|
sprintf (buffer, "get_ilong_prefetch(%d)", r); |
146 |
|
|
else |
147 |
|
|
sprintf (buffer, "get_ilong(%d)", r); |
148 |
|
|
return buffer; |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
static const char *gen_nextiword (void) |
152 |
|
|
{ |
153 |
|
|
static char buffer[80]; |
154 |
|
|
int r = m68k_pc_offset; |
155 |
|
|
m68k_pc_offset += 2; |
156 |
|
|
|
157 |
|
|
insn_n_cycles += 2; |
158 |
|
|
|
159 |
|
|
if (using_prefetch) |
160 |
|
|
sprintf (buffer, "get_iword_prefetch(%d)", r); |
161 |
|
|
else |
162 |
|
|
sprintf (buffer, "get_iword(%d)", r); |
163 |
|
|
return buffer; |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
static const char *gen_nextibyte (void) |
167 |
|
|
{ |
168 |
|
|
static char buffer[80]; |
169 |
|
|
int r = m68k_pc_offset; |
170 |
|
|
m68k_pc_offset += 2; |
171 |
|
|
|
172 |
|
|
insn_n_cycles += 2; |
173 |
|
|
|
174 |
|
|
if (using_prefetch) |
175 |
|
|
sprintf (buffer, "get_ibyte_prefetch(%d)", r); |
176 |
|
|
else |
177 |
|
|
sprintf (buffer, "get_ibyte(%d)", r); |
178 |
|
|
return buffer; |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
static void fill_prefetch_0 (void) |
182 |
|
|
{ |
183 |
|
|
if (using_prefetch) |
184 |
|
|
printf ("fill_prefetch_0 ();\n"); |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
static void fill_prefetch_2 (void) |
188 |
|
|
{ |
189 |
|
|
if (using_prefetch) |
190 |
|
|
printf ("fill_prefetch_2 ();\n"); |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
static void swap_opcode (void) |
194 |
|
|
{ |
195 |
|
|
printf ("#ifdef HAVE_GET_WORD_UNSWAPPED\n"); |
196 |
|
|
printf ("\topcode = ((opcode << 8) & 0xFF00) | ((opcode >> 8) & 0xFF);\n"); |
197 |
|
|
printf ("#endif\n"); |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
static void sync_m68k_pc (void) |
201 |
|
|
{ |
202 |
|
|
if (m68k_pc_offset == 0) |
203 |
|
|
return; |
204 |
|
|
printf ("m68k_incpc(%d);\n", m68k_pc_offset); |
205 |
|
|
switch (m68k_pc_offset) { |
206 |
|
|
case 0: |
207 |
|
|
/*fprintf (stderr, "refilling prefetch at 0\n"); */ |
208 |
|
|
break; |
209 |
|
|
case 2: |
210 |
|
|
fill_prefetch_2 (); |
211 |
|
|
break; |
212 |
|
|
default: |
213 |
|
|
fill_prefetch_0 (); |
214 |
|
|
break; |
215 |
|
|
} |
216 |
|
|
m68k_pc_offset = 0; |
217 |
|
|
} |
218 |
|
|
|
219 |
|
|
/* getv == 1: fetch data; getv != 0: check for odd address. If movem != 0, |
220 |
|
|
* the calling routine handles Apdi and Aipi modes. */ |
221 |
|
|
static void genamode (amodes mode, char *reg, wordsizes size, char *name, int getv, int movem) |
222 |
|
|
{ |
223 |
|
|
start_brace (); |
224 |
|
|
switch (mode) { |
225 |
|
|
case Dreg: |
226 |
|
|
if (movem) |
227 |
|
|
abort (); |
228 |
|
|
if (getv == 1) |
229 |
|
|
switch (size) { |
230 |
|
|
case sz_byte: |
231 |
|
|
#ifdef AMIGA |
232 |
|
|
/* sam: I don't know why gcc.2.7.2.1 produces a code worse */ |
233 |
|
|
/* if it is not done like that: */ |
234 |
|
|
printf ("\tuae_s8 %s = ((uae_u8*)&m68k_dreg(regs, %s))[3];\n", name, reg); |
235 |
|
|
#else |
236 |
|
|
printf ("\tuae_s8 %s = m68k_dreg(regs, %s);\n", name, reg); |
237 |
|
|
#endif |
238 |
|
|
break; |
239 |
|
|
case sz_word: |
240 |
|
|
#ifdef AMIGA |
241 |
|
|
printf ("\tuae_s16 %s = ((uae_s16*)&m68k_dreg(regs, %s))[1];\n", name, reg); |
242 |
|
|
#else |
243 |
|
|
printf ("\tuae_s16 %s = m68k_dreg(regs, %s);\n", name, reg); |
244 |
|
|
#endif |
245 |
|
|
break; |
246 |
|
|
case sz_long: |
247 |
|
|
printf ("\tuae_s32 %s = m68k_dreg(regs, %s);\n", name, reg); |
248 |
|
|
break; |
249 |
|
|
default: |
250 |
|
|
abort (); |
251 |
|
|
} |
252 |
|
|
return; |
253 |
|
|
case Areg: |
254 |
|
|
if (movem) |
255 |
|
|
abort (); |
256 |
|
|
if (getv == 1) |
257 |
|
|
switch (size) { |
258 |
|
|
case sz_word: |
259 |
|
|
printf ("\tuae_s16 %s = m68k_areg(regs, %s);\n", name, reg); |
260 |
|
|
break; |
261 |
|
|
case sz_long: |
262 |
|
|
printf ("\tuae_s32 %s = m68k_areg(regs, %s);\n", name, reg); |
263 |
|
|
break; |
264 |
|
|
default: |
265 |
|
|
abort (); |
266 |
|
|
} |
267 |
|
|
return; |
268 |
|
|
case Aind: |
269 |
|
|
printf ("\tuaecptr %sa = m68k_areg(regs, %s);\n", name, reg); |
270 |
|
|
break; |
271 |
|
|
case Aipi: |
272 |
|
|
printf ("\tuaecptr %sa = m68k_areg(regs, %s);\n", name, reg); |
273 |
|
|
break; |
274 |
|
|
case Apdi: |
275 |
|
|
switch (size) { |
276 |
|
|
case sz_byte: |
277 |
|
|
if (movem) |
278 |
|
|
printf ("\tuaecptr %sa = m68k_areg(regs, %s);\n", name, reg); |
279 |
|
|
else |
280 |
|
|
printf ("\tuaecptr %sa = m68k_areg(regs, %s) - areg_byteinc[%s];\n", name, reg, reg); |
281 |
|
|
break; |
282 |
|
|
case sz_word: |
283 |
|
|
printf ("\tuaecptr %sa = m68k_areg(regs, %s) - %d;\n", name, reg, movem ? 0 : 2); |
284 |
|
|
break; |
285 |
|
|
case sz_long: |
286 |
|
|
printf ("\tuaecptr %sa = m68k_areg(regs, %s) - %d;\n", name, reg, movem ? 0 : 4); |
287 |
|
|
break; |
288 |
|
|
default: |
289 |
|
|
abort (); |
290 |
|
|
} |
291 |
|
|
break; |
292 |
|
|
case Ad16: |
293 |
|
|
printf ("\tuaecptr %sa = m68k_areg(regs, %s) + (uae_s32)(uae_s16)%s;\n", name, reg, gen_nextiword ()); |
294 |
|
|
break; |
295 |
|
|
case Ad8r: |
296 |
|
|
if (cpu_level > 1) { |
297 |
|
|
if (next_cpu_level < 1) |
298 |
|
|
next_cpu_level = 1; |
299 |
|
|
sync_m68k_pc (); |
300 |
|
|
start_brace (); |
301 |
|
|
printf ("\tuaecptr %sa = get_disp_ea_020(m68k_areg(regs, %s), next_iword());\n", name, reg); |
302 |
|
|
} else |
303 |
|
|
printf ("\tuaecptr %sa = get_disp_ea_000(m68k_areg(regs, %s), %s);\n", name, reg, gen_nextiword ()); |
304 |
|
|
|
305 |
|
|
break; |
306 |
|
|
case PC16: |
307 |
|
|
printf ("\tuaecptr %sa = m68k_getpc () + %d;\n", name, m68k_pc_offset); |
308 |
|
|
printf ("\t%sa += (uae_s32)(uae_s16)%s;\n", name, gen_nextiword ()); |
309 |
|
|
break; |
310 |
|
|
case PC8r: |
311 |
|
|
if (cpu_level > 1) { |
312 |
|
|
if (next_cpu_level < 1) |
313 |
|
|
next_cpu_level = 1; |
314 |
|
|
sync_m68k_pc (); |
315 |
|
|
start_brace (); |
316 |
|
|
printf ("\tuaecptr tmppc = m68k_getpc();\n"); |
317 |
|
|
printf ("\tuaecptr %sa = get_disp_ea_020(tmppc, next_iword());\n", name); |
318 |
|
|
} else { |
319 |
|
|
printf ("\tuaecptr tmppc = m68k_getpc() + %d;\n", m68k_pc_offset); |
320 |
|
|
printf ("\tuaecptr %sa = get_disp_ea_000(tmppc, %s);\n", name, gen_nextiword ()); |
321 |
|
|
} |
322 |
|
|
|
323 |
|
|
break; |
324 |
|
|
case absw: |
325 |
|
|
printf ("\tuaecptr %sa = (uae_s32)(uae_s16)%s;\n", name, gen_nextiword ()); |
326 |
|
|
break; |
327 |
|
|
case absl: |
328 |
|
|
printf ("\tuaecptr %sa = %s;\n", name, gen_nextilong ()); |
329 |
|
|
break; |
330 |
|
|
case imm: |
331 |
|
|
if (getv != 1) |
332 |
|
|
abort (); |
333 |
|
|
switch (size) { |
334 |
|
|
case sz_byte: |
335 |
|
|
printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte ()); |
336 |
|
|
break; |
337 |
|
|
case sz_word: |
338 |
|
|
printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword ()); |
339 |
|
|
break; |
340 |
|
|
case sz_long: |
341 |
|
|
printf ("\tuae_s32 %s = %s;\n", name, gen_nextilong ()); |
342 |
|
|
break; |
343 |
|
|
default: |
344 |
|
|
abort (); |
345 |
|
|
} |
346 |
|
|
return; |
347 |
|
|
case imm0: |
348 |
|
|
if (getv != 1) |
349 |
|
|
abort (); |
350 |
|
|
printf ("\tuae_s8 %s = %s;\n", name, gen_nextibyte ()); |
351 |
|
|
return; |
352 |
|
|
case imm1: |
353 |
|
|
if (getv != 1) |
354 |
|
|
abort (); |
355 |
|
|
printf ("\tuae_s16 %s = %s;\n", name, gen_nextiword ()); |
356 |
|
|
return; |
357 |
|
|
case imm2: |
358 |
|
|
if (getv != 1) |
359 |
|
|
abort (); |
360 |
|
|
printf ("\tuae_s32 %s = %s;\n", name, gen_nextilong ()); |
361 |
|
|
return; |
362 |
|
|
case immi: |
363 |
|
|
if (getv != 1) |
364 |
|
|
abort (); |
365 |
|
|
printf ("\tuae_u32 %s = %s;\n", name, reg); |
366 |
|
|
return; |
367 |
|
|
default: |
368 |
|
|
abort (); |
369 |
|
|
} |
370 |
|
|
|
371 |
|
|
/* We get here for all non-reg non-immediate addressing modes to |
372 |
|
|
* actually fetch the value. */ |
373 |
|
|
|
374 |
|
|
if (using_exception_3 && getv != 0 && size != sz_byte) { |
375 |
|
|
printf ("\tif ((%sa & 1) != 0) {\n", name); |
376 |
|
|
printf ("\t\tlast_fault_for_exception_3 = %sa;\n", name); |
377 |
|
|
printf ("\t\tlast_op_for_exception_3 = opcode;\n"); |
378 |
|
|
printf ("\t\tlast_addr_for_exception_3 = m68k_getpc() + %d;\n", m68k_pc_offset); |
379 |
|
|
printf ("\t\tException(3, 0);\n"); |
380 |
|
|
printf ("\t\tgoto %s;\n", endlabelstr); |
381 |
|
|
printf ("\t}\n"); |
382 |
|
|
need_endlabel = 1; |
383 |
|
|
start_brace (); |
384 |
|
|
} |
385 |
|
|
|
386 |
|
|
if (getv == 1) { |
387 |
|
|
switch (size) { |
388 |
|
|
case sz_byte: insn_n_cycles += 2; break; |
389 |
|
|
case sz_word: insn_n_cycles += 2; break; |
390 |
|
|
case sz_long: insn_n_cycles += 4; break; |
391 |
|
|
default: abort (); |
392 |
|
|
} |
393 |
|
|
start_brace (); |
394 |
|
|
switch (size) { |
395 |
|
|
case sz_byte: printf ("\tuae_s8 %s = get_byte(%sa);\n", name, name); break; |
396 |
|
|
case sz_word: printf ("\tuae_s16 %s = get_word(%sa);\n", name, name); break; |
397 |
|
|
case sz_long: printf ("\tuae_s32 %s = get_long(%sa);\n", name, name); break; |
398 |
|
|
default: abort (); |
399 |
|
|
} |
400 |
|
|
} |
401 |
|
|
|
402 |
|
|
/* We now might have to fix up the register for pre-dec or post-inc |
403 |
|
|
* addressing modes. */ |
404 |
|
|
if (!movem) |
405 |
|
|
switch (mode) { |
406 |
|
|
case Aipi: |
407 |
|
|
switch (size) { |
408 |
|
|
case sz_byte: |
409 |
|
|
printf ("\tm68k_areg(regs, %s) += areg_byteinc[%s];\n", reg, reg); |
410 |
|
|
break; |
411 |
|
|
case sz_word: |
412 |
|
|
printf ("\tm68k_areg(regs, %s) += 2;\n", reg); |
413 |
|
|
break; |
414 |
|
|
case sz_long: |
415 |
|
|
printf ("\tm68k_areg(regs, %s) += 4;\n", reg); |
416 |
|
|
break; |
417 |
|
|
default: |
418 |
|
|
abort (); |
419 |
|
|
} |
420 |
|
|
break; |
421 |
|
|
case Apdi: |
422 |
|
|
printf ("\tm68k_areg (regs, %s) = %sa;\n", reg, name); |
423 |
|
|
break; |
424 |
|
|
default: |
425 |
|
|
break; |
426 |
|
|
} |
427 |
|
|
} |
428 |
|
|
|
429 |
|
|
static void genastore (char *from, amodes mode, char *reg, wordsizes size, char *to) |
430 |
|
|
{ |
431 |
|
|
switch (mode) { |
432 |
|
|
case Dreg: |
433 |
|
|
switch (size) { |
434 |
|
|
case sz_byte: |
435 |
|
|
printf ("\tm68k_dreg(regs, %s) = (m68k_dreg(regs, %s) & ~0xff) | ((%s) & 0xff);\n", reg, reg, from); |
436 |
|
|
break; |
437 |
|
|
case sz_word: |
438 |
|
|
printf ("\tm68k_dreg(regs, %s) = (m68k_dreg(regs, %s) & ~0xffff) | ((%s) & 0xffff);\n", reg, reg, from); |
439 |
|
|
break; |
440 |
|
|
case sz_long: |
441 |
|
|
printf ("\tm68k_dreg(regs, %s) = (%s);\n", reg, from); |
442 |
|
|
break; |
443 |
|
|
default: |
444 |
|
|
abort (); |
445 |
|
|
} |
446 |
|
|
break; |
447 |
|
|
case Areg: |
448 |
|
|
switch (size) { |
449 |
|
|
case sz_word: |
450 |
|
|
fprintf (stderr, "Foo\n"); |
451 |
|
|
printf ("\tm68k_areg(regs, %s) = (uae_s32)(uae_s16)(%s);\n", reg, from); |
452 |
|
|
break; |
453 |
|
|
case sz_long: |
454 |
|
|
printf ("\tm68k_areg(regs, %s) = (%s);\n", reg, from); |
455 |
|
|
break; |
456 |
|
|
default: |
457 |
|
|
abort (); |
458 |
|
|
} |
459 |
|
|
break; |
460 |
|
|
case Aind: |
461 |
|
|
case Aipi: |
462 |
|
|
case Apdi: |
463 |
|
|
case Ad16: |
464 |
|
|
case Ad8r: |
465 |
|
|
case absw: |
466 |
|
|
case absl: |
467 |
|
|
case PC16: |
468 |
|
|
case PC8r: |
469 |
|
|
if (using_prefetch) |
470 |
|
|
sync_m68k_pc (); |
471 |
|
|
switch (size) { |
472 |
|
|
case sz_byte: |
473 |
|
|
insn_n_cycles += 2; |
474 |
|
|
printf ("\tput_byte(%sa,%s);\n", to, from); |
475 |
|
|
break; |
476 |
|
|
case sz_word: |
477 |
|
|
insn_n_cycles += 2; |
478 |
|
|
if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) |
479 |
|
|
abort (); |
480 |
|
|
printf ("\tput_word(%sa,%s);\n", to, from); |
481 |
|
|
break; |
482 |
|
|
case sz_long: |
483 |
|
|
insn_n_cycles += 4; |
484 |
|
|
if (cpu_level < 2 && (mode == PC16 || mode == PC8r)) |
485 |
|
|
abort (); |
486 |
|
|
printf ("\tput_long(%sa,%s);\n", to, from); |
487 |
|
|
break; |
488 |
|
|
default: |
489 |
|
|
abort (); |
490 |
|
|
} |
491 |
|
|
break; |
492 |
|
|
case imm: |
493 |
|
|
case imm0: |
494 |
|
|
case imm1: |
495 |
|
|
case imm2: |
496 |
|
|
case immi: |
497 |
|
|
abort (); |
498 |
|
|
break; |
499 |
|
|
default: |
500 |
|
|
abort (); |
501 |
|
|
} |
502 |
|
|
} |
503 |
|
|
|
504 |
|
|
static void genmovemel (uae_u16 opcode) |
505 |
|
|
{ |
506 |
|
|
char getcode[100]; |
507 |
|
|
int size = table68k[opcode].size == sz_long ? 4 : 2; |
508 |
|
|
|
509 |
|
|
if (table68k[opcode].size == sz_long) { |
510 |
|
|
strcpy (getcode, "get_long(srca)"); |
511 |
|
|
} else { |
512 |
|
|
strcpy (getcode, "(uae_s32)(uae_s16)get_word(srca)"); |
513 |
|
|
} |
514 |
|
|
|
515 |
|
|
printf ("\tuae_u16 mask = %s;\n", gen_nextiword ()); |
516 |
|
|
printf ("\tunsigned int dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); |
517 |
|
|
genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1); |
518 |
|
|
start_brace (); |
519 |
|
|
printf ("\twhile (dmask) { m68k_dreg(regs, movem_index1[dmask]) = %s; srca += %d; dmask = movem_next[dmask]; }\n", |
520 |
|
|
getcode, size); |
521 |
|
|
printf ("\twhile (amask) { m68k_areg(regs, movem_index1[amask]) = %s; srca += %d; amask = movem_next[amask]; }\n", |
522 |
|
|
getcode, size); |
523 |
|
|
|
524 |
|
|
if (table68k[opcode].dmode == Aipi) |
525 |
|
|
printf ("\tm68k_areg(regs, dstreg) = srca;\n"); |
526 |
|
|
} |
527 |
|
|
|
528 |
|
|
static void genmovemle (uae_u16 opcode) |
529 |
|
|
{ |
530 |
|
|
char putcode[100]; |
531 |
|
|
int size = table68k[opcode].size == sz_long ? 4 : 2; |
532 |
|
|
if (table68k[opcode].size == sz_long) { |
533 |
|
|
strcpy (putcode, "put_long(srca,"); |
534 |
|
|
} else { |
535 |
|
|
strcpy (putcode, "put_word(srca,"); |
536 |
|
|
} |
537 |
|
|
|
538 |
|
|
printf ("\tuae_u16 mask = %s;\n", gen_nextiword ()); |
539 |
|
|
genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1); |
540 |
|
|
if (using_prefetch) |
541 |
|
|
sync_m68k_pc (); |
542 |
|
|
|
543 |
|
|
start_brace (); |
544 |
|
|
if (table68k[opcode].dmode == Apdi) { |
545 |
|
|
printf ("\tuae_u16 amask = mask & 0xff, dmask = (mask >> 8) & 0xff;\n"); |
546 |
|
|
printf ("\twhile (amask) { srca -= %d; %s m68k_areg(regs, movem_index2[amask])); amask = movem_next[amask]; }\n", |
547 |
|
|
size, putcode); |
548 |
|
|
printf ("\twhile (dmask) { srca -= %d; %s m68k_dreg(regs, movem_index2[dmask])); dmask = movem_next[dmask]; }\n", |
549 |
|
|
size, putcode); |
550 |
|
|
printf ("\tm68k_areg(regs, dstreg) = srca;\n"); |
551 |
|
|
} else { |
552 |
|
|
printf ("\tuae_u16 dmask = mask & 0xff, amask = (mask >> 8) & 0xff;\n"); |
553 |
|
|
printf ("\twhile (dmask) { %s m68k_dreg(regs, movem_index1[dmask])); srca += %d; dmask = movem_next[dmask]; }\n", |
554 |
|
|
putcode, size); |
555 |
|
|
printf ("\twhile (amask) { %s m68k_areg(regs, movem_index1[amask])); srca += %d; amask = movem_next[amask]; }\n", |
556 |
|
|
putcode, size); |
557 |
|
|
} |
558 |
|
|
} |
559 |
|
|
|
560 |
|
|
static void duplicate_carry (void) |
561 |
|
|
{ |
562 |
|
|
printf ("\tCOPY_CARRY;\n"); |
563 |
|
|
} |
564 |
|
|
|
565 |
|
|
typedef enum { |
566 |
|
|
flag_logical_noclobber, flag_logical, flag_add, flag_sub, flag_cmp, flag_addx, flag_subx, flag_zn, |
567 |
|
|
flag_av, flag_sv |
568 |
|
|
} flagtypes; |
569 |
|
|
|
570 |
|
|
static void genflags_normal (flagtypes type, wordsizes size, char *value, char *src, char *dst) |
571 |
|
|
{ |
572 |
|
|
char vstr[100], sstr[100], dstr[100]; |
573 |
|
|
char usstr[100], udstr[100]; |
574 |
|
|
char unsstr[100], undstr[100]; |
575 |
|
|
|
576 |
|
|
switch (size) { |
577 |
|
|
case sz_byte: |
578 |
|
|
strcpy (vstr, "((uae_s8)("); |
579 |
|
|
strcpy (usstr, "((uae_u8)("); |
580 |
|
|
break; |
581 |
|
|
case sz_word: |
582 |
|
|
strcpy (vstr, "((uae_s16)("); |
583 |
|
|
strcpy (usstr, "((uae_u16)("); |
584 |
|
|
break; |
585 |
|
|
case sz_long: |
586 |
|
|
strcpy (vstr, "((uae_s32)("); |
587 |
|
|
strcpy (usstr, "((uae_u32)("); |
588 |
|
|
break; |
589 |
|
|
default: |
590 |
|
|
abort (); |
591 |
|
|
} |
592 |
|
|
strcpy (unsstr, usstr); |
593 |
|
|
|
594 |
|
|
strcpy (sstr, vstr); |
595 |
|
|
strcpy (dstr, vstr); |
596 |
|
|
strcat (vstr, value); |
597 |
|
|
strcat (vstr, "))"); |
598 |
|
|
strcat (dstr, dst); |
599 |
|
|
strcat (dstr, "))"); |
600 |
|
|
strcat (sstr, src); |
601 |
|
|
strcat (sstr, "))"); |
602 |
|
|
|
603 |
|
|
strcpy (udstr, usstr); |
604 |
|
|
strcat (udstr, dst); |
605 |
|
|
strcat (udstr, "))"); |
606 |
|
|
strcat (usstr, src); |
607 |
|
|
strcat (usstr, "))"); |
608 |
|
|
|
609 |
|
|
strcpy (undstr, unsstr); |
610 |
|
|
strcat (unsstr, "-"); |
611 |
|
|
strcat (undstr, "~"); |
612 |
|
|
strcat (undstr, dst); |
613 |
|
|
strcat (undstr, "))"); |
614 |
|
|
strcat (unsstr, src); |
615 |
|
|
strcat (unsstr, "))"); |
616 |
|
|
|
617 |
|
|
switch (type) { |
618 |
|
|
case flag_logical_noclobber: |
619 |
|
|
case flag_logical: |
620 |
|
|
case flag_zn: |
621 |
|
|
case flag_av: |
622 |
|
|
case flag_sv: |
623 |
|
|
case flag_addx: |
624 |
|
|
case flag_subx: |
625 |
|
|
break; |
626 |
|
|
|
627 |
|
|
case flag_add: |
628 |
|
|
start_brace (); |
629 |
|
|
printf ("uae_u32 %s = %s + %s;\n", value, dstr, sstr); |
630 |
|
|
break; |
631 |
|
|
case flag_sub: |
632 |
|
|
case flag_cmp: |
633 |
|
|
start_brace (); |
634 |
|
|
printf ("uae_u32 %s = %s - %s;\n", value, dstr, sstr); |
635 |
|
|
break; |
636 |
|
|
} |
637 |
|
|
|
638 |
|
|
switch (type) { |
639 |
|
|
case flag_logical_noclobber: |
640 |
|
|
case flag_logical: |
641 |
|
|
case flag_zn: |
642 |
|
|
break; |
643 |
|
|
|
644 |
|
|
case flag_add: |
645 |
|
|
case flag_sub: |
646 |
|
|
case flag_addx: |
647 |
|
|
case flag_subx: |
648 |
|
|
case flag_cmp: |
649 |
|
|
case flag_av: |
650 |
|
|
case flag_sv: |
651 |
|
|
start_brace (); |
652 |
|
|
printf ("\t" BOOL_TYPE " flgs = %s < 0;\n", sstr); |
653 |
|
|
printf ("\t" BOOL_TYPE " flgo = %s < 0;\n", dstr); |
654 |
|
|
printf ("\t" BOOL_TYPE " flgn = %s < 0;\n", vstr); |
655 |
|
|
break; |
656 |
|
|
} |
657 |
|
|
|
658 |
|
|
switch (type) { |
659 |
|
|
case flag_logical: |
660 |
|
|
printf ("\tCLEAR_CZNV;\n"); |
661 |
|
|
printf ("\tSET_ZFLG (%s == 0);\n", vstr); |
662 |
|
|
printf ("\tSET_NFLG (%s < 0);\n", vstr); |
663 |
|
|
break; |
664 |
|
|
case flag_logical_noclobber: |
665 |
|
|
printf ("\tSET_ZFLG (%s == 0);\n", vstr); |
666 |
|
|
printf ("\tSET_NFLG (%s < 0);\n", vstr); |
667 |
|
|
break; |
668 |
|
|
case flag_av: |
669 |
|
|
printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); |
670 |
|
|
break; |
671 |
|
|
case flag_sv: |
672 |
|
|
printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n"); |
673 |
|
|
break; |
674 |
|
|
case flag_zn: |
675 |
|
|
printf ("\tSET_ZFLG (GET_ZFLG & (%s == 0));\n", vstr); |
676 |
|
|
printf ("\tSET_NFLG (%s < 0);\n", vstr); |
677 |
|
|
break; |
678 |
|
|
case flag_add: |
679 |
|
|
printf ("\tSET_ZFLG (%s == 0);\n", vstr); |
680 |
|
|
printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); |
681 |
|
|
printf ("\tSET_CFLG (%s < %s);\n", undstr, usstr); |
682 |
|
|
duplicate_carry (); |
683 |
|
|
printf ("\tSET_NFLG (flgn != 0);\n"); |
684 |
|
|
break; |
685 |
|
|
case flag_sub: |
686 |
|
|
printf ("\tSET_ZFLG (%s == 0);\n", vstr); |
687 |
|
|
printf ("\tSET_VFLG ((flgs ^ flgo) & (flgn ^ flgo));\n"); |
688 |
|
|
printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr); |
689 |
|
|
duplicate_carry (); |
690 |
|
|
printf ("\tSET_NFLG (flgn != 0);\n"); |
691 |
|
|
break; |
692 |
|
|
case flag_addx: |
693 |
|
|
printf ("\tSET_VFLG ((flgs ^ flgn) & (flgo ^ flgn));\n"); /* minterm SON: 0x42 */ |
694 |
|
|
printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgo) & (flgo ^ flgn)));\n"); /* minterm SON: 0xD4 */ |
695 |
|
|
duplicate_carry (); |
696 |
|
|
break; |
697 |
|
|
case flag_subx: |
698 |
|
|
printf ("\tSET_VFLG ((flgs ^ flgo) & (flgo ^ flgn));\n"); /* minterm SON: 0x24 */ |
699 |
|
|
printf ("\tSET_CFLG (flgs ^ ((flgs ^ flgn) & (flgo ^ flgn)));\n"); /* minterm SON: 0xB2 */ |
700 |
|
|
duplicate_carry (); |
701 |
|
|
break; |
702 |
|
|
case flag_cmp: |
703 |
|
|
printf ("\tSET_ZFLG (%s == 0);\n", vstr); |
704 |
|
|
printf ("\tSET_VFLG ((flgs != flgo) && (flgn != flgo));\n"); |
705 |
|
|
printf ("\tSET_CFLG (%s > %s);\n", usstr, udstr); |
706 |
|
|
printf ("\tSET_NFLG (flgn != 0);\n"); |
707 |
|
|
break; |
708 |
|
|
} |
709 |
|
|
} |
710 |
|
|
|
711 |
|
|
static void genflags (flagtypes type, wordsizes size, char *value, char *src, char *dst) |
712 |
|
|
{ |
713 |
|
|
#ifdef X86_ASSEMBLY |
714 |
|
|
switch (type) { |
715 |
|
|
case flag_add: |
716 |
|
|
case flag_sub: |
717 |
|
|
start_brace (); |
718 |
|
|
printf ("\tuae_u32 %s;\n", value); |
719 |
|
|
break; |
720 |
|
|
|
721 |
|
|
default: |
722 |
|
|
break; |
723 |
|
|
} |
724 |
|
|
|
725 |
|
|
/* At least some of those casts are fairly important! */ |
726 |
|
|
switch (type) { |
727 |
|
|
case flag_logical_noclobber: |
728 |
|
|
printf ("\t{uae_u32 oldcznv = regflags.cznv & ~0xC0;\n"); |
729 |
|
|
if (strcmp (value, "0") == 0) { |
730 |
|
|
printf ("\tregflags.cznv = olcznv | 64;\n"); |
731 |
|
|
} else { |
732 |
|
|
switch (size) { |
733 |
|
|
case sz_byte: printf ("\tx86_flag_testb ((uae_s8)(%s));\n", value); break; |
734 |
|
|
case sz_word: printf ("\tx86_flag_testw ((uae_s16)(%s));\n", value); break; |
735 |
|
|
case sz_long: printf ("\tx86_flag_testl ((uae_s32)(%s));\n", value); break; |
736 |
|
|
} |
737 |
|
|
printf ("\tregflags.cznv |= oldcznv;\n"); |
738 |
|
|
} |
739 |
|
|
printf ("\t}\n"); |
740 |
|
|
return; |
741 |
|
|
case flag_logical: |
742 |
|
|
if (strcmp (value, "0") == 0) { |
743 |
|
|
printf ("\tregflags.cznv = 64;\n"); |
744 |
|
|
} else { |
745 |
|
|
switch (size) { |
746 |
|
|
case sz_byte: printf ("\tx86_flag_testb ((uae_s8)(%s));\n", value); break; |
747 |
|
|
case sz_word: printf ("\tx86_flag_testw ((uae_s16)(%s));\n", value); break; |
748 |
|
|
case sz_long: printf ("\tx86_flag_testl ((uae_s32)(%s));\n", value); break; |
749 |
|
|
} |
750 |
|
|
} |
751 |
|
|
return; |
752 |
|
|
|
753 |
|
|
case flag_add: |
754 |
|
|
switch (size) { |
755 |
|
|
case sz_byte: printf ("\tx86_flag_addb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break; |
756 |
|
|
case sz_word: printf ("\tx86_flag_addw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break; |
757 |
|
|
case sz_long: printf ("\tx86_flag_addl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break; |
758 |
|
|
} |
759 |
|
|
return; |
760 |
|
|
|
761 |
|
|
case flag_sub: |
762 |
|
|
switch (size) { |
763 |
|
|
case sz_byte: printf ("\tx86_flag_subb (%s, (uae_s8)(%s), (uae_s8)(%s));\n", value, src, dst); break; |
764 |
|
|
case sz_word: printf ("\tx86_flag_subw (%s, (uae_s16)(%s), (uae_s16)(%s));\n", value, src, dst); break; |
765 |
|
|
case sz_long: printf ("\tx86_flag_subl (%s, (uae_s32)(%s), (uae_s32)(%s));\n", value, src, dst); break; |
766 |
|
|
} |
767 |
|
|
return; |
768 |
|
|
|
769 |
|
|
case flag_cmp: |
770 |
|
|
switch (size) { |
771 |
|
|
case sz_byte: printf ("\tx86_flag_cmpb ((uae_s8)(%s), (uae_s8)(%s));\n", src, dst); break; |
772 |
|
|
case sz_word: printf ("\tx86_flag_cmpw ((uae_s16)(%s), (uae_s16)(%s));\n", src, dst); break; |
773 |
|
|
case sz_long: printf ("\tx86_flag_cmpl ((uae_s32)(%s), (uae_s32)(%s));\n", src, dst); break; |
774 |
|
|
} |
775 |
|
|
return; |
776 |
|
|
|
777 |
|
|
default: |
778 |
|
|
break; |
779 |
|
|
} |
780 |
|
|
#elif defined(M68K_FLAG_OPT) |
781 |
|
|
/* sam: here I'm cloning what X86_ASSEMBLY does */ |
782 |
|
|
#define EXT(size) (size==sz_byte?"b":(size==sz_word?"w":"l")) |
783 |
|
|
#define CAST(size) (size==sz_byte?"uae_s8":(size==sz_word?"uae_s16":"uae_s32")) |
784 |
|
|
switch (type) { |
785 |
|
|
case flag_add: |
786 |
|
|
case flag_sub: |
787 |
|
|
start_brace (); |
788 |
|
|
printf ("\tuae_u32 %s;\n", value); |
789 |
|
|
break; |
790 |
|
|
|
791 |
|
|
default: |
792 |
|
|
break; |
793 |
|
|
} |
794 |
|
|
|
795 |
|
|
switch (type) { |
796 |
|
|
case flag_logical: |
797 |
|
|
if (strcmp (value, "0") == 0) { |
798 |
|
|
printf ("\t*(uae_u16 *)®flags = 4;\n"); /* Z = 1 */ |
799 |
|
|
} else { |
800 |
|
|
printf ("\tm68k_flag_tst (%s, (%s)(%s));\n", |
801 |
|
|
EXT (size), CAST (size), value); |
802 |
|
|
} |
803 |
|
|
return; |
804 |
|
|
|
805 |
|
|
case flag_add: |
806 |
|
|
printf ("\t{uae_u16 ccr;\n"); |
807 |
|
|
printf ("\tm68k_flag_add (%s, (%s)%s, (%s)(%s), (%s)(%s));\n", |
808 |
|
|
EXT (size), CAST (size), value, CAST (size), src, CAST (size), dst); |
809 |
|
|
printf ("\t((uae_u16*)®flags)[1]=((uae_u16*)®flags)[0]=ccr;}\n"); |
810 |
|
|
return; |
811 |
|
|
|
812 |
|
|
case flag_sub: |
813 |
|
|
printf ("\t{uae_u16 ccr;\n"); |
814 |
|
|
printf ("\tm68k_flag_sub (%s, (%s)%s, (%s)(%s), (%s)(%s));\n", |
815 |
|
|
EXT (size), CAST (size), value, CAST (size), src, CAST (size), dst); |
816 |
|
|
printf ("\t((uae_u16*)®flags)[1]=((uae_u16*)®flags)[0]=ccr;}\n"); |
817 |
|
|
return; |
818 |
|
|
|
819 |
|
|
case flag_cmp: |
820 |
|
|
printf ("\tm68k_flag_cmp (%s, (%s)(%s), (%s)(%s));\n", |
821 |
|
|
EXT (size), CAST (size), src, CAST (size), dst); |
822 |
|
|
return; |
823 |
|
|
|
824 |
|
|
default: |
825 |
|
|
break; |
826 |
|
|
} |
827 |
|
|
#elif defined(ACORN_FLAG_OPT) && defined(__GNUC_MINOR__) |
828 |
|
|
/* |
829 |
|
|
* This is new. Might be quite buggy. |
830 |
|
|
*/ |
831 |
|
|
switch (type) { |
832 |
|
|
case flag_av: |
833 |
|
|
case flag_sv: |
834 |
|
|
case flag_zn: |
835 |
|
|
case flag_addx: |
836 |
|
|
case flag_subx: |
837 |
|
|
break; |
838 |
|
|
|
839 |
|
|
case flag_logical: |
840 |
|
|
if (strcmp (value, "0") == 0) { |
841 |
|
|
/* v=c=n=0 z=1 */ |
842 |
|
|
printf ("\t*(ULONG*)®flags = 0x40000000;\n"); |
843 |
|
|
return; |
844 |
|
|
} else { |
845 |
|
|
start_brace (); |
846 |
|
|
switch (size) { |
847 |
|
|
case sz_byte: |
848 |
|
|
printf ("\tUBYTE ccr;\n"); |
849 |
|
|
printf ("\tULONG shift;\n"); |
850 |
|
|
printf ("\t__asm__(\"mov %%2,%%1,lsl#24\n\ttst %%2,%%2\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n" |
851 |
|
|
"\t: \"=r\" (ccr) : \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value); |
852 |
|
|
printf ("\t*((UBYTE*)®flags+3) = ccr;\n"); |
853 |
|
|
return; |
854 |
|
|
case sz_word: |
855 |
|
|
printf ("\tUBYTE ccr;\n"); |
856 |
|
|
printf ("\tULONG shift;\n"); |
857 |
|
|
printf ("\t__asm__(\"mov %%2,%%1,lsl#16\n\ttst %%2,%%2\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n" |
858 |
|
|
"\t: \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value); |
859 |
|
|
printf ("\t*((UBYTE*)®flags+3) = ccr;\n"); |
860 |
|
|
return; |
861 |
|
|
case sz_long: |
862 |
|
|
printf ("\tUBYTE ccr;\n"); |
863 |
|
|
printf ("\t__asm__(\"tst %%1,%%1\n\tmov %%0,r15,lsr#24\n\tbic %%0,%%0,#0x30\"\n" |
864 |
|
|
"\t: \"=r\" (ccr) : \"r\" ((LONG)%s) : \"cc\" );\n", value); |
865 |
|
|
printf ("\t*((UBYTE*)®flags+3) = ccr;\n"); |
866 |
|
|
return; |
867 |
|
|
} |
868 |
|
|
} |
869 |
|
|
break; |
870 |
|
|
case flag_add: |
871 |
|
|
if (strcmp (dst, "0") == 0) { |
872 |
|
|
printf ("/* Error! Hier muss Peter noch was machen !!! (ADD-Flags) */"); |
873 |
|
|
} else { |
874 |
|
|
start_brace (); |
875 |
|
|
switch (size) { |
876 |
|
|
case sz_byte: |
877 |
|
|
printf ("\tULONG ccr, shift, %s;\n", value); |
878 |
|
|
printf ("\t__asm__(\"mov %%4,%%3,lsl#24\n\tadds %%0,%%4,%%2,lsl#24\n\tmov %%0,%%0,asr#24\n\tmov %%1,r15\n\torr %%1,%%1,%%1,lsr#29\"\n" |
879 |
|
|
"\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value, src, dst); |
880 |
|
|
printf ("\t*(ULONG*)®flags = ccr;\n"); |
881 |
|
|
return; |
882 |
|
|
case sz_word: |
883 |
|
|
printf ("\tULONG ccr, shift, %s;\n", value); |
884 |
|
|
printf ("\t__asm__(\"mov %%4,%%3,lsl#16\n\tadds %%0,%%4,%%2,lsl#16\n\tmov %%0,%%0,asr#16\n\tmov %%1,r15\n\torr %%1,%%1,%%1,lsr#29\"\n" |
885 |
|
|
"\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value, src, dst); |
886 |
|
|
printf ("\t*(ULONG*)®flags = ccr;\n"); |
887 |
|
|
return; |
888 |
|
|
case sz_long: |
889 |
|
|
printf ("\tULONG ccr, %s;\n", value); |
890 |
|
|
printf ("\t__asm__(\"adds %%0,%%3,%%2\n\tmov %%1,r15\n\torr %%1,%%1,%%1,lsr#29\"\n" |
891 |
|
|
"\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", value, src, dst); |
892 |
|
|
printf ("\t*(ULONG*)®flags = ccr;\n"); |
893 |
|
|
return; |
894 |
|
|
} |
895 |
|
|
} |
896 |
|
|
break; |
897 |
|
|
case flag_sub: |
898 |
|
|
if (strcmp (dst, "0") == 0) { |
899 |
|
|
printf ("/* Error! Hier muss Peter noch was machen !!! (SUB-Flags) */"); |
900 |
|
|
} else { |
901 |
|
|
start_brace (); |
902 |
|
|
switch (size) { |
903 |
|
|
case sz_byte: |
904 |
|
|
printf ("\tULONG ccr, shift, %s;\n", value); |
905 |
|
|
printf ("\t__asm__(\"mov %%4,%%3,lsl#24\n\tsubs %%0,%%4,%%2,lsl#24\n\tmov %%0,%%0,asr#24\n\tmov %%1,r15\n\teor %%1,%%1,#0x20000000\n\torr %%1,%%1,%%1,lsr#29\"\n" |
906 |
|
|
"\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", value, src, dst); |
907 |
|
|
printf ("\t*(ULONG*)®flags = ccr;\n"); |
908 |
|
|
return; |
909 |
|
|
case sz_word: |
910 |
|
|
printf ("\tULONG ccr, shift, %s;\n", value); |
911 |
|
|
printf ("\t__asm__(\"mov %%4,%%3,lsl#16\n\tsubs %%0,%%4,%%2,lsl#16\n\tmov %%0,%%0,asr#16\n\tmov %%1,r15\n\teor %%1,%%1,#0x20000000\n\torr %%1,%%1,%%1,lsr#29\"\n" |
912 |
|
|
"\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", value, src, dst); |
913 |
|
|
printf ("\t*(ULONG*)®flags = ccr;\n"); |
914 |
|
|
return; |
915 |
|
|
case sz_long: |
916 |
|
|
printf ("\tULONG ccr, %s;\n", value); |
917 |
|
|
printf ("\t__asm__(\"subs %%0,%%3,%%2\n\tmov %%1,r15\n\teor %%1,%%1,#0x20000000\n\torr %%1,%%1,%%1,lsr#29\"\n" |
918 |
|
|
"\t: \"=r\" (%s), \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", value, src, dst); |
919 |
|
|
printf ("\t*(ULONG*)®flags = ccr;\n"); |
920 |
|
|
return; |
921 |
|
|
} |
922 |
|
|
} |
923 |
|
|
break; |
924 |
|
|
case flag_cmp: |
925 |
|
|
if (strcmp (dst, "0") == 0) { |
926 |
|
|
printf ("/*Error! Hier muss Peter noch was machen !!! (CMP-Flags)*/"); |
927 |
|
|
} else { |
928 |
|
|
start_brace (); |
929 |
|
|
switch (size) { |
930 |
|
|
case sz_byte: |
931 |
|
|
printf ("\tULONG shift, ccr;\n"); |
932 |
|
|
printf ("\t__asm__(\"mov %%3,%%2,lsl#24\n\tcmp %%3,%%1,lsl#24\n\tmov %%0,r15,lsr#24\n\teor %%0,%%0,#0x20\"\n" |
933 |
|
|
"\t: \"=r\" (ccr) : \"r\" (%s), \"r\" (%s), \"r\" (shift) : \"cc\" );\n", src, dst); |
934 |
|
|
printf ("\t*((UBYTE*)®flags+3) = ccr;\n"); |
935 |
|
|
return; |
936 |
|
|
case sz_word: |
937 |
|
|
printf ("\tULONG shift, ccr;\n"); |
938 |
|
|
printf ("\t__asm__(\"mov %%3,%%2,lsl#16\n\tcmp %%3,%%1,lsl#16\n\tmov %%0,r15,lsr#24\n\teor %%0,%%0,#0x20\"\n" |
939 |
|
|
"\t: \"=r\" (ccr) : \"r\" ((WORD)%s), \"r\" ((WORD)%s), \"r\" (shift) : \"cc\" );\n", src, dst); |
940 |
|
|
printf ("\t*((UBYTE*)®flags+3) = ccr;\n"); |
941 |
|
|
return; |
942 |
|
|
case sz_long: |
943 |
|
|
printf ("\tULONG ccr;\n"); |
944 |
|
|
printf ("\t__asm__(\"cmp %%2,%%1\n\tmov %%0,r15,lsr#24\n\teor %%0,%%0,#0x20\"\n" |
945 |
|
|
"\t: \"=r\" (ccr) : \"r\" ((LONG)%s), \"r\" ((LONG)%s) : \"cc\" );\n", src, dst); |
946 |
|
|
printf ("\t*((UBYTE*)®flags+3) = ccr;\n"); |
947 |
|
|
/*printf ("\tprintf (\"%%08x %%08x %%08x\\n\", %s, %s, *((ULONG*)®flags));\n", src, dst); */ |
948 |
|
|
return; |
949 |
|
|
} |
950 |
|
|
} |
951 |
|
|
break; |
952 |
|
|
} |
953 |
|
|
#endif |
954 |
|
|
genflags_normal (type, size, value, src, dst); |
955 |
|
|
} |
956 |
|
|
|
957 |
|
|
static void force_range_for_rox (const char *var, wordsizes size) |
958 |
|
|
{ |
959 |
|
|
/* Could do a modulo operation here... which one is faster? */ |
960 |
|
|
switch (size) { |
961 |
|
|
case sz_long: |
962 |
|
|
printf ("\tif (%s >= 33) %s -= 33;\n", var, var); |
963 |
|
|
break; |
964 |
|
|
case sz_word: |
965 |
|
|
printf ("\tif (%s >= 34) %s -= 34;\n", var, var); |
966 |
|
|
printf ("\tif (%s >= 17) %s -= 17;\n", var, var); |
967 |
|
|
break; |
968 |
|
|
case sz_byte: |
969 |
|
|
printf ("\tif (%s >= 36) %s -= 36;\n", var, var); |
970 |
|
|
printf ("\tif (%s >= 18) %s -= 18;\n", var, var); |
971 |
|
|
printf ("\tif (%s >= 9) %s -= 9;\n", var, var); |
972 |
|
|
break; |
973 |
|
|
} |
974 |
|
|
} |
975 |
|
|
|
976 |
|
|
static const char *cmask (wordsizes size) |
977 |
|
|
{ |
978 |
|
|
switch (size) { |
979 |
|
|
case sz_byte: return "0x80"; |
980 |
|
|
case sz_word: return "0x8000"; |
981 |
|
|
case sz_long: return "0x80000000"; |
982 |
|
|
default: abort (); |
983 |
|
|
} |
984 |
|
|
} |
985 |
|
|
|
986 |
|
|
static int source_is_imm1_8 (struct instr *i) |
987 |
|
|
{ |
988 |
|
|
return i->stype == 3; |
989 |
|
|
} |
990 |
|
|
|
991 |
|
|
static void gen_opcode (unsigned long int opcode) |
992 |
|
|
{ |
993 |
|
|
struct instr *curi = table68k + opcode; |
994 |
|
|
insn_n_cycles = 2; |
995 |
|
|
|
996 |
|
|
start_brace (); |
997 |
|
|
#if 0 |
998 |
|
|
printf ("uae_u8 *m68k_pc = regs.pc_p;\n"); |
999 |
|
|
#endif |
1000 |
|
|
m68k_pc_offset = 2; |
1001 |
|
|
switch (curi->plev) { |
1002 |
|
|
case 0: /* not privileged */ |
1003 |
|
|
break; |
1004 |
|
|
case 1: /* unprivileged only on 68000 */ |
1005 |
|
|
if (cpu_level == 0) |
1006 |
|
|
break; |
1007 |
|
|
if (next_cpu_level < 0) |
1008 |
|
|
next_cpu_level = 0; |
1009 |
|
|
|
1010 |
|
|
/* fall through */ |
1011 |
|
|
case 2: /* priviledged */ |
1012 |
|
|
printf ("if (!regs.s) { Exception(8,0); goto %s; }\n", endlabelstr); |
1013 |
|
|
need_endlabel = 1; |
1014 |
|
|
start_brace (); |
1015 |
|
|
break; |
1016 |
|
|
case 3: /* privileged if size == word */ |
1017 |
|
|
if (curi->size == sz_byte) |
1018 |
|
|
break; |
1019 |
|
|
printf ("if (!regs.s) { Exception(8,0); goto %s; }\n", endlabelstr); |
1020 |
|
|
need_endlabel = 1; |
1021 |
|
|
start_brace (); |
1022 |
|
|
break; |
1023 |
|
|
} |
1024 |
|
|
switch (curi->mnemo) { |
1025 |
|
|
case i_OR: |
1026 |
|
|
case i_AND: |
1027 |
|
|
case i_EOR: |
1028 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1029 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1030 |
|
|
printf ("\tsrc %c= dst;\n", curi->mnemo == i_OR ? '|' : curi->mnemo == i_AND ? '&' : '^'); |
1031 |
|
|
genflags (flag_logical, curi->size, "src", "", ""); |
1032 |
|
|
genastore ("src", curi->dmode, "dstreg", curi->size, "dst"); |
1033 |
|
|
break; |
1034 |
|
|
case i_ORSR: |
1035 |
|
|
case i_EORSR: |
1036 |
|
|
printf ("\tMakeSR();\n"); |
1037 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1038 |
|
|
if (curi->size == sz_byte) { |
1039 |
|
|
printf ("\tsrc &= 0xFF;\n"); |
1040 |
|
|
} |
1041 |
|
|
printf ("\tregs.sr %c= src;\n", curi->mnemo == i_EORSR ? '^' : '|'); |
1042 |
|
|
printf ("\tMakeFromSR();\n"); |
1043 |
|
|
break; |
1044 |
|
|
case i_ANDSR: |
1045 |
|
|
printf ("\tMakeSR();\n"); |
1046 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1047 |
|
|
if (curi->size == sz_byte) { |
1048 |
|
|
printf ("\tsrc |= 0xFF00;\n"); |
1049 |
|
|
} |
1050 |
|
|
printf ("\tregs.sr &= src;\n"); |
1051 |
|
|
printf ("\tMakeFromSR();\n"); |
1052 |
|
|
break; |
1053 |
|
|
case i_SUB: |
1054 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1055 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1056 |
|
|
start_brace (); |
1057 |
|
|
genflags (flag_sub, curi->size, "newv", "src", "dst"); |
1058 |
|
|
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); |
1059 |
|
|
break; |
1060 |
|
|
case i_SUBA: |
1061 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1062 |
|
|
genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0); |
1063 |
|
|
start_brace (); |
1064 |
|
|
printf ("\tuae_u32 newv = dst - src;\n"); |
1065 |
|
|
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); |
1066 |
|
|
break; |
1067 |
|
|
case i_SUBX: |
1068 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1069 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1070 |
|
|
start_brace (); |
1071 |
|
|
printf ("\tuae_u32 newv = dst - src - (GET_XFLG ? 1 : 0);\n"); |
1072 |
|
|
genflags (flag_subx, curi->size, "newv", "src", "dst"); |
1073 |
|
|
genflags (flag_zn, curi->size, "newv", "", ""); |
1074 |
|
|
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); |
1075 |
|
|
break; |
1076 |
|
|
case i_SBCD: |
1077 |
|
|
/* Let's hope this works... */ |
1078 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1079 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1080 |
|
|
start_brace (); |
1081 |
|
|
printf ("\tuae_u16 newv_lo = (dst & 0xF) - (src & 0xF) - (GET_XFLG ? 1 : 0);\n"); |
1082 |
|
|
printf ("\tuae_u16 newv_hi = (dst & 0xF0) - (src & 0xF0);\n"); |
1083 |
|
|
printf ("\tuae_u16 newv;\n"); |
1084 |
|
|
printf ("\tint cflg;\n"); |
1085 |
|
|
printf ("\tif (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }\n"); |
1086 |
|
|
printf ("\tnewv = newv_hi + (newv_lo & 0xF);"); |
1087 |
|
|
printf ("\tSET_CFLG (cflg = (newv_hi & 0x1F0) > 0x90);\n"); |
1088 |
|
|
duplicate_carry (); |
1089 |
|
|
printf ("\tif (cflg) newv -= 0x60;\n"); |
1090 |
|
|
genflags (flag_zn, curi->size, "newv", "", ""); |
1091 |
|
|
genflags (flag_sv, curi->size, "newv", "src", "dst"); |
1092 |
|
|
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); |
1093 |
|
|
break; |
1094 |
|
|
case i_ADD: |
1095 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1096 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1097 |
|
|
start_brace (); |
1098 |
|
|
genflags (flag_add, curi->size, "newv", "src", "dst"); |
1099 |
|
|
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); |
1100 |
|
|
break; |
1101 |
|
|
case i_ADDA: |
1102 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1103 |
|
|
genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0); |
1104 |
|
|
start_brace (); |
1105 |
|
|
printf ("\tuae_u32 newv = dst + src;\n"); |
1106 |
|
|
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); |
1107 |
|
|
break; |
1108 |
|
|
case i_ADDX: |
1109 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1110 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1111 |
|
|
start_brace (); |
1112 |
|
|
printf ("\tuae_u32 newv = dst + src + (GET_XFLG ? 1 : 0);\n"); |
1113 |
|
|
genflags (flag_addx, curi->size, "newv", "src", "dst"); |
1114 |
|
|
genflags (flag_zn, curi->size, "newv", "", ""); |
1115 |
|
|
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); |
1116 |
|
|
break; |
1117 |
|
|
case i_ABCD: |
1118 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1119 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1120 |
|
|
start_brace (); |
1121 |
|
|
printf ("\tuae_u16 newv_lo = (src & 0xF) + (dst & 0xF) + (GET_XFLG ? 1 : 0);\n"); |
1122 |
|
|
printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n"); |
1123 |
|
|
printf ("\tuae_u16 newv;\n"); |
1124 |
|
|
printf ("\tint cflg;\n"); |
1125 |
|
|
printf ("\tif (newv_lo > 9) { newv_lo +=6; }\n"); |
1126 |
|
|
printf ("\tnewv = newv_hi + newv_lo;"); |
1127 |
|
|
printf ("\tSET_CFLG (cflg = (newv & 0x1F0) > 0x90);\n"); |
1128 |
|
|
duplicate_carry (); |
1129 |
|
|
printf ("\tif (cflg) newv += 0x60;\n"); |
1130 |
|
|
genflags (flag_zn, curi->size, "newv", "", ""); |
1131 |
|
|
genflags (flag_sv, curi->size, "newv", "src", "dst"); |
1132 |
|
|
genastore ("newv", curi->dmode, "dstreg", curi->size, "dst"); |
1133 |
|
|
break; |
1134 |
|
|
case i_NEG: |
1135 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1136 |
|
|
start_brace (); |
1137 |
|
|
genflags (flag_sub, curi->size, "dst", "src", "0"); |
1138 |
|
|
genastore ("dst", curi->smode, "srcreg", curi->size, "src"); |
1139 |
|
|
break; |
1140 |
|
|
case i_NEGX: |
1141 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1142 |
|
|
start_brace (); |
1143 |
|
|
printf ("\tuae_u32 newv = 0 - src - (GET_XFLG ? 1 : 0);\n"); |
1144 |
|
|
genflags (flag_subx, curi->size, "newv", "src", "0"); |
1145 |
|
|
genflags (flag_zn, curi->size, "newv", "", ""); |
1146 |
|
|
genastore ("newv", curi->smode, "srcreg", curi->size, "src"); |
1147 |
|
|
break; |
1148 |
|
|
case i_NBCD: |
1149 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1150 |
|
|
start_brace (); |
1151 |
|
|
printf ("\tuae_u16 newv_lo = - (src & 0xF) - (GET_XFLG ? 1 : 0);\n"); |
1152 |
|
|
printf ("\tuae_u16 newv_hi = - (src & 0xF0);\n"); |
1153 |
|
|
printf ("\tuae_u16 newv;\n"); |
1154 |
|
|
printf ("\tint cflg;\n"); |
1155 |
|
|
printf ("\tif (newv_lo > 9) { newv_lo-=6; newv_hi-=0x10; }\n"); |
1156 |
|
|
printf ("\tnewv = newv_hi + (newv_lo & 0xF);"); |
1157 |
|
|
printf ("\tSET_CFLG (cflg = (newv_hi & 0x1F0) > 0x90);\n"); |
1158 |
|
|
duplicate_carry(); |
1159 |
|
|
printf ("\tif (cflg) newv -= 0x60;\n"); |
1160 |
|
|
genflags (flag_zn, curi->size, "newv", "", ""); |
1161 |
|
|
genastore ("newv", curi->smode, "srcreg", curi->size, "src"); |
1162 |
|
|
break; |
1163 |
|
|
case i_CLR: |
1164 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 2, 0); |
1165 |
|
|
genflags (flag_logical, curi->size, "0", "", ""); |
1166 |
|
|
genastore ("0", curi->smode, "srcreg", curi->size, "src"); |
1167 |
|
|
break; |
1168 |
|
|
case i_NOT: |
1169 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1170 |
|
|
start_brace (); |
1171 |
|
|
printf ("\tuae_u32 dst = ~src;\n"); |
1172 |
|
|
genflags (flag_logical, curi->size, "dst", "", ""); |
1173 |
|
|
genastore ("dst", curi->smode, "srcreg", curi->size, "src"); |
1174 |
|
|
break; |
1175 |
|
|
case i_TST: |
1176 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1177 |
|
|
genflags (flag_logical, curi->size, "src", "", ""); |
1178 |
|
|
break; |
1179 |
|
|
case i_BTST: |
1180 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1181 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1182 |
|
|
if (curi->size == sz_byte) |
1183 |
|
|
printf ("\tsrc &= 7;\n"); |
1184 |
|
|
else |
1185 |
|
|
printf ("\tsrc &= 31;\n"); |
1186 |
|
|
printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n"); |
1187 |
|
|
break; |
1188 |
|
|
case i_BCHG: |
1189 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1190 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1191 |
|
|
if (curi->size == sz_byte) |
1192 |
|
|
printf ("\tsrc &= 7;\n"); |
1193 |
|
|
else |
1194 |
|
|
printf ("\tsrc &= 31;\n"); |
1195 |
|
|
printf ("\tdst ^= (1 << src);\n"); |
1196 |
|
|
printf ("\tSET_ZFLG ((dst & (1 << src)) >> src);\n"); |
1197 |
|
|
genastore ("dst", curi->dmode, "dstreg", curi->size, "dst"); |
1198 |
|
|
break; |
1199 |
|
|
case i_BCLR: |
1200 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1201 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1202 |
|
|
if (curi->size == sz_byte) |
1203 |
|
|
printf ("\tsrc &= 7;\n"); |
1204 |
|
|
else |
1205 |
|
|
printf ("\tsrc &= 31;\n"); |
1206 |
|
|
printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n"); |
1207 |
|
|
printf ("\tdst &= ~(1 << src);\n"); |
1208 |
|
|
genastore ("dst", curi->dmode, "dstreg", curi->size, "dst"); |
1209 |
|
|
break; |
1210 |
|
|
case i_BSET: |
1211 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1212 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1213 |
|
|
if (curi->size == sz_byte) |
1214 |
|
|
printf ("\tsrc &= 7;\n"); |
1215 |
|
|
else |
1216 |
|
|
printf ("\tsrc &= 31;\n"); |
1217 |
|
|
printf ("\tSET_ZFLG (1 ^ ((dst >> src) & 1));\n"); |
1218 |
|
|
printf ("\tdst |= (1 << src);\n"); |
1219 |
|
|
genastore ("dst", curi->dmode, "dstreg", curi->size, "dst"); |
1220 |
|
|
break; |
1221 |
|
|
case i_CMPM: |
1222 |
|
|
case i_CMP: |
1223 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1224 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1225 |
|
|
start_brace (); |
1226 |
|
|
genflags (flag_cmp, curi->size, "newv", "src", "dst"); |
1227 |
|
|
break; |
1228 |
|
|
case i_CMPA: |
1229 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1230 |
|
|
genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0); |
1231 |
|
|
start_brace (); |
1232 |
|
|
genflags (flag_cmp, sz_long, "newv", "src", "dst"); |
1233 |
|
|
break; |
1234 |
|
|
/* The next two are coded a little unconventional, but they are doing |
1235 |
|
|
* weird things... */ |
1236 |
|
|
case i_MVPRM: |
1237 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1238 |
|
|
|
1239 |
|
|
printf ("\tuaecptr memp = m68k_areg(regs, dstreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword ()); |
1240 |
|
|
if (curi->size == sz_word) { |
1241 |
|
|
printf ("\tput_byte(memp, src >> 8); put_byte(memp + 2, src);\n"); |
1242 |
|
|
} else { |
1243 |
|
|
printf ("\tput_byte(memp, src >> 24); put_byte(memp + 2, src >> 16);\n"); |
1244 |
|
|
printf ("\tput_byte(memp + 4, src >> 8); put_byte(memp + 6, src);\n"); |
1245 |
|
|
} |
1246 |
|
|
break; |
1247 |
|
|
case i_MVPMR: |
1248 |
|
|
printf ("\tuaecptr memp = m68k_areg(regs, srcreg) + (uae_s32)(uae_s16)%s;\n", gen_nextiword ()); |
1249 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0); |
1250 |
|
|
if (curi->size == sz_word) { |
1251 |
|
|
printf ("\tuae_u16 val = (get_byte(memp) << 8) + get_byte(memp + 2);\n"); |
1252 |
|
|
} else { |
1253 |
|
|
printf ("\tuae_u32 val = (get_byte(memp) << 24) + (get_byte(memp + 2) << 16)\n"); |
1254 |
|
|
printf (" + (get_byte(memp + 4) << 8) + get_byte(memp + 6);\n"); |
1255 |
|
|
} |
1256 |
|
|
genastore ("val", curi->dmode, "dstreg", curi->size, "dst"); |
1257 |
|
|
break; |
1258 |
|
|
case i_MOVE: |
1259 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1260 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0); |
1261 |
|
|
genflags (flag_logical, curi->size, "src", "", ""); |
1262 |
|
|
genastore ("src", curi->dmode, "dstreg", curi->size, "dst"); |
1263 |
|
|
break; |
1264 |
|
|
case i_MOVEA: |
1265 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1266 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0); |
1267 |
|
|
if (curi->size == sz_word) { |
1268 |
|
|
printf ("\tuae_u32 val = (uae_s32)(uae_s16)src;\n"); |
1269 |
|
|
} else { |
1270 |
|
|
printf ("\tuae_u32 val = src;\n"); |
1271 |
|
|
} |
1272 |
|
|
genastore ("val", curi->dmode, "dstreg", sz_long, "dst"); |
1273 |
|
|
break; |
1274 |
|
|
case i_MVSR2: |
1275 |
|
|
genamode (curi->smode, "srcreg", sz_word, "src", 2, 0); |
1276 |
|
|
printf ("\tMakeSR();\n"); |
1277 |
|
|
if (curi->size == sz_byte) |
1278 |
|
|
genastore ("regs.sr & 0xff", curi->smode, "srcreg", sz_word, "src"); |
1279 |
|
|
else |
1280 |
|
|
genastore ("regs.sr", curi->smode, "srcreg", sz_word, "src"); |
1281 |
|
|
break; |
1282 |
|
|
case i_MV2SR: |
1283 |
|
|
genamode (curi->smode, "srcreg", sz_word, "src", 1, 0); |
1284 |
|
|
if (curi->size == sz_byte) |
1285 |
|
|
printf ("\tMakeSR();\n\tregs.sr &= 0xFF00;\n\tregs.sr |= src & 0xFF;\n"); |
1286 |
|
|
else { |
1287 |
|
|
printf ("\tregs.sr = src;\n"); |
1288 |
|
|
} |
1289 |
|
|
printf ("\tMakeFromSR();\n"); |
1290 |
|
|
break; |
1291 |
|
|
case i_SWAP: |
1292 |
|
|
genamode (curi->smode, "srcreg", sz_long, "src", 1, 0); |
1293 |
|
|
start_brace (); |
1294 |
|
|
printf ("\tuae_u32 dst = ((src >> 16)&0xFFFF) | ((src&0xFFFF)<<16);\n"); |
1295 |
|
|
genflags (flag_logical, sz_long, "dst", "", ""); |
1296 |
|
|
genastore ("dst", curi->smode, "srcreg", sz_long, "src"); |
1297 |
|
|
break; |
1298 |
|
|
case i_EXG: |
1299 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1300 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1301 |
|
|
genastore ("dst", curi->smode, "srcreg", curi->size, "src"); |
1302 |
|
|
genastore ("src", curi->dmode, "dstreg", curi->size, "dst"); |
1303 |
|
|
break; |
1304 |
|
|
case i_EXT: |
1305 |
|
|
genamode (curi->smode, "srcreg", sz_long, "src", 1, 0); |
1306 |
|
|
start_brace (); |
1307 |
|
|
switch (curi->size) { |
1308 |
|
|
case sz_byte: printf ("\tuae_u32 dst = (uae_s32)(uae_s8)src;\n"); break; |
1309 |
|
|
case sz_word: printf ("\tuae_u16 dst = (uae_s16)(uae_s8)src;\n"); break; |
1310 |
|
|
case sz_long: printf ("\tuae_u32 dst = (uae_s32)(uae_s16)src;\n"); break; |
1311 |
|
|
default: abort (); |
1312 |
|
|
} |
1313 |
|
|
genflags (flag_logical, |
1314 |
|
|
curi->size == sz_word ? sz_word : sz_long, "dst", "", ""); |
1315 |
|
|
genastore ("dst", curi->smode, "srcreg", |
1316 |
|
|
curi->size == sz_word ? sz_word : sz_long, "src"); |
1317 |
|
|
break; |
1318 |
|
|
case i_MVMEL: |
1319 |
|
|
genmovemel (opcode); |
1320 |
|
|
break; |
1321 |
|
|
case i_MVMLE: |
1322 |
|
|
genmovemle (opcode); |
1323 |
|
|
break; |
1324 |
|
|
case i_TRAP: |
1325 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1326 |
|
|
sync_m68k_pc (); |
1327 |
|
|
printf ("\tException(src+32,0);\n"); |
1328 |
|
|
m68k_pc_offset = 0; |
1329 |
|
|
break; |
1330 |
|
|
case i_MVR2USP: |
1331 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1332 |
|
|
printf ("\tregs.usp = src;\n"); |
1333 |
|
|
break; |
1334 |
|
|
case i_MVUSP2R: |
1335 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 2, 0); |
1336 |
|
|
genastore ("regs.usp", curi->smode, "srcreg", curi->size, "src"); |
1337 |
|
|
break; |
1338 |
|
|
case i_RESET: |
1339 |
|
|
break; |
1340 |
|
|
case i_NOP: |
1341 |
|
|
break; |
1342 |
|
|
case i_STOP: |
1343 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1344 |
|
|
printf ("\tregs.sr = src;\n"); |
1345 |
|
|
printf ("\tMakeFromSR();\n"); |
1346 |
|
|
printf ("\tm68k_setstopped(1);\n"); |
1347 |
|
|
break; |
1348 |
|
|
case i_RTE: |
1349 |
|
|
if (cpu_level == 0) { |
1350 |
|
|
genamode (Aipi, "7", sz_word, "sr", 1, 0); |
1351 |
|
|
genamode (Aipi, "7", sz_long, "pc", 1, 0); |
1352 |
|
|
printf ("\tregs.sr = sr; m68k_setpc_rte(pc);\n"); |
1353 |
|
|
fill_prefetch_0 (); |
1354 |
|
|
printf ("\tMakeFromSR();\n"); |
1355 |
|
|
} else { |
1356 |
|
|
int old_brace_level = n_braces; |
1357 |
|
|
if (next_cpu_level < 0) |
1358 |
|
|
next_cpu_level = 0; |
1359 |
|
|
printf ("\tuae_u16 newsr; uae_u32 newpc; for (;;) {\n"); |
1360 |
|
|
genamode (Aipi, "7", sz_word, "sr", 1, 0); |
1361 |
|
|
genamode (Aipi, "7", sz_long, "pc", 1, 0); |
1362 |
|
|
genamode (Aipi, "7", sz_word, "format", 1, 0); |
1363 |
|
|
printf ("\tnewsr = sr; newpc = pc;\n"); |
1364 |
|
|
printf ("\tif ((format & 0xF000) == 0x0000) { break; }\n"); |
1365 |
|
|
printf ("\telse if ((format & 0xF000) == 0x1000) { ; }\n"); |
1366 |
|
|
printf ("\telse if ((format & 0xF000) == 0x2000) { m68k_areg(regs, 7) += 4; break; }\n"); |
1367 |
|
|
printf ("\telse if ((format & 0xF000) == 0x8000) { m68k_areg(regs, 7) += 50; break; }\n"); |
1368 |
|
|
printf ("\telse if ((format & 0xF000) == 0x9000) { m68k_areg(regs, 7) += 12; break; }\n"); |
1369 |
|
|
printf ("\telse if ((format & 0xF000) == 0xa000) { m68k_areg(regs, 7) += 24; break; }\n"); |
1370 |
|
|
printf ("\telse if ((format & 0xF000) == 0xb000) { m68k_areg(regs, 7) += 84; break; }\n"); |
1371 |
|
|
printf ("\telse { Exception(14,0); goto %s; }\n", endlabelstr); |
1372 |
|
|
printf ("\tregs.sr = newsr; MakeFromSR();\n}\n"); |
1373 |
|
|
pop_braces (old_brace_level); |
1374 |
|
|
printf ("\tregs.sr = newsr; MakeFromSR();\n"); |
1375 |
|
|
printf ("\tm68k_setpc_rte(newpc);\n"); |
1376 |
|
|
fill_prefetch_0 (); |
1377 |
|
|
need_endlabel = 1; |
1378 |
|
|
} |
1379 |
|
|
/* PC is set and prefetch filled. */ |
1380 |
|
|
m68k_pc_offset = 0; |
1381 |
|
|
break; |
1382 |
|
|
case i_RTD: |
1383 |
|
|
printf ("\tcompiler_flush_jsr_stack();\n"); |
1384 |
|
|
genamode (Aipi, "7", sz_long, "pc", 1, 0); |
1385 |
|
|
genamode (curi->smode, "srcreg", curi->size, "offs", 1, 0); |
1386 |
|
|
printf ("\tm68k_areg(regs, 7) += offs;\n"); |
1387 |
|
|
printf ("\tm68k_setpc_rte(pc);\n"); |
1388 |
|
|
fill_prefetch_0 (); |
1389 |
|
|
/* PC is set and prefetch filled. */ |
1390 |
|
|
m68k_pc_offset = 0; |
1391 |
|
|
break; |
1392 |
|
|
case i_LINK: |
1393 |
|
|
genamode (Apdi, "7", sz_long, "old", 2, 0); |
1394 |
|
|
genamode (curi->smode, "srcreg", sz_long, "src", 1, 0); |
1395 |
|
|
genastore ("src", Apdi, "7", sz_long, "old"); |
1396 |
|
|
genastore ("m68k_areg(regs, 7)", curi->smode, "srcreg", sz_long, "src"); |
1397 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0); |
1398 |
|
|
printf ("\tm68k_areg(regs, 7) += offs;\n"); |
1399 |
|
|
break; |
1400 |
|
|
case i_UNLK: |
1401 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1402 |
|
|
printf ("\tm68k_areg(regs, 7) = src;\n"); |
1403 |
|
|
genamode (Aipi, "7", sz_long, "old", 1, 0); |
1404 |
|
|
genastore ("old", curi->smode, "srcreg", curi->size, "src"); |
1405 |
|
|
break; |
1406 |
|
|
case i_RTS: |
1407 |
|
|
printf ("\tm68k_do_rts();\n"); |
1408 |
|
|
fill_prefetch_0 (); |
1409 |
|
|
m68k_pc_offset = 0; |
1410 |
|
|
break; |
1411 |
|
|
case i_TRAPV: |
1412 |
|
|
sync_m68k_pc (); |
1413 |
|
|
printf ("\tif (GET_VFLG) { Exception(7,m68k_getpc()); goto %s; }\n", endlabelstr); |
1414 |
|
|
need_endlabel = 1; |
1415 |
|
|
break; |
1416 |
|
|
case i_RTR: |
1417 |
|
|
printf ("\tcompiler_flush_jsr_stack();\n"); |
1418 |
|
|
printf ("\tMakeSR();\n"); |
1419 |
|
|
genamode (Aipi, "7", sz_word, "sr", 1, 0); |
1420 |
|
|
genamode (Aipi, "7", sz_long, "pc", 1, 0); |
1421 |
|
|
printf ("\tregs.sr &= 0xFF00; sr &= 0xFF;\n"); |
1422 |
|
|
printf ("\tregs.sr |= sr; m68k_setpc(pc);\n"); |
1423 |
|
|
fill_prefetch_0 (); |
1424 |
|
|
printf ("\tMakeFromSR();\n"); |
1425 |
|
|
m68k_pc_offset = 0; |
1426 |
|
|
break; |
1427 |
|
|
case i_JSR: |
1428 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 0, 0); |
1429 |
|
|
printf ("\tm68k_do_jsr(m68k_getpc() + %d, srca);\n", m68k_pc_offset); |
1430 |
|
|
fill_prefetch_0 (); |
1431 |
|
|
m68k_pc_offset = 0; |
1432 |
|
|
break; |
1433 |
|
|
case i_JMP: |
1434 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 0, 0); |
1435 |
|
|
printf ("\tm68k_setpc(srca);\n"); |
1436 |
|
|
fill_prefetch_0 (); |
1437 |
|
|
m68k_pc_offset = 0; |
1438 |
|
|
break; |
1439 |
|
|
case i_BSR: |
1440 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1441 |
|
|
printf ("\tuae_s32 s = (uae_s32)src + 2;\n"); |
1442 |
|
|
if (using_exception_3) { |
1443 |
|
|
printf ("\tif (src & 1) {\n"); |
1444 |
|
|
printf ("\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n"); |
1445 |
|
|
printf ("\t\tlast_fault_for_exception_3 = m68k_getpc() + s;\n"); |
1446 |
|
|
printf ("\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr); |
1447 |
|
|
printf ("\t}\n"); |
1448 |
|
|
need_endlabel = 1; |
1449 |
|
|
} |
1450 |
|
|
printf ("\tm68k_do_bsr(m68k_getpc() + %d, s);\n", m68k_pc_offset); |
1451 |
|
|
fill_prefetch_0 (); |
1452 |
|
|
m68k_pc_offset = 0; |
1453 |
|
|
break; |
1454 |
|
|
case i_Bcc: |
1455 |
|
|
if (curi->size == sz_long) { |
1456 |
|
|
if (cpu_level < 2) { |
1457 |
|
|
printf ("\tm68k_incpc(2);\n"); |
1458 |
|
|
printf ("\tif (!cctrue(%d)) goto %s;\n", curi->cc, endlabelstr); |
1459 |
|
|
printf ("\t\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n"); |
1460 |
|
|
printf ("\t\tlast_fault_for_exception_3 = m68k_getpc() + 1;\n"); |
1461 |
|
|
printf ("\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr); |
1462 |
|
|
need_endlabel = 1; |
1463 |
|
|
} else { |
1464 |
|
|
if (next_cpu_level < 1) |
1465 |
|
|
next_cpu_level = 1; |
1466 |
|
|
} |
1467 |
|
|
} |
1468 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1469 |
|
|
printf ("\tif (!cctrue(%d)) goto didnt_jump;\n", curi->cc); |
1470 |
|
|
if (using_exception_3) { |
1471 |
|
|
printf ("\tif (src & 1) {\n"); |
1472 |
|
|
printf ("\t\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n"); |
1473 |
|
|
printf ("\t\tlast_fault_for_exception_3 = m68k_getpc() + 2 + (uae_s32)src;\n"); |
1474 |
|
|
printf ("\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr); |
1475 |
|
|
printf ("\t}\n"); |
1476 |
|
|
need_endlabel = 1; |
1477 |
|
|
} |
1478 |
|
|
#ifdef USE_COMPILER |
1479 |
|
|
printf ("\tm68k_setpc_bcc(m68k_getpc() + 2 + (uae_s32)src);\n"); |
1480 |
|
|
#else |
1481 |
|
|
printf ("\tm68k_incpc ((uae_s32)src + 2);\n"); |
1482 |
|
|
#endif |
1483 |
|
|
fill_prefetch_0 (); |
1484 |
|
|
printf ("\tgoto %s;\n", endlabelstr); |
1485 |
|
|
printf ("didnt_jump:;\n"); |
1486 |
|
|
need_endlabel = 1; |
1487 |
|
|
break; |
1488 |
|
|
case i_LEA: |
1489 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 0, 0); |
1490 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0); |
1491 |
|
|
genastore ("srca", curi->dmode, "dstreg", curi->size, "dst"); |
1492 |
|
|
break; |
1493 |
|
|
case i_PEA: |
1494 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 0, 0); |
1495 |
|
|
genamode (Apdi, "7", sz_long, "dst", 2, 0); |
1496 |
|
|
genastore ("srca", Apdi, "7", sz_long, "dst"); |
1497 |
|
|
break; |
1498 |
|
|
case i_DBcc: |
1499 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1500 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "offs", 1, 0); |
1501 |
|
|
|
1502 |
|
|
printf ("\tif (!cctrue(%d)) {\n", curi->cc); |
1503 |
|
|
genastore ("(src-1)", curi->smode, "srcreg", curi->size, "src"); |
1504 |
|
|
|
1505 |
|
|
printf ("\t\tif (src) {\n"); |
1506 |
|
|
if (using_exception_3) { |
1507 |
|
|
printf ("\t\t\tif (offs & 1) {\n"); |
1508 |
|
|
printf ("\t\t\tlast_addr_for_exception_3 = m68k_getpc() + 2;\n"); |
1509 |
|
|
printf ("\t\t\tlast_fault_for_exception_3 = m68k_getpc() + 2 + (uae_s32)offs + 2;\n"); |
1510 |
|
|
printf ("\t\t\tlast_op_for_exception_3 = opcode; Exception(3,0); goto %s;\n", endlabelstr); |
1511 |
|
|
printf ("\t\t}\n"); |
1512 |
|
|
need_endlabel = 1; |
1513 |
|
|
} |
1514 |
|
|
#ifdef USE_COMPILER |
1515 |
|
|
printf ("\t\t\tm68k_setpc_bcc(m68k_getpc() + (uae_s32)offs + 2);\n"); |
1516 |
|
|
#else |
1517 |
|
|
printf ("\t\t\tm68k_incpc((uae_s32)offs + 2);\n"); |
1518 |
|
|
#endif |
1519 |
|
|
fill_prefetch_0 (); |
1520 |
|
|
printf ("\t\tgoto %s;\n", endlabelstr); |
1521 |
|
|
printf ("\t\t}\n"); |
1522 |
|
|
printf ("\t}\n"); |
1523 |
|
|
need_endlabel = 1; |
1524 |
|
|
break; |
1525 |
|
|
case i_Scc: |
1526 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 2, 0); |
1527 |
|
|
start_brace (); |
1528 |
|
|
printf ("\tint val = cctrue(%d) ? 0xff : 0;\n", curi->cc); |
1529 |
|
|
genastore ("val", curi->smode, "srcreg", curi->size, "src"); |
1530 |
|
|
break; |
1531 |
|
|
case i_DIVU: |
1532 |
|
|
printf ("\tuaecptr oldpc = m68k_getpc();\n"); |
1533 |
|
|
genamode (curi->smode, "srcreg", sz_word, "src", 1, 0); |
1534 |
|
|
genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0); |
1535 |
|
|
printf ("\tif(src == 0) { Exception(5,oldpc); goto %s; } else {\n", endlabelstr); |
1536 |
|
|
printf ("\tuae_u32 newv = (uae_u32)dst / (uae_u32)(uae_u16)src;\n"); |
1537 |
|
|
printf ("\tuae_u32 rem = (uae_u32)dst %% (uae_u32)(uae_u16)src;\n"); |
1538 |
|
|
/* The N flag appears to be set each time there is an overflow. |
1539 |
|
|
* Weird. */ |
1540 |
|
|
printf ("\tif (newv > 0xffff) { SET_VFLG (1); SET_NFLG (1); SET_CFLG (0); } else\n\t{\n"); |
1541 |
|
|
genflags (flag_logical, sz_word, "newv", "", ""); |
1542 |
|
|
printf ("\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n"); |
1543 |
|
|
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); |
1544 |
|
|
printf ("\t}\n"); |
1545 |
|
|
printf ("\t}\n"); |
1546 |
|
|
insn_n_cycles += 68; |
1547 |
|
|
need_endlabel = 1; |
1548 |
|
|
break; |
1549 |
|
|
case i_DIVS: |
1550 |
|
|
printf ("\tuaecptr oldpc = m68k_getpc();\n"); |
1551 |
|
|
genamode (curi->smode, "srcreg", sz_word, "src", 1, 0); |
1552 |
|
|
genamode (curi->dmode, "dstreg", sz_long, "dst", 1, 0); |
1553 |
|
|
printf ("\tif(src == 0) { Exception(5,oldpc); goto %s; } else {\n", endlabelstr); |
1554 |
|
|
printf ("\tuae_s32 newv = (uae_s32)dst / (uae_s32)(uae_s16)src;\n"); |
1555 |
|
|
printf ("\tuae_u16 rem = (uae_s32)dst %% (uae_s32)(uae_s16)src;\n"); |
1556 |
|
|
printf ("\tif ((newv & 0xffff8000) != 0 && (newv & 0xffff8000) != 0xffff8000) { SET_VFLG (1); SET_NFLG (1); SET_CFLG (0); } else\n\t{\n"); |
1557 |
|
|
printf ("\tif (((uae_s16)rem < 0) != ((uae_s32)dst < 0)) rem = -rem;\n"); |
1558 |
|
|
genflags (flag_logical, sz_word, "newv", "", ""); |
1559 |
|
|
printf ("\tnewv = (newv & 0xffff) | ((uae_u32)rem << 16);\n"); |
1560 |
|
|
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); |
1561 |
|
|
printf ("\t}\n"); |
1562 |
|
|
printf ("\t}\n"); |
1563 |
|
|
insn_n_cycles += 72; |
1564 |
|
|
need_endlabel = 1; |
1565 |
|
|
break; |
1566 |
|
|
case i_MULU: |
1567 |
|
|
genamode (curi->smode, "srcreg", sz_word, "src", 1, 0); |
1568 |
|
|
genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0); |
1569 |
|
|
start_brace (); |
1570 |
|
|
printf ("\tuae_u32 newv = (uae_u32)(uae_u16)dst * (uae_u32)(uae_u16)src;\n"); |
1571 |
|
|
genflags (flag_logical, sz_long, "newv", "", ""); |
1572 |
|
|
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); |
1573 |
|
|
insn_n_cycles += 32; |
1574 |
|
|
break; |
1575 |
|
|
case i_MULS: |
1576 |
|
|
genamode (curi->smode, "srcreg", sz_word, "src", 1, 0); |
1577 |
|
|
genamode (curi->dmode, "dstreg", sz_word, "dst", 1, 0); |
1578 |
|
|
start_brace (); |
1579 |
|
|
printf ("\tuae_u32 newv = (uae_s32)(uae_s16)dst * (uae_s32)(uae_s16)src;\n"); |
1580 |
|
|
genflags (flag_logical, sz_long, "newv", "", ""); |
1581 |
|
|
genastore ("newv", curi->dmode, "dstreg", sz_long, "dst"); |
1582 |
|
|
insn_n_cycles += 32; |
1583 |
|
|
break; |
1584 |
|
|
case i_CHK: |
1585 |
|
|
printf ("\tuaecptr oldpc = m68k_getpc();\n"); |
1586 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
1587 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
1588 |
|
|
printf ("\tif ((uae_s32)dst < 0) { SET_NFLG (1); Exception(6,oldpc); goto %s; }\n", endlabelstr); |
1589 |
|
|
printf ("\telse if (dst > src) { SET_NFLG (0); Exception(6,oldpc); goto %s; }\n", endlabelstr); |
1590 |
|
|
need_endlabel = 1; |
1591 |
|
|
break; |
1592 |
|
|
|
1593 |
|
|
case i_CHK2: |
1594 |
|
|
printf ("\tuaecptr oldpc = m68k_getpc();\n"); |
1595 |
|
|
genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0); |
1596 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0); |
1597 |
|
|
printf ("\t{uae_s32 upper,lower,reg = regs.regs[(extra >> 12) & 15];\n"); |
1598 |
|
|
switch (curi->size) { |
1599 |
|
|
case sz_byte: |
1600 |
|
|
printf ("\tlower=(uae_s32)(uae_s8)get_byte(dsta); upper = (uae_s32)(uae_s8)get_byte(dsta+1);\n"); |
1601 |
|
|
printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s8)reg;\n"); |
1602 |
|
|
break; |
1603 |
|
|
case sz_word: |
1604 |
|
|
printf ("\tlower=(uae_s32)(uae_s16)get_word(dsta); upper = (uae_s32)(uae_s16)get_word(dsta+2);\n"); |
1605 |
|
|
printf ("\tif ((extra & 0x8000) == 0) reg = (uae_s32)(uae_s16)reg;\n"); |
1606 |
|
|
break; |
1607 |
|
|
case sz_long: |
1608 |
|
|
printf ("\tlower=get_long(dsta); upper = get_long(dsta+4);\n"); |
1609 |
|
|
break; |
1610 |
|
|
default: |
1611 |
|
|
abort (); |
1612 |
|
|
} |
1613 |
|
|
printf ("\tSET_ZFLG (upper == reg || lower == reg);\n"); |
1614 |
|
|
printf ("\tSET_CFLG (lower <= upper ? reg < lower || reg > upper : reg > upper || reg < lower);\n"); |
1615 |
|
|
printf ("\tif ((extra & 0x800) && GET_CFLG) { Exception(6,oldpc); goto %s; }\n}\n", endlabelstr); |
1616 |
|
|
need_endlabel = 1; |
1617 |
|
|
break; |
1618 |
|
|
|
1619 |
|
|
case i_ASR: |
1620 |
|
|
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0); |
1621 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0); |
1622 |
|
|
start_brace (); |
1623 |
|
|
switch (curi->size) { |
1624 |
|
|
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; |
1625 |
|
|
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; |
1626 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1627 |
|
|
default: abort (); |
1628 |
|
|
} |
1629 |
|
|
printf ("\tuae_u32 sign = (%s & val) >> %d;\n", cmask (curi->size), bit_size (curi->size) - 1); |
1630 |
|
|
printf ("\tcnt &= 63;\n"); |
1631 |
|
|
printf ("\tCLEAR_CZNV;\n"); |
1632 |
|
|
printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); |
1633 |
|
|
printf ("\t\tval = %s & (uae_u32)-sign;\n", bit_mask (curi->size)); |
1634 |
|
|
printf ("\t\tSET_CFLG (sign);\n"); |
1635 |
|
|
duplicate_carry (); |
1636 |
|
|
if (source_is_imm1_8 (curi)) |
1637 |
|
|
printf ("\t} else {\n"); |
1638 |
|
|
else |
1639 |
|
|
printf ("\t} else if (cnt > 0) {\n"); |
1640 |
|
|
printf ("\t\tval >>= cnt - 1;\n"); |
1641 |
|
|
printf ("\t\tSET_CFLG (val & 1);\n"); |
1642 |
|
|
duplicate_carry (); |
1643 |
|
|
printf ("\t\tval >>= 1;\n"); |
1644 |
|
|
printf ("\t\tval |= (%s << (%d - cnt)) & (uae_u32)-sign;\n", |
1645 |
|
|
bit_mask (curi->size), |
1646 |
|
|
bit_size (curi->size)); |
1647 |
|
|
printf ("\t\tval &= %s;\n", bit_mask (curi->size)); |
1648 |
|
|
printf ("\t}\n"); |
1649 |
|
|
genflags (flag_logical_noclobber, curi->size, "val", "", ""); |
1650 |
|
|
genastore ("val", curi->dmode, "dstreg", curi->size, "data"); |
1651 |
|
|
break; |
1652 |
|
|
case i_ASL: |
1653 |
|
|
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0); |
1654 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0); |
1655 |
|
|
start_brace (); |
1656 |
|
|
switch (curi->size) { |
1657 |
|
|
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; |
1658 |
|
|
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; |
1659 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1660 |
|
|
default: abort (); |
1661 |
|
|
} |
1662 |
|
|
printf ("\tcnt &= 63;\n"); |
1663 |
|
|
printf ("\tCLEAR_CZNV;\n"); |
1664 |
|
|
printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); |
1665 |
|
|
printf ("\t\tSET_VFLG (val != 0);\n"); |
1666 |
|
|
printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n", |
1667 |
|
|
bit_size (curi->size)); |
1668 |
|
|
duplicate_carry (); |
1669 |
|
|
printf ("\t\tval = 0;\n"); |
1670 |
|
|
if (source_is_imm1_8 (curi)) |
1671 |
|
|
printf ("\t} else {\n"); |
1672 |
|
|
else |
1673 |
|
|
printf ("\t} else if (cnt > 0) {\n"); |
1674 |
|
|
printf ("\t\tuae_u32 mask = (%s << (%d - cnt)) & %s;\n", |
1675 |
|
|
bit_mask (curi->size), |
1676 |
|
|
bit_size (curi->size) - 1, |
1677 |
|
|
bit_mask (curi->size)); |
1678 |
|
|
printf ("\t\tSET_VFLG ((val & mask) != mask && (val & mask) != 0);\n"); |
1679 |
|
|
printf ("\t\tval <<= cnt - 1;\n"); |
1680 |
|
|
printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1); |
1681 |
|
|
duplicate_carry (); |
1682 |
|
|
printf ("\t\tval <<= 1;\n"); |
1683 |
|
|
printf ("\t\tval &= %s;\n", bit_mask (curi->size)); |
1684 |
|
|
printf ("\t}\n"); |
1685 |
|
|
genflags (flag_logical_noclobber, curi->size, "val", "", ""); |
1686 |
|
|
genastore ("val", curi->dmode, "dstreg", curi->size, "data"); |
1687 |
|
|
break; |
1688 |
|
|
case i_LSR: |
1689 |
|
|
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0); |
1690 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0); |
1691 |
|
|
start_brace (); |
1692 |
|
|
switch (curi->size) { |
1693 |
|
|
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; |
1694 |
|
|
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; |
1695 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1696 |
|
|
default: abort (); |
1697 |
|
|
} |
1698 |
|
|
printf ("\tcnt &= 63;\n"); |
1699 |
|
|
printf ("\tCLEAR_CZNV;\n"); |
1700 |
|
|
printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); |
1701 |
|
|
printf ("\t\tSET_CFLG ((cnt == %d) & (val >> %d));\n", |
1702 |
|
|
bit_size (curi->size), bit_size (curi->size) - 1); |
1703 |
|
|
duplicate_carry (); |
1704 |
|
|
printf ("\t\tval = 0;\n"); |
1705 |
|
|
if (source_is_imm1_8 (curi)) |
1706 |
|
|
printf ("\t} else {\n"); |
1707 |
|
|
else |
1708 |
|
|
printf ("\t} else if (cnt > 0) {\n"); |
1709 |
|
|
printf ("\t\tval >>= cnt - 1;\n"); |
1710 |
|
|
printf ("\t\tSET_CFLG (val & 1);\n"); |
1711 |
|
|
duplicate_carry (); |
1712 |
|
|
printf ("\t\tval >>= 1;\n"); |
1713 |
|
|
printf ("\t}\n"); |
1714 |
|
|
genflags (flag_logical_noclobber, curi->size, "val", "", ""); |
1715 |
|
|
genastore ("val", curi->dmode, "dstreg", curi->size, "data"); |
1716 |
|
|
break; |
1717 |
|
|
case i_LSL: |
1718 |
|
|
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0); |
1719 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0); |
1720 |
|
|
start_brace (); |
1721 |
|
|
switch (curi->size) { |
1722 |
|
|
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; |
1723 |
|
|
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; |
1724 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1725 |
|
|
default: abort (); |
1726 |
|
|
} |
1727 |
|
|
printf ("\tcnt &= 63;\n"); |
1728 |
|
|
printf ("\tCLEAR_CZNV;\n"); |
1729 |
|
|
printf ("\tif (cnt >= %d) {\n", bit_size (curi->size)); |
1730 |
|
|
printf ("\t\tSET_CFLG (cnt == %d ? val & 1 : 0);\n", |
1731 |
|
|
bit_size (curi->size)); |
1732 |
|
|
duplicate_carry (); |
1733 |
|
|
printf ("\t\tval = 0;\n"); |
1734 |
|
|
if (source_is_imm1_8 (curi)) |
1735 |
|
|
printf ("\t} else {\n"); |
1736 |
|
|
else |
1737 |
|
|
printf ("\t} else if (cnt > 0) {\n"); |
1738 |
|
|
printf ("\t\tval <<= (cnt - 1);\n"); |
1739 |
|
|
printf ("\t\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1); |
1740 |
|
|
duplicate_carry (); |
1741 |
|
|
printf ("\t\tval <<= 1;\n"); |
1742 |
|
|
printf ("\tval &= %s;\n", bit_mask (curi->size)); |
1743 |
|
|
printf ("\t}\n"); |
1744 |
|
|
genflags (flag_logical_noclobber, curi->size, "val", "", ""); |
1745 |
|
|
genastore ("val", curi->dmode, "dstreg", curi->size, "data"); |
1746 |
|
|
break; |
1747 |
|
|
case i_ROL: |
1748 |
|
|
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0); |
1749 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0); |
1750 |
|
|
start_brace (); |
1751 |
|
|
switch (curi->size) { |
1752 |
|
|
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; |
1753 |
|
|
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; |
1754 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1755 |
|
|
default: abort (); |
1756 |
|
|
} |
1757 |
|
|
printf ("\tcnt &= 63;\n"); |
1758 |
|
|
printf ("\tCLEAR_CZNV;\n"); |
1759 |
|
|
if (source_is_imm1_8 (curi)) |
1760 |
|
|
printf ("{"); |
1761 |
|
|
else |
1762 |
|
|
printf ("\tif (cnt > 0) {\n"); |
1763 |
|
|
printf ("\tuae_u32 loval;\n"); |
1764 |
|
|
printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1); |
1765 |
|
|
printf ("\tloval = val >> (%d - cnt);\n", bit_size (curi->size)); |
1766 |
|
|
printf ("\tval <<= cnt;\n"); |
1767 |
|
|
printf ("\tval |= loval;\n"); |
1768 |
|
|
printf ("\tval &= %s;\n", bit_mask (curi->size)); |
1769 |
|
|
printf ("\tSET_CFLG (val & 1);\n"); |
1770 |
|
|
printf ("}\n"); |
1771 |
|
|
genflags (flag_logical_noclobber, curi->size, "val", "", ""); |
1772 |
|
|
genastore ("val", curi->dmode, "dstreg", curi->size, "data"); |
1773 |
|
|
break; |
1774 |
|
|
case i_ROR: |
1775 |
|
|
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0); |
1776 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0); |
1777 |
|
|
start_brace (); |
1778 |
|
|
switch (curi->size) { |
1779 |
|
|
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; |
1780 |
|
|
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; |
1781 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1782 |
|
|
default: abort (); |
1783 |
|
|
} |
1784 |
|
|
printf ("\tcnt &= 63;\n"); |
1785 |
|
|
printf ("\tCLEAR_CZNV;\n"); |
1786 |
|
|
if (source_is_imm1_8 (curi)) |
1787 |
|
|
printf ("{"); |
1788 |
|
|
else |
1789 |
|
|
printf ("\tif (cnt > 0) {"); |
1790 |
|
|
printf ("\tuae_u32 hival;\n"); |
1791 |
|
|
printf ("\tcnt &= %d;\n", bit_size (curi->size) - 1); |
1792 |
|
|
printf ("\thival = val << (%d - cnt);\n", bit_size (curi->size)); |
1793 |
|
|
printf ("\tval >>= cnt;\n"); |
1794 |
|
|
printf ("\tval |= hival;\n"); |
1795 |
|
|
printf ("\tval &= %s;\n", bit_mask (curi->size)); |
1796 |
|
|
printf ("\tSET_CFLG ((val & %s) >> %d);\n", cmask (curi->size), bit_size (curi->size) - 1); |
1797 |
|
|
printf ("\t}\n"); |
1798 |
|
|
genflags (flag_logical_noclobber, curi->size, "val", "", ""); |
1799 |
|
|
genastore ("val", curi->dmode, "dstreg", curi->size, "data"); |
1800 |
|
|
break; |
1801 |
|
|
case i_ROXL: |
1802 |
|
|
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0); |
1803 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0); |
1804 |
|
|
start_brace (); |
1805 |
|
|
switch (curi->size) { |
1806 |
|
|
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; |
1807 |
|
|
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; |
1808 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1809 |
|
|
default: abort (); |
1810 |
|
|
} |
1811 |
|
|
printf ("\tcnt &= 63;\n"); |
1812 |
|
|
printf ("\tCLEAR_CZNV;\n"); |
1813 |
|
|
if (! source_is_imm1_8 (curi)) |
1814 |
|
|
force_range_for_rox ("cnt", curi->size); |
1815 |
|
|
if (source_is_imm1_8 (curi)) |
1816 |
|
|
printf ("{"); |
1817 |
|
|
else |
1818 |
|
|
printf ("\tif (cnt > 0) {\n"); |
1819 |
|
|
printf ("\tcnt--;\n"); |
1820 |
|
|
printf ("\t{\n\tuae_u32 carry;\n"); |
1821 |
|
|
printf ("\tuae_u32 loval = val >> (%d - cnt);\n", bit_size (curi->size) - 1); |
1822 |
|
|
printf ("\tcarry = loval & 1;\n"); |
1823 |
|
|
printf ("\tval = (((val << 1) | GET_XFLG) << cnt) | (loval >> 1);\n"); |
1824 |
|
|
printf ("\tSET_XFLG (carry);\n"); |
1825 |
|
|
printf ("\tval &= %s;\n", bit_mask (curi->size)); |
1826 |
|
|
printf ("\t} }\n"); |
1827 |
|
|
printf ("\tSET_CFLG (GET_XFLG);\n"); |
1828 |
|
|
genflags (flag_logical_noclobber, curi->size, "val", "", ""); |
1829 |
|
|
genastore ("val", curi->dmode, "dstreg", curi->size, "data"); |
1830 |
|
|
break; |
1831 |
|
|
case i_ROXR: |
1832 |
|
|
genamode (curi->smode, "srcreg", curi->size, "cnt", 1, 0); |
1833 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "data", 1, 0); |
1834 |
|
|
start_brace (); |
1835 |
|
|
switch (curi->size) { |
1836 |
|
|
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; |
1837 |
|
|
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; |
1838 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1839 |
|
|
default: abort (); |
1840 |
|
|
} |
1841 |
|
|
printf ("\tcnt &= 63;\n"); |
1842 |
|
|
printf ("\tCLEAR_CZNV;\n"); |
1843 |
|
|
if (! source_is_imm1_8 (curi)) |
1844 |
|
|
force_range_for_rox ("cnt", curi->size); |
1845 |
|
|
if (source_is_imm1_8 (curi)) |
1846 |
|
|
printf ("{"); |
1847 |
|
|
else |
1848 |
|
|
printf ("\tif (cnt > 0) {\n"); |
1849 |
|
|
printf ("\tcnt--;\n"); |
1850 |
|
|
printf ("\t{\n\tuae_u32 carry;\n"); |
1851 |
|
|
printf ("\tuae_u32 hival = (val << 1) | GET_XFLG;\n"); |
1852 |
|
|
printf ("\thival <<= (%d - cnt);\n", bit_size (curi->size) - 1); |
1853 |
|
|
printf ("\tval >>= cnt;\n"); |
1854 |
|
|
printf ("\tcarry = val & 1;\n"); |
1855 |
|
|
printf ("\tval >>= 1;\n"); |
1856 |
|
|
printf ("\tval |= hival;\n"); |
1857 |
|
|
printf ("\tSET_XFLG (carry);\n"); |
1858 |
|
|
printf ("\tval &= %s;\n", bit_mask (curi->size)); |
1859 |
|
|
printf ("\t} }\n"); |
1860 |
|
|
printf ("\tSET_CFLG (GET_XFLG);\n"); |
1861 |
|
|
genflags (flag_logical_noclobber, curi->size, "val", "", ""); |
1862 |
|
|
genastore ("val", curi->dmode, "dstreg", curi->size, "data"); |
1863 |
|
|
break; |
1864 |
|
|
case i_ASRW: |
1865 |
|
|
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0); |
1866 |
|
|
start_brace (); |
1867 |
|
|
switch (curi->size) { |
1868 |
|
|
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; |
1869 |
|
|
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; |
1870 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1871 |
|
|
default: abort (); |
1872 |
|
|
} |
1873 |
|
|
printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size)); |
1874 |
|
|
printf ("\tuae_u32 cflg = val & 1;\n"); |
1875 |
|
|
printf ("\tval = (val >> 1) | sign;\n"); |
1876 |
|
|
genflags (flag_logical, curi->size, "val", "", ""); |
1877 |
|
|
printf ("\tSET_CFLG (cflg);\n"); |
1878 |
|
|
duplicate_carry (); |
1879 |
|
|
genastore ("val", curi->smode, "srcreg", curi->size, "data"); |
1880 |
|
|
break; |
1881 |
|
|
case i_ASLW: |
1882 |
|
|
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0); |
1883 |
|
|
start_brace (); |
1884 |
|
|
switch (curi->size) { |
1885 |
|
|
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; |
1886 |
|
|
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; |
1887 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1888 |
|
|
default: abort (); |
1889 |
|
|
} |
1890 |
|
|
printf ("\tuae_u32 sign = %s & val;\n", cmask (curi->size)); |
1891 |
|
|
printf ("\tuae_u32 sign2;\n"); |
1892 |
|
|
printf ("\tval <<= 1;\n"); |
1893 |
|
|
genflags (flag_logical, curi->size, "val", "", ""); |
1894 |
|
|
printf ("\tsign2 = %s & val;\n", cmask (curi->size)); |
1895 |
|
|
printf ("\tSET_CFLG (sign != 0);\n"); |
1896 |
|
|
duplicate_carry (); |
1897 |
|
|
|
1898 |
|
|
printf ("\tSET_VFLG (GET_VFLG | (sign2 != sign));\n"); |
1899 |
|
|
genastore ("val", curi->smode, "srcreg", curi->size, "data"); |
1900 |
|
|
break; |
1901 |
|
|
case i_LSRW: |
1902 |
|
|
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0); |
1903 |
|
|
start_brace (); |
1904 |
|
|
switch (curi->size) { |
1905 |
|
|
case sz_byte: printf ("\tuae_u32 val = (uae_u8)data;\n"); break; |
1906 |
|
|
case sz_word: printf ("\tuae_u32 val = (uae_u16)data;\n"); break; |
1907 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1908 |
|
|
default: abort (); |
1909 |
|
|
} |
1910 |
|
|
printf ("\tuae_u32 carry = val & 1;\n"); |
1911 |
|
|
printf ("\tval >>= 1;\n"); |
1912 |
|
|
genflags (flag_logical, curi->size, "val", "", ""); |
1913 |
|
|
printf ("SET_CFLG (carry);\n"); |
1914 |
|
|
duplicate_carry (); |
1915 |
|
|
genastore ("val", curi->smode, "srcreg", curi->size, "data"); |
1916 |
|
|
break; |
1917 |
|
|
case i_LSLW: |
1918 |
|
|
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0); |
1919 |
|
|
start_brace (); |
1920 |
|
|
switch (curi->size) { |
1921 |
|
|
case sz_byte: printf ("\tuae_u8 val = data;\n"); break; |
1922 |
|
|
case sz_word: printf ("\tuae_u16 val = data;\n"); break; |
1923 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1924 |
|
|
default: abort (); |
1925 |
|
|
} |
1926 |
|
|
printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size)); |
1927 |
|
|
printf ("\tval <<= 1;\n"); |
1928 |
|
|
genflags (flag_logical, curi->size, "val", "", ""); |
1929 |
|
|
printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1); |
1930 |
|
|
duplicate_carry (); |
1931 |
|
|
genastore ("val", curi->smode, "srcreg", curi->size, "data"); |
1932 |
|
|
break; |
1933 |
|
|
case i_ROLW: |
1934 |
|
|
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0); |
1935 |
|
|
start_brace (); |
1936 |
|
|
switch (curi->size) { |
1937 |
|
|
case sz_byte: printf ("\tuae_u8 val = data;\n"); break; |
1938 |
|
|
case sz_word: printf ("\tuae_u16 val = data;\n"); break; |
1939 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1940 |
|
|
default: abort (); |
1941 |
|
|
} |
1942 |
|
|
printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size)); |
1943 |
|
|
printf ("\tval <<= 1;\n"); |
1944 |
|
|
printf ("\tif (carry) val |= 1;\n"); |
1945 |
|
|
genflags (flag_logical, curi->size, "val", "", ""); |
1946 |
|
|
printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1); |
1947 |
|
|
genastore ("val", curi->smode, "srcreg", curi->size, "data"); |
1948 |
|
|
break; |
1949 |
|
|
case i_RORW: |
1950 |
|
|
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0); |
1951 |
|
|
start_brace (); |
1952 |
|
|
switch (curi->size) { |
1953 |
|
|
case sz_byte: printf ("\tuae_u8 val = data;\n"); break; |
1954 |
|
|
case sz_word: printf ("\tuae_u16 val = data;\n"); break; |
1955 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1956 |
|
|
default: abort (); |
1957 |
|
|
} |
1958 |
|
|
printf ("\tuae_u32 carry = val & 1;\n"); |
1959 |
|
|
printf ("\tval >>= 1;\n"); |
1960 |
|
|
printf ("\tif (carry) val |= %s;\n", cmask (curi->size)); |
1961 |
|
|
genflags (flag_logical, curi->size, "val", "", ""); |
1962 |
|
|
printf ("SET_CFLG (carry);\n"); |
1963 |
|
|
genastore ("val", curi->smode, "srcreg", curi->size, "data"); |
1964 |
|
|
break; |
1965 |
|
|
case i_ROXLW: |
1966 |
|
|
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0); |
1967 |
|
|
start_brace (); |
1968 |
|
|
switch (curi->size) { |
1969 |
|
|
case sz_byte: printf ("\tuae_u8 val = data;\n"); break; |
1970 |
|
|
case sz_word: printf ("\tuae_u16 val = data;\n"); break; |
1971 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1972 |
|
|
default: abort (); |
1973 |
|
|
} |
1974 |
|
|
printf ("\tuae_u32 carry = val & %s;\n", cmask (curi->size)); |
1975 |
|
|
printf ("\tval <<= 1;\n"); |
1976 |
|
|
printf ("\tif (GET_XFLG) val |= 1;\n"); |
1977 |
|
|
genflags (flag_logical, curi->size, "val", "", ""); |
1978 |
|
|
printf ("SET_CFLG (carry >> %d);\n", bit_size (curi->size) - 1); |
1979 |
|
|
duplicate_carry (); |
1980 |
|
|
genastore ("val", curi->smode, "srcreg", curi->size, "data"); |
1981 |
|
|
break; |
1982 |
|
|
case i_ROXRW: |
1983 |
|
|
genamode (curi->smode, "srcreg", curi->size, "data", 1, 0); |
1984 |
|
|
start_brace (); |
1985 |
|
|
switch (curi->size) { |
1986 |
|
|
case sz_byte: printf ("\tuae_u8 val = data;\n"); break; |
1987 |
|
|
case sz_word: printf ("\tuae_u16 val = data;\n"); break; |
1988 |
|
|
case sz_long: printf ("\tuae_u32 val = data;\n"); break; |
1989 |
|
|
default: abort (); |
1990 |
|
|
} |
1991 |
|
|
printf ("\tuae_u32 carry = val & 1;\n"); |
1992 |
|
|
printf ("\tval >>= 1;\n"); |
1993 |
|
|
printf ("\tif (GET_XFLG) val |= %s;\n", cmask (curi->size)); |
1994 |
|
|
genflags (flag_logical, curi->size, "val", "", ""); |
1995 |
|
|
printf ("SET_CFLG (carry);\n"); |
1996 |
|
|
duplicate_carry (); |
1997 |
|
|
genastore ("val", curi->smode, "srcreg", curi->size, "data"); |
1998 |
|
|
break; |
1999 |
|
|
case i_MOVEC2: |
2000 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
2001 |
|
|
start_brace (); |
2002 |
|
|
printf ("\tint regno = (src >> 12) & 15;\n"); |
2003 |
|
|
printf ("\tuae_u32 *regp = regs.regs + regno;\n"); |
2004 |
|
|
printf ("\tm68k_movec2(src & 0xFFF, regp);\n"); |
2005 |
|
|
break; |
2006 |
|
|
case i_MOVE2C: |
2007 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
2008 |
|
|
start_brace (); |
2009 |
|
|
printf ("\tint regno = (src >> 12) & 15;\n"); |
2010 |
|
|
printf ("\tuae_u32 *regp = regs.regs + regno;\n"); |
2011 |
|
|
printf ("\tm68k_move2c(src & 0xFFF, regp);\n"); |
2012 |
|
|
break; |
2013 |
|
|
case i_CAS: |
2014 |
|
|
{ |
2015 |
|
|
int old_brace_level; |
2016 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
2017 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
2018 |
|
|
start_brace (); |
2019 |
|
|
printf ("\tint ru = (src >> 6) & 7;\n"); |
2020 |
|
|
printf ("\tint rc = src & 7;\n"); |
2021 |
|
|
genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, rc)", "dst"); |
2022 |
|
|
printf ("\tif (GET_ZFLG)"); |
2023 |
|
|
old_brace_level = n_braces; |
2024 |
|
|
start_brace (); |
2025 |
|
|
genastore ("(m68k_dreg(regs, ru))", curi->dmode, "dstreg", curi->size, "dst"); |
2026 |
|
|
pop_braces (old_brace_level); |
2027 |
|
|
printf ("else"); |
2028 |
|
|
start_brace (); |
2029 |
|
|
printf ("m68k_dreg(regs, rc) = dst;\n"); |
2030 |
|
|
pop_braces (old_brace_level); |
2031 |
|
|
} |
2032 |
|
|
break; |
2033 |
|
|
case i_CAS2: |
2034 |
|
|
genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0); |
2035 |
|
|
printf ("\tuae_u32 rn1 = regs.regs[(extra >> 28) & 15];\n"); |
2036 |
|
|
printf ("\tuae_u32 rn2 = regs.regs[(extra >> 12) & 15];\n"); |
2037 |
|
|
if (curi->size == sz_word) { |
2038 |
|
|
int old_brace_level = n_braces; |
2039 |
|
|
printf ("\tuae_u16 dst1 = get_word(rn1), dst2 = get_word(rn2);\n"); |
2040 |
|
|
genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, (extra >> 16) & 7)", "dst1"); |
2041 |
|
|
printf ("\tif (GET_ZFLG) {\n"); |
2042 |
|
|
genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, extra & 7)", "dst2"); |
2043 |
|
|
printf ("\tif (GET_ZFLG) {\n"); |
2044 |
|
|
printf ("\tput_word(rn1, m68k_dreg(regs, (extra >> 22) & 7));\n"); |
2045 |
|
|
printf ("\tput_word(rn1, m68k_dreg(regs, (extra >> 6) & 7));\n"); |
2046 |
|
|
printf ("\t}}\n"); |
2047 |
|
|
pop_braces (old_brace_level); |
2048 |
|
|
printf ("\tif (! GET_ZFLG) {\n"); |
2049 |
|
|
printf ("\tm68k_dreg(regs, (extra >> 22) & 7) = (m68k_dreg(regs, (extra >> 22) & 7) & ~0xffff) | (dst1 & 0xffff);\n"); |
2050 |
|
|
printf ("\tm68k_dreg(regs, (extra >> 6) & 7) = (m68k_dreg(regs, (extra >> 6) & 7) & ~0xffff) | (dst2 & 0xffff);\n"); |
2051 |
|
|
printf ("\t}\n"); |
2052 |
|
|
} else { |
2053 |
|
|
int old_brace_level = n_braces; |
2054 |
|
|
printf ("\tuae_u32 dst1 = get_long(rn1), dst2 = get_long(rn2);\n"); |
2055 |
|
|
genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, (extra >> 16) & 7)", "dst1"); |
2056 |
|
|
printf ("\tif (GET_ZFLG) {\n"); |
2057 |
|
|
genflags (flag_cmp, curi->size, "newv", "m68k_dreg(regs, extra & 7)", "dst2"); |
2058 |
|
|
printf ("\tif (GET_ZFLG) {\n"); |
2059 |
|
|
printf ("\tput_long(rn1, m68k_dreg(regs, (extra >> 22) & 7));\n"); |
2060 |
|
|
printf ("\tput_long(rn1, m68k_dreg(regs, (extra >> 6) & 7));\n"); |
2061 |
|
|
printf ("\t}}\n"); |
2062 |
|
|
pop_braces (old_brace_level); |
2063 |
|
|
printf ("\tif (! GET_ZFLG) {\n"); |
2064 |
|
|
printf ("\tm68k_dreg(regs, (extra >> 22) & 7) = dst1;\n"); |
2065 |
|
|
printf ("\tm68k_dreg(regs, (extra >> 6) & 7) = dst2;\n"); |
2066 |
|
|
printf ("\t}\n"); |
2067 |
|
|
} |
2068 |
|
|
break; |
2069 |
|
|
case i_MOVES: /* ignore DFC and SFC because we have no MMU */ |
2070 |
|
|
{ |
2071 |
|
|
int old_brace_level; |
2072 |
|
|
genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0); |
2073 |
|
|
printf ("\tif (extra & 0x800)\n"); |
2074 |
|
|
old_brace_level = n_braces; |
2075 |
|
|
start_brace (); |
2076 |
|
|
printf ("\tuae_u32 src = regs.regs[(extra >> 12) & 15];\n"); |
2077 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 2, 0); |
2078 |
|
|
genastore ("src", curi->dmode, "dstreg", curi->size, "dst"); |
2079 |
|
|
pop_braces (old_brace_level); |
2080 |
|
|
printf ("else"); |
2081 |
|
|
start_brace (); |
2082 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "src", 1, 0); |
2083 |
|
|
printf ("\tif (extra & 0x8000) {\n"); |
2084 |
|
|
switch (curi->size) { |
2085 |
|
|
case sz_byte: printf ("\tm68k_areg(regs, (extra >> 12) & 7) = (uae_s32)(uae_s8)src;\n"); break; |
2086 |
|
|
case sz_word: printf ("\tm68k_areg(regs, (extra >> 12) & 7) = (uae_s32)(uae_s16)src;\n"); break; |
2087 |
|
|
case sz_long: printf ("\tm68k_areg(regs, (extra >> 12) & 7) = src;\n"); break; |
2088 |
|
|
default: abort (); |
2089 |
|
|
} |
2090 |
|
|
printf ("\t} else {\n"); |
2091 |
|
|
genastore ("src", Dreg, "(extra >> 12) & 7", curi->size, ""); |
2092 |
|
|
printf ("\t}\n"); |
2093 |
|
|
pop_braces (old_brace_level); |
2094 |
|
|
} |
2095 |
|
|
break; |
2096 |
|
|
case i_BKPT: /* only needed for hardware emulators */ |
2097 |
|
|
sync_m68k_pc (); |
2098 |
|
|
printf ("\top_illg(opcode);\n"); |
2099 |
|
|
break; |
2100 |
|
|
case i_CALLM: /* not present in 68030 */ |
2101 |
|
|
sync_m68k_pc (); |
2102 |
|
|
printf ("\top_illg(opcode);\n"); |
2103 |
|
|
break; |
2104 |
|
|
case i_RTM: /* not present in 68030 */ |
2105 |
|
|
sync_m68k_pc (); |
2106 |
|
|
printf ("\top_illg(opcode);\n"); |
2107 |
|
|
break; |
2108 |
|
|
case i_TRAPcc: |
2109 |
|
|
if (curi->smode != am_unknown && curi->smode != am_illg) |
2110 |
|
|
genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0); |
2111 |
|
|
printf ("\tif (cctrue(%d)) { Exception(7,m68k_getpc()); goto %s; }\n", curi->cc, endlabelstr); |
2112 |
|
|
need_endlabel = 1; |
2113 |
|
|
break; |
2114 |
|
|
case i_DIVL: |
2115 |
|
|
sync_m68k_pc (); |
2116 |
|
|
start_brace (); |
2117 |
|
|
printf ("\tuaecptr oldpc = m68k_getpc();\n"); |
2118 |
|
|
genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0); |
2119 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
2120 |
|
|
sync_m68k_pc (); |
2121 |
|
|
printf ("\tm68k_divl(opcode, dst, extra, oldpc);\n"); |
2122 |
|
|
break; |
2123 |
|
|
case i_MULL: |
2124 |
|
|
genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0); |
2125 |
|
|
genamode (curi->dmode, "dstreg", curi->size, "dst", 1, 0); |
2126 |
|
|
sync_m68k_pc (); |
2127 |
|
|
printf ("\tm68k_mull(opcode, dst, extra);\n"); |
2128 |
|
|
break; |
2129 |
|
|
case i_BFTST: |
2130 |
|
|
case i_BFEXTU: |
2131 |
|
|
case i_BFCHG: |
2132 |
|
|
case i_BFEXTS: |
2133 |
|
|
case i_BFCLR: |
2134 |
|
|
case i_BFFFO: |
2135 |
|
|
case i_BFSET: |
2136 |
|
|
case i_BFINS: |
2137 |
|
|
genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0); |
2138 |
|
|
genamode (curi->dmode, "dstreg", sz_long, "dst", 2, 0); |
2139 |
|
|
start_brace (); |
2140 |
|
|
printf ("\tuae_s32 offset = extra & 0x800 ? m68k_dreg(regs, (extra >> 6) & 7) : (extra >> 6) & 0x1f;\n"); |
2141 |
|
|
printf ("\tint width = (((extra & 0x20 ? m68k_dreg(regs, extra & 7) : extra) -1) & 0x1f) +1;\n"); |
2142 |
|
|
if (curi->dmode == Dreg) { |
2143 |
|
|
printf ("\tuae_u32 tmp = m68k_dreg(regs, dstreg) << (offset & 0x1f);\n"); |
2144 |
|
|
} else { |
2145 |
|
|
printf ("\tuae_u32 tmp,bf0,bf1;\n"); |
2146 |
|
|
printf ("\tdsta += (offset >> 3) | (offset & 0x80000000 ? ~0x1fffffff : 0);\n"); |
2147 |
|
|
printf ("\tbf0 = get_long(dsta);bf1 = get_byte(dsta+4) & 0xff;\n"); |
2148 |
|
|
printf ("\ttmp = (bf0 << (offset & 7)) | (bf1 >> (8 - (offset & 7)));\n"); |
2149 |
|
|
} |
2150 |
|
|
printf ("\ttmp >>= (32 - width);\n"); |
2151 |
|
|
printf ("\tSET_NFLG (tmp & (1 << (width-1)) ? 1 : 0);\n"); |
2152 |
|
|
printf ("\tSET_ZFLG (tmp == 0); SET_VFLG (0); SET_CFLG (0);\n"); |
2153 |
|
|
switch (curi->mnemo) { |
2154 |
|
|
case i_BFTST: |
2155 |
|
|
break; |
2156 |
|
|
case i_BFEXTU: |
2157 |
|
|
printf ("\tm68k_dreg(regs, (extra >> 12) & 7) = tmp;\n"); |
2158 |
|
|
break; |
2159 |
|
|
case i_BFCHG: |
2160 |
|
|
printf ("\ttmp = ~tmp;\n"); |
2161 |
|
|
break; |
2162 |
|
|
case i_BFEXTS: |
2163 |
|
|
printf ("\tif (GET_NFLG) tmp |= width == 32 ? 0 : (-1 << width);\n"); |
2164 |
|
|
printf ("\tm68k_dreg(regs, (extra >> 12) & 7) = tmp;\n"); |
2165 |
|
|
break; |
2166 |
|
|
case i_BFCLR: |
2167 |
|
|
printf ("\ttmp = 0;\n"); |
2168 |
|
|
break; |
2169 |
|
|
case i_BFFFO: |
2170 |
|
|
printf ("\t{ uae_u32 mask = 1 << (width-1);\n"); |
2171 |
|
|
printf ("\twhile (mask) { if (tmp & mask) break; mask >>= 1; offset++; }}\n"); |
2172 |
|
|
printf ("\tm68k_dreg(regs, (extra >> 12) & 7) = offset;\n"); |
2173 |
|
|
break; |
2174 |
|
|
case i_BFSET: |
2175 |
|
|
printf ("\ttmp = 0xffffffff;\n"); |
2176 |
|
|
break; |
2177 |
|
|
case i_BFINS: |
2178 |
|
|
printf ("\ttmp = m68k_dreg(regs, (extra >> 12) & 7);\n"); |
2179 |
|
|
break; |
2180 |
|
|
default: |
2181 |
|
|
break; |
2182 |
|
|
} |
2183 |
|
|
if (curi->mnemo == i_BFCHG |
2184 |
|
|
|| curi->mnemo == i_BFCLR |
2185 |
|
|
|| curi->mnemo == i_BFSET |
2186 |
|
|
|| curi->mnemo == i_BFINS) |
2187 |
|
|
{ |
2188 |
|
|
printf ("\ttmp <<= (32 - width);\n"); |
2189 |
|
|
if (curi->dmode == Dreg) { |
2190 |
|
|
printf ("\tm68k_dreg(regs, dstreg) = (m68k_dreg(regs, dstreg) & ((offset & 0x1f) == 0 ? 0 :\n"); |
2191 |
|
|
printf ("\t\t(0xffffffff << (32 - (offset & 0x1f))))) |\n"); |
2192 |
|
|
printf ("\t\t(tmp >> (offset & 0x1f)) |\n"); |
2193 |
|
|
printf ("\t\t(((offset & 0x1f) + width) >= 32 ? 0 :\n"); |
2194 |
|
|
printf (" (m68k_dreg(regs, dstreg) & ((uae_u32)0xffffffff >> ((offset & 0x1f) + width))));\n"); |
2195 |
|
|
} else { |
2196 |
|
|
printf ("\tbf0 = (bf0 & (0xff000000 << (8 - (offset & 7)))) |\n"); |
2197 |
|
|
printf ("\t\t(tmp >> (offset & 7)) |\n"); |
2198 |
|
|
printf ("\t\t(((offset & 7) + width) >= 32 ? 0 :\n"); |
2199 |
|
|
printf ("\t\t (bf0 & ((uae_u32)0xffffffff >> ((offset & 7) + width))));\n"); |
2200 |
|
|
printf ("\tput_long(dsta,bf0 );\n"); |
2201 |
|
|
printf ("\tif (((offset & 7) + width) > 32) {\n"); |
2202 |
|
|
printf ("\t\tbf1 = (bf1 & (0xff >> (width - 32 + (offset & 7)))) |\n"); |
2203 |
|
|
printf ("\t\t\t(tmp << (8 - (offset & 7)));\n"); |
2204 |
|
|
printf ("\t\tput_byte(dsta+4,bf1);\n"); |
2205 |
|
|
printf ("\t}\n"); |
2206 |
|
|
} |
2207 |
|
|
} |
2208 |
|
|
break; |
2209 |
|
|
case i_PACK: |
2210 |
|
|
if (curi->smode == Dreg) { |
2211 |
|
|
printf ("\tuae_u16 val = m68k_dreg(regs, srcreg) + %s;\n", gen_nextiword ()); |
2212 |
|
|
printf ("\tm68k_dreg(regs, dstreg) = (m68k_dreg(regs, dstreg) & 0xffffff00) | ((val >> 4) & 0xf0) | (val & 0xf);\n"); |
2213 |
|
|
} else { |
2214 |
|
|
printf ("\tuae_u16 val;\n"); |
2215 |
|
|
printf ("\tm68k_areg(regs, srcreg) -= areg_byteinc[srcreg];\n"); |
2216 |
|
|
printf ("\tval = (uae_u16)get_byte(m68k_areg(regs, srcreg));\n"); |
2217 |
|
|
printf ("\tm68k_areg(regs, srcreg) -= areg_byteinc[srcreg];\n"); |
2218 |
|
|
printf ("\tval = (val | ((uae_u16)get_byte(m68k_areg(regs, srcreg)) << 8)) + %s;\n", gen_nextiword ()); |
2219 |
|
|
printf ("\tm68k_areg(regs, dstreg) -= areg_byteinc[dstreg];\n"); |
2220 |
|
|
printf ("\tput_byte(m68k_areg(regs, dstreg),((val >> 4) & 0xf0) | (val & 0xf));\n"); |
2221 |
|
|
} |
2222 |
|
|
break; |
2223 |
|
|
case i_UNPK: |
2224 |
|
|
if (curi->smode == Dreg) { |
2225 |
|
|
printf ("\tuae_u16 val = m68k_dreg(regs, srcreg);\n"); |
2226 |
|
|
printf ("\tval = (((val << 4) & 0xf00) | (val & 0xf)) + %s;\n", gen_nextiword ()); |
2227 |
|
|
printf ("\tm68k_dreg(regs, dstreg) = (m68k_dreg(regs, dstreg) & 0xffff0000) | (val & 0xffff);\n"); |
2228 |
|
|
} else { |
2229 |
|
|
printf ("\tuae_u16 val;\n"); |
2230 |
|
|
printf ("\tm68k_areg(regs, srcreg) -= areg_byteinc[srcreg];\n"); |
2231 |
|
|
printf ("\tval = (uae_u16)get_byte(m68k_areg(regs, srcreg));\n"); |
2232 |
|
|
printf ("\tval = (((val << 4) & 0xf00) | (val & 0xf)) + %s;\n", gen_nextiword ()); |
2233 |
|
|
printf ("\tm68k_areg(regs, dstreg) -= areg_byteinc[dstreg];\n"); |
2234 |
|
|
printf ("\tput_byte(m68k_areg(regs, dstreg),val);\n"); |
2235 |
|
|
printf ("\tm68k_areg(regs, dstreg) -= areg_byteinc[dstreg];\n"); |
2236 |
|
|
printf ("\tput_byte(m68k_areg(regs, dstreg),val >> 8);\n"); |
2237 |
|
|
} |
2238 |
|
|
break; |
2239 |
|
|
case i_TAS: |
2240 |
|
|
genamode (curi->smode, "srcreg", curi->size, "src", 1, 0); |
2241 |
|
|
genflags (flag_logical, curi->size, "src", "", ""); |
2242 |
|
|
printf ("\tsrc |= 0x80;\n"); |
2243 |
|
|
genastore ("src", curi->smode, "srcreg", curi->size, "src"); |
2244 |
|
|
break; |
2245 |
|
|
case i_FPP: |
2246 |
|
|
genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0); |
2247 |
|
|
sync_m68k_pc (); |
2248 |
|
|
swap_opcode (); |
2249 |
|
|
printf ("\tfpp_opp(opcode,extra);\n"); |
2250 |
|
|
break; |
2251 |
|
|
case i_FDBcc: |
2252 |
|
|
genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0); |
2253 |
|
|
sync_m68k_pc (); |
2254 |
|
|
swap_opcode (); |
2255 |
|
|
printf ("\tfdbcc_opp(opcode,extra);\n"); |
2256 |
|
|
break; |
2257 |
|
|
case i_FScc: |
2258 |
|
|
genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0); |
2259 |
|
|
sync_m68k_pc (); |
2260 |
|
|
swap_opcode (); |
2261 |
|
|
printf ("\tfscc_opp(opcode,extra);\n"); |
2262 |
|
|
break; |
2263 |
|
|
case i_FTRAPcc: |
2264 |
|
|
sync_m68k_pc (); |
2265 |
|
|
start_brace (); |
2266 |
|
|
printf ("\tuaecptr oldpc = m68k_getpc();\n"); |
2267 |
|
|
if (curi->smode != am_unknown && curi->smode != am_illg) |
2268 |
|
|
genamode (curi->smode, "srcreg", curi->size, "dummy", 1, 0); |
2269 |
|
|
sync_m68k_pc (); |
2270 |
|
|
swap_opcode (); |
2271 |
|
|
printf ("\tftrapcc_opp(opcode,oldpc);\n"); |
2272 |
|
|
break; |
2273 |
|
|
case i_FBcc: |
2274 |
|
|
sync_m68k_pc (); |
2275 |
|
|
start_brace (); |
2276 |
|
|
printf ("\tuaecptr pc = m68k_getpc();\n"); |
2277 |
|
|
genamode (curi->dmode, "srcreg", curi->size, "extra", 1, 0); |
2278 |
|
|
sync_m68k_pc (); |
2279 |
|
|
swap_opcode (); |
2280 |
|
|
printf ("\tfbcc_opp(opcode,pc,extra);\n"); |
2281 |
|
|
break; |
2282 |
|
|
case i_FSAVE: |
2283 |
|
|
sync_m68k_pc (); |
2284 |
|
|
swap_opcode (); |
2285 |
|
|
printf ("\tfsave_opp(opcode);\n"); |
2286 |
|
|
break; |
2287 |
|
|
case i_FRESTORE: |
2288 |
|
|
sync_m68k_pc (); |
2289 |
|
|
swap_opcode (); |
2290 |
|
|
printf ("\tfrestore_opp(opcode);\n"); |
2291 |
|
|
break; |
2292 |
|
|
case i_MMUOP: |
2293 |
|
|
genamode (curi->smode, "srcreg", curi->size, "extra", 1, 0); |
2294 |
|
|
sync_m68k_pc (); |
2295 |
|
|
swap_opcode (); |
2296 |
|
|
printf ("\tmmu_op(opcode,extra);\n"); |
2297 |
|
|
break; |
2298 |
|
|
default: |
2299 |
|
|
abort (); |
2300 |
|
|
break; |
2301 |
|
|
} |
2302 |
|
|
finish_braces (); |
2303 |
|
|
sync_m68k_pc (); |
2304 |
|
|
} |
2305 |
|
|
|
2306 |
|
|
static void generate_includes (FILE * f) |
2307 |
|
|
{ |
2308 |
|
|
fprintf (f, "#include \"sysdeps.h\"\n"); |
2309 |
|
|
fprintf (f, "#include \"m68k.h\"\n"); |
2310 |
|
|
fprintf (f, "#include \"memory.h\"\n"); |
2311 |
|
|
fprintf (f, "#include \"readcpu.h\"\n"); |
2312 |
|
|
fprintf (f, "#include \"newcpu.h\"\n"); |
2313 |
|
|
fprintf (f, "#include \"compiler.h\"\n"); |
2314 |
|
|
fprintf (f, "#include \"cputbl.h\"\n"); |
2315 |
|
|
} |
2316 |
|
|
|
2317 |
|
|
static int postfix; |
2318 |
|
|
|
2319 |
|
|
static void generate_one_opcode (int rp) |
2320 |
|
|
{ |
2321 |
|
|
int i; |
2322 |
|
|
uae_u16 smsk, dmsk; |
2323 |
|
|
long int opcode = opcode_map[rp]; |
2324 |
|
|
|
2325 |
|
|
if (table68k[opcode].mnemo == i_ILLG |
2326 |
|
|
|| table68k[opcode].clev > cpu_level) |
2327 |
|
|
return; |
2328 |
|
|
|
2329 |
|
|
for (i = 0; lookuptab[i].name[0]; i++) { |
2330 |
|
|
if (table68k[opcode].mnemo == lookuptab[i].mnemo) |
2331 |
|
|
break; |
2332 |
|
|
} |
2333 |
|
|
|
2334 |
|
|
if (table68k[opcode].handler != -1) |
2335 |
|
|
return; |
2336 |
|
|
|
2337 |
|
|
if (opcode_next_clev[rp] != cpu_level) { |
2338 |
|
|
fprintf (stblfile, "{ op_%lx_%d, 0, %ld }, /* %s */\n", opcode, opcode_last_postfix[rp], |
2339 |
|
|
opcode, lookuptab[i].name); |
2340 |
|
|
return; |
2341 |
|
|
} |
2342 |
|
|
fprintf (stblfile, "{ op_%lx_%d, 0, %ld }, /* %s */\n", opcode, postfix, opcode, lookuptab[i].name); |
2343 |
|
|
fprintf (headerfile, "extern cpuop_func op_%lx_%d;\n", opcode, postfix); |
2344 |
|
|
printf ("unsigned long REGPARAM2 op_%lx_%d(uae_u32 opcode) /* %s */\n{\n", opcode, postfix, lookuptab[i].name); |
2345 |
|
|
|
2346 |
|
|
switch (table68k[opcode].stype) { |
2347 |
|
|
case 0: smsk = 7; break; |
2348 |
|
|
case 1: smsk = 255; break; |
2349 |
|
|
case 2: smsk = 15; break; |
2350 |
|
|
case 3: smsk = 7; break; |
2351 |
|
|
case 4: smsk = 7; break; |
2352 |
|
|
case 5: smsk = 63; break; |
2353 |
|
|
default: abort (); |
2354 |
|
|
} |
2355 |
|
|
dmsk = 7; |
2356 |
|
|
|
2357 |
|
|
next_cpu_level = -1; |
2358 |
|
|
if (table68k[opcode].suse |
2359 |
|
|
&& table68k[opcode].smode != imm && table68k[opcode].smode != imm0 |
2360 |
|
|
&& table68k[opcode].smode != imm1 && table68k[opcode].smode != imm2 |
2361 |
|
|
&& table68k[opcode].smode != absw && table68k[opcode].smode != absl |
2362 |
|
|
&& table68k[opcode].smode != PC8r && table68k[opcode].smode != PC16) |
2363 |
|
|
{ |
2364 |
|
|
if (table68k[opcode].spos == -1) { |
2365 |
|
|
if (((int) table68k[opcode].sreg) >= 128) |
2366 |
|
|
printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].sreg); |
2367 |
|
|
else |
2368 |
|
|
printf ("\tuae_u32 srcreg = %d;\n", (int) table68k[opcode].sreg); |
2369 |
|
|
} else { |
2370 |
|
|
char source[100]; |
2371 |
|
|
int pos = table68k[opcode].spos; |
2372 |
|
|
|
2373 |
|
|
#if 0 |
2374 |
|
|
/* Check that we can do the little endian optimization safely. */ |
2375 |
|
|
if (pos < 8 && (smsk >> (8 - pos)) != 0) |
2376 |
|
|
abort (); |
2377 |
|
|
#endif |
2378 |
|
|
printf ("#ifdef HAVE_GET_WORD_UNSWAPPED\n"); |
2379 |
|
|
|
2380 |
|
|
if (pos < 8 && (smsk >> (8 - pos)) != 0) |
2381 |
|
|
sprintf (source, "(((opcode >> %d) | (opcode << %d)) & %d)", |
2382 |
|
|
pos ^ 8, 8 - pos, dmsk); |
2383 |
|
|
else if (pos != 8) |
2384 |
|
|
sprintf (source, "((opcode >> %d) & %d)", pos ^ 8, smsk); |
2385 |
|
|
else |
2386 |
|
|
sprintf (source, "(opcode & %d)", smsk); |
2387 |
|
|
|
2388 |
|
|
if (table68k[opcode].stype == 3) |
2389 |
|
|
printf ("\tuae_u32 srcreg = imm8_table[%s];\n", source); |
2390 |
|
|
else if (table68k[opcode].stype == 1) |
2391 |
|
|
printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%s;\n", source); |
2392 |
|
|
else |
2393 |
|
|
printf ("\tuae_u32 srcreg = %s;\n", source); |
2394 |
|
|
|
2395 |
|
|
printf ("#else\n"); |
2396 |
|
|
|
2397 |
|
|
if (pos) |
2398 |
|
|
sprintf (source, "((opcode >> %d) & %d)", pos, smsk); |
2399 |
|
|
else |
2400 |
|
|
sprintf (source, "(opcode & %d)", smsk); |
2401 |
|
|
|
2402 |
|
|
if (table68k[opcode].stype == 3) |
2403 |
|
|
printf ("\tuae_u32 srcreg = imm8_table[%s];\n", source); |
2404 |
|
|
else if (table68k[opcode].stype == 1) |
2405 |
|
|
printf ("\tuae_u32 srcreg = (uae_s32)(uae_s8)%s;\n", source); |
2406 |
|
|
else |
2407 |
|
|
printf ("\tuae_u32 srcreg = %s;\n", source); |
2408 |
|
|
|
2409 |
|
|
printf ("#endif\n"); |
2410 |
|
|
} |
2411 |
|
|
} |
2412 |
|
|
if (table68k[opcode].duse |
2413 |
|
|
/* Yes, the dmode can be imm, in case of LINK or DBcc */ |
2414 |
|
|
&& table68k[opcode].dmode != imm && table68k[opcode].dmode != imm0 |
2415 |
|
|
&& table68k[opcode].dmode != imm1 && table68k[opcode].dmode != imm2 |
2416 |
|
|
&& table68k[opcode].dmode != absw && table68k[opcode].dmode != absl) |
2417 |
|
|
{ |
2418 |
|
|
if (table68k[opcode].dpos == -1) { |
2419 |
|
|
if (((int) table68k[opcode].dreg) >= 128) |
2420 |
|
|
printf ("\tuae_u32 dstreg = (uae_s32)(uae_s8)%d;\n", (int) table68k[opcode].dreg); |
2421 |
|
|
else |
2422 |
|
|
printf ("\tuae_u32 dstreg = %d;\n", (int) table68k[opcode].dreg); |
2423 |
|
|
} else { |
2424 |
|
|
int pos = table68k[opcode].dpos; |
2425 |
|
|
#if 0 |
2426 |
|
|
/* Check that we can do the little endian optimization safely. */ |
2427 |
|
|
if (pos < 8 && (dmsk >> (8 - pos)) != 0) |
2428 |
|
|
abort (); |
2429 |
|
|
#endif |
2430 |
|
|
printf ("#ifdef HAVE_GET_WORD_UNSWAPPED\n"); |
2431 |
|
|
|
2432 |
|
|
if (pos < 8 && (dmsk >> (8 - pos)) != 0) |
2433 |
|
|
printf ("\tuae_u32 dstreg = ((opcode >> %d) | (opcode << %d)) & %d;\n", |
2434 |
|
|
pos ^ 8, 8 - pos, dmsk); |
2435 |
|
|
else if (pos != 8) |
2436 |
|
|
printf ("\tuae_u32 dstreg = (opcode >> %d) & %d;\n", |
2437 |
|
|
pos ^ 8, dmsk); |
2438 |
|
|
else |
2439 |
|
|
printf ("\tuae_u32 dstreg = opcode & %d;\n", dmsk); |
2440 |
|
|
|
2441 |
|
|
printf ("#else\n"); |
2442 |
|
|
|
2443 |
|
|
if (pos) |
2444 |
|
|
printf ("\tuae_u32 dstreg = (opcode >> %d) & %d;\n", |
2445 |
|
|
pos, dmsk); |
2446 |
|
|
else |
2447 |
|
|
printf ("\tuae_u32 dstreg = opcode & %d;\n", dmsk); |
2448 |
|
|
|
2449 |
|
|
printf ("#endif\n"); |
2450 |
|
|
} |
2451 |
|
|
} |
2452 |
|
|
need_endlabel = 0; |
2453 |
|
|
endlabelno++; |
2454 |
|
|
sprintf (endlabelstr, "endlabel%d", endlabelno); |
2455 |
|
|
gen_opcode (opcode); |
2456 |
|
|
if (need_endlabel) |
2457 |
|
|
printf ("%s: ;\n", endlabelstr); |
2458 |
|
|
printf ("return %d;\n", insn_n_cycles); |
2459 |
|
|
printf ("}\n"); |
2460 |
|
|
opcode_next_clev[rp] = next_cpu_level; |
2461 |
|
|
opcode_last_postfix[rp] = postfix; |
2462 |
|
|
} |
2463 |
|
|
|
2464 |
|
|
static void generate_func (void) |
2465 |
|
|
{ |
2466 |
|
|
int i, j, rp; |
2467 |
|
|
|
2468 |
|
|
using_prefetch = 0; |
2469 |
|
|
using_exception_3 = 0; |
2470 |
|
|
for (i = 0; i < 5; i++) { |
2471 |
|
|
cpu_level = 3 - i; |
2472 |
|
|
if (i == 4) { |
2473 |
|
|
cpu_level = 0; |
2474 |
|
|
using_prefetch = 1; |
2475 |
|
|
using_exception_3 = 1; |
2476 |
|
|
for (rp = 0; rp < nr_cpuop_funcs; rp++) |
2477 |
|
|
opcode_next_clev[rp] = 0; |
2478 |
|
|
} |
2479 |
|
|
postfix = i; |
2480 |
|
|
fprintf (stblfile, "struct cputbl op_smalltbl_%d[] = {\n", postfix); |
2481 |
|
|
|
2482 |
|
|
/* sam: this is for people with low memory (eg. me :)) */ |
2483 |
|
|
printf ("\n" |
2484 |
|
|
"#if !defined(PART_1) && !defined(PART_2) && " |
2485 |
|
|
"!defined(PART_3) && !defined(PART_4) && " |
2486 |
|
|
"!defined(PART_5) && !defined(PART_6) && " |
2487 |
|
|
"!defined(PART_7) && !defined(PART_8)" |
2488 |
|
|
"\n" |
2489 |
|
|
"#define PART_1 1\n" |
2490 |
|
|
"#define PART_2 1\n" |
2491 |
|
|
"#define PART_3 1\n" |
2492 |
|
|
"#define PART_4 1\n" |
2493 |
|
|
"#define PART_5 1\n" |
2494 |
|
|
"#define PART_6 1\n" |
2495 |
|
|
"#define PART_7 1\n" |
2496 |
|
|
"#define PART_8 1\n" |
2497 |
|
|
"#endif\n\n"); |
2498 |
|
|
|
2499 |
|
|
rp = 0; |
2500 |
|
|
for(j=1;j<=8;++j) { |
2501 |
|
|
int k = (j*nr_cpuop_funcs)/8; |
2502 |
|
|
printf ("#ifdef PART_%d\n",j); |
2503 |
|
|
for (; rp < k; rp++) |
2504 |
|
|
generate_one_opcode (rp); |
2505 |
|
|
printf ("#endif\n\n"); |
2506 |
|
|
} |
2507 |
|
|
|
2508 |
|
|
fprintf (stblfile, "{ 0, 0, 0 }};\n"); |
2509 |
|
|
} |
2510 |
|
|
|
2511 |
|
|
} |
2512 |
|
|
|
2513 |
|
|
int main (int argc, char **argv) |
2514 |
|
|
{ |
2515 |
|
|
read_table68k (); |
2516 |
|
|
do_merges (); |
2517 |
|
|
|
2518 |
|
|
opcode_map = (int *) malloc (sizeof (int) * nr_cpuop_funcs); |
2519 |
|
|
opcode_last_postfix = (int *) malloc (sizeof (int) * nr_cpuop_funcs); |
2520 |
|
|
opcode_next_clev = (int *) malloc (sizeof (int) * nr_cpuop_funcs); |
2521 |
|
|
counts = (unsigned long *) malloc (65536 * sizeof (unsigned long)); |
2522 |
|
|
read_counts (); |
2523 |
|
|
|
2524 |
|
|
/* It would be a lot nicer to put all in one file (we'd also get rid of |
2525 |
|
|
* cputbl.h that way), but cpuopti can't cope. That could be fixed, but |
2526 |
|
|
* I don't dare to touch the 68k version. */ |
2527 |
|
|
|
2528 |
|
|
headerfile = fopen ("cputbl.h", "wb"); |
2529 |
|
|
stblfile = fopen ("cpustbl.cpp", "wb"); |
2530 |
|
|
freopen ("cpuemu.cpp", "wb", stdout); |
2531 |
|
|
|
2532 |
|
|
generate_includes (stdout); |
2533 |
|
|
generate_includes (stblfile); |
2534 |
|
|
|
2535 |
|
|
generate_func (); |
2536 |
|
|
|
2537 |
|
|
free (table68k); |
2538 |
|
|
return 0; |
2539 |
|
|
} |