CP/M-386

CP/M‑386 is CP/M for 386 protected mode, derived from CP/M‑68K.



Overview

CP/M‑386 is currently in the very early development stages.

Hardware support

  • Compatible with 386 (and later systems) with 2MB (or more) memory.
  • Systems using either PC BIOS or UEFI (with CSM) are supported.
  • VGA, 8042 PS/2, 8250/16450/16550 UART, CMOS RTC, and 8253/8254 PIT are supported.

CP/M compatibility

CP/M‑386 should be highly source‑compatible with other implementations:

SystemBDOS coverage
CP/M‑68K 1.3100%
CP/M 2.2100%
CP/M‑Plus74%
DOS‑Plus62%
MP/M 2.150%

The system currently reports BDOS 2.2 to applications.

  • The CP/M‑386 BDOS is at full parity with CP/M‑68K 1.3 and CP/M 2.2.
  • A large majority of the CP/M‑Plus (CP/M 3) BDOS is also supported.
  • More than 60% of the DOS‑Plus additions have been implemented.
  • Approximately half of the MP/M extensions have been completed.
    • The missing functionality is largely the multi‑user, multi‑tasking, message queuing, and process control calls that don't apply to a single‑user CP/M implementation.
  • Unique CP/M‑386‑specific BDOS extensions have been added to accommodate new features like direct video access, high‑resolution timing, PRNG, etc.

Build requirements

The following dependencies are required to compile CP/M‑386:

Be sure to use cpmtools version 2.23 or later. Older versions may appear to work but have several known bugs.

Downloads

Compilation

Building CP/M‑386 is supported on the current releases of NetBSD and FreeBSD, as well as Red Hat Enterprise Linux 9 (or later), CentOS Stream 9 (or later), and Fedora 36 (or later).

  • GCC build (recommended):
    make -Orecurse -j "$(nproc 2> /dev/null || printf '%s' 1)"
    

  • Clang build:
    make -Orecurse -j "$(nproc 2> /dev/null || printf '%s' 1)" CC="clang" OPTFLAGS="-O1"
    

  • It is recommended to use GCC as Clang‑compiled i386 code is larger.
    • Clang‑compiled builds will need to use OPTFLAGS=-O1 (or -Os or -Oz) to avoid exceeding the 384 KiB allocated for the ramdisk, or the kernel size + Ring-0 stack exceeding conventional memory.
  • Be sure to make clean if switching compilers or adjusting compiler flags.
  • You may need to adjust the make -j argument depending on your operating system (e.g., gnproc, sysctl -n hw.ncpu, getconf NPROCESSORS_ONLN, psrinfo -p).
  • 32‑bit support libraries are required to run the test suite (make test).
  • At the time of writing, FreeBSD is shipping non‑functional cpmtools2 packages with broken mkfs.cpm functionality. To successfully build on FreeBSD, you must rebuild cpmtools and ensure it is not linked with libdsk. If you receive a Disc rejected by driver error on FreeBSD from mkfs.cpm, your tools are broken and cannot be used to build CP/M‑386.

Docker build

If you are unable to build CP/M‑386 natively on your system, a Docker‑based Fedora build is available.

  • First, build the cpm386/cpm386-build container:
    docker build --progress plain -t cpm386/cpm386-build:latest -f Dockerfile .
    

  • Next, build CP/M‑386 using this container:
    docker run --rm -v "$(pwd -P)":/src -w /src cpm386/cpm386-build:latest \
      make -Orecurse -j "$(nproc 2> /dev/null || printf '%s' 1)"
    

Additional targets (i.e., clean, test, lint, update-readme) and builds using the Clang compiler (CC="clang" OPTFLAGS="-O1") are also supported.

Build output

  • The build produces four primary artifacts:
    FileDescription
    cpm386.elfMultiboot kernel image
    floppy.imgBootable 3.5" 1.44MB floppy disk image
    fd.imgBlank CP/M 3.5" 1.44MB floppy disk image
    hd.imgBlank CP/M 8MB hard disk image

  • The mboot.sh convenience script (tested on GNU/Linux systems with GRUB2) can be used to create bootable multiboot media (such as a USB drive or SD card) using the cpm386.elf file.
  • The floppy.img file can be written directly to a 1.44MB floppy disk.
    • NOTE: This disk image does not contain a CP/M filesystem. It can be removed from the drive once system is up and running.
  • The blank images are useful because CP/M‑386 does not yet have a FORMAT utility.

QEMU testing

  • Multiboot kernel (recommended):
    qemu-system-i386 -m 2M -serial stdio -monitor none -kernel "cpm386.elf"
    

  • Floppy boot sector loader:
    qemu-system-i386 -m 2M -serial stdio -monitor none -drive if=floppy,format=raw,file="floppy.img" -boot a
    

QEMU notes

  • Use -nographic -display none -vga none to disable VGA video (and use only serial console).
  • Use -serial none to disable the serial UART (and use only VGA console).

  • Use make disks to create empty disk images. To attach them to QEMU, use:
    -drive if=floppy,format=raw,file="fd.img"
    -drive if=ide,format=raw,file="hd.img",index=0
    

