TurtleOS System Architecture & Runtime Analysis

Document Created by Freeze Software Team
Category: Technical Documentation
Version: 0.1

This is an introduction to the internal architecture of TurtleOS, examining its kernel initialization, memory management, display systems, input handling, and runtime environment.

Document Purpose: This document explores how TurtleOS operates internally. It provides a technical foundation for studying system behaviour, collecting performance information, and understanding the relationship between its components.

1. Introduction

TurtleOS is a lightweight operating system kernel developed by Freeze Software. It is designed around low-level system programming and direct interaction with computer hardware.

Unlike conventional desktop operating systems, TurtleOS operates through its own kernel environment, handling hardware initialization, memory allocation, input devices, and display output.

The project is primarily written in C and x86 assembly. Its source code is organized into individual components responsible for different areas of the operating system.

This document examines these components from a technical perspective, with particular attention to their responsibilities and how they interact.

2. Kernel Architecture

The TurtleOS kernel is responsible for coordinating the fundamental operations of the computer. Its implementation is separated into several modules.

Component Responsibility
Kernel Coordinates system initialization and execution.
GDT Initializes the Global Descriptor Table.
IDT Initializes the Interrupt Descriptor Table.
Memory Provides heap initialization and memory allocation.
Display Handles graphical framebuffer output.
Console Provides terminal-style text output.
Keyboard Handles keyboard input.
Serial Provides serial communication.
Multitasking Provides task creation and execution.
PIT Provides programmable interval timer functionality.

Source Organization

TurtleOS organizes its implementation into directories such as architecture, memory, multitasking, and device handling. This separates hardware-specific operations from the main kernel implementation.

3. Kernel Initialization

The kernel initialization routine is one of the most important parts of TurtleOS. It prepares the system before normal execution begins.

In the current implementation, kernel_main() performs several initialization operations.

Initialization Sequence

  1. Disable interrupts using cli().
  2. Initialize the Global Descriptor Table.
  3. Initialize the Interrupt Descriptor Table.
  4. Initialize the heap.
  5. Initialize the PS/2 mouse.
  6. Initialize the Programmable Interval Timer.
  7. Initialize the console.
  8. Create the initial Shell task.
  9. Enable interrupts using sti().

Initialization Analysis

Disabling interrupts during initialization helps prevent interrupt handling while essential system components are being prepared.

Once initialization is complete, interrupts are enabled and the shell task can begin executing.

Source Reference: src/kernel.c — kernel_main()

4. Memory Management

Memory management is responsible for providing the kernel with space for storing and manipulating runtime information.

TurtleOS initializes its heap through the init_heap() function during kernel startup.

Heap Allocation

The console implementation uses dynamic allocation to create its internal character buffer and dirty-row tracking array.

console = malloc(rows * cols * sizeof(term_char_t));

dirty_rows = malloc(rows * sizeof(uint8_t));

These allocations allow the console to store character information and track which rows require rendering.

Memory Considerations

  • Heap initialization occurs during kernel startup.
  • Console memory is allocated dynamically.
  • Allocation failures are checked during console initialization.
  • Memory allocation is an important consideration when determining system stability.

Further investigation could examine heap capacity, allocation behaviour, fragmentation, and memory usage during extended operation.

5. Display System

TurtleOS includes a framebuffer-based display system used to render information onto the screen.

The console implementation obtains framebuffer information through Multiboot framebuffer tags. This information includes the framebuffer address, width, height, pitch, and bits per pixel.

Character Rendering

The terminal implementation uses fixed character dimensions:

Property Value
Character Width 8 pixels
Character Height 16 pixels

The number of terminal rows and columns is calculated from the available screen resolution.

rows = height / CHAR_HEIGHT;
cols = width / CHAR_WIDTH;

Rendering Optimization

TurtleOS uses a dirty-row tracking system. Instead of rendering every row whenever text changes, it checks which rows have been marked for updating.

This provides a way to avoid unnecessary redraw operations when only part of the terminal changes.

6. Console & Output

The console provides the main text-based interface for interacting with TurtleOS.

