Skip to content

Commit 01755d7

Browse files
committed
refactor: remove the E flag
This increases the space for DID Checking for empty address range simply checks its length. Shadow address ranges are neither device nor memory. This is because they cannot be read/written with read_device/write_device. They do not implement get_host_memory() either.
1 parent ba09c01 commit 01755d7

20 files changed

+176
-253
lines changed

src/address-range.h

+12-17
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class address_range {
5656
m_length{0},
5757
m_length_bit_ceil{0},
5858
m_flags{} {
59-
m_flags.E = true;
6059
for (unsigned i = 0; i < std::min<unsigned>(N, m_description.size() - 1); ++i) {
6160
m_description[i] = description[i];
6261
}
@@ -98,36 +97,29 @@ class address_range {
9897
m_description[i] = description[i];
9998
}
10099
// All address ranges must be page-aligned
101-
if ((m_length & ~AR_ISTART_START_MASK) != 0) {
100+
if ((m_length & ~PMA_ISTART_START_MASK) != 0) {
102101
ABRTF(abrt, "length must be multiple of page size when initializing %s", m_description);
103102
}
104-
if ((m_start & ~AR_ISTART_START_MASK) != 0) {
103+
if ((m_start & ~PMA_ISTART_START_MASK) != 0) {
105104
ABRTF(abrt, "start of %s (0x%" PRIx64 ") must be aligned to page boundary of %d bytes", m_description,
106105
start, AR_PAGE_SIZE);
107106
}
108107
// It must be possible to round length up to the next power of two
109108
if (m_length_bit_ceil == 0) {
110-
ABRTF(abrt, "range too long when initializing %s", m_description);
109+
ABRTF(abrt, "address range too long when initializing %s", m_description);
111110
}
112111
// Empty range must really be empty
113112
if (m_length == 0) {
114113
if (m_start != 0) {
115114
ABRTF(abrt, "range with length 0 must start at 0 when initializing %s", m_description);
116115
}
117-
if (!m_flags.E) {
118-
ABRTF(abrt, "range with length 0 must be flagged empty when initializing %s", m_description);
119-
}
120116
if (m_flags.M) {
121-
ABRTF(abrt, "memory range cannot be empty when initializing %s", m_description);
117+
ABRTF(abrt, "memory address range cannot have length 0 when initializing %s", m_description);
122118
}
123119
if (m_flags.IO) {
124-
ABRTF(abrt, "device range cannot be empty when initializing %s", m_description);
120+
ABRTF(abrt, "device address range cannot have length 0 when initializing %s", m_description);
125121
}
126122
}
127-
// Non-empty range must either be memory or device
128-
if (static_cast<int>(m_flags.M) + static_cast<int>(m_flags.IO) + static_cast<int>(m_flags.E) != 1) {
129-
ABRTF(abrt, "range must be one of empty, memory, or device when initializing %s", m_description);
130-
}
131123
}
132124

133125
/// \brief Checks if a range of addresses is entirely contained within this range
@@ -178,36 +170,39 @@ class address_range {
178170

179171
/// \brief Test if address range is occupied by memory
180172
/// \returns True if and only if range is occupied by memory
173+
/// \details In this case, get_host_memory() is guaranteed not to return nullptr.
181174
bool is_memory() const noexcept {
182175
return m_flags.M;
183176
}
184177

185178
/// \brief Test if address range is occupied by a device
186179
/// \returns True if and only if range is occupied by a device
180+
/// \details In this case, read_device() and write_device() are operational.
187181
bool is_device() const noexcept {
188182
return m_flags.IO;
189183
}
190184

191185
/// \brief Test if address range is empty
192186
/// \returns True if and only if range is empty
187+
/// \details Empty ranges should be used only for sentinels.
193188
bool is_empty() const noexcept {
194-
return m_flags.E;
189+
return m_length == 0;
195190
}
196191

197192
/// \brief Tests if range is readable
198-
/// \returns True if and only if range is readable
193+
/// \returns True if and only if range is readable from within the machine.
199194
bool is_readable() const noexcept {
200195
return m_flags.R;
201196
}
202197

203198
/// \brief Tests if range is writeable
204-
/// \returns True if and only if range is writeable
199+
/// \returns True if and only if range is writeable from within the machine.
205200
bool is_writeable() const noexcept {
206201
return m_flags.W;
207202
}
208203

209204
/// \brief Tests if range is executable
210-
/// \returns True if and only if range is executable
205+
/// \returns True if and only if range is executable from within the machine.
211206
bool is_executable() const noexcept {
212207
return m_flags.X;
213208
}

src/clint-address-range.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <cstdint>
2121

22+
#include "address-range-constants.h"
2223
#include "pristine-address-range.h"
2324

2425
/// \file
@@ -31,7 +32,6 @@ class clint_address_range final : public pristine_address_range {
3132
static constexpr pmas_flags m_clint_flags{
3233
.M = false,
3334
.IO = true,
34-
.E = false,
3535
.R = true,
3636
.W = true,
3737
.X = false,
@@ -42,8 +42,8 @@ class clint_address_range final : public pristine_address_range {
4242

4343
public:
4444
template <typename ABRT>
45-
clint_address_range(uint64_t start, uint64_t length, ABRT abrt) :
46-
pristine_address_range("CLINT device", start, length, m_clint_flags, abrt) {
45+
explicit clint_address_range(ABRT abrt) :
46+
pristine_address_range("CLINT device", AR_CLINT_START, AR_CLINT_LENGTH, m_clint_flags, abrt) {
4747
;
4848
}
4949

@@ -61,8 +61,8 @@ class clint_address_range final : public pristine_address_range {
6161
};
6262

6363
template <typename ABRT>
64-
static inline clint_address_range make_clint_address_range(uint64_t start, uint64_t length, ABRT abrt) {
65-
return clint_address_range{start, length, abrt};
64+
static inline clint_address_range make_clint_address_range(ABRT abrt) {
65+
return clint_address_range{abrt};
6666
}
6767

6868
} // namespace cartesi

src/find-pmas-entry.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ address_range &find_pma(const STATE_ACCESS a, uint64_t paddr, uint64_t &index) {
4040
// The pmas array always contain a sentinel.
4141
// It is an entry with zero length.
4242
// If we hit it, return it
43-
if (unlikely(ar.get_length() == 0)) {
43+
if (unlikely(ar.is_empty())) {
4444
return ar;
4545
}
4646
if (ar.contains_absolute(paddr, sizeof(T))) {

src/htif-address-range.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <cstdint>
2121

22+
#include "address-range-constants.h"
2223
#include "i-device-state-access.h"
2324
#include "pmas-constants.h"
2425
#include "pristine-address-range.h"
@@ -33,7 +34,6 @@ class htif_address_range final : public pristine_address_range {
3334
static constexpr pmas_flags m_htif_flags{
3435
.M = false,
3536
.IO = true,
36-
.E = false,
3737
.R = true,
3838
.W = true,
3939
.X = false,
@@ -44,8 +44,8 @@ class htif_address_range final : public pristine_address_range {
4444

4545
public:
4646
template <typename ABRT>
47-
htif_address_range(uint64_t start, uint64_t length, ABRT abrt) :
48-
pristine_address_range("HTIF device", start, length, m_htif_flags, abrt) {
47+
explicit htif_address_range(ABRT abrt) :
48+
pristine_address_range("HTIF device", AR_HTIF_START, AR_HTIF_LENGTH, m_htif_flags, abrt) {
4949
;
5050
}
5151

@@ -63,8 +63,8 @@ class htif_address_range final : public pristine_address_range {
6363
};
6464

6565
template <typename ABRT>
66-
static inline htif_address_range make_htif_address_range(uint64_t start, uint64_t length, ABRT abrt) {
67-
return htif_address_range{start, length, abrt};
66+
static inline htif_address_range make_htif_address_range(ABRT abrt) {
67+
return htif_address_range{abrt};
6868
}
6969

7070
} // namespace cartesi

0 commit comments

Comments
 (0)