OS!!!

Printhan vigneswaran
4 min readOct 1, 2022

--

Introduction

These blog article series explain how we can develop our own x86 operating system. Since this is a complex task, we can divide the whole task into several chapters. With this week’s we are going to learn how we can set up our developing environment and how to boot the small operating system

The tools we going to use

First, let’s decide what tools and technologies we going to use in our implementation so that we can get started.

Host Operating System- we will be using Ubuntu as our host operating system. It’s a good practice to install your host OS on a virtual machine like VirtualBox test your OS.

After Installing ubuntu in a virtual machine, we should install following packages using apt-get for this.

NASM is the Assembler used to write the assembly code. Bochs is the best emulator for x86 platform So, we used bochs as the emulator for this.

Booting Process

Booting an operating system consists of transferring along a chain of small programs each one more “powerful” than the previous one, where the operating system is the last “program”. See the following figure for an example of the boot process.

An example of the boot process. Each box is a program.

Writing CAFEBABE to EAX

Now we will write smallest possible OS that can use with GRUB. The only thing do by this is writing OXcafebabe to EAX.

Compiling the operating system

We use assembly code to write the booting part of the operating system.

Save above code in a file named loader. s to generate a 32-bit ELE object file

Linking the Kernel

Following linker script used to produce an executable file to load the kernel at a memory address larger or equal to 1MB

Save above code in a file named link.ld .

By using following command, we can get the kernel.elf executable file.

Obtaining GRUB and Generating the ISO Image

Here binary file of GRUB Legacy stage2_eltorito bootloader built by GRUB 0.97 is used for this. This file can be downloaded by the following link:

copy this ‘stage2_eltorito’ to the working directory.

This operating system needs to store in a bootable media CD or USBs. So, to create ISO image we used following command.

Now we Generated the iso image OS. iso using above command. This contains the kernel executable, GRUB bootloader and the configuration file.

Then we created the following directories in the folder. Then copy the stage2_eltorito binary file in the iso/boot/grub folder. Then copy the kernel.elf executable linked format file to iso/boot directory. Now we created a configuration file for GRUB named menu.lst using following code. This file says where the kernel is located and some configurations.

Running Bochs Emulator

As the final step, we created a configuration file to start Bochs using following code and named its as bochsrc.txt.

Depending on how you installed Bochs, you may need to acclimate the path to romimage and vgaromimage. You can relate to Boch’s official website to find out further about Bochs configuration. Save the configuration train as ‘bochsrc. Txt’ and run Bochs with the following command.

bochs -f bochsrc.txt -q

Then you can see like this,

Give continue on terminal

Then you can see like this,

Bochs should now be running and presenting a console with some information on it. Quit Bochs and display the log generated by Bochs with the command below:

cat bochslog.txt

The contents of the registers of the CPU replicated by Bochs should now appear somewhere in the output. Your OS has successfully booted if you see RAX=00000000CAFEBABE or EAX=CAFEBABE in the output.

Congratulations We just created a simple Operating System. Next week we’ll see how can get the help of C programming Language to further develop our OS.

References:

The Little OS Book: https://littleosbook.github.io/book.pdf

Thank you very much for reading!

--

--

Printhan vigneswaran

Software Engineering Undergraduate at University of Kelaniya