Making your own operating system
The operating system is a system software that loaded to a computer and manages all hardware, applications, resources on a computer. Have you ever think about how an operating system is built? Do you have ever try to make your own operating system? It sounds like more difficult. But if you follow the correct steps and start doing it, in the end, you will feel awesome.
I tried out to make my own OS. It’s GimmyOS! :D For the operating system implementation, I followed the JOSH operating system tutorial written by Dr. Mohan Raj Dhanagopal. I followed that tutorial and now I would like to share the information with you.
JOSH OS implementation https://www.cs.bgu.ac.il/~yagel/dolev/MinimalOS/josh/
As I mentioned previously, if you follow the correct steps for this implementation, it is not a big deal to have success. Here we are going to have the design, display hardware information and little interrupt handling in our operating system. We are going to make a single-tasking operating system. Before starting the implementation, it is good to have a basic knowledge of working with Assembly language. There are many resources that you can learn about assembly language and the below tutorial helped me to have a better understanding of the language.
Assembly Language
https://www.youtube.com/watch?v=vtWKlgEi9js&list=PLPedo-T7QiNsIji329HyTzbKBuCAHwNFC
You can do the implementation in both Windows and Unix/ Linux operating systems. I tried it with a Linux operating system. You have to download NASM (nasmw.exe) for the development of the system.
As the first step of the implementation, we have to make the boot loader file. But where we keep it? We can create a virtual drive image (floppy image) and keep the boot leader and other relevant files there. Otherwise, our real hard drives and burning CD’s in our PC are at a risk stage.
How to make a floppy image? Type this command in your Linux terminal.
$ mkfs.msdos –C myfloppy.img 1440
You can mount the floppy image by typing this command.
$ sudo mount –o loop myfloppy.img /media/floppy/
From the below link you can have a detailed idea.
https://taufanlubis.wordpress.com/2016/01/04/virtual-box-how-to-create-floppy-disk-image/
Then you can download the bootloader code. If you see the JOSH tutorial you can see, you don’t have to change or write anything in the bootloader code. Therefore, download it and save it as boot.asm at the same directory you are working on.
Assemble the code with the following command.
$ nasm boot.asm –o boot.bin –f bin
Then we have to copy the boot image to the boot sector of the floppy image.
For Unix/ Linux users –
# dd if=boot.bin bs=512 count=1 of=/dev/fdo
For Windows users –
C:\NASM>Debug boot.bin
-W 100 0 0 1
-Q
C:\>
Now bootloader for your new operating system is ready. Next, we have to develop a kernel to be loaded.
In the JOSH OS tutorial, you can see code for the kernel that displaying a welcome message, waiting for a keypress to load the bootloader, doing interrupt handling, and for making the shell overview. This kernel implementation is done in 3 steps. You can download the lengthy code from the tutorial. Also, you can add your own functions for various commands.
You can save the file as kernel.asm and the following command will assemble the code.
$ nasm kernel.asm –o kernel.bin –f bin
Here you go! Now you have your own operating system.
After creating the operating system you can check some simple commands.
ver — You can check the version of the OS.
; display version
_cmd_ver:
mov si, strCmd0
mov di, cmdVer
mov cx, 4
repe cmpsb
jne _cmd_exit ;next command
info — You can get the hardware information of the operating system.
; display hardware info
_cmd_info:
mov si, strCmd0
mov di, cmdInfo
mov cx, 5
repe cmpsb
jne _cmd_displayHelpMenu ;next command
call _display_endl
call _display_hardware_info ;display Information
jmp _cmd_done
help — If any user doesn’t know any commands he or she can type help and see what are the commands in the operating system.
_cmd_displayHelpMenu:
call _display_endl
mov si, strCmd0
mov di, cmdHelp
mov cx, 5
repe cmpsb
jne _cmd_exitcall _display_endl
mov si, strHelpMsg1
mov al, 0x01
int 0x21
call _display_endl
mov si, strHelpMsg2
mov al, 0x01
int 0x21
call _display_endl
mov si, strHelpMsg3
mov al, 0x01
int 0x21
call _display_endl
jmp _cmd_done
exit - You can exit from the shell.
; exit shell
_cmd_exit:
mov si, strCmd0
mov di, cmdExit
mov cx, 5
repe cmpsb
jne _cmd_unknown ;next command
I previously mentioned that kernel implementation of the JOSH operating system has done in three steps. Below you can see first and the last versions of GimmyOS.
Now you have your own operating system with some specific commands. You can add more commands to display.
Also, you can see my Github repository.
https://github.com/wvGithmi/Own-OS
I hope you all now have an idea about how to implement your own operating system with a shell overview. By following the correct procedure you can make the OS without facing many difficulties. Of course, there are some other ways of implementing operating systems. Below in the resources section, you can find them. Go through them also and try these various implementations. Thank you for reading my article.
Resources:
https://medium.com/setublog/hands-on-to-operating-systems-a847e9dc75f7
https://www.instructables.com/id/Make-A-Simple-Operating-System/
https://medium.com/@abeysinghechamath/writing-your-own-operating-system-2e0909938249