A Simple OS Design & Implementation — Using Assembly Language

Maleesha Mihiranga
4 min readJul 31, 2020

Introduction

This is simple guidance of showing how to implement an OS using Assembly language to show hardware information on a computer. In this article, this task is performed in Linux based OS called Ubuntu.

Structure

  • source/ — Contains the entire OS source code
  • source/bootload/ — Source to generate BOOTLOAD.BIN, which is added to the disk image when building
  • source/features/ — Components of GOS such as FAT12 support, string routines, the BASIC interpreter, etc
  • source/kernel.asm — The core kernel source file, which pulls in other source files
  • programs/ — Source code for programs added to the disk image

Pre-requisites for this task

Basic knowledge of assembly language is needed for this.

mkisofs — This is to generate a CD-ROM ISO image of AMOS

sudo apt-get install cdda2wav cdrecord mkisofs

NASM — This tool can be installed using a terminal in Ubuntu following code.

sudo  bash  apt-get  install  nasm

QEMU — This is an emulator and this is to run .flp/.iso file that we needed. Code to install this tool is,

sudo  bash  apt-get  install  qemu-system-x86

Above mentioned tools should be installed prior to coding of OS.

Codes

All code lines for this OS can be obtained from here.

Building

Linux

Build requirements: the NASM assembler, dosfstools package, ‘mkisofs’ utility, and root access. We need root access because we loopback-mount the floppy disk image to insert our files.

To build GOS, open a terminal, and switch into the expanded GOS package. Enter “sudo bash” in Ubuntu-flavoured distros, or just su in others, to switch to the root user. Then enter:

./build-linux.sh

This will use NASM to assemble the bootloader, kernel, and supply programs, then write the bootloader to the gos.flp floppy disk image in the disk_images/ directory. (It writes the 512-byte bootloader to the first sector of the floppy disk image to create a boot sector and set up a DOS-like filesystem.) Next, the build script loopback-mounts the gos.flp image onto the filesystem — in other words, mounting the image as if it was a real floppy. The script copies over the kernel (kernel.bin) and binaries from the programs/ directory, before unmounting the floppy image.

With that done, the script runs the ‘mkisofs’ utility to generate a CD-ROM ISO image of GOS, injecting the floppy image as a boot section. So we end up with two files in the disk_images/ directory: one for floppy disks and one for CD-Rs. You can now use them in an emulator or on a real PC as described in the Running section above.

Windows

Get the latest version of NASM for Windows from this site (look for the ‘win32’ package. Then extract the nasm.exe file into your Windows folder (or somewhere in the path).

The ImDisk Virtual Disk Driver is needed since Windows does not have a built-in mechanism for loopback drives. Get it from here (or Google it if the link is outdated). After downloading run imdiskinst.exe to install. Follow the default prompts during the install. Also get PartCopy for copying the bootloader on to the disk image.

To build GOS, double-click on build-win.bat or run it from the command line. This batch file calls NASM to do the work needed to compile GOS and its applications. This script mounts the floppy disk image as if it were a real disk, using:

imdisk -a -f gos.flp -s 1440K -m B:

You can use that command outside of build-win.bat if you want to add files to gos.flp, and unmount it with:

imdisk -d -m B:

Lastly, to test in the QEMU PC emulator, Extract QEMU to somewhere on your computer — C:\ is best. Then enter: the following to run GOS under QEMU:

qemu.exe -L . -m 4 -boot a -fda gos.flp -soundhw all -localtime

Others

Along with the scripts for building on Linux and Windows, you’ll also find scripts for Mac OS X and OpenBSD. These have not been as thoroughly tested as the others,

If you want to make a build script for a new platform, it needs to:

  1. Assemble the bootloader and add it to the first sector of gos.flp
  2. Assemble the kernel and copy it onto the floppy
  3. Assemble the add-on programs and copy them onto the floppy

So you will need some way of copying the 512-byte bootsector into a floppy image, and loopback mounting the image to copy across the kernel and programs.

Running the OS

Now we can now use amos.iso /Amos.flp in an emulator or on a real PC. In here we used qemu for this and code for that is (when we are using qemu ):

sudo  bash  qemu-system-x86  -soundhw  pcspk  -drive  format=raw,file=disk_images/amos.flp,index=0,if=floppy

If we are running this OS in windows we can use virtual box and amos .iso

--

--