Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ jobs:
tags: ${{ github.repository_owner }}/machine-emulator:devel.build
push: false
load: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
build-args: |
DEBUG=${{ (startsWith(github.ref, 'refs/tags/v') && 'no' || 'yes') }}
GIT_COMMIT=${GITHUB_SHA}
Expand All @@ -60,8 +58,6 @@ jobs:
tags: cartesi/machine-emulator:amd64_deb
push: false
load: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
build-args: |
DEBUG=${{ (startsWith(github.ref, 'refs/tags/v') && 'no' || 'yes') }}
GIT_COMMIT=${GITHUB_SHA}
Expand All @@ -82,8 +78,6 @@ jobs:
tags: cartesi/machine-emulator:arm64_deb
push: false
load: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
build-args: |
DEBUG=${{ (startsWith(github.ref, 'refs/tags/v') && 'no' || 'yes') }}
GIT_COMMIT=${GITHUB_SHA}
Expand Down Expand Up @@ -146,8 +140,6 @@ jobs:
tags: ${{ github.repository_owner }}/machine-emulator:builder
push: false
load: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
build-args: |
DEBUG=${{ (startsWith(github.ref, 'refs/tags/v') && 'no' || 'yes') }}
GIT_COMMIT=${GITHUB_SHA}
Expand All @@ -164,8 +156,6 @@ jobs:
tags: ${{ github.repository_owner }}/machine-emulator:devel
push: false
load: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
build-args: |
DEBUG=${{ (startsWith(github.ref, 'refs/tags/v') && 'no' || 'yes') }}
GIT_COMMIT=${GITHUB_SHA}
Expand Down Expand Up @@ -321,8 +311,6 @@ jobs:
tags: ${{ github.repository_owner }}/machine-emulator:builder
push: false
load: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
build-args: |
DEBUG=${{ (startsWith(github.ref, 'refs/tags/v') && 'no' || 'yes') }}
GIT_COMMIT=${GITHUB_SHA}
Expand All @@ -339,8 +327,6 @@ jobs:
tags: ${{ github.repository_owner }}/machine-emulator:devel
push: false
load: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
build-args: |
DEBUG=${{ (startsWith(github.ref, 'refs/tags/v') && 'no' || 'yes') }}
GIT_COMMIT=${GITHUB_SHA}
Expand Down Expand Up @@ -478,8 +464,6 @@ jobs:
tags: ${{ github.repository_owner }}/machine-emulator:devel
push: false
load: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
build-args: |
DEBUG=${{ (startsWith(github.ref, 'refs/tags/v') && 'no' || 'yes') }}
GIT_COMMIT=${GITHUB_SHA}
Expand Down Expand Up @@ -541,8 +525,6 @@ jobs:
tags: ${{ github.repository_owner }}/machine-emulator:builder
push: false
load: true
cache-from: type=gha,scope=debian-coverage
cache-to: type=gha,mode=max,scope=debian-coverage
build-args: |
GIT_COMMIT=${GITHUB_SHA}
DEBUG=yes
Expand Down Expand Up @@ -623,8 +605,6 @@ jobs:
tags: ${{ github.repository_owner }}/machine-emulator:builder
push: false
load: true
cache-from: type=gha,scope=debian-sanitize
cache-to: type=gha,mode=max,scope=debian-sanitize
build-args: |
DEBUG=yes
GIT_COMMIT=${GITHUB_SHA}
Expand Down Expand Up @@ -703,8 +683,6 @@ jobs:
platforms: linux/amd64,linux/arm64
tags: ${{ steps.docker_image_tags.outputs.tags }}
push: true
cache-from: type=gha,scope=debian
cache-to: type=gha,mode=max,scope=debian
build-args: |
DEBUG=${{ (startsWith(github.ref, 'refs/tags/v') && 'no' || 'yes') }}
GIT_COMMIT=${GITHUB_SHA}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.a
*.lib
*.wasm
*.TODO

build
pkg
Expand Down
11 changes: 5 additions & 6 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ HASH_LIBS=

#DEFS+= -DMT_ALL_DIRTY

WARNS=-Wall -Wextra -Wpedantic
C_WARNS=-Wall -Wextra -Wpedantic
CXX_WARNS=$(C_WARNS) -Wno-missing-field-initializers

# Place our include directories before the system's
INCS+= \
Expand Down Expand Up @@ -305,8 +306,8 @@ else
DEFS+=-DNO_THREADS
endif

