Browse documentation

Your first app

A minimal program that builds for DurgX.

Preview interface

The app developer kit (SDK) is not public yet. The snippets here show the shape of the interface described in the v0.1 specification. Names, numbers and signatures can change before release. For early access, write to [email protected].

1. Set up Rust

terminal
rustup toolchain install nightly --component rust-src
rustup target add x86_64-unknown-none --toolchain nightly
cargo new --bin hello-durgx && cd hello-durgx

2. Configure the project

Cargo.toml
[package]
name = "hello-durgx"
version = "0.1.0"
edition = "2021"

[dependencies]
libipc = "0.1"      # ring layouts shared with the kernel (SDK)

[profile.release]
panic = "abort"

3. Write the program

An app has no operating system under it to provide main. It defines its own entry point _start and its own panic handler. This one does nothing but politely give up the CPU in a loop.

src/main.rs
#![no_std]
#![no_main]

use core::arch::asm;
use core::panic::PanicInfo;

// The real numbers come with the SDK headers.
const SYS_YIELD: u64 = 0; // placeholder

#[inline(always)]
unsafe fn syscall0(nr: u64) -> u64 {
    let ret: u64;
    asm!(
        "syscall",
        inlateout("rax") nr => ret,
        lateout("rcx") _,
        lateout("r11") _,
        options(nostack),
    );
    ret
}

#[no_mangle]
pub extern "C" fn _start() -> ! {
    loop {
        // Give up the CPU so other tasks can run.
        unsafe { syscall0(SYS_YIELD) };
    }
}

#[panic_handler]
fn panic(_: &PanicInfo) -> ! {
    loop {}
}

4. Build

terminal
cargo +nightly build --release --target x86_64-unknown-none

5. Get it onto a DurgX image

Programs are loaded by a loader program that runs outside the kernel, and the packaging tool that adds your program to an image ships with the SDK. Until the SDK is public, email [email protected] and we will help you get your first app running.

Next