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/>.
23 const uint8_t parity_table[256] = {
24 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
25 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
26 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
27 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
28 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
29 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
30 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
31 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
32 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
33 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
34 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
35 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
36 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
37 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
38 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
39 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
40 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
41 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
42 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
43 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
44 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
45 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
46 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
47 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
48 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
49 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
50 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
51 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
52 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
53 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
54 CC_P, 0, 0, CC_P, 0, CC_P, CC_P, 0,
55 0, CC_P, CC_P, 0, CC_P, 0, 0, CC_P,
59 #include "cc_helper_template.h"
63 #include "cc_helper_template.h"
67 #include "cc_helper_template.h"
73 #include "cc_helper_template.h"
78 static int compute_all_eflags(CPUX86State *env)
83 static int compute_c_eflags(CPUX86State *env)
88 uint32_t helper_cc_compute_all(CPUX86State *env, int op)
91 default: /* should never happen */
95 return compute_all_eflags(env);
98 return compute_all_mulb(env);
100 return compute_all_mulw(env);
102 return compute_all_mull(env);
105 return compute_all_addb(env);
107 return compute_all_addw(env);
109 return compute_all_addl(env);
112 return compute_all_adcb(env);
114 return compute_all_adcw(env);
116 return compute_all_adcl(env);
119 return compute_all_subb(env);
121 return compute_all_subw(env);
123 return compute_all_subl(env);
126 return compute_all_sbbb(env);
128 return compute_all_sbbw(env);
130 return compute_all_sbbl(env);
133 return compute_all_logicb(env);
135 return compute_all_logicw(env);
137 return compute_all_logicl(env);
140 return compute_all_incb(env);
142 return compute_all_incw(env);
144 return compute_all_incl(env);
147 return compute_all_decb(env);
149 return compute_all_decw(env);
151 return compute_all_decl(env);
154 return compute_all_shlb(env);
156 return compute_all_shlw(env);
158 return compute_all_shll(env);
161 return compute_all_sarb(env);
163 return compute_all_sarw(env);
165 return compute_all_sarl(env);
169 return compute_all_mulq(env);
172 return compute_all_addq(env);
175 return compute_all_adcq(env);
178 return compute_all_subq(env);
181 return compute_all_sbbq(env);
184 return compute_all_logicq(env);
187 return compute_all_incq(env);
190 return compute_all_decq(env);
193 return compute_all_shlq(env);
196 return compute_all_sarq(env);
201 uint32_t cpu_cc_compute_all(CPUX86State *env, int op)
203 return helper_cc_compute_all(env, op);
206 uint32_t helper_cc_compute_c(CPUX86State *env, int op)
209 default: /* should never happen */
213 return compute_c_eflags(env);
216 return compute_c_mull(env);
218 return compute_c_mull(env);
220 return compute_c_mull(env);
223 return compute_c_addb(env);
225 return compute_c_addw(env);
227 return compute_c_addl(env);
230 return compute_c_adcb(env);
232 return compute_c_adcw(env);
234 return compute_c_adcl(env);
237 return compute_c_subb(env);
239 return compute_c_subw(env);
241 return compute_c_subl(env);
244 return compute_c_sbbb(env);
246 return compute_c_sbbw(env);
248 return compute_c_sbbl(env);
251 return compute_c_logicb();
253 return compute_c_logicw();
255 return compute_c_logicl();
258 return compute_c_incl(env);
260 return compute_c_incl(env);
262 return compute_c_incl(env);
265 return compute_c_incl(env);
267 return compute_c_incl(env);
269 return compute_c_incl(env);
272 return compute_c_shlb(env);
274 return compute_c_shlw(env);
276 return compute_c_shll(env);
279 return compute_c_sarl(env);
281 return compute_c_sarl(env);
283 return compute_c_sarl(env);
287 return compute_c_mull(env);
290 return compute_c_addq(env);
293 return compute_c_adcq(env);
296 return compute_c_subq(env);
299 return compute_c_sbbq(env);
302 return compute_c_logicq();
305 return compute_c_incl(env);
308 return compute_c_incl(env);
311 return compute_c_shlq(env);
314 return compute_c_sarl(env);
319 void helper_write_eflags(CPUX86State *env, target_ulong t0,
320 uint32_t update_mask)
322 cpu_load_eflags(env, t0, update_mask);
325 target_ulong helper_read_eflags(CPUX86State *env)
329 eflags = helper_cc_compute_all(env, CC_OP);
330 eflags |= (DF & DF_MASK);
331 eflags |= env->eflags & ~(VM_MASK | RF_MASK);
335 void helper_clts(CPUX86State *env)
337 env->cr[0] &= ~CR0_TS_MASK;
338 env->hflags &= ~HF_TS_MASK;
341 void helper_reset_rf(CPUX86State *env)
343 env->eflags &= ~RF_MASK;
346 void helper_cli(CPUX86State *env)
348 env->eflags &= ~IF_MASK;
351 void helper_sti(CPUX86State *env)
353 env->eflags |= IF_MASK;
356 void helper_clac(CPUX86State *env)
358 env->eflags &= ~AC_MASK;
361 void helper_stac(CPUX86State *env)
363 env->eflags |= AC_MASK;
367 /* vm86plus instructions */
368 void helper_cli_vm(CPUX86State *env)
370 env->eflags &= ~VIF_MASK;
373 void helper_sti_vm(CPUX86State *env)
375 env->eflags |= VIF_MASK;
376 if (env->eflags & VIP_MASK) {
377 raise_exception(env, EXCP0D_GPF);
382 void helper_set_inhibit_irq(CPUX86State *env)
384 env->hflags |= HF_INHIBIT_IRQ_MASK;
387 void helper_reset_inhibit_irq(CPUX86State *env)
389 env->hflags &= ~HF_INHIBIT_IRQ_MASK;