VOGONS


CPU test program for 8086 emulator

Topic actions

First post, by phix

User metadata
Rank Newbie
Rank
Newbie

Hi!

I'm currently working on a small PC/XT emulator as a learning experience and so far things has progressed quite nicely. 😀
Currently I'm at a state where I handle all 8086 instruction (with only one or two exceptions) and I'm using a modified version of Adrian Cable's BIOS for his 8086tiny project.
I have *some* emulation in place for the PC hardware like PIC, PIT and video that allows me to actually run not only the BIOS code but also some smaller applications (some boot-sector games kind of works).

So the current problem I have right now (which leads me to the question here) is that I have bugs in my instruction interpretation. I have not yet been able to boot a real OS for example.
This is of course not always that easy to track down so I have been thinking of ways to help with debug that.

1.) The obvious thing would be to use application level unit tests. (preferably I should have done that from day one, but I have not)

2.) The other thing I did try was to do "locksteping" with a known working emulator. That helped me track down a few things but it got very complicated in the end.

3.) The other thing i ran across was this: https://github.com/spycrab/8086-accuracy. This program is no where near complete (and has a few problems of its own) but it got me thinking that there might be others like it!

So my QUESTION is:

Are there any CPU verification program that run on a 8086/88 CPU? I imagine it would be very helpful in emulator development if it did.
Especially when you are relatively new to the subject like I am. 😀

Any help or tips is greatly appreciated!

VirtualXT - A portable, lightweight Turbo PC/XT emulator written in C.

Reply 1 of 22, by superfury

User metadata
Rank l33t++
Rank
l33t++

If you can upgrade to 80186 CPU emulation(a handful of new instructions) you can run the 80186 testsuite (I mentioned it here: Re: Test suite and/or how to find bugs in x86 VM).
You can alternatively take Hottobar's 80386 testsuite(https://github.com/barotto/test386.asm) and rip out all 80186+ instructions.