CXXFLAGS+=$(OPTFLAGS) -std=gnu++20 -fvisibility=hidden -MMD $(PICCFLAGS) $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS)
CFLAGS+=$(OPTFLAGS) -std=gnu99 -fvisibility=hidden -MMD $(PICCFLAGS) $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS)
CXXFLAGS+=$(OPTFLAGS) -std=gnu++20 -fvisibility=hidden -MMD $(PICCFLAGS) $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(CXX_WARNS)
CFLAGS+=$(OPTFLAGS) -std=gnu99 -fvisibility=hidden -MMD $(PICCFLAGS) $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(C_WARNS)
LDFLAGS+=$(UBFLAGS)

ifeq ($(coverage),yes)
Expand Down Expand Up @@ -357,14 +358,12 @@ LIBCARTESI_OBJS:= \
machine.o \
memory-address-range.o \
os.o \
os-mmap.o \
plic-address-range.o \
pristine-merkle-tree.o \
replay-step-state-access-interop.o \
send-cmio-response.o \
sha3.o \
shadow-state-address-range.o \
shadow-tlb-address-range.o \
shadow-uarch-state-address-range.o \
uarch-pristine-hash.o \
uarch-pristine-ram.o \
uarch-pristine-state-hash.o \
Expand Down
22 changes: 14 additions & 8 deletions src/address-range-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ namespace cartesi {

/// \brief Fixed address ranges.
enum AR_ranges : uint64_t {
AR_SHADOW_STATE_START = EXPAND_UINT64_C(AR_SHADOW_STATE_START_DEF), ///< Start of shadow state range
AR_SHADOW_STATE_LENGTH = EXPAND_UINT64_C(AR_SHADOW_STATE_LENGTH_DEF), ///< Length of shadow state range
AR_PMAS_START = EXPAND_UINT64_C(AR_PMAS_START_DEF), ///< Start of PMAS list range
AR_PMAS_LENGTH = EXPAND_UINT64_C(AR_PMAS_LENGTH_DEF), ///< Length of PMAS list range
AR_DTB_START = EXPAND_UINT64_C(AR_DTB_START_DEF), ///< Start of DTB range
AR_DTB_LENGTH = EXPAND_UINT64_C(AR_DTB_LENGTH_DEF), ///< Length of DTB range
AR_SHADOW_TLB_START = EXPAND_UINT64_C(AR_SHADOW_TLB_START_DEF), ///< Start of shadow TLB range
AR_SHADOW_TLB_LENGTH = EXPAND_UINT64_C(AR_SHADOW_TLB_LENGTH_DEF), ///< Length of shadow TLB range
AR_SHADOW_STATE_START = EXPAND_UINT64_C(AR_SHADOW_STATE_START_DEF), ///< Start of shadow state range
AR_SHADOW_STATE_LENGTH = EXPAND_UINT64_C(AR_SHADOW_STATE_LENGTH_DEF), ///< Length of shadow state range
AR_SHADOW_REGISTERS_START = EXPAND_UINT64_C(AR_SHADOW_REGISTERS_START_DEF), ///< Start of shadow registers range
AR_SHADOW_REGISTERS_LENGTH = EXPAND_UINT64_C(AR_SHADOW_REGISTERS_LENGTH_DEF), ///< Length of shadow registers range
AR_SHADOW_TLB_START = EXPAND_UINT64_C(AR_SHADOW_TLB_START_DEF), ///< Start of shadow TLB range
AR_SHADOW_TLB_LENGTH = EXPAND_UINT64_C(AR_SHADOW_TLB_LENGTH_DEF), ///< Length of shadow TLB range
AR_PMAS_START = EXPAND_UINT64_C(AR_PMAS_START_DEF), ///< Start of PMAS list range
AR_PMAS_LENGTH = EXPAND_UINT64_C(AR_PMAS_LENGTH_DEF), ///< Length of PMAS list range
AR_DTB_START = EXPAND_UINT64_C(AR_DTB_START_DEF), ///< Start of DTB range
AR_DTB_LENGTH = EXPAND_UINT64_C(AR_DTB_LENGTH_DEF), ///< Length of DTB range
AR_SHADOW_UARCH_STATE_START =
EXPAND_UINT64_C(AR_SHADOW_UARCH_STATE_START_DEF), ///< Start of uarch shadow state range
AR_SHADOW_UARCH_STATE_LENGTH =
Expand Down Expand Up @@ -61,6 +63,10 @@ enum AR_ranges : uint64_t {
AR_RAM_START = EXPAND_UINT64_C(AR_RAM_START_DEF), ///< Start of RAM range
};

static_assert(AR_SHADOW_STATE_LENGTH >= AR_SHADOW_REGISTERS_LENGTH + AR_SHADOW_TLB_LENGTH);
static_assert(AR_SHADOW_TLB_START == AR_SHADOW_REGISTERS_START + AR_SHADOW_REGISTERS_LENGTH);
static_assert(AR_SHADOW_STATE_START == AR_SHADOW_REGISTERS_START);

/// \brief PMA constants.
enum AR_constants : uint64_t {
AR_PAGE_SIZE_LOG2 = EXPAND_UINT64_C(AR_PAGE_SIZE_LOG2_DEF), ///< Log<sub>2</sub> of physical memory page size.
Expand Down
8 changes: 5 additions & 3 deletions src/address-range-defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

// NOLINTBEGIN(cppcoreguidelines-macro-usage,cppcoreguidelines-macro-to-enum,modernize-macro-to-enum)
#define AR_SHADOW_STATE_START_DEF 0x0 ///< Shadow start address
#define AR_SHADOW_STATE_LENGTH_DEF 0x1000 ///< Shadow length in bytes
#define AR_SHADOW_STATE_LENGTH_DEF 0x8000 ///< Shadow length in bytes
#define AR_SHADOW_REGISTERS_START_DEF 0x0 ///< Shadow registers start address
#define AR_SHADOW_REGISTERS_LENGTH_DEF 0x1000 ///< Shadow registers length in bytes
#define AR_SHADOW_TLB_START_DEF 0x1000 ///< Shadow TLB start address
#define AR_SHADOW_TLB_LENGTH_DEF 0x6000 ///< Shadow TLB length in bytes
#define AR_PMAS_START_DEF 0x10000 ///< PMA Array start address
#define AR_PMAS_LENGTH_DEF 0x1000 ///< PMA Array length in bytes
#define AR_SHADOW_TLB_START_DEF 0x20000 ///< TLB start address
#define AR_SHADOW_TLB_LENGTH_DEF 0x6000 ///< TLB length in bytes
#define AR_SHADOW_UARCH_STATE_START_DEF 0x400000 ///< microarchitecture shadow state start address
#define AR_SHADOW_UARCH_STATE_LENGTH_DEF 0x1000 ///< microarchitecture shadow state length
#define AR_UARCH_RAM_START_DEF 0x600000 ///< microarchitecture RAM start address
Expand Down
34 changes: 34 additions & 0 deletions src/address-range.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ class address_range {
return m_flags.IW;
}

/// \brief Tests if range can be replaced
/// \returns True if and only if range can be replaced
bool is_replaceable() const noexcept {
switch (m_flags.DID) {
case PMA_ISTART_DID::memory:
case PMA_ISTART_DID::flash_drive:
case PMA_ISTART_DID::cmio_rx_buffer:
case PMA_ISTART_DID::cmio_tx_buffer:
return true;
default:
return false;
}
}

/// \brief Returns driver ID associated to range
/// \returns Teh driver ID
PMA_ISTART_DID get_driver_id() const noexcept {
Expand Down Expand Up @@ -327,6 +341,18 @@ class address_range {
return do_is_page_marked_dirty(offset);
}

/// \brief Returns true if the mapped memory is read-only on the host
/// \returns True if the memory is read-only in the host
bool is_host_read_only() const noexcept {
return do_is_host_read_only();
}

/// \brief Returns true if pages marked as dirty once are uncleanable
/// \returns True if and only if dirty pages are uncleanable
bool is_page_uncleanable() const noexcept {
return do_is_page_uncleanable();
}

private:
// Default implementation of peek() always fails
virtual bool do_peek(const machine & /*m*/, uint64_t /*offset*/, uint64_t /*length*/,
Expand Down Expand Up @@ -371,6 +397,14 @@ class address_range {
virtual bool do_is_page_marked_dirty(uint64_t /*offset*/) const noexcept {
return true;
}

virtual bool do_is_host_read_only() const noexcept {
return false;
}

virtual bool do_is_page_uncleanable() const noexcept {
return false;
}
};

template <size_t N>
Expand Down
Loading