From owner-svn-src-all@FreeBSD.ORG Tue Apr 15 15:11:11 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A616560A; Tue, 15 Apr 2014 15:11:11 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7911E16AE; Tue, 15 Apr 2014 15:11:11 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3FFBB4G087670; Tue, 15 Apr 2014 15:11:11 GMT (envelope-from tychon@svn.freebsd.org) Received: (from tychon@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3FFBBIW087669; Tue, 15 Apr 2014 15:11:11 GMT (envelope-from tychon@svn.freebsd.org) Message-Id: <201404151511.s3FFBBIW087669@svn.freebsd.org> From: Tycho Nightingale Date: Tue, 15 Apr 2014 15:11:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264501 - head/sys/amd64/vmm X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Apr 2014 15:11:11 -0000 Author: tychon Date: Tue Apr 15 15:11:10 2014 New Revision: 264501 URL: http://svnweb.freebsd.org/changeset/base/264501 Log: Add support for emulating the byte move and sign extend instructions: "movsx r/m8, r32" and "movsx r/m8, r64". Approved by: grehan (co-mentor) Modified: head/sys/amd64/vmm/vmm_instruction_emul.c Modified: head/sys/amd64/vmm/vmm_instruction_emul.c ============================================================================== --- head/sys/amd64/vmm/vmm_instruction_emul.c Tue Apr 15 14:55:56 2014 (r264500) +++ head/sys/amd64/vmm/vmm_instruction_emul.c Tue Apr 15 15:11:10 2014 (r264501) @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); enum { VIE_OP_TYPE_NONE = 0, VIE_OP_TYPE_MOV, + VIE_OP_TYPE_MOVSX, VIE_OP_TYPE_MOVZX, VIE_OP_TYPE_AND, VIE_OP_TYPE_OR, @@ -69,6 +70,10 @@ static const struct vie_op two_byte_opco .op_byte = 0xB6, .op_type = VIE_OP_TYPE_MOVZX, }, + [0xBE] = { + .op_byte = 0xBE, + .op_type = VIE_OP_TYPE_MOVSX, + }, }; static const struct vie_op one_byte_opcodes[256] = { @@ -333,9 +338,9 @@ emulate_mov(void *vm, int vcpuid, uint64 * - address size override is not supported */ static int -emulate_movzx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie, - mem_region_read_t memread, mem_region_write_t memwrite, - void *arg) +emulate_movx(void *vm, int vcpuid, uint64_t gpa, struct vie *vie, + mem_region_read_t memread, mem_region_write_t memwrite, + void *arg) { int error, size; enum vm_reg_name reg; @@ -368,6 +373,32 @@ emulate_movzx(void *vm, int vcpuid, uint /* write the result */ error = vie_update_register(vm, vcpuid, reg, val, size); break; + case 0xBE: + /* + * MOV and sign extend byte from mem (ModRM:r/m) to + * reg (ModRM:reg). + * + * 0F BE/r movsx r/m8, r32 + * REX.W + 0F BE/r movsx r/m8, r64 + */ + + /* get the first operand */ + error = memread(vm, vcpuid, gpa, &val, 1, arg); + if (error) + break; + + /* get the second operand */ + reg = gpr_map[vie->reg]; + + if (vie->rex_w) + size = 8; + + /* sign extend byte */ + val = (int8_t)val; + + /* write the result */ + error = vie_update_register(vm, vcpuid, reg, val, size); + break; default: break; } @@ -508,9 +539,10 @@ vmm_emulate_instruction(void *vm, int vc error = emulate_mov(vm, vcpuid, gpa, vie, memread, memwrite, memarg); break; + case VIE_OP_TYPE_MOVSX: case VIE_OP_TYPE_MOVZX: - error = emulate_movzx(vm, vcpuid, gpa, vie, - memread, memwrite, memarg); + error = emulate_movx(vm, vcpuid, gpa, vie, + memread, memwrite, memarg); break; case VIE_OP_TYPE_AND: error = emulate_and(vm, vcpuid, gpa, vie,