Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

Lanai

This is an extern struct so that inline assembly in current can use field offsets.

cpu_context.Lanai
const Lanai = extern struct

File

lib/std/debug/cpu_context.zig:711

Code

const Lanai = extern struct {
    r: [32]Gpr,

    pub const Gpr = u32;

    pub inline fn current() Lanai {
        var ctx: Lanai = undefined;
        asm volatile (
            \\ st %%r0, 0[r9]
            \\ st %%r1, 4[r9]
            \\ st %%r2, 8[r9]
            \\ st %%r3, 12[r9]
            \\ st %%r4, 16[r9]
            \\ st %%r5, 20[r9]
            \\ st %%r6, 24[r9]
            \\ st %%r7, 28[r9]
            \\ st %%r8, 32[r9]
            \\ st %%r9, 36[r9]
            \\ st %%r10, 40[r9]
            \\ st %%r11, 44[r9]
            \\ st %%r12, 48[r9]
            \\ st %%r13, 52[r9]
            \\ st %%r14, 56[r9]
            \\ st %%r15, 60[r9]
            \\ st %%r16, 64[r9]
            \\ st %%r17, 68[r9]
            \\ st %%r18, 72[r9]
            \\ st %%r19, 76[r9]
            \\ st %%r20, 80[r9]
            \\ st %%r21, 84[r9]
            \\ st %%r22, 88[r9]
            \\ st %%r23, 92[r9]
            \\ st %%r24, 96[r9]
            \\ st %%r25, 100[r9]
            \\ st %%r26, 104[r9]
            \\ st %%r27, 108[r9]
            \\ st %%r28, 112[r9]
            \\ st %%r29, 116[r9]
            \\ st %%r30, 120[r9]
            \\ st %%r31, 124[r9]
            :
            : [ctx] "{r9}" (&ctx),
            : .{ .memory = true });
        return ctx;
    }

    pub fn getFp(ctx: *const Lanai) usize {
        return ctx.r[5];
    }
    pub fn getPc(ctx: *const Lanai) usize {
        return ctx.r[2];
    }

    pub fn dwarfRegisterBytes(ctx: *Lanai, register_num: u16) DwarfRegisterError![]u8 {
        switch (register_num) {
            0...31 => return @ptrCast(&ctx.s[register_num]),

            else => return error.InvalidRegister,
        }
    }
}