switchboard-on-demand 0.8.0

A Rust library to interact with the Switchboard Solana program.
Documentation
// BPF Assembly using GNU assembler syntax
.section .text
.globl write_instruction_0_data_asm_extern
.type write_instruction_0_data_asm_extern, @function

write_instruction_0_data_asm_extern:
    // r1 = base_ptr, r2 = dst_ptr, r3 = dst_len

    // Step 1: Read offset at base+2 and calculate p = base + offset
    r4 = *(u16*)(r1 + 2)        // Load offset from base+2
    r4 += r1                    // p = base + offset

    // Step 2: Trap check - (*p | *p.add(1) == 0)
    r5 = *(u8*)(r4 + 0)         // Load *p
    r6 = *(u8*)(r4 + 1)         // Load *p.add(1)
    r5 |= r6                    // OR them together
    r6 = 1                      // Prepare for division
    r6 /= r5                    // Will trap if r5 == 0

    // Step 3: Read data length at p+34
    r0 = *(u16*)(r4 + 34)       // Load data_len, also return value

    // Step 4: Call sol_memcpy_(dst_ptr, src_ptr, len)
    r1 = r2                     // r1 = dst_ptr
    r2 = r4                     // r2 = p
    r2 += 36                    // r2 = p + 36 (src_ptr)
    r3 = r0                     // r3 = len
    call sol_memcpy_

    // r0 already contains the length to return
    exit

.size write_instruction_0_data_asm_extern, .-write_instruction_0_data_asm_extern