KoizOS - Introduction

Introduction

It's taken me a few revisions revisions to figure out how exactly I want to write this series. At first, I made it like a tutorial and a how-to, but since I'm learning and realizing what I'm doing wrong, I'm straying away from that approach. This is now just a series of posts showing the journey of what I did and had to go through to get my operating system to work.

For the how-to / tutorial areas, instead of reinventing the wheel, I'm just contributing back to OSdev.org so I'll be referencing pages there instead.

Tooling

I first started with Rust, and then ended up just using C

I originally started with Rust for developing the OS and have been following the excellent tutorial listed here. However, it is a HUGE pain to get Rust working for all the OS development stuff. Many of the features you need to use in the language are experimental, and I actually discovered a bug within Rust itself that caused my OS to perform undesired behavior when handling Interrupts. It seems other users were having this issue, it was not yet addressed, and this ultimately was the last straw for me.  

After ditching Rust, I simply decided to develop my OS in C. This is mostly because it's the language I'm most familiar with for systems programming, and I'm fairly comfortable with exactly how C code translates down to assembly and is executed on the processor.

If you were curious you can still see a very old revision of my Rust implementation that I committed to master near the beginning.  

Regardless, I'm still optimistic and would love to Rust if I ever develop another OS once it's more fleshed out.

FASM

I've used GAS, NASM, and FASM, but I feel most comfortable with FASM. Interestingly, literally every guide out there uses NASM, so I had to translate some of the code to something that will work in FASM instead. Since others may decide to use FASM, I'll list out a few specific code segments that may help out anyone using FASM for their operating system.

WSL2

I primarily use Windows for development, mostly because WSL2 is actually pretty wonderful and I don't have to boot up a virtual machine or dual-boot my desktop whenever I want to switch from gaming to development. I run Debian and installed QEMU to test my operating system. I'm also using VcXsrc X Server to get a visual of my operating system. Since this was kind of a pain, I'm adding a section specifically to help others that may want to go down the WSL2 operating system development route. This also works for other applications outside just QEMU

My full source code is also available at the end for anyone who is curious

I'm also using  to visualize my operating system since I'm developing and testing this under Linux Subsystem for windows.

How to run a GUI Application under WSL2

1) Install WSL2 from the Microsoft Store. Make sure it's WSL2. I'm also using a Ubuntu 18.04 Kernel so your linux commands may be different if using a different distribution.

2) Run the following commands in WSL2 console to install QEMU

apt-get update

# For install xclock to test our XServer connection
apt-get install x11-apps

# For installing 32-bit QEMU on Ubuntu
apt-get install qemu-system-x86

# For installing 64-bit QEMU on Ubuntu
apt-get install qemu-system-x86_64

# Installs X-server on Ubuntu
apt-get install xvfb

2) Download and Install VcXsrv Windows X Server

[SourceForge Official Link]
[My Mirror | VirusTotal]

3) Run VcXsrv and set the following settings:

4) In your WSL2 console, run the following commands to

# Sets up display environment
export LIBGL_ALWAYS_INDIRECT=Yes
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0

# Example of running xclock to test our connection
xclock

5) With any luck, you'll see this screen!

Troubleshooting:

If you get a message like the image below. try messing around with the DISPLAY variable. Sometimes, one of these will work:

export DISPLAY=127.0.0.1:0.0
export DISPLAY=PCNAME:0.0

Next Steps

The next (or rather first) step is writing a bootloader for my custom OS! Stay tuned!