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 status_t platform_kernel_address_to_bootloader_address(addr_t address, 43 void **_result); 44 45 extern status_t platform_bootloader_address_to_kernel_address(void *address, 46 addr_t *_result); 47 48 #ifdef __cplusplus 49 } 50 #endif 51 52 53 /*! Convert a 32-bit address to a 64-bit address. */ 54 inline addr_t 55 fix_address(addr_t address) 56 { 57 addr_t result; 58 if (platform_bootloader_address_to_kernel_address((void *)address, &result) 59 != B_OK) { 60 return address; 61 } else 62 return result; 63 } 64 65 66 template<typename Type> 67 inline void 68 fix_address(FixedWidthPointer<Type>& p) 69 { 70 if (p != NULL) 71 p.SetTo(fix_address(p.Get())); 72 } 73 74 75 #endif // !_ASSEMBLER 76 77 #endif /* MMU_H */ 78