user14618630
user14618630

Reputation:

How does a modern operating system work and how to make one from scratch?

I want to make a modern operating system but how does it work and from where should I start.

Upvotes: 1

Views: 363

Answers (1)

user123
user123

Reputation: 2884

You should probably start by choosing a development OS and a target processor. I would choose Ubuntu Linux as it is easy to use and has out of the box access to all required software to write and build a modern OS. It has Gedit as IDE which works well for most standalone development environment where you don't have access to libraries which aren't your own (like when you develop an OS). As to the target processor I would choose x86-64 as it is the most modern and widespread one.

I am personally in the process of developing a small minimal OS. I got a UEFI bootloader ready which loads an ELF file compiled with g++ into memory and then jumps to its entry point. It does some printing using the GOP provided framebuffer.

If I can give some tips one would be to start with a legacy bootloader. A legacy bootloader will teach you a lot more then going with a UEFI bootloader. Here's a few things you will learn writing a legacy bootloader:

  1. You will learn some processor history. How x86 started with the 8086. Then how protected mode arrived with segmentation, then paging. How long mode arrived with 4 levels paging and x86-64 processors.

  2. You will learn about segmentation and how it works.

  3. You will learn about paging in depth.

  4. You will learn how a computer boots in general and how a legacy bootloader like GRUB works.

  5. You will learn about assembly and the intricacies of x86. For example, what register does what, how to setup paging, how to setup segmentation.

  6. You will learn about legacy interrupts (the PIC, the old PS/2 keyboards etc).

Here's just a few cool things to know before you switch to a UEFI bootloader. The UEFI bootloader does all this for you so you don't need to learn about it. I guess it would make it difficult for a beginner to go right ahead with a UEFI bootloader since it would be a stiff learning curve without the practice that comes with it. While writing a legacy bootloader will make you learn all these subjects by heart and in depth so you can switch to UEFI with a clear understanding.

You will find plenty of information on StackOverflow and elsewhere once you start coding. Also, https://osdev.org/Main_Page is an invaluable resource for information on OS development.

If you decide to go with UEFI than here's some tips to set it up on Ubuntu Linux 20: Build edk2 in linux. My answer there will take you step by step to have a minimal UEFI application running. You can then build from there to have a complete bootloader.

Another tip is to have the bootloader as a separate program than the kernel of your OS. One problem I encountered is solving how to jump into C++. I think you should inevitably learn how to parse an ELF file and parse it from your bootloader then jump to its entry point. Otherwise, you will be left with linking scripts and twists that won't always work or that will make your experience less complete.

To develop a minimal OS from scratch you should have some software that will do things for you like compilation and emulation. I would choose Bochs for a legacy bootloader which has an integrated debugger. While I would go with QEMU or VirtualBox for UEFI booting. Both QEMU and VirtualBox will work very well to test an OS with UEFI while Bochs has rich debugging features when you develop with a legacy bootloader.

One last tip, if you really decide to venture into OS development, is to give yourself some time because you will need it.

Upvotes: 1

Related Questions