OS Development on Windows

OS Development on Windows

Introduction

This tutorial describes how to build and execute a boot loader and kernel from within windows in a signle click in order to facilitate RAD of kernels and subsystems. The batch script detailed is meant to deploy to a sub directory (OSD/build) and only contains the code to build and deploy a simple kernel for the sake of simplicity.

Required Tools

The following tools are used in this build and test process, I recommend them all:

  • NASM – The Netwide Assembler, my choice assembly compiler, there are others but I like this one and it’s reliable.
  • DJGPP – c/c++ compiler that works with windows, more dependable than CygWin in my opinion.
  • Bochs – virtual machine sandbox with great flexibility.
  • Ultra ISO – ISO creation tool (I use the v9.2 trial and it works fine – no nag screen via command line execution).

build.bat – 1 click build and execution

The batch file below assumes a few things, adjust locations or substitute environment variables as needed inline if you want to risk it:

  • build.bat is located in your base project directory at H:\Projects\OS_cpp\
  • You have the build.bat file located in a directory containing bochs.exe, a src/ and an OSD/ directory
  • Within your OSD/ directory you have a build/ directory – everything in this directory will be incorporated in your image
  • Your UltraISO executable is located at D:\Program Files\UltraISO\UltraISO.exe
  • Your Bochs executable is located in the same directory as build.bat
  • Your Bochs configuration is located in the subdirectory OSD/ and named default.cfg
  • Your linker file is located alongside your source at src/link.ld

rem #########################
rem Building and Deploying
rem #########################
gxx -c src/video.cpp -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions
gxx -c src/kernel.cpp -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions
nasm -f aout src/start.asm -o start.o
ld -T src/link.ld -o kernel.bin start.o kernel.o video.o
del *.o
rem #########################
rem Making Drive Image
rem #########################
rm "OSD/build/kernel.bin"
mv kernel.bin "OSD/build/kernel.bin"
rm "OSD/drive.iso"
"D:\Program Files\UltraISO\UltraISO.exe" -directory "H:\Projects\OS_cpp\OSD\build" -bootfile "H:\Projects\OS_cpp\OSD\build\kernel.bin" -output "H:\Projects\OS_cpp\OSD\drive.iso"
rem #########################
rem Executing
rem #########################
bochs -f "OSD/default.cfg"

OSD/default.cfg – Default Bochs Configuration

The default.cfg file detailed below configures Bochs as follows:

  • 32 MB RAM
  • ROM and VGA ROM images located in ODS/bios/ from the build.bat directory (these are attainable from the Bochs website)
  • A CD ROM drive on ata0 with it’s image loaded from OSD/drive.iso (as defined in buidl.bat)
  • Boot from CDROM
  • Log to bochsout.txt within the same directory as build.bat
  • No mouse support

Adjust this file as needed – this is just to get started.

megs: 32
romimage: file="OSD/bios/BIOS-bochs-latest"
vgaromimage: "OSD/bios/VGABIOS-elpin-2.40"
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=cdrom, path="OSD/drive.iso", status=inserted
boot: cdrom
log: bochsout.txt
mouse: enabled=0

Hope this information can be of use to someone, more will likely come as time allows.

About the Author