699be18
From: Kevin O'Connor <kevin@koconnor.net>
699be18
Date: Wed Feb 5 22:47:29 2014 -0500
699be18
Subject: vgabios: Attempt to detect old x86emu and force a fault.
699be18
Upstream-Commit: 8032b8a0fec550de5cb2f7d37aa031cebc2200c3
699be18
Bug-Debian: http://bugs.debian.org/737142
699be18
699be18
Check for cases where the leal instruction does not work.  This
699be18
instruction is known to not be emulated properly on old versions of
699be18
x86emu.  If a broken version of x86emu is found, force a fault that
699be18
x86emu will easily detect.  This should help prevent soft failures
699be18
when running old software.
699be18
    
699be18
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
699be18
699be18
diff --git a/vgasrc/vgaentry.S b/vgasrc/vgaentry.S
699be18
index 9854448..6e31c4e 100644
699be18
--- a/vgasrc/vgaentry.S
699be18
+++ b/vgasrc/vgaentry.S
699be18
@@ -45,9 +45,26 @@ _rom_header_signature:
699be18
  * Entry points
699be18
  ****************************************************************/
699be18
 
699be18
-        // This macro is the same as ENTRY_ARG except the "calll"
699be18
-        // instruction is avoided to work around known issues in the
699be18
-        // emulation of some versions of x86emu.
699be18
+        // Force a fault if found to be running on broken x86emu versions.
699be18
+        DECLFUNC x86emu_fault
699be18
+x86emu_fault:
699be18
+1:      hlt
699be18
+        jmp 1b
699be18
+
699be18
+        // This macro implements a call while avoiding instructions
699be18
+        // that old versions of x86emu have problems with.
699be18
+        .macro VGA_CALLL cfunc
699be18
+        // Make sure leal instruction works.
699be18
+        movl $0x8000, %ecx
699be18
+        leal (%ecx, %ecx, 1), %ecx
699be18
+        cmpl $0x10000, %ecx
699be18
+        jne x86emu_fault
699be18
+        // Use callw instead of calll
699be18
+        push %ax
699be18
+        callw \cfunc
699be18
+        .endm
699be18
+
699be18
+        // This macro is the same as ENTRY_ARG except VGA_CALLL is used.
699be18
         .macro ENTRY_ARG_VGA cfunc
699be18
         cli
699be18
         cld
699be18
@@ -57,7 +74,7 @@ _rom_header_signature:
699be18
         movl %esp, %ebx         // Backup %esp, then zero high bits
699be18
         movzwl %sp, %esp
699be18
         movl %esp, %eax         // First arg is pointer to struct bregs
699be18
-        pushw %ax ; callw \cfunc
699be18
+        VGA_CALLL \cfunc
699be18
         movl %ebx, %esp         // Restore %esp (including high bits)
699be18
         POPBREGS
699be18
         .endm
699be18
@@ -103,7 +120,7 @@ entry_10_extrastack:
699be18
         movw %ds, %dx           // Setup %ss/%esp and call function
699be18
         movw %dx, %ss
699be18
         movl %eax, %esp
699be18
-        pushw %ax ; callw handle_10
699be18
+        VGA_CALLL handle_10
699be18
 
699be18
         movl %esp, %eax         // Restore registers and return
699be18
         movw BREGS_size+4(%eax), %ss