X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/9e581025ea6278702d605c8022eda888d37d8361..d0e3d2eb32f32869bb54b5724e19780c83fb592b:/README.md
diff --git a/README.md b/README.md
index e56afc9..c4a4ea9 100644
--- a/README.md
+++ b/README.md
@@ -3,53 +3,234 @@
- ç®ä½ä¸æ | English
+ ç®ä½ä¸æ | English
-# LunaixOS Project
-LunaixOS - ä¸ä¸ªç®åçï¼è¯¦ç»çï¼POSIXå
¼å®¹çï¼ä½æ¿ï¼ï¼ï¼å¸¦ææµéä¸ªäººé£æ ¼çæä½ç³»ç»ãå¼åè¿ç¨ä»¥è§é¢æç¨å½¢å¼å¨Bilibiliåç°ï¼[ãä»é¶å¼å§èªå¶æä½ç³»ç»ç³»åã](https://space.bilibili.com/12995787/channel/collectiondetail?sid=196337)ã
+# 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.
-该æä½ç³»ç»æ¯æx86æ¶æï¼è¿è¡å¨ä¿æ¤æ¨¡å¼ä¸ï¼éç¨å®å
æ ¸æ¶æï¼ç®åä»
æ¯æåæ ¸å¿ãå
åç»æéç¨ç»å
¸ç3:1ååï¼å³ä½3GiBä¸ºç¨æ·å°å空é´ï¼0x400000 ~ 0xBFFFFFFFï¼ï¼å
æ ¸å°å空é´éæ å°è³é«1GiBï¼0xC0000000 ~ 0xFFFFFFFFï¼ãå
åç详ç»å¸å±å¯åè[LunaixOSå
åå°å¾](docs/img/lunaix-os-mem.png)
+This project is based solely on first principles. Meaning that it does neither copy-pasting nor recycling other os projects/tutorials. However, this doesn't necessarily imply superiority; In fact, Lunaix starts out as a mean to challenge my understanding in OS theory and also a platform for experimenting some advanced (and cool) kernel features. If you are a kernel hobbyist who want some new perspectives or just simply get fatigued on those recycled content, then you have came to the right place!
-å¨ä¸è¿°å表ä¸ï¼åååºç®åææ¯æçæç¨åè½åç¹æ§ãå表项æç
§é¡¹ç®æ¶é´æ³è¿è¡ååºæåã
-+ 使ç¨Multibootè¿è¡å¼å¯¼å¯å¨
-+ APIC/IOAPICä½ä¸ºä¸æç®¡çå¨å计æ¶å¨
-+ ACPI
-+ èæå
å
-+ å
å管ç䏿éå页ï¼Demand Pagingï¼
-+ é®çè¾å
¥
-+ å¤è¿ç¨
-+ 17个常è§çLinux/POSIXç³»ç»è°ç¨ï¼[éå½1](#appendix1)ï¼
-+ ç¨æ·æ¨¡å¼
-+ ä¿¡å·æºå¶
-+ PCI 3.0
-+ PCIe 1.1 (WIP)
-+ Serial ATA AHCI (WIP)
+|  |
+|:--:|
+| *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
+
+In a nutshell, Lunaix is a multi-architectural general purpose kernel, and she 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.
+
+The author has put a significant amount of time on devising better abstractions, advance kernel features and various optimisation techniques. To give a better understanding (and appreciation) of the works being done, the following non-exhaust list has been compiled with features that are currently supported in lunaix:
+
++ Multi-ISA
+ + x86_32
+ + x86_64
+ + Aarch64 (W.I.P)
++ Boot protocol
+ + abstraction for different protocol
+ + configurable kernel boot-time parameters
++ Platform resource management and definition
+ + ACPI
+ + Devicetree
++ Memory management
+ + architecture-neutral abstraction
+ + 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
+ + highmem support
+ + remote address space accessing
++ Multi-tasking
+ + Protection level and process image isolation
+ + Native threading support (no more lightweight process nonsense)
+ + Signal mechanism
+ + Kernel level multi-tasking (i.e. kernel threads)
+ + Round-robin scheduling (for now)
+ + Preemptive kernel design
+ + taskfs: file system interface to process and threads
++ File system
+ + virtual file system framework
+ + ...with POSIX compliant interfaces
+ + file system mounting mechanism
+ + page cache for file IO
+ + node cache for vfs structure representation.
+ + ext2 (rev.0, rev.1)
+ + iso9660 (rock-ridge)
+ + twifs: file system interface to kernel states.
++ Device management and interrupt handling
+ + architecture-neutral design
+ + generalised driver framework
+ + generalised irq framework
+ + driver modularisation design
+ + support asynchronous device model
+ + devfs: file system interface to device subsystem
++ Block I/O (blkio)
+ + generalised block IO interface and encapsulation
+ + blkio packets caching
+ + asynchronous blkio operation in nature
++ Serial I/O
+ + POSIX-compliant serial port model
+ + serial device driver framework (part of driver framework)
++ Caching Infrastructure
+ + primitive: generic sparse associative array (spatial data)
+ + LRU replacement policy and pooling
+ + kernel daemon for scheduled cache eviction
++ Error handling and detection
+ + stack back-tracing with symbol resolution
+ + nested exception unfolding
+ + CPU state dumping
+ + Deadlock/hung-up detection
+
+For the device drivers that are currently support see below:
+
++ Arhcitecture 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 (W.I.P)
+
+## Project Structure
+
+| Path | Description |
|-----|------|
-| [lunaix-os](lunaix-os/) | LunaixOSæºä»£ç |
-| [slides](slides/) | è§é¢ä¸æç¨çå¹»ç¯çåè¡¥å
ææ |
-| [reference-material](reference-material/)| æ åï¼ææ¯ææ¡£ååèæç® |
+| [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+)
+
+And also one should have environment variable `ARCH=` exported, where `` 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 ``.
+
+The following `make` actions are then available to use.
+
+| Make command | Usage |
+| ---- | ---- |
+| `make all` | Build the kernel bin |
+| `make rootfs` | Build the stock rootfs |
+| `make clean` | clean |
+| `make config` | menuconfig |
+
+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).
+
+Following the steps:
+
+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
+
+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
+
+The kernel command line, is however, a bit differentiated.
+The syntax is similar, both takes form of space-separated array of `=` pairs or boolean ``.
+
+Currently, lunaix support the following options
-## åèæç¨
+| 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` |
-**没æï¼ï¼** æ¬æç¨ä»¥å该æä½ç³»ç»å为ååï¼æ²¡æåºäºä»»ä½å¸é¢ä¸ç°è¡çæä½ç³»ç»å¼åæç¨ï¼ä¸å¹¶éæ¯åºäºä»»ä½ç弿ºå
æ ¸çäºæ¬¡å¼åã
-为äºå¶ä½LunaixOSï¼ä½è
èè´¹å¤§éæ¶é´åç²¾åé»ç ææ¯ææ¡£ï¼æåï¼ç论书ç±ä»¥åç°è¡å·¥ä¸æ åï¼ä»èå°½éä¿è¯äºç¥è¯ç䏿æ§ãï¼è¿æ ·ä¸æ¥ï¼è¯»è
åå¬ä¼ä»¬ä¹ç®æ¯æ¿å°äºäºæçç¥è¯ï¼è䏿¯ä¸æï¼åæï¼çè³næçç¥è¯ï¼ã
+## Submit an Issue
-大é¨åçææ¡£åæ åå¯ä»¥å¨ä¸è¿°ç[reference-material](reference-material/)䏿¾å°ã
+If one ran into bug, one can submit an issue by filling up the following template
-å½ç¶ï¼æ¨ä¹å¯ä»¥åè以ä¸å表æ¥äºè§£ç°é¶æ®µçLunaixOSé½ä½¿ç¨äºåªäºèµæï¼æ¬å表ä¼éçå¼åè¿åº¦æ´æ°ï¼ï¼
+```
+1. Describe the problem
+ "How does it look like, anything descriptive: visual, sonic, emotional experience"
-#### æåï¼æ åï¼ææ¯ææ¡£
-+ [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)
+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 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.
+
+## Acknowledgement
+
+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.
+
+As a personal challenge, this project is independently developed by the author single-handly, which means:
+
++ 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)
++ 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)
@@ -59,29 +240,24 @@ LunaixOS - ä¸ä¸ªç®åçï¼è¯¦ç»çï¼POSIXå
¼å®¹çï¼ä½æ¿ï¼ï¼ï¼å¸¦æ
+ PCI Express Base Specification, Revision 1.1
+ PCI Firmware Specification, Revision 3.0
+ Serial ATA - Advanced Host Controller Interface (AHCI), Revision 1.3.1
-+ Serial ATA: HIgh Speed Serialized AT Attachment, Revision 3.2
-
-**å
责声æï¼PCIç¸å
³çæ åæç»è§£éæå½PCI-SIGææãæ¤å¤æä¾ç坿¬ä»
ä¾ä¸ªäººå¦ä¹ 使ç¨ãä»»ä½åç¨ç®çé¡»åPCI-SIGè´ä¹°ã**
-
-#### ç论书ç±
-+ *Computer System - A Programmer's Perspective Third Edition (CS:APP)* (Bryant, R & O'Hallaron, D)
++ Serial ATA: High Speed Serialized AT Attachment, Revision 3.2
++ SCSI Command Reference Manual
++ ATA/ATAPI Command Set - 3 (ACS-3)
++ 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)
++ *Computer System - A Programmer's Perspective Third Edition* (Bryant, R & O'Hallaron, D), a.k.a. CS:APP
+ *Modern Operating System* (Tanenbaum, A)
-+ ãæ±ç¼è¯è¨ãï¼çç½ï¼ - ç¨äºå
¥é¨Intelè¯æ³çx86æ±ç¼ï¼å¯¹äºAT&Tè¯æ³ï¼æ¨èé
读CS:APPï¼
-+ ~~ãå¾®æºåç䏿¥å£ææ¯ã - ç¨äºå¤§è´äºè§£x86æ¶æçå¾®æºä½ç³»ï¼æ´å ç»è´çäºè§£å¯ä»¥é
读Intel Manualï¼~~ ï¼å·²è¿æ¶ï¼æ¨èé
读CS:APPï¼
-
-#### ç½ç«
-+ [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çä¸äºå
·ä½è¡ä¸ºã
++ Free VGA, http://www.osdever.net/FreeVGA/home.htm
++ GNU CC & LD online documentation.
++ PCI Lookup, https://www.pcilookup.com/
++ Linux man pages
+## Appendix 1: Supported System Call
-## éå½1ï¼æ¯æçç³»ç»è°ç¨
+**Unix/Linux/POSIX**
-### Unix/Linux/POSIX
1. `sleep(3)`
1. `wait(2)`
1. `waitpid(2)`
@@ -99,7 +275,87 @@ LunaixOS - ä¸ä¸ªç®åçï¼è¯¦ç»çï¼POSIXå
¼å®¹çï¼ä½æ¿ï¼ï¼ï¼å¸¦æ
1. `kill(2)`
1. `sigpending(2)`
1. `sigsuspend(2)`
+2. `read(2)`
+2. `write(2)`
+2. `open(2)`
+2. `close(2)`
+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. `dup(2)`
+2. `dup2(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. `getxattr(2)`â»
+2. `setxattr(2)`â»
+2. `fgetxattr(2)`â»
+2. `fsetxattr(2)`â»
+2. `ioctl(2)`
+2. `getpgid(2)`
+2. `setpgid(2)`
+2. `mmap(2)`
+2. `munmap(2)`
+2. `execve(2)`
+3. `poll(2)` (via `pollctl`)
+3. `epoll_create(2)` (via `pollctl`)
+3. `epoll_ctl(2)` (via `pollctl`)
+3. `epoll_wait(2)` (via `pollctl`)
+4. `pthread_create`
+4. `pthread_self`
+4. `pthread_exit`
+4. `pthread_join`
+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èªæ
+**LunaixOS**
1. `yield`
+2. `geterrno`
+3. `realpathat`
+
+( **â»**ï¼Indicate syscall is not tested )
+
+## Appendix 2: Debugging with GDB remotely via UART
+
+**(((( 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.
+
+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.
+
+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.
+
+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.
+
+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.
+
+### Limitations
+
+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.