Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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. Public Enum

MemoryType

Public Enum
std.os.uefi.tables.MemoryType
pub const MemoryType = enum(u32)

Values

Functions

pub fn fromOem(value: Oem) MemoryType
pub fn toOem(memtype: MemoryType) ?Oem
pub fn fromVendor(value: Vendor) MemoryType
pub fn toVendor(memtype: MemoryType) ?Vendor
pub fn format(self: MemoryType, w: *std.Io.Writer) std.Io.Writer.Error!void

File

os/uefi/tables.zig:24
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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)});
    }
}