[logo]

the tape-kernel

a modular modern independent kernel

overview

the tape-kernel is a minimal, modular, independent 32 bit kernel. it boots from bios/csm via multiboot, runs in protected mode on an i486 or better, and fits on a 1.44MB FAT12 floppy image. there is no unix, no posix, no libc—just a bump allocator, a flat file system, a shell, and a text editor.

the system has:

the entire kernel is written from scratch in c and assembly. it uses no external libraries and links against nothing—-nostdlib -nostdinc -ffreestanding.

quickstart

git clone https://codeberg.org/druid520/tape-kernel.git
cd tape-kernel
make iso
make run

once booted, type help at the tape@ prompt to see available commands.

requirements

hardwareminimum
cpui486 (or better)
ram3.8 MB
disk1.44 MB FAT12 image
displayvga text mode (80x25)
inputps/2 keyboard
mode32-bit protected mode
firmwarebios / csm

dependencies

to build and run:

qemu-system-i386  gcc  as  ld  make  binutils  coreutils  git  xorriso  dosfstools

for development and debugging:

gdb  doxygen  graphviz
install on arch: sudo pacman -S qemu-system-i386 gcc binutils make git xorriso dosfstools gdb
install on debian: sudo apt install qemu-system-x86 gcc binutils make git xorriso dosfstools gdb
install on fedora: sudo dnf install qemu-system-i386 gcc binutils make git xorriso dosfstools gdb
install on alpine: doas apk add qemu-system-i386 gcc binutils make git xorriso dosfstools gdb
install on void: sudo xbps-install qemu gcc binutils make git xorriso dosfstools gdb
install on freebsd: pkg install qemu gcc binutils gmake git xorriso dosfstools gdb

build targets

make          build the kernel elf
make iso      build the kernel and create a bootable iso
make run      build the iso and run in qemu
make debug    build the iso and run in qemu with gdb attached
make clean    remove build artifacts

for debugging, use target remote localhost:1234 in gdb after make debug starts qemu. the makefile builds with -g so symbols are available.

in-kernel usage

commands available at the tape@ prompt:

commanddescription
helpshow all available commands
clearclear the screen
lslist all files on disk
read <file>read and display a file
write <file>write text to a file (opens editor)
rm <file>delete a file
echo <text>print text to screen
rebootreboot the machine
alloc <n>allocate n bytes from the heap
heapshow heap status
panictrigger a kernel panic
infoshow memory and cpu info
editor <file>open the line-based text editor

the editor uses hotkeys: [e] to edit a line, [w] to save, [q] to quit. it supports up to 32 lines of 80 characters each.

memory layout

0x00000000 +------------------+
           |   ivt / bda      |  real-mode data
0x00001000 +------------------+
           |   kernel code    |  .text (loaded at 1M)
           |   kernel data    |  .data / .bss
           |   stack          |  16 KB
           |   arena heap     |  bump allocator
           |   ...            |  grows upward
0x00FFFFFF +------------------+

the kernel is loaded at 1MB by the multiboot bootloader. the stack is 16KB. the heap is an arena bump allocator with no free support. allocation is 4-byte aligned with overflow checking. child arenas can be created from the parent heap via anew.

project structure

src/
  boot/     multiboot header and entry point (.s)
  fs/       flat file system, ide disk driver
  io/       vga output, keyboard input, cursor control, port i/o
  kernel/   main kernel entry, cpu detection, interrupt wrappers
  lib/      string utils, math, panic handler, pit timer, types
  mem/      arena allocator, memory info
  usr/      shell, text editor

coding conventions

license

the tape-kernel is free software, licensed under the gpl-3.0-or-later.

contributing

contributions are welcome. follow the coding style, use the commit prefixes, and keep things simple—dont add unless needed. open an issue or pull request on codeberg.

troubleshooting