2 <img width="auto" src="img/lunaix-os-logo.png">
6 <a href="../README.md"><b>简体中文</b></a> | <span><b>English</b></span>
11 LunaixOS - A simple (yet naive), POSIX-complaint (hopefully!), operating system from scratch. This is started for educational & learning purpose, for my online video tutorial on OS development **in Chinese**:[*Do It Yourself an Operating System*](https://space.bilibili.com/12995787/channel/collectiondetail?sid=196337).
15 This operating system is a macro-kernel, has its root in Intel's x86 platform and its ecosystem. It runs in protected mode and uses 4GiB addressing with two-level paging mechanism. It does not have x86_64 variant and does not support multi-core machine.
17 The virtual address space is divided into two parts, that is, 3GiB for user space (0x400000 ~ 0xBFFFFFFF) and 1GiB for kernel space (0xC0000000 ~ 0xFFFFFFFF). Such paradigm is a common practicing found in major operating systems, for example x86_32 version of Linux and Windows. For a more detailed arrangement of memory in LunaixOS, please refer to [LunaixOS Virtual Memory Mappings](img/lunaix-os-mem.png).
19 The following list presents all features it does have in current stage.
21 + Multiboot for bootstrapping
22 + APIC/IOAPIC as interrupt controller and programmable timer.
24 + Virtual memory & paging
25 + Memory management & demand paging
26 + PS/2 Keyboard support
27 + Muti-tasking and task management
28 + 50 commonly used POSIX syscall([See Appendix 1](#appendix1))
38 + Rock Ridge Extension (WIP)
39 + GDB Remote debugger (via UART)
41 The OS has been tested in the following environments, including both virtual and bare-metal.
44 + Bochs (Not really, as it lacks support on SATA)
52 | [lunaix-os](../lunaix-os/) | LunaixOS source code |
53 | [slides](../slides/) | Slides used in my videos |
54 | [reference-material](../reference-material/)| References |
58 You will need following dependencies in order to build LunaixOS
60 + gcc **(target=i686-elf)**
66 The following `make` actions are available to use.
68 | Action | Description |
70 | `make all` | Build bootable(`-O2`) |
71 | `make all-debug` | Build debuggable bootable(`-Og`) |
72 | `make run` | Boot the OS with QEMU |
73 | `make debug-qemu` | Build and debug with QEMU |
74 | `make debug-bochs` | Build and debug with Bochs |
75 | `make debug-qemu-vscode` | Used for integrated with vscode for better debug experience |
76 | `make clean` | Delete recent build |
78 When a bootable is built, it is an `.iso` image file and can be found under `build/` directory.
82 To run LunaixOS, you will be required to attach a usable virtual disk image. You can use the following handy command to create one:
85 qemu-img create -f vdi machine/disk0.vdi 128M
88 However, if you have image other than standard `.vdi`, you shall change `configs/make-debug-tool` accordingly.
90 Locate this particular line:
93 -drive id=disk,file="machine/disk0.vdi",if=none \
96 and replace the default path with your preferred.
98 There are also many other ways to create disk image, such as the aforementioned `qemu-img`.
100 The next thing is about issue. In the most common situation, the master branch should be stable in aforementioned running environments. However, one might encounter compiler-optimization related issue when they compiled with `-O2`. Such condition will usually be addressed and fixed in the following commits. Should the issue remains, please post your issue here.
102 To maximize the value of this section, we will provide some FAQ below that hopefully resolve some "not working" complains:
104 #### Q1: Prompting "i8042: not found" after boot in QEMU
106 This is a issue related to misconfiguration of ACPI table in QEMU, and has been addressed in version 7.0.0.
108 #### Q2: General Protection exception get triggered
110 It is possible a race condition result from multiprogramming. This is not possible in current stage, and we however encourage you to report in case of it.
112 #### Q3: Prompting "AHCI: Not found." after boot in Bochs
114 This is an expected behaviour, as Bochs does not support SATA!
116 ## Referenced Tutorial
118 **THERE IS NONE !** The project is based solely on my understanding on operating system concepts and relevant research. And has referenced no third party tutorial nor open source project like the Linux or other hobbyist project.
120 Thus, the author has devoted large amount of time to go through any related materials such as technical references, manuals, textbooks, and industrial standards. To further ensure the technology used and knowledge taught is up-to-date and is coming "straight from the factory".
122 You can find most of aforementioned materials in [reference-material](../reference-material/).
124 The following list also enumerated such materials the author has used:
126 #### Manuals, Technical References and Standards
128 + [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)
129 + [ACPI Specification (version 6.4)](https://uefi.org/sites/default/files/resources/ACPI_Spec_6_4_Jan22.pdf)
130 + IBM PC/AT Technical Reference
131 + IBM VGA/XGA Technical Reference
132 + 82093AA I/O Advanced Programmable Controller (IOAPIC) (Datasheet)
133 + MC146818A (Datasheet)
134 + Intel 500 Series Chipset Family Platform Controller Hub (Datasheet - Volume 2)
135 + PCI Local Bus Specification, Revision 3.0
136 + PCI Express Base Specification, Revision 1.1
137 + PCI Firmware Specification, Revision 3.0
138 + Serial ATA - Advanced Host Controller Interface (AHCI), Revision 1.3.1
139 + Serial ATA: High Speed Serialized AT Attachment, Revision 3.2
140 + SCSI Command Reference Manual
141 + ATA/ATAPI Command Set - 3 (ACS-3)
142 + [ECMA-119 (ISO9660)](https://www.ecma-international.org/publications-and-standards/standards/ecma-119/)
143 + Rock Ridge Interchange Protocol (RRIP: IEEE P1282)
144 + System Use Sharing Protocol (SUSP: IEEE P1281)
146 **DISCLAIMER: All rights of PCI-related specification is reserved by PCI-SIG. It is provided ONLY for learning purpose. Any commercial use should purchase a copy from PCI-SIG**
150 + *Computer System - A Programmer's Perspective Third Edition* (Bryant, R & O'Hallaron, D), a.k.a. CS:APP
151 + *Modern Operating System* (Tanenbaum, A)
155 + [OSDev](https://wiki.osdev.org/Main_Page) - For material gathering.
156 + [FreeVGA](http://www.osdever.net/FreeVGA/home.htm) - For VGA references.
157 + GNU CC & LD online documentation.
158 + [PCI Lookup](https://www.pcilookup.com/) - For device look up
162 + Linux Manual - For learning the system call behavior on real machine.
164 ## Appendix 1: Supported System Call<a id="appendix1"></a>
207 2. `unmount` (a.k.a `umount(2)`)※
225 ( **※**:Indicate syscall is not tested )
227 ## Appendix 2: Debugging with GDB remotely via UART
229 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.
231 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.
233 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.
235 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.
237 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.
241 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.