A heavily commented OS in Rust for reference purposes (documentation in progress).
Check out the companion site here: Tutorials
This OS is a hard fork of my private OS that I'm also working on. No more features will be added to this OS as it is for reference purposes only.
Huge thanks to Phil-opp and the OSDev wiki
Everything in this repository is under the MIT license, excluding the _posts and assets folder (which contains data for the companion website), which is copyrighted.
- Preemptive Multitasking (including system calls)
- System Calls (well, one of them)
- Primitive filesystem (Tar archive ram disk)
- Stack traces (with kernel symbols)
- Huge page support
- Huge frame allocation
- Keyboard driver
- Kernel shell (with tab completion)
You can find most of the prerequisites needed in the CMakeLists.txt
files located in the root and in kernel
folder.
Build requirements:
- NASM Assembler
- Binutils
- nm (Symbol table displayer)
- Rust
- Cargo
- Xargo
- LLVM linker
- tar (for creating the boot disk)
- grub-mkrescue (to generate the .iso file)
- CMake (if you wish to compile with CMake)
Execution requirements:
- QEMU
- Bochs
A bochsrc
file is located in the root.
Once you have installed the prerequisites, you can either compile everything manually or use CMake.
Change XARGO_TOOL
in the kernel CMake file from xargo-m
to xargo
. The -m suffix is to avoid Intellij-Rust from using Xargo to run tests.
Change OBJECT_COPY_TOOL
from gobjcopy
to objcopy
or whatever the objcopy
tool is aliased to.
Finally, run this command:
cmake --build cmake-build-debug --target x86_64-example_os.iso
The .iso file will be located in the cmake-build-debug folder
Import the project and then build the .iso
target after making the changes in the CMake section.
- Use NASM to compile all the files in
kernel/assembly
with the command
nasm -felf64 -w-number-overflow -Ikernel/assembly
- Use Xargo to compile the Rust binary with the command (execute in the
kernel
folder)
RUST_FLAGS=-Cforce-frame-pointers=yes RUST_TARGET_PATH=`pwd` xargo build --target x86_64-example_os
TheRUST_TARGET_PATH
is needed to allow xargo to locate the target specification. - Link all the files together
ld.lld --gc-sections -Tlinker.ld <Assembly object files> <Generated Rust file>
The Rust file is located inkernel/target/x86_64-example_os/debug/libkernel.a
- Create a
boot_disk
folder, and akernel
folder inside of that - Use
nm
against the linked binary and pipe it to a filesymbols.table
.
Copy this file into theboot_disk/kernel
folder. - Tar the
boot_disk
folder intoboot_disk.tar
- Create a
iso_files
folder, and aboot
folder inside of that, and agrub
folder inside of that - Copy the
grub.cfg
file intoiso_files/boot/grub
- Copy the
boot_disk.tar
intoiso_files/boot
- Create the .iso with the command
grub-mkrescue -o <ISO file> iso_files
Just run bochs
in the root directory. You may need to change the path to the iso file in the bochsrc
.
Run the command
qemu-system-x86_64 -cdrom x86_64-example_os.iso -monitor stdio -d int -no-reboot -no-shutdown