Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A comprehensive educational operating system kernel developed for teaching OS concepts at FCIS - Ain Shams University.

License

Notifications You must be signed in to change notification settings

Fady2024/OS_Project_2025

Repository files navigation

๐Ÿ–ฅ๏ธ FOS - FCIS Operating System

Architecture Language Platform Type License


๐ŸŽ“ A Comprehensive Educational Operating System Kernel

Developed for Teaching OS Concepts at FCIS - Ain Shams University

Based on MIT Exokernel Architecture with Extensive Modifications


GitHub stars GitHub forks GitHub issues GitHub license


๐Ÿš€ Quick Start โ€ข ๐Ÿ“– Documentation โ€ข ๐Ÿ‘ฅ Team โ€ข ๐Ÿงช Testing


๐Ÿ“‹ Table of Contents

๐Ÿ“š Click to expand full table of contents
  1. ๐ŸŒŸ Introduction
  2. โœจ Features
  3. ๐Ÿ—๏ธ System Architecture
  4. ๐Ÿ“ Project Structure
  5. ๐Ÿ’พ Memory Management
  6. ๐Ÿ”„ Process Management
  7. โฐ CPU Scheduling
  8. ๐Ÿ“„ Page Replacement
  9. ๐Ÿ“ž System Calls
  10. ๐Ÿš€ Quick Start
  11. ๐Ÿ’ป Commands Reference
  12. ๐Ÿงช Testing Framework
  13. ๐Ÿ› Debugging
  14. ๐Ÿ‘จโ€๐Ÿซ Course Instructor
  15. ๐Ÿ‘ฅ Development Team
  16. ๐Ÿ“œ License
  17. ๐Ÿ™ Acknowledgments

๐ŸŒŸ Introduction

What is FOS?

FOS (FCIS Operating System) is a state-of-the-art educational operating system kernel that bridges the gap between theoretical OS concepts and practical implementation. Born from the legendary MIT Exokernel project, FOS has evolved into a comprehensive learning platform that empowers students with hands-on experience in systems programming.

๐Ÿ’ก Fun Fact: FOS contains over 15,000+ lines of C code and 100+ user programs for testing and learning!

๐ŸŽฏ Educational Goals

๐Ÿง 

Memory Management

Learn virtual memory, paging, heap allocation, and page replacement strategies

โšก

Process Scheduling

Master multiple scheduling algorithms with real-time process management

๐Ÿ”’

System Protection

Understand kernel/user mode separation, trap handling, and interrupts

๐Ÿ’ป

Systems Programming

Get hands-on with low-level C and x86 Assembly programming

๐Ÿ† Why FOS?

Advantage Description
๐ŸŽ“ Educational Focus Designed specifically for learning, not just running
๐Ÿ“š Well Documented Extensive comments and documentation throughout
๐Ÿ”ง Modular Design Easy to understand and modify individual components
๐Ÿงช Comprehensive Tests 50+ test cases covering all major features
๐ŸŒ Real-World Concepts Implements actual OS algorithms used in production systems

โœจ Features

๐Ÿ”ฅ Core Kernel Features

๐Ÿ’พ Memory Management
Feature Description Status
Virtual Memory Full paging support with 4KB pages โœ…
Two-Level Page Tables Efficient address translation โœ…
Memory Protection Kernel/User space separation โœ…
Frame Allocator Physical frame management โœ…
Page Table Management Dynamic creation and manipulation โœ…
โšก Process Management
Feature Description Status
Multi-tasking Pre-emptive multitasking โœ…
Context Switching Fast assembly-based switching โœ…
Process Isolation Separate address spaces โœ…
ELF Loading Load executable programs โœ…
Process Priority Priority-based scheduling โœ…
๐Ÿ“„ Page Replacement
Algorithm Type Status
FIFO Simple โœ…
Clock Second Chance โœ…
Modified Clock Dirty Bit Aware โœ…
LRU (Time) Timestamp Based โœ…
LRU (Lists) Active/Second Lists โœ…
N-Chance Configurable โœ…
Optimal For Testing โœ…
โฐ CPU Scheduling
Algorithm Description Status
Round Robin Equal time quantum โœ…
MLFQ Multi-level feedback โœ…
BSD FreeBSD-based โœ…
Priority RR Priority with RR โœ…
๐Ÿ”— Inter-Process Communication
Feature Description Status
Shared Memory Share memory regions โœ…
Kernel Semaphores Synchronization โœ…
User Semaphores User-level sync โœ…
Sleep/Wakeup Process blocking โœ…

