Skip to content

Learning operating system and kernel development by building a multithreaded OS called ToyOS

Notifications You must be signed in to change notification settings

markCwatson/toyos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ToyOS

ToyOS is a work-in-progress (WIP) hobby operating system meant for educational purposes. The OS is being developed with a focus on foundational operating system concepts and practical implementations. The following GIF shows ToyOS running in QEMU. In this demonstration, the shell is interacting with the kernel to execute commands (currently, only the ps, echo, and clear commands are supported).

alt-text

Current features include:

  • 16-bit Bootloader: A basic bootloader that initializes the system and loads the 32-bit kernel.
  • 32-bit Kernel: The core of ToyOS, built for x86 platforms, handling essential system tasks.
  • Virtual Memory with Paging: Implements paging to manage memory, providing virtual memory support.
  • Virtual Filesystem (VFS): An abstraction layer for file system operations, allowing different filesystem types to be used seamlessly.
  • FAT16 Filesystem: Supports reading and writing files using the FAT16 format. Writing in append mode is under development.
  • Simple Terminal: A basic terminal interface for user interaction, currently under development.
  • Simple Test Framework: A basic test framework for functional testing, currently under development.
  • Multi-threading: Support for concurrent execution of processes, enabling more complex and efficient program execution.
  • User-Level Programs: Support for running user programs, expanding the OS's functionality beyond system-level operations.
  • Interactive Shell: A user-friendly command-line interface to interact with the OS.
  • Loading ELF files at runtime: The ability to dynamically load shared libraries and user programs at runtime.

Building

From the root of the project, invoke the make build system (will need to make build script executable beforehand: sudo chmod +x ./build.sh)

make clean
./build.sh

Note

This project was developed on Linux. The assembler used here is nasmversion 2.15.05 . It can be installed using

sudo apt install nasm

The makefile invokes a gcc cross-compiler with a generic target (i686-elf) custom built to not include any reminants of the host OS (stdlib, etc.). It needs to be built from source. Follow the instructions here.


Tests

To run the tests (see tests folder at root of project), use the --tests flag

make clean
./build.sh --tests

Emulation (QEMU) and debugging (GDB)

QEMU is used to emulate the x86 hardware. It can be installed using.

sudo apt install qemu-system-x86

To run the kernel in the QEMU emulator without debugging, simply run the 32-bit x86 emulator

qemu-system-i386 -hda ./bin/os.bin

To debug with GDB, first start GDB

$ gdb

Next, manually load symbol file at the specified address for debugging (because the emulator does not load symbol information from os.bin automatically).

(gdb) add-symbol-file "./build/kernelfull.o" 0x100000

Connect to the 32-bit QEMU instance with GDB

(gdb) target remote | qemu-system-i386 -hda ./bin/os.bin -S -gdb stdio

To debug user programs, use address 0x400000 for user space.

(gdb) break *0x400000

Elf Files

To view the content of ELF files, install dumpelf

sudo apt install pax-utils

and dump the contents of an ELF file, for example

dumpelf programs/shell/shell.elf

References

  1. Developing a Multithreaded Kernel From Scratch! by Daniel McCarthy
  2. The Little Book About OS Development by Erik Helin and Adam Renberg
  3. OSdev.org
  4. Modern Operating Systems 4th Edition by Andrew Tanenbaum and Herbert Bos
  5. Various OS courses on Udemy by the group Abhishek CSEPracticals, Ekta Ekta, and Shiwani Nigam

About

Learning operating system and kernel development by building a multithreaded OS called ToyOS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published