All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [RFC] More fp instructions for realmode emulation (Enables booting OS/2 as a HVM guest on Intel/VT hardware)
@ 2008-02-29 22:14 Trolle Selander
  2008-03-01  8:46 ` Keir Fraser
  2008-03-04 10:13 ` Keir Fraser
  0 siblings, 2 replies; 11+ messages in thread
From: Trolle Selander @ 2008-02-29 22:14 UTC (permalink / raw)
  To: xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 1091 bytes --]

This patch adds a number of fp instructions needed for OS/2 to boot as a HVM
guest on Intel/VT hardware. It appears to work fine, and OS/2 is now finally
working on Intel/VT as well as AMD/SVM.

I'm a little concerned about the "correctness" of the FSTSW emulation and
the use of inline assembly directly using the corresponding ops for
emulation. Wrt FSTSW, it is really two ops FNSTSW immediately preceeded by
an FWAIT. I've left FWAIT defined, but a no-op because after looking at
realmode.c it seems in the emulation, exceptions are always processed if a
call to x86_emulate returns an exception, so there should be no way for
there to be "pending" exceptions for FWAIT to wait for. I may have missed
something, though, hence the RFC.

Secondly, about the inline assembly - i saw that this was how many of the
other FP instructions were done, so I did it that way as well. However, none
of the previous instructions done that way referenced the fp registers. Does
this make a difference, or is it ok the way i've done it here?

Signed-off-by: Trolle Selander <trolle.selander@gmail.com>

[-- Attachment #1.2: Type: text/html, Size: 1303 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: xen-x86_emulate-more-fp-insns.patch --]
[-- Type: text/x-patch; name=xen-x86_emulate-more-fp-insns.patch, Size: 3355 bytes --]

diff -uNr xen-unstable.hg/xen/arch/x86/x86_emulate.c xen-unstable.hg-patched/xen/arch/x86/x86_emulate.c
--- xen-unstable.hg/xen/arch/x86/x86_emulate.c	2008-02-27 09:53:48.219043994 +0100
+++ xen-unstable.hg-patched/xen/arch/x86/x86_emulate.c	2008-02-29 23:09:48.858727693 +0100
@@ -127,7 +127,7 @@
     ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
     ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
     /* 0x98 - 0x9F */
-    ImplicitOps, ImplicitOps, ImplicitOps, 0,
+    ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
     ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
     /* 0xA0 - 0xA7 */
     ByteOp|ImplicitOps|Mov, ImplicitOps|Mov,
@@ -160,7 +160,7 @@
     ByteOp|DstMem|SrcImplicit|ModRM, DstMem|SrcImplicit|ModRM, 
     ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
     /* 0xD8 - 0xDF */
-    0, ImplicitOps|ModRM, 0, ImplicitOps|ModRM, 0, ImplicitOps|ModRM, 0, 0,
+    0, ImplicitOps|ModRM, 0, ImplicitOps|ModRM, 0, ImplicitOps|ModRM, ImplicitOps|ModRM, ImplicitOps|ModRM,
     /* 0xE0 - 0xE7 */
     ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
     ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
@@ -2355,6 +2355,10 @@
         break;
     }
 
+    case 0x9b:  /* wait/fwait */
+        /* No-op */
+        break;
+
     case 0x9c: /* pushf */
         src.val = _regs.eflags;
         goto push;
@@ -2670,12 +2674,28 @@
     case 0xd9: /* FPU 0xd9 */
         fail_if(ops->load_fpu_ctxt == NULL);
         ops->load_fpu_ctxt(ctxt);
-        fail_if((modrm_reg & 7) != 7);
-        fail_if(modrm >= 0xc0);
-        /* fnstcw m2byte */
-        ea.bytes = 2;
-        dst = ea;
-        asm volatile ( "fnstcw %0" : "=m" (dst.val) );
+        switch ( modrm )
+        {
+        case 0xc0:
+             asm volatile ( "fld %st(0)" );
+             break;
+        case 0xe0:
+             asm volatile ( "fchs" );
+             break;
+        case 0xe8:
+             asm volatile ( "fld1" );
+             break;
+        case 0xee:
+             asm volatile ( "fldz" );
+             break;
+        default:
+            fail_if((modrm_reg & 7) != 7);
+            fail_if(modrm >= 0xc0);
+            /* fnstcw m2byte */
+            ea.bytes = 2;
+            dst = ea;
+            asm volatile ( "fnstcw %0" : "=m" (dst.val) );
+        }
         break;
 
     case 0xdb: /* FPU 0xdb */
@@ -2697,6 +2717,34 @@
         asm volatile ( "fnstsw %0" : "=m" (dst.val) );
         break;
 
+    case 0xde: /* FPU 0xde */
+        fail_if(ops->load_fpu_ctxt == NULL);
+        ops->load_fpu_ctxt(ctxt);
+        switch ( modrm )
+        {
+        case 0xd9:
+             asm volatile ( "fcompp" );
+             break;
+        case 0xf9:
+             asm volatile ( "fdivp %st(1),%st" );
+             break;
+        default:
+            goto cannot_emulate;
+        }
+        break;
+
+
+    case 0xdf: /* FPU 0xdf */
+        fail_if(ops->load_fpu_ctxt == NULL);
+        ops->load_fpu_ctxt(ctxt);
+        fail_if(modrm != 0xe0);
+        /* fnstsw %ax */
+        dst.bytes = 2;
+        dst.type = OP_REG;
+        dst.reg = (unsigned long *)&_regs.eax;
+        asm volatile ( "fnstsw %0" : "=m" (dst.val) );
+        break;
+
     case 0xe0 ... 0xe2: /* loop{,z,nz} */ {
         int rel = insn_fetch_type(int8_t);
         int do_jmp = !(_regs.eflags & EFLG_ZF); /* loopnz */

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-03-04 10:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-29 22:14 [PATCH] [RFC] More fp instructions for realmode emulation (Enables booting OS/2 as a HVM guest on Intel/VT hardware) Trolle Selander
2008-03-01  8:46 ` Keir Fraser
2008-03-01  9:18   ` Keir Fraser
2008-03-03 12:18     ` Trolle Selander
2008-03-03 12:21       ` Keir Fraser
2008-03-03 14:52     ` Andi Kleen
2008-03-03 15:00       ` Keir Fraser
2008-03-03 16:59         ` Andi Kleen
2008-03-03 17:30           ` Keir Fraser
2008-03-03 18:11             ` Andi Kleen
2008-03-04 10:13 ` Keir Fraser

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.