aboutsummaryrefslogtreecommitdiff
path: root/mirai/kagami/types/entry.zig
blob: 5fc7a8d3a5bcf5fa0129707510daccaedef27134 (plain)
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
//! Page Table Entry Type

const common = @import("../../../common/common.zig");
const paging_flags = common.constants.paging.flags;

pub const Entry = packed struct {
    present: bool = false,
    writable: bool = false,
    user_accessible: bool = false,
    write_through: bool = false,
    cache_disabled: bool = false,
    accessed: bool = false,
    dirty: bool = false,
    huge_page: bool = false,
    global: bool = false,
    available_low: u3 = 0,
    physical_address: u40 = 0,
    available_high: u11 = 0,
    no_execute: bool = false,

    pub fn is_present(self: Entry) bool {
        return self.present;
    }

    pub fn is_writable(self: Entry) bool {
        return self.writable;
    }

    pub fn is_user(self: Entry) bool {
        return self.user_accessible;
    }

    pub fn is_huge(self: Entry) bool {
        return self.huge_page;
    }

    pub fn get_physical_address(self: Entry) u64 {
        return @as(u64, self.physical_address) << 12;
    }

    pub fn set_physical_address(self: *Entry, address: u64) void {
        self.physical_address = @truncate(address >> 12);
    }

    pub fn clear(self: *Entry) void {
        self.* = Entry{};
    }

    pub fn from_raw(raw: u64) Entry {
        return @bitCast(raw);
    }

    pub fn to_raw(self: Entry) u64 {
        return @bitCast(self);
    }
};