To be able to extract easily prefix decoding from x86_emulate_memop(), change
ctxt.*_base to an array ctxt.base[X86EMUL_BASE_*]

Signed-off-by: Laurent Vivier <[EMAIL PROTECTED]>
-- 
------------- [EMAIL PROTECTED]  --------------
          "Software is hard" - Donald Knuth
Index: kvm/drivers/kvm/kvm_main.c
===================================================================
--- kvm.orig/drivers/kvm/kvm_main.c     2007-07-31 15:09:01.000000000 +0200
+++ kvm/drivers/kvm/kvm_main.c  2007-07-31 15:12:47.000000000 +0200
@@ -1236,19 +1236,25 @@
                ? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16;
 
        if (emulate_ctxt.mode == X86EMUL_MODE_PROT64) {
-               emulate_ctxt.cs_base = 0;
-               emulate_ctxt.ds_base = 0;
-               emulate_ctxt.es_base = 0;
-               emulate_ctxt.ss_base = 0;
+               emulate_ctxt.base[X86EMUL_BASE_CS] = 0;
+               emulate_ctxt.base[X86EMUL_BASE_DS] = 0;
+               emulate_ctxt.base[X86EMUL_BASE_ES] = 0;
+               emulate_ctxt.base[X86EMUL_BASE_SS] = 0;
        } else {
-               emulate_ctxt.cs_base = get_segment_base(vcpu, VCPU_SREG_CS);
-               emulate_ctxt.ds_base = get_segment_base(vcpu, VCPU_SREG_DS);
-               emulate_ctxt.es_base = get_segment_base(vcpu, VCPU_SREG_ES);
-               emulate_ctxt.ss_base = get_segment_base(vcpu, VCPU_SREG_SS);
+               emulate_ctxt.base[X86EMUL_BASE_CS] =
+                                       get_segment_base(vcpu, VCPU_SREG_CS);
+               emulate_ctxt.base[X86EMUL_BASE_DS] =
+                                       get_segment_base(vcpu, VCPU_SREG_DS);
+               emulate_ctxt.base[X86EMUL_BASE_ES] =
+                                       get_segment_base(vcpu, VCPU_SREG_ES);
+               emulate_ctxt.base[X86EMUL_BASE_SS] =
+                                       get_segment_base(vcpu, VCPU_SREG_SS);
        }
 
-       emulate_ctxt.gs_base = get_segment_base(vcpu, VCPU_SREG_GS);
-       emulate_ctxt.fs_base = get_segment_base(vcpu, VCPU_SREG_FS);
+       emulate_ctxt.base[X86EMUL_BASE_GS] =
+                                       get_segment_base(vcpu, VCPU_SREG_GS);
+       emulate_ctxt.base[X86EMUL_BASE_FS] =
+                                       get_segment_base(vcpu, VCPU_SREG_FS);
 
        vcpu->mmio_is_write = 0;
        r = x86_emulate_memop(&emulate_ctxt, &emulate_ops);
Index: kvm/drivers/kvm/x86_emulate.c
===================================================================
--- kvm.orig/drivers/kvm/x86_emulate.c  2007-07-31 15:09:01.000000000 +0200
+++ kvm/drivers/kvm/x86_emulate.c       2007-07-31 17:01:52.000000000 +0200
@@ -419,7 +419,8 @@
 /* Fetch next part of the instruction being emulated. */
 #define insn_fetch(_type, _size, _eip)                                  \
 ({     unsigned long _x;                                               \
-       rc = ops->read_std((unsigned long)(_eip) + ctxt->cs_base, &_x,  \
+       rc = ops->read_std((unsigned long)(_eip) +                      \
+                          ctxt->base[X86EMUL_BASE_CS], &_x,            \
                                                   (_size), ctxt->vcpu); \
        if ( rc != 0 )                                                  \
                goto done;                                              \
@@ -484,7 +485,7 @@
        unsigned d;
        u8 b, sib, twobyte = 0, rex_prefix = 0;
        u8 modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
-       unsigned long *override_base = NULL;
+       int override_base = -1;
        unsigned int op_bytes, ad_bytes, lock_prefix = 0, rep_prefix = 0, i;
        int rc = 0;
        struct operand src, dst;
@@ -533,22 +534,22 @@
                                ad_bytes ^= 6;  /* switch between 2/4 bytes */
                        break;
                case 0x2e:      /* CS override */
-                       override_base = &ctxt->cs_base;
+                       override_base = X86EMUL_BASE_CS;
                        break;
                case 0x3e:      /* DS override */
-                       override_base = &ctxt->ds_base;
+                       override_base = X86EMUL_BASE_DS;
                        break;
                case 0x26:      /* ES override */
-                       override_base = &ctxt->es_base;
+                       override_base = X86EMUL_BASE_ES;
                        break;
                case 0x64:      /* FS override */
-                       override_base = &ctxt->fs_base;
+                       override_base = X86EMUL_BASE_FS;
                        break;
                case 0x65:      /* GS override */
-                       override_base = &ctxt->gs_base;
+                       override_base = X86EMUL_BASE_GS;
                        break;
                case 0x36:      /* SS override */
-                       override_base = &ctxt->ss_base;
+                       override_base = X86EMUL_BASE_SS;
                        break;
                case 0xf0:      /* LOCK */
                        lock_prefix = 1;
@@ -654,8 +655,8 @@
                        }
                        if (modrm_rm == 2 || modrm_rm == 3 ||
                            (modrm_rm == 6 && modrm_mod != 0))
-                               if (!override_base)
-                                       override_base = &ctxt->ss_base;
+                               if (override_base == -1)
+                                       override_base = X86EMUL_BASE_SS;
                        modrm_ea = (u16)modrm_ea;
                } else {
                        /* 32/64-bit ModR/M decode. */
@@ -708,15 +709,15 @@
                                break;
                        }
                }
