Skip to contentSkip to conversation

(big) real mode emulation - aas

PATCH In review Nitin A Kamble 2 participants 2 messages Oct 31, 2007 1 message not in the archive KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 (big) real mode emulation - aas

Hi Avi,
Attached is the patch to implement emulation of instruction aas
please apply.

Signature · 5 lines
Thanks & Regards,
Nitin
Open Source Technology Center, Intel Corporation
-----------------------------------------------------------------
The mind is like a parachute; it works much better when it's open

From 8186c246a2f2753dd73bbc5583403afff7c4dfaf Mon Sep 17 00:00:00 2001
From: Nitin A Kamble <[email protected]>
Date: Tue, 30 Oct 2007 19:33:21 -0800
Subject: [PATCH] Implement emulation of instruction: aas
opcode: 0x3f

---
 drivers/kvm/x86_emulate.c |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)
drivers/kvm/x86_emulate.c +26 -1
index 5815128..0f6ded5 100644
@@ -97,7 +97,7 @@ static u16 opcode_table[256] = {
 	/* 0x38 - 0x3F */
 	ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
 	ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
-	0, 0, 0, 0,
+	0, 0, 0, ImplicitOps,
 	/* 0x40 - 0x47 */
 	ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
 	ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
@@ -1284,6 +1284,31 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
 	      cmp:		/* cmp */
 		emulate_2op_SrcV("cmp", c->src, c->dst, ctxt->eflags);
 		break;
+	case 0x3f: /* aas */ {
+		u8 al, ah, af, cf;
+		al = c->regs[VCPU_REGS_RAX] & 0xff;
+		ah = (c->regs[VCPU_REGS_RAX] >> 8) & 0xff;
+		af = (ctxt->eflags & EFLG_AF);
+		cf = (ctxt->eflags & EFLG_CF);
+		if (((al & 0x0f) > 9) || af) {
+			al = al - 6;
+			ah = ah - 1;
+			af = cf = 1;
+		} else {
+			cf = af = 0;
+		}
+		al = al & 0x0f;
+		if (af)
+			ctxt->eflags |= EFLG_AF;
+		else
+			ctxt->eflags &= ~EFLG_AF;
+		if (cf)
+			ctxt->eflags |= EFLG_CF;
+		else
+			ctxt->eflags &= ~EFLG_CF;
+		*(u16 *) &c->regs[VCPU_REGS_RAX] = (ah << 8) & al;
+		}
+		break;
 	case 0x63:		/* movsxd */
 		if (ctxt->mode != X86EMUL_MODE_PROT64)
 			goto cannot_emulate;
Signature · 1 line
1.5.2.2

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

A message that is not in the archive (sent off-list or not yet received): 1193791138.9258.11.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org

#2 lore raw
Quoted 18 lines · Nitin A Kamble

Hi Avi,
Attached is the patch to implement emulation of instruction aas

drivers/kvm/x86_emulate.c +15 -0
+       case 0x3f: /* aas */ {
+               u8 al, ah, af, cf;
+               al = c->regs[VCPU_REGS_RAX] & 0xff;
+               ah = (c->regs[VCPU_REGS_RAX] >> 8) & 0xff;
+               af = (ctxt->eflags & EFLG_AF);
+               cf = (ctxt->eflags & EFLG_CF);
+               if (((al & 0x0f) > 9) || af) {
+                       al = al - 6;
+                       ah = ah - 1;
+                       af = cf = 1;
+               } else {
+                       cf = af = 0;
+               }
+               al = al & 0x0f;
+               if (af)

drivers/kvm/x86_emulate.c x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) · line 1311

Quoted 10 lines
drivers/kvm/x86_emulate.c +10 -0
+                       ctxt->eflags |= EFLG_AF;
+               else
+                       ctxt->eflags &= ~EFLG_AF;
+               if (cf)
+                       ctxt->eflags |= EFLG_CF;
+               else
+                       ctxt->eflags &= ~EFLG_CF;
+               *(u16 *) &c->regs[VCPU_REGS_RAX] = (ah << 8) & al;
+               }
+               break;

Please move the whole thing to a static function in order to reduce clutter.

Also, a helper

static void set_flag_value(struct emulate_context *ctxt, u32 mask,
int value) {... }

can simplify some of the code.

Signature · 8 lines
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/