Skip to content

jorgeandrecastro/JC-OS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

JC-OS โ€” Bare-Metal Operating System Kernel

A minimalist operating system kernel written in Rust, designed to run directly on x86_64 hardware without any underlying operating system.

๐Ÿ“– Project Description

JC-OS is a personal hobby kernel project focused on low-level system programming. It runs in a no_std environment and is bootstrapped via the Rust bootloader crate on x86_64 systems.

This project demonstrates the fundamentals of OS creation:

  • Custom boot via UEFI/Legacy bootloader
  • Hardware management without system abstraction
  • Direct communication with CPU and peripherals
  • VGA video memory manipulation
  • Hardware interrupt handling
  • Virtual memory with paging
  • Dynamic memory allocation (heap)
  • Hierarchical file system with directories and permissions
  • Interactive shell with real-time clock display
  • Async/await task scheduling with executor
  • User management with UID system
  • Automatic timezone support (Europe/France)
  • PS/2 mouse driver (in development)

โœจ Implemented Features

Display

  • VGA text output (80ร—25 characters)
  • 16 foreground and background colors
  • Automatic scrolling when screen is full
  • Smart backspace with line wrapping
  • Hardware cursor update (ports 0x3D4/0x3D5)
  • Color-coded UI elements with border boxes

Input

  • PS/2 keyboard with French AZERTY layout
  • Scancode Set 2 (IBM standard)
  • Complete alphanumeric key mapping
  • Special keys: Enter, Backspace, Escape
  • Command buffer with 256 character capacity

File System

  • Hierarchical RAM File System - Multi-level directory structure
  • Inode-based design with UID and permissions
  • Current Working Directory (CWD) navigation
  • Directory operations: look, open, room (create directory)
  • File operations: touch, cat, read, edit, note, drop
  • Path navigation: absolute and relative paths
  • Automatic home directory creation for new users
  • BTreeMap-based organization for efficient lookup
  • Statistics tracking: file count and total size
  • Unicode support via UTF-8 lossless conversion

Interactive Shell

  • Command interpreter with multiple built-in commands
  • File management commands: touch, cat, rm, edit
  • System information: info, stats, whoami, neofetch, date
  • Utility commands: help, echo, clear, ls
  • Secure login system with authentication

User Authentication & Management

  • Role-based access control with Admin and Standard roles
  • User management with login/logout functionality
  • Dynamic user creation with useradd command (Admin only)
  • User deletion with userdel command (Admin only)
  • UID system for user identification
  • Session tracking with current user identification
  • Password authentication with credential validation
  • Automatic home directory creation for new users
  • Default admin account: username "andre", password "admin123"

Real-Time Clock (RTC)

  • CMOS RTC access via ports 0x70/0x71
  • BCD to decimal conversion for accurate time reading
  • Time struct with hours, minutes, seconds
  • Automatic timezone adjustment for France (UTC+1/+2)
  • Daylight Saving Time (DST) support with European rules
  • Non-volatile time keeping independent of system power

PS/2 Mouse Driver

  • PS/2 mouse interface via ports 0x60/0x64
  • 3-byte packet protocol for movement and button data
  • Movement delta calculation with sign extension
  • Cursor position tracking with screen boundary clamping
  • Mouse state management with phase-based packet decoding
  • Auxiliary port enablement for mouse device
  • Data reporting activation for real-time input

Task Scheduling

  • Async/await support with Rust futures
  • Task executor with round-robin scheduling
  • Task queue using VecDeque
  • Cooperative multitasking via yield_now()
  • Task identification with atomic TaskId
  • Pin-based future pinning for safe async execution

System Management

  • GDT (Global Descriptor Table) - CPU segmentation
  • TSS (Task State Segment) with Double Fault stack
  • IDT (Interrupt Descriptor Table) - Interrupt vectors
  • PIC 8259 - Programmable Interrupt Controller
  • Double Fault Handler protected by IST (Interrupt Stack Table)
  • Timer Interrupt - Hardware timer (IRQ0) for real-time clock display
  • Keyboard Interrupt - PS/2 keyboard input handling
  • Mouse Interrupt - PS/2 mouse input handling (IRQ12)

Memory Management

  • x86_64 Paging (4-level page tables)
  • Physical memory mapping via bootloader info
  • Frame allocator using UEFI memory map
  • Heap allocation (100 KiB) with linked-list allocator
  • Virtual to physical address translation
  • Page-level protection (PRESENT, WRITABLE flags)
  • Error handling with Result type and alloc_error_handler

