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/>.
21 #include "dyngen-exec.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 int compute_all_eflags(void)
84 static int compute_c_eflags(void)
89 uint32_t helper_cc_compute_all(int op
)
92 default: /* should never happen */
96 return compute_all_eflags();
99 return compute_all_mulb();
101 return compute_all_mulw();
103 return compute_all_mull();
106 return compute_all_addb();
108 return compute_all_addw();
110 return compute_all_addl();
113 return compute_all_adcb();
115 return compute_all_adcw();
117 return compute_all_adcl();
120 return compute_all_subb();
122 return compute_all_subw();
124 return compute_all_subl();
127 return compute_all_sbbb();
129 return compute_all_sbbw();
131 return compute_all_sbbl();
134 return compute_all_logicb();
136 return compute_all_logicw();
138 return compute_all_logicl();
141 return compute_all_incb();
143 return compute_all_incw();
145 return compute_all_incl();
148 return compute_all_decb();
150 return compute_all_decw();
152 return compute_all_decl();
155 return compute_all_shlb();
157 return compute_all_shlw();
159 return compute_all_shll();
162 return compute_all_sarb();
164 return compute_all_sarw();
166 return compute_all_sarl();
170 return compute_all_mulq();
173 return compute_all_addq();
176 return compute_all_adcq();
179 return compute_all_subq();
182 return compute_all_sbbq();
185 return compute_all_logicq();
188 return compute_all_incq();
191 return compute_all_decq();
194 return compute_all_shlq();
197 return compute_all_sarq();
202 uint32_t cpu_cc_compute_all(CPUX86State
*env1
, int op
)
204 CPUX86State
*saved_env
;
209 ret
= helper_cc_compute_all(op
);
214 uint32_t helper_cc_compute_c(int op
)
217 default: /* should never happen */
221 return compute_c_eflags();
224 return compute_c_mull();
226 return compute_c_mull();
228 return compute_c_mull();
231 return compute_c_addb();
233 return compute_c_addw();
235 return compute_c_addl();
238 return compute_c_adcb();
240 return compute_c_adcw();
242 return compute_c_adcl();
245 return compute_c_subb();
247 return compute_c_subw();
249 return compute_c_subl();
252 return compute_c_sbbb();
254 return compute_c_sbbw();
256 return compute_c_sbbl();
259 return compute_c_logicb();
261 return compute_c_logicw();
263 return compute_c_logicl();
266 return compute_c_incl();
268 return compute_c_incl();
270 return compute_c_incl();
273 return compute_c_incl();
275 return compute_c_incl();
277 return compute_c_incl();
280 return compute_c_shlb();
282 return compute_c_shlw();
284 return compute_c_shll();
287 return compute_c_sarl();
289 return compute_c_sarl();
291 return compute_c_sarl();
295 return compute_c_mull();
298 return compute_c_addq();
301 return compute_c_adcq();
304 return compute_c_subq();
307 return compute_c_sbbq();
310 return compute_c_logicq();
313 return compute_c_incl();
316 return compute_c_incl();
319 return compute_c_shlq();
322 return compute_c_sarl();
327 void helper_write_eflags(target_ulong t0
, uint32_t update_mask
)
329 cpu_load_eflags(env
, t0
, update_mask
);
332 target_ulong
helper_read_eflags(void)
336 eflags
= helper_cc_compute_all(CC_OP
);
337 eflags
|= (DF
& DF_MASK
);
338 eflags
|= env
->eflags
& ~(VM_MASK
| RF_MASK
);
342 void helper_clts(void)
344 env
->cr
[0] &= ~CR0_TS_MASK
;
345 env
->hflags
&= ~HF_TS_MASK
;
348 void helper_reset_rf(void)
350 env
->eflags
&= ~RF_MASK
;
353 void helper_cli(void)
355 env
->eflags
&= ~IF_MASK
;
358 void helper_sti(void)
360 env
->eflags
|= IF_MASK
;
364 /* vm86plus instructions */
365 void helper_cli_vm(void)
367 env
->eflags
&= ~VIF_MASK
;
370 void helper_sti_vm(void)
372 env
->eflags
|= VIF_MASK
;
373 if (env
->eflags
& VIP_MASK
) {
374 raise_exception(env
, EXCP0D_GPF
);
379 void helper_set_inhibit_irq(void)
381 env
->hflags
|= HF_INHIBIT_IRQ_MASK
;
384 void helper_reset_inhibit_irq(void)
386 env
->hflags
&= ~HF_INHIBIT_IRQ_MASK
;