Mos Operating system(part 1): Learn to Build A Custom OS from Strach.

Ukpa Uchechi
5 min readMar 22, 2023

--

Hey Everyone welcome to my custom OS, The Mos Operating system, if you clicked this link you are probably interested in building an os and I mean why not it's a cool project. I’m a software developer with an old laptop so I decided to build an OS for it and document my process. Of course, I am no expert so take my word with a grain of salt.

I have a laptop that has an intel x86–64 architecture, it’s a core i5 so it will be great to learn a lot of modern things with it. So in this article, we would start by looking at a fundamental process (the boot process).

Boot Process
The boot process is the series of events that occurs from when you power on a computer till when the operating system is fully loaded and operational.

Why should I understand the boot process?
Well understanding the boot process is essential for developing an operating system because it establishes the foundation for which the os will run. It allows the os take control of the hardware, enabling it to perform its tasks and manage resources.

When the computer is turned on, the firmware(BIOS or UEFI) is stored in a non-volatile memory chip on the motherboard and it’s the first code that gets executed. The firmware is responsible for initializing the hardware components and setting up the system’s initial state to prepare for the boot process. This involves several tasks to ensure the system is ready to load and execute the operating system.

Some of the tasks performed by the firmware during the initialization process include:

  1. Power-On-Self-Test(POST): The firmware runs a series of diagnostics tests(POST) to verify the functionality of critical hardware components like the CPU, memory, and peripherals. This ensures the hardware is functioning correctly before proceeding with the boot process, If this process fails the computer will not continue with the boot process and an error message or beep codes may be displayed or emitted to indicate the issue.
  2. Memory and CPU initialization: The firmware configures the memory controller and initializes the CPU with the correct settings such as the operating mode, clock speed, and cache configuration.
  3. Hardware device enumeration: The firmware scans the systems for connected devices, network interfaces, and input/output devices. It assigns system resources like I/O ports, memory addresses, and interrupts numbers to these devices. It sets up the basic, functional environment to enable the bootloader and operating system to load and run.
  4. Hardware device initialization: The firmware initializes the hardware devices and configures them to their default or user-defined settings. This includes setting up the video card for display output, initializing storage devices, and configuring other peripherals like keyboards, mice, and network interfaces.
  5. Setting up system services: The firmware sets up essential system services, such as the interrupt vector table, system timers, and power management settings.
  6. Boot device selection: The firmware determines the boot order, which is the sequence of devices it will search for a bootloader. This order is typically configurable by the user through the firmware setup utility. Common boot devices include hard drives, optical drives, and USB drives.
  7. Loading the bootloader: Once the firmware finds a valid bootloader on a bootable device, it loads the bootloader into memory and transfers control to it. The bootloader is responsible for locating and loading the operating system kernel.

I will start with writing the bootloader, but first, let's understand what it does.

Well, we understand the firmware, but how is that different from a bootloader?

A bootloader's primary function is to initialize the hardware and load the operating system into memory. The bootloader resides in specific locations such as the boot sector of the hard drive or a separate boot partition and is executed by the firmware(BIOS or UEFI) during the boot process.

The bootloader performs the following tasks:

  1. Hardware initialization: The bootloader initializes essential hardware components, such as the CPU, memory controller, and display, if not already done by the firmware.
  2. Locating the operating system: The bootloader searches for a valid operating system on available storage devices, such as hard drives, SSDs, or removable media. The bootloader may use a predefined order or user-configurable settings to determine which device to search first.
  3. Loading the operating system: Once the bootloader finds a valid operating system, it reads the operating system’s kernel (the core part of the OS) from the storage device and loads it into memory.
  4. Transferring control: After loading the kernel into memory, the bootloader transfers control to it. The kernel then takes over the boot process, initializing the rest of the system and eventually starting the user interface and applications.

Wait why can’t the firmware load the operating system?

The firmware (BIOS or UEFI) could load the operating system directly, but there are several reasons why using a bootloader is more practical and efficient:

  1. Flexibility: Bootloaders provide flexibility when it comes to choosing the operating system to load. They often support multiple operating systems or different versions of the same OS installed on the same machine. The firmware would need to be updated frequently to accommodate the ever-changing landscape of operating systems if it were responsible for loading the OS directly.
  2. Modularity: Separating the responsibilities of the firmware and the bootloader allows for a modular design. The firmware focuses on initializing the hardware and providing essential system services, while the bootloader is responsible for locating and loading the operating system. This modularity makes it easier to update or replace individual components without affecting the entire system.
  3. Compatibility: A bootloader can be tailored to a specific operating system or family of operating systems, ensuring compatibility and smooth operation. The firmware, on the other hand, is designed to work with a wide variety of hardware and software configurations, making it difficult to provide seamless compatibility with every possible OS.
  4. Simplified firmware: By offloading the task of loading the operating system to a bootloader, the firmware can be smaller and simpler, reducing the chance of bugs and making it easier to maintain. This also allows firmware developers to focus on core functionality and hardware compatibility, rather than dealing with the intricacies of loading different operating systems.
  5. Customization: Bootloaders can be customized by users or developers to enable advanced features, such as custom boot menus, encryption, or debugging options. By keeping these features in the bootloader, the firmware remains clean and focused on its primary task.

So in a nutshell this is the boot process:
When the computer is powered on or reset, the firmware (BIOS or UEFI) is the first code that gets executed. It initializes the hardware, performs the Power-On Self-Test (POST), and sets up the system’s initial state.

  1. After completing the initialization tasks and POST, the firmware searches for a bootable device containing a bootloader. When it finds one, it loads the bootloader into memory and transfers control to it.
  2. The bootloader then takes over the responsibility of locating and loading the operating system kernel. It searches for a valid operating system on available storage devices, loads the kernel into memory, and transfers control to the kernel.
  3. Finally, the operating system kernel initializes the rest of the system, starts the user interface, and runs applications.

The boot process can be summarized as Firmware → Bootloader → Operating System.

I would be using a mac for now to develop this os, in part 2 we would talk about the tools and resources we would be using for our Mos operating system. Stay Motivated

--

--

Ukpa Uchechi
Ukpa Uchechi

Written by Ukpa Uchechi

A Tech Enthusiastic and lover, who loves teaching and learning.

No responses yet