Skip to contentSkip to conversation

x86 emulator: Add 'push es' instruction (opcode 0x06)

PATCH In review Mohammed Gamal 2 participants 3 messages Aug 16, 2009 – Aug 17, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86 emulator: Add 'push es' instruction (opcode 0x06)

---
 arch/x86/kvm/emulate.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
arch/x86/kvm/emulate.c +13 -1
index 2eb807a..7688c0b 100644
@@ -92,7 +92,7 @@ static u32 opcode_table[256] = {
 	/* 0x00 - 0x07 */
 	ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
 	ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
-	ByteOp | DstAcc | SrcImm, DstAcc | SrcImm, 0, 0,
+	ByteOp | DstAcc | SrcImm, DstAcc | SrcImm, ImplicitOps | Stack, 0,
 	/* 0x08 - 0x0F */
 	ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
 	ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
@@ -1186,6 +1186,15 @@ static int emulate_pop(struct x86_emulate_ctxt *ctxt,
 	return rc;
 }
 
+static void emulate_push_sreg(struct x86_emulate_ctxt *ctxt, int seg)
+{
+	struct decode_cache *c = &ctxt->decode;
+	struct kvm_segment segment;
+	kvm_x86_ops->get_segment(ctxt->vcpu, &segment, seg);
+	c->src.ptr = (unsigned long *) &segment.selector;
+	emulate_push(ctxt);
+}
+
 static inline int emulate_grp1a(struct x86_emulate_ctxt *ctxt,
 				struct x86_emulate_ops *ops)
 {
@@ -1707,6 +1716,9 @@ special_insn:
 	      add:		/* add */
 		emulate_2op_SrcV("add", c->src, c->dst, ctxt->eflags);
 		break;
+	case 0x06:		/* push es */
+		emulate_push_sreg(ctxt, VCPU_SREG_ES);
+		break;
 	case 0x08 ... 0x0d:
 	      or:		/* or */
 		emulate_2op_SrcV("or", c->src, c->dst, ctxt->eflags);
Signature · 1 line
1.6.0.4
#1 lore raw

arch/x86/kvm/emulate.c static int emulate_pop(struct x86_emulate_ctxt *ctxt, · line 1196

Quoted 10 lines · Mohammed Gamal
arch/x86/kvm/emulate.c +8 -0
+static void emulate_push_sreg(struct x86_emulate_ctxt *ctxt, int seg)
+{
+	struct decode_cache *c =&ctxt->decode;
+	struct kvm_segment segment;
+	kvm_x86_ops->get_segment(ctxt->vcpu,&segment, seg);
+	c->src.ptr = (unsigned long *)&segment.selector;
+	emulate_push(ctxt);
+}

This will pick up random junk from segment.type if used in 32-bit mode, since segment.selector is only 16 bits wide.

btw, I see that emulate_push() uses src.val, not src.ptr. Have you tested this?

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 15 lines · Avi Kivity

arch/x86/kvm/emulate.c static int emulate_pop(struct x86_emulate_ctxt *ctxt, · line 1196

Quoted 10 lines · Mohammed Gamal
arch/x86/kvm/emulate.c +8 -0
+static void emulate_push_sreg(struct x86_emulate_ctxt *ctxt, int seg)
+{
+       struct decode_cache *c =&ctxt->decode;
+       struct kvm_segment segment;
+       kvm_x86_ops->get_segment(ctxt->vcpu,&segment, seg);
+       c->src.ptr = (unsigned long *)&segment.selector;
+       emulate_push(ctxt);
+}

This will pick up random junk from segment.type if used in 32-bit mode, since segment.selector is only 16 bits wide.

Quoted 3 lines

btw, I see that emulate_push() uses src.val, not src.ptr.  Have you tested this?

Hmmm, there are no test cases that test conventional push/pop instructions. I'll write a test case and see if the function behaves correctly.

Quoted 5 lines

--
error compiling committee.c: too many arguments to function