Skip to content

yusufnasserdev/fos-kernel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

133 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fos-kernel

An educational operating system kernel, built to demonstrate core OS concepts and memory management techniques.

Background

This project is based on the FCIS OS course at Ain Shams University, Cairo, Egypt.

Overview

  • Protected memory management using paging and segmentation
  • Virtual memory with demand paging
  • User/kernel space separation
  • Process management and scheduling
  • Hardware interrupt handling
  • System calls interface
  • Synchronization primitives

Core Features

Memory Management

  • Two-level paging
    • Block allocation with max 2KB block size.
    • Page allocation for bigger sizes.
  • Fast page allocation using first-fit pointer.
  • Kernel Heap memory re-allocation.
  • Virtual address spaces (kernel/user)
  • Page fault handling
  • N-chance CLOCK page replacement
  • Dynamic kernel heap allocation
  • Shared memory management
    • Sharing pages between processes
    • Allowing for inter-process communication and synchronization using semaphores
    • Freeing shared pages and page tables when no longer needed

Process Management

  • Process creation and termination
  • One-to-one thread mapping
  • Separate kernel/user stacks
  • Priority round-robin scheduling
  • Inter-process communication
  • Process isolation and protection

System Services

  • Hardware interrupt handling
  • Essential system calls
  • Console I/O
  • Synchronization mechanisms
    • Semaphores
    • Spinlock
    • Sleeplock

Building

Please note that this project is built on a Linux environment (Debian).

Kindly follow the instructions below to build and run the project, based on the work of fos-v2 maintainers.

# Required Packages
sudo apt-get update
sudo apt-get install build-essential qemu-system-i386 gdb libfl-dev

# Create directory
sudo mkdir /opt/cross
cd /opt/cross

# Install Toolchain
sudo wget https://github.com/YoussefRaafatNasry/fos-v2/releases/download/toolchain/i386-elf-toolchain-linux.tar.bz2
sudo tar xjf i386-elf-toolchain-linux.tar.bz2
sudo rm i386-elf-toolchain-linux.tar.bz2

# Update your PATH in your ~/.bashrc file.
echo 'export PATH="$PATH:/opt/cross/bin"' >> ~/.bashrc

# If you're using zsh or any other shell, update the appropriate file.
make clean
make 

To run the OS using QEMU:

Make sure you have QEMU x86 installed on your machine.

# Run the OS using QEMU graphical mode
make qemu

# Run the OS using QEMU inside the terminal
make qemu-term

Directory Structure

  • boot (Bootloader code)
  • kern (Kernel code)
    • cpu - CPU management
    • mem - Memory management
    • proc - Process management
    • conc - Concurrency and synchronization
    • trap - Interrupt & fault handling
    • tests - Kernel tests
    • cons - Console driver
    • cmd - Command line interface
  • inc (Header files)
  • lib (Common libraries)
  • user (User programs, mostly for testing)

Notable Modifications & Additions

  • Added command brb to reboot the OS using assembly code.
  • Fixed GNUmakefile issue where all kernel files had to be touched to recompile.

Work in Progress

  • Freeing all used memory when a process is terminated.

  • Better implementation of the N-chance CLOCK page replacement algorithm.

Main Areas of Improvement

  • Refactor the codebase to be more modular and maintainable
  • Introduce a proper testing framework to enable unit, regression, and integration testing
  • Introduce a way to shutdown the OS gracefully, without having to kill the QEMU process
  • Introduce a way of debugging user and lib files, currently only the kernel is debuggable

Contributing

Feel free to inspect the code and suggest improvements, I believe this project needs a complete overhaul as it hasn't been maintained properly by the course staff.

Their version of maintainance is to patch the code with the fixes they find necessary.

I'm happy to work with anyone who wants to contribute to this project.

Contributions are welcome through pull requests.

Acknowledgements

  • The maintainers of fos-v2, thanks for introducing a way to work on the project using QEMU and vscode.
  • The maintainers of FOS_Project, thanks for working on a test for the kheap realloc function.

License

This project is licensed under the GNU GPL v3

About

My FCIS OS kernel implementation, year 2024.

Topics

Resources

License

Stars

Watchers

Forks

Languages