Skip to content
SingleStepTestsPublic

About

A Hardware-Generated CPU Test Suite for the Intel 8086

Resources

Stars

22 stars

Watchers

1 watching

Forks

Repository files navigation

8086 V2

This is a set of 8086 CPU tests produced by Daniel Balsom using the ArduinoX86 interface and test generator.

Current version: 2.0

This repository contains the following directories:

Directory Description
v1 Version 1 of the 8086 test suite in JSON format.
v1_binary Version 1 of the 8086 test suite in binary MOO 1.0 format.
v2/core Version 2 of the main test suite in binary MOO 1.2 format.
v2/tin_cycle A test suite for cycle-accurate emulators that exercises the trap flag and the INTR and NMI pins.
v2/tin_instruction A test suite for instruction-accurate emulators that exercises the trap flag and the INTR and NMI pins.
v2/tin_rep_prefix A test suite that exercises various REP-prefixed string instructions.
v2/wait Standalone WAIT tests with the Arduino driving the 8086 TEST input.
v2_harris_80c86/setlo Harris 80C86 SETLO tests for opcode forms D0.6, D1.6, D2.6, and D3.6.
v2_harris_80c86/tin_cycle Cycle-timed trap, INTR, and NMI tests captured on the Harris 80C86.
v2_minimal/core Minimal selection from the main v2 test suite.
v2_minimal/tin_cycle Minimal selection of cycle-accurate TIN tests.
v2_minimal/tin_instruction Minimal selection of instruction-accurate TIN tests.
v2_minimal/tin_rep_prefix Minimal selection of tests for interrupted REP-prefixed string instructions.
v2_undefined A test suite that exercises reserved and undefined ModR/M encodings.
v2_undefined/core Core tests for reserved ModR/M encodings and undefined register forms.
v2_undefined/tin_cycle Cycle-accurate TIN tests for reserved ModR/M encodings.
v2_undefined/tin_instruction Instruction-accurate TIN tests for reserved ModR/M encodings.
v2_undefined_minimal Minimal selections from each v2_undefined profile.
v2_undefined_minimal/core Minimal selection from the undefined core test suite.
v2_undefined_minimal/tin_cycle Minimal selection of cycle-accurate TIN tests for reserved ModR/M encodings.
v2_undefined_minimal/tin_instruction Minimal selection of instruction-accurate TIN tests for reserved ModR/M encodings.
v2_wavedrom_gallery WaveDrom timing diagrams from selected v2 tests.

About the Tests

v1

Note

The v1 test suite is now deprecated - all users should use the v2 test suites.

See /v1/README.md.

v2

These tests are produced with an Intel P80C86A-2 CPU, running in maximum mode, using an ArduinoX86 8088 Shield V1.1. Bus signals are provided via an OKI M82C88 bus controller.

An Intel P80C86A-2 CPU

Each test records an execution sequence consisting of one or more instructions. The test records the initial and final registers, memory and instruction queue, together with per-clock bus activity.

All tests assume a writable 1 MiB address space, with physical addresses wrapping at 0xFFFFF.

This test suite exercises the 8086's prefetch queue. Some instructions execute from as full a prefetch queue as possible (5 bytes for instructions starting at odd addresses, 6 bytes otherwise).

Register state is randomized using a beta distribution (α=0.65, β=0.65) that weights values toward the extremes. After randomization, each register has a chance of being set to one of a list of 'interesting' binary patterns, including 0 and FFFF.

Memory contents are also randomized, each test having a chance of memory being set to all 0x00 or 0xFF. The rationale for this is to attempt to exercise more edge cases and ensure good flag test coverage.

The SingleStepTests organization name reflects the original design intent that each test represents a single instruction execution. However, the quirks of the 8086 CPU make testing all its behavior with a single instruction intractable. Therefore, some tests in this repository may contain multiple instructions that execute sequentially.

Accuracy

The tests are derived directly from hardware, using CPU control hardware and software that is now quite mature. Errors in the test suites are usually caused by test generator bugs or electrical capture issues. Each test in the corpus is replayed against the CPU after generation to ensure that the test is reproducable. This eliminates many issues.

In the event that a problematic test is discovered within the test corpus, the hexadecimal string of the faulty test's hash key will be added to a revocation_list.txt, one hash per line.

You are encouraged to open an issue for any suspect tests you may encounter, or if you simply have a question. Please include the filename, test index and SHA-1 hash when reporting an issue with any test.

v2/core

