1 // Copyright 2016 The Fuchsia Authors 2 // Copyright (c) 2014 Travis Geiselbrecht 3 // 4 // Use of this source code is governed by a MIT-style 5 // license that can be found in the LICENSE file or at 6 // https://opensource.org/licenses/MIT 7 8 #pragma once 9 10 #include <zircon/compiler.h> 11 #include <zircon/types.h> 12 13 // page fault flags 14 const uint VMM_PF_FLAG_WRITE = (1u << 0); 15 const uint VMM_PF_FLAG_USER = (1u << 1); 16 const uint VMM_PF_FLAG_GUEST = (1u << 2); 17 const uint VMM_PF_FLAG_INSTRUCTION = (1u << 3); 18 const uint VMM_PF_FLAG_NOT_PRESENT = (1u << 4); 19 const uint VMM_PF_FLAG_HW_FAULT = (1u << 5); // hardware is requesting a fault 20 const uint VMM_PF_FLAG_SW_FAULT = (1u << 6); // software fault 21 const uint VMM_PF_FLAG_FAULT_MASK = (VMM_PF_FLAG_HW_FAULT | VMM_PF_FLAG_SW_FAULT); 22 23 // convenience routine for converting page fault flags to a string vmm_pf_flags_to_string(uint pf_flags,char str[5])24static const char* vmm_pf_flags_to_string(uint pf_flags, char str[5]) { 25 str[0] = (pf_flags & VMM_PF_FLAG_WRITE) ? 'w' : 'r'; 26 str[1] = (pf_flags & VMM_PF_FLAG_USER) ? 'u' : ((pf_flags & VMM_PF_FLAG_GUEST) ? 'g' : 's'); 27 str[2] = (pf_flags & VMM_PF_FLAG_INSTRUCTION) ? 'i' : 'd'; 28 str[3] = (pf_flags & VMM_PF_FLAG_NOT_PRESENT) ? 'n' : 'p'; 29 str[4] = '\0'; 30 31 return str; 32 } 33 34 // page fault handler, called during page fault context, with interrupts enabled 35 zx_status_t vmm_page_fault_handler(vaddr_t addr, uint pf_flags); 36