The purpose of this "wiki", web documentation, guide, however you call it, is to use it as a personal memory aid
for kernel development.
It doesn't have to be an ultra-aesthetic page, but I'm trying hard so it doesn't show that I made it
with vanilla html, css and js like some amateur project
that's out there.
A minimally functional operating system kernel (all the Kernel Space plus a minimal user space)
can easily run in 15,000 lines of code, so as you'll see;
it's humanly impossible to memorize and understand the entire kernel flow by myself. Besides, there are many complex subsystems working together at a low level to mediate between hardware and software.
IR0 is a multipurpose operating system kernel developed
from scratch for x86-64 architecture written primarily in C and ASM (Although
I have no problem including code from other specialized languages in performance such as
Cpp or Rust).
I'm creating it to learn more about operating systems and be able to use it as raw material
for another project that replicates WSL2 but with my own kernel.
I don't rule out scaling it enough to make it usable in minimal servers or even IoT,
but I understand that's in the very long term.
This
is its GitHub Repository.
Discord community
Version: v0.0.1 pre-release candidate 1
Architecture: x86-64 (primary), x86-32 (experimental), ARM (in development)
Bootloader: GRUB
License: GNU GPL v3.0
Type: Monolithic Modular Kernel
ASM Syntax: Intel (NASM)
Unlike kernels such as Microsoft's NT kernel (Hybrid), Redox-OS
(Microkernel),
or the same MINIX kernel (microkernel), IR0 is based on a more similar architecture
to what Linux has, which is monolithic.
However, my main argument is that of performance. I understand that someone could come and
point out that, like any monolith, if a subcomponent breaks, the entire system crashes (and
they would be right)
but what I respond to that is "What good does it do me that the kernel supports continuing without
filesystem if I can't do anything practical without it?", that is, it doesn't make sense that the
kernel
continues functioning without one of its key components running.
That's why I don't see a better alternative (for now) than the monolithic pattern. And it also saves me from having to interconnect
key subsystems with each other via IPC, which impacts performance of the Operating System. It's not
perfect, but it's stable. It's not entirely traceable and requires scaling little by little, but if it scales well it performs a lot.
However, I also have disagreements with the UNIX philosophy. They (among other things and very briefly)
consider
that if something fails, let it fail well. Which in kernel terms would be: If the scheduler breaks, Panic() directly. If you have memory corruption (in kernel space),
Panic.
And it's not that I question it for no reason, I simply ask (although without solutions yet) "Why not rescue the system during Panic()?, or at least try".
Beyond the philosophical point and to summarize, the kernel is monolithic because it's more performant and
I feel that the key pieces of the kernel must work without overhead.
However, if in the future I needed to integrate some specific subsystem in a hybrid way,
I would surely be pragmatic.
I know I talk as if IR0 were used by thousands of people and all the history, but I'm going to give myself the luxury of opining
about it.
So, the point is that kernel space has to be only habitable by subsystems
that work in that Environment,
nothing else.
I understand that there are certain manufacturers concerned about their clients' security who,
coincidentally, have access to every interruption that the user makes (they know what keys you press,
your session time every time you turn on the computer, etc.) And all that because they have
software running in the kernel space with all the privileges that implies.
RING 0 is only for the kernel. Everything that comes from RING 3
communicates with syscalls(), end of statement.
For IR0 to work as support for basic servers and IoT applications, I need
fundamental network support but without the massive complexity of Linux's complete stack.
In the Linux Kernel there are more or less 1,500,000 lines of code ONLY THE COMPLETE NETWORK STACK. Instead of trying to port all of that, I've decided to use a more pragmatic approach:
Basic implementation with IoT library:
How the file structure can change constantly, I prefer you consult it in the GitHub Repository.
- Main branch with stable and tested code.
- Active development branch where new features are implemented and tested.
- I add it because it's the branch where feats are created that later go to upstream merging to dev. It's the most unstable of all because it's where new code is integrated that must also be tested and reviewed before reaching merge.
- In this branch, features are integrated unstable enough to end up in mainline but that may have potential in the future.
Version: v0.0.01 pre-release candidate 1
Architecture: x86-64 (primary), x86-32 (experimental), ARM (in development)
License: GNU GPL v3.0
Type: Monolithic Modular Kernel
SYS_EXIT(0) - Process termination SYS_WRITE(1) - Write to file descriptor SYS_READ(2) - Read from file descriptor SYS_GETPID(3) - Get process ID SYS_GETPPID(4) - Get parent process ID SYS_LS(5) - List directory contents SYS_MKDIR(6) - Create directory SYS_PS(7) - Show process list SYS_WRITE_FILE(8) - Write file to filesystem SYS_CAT(9) - Display file contents SYS_TOUCH(10) - Create empty file SYS_RM(11) - Remove file SYS_FORK(12) - Create child process SYS_WAITPID(13) - Wait for child process SYS_RMDIR(40) - Remove directory SYS_MALLOC_TEST(50) - Memory allocation test SYS_BRK(51) - Change heap break SYS_SBRK(52) - Increment heap break SYS_MMAP(53) - Memory mapping SYS_MUNMAP(54) - Unmap memory SYS_MPROTECT(55) - Change memory protection SYS_EXEC(56) - Execute program
Note: Opted for a basic implementation with IoT library instead of porting Linux's complete stack (1.5M lines) to keep the kernel lightweight and manageable.
Kernel Space: 0x100000 - 0x800000 (1MB-8MB) Heap Space: 0x800000 - 0x2000000 (8MB-32MB, 24MB total) User Space: 0x40000000+ (1GB+)
print(), write()
, etc. because there's no operating system that
responds to those functions . You are the
operating system. that's why, in the repo I have the folder of dependencies "includes".
snake_case()
UPPER_CASE
struct_name_t
g_variable_name
CONSTANT_NAME
#INCLUDE -ir0/Lib.h -
(are being migrated to that format)
- This section details the main subsystems that compose the IR0 kernel,
their current development status and technical characteristics of each one.
The best way to understand the internal operation is by reviewing the source code in the
GitHub Repository.
The scheduler is the heart of the multiprocessing system. Currently implements a simple Round-Robin algorithm as fallback, but the goal is to migrate to a preemptive scheduler with priority scheme similar to Linux's CFS (Completely Fair Scheduler).
Files: scheduler/scheduler.c, scheduler/task.h, scheduler/switch/switch.asm
Own filesystem based on EXT2 but with modern innovations. The distinctive feature is the integration of a vectorial database to optimize file search and indexing operations.
Status: Active development
Files: fs/ext2.c, fs/victor_index.c, fs/journal.c
Robust interrupt and exception handling system that ensures kernel stability and provides a clean interface for handling hardware and software events.
Files: interrupt/idt.c, interrupt/interrupt.asm, interrupt/isr_handlers.c, interrupt/irq.c
Initialization system that prepares the environment for kernel execution, handling the transition from bootloader to user space.
Files: boot/boot.asm, boot/kmain.c, boot/arch.c, boot/kernel_start.c
Advanced memory management system that provides process isolation, performance optimization and protection against unauthorized access.
Files: mm/page_alloc.c, mm/slab.c, mm/vmalloc.c, mm/protection.c
Complete network stack based on Linux but optimized for the IR0 kernel, providing support for modern protocols and specific optimizations.
Status: Integration with Linux networking stack
Files: net/tcp.c, net/udp.c, net/socket.c, net/protocols/
Modular framework for hardware driver development and management, with support for hot-plugging and automatic device management.
Files: drivers/core.c, drivers/block/, drivers/char/, drivers/net/
Comprehensive security framework that protects the kernel and user processes, implementing multiple layers of protection and security auditing.
Files: security/capability.c, security/seccomp.c, security/lsm/, security/audit.c
Advanced power management system that optimizes battery consumption in mobile devices and reduces energy consumption in servers while maintaining performance.
Files: power/suspend.c, power/cpuidle.c, power/thermal.c, power/battery.c
Virtualization subsystem that allows running multiple operating systems simultaneously, with support for containers and complete virtual machines.
Files: virt/kvm/, virt/xen/, kernel/nsproxy.c, kernel/cgroup.c
Complete monitoring and debugging system that provides deep visibility into kernel operation and enables real-time problem diagnosis.
Files: kernel/trace/, kernel/debug/, kernel/profiling/, kernel/bpf/
Hardware description system that allows the kernel to automatically discover and configure hardware devices without needing hardcoded specific drivers.
Files: drivers/of/, drivers/acpi/, drivers/firmware/
Graphics subsystem that provides hardware acceleration, multi-monitor support and advanced multimedia capabilities.
Files: drivers/gpu/drm/, drivers/media/, drivers/video/
Advanced audio system that provides support for multiple formats, real-time audio processing and management of complex audio devices.
Files: sound/core/, sound/soc/, sound/pci/, sound/usb/
Unified input and output system that handles all user interface devices, from keyboards and mice to touchscreens and sensors.
Files: drivers/input/, drivers/hid/, drivers/iio/