Skip to content

Commit d523369

Browse files
authored
[Patch] Documentation for Bootloader, Kernel, VGA, CI Github Actions and Multiboot (#20)
1 parent 319f8d3 commit d523369

File tree

16 files changed

+1082
-2
lines changed

16 files changed

+1082
-2
lines changed

README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,65 @@
11
# AnasOS
2-
an operatin system
32

4-
Curently in development.
3+
AnasOS is a lightweight operating system developed as a graduation project. The primary goal is to create a functional OS from scratch using modern technologies.
4+
5+
## Download
6+
7+
You can download the latest release of AnasOS, including the `iso.zip` file, from the [releases page](https://github.com/Mrgoblings/AnasOS/releases).
8+
9+
## Technologies Used
10+
11+
- **Rust**: The core of the operating system is written in Rust for safety and performance.
12+
- **Assembly**: Utilized for low-level system programming.
13+
- **Makefile**: Used for managing build automation.
14+
15+
## Building the OS
16+
17+
If you want to build AnasOS yourself, please follow these instructions for a Debian-based Linux distribution:
18+
19+
1. **Clone the repository**:
20+
21+
```sh
22+
git clone https://github.com/Mrgoblings/AnasOS.git
23+
cd AnasOS
24+
```
25+
26+
2. **Install dependencies**:
27+
28+
```sh
29+
sudo apt update
30+
sudo apt install -y nasm grub-pc-bin grub-common make mtools xorriso
31+
rustup update nightly
32+
rustup target add x86_64-unknown-none --toolchain nightly
33+
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
34+
```
35+
36+
3. **Build & Run the OS in qemu**:
37+
38+
```sh
39+
make
40+
```
41+
42+
## Documentation
43+
44+
For more detailed instructions and documentation, please refer to the [docs/](docs/) directory. There is a README file that explains everything needed for the OS.
45+
46+
## References
47+
48+
Here are some tutorials and resources that were used in the creation of AnasOS:
49+
50+
- [ Writing an OS in Rust from Philipp Oppermann's blog](https://os.phil-opp.com/)
51+
- [Write Your Own 64-bit Operating System Kernel by CodePulse](https://www.youtube.com/playlist?list=PLZQftyCk7_SeZRitx5MjBKzTtvk0pHMtp)
52+
- [Making an OS (x86) by Daedalus Community](https://www.youtube.com/playlist?list=PLm3B56ql_akNcvH8vvJRYOc7TbYhRs19M)
53+
- [Operating Systems by OliveStem](https://www.youtube.com/playlist?list=PL2EF13wm-hWAglI8rRbdsCPq_wRpYvQQy)
54+
- [Stack Unwinding](https://www.bogotobogo.com/cplusplus/stackunwinding.php)
55+
- [Rust Standard Library Runtime](https://github.com/rust-lang/rust/blob/bb4d1491466d8239a7a5fd68bd605e3276e97afb/src/libstd/rt.rs#L32-L73)
56+
- [Name Mangling](https://en.wikipedia.org/wiki/Name_mangling)
57+
- [Calling Convention](https://en.wikipedia.org/wiki/Calling_convention)
58+
- [Cross Compilation with Clang](https://clang.llvm.org/docs/CrossCompilation.html#target-triple)
59+
- [Multiboot Specification](https://wiki.osdev.org/Multiboot)
60+
- [GNU GRUB Multiboot](https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#OS-image-format)
61+
- [Paging in Operating System](https://www.geeksforgeeks.org/paging-in-operating-system/)
62+
63+
## Author and Licensing
64+
65+
AnasOS is developed by Emil Momchev. The project is licensed under the [MIT License](LICENSE). When distributing, mention the author and the repository.

docs/README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# AnasOS Documentation
2+
3+
Welcome to the AnasOS documentation. This document will guide you through the various components of the AnasOS operating system, including the multiboot configuration, kernel, window manager, and applications.
4+
5+
## Table of Contents
6+
7+
1. [Introduction](#introduction)
8+
2. [File Structure](#file-structure)
9+
3. [Multiboot Configuration](#multiboot-configuration)
10+
4. [Bootloader](#bootloader)
11+
4. [Kernel](#kernel)
12+
5. [Window Manager](#window-manager)
13+
6. [Applications](#applications)
14+
7. [Technologies Used](#technologies-used)
15+
8. [CI with GitHub Actions](#ci-with-github-actions)
16+
9. [Requirements](#requirements)
17+
18+
## Introduction
19+
20+
AnasOS is a custom operating system designed for educational purposes as part of a 12th-grade thesis project. This documentation provides detailed information about the different parts of the OS and how they work together. AnasOS is built for the **_x86_64_** architecture, chosen over ARM due to the availability of more and better resources on the topic.
21+
22+
## Technologies Used
23+
24+
- **Rust**: The core of the operating system is written in Rust for safety and performance.
25+
- **NASM**: The assembler used for writing assembly code for the bootloader.
26+
- **Makefile**: Used for managing build automation.
27+
- **GRUB**: The bootloader used for loading the kernel.
28+
- **QEMU**: The emulator used for testing the operating system.
29+
- **GitHub Actions**: Used for continuous integration and deployment.
30+
31+
## File Structure
32+
33+
Below is the file structure for the AnasOS documentation:
34+
35+
```
36+
/docs
37+
├── README.md
38+
├── applications
39+
│ ├── README.md
40+
│ ├── browser.md
41+
│ └── terminal.md
42+
├── bootloader
43+
│ ├── README.md
44+
│ ├── header.md
45+
│ ├── boot.md
46+
│ └── boot-64.md
47+
├── ci-github-actions
48+
│ ├── README.md
49+
│ ├── header.md
50+
│ ├── boot.md
51+
│ └── boot-64.md
52+
├── kernel
53+
│ ├── README.md
54+
│ └── kernel.md
55+
├── multiboot
56+
│ ├── README.md
57+
│ └── multiboot.md
58+
└── window-manager
59+
├── README.md
60+
└── window_manager.md
61+
```
62+
63+
## Multiboot Configuration
64+
65+
The multiboot configuration is responsible for initializing the hardware and loading the kernel into memory. Detailed documentation about the multiboot configuration can be found [here](multiboot/).
66+
67+
## Bootloader
68+
69+
The bootloader is a critical component that initializes the system and loads the kernel into memory. It is responsible for setting up the environment so that the kernel can execute properly. Detailed documentation about the bootloader can be found [here](bootloader/).
70+
71+
## Kernel
72+
73+
The kernel is the core component of AnasOS, managing system resources and providing essential services. Detailed documentation about the kernel can be found [here](kernel/).
74+
75+
## Window Manager
76+
77+
The window manager **WILL** handle the graphical user interface and window management. Detailed documentation about the window manager will be available [here](window-manager/).
78+
79+
## Applications
80+
81+
AnasOS **WILL** include two main applications: a [browser](applications/browser.md) and a [terminal](applications/terminal.md). Detailed documentation about these applications will be available [here](applications/).
82+
83+
## CI with GitHub Actions
84+
85+
GitHub Actions is used for continuous integration (CI) to automate the build, testing, and release processes of AnasOS. This ensures that every change is verified, the system remains stable, and new versions are released efficiently. The workflows are defined in the `.github/workflows` directory, with detailed documentation available in the [here](ci-github-actions/).
86+
87+
## Requirements
88+
89+
Before fully testing the OS, ensure you have the following requirements installed:
90+
91+
- **Rust**: Install Rust from [rust-lang.org](https://www.rust-lang.org/).
92+
- **NASM**: Install NASM from [nasm.us](https://www.nasm.us/).
93+
- **GRUB**: Install GRUB using your package manager.
94+
- **QEMU**: Install QEMU from [qemu.org](https://www.qemu.org/).
95+
- **Make**: Ensure Make is installed on your system.
96+
97+
98+
You can install the required packages on Debian-based Linux distributions using `apt` with the example from the [main README](../) file

docs/applications/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Applications
2+
3+
## Available Applications
4+
5+
### Browser
6+
For more information, see [Browser](browser.md).
7+
8+
### Terminal
9+
For more information, see [Terminal](terminal.md).

docs/applications/browser.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Browser Application
2+
3+
Coming soon. Not yet implemented.

docs/applications/terminal.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Terminal Application
2+
3+
Coming soon. Not yet implemented.

docs/bootloader/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# AnasOS Bootloader Documentation
2+
3+
## Overview
4+
5+
The AnasOS bootloader is a critical component of the AnasOS operating system. Written in NASM assembly, it is responsible for initializing the system and transitioning the CPU from real mode to 64-bit long mode. This document provides an overview of the bootloader's functionality and its role in the boot process.
6+
7+
## Boot Files
8+
9+
The bootloader consists of three main files:
10+
- **header.asm**: Contains the Multiboot2 header required for bootloader compatibility. More in the [header.md](header.md)
11+
- **boot.asm**: The main bootloader code, responsible for the entire boot process including setting up the stack, checking Multiboot compatibility, enabling paging, and handling errors More in the [boot.md](boot.md)
12+
- **boot-64.asm**: Handles the transition to 64-bit long mode. More in the [boot-64.md](boot-64.md)
13+
14+
## Integration with the Kernel
15+
16+
The bootloader is tightly integrated with the AnasOS kernel. The build process is managed by a `build.rs` script, which automates the compilation and linking of the bootloader and kernel object files into a single binary.
17+
18+
### Build Process
19+
20+
The `build.rs` script performs the following steps:
21+
1. **Assemble Bootloader**: The NASM assembler is used to compile the bootloader assembly files into object files.
22+
```sh
23+
nasm -f elf64 header.asm -o header.o
24+
nasm -f elf64 boot.asm -o boot.o
25+
nasm -f elf64 boot-64.asm -o boot-64.o
26+
```
27+
2. **Link Object Files**: The object files are linked together with the kernel object files to create a single binary.
28+
```sh
29+
ld -n -o bootloader.bin -T linker.ld header.o boot.o boot-64.o kernel.o
30+
```
31+
32+
### Bootloader Compilation
33+
34+
To compile only the bootloader manually, you would typically run the following commands:
35+
```sh
36+
nasm -f elf64 header.asm -o header.o
37+
nasm -f elf64 boot.asm -o boot.o
38+
nasm -f elf64 boot-64.asm -o boot-64.o
39+
ld -n -o bootloader.bin -T linker.ld header.o boot.o boot-64.o
40+
```
41+
42+
For simplicity, there is a Makefile in the `anasos-kernel/bootloader` folder that handles this compilation. This Makefile is a simplified version of the main Makefile from the root folder, but its purpose is to compile correctly and run the newly created ISO from the bootloader with QEMU.
43+
44+
## Conclusion
45+
46+
The AnasOS bootloader is a sophisticated piece of software that ensures a smooth transition from the initial power-on state to a fully operational 64-bit environment. Its careful design and implementation in NASM assembly make it a reliable foundation for the AnasOS operating system.

docs/bootloader/boot-64.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# BOOT-64.ASM Documentation
2+
3+
## Introduction
4+
This document provides a detailed explanation of the `BOOT-64.ASM` file, which is responsible for initializing the CPU in 64-bit long mode. After jumping into 64-bit mode, it's essential to set up the CPU environment correctly to ensure proper operation. The code is written in assembly language and is crucial for setting up the environment before the operating system kernel takes over. This documentation aims to explain each instruction and its purpose.
5+
6+
## Code Explanation
7+
8+
### Section: Setting Up Long Mode
9+
```assembly
10+
GLOBAL long_mode_start
11+
EXTERN _start
12+
13+
SECTION .text
14+
BITS 64
15+
long_mode_start:
16+
; load null to all data segment registers (needed for the cpu to work as intended)
17+
MOV ax, 0
18+
MOV ss, ax
19+
MOV ds, ax
20+
MOV es, ax
21+
MOV fs, ax
22+
MOV gs, ax
23+
24+
CALL _start
25+
26+
HLT
27+
```
28+
29+
#### Detailed Breakdown
30+
31+
1. **GLOBAL long_mode_start**
32+
- Makes the `long_mode_start` label available to other files, allowing them to reference this entry point.
33+
34+
2. **EXTERN _start**
35+
- Declares an external symbol `_start`, which is the main function of the Rust kernel. This is where the kernel's execution begins.
36+
37+
3. **SECTION .text**
38+
- Defines the beginning of a code section named `.text`, where the executable code resides.
39+
40+
4. **BITS 64**
41+
- Informs the assembler that the following code is intended for 64-bit mode.
42+
43+
5. **long_mode_start:**
44+
- A label marking the entry point of the long mode setup code. At this point, the system has just transitioned into 64-bit mode.
45+
46+
6. **MOV ax, 0**
47+
- Loads the value `0` into the `AX` register to prepare for initializing the segment registers.
48+
49+
7. **MOV ss, ax**
50+
- Sets the `SS` (Stack Segment) register to `0`. In 64-bit mode, all segment registers need to be set to `0` for the CPU to function properly, ensuring correct memory addressing.
51+
52+
8. **MOV ds, ax**
53+
- Sets the `DS` (Data Segment) register to `0`, which is necessary for proper data access.
54+
55+
9. **MOV es, ax**
56+
- Sets the `ES` (Extra Segment) register to `0`.
57+
58+
10. **MOV fs, ax**
59+
- Sets the `FS` (Additional Data Segment) register to `0`.
60+
61+
11. **MOV gs, ax**
62+
- Sets the `GS` (Additional Data Segment) register to `0`. Initializing all these registers prevents segmentation errors and ensures the CPU operates as expected.
63+
64+
12. **CALL _start**
65+
- Calls the `_start` function, transferring control to the Rust kernel's main function.
66+
67+
13. **HLT**
68+
- Halts the CPU, typically used if there is nothing else to execute.
69+
70+
## Conclusion
71+
The `BOOT-64.ASM` file is a critical component in the boot process of an operating system. After entering 64-bit long mode, setting all segment registers to `0` is essential for the CPU to function properly. This setup prepares the environment for the kernel's main function `_start` to take over. Each instruction serves a specific purpose to ensure the CPU operates correctly and transitions smoothly to the kernel.

0 commit comments

Comments
 (0)