Khaled Hammouda
Home
Fusion OS
NimJet
Home
Fusion OS
NimJet
  • Fusion OS
    • Writing an OS in Nim
    • Environment Setup
    • Targeting UEFI (Part 1)
    • Targeting UEFI (Part 2)
    • UEFI Bootloader (Part 1)
    • UEFI Bootloader (Part 2)
    • Kernel Image
    • Loading the Kernel (Part 1)
    • Loading the Kernel (Part 2)
    • Loading the Kernel (Part 3)
    • Physical Memory
    • Virtual Memory
    • Higher Half Kernel
    • Memory Segments
    • Interrupts
    • User Mode
    • Task State Segment
    • System Calls
    • Tasks
    • Position Independent Code
    • ELF Loader (Part 1)
    • ELF Loader (Part 2)
    • Cooperative Multitasking
    • System Library
    • Interrupt Controller

Environment Setup

In this section, we'll set up our development environment. We'll be using Nim as our programming language, so obviously we'll need to install the Nim compiler. We also need a way to cross-compile to a freestanding environment. We'll use LLVM's clang and lld for that. Finally, we'll need a way to test our OS. We'll use QEMU for that.

Nim compiler

First, we need to install the Nim compiler. An easy way to install Nim is through the choosenim installer (or you can install it using your system's package manager), so let's install that first:

$ curl https://nim-lang.org/choosenim/init.sh -sSf | sh

Then, we can install the latest stable version of Nim:

$ choosenim stable
Downloading Nim 2.0.4 from nim-lang.org
...

$ nim -v
Nim Compiler Version 2.0.4 [Linux: amd64]
...

LLVM toolchain

Now that we have Nim installed, we need to install the LLVM toolchain. We'll use * clang* and lld to cross-compile to a UEFI environment.

$ sudo pacman -S clang lld
...

$ clang --version
clang version 18.0.0
...

$ ld.lld --version
LLD 18.0.0 (compatible with GNU linkers)

QEMU

Next, let's install QEMU so that we can test our OS:

$ sudo pacman -S qemu-desktop
...

$ qemu-system-x86_64 --version
QEMU emulator version 8.1.3
...

Creating the project

Now that we have our environment set up, we can create our project. We'll start by creating a new directory for our project:

$ mkdir fusion && cd fusion

Next, we'll create a new nimble project with binary package type:

$ nimble init
...
    Prompt: Package type?
        ... Library - provides functionality for other packages.
        ... Binary  - produces an executable for the end-user.
        ... Hybrid  - combination of library and binary
        ... For more information see https://goo.gl/cm2RX5
     Select Cycle with 'Tab', 'Enter' when done
    Answer: binary
...

Let's also create a build directory for our build artifacts and add it to .gitignore:

$ mkdir build
$ echo build >> .gitignore

Now that we have our project set up, let's move on to setting up our build to target the UEFI environment.

Last Updated:
Prev
Writing an OS in Nim
Next
Targeting UEFI (Part 1)