From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] x86 emulator: Add 'push/pop sreg' instructions Date: Wed, 19 Aug 2009 11:32:42 +0300 Message-ID: <4A8BB8AA.5020401@redhat.com> References: <1250655104-437-1-git-send-email-m.gamal005@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Mohammed Gamal Return-path: Received: from mx2.redhat.com ([66.187.237.31]:55592 "EHLO mx2.redhat.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750770AbZHSIcp (ORCPT ); Wed, 19 Aug 2009 04:32:45 -0400 In-Reply-To: <1250655104-437-1-git-send-email-m.gamal005@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On 08/19/2009 07:11 AM, Mohammed Gamal wrote: > > +static void emulate_push_sreg(struct x86_emulate_ctxt *ctxt, int seg) > +{ > + struct decode_cache *c =&ctxt->decode; > + struct kvm_segment segment; > + > + if (ctxt->mode == X86EMUL_MODE_PROT64&& (seg != VCPU_SREG_FS || > + seg != VCPU_SREG_GS)) { > + kvm_queue_exception(ctxt->vcpu, UD_VECTOR); > + return; > + } > It's better to check at the callsite, in case the opcode is ever reused for a new instruction. Or even better, add a new decode flag No64 so we can do this during the decode stage. > + > +static int emulate_pop_sreg(struct x86_emulate_ctxt *ctxt, > + struct x86_emulate_ops *ops, int seg) > +{ > + struct decode_cache *c =&ctxt->decode; > + struct kvm_segment segment; > + int rc; > + > + if (ctxt->mode == X86EMUL_MODE_PROT64&& (seg != VCPU_SREG_FS || > + seg != VCPU_SREG_GS)) { > + kvm_queue_exception(ctxt->vcpu, UD_VECTOR); > + return -1; > + } > + > + kvm_x86_ops->get_segment(ctxt->vcpu,&segment, seg); > + rc = emulate_pop(ctxt, ops,&segment.selector, c->op_bytes); > + if (rc != 0) > + return rc; > + > + rc = kvm_load_segment_descriptor(ctxt->vcpu, segment.selector, 1, seg); > + return rc; > +} > Why do the ->get_segment() at all? pop into a temporary variable, and call kvm_load_segment_descriptor() with that. -- error compiling committee.c: too many arguments to function