Build MS-DOS 4.0

Just recently the following news appeared on Habré:

MS-DOS 4.00 source code published on GitHub under MIT license

. Once the source codes appeared, it immediately became interesting:

Is it possible to build this operating system?

The task turned out to be non-trivial and not at all obvious. It turns out that DOS source files don't transfer easily to git, and certainly not as UTF-8 text files. But, fortunately, unlike the leaked MS-DOS 6.0 sources, there is a complete set of files and tools sufficient for correct assembly and testing. There were mere nuances that drank a lot of blood.

Therefore, I, like many, began my experiments in assembling MS-DOS 4.0, with error correction, as well as the ability to study source codes and test them on real hardware.

The article provides a brief guide to assembling and creating a boot floppy disk.

Tools

I will collect everything in Linux Mint (read Ubuntu). I chose dosbox as the DOS environment for the build; unfortunately, this is not the best option, because it slows down the frequency (so that old programs work correctly), so the build takes quite a long time. It is best to use any convenient DOS running in a virtual machine.

To create a boot floppy disk and test the resulting assembly, I will use the qemu virtual machine. And to get floppy disks with a ready-made image, I will use the MS-DOS 4.0 installation floppy disk (found here see 4.00 OEM [Sampo]).

Before we go any further, an important note:

I don’t intend to infringe on anyone else’s rights; all modifications to the code were made solely for humorous purposes and are not subject to distribution. Modified sources have been removed.

What are the difficulties of assembly?

Two problems:

  1. Incorrect initialization of environment variables (in the bat file itself SETENV.BAT contains errors or typos).
  2. Problems with encoding when transferring code from DOS floppy disks to GIT with UTF-8 encoding.

The first problem can be easily corrected even on your own, with a quick analysis of the source code. It can be easily opened during assembly; then you just need to make changes, or create your own updated bat file, which will initialize the environment variables.

The situation is much more complicated due to the fact that in part of the code, when transferred to UTF-8, some characters were broken. I tried to build it, which I described in my LiveJournaland in the end I got this:

This is a fairly common and painful problem with old DOS-era sources. I encountered a similar problem when trying to build the RAM View program. I wrote in detail about this path and fixing the problem in the article Editing someone else's code.

Here we will eliminate manual labor and automate the correction of encoding problems.

Preparatory operations before assembly

So, the steps to build DOS. Clone the original repository:

git clone https://github.com/microsoft/MS-DOS.git

Fixing problems with encodings:

sed -i -re 's/\xEF\xBF\xBD|\xC4\xBF|\xC4\xB4/#/g' MS-DOS/v4.0/src/MAPPER/GETMSG.ASM
sed -i -re 's/\xEF\xBF\xBD|\xC4\xBF|\xC4\xB4/#/g' MS-DOS/v4.0/src/SELECT/SELECT2.ASM
sed -i -re 's/\xEF\xBF\xBD|\xC4\xBF|\xC4\xB4/#/g' MS-DOS/v4.0/src/SELECT/USA.INF 

Go to the working folder:

cd MS-DOS/v4.0

Let's recode all text files into MS-DOS format:

find -iname '*.bat' -o -iname '*.asm' -o -iname '*.skl' -o -iname 'zero.dat' -o -iname 'locscr' | xargs unix2dos -f
find -iname '*.BAT' -o -iname '*.ASM' -o -iname '*.SKL' -o -iname 'ZERO.DAT' -o -iname 'LOCSCR' | xargs unix2dos -f

and create an updated bat file there for environment variables, with the following content:

$ cat src/e.bat
@echo off
echo setting up system to build the MS-DOS 4.01 SOURCE BAK...
set CL=
set LINK=
set MASM=
set COUNTRY=usa-ms
set BAKROOT=e:
rem BAKROOT points to the home drive/directory of the sources.
set LIB=%BAKROOT%\src\tools\bld\lib
set INIT=%BAKROOT%\src\tools
set INCLUDE=%BAKROOT%\src\tools\bld\inc
set PATH=%BAKROOT%\src\tools;%PATH%

In principle, these operations are enough for assembly, and what is below is my personal hooliganism to demonstrate that DOS is actually assembled and there is no substitution of files. I replace Microsoft with my nickname:

