updated readme, fix configuration shell invoked twice.
[lunaix-os.git] / README.md
index 310fd752e471f6c7c3b55219ebbcac4ba6b1279c..fe73edc437d3c2498af76fa60ec5cb438e0640f3 100644 (file)
--- a/README.md
+++ b/README.md
 
 # The Lunaix Project
 
-The Lunaix, LunaixOS, or Lunaix kernel to be exact, is a multi-architectural general purpose kernel written from scratch by the author *independently*. And it is the author's years-long personal endeavor and also a challenge to oneself for writing a functioning kernel **without** any external reference such as existing implementation, tutorial and books (with code) on kernel design. 
+The Lunaix kernel (or soon-to-be LunaixOS) is a hobby kernel, written entirely from scratch. Designed to be POSIX-compliance, performance critical and modern, with some independent thoughts being applied in architectural design.
 
-The overall design is aimed to be modern and POSIX-compliance. In a nutshell, Lunaix is:
 
-+ fully-preemptive
-+ modular design with configurable components at compile-time and extendable subsystems
-+ high-performance by utilising advanced caching techniques and infrastructure.
-+ fault-tolerance with sophisticated builtin error handling and tracing techniques.
-+ robust in nature with techniques such as proactive deadlock detection and driver isolation mechanism.
+This project is built entirely from first principles - meaning no code was copy-pasted or recycled from other OS projects or tutorials. Lunaix didn't begin as an attempt to outperform anything; it started as a personal challenge to learn OS theory and explore advanced kernel features through original design and implementation. Everything you see here was developed solo, part-time, with only hardware specs and my beloved **Modern Operating Systems** as guidance.
 
-To give a better understanding (and appreciation) of the works, the following list has been compiled with all feature that lunaix currently supported:
+If you're a kernel hobbyist looking for a fresh take or tired of mass-produced projects, then welcome, you're in the right place!
+
+
+| ![showcase_lunaix-over-serial.png](docs/img/showcase_lunaix-over-serial.png) |
+|:--:|
+| *Lunaix over serial* (`console=/dev/ttyS0`) |
+
+| ![showcase_lunaix-over-serial.png](docs/img/showcase_lunaix-over-vga-text.png) |
+|:--:|
+| *Lunaix over VGA text mode* (`console=/dev/ttyVCON0`) |
+
+> By the way, do you know there is an online video course  by the author on the design of lunaix? [Check it out](https://space.bilibili.com/12995787/channel/collectiondetail?sid=196337) (although it is in Chinese!)
+
+## Features
+
+Lunaix is a multi-architecture, general-purpose kernel built with performance, modularity, and robustness in mind. Its design emphasizes advanced abstractions, proactive error detection, and subsystem isolation. Lunaix is
+
++ **Fully-preemptive** for responsive multi-tasking
++ **Modular** with compile-time configurable components and extensible subsystems
++ **High-performance**, leveraging modern caching strategies and efficient infrastructures.
++ **Fault-tolerant**, with built-in error handling and stack backtracing
++ **Robust by design**, using mechanisms like proactive deadlock detection and driver isolation
+
+A significant amount of effort has gone into crafting clean abstractions, implementing advanced kernel features, and applying performance optimizations throughout the system.
+
+To better illustrate the scope of work already done, the following non-exhaustive list outlines currently supported features in Lunaix:
+
+<details>
+
+<summary>List of all features implemented</summary>
 
 + Multi-ISA
   + x86_32
   + x86_64
-  + Aarch64 (W.I.P)
-+ Boot protocol abstraction
+  + Aarch64 (WIP)
++ Boot protocol
+  + abstraction for different protocol
+  + configurable kernel boot-time parameters
 + Platform resource management and definition
-  + ACPI
-  + Devicetree
+  + read-only ACPI table interpretation
+  + full devicetree implementation
 + Memory management
-  + multi-architecture abstraction
+  + architecture-neutral abstraction
+  + highmem
+  + copy-on-write
+  + page sharing
+  + explicit huge page
   + on-demand paging
-  + copy-on-write and page sharing
-  + compound page support
-  + explicit huge page support (sorry, not THP!)
-  + reverse mapping indexing (rmap)
-  + memory compaction (W.I.P)
-  + slab-alike object allocator
-+ Multi-threadingg and multi-tasking
-  + Protection level and memory space isolation
-  + Native threading support (no more lightweight process nonsense)
-  + Signal handling
-  + Kernel-level multi-tasking (i.e. kernel threads)
-  + Round-robin scheduling (for now)
-  + Fully-preemptive kernel design
+  + compound page
+  + reverse mapping (rmap)
+  + memory compaction (WIP)
+  + slab-style object allocator
+  + inter-process address space access
++ Multi-tasking
+  + fully preemptive
+  + protection levels
+  + process isolation
+  + native threading
+  + signal mechanism
+  + round-robin scheduler (for now)
+  + kernel level multi-tasking (i.e. kernel threads)
   + taskfs: file system interface to process and threads
 + File system
+  + POSIX-compliant interface
   + virtual file system framework
-  + ...with POSIX compliant file system interface
-  + mountable file system
+  + file system mounting mechanism
   + page cache for file IO
-  + node cache for vfs structure representation.
+  + inode/dnode caching
   + ext2 (rev.0, rev.1)
   + iso9660 (rock-ridge)
-  + twifs: file system interface to kernel states.
+  + twifs: kernel state fs interface.
 + Device management and interrupt handling
-  + architectural decoupled design
-  + generalised driver framework
-  + generalised irq framework
-  + driver modularisation design
-  + support asynchronous device model
-  + devfs: file system interface to device subsystem
+  + unified IRQ framework
+  + unified driver framework for heterogenous devices
+  + modular driver model allow compiled-time toggling
+  + asynchronous operation model supported
+  + devfs: device fs interface.
 + Block I/O (blkio)
-  + generalised block IO interface and encapsulation
-  + blkio request caching
-  + asynchronous blkio operation in nature
+  + unified block IO interface
+  + IO request packets caching
+  + asynchronous IO operation
 + Serial I/O
-  + POSIX-compliant serial port model
-  + serial device driver framework (part of driver framework)
+  + POSIX-compliant serial IO model
 + Caching Infrastructure
-  + primtive: generic sparse associative array
   + LRU replacement policy and pooling
-  + kernel daemon for periodical cache eviction
+  + kernel daemon for dynamic and transparent cache managements
 + Error handling and detection
-  + stack back-tracing with symbol resolution
-  + nested exception unfolding
+  + stack backtracing with symbol resolution
+  + stack unwinding for nested exception
   + CPU state dumping
-  + Deadlock/hung-up detection
+  + deadlock/hung-up detection
+
+</details>
+
+<details>
 
-For the device driver that is currently support see below:
+<summary>List of currently supported device</summary>
 
-+ Arhcitecture Neutral
++ Architecture Neutral
   + UART 16650-compatible driver
   + Serial ATA AHCI
   + PCI 3.0
@@ -88,18 +119,17 @@ For the device driver that is currently support see below:
   + Standard VGA
 + Intel x86
   + RTC (Intel PCH)
-  + IOAPIC irq controller
+  + IOAPIC IRQ controller
   + APIC Timer
   + Legacy i8042 keyboard controller
 + ARM
   + GICv3
-  + PL011 (W.I.P)
-
-By the way, do you know there is an online video course  by the author on the design of lunaix? [Check it out](https://space.bilibili.com/12995787/channel/collectiondetail?sid=196337) (although it is in Chinese!) 
+  + PL011 (WIP)
+</details>
 
 ## Project Structure
 
-| | |
+| Path | Description |
 |-----|------|
 | [lunaix-os](../lunaix-os/) | LunaixOS source code |
 | [slides](../slides/) | Slides used in my videos |
@@ -107,16 +137,18 @@ By the way, do you know there is an online video course  by the author on the de
 
 ## Compile and Build
 
-You will need following dependencies in order to build Lunaix
+Building lunaix is simple, no more bloated dependencies to install, basic `build-essentials` installation plus a python are sufficient.
 
 + gcc (recommend v12+)
 + binutils
 + make
 + python (recommend v3.11+)
 
-And also one should have environment variable `ARCH=<arch>` exported, where `<arch>` is one of the supported arhcitecture (`x86_32`, `x86_64`, `arm64`)
+And also one should have environment variable `ARCH=<arch>` exported, where `<arch>` is one of the supported arhcitecture (`x86_32`, `x86_64`, `aarch64`).
+
+For cross compilation, also export `CX_PREFIX` to the gcc prefix for the corresponding `<arch>`.
 
-The following `make` actions are available to use.
+The following `make` actions are then available to use.
 
 | Make command | Usage |
 | ---- | ---- |
@@ -129,9 +161,102 @@ A successful build will give `build/bin/kernel.bin`.
 
 **Please note: this is the kernel, not a bootable image, it require a bootloader to boot and specify the rootfs.**
 
+## Get Started
+
+If you are impatient, or just want something to run and don't want to went through tedious process of configuring rootfs and tweak kernel parameters. You can use the `live_debug.sh` provided in the lunaix root directory to quickly bring up the system with default parameters (also used by the author for debugging).
+
+### Quick Start
+
+This will get you up and running real quick. We will use `x86_64` as example.
+
+Assuming a Linux or other Unix-like shell environment.
+
+#### Select your target
+```sh
+$ export ARCH=x86_64
+```
+
+#### Check Python
+```sh
+$ python --version
+```
+
+Ensure at least `3.11`
+
+#### Check compiler
+```sh
+$ gcc -dumpmachine
+```
+
+Ensure `x86_64-linux-gnu` or anything resemble `x86_64`
+
+#### Check QEMU
+```sh
+$ which qemu-system-x86_64
+```
+
+Should display a valid installation path
+
+#### Optional: Setting up Cross-Compiler
+```sh
+$ export CX_PREFIX=x86_64-linux-gnu-
+```
+
+#### Run Configuration
+```sh
+make config
+```
+
+Then hitting `q` in the interactive shell to save and quit
+
+#### Build stock rootfs
+
+```sh
+make rootfs
+```
+
+#### Build & Run
+```sh
+./live_debug.sh
+```
+
+you should see gdb now take control of your shell
+
+#### Connect to serial via telnet
+
+Open up another window or session
+```sh
+telnet localhost 12345
+```
+
+#### Commence simulation
+
+Back to the gdb session and type `c` to countine
+
+
+#### Watch Lunaix booting!
+
+Congrats, enjoy your lunaix! (or submit an issue)
+
+
+### Not so Quick Start
+
+Here is a slower and yet more verbose steps:
+
+1. Select an architecture `<arch>`
+2. Check the compilation prerequisites and presence of `qemu-system-<arch>`
+3. Optionally export `CX_PREFIX` if you are building for another architecture.
+4. Run `make ARCH=<arch> rootfs` to build stock rootfs image, require support of `dd`,`mkfs.ext2`, `mount -o loop`, `mktemp`.
+5. Run `ARCH=<arch> live_debug.sh` to boot in QEMU with gdb hooked (one should see a gdb session)
+6. telnet to `localhost:12345`, this is QEMU emulated serial port
+7. type `c` in the active gdb session and commence emulation.
+8. Congrats, enjoy your lunaix!
+(or submit an issue)
+
+
 ## Booting the kernel
 
-Since lunaix is a kernel, much like linux. It require additional setup to make the magic. And, as it is "much like linux", methods to make linux kernel boot can also apply to lunaix without or with little translation, as we will discuss below.
+Since lunaix is a kernel, much like linux. It requires additional setup to do the magic. And, as in "much like linux", methods to make linux kernel boot can also apply to lunaix without or with little translation, as we will discuss below.
 
 The bootloader part is generic, any bootloader, for example GRUB will work (not tested for UEFI, but I expect this would be an exception), or booting up in QEMU using `-kernel` option
 
@@ -146,22 +271,6 @@ Currently, lunaix support the following options
 | rootfs | `/dev/block/sda` | No | Specify the device contain rootfs image, path within lunaix's devfs |
 | init | `/init` | Yes | Path within rootfs of the `init` |
 
-### A quick 'Get Started'
-
-One can use the `live_debug.sh` provided in the lunaix root directory to quickly bring up the system with default parameter (which is used by the author for debugging).
-
-Following the steps:
-
-1. Select a architecture `<arch>`
-2. Check the compilation prerequisites and presence of `qemu-system-<arch>`
-3. Run `make ARCH=<arch> user` to build the stock user program
-4. Run `make ARCH=<arch> rootfs` to build stock rootfs image, require support of `dd`,`mkfs.ext2`, `mount -o loop`, `mktemp`.
-5. Run `ARCH=<arch> live_debug.sh` to boot in QEMU with gdb hooked (one should see a gdb session)
-6. telenet to `localhost:12345`, this is QEMU emulated serial port
-7. type `c` in the active gdb session and commence emualtion.
-8. Congrats, enjoy your lunaix!
-(or submit an issue)
-
 
 ## Submit an Issue
 
@@ -170,22 +279,26 @@ If one ran into bug, one can submit an issue by filling up the following templat
 ```
 1. Describe the problem
     "How does it look like, anything descriptive: visual, sonic, emotional experience"
+
 2. Steps to reproduce
     "How you ran into this mess?"
+
 3. Expected behaviour
     "What do you intended/expected to achieve/to be"
+
 4. Lunaix's panic trace (if applicable)
+
 5. Other clues that you think might be helpful
 ```
 
 
 ## Limitations
 
-The development process is still in motion, any limitation can be categorised as yet to be finished feature. However, some feature that the author considered to be the most urgent and wish the matters to be discussed.
+The development process is still in motion, any limitation can be categorised as a feature yet to be. However, some features that the author considered to be the most urgent and wish the matters to be discussed.
 
-Lunaix is under assumption of uniprocessor and not capable of running in SMP environment. This is major held back of being a modern operating system. It has the highest priority among all other tasks
+Lunaix is under impression of uniprocessor and not capable of running in SMP environment. This is major held back of being a modern operating system. It has the highest priority among all other tasks
 
-Lunaix is do not have a mature user space ecosystem, mainly because the lack of a proper and sophisticated libc. Efforts need to be done for porting one to the target. However, given the author's tight schedule, this task is unfortunately still beyond the horizon.
+Lunaix do not have a mature (or even, an infant) user space ecosystem, mainly because the lack of a proper and sophisticated libc. Efforts need to be done for porting one to the target. However, given the author's tight schedule, this task is unfortunately still beyond the horizon.
 
 ## Acknowledgement
 
@@ -193,11 +306,11 @@ Albeit one must realise that the author has mentioned it in the very beginning,
 
 As a personal challenge, this project is independently developed by the author single-handly, which means:
 
-+ No reference to existing tutorial, books, online course or any open source project that might provide example, hint or working prototype on the design and implementation of kernel, it's various subsystems or anythings that can be contributed towards a working prototype.
++ No reference to existing tutorials, books, online courses or any open source project that might provide any example, hint or working prototype on the design and implementation of kernel, subsystems or anythings that can be contributed towards a working prototype.
 + The author has no prior knowledge on Linux kernel through out 90% of the project time.
-+ All knowledge on the kernel design is comming from the basic textbook on operating system theory, that is, *Modern Operating System* by Tanenbaum.
-+ All knowledge on the system programming is commingg from the basic textbook, that is, *Computer System - A Programmer's Perspective Third Edition*
-+ All knowledge on the generic framework design and driver development are ingested from various technical specifications gathered across internet.
++ All knowledge on the kernel design is coming from the basic textbook on operating system theory, that is, *Modern Operating System* by Tanenbaum.
++ All knowledge on the system programming is coming from the basic textbook, that is, *Computer System - A Programmer's Perspective Third Edition*
++ All knowledge on the generic framework design and driver development are ingested from various technical specifications gathered across the Internet.
 
 ## References
 
@@ -258,22 +371,22 @@ As a personal challenge, this project is independently developed by the author s
 2. `mkdir(2)`
 2. `lseek(2)`
 2. `readdir(2)`
-2. `readlink(2)`
-2. `readlinkat(2)`
-2. `rmdir(2)`
-2. `unlink(2)`
-2. `unlinkat(2)`
-2. `link(2)`
-2. `fsync(2)`
+2. `readlink(2)`
+2. `readlinkat(2)`
+2. `rmdir(2)`
+2. `unlink(2)`
+2. `unlinkat(2)`
+2. `link(2)`
+2. `fsync(2)`
 2. `dup(2)`
 2. `dup2(2)`
-2. `symlink(2)`
+2. `symlink(2)`
 2. `chdir(2)`
 2. `fchdir(2)`
 2. `getcwd(2)`
 2. `rename(2)`※
 2. `mount(2)`
-2. `unmount` (a.k.a `umount(2)`)
+2. `unmount` (a.k.a `umount(2)`)
 2. `getxattr(2)`※
 2. `setxattr(2)`※
 2. `fgetxattr(2)`※
@@ -295,6 +408,20 @@ As a personal challenge, this project is independently developed by the author s
 4. `pthread_kill`
 4. `pthread_detach`
 4. `pthread_sigmask`
+4. `getuid`
+4. `getgid`
+4. `geteuid`
+4. `getegid`
+4. `getgroups`
+4. `setuid`
+4. `setgid`
+4. `seteuid`
+4. `setegid`
+4. `setgroups`
+4. `chroot`
+4. `fchmodat`
+4. `fchownat`
+4. `faccessat`
 
 **LunaixOS**
 
@@ -306,7 +433,7 @@ As a personal challenge, this project is independently developed by the author s
 
 ## Appendix 2: Debugging with GDB remotely via UART
 
-**(((( Not working yet, need rework ))))**
+**(((( Broken after a refactoring years ago, need rework ))))**
 
 The LunaixOS kernel comes with a built-in GDB debugging server, which runs on COM1@9600Bd. However, LunaixOS must be in debug mode before involving GDB.