-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm.h
64 lines (50 loc) · 1.27 KB
/
vm.h
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
#ifndef __VM_H__
#define __VM_H__
#include "csr.h"
#include "vm_defs.h"
extern uintptr_t runtime_va_start;
extern uintptr_t load_pa_start;
/* Loader is for Sv39 */
static inline uintptr_t satp_new(uintptr_t pa)
{
return (SATP_MODE | (pa >> RISCV_PAGE_BITS));
}
static inline uintptr_t __va(uintptr_t pa)
{
return (pa - load_pa_start) + EYRIE_LOAD_START;
}
static inline uintptr_t __pa(uintptr_t va)
{
return (va - EYRIE_LOAD_START) + load_pa_start;
}
static inline pte pte_create(uintptr_t ppn, int type)
{
return (pte)((ppn << PTE_PPN_SHIFT) | PTE_V | (type & PTE_FLAG_MASK) );
}
static inline pte pte_create_invalid(uintptr_t ppn, int type)
{
return (pte)((ppn << PTE_PPN_SHIFT) | (type & PTE_FLAG_MASK & ~PTE_V));
}
static inline pte ptd_create(uintptr_t ppn)
{
return pte_create(ppn, PTE_V);
}
static inline uintptr_t ppn(uintptr_t pa)
{
return pa >> RISCV_PAGE_BITS;
}
// this is identical to ppn, but separate it to avoid confusion between va/pa
static inline uintptr_t vpn(uintptr_t va)
{
return va >> RISCV_PAGE_BITS;
}
static inline uintptr_t pte_ppn(pte pte)
{
return pte >> PTE_PPN_SHIFT;
}
/* root page table */
extern pte root_page_table[];
/* page tables for loading physical memory */
extern pte load_l2_page_table[];
extern pte load_l3_page_table[];
#endif