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.

MemoryType

tables.MemoryType
pub const MemoryType = enum(u32)

File

lib/std/os/uefi/tables.zig:24

Code

pub const MemoryType = enum(u32) {
    pub const Oem = math.IntFittingRange(
        0,
        @backingInt(MemoryType.oem_end) - @backingInt(MemoryType.oem_start),
    );
    pub const Vendor = math.IntFittingRange(
        0,
        @backingInt(MemoryType.vendor_end) - @backingInt(MemoryType.vendor_start),
    );

    /// can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise
    reserved_memory_type,
    loader_code,
    loader_data,
    boot_services_code,
    boot_services_data,
    /// can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise
    runtime_services_code,
    /// can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise
    runtime_services_data,
    conventional_memory,
    unusable_memory,
    /// can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise
    acpi_reclaim_memory,
    /// can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise
    acpi_memory_nvs,
    memory_mapped_io,
    memory_mapped_io_port_space,
    pal_code,
    persistent_memory,
    unaccepted_memory,
    max_memory_type,
    invalid_start,
    invalid_end = 0x6FFFFFFF,
    /// MemoryType values in the range 0x70000000..0x7FFFFFFF are reserved for OEM use.
    oem_start = 0x70000000,
    oem_end = 0x7FFFFFFF,
    /// MemoryType values in the range 0x80000000..0xFFFFFFFF are reserved for use by UEFI
    /// OS loaders that are provided by operating system vendors.
    vendor_start = 0x80000000,
    vendor_end = 0xFFFFFFFF,
    _,

    pub fn fromOem(value: Oem) MemoryType {
        const oem_start = @backingInt(MemoryType.oem_start);
        return @fromBackingInt(@intCast(oem_start + value));
    }

    pub fn toOem(memtype: MemoryType) ?Oem {
        const as_int = @backingInt(memtype);
        const oem_start = @backingInt(MemoryType.oem_start);
        if (as_int < oem_start) return null;
        if (as_int > @backingInt(MemoryType.oem_end)) return null;
        return @truncate(as_int - oem_start);
    }

    pub fn fromVendor(value: Vendor) MemoryType {
        const vendor_start = @backingInt(MemoryType.vendor_start);
        return @fromBackingInt(@intCast(vendor_start + value));
    }

    pub fn toVendor(memtype: MemoryType) ?Vendor {
        const as_int = @backingInt(memtype);
        const vendor_start = @backingInt(MemoryType.vendor_start);
        if (as_int < @backingInt(MemoryType.vendor_end)) return null;
        if (as_int > @backingInt(MemoryType.vendor_end)) return null;
        return @truncate(as_int - vendor_start);
    }

    pub fn format(self: MemoryType, w: *std.Io.Writer) std.Io.Writer.Error!void {
        if (self.toOem()) |oemval|
            try w.print("OEM({X})", .{oemval})
        else if (self.toVendor()) |vendorval|
            try w.print("Vendor({X})", .{vendorval})
        else if (std.enums.tagName(MemoryType, self)) |name|
            try w.print("{s}", .{name})
        else
            try w.print("INVALID({X})", .{@backingInt(self)});
    }
}