๐Ÿ“Š Feature Statistics

Category Count
๐Ÿ“„ Scheduling Algorithms 4
๐Ÿ”„ Page Replacement Algorithms 7
๐Ÿ’พ Memory Allocation Strategies 6
๐Ÿ“ž System Calls 30+
๐Ÿ‘ค User Programs 100+
๐Ÿงช Test Cases 50+
๐Ÿ’ป Kernel Commands 40+

๐Ÿ—๏ธ System Architecture

๐Ÿ—บ๏ธ Memory Layout

The FOS kernel uses a well-defined memory layout that separates kernel and user space:

Region Start Address End Address Permissions Description
Invalid Memory 0xFFFFF000 0xFFFFFFFF --/-- Guard page at top
Kernel Heap 0xF6000000 0xFFFFF000 RW/-- Dynamic kernel memory
Remapped Physical 0xF0000000 0xF6000000 RW/-- Physical memory access
Kernel Base 0xF0000000 - - Kernel/User boundary
Virtual Page Table 0xEFC00000 0xF0000000 RW/-- Kernel page table access
Scheduler Stack Below VPT - RW/-- Per-CPU kernel stacks
User Limit 0xEF800000 - - Top of user memory
User Page Table 0xEF400000 0xEF800000 R-/R- User-readable page table
Read-Only ENVs 0xEEC00000 0xEF000000 R-/R- Process info
User Exception Stack 0xEEBFF000 0xEEC00000 RW/RW Exception handling
User Stack Below USTACKTOP - RW/RW Normal stack (grows up)
User Heap 0x80000000 0xA0000000 RW/RW Dynamic user memory
Program Code 0x00800000 - R-/R- .text and .data

๐Ÿ”‘ Key Memory Constants

// Kernel Memory
#define KERNEL_BASE 0xF0000000 // Kernel virtual address start
#define KERNEL_HEAP_START 0xF6000000 // Kernel heap begins here
#define KERNEL_HEAP_MAX 0xFFFFF000 // Kernel heap maximum
#define KERNEL_STACK_SIZE (8*PAGE_SIZE) // 32 KB per kernel stack
// User Memory
#define USER_HEAP_START 0x80000000 // User heap begins here
#define USER_HEAP_MAX 0xA0000000 // User heap maximum (512 MB heap)
#define USER_TOP 0xEEC00000 // Top of user-accessible memory
#define USTACKTOP 0xEEBFE000 // Top of user stack
// Common
#define PAGE_SIZE 4096 // 4 KB pages
#define PTSIZE (1024*PAGE_SIZE) // 4 MB per page table

๐Ÿ“ Project Structure

๐Ÿš€ boot/ - Boot Loader

The boot loader is the first code to execute when the system starts.

File Description
boot.S Assembly boot sector (512 bytes), enables A20, switches to protected mode
main.c Loads kernel ELF from disk, validates headers, jumps to kernel
sign.pl Perl script to add boot sector signature
Makefrag Build configuration for boot loader
๐Ÿง  kern/ - Kernel Source Code

The heart of the operating system.

Directory Files Description
kern/ init.c, entry.S Kernel entry and initialization
kern/cmd/ commands.c, command_prompt.c 40+ kernel commands
kern/cons/ console.c VGA text mode console driver
kern/cpu/ sched.c, context_switch.S, kclock.c CPU and scheduling
kern/mem/ memory_manager.c, kheap.c, working_set_manager.c Memory management
kern/proc/ user_environment.c, user_programs.c Process management
kern/trap/ trap.c, fault_handler.c, syscall.c Trap and interrupt handling
kern/disk/ pagefile_manager.c Page file operations
kern/tests/ Various test files Kernel test suite
๐Ÿ“š inc/ - Header Files

Shared definitions used by kernel and user programs.

