AFOS

AFOS - Aspen Feltner Operating System

A 32-bit operating system kernel written in C and Assembly, featuring a comprehensive set of subsystems including filesystems, network stack, graphics, audio, and programming language interpreters.

Overview

AFOS is a monolithic kernel operating system designed for educational purposes and experimentation. It runs entirely in kernel space (ring 0) and provides a rich set of features including:

Architecture

Kernel Architecture

AFOS uses a monolithic kernel architecture where all kernel services run in privileged mode (ring 0). This simplifies development but means:

Memory Layout

Boot Process

  1. GRUB loads the kernel binary (afos.bin) via Multiboot protocol
  2. Boot assembly (boot/boot.asm) sets up Multiboot header
  3. Entry point (boot/entry.asm) initializes stack and calls kernel
  4. Kernel initialization (kernel/kernel.c) sets up all subsystems
  5. Shell starts interactive command-line interface

Core System Components

Global Descriptor Table (GDT)

The GDT (kernel/gdt.c, boot/gdt.asm) defines memory segments for:

Interrupt Descriptor Table (IDT)

The IDT (kernel/idt.c) sets up interrupt handlers for:

Interrupt Service Routines (ISR)

ISRs (kernel/isr.c, boot/isr.asm) handle:

Programmable Interrupt Controller (PIC)

PIC initialization (kernel/idt.c) remaps IRQ vectors to avoid conflicts with CPU exceptions and enables interrupt handling.

Hardware Support

Keyboard (PS/2)

Timer (PIT - Programmable Interval Timer)

VGA Text Mode

Graphics System

Storage (ATA/IDE)

Network Card (RTL8139)

Audio (AC97)

Filesystem

AFOS implements a hybrid filesystem system combining in-memory and disk-based storage.

In-Memory Filesystem

FAT32 Filesystem

Filesystem Integration

Filesystem Operations

Network Stack

AFOS implements a complete TCP/IP network stack (subset):

Ethernet Layer

ARP (Address Resolution Protocol)

IP (Internet Protocol)

ICMP (Internet Control Message Protocol)

Network Configuration

Programming Languages

BASIC Interpreter

Brainfuck Interpreter

Executable System

AFOS Binary Format

Program Execution

Programs can be executed via:

Shell

The AFOS shell (kernel/shell.c) provides an interactive command-line interface.

Built-in Commands

Features

Audio System

AC97 Audio

Audio Features

Graphics System

Graphics Modes

Graphics API

Graphics Demo

The graphics-test command demonstrates:

Build System

Makefile Targets

Build Scripts

Build Requirements

Build Process

  1. System files: build_sysfs.py processes files/sys/kernel/sysfs_data.c
  2. Compilation: C and Assembly files compiled to object files
  3. Linking: Object files linked into afos.bin kernel binary
  4. Disk image: build_home.py creates/updates afos_disk.img FAT32 image
  5. ISO creation: Kernel + GRUB config → afos.iso

Quick Start

Building and Running

# Build the kernel
make all

# Create ISO and run in QEMU (recommended)
make iso
make run-iso

# Or use the convenience target (clean + build + run)
make go

QEMU Configuration

The run-iso target uses:

Adding Files

System files (embedded in kernel):

cp myprogram.bas files/sys/components/
make go
# Access as: /sys/components/myprogram.bas

User files (on disk):

cp myfile.wav files/home/
make go
# Access as: /home/myfile.wav

File Structure

AFOS/
├── boot/              # Bootloader and assembly initialization
│   ├── boot.asm       # Multiboot header
│   ├── entry.asm      # Kernel entry point
│   ├── gdt.asm        # GDT initialization
│   └── isr.asm        # ISR stubs
├── kernel/            # Kernel source code
│   ├── kernel.c       # Main kernel initialization
│   ├── idt.c          # Interrupt Descriptor Table
│   ├── gdt.c          # Global Descriptor Table
│   ├── isr.c          # Interrupt Service Routines
│   ├── keyboard.c     # Keyboard driver
│   ├── filesystem.c   # In-memory filesystem
│   ├── fat32.c        # FAT32 filesystem
│   ├── shell.c        # Shell implementation
│   ├── executable.c   # Executable loader
│   ├── basic.c        # BASIC interpreter
│   ├── brainfuck.c    # Brainfuck interpreter
│   ├── graphics.c     # Graphics subsystem
│   ├── vesa.c         # VESA/VGA graphics
│   ├── audio.c        # Audio subsystem
│   ├── ac97.c         # AC97 audio driver
│   ├── wav.c          # WAV file parser
│   ├── rtl8139.c      # RTL8139 network driver
│   ├── ethernet.c     # Ethernet layer
│   ├── arp.c          # ARP protocol
│   ├── ip.c           # IP protocol
│   ├── icmp.c         # ICMP protocol
│   ├── ata.c          # ATA disk driver
│   ├── blockdev.c     # Block device abstraction
│   ├── pit.c          # Timer (PIT)
│   └── malloc.c       # Memory allocator
├── include/           # Header files
├── files/             # Source files for filesystem
│   ├── sys/           # System files (embedded)
│   └── home/          # User files (on disk)
├── examples/          # Example programs
├── tools/             # Build utilities
├── linker.ld          # Linker script
├── grub.cfg           # GRUB configuration
└── Makefile           # Build system

Development

Writing Programs

BASIC programs:

PRINT "Hello, AFOS!"
FOR i = 1 TO 10
    PRINT i
NEXT i

Brainfuck programs:

++++++++++[>+++++++>++++++++++>+++>+<<<<-]
>++.>+.+++++++..+++.>++.<<+++++++++++++++.
>.+++.------.--------.>+.>.

C programs (compile to AFOS binary format):

Kernel Development

Debugging

Limitations and Design Decisions

License

This is an educational operating system project.

Credits

Created by Aspen Feltner as an educational operating system project demonstrating low-level system programming concepts.