diff mbox

uvesafb doesn't work with seabios

Message ID 20140512200731.GA15678@morn.localdomain
State New
Headers show

Commit Message

Kevin O'Connor May 12, 2014, 8:07 p.m. UTC
On Mon, May 12, 2014 at 08:53:53PM +0200, Bernhard Walle wrote:
> Am 2014-05-12 07:29, schrieb Kevin O'Connor:
> >
> >It does look like the x86emu issue.  You can try applying the
> >SeaVGABIOS patch below to confirm it.
> 
> The output doesn't appear. But I'm sure that I copied the correct files
> because modifications of other strings worked.

Heh - old versions of x86emu apparently don't support "rep outsb"
either.  Can you test the patch below instead?

-Kevin

Comments

Bernhard Walle May 13, 2014, 5:52 a.m. UTC | #1
Hi,

* Kevin O'Connor <kevin@koconnor.net> [2014-05-12 22:07]:
> On Mon, May 12, 2014 at 08:53:53PM +0200, Bernhard Walle wrote:
> > Am 2014-05-12 07:29, schrieb Kevin O'Connor:
> > >
> > >It does look like the x86emu issue.  You can try applying the
> > >SeaVGABIOS patch below to confirm it.
> > 
> > The output doesn't appear. But I'm sure that I copied the correct files
> > because modifications of other strings worked.
> 
> Heh - old versions of x86emu apparently don't support "rep outsb"
> either.  Can you test the patch below instead?

Okay, the output appears. So that means that I should update
v86d (the x86emu lib included there is okay?)?


Regards,
Bernhard
Bernhard Walle May 13, 2014, 9:20 a.m. UTC | #2
Am 2014-05-13 07:52, schrieb Bernhard Walle:
> Hi,
> 
> * Kevin O'Connor <kevin@koconnor.net> [2014-05-12 22:07]:
>> On Mon, May 12, 2014 at 08:53:53PM +0200, Bernhard Walle wrote:
>> > Am 2014-05-12 07:29, schrieb Kevin O'Connor:
>> > >
>> > >It does look like the x86emu issue.  You can try applying the
>> > >SeaVGABIOS patch below to confirm it.
>> >
>> > The output doesn't appear. But I'm sure that I copied the correct files
>> > because modifications of other strings worked.
>> 
>> Heh - old versions of x86emu apparently don't support "rep outsb"
>> either.  Can you test the patch below instead?
> 
> Okay, the output appears. So that means that I should update
> v86d (the x86emu lib included there is okay?)?

I already have the latest version of x86d from
https://github.com/mjanusz/v86d/commits/master.


Regards,
Bernhard
Kevin O'Connor May 13, 2014, 3:41 p.m. UTC | #3
On Tue, May 13, 2014 at 11:20:11AM +0200, Bernhard Walle wrote:
> Am 2014-05-13 07:52, schrieb Bernhard Walle:
> >* Kevin O'Connor <kevin@koconnor.net> [2014-05-12 22:07]:
> >>On Mon, May 12, 2014 at 08:53:53PM +0200, Bernhard Walle wrote:
> >>> Am 2014-05-12 07:29, schrieb Kevin O'Connor:
> >>> >
> >>> >It does look like the x86emu issue.  You can try applying the
> >>> >SeaVGABIOS patch below to confirm it.
> >>>
> >>> The output doesn't appear. But I'm sure that I copied the correct files
> >>> because modifications of other strings worked.
> >>
> >>Heh - old versions of x86emu apparently don't support "rep outsb"
> >>either.  Can you test the patch below instead?
> >
> >Okay, the output appears. So that means that I should update
> >v86d (the x86emu lib included there is okay?)?
> 
> I already have the latest version of x86d from
> https://github.com/mjanusz/v86d/commits/master.

Thanks for running further tests.

Unfortunately, I don't know enough about v86d or x86emu to really help
here.  I do know that the version of x86emu that ships with Xorg was
updated several years back and no longer has trouble with the leal
instruction.

As background, the root of the problem is that SeaVGABIOS is compiled
with gcc, and gcc can emit the "leal" instruction.  The old "lgpl VGA
BIOS" uses a really old compiler (bcc) which doesn't emit that x86
instruction.  The x86emu code does not properly emulate "leal" (as
near as I can tell it treats it as a "leaw" instead), which leads to
all sorts of bizarre behavior when it tries to interpret the code.
This type of issue has occurred for a bunch of instructions (on both
x86emu and on an emulator Windows uses) and we've worked around it in
SeaVGABIOS with a combination of gcc compiler flags and by post
processing gcc's assembler to remove some troublesome instructions.
Unfortunately, I don't know of any way to convince gcc to not emit the
"leal" instruction and the instruction appears too complex to readily
patch out of the assembler.