File Description
memlayout.h Memory layout constants and definitions
mmu.h MMU and paging definitions
environment_definitions.h Process (Env) structure
trap.h Trap frame definitions
queue.h List/Queue macros
syscall.h System call numbers
types.h Basic type definitions
dynamic_allocator.h Heap allocator interface
๐Ÿ“– lib/ - User Library

Runtime library for user programs.

File Description
libmain.c User program entry point
syscall.c System call wrappers
uheap.c User heap (malloc/free)
dynamic_allocator.c Block-based allocator
string.c String manipulation
printf.c Formatted output
๐Ÿ‘ค user/ - User Programs (100+)

Sample user programs for testing and learning.

Category Examples
Basic fos_helloWorld.c, fos_factorial.c, fos_fibonacci.c
Sorting quicksort_*.c, mergesort_*.c
Memory Tests tst_malloc_*.c, tst_free_*.c, heap_program.c
Page Replacement tst_page_replacement_*.c
Shared Memory tst_sharing_*.c
Semaphores tst_semaphore_*.c, tst_ksemaphore_*.c
Scheduling priRR_*.c

๐Ÿ’พ Memory Management

๐Ÿ”ท Physical Memory Management

FOS uses a frame allocator to manage physical memory pages.

// Allocate a physical frame
int allocate_frame(struct FrameInfo **ptr_frame_info);
// Free a physical frame
void free_frame(struct FrameInfo *ptr_frame_info);
// Decrement reference count
void decrement_references(struct FrameInfo* ptr_frame_info);
๐Ÿ“Š Frame Info Structure
struct FrameInfo {
 Page_LIST_entry_t prev_next_info; // Free list links
 uint16 references; // Reference count (for sharing)
 struct Env *proc; // Owning process
 unsigned char isBuffered; // In modified buffer?
};

๐Ÿ”ท Virtual Memory Management

FOS implements two-level paging with 4KB pages.

// Get page table for a virtual address
int get_page_table(uint32 *ptr_page_directory, 
 const uint32 virtual_address, 
 uint32 **ptr_page_table);
// Create a new page table
void create_page_table(uint32 *ptr_directory, 
 const uint32 virtual_address);
// Map a frame to a virtual address
int map_frame(uint32 *ptr_page_directory, 
 struct FrameInfo *ptr_frame_info, 
 uint32 virtual_address, int perm);
// Unmap a virtual address
void unmap_frame(uint32 *ptr_page_directory, 
 uint32 virtual_address);
// Invalidate TLB entry
void tlb_invalidate(uint32 *ptr_page_directory, void *virtual_address);

๐Ÿ”ท Kernel Heap (KHEAP)

Dynamic memory allocation within the kernel.

// Allocate kernel memory
void* kmalloc(unsigned int size);
// Free kernel memory
void kfree(void* virtual_address);
// Reallocate kernel memory
void* krealloc(void* virtual_address, uint32 new_size);
// Address conversion
unsigned int kheap_virtual_address(unsigned int physical_address);
unsigned int kheap_physical_address(unsigned int virtual_address);

Allocation Strategies:

Strategy Command Description Best For
๐ŸŽฏ First Fit khfirstfit First block that fits General purpose
๐Ÿ” Best Fit khbestfit Smallest fitting block Minimize fragmentation
โžก๏ธ Next Fit khnextfit Continue from last Faster allocation
๐Ÿ“ Worst Fit khworstfit Largest block Large allocations
โš™๏ธ Custom Fit khcustomfit Optimized hybrid Best performance

๐Ÿ”ท User Heap

Each process has its own heap for dynamic memory.

// User-level allocator (in lib/)
void* malloc(uint32 size);
void free(void* virtual_address);
void* realloc(void* virtual_address, uint32 new_size);
// System calls for heap management
void* sys_sbrk(int increment);
void allocate_user_mem(uint32 va, uint32 size);
void free_user_mem(uint32 va, uint32 size);

๐Ÿ”„ Process Management

๐Ÿ“ฆ Environment Structure

Each process is represented by an Env structure:

View Complete Env Structure
struct Env {
 // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 // MAIN INFORMATION
 // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 struct Trapframe *env_tf; // Saved registers during trap
 struct Context *context; // Context switch registers
 LIST_ENTRY(Env) prev_next_info; // Queue links
 int32 env_id; // Unique process identifier
 int32 env_parent_id; // Parent process ID
 unsigned env_status; // Current state
 int priority; // Scheduling priority
 char prog_name[PROGNAMELEN]; // Program name (64 chars)
 void* channel; // Sleep channel (blocking)
 
 // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 // ADDRESS SPACE
 // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 uint32 *env_page_directory; // Page directory (virtual)
 uint32 env_cr3; // Page directory (physical)
 uint32 initNumStackPages; // Initial stack pages
 char* kstack; // Kernel stack bottom
 
 // Page file management
 uint32* disk_env_pgdir;
 unsigned int disk_env_pgdir_PA;
 uint32* disk_env_tabledir;
 unsigned int disk_env_tabledir_PA;
 
 // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 // WORKING SET
 // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 unsigned int page_WS_max_size; // Maximum working set size
 struct WS_List page_WS_list; // Working set elements
 struct WorkingSetElement* page_last_WS_element;
 
 // LRU Lists
 struct WS_List ActiveList; // Hot pages
 struct WS_List SecondList; // Cold pages
 int ActiveListSize; // Max active list size
 int SecondListSize; // Max second list size
 
 // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 // STATISTICS
 // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 uint32 pageFaultsCounter;
 uint32 tableFaultsCounter;
 uint32 freeingFullWSCounter;
 uint32 freeingScarceMemCounter;
 uint32 nModifiedPages;
 uint32 nNotModifiedPages;
 uint32 env_runs; // Times this env has run
 uint32 nPageIn, nPageOut, nNewPageAdded;
 uint32 nClocks;
};

๐Ÿ”„ Process States

State Value Description Next States
๐Ÿ†“ ENV_FREE 0 Available in free list NEW
๐Ÿ†• ENV_NEW 4 Newly created READY
โœ… ENV_READY 1 Ready to run RUNNING
โ–ถ๏ธ ENV_RUNNING 2 Currently executing READY, BLOCKED, EXIT
โธ๏ธ ENV_BLOCKED 3 Waiting for resource READY
๐Ÿšช ENV_EXIT 5 Terminated normally FREE
โ˜ ๏ธ ENV_KILLED 6 Killed externally FREE

๐Ÿ”„ Process Lifecycle

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ PROCESS LIFECYCLE โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ โ”‚
โ”‚ FREE โ”€โ”€createโ”€โ”€โ–บ NEW โ”€โ”€scheduleโ”€โ”€โ–บ READY โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚ โ–ฒใ•ใ‚“ใ‹ใ โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ dispatch โ”‚ โ”‚
โ”‚ โ”‚ โ–ผ โ”‚ โ”‚
โ”‚ โ”‚ RUNNING โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ free โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ โ”‚ โ–ผ โ–ผ โ–ผ โ”‚ โ”‚
โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ BLOCKED EXIT preempt โ”‚
โ”‚ โ”‚ โ”‚
โ”‚ wakeup โ”€โ”€โ–บ READY โ”‚
โ”‚ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“‹ Process Functions

// Create a new process
struct Env* env_create(char* user_program_name, 
 unsigned int page_WS_size,
 unsigned int LRU_second_list_size,
 unsigned int percent_WS_pages_to_remove);
// Free a process and its resources
void env_free(struct Env *e);
// Exit current process
void env_exit(void);
// Get current running process
struct Env* get_cpu_proc(void);
// Convert env ID to env pointer
int envid2env(int32 envid, struct Env **env_store, bool checkperm);

โฐ CPU Scheduling

FOS implements four different scheduling algorithms, each with unique characteristics.

1๏ธโƒฃ Round Robin (RR)

The simplest fair scheduling algorithm.

Property Value
Fairness โญโญโญโญโญ Equal time for all
Complexity โญ Very simple
Responsiveness โญโญโญ Depends on quantum
Overhead โญโญ Context switches

Command: schedRR <quantum>

How it works:

  1. All processes are in a single FIFO queue
  2. Each process runs for exactly quantum time units
  3. After quantum expires, process moves to end of queue
  4. Next process in queue starts executing

2๏ธโƒฃ Multi-Level Feedback Queue (MLFQ)

Adaptive scheduling that learns process behavior.

Property Value
Fairness โญโญโญ Based on behavior
Complexity โญโญโญโญ Multiple queues
Responsiveness โญโญโญโญโญ Interactive friendly
Overhead โญโญโญ Queue management

