diff options
author | Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> | 2010-02-12 01:57:56 -0500 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-04-25 05:27:46 -0400 |
commit | 1b30eaa84609031c06e417eafd5b68f45e4266f7 (patch) | |
tree | b5c38cbfb875cf7cb8c7bf3bd023892bc1692ef9 /arch/x86/kvm/emulate.c | |
parent | 3e2815e9fa6c06bcb8a9340e43008bbe48437d25 (diff) |
KVM: x86 emulator: X86EMUL macro replacements: x86_emulate_insn() and its helpers
This patch just replaces integer values used inside
x86_emulate_insn() and its helper functions to X86EMUL_*.
The purpose of this is to make it clear what will happen
when the variable rc is compared to X86EMUL_* at the end
of x86_emulate_insn().
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/emulate.c')
-rw-r--r-- | arch/x86/kvm/emulate.c | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index b8aed35ab5f9..ee1a2a2c12e9 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c | |||
@@ -702,7 +702,7 @@ static int read_descriptor(struct x86_emulate_ctxt *ctxt, | |||
702 | *address = 0; | 702 | *address = 0; |
703 | rc = ops->read_std((unsigned long)ptr, (unsigned long *)size, 2, | 703 | rc = ops->read_std((unsigned long)ptr, (unsigned long *)size, 2, |
704 | ctxt->vcpu, NULL); | 704 | ctxt->vcpu, NULL); |
705 | if (rc) | 705 | if (rc != X86EMUL_CONTINUE) |
706 | return rc; | 706 | return rc; |
707 | rc = ops->read_std((unsigned long)ptr + 2, address, op_bytes, | 707 | rc = ops->read_std((unsigned long)ptr + 2, address, op_bytes, |
708 | ctxt->vcpu, NULL); | 708 | ctxt->vcpu, NULL); |
@@ -1301,7 +1301,7 @@ static int emulate_pop_sreg(struct x86_emulate_ctxt *ctxt, | |||
1301 | int rc; | 1301 | int rc; |
1302 | 1302 | ||
1303 | rc = emulate_pop(ctxt, ops, &selector, c->op_bytes); | 1303 | rc = emulate_pop(ctxt, ops, &selector, c->op_bytes); |
1304 | if (rc != 0) | 1304 | if (rc != X86EMUL_CONTINUE) |
1305 | return rc; | 1305 | return rc; |
1306 | 1306 | ||
1307 | rc = kvm_load_segment_descriptor(ctxt->vcpu, (u16)selector, seg); | 1307 | rc = kvm_load_segment_descriptor(ctxt->vcpu, (u16)selector, seg); |
@@ -1327,7 +1327,7 @@ static int emulate_popa(struct x86_emulate_ctxt *ctxt, | |||
1327 | struct x86_emulate_ops *ops) | 1327 | struct x86_emulate_ops *ops) |
1328 | { | 1328 | { |
1329 | struct decode_cache *c = &ctxt->decode; | 1329 | struct decode_cache *c = &ctxt->decode; |
1330 | int rc = 0; | 1330 | int rc = X86EMUL_CONTINUE; |
1331 | int reg = VCPU_REGS_RDI; | 1331 | int reg = VCPU_REGS_RDI; |
1332 | 1332 | ||
1333 | while (reg >= VCPU_REGS_RAX) { | 1333 | while (reg >= VCPU_REGS_RAX) { |
@@ -1338,7 +1338,7 @@ static int emulate_popa(struct x86_emulate_ctxt *ctxt, | |||
1338 | } | 1338 | } |
1339 | 1339 | ||
1340 | rc = emulate_pop(ctxt, ops, &c->regs[reg], c->op_bytes); | 1340 | rc = emulate_pop(ctxt, ops, &c->regs[reg], c->op_bytes); |
1341 | if (rc != 0) | 1341 | if (rc != X86EMUL_CONTINUE) |
1342 | break; | 1342 | break; |
1343 | --reg; | 1343 | --reg; |
1344 | } | 1344 | } |
@@ -1349,12 +1349,8 @@ static inline int emulate_grp1a(struct x86_emulate_ctxt *ctxt, | |||
1349 | struct x86_emulate_ops *ops) | 1349 | struct x86_emulate_ops *ops) |
1350 | { | 1350 | { |
1351 | struct decode_cache *c = &ctxt->decode; | 1351 | struct decode_cache *c = &ctxt->decode; |
1352 | int rc; | ||
1353 | 1352 | ||
1354 | rc = emulate_pop(ctxt, ops, &c->dst.val, c->dst.bytes); | 1353 | return emulate_pop(ctxt, ops, &c->dst.val, c->dst.bytes); |
1355 | if (rc != 0) | ||
1356 | return rc; | ||
1357 | return 0; | ||
1358 | } | 1354 | } |
1359 | 1355 | ||
1360 | static inline void emulate_grp2(struct x86_emulate_ctxt *ctxt) | 1356 | static inline void emulate_grp2(struct x86_emulate_ctxt *ctxt) |
@@ -1390,7 +1386,7 @@ static inline int emulate_grp3(struct x86_emulate_ctxt *ctxt, | |||
1390 | struct x86_emulate_ops *ops) | 1386 | struct x86_emulate_ops *ops) |
1391 | { | 1387 | { |
1392 | struct decode_cache *c = &ctxt->decode; | 1388 | struct decode_cache *c = &ctxt->decode; |
1393 | int rc = 0; | 1389 | int rc = X86EMUL_CONTINUE; |
1394 | 1390 | ||
1395 | switch (c->modrm_reg) { | 1391 | switch (c->modrm_reg) { |
1396 | case 0 ... 1: /* test */ | 1392 | case 0 ... 1: /* test */ |
@@ -1437,7 +1433,7 @@ static inline int emulate_grp45(struct x86_emulate_ctxt *ctxt, | |||
1437 | emulate_push(ctxt); | 1433 | emulate_push(ctxt); |
1438 | break; | 1434 | break; |
1439 | } | 1435 | } |
1440 | return 0; | 1436 | return X86EMUL_CONTINUE; |
1441 | } | 1437 | } |
1442 | 1438 | ||
1443 | static inline int emulate_grp9(struct x86_emulate_ctxt *ctxt, | 1439 | static inline int emulate_grp9(struct x86_emulate_ctxt *ctxt, |
@@ -1468,7 +1464,7 @@ static inline int emulate_grp9(struct x86_emulate_ctxt *ctxt, | |||
1468 | return rc; | 1464 | return rc; |
1469 | ctxt->eflags |= EFLG_ZF; | 1465 | ctxt->eflags |= EFLG_ZF; |
1470 | } | 1466 | } |
1471 | return 0; | 1467 | return X86EMUL_CONTINUE; |
1472 | } | 1468 | } |
1473 | 1469 | ||
1474 | static int emulate_ret_far(struct x86_emulate_ctxt *ctxt, | 1470 | static int emulate_ret_far(struct x86_emulate_ctxt *ctxt, |
@@ -1479,12 +1475,12 @@ static int emulate_ret_far(struct x86_emulate_ctxt *ctxt, | |||
1479 | unsigned long cs; | 1475 | unsigned long cs; |
1480 | 1476 | ||
1481 | rc = emulate_pop(ctxt, ops, &c->eip, c->op_bytes); | 1477 | rc = emulate_pop(ctxt, ops, &c->eip, c->op_bytes); |
1482 | if (rc) | 1478 | if (rc != X86EMUL_CONTINUE) |
1483 | return rc; | 1479 | return rc; |
1484 | if (c->op_bytes == 4) | 1480 | if (c->op_bytes == 4) |
1485 | c->eip = (u32)c->eip; | 1481 | c->eip = (u32)c->eip; |
1486 | rc = emulate_pop(ctxt, ops, &cs, c->op_bytes); | 1482 | rc = emulate_pop(ctxt, ops, &cs, c->op_bytes); |
1487 | if (rc) | 1483 | if (rc != X86EMUL_CONTINUE) |
1488 | return rc; | 1484 | return rc; |
1489 | rc = kvm_load_segment_descriptor(ctxt->vcpu, (u16)cs, VCPU_SREG_CS); | 1485 | rc = kvm_load_segment_descriptor(ctxt->vcpu, (u16)cs, VCPU_SREG_CS); |
1490 | return rc; | 1486 | return rc; |
@@ -1539,7 +1535,7 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt, | |||
1539 | default: | 1535 | default: |
1540 | break; | 1536 | break; |
1541 | } | 1537 | } |
1542 | return 0; | 1538 | return X86EMUL_CONTINUE; |
1543 | } | 1539 | } |
1544 | 1540 | ||
1545 | static void toggle_interruptibility(struct x86_emulate_ctxt *ctxt, u32 mask) | 1541 | static void toggle_interruptibility(struct x86_emulate_ctxt *ctxt, u32 mask) |
@@ -1811,7 +1807,7 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) | |||
1811 | struct decode_cache *c = &ctxt->decode; | 1807 | struct decode_cache *c = &ctxt->decode; |
1812 | unsigned int port; | 1808 | unsigned int port; |
1813 | int io_dir_in; | 1809 | int io_dir_in; |
1814 | int rc = 0; | 1810 | int rc = X86EMUL_CONTINUE; |
1815 | 1811 | ||
1816 | ctxt->interruptibility = 0; | 1812 | ctxt->interruptibility = 0; |
1817 | 1813 | ||
@@ -1926,7 +1922,7 @@ special_insn: | |||
1926 | break; | 1922 | break; |
1927 | case 0x07: /* pop es */ | 1923 | case 0x07: /* pop es */ |
1928 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_ES); | 1924 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_ES); |
1929 | if (rc != 0) | 1925 | if (rc != X86EMUL_CONTINUE) |
1930 | goto done; | 1926 | goto done; |
1931 | break; | 1927 | break; |
1932 | case 0x08 ... 0x0d: | 1928 | case 0x08 ... 0x0d: |
@@ -1945,7 +1941,7 @@ special_insn: | |||
1945 | break; | 1941 | break; |
1946 | case 0x17: /* pop ss */ | 1942 | case 0x17: /* pop ss */ |
1947 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_SS); | 1943 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_SS); |
1948 | if (rc != 0) | 1944 | if (rc != X86EMUL_CONTINUE) |
1949 | goto done; | 1945 | goto done; |
1950 | break; | 1946 | break; |
1951 | case 0x18 ... 0x1d: | 1947 | case 0x18 ... 0x1d: |
@@ -1957,7 +1953,7 @@ special_insn: | |||
1957 | break; | 1953 | break; |
1958 | case 0x1f: /* pop ds */ | 1954 | case 0x1f: /* pop ds */ |
1959 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_DS); | 1955 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_DS); |
1960 | if (rc != 0) | 1956 | if (rc != X86EMUL_CONTINUE) |
1961 | goto done; | 1957 | goto done; |
1962 | break; | 1958 | break; |
1963 | case 0x20 ... 0x25: | 1959 | case 0x20 ... 0x25: |
@@ -1988,7 +1984,7 @@ special_insn: | |||
1988 | case 0x58 ... 0x5f: /* pop reg */ | 1984 | case 0x58 ... 0x5f: /* pop reg */ |
1989 | pop_instruction: | 1985 | pop_instruction: |
1990 | rc = emulate_pop(ctxt, ops, &c->dst.val, c->op_bytes); | 1986 | rc = emulate_pop(ctxt, ops, &c->dst.val, c->op_bytes); |
1991 | if (rc != 0) | 1987 | if (rc != X86EMUL_CONTINUE) |
1992 | goto done; | 1988 | goto done; |
1993 | break; | 1989 | break; |
1994 | case 0x60: /* pusha */ | 1990 | case 0x60: /* pusha */ |
@@ -1996,7 +1992,7 @@ special_insn: | |||
1996 | break; | 1992 | break; |
1997 | case 0x61: /* popa */ | 1993 | case 0x61: /* popa */ |
1998 | rc = emulate_popa(ctxt, ops); | 1994 | rc = emulate_popa(ctxt, ops); |
1999 | if (rc != 0) | 1995 | if (rc != X86EMUL_CONTINUE) |
2000 | goto done; | 1996 | goto done; |
2001 | break; | 1997 | break; |
2002 | case 0x63: /* movsxd */ | 1998 | case 0x63: /* movsxd */ |
@@ -2141,7 +2137,7 @@ special_insn: | |||
2141 | } | 2137 | } |
2142 | case 0x8f: /* pop (sole member of Grp1a) */ | 2138 | case 0x8f: /* pop (sole member of Grp1a) */ |
2143 | rc = emulate_grp1a(ctxt, ops); | 2139 | rc = emulate_grp1a(ctxt, ops); |
2144 | if (rc != 0) | 2140 | if (rc != X86EMUL_CONTINUE) |
2145 | goto done; | 2141 | goto done; |
2146 | break; | 2142 | break; |
2147 | case 0x90: /* nop / xchg r8,rax */ | 2143 | case 0x90: /* nop / xchg r8,rax */ |
@@ -2277,7 +2273,7 @@ special_insn: | |||
2277 | break; | 2273 | break; |
2278 | case 0xcb: /* ret far */ | 2274 | case 0xcb: /* ret far */ |
2279 | rc = emulate_ret_far(ctxt, ops); | 2275 | rc = emulate_ret_far(ctxt, ops); |
2280 | if (rc) | 2276 | if (rc != X86EMUL_CONTINUE) |
2281 | goto done; | 2277 | goto done; |
2282 | break; | 2278 | break; |
2283 | case 0xd0 ... 0xd1: /* Grp2 */ | 2279 | case 0xd0 ... 0xd1: /* Grp2 */ |
@@ -2351,7 +2347,7 @@ special_insn: | |||
2351 | break; | 2347 | break; |
2352 | case 0xf6 ... 0xf7: /* Grp3 */ | 2348 | case 0xf6 ... 0xf7: /* Grp3 */ |
2353 | rc = emulate_grp3(ctxt, ops); | 2349 | rc = emulate_grp3(ctxt, ops); |
2354 | if (rc != 0) | 2350 | if (rc != X86EMUL_CONTINUE) |
2355 | goto done; | 2351 | goto done; |
2356 | break; | 2352 | break; |
2357 | case 0xf8: /* clc */ | 2353 | case 0xf8: /* clc */ |
@@ -2385,14 +2381,14 @@ special_insn: | |||
2385 | break; | 2381 | break; |
2386 | case 0xfe ... 0xff: /* Grp4/Grp5 */ | 2382 | case 0xfe ... 0xff: /* Grp4/Grp5 */ |
2387 | rc = emulate_grp45(ctxt, ops); | 2383 | rc = emulate_grp45(ctxt, ops); |
2388 | if (rc != 0) | 2384 | if (rc != X86EMUL_CONTINUE) |
2389 | goto done; | 2385 | goto done; |
2390 | break; | 2386 | break; |
2391 | } | 2387 | } |
2392 | 2388 | ||
2393 | writeback: | 2389 | writeback: |
2394 | rc = writeback(ctxt, ops); | 2390 | rc = writeback(ctxt, ops); |
2395 | if (rc != 0) | 2391 | if (rc != X86EMUL_CONTINUE) |
2396 | goto done; | 2392 | goto done; |
2397 | 2393 | ||
2398 | /* Commit shadow register state. */ | 2394 | /* Commit shadow register state. */ |
@@ -2418,7 +2414,7 @@ twobyte_insn: | |||
2418 | goto cannot_emulate; | 2414 | goto cannot_emulate; |
2419 | 2415 | ||
2420 | rc = kvm_fix_hypercall(ctxt->vcpu); | 2416 | rc = kvm_fix_hypercall(ctxt->vcpu); |
2421 | if (rc) | 2417 | if (rc != X86EMUL_CONTINUE) |
2422 | goto done; | 2418 | goto done; |
2423 | 2419 | ||
2424 | /* Let the processor re-execute the fixed hypercall */ | 2420 | /* Let the processor re-execute the fixed hypercall */ |
@@ -2429,7 +2425,7 @@ twobyte_insn: | |||
2429 | case 2: /* lgdt */ | 2425 | case 2: /* lgdt */ |
2430 | rc = read_descriptor(ctxt, ops, c->src.ptr, | 2426 | rc = read_descriptor(ctxt, ops, c->src.ptr, |
2431 | &size, &address, c->op_bytes); | 2427 | &size, &address, c->op_bytes); |
2432 | if (rc) | 2428 | if (rc != X86EMUL_CONTINUE) |
2433 | goto done; | 2429 | goto done; |
2434 | realmode_lgdt(ctxt->vcpu, size, address); | 2430 | realmode_lgdt(ctxt->vcpu, size, address); |
2435 | /* Disable writeback. */ | 2431 | /* Disable writeback. */ |
@@ -2440,7 +2436,7 @@ twobyte_insn: | |||
2440 | switch (c->modrm_rm) { | 2436 | switch (c->modrm_rm) { |
2441 | case 1: | 2437 | case 1: |
2442 | rc = kvm_fix_hypercall(ctxt->vcpu); | 2438 | rc = kvm_fix_hypercall(ctxt->vcpu); |
2443 | if (rc) | 2439 | if (rc != X86EMUL_CONTINUE) |
2444 | goto done; | 2440 | goto done; |
2445 | break; | 2441 | break; |
2446 | default: | 2442 | default: |
@@ -2450,7 +2446,7 @@ twobyte_insn: | |||
2450 | rc = read_descriptor(ctxt, ops, c->src.ptr, | 2446 | rc = read_descriptor(ctxt, ops, c->src.ptr, |
2451 | &size, &address, | 2447 | &size, &address, |
2452 | c->op_bytes); | 2448 | c->op_bytes); |
2453 | if (rc) | 2449 | if (rc != X86EMUL_CONTINUE) |
2454 | goto done; | 2450 | goto done; |
2455 | realmode_lidt(ctxt->vcpu, size, address); | 2451 | realmode_lidt(ctxt->vcpu, size, address); |
2456 | } | 2452 | } |
@@ -2577,7 +2573,7 @@ twobyte_insn: | |||
2577 | break; | 2573 | break; |
2578 | case 0xa1: /* pop fs */ | 2574 | case 0xa1: /* pop fs */ |
2579 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_FS); | 2575 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_FS); |
2580 | if (rc != 0) | 2576 | if (rc != X86EMUL_CONTINUE) |
2581 | goto done; | 2577 | goto done; |
2582 | break; | 2578 | break; |
2583 | case 0xa3: | 2579 | case 0xa3: |
@@ -2596,7 +2592,7 @@ twobyte_insn: | |||
2596 | break; | 2592 | break; |
2597 | case 0xa9: /* pop gs */ | 2593 | case 0xa9: /* pop gs */ |
2598 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_GS); | 2594 | rc = emulate_pop_sreg(ctxt, ops, VCPU_SREG_GS); |
2599 | if (rc != 0) | 2595 | if (rc != X86EMUL_CONTINUE) |
2600 | goto done; | 2596 | goto done; |
2601 | break; | 2597 | break; |
2602 | case 0xab: | 2598 | case 0xab: |
@@ -2669,7 +2665,7 @@ twobyte_insn: | |||
2669 | break; | 2665 | break; |
2670 | case 0xc7: /* Grp9 (cmpxchg8b) */ | 2666 | case 0xc7: /* Grp9 (cmpxchg8b) */ |
2671 | rc = emulate_grp9(ctxt, ops, memop); | 2667 | rc = emulate_grp9(ctxt, ops, memop); |
2672 | if (rc != 0) | 2668 | if (rc != X86EMUL_CONTINUE) |
2673 | goto done; | 2669 | goto done; |
2674 | c->dst.type = OP_NONE; | 2670 | c->dst.type = OP_NONE; |
2675 | break; | 2671 | break; |