| 1 | /* |
| 2 | * Copyright (C) 2016 Veertu Inc, |
| 3 | * Copyright (C) 2017 Google Inc, |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #ifndef X86_MMU_H |
| 20 | #define X86_MMU_H |
| 21 | |
| 22 | #define PT_PRESENT (1 << 0) |
| 23 | #define PT_WRITE (1 << 1) |
| 24 | #define PT_USER (1 << 2) |
| 25 | #define PT_WT (1 << 3) |
| 26 | #define PT_CD (1 << 4) |
| 27 | #define PT_ACCESSED (1 << 5) |
| 28 | #define PT_DIRTY (1 << 6) |
| 29 | #define PT_PS (1 << 7) |
| 30 | #define PT_GLOBAL (1 << 8) |
| 31 | #define PT_NX (1llu << 63) |
| 32 | |
| 33 | typedef enum MMUTranslateFlags { |
| 34 | MMU_TRANSLATE_VALIDATE_WRITE = BIT(1), |
| 35 | MMU_TRANSLATE_VALIDATE_EXECUTE = BIT(2), |
| 36 | MMU_TRANSLATE_PRIV_CHECKS_EXEMPT = BIT(3) |
| 37 | } MMUTranslateFlags; |
| 38 | |
| 39 | typedef enum MMUTranslateResult { |
| 40 | MMU_TRANSLATE_SUCCESS = 0, |
| 41 | MMU_TRANSLATE_PAGE_NOT_MAPPED = 1, |
| 42 | MMU_TRANSLATE_PRIV_VIOLATION = 2, |
| 43 | MMU_TRANSLATE_INVALID_PT_FLAGS = 3, |
| 44 | MMU_TRANSLATE_GPA_UNMAPPED = 4, |
| 45 | MMU_TRANSLATE_GPA_NO_READ_ACCESS = 5, |
| 46 | MMU_TRANSLATE_GPA_NO_WRITE_ACCESS = 6 |
| 47 | } MMUTranslateResult; |
| 48 | |
| 49 | MMUTranslateResult mmu_gva_to_gpa(CPUState *cpu, target_ulong gva, uint64_t *gpa, MMUTranslateFlags flags); |
| 50 | |
| 51 | /* Thin wrappers x86_write_mem_ex/x86_read_mem_ex for code readability */ |
| 52 | MMUTranslateResult x86_write_mem(CPUState *cpu, void *data, target_ulong gva, int bytes); |
| 53 | MMUTranslateResult x86_read_mem(CPUState *cpu, void *data, target_ulong gva, int bytes); |
| 54 | |
| 55 | MMUTranslateResult x86_write_mem_priv(CPUState *cpu, void *data, target_ulong gva, int bytes); |
| 56 | MMUTranslateResult x86_read_mem_priv(CPUState *cpu, void *data, target_ulong gva, int bytes); |
| 57 | |
| 58 | |
| 59 | #endif /* X86_MMU_H */ |