root / target-sh4 / translate.c @ 927e3a4e
History | View | Annotate | Download (59.3 kB)
1 | fdf9b3e8 | bellard | /*
|
---|---|---|---|
2 | fdf9b3e8 | bellard | * SH4 translation
|
3 | 5fafdf24 | ths | *
|
4 | fdf9b3e8 | bellard | * Copyright (c) 2005 Samuel Tardieu
|
5 | fdf9b3e8 | bellard | *
|
6 | fdf9b3e8 | bellard | * This library is free software; you can redistribute it and/or
|
7 | fdf9b3e8 | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | fdf9b3e8 | bellard | * License as published by the Free Software Foundation; either
|
9 | fdf9b3e8 | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | fdf9b3e8 | bellard | *
|
11 | fdf9b3e8 | bellard | * This library is distributed in the hope that it will be useful,
|
12 | fdf9b3e8 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | fdf9b3e8 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | fdf9b3e8 | bellard | * Lesser General Public License for more details.
|
15 | fdf9b3e8 | bellard | *
|
16 | fdf9b3e8 | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | fdf9b3e8 | bellard | * License along with this library; if not, write to the Free Software
|
18 | fad6cb1a | aurel32 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
|
19 | fdf9b3e8 | bellard | */
|
20 | fdf9b3e8 | bellard | #include <stdarg.h> |
21 | fdf9b3e8 | bellard | #include <stdlib.h> |
22 | fdf9b3e8 | bellard | #include <stdio.h> |
23 | fdf9b3e8 | bellard | #include <string.h> |
24 | fdf9b3e8 | bellard | #include <inttypes.h> |
25 | fdf9b3e8 | bellard | #include <assert.h> |
26 | fdf9b3e8 | bellard | |
27 | fdf9b3e8 | bellard | #define DEBUG_DISAS
|
28 | fdf9b3e8 | bellard | #define SH4_DEBUG_DISAS
|
29 | fdf9b3e8 | bellard | //#define SH4_SINGLE_STEP
|
30 | fdf9b3e8 | bellard | |
31 | fdf9b3e8 | bellard | #include "cpu.h" |
32 | fdf9b3e8 | bellard | #include "exec-all.h" |
33 | fdf9b3e8 | bellard | #include "disas.h" |
34 | 57fec1fe | bellard | #include "tcg-op.h" |
35 | ca10f867 | aurel32 | #include "qemu-common.h" |
36 | fdf9b3e8 | bellard | |
37 | a7812ae4 | pbrook | #include "helper.h" |
38 | a7812ae4 | pbrook | #define GEN_HELPER 1 |
39 | a7812ae4 | pbrook | #include "helper.h" |
40 | a7812ae4 | pbrook | |
41 | fdf9b3e8 | bellard | typedef struct DisasContext { |
42 | fdf9b3e8 | bellard | struct TranslationBlock *tb;
|
43 | fdf9b3e8 | bellard | target_ulong pc; |
44 | fdf9b3e8 | bellard | uint32_t sr; |
45 | eda9b09b | bellard | uint32_t fpscr; |
46 | fdf9b3e8 | bellard | uint16_t opcode; |
47 | fdf9b3e8 | bellard | uint32_t flags; |
48 | 823029f9 | ths | int bstate;
|
49 | fdf9b3e8 | bellard | int memidx;
|
50 | fdf9b3e8 | bellard | uint32_t delayed_pc; |
51 | fdf9b3e8 | bellard | int singlestep_enabled;
|
52 | 71968fa6 | aurel32 | uint32_t features; |
53 | fdf9b3e8 | bellard | } DisasContext; |
54 | fdf9b3e8 | bellard | |
55 | fe25591e | aurel32 | #if defined(CONFIG_USER_ONLY)
|
56 | fe25591e | aurel32 | #define IS_USER(ctx) 1 |
57 | fe25591e | aurel32 | #else
|
58 | fe25591e | aurel32 | #define IS_USER(ctx) (!(ctx->sr & SR_MD))
|
59 | fe25591e | aurel32 | #endif
|
60 | fe25591e | aurel32 | |
61 | 823029f9 | ths | enum {
|
62 | 823029f9 | ths | BS_NONE = 0, /* We go out of the TB without reaching a branch or an |
63 | 823029f9 | ths | * exception condition
|
64 | 823029f9 | ths | */
|
65 | 823029f9 | ths | BS_STOP = 1, /* We want to stop translation for any reason */ |
66 | 823029f9 | ths | BS_BRANCH = 2, /* We reached a branch condition */ |
67 | 823029f9 | ths | BS_EXCP = 3, /* We reached an exception condition */ |
68 | 823029f9 | ths | }; |
69 | 823029f9 | ths | |
70 | 1e8864f7 | aurel32 | /* global register indexes */
|
71 | a7812ae4 | pbrook | static TCGv_ptr cpu_env;
|
72 | 1e8864f7 | aurel32 | static TCGv cpu_gregs[24]; |
73 | 3a8a44c4 | aurel32 | static TCGv cpu_pc, cpu_sr, cpu_ssr, cpu_spc, cpu_gbr;
|
74 | 3a8a44c4 | aurel32 | static TCGv cpu_vbr, cpu_sgr, cpu_dbr, cpu_mach, cpu_macl;
|
75 | 66c7c806 | aurel32 | static TCGv cpu_pr, cpu_fpscr, cpu_fpul, cpu_ldst;
|
76 | 66ba317c | aurel32 | static TCGv cpu_fregs[32]; |
77 | 1000822b | aurel32 | |
78 | 1000822b | aurel32 | /* internal register indexes */
|
79 | 1000822b | aurel32 | static TCGv cpu_flags, cpu_delayed_pc;
|
80 | 1e8864f7 | aurel32 | |
81 | 2e70f6ef | pbrook | #include "gen-icount.h" |
82 | 2e70f6ef | pbrook | |
83 | a5f1b965 | blueswir1 | static void sh4_translate_init(void) |
84 | 2e70f6ef | pbrook | { |
85 | 1e8864f7 | aurel32 | int i;
|
86 | 2e70f6ef | pbrook | static int done_init = 0; |
87 | 559dd74d | aurel32 | static const char * const gregnames[24] = { |
88 | 1e8864f7 | aurel32 | "R0_BANK0", "R1_BANK0", "R2_BANK0", "R3_BANK0", |
89 | 1e8864f7 | aurel32 | "R4_BANK0", "R5_BANK0", "R6_BANK0", "R7_BANK0", |
90 | 1e8864f7 | aurel32 | "R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15", |
91 | 1e8864f7 | aurel32 | "R0_BANK1", "R1_BANK1", "R2_BANK1", "R3_BANK1", |
92 | 1e8864f7 | aurel32 | "R4_BANK1", "R5_BANK1", "R6_BANK1", "R7_BANK1" |
93 | 1e8864f7 | aurel32 | }; |
94 | 66ba317c | aurel32 | static const char * const fregnames[32] = { |
95 | 66ba317c | aurel32 | "FPR0_BANK0", "FPR1_BANK0", "FPR2_BANK0", "FPR3_BANK0", |
96 | 66ba317c | aurel32 | "FPR4_BANK0", "FPR5_BANK0", "FPR6_BANK0", "FPR7_BANK0", |
97 | 66ba317c | aurel32 | "FPR8_BANK0", "FPR9_BANK0", "FPR10_BANK0", "FPR11_BANK0", |
98 | 66ba317c | aurel32 | "FPR12_BANK0", "FPR13_BANK0", "FPR14_BANK0", "FPR15_BANK0", |
99 | 66ba317c | aurel32 | "FPR0_BANK1", "FPR1_BANK1", "FPR2_BANK1", "FPR3_BANK1", |
100 | 66ba317c | aurel32 | "FPR4_BANK1", "FPR5_BANK1", "FPR6_BANK1", "FPR7_BANK1", |
101 | 66ba317c | aurel32 | "FPR8_BANK1", "FPR9_BANK1", "FPR10_BANK1", "FPR11_BANK1", |
102 | 66ba317c | aurel32 | "FPR12_BANK1", "FPR13_BANK1", "FPR14_BANK1", "FPR15_BANK1", |
103 | 66ba317c | aurel32 | }; |
104 | 1e8864f7 | aurel32 | |
105 | 2e70f6ef | pbrook | if (done_init)
|
106 | 2e70f6ef | pbrook | return;
|
107 | 1e8864f7 | aurel32 | |
108 | a7812ae4 | pbrook | cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
|
109 | 1e8864f7 | aurel32 | |
110 | 1e8864f7 | aurel32 | for (i = 0; i < 24; i++) |
111 | a7812ae4 | pbrook | cpu_gregs[i] = tcg_global_mem_new_i32(TCG_AREG0, |
112 | 66ba317c | aurel32 | offsetof(CPUState, gregs[i]), |
113 | 66ba317c | aurel32 | gregnames[i]); |
114 | 988d7eaa | aurel32 | |
115 | a7812ae4 | pbrook | cpu_pc = tcg_global_mem_new_i32(TCG_AREG0, |
116 | a7812ae4 | pbrook | offsetof(CPUState, pc), "PC");
|
117 | a7812ae4 | pbrook | cpu_sr = tcg_global_mem_new_i32(TCG_AREG0, |
118 | a7812ae4 | pbrook | offsetof(CPUState, sr), "SR");
|
119 | a7812ae4 | pbrook | cpu_ssr = tcg_global_mem_new_i32(TCG_AREG0, |
120 | a7812ae4 | pbrook | offsetof(CPUState, ssr), "SSR");
|
121 | a7812ae4 | pbrook | cpu_spc = tcg_global_mem_new_i32(TCG_AREG0, |
122 | a7812ae4 | pbrook | offsetof(CPUState, spc), "SPC");
|
123 | a7812ae4 | pbrook | cpu_gbr = tcg_global_mem_new_i32(TCG_AREG0, |
124 | a7812ae4 | pbrook | offsetof(CPUState, gbr), "GBR");
|
125 | a7812ae4 | pbrook | cpu_vbr = tcg_global_mem_new_i32(TCG_AREG0, |
126 | a7812ae4 | pbrook | offsetof(CPUState, vbr), "VBR");
|
127 | a7812ae4 | pbrook | cpu_sgr = tcg_global_mem_new_i32(TCG_AREG0, |
128 | a7812ae4 | pbrook | offsetof(CPUState, sgr), "SGR");
|
129 | a7812ae4 | pbrook | cpu_dbr = tcg_global_mem_new_i32(TCG_AREG0, |
130 | a7812ae4 | pbrook | offsetof(CPUState, dbr), "DBR");
|
131 | a7812ae4 | pbrook | cpu_mach = tcg_global_mem_new_i32(TCG_AREG0, |
132 | a7812ae4 | pbrook | offsetof(CPUState, mach), "MACH");
|
133 | a7812ae4 | pbrook | cpu_macl = tcg_global_mem_new_i32(TCG_AREG0, |
134 | a7812ae4 | pbrook | offsetof(CPUState, macl), "MACL");
|
135 | a7812ae4 | pbrook | cpu_pr = tcg_global_mem_new_i32(TCG_AREG0, |
136 | a7812ae4 | pbrook | offsetof(CPUState, pr), "PR");
|
137 | a7812ae4 | pbrook | cpu_fpscr = tcg_global_mem_new_i32(TCG_AREG0, |
138 | a7812ae4 | pbrook | offsetof(CPUState, fpscr), "FPSCR");
|
139 | a7812ae4 | pbrook | cpu_fpul = tcg_global_mem_new_i32(TCG_AREG0, |
140 | a7812ae4 | pbrook | offsetof(CPUState, fpul), "FPUL");
|
141 | a7812ae4 | pbrook | |
142 | a7812ae4 | pbrook | cpu_flags = tcg_global_mem_new_i32(TCG_AREG0, |
143 | a7812ae4 | pbrook | offsetof(CPUState, flags), "_flags_");
|
144 | a7812ae4 | pbrook | cpu_delayed_pc = tcg_global_mem_new_i32(TCG_AREG0, |
145 | a7812ae4 | pbrook | offsetof(CPUState, delayed_pc), |
146 | a7812ae4 | pbrook | "_delayed_pc_");
|
147 | 66c7c806 | aurel32 | cpu_ldst = tcg_global_mem_new_i32(TCG_AREG0, |
148 | 66c7c806 | aurel32 | offsetof(CPUState, ldst), "_ldst_");
|
149 | 1000822b | aurel32 | |
150 | 66ba317c | aurel32 | for (i = 0; i < 32; i++) |
151 | 66ba317c | aurel32 | cpu_fregs[i] = tcg_global_mem_new_i32(TCG_AREG0, |
152 | 66ba317c | aurel32 | offsetof(CPUState, fregs[i]), |
153 | 66ba317c | aurel32 | fregnames[i]); |
154 | 66ba317c | aurel32 | |
155 | 988d7eaa | aurel32 | /* register helpers */
|
156 | a7812ae4 | pbrook | #define GEN_HELPER 2 |
157 | 988d7eaa | aurel32 | #include "helper.h" |
158 | 988d7eaa | aurel32 | |
159 | 2e70f6ef | pbrook | done_init = 1;
|
160 | 2e70f6ef | pbrook | } |
161 | 2e70f6ef | pbrook | |
162 | fdf9b3e8 | bellard | void cpu_dump_state(CPUState * env, FILE * f,
|
163 | fdf9b3e8 | bellard | int (*cpu_fprintf) (FILE * f, const char *fmt, ...), |
164 | fdf9b3e8 | bellard | int flags)
|
165 | fdf9b3e8 | bellard | { |
166 | fdf9b3e8 | bellard | int i;
|
167 | eda9b09b | bellard | cpu_fprintf(f, "pc=0x%08x sr=0x%08x pr=0x%08x fpscr=0x%08x\n",
|
168 | eda9b09b | bellard | env->pc, env->sr, env->pr, env->fpscr); |
169 | 274a9e70 | aurel32 | cpu_fprintf(f, "spc=0x%08x ssr=0x%08x gbr=0x%08x vbr=0x%08x\n",
|
170 | 274a9e70 | aurel32 | env->spc, env->ssr, env->gbr, env->vbr); |
171 | 274a9e70 | aurel32 | cpu_fprintf(f, "sgr=0x%08x dbr=0x%08x delayed_pc=0x%08x fpul=0x%08x\n",
|
172 | 274a9e70 | aurel32 | env->sgr, env->dbr, env->delayed_pc, env->fpul); |
173 | fdf9b3e8 | bellard | for (i = 0; i < 24; i += 4) { |
174 | fdf9b3e8 | bellard | cpu_fprintf(f, "r%d=0x%08x r%d=0x%08x r%d=0x%08x r%d=0x%08x\n",
|
175 | fdf9b3e8 | bellard | i, env->gregs[i], i + 1, env->gregs[i + 1], |
176 | fdf9b3e8 | bellard | i + 2, env->gregs[i + 2], i + 3, env->gregs[i + 3]); |
177 | fdf9b3e8 | bellard | } |
178 | fdf9b3e8 | bellard | if (env->flags & DELAY_SLOT) {
|
179 | fdf9b3e8 | bellard | cpu_fprintf(f, "in delay slot (delayed_pc=0x%08x)\n",
|
180 | fdf9b3e8 | bellard | env->delayed_pc); |
181 | fdf9b3e8 | bellard | } else if (env->flags & DELAY_SLOT_CONDITIONAL) { |
182 | fdf9b3e8 | bellard | cpu_fprintf(f, "in conditional delay slot (delayed_pc=0x%08x)\n",
|
183 | fdf9b3e8 | bellard | env->delayed_pc); |
184 | fdf9b3e8 | bellard | } |
185 | fdf9b3e8 | bellard | } |
186 | fdf9b3e8 | bellard | |
187 | b79e1752 | aurel32 | static void cpu_sh4_reset(CPUSH4State * env) |
188 | fdf9b3e8 | bellard | { |
189 | eca1bdf4 | aliguori | if (qemu_loglevel_mask(CPU_LOG_RESET)) {
|
190 | eca1bdf4 | aliguori | qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
|
191 | eca1bdf4 | aliguori | log_cpu_state(env, 0);
|
192 | eca1bdf4 | aliguori | } |
193 | eca1bdf4 | aliguori | |
194 | 9c2a9ea1 | pbrook | #if defined(CONFIG_USER_ONLY)
|
195 | f3ff7fac | aurel32 | env->sr = 0;
|
196 | 9c2a9ea1 | pbrook | #else
|
197 | 56cd2b96 | aurel32 | env->sr = SR_MD | SR_RB | SR_BL | SR_I3 | SR_I2 | SR_I1 | SR_I0; |
198 | 9c2a9ea1 | pbrook | #endif
|
199 | fdf9b3e8 | bellard | env->vbr = 0;
|
200 | fdf9b3e8 | bellard | env->pc = 0xA0000000;
|
201 | ea6cf6be | ths | #if defined(CONFIG_USER_ONLY)
|
202 | ea6cf6be | ths | env->fpscr = FPSCR_PR; /* value for userspace according to the kernel */
|
203 | b0b3de89 | bellard | set_float_rounding_mode(float_round_nearest_even, &env->fp_status); /* ?! */
|
204 | ea6cf6be | ths | #else
|
205 | ea6cf6be | ths | env->fpscr = 0x00040001; /* CPU reset value according to SH4 manual */ |
206 | b0b3de89 | bellard | set_float_rounding_mode(float_round_to_zero, &env->fp_status); |
207 | ea6cf6be | ths | #endif
|
208 | fdf9b3e8 | bellard | env->mmucr = 0;
|
209 | fdf9b3e8 | bellard | } |
210 | fdf9b3e8 | bellard | |
211 | 0fd3ca30 | aurel32 | typedef struct { |
212 | b55266b5 | blueswir1 | const char *name; |
213 | 0fd3ca30 | aurel32 | int id;
|
214 | 0fd3ca30 | aurel32 | uint32_t pvr; |
215 | 0fd3ca30 | aurel32 | uint32_t prr; |
216 | 0fd3ca30 | aurel32 | uint32_t cvr; |
217 | 71968fa6 | aurel32 | uint32_t features; |
218 | 0fd3ca30 | aurel32 | } sh4_def_t; |
219 | 0fd3ca30 | aurel32 | |
220 | 0fd3ca30 | aurel32 | static sh4_def_t sh4_defs[] = {
|
221 | 0fd3ca30 | aurel32 | { |
222 | 0fd3ca30 | aurel32 | .name = "SH7750R",
|
223 | 0fd3ca30 | aurel32 | .id = SH_CPU_SH7750R, |
224 | 0fd3ca30 | aurel32 | .pvr = 0x00050000,
|
225 | 0fd3ca30 | aurel32 | .prr = 0x00000100,
|
226 | 0fd3ca30 | aurel32 | .cvr = 0x00110000,
|
227 | c2432a42 | aurel32 | .features = SH_FEATURE_BCR3_AND_BCR4, |
228 | 0fd3ca30 | aurel32 | }, { |
229 | 0fd3ca30 | aurel32 | .name = "SH7751R",
|
230 | 0fd3ca30 | aurel32 | .id = SH_CPU_SH7751R, |
231 | 0fd3ca30 | aurel32 | .pvr = 0x04050005,
|
232 | 0fd3ca30 | aurel32 | .prr = 0x00000113,
|
233 | 0fd3ca30 | aurel32 | .cvr = 0x00110000, /* Neutered caches, should be 0x20480000 */ |
234 | c2432a42 | aurel32 | .features = SH_FEATURE_BCR3_AND_BCR4, |
235 | a9c43f8e | aurel32 | }, { |
236 | a9c43f8e | aurel32 | .name = "SH7785",
|
237 | a9c43f8e | aurel32 | .id = SH_CPU_SH7785, |
238 | a9c43f8e | aurel32 | .pvr = 0x10300700,
|
239 | a9c43f8e | aurel32 | .prr = 0x00000200,
|
240 | a9c43f8e | aurel32 | .cvr = 0x71440211,
|
241 | 71968fa6 | aurel32 | .features = SH_FEATURE_SH4A, |
242 | a9c43f8e | aurel32 | }, |
243 | 0fd3ca30 | aurel32 | }; |
244 | 0fd3ca30 | aurel32 | |
245 | b55266b5 | blueswir1 | static const sh4_def_t *cpu_sh4_find_by_name(const char *name) |
246 | 0fd3ca30 | aurel32 | { |
247 | 0fd3ca30 | aurel32 | int i;
|
248 | 0fd3ca30 | aurel32 | |
249 | 0fd3ca30 | aurel32 | if (strcasecmp(name, "any") == 0) |
250 | 0fd3ca30 | aurel32 | return &sh4_defs[0]; |
251 | 0fd3ca30 | aurel32 | |
252 | b1503cda | malc | for (i = 0; i < ARRAY_SIZE(sh4_defs); i++) |
253 | 0fd3ca30 | aurel32 | if (strcasecmp(name, sh4_defs[i].name) == 0) |
254 | 0fd3ca30 | aurel32 | return &sh4_defs[i];
|
255 | 0fd3ca30 | aurel32 | |
256 | 0fd3ca30 | aurel32 | return NULL; |
257 | 0fd3ca30 | aurel32 | } |
258 | 0fd3ca30 | aurel32 | |
259 | 0fd3ca30 | aurel32 | void sh4_cpu_list(FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt, ...)) |
260 | 0fd3ca30 | aurel32 | { |
261 | 0fd3ca30 | aurel32 | int i;
|
262 | 0fd3ca30 | aurel32 | |
263 | b1503cda | malc | for (i = 0; i < ARRAY_SIZE(sh4_defs); i++) |
264 | 0fd3ca30 | aurel32 | (*cpu_fprintf)(f, "%s\n", sh4_defs[i].name);
|
265 | 0fd3ca30 | aurel32 | } |
266 | 0fd3ca30 | aurel32 | |
267 | 1ed1a787 | blueswir1 | static void cpu_sh4_register(CPUSH4State *env, const sh4_def_t *def) |
268 | 0fd3ca30 | aurel32 | { |
269 | 0fd3ca30 | aurel32 | env->pvr = def->pvr; |
270 | 0fd3ca30 | aurel32 | env->prr = def->prr; |
271 | 0fd3ca30 | aurel32 | env->cvr = def->cvr; |
272 | 0fd3ca30 | aurel32 | env->id = def->id; |
273 | 0fd3ca30 | aurel32 | } |
274 | 0fd3ca30 | aurel32 | |
275 | aaed909a | bellard | CPUSH4State *cpu_sh4_init(const char *cpu_model) |
276 | fdf9b3e8 | bellard | { |
277 | fdf9b3e8 | bellard | CPUSH4State *env; |
278 | 0fd3ca30 | aurel32 | const sh4_def_t *def;
|
279 | fdf9b3e8 | bellard | |
280 | 0fd3ca30 | aurel32 | def = cpu_sh4_find_by_name(cpu_model); |
281 | 0fd3ca30 | aurel32 | if (!def)
|
282 | 0fd3ca30 | aurel32 | return NULL; |
283 | fdf9b3e8 | bellard | env = qemu_mallocz(sizeof(CPUSH4State));
|
284 | 71968fa6 | aurel32 | env->features = def->features; |
285 | fdf9b3e8 | bellard | cpu_exec_init(env); |
286 | 2e70f6ef | pbrook | sh4_translate_init(); |
287 | 7478757e | aurel32 | env->cpu_model_str = cpu_model; |
288 | fdf9b3e8 | bellard | cpu_sh4_reset(env); |
289 | 0fd3ca30 | aurel32 | cpu_sh4_register(env, def); |
290 | fdf9b3e8 | bellard | tlb_flush(env, 1);
|
291 | fdf9b3e8 | bellard | return env;
|
292 | fdf9b3e8 | bellard | } |
293 | fdf9b3e8 | bellard | |
294 | fdf9b3e8 | bellard | static void gen_goto_tb(DisasContext * ctx, int n, target_ulong dest) |
295 | fdf9b3e8 | bellard | { |
296 | fdf9b3e8 | bellard | TranslationBlock *tb; |
297 | fdf9b3e8 | bellard | tb = ctx->tb; |
298 | fdf9b3e8 | bellard | |
299 | fdf9b3e8 | bellard | if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
|
300 | fdf9b3e8 | bellard | !ctx->singlestep_enabled) { |
301 | fdf9b3e8 | bellard | /* Use a direct jump if in same page and singlestep not enabled */
|
302 | 57fec1fe | bellard | tcg_gen_goto_tb(n); |
303 | 3a8a44c4 | aurel32 | tcg_gen_movi_i32(cpu_pc, dest); |
304 | 57fec1fe | bellard | tcg_gen_exit_tb((long) tb + n);
|
305 | fdf9b3e8 | bellard | } else {
|
306 | 3a8a44c4 | aurel32 | tcg_gen_movi_i32(cpu_pc, dest); |
307 | 57fec1fe | bellard | if (ctx->singlestep_enabled)
|
308 | a7812ae4 | pbrook | gen_helper_debug(); |
309 | 57fec1fe | bellard | tcg_gen_exit_tb(0);
|
310 | fdf9b3e8 | bellard | } |
311 | fdf9b3e8 | bellard | } |
312 | fdf9b3e8 | bellard | |
313 | fdf9b3e8 | bellard | static void gen_jump(DisasContext * ctx) |
314 | fdf9b3e8 | bellard | { |
315 | fdf9b3e8 | bellard | if (ctx->delayed_pc == (uint32_t) - 1) { |
316 | fdf9b3e8 | bellard | /* Target is not statically known, it comes necessarily from a
|
317 | fdf9b3e8 | bellard | delayed jump as immediate jump are conditinal jumps */
|
318 | 1000822b | aurel32 | tcg_gen_mov_i32(cpu_pc, cpu_delayed_pc); |
319 | fdf9b3e8 | bellard | if (ctx->singlestep_enabled)
|
320 | a7812ae4 | pbrook | gen_helper_debug(); |
321 | 57fec1fe | bellard | tcg_gen_exit_tb(0);
|
322 | fdf9b3e8 | bellard | } else {
|
323 | fdf9b3e8 | bellard | gen_goto_tb(ctx, 0, ctx->delayed_pc);
|
324 | fdf9b3e8 | bellard | } |
325 | fdf9b3e8 | bellard | } |
326 | fdf9b3e8 | bellard | |
327 | 1000822b | aurel32 | static inline void gen_branch_slot(uint32_t delayed_pc, int t) |
328 | 1000822b | aurel32 | { |
329 | c55497ec | aurel32 | TCGv sr; |
330 | 1000822b | aurel32 | int label = gen_new_label();
|
331 | 1000822b | aurel32 | tcg_gen_movi_i32(cpu_delayed_pc, delayed_pc); |
332 | a7812ae4 | pbrook | sr = tcg_temp_new(); |
333 | c55497ec | aurel32 | tcg_gen_andi_i32(sr, cpu_sr, SR_T); |
334 | c55497ec | aurel32 | tcg_gen_brcondi_i32(TCG_COND_NE, sr, t ? SR_T : 0, label);
|
335 | 1000822b | aurel32 | tcg_gen_ori_i32(cpu_flags, cpu_flags, DELAY_SLOT_TRUE); |
336 | 1000822b | aurel32 | gen_set_label(label); |
337 | 1000822b | aurel32 | } |
338 | 1000822b | aurel32 | |
339 | fdf9b3e8 | bellard | /* Immediate conditional jump (bt or bf) */
|
340 | fdf9b3e8 | bellard | static void gen_conditional_jump(DisasContext * ctx, |
341 | fdf9b3e8 | bellard | target_ulong ift, target_ulong ifnott) |
342 | fdf9b3e8 | bellard | { |
343 | fdf9b3e8 | bellard | int l1;
|
344 | c55497ec | aurel32 | TCGv sr; |
345 | fdf9b3e8 | bellard | |
346 | fdf9b3e8 | bellard | l1 = gen_new_label(); |
347 | a7812ae4 | pbrook | sr = tcg_temp_new(); |
348 | c55497ec | aurel32 | tcg_gen_andi_i32(sr, cpu_sr, SR_T); |
349 | c55497ec | aurel32 | tcg_gen_brcondi_i32(TCG_COND_EQ, sr, SR_T, l1); |
350 | fdf9b3e8 | bellard | gen_goto_tb(ctx, 0, ifnott);
|
351 | fdf9b3e8 | bellard | gen_set_label(l1); |
352 | fdf9b3e8 | bellard | gen_goto_tb(ctx, 1, ift);
|
353 | fdf9b3e8 | bellard | } |
354 | fdf9b3e8 | bellard | |
355 | fdf9b3e8 | bellard | /* Delayed conditional jump (bt or bf) */
|
356 | fdf9b3e8 | bellard | static void gen_delayed_conditional_jump(DisasContext * ctx) |
357 | fdf9b3e8 | bellard | { |
358 | fdf9b3e8 | bellard | int l1;
|
359 | c55497ec | aurel32 | TCGv ds; |
360 | fdf9b3e8 | bellard | |
361 | fdf9b3e8 | bellard | l1 = gen_new_label(); |
362 | a7812ae4 | pbrook | ds = tcg_temp_new(); |
363 | c55497ec | aurel32 | tcg_gen_andi_i32(ds, cpu_flags, DELAY_SLOT_TRUE); |
364 | c55497ec | aurel32 | tcg_gen_brcondi_i32(TCG_COND_EQ, ds, DELAY_SLOT_TRUE, l1); |
365 | 823029f9 | ths | gen_goto_tb(ctx, 1, ctx->pc + 2); |
366 | fdf9b3e8 | bellard | gen_set_label(l1); |
367 | 1000822b | aurel32 | tcg_gen_andi_i32(cpu_flags, cpu_flags, ~DELAY_SLOT_TRUE); |
368 | 9c2a9ea1 | pbrook | gen_jump(ctx); |
369 | fdf9b3e8 | bellard | } |
370 | fdf9b3e8 | bellard | |
371 | a4625612 | aurel32 | static inline void gen_set_t(void) |
372 | a4625612 | aurel32 | { |
373 | a4625612 | aurel32 | tcg_gen_ori_i32(cpu_sr, cpu_sr, SR_T); |
374 | a4625612 | aurel32 | } |
375 | a4625612 | aurel32 | |
376 | a4625612 | aurel32 | static inline void gen_clr_t(void) |
377 | a4625612 | aurel32 | { |
378 | a4625612 | aurel32 | tcg_gen_andi_i32(cpu_sr, cpu_sr, ~SR_T); |
379 | a4625612 | aurel32 | } |
380 | a4625612 | aurel32 | |
381 | a4625612 | aurel32 | static inline void gen_cmp(int cond, TCGv t0, TCGv t1) |
382 | a4625612 | aurel32 | { |
383 | a4625612 | aurel32 | int label1 = gen_new_label();
|
384 | a4625612 | aurel32 | int label2 = gen_new_label();
|
385 | a4625612 | aurel32 | tcg_gen_brcond_i32(cond, t1, t0, label1); |
386 | a4625612 | aurel32 | gen_clr_t(); |
387 | a4625612 | aurel32 | tcg_gen_br(label2); |
388 | a4625612 | aurel32 | gen_set_label(label1); |
389 | a4625612 | aurel32 | gen_set_t(); |
390 | a4625612 | aurel32 | gen_set_label(label2); |
391 | a4625612 | aurel32 | } |
392 | a4625612 | aurel32 | |
393 | a4625612 | aurel32 | static inline void gen_cmp_imm(int cond, TCGv t0, int32_t imm) |
394 | a4625612 | aurel32 | { |
395 | a4625612 | aurel32 | int label1 = gen_new_label();
|
396 | a4625612 | aurel32 | int label2 = gen_new_label();
|
397 | a4625612 | aurel32 | tcg_gen_brcondi_i32(cond, t0, imm, label1); |
398 | a4625612 | aurel32 | gen_clr_t(); |
399 | a4625612 | aurel32 | tcg_gen_br(label2); |
400 | a4625612 | aurel32 | gen_set_label(label1); |
401 | a4625612 | aurel32 | gen_set_t(); |
402 | a4625612 | aurel32 | gen_set_label(label2); |
403 | a4625612 | aurel32 | } |
404 | a4625612 | aurel32 | |
405 | 1000822b | aurel32 | static inline void gen_store_flags(uint32_t flags) |
406 | 1000822b | aurel32 | { |
407 | 1000822b | aurel32 | tcg_gen_andi_i32(cpu_flags, cpu_flags, DELAY_SLOT_TRUE); |
408 | 1000822b | aurel32 | tcg_gen_ori_i32(cpu_flags, cpu_flags, flags); |
409 | 1000822b | aurel32 | } |
410 | 1000822b | aurel32 | |
411 | 69d6275b | aurel32 | static inline void gen_copy_bit_i32(TCGv t0, int p0, TCGv t1, int p1) |
412 | 69d6275b | aurel32 | { |
413 | a7812ae4 | pbrook | TCGv tmp = tcg_temp_new(); |
414 | 69d6275b | aurel32 | |
415 | 69d6275b | aurel32 | p0 &= 0x1f;
|
416 | 69d6275b | aurel32 | p1 &= 0x1f;
|
417 | 69d6275b | aurel32 | |
418 | 69d6275b | aurel32 | tcg_gen_andi_i32(tmp, t1, (1 << p1));
|
419 | 69d6275b | aurel32 | tcg_gen_andi_i32(t0, t0, ~(1 << p0));
|
420 | 69d6275b | aurel32 | if (p0 < p1)
|
421 | 69d6275b | aurel32 | tcg_gen_shri_i32(tmp, tmp, p1 - p0); |
422 | 69d6275b | aurel32 | else if (p0 > p1) |
423 | 69d6275b | aurel32 | tcg_gen_shli_i32(tmp, tmp, p0 - p1); |
424 | 69d6275b | aurel32 | tcg_gen_or_i32(t0, t0, tmp); |
425 | 69d6275b | aurel32 | |
426 | 69d6275b | aurel32 | tcg_temp_free(tmp); |
427 | 69d6275b | aurel32 | } |
428 | 69d6275b | aurel32 | |
429 | a7812ae4 | pbrook | static inline void gen_load_fpr64(TCGv_i64 t, int reg) |
430 | cc4ba6a9 | aurel32 | { |
431 | 66ba317c | aurel32 | tcg_gen_concat_i32_i64(t, cpu_fregs[reg + 1], cpu_fregs[reg]);
|
432 | cc4ba6a9 | aurel32 | } |
433 | cc4ba6a9 | aurel32 | |
434 | a7812ae4 | pbrook | static inline void gen_store_fpr64 (TCGv_i64 t, int reg) |
435 | cc4ba6a9 | aurel32 | { |
436 | a7812ae4 | pbrook | TCGv_i32 tmp = tcg_temp_new_i32(); |
437 | cc4ba6a9 | aurel32 | tcg_gen_trunc_i64_i32(tmp, t); |
438 | 66ba317c | aurel32 | tcg_gen_mov_i32(cpu_fregs[reg + 1], tmp);
|
439 | cc4ba6a9 | aurel32 | tcg_gen_shri_i64(t, t, 32);
|
440 | cc4ba6a9 | aurel32 | tcg_gen_trunc_i64_i32(tmp, t); |
441 | 66ba317c | aurel32 | tcg_gen_mov_i32(cpu_fregs[reg], tmp); |
442 | a7812ae4 | pbrook | tcg_temp_free_i32(tmp); |
443 | cc4ba6a9 | aurel32 | } |
444 | cc4ba6a9 | aurel32 | |
445 | fdf9b3e8 | bellard | #define B3_0 (ctx->opcode & 0xf) |
446 | fdf9b3e8 | bellard | #define B6_4 ((ctx->opcode >> 4) & 0x7) |
447 | fdf9b3e8 | bellard | #define B7_4 ((ctx->opcode >> 4) & 0xf) |
448 | fdf9b3e8 | bellard | #define B7_0 (ctx->opcode & 0xff) |
449 | fdf9b3e8 | bellard | #define B7_0s ((int32_t) (int8_t) (ctx->opcode & 0xff)) |
450 | fdf9b3e8 | bellard | #define B11_0s (ctx->opcode & 0x800 ? 0xfffff000 | (ctx->opcode & 0xfff) : \ |
451 | fdf9b3e8 | bellard | (ctx->opcode & 0xfff))
|
452 | fdf9b3e8 | bellard | #define B11_8 ((ctx->opcode >> 8) & 0xf) |
453 | fdf9b3e8 | bellard | #define B15_12 ((ctx->opcode >> 12) & 0xf) |
454 | fdf9b3e8 | bellard | |
455 | fdf9b3e8 | bellard | #define REG(x) ((x) < 8 && (ctx->sr & (SR_MD | SR_RB)) == (SR_MD | SR_RB) ? \ |
456 | 7efbe241 | aurel32 | (cpu_gregs[x + 16]) : (cpu_gregs[x]))
|
457 | fdf9b3e8 | bellard | |
458 | fdf9b3e8 | bellard | #define ALTREG(x) ((x) < 8 && (ctx->sr & (SR_MD | SR_RB)) != (SR_MD | SR_RB) \ |
459 | 7efbe241 | aurel32 | ? (cpu_gregs[x + 16]) : (cpu_gregs[x]))
|
460 | fdf9b3e8 | bellard | |
461 | eda9b09b | bellard | #define FREG(x) (ctx->fpscr & FPSCR_FR ? (x) ^ 0x10 : (x)) |
462 | f09111e0 | ths | #define XHACK(x) ((((x) & 1 ) << 4) | ((x) & 0xe)) |
463 | eda9b09b | bellard | #define XREG(x) (ctx->fpscr & FPSCR_FR ? XHACK(x) ^ 0x10 : XHACK(x)) |
464 | ea6cf6be | ths | #define DREG(x) FREG(x) /* Assumes lsb of (x) is always 0 */ |
465 | eda9b09b | bellard | |
466 | fdf9b3e8 | bellard | #define CHECK_NOT_DELAY_SLOT \
|
467 | d8299bcc | aurel32 | if (ctx->flags & (DELAY_SLOT | DELAY_SLOT_CONDITIONAL)) \
|
468 | d8299bcc | aurel32 | { \ |
469 | d8299bcc | aurel32 | tcg_gen_movi_i32(cpu_pc, ctx->pc-2); \
|
470 | d8299bcc | aurel32 | gen_helper_raise_slot_illegal_instruction(); \ |
471 | d8299bcc | aurel32 | ctx->bstate = BS_EXCP; \ |
472 | d8299bcc | aurel32 | return; \
|
473 | d8299bcc | aurel32 | } |
474 | fdf9b3e8 | bellard | |
475 | fe25591e | aurel32 | #define CHECK_PRIVILEGED \
|
476 | fe25591e | aurel32 | if (IS_USER(ctx)) { \
|
477 | d8299bcc | aurel32 | tcg_gen_movi_i32(cpu_pc, ctx->pc); \ |
478 | a7812ae4 | pbrook | gen_helper_raise_illegal_instruction(); \ |
479 | fe25591e | aurel32 | ctx->bstate = BS_EXCP; \ |
480 | fe25591e | aurel32 | return; \
|
481 | fe25591e | aurel32 | } |
482 | fe25591e | aurel32 | |
483 | d8299bcc | aurel32 | #define CHECK_FPU_ENABLED \
|
484 | d8299bcc | aurel32 | if (ctx->flags & SR_FD) { \
|
485 | d8299bcc | aurel32 | if (ctx->flags & (DELAY_SLOT | DELAY_SLOT_CONDITIONAL)) { \
|
486 | d8299bcc | aurel32 | tcg_gen_movi_i32(cpu_pc, ctx->pc-2); \
|
487 | d8299bcc | aurel32 | gen_helper_raise_slot_fpu_disable(); \ |
488 | d8299bcc | aurel32 | } else { \
|
489 | d8299bcc | aurel32 | tcg_gen_movi_i32(cpu_pc, ctx->pc); \ |
490 | d8299bcc | aurel32 | gen_helper_raise_fpu_disable(); \ |
491 | d8299bcc | aurel32 | } \ |
492 | d8299bcc | aurel32 | ctx->bstate = BS_EXCP; \ |
493 | d8299bcc | aurel32 | return; \
|
494 | d8299bcc | aurel32 | } |
495 | d8299bcc | aurel32 | |
496 | b1d8e52e | blueswir1 | static void _decode_opc(DisasContext * ctx) |
497 | fdf9b3e8 | bellard | { |
498 | fdf9b3e8 | bellard | #if 0
|
499 | fdf9b3e8 | bellard | fprintf(stderr, "Translating opcode 0x%04x\n", ctx->opcode);
|
500 | fdf9b3e8 | bellard | #endif
|
501 | f6198371 | aurel32 | |
502 | fdf9b3e8 | bellard | switch (ctx->opcode) {
|
503 | fdf9b3e8 | bellard | case 0x0019: /* div0u */ |
504 | 3a8a44c4 | aurel32 | tcg_gen_andi_i32(cpu_sr, cpu_sr, ~(SR_M | SR_Q | SR_T)); |
505 | fdf9b3e8 | bellard | return;
|
506 | fdf9b3e8 | bellard | case 0x000b: /* rts */ |
507 | 1000822b | aurel32 | CHECK_NOT_DELAY_SLOT |
508 | 1000822b | aurel32 | tcg_gen_mov_i32(cpu_delayed_pc, cpu_pr); |
509 | fdf9b3e8 | bellard | ctx->flags |= DELAY_SLOT; |
510 | fdf9b3e8 | bellard | ctx->delayed_pc = (uint32_t) - 1;
|
511 | fdf9b3e8 | bellard | return;
|
512 | fdf9b3e8 | bellard | case 0x0028: /* clrmac */ |
513 | 3a8a44c4 | aurel32 | tcg_gen_movi_i32(cpu_mach, 0);
|
514 | 3a8a44c4 | aurel32 | tcg_gen_movi_i32(cpu_macl, 0);
|
515 | fdf9b3e8 | bellard | return;
|
516 | fdf9b3e8 | bellard | case 0x0048: /* clrs */ |
517 | 3a8a44c4 | aurel32 | tcg_gen_andi_i32(cpu_sr, cpu_sr, ~SR_S); |
518 | fdf9b3e8 | bellard | return;
|
519 | fdf9b3e8 | bellard | case 0x0008: /* clrt */ |
520 | a4625612 | aurel32 | gen_clr_t(); |
521 | fdf9b3e8 | bellard | return;
|
522 | fdf9b3e8 | bellard | case 0x0038: /* ldtlb */ |
523 | fe25591e | aurel32 | CHECK_PRIVILEGED |
524 | a7812ae4 | pbrook | gen_helper_ldtlb(); |
525 | fdf9b3e8 | bellard | return;
|
526 | c5e814b2 | ths | case 0x002b: /* rte */ |
527 | fe25591e | aurel32 | CHECK_PRIVILEGED |
528 | 1000822b | aurel32 | CHECK_NOT_DELAY_SLOT |
529 | 1000822b | aurel32 | tcg_gen_mov_i32(cpu_sr, cpu_ssr); |
530 | 1000822b | aurel32 | tcg_gen_mov_i32(cpu_delayed_pc, cpu_spc); |
531 | fdf9b3e8 | bellard | ctx->flags |= DELAY_SLOT; |
532 | fdf9b3e8 | bellard | ctx->delayed_pc = (uint32_t) - 1;
|
533 | fdf9b3e8 | bellard | return;
|
534 | fdf9b3e8 | bellard | case 0x0058: /* sets */ |
535 | 3a8a44c4 | aurel32 | tcg_gen_ori_i32(cpu_sr, cpu_sr, SR_S); |
536 | fdf9b3e8 | bellard | return;
|
537 | fdf9b3e8 | bellard | case 0x0018: /* sett */ |
538 | a4625612 | aurel32 | gen_set_t(); |
539 | fdf9b3e8 | bellard | return;
|
540 | 24988dc2 | aurel32 | case 0xfbfd: /* frchg */ |
541 | 6f06939b | aurel32 | tcg_gen_xori_i32(cpu_fpscr, cpu_fpscr, FPSCR_FR); |
542 | 823029f9 | ths | ctx->bstate = BS_STOP; |
543 | fdf9b3e8 | bellard | return;
|
544 | 24988dc2 | aurel32 | case 0xf3fd: /* fschg */ |
545 | 6f06939b | aurel32 | tcg_gen_xori_i32(cpu_fpscr, cpu_fpscr, FPSCR_SZ); |
546 | 823029f9 | ths | ctx->bstate = BS_STOP; |
547 | fdf9b3e8 | bellard | return;
|
548 | fdf9b3e8 | bellard | case 0x0009: /* nop */ |
549 | fdf9b3e8 | bellard | return;
|
550 | fdf9b3e8 | bellard | case 0x001b: /* sleep */ |
551 | fe25591e | aurel32 | CHECK_PRIVILEGED |
552 | a7812ae4 | pbrook | gen_helper_sleep(tcg_const_i32(ctx->pc + 2));
|
553 | fdf9b3e8 | bellard | return;
|
554 | fdf9b3e8 | bellard | } |
555 | fdf9b3e8 | bellard | |
556 | fdf9b3e8 | bellard | switch (ctx->opcode & 0xf000) { |
557 | fdf9b3e8 | bellard | case 0x1000: /* mov.l Rm,@(disp,Rn) */ |
558 | c55497ec | aurel32 | { |
559 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
560 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, REG(B11_8), B3_0 * 4);
|
561 | c55497ec | aurel32 | tcg_gen_qemu_st32(REG(B7_4), addr, ctx->memidx); |
562 | c55497ec | aurel32 | tcg_temp_free(addr); |
563 | c55497ec | aurel32 | } |
564 | fdf9b3e8 | bellard | return;
|
565 | fdf9b3e8 | bellard | case 0x5000: /* mov.l @(disp,Rm),Rn */ |
566 | c55497ec | aurel32 | { |
567 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
568 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, REG(B7_4), B3_0 * 4);
|
569 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(REG(B11_8), addr, ctx->memidx); |
570 | c55497ec | aurel32 | tcg_temp_free(addr); |
571 | c55497ec | aurel32 | } |
572 | fdf9b3e8 | bellard | return;
|
573 | 24988dc2 | aurel32 | case 0xe000: /* mov #imm,Rn */ |
574 | 7efbe241 | aurel32 | tcg_gen_movi_i32(REG(B11_8), B7_0s); |
575 | fdf9b3e8 | bellard | return;
|
576 | fdf9b3e8 | bellard | case 0x9000: /* mov.w @(disp,PC),Rn */ |
577 | c55497ec | aurel32 | { |
578 | c55497ec | aurel32 | TCGv addr = tcg_const_i32(ctx->pc + 4 + B7_0 * 2); |
579 | c55497ec | aurel32 | tcg_gen_qemu_ld16s(REG(B11_8), addr, ctx->memidx); |
580 | c55497ec | aurel32 | tcg_temp_free(addr); |
581 | c55497ec | aurel32 | } |
582 | fdf9b3e8 | bellard | return;
|
583 | fdf9b3e8 | bellard | case 0xd000: /* mov.l @(disp,PC),Rn */ |
584 | c55497ec | aurel32 | { |
585 | c55497ec | aurel32 | TCGv addr = tcg_const_i32((ctx->pc + 4 + B7_0 * 4) & ~3); |
586 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(REG(B11_8), addr, ctx->memidx); |
587 | c55497ec | aurel32 | tcg_temp_free(addr); |
588 | c55497ec | aurel32 | } |
589 | fdf9b3e8 | bellard | return;
|
590 | 24988dc2 | aurel32 | case 0x7000: /* add #imm,Rn */ |
591 | 7efbe241 | aurel32 | tcg_gen_addi_i32(REG(B11_8), REG(B11_8), B7_0s); |
592 | fdf9b3e8 | bellard | return;
|
593 | fdf9b3e8 | bellard | case 0xa000: /* bra disp */ |
594 | fdf9b3e8 | bellard | CHECK_NOT_DELAY_SLOT |
595 | 1000822b | aurel32 | ctx->delayed_pc = ctx->pc + 4 + B11_0s * 2; |
596 | 1000822b | aurel32 | tcg_gen_movi_i32(cpu_delayed_pc, ctx->delayed_pc); |
597 | fdf9b3e8 | bellard | ctx->flags |= DELAY_SLOT; |
598 | fdf9b3e8 | bellard | return;
|
599 | fdf9b3e8 | bellard | case 0xb000: /* bsr disp */ |
600 | fdf9b3e8 | bellard | CHECK_NOT_DELAY_SLOT |
601 | 1000822b | aurel32 | tcg_gen_movi_i32(cpu_pr, ctx->pc + 4);
|
602 | 1000822b | aurel32 | ctx->delayed_pc = ctx->pc + 4 + B11_0s * 2; |
603 | 1000822b | aurel32 | tcg_gen_movi_i32(cpu_delayed_pc, ctx->delayed_pc); |
604 | fdf9b3e8 | bellard | ctx->flags |= DELAY_SLOT; |
605 | fdf9b3e8 | bellard | return;
|
606 | fdf9b3e8 | bellard | } |
607 | fdf9b3e8 | bellard | |
608 | fdf9b3e8 | bellard | switch (ctx->opcode & 0xf00f) { |
609 | fdf9b3e8 | bellard | case 0x6003: /* mov Rm,Rn */ |
610 | 7efbe241 | aurel32 | tcg_gen_mov_i32(REG(B11_8), REG(B7_4)); |
611 | fdf9b3e8 | bellard | return;
|
612 | fdf9b3e8 | bellard | case 0x2000: /* mov.b Rm,@Rn */ |
613 | 7efbe241 | aurel32 | tcg_gen_qemu_st8(REG(B7_4), REG(B11_8), ctx->memidx); |
614 | fdf9b3e8 | bellard | return;
|
615 | fdf9b3e8 | bellard | case 0x2001: /* mov.w Rm,@Rn */ |
616 | 7efbe241 | aurel32 | tcg_gen_qemu_st16(REG(B7_4), REG(B11_8), ctx->memidx); |
617 | fdf9b3e8 | bellard | return;
|
618 | fdf9b3e8 | bellard | case 0x2002: /* mov.l Rm,@Rn */ |
619 | 7efbe241 | aurel32 | tcg_gen_qemu_st32(REG(B7_4), REG(B11_8), ctx->memidx); |
620 | fdf9b3e8 | bellard | return;
|
621 | fdf9b3e8 | bellard | case 0x6000: /* mov.b @Rm,Rn */ |
622 | 7efbe241 | aurel32 | tcg_gen_qemu_ld8s(REG(B11_8), REG(B7_4), ctx->memidx); |
623 | fdf9b3e8 | bellard | return;
|
624 | fdf9b3e8 | bellard | case 0x6001: /* mov.w @Rm,Rn */ |
625 | 7efbe241 | aurel32 | tcg_gen_qemu_ld16s(REG(B11_8), REG(B7_4), ctx->memidx); |
626 | fdf9b3e8 | bellard | return;
|
627 | fdf9b3e8 | bellard | case 0x6002: /* mov.l @Rm,Rn */ |
628 | 7efbe241 | aurel32 | tcg_gen_qemu_ld32s(REG(B11_8), REG(B7_4), ctx->memidx); |
629 | fdf9b3e8 | bellard | return;
|
630 | fdf9b3e8 | bellard | case 0x2004: /* mov.b Rm,@-Rn */ |
631 | c55497ec | aurel32 | { |
632 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
633 | c55497ec | aurel32 | tcg_gen_subi_i32(addr, REG(B11_8), 1);
|
634 | c55497ec | aurel32 | tcg_gen_qemu_st8(REG(B7_4), addr, ctx->memidx); /* might cause re-execution */
|
635 | c55497ec | aurel32 | tcg_gen_subi_i32(REG(B11_8), REG(B11_8), 1); /* modify register status */ |
636 | c55497ec | aurel32 | tcg_temp_free(addr); |
637 | c55497ec | aurel32 | } |
638 | fdf9b3e8 | bellard | return;
|
639 | fdf9b3e8 | bellard | case 0x2005: /* mov.w Rm,@-Rn */ |
640 | c55497ec | aurel32 | { |
641 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
642 | c55497ec | aurel32 | tcg_gen_subi_i32(addr, REG(B11_8), 2);
|
643 | c55497ec | aurel32 | tcg_gen_qemu_st16(REG(B7_4), addr, ctx->memidx); |
644 | c55497ec | aurel32 | tcg_gen_subi_i32(REG(B11_8), REG(B11_8), 2);
|
645 | c55497ec | aurel32 | tcg_temp_free(addr); |
646 | c55497ec | aurel32 | } |
647 | fdf9b3e8 | bellard | return;
|
648 | fdf9b3e8 | bellard | case 0x2006: /* mov.l Rm,@-Rn */ |
649 | c55497ec | aurel32 | { |
650 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
651 | c55497ec | aurel32 | tcg_gen_subi_i32(addr, REG(B11_8), 4);
|
652 | c55497ec | aurel32 | tcg_gen_qemu_st32(REG(B7_4), addr, ctx->memidx); |
653 | c55497ec | aurel32 | tcg_gen_subi_i32(REG(B11_8), REG(B11_8), 4);
|
654 | c55497ec | aurel32 | } |
655 | fdf9b3e8 | bellard | return;
|
656 | eda9b09b | bellard | case 0x6004: /* mov.b @Rm+,Rn */ |
657 | 7efbe241 | aurel32 | tcg_gen_qemu_ld8s(REG(B11_8), REG(B7_4), ctx->memidx); |
658 | 24988dc2 | aurel32 | if ( B11_8 != B7_4 )
|
659 | 7efbe241 | aurel32 | tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 1);
|
660 | fdf9b3e8 | bellard | return;
|
661 | fdf9b3e8 | bellard | case 0x6005: /* mov.w @Rm+,Rn */ |
662 | 7efbe241 | aurel32 | tcg_gen_qemu_ld16s(REG(B11_8), REG(B7_4), ctx->memidx); |
663 | 24988dc2 | aurel32 | if ( B11_8 != B7_4 )
|
664 | 7efbe241 | aurel32 | tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 2);
|
665 | fdf9b3e8 | bellard | return;
|
666 | fdf9b3e8 | bellard | case 0x6006: /* mov.l @Rm+,Rn */ |
667 | 7efbe241 | aurel32 | tcg_gen_qemu_ld32s(REG(B11_8), REG(B7_4), ctx->memidx); |
668 | 24988dc2 | aurel32 | if ( B11_8 != B7_4 )
|
669 | 7efbe241 | aurel32 | tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 4);
|
670 | fdf9b3e8 | bellard | return;
|
671 | fdf9b3e8 | bellard | case 0x0004: /* mov.b Rm,@(R0,Rn) */ |
672 | c55497ec | aurel32 | { |
673 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
674 | c55497ec | aurel32 | tcg_gen_add_i32(addr, REG(B11_8), REG(0));
|
675 | c55497ec | aurel32 | tcg_gen_qemu_st8(REG(B7_4), addr, ctx->memidx); |
676 | c55497ec | aurel32 | tcg_temp_free(addr); |
677 | c55497ec | aurel32 | } |
678 | fdf9b3e8 | bellard | return;
|
679 | fdf9b3e8 | bellard | case 0x0005: /* mov.w Rm,@(R0,Rn) */ |
680 | c55497ec | aurel32 | { |
681 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
682 | c55497ec | aurel32 | tcg_gen_add_i32(addr, REG(B11_8), REG(0));
|
683 | c55497ec | aurel32 | tcg_gen_qemu_st16(REG(B7_4), addr, ctx->memidx); |
684 | c55497ec | aurel32 | tcg_temp_free(addr); |
685 | c55497ec | aurel32 | } |
686 | fdf9b3e8 | bellard | return;
|
687 | fdf9b3e8 | bellard | case 0x0006: /* mov.l Rm,@(R0,Rn) */ |
688 | c55497ec | aurel32 | { |
689 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
690 | c55497ec | aurel32 | tcg_gen_add_i32(addr, REG(B11_8), REG(0));
|
691 | c55497ec | aurel32 | tcg_gen_qemu_st32(REG(B7_4), addr, ctx->memidx); |
692 | c55497ec | aurel32 | tcg_temp_free(addr); |
693 | c55497ec | aurel32 | } |
694 | fdf9b3e8 | bellard | return;
|
695 | fdf9b3e8 | bellard | case 0x000c: /* mov.b @(R0,Rm),Rn */ |
696 | c55497ec | aurel32 | { |
697 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
698 | c55497ec | aurel32 | tcg_gen_add_i32(addr, REG(B7_4), REG(0));
|
699 | c55497ec | aurel32 | tcg_gen_qemu_ld8s(REG(B11_8), addr, ctx->memidx); |
700 | c55497ec | aurel32 | tcg_temp_free(addr); |
701 | c55497ec | aurel32 | } |
702 | fdf9b3e8 | bellard | return;
|
703 | fdf9b3e8 | bellard | case 0x000d: /* mov.w @(R0,Rm),Rn */ |
704 | c55497ec | aurel32 | { |
705 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
706 | c55497ec | aurel32 | tcg_gen_add_i32(addr, REG(B7_4), REG(0));
|
707 | c55497ec | aurel32 | tcg_gen_qemu_ld16s(REG(B11_8), addr, ctx->memidx); |
708 | c55497ec | aurel32 | tcg_temp_free(addr); |
709 | c55497ec | aurel32 | } |
710 | fdf9b3e8 | bellard | return;
|
711 | fdf9b3e8 | bellard | case 0x000e: /* mov.l @(R0,Rm),Rn */ |
712 | c55497ec | aurel32 | { |
713 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
714 | c55497ec | aurel32 | tcg_gen_add_i32(addr, REG(B7_4), REG(0));
|
715 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(REG(B11_8), addr, ctx->memidx); |
716 | c55497ec | aurel32 | tcg_temp_free(addr); |
717 | c55497ec | aurel32 | } |
718 | fdf9b3e8 | bellard | return;
|
719 | fdf9b3e8 | bellard | case 0x6008: /* swap.b Rm,Rn */ |
720 | c55497ec | aurel32 | { |
721 | c69e3264 | aurel32 | TCGv highw, high, low; |
722 | a7812ae4 | pbrook | highw = tcg_temp_new(); |
723 | c69e3264 | aurel32 | tcg_gen_andi_i32(highw, REG(B7_4), 0xffff0000);
|
724 | a7812ae4 | pbrook | high = tcg_temp_new(); |
725 | c55497ec | aurel32 | tcg_gen_ext8u_i32(high, REG(B7_4)); |
726 | c55497ec | aurel32 | tcg_gen_shli_i32(high, high, 8);
|
727 | a7812ae4 | pbrook | low = tcg_temp_new(); |
728 | c55497ec | aurel32 | tcg_gen_shri_i32(low, REG(B7_4), 8);
|
729 | c55497ec | aurel32 | tcg_gen_ext8u_i32(low, low); |
730 | c55497ec | aurel32 | tcg_gen_or_i32(REG(B11_8), high, low); |
731 | c69e3264 | aurel32 | tcg_gen_or_i32(REG(B11_8), REG(B11_8), highw); |
732 | c55497ec | aurel32 | tcg_temp_free(low); |
733 | c55497ec | aurel32 | tcg_temp_free(high); |
734 | c55497ec | aurel32 | } |
735 | fdf9b3e8 | bellard | return;
|
736 | fdf9b3e8 | bellard | case 0x6009: /* swap.w Rm,Rn */ |
737 | c55497ec | aurel32 | { |
738 | c55497ec | aurel32 | TCGv high, low; |
739 | a7812ae4 | pbrook | high = tcg_temp_new(); |
740 | c55497ec | aurel32 | tcg_gen_ext16u_i32(high, REG(B7_4)); |
741 | c55497ec | aurel32 | tcg_gen_shli_i32(high, high, 16);
|
742 | a7812ae4 | pbrook | low = tcg_temp_new(); |
743 | c55497ec | aurel32 | tcg_gen_shri_i32(low, REG(B7_4), 16);
|
744 | c55497ec | aurel32 | tcg_gen_ext16u_i32(low, low); |
745 | c55497ec | aurel32 | tcg_gen_or_i32(REG(B11_8), high, low); |
746 | c55497ec | aurel32 | tcg_temp_free(low); |
747 | c55497ec | aurel32 | tcg_temp_free(high); |
748 | c55497ec | aurel32 | } |
749 | fdf9b3e8 | bellard | return;
|
750 | fdf9b3e8 | bellard | case 0x200d: /* xtrct Rm,Rn */ |
751 | c55497ec | aurel32 | { |
752 | c55497ec | aurel32 | TCGv high, low; |
753 | a7812ae4 | pbrook | high = tcg_temp_new(); |
754 | c55497ec | aurel32 | tcg_gen_ext16u_i32(high, REG(B7_4)); |
755 | c55497ec | aurel32 | tcg_gen_shli_i32(high, high, 16);
|
756 | a7812ae4 | pbrook | low = tcg_temp_new(); |
757 | c55497ec | aurel32 | tcg_gen_shri_i32(low, REG(B11_8), 16);
|
758 | c55497ec | aurel32 | tcg_gen_ext16u_i32(low, low); |
759 | c55497ec | aurel32 | tcg_gen_or_i32(REG(B11_8), high, low); |
760 | c55497ec | aurel32 | tcg_temp_free(low); |
761 | c55497ec | aurel32 | tcg_temp_free(high); |
762 | c55497ec | aurel32 | } |
763 | fdf9b3e8 | bellard | return;
|
764 | fdf9b3e8 | bellard | case 0x300c: /* add Rm,Rn */ |
765 | 7efbe241 | aurel32 | tcg_gen_add_i32(REG(B11_8), REG(B11_8), REG(B7_4)); |
766 | fdf9b3e8 | bellard | return;
|
767 | fdf9b3e8 | bellard | case 0x300e: /* addc Rm,Rn */ |
768 | a7812ae4 | pbrook | gen_helper_addc(REG(B11_8), REG(B7_4), REG(B11_8)); |
769 | fdf9b3e8 | bellard | return;
|
770 | fdf9b3e8 | bellard | case 0x300f: /* addv Rm,Rn */ |
771 | a7812ae4 | pbrook | gen_helper_addv(REG(B11_8), REG(B7_4), REG(B11_8)); |
772 | fdf9b3e8 | bellard | return;
|
773 | fdf9b3e8 | bellard | case 0x2009: /* and Rm,Rn */ |
774 | 7efbe241 | aurel32 | tcg_gen_and_i32(REG(B11_8), REG(B11_8), REG(B7_4)); |
775 | fdf9b3e8 | bellard | return;
|
776 | fdf9b3e8 | bellard | case 0x3000: /* cmp/eq Rm,Rn */ |
777 | 7efbe241 | aurel32 | gen_cmp(TCG_COND_EQ, REG(B7_4), REG(B11_8)); |
778 | fdf9b3e8 | bellard | return;
|
779 | fdf9b3e8 | bellard | case 0x3003: /* cmp/ge Rm,Rn */ |
780 | 7efbe241 | aurel32 | gen_cmp(TCG_COND_GE, REG(B7_4), REG(B11_8)); |
781 | fdf9b3e8 | bellard | return;
|
782 | fdf9b3e8 | bellard | case 0x3007: /* cmp/gt Rm,Rn */ |
783 | 7efbe241 | aurel32 | gen_cmp(TCG_COND_GT, REG(B7_4), REG(B11_8)); |
784 | fdf9b3e8 | bellard | return;
|
785 | fdf9b3e8 | bellard | case 0x3006: /* cmp/hi Rm,Rn */ |
786 | 7efbe241 | aurel32 | gen_cmp(TCG_COND_GTU, REG(B7_4), REG(B11_8)); |
787 | fdf9b3e8 | bellard | return;
|
788 | fdf9b3e8 | bellard | case 0x3002: /* cmp/hs Rm,Rn */ |
789 | 7efbe241 | aurel32 | gen_cmp(TCG_COND_GEU, REG(B7_4), REG(B11_8)); |
790 | fdf9b3e8 | bellard | return;
|
791 | fdf9b3e8 | bellard | case 0x200c: /* cmp/str Rm,Rn */ |
792 | 69d6275b | aurel32 | { |
793 | 69d6275b | aurel32 | int label1 = gen_new_label();
|
794 | 69d6275b | aurel32 | int label2 = gen_new_label();
|
795 | df9247b2 | aurel32 | TCGv cmp1 = tcg_temp_local_new(); |
796 | df9247b2 | aurel32 | TCGv cmp2 = tcg_temp_local_new(); |
797 | c55497ec | aurel32 | tcg_gen_xor_i32(cmp1, REG(B7_4), REG(B11_8)); |
798 | c55497ec | aurel32 | tcg_gen_andi_i32(cmp2, cmp1, 0xff000000);
|
799 | c55497ec | aurel32 | tcg_gen_brcondi_i32(TCG_COND_EQ, cmp2, 0, label1);
|
800 | c55497ec | aurel32 | tcg_gen_andi_i32(cmp2, cmp1, 0x00ff0000);
|
801 | c55497ec | aurel32 | tcg_gen_brcondi_i32(TCG_COND_EQ, cmp2, 0, label1);
|
802 | c55497ec | aurel32 | tcg_gen_andi_i32(cmp2, cmp1, 0x0000ff00);
|
803 | c55497ec | aurel32 | tcg_gen_brcondi_i32(TCG_COND_EQ, cmp2, 0, label1);
|
804 | c55497ec | aurel32 | tcg_gen_andi_i32(cmp2, cmp1, 0x000000ff);
|
805 | c55497ec | aurel32 | tcg_gen_brcondi_i32(TCG_COND_EQ, cmp2, 0, label1);
|
806 | 69d6275b | aurel32 | tcg_gen_andi_i32(cpu_sr, cpu_sr, ~SR_T); |
807 | 69d6275b | aurel32 | tcg_gen_br(label2); |
808 | 69d6275b | aurel32 | gen_set_label(label1); |
809 | 69d6275b | aurel32 | tcg_gen_ori_i32(cpu_sr, cpu_sr, SR_T); |
810 | 69d6275b | aurel32 | gen_set_label(label2); |
811 | c55497ec | aurel32 | tcg_temp_free(cmp2); |
812 | c55497ec | aurel32 | tcg_temp_free(cmp1); |
813 | 69d6275b | aurel32 | } |
814 | fdf9b3e8 | bellard | return;
|
815 | fdf9b3e8 | bellard | case 0x2007: /* div0s Rm,Rn */ |
816 | c55497ec | aurel32 | { |
817 | c55497ec | aurel32 | gen_copy_bit_i32(cpu_sr, 8, REG(B11_8), 31); /* SR_Q */ |
818 | c55497ec | aurel32 | gen_copy_bit_i32(cpu_sr, 9, REG(B7_4), 31); /* SR_M */ |
819 | a7812ae4 | pbrook | TCGv val = tcg_temp_new(); |
820 | c55497ec | aurel32 | tcg_gen_xor_i32(val, REG(B7_4), REG(B11_8)); |
821 | c55497ec | aurel32 | gen_copy_bit_i32(cpu_sr, 0, val, 31); /* SR_T */ |
822 | c55497ec | aurel32 | tcg_temp_free(val); |
823 | c55497ec | aurel32 | } |
824 | fdf9b3e8 | bellard | return;
|
825 | fdf9b3e8 | bellard | case 0x3004: /* div1 Rm,Rn */ |
826 | a7812ae4 | pbrook | gen_helper_div1(REG(B11_8), REG(B7_4), REG(B11_8)); |
827 | fdf9b3e8 | bellard | return;
|
828 | fdf9b3e8 | bellard | case 0x300d: /* dmuls.l Rm,Rn */ |
829 | 6f06939b | aurel32 | { |
830 | a7812ae4 | pbrook | TCGv_i64 tmp1 = tcg_temp_new_i64(); |
831 | a7812ae4 | pbrook | TCGv_i64 tmp2 = tcg_temp_new_i64(); |
832 | 6f06939b | aurel32 | |
833 | 7efbe241 | aurel32 | tcg_gen_ext_i32_i64(tmp1, REG(B7_4)); |
834 | 7efbe241 | aurel32 | tcg_gen_ext_i32_i64(tmp2, REG(B11_8)); |
835 | 6f06939b | aurel32 | tcg_gen_mul_i64(tmp1, tmp1, tmp2); |
836 | 6f06939b | aurel32 | tcg_gen_trunc_i64_i32(cpu_macl, tmp1); |
837 | 6f06939b | aurel32 | tcg_gen_shri_i64(tmp1, tmp1, 32);
|
838 | 6f06939b | aurel32 | tcg_gen_trunc_i64_i32(cpu_mach, tmp1); |
839 | 6f06939b | aurel32 | |
840 | a7812ae4 | pbrook | tcg_temp_free_i64(tmp2); |
841 | a7812ae4 | pbrook | tcg_temp_free_i64(tmp1); |
842 | 6f06939b | aurel32 | } |
843 | fdf9b3e8 | bellard | return;
|
844 | fdf9b3e8 | bellard | case 0x3005: /* dmulu.l Rm,Rn */ |
845 | 6f06939b | aurel32 | { |
846 | a7812ae4 | pbrook | TCGv_i64 tmp1 = tcg_temp_new_i64(); |
847 | a7812ae4 | pbrook | TCGv_i64 tmp2 = tcg_temp_new_i64(); |
848 | 6f06939b | aurel32 | |
849 | 7efbe241 | aurel32 | tcg_gen_extu_i32_i64(tmp1, REG(B7_4)); |
850 | 7efbe241 | aurel32 | tcg_gen_extu_i32_i64(tmp2, REG(B11_8)); |
851 | 6f06939b | aurel32 | tcg_gen_mul_i64(tmp1, tmp1, tmp2); |
852 | 6f06939b | aurel32 | tcg_gen_trunc_i64_i32(cpu_macl, tmp1); |
853 | 6f06939b | aurel32 | tcg_gen_shri_i64(tmp1, tmp1, 32);
|
854 | 6f06939b | aurel32 | tcg_gen_trunc_i64_i32(cpu_mach, tmp1); |
855 | 6f06939b | aurel32 | |
856 | a7812ae4 | pbrook | tcg_temp_free_i64(tmp2); |
857 | a7812ae4 | pbrook | tcg_temp_free_i64(tmp1); |
858 | 6f06939b | aurel32 | } |
859 | fdf9b3e8 | bellard | return;
|
860 | fdf9b3e8 | bellard | case 0x600e: /* exts.b Rm,Rn */ |
861 | 7efbe241 | aurel32 | tcg_gen_ext8s_i32(REG(B11_8), REG(B7_4)); |
862 | fdf9b3e8 | bellard | return;
|
863 | fdf9b3e8 | bellard | case 0x600f: /* exts.w Rm,Rn */ |
864 | 7efbe241 | aurel32 | tcg_gen_ext16s_i32(REG(B11_8), REG(B7_4)); |
865 | fdf9b3e8 | bellard | return;
|
866 | fdf9b3e8 | bellard | case 0x600c: /* extu.b Rm,Rn */ |
867 | 7efbe241 | aurel32 | tcg_gen_ext8u_i32(REG(B11_8), REG(B7_4)); |
868 | fdf9b3e8 | bellard | return;
|
869 | fdf9b3e8 | bellard | case 0x600d: /* extu.w Rm,Rn */ |
870 | 7efbe241 | aurel32 | tcg_gen_ext16u_i32(REG(B11_8), REG(B7_4)); |
871 | fdf9b3e8 | bellard | return;
|
872 | 24988dc2 | aurel32 | case 0x000f: /* mac.l @Rm+,@Rn+ */ |
873 | c55497ec | aurel32 | { |
874 | c55497ec | aurel32 | TCGv arg0, arg1; |
875 | a7812ae4 | pbrook | arg0 = tcg_temp_new(); |
876 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(arg0, REG(B7_4), ctx->memidx); |
877 | a7812ae4 | pbrook | arg1 = tcg_temp_new(); |
878 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(arg1, REG(B11_8), ctx->memidx); |
879 | a7812ae4 | pbrook | gen_helper_macl(arg0, arg1); |
880 | c55497ec | aurel32 | tcg_temp_free(arg1); |
881 | c55497ec | aurel32 | tcg_temp_free(arg0); |
882 | c55497ec | aurel32 | tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 4);
|
883 | c55497ec | aurel32 | tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4);
|
884 | c55497ec | aurel32 | } |
885 | fdf9b3e8 | bellard | return;
|
886 | fdf9b3e8 | bellard | case 0x400f: /* mac.w @Rm+,@Rn+ */ |
887 | c55497ec | aurel32 | { |
888 | c55497ec | aurel32 | TCGv arg0, arg1; |
889 | a7812ae4 | pbrook | arg0 = tcg_temp_new(); |
890 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(arg0, REG(B7_4), ctx->memidx); |
891 | a7812ae4 | pbrook | arg1 = tcg_temp_new(); |
892 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(arg1, REG(B11_8), ctx->memidx); |
893 | a7812ae4 | pbrook | gen_helper_macw(arg0, arg1); |
894 | c55497ec | aurel32 | tcg_temp_free(arg1); |
895 | c55497ec | aurel32 | tcg_temp_free(arg0); |
896 | c55497ec | aurel32 | tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 2);
|
897 | c55497ec | aurel32 | tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 2);
|
898 | c55497ec | aurel32 | } |
899 | fdf9b3e8 | bellard | return;
|
900 | fdf9b3e8 | bellard | case 0x0007: /* mul.l Rm,Rn */ |
901 | 7efbe241 | aurel32 | tcg_gen_mul_i32(cpu_macl, REG(B7_4), REG(B11_8)); |
902 | fdf9b3e8 | bellard | return;
|
903 | fdf9b3e8 | bellard | case 0x200f: /* muls.w Rm,Rn */ |
904 | c55497ec | aurel32 | { |
905 | c55497ec | aurel32 | TCGv arg0, arg1; |
906 | a7812ae4 | pbrook | arg0 = tcg_temp_new(); |
907 | c55497ec | aurel32 | tcg_gen_ext16s_i32(arg0, REG(B7_4)); |
908 | a7812ae4 | pbrook | arg1 = tcg_temp_new(); |
909 | c55497ec | aurel32 | tcg_gen_ext16s_i32(arg1, REG(B11_8)); |
910 | c55497ec | aurel32 | tcg_gen_mul_i32(cpu_macl, arg0, arg1); |
911 | c55497ec | aurel32 | tcg_temp_free(arg1); |
912 | c55497ec | aurel32 | tcg_temp_free(arg0); |
913 | c55497ec | aurel32 | } |
914 | fdf9b3e8 | bellard | return;
|
915 | fdf9b3e8 | bellard | case 0x200e: /* mulu.w Rm,Rn */ |
916 | c55497ec | aurel32 | { |
917 | c55497ec | aurel32 | TCGv arg0, arg1; |
918 | a7812ae4 | pbrook | arg0 = tcg_temp_new(); |
919 | c55497ec | aurel32 | tcg_gen_ext16u_i32(arg0, REG(B7_4)); |
920 | a7812ae4 | pbrook | arg1 = tcg_temp_new(); |
921 | c55497ec | aurel32 | tcg_gen_ext16u_i32(arg1, REG(B11_8)); |
922 | c55497ec | aurel32 | tcg_gen_mul_i32(cpu_macl, arg0, arg1); |
923 | c55497ec | aurel32 | tcg_temp_free(arg1); |
924 | c55497ec | aurel32 | tcg_temp_free(arg0); |
925 | c55497ec | aurel32 | } |
926 | fdf9b3e8 | bellard | return;
|
927 | fdf9b3e8 | bellard | case 0x600b: /* neg Rm,Rn */ |
928 | 7efbe241 | aurel32 | tcg_gen_neg_i32(REG(B11_8), REG(B7_4)); |
929 | fdf9b3e8 | bellard | return;
|
930 | fdf9b3e8 | bellard | case 0x600a: /* negc Rm,Rn */ |
931 | a7812ae4 | pbrook | gen_helper_negc(REG(B11_8), REG(B7_4)); |
932 | fdf9b3e8 | bellard | return;
|
933 | fdf9b3e8 | bellard | case 0x6007: /* not Rm,Rn */ |
934 | 7efbe241 | aurel32 | tcg_gen_not_i32(REG(B11_8), REG(B7_4)); |
935 | fdf9b3e8 | bellard | return;
|
936 | fdf9b3e8 | bellard | case 0x200b: /* or Rm,Rn */ |
937 | 7efbe241 | aurel32 | tcg_gen_or_i32(REG(B11_8), REG(B11_8), REG(B7_4)); |
938 | fdf9b3e8 | bellard | return;
|
939 | fdf9b3e8 | bellard | case 0x400c: /* shad Rm,Rn */ |
940 | 69d6275b | aurel32 | { |
941 | 69d6275b | aurel32 | int label1 = gen_new_label();
|
942 | 69d6275b | aurel32 | int label2 = gen_new_label();
|
943 | 69d6275b | aurel32 | int label3 = gen_new_label();
|
944 | 69d6275b | aurel32 | int label4 = gen_new_label();
|
945 | df9247b2 | aurel32 | TCGv shift = tcg_temp_local_new(); |
946 | 7efbe241 | aurel32 | tcg_gen_brcondi_i32(TCG_COND_LT, REG(B7_4), 0, label1);
|
947 | 69d6275b | aurel32 | /* Rm positive, shift to the left */
|
948 | c55497ec | aurel32 | tcg_gen_andi_i32(shift, REG(B7_4), 0x1f);
|
949 | c55497ec | aurel32 | tcg_gen_shl_i32(REG(B11_8), REG(B11_8), shift); |
950 | 69d6275b | aurel32 | tcg_gen_br(label4); |
951 | 69d6275b | aurel32 | /* Rm negative, shift to the right */
|
952 | 69d6275b | aurel32 | gen_set_label(label1); |
953 | c55497ec | aurel32 | tcg_gen_andi_i32(shift, REG(B7_4), 0x1f);
|
954 | c55497ec | aurel32 | tcg_gen_brcondi_i32(TCG_COND_EQ, shift, 0, label2);
|
955 | c55497ec | aurel32 | tcg_gen_not_i32(shift, REG(B7_4)); |
956 | c55497ec | aurel32 | tcg_gen_andi_i32(shift, shift, 0x1f);
|
957 | c55497ec | aurel32 | tcg_gen_addi_i32(shift, shift, 1);
|
958 | c55497ec | aurel32 | tcg_gen_sar_i32(REG(B11_8), REG(B11_8), shift); |
959 | 69d6275b | aurel32 | tcg_gen_br(label4); |
960 | 69d6275b | aurel32 | /* Rm = -32 */
|
961 | 69d6275b | aurel32 | gen_set_label(label2); |
962 | 7efbe241 | aurel32 | tcg_gen_brcondi_i32(TCG_COND_LT, REG(B11_8), 0, label3);
|
963 | 7efbe241 | aurel32 | tcg_gen_movi_i32(REG(B11_8), 0);
|
964 | 69d6275b | aurel32 | tcg_gen_br(label4); |
965 | 69d6275b | aurel32 | gen_set_label(label3); |
966 | 7efbe241 | aurel32 | tcg_gen_movi_i32(REG(B11_8), 0xffffffff);
|
967 | 69d6275b | aurel32 | gen_set_label(label4); |
968 | c55497ec | aurel32 | tcg_temp_free(shift); |
969 | 69d6275b | aurel32 | } |
970 | fdf9b3e8 | bellard | return;
|
971 | fdf9b3e8 | bellard | case 0x400d: /* shld Rm,Rn */ |
972 | 69d6275b | aurel32 | { |
973 | 69d6275b | aurel32 | int label1 = gen_new_label();
|
974 | 69d6275b | aurel32 | int label2 = gen_new_label();
|
975 | 69d6275b | aurel32 | int label3 = gen_new_label();
|
976 | df9247b2 | aurel32 | TCGv shift = tcg_temp_local_new(); |
977 | 7efbe241 | aurel32 | tcg_gen_brcondi_i32(TCG_COND_LT, REG(B7_4), 0, label1);
|
978 | 69d6275b | aurel32 | /* Rm positive, shift to the left */
|
979 | c55497ec | aurel32 | tcg_gen_andi_i32(shift, REG(B7_4), 0x1f);
|
980 | c55497ec | aurel32 | tcg_gen_shl_i32(REG(B11_8), REG(B11_8), shift); |
981 | 69d6275b | aurel32 | tcg_gen_br(label3); |
982 | 69d6275b | aurel32 | /* Rm negative, shift to the right */
|
983 | 69d6275b | aurel32 | gen_set_label(label1); |
984 | c55497ec | aurel32 | tcg_gen_andi_i32(shift, REG(B7_4), 0x1f);
|
985 | c55497ec | aurel32 | tcg_gen_brcondi_i32(TCG_COND_EQ, shift, 0, label2);
|
986 | c55497ec | aurel32 | tcg_gen_not_i32(shift, REG(B7_4)); |
987 | c55497ec | aurel32 | tcg_gen_andi_i32(shift, shift, 0x1f);
|
988 | c55497ec | aurel32 | tcg_gen_addi_i32(shift, shift, 1);
|
989 | c55497ec | aurel32 | tcg_gen_shr_i32(REG(B11_8), REG(B11_8), shift); |
990 | 69d6275b | aurel32 | tcg_gen_br(label3); |
991 | 69d6275b | aurel32 | /* Rm = -32 */
|
992 | 69d6275b | aurel32 | gen_set_label(label2); |
993 | 7efbe241 | aurel32 | tcg_gen_movi_i32(REG(B11_8), 0);
|
994 | 69d6275b | aurel32 | gen_set_label(label3); |
995 | c55497ec | aurel32 | tcg_temp_free(shift); |
996 | 69d6275b | aurel32 | } |
997 | fdf9b3e8 | bellard | return;
|
998 | fdf9b3e8 | bellard | case 0x3008: /* sub Rm,Rn */ |
999 | 7efbe241 | aurel32 | tcg_gen_sub_i32(REG(B11_8), REG(B11_8), REG(B7_4)); |
1000 | fdf9b3e8 | bellard | return;
|
1001 | fdf9b3e8 | bellard | case 0x300a: /* subc Rm,Rn */ |
1002 | a7812ae4 | pbrook | gen_helper_subc(REG(B11_8), REG(B7_4), REG(B11_8)); |
1003 | fdf9b3e8 | bellard | return;
|
1004 | fdf9b3e8 | bellard | case 0x300b: /* subv Rm,Rn */ |
1005 | a7812ae4 | pbrook | gen_helper_subv(REG(B11_8), REG(B7_4), REG(B11_8)); |
1006 | fdf9b3e8 | bellard | return;
|
1007 | fdf9b3e8 | bellard | case 0x2008: /* tst Rm,Rn */ |
1008 | c55497ec | aurel32 | { |
1009 | a7812ae4 | pbrook | TCGv val = tcg_temp_new(); |
1010 | c55497ec | aurel32 | tcg_gen_and_i32(val, REG(B7_4), REG(B11_8)); |
1011 | c55497ec | aurel32 | gen_cmp_imm(TCG_COND_EQ, val, 0);
|
1012 | c55497ec | aurel32 | tcg_temp_free(val); |
1013 | c55497ec | aurel32 | } |
1014 | fdf9b3e8 | bellard | return;
|
1015 | fdf9b3e8 | bellard | case 0x200a: /* xor Rm,Rn */ |
1016 | 7efbe241 | aurel32 | tcg_gen_xor_i32(REG(B11_8), REG(B11_8), REG(B7_4)); |
1017 | fdf9b3e8 | bellard | return;
|
1018 | e67888a7 | ths | case 0xf00c: /* fmov {F,D,X}Rm,{F,D,X}Rn - FPSCR: Nothing */ |
1019 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1020 | 022a22c7 | ths | if (ctx->fpscr & FPSCR_SZ) {
|
1021 | a7812ae4 | pbrook | TCGv_i64 fp = tcg_temp_new_i64(); |
1022 | cc4ba6a9 | aurel32 | gen_load_fpr64(fp, XREG(B7_4)); |
1023 | cc4ba6a9 | aurel32 | gen_store_fpr64(fp, XREG(B11_8)); |
1024 | a7812ae4 | pbrook | tcg_temp_free_i64(fp); |
1025 | eda9b09b | bellard | } else {
|
1026 | 66ba317c | aurel32 | tcg_gen_mov_i32(cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B7_4)]); |
1027 | eda9b09b | bellard | } |
1028 | eda9b09b | bellard | return;
|
1029 | e67888a7 | ths | case 0xf00a: /* fmov {F,D,X}Rm,@Rn - FPSCR: Nothing */ |
1030 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1031 | 022a22c7 | ths | if (ctx->fpscr & FPSCR_SZ) {
|
1032 | 11bb09f1 | aurel32 | TCGv addr_hi = tcg_temp_new(); |
1033 | 11bb09f1 | aurel32 | int fr = XREG(B7_4);
|
1034 | 11bb09f1 | aurel32 | tcg_gen_addi_i32(addr_hi, REG(B11_8), 4);
|
1035 | 11bb09f1 | aurel32 | tcg_gen_qemu_st32(cpu_fregs[fr ], REG(B11_8), ctx->memidx); |
1036 | 11bb09f1 | aurel32 | tcg_gen_qemu_st32(cpu_fregs[fr+1], addr_hi, ctx->memidx);
|
1037 | 11bb09f1 | aurel32 | tcg_temp_free(addr_hi); |
1038 | eda9b09b | bellard | } else {
|
1039 | 66ba317c | aurel32 | tcg_gen_qemu_st32(cpu_fregs[FREG(B7_4)], REG(B11_8), ctx->memidx); |
1040 | eda9b09b | bellard | } |
1041 | eda9b09b | bellard | return;
|
1042 | e67888a7 | ths | case 0xf008: /* fmov @Rm,{F,D,X}Rn - FPSCR: Nothing */ |
1043 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1044 | 022a22c7 | ths | if (ctx->fpscr & FPSCR_SZ) {
|
1045 | 11bb09f1 | aurel32 | TCGv addr_hi = tcg_temp_new(); |
1046 | 11bb09f1 | aurel32 | int fr = XREG(B11_8);
|
1047 | 11bb09f1 | aurel32 | tcg_gen_addi_i32(addr_hi, REG(B7_4), 4);
|
1048 | 11bb09f1 | aurel32 | tcg_gen_qemu_ld32u(cpu_fregs[fr ], REG(B7_4), ctx->memidx); |
1049 | 11bb09f1 | aurel32 | tcg_gen_qemu_ld32u(cpu_fregs[fr+1], addr_hi, ctx->memidx);
|
1050 | 11bb09f1 | aurel32 | tcg_temp_free(addr_hi); |
1051 | eda9b09b | bellard | } else {
|
1052 | 66ba317c | aurel32 | tcg_gen_qemu_ld32u(cpu_fregs[FREG(B11_8)], REG(B7_4), ctx->memidx); |
1053 | eda9b09b | bellard | } |
1054 | eda9b09b | bellard | return;
|
1055 | e67888a7 | ths | case 0xf009: /* fmov @Rm+,{F,D,X}Rn - FPSCR: Nothing */ |
1056 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1057 | 022a22c7 | ths | if (ctx->fpscr & FPSCR_SZ) {
|
1058 | 11bb09f1 | aurel32 | TCGv addr_hi = tcg_temp_new(); |
1059 | 11bb09f1 | aurel32 | int fr = XREG(B11_8);
|
1060 | 11bb09f1 | aurel32 | tcg_gen_addi_i32(addr_hi, REG(B7_4), 4);
|
1061 | 11bb09f1 | aurel32 | tcg_gen_qemu_ld32u(cpu_fregs[fr ], REG(B7_4), ctx->memidx); |
1062 | 11bb09f1 | aurel32 | tcg_gen_qemu_ld32u(cpu_fregs[fr+1], addr_hi, ctx->memidx);
|
1063 | 11bb09f1 | aurel32 | tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 8);
|
1064 | 11bb09f1 | aurel32 | tcg_temp_free(addr_hi); |
1065 | eda9b09b | bellard | } else {
|
1066 | 66ba317c | aurel32 | tcg_gen_qemu_ld32u(cpu_fregs[FREG(B11_8)], REG(B7_4), ctx->memidx); |
1067 | cc4ba6a9 | aurel32 | tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 4);
|
1068 | eda9b09b | bellard | } |
1069 | eda9b09b | bellard | return;
|
1070 | e67888a7 | ths | case 0xf00b: /* fmov {F,D,X}Rm,@-Rn - FPSCR: Nothing */ |
1071 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1072 | 022a22c7 | ths | if (ctx->fpscr & FPSCR_SZ) {
|
1073 | 11bb09f1 | aurel32 | TCGv addr = tcg_temp_new_i32(); |
1074 | 11bb09f1 | aurel32 | int fr = XREG(B7_4);
|
1075 | 11bb09f1 | aurel32 | tcg_gen_subi_i32(addr, REG(B11_8), 4);
|
1076 | 11bb09f1 | aurel32 | tcg_gen_qemu_st32(cpu_fregs[fr+1], addr, ctx->memidx);
|
1077 | cc4ba6a9 | aurel32 | tcg_gen_subi_i32(addr, REG(B11_8), 8);
|
1078 | 11bb09f1 | aurel32 | tcg_gen_qemu_st32(cpu_fregs[fr ], addr, ctx->memidx); |
1079 | 11bb09f1 | aurel32 | tcg_gen_mov_i32(REG(B11_8), addr); |
1080 | cc4ba6a9 | aurel32 | tcg_temp_free(addr); |
1081 | eda9b09b | bellard | } else {
|
1082 | a7812ae4 | pbrook | TCGv addr; |
1083 | a7812ae4 | pbrook | addr = tcg_temp_new_i32(); |
1084 | cc4ba6a9 | aurel32 | tcg_gen_subi_i32(addr, REG(B11_8), 4);
|
1085 | 66ba317c | aurel32 | tcg_gen_qemu_st32(cpu_fregs[FREG(B7_4)], addr, ctx->memidx); |
1086 | cc4ba6a9 | aurel32 | tcg_temp_free(addr); |
1087 | 7efbe241 | aurel32 | tcg_gen_subi_i32(REG(B11_8), REG(B11_8), 4);
|
1088 | eda9b09b | bellard | } |
1089 | eda9b09b | bellard | return;
|
1090 | e67888a7 | ths | case 0xf006: /* fmov @(R0,Rm),{F,D,X}Rm - FPSCR: Nothing */ |
1091 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1092 | cc4ba6a9 | aurel32 | { |
1093 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new_i32(); |
1094 | cc4ba6a9 | aurel32 | tcg_gen_add_i32(addr, REG(B7_4), REG(0));
|
1095 | cc4ba6a9 | aurel32 | if (ctx->fpscr & FPSCR_SZ) {
|
1096 | 11bb09f1 | aurel32 | int fr = XREG(B11_8);
|
1097 | 11bb09f1 | aurel32 | tcg_gen_qemu_ld32u(cpu_fregs[fr ], addr, ctx->memidx); |
1098 | 11bb09f1 | aurel32 | tcg_gen_addi_i32(addr, addr, 4);
|
1099 | 11bb09f1 | aurel32 | tcg_gen_qemu_ld32u(cpu_fregs[fr+1], addr, ctx->memidx);
|
1100 | cc4ba6a9 | aurel32 | } else {
|
1101 | 66ba317c | aurel32 | tcg_gen_qemu_ld32u(cpu_fregs[FREG(B11_8)], addr, ctx->memidx); |
1102 | cc4ba6a9 | aurel32 | } |
1103 | cc4ba6a9 | aurel32 | tcg_temp_free(addr); |
1104 | eda9b09b | bellard | } |
1105 | eda9b09b | bellard | return;
|
1106 | e67888a7 | ths | case 0xf007: /* fmov {F,D,X}Rn,@(R0,Rn) - FPSCR: Nothing */ |
1107 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1108 | cc4ba6a9 | aurel32 | { |
1109 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1110 | cc4ba6a9 | aurel32 | tcg_gen_add_i32(addr, REG(B11_8), REG(0));
|
1111 | cc4ba6a9 | aurel32 | if (ctx->fpscr & FPSCR_SZ) {
|
1112 | 11bb09f1 | aurel32 | int fr = XREG(B7_4);
|
1113 | 11bb09f1 | aurel32 | tcg_gen_qemu_ld32u(cpu_fregs[fr ], addr, ctx->memidx); |
1114 | 11bb09f1 | aurel32 | tcg_gen_addi_i32(addr, addr, 4);
|
1115 | 11bb09f1 | aurel32 | tcg_gen_qemu_ld32u(cpu_fregs[fr+1], addr, ctx->memidx);
|
1116 | cc4ba6a9 | aurel32 | } else {
|
1117 | 66ba317c | aurel32 | tcg_gen_qemu_st32(cpu_fregs[FREG(B7_4)], addr, ctx->memidx); |
1118 | cc4ba6a9 | aurel32 | } |
1119 | cc4ba6a9 | aurel32 | tcg_temp_free(addr); |
1120 | eda9b09b | bellard | } |
1121 | eda9b09b | bellard | return;
|
1122 | e67888a7 | ths | case 0xf000: /* fadd Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */ |
1123 | e67888a7 | ths | case 0xf001: /* fsub Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */ |
1124 | e67888a7 | ths | case 0xf002: /* fmul Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */ |
1125 | e67888a7 | ths | case 0xf003: /* fdiv Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */ |
1126 | e67888a7 | ths | case 0xf004: /* fcmp/eq Rm,Rn - FPSCR: R[PR,Enable.V]/W[Cause,Flag] */ |
1127 | e67888a7 | ths | case 0xf005: /* fcmp/gt Rm,Rn - FPSCR: R[PR,Enable.V]/W[Cause,Flag] */ |
1128 | cc4ba6a9 | aurel32 | { |
1129 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1130 | cc4ba6a9 | aurel32 | if (ctx->fpscr & FPSCR_PR) {
|
1131 | a7812ae4 | pbrook | TCGv_i64 fp0, fp1; |
1132 | a7812ae4 | pbrook | |
1133 | cc4ba6a9 | aurel32 | if (ctx->opcode & 0x0110) |
1134 | cc4ba6a9 | aurel32 | break; /* illegal instruction */ |
1135 | a7812ae4 | pbrook | fp0 = tcg_temp_new_i64(); |
1136 | a7812ae4 | pbrook | fp1 = tcg_temp_new_i64(); |
1137 | cc4ba6a9 | aurel32 | gen_load_fpr64(fp0, DREG(B11_8)); |
1138 | cc4ba6a9 | aurel32 | gen_load_fpr64(fp1, DREG(B7_4)); |
1139 | a7812ae4 | pbrook | switch (ctx->opcode & 0xf00f) { |
1140 | a7812ae4 | pbrook | case 0xf000: /* fadd Rm,Rn */ |
1141 | a7812ae4 | pbrook | gen_helper_fadd_DT(fp0, fp0, fp1); |
1142 | a7812ae4 | pbrook | break;
|
1143 | a7812ae4 | pbrook | case 0xf001: /* fsub Rm,Rn */ |
1144 | a7812ae4 | pbrook | gen_helper_fsub_DT(fp0, fp0, fp1); |
1145 | a7812ae4 | pbrook | break;
|
1146 | a7812ae4 | pbrook | case 0xf002: /* fmul Rm,Rn */ |
1147 | a7812ae4 | pbrook | gen_helper_fmul_DT(fp0, fp0, fp1); |
1148 | a7812ae4 | pbrook | break;
|
1149 | a7812ae4 | pbrook | case 0xf003: /* fdiv Rm,Rn */ |
1150 | a7812ae4 | pbrook | gen_helper_fdiv_DT(fp0, fp0, fp1); |
1151 | a7812ae4 | pbrook | break;
|
1152 | a7812ae4 | pbrook | case 0xf004: /* fcmp/eq Rm,Rn */ |
1153 | a7812ae4 | pbrook | gen_helper_fcmp_eq_DT(fp0, fp1); |
1154 | a7812ae4 | pbrook | return;
|
1155 | a7812ae4 | pbrook | case 0xf005: /* fcmp/gt Rm,Rn */ |
1156 | a7812ae4 | pbrook | gen_helper_fcmp_gt_DT(fp0, fp1); |
1157 | a7812ae4 | pbrook | return;
|
1158 | a7812ae4 | pbrook | } |
1159 | a7812ae4 | pbrook | gen_store_fpr64(fp0, DREG(B11_8)); |
1160 | a7812ae4 | pbrook | tcg_temp_free_i64(fp0); |
1161 | a7812ae4 | pbrook | tcg_temp_free_i64(fp1); |
1162 | a7812ae4 | pbrook | } else {
|
1163 | a7812ae4 | pbrook | switch (ctx->opcode & 0xf00f) { |
1164 | a7812ae4 | pbrook | case 0xf000: /* fadd Rm,Rn */ |
1165 | 66ba317c | aurel32 | gen_helper_fadd_FT(cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B7_4)]); |
1166 | a7812ae4 | pbrook | break;
|
1167 | a7812ae4 | pbrook | case 0xf001: /* fsub Rm,Rn */ |
1168 | 66ba317c | aurel32 | gen_helper_fsub_FT(cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B7_4)]); |
1169 | a7812ae4 | pbrook | break;
|
1170 | a7812ae4 | pbrook | case 0xf002: /* fmul Rm,Rn */ |
1171 | 66ba317c | aurel32 | gen_helper_fmul_FT(cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B7_4)]); |
1172 | a7812ae4 | pbrook | break;
|
1173 | a7812ae4 | pbrook | case 0xf003: /* fdiv Rm,Rn */ |
1174 | 66ba317c | aurel32 | gen_helper_fdiv_FT(cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B7_4)]); |
1175 | a7812ae4 | pbrook | break;
|
1176 | a7812ae4 | pbrook | case 0xf004: /* fcmp/eq Rm,Rn */ |
1177 | 66ba317c | aurel32 | gen_helper_fcmp_eq_FT(cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B7_4)]); |
1178 | a7812ae4 | pbrook | return;
|
1179 | a7812ae4 | pbrook | case 0xf005: /* fcmp/gt Rm,Rn */ |
1180 | 66ba317c | aurel32 | gen_helper_fcmp_gt_FT(cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B7_4)]); |
1181 | a7812ae4 | pbrook | return;
|
1182 | a7812ae4 | pbrook | } |
1183 | cc4ba6a9 | aurel32 | } |
1184 | ea6cf6be | ths | } |
1185 | ea6cf6be | ths | return;
|
1186 | 5b7141a1 | aurel32 | case 0xf00e: /* fmac FR0,RM,Rn */ |
1187 | 5b7141a1 | aurel32 | { |
1188 | 5b7141a1 | aurel32 | CHECK_FPU_ENABLED |
1189 | 5b7141a1 | aurel32 | if (ctx->fpscr & FPSCR_PR) {
|
1190 | 5b7141a1 | aurel32 | break; /* illegal instruction */ |
1191 | 5b7141a1 | aurel32 | } else {
|
1192 | 5b7141a1 | aurel32 | gen_helper_fmac_FT(cpu_fregs[FREG(B11_8)], |
1193 | 5b7141a1 | aurel32 | cpu_fregs[FREG(0)], cpu_fregs[FREG(B7_4)], cpu_fregs[FREG(B11_8)]);
|
1194 | 5b7141a1 | aurel32 | return;
|
1195 | 5b7141a1 | aurel32 | } |
1196 | 5b7141a1 | aurel32 | } |
1197 | fdf9b3e8 | bellard | } |
1198 | fdf9b3e8 | bellard | |
1199 | fdf9b3e8 | bellard | switch (ctx->opcode & 0xff00) { |
1200 | fdf9b3e8 | bellard | case 0xc900: /* and #imm,R0 */ |
1201 | 7efbe241 | aurel32 | tcg_gen_andi_i32(REG(0), REG(0), B7_0); |
1202 | fdf9b3e8 | bellard | return;
|
1203 | 24988dc2 | aurel32 | case 0xcd00: /* and.b #imm,@(R0,GBR) */ |
1204 | c55497ec | aurel32 | { |
1205 | c55497ec | aurel32 | TCGv addr, val; |
1206 | a7812ae4 | pbrook | addr = tcg_temp_new(); |
1207 | c55497ec | aurel32 | tcg_gen_add_i32(addr, REG(0), cpu_gbr);
|
1208 | a7812ae4 | pbrook | val = tcg_temp_new(); |
1209 | c55497ec | aurel32 | tcg_gen_qemu_ld8u(val, addr, ctx->memidx); |
1210 | c55497ec | aurel32 | tcg_gen_andi_i32(val, val, B7_0); |
1211 | c55497ec | aurel32 | tcg_gen_qemu_st8(val, addr, ctx->memidx); |
1212 | c55497ec | aurel32 | tcg_temp_free(val); |
1213 | c55497ec | aurel32 | tcg_temp_free(addr); |
1214 | c55497ec | aurel32 | } |
1215 | fdf9b3e8 | bellard | return;
|
1216 | fdf9b3e8 | bellard | case 0x8b00: /* bf label */ |
1217 | fdf9b3e8 | bellard | CHECK_NOT_DELAY_SLOT |
1218 | fdf9b3e8 | bellard | gen_conditional_jump(ctx, ctx->pc + 2,
|
1219 | fdf9b3e8 | bellard | ctx->pc + 4 + B7_0s * 2); |
1220 | 823029f9 | ths | ctx->bstate = BS_BRANCH; |
1221 | fdf9b3e8 | bellard | return;
|
1222 | fdf9b3e8 | bellard | case 0x8f00: /* bf/s label */ |
1223 | fdf9b3e8 | bellard | CHECK_NOT_DELAY_SLOT |
1224 | 1000822b | aurel32 | gen_branch_slot(ctx->delayed_pc = ctx->pc + 4 + B7_0s * 2, 0); |
1225 | fdf9b3e8 | bellard | ctx->flags |= DELAY_SLOT_CONDITIONAL; |
1226 | fdf9b3e8 | bellard | return;
|
1227 | fdf9b3e8 | bellard | case 0x8900: /* bt label */ |
1228 | fdf9b3e8 | bellard | CHECK_NOT_DELAY_SLOT |
1229 | fdf9b3e8 | bellard | gen_conditional_jump(ctx, ctx->pc + 4 + B7_0s * 2, |
1230 | fdf9b3e8 | bellard | ctx->pc + 2);
|
1231 | 823029f9 | ths | ctx->bstate = BS_BRANCH; |
1232 | fdf9b3e8 | bellard | return;
|
1233 | fdf9b3e8 | bellard | case 0x8d00: /* bt/s label */ |
1234 | fdf9b3e8 | bellard | CHECK_NOT_DELAY_SLOT |
1235 | 1000822b | aurel32 | gen_branch_slot(ctx->delayed_pc = ctx->pc + 4 + B7_0s * 2, 1); |
1236 | fdf9b3e8 | bellard | ctx->flags |= DELAY_SLOT_CONDITIONAL; |
1237 | fdf9b3e8 | bellard | return;
|
1238 | fdf9b3e8 | bellard | case 0x8800: /* cmp/eq #imm,R0 */ |
1239 | 7efbe241 | aurel32 | gen_cmp_imm(TCG_COND_EQ, REG(0), B7_0s);
|
1240 | fdf9b3e8 | bellard | return;
|
1241 | fdf9b3e8 | bellard | case 0xc400: /* mov.b @(disp,GBR),R0 */ |
1242 | c55497ec | aurel32 | { |
1243 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1244 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, cpu_gbr, B7_0); |
1245 | c55497ec | aurel32 | tcg_gen_qemu_ld8s(REG(0), addr, ctx->memidx);
|
1246 | c55497ec | aurel32 | tcg_temp_free(addr); |
1247 | c55497ec | aurel32 | } |
1248 | fdf9b3e8 | bellard | return;
|
1249 | fdf9b3e8 | bellard | case 0xc500: /* mov.w @(disp,GBR),R0 */ |
1250 | c55497ec | aurel32 | { |
1251 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1252 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, cpu_gbr, B7_0 * 2);
|
1253 | c55497ec | aurel32 | tcg_gen_qemu_ld16s(REG(0), addr, ctx->memidx);
|
1254 | c55497ec | aurel32 | tcg_temp_free(addr); |
1255 | c55497ec | aurel32 | } |
1256 | fdf9b3e8 | bellard | return;
|
1257 | fdf9b3e8 | bellard | case 0xc600: /* mov.l @(disp,GBR),R0 */ |
1258 | c55497ec | aurel32 | { |
1259 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1260 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, cpu_gbr, B7_0 * 4);
|
1261 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(REG(0), addr, ctx->memidx);
|
1262 | c55497ec | aurel32 | tcg_temp_free(addr); |
1263 | c55497ec | aurel32 | } |
1264 | fdf9b3e8 | bellard | return;
|
1265 | fdf9b3e8 | bellard | case 0xc000: /* mov.b R0,@(disp,GBR) */ |
1266 | c55497ec | aurel32 | { |
1267 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1268 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, cpu_gbr, B7_0); |
1269 | c55497ec | aurel32 | tcg_gen_qemu_st8(REG(0), addr, ctx->memidx);
|
1270 | c55497ec | aurel32 | tcg_temp_free(addr); |
1271 | c55497ec | aurel32 | } |
1272 | fdf9b3e8 | bellard | return;
|
1273 | fdf9b3e8 | bellard | case 0xc100: /* mov.w R0,@(disp,GBR) */ |
1274 | c55497ec | aurel32 | { |
1275 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1276 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, cpu_gbr, B7_0 * 2);
|
1277 | c55497ec | aurel32 | tcg_gen_qemu_st16(REG(0), addr, ctx->memidx);
|
1278 | c55497ec | aurel32 | tcg_temp_free(addr); |
1279 | c55497ec | aurel32 | } |
1280 | fdf9b3e8 | bellard | return;
|
1281 | fdf9b3e8 | bellard | case 0xc200: /* mov.l R0,@(disp,GBR) */ |
1282 | c55497ec | aurel32 | { |
1283 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1284 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, cpu_gbr, B7_0 * 4);
|
1285 | c55497ec | aurel32 | tcg_gen_qemu_st32(REG(0), addr, ctx->memidx);
|
1286 | c55497ec | aurel32 | tcg_temp_free(addr); |
1287 | c55497ec | aurel32 | } |
1288 | fdf9b3e8 | bellard | return;
|
1289 | fdf9b3e8 | bellard | case 0x8000: /* mov.b R0,@(disp,Rn) */ |
1290 | c55497ec | aurel32 | { |
1291 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1292 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, REG(B7_4), B3_0); |
1293 | c55497ec | aurel32 | tcg_gen_qemu_st8(REG(0), addr, ctx->memidx);
|
1294 | c55497ec | aurel32 | tcg_temp_free(addr); |
1295 | c55497ec | aurel32 | } |
1296 | fdf9b3e8 | bellard | return;
|
1297 | fdf9b3e8 | bellard | case 0x8100: /* mov.w R0,@(disp,Rn) */ |
1298 | c55497ec | aurel32 | { |
1299 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1300 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, REG(B7_4), B3_0 * 2);
|
1301 | c55497ec | aurel32 | tcg_gen_qemu_st16(REG(0), addr, ctx->memidx);
|
1302 | c55497ec | aurel32 | tcg_temp_free(addr); |
1303 | c55497ec | aurel32 | } |
1304 | fdf9b3e8 | bellard | return;
|
1305 | fdf9b3e8 | bellard | case 0x8400: /* mov.b @(disp,Rn),R0 */ |
1306 | c55497ec | aurel32 | { |
1307 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1308 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, REG(B7_4), B3_0); |
1309 | c55497ec | aurel32 | tcg_gen_qemu_ld8s(REG(0), addr, ctx->memidx);
|
1310 | c55497ec | aurel32 | tcg_temp_free(addr); |
1311 | c55497ec | aurel32 | } |
1312 | fdf9b3e8 | bellard | return;
|
1313 | fdf9b3e8 | bellard | case 0x8500: /* mov.w @(disp,Rn),R0 */ |
1314 | c55497ec | aurel32 | { |
1315 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1316 | c55497ec | aurel32 | tcg_gen_addi_i32(addr, REG(B7_4), B3_0 * 2);
|
1317 | c55497ec | aurel32 | tcg_gen_qemu_ld16s(REG(0), addr, ctx->memidx);
|
1318 | c55497ec | aurel32 | tcg_temp_free(addr); |
1319 | c55497ec | aurel32 | } |
1320 | fdf9b3e8 | bellard | return;
|
1321 | fdf9b3e8 | bellard | case 0xc700: /* mova @(disp,PC),R0 */ |
1322 | 7efbe241 | aurel32 | tcg_gen_movi_i32(REG(0), ((ctx->pc & 0xfffffffc) + 4 + B7_0 * 4) & ~3); |
1323 | fdf9b3e8 | bellard | return;
|
1324 | fdf9b3e8 | bellard | case 0xcb00: /* or #imm,R0 */ |
1325 | 7efbe241 | aurel32 | tcg_gen_ori_i32(REG(0), REG(0), B7_0); |
1326 | fdf9b3e8 | bellard | return;
|
1327 | 24988dc2 | aurel32 | case 0xcf00: /* or.b #imm,@(R0,GBR) */ |
1328 | c55497ec | aurel32 | { |
1329 | c55497ec | aurel32 | TCGv addr, val; |
1330 | a7812ae4 | pbrook | addr = tcg_temp_new(); |
1331 | c55497ec | aurel32 | tcg_gen_add_i32(addr, REG(0), cpu_gbr);
|
1332 | a7812ae4 | pbrook | val = tcg_temp_new(); |
1333 | c55497ec | aurel32 | tcg_gen_qemu_ld8u(val, addr, ctx->memidx); |
1334 | c55497ec | aurel32 | tcg_gen_ori_i32(val, val, B7_0); |
1335 | c55497ec | aurel32 | tcg_gen_qemu_st8(val, addr, ctx->memidx); |
1336 | c55497ec | aurel32 | tcg_temp_free(val); |
1337 | c55497ec | aurel32 | tcg_temp_free(addr); |
1338 | c55497ec | aurel32 | } |
1339 | fdf9b3e8 | bellard | return;
|
1340 | fdf9b3e8 | bellard | case 0xc300: /* trapa #imm */ |
1341 | c55497ec | aurel32 | { |
1342 | c55497ec | aurel32 | TCGv imm; |
1343 | c55497ec | aurel32 | CHECK_NOT_DELAY_SLOT |
1344 | c55497ec | aurel32 | tcg_gen_movi_i32(cpu_pc, ctx->pc); |
1345 | c55497ec | aurel32 | imm = tcg_const_i32(B7_0); |
1346 | a7812ae4 | pbrook | gen_helper_trapa(imm); |
1347 | c55497ec | aurel32 | tcg_temp_free(imm); |
1348 | c55497ec | aurel32 | ctx->bstate = BS_BRANCH; |
1349 | c55497ec | aurel32 | } |
1350 | fdf9b3e8 | bellard | return;
|
1351 | fdf9b3e8 | bellard | case 0xc800: /* tst #imm,R0 */ |
1352 | c55497ec | aurel32 | { |
1353 | a7812ae4 | pbrook | TCGv val = tcg_temp_new(); |
1354 | c55497ec | aurel32 | tcg_gen_andi_i32(val, REG(0), B7_0);
|
1355 | c55497ec | aurel32 | gen_cmp_imm(TCG_COND_EQ, val, 0);
|
1356 | c55497ec | aurel32 | tcg_temp_free(val); |
1357 | c55497ec | aurel32 | } |
1358 | fdf9b3e8 | bellard | return;
|
1359 | 24988dc2 | aurel32 | case 0xcc00: /* tst.b #imm,@(R0,GBR) */ |
1360 | c55497ec | aurel32 | { |
1361 | a7812ae4 | pbrook | TCGv val = tcg_temp_new(); |
1362 | c55497ec | aurel32 | tcg_gen_add_i32(val, REG(0), cpu_gbr);
|
1363 | c55497ec | aurel32 | tcg_gen_qemu_ld8u(val, val, ctx->memidx); |
1364 | c55497ec | aurel32 | tcg_gen_andi_i32(val, val, B7_0); |
1365 | c55497ec | aurel32 | gen_cmp_imm(TCG_COND_EQ, val, 0);
|
1366 | c55497ec | aurel32 | tcg_temp_free(val); |
1367 | c55497ec | aurel32 | } |
1368 | fdf9b3e8 | bellard | return;
|
1369 | fdf9b3e8 | bellard | case 0xca00: /* xor #imm,R0 */ |
1370 | 7efbe241 | aurel32 | tcg_gen_xori_i32(REG(0), REG(0), B7_0); |
1371 | fdf9b3e8 | bellard | return;
|
1372 | 24988dc2 | aurel32 | case 0xce00: /* xor.b #imm,@(R0,GBR) */ |
1373 | c55497ec | aurel32 | { |
1374 | c55497ec | aurel32 | TCGv addr, val; |
1375 | a7812ae4 | pbrook | addr = tcg_temp_new(); |
1376 | c55497ec | aurel32 | tcg_gen_add_i32(addr, REG(0), cpu_gbr);
|
1377 | a7812ae4 | pbrook | val = tcg_temp_new(); |
1378 | c55497ec | aurel32 | tcg_gen_qemu_ld8u(val, addr, ctx->memidx); |
1379 | c55497ec | aurel32 | tcg_gen_xori_i32(val, val, B7_0); |
1380 | c55497ec | aurel32 | tcg_gen_qemu_st8(val, addr, ctx->memidx); |
1381 | c55497ec | aurel32 | tcg_temp_free(val); |
1382 | c55497ec | aurel32 | tcg_temp_free(addr); |
1383 | c55497ec | aurel32 | } |
1384 | fdf9b3e8 | bellard | return;
|
1385 | fdf9b3e8 | bellard | } |
1386 | fdf9b3e8 | bellard | |
1387 | fdf9b3e8 | bellard | switch (ctx->opcode & 0xf08f) { |
1388 | fdf9b3e8 | bellard | case 0x408e: /* ldc Rm,Rn_BANK */ |
1389 | fe25591e | aurel32 | CHECK_PRIVILEGED |
1390 | 7efbe241 | aurel32 | tcg_gen_mov_i32(ALTREG(B6_4), REG(B11_8)); |
1391 | fdf9b3e8 | bellard | return;
|
1392 | fdf9b3e8 | bellard | case 0x4087: /* ldc.l @Rm+,Rn_BANK */ |
1393 | fe25591e | aurel32 | CHECK_PRIVILEGED |
1394 | 7efbe241 | aurel32 | tcg_gen_qemu_ld32s(ALTREG(B6_4), REG(B11_8), ctx->memidx); |
1395 | 7efbe241 | aurel32 | tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4);
|
1396 | fdf9b3e8 | bellard | return;
|
1397 | fdf9b3e8 | bellard | case 0x0082: /* stc Rm_BANK,Rn */ |
1398 | fe25591e | aurel32 | CHECK_PRIVILEGED |
1399 | 7efbe241 | aurel32 | tcg_gen_mov_i32(REG(B11_8), ALTREG(B6_4)); |
1400 | fdf9b3e8 | bellard | return;
|
1401 | fdf9b3e8 | bellard | case 0x4083: /* stc.l Rm_BANK,@-Rn */ |
1402 | fe25591e | aurel32 | CHECK_PRIVILEGED |
1403 | c55497ec | aurel32 | { |
1404 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1405 | c55497ec | aurel32 | tcg_gen_subi_i32(addr, REG(B11_8), 4);
|
1406 | c55497ec | aurel32 | tcg_gen_qemu_st32(ALTREG(B6_4), addr, ctx->memidx); |
1407 | c55497ec | aurel32 | tcg_temp_free(addr); |
1408 | c55497ec | aurel32 | tcg_gen_subi_i32(REG(B11_8), REG(B11_8), 4);
|
1409 | c55497ec | aurel32 | } |
1410 | fdf9b3e8 | bellard | return;
|
1411 | fdf9b3e8 | bellard | } |
1412 | fdf9b3e8 | bellard | |
1413 | fdf9b3e8 | bellard | switch (ctx->opcode & 0xf0ff) { |
1414 | fdf9b3e8 | bellard | case 0x0023: /* braf Rn */ |
1415 | 7efbe241 | aurel32 | CHECK_NOT_DELAY_SLOT |
1416 | 7efbe241 | aurel32 | tcg_gen_addi_i32(cpu_delayed_pc, REG(B11_8), ctx->pc + 4);
|
1417 | fdf9b3e8 | bellard | ctx->flags |= DELAY_SLOT; |
1418 | fdf9b3e8 | bellard | ctx->delayed_pc = (uint32_t) - 1;
|
1419 | fdf9b3e8 | bellard | return;
|
1420 | fdf9b3e8 | bellard | case 0x0003: /* bsrf Rn */ |
1421 | 7efbe241 | aurel32 | CHECK_NOT_DELAY_SLOT |
1422 | 1000822b | aurel32 | tcg_gen_movi_i32(cpu_pr, ctx->pc + 4);
|
1423 | 7efbe241 | aurel32 | tcg_gen_add_i32(cpu_delayed_pc, REG(B11_8), cpu_pr); |
1424 | fdf9b3e8 | bellard | ctx->flags |= DELAY_SLOT; |
1425 | fdf9b3e8 | bellard | ctx->delayed_pc = (uint32_t) - 1;
|
1426 | fdf9b3e8 | bellard | return;
|
1427 | fdf9b3e8 | bellard | case 0x4015: /* cmp/pl Rn */ |
1428 | 7efbe241 | aurel32 | gen_cmp_imm(TCG_COND_GT, REG(B11_8), 0);
|
1429 | fdf9b3e8 | bellard | return;
|
1430 | fdf9b3e8 | bellard | case 0x4011: /* cmp/pz Rn */ |
1431 | 7efbe241 | aurel32 | gen_cmp_imm(TCG_COND_GE, REG(B11_8), 0);
|
1432 | fdf9b3e8 | bellard | return;
|
1433 | fdf9b3e8 | bellard | case 0x4010: /* dt Rn */ |
1434 | 7efbe241 | aurel32 | tcg_gen_subi_i32(REG(B11_8), REG(B11_8), 1);
|
1435 | 7efbe241 | aurel32 | gen_cmp_imm(TCG_COND_EQ, REG(B11_8), 0);
|
1436 | fdf9b3e8 | bellard | return;
|
1437 | fdf9b3e8 | bellard | case 0x402b: /* jmp @Rn */ |
1438 | 7efbe241 | aurel32 | CHECK_NOT_DELAY_SLOT |
1439 | 7efbe241 | aurel32 | tcg_gen_mov_i32(cpu_delayed_pc, REG(B11_8)); |
1440 | fdf9b3e8 | bellard | ctx->flags |= DELAY_SLOT; |
1441 | fdf9b3e8 | bellard | ctx->delayed_pc = (uint32_t) - 1;
|
1442 | fdf9b3e8 | bellard | return;
|
1443 | fdf9b3e8 | bellard | case 0x400b: /* jsr @Rn */ |
1444 | 7efbe241 | aurel32 | CHECK_NOT_DELAY_SLOT |
1445 | 1000822b | aurel32 | tcg_gen_movi_i32(cpu_pr, ctx->pc + 4);
|
1446 | 7efbe241 | aurel32 | tcg_gen_mov_i32(cpu_delayed_pc, REG(B11_8)); |
1447 | fdf9b3e8 | bellard | ctx->flags |= DELAY_SLOT; |
1448 | fdf9b3e8 | bellard | ctx->delayed_pc = (uint32_t) - 1;
|
1449 | fdf9b3e8 | bellard | return;
|
1450 | fe25591e | aurel32 | case 0x400e: /* ldc Rm,SR */ |
1451 | fe25591e | aurel32 | CHECK_PRIVILEGED |
1452 | 7efbe241 | aurel32 | tcg_gen_andi_i32(cpu_sr, REG(B11_8), 0x700083f3);
|
1453 | 390af821 | aurel32 | ctx->bstate = BS_STOP; |
1454 | 390af821 | aurel32 | return;
|
1455 | fe25591e | aurel32 | case 0x4007: /* ldc.l @Rm+,SR */ |
1456 | fe25591e | aurel32 | CHECK_PRIVILEGED |
1457 | c55497ec | aurel32 | { |
1458 | a7812ae4 | pbrook | TCGv val = tcg_temp_new(); |
1459 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(val, REG(B11_8), ctx->memidx); |
1460 | c55497ec | aurel32 | tcg_gen_andi_i32(cpu_sr, val, 0x700083f3);
|
1461 | c55497ec | aurel32 | tcg_temp_free(val); |
1462 | c55497ec | aurel32 | tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4);
|
1463 | c55497ec | aurel32 | ctx->bstate = BS_STOP; |
1464 | c55497ec | aurel32 | } |
1465 | 390af821 | aurel32 | return;
|
1466 | fe25591e | aurel32 | case 0x0002: /* stc SR,Rn */ |
1467 | fe25591e | aurel32 | CHECK_PRIVILEGED |
1468 | 7efbe241 | aurel32 | tcg_gen_mov_i32(REG(B11_8), cpu_sr); |
1469 | 390af821 | aurel32 | return;
|
1470 | fe25591e | aurel32 | case 0x4003: /* stc SR,@-Rn */ |
1471 | fe25591e | aurel32 | CHECK_PRIVILEGED |
1472 | c55497ec | aurel32 | { |
1473 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1474 | c55497ec | aurel32 | tcg_gen_subi_i32(addr, REG(B11_8), 4);
|
1475 | c55497ec | aurel32 | tcg_gen_qemu_st32(cpu_sr, addr, ctx->memidx); |
1476 | c55497ec | aurel32 | tcg_temp_free(addr); |
1477 | c55497ec | aurel32 | tcg_gen_subi_i32(REG(B11_8), REG(B11_8), 4);
|
1478 | c55497ec | aurel32 | } |
1479 | 390af821 | aurel32 | return;
|
1480 | fe25591e | aurel32 | #define LDST(reg,ldnum,ldpnum,stnum,stpnum,prechk) \
|
1481 | fdf9b3e8 | bellard | case ldnum: \
|
1482 | fe25591e | aurel32 | prechk \ |
1483 | 7efbe241 | aurel32 | tcg_gen_mov_i32 (cpu_##reg, REG(B11_8)); \ |
1484 | fdf9b3e8 | bellard | return; \
|
1485 | fdf9b3e8 | bellard | case ldpnum: \
|
1486 | fe25591e | aurel32 | prechk \ |
1487 | 7efbe241 | aurel32 | tcg_gen_qemu_ld32s (cpu_##reg, REG(B11_8), ctx->memidx); \ |
1488 | 7efbe241 | aurel32 | tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4); \
|
1489 | fdf9b3e8 | bellard | return; \
|
1490 | fdf9b3e8 | bellard | case stnum: \
|
1491 | fe25591e | aurel32 | prechk \ |
1492 | 7efbe241 | aurel32 | tcg_gen_mov_i32 (REG(B11_8), cpu_##reg); \ |
1493 | fdf9b3e8 | bellard | return; \
|
1494 | fdf9b3e8 | bellard | case stpnum: \
|
1495 | fe25591e | aurel32 | prechk \ |
1496 | c55497ec | aurel32 | { \ |
1497 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); \ |
1498 | c55497ec | aurel32 | tcg_gen_subi_i32(addr, REG(B11_8), 4); \
|
1499 | c55497ec | aurel32 | tcg_gen_qemu_st32 (cpu_##reg, addr, ctx->memidx); \ |
1500 | c55497ec | aurel32 | tcg_temp_free(addr); \ |
1501 | c55497ec | aurel32 | tcg_gen_subi_i32(REG(B11_8), REG(B11_8), 4); \
|
1502 | 86e0abc7 | aurel32 | } \ |
1503 | fdf9b3e8 | bellard | return;
|
1504 | fe25591e | aurel32 | LDST(gbr, 0x401e, 0x4017, 0x0012, 0x4013, {}) |
1505 | fe25591e | aurel32 | LDST(vbr, 0x402e, 0x4027, 0x0022, 0x4023, CHECK_PRIVILEGED) |
1506 | fe25591e | aurel32 | LDST(ssr, 0x403e, 0x4037, 0x0032, 0x4033, CHECK_PRIVILEGED) |
1507 | fe25591e | aurel32 | LDST(spc, 0x404e, 0x4047, 0x0042, 0x4043, CHECK_PRIVILEGED) |
1508 | fe25591e | aurel32 | LDST(dbr, 0x40fa, 0x40f6, 0x00fa, 0x40f2, CHECK_PRIVILEGED) |
1509 | fe25591e | aurel32 | LDST(mach, 0x400a, 0x4006, 0x000a, 0x4002, {}) |
1510 | fe25591e | aurel32 | LDST(macl, 0x401a, 0x4016, 0x001a, 0x4012, {}) |
1511 | fe25591e | aurel32 | LDST(pr, 0x402a, 0x4026, 0x002a, 0x4022, {}) |
1512 | d8299bcc | aurel32 | LDST(fpul, 0x405a, 0x4056, 0x005a, 0x4052, {CHECK_FPU_ENABLED}) |
1513 | 390af821 | aurel32 | case 0x406a: /* lds Rm,FPSCR */ |
1514 | d8299bcc | aurel32 | CHECK_FPU_ENABLED |
1515 | a7812ae4 | pbrook | gen_helper_ld_fpscr(REG(B11_8)); |
1516 | 390af821 | aurel32 | ctx->bstate = BS_STOP; |
1517 | 390af821 | aurel32 | return;
|
1518 | 390af821 | aurel32 | case 0x4066: /* lds.l @Rm+,FPSCR */ |
1519 | d8299bcc | aurel32 | CHECK_FPU_ENABLED |
1520 | c55497ec | aurel32 | { |
1521 | a7812ae4 | pbrook | TCGv addr = tcg_temp_new(); |
1522 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(addr, REG(B11_8), ctx->memidx); |
1523 | c55497ec | aurel32 | tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4);
|
1524 | a7812ae4 | pbrook | gen_helper_ld_fpscr(addr); |
1525 | c55497ec | aurel32 | tcg_temp_free(addr); |
1526 | c55497ec | aurel32 | ctx->bstate = BS_STOP; |
1527 | c55497ec | aurel32 | } |
1528 | 390af821 | aurel32 | return;
|
1529 | 390af821 | aurel32 | case 0x006a: /* sts FPSCR,Rn */ |
1530 | d8299bcc | aurel32 | CHECK_FPU_ENABLED |
1531 | c55497ec | aurel32 | tcg_gen_andi_i32(REG(B11_8), cpu_fpscr, 0x003fffff);
|
1532 | 390af821 | aurel32 | return;
|
1533 | 390af821 | aurel32 | case 0x4062: /* sts FPSCR,@-Rn */ |
1534 | d8299bcc | aurel32 | CHECK_FPU_ENABLED |
1535 | c55497ec | aurel32 | { |
1536 | c55497ec | aurel32 | TCGv addr, val; |
1537 | a7812ae4 | pbrook | val = tcg_temp_new(); |
1538 | c55497ec | aurel32 | tcg_gen_andi_i32(val, cpu_fpscr, 0x003fffff);
|
1539 | a7812ae4 | pbrook | addr = tcg_temp_new(); |
1540 | c55497ec | aurel32 | tcg_gen_subi_i32(addr, REG(B11_8), 4);
|
1541 | c55497ec | aurel32 | tcg_gen_qemu_st32(val, addr, ctx->memidx); |
1542 | c55497ec | aurel32 | tcg_temp_free(addr); |
1543 | c55497ec | aurel32 | tcg_temp_free(val); |
1544 | c55497ec | aurel32 | tcg_gen_subi_i32(REG(B11_8), REG(B11_8), 4);
|
1545 | c55497ec | aurel32 | } |
1546 | 390af821 | aurel32 | return;
|
1547 | fdf9b3e8 | bellard | case 0x00c3: /* movca.l R0,@Rm */ |
1548 | 7efbe241 | aurel32 | tcg_gen_qemu_st32(REG(0), REG(B11_8), ctx->memidx);
|
1549 | fdf9b3e8 | bellard | return;
|
1550 | 7526aa2d | aurel32 | case 0x40a9: |
1551 | 7526aa2d | aurel32 | /* MOVUA.L @Rm,R0 (Rm) -> R0
|
1552 | 7526aa2d | aurel32 | Load non-boundary-aligned data */
|
1553 | 7526aa2d | aurel32 | tcg_gen_qemu_ld32u(REG(0), REG(B11_8), ctx->memidx);
|
1554 | 7526aa2d | aurel32 | return;
|
1555 | 7526aa2d | aurel32 | case 0x40e9: |
1556 | 7526aa2d | aurel32 | /* MOVUA.L @Rm+,R0 (Rm) -> R0, Rm + 4 -> Rm
|
1557 | 7526aa2d | aurel32 | Load non-boundary-aligned data */
|
1558 | 7526aa2d | aurel32 | tcg_gen_qemu_ld32u(REG(0), REG(B11_8), ctx->memidx);
|
1559 | 7526aa2d | aurel32 | tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4);
|
1560 | 7526aa2d | aurel32 | return;
|
1561 | fdf9b3e8 | bellard | case 0x0029: /* movt Rn */ |
1562 | 7efbe241 | aurel32 | tcg_gen_andi_i32(REG(B11_8), cpu_sr, SR_T); |
1563 | fdf9b3e8 | bellard | return;
|
1564 | 66c7c806 | aurel32 | case 0x0073: |
1565 | 66c7c806 | aurel32 | /* MOVCO.L
|
1566 | 66c7c806 | aurel32 | LDST -> T
|
1567 | 66c7c806 | aurel32 | If (T == 1) R0 -> (Rn)
|
1568 | 66c7c806 | aurel32 | 0 -> LDST
|
1569 | 66c7c806 | aurel32 | */
|
1570 | 66c7c806 | aurel32 | if (ctx->features & SH_FEATURE_SH4A) {
|
1571 | 66c7c806 | aurel32 | int label = gen_new_label();
|
1572 | 66c7c806 | aurel32 | gen_clr_t(); |
1573 | 66c7c806 | aurel32 | tcg_gen_or_i32(cpu_sr, cpu_sr, cpu_ldst); |
1574 | 66c7c806 | aurel32 | tcg_gen_brcondi_i32(TCG_COND_EQ, cpu_ldst, 0, label);
|
1575 | 66c7c806 | aurel32 | tcg_gen_qemu_st32(REG(0), REG(B11_8), ctx->memidx);
|
1576 | 66c7c806 | aurel32 | gen_set_label(label); |
1577 | 66c7c806 | aurel32 | tcg_gen_movi_i32(cpu_ldst, 0);
|
1578 | 66c7c806 | aurel32 | return;
|
1579 | 66c7c806 | aurel32 | } else
|
1580 | 66c7c806 | aurel32 | break;
|
1581 | 66c7c806 | aurel32 | case 0x0063: |
1582 | 66c7c806 | aurel32 | /* MOVLI.L @Rm,R0
|
1583 | 66c7c806 | aurel32 | 1 -> LDST
|
1584 | 66c7c806 | aurel32 | (Rm) -> R0
|
1585 | 66c7c806 | aurel32 | When interrupt/exception
|
1586 | 66c7c806 | aurel32 | occurred 0 -> LDST
|
1587 | 66c7c806 | aurel32 | */
|
1588 | 66c7c806 | aurel32 | if (ctx->features & SH_FEATURE_SH4A) {
|
1589 | 66c7c806 | aurel32 | tcg_gen_movi_i32(cpu_ldst, 0);
|
1590 | 66c7c806 | aurel32 | tcg_gen_qemu_ld32s(REG(0), REG(B11_8), ctx->memidx);
|
1591 | 66c7c806 | aurel32 | tcg_gen_movi_i32(cpu_ldst, 1);
|
1592 | 66c7c806 | aurel32 | return;
|
1593 | 66c7c806 | aurel32 | } else
|
1594 | 66c7c806 | aurel32 | break;
|
1595 | fdf9b3e8 | bellard | case 0x0093: /* ocbi @Rn */ |
1596 | c55497ec | aurel32 | { |
1597 | a7812ae4 | pbrook | TCGv dummy = tcg_temp_new(); |
1598 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(dummy, REG(B11_8), ctx->memidx); |
1599 | c55497ec | aurel32 | tcg_temp_free(dummy); |
1600 | c55497ec | aurel32 | } |
1601 | fdf9b3e8 | bellard | return;
|
1602 | 24988dc2 | aurel32 | case 0x00a3: /* ocbp @Rn */ |
1603 | c55497ec | aurel32 | { |
1604 | a7812ae4 | pbrook | TCGv dummy = tcg_temp_new(); |
1605 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(dummy, REG(B11_8), ctx->memidx); |
1606 | c55497ec | aurel32 | tcg_temp_free(dummy); |
1607 | c55497ec | aurel32 | } |
1608 | fdf9b3e8 | bellard | return;
|
1609 | fdf9b3e8 | bellard | case 0x00b3: /* ocbwb @Rn */ |
1610 | c55497ec | aurel32 | { |
1611 | a7812ae4 | pbrook | TCGv dummy = tcg_temp_new(); |
1612 | c55497ec | aurel32 | tcg_gen_qemu_ld32s(dummy, REG(B11_8), ctx->memidx); |
1613 | c55497ec | aurel32 | tcg_temp_free(dummy); |
1614 | c55497ec | aurel32 | } |
1615 | fdf9b3e8 | bellard | return;
|
1616 | fdf9b3e8 | bellard | case 0x0083: /* pref @Rn */ |
1617 | fdf9b3e8 | bellard | return;
|
1618 | 71968fa6 | aurel32 | case 0x00d3: /* prefi @Rn */ |
1619 | 71968fa6 | aurel32 | if (ctx->features & SH_FEATURE_SH4A)
|
1620 | 71968fa6 | aurel32 | return;
|
1621 | 71968fa6 | aurel32 | else
|
1622 | 71968fa6 | aurel32 | break;
|
1623 | 71968fa6 | aurel32 | case 0x00e3: /* icbi @Rn */ |
1624 | 71968fa6 | aurel32 | if (ctx->features & SH_FEATURE_SH4A)
|
1625 | 71968fa6 | aurel32 | return;
|
1626 | 71968fa6 | aurel32 | else
|
1627 | 71968fa6 | aurel32 | break;
|
1628 | 71968fa6 | aurel32 | case 0x00ab: /* synco */ |
1629 | 71968fa6 | aurel32 | if (ctx->features & SH_FEATURE_SH4A)
|
1630 | 71968fa6 | aurel32 | return;
|
1631 | 71968fa6 | aurel32 | else
|
1632 | 71968fa6 | aurel32 | break;
|
1633 | fdf9b3e8 | bellard | case 0x4024: /* rotcl Rn */ |
1634 | c55497ec | aurel32 | { |
1635 | a7812ae4 | pbrook | TCGv tmp = tcg_temp_new(); |
1636 | c55497ec | aurel32 | tcg_gen_mov_i32(tmp, cpu_sr); |
1637 | c55497ec | aurel32 | gen_copy_bit_i32(cpu_sr, 0, REG(B11_8), 31); |
1638 | c55497ec | aurel32 | tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 1);
|
1639 | c55497ec | aurel32 | gen_copy_bit_i32(REG(B11_8), 0, tmp, 0); |
1640 | c55497ec | aurel32 | tcg_temp_free(tmp); |
1641 | c55497ec | aurel32 | } |
1642 | fdf9b3e8 | bellard | return;
|
1643 | fdf9b3e8 | bellard | case 0x4025: /* rotcr Rn */ |
1644 | c55497ec | aurel32 | { |
1645 | a7812ae4 | pbrook | TCGv tmp = tcg_temp_new(); |
1646 | c55497ec | aurel32 | tcg_gen_mov_i32(tmp, cpu_sr); |
1647 | c55497ec | aurel32 | gen_copy_bit_i32(cpu_sr, 0, REG(B11_8), 0); |
1648 | c55497ec | aurel32 | tcg_gen_shri_i32(REG(B11_8), REG(B11_8), 1);
|
1649 | c55497ec | aurel32 | gen_copy_bit_i32(REG(B11_8), 31, tmp, 0); |
1650 | c55497ec | aurel32 | tcg_temp_free(tmp); |
1651 | c55497ec | aurel32 | } |
1652 | fdf9b3e8 | bellard | return;
|
1653 | fdf9b3e8 | bellard | case 0x4004: /* rotl Rn */ |
1654 | 7efbe241 | aurel32 | gen_copy_bit_i32(cpu_sr, 0, REG(B11_8), 31); |
1655 | 7efbe241 | aurel32 | tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 1);
|
1656 | 7efbe241 | aurel32 | gen_copy_bit_i32(REG(B11_8), 0, cpu_sr, 0); |
1657 | fdf9b3e8 | bellard | return;
|
1658 | fdf9b3e8 | bellard | case 0x4005: /* rotr Rn */ |
1659 | 7efbe241 | aurel32 | gen_copy_bit_i32(cpu_sr, 0, REG(B11_8), 0); |
1660 | 7efbe241 | aurel32 | tcg_gen_shri_i32(REG(B11_8), REG(B11_8), 1);
|
1661 | 7efbe241 | aurel32 | gen_copy_bit_i32(REG(B11_8), 31, cpu_sr, 0); |
1662 | fdf9b3e8 | bellard | return;
|
1663 | fdf9b3e8 | bellard | case 0x4000: /* shll Rn */ |
1664 | fdf9b3e8 | bellard | case 0x4020: /* shal Rn */ |
1665 | 7efbe241 | aurel32 | gen_copy_bit_i32(cpu_sr, 0, REG(B11_8), 31); |
1666 | 7efbe241 | aurel32 | tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 1);
|
1667 | fdf9b3e8 | bellard | return;
|
1668 | fdf9b3e8 | bellard | case 0x4021: /* shar Rn */ |
1669 | 7efbe241 | aurel32 | gen_copy_bit_i32(cpu_sr, 0, REG(B11_8), 0); |
1670 | 7efbe241 | aurel32 | tcg_gen_sari_i32(REG(B11_8), REG(B11_8), 1);
|
1671 | fdf9b3e8 | bellard | return;
|
1672 | fdf9b3e8 | bellard | case 0x4001: /* shlr Rn */ |
1673 | 7efbe241 | aurel32 | gen_copy_bit_i32(cpu_sr, 0, REG(B11_8), 0); |
1674 | 7efbe241 | aurel32 | tcg_gen_shri_i32(REG(B11_8), REG(B11_8), 1);
|
1675 | fdf9b3e8 | bellard | return;
|
1676 | fdf9b3e8 | bellard | case 0x4008: /* shll2 Rn */ |
1677 | 7efbe241 | aurel32 | tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 2);
|
1678 | fdf9b3e8 | bellard | return;
|
1679 | fdf9b3e8 | bellard | case 0x4018: /* shll8 Rn */ |
1680 | 7efbe241 | aurel32 | tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 8);
|
1681 | fdf9b3e8 | bellard | return;
|
1682 | fdf9b3e8 | bellard | case 0x4028: /* shll16 Rn */ |
1683 | 7efbe241 | aurel32 | tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 16);
|
1684 | fdf9b3e8 | bellard | return;
|
1685 | fdf9b3e8 | bellard | case 0x4009: /* shlr2 Rn */ |
1686 | 7efbe241 | aurel32 | tcg_gen_shri_i32(REG(B11_8), REG(B11_8), 2);
|
1687 | fdf9b3e8 | bellard | return;
|
1688 | fdf9b3e8 | bellard | case 0x4019: /* shlr8 Rn */ |
1689 | 7efbe241 | aurel32 | tcg_gen_shri_i32(REG(B11_8), REG(B11_8), 8);
|
1690 | fdf9b3e8 | bellard | return;
|
1691 | fdf9b3e8 | bellard | case 0x4029: /* shlr16 Rn */ |
1692 | 7efbe241 | aurel32 | tcg_gen_shri_i32(REG(B11_8), REG(B11_8), 16);
|
1693 | fdf9b3e8 | bellard | return;
|
1694 | fdf9b3e8 | bellard | case 0x401b: /* tas.b @Rn */ |
1695 | c55497ec | aurel32 | { |
1696 | c55497ec | aurel32 | TCGv addr, val; |
1697 | df9247b2 | aurel32 | addr = tcg_temp_local_new(); |
1698 | c55497ec | aurel32 | tcg_gen_mov_i32(addr, REG(B11_8)); |
1699 | df9247b2 | aurel32 | val = tcg_temp_local_new(); |
1700 | c55497ec | aurel32 | tcg_gen_qemu_ld8u(val, addr, ctx->memidx); |
1701 | c55497ec | aurel32 | gen_cmp_imm(TCG_COND_EQ, val, 0);
|
1702 | c55497ec | aurel32 | tcg_gen_ori_i32(val, val, 0x80);
|
1703 | c55497ec | aurel32 | tcg_gen_qemu_st8(val, addr, ctx->memidx); |
1704 | c55497ec | aurel32 | tcg_temp_free(val); |
1705 | c55497ec | aurel32 | tcg_temp_free(addr); |
1706 | c55497ec | aurel32 | } |
1707 | fdf9b3e8 | bellard | return;
|
1708 | e67888a7 | ths | case 0xf00d: /* fsts FPUL,FRn - FPSCR: Nothing */ |
1709 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1710 | f6198371 | aurel32 | tcg_gen_mov_i32(cpu_fregs[FREG(B11_8)], cpu_fpul); |
1711 | eda9b09b | bellard | return;
|
1712 | e67888a7 | ths | case 0xf01d: /* flds FRm,FPUL - FPSCR: Nothing */ |
1713 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1714 | f6198371 | aurel32 | tcg_gen_mov_i32(cpu_fpul, cpu_fregs[FREG(B11_8)]); |
1715 | eda9b09b | bellard | return;
|
1716 | e67888a7 | ths | case 0xf02d: /* float FPUL,FRn/DRn - FPSCR: R[PR,Enable.I]/W[Cause,Flag] */ |
1717 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1718 | ea6cf6be | ths | if (ctx->fpscr & FPSCR_PR) {
|
1719 | a7812ae4 | pbrook | TCGv_i64 fp; |
1720 | ea6cf6be | ths | if (ctx->opcode & 0x0100) |
1721 | ea6cf6be | ths | break; /* illegal instruction */ |
1722 | a7812ae4 | pbrook | fp = tcg_temp_new_i64(); |
1723 | a7812ae4 | pbrook | gen_helper_float_DT(fp, cpu_fpul); |
1724 | cc4ba6a9 | aurel32 | gen_store_fpr64(fp, DREG(B11_8)); |
1725 | a7812ae4 | pbrook | tcg_temp_free_i64(fp); |
1726 | ea6cf6be | ths | } |
1727 | ea6cf6be | ths | else {
|
1728 | 66ba317c | aurel32 | gen_helper_float_FT(cpu_fregs[FREG(B11_8)], cpu_fpul); |
1729 | ea6cf6be | ths | } |
1730 | ea6cf6be | ths | return;
|
1731 | e67888a7 | ths | case 0xf03d: /* ftrc FRm/DRm,FPUL - FPSCR: R[PR,Enable.V]/W[Cause,Flag] */ |
1732 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1733 | ea6cf6be | ths | if (ctx->fpscr & FPSCR_PR) {
|
1734 | a7812ae4 | pbrook | TCGv_i64 fp; |
1735 | ea6cf6be | ths | if (ctx->opcode & 0x0100) |
1736 | ea6cf6be | ths | break; /* illegal instruction */ |
1737 | a7812ae4 | pbrook | fp = tcg_temp_new_i64(); |
1738 | cc4ba6a9 | aurel32 | gen_load_fpr64(fp, DREG(B11_8)); |
1739 | a7812ae4 | pbrook | gen_helper_ftrc_DT(cpu_fpul, fp); |
1740 | a7812ae4 | pbrook | tcg_temp_free_i64(fp); |
1741 | ea6cf6be | ths | } |
1742 | ea6cf6be | ths | else {
|
1743 | 66ba317c | aurel32 | gen_helper_ftrc_FT(cpu_fpul, cpu_fregs[FREG(B11_8)]); |
1744 | ea6cf6be | ths | } |
1745 | ea6cf6be | ths | return;
|
1746 | 24988dc2 | aurel32 | case 0xf04d: /* fneg FRn/DRn - FPSCR: Nothing */ |
1747 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1748 | 7fdf924f | aurel32 | { |
1749 | 66ba317c | aurel32 | gen_helper_fneg_T(cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B11_8)]); |
1750 | 7fdf924f | aurel32 | } |
1751 | 24988dc2 | aurel32 | return;
|
1752 | 24988dc2 | aurel32 | case 0xf05d: /* fabs FRn/DRn */ |
1753 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1754 | 24988dc2 | aurel32 | if (ctx->fpscr & FPSCR_PR) {
|
1755 | 24988dc2 | aurel32 | if (ctx->opcode & 0x0100) |
1756 | 24988dc2 | aurel32 | break; /* illegal instruction */ |
1757 | a7812ae4 | pbrook | TCGv_i64 fp = tcg_temp_new_i64(); |
1758 | cc4ba6a9 | aurel32 | gen_load_fpr64(fp, DREG(B11_8)); |
1759 | a7812ae4 | pbrook | gen_helper_fabs_DT(fp, fp); |
1760 | cc4ba6a9 | aurel32 | gen_store_fpr64(fp, DREG(B11_8)); |
1761 | a7812ae4 | pbrook | tcg_temp_free_i64(fp); |
1762 | 24988dc2 | aurel32 | } else {
|
1763 | 66ba317c | aurel32 | gen_helper_fabs_FT(cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B11_8)]); |
1764 | 24988dc2 | aurel32 | } |
1765 | 24988dc2 | aurel32 | return;
|
1766 | 24988dc2 | aurel32 | case 0xf06d: /* fsqrt FRn */ |
1767 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1768 | 24988dc2 | aurel32 | if (ctx->fpscr & FPSCR_PR) {
|
1769 | 24988dc2 | aurel32 | if (ctx->opcode & 0x0100) |
1770 | 24988dc2 | aurel32 | break; /* illegal instruction */ |
1771 | a7812ae4 | pbrook | TCGv_i64 fp = tcg_temp_new_i64(); |
1772 | cc4ba6a9 | aurel32 | gen_load_fpr64(fp, DREG(B11_8)); |
1773 | a7812ae4 | pbrook | gen_helper_fsqrt_DT(fp, fp); |
1774 | cc4ba6a9 | aurel32 | gen_store_fpr64(fp, DREG(B11_8)); |
1775 | a7812ae4 | pbrook | tcg_temp_free_i64(fp); |
1776 | 24988dc2 | aurel32 | } else {
|
1777 | 66ba317c | aurel32 | gen_helper_fsqrt_FT(cpu_fregs[FREG(B11_8)], cpu_fregs[FREG(B11_8)]); |
1778 | 24988dc2 | aurel32 | } |
1779 | 24988dc2 | aurel32 | return;
|
1780 | 24988dc2 | aurel32 | case 0xf07d: /* fsrra FRn */ |
1781 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1782 | 24988dc2 | aurel32 | break;
|
1783 | e67888a7 | ths | case 0xf08d: /* fldi0 FRn - FPSCR: R[PR] */ |
1784 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1785 | ea6cf6be | ths | if (!(ctx->fpscr & FPSCR_PR)) {
|
1786 | 66ba317c | aurel32 | tcg_gen_movi_i32(cpu_fregs[FREG(B11_8)], 0);
|
1787 | ea6cf6be | ths | } |
1788 | 12d96138 | aurel32 | return;
|
1789 | e67888a7 | ths | case 0xf09d: /* fldi1 FRn - FPSCR: R[PR] */ |
1790 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1791 | ea6cf6be | ths | if (!(ctx->fpscr & FPSCR_PR)) {
|
1792 | 66ba317c | aurel32 | tcg_gen_movi_i32(cpu_fregs[FREG(B11_8)], 0x3f800000);
|
1793 | ea6cf6be | ths | } |
1794 | 12d96138 | aurel32 | return;
|
1795 | 24988dc2 | aurel32 | case 0xf0ad: /* fcnvsd FPUL,DRn */ |
1796 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1797 | cc4ba6a9 | aurel32 | { |
1798 | a7812ae4 | pbrook | TCGv_i64 fp = tcg_temp_new_i64(); |
1799 | a7812ae4 | pbrook | gen_helper_fcnvsd_FT_DT(fp, cpu_fpul); |
1800 | cc4ba6a9 | aurel32 | gen_store_fpr64(fp, DREG(B11_8)); |
1801 | a7812ae4 | pbrook | tcg_temp_free_i64(fp); |
1802 | cc4ba6a9 | aurel32 | } |
1803 | 24988dc2 | aurel32 | return;
|
1804 | 24988dc2 | aurel32 | case 0xf0bd: /* fcnvds DRn,FPUL */ |
1805 | f6198371 | aurel32 | CHECK_FPU_ENABLED |
1806 | cc4ba6a9 | aurel32 | { |
1807 | a7812ae4 | pbrook | TCGv_i64 fp = tcg_temp_new_i64(); |
1808 | cc4ba6a9 | aurel32 | gen_load_fpr64(fp, DREG(B11_8)); |
1809 | a7812ae4 | pbrook | gen_helper_fcnvds_DT_FT(cpu_fpul, fp); |
1810 | a7812ae4 | pbrook | tcg_temp_free_i64(fp); |
1811 | cc4ba6a9 | aurel32 | } |
1812 | 24988dc2 | aurel32 | return;
|
1813 | fdf9b3e8 | bellard | } |
1814 | bacc637a | aurel32 | #if 0
|
1815 | fdf9b3e8 | bellard | fprintf(stderr, "unknown instruction 0x%04x at pc 0x%08x\n",
|
1816 | fdf9b3e8 | bellard | ctx->opcode, ctx->pc);
|
1817 | bacc637a | aurel32 | fflush(stderr);
|
1818 | bacc637a | aurel32 | #endif
|
1819 | a7812ae4 | pbrook | gen_helper_raise_illegal_instruction(); |
1820 | 823029f9 | ths | ctx->bstate = BS_EXCP; |
1821 | 823029f9 | ths | } |
1822 | 823029f9 | ths | |
1823 | b1d8e52e | blueswir1 | static void decode_opc(DisasContext * ctx) |
1824 | 823029f9 | ths | { |
1825 | 823029f9 | ths | uint32_t old_flags = ctx->flags; |
1826 | 823029f9 | ths | |
1827 | 823029f9 | ths | _decode_opc(ctx); |
1828 | 823029f9 | ths | |
1829 | 823029f9 | ths | if (old_flags & (DELAY_SLOT | DELAY_SLOT_CONDITIONAL)) {
|
1830 | 823029f9 | ths | if (ctx->flags & DELAY_SLOT_CLEARME) {
|
1831 | 1000822b | aurel32 | gen_store_flags(0);
|
1832 | 274a9e70 | aurel32 | } else {
|
1833 | 274a9e70 | aurel32 | /* go out of the delay slot */
|
1834 | 274a9e70 | aurel32 | uint32_t new_flags = ctx->flags; |
1835 | 274a9e70 | aurel32 | new_flags &= ~(DELAY_SLOT | DELAY_SLOT_CONDITIONAL); |
1836 | 1000822b | aurel32 | gen_store_flags(new_flags); |
1837 | 823029f9 | ths | } |
1838 | 823029f9 | ths | ctx->flags = 0;
|
1839 | 823029f9 | ths | ctx->bstate = BS_BRANCH; |
1840 | 823029f9 | ths | if (old_flags & DELAY_SLOT_CONDITIONAL) {
|
1841 | 823029f9 | ths | gen_delayed_conditional_jump(ctx); |
1842 | 823029f9 | ths | } else if (old_flags & DELAY_SLOT) { |
1843 | 823029f9 | ths | gen_jump(ctx); |
1844 | 823029f9 | ths | } |
1845 | 823029f9 | ths | |
1846 | 823029f9 | ths | } |
1847 | 274a9e70 | aurel32 | |
1848 | 274a9e70 | aurel32 | /* go into a delay slot */
|
1849 | 274a9e70 | aurel32 | if (ctx->flags & (DELAY_SLOT | DELAY_SLOT_CONDITIONAL))
|
1850 | 1000822b | aurel32 | gen_store_flags(ctx->flags); |
1851 | fdf9b3e8 | bellard | } |
1852 | fdf9b3e8 | bellard | |
1853 | 2cfc5f17 | ths | static inline void |
1854 | 820e00f2 | ths | gen_intermediate_code_internal(CPUState * env, TranslationBlock * tb, |
1855 | 820e00f2 | ths | int search_pc)
|
1856 | fdf9b3e8 | bellard | { |
1857 | fdf9b3e8 | bellard | DisasContext ctx; |
1858 | fdf9b3e8 | bellard | target_ulong pc_start; |
1859 | fdf9b3e8 | bellard | static uint16_t *gen_opc_end;
|
1860 | a1d1bb31 | aliguori | CPUBreakpoint *bp; |
1861 | 355fb23d | pbrook | int i, ii;
|
1862 | 2e70f6ef | pbrook | int num_insns;
|
1863 | 2e70f6ef | pbrook | int max_insns;
|
1864 | fdf9b3e8 | bellard | |
1865 | fdf9b3e8 | bellard | pc_start = tb->pc; |
1866 | fdf9b3e8 | bellard | gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; |
1867 | fdf9b3e8 | bellard | ctx.pc = pc_start; |
1868 | 823029f9 | ths | ctx.flags = (uint32_t)tb->flags; |
1869 | 823029f9 | ths | ctx.bstate = BS_NONE; |
1870 | fdf9b3e8 | bellard | ctx.sr = env->sr; |
1871 | eda9b09b | bellard | ctx.fpscr = env->fpscr; |
1872 | fdf9b3e8 | bellard | ctx.memidx = (env->sr & SR_MD) ? 1 : 0; |
1873 | 9854bc46 | pbrook | /* We don't know if the delayed pc came from a dynamic or static branch,
|
1874 | 9854bc46 | pbrook | so assume it is a dynamic branch. */
|
1875 | 823029f9 | ths | ctx.delayed_pc = -1; /* use delayed pc from env pointer */ |
1876 | fdf9b3e8 | bellard | ctx.tb = tb; |
1877 | fdf9b3e8 | bellard | ctx.singlestep_enabled = env->singlestep_enabled; |
1878 | 71968fa6 | aurel32 | ctx.features = env->features; |
1879 | fdf9b3e8 | bellard | |
1880 | fdf9b3e8 | bellard | #ifdef DEBUG_DISAS
|
1881 | 93fcfe39 | aliguori | qemu_log_mask(CPU_LOG_TB_CPU, |
1882 | 93fcfe39 | aliguori | "------------------------------------------------\n");
|
1883 | 93fcfe39 | aliguori | log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0);
|
1884 | fdf9b3e8 | bellard | #endif
|
1885 | fdf9b3e8 | bellard | |
1886 | 355fb23d | pbrook | ii = -1;
|
1887 | 2e70f6ef | pbrook | num_insns = 0;
|
1888 | 2e70f6ef | pbrook | max_insns = tb->cflags & CF_COUNT_MASK; |
1889 | 2e70f6ef | pbrook | if (max_insns == 0) |
1890 | 2e70f6ef | pbrook | max_insns = CF_COUNT_MASK; |
1891 | 2e70f6ef | pbrook | gen_icount_start(); |
1892 | 823029f9 | ths | while (ctx.bstate == BS_NONE && gen_opc_ptr < gen_opc_end) {
|
1893 | c0ce998e | aliguori | if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
|
1894 | c0ce998e | aliguori | TAILQ_FOREACH(bp, &env->breakpoints, entry) { |
1895 | a1d1bb31 | aliguori | if (ctx.pc == bp->pc) {
|
1896 | fdf9b3e8 | bellard | /* We have hit a breakpoint - make sure PC is up-to-date */
|
1897 | 3a8a44c4 | aurel32 | tcg_gen_movi_i32(cpu_pc, ctx.pc); |
1898 | a7812ae4 | pbrook | gen_helper_debug(); |
1899 | 823029f9 | ths | ctx.bstate = BS_EXCP; |
1900 | fdf9b3e8 | bellard | break;
|
1901 | fdf9b3e8 | bellard | } |
1902 | fdf9b3e8 | bellard | } |
1903 | fdf9b3e8 | bellard | } |
1904 | 355fb23d | pbrook | if (search_pc) {
|
1905 | 355fb23d | pbrook | i = gen_opc_ptr - gen_opc_buf; |
1906 | 355fb23d | pbrook | if (ii < i) {
|
1907 | 355fb23d | pbrook | ii++; |
1908 | 355fb23d | pbrook | while (ii < i)
|
1909 | 355fb23d | pbrook | gen_opc_instr_start[ii++] = 0;
|
1910 | 355fb23d | pbrook | } |
1911 | 355fb23d | pbrook | gen_opc_pc[ii] = ctx.pc; |
1912 | 823029f9 | ths | gen_opc_hflags[ii] = ctx.flags; |
1913 | 355fb23d | pbrook | gen_opc_instr_start[ii] = 1;
|
1914 | 2e70f6ef | pbrook | gen_opc_icount[ii] = num_insns; |
1915 | 355fb23d | pbrook | } |
1916 | 2e70f6ef | pbrook | if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) |
1917 | 2e70f6ef | pbrook | gen_io_start(); |
1918 | fdf9b3e8 | bellard | #if 0
|
1919 | fdf9b3e8 | bellard | fprintf(stderr, "Loading opcode at address 0x%08x\n", ctx.pc);
|
1920 | fdf9b3e8 | bellard | fflush(stderr);
|
1921 | fdf9b3e8 | bellard | #endif
|
1922 | fdf9b3e8 | bellard | ctx.opcode = lduw_code(ctx.pc); |
1923 | fdf9b3e8 | bellard | decode_opc(&ctx); |
1924 | 2e70f6ef | pbrook | num_insns++; |
1925 | fdf9b3e8 | bellard | ctx.pc += 2;
|
1926 | fdf9b3e8 | bellard | if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0) |
1927 | fdf9b3e8 | bellard | break;
|
1928 | fdf9b3e8 | bellard | if (env->singlestep_enabled)
|
1929 | fdf9b3e8 | bellard | break;
|
1930 | 2e70f6ef | pbrook | if (num_insns >= max_insns)
|
1931 | 2e70f6ef | pbrook | break;
|
1932 | fdf9b3e8 | bellard | #ifdef SH4_SINGLE_STEP
|
1933 | fdf9b3e8 | bellard | break;
|
1934 | fdf9b3e8 | bellard | #endif
|
1935 | fdf9b3e8 | bellard | } |
1936 | 2e70f6ef | pbrook | if (tb->cflags & CF_LAST_IO)
|
1937 | 2e70f6ef | pbrook | gen_io_end(); |
1938 | fdf9b3e8 | bellard | if (env->singlestep_enabled) {
|
1939 | bdbf22e6 | aurel32 | tcg_gen_movi_i32(cpu_pc, ctx.pc); |
1940 | a7812ae4 | pbrook | gen_helper_debug(); |
1941 | 823029f9 | ths | } else {
|
1942 | 823029f9 | ths | switch (ctx.bstate) {
|
1943 | 823029f9 | ths | case BS_STOP:
|
1944 | 823029f9 | ths | /* gen_op_interrupt_restart(); */
|
1945 | 823029f9 | ths | /* fall through */
|
1946 | 823029f9 | ths | case BS_NONE:
|
1947 | 823029f9 | ths | if (ctx.flags) {
|
1948 | 1000822b | aurel32 | gen_store_flags(ctx.flags | DELAY_SLOT_CLEARME); |
1949 | 823029f9 | ths | } |
1950 | 823029f9 | ths | gen_goto_tb(&ctx, 0, ctx.pc);
|
1951 | 823029f9 | ths | break;
|
1952 | 823029f9 | ths | case BS_EXCP:
|
1953 | 823029f9 | ths | /* gen_op_interrupt_restart(); */
|
1954 | 57fec1fe | bellard | tcg_gen_exit_tb(0);
|
1955 | 823029f9 | ths | break;
|
1956 | 823029f9 | ths | case BS_BRANCH:
|
1957 | 823029f9 | ths | default:
|
1958 | 823029f9 | ths | break;
|
1959 | 823029f9 | ths | } |
1960 | fdf9b3e8 | bellard | } |
1961 | 823029f9 | ths | |
1962 | 2e70f6ef | pbrook | gen_icount_end(tb, num_insns); |
1963 | fdf9b3e8 | bellard | *gen_opc_ptr = INDEX_op_end; |
1964 | 355fb23d | pbrook | if (search_pc) {
|
1965 | 355fb23d | pbrook | i = gen_opc_ptr - gen_opc_buf; |
1966 | 355fb23d | pbrook | ii++; |
1967 | 355fb23d | pbrook | while (ii <= i)
|
1968 | 355fb23d | pbrook | gen_opc_instr_start[ii++] = 0;
|
1969 | 355fb23d | pbrook | } else {
|
1970 | 355fb23d | pbrook | tb->size = ctx.pc - pc_start; |
1971 | 2e70f6ef | pbrook | tb->icount = num_insns; |
1972 | 355fb23d | pbrook | } |
1973 | fdf9b3e8 | bellard | |
1974 | fdf9b3e8 | bellard | #ifdef DEBUG_DISAS
|
1975 | fdf9b3e8 | bellard | #ifdef SH4_DEBUG_DISAS
|
1976 | 93fcfe39 | aliguori | qemu_log_mask(CPU_LOG_TB_IN_ASM, "\n");
|
1977 | fdf9b3e8 | bellard | #endif
|
1978 | 8fec2b8c | aliguori | if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
|
1979 | 93fcfe39 | aliguori | qemu_log("IN:\n"); /* , lookup_symbol(pc_start)); */ |
1980 | 93fcfe39 | aliguori | log_target_disas(pc_start, ctx.pc - pc_start, 0);
|
1981 | 93fcfe39 | aliguori | qemu_log("\n");
|
1982 | fdf9b3e8 | bellard | } |
1983 | fdf9b3e8 | bellard | #endif
|
1984 | fdf9b3e8 | bellard | } |
1985 | fdf9b3e8 | bellard | |
1986 | 2cfc5f17 | ths | void gen_intermediate_code(CPUState * env, struct TranslationBlock *tb) |
1987 | fdf9b3e8 | bellard | { |
1988 | 2cfc5f17 | ths | gen_intermediate_code_internal(env, tb, 0);
|
1989 | fdf9b3e8 | bellard | } |
1990 | fdf9b3e8 | bellard | |
1991 | 2cfc5f17 | ths | void gen_intermediate_code_pc(CPUState * env, struct TranslationBlock *tb) |
1992 | fdf9b3e8 | bellard | { |
1993 | 2cfc5f17 | ths | gen_intermediate_code_internal(env, tb, 1);
|
1994 | fdf9b3e8 | bellard | } |
1995 | d2856f1a | aurel32 | |
1996 | d2856f1a | aurel32 | void gen_pc_load(CPUState *env, TranslationBlock *tb,
|
1997 | d2856f1a | aurel32 | unsigned long searched_pc, int pc_pos, void *puc) |
1998 | d2856f1a | aurel32 | { |
1999 | d2856f1a | aurel32 | env->pc = gen_opc_pc[pc_pos]; |
2000 | d2856f1a | aurel32 | env->flags = gen_opc_hflags[pc_pos]; |
2001 | d2856f1a | aurel32 | } |