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; // present, R/W 24 static const uint64 kTableMappingFlags = 0x7; // present, R/W, user 25 static const uint64 kLargePageMappingFlags = 0x183; // present, R/W, user, global, large 26 static const uint64 kPageMappingFlags = 0x103; // present, R/W, user, global 27 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 extern addr_t mmu_map_physical_memory(addr_t physicalAddress, size_t size, uint32 flags); 34 extern void mmu_free(void *virtualAddress, size_t size); 35 36 extern void 37 mmu_post_efi_setup(UINTN memory_map_size, EFI_MEMORY_DESCRIPTOR *memory_map, UINTN descriptor_size, UINTN descriptor_version); 38 extern uint64_t 39 mmu_generate_post_efi_page_tables(UINTN memory_map_size, EFI_MEMORY_DESCRIPTOR *memory_map, UINTN descriptor_size, UINTN descriptor_version); 40 extern status_t 41 platform_kernel_address_to_bootloader_address(uint64_t address, void **_result); 42 extern status_t 43 platform_bootloader_address_to_kernel_address(void *address, uint64_t *_result); 44 45 #ifdef __cplusplus 46 } 47 #endif 48 49 50 /*! Convert a 32-bit address to a 64-bit address. */ 51 inline uint64 52 fix_address(uint64 address) 53 { 54 uint64 result; 55 if (platform_bootloader_address_to_kernel_address((void *)address, &result) != B_OK) 56 return address; 57 else 58 return result; 59 } 60 61 62 template<typename Type> 63 inline void 64 fix_address(FixedWidthPointer<Type>& p) 65 { 66 if (p != NULL) 67 p.SetTo(fix_address(p.Get())); 68 } 69 70 71 #endif // !_ASSEMBLER 72 73 #endif /* MMU_H */ 74