Command: schedMLFQ <num_levels> <q1> <q2> ...

How it works:

  1. Multiple priority queues with different time quantums
  2. New processes start at highest priority (shortest quantum)
  3. If process uses full quantum โ†’ move to lower priority
  4. If process blocks for I/O โ†’ stay at current or move up
  5. Periodic priority boost to prevent starvation

3๏ธโƒฃ BSD Scheduler

Based on the FreeBSD scheduler with dynamic priority calculation.

Property Value
Fairness โญโญโญโญ Dynamic adjustment
Complexity โญโญโญโญ Priority calculation
Responsiveness โญโญโญโญ Good for mixed workloads
Overhead โญโญโญ Recalculation

Command: schedBSD <num_levels> <quantum>

Priority Formula:

ร—ใฐใค 2)">
priority = PRI_BASE + (recent_cpu / 4) + (nice ร—ใฐใค 2)

4๏ธโƒฃ Priority Round Robin (PRIRR)

Combines priority scheduling with round-robin within each level.

Property Value
Fairness โญโญโญ Within priority levels
Complexity โญโญโญ Multiple queues + RR
Responsiveness โญโญโญโญ High priority = fast
Overhead โญโญโญ Anti-starvation

Command: schedPRIRR <num_priorities> <quantum> <starvation_threshold>

Priority Levels:

Level Name Value
5 HIGH Highest priority
4 ABOVENORMAL Above average
3 NORMAL Default
2 BELOWNORMAL Below average
1 LOW Lowest priority

Anti-Starvation: After starvation_threshold ticks without running, low-priority processes get a priority boost.


๐Ÿ“„ Page Replacement Algorithms

FOS implements 7 page replacement algorithms for virtual memory management.

๐Ÿ“Š Algorithm Comparison

Algorithm Command Complexity Accuracy Best For
๐Ÿ”ข FIFO fifo O(1) Low Simple systems
โฐ Clock clock O(n) Medium General purpose
โฐ Modified Clock modclock O(n) Good Write-heavy
๐Ÿ“ˆ LRU (Time) lru 1 O(n) High Accuracy needed
๐Ÿ“ˆ LRU (Lists) lru 2 O(1) Good Fast approximation
๐Ÿ”„ N-Chance nthclk <n> O(n) Configurable Flexible
โญ Optimal optimal O(nร—ใฐใคm) Perfect Testing only
๐Ÿ”ข FIFO - First In First Out

The simplest replacement algorithm.

  • Idea: Replace the oldest page in memory
  • Pros: Very simple to implement
  • Cons: Doesn't consider page usage (Belady's anomaly possible)
โฐ Clock (Second Chance)

An approximation of LRU using a reference bit.

  • Idea: Give pages a "second chance" if recently used
  • Implementation: Circular buffer with clock hand
  • Reference bit: Set to 1 when page accessed, cleared by clock hand
โฐ Modified Clock

Clock algorithm that also considers the dirty bit.

  • Idea: Prefer replacing clean pages (no write-back needed)
  • Priority: (R=0, M=0) > (R=0, M=1) > (R=1, M=0) > (R=1, M=1)
๐Ÿ“ˆ LRU - Least Recently Used

Replace the page that hasn't been used for the longest time.

Two implementations:

  1. Time-based: Each page has a timestamp of last access
  2. Lists-based: Active list (hot) and Second list (cold)
