| /* |
| * Copyright 2023 Google LLC |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| |
| #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_ |