find -name "*.ASM" -type f -exec sed -i 's/Microsoft/Dlinyj/g' {} +
find -name "*.INC" -type f -exec sed -i 's/Microsoft/Dlinyj/g' {} +
find -name "*.H" -type f -exec sed -i 's/Microsoft/Dlinyj/g' {} +
find -name "*.MAC"  -type f -exec sed -i 's/Microsoft/Dlinyj/g' {} +
find -name "*.MSG"  -type f -exec sed -i 's/Microsoft/Dlinyj/g' {} +
find -name "*.C"  -type f -exec sed -i 's/Microsoft/Dlinyj/g' {} +
find -name "*.CLB"  -type f -exec sed -i 's/Microsoft/Dlinyj/g' {} +
find -name "*.SKL"  -type f -exec sed -i 's/Microsoft/Dlinyj/g' {} +

That's it, now the sources are prepared so that they can be compiled correctly.

Assembly

I will assemble it in dosbox, as practice has shown – this is not the best solution, assembly takes about an hour, which, to put it mildly, is annoying.

I launch dosbox:

dosbox

Next, I mount the current directory in it as drive E.

mount e: ./

And go to drive e, run the bat file in dosbox, which initializes the environment, and begin the build:

e:
cd SRC
e.bat

and start the build with the nmake command:

If you do this in dosbox, then you can go for a walk. The finished build will look like this:

After this, you need to copy all the collected files into one directory. Create a directory “4” in the root of the disk and copy all the binaries using a special script:

mkdir \4
CPY.BAT \4

Next is the most interesting:

checking that the files run. To do this, you need to make dosbox pretend to be old DOS. We run the following command:

ver set 4.0

Then we go to the directory \4 and you can do it in it command.com:

The hooliganism worked, DOS got together and pretends that I developed it. All that was left was to test it on real hardware.

Creating a boot floppy

Next, I thought of simply mounting an empty floppy disk image in dosbox, and transferring system files directly from the collected files with the command:

sys <path> a:

But the fakir was drunk, and the trick failed. Therefore I decided MBR (

Master Boot Record

) borrowed from the DOS 4.0 boot floppy. Unfortunately, the MBR from MS-DOS 6.22 did not work for me.

Download the installation floppy disks, and at the same time create an empty floppy disk with the command:

truncate --size 1474560 fdd.img

We boot from the installation floppy and install our empty 1.44 MB floppy image into drive B using qemu:

qemu-system-i386 -fda Disk01.img -fdb fdd.img

Cancel the installation and format the floppy disk with the transfer of system files:

When finished, you can close the qemu window. We return to the dosbox window and mount the resulting floppy disk image using the following command:

imgmount a: <path to fdd.img> -t floppy

And then we just manually transfer the files

COMMAND.COM

,

IO.SYS

And

MSDOS.SYS

to floppy disk:

That's it, the image is ready. You can test it in a virtual machine, or even burn it to a real floppy disk and boot!

To run in qemu you should use the following command:

qemu-system-i386 -fda fdd.img

You can write to a floppy disk using the dd command; I use a USB-FDD drive.

sudo dd if=fdd.img of=/dev/sdk status=progress

And, yes! This system works successfully on real hardware. In this case, the check takes place on a 386 computer.

conclusions



Running freshly assembled MS-DOS 4.0 on real hardware

I won't lie, assembling MS-DOS 4.0 turned out to be not so simple. I had to watch some videos and scour various repositories. But it’s still a wonderful experience that allows you to look inside the historical sources and delve into them.

The long-ago leak of MS-DOS 6.0 was incomplete and it was not possible to assemble it. And now researchers have ready-made tools to practice developing some of their own modules of the old operating system.

Of course, I'm really looking forward to the release of the MS-DOS 6.22 source code, as I still hope to see it in my lifetime.

Good luck with your experiments!

Useful links:

  1. MS-DOS source codes from Microsoft
  2. Example of building MS-DOS 4.0 in FreeDOS (video)
  3. Compiling MS-DOS 4.0 from DOS 4.0, on a PS/2!

If you are interested in metalworking, old iron, all sorts of DIY things, trashing and linux, then you can Follow me also on telegram.


You might also want to read this:

News, product reviews and competitions from the Timeweb.Cloud team – in our Telegram channel

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *