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.

M88k

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

cpu_context.M88k
const M88k = extern struct

File

lib/std/debug/cpu_context.zig:924

Code

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

    pub const Gpr = u32;

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

    pub fn getFp(ctx: *const M88k) usize {
        return ctx.r[30];
    }
    pub fn getPc(ctx: *const M88k) usize {
        return ctx.xip;
    }

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

            32...63 => return error.UnsupportedRegister, // x0 - x31

            else => return error.InvalidRegister,
        }
    }
}