The main test corpus of the v2 suite. The interrupt and trap flags are not exercised. The suite covers all defined opcodes and instruction forms except HLT and WAIT.

v2/tin_cycle

A TIN (Trap, Interrupt, NMI) test suite exercises the Trap Flag along with the INTR and NMI pins.

In the tin_cycle test suite, these signals may assert on any cycle of instruction execution, between the first queue read of the instruction under test and the terminating queue read.

v2/tin_instruction

In the instruction-suffixed TIN test suite, the INTR and NMI pins will always be asserted, if applicable, before the first cycle of the instruction under test.

v2/tin_rep_prefix

These tests exercise a variety of prefix combinations with REP-prefixed string instructions. The 8086 has a bug when resuming interrupted string instructions, in that it only accounts for a single prefix when adjusting IP to resume the interrupted instruction. These tests are designed to ensure 8086-accurate modeling of this bug. If you've designed your 8086 emulator to not have this bug, you can skip these tests.

v2/wait

This directory contains a single test file with 5,000 tests for WAIT (9Bh). See Testing WAIT on the 8086.

v2_minimal

A minimal test suite that still provides full operational flag coverage. This suite is intended for integration with CI pipelines or inclusion in emulator source repos.

v2_undefined

These tests exercise strictly undefined instruction forms, including undefined opcodes and invalid ModR/M reg values.

v2_harris_80c86

These tests were captured with a Harris CP80C86-2 running in maximum mode on an ArduinoX86 8088 Shield V1.1. Bus signals are provided via an OKI M82C88 bus controller.

v2_harris_80c86/setlo

Tests for the Harris 80c86's unique SETLO instruction

v2_harris_80c86/tin_cycle

A TIN (Trap, Interrupt, NMI) test suite exercises the Trap Flag along with the INTR and NMI pins.

The Harris CP80C86-2 has multiple interrupt timing differences from the Intel P80C86 which are captured here.

Test Methodology

The tests are created by directly manipulating the 8086's bus and status pins by connecting them to the GPIO lines of an Arduino Giga microcontroller. In this manner every cycle of the CPU's activity is known and can be captured.

A randomized initial CPU state can be loaded onto the CPU via means of a small register setup program, and the final register state dumped by writing each register in turn to a special IO port address.

Since the 8086 exposes the QS0 and QS1 status pins, the exact cycle boundaries of instruction execution can be determined, alowing only the cycles representing instruction execution to be captured. There is a bit more to it, since setting up prefetched tests requires a bit more work. See the ArduinoX86 project for more details.

Using the Tests

To run a SST:

  • Write the values in the initial RAM state to your emulator's memory.
  • Use the values in the initial regsiter state to set your emulator's CPU registers.
  • Execute a far jump to the CS:IP specified by the test's initial state.

Prefetched Tests

  • If cycle-accurate verification of bus activity is desired, the provided initial queue contents should be set after the prefetch queue is flushed by jumping to the CS:IP in the initial test state. This should trigger your emulator to suspend prefetching since the queue is full.

  • You will need to add the length of the queue contents to your PC register (or adjust the reset vector IP) so that fetching begins at the correct address.

  • Once you read the first instruction byte out of the queue to begin test execution, prefetching should be resumed since there is now room in the queue. It takes two cycles to begin a fetch after reading from a full queue. Therefore, tests that specify an initial queue state will start with two Ti cycle states.

  • If you're not interested in per-cycle validation, you can ignore the queue fields and not strictly validate code fetch bus transfers.

TIN Tests

TIN tests (Trap, Interrupt, NMI) can be used to test your emulator's handling of said signals.

TIN test suites contain two additional pin_bitfield0 values in the captured cycles, INTR and NMI. These pins were added to the MOO v1.2 specification.

Bit Description
0 ALE pin
1 BHE pin
2 READY pin
3 LOCK pin
4 INTR pin
5 NMI pin
6 BUSY pin
7 Reserved

Both of these signals are active-high. In the tin_cycle test suite, these signals may assert on any cycle of instruction execution, between the first queue read of the instruction under test and the terminating queue read.

In the instruction-suffixed TIN test suite, when either INTR or NMI will be asserted during a test, the assertion occurs on the cycle immediately before instruction execution. This is intended to accommodate instruction-accurate emulators that cannot change the state of the INTR or NMI pins mid-instruction.

See 8086_INTERRUPTS.md for an in-depth discussion of 8086 interrupt handling and its consequences for test validation.

Segment Override Prefixes

Random segment override prefixes have been prepended to a percentage of instructions, even if they may not do anything. This isn't completely useless - a few bugs have been found in emulators where segment overrides had an effect when they should not have.

String Prefixes

REP, REPE, or REPNE prefixes may be prepended to string instructions. In this event, CX is masked to 7 bits to produce reasonably sized tests (a string instruction with CX==65535 would be over a million cycles in execution).

Instruction Prefetching

All bytes fetched after the initial instruction bytes are set to 0x90 (144) (NOP). Therefore, the queue contents at the end of all tests will contain only NOPs, with a maximum of 5 (since one has been read out).

Test Formats

The v1 8086 test suite was distributed in two formats: JSON, and a simple chunked binary format I call MOO (Machine Opcode Operation). The v2 test suite is only distributed here as MOO, but a conversion script is available if you prefer the traditional JSON format.

If your language of choice (such as C) lacks a convenient facility for parsing JSON, you may prefer the binary MOO format tests.

You can find more information about the binary MOO format at the MOO repository here. This repository contains a Rust library crate for working with MOO files as well as code for parsing MOO files in C, C++ and Python.

See 8086_JSON_FORMAT.md for a reference to the traditional JSON test format.

Undefined Instructions

Note that these tests include many undocumented/undefined opcodes and instruction forms. The 8086 has no concept of an invalid instruction, and will perform some task for any provided sequence of instruction bytes. Additionally, flags may be changed by documented instructions in ways that are officially undefined.

Some register forms in v2_undefined/core and v2_undefined_minimal/core depend on internal CPU state. In these tests, BYTS contains the setup instruction followed by the instruction under test. NAME lists the two instructions separated by a semicolon. Compare the final state after executing both instructions.

Per-Instruction Notes

Opcode(s) Notes
0F v1 omits POP CS. v2/core includes 5,000 tests.
POP CS will replace the value of CS without flushing the prefetch queue, which will likely cause unintended opcodes to execute unless the queue was emptied by jumping to this instruction.
8F Only ModR/M reg = 0 is documented for POP r/m16. The v1 tests use all eight values. The 5,000 tests in v2/core use reg = 0. The 4,412 core captures with nonzero reg are in v2_undefined/core.
9B The standalone v2/wait suite exercises WAIT with the Arduino driving TEST.
8C, 8E Only the low two bits of the ModR/M segment-register selector are checked. The regular v2 profiles use reg values 0-3. Tests with values 4-7 are in v2_undefined.
8D, C4, C5 The register forms of LEA, LES, and LDS are undefined. In v2_undefined/core, each test executes MOV AX,[BX] immediately before the register form. LEA returns BX. LES and LDS load the destination register from the word at DS:BX and the segment register from the word at DS:(BX+2). Each test initializes AX to the word at DS:BX so the setup preserves the visible registers and flags.
A4-A7, AA-AF For REP-prefixed string instructions, CX is masked to 7 bits. This provides a reasonable test length, as the full 65535 value in CX with a REP prefix could result in over one million cycles.
C6, C7 Only ModR/M reg = 0 is documented for these immediate MOV encodings. The 8086 ignores this field. The regular v2 profiles use reg = 0. Tests with nonzero values are in v2_undefined.
D0.6, D1.6, D2.6, D3.6 On the Intel 8086, SETMO (D0.6, D1.6) sets all destination bits to one. SETMOC (D2.6, D3.6) does the same if CL is nonzero.
On the Harris CP80C86-2, these opcodes execute SETLO. Each iteration replaces x with x XOR (x - 1) at the operand width. D0.6 and D1.6 perform one iteration, and D2.6 and D3.6 perform CL iterations. On both CPUs, a count of zero leaves the operand and flags unchanged.
D2, D3 The OF flag is undefined in the case that CL > 1. Using the flag mask from metadata.json will not validate correctness when CL is 0 or 1.
Later Intel CPUs limited the number of shifts possible by masking CL to 5 bits. However, the 8088 does not mask the value of CL, so shifts of up to 255 are possible.
CL is masked to 6 bits in the test suite to shorten the possible test length while still hopefully catching the case where CL may be improperly masked to 5 bits.
E4, E5, EC, ED All reads of IO port addresses should return 0xFF or 0xFFFF and incur no wait states.
F0 The LOCK prefix is not exercised in the v1 test suite. It is exercised in the v2 test suite at a 2.5% probability.
F1 F1 is an alias for the LOCK prefix. It is not exercised in this test suite.
F4 v1 and v2/core omit HLT. A halted CPU needs an interrupt before it can read the next opcode from the queue. See Testing HLT on the 8086.
D4, F6.6, F6.7, F7.6, F7.7 These instructions can generate a divide exception (more accurately, a Type-0 Interrupt).
When this occurs, cycle traces continue until the first byte of the exception handler is fetched and read from the queue. The IVT entry for INT0 is set up to point to 1024 (0x0400).
NOTE: On the 8088 specifically, the return address pushed to the stack on a divide exception is the address of the next instruction. This differs from the behavior of later CPUs and generic Intel IA-32 emulators.
F6.5, F7.5 Presence of a REP prefix preceding IMUL will invert the sign of the product. This was not tested in v1. In v2, REP prefixes are prepended to 10% of IMUL tests.
F6.7, F7.7 Presence of a REP prefix preceding IDIV will invert the sign of the quotient. Therefore, REP prefixes are prepended to 10% of IDIV tests.
FE Forms with a ModR/M reg field of 2-7 are undefined. The undefined core suites cover all eight register operands (mod = 11b) for each of these extensions. Each test sets up TMPB and IND with MOV AX,[BX]. The far forms (FE.3 and FE.5) take the destination IP from TMPB and read one byte at DS:(BX+2) for the low byte of CS.
FF v2/core tests both register and memory operands for near CALL (FF.2), near JMP (FF.4), and PUSH (FF.6 and the undocumented FF.7). Its far CALL (FF.3) and far JMP (FF.5) tests use only memory operands. The undefined core suites cover the register forms (mod = 11b). Here MOV AX,[BX] leaves the word at DS:BX in TMPB and BX in IND. The far transfer takes IP from TMPB and reads CS from DS:(BX+2).

FAQs and General Advice

Why Are Instructions Longer Than Expected?

Instruction cycles begin from the cycle in which the CPU's queue status lines indicate that an instruction "First Byte" has been fetched (QS==0b01).

Instruction cycles end when the queue status lines indicate that the first byte of the next instruction has been read from the queue. If the instruction started fully prefetched and the next instruction byte was present in the queue at the end of the instruction, the instruction cycles should reflect the documented best-case timings. If the queue was empty at the end of execution, the extra cycles spent fetching the next instruction byte may make the instruction take longer than the documented timings. There is no indication from the CPU when an instruction ends - only when a new one begins. The 8086 can execute the final cycle of an instruction on the same cycle the first byte of the next instruction is read via the NXT microcode flag.

ModR/M Handling

One simple thing that is easy to miss: when BP is referenced in an EA calculation, the default base register is SS, not DS.

The x86 16-bit ModR/M table

Segment Wrapping

The 8086 has wrapping semantics for segment addressing math. This means that a word accessed at segment 1000h and offset FFFFh will access one byte at 1FFFFh (1000:FFFF) and the second at 10000h (1000:0000). The 8086 will wrap the entire address space as well at FFFFFh, rolling over to address 0 (in the IVT). This is the reason for the IBM AT's infamous A20 gate.

The stack on the 8086 grows downwards, and thus the stack pointer (SP) is decremented by 2 on each PUSH. SP can therefore wrap from 0 to FFFE or from 1 to FFFF if unaligned.

How Do I Handle Undefined Flags?

The 8086 ISA specifies that certain instructions leave one or more flags in an undefined state after execution. These flags are not indeterminate, but their state across steppings, models and CPU generations was not guaranteed.

It is up to you if you wish to emulate undefined flags. There is real software that depends on them, such as Microsoft Flight Simulator 2. In addition, utilities such as CheckIt may fail to correctly identify your emulated CPU. In the worst case scenario, this could lead to incorrect code selection and crashes.

If you wish to skip validation of undefined flags, you can use one of the provided flag masks. In the v2 suite, an RMSK chunk provides a mask for the FLAGS register in each test, so no external reference is required.

I have produced a guide to the behavior of the 8086's undefined flags. See 8086_UNDEFINED_FLAGS.md

Handling Divide Exceptions

If you are validating memory operations for both addresses and values, you might struggle a bit with IDIV exceptions. When the CPU enters the divide-exception handler, it pushes the FLAGS register, including several undefined flag bits, onto the stack. It is annoying to emulate the undefined flags for IDIV in a traditional instruction-stepped emulator, as flags are repeatedly calculated in a loop within the microcode division algorithm.

