8000 GitHub - kadds/NaOS: A 64bit (x86-64) Simple Operating System Writing By C++. · GitHub
[go: up one dir, main page]

Skip to content
kaddsPublic

About

A 64bit (x86-64) Simple Operating System Writing By C++.

Topics

Resources

Stars

18 stars

Watchers

2 watching

Forks

Repository files navigation

NaOS

Nano Operating system

A 64bit (arch x86-64) simple operating system writing by c++. (:sunglasses:)
NaOS runs on Intel / AMD modern processors.

BSD-3-Clause development on linux

Features

View Features .

Preview

preview1

Quick Start

Requirements

  • GNU Binutils (version 2.38 tested)
  • GNU EFI lib pacman -S gnu-efi
  • GCC or Clang (GCC 12.1.1 tested)
  • CMake 3.3+
  • ninja and meson are required to build libc
  • Python 3 (For running utilities and the NaoIDL compiler)
  • iasl (For compiling the QEMU Q35 root-disk firmware table)
  • Lark 1.3.1 (python3 -m pip install -r idl/requirements.txt)
  • An emulator or virtual machine such as Bochs, QEMU, Virtual Box, hyper-v and VMware Workstation (For running OS)
  • Grub2, fdisk / gdisk, qemu-img, fstool (For creating and editing raw disk images without host mount privileges)

Optional

  • OVMF (UEFI firmware) for QEMU if boot from UEFI environment

1. Download source code

Clone this repo

git clone https://url/path/to/repo
git submodule update --init --recursive
python3 -m pip install -r idl/requirements.txt

2. Compile

  • GCC
cd /path/to/repo

# build libc first
cd naos/libc/mlibc/
cat > cross_file.txt << EOF
[host_machine]
system = 'naos'
cpu_family = 'x86_64'
cpu = 'i686'
endian = 'little'

[binaries]
c = '/usr/bin/x86_64-pc-linux-gnu-gcc' 
cpp = '/usr/bin/x86_64-pc-linux-gnu-g++'
ar = '/usr/bin/ar'
strip = '/usr/bin/strip'

[properties]
needs_exe_wrapper = true
EOF

meson setup build --cross-file cross_file.txt -Ddefault_library=static
cd build && ninja

cd /path/to/repo
# build kernel and userland binaries (BusyBox + legacy nanobox)
mkdir build-debug
cd build-debug
# CMAKE_BUILD_TYPE: Debug\Release
cmake -DCMAKE_BUILD_TYPE=Debug -DFREELIBCXX_TEST=OFF ..
make -j
  • Or Clang/LLVM (Not tested yet)
cd /path/to/repo

# build libc first
cd naos/libc/mlibc/
cat > cross_file.txt << EOF
[host_machine]
system = 'naos'
cpu_family = 'x86_64'
cpu = 'i686'
endian = 'little'

[binaries]
c = '/usr/bin/clang'
c_ld = '/usr/bin/lld'
cpp = '/usr/bin/clang++'
cpp_ld = '/usr/bin/lld'
ar = '/usr/bin/ar'
strip = '/usr/bin/strip'

[properties]
needs_exe_wrapper = true
EOF
meson setup build --cross-file cross_file.txt -Ddefault_library=static
cd build && ninja 

cd /path/to/repo
# build kernel and userland binaries (BusyBox + legacy nanobox)
mkdir build-release
cd build-release

# CMAKE_BUILD_TYPE: Debug\Release
cmake -DCMAKE_BUILD_TYPE=Release -DFREELIBCXX_TEST=OFF  -DCMAKE_CXX_COMPILER="/usr/bin/clang++" -DCMAKE_C_COMPILER="/usr/bin/clang" -DCMAKE_CXX_FLAGS="-fuse-ld=lld" -DCMAKE_C_FLAGS="-fuse-ld=lld" ..

make -j

Linux host service smoke (no QEMU)

The standalone Linux host-service harness is retained for isolated transport and filesystem development, but it is not the production boot flow. Production boot uses the VirtIO block driver and the FAT32 system disk described below.

3. Creating and running boot artifacts

NaOS uses GRUB's Multiboot2 loader. The runner stages the system tree and fixed boot modules, creates a new FAT32 disk when needed, and installs BIOS GRUB:

python3 util/run.py --build-dir build-debug q

An ISO boot can be selected explicitly. The same build-local FAT32 disk is attached as a VirtIO block device. The ISO carries the kernel, ld-naos, and the five early services. Init and ordinary commands load from the disk.

Debug builds include the guest smoke binaries by default. For a Release smoke run, configure with -DNAOS_PACKAGE_SMOKE=ON. Set it to OFF to omit the binaries from a Debug image. Smoke scripts run only through an opt-in init hook.

python3 util/run.py --build-dir build-debug q --iso -n
python3 util/run.py --build-dir build-debug q --iso --uefi