-               if (!override_base)
-                       override_base = &ctxt->ds_base;
+               if (override_base == -1)
+                       override_base = X86EMUL_BASE_DS;
                if (mode == X86EMUL_MODE_PROT64 &&
-                   override_base != &ctxt->fs_base &&
-                   override_base != &ctxt->gs_base)
-                       override_base = NULL;
+                   override_base != X86EMUL_BASE_FS &&
+                   override_base != X86EMUL_BASE_GS)
+                       override_base = -1;
 
-               if (override_base)
-                       modrm_ea += *override_base;
+               if (override_base != -1)
+                       modrm_ea += ctxt->base[override_base];
 
                if (rip_relative) {
                        modrm_ea += _eip;
@@ -963,8 +964,9 @@
                /* 64-bit mode: POP always pops a 64-bit operand. */
                if (mode == X86EMUL_MODE_PROT64)
                        dst.bytes = 8;
-               if ((rc = ops->read_std(register_address(ctxt->ss_base,
-                                                        _regs[VCPU_REGS_RSP]),
+               if ((rc = ops->read_std(
+                               register_address(ctxt->base[X86EMUL_BASE_SS],
+                                       _regs[VCPU_REGS_RSP]),
                                        &dst.val, dst.bytes, ctxt->vcpu)) != 0)
                        goto done;
                register_address_increment(_regs[VCPU_REGS_RSP], dst.bytes);
@@ -1056,8 +1058,8 @@
                        register_address_increment(_regs[VCPU_REGS_RSP],
                                                   -dst.bytes);
                        if ((rc = ops->write_std(
-                                    register_address(ctxt->ss_base,
-                                                     _regs[VCPU_REGS_RSP]),
+                               register_address(ctxt->base[X86EMUL_BASE_SS],
+                                                _regs[VCPU_REGS_RSP]),
                                     &dst.val, dst.bytes, ctxt->vcpu)) != 0)
                                goto done;
                        no_wb = 1;
@@ -1128,10 +1130,12 @@
        case 0xa4 ... 0xa5:     /* movs */
                dst.type = OP_MEM;
                dst.bytes = (d & ByteOp) ? 1 : op_bytes;
-               dst.ptr = (unsigned long *)register_address(ctxt->es_base,
+               dst.ptr = (unsigned long *)register_address(
+                                               ctxt->base[X86EMUL_BASE_ES],
                                                        _regs[VCPU_REGS_RDI]);
                if ((rc = ops->read_emulated(register_address(
-                     override_base ? *override_base : ctxt->ds_base,
+                     (override_base != -1) ?
+                       ctxt->base[override_base] : ctxt->base[X86EMUL_BASE_DS],
                      _regs[VCPU_REGS_RSI]), &dst.val, dst.bytes, ctxt->vcpu)) 
!= 0)
                        goto done;
                register_address_increment(_regs[VCPU_REGS_RSI],
@@ -1173,7 +1177,8 @@
                dst.ptr = (unsigned long *)&_regs[b & 0x7];
 
 pop_instruction:
-               if ((rc = ops->read_std(register_address(ctxt->ss_base,
+               if ((rc = ops->read_std(
+                       register_address(ctxt->base[X86EMUL_BASE_SS],
                        _regs[VCPU_REGS_RSP]), dst.ptr, op_bytes, ctxt->vcpu))
                        != 0)
                        goto done;
Index: kvm/drivers/kvm/x86_emulate.h
===================================================================
--- kvm.orig/drivers/kvm/x86_emulate.h  2007-07-31 15:09:01.000000000 +0200
+++ kvm/drivers/kvm/x86_emulate.h       2007-07-31 17:00:22.000000000 +0200
@@ -112,6 +112,16 @@
 
 };
 
+enum {
+       X86EMUL_BASE_CS,
+       X86EMUL_BASE_DS,
+       X86EMUL_BASE_ES,
+       X86EMUL_BASE_SS,
+       X86EMUL_BASE_GS,
+       X86EMUL_BASE_FS,
+       X86EMUL_BASE_SIZE
+};
+
 struct x86_emulate_ctxt {
        /* Register state before/after emulation. */
        struct kvm_vcpu *vcpu;
@@ -122,13 +132,7 @@
 
        /* Emulated execution mode, represented by an X86EMUL_MODE value. */
        int mode;
-
-       unsigned long cs_base;
-       unsigned long ds_base;
-       unsigned long es_base;
-       unsigned long ss_base;
-       unsigned long gs_base;
-       unsigned long fs_base;
+       unsigned long base[X86EMUL_BASE_SIZE];
 };
 
 /* Execution mode, passed to the emulator. */

Attachment: signature.asc
Description: OpenPGP digital signature

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

Reply via email to