2 * x86 condition code helpers
4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
22 #include "exec/helper-proto.h"
24 const uint8_t parity_table[256] = {
25 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
26 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
27 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
28 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
29 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
30 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
31 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
32 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
33 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
34 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
35 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
36 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
37 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
38 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
39 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
40 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
41 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
42 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
43 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
44 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
45 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
46 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
47 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
48 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
49 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
50 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
51 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
52 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
53 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
54 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
55 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
56 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
60 #include "cc_helper_template.h"
64 #include "cc_helper_template.h"
68 #include "cc_helper_template.h"
74 #include "cc_helper_template.h"
79 static target_ulong compute_all_adcx(target_ulong dst, target_ulong src1,
82 return (src1 & ~CC_C) | (dst * CC_C);
85 static target_ulong compute_all_adox(target_ulong dst, target_ulong src1,
88 return (src1 & ~CC_O) | (src2 * CC_O);
91 static target_ulong compute_all_adcox(target_ulong dst, target_ulong src1,
94 return (src1 & ~(CC_C | CC_O)) | (dst * CC_C) | (src2 * CC_O);
97 target_ulong helper_cc_compute_all(target_ulong dst, target_ulong src1,
98 target_ulong src2, int op)
101 default: /* should never happen */
109 return src1 ? 0 : CC_Z;
112 return compute_all_mulb(dst, src1);
114 return compute_all_mulw(dst, src1);
116 return compute_all_mull(dst, src1);
119 return compute_all_addb(dst, src1);
121 return compute_all_addw(dst, src1);
123 return compute_all_addl(dst, src1);
126 return compute_all_adcb(dst, src1, src2);
128 return compute_all_adcw(dst, src1, src2);
130 return compute_all_adcl(dst, src1, src2);
133 return compute_all_subb(dst, src1);
135 return compute_all_subw(dst, src1);
137 return compute_all_subl(dst, src1);
140 return compute_all_sbbb(dst, src1, src2);
142 return compute_all_sbbw(dst, src1, src2);
144 return compute_all_sbbl(dst, src1, src2);
147 return compute_all_logicb(dst, src1);
149 return compute_all_logicw(dst, src1);
151 return compute_all_logicl(dst, src1);
154 return compute_all_incb(dst, src1);
156 return compute_all_incw(dst, src1);
158 return compute_all_incl(dst, src1);
161 return compute_all_decb(dst, src1);
163 return compute_all_decw(dst, src1);
165 return compute_all_decl(dst, src1);
168 return compute_all_shlb(dst, src1);
170 return compute_all_shlw(dst, src1);
172 return compute_all_shll(dst, src1);
175 return compute_all_sarb(dst, src1);
177 return compute_all_sarw(dst, src1);
179 return compute_all_sarl(dst, src1);
182 return compute_all_bmilgb(dst, src1);
184 return compute_all_bmilgw(dst, src1);
186 return compute_all_bmilgl(dst, src1);
189 return compute_all_adcx(dst, src1, src2);
191 return compute_all_adox(dst, src1, src2);
193 return compute_all_adcox(dst, src1, src2);
197 return compute_all_mulq(dst, src1);
199 return compute_all_addq(dst, src1);
201 return compute_all_adcq(dst, src1, src2);
203 return compute_all_subq(dst, src1);
205 return compute_all_sbbq(dst, src1, src2);
207 return compute_all_logicq(dst, src1);
209 return compute_all_incq(dst, src1);
211 return compute_all_decq(dst, src1);
213 return compute_all_shlq(dst, src1);
215 return compute_all_sarq(dst, src1);
217 return compute_all_bmilgq(dst, src1);
222 uint32_t cpu_cc_compute_all(CPUX86State *env, int op)
224 return helper_cc_compute_all(CC_DST, CC_SRC, CC_SRC2, op);
227 target_ulong helper_cc_compute_c(target_ulong dst, target_ulong src1,
228 target_ulong src2, int op)
231 default: /* should never happen */
269 return compute_c_addb(dst, src1);
271 return compute_c_addw(dst, src1);
273 return compute_c_addl(dst, src1);
276 return compute_c_adcb(dst, src1, src2);
278 return compute_c_adcw(dst, src1, src2);
280 return compute_c_adcl(dst, src1, src2);
283 return compute_c_subb(dst, src1);
285 return compute_c_subw(dst, src1);
287 return compute_c_subl(dst, src1);
290 return compute_c_sbbb(dst, src1, src2);
292 return compute_c_sbbw(dst, src1, src2);
294 return compute_c_sbbl(dst, src1, src2);
297 return compute_c_shlb(dst, src1);
299 return compute_c_shlw(dst, src1);
301 return compute_c_shll(dst, src1);
304 return compute_c_bmilgb(dst, src1);
306 return compute_c_bmilgw(dst, src1);
308 return compute_c_bmilgl(dst, src1);
312 return compute_c_addq(dst, src1);
314 return compute_c_adcq(dst, src1, src2);
316 return compute_c_subq(dst, src1);
318 return compute_c_sbbq(dst, src1, src2);
320 return compute_c_shlq(dst, src1);
322 return compute_c_bmilgq(dst, src1);
327 void helper_write_eflags(CPUX86State *env, target_ulong t0,
328 uint32_t update_mask)
330 cpu_load_eflags(env, t0, update_mask);
333 target_ulong helper_read_eflags(CPUX86State *env)
337 eflags = cpu_cc_compute_all(env, CC_OP);
338 eflags |= (env->df & DF_MASK);
339 eflags |= env->eflags & ~(VM_MASK | RF_MASK);
343 void helper_clts(CPUX86State *env)
345 env->cr[0] &= ~CR0_TS_MASK;
346 env->hflags &= ~HF_TS_MASK;
349 void helper_reset_rf(CPUX86State *env)
351 env->eflags &= ~RF_MASK;
354 void helper_cli(CPUX86State *env)
356 env->eflags &= ~IF_MASK;
359 void helper_sti(CPUX86State *env)
361 env->eflags |= IF_MASK;
364 void helper_clac(CPUX86State *env)
366 env->eflags &= ~AC_MASK;
369 void helper_stac(CPUX86State *env)
371 env->eflags |= AC_MASK;
375 /* vm86plus instructions */
376 void helper_cli_vm(CPUX86State *env)
378 env->eflags &= ~VIF_MASK;
381 void helper_sti_vm(CPUX86State *env)
383 env->eflags |= VIF_MASK;
384 if (env->eflags & VIP_MASK) {
385 raise_exception_ra(env, EXCP0D_GPF, GETPC());