Mercurial > repos > blastem
annotate m68k_core_x86.c @ 1877:9486236f28ac
Fix sprite rendering regression introduced by H40 line at a time optimization
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 20 Aug 2019 07:07:31 -0700 |
parents | 37afb9cf58be |
children | 35722beaf895 |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
457
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
457
diff
changeset
|
2 Copyright 2013 Michael Pavone |
485
b449af228c63
Follow amd64 ABI stack alignment requirements in places it matters so we can call sprintf with floating point arguments without crashing
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
457
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
457
diff
changeset
|
5 */ |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "gen_x86.h" |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
7 #include "m68k_core.h" |
570
76bba9ffe351
Initial stab at separating the generic parts of the 68K core from the host-cpu specific parts.
Michael Pavone <pavone@retrodev.com>
parents:
569
diff
changeset
|
8 #include "m68k_internal.h" |
208
3457dc6fd558
Tweaks to make blastem compatible with m68k-tester
Mike Pavone <pavone@retrodev.com>
parents:
207
diff
changeset
|
9 #include "68kinst.h" |
95
dd3c680c618c
Initial work on allowing dynamic branches and code in RAM plus a small fix to effective address decoding
Mike Pavone <pavone@retrodev.com>
parents:
93
diff
changeset
|
10 #include "mem.h" |
557
acec5464fa1e
Rename x86_backend.h and x86_backend.c to backend.h and backend.c respectively
Mike Pavone <pavone@retrodev.com>
parents:
555
diff
changeset
|
11 #include "backend.h" |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
757
diff
changeset
|
12 #include "util.h" |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
13 #include <stdio.h> |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
14 #include <stddef.h> |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
15 #include <stdlib.h> |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
16 #include <string.h> |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
18 enum { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
19 FLAG_X, |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
20 FLAG_N, |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
21 FLAG_Z, |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
22 FLAG_V, |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
23 FLAG_C |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
24 }; |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
26 void set_flag(m68k_options * opts, uint8_t val, uint8_t flag) |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
28 if (opts->flag_regs[flag] >= 0) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
29 mov_ir(&opts->gen.code, val, opts->flag_regs[flag], SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
30 } else { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
31 int8_t offset = offsetof(m68k_context, flags) + flag; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
32 if (offset) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
33 mov_irdisp(&opts->gen.code, val, opts->gen.context_reg, offset, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
34 } else { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
35 mov_irind(&opts->gen.code, val, opts->gen.context_reg, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
36 } |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
37 } |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 } |
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
40 void set_flag_cond(m68k_options *opts, uint8_t cond, uint8_t flag) |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
41 { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
42 if (opts->flag_regs[flag] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
43 setcc_r(&opts->gen.code, cond, opts->flag_regs[flag]); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
44 } else { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
45 int8_t offset = offsetof(m68k_context, flags) + flag; |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
46 if (offset) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
47 setcc_rdisp(&opts->gen.code, cond, opts->gen.context_reg, offset); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
48 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
49 setcc_rind(&opts->gen.code, cond, opts->gen.context_reg); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
50 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
51 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
52 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
53 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
54 void check_flag(m68k_options *opts, uint8_t flag) |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
55 { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
56 if (opts->flag_regs[flag] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
57 cmp_ir(&opts->gen.code, 0, opts->flag_regs[flag], SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
58 } else { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
59 cmp_irdisp(&opts->gen.code, 0, opts->gen.context_reg, offsetof(m68k_context, flags) + flag, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
60 } |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
61 } |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
62 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
63 void flag_to_reg(m68k_options *opts, uint8_t flag, uint8_t reg) |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
64 { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
65 if (opts->flag_regs[flag] >= 0) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
66 mov_rr(&opts->gen.code, opts->flag_regs[flag], reg, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
67 } else { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
68 int8_t offset = offsetof(m68k_context, flags) + flag; |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
69 if (offset) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
70 mov_rdispr(&opts->gen.code, opts->gen.context_reg, offset, reg, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
71 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
72 mov_rindr(&opts->gen.code, opts->gen.context_reg, reg, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
73 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
74 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
75 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
76 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
77 void reg_to_flag(m68k_options *opts, uint8_t reg, uint8_t flag) |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
78 { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
79 if (opts->flag_regs[flag] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
80 mov_rr(&opts->gen.code, reg, opts->flag_regs[flag], SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
81 } else { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
82 int8_t offset = offsetof(m68k_context, flags) + flag; |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
83 if (offset) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
84 mov_rrdisp(&opts->gen.code, reg, opts->gen.context_reg, offset, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
85 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
86 mov_rrind(&opts->gen.code, reg, opts->gen.context_reg, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
87 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
88 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
89 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
90 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
91 void flag_to_flag(m68k_options *opts, uint8_t flag1, uint8_t flag2) |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
92 { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
93 code_info *code = &opts->gen.code; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
94 if (opts->flag_regs[flag1] >= 0 && opts->flag_regs[flag2] >= 0) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
95 mov_rr(code, opts->flag_regs[flag1], opts->flag_regs[flag2], SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
96 } else if(opts->flag_regs[flag1] >= 0) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
97 mov_rrdisp(code, opts->flag_regs[flag1], opts->gen.context_reg, offsetof(m68k_context, flags) + flag2, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
98 } else if (opts->flag_regs[flag2] >= 0) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
99 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, flags) + flag1, opts->flag_regs[flag2], SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
100 } else { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
101 push_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
102 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, flags) + flag1, opts->gen.scratch1, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
103 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, offsetof(m68k_context, flags) + flag2, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
104 pop_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
105 } |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
106 } |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
107 |
576
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
108 void update_flags(m68k_options *opts, uint32_t update_mask) |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
109 { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
110 uint8_t native_flags[] = {0, CC_S, CC_Z, CC_O, CC_C}; |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
111 for (int8_t flag = FLAG_C; flag >= FLAG_X; --flag) |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
112 { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
113 if (update_mask & X0 << (flag*3)) { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
114 set_flag(opts, 0, flag); |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
115 } else if(update_mask & X1 << (flag*3)) { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
116 set_flag(opts, 1, flag); |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
117 } else if(update_mask & X << (flag*3)) { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
118 if (flag == FLAG_X) { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
119 if (opts->flag_regs[FLAG_C] >= 0 || !(update_mask & (C0|C1|C))) { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
120 flag_to_flag(opts, FLAG_C, FLAG_X); |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
121 } else if(update_mask & C0) { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
122 set_flag(opts, 0, flag); |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
123 } else if(update_mask & C1) { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
124 set_flag(opts, 1, flag); |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
125 } else { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
126 set_flag_cond(opts, CC_C, flag); |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
127 } |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
128 } else { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
129 set_flag_cond(opts, native_flags[flag], flag); |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
130 } |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
131 } |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
132 } |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
133 } |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
134 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
135 void flag_to_carry(m68k_options * opts, uint8_t flag) |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
136 { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
137 if (opts->flag_regs[flag] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
138 bt_ir(&opts->gen.code, 0, opts->flag_regs[flag], SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
139 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
140 bt_irdisp(&opts->gen.code, 0, opts->gen.context_reg, offsetof(m68k_context, flags) + flag, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
141 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
142 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
143 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
144 void or_flag_to_reg(m68k_options *opts, uint8_t flag, uint8_t reg) |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
145 { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
146 if (opts->flag_regs[flag] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
147 or_rr(&opts->gen.code, opts->flag_regs[flag], reg, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
148 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
149 or_rdispr(&opts->gen.code, opts->gen.context_reg, offsetof(m68k_context, flags) + flag, reg, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
150 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
151 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
152 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
153 void xor_flag_to_reg(m68k_options *opts, uint8_t flag, uint8_t reg) |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
154 { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
155 if (opts->flag_regs[flag] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
156 xor_rr(&opts->gen.code, opts->flag_regs[flag], reg, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
157 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
158 xor_rdispr(&opts->gen.code, opts->gen.context_reg, offsetof(m68k_context, flags) + flag, reg, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
159 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
160 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
161 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
162 void xor_flag(m68k_options *opts, uint8_t val, uint8_t flag) |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
163 { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
164 if (opts->flag_regs[flag] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
165 xor_ir(&opts->gen.code, val, opts->flag_regs[flag], SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
166 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
167 xor_irdisp(&opts->gen.code, val, opts->gen.context_reg, offsetof(m68k_context, flags) + flag, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
168 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
169 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
170 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
171 void cmp_flags(m68k_options *opts, uint8_t flag1, uint8_t flag2) |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
172 { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
173 code_info *code = &opts->gen.code; |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
174 if (opts->flag_regs[flag1] >= 0 && opts->flag_regs[flag2] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
175 cmp_rr(code, opts->flag_regs[flag1], opts->flag_regs[flag2], SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
176 } else if(opts->flag_regs[flag1] >= 0 || opts->flag_regs[flag2] >= 0) { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
177 if (opts->flag_regs[flag2] >= 0) { |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
178 uint8_t tmp = flag1; |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
179 flag1 = flag2; |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
180 flag2 = tmp; |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
181 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
182 cmp_rrdisp(code, opts->flag_regs[flag1], opts->gen.context_reg, offsetof(m68k_context, flags) + flag2, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
183 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
184 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, flags) + flag1, opts->gen.scratch1, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
185 cmp_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, offsetof(m68k_context, flags) + flag2, SZ_B); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
186 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
187 } |
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
188 |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
189 void areg_to_native(m68k_options *opts, uint8_t reg, uint8_t native_reg) |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
190 { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
191 if (opts->aregs[reg] >= 0) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
192 mov_rr(&opts->gen.code, opts->aregs[reg], native_reg, SZ_D); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
193 } else { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
194 mov_rdispr(&opts->gen.code, opts->gen.context_reg, areg_offset(reg), native_reg, SZ_D); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
195 } |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
196 } |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
197 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
198 void dreg_to_native(m68k_options *opts, uint8_t reg, uint8_t native_reg) |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
199 { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
200 if (opts->dregs[reg] >= 0) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
201 mov_rr(&opts->gen.code, opts->dregs[reg], native_reg, SZ_D); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
202 } else { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
203 mov_rdispr(&opts->gen.code, opts->gen.context_reg, dreg_offset(reg), native_reg, SZ_D); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
204 } |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
205 } |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
206 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
207 void areg_to_native_sx(m68k_options *opts, uint8_t reg, uint8_t native_reg) |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
208 { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
209 if (opts->aregs[reg] >= 0) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
210 movsx_rr(&opts->gen.code, opts->aregs[reg], native_reg, SZ_W, SZ_D); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
211 } else { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
212 movsx_rdispr(&opts->gen.code, opts->gen.context_reg, areg_offset(reg), native_reg, SZ_W, SZ_D); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
213 } |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
214 } |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
215 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
216 void dreg_to_native_sx(m68k_options *opts, uint8_t reg, uint8_t native_reg) |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
217 { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
218 if (opts->dregs[reg] >= 0) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
219 movsx_rr(&opts->gen.code, opts->dregs[reg], native_reg, SZ_W, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
220 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
221 movsx_rdispr(&opts->gen.code, opts->gen.context_reg, dreg_offset(reg), native_reg, SZ_W, SZ_D); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
222 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
223 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
224 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
225 void native_to_areg(m68k_options *opts, uint8_t native_reg, uint8_t reg) |
682 | 226 { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
227 if (opts->aregs[reg] >= 0) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
228 mov_rr(&opts->gen.code, native_reg, opts->aregs[reg], SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
229 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
230 mov_rrdisp(&opts->gen.code, native_reg, opts->gen.context_reg, areg_offset(reg), SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
231 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
232 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
233 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
234 void native_to_dreg(m68k_options *opts, uint8_t native_reg, uint8_t reg) |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
235 { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
236 if (opts->dregs[reg] >= 0) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
237 mov_rr(&opts->gen.code, native_reg, opts->dregs[reg], SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
238 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
239 mov_rrdisp(&opts->gen.code, native_reg, opts->gen.context_reg, dreg_offset(reg), SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
240 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
241 } |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
242 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
243 void ldi_areg(m68k_options *opts, int32_t value, uint8_t reg) |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
244 { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
245 if (opts->aregs[reg] >= 0) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
246 mov_ir(&opts->gen.code, value, opts->aregs[reg], SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
247 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
248 mov_irdisp(&opts->gen.code, value, opts->gen.context_reg, areg_offset(reg), SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
249 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
250 } |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
251 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
252 void ldi_native(m68k_options *opts, int32_t value, uint8_t reg) |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
253 { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
254 mov_ir(&opts->gen.code, value, reg, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
255 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
256 |
588
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
257 void addi_native(m68k_options *opts, int32_t value, uint8_t reg) |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
258 { |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
259 add_ir(&opts->gen.code, value, reg, SZ_D); |
682 | 260 } |
588
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
261 |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
262 void subi_native(m68k_options *opts, int32_t value, uint8_t reg) |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
263 { |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
264 sub_ir(&opts->gen.code, value, reg, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
265 } |
588
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
266 |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
267 void push_native(m68k_options *opts, uint8_t reg) |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
268 { |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
269 push_r(&opts->gen.code, reg); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
270 } |
588
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
271 |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
272 void pop_native(m68k_options *opts, uint8_t reg) |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
273 { |
588
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
274 pop_r(&opts->gen.code, reg); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
275 } |
588
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
276 |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
277 void sign_extend16_native(m68k_options *opts, uint8_t reg) |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
278 { |
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
279 movsx_rr(&opts->gen.code, reg, reg, SZ_W, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
280 } |
588
963d5901f583
Move translate_m68k_movem to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
587
diff
changeset
|
281 |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
282 void addi_areg(m68k_options *opts, int32_t val, uint8_t reg) |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
283 { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
284 if (opts->aregs[reg] >= 0) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
285 add_ir(&opts->gen.code, val, opts->aregs[reg], SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
286 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
287 add_irdisp(&opts->gen.code, val, opts->gen.context_reg, areg_offset(reg), SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
288 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
289 } |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
290 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
291 void subi_areg(m68k_options *opts, int32_t val, uint8_t reg) |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
292 { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
293 if (opts->aregs[reg] >= 0) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
294 sub_ir(&opts->gen.code, val, opts->aregs[reg], SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
295 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
296 sub_irdisp(&opts->gen.code, val, opts->gen.context_reg, areg_offset(reg), SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
297 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
298 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
299 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
300 void add_areg_native(m68k_options *opts, uint8_t reg, uint8_t native_reg) |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
301 { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
302 if (opts->aregs[reg] >= 0) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
303 add_rr(&opts->gen.code, opts->aregs[reg], native_reg, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
304 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
305 add_rdispr(&opts->gen.code, opts->gen.context_reg, areg_offset(reg), native_reg, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
306 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
307 } |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
308 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
309 void add_dreg_native(m68k_options *opts, uint8_t reg, uint8_t native_reg) |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
310 { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
311 if (opts->dregs[reg] >= 0) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
312 add_rr(&opts->gen.code, opts->dregs[reg], native_reg, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
313 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
314 add_rdispr(&opts->gen.code, opts->gen.context_reg, dreg_offset(reg), native_reg, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
315 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
316 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
317 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
318 void calc_areg_displace(m68k_options *opts, m68k_op_info *op, uint8_t native_reg) |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
319 { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
320 areg_to_native(opts, op->params.regs.pri, native_reg); |
751
cf09b189a0ca
Fix negative offsets in calc_areg_displace
Michael Pavone <pavone@retrodev.com>
parents:
733
diff
changeset
|
321 add_ir(&opts->gen.code, op->params.regs.displacement & 0x8000 ? op->params.regs.displacement | 0xFFFF0000 : op->params.regs.displacement, native_reg, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
322 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
323 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
324 void calc_index_disp8(m68k_options *opts, m68k_op_info *op, uint8_t native_reg) |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
325 { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
326 uint8_t sec_reg = (op->params.regs.sec >> 1) & 0x7; |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
327 if (op->params.regs.sec & 1) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
328 if (op->params.regs.sec & 0x10) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
329 add_areg_native(opts, sec_reg, native_reg); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
330 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
331 add_dreg_native(opts, sec_reg, native_reg); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
332 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
333 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
334 uint8_t other_reg = native_reg == opts->gen.scratch1 ? opts->gen.scratch2 : opts->gen.scratch1; |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
335 if (op->params.regs.sec & 0x10) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
336 areg_to_native_sx(opts, sec_reg, other_reg); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
337 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
338 dreg_to_native_sx(opts, sec_reg, other_reg); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
339 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
340 add_rr(&opts->gen.code, other_reg, native_reg, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
341 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
342 if (op->params.regs.displacement) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
343 add_ir(&opts->gen.code, op->params.regs.displacement, native_reg, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
344 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
345 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
346 |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
347 void calc_areg_index_disp8(m68k_options *opts, m68k_op_info *op, uint8_t native_reg) |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
348 { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
349 areg_to_native(opts, op->params.regs.pri, native_reg); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
350 calc_index_disp8(opts, op, native_reg); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
351 } |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
352 |
1363
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
353 void m68k_check_cycles_int_latch(m68k_options *opts) |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
354 { |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
355 code_info *code = &opts->gen.code; |
1375
b68732dcbf00
Avoid splitting m68k_check_cycles_int_latch code across memory chunks since it expects a byte-sized jump offset. Avoid an unnecessary m68k_check_cycles_int_latch for register to register moves
Michael Pavone <pavone@retrodev.com>
parents:
1370
diff
changeset
|
356 check_alloc_code(code, 3*MAX_INST_LEN); |
1363
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
357 uint8_t cc; |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
358 if (opts->gen.limit < 0) { |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
359 cmp_ir(code, 1, opts->gen.cycles, SZ_D); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
360 cc = CC_NS; |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
361 } else { |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
362 cmp_rr(code, opts->gen.cycles, opts->gen.limit, SZ_D); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
363 cc = CC_A; |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
364 } |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
365 code_ptr jmp_off = code->cur+1; |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
366 jcc(code, cc, jmp_off+1); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
367 call(code, opts->handle_int_latch); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
368 *jmp_off = code->cur - (jmp_off+1); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
369 } |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
370 |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
371 uint8_t translate_m68k_op(m68kinst * inst, host_ea * ea, m68k_options * opts, uint8_t dst) |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
372 { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
373 code_info *code = &opts->gen.code; |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
374 m68k_op_info *op = dst ? &inst->dst : &inst->src; |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
375 int8_t reg = native_reg(op, opts); |
81
6d231dbe75ab
Add support for indexed modes as a source, some work on jmp and jsr with areg indirect mode
Mike Pavone <pavone@retrodev.com>
parents:
78
diff
changeset
|
376 uint8_t sec_reg; |
1363
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
377 uint8_t ret = 1; |
682 | 378 int32_t dec_amount, inc_amount; |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 if (reg >= 0) { |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
380 ea->mode = MODE_REG_DIRECT; |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
381 if (!dst && inst->dst.addr_mode == MODE_AREG && inst->extra.size == OPSIZE_WORD) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
382 movsx_rr(code, reg, opts->gen.scratch1, SZ_W, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
383 ea->base = opts->gen.scratch1; |
1430
747c779fc137
Avoid generating an instruction that would require a REX prefix when a7 is used as a byte-wide source operand in 32-bit builds. Fixes a fatal error in Dragon's Fury when entering the option menu in a 32-bit build
Michael Pavone <pavone@retrodev.com>
parents:
1375
diff
changeset
|
384 #ifdef X86_32 |
747c779fc137
Avoid generating an instruction that would require a REX prefix when a7 is used as a byte-wide source operand in 32-bit builds. Fixes a fatal error in Dragon's Fury when entering the option menu in a 32-bit build
Michael Pavone <pavone@retrodev.com>
parents:
1375
diff
changeset
|
385 } else if (reg > RBX && inst->extra.size == OPSIZE_BYTE) { |
747c779fc137
Avoid generating an instruction that would require a REX prefix when a7 is used as a byte-wide source operand in 32-bit builds. Fixes a fatal error in Dragon's Fury when entering the option menu in a 32-bit build
Michael Pavone <pavone@retrodev.com>
parents:
1375
diff
changeset
|
386 mov_rr(code, reg, opts->gen.scratch1, SZ_D); |
747c779fc137
Avoid generating an instruction that would require a REX prefix when a7 is used as a byte-wide source operand in 32-bit builds. Fixes a fatal error in Dragon's Fury when entering the option menu in a 32-bit build
Michael Pavone <pavone@retrodev.com>
parents:
1375
diff
changeset
|
387 ea->base = opts->gen.scratch1; |
747c779fc137
Avoid generating an instruction that would require a REX prefix when a7 is used as a byte-wide source operand in 32-bit builds. Fixes a fatal error in Dragon's Fury when entering the option menu in a 32-bit build
Michael Pavone <pavone@retrodev.com>
parents:
1375
diff
changeset
|
388 #endif |
181
3b4ef459aa8d
Fix signed division with negative result, fix address reg destination with word-sized operand, fix cmpm decoding and code generation, fix unbalanced pop in bit instructions
Mike Pavone <pavone@retrodev.com>
parents:
179
diff
changeset
|
389 } else { |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
390 ea->base = reg; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
391 } |
1363
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
392 return 0; |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
393 } |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
394 switch (op->addr_mode) |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
395 { |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
396 case MODE_REG: |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
397 case MODE_AREG: |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
398 //We only get one memory parameter, so if the dst operand is a register in memory, |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
399 //we need to copy this to a temp register first if we're translating the src operand |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
400 if (dst || native_reg(&(inst->dst), opts) >= 0 || inst->dst.addr_mode == MODE_UNUSED || !(inst->dst.addr_mode == MODE_REG || inst->dst.addr_mode == MODE_AREG) |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
401 || inst->op == M68K_EXG) { |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
402 |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
403 ea->mode = MODE_REG_DISPLACE8; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
404 ea->base = opts->gen.context_reg; |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
405 ea->disp = reg_offset(op); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
406 } else { |
181
3b4ef459aa8d
Fix signed division with negative result, fix address reg destination with word-sized operand, fix cmpm decoding and code generation, fix unbalanced pop in bit instructions
Mike Pavone <pavone@retrodev.com>
parents:
179
diff
changeset
|
407 if (inst->dst.addr_mode == MODE_AREG && inst->extra.size == OPSIZE_WORD) { |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
408 movsx_rdispr(code, opts->gen.context_reg, reg_offset(op), opts->gen.scratch1, SZ_W, SZ_D); |
181
3b4ef459aa8d
Fix signed division with negative result, fix address reg destination with word-sized operand, fix cmpm decoding and code generation, fix unbalanced pop in bit instructions
Mike Pavone <pavone@retrodev.com>
parents:
179
diff
changeset
|
409 } else { |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
410 mov_rdispr(code, opts->gen.context_reg, reg_offset(op), opts->gen.scratch1, inst->extra.size); |
181
3b4ef459aa8d
Fix signed division with negative result, fix address reg destination with word-sized operand, fix cmpm decoding and code generation, fix unbalanced pop in bit instructions
Mike Pavone <pavone@retrodev.com>
parents:
179
diff
changeset
|
411 } |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
412 ea->mode = MODE_REG_DIRECT; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
413 ea->base = opts->gen.scratch1; |
181
3b4ef459aa8d
Fix signed division with negative result, fix address reg destination with word-sized operand, fix cmpm decoding and code generation, fix unbalanced pop in bit instructions
Mike Pavone <pavone@retrodev.com>
parents:
179
diff
changeset
|
414 //we're explicitly handling the areg dest here, so we exit immediately |
1363
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
415 return 0; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
416 } |
1363
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
417 ret = 0; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
418 break; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
419 case MODE_AREG_PREDEC: |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
420 if (dst && inst->src.addr_mode == MODE_AREG_PREDEC) { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
421 push_r(code, opts->gen.scratch1); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
422 } |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
423 dec_amount = inst->extra.size == OPSIZE_WORD ? 2 : (inst->extra.size == OPSIZE_LONG ? 4 : (op->params.regs.pri == 7 ? 2 :1)); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
424 if (!dst) { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
425 cycles(&opts->gen, PREDEC_PENALTY); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
426 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
427 subi_areg(opts, dec_amount, op->params.regs.pri); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
428 case MODE_AREG_INDIRECT: |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
429 case MODE_AREG_POSTINC: |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
430 areg_to_native(opts, op->params.regs.pri, opts->gen.scratch1); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
431 m68k_read_size(opts, inst->extra.size); |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
432 |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
433 if (dst) { |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
434 if (inst->src.addr_mode == MODE_AREG_PREDEC) { |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
435 //restore src operand to opts->gen.scratch2 |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
436 pop_r(code, opts->gen.scratch2); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
437 } else { |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
438 //save reg value in opts->gen.scratch2 so we can use it to save the result in memory later |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
439 areg_to_native(opts, op->params.regs.pri, opts->gen.scratch2); |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
440 } |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
441 } |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
442 |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
443 if (op->addr_mode == MODE_AREG_POSTINC) { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
444 inc_amount = inst->extra.size == OPSIZE_WORD ? 2 : (inst->extra.size == OPSIZE_LONG ? 4 : (op->params.regs.pri == 7 ? 2 : 1)); |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
445 addi_areg(opts, inc_amount, op->params.regs.pri); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
446 } |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
447 ea->mode = MODE_REG_DIRECT; |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
448 ea->base = (!dst && inst->dst.addr_mode == MODE_AREG_PREDEC && inst->op != M68K_MOVE) ? opts->gen.scratch2 : opts->gen.scratch1; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
449 break; |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
450 case MODE_AREG_DISPLACE: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
451 cycles(&opts->gen, BUS); |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
452 calc_areg_displace(opts, op, opts->gen.scratch1); |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
453 if (dst) { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
454 push_r(code, opts->gen.scratch1); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
455 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
456 m68k_read_size(opts, inst->extra.size); |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
457 if (dst) { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
458 pop_r(code, opts->gen.scratch2); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
459 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
460 |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
461 ea->mode = MODE_REG_DIRECT; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
462 ea->base = opts->gen.scratch1; |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
463 break; |
81
6d231dbe75ab
Add support for indexed modes as a source, some work on jmp and jsr with areg indirect mode
Mike Pavone <pavone@retrodev.com>
parents:
78
diff
changeset
|
464 case MODE_AREG_INDEX_DISP8: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
465 cycles(&opts->gen, 6); |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
466 calc_areg_index_disp8(opts, op, opts->gen.scratch1); |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
467 if (dst) { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
468 push_r(code, opts->gen.scratch1); |
81
6d231dbe75ab
Add support for indexed modes as a source, some work on jmp and jsr with areg indirect mode
Mike Pavone <pavone@retrodev.com>
parents:
78
diff
changeset
|
469 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
470 m68k_read_size(opts, inst->extra.size); |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
471 if (dst) { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
472 pop_r(code, opts->gen.scratch2); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
473 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
474 |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
475 ea->mode = MODE_REG_DIRECT; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
476 ea->base = opts->gen.scratch1; |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
477 break; |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
478 case MODE_PC_DISPLACE: |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
479 cycles(&opts->gen, BUS); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
480 mov_ir(code, op->params.regs.displacement + inst->address+2, opts->gen.scratch1, SZ_D); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
481 if (dst) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
482 push_r(code, opts->gen.scratch1); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
483 } |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
484 m68k_read_size(opts, inst->extra.size); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
485 if (dst) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
486 pop_r(code, opts->gen.scratch2); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
487 } |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
488 |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
489 ea->mode = MODE_REG_DIRECT; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
490 ea->base = opts->gen.scratch1; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
491 break; |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
492 case MODE_PC_INDEX_DISP8: |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
493 cycles(&opts->gen, 6); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
494 mov_ir(code, inst->address+2, opts->gen.scratch1, SZ_D); |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
495 calc_index_disp8(opts, op, opts->gen.scratch1); |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
496 if (dst) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
497 push_r(code, opts->gen.scratch1); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
498 } |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
499 m68k_read_size(opts, inst->extra.size); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
500 if (dst) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
501 pop_r(code, opts->gen.scratch2); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
502 } |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
503 |
98
104e257fb93c
Allow indexed modes to be used as a destination
Mike Pavone <pavone@retrodev.com>
parents:
97
diff
changeset
|
504 ea->mode = MODE_REG_DIRECT; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
505 ea->base = opts->gen.scratch1; |
98
104e257fb93c
Allow indexed modes to be used as a destination
Mike Pavone <pavone@retrodev.com>
parents:
97
diff
changeset
|
506 break; |
61
918468c623e9
Add support for BTST instruction (untested), absolute addressing mode for instructions other than move (untested) and fix decoding of MOVEM.
Mike Pavone <pavone@retrodev.com>
parents:
59
diff
changeset
|
507 case MODE_ABSOLUTE: |
918468c623e9
Add support for BTST instruction (untested), absolute addressing mode for instructions other than move (untested) and fix decoding of MOVEM.
Mike Pavone <pavone@retrodev.com>
parents:
59
diff
changeset
|
508 case MODE_ABSOLUTE_SHORT: |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
509 cycles(&opts->gen, op->addr_mode == MODE_ABSOLUTE ? BUS*2 : BUS); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
510 mov_ir(code, op->params.immed, opts->gen.scratch1, SZ_D); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
511 if (dst) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
512 push_r(code, opts->gen.scratch1); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
513 } |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
514 m68k_read_size(opts, inst->extra.size); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
515 if (dst) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
516 pop_r(code, opts->gen.scratch2); |
61
918468c623e9
Add support for BTST instruction (untested), absolute addressing mode for instructions other than move (untested) and fix decoding of MOVEM.
Mike Pavone <pavone@retrodev.com>
parents:
59
diff
changeset
|
517 } |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
518 |
61
918468c623e9
Add support for BTST instruction (untested), absolute addressing mode for instructions other than move (untested) and fix decoding of MOVEM.
Mike Pavone <pavone@retrodev.com>
parents:
59
diff
changeset
|
519 ea->mode = MODE_REG_DIRECT; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
520 ea->base = opts->gen.scratch1; |
61
918468c623e9
Add support for BTST instruction (untested), absolute addressing mode for instructions other than move (untested) and fix decoding of MOVEM.
Mike Pavone <pavone@retrodev.com>
parents:
59
diff
changeset
|
521 break; |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
522 case MODE_IMMEDIATE: |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
523 case MODE_IMMEDIATE_WORD: |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
524 if (inst->variant != VAR_QUICK) { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
525 cycles(&opts->gen, (inst->extra.size == OPSIZE_LONG && op->addr_mode == MODE_IMMEDIATE) ? BUS*2 : BUS); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
526 } |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
527 ea->mode = MODE_IMMED; |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
528 ea->disp = op->params.immed; |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
529 //sign extend value when the destination is an address register |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
530 if (inst->dst.addr_mode == MODE_AREG && inst->extra.size == OPSIZE_WORD && ea->disp & 0x8000) { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
531 ea->disp |= 0xFFFF0000; |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
532 } |
1363
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
533 return inst->variant != VAR_QUICK; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
534 default: |
151
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
535 m68k_disasm(inst, disasm_buf); |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
757
diff
changeset
|
536 fatal_error("%X: %s\naddress mode %d not implemented (%s)\n", inst->address, disasm_buf, op->addr_mode, dst ? "dst" : "src"); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
537 } |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
538 if (!dst && inst->dst.addr_mode == MODE_AREG && inst->extra.size == OPSIZE_WORD) { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
539 if (ea->mode == MODE_REG_DIRECT) { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
540 movsx_rr(code, ea->base, opts->gen.scratch1, SZ_W, SZ_D); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
541 } else { |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
542 movsx_rdispr(code, ea->base, ea->disp, opts->gen.scratch1, SZ_W, SZ_D); |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
543 ea->mode = MODE_REG_DIRECT; |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
544 } |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
545 ea->base = opts->gen.scratch1; |
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
546 } |
1363
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
547 return ret; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
548 } |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
549 |
687
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
550 void check_user_mode_swap_ssp_usp(m68k_options *opts) |
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
551 { |
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
552 code_info * code = &opts->gen.code; |
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
553 //Check if we've switched to user mode and swap stack pointers if needed |
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
554 bt_irdisp(code, 5, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
555 code_ptr end_off = code->cur + 1; |
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
556 jcc(code, CC_C, code->cur + 2); |
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
557 swap_ssp_usp(opts); |
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
558 *end_off = code->cur - (end_off + 1); |
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
559 } |
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
560 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
561 void translate_m68k_move(m68k_options * opts, m68kinst * inst) |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
562 { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
563 code_info *code = &opts->gen.code; |
99
8491de5d6c06
Allow use of indexed modes as move dst
Mike Pavone <pavone@retrodev.com>
parents:
98
diff
changeset
|
564 int8_t reg, flags_reg, sec_reg; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
565 uint8_t dir = 0; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
566 int32_t offset; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
567 int32_t inc_amount, dec_amount; |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
568 host_ea src; |
1370
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
569 uint8_t needs_int_latch = translate_m68k_op(inst, &src, opts, 0); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
570 reg = native_reg(&(inst->dst), opts); |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
571 |
216
0b5ec22dcda2
Fix some bugs related to sign-extension of address registers and pre-decrement amount for a7 when used as a source.
Mike Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
572 if (inst->dst.addr_mode != MODE_AREG) { |
0b5ec22dcda2
Fix some bugs related to sign-extension of address registers and pre-decrement amount for a7 when used as a source.
Mike Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
573 if (src.mode == MODE_REG_DIRECT) { |
0b5ec22dcda2
Fix some bugs related to sign-extension of address registers and pre-decrement amount for a7 when used as a source.
Mike Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
574 flags_reg = src.base; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
575 } else { |
216
0b5ec22dcda2
Fix some bugs related to sign-extension of address registers and pre-decrement amount for a7 when used as a source.
Mike Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
576 if (reg >= 0) { |
0b5ec22dcda2
Fix some bugs related to sign-extension of address registers and pre-decrement amount for a7 when used as a source.
Mike Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
577 flags_reg = reg; |
128
fe598ffd85ce
Cleanup bit instructions and fix bug in translate_m68k_move that caused incorrect results once translate_m68k_src was fixed
Mike Pavone <pavone@retrodev.com>
parents:
126
diff
changeset
|
578 } else { |
216
0b5ec22dcda2
Fix some bugs related to sign-extension of address registers and pre-decrement amount for a7 when used as a source.
Mike Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
579 if(src.mode == MODE_REG_DISPLACE8) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
580 mov_rdispr(code, src.base, src.disp, opts->gen.scratch1, inst->extra.size); |
216
0b5ec22dcda2
Fix some bugs related to sign-extension of address registers and pre-decrement amount for a7 when used as a source.
Mike Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
581 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
582 mov_ir(code, src.disp, opts->gen.scratch1, inst->extra.size); |
216
0b5ec22dcda2
Fix some bugs related to sign-extension of address registers and pre-decrement amount for a7 when used as a source.
Mike Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
583 } |
0b5ec22dcda2
Fix some bugs related to sign-extension of address registers and pre-decrement amount for a7 when used as a source.
Mike Pavone <pavone@retrodev.com>
parents:
213
diff
changeset
|
584 src.mode = MODE_REG_DIRECT; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
585 flags_reg = src.base = opts->gen.scratch1; |
128
fe598ffd85ce
Cleanup bit instructions and fix bug in translate_m68k_move that caused incorrect results once translate_m68k_src was fixed
Mike Pavone <pavone@retrodev.com>
parents:
126
diff
changeset
|
586 } |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
587 } |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
588 } |
181
3b4ef459aa8d
Fix signed division with negative result, fix address reg destination with word-sized operand, fix cmpm decoding and code generation, fix unbalanced pop in bit instructions
Mike Pavone <pavone@retrodev.com>
parents:
179
diff
changeset
|
589 uint8_t size = inst->extra.size; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
590 switch(inst->dst.addr_mode) |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
591 { |
181
3b4ef459aa8d
Fix signed division with negative result, fix address reg destination with word-sized operand, fix cmpm decoding and code generation, fix unbalanced pop in bit instructions
Mike Pavone <pavone@retrodev.com>
parents:
179
diff
changeset
|
592 case MODE_AREG: |
3b4ef459aa8d
Fix signed division with negative result, fix address reg destination with word-sized operand, fix cmpm decoding and code generation, fix unbalanced pop in bit instructions
Mike Pavone <pavone@retrodev.com>
parents:
179
diff
changeset
|
593 size = OPSIZE_LONG; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
594 case MODE_REG: |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
595 if (reg >= 0) { |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
596 if (src.mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
597 mov_rr(code, src.base, reg, size); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
598 } else if (src.mode == MODE_REG_DISPLACE8) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
599 mov_rdispr(code, src.base, src.disp, reg, size); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
600 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
601 mov_ir(code, src.disp, reg, size); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
602 } |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
603 } else if(src.mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
604 mov_rrdisp(code, src.base, opts->gen.context_reg, reg_offset(&(inst->dst)), size); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
605 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
606 mov_irdisp(code, src.disp, opts->gen.context_reg, reg_offset(&(inst->dst)), size); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
607 } |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
608 break; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
609 case MODE_AREG_PREDEC: |
182
924af8b2f7a0
Fix -(a7) dest when size is byte
Mike Pavone <pavone@retrodev.com>
parents:
181
diff
changeset
|
610 dec_amount = inst->extra.size == OPSIZE_WORD ? 2 : (inst->extra.size == OPSIZE_LONG ? 4 : (inst->dst.params.regs.pri == 7 ? 2 : 1)); |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
611 case MODE_AREG_INDIRECT: |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
612 case MODE_AREG_POSTINC: |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
613 if (src.mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
614 if (src.base != opts->gen.scratch1) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
615 mov_rr(code, src.base, opts->gen.scratch1, inst->extra.size); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
616 } |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
617 } else if (src.mode == MODE_REG_DISPLACE8) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
618 mov_rdispr(code, src.base, src.disp, opts->gen.scratch1, inst->extra.size); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
619 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
620 mov_ir(code, src.disp, opts->gen.scratch1, inst->extra.size); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
621 } |
610
314373222b1a
Decrement address register after fetching source in move with -(ax) dest to avoid bug when src is the dst addres reg
Michael Pavone <pavone@retrodev.com>
parents:
605
diff
changeset
|
622 if (inst->dst.addr_mode == MODE_AREG_PREDEC) { |
314373222b1a
Decrement address register after fetching source in move with -(ax) dest to avoid bug when src is the dst addres reg
Michael Pavone <pavone@retrodev.com>
parents:
605
diff
changeset
|
623 subi_areg(opts, dec_amount, inst->dst.params.regs.pri); |
314373222b1a
Decrement address register after fetching source in move with -(ax) dest to avoid bug when src is the dst addres reg
Michael Pavone <pavone@retrodev.com>
parents:
605
diff
changeset
|
624 } |
314373222b1a
Decrement address register after fetching source in move with -(ax) dest to avoid bug when src is the dst addres reg
Michael Pavone <pavone@retrodev.com>
parents:
605
diff
changeset
|
625 areg_to_native(opts, inst->dst.params.regs.pri, opts->gen.scratch2); |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
626 break; |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
627 case MODE_AREG_DISPLACE: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
628 cycles(&opts->gen, BUS); |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
629 calc_areg_displace(opts, &inst->dst, opts->gen.scratch2); |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
630 if (src.mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
631 if (src.base != opts->gen.scratch1) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
632 mov_rr(code, src.base, opts->gen.scratch1, inst->extra.size); |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
633 } |
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
634 } else if (src.mode == MODE_REG_DISPLACE8) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
635 mov_rdispr(code, src.base, src.disp, opts->gen.scratch1, inst->extra.size); |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
636 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
637 mov_ir(code, src.disp, opts->gen.scratch1, inst->extra.size); |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
638 } |
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
639 break; |
99
8491de5d6c06
Allow use of indexed modes as move dst
Mike Pavone <pavone@retrodev.com>
parents:
98
diff
changeset
|
640 case MODE_AREG_INDEX_DISP8: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
641 cycles(&opts->gen, 6);//TODO: Check to make sure this is correct |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
642 //calc_areg_index_disp8 will clober scratch1 when a 16-bit index is used |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
643 if (src.base == opts->gen.scratch1 && !(inst->dst.params.regs.sec & 1)) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
644 push_r(code, opts->gen.scratch1); |
99
8491de5d6c06
Allow use of indexed modes as move dst
Mike Pavone <pavone@retrodev.com>
parents:
98
diff
changeset
|
645 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
646 calc_areg_index_disp8(opts, &inst->dst, opts->gen.scratch2); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
647 if (src.base == opts->gen.scratch1 && !(inst->dst.params.regs.sec & 1)) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
648 pop_r(code, opts->gen.scratch1); |
99
8491de5d6c06
Allow use of indexed modes as move dst
Mike Pavone <pavone@retrodev.com>
parents:
98
diff
changeset
|
649 } |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
183
diff
changeset
|
650 if (src.mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
651 if (src.base != opts->gen.scratch1) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
652 mov_rr(code, src.base, opts->gen.scratch1, inst->extra.size); |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
183
diff
changeset
|
653 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
183
diff
changeset
|
654 } else if (src.mode == MODE_REG_DISPLACE8) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
655 mov_rdispr(code, src.base, src.disp, opts->gen.scratch1, inst->extra.size); |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
183
diff
changeset
|
656 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
657 mov_ir(code, src.disp, opts->gen.scratch1, inst->extra.size); |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
183
diff
changeset
|
658 } |
99
8491de5d6c06
Allow use of indexed modes as move dst
Mike Pavone <pavone@retrodev.com>
parents:
98
diff
changeset
|
659 break; |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
660 case MODE_PC_DISPLACE: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
661 cycles(&opts->gen, BUS); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
662 mov_ir(code, inst->dst.params.regs.displacement + inst->address+2, opts->gen.scratch2, SZ_D); |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
663 if (src.mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
664 if (src.base != opts->gen.scratch1) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
665 mov_rr(code, src.base, opts->gen.scratch1, inst->extra.size); |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
666 } |
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
667 } else if (src.mode == MODE_REG_DISPLACE8) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
668 mov_rdispr(code, src.base, src.disp, opts->gen.scratch1, inst->extra.size); |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
669 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
670 mov_ir(code, src.disp, opts->gen.scratch1, inst->extra.size); |
71
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
671 } |
f80fa1776507
Implement more instructions and address modes
Mike Pavone <pavone@retrodev.com>
parents:
70
diff
changeset
|
672 break; |
196
f8955d33486d
Implement pc indexed mode as move dst
Mike Pavone <pavone@retrodev.com>
parents:
194
diff
changeset
|
673 case MODE_PC_INDEX_DISP8: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
674 cycles(&opts->gen, 6);//TODO: Check to make sure this is correct |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
675 mov_ir(code, inst->address, opts->gen.scratch2, SZ_D); |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
676 if (src.base == opts->gen.scratch1 && !(inst->dst.params.regs.sec & 1)) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
677 push_r(code, opts->gen.scratch1); |
689
858e31f977ae
A couple more indentation fixes
Michael Pavone <pavone@retrodev.com>
parents:
688
diff
changeset
|
678 } |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
679 calc_index_disp8(opts, &inst->dst, opts->gen.scratch2); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
680 if (src.base == opts->gen.scratch1 && !(inst->dst.params.regs.sec & 1)) { |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
681 pop_r(code, opts->gen.scratch1); |
196
f8955d33486d
Implement pc indexed mode as move dst
Mike Pavone <pavone@retrodev.com>
parents:
194
diff
changeset
|
682 } |
f8955d33486d
Implement pc indexed mode as move dst
Mike Pavone <pavone@retrodev.com>
parents:
194
diff
changeset
|
683 if (src.mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
684 if (src.base != opts->gen.scratch1) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
685 mov_rr(code, src.base, opts->gen.scratch1, inst->extra.size); |
196
f8955d33486d
Implement pc indexed mode as move dst
Mike Pavone <pavone@retrodev.com>
parents:
194
diff
changeset
|
686 } |
f8955d33486d
Implement pc indexed mode as move dst
Mike Pavone <pavone@retrodev.com>
parents:
194
diff
changeset
|
687 } else if (src.mode == MODE_REG_DISPLACE8) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
688 mov_rdispr(code, src.base, src.disp, opts->gen.scratch1, inst->extra.size); |
196
f8955d33486d
Implement pc indexed mode as move dst
Mike Pavone <pavone@retrodev.com>
parents:
194
diff
changeset
|
689 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
690 mov_ir(code, src.disp, opts->gen.scratch1, inst->extra.size); |
196
f8955d33486d
Implement pc indexed mode as move dst
Mike Pavone <pavone@retrodev.com>
parents:
194
diff
changeset
|
691 } |
f8955d33486d
Implement pc indexed mode as move dst
Mike Pavone <pavone@retrodev.com>
parents:
194
diff
changeset
|
692 break; |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
693 case MODE_ABSOLUTE: |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
694 case MODE_ABSOLUTE_SHORT: |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
695 if (src.mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
696 if (src.base != opts->gen.scratch1) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
697 mov_rr(code, src.base, opts->gen.scratch1, inst->extra.size); |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
698 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
699 } else if (src.mode == MODE_REG_DISPLACE8) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
700 mov_rdispr(code, src.base, src.disp, opts->gen.scratch1, inst->extra.size); |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
701 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
702 mov_ir(code, src.disp, opts->gen.scratch1, inst->extra.size); |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
703 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
704 if (inst->dst.addr_mode == MODE_ABSOLUTE) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
705 cycles(&opts->gen, BUS*2); |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
706 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
707 cycles(&opts->gen, BUS); |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
183
diff
changeset
|
708 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
709 mov_ir(code, inst->dst.params.immed, opts->gen.scratch2, SZ_D); |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
53
diff
changeset
|
710 break; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
711 default: |
151
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
712 m68k_disasm(inst, disasm_buf); |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
757
diff
changeset
|
713 fatal_error("%X: %s\naddress mode %d not implemented (move dst)\n", inst->address, disasm_buf, inst->dst.addr_mode); |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
714 } |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
715 |
576
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
716 if (inst->dst.addr_mode != MODE_AREG) { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
717 cmp_ir(code, 0, flags_reg, inst->extra.size); |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
718 update_flags(opts, N|Z|V0|C0); |
689
858e31f977ae
A couple more indentation fixes
Michael Pavone <pavone@retrodev.com>
parents:
688
diff
changeset
|
719 } |
576
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
720 if (inst->dst.addr_mode != MODE_REG && inst->dst.addr_mode != MODE_AREG) { |
1370
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
721 if (inst->extra.size == OPSIZE_LONG) { |
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
722 //We want the int latch to occur between the two writes, |
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
723 //but that's a pain to do without refactoring how 32-bit writes work |
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
724 //workaround it by temporarily increasing the cycle count before the check |
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
725 cycles(&opts->gen, BUS); |
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
726 } |
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
727 m68k_check_cycles_int_latch(opts); |
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
728 if (inst->extra.size == OPSIZE_LONG) { |
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
729 //and then backing out that extra increment here before the write happens |
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
730 cycles(&opts->gen, -BUS); |
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
731 } |
979
771875b5f519
Fix order of writes for move.l with a predec destination
Michael Pavone <pavone@retrodev.com>
parents:
976
diff
changeset
|
732 m68k_write_size(opts, inst->extra.size, inst->dst.addr_mode == MODE_AREG_PREDEC); |
576
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
733 if (inst->dst.addr_mode == MODE_AREG_POSTINC) { |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
734 inc_amount = inst->extra.size == OPSIZE_WORD ? 2 : (inst->extra.size == OPSIZE_LONG ? 4 : (inst->dst.params.regs.pri == 7 ? 2 : 1)); |
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
735 addi_areg(opts, inc_amount, inst->dst.params.regs.pri); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
736 } |
1375
b68732dcbf00
Avoid splitting m68k_check_cycles_int_latch code across memory chunks since it expects a byte-sized jump offset. Avoid an unnecessary m68k_check_cycles_int_latch for register to register moves
Michael Pavone <pavone@retrodev.com>
parents:
1370
diff
changeset
|
737 } else if (needs_int_latch) { |
1370
eaca4443e831
Fix interrupt latency for move.l with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1363
diff
changeset
|
738 m68k_check_cycles_int_latch(opts); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
739 } |
576
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
740 |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
741 //add cycles for prefetch |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
742 cycles(&opts->gen, BUS); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
743 } |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
744 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
745 void translate_m68k_ext(m68k_options * opts, m68kinst * inst) |
93
f63b0e58e2d5
Implement EXT, add some fixes to LINK/UNLK
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
746 { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
747 code_info *code = &opts->gen.code; |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
748 host_ea dst_op; |
93
f63b0e58e2d5
Implement EXT, add some fixes to LINK/UNLK
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
749 uint8_t dst_size = inst->extra.size; |
f63b0e58e2d5
Implement EXT, add some fixes to LINK/UNLK
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
750 inst->extra.size--; |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
751 translate_m68k_op(inst, &dst_op, opts, 1); |
93
f63b0e58e2d5
Implement EXT, add some fixes to LINK/UNLK
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
752 if (dst_op.mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
753 movsx_rr(code, dst_op.base, dst_op.base, inst->extra.size, dst_size); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
754 cmp_ir(code, 0, dst_op.base, dst_size); |
93
f63b0e58e2d5
Implement EXT, add some fixes to LINK/UNLK
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
755 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
756 movsx_rdispr(code, dst_op.base, dst_op.disp, opts->gen.scratch1, inst->extra.size, dst_size); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
757 cmp_ir(code, 0, opts->gen.scratch1, dst_size); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
758 mov_rrdisp(code, opts->gen.scratch1, dst_op.base, dst_op.disp, dst_size); |
93
f63b0e58e2d5
Implement EXT, add some fixes to LINK/UNLK
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
759 } |
f63b0e58e2d5
Implement EXT, add some fixes to LINK/UNLK
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
760 inst->extra.size = dst_size; |
576
a6f2db4df70d
Small refactor to flag handling in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
574
diff
changeset
|
761 update_flags(opts, N|V0|C0|Z); |
1584
e01adbe1a75b
Fix instruction timing for a number of instructions with only a single operand
Michael Pavone <pavone@retrodev.com>
parents:
1510
diff
changeset
|
762 cycles(&opts->gen, BUS); |
93
f63b0e58e2d5
Implement EXT, add some fixes to LINK/UNLK
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
763 //M68K EXT only operates on registers so no need for a call to save result here |
f63b0e58e2d5
Implement EXT, add some fixes to LINK/UNLK
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
764 } |
f63b0e58e2d5
Implement EXT, add some fixes to LINK/UNLK
Mike Pavone <pavone@retrodev.com>
parents:
92
diff
changeset
|
765 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
766 uint8_t m68k_eval_cond(m68k_options * opts, uint8_t cc) |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
767 { |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
768 uint8_t cond = CC_NZ; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
769 switch (cc) |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
770 { |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
771 case COND_HIGH: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
772 cond = CC_Z; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
773 case COND_LOW_SAME: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
774 flag_to_reg(opts, FLAG_Z, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
775 or_flag_to_reg(opts, FLAG_C, opts->gen.scratch1); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
776 break; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
777 case COND_CARRY_CLR: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
778 cond = CC_Z; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
779 case COND_CARRY_SET: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
780 check_flag(opts, FLAG_C); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
781 break; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
782 case COND_NOT_EQ: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
783 cond = CC_Z; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
784 case COND_EQ: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
785 check_flag(opts, FLAG_Z); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
786 break; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
787 case COND_OVERF_CLR: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
788 cond = CC_Z; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
789 case COND_OVERF_SET: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
790 check_flag(opts, FLAG_V); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
791 break; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
792 case COND_PLUS: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
793 cond = CC_Z; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
794 case COND_MINUS: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
795 check_flag(opts, FLAG_N); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
796 break; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
797 case COND_GREATER_EQ: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
798 cond = CC_Z; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
799 case COND_LESS: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
800 cmp_flags(opts, FLAG_N, FLAG_V); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
801 break; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
802 case COND_GREATER: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
803 cond = CC_Z; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
804 case COND_LESS_EQ: |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
805 flag_to_reg(opts, FLAG_V, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
806 xor_flag_to_reg(opts, FLAG_N, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
807 or_flag_to_reg(opts, FLAG_Z, opts->gen.scratch1); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
808 break; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
809 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
810 return cond; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
811 } |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
812 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
813 void translate_m68k_bcc(m68k_options * opts, m68kinst * inst) |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
814 { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
815 code_info *code = &opts->gen.code; |
1332
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
816 |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
817 int32_t disp = inst->src.params.immed; |
46
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
818 uint32_t after = inst->address + 2; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
819 if (inst->extra.cond == COND_TRUE) { |
1332
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
820 cycles(&opts->gen, 10); |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
821 jump_m68k_abs(opts, after + disp); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
822 } else { |
1332
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
823 uint8_t cond = m68k_eval_cond(opts, inst->extra.cond); |
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
824 code_ptr do_branch = code->cur + 1; |
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
825 jcc(code, cond, do_branch); |
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
826 |
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
827 cycles(&opts->gen, inst->variant == VAR_BYTE ? 8 : 12); |
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
828 code_ptr done = code->cur + 1; |
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
829 jmp(code, done); |
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
830 |
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
831 *do_branch = code->cur - (do_branch + 1); |
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
832 cycles(&opts->gen, 10); |
726
7367b14ac01c
Don't attempt to translate or map code at odd addresses. This fixes a bug that shows up when playing College Footbal USA 96
Michael Pavone <pavone@retrodev.com>
parents:
698
diff
changeset
|
833 code_ptr dest_addr = get_native_address(opts, after + disp); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
834 if (!dest_addr) { |
1332
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
835 opts->gen.deferred = defer_address(opts->gen.deferred, after + disp, code->cur + 1); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
836 //dummy address to be replaced later, make sure it generates a 4-byte displacement |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
837 dest_addr = code->cur + 256; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
838 } |
1332
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
839 jmp(code, dest_addr); |
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
840 |
87bbc4bec958
Fix timing for branch not taken case in the M68K BCC intruction
Michael Pavone <pavone@retrodev.com>
parents:
1329
diff
changeset
|
841 *done = code->cur - (done + 1); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
842 } |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
843 } |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
844 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
845 void translate_m68k_scc(m68k_options * opts, m68kinst * inst) |
112 | 846 { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
847 code_info *code = &opts->gen.code; |
112 | 848 uint8_t cond = inst->extra.cond; |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
849 host_ea dst_op; |
112 | 850 inst->extra.size = OPSIZE_BYTE; |
571
c90fc522e7e3
Refactor translat_m68k_src and translate_m68k_dst into a single function
Michael Pavone <pavone@retrodev.com>
parents:
570
diff
changeset
|
851 translate_m68k_op(inst, &dst_op, opts, 1); |
112 | 852 if (cond == COND_TRUE || cond == COND_FALSE) { |
853 if ((inst->dst.addr_mode == MODE_REG || inst->dst.addr_mode == MODE_AREG) && inst->extra.cond == COND_TRUE) { | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
854 cycles(&opts->gen, 6); |
112 | 855 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
856 cycles(&opts->gen, BUS); |
112 | 857 } |
858 if (dst_op.mode == MODE_REG_DIRECT) { | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
859 mov_ir(code, cond == COND_TRUE ? 0xFF : 0, dst_op.base, SZ_B); |
112 | 860 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
861 mov_irdisp(code, cond == COND_TRUE ? 0xFF : 0, dst_op.base, dst_op.disp, SZ_B); |
112 | 862 } |
863 } else { | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
864 uint8_t cc = m68k_eval_cond(opts, cond); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
865 check_alloc_code(code, 6*MAX_INST_LEN); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
866 code_ptr true_off = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
867 jcc(code, cc, code->cur+2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
868 cycles(&opts->gen, BUS); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
869 if (dst_op.mode == MODE_REG_DIRECT) { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
870 mov_ir(code, 0, dst_op.base, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
871 } else { |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
872 mov_irdisp(code, 0, dst_op.base, dst_op.disp, SZ_B); |
112 | 873 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
874 code_ptr end_off = code->cur+1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
875 jmp(code, code->cur+2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
876 *true_off = code->cur - (true_off+1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
877 cycles(&opts->gen, 6); |
179
68af8a56ab7a
Fix scc to set reg to 0xFF rather than 1 when the condition is true
Mike Pavone <pavone@retrodev.com>
parents:
178
diff
changeset
|
878 if (dst_op.mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
879 mov_ir(code, 0xFF, dst_op.base, SZ_B); |
112 | 880 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
881 mov_irdisp(code, 0xFF, dst_op.base, dst_op.disp, SZ_B); |
112 | 882 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
883 *end_off = code->cur - (end_off+1); |
112 | 884 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
885 m68k_save_result(inst, opts); |
112 | 886 } |
887 | |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
888 void translate_m68k_dbcc(m68k_options * opts, m68kinst * inst) |
46
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
889 { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
890 code_info *code = &opts->gen.code; |
46
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
891 //best case duration |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
892 cycles(&opts->gen, 10); |
558
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
893 code_ptr skip_loc = NULL; |
46
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
894 //TODO: Check if COND_TRUE technically valid here even though |
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
895 //it's basically a slow NOP |
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
896 if (inst->extra.cond != COND_FALSE) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
897 uint8_t cond = m68k_eval_cond(opts, inst->extra.cond); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
898 check_alloc_code(code, 6*MAX_INST_LEN); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
899 skip_loc = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
900 jcc(code, cond, code->cur + 2); |
46
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
901 } |
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
902 if (opts->dregs[inst->dst.params.regs.pri] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
903 sub_ir(code, 1, opts->dregs[inst->dst.params.regs.pri], SZ_W); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
904 cmp_ir(code, -1, opts->dregs[inst->dst.params.regs.pri], SZ_W); |
46
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
905 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
906 sub_irdisp(code, 1, opts->gen.context_reg, offsetof(m68k_context, dregs) + 4 * inst->dst.params.regs.pri, SZ_W); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
907 cmp_irdisp(code, -1, opts->gen.context_reg, offsetof(m68k_context, dregs) + 4 * inst->dst.params.regs.pri, SZ_W); |
46
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
908 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
909 code_ptr loop_end_loc = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
910 jcc(code, CC_Z, code->cur + 2); |
46
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
911 uint32_t after = inst->address + 2; |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
912 jump_m68k_abs(opts, after + inst->src.params.immed); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
913 *loop_end_loc = code->cur - (loop_end_loc+1); |
46
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
914 if (skip_loc) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
915 cycles(&opts->gen, 2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
916 *skip_loc = code->cur - (skip_loc+1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
917 cycles(&opts->gen, 2); |
46
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
918 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
919 cycles(&opts->gen, 4); |
46
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
920 } |
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
921 } |
f2aaaf36c875
Add support for dbcc instruction
Mike Pavone <pavone@retrodev.com>
parents:
19
diff
changeset
|
922 |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
923 void translate_m68k_movep(m68k_options * opts, m68kinst * inst) |
172 | 924 { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
925 code_info *code = &opts->gen.code; |
172 | 926 int8_t reg; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
927 cycles(&opts->gen, BUS*2); |
172 | 928 if (inst->src.addr_mode == MODE_REG) { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
929 calc_areg_displace(opts, &inst->dst, opts->gen.scratch2); |
172 | 930 reg = native_reg(&(inst->src), opts); |
931 if (inst->extra.size == OPSIZE_LONG) { | |
932 if (reg >= 0) { | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
933 mov_rr(code, reg, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
934 shr_ir(code, 24, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
935 push_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
936 call(code, opts->write_8); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
937 pop_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
938 mov_rr(code, reg, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
939 shr_ir(code, 16, opts->gen.scratch1, SZ_D); |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
940 |
172 | 941 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
942 mov_rdispr(code, opts->gen.context_reg, reg_offset(&(inst->src))+3, opts->gen.scratch1, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
943 push_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
944 call(code, opts->write_8); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
945 pop_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
946 mov_rdispr(code, opts->gen.context_reg, reg_offset(&(inst->src))+2, opts->gen.scratch1, SZ_B); |
172 | 947 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
948 add_ir(code, 2, opts->gen.scratch2, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
949 push_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
950 call(code, opts->write_8); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
951 pop_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
952 add_ir(code, 2, opts->gen.scratch2, SZ_D); |
172 | 953 } |
954 if (reg >= 0) { | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
955 mov_rr(code, reg, opts->gen.scratch1, SZ_W); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
956 shr_ir(code, 8, opts->gen.scratch1, SZ_W); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
957 push_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
958 call(code, opts->write_8); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
959 pop_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
960 mov_rr(code, reg, opts->gen.scratch1, SZ_W); |
172 | 961 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
962 mov_rdispr(code, opts->gen.context_reg, reg_offset(&(inst->src))+1, opts->gen.scratch1, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
963 push_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
964 call(code, opts->write_8); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
965 pop_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
966 mov_rdispr(code, opts->gen.context_reg, reg_offset(&(inst->src)), opts->gen.scratch1, SZ_B); |
172 | 967 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
968 add_ir(code, 2, opts->gen.scratch2, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
969 call(code, opts->write_8); |
172 | 970 } else { |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
971 calc_areg_displace(opts, &inst->src, opts->gen.scratch1); |
172 | 972 reg = native_reg(&(inst->dst), opts); |
973 if (inst->extra.size == OPSIZE_LONG) { | |
974 if (reg >= 0) { | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
975 push_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
976 call(code, opts->read_8); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
977 shl_ir(code, 24, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
978 mov_rr(code, opts->gen.scratch1, reg, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
979 pop_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
980 add_ir(code, 2, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
981 push_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
982 call(code, opts->read_8); |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
996
diff
changeset
|
983 movzx_rr(code, opts->gen.scratch1, opts->gen.scratch1, SZ_B, SZ_W); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
984 shl_ir(code, 16, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
985 or_rr(code, opts->gen.scratch1, reg, SZ_D); |
172 | 986 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
987 push_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
988 call(code, opts->read_8); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
989 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, reg_offset(&(inst->dst))+3, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
990 pop_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
991 add_ir(code, 2, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
992 push_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
993 call(code, opts->read_8); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
994 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, reg_offset(&(inst->dst))+2, SZ_B); |
172 | 995 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
996 pop_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
997 add_ir(code, 2, opts->gen.scratch1, SZ_D); |
172 | 998 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
999 push_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1000 call(code, opts->read_8); |
172 | 1001 if (reg >= 0) { |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
1002 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1003 shl_ir(code, 8, opts->gen.scratch1, SZ_W); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1004 mov_rr(code, opts->gen.scratch1, reg, SZ_W); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1005 pop_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1006 add_ir(code, 2, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1007 call(code, opts->read_8); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1008 mov_rr(code, opts->gen.scratch1, reg, SZ_B); |
172 | 1009 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1010 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, reg_offset(&(inst->dst))+1, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1011 pop_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1012 add_ir(code, 2, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1013 call(code, opts->read_8); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1014 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, reg_offset(&(inst->dst)), SZ_B); |
172 | 1015 } |
1016 } | |
1017 } | |
1018 | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1019 typedef void (*shift_ir_t)(code_info *code, uint8_t val, uint8_t dst, uint8_t size); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1020 typedef void (*shift_irdisp_t)(code_info *code, uint8_t val, uint8_t dst_base, int32_t disp, uint8_t size); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1021 typedef void (*shift_clr_t)(code_info *code, uint8_t dst, uint8_t size); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1022 typedef void (*shift_clrdisp_t)(code_info *code, uint8_t dst_base, int32_t disp, uint8_t size); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1023 |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1024 void translate_shift(m68k_options * opts, m68kinst * inst, host_ea *src_op, host_ea * dst_op, shift_ir_t shift_ir, shift_irdisp_t shift_irdisp, shift_clr_t shift_clr, shift_clrdisp_t shift_clrdisp, shift_ir_t special, shift_irdisp_t special_disp) |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1025 { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1026 code_info *code = &opts->gen.code; |
558
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
1027 code_ptr end_off = NULL; |
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
1028 code_ptr nz_off = NULL; |
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
1029 code_ptr z_off = NULL; |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1030 if (inst->src.addr_mode == MODE_UNUSED) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1031 cycles(&opts->gen, BUS); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1032 //Memory shift |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1033 shift_ir(code, 1, dst_op->base, SZ_W); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1034 } else { |
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1035 if (src_op->mode == MODE_IMMED) { |
667
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
1036 cycles(&opts->gen, (inst->extra.size == OPSIZE_LONG ? 8 : 6) + 2 * src_op->disp); |
207 | 1037 if (src_op->disp != 1 && inst->op == M68K_ASL) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1038 set_flag(opts, 0, FLAG_V); |
207 | 1039 for (int i = 0; i < src_op->disp; i++) { |
1040 if (dst_op->mode == MODE_REG_DIRECT) { | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1041 shift_ir(code, 1, dst_op->base, inst->extra.size); |
207 | 1042 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1043 shift_irdisp(code, 1, dst_op->base, dst_op->disp, inst->extra.size); |
207 | 1044 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1045 check_alloc_code(code, 2*MAX_INST_LEN); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1046 code_ptr after_flag_set = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1047 jcc(code, CC_NO, code->cur + 2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1048 set_flag(opts, 1, FLAG_V); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1049 *after_flag_set = code->cur - (after_flag_set+1); |
207 | 1050 } |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1051 } else { |
207 | 1052 if (dst_op->mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1053 shift_ir(code, src_op->disp, dst_op->base, inst->extra.size); |
207 | 1054 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1055 shift_irdisp(code, src_op->disp, dst_op->base, dst_op->disp, inst->extra.size); |
207 | 1056 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1057 set_flag_cond(opts, CC_O, FLAG_V); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1058 } |
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1059 } else { |
667
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
1060 cycles(&opts->gen, inst->extra.size == OPSIZE_LONG ? 8 : 6); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1061 if (src_op->base != RCX) { |
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1062 if (src_op->mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1063 mov_rr(code, src_op->base, RCX, SZ_B); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1064 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1065 mov_rdispr(code, src_op->base, src_op->disp, RCX, SZ_B); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1066 } |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
1067 |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1068 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1069 and_ir(code, 63, RCX, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1070 check_alloc_code(code, 7*MAX_INST_LEN); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1071 nz_off = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1072 jcc(code, CC_NZ, code->cur + 2); |
207 | 1073 //Flag behavior for shift count of 0 is different for x86 than 68K |
1074 if (dst_op->mode == MODE_REG_DIRECT) { | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1075 cmp_ir(code, 0, dst_op->base, inst->extra.size); |
207 | 1076 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1077 cmp_irdisp(code, 0, dst_op->base, dst_op->disp, inst->extra.size); |
207 | 1078 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1079 set_flag_cond(opts, CC_Z, FLAG_Z); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1080 set_flag_cond(opts, CC_S, FLAG_N); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1081 set_flag(opts, 0, FLAG_C); |
207 | 1082 //For other instructions, this flag will be set below |
1083 if (inst->op == M68K_ASL) { | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1084 set_flag(opts, 0, FLAG_V); |
207 | 1085 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1086 z_off = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1087 jmp(code, code->cur + 2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1088 *nz_off = code->cur - (nz_off + 1); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1089 //add 2 cycles for every bit shifted |
667
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
1090 mov_ir(code, 2 * opts->gen.clock_divider, opts->gen.scratch2, SZ_D); |
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
1091 imul_rr(code, RCX, opts->gen.scratch2, SZ_D); |
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
1092 add_rr(code, opts->gen.scratch2, opts->gen.cycles, SZ_D); |
207 | 1093 if (inst->op == M68K_ASL) { |
1094 //ASL has Overflow flag behavior that depends on all of the bits shifted through the MSB | |
1095 //Easiest way to deal with this is to shift one bit at a time | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1096 set_flag(opts, 0, FLAG_V); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1097 check_alloc_code(code, 5*MAX_INST_LEN); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1098 code_ptr loop_start = code->cur; |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1099 if (dst_op->mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1100 shift_ir(code, 1, dst_op->base, inst->extra.size); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1101 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1102 shift_irdisp(code, 1, dst_op->base, dst_op->disp, inst->extra.size); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1103 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1104 code_ptr after_flag_set = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1105 jcc(code, CC_NO, code->cur + 2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1106 set_flag(opts, 1, FLAG_V); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1107 *after_flag_set = code->cur - (after_flag_set+1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1108 loop(code, loop_start); |
207 | 1109 } else { |
1110 //x86 shifts modulo 32 for operand sizes less than 64-bits | |
1111 //but M68K shifts modulo 64, so we need to check for large shifts here | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1112 cmp_ir(code, 32, RCX, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1113 check_alloc_code(code, 14*MAX_INST_LEN); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1114 code_ptr norm_shift_off = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1115 jcc(code, CC_L, code->cur + 2); |
207 | 1116 if (special) { |
558
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
1117 code_ptr after_flag_set = NULL; |
207 | 1118 if (inst->extra.size == OPSIZE_LONG) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1119 code_ptr neq_32_off = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1120 jcc(code, CC_NZ, code->cur + 2); |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
1121 |
207 | 1122 //set the carry bit to the lsb |
1123 if (dst_op->mode == MODE_REG_DIRECT) { | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1124 special(code, 1, dst_op->base, SZ_D); |
207 | 1125 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1126 special_disp(code, 1, dst_op->base, dst_op->disp, SZ_D); |
207 | 1127 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1128 set_flag_cond(opts, CC_C, FLAG_C); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1129 after_flag_set = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1130 jmp(code, code->cur + 2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1131 *neq_32_off = code->cur - (neq_32_off+1); |
207 | 1132 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1133 set_flag(opts, 0, FLAG_C); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
1134 if (after_flag_set) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1135 *after_flag_set = code->cur - (after_flag_set+1); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
1136 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1137 set_flag(opts, 1, FLAG_Z); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1138 set_flag(opts, 0, FLAG_N); |
207 | 1139 if (dst_op->mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1140 xor_rr(code, dst_op->base, dst_op->base, inst->extra.size); |
207 | 1141 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1142 mov_irdisp(code, 0, dst_op->base, dst_op->disp, inst->extra.size); |
207 | 1143 } |
1144 } else { | |
1145 if (dst_op->mode == MODE_REG_DIRECT) { | |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1146 shift_ir(code, 31, dst_op->base, inst->extra.size); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1147 shift_ir(code, 1, dst_op->base, inst->extra.size); |
207 | 1148 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1149 shift_irdisp(code, 31, dst_op->base, dst_op->disp, inst->extra.size); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1150 shift_irdisp(code, 1, dst_op->base, dst_op->disp, inst->extra.size); |
207 | 1151 } |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
1152 |
207 | 1153 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1154 end_off = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1155 jmp(code, code->cur + 2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1156 *norm_shift_off = code->cur - (norm_shift_off+1); |
207 | 1157 if (dst_op->mode == MODE_REG_DIRECT) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1158 shift_clr(code, dst_op->base, inst->extra.size); |
207 | 1159 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1160 shift_clrdisp(code, dst_op->base, dst_op->disp, inst->extra.size); |
207 | 1161 } |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1162 } |
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1163 } |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
1164 |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1165 } |
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1166 if (!special && end_off) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1167 *end_off = code->cur - (end_off + 1); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1168 } |
583
819921b76b4b
Use update_flags instead of individual set_flag calls in a few places
Michael Pavone <pavone@retrodev.com>
parents:
582
diff
changeset
|
1169 update_flags(opts, C|Z|N); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1170 if (special && end_off) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1171 *end_off = code->cur - (end_off + 1); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1172 } |
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1173 //set X flag to same as C flag |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
1174 if (opts->flag_regs[FLAG_C] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1175 flag_to_flag(opts, FLAG_C, FLAG_X); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
1176 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1177 set_flag_cond(opts, CC_C, FLAG_X); |
546
90aca661542b
Make references to flags in the M68K core respect the flag_regs options array so that flags can be moved out of registers for the 32-bit port. set/get ccr/sr still need to be updated to support this, but everything else should be done.
Michael Pavone <pavone@retrodev.com>
parents:
545
diff
changeset
|
1178 } |
207 | 1179 if (z_off) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1180 *z_off = code->cur - (z_off + 1); |
207 | 1181 } |
219
8d3c16071559
Fix overflow flag behavior for lsl/lsr/asr
Mike Pavone <pavone@retrodev.com>
parents:
218
diff
changeset
|
1182 if (inst->op != M68K_ASL) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1183 set_flag(opts, 0, FLAG_V); |
207 | 1184 } |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1185 if (inst->src.addr_mode == MODE_UNUSED) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
1186 m68k_save_result(inst, opts); |
51
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1187 } |
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1188 } |
937b47c9b79b
Implement shift instructions (asl, lsl, asr, lsr). Add flags to register printout. Fix minor bug in shift/rotate instruction decoding.
Mike Pavone <pavone@retrodev.com>
parents:
49
diff
changeset
|
1189 |
1082
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1190 void translate_m68k_reset(m68k_options *opts, m68kinst *inst) |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1191 { |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1192 code_info *code = &opts->gen.code; |
1585
15116d4fdf40
Fix cycle counts for BCD instructions, RESET, and MOVE from SR
Michael Pavone <pavone@retrodev.com>
parents:
1584
diff
changeset
|
1193 //RESET instructions take a long time to give peripherals time to reset themselves |
15116d4fdf40
Fix cycle counts for BCD instructions, RESET, and MOVE from SR
Michael Pavone <pavone@retrodev.com>
parents:
1584
diff
changeset
|
1194 cycles(&opts->gen, 132); |
1082
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1195 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, reset_handler), opts->gen.scratch1, SZ_PTR); |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1196 cmp_ir(code, 0, opts->gen.scratch1, SZ_PTR); |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1197 code_ptr no_reset_handler = code->cur + 1; |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1198 jcc(code, CC_Z, code->cur+2); |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1199 call(code, opts->gen.save_context); |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1200 call_args_r(code, opts->gen.scratch1, 1, opts->gen.context_reg); |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1201 mov_rr(code, RAX, opts->gen.context_reg, SZ_PTR); |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1202 call(code, opts->gen.load_context); |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1203 *no_reset_handler = code->cur - (no_reset_handler + 1); |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1204 } |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1205 |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1206 void op_ir(code_info *code, m68kinst *inst, int32_t val, uint8_t dst, uint8_t size) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1207 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1208 switch (inst->op) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1209 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1210 case M68K_ADD: add_ir(code, val, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1211 case M68K_ADDX: adc_ir(code, val, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1212 case M68K_AND: and_ir(code, val, dst, size); break; |
581
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1213 case M68K_BTST: bt_ir(code, val, dst, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1214 case M68K_BSET: bts_ir(code, val, dst, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1215 case M68K_BCLR: btr_ir(code, val, dst, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1216 case M68K_BCHG: btc_ir(code, val, dst, size); break; |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1217 case M68K_CMP: cmp_ir(code, val, dst, size); break; |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1218 case M68K_EOR: xor_ir(code, val, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1219 case M68K_OR: or_ir(code, val, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1220 case M68K_ROL: rol_ir(code, val, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1221 case M68K_ROR: ror_ir(code, val, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1222 case M68K_ROXL: rcl_ir(code, val, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1223 case M68K_ROXR: rcr_ir(code, val, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1224 case M68K_SUB: sub_ir(code, val, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1225 case M68K_SUBX: sbb_ir(code, val, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1226 } |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1227 } |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1228 |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1229 void op_irdisp(code_info *code, m68kinst *inst, int32_t val, uint8_t dst, int32_t disp, uint8_t size) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1230 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1231 switch (inst->op) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1232 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1233 case M68K_ADD: add_irdisp(code, val, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1234 case M68K_ADDX: adc_irdisp(code, val, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1235 case M68K_AND: and_irdisp(code, val, dst, disp, size); break; |
581
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1236 case M68K_BTST: bt_irdisp(code, val, dst, disp, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1237 case M68K_BSET: bts_irdisp(code, val, dst, disp, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1238 case M68K_BCLR: btr_irdisp(code, val, dst, disp, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1239 case M68K_BCHG: btc_irdisp(code, val, dst, disp, size); break; |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1240 case M68K_CMP: cmp_irdisp(code, val, dst, disp, size); break; |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1241 case M68K_EOR: xor_irdisp(code, val, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1242 case M68K_OR: or_irdisp(code, val, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1243 case M68K_ROL: rol_irdisp(code, val, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1244 case M68K_ROR: ror_irdisp(code, val, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1245 case M68K_ROXL: rcl_irdisp(code, val, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1246 case M68K_ROXR: rcr_irdisp(code, val, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1247 case M68K_SUB: sub_irdisp(code, val, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1248 case M68K_SUBX: sbb_irdisp(code, val, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1249 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1250 } |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1251 |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1252 void op_rr(code_info *code, m68kinst *inst, uint8_t src, uint8_t dst, uint8_t size) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1253 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1254 switch (inst->op) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1255 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1256 case M68K_ADD: add_rr(code, src, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1257 case M68K_ADDX: adc_rr(code, src, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1258 case M68K_AND: and_rr(code, src, dst, size); break; |
581
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1259 case M68K_BTST: bt_rr(code, src, dst, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1260 case M68K_BSET: bts_rr(code, src, dst, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1261 case M68K_BCLR: btr_rr(code, src, dst, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1262 case M68K_BCHG: btc_rr(code, src, dst, size); break; |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1263 case M68K_CMP: cmp_rr(code, src, dst, size); break; |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1264 case M68K_EOR: xor_rr(code, src, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1265 case M68K_OR: or_rr(code, src, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1266 case M68K_SUB: sub_rr(code, src, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1267 case M68K_SUBX: sbb_rr(code, src, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1268 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1269 } |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1270 |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1271 void op_rrdisp(code_info *code, m68kinst *inst, uint8_t src, uint8_t dst, int32_t disp, uint8_t size) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1272 { |
14
2bdad0f52f42
x86 code gen, initial work on translator
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1273 switch(inst->op) |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1274 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1275 case M68K_ADD: add_rrdisp(code, src, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1276 case M68K_ADDX: adc_rrdisp(code, src, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1277 case M68K_AND: and_rrdisp(code, src, dst, disp, size); break; |
581
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1278 case M68K_BTST: bt_rrdisp(code, src, dst, disp, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1279 case M68K_BSET: bts_rrdisp(code, src, dst, disp, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1280 case M68K_BCLR: btr_rrdisp(code, src, dst, disp, size); break; |
9f40aa5243c2
Combine implementations of lea and pea. Update bit instructions to use the op_ family of functions to simplify their implementation a bit.
Michael Pavone <pavone@retrodev.com>
parents:
580
diff
changeset
|
1281 case M68K_BCHG: btc_rrdisp(code, src, dst, disp, size); break; |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1282 case M68K_CMP: cmp_rrdisp(code, src, dst, disp, size); break; |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1283 case M68K_EOR: xor_rrdisp(code, src, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1284 case M68K_OR: or_rrdisp(code, src, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1285 case M68K_SUB: sub_rrdisp(code, src, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1286 case M68K_SUBX: sbb_rrdisp(code, src, dst, disp, size); break; |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1287 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1288 } |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1289 |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1290 void op_rdispr(code_info *code, m68kinst *inst, uint8_t src, int32_t disp, uint8_t dst, uint8_t size) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1291 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1292 switch (inst->op) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1293 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1294 case M68K_ADD: add_rdispr(code, src, disp, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1295 case M68K_ADDX: adc_rdispr(code, src, disp, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1296 case M68K_AND: and_rdispr(code, src, disp, dst, size); break; |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1297 case M68K_CMP: cmp_rdispr(code, src, disp, dst, size); break; |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1298 case M68K_EOR: xor_rdispr(code, src, disp, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1299 case M68K_OR: or_rdispr(code, src, disp, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1300 case M68K_SUB: sub_rdispr(code, src, disp, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1301 case M68K_SUBX: sbb_rdispr(code, src, disp, dst, size); break; |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1302 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1303 } |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1304 |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1305 void translate_m68k_arith(m68k_options *opts, m68kinst * inst, uint32_t flag_mask, host_ea *src_op, host_ea *dst_op) |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1306 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1307 code_info *code = &opts->gen.code; |
1219
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1308 uint8_t size = inst->dst.addr_mode == MODE_AREG ? OPSIZE_LONG : inst->extra.size; |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1309 |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1310 uint32_t numcycles; |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1311 if ((inst->op == M68K_ADDX || inst->op == M68K_SUBX) && inst->src.addr_mode != MODE_REG) { |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1312 numcycles = 6; |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1313 } else if (size == OPSIZE_LONG) { |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1314 if (inst->op == M68K_CMP) { |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1315 numcycles = 6; |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1316 } else if (inst->op == M68K_AND && inst->variant == VAR_IMMEDIATE) { |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1317 numcycles = 6; |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1318 } else if (inst->op == M68K_ADD && inst->dst.addr_mode == MODE_AREG && inst->extra.size == OPSIZE_WORD && inst->variant == VAR_QUICK) { |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1319 numcycles = 4; |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1320 } else if (inst->dst.addr_mode <= MODE_AREG) { |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1321 numcycles = inst->src.addr_mode <= MODE_AREG || inst->src.addr_mode == MODE_IMMEDIATE ? 8 : 6; |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1322 } else { |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1323 numcycles = 4; |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1324 } |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1325 } else { |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1326 numcycles = 4; |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1327 } |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1328 cycles(&opts->gen, numcycles); |
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1329 |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1330 if (inst->op == M68K_ADDX || inst->op == M68K_SUBX) { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1331 flag_to_carry(opts, FLAG_X); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1332 } |
1219
4399044adbef
Fix timing for instructions using BINARY_IMPL
Michael Pavone <pavone@retrodev.com>
parents:
1216
diff
changeset
|
1333 |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1334 if (src_op->mode == MODE_REG_DIRECT) { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1335 if (dst_op->mode == MODE_REG_DIRECT) { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1336 op_rr(code, inst, src_op->base, dst_op->base, size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1337 } else { |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1338 op_rrdisp(code, inst, src_op->base, dst_op->base, dst_op->disp, size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1339 } |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1340 } else if (src_op->mode == MODE_REG_DISPLACE8) { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1341 op_rdispr(code, inst, src_op->base, src_op->disp, dst_op->base, size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1342 } else { |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1343 if (dst_op->mode == MODE_REG_DIRECT) { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1344 op_ir(code, inst, src_op->disp, dst_op->base, size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1345 } else { |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1346 op_irdisp(code, inst, src_op->disp, dst_op->base, dst_op->disp, size); |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1347 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1348 } |
580
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1349 if (inst->dst.addr_mode != MODE_AREG || inst->op == M68K_CMP) { |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1350 update_flags(opts, flag_mask); |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1351 if (inst->op == M68K_ADDX || inst->op == M68K_SUBX) { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1352 check_alloc_code(code, 2*MAX_INST_LEN); |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1353 code_ptr after_flag_set = code->cur + 1; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1354 jcc(code, CC_Z, code->cur + 2); |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1355 set_flag(opts, 0, FLAG_Z); |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1356 *after_flag_set = code->cur - (after_flag_set+1); |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1357 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1358 } |
580
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1359 if (inst->op != M68K_CMP) { |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1360 m68k_save_result(inst, opts); |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1361 } |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1362 } |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1363 |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1364 void translate_m68k_cmp(m68k_options * opts, m68kinst * inst) |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1365 { |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1366 code_info *code = &opts->gen.code; |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1367 uint8_t size = inst->extra.size; |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1368 host_ea src_op, dst_op; |
580
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1369 translate_m68k_op(inst, &src_op, opts, 0); |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1370 if (inst->dst.addr_mode == MODE_AREG_POSTINC) { |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1371 push_r(code, opts->gen.scratch1); |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1372 translate_m68k_op(inst, &dst_op, opts, 1); |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1373 pop_r(code, opts->gen.scratch2); |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1374 src_op.base = opts->gen.scratch2; |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1375 } else { |
580
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1376 translate_m68k_op(inst, &dst_op, opts, 1); |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1377 if (inst->dst.addr_mode == MODE_AREG && size == OPSIZE_WORD) { |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1378 size = OPSIZE_LONG; |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1379 } |
580
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1380 } |
5157bc966c1a
Refactor translate_m68k_cmp to use translate_m68k_arith
Michael Pavone <pavone@retrodev.com>
parents:
579
diff
changeset
|
1381 translate_m68k_arith(opts, inst, N|Z|V|C, &src_op, &dst_op); |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1382 } |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1383 |
837 | 1384 void translate_m68k_tas(m68k_options *opts, m68kinst *inst) |
1385 { | |
1386 code_info *code = &opts->gen.code; | |
1387 host_ea op; | |
1388 translate_m68k_op(inst, &op, opts, 1); | |
1389 if (op.mode == MODE_REG_DIRECT) { | |
1390 cmp_ir(code, 0, op.base, SZ_B); | |
1391 } else { | |
1392 cmp_irdisp(code, 0, op.base, op.disp, SZ_B); | |
1393 } | |
1394 update_flags(opts, N|Z|V0|C0); | |
1395 if (inst->dst.addr_mode == MODE_REG) { | |
1396 cycles(&opts->gen, BUS); | |
1397 if (op.mode == MODE_REG_DIRECT) { | |
1398 bts_ir(code, 7, op.base, SZ_B); | |
1399 } else { | |
1400 bts_irdisp(code, 7, op.base, op.disp, SZ_B); | |
1401 } | |
1402 } else { | |
1403 if (opts->gen.flags & M68K_OPT_BROKEN_READ_MODIFY) { | |
1404 //2 cycles for processing | |
1405 //4 for failed writeback | |
1406 //4 for prefetch | |
1407 cycles(&opts->gen, BUS * 2 + 2); | |
1408 } else { | |
1409 cycles(&opts->gen, 2); | |
1410 bts_ir(code, 7, op.base, SZ_B); | |
1411 m68k_save_result(inst, opts); | |
1412 cycles(&opts->gen, BUS); | |
1413 } | |
1414 } | |
1415 } | |
1416 | |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1417 void op_r(code_info *code, m68kinst *inst, uint8_t dst, uint8_t size) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1418 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1419 switch(inst->op) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1420 { |
1584
e01adbe1a75b
Fix instruction timing for a number of instructions with only a single operand
Michael Pavone <pavone@retrodev.com>
parents:
1510
diff
changeset
|
1421 case M68K_CLR: xor_rr(code, dst, dst, size); break; |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1422 case M68K_NEG: neg_r(code, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1423 case M68K_NOT: not_r(code, dst, size); cmp_ir(code, 0, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1424 case M68K_ROL: rol_clr(code, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1425 case M68K_ROR: ror_clr(code, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1426 case M68K_ROXL: rcl_clr(code, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1427 case M68K_ROXR: rcr_clr(code, dst, size); break; |
578
ec1365fb2954
Use translate_m68k_unary for SWAP in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
577
diff
changeset
|
1428 case M68K_SWAP: rol_ir(code, 16, dst, SZ_D); cmp_ir(code, 0, dst, SZ_D); break; |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1429 case M68K_TST: cmp_ir(code, 0, dst, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1430 } |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1431 } |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1432 |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1433 void op_rdisp(code_info *code, m68kinst *inst, uint8_t dst, int32_t disp, uint8_t size) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1434 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1435 switch(inst->op) |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1436 { |
1584
e01adbe1a75b
Fix instruction timing for a number of instructions with only a single operand
Michael Pavone <pavone@retrodev.com>
parents:
1510
diff
changeset
|
1437 case M68K_CLR: mov_irdisp(code, 0, dst, disp, size); break; |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1438 case M68K_NEG: neg_rdisp(code, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1439 case M68K_NOT: not_rdisp(code, dst, disp, size); cmp_irdisp(code, 0, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1440 case M68K_ROL: rol_clrdisp(code, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1441 case M68K_ROR: ror_clrdisp(code, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1442 case M68K_ROXL: rcl_clrdisp(code, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1443 case M68K_ROXR: rcr_clrdisp(code, dst, disp, size); break; |
578
ec1365fb2954
Use translate_m68k_unary for SWAP in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
577
diff
changeset
|
1444 case M68K_SWAP: rol_irdisp(code, 16, dst, disp, SZ_D); cmp_irdisp(code, 0, dst, disp, SZ_D); break; |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1445 case M68K_TST: cmp_irdisp(code, 0, dst, disp, size); break; |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1446 } |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1447 } |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1448 |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1449 void translate_m68k_unary(m68k_options *opts, m68kinst *inst, uint32_t flag_mask, host_ea *dst_op) |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1450 { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1451 code_info *code = &opts->gen.code; |
1584
e01adbe1a75b
Fix instruction timing for a number of instructions with only a single operand
Michael Pavone <pavone@retrodev.com>
parents:
1510
diff
changeset
|
1452 uint32_t num_cycles = BUS; |
e01adbe1a75b
Fix instruction timing for a number of instructions with only a single operand
Michael Pavone <pavone@retrodev.com>
parents:
1510
diff
changeset
|
1453 if (inst->extra.size == OPSIZE_LONG && (inst->dst.addr_mode == MODE_REG || inst->dst.addr_mode == MODE_AREG)) { |
e01adbe1a75b
Fix instruction timing for a number of instructions with only a single operand
Michael Pavone <pavone@retrodev.com>
parents:
1510
diff
changeset
|
1454 num_cycles += 2; |
e01adbe1a75b
Fix instruction timing for a number of instructions with only a single operand
Michael Pavone <pavone@retrodev.com>
parents:
1510
diff
changeset
|
1455 } |
e01adbe1a75b
Fix instruction timing for a number of instructions with only a single operand
Michael Pavone <pavone@retrodev.com>
parents:
1510
diff
changeset
|
1456 cycles(&opts->gen, num_cycles); |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1457 if (dst_op->mode == MODE_REG_DIRECT) { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1458 op_r(code, inst, dst_op->base, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1459 } else { |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1460 op_rdisp(code, inst, dst_op->base, dst_op->disp, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1461 } |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1462 update_flags(opts, flag_mask); |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1463 m68k_save_result(inst, opts); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1464 } |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
1465 |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1466 void translate_m68k_abcd_sbcd(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1467 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1468 code_info *code = &opts->gen.code; |
834 | 1469 if (inst->op == M68K_NBCD) { |
1470 if (dst_op->base != opts->gen.scratch2) { | |
1471 if (dst_op->mode == MODE_REG_DIRECT) { | |
1472 mov_rr(code, dst_op->base, opts->gen.scratch2, SZ_B); | |
1473 } else { | |
1474 mov_rdispr(code, dst_op->base, dst_op->disp, opts->gen.scratch2, SZ_B); | |
1475 } | |
208
3457dc6fd558
Tweaks to make blastem compatible with m68k-tester
Mike Pavone <pavone@retrodev.com>
parents:
207
diff
changeset
|
1476 } |
834 | 1477 xor_rr(code, opts->gen.scratch1, opts->gen.scratch1, SZ_B); |
1478 } else { | |
1479 if (src_op->base != opts->gen.scratch2) { | |
1480 if (src_op->mode == MODE_REG_DIRECT) { | |
1481 mov_rr(code, src_op->base, opts->gen.scratch2, SZ_B); | |
1482 } else { | |
1483 mov_rdispr(code, src_op->base, src_op->disp, opts->gen.scratch2, SZ_B); | |
1484 } | |
1485 } | |
1486 if (dst_op->base != opts->gen.scratch1) { | |
1487 if (dst_op->mode == MODE_REG_DIRECT) { | |
1488 mov_rr(code, dst_op->base, opts->gen.scratch1, SZ_B); | |
1489 } else { | |
1490 mov_rdispr(code, dst_op->base, dst_op->disp, opts->gen.scratch1, SZ_B); | |
1491 } | |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1492 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1493 } |
1461
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
1494 if (inst->dst.addr_mode != MODE_REG && inst->dst.addr_mode != MODE_AREG && inst->dst.addr_mode != MODE_AREG_PREDEC) { |
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
1495 //destination is in memory so we need to preserve scratch2 for the write at the end |
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
1496 push_r(code, opts->gen.scratch2); |
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
1497 } |
1585
15116d4fdf40
Fix cycle counts for BCD instructions, RESET, and MOVE from SR
Michael Pavone <pavone@retrodev.com>
parents:
1584
diff
changeset
|
1498 //MC68000 User's Manual suggests NBCD hides the 2 cycle penalty during the write cycle somehow |
15116d4fdf40
Fix cycle counts for BCD instructions, RESET, and MOVE from SR
Michael Pavone <pavone@retrodev.com>
parents:
1584
diff
changeset
|
1499 cycles(&opts->gen, inst->op == M68K_NBCD && inst->dst.addr_mode != MODE_REG_DIRECT ? BUS : BUS + 2); |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1500 uint8_t other_reg; |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1501 //WARNING: This may need adjustment if register assignments change |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1502 if (opts->gen.scratch2 > RBX) { |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1503 other_reg = RAX; |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1504 xchg_rr(code, opts->gen.scratch2, RAX, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1505 } else { |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1506 other_reg = opts->gen.scratch2; |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1507 } |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1508 mov_rr(code, opts->gen.scratch1, opts->gen.scratch1 + (AH-RAX), SZ_B); |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1509 mov_rr(code, other_reg, other_reg + (AH-RAX), SZ_B); |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1510 and_ir(code, 0xF, opts->gen.scratch1 + (AH-RAX), SZ_B); |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1511 and_ir(code, 0xF, other_reg + (AH-RAX), SZ_B); |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1512 //do op on low nibble so we can determine if an adjustment is necessary |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1513 flag_to_carry(opts, FLAG_X); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1514 if (inst->op == M68K_ABCD) { |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1515 adc_rr(code, other_reg + (AH-RAX), opts->gen.scratch1 + (AH-RAX), SZ_B); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1516 } else { |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1517 sbb_rr(code, other_reg + (AH-RAX), opts->gen.scratch1 + (AH-RAX), SZ_B); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1518 } |
1297
71b1a080b30c
Fix SBCD edge cases to pass Flamewing's test ROM. Could use some cleanup to produce better code for the SBCD case, but produces correct results now
Michael Pavone <pavone@retrodev.com>
parents:
1284
diff
changeset
|
1519 cmp_ir(code, inst->op == M68K_SBCD ? 0x10 : 0xA, opts->gen.scratch1 + (AH-RAX), SZ_B); |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1520 mov_ir(code, 0xA0, other_reg + (AH-RAX), SZ_B); |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1521 code_ptr no_adjust = code->cur+1; |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1522 //add correction factor if necessary |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1523 jcc(code, CC_B, no_adjust); |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1524 mov_ir(code, 6, opts->gen.scratch1 + (AH-RAX), SZ_B); |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1525 mov_ir(code, inst->op == M68K_ABCD ? 0x9A : 0xA6, other_reg + (AH-RAX), SZ_B); |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1526 code_ptr after_adjust = code->cur+1; |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1527 jmp(code, after_adjust); |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1528 |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1529 *no_adjust = code->cur - (no_adjust+1); |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1530 xor_rr(code, opts->gen.scratch1 + (AH-RAX), opts->gen.scratch1 + (AH-RAX), SZ_B); |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1531 *after_adjust = code->cur - (after_adjust+1); |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1532 |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1533 //do op on full byte |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1534 flag_to_carry(opts, FLAG_X); |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1535 if (inst->op == M68K_ABCD) { |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1536 adc_rr(code, other_reg, opts->gen.scratch1, SZ_B); |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1537 } else { |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1538 sbb_rr(code, other_reg, opts->gen.scratch1, SZ_B); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1539 } |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1540 set_flag(opts, 0, FLAG_C); |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1541 //determine if we need a correction on the upper nibble |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1542 code_ptr def_adjust = code->cur+1; |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1543 jcc(code, CC_C, def_adjust); |
1297
71b1a080b30c
Fix SBCD edge cases to pass Flamewing's test ROM. Could use some cleanup to produce better code for the SBCD case, but produces correct results now
Michael Pavone <pavone@retrodev.com>
parents:
1284
diff
changeset
|
1544 if (inst->op == M68K_SBCD) { |
71b1a080b30c
Fix SBCD edge cases to pass Flamewing's test ROM. Could use some cleanup to produce better code for the SBCD case, but produces correct results now
Michael Pavone <pavone@retrodev.com>
parents:
1284
diff
changeset
|
1545 no_adjust = code->cur+1; |
71b1a080b30c
Fix SBCD edge cases to pass Flamewing's test ROM. Could use some cleanup to produce better code for the SBCD case, but produces correct results now
Michael Pavone <pavone@retrodev.com>
parents:
1284
diff
changeset
|
1546 jmp(code, no_adjust); |
71b1a080b30c
Fix SBCD edge cases to pass Flamewing's test ROM. Could use some cleanup to produce better code for the SBCD case, but produces correct results now
Michael Pavone <pavone@retrodev.com>
parents:
1284
diff
changeset
|
1547 } else { |
71b1a080b30c
Fix SBCD edge cases to pass Flamewing's test ROM. Could use some cleanup to produce better code for the SBCD case, but produces correct results now
Michael Pavone <pavone@retrodev.com>
parents:
1284
diff
changeset
|
1548 cmp_rr(code, other_reg + (AH-RAX), opts->gen.scratch1, SZ_B); |
71b1a080b30c
Fix SBCD edge cases to pass Flamewing's test ROM. Could use some cleanup to produce better code for the SBCD case, but produces correct results now
Michael Pavone <pavone@retrodev.com>
parents:
1284
diff
changeset
|
1549 no_adjust = code->cur+1; |
71b1a080b30c
Fix SBCD edge cases to pass Flamewing's test ROM. Could use some cleanup to produce better code for the SBCD case, but produces correct results now
Michael Pavone <pavone@retrodev.com>
parents:
1284
diff
changeset
|
1550 jcc(code, CC_B, no_adjust); |
71b1a080b30c
Fix SBCD edge cases to pass Flamewing's test ROM. Could use some cleanup to produce better code for the SBCD case, but produces correct results now
Michael Pavone <pavone@retrodev.com>
parents:
1284
diff
changeset
|
1551 } |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1552 *def_adjust = code->cur - (def_adjust + 1); |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1553 set_flag(opts, 1, FLAG_C); |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1554 or_ir(code, 0x60, opts->gen.scratch1 + (AH-RAX), SZ_B); |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1555 *no_adjust = code->cur - (no_adjust+1); |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1556 if (inst->op == M68K_ABCD) { |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1557 add_rr(code, opts->gen.scratch1 + (AH-RAX), opts->gen.scratch1, SZ_B); |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1558 } else { |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1559 sub_rr(code, opts->gen.scratch1 + (AH-RAX), opts->gen.scratch1, SZ_B); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1560 } |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1561 code_ptr no_ensure_carry = code->cur+1; |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1562 jcc(code, CC_NC, no_ensure_carry); |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1563 set_flag(opts, 1, FLAG_C); |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1564 *no_ensure_carry = code->cur - (no_ensure_carry+1); |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1565 //restore RAX if necessary |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1566 if (opts->gen.scratch2 > RBX) { |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1567 mov_rr(code, opts->gen.scratch2, RAX, SZ_D); |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1568 } |
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1569 //V flag is set based on the result of the addition/subtraction of the |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1570 //result and the correction factor |
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1571 set_flag_cond(opts, CC_O, FLAG_V); |
833
841e44c5af83
Fix for abcd/sbcd. Hopefully got it 100% right this time.
Michael Pavone <pavone@retrodev.com>
parents:
792
diff
changeset
|
1572 |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1573 flag_to_flag(opts, FLAG_C, FLAG_X); |
653
a18e3923481e
Remove some of the hard coded assumptions about the memory map from the CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
620
diff
changeset
|
1574 |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1575 cmp_ir(code, 0, opts->gen.scratch1, SZ_B); |
612
5a6ff0d76032
Removed bcd_add and bcd_sub from runtime.S and generated the logic inline with the rest of abcd and sbcd translation. Fixed some edge cases and undefined flag behavior in the process
Michael Pavone <pavone@retrodev.com>
parents:
611
diff
changeset
|
1576 set_flag_cond(opts, CC_S, FLAG_N); |
733
fbda8e865dae
Fix crash bug in 32-bit build for certain secnarios with bcd instructions
Michael Pavone <pavone@retrodev.com>
parents:
732
diff
changeset
|
1577 code_ptr no_setz = code->cur+1; |
fbda8e865dae
Fix crash bug in 32-bit build for certain secnarios with bcd instructions
Michael Pavone <pavone@retrodev.com>
parents:
732
diff
changeset
|
1578 jcc(code, CC_Z, no_setz); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1579 set_flag(opts, 0, FLAG_Z); |
733
fbda8e865dae
Fix crash bug in 32-bit build for certain secnarios with bcd instructions
Michael Pavone <pavone@retrodev.com>
parents:
732
diff
changeset
|
1580 *no_setz = code->cur - (no_setz + 1); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1581 if (dst_op->base != opts->gen.scratch1) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1582 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1583 mov_rr(code, opts->gen.scratch1, dst_op->base, SZ_B); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1584 } else { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1585 mov_rrdisp(code, opts->gen.scratch1, dst_op->base, dst_op->disp, SZ_B); |
73
8da611e69b32
Implement a couple of supervisor instructions
Mike Pavone <pavone@retrodev.com>
parents:
71
diff
changeset
|
1586 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1587 } |
1461
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
1588 if (inst->dst.addr_mode != MODE_REG && inst->dst.addr_mode != MODE_AREG && inst->dst.addr_mode != MODE_AREG_PREDEC) { |
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
1589 //destination is in memory so we need to restore scratch2 for the write at the end |
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
1590 pop_r(code, opts->gen.scratch2); |
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
1591 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1592 m68k_save_result(inst, opts); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1593 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1594 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1595 void translate_m68k_sl(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1596 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1597 translate_shift(opts, inst, src_op, dst_op, shl_ir, shl_irdisp, shl_clr, shl_clrdisp, shr_ir, shr_irdisp); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1598 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1599 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1600 void translate_m68k_asr(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1601 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1602 translate_shift(opts, inst, src_op, dst_op, sar_ir, sar_irdisp, sar_clr, sar_clrdisp, NULL, NULL); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1603 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1604 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1605 void translate_m68k_lsr(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1606 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1607 translate_shift(opts, inst, src_op, dst_op, shr_ir, shr_irdisp, shr_clr, shr_clrdisp, shl_ir, shl_irdisp); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1608 } |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1609 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1610 void translate_m68k_bit(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1611 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1612 code_info *code = &opts->gen.code; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1613 cycles(&opts->gen, inst->extra.size == OPSIZE_BYTE ? 4 : ( |
457
6a315728fede
Fix bit instruction timing
Mike Pavone <pavone@retrodev.com>
parents:
447
diff
changeset
|
1614 inst->op == M68K_BTST ? 6 : (inst->op == M68K_BCLR ? 10 : 8)) |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1615 ); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1616 if (src_op->mode == MODE_IMMED) { |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1617 if (inst->extra.size == OPSIZE_BYTE) { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1618 src_op->disp &= 0x7; |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1619 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1620 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1621 op_ir(code, inst, src_op->disp, dst_op->base, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1622 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1623 op_irdisp(code, inst, src_op->disp, dst_op->base, dst_op->disp, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1624 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1625 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1626 if (src_op->mode == MODE_REG_DISPLACE8 || (inst->dst.addr_mode != MODE_REG && src_op->base != opts->gen.scratch1 && src_op->base != opts->gen.scratch2)) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1627 if (dst_op->base == opts->gen.scratch1) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1628 push_r(code, opts->gen.scratch2); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1629 if (src_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1630 mov_rr(code, src_op->base, opts->gen.scratch2, SZ_B); |
61
918468c623e9
Add support for BTST instruction (untested), absolute addressing mode for instructions other than move (untested) and fix decoding of MOVEM.
Mike Pavone <pavone@retrodev.com>
parents:
59
diff
changeset
|
1631 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1632 mov_rdispr(code, src_op->base, src_op->disp, opts->gen.scratch2, SZ_B); |
154
4791c0204410
Small fix for bit instructions
Mike Pavone <pavone@retrodev.com>
parents:
152
diff
changeset
|
1633 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1634 src_op->base = opts->gen.scratch2; |
61
918468c623e9
Add support for BTST instruction (untested), absolute addressing mode for instructions other than move (untested) and fix decoding of MOVEM.
Mike Pavone <pavone@retrodev.com>
parents:
59
diff
changeset
|
1635 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1636 if (src_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1637 mov_rr(code, src_op->base, opts->gen.scratch1, SZ_B); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1638 } else { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1639 mov_rdispr(code, src_op->base, src_op->disp, opts->gen.scratch1, SZ_B); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1640 } |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1641 src_op->base = opts->gen.scratch1; |
61
918468c623e9
Add support for BTST instruction (untested), absolute addressing mode for instructions other than move (untested) and fix decoding of MOVEM.
Mike Pavone <pavone@retrodev.com>
parents:
59
diff
changeset
|
1642 } |
226
28a6697e847b
Implement CHK instruction (not fully tested).
Mike Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
1643 } |
221
71f6b76639db
Fix modulo on bit operations with a memory destination
Mike Pavone <pavone@retrodev.com>
parents:
219
diff
changeset
|
1644 uint8_t size = inst->extra.size; |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1645 if (dst_op->mode == MODE_REG_DISPLACE8) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1646 if (src_op->base != opts->gen.scratch1 && src_op->base != opts->gen.scratch2) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1647 if (src_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1648 mov_rr(code, src_op->base, opts->gen.scratch1, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1649 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1650 mov_rdispr(code, src_op->base, src_op->disp, opts->gen.scratch1, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1651 src_op->mode = MODE_REG_DIRECT; |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1652 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1653 src_op->base = opts->gen.scratch1; |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1654 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1655 //b### with register destination is modulo 32 |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1656 //x86 with a memory destination isn't modulo anything |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1657 //so use an and here to force the value to be modulo 32 |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1658 and_ir(code, 31, opts->gen.scratch1, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1659 } else if(inst->dst.addr_mode != MODE_REG) { |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1660 //b### with memory destination is modulo 8 |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1661 //x86-64 doesn't support 8-bit bit operations |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1662 //so we fake it by forcing the bit number to be modulo 8 |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1663 and_ir(code, 7, src_op->base, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1664 size = SZ_D; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1665 } |
976
8cdd4ddedd9a
Properly imlement btst with an immediate destination. Fixes a crash in NHL 95.
Michael Pavone <pavone@retrodev.com>
parents:
908
diff
changeset
|
1666 if (dst_op->mode == MODE_IMMED) { |
8cdd4ddedd9a
Properly imlement btst with an immediate destination. Fixes a crash in NHL 95.
Michael Pavone <pavone@retrodev.com>
parents:
908
diff
changeset
|
1667 dst_op->base = src_op->base == opts->gen.scratch1 ? opts->gen.scratch2 : opts->gen.scratch1; |
8cdd4ddedd9a
Properly imlement btst with an immediate destination. Fixes a crash in NHL 95.
Michael Pavone <pavone@retrodev.com>
parents:
908
diff
changeset
|
1668 mov_ir(code, dst_op->disp, dst_op->base, SZ_B); |
8cdd4ddedd9a
Properly imlement btst with an immediate destination. Fixes a crash in NHL 95.
Michael Pavone <pavone@retrodev.com>
parents:
908
diff
changeset
|
1669 dst_op->mode = MODE_REG_DIRECT; |
8cdd4ddedd9a
Properly imlement btst with an immediate destination. Fixes a crash in NHL 95.
Michael Pavone <pavone@retrodev.com>
parents:
908
diff
changeset
|
1670 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1671 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1672 op_rr(code, inst, src_op->base, dst_op->base, size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1673 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1674 op_rrdisp(code, inst, src_op->base, dst_op->base, dst_op->disp, size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1675 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1676 if (src_op->base == opts->gen.scratch2) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1677 pop_r(code, opts->gen.scratch2); |
151
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
1678 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1679 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1680 //x86 sets the carry flag to the value of the bit tested |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1681 //68K sets the zero flag to the complement of the bit tested |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1682 set_flag_cond(opts, CC_NC, FLAG_Z); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1683 if (inst->op != M68K_BTST) { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1684 m68k_save_result(inst, opts); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1685 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1686 } |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1687 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1688 void translate_m68k_chk(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
226
28a6697e847b
Implement CHK instruction (not fully tested).
Mike Pavone <pavone@retrodev.com>
parents:
225
diff
changeset
|
1689 { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1690 code_info *code = &opts->gen.code; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1691 cycles(&opts->gen, 6); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1692 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1693 cmp_ir(code, 0, dst_op->base, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1694 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1695 cmp_irdisp(code, 0, dst_op->base, dst_op->disp, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1696 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1697 uint32_t isize; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1698 switch(inst->src.addr_mode) |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1699 { |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1700 case MODE_AREG_DISPLACE: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1701 case MODE_AREG_INDEX_DISP8: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1702 case MODE_ABSOLUTE_SHORT: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1703 case MODE_PC_INDEX_DISP8: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1704 case MODE_PC_DISPLACE: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1705 case MODE_IMMEDIATE: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1706 isize = 4; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1707 break; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1708 case MODE_ABSOLUTE: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1709 isize = 6; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1710 break; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1711 default: |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1712 isize = 2; |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1713 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1714 //make sure we won't start a new chunk in the middle of these branches |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1715 check_alloc_code(code, MAX_INST_LEN * 11); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1716 code_ptr passed = code->cur + 1; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1717 jcc(code, CC_GE, code->cur + 2); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1718 set_flag(opts, 1, FLAG_N); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1719 mov_ir(code, VECTOR_CHK, opts->gen.scratch2, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1720 mov_ir(code, inst->address+isize, opts->gen.scratch1, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1721 jmp(code, opts->trap); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1722 *passed = code->cur - (passed+1); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1723 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1724 if (src_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1725 cmp_rr(code, src_op->base, dst_op->base, inst->extra.size); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1726 } else if(src_op->mode == MODE_REG_DISPLACE8) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1727 cmp_rdispr(code, src_op->base, src_op->disp, dst_op->base, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1728 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1729 cmp_ir(code, src_op->disp, dst_op->base, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1730 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1731 } else if(dst_op->mode == MODE_REG_DISPLACE8) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1732 if (src_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1733 cmp_rrdisp(code, src_op->base, dst_op->base, dst_op->disp, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1734 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1735 cmp_irdisp(code, src_op->disp, dst_op->base, dst_op->disp, inst->extra.size); |
171 | 1736 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1737 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1738 passed = code->cur + 1; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1739 jcc(code, CC_LE, code->cur + 2); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1740 set_flag(opts, 0, FLAG_N); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1741 mov_ir(code, VECTOR_CHK, opts->gen.scratch2, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1742 mov_ir(code, inst->address+isize, opts->gen.scratch1, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1743 jmp(code, opts->trap); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1744 *passed = code->cur - (passed+1); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1745 cycles(&opts->gen, 4); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1746 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1747 |
1262
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1748 static uint32_t divu(uint32_t dividend, m68k_context *context, uint32_t divisor_shift) |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1749 { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1750 uint16_t quotient = 0; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1751 uint8_t force = 0; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1752 uint16_t bit = 0; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1753 uint32_t cycles = 6; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1754 for (int i = 0; i < 16; i++) |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1755 { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1756 force = dividend >> 31; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1757 quotient = quotient << 1 | bit; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1758 dividend = dividend << 1; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1759 |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1760 if (force || dividend >= divisor_shift) { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1761 dividend -= divisor_shift; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1762 cycles += force ? 4 : 6; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1763 bit = 1; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1764 } else { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1765 bit = 0; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1766 cycles += 8; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1767 } |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1768 } |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1769 cycles += force ? 6 : bit ? 4 : 2; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1770 context->current_cycle += cycles * context->options->gen.clock_divider; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1771 quotient = quotient << 1 | bit; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1772 return dividend | quotient; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1773 } |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1774 |
1282
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1775 static uint32_t divs(uint32_t dividend, m68k_context *context, uint32_t divisor_shift) |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1776 { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1777 uint32_t orig_divisor = divisor_shift, orig_dividend = dividend; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1778 if (divisor_shift & 0x80000000) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1779 divisor_shift = 0 - divisor_shift; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1780 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1781 |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1782 uint32_t cycles = 12; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1783 if (dividend & 0x80000000) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1784 //dvs10 |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1785 dividend = 0 - dividend; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1786 cycles += 2; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1787 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1788 if (divisor_shift <= dividend) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1789 context->flags[FLAG_V] = 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1790 context->flags[FLAG_N] = 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1791 context->flags[FLAG_Z] = 0; |
1284
82838d4c84d9
Minor fix to timing of "early" overflow case in divs when the dividend is negative
Michael Pavone <pavone@retrodev.com>
parents:
1282
diff
changeset
|
1792 cycles += 2; |
82838d4c84d9
Minor fix to timing of "early" overflow case in divs when the dividend is negative
Michael Pavone <pavone@retrodev.com>
parents:
1282
diff
changeset
|
1793 context->current_cycle += cycles * context->options->gen.clock_divider; |
1282
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1794 return orig_dividend; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1795 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1796 uint16_t quotient = 0; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1797 uint16_t bit = 0; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1798 for (int i = 0; i < 15; i++) |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1799 { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1800 quotient = quotient << 1 | bit; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1801 dividend = dividend << 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1802 |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1803 if (dividend >= divisor_shift) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1804 dividend -= divisor_shift; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1805 cycles += 6; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1806 bit = 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1807 } else { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1808 bit = 0; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1809 cycles += 8; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1810 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1811 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1812 quotient = quotient << 1 | bit; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1813 dividend = dividend << 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1814 if (dividend >= divisor_shift) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1815 dividend -= divisor_shift; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1816 quotient = quotient << 1 | 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1817 } else { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1818 quotient = quotient << 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1819 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1820 cycles += 4; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1821 |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1822 context->flags[FLAG_V] = 0; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1823 if (orig_divisor & 0x80000000) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1824 cycles += 16; //was 10 |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1825 if (orig_dividend & 0x80000000) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1826 if (quotient & 0x8000) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1827 context->flags[FLAG_V] = 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1828 context->flags[FLAG_N] = 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1829 context->flags[FLAG_Z] = 0; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1830 context->current_cycle += cycles * context->options->gen.clock_divider; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1831 return orig_dividend; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1832 } else { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1833 dividend = -dividend; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1834 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1835 } else { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1836 quotient = -quotient; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1837 if (quotient && !(quotient & 0x8000)) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1838 context->flags[FLAG_V] = 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1839 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1840 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1841 } else if (orig_dividend & 0x80000000) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1842 cycles += 18; // was 12 |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1843 quotient = -quotient; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1844 if (quotient && !(quotient & 0x8000)) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1845 context->flags[FLAG_V] = 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1846 } else { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1847 dividend = -dividend; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1848 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1849 } else { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1850 cycles += 14; //was 10 |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1851 if (quotient & 0x8000) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1852 context->flags[FLAG_V] = 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1853 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1854 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1855 if (context->flags[FLAG_V]) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1856 context->flags[FLAG_N] = 1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1857 context->flags[FLAG_Z] = 0; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1858 context->current_cycle += cycles * context->options->gen.clock_divider; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1859 return orig_dividend; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1860 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1861 context->flags[FLAG_N] = (quotient & 0x8000) ? 1 : 0; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1862 context->flags[FLAG_Z] = quotient == 0; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1863 //V was cleared above, C is cleared by the generated machine code |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1864 context->current_cycle += cycles * context->options->gen.clock_divider; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1865 return dividend | quotient; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1866 } |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1867 |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1868 void translate_m68k_div(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
1262
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1869 { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1870 code_info *code = &opts->gen.code; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1871 check_alloc_code(code, MAX_NATIVE_SIZE); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1872 set_flag(opts, 0, FLAG_C); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1873 if (dst_op->mode == MODE_REG_DIRECT) { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1874 mov_rr(code, dst_op->base, opts->gen.scratch2, SZ_D); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1875 } else { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1876 mov_rdispr(code, dst_op->base, dst_op->disp, opts->gen.scratch2, SZ_D); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1877 } |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1878 if (src_op->mode == MODE_IMMED) { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1879 mov_ir(code, src_op->disp << 16, opts->gen.scratch1, SZ_D); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1880 } else { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1881 if (src_op->mode == MODE_REG_DISPLACE8) { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1882 movzx_rdispr(code, src_op->base, src_op->disp, opts->gen.scratch1, SZ_W, SZ_D); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1883 } else if (src_op->base != opts->gen.scratch1) { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1884 movzx_rr(code, src_op->base, opts->gen.scratch1, SZ_W, SZ_D); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1885 } |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1886 shl_ir(code, 16, opts->gen.scratch1, SZ_D); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1887 } |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1888 cmp_ir(code, 0, opts->gen.scratch1, SZ_D); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1889 code_ptr not_zero = code->cur+1; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1890 jcc(code, CC_NZ, not_zero); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1891 |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1892 //TODO: Check that opts->trap includes the cycles conumed by the first trap0 microinstruction |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1893 cycles(&opts->gen, 4); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1894 uint32_t isize = 2; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1895 switch(inst->src.addr_mode) |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1896 { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1897 case MODE_AREG_DISPLACE: |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1898 case MODE_AREG_INDEX_DISP8: |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1899 case MODE_ABSOLUTE_SHORT: |
1466
f2ee46d08b01
Push correct PC onto stack on divide by zero for pc-relative case
Michael Pavone <pavone@retrodev.com>
parents:
1465
diff
changeset
|
1900 case MODE_PC_DISPLACE: |
1262
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1901 case MODE_PC_INDEX_DISP8: |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1902 case MODE_IMMEDIATE: |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1903 isize = 4; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1904 break; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1905 case MODE_ABSOLUTE: |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1906 isize = 6; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1907 break; |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1908 } |
1276
2d8b9d40f5ea
Fix undefined flags on overflow and divide by zero for divu based on hardware test. Fix saving result of divu when destination is not stored in a host register
Michael Pavone <pavone@retrodev.com>
parents:
1274
diff
changeset
|
1909 //zero seems to clear all flags |
2d8b9d40f5ea
Fix undefined flags on overflow and divide by zero for divu based on hardware test. Fix saving result of divu when destination is not stored in a host register
Michael Pavone <pavone@retrodev.com>
parents:
1274
diff
changeset
|
1910 update_flags(opts, N0|Z0|V0); |
1262
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1911 mov_ir(code, VECTOR_INT_DIV_ZERO, opts->gen.scratch2, SZ_D); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1912 mov_ir(code, inst->address+isize, opts->gen.scratch1, SZ_D); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1913 jmp(code, opts->trap); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1914 |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1915 *not_zero = code->cur - (not_zero + 1); |
1282
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1916 code_ptr end = NULL; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1917 if (inst->op == M68K_DIVU) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1918 //initial overflow check needs to be done in the C code for divs |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1919 //but can be done before dumping state to mem in divu as an optimization |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1920 cmp_rr(code, opts->gen.scratch1, opts->gen.scratch2, SZ_D); |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1921 code_ptr not_overflow = code->cur+1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1922 jcc(code, CC_C, not_overflow); |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1923 |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1924 //overflow seems to always set the N and clear Z |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1925 update_flags(opts, N1|Z0|V1); |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1926 cycles(&opts->gen, 10); |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1927 end = code->cur+1; |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1928 jmp(code, end); |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1929 |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1930 *not_overflow = code->cur - (not_overflow + 1); |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1931 } |
1262
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1932 call(code, opts->gen.save_context); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1933 push_r(code, opts->gen.context_reg); |
1282
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1934 //TODO: inline the functionality of divudivs/ so we don't need to dump context to memory |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1935 call_args(code, (code_ptr)(inst->op == M68K_DIVU ? divu : divs), 3, opts->gen.scratch2, opts->gen.context_reg, opts->gen.scratch1); |
1262
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1936 pop_r(code, opts->gen.context_reg); |
1274
779920729249
Forgot to update flags in the "good" case of the new divu code
Michael Pavone <pavone@retrodev.com>
parents:
1262
diff
changeset
|
1937 mov_rr(code, RAX, opts->gen.scratch1, SZ_D); |
779920729249
Forgot to update flags in the "good" case of the new divu code
Michael Pavone <pavone@retrodev.com>
parents:
1262
diff
changeset
|
1938 |
1262
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1939 call(code, opts->gen.load_context); |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1940 |
1282
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1941 if (inst->op == M68K_DIVU) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1942 cmp_ir(code, 0, opts->gen.scratch1, SZ_W); |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1943 update_flags(opts, V0|Z|N); |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1944 } |
1274
779920729249
Forgot to update flags in the "good" case of the new divu code
Michael Pavone <pavone@retrodev.com>
parents:
1262
diff
changeset
|
1945 |
1262
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1946 if (dst_op->mode == MODE_REG_DIRECT) { |
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1947 mov_rr(code, opts->gen.scratch1, dst_op->base, SZ_D); |
1274
779920729249
Forgot to update flags in the "good" case of the new divu code
Michael Pavone <pavone@retrodev.com>
parents:
1262
diff
changeset
|
1948 } else { |
1276
2d8b9d40f5ea
Fix undefined flags on overflow and divide by zero for divu based on hardware test. Fix saving result of divu when destination is not stored in a host register
Michael Pavone <pavone@retrodev.com>
parents:
1274
diff
changeset
|
1949 mov_rrdisp(code, opts->gen.scratch1, dst_op->base, dst_op->disp, SZ_D); |
1262
462d9770d467
Cycle accurate divu and undefined flags for overflow case
Michael Pavone <pavone@retrodev.com>
parents:
1228
diff
changeset
|
1950 } |
1282
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1951 if (end) { |
c5821f9de325
Cycle accurate implementation of divs
Michael Pavone <pavone@retrodev.com>
parents:
1276
diff
changeset
|
1952 *end = code->cur - (end + 1); |
611
744b305965f7
Fix divide by zero exception return address when div instruction is bigger than 1 word
Michael Pavone <pavone@retrodev.com>
parents:
610
diff
changeset
|
1953 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1954 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1955 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1956 void translate_m68k_exg(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1957 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1958 code_info *code = &opts->gen.code; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1959 cycles(&opts->gen, 6); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1960 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1961 mov_rr(code, dst_op->base, opts->gen.scratch2, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1962 if (src_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1963 mov_rr(code, src_op->base, dst_op->base, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1964 mov_rr(code, opts->gen.scratch2, src_op->base, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1965 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1966 mov_rdispr(code, src_op->base, src_op->disp, dst_op->base, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1967 mov_rrdisp(code, opts->gen.scratch2, src_op->base, src_op->disp, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1968 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1969 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1970 mov_rdispr(code, dst_op->base, dst_op->disp, opts->gen.scratch2, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1971 if (src_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1972 mov_rrdisp(code, src_op->base, dst_op->base, dst_op->disp, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1973 mov_rr(code, opts->gen.scratch2, src_op->base, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1974 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1975 mov_rdispr(code, src_op->base, src_op->disp, opts->gen.scratch1, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1976 mov_rrdisp(code, opts->gen.scratch1, dst_op->base, dst_op->disp, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1977 mov_rrdisp(code, opts->gen.scratch2, src_op->base, src_op->disp, SZ_D); |
151
6b593ea0ed90
Implement MULU/MULS and DIVU/DIVS
Mike Pavone <pavone@retrodev.com>
parents:
150
diff
changeset
|
1978 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1979 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
1980 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
1981 |
1216
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1982 |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1983 |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1984 static uint32_t mulu_cycles(uint16_t value) |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1985 { |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1986 //4 for prefetch, 2-cycles per bit x 16, 2 for cleanup |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1987 uint32_t cycles = 38; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1988 uint16_t a = (value & 0b1010101010101010) >> 1; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1989 uint16_t b = value & 0b0101010101010101; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1990 value = a + b; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1991 a = (value & 0b1100110011001100) >> 2; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1992 b = value & 0b0011001100110011; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1993 value = a + b; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1994 a = (value & 0b1111000011110000) >> 4; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1995 b = value & 0b0000111100001111; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1996 value = a + b; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1997 a = (value & 0b1111111100000000) >> 8; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1998 b = value & 0b0000000011111111; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
1999 value = a + b; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2000 return cycles + 2*value; |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2001 } |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2002 |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2003 static uint32_t muls_cycles(uint16_t value) |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2004 { |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2005 //muls timing is essentially the same as muls, but it's based on the number of 0/1 |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2006 //transitions rather than the number of 1 bits. xoring the value with itself shifted |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2007 //by one effectively sets one bit for every transition |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2008 return mulu_cycles((value << 1) ^ value); |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2009 } |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2010 |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2011 void translate_m68k_mul(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2012 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2013 code_info *code = &opts->gen.code; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2014 if (src_op->mode == MODE_IMMED) { |
1216
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2015 cycles(&opts->gen, inst->op == M68K_MULU ? mulu_cycles(src_op->disp) : muls_cycles(src_op->disp)); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2016 mov_ir(code, inst->op == M68K_MULU ? (src_op->disp & 0xFFFF) : ((src_op->disp & 0x8000) ? src_op->disp | 0xFFFF0000 : src_op->disp), opts->gen.scratch1, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2017 } else if (src_op->mode == MODE_REG_DIRECT) { |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2018 if (inst->op == M68K_MULS) { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2019 movsx_rr(code, src_op->base, opts->gen.scratch1, SZ_W, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2020 } else { |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2021 movzx_rr(code, src_op->base, opts->gen.scratch1, SZ_W, SZ_D); |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2022 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2023 } else { |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2024 if (inst->op == M68K_MULS) { |
682 | 2025 movsx_rdispr(code, src_op->base, src_op->disp, opts->gen.scratch1, SZ_W, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2026 } else { |
682 | 2027 movzx_rdispr(code, src_op->base, src_op->disp, opts->gen.scratch1, SZ_W, SZ_D); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2028 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2029 } |
1216
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2030 if (src_op->mode != MODE_IMMED) { |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2031 //TODO: Inline cycle calculation so we don't need to save/restore a bunch of registers |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2032 //save context to memory and call the relevant C function for calculating the cycle count |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2033 call(code, opts->gen.save_context); |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2034 push_r(code, opts->gen.scratch1); |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2035 push_r(code, opts->gen.context_reg); |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2036 call_args(code, (code_ptr)(inst->op == M68K_MULS ? muls_cycles : mulu_cycles), 1, opts->gen.scratch1); |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2037 pop_r(code, opts->gen.context_reg); |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2038 //turn 68K cycles into master clock cycles and add to the current cycle count |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2039 imul_irr(code, opts->gen.clock_divider, RAX, RAX, SZ_D); |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2040 add_rrdisp(code, RAX, opts->gen.context_reg, offsetof(m68k_context, current_cycle), SZ_D); |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2041 //restore context and scratch1 |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2042 call(code, opts->gen.load_context); |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2043 pop_r(code, opts->gen.scratch1); |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2044 } |
0649cd8ca097
Cycle accurate MULU/MULS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1192
diff
changeset
|
2045 |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2046 uint8_t dst_reg; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2047 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2048 dst_reg = dst_op->base; |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2049 if (inst->op == M68K_MULS) { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2050 movsx_rr(code, dst_reg, dst_reg, SZ_W, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2051 } else { |
682 | 2052 movzx_rr(code, dst_reg, dst_reg, SZ_W, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2053 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2054 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2055 dst_reg = opts->gen.scratch2; |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2056 if (inst->op == M68K_MULS) { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2057 movsx_rdispr(code, dst_op->base, dst_op->disp, opts->gen.scratch2, SZ_W, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2058 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2059 movzx_rdispr(code, dst_op->base, dst_op->disp, opts->gen.scratch2, SZ_W, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2060 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2061 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2062 imul_rr(code, opts->gen.scratch1, dst_reg, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2063 if (dst_op->mode == MODE_REG_DISPLACE8) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2064 mov_rrdisp(code, dst_reg, dst_op->base, dst_op->disp, SZ_D); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2065 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2066 cmp_ir(code, 0, dst_reg, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2067 update_flags(opts, N|Z|V0|C0); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2068 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2069 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2070 void translate_m68k_negx(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2071 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2072 code_info *code = &opts->gen.code; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2073 cycles(&opts->gen, BUS); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2074 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2075 if (dst_op->base == opts->gen.scratch1) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2076 push_r(code, opts->gen.scratch2); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2077 xor_rr(code, opts->gen.scratch2, opts->gen.scratch2, inst->extra.size); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2078 flag_to_carry(opts, FLAG_X); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2079 sbb_rr(code, dst_op->base, opts->gen.scratch2, inst->extra.size); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2080 mov_rr(code, opts->gen.scratch2, dst_op->base, inst->extra.size); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2081 pop_r(code, opts->gen.scratch2); |
173 | 2082 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2083 xor_rr(code, opts->gen.scratch1, opts->gen.scratch1, inst->extra.size); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2084 flag_to_carry(opts, FLAG_X); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2085 sbb_rr(code, dst_op->base, opts->gen.scratch1, inst->extra.size); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2086 mov_rr(code, opts->gen.scratch1, dst_op->base, inst->extra.size); |
106 | 2087 } |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2088 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2089 xor_rr(code, opts->gen.scratch1, opts->gen.scratch1, inst->extra.size); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2090 flag_to_carry(opts, FLAG_X); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2091 sbb_rdispr(code, dst_op->base, dst_op->disp, opts->gen.scratch1, inst->extra.size); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2092 mov_rrdisp(code, opts->gen.scratch1, dst_op->base, dst_op->disp, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2093 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2094 set_flag_cond(opts, CC_C, FLAG_C); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2095 code_ptr after_flag_set = code->cur + 1; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2096 jcc(code, CC_Z, code->cur + 2); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2097 set_flag(opts, 0, FLAG_Z); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2098 *after_flag_set = code->cur - (after_flag_set+1); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2099 set_flag_cond(opts, CC_S, FLAG_N); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2100 set_flag_cond(opts, CC_O, FLAG_V); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2101 if (opts->flag_regs[FLAG_C] >= 0) { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2102 flag_to_flag(opts, FLAG_C, FLAG_X); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2103 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2104 set_flag_cond(opts, CC_C, FLAG_X); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2105 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2106 m68k_save_result(inst, opts); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2107 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2108 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2109 void translate_m68k_rot(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2110 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2111 code_info *code = &opts->gen.code; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2112 int32_t init_flags = C|V0; |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2113 if (inst->src.addr_mode == MODE_UNUSED) { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2114 cycles(&opts->gen, BUS); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2115 //Memory rotate |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2116 if (inst->op == M68K_ROXR || inst->op == M68K_ROXL) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2117 flag_to_carry(opts, FLAG_X); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2118 init_flags |= X; |
106 | 2119 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2120 op_ir(code, inst, 1, dst_op->base, inst->extra.size); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2121 update_flags(opts, init_flags); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2122 cmp_ir(code, 0, dst_op->base, inst->extra.size); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2123 update_flags(opts, Z|N); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2124 m68k_save_result(inst, opts); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2125 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2126 if (src_op->mode == MODE_IMMED) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2127 cycles(&opts->gen, (inst->extra.size == OPSIZE_LONG ? 8 : 6) + src_op->disp*2); |
577
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
2128 if (inst->op == M68K_ROXR || inst->op == M68K_ROXL) { |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
2129 flag_to_carry(opts, FLAG_X); |
0f367276a80c
Refactor a bunch of the arithmetic instructions in the 68K core to reduce duplicate code
Michael Pavone <pavone@retrodev.com>
parents:
576
diff
changeset
|
2130 init_flags |= X; |
122 | 2131 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2132 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2133 op_ir(code, inst, src_op->disp, dst_op->base, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2134 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2135 op_irdisp(code, inst, src_op->disp, dst_op->base, dst_op->disp, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2136 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2137 update_flags(opts, init_flags); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2138 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2139 if (src_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2140 if (src_op->base != opts->gen.scratch1) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2141 mov_rr(code, src_op->base, opts->gen.scratch1, SZ_B); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2142 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2143 } else { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2144 mov_rdispr(code, src_op->base, src_op->disp, opts->gen.scratch1, SZ_B); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2145 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2146 and_ir(code, 63, opts->gen.scratch1, SZ_D); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2147 code_ptr zero_off = code->cur + 1; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2148 jcc(code, CC_Z, code->cur + 2); |
667
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
2149 //add 2 cycles for every bit shifted |
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
2150 mov_ir(code, 2 * opts->gen.clock_divider, opts->gen.scratch2, SZ_D); |
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
2151 imul_rr(code, RCX, opts->gen.scratch2, SZ_D); |
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
2152 add_rr(code, opts->gen.scratch2, opts->gen.cycles, SZ_D); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2153 cmp_ir(code, 32, opts->gen.scratch1, SZ_B); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2154 code_ptr norm_off = code->cur + 1; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2155 jcc(code, CC_L, code->cur + 2); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2156 if (inst->op == M68K_ROXR || inst->op == M68K_ROXL) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2157 flag_to_carry(opts, FLAG_X); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2158 init_flags |= X; |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2159 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2160 sub_ir(code, 32, opts->gen.scratch1, SZ_B); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2161 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2162 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2163 op_ir(code, inst, 31, dst_op->base, inst->extra.size); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2164 op_ir(code, inst, 1, dst_op->base, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2165 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2166 op_irdisp(code, inst, 31, dst_op->base, dst_op->disp, inst->extra.size); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2167 op_irdisp(code, inst, 1, dst_op->base, dst_op->disp, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2168 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2169 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2170 if (inst->op == M68K_ROXR || inst->op == M68K_ROXL) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2171 set_flag_cond(opts, CC_C, FLAG_X); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2172 sub_ir(code, 32, opts->gen.scratch1, SZ_B); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2173 *norm_off = code->cur - (norm_off+1); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2174 flag_to_carry(opts, FLAG_X); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2175 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2176 *norm_off = code->cur - (norm_off+1); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2177 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2178 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2179 op_r(code, inst, dst_op->base, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2180 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2181 op_rdisp(code, inst, dst_op->base, dst_op->disp, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2182 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2183 update_flags(opts, init_flags); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2184 code_ptr end_off = code->cur + 1; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2185 jmp(code, code->cur + 2); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2186 *zero_off = code->cur - (zero_off+1); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2187 if (inst->op == M68K_ROXR || inst->op == M68K_ROXL) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2188 //Carry flag is set to X flag when count is 0, this is different from ROR/ROL |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2189 flag_to_flag(opts, FLAG_X, FLAG_C); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2190 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2191 set_flag(opts, 0, FLAG_C); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2192 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2193 *end_off = code->cur - (end_off+1); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2194 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2195 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2196 cmp_ir(code, 0, dst_op->base, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2197 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2198 cmp_irdisp(code, 0, dst_op->base, dst_op->disp, inst->extra.size); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2199 } |
682 | 2200 update_flags(opts, Z|N); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2201 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2202 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2203 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2204 #define BIT_SUPERVISOR 5 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2205 |
990
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2206 void m68k_trap_if_not_supervisor(m68k_options *opts, m68kinst *inst) |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2207 { |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2208 code_info *code = &opts->gen.code; |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2209 //check supervisor bit in SR and trap if not in supervisor mode |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2210 bt_irdisp(code, BIT_SUPERVISOR, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2211 code_ptr in_sup_mode = code->cur + 1; |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2212 jcc(code, CC_C, code->cur + 2); |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2213 |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2214 ldi_native(opts, VECTOR_PRIV_VIOLATION, opts->gen.scratch2); |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2215 ldi_native(opts, inst->address, opts->gen.scratch1); |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2216 jmp(code, opts->trap); |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2217 |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2218 *in_sup_mode = code->cur - (in_sup_mode + 1); |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2219 } |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2220 |
584
b6713c1b6f55
Combine andi ccr/sr and ori ccr/sr.
Michael Pavone <pavone@retrodev.com>
parents:
583
diff
changeset
|
2221 void translate_m68k_andi_ori_ccr_sr(m68k_options *opts, m68kinst *inst) |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2222 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2223 code_info *code = &opts->gen.code; |
990
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2224 if (inst->op == M68K_ANDI_SR || inst->op == M68K_ORI_SR) { |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2225 m68k_trap_if_not_supervisor(opts, inst); |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2226 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2227 cycles(&opts->gen, 20); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2228 uint32_t flag_mask = 0; |
584
b6713c1b6f55
Combine andi ccr/sr and ori ccr/sr.
Michael Pavone <pavone@retrodev.com>
parents:
583
diff
changeset
|
2229 uint32_t base_flag = inst->op == M68K_ANDI_SR || inst->op == M68K_ANDI_CCR ? X0 : X1; |
b6713c1b6f55
Combine andi ccr/sr and ori ccr/sr.
Michael Pavone <pavone@retrodev.com>
parents:
583
diff
changeset
|
2230 for (int i = 0; i < 5; i++) |
b6713c1b6f55
Combine andi ccr/sr and ori ccr/sr.
Michael Pavone <pavone@retrodev.com>
parents:
583
diff
changeset
|
2231 { |
757
483f7e7926a6
More clang warning cleanup
Michael Pavone <pavone@retrodev.com>
parents:
751
diff
changeset
|
2232 if ((base_flag == X0) ^ ((inst->src.params.immed & 1 << i) > 0)) |
584
b6713c1b6f55
Combine andi ccr/sr and ori ccr/sr.
Michael Pavone <pavone@retrodev.com>
parents:
583
diff
changeset
|
2233 { |
b6713c1b6f55
Combine andi ccr/sr and ori ccr/sr.
Michael Pavone <pavone@retrodev.com>
parents:
583
diff
changeset
|
2234 flag_mask |= base_flag << ((4 - i) * 3); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2235 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2236 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2237 update_flags(opts, flag_mask); |
584
b6713c1b6f55
Combine andi ccr/sr and ori ccr/sr.
Michael Pavone <pavone@retrodev.com>
parents:
583
diff
changeset
|
2238 if (inst->op == M68K_ANDI_SR || inst->op == M68K_ORI_SR) { |
b6713c1b6f55
Combine andi ccr/sr and ori ccr/sr.
Michael Pavone <pavone@retrodev.com>
parents:
583
diff
changeset
|
2239 if (inst->op == M68K_ANDI_SR) { |
b6713c1b6f55
Combine andi ccr/sr and ori ccr/sr.
Michael Pavone <pavone@retrodev.com>
parents:
583
diff
changeset
|
2240 and_irdisp(code, inst->src.params.immed >> 8, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2241 } else { |
584
b6713c1b6f55
Combine andi ccr/sr and ori ccr/sr.
Michael Pavone <pavone@retrodev.com>
parents:
583
diff
changeset
|
2242 or_irdisp(code, inst->src.params.immed >> 8, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2243 } |
605
49d9928353be
Fix a bug in ori to SR that was swapping USP and SSP inappropriately
Michael Pavone <pavone@retrodev.com>
parents:
601
diff
changeset
|
2244 if (inst->op == M68K_ANDI_SR && !(inst->src.params.immed & (1 << (BIT_SUPERVISOR + 8)))) { |
446
1e828ed04a7c
Implement 68K stop instruction
Mike Pavone <pavone@retrodev.com>
parents:
443
diff
changeset
|
2245 //leave supervisor mode |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
2246 swap_ssp_usp(opts); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2247 } |
584
b6713c1b6f55
Combine andi ccr/sr and ori ccr/sr.
Michael Pavone <pavone@retrodev.com>
parents:
583
diff
changeset
|
2248 if ((inst->op == M68K_ANDI_SR && (inst->src.params.immed & 0x700) != 0x700) |
1303
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2249 || (inst->op == M68K_ORI_SR && inst->src.params.immed & 0x8700)) { |
846
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
2250 if (inst->op == M68K_ANDI_SR) { |
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
2251 //set int pending flag in case we trigger an interrupt as a result of the mask change |
996
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
2252 mov_irdisp(code, INT_PENDING_SR_CHANGE, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
846
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
2253 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2254 call(code, opts->do_sync); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2255 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2256 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2257 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2258 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2259 void translate_m68k_eori_ccr_sr(m68k_options *opts, m68kinst *inst) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2260 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2261 code_info *code = &opts->gen.code; |
990
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2262 if (inst->op == M68K_EORI_SR) { |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2263 m68k_trap_if_not_supervisor(opts, inst); |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2264 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2265 cycles(&opts->gen, 20); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2266 if (inst->src.params.immed & 0x1) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2267 xor_flag(opts, 1, FLAG_C); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2268 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2269 if (inst->src.params.immed & 0x2) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2270 xor_flag(opts, 1, FLAG_V); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2271 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2272 if (inst->src.params.immed & 0x4) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2273 xor_flag(opts, 1, FLAG_Z); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2274 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2275 if (inst->src.params.immed & 0x8) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2276 xor_flag(opts, 1, FLAG_N); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2277 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2278 if (inst->src.params.immed & 0x10) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2279 xor_flag(opts, 1, FLAG_X); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2280 } |
846
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
2281 if (inst->op == M68K_EORI_SR) { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2282 xor_irdisp(code, inst->src.params.immed >> 8, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
1304
5b90d7669eee
Fix exit trace mode edge case. Call do_sync if trace mode bit is changed in eori sr
Michael Pavone <pavone@retrodev.com>
parents:
1303
diff
changeset
|
2283 if (inst->src.params.immed & 0x8700) { |
846
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
2284 //set int pending flag in case we trigger an interrupt as a result of the mask change |
996
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
2285 mov_irdisp(code, INT_PENDING_SR_CHANGE, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2286 call(code, opts->do_sync); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2287 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2288 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2289 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2290 |
586
aa35ccb90aa9
Minor refactor to translate_m68k_move_ccr_sr and translate_m68k_stop to reduce code duplication
Michael Pavone <pavone@retrodev.com>
parents:
585
diff
changeset
|
2291 void set_all_flags(m68k_options *opts, uint8_t flags) |
aa35ccb90aa9
Minor refactor to translate_m68k_move_ccr_sr and translate_m68k_stop to reduce code duplication
Michael Pavone <pavone@retrodev.com>
parents:
585
diff
changeset
|
2292 { |
aa35ccb90aa9
Minor refactor to translate_m68k_move_ccr_sr and translate_m68k_stop to reduce code duplication
Michael Pavone <pavone@retrodev.com>
parents:
585
diff
changeset
|
2293 uint32_t flag_mask = flags & 0x10 ? X1 : X0; |
aa35ccb90aa9
Minor refactor to translate_m68k_move_ccr_sr and translate_m68k_stop to reduce code duplication
Michael Pavone <pavone@retrodev.com>
parents:
585
diff
changeset
|
2294 flag_mask |= flags & 0x8 ? N1 : N0; |
aa35ccb90aa9
Minor refactor to translate_m68k_move_ccr_sr and translate_m68k_stop to reduce code duplication
Michael Pavone <pavone@retrodev.com>
parents:
585
diff
changeset
|
2295 flag_mask |= flags & 0x4 ? Z1 : Z0; |
aa35ccb90aa9
Minor refactor to translate_m68k_move_ccr_sr and translate_m68k_stop to reduce code duplication
Michael Pavone <pavone@retrodev.com>
parents:
585
diff
changeset
|
2296 flag_mask |= flags & 0x2 ? V1 : V0; |
aa35ccb90aa9
Minor refactor to translate_m68k_move_ccr_sr and translate_m68k_stop to reduce code duplication
Michael Pavone <pavone@retrodev.com>
parents:
585
diff
changeset
|
2297 flag_mask |= flags & 0x1 ? C1 : C0; |
aa35ccb90aa9
Minor refactor to translate_m68k_move_ccr_sr and translate_m68k_stop to reduce code duplication
Michael Pavone <pavone@retrodev.com>
parents:
585
diff
changeset
|
2298 update_flags(opts, flag_mask); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2299 } |
586
aa35ccb90aa9
Minor refactor to translate_m68k_move_ccr_sr and translate_m68k_stop to reduce code duplication
Michael Pavone <pavone@retrodev.com>
parents:
585
diff
changeset
|
2300 |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2301 void translate_m68k_move_ccr_sr(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2302 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2303 code_info *code = &opts->gen.code; |
990
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2304 if (inst->op == M68K_MOVE_SR) { |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2305 m68k_trap_if_not_supervisor(opts, inst); |
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2306 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2307 if (src_op->mode == MODE_IMMED) { |
586
aa35ccb90aa9
Minor refactor to translate_m68k_move_ccr_sr and translate_m68k_stop to reduce code duplication
Michael Pavone <pavone@retrodev.com>
parents:
585
diff
changeset
|
2308 set_all_flags(opts, src_op->disp); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2309 if (inst->op == M68K_MOVE_SR) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2310 mov_irdisp(code, (src_op->disp >> 8), opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2311 if (!((inst->src.params.immed >> 8) & (1 << BIT_SUPERVISOR))) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2312 //leave supervisor mode |
585
82aadd5d103a
Use swap_ssp_usp in translate_m68k_move_ccr_sr
Michael Pavone <pavone@retrodev.com>
parents:
584
diff
changeset
|
2313 swap_ssp_usp(opts); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2314 } |
846
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
2315 if (((src_op->disp >> 8) & 7) < 7) { |
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
2316 //set int pending flag in case we trigger an interrupt as a result of the mask change |
996
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
2317 mov_irdisp(code, INT_PENDING_SR_CHANGE, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
846
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
2318 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2319 call(code, opts->do_sync); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2320 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2321 cycles(&opts->gen, 12); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2322 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2323 if (src_op->base != opts->gen.scratch1) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2324 if (src_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2325 mov_rr(code, src_op->base, opts->gen.scratch1, SZ_W); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2326 } else { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2327 mov_rdispr(code, src_op->base, src_op->disp, opts->gen.scratch1, SZ_W); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2328 } |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2329 } |
698
0a86e81fa87d
Fixed a missed call to do_sync when updating SR in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
690
diff
changeset
|
2330 if (inst->op == M68K_MOVE_SR) { |
0a86e81fa87d
Fixed a missed call to do_sync when updating SR in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
690
diff
changeset
|
2331 call(code, opts->set_sr); |
0a86e81fa87d
Fixed a missed call to do_sync when updating SR in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
690
diff
changeset
|
2332 call(code, opts->do_sync); |
0a86e81fa87d
Fixed a missed call to do_sync when updating SR in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
690
diff
changeset
|
2333 } else { |
0a86e81fa87d
Fixed a missed call to do_sync when updating SR in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
690
diff
changeset
|
2334 call(code, opts->set_ccr); |
0a86e81fa87d
Fixed a missed call to do_sync when updating SR in 68K core
Michael Pavone <pavone@retrodev.com>
parents:
690
diff
changeset
|
2335 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2336 cycles(&opts->gen, 12); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2337 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2338 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2339 |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2340 void translate_m68k_stop(m68k_options *opts, m68kinst *inst) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2341 { |
990
33a46d35b913
Implement privelege violation exceptions
Michael Pavone <pavone@retrodev.com>
parents:
989
diff
changeset
|
2342 m68k_trap_if_not_supervisor(opts, inst); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2343 //manual says 4 cycles, but it has to be at least 8 since it's a 2-word instruction |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2344 //possibly even 12 since that's how long MOVE to SR takes |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2345 //On further thought prefetch + the fact that this stops the CPU may make |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2346 //Motorola's accounting make sense here |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2347 code_info *code = &opts->gen.code; |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2348 cycles(&opts->gen, BUS*2); |
586
aa35ccb90aa9
Minor refactor to translate_m68k_move_ccr_sr and translate_m68k_stop to reduce code duplication
Michael Pavone <pavone@retrodev.com>
parents:
585
diff
changeset
|
2349 set_all_flags(opts, inst->src.params.immed); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2350 mov_irdisp(code, (inst->src.params.immed >> 8), opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2351 if (!((inst->src.params.immed >> 8) & (1 << BIT_SUPERVISOR))) { |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2352 //leave supervisor mode |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2353 swap_ssp_usp(opts); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2354 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2355 code_ptr loop_top = code->cur; |
985
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2356 call(code, opts->do_sync); |
1510
5eb954b76e65
Fix silly bug in STOP implementation that caused excessive CPU usage
Michael Pavone <pavone@retrodev.com>
parents:
1466
diff
changeset
|
2357 cmp_rr(code, opts->gen.cycles, opts->gen.limit, SZ_D); |
985
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2358 code_ptr normal_cycle_up = code->cur + 1; |
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2359 jcc(code, CC_A, code->cur + 2); |
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2360 cycles(&opts->gen, BUS); |
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2361 code_ptr after_cycle_up = code->cur + 1; |
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2362 jmp(code, code->cur + 2); |
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2363 *normal_cycle_up = code->cur - (normal_cycle_up + 1); |
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2364 mov_rr(code, opts->gen.limit, opts->gen.cycles, SZ_D); |
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2365 *after_cycle_up = code->cur - (after_cycle_up+1); |
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2366 cmp_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, int_cycle), opts->gen.cycles, SZ_D); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2367 jcc(code, CC_C, loop_top); |
985
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2368 //set int pending flag so interrupt fires immediately after stop is done |
996
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
2369 mov_irdisp(code, INT_PENDING_SR_CHANGE, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2370 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2371 |
839 | 2372 void translate_m68k_trapv(m68k_options *opts, m68kinst *inst) |
2373 { | |
2374 code_info *code = &opts->gen.code; | |
2375 cycles(&opts->gen, BUS); | |
2376 flag_to_carry(opts, FLAG_V); | |
2377 code_ptr no_trap = code->cur + 1; | |
2378 jcc(code, CC_NC, no_trap); | |
2379 ldi_native(opts, VECTOR_TRAPV, opts->gen.scratch2); | |
2380 ldi_native(opts, inst->address+2, opts->gen.scratch1); | |
2381 jmp(code, opts->trap); | |
2382 *no_trap = code->cur - (no_trap + 1); | |
2383 } | |
2384 | |
987
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2385 void translate_m68k_odd(m68k_options *opts, m68kinst *inst) |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2386 { |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2387 code_info *code = &opts->gen.code; |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2388 //swap USP and SSP if not already in supervisor mode |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2389 check_user_mode_swap_ssp_usp(opts); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2390 //save PC |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2391 subi_areg(opts, 4, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2392 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2393 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, last_prefetch_address), opts->gen.scratch1, SZ_D); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2394 call(code, opts->write_32_lowfirst); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2395 //save status register |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2396 subi_areg(opts, 2, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2397 call(code, opts->get_sr); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2398 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2399 call(code, opts->write_16); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2400 //save instruction register |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2401 subi_areg(opts, 2, 7); |
989
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2402 //calculate IR |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2403 push_r(code, opts->gen.context_reg); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2404 call(code, opts->gen.save_context); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2405 call_args_abi(code, (code_ptr)m68k_get_ir, 1, opts->gen.context_reg); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2406 mov_rr(code, RAX, opts->gen.scratch1, SZ_W); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2407 pop_r(code, opts->gen.context_reg); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2408 push_r(code, RAX); //save it for use in the "info" word |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2409 call(code, opts->gen.load_context); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2410 //write it to the stack |
987
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2411 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2412 call(code, opts->write_16); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2413 //save access address |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2414 subi_areg(opts, 4, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2415 mov_ir(code, inst->address, opts->gen.scratch1, SZ_D); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2416 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2417 call(code, opts->write_32_lowfirst); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2418 //save FC, I/N and R/W word' |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2419 xor_rr(code, opts->gen.scratch1, opts->gen.scratch1, SZ_W); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2420 //FC3 is basically the same as the supervisor bit |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2421 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, status), opts->gen.scratch1, SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2422 shr_ir(code, 3, opts->gen.scratch1, SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2423 and_ir(code, 4, opts->gen.scratch1, SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2424 //set FC1 to one to indicate instruction fetch, and R/W to indicate read |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2425 or_ir(code, 0x12, opts->gen.scratch1, SZ_B); |
989
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2426 //set undefined bits to IR value |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2427 pop_r(code, opts->gen.scratch2); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2428 and_ir(code, 0xFFE0, opts->gen.scratch2, SZ_W); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2429 or_rr(code, opts->gen.scratch2, opts->gen.scratch1, SZ_W); |
987
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2430 subi_areg(opts, 2, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2431 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2432 call(code, opts->write_16); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2433 //set supervisor bit |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2434 or_irdisp(code, 0x20, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2435 //load vector address |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2436 mov_ir(code, 4 * VECTOR_ADDRESS_ERROR, opts->gen.scratch1, SZ_D); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2437 call(code, opts->read_32); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2438 call(code, opts->native_addr_and_sync); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2439 cycles(&opts->gen, 18); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2440 jmp_r(code, opts->gen.scratch1); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2441 } |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2442 |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2443 void translate_m68k_move_from_sr(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op) |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2444 { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2445 code_info *code = &opts->gen.code; |
1585
15116d4fdf40
Fix cycle counts for BCD instructions, RESET, and MOVE from SR
Michael Pavone <pavone@retrodev.com>
parents:
1584
diff
changeset
|
2446 cycles(&opts->gen, inst->dst.addr_mode == MODE_REG_DIRECT ? BUS+2 : BUS); |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2447 call(code, opts->get_sr); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2448 if (dst_op->mode == MODE_REG_DIRECT) { |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2449 mov_rr(code, opts->gen.scratch1, dst_op->base, SZ_W); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2450 } else { |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2451 mov_rrdisp(code, opts->gen.scratch1, dst_op->base, dst_op->disp, SZ_W); |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2452 } |
582
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2453 m68k_save_result(inst, opts); |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2454 } |
c05fcbfe1b1a
Refactored translate_m68k so that it contains no host-cpu specific code and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
581
diff
changeset
|
2455 |
1082
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
2456 void m68k_out_of_bounds_execution(uint32_t address) |
319
0bcab0475a7f
Port instruction retranslation improvements from Z80 core to M68K core
Mike Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
2457 { |
1082
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
2458 fatal_error("M68K attempted to execute code at unmapped or I/O address %X\n", address); |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
2459 } |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
2460 |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
2461 void translate_out_of_bounds(m68k_options *opts, uint32_t address) |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
2462 { |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
2463 code_info *code = &opts->gen.code; |
1228
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2464 check_cycles_int(&opts->gen, address); |
1082
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
2465 mov_ir(code, address, opts->gen.scratch1, SZ_D); |
2ec5e6eaf81d
Add support for specifying a reset handler in the M68K core. Adjust memory map initialization to handle extra field. Improved handling of out of bounds execution.
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
2466 call_args(code, (code_ptr)m68k_out_of_bounds_execution, 1, opts->gen.scratch1); |
319
0bcab0475a7f
Port instruction retranslation improvements from Z80 core to M68K core
Mike Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
2467 } |
0bcab0475a7f
Port instruction retranslation improvements from Z80 core to M68K core
Mike Pavone <pavone@retrodev.com>
parents:
235
diff
changeset
|
2468 |
981
902c53d9c16f
Half assed, prefetch based open bus value emulation. Gets BlastEm up to 119/122 in VDP FIFO Testing
Michael Pavone <pavone@retrodev.com>
parents:
979
diff
changeset
|
2469 void m68k_set_last_prefetch(m68k_options *opts, uint32_t address) |
902c53d9c16f
Half assed, prefetch based open bus value emulation. Gets BlastEm up to 119/122 in VDP FIFO Testing
Michael Pavone <pavone@retrodev.com>
parents:
979
diff
changeset
|
2470 { |
902c53d9c16f
Half assed, prefetch based open bus value emulation. Gets BlastEm up to 119/122 in VDP FIFO Testing
Michael Pavone <pavone@retrodev.com>
parents:
979
diff
changeset
|
2471 mov_irdisp(&opts->gen.code, address, opts->gen.context_reg, offsetof(m68k_context, last_prefetch_address), SZ_D); |
902c53d9c16f
Half assed, prefetch based open bus value emulation. Gets BlastEm up to 119/122 in VDP FIFO Testing
Michael Pavone <pavone@retrodev.com>
parents:
979
diff
changeset
|
2472 } |
902c53d9c16f
Half assed, prefetch based open bus value emulation. Gets BlastEm up to 119/122 in VDP FIFO Testing
Michael Pavone <pavone@retrodev.com>
parents:
979
diff
changeset
|
2473 |
587
55c5b0f913ce
Made m68k_retranslate_inst host-cpu generic and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
586
diff
changeset
|
2474 void nop_fill_or_jmp_next(code_info *code, code_ptr old_end, code_ptr next_inst) |
55c5b0f913ce
Made m68k_retranslate_inst host-cpu generic and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
586
diff
changeset
|
2475 { |
55c5b0f913ce
Made m68k_retranslate_inst host-cpu generic and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
586
diff
changeset
|
2476 if (next_inst == old_end && next_inst - code->cur < 2) { |
55c5b0f913ce
Made m68k_retranslate_inst host-cpu generic and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
586
diff
changeset
|
2477 while (code->cur < old_end) { |
55c5b0f913ce
Made m68k_retranslate_inst host-cpu generic and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
586
diff
changeset
|
2478 *(code->cur++) = 0x90; //NOP |
686
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2479 } |
8cb61671777b
Fix indentation that presumably got messed up in a merge
Michael Pavone <pavone@retrodev.com>
parents:
682
diff
changeset
|
2480 } else { |
587
55c5b0f913ce
Made m68k_retranslate_inst host-cpu generic and moved it to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
586
diff
changeset
|
2481 jmp(code, next_inst); |
193
c66e4636f991
Implement support for self-modifying code
Mike Pavone <pavone@retrodev.com>
parents:
192
diff
changeset
|
2482 } |
c66e4636f991
Implement support for self-modifying code
Mike Pavone <pavone@retrodev.com>
parents:
192
diff
changeset
|
2483 } |
c66e4636f991
Implement support for self-modifying code
Mike Pavone <pavone@retrodev.com>
parents:
192
diff
changeset
|
2484 |
1192
e0fc8967d380
Inefficient fix for overlapping instruction problem that was causing issues with Outrunners
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
2485 #define M68K_MAX_INST_SIZE (2*(1+2+2)) |
e0fc8967d380
Inefficient fix for overlapping instruction problem that was causing issues with Outrunners
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
2486 |
193
c66e4636f991
Implement support for self-modifying code
Mike Pavone <pavone@retrodev.com>
parents:
192
diff
changeset
|
2487 m68k_context * m68k_handle_code_write(uint32_t address, m68k_context * context) |
c66e4636f991
Implement support for self-modifying code
Mike Pavone <pavone@retrodev.com>
parents:
192
diff
changeset
|
2488 { |
985
751280fb4494
Fix interrupt latency from STOP instruction status reg changes. Fix modified code patching when non-standard aliases are used. This fixes the demo MDEM's First
Michael Pavone <pavone@retrodev.com>
parents:
981
diff
changeset
|
2489 m68k_options * options = context->options; |
1130
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
2490 uint32_t inst_start = get_instruction_start(options, address); |
1192
e0fc8967d380
Inefficient fix for overlapping instruction problem that was causing issues with Outrunners
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
2491 while (inst_start && (address - inst_start) < M68K_MAX_INST_SIZE) { |
726
7367b14ac01c
Don't attempt to translate or map code at odd addresses. This fixes a bug that shows up when playing College Footbal USA 96
Michael Pavone <pavone@retrodev.com>
parents:
698
diff
changeset
|
2492 code_ptr dst = get_native_address(context->options, inst_start); |
1465
5d41d0574863
Preserve original address when retranslating instructions instead of switching to the lowest alias
Michael Pavone <pavone@retrodev.com>
parents:
1461
diff
changeset
|
2493 patch_for_retranslate(&options->gen, dst, options->retrans_stub); |
1192
e0fc8967d380
Inefficient fix for overlapping instruction problem that was causing issues with Outrunners
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
2494 inst_start = get_instruction_start(options, inst_start - 2); |
193
c66e4636f991
Implement support for self-modifying code
Mike Pavone <pavone@retrodev.com>
parents:
192
diff
changeset
|
2495 } |
c66e4636f991
Implement support for self-modifying code
Mike Pavone <pavone@retrodev.com>
parents:
192
diff
changeset
|
2496 return context; |
c66e4636f991
Implement support for self-modifying code
Mike Pavone <pavone@retrodev.com>
parents:
192
diff
changeset
|
2497 } |
c66e4636f991
Implement support for self-modifying code
Mike Pavone <pavone@retrodev.com>
parents:
192
diff
changeset
|
2498 |
1228
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2499 void m68k_invalidate_code_range(m68k_context *context, uint32_t start, uint32_t end) |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2500 { |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2501 m68k_options *opts = context->options; |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2502 native_map_slot *native_code_map = opts->gen.native_code_map; |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2503 memmap_chunk const *mem_chunk = find_map_chunk(start, &opts->gen, 0, NULL); |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2504 if (mem_chunk) { |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2505 //calculate the lowest alias for this address |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2506 start = mem_chunk->start + ((start - mem_chunk->start) & mem_chunk->mask); |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2507 } |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2508 mem_chunk = find_map_chunk(end, &opts->gen, 0, NULL); |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2509 if (mem_chunk) { |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2510 //calculate the lowest alias for this address |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2511 end = mem_chunk->start + ((end - mem_chunk->start) & mem_chunk->mask); |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2512 } |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2513 uint32_t start_chunk = start / NATIVE_CHUNK_SIZE, end_chunk = end / NATIVE_CHUNK_SIZE; |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2514 for (uint32_t chunk = start_chunk; chunk <= end_chunk; chunk++) |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2515 { |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2516 if (native_code_map[chunk].base) { |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2517 uint32_t start_offset = chunk == start_chunk ? start % NATIVE_CHUNK_SIZE : 0; |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2518 uint32_t end_offset = chunk == end_chunk ? end % NATIVE_CHUNK_SIZE : NATIVE_CHUNK_SIZE; |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2519 for (uint32_t offset = start_offset; offset < end_offset; offset++) |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2520 { |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2521 if (native_code_map[chunk].offsets[offset] != INVALID_OFFSET && native_code_map[chunk].offsets[offset] != EXTENSION_WORD) { |
1465
5d41d0574863
Preserve original address when retranslating instructions instead of switching to the lowest alias
Michael Pavone <pavone@retrodev.com>
parents:
1461
diff
changeset
|
2522 patch_for_retranslate(&opts->gen, native_code_map[chunk].base + native_code_map[chunk].offsets[offset], opts->retrans_stub); |
5d41d0574863
Preserve original address when retranslating instructions instead of switching to the lowest alias
Michael Pavone <pavone@retrodev.com>
parents:
1461
diff
changeset
|
2523 /*code_info code; |
1228
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2524 code.cur = native_code_map[chunk].base + native_code_map[chunk].offsets[offset]; |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2525 code.last = code.cur + 32; |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2526 code.stack_off = 0; |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2527 mov_ir(&code, chunk * NATIVE_CHUNK_SIZE + offset, opts->gen.scratch2, SZ_D); |
1465
5d41d0574863
Preserve original address when retranslating instructions instead of switching to the lowest alias
Michael Pavone <pavone@retrodev.com>
parents:
1461
diff
changeset
|
2528 jmp(&code, opts->retrans_stub);*/ |
1228
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2529 } |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2530 } |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2531 } |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2532 } |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2533 } |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
2534 |
1329
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2535 void m68k_breakpoint_patch(m68k_context *context, uint32_t address, m68k_debug_handler bp_handler, code_ptr native_addr) |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
183
diff
changeset
|
2536 { |
569
9b7fcf748be0
Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents:
567
diff
changeset
|
2537 m68k_options * opts = context->options; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2538 code_info native; |
1329
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2539 native.cur = native_addr ? native_addr : get_native_address(context->options, address); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2540 |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2541 if (!native.cur) { |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2542 return; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2543 } |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2544 |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2545 if (*native.cur != opts->prologue_start) { |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2546 //instruction has already been patched, probably for retranslation |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2547 return; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2548 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2549 native.last = native.cur + 128; |
908
20e30ca7e8a2
Fix problem in 68K debugger caused by stack alignment change
Michael Pavone <pavone@retrodev.com>
parents:
902
diff
changeset
|
2550 native.stack_off = 0; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2551 code_ptr start_native = native.cur; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2552 mov_ir(&native, address, opts->gen.scratch1, SZ_D); |
1329
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2553 |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2554 |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
2555 call(&native, opts->bp_stub); |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
183
diff
changeset
|
2556 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
183
diff
changeset
|
2557 |
667
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
2558 void init_m68k_opts(m68k_options * opts, memmap_chunk * memmap, uint32_t num_chunks, uint32_t clock_divider) |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
2559 { |
440 | 2560 memset(opts, 0, sizeof(*opts)); |
653
a18e3923481e
Remove some of the hard coded assumptions about the memory map from the CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
620
diff
changeset
|
2561 opts->gen.memmap = memmap; |
a18e3923481e
Remove some of the hard coded assumptions about the memory map from the CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
620
diff
changeset
|
2562 opts->gen.memmap_chunks = num_chunks; |
589
2dde38c1744f
Split gen_mem_fun out of m68k_core_x86 and make it more generic so it can be used by the Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
588
diff
changeset
|
2563 opts->gen.address_size = SZ_D; |
2dde38c1744f
Split gen_mem_fun out of m68k_core_x86 and make it more generic so it can be used by the Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
588
diff
changeset
|
2564 opts->gen.address_mask = 0xFFFFFF; |
596
9853bcce4729
Set the byte_swap flag in the M68K core so gen_mem_fun correctly inserts xor instructions for byte access functions
Michael Pavone <pavone@retrodev.com>
parents:
590
diff
changeset
|
2565 opts->gen.byte_swap = 1; |
589
2dde38c1744f
Split gen_mem_fun out of m68k_core_x86 and make it more generic so it can be used by the Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
588
diff
changeset
|
2566 opts->gen.max_address = 0x1000000; |
2dde38c1744f
Split gen_mem_fun out of m68k_core_x86 and make it more generic so it can be used by the Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
588
diff
changeset
|
2567 opts->gen.bus_cycles = BUS; |
667
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
2568 opts->gen.clock_divider = clock_divider; |
589
2dde38c1744f
Split gen_mem_fun out of m68k_core_x86 and make it more generic so it can be used by the Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
588
diff
changeset
|
2569 opts->gen.mem_ptr_off = offsetof(m68k_context, mem_pointers); |
2dde38c1744f
Split gen_mem_fun out of m68k_core_x86 and make it more generic so it can be used by the Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
588
diff
changeset
|
2570 opts->gen.ram_flags_off = offsetof(m68k_context, ram_code_flags); |
620
9d6fed6501ba
Fix handling of code writes for Z80 core. This seems to get things close to being back to where they were before the big refactor that broke the Z80 core. Some problems remain. Notably the sound driver in Sonic 2 is still quite broken.
Michael Pavone <pavone@retrodev.com>
parents:
612
diff
changeset
|
2571 opts->gen.ram_flags_shift = 11; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
2572 for (int i = 0; i < 8; i++) |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2573 { |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
2574 opts->dregs[i] = opts->aregs[i] = -1; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2575 } |
548
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
547
diff
changeset
|
2576 #ifdef X86_64 |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
2577 opts->dregs[0] = R10; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
2578 opts->dregs[1] = R11; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
2579 opts->dregs[2] = R12; |
423
8e136187c0e0
Use the registers that were freed up by the memory map function changes
Mike Pavone <pavone@retrodev.com>
parents:
352
diff
changeset
|
2580 opts->dregs[3] = R8; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
2581 opts->aregs[0] = R13; |
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
2582 opts->aregs[1] = R14; |
423
8e136187c0e0
Use the registers that were freed up by the memory map function changes
Mike Pavone <pavone@retrodev.com>
parents:
352
diff
changeset
|
2583 opts->aregs[2] = R9; |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
2584 opts->aregs[7] = R15; |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2585 |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2586 opts->flag_regs[0] = -1; |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2587 opts->flag_regs[1] = RBX; |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2588 opts->flag_regs[2] = RDX; |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2589 opts->flag_regs[3] = BH; |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2590 opts->flag_regs[4] = DH; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2591 |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2592 opts->gen.scratch2 = RDI; |
548
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
547
diff
changeset
|
2593 #else |
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
547
diff
changeset
|
2594 opts->dregs[0] = RDX; |
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
547
diff
changeset
|
2595 opts->aregs[7] = RDI; |
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
547
diff
changeset
|
2596 |
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
547
diff
changeset
|
2597 for (int i = 0; i < 5; i++) |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2598 { |
548
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
547
diff
changeset
|
2599 opts->flag_regs[i] = -1; |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2600 } |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2601 opts->gen.scratch2 = RBX; |
548
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
547
diff
changeset
|
2602 #endif |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2603 opts->gen.context_reg = RSI; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2604 opts->gen.cycles = RAX; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2605 opts->gen.limit = RBP; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2606 opts->gen.scratch1 = RCX; |
987
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2607 opts->gen.align_error_mask = 1; |
548
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
547
diff
changeset
|
2608 |
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
547
diff
changeset
|
2609 |
558
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
2610 opts->gen.native_code_map = malloc(sizeof(native_map_slot) * NATIVE_MAP_CHUNKS); |
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
2611 memset(opts->gen.native_code_map, 0, sizeof(native_map_slot) * NATIVE_MAP_CHUNKS); |
dc9f178085a0
Use a typedef code_ptr in place of uint8_t * in 68K core to better support host instruction sets with different instruction word sizes. Make x86_68k_options contain a cpu_options so that gen_mem_fun can eventually be shared with the Z80 core.
Mike Pavone <pavone@retrodev.com>
parents:
557
diff
changeset
|
2612 opts->gen.deferred = NULL; |
690
fc04781f4d28
Removed hardcoded assumptions in M68K core about which parts of the memory map are RAM
Michael Pavone <pavone@retrodev.com>
parents:
689
diff
changeset
|
2613 |
fc04781f4d28
Removed hardcoded assumptions in M68K core about which parts of the memory map are RAM
Michael Pavone <pavone@retrodev.com>
parents:
689
diff
changeset
|
2614 uint32_t inst_size_size = sizeof(uint8_t *) * ram_size(&opts->gen) / 1024; |
fc04781f4d28
Removed hardcoded assumptions in M68K core about which parts of the memory map are RAM
Michael Pavone <pavone@retrodev.com>
parents:
689
diff
changeset
|
2615 opts->gen.ram_inst_sizes = malloc(inst_size_size); |
fc04781f4d28
Removed hardcoded assumptions in M68K core about which parts of the memory map are RAM
Michael Pavone <pavone@retrodev.com>
parents:
689
diff
changeset
|
2616 memset(opts->gen.ram_inst_sizes, 0, inst_size_size); |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
2617 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2618 code_info *code = &opts->gen.code; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2619 init_code_info(code); |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2620 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2621 opts->gen.save_context = code->cur; |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2622 for (int i = 0; i < 5; i++) |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2623 if (opts->flag_regs[i] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2624 mov_rrdisp(code, opts->flag_regs[i], opts->gen.context_reg, offsetof(m68k_context, flags) + i, SZ_B); |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2625 } |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2626 for (int i = 0; i < 8; i++) |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2627 { |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2628 if (opts->dregs[i] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2629 mov_rrdisp(code, opts->dregs[i], opts->gen.context_reg, offsetof(m68k_context, dregs) + sizeof(uint32_t) * i, SZ_D); |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2630 } |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2631 if (opts->aregs[i] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2632 mov_rrdisp(code, opts->aregs[i], opts->gen.context_reg, offsetof(m68k_context, aregs) + sizeof(uint32_t) * i, SZ_D); |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2633 } |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2634 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2635 mov_rrdisp(code, opts->gen.cycles, opts->gen.context_reg, offsetof(m68k_context, current_cycle), SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2636 retn(code); |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2637 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2638 opts->gen.load_context = code->cur; |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2639 for (int i = 0; i < 5; i++) |
690
fc04781f4d28
Removed hardcoded assumptions in M68K core about which parts of the memory map are RAM
Michael Pavone <pavone@retrodev.com>
parents:
689
diff
changeset
|
2640 { |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2641 if (opts->flag_regs[i] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2642 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, flags) + i, opts->flag_regs[i], SZ_B); |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2643 } |
690
fc04781f4d28
Removed hardcoded assumptions in M68K core about which parts of the memory map are RAM
Michael Pavone <pavone@retrodev.com>
parents:
689
diff
changeset
|
2644 } |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2645 for (int i = 0; i < 8; i++) |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2646 { |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2647 if (opts->dregs[i] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2648 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, dregs) + sizeof(uint32_t) * i, opts->dregs[i], SZ_D); |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2649 } |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2650 if (opts->aregs[i] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2651 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, aregs) + sizeof(uint32_t) * i, opts->aregs[i], SZ_D); |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2652 } |
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2653 } |
656
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2654 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, current_cycle), opts->gen.cycles, SZ_D); |
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2655 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, target_cycle), opts->gen.limit, SZ_D); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2656 retn(code); |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2657 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2658 opts->start_context = (start_fun)code->cur; |
665
d0943769353b
Added functions to gen_x86 for saving and restoring callee save registers to better abstract over ABI differences between x86 and x86-64
Michael Pavone <pavone@retrodev.com>
parents:
657
diff
changeset
|
2659 save_callee_save_regs(code); |
550
96489fb27dbf
Apart from the Z80 core, BlastEm now supports 32-bit x86
Michael Pavone <pavone@retrodev.com>
parents:
548
diff
changeset
|
2660 #ifdef X86_64 |
1828
37afb9cf58be
Get 64-bit builds working for Windows target
Michael Pavone <pavone@retrodev.com>
parents:
1585
diff
changeset
|
2661 if (opts->gen.scratch2 != FIRST_ARG_REG) { |
37afb9cf58be
Get 64-bit builds working for Windows target
Michael Pavone <pavone@retrodev.com>
parents:
1585
diff
changeset
|
2662 mov_rr(code, FIRST_ARG_REG, opts->gen.scratch2, SZ_PTR); |
37afb9cf58be
Get 64-bit builds working for Windows target
Michael Pavone <pavone@retrodev.com>
parents:
1585
diff
changeset
|
2663 } |
37afb9cf58be
Get 64-bit builds working for Windows target
Michael Pavone <pavone@retrodev.com>
parents:
1585
diff
changeset
|
2664 if (opts->gen.context_reg != SECOND_ARG_REG) { |
37afb9cf58be
Get 64-bit builds working for Windows target
Michael Pavone <pavone@retrodev.com>
parents:
1585
diff
changeset
|
2665 mov_rr(code, SECOND_ARG_REG, opts->gen.context_reg, SZ_PTR); |
548
a3afee2271ce
Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents:
547
diff
changeset
|
2666 } |
550
96489fb27dbf
Apart from the Z80 core, BlastEm now supports 32-bit x86
Michael Pavone <pavone@retrodev.com>
parents:
548
diff
changeset
|
2667 #else |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2668 mov_rdispr(code, RSP, 20, opts->gen.scratch2, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2669 mov_rdispr(code, RSP, 24, opts->gen.context_reg, SZ_D); |
550
96489fb27dbf
Apart from the Z80 core, BlastEm now supports 32-bit x86
Michael Pavone <pavone@retrodev.com>
parents:
548
diff
changeset
|
2670 #endif |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2671 call(code, opts->gen.load_context); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2672 call_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2673 call(code, opts->gen.save_context); |
665
d0943769353b
Added functions to gen_x86 for saving and restoring callee save registers to better abstract over ABI differences between x86 and x86-64
Michael Pavone <pavone@retrodev.com>
parents:
657
diff
changeset
|
2674 restore_callee_save_regs(code); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2675 retn(code); |
540
4ca826862174
Generate m68k_start_context at runtime so it can use the generated load_context and save_context
Michael Pavone <pavone@retrodev.com>
parents:
539
diff
changeset
|
2676 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2677 opts->native_addr = code->cur; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2678 call(code, opts->gen.save_context); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2679 push_r(code, opts->gen.context_reg); |
656
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2680 call_args(code, (code_ptr)get_native_address_trans, 2, opts->gen.context_reg, opts->gen.scratch1); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2681 mov_rr(code, RAX, opts->gen.scratch1, SZ_PTR); //move result to scratch reg |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2682 pop_r(code, opts->gen.context_reg); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2683 call(code, opts->gen.load_context); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2684 retn(code); |
544
8a26567852b7
Generate native_addr and native_addr_and_sync at runtime so they can use the generated save/load_context functions
Michael Pavone <pavone@retrodev.com>
parents:
543
diff
changeset
|
2685 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2686 opts->native_addr_and_sync = code->cur; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2687 call(code, opts->gen.save_context); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2688 push_r(code, opts->gen.scratch1); |
667
30ccf56842d6
All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents:
665
diff
changeset
|
2689 |
656
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2690 xor_rr(code, opts->gen.scratch1, opts->gen.scratch1, SZ_D); |
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2691 call_args_abi(code, (code_ptr)sync_components, 2, opts->gen.context_reg, opts->gen.scratch1); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2692 pop_r(code, RSI); //restore saved address from opts->gen.scratch1 |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2693 push_r(code, RAX); //save context pointer for later |
656
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2694 call_args(code, (code_ptr)get_native_address_trans, 2, RAX, RSI); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2695 mov_rr(code, RAX, opts->gen.scratch1, SZ_PTR); //move result to scratch reg |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2696 pop_r(code, opts->gen.context_reg); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2697 call(code, opts->gen.load_context); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2698 retn(code); |
544
8a26567852b7
Generate native_addr and native_addr_and_sync at runtime so they can use the generated save/load_context functions
Michael Pavone <pavone@retrodev.com>
parents:
543
diff
changeset
|
2699 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2700 opts->gen.handle_cycle_limit = code->cur; |
656
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2701 cmp_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, sync_cycle), opts->gen.cycles, SZ_D); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2702 code_ptr skip_sync = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2703 jcc(code, CC_C, code->cur + 2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2704 opts->do_sync = code->cur; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2705 push_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2706 push_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2707 call(code, opts->gen.save_context); |
656
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2708 xor_rr(code, opts->gen.scratch1, opts->gen.scratch1, SZ_D); |
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2709 call_args_abi(code, (code_ptr)sync_components, 2, opts->gen.context_reg, opts->gen.scratch1); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2710 mov_rr(code, RAX, opts->gen.context_reg, SZ_PTR); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2711 call(code, opts->gen.load_context); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2712 pop_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2713 pop_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2714 *skip_sync = code->cur - (skip_sync+1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2715 retn(code); |
539
c2716b502a81
Generate save_context and load_context functions at runtime
Michael Pavone <pavone@retrodev.com>
parents:
516
diff
changeset
|
2716 |
590
ea80559c67cb
WIP effort to update z80 core for code gen changes
Michael Pavone <pavone@retrodev.com>
parents:
589
diff
changeset
|
2717 opts->gen.handle_code_write = (code_ptr)m68k_handle_code_write; |
987
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2718 |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2719 check_alloc_code(code, 256); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2720 opts->gen.handle_align_error_write = code->cur; |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2721 code->cur += 256; |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2722 check_alloc_code(code, 256); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2723 opts->gen.handle_align_error_read = code->cur; |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2724 code->cur += 256; |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2725 |
590
ea80559c67cb
WIP effort to update z80 core for code gen changes
Michael Pavone <pavone@retrodev.com>
parents:
589
diff
changeset
|
2726 opts->read_16 = gen_mem_fun(&opts->gen, memmap, num_chunks, READ_16, NULL); |
ea80559c67cb
WIP effort to update z80 core for code gen changes
Michael Pavone <pavone@retrodev.com>
parents:
589
diff
changeset
|
2727 opts->read_8 = gen_mem_fun(&opts->gen, memmap, num_chunks, READ_8, NULL); |
ea80559c67cb
WIP effort to update z80 core for code gen changes
Michael Pavone <pavone@retrodev.com>
parents:
589
diff
changeset
|
2728 opts->write_16 = gen_mem_fun(&opts->gen, memmap, num_chunks, WRITE_16, NULL); |
ea80559c67cb
WIP effort to update z80 core for code gen changes
Michael Pavone <pavone@retrodev.com>
parents:
589
diff
changeset
|
2729 opts->write_8 = gen_mem_fun(&opts->gen, memmap, num_chunks, WRITE_8, NULL); |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
2730 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2731 opts->read_32 = code->cur; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2732 push_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2733 call(code, opts->read_16); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2734 mov_rr(code, opts->gen.scratch1, opts->gen.scratch2, SZ_W); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2735 pop_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2736 push_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2737 add_ir(code, 2, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2738 call(code, opts->read_16); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2739 pop_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2740 movzx_rr(code, opts->gen.scratch1, opts->gen.scratch1, SZ_W, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2741 shl_ir(code, 16, opts->gen.scratch2, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2742 or_rr(code, opts->gen.scratch2, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2743 retn(code); |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
2744 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2745 opts->write_32_lowfirst = code->cur; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2746 push_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2747 push_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2748 add_ir(code, 2, opts->gen.scratch2, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2749 call(code, opts->write_16); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2750 pop_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2751 pop_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2752 shr_ir(code, 16, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2753 jmp(code, opts->write_16); |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
2754 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2755 opts->write_32_highfirst = code->cur; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2756 push_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2757 push_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2758 shr_ir(code, 16, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2759 call(code, opts->write_16); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2760 pop_r(code, opts->gen.scratch2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2761 pop_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2762 add_ir(code, 2, opts->gen.scratch2, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2763 jmp(code, opts->write_16); |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
2764 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2765 opts->get_sr = code->cur; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2766 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, status), opts->gen.scratch1, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2767 shl_ir(code, 8, opts->gen.scratch1, SZ_W); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2768 if (opts->flag_regs[FLAG_X] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2769 mov_rr(code, opts->flag_regs[FLAG_X], opts->gen.scratch1, SZ_B); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2770 } else { |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2771 int8_t offset = offsetof(m68k_context, flags); |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2772 if (offset) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2773 mov_rdispr(code, opts->gen.context_reg, offset, opts->gen.scratch1, SZ_B); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2774 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2775 mov_rindr(code, opts->gen.context_reg, opts->gen.scratch1, SZ_B); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2776 } |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2777 } |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2778 for (int flag = FLAG_N; flag <= FLAG_C; flag++) |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2779 { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2780 shl_ir(code, 1, opts->gen.scratch1, SZ_B); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2781 if (opts->flag_regs[flag] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2782 or_rr(code, opts->flag_regs[flag], opts->gen.scratch1, SZ_B); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2783 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2784 or_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, flags) + flag, opts->gen.scratch1, SZ_B); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2785 } |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2786 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2787 retn(code); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2788 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2789 opts->set_sr = code->cur; |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2790 for (int flag = FLAG_C; flag >= FLAG_X; flag--) |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2791 { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2792 rcr_ir(code, 1, opts->gen.scratch1, SZ_B); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2793 if (opts->flag_regs[flag] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2794 setcc_r(code, CC_C, opts->flag_regs[flag]); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2795 } else { |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2796 int8_t offset = offsetof(m68k_context, flags) + flag; |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2797 if (offset) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2798 setcc_rdisp(code, CC_C, opts->gen.context_reg, offset); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2799 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2800 setcc_rind(code, CC_C, opts->gen.context_reg); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2801 } |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2802 } |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2803 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2804 shr_ir(code, 8, opts->gen.scratch1, SZ_W); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2805 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
846
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
2806 //set int pending flag in case we trigger an interrupt as a result of the mask change |
996
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
2807 mov_irdisp(code, INT_PENDING_SR_CHANGE, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2808 retn(code); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2809 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2810 opts->set_ccr = code->cur; |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2811 for (int flag = FLAG_C; flag >= FLAG_X; flag--) |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2812 { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2813 rcr_ir(code, 1, opts->gen.scratch1, SZ_B); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2814 if (opts->flag_regs[flag] >= 0) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2815 setcc_r(code, CC_C, opts->flag_regs[flag]); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2816 } else { |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2817 int8_t offset = offsetof(m68k_context, flags) + flag; |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2818 if (offset) { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2819 setcc_rdisp(code, CC_C, opts->gen.context_reg, offset); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2820 } else { |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2821 setcc_rind(code, CC_C, opts->gen.context_reg); |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2822 } |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2823 } |
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2824 } |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2825 retn(code); |
987
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2826 |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2827 code_info tmp_code = *code; |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2828 code->cur = opts->gen.handle_align_error_write; |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2829 code->last = code->cur + 256; |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2830 //unwind the stack one functinon call |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2831 add_ir(code, 16, RSP, SZ_PTR); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2832 //save address that triggered error so we can write it to the 68K stack at the appropriate place |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2833 push_r(code, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2834 //swap USP and SSP if not already in supervisor mode |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2835 check_user_mode_swap_ssp_usp(opts); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2836 //save PC |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2837 subi_areg(opts, 4, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2838 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2839 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, last_prefetch_address), opts->gen.scratch1, SZ_D); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2840 call(code, opts->write_32_lowfirst); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2841 //save status register |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2842 subi_areg(opts, 2, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2843 call(code, opts->get_sr); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2844 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2845 call(code, opts->write_16); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2846 //save instruction register |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2847 subi_areg(opts, 2, 7); |
989
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2848 //calculate IR |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2849 push_r(code, opts->gen.context_reg); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2850 call(code, opts->gen.save_context); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2851 call_args_abi(code, (code_ptr)m68k_get_ir, 1, opts->gen.context_reg); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2852 mov_rr(code, RAX, opts->gen.scratch1, SZ_W); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2853 pop_r(code, opts->gen.context_reg); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2854 pop_r(code, opts->gen.scratch2); //access address |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2855 push_r(code, RAX); //save it for use in the "info" word |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2856 push_r(code, opts->gen.scratch2); //access address |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2857 call(code, opts->gen.load_context); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2858 //write it to the stack |
987
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2859 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2860 call(code, opts->write_16); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2861 //save access address |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2862 subi_areg(opts, 4, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2863 pop_r(code, opts->gen.scratch1); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2864 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2865 call(code, opts->write_32_lowfirst); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2866 //save FC, I/N and R/W word' |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2867 xor_rr(code, opts->gen.scratch1, opts->gen.scratch1, SZ_W); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2868 //FC3 is basically the same as the supervisor bit |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2869 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, status), opts->gen.scratch1, SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2870 shr_ir(code, 3, opts->gen.scratch1, SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2871 and_ir(code, 4, opts->gen.scratch1, SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2872 //set FC0 to one to indicate data access |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2873 or_ir(code, 1, opts->gen.scratch1, SZ_B); |
989
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2874 //set undefined bits to IR value |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2875 pop_r(code, opts->gen.scratch2); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2876 and_ir(code, 0xFFE0, opts->gen.scratch2, SZ_W); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2877 or_rr(code, opts->gen.scratch2, opts->gen.scratch1, SZ_W); |
987
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2878 subi_areg(opts, 2, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2879 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2880 call(code, opts->write_16); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2881 //set supervisor bit |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2882 or_irdisp(code, 0x20, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2883 //load vector address |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2884 mov_ir(code, 4 * VECTOR_ADDRESS_ERROR, opts->gen.scratch1, SZ_D); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2885 call(code, opts->read_32); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2886 call(code, opts->native_addr_and_sync); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2887 cycles(&opts->gen, 18); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2888 jmp_r(code, opts->gen.scratch1); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2889 |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2890 code->cur = opts->gen.handle_align_error_read; |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2891 code->last = code->cur + 256; |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2892 //unwind the stack one functinon call |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2893 add_ir(code, 16, RSP, SZ_PTR); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2894 //save address that triggered error so we can write it to the 68K stack at the appropriate place |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2895 push_r(code, opts->gen.scratch1); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2896 //swap USP and SSP if not already in supervisor mode |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2897 check_user_mode_swap_ssp_usp(opts); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2898 //save PC |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2899 subi_areg(opts, 4, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2900 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2901 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, last_prefetch_address), opts->gen.scratch1, SZ_D); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2902 call(code, opts->write_32_lowfirst); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2903 //save status register |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2904 subi_areg(opts, 2, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2905 call(code, opts->get_sr); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2906 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2907 call(code, opts->write_16); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2908 //save instruction register |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2909 subi_areg(opts, 2, 7); |
989
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2910 //calculate IR |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2911 push_r(code, opts->gen.context_reg); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2912 call(code, opts->gen.save_context); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2913 call_args_abi(code, (code_ptr)m68k_get_ir, 1, opts->gen.context_reg); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2914 mov_rr(code, RAX, opts->gen.scratch1, SZ_W); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2915 pop_r(code, opts->gen.context_reg); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2916 pop_r(code, opts->gen.scratch2); //access address |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2917 push_r(code, RAX); //save it for use in the "info" word |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2918 push_r(code, opts->gen.scratch2); //access address |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2919 call(code, opts->gen.load_context); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2920 //write it to the stack |
987
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2921 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2922 call(code, opts->write_16); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2923 //save access address |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2924 subi_areg(opts, 4, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2925 pop_r(code, opts->gen.scratch1); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2926 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2927 call(code, opts->write_32_lowfirst); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2928 //save FC, I/N and R/W word' |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2929 xor_rr(code, opts->gen.scratch1, opts->gen.scratch1, SZ_W); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2930 //FC3 is basically the same as the supervisor bit |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2931 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, status), opts->gen.scratch1, SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2932 shr_ir(code, 3, opts->gen.scratch1, SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2933 and_ir(code, 4, opts->gen.scratch1, SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2934 //set FC0 to one to indicate data access, and R/W to indicate read |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2935 or_ir(code, 0x11, opts->gen.scratch1, SZ_B); |
989
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2936 //set undefined bits to IR value |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2937 pop_r(code, opts->gen.scratch2); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2938 and_ir(code, 0xFFE0, opts->gen.scratch2, SZ_W); |
d70000fdff0b
Implemented IR and undefined bits of info word for address error exception frames
Michael Pavone <pavone@retrodev.com>
parents:
987
diff
changeset
|
2939 or_rr(code, opts->gen.scratch2, opts->gen.scratch1, SZ_W); |
987
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2940 subi_areg(opts, 2, 7); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2941 areg_to_native(opts, 7, opts->gen.scratch2); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2942 call(code, opts->write_16); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2943 //set supervisor bit |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2944 or_irdisp(code, 0x20, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2945 //load vector address |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2946 mov_ir(code, 4 * VECTOR_ADDRESS_ERROR, opts->gen.scratch1, SZ_D); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2947 call(code, opts->read_32); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2948 call(code, opts->native_addr_and_sync); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2949 cycles(&opts->gen, 18); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2950 jmp_r(code, opts->gen.scratch1); |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2951 |
1f09994e92c5
Initial stab at implementing address error exceptions. Need to fill in the value of IR, undefined bits of last stack frame word and properly deal with address errors that occur during exception processing.
Michael Pavone <pavone@retrodev.com>
parents:
986
diff
changeset
|
2952 *code = tmp_code; |
547
3090d016c9e9
Generate get_sr, set_sr and set_ccr at runtime so they can respect the flag_regs setting
Michael Pavone <pavone@retrodev.com>
parents:
546
diff
changeset
|
2953 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2954 opts->gen.handle_cycle_limit_int = code->cur; |
902
6011409ded0d
Fix a few lingering stack alignment rework bugs
Michael Pavone <pavone@retrodev.com>
parents:
894
diff
changeset
|
2955 //calculate stack adjust size |
6011409ded0d
Fix a few lingering stack alignment rework bugs
Michael Pavone <pavone@retrodev.com>
parents:
894
diff
changeset
|
2956 add_ir(code, 16-sizeof(void*), RSP, SZ_PTR); |
6011409ded0d
Fix a few lingering stack alignment rework bugs
Michael Pavone <pavone@retrodev.com>
parents:
894
diff
changeset
|
2957 uint32_t adjust_size = code->cur - opts->gen.handle_cycle_limit_int; |
6011409ded0d
Fix a few lingering stack alignment rework bugs
Michael Pavone <pavone@retrodev.com>
parents:
894
diff
changeset
|
2958 code->cur = opts->gen.handle_cycle_limit_int; |
1304
5b90d7669eee
Fix exit trace mode edge case. Call do_sync if trace mode bit is changed in eori sr
Michael Pavone <pavone@retrodev.com>
parents:
1303
diff
changeset
|
2959 //handle trace mode |
1303
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2960 cmp_irdisp(code, 0, opts->gen.context_reg, offsetof(m68k_context, trace_pending), SZ_B); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2961 code_ptr do_trace = code->cur + 1; |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2962 jcc(code, CC_NZ, do_trace); |
1304
5b90d7669eee
Fix exit trace mode edge case. Call do_sync if trace mode bit is changed in eori sr
Michael Pavone <pavone@retrodev.com>
parents:
1303
diff
changeset
|
2963 bt_irdisp(code, 7, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
5b90d7669eee
Fix exit trace mode edge case. Call do_sync if trace mode bit is changed in eori sr
Michael Pavone <pavone@retrodev.com>
parents:
1303
diff
changeset
|
2964 code_ptr no_trace = code->cur + 1; |
5b90d7669eee
Fix exit trace mode edge case. Call do_sync if trace mode bit is changed in eori sr
Michael Pavone <pavone@retrodev.com>
parents:
1303
diff
changeset
|
2965 jcc(code, CC_NC, no_trace); |
1303
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2966 mov_irdisp(code, 1, opts->gen.context_reg, offsetof(m68k_context, trace_pending), SZ_B); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2967 *no_trace = code->cur - (no_trace + 1); |
1304
5b90d7669eee
Fix exit trace mode edge case. Call do_sync if trace mode bit is changed in eori sr
Michael Pavone <pavone@retrodev.com>
parents:
1303
diff
changeset
|
2968 //handle interrupts |
656
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2969 cmp_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, int_cycle), opts->gen.cycles, SZ_D); |
1303
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2970 code_ptr do_int = code->cur + 2; |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2971 jcc(code, CC_NC, do_int+512);//force 32-bit displacement |
1304
5b90d7669eee
Fix exit trace mode edge case. Call do_sync if trace mode bit is changed in eori sr
Michael Pavone <pavone@retrodev.com>
parents:
1303
diff
changeset
|
2972 //handle component synchronization |
656
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2973 cmp_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, sync_cycle), opts->gen.cycles, SZ_D); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2974 skip_sync = code->cur + 1; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2975 jcc(code, CC_C, code->cur + 2); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2976 call(code, opts->gen.save_context); |
656
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
2977 call_args_abi(code, (code_ptr)sync_components, 2, opts->gen.context_reg, opts->gen.scratch1); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2978 mov_rr(code, RAX, opts->gen.context_reg, SZ_PTR); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2979 jmp(code, opts->gen.load_context); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2980 *skip_sync = code->cur - (skip_sync+1); |
872
7022ba865cfd
Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents:
847
diff
changeset
|
2981 cmp_irdisp(code, 0, opts->gen.context_reg, offsetof(m68k_context, should_return), SZ_B); |
7022ba865cfd
Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents:
847
diff
changeset
|
2982 code_ptr do_ret = code->cur + 1; |
7022ba865cfd
Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents:
847
diff
changeset
|
2983 jcc(code, CC_NZ, do_ret); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
2984 retn(code); |
872
7022ba865cfd
Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents:
847
diff
changeset
|
2985 *do_ret = code->cur - (do_ret+1); |
894
a7774fc2de4b
Partially working change to do proper stack alignment rather than doing a lame alignment check when calling a C compile dfunction. 68K core seems okay, but Z80 is busted.
Michael Pavone <pavone@retrodev.com>
parents:
887
diff
changeset
|
2986 uint32_t tmp_stack_off = code->stack_off; |
a7774fc2de4b
Partially working change to do proper stack alignment rather than doing a lame alignment check when calling a C compile dfunction. 68K core seems okay, but Z80 is busted.
Michael Pavone <pavone@retrodev.com>
parents:
887
diff
changeset
|
2987 //fetch return address and adjust RSP |
872
7022ba865cfd
Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents:
847
diff
changeset
|
2988 pop_r(code, opts->gen.scratch1); |
894
a7774fc2de4b
Partially working change to do proper stack alignment rather than doing a lame alignment check when calling a C compile dfunction. 68K core seems okay, but Z80 is busted.
Michael Pavone <pavone@retrodev.com>
parents:
887
diff
changeset
|
2989 add_ir(code, 16-sizeof(void *), RSP, SZ_PTR); |
902
6011409ded0d
Fix a few lingering stack alignment rework bugs
Michael Pavone <pavone@retrodev.com>
parents:
894
diff
changeset
|
2990 add_ir(code, adjust_size, opts->gen.scratch1, SZ_PTR); |
894
a7774fc2de4b
Partially working change to do proper stack alignment rather than doing a lame alignment check when calling a C compile dfunction. 68K core seems okay, but Z80 is busted.
Michael Pavone <pavone@retrodev.com>
parents:
887
diff
changeset
|
2991 //save return address for restoring later |
883
9f149f0e98b7
It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents:
872
diff
changeset
|
2992 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, offsetof(m68k_context, resume_pc), SZ_PTR); |
872
7022ba865cfd
Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents:
847
diff
changeset
|
2993 retn(code); |
894
a7774fc2de4b
Partially working change to do proper stack alignment rather than doing a lame alignment check when calling a C compile dfunction. 68K core seems okay, but Z80 is busted.
Michael Pavone <pavone@retrodev.com>
parents:
887
diff
changeset
|
2994 code->stack_off = tmp_stack_off; |
1303
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2995 *do_trace = code->cur - (do_trace + 1); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2996 //clear out trace pending flag |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2997 mov_irdisp(code, 0, opts->gen.context_reg, offsetof(m68k_context, trace_pending), SZ_B); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2998 //save PC as stored in scratch1 for later |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
2999 push_r(code, opts->gen.scratch1); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3000 //swap USP and SSP if not already in supervisor mode |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3001 check_user_mode_swap_ssp_usp(opts); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3002 //save status register |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3003 subi_areg(opts, 6, 7); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3004 call(code, opts->get_sr); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3005 cycles(&opts->gen, 6); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3006 //save SR to stack |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3007 areg_to_native(opts, 7, opts->gen.scratch2); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3008 call(code, opts->write_16); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3009 //update the status register |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3010 and_irdisp(code, 0x7F, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3011 or_irdisp(code, 0x20, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3012 //save PC |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3013 areg_to_native(opts, 7, opts->gen.scratch2); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3014 add_ir(code, 2, opts->gen.scratch2, SZ_D); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3015 pop_r(code, opts->gen.scratch1); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3016 call(code, opts->write_32_lowfirst); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3017 //read vector |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3018 mov_ir(code, 0x24, opts->gen.scratch1, SZ_D); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3019 call(code, opts->read_32); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3020 call(code, opts->native_addr_and_sync); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3021 //2 prefetch bus operations + 2 idle bus cycles |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3022 cycles(&opts->gen, 10); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3023 //discard function return address |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3024 pop_r(code, opts->gen.scratch2); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3025 add_ir(code, 16-sizeof(void *), RSP, SZ_PTR); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3026 jmp_r(code, opts->gen.scratch1); |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3027 |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3028 code->stack_off = tmp_stack_off; |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3029 |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1297
diff
changeset
|
3030 *((uint32_t *)do_int) = code->cur - (do_int+4); |
846
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
3031 //implement 1 instruction latency |
1097
faa3a4617f62
Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents:
1084
diff
changeset
|
3032 cmp_irdisp(code, INT_PENDING_NONE, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
846
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
3033 do_int = code->cur + 1; |
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
3034 jcc(code, CC_NZ, do_int); |
996
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3035 //store current interrupt number so it doesn't change before we start processing the vector |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3036 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, int_num), opts->gen.scratch1, SZ_B); |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3037 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
846
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
3038 retn(code); |
98d7b6073163
Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents:
839
diff
changeset
|
3039 *do_int = code->cur - (do_int + 1); |
996
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3040 //Check if int_pending has an actual interrupt priority in it |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3041 cmp_irdisp(code, INT_PENDING_SR_CHANGE, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3042 code_ptr already_int_num = code->cur + 1; |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3043 jcc(code, CC_NZ, already_int_num); |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3044 |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3045 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, int_num), opts->gen.scratch2, SZ_B); |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3046 mov_rrdisp(code, opts->gen.scratch2, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3047 |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3048 *already_int_num = code->cur - (already_int_num + 1); |
847
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3049 //save PC as stored in scratch1 for later |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3050 push_r(code, opts->gen.scratch1); |
347
b24556b45d1e
Generate handle_cycle_limit_int at runtime so it can refer to the runtime generated memory map functions
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
3051 //set target cycle to sync cycle |
656
24ccfd70133a
Added 2 new functions to gen_x86.c for handling passing args according to the C abi of the host system and adapted the code in m68k_core_x86.c to use that instead of doing everything by hand
Michael Pavone <pavone@retrodev.com>
parents:
654
diff
changeset
|
3052 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, sync_cycle), opts->gen.limit, SZ_D); |
347
b24556b45d1e
Generate handle_cycle_limit_int at runtime so it can refer to the runtime generated memory map functions
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
3053 //swap USP and SSP if not already in supervisor mode |
687
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
3054 check_user_mode_swap_ssp_usp(opts); |
347
b24556b45d1e
Generate handle_cycle_limit_int at runtime so it can refer to the runtime generated memory map functions
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
3055 //save status register |
847
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3056 subi_areg(opts, 6, 7); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3057 call(code, opts->get_sr); |
847
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3058 //6 cycles before SR gets saved |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3059 cycles(&opts->gen, 6); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3060 //save SR to stack |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
3061 areg_to_native(opts, 7, opts->gen.scratch2); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3062 call(code, opts->write_16); |
847
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3063 //interrupt ack cycle |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3064 //the Genesis responds to these exclusively with !VPA which means its a slow |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3065 //6800 operation. documentation says these can take between 10 and 19 cycles. |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3066 //actual results measurements seem to suggest it's actually between 9 and 18 |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3067 //WARNING: this code might break with register assignment changes |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3068 //save RDX |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3069 push_r(code, RDX); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3070 //save cycle count |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3071 mov_rr(code, RAX, opts->gen.scratch1, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3072 //clear top doubleword of dividend |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3073 xor_rr(code, RDX, RDX, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3074 //set divisor to clock divider |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3075 mov_ir(code, opts->gen.clock_divider, opts->gen.scratch2, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3076 div_r(code, opts->gen.scratch2, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3077 //discard remainder |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3078 xor_rr(code, RDX, RDX, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3079 //set divisor to 10, the period of E |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3080 mov_ir(code, 10, opts->gen.scratch2, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3081 div_r(code, opts->gen.scratch2, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3082 //delay will be (9 + 4 + the remainder) * clock_divider |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3083 //the extra 4 is to cover the idle bus period after the ack |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3084 add_ir(code, 9 + 4, RDX, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3085 mov_ir(code, opts->gen.clock_divider, RAX, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3086 mul_r(code, RDX, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3087 pop_r(code, RDX); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3088 //add saved cycle count to result |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3089 add_rr(code, opts->gen.scratch1, RAX, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3090 |
347
b24556b45d1e
Generate handle_cycle_limit_int at runtime so it can refer to the runtime generated memory map functions
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
3091 //update status register |
1461
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
3092 and_irdisp(code, 0x78, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3093 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, int_num), opts->gen.scratch1, SZ_B); |
1461
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
3094 //clear trace pending flag |
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
3095 mov_irdisp(code, 0, opts->gen.context_reg, offsetof(m68k_context, trace_pending), SZ_B); |
1097
faa3a4617f62
Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents:
1084
diff
changeset
|
3096 //need to separate int priority and interrupt vector, but for now mask out large interrupt numbers |
faa3a4617f62
Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents:
1084
diff
changeset
|
3097 and_ir(code, 0x7, opts->gen.scratch1, SZ_B); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3098 or_ir(code, 0x20, opts->gen.scratch1, SZ_B); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3099 or_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
847
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3100 |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3101 pop_r(code, opts->gen.scratch1); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3102 |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3103 //save PC |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3104 areg_to_native(opts, 7, opts->gen.scratch2); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3105 add_ir(code, 2, opts->gen.scratch2, SZ_D); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3106 call(code, opts->write_32_lowfirst); |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3107 |
996
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3108 //grab saved interrupt number |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3109 xor_rr(code, opts->gen.scratch1, opts->gen.scratch1, SZ_D); |
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3110 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, int_pending), opts->gen.scratch1, SZ_B); |
887
fb4d09f874dd
Prevent the current interrupt number from being changed while interrupt is being processed. This fixes a bug in Sonic 2 split screen that showed up when interrupt timing was adjusted
Michael Pavone <pavone@retrodev.com>
parents:
883
diff
changeset
|
3111 //ack the interrupt (happens earlier on hardware, but shouldn't be an observable difference) |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3112 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, offsetof(m68k_context, int_ack), SZ_W); |
887
fb4d09f874dd
Prevent the current interrupt number from being changed while interrupt is being processed. This fixes a bug in Sonic 2 split screen that showed up when interrupt timing was adjusted
Michael Pavone <pavone@retrodev.com>
parents:
883
diff
changeset
|
3113 //calculate the vector address |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3114 shl_ir(code, 2, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3115 add_ir(code, 0x60, opts->gen.scratch1, SZ_D); |
996
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3116 //clear out pending flag |
1097
faa3a4617f62
Get Jaguar video interrupt working
Michael Pavone <pavone@retrodev.com>
parents:
1084
diff
changeset
|
3117 mov_irdisp(code, INT_PENDING_NONE, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
996
784bc1e45e80
Fix 68K interrupt handling some more. Fatal Rewind is working again.
Michael Pavone <pavone@retrodev.com>
parents:
990
diff
changeset
|
3118 //read vector |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3119 call(code, opts->read_32); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3120 call(code, opts->native_addr_and_sync); |
847
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3121 //2 prefetch bus operations + 2 idle bus cycles |
7decd421cdc8
Update timing and order of steps in interrupt processing to match latest measurements
Michael Pavone <pavone@retrodev.com>
parents:
846
diff
changeset
|
3122 cycles(&opts->gen, 10); |
894
a7774fc2de4b
Partially working change to do proper stack alignment rather than doing a lame alignment check when calling a C compile dfunction. 68K core seems okay, but Z80 is busted.
Michael Pavone <pavone@retrodev.com>
parents:
887
diff
changeset
|
3123 tmp_stack_off = code->stack_off; |
347
b24556b45d1e
Generate handle_cycle_limit_int at runtime so it can refer to the runtime generated memory map functions
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
3124 //discard function return address |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3125 pop_r(code, opts->gen.scratch2); |
894
a7774fc2de4b
Partially working change to do proper stack alignment rather than doing a lame alignment check when calling a C compile dfunction. 68K core seems okay, but Z80 is busted.
Michael Pavone <pavone@retrodev.com>
parents:
887
diff
changeset
|
3126 add_ir(code, 16-sizeof(void *), RSP, SZ_PTR); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3127 jmp_r(code, opts->gen.scratch1); |
894
a7774fc2de4b
Partially working change to do proper stack alignment rather than doing a lame alignment check when calling a C compile dfunction. 68K core seems okay, but Z80 is busted.
Michael Pavone <pavone@retrodev.com>
parents:
887
diff
changeset
|
3128 code->stack_off = tmp_stack_off; |
1363
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3129 |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3130 opts->handle_int_latch = code->cur; |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3131 cmp_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, int_cycle), opts->gen.cycles, SZ_D); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3132 code_ptr do_latch = code->cur + 1; |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3133 jcc(code, CC_NC, do_latch); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3134 retn(code); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3135 *do_latch = code->cur - (do_latch + 1); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3136 cmp_irdisp(code, INT_PENDING_NONE, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3137 do_latch = code->cur + 1; |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3138 jcc(code, CC_Z, do_latch); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3139 retn(code); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3140 *do_latch = code->cur - (do_latch + 1); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3141 //store current interrupt number so it doesn't change before we start processing the vector |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3142 push_r(code, opts->gen.scratch1); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3143 mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, int_num), opts->gen.scratch1, SZ_B); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3144 mov_rrdisp(code, opts->gen.scratch1, opts->gen.context_reg, offsetof(m68k_context, int_pending), SZ_B); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3145 pop_r(code, opts->gen.scratch1); |
df6af7187b36
Fix to M68K interrupt latency for most instructions. Still needs some work for RAW_IMPL instructions besides move
Michael Pavone <pavone@retrodev.com>
parents:
1332
diff
changeset
|
3146 retn(code); |
447
e730fc040169
Fix performance regression from stop instruction work
Mike Pavone <pavone@retrodev.com>
parents:
446
diff
changeset
|
3147 |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3148 opts->trap = code->cur; |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3149 push_r(code, opts->gen.scratch2); |
348
3923dbc2dcc4
m68k_trap is now replaced with a generated one so it can call the generated memory acccess functions. The old static memory access functions have been removed from runtime.S
Mike Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
3150 //swap USP and SSP if not already in supervisor mode |
687
a61d33ccea7d
Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c
Michael Pavone <pavone@retrodev.com>
parents:
686
diff
changeset
|
3151 check_user_mode_swap_ssp_usp(opts); |
348
3923dbc2dcc4
m68k_trap is now replaced with a generated one so it can call the generated memory acccess functions. The old static memory access functions have been removed from runtime.S
Mike Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
3152 //save PC |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
3153 subi_areg(opts, 4, 7); |
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
3154 areg_to_native(opts, 7, opts->gen.scratch2); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3155 call(code, opts->write_32_lowfirst); |
348
3923dbc2dcc4
m68k_trap is now replaced with a generated one so it can call the generated memory acccess functions. The old static memory access functions have been removed from runtime.S
Mike Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
3156 //save status register |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
3157 subi_areg(opts, 2, 7); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3158 call(code, opts->get_sr); |
574
1594525e2157
More 68K core refactoring to both reduce the amount of code and better split the host-cpu specific parts from the generic parts
Michael Pavone <pavone@retrodev.com>
parents:
571
diff
changeset
|
3159 areg_to_native(opts, 7, opts->gen.scratch2); |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3160 call(code, opts->write_16); |
348
3923dbc2dcc4
m68k_trap is now replaced with a generated one so it can call the generated memory acccess functions. The old static memory access functions have been removed from runtime.S
Mike Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
3161 //set supervisor bit |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3162 or_irdisp(code, 0x20, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
1461
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
3163 //clear trace bit |
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
3164 and_irdisp(code, 0x7F, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); |
aa945f1bdd71
Properly clear trace mode on interrupt or other exception. Fix NBCD with memory destination
Michael Pavone <pavone@retrodev.com>
parents:
1430
diff
changeset
|
3165 mov_irdisp(code, 0, opts->gen.context_reg, offsetof(m68k_context, trace_pending), SZ_B); |
348
3923dbc2dcc4
m68k_trap is now replaced with a generated one so it can call the generated memory acccess functions. The old static memory access functions have been removed from runtime.S
Mike Pavone <pavone@retrodev.com>
parents:
347
diff
changeset
|
3166 //calculate vector address |
567
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3167 pop_r(code, opts->gen.scratch1); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3168 shl_ir(code, 2, opts->gen.scratch1, SZ_D); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3169 call(code, opts->read_32); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3170 call(code, opts->native_addr_and_sync); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3171 cycles(&opts->gen, 18); |
8e395210f50f
Refactor gen_x86 to use an interface more like gen_arm and to remove the need for the caller to decide whether an 8-bit or 32-bit displacement is needed in the rdisp functions. Update m68k_to_x86 to use the new version of the gen_x86 functions and do some minor refactoring there in the process
Michael Pavone <pavone@retrodev.com>
parents:
558
diff
changeset
|
3172 jmp_r(code, opts->gen.scratch1); |
1228
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
3173 |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
3174 opts->retrans_stub = code->cur; |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
3175 call(code, opts->gen.save_context); |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
3176 push_r(code, opts->gen.context_reg); |
1465
5d41d0574863
Preserve original address when retranslating instructions instead of switching to the lowest alias
Michael Pavone <pavone@retrodev.com>
parents:
1461
diff
changeset
|
3177 call_args(code,(code_ptr)m68k_retranslate_inst, 2, opts->gen.scratch1, opts->gen.context_reg); |
1228
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
3178 pop_r(code, opts->gen.context_reg); |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
3179 mov_rr(code, RAX, opts->gen.scratch1, SZ_PTR); |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
3180 call(code, opts->gen.load_context); |
2e6dcb5c11a2
WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
1219
diff
changeset
|
3181 jmp_r(code, opts->gen.scratch1); |
1329
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3182 |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3183 |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3184 check_code_prologue(code); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3185 opts->bp_stub = code->cur; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3186 |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3187 tmp_stack_off = code->stack_off; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3188 //Calculate length of prologue |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3189 check_cycles_int(&opts->gen, 0x1234); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3190 int check_int_size = code->cur-opts->bp_stub; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3191 code->cur = opts->bp_stub; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3192 code->stack_off = tmp_stack_off; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3193 opts->prologue_start = *opts->bp_stub; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3194 //Calculate length of patch |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3195 mov_ir(code, 0x1234, opts->gen.scratch1, SZ_D); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3196 call(code, opts->bp_stub); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3197 int patch_size = code->cur - opts->bp_stub; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3198 code->cur = opts->bp_stub; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3199 code->stack_off = tmp_stack_off; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3200 |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3201 //Save context and call breakpoint handler |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3202 call(code, opts->gen.save_context); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3203 push_r(code, opts->gen.scratch1); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3204 call_args_abi(code, (code_ptr)m68k_bp_dispatcher, 2, opts->gen.context_reg, opts->gen.scratch1); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3205 mov_rr(code, RAX, opts->gen.context_reg, SZ_PTR); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3206 //Restore context |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3207 call(code, opts->gen.load_context); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3208 pop_r(code, opts->gen.scratch1); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3209 //do prologue stuff |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3210 cmp_rr(code, opts->gen.cycles, opts->gen.limit, SZ_D); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3211 code_ptr jmp_off = code->cur + 1; |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3212 jcc(code, CC_NC, code->cur + 7); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3213 call(code, opts->gen.handle_cycle_limit_int); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3214 *jmp_off = code->cur - (jmp_off+1); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3215 //jump back to body of translated instruction |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3216 pop_r(code, opts->gen.scratch1); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3217 add_ir(code, check_int_size - patch_size, opts->gen.scratch1, SZ_PTR); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3218 jmp_r(code, opts->gen.scratch1); |
85a90964b557
Fix interaction between 68K debugger and instruction retranslation due to self modifying code or bank switching
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
3219 code->stack_off = tmp_stack_off; |
1465
5d41d0574863
Preserve original address when retranslating instructions instead of switching to the lowest alias
Michael Pavone <pavone@retrodev.com>
parents:
1461
diff
changeset
|
3220 |
5d41d0574863
Preserve original address when retranslating instructions instead of switching to the lowest alias
Michael Pavone <pavone@retrodev.com>
parents:
1461
diff
changeset
|
3221 retranslate_calc(&opts->gen); |
18
3e7bfde7606e
M68K to x86 translation works for a limited subset of instructions and addressing modes
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
3222 } |