summaryrefslogtreecommitdiffstats
path: root/include/arch/x86_64/page.h
blob: 4460720b971b26758f5eb6a513e5f423933920bd (plain) (blame)
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
#ifndef _JOVE_ARCH_x86_64_PAGE_H
#define _JOVE_ARCH_x86_64_PAGE_H 1

#include <stdint.h>
#include "include/object.h"

#define PAGE_PRESENT (1ULL << 0)
#define PAGE_RW (1ULL << 1)
#define PAGE_US (1ULL << 2)
#define PAGE_XD (1ULL << 63)

typedef union jove_PageMapLevelEntry
{
    struct {
        uint8_t p : 1; /* Present */
        uint8_t rw : 1; /* Read/write. 0 for RO.*/
        uint8_t us : 1; /* User/supervisor. 0 for DPL3 forbid */
        uint8_t pwt : 1;
        uint8_t pcd : 1;
        uint8_t a : 1; /* Accessed */
        uint8_t d : 1; /* Dirty */
        uint8_t ps_pat : 1;
        uint8_t g : 1; /* Global */
        uint8_t osflg : 2;
        uint8_t r : 1;
        uint64_t paddr : 35;
        uint8_t _r1;
        uint8_t pk : 4;
        uint8_t xd : 1;
    }__attribute__((packed));
    uint64_t value;
} __attribute__((packed)) pmle_t;

typedef uint16_t pmli_t;

#define PML_SHL(l) ((l * 9) + 3)
#define PML_I_FOR_LAYER(v, l) ((v >> PML_SHL(l)) % 512)

uintptr_t vmem_ident_tophys(void *vptr);
void *vmem_phys_tovirt(uintptr_t pptr);

void *pmle_get_page(pmle_t entry);
uint8_t pmle_level(pmle_t entry);

int untyped_retype_page(objdir_entry_t *untyped_entry, void **dest_ptr);

#endif