Debugging

  • COM1 serial output via UART 16550
  • Complete boot logging
  • Memory statistics display (heap start, size, status)
  • Panic error display via serial
  • Interrupt event logging

๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              JC-OS Kernel v0.4                   โ”‚
โ”‚              Andre Edition                       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Entry Point: kernel_main()                     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚           Initialization Order            โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚  โ”‚  1. GDT + TSS     (CPU segmentation)      โ”‚  โ”‚
โ”‚  โ”‚  2. IDT           (interrupt table)       โ”‚  โ”‚
โ”‚  โ”‚  3. PIC           (interrupt controller)  โ”‚  โ”‚
โ”‚  โ”‚  4. PS/2 Controller (keyboard+mouse)     โ”‚  โ”‚
โ”‚  โ”‚  5. Keyboard Driver (AZERTY Set2)        โ”‚  โ”‚
โ”‚  โ”‚  6. Paging Setup  (4-level page tables)  โ”‚  โ”‚
โ”‚  โ”‚  7. Frame Allocator (memory map parsing) โ”‚  โ”‚
โ”‚  โ”‚  8. Heap Init      (100 KiB allocator)   โ”‚  โ”‚
โ”‚  โ”‚  9. File System    (Hierarchical RAMFS)  โ”‚  โ”‚
โ”‚  โ”‚  10. Auth System    (user management)    โ”‚  โ”‚
โ”‚  โ”‚  11. RTC Driver     (time+timezone)     โ”‚  โ”‚
โ”‚  โ”‚  12. Mouse Driver   (PS/2 input)        โ”‚  โ”‚
โ”‚  โ”‚  13. Task System    (Executor init)     โ”‚  โ”‚
โ”‚  โ”‚  14. Interrupts enabled                  โ”‚  โ”‚
โ”‚  โ”‚  15. UI Launch     (shell prompt)        โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Memory Layout (Virtual Address Space)          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  0x0000_0000_0000 - Kernel Code           โ”‚  โ”‚
โ”‚  โ”‚  ...                                      โ”‚  โ”‚
โ”‚  โ”‚  0x4444_4444_0000 - HEAP START (100 KiB)  โ”‚  โ”‚
โ”‚  โ”‚  0x4444_4444_19000 - HEAP END             โ”‚  โ”‚
โ”‚  โ”‚  ...                                      โ”‚  โ”‚
โ”‚  โ”‚  Higher half kernel (identity mapped)     โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Task Scheduling Architecture                    โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  Executor                                  โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ Task Queue: VecDeque<Task>           โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ spawn(task) โ†’ push_back              โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ run() โ†’ poll futures in loop         โ”‚  โ”‚
โ”‚  โ”‚                                            โ”‚  โ”‚
โ”‚  โ”‚  Task                                      โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ id: TaskId (atomic u64)              โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ future: Pin<Box<dyn Future>>         โ”‚  โ”‚
โ”‚  โ”‚                                            โ”‚  โ”‚
โ”‚  โ”‚  YieldNow Future                          โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ yielded: bool                        โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ poll() โ†’ Pending/Ready               โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Authentication & User Management               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  AuthManager                               โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ users: Vec<User>                     โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ current_user: Option<User>           โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ next_uid: u32                        โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ login(username, password) -> bool   โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ logout()                             โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ add_user(username, pass) -> uid      โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ delete_user(username) -> Result      โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ get_current_uid() -> u32             โ”‚  โ”‚
โ”‚  โ”‚                                            โ”‚  โ”‚
โ”‚  โ”‚  User                                      โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ username: String                     โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ password_hash: String                โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ role: Role (Admin/Standard)          โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ uid: u32                             โ”‚  โ”‚
โ”‚  โ”‚                                            โ”‚  โ”‚
โ”‚  โ”‚  Role Enum                                โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ Admin     - Full system access       โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ Standard  - Limited access           โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Hierarchical File System Architecture          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  RamFileSystem                            โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ root: Directory                      โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ cwd: Vec<String>                     โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ look() -> Vec<(name, type)>         โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ open(path) -> Result                 โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ room(name, uid) -> Result            โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ write_file(name, content, uid)       โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ read_file(name) -> Option<String>    โ”‚  โ”‚
โ”‚  โ”‚                                            โ”‚  โ”‚
โ”‚  โ”‚  Directory                                 โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ inode: Inode                         โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ entries: BTreeMap<String, FsNode>    โ”‚  โ”‚
โ”‚  โ”‚                                            โ”‚  โ”‚
โ”‚  โ”‚  Inode                                     โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ uid: u32                             โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ permissions: u16                      โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ node_type: File/Directory            โ”‚  โ”‚
โ”‚  โ”‚                                            โ”‚  โ”‚
โ”‚  โ”‚  FsNode Variants                          โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€โ”€ File(File)                           โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€ Directory(Directory)                 โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Managed Peripherals:                           โ”‚
โ”‚  โ€ข VGA 0xB8000  - Text screen                  โ”‚
โ”‚  โ€ข COM1 0x3F8   - Serial port                  โ”‚
โ”‚  โ€ข PIC 0x20/0xA0 - Interrupt controller        โ”‚
โ”‚  โ€ข PS/2 0x60/0x64 - Keyboard + Mouse           โ”‚
โ”‚  โ€ข PIT 0x40     - Programmable Interval Timer  โ”‚
โ”‚  โ€ข RTC 0x70/0x71 - Real Time Clock (CMOS)      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ Project Structure

