From: Bastian Blank Subject: [RFC][PATCH] Emulate instructions in vm86 mode Date: Thu, 7 Sep 2006 11:51:04 +0200 Message-ID: <20060907095104.GA23514@wavehammer.waldi.eu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1349069009==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============1349069009== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="xXmbgvnjoT4axfJE" Content-Disposition: inline --xXmbgvnjoT4axfJE Content-Type: multipart/mixed; boundary="cWoXeonUoKmBZSoM" Content-Disposition: inline --cWoXeonUoKmBZSoM Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi folks This patch fixes the emulation of instructions in vm86 mode. It fetches them using cs and eip instead of only eip. This makes it at least possible to use the i945GM vesa bios from the running system. I'm not sure if this is the correct fix or if we should call the gpf handler of the running system. At least the support in linux reports traps back to the userspace caller which is not possible if emulated in xen. Signed-off-by: Bastian Blank Bastian --=20 Not one hundred percent efficient, of course ... but nothing ever is. -- Kirk, "Metamorphosis", stardate 3219.8 --cWoXeonUoKmBZSoM Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename=diff Content-Transfer-Encoding: quoted-printable #! /bin/sh /usr/share/dpatch/dpatch-run ## vm86-support.dpatch by Bastian Blank ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: No description. @DPATCH@ diff -urNad xen-unstable~/xen/arch/x86/traps.c xen-unstable/xen/arch/x86/tr= aps.c --- xen-unstable~/xen/arch/x86/traps.c 2006-08-30 18:36:52.000000000 +0200 +++ xen-unstable/xen/arch/x86/traps.c 2006-09-07 01:27:22.000000000 +0200 @@ -1015,9 +1015,11 @@ (admin_io_okay(_p, 4, _d, _r) ? outl(_v, _p) : ((void)0)) =20 /* Instruction fetch with error handling. */ -#define insn_fetch(_type, _size, _ptr) = \ -({ unsigned long _rc, _x; = \ - if ( (_rc =3D copy_from_user(&_x, (_type *)eip, sizeof(_type))) !=3D 0= ) \ +#define insn_fetch(_type, _size, cs, eip) = \ +({ unsigned long _rc, _x, _ptr =3D eip; = \ + if ( vm86_mode(regs) ) = \ + _ptr +=3D cs << 4; = \ + if ( (_rc =3D copy_from_user(&_x, (_type *)_ptr, sizeof(_type))) !=3D = 0 ) \ { = \ propagate_page_fault(eip + sizeof(_type) - _rc, 0); = \ return EXCRET_fault_fixed; = \ @@ -1027,7 +1029,7 @@ static int emulate_privileged_op(struct cpu_user_regs *regs) { struct vcpu *v =3D current; - unsigned long *reg, eip =3D regs->eip, res; + unsigned long *reg, eip =3D regs->eip, cs =3D regs->cs, res; u8 opcode, modrm_reg =3D 0, modrm_rm =3D 0, rep_prefix =3D 0; unsigned int port, i, op_bytes =3D 4, data, rc; u32 l, h; @@ -1035,7 +1037,7 @@ /* Legacy prefixes. */ for ( i =3D 0; i < 8; i++ ) { - switch ( opcode =3D insn_fetch(u8, 1, eip) ) + switch ( opcode =3D insn_fetch(u8, 1, cs, eip) ) { case 0x66: /* operand-size override */ op_bytes ^=3D 6; /* switch between 2/4 bytes */ @@ -1067,7 +1069,7 @@ modrm_rm =3D (opcode & 1) << 3; /* REX.B */ =20 /* REX.W and REX.X do not need to be decoded. */ - opcode =3D insn_fetch(u8, 1, eip); + opcode =3D insn_fetch(u8, 1, cs, eip); } #endif =20 @@ -1149,7 +1151,7 @@ case 0xe4: /* IN imm8,%al */ op_bytes =3D 1; case 0xe5: /* IN imm8,%eax */ - port =3D insn_fetch(u8, 1, eip); + port =3D insn_fetch(u8, 1, cs, eip); exec_in: if ( !guest_io_okay(port, op_bytes, v, regs) ) goto fail; @@ -1178,7 +1180,7 @@ case 0xe6: /* OUT %al,imm8 */ op_bytes =3D 1; case 0xe7: /* OUT %eax,imm8 */ - port =3D insn_fetch(u8, 1, eip); + port =3D insn_fetch(u8, 1, cs, eip); exec_out: if ( !guest_io_okay(port, op_bytes, v, regs) ) goto fail; @@ -1227,7 +1229,7 @@ goto fail; =20 /* Privileged (ring 0) instructions. */ - opcode =3D insn_fetch(u8, 1, eip); + opcode =3D insn_fetch(u8, 1, cs, eip); switch ( opcode ) { case 0x06: /* CLTS */ @@ -1245,7 +1247,7 @@ break; =20 case 0x20: /* MOV CR?, */ - opcode =3D insn_fetch(u8, 1, eip); + opcode =3D insn_fetch(u8, 1, cs, eip); modrm_reg |=3D (opcode >> 3) & 7; modrm_rm |=3D (opcode >> 0) & 7; reg =3D decode_register(modrm_rm, regs, 0); @@ -1279,7 +1281,7 @@ break; =20 case 0x21: /* MOV DR?, */ - opcode =3D insn_fetch(u8, 1, eip); + opcode =3D insn_fetch(u8, 1, cs, eip); modrm_reg |=3D (opcode >> 3) & 7; modrm_rm |=3D (opcode >> 0) & 7; reg =3D decode_register(modrm_rm, regs, 0); @@ -1289,7 +1291,7 @@ break; =20 case 0x22: /* MOV ,CR? */ - opcode =3D insn_fetch(u8, 1, eip); + opcode =3D insn_fetch(u8, 1, cs, eip); modrm_reg |=3D (opcode >> 3) & 7; modrm_rm |=3D (opcode >> 0) & 7; reg =3D decode_register(modrm_rm, regs, 0); @@ -1329,7 +1331,7 @@ break; =20 case 0x23: /* MOV ,DR? */ - opcode =3D insn_fetch(u8, 1, eip); + opcode =3D insn_fetch(u8, 1, cs, eip); modrm_reg |=3D (opcode >> 3) & 7; modrm_rm |=3D (opcode >> 0) & 7; reg =3D decode_register(modrm_rm, regs, 0); --cWoXeonUoKmBZSoM-- --xXmbgvnjoT4axfJE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) iEYEARECAAYFAkT/64gACgkQnw66O/MvCNFK0ACfTbDp8kRyhXI7yDF1umjIkqhv EmAAoKkOZF/ghq6P4qDiHgIi+wxH5hex =jQse -----END PGP SIGNATURE----- --xXmbgvnjoT4axfJE-- --===============1349069009== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1349069009==--