copy / v86

x86 PC emulator and x86-to-wasm JIT, running in the browser
https://copy.sh/v86/
BSD 2-Clause "Simplified" License
19.91k stars 1.41k forks source link

Compiling Microsoft's MS-DOS 4.00 sources under V86 #1068

Closed chschnell closed 5 months ago

chschnell commented 5 months ago

Hello,

out of curiosity I'm trying to compile the recently released source code of Microsoft's MS-DOS 4.00 using V86.

In around 50% of the V86 test runs it compiles as it is supposed to, but in the other cases it either freezes, generates a DIV0 error or starts printing garbage. I'm using current releases of Firefox and Chrome under Windows 10 Pro for testing.

For my tests I've created a 64MB image, installed MS-DOS 6.22 from floppies, and copied Microsoft's source tree into that image (which also includes the full toolchain to build MS-DOS 4.00, i.e. nmake, masm, C-compiler and -runtime, etc.). Note that Microsoft's sources need to be patched in order to compile. In case it matters, I can provide a copy of that image. It compiles reliably under 86Box and PCem (tested both under Windows and Linux), however under qemu it's unstable too (but in a deterimnistic way different from V86).

I've compiled bochs' current BIOS and VGABIOS for these tests, first I thought it was more stable than SeaBIOS, but I'm not anymore sure about this at all, I'm tending to believe that they behave equally (un)stable.

Here some of the versions of Microsoft's toolchain being used:

NMAKE.EXE:
    Microsoft (R) Program Maintenance Utility   Version 1.00.05
    Copyright (c) Microsoft Corp 1987, 1988. All rights reserved.
MASM.EXE:
    Microsoft (R) Macro Assembler Version 5.10
    Copyright (C) Microsoft Corp 1981, 1988.  All rights reserved.
CL.EXE:
    Microsoft (R) C Optimizing Compiler Version 5.10
    Copyright (c) Microsoft Corp 1984, 1985, 1986, 1987, 1988. All rights reserved.

Any ideas as to what could cause these instabilities in V86, or any tips to try out to get a better understanding? Except for BIOS, VGABIOS and HDA I'm using V86 defaults as I think these should be ok.

There is really no urgency to this matter.

Thanks!

SuperMaxusa commented 5 months ago

however under qemu it's unstable too (but in a deterimnistic way different from V86)

Did you try building in FreeDOS? https://fosstodon.org/@freedosproject/112350709089041734 I tested on QEMU 9.0-RC3, it builds on MS-DOS 6.22 and FreeDOS 1.3 without any problems.

On v86 I successfully built patched source code that you mentioned (https://fabulous.systems/posts/2024/05/the-broken-source-code-for-ms-dos-4-has-been-restored/) on FreeDOS, but on MS-DOS I get hangs, but no errors or garbage print.

freedos

Any ideas as to what could cause these instabilities in V86, or any tips to try out to get a better understanding?

chschnell commented 5 months ago

I haven't tried FreeDOS, yet. I know that video, but I didn't think the OS would make the difference.

I've constructed my image in different ways, since it's a raw image I thought it should be interchangeable (specifically to V86). I've used 86Box (Windows) plus WinImage (to copy the SRC file tree into the image) as well as qemu (Linux and MSYS2) to build the image, I think also PCem (Linux) at some point. Under Linux I simply mount the raw image to copy the file tree into it. In any case, when building an image I go through the MS-DOS 6.22 installer to partition and format the hard disk and to make it bootable.

In qemu (ver 9.0.0 under MSYS2 and I believe 7 under Debian) it always fails with a bogus "File not found" error when compiling select8.asm (pretty late into the build), however the error is not only deterministic but also recoverable, all you need to do is to return to the C:\SRC build directory and run nmake a 2nd time, it will pick up where it failed and complete the build successfully.

Anyways thanks a lot for your input, will try FreeDOS next. I am currently using MS-DOS 6.22 installer disks from winworldpc.com.

copy commented 5 months ago

In case it matters, I can provide a copy of that image

Yes, that would be useful.

There are some (older x86) features that are not fully implemented in v86 yet:

Additionally, there are probably bugs in segmentation wrap-around, especially with the instruction pointer in jit mode.

You could some of these things:

chschnell commented 5 months ago

Here's my image file: MSDOS622-dos4src.7z (6MB download, 64MB unpacked). Build instructions after booting:

cd src
setenv
nmake

I will come back after testing without jit. Thanks a lot!

SuperMaxusa commented 5 months ago

And here's my image with FreeDOS if you need it: fd-msdos4.tar.gz. Source code, toolchain and build instruction are identical to the image above.

chschnell commented 5 months ago

SuperMaxusa, thanks to you I've made some progress!

First I disabled JIT which unfortunately did not help, V86 froze again while building DOS 4.

Next I gave FreeDOS 1.3 a try, and after the 12th consecutive, perfectly successfull build I gave in. FreeDOS is rock-solid in my use-case, unlike the MS-DOS 6.22 distribution I used with which I had about a 50/50 chance. Isn't it ironic?

So unless there's something wrong with my MS-DOS 6.22 distribution, there is something peculiar going on here between V86 and DOS6.22 which isn't between V86 and FreeDOS1.3, most likely rooted in some behaviour in the binary toolchain which comes with the DOS4.00 sources.

I removed the image file I had published earlier as it is broken. Here the step-by-step instructions how I build the working FreeDOS image:

And to Copy and all contributers, V86 is an impressive piece of work, a bold idea which works really well, I love it and encourage you to keep on with this project!