I remember wondering if you could make a bootloader that jumps directly into your program’s main function, and then run without any operating system to minimize overhead.

The answer is probably, but it would be a real pain. Without an OS you’d be responsible for handling multithread/core scheduling, managing memory, all the device hardware controllers (e.g. drives, network cards, keyboards), any abstractions like file systems, networking and a bunch of small stuff like error handling for processor interrupts.

Turns out these are all fundamentals of operating systems: you’d just be building your own OS to package with the program you want to boot into!

What is an Operating System

An operating system is a software controlling the operation of a computer system and its resources - wiki.osdev.org

An operating system is the supervising software that sits between hardware and all other programs, trying to provide safe and convenient ways of interacting with resources. The operating system facilities many programs running on the system by managing and virtualizing resources (e.g. virtualizing CPU so multiple programs run on a single core) and providing isolation (e.g. memory) while maintaining minimum performance overhead, and reliability.

Kernel vs Userland

Typically operating systems provide two pieces:

For example, many distributions like Ubuntu, NixOS, Arch all use the Linux kernel, even though the userland programs and thus user experience is very different. Other kernels include: FreeBSD, Windows NT.

What does a kernel provide?

The major things you might expect in a “reasonable” operating system kernel are:

Those are the core 4, but also some other things like:

Kernels also differ in their architecture, especially around what they keep in kernel space vs userspace (e.g. the filesystem or driver).

Monolithic kernels (e.g. Linux) keep all or most of the services in kernel space, making them generally fast. Hybrid kernels (e.g. Windows NT and above) put some components in userland, especially 3rd-party features like drivers which may be buggy/malicious. Micro kernels try to run services like filesystems and drivers in userspace, relying on messaging between services.

Unix Architecture Diagrams (Update 07-04-17)

Diomidis Spinellis made some awesome architecture diagrams of two Unix operating systems. I like it because it’s a really comprehensive (and organized) way of seeing everything thats provided in user space and kernel space.

Spinellis First Edition Unix Architecture

First Edition Unix Architecture

Spinellis FreeBSD Unix Architecture

FreeBSD Unix Architecture