From: Mohammed Gamal Subject: Re: [PATCH] x86 emulator: Add 'push/pop sreg' instructions Date: Tue, 18 Aug 2009 22:40:46 +0300 Message-ID: <52d4a3890908181240t2cfd696rf1b7a5d99175c0f7@mail.gmail.com> References: <1250599685-2351-1-git-send-email-m.gamal005@gmail.com> <4A8ABD19.1000807@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mail-fx0-f215.google.com ([209.85.220.215]:33435 "EHLO mail-fx0-f215.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750823AbZHRTkp convert rfc822-to-8bit (ORCPT ); Tue, 18 Aug 2009 15:40:45 -0400 Received: by fxm11 with SMTP id 11so498970fxm.39 for ; Tue, 18 Aug 2009 12:40:46 -0700 (PDT) In-Reply-To: <4A8ABD19.1000807@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Aug 18, 2009 at 5:39 PM, Avi Kivity wrote: > On 08/18/2009 03:48 PM, Mohammed Gamal wrote: >> >> + >> +static int emulate_pop_sreg(struct x86_emulate_ctxt *ctxt, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0struct x86_= emulate_ops *ops, int seg) >> +{ >> + =A0 =A0 =A0 struct kvm_segment segment; >> + =A0 =A0 =A0 int rc; >> + >> + =A0 =A0 =A0 kvm_x86_ops->get_segment(ctxt->vcpu,&segment, seg); >> + =A0 =A0 =A0 rc =3D emulate_pop(ctxt, ops,&segment.selector, sizeof= (uint16_t)); >> > > 'pop seg' is still subject to the operand size (I think). > >> + =A0 =A0 =A0 kvm_x86_ops->set_segment(ctxt->vcpu,&segment, seg); >> But we're popping the contents of the stack top to a segment register which is going to be of 16-bits anyway, so we know the length before hand, no? > > You need to call kvm_load_segment_descriptor() so that the segment ca= che is > also loaded correctly. > > Note some of these instructions are not encodable in long mode; need = to > check for that instead of emulating the wrong instruction. > >> @@ -1707,18 +1732,45 @@ special_insn: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0add: =A0 =A0 =A0 =A0 =A0 =A0 =A0/* add */ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0emulate_2op_SrcV("add", c->src, c->ds= t, ctxt->eflags); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; >> + =A0 =A0 =A0 case 0x06: =A0 =A0 =A0 =A0 =A0 =A0 =A0/* push es */ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 emulate_push_sreg(ctxt, VCPU_SREG_ES); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> + =A0 =A0 =A0 case 0x07: =A0 =A0 =A0 =A0 =A0 =A0 =A0/* pop es */ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rc =3D emulate_pop_sreg(ctxt, ops, VCP= U_SREG_ES); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (rc !=3D 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto done; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> =A0 =A0 =A0 =A0case 0x08 ... 0x0d: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0or: =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* or */ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0emulate_2op_SrcV("or", c->src, c->dst= , ctxt->eflags); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; >> + =A0 =A0 =A0 case 0x0e: =A0 =A0 =A0 =A0 =A0 =A0 =A0/* push cs */ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 emulate_push_sreg(ctxt, VCPU_SREG_CS); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> =A0 =A0 =A0 =A0case 0x10 ... 0x15: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0adc: =A0 =A0 =A0 =A0 =A0 =A0 =A0/* adc */ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0emulate_2op_SrcV("adc", c->src, c->ds= t, ctxt->eflags); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; >> + =A0 =A0 =A0 case 0x16: =A0 =A0 =A0 =A0 =A0 =A0 =A0/* push ss */ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 emulate_push_sreg(ctxt, VCPU_SREG_SS); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> + =A0 =A0 =A0 case 0x17: =A0 =A0 =A0 =A0 =A0 =A0 =A0/* pop ss */ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rc =3D emulate_pop_sreg(ctxt, ops, VCP= U_SREG_SS); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (rc !=3D 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto done; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> =A0 =A0 =A0 =A0case 0x18 ... 0x1d: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0sbb: =A0 =A0 =A0 =A0 =A0 =A0 =A0/* sbb */ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0emulate_2op_SrcV("sbb", c->src, c->ds= t, ctxt->eflags); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; >> + =A0 =A0 =A0 case 0x1e: =A0 =A0 =A0 =A0 =A0 =A0 =A0/* push ds */ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 emulate_push_sreg(ctxt, VCPU_SREG_DS); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> + =A0 =A0 =A0 case 0x1f: =A0 =A0 =A0 =A0 =A0 =A0 =A0/* pop ds */ >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 rc =3D emulate_pop_sreg(ctxt, ops, VCP= U_SREG_DS); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (rc !=3D 0) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto done; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 break; >> =A0 =A0 =A0 =A0case 0x20 ... 0x25: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0and: =A0 =A0 =A0 =A0 =A0 =A0 =A0/* and */ >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0emulate_2op_SrcV("and", c->src, c->ds= t, ctxt->eflags); >> > > I was under the impression that the emulator doesn't support long mode yet, is that still the case?