So, my advice would be to either avoid x86emu (eg, maybe by trying the
vm86 mode of v86d, or maybe by not using uvesafb), try compiling v86d
with a newer version of x86emu, or stick with the "lgpl VGA BIOS".

-Kevin
Gerhard Wiesinger May 13, 2014, 6:08 p.m. UTC | #4
On 13.05.2014 17:41, Kevin O'Connor wrote:
>  The x86emu code does not properly emulate "leal" (as near as I can 
> tell it treats it as a "leaw" instead), which leads to all sorts of 
> bizarre behavior when it tries to interpret the code. This type of 
> issue has occurred for a bunch of instructions (on both x86emu and on 
> an emulator Windows uses) and we've worked around it in SeaVGABIOS 
> with a combination of gcc compiler flags and by post processing gcc's 
> assembler to remove some troublesome instructions. Unfortunately, I 
> don't know of any way to convince gcc to not emit the "leal" 
> instruction and the instruction appears too complex to readily patch 
> out of the assembler.

Can't that wrong behaviour of "leal" instruction be fixed in qemu?

Ciao,
Gerhard
Kevin O'Connor May 13, 2014, 6:20 p.m. UTC | #5
On Tue, May 13, 2014 at 08:08:41PM +0200, Gerhard Wiesinger wrote:
> On 13.05.2014 17:41, Kevin O'Connor wrote:
> > The x86emu code does not properly emulate "leal" (as near as I can tell
> >it treats it as a "leaw" instead), which leads to all sorts of bizarre
> >behavior when it tries to interpret the code. This type of issue has
> >occurred for a bunch of instructions (on both x86emu and on an emulator
> >Windows uses) and we've worked around it in SeaVGABIOS with a combination
> >of gcc compiler flags and by post processing gcc's assembler to remove
> >some troublesome instructions. Unfortunately, I don't know of any way to
> >convince gcc to not emit the "leal" instruction and the instruction
> >appears too complex to readily patch out of the assembler.
> 
> Can't that wrong behaviour of "leal" instruction be fixed in qemu?

QEMU doesn't have any issue with leal.  x86emu is a separate program
that implements a (partial) x86 interpretter.

The issue being reported is when QEMU runs a guest which uses x86emu
to interpret SeaVGABIOS - QEMU is correctly emulating what a real
machine would do (random faults) and thus it can't be fixed in QEMU
itself.

-Kevin
Bernhard Walle May 13, 2014, 7:48 p.m. UTC | #6
Am 13.05.14 17:41, schrieb Kevin O'Connor:
> 
> So, my advice would be to either avoid x86emu (eg, maybe by trying the
> vm86 mode of v86d, or maybe by not using uvesafb), try compiling v86d
> with a newer version of x86emu, or stick with the "lgpl VGA BIOS".

Unfortunately I cannot use vm86 mode because it's a x86-64 image (and I
really want to avoid kernel patches that seem to provide vm86 on 64 bit
kernels).

However, I took the step to update the x86emu code from X.org. That
seems to work! At least with my test VM that is based on Arch Linux.
I'll try the original Gentoo-based VM tomorrow.

For the meanwhile, I uploaded my patch at
https://bitbucket.org/bwalle/v86d/commits/all. Maybe someone else can
use it.

I'll try to push the fix to the original v86d repo, but the project seem
to be a bit unmaintained. Unfortunately, there seem to be three
independent versions of x86emu out there that even have different APIs
(luckily the X.org copy still has the same API as the "original" x86emu).

Thanks for your advise and debugging help!



Regards,
Bernhard
Bernhard Walle May 14, 2014, 7:08 p.m. UTC | #7
Am 13.05.14 21:48, schrieb Bernhard Walle:
> However, I took the step to update the x86emu code from X.org. That
> seems to work! At least with my test VM that is based on Arch Linux.
> I'll try the original Gentoo-based VM tomorrow.

That worked, too. :)

I sent a pull request via https://github.com/bwalle/v86d to
https://github.com/mjanusz/v86d.

Regards,
Bernhard
diff mbox

Patch

--- a/vgasrc/vgaentry.S
+++ b/vgasrc/vgaentry.S
@@ -47,7 +47,17 @@  _rom_header_signature:
 
         // Force a fault if found to be running on broken x86emu versions.
         DECLFUNC x86emu_fault
+msg:    .ascii "SeaVGABIOS: x86emu leal trap!\n"
 x86emu_fault:
+#if CONFIG_DEBUG_IO
+        movw %cs:DebugOutputPort, %dx
+        movw $msg, %si
+1:      movb %cs:(%si), %al
+        outb %al, (%dx)
+        incw %si
+        cmpw $x86emu_fault, %si
+        jl 1b
+#endif
 1:      hlt
         jmp 1b