-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfio.zig
45 lines (39 loc) · 1.13 KB
/
fio.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
const builtin = @import("builtin");
const std = @import("std");
// Port IO
pub const port = switch (builtin.cpu.arch) {
.x86,
.x86_64,
=> @import("fio/port/x86.zig"),
else => struct {},
};
// Memory mapped IO
pub const mem = switch (builtin.os.tag) {
.linux => @import("fio/mem/linux.zig"),
else => @import("fio/mem/freestanding.zig"),
};
pub const IO = union(enum) {
port: u16,
mem: struct {
allocator: std.mem.Allocator,
address: usize,
},
pub inline fn read(self: IO, comptime T: type) T {
return switch (self) {
.port => |p| port.in(T, p),
.mem => |m| mem.read(T, m.allocator, m.address),
};
}
pub inline fn write(self: IO, data: anytype) void {
switch (self) {
.port => |p| port.out(p, data),
.mem => |m| mem.write(m.address, data),
}
}
};
pub const FwCfg = @import("fio/fw-cfg.zig");
pub const DeviceManager = @import("fio/devman.zig");
pub const Nvme = @import("fio/nvme.zig");
pub const pci = @import("fio/pci.zig");
pub const rtc = @import("fio/rtc.zig");
pub const uart = @import("fio/uart.zig");