Compiling FreeDOS
From Zet
We are going to compile the FreeDOS kernel and freecom (command.com replacement). After setting the build environment, we'll be able to change its source code for customizing it. We are going to do it in Linux.
First of all, FreeDOS must be compiled in a DOS or Windows environment, so the first thing we are going to do is set up a virtual machine to do our tests. Bochs is being used as a virtual machine because of its internal debugger and disassembler, and the possibility of mounting the virtual hard disks.
Contents |
Bochs setup
In Ubuntu, we need to install 4 packages: bochs, bochsbios, bochs-x and bximage.
Next, we create the image and configuration directory. In my case, the path will be /home/zeus/zet/freedos', but you can choose what you want.
CDROM image
We need to download the base FreeDOS image which is just 8Mb in the directory specified above:
cd /home/zeus/zet/freedos wget http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.0/fdbasecd.iso
Hard disk image
And we create the hard disk image, which will be about 50Mb long:
bximage -hd -mode=flat -size=50 -q c.img
Configuration file
In the current directory, we create a file named .bochsrc with the following lines:
romimage: file=/usr/share/bochs/BIOS-bochs-legacy vgaromimage: file=/usr/share/vgabios/vgabios.bin ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 ata0-master: type=disk, path="c.img", mode=flat, cylinders=101, heads=16, spt=63 ata0-slave: type=cdrom, path="fdbasecd.iso", status=inserted boot: cdrom
Booting bochs
To boot this newly created virtual machine, we execute bochs -q in the command line. This will bring up Bochs interface and the system will boot with the CD image we just downloaded, with the FreeDOS logo appearing in the screen.
FreeDOS 1.0 installation
In the boot menu, we just press ENTER. A text mode menu will appear, we choose the default option of installing to harddisk by pressing ENTER.
The installation program appears. The first screen is the language. We select English as default by pressing ENTER. Next, we need to prepare the harddisk, which is the default option selected, so we press ENTER again.
The eXtended FDisk appears with its welcome screen, where we just press ENTER. The 50Mb hard disk appears, we press six times the ENTER key to create a primary partition (several questions will appear, we just select the default options). We are ready. We just press F3 and exit selecting YES and INTRO in the question to write the Partition Table. After that, it asks us to reboot the system, where we press ENTER again and the system will reboot.
We repeat the same steps above, by pressing ENTER in the boot screen, and ENTER again in the harddisk installation menu. Now comes again language selection, where we accept pressing ENTER. Now, it's time to format the partition, we just press ENTER, and YES in the confirmation prompt. Next, we continue with the installation by pressing ENTER in the menu, and ENTER again to start copying files.
The GPL license text appears, we just press any key twice. Next, it asks for the installation directory, where we accept the default C:\FDOS directory by pressing ENTER twice. The list of commands that are to be copied appears, we just press ENTER twice and it starts copying files.
After the files have been copied, we just press any key in the other disks prompt and the configuration starts, after a while the system reboots and FreeDOS is installed.
Now, in order to boot the hard disk, we have to edit the config file .bochsrc we created before and change the line boot: cdrom to boot: disk.
Compiler, assembler and source code setup
OpenWatcom 1.0
We are going to use OpenWatcom 1.0. So, the first thing we need are the files. We can get them from ftp://ftp.openwatcom.org/archive/zips-1.0/ (we need 11 files):
wget ftp://ftp.openwatcom.org/archive/zips-1.0/c_doswin.zip wget ftp://ftp.openwatcom.org/archive/zips-1.0/clib_a16.zip wget ftp://ftp.openwatcom.org/archive/zips-1.0/clib_d16.zip wget ftp://ftp.openwatcom.org/archive/zips-1.0/cm_clib_a16.zip wget ftp://ftp.openwatcom.org/archive/zips-1.0/cm_clib_d16.zip wget ftp://ftp.openwatcom.org/archive/zips-1.0/cm_clib_hdr.zip wget ftp://ftp.openwatcom.org/archive/zips-1.0/cm_core_all.zip wget ftp://ftp.openwatcom.org/archive/zips-1.0/cm_core_doswin.zip wget ftp://ftp.openwatcom.org/archive/zips-1.0/cm_core_dos.zip wget ftp://ftp.openwatcom.org/archive/zips-1.0/core_doswin.zip wget ftp://ftp.openwatcom.org/archive/zips-1.0/ext_dos4gw.zip
After that, we are going to unzip them into Bochs virtual hard disk:
mkdir hd/ sudo losetup /dev/loop0 ./c.img -o 32256 sudo mount /dev/loop0 -o loop ./hd cd hd/ sudo mkdir watcom/ cd watcom/ for i in $(ls ../../*.zip); do sudo unzip -o $i; done cd ../../
Turbo C++ 1.01
This is the compiler recommended for the freecom build. We can get it from the Borland museum, but they require us to register. They don't check a valid email. We save the file tcpp101.zip in the directory /home/zeus/zet/freedos as above, and unzip it:
cd hd/ sudo mkdir tcpp101/ cd tcpp101/ sudo unzip ../../tcpp101.zip cd ../../
nasm 0.98.39
For the assembler, we are going to use nasm version 0.98.39. For that, we go to the download page and select the file nsm09839.zip.
After downloading it, we unpack it into the virtual hard disk:
cd hd sudo mkdir nasm16 sudo unzip ../../nsm090839.zip cd ../../
FreeDOS kernel source download
We navigate to the main FreeDOS website and click on the link source code on the left, in the developers menu. We will see that for downloading the source code, we need to do it via subversion:
cd hd/ sudo mkdir src/ cd src/ svn export https://freedos.svn.sourceforge.net/svnroot/freedos/freecom/trunk freecom cd ../../
Note: Seems that the kernel trunk does not link well. Here is the alternative: http://www.fdos.org/bootdisks/autogen/source_core.zip We can also download the format program:
wget http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/dos/format/format-0.91v.zip cd hd/src/ sudo mkdir format/ cd format/ unzip ../../../format-0.91v.zip cd ../../../
And the fdisk program:
wget http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/dos/fdisk/fdisk121.zip cd hd/src sudo mkdir fdisk/ cd fdisk/ unzip ../../../fdisk121.zip cd ../../../
Finally we unmount the hard disk and release the loop device:
sudo umount ./hd sudo losetup -d /dev/loop0
Turbo C++ installation
Now, we are ready to install the Turbo C++ and start compiling the source. For doing that, we enter the bochs virtual machine:
bochs -q
Inside the virtual machine, once is booted:
cd \tcpp101 install
In the installation program, we hit ENTER to continue and select drive C, the source path is the default \TCP101. After that, we press ENTER and accept the default paths selecting Start installation at the end and pressing ENTER. The installation finally ends and we exit pressing ENTER twice.
We have to edit \autoexec.bat and add to the variable PATH the TC binary path:
set PATH=%dosdir%\bin;C:\TC\bin
Source code compilation
Kernel build
In the virtual machine:
cd \src\kernel copy config.b config.bat edit config.bat
This file must have the following variables set:
set XNASM=c:\nasm16\nasm.exe set COMPILER=WATCOM set WATCOM=c:\watcom set PATH=%PATH%;%WATCOM%\binw set XUPX= set XLINK=..\utils\wlinker /ma /nologo set XCPU=86 set XFAT=16
After creating the file config.bat with these lines, now we can start to compile with build. After a while, it will end compiling and the makefile will copy the resulting files to the subdirectory bin/.
freecom build
To compile the command.com (freecom), we need to cd into the source directory, inside the virtual machine and copy the file config.std:
cd \src\freecom copy config.std config.mak
We have to change two lines:
CC_BASE_PATH = C:\TC NASM = C:\nasm16\nasm.exe
And delete the line -1- of the options flags. After this, we only have to execute build and it will start compiling.
When the command.com will be compiled, you'll find it in the current directory, we'll copy it to the output directory of the kernel to install it afterwards:
copy command.com ..\kernel\bin
format build
To compile the format.com, we need to edit two files:
cd \src\format\source\format edit turboc.cfg
And put these two lines:
-IC:\BORLANDC\INCLUDE -LC:\BORLANDC\LIB
We have to edit too the file userint.c and change the line 43: from #if (__TURBOC__) to #if 0. Next, we can make, and copy the program:
make copy format.exe ..\..\..\kernel\bin
fdisk build
To compile fdisk, we first unzip the CAT database:
cd \src\fdisk\source unzip cats396S.zip cd cat../src/ edit makefile.tc
Installation
To test if this kernel works, we'll need to create an empty floppy disk image. To do so, we first shutdown the virtual machine and execute the bximage command like before:
bximage -fd -size=1.44 a.img -q
And we add to the config file .bochsrc the following line:
floppya: 1_44="a.img", status=inserted
Then, we can boot the virtual machine again with bochs -q. And type inside:
cd \src\kernel\bin format a: install copy format.exe a:\
The system will be tranferred, and then we can try to boot with this floppy disk. To do so, we switch off the virtual machine and change the configuration option for the boot drive in .bochsrc:
boot: floppy
We can try it, executing bochs -q. The floppy disk should boot with our recently compiled system. We should note so because while booting, we can see the build date.

