fix: PS/2 keyboard initialization sequence
[lunaix-os.git] / docs / README_en.md
1 <p align="center">
2   <img width="auto" src="img/lunaix-os-logo.png">
3 </p>
4
5 <p align="center">
6   <a href="../README.md"><b>简体中文</b></a> | <span><b>English</b></span>
7 </p>
8
9 # The LunaixOS Project 
10 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).
11
12 ## Features
13
14 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. 
15
16 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).
17
18
19 The following list presents all features it does have in current stage.
20
21 + Multiboot for bootstrapping
22 + APIC/IOAPIC as interrupt controller and programmable timer.
23 + ACPI table parsing.
24 + Virtual memory & paging
25 + Memory management & demand paging
26 + PS/2 Keyboard support
27 + Muti-tasking and task management
28 + 47 commonly used POSIX syscall([See Appendix 1](#appendix1))
29 + User Space
30 + Signal
31 + PCI 3.0
32 + PCIe 1.1 (WIP)
33 + Serial ATA AHCI
34 + Virtual File System
35 + GDB Remote debugger (via UART)
36   
37 The OS has been tested in the following environments, including both virtual and bare-metal.
38
39 + QEMU (>=7.0.0)
40 + Bochs (Not really, as it lacks support on SATA)
41 + Virtualbox
42 + Dell G3 3775 Laptop
43
44 ## Project Structure
45
46 | | |
47 |-----|------|
48 | [lunaix-os](../lunaix-os/) | LunaixOS source code |
49 | [slides](../slides/) | Slides used in my videos |
50 | [reference-material](../reference-material/)| References |
51
52 ## Compile and Build
53
54 You will need following dependencies in order to build LunaixOS
55
56 + gcc **(target=i686-elf)**
57 + binutils
58 + make
59 + xorriso
60 + grub-mkrescue
61
62 The following `make` actions are available to use.
63
64 | Action | Description |
65 |---|---|
66 | `make all` | Build bootable(`-O2`) |
67 | `make all-debug` | Build debuggable bootable(`-Og`) |
68 | `make run` | Boot the OS with QEMU |
69 | `make debug-qemu` | Build and debug with QEMU |
70 | `make debug-bochs` | Build and debug with Bochs |
71 | `make debug-qemu-vscode` | Used for integrated with vscode for better debug experience |
72 | `make clean` | Delete recent build |
73
74 When a bootable is built, it is an `.iso` image file and can be found under `build/` directory.
75
76 ## Running and Issue
77
78 To run LunaixOS, you will be required to attach a usable virtual disk image. You can use the following handy command to create one:
79
80 ```bash
81 qemu-img create -f vdi machine/disk0.vdi 128M
82 ```
83
84 However, if you have image other than standard `.vdi`, you shall change `configs/make-debug-tool` accordingly.
85
86 Locate this particular line:
87
88 ```
89 -drive id=disk,file="machine/disk0.vdi",if=none \
90 ```
91
92 and replace the default path with your preferred.
93
94 There are also many other ways to create disk image, such as the aforementioned `qemu-img`.
95
96 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.
97
98 To maximize the value of this section, we will provide some FAQ below that hopefully resolve some "not working" complains:
99
100 #### Q1: Prompting "i8042: not found" after boot in QEMU
101
102 This is a issue related to misconfiguration of ACPI table in QEMU, and has been addressed in version 7.0.0.
103
104 #### Q2: General Protection exception get triggered.
105
106 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.
107
108 #### Q3: Prompting "AHCI: Not found." after boot in Bochs
109
110 This is an expected behaviour, as Bochs does not support SATA!
111
112 ## Referenced Tutorial
113
114 **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.
115
116 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".
117
118 You can find most of aforementioned materials in [reference-material](../reference-material/).
119
120 The following list also enumerated such materials the author has used:
121
122 #### Manuals, Technical References and Standards
123
124 + [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)
125 + [ACPI Specification (version 6.4)](https://uefi.org/sites/default/files/resources/ACPI_Spec_6_4_Jan22.pdf)
126 + IBM PC/AT Technical Reference
127 + IBM VGA/XGA Technical Reference
128 + 82093AA I/O Advanced Programmable Controller (IOAPIC) (Datasheet)
129 + MC146818A (Datasheet)
130 + Intel 500 Series Chipset Family Platform Controller Hub (Datasheet - Volume 2)
131 + PCI Local Bus Specification, Revision 3.0
132 + PCI Express Base Specification, Revision 1.1
133 + PCI Firmware Specification, Revision 3.0
134 + Serial ATA - Advanced Host Controller Interface (AHCI), Revision 1.3.1
135 + Serial ATA: HIgh Speed Serialized AT Attachment, Revision 3.2
136 + SCSI Command Reference Manual
137 + ATA/ATAPI Command Set - 3 (ACS-3)
138
139 **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**
140
141 #### Textbook
142 + *Computer System - A Programmer's Perspective Third Edition* (Bryant, R & O'Hallaron, D), a.k.a. CS:APP
143 + *Modern Operating System* (Tanenbaum, A)
144
145
146 #### Website 
147 + [OSDev](https://wiki.osdev.org/Main_Page) - For material gathering.
148 + [FreeVGA](http://www.osdever.net/FreeVGA/home.htm) - For VGA references.
149 + GNU CC & LD online documentation.
150 + [PCI Lookup](https://www.pcilookup.com/) - For device look up
151
152 #### Others
153 + Linux Manual - For learning the system call behavior on real machine.
154
155
156 ## Appendix 1: Supported System Call<a id="appendix1"></a>
157
158 **Unix/Linux/POSIX**
159 1. `sleep(3)`
160 1. `wait(2)`
161 1. `waitpid(2)`
162 1. `fork(2)`
163 1. `getpid(2)`
164 1. `getppid(2)`
165 1. `getpgid(2)`
166 1. `setpgid(2)`
167 1. `brk(2)`
168 1. `sbrk(2)`
169 1. `_exit(2)`
170 1. `sigreturn(2)`
171 1. `sigprocmask(2)`
172 1. `signal(2)`
173 1. `kill(2)`
174 1. `sigpending(2)`
175 1. `sigsuspend(2)`
176 2. `read(2)`
177 2. `write(2)`
178 2. `open(2)`
179 2. `close(2)`
180 2. `mkdir(2)`※
181 2. `lseek(2)`
182 2. `readdir(2)`
183 2. `readlink(2)`※
184 2. `readlinkat(2)`※
185 2. `rmdir(2)`※
186 2. `unlink(2)`※
187 2. `unlinkat(2)`※
188 2. `link(2)`※
189 2. `fsync(2)`※
190 2. `dup(2)`
191 2. `dup2(2)`
192 2. `symlink(2)`※
193 2. `chdir(2)`
194 2. `fchdir(2)`
195 2. `getcwd(2)`
196 2. `rename(2)`※
197 2. `mount(2)`
198 2. `unmount` (a.k.a `umount(2)`)※
199 2. `getxattr(2)`※
200 2. `setxattr(2)`※
201 2. `fgetxattr(2)`※
202 2. `fsetxattr(2)`※
203 2. `ioctl(2)`※
204 2. `getpgid(2)`
205 2. `setpgid(2)`
206
207 **LunaixOS**
208
209 1. `yield`
210 2. `geterrno`
211 3. `realpathat`
212
213 ( **※**:Indicate syscall is not tested )
214
215 ## Appendix 2: Debugging with GDB remotely via UART
216
217 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.
218
219 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.
220
221 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.
222
223 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.
224
225 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.
226
227 ### Limitations
228
229 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.