m68 runs 68000 Linux elf, Motorola hex, and CP/M 68K binaries on Windows, macOS, and Linux.
m68 loads binaries into memory then emulates the Motorola 68000 and required system calls to execute them.
C and C++ programs in the c_tests folder can be built with a 68000 cross compiler on most platforms. I've run buildgcc-8.2.0.sh on Windows 11 running on AMD64 and Ubuntu running on both Arm64 and AMD64 to build the GNU gcc 8.2.0 cross compiler. See Building GCC for 68000 for details.
On Apple Silicon macOS, buildgcc-macos.sh builds a native 68000 cross-compiler; see the setup instructions below. On Raspberry Pi 5, the Linux Arm64 cross-compiler can be used.
I also tested with gcc 13.2.0 built from https://github.com/haarer/toolchain68k on Windows for AMD64 and Ubuntu for AMD64 and Arm64. It almost certainly works on other platforms as well. The Ubuntu Arm64 cross compiler works on the Raspberr PI 5 as well. One thing that doesn't work with 13.2.0 is the test application ttypes.c, which causes gcc to go into an infinite loop. I've used an ifdef to remove the offending lines. Lots of other compilers have no problem with ttypes.c.
The build scripts m.bat and m.sh in the c_tests folder can be used to build samples on Windows, macOS, and Linux. mm68.bat and mm68.sh build the m68 emulator targeting the 68000 so the emulator can run itself recursively. mall.bat and mall.sh build all of the test apps.
The test apps in the c_tests folder build with newlib and have the required BSP stubs for newlib to call into Linux-like system calls emulated by m68. m68start.s has the assembly code that initializes newlib then calls main(). newlib68.c has the small wrappers that are called by newlib then make Linux-style system calls into the m68 emulator via the Trap insruction. It's required to link these two object files with your C apps for them to link and run.
m68 can also load and run CP/M 68K .68k binary files. The cpm folder has the Digital Research C compiler, assembler, and linker along with some test .c and .s apps that can be built and run. Those tools all run in m68 along with the binaries they produce. Same for the Pascal and BASIC compilers in the mtpascal and CB68 folders. The DDT debugger works in the emulator including instruction tracing and breakpoints.
Trap 0 is used for linux-style syscalls, trap 2 and trap 3 are used for CP/M 68K, and Trap 15 is used to mimic the Peter J. Fondse 68k emulator
I've built and tested m68 on Amd64 on Windows and Ubuntu as well as Arm64 on Raspberry PI OS, Ubuntu, and macOS. Tested on a Arm32 Raspberry PI 4. It also builds with GCC targeting 68000 (mm68.bat/mm68.sh in c_tests) and that runs in any other build of m68 recursively. I've also tested on RISC-V 64 using hardware running Debian and in the RVOS emulator.
M68 can run the NTVAO 6502 + Apple 1 emulator built for 68000 targeting Linux. Same for NTVCM (Z80 + CP/M 2.2), NTVDM (8086 + DOS 3.3), ARMOS (Arm64 + Linux), x64os/x32os (AMD64/x86 + Linux), SPARCOS (Sparc v8 + Linux), and RVOS (RISC-V + Linux). All of these can be found in sister repos.
All test cases can run with plain m68, m68 nested in itself, or m68 running in ARMOS or RVOS for versions built for Arm64 or RISC-V 64.
usage: M68
arguments: -e just show information about the elf executable; don't actually run it
-h:X # of meg for the heap (brk space). 0..1024 are valid. default is 40
-i if -t is set, also enables instruction tracing with symbols.
-l when a LF (10) is output, allow Windows to add a CR (13) beforehand
-m:X # of meg for mmap space. 0..1024 are valid. default is 40. 0 for CP/M.
-p shows performance information at app exit
-t enable debug tracing to m68.log
-v used with -e shows verbose information (e.g. symbols)
files:
- m68.cxx: Loads programs and OS services (Linux-style syscall() or CP/M 68K BDOS) from apps
- linuxem.h: Defines syscall IDs. Same values as for RISC-V 64 and Arm64.
- m68000.cxx: Emulates a 68000
- m68000.hxx: Header for the 68000
- djl_con.hxx: Console / terminal related functionality
- djl_mmap.hxx: Support for mmap syscalls.
- djl_os.hxx: Abstracts various OS, CPU, and compiler-specific concepts
- djltrace.hxx: Used for tracing status and instructions
- m.bat/m.sh: Builds debug versions of m68 on Windows or Linux/macOS
- mr.bat/mr.sh: Builds release versions of m68 on Windows or Linux/macOS
- runall.bat/runall.sh: Runs test apps in c_tests to validate m68. Use argument "nested" to run the 68000 c_tests\m68.elf in the native m68.
- baseline_test_m68.txt: Expected results of runall.bat/runall.sh test scripts
- mgr.bat/mclr.bat: Builds m68 on Windows using gcc and clang. clang and gcc versions of m68 are about 14% faster than msft C++.
- words.txt: Dictionary file for the AN test app
Test files in the hexapps folder are Motorolla hex files generated by Peter J. Fondse's 68000 IDE + emulator. More information is here: m68k
c_tests folder (test apps + newlib stubs with Linux syscall support)
- m68start.s: _start and syscall() for C/C++ apps built with newlib
- newlib68.c: stubs called by newlib() for primitives including exit, open, close, etc. Also, printf/sprintf/fprintf overrides of newlib that support floating point (%f, %lf), 8-byte integers (%lld), and size_t integers (%zd).
- m.bat/m.sh: builds C++ apps on Windows and Linux
- mm68.bat/mm68.sh: builds the m68 emulator for the 68000 to run nested as another test case.
- mall.bat/mall.sh: builds all test apps on Windows/Linux
- ma.bat/ma.sh: builds .s 68000 assembly file apps
- *.c: various test apps in C and C++. All are built as C++.
- tbcd.s: validates the 3 68000 BCD instructions
- tshift.s, taddsubm.s, tea.s, tt68.s, ttt68u.s, tchk.s: other test cases written in assembly, generally for when C can't validate instrutcions.
cpm folder:
- standard distribution of the Digital Research C compiler, assembler, and linker with support files
- e.c, sieve.c, tm.c, ttt.c: apps that can be built with the C compiler running in m68
- ttt68u.s: a 68000 assembly version of ttt with loops unrolled for performance.
- e68.s and sieve68.s: 68000 assembly versions of these benchmarks
- tchk.s: validates the chk instruction since I can't get the compilers to generate code using it
- m.bat/m.sh: builds C apps
- ma.bat/ma.sh: builds .s assembly apps that link with the C runtime
- maa.bat/maa.sh: builds .s assembly apps that don't require the C runtime
- mf.bat/mf.sh: builds C apps that use floating point
- mall.bat/mall.sh and runall.bat/runall.sh: builds and runs all test cases
cpmcv11 and cpmcv12 folders:
- older versions of the C compiler. v11 can't build and/or run some of the tests. The C runtime has a stack corruption when using printf.
- these compilers generate slower code than the one in the cpm folder. None of the compilers work with floating point.
mtpascal folder:
- standard distribution of the Digital Research MT Pascal compiler
- e.pas, sieve.pas, ttt.pas: apps that can be built with the Pascal compiler running in m68
- m.bat/m.sh: builds Pascal apps
- mall.bat/mall.sh and runall.bat/runall.sh: builds and runs all test cases
cb68 folder:
- standard distribution of the Digital Research BASIC compiler
- DDT.68K and DDT68000.68K: debugger
- e.bas, sieve.bas, ttt.bas: apps that can be built with the BASIC compiler running in m68
- m.bat/m.sh: builds BASIC apps
- mall.bat/mall.sh and runall.bat/runall.sh: builds and runs all test cases
com folder: (More information about COM can be found here: https://github.com/johnsonjh/com-cpm/tree/master/COM)
- COM.68K: CP/M v2.2 + 8080 emulator for CP/M 68K. I've tested it running in m68 using a variety of CP/M v2.2 tools in my cpm_compilers repo.
- MBASIC.COM: Microsoft BASIC interpreter
- TTT.BAS/E.BAS/ASCIIART.BAS/SIEVE.BAS/HELLO.BAS: various test programs for mbasic.
- TTTCPM.COM: cp/m 2.2 app to prove you can't win at tic-tac-toe
- COM.68K running in m68 was tested with Wordstar as well.
- COM.68K doesn't compute the Parity Even flag for the 8080 correctly with the ADI instruction. Sources for the newer version rewritten in C appear to fix this bug.
- The Parity Even bug means that apps generated by the Manx C Vers. 1.06D 8080 compiler (and other versions) fail to run correctly.
ntvcm folder:
- mntvcm.bat: Windows build script for my ntvcm repo. ntvcm gives full Z80 + CP/M 2.2 emulation running inside of m68.
- tested with a Z80 validation app and a variety of cp/m 2.2 apps including Wordstar. Plus 77 CP/M compilers and interpreters.
ntvao folder:
- mntvao.bat: Windows build script for my ntvao repo. ntvao is an Apple 1 emulator with WozMon and WozBasic
- validated with assembly, C, and BASIC apps along with a 6502 instruction validation app.
rvos folder:
- mrvos.bat: Windows build script for my rvos repo. rvos is a RISC-V 64 + Linux emulator.
- validated running the rvos test suite in that repo with rvos running in m68.
svsfor and svspas folders:
- Silicon Valley Software FORTRAN and Pascal compilers
- *.sh and *.bat: scripts to build and run test apps
- e.pas, ttt.pas, sieve.pas, mm.pas, e.for, ttt.for, sieve.for, mm.for: test apps
forth83 folder:
- 68000 Forth 83 version 2.1.0
- m.bat/m.sh: invokes the interpreter for a Forth file
- e.f, sieve.f, ttt.f: sample Forth apps
- runall.bat/runall.sh: runs all of the sample Forth apps
- this does not run on physical CP/M 68K machines that don't make address 0x500 available. F83.68K is non-relocatable and must load there.
relocatable f86 describes how to hack f83.68k to run on such hardware, but this impacts performance of the interpreter.
elfto68k folder:
- converts Linux-style 68000 ELF executables to CP/M 68K .68K executables
- tested most of the .c apps in c_tests except those that require more RAM than my hardware has, directories, or a real-time clock.
- elfto68k.cxx: converts .elf files built for 68000 with a newlib BSP targeting CP/M 68K and linked statically.
- m.bat/m.sh: builds elftl68k
- nlcpm.c implements a newlib BSP targeting CP/M 68K
- startcpm.s: implements assembly portions of the newlib BSP targeting CP/M 68K
- mt.bat/mt.sh: builds a single test app
- runall.bat/runall.sh: builds and runs the test apps in m68
- words.txt: support file for the an.c test app
aztec68k folder: (requires a DOS emulator to run, such as https://github.com/davidly/ntvdm)
- Aztec C68K 3.6b Rom 6-6-88 Copyright 1982-88 Manx Software Systems, Inc.
- Stock distribution that can be found in many places on the internet.
- I added the tests folder that contains CP/M 68K C runtime support: .begin startup, console, and file I/O.
- The tests folder also includes C test cases for the compiler and C runtime.
- This compiler is old and requires use of the K&R syntax, but floating point works, making it better than the other C compilers.
- It also generally generates faster and smaller binaries than the C compiler that's part of CP/M 68K. See the table below.
- This is a cross-compiler that runs on MS-DOS. Build scripts assume that ntvdm is in the path.
aztec68k_5.2a folder: same as aztec68k but for a later version of the compiler.
notes/bugs:
* Unlike the 68000, addresses aren't limited to 24 bits. Data in the high bits will be used as part of the address.
compiler and assembler benchmark performance:
- source code, tools, and build scripts for all benchmarks are in this repo
- DR = Digital Research
- SVS = Silicon Valley Software
- g++ = GNU C++ cross compiler m68k-elf-gcc (GCC) 8.2.0. Optimization level -O2 (-O3 generates faster code but it's often much larger)
- ms = milliseconds
- DR C v1.3 has text in cp68.68k that indicates v1.2, but it ships with CP/M 68K v1.3
- Dr C v1.1 initializes all free RAM to 0 on app startup; other compilers don't generate such code. m68 has a minimum of 1MB of heap space it initializes.
- times on the 68008 are with CP/M 68K and include significant (often relocatable) binary load times. These load times dominate overall runtimes.
- much of the g++ e benchmark instruction count is consumed by division calculations on full 32-bit integers. Other implementations use the 68000 div instruction for 32 over 16 bit quantities.
- Forth is interpreted, not compiled
- f83.68k won't load on my CP/M 68K device. The start address is 0x500, which is reserved on that machine. There is a documented hack available, but it changes performance.
- the BA compiler only supports 4-byte integers, which dramatically slows 68008 performance.
- assembly code always wins, though on hardware it's especially true due to smaller binary sizes.
The checked-in builder produces native macOS GCC 8.2.0 and binutils 2.32 tools targeting m68k-elf, with newlib 3.1.0 and the C++ runtime. It verifies downloaded archive checksums and applies the Darwin host/page-alignment fixes needed on Apple Silicon. The C test scripts link the project's startup and syscall adapters for m68; this is a newlib toolchain rather than Linux/glibc.
Install Xcode Command Line Tools and the Homebrew prerequisites, then build from the checkout:
xcode-select --install # If developer tools are not already installed.
brew install gcc@14 make gmp mpfr libmpc
cd ~/github/m68
JOBS=4 bash buildgcc-macos.sh
./mr.sh
bash c_tests/m.sh e 2 8.2.0
./m68 c_tests/e.elfThe default installation is $HOME/outrun/8.2.0. The Bash test scripts discover it automatically on macOS, so a PATH change is unnecessary. BUILD_DIR changes the build/download directory (default gcc-temp-macos); PREFIX changes the installation prefix. When using a custom prefix, set GCCPATH to that same prefix when building tests. CC/CXX can override the native Homebrew GCC 14 used to build the cross-compiler. Keep the build directory to resume completed stages; build logs are in its logs folder.
Build all C/C++ and assembly tests at one optimization level, or all five levels, with:
bash c_tests/mall.sh 2 8.2.0
for opt in 0 1 2 3 fast; do
bash c_tests/mall.sh "$opt" 8.2.0
doneThe C test outputs are c_tests/<name>.elf. elfto68k has separate builds and CP/M tests; its runall.sh accepts normal or nested, followed by the optimization level and GCC version. The converted suite defaults to -O1 (also in runall.bat) to reduce build time. With GCC 8.2.0, ttypes retains -O2: the compiler's xfgnulib mishandles conversion of LDBL_MIN to double, affecting out-of-line long-double comparisons at -O1. Inlining at -O2 avoids that path; the incorrect numeric output is not accepted into the baseline. An explicit optimization argument still selects the suite level, subject to this -O1 exception. Historical output comparisons can include host-, compiler-, and timing-dependent differences.
Python 3.7 or newer runs the regression tests on macOS, Linux, and Windows. Build the emulator and guest test binaries first using the instructions above. From the repository root:
python3 runall.py -j 4
python3 runall.py --only nantst --opt fast -j 4
python3 runall.py --suite c --no-compare -j 4
python3 runall.py --listOn Windows use py -3 runall.py (or python runall.py). Existing runall.sh
and runall.bat commands are thin launchers and forward their arguments.
Python owns the test lists, scheduling, output collection, and baseline comparison;
there is no separate shell/batch test list. test_suites.json defines this
repository's suites. The identical runall.py engine is vendored in each emulator
repository so normal testing needs no sibling checkout or Python packages.
The default worker count is the smaller of eight and the CPU count. Output is
collected in the original test order, regardless of completion order. The
scheduling policies in test_suites.json identify filesystem readers, writers,
and tests that can run freely. Writers that share a fixture group retain their
original order. Different fixture groups (for example trw.dat, trw2.dat, and
sorted.txt) can overlap, as can unrelated CPU tests. Directory scanners read
all fixture groups and exclude writers, while other readers can overlap them.
Waiting for a resource does not occupy a worker, so the scheduler can run
independent tests further down the queue.
sleeptm runs in parallel: its busy loop stops after elapsed wall time, so it
does not require a dedicated core. Explicit barriers and interactive terminal
tests still drain the pool. Scripts retain a global barrier unless their segment
explicitly sets serial: false and has an audited scheduling policy.
Noninteractive terminal tests are skipped without draining it. A checkout lock
prevents two runners from modifying the same fixtures simultaneously. --list shows resource constraints and global barriers.
Profiles without an audited scheduling policy retain the conservative legacy behavior.
The original transcript filenames and baselines are retained. Each transcript
also has a .stderr companion, and mismatches produce a .diff. A JSON results
report records test status, commands, exit codes, and duration. Comparison
normalizes checkout prefixes, inherited host timezone observations, address fields,
and file-search metadata; filenames and source sizes remain checked. Optional
termios header features accept only their known constant values. m68's compiler
transcript also ignores blank lines in legacy compiler banners.
The deliberately overflow-heavy ttypes test documents compiler-dependent
results. Comparison permits bounded float rounding (relative tolerance 2e-6)
and sumB variations for its affected int32/int16, uint32/int32, and
uint64/float pairs, while preserving the operation, types, dimensions, other
integer totals, and row count. Rust's r32 acos display permits 1e-6 relative
rounding. These are specific field rules, not a general numeric tolerance;
NaN/infinity, signed zero, missing rows, matrix results, and other output remain
strict. The JSON report records accepted numeric-line counts, and raw transcripts
retain the original values.
--output-dir PATH places reports outside the checkout. A nonzero runner exit
status indicates execution failures or remaining baseline differences.
--only accepts an application name or test-name glob (quote globs in the shell).
--opt selects optimization levels; both options disable full-suite baseline
comparison because they produce partial transcripts. Repeat --suite to select
multiple suites; use --list to inspect their tests. --no-compare checks execution
without comparing historical output. Missing binaries fail by default;
--skip-missing explicitly reports them as skipped. --timeout SECONDS limits
each process and kills its process tree on expiry; the default is unlimited.
The positional emulator selection is retained, for example python3 runall.py nested
or python3 runall.py rvos where supported by the built guest emulators. native
executes test binaries directly on a compatible host. --emulator PATH overrides
the executable, and repeatable --emulator-arg=-h:200 supplies arguments.
Runner scheduling, ordering, fixtures, failure handling, and timeout behavior can be checked without building guest programs:
python3 -m unittest discover -s tests -p test_runall.pyThe legacy compiler suites (such as CP/M and Pascal) run as jobs that invoke their existing platform-specific build/run scripts. Each folder's build/run sequence stays together, while different folders can run in parallel. CP/M also locks the shared BASIC code-generation output and its nested test binary. Those subordinate scripts retain their existing compiler and utility dependencies; the Python runner consolidates the emulator-level orchestration, not those build systems.
CP/M BDOS System Reset, BIOS cold/warm boot, and return through the loader's
initial return address complete successfully without interpreting scratch D0/D1
registers as exit codes. They preserve a return code explicitly set through the
existing BDOS 108 extension. Linux-style exit syscalls still use their explicit
exit argument. After building m68, run the shutdown regression tests with
python3 -m unittest discover -s tests -p test_cpm_exit.py.
The overall Python runner includes elfto68k/runall.sh,
aztec68k/tests/runall.sh, and aztec68k_5.2a/tests/runall.sh (their .bat
counterparts on Windows). Each build/run sequence locks its own directory and
can overlap the other suites. All output groups share one worker queue;
The audited start_first_suites policy moves these build suites ahead of the
main tests, with elfto68k first. This also lets directory scans see their
completed filesystem state. elfto68k has the highest scheduling priority.
Priorities apply only to independent jobs: shared-file ordering and explicit
barriers remain enforced. Transcript and report ordering stay unchanged.
--list displays priorities. To run just these additions:
python3 runall.py --suite elfto68k --suite aztec --suite aztec52They use their original working directories, build tools, input fixtures, and
baseline transcripts. elfto68k needs the m68k-elf cross-compiler; the Aztec tests
need ntvdm on PATH for the DOS compiler tools and a host C++ compiler for
symto68k. The selected emulator command is passed through to the child scripts.
They may take longer than the prebuilt C tests because they rebuild their guest
programs and support libraries. --timeout applies to each complete child suite.
Python owns their baseline comparisons when called through the overall runner,
so --no-compare applies to these suites too. Reports retain the original paths:
elfto68k/test_elfto68k.txt, aztec68k/tests/test_aztec.txt, and
aztec68k_5.2a/tests/test_aztec.txt. --output-dir puts collected reports elsewhere;
the child build scripts still create their normal artifacts in their directories.
Running a child script directly retains its standalone comparison behavior.
The two Aztec baselines contain historical Date: / Time: output and an MSVC
symto68k.cxx build banner; those differences remain visible during comparison. Use --no-compare to validate execution separately, as with the
original suites' variable timing and date output.
With all sibling emulator checkouts and their cross-compilers installed, build all six emulators for all six ISAs from the rvos checkout:
python3 tools/build-nested-emulators.py -j 4The builder writes <target-repository>/bin/<inner-emulator>; 32-bit x86 uses
x64os/x32bin/<inner-emulator> alongside the x64 bin directory. m68's startup
and newlib BSP objects are built privately, without replacing test objects.
--target m68 or --inner rvos restricts the matrix (both are repeatable).
--build-dir PATH retains objects and logs at a chosen location; the default is
a fresh temporary directory. NESTED_<TARGET>_CXX overrides a target compiler,
for example NESTED_RVOS_CXX=/usr/bin/riscv64-linux-gnu-g++.
In the repository whose test suite you want to run, choose the outer emulator:
python3 runall.py --outer rvos -j 4
python3 runall.py rvos --only tcmp --opt 2 --no-compare
python3 runall.py nested --only tcmp --opt 2 --no-compare--outer rvos and positional rvos select the sibling RISC-V host executable
and its bin/<this-emulator> binary, even when this emulator is rvos itself.
nested selects this emulator as the outer host. Omitting an outer/mode retains
normal execution through the host executable. --emulator PATH overrides the
outer executable while retaining automatic inner-binary selection. Legacy
suffixed binary locations are fallback options; canonical bin builds win.
For x32 tests use --variant x32os; as an outer host, --outer x32os selects
x64os/x32bin/<inner-emulator>.
The GCC 8.2.0/newlib 3.1.0 toolchain is installed locally as
gcc-8.2.0-linux on WSL and gcc-8.2.0 on Windows. Both target
m68k-elf with -mcpu=68000, matching the custom startup code and
newlib68.c syscall layer in c_tests. The Windows compiler executables
run directly in cmd.exe and include their host DLL dependencies.
Run ./mall.sh or mall.bat from c_tests to build the test cases and
nested emulator. The optional first argument selects the optimization
level (default 2); the optional second selects the installed GCC version
(default 8.2.0). On Linux, GCCPATH can override the installation prefix.
The root runall.sh / runall.bat use the Python runner; --suite c
selects these compiled tests, and --no-compare validates execution
without comparing historical output.
./m.sh # Debug: -O0 -g3, DEBUG defined, assertions enabled
./mr.sh # Release: -O3, NDEBUG definedBoth launchers work from any current directory and write the named emulator in
the checkout. Linux links statically by default; use STATIC=0 for dynamic
linking. macOS uses the selected SDK and normal system linking. The shared
tools/build-host.sh contains the platform and compiler selection.
Set CXX to a compiler executable (for example CXX=clang++ ./mr.sh).
CPPFLAGS, CXXFLAGS, LDFLAGS, and LDLIBS accept whitespace-separated
flags; additional quoted compiler arguments may be passed to either launcher.
Use OUTPUT=/path/to/emulator to choose another output, or
CXXFLAGS=-flto ./mr.sh to enable link-time optimization. --help lists the
interface. Old platform/compiler-specific host launchers have been removed;
Windows batch files and guest cross-compilation scripts retain their own roles.