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.

X86_16

cpu_context.X86_16
const X86_16 = struct

File

lib/std/debug/cpu_context.zig:1721

Code

const X86_16 = struct {
    regs: std.enums.EnumArray(GprName, Gpr),

    pub const GprName = enum {
        // zig fmt: off
        sp, bp, ss,
        ip, cs,
        // zig fmt: on
    };
    pub const Gpr = u16;

    pub inline fn current() X86_16 {
        var ctx: X86_16 = undefined;
        asm volatile (
            \\ movw %%sp, 0x00(%%di)
            \\ movw %%bp, 0x02(%%di)
            \\ movw %%ss, 0x04(%%di)
            \\ pushw %%cs
            \\ call 1f
            \\1:
            \\ popw 0x06(%%di)
            \\ popw 0x08(%%di)
            :
            : [gprs] "{di}" (&ctx.regs.values),
            : .{ .memory = true });
        return ctx;
    }

    pub fn getFp(ctx: *const X86_16) usize {
        return ctx.regs.get(.bp);
    }
    pub fn getPc(ctx: *const X86_16) usize {
        return ctx.regs.get(.ip);
    }

    // NOTE: There doesn't seem to be any standard for DWARF x86-16 so we'll just reuse the ones for x86.
    pub fn dwarfRegisterBytes(ctx: *X86_16, register_num: u16) DwarfRegisterError![]u8 {
        switch (register_num) {
            4 => return @ptrCast(ctx.regs.getPtr(.sp)),
            5 => return @ptrCast(ctx.regs.getPtr(.bp)),
            6 => return @ptrCast(ctx.regs.getPtr(.ip)),
            41 => return @ptrCast(ctx.regs.getPtr(.cs)),
            42 => return @ptrCast(ctx.regs.getPtr(.ss)),
            else => return error.InvalidRegister,
        }
    }
}