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.

M68k

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

cpu_context.M68k
const M68k = extern struct

File

lib/std/debug/cpu_context.zig:881

Code

const M68k = extern struct {
    /// The numbered data registers d0 - d7.
    d: [8]Gpr,
    /// The numbered address registers a0 - a7.
    a: [8]Gpr,
    pc: Gpr,

    pub const Gpr = u32;

    pub inline fn current() M68k {
        var ctx: M68k = undefined;
        asm volatile (
            \\ movem.l %%d0 - %%a7, (%%a0)
            \\ lea.l (%%pc), %%a1
            \\ move.l %%a1, (%%a0, 64)
            :
            : [ctx] "{a0}" (&ctx),
            : .{ .a1 = true, .memory = true });
        return ctx;
    }

    pub fn getFp(ctx: *const M68k) usize {
        return ctx.a[6];
    }
    pub fn getPc(ctx: *const M68k) usize {
        return ctx.pc;
    }

    pub fn dwarfRegisterBytes(ctx: *M68k, register_num: u16) DwarfRegisterError![]u8 {
        switch (register_num) {
            0...7 => return @ptrCast(&ctx.d[register_num]),
            8...15 => return @ptrCast(&ctx.a[register_num - 8]),
            26 => return @ptrCast(&ctx.pc),

            16...23 => return error.UnsupportedRegister, // fp0 - fp7
            24...25 => return error.UnsupportedRegister, // Return columns in GCC...?

            else => return error.InvalidRegister,
        }
    }
}