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.

Arc

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

cpu_context.Arc
const Arc = extern struct

File

lib/std/debug/cpu_context.zig:383

Code

const Arc = extern struct {
    /// The numbered general-purpose registers r0 - r31.
    r: [32]Gpr,
    pcl: Gpr,

    pub const Gpr = u32;

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

    pub fn getFp(ctx: *const Arc) usize {
        return ctx.r[27];
    }
    pub fn getPc(ctx: *const Arc) usize {
        return ctx.pcl;
    }

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

            32...57 => return error.UnsupportedRegister, // Extension Core Registers
            58...127 => return error.UnsupportedRegister, // Reserved
            128...159 => return error.UnsupportedRegister, // f0 - f31

            else => return error.InvalidRegister,
        }
    }
}