From mboxrd@z Thu Jan 1 00:00:00 1970 From: Laurent Vivier Subject: [PATCH 1/5] change ctxt.*_base to an array ctxt.base[X86EMUL_BASE_*] Date: Wed, 01 Aug 2007 11:09:42 +0200 Message-ID: <46B04DD6.7010702@bull.net> References: <46B04CCA.2010503@bull.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0873090127==" To: kvm-devel Return-path: In-Reply-To: <46B04CCA.2010503-6ktuUTfB/bM@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --===============0873090127== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig52E467BFC49F22886279CC80" This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig52E467BFC49F22886279CC80 Content-Type: multipart/mixed; boundary="------------060604060009070405070407" This is a multi-part message in MIME format. --------------060604060009070405070407 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable To be able to extract easily prefix decoding from x86_emulate_memop(), ch= ange ctxt.*_base to an array ctxt.base[X86EMUL_BASE_*] Signed-off-by: Laurent Vivier --=20 ------------- Laurent.Vivier-6ktuUTfB/bM@public.gmane.org -------------- "Software is hard" - Donald Knuth --------------060604060009070405070407 Content-Type: text/plain; name="x86_ctxt_segment_array" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="x86_ctxt_segment_array" Index: kvm/drivers/kvm/kvm_main.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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; =20 if (emulate_ctxt.mode =3D=3D X86EMUL_MODE_PROT64) { - emulate_ctxt.cs_base =3D 0; - emulate_ctxt.ds_base =3D 0; - emulate_ctxt.es_base =3D 0; - emulate_ctxt.ss_base =3D 0; + emulate_ctxt.base[X86EMUL_BASE_CS] =3D 0; + emulate_ctxt.base[X86EMUL_BASE_DS] =3D 0; + emulate_ctxt.base[X86EMUL_BASE_ES] =3D 0; + emulate_ctxt.base[X86EMUL_BASE_SS] =3D 0; } else { - emulate_ctxt.cs_base =3D get_segment_base(vcpu, VCPU_SREG_CS); - emulate_ctxt.ds_base =3D get_segment_base(vcpu, VCPU_SREG_DS); - emulate_ctxt.es_base =3D get_segment_base(vcpu, VCPU_SREG_ES); - emulate_ctxt.ss_base =3D get_segment_base(vcpu, VCPU_SREG_SS); + emulate_ctxt.base[X86EMUL_BASE_CS] =3D + get_segment_base(vcpu, VCPU_SREG_CS); + emulate_ctxt.base[X86EMUL_BASE_DS] =3D + get_segment_base(vcpu, VCPU_SREG_DS); + emulate_ctxt.base[X86EMUL_BASE_ES] =3D + get_segment_base(vcpu, VCPU_SREG_ES); + emulate_ctxt.base[X86EMUL_BASE_SS] =3D + get_segment_base(vcpu, VCPU_SREG_SS); } =20 - emulate_ctxt.gs_base =3D get_segment_base(vcpu, VCPU_SREG_GS); - emulate_ctxt.fs_base =3D get_segment_base(vcpu, VCPU_SREG_FS); + emulate_ctxt.base[X86EMUL_BASE_GS] =3D + get_segment_base(vcpu, VCPU_SREG_GS); + emulate_ctxt.base[X86EMUL_BASE_FS] =3D + get_segment_base(vcpu, VCPU_SREG_FS); =20 vcpu->mmio_is_write =3D 0; r =3D x86_emulate_memop(&emulate_ctxt, &emulate_ops); Index: kvm/drivers/kvm/x86_emulate.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- kvm.orig/drivers/kvm/x86_emulate.c 2007-07-31 15:09:01.000000000 +020= 0 +++ 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 =3D ops->read_std((unsigned long)(_eip) + ctxt->cs_base, &_x, \ + rc =3D ops->read_std((unsigned long)(_eip) + \ + ctxt->base[X86EMUL_BASE_CS], &_x, \ (_size), ctxt->vcpu); = \ if ( rc !=3D 0 ) \ goto done; \ @@ -484,7 +485,7 @@ unsigned d; u8 b, sib, twobyte =3D 0, rex_prefix =3D 0; u8 modrm, modrm_mod =3D 0, modrm_reg =3D 0, modrm_rm =3D 0; - unsigned long *override_base =3D NULL; + int override_base =3D -1; unsigned int op_bytes, ad_bytes, lock_prefix =3D 0, rep_prefix =3D 0, i= ; int rc =3D 0; struct operand src, dst; @@ -533,22 +534,22 @@ ad_bytes ^=3D 6; /* switch between 2/4 bytes */ break; case 0x2e: /* CS override */ - override_base =3D &ctxt->cs_base; + override_base =3D X86EMUL_BASE_CS; break; case 0x3e: /* DS override */ - override_base =3D &ctxt->ds_base; + override_base =3D X86EMUL_BASE_DS; break; case 0x26: /* ES override */ - override_base =3D &ctxt->es_base; + override_base =3D X86EMUL_BASE_ES; break; case 0x64: /* FS override */ - override_base =3D &ctxt->fs_base; + override_base =3D X86EMUL_BASE_FS; break; case 0x65: /* GS override */ - override_base =3D &ctxt->gs_base; + override_base =3D X86EMUL_BASE_GS; break; case 0x36: /* SS override */ - override_base =3D &ctxt->ss_base; + override_base =3D X86EMUL_BASE_SS; break; case 0xf0: /* LOCK */ lock_prefix =3D 1; @@ -654,8 +655,8 @@ } if (modrm_rm =3D=3D 2 || modrm_rm =3D=3D 3 || (modrm_rm =3D=3D 6 && modrm_mod !=3D 0)) - if (!override_base) - override_base =3D &ctxt->ss_base; + if (override_base =3D=3D -1) + override_base =3D X86EMUL_BASE_SS; modrm_ea =3D (u16)modrm_ea; } else { /* 32/64-bit ModR/M decode. */ @@ -708,15 +709,15 @@ break; } } - if (!override_base) - override_base =3D &ctxt->ds_base; + if (override_base =3D=3D -1) + override_base =3D X86EMUL_BASE_DS; if (mode =3D=3D X86EMUL_MODE_PROT64 && - override_base !=3D &ctxt->fs_base && - override_base !=3D &ctxt->gs_base) - override_base =3D NULL; + override_base !=3D X86EMUL_BASE_FS && + override_base !=3D X86EMUL_BASE_GS) + override_base =3D -1; =20 - if (override_base) - modrm_ea +=3D *override_base; + if (override_base !=3D -1) + modrm_ea +=3D ctxt->base[override_base]; =20 if (rip_relative) { modrm_ea +=3D _eip; @@ -963,8 +964,9 @@ /* 64-bit mode: POP always pops a 64-bit operand. */ if (mode =3D=3D X86EMUL_MODE_PROT64) dst.bytes =3D 8; - if ((rc =3D ops->read_std(register_address(ctxt->ss_base, - _regs[VCPU_REGS_RSP]), + if ((rc =3D ops->read_std( + register_address(ctxt->base[X86EMUL_BASE_SS], + _regs[VCPU_REGS_RSP]), &dst.val, dst.bytes, ctxt->vcpu)) !=3D 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 =3D 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)) !=3D 0) goto done; no_wb =3D 1; @@ -1128,10 +1130,12 @@ case 0xa4 ... 0xa5: /* movs */ dst.type =3D OP_MEM; dst.bytes =3D (d & ByteOp) ? 1 : op_bytes; - dst.ptr =3D (unsigned long *)register_address(ctxt->es_base, + dst.ptr =3D (unsigned long *)register_address( + ctxt->base[X86EMUL_BASE_ES], _regs[VCPU_REGS_RDI]); if ((rc =3D ops->read_emulated(register_address( - override_base ? *override_base : ctxt->ds_base, + (override_base !=3D -1) ? + ctxt->base[override_base] : ctxt->base[X86EMUL_BASE_DS], _regs[VCPU_REGS_RSI]), &dst.val, dst.bytes, ctxt->vcpu)) !=3D 0)= goto done; register_address_increment(_regs[VCPU_REGS_RSI], @@ -1173,7 +1177,8 @@ dst.ptr =3D (unsigned long *)&_regs[b & 0x7]; =20 pop_instruction: - if ((rc =3D ops->read_std(register_address(ctxt->ss_base, + if ((rc =3D ops->read_std( + register_address(ctxt->base[X86EMUL_BASE_SS], _regs[VCPU_REGS_RSP]), dst.ptr, op_bytes, ctxt->vcpu)) !=3D 0) goto done; Index: kvm/drivers/kvm/x86_emulate.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- kvm.orig/drivers/kvm/x86_emulate.h 2007-07-31 15:09:01.000000000 +020= 0 +++ kvm/drivers/kvm/x86_emulate.h 2007-07-31 17:00:22.000000000 +0200 @@ -112,6 +112,16 @@ =20 }; =20 +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 @@ =20 /* 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]; }; =20 /* Execution mode, passed to the emulator. */ --------------060604060009070405070407-- --------------enig52E467BFC49F22886279CC80 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.7 (GNU/Linux) iD8DBQFGsE3W9Kffa9pFVzwRAlgEAJ0Q0+E0b6oa8dr8FAnuM/5dJKbH4ACeMOSI nsGZ1O5fjq2D/7wsfyfkAwo= =aMap -----END PGP SIGNATURE----- --------------enig52E467BFC49F22886279CC80-- --===============0873090127== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- 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/ --===============0873090127== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/kvm-devel --===============0873090127==--