xref: /freebsd-src/contrib/llvm-project/lldb/source/Utility/AddressableBits.cpp (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
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/Target/Process.h"
11 #include "lldb/lldb-types.h"
12 
13 using namespace lldb;
14 using namespace lldb_private;
15 
16 void AddressableBits::SetAddressableBits(uint32_t addressing_bits) {
17   m_low_memory_addr_bits = m_high_memory_addr_bits = addressing_bits;
18 }
19 
20 void AddressableBits::SetAddressableBits(uint32_t lowmem_addressing_bits,
21                                          uint32_t highmem_addressing_bits) {
22   m_low_memory_addr_bits = lowmem_addressing_bits;
23   m_high_memory_addr_bits = highmem_addressing_bits;
24 }
25 
26 void AddressableBits::SetLowmemAddressableBits(
27     uint32_t lowmem_addressing_bits) {
28   m_low_memory_addr_bits = lowmem_addressing_bits;
29 }
30 
31 void AddressableBits::SetHighmemAddressableBits(
32     uint32_t highmem_addressing_bits) {
33   m_high_memory_addr_bits = highmem_addressing_bits;
34 }
35 
36 void AddressableBits::SetProcessMasks(Process &process) {
37   if (m_low_memory_addr_bits == 0 && m_high_memory_addr_bits == 0)
38     return;
39 
40   if (m_low_memory_addr_bits != 0) {
41     addr_t low_addr_mask = ~((1ULL << m_low_memory_addr_bits) - 1);
42     process.SetCodeAddressMask(low_addr_mask);
43     process.SetDataAddressMask(low_addr_mask);
44   }
45 
46   if (m_high_memory_addr_bits != 0) {
47     addr_t hi_addr_mask = ~((1ULL << m_high_memory_addr_bits) - 1);
48     process.SetHighmemCodeAddressMask(hi_addr_mask);
49     process.SetHighmemDataAddressMask(hi_addr_mask);
50   }
51 }
52