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 standard library.
std › debug › cpu_context › X86_16 Private Struct X86_16 Doc Source Private Struct std.debug.cpu_context.X86_16
const X86_16 = struct Fields Types Values Functions File debug/cpu_context.zig: 1731
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777 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 )),
8 => return @ptrCast (ctx .regs .getPtr (.ip )),
41 => return @ptrCast (ctx .regs .getPtr (.cs )),
42 => return @ptrCast (ctx .regs .getPtr (.ss )),
else => return error .InvalidRegister ,
}
}
}