1

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

Saptak Bhoumik
  • 127
  • 3
  • 9
  • Hey, while an interesting question, this is not a good fit for stack overflow. As SO is for question that have concrete, correct, specific answers. You are asking a very general question that you better ask on some reddit or forums specific to creating operating systems. Good luck! – Roland Studer Mar 04 '21 at 10:14
  • 1
    I encourage you to google "how to write an operating system". You'll find tons of stuff! – user253751 Mar 05 '21 at 14:26

1 Answers1

2

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.

user123
  • 2,510
  • 2
  • 6
  • 20
  • Can I use Linux from scratch on windows – Saptak Bhoumik Mar 06 '21 at 18:08
  • What do you mean by Linux on Windows? – user123 Mar 07 '21 at 04:51
  • You can always work in a VM but that makes it harder to develop. Maybe a dual boot with ubuntu and Windows or a second hard disk (like a usb hard disk) on your computer would do the job. – user123 Mar 07 '21 at 04:52
  • LFS isn't developing an OS from scratch it is more like compiling an existing OS and installing it. While a good learning experience, it isn't what you asked. – user123 Mar 07 '21 at 04:55
  • Can you tell me what are the various function performed by the kernal of a modern operating system – Saptak Bhoumik Mar 07 '21 at 10:51
  • Well it does quite a lot of stuff. If you have any questions about a specific thing they do feel free to ask a new question. – user123 Mar 07 '21 at 10:55