The standard Q35 profile uses 512 MiB of guest RAM, VT-d interrupt remapping, and a firmware resource table for its single modern VirtIO root disk. Use --no-root-virtio-profile for a hardware test that supplies its own topology. Custom topologies need their own firmware BAR descriptions and DMA isolation to boot from VirtIO. Use --read-only-system-disk to attach the prepared system volume read-only.

The system volume is p1 in <build-dir>/image/disk.img. New images are formatted as FAT32; existing images are never reformatted, repaired, or silently converted. An existing volume must already be FAT32. Formatting is an explicit offline action:

python3 util/disk.py create --build-dir build-debug
python3 util/disk.py mkfat --build-dir build-debug
python3 util/disk.py mount --build-dir build-debug

The disk helper edits image files through fstool without a host mount or loop device. Install it with cargo install --git https://github.com/KarpelesLab/fstool --locked --force fstool.

CMake emits the kernel under build-debug/bin/system/kernel and the userland root tree under build-debug/bin/rfsroot. The real disk contains ordinary commands in /bin, system components in /bin/sys, and the VirtIO driver in /bin/drive; there is no production root.img.

Boot serial output is written to build-debug/kernel_out.log.

5. Debug

The command python util/gen_debug_asm.py kernel will generate kernel disassembly if needed. (e.g. Debug in bochs)

Repo Tree

NaOS
├── build-debug # build target directory; use another build-* for parallel validation
├── naos
│   ├── includes
│   │   └── kernel
│   └── src
│       ├── kernel
│       │   ├── arch # arch x86_64 specification source code
│       │   ├── common # kernel data
│       │   ├── dev # driver interface & drivers
│       │   ├── fs # file subsystem 
│       │   ├── io # io subsystem
│       │   ├── mm # memory subsystem
│       │   ├── module # module support code
│       │   ├── schedulers # round robin scheduler and completely fair scheduler
│       │   ├── syscall # syscall entries
│       │   ├── task # ELF loader and built-in task
│       │   └── util # util functions: memcpy, strcpy, cxxlib, formatter, containers
│       └── usr
│           ├── init # the userland init program 
│           ├── busybox # BusyBox 1.37.0 source and independent build input
│           └── bin # legacy nanobox program
├── run
│   ├── fakeroot # the files in fake root path will be overwritten to the real root path
│   └── cfg # emulator configuration files
├── build-debug
│   ├── image # generated ISO and disk images
│   ├── iso # per-build ISO staging directory
│   └── kernel_out.log # per-build QEMU serial output
└── util # Python tools

References

License

BSD-3-Clause © Kadds


          _____                    _____                   _______                   _____          
         /\    \                  /\    \                 /::\    \                 /\    \         
        /::\____\                /::\    \               /::::\    \               /::\    \        
       /::::|   |               /::::\    \             /::::::\    \             /::::\    \       
      /:::::|   |              /::::::\    \           /::::::::\    \           /::::::\    \      
     /::::::|   |             /:::/\:::\    \         /:::/~~\:::\    \         /:::/\:::\    \     
    /:::/|::|   |            /:::/__\:::\    \       /:::/    \:::\    \       /:::/__\:::\    \    
   /:::/ |::|   |           /::::\   \:::\    \     /:::/    / \:::\    \      \:::\   \:::\    \   
  /:::/  |::|   | _____    /::::::\   \:::\    \   /:::/____/   \:::\____\   ___\:::\   \:::\    \  
 /:::/   |::|   |/\    \  /:::/\:::\   \:::\    \ |:::|    |     |:::|    | /\   \:::\   \:::\    \ 
/:: /    |::|   /::\____\/:::/  \:::\   \:::\____\|:::|____|     |:::|    |/::\   \:::\   \:::\____\
\::/    /|::|  /:::/    /\::/    \:::\  /:::/    / \:::\    \   /:::/    / \:::\   \:::\   \::/    /
 \/____/ |::| /:::/    /  \/____/ \:::\/:::/    /   \:::\    \ /:::/    /   \:::\   \:::\   \/____/ 
         |::|/:::/    /            \::::::/    /     \:::\    /:::/    /     \:::\   \:::\    \     
         |::::::/    /              \::::/    /       \:::\__/:::/    /       \:::\   \:::\____\    
         |:::::/    /               /:::/    /         \::::::::/    /         \:::\  /:::/    /    
         |::::/    /               /:::/    /           \::::::/    /           \:::\/:::/    /     
         /:::/    /               /:::/    /             \::::/    /             \::::::/    /      
        /:::/    /               /:::/    /               \::/____/               \::::/    /       
        \::/    /                \::/    /                 ~~                      \::/    /        
         \/____/                  \/____/                                           \/____/         
                                                                                                    

About

A 64bit (x86-64) Simple Operating System Writing By C++.

Topics

Resources

Stars

18 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0