HendOS

A Custom Unix-like x86-64 Operating System
by Hendrik Sorensen

Project Overview

HendOS is a custom, educational Unix-like operating system for x86-64, built from scratch in C and assembly. It features a modern kernel, UEFI boot, multitasking, virtual memory, a custom shell, and a userland with core utilities. The project demonstrates low-level systems programming, OS architecture, and hardware interfacing.

Complete OS stack: From UEFI bootloader to userland applications, every component is custom-built.
Modern architecture: x86-64, virtual memory, multitasking, and POSIX-compatible system calls.

Implemented Features

Boot & Kernel Init

UEFI bootloader/stub, assembly startup, page-aligned kernel memory layout

Memory Management

Physical memory map parsing, PML4 page tables, virtual memory, page fault handling

Interrupt Handling

IDT, ISRs for CPU faults, APIC/PIC, timer setup, context switch code

Process Management

PCB design, fork(), ELF loader, user/kernel mode transitions, scheduler

Process Groups & Signals

PGID/SID, setsid(), signal definitions, signal delivery and masking

Terminals & Shell

Keyboard driver, line discipline, TTY master/slave, job control, userland shell

File & I/O System

File descriptor table per process, VFS abstraction, ext2 driver

Syscalls & libc

Syscall mechanism, syscall table/dispatcher, minimal libc implementation

Init System & Services

PID 1 init process, shell from init, system services

Tooling

Cross-compiler toolchain, QEMU run script, disk image builder

Subsystems: In-Depth

Boot & Kernel Initialization

  • UEFI bootloader or boot stub loads the kernel as an EFI application.
  • Assembly startup code sets up the stack and jumps to kernel_main().
  • Page-aligned kernel memory layout ensures efficient paging and memory protection.
  • Framebuffer graphics and font rendering initialized before exiting boot services.

Memory Management

  • Physical memory map parsed from UEFI/BIOS.
  • Physical memory allocator (bitmap/buddy system).
  • PML4 page table setup for x86_64, supporting 4KB and 2MB pages.
  • Virtual memory mapping for kernel and user processes.
  • Page fault handler for demand paging and copy-on-write.
  • Kernel heap allocator (kmalloc, kfree).

Interrupt Handling

  • Full IDT (Interrupt Descriptor Table) setup.
  • ISRs for all CPU faults and hardware interrupts.
  • APIC or PIC initialization for interrupt routing.
  • Timer (PIT/HPET) setup and timer interrupts.
  • Context switch code in timer ISR for preemptive multitasking.

Process Management

  • Process Control Block (PCB) design for each process.
  • fork() system call for process creation (copy-on-write semantics).
  • ELF loader for user programs.
  • User/kernel mode transitions for syscall and interrupt safety.
  • Round-robin scheduler (with future support for priorities).
  • execve(), exit(), waitpid() syscalls.
  • Zombie process reaping logic.

Process Groups & Signals

  • Process Group ID (PGID) and Session ID (SID) support.
  • setsid(), setpgid(), getpgid() syscalls.
  • UNIX-style signal definitions (SIGKILL, SIGINT, etc.).
  • Signal delivery engine and per-process signal masking.

Terminals & Shell

  • Keyboard driver with scancode translation and event queue.
  • Line discipline (echo, backspace, canonical mode).
  • TTY master/slave (PTY) implementation for terminal multiplexing.
  • tcgetpgrp(), tcsetpgrp() for controlling terminal.
  • Foreground/background job control.
  • Custom userland shell with variables, aliases, and command parsing.

File & I/O System

  • File descriptor table per process.
  • Virtual Filesystem Switch (VFS) abstraction.
  • ext2 filesystem driver for persistent storage.

Syscalls & libc

  • Custom syscall mechanism (SYSCALL instruction or int 0x80).
  • Syscall table and dispatcher for kernel entry points.
  • Minimal libc implementation: malloc, free, printf, str*, open, close, read, write, fork, exec, wait, exit.

Init System & Services

  • PID 1 init process launches at boot.
  • Shell is started from init for user interaction.

Tooling

  • Cross-compiler toolchain for building the OS and userland.
  • QEMU run script for emulation and testing.
  • Disk image builder for creating bootable images.

Userland Programs

shell ls cp mv rm mkdir rmdir stat touch find file readlink getty systemd args gui helloworld segfault

All userland programs are written in C and run in protected user mode, demonstrating process isolation and system call usage.

How to Build & Run

  1. Ensure you have a cross-compiler toolchain and QEMU installed.
  2. Clone the repository from your source control.
  3. Open a terminal in the HendOS directory.
  4. Run the following commands:
cd HendOS
make
make run