blob: 8a241706f46f0adf25acc86236f6fd871219d69b [file] [log] [blame]
// Copyright 2023 Google LLC.
#ifndef SW_DEVICE_LIB_VIRTUAL_MEMORY_H_
#define SW_DEVICE_LIB_VIRTUAL_MEMORY_H_
#include <stdbool.h>
#include <stdint.h>
#define PAGE_SIZE (0x1000)
// Add a page table entry for a megapage, which maps
// a 4MB region in virtual memory.
void machine_map_megapage(void *paddr, void *vaddr, uint32_t *pt);
// Generate 2-level page table entries to cover a specified region.
void machine_map_region(uint32_t paddr, uint32_t vaddr_start,
uint32_t vaddr_end, uint32_t *l1pt, uint32_t *l2pt,
bool user);
// Trampoline that writes the page table base, exception and interrupt
// delegation, and S-mode trap vector. Afterwards, returns into supervisor mode.
void supervisor_trampoline(uint32_t a0_smode_fn, uint32_t a1_satp,
uint32_t a2_medeleg, uint32_t a3_stvec,
uint32_t a4_mideleg);
// Trampoline that drops into U-mode, at the given address.
void user_trampoline(uint32_t a0_umode_fn);
#endif // SW_DEVICE_LIB_VIRTUAL_MEMORY_H_