jc-os/
โ”œโ”€โ”€ Cargo.toml                    # Rust project configuration
โ”œโ”€โ”€ Readme.md                     # This file
โ”œโ”€โ”€ x86_64-jc-os.json             # Custom target spec
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main.rs                   # Entry point + initialization
โ”‚   โ”œโ”€โ”€ gdt.rs                    # GDT + TSS (segmentation)
โ”‚   โ”œโ”€โ”€ interrupts.rs             # IDT + PIC handling + handlers
โ”‚   โ”œโ”€โ”€ vga_buffer.rs             # Color VGA text driver
โ”‚   โ”œโ”€โ”€ serial.rs                 # COM1 serial output (UART 16550)
โ”‚   โ”œโ”€โ”€ memory.rs                 # Paging + frame allocator
โ”‚   โ”œโ”€โ”€ allocator.rs              # Heap allocator (linked-list)
โ”‚   โ”œโ”€โ”€ fs.rs                     # RAM File System (RAMFS)
โ”‚   โ”œโ”€โ”€ auth.rs                   # User authentication system
โ”‚   โ”œโ”€โ”€ task.rs                   # Task structures + async support
โ”‚   โ”œโ”€โ”€ executor.rs               # Task executor + scheduler
โ”‚   โ”œโ”€โ”€ shell.rs                  # Interactive shell with login
โ”‚   โ””โ”€โ”€ drivers/
โ”‚       โ”œโ”€โ”€ mod.rs                # Drivers module (export)
โ”‚       โ”œโ”€โ”€ keyboard.rs           # PS/2 AZERTY keyboard driver + shell
โ”‚       โ”œโ”€โ”€ mouse.rs              # PS/2 mouse driver (in development)
โ”‚       โ””โ”€โ”€ rtc.rs                # Real Time Clock driver
โ””โ”€โ”€ target/
    โ””โ”€โ”€ x86_64-jc-os/             # Compiled binaries

๐Ÿ”ง Detailed Components

1. GDT (src/gdt.rs)

Role: CPU memory segmentation configuration

โ€ข Kernel Code Segment (64-bit execution)
โ€ข TSS (Task State Segment) for:
  - Double Fault Handler stack
  - IST Index 0: 5 stack pages (20KB)

2. IDT (src/interrupts.rs)

Role: Routes interrupts to appropriate handlers

Configured Vectors:
โ€ข Double Fault (CPU Exception) โ†’ Isolated stack
โ€ข Timer (IRQ0)    โ†’ Basic handler (for future scheduling)
โ€ข Keyboard (IRQ1) โ†’ Keyboard driver

PIC Configuration:
โ€ข Master: Timer + Keyboard enabled (0xF8)
โ€ข Slave:  All disabled (0xFF)

3. Memory Management (src/memory.rs)

Role: Paging and physical memory allocation

Features:
โ€ข 4-Level Paging (PML4 โ†’ PDP โ†’ PD โ†’ PT)
โ€ข CR3 register read for active page table
โ€ข OffsetPageTable for higher-half mapping
โ€ข BootInfoFrameAllocator uses UEFI memory map

Memory Map Parsing:
โ€ข Iterates through bootloader memory regions
โ€ข Filters for Usable memory type
โ€ข Allocates 4KiB frames for page mapping
โ€ข Tracks next available frame index

Memory Map Entry Example:

Region types:
โ€ข Usable RAM          โ†’ Can be allocated
โ€ข Reserved            โ†’ Not available
โ€ข ACPI Reclaimable    โ†’ Can be used after ACPI
โ€ข EFI Runtime         โ†’ Reserved for firmware

4. Heap Allocator (src/allocator.rs)

Role: Dynamic memory allocation for kernel

Configuration:
โ€ข Heap Start:  0x4444_4444_0000 (virtual)
โ€ข Heap Size:   100 KiB
โ€ข Allocator:   linked_list_allocator::LockedHeap
โ€ข Page Flags:  PRESENT | WRITABLE

Initialization:
โ€ข Maps 25 pages (25 ร— 4KiB = 100 KiB)
โ€ข Initializes LockedHeap with start pointer
โ€ข Provides heap_start() and heap_size() queries
โ€ข Returns Result<(), ()> for error handling

Memory Statistics (displayed at boot):
โ€ข Heap Start : 0x444444440000
โ€ข Heap Size  : 100 KB
โ€ข Status     : DYNAMIC ALLOCATION OK

5. Hierarchical RAM File System (src/fs.rs)

Role: Hierarchical in-memory file storage with directories and permissions

Structure:
โ€ข Inode: uid, permissions, node_type (File/Directory)
โ€ข File: inode + data (Vec<u8>)
โ€ข Directory: inode + entries (BTreeMap<String, FsNode>)
โ€ข RamFileSystem: root Directory + cwd (current working directory)
โ€ข Global instance protected by Mutex

FsNode Enum:
โ€ข File(File) - Regular file with content
โ€ข Directory(Directory) - Container for other nodes

Features:
โ€ข Hierarchical Structure:
  - Root directory "/" as entry point
  - Current Working Directory (CWD) navigation
  - open(path) - Navigate to directory
  - look() - List current directory contents
  - room(name, uid) - Create new directory

โ€ข File Operations:
  - write_file(name, content, uid) - Create/overwrite with UID tracking
  - read_file(name) - Read file as String (returns Option)
  - remove_file(name) - Delete file/directory (returns bool)
  - get_stats() - Returns (file_count, total_bytes)

โ€ข Path Navigation:
  - "/" - Return to root
  - ".." - Go up one level
  - name - Enter subdirectory

โ€ข Security:
  - UID tracking for file ownership
  - Permission flags (0o644 for files, 0o755 for directories)
  - Home directory auto-creation for new users

Storage:
โ€ข In-memory only (volatile)
โ€ข Unicode support via UTF-8 lossless conversion
โ€ข No persistence (data lost on reboot)

6. User Authentication & Management (src/auth.rs)

Role: User management, authentication, and access control

Structure:
โ€ข Role Enum: Admin, Standard
โ€ข User: username, password_hash, role, uid
โ€ข AuthManager: users Vec, current_user Option, next_uid u32

Features:
โ€ข login(username, password) -> bool
  - Authenticates user credentials
  - Case-insensitive username matching
  - Returns true on successful authentication
  - Sets current_user session

โ€ข logout()
  - Clears current user session
  - Sets current_user to None

โ€ข add_user(username, password) -> Result<u32, &str>
  - Creates new user with Standard role
  - Assigns unique UID (starting from 1000)
  - Prevents duplicate usernames
  - Returns new UID on success

โ€ข delete_user(username) -> Result<(), &str>
  - Removes user from system
  - Protects primary admin account
  - Prevents deleting current user
  - Returns error if user not found

โ€ข get_current_username() -> String
  - Returns current username or "Guest" if not logged in

โ€ข get_current_uid() -> u32
  - Returns current user's UID
  - Returns 1000 for Guest

โ€ข Role-based access control
  - Admin: Full system access, user management
  - Standard: Limited permissions

Default User:
โ€ข Username: "andre"
โ€ข Password: "admin123"
โ€ข Role: Admin
โ€ข UID: 0

Security Features:
โ€ข Password masking during input
โ€ข Session management
โ€ข Credential validation
โ€ข Case-insensitive username matching
โ€ข Admin-only user management operations

Lazy Static Initialization:
โ€ข AUTH: Mutex<AuthManager> for thread-safe access
โ€ข Automatically initialized at kernel startup

7. Real-Time Clock (src/drivers/rtc.rs)

Role: CMOS RTC access for time keeping with automatic timezone

Hardware Interface:
โ€ข Address Port: 0x70 (write register index)
โ€ข Data Port: 0x71 (read/write data)
โ€ข BCD Format: Binary Coded Decimal

RtcTime Structure:
โ€ข seconds: u8 (0-59)
โ€ข minutes: u8 (0-59)
โ€ข hours: u8 (0-23)

Functions:
โ€ข read_rtc_register(reg: u8) -> u8
  - Writes register index to port 0x70
  - Reads data from port 0x71
  - Returns raw BCD value

โ€ข get_time() -> RtcTime
  - Reads registers 0x00 (seconds), 0x02 (minutes), 0x04 (hours)
  - Reads date registers 0x07 (day), 0x08 (month), 0x09 (year)
  - Converts BCD to decimal
  - Applies timezone adjustment (France UTC+1/+2)
  - Returns RtcTime struct with corrected time

BCD Conversion:
โ€ข BCD = (value & 0x0F) + ((value / 16) * 10)
โ€ข Extracts low nibble and high nibble
โ€ข Combines for correct decimal value

Timezone Support:
โ€ข Automatic adjustment for France timezone
โ€ข Summer time (DST): UTC+2 (March-October)
โ€ข Winter time: UTC+1 (November-February)
โ€ข DST calculated using European rules (last Sunday of March/October)

Features:
โ€ข Battery-backed time keeping (independent of power)
โ€ข Standard CMOS RTC chip compatible
โ€ข 24-hour format support
โ€ข No interrupts required for reading
โ€ข Real-time clock display in shell (updated every second)

8. PS/2 Mouse Driver (src/drivers/mouse.rs)

Role: PS/2 mouse input handling for cursor tracking

Hardware Interface:
โ€ข Command Port: 0x64 (PS/2 controller)
โ€ข Data Port: 0x60 (keyboard/mouse data)
โ€ข Auxiliary Port: Enabled via command 0xA8

MouseState Structure:
โ€ข phase: u8 - Packet decoding phase (0-2)
โ€ข buffer: [u8; 3] - Raw packet data
โ€ข x, y: i32 - Current cursor position
โ€ข old_x, old_y: i32 - Previous position for rendering

Packet Protocol (3 bytes):
โ€ข Byte 0: Flags (bit 0=Left, 1=Right, 2=Middle, 3=Always 1, 4=X sign, 5=Y sign, 6=X overflow, 7=Y overflow)
โ€ข Byte 1: X movement delta (signed)
โ€ข Byte 2: Y movement delta (signed)

Functions:
โ€ข init() - Initialize mouse controller
  - Enables auxiliary port
  - Configures interrupt enable
  - Sets bit default mouse parameters
  - Enables data reporting

โ€ข add_mouse_data(data: u8) - Process incoming mouse data
  - Phase-based packet decoding
  - Movement delta calculation with sign extension
  - Position clamping to screen bounds (0-79 for X, 0-24 for Y)
  - Cursor rendering

โ€ข draw_cursor(x, y, old_x, old_y) - Render mouse cursor
  - Tracks cursor position changes
  - Prepares for visual cursor display

Features:
โ€ข 3-byte packet protocol standard
โ€ข Movement delta with sign extension
โ€ข Screen boundary clamping
โ€ข Button state tracking (left, right, middle)
โ€ข Real-time position updates
โ€ข Auxiliary port communication
โ€ข Data reporting enable/disable

Status:
โ€ข Driver initialized and functional
โ€ข Cursor position tracking implemented
โ€ข Visual cursor rendering prepared

9. Task Management (src/task.rs)

Role: Async task structures and cooperative multitasking

TaskId:
โ€ข Atomic u64 counter for unique identification
โ€ข Thread-safe ID generation
โ€ข Implements Debug, Clone, Copy, Eq, Ord

Task:
โ€ข id: TaskId - Unique task identifier
โ€ข future: Pin<Box<dyn Future<Output = ()>>>
  - Pinned future for safe async execution
  - Boxed for heap allocation
  - Sized for task queue storage

YieldNow Future:
โ€ข Cooperative multitasking primitive
โ€ข yielded: bool flag
โ€ข First poll returns Pending, second returns Ready
โ€ข Used for task yielding in async contexts

yield_now() Function:
โ€ข Creates YieldNow future
โ€ข Enables cooperative task switching
โ€ข Simple API for async code

9. Task Executor (src/executor.rs)

Role: Async task scheduler and runtime

Executor Structure:
โ€ข task_queue: VecDeque<Task>
  - Double-ended queue for efficient push/pop
  - FIFO ordering for round-robin scheduling
  - Dynamic task storage

Methods:
โ€ข new() -> Self
  - Creates empty executor instance
  - Initializes task queue

โ€ข spawn(&mut self, task: Task)
  - Adds task to end of queue
  - Task: Future wrapped in Task struct
  - Non-blocking operation

โ€ข run(&mut self) -> !
  - Main executor loop
  - Calls run_ready_tasks() repeatedly
  - Uses hlt() for power efficiency
  - Never returns (infinite loop)

โ€ข run_ready_tasks(&mut self)
  - Polls all ready tasks
  - Processes tasks in queue order
  - Maintains remaining_tasks counter
  - Re-queues pending tasks

Internal Functions:
โ€ข dummy_waker() -> Waker
  - Creates no-op waker for polling
  - RawWaker with minimal VTable
  - Required by Context::from_waker()

Waker Implementation:
โ€ข clone: Duplicates RawWaker
โ€ข no_op: Empty wake function
โ€ข VTable: Static RawWakerVTable

10. VGA Buffer (src/vga_buffer.rs)

Role: Text display on VGA screen

Specifications:
โ€ข Address: 0xB8000
โ€ข Size: 80 ร— 25 = 2000 characters
โ€ข Attributes: 1 color byte + 1 character byte

Features:
โ€ข 16 ANSI colors (Black โ†’ White)
โ€ข Automatic scroll with line preservation
โ€ข Smart backspace (wraps to previous line)
โ€ข Hardware cursor update
โ€ข Color-coded output support

11. PS/2 Keyboard (src/drivers/keyboard.rs)

Role: Translates scancodes to characters and shell command handling

Configuration:
โ€ข Layout: French AZERTY
โ€ข Scancode Set: 2 (IBM standard)
โ€ข Control: Ignore Ctrl (for testing)
โ€ข Command Buffer: 256 character capacity

Shell Commands:
โ€ข help     - Show available commands
โ€ข info     - Display system information
โ€ข whoami   - Display current user
โ€ข date     - Display current time from RTC
โ€ข echo     - Print text to screen
โ€ข ls       - List files in RAMFS
โ€ข touch    - Create new file
โ€ข cat      - Read file content
โ€ข rm       - Delete file
โ€ข edit     - Modify existing file
โ€ข stats    - Show filesystem statistics
โ€ข neofetch - Display system info (ASCII art)
โ€ข clear    - Clear screen
โ€ข Esc      - Clear buffer + reset screen

Handled Keys:
โ€ข Letters a-z, A-Z (AZERTY layout)
โ€ข Digits 0-9
โ€ข French accented characters (รจ, รฉ, รช, รซ)
โ€ข Special characters (, ; : !)
โ€ข Enter, Backspace, Escape

12. Interactive Shell (src/shell.rs)

Role: Command interpreter with authentication

Shell Features:
โ€ข Secure login system on boot
โ€ข Password masking for sensitive input
โ€ข Command history and buffer management
โ€ข Multi-line command support
โ€ข Color-coded prompt with user info

Login System:
โ€ข Requires authentication before command access
โ€ข Username and password prompts
โ€ข Credential validation via AuthManager
โ€ข Session persistence until logout

Prompt Format:
โ€ข Shows current username and hostname
โ€ข Visual indicator of authentication status
โ€ข Example: "andre@jc-os:~$ "

Session Management:
โ€ข Automatic login requirement
โ€ข Session tracking with AuthManager
โ€ข User identification for commands
โ€ข Future: Multiple user sessions

Command Buffer:
โ€ข 256 character capacity
โ€ข Backspace with visual feedback
โ€ข Escape key to clear and reset
โ€ข Support for long commands with wrapping

13. Serial Port (src/serial.rs)

Role: Debugging via serial connection

Configuration:
โ€ข Port: COM1 (0x3F8)
โ€ข UART: 16550 standard
โ€ข Output: stdout during QEMU debugging

Usage:
โ€ข Boot log: "[JC-OS] Kernel starting..."
โ€ข System log: "[GDT] Loaded", "[IDT] Loaded"
โ€ข Memory stats: "Heap Allocator Ready"
โ€ข Panic display
โ€ข Serial print for debugging

๐Ÿš€ Installation and Compilation

Prerequisites

# Rust nightly with bare-metal target
rustup target add x86_64-unknown-none

# Bootable image creation tool
cargo install bootimage

# Required LLVM components
rustup component add llvm-tools-preview

# QEMU emulator
# Ubuntu/Debian: sudo apt install qemu-system-x86
# Arch: sudo pacman -S qemu
# macOS: brew install qemu

Compilation and Execution

# Debug mode (fast, with asserts)
cargo run

# Release mode (optimized, faster)
cargo run --release

# Create bootable image only
cargo bootimage

# Run bootable image with QEMU
qemu-system-x86_64 \
  -drive format=raw,file=target/x86_64-jc-os/release/bootimage-jc-os.bin \
  -serial stdio

๐Ÿ” Login Credentials

By default, JC-OS v0.4 includes a secure login system:

Username: andre
Password: admin123
Role: Admin
UID: 0

Note: The first time you run JC-OS v0.4, you will be presented with a login screen. Use the default credentials above to access the shell. Administrators can create new users using the useradd command.

โŒจ๏ธ Shell Commands

Authentication

Command Description
(Login) Enter username and password at startup
whoami Display current authenticated user
logout End current session
useradd Create new user (Admin only)
userdel Delete user (Admin only)

File Management

Command Description Usage
look List directory contents look
open Change directory open <directory>
room Create directory room <name>
where Show current path where
note Create file with content note <filename> <content>
read Read file content read <filename>
drop Delete file/directory drop <filename>
edit Modify file edit <filename> <new_content>
type Interactive file editor type <filename>

Navigation

Command Description
/ Go to root directory
.. Go up one directory level
directory_name Enter subdirectory

System Information

Command Description Output Example
info Display system info JC-OS v0.4 - Andre Edition
whoami Display current user andre
date Display current time (timezone adjusted) Time: 14:30:45
stats Show filesystem stats Files: 3, Memory: 256 bytes
neofetch ASCII system info Art + system details

Utilities

Command Description
help Show available commands
echo Print text to screen
clear Clear the screen
Enter Execute command
Backspace Delete previous character
Esc Clear buffer + reset screen

Editor Shortcuts (type command)

Shortcut Description
Ctrl+S Save file
Ctrl+Q Quit editor

๐Ÿ” Example Session

qemu-system-x86_64 -drive format=raw,file=target/x86_64-jc-os/debug/bootimage-jc-os.bin -serial stdio

[JC-OS] Kernel starting...
[GDT] Loaded
[IDT] Interrupt Descriptor Table loaded
[PIC] Initialized - Timer and Keyboard enabled
[PS/2] Keyboard controller initialized
[KEYBOARD] Driver initialized (AZERTY layout, Set2)
[PAGING] 4-Level page tables initialized
[FRAMES] Boot info frame allocator ready
[SYSTEM] Heap Allocator Ready
[FS] RAM File System initialized (Hierarchical)
[AUTH] Authentication system initialized
[RTC] Real Time Clock initialized (Timezone: Europe/Paris)
[MOUSE] PS/2 Mouse driver initialized
[EXECUTOR] Task scheduler ready

 JC-OS - BARE METAL KERNEL v0.4 - RUST EDITION

--- LOGIN REQUIRED ---
Username: andre
Password: ********
Welcome back, andre!

Digital Sovereignty System
File System: READY (Hierarchical RAMFS) | Try: look, open, room, where
Task Scheduling: READY | Async/Await supported
Authentication: ENABLED | Session active

andre@jc-os:/$ help
Commands: help, info, stats, echo, whoami, look, open, room, where, note, read, drop, type, useradd, userdel, date, neofetch

andre@jc-os:/$ date
Time: 14:30:45 (UTC+2, Summer Time)

andre@jc-os:/$ room home
Directory 'home' created.

andre@jc-os:/$ open home
andre@jc-os:/home$

andre@jc-os:/home$ room andre
Directory 'andre' created.

andre@jc-os:/home$ note welcome.txt "Welcome to JC-OS!"
File 'welcome.txt' created.

andre@jc-os:/home$ look
andre/
welcome.txt

andre@jc-os:/home$ where
/home

andre@jc-os:/home$ open andre
andre@jc-os:/home/andre$

andre@jc-os:/home/andre$ type test.txt
[TYPE: test.txt] (Ctrl+S to save, Ctrl+Q to exit)
Hello from interactive editor!

andre@jc-os:/home/andre$ useradd john secret123
[AUTH] User 'john' created with UID 1000.
[FS] Home directory /home/john created.

andre@jc-os:/home/andre$ stats
--- SYSTEM STATS ---
Files/Folders : 2
Used Space    : 25 bytes

andre@jc-os:/home/andre$ neofetch
  _/_/   JC-OS v0.4 - Rust Edition
 _/      User : andre
_/_/_/    FS   : Hierarchical RAMFS
           Time : 14:30:45

andre@jc-os:/home/andre$ where
/home/andre

andre@jc-os:/home/andre$ logout

--- LOGIN REQUIRED ---
Username: andre
Password: ********

๐Ÿ“ฆ Cargo Dependencies

Crate Version Usage
bootloader 0.9.23 Kernel bootstrapping + memory map
x86_64 0.14 x86_64 CPU structures + paging
spin 0.9 Lock-free synchronization
pc-keyboard 0.7.0 PS/2 scancode parsing
pic8259 0.10.1 8259 PIC controller
uart_16550 0.2.0 COM1 serial port
lazy_static 1.4.0 Deferred static initialization
volatile 0.2.6 VGA volatile memory access
linked_list_allocator 0.10 Heap allocation algorithm
crossbeam-queue 0.3.12 Lock-free queue for task scheduling
alloc - Dynamic memory allocation

๐Ÿ› Troubleshooting

QEMU not found

# Check installation
which qemu-system-x86_64

# Install if needed
sudo apt install qemu-system-x86  # Debian/Ubuntu

"target not found" compilation error

# Add x86_64-unknown-none target
rustup target add x86_64-unknown-none

No VGA output

Verify VGA graphics mode is enabled in QEMU with -vga std.

No serial output

Use -serial stdio parameter to redirect COM1 to the terminal.

Heap allocation failed

Ensure enough physical memory is available (QEMU default: 128MiB). Increase with: -m 256M

Keyboard not responding

Check AZERTY layout mapping or try with US QWERTY layout.

File system commands not working

Ensure RAMFS is initialized: check boot log for "[FS] RAM File System initialized"

RTC time showing incorrect values

  • Verify RTC is properly initialized in QEMU
  • Check CMOS battery status (virtual in QEMU)
  • Ensure BCD conversion is working correctly

Authentication login fails

  • Verify credentials: username "andre", password "admin123"
  • Check that AUTH system initialized in boot log
  • Ensure passwords are case-sensitive for username matching
  • Try resetting credentials if persistent storage available

Async tasks not running

Verify executor is initialized and run() is called in main loop

๐Ÿ”ฎ Future Improvements

  • Mouse Integration - Full cursor rendering, click events, GUI interaction
  • Page Fault Handler - Better memory error reporting and debugging
  • Kernel Heap Expansion - Dynamic heap growth based on demand
  • Persistent Storage - Disk driver with FAT32 reading/writing
  • Advanced Shell - Tab completion, command history, environment variables
  • Preemptive Scheduling - Timer-based task switching
  • Multiple Executors - Multi-core task distribution
  • Task Priorities - Priority-based task scheduling
  • Inter-Task Communication - Channels, signals, and message passing
  • Virtual File System - VFS abstraction layer for multiple file systems
  • Process Management - Process creation, termination, and IPC
  • System Calls - User-mode to kernel-mode transitions
  • Memory Protection - User/kernel memory isolation
  • Enhanced Authentication - Password hashing with bcrypt/argon2
  • Multi-User Sessions - Multiple concurrent user sessions
  • Audit Logging - Authentication logs, command history tracking
  • Network Support - Network card driver and basic networking
  • GUI Subsystem - Window manager and basic graphics
  • Date Display - Full date functionality with timezone selection
  • File Permissions - Permission enforcement per UID

๐Ÿ”’ Security Features

Current Implementation

  • User Authentication: Login required before shell access
  • Role-Based Access: Admin vs Standard user roles
  • User Management: Admin-only user creation and deletion
  • UID Tracking: Unique user identification system
  • Session Management: Track current authenticated user
  • Password Masking: Hide password input during login
  • Credential Validation: Case-insensitive username matching
  • Home Directory Isolation: Each user gets personal directory

Planned Security Enhancements

  • Password Hashing: Replace plain-text password storage with bcrypt/argon2
  • Multi-Factor Authentication: Additional verification methods
  • Session Timeout: Automatic logout after inactivity
  • Account Lockout: Brute-force protection
  • Audit Trail: Log all authentication attempts and privileged actions
  • Secure Boot: Verify kernel integrity at startup
  • User Isolation: Separate memory spaces per user
  • Permission System: File and command access control enforcement

๐Ÿ“„ License

This project is licensed under Apache 2.0.

๐Ÿค Contributions

Issues and pull requests are welcome to improve the project!


JC-OS v0.4 - Andre Edition
A minimalist bare-metal operating system written in Rust

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages