github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/utils/address.c (about) 1 /* 2 * Copyright (c) 2013 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 #include "hw_includes.h" 16 #include "address.h" 17 18 19 static ADDRESS max_virtual_address; 20 static ADDRESS virtual_address_copmplement; 21 22 static UINT8 physical_address_size; 23 static UINT8 virtual_address_size; 24 25 extern UINT32 pw_reserved_bits_high_mask; 26 27 void addr_setup_address_space(void) 28 { 29 UINT32 value = hw_read_address_size(); 30 31 physical_address_size = (UINT8) (value & 0xFF); 32 virtual_address_size = (UINT8) ((value >> 8) & 0xFF); 33 max_virtual_address = ((ADDRESS) 1 << virtual_address_size) - 1;; 34 virtual_address_copmplement = ~(max_virtual_address >> 1);; 35 // bit mask to identify the reserved bits in paging structure high order address field 36 pw_reserved_bits_high_mask = ~((1 << (physical_address_size - 32)) - 1); 37 } 38 39 UINT8 addr_get_physical_address_size(void) 40 { 41 return physical_address_size; 42 } 43 44 #ifdef INCLUDE_UNUSED_CODE 45 UINT8 addr_get_virtual_address_size(void) 46 { 47 return virtual_address_size; 48 } 49 #endif 50 51 ADDRESS addr_canonize_address( 52 ADDRESS address) 53 { 54 if (address & virtual_address_copmplement) { 55 address |= virtual_address_copmplement; 56 } 57 return address; 58 } 59 BOOLEAN addr_is_canonical(ADDRESS address) 60 { 61 return addr_canonize_address(address) == address; 62 } 63 64 BOOLEAN addr_physical_is_valid(ADDRESS address) 65 { 66 ADDRESS phys_address_space = BIT_VALUE64((ADDRESS)(physical_address_size)); 67 return address < phys_address_space; 68 }