Finally, UniPCemu supports importing instruction output in the common emulator format for verification(It'll dump information when a mismatch occurs). You'll just have to redirect the output from your emulator to UniPCemu's input(using simple piping) and have UniPCemu start it's verification using the "debuggerin"(unquoted) command line parameter(debuggerout does the opposite, dumping it's own debugger output to stdout instead of reading from stdin). Said read data(line endings automatically converted) from stdin is compared with it's own. If a mismatch occurs, "<VERIFY:MISMATCH>"(without quotes) is logged after any mismatching line not matching UniPCemu's logging.

Of course, it requires that the logging is enabled in it's settings.
Edit: Just added documentation on the command-line parameters to the manual.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 3 of 22, by Peter Swinkels

User metadata
Rank Oldbie
Rank
Oldbie

Oh my! I am trying to build an emulator too, this post looks useful. Thank you.

Do not read if you don't like attention seeking self-advertisements!

Did you read it anyway? Well, you can find all sorts of stuff I made using various programming languages over here:
https://github.com/peterswinkels

Reply 4 of 22, by phix

User metadata
Rank Newbie
Rank
Newbie

I just want to give you a special thanks @superfury for suggesting the 186 tests. It helped me a lot with the final piece of the puzzle.

My emulator is now released here here.

It is still a long way from UniPCemu but I'm quite happy with how it has turned out so far. 😉

Thanks!

Attachments

  • screenshot3.png
    Filename
    screenshot3.png
    File size
    10.92 KiB
    Views
    4505 views
    File license
    Public domain
Last edited by Stiletto on 2020-08-31, 05:30. Edited 1 time in total.

VirtualXT - A portable, lightweight Turbo PC/XT emulator written in C.

Reply 5 of 22, by davecom

User metadata
Rank Newbie
Rank
Newbie

Thanks for replying to this thread. I am going to integrate the 186 tests into my WIP emulator as well and use the example from your code for how they are supposed to be run. It's really too bad that the tests don't have a license... If anyone knows the license please let us know. Does anyone know the original source of them before they made their way onto this forum?

Reply 6 of 22, by superfury

User metadata
Rank l33t++
Rank
l33t++

I originally found them on the fakex86 project forum before I posted a link to it and the files here.

https://forum.osdev.org/viewtopic.php?f=13&t=23739&start=15

It's the post by Artlav.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 8 of 22, by davecom

User metadata
Rank Newbie
Rank
Newbie

The 80186 tests by Artlav were helpful to me, but unfortunately (unless I'm mistaken in my interpretation of them) they make a lot of poor assumptions. For example some of them assume flag results for instructions that set some of their flags to undefined. Others assume exact memory locations when the tests have been modified over time and those locations no longer hold. I still have CPU bugs and I am still looking for good 8086 CPU tests that can be loaded in place of a BIOS or run completely independently. To see how I'm using the Artlav CPU tests, you can find the tests in my repository here:
https://github.com/davecom/DK86PC/tree/master/CPUTests

Does anyone have any alternative 8086 CPU tests?

Reply 9 of 22, by superfury

User metadata
Rank l33t++
Rank
l33t++

Like I said, try the 80386 testsuite and strip out the 80286+ stuff. Just real mode and strip out the 32-bit instructions and protected mode stuff.

Otherwise, if you can create command line output in the common log format, you can compare to UniPCemu at least, which should be able to find more bugs where present(using piping between the programs).

The current commit of UniPCemu has a little 32-bit instruction(RCR) bugfix which isn't in a released version yet, but that shouldn't be a problem with the 16-bit/8-bit instructions, which should be working properly in UniPCemu afaik.
Perhaps try looking at Bochs handling of flags calculation for math instructions (add, sub etc.)? That was the way I finally managed to get it working in UniPCemu. Look at flags.c in UniPCemu's source code for that. Although it's not using lazy flags (which don't seem to cause big improvements in interpreting emulation anyways. They don't even show up in profiling results).

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 10 of 22, by phix

User metadata
Rank Newbie
Rank
Newbie

Yea, the 186 tests got me to a point where FreeDOS runs (seemingly flawless). So does most games that I have tested.
But I can still not boot any version of MS-DOS or Windows 3.0 yet. So there are obviously still issues with my emulator.

My current approach is to do what @superfury suggested. Logging input/output of all instructions and then compare it to another emulator.

UniPCemu is an interesting choice if instruction logging is already supported.

VirtualXT - A portable, lightweight Turbo PC/XT emulator written in C.

Reply 11 of 22, by davecom

User metadata
Rank Newbie
Rank
Newbie
superfury wrote on 2021-01-31, 11:57:

Like I said, try the 80386 testsuite and strip out the 80286+ stuff. Just real mode and strip out the 32-bit instructions and protected mode stuff.

Unfortunately, it's not so trivial to do that. The creator of the 80386 test suite looked into the issue:
https://github.com/barotto/test386.asm/issues/12

Reply 12 of 22, by Jo22

User metadata
Rank l33t++
Rank
l33t++
phix wrote on 2021-02-01, 09:13:

Yea, the 186 tests got me to a point where FreeDOS runs (seemingly flawless). So does most games that I have tested.
But I can still not boot any version of MS-DOS or Windows 3.0 yet. So there are obviously still issues with my emulator.

Hi, I'm no developer, but I remember that os2museum.com always has some interesting texts to read..

https://www.os2museum.com/wp/undocumented-808 … opcodes-part-i/
https://www.os2museum.com/wp/undocumented-8086-opcodes/

From what I remember, MS-DOS/PC-DOS did things often differently.

The early versions (v2?) of MS-DOS tried to read system files in a single run, whereas later versions couldn't do that anymore because the system was too large to fit a cluster.
The Japanese versions (DOS/V) did some pretty weird stuff, too.

From what I remember, MS-DOS (incl. DOS622) also implemented a CALL5 interface to ease porting of CP/M-80 programs.

Modern DOSes and DOSBox do not emulate this aspect of MS-DOS.

https://www.os2museum.com/wp/a-word-on-the-call-5-spell/

https://www.os2museum.com/wp/the-a20-gate-it-wasnt-wordstar/

https://www.os2museum.com/wp/who-needs-the-ad … paround-anyway/

https://www.os2museum.com/wp/wordstar-needs-a … ess-wraparound/

Anyways, you can also try DCP or a real OS like PC-MOS/386, too.
Older versions of PC-MOS/386 (v1 to ~v3) do run fine on an XT.

https://m.youtube.com/channel/UCM_rzw6WcXibc7 … ry=PC-MOS%2F386

Version 5 became open source, even.

PC-MOS/386 released under GPL

"Time, it seems, doesn't flow. For some it's fast, for some it's slow.
In what to one race is no time at all, another race can rise and fall..." - The Minstrel

//My video channel//

Reply 13 of 22, by TheMechanist

User metadata
Rank Newbie
Rank
Newbie

Wow, that's a pretty cool project, I also always wanted to code some kind of emulator ... if you want to test the (graphics) compatibility of your emulator someday, try some of these releases 😀

http://www.pouet.net/prod.php?which=65371
http://www.pouet.net/party.php?which=204&when=1996
http://www.pouet.net/topic.php?which=11077&page=1#c530904

And if you add adlib support, I've coded a small 8086 compatible adlib player for my projects ..

Unchained demo group
swap42

Reply 14 of 22, by mr.cat

User metadata
Rank Member
Rank
Member

👍 Yeah, that 8088MPH in particular will blow your mind...it's meant to be run only in the original IBM hardware, so no easy task for emulators.

Earlier thread about UniPCemu + 8088MPH:
UniPCemu cycle accurate 8088 implementation

Reply 15 of 22, by TheMechanist

User metadata
Rank Newbie
Rank
Newbie
mr.cat wrote on 2021-03-16, 18:13:

👍 Yeah, that 8088MPH in particular will blow your mind...it's meant to be run only in the original IBM hardware, so no easy task for emulators.

seems that 86box finally made it ...
https://www.youtube.com/watch?v=CWDRSx1LYTU

Unchained demo group
swap42

Reply 16 of 22, by Jo22

User metadata
Rank l33t++
Rank
l33t++
TheMechanist wrote on 2021-03-16, 17:54:
Wow, that's a pretty cool project, I also always wanted to code some kind of emulator ... if you want to test the (graphics) com […]
Show full quote

Wow, that's a pretty cool project, I also always wanted to code some kind of emulator ... if you want to test the (graphics) compatibility of your emulator someday, try some of these releases 😀

http://www.pouet.net/prod.php?which=65371
http://www.pouet.net/party.php?which=204&when=1996
http://www.pouet.net/topic.php?which=11077&page=1#c530904

And if you add adlib support, I've coded a small 8086 compatible adlib player for my projects ..

+1

Speaking of CGA.. What about adding that 640x400 mode?
The Olivetti/AT&T graphics mode is a superset of CGA.
Adding it wouldn't break anything, would it? 😀
Would be interesting for Windows 3.0, for example.
Or many of the Turbo Pascal programs.

Olivetti/Logabax/AT&T/Toshiba 640x400 hi-res graphics mode

"Time, it seems, doesn't flow. For some it's fast, for some it's slow.
In what to one race is no time at all, another race can rise and fall..." - The Minstrel

//My video channel//

Reply 17 of 22, by phix

User metadata
Rank Newbie
Rank
Newbie

Just to share how I ended up doing in the end.

I created a hardware validator using a real 8088 and then use that in conjecture with the 186 tests @superfury mentioned.

Details

7721191646056848126.jpg

Details

1818451646056887854.png

Details

7608791646056967209.jpg

It has been a very helpful tool and I found a lot of bugs with it. I hope it can be useful to some one else as well. 😁

VirtualXT - A portable, lightweight Turbo PC/XT emulator written in C.

Reply 18 of 22, by TheMechanist

User metadata
Rank Newbie
Rank
Newbie

Congrats, seems, that you reached your goal and running windows 3.0 is a great milestone!

Now, looking at the final (?) product - would you say, that it's an accurate emulation of a XT - in terms of speed, compatibility and so on?

Unchained demo group
swap42

Reply 19 of 22, by TheMechanist

User metadata
Rank Newbie
Rank
Newbie

unfortunately VirtualXT doesn't build on Ubuntu 18.04 (latest Zig from github) ..

"Semantic Analysis [1615/2537] 
./build.zig:221:23:error: no member named 'defineCMacroRaw' in struct 'std.build.LibExeObjStep'
pirepheral.defineCMacroRaw("PI8088");
^
./build.zig:150:22: error: container 'builtin' has no member called 'zig_version'
const a = builtin.zig_version.major;
^
./build.zig:101:12: error: no member named 'defineCMacroRaw' in struct 'std.build.LibExeObjStep'
lib.defineCMacroRaw("VXT_CPU_286");"

Unchained demo group
swap42