docs: enrich README.md with comprehensive documentation, badges, architecture diagrams, and command guides

This commit is contained in:
RarDog
2026-09-02 21:32:30 +03:00
parent 1ef1fe8a60
commit 7cae3b55a6
+192 -103
View File
@@ -1,149 +1,238 @@
# opencoreC: High-Performance x86_64 Microkernel OS # 🌟 opencoreC: High-Performance x86_64 Microkernel OS
[![Architecture](https://img.shields.io/badge/Arch-x86__64%20(Long%20Mode)-blue.svg)]() <div align="center">
[![Kernel](https://img.shields.io/badge/Kernel-Rust%20%23!%5Bno__std%5D-orange.svg)]()
[![HAL](https://img.shields.io/badge/HAL%20%2F%20Drivers-C11%20Freestanding-green.svg)]()
[![Services](https://img.shields.io/badge/Services-C%2B%2B20%20RAII-purple.svg)]()
[![Bootloader](https://img.shields.io/badge/Boot-Limine%20v3-brightgreen.svg)]()
**opencoreC** is a modern, modular, capability-based microkernel operating system written in **Rust (`#![no_std]`)**, **Freestanding C**, and **Modern C++20**. It is designed around principles of strict hardware isolation, capability security, and zero-copy / fast-path inter-process communication (IPC). ```text
___ root@opencoreC
/ \ -----------------
| (o) | ___ OS: opencoreC Microkernel x86_64
| | / \ Kernel: v0.1.0-release (Rust #![no_std])
\ ___ / | (o) | Uptime: 42 mins, 12 secs
\___/ Shell: osh (opencore shell 1.0)
[=== opencoreC ===] Display: 1280x800 @ 60Hz 32bpp (Linear FB)
x86_64 SMP DE / WM: LVGL v8.3 Windows/KDE Compositor
Ring 3 Userspace CPU: QEMU Virtual CPU (4 Cores SMP)
Fast-Path IPC Cap Memory: 38 MiB / 509 MiB (7%)
Network: Realtek RTL8139 (10.0.2.15)
ACPI: S5 Poweroff, Reset, MADT 4 Cores
Security: Ring 3 Signal Fault Isolation (SIGSEGV)
Entropy: Hardware RNG (RDRAND / TSC)
```
[![Architecture](https://img.shields.io/badge/Architecture-x86__64%20(Long%20Mode)-007acc?style=for-the-badge&logo=cpu)]()
[![Kernel](https://img.shields.io/badge/Kernel-Rust%20%23!%5Bno__std%5D-dea584?style=for-the-badge&logo=rust)]()
[![User Space](https://img.shields.io/badge/User%20Space-C%2B%2B20%20%26%20C11-00599c?style=for-the-badge&logo=c%2B%2B)]()
[![GUI](https://img.shields.io/badge/GUI-LVGL%20v8.3%20Windows%2FKDE-4ba3e3?style=for-the-badge)]()
[![SMP](https://img.shields.io/badge/Multi--Core-SMP%204%20Cores-brightgreen?style=for-the-badge)]()
[![Network](https://img.shields.io/badge/Network-RTL8139%20PCI%20DMA-orange?style=for-the-badge)]()
[![Bootloader](https://img.shields.io/badge/Boot-Limine%20BIOS%20%2B%20UEFI-success?style=for-the-badge)]()
[![License](https://img.shields.io/badge/License-MIT%20%2F%20Apache--2.0-yellow?style=for-the-badge)]()
<p align="center">
<b>A state-of-the-art, capability-based microkernel operating system written in Rust and modern C++20.</b><br>
Designed from scratch for x86_64 long mode, featuring SMP multi-core affinity, an LVGL-powered desktop compositor, hardware ACPI power management, hardware random generation, and fault-tolerant process signal isolation.
</p>
</div>
---
## 🚀 Key Highlights & Subsystems
### ⚡ 1. SMP Multi-Core & Core Affinity Optimization
* **Application Processor Startup:** Secondary cores (Core 1, 2, 3) are booted via the Limine SMP protocol with dedicated TSS descriptors (`PER_CPU_TSS`), GDT, IDT, SSE/AVX registers, and fast-path syscall MSRs (`IA32_LSTAR`, `IA32_STAR`, `IA32_FMASK`).
* **Fast Non-Locking CPU ID:** Uses CPU MSR `0xC0000103` (`IA32_TSC_AUX`) to retrieve the current physical core index in a single assembly instruction (`rdmsr`).
* **Dedicated Core Affinity:**
- **Core 0:** Microkernel Core, Hardware Timer PIT (100 Hz), Hardware IRQs (Mouse, Keyboard, RTL8139 NIC).
- **Core 1:** Dedicated to **`gui_server`** — 60 FPS graphics rendering without lag or priority inversions.
- **Core 2:** Dedicated to **`sh`** (Interactive shell and command execution).
- **Core 3:** Dedicated to background servers (`init_server`, `uart_driver`, `procmgr`).
### 🪟 2. LVGL v8.3 Windows/KDE Desktop GUI
* **Hardware PS/2 Mouse Tracking:** Smooth double-buffered cursor rendering at 1280x800 resolution directly over Limine linear framebuffer (`0x80000000`).
* **Zero-Lag Window Dragging:** High-performance dirty-region raster bands (`BUF_HEIGHT = 80`) and optimized composition.
* **Windows 11 / KDE Plasma Aesthetic:**
- Glassmorphic Taskbar with Start Menu button, running task chips, and live CMOS digital clock.
- Interactive Start Menu with quick application launcher and system power controls.
- **Task Manager / Resource Monitor:** Real-time multi-core CPU utilization meters across all 4 cores and physical memory progress bar.
- **Linux-style Graphical Terminal:** Dark-mode terminal with blinking cursor and full command interpreter.
- **About System & Network Diagnostics Center:** Real-time RTL8139 MAC, IP, and packet counters.
### 🌐 3. Realtek RTL8139 PCI Fast Ethernet Network
* **PCI Bus Mastering:** Auto-probes PCI bus `0:2:0`, enables Bus Master DMA.
* **Zero-Copy Physical DMA:** Configured with physical transmit and receive ring buffers (`0x90000000`).
* **Network Stack:** Full ARP request/reply, IPv4 packet parsing, and ICMP Echo transmission (`ping 10.0.2.2`).
### 🛡️ 4. Process Signals & Fault Isolation (Ring 3)
* **Kernel Stability:** Ring 3 crashes no longer trigger Kernel Panics:
- Vector 14 (`#PF` Page Fault) $\rightarrow$ `SIGSEGV` (11)
- Vector 13 (`#GP` General Protection) $\rightarrow$ `SIGSEGV` (11)
- Vector 6 (`#UD` Invalid Opcode) $\rightarrow$ `SIGILL` (4)
- Vector 0 (`#DE` Divide by Zero) $\rightarrow$ `SIGFPE` (8)
* Faulting threads are cleanly isolated, logged with crash diagnostics (`RIP`, `ErrCode`, `CR2`), and terminated. The microkernel, GUI desktop, and sibling tasks remain fully active. Test with `crash_test`.
### 🔋 5. Hardware ACPI Subsystem
* **Table Discovery:** Scans BIOS memory (`0xE0000..0xFFFFF`) for `RSDP` with checksum verification.
* **Tables Parsed:** `RSDT`, `FADT` (`PM1a_CNT`), `MADT` (LAPIC CPU Core Discovery), `HPET`, `MCFG`.
* **Power Management:** Native hardware ACPI S5 Sleep/Poweroff and 8042/ACPI hardware reset.
### 🎲 6. Hardware Random Number Generator (RNG)
* **Entropy Sources:** Checks CPUID for hardware `RDRAND` (Leaf 1, ECX 30) and `RDSEED` (Leaf 7, EBX 18).
* **PRNG Fallback:** Xorshift64* stirred with CPU cycle counter (`rdtsc`) and CMOS RTC.
* **Syscall & Tool:** Syscall 22 (`SYS_GETRANDOM`) and user command `random` / `rng` generating UUID v4 identifiers.
### 💻 7. Interactive Terminal Shell (`osh`)
* **Stylized Powerline Prompt:** `┌──(root@opencoreC)-[~]\n└─# `
* **Built-in `fastfetch`:** Integrated system information tool with custom ASCII logo and ANSI palette.
* **Log Isolation:** Daemon logs (`gui_server`, `procmgr`, `init_server`) are routed to `dmesg`, leaving the interactive terminal pristine.
--- ---
## 🏛️ Architecture Overview ## 🏛️ Architecture Overview
The system follows a pure microkernel design paradigm where only the essential primitives reside in **Ring 0**, while device drivers, file systems, and system servers operate in isolated **Ring 3** user spaces.
```mermaid ```mermaid
graph TD graph TD
subgraph Ring 3 [User Space - Ring 3] subgraph Hardware [Physical & Virtual Hardware]
INIT["init_server (C++20 Root Server)"] CPU["x86_64 SMP (4 Cores)"]
PROCMGR["procmgr (Process & Server Manager)"] FB["Linear Framebuffer (1280x800@32bpp)"]
UART_DRV["uart_driver (16550 COM1 Driver)"] NIC["PCI Realtek RTL8139 Fast Ethernet"]
FS["VFS / Storage Server (Future)"] PS2["PS/2 Keyboard & Mouse"]
ACPI_HW["ACPI FADT / MADT / PM1a"]
RNG_HW["Hardware RNG (RDRAND/RDSEED)"]
end end
subgraph Ring 0 [Microkernel - Ring 0] subgraph Ring0 [Rust Microkernel - Ring 0]
IPC["Fast-Path IPC Dispatcher (Registers + SHM)"] SCHED["SMP Scheduler (Core Affinity & Quantum)"]
CAP["Capability Table & CNode Tracker"] VMM["4-Level Paging (PML4) & VMM"]
VMM["Virtual Memory Manager (PML4 4-Level Paging)"] PFA["Physical Frame Allocator (Bitmap)"]
PFA["Physical Frame Allocator (Bitmap Allocator)"] IPC["Fast-Path Rendezvous & Capability IPC"]
SCHED["Thread Scheduler & Context Switch (ASM)"] SIG["Signal Dispatcher (SIGSEGV/SIGILL/SIGFPE)"]
DMESG["Kernel Circular Log Ring Buffer"]
end end
INIT -- "Fast-Path IPC (Syscall)" --> IPC subgraph Ring3 [Isolated User Space - Ring 3]
PROCMGR -- "Fast-Path IPC (Syscall)" --> IPC GUI["gui_server (LVGL Desktop Compositor) [Core 1]"]
UART_DRV -- "Fast-Path IPC (Syscall)" --> IPC SH["sh (Interactive UNIX Terminal Shell) [Core 2]"]
IPC --> CAP INIT["init_server (System Root Server) [Core 3]"]
IPC --> SCHED UART["uart_driver (16550 Serial Driver) [Core 3]"]
PROC["procmgr (Process & Server Manager) [Core 3]"]
end
Hardware <--> Ring0
Ring0 <--> Ring3
``` ```
### 🔀 Language & Subsystem Distribution
| Component | Language | Privilege | Responsibilities |
| :--- | :--- | :--- | :--- |
| **Microkernel Core** | **Rust** (`#![no_std]`) | Ring 0 | PFA (Physical Memory), VMM (Paging), Capabilities, Fast IPC dispatcher, Scheduler. |
| **Low-Level Glue** | **x86_64 ASM** | Ring 0 / 3 | `_start`, `switch_to` context switch, `syscall_entry` / `sysretq`, IDT vectors. |
| **HAL & Hardware** | **C** (`-ffreestanding`) | Ring 3 / Ring 0 | Minimal bare-metal libc, 16550 UART COM driver, PCI bus scanning, APIC/IOAPIC. |
| **User Services** | **C++20** (`-nostdlib`) | Ring 3 | System servers, process management, RAII IPC endpoints (`ipc::Endpoint`, `ipc::SharedBuffer`). |
--- ---
## 📁 Repository Structure ## 📁 Repository Structure
```text ```text
opencoreC/ opencoreC/
├── Cargo.toml # Root Rust workspace manifest ├── boot/
├── rust-toolchain.toml # Fixed toolchain (x86_64-unknown-none) │ └── limine/ # Limine bootloader binaries & installer
├── Makefile # Unified root build system ├── build/ # Output directory for ELF binaries & disk image
├── CMakeLists.txt # Alternative CMake build for C/C++ components
├── limine.conf # Limine bootloader configuration
├── config/ ├── config/
│ ├── linker.ld # Higher-half kernel linker script (0xffffffff80000000) │ ├── linker.ld # Higher-half kernel linker script (0xffffffff80000000)
│ └── user.ld # Userspace ELF linker script (0x400000) │ └── user.ld # Userspace Ring 3 ELF linker script (0x400000)
├── hal/ # Hardware Abstraction Layer (PCI, 16550 UART)
├── include/ ├── include/
│ └── abi/ │ └── abi/
│ ├── types.h # ABI primitive types (cap_t, sysret_t, vaddr_t) │ ├── ipc.h # Fast-Path IPC register layout & protocols
│ ├── syscalls.h # Syscall numbers and inline assembly wrappers │ ├── syscalls.h # System call numbers, structures, and POSIX signals
│ └── ipc.h # Fast-Path IPC register layout and SHM headers │ └── types.h # ABI primitive types
├── kernel/ # Microkernel crate (Rust) ├── kernel/ # Microkernel crate (Rust #![no_std])
│ ├── Cargo.toml │ ├── Cargo.toml
│ ├── asm/ │ ├── asm/
│ │ ├── context.S # Cooperative/Preemptive context switcher │ │ ├── context.S # Preemptive context switcher (switch_to)
│ │ └── syscall_entry.S # x86_64 fast syscall trampoline │ │ └── syscall_entry.S # Fast syscall/sysretq entry trampoline
│ └── src/ │ └── src/
│ ├── main.rs # Kernel entry point & self-tests │ ├── main.rs # Kernel entry point & subsystem orchestrator
│ ├── limine_requests.rs # Limine protocol responses (HHDM, Memmap) │ ├── arch/ # GDT, TSS, IDT, SMP, ACPI, Syscalls
│ ├── arch/ # GDT, TSS, IDT, Syscall MSRs │ │ ├── acpi.rs # RSDP, RSDT, FADT, MADT parser & poweroff
│ │ ├── gdt.rs # Per-CPU GDT & TSS selectors
│ │ ├── idt.rs # IDT vectors & Ring 3 signal fault handler
│ │ ├── smp.rs # SMP multi-core AP boot & TSC_AUX per-CPU query
│ │ └── syscall.rs # Fast-path syscall dispatcher
│ ├── drivers/ # Microkernel drivers
│ │ ├── dmesg.rs # Circular kernel log ring buffer
│ │ ├── keyboard.rs # PS/2 keyboard driver
│ │ ├── mouse.rs # PS/2 mouse driver with screen clamping
│ │ ├── rng.rs # Hardware RNG (RDRAND / RDSEED / PRNG)
│ │ ├── serial.rs # 16550 UART serial logger
│ │ └── timer.rs # PIT 8254 timer (100 Hz preemptive ticks)
│ ├── ipc/ # Capability-based synchronous rendezvous IPC
│ ├── mm/ # Physical Frame Allocator & 4-Level Paging │ ├── mm/ # Physical Frame Allocator & 4-Level Paging
│ ├── ipc/ # Register-based Fast-Path IPC │ └── sched/ # Preemptive Multi-Core Scheduler & Threads
│ └── sched/ # Thread control blocks & scheduler
├── lib/ ├── lib/
│ ├── libc/ # Minimal freestanding C library │ ├── libc/ # Minimal freestanding C library (string, stdlib, stdio)
│ └── libipc_cpp/ # Modern C++ RAII IPC client library │ ├── libipc_cpp/ # C++20 RAII IPC endpoints & message wrappers
├── hal/ # Hardware Abstraction Layer (UART, PCI, APIC) │ └── lvgl/ # LVGL v8.3 embedded graphics library
└── servers/ # Ring 3 User-space servers (init, procmgr, uart_driver) ├── servers/ # Ring 3 User-space processes
│ ├── gui_server/ # Windows/KDE Desktop Compositor (LVGL v8.3)
│ ├── init_server/ # System root server
│ ├── procmgr/ # Process & server manager daemon
│ ├── sh/ # Interactive UNIX shell (Powerline prompt & fastfetch)
│ └── uart_driver/ # 16550 COM1 serial driver server
├── limine.conf # Limine bootloader configuration
├── Makefile # Unified build system
└── README.md # Documentation & project manual
``` ```
--- ---
## ⚡ Fast-Path IPC Specification ## 🛠️ Build & Run Guide
Short messages (up to 32 bytes of arguments) are passed directly through CPU registers without memory allocations or deep kernel stack copies: ### Prerequisites (Ubuntu/Debian)
```bash
sudo apt-get update
sudo apt-get install -y build-essential gcc g++ qemu-system-x86 nasm mtools xorriso
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add x86_64-unknown-none
```
* **`RAX`**: Syscall Number (`SYS_IPC_CALL = 1`, `SYS_IPC_REPLY_RECV = 2`, etc.) ### Quick Commands
* **`RDI`**: Target Capability Handle (`cap_t dest_cap`) | Target | Description |
* **`RSI`**: IPC Opcode / Interface Method ID | :--- | :--- |
* **`RDX`**: Argument 0 (`uint64_t`) | `make all` | Compiles the Rust microkernel, freestanding libc, drivers, and Ring 3 servers. |
* **`R8`** : Argument 1 (`uint64_t`) | `make image` | Builds a bootable 64 MiB hybrid FAT32 disk image (`build/opencoreC.img`) with Limine BIOS + UEFI. |
* **`R9`** : Argument 2 (`uint64_t`) | `make gui` | **Launches QEMU in GUI mode** with the LVGL Desktop Compositor, hardware mouse, and terminal. |
* **`R10`**: Argument 3 / SHM token (`uint64_t`) | `make run` | **Launches QEMU in serial console mode** with `fastfetch` and the Powerline shell prompt. |
* **Return Registers**: `RAX` (Status code), `RDX` (Result 0), `R8` (Result 1) | `make clean` | Cleans all compiled binaries, intermediate objects, and disk images. |
--- ---
## 🚀 Building & Running ## ⌨️ Shell Command Reference (`osh`)
### Prerequisites Available in both the **Serial Console (`make run`)** and the **GUI Terminal Window (`make gui`)**:
* `rustc` & `cargo` (with target `x86_64-unknown-none`) | Command | Description |
* `gcc` & `g++` (supporting C11 and C++20) | :--- | :--- |
* `qemu-system-x86_64` | `fastfetch` / `neofetch` | Displays the system summary, ASCII logo, and ANSI color palette. |
| `smp` / `cpu` | Displays online physical cores, current executing CPU, and per-core scheduler ticks. |
### Quick Start | `acpi` | Displays ACPI RSDP status, MADT discovered cores, and FADT power management ports. |
| `random` / `rng` | Generates 16 bytes of entropy via hardware RNG and formats as a UUID v4. |
1. **Build all components:** | `crash_test` | Triggers a Ring 3 null-pointer fault to verify kernel `SIGSEGV` signal handling. |
```bash | `ps` | Lists active threads, states (`READY`, `RUNNING`, `BLOCKED`), RIP, and CPU ticks. |
make all | `top` | Dynamic multi-core process and CPU load monitor. |
``` | `mem` / `free` | Displays Physical Frame Allocator (PFA) RAM usage (Total, Used, Free). |
| `ifconfig` / `ip` | Displays Realtek RTL8139 PCI Fast Ethernet MAC, IP, and status. |
2. **Run in QEMU with Serial Console Output:** | `ping <ip>` | Transmits real ICMP Echo Ping packets over RTL8139 PCI DMA. |
```bash | `dmesg` | Displays the circular kernel and background daemon log ring buffer. |
make run | `date` | Queries CMOS Real-Time Clock date and time. |
``` | `uptime` | Displays system uptime and PIT timer clock ticks. |
| `uname -a` | Prints operating system name, kernel version, and architecture. |
3. **Clean build artifacts:** | `whoami` | Prints the active user identity (`root`). |
```bash | `kill <tid>` | Sends a termination request to stop a specific thread by PID. |
make clean | `calc <expr>` | Freestanding arithmetic calculator (`+`, `-`, `*`). |
``` | `ls` / `dir` | Lists files in the in-memory RAM disk. |
| `cat <file>` | Reads and displays text file contents. |
--- | `touch <file>` | Creates a new file in RAM disk. |
| `clear` | Clears the terminal screen. |
## 🗺️ Roadmap | `reboot` | Reboots the machine via ACPI / 8042 reset. |
| `poweroff` / `exit` | Powers off the computer via hardware ACPI S5 shutdown. |
- [x] Higher-Half Limine bootloader protocol initialization (HHDM).
- [x] Physical Frame Allocator (PFA) via bitmap.
- [x] 4-Level Paging (VMM) with dynamic page table allocation.
- [x] Fast-Path register IPC infrastructure (`syscall`/`sysretq`).
- [x] Freestanding bare-metal libc and 16550 UART driver.
- [x] Modern C++ RAII IPC wrappers and initial userspace servers.
- [ ] **Phase 1:** ELF Loader, User Address Space isolation, and `iretq` jump to Ring 3.
- [ ] **Phase 2:** Synchronous IPC Rendezvous (blocking call / reply loop).
- [ ] **Phase 3:** Preemptive Multi-Tasking via LAPIC Timer interrupts.
- [ ] **Phase 4:** Userspace device driver model & interrupt forwarding.
--- ---
## 📜 License ## 📜 License
Distributed under the MIT / Apache-2.0 License. Distributed under the **MIT / Apache-2.0** dual license. See `LICENSE` for details.