An Intel i860 XR CPU core in Swift, as a Swift package (library I860). It contains no
machine-specific code: a machine supplies its memory map through the I860Bus protocol
and runs the processor a number of instructions at a time.
It is a port of the i860 core of the Previous emulator, which is Jason Eckhardt's i860 emulator adapted for the NeXTdimension board; see NOTICE for the credits and the licence that follows from that.
Used by MacXT, a NeXT emulator for macOS, for the NeXTdimension board.
Swift 6 (tools version 6.0), macOS 13 or later.
dependencies: [
.package(url: "https://github.com/AgentiLoop/I860.git", from: "1.0.0")
],
targets: [
.target(name: "MyMachine", dependencies: [.product(name: "I860", package: "I860")])
]import I860
struct Board: I860Bus {
var ram = [UInt8](repeating: 0, count: 1 << 20)
mutating func readByte(at address: UInt32) -> UInt8 { ram[Int(address) & 0xFFFFF] }
// … readWord, readLong, writeByte, writeWord, writeLong, readBootByte
}
var board = Board()
var cpu = I860XR()
cpu.reset() // starts at $FFFFFF00 in CS8 boot mode
cpu.run(memory: &board, instructions: 1000)
print(cpu.pc, cpu[r: 1], cpu[.psr])The bus is the board's memory with the most significant byte first, as the
NeXTdimension presents it to its 68k host; the core applies the processor's own byte
order (cpu.bigEndian, EPSR.BE) on top. interruptRequest is the INT pin, sampled
after every cycle. needsAttention lets a bus end run early.
- The integer and control instructions, including the delayed branches and
bla. - The floating-point unit with its adder, multiplier and load pipelines, the dual
operations (
pfam,pfmamand their subtracting forms), and the graphics unit (faddp,faddz,form,fzchks,fzchkl,pst.d). - Dual-instruction mode.
- Paging with the translation look-aside buffer, the traps (instruction, data access,
instruction access, floating point, interrupt) and return from a trap with
bri. - Both byte orders and the CS8 boot mode.
Not modelled: the data cache, bus lock sequences (lock and unlock do nothing),
alignment traps, the data breakpoint register, floating-point exceptions other than
the source exception of frcp and frsqr, and timing. A cycle executes one
instruction, or the two of an aligned pair.
Arithmetic is the host's IEEE arithmetic; the fsr's directed rounding modes are applied to the round-to-nearest results from their exact error.
Where the Previous core differs from the Programmer's Reference Manual in a way that
software could notice, this port follows the manual; I860XR.swift lists the cases
(the lock, unlock and intovr encodings, OF after adds and subs, the ITI bit,
the layout of 64-bit operands in little-endian mode, and the pixel order of pst.d). None of them changes what that core does in big-endian
mode with whole-register stores, which is how the NeXTdimension software runs.
I860Disassembler.disassemble(_:at:) gives one instruction as text, and
cpu.instruction(at:memory:) the instruction the processor would fetch at an address.
GNU General Public License, version 2 or any later version (LICENSE), with the credit notice in NOTICE: this package is derived from the i860 core of Previous. A program that links this library is distributed under those terms too.
swift test runs 38 tests of instruction semantics against hand-assembled programs:
arithmetic and flags, both byte orders, branches and delay slots, control registers,
traps and interrupts, paging and the TLB, the floating-point pipelines, rounding modes,
the graphics unit and dual-instruction mode. They check this port against the manual
and the reference core's behaviour as read from its source; they are not a comparison
against a real processor. In MacXT the core runs the NeXTdimension's boot ROM through
its self-test and NeXT's i860 kernel and window server to the NeXTSTEP 3.3 Workspace.
I860_BENCH=1 swift test -c release --filter benchmark prints the core's speed.