1 //===-- AddressableBits.cpp -----------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Utility/AddressableBits.h" 10 #include "lldb/lldb-types.h" 11 12 #include <cassert> 13 14 using namespace lldb; 15 using namespace lldb_private; 16 SetAddressableBits(uint32_t addressing_bits)17void AddressableBits::SetAddressableBits(uint32_t addressing_bits) { 18 m_low_memory_addr_bits = m_high_memory_addr_bits = addressing_bits; 19 } 20 SetAddressableBits(uint32_t lowmem_addressing_bits,uint32_t highmem_addressing_bits)21void AddressableBits::SetAddressableBits(uint32_t lowmem_addressing_bits, 22 uint32_t highmem_addressing_bits) { 23 m_low_memory_addr_bits = lowmem_addressing_bits; 24 m_high_memory_addr_bits = highmem_addressing_bits; 25 } 26 SetLowmemAddressableBits(uint32_t lowmem_addressing_bits)27void AddressableBits::SetLowmemAddressableBits( 28 uint32_t lowmem_addressing_bits) { 29 m_low_memory_addr_bits = lowmem_addressing_bits; 30 } 31 GetLowmemAddressableBits() const32uint32_t AddressableBits::GetLowmemAddressableBits() const { 33 return m_low_memory_addr_bits; 34 } 35 SetHighmemAddressableBits(uint32_t highmem_addressing_bits)36void AddressableBits::SetHighmemAddressableBits( 37 uint32_t highmem_addressing_bits) { 38 m_high_memory_addr_bits = highmem_addressing_bits; 39 } 40 GetHighmemAddressableBits() const41uint32_t AddressableBits::GetHighmemAddressableBits() const { 42 return m_high_memory_addr_bits; 43 } 44 AddressableBitToMask(uint32_t addressable_bits)45addr_t AddressableBits::AddressableBitToMask(uint32_t addressable_bits) { 46 assert(addressable_bits <= sizeof(addr_t) * 8); 47 if (addressable_bits == 64) 48 return 0; // all bits used for addressing 49 else 50 return ~((1ULL << addressable_bits) - 1); 51 } 52