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