1// See LICENSE for license details.
2
3#ifndef _VM_H
4#define _VM_H
5
6#include "encoding.h"
7#include <stdint.h>
8
9#define MEGAPAGE_SIZE ((uintptr_t)(RISCV_PGSIZE << RISCV_PGLEVEL_BITS))
10#if __riscv_xlen == 64
11# define SATP_MODE_CHOICE INSERT_FIELD(0, SATP64_MODE, SATP_MODE_SV39)
12# define VA_BITS 39
13# define GIGAPAGE_SIZE (MEGAPAGE_SIZE << RISCV_PGLEVEL_BITS)
14#else
15# define SATP_MODE_CHOICE INSERT_FIELD(0, SATP32_MODE, SATP_MODE_SV32)
16# define VA_BITS 32
17#endif
18
19typedef uintptr_t pte_t;
20extern pte_t* root_page_table;
21
22static inline void flush_tlb()
23{
24  asm volatile ("sfence.vma");
25}
26
27static inline pte_t pte_create(uintptr_t ppn, int type)
28{
29  return (ppn << PTE_PPN_SHIFT) | PTE_V | type;
30}
31
32static inline pte_t ptd_create(uintptr_t ppn)
33{
34  return pte_create(ppn, PTE_V);
35}
36
37#endif
38