Each terminal cell stores three properties:

  • Character value
  • Foreground color
  • Background color

Console Operations

Function Purpose
console_clear() Clears the console.
console_scroll() Scrolls the terminal when necessary.
render_console() Renders modified terminal rows.
console_backspace() Removes the previous character.
console_write() Writes text to the console.
console_writeln() Writes text followed by a newline.
console_getc_blocking() Waits for serial or keyboard input.

Serial Output

Console output is also mirrored to the serial interface through serial_write().

This provides an additional way to observe system output, particularly when using a terminal-based emulator configuration.

7. Input Systems

TurtleOS contains input handling for keyboard and mouse devices.

Keyboard

The keyboard subsystem provides input to the console. The console_getc_blocking() function checks whether serial input or keyboard input is available.

Mouse

The kernel initialization sequence includes ps2mouse_init(), which initializes the PS/2 mouse subsystem.

The mouse implementation is a separate component and can be examined independently from the console.

8. Timing & Interrupts

TurtleOS initializes its Programmable Interval Timer through pit_init(100).

The argument configures the timer initialization with a frequency value of 100.

Why Timing Matters

Timer functionality is important for operating system tasks that depend on regular timing events. It can also provide a foundation for measuring runtime behaviour.

The exact scheduling behaviour and timer event handling should be examined alongside the PIT and multitasking implementations.

9. Runtime Environment

TurtleOS is built as a freestanding 32-bit x86 kernel. Its Makefile configures GCC with options intended for low-level kernel development.

Compilation Configuration

Setting Configuration
Compiler GCC
Assembler NASM
Architecture 32-bit x86
Compilation Mode Freestanding
Optimization -O2
Linker GNU LD

Emulated Environment

The Makefile provides QEMU execution targets using qemu-system-i386.

The configured virtual machine uses 512 MB of memory and includes the generated TurtleOS ISO.

The Makefile also supports a terminal-only mode through the run-nographic target.

10. Storage

The TurtleOS Makefile defines a separate data disk image named turtleos-data.img.

The image is created as a 4 MB file when it does not already exist.

DATA_DISK := build/turtleos-data.img

The disk image is attached to QEMU as an additional IDE disk.

Implementation Note: The existence of this data image does not by itself establish that TurtleOS currently implements a filesystem or persistent file storage system.

Further research is needed to establish how the kernel interacts with the attached disk.

11. System Analysis

Understanding the internal architecture of TurtleOS provides several opportunities for technical analysis.

Current Implementation Overview

Area Observed Implementation
Kernel Startup Initialization sequence in kernel_main().
Memory Heap initialization and dynamic allocation.
Display Framebuffer-based rendering.
Console Character buffer and dirty-row tracking.
Serial COM1 serial communication.
Input Keyboard and PS/2 mouse initialization.
Timing PIT initialization with argument 100.
Multitasking Initial Shell task creation.
Storage QEMU data disk image configuration.

Potential Performance Measurements

The following measurements could be investigated in future testing:

  • Kernel initialization duration.
  • Heap allocation behaviour.
  • Framebuffer rendering performance.
  • Console scrolling performance.
  • Serial output throughput.
  • Timer accuracy.
  • Task execution behaviour.

These are proposed measurements, not existing TurtleOS performance benchmarks.

12. Future Research

This document provides an initial overview of TurtleOS architecture. Additional research can expand the documentation into a more detailed technical reference.

Areas for Further Investigation

  • Detailed heap implementation and memory layout.
  • Interrupt handling and descriptor configuration.
  • Task creation and scheduling implementation.
  • Keyboard and mouse event processing.
  • Framebuffer rendering and display performance.
  • Hardware communication and port operations.
  • Disk access and possible filesystem support.

Conclusion

TurtleOS consists of several interconnected low-level components that work together to initialize and operate the system.

Understanding these components is essential for evaluating the kernel's behaviour and identifying opportunities for improvement.

This document will serve as a foundation for future technical analysis and documentation of the TurtleOS project.

13. Credits and Resources

TurtleOS is developed by Freeze Software.