1 /* 2 * Copyright 2014, Henry Harrington, henry.harrington@gmail.com. 3 * Copyright 2019-2020, Haiku, Inc. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef MMU_H 7 #define MMU_H 8 9 10 #ifndef _ASSEMBLER 11 12 13 #include "efi_platform.h" 14 15 #include <util/FixedWidthPointer.h> 16 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 static const uint32 kDefaultPageFlags = 0x3; 23 // present, R/W 24 static const uint64 kTableMappingFlags = 0x7; 25 // present, R/W, user 26 static const uint64 kLargePageMappingFlags = 0x183; 27 // present, R/W, user, global, large 28 static const uint64 kPageMappingFlags = 0x103; 29 // present, R/W, user, global 30 31 32 extern addr_t get_next_virtual_address(size_t size); 33 extern addr_t get_current_virtual_address(); 34 35 extern void mmu_init(); 36 37 extern phys_addr_t mmu_allocate_page(); 38 39 extern addr_t mmu_map_physical_memory(addr_t physicalAddress, size_t size, 40 uint32 flags); 41 42 extern void mmu_free(void *virtualAddress, size_t size); 43 44 extern status_t platform_kernel_address_to_bootloader_address(addr_t address, 45 void **_result); 46 47 extern status_t platform_bootloader_address_to_kernel_address(void *address, 48 addr_t *_result); 49 50 #ifdef __cplusplus 51 } 52 #endif 53 54 55 /*! Convert a 32-bit address to a 64-bit address. */ 56 inline addr_t 57 fix_address(addr_t address) 58 { 59 addr_t result; 60 if (platform_bootloader_address_to_kernel_address((void *)address, &result) 61 != B_OK) { 62 return address; 63 } else 64 return result; 65 } 66 67 68 template<typename Type> 69 inline void 70 fix_address(FixedWidthPointer<Type>& p) 71 { 72 if (p != NULL) 73 p.SetTo(fix_address(p.Get())); 74 } 75 76 77 #endif // !_ASSEMBLER 78 79 #endif /* MMU_H */ 80