The v2 MOO format files contain an EXCP chunk in the event that a interrupt 0 divide exception occurs; this chunk provides the physical address of the FLAGS word pushed to the stack.

One good way to detect a divide exception is if a test suddenly performs two successive reads at addresses 00000 and 00002.

8086.csv

The included 8086.csv is table of all 8086 instructions.

This is non-exhaustive list of columns present:

Column Brief meaning for 8086
op Opcode byte, hexadecimal.
g Instruction group number.
ex ModR/M opcode extension, /0–/7.
rm Specific ModR/M byte match; unused here.
ud Undefined/undocumented encoding
pf Opcode is a prefix.
fc Flow-control instruction.
fpu Coprocessor/FPU escape instruction.
uc Hardware carry-update enable.
fb Hardware forces byte-sized operation.
w Opcode bit 0 selects byte/word size.
d Opcode contains a source/destination direction bit.
sr Hardware selects a segment-register operand.
ar Hardware selects accumulator AL/AX.
nea Suppresses automatic effective-address operand read.
io Port I/O instruction.
flds Opcode field annotation, e.g. dw, sr, tttn.
mc Microcode entry address, hexadecimal.
mnemonic Primary instruction mnemonic.
alt_names Alternative mnemonics/aliases.
lck Marks LOCK-compatible instruction forms.
rep Marks repeatable string instructions.
reg Allows ModR/M register form (mod=11).
m Instruction has a ModR/M byte.
copt1 Operand 1 in coder notation, e.g. r/m8.
copt2 Operand 2 in coder notation, e.g. r8.
gop1 Operand 1 in geek notation, e.g. Eb.
gop2 Operand 2 in geek notation, e.g. Gb.
f_tested Flags read/tested.
f_mod Flags that may be modified.
f_def Flags with defined results.
f_undef Flags with undefined results.
f_values Fixed flag values: uppercase=set, lowercase=cleared.
exceptions Exception metadata; empty here.
description Short instruction description.
  • Coder and geek refer to the operand notation used by mazegen/x86reference.
  • Flag strings use ODISZAPC order: overflow, direction, interrupt, sign, zero, auxiliary carry, parity, carry. A dot means unlisted; an empty field means no information reported in that category.

metadata.json

The included metadata.json file lists which instructions are undocumented or undefined and provides masks for undefined flags.

{
    "url": "https://github.com/SingleStepTests/8086/",
    "version": "1.0.0",
    "syntax_version": 2,
    "cpu": "8086",
    "cpu_detail": "Intel P80C86A-2 782003 J20",
    "generator": "arduino808X",
    "date": "2025",
    "opcodes": {
        "00": {
            "status": "normal"
        },
        "01": {
            "status": "normal"
        },
        "02": {
            "status": "normal"
        },
        "03": {
            "status": "normal"
        },
        ...

In metadata.json, opcodes are listed as object keys under the opcodes field. Each key is the opcode written as a two-digit hexadecimal string. Each opcode entry has a status field which may be normal, prefix, alias, undocumented, undefined, or fpu.

An opcode marked prefix is an instruction prefix. These opcodes will not have individual tests. An opcode marked alias is simply an alias for another instruction. These exist because the mask that determines which microcode address maps to which opcode is not always perfectly specific. An opcode marked undocumented has well-defined and potentially useful behavior, such as SETMO and SETMOC. An opcode marked undefined likely has unusual or unpredictable behavior of limited usefulness. An opcode marked fpu is an FPU instruction (ESC opcode).

If present, the flags field indicates which flags are undefined after the instruction has executed. A flag is either a letter from the pattern odiszapc indicating it is undefined, or a period, indicating it is defined. The flags-mask field is a 16-bit value that can be applied with an AND to the flags register after instruction execution to clear any flags left undefined.

An opcode may have a reg field which will be an object of opcode extensions/register specifiers represented by single-digit string keys - this is the "reg" field of the ModR/M byte. Certain opcodes may be defined or undefined depending on their register specifier or opcode extension. Therefore, each entry within this reg object will have the same fields as a top-level opcode object.

Reference Emulators

Below is a list of emulators that can pass the entire v2 corpus, validating every single cycle, bus state and flag, including undefined instructions and flags.

  • XTCE-Blue
  • Neetan (transpiled version of XTCE-Blue's microcoded 808X core)

Does your emulator pass 100%? Let me know and I'll add it here.

Related x86 Test Suites

About

A Hardware-Generated CPU Test Suite for the Intel 8086

Resources

Stars

22 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages