74 lines
2.0 KiB
Zig
74 lines
2.0 KiB
Zig
const std = @import("std");
|
|
const types = @import("types.zig");
|
|
|
|
const PixelType = @import("framebuffer.zig").PixelType;
|
|
|
|
pub const c = @cImport({
|
|
@cDefine("uint8_t", "unsigned char");
|
|
@cDefine("uint16_t", "unsigned short");
|
|
@cDefine("uint32_t", "unsigned int");
|
|
@cDefine("uint64_t", "unsigned long");
|
|
@cDefine("int8_t", "char");
|
|
@cDefine("int16_t", "short");
|
|
@cDefine("int32_t", "int");
|
|
@cDefine("int64_t", "long");
|
|
@cInclude("bootboot.h");
|
|
});
|
|
|
|
pub extern const bootboot: c.BOOTBOOT;
|
|
pub extern const environment: [4096]u8;
|
|
pub extern var fb: u32;
|
|
pub extern var mmio: u8;
|
|
|
|
pub fn memory_map() []align(1) const MemoryMapEntry {
|
|
const entry_count = (bootboot.size - 128) / @sizeOf(c.MMapEnt);
|
|
return @ptrCast([*]align(1) const MemoryMapEntry, &bootboot.mmap)[0..entry_count];
|
|
}
|
|
|
|
pub const MemoryMapEntry = extern struct {
|
|
const Self = @This();
|
|
comptime {
|
|
std.debug.assert(@sizeOf(@This()) == @sizeOf(c.MMapEnt));
|
|
}
|
|
|
|
_ptr: [*]u8,
|
|
_size: u64,
|
|
|
|
pub fn ptr(self: Self) [*]u8 {
|
|
return self._ptr;
|
|
}
|
|
|
|
pub fn size(self: Self) u64 {
|
|
return self._size & 0xfffffffffffffff0;
|
|
}
|
|
|
|
pub fn usage(self: Self) Usage {
|
|
return @intToEnum(Usage, @intCast(u4, self._size & 0xf));
|
|
}
|
|
|
|
const Usage = enum(u4) {
|
|
Used,
|
|
Free,
|
|
Acpi,
|
|
Mmio,
|
|
};
|
|
|
|
pub fn format(self: @This(), comptime fmt: []const u8, options: std.fmt.FormatOptions, context: var, comptime Errors: type, output: fn (@TypeOf(context), []const u8) Errors!void) Errors!void {
|
|
try std.fmt.format(context, Errors, output, "Memory {} size {} usage {}", .{
|
|
self.ptr(),
|
|
self.size(),
|
|
@tagName(self.usage()),
|
|
});
|
|
}
|
|
};
|
|
|
|
pub fn framebuffer_pixel_type() !PixelType {
|
|
return switch (bootboot.fb_type) {
|
|
c.FB_ARGB => PixelType.ARGB,
|
|
c.FB_RGBA => PixelType.RGBA,
|
|
c.FB_ABGR => PixelType.ABGR,
|
|
c.FB_BGRA => PixelType.BGRA,
|
|
else => return error.Unsupported,
|
|
};
|
|
}
|