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 | |
17 | void AddressableBits::SetAddressableBits(uint32_t addressing_bits) { |
18 | m_low_memory_addr_bits = m_high_memory_addr_bits = addressing_bits; |
19 | } |
20 | |
21 | void 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 | |
27 | void AddressableBits::SetLowmemAddressableBits( |
28 | uint32_t lowmem_addressing_bits) { |
29 | m_low_memory_addr_bits = lowmem_addressing_bits; |
30 | } |
31 | |
32 | uint32_t AddressableBits::GetLowmemAddressableBits() const { |
33 | return m_low_memory_addr_bits; |
34 | } |
35 | |
36 | void AddressableBits::SetHighmemAddressableBits( |
37 | uint32_t highmem_addressing_bits) { |
38 | m_high_memory_addr_bits = highmem_addressing_bits; |
39 | } |
40 | |
41 | uint32_t AddressableBits::GetHighmemAddressableBits() const { |
42 | return m_high_memory_addr_bits; |
43 | } |
44 | |
45 | addr_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 |