Skip to content

Commit e19000b

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 e19000b

21 files changed

+194
-270
lines changed

src/Makefile

+12-12
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,19 @@ DEFS+=-DJSON_HAS_FILESYSTEM=0
171171
DEFS+=-DBOOST_ASIO_DISABLE_THREADS -DBOOST_ASIO_DISABLE_EPOLL -DBOOST_ASIO_DISABLE_EVENTFD
172172

173173
ifeq ($(dump),yes)
174-
#DUMP_DEFS+=-DDUMP_ILLEGAL_INSN_EXCEPTIONS
175-
#DUMP_DEFS+=-DDUMP_EXCEPTIONS
176-
#DUMP_DEFS+=-DDUMP_INTERRUPTS
177-
#DUMP_DEFS+=-DDUMP_MMU_EXCEPTIONS
178-
#DUMP_DEFS+=-DDUMP_INVALID_CSR
179-
#DUMP_DEFS+=-DDUMP_REGS
180-
#DUMP_DEFS+=-DDUMP_INSN_HIST
181-
#DUMP_DEFS+=-DDUMP_STATS
174+
DUMP_DEFS+=-DDUMP_ILLEGAL_INSN_EXCEPTIONS
175+
DUMP_DEFS+=-DDUMP_EXCEPTIONS
176+
DUMP_DEFS+=-DDUMP_INTERRUPTS
177+
DUMP_DEFS+=-DDUMP_MMU_EXCEPTIONS
178+
DUMP_DEFS+=-DDUMP_INVALID_CSR
179+
DUMP_DEFS+=-DDUMP_REGS
180+
DUMP_DEFS+=-DDUMP_INSN_HIST
181+
DUMP_DEFS+=-DDUMP_STATS
182182
DUMP_DEFS+=-DDUMP_INSN
183-
#DUMP_DEFS+=-DDUMP_UARCH_INSN
184-
#DUMP_DEFS+=-DDUMP_SCOPED_NOTE
185-
#DUMP_DEFS+=-DDUMP_STATE_ACCESS
186-
#DUMP_DEFS+=-DDUMP_UARCH_STATE_ACCESS
183+
DUMP_DEFS+=-DDUMP_UARCH_INSN
184+
DUMP_DEFS+=-DDUMP_SCOPED_NOTE
185+
DUMP_DEFS+=-DDUMP_STATE_ACCESS
186+
DUMP_DEFS+=-DDUMP_UARCH_STATE_ACCESS
187187
endif
188188
DEFS += $(DUMP_DEFS)
189189
# Pass down UARCH_DEFS to sub-makefiles

src/address-range.h

+18-22
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
}
@@ -70,7 +69,8 @@ class address_range {
7069
constexpr virtual ~address_range() {}; // = default; // doesn't work due to bug in gcc
7170

7271
template <typename ABRT, size_t N, typename... ARGS>
73-
[[noreturn]] static void ABRTF(ABRT abrt, const char (&fmt)[N], ARGS... args) {
72+
[[noreturn]]
73+
static void ABRTF(ABRT abrt, const char (&fmt)[N], ARGS... args) {
7474
char buf[256]{};
7575
std::ignore = snprintf(buf, std::size(buf), fmt, args...);
7676
abrt(buf);
@@ -98,36 +98,29 @@ class address_range {
9898
m_description[i] = description[i];
9999
}
100100
// All address ranges must be page-aligned
101-
if ((m_length & ~AR_ISTART_START_MASK) != 0) {
102-
ABRTF(abrt, "length must be multiple of page size when initializing %s", m_description);
101+
if ((m_length & ~PMA_ISTART_START_MASK) != 0) {
102+
ABRTF(abrt, "length must be multiple of page size when initializing %s", description);
103103
}
104-
if ((m_start & ~AR_ISTART_START_MASK) != 0) {
105-
ABRTF(abrt, "start of %s (0x%" PRIx64 ") must be aligned to page boundary of %d bytes", m_description,
106-
start, AR_PAGE_SIZE);
104+
if ((m_start & ~PMA_ISTART_START_MASK) != 0) {
105+
ABRTF(abrt, "start of %s (0x%" PRIx64 ") must be aligned to page boundary of %" PRId64 " bytes",
106+
description, start, AR_PAGE_SIZE);
107107
}
108108
// It must be possible to round length up to the next power of two
109109
if (m_length_bit_ceil == 0) {
110-
ABRTF(abrt, "range too long when initializing %s", m_description);
110+
ABRTF(abrt, "address range too long when initializing %s", description);
111111
}
112112
// Empty range must really be empty
113113
if (m_length == 0) {
114114
if (m_start != 0) {
115-
ABRTF(abrt, "range with length 0 must start at 0 when initializing %s", m_description);
116-
}
117-
if (!m_flags.E) {
118-
ABRTF(abrt, "range with length 0 must be flagged empty when initializing %s", m_description);
115+
ABRTF(abrt, "range with length 0 must start at 0 when initializing %s", description);
119116
}
120117
if (m_flags.M) {
121-
ABRTF(abrt, "memory range cannot be empty when initializing %s", m_description);
118+
ABRTF(abrt, "memory address range cannot have length 0 when initializing %s", description);
122119
}
123120
if (m_flags.IO) {
124-
ABRTF(abrt, "device range cannot be empty when initializing %s", m_description);
121+
ABRTF(abrt, "device address range cannot have length 0 when initializing %s", description);
125122
}
126123
}
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-
}
131124
}
132125

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

179172
/// \brief Test if address range is occupied by memory
180173
/// \returns True if and only if range is occupied by memory
174+
/// \details In this case, get_host_memory() is guaranteed not to return nullptr.
181175
bool is_memory() const noexcept {
182176
return m_flags.M;
183177
}
184178

185179
/// \brief Test if address range is occupied by a device
186180
/// \returns True if and only if range is occupied by a device
181+
/// \details In this case, read_device() and write_device() are operational.
187182
bool is_device() const noexcept {
188183
return m_flags.IO;
189184
}
190185

191186
/// \brief Test if address range is empty
192187
/// \returns True if and only if range is empty
188+
/// \details Empty ranges should be used only for sentinels.
193189
bool is_empty() const noexcept {
194-
return m_flags.E;
190+
return m_length == 0;
195191
}
196192

197193
/// \brief Tests if range is readable
198-
/// \returns True if and only if range is readable
194+
/// \returns True if and only if range is readable from within the machine.
199195
bool is_readable() const noexcept {
200196
return m_flags.R;
201197
}
202198

203199
/// \brief Tests if range is writeable
204-
/// \returns True if and only if range is writeable
200+
/// \returns True if and only if range is writeable from within the machine.
205201
bool is_writeable() const noexcept {
206202
return m_flags.W;
207203
}
208204

209205
/// \brief Tests if range is executable
210-
/// \returns True if and only if range is executable
206+
/// \returns True if and only if range is executable from within the machine.
211207
bool is_executable() const noexcept {
212208
return m_flags.X;
213209
}

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)