โญ Optimal (Belady's)

The theoretically optimal algorithm - replace the page that won't be used for the longest time.

  • Uses: Future knowledge (reference string)
  • Purpose: Benchmarking other algorithms
  • Reality: Cannot be implemented in real systems

๐Ÿ“ž System Calls

FOS provides 30+ system calls for user programs.

๐Ÿ”„ Process Management
int32 sys_getenvid(void); // Get current process ID
void sys_exit(void); // Terminate process
int sys_create_env(char* prog_name, 
 unsigned int page_WS_size,
 unsigned int lru_second_size,
 unsigned int percent_WS_remove);
void sys_run_env(int32 envid); // Start process execution
void sys_destroy_env(int envid); // Destroy a process
void sys_yield(void); // Give up CPU
๐Ÿ’พ Memory Management
int sys_allocate_page(void *va, int perm);
int sys_map_frame(int32 srcenvid, void *srcva,
 int32 dstenvid, void *dstva, int perm);
int sys_unmap_frame(int32 envid, void *va);
void* sys_sbrk(int increment);
uint32 sys_get_brk();
void sys_free_user_mem(uint32 va, uint32 size);
uint32 sys_calculate_free_frames();
uint32 sys_calculate_modified_frames();
๐Ÿ”— Shared Memory
int sys_createSharedObject(char* shareName, uint32 size, 
 uint8 isWritable, void** returned_shared_address);
int sys_getSharedObject(int32 ownerEnvID, char* shareName, 
 void** returned_shared_address);
int sys_freeSharedObject(int32 sharedObjectID, void* startVA);
๐Ÿ”’ Semaphores
// Kernel semaphores
int sys_createSemaphore(char* name, int value);
void sys_waitSemaphore(int id);
void sys_signalSemaphore(int id);
// User semaphores
void sys_acquire_lock(struct uspinlock* lock);
void sys_release_lock(struct uspinlock* lock);
๐Ÿ–ฅ๏ธ Console I/O
void sys_cputs(const char *s, uint32 len);
int sys_cgetc(void);
void sys_cputc(int c);

๐Ÿš€ Quick Start

๐Ÿ“‹ Prerequisites

Tool Version Purpose
i386-elf-gcc Latest Cross-compiler for x86-32
i386-elf-as Latest Assembler
i386-elf-ld Latest Linker
i386-elf-objcopy Latest Binary manipulation
bochs 2.6+ x86 Emulator
make GNU Make Build system
perl 5.x Build scripts

๐Ÿ”จ Build Commands

# Build the entire project
make all
# Clean build artifacts
make clean
# Full clean (including logs)
make realclean
# Build and run in Bochs (no GUI)
make bochs

โ–ถ๏ธ Running FOS

# Start Bochs with GUI
bochs
# Start Bochs without GUI (console mode)
bochs 'display_library: nogui'
# Windows users
bochscon.bat

๐ŸŽฎ First Steps

  1. Boot FOS - Watch the initialization messages
  2. Type help - See all available commands
  3. Run Hello World: run fos_helloWorld 10
  4. Check memory: meminfo
  5. Run more programs: run fos_factorial 15
  6. Kill all processes: killall

๐Ÿ’ป Commands Reference

๐Ÿ”„ Process Management

Command Arguments Description
run <program> <ws_size> Run a program with working set size
kill <env_id> Kill a specific process
killall - Kill all running processes
runall - Run all loaded programs
printall - Print info about all processes

๐Ÿ’พ Memory Management

Command Arguments Description
meminfo - Display memory statistics
allocuserpage <va> Allocate a user page
remove_table <va> Remove a page table
readmem_k <va> Read kernel memory
writemem_k <va> <val> Write to kernel memory

๐Ÿ“„ Page Replacement

Command Description
fifo Set FIFO replacement
clock Set Clock (second chance)
modclock Set Modified Clock
lru 1 Set LRU with timestamps
lru 2 Set LRU with lists
nthclk <n> Set N-Chance Clock
optimal Set Optimal (for testing)
pagerep Print current algorithm

โฐ Scheduler

Command Arguments Description
schedRR <quantum> Set Round Robin
schedMLFQ <levels> <q1> <q2>... Set MLFQ
schedBSD <levels> <quantum> Set BSD
schedPRIRR <pri> <quantum> <thresh> Set Priority RR
schedmethod - Print current scheduler
setpriority <env_id> <priority> Set process priority

๐Ÿ’พ Heap Strategies

Command Description
khfirstfit Kernel heap: First Fit
khbestfit Kernel heap: Best Fit
khnextfit Kernel heap: Next Fit
khworstfit Kernel heap: Worst Fit
khcustomfit Kernel heap: Custom Fit
uhfirstfit User heap: First Fit
uhbestfit User heap: Best Fit
uhcustomfit User heap: Custom Fit

๐Ÿงช Testing Framework

FOS includes a comprehensive testing framework with 50+ test cases.

๐Ÿ“Š Test Categories

Category Command Prefix Description
Dynamic Allocator tst dynalloc Block allocation and freeing
Kernel Heap tst kheap kmalloc, kfree, krealloc
Page Replacement run tpr*, run tclock* All replacement algorithms
User Heap run tm*, run tf* malloc and free tests
Custom Fit run tcf* Custom allocation tests
Shared Memory run tshr* Shared memory operations
Semaphores run tst_ksem* Synchronization tests
Scheduler tst priorityRR Priority scheduling
Environment Free run tef* Process cleanup tests

๐Ÿ”„ Running Tests

# Dynamic allocator tests
FOS> tst dynalloc init
FOS> tst dynalloc alloc
FOS> tst dynalloc free
FOS> tst dynalloc realloc
# Kernel heap tests
FOS> tst kheap CF kmalloc blk
FOS> tst kheap CF kfree both
# User program tests
FOS> run tm1 3000
FOS> run tm2 3000
FOS> run tshr1 3000
# Page replacement tests
FOS> clock
FOS> run tclock1 11
FOS> run tclock2 11
# Scheduler tests
FOS> schedPRIRR 10 40 1000
FOS> tst priorityRR 0

๐Ÿ› Debugging

๐Ÿ”ง GDB Debugging

# Start Bochs in debug mode
bochs -f .bochsrc-debug
# In another terminal, connect with GDB
gdb obj/kern/kernel
(gdb) target remote localhost:1234
(gdb) break FOS_initialize
(gdb) continue
(gdb) info registers
(gdb) x/10x $esp

๐Ÿ” Kernel Debug Functions

// Print debug information
void debug_printinfo(void);
// Print stack backtrace
void debug_backtrace(void);
// Kernel panic - halt system
void _panic(const char *file, int line, const char *fmt, ...);
// Panic and exit all environments
void _panic_all(const char *file, int line, const char *fmt, ...);
// Warning - continue execution
void _warn(const char *file, int line, const char *fmt, ...);

๐Ÿ“ Debug Macros

// Assert condition
assert(condition);
// Panic with message
panic("Something went wrong: %d", error_code);
// Warning message
warn("Unexpected value: %x", value);

๐Ÿ‘จโ€๐Ÿซ Course Instructor

๐ŸŽ“ Dr. Ahmed Salah

Course Instructor

Faculty of Computers and Information Science
Ain Shams University

Operating Systems Course


๐Ÿ‘ฅ Development Team


๐Ÿ“œ License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

๐Ÿ“‹ License Summary

Permissions Conditions Limitations
โœ… Commercial use ๐Ÿ“‹ License and copyright notice โŒ Liability
โœ… Modification ๐Ÿ“‹ State changes โŒ Warranty
โœ… Distribution ๐Ÿ“‹ Disclose source
โœ… Patent use ๐Ÿ“‹ Same license
โœ… Private use

๐Ÿ›๏ธ Original Components

FOS is derived from multiple open-source projects:

Component Source Original License
Core Kernel MIT Exokernel MIT License
Console Driver NetBSD pccons BSD License
Clock/Scheduler Exotec, Inc. Exotec License
Printf UC Berkeley BSD License
Process Management xv6 (MIT) MIT License

๐Ÿ™ Acknowledgments

Contributor Contribution
Dr. Ahmed Salah Course instructor and guidance
MIT PDOS Group Exokernel foundation
UC Berkeley Console and printf code
xv6 Developers Inspiration and reference

๐ŸŽ“ Developed at

Faculty of Computers and Information Science
Ain Shams University
Cairo, Egypt


๐Ÿ“ง Contact

Fady Gerges
๐Ÿ“ง Email: fadygerges2023@gmail.com
๐Ÿ”— GitHub: @Fady2024
๐Ÿ“‚ Repository: OS_Project_2025


Made with Love For Education Team


โญ Star this repo if you found it helpful!

GitHub stars


Copyright ยฉ 2025 Fady Gerges and contributors
Last Updated: January 2026

About

A comprehensive educational operating system kernel developed for teaching OS concepts at FCIS - Ain Shams University.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

AltStyle ใซใ‚ˆใฃใฆๅค‰ๆ›ใ•ใ‚ŒใŸใƒšใƒผใ‚ธ (->ใ‚ชใƒชใ‚ธใƒŠใƒซ) /