-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.zig
68 lines (54 loc) · 2.61 KB
/
main.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
const uefi = @import("std").os.uefi;
const allocator = uefi.pool_allocator;
const ConfigurationTable = uefi.tables.ConfigurationTable;
const bufPrint = @import("std").fmt.bufPrint;
const eql = @import("std").meta.eql;
const ArrayList = @import("std").ArrayList;
const smbios = @import("smbios");
var con_out: *uefi.protocol.SimpleTextOutput = undefined;
pub fn main() void {
con_out = uefi.system_table.con_out.?;
_ = con_out.reset(false);
const number_of_table_entries = uefi.system_table.number_of_table_entries;
const configuration_table = uefi.system_table.configuration_table;
for (0..number_of_table_entries) |i| {
const system_table = configuration_table[i];
if (system_table.vendor_guid.eql(ConfigurationTable.smbios_table_guid)) {
const entrypoint_table = smbios.init_entrypoint(system_table.vendor_table);
entrypoint_table.debug_print(printf);
var offset: u32 = 0;
const structure_table_pointer: [*]u8 = @ptrFromInt(entrypoint_table.structure_table_address);
for (0..2) |_| {
const header = smbios.init_header(structure_table_pointer + offset);
header.debug_print(printf);
switch (header.type) {
1 => {
var strings = ArrayList([]u8).init(allocator);
defer strings.deinit();
const table = smbios.init_system_information(@constCast(&strings), structure_table_pointer[offset .. entrypoint_table.max_structure_size + offset]);
offset += table.body.length;
table.debug_print(printf);
offset += smbios.get_structure_end(structure_table_pointer[offset .. offset + entrypoint_table.max_structure_size]);
},
3 => {
var strings = ArrayList([]u8).init(allocator);
defer strings.deinit();
const table = smbios.init_system_enclosure(&strings, structure_table_pointer[offset .. entrypoint_table.max_structure_size + offset]);
table.debug_print(printf);
},
else => {},
}
}
}
}
}
fn puts(msg: []const u8) void {
for (msg) |c| {
const c_ = [2]u16{ c, 0 }; // work around https://github.com/ziglang/zig/issues/4372
_ = con_out.outputString(@ptrCast(&c_));
}
}
fn printf(comptime format: []const u8, args: anytype) void {
var buf: [256]u8 = undefined;
puts(bufPrint(&buf, format, args) catch "error\r\n");
}