]> git.proxmox.com Git - mirror_qemu.git/blame - target/i386/cc_helper.c
stellaris: delay timer_new to avoid memleaks
[mirror_qemu.git] / target / i386 / cc_helper.c
CommitLineData
5918fffb
BS
1/*
2 * x86 condition code helpers
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
b6a0aa05 20#include "qemu/osdep.h"
5918fffb 21#include "cpu.h"
2ef6175a 22#include "exec/helper-proto.h"
5918fffb
BS
23
24const 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,
57};
58
59#define SHIFT 0
60#include "cc_helper_template.h"
61#undef SHIFT
62
63#define SHIFT 1
64#include "cc_helper_template.h"
65#undef SHIFT
66
67#define SHIFT 2
68#include "cc_helper_template.h"
69#undef SHIFT
70
71#ifdef TARGET_X86_64
72
73#define SHIFT 3
74#include "cc_helper_template.h"
75#undef SHIFT
76
77#endif
78
cd7f97ca
RH
79static target_ulong compute_all_adcx(target_ulong dst, target_ulong src1,
80 target_ulong src2)
81{
82 return (src1 & ~CC_C) | (dst * CC_C);
83}
84
85static target_ulong compute_all_adox(target_ulong dst, target_ulong src1,
86 target_ulong src2)
87{
88 return (src1 & ~CC_O) | (src2 * CC_O);
89}
90
91static target_ulong compute_all_adcox(target_ulong dst, target_ulong src1,
92 target_ulong src2)
93{
94 return (src1 & ~(CC_C | CC_O)) | (dst * CC_C) | (src2 * CC_O);
95}
96
988c3eb0
RH
97target_ulong helper_cc_compute_all(target_ulong dst, target_ulong src1,
98 target_ulong src2, int op)
5918fffb
BS
99{
100 switch (op) {
101 default: /* should never happen */
102 return 0;
103
104 case CC_OP_EFLAGS:
8601c0b6 105 return src1;
436ff2d2 106 case CC_OP_CLR:
d2fe51bd 107 return CC_Z | CC_P;
4885c3c4
RH
108 case CC_OP_POPCNT:
109 return src1 ? 0 : CC_Z;
5918fffb
BS
110
111 case CC_OP_MULB:
8601c0b6 112 return compute_all_mulb(dst, src1);
5918fffb 113 case CC_OP_MULW:
8601c0b6 114 return compute_all_mulw(dst, src1);
5918fffb 115 case CC_OP_MULL:
8601c0b6 116 return compute_all_mull(dst, src1);
5918fffb
BS
117
118 case CC_OP_ADDB:
8601c0b6 119 return compute_all_addb(dst, src1);
5918fffb 120 case CC_OP_ADDW:
8601c0b6 121 return compute_all_addw(dst, src1);
5918fffb 122 case CC_OP_ADDL:
8601c0b6 123 return compute_all_addl(dst, src1);
5918fffb
BS
124
125 case CC_OP_ADCB:
988c3eb0 126 return compute_all_adcb(dst, src1, src2);
5918fffb 127 case CC_OP_ADCW:
988c3eb0 128 return compute_all_adcw(dst, src1, src2);
5918fffb 129 case CC_OP_ADCL:
988c3eb0 130 return compute_all_adcl(dst, src1, src2);
5918fffb
BS
131
132 case CC_OP_SUBB:
8601c0b6 133 return compute_all_subb(dst, src1);
5918fffb 134 case CC_OP_SUBW:
8601c0b6 135 return compute_all_subw(dst, src1);
5918fffb 136 case CC_OP_SUBL:
8601c0b6 137 return compute_all_subl(dst, src1);
5918fffb
BS
138
139 case CC_OP_SBBB:
988c3eb0 140 return compute_all_sbbb(dst, src1, src2);
5918fffb 141 case CC_OP_SBBW:
988c3eb0 142 return compute_all_sbbw(dst, src1, src2);
5918fffb 143 case CC_OP_SBBL:
988c3eb0 144 return compute_all_sbbl(dst, src1, src2);
5918fffb
BS
145
146 case CC_OP_LOGICB:
8601c0b6 147 return compute_all_logicb(dst, src1);
5918fffb 148 case CC_OP_LOGICW:
8601c0b6 149 return compute_all_logicw(dst, src1);
5918fffb 150 case CC_OP_LOGICL:
8601c0b6 151 return compute_all_logicl(dst, src1);
5918fffb
BS
152
153 case CC_OP_INCB:
8601c0b6 154 return compute_all_incb(dst, src1);
5918fffb 155 case CC_OP_INCW:
8601c0b6 156 return compute_all_incw(dst, src1);
5918fffb 157 case CC_OP_INCL:
8601c0b6 158 return compute_all_incl(dst, src1);
5918fffb
BS
159
160 case CC_OP_DECB:
8601c0b6 161 return compute_all_decb(dst, src1);
5918fffb 162 case CC_OP_DECW:
8601c0b6 163 return compute_all_decw(dst, src1);
5918fffb 164 case CC_OP_DECL:
8601c0b6 165 return compute_all_decl(dst, src1);
5918fffb
BS
166
167 case CC_OP_SHLB:
8601c0b6 168 return compute_all_shlb(dst, src1);
5918fffb 169 case CC_OP_SHLW:
8601c0b6 170 return compute_all_shlw(dst, src1);
5918fffb 171 case CC_OP_SHLL:
8601c0b6 172 return compute_all_shll(dst, src1);
5918fffb
BS
173
174 case CC_OP_SARB:
8601c0b6 175 return compute_all_sarb(dst, src1);
5918fffb 176 case CC_OP_SARW:
8601c0b6 177 return compute_all_sarw(dst, src1);
5918fffb 178 case CC_OP_SARL:
8601c0b6 179 return compute_all_sarl(dst, src1);
5918fffb 180
bc4b43dc
RH
181 case CC_OP_BMILGB:
182 return compute_all_bmilgb(dst, src1);
183 case CC_OP_BMILGW:
184 return compute_all_bmilgw(dst, src1);
185 case CC_OP_BMILGL:
186 return compute_all_bmilgl(dst, src1);
187
cd7f97ca
RH
188 case CC_OP_ADCX:
189 return compute_all_adcx(dst, src1, src2);
190 case CC_OP_ADOX:
191 return compute_all_adox(dst, src1, src2);
192 case CC_OP_ADCOX:
193 return compute_all_adcox(dst, src1, src2);
194
5918fffb
BS
195#ifdef TARGET_X86_64
196 case CC_OP_MULQ:
8601c0b6 197 return compute_all_mulq(dst, src1);
5918fffb 198 case CC_OP_ADDQ:
8601c0b6 199 return compute_all_addq(dst, src1);
5918fffb 200 case CC_OP_ADCQ:
988c3eb0 201 return compute_all_adcq(dst, src1, src2);
5918fffb 202 case CC_OP_SUBQ:
8601c0b6 203 return compute_all_subq(dst, src1);
5918fffb 204 case CC_OP_SBBQ:
988c3eb0 205 return compute_all_sbbq(dst, src1, src2);
5918fffb 206 case CC_OP_LOGICQ:
8601c0b6 207 return compute_all_logicq(dst, src1);
5918fffb 208 case CC_OP_INCQ:
8601c0b6 209 return compute_all_incq(dst, src1);
5918fffb 210 case CC_OP_DECQ:
8601c0b6 211 return compute_all_decq(dst, src1);
5918fffb 212 case CC_OP_SHLQ:
8601c0b6 213 return compute_all_shlq(dst, src1);
5918fffb 214 case CC_OP_SARQ:
8601c0b6 215 return compute_all_sarq(dst, src1);
bc4b43dc
RH
216 case CC_OP_BMILGQ:
217 return compute_all_bmilgq(dst, src1);
5918fffb
BS
218#endif
219 }
220}
221
f0967a1a 222uint32_t cpu_cc_compute_all(CPUX86State *env, int op)
5918fffb 223{
988c3eb0 224 return helper_cc_compute_all(CC_DST, CC_SRC, CC_SRC2, op);
5918fffb
BS
225}
226
988c3eb0
RH
227target_ulong helper_cc_compute_c(target_ulong dst, target_ulong src1,
228 target_ulong src2, int op)
5918fffb
BS
229{
230 switch (op) {
231 default: /* should never happen */
8601c0b6
RH
232 case CC_OP_LOGICB:
233 case CC_OP_LOGICW:
234 case CC_OP_LOGICL:
235 case CC_OP_LOGICQ:
436ff2d2 236 case CC_OP_CLR:
4885c3c4 237 case CC_OP_POPCNT:
5918fffb
BS
238 return 0;
239
240 case CC_OP_EFLAGS:
8601c0b6
RH
241 case CC_OP_SARB:
242 case CC_OP_SARW:
243 case CC_OP_SARL:
244 case CC_OP_SARQ:
cd7f97ca 245 case CC_OP_ADOX:
8601c0b6
RH
246 return src1 & 1;
247
248 case CC_OP_INCB:
249 case CC_OP_INCW:
250 case CC_OP_INCL:
251 case CC_OP_INCQ:
252 case CC_OP_DECB:
253 case CC_OP_DECW:
254 case CC_OP_DECL:
255 case CC_OP_DECQ:
256 return src1;
5918fffb
BS
257
258 case CC_OP_MULB:
5918fffb 259 case CC_OP_MULW:
5918fffb 260 case CC_OP_MULL:
8601c0b6
RH
261 case CC_OP_MULQ:
262 return src1 != 0;
5918fffb 263
cd7f97ca
RH
264 case CC_OP_ADCX:
265 case CC_OP_ADCOX:
266 return dst;
267
5918fffb 268 case CC_OP_ADDB:
8601c0b6 269 return compute_c_addb(dst, src1);
5918fffb 270 case CC_OP_ADDW:
8601c0b6 271 return compute_c_addw(dst, src1);
5918fffb 272 case CC_OP_ADDL:
8601c0b6 273 return compute_c_addl(dst, src1);
5918fffb
BS
274
275 case CC_OP_ADCB:
988c3eb0 276 return compute_c_adcb(dst, src1, src2);
5918fffb 277 case CC_OP_ADCW:
988c3eb0 278 return compute_c_adcw(dst, src1, src2);
5918fffb 279 case CC_OP_ADCL:
988c3eb0 280 return compute_c_adcl(dst, src1, src2);
5918fffb
BS
281
282 case CC_OP_SUBB:
8601c0b6 283 return compute_c_subb(dst, src1);
5918fffb 284 case CC_OP_SUBW:
8601c0b6 285 return compute_c_subw(dst, src1);
5918fffb 286 case CC_OP_SUBL:
8601c0b6 287 return compute_c_subl(dst, src1);
5918fffb
BS
288
289 case CC_OP_SBBB:
988c3eb0 290 return compute_c_sbbb(dst, src1, src2);
5918fffb 291 case CC_OP_SBBW:
988c3eb0 292 return compute_c_sbbw(dst, src1, src2);
5918fffb 293 case CC_OP_SBBL:
988c3eb0 294 return compute_c_sbbl(dst, src1, src2);
5918fffb
BS
295
296 case CC_OP_SHLB:
8601c0b6 297 return compute_c_shlb(dst, src1);
5918fffb 298 case CC_OP_SHLW:
8601c0b6 299 return compute_c_shlw(dst, src1);
5918fffb 300 case CC_OP_SHLL:
8601c0b6 301 return compute_c_shll(dst, src1);
5918fffb 302
bc4b43dc
RH
303 case CC_OP_BMILGB:
304 return compute_c_bmilgb(dst, src1);
305 case CC_OP_BMILGW:
306 return compute_c_bmilgw(dst, src1);
307 case CC_OP_BMILGL:
308 return compute_c_bmilgl(dst, src1);
309
5918fffb 310#ifdef TARGET_X86_64
5918fffb 311 case CC_OP_ADDQ:
8601c0b6 312 return compute_c_addq(dst, src1);
5918fffb 313 case CC_OP_ADCQ:
988c3eb0 314 return compute_c_adcq(dst, src1, src2);
5918fffb 315 case CC_OP_SUBQ:
8601c0b6 316 return compute_c_subq(dst, src1);
5918fffb 317 case CC_OP_SBBQ:
988c3eb0 318 return compute_c_sbbq(dst, src1, src2);
5918fffb 319 case CC_OP_SHLQ:
8601c0b6 320 return compute_c_shlq(dst, src1);
bc4b43dc
RH
321 case CC_OP_BMILGQ:
322 return compute_c_bmilgq(dst, src1);
5918fffb
BS
323#endif
324 }
325}
326
f0967a1a
BS
327void helper_write_eflags(CPUX86State *env, target_ulong t0,
328 uint32_t update_mask)
5918fffb
BS
329{
330 cpu_load_eflags(env, t0, update_mask);
331}
332
f0967a1a 333target_ulong helper_read_eflags(CPUX86State *env)
5918fffb
BS
334{
335 uint32_t eflags;
336
db9f2597 337 eflags = cpu_cc_compute_all(env, CC_OP);
80cf2c81 338 eflags |= (env->df & DF_MASK);
5918fffb
BS
339 eflags |= env->eflags & ~(VM_MASK | RF_MASK);
340 return eflags;
341}
342
f0967a1a 343void helper_clts(CPUX86State *env)
5918fffb
BS
344{
345 env->cr[0] &= ~CR0_TS_MASK;
346 env->hflags &= ~HF_TS_MASK;
347}
348
f0967a1a 349void helper_reset_rf(CPUX86State *env)
5918fffb
BS
350{
351 env->eflags &= ~RF_MASK;
352}
353
f0967a1a 354void helper_cli(CPUX86State *env)
5918fffb
BS
355{
356 env->eflags &= ~IF_MASK;
357}
358
f0967a1a 359void helper_sti(CPUX86State *env)
5918fffb
BS
360{
361 env->eflags |= IF_MASK;
362}
363
a9321a4d
PA
364void helper_clac(CPUX86State *env)
365{
366 env->eflags &= ~AC_MASK;
367}
368
369void helper_stac(CPUX86State *env)
370{
371 env->eflags |= AC_MASK;
372}
373
5918fffb
BS
374#if 0
375/* vm86plus instructions */
f0967a1a 376void helper_cli_vm(CPUX86State *env)
5918fffb
BS
377{
378 env->eflags &= ~VIF_MASK;
379}
380
f0967a1a 381void helper_sti_vm(CPUX86State *env)
5918fffb
BS
382{
383 env->eflags |= VIF_MASK;
384 if (env->eflags & VIP_MASK) {
4054cdec 385 raise_exception_ra(env, EXCP0D_GPF, GETPC());
5918fffb
BS
386 }
387}
388#endif