CP/M‑386 is CP/M for 386 protected mode, derived from CP/M‑68K.
- Overview
- Hardware support
- CP/M compatibility
- Build requirements
- Downloads
- Compilation
- Docker build
- Build output
- QEMU testing
- QEMU notes
- Included utilities
- Contributing
- Future plans
- Code statistics
- Mirrors
- License
Overview
CP/M‑386 is currently in the very early development stages.
- Full 32‑bit protected mode implementation with Ring‑3 TPA.
- Bootable via 3.5" 1.44MB floppy disk boot sector or Multiboot kernel.
- Supports VGA text (
0xB8000) and/or COM1 serial (9600/N/8/1,0x3F8) consoles. - No CD/USB/network/sound/other drivers (yet).
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:
| System | BDOS coverage |
|---|---|
| CP/M‑68K 1.3 | 100% |
| CP/M 2.2 | 100% |
| CP/M‑Plus | 74% |
| DOS‑Plus | 62% |
| MP/M 2.1 | 50% |
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:
- AWK
- Cpmtools†
- GNU Binutils
- GNU Coreutils
- GNU GCC or LLVM Clang
- GNU Make
- LZ4
- NASM
- QEMU (required only for testing)
†Be sure to use cpmtools version 2.23 or later. Older
versions may appear to work but have several known bugs.
Downloads
- Download the current CP/M‑386 build.
- View the GitLab CI/CD logs.
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-Osor-Oz) to avoid exceeding the 384 KiB allocated for the ramdisk, or the kernel size + Ring-0 stack exceeding conventional memory.
- Clang‑compiled builds will need to use
- Be sure to
make cleanif switching compilers or adjusting compiler flags. - You may need to adjust the
make -jargument 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
cpmtools2packages with brokenmkfs.cpmfunctionality. To successfully build on FreeBSD, you must rebuildcpmtoolsand ensure it is not linked withlibdsk. If you receive aDisc rejected by drivererror on FreeBSD frommkfs.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 Linux distribution, a Docker‑based Fedora build is available:
docker build --progress plain -t cpm386/cpm386-build:latest -f Dockerfile . docker run --rm -v "$(pwd -P)":/src -w /src cpm386/cpm386-build:latest
Build output
- The build produces four primary artifacts:
File Description 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.shconvenience 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 thecpm386.elffile. - The
floppy.imgfile 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
FORMATutility.
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 noneto disable VGA video (and use only serial console). - Use
-serial noneto disable the serial UART (and use only VGA console).
- Use
make disksto 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
| Program | Description |
|---|---|
ACLOCKDV.386 |
aclock (VGA text console version) |
ACLOCKVT.386 |
aclock (ANSI terminal version) |
ALVTST.386 |
Get Allocation Vector test (DRV_ALLOCVEC, BDOS 27) |
CAPSLOCK.386 |
Caps‑Lock key behavior utility (BDOS 235) |
CLEARTPA.386 |
Clears (zeros) and optionally verifies the TPA |
CLS.386 |
Clear screen (BDOS 221) |
DELAY.386 |
Delay test (P_DELAY, BDOS 141) |
DEMO.SUB |
SUBMIT demonstration |
DUMPDIR.386 |
Directory entry dump utility (F_SFIRST/F_SNEXT, BDOS 17/18) |
DUMPFCB.386 |
File control block dump utility (F_OPEN, BDOS 15) |
ED.386 |
ED (A WIP port of the DRI CP/M Context Editor, August 1982) |
ENV.DAT |
Environment data file |
ESCTILDE.386 |
Escape and Tilde key behavior utility (BDOS 237) |
FPARSE.386 |
Filename parsing test (F_PARSE, BDOS 152) |
GETSN.386 |
Display serial number (S_SERIAL, BDOS 107) |
GFXTEST.386 |
Graphics and framebuffer demo (BDOS 229/230/231/233) |
HD.386 |
Hex dump utility |
HELLO.386 |
Hello world - the first CP/M‑386 program! (C_WRITESTR, BDOS 9) |
ILLEGAL.386 |
Ring‑3 protection and exception handler test |
IOTEST.386 |
File I/O BDOS tests |
JULIA.386 |
Draw a Julia set fractal (terminal version) |
LRBC.386 |
Query and/or set Last Record Byte Count |
LS.386 |
List files (with sizes) |
MANDEL.386 |
Draw a Mandelbrot set fractal (terminal version) |
MEM.386 |
Memory map utility (BDOS 227/228) |
MORE.386 |
UNIX more‑style pager |
NUMLOCK.386 |
Num‑Lock key behavior utility (BDOS 236) |
OD.386 |
Octal dump utility |
PAUSE.386 |
Wait for keypress (C_RAWIO, BDOS 6) |
PIP.386 |
PIP (A port of Zilog CP/M-Z8000 PIP v1.0A, January 1984) |
PRINTENV.386 |
Print environment and system data |
PRNG.386 |
PRNG test and demo utility (BDOS 253/254) |
PROFILE.SUB |
SUBMIT script (automatically executed at boot) |
RC.386 |
Return code test and query (P_CODE, BDOS 108) |
README.TXT |
Sample text file |
REBOOT.386 |
Reboot utility (BDOS 220) |
RM.386 |
UNIX rm‑like interactive file deletion utility (F_DELETE, BDOS 19) |
SEROFF.386 |
Disable serial console (BDOS 223) |
SERON.386 |
Enable serial console (BDOS 223) |
STAT.386 |
STAT (A port of Zilog CP/M‑Z8000 STAT v1.0C January 1984) |
SYNC.386 |
Synchronize disks (DRV_FLUSH, BDOS 48) |
TERMTEST.386 |
Terminal and keyboard test utility |
TEST110.386 |
String delimiter test (C_DELIMIT, BDOS 110) |
TEST211.386 |
Numeric format test (C_DECNUM, BDOS 211) |
TEXTMODE.386 |
Query and/or set the text mode and cursor state (BDOS 229/230/231/234) |
TICKS.386 |
High‑resolution timer tests (BDOS 225/226) |
TOD.386 |
Get (and set) Time of Day clock (T_SET/T_GET, BDOS 104/105) |
TOUCH.386 |
Create an empty file (F_MAKE, BDOS 22) |
TRUNCATE.386 |
File truncation utility (LRBC aware) |
TRUNCTST.386 |
Truncation tests (F_TRUNCATE, BDOS 99) |
TSEC.386 |
Get date and time (T_SECONDS, BDOS 155) |
VER.386 |
Display OS version (S_OSVER, BDOS 163) |
VGAFONT.386 |
Load a text console font or restore the ROM font (BDOS 232) |
VGAOFF.386 |
Disable VGA text console (BDOS 222) |
VGAON.386 |
Enable VGA text console (BDOS 222) |
VGATEXT.386 |
VGA 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 some 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
| Language | Files | Lines | Blank | Comment | Code | Complexity | Bytes | Uloc |
|---|---|---|---|---|---|---|---|---|
| C | 74 | 46336 | 8739 | 7922 | 29675 | 6062 | 1280486 | 17599 |
| C Header | 24 | 3344 | 652 | 1472 | 1220 | 11 | 122859 | 1618 |
| Assembly | 8 | 1865 | 327 | 413 | 1125 | 1 | 46692 | 965 |
| Makefile | 2 | 1706 | 333 | 215 | 1158 | 352 | 56926 | 823 |
| Markdown | 2 | 529 | 58 | 0 | 471 | 0 | 21756 | 418 |
| Shell | 1 | 291 | 86 | 62 | 143 | 30 | 8298 | 114 |
| Linker Script | 2 | 207 | 39 | 0 | 168 | 0 | 5137 | 95 |
| YAML | 1 | 86 | 6 | 15 | 65 | 0 | 3679 | 69 |
| Dockerfile | 1 | 47 | 8 | 12 | 27 | 4 | 1310 | 34 |
| Total | 115 | 54411 | 10248 | 10111 | 34052 | 6460 | 1547143 | 21640 |
Mirrors
- The canonical home of this software is
https://gitlab.com/johnsonjh/cpm386, with a mirror on GitHub.
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.