X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/bffa3430fbbaaad29bec0b5bee9c1f0bfc7fd068..9e622bd093f8e106b7e8a00f55620f13cc5cd87f:/README.md
diff --git a/README.md b/README.md
index 2fce0e9..fe73edc 100644
--- a/README.md
+++ b/README.md
@@ -3,247 +3,323 @@
- ç®ä½ä¸æ | English
+ ç®ä½ä¸æ | English
-# The LunaixOS Project
+# The Lunaix Project
+
+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.
+
+
+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.
+
+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!
+
+
+|  |
+|:--:|
+| *Lunaix over serial* (`console=/dev/ttyS0`) |
+
+|  |
+|:--:|
+| *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:
+
+
+
+List of all features implemented
+
++ Multi-ISA
+ + x86_32
+ + x86_64
+ + Aarch64 (WIP)
++ Boot protocol
+ + abstraction for different protocol
+ + configurable kernel boot-time parameters
++ Platform resource management and definition
+ + read-only ACPI table interpretation
+ + full devicetree implementation
++ Memory management
+ + architecture-neutral abstraction
+ + highmem
+ + copy-on-write
+ + page sharing
+ + explicit huge page
+ + on-demand paging
+ + 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
+ + file system mounting mechanism
+ + page cache for file IO
+ + inode/dnode caching
+ + ext2 (rev.0, rev.1)
+ + iso9660 (rock-ridge)
+ + twifs: kernel state fs interface.
++ Device management and interrupt handling
+ + 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)
+ + unified block IO interface
+ + IO request packets caching
+ + asynchronous IO operation
++ Serial I/O
+ + POSIX-compliant serial IO model
++ Caching Infrastructure
+ + LRU replacement policy and pooling
+ + kernel daemon for dynamic and transparent cache managements
++ Error handling and detection
+ + stack backtracing with symbol resolution
+ + stack unwinding for nested exception
+ + CPU state dumping
+ + deadlock/hung-up detection
+
+
+
+
+
+List of currently supported device
+
++ Architecture Neutral
+ + UART 16650-compatible driver
+ + Serial ATA AHCI
+ + PCI 3.0
+ + PCIe 1.1
+ + Standard VGA
++ Intel x86
+ + RTC (Intel PCH)
+ + IOAPIC IRQ controller
+ + APIC Timer
+ + Legacy i8042 keyboard controller
++ ARM
+ + GICv3
+ + PL011 (WIP)
+
+
+## Project Structure
+
+| Path | Description |
+|-----|------|
+| [lunaix-os](../lunaix-os/) | LunaixOS source code |
+| [slides](../slides/) | Slides used in my videos |
+| [reference-material](../reference-material/)| References |
+
+## Compile and Build
+
+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+)
-LunaixOS - ä¸ä¸ªç®åçï¼è¯¦ç»çï¼POSIXå
¼å®¹çï¼ä½æ¿ï¼ï¼ï¼å¸¦ææµéä¸ªäººé£æ ¼çæä½ç³»ç»ï¼ç± Lunaix å
æ ¸é©±å¨ãå¼åè¿ç¨ä»¥è§é¢æç¨å½¢å¼å¨Bilibiliåç°ï¼[ãä»é¶å¼å§èªå¶æä½ç³»ç»ç³»åã](https://space.bilibili.com/12995787/channel/collectiondetail?sid=196337)ã
+And also one should have environment variable `ARCH=` exported, where `` is one of the supported arhcitecture (`x86_32`, `x86_64`, `aarch64`).
-## 1. ä¸äºå®ç¨èµæº
+For cross compilation, also export `CX_PREFIX` to the gcc prefix for the corresponding ``.
-妿ææç 读 Lunaix å
æ ¸ä»£ç åå
¶ä¸çè®¾è®¡ï¼ææ¬²å¼å§å±äºèªå·±çOSå¼åä¹éï¼ä»¥ä¸èµæå¯è½ä¼å¯¹æ¤æç¨ã
+The following `make` actions are then available to use.
-+ [å
æ ¸ææ¡£ï¼Luna's Tourï¼](docs/lunaix-internal.md)
-+ [LunaixOSæºä»£ç åææç¨](docs/tutorial/0-æç¨ä»ç»åç¯å¢æå»º.md)
-+ [ä½è
ä¿®æ¹çQEMU](https://github.com/Minep/qemu) (æ·»å äºä¸äºé¢å¤ç¨äºè°è¯çåè½)
+| Make command | Usage |
+| ---- | ---- |
+| `make all` | Build the kernel bin |
+| `make rootfs` | Build the stock rootfs |
+| `make clean` | clean |
+| `make config` | menuconfig |
-## 2. å½åè¿åº¦ä»¥åæ¯æçåè½
+A successful build will give `build/bin/kernel.bin`.
-Lunaixå
æ ¸å
·ææ¯æå¤ç§ä¸åçæä»¤éæ¶æçè½åï¼ç®åæ¯æå¦ä¸ï¼
+**Please note: this is the kernel, not a bootable image, it require a bootloader to boot and specify the rootfs.**
-+ x86_32
-+ x86_64
+## Get Started
-Lunaixå
¨é¨ç¹æ§ä¸è§ï¼
+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).
-+ 使ç¨Multibootè¿è¡å¼å¯¼å¯å¨
- + Multiboot 1
- + Multiboot 2 (WIP)
-+ APIC/IOAPICä½ä¸ºä¸æç®¡çå¨å计æ¶å¨
-+ ACPI
-+ èæå
å
- + æ¶æä¸æ§è®¾è®¡
- + æéå页
- + Copy-on-Write
-+ å
å管ç
-+ è¿ç¨æ¨¡å
-+ 61个常è§çLinux/POSIXç³»ç»è°ç¨ï¼[éå½1](#appendix1)ï¼
-+ ç¨æ·/å
æ ¸æé离
-+ ä¿¡å·æºå¶
-+ PCI 3.0
-+ PCIe 1.1 (WIP)
-+ å设å¤IOä¸é©±å¨
- + åIOéç¨ç¼åæ±
- + Serial ATA AHCI
- + ATA设å¤
- + ATAPIå°è£
çSCSIåè®®
-+ æä»¶ç³»ç»ï¼POSIX.1-2008, section 5 & 10ï¼
- + èææä»¶ç³»ç»
- + å
æ ¸ææä»¶ç³»ç»ï¼twifs, Lunaixèªå·±çsysfsï¼
- + è®¾å¤æä»¶ç³»ç»ï¼devfs, Lunaixèªå·±çudevï¼
- + è¿ç¨æä»¶ç³»ç»ï¼procfsï¼
- + ISO9660
- + ECMA-119
- + IEEE P1282ï¼Rock Ridgeæå±ï¼
- + ext2
- + Revision 0
- + Revision 1 ï¼é¢å¤ç¹æ§ä¸æ¯æï¼
-+ è¿ç¨GDB串å£è°è¯ (COM1@9600Bd)
-+ ç¨æ·ç¨åºå è½½ä¸æ§è¡
-+ éç¨è®¾å¤æ½è±¡å±
- + æ¶æä¸æ§çè®¾å¤æ¯æä½äºï¼`lunaix-os/hal`
- + 16550 UART
- + ACPI ï¼ä¸å®å
¨å®ç°ï¼
- + æ¶æè¦åçè®¾å¤æ¯æä½äºï¼`lunaix-os/arch//hal`
- + x86
- + APIC/IOAPIC ç»å
- + MC146818 RTC
- + i8042 PS/2
- + RNGï¼ä½¿ç¨`rdrand`ï¼
- + [Devicetree](https://www.devicetree.org/)
-+ éç¨å¾å½¢è®¾å¤æ½è±¡å± (Draft)
- + åèï¼`lunaix-os/hal/gfxa`
-+ èæç»ç«¯è®¾å¤æ¥å£ï¼POSIX.1-2008, section 11ï¼
- + åèï¼`lunaix-os/hal/term`
-+ çº¿ç¨æ¨¡å
- + ç¨æ·çº¿ç¨æ¯æï¼pthreadç³»åï¼
- + å
æ ¸çº¿ç¨æ¯æ
-+ æ¢å å¼å
æ ¸è®¾è®¡
- + å
æ ¸æä¸ä¸æåæ¢
- + å
æ ¸æå¼å¸¸æèµ·/æ»éèªå¨æ£æµæºå¶
-
-## 3. ç®å½ç»æ
-
-| | |
-| ----------------------------------------- | ---------------------------- |
-| [lunaix-os](lunaix-os/) | LunaixOSæºä»£ç |
-| [slides](slides/) | è§é¢ä¸æç¨çå¹»ç¯çåè¡¥å
ææ |
-| [reference-material](reference-material/) | æ åï¼ææ¯ææ¡£ååèæç® |
-
-## 4. ç¼è¯ä¸æå»º
-
-**ï¼å¦ææ³è¦ç«å»æå»ºå¹¶è¿è¡ï¼è¯·åè4.7ï¼**
-
-æå»ºè¯¥é¡¹ç®éè¦æ»¡è¶³ä»¥ä¸æ¡ä»¶ï¼
-
-+ gcc å·¥å
·é¾
-+ make
-+ xorriso
-+ grub-mkrescue
+### Quick Start
-### 4.1 ä½¿ç¨ GNU CC å·¥å
·é¾
+This will get you up and running real quick. We will use `x86_64` as example.
-æ£å¦å大夿°å
æ ¸ä¸æ ·ï¼Lunaix æ¯ä¸ä¸ªæ··åäº C åæ±ç¼ç产ç©ãè¿å°±æå³çä½ å¾è¦ä½¿ç¨ä¸äºæ åçCç¼è¯å¨æ¥æå»ºLunaixãå¨è¿éï¼ææ¨èä½¿ç¨ GNU CC å·¥å
·é¾æ¥è¿è¡æå»ºãå 为Lunaix å¨ç¼åæ¶ä½¿ç¨äºå¤§éçGNU CC ç¸å
³ç¼è¯å¨å±æ§ä¿®é¥° (`__attribute__`) ãåè¥ä½¿ç¨å
¶ä»å·¥å
·é¾ï¼å¦LLVMï¼æå¯¹æ¤å°±ä¸è½ååºä»»ä½ä¿è¯äºã
+Assuming a Linux or other Unix-like shell environment.
-å¦æä½ ä½¿ç¨çæ¯åºäº x86 æä»¤éçLinuxç³»ç»ï¼ä¸è®ºæ¯64ä½è¿æ¯32ä½ï¼**å
¶æ¬æºèªå¸¦çgcc就足以ç¼è¯Lunaix**ã å½ç¶äºï¼å¦æè¯´ä½ ç平尿¯å
¶ä»éx86çï¼ä½ ä¹å¯ä»¥æå®ä½¿ç¨æä¸ªé对x86_32çgccå¥ä»¶æ¥è¿è¡äº¤åç¼è¯ââå¨`make`æ¶éè¿`CX_PREFIX`å鿥æå®gccå¥ä»¶çåç¼ãå¦ä¸ä¾æç¤ºï¼æä»¬å¯ä»¥å¨ä»»æå¹³å°ä¸ï¼å¦risc-vï¼åç¬ä½¿ç¨ä¸ä¸ªé¢åx86_32çgccæ¥è¿è¡äº¤åç¼è¯ï¼
-
-```
-make CX_PREFIX=i686-linux-gnu- all
+#### Select your target
+```sh
+$ export ARCH=x86_64
```
-### 4.2 Dockeréå
-
-对äºå¼åç¯å¢ï¼æ¬é¡¹ç®ä¹æä¾äºDockeréåå°è£
ãå¼ç®±å³ç¨ï¼æ éé
ç½®ï¼é常éåæäººæææ¶è
ã详ç»ä½¿ç¨æ¹æ³è¯·è½¬å°ï¼[Lunaix OSDK项ç®](https://github.com/Minep/os-devkit)ã
-
-### 4.3 æå»ºé项
+#### Check Python
+```sh
+$ python --version
+```
-æ¬é¡¹ç®æ¯æçmakeå½ä»¤ï¼
-| å½ä»¤ | ç¨é |
-| ------------------------ | ----------------------------------------------- |
-| `make all` | æå»ºå
æ ¸ELFéå |
-| `make rootfs` | æå»ºæ ¹æä»¶ç³»ç»éåï¼å°ä¼å°è£
`usr/`ä¸çç¨åº |
-| `make clean` | å é¤æå»ºç¼åï¼ç¨äºéæ°æå»º |
-| `make config` | é
ç½®Lunaix |
+Ensure at least `3.11`
-ä¸makeå½ä»¤é
å¥çç¯å¢åéï¼Lunaixçmakefileä¼èªå¨æ£æµè¿äºç¯å¢åéï¼ä»¥æ´æ¹æå»ºè¡ä¸º
+#### Check compiler
+```sh
+$ gcc -dumpmachine
+```
-+ `MODE={debug|release}` 使ç¨debugæ¨¡å¼æå»ºï¼-Ogï¼æè
release模å¼ï¼-O2ï¼
-+ `ARCH=` 为æå®çæä»¤éæ¶æç¼è¯Lunaixã æä½¿ç¨çé
ç½®é项å为é宿¶æé»è®¤ï¼è¯¥ç¯å¢åé
- åå¨çç®çå°±æ¯æ¹ä¾¿ç¨æ·è¿è¡å¿«éç¼è¯ï¼èæ éé»ç Lunaixçç§ç§é
置项ã
+Ensure `x86_64-linux-gnu` or anything resemble `x86_64`
-### 4.4 Lunaixçåè½é
ç½®
+#### Check QEMU
+```sh
+$ which qemu-system-x86_64
+```
-Lunaixæ¯ä¸ä¸ªå¯é
ç½®çå
æ ¸ï¼å
è®¸ç¨æ·å¨ç¼è¯åéæ©åºå½å
å«æç§»é¤çåè½ã
+Should display a valid installation path
-使ç¨`make config`æ¥è¿è¡åºäºå½ä»¤è¡ç交äºé
ç½®ãéç¨TUIåç°ï¼ææç±»ä¼¼äºmenuconfig.
+#### Optional: Setting up Cross-Compiler
+```sh
+$ export CX_PREFIX=x86_64-linux-gnu-
+```
-妿å 为æç§åå ï¼TUIç颿 æ³åç°ï¼é£ä¹å°ä¼é»è®¤ä½¿ç¨shellå½¢å¼çåç°ï¼
+#### Run Configuration
+```sh
+make config
+```
-ææçé
置项æç
§ç±»ä¼¼äºæä»¶æ çå½¢å¼ç»ç»ï¼å¦å个é
置项为ä¸ä¸ªâæä»¶âï¼å¤ä¸ªé
ç½®é¡¹ç»æçé
ç½®ç»ä¸ºä¸ä¸ªç®å½ï¼åç°å½¢å¼ä¸ºæ¹æ¬å·`[]`å
裹起æ¥ç项ç®ãå¨æç¤ºç¬¦ä¸è¾å
¥`usage`å¹¶å车å¯ä»¥æ¥çå
·ä½çä½¿ç¨æ¹æ³ã
+Then hitting `q` in the interactive shell to save and quit
-ä¸ä¸ªæå¸¸ç¨çé
ç½®å¯è½å°±æ¯`architecture_support/arch`äºï¼ä¹å°±æ¯é
ç½®Lunaixæé¢åçæä»¤éãæ¯å¦ï¼ç¼è¯ä¸ä¸ªå¨x86_64å¹³å°ä¸è¿è¡çLunaixï¼å¨æç¤ºç¬¦ä¸è¾å
¥ï¼**注æçå·ä¸¤ä¾§çç©ºæ ¼ï¼è¿æ¯ä¸è½çç¥ç**ï¼ï¼
+#### Build stock rootfs
-```
-/architecture_support/arch = x86_64
+```sh
+make rootfs
```
-ä¹åè¾å
¥`exit`ä¿åå¹¶éåºãè忣叏ç¼è¯ã
-
-### 4.5 设置å
æ ¸åæ°
-
-å¨ make çæ¶åéè¿`CMDLINE`åéå¯ä»¥è®¾ç½®å
æ ¸å¯å¨åæ°å表ã该å表å¯ä»¥å
å«å¤ä¸ªåæ°ï¼éè¿ä¸ä¸ªæå¤ä¸ªç©ºæ ¼æ¥åå²ãæ¯ä¸ªåæ°å¯ä»¥ä¸ºé®å¼å¯¹ `=` æè
æ¯å¼å
³æ å¿ä½ ``ãç®å Lunaix æ¯æä»¥ä¸åæ°ï¼
+#### Build & Run
+```sh
+./live_debug.sh
+```
-+ `console=` 设置系ç»ç»ç«¯çè¾å
¥è¾åºè®¾å¤ï¼tty设å¤ï¼ãå
¶ä¸ `` æ¯è®¾å¤æä»¶è·¯å¾ ï¼æ³¨æï¼è¿éçè®¾å¤æä»¶è·¯å¾æ¯é对Lunaixï¼èéLinuxï¼ãå
³äºLunaixOSè®¾å¤æä»¶ç³»ç»çä»ç»å¯åè Lunaix Wikiï¼WIPï¼
-+ ï¼åè 4.6ï¼
+you should see gdb now take control of your shell
-妿`CMDLINE`æªæå®ï¼åå°ä¼è½½å
¥é»è®¤åæ°ï¼
+#### Connect to serial via telnet
-```
-console=/dev/ttyFB0
+Open up another window or session
+```sh
+telnet localhost 12345
```
-å
¶ä¸ï¼`/dev/ttyFB0` æååºäºVGAææ¬æ¨¡å¼çtty设å¤ï¼ä¹å°±æ¯å¹³æ¶å¯å¨QEMUæ¶çå°çé»è²çªå£ã
+#### Commence simulation
-å½ç¶ï¼è¯»è
ä¹å¯ä»¥ä½¿ç¨ `/dev/ttyS0` æ¥ä½ä¸ºé»è®¤tty设å¤ï¼æ¥éªè¯ Lunaix ççµæ´»æ§ä¸å
¼å®¹æ§ãè¯¥è·¯å¾æå第ä¸ä¸ªä¸²å£è®¾å¤ãå¯ä»¥éè¿telnetåè®®å¨`12345`端å£ä¸è¿è¡è®¿é®ââ端å£å·å¯ä»¥èªè¡ä¿®æ¹QEMUå¯å¨åæ°ï¼ä½äºï¼`makeinc/qemu.mkinc`ï¼æ¥åæ´ã
+Back to the gdb session and type `c` to countine
-**注æï¼** æ ¹æ®æä½ç³»ç»åé®çå¸å±çä¸åï¼telnet客æ·ç«¯å¯¹ä¸äºå
³é®é®ä½çæ å°ï¼å¦éæ ¼ï¼å车ï¼å¯è½ææå·®å«ï¼å¦æäºçæ¬çLinuxä¼å°éæ ¼é®æ å°ä¸º`0x7f`ï¼ä¹å°±æ¯ASCIIç``å符ï¼èéæä»¬çç¥`0x08`ï¼ãå¦æè¯»è
æ³è¦éè¿ä¸²å£æ¹å¼æç©Lunaixï¼è¯·ä¿®æ¹`usr/init/init.c`éé¢çç»ç«¯åå§å代ç ï¼å°`VERASE`设置为æ£ç¡®çæ å°ï¼ä¿®æ¹æ¹å¼å¯ä»¥åè POSIX termios çä½¿ç¨æ¹å¼ãç±äºLunaixçç»ç«¯æ¥å£çå®ç°æ¯å®å
¨å
¼å®¹POSIXçï¼è¯»è
å¯ä»¥ç´æ¥å»æ¥é
Linuxèªå¸¦ç帮å©`man termios`ï¼æ éä½ä»»ä½ç转æ¢ï¼
+#### Watch Lunaix booting!
-### 4.6 Lunaixçå¯å¨
+Congrats, enjoy your lunaix! (or submit an issue)
-ç±äº Lunaix çå®ä½æ¯å
æ ¸ã为äºé¿å
太å¤çç¼è¯æ¶çåç½®è¦æ±ï¼åæ¶ä¸ºäºæé«çµæ´»æ§ï¼æä»¬ç§»é¤äºisoæä»¶çå°è£
åè½ãç®åç Lunaix å°åªä¼ç¼è¯åºä¸ä¸ª ELF æ ¼å¼çäºè¿å¶æä»¶ãç¨æ·å¯ä»¥æ ¹æ®èªå·±çå好ï¼ä½¿ç¨çä¸åçæ¹å¼ï¼ä¸åç bootloader æ¥å¼å¯¼ Lunaix.
-为äºè½å¤ä½¿å¾ Lunaix è½å¤æ£ç¡®çå¯å¨ï¼ç¨æ·å¿
须设置以ä¸å
æ ¸åæ°ï¼
+### Not so Quick Start
-+ `rootfs=` æææ ¹ç®å½è®¾å¤ï¼å¼ä¸ºè®¾å¤æä»¶è·¯å¾ï¼æåå
嫿 ¹æä»¶ç³»ç»çç£ç设å¤ï¼å¦`/dev/block/sda`ã Lunaixå°ä¼å¨å¯å¨ä¹åèªå¨æå¨è¯¥æä»¶ç³»ç»å°æ ¹ç®å½ãç¼ºå°æ¤é项 Lunaix å°ä¼æç»å¯å¨ï¼å¹¶è¿å
¥ kernel panic ï¼å¨ Lunaix çä¸çéï¼è¿ä¸ªè¢«ç§°ä¹ä¸º Nightmare Moon arrival ï¼
-+ `init=` ææ init ç¨åºçä½ç½®ï¼è¯¥ç¨åºå¿
é¡»æ¾å¨ `rootfs` ä¸ãæ¹é项为å¯é设置ï¼å
¶é»è®¤å¼ä¸º `/init`ã init ç¨åºæ¯ Lunaix å¨å¯å¨åæè¿è¡ç第ä¸ä¸ªç¨åºã
+Here is a slower and yet more verbose steps:
-### 4.7 æµè¯ä¸ä½éª Lunaix
+1. Select an architecture ``
+2. Check the compilation prerequisites and presence of `qemu-system-`
+3. Optionally export `CX_PREFIX` if you are building for another architecture.
+4. Run `make ARCH= rootfs` to build stock rootfs image, require support of `dd`ï¼`mkfs.ext2`, `mount -o loop`, `mktemp`.
+5. Run `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
-1. å³å®ä¸ä¸ªä½ æ³è¦ä½éªçæ¶æï¼å¦ `x86_64`ã ï¼æ¯æï¼`x86_64`, `i386`ï¼ä¸ºäºåè¿°æ¹ä¾¿ï¼è¿ä¸ªæ¶æå¨ä¸æè¢«æä»£ä¸º``
-2. æ£æ¥ä½ æ¯å¦å®è£
äºï¼ `qemu-system-`ï¼`gdb`ï¼`python3`ï¼`telnet`ï¼`gcc`
-3. è¿è¡ `make ARCH= user` æ¥ç¼è¯èªå¸¦çç¨æ·ç¨åº
-4. è¿è¡ `make ARCH= rootfs` æ¥æå
æ ¹æä»¶ç³»ç»éåãï¼éè¦æ¬æºç³»ç»æ¯æ `dd`ï¼`mkfs.ext2`, `mount -o loop`, `mktemp`ï¼
-5. è¿è¡ `ARCH= live_debug.sh` æ¥å¯å¨
+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.
-è¯¥èæ¬èªå¨æç
§é»è®¤çé项æå»ºLunaixï¼èåè°ç¨ `scripts/qemu.py` æ ¹æ®é
ç½®æä»¶çæQEMUå¯å¨åæ°ï¼é
ç½®æä»¶ä½äº`scripts/qemus/`ï¼
+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
-ç±äºè¯¥èæ¬ç主è¦ç¨éæ¯æ¹ä¾¿ä½è
è¿è¡è°è¯ï¼æä»¥å¨QEMUçªå£æå¼åè¿éè¦è¿è¡ä»¥ä¸å¨ä½ï¼
+The kernel command line, is however, a bit differentiated.
+The syntax is similar, both takes form of space-separated array of `=` pairs or boolean ``.
-1. 使ç¨telnetè¿æ¥å°`localhost:12345`ï¼è¿éæ¯Lunaixè¿è¡æ åè¾å
¥è¾åºæä½¿ç¨çUARTæ å°ï¼QEMU为guestæä¾UARTå®ç°ï¼å¹¶å°å
¶å©ç¨telnetåè®®éå®åå°å®¿ä¸»æºï¼
-2. å¨GDBçªå£ä¸è¾å
¥`c`ç¶ååè½¦ï¼æ¤æ¶Lunaixå¼å§è¿è¡ãè¿æ ·åçç®çæ¯å
许å¨QEMUè¿è¡æ¨¡æåï¼äºå
æå¥½æå
´è¶£çæç¹ã
+Currently, lunaix support the following options
-## 5. è¿è¡ï¼åæ¯ä»¥å Issue
+| Option | Default Value | Optional | Usage |
+| ------ | ---- | ----- | ---- |
+| console | `/dev/ttyS0` | No | Specify the system console device, path within lunaix's devfs |
+| 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` |
-### 5.1 代ç ç¨³å®æ§
-䏻忝ä¸è¬æ¯ç¨³å®çãå 为å¨å¤§å¤æ°æ
åµä¸ï¼æé½ä¼å°½éä¿è¯æ¬æºè¿è¡æ 误åï¼pushå°è¯¥åæ¯ä¸ãæææ£å¨å¼åçåè½è¯·åèå½åæ´»è·çPull Requestã
+## Submit an Issue
-妿䏻忝çè¿è¡åºç°äºæ¤é®é¢ï¼æ¬¢è¿æissueã请åè[éå½3ï¼Issueçæäº¤](#appendix3)
+If one ran into bug, one can submit an issue by filling up the following template
-## 6. è°è¯ Lunaix å
æ ¸
+```
+1. Describe the problem
+ "How does it look like, anything descriptive: visual, sonic, emotional experience"
-é¤äº[éå½4ï¼ä¸²å£GDBè¿ç¨è°è¯](#appendix4)æè¿°çä¸ç§ç¨äºå®æºè°è¯çæ¹å¼ä»¥å¤ãLunaixOSè¿æä¾äºLunaDBGè°è¯å¥ä»¶ãè¿æ¯ä¸ä¸ªGDB客æ·ç«¯æä»¶ï¼å
å«äºå¯¹GDBåçå½ä»¤éçä¸äºæ©å
ï¼ä¸»è¦ç¨äºæ¹åä¸ç®åå
æ ¸è°è¯çè¿ç¨ãç®åå
å«ä»¥ä¸å 个å½ä»¤ï¼
+2. Steps to reproduce
+ "How you ran into this mess?"
-+ `vmrs [pid]` å举è¿ç¨``çå
ååºåå¾ï¼Memory Regionsï¼ï¼å¦æ``æªæå®ï¼åé»è®¤ä¸ºæ£å¨è¿è¡çè¿ç¨ï¼smp=1ï¼ã
-+ `proc [pid]` æå°è¿ç¨``çè¿ç¨æ§å¶åç¶æï¼å¦æ``æªæå®ï¼åé»è®¤ä¸ºæ£å¨è¿è¡çè¿ç¨ï¼smp=1ï¼ã
-+ `sched [-l]` æ¥çè°åº¦å¨ä¿¡æ¯ï¼æ¥åä¸¤ä¸ªåæ°ï¼
- + `threads` æå°ææä¾ç¶å¨è°åº¦å¨ä¸ææ³¨åç线ç¨
- + `procs` æå°ææä¾ç¶å¨è°åº¦å¨ä¸ææ³¨åçè¿ç¨
- + å¯éå¼å
³ `-l` å³å®æ¯å¦ä»¥é¿å表æå°ï¼æ´è¯¦ç»çä¿¡æ¯ï¼
+3. Expected behaviour
+ "What do you intended/expected to achieve/to be"
-该æä»¶å¯ä»¥éè¿è¿è¡ä»¥ä¸å½ä»¤æ¥è¿è¡å®è£
ï¼
+4. Lunaix's panic trace (if applicable)
-```shell
-./scripts/gdb/install_lunadbg
+5. Other clues that you think might be helpful
```
-## 7. åèæç¨
-#### 没æï¼ï¼
+## Limitations
+
+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 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 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.
-+ **没æ** åèä»»ä½ç°è¡çï¼å
³äºæä½ç³»ç»å¼åçï¼æç¨æä¹¦ç±ã
-+ **没æ** åèä»»ä½å¼æºå
æ ¸çæºä»£ç ï¼å
æ¬Linuxï¼
-+ **没æ** åºäºä»»ä½å¼æºå
æ ¸çäºæ¬¡å¼åè¡ä¸ºã
+## Acknowledgement
-为äºå¶ä½LunaixOSï¼ä½è
èè´¹å¤§éæ¶é´åç²¾åé»ç ææ¯ææ¡£ï¼æåï¼ç论书ç±ä»¥åç°è¡å·¥ä¸æ åï¼ä»èå°½éä¿è¯äºç¥è¯ç䏿æ§ãï¼è¿æ ·ä¸æ¥ï¼è¯»è
åå¬ä¼ä»¬ä¹ç®æ¯æ¿å°äºäºæçç¥è¯ï¼è䏿¯ä¸æï¼åæï¼çè³næçç¥è¯ï¼ã
+Albeit one must realise that the author has mentioned it in the very beginning, the author would like to emphaise **again** on the nature of this project.
-大é¨åçææ¡£åæ åå¯ä»¥å¨ä¸è¿°ç[reference-material](reference-material/)䏿¾å°ã
+As a personal challenge, this project is independently developed by the author single-handly, which means:
-å½ç¶ï¼æ¨ä¹å¯ä»¥åè以ä¸å表æ¥äºè§£ç°é¶æ®µçLunaixOSé½ä½¿ç¨äºåªäºèµæï¼æ¬å表ä¼éçå¼åè¿åº¦æ´æ°ï¼ï¼
++ 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 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
-+ [Intel 64 and IA-32 Architecture Software Developer's Manual (Full Volume Bundle)](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html)
-+ [ACPI Specification (version 6.4)](https://uefi.org/sites/default/files/resources/ACPI_Spec_6_4_Jan22.pdf)
++ Intel 64 and IA-32 Architecture Software Developer's Manual (Full Volume Bundle)
++ ACPI Specification (version 6.4)
++ Devicetree Specification
++ ARM® Generic Interrupt Controller (v3)
++ Arm® Architecture Reference Manual (Profile-A)
++ Procedure Call Standard for the Arm® 64-bit Architecture (AArch64)
+ IBM PC/AT Technical Reference
+ IBM VGA/XGA Technical Reference
+ 82093AA I/O Advanced Programmable Controller (IOAPIC) (Datasheet)
@@ -256,32 +332,20 @@ console=/dev/ttyFB0
+ Serial ATA: High Speed Serialized AT Attachment, Revision 3.2
+ SCSI Command Reference Manual
+ ATA/ATAPI Command Set - 3 (ACS-3)
-+ [ECMA-119 (ISO9660)](https://www.ecma-international.org/publications-and-standards/standards/ecma-119/)
++ ECMA-119 (ISO9660)
+ Rock Ridge Interchange Protocol (RRIP: IEEE P1282)
+ System Use Sharing Protocol (SUSP: IEEE P1281)
+ Tool Interface Standard (TIS) Portable Formats Specification (Version 1.1)
-
-**å
责声æï¼PCIç¸å
³çæ åæç»è§£éæå½PCI-SIGææãæ¤å¤æä¾ç坿¬ä»
ä¾ä¸ªäººå¦ä¹ 使ç¨ãä»»ä½åç¨ç®çé¡»åPCI-SIGè´ä¹°ã**
-
-#### ç论书ç±
-
-+ *Computer System - A Programmer's Perspective Third Edition (CS:APP)* (Bryant, R & O'Hallaron, D)
++ *Computer System - A Programmer's Perspective Third Edition* (Bryant, R & O'Hallaron, D), a.k.a. CS:APP
+ *Modern Operating System* (Tanenbaum, A)
++ Free VGA, http://www.osdever.net/FreeVGA/home.htm
++ GNU CC & LD online documentation.
++ PCI Lookup, https://www.pcilookup.com/
++ Linux man pages
-#### ç½ç«
-
-+ [OSDev](https://wiki.osdev.org/Main_Page) - éåå¿«éå
¥é¨ï¼åä¸äºææ¡£æåçæ»ç»ã
-+ [FreeVGA](http://www.osdever.net/FreeVGA/home.htm) - 98å¹´çèµæºï¼å
³äºVGAç¼ç¨ææ¯çå®èç½ç«ã
-+ GNU CC å GNU LD ç宿¹ææ¡£ã
-+ [PCI Lookup](https://www.pcilookup.com/) - PCI设å¤ç¼å·æ¥è¯¢
-
-#### å
¶ä»
-
-+ Linux Manual - ç¨äºæ¥è¯¢*nix APIçä¸äºå
·ä½è¡ä¸ºã
-
-## éå½1ï¼å®ç°ç POSIX ç³»ç»æ¥å£
+## Appendix 1: Supported System Call
-LunaixOS æä¾å¯¹ä»¥ä¸POSIXçç³»ç»æ¥å£çå®ç°ãå
æ ¸å®ä¹çç³»ç»è°ç¨å·å¯ä»¥åè [LunaixOSç³»ç»è°ç¨è¡¨](docs/lunaix-syscall-table.md) ã
+**Unix/Linux/POSIX**
1. `sleep(3)`
1. `wait(2)`
@@ -296,7 +360,7 @@ LunaixOS æä¾å¯¹ä»¥ä¸POSIXçç³»ç»æ¥å£çå®ç°ãå
æ ¸å®ä¹çç³»ç»è°
1. `_exit(2)`
1. `sigreturn(2)`
1. `sigprocmask(2)`
-1. `sigaction(2)`
+1. `signal(2)`
1. `kill(2)`
1. `sigpending(2)`
1. `sigsuspend(2)`
@@ -312,7 +376,7 @@ LunaixOS æä¾å¯¹ä»¥ä¸POSIXçç³»ç»æ¥å£çå®ç°ãå
æ ¸å®ä¹çç³»ç»è°
2. `rmdir(2)`
2. `unlink(2)`
2. `unlinkat(2)`
-2. `link(2)`â»
+2. `link(2)`
2. `fsync(2)`
2. `dup(2)`
2. `dup2(2)`
@@ -322,7 +386,7 @@ LunaixOS æä¾å¯¹ä»¥ä¸POSIXçç³»ç»æ¥å£çå®ç°ãå
æ ¸å®ä¹çç³»ç»è°
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)`â»
@@ -344,28 +408,43 @@ LunaixOS æä¾å¯¹ä»¥ä¸POSIXçç³»ç»æ¥å£çå®ç°ãå
æ ¸å®ä¹çç³»ç»è°
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**
-( **â»**ï¼è¯¥ç³»ç»è°ç¨ææªç»è¿æµè¯ )
+1. `yield`
+2. `geterrno`
+3. `realpathat`
-## éå½2ï¼Issueçæäº¤
+( **â»**ï¼Indicate syscall is not tested )
-åè¥Lunaixçè¿è¡åºç°ä»»ä½é®é¢ï¼è¿è¯·æç
§ä»¥ä¸çæè¿°ï¼å¨Issueé颿ä¾è¯¦ç»çä¿¡æ¯ã
+## Appendix 2: Debugging with GDB remotely via UART
-+ å¯ç¨äºå¤ç°é®é¢çæè¿°åæå¼ï¼å¦Lunaixè¿è¡å¹³å°ç软硬件é
ç½®ï¼
-+ é误çç¶æè¿°
-+ LunaixOSå¨panicæ¶æå°çè°è¯ä¿¡æ¯ï¼å¦æ æ³å¤å¶ï¼å¯ä»¥æªå¾ï¼
+**(((( Broken after a refactoring years ago, need rework ))))**
-## éå½3ï¼ä¸²å£GDBè¿ç¨è°è¯
+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.
-**ï¼è¯¥åè½æ£å¨éæï¼ç®åä¸å¯ç¨ï¼**
+One could trigger the debug mode by writing a byte sequence `0x40` `0x63` `0x6D` `0x63`, to the same serial port. A text "DEBUG MODE" with magenta-coloured background shall be present at the bottom of the screen.
-LunaixOSå
æ ¸éæäºæåºæ¬çGDBè¿ç¨è°è¯æå¡å¨ãå¯éè¿ä¸²å£COM1å¨9600æ³¢ç¹çä¸ä¸ä¹å»ºç«é¾æ¥ã使¯ï¼å¨å°GDBä¸å
æ ¸é¾æ¥èµ·æ¥ä¹åï¼è¿éè¦è®©å
æ ¸å¤å¨è°è¯æ¨¡å¼ä¸ã
+Note that, whenever the text appears, the LunaixOS always halt all activities other than the debugging server, which means no scheduling and no external interrupt servicing. Users are now recommended to attach their GDB and drive the kernel with the debugging workflow.
-è¦è¿å
¥è°è¯æ¨¡å¼ï¼éè¦å¾ä¸²å£ï¼æ³¢ç¹çå¦ä¸ï¼åå
¥åè串 `0x40` `0x63` `0x6D` `0x63`ãæ¤æ¶ï¼å¦æå±å¹åºé¨åºç°ä¸æ¡å红è²èæ¯ç`DEBUG` åæ ·ï¼é£ä¹å°±è¯´æLunaixOSå·²å¤å¨è°è¯æ¨¡å¼ä¸ã
+Currently, LunaixOS implements the required minimal server-side command subset required by GDB Remote Protocol, namely, `g`, `G`, `p`, `P`, `Q`, `S`, `k`, `?`, `m`, `M`, `X`. Which should be enough to cover most debugging activities.
-注æï¼å¨è¿ä¸ªæ¶åï¼LunaixOSä¼å¼å§å¨`COM1`ä¸çå¬GDBå议信æ¯ï¼å¹¶ä¸æåä¸åçæ´»å¨ï¼å¦è°åº¦ï¼ä»¥å对å¤é¨ä¸æçä¸åååºï¼ãç¨æ·æ¤æ¶éè¦å°GDBä¸å
¶æè½½ï¼å¹¶ä½¿ç¨GDBç工使µæ¥æç¤ºå
æ ¸ä¸ä¸æ¥çå¨ä½ã
+When debugging is finished, one shall disconnect with `kill` command. This command will not force LunaixOS to power down the computer, instead it just resume the execution (identical behavior as `c` command). However, disconnecting does not means exiting of debug mode. The debug mode is still actived and any subsequent GDB attaching request shall remain the highest priority amongst all other activity. One shall deactivate the debug mode by writing byte sequence `0x40` `0x79` `0x61` `0x79` to the port, after GDB detached.
-å¨ç®åï¼ä¸ºäºé²æ¢ä»£ç è¿äºèè¿ï¼LunaixOSå®ç°çæ¯GDBè¿ç¨åè®®è¦æ±çæå°æå¡ç«¯å½ä»¤åéï¼`g`, `G`, `p`, `P`, `Q`, `S`, `k`, `?`, `m`, `M`, `X`ã足以满足大é¨åçè°è¯éæ±ã
+### Limitations
-å½ç»æè°è¯çæ¶åï¼è¯·ä½¿ç¨GDBç`kill`æä»¤è¿è¡è¿æ¥çæå¼ã注æï¼è¿ä¸ªæä»¤ä¼ä½¿å¾LunaixOSæ¢å¤æææåçæ´»å¨ï¼è¿å
¥æ£å¸¸çè¿è¡åºåï¼ä½å¹¶ä¸ä¼éåºè°è¯æ¨¡å¼ãGDBçæè½½è¯·æ±ä¾ç¶å¨LunaixOSä¸äº«ææé«ä¼å
æã妿éè¦éåºè°è¯æ¨¡å¼ï¼éè¦å¾ä¸²å£åå
¥åè串ï¼`0x40` `0x79` `0x61` `0x79`ã
+Currently, one should avoid the use of `info stack`, `bt` or any other command that involves stack unwinding or stack backtracing. As it will somehow corrupt the stack layout and result in undefined behaviour. This issue should be addressed in future releases.