Included utilities

ProgramDescription
ACLOCKDV.386aclock (VGA text console version)
ACLOCKVT.386aclock (ANSI terminal version)
ALVTST.386Get Allocation Vector test (DRV_ALLOCVEC, BDOS 27)
CAPSLOCK.386Caps‑Lock key behavior utility (BDOS 235)
CLEARTPA.386Clears (zeros) and optionally verifies the TPA
CLS.386Clear screen (BDOS 221)
DELAY.386Delay test (P_DELAY, BDOS 141)
DEMO.SUBSUBMIT demonstration
DUMPDIR.386Directory entry dump utility (F_SFIRST/F_SNEXT, BDOS 17/18)
DUMPFCB.386File control block dump utility (F_OPEN, BDOS 15)
ED.386ED (A WIP port of the DRI CP/M Context Editor, August 1982)
ENV.DATEnvironment data file
ESCTILDE.386Escape and Tilde key behavior utility (BDOS 237)
FPARSE.386Filename parsing test (F_PARSE, BDOS 152)
GETSN.386Display serial number (S_SERIAL, BDOS 107)
GFXTEST.386Graphics and framebuffer demo (BDOS 229/230/231/233)
HD.386Hex dump utility
HELLO.386Hello world - the first CP/M‑386 program! (C_WRITESTR, BDOS 9)
ILLEGAL.386Ring‑3 protection and exception handler test
IOTEST.386File I/O BDOS tests
JULIA.386Draw a Julia set fractal (terminal version)
LRBC.386Query and/or set Last Record Byte Count
LS.386List files (with sizes)
MANDEL.386Draw a Mandelbrot set fractal (terminal version)
MEM.386Memory map utility (BDOS 227/228)
MORE.386UNIX more‑style pager
NUMLOCK.386Num‑Lock key behavior utility (BDOS 236)
OD.386Octal dump utility
PAUSE.386Wait for keypress (C_RAWIO, BDOS 6)
PIP.386PIP (A port of Zilog CP/M-Z8000 PIP v1.0A, January 1984)
PRINTENV.386Print environment and system data
PRNG.386PRNG test and demo utility (BDOS 253/254)
PROFILE.SUBSUBMIT script (automatically executed at boot)
RC.386Return code test and query (P_CODE, BDOS 108)
README.TXTSample text file
REBOOT.386Reboot utility (BDOS 220)
RM.386UNIX rm‑like interactive file deletion utility (F_DELETE, BDOS 19)
SEROFF.386Disable serial console (BDOS 223)
SERON.386Enable serial console (BDOS 223)
STAT.386STAT (A port of Zilog CP/M‑Z8000 STAT v1.0C January 1984)
SYNC.386Synchronize disks (DRV_FLUSH, BDOS 48)
TERMTEST.386Terminal and keyboard test utility
TEST110.386String delimiter test (C_DELIMIT, BDOS 110)
TEST211.386Numeric format test (C_DECNUM, BDOS 211)
TEXTMODE.386Query and/or set the text mode and cursor state (BDOS 229/230/231/234)
TICKS.386High‑resolution timer tests (BDOS 225/226)
TOD.386Get (and set) Time of Day clock (T_SET/T_GET, BDOS 104/105)
TOUCH.386Create an empty file (F_MAKE, BDOS 22)
TRUNCATE.386File truncation utility (LRBC aware)
TRUNCTST.386Truncation tests (F_TRUNCATE, BDOS 99)
TSEC.386Get date and time (T_SECONDS, BDOS 155)
VER.386Display OS version (S_OSVER, BDOS 163)
VGAFONT.386Load a text console font or restore the ROM font (BDOS 232)
VGAOFF.386Disable VGA text console (BDOS 222)
VGAON.386Enable VGA text console (BDOS 222)
VGATEXT.386VGA text direct access demo (BDOS 224)

Contributing

  • Do not open pull requests with large amounts of LLM‑generated code. These will be immediately rejected.
  • There is no AI‑generated code in the core operating system at this time (though there are AI‑generated tests, comments, and analysis), as the project is intended to be as much of a learning experience for me as it is a useful OS port.
  • Usage of AI (artificial intelligence) tools by contributors is currently permitted, subject to the same terms and conditions as the LLVM AI Tool Use Policy, but this permission may be withdrawn at any time and without notice.

Future plans

See FUTURE.md.

Code statistics

LanguageFilesLinesBlankCommentCodeComplexityBytesUloc
C744637387407948296856065128257817674
C Header24334464814851211111233051647
Assembly819393394181182147942999
Makefile21774340218121637158915860
Markdown3609740535025577473
Shell12918662143308316114
Linker Script22073901680515996
Dockerfile1938127334312778
YAML188615670389071
Total116547181028010158342806512155880921905

Mirrors

License

  • CP/M‑386 is distributed under the terms of the permissive MIT License.
  • Bryan W. Sparks of DRDOS, Inc. dba DeviceLogics LLC, successor in interest to Digital Research, Inc.’s CP/M assets, explicitly grants an unlimited authorization to use, distribute, modify, enhance, and otherwise make available CP/M technology, including the CP/M operating systems and their derivatives.