From 803fc4638c5685e9a137990603e955e5c0dd68f8 Mon Sep 17 00:00:00 2001 From: Diego Nehab <1635557+diegonehab@users.noreply.github.com> Date: Sun, 2 Mar 2025 13:07:41 +0000 Subject: [PATCH] refactor: split PMA and AR constants PMA is only used for the two-word description of address ranges in memory All other constants use AR (for address range) Also simplified machine::read_memory() --- src/Makefile | 24 +- src/address-range-constants.h | 77 ++++++ src/address-range-defines.h | 58 +++++ src/address-range.h | 22 +- src/clint-address-range.cpp | 4 +- src/clint-address-range.h | 2 +- src/clua-cartesi.cpp | 10 +- src/dtb.cpp | 38 +-- src/{find-pma-entry.h => find-pmas-entry.h} | 0 src/htif-address-range.h | 4 +- src/i-state-access.h | 2 +- src/interpret.cpp | 2 +- src/machine-c-api.cpp | 14 +- src/machine-c-api.h | 14 +- src/machine-config.cpp | 14 +- src/machine.cpp | 263 ++++++++++---------- src/machine.h | 2 +- src/memory-address-range.cpp | 8 +- src/memory-address-range.h | 14 +- src/mock-address-range.h | 8 +- src/plic-address-range.cpp | 10 +- src/plic-address-range.h | 2 +- src/plic-constants.h | 1 + src/pma-constants.h | 126 ---------- src/pma-defines.h | 71 ------ src/pmas-address-range.h | 4 +- src/pmas-constants.h | 77 ++++++ src/pmas-defines.h | 41 +++ src/{pma.h => pmas.h} | 65 ++--- src/pristine-address-range.h | 2 +- src/record-step-state-access.h | 6 +- src/replay-step-state-access.h | 31 ++- src/riscv-constants.h | 69 ++--- src/send-cmio-response.cpp | 6 +- src/shadow-state-address-range.h | 2 +- src/shadow-state.h | 218 ++++++++-------- src/shadow-tlb-address-range.h | 2 +- src/shadow-tlb-factory.h | 2 +- src/shadow-tlb.h | 8 +- src/shadow-uarch-state-address-range.cpp | 4 +- src/shadow-uarch-state-address-range.h | 2 +- src/shadow-uarch-state.h | 74 +++--- src/state-access.h | 2 +- src/tlb.h | 2 +- src/translate-virtual-address.h | 2 +- src/uarch-constants.h | 16 +- src/uarch-defines.h | 4 +- src/virtio-address-range.cpp | 2 +- src/virtio-address-range.h | 2 +- tests/lua/htif-cmio.lua | 8 +- tests/lua/machine-bind.lua | 73 +++--- tests/lua/machine-test.lua | 4 +- tests/machine/src/access.S | 4 +- tests/machine/src/bootstrap.S | 4 +- tests/machine/src/clint_ops.S | 26 +- tests/machine/src/compressed.S | 4 +- tests/machine/src/csr_counters.S | 4 +- tests/machine/src/csr_semantics.S | 4 +- tests/machine/src/dont_write_x0.S | 4 +- tests/machine/src/ebreak.S | 4 +- tests/machine/src/htif_cmio.S | 9 +- tests/machine/src/htif_console.S | 2 +- tests/machine/src/htif_invalid_ops.S | 20 +- tests/machine/src/htif_util.h | 4 +- tests/machine/src/htif_yield.S | 6 +- tests/machine/src/illegal_insn.S | 4 +- tests/machine/src/interrupts.S | 6 +- tests/machine/src/lrsc_semantics.S | 6 +- tests/machine/src/mcycle_overflow.S | 4 +- tests/machine/src/mcycle_write.S | 4 +- tests/machine/src/mtime_interrupt.S | 6 +- tests/machine/src/pte_reserved_exception.S | 4 +- tests/machine/src/sd_pma_overflow.S | 4 +- tests/machine/src/shadow_ops.S | 26 +- tests/machine/src/translate_vaddr.S | 4 +- tests/machine/src/version_check.S | 4 +- tests/machine/src/xpie_exceptions.S | 4 +- tests/misc/test-machine-c-api.cpp | 6 +- uarch/compute-uarch-pristine-hash.cpp | 14 +- uarch/machine-uarch-bridge-state-access.h | 7 +- uarch/uarch-ram-entry.S | 6 +- uarch/uarch-ram.ld.in | 12 +- 82 files changed, 886 insertions(+), 848 deletions(-) create mode 100644 src/address-range-constants.h create mode 100644 src/address-range-defines.h rename src/{find-pma-entry.h => find-pmas-entry.h} (100%) delete mode 100644 src/pma-constants.h delete mode 100644 src/pma-defines.h create mode 100644 src/pmas-constants.h create mode 100644 src/pmas-defines.h rename src/{pma.h => pmas.h} (73%) diff --git a/src/Makefile b/src/Makefile index f0e818cde..45c5552a7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -171,19 +171,19 @@ DEFS+=-DJSON_HAS_FILESYSTEM=0 DEFS+=-DBOOST_ASIO_DISABLE_THREADS -DBOOST_ASIO_DISABLE_EPOLL -DBOOST_ASIO_DISABLE_EVENTFD ifeq ($(dump),yes) -DUMP_DEFS+=-DDUMP_ILLEGAL_INSN_EXCEPTIONS -DUMP_DEFS+=-DDUMP_EXCEPTIONS -DUMP_DEFS+=-DDUMP_INTERRUPTS -DUMP_DEFS+=-DDUMP_MMU_EXCEPTIONS -DUMP_DEFS+=-DDUMP_INVALID_CSR -DUMP_DEFS+=-DDUMP_REGS -DUMP_DEFS+=-DDUMP_INSN_HIST -DUMP_DEFS+=-DDUMP_STATS +#DUMP_DEFS+=-DDUMP_ILLEGAL_INSN_EXCEPTIONS +#DUMP_DEFS+=-DDUMP_EXCEPTIONS +#DUMP_DEFS+=-DDUMP_INTERRUPTS +#DUMP_DEFS+=-DDUMP_MMU_EXCEPTIONS +#DUMP_DEFS+=-DDUMP_INVALID_CSR +#DUMP_DEFS+=-DDUMP_REGS +#DUMP_DEFS+=-DDUMP_INSN_HIST +#DUMP_DEFS+=-DDUMP_STATS DUMP_DEFS+=-DDUMP_INSN -DUMP_DEFS+=-DDUMP_UARCH_INSN -DUMP_DEFS+=-DDUMP_SCOPED_NOTE -DUMP_DEFS+=-DDUMP_STATE_ACCESS -DUMP_DEFS+=-DDUMP_UARCH_STATE_ACCESS +#DUMP_DEFS+=-DDUMP_UARCH_INSN +#DUMP_DEFS+=-DDUMP_SCOPED_NOTE +#DUMP_DEFS+=-DDUMP_STATE_ACCESS +#DUMP_DEFS+=-DDUMP_UARCH_STATE_ACCESS endif DEFS += $(DUMP_DEFS) # Pass down UARCH_DEFS to sub-makefiles diff --git a/src/address-range-constants.h b/src/address-range-constants.h new file mode 100644 index 000000000..1c4fdb65f --- /dev/null +++ b/src/address-range-constants.h @@ -0,0 +1,77 @@ +// Copyright Cartesi and individual authors (see AUTHORS) +// SPDX-License-Identifier: LGPL-3.0-or-later +// +// This program is free software: you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) any +// later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License along +// with this program (see COPYING). If not, see . +// + +#ifndef ADDRESS_RANGE_CONSTANTS_H +#define ADDRESS_RANGE_CONSTANTS_H + +#include + +#include "address-range-defines.h" + +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_UARCH_STATE_START = + EXPAND_UINT64_C(AR_SHADOW_UARCH_STATE_START_DEF), ///< Start of uarch shadow state range + AR_SHADOW_UARCH_STATE_LENGTH = + EXPAND_UINT64_C(AR_SHADOW_UARCH_STATE_LENGTH_DEF), ///< Length of uarch shadow state range + AR_CLINT_START = EXPAND_UINT64_C(AR_CLINT_START_DEF), ///< Start of CLINT range + AR_CLINT_LENGTH = EXPAND_UINT64_C(AR_CLINT_LENGTH_DEF), ///< Length of CLINT range + AR_PLIC_START = EXPAND_UINT64_C(AR_PLIC_START_DEF), ///< Start of PLIC range + AR_PLIC_LENGTH = EXPAND_UINT64_C(AR_PLIC_LENGTH_DEF), ///< Length of PLIC range + AR_HTIF_START = EXPAND_UINT64_C(AR_HTIF_START_DEF), ///< Start of HTIF range + AR_HTIF_LENGTH = EXPAND_UINT64_C(AR_HTIF_LENGTH_DEF), ///< Length of HTIF range + AR_UARCH_RAM_START = EXPAND_UINT64_C(AR_UARCH_RAM_START_DEF), ///< Start of uarch RAM range + AR_UARCH_RAM_LENGTH = EXPAND_UINT64_C(AR_UARCH_RAM_LENGTH_DEF), ///< Length of uarch RAM range + AR_CMIO_RX_BUFFER_START = EXPAND_UINT64_C(AR_CMIO_RX_BUFFER_START_DEF), ///< Start of CMIO RX buffer range + AR_CMIO_RX_BUFFER_LOG2_SIZE = EXPAND_UINT64_C(AR_CMIO_RX_BUFFER_LOG2_SIZE_DEF), ///< Log2 of CMIO RX buffer range + AR_CMIO_RX_BUFFER_LENGTH = (UINT64_C(1) << AR_CMIO_RX_BUFFER_LOG2_SIZE_DEF), ///< Length of CMIO RX buffer range + AR_CMIO_TX_BUFFER_START = EXPAND_UINT64_C(AR_CMIO_TX_BUFFER_START_DEF), ///< Start of CMIO TX buffer range + AR_CMIO_TX_BUFFER_LOG2_SIZE = EXPAND_UINT64_C(AR_CMIO_TX_BUFFER_LOG2_SIZE_DEF), ///< Log2 of CMIO TX buffer range + AR_CMIO_TX_BUFFER_LENGTH = (UINT64_C(1) << AR_CMIO_TX_BUFFER_LOG2_SIZE_DEF), ///< Length of CMIO TX buffer range + AR_DRIVE_START = EXPAND_UINT64_C(AR_DRIVE_START_DEF), ///< Start address for flash drive ranges + AR_DRIVE_OFFSET = EXPAND_UINT64_C(AR_DRIVE_OFFSET_DEF), ///< Offset for extra flash drive ranges + + AR_FIRST_VIRTIO_START = EXPAND_UINT64_C(AR_FIRST_VIRTIO_START_DEF), ///< Start of first VIRTIO range + AR_VIRTIO_LENGTH = EXPAND_UINT64_C(AR_VIRTIO_LENGTH_DEF), ///< Length of each VIRTIO range + AR_LAST_VIRTIO_END = EXPAND_UINT64_C(AR_LAST_VIRTIO_END_DEF), ///< End of last VIRTIO range + + AR_RAM_START = EXPAND_UINT64_C(AR_RAM_START_DEF), ///< Start of RAM range +}; + +/// \brief PMA constants. +enum AR_constants : uint64_t { + AR_PAGE_SIZE_LOG2 = EXPAND_UINT64_C(AR_PAGE_SIZE_LOG2_DEF), ///< Log2 of physical memory page size. + AR_PAGE_SIZE = (UINT64_C(1) << AR_PAGE_SIZE_LOG2_DEF), ///< Physical memory page size. +}; + +/// \brief PMA masks. +enum AR_masks : uint64_t { + AR_ADDRESSABLE_MASK = ((UINT64_C(1) << 56) - 1) ///< Mask for addressable ranges. +}; + +} // namespace cartesi + +#endif diff --git a/src/address-range-defines.h b/src/address-range-defines.h new file mode 100644 index 000000000..4f49e9141 --- /dev/null +++ b/src/address-range-defines.h @@ -0,0 +1,58 @@ +// Copyright Cartesi and individual authors (see AUTHORS) +// SPDX-License-Identifier: LGPL-3.0-or-later +// +// This program is free software: you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) any +// later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License along +// with this program (see COPYING). If not, see . +// + +#ifndef AR_DEFINES_H +#define AR_DEFINES_H + +// 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_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 +#define AR_UARCH_RAM_LENGTH_DEF 0x200000 ///< microarchitecture RAM length +#define AR_CLINT_START_DEF 0x2000000 ///< CLINT start address +#define AR_CLINT_LENGTH_DEF 0xC0000 ///< CLINT length in bytes +#define AR_PLIC_START_DEF 0x40100000 ///< Start of PLIC range +#define AR_PLIC_LENGTH_DEF 0x00400000 ///< Length of PLIC range +#define AR_HTIF_START_DEF 0x40008000 ///< HTIF base address (to_host) +#define AR_HTIF_LENGTH_DEF 0x1000 ///< HTIF length in bytes +#define AR_FIRST_VIRTIO_START_DEF 0x40010000 ///< Start of first VIRTIO range +#define AR_VIRTIO_LENGTH_DEF 0x1000 ///< Length of each VIRTIO range +#define AR_LAST_VIRTIO_END_DEF 0x40020000 ///< End of last VIRTIO range +#define AR_DTB_START_DEF 0x7ff00000 ///< DTB start address +#define AR_DTB_LENGTH_DEF 0x100000 ///< DTB length in bytes +#define AR_CMIO_RX_BUFFER_START_DEF 0x60000000 ///< CMIO RX buffer start address +#define AR_CMIO_RX_BUFFER_LOG2_SIZE_DEF 21 ///< log2 of CMIO RX buffer length in bytes +#define AR_CMIO_TX_BUFFER_START_DEF 0x60800000 ///< CMIO TX buffer start address +#define AR_CMIO_TX_BUFFER_LOG2_SIZE_DEF 21 ///< log2 of CMIO TX buffer length in bytes +#define AR_DRIVE_START_DEF 0x80000000000000 ///< Start PMA address for flash drives +#define AR_DRIVE_OFFSET_DEF 0x10000000000000 ///< PMA offset for extra flash drives + +#define AR_RAM_START_DEF 0x80000000 ///< RAM start address + +#define AR_PAGE_SIZE_LOG2_DEF 12 ///< log2 of physical memory page size. + +// helper for using UINT64_C with defines +#ifndef EXPAND_UINT64_C +#define EXPAND_UINT64_C(a) UINT64_C(a) +#endif +// NOLINTEND(cppcoreguidelines-macro-usage,cppcoreguidelines-macro-to-enum,modernize-macro-to-enum) +#endif /* end of include guard: AR_DEFINES_H */ diff --git a/src/address-range.h b/src/address-range.h index 58ca773f3..354e5f80b 100644 --- a/src/address-range.h +++ b/src/address-range.h @@ -26,7 +26,7 @@ #include "assert-printf.h" #include "i-device-state-access.h" #include "interpret.h" -#include "pma.h" +#include "pmas.h" namespace cartesi { @@ -44,7 +44,7 @@ class address_range { uint64_t m_start; ///< Target physical address where range starts. uint64_t m_length; ///< Length of range, in bytes. uint64_t m_length_bit_ceil; ///< Smallest power of 2 that is not smaller than length, in bytes. - pma_flags m_flags; ///< Physical memory attribute flags for range. + pmas_flags m_flags; ///< Physical memory attribute flags for range. public: /// \brief Noexcept constexpr constructor for empty ranges with description @@ -84,7 +84,7 @@ class address_range { /// \param length Length of range, in bytes /// \param f Phyical memory attribute flags for range template - address_range(const char *description, uint64_t start, uint64_t length, const pma_flags &flags, ABRT abrt) : + address_range(const char *description, uint64_t start, uint64_t length, const pmas_flags &flags, ABRT abrt) : m_description{}, m_start{start}, m_length{length}, @@ -98,12 +98,12 @@ class address_range { m_description[i] = description[i]; } // All address ranges must be page-aligned - if ((m_length & ~PMA_ISTART_START_MASK) != 0) { + if ((m_length & ~AR_ISTART_START_MASK) != 0) { ABRTF(abrt, "length must be multiple of page size when initializing %s", m_description); } - if ((m_start & ~PMA_ISTART_START_MASK) != 0) { + if ((m_start & ~AR_ISTART_START_MASK) != 0) { ABRTF(abrt, "start of %s (0x%" PRIx64 ") must be aligned to page boundary of %d bytes", m_description, - start, PMA_PAGE_SIZE); + start, AR_PAGE_SIZE); } // It must be possible to round length up to the next power of two if (m_length_bit_ceil == 0) { @@ -148,7 +148,7 @@ class address_range { /// \brief Returns PMA flags used during construction /// \returns Flags - const pma_flags &get_flags() const noexcept { + const pmas_flags &get_flags() const noexcept { return m_flags; } @@ -233,7 +233,7 @@ class address_range { /// \brief Returns packed address range istart field as per whitepaper /// \returns Packed address range istart uint64_t get_istart() const noexcept { - return pma_pack_istart(m_flags, m_start); + return pmas_pack_istart(m_flags, m_start); } /// \brief Returns encoded addres range ilength field as per whitepaper @@ -306,9 +306,9 @@ class address_range { /// \param offset Start of range of interest, relative to start of this range /// \param length Length of range of interest, in bytes void mark_dirty_pages(uint64_t offset, uint64_t length) noexcept { - auto offset_aligned = offset &= ~(PMA_PAGE_SIZE - 1); + auto offset_aligned = offset &= ~(AR_PAGE_SIZE - 1); const auto length_aligned = length + (offset - offset_aligned); - for (; offset_aligned < length_aligned; offset_aligned += PMA_PAGE_SIZE) { + for (; offset_aligned < length_aligned; offset_aligned += AR_PAGE_SIZE) { mark_dirty_page(offset_aligned); } } @@ -383,7 +383,7 @@ constexpr static auto make_empty_address_range(const char (&description)[N]) { } template -static inline auto make_address_range(const char *description, uint64_t start, uint64_t length, pma_flags f, +static inline auto make_address_range(const char *description, uint64_t start, uint64_t length, pmas_flags f, ABRT abrt) { return address_range{description, start, length, f, abrt}; } diff --git a/src/clint-address-range.cpp b/src/clint-address-range.cpp index 4622fa42e..9ffeb0416 100644 --- a/src/clint-address-range.cpp +++ b/src/clint-address-range.cpp @@ -20,7 +20,7 @@ #include "i-device-state-access.h" #include "interpret.h" -#include "pma-constants.h" +#include "pmas-constants.h" #include "riscv-constants.h" #include "rtc.h" @@ -43,7 +43,7 @@ static constexpr auto clint_mtime_rel_addr = static_cast(clint_csr::mt constexpr auto clint_mtimecmp_rel_addr = static_cast(clint_csr::mtimecmp); static constexpr uint64_t base(uint64_t v) { - return v - (v % PMA_PAGE_SIZE); + return v - (v % AR_PAGE_SIZE); } static bool clint_read_msip(i_device_state_access *a, uint64_t *val, int log2_size) { diff --git a/src/clint-address-range.h b/src/clint-address-range.h index b1d46aef0..96b024075 100644 --- a/src/clint-address-range.h +++ b/src/clint-address-range.h @@ -28,7 +28,7 @@ namespace cartesi { class clint_address_range final : public pristine_address_range { - static constexpr pma_flags m_clint_flags{ + static constexpr pmas_flags m_clint_flags{ .M = false, .IO = true, .E = false, diff --git a/src/clua-cartesi.cpp b/src/clua-cartesi.cpp index 232638c87..f39ee3250 100644 --- a/src/clua-cartesi.cpp +++ b/src/clua-cartesi.cpp @@ -220,11 +220,11 @@ CM_API int luaopen_cartesi(lua_State *L) { clua_setintegerfield(L, CM_CMIO_YIELD_MANUAL_REASON_TX_EXCEPTION, "CMIO_YIELD_MANUAL_REASON_TX_EXCEPTION", -1); clua_setintegerfield(L, CM_CMIO_YIELD_REASON_ADVANCE_STATE, "CMIO_YIELD_REASON_ADVANCE_STATE", -1); clua_setintegerfield(L, CM_CMIO_YIELD_REASON_INSPECT_STATE, "CMIO_YIELD_REASON_INSPECT_STATE", -1); - clua_setintegerfield(L, CM_PMA_CMIO_RX_BUFFER_START, "PMA_CMIO_RX_BUFFER_START", -1); - clua_setintegerfield(L, CM_PMA_CMIO_RX_BUFFER_LOG2_SIZE, "PMA_CMIO_RX_BUFFER_LOG2_SIZE", -1); - clua_setintegerfield(L, CM_PMA_CMIO_TX_BUFFER_START, "PMA_CMIO_TX_BUFFER_START", -1); - clua_setintegerfield(L, CM_PMA_CMIO_TX_BUFFER_LOG2_SIZE, "PMA_CMIO_TX_BUFFER_LOG2_SIZE", -1); - clua_setintegerfield(L, CM_PMA_RAM_START, "PMA_RAM_START", -1); + clua_setintegerfield(L, CM_AR_CMIO_RX_BUFFER_START, "AR_CMIO_RX_BUFFER_START", -1); + clua_setintegerfield(L, CM_AR_CMIO_RX_BUFFER_LOG2_SIZE, "AR_CMIO_RX_BUFFER_LOG2_SIZE", -1); + clua_setintegerfield(L, CM_AR_CMIO_TX_BUFFER_START, "AR_CMIO_TX_BUFFER_START", -1); + clua_setintegerfield(L, CM_AR_CMIO_TX_BUFFER_LOG2_SIZE, "AR_CMIO_TX_BUFFER_LOG2_SIZE", -1); + clua_setintegerfield(L, CM_AR_RAM_START, "AR_RAM_START", -1); // Set other constants used by internal tests clua_setintegerfield(L, UARCH_STATE_START_ADDRESS, "UARCH_STATE_START_ADDRESS", -1); clua_setintegerfield(L, UARCH_STATE_LOG2_SIZE, "UARCH_STATE_LOG2_SIZE", -1); diff --git a/src/dtb.cpp b/src/dtb.cpp index 5d0914896..7024fd3ad 100644 --- a/src/dtb.cpp +++ b/src/dtb.cpp @@ -24,10 +24,12 @@ #include #include +#include "address-range-constants.h" #include "fdt-builder.h" #include "machine-c-version.h" #include "machine-config.h" -#include "pma-constants.h" +#include "plic-constants.h" +#include "pmas-constants.h" #include "riscv-constants.h" #include "rng-seed.h" #include "rtc.h" @@ -119,38 +121,38 @@ void dtb_init(const machine_config &c, unsigned char *dtb_start, uint64_t dtb_le fdt.prop_string("compatible", "ucbbar,riscvemu-bar-soc\0simple-bus"s); fdt.prop_empty("ranges"); { // clint - fdt.begin_node_num("clint", PMA_CLINT_START); + fdt.begin_node_num("clint", AR_CLINT_START); fdt.prop_string("compatible", "riscv,clint0"); - fdt.prop_u64_list<2>("reg", {PMA_CLINT_START, PMA_CLINT_LENGTH}); + fdt.prop_u64_list<2>("reg", {AR_CLINT_START, AR_CLINT_LENGTH}); fdt.prop_u32_list<4>("interrupts-extended", {INTC_PHANDLE, MIP_MSIP_SHIFT, INTC_PHANDLE, MIP_MTIP_SHIFT}); fdt.end_node(); } { // plic - fdt.begin_node_num("plic", PMA_PLIC_START); + fdt.begin_node_num("plic", AR_PLIC_START); fdt.prop_u32("#interrupt-cells", 1); fdt.prop_empty("interrupt-controller"); fdt.prop_string("compatible", "riscv,plic0"); - fdt.prop_u32("riscv,ndev", PMA_PLIC_MAX_IRQ); - fdt.prop_u64_list<2>("reg", {PMA_PLIC_START, PMA_PLIC_LENGTH}); + fdt.prop_u32("riscv,ndev", PLIC_MAX_IRQ); + fdt.prop_u64_list<2>("reg", {AR_PLIC_START, AR_PLIC_LENGTH}); fdt.prop_u32_list<4>("interrupts-extended", {INTC_PHANDLE, MIP_SEIP_SHIFT, INTC_PHANDLE, MIP_MEIP_SHIFT}); fdt.prop_u32("phandle", PLIC_PHANDLE); fdt.end_node(); } { // htif - fdt.begin_node_num("htif", PMA_HTIF_START); + fdt.begin_node_num("htif", AR_HTIF_START); fdt.prop_string("compatible", "ucb,htif0"); - fdt.prop_u64_list<2>("reg", {PMA_HTIF_START, PMA_HTIF_LENGTH}); + fdt.prop_u64_list<2>("reg", {AR_HTIF_START, AR_HTIF_LENGTH}); fdt.prop_u32_list<2>("interrupts-extended", {INTC_PHANDLE, X_HOST}); fdt.end_node(); } for (uint32_t virtio_idx = 0; virtio_idx < c.virtio.size(); ++virtio_idx) { // virtio - const uint64_t virtio_paddr = PMA_FIRST_VIRTIO_START + (virtio_idx * PMA_VIRTIO_LENGTH); + const uint64_t virtio_paddr = AR_FIRST_VIRTIO_START + (virtio_idx * AR_VIRTIO_LENGTH); const uint32_t plic_irq_id = virtio_idx + 1; fdt.begin_node_num("virtio", virtio_paddr); fdt.prop_string("compatible", "virtio,mmio"); - fdt.prop_u64_list<2>("reg", {virtio_paddr, PMA_VIRTIO_LENGTH}); + fdt.prop_u64_list<2>("reg", {virtio_paddr, AR_VIRTIO_LENGTH}); fdt.prop_u32_list<2>("interrupts-extended", {PLIC_PHANDLE, plic_irq_id}); fdt.end_node(); } @@ -158,9 +160,9 @@ void dtb_init(const machine_config &c, unsigned char *dtb_start, uint64_t dtb_le } { // memory - fdt.begin_node_num("memory", PMA_RAM_START); + fdt.begin_node_num("memory", AR_RAM_START); fdt.prop_string("device_type", "memory"); - fdt.prop_u64_list<2>("reg", {PMA_RAM_START, c.ram.length}); + fdt.prop_u64_list<2>("reg", {AR_RAM_START, c.ram.length}); fdt.end_node(); } @@ -170,8 +172,8 @@ void dtb_init(const machine_config &c, unsigned char *dtb_start, uint64_t dtb_le fdt.prop_u32("#size-cells", 2); fdt.prop_empty("ranges"); { // reserve 256KB for firmware M-mode code (such as OpenSBI) - fdt.begin_node_num("fw_resv", PMA_RAM_START); - fdt.prop_u64_list<2>("reg", {PMA_RAM_START, 0x40000}); + fdt.begin_node_num("fw_resv", AR_RAM_START); + fdt.prop_u64_list<2>("reg", {AR_RAM_START, 0x40000}); fdt.prop_empty("no-map"); fdt.end_node(); } @@ -193,13 +195,13 @@ void dtb_init(const machine_config &c, unsigned char *dtb_start, uint64_t dtb_le fdt.prop_u32("#size-cells", 2); fdt.prop_string("compatible", "ctsi-cmio"); { // rx_buffer - fdt.begin_node_num("rx_buffer", PMA_CMIO_RX_BUFFER_START); - fdt.prop_u64_list<2>("reg", {PMA_CMIO_RX_BUFFER_START, PMA_CMIO_RX_BUFFER_LENGTH}); + fdt.begin_node_num("rx_buffer", AR_CMIO_RX_BUFFER_START); + fdt.prop_u64_list<2>("reg", {AR_CMIO_RX_BUFFER_START, AR_CMIO_RX_BUFFER_LENGTH}); fdt.end_node(); } { // tx_buffer - fdt.begin_node_num("tx_buffer", PMA_CMIO_TX_BUFFER_START); - fdt.prop_u64_list<2>("reg", {PMA_CMIO_TX_BUFFER_START, PMA_CMIO_TX_BUFFER_LENGTH}); + fdt.begin_node_num("tx_buffer", AR_CMIO_TX_BUFFER_START); + fdt.prop_u64_list<2>("reg", {AR_CMIO_TX_BUFFER_START, AR_CMIO_TX_BUFFER_LENGTH}); fdt.end_node(); } fdt.end_node(); diff --git a/src/find-pma-entry.h b/src/find-pmas-entry.h similarity index 100% rename from src/find-pma-entry.h rename to src/find-pmas-entry.h diff --git a/src/htif-address-range.h b/src/htif-address-range.h index d7fd5cde8..c19ec87e5 100644 --- a/src/htif-address-range.h +++ b/src/htif-address-range.h @@ -20,7 +20,7 @@ #include #include "i-device-state-access.h" -#include "pma-constants.h" +#include "pmas-constants.h" #include "pristine-address-range.h" /// \file @@ -30,7 +30,7 @@ namespace cartesi { class htif_address_range final : public pristine_address_range { - static constexpr pma_flags m_htif_flags{ + static constexpr pmas_flags m_htif_flags{ .M = false, .IO = true, .E = false, diff --git a/src/i-state-access.h b/src/i-state-access.h index 4fc9bbb25..9af18c05f 100644 --- a/src/i-state-access.h +++ b/src/i-state-access.h @@ -270,7 +270,7 @@ class i_state_access { // CRTP address_range &read_pma(uint64_t index) const { auto &ar = derived().do_read_pma(index); DSA_PRINTF("%s::read_address_range(%" PRIu64 ") = {%s, 0x%" PRIx64 ", 0x%" PRIx64 "}\n", get_name(), index, - pma_get_DID_name(ar.get_driver_id()), ar.get_start(), ar.get_length()); + pmas_get_DID_name(ar.get_driver_id()), ar.get_start(), ar.get_length()); return ar; } diff --git a/src/interpret.cpp b/src/interpret.cpp index 282344f4b..30507daa7 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -103,7 +103,7 @@ #include "compiler-defines.h" #include "device-state-access.h" #include "dump.h" -#include "find-pma-entry.h" +#include "find-pmas-entry.h" #include "i-accept-counters.h" #include "i-interactive-state-access.h" #include "i-state-access.h" diff --git a/src/machine-c-api.cpp b/src/machine-c-api.cpp index 2209b22e0..3e00b7244 100644 --- a/src/machine-c-api.cpp +++ b/src/machine-c-api.cpp @@ -44,14 +44,14 @@ #include "machine-runtime-config.h" #include "machine.h" #include "os-features.h" -#include "pma-defines.h" +#include "pmas-defines.h" #include "virtual-machine.h" -static_assert(PMA_CMIO_RX_BUFFER_START_DEF == CM_PMA_CMIO_RX_BUFFER_START); -static_assert(PMA_CMIO_RX_BUFFER_LOG2_SIZE_DEF == CM_PMA_CMIO_RX_BUFFER_LOG2_SIZE); -static_assert(PMA_CMIO_TX_BUFFER_START_DEF == CM_PMA_CMIO_TX_BUFFER_START); -static_assert(PMA_CMIO_TX_BUFFER_LOG2_SIZE_DEF == CM_PMA_CMIO_TX_BUFFER_LOG2_SIZE); -static_assert(PMA_RAM_START_DEF == CM_PMA_RAM_START); +static_assert(AR_CMIO_RX_BUFFER_START_DEF == CM_AR_CMIO_RX_BUFFER_START); +static_assert(AR_CMIO_RX_BUFFER_LOG2_SIZE_DEF == CM_AR_CMIO_RX_BUFFER_LOG2_SIZE); +static_assert(AR_CMIO_TX_BUFFER_START_DEF == CM_AR_CMIO_TX_BUFFER_START); +static_assert(AR_CMIO_TX_BUFFER_LOG2_SIZE_DEF == CM_AR_CMIO_TX_BUFFER_LOG2_SIZE); +static_assert(AR_RAM_START_DEF == CM_AR_RAM_START); static_assert(HTIF_YIELD_AUTOMATIC_REASON_PROGRESS_DEF == CM_CMIO_YIELD_AUTOMATIC_REASON_PROGRESS); static_assert(HTIF_YIELD_AUTOMATIC_REASON_TX_OUTPUT_DEF == CM_CMIO_YIELD_AUTOMATIC_REASON_TX_OUTPUT); @@ -1036,7 +1036,7 @@ cm_error cm_receive_cmio_request(const cm_machine *m, uint8_t *cmd, uint16_t *re if (data_length > *length) { throw std::invalid_argument{"data buffer length is too small"}; } - cpp_m->read_memory(cartesi::PMA_CMIO_TX_BUFFER_START, data, data_length); + cpp_m->read_memory(cartesi::AR_CMIO_TX_BUFFER_START, data, data_length); } } if (cmd != nullptr) { diff --git a/src/machine-c-api.h b/src/machine-c-api.h index 515863261..590db3769 100644 --- a/src/machine-c-api.h +++ b/src/machine-c-api.h @@ -51,13 +51,13 @@ typedef enum cm_constant { } cm_constant; /// \brief Physical memory addresses (only the most useful are exposed in the API). -typedef enum cm_pma_constant { - CM_PMA_CMIO_RX_BUFFER_START = 0x60000000, - CM_PMA_CMIO_RX_BUFFER_LOG2_SIZE = 21, - CM_PMA_CMIO_TX_BUFFER_START = 0x60800000, - CM_PMA_CMIO_TX_BUFFER_LOG2_SIZE = 21, - CM_PMA_RAM_START = 0x80000000, -} cm_pma_constant; +typedef enum cm_pmas_constant { + CM_AR_CMIO_RX_BUFFER_START = 0x60000000, + CM_AR_CMIO_RX_BUFFER_LOG2_SIZE = 21, + CM_AR_CMIO_TX_BUFFER_START = 0x60800000, + CM_AR_CMIO_TX_BUFFER_LOG2_SIZE = 21, + CM_AR_RAM_START = 0x80000000, +} cm_pmas_constant; /// \brief Error codes returned from the C API. typedef enum cm_error { diff --git a/src/machine-config.cpp b/src/machine-config.cpp index c52a6118d..cfd5f28b5 100644 --- a/src/machine-config.cpp +++ b/src/machine-config.cpp @@ -29,7 +29,7 @@ #include #include "json-util.h" -#include "pma-constants.h" +#include "pmas-constants.h" static constexpr uint32_t archive_version = 5; @@ -50,17 +50,17 @@ std::string machine_config::get_config_filename(const std::string &dir) { } static void adjust_image_filenames(machine_config &c, const std::string &dir) { - c.dtb.image_filename = machine_config::get_image_filename(dir, PMA_DTB_START, PMA_DTB_LENGTH); - c.ram.image_filename = machine_config::get_image_filename(dir, PMA_RAM_START, c.ram.length); - c.tlb.image_filename = machine_config::get_image_filename(dir, PMA_SHADOW_TLB_START, PMA_SHADOW_TLB_LENGTH); + c.dtb.image_filename = machine_config::get_image_filename(dir, AR_DTB_START, AR_DTB_LENGTH); + c.ram.image_filename = machine_config::get_image_filename(dir, AR_RAM_START, c.ram.length); + c.tlb.image_filename = machine_config::get_image_filename(dir, AR_SHADOW_TLB_START, AR_SHADOW_TLB_LENGTH); for (auto &f : c.flash_drive) { f.image_filename = machine_config::get_image_filename(dir, f); } - c.uarch.ram.image_filename = machine_config::get_image_filename(dir, PMA_UARCH_RAM_START, PMA_UARCH_RAM_LENGTH); + c.uarch.ram.image_filename = machine_config::get_image_filename(dir, AR_UARCH_RAM_START, AR_UARCH_RAM_LENGTH); c.cmio.rx_buffer.image_filename = - machine_config::get_image_filename(dir, PMA_CMIO_RX_BUFFER_START, PMA_CMIO_RX_BUFFER_LENGTH); + machine_config::get_image_filename(dir, AR_CMIO_RX_BUFFER_START, AR_CMIO_RX_BUFFER_LENGTH); c.cmio.tx_buffer.image_filename = - machine_config::get_image_filename(dir, PMA_CMIO_TX_BUFFER_START, PMA_CMIO_TX_BUFFER_LENGTH); + machine_config::get_image_filename(dir, AR_CMIO_TX_BUFFER_START, AR_CMIO_TX_BUFFER_LENGTH); } machine_config machine_config::load(const std::string &dir) { diff --git a/src/machine.cpp b/src/machine.cpp index b45f36432..a869e6390 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -54,8 +54,8 @@ #include "machine-runtime-config.h" #include "memory-address-range.h" #include "plic-address-range.h" -#include "pma.h" #include "pmas-address-range.h" +#include "pmas.h" #include "record-send-cmio-state-access.h" #include "record-step-state-access.h" #include "replay-send-cmio-state-access.h" @@ -104,7 +104,7 @@ static const auto throw_invalid_argument = [](const char *err) { throw std::inva /// \param shared If true, changes to memory range reflect in backing file. /// \returns New address range with flags already set. /// \details If \p image_filename is non-empty, return a memory-mapped range, otherwise use calloc. -static inline auto make_memory_address_range(const std::string &d, uint64_t start, uint64_t length, pma_flags flags, +static inline auto make_memory_address_range(const std::string &d, uint64_t start, uint64_t length, pmas_flags flags, const std::string &image_filename, bool shared) { if (image_filename.empty() && shared) { throw std::invalid_argument{"shared address range requires non-empty image filename when initializing " + d}; @@ -125,7 +125,7 @@ void machine::check_address_range(const address_range &ar, register_where where) const auto start = ar.get_start(); const auto length = ar.get_length(); // Checks if new range is machine addressable space (safe unsigned overflows) - if (start > PMA_ADDRESSABLE_MASK || (length > 0 && (length - 1) > (PMA_ADDRESSABLE_MASK - start))) { + if (start > AR_ADDRESSABLE_MASK || (length > 0 && (length - 1) > (AR_ADDRESSABLE_MASK - start))) { throw std::invalid_argument{ "address range of "s + ar.get_description() + " must use at most 56 bits to be addressable"s}; } @@ -179,14 +179,14 @@ void machine::init_uarch(const uarch_config &c) { write_reg(machine_reg_enum(reg::uarch_x0, i), c.processor.x[i]); } // Register shadow state - m_us.shadow_state = ®ister_address_range(make_shadow_uarch_state_address_range(PMA_SHADOW_UARCH_STATE_START, - PMA_SHADOW_UARCH_STATE_LENGTH, throw_invalid_argument), + m_us.shadow_state = ®ister_address_range(make_shadow_uarch_state_address_range(AR_SHADOW_UARCH_STATE_START, + AR_SHADOW_UARCH_STATE_LENGTH, throw_invalid_argument), register_where{.merkle = true, .interpret = false}); // Register RAM - if (uarch_pristine_ram_len > PMA_UARCH_RAM_LENGTH) { + if (uarch_pristine_ram_len > AR_UARCH_RAM_LENGTH) { throw std::runtime_error("embedded uarch RAM image does not fit in uarch memory"); } - static constexpr pma_flags uram_flags{ + static constexpr pmas_flags uram_flags{ .M = true, .IO = false, .E = false, @@ -200,12 +200,12 @@ void machine::init_uarch(const uarch_config &c) { constexpr auto ram_description = "uarch RAM"; if (c.ram.image_filename.empty()) { m_us.ram = ®ister_address_range( - make_callocd_memory_address_range(ram_description, PMA_UARCH_RAM_START, UARCH_RAM_LENGTH, uram_flags), + make_callocd_memory_address_range(ram_description, AR_UARCH_RAM_START, UARCH_RAM_LENGTH, uram_flags), register_where{.merkle = true, .interpret = false}); memcpy(m_us.ram->get_host_memory(), uarch_pristine_ram, uarch_pristine_ram_len); } else { m_us.ram = - ®ister_address_range(make_memory_address_range(ram_description, PMA_UARCH_RAM_START, UARCH_RAM_LENGTH, + ®ister_address_range(make_memory_address_range(ram_description, AR_UARCH_RAM_START, UARCH_RAM_LENGTH, uram_flags, c.ram.image_filename, false /* not shared */), register_where{.merkle = true, .interpret = false}); } @@ -283,7 +283,7 @@ void machine::init_processor(processor_config &p, const machine_runtime_config & void machine::init_ram_ar(const ram_config &ram) { // Flags for RAM - static constexpr pma_flags ram_flags{ + static constexpr pmas_flags ram_flags{ .M = true, .IO = false, .E = false, @@ -298,13 +298,13 @@ void machine::init_ram_ar(const ram_config &ram) { throw std::invalid_argument("RAM length cannot be zero"); } register_address_range( - make_callocd_memory_address_range("RAM"s, PMA_RAM_START, ram.length, ram_flags, ram.image_filename), + make_callocd_memory_address_range("RAM"s, AR_RAM_START, ram.length, ram_flags, ram.image_filename), register_where{.merkle = true, .interpret = true}); } void machine::init_flash_drive_ars(flash_drive_configs &flash_drive) { // Flags for flash drives - static const pma_flags flash_flags{ + static const pmas_flags flash_flags{ .M = true, .IO = false, .E = false, @@ -321,7 +321,7 @@ void machine::init_flash_drive_ars(flash_drive_configs &flash_drive) { const std::string flash_description = "flash drive "s + std::to_string(i); // Auto detect flash drive start address if (f.start == UINT64_C(-1)) { - f.start = PMA_DRIVE_START + PMA_DRIVE_OFFSET * i; + f.start = AR_DRIVE_START + AR_DRIVE_OFFSET * i; } // Auto detect flash drive image length if (f.length == UINT64_C(-1)) { @@ -360,14 +360,14 @@ void machine::init_virtio_ars(const virtio_configs &cs, uint64_t iunrep) { const auto where = register_where{.merkle = false, .interpret = true}; const auto visitor = overloads{ [this, virtio_idx, where](const virtio_console_config &) { - const auto start = PMA_FIRST_VIRTIO_START + (virtio_idx * PMA_VIRTIO_LENGTH); - register_address_range(make_virtio_console_address_range(start, PMA_VIRTIO_LENGTH, virtio_idx), where); + const auto start = AR_FIRST_VIRTIO_START + (virtio_idx * AR_VIRTIO_LENGTH); + register_address_range(make_virtio_console_address_range(start, AR_VIRTIO_LENGTH, virtio_idx), where); }, [this, virtio_idx, where](const virtio_p9fs_config &c) { #ifdef HAVE_POSIX_FS - const auto start = PMA_FIRST_VIRTIO_START + (virtio_idx * PMA_VIRTIO_LENGTH); + const auto start = AR_FIRST_VIRTIO_START + (virtio_idx * AR_VIRTIO_LENGTH); register_address_range( - make_virtio_p9fs_address_range(start, PMA_VIRTIO_LENGTH, virtio_idx, c.tag, c.host_directory), + make_virtio_p9fs_address_range(start, AR_VIRTIO_LENGTH, virtio_idx, c.tag, c.host_directory), where); #else (void) c; @@ -379,9 +379,9 @@ void machine::init_virtio_ars(const virtio_configs &cs, uint64_t iunrep) { }, [this, virtio_idx, where](const virtio_net_tuntap_config &c) { #ifdef HAVE_TUNTAP - const auto start = PMA_FIRST_VIRTIO_START + (virtio_idx * PMA_VIRTIO_LENGTH); + const auto start = AR_FIRST_VIRTIO_START + (virtio_idx * AR_VIRTIO_LENGTH); register_address_range( - make_virtio_net_tuntap_address_range(start, PMA_VIRTIO_LENGTH, virtio_idx, c.iface), where); + make_virtio_net_tuntap_address_range(start, AR_VIRTIO_LENGTH, virtio_idx, c.iface), where); #else (void) c; (void) this; @@ -392,8 +392,8 @@ void machine::init_virtio_ars(const virtio_configs &cs, uint64_t iunrep) { }, [this, virtio_idx, where](const virtio_net_user_config &c) { #ifdef HAVE_SLIRP - const auto start = PMA_FIRST_VIRTIO_START + (virtio_idx * PMA_VIRTIO_LENGTH); - register_address_range(make_virtio_net_user_address_range(start, PMA_VIRTIO_LENGTH, virtio_idx, c), + const auto start = AR_FIRST_VIRTIO_START + (virtio_idx * AR_VIRTIO_LENGTH); + register_address_range(make_virtio_net_user_address_range(start, AR_VIRTIO_LENGTH, virtio_idx, c), where); #else (void) c; @@ -411,7 +411,7 @@ void machine::init_virtio_ars(const virtio_configs &cs, uint64_t iunrep) { void machine::init_htif_ar(const htif_config &h) { // Register HTIF device - register_address_range(make_htif_address_range(PMA_HTIF_START, PMA_HTIF_LENGTH, throw_invalid_argument), + register_address_range(make_htif_address_range(AR_HTIF_START, AR_HTIF_LENGTH, throw_invalid_argument), register_where{.merkle = false, .interpret = true}); // Copy HTIF state to from config to machine write_reg(reg::htif_tohost, h.tohost); @@ -428,7 +428,7 @@ void machine::init_htif_ar(const htif_config &h) { } void machine::init_cmio_ars(const cmio_config &c) { - static const pma_flags tx_flags{ + static const pmas_flags tx_flags{ .M = true, .IO = false, .E = false, @@ -439,7 +439,7 @@ void machine::init_cmio_ars(const cmio_config &c) { .IW = true, .DID = PMA_ISTART_DID::cmio_tx_buffer, }; - static const pma_flags rx_flags{ + static const pmas_flags rx_flags{ .M = true, .IO = false, .E = false, @@ -450,11 +450,11 @@ void machine::init_cmio_ars(const cmio_config &c) { .IW = true, .DID = PMA_ISTART_DID::cmio_rx_buffer, }; - register_address_range(make_memory_address_range("CMIO tx buffer memory range"s, PMA_CMIO_TX_BUFFER_START, - PMA_CMIO_TX_BUFFER_LENGTH, tx_flags, c.tx_buffer.image_filename, c.tx_buffer.shared), + register_address_range(make_memory_address_range("CMIO tx buffer memory range"s, AR_CMIO_TX_BUFFER_START, + AR_CMIO_TX_BUFFER_LENGTH, tx_flags, c.tx_buffer.image_filename, c.tx_buffer.shared), register_where{.merkle = true, .interpret = true}); - register_address_range(make_memory_address_range("CMIO rx buffer memory range"s, PMA_CMIO_RX_BUFFER_START, - PMA_CMIO_RX_BUFFER_LENGTH, rx_flags, c.rx_buffer.image_filename, c.rx_buffer.shared), + register_address_range(make_memory_address_range("CMIO rx buffer memory range"s, AR_CMIO_RX_BUFFER_START, + AR_CMIO_RX_BUFFER_LENGTH, rx_flags, c.rx_buffer.image_filename, c.rx_buffer.shared), register_where{.merkle = true, .interpret = true}); } @@ -479,7 +479,7 @@ void machine::init_ars_descriptions() { void machine::init_clint_ar(const clint_config &c) { // Register CLINT device - register_address_range(make_clint_address_range(PMA_CLINT_START, PMA_CLINT_LENGTH, throw_invalid_argument), + register_address_range(make_clint_address_range(AR_CLINT_START, AR_CLINT_LENGTH, throw_invalid_argument), register_where{.merkle = false, .interpret = true}); // Copy CLINT state to from config to machine write_reg(reg::clint_mtimecmp, c.mtimecmp); @@ -487,7 +487,7 @@ void machine::init_clint_ar(const clint_config &c) { void machine::init_plic_ar(const plic_config &p) { // Register PLIC device - register_address_range(make_plic_address_range(PMA_PLIC_START, PMA_PLIC_LENGTH, throw_invalid_argument), + register_address_range(make_plic_address_range(AR_PLIC_START, AR_PLIC_LENGTH, throw_invalid_argument), register_where{.merkle = false, .interpret = true}); // Copy PLIC state from config to machine write_reg(reg::plic_girqpend, p.girqpend); @@ -506,11 +506,11 @@ void machine::init_sentinel_ars() { void machine::init_pmas_contents(memory_address_range &pmas) const { static_assert(sizeof(pmas_state) == PMA_MAX * 2 * sizeof(uint64_t), "inconsistent PMAs state length"); - static_assert(PMA_PMAS_LENGTH >= sizeof(pmas_state), "PMAs address range too short"); + static_assert(AR_PMAS_LENGTH >= sizeof(pmas_state), "PMAs address range too short"); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto &dest = *reinterpret_cast(pmas.get_host_memory()); std::ranges::transform(m_s.pmas, dest.begin(), - [this](auto i) { return pma_entry{.istart = m_ars[i]->get_istart(), .ilength = m_ars[i]->get_ilength()}; }); + [this](auto i) { return pmas_entry{.istart = m_ars[i]->get_istart(), .ilength = m_ars[i]->get_ilength()}; }); } void machine::init_tlb_contents(const std::string &image_filename) { @@ -538,7 +538,7 @@ void machine::init_tlb_contents(const std::string &image_filename) { address_range &machine::init_dtb_ar(const dtb_config &c) { // When we pass a RNG seed in a FDT stored in DTB, Linux will wipe out its contents as a security measure, // therefore we need to make DTB writable, otherwise boot will hang. - static constexpr pma_flags dtb_flags{ + static constexpr pmas_flags dtb_flags{ .M = true, .IO = false, .E = false, @@ -549,14 +549,14 @@ address_range &machine::init_dtb_ar(const dtb_config &c) { .IW = true, .DID = PMA_ISTART_DID::memory, }; - return register_address_range(make_memory_address_range("DTB"s, PMA_DTB_START, PMA_DTB_LENGTH, dtb_flags, + return register_address_range(make_memory_address_range("DTB"s, AR_DTB_START, AR_DTB_LENGTH, dtb_flags, c.image_filename, false /* not shared */), register_where{.merkle = true, .interpret = true}); } void machine::init_dtb_contents(const machine_config &c, address_range &dtb) { if (c.dtb.image_filename.empty()) { - dtb_init(c, dtb.get_host_memory(), PMA_DTB_LENGTH); + dtb_init(c, dtb.get_host_memory(), AR_DTB_LENGTH); } } @@ -576,13 +576,13 @@ machine::machine(machine_config c, machine_runtime_config r) : m_c{std::move(c)} init_plic_ar(m_c.plic); // Will populate when initialization of PMAs is done register_address_range( - make_shadow_tlb_address_range(PMA_SHADOW_TLB_START, PMA_SHADOW_TLB_LENGTH, throw_invalid_argument), + make_shadow_tlb_address_range(AR_SHADOW_TLB_START, AR_SHADOW_TLB_LENGTH, throw_invalid_argument), register_where{.merkle = true, .interpret = false}); register_address_range( - make_shadow_state_address_range(PMA_SHADOW_STATE_START, PMA_SHADOW_STATE_LENGTH, throw_invalid_argument), + make_shadow_state_address_range(AR_SHADOW_STATE_START, AR_SHADOW_STATE_LENGTH, throw_invalid_argument), register_where{.merkle = true, .interpret = false}); // Will populate when initialization of PMAs is done - auto &shpmas = register_address_range(make_pmas_address_range(PMA_PMAS_START, PMA_PMAS_LENGTH), + auto &shpmas = register_address_range(make_pmas_address_range(AR_PMAS_START, AR_PMAS_LENGTH), register_where{.merkle = true, .interpret = true}); init_virtio_ars(m_c.virtio, m_c.processor.iunrep); init_sentinel_ars(); @@ -781,19 +781,19 @@ static void store_device_address_range(const machine &m, const address_range &ar if (!ar.is_device()) { throw std::runtime_error{"attempt to save non-device address range "s + ar.get_description()}; } - auto scratch = make_unique_calloc(PMA_PAGE_SIZE); // will throw if it fails + auto scratch = make_unique_calloc(AR_PAGE_SIZE); // will throw if it fails auto name = machine_config::get_image_filename(dir, ar.get_start(), ar.get_length()); auto fp = make_unique_fopen(name.c_str(), "wb"); // will throw if it fails - for (uint64_t offset = 0; offset < ar.get_length(); offset += PMA_PAGE_SIZE) { + for (uint64_t offset = 0; offset < ar.get_length(); offset += AR_PAGE_SIZE) { const unsigned char *page_data = nullptr; - if (!ar.peek(m, offset, PMA_PAGE_SIZE, &page_data, scratch.get())) { + if (!ar.peek(m, offset, AR_PAGE_SIZE, &page_data, scratch.get())) { throw std::runtime_error{"peek failed"}; } if (page_data == nullptr) { - memset(scratch.get(), 0, PMA_PAGE_SIZE); + memset(scratch.get(), 0, AR_PAGE_SIZE); page_data = scratch.get(); } - if (fwrite(page_data, 1, PMA_PAGE_SIZE, fp.get()) != PMA_PAGE_SIZE) { + if (fwrite(page_data, 1, AR_PAGE_SIZE, fp.get()) != AR_PAGE_SIZE) { throw std::system_error{errno, std::generic_category(), "error writing to '" + name + "'"}; } } @@ -874,8 +874,8 @@ void machine::check_shadow_tlb(TLB_set_index set_index, uint64_t slot_index, uin if ((paddr_page & PAGE_OFFSET_MASK) != 0) { throw std::invalid_argument{prefix + "vp_offset is not aligned"s}; } - const auto pma_end = ar.get_start() + (ar.get_length() - PMA_PAGE_SIZE); - if (paddr_page < ar.get_start() || paddr_page > pma_end) { + const auto pmas_end = ar.get_start() + (ar.get_length() - AR_PAGE_SIZE); + if (paddr_page < ar.get_start() || paddr_page > pmas_end) { throw std::invalid_argument{prefix + "vp_offset is inconsistent with pma_index"s}; } } else if (pma_index != TLB_INVALID_PMA_INDEX || vp_offset != 0) { @@ -926,16 +926,16 @@ void machine::store_address_ranges(const machine_config &c, const std::string &d if (read_reg(reg::iunrep) != 0) { throw std::runtime_error{"cannot store PMAs of unreproducible machines"}; } - store_memory_address_range(find_address_range(PMA_DTB_START), dir); - store_memory_address_range(find_address_range(PMA_RAM_START), dir); - store_device_address_range(*this, find_address_range(PMA_SHADOW_TLB_START), dir); + store_memory_address_range(find_address_range(AR_DTB_START), dir); + store_memory_address_range(find_address_range(AR_RAM_START), dir); + store_device_address_range(*this, find_address_range(AR_SHADOW_TLB_START), dir); // Could iterate over PMAs checking for those with a drive DID but this is easier for (const auto &f : c.flash_drive) { store_memory_address_range(find_address_range(f.start), dir); } - store_memory_address_range(find_address_range(PMA_CMIO_RX_BUFFER_START), dir); - store_memory_address_range(find_address_range(PMA_CMIO_TX_BUFFER_START), dir); - store_memory_address_range(find_address_range(PMA_UARCH_RAM_START), dir); + store_memory_address_range(find_address_range(AR_CMIO_RX_BUFFER_START), dir); + store_memory_address_range(find_address_range(AR_CMIO_TX_BUFFER_START), dir); + store_memory_address_range(find_address_range(AR_UARCH_RAM_START), dir); } static void store_hash(const machine::hash_type &h, const std::string &dir) { @@ -1811,7 +1811,7 @@ void machine::mark_write_tlb_dirty_pages() const { throw std::runtime_error{"could not mark dirty page for a TLB entry: TLB is corrupt"}; } auto paddr_page = get_paddr(haddr_page, cold_slot.pma_index); - if (!ar.contains_absolute(paddr_page, PMA_PAGE_SIZE)) { + if (!ar.contains_absolute(paddr_page, AR_PAGE_SIZE)) { throw std::runtime_error{"could not mark dirty page for a TLB entry: TLB is corrupt"}; } ar.mark_dirty_page(paddr_page - ar.get_start()); @@ -1820,10 +1820,10 @@ void machine::mark_write_tlb_dirty_pages() const { } bool machine::verify_dirty_page_maps() const { - static_assert(PMA_PAGE_SIZE == machine_merkle_tree::get_page_size(), + static_assert(AR_PAGE_SIZE == machine_merkle_tree::get_page_size(), "PMA and machine_merkle_tree page sizes must match"); machine_merkle_tree::hasher_type h; - auto scratch = make_unique_calloc(PMA_PAGE_SIZE, std::nothrow_t{}); + auto scratch = make_unique_calloc(AR_PAGE_SIZE, std::nothrow_t{}); if (!scratch) { return false; } @@ -1832,11 +1832,11 @@ bool machine::verify_dirty_page_maps() const { mark_write_tlb_dirty_pages(); // Now go over all memory PMAs verifying that all dirty pages are marked for (const auto &ar : m_ars) { - for (uint64_t offset = 0; offset < ar->get_length(); offset += PMA_PAGE_SIZE) { + for (uint64_t offset = 0; offset < ar->get_length(); offset += AR_PAGE_SIZE) { const uint64_t page_address = ar->get_start() + offset; if (ar->is_memory()) { const unsigned char *page_data = nullptr; - ar->peek(*this, offset, PMA_PAGE_SIZE, &page_data, scratch.get()); + ar->peek(*this, offset, AR_PAGE_SIZE, &page_data, scratch.get()); hash_type stored; hash_type real; m_t.get_page_node_hash(page_address, stored); @@ -1872,7 +1872,7 @@ static uint64_t get_task_concurrency(uint64_t value) { bool machine::update_merkle_tree() const { machine_merkle_tree::hasher_type gh; - static_assert(PMA_PAGE_SIZE == machine_merkle_tree::get_page_size(), + static_assert(AR_PAGE_SIZE == machine_merkle_tree::get_page_size(), "PMA and machine_merkle_tree page sizes must match"); // Go over the write TLB and mark as dirty all pages currently there mark_write_tlb_dirty_pages(); @@ -1880,19 +1880,19 @@ bool machine::update_merkle_tree() const { m_t.begin_update(); for (auto &ar : m_merkle_ars | std::views::transform([this](auto i) -> address_range & { return *m_ars[i]; })) { // Each PMA has a number of pages - auto pages_in_range = (ar.get_length() + PMA_PAGE_SIZE - 1) / PMA_PAGE_SIZE; + auto pages_in_range = (ar.get_length() + AR_PAGE_SIZE - 1) / AR_PAGE_SIZE; // For each PMA, we launch as many threads (n) as defined on concurrency // runtime config or as the hardware supports. const uint64_t n = get_task_concurrency(m_r.concurrency.update_merkle_tree); const bool succeeded = os_parallel_for(n, [&](int j, const parallel_for_mutex &mutex) -> bool { - auto scratch = make_unique_calloc(PMA_PAGE_SIZE, std::nothrow_t{}); + auto scratch = make_unique_calloc(AR_PAGE_SIZE, std::nothrow_t{}); if (!scratch) { return false; } machine_merkle_tree::hasher_type h; // Thread j is responsible for page i if i % n == j. for (uint64_t i = j; i < pages_in_range; i += n) { - const uint64_t page_start_in_range = i * PMA_PAGE_SIZE; + const uint64_t page_start_in_range = i * AR_PAGE_SIZE; const uint64_t page_address = ar.get_start() + page_start_in_range; const unsigned char *page_data = nullptr; // Skip any clean pages @@ -1901,11 +1901,11 @@ bool machine::update_merkle_tree() const { } // If the peek failed, or if it returned a page for update but // we failed updating it, the entire process failed - if (!ar.peek(*this, page_start_in_range, PMA_PAGE_SIZE, &page_data, scratch.get())) { + if (!ar.peek(*this, page_start_in_range, AR_PAGE_SIZE, &page_data, scratch.get())) { return false; } if (page_data != nullptr) { - if (is_pristine(page_data, PMA_PAGE_SIZE)) { + if (is_pristine(page_data, AR_PAGE_SIZE)) { // The update_page_node_hash function in the machine_merkle_tree is not thread // safe, so we protect it with a mutex const parallel_for_mutex_guard lock(mutex); @@ -1942,20 +1942,20 @@ bool machine::update_merkle_tree() const { } bool machine::update_merkle_tree_page(uint64_t address) { - static_assert(PMA_PAGE_SIZE == machine_merkle_tree::get_page_size(), + static_assert(AR_PAGE_SIZE == machine_merkle_tree::get_page_size(), "PMA and machine_merkle_tree page sizes must match"); // Align address to beginning of page - address &= ~(PMA_PAGE_SIZE - 1); + address &= ~(AR_PAGE_SIZE - 1); auto &ar = find_address_range(address); const uint64_t page_start_in_range = address - ar.get_start(); machine_merkle_tree::hasher_type h; - auto scratch = make_unique_calloc(PMA_PAGE_SIZE, std::nothrow_t{}); + auto scratch = make_unique_calloc(AR_PAGE_SIZE, std::nothrow_t{}); if (!scratch) { return false; } m_t.begin_update(); const unsigned char *page_data = nullptr; - if (!ar.peek(*this, page_start_in_range, PMA_PAGE_SIZE, &page_data, scratch.get())) { + if (!ar.peek(*this, page_start_in_range, AR_PAGE_SIZE, &page_data, scratch.get())) { m_t.end_update(h); return false; } @@ -2003,22 +2003,22 @@ machine::hash_type machine::get_merkle_tree_node_hash(uint64_t address, int log2 } const char *machine::get_what_name(uint64_t paddr) { - if (paddr >= PMA_UARCH_RAM_START && paddr - PMA_UARCH_RAM_START < PMA_UARCH_RAM_LENGTH) { + if (paddr >= AR_UARCH_RAM_START && paddr - AR_UARCH_RAM_START < AR_UARCH_RAM_LENGTH) { return "uarch.ram"; } // If in shadow, return refined name - if (paddr >= PMA_SHADOW_TLB_START && paddr - PMA_SHADOW_TLB_START < PMA_SHADOW_TLB_LENGTH) { + if (paddr >= AR_SHADOW_TLB_START && paddr - AR_SHADOW_TLB_START < AR_SHADOW_TLB_LENGTH) { [[maybe_unused]] TLB_set_index set_index{}; [[maybe_unused]] uint64_t slot_index{}; return shadow_tlb_get_what_name(shadow_tlb_get_what(paddr, set_index, slot_index)); } - if (paddr >= PMA_SHADOW_STATE_START && paddr - PMA_SHADOW_STATE_START < PMA_SHADOW_STATE_LENGTH) { + if (paddr >= AR_SHADOW_STATE_START && paddr - AR_SHADOW_STATE_START < AR_SHADOW_STATE_LENGTH) { return shadow_state_get_what_name(shadow_state_get_what(paddr)); } - if (paddr >= PMA_PMAS_START && paddr - PMA_PMAS_START < PMA_PMAS_LENGTH) { - return pma_get_what_name(pma_get_what(paddr)); + if (paddr >= AR_PMAS_START && paddr - AR_PMAS_START < AR_PMAS_LENGTH) { + return pmas_get_what_name(pmas_get_what(paddr)); } - if (paddr >= PMA_SHADOW_UARCH_STATE_START && paddr - PMA_SHADOW_UARCH_STATE_START < PMA_SHADOW_UARCH_STATE_LENGTH) { + if (paddr >= AR_SHADOW_UARCH_STATE_START && paddr - AR_SHADOW_UARCH_STATE_START < AR_SHADOW_UARCH_STATE_LENGTH) { return shadow_uarch_state_get_what_name(shadow_uarch_state_get_what(paddr)); } return "memory"; @@ -2037,7 +2037,7 @@ bool machine::verify_merkle_tree() const { machine_merkle_tree::proof_type machine::get_proof(uint64_t address, int log2_size, skip_merkle_tree_update_t /*unused*/) const { - static_assert(PMA_PAGE_SIZE == machine_merkle_tree::get_page_size(), + static_assert(AR_PAGE_SIZE == machine_merkle_tree::get_page_size(), "PMA and machine_merkle_tree page sizes must match"); // Check for valid target node size if (log2_size > machine_merkle_tree::get_log2_root_size() || @@ -2059,15 +2059,15 @@ machine_merkle_tree::proof_type machine::get_proof(uint64_t address, int log2_si if (log2_size < machine_merkle_tree::get_log2_page_size()) { const uint64_t length = UINT64_C(1) << log2_size; const auto &ar = find_address_range(address, length); - auto scratch = make_unique_calloc(PMA_PAGE_SIZE); + auto scratch = make_unique_calloc(AR_PAGE_SIZE); const unsigned char *page_data = nullptr; // If the PMA range is empty, we know the desired range is // entirely outside of any non-pristine PMA. // Therefore, the entire page where it lies is also pristine // Otherwise, the entire desired range is inside it. if (ar.get_length() != 0) { - const uint64_t page_start_in_range = (address - ar.get_start()) & (~(PMA_PAGE_SIZE - 1)); - if (!ar.peek(*this, page_start_in_range, PMA_PAGE_SIZE, &page_data, scratch.get())) { + const uint64_t page_start_in_range = (address - ar.get_start()) & (~(AR_PAGE_SIZE - 1)); + if (!ar.peek(*this, page_start_in_range, AR_PAGE_SIZE, &page_data, scratch.get())) { throw std::runtime_error{"PMA peek failed"}; } } @@ -2113,65 +2113,54 @@ void machine::read_memory(uint64_t paddr, unsigned char *data, uint64_t length) if (data == nullptr) { throw std::invalid_argument{"invalid data buffer"}; } - //??D this loop can be much improved and simplified... I don't remember why I am going page - //??D by page when inside an occupied address range... Will fix. - // Compute the distance between the initial paddr and the first page boundary - const uint64_t align_paddr = (paddr & PAGE_OFFSET_MASK) != 0 ? (paddr | PAGE_OFFSET_MASK) + 1 : paddr; - uint64_t align_length = align_paddr - paddr; - const uint64_t page_size = PMA_PAGE_SIZE; - align_length = (align_length == 0) ? page_size : align_length; - // First peek goes at most to the next page boundary, or up to length - uint64_t peek_length = std::min(align_length, length); - // The outer loop finds the address range for all peeks performed by the inner loop - // The inner loop peeks at most min(page_size, length) from the range per iteration - // All peeks but the absolute first peek start at a page boundary. - // That first peek reads at most up to the next page boundary. - // So the inner loop iterations never cross page boundaries. - for (;;) { - const auto &ar = find_address_range(paddr, peek_length); - const auto pma_start = ar.get_start(); - const auto occupied = ar.get_length() != 0; - const auto pma_length = ar.get_length(); - // If we are in an unoccupied range, the inner loop will break after a single iteration. - // But it is safe to return pristine data for that one iteration, without even peeking. - // This is because the inner iteration never reads past a page boundary, and the next - // occupied range starts at the earliest on the next page boundary after paddr. - for (;;) { + uint64_t gap_start = 0; + auto view = m_merkle_ars | // Indices of Mekrle tree address ranges + std::views::transform( + [this](auto i) -> address_range & { return *m_ars[i]; }) | // Now address ranges themselves + std::views::drop_while([paddr, &gap_start](const address_range &ar) { // Only those that end after paddr + const auto ar_end = ar.get_start() + ar.get_length(); + if (paddr >= ar_end) { + gap_start = ar_end; + return true; + } + return false; + }); + for (auto &ar : view) { + const auto ar_start = ar.get_start(); + // Write as much as possible from pristine gap between last address range and current address range + if (paddr >= gap_start && paddr < ar_start) { + const auto from_gap = std::min(ar_start - paddr, length); + memset(data, 0, from_gap); + length -= from_gap; + paddr += from_gap; + data += from_gap; + } + gap_start = ar_start + ar.get_length(); + // Write as much as possible from current address range + if (paddr >= ar_start && paddr < gap_start) { + const auto from_ar = std::min(gap_start - paddr, length); const unsigned char *peek_data = nullptr; - // If we found an occupied range, peek, otherwise leave peek_data as nullptr (i.e. pristine) - if (occupied && !ar.peek(*this, paddr - pma_start, peek_length, &peek_data, data)) { + if (!ar.peek(*this, paddr - ar_start, from_ar, &peek_data, data)) { throw std::runtime_error{"peek failed"}; } - // If the chunk is pristine, copy zero data to buffer if (peek_data == nullptr) { - memset(data, 0, peek_length); - // If peek returned pointer to internal buffer, copy to data buffer + // If the chunk is pristine, copy zero data to buffer + memset(data, 0, from_ar); } else if (peek_data != data) { - memcpy(data, peek_data, peek_length); + // If peek returned pointer to internal buffer, copy to data buffer + memcpy(data, peek_data, from_ar); } - // Otherwise, peek copied data straight into the data buffer - // If we read everything we wanted to read, we are done - length -= peek_length; + // Otherwise, peek already copied to data buffer + length -= from_ar; if (length == 0) { return; } - paddr += peek_length; - data += peek_length; - peek_length = std::min(page_size, length); - // If we are outside any valid range, break to check if next read hits a valid range - if (!occupied) { - break; - } - // If the next read does not fit in current range, break to get the next one - // There can be no overflow in the condition. - // Since the range is occupied, (paddr-pma_start) >= 0. - // Moreover, pma_length >= page_size. - // Since, peek_length <= page_size, we get (pma_length-peek_length) >= 0. - if (paddr - pma_start >= pma_length - peek_length) { - break; - } + paddr += from_ar; + data += from_ar; } } + // Finish up with pristine padding after last address range + memset(data, 0, length); } void machine::write_memory(uint64_t paddr, const unsigned char *data, uint64_t length) { @@ -2191,7 +2180,7 @@ void machine::write_memory(uint64_t paddr, const unsigned char *data, uint64_t l if (is_protected(ar.get_driver_id())) { throw std::invalid_argument{"attempt to write to protected memory range"}; } - foreach_aligned_chunk(paddr, length, PMA_PAGE_SIZE, [&ar, paddr, data](auto chunk_start, auto chunk_length) { + foreach_aligned_chunk(paddr, length, AR_PAGE_SIZE, [&ar, paddr, data](auto chunk_start, auto chunk_length) { const auto *src = data + (chunk_start - paddr); const auto offset = chunk_start - ar.get_start(); auto *dest = ar.get_host_memory() + offset; @@ -2218,7 +2207,7 @@ void machine::fill_memory(uint64_t paddr, uint8_t val, uint64_t length) { throw std::invalid_argument{"attempt fill to protected memory range"}; } // The case of filling a range with zeros is special and optimized for uarch reset - foreach_aligned_chunk(paddr, length, PMA_PAGE_SIZE, [&ar, val](auto chunk_start, auto chunk_length) { + foreach_aligned_chunk(paddr, length, AR_PAGE_SIZE, [&ar, val](auto chunk_start, auto chunk_length) { const auto offset = chunk_start - ar.get_start(); const auto dest = ar.get_host_memory() + offset; if (val != 0 || !is_pristine(dest, chunk_length)) { @@ -2237,17 +2226,17 @@ void machine::read_virtual_memory(uint64_t vaddr_start, unsigned char *data, uin throw std::invalid_argument{"invalid data buffer"}; } const uint64_t vaddr_limit = vaddr_start + length; - const uint64_t vaddr_page_start = vaddr_start & ~(PMA_PAGE_SIZE - 1); // align page backward - const uint64_t vaddr_page_limit = (vaddr_limit + PMA_PAGE_SIZE - 1) & ~(PMA_PAGE_SIZE - 1); // align page forward + const uint64_t vaddr_page_start = vaddr_start & ~(AR_PAGE_SIZE - 1); // align page backward + const uint64_t vaddr_page_limit = (vaddr_limit + AR_PAGE_SIZE - 1) & ~(AR_PAGE_SIZE - 1); // align page forward // copy page by page, because we need to perform address translation again for each page - for (uint64_t vaddr_page = vaddr_page_start; vaddr_page < vaddr_page_limit; vaddr_page += PMA_PAGE_SIZE) { + for (uint64_t vaddr_page = vaddr_page_start; vaddr_page < vaddr_page_limit; vaddr_page += AR_PAGE_SIZE) { uint64_t paddr_page = 0; if (!cartesi::translate_virtual_address(a, &paddr_page, vaddr_page, PTE_XWR_R_SHIFT)) { throw std::domain_error{"page fault"}; } uint64_t paddr = paddr_page; uint64_t vaddr = vaddr_page; - uint64_t chunklen = std::min(PMA_PAGE_SIZE, vaddr_limit - vaddr); + uint64_t chunklen = std::min(AR_PAGE_SIZE, vaddr_limit - vaddr); if (vaddr_page < vaddr_start) { const uint64_t off = vaddr_start - vaddr_page; paddr += off; @@ -2268,10 +2257,10 @@ void machine::write_virtual_memory(uint64_t vaddr_start, const unsigned char *da throw std::invalid_argument{"invalid data buffer"}; } const uint64_t vaddr_limit = vaddr_start + length; - const uint64_t vaddr_page_start = vaddr_start & ~(PMA_PAGE_SIZE - 1); // align page backward - const uint64_t vaddr_page_limit = (vaddr_limit + PMA_PAGE_SIZE - 1) & ~(PMA_PAGE_SIZE - 1); // align page forward + const uint64_t vaddr_page_start = vaddr_start & ~(AR_PAGE_SIZE - 1); // align page backward + const uint64_t vaddr_page_limit = (vaddr_limit + AR_PAGE_SIZE - 1) & ~(AR_PAGE_SIZE - 1); // align page forward // copy page by page, because we need to perform address translation again for each page - for (uint64_t vaddr_page = vaddr_page_start; vaddr_page < vaddr_page_limit; vaddr_page += PMA_PAGE_SIZE) { + for (uint64_t vaddr_page = vaddr_page_start; vaddr_page < vaddr_page_limit; vaddr_page += AR_PAGE_SIZE) { uint64_t paddr_page = 0; // perform address translation using read access mode, // so we can write any reachable virtual memory range @@ -2280,7 +2269,7 @@ void machine::write_virtual_memory(uint64_t vaddr_start, const unsigned char *da } uint64_t paddr = paddr_page; uint64_t vaddr = vaddr_page; - uint64_t chunklen = std::min(PMA_PAGE_SIZE, vaddr_limit - vaddr); + uint64_t chunklen = std::min(AR_PAGE_SIZE, vaddr_limit - vaddr); if (vaddr_page < vaddr_start) { const uint64_t off = vaddr_start - vaddr_page; paddr += off; @@ -2319,7 +2308,7 @@ void machine::write_word(uint64_t paddr, uint64_t val) { throw std::domain_error{"attempted misaligned write to word"}; } // If in shadow, forward to write_reg - if (paddr >= PMA_SHADOW_STATE_START && paddr - PMA_SHADOW_STATE_START < PMA_SHADOW_STATE_LENGTH) { + if (paddr >= AR_SHADOW_STATE_START && paddr - AR_SHADOW_STATE_START < AR_SHADOW_STATE_LENGTH) { auto reg = shadow_state_get_what(paddr); if (reg == shadow_state_what::unknown_) { throw std::runtime_error("unhandled write to shadow state"); @@ -2328,7 +2317,7 @@ void machine::write_word(uint64_t paddr, uint64_t val) { return; } // If in uarch shadow, forward to write_reg - if (paddr >= PMA_SHADOW_UARCH_STATE_START && paddr - PMA_SHADOW_UARCH_STATE_START < PMA_SHADOW_UARCH_STATE_LENGTH) { + if (paddr >= AR_SHADOW_UARCH_STATE_START && paddr - AR_SHADOW_UARCH_STATE_START < AR_SHADOW_UARCH_STATE_LENGTH) { auto reg = shadow_uarch_state_get_what(paddr); if (reg == shadow_uarch_state_what::unknown_) { throw std::runtime_error("unhandled write to shadow uarch state"); @@ -2506,7 +2495,7 @@ interpreter_break_reason machine::log_step(uint64_t mcycle_count, const std::str } // Ensure that the microarchitecture is reset auto current_uarch_state_hash = - get_merkle_tree_node_hash(PMA_SHADOW_UARCH_STATE_START, UARCH_STATE_LOG2_SIZE, skip_merkle_tree_update); + get_merkle_tree_node_hash(AR_SHADOW_UARCH_STATE_START, UARCH_STATE_LOG2_SIZE, skip_merkle_tree_update); if (current_uarch_state_hash != uarch_pristine_state_hash) { throw std::runtime_error{"microarchitecture is not reset"}; } diff --git a/src/machine.h b/src/machine.h index cf75ac872..06ca721ea 100644 --- a/src/machine.h +++ b/src/machine.h @@ -40,7 +40,7 @@ #include "machine-runtime-config.h" #include "machine-state.h" #include "os.h" -#include "pma-constants.h" +#include "pmas-constants.h" #include "shadow-tlb.h" #include "uarch-interpret.h" #include "uarch-state.h" diff --git a/src/memory-address-range.cpp b/src/memory-address-range.cpp index a8d05ec63..da61d5d12 100644 --- a/src/memory-address-range.cpp +++ b/src/memory-address-range.cpp @@ -28,14 +28,14 @@ class base_error : public std::invalid_argument { }; memory_address_range::memory_address_range(const std::string &description, uint64_t start, uint64_t length, - const pma_flags &flags, const std::string &image_filename, const mmapd &m) try : + const pmas_flags &flags, const std::string &image_filename, const mmapd &m) try : address_range(description.c_str(), start, length, flags, [](const char *err) { throw base_error{err}; }), m_ptr{make_unique_mmap(image_filename.c_str(), length, m.shared)}, m_host_memory{std::get(m_ptr).get()} { if (!is_memory()) { throw std::invalid_argument{"memory range must be flagged memory when initializing "s + description}; } - m_dirty_page_map.resize((get_length() / (8 * PMA_PAGE_SIZE)) + 1, 0xff); + m_dirty_page_map.resize((get_length() / (8 * AR_PAGE_SIZE)) + 1, 0xff); } catch (base_error &b) { throw; // already contains the description } catch (std::exception &e) { @@ -45,14 +45,14 @@ memory_address_range::memory_address_range(const std::string &description, uint6 } memory_address_range::memory_address_range(const std::string &description, uint64_t start, uint64_t length, - const pma_flags &flags, const std::string &image_filename, const callocd & /*c*/) try : + const pmas_flags &flags, const std::string &image_filename, const callocd & /*c*/) try : address_range(description.c_str(), start, length, flags, [](const char *err) { throw base_error{err}; }), m_ptr{make_unique_calloc(length)}, m_host_memory{std::get(m_ptr).get()} { if (!is_memory()) { throw std::invalid_argument{"memory range must be flagged memory when initializing "s + description}; } - m_dirty_page_map.resize((length / (8 * PMA_PAGE_SIZE)) + 1, 0xff); + m_dirty_page_map.resize((length / (8 * AR_PAGE_SIZE)) + 1, 0xff); // Try to load image file, if any if (!image_filename.empty()) { auto fp = make_unique_fopen(image_filename.c_str(), "rb", std::nothrow_t{}); diff --git a/src/memory-address-range.h b/src/memory-address-range.h index 7beb6a56f..e7b828147 100644 --- a/src/memory-address-range.h +++ b/src/memory-address-range.h @@ -60,7 +60,7 @@ class memory_address_range : public address_range { /// \param flags Range flags /// \param image_filename Path to backing file. /// \param m Mmap'd range data (shared or not). - memory_address_range(const std::string &description, uint64_t start, uint64_t length, const pma_flags &flags, + memory_address_range(const std::string &description, uint64_t start, uint64_t length, const pmas_flags &flags, const std::string &image_filename, const mmapd &m); /// \brief Calloc'd range data (just a tag). @@ -73,7 +73,7 @@ class memory_address_range : public address_range { /// \param flags Range flags /// \param image_filename Path to backing file. /// \param c Calloc'd range data (just a tag). - memory_address_range(const std::string &description, uint64_t start, uint64_t length, const pma_flags &flags, + memory_address_range(const std::string &description, uint64_t start, uint64_t length, const pmas_flags &flags, const std::string &image_filename, const callocd & /*c*/); memory_address_range(const memory_address_range &) = delete; @@ -93,14 +93,14 @@ class memory_address_range : public address_range { } void do_mark_dirty_page(uint64_t offset) noexcept override { - auto page_index = offset >> PMA_constants::PMA_PAGE_SIZE_LOG2; + auto page_index = offset >> AR_constants::AR_PAGE_SIZE_LOG2; auto map_index = page_index >> 3; assert(map_index < m_dirty_page_map.size()); m_dirty_page_map[map_index] |= (1 << (page_index & 7)); } void do_mark_clean_page(uint64_t offset) noexcept override { - auto page_index = offset >> PMA_constants::PMA_PAGE_SIZE_LOG2; + auto page_index = offset >> AR_constants::AR_PAGE_SIZE_LOG2; auto map_index = page_index >> 3; assert(map_index < m_dirty_page_map.size()); m_dirty_page_map[map_index] &= ~(1 << (page_index & 7)); @@ -111,7 +111,7 @@ class memory_address_range : public address_range { } bool do_is_page_marked_dirty(uint64_t offset) const noexcept override { - auto page_index = offset >> PMA_constants::PMA_PAGE_SIZE_LOG2; + auto page_index = offset >> AR_constants::AR_PAGE_SIZE_LOG2; auto map_index = page_index >> 3; assert(map_index < m_dirty_page_map.size()); return (m_dirty_page_map[map_index] & (1 << (page_index & 7))) != 0; @@ -129,12 +129,12 @@ class memory_address_range : public address_range { }; static inline auto make_callocd_memory_address_range(const std::string &description, uint64_t start, uint64_t length, - pma_flags flags, const std::string &image_filename = {}) { + pmas_flags flags, const std::string &image_filename = {}) { return memory_address_range{description, start, length, flags, image_filename, memory_address_range::callocd{}}; } static inline auto make_mmapd_memory_address_range(const std::string &description, uint64_t start, uint64_t length, - pma_flags flags, const std::string &image_filename, bool shared) { + pmas_flags flags, const std::string &image_filename, bool shared) { return memory_address_range{description, start, length, flags, image_filename, memory_address_range::mmapd{shared}}; } diff --git a/src/mock-address-range.h b/src/mock-address-range.h index b79ede8d0..5f51ff520 100644 --- a/src/mock-address-range.h +++ b/src/mock-address-range.h @@ -25,7 +25,7 @@ #include "clint-address-range.h" #include "htif-address-range.h" #include "plic-address-range.h" -#include "pma.h" +#include "pmas.h" #include "shadow-state-address-range.h" #include "shadow-tlb-address-range.h" @@ -37,7 +37,7 @@ using mock_address_range = std::variant; template -static inline mock_address_range check_mock_flags(AR &&ar, const pma_flags &flags, ABRT abrt) +static inline mock_address_range check_mock_flags(AR &&ar, const pmas_flags &flags, ABRT abrt) requires std::is_rvalue_reference_v && std::derived_from { if (ar.get_flags() != flags) { @@ -51,9 +51,9 @@ static inline mock_address_range check_mock_flags(AR &&ar, const pma_flags &flag template static inline mock_address_range make_mock_address_range(uint64_t istart, uint64_t ilength, ABRT abrt) { uint64_t start{}; - auto flags = pma_unpack_istart(istart, start); + auto flags = pmas_unpack_istart(istart, start); if (flags.M) { - return make_address_range(pma_get_DID_name(flags.DID), start, ilength, flags, abrt); + return make_address_range(pmas_get_DID_name(flags.DID), start, ilength, flags, abrt); } if (flags.E) { return make_address_range("empty", start, ilength, flags, abrt); diff --git a/src/plic-address-range.cpp b/src/plic-address-range.cpp index cd8148561..fe7a01357 100644 --- a/src/plic-address-range.cpp +++ b/src/plic-address-range.cpp @@ -21,7 +21,7 @@ #include "i-device-state-access.h" #include "interpret.h" -#include "pma-constants.h" +#include "pmas-constants.h" #include "riscv-constants.h" // Enable these defines to debug PLIC @@ -86,7 +86,7 @@ static execute_status plic_write_claim_complete(i_device_state_access *a, uint32 #ifdef DEBUG_PLIC std::ignore = fprintf(stderr, "plic: claim complete irq_id=%d\n", val); #endif - if (val >= 1 && val <= PMA_PLIC_MAX_IRQ_DEF) { + if (val >= 1 && val <= PLIC_MAX_IRQ) { // On completing, we need to clear its corresponding girqsrvd mask const uint32_t girqpend = a->read_plic_girqpend(); uint32_t girqsrvd = a->read_plic_girqsrvd(); @@ -112,7 +112,7 @@ bool plic_address_range::do_read_device(i_device_state_access *a, uint64_t offse #endif // Our PLIC only supports aligned 32-bit reads - if (((offset & 3) != 0) || log2_size != 2 || offset > PMA_PLIC_LENGTH) { + if (((offset & 3) != 0) || log2_size != 2 || offset > AR_PLIC_LENGTH) { return false; } @@ -169,7 +169,7 @@ bool plic_address_range::do_read_device(i_device_state_access *a, uint64_t offse } } -/// \brief PLIC device read callback. See ::pma_write. +/// \brief PLIC device read callback. See ::pmas_write. execute_status plic_address_range::do_write_device(i_device_state_access *a, uint64_t offset, int log2_size, uint64_t val) noexcept { #ifdef DEBUG_PLIC_MMIO @@ -178,7 +178,7 @@ execute_status plic_address_range::do_write_device(i_device_state_access *a, uin #endif // Our PLIC only supports aligned 32-bit reads - if (((offset & 3) != 0) || log2_size != 2 || offset > PMA_PLIC_LENGTH) { + if (((offset & 3) != 0) || log2_size != 2 || offset > AR_PLIC_LENGTH) { return execute_status::failure; } diff --git a/src/plic-address-range.h b/src/plic-address-range.h index e430a1974..76ab71de8 100644 --- a/src/plic-address-range.h +++ b/src/plic-address-range.h @@ -38,7 +38,7 @@ void plic_reset_pending_irq(i_device_state_access *a, uint32_t irq_id); class plic_address_range final : public pristine_address_range { - static constexpr pma_flags m_plic_flags{ + static constexpr pmas_flags m_plic_flags{ .M = false, .IO = true, .E = false, diff --git a/src/plic-constants.h b/src/plic-constants.h index d6eda8311..db3e15ca0 100644 --- a/src/plic-constants.h +++ b/src/plic-constants.h @@ -27,6 +27,7 @@ namespace cartesi { enum PLIC_constants : uint64_t { PLIC_ENABLED_IRQ_MASK = UINT64_C(0xfffffffe), // Interrupt mask for all enabled interrupt sources (1-31) PLIC_LOWEST_IRQ_PRIORITY = 1, + PLIC_MAX_IRQ = 31 ///< Maximum PLIC interrupt }; /// \brief Mapping between CSRs and their relative addresses in PLIC memory diff --git a/src/pma-constants.h b/src/pma-constants.h deleted file mode 100644 index 14a589a11..000000000 --- a/src/pma-constants.h +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright Cartesi and individual authors (see AUTHORS) -// SPDX-License-Identifier: LGPL-3.0-or-later -// -// This program is free software: you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) any -// later version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License along -// with this program (see COPYING). If not, see . -// - -#ifndef PMA_CONSTANTS_H -#define PMA_CONSTANTS_H - -#include - -#include "pma-defines.h" - -namespace cartesi { - -/// \brief Fixed PMA ranges. -enum PMA_ranges : uint64_t { - PMA_SHADOW_STATE_START = EXPAND_UINT64_C(PMA_SHADOW_STATE_START_DEF), ///< Start of processor shadow range - PMA_SHADOW_STATE_LENGTH = EXPAND_UINT64_C(PMA_SHADOW_STATE_LENGTH_DEF), ///< Length of processor shadow range - PMA_PMAS_START = EXPAND_UINT64_C(PMA_PMAS_START_DEF), ///< Start of pma board shadow range - PMA_PMAS_LENGTH = EXPAND_UINT64_C(PMA_PMAS_LENGTH_DEF), ///< Length of pma board shadow range - PMA_DTB_START = EXPAND_UINT64_C(PMA_DTB_START_DEF), ///< Start of DTB range - PMA_DTB_LENGTH = EXPAND_UINT64_C(PMA_DTB_LENGTH_DEF), ///< Length of DTB range - PMA_SHADOW_TLB_START = EXPAND_UINT64_C(PMA_SHADOW_TLB_START_DEF), ///< Start of TLB shadow range - PMA_SHADOW_TLB_LENGTH = EXPAND_UINT64_C(PMA_SHADOW_TLB_LENGTH_DEF), ///< Length of TLB shadow range - PMA_SHADOW_UARCH_STATE_START = - EXPAND_UINT64_C(PMA_SHADOW_UARCH_STATE_START_DEF), ///< Start of microarchitecture shadow state range - PMA_SHADOW_UARCH_STATE_LENGTH = - EXPAND_UINT64_C(PMA_SHADOW_UARCH_STATE_LENGTH_DEF), ///< Length of microarchitecture shadow state range - PMA_CLINT_START = EXPAND_UINT64_C(PMA_CLINT_START_DEF), ///< Start of CLINT range - PMA_CLINT_LENGTH = EXPAND_UINT64_C(PMA_CLINT_LENGTH_DEF), ///< Length of CLINT range - PMA_PLIC_START = EXPAND_UINT64_C(PMA_PLIC_START_DEF), ///< Start of PLIC range - PMA_PLIC_LENGTH = EXPAND_UINT64_C(PMA_PLIC_LENGTH_DEF), ///< Length of PLIC range - PMA_HTIF_START = EXPAND_UINT64_C(PMA_HTIF_START_DEF), ///< Start of HTIF range - PMA_HTIF_LENGTH = EXPAND_UINT64_C(PMA_HTIF_LENGTH_DEF), ///< Length of HTIF range - PMA_UARCH_RAM_START = EXPAND_UINT64_C(PMA_UARCH_RAM_START_DEF), ///< Start of microarchitecture RAM range - PMA_UARCH_RAM_LENGTH = EXPAND_UINT64_C(PMA_UARCH_RAM_LENGTH_DEF), ///< Length of microarchitecture RAM range - PMA_CMIO_RX_BUFFER_START = EXPAND_UINT64_C(PMA_CMIO_RX_BUFFER_START_DEF), ///< Start of CMIO RX buffer range - PMA_CMIO_RX_BUFFER_LOG2_SIZE = EXPAND_UINT64_C(PMA_CMIO_RX_BUFFER_LOG2_SIZE_DEF), ///< Log2 of CMIO RX buffer range - PMA_CMIO_RX_BUFFER_LENGTH = (UINT64_C(1) << PMA_CMIO_RX_BUFFER_LOG2_SIZE_DEF), ///< Length of CMIO RX buffer range - PMA_CMIO_TX_BUFFER_START = EXPAND_UINT64_C(PMA_CMIO_TX_BUFFER_START_DEF), ///< Start of CMIO TX buffer range - PMA_CMIO_TX_BUFFER_LOG2_SIZE = EXPAND_UINT64_C(PMA_CMIO_TX_BUFFER_LOG2_SIZE_DEF), ///< Log2 of CMIO TX buffer range - PMA_CMIO_TX_BUFFER_LENGTH = (UINT64_C(1) << PMA_CMIO_TX_BUFFER_LOG2_SIZE_DEF), ///< Length of CMIO TX buffer range - PMA_DRIVE_START = EXPAND_UINT64_C(PMA_DRIVE_START_DEF), ///< Start PMA address for flash drives - PMA_DRIVE_OFFSET = EXPAND_UINT64_C(PMA_DRIVE_OFFSET_DEF), ///< PMA offset for extra flash drives - - PMA_FIRST_VIRTIO_START = EXPAND_UINT64_C(PMA_FIRST_VIRTIO_START_DEF), ///< Start of first VIRTIO range - PMA_VIRTIO_LENGTH = EXPAND_UINT64_C(PMA_VIRTIO_LENGTH_DEF), ///< Length of each VIRTIO range - PMA_LAST_VIRTIO_END = EXPAND_UINT64_C(PMA_LAST_VIRTIO_END_DEF), ///< End of last VIRTIO range - - PMA_RAM_START = EXPAND_UINT64_C(PMA_RAM_START_DEF), ///< Start of RAM range -}; - -/// \brief PMA constants. -enum PMA_constants : uint64_t { - PMA_PAGE_SIZE_LOG2 = EXPAND_UINT64_C(PMA_PAGE_SIZE_LOG2_DEF), ///< log2 of physical memory page size. - PMA_PAGE_SIZE = (UINT64_C(1) << PMA_PAGE_SIZE_LOG2_DEF), ///< Physical memory page size. - PMA_MAX = EXPAND_UINT64_C(PMA_MAX_DEF) ///< Maximum number of PMAs -}; - -/// \brief PMA PLIC constants. -enum PMA_plic_constants : uint64_t { - PMA_PLIC_MAX_IRQ = EXPAND_UINT64_C(PMA_PLIC_MAX_IRQ_DEF), ///< Maximum PLIC interrupt -}; - -/// \brief PMA masks. -enum PMA_masks : uint64_t { - PMA_ADDRESSABLE_MASK = ((UINT64_C(1) << 56) - 1) ///< Mask for addressable PMA ranges. -}; - -/// \brief PMA istart shifts -enum PMA_ISTART_shifts { - PMA_ISTART_M_SHIFT = 0, - PMA_ISTART_IO_SHIFT = 1, - PMA_ISTART_E_SHIFT = 2, - PMA_ISTART_R_SHIFT = 3, - PMA_ISTART_W_SHIFT = 4, - PMA_ISTART_X_SHIFT = 5, - PMA_ISTART_IR_SHIFT = 6, - PMA_ISTART_IW_SHIFT = 7, - PMA_ISTART_DID_SHIFT = 8, - PMA_ISTART_START_SHIFT = PMA_PAGE_SIZE_LOG2_DEF -}; - -/// \brief PMA istart masks -enum PMA_ISTART_masks : uint64_t { - PMA_ISTART_M_MASK = UINT64_C(1) << PMA_ISTART_M_SHIFT, ///< Memory range - PMA_ISTART_IO_MASK = UINT64_C(1) << PMA_ISTART_IO_SHIFT, ///< Device range - PMA_ISTART_E_MASK = UINT64_C(1) << PMA_ISTART_E_SHIFT, ///< Empty range - PMA_ISTART_R_MASK = UINT64_C(1) << PMA_ISTART_R_SHIFT, ///< Readable - PMA_ISTART_W_MASK = UINT64_C(1) << PMA_ISTART_W_SHIFT, ///< Writable - PMA_ISTART_X_MASK = UINT64_C(1) << PMA_ISTART_X_SHIFT, ///< Executable - PMA_ISTART_IR_MASK = UINT64_C(1) << PMA_ISTART_IR_SHIFT, ///< Idempotent reads - PMA_ISTART_IW_MASK = UINT64_C(1) << PMA_ISTART_IW_SHIFT, ///< Idempotent writes - PMA_ISTART_DID_MASK = UINT64_C(15) << PMA_ISTART_DID_SHIFT, ///< Device id - PMA_ISTART_START_MASK = UINT64_C(-1) << PMA_ISTART_START_SHIFT ///< Start of range -}; - -/// \brief PMA device ids -enum class PMA_ISTART_DID { - memory = PMA_MEMORY_DID_DEF, ///< DID for memory - shadow_state = PMA_SHADOW_STATE_DID_DEF, ///< DID for shadow device - shadow_TLB = PMA_SHADOW_TLB_DID_DEF, ///< DID for shadow TLB device - flash_drive = PMA_FLASH_DRIVE_DID_DEF, ///< DID for drive device - CLINT = PMA_CLINT_DID_DEF, ///< DID for CLINT device - PLIC = PMA_PLIC_DID_DEF, ///< DID for PLIC device - HTIF = PMA_HTIF_DID_DEF, ///< DID for HTIF device - VIRTIO = PMA_VIRTIO_DID_DEF, ///< DID for VirtIO devices - cmio_rx_buffer = PMA_CMIO_RX_BUFFER_DID_DEF, ///< DID for cmio receive buffer - cmio_tx_buffer = PMA_CMIO_TX_BUFFER_DID_DEF, ///< DID for cmio transmit buffer - shadow_uarch_state = PMA_SHADOW_UARCH_STATE_DID_DEF, ///< DID for shadow uarch state device -}; - -} // namespace cartesi - -#endif diff --git a/src/pma-defines.h b/src/pma-defines.h deleted file mode 100644 index 8ad7dfff4..000000000 --- a/src/pma-defines.h +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright Cartesi and individual authors (see AUTHORS) -// SPDX-License-Identifier: LGPL-3.0-or-later -// -// This program is free software: you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) any -// later version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License along -// with this program (see COPYING). If not, see . -// - -#ifndef PMA_DEFINES_H -#define PMA_DEFINES_H -// NOLINTBEGIN(cppcoreguidelines-macro-usage,cppcoreguidelines-macro-to-enum,modernize-macro-to-enum) -#define PMA_SHADOW_STATE_START_DEF 0x0 ///< Shadow start address -#define PMA_SHADOW_STATE_LENGTH_DEF 0x1000 ///< Shadow length in bytes -#define PMA_PMAS_START_DEF 0x10000 ///< PMA Array start address -#define PMA_PMAS_LENGTH_DEF 0x1000 ///< PMA Array length in bytes -#define PMA_SHADOW_TLB_START_DEF 0x20000 ///< TLB start address -#define PMA_SHADOW_TLB_LENGTH_DEF 0x6000 ///< TLB length in bytes -#define PMA_SHADOW_UARCH_STATE_START_DEF 0x400000 ///< microarchitecture shadow state start address -#define PMA_SHADOW_UARCH_STATE_LENGTH_DEF 0x1000 ///< microarchitecture shadow state length -#define PMA_UARCH_RAM_START_DEF 0x600000 ///< microarchitecture RAM start address -#define PMA_UARCH_RAM_LENGTH_DEF 0x200000 ///< microarchitecture RAM length -#define PMA_CLINT_START_DEF 0x2000000 ///< CLINT start address -#define PMA_CLINT_LENGTH_DEF 0xC0000 ///< CLINT length in bytes -#define PMA_PLIC_START_DEF 0x40100000 ///< Start of PLIC range -#define PMA_PLIC_LENGTH_DEF 0x00400000 ///< Length of PLIC range -#define PMA_HTIF_START_DEF 0x40008000 ///< HTIF base address (to_host) -#define PMA_HTIF_LENGTH_DEF 0x1000 ///< HTIF length in bytes -#define PMA_FIRST_VIRTIO_START_DEF 0x40010000 ///< Start of first VIRTIO range -#define PMA_VIRTIO_LENGTH_DEF 0x1000 ///< Length of each VIRTIO range -#define PMA_LAST_VIRTIO_END_DEF 0x40020000 ///< End of last VIRTIO range -#define PMA_DTB_START_DEF 0x7ff00000 ///< DTB start address -#define PMA_DTB_LENGTH_DEF 0x100000 ///< DTB length in bytes -#define PMA_CMIO_RX_BUFFER_START_DEF 0x60000000 ///< CMIO RX buffer start address -#define PMA_CMIO_RX_BUFFER_LOG2_SIZE_DEF 21 ///< log2 of CMIO RX buffer length in bytes -#define PMA_CMIO_TX_BUFFER_START_DEF 0x60800000 ///< CMIO TX buffer start address -#define PMA_CMIO_TX_BUFFER_LOG2_SIZE_DEF 21 ///< log2 of CMIO TX buffer length in bytes -#define PMA_DRIVE_START_DEF 0x80000000000000 ///< Start PMA address for flash drives -#define PMA_DRIVE_OFFSET_DEF 0x10000000000000 ///< PMA offset for extra flash drives - -#define PMA_RAM_START_DEF 0x80000000 ///< RAM start address - -#define PMA_PAGE_SIZE_LOG2_DEF 12 ///< log2 of physical memory page size. -#define PMA_MAX_DEF 32 ///< Maximum number of PMAs -#define PMA_PLIC_MAX_IRQ_DEF 31 ///< Maximum PLIC interrupt - -#define PMA_MEMORY_DID_DEF 0 ///< Device ID for memory -#define PMA_SHADOW_STATE_DID_DEF 1 ///< Device ID for shadow state device -#define PMA_FLASH_DRIVE_DID_DEF 2 ///< Device ID for flash drive device -#define PMA_CLINT_DID_DEF 3 ///< Device ID for CLINT device -#define PMA_HTIF_DID_DEF 4 ///< Device ID for HTIF device -#define PMA_SHADOW_TLB_DID_DEF 5 ///< Device ID for shadow TLB device -#define PMA_CMIO_RX_BUFFER_DID_DEF 6 ///< Device ID for cmio RX buffer -#define PMA_CMIO_TX_BUFFER_DID_DEF 7 ///< Device ID for cmio TX buffer -#define PMA_PLIC_DID_DEF 9 ///< Device ID for PLIC device -#define PMA_VIRTIO_DID_DEF 10 ///< Device ID for VirtIO devices -#define PMA_SHADOW_UARCH_STATE_DID_DEF 11 ///< Device ID for uarch shadow state device - -// helper for using UINT64_C with defines -#ifndef EXPAND_UINT64_C -#define EXPAND_UINT64_C(a) UINT64_C(a) -#endif -// NOLINTEND(cppcoreguidelines-macro-usage,cppcoreguidelines-macro-to-enum,modernize-macro-to-enum) -#endif /* end of include guard: PMA_DEFINES_H */ diff --git a/src/pmas-address-range.h b/src/pmas-address-range.h index 4a2ce8f07..960f20e41 100644 --- a/src/pmas-address-range.h +++ b/src/pmas-address-range.h @@ -21,7 +21,7 @@ #include #include "memory-address-range.h" -#include "pma.h" +#include "pmas.h" /// \file /// \brief Shadow device. @@ -29,7 +29,7 @@ namespace cartesi { static inline auto make_pmas_address_range(uint64_t start, uint64_t length) { - static constexpr pma_flags m_flags{ + static constexpr pmas_flags m_flags{ .M = true, .IO = false, .E = false, diff --git a/src/pmas-constants.h b/src/pmas-constants.h new file mode 100644 index 000000000..d7fa628b2 --- /dev/null +++ b/src/pmas-constants.h @@ -0,0 +1,77 @@ +// Copyright Cartesi and individual authors (see AUTHORS) +// SPDX-License-Identifier: LGPL-3.0-or-later +// +// This program is free software: you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) any +// later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License along +// with this program (see COPYING). If not, see . +// + +#ifndef PMAS_CONSTANTS_H +#define PMAS_CONSTANTS_H + +#include + +#include "pmas-defines.h" + +namespace cartesi { + +/// \brief PMA constants. +enum PMA_constants : uint64_t { + PMA_MAX = EXPAND_UINT64_C(PMA_MAX_DEF) ///< Maximum number of PMAs +}; + +/// \brief PMA istart shifts +enum PMA_ISTART_shifts { + PMA_ISTART_M_SHIFT = 0, + PMA_ISTART_IO_SHIFT = 1, + PMA_ISTART_E_SHIFT = 2, + PMA_ISTART_R_SHIFT = 3, + PMA_ISTART_W_SHIFT = 4, + PMA_ISTART_X_SHIFT = 5, + PMA_ISTART_IR_SHIFT = 6, + PMA_ISTART_IW_SHIFT = 7, + PMA_ISTART_DID_SHIFT = 8, + AR_ISTART_START_SHIFT = 12 +}; + +/// \brief PMA istart masks +enum PMA_ISTART_masks : uint64_t { + PMA_ISTART_M_MASK = UINT64_C(1) << PMA_ISTART_M_SHIFT, ///< Memory range + PMA_ISTART_IO_MASK = UINT64_C(1) << PMA_ISTART_IO_SHIFT, ///< Device range + PMA_ISTART_E_MASK = UINT64_C(1) << PMA_ISTART_E_SHIFT, ///< Empty range + PMA_ISTART_R_MASK = UINT64_C(1) << PMA_ISTART_R_SHIFT, ///< Readable + PMA_ISTART_W_MASK = UINT64_C(1) << PMA_ISTART_W_SHIFT, ///< Writable + PMA_ISTART_X_MASK = UINT64_C(1) << PMA_ISTART_X_SHIFT, ///< Executable + PMA_ISTART_IR_MASK = UINT64_C(1) << PMA_ISTART_IR_SHIFT, ///< Idempotent reads + PMA_ISTART_IW_MASK = UINT64_C(1) << PMA_ISTART_IW_SHIFT, ///< Idempotent writes + PMA_ISTART_DID_MASK = UINT64_C(15) << PMA_ISTART_DID_SHIFT, ///< Device id + AR_ISTART_START_MASK = UINT64_C(-1) << AR_ISTART_START_SHIFT ///< Start of range +}; + +/// \brief PMA device ids +enum class PMA_ISTART_DID { + empty = PMA_EMPTY_DID_DEF, ///< DID for empty range + memory = PMA_MEMORY_DID_DEF, ///< DID for memory + shadow_state = PMA_SHADOW_STATE_DID_DEF, ///< DID for shadow state + shadow_TLB = PMA_SHADOW_TLB_DID_DEF, ///< DID for shadow TLB + flash_drive = PMA_FLASH_DRIVE_DID_DEF, ///< DID for flash drives + CLINT = PMA_CLINT_DID_DEF, ///< DID for CLINT device + PLIC = PMA_PLIC_DID_DEF, ///< DID for PLIC device + HTIF = PMA_HTIF_DID_DEF, ///< DID for HTIF device + VIRTIO = PMA_VIRTIO_DID_DEF, ///< DID for VirtIO devices + cmio_rx_buffer = PMA_CMIO_RX_BUFFER_DID_DEF, ///< DID for cmio receive buffer + cmio_tx_buffer = PMA_CMIO_TX_BUFFER_DID_DEF, ///< DID for cmio transmit buffer + shadow_uarch_state = PMA_SHADOW_UARCH_STATE_DID_DEF, ///< DID for shadow uarch state +}; + +} // namespace cartesi + +#endif diff --git a/src/pmas-defines.h b/src/pmas-defines.h new file mode 100644 index 000000000..38008e7c7 --- /dev/null +++ b/src/pmas-defines.h @@ -0,0 +1,41 @@ +// Copyright Cartesi and individual authors (see AUTHORS) +// SPDX-License-Identifier: LGPL-3.0-or-later +// +// This program is free software: you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) any +// later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License along +// with this program (see COPYING). If not, see . +// + +#ifndef PMA_DEFINES_H +#define PMA_DEFINES_H +// NOLINTBEGIN(cppcoreguidelines-macro-usage,cppcoreguidelines-macro-to-enum,modernize-macro-to-enum) + +#define PMA_MAX_DEF 32 ///< Maximum number of PMAs + +#define PMA_EMPTY_DID_DEF 0 ///< Device ID for empty range +#define PMA_MEMORY_DID_DEF 1 ///< Device ID for memory +#define PMA_SHADOW_STATE_DID_DEF 2 ///< Device ID for shadow state device +#define PMA_FLASH_DRIVE_DID_DEF 3 ///< Device ID for flash drive device +#define PMA_CLINT_DID_DEF 4 ///< Device ID for CLINT device +#define PMA_HTIF_DID_DEF 5 ///< Device ID for HTIF device +#define PMA_SHADOW_TLB_DID_DEF 6 ///< Device ID for shadow TLB device +#define PMA_CMIO_RX_BUFFER_DID_DEF 7 ///< Device ID for cmio RX buffer +#define PMA_CMIO_TX_BUFFER_DID_DEF 8 ///< Device ID for cmio TX buffer +#define PMA_PLIC_DID_DEF 10 ///< Device ID for PLIC device +#define PMA_VIRTIO_DID_DEF 11 ///< Device ID for VirtIO devices +#define PMA_SHADOW_UARCH_STATE_DID_DEF 12 ///< Device ID for uarch shadow state device + +// helper for using UINT64_C with defines +#ifndef EXPAND_UINT64_C +#define EXPAND_UINT64_C(a) UINT64_C(a) +#endif +// NOLINTEND(cppcoreguidelines-macro-usage,cppcoreguidelines-macro-to-enum,modernize-macro-to-enum) +#endif /* end of include guard: PMA_DEFINES_H */ diff --git a/src/pma.h b/src/pmas.h similarity index 73% rename from src/pma.h rename to src/pmas.h index 19ac32fb1..fe178e0e4 100644 --- a/src/pma.h +++ b/src/pmas.h @@ -14,21 +14,23 @@ // with this program (see COPYING). If not, see . // -#ifndef PMA_H -#define PMA_H +#ifndef PMAS_H +#define PMAS_H #include +#include #include +#include "address-range-constants.h" #include "compiler-defines.h" -#include "pma-constants.h" +#include "pmas-constants.h" namespace cartesi { /// \file /// \brief Physical memory attributes. -static constexpr const char *pma_get_DID_name(PMA_ISTART_DID did) { +static constexpr const char *pmas_get_DID_name(PMA_ISTART_DID did) { switch (did) { case PMA_ISTART_DID::memory: return "DID.memory"; @@ -58,7 +60,7 @@ static constexpr const char *pma_get_DID_name(PMA_ISTART_DID did) { } ///< Unpacked attribute flags -struct pma_flags { +struct pmas_flags { bool M; ///< is memory bool IO; ///< is device bool E; ///< is empty @@ -70,12 +72,12 @@ struct pma_flags { PMA_ISTART_DID DID; ///< driver id // Defaulted comparison operator - bool operator==(const pma_flags &) const = default; + bool operator==(const pmas_flags &) const = default; }; -static constexpr pma_flags pma_unpack_istart(uint64_t istart, uint64_t &start) { - start = istart & PMA_ISTART_START_MASK; - return pma_flags{.M = ((istart & PMA_ISTART_M_MASK) >> PMA_ISTART_M_SHIFT) != 0, +static constexpr pmas_flags pmas_unpack_istart(uint64_t istart, uint64_t &start) { + start = istart & AR_ISTART_START_MASK; + return pmas_flags{.M = ((istart & PMA_ISTART_M_MASK) >> PMA_ISTART_M_SHIFT) != 0, .IO = ((istart & PMA_ISTART_IO_MASK) >> PMA_ISTART_IO_SHIFT) != 0, .E = ((istart & PMA_ISTART_E_MASK) >> PMA_ISTART_E_SHIFT) != 0, .R = ((istart & PMA_ISTART_R_MASK) >> PMA_ISTART_R_SHIFT) != 0, @@ -86,7 +88,7 @@ static constexpr pma_flags pma_unpack_istart(uint64_t istart, uint64_t &start) { .DID = static_cast((istart & PMA_ISTART_DID_MASK) >> PMA_ISTART_DID_SHIFT)}; } -static constexpr uint64_t pma_pack_istart(const pma_flags &flags, uint64_t start) { +static constexpr uint64_t pmas_pack_istart(const pmas_flags &flags, uint64_t start) { uint64_t istart = start; istart |= (static_cast(flags.M) << PMA_ISTART_M_SHIFT); istart |= (static_cast(flags.IO) << PMA_ISTART_IO_SHIFT); @@ -101,61 +103,60 @@ static constexpr uint64_t pma_pack_istart(const pma_flags &flags, uint64_t start } /// \brief Shadow memory layout -struct PACKED pma_entry { +struct PACKED pmas_entry { uint64_t istart; uint64_t ilength; }; -using pmas_state = std::array; +using pmas_state = std::array; /// \brief List of field types -enum class pma_what : uint64_t { - istart = offsetof(pma_entry, istart), - ilength = offsetof(pma_entry, ilength), +enum class pmas_what : uint64_t { + istart = offsetof(pmas_entry, istart), + ilength = offsetof(pmas_entry, ilength), unknown_ = UINT64_C(1) << 63, // Outside of RISC-V address space }; /// \brief Obtains the absolute address of a PMA entry. /// \param p Index of desired PMA entry /// \returns The address. -static constexpr uint64_t pma_get_abs_addr(uint64_t p) { - return PMA_PMAS_START + (p * sizeof(pma_entry)); +static constexpr uint64_t pmas_get_abs_addr(uint64_t p) { + return AR_PMAS_START + (p * sizeof(pmas_entry)); } /// \brief Obtains the absolute address of a PMA entry. /// \param p Index of desired PMA entry /// \param what Desired field /// \returns The address. -static constexpr uint64_t pma_get_abs_addr(uint64_t p, pma_what what) { - return pma_get_abs_addr(p) + static_cast(what); +static constexpr uint64_t pmas_get_abs_addr(uint64_t p, pmas_what what) { + return pmas_get_abs_addr(p) + static_cast(what); } -static constexpr pma_what pma_get_what(uint64_t paddr) { - if (paddr < PMA_PMAS_START || paddr - PMA_PMAS_START >= sizeof(pmas_state) || - (paddr & (sizeof(uint64_t) - 1)) != 0) { - return pma_what::unknown_; +static constexpr pmas_what pmas_get_what(uint64_t paddr) { + if (paddr < AR_PMAS_START || paddr - AR_PMAS_START >= sizeof(pmas_state) || (paddr & (sizeof(uint64_t) - 1)) != 0) { + return pmas_what::unknown_; } - //??D First condition ensures offset = (paddr-PMA_PMAS_START) >= 0 + //??D First condition ensures offset = (paddr-AR_PMAS_START) >= 0 //??D Second ensures offset < sizeof(pmas_state) //??D Third ensures offset is aligned to sizeof(uint64_t) - //??D pma_entry only contains uint64_t fields - //??D pmas_state_what contains one entry with the offset of each field in pma_entry + //??D pmas_entry only contains uint64_t fields + //??D pmas_state_what contains one entry with the offset of each field in pmas_entry //??D I don't see how the cast can produce something outside the enum... // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) - return pma_what{(paddr - PMA_PMAS_START) % sizeof(pma_entry)}; + return pmas_what{(paddr - AR_PMAS_START) % sizeof(pmas_entry)}; } -static constexpr const char *pma_get_what_name(pma_what what) { +static constexpr const char *pmas_get_what_name(pmas_what what) { const auto paddr = static_cast(what); - if (paddr >= sizeof(pma_entry) || (paddr & (sizeof(uint64_t) - 1)) != 0) { + if (paddr >= sizeof(pmas_entry) || (paddr & (sizeof(uint64_t) - 1)) != 0) { return "pma.unknown_"; } switch (what) { - case pma_what::istart: + case pmas_what::istart: return "pma.istart"; - case pma_what::ilength: + case pmas_what::ilength: return "pma.ilength"; - case pma_what::unknown_: + case pmas_what::unknown_: return "pma.unknown_"; } return "pmas.unknown_"; diff --git a/src/pristine-address-range.h b/src/pristine-address-range.h index f59a6aae5..9324e6e71 100644 --- a/src/pristine-address-range.h +++ b/src/pristine-address-range.h @@ -35,7 +35,7 @@ class pristine_address_range : public address_range { /// \param length Length of range, in bytes /// \param f Phyical memory attribute flags for range template - pristine_address_range(const char *description, uint64_t start, uint64_t length, pma_flags f, ABRT abrt) : + pristine_address_range(const char *description, uint64_t start, uint64_t length, pmas_flags f, ABRT abrt) : address_range{description, start, length, f, abrt} { ; } diff --git a/src/record-step-state-access.h b/src/record-step-state-access.h index c3df12494..e1cc987a5 100644 --- a/src/record-step-state-access.h +++ b/src/record-step-state-access.h @@ -27,7 +27,7 @@ #include "i-prefer-shadow-state.h" #include "i-state-access.h" #include "machine.h" -#include "pma.h" +#include "pmas.h" #include "shadow-tlb.h" #include "unique-c-ptr.h" @@ -235,8 +235,8 @@ class record_step_state_access : // replay_step_state_access reconstructs a mock_address_range from the // corresponding istart and ilength fields in the shadow pmas // so we mark the page where they live here - touch_page(pma_get_abs_addr(index, pma_what::istart)); - touch_page(pma_get_abs_addr(index, pma_what::ilength)); + touch_page(pmas_get_abs_addr(index, pmas_what::istart)); + touch_page(pmas_get_abs_addr(index, pmas_what::ilength)); return m_m.read_pma(index); } diff --git a/src/replay-step-state-access.h b/src/replay-step-state-access.h index 933506236..01c5a9ac1 100644 --- a/src/replay-step-state-access.h +++ b/src/replay-step-state-access.h @@ -27,7 +27,7 @@ #include "i-prefer-shadow-state.h" #include "i-state-access.h" #include "mock-address-range.h" -#include "pma.h" +#include "pmas.h" #include "replay-step-state-access-interop.h" #include "riscv-constants.h" #include "shadow-state.h" @@ -76,7 +76,7 @@ class replay_step_state_access : public i_prefer_shadow_state { public: using address_type = uint64_t; - using data_type = unsigned char[PMA_PAGE_SIZE]; + using data_type = unsigned char[AR_PAGE_SIZE]; using hash_type = std::array; static_assert(sizeof(hash_type) == interop_machine_hash_byte_size); @@ -199,7 +199,7 @@ class replay_step_state_access : /// \param paddr The physical address of the page /// \return A pointer to the page_type structure if found, nullptr otherwise page_type *try_find_page(uint64_t paddr_page) const { - const auto page_index = paddr_page >> PMA_PAGE_SIZE_LOG2; + const auto page_index = paddr_page >> AR_PAGE_SIZE_LOG2; uint64_t min{0}; uint64_t max{m_context.page_count}; while (min < max) { @@ -305,7 +305,7 @@ class replay_step_state_access : if (page_log == nullptr) { continue; } - const auto paddr_page = page_log->index << PMA_PAGE_SIZE_LOG2; + const auto paddr_page = page_log->index << AR_PAGE_SIZE_LOG2; const auto vp_offset = paddr_page - vaddr_page; aliased_aligned_write(vp_offset_field_haddr, vp_offset); } @@ -335,14 +335,13 @@ class replay_step_state_access : //??D But in the end, we should only update those pages that we touched //??D May improve performance when we are running this on ZK for (uint64_t i = 0; i < m_context.page_count; i++) { - interop_merkle_tree_hash(m_context.pages[i].data, PMA_PAGE_SIZE, + interop_merkle_tree_hash(m_context.pages[i].data, AR_PAGE_SIZE, // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) reinterpret_cast(&m_context.pages[i].hash)); } size_t next_page = 0; size_t next_sibling = 0; - auto root_hash = - compute_root_hash_impl(0, interop_log2_root_size - PMA_PAGE_SIZE_LOG2, next_page, next_sibling); + auto root_hash = compute_root_hash_impl(0, interop_log2_root_size - AR_PAGE_SIZE_LOG2, next_page, next_sibling); if (next_page != m_context.page_count) { interop_throw_runtime_error("too many pages in log"); } @@ -389,7 +388,7 @@ class replay_step_state_access : //??D we should probably optimize access to the shadow so it doesn't perform a translation every time // We can do this by caching the vh_offset trasnslation of the processor shadow page. This is easy if - // static_assert(sizeof(shadow_state) <= PMA_PAGE_SIZE, "shadow state must fit in single page"); + // static_assert(sizeof(shadow_state) <= AR_PAGE_SIZE, "shadow state must fit in single page"); uint64_t check_read_reg(machine_reg reg) const { const auto haddr = do_get_faddr(machine_reg_address(reg)); return aliased_aligned_read(haddr); @@ -397,19 +396,19 @@ class replay_step_state_access : //??D we should probably optimize access to the shadow so it doesn't perform a translation every time // We can do this by caching the vh_offset trasnslation of the processor shadow page. This is easy if - // static_assert(sizeof(shadow_state) <= PMA_PAGE_SIZE, "shadow state must fit in single page"); + // static_assert(sizeof(shadow_state) <= AR_PAGE_SIZE, "shadow state must fit in single page"); void check_write_reg(machine_reg reg, uint64_t val) const { const auto haddr = do_get_faddr(machine_reg_address(reg)); aliased_aligned_write(haddr, val); } - uint64_t read_pma_istart(uint64_t index) const { - const auto haddr = do_get_faddr(pma_get_abs_addr(index, pma_what::istart)); + uint64_t read_pmas_istart(uint64_t index) const { + const auto haddr = do_get_faddr(pmas_get_abs_addr(index, pmas_what::istart)); return aliased_aligned_read(haddr); } - uint64_t read_pma_ilength(uint64_t index) const { - const auto haddr = do_get_faddr(pma_get_abs_addr(index, pma_what::ilength)); + uint64_t read_pmas_ilength(uint64_t index) const { + const auto haddr = do_get_faddr(pmas_get_abs_addr(index, pmas_what::ilength)); return aliased_aligned_read(haddr); } @@ -462,9 +461,9 @@ class replay_step_state_access : address_range &do_read_pma(uint64_t index) const { assert(index < PMA_MAX); // record_step_state_access will have recorded the access to istart and - // ilength in its implementation of read_pma_entry. - const uint64_t istart = read_pma_istart(index); - const uint64_t ilength = read_pma_ilength(index); + // ilength in its implementation of read_pmas_entry. + const uint64_t istart = read_pmas_istart(index); + const uint64_t ilength = read_pmas_ilength(index); // NOLINTNEXTLINE(bugprone-narrowing-conversions) const int i = static_cast(index); const auto abrt = [](const char *err) { interop_throw_runtime_error(err); }; diff --git a/src/riscv-constants.h b/src/riscv-constants.h index 8d2ffca82..91853ba30 100644 --- a/src/riscv-constants.h +++ b/src/riscv-constants.h @@ -19,8 +19,9 @@ #include +#include "address-range-constants.h" #include "machine-c-version.h" -#include "pma-constants.h" +#include "pmas-constants.h" /// \file /// \brief RISC-V constants @@ -424,7 +425,7 @@ enum COUNTEREN_rw_masks : uint64_t { enum CARTESI_init : uint64_t { // The machines starts executing instructions from RAM start by default, // and expects a working firmware to be available there. - PC_INIT = PMA_RAM_START, ///< Initial value for pc + PC_INIT = AR_RAM_START, ///< Initial value for pc FCSR_INIT = UINT64_C(0), ///< Initial value for fcsr MVENDORID_INIT = UINT64_C(0x6361727465736920), ///< Initial value for mvendorid MARCHID_INIT = CM_MARCHID, ///< Initial value for marchid @@ -440,38 +441,38 @@ enum CARTESI_init : uint64_t { MTVAL_INIT = UINT64_C(0), ///< Initial value for mtval MISA_INIT = (MISA_MXL_VALUE << MISA_MXL_SHIFT) | MISA_EXT_S_MASK | MISA_EXT_U_MASK | MISA_EXT_I_MASK | MISA_EXT_M_MASK | MISA_EXT_A_MASK | MISA_EXT_F_MASK | MISA_EXT_D_MASK | - MISA_EXT_C_MASK, ///< Initial value for misa - MIE_INIT = UINT64_C(0), ///< Initial value for mie - MIP_INIT = UINT64_C(0), ///< Initial value for mip - MEDELEG_INIT = UINT64_C(0), ///< Initial value for medeleg - MIDELEG_INIT = UINT64_C(0), ///< Initial value for mideleg - MCOUNTEREN_INIT = UINT64_C(0), ///< Initial value for mcounteren - STVEC_INIT = UINT64_C(0), ///< Initial value for stvec - SSCRATCH_INIT = UINT64_C(0), ///< Initial value for sscratch - SEPC_INIT = UINT64_C(0), ///< Initial value for sepc - SCAUSE_INIT = UINT64_C(0), ///< Initial value for scause - STVAL_INIT = UINT64_C(0), ///< Initial value for stval - SATP_INIT = UINT64_C(0), ///< Initial value for satp - SCOUNTEREN_INIT = UINT64_C(0), ///< Initial value for scounteren - ILRSC_INIT = UINT64_C(-1), ///< Initial value for ilrsc - IPRV_INIT = PRV_M, ///< Initial value for iprv - IFLAGS_X_INIT = UINT64_C(0), ///< Initial value for iflags_X - IFLAGS_Y_INIT = UINT64_C(0), ///< Initial value for iflags_Y - IFLAGS_H_INIT = UINT64_C(0), ///< Initial value for iflags_H - IUNREP_INIT = UINT64_C(0), ///< Initial value for iunrep - MTIMECMP_INIT = UINT64_C(0), ///< Initial value for mtimecmp - GIRQPEND_INIT = UINT64_C(0), ///< Initial value for girqpend - GIRQSRVD_INIT = UINT64_C(0), ///< Initial value for girqsrvd - FROMHOST_INIT = UINT64_C(0), ///< Initial value for fromhost - TOHOST_INIT = UINT64_C(0), ///< Initial value for tohost - MENVCFG_INIT = UINT64_C(0), ///< Initial value for menvcfg - SENVCFG_INIT = UINT64_C(0), ///< Initial value for senvcfg - UARCH_HALT_FLAG_INIT = UINT64_C(0), ///< Initial value for microarchitecture halt flag - UARCH_X_INIT = UINT64_C(0), ///< Initial value for microarchitecture general purpose register x - UARCH_PC_INIT = PMA_UARCH_RAM_START, ///< Initial value for microarchitecture pc - UARCH_CYCLE_INIT = UINT64_C(0), ///< Initial value for microarchitecture cycle - MHARTID_INIT = UINT64_C(0), ///< Initial mhartid - FDTADDR_INIT = PMA_DTB_START, ///< Initial FDT address + MISA_EXT_C_MASK, ///< Initial value for misa + MIE_INIT = UINT64_C(0), ///< Initial value for mie + MIP_INIT = UINT64_C(0), ///< Initial value for mip + MEDELEG_INIT = UINT64_C(0), ///< Initial value for medeleg + MIDELEG_INIT = UINT64_C(0), ///< Initial value for mideleg + MCOUNTEREN_INIT = UINT64_C(0), ///< Initial value for mcounteren + STVEC_INIT = UINT64_C(0), ///< Initial value for stvec + SSCRATCH_INIT = UINT64_C(0), ///< Initial value for sscratch + SEPC_INIT = UINT64_C(0), ///< Initial value for sepc + SCAUSE_INIT = UINT64_C(0), ///< Initial value for scause + STVAL_INIT = UINT64_C(0), ///< Initial value for stval + SATP_INIT = UINT64_C(0), ///< Initial value for satp + SCOUNTEREN_INIT = UINT64_C(0), ///< Initial value for scounteren + ILRSC_INIT = UINT64_C(-1), ///< Initial value for ilrsc + IPRV_INIT = PRV_M, ///< Initial value for iprv + IFLAGS_X_INIT = UINT64_C(0), ///< Initial value for iflags_X + IFLAGS_Y_INIT = UINT64_C(0), ///< Initial value for iflags_Y + IFLAGS_H_INIT = UINT64_C(0), ///< Initial value for iflags_H + IUNREP_INIT = UINT64_C(0), ///< Initial value for iunrep + MTIMECMP_INIT = UINT64_C(0), ///< Initial value for mtimecmp + GIRQPEND_INIT = UINT64_C(0), ///< Initial value for girqpend + GIRQSRVD_INIT = UINT64_C(0), ///< Initial value for girqsrvd + FROMHOST_INIT = UINT64_C(0), ///< Initial value for fromhost + TOHOST_INIT = UINT64_C(0), ///< Initial value for tohost + MENVCFG_INIT = UINT64_C(0), ///< Initial value for menvcfg + SENVCFG_INIT = UINT64_C(0), ///< Initial value for senvcfg + UARCH_HALT_FLAG_INIT = UINT64_C(0), ///< Initial value for microarchitecture halt flag + UARCH_X_INIT = UINT64_C(0), ///< Initial value for microarchitecture general purpose register x + UARCH_PC_INIT = AR_UARCH_RAM_START, ///< Initial value for microarchitecture pc + UARCH_CYCLE_INIT = UINT64_C(0), ///< Initial value for microarchitecture cycle + MHARTID_INIT = UINT64_C(0), ///< Initial mhartid + FDTADDR_INIT = AR_DTB_START, ///< Initial FDT address // Registers REG_X0 = UINT64_C(0), //< zero - hardwired zero diff --git a/src/send-cmio-response.cpp b/src/send-cmio-response.cpp index 4e41cd401..058640687 100644 --- a/src/send-cmio-response.cpp +++ b/src/send-cmio-response.cpp @@ -22,7 +22,7 @@ #include "send-cmio-response.h" #include "machine-merkle-tree.h" -#include "pma-constants.h" +#include "pmas-constants.h" #include "record-send-cmio-state-access.h" #include "replay-send-cmio-state-access.h" #include "state-access.h" @@ -45,10 +45,10 @@ void send_cmio_response(STATE_ACCESS a, uint16 reason, bytes data, uint32 dataLe if (uint32ShiftLeft(1, writeLengthLog2Size) < dataLength) { writeLengthLog2Size += 1; } - if (writeLengthLog2Size > PMA_CMIO_RX_BUFFER_LOG2_SIZE) { + if (writeLengthLog2Size > AR_CMIO_RX_BUFFER_LOG2_SIZE) { throwRuntimeError(a, "CMIO response data is too large"); } - writeMemoryWithPadding(a, PMA_CMIO_RX_BUFFER_START, data, dataLength, writeLengthLog2Size); + writeMemoryWithPadding(a, AR_CMIO_RX_BUFFER_START, data, dataLength, writeLengthLog2Size); } // Write data length and reason to fromhost const uint64 mask16 = uint64ShiftLeft(1, 16) - 1; diff --git a/src/shadow-state-address-range.h b/src/shadow-state-address-range.h index 59b350601..45023bb42 100644 --- a/src/shadow-state-address-range.h +++ b/src/shadow-state-address-range.h @@ -30,7 +30,7 @@ namespace cartesi { class shadow_state_address_range final : public address_range { - static constexpr pma_flags m_shadow_state_flags{ + static constexpr pmas_flags m_shadow_state_flags{ .M = false, .IO = true, .E = false, diff --git a/src/shadow-state.h b/src/shadow-state.h index 73766cde8..57ebad79c 100644 --- a/src/shadow-state.h +++ b/src/shadow-state.h @@ -22,7 +22,7 @@ #include "address-range.h" #include "compiler-defines.h" -#include "pma-constants.h" +#include "pmas-constants.h" #include "riscv-constants.h" /// \file @@ -79,117 +79,117 @@ struct PACKED shadow_state { }; enum class shadow_state_what : uint64_t { - x0 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[0]), - x1 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[1]), - x2 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[2]), - x3 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[3]), - x4 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[4]), - x5 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[5]), - x6 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[6]), - x7 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[7]), - x8 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[8]), - x9 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[9]), - x10 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[10]), - x11 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[11]), - x12 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[12]), - x13 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[13]), - x14 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[14]), - x15 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[15]), - x16 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[16]), - x17 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[17]), - x18 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[18]), - x19 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[19]), - x20 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[20]), - x21 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[21]), - x22 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[22]), - x23 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[23]), - x24 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[24]), - x25 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[25]), - x26 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[26]), - x27 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[27]), - x28 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[28]), - x29 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[29]), - x30 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[30]), - x31 = PMA_SHADOW_STATE_START + offsetof(shadow_state, x[31]), - f0 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[0]), - f1 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[1]), - f2 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[2]), - f3 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[3]), - f4 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[4]), - f5 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[5]), - f6 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[6]), - f7 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[7]), - f8 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[8]), - f9 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[9]), - f10 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[10]), - f11 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[11]), - f12 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[12]), - f13 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[13]), - f14 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[14]), - f15 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[15]), - f16 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[16]), - f17 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[17]), - f18 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[18]), - f19 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[19]), - f20 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[20]), - f21 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[21]), - f22 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[22]), - f23 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[23]), - f24 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[24]), - f25 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[25]), - f26 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[26]), - f27 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[27]), - f28 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[28]), - f29 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[29]), - f30 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[30]), - f31 = PMA_SHADOW_STATE_START + offsetof(shadow_state, f[31]), - pc = PMA_SHADOW_STATE_START + offsetof(shadow_state, pc), - fcsr = PMA_SHADOW_STATE_START + offsetof(shadow_state, fcsr), - mvendorid = PMA_SHADOW_STATE_START + offsetof(shadow_state, mvendorid), - marchid = PMA_SHADOW_STATE_START + offsetof(shadow_state, marchid), - mimpid = PMA_SHADOW_STATE_START + offsetof(shadow_state, mimpid), - mcycle = PMA_SHADOW_STATE_START + offsetof(shadow_state, mcycle), - icycleinstret = PMA_SHADOW_STATE_START + offsetof(shadow_state, icycleinstret), - mstatus = PMA_SHADOW_STATE_START + offsetof(shadow_state, mstatus), - mtvec = PMA_SHADOW_STATE_START + offsetof(shadow_state, mtvec), - mscratch = PMA_SHADOW_STATE_START + offsetof(shadow_state, mscratch), - mepc = PMA_SHADOW_STATE_START + offsetof(shadow_state, mepc), - mcause = PMA_SHADOW_STATE_START + offsetof(shadow_state, mcause), - mtval = PMA_SHADOW_STATE_START + offsetof(shadow_state, mtval), - misa = PMA_SHADOW_STATE_START + offsetof(shadow_state, misa), - mie = PMA_SHADOW_STATE_START + offsetof(shadow_state, mie), - mip = PMA_SHADOW_STATE_START + offsetof(shadow_state, mip), - medeleg = PMA_SHADOW_STATE_START + offsetof(shadow_state, medeleg), - mideleg = PMA_SHADOW_STATE_START + offsetof(shadow_state, mideleg), - mcounteren = PMA_SHADOW_STATE_START + offsetof(shadow_state, mcounteren), - menvcfg = PMA_SHADOW_STATE_START + offsetof(shadow_state, menvcfg), - stvec = PMA_SHADOW_STATE_START + offsetof(shadow_state, stvec), - sscratch = PMA_SHADOW_STATE_START + offsetof(shadow_state, sscratch), - sepc = PMA_SHADOW_STATE_START + offsetof(shadow_state, sepc), - scause = PMA_SHADOW_STATE_START + offsetof(shadow_state, scause), - stval = PMA_SHADOW_STATE_START + offsetof(shadow_state, stval), - satp = PMA_SHADOW_STATE_START + offsetof(shadow_state, satp), - scounteren = PMA_SHADOW_STATE_START + offsetof(shadow_state, scounteren), - senvcfg = PMA_SHADOW_STATE_START + offsetof(shadow_state, senvcfg), - ilrsc = PMA_SHADOW_STATE_START + offsetof(shadow_state, ilrsc), - iprv = PMA_SHADOW_STATE_START + offsetof(shadow_state, iprv), - iflags_X = PMA_SHADOW_STATE_START + offsetof(shadow_state, iflags_X), - iflags_Y = PMA_SHADOW_STATE_START + offsetof(shadow_state, iflags_Y), - iflags_H = PMA_SHADOW_STATE_START + offsetof(shadow_state, iflags_H), - iunrep = PMA_SHADOW_STATE_START + offsetof(shadow_state, iunrep), - clint_mtimecmp = PMA_SHADOW_STATE_START + offsetof(shadow_state, clint_mtimecmp), - plic_girqpend = PMA_SHADOW_STATE_START + offsetof(shadow_state, plic_girqpend), - plic_girqsrvd = PMA_SHADOW_STATE_START + offsetof(shadow_state, plic_girqsrvd), - htif_tohost = PMA_SHADOW_STATE_START + offsetof(shadow_state, htif_tohost), - htif_fromhost = PMA_SHADOW_STATE_START + offsetof(shadow_state, htif_fromhost), - htif_ihalt = PMA_SHADOW_STATE_START + offsetof(shadow_state, htif_ihalt), - htif_iconsole = PMA_SHADOW_STATE_START + offsetof(shadow_state, htif_iconsole), - htif_iyield = PMA_SHADOW_STATE_START + offsetof(shadow_state, htif_iyield), + x0 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[0]), + x1 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[1]), + x2 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[2]), + x3 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[3]), + x4 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[4]), + x5 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[5]), + x6 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[6]), + x7 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[7]), + x8 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[8]), + x9 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[9]), + x10 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[10]), + x11 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[11]), + x12 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[12]), + x13 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[13]), + x14 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[14]), + x15 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[15]), + x16 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[16]), + x17 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[17]), + x18 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[18]), + x19 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[19]), + x20 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[20]), + x21 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[21]), + x22 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[22]), + x23 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[23]), + x24 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[24]), + x25 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[25]), + x26 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[26]), + x27 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[27]), + x28 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[28]), + x29 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[29]), + x30 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[30]), + x31 = AR_SHADOW_STATE_START + offsetof(shadow_state, x[31]), + f0 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[0]), + f1 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[1]), + f2 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[2]), + f3 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[3]), + f4 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[4]), + f5 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[5]), + f6 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[6]), + f7 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[7]), + f8 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[8]), + f9 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[9]), + f10 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[10]), + f11 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[11]), + f12 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[12]), + f13 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[13]), + f14 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[14]), + f15 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[15]), + f16 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[16]), + f17 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[17]), + f18 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[18]), + f19 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[19]), + f20 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[20]), + f21 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[21]), + f22 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[22]), + f23 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[23]), + f24 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[24]), + f25 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[25]), + f26 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[26]), + f27 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[27]), + f28 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[28]), + f29 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[29]), + f30 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[30]), + f31 = AR_SHADOW_STATE_START + offsetof(shadow_state, f[31]), + pc = AR_SHADOW_STATE_START + offsetof(shadow_state, pc), + fcsr = AR_SHADOW_STATE_START + offsetof(shadow_state, fcsr), + mvendorid = AR_SHADOW_STATE_START + offsetof(shadow_state, mvendorid), + marchid = AR_SHADOW_STATE_START + offsetof(shadow_state, marchid), + mimpid = AR_SHADOW_STATE_START + offsetof(shadow_state, mimpid), + mcycle = AR_SHADOW_STATE_START + offsetof(shadow_state, mcycle), + icycleinstret = AR_SHADOW_STATE_START + offsetof(shadow_state, icycleinstret), + mstatus = AR_SHADOW_STATE_START + offsetof(shadow_state, mstatus), + mtvec = AR_SHADOW_STATE_START + offsetof(shadow_state, mtvec), + mscratch = AR_SHADOW_STATE_START + offsetof(shadow_state, mscratch), + mepc = AR_SHADOW_STATE_START + offsetof(shadow_state, mepc), + mcause = AR_SHADOW_STATE_START + offsetof(shadow_state, mcause), + mtval = AR_SHADOW_STATE_START + offsetof(shadow_state, mtval), + misa = AR_SHADOW_STATE_START + offsetof(shadow_state, misa), + mie = AR_SHADOW_STATE_START + offsetof(shadow_state, mie), + mip = AR_SHADOW_STATE_START + offsetof(shadow_state, mip), + medeleg = AR_SHADOW_STATE_START + offsetof(shadow_state, medeleg), + mideleg = AR_SHADOW_STATE_START + offsetof(shadow_state, mideleg), + mcounteren = AR_SHADOW_STATE_START + offsetof(shadow_state, mcounteren), + menvcfg = AR_SHADOW_STATE_START + offsetof(shadow_state, menvcfg), + stvec = AR_SHADOW_STATE_START + offsetof(shadow_state, stvec), + sscratch = AR_SHADOW_STATE_START + offsetof(shadow_state, sscratch), + sepc = AR_SHADOW_STATE_START + offsetof(shadow_state, sepc), + scause = AR_SHADOW_STATE_START + offsetof(shadow_state, scause), + stval = AR_SHADOW_STATE_START + offsetof(shadow_state, stval), + satp = AR_SHADOW_STATE_START + offsetof(shadow_state, satp), + scounteren = AR_SHADOW_STATE_START + offsetof(shadow_state, scounteren), + senvcfg = AR_SHADOW_STATE_START + offsetof(shadow_state, senvcfg), + ilrsc = AR_SHADOW_STATE_START + offsetof(shadow_state, ilrsc), + iprv = AR_SHADOW_STATE_START + offsetof(shadow_state, iprv), + iflags_X = AR_SHADOW_STATE_START + offsetof(shadow_state, iflags_X), + iflags_Y = AR_SHADOW_STATE_START + offsetof(shadow_state, iflags_Y), + iflags_H = AR_SHADOW_STATE_START + offsetof(shadow_state, iflags_H), + iunrep = AR_SHADOW_STATE_START + offsetof(shadow_state, iunrep), + clint_mtimecmp = AR_SHADOW_STATE_START + offsetof(shadow_state, clint_mtimecmp), + plic_girqpend = AR_SHADOW_STATE_START + offsetof(shadow_state, plic_girqpend), + plic_girqsrvd = AR_SHADOW_STATE_START + offsetof(shadow_state, plic_girqsrvd), + htif_tohost = AR_SHADOW_STATE_START + offsetof(shadow_state, htif_tohost), + htif_fromhost = AR_SHADOW_STATE_START + offsetof(shadow_state, htif_fromhost), + htif_ihalt = AR_SHADOW_STATE_START + offsetof(shadow_state, htif_ihalt), + htif_iconsole = AR_SHADOW_STATE_START + offsetof(shadow_state, htif_iconsole), + htif_iyield = AR_SHADOW_STATE_START + offsetof(shadow_state, htif_iyield), unknown_ = UINT64_C(1) << 63, // Outside of RISC-V address space }; static constexpr shadow_state_what shadow_state_get_what(uint64_t paddr) { - if (paddr < PMA_SHADOW_STATE_START || paddr - PMA_SHADOW_STATE_START >= sizeof(shadow_state) || + if (paddr < AR_SHADOW_STATE_START || paddr - AR_SHADOW_STATE_START >= sizeof(shadow_state) || (paddr & (sizeof(uint64_t) - 1)) != 0) { return shadow_state_what::unknown_; } @@ -203,7 +203,7 @@ static constexpr shadow_state_what shadow_state_get_what(shadow_state_what what, static constexpr const char *shadow_state_get_what_name(shadow_state_what what) { const auto paddr = static_cast(what); - if (paddr < PMA_SHADOW_STATE_START || paddr - PMA_SHADOW_STATE_START >= sizeof(shadow_state) || + if (paddr < AR_SHADOW_STATE_START || paddr - AR_SHADOW_STATE_START >= sizeof(shadow_state) || (paddr & (sizeof(uint64_t) - 1)) != 0) { return "state.unknown_"; } diff --git a/src/shadow-tlb-address-range.h b/src/shadow-tlb-address-range.h index 1956ba99b..7067e94fe 100644 --- a/src/shadow-tlb-address-range.h +++ b/src/shadow-tlb-address-range.h @@ -30,7 +30,7 @@ namespace cartesi { class shadow_tlb_address_range final : public address_range { - static constexpr pma_flags m_shadow_tlb_flags{ + static constexpr pmas_flags m_shadow_tlb_flags{ .M = false, .IO = true, .E = false, diff --git a/src/shadow-tlb-factory.h b/src/shadow-tlb-factory.h index b372d7a67..635b63d3e 100644 --- a/src/shadow-tlb-factory.h +++ b/src/shadow-tlb-factory.h @@ -28,7 +28,7 @@ namespace cartesi { /// \param start Start address for memory range. /// \param length Length of memory range. /// \returns Corresponding PMA entry -pma_entry make_shadow_tlb_pma_entry(uint64_t start, uint64_t length); +pmas_entry make_shadow_tlb_pmas_entry(uint64_t start, uint64_t length); } // namespace cartesi diff --git a/src/shadow-tlb.h b/src/shadow-tlb.h index c7b6df025..f6e9bfeee 100644 --- a/src/shadow-tlb.h +++ b/src/shadow-tlb.h @@ -58,7 +58,7 @@ using shadow_tlb_set = std::array; /// \brief Shadow TLB memory layout using shadow_tlb_state = std::array; // one set for code, one for read and one for write -static_assert(PMA_SHADOW_TLB_LENGTH >= sizeof(shadow_tlb_state), "TLB state must fit in TLB shadow"); +static_assert(AR_SHADOW_TLB_LENGTH >= sizeof(shadow_tlb_state), "TLB state must fit in TLB shadow"); /// \brief List of field types enum class shadow_tlb_what : uint64_t { @@ -70,7 +70,7 @@ enum class shadow_tlb_what : uint64_t { }; static constexpr uint64_t shadow_tlb_get_abs_addr(TLB_set_index set_index, uint64_t slot_index) { - return PMA_SHADOW_TLB_START + (set_index * sizeof(shadow_tlb_set)) + (slot_index * sizeof(shadow_tlb_slot)); + return AR_SHADOW_TLB_START + (set_index * sizeof(shadow_tlb_set)) + (slot_index * sizeof(shadow_tlb_slot)); } static constexpr uint64_t shadow_tlb_get_abs_addr(TLB_set_index set_index, uint64_t slot_index, shadow_tlb_what what) { @@ -78,11 +78,11 @@ static constexpr uint64_t shadow_tlb_get_abs_addr(TLB_set_index set_index, uint6 } static constexpr shadow_tlb_what shadow_tlb_get_what(uint64_t paddr, TLB_set_index &set_index, uint64_t &slot_index) { - if (paddr < PMA_SHADOW_TLB_START || paddr - PMA_SHADOW_TLB_START >= sizeof(shadow_tlb_state) || + if (paddr < AR_SHADOW_TLB_START || paddr - AR_SHADOW_TLB_START >= sizeof(shadow_tlb_state) || (paddr & (sizeof(uint64_t) - 1)) != 0) { return shadow_tlb_what::unknown_; } - paddr -= PMA_SHADOW_TLB_START; + paddr -= AR_SHADOW_TLB_START; set_index = TLB_set_index{paddr / sizeof(shadow_tlb_set)}; slot_index = (paddr % sizeof(shadow_tlb_set)) / sizeof(shadow_tlb_slot); return shadow_tlb_what{paddr % sizeof(shadow_tlb_slot)}; diff --git a/src/shadow-uarch-state-address-range.cpp b/src/shadow-uarch-state-address-range.cpp index b4d19b54c..61dfdf649 100644 --- a/src/shadow-uarch-state-address-range.cpp +++ b/src/shadow-uarch-state-address-range.cpp @@ -20,13 +20,13 @@ #include "machine-reg.h" #include "machine.h" -#include "pma-constants.h" +#include "pmas-constants.h" #include "shadow-peek.h" #include "shadow-uarch-state.h" namespace cartesi { -/// \brief Shadow uarch state device peek callback. See ::pma_peek. +/// \brief Shadow uarch state device peek callback. See ::pmas_peek. bool shadow_uarch_state_address_range::do_peek(const machine &m, uint64_t offset, uint64_t length, const unsigned char **data, unsigned char *scratch) const noexcept { // If past useful range diff --git a/src/shadow-uarch-state-address-range.h b/src/shadow-uarch-state-address-range.h index f9b286111..cc2972f5b 100644 --- a/src/shadow-uarch-state-address-range.h +++ b/src/shadow-uarch-state-address-range.h @@ -30,7 +30,7 @@ namespace cartesi { class shadow_uarch_state_address_range final : public address_range { - static constexpr pma_flags m_shadow_uarch_state_flags{ + static constexpr pmas_flags m_shadow_uarch_state_flags{ .M = false, .IO = true, .E = false, diff --git a/src/shadow-uarch-state.h b/src/shadow-uarch-state.h index a5ff6d92e..ded6e0201 100644 --- a/src/shadow-uarch-state.h +++ b/src/shadow-uarch-state.h @@ -37,46 +37,46 @@ struct PACKED shadow_uarch_state { }; enum class shadow_uarch_state_what : uint64_t { - uarch_halt_flag = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, halt_flag), - uarch_cycle = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, cycle), - uarch_pc = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, pc), - uarch_x0 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[0]), - uarch_x1 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[1]), - uarch_x2 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[2]), - uarch_x3 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[3]), - uarch_x4 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[4]), - uarch_x5 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[5]), - uarch_x6 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[6]), - uarch_x7 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[7]), - uarch_x8 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[8]), - uarch_x9 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[9]), - uarch_x10 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[10]), - uarch_x11 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[11]), - uarch_x12 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[12]), - uarch_x13 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[13]), - uarch_x14 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[14]), - uarch_x15 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[15]), - uarch_x16 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[16]), - uarch_x17 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[17]), - uarch_x18 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[18]), - uarch_x19 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[19]), - uarch_x20 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[20]), - uarch_x21 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[21]), - uarch_x22 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[22]), - uarch_x23 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[23]), - uarch_x24 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[24]), - uarch_x25 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[25]), - uarch_x26 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[26]), - uarch_x27 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[27]), - uarch_x28 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[28]), - uarch_x29 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[29]), - uarch_x30 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[30]), - uarch_x31 = PMA_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[31]), + uarch_halt_flag = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, halt_flag), + uarch_cycle = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, cycle), + uarch_pc = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, pc), + uarch_x0 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[0]), + uarch_x1 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[1]), + uarch_x2 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[2]), + uarch_x3 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[3]), + uarch_x4 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[4]), + uarch_x5 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[5]), + uarch_x6 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[6]), + uarch_x7 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[7]), + uarch_x8 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[8]), + uarch_x9 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[9]), + uarch_x10 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[10]), + uarch_x11 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[11]), + uarch_x12 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[12]), + uarch_x13 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[13]), + uarch_x14 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[14]), + uarch_x15 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[15]), + uarch_x16 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[16]), + uarch_x17 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[17]), + uarch_x18 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[18]), + uarch_x19 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[19]), + uarch_x20 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[20]), + uarch_x21 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[21]), + uarch_x22 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[22]), + uarch_x23 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[23]), + uarch_x24 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[24]), + uarch_x25 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[25]), + uarch_x26 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[26]), + uarch_x27 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[27]), + uarch_x28 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[28]), + uarch_x29 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[29]), + uarch_x30 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[30]), + uarch_x31 = AR_SHADOW_UARCH_STATE_START + offsetof(shadow_uarch_state, x[31]), unknown_ = UINT64_C(1) << 63, // Outside of RISC-V address space }; static constexpr shadow_uarch_state_what shadow_uarch_state_get_what(uint64_t paddr) { - if (paddr < PMA_SHADOW_UARCH_STATE_START || paddr - PMA_SHADOW_UARCH_STATE_START >= sizeof(shadow_uarch_state) || + if (paddr < AR_SHADOW_UARCH_STATE_START || paddr - AR_SHADOW_UARCH_STATE_START >= sizeof(shadow_uarch_state) || (paddr & (sizeof(uint64_t) - 1)) != 0) { return shadow_uarch_state_what::unknown_; } @@ -90,7 +90,7 @@ static constexpr shadow_uarch_state_what shadow_uarch_state_get_what(shadow_uarc static constexpr const char *shadow_uarch_state_get_what_name(shadow_uarch_state_what what) { const auto paddr = static_cast(what); - if (paddr < PMA_SHADOW_UARCH_STATE_START || paddr - PMA_SHADOW_UARCH_STATE_START >= sizeof(shadow_uarch_state) || + if (paddr < AR_SHADOW_UARCH_STATE_START || paddr - AR_SHADOW_UARCH_STATE_START >= sizeof(shadow_uarch_state) || (paddr & (sizeof(uint64_t) - 1)) != 0) { return "uarch.unknown_"; } diff --git a/src/state-access.h b/src/state-access.h index 86c4c883f..6f079853a 100644 --- a/src/state-access.h +++ b/src/state-access.h @@ -36,7 +36,7 @@ #include "machine-state.h" #include "machine.h" #include "os.h" -#include "pma-constants.h" +#include "pmas-constants.h" #include "riscv-constants.h" #include "shadow-tlb.h" #include "strict-aliasing.h" diff --git a/src/tlb.h b/src/tlb.h index 0383e7da1..f78905b1d 100644 --- a/src/tlb.h +++ b/src/tlb.h @@ -26,7 +26,7 @@ #include #include "host-addr.h" -#include "pma-constants.h" +#include "pmas-constants.h" #include "riscv-constants.h" namespace cartesi { diff --git a/src/translate-virtual-address.h b/src/translate-virtual-address.h index 3d8b536f4..73b11d0bb 100644 --- a/src/translate-virtual-address.h +++ b/src/translate-virtual-address.h @@ -46,7 +46,7 @@ #include #include "compiler-defines.h" -#include "find-pma-entry.h" +#include "find-pmas-entry.h" #include "riscv-constants.h" namespace cartesi { diff --git a/src/uarch-constants.h b/src/uarch-constants.h index da52db2e2..6930cc527 100644 --- a/src/uarch-constants.h +++ b/src/uarch-constants.h @@ -17,8 +17,7 @@ #ifndef UARCH_CONSTANTS_H #define UARCH_CONSTANTS_H -#include "pma-constants.h" -#include "pma-defines.h" +#include "address-range-constants.h" #include "uarch-defines.h" #include @@ -32,10 +31,10 @@ enum uarch_state_constants : uint64_t { UARCH_STATE_LOG2_SIZE = EXPAND_UINT64_C(UARCH_STATE_LOG2_SIZE_DEF), ///< Log2 size of the uarch state: shadow + ram UARCH_STATE_CHILD_LOG2_SIZE = UARCH_STATE_LOG2_SIZE - 1, ///< Log2 size of a uarch state child: shadow or ram UARCH_SHADOW_START_ADDRESS = - EXPAND_UINT64_C(PMA_SHADOW_UARCH_STATE_START_DEF), ///< Start address of the shadow uarch state - UARCH_SHADOW_LENGTH = EXPAND_UINT64_C(PMA_SHADOW_UARCH_STATE_LENGTH_DEF), ///< Length of the shadow uarch state - UARCH_RAM_START_ADDRESS = EXPAND_UINT64_C(PMA_UARCH_RAM_START_DEF), ///< Start address of the uarch ram - UARCH_RAM_LENGTH = EXPAND_UINT64_C(PMA_UARCH_RAM_LENGTH_DEF), ///< Length of the uarch ram + EXPAND_UINT64_C(AR_SHADOW_UARCH_STATE_START_DEF), ///< Start address of the shadow uarch state + UARCH_SHADOW_LENGTH = EXPAND_UINT64_C(AR_SHADOW_UARCH_STATE_LENGTH_DEF), ///< Length of the shadow uarch state + UARCH_RAM_START_ADDRESS = EXPAND_UINT64_C(AR_UARCH_RAM_START_DEF), ///< Start address of the uarch ram + UARCH_RAM_LENGTH = EXPAND_UINT64_C(AR_UARCH_RAM_LENGTH_DEF), ///< Length of the uarch ram UARCH_STATE_ALIGN_MASK = (EXPAND_UINT64_C(1) << UARCH_STATE_LOG2_SIZE) - 1, ///< Mask for uarch state alignment UARCH_STATE_MASK = ~UARCH_STATE_ALIGN_MASK, ///< Mask for uarch state address space UARCH_STATE_CHILD_ALIGN_MASK = @@ -58,9 +57,8 @@ static_assert(UARCH_SHADOW_LENGTH <= (static_cast(1) << UARCH_STATE_CH "UARCH_SHADOW_LENGTH is too big"); static_assert(UARCH_SHADOW_START_ADDRESS < UARCH_RAM_START_ADDRESS, "UARCH_SHADOW_START_ADDRESS must be smaller than UARCH_RAN_START_ADDRESS"); -static_assert((UARCH_SHADOW_LENGTH & (PMA_PAGE_SIZE - 1)) == 0, - "UARCH_SHADOW_LENGTH must be multiple of PMA_PAGE_SIZE"); -static_assert((UARCH_RAM_LENGTH & (PMA_PAGE_SIZE - 1)) == 0, "UARCH_RAM_LENGTH must be multiple of PMA_PAGE_SIZE"); +static_assert((UARCH_SHADOW_LENGTH & (AR_PAGE_SIZE - 1)) == 0, "UARCH_SHADOW_LENGTH must be multiple of AR_PAGE_SIZE"); +static_assert((UARCH_RAM_LENGTH & (AR_PAGE_SIZE - 1)) == 0, "UARCH_RAM_LENGTH must be multiple of AR_PAGE_SIZE"); /// \brief ecall function codes enum uarch_ecall_functions : uint64_t { diff --git a/src/uarch-defines.h b/src/uarch-defines.h index c5d3abb8b..db2aabac4 100644 --- a/src/uarch-defines.h +++ b/src/uarch-defines.h @@ -17,10 +17,10 @@ #ifndef UARCH_DEFINES_H #define UARCH_DEFINES_H -#include "pma-defines.h" +#include "address-range-defines.h" // NOLINTBEGIN(cppcoreguidelines-macro-usage,cppcoreguidelines-macro-to-enum,modernize-macro-to-enum) /// \brief Start address of the entire uarch memory range: shadow and ram -#define UARCH_STATE_START_ADDRESS_DEF PMA_SHADOW_UARCH_STATE_START_DEF +#define UARCH_STATE_START_ADDRESS_DEF AR_SHADOW_UARCH_STATE_START_DEF /// \brief Log2 size of the entire uarch memory range: shadow and ram #define UARCH_STATE_LOG2_SIZE_DEF 22 diff --git a/src/virtio-address-range.cpp b/src/virtio-address-range.cpp index 92dbf0fc9..25e196889 100644 --- a/src/virtio-address-range.cpp +++ b/src/virtio-address-range.cpp @@ -827,7 +827,7 @@ bool virtio_address_range::do_read_device(i_device_state_access *a, uint64_t off return status; } -/// \brief VirtIO device read callback. See ::pma_write. +/// \brief VirtIO device read callback. See ::pmas_write. execute_status virtio_address_range::do_write_device(i_device_state_access *a, uint64_t offset, int log2_size, uint64_t val) noexcept { #ifdef DEBUG_VIRTIO_MMIO diff --git a/src/virtio-address-range.h b/src/virtio-address-range.h index 4e45c0159..337f3b784 100644 --- a/src/virtio-address-range.h +++ b/src/virtio-address-range.h @@ -257,7 +257,7 @@ class virtio_address_range : public pristine_address_range { uint32_t config_generation = 0; ///< Configuration generation counter uint32_t config_space_size = 0; ///< Configuration size - static constexpr pma_flags m_virtio_flags{ + static constexpr pmas_flags m_virtio_flags{ .M = false, .IO = true, .E = false, diff --git a/tests/lua/htif-cmio.lua b/tests/lua/htif-cmio.lua index 60d0ae858..935732a14 100755 --- a/tests/lua/htif-cmio.lua +++ b/tests/lua/htif-cmio.lua @@ -41,14 +41,14 @@ local function test(config) local machine = cartesi.machine(config) -- fill input with `pattern` - local rx_length = 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE - machine:write_memory(cartesi.PMA_CMIO_RX_BUFFER_START, string.rep(pattern, rx_length / 8), rx_length) + local rx_length = 1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE + machine:write_memory(cartesi.AR_CMIO_RX_BUFFER_START, string.rep(pattern, rx_length / 8), rx_length) machine:run(math.maxinteger) -- check that buffers got filled in with `pattern` - local tx_length = 1 << cartesi.PMA_CMIO_TX_BUFFER_LOG2_SIZE - assert(string.rep(pattern, tx_length / 8) == machine:read_memory(cartesi.PMA_CMIO_TX_BUFFER_START, tx_length)) + local tx_length = 1 << cartesi.AR_CMIO_TX_BUFFER_LOG2_SIZE + assert(string.rep(pattern, tx_length / 8) == machine:read_memory(cartesi.AR_CMIO_TX_BUFFER_START, tx_length)) assert(machine:read_reg("iflags_H") ~= 0) diff --git a/tests/lua/machine-bind.lua b/tests/lua/machine-bind.lua index 448b2e68d..521ce3220 100755 --- a/tests/lua/machine-bind.lua +++ b/tests/lua/machine-bind.lua @@ -1141,7 +1141,7 @@ print("\n\ntesting send cmio response ") do_test("send_cmio_response fails if iflags.Y is not set", function(machine) local reason = 1 - local data = string.rep("a", 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE) + local data = string.rep("a", 1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE) machine:write_reg("iflags_Y", 0) assert(machine:read_reg("iflags_Y") == 0) test_util.assert_error("iflags.Y is not set", function() @@ -1154,7 +1154,7 @@ end) do_test("send_cmio_response fails if data is too big", function(machine) local reason = 1 - local data_too_big = string.rep("a", 1 + (1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE)) + local data_too_big = string.rep("a", 1 + (1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE)) machine:write_reg("iflags_Y", 1) test_util.assert_error("CMIO response data is too large", function() machine:send_cmio_response(reason, data_too_big) @@ -1173,31 +1173,23 @@ local function assert_access(accesses, index, expected_key_and_values) end end -local function dump_pmas(machine) - for _, v in ipairs(machine:get_address_ranges()) do - local filename = string.format("%016x--%016x.bin", v.start, v.length) - local file = assert(io.open(filename, "w")) - assert(file:write(machine:read_memory(v.start, v.length))) - end -end - local function test_send_cmio_input_with_different_arguments() - local data = string.rep("a", 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE) + local data = string.rep("a", 1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE) local reason = 1 - local max_rx_buffer_len = 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE - local data_hash = test_util.merkle_hash(data, 0, cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE) + local max_rx_buffer_len = 1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE + local data_hash = test_util.merkle_hash(data, 0, cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE) local all_zeros = string.rep("\0", max_rx_buffer_len) - local all_zeros_hash = test_util.merkle_hash(all_zeros, 0, cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE) + local all_zeros_hash = test_util.merkle_hash(all_zeros, 0, cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE) -- prepares and asserts the state before send_cmio_response is called local function assert_before_cmio_response_sent(machine) machine:write_reg("iflags_Y", 1) -- initial rx buffer should be all zeros - assert(machine:read_memory(cartesi.PMA_CMIO_RX_BUFFER_START, max_rx_buffer_len) == all_zeros) + assert(machine:read_memory(cartesi.AR_CMIO_RX_BUFFER_START, max_rx_buffer_len) == all_zeros) end -- asserts that the machine state is as expected after send_cmio_response is called local function assert_after_cmio_response_sent(machine) -- rx buffer should now contain the data - assert(machine:read_memory(cartesi.PMA_CMIO_RX_BUFFER_START, max_rx_buffer_len) == data) + assert(machine:read_memory(cartesi.AR_CMIO_RX_BUFFER_START, max_rx_buffer_len) == data) -- iflags.Y should be cleared assert(machine:read_reg("iflags_Y") == 0) -- fromhost should reflect the reason and data length @@ -1222,7 +1214,6 @@ local function test_send_cmio_input_with_different_arguments() | (large_data and cartesi.ACCESS_LOG_TYPE_LARGE_DATA or 0) assert_before_cmio_response_sent(machine) local root_hash_before = machine:get_root_hash() - dump_pmas(machine) local log = machine:log_send_cmio_response(reason, data, log_type) assert_after_cmio_response_sent(machine) local root_hash_after = machine:get_root_hash() @@ -1236,8 +1227,8 @@ local function test_send_cmio_input_with_different_arguments() }) assert_access(accesses, 2, { type = "write", - address = cartesi.PMA_CMIO_RX_BUFFER_START, - log2_size = cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE, + address = cartesi.AR_CMIO_RX_BUFFER_START, + log2_size = cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE, read_hash = all_zeros_hash, read = large_data and all_zeros or nil, written_hash = data_hash, @@ -1295,7 +1286,7 @@ do_test("send_cmio_response with different data sizes", function(machine) { data_len = (1 << 20) + 1, write_len = 1 << 21 }, { data_len = 1 << 21, write_len = 1 << 21 }, } - local rx_buffer_size = 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE + local rx_buffer_size = 1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE local initial_rx_buffer = string.rep("x", rx_buffer_size) local reason = 1 local function padded_data(data, len, padding) @@ -1312,8 +1303,8 @@ do_test("send_cmio_response with different data sizes", function(machine) logging ) ) - machine:write_memory(cartesi.PMA_CMIO_RX_BUFFER_START, initial_rx_buffer) - assert(machine:read_memory(cartesi.PMA_CMIO_RX_BUFFER_START, rx_buffer_size) == initial_rx_buffer) + machine:write_memory(cartesi.AR_CMIO_RX_BUFFER_START, initial_rx_buffer) + assert(machine:read_memory(cartesi.AR_CMIO_RX_BUFFER_START, rx_buffer_size) == initial_rx_buffer) local data = string.rep("a", case.data_len) machine:write_reg("iflags_Y", 1) if logging then @@ -1326,7 +1317,7 @@ do_test("send_cmio_response with different data sizes", function(machine) end local expected_rx_buffer = padded_data(data, case.write_len, "\0") .. string.rep("x", rx_buffer_size - case.write_len) - local new_rx_buffer = machine:read_memory(cartesi.PMA_CMIO_RX_BUFFER_START, rx_buffer_size) + local new_rx_buffer = machine:read_memory(cartesi.AR_CMIO_RX_BUFFER_START, rx_buffer_size) assert( new_rx_buffer == expected_rx_buffer, string.format( @@ -1342,15 +1333,15 @@ do_test("send_cmio_response with different data sizes", function(machine) end) do_test("send_cmio_response of zero bytes", function(machine) - local rx_buffer_size = 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE + local rx_buffer_size = 1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE local initial_rx_buffer = string.rep("x", rx_buffer_size) - machine:write_memory(cartesi.PMA_CMIO_RX_BUFFER_START, initial_rx_buffer) - assert(machine:read_memory(cartesi.PMA_CMIO_RX_BUFFER_START, rx_buffer_size) == initial_rx_buffer) + machine:write_memory(cartesi.AR_CMIO_RX_BUFFER_START, initial_rx_buffer) + assert(machine:read_memory(cartesi.AR_CMIO_RX_BUFFER_START, rx_buffer_size) == initial_rx_buffer) machine:write_reg("iflags_Y", 1) local reason = 1 local data = "" machine:send_cmio_response(reason, data) - local new_rx_buffer = machine:read_memory(cartesi.PMA_CMIO_RX_BUFFER_START, rx_buffer_size) + local new_rx_buffer = machine:read_memory(cartesi.AR_CMIO_RX_BUFFER_START, rx_buffer_size) assert(new_rx_buffer == initial_rx_buffer, "rx_buffer should not have been modified") assert(machine:read_reg("iflags_Y") == 0, "iflags.Y should be cleared") -- log and verify @@ -1366,8 +1357,8 @@ end) local function test_cmio_buffers_backed_by_files() local rx_filename = os.tmpname() local tx_filename = os.tmpname() - local rx_init_data = string.rep("R", 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE) - local tx_init_data = string.rep("T", 1 << cartesi.PMA_CMIO_TX_BUFFER_LOG2_SIZE) + local rx_init_data = string.rep("R", 1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE) + local tx_init_data = string.rep("T", 1 << cartesi.AR_CMIO_TX_BUFFER_LOG2_SIZE) local deleter = {} setmetatable(deleter, { __gc = function() @@ -1382,8 +1373,8 @@ local function test_cmio_buffers_backed_by_files() local tx = assert(io.open(tx_filename, "w+")) tx:write(tx_init_data) tx:close() - local tx_new_data = string.rep("x", 1 << cartesi.PMA_CMIO_TX_BUFFER_LOG2_SIZE) - local rx_new_data = string.rep("y", 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE) + local tx_new_data = string.rep("x", 1 << cartesi.AR_CMIO_TX_BUFFER_LOG2_SIZE) + local rx_new_data = string.rep("y", 1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE) test_util.make_do_test(build_machine, machine_type, { cmio = { @@ -1391,13 +1382,13 @@ local function test_cmio_buffers_backed_by_files() tx_buffer = { image_filename = tx_filename, shared = false }, }, })("cmio buffers initialized from backing files", function(machine) - local rx_data = machine:read_memory(cartesi.PMA_CMIO_RX_BUFFER_START, 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE) + local rx_data = machine:read_memory(cartesi.AR_CMIO_RX_BUFFER_START, 1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE) assert(rx_data == rx_init_data, "rx buffer data does not match") - local tx_data = machine:read_memory(cartesi.PMA_CMIO_TX_BUFFER_START, 1 << cartesi.PMA_CMIO_TX_BUFFER_LOG2_SIZE) + local tx_data = machine:read_memory(cartesi.AR_CMIO_TX_BUFFER_START, 1 << cartesi.AR_CMIO_TX_BUFFER_LOG2_SIZE) assert(tx_data == tx_init_data, "tx buffer data does not match") -- write new data to buffers to later assert that it was not written to the files - machine:write_memory(cartesi.PMA_CMIO_RX_BUFFER_START, rx_new_data) - machine:write_memory(cartesi.PMA_CMIO_TX_BUFFER_START, tx_new_data) + machine:write_memory(cartesi.AR_CMIO_RX_BUFFER_START, rx_new_data) + machine:write_memory(cartesi.AR_CMIO_TX_BUFFER_START, tx_new_data) end) -- the shared=false from last test should prevent saving the new data to files test_util.make_do_test(build_machine, machine_type, { @@ -1406,13 +1397,13 @@ local function test_cmio_buffers_backed_by_files() tx_buffer = { image_filename = tx_filename, shared = true }, }, })("cmio buffers initialized from backing files should not change", function(machine) - local rx_data = machine:read_memory(cartesi.PMA_CMIO_RX_BUFFER_START, 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE) + local rx_data = machine:read_memory(cartesi.AR_CMIO_RX_BUFFER_START, 1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE) assert(rx_data == rx_init_data, "rx buffer data does not match") - local tx_data = machine:read_memory(cartesi.PMA_CMIO_TX_BUFFER_START, 1 << cartesi.PMA_CMIO_TX_BUFFER_LOG2_SIZE) + local tx_data = machine:read_memory(cartesi.AR_CMIO_TX_BUFFER_START, 1 << cartesi.AR_CMIO_TX_BUFFER_LOG2_SIZE) assert(tx_data == tx_init_data, "tx buffer data does not match") -- write new data to buffers to later assert that it was written to the files - machine:write_memory(cartesi.PMA_CMIO_RX_BUFFER_START, rx_new_data) - machine:write_memory(cartesi.PMA_CMIO_TX_BUFFER_START, tx_new_data) + machine:write_memory(cartesi.AR_CMIO_RX_BUFFER_START, rx_new_data) + machine:write_memory(cartesi.AR_CMIO_TX_BUFFER_START, tx_new_data) end) -- the shared=true from last test should save memory changes to files test_util.make_do_test(build_machine, machine_type, { @@ -1421,9 +1412,9 @@ local function test_cmio_buffers_backed_by_files() tx_buffer = { image_filename = tx_filename, shared = false }, }, })("cmio buffer files should be modified by last write_memory", function(machine) - local rx_data = machine:read_memory(cartesi.PMA_CMIO_RX_BUFFER_START, 1 << cartesi.PMA_CMIO_RX_BUFFER_LOG2_SIZE) + local rx_data = machine:read_memory(cartesi.AR_CMIO_RX_BUFFER_START, 1 << cartesi.AR_CMIO_RX_BUFFER_LOG2_SIZE) assert(rx_data == rx_new_data, "rx buffer data does not match") - local tx_data = machine:read_memory(cartesi.PMA_CMIO_TX_BUFFER_START, 1 << cartesi.PMA_CMIO_TX_BUFFER_LOG2_SIZE) + local tx_data = machine:read_memory(cartesi.AR_CMIO_TX_BUFFER_START, 1 << cartesi.AR_CMIO_TX_BUFFER_LOG2_SIZE) assert(tx_data == tx_new_data, "tx buffer data does not match") end) end diff --git a/tests/lua/machine-test.lua b/tests/lua/machine-test.lua index e9ea46b39..f0127e736 100755 --- a/tests/lua/machine-test.lua +++ b/tests/lua/machine-test.lua @@ -155,7 +155,7 @@ do_test("machine halt and yield flags and config matches", function(machine) local initial_config = machine:get_initial_config() -- test_util.print_table(initial_config) assert(initial_config["processor"]["marchid"] == cartesi.MARCHID, "marchid value does not match") - assert(initial_config["processor"]["pc"] == cartesi.PMA_RAM_START, "pc value does not match") + assert(initial_config["processor"]["pc"] == cartesi.AR_RAM_START, "pc value does not match") assert(initial_config["ram"]["length"] == 1048576, "ram length value does not match") -- Check machine is not halted assert(machine:read_reg("iflags_H") == 0, "machine shouldn't be halted") @@ -291,7 +291,7 @@ end print("\n\nwrite something to ram memory and check if hash and proof matches") do_test("proof and root hash should match", function(machine) - local ram_address_start = cartesi.PMA_RAM_START + local ram_address_start = cartesi.AR_RAM_START -- Find proof for first KB of ram local initial_ram_proof = machine:get_proof(ram_address_start, 10) diff --git a/tests/machine/src/access.S b/tests/machine/src/access.S index 24470c76f..d73d08f1f 100644 --- a/tests/machine/src/access.S +++ b/tests/machine/src/access.S @@ -15,7 +15,7 @@ */ -#include +#include #define exit_imm(imm) \ li gp, imm; \ @@ -139,6 +139,6 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/bootstrap.S b/tests/machine/src/bootstrap.S index 9cf8bdc4b..a20ce4f21 100644 --- a/tests/machine/src/bootstrap.S +++ b/tests/machine/src/bootstrap.S @@ -15,13 +15,13 @@ */ -#include +#include .section .text.init; .align 2; .global _start; _start: - li t0, PMA_RAM_START_DEF; // converted to 2 instructions addiw and slli + li t0, AR_RAM_START_DEF; // converted to 2 instructions addiw and slli csrr a0, mhartid; jr t0; diff --git a/tests/machine/src/clint_ops.S b/tests/machine/src/clint_ops.S index 2e8342078..69ea8d05e 100644 --- a/tests/machine/src/clint_ops.S +++ b/tests/machine/src/clint_ops.S @@ -17,7 +17,7 @@ // This programs exercise load/writes in the CLINT device. -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -49,12 +49,12 @@ _start: csrw mtvec, t0; // Load CLINT.MTIME, it should equal to zero at the very start - li t0, PMA_CLINT_START_DEF + O_MTIME; + li t0, AR_CLINT_START_DEF + O_MTIME; ld t1, 0(t0); bnez t1, fail; // Store and load CLINT.MSIP - li t0, PMA_CLINT_START_DEF + O_MSIP; + li t0, AR_CLINT_START_DEF + O_MSIP; li t1, 0xffffffffff; sw t1, 0(t0); lw t2, 0(t0); // note that this won't raise an interrupts, because mip should be 0 @@ -65,7 +65,7 @@ _start: bne t2, t3, fail; // make sure mie.MSIP is set // Store and load CLINT.MTIMECMP - li t0, PMA_CLINT_START_DEF + O_MTIMECMP; + li t0, AR_CLINT_START_DEF + O_MTIMECMP; li t1, 0xffffffffffffffff; sd t1, 0(t0); ld t2, 0(t0); @@ -77,49 +77,49 @@ _start: // Attempt to load a non 4-bytes value from CLINT.MSIP expect_trap(MCAUSE_LOAD_ACCESS_FAULT, - li t0, PMA_CLINT_START_DEF + O_MSIP; + li t0, AR_CLINT_START_DEF + O_MSIP; ld t1, 0(t0); ) // Attempt to load a non 8-bytes value from CLINT.MTIMECMP expect_trap(MCAUSE_LOAD_ACCESS_FAULT, - li t0, PMA_CLINT_START_DEF + O_MTIMECMP; + li t0, AR_CLINT_START_DEF + O_MTIMECMP; lw t1, 0(t0); ) // Attempt to load a non 8-bytes value from CLINT.MTIME expect_trap(MCAUSE_LOAD_ACCESS_FAULT, - li t0, PMA_CLINT_START_DEF + O_MTIME; + li t0, AR_CLINT_START_DEF + O_MTIME; lw t1, 0(t0); ) // Attempt to load from an invalid CLINT offset expect_trap(MCAUSE_LOAD_ACCESS_FAULT, - li t0, PMA_CLINT_START_DEF + 1; + li t0, AR_CLINT_START_DEF + 1; lb t1, 0(t0); ) // Attempt to store a non 4-bytes value in CLINT.MSIP expect_trap(MCAUSE_STORE_AMO_ACCESS_FAULT, - li t0, PMA_CLINT_START_DEF + O_MSIP; + li t0, AR_CLINT_START_DEF + O_MSIP; sd zero, 0(t0); ) // Attempt to store a non 8-bytes value in CLINT.MTIMECMP expect_trap(MCAUSE_STORE_AMO_ACCESS_FAULT, - li t0, PMA_CLINT_START_DEF + O_MTIMECMP; + li t0, AR_CLINT_START_DEF + O_MTIMECMP; sw zero, 0(t0); ) // Attempt to write to CLINT.MTIME expect_trap(MCAUSE_STORE_AMO_ACCESS_FAULT, - li t0, PMA_CLINT_START_DEF + O_MTIME; + li t0, AR_CLINT_START_DEF + O_MTIME; sd zero, 0(t0); ) // Attempt to store in an invalid CLINT offset expect_trap(MCAUSE_STORE_AMO_ACCESS_FAULT, - li t0, PMA_CLINT_START_DEF + 1; + li t0, AR_CLINT_START_DEF + 1; sb zero, 0(t0); ) @@ -143,6 +143,6 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; diff --git a/tests/machine/src/compressed.S b/tests/machine/src/compressed.S index e612360e3..e164c92d9 100644 --- a/tests/machine/src/compressed.S +++ b/tests/machine/src/compressed.S @@ -15,7 +15,7 @@ */ -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -214,7 +214,7 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/csr_counters.S b/tests/machine/src/csr_counters.S index cfe0ba4d3..bece06355 100644 --- a/tests/machine/src/csr_counters.S +++ b/tests/machine/src/csr_counters.S @@ -17,7 +17,7 @@ // This test case tests all hardware counters in different privilege modes -#include +#include #define exit_imm(imm) \ li gp, imm; \ @@ -361,6 +361,6 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/csr_semantics.S b/tests/machine/src/csr_semantics.S index 1a3009d83..4ee1c8e3c 100644 --- a/tests/machine/src/csr_semantics.S +++ b/tests/machine/src/csr_semantics.S @@ -17,7 +17,7 @@ // This test case tests many CSR semantics in different privilege modes -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -320,6 +320,6 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/dont_write_x0.S b/tests/machine/src/dont_write_x0.S index 77b3b02f2..63adb8a60 100644 --- a/tests/machine/src/dont_write_x0.S +++ b/tests/machine/src/dont_write_x0.S @@ -15,7 +15,7 @@ */ -#include +#include #define MSTATUS_FS_MASK (3<<13) @@ -147,7 +147,7 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/ebreak.S b/tests/machine/src/ebreak.S index 9dbf1e9fb..bcf8615ce 100644 --- a/tests/machine/src/ebreak.S +++ b/tests/machine/src/ebreak.S @@ -15,7 +15,7 @@ */ -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -57,7 +57,7 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/htif_cmio.S b/tests/machine/src/htif_cmio.S index c21f08e62..fbd6f60db 100644 --- a/tests/machine/src/htif_cmio.S +++ b/tests/machine/src/htif_cmio.S @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include "htif_util.h" // This test will fetch the cmio buffers from the PMA entries; check that @@ -38,7 +39,7 @@ #define PMA_START_DID_CONST(did) ((did) << 8) #define PMA_START_DID_MASK 0x0000000000000f00 -#define PMA_START_START_MASK 0xfffffffffffff000 +#define AR_START_START_MASK 0xfffffffffffff000 .global _start .align 2; @@ -61,7 +62,7 @@ _start: * a0: a pma_did_const(x) * ret: pointer to pma entry */ find_pma_by_did: - li t0, PMA_SHADOW_PMAS_START_DEF; + li t0, AR_PMAS_START_DEF; li t2, PMA_START_DID_MASK; /* is the pma array empty? */ ld t1, O_LENGTH (t0); @@ -86,7 +87,7 @@ found: fill_pma_with_a2: ld a1, O_LENGTH(a0); ld a0, O_START (a0); - li t0, PMA_START_START_MASK; + li t0, AR_START_START_MASK; and a0, a0, t0; j memset64; // tail call @@ -108,7 +109,7 @@ l2: jr ra; check_pma_with_a2: ld a1, O_LENGTH(a0); ld a0, O_START (a0); - li t0, PMA_START_START_MASK; + li t0, AR_START_START_MASK; and a0, a0, t0; j memcheck64; diff --git a/tests/machine/src/htif_console.S b/tests/machine/src/htif_console.S index da27dead5..66aba2128 100644 --- a/tests/machine/src/htif_console.S +++ b/tests/machine/src/htif_console.S @@ -70,7 +70,7 @@ wait: ret is_console_getchar_enabled: - li t0, PMA_HTIF_START_DEF; \ + li t0, AR_HTIF_START_DEF; \ ld t0, O_ICONSOLE (t0); \ srli t0, t0, HTIF_CONSOLE_CMD_GETCHAR_DEF; \ andi a0, t0, 1; diff --git a/tests/machine/src/htif_invalid_ops.S b/tests/machine/src/htif_invalid_ops.S index d0a7a6710..ee0f4a659 100644 --- a/tests/machine/src/htif_invalid_ops.S +++ b/tests/machine/src/htif_invalid_ops.S @@ -43,7 +43,7 @@ _start: csrw mtvec, t0; // Unknown HTIF devices are silently ignored - li t0, PMA_HTIF_START_DEF; + li t0, AR_HTIF_START_DEF; li t1, htif_const(0xff, 0, 0); sd zero, O_FROMHOST(t0); sd t1, O_TOHOST(t0); @@ -51,7 +51,7 @@ _start: bnez t2, fail; // HTIF halt with invalid commands is silently ignored - li t0, PMA_HTIF_START_DEF; + li t0, AR_HTIF_START_DEF; li t1, htif_const(HTIF_DEV_HALT_DEF, 0xff, 3); sd zero, O_FROMHOST(t0); sd t1, O_TOHOST(t0); @@ -59,7 +59,7 @@ _start: bnez t2, fail; // HTIF halt with exit least-signed bit unset is silently ignored - li t0, PMA_HTIF_START_DEF; + li t0, AR_HTIF_START_DEF; li t1, htif_const(HTIF_DEV_HALT_DEF, HTIF_HALT_CMD_HALT_DEF, 2); sd zero, O_FROMHOST(t0); sd t1, O_TOHOST(t0); @@ -72,39 +72,39 @@ _start: // Attempt to load a non 8-bytes value from HTIF expect_trap(MCAUSE_LOAD_ACCESS_FAULT, - li t0, PMA_HTIF_START_DEF; + li t0, AR_HTIF_START_DEF; lw t1, O_TOHOST(t0); ) // Attempt to load from a misaligned HTIF offset expect_trap(MCAUSE_LOAD_ACCESS_FAULT, - li t0, PMA_HTIF_START_DEF; + li t0, AR_HTIF_START_DEF; lb t1, 1(t0); ) // Attempt to load from an invalid HTIF offset expect_trap(MCAUSE_LOAD_ACCESS_FAULT, - li t0, PMA_HTIF_START_DEF; + li t0, AR_HTIF_START_DEF; ld t1, (O_IYIELD+8)(t0); ) // Attempt to store a non 8-bytes value in HTIF expect_trap(MCAUSE_STORE_AMO_ACCESS_FAULT, - li t0, PMA_HTIF_START_DEF; + li t0, AR_HTIF_START_DEF; li t1, 3; sw t1, O_TOHOST(t0); ) // Attempt to store in a misaligned HTIF offset expect_trap(MCAUSE_STORE_AMO_ACCESS_FAULT, - li t0, PMA_HTIF_START_DEF; + li t0, AR_HTIF_START_DEF; li t1, 3; sb t1, 1(t0); ) // Attempt to store in an invalid HTIF offset expect_trap(MCAUSE_STORE_AMO_ACCESS_FAULT, - li t0, PMA_HTIF_START_DEF; + li t0, AR_HTIF_START_DEF; li t1, 3; sd t1, (O_IYIELD+8)(t0); ) @@ -129,6 +129,6 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; diff --git a/tests/machine/src/htif_util.h b/tests/machine/src/htif_util.h index 820de173e..ab2908660 100644 --- a/tests/machine/src/htif_util.h +++ b/tests/machine/src/htif_util.h @@ -1,6 +1,6 @@ #ifndef HTIF_UTIL_H #define HTIF_UTIL_H -#include +#include #include /* from: https://www.cartesi.io/en/docs/machine/target/architecture/ @@ -36,7 +36,7 @@ // Issue a HTIF call with `ireg` as the input, place the output in `oreg`. // NOTE: `base` will be used as scratch register #define htif_call(base, ireg, oreg) \ - li base, PMA_HTIF_START_DEF; \ + li base, AR_HTIF_START_DEF; \ sd zero, O_FROMHOST (base); \ sd ireg, O_TOHOST (base); \ ld oreg, O_FROMHOST (base) diff --git a/tests/machine/src/htif_yield.S b/tests/machine/src/htif_yield.S index 7e5ff7d0b..e06c8a953 100644 --- a/tests/machine/src/htif_yield.S +++ b/tests/machine/src/htif_yield.S @@ -28,7 +28,7 @@ // Check HTIF fromhost address for yield command ack #define check_htif_ack(dev, cmd, data) \ - li t0, PMA_HTIF_START_DEF; \ + li t0, AR_HTIF_START_DEF; \ ld t3, O_IYIELD (t0); \ srli t3, t3, cmd; \ andi t3, t3, 1; \ @@ -46,7 +46,7 @@ and t0, t0, t2; \ or t1, t1, t0; \ and t1, t1, t3; /* if cmd is disabled, expect 0 ack */ \ - li t0, PMA_HTIF_START_DEF; \ + li t0, AR_HTIF_START_DEF; \ ld t2, O_FROMHOST (t0); \ bne t1, t2, ack_failed; @@ -122,7 +122,7 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF; + li t0, AR_HTIF_START_DEF; sd x0, O_FROMHOST (t0); sd gp, O_TOHOST (t0); j 1b; // unreachable diff --git a/tests/machine/src/illegal_insn.S b/tests/machine/src/illegal_insn.S index 296a51ce8..4e6d36761 100644 --- a/tests/machine/src/illegal_insn.S +++ b/tests/machine/src/illegal_insn.S @@ -15,7 +15,7 @@ */ -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -203,7 +203,7 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/interrupts.S b/tests/machine/src/interrupts.S index e3cb4bbe6..db5612b0f 100644 --- a/tests/machine/src/interrupts.S +++ b/tests/machine/src/interrupts.S @@ -17,7 +17,7 @@ // This test case tests software interrupts and interrupt delegation -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -33,7 +33,7 @@ #define MCAUSE_SSIP ((1< +#include #define exit_imm(imm) \ li gp, imm; \ @@ -68,10 +68,10 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary .data .align 3; foo: .dword 0 -.align 3; boo: .dword 0 \ No newline at end of file +.align 3; boo: .dword 0 diff --git a/tests/machine/src/mcycle_overflow.S b/tests/machine/src/mcycle_overflow.S index 31fdb51f3..b9a307412 100644 --- a/tests/machine/src/mcycle_overflow.S +++ b/tests/machine/src/mcycle_overflow.S @@ -15,7 +15,7 @@ */ -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -58,7 +58,7 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/mcycle_write.S b/tests/machine/src/mcycle_write.S index 15a929867..6da637fd5 100644 --- a/tests/machine/src/mcycle_write.S +++ b/tests/machine/src/mcycle_write.S @@ -15,7 +15,7 @@ */ -#include +#include #define exit_imm(imm) \ li gp, imm; \ @@ -52,6 +52,6 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/mtime_interrupt.S b/tests/machine/src/mtime_interrupt.S index 328a51ec5..841de9270 100644 --- a/tests/machine/src/mtime_interrupt.S +++ b/tests/machine/src/mtime_interrupt.S @@ -19,7 +19,7 @@ // WFI loop for this interrupt to happen. When the interrupt occurs, the test // checks whether the cause CSR is set properly. -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -27,7 +27,7 @@ j exit; // MTIMECMP is a CLINT register that is mapped to RAM -#define MTIMECMP_ADDR (PMA_CLINT_START_DEF + 0x4000) +#define MTIMECMP_ADDR (AR_CLINT_START_DEF + 0x4000) #define MTIE_MASK (1<<7) #define MIE_MASK (1<<3) @@ -90,6 +90,6 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/pte_reserved_exception.S b/tests/machine/src/pte_reserved_exception.S index 3c9273025..b5974c2db 100644 --- a/tests/machine/src/pte_reserved_exception.S +++ b/tests/machine/src/pte_reserved_exception.S @@ -15,7 +15,7 @@ */ -#include +#include #define MSTATUS_MPP 0x1800 #define CAUSE_USER_ECALL 0x8 @@ -79,7 +79,7 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/sd_pma_overflow.S b/tests/machine/src/sd_pma_overflow.S index 1aded5e2a..072dc275d 100644 --- a/tests/machine/src/sd_pma_overflow.S +++ b/tests/machine/src/sd_pma_overflow.S @@ -15,7 +15,7 @@ */ -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -53,6 +53,6 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/shadow_ops.S b/tests/machine/src/shadow_ops.S index 530f36547..1c3336f12 100644 --- a/tests/machine/src/shadow_ops.S +++ b/tests/machine/src/shadow_ops.S @@ -17,7 +17,7 @@ // This programs exercise load/writes in the shadow. -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -32,9 +32,9 @@ #define MCAUSE_STORE_AMO_ACCESS_FAULT 0x7 #define MCAUSE_LOAD_ACCESS_FAULT 0x5 -#define SHADOWS_PMA_LAST_ENTRY_ISTART (31*16) -#define SHADOWS_PMA_LAST_ENTRY_ILENGTH (31*16+8) -#define SHADOWS_PMA_TOTAL_SIZE (32*16) +#define PMAS_LAST_ENTRY_ISTART (31*16) +#define PMAS_LAST_ENTRY_ILENGTH (31*16+8) +#define PMAS_TOTAL_SIZE (32*16) #define EMPTY_PMA_ISTART (4) #define EMPTY_PMA_ILENGTH (0) @@ -48,11 +48,11 @@ _start: csrw mtvec, t0; // We are allowed to read the shadow PMAs - li t0, PMA_SHADOW_PMAS_START_DEF; - ld t1, SHADOWS_PMA_LAST_ENTRY_ISTART(t0); + li t0, AR_PMAS_START_DEF; + ld t1, PMAS_LAST_ENTRY_ISTART(t0); li t2, EMPTY_PMA_ISTART bne t1, t2, fail; - ld t1, SHADOWS_PMA_LAST_ENTRY_ILENGTH(t0); + ld t1, PMAS_LAST_ENTRY_ILENGTH(t0); li t2, EMPTY_PMA_ILENGTH bne t1, t2, fail; @@ -62,31 +62,31 @@ _start: // Attempt to load a value from the shadow state expect_trap(MCAUSE_LOAD_ACCESS_FAULT, - li t0, PMA_SHADOW_STATE_START_DEF; + li t0, AR_SHADOW_STATE_START_DEF; ld t1, 8(t0); ) // Attempt to load a value from the shadow TLB expect_trap(MCAUSE_LOAD_ACCESS_FAULT, - li t0, PMA_SHADOW_TLB_START_DEF; + li t0, AR_SHADOW_TLB_START_DEF; ld t1, 0(t0); ) // Attempt to store a value in the shadow PMAs expect_trap(MCAUSE_STORE_AMO_ACCESS_FAULT, - li t0, PMA_SHADOW_PMAS_START_DEF; + li t0, AR_PMAS_START_DEF; sd x0, 0(t0); ) // Attempt to store a value in the shadow state expect_trap(MCAUSE_STORE_AMO_ACCESS_FAULT, - li t0, PMA_SHADOW_STATE_START_DEF; + li t0, AR_SHADOW_STATE_START_DEF; sd x0, 8(t0); ) // Attempt to store a value in the shadow TLB expect_trap(MCAUSE_STORE_AMO_ACCESS_FAULT, - li t0, PMA_SHADOW_TLB_START_DEF; + li t0, AR_SHADOW_TLB_START_DEF; sd x0, 0(t0); ) @@ -110,6 +110,6 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; diff --git a/tests/machine/src/translate_vaddr.S b/tests/machine/src/translate_vaddr.S index cea1655bf..d628d746d 100644 --- a/tests/machine/src/translate_vaddr.S +++ b/tests/machine/src/translate_vaddr.S @@ -15,7 +15,7 @@ */ -#include +#include #include #define PTE_FLAGS (PTE_V | PTE_R | PTE_W | PTE_X | PTE_U) @@ -286,7 +286,7 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/version_check.S b/tests/machine/src/version_check.S index 564d87443..a642717ca 100644 --- a/tests/machine/src/version_check.S +++ b/tests/machine/src/version_check.S @@ -15,7 +15,7 @@ */ -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -67,6 +67,6 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/machine/src/xpie_exceptions.S b/tests/machine/src/xpie_exceptions.S index d741d8172..efb84ebb4 100644 --- a/tests/machine/src/xpie_exceptions.S +++ b/tests/machine/src/xpie_exceptions.S @@ -15,7 +15,7 @@ */ -#include +#include // Uses HTIF to exit the emulator with exit code in an immediate #define exit_imm(imm) \ @@ -110,6 +110,6 @@ exit: srli gp, gp, 15; ori gp, gp, 1; 1: - li t0, PMA_HTIF_START_DEF + li t0, AR_HTIF_START_DEF sd gp, 0(t0); j 1b; // Should not be necessary diff --git a/tests/misc/test-machine-c-api.cpp b/tests/misc/test-machine-c-api.cpp index 11ab4f23f..ec101a8db 100644 --- a/tests/misc/test-machine-c-api.cpp +++ b/tests/misc/test-machine-c-api.cpp @@ -990,7 +990,7 @@ BOOST_FIXTURE_TEST_CASE_NOLINT(read_write_uarch_x_basic_test, ordinary_machine_f uint64_t uarch_x2_addr{}; BOOST_CHECK_EQUAL(cm_get_reg_address(_machine, CM_REG_UARCH_X2, &uarch_x2_addr), CM_ERROR_OK); - BOOST_CHECK_EQUAL(static_cast(cartesi::PMA_SHADOW_UARCH_STATE_START + 40), uarch_x2_addr); + BOOST_CHECK_EQUAL(static_cast(cartesi::AR_SHADOW_UARCH_STATE_START + 40), uarch_x2_addr); } BOOST_AUTO_TEST_CASE_NOLINT(read_reg_null_machine_test) { @@ -1460,11 +1460,11 @@ BOOST_FIXTURE_TEST_CASE_NOLINT(machine_reset_uarch, ordinary_machine_fixture) { // change the uarch ram in order to confirm if reset will restore it to the initial value std::array random_bytes{1, 2, 3, 4, 5, 6, 7, 8}; - error_code = cm_write_memory(_machine, cartesi::PMA_UARCH_RAM_START, random_bytes.data(), random_bytes.size()); + error_code = cm_write_memory(_machine, cartesi::AR_UARCH_RAM_START, random_bytes.data(), random_bytes.size()); BOOST_REQUIRE_EQUAL(error_code, CM_ERROR_OK); // grab the modified ram bytes - std::vector modified_uarch_ram(cartesi::PMA_UARCH_RAM_LENGTH); + std::vector modified_uarch_ram(cartesi::AR_UARCH_RAM_LENGTH); error_code = cm_read_memory(_machine, cartesi::UARCH_RAM_START_ADDRESS, modified_uarch_ram.data(), modified_uarch_ram.size()); BOOST_REQUIRE_EQUAL(error_code, CM_ERROR_OK); diff --git a/uarch/compute-uarch-pristine-hash.cpp b/uarch/compute-uarch-pristine-hash.cpp index caf0c09b3..87ed4f92e 100644 --- a/uarch/compute-uarch-pristine-hash.cpp +++ b/uarch/compute-uarch-pristine-hash.cpp @@ -35,8 +35,8 @@ using hash_type = tree_type::hash_type; using hashertype = tree_type::hasher_type; using proof_type = tree_type::proof_type; -static_assert(PMA_PAGE_SIZE == tree_type::get_page_size(), "PMA and machine_merkle_tree page sizes must match"); -static_assert(sizeof(shadow_uarch_state) <= PMA_PAGE_SIZE, "shadow_uarch_state must fit in one page"); +static_assert(AR_PAGE_SIZE == tree_type::get_page_size(), "PMA and machine_merkle_tree page sizes must match"); +static_assert(sizeof(shadow_uarch_state) <= AR_PAGE_SIZE, "shadow_uarch_state must fit in one page"); /// \brief Prints help message static void help(const char *name) { @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) try { } // Allocate scratch page buffer - auto scratch = make_unique_calloc(PMA_PAGE_SIZE, std::nothrow_t{}); + auto scratch = make_unique_calloc(AR_PAGE_SIZE, std::nothrow_t{}); if (!scratch) { throw std::runtime_error("Could not allocate scratch memory"); } @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) try { // Build pristine shadow uarch state // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto *shadow = reinterpret_cast(scratch.get()); - memset(scratch.get(), 0, PMA_PAGE_SIZE); + memset(scratch.get(), 0, AR_PAGE_SIZE); shadow->halt_flag = UARCH_HALT_FLAG_INIT; shadow->pc = UARCH_PC_INIT; shadow->cycle = UARCH_CYCLE_INIT; @@ -94,10 +94,10 @@ int main(int argc, char *argv[]) try { throw std::runtime_error("Could not update uarch shadow tree node hash"); } // Add all pages of uarch ram to merkle tree - for (uint32_t p = 0; p < uarch_pristine_ram_len; p += PMA_PAGE_SIZE) { + for (uint32_t p = 0; p < uarch_pristine_ram_len; p += AR_PAGE_SIZE) { const auto *page_data = uarch_pristine_ram + p; - if (p + PMA_PAGE_SIZE > uarch_pristine_ram_len) { - memset(scratch.get(), 0, PMA_PAGE_SIZE); + if (p + AR_PAGE_SIZE > uarch_pristine_ram_len) { + memset(scratch.get(), 0, AR_PAGE_SIZE); memcpy(scratch.get(), uarch_pristine_ram + p, uarch_pristine_ram_len - p); page_data = scratch.get(); } diff --git a/uarch/machine-uarch-bridge-state-access.h b/uarch/machine-uarch-bridge-state-access.h index bcf842a8d..65230497e 100644 --- a/uarch/machine-uarch-bridge-state-access.h +++ b/uarch/machine-uarch-bridge-state-access.h @@ -27,9 +27,8 @@ #include "i-state-access.h" #include "machine-reg.h" #include "mock-address-range.h" -#include "pma-constants.h" +#include "pmas.h" #include "riscv-constants.h" -#include "shadow-pmas.h" #include "shadow-tlb.h" #include "uarch-constants.h" #include "uarch-defines.h" @@ -73,11 +72,11 @@ class machine_uarch_bridge_state_access : } static uint64_t bridge_read_pma_istart(int i) { - return ua_aliased_aligned_read(shadow_pmas_get_pma_abs_addr(i, shadow_pmas_what::istart)); + return ua_aliased_aligned_read(pmas_get_abs_addr(i, pmas_what::istart)); } static uint64_t bridge_read_pma_ilength(int i) { - return ua_aliased_aligned_read(shadow_pmas_get_pma_abs_addr(i, shadow_pmas_what::ilength)); + return ua_aliased_aligned_read(pmas_get_abs_addr(i, pmas_what::ilength)); } static uint64_t bridge_read_shadow_tlb(TLB_set_index set_index, uint64_t slot_index, shadow_tlb_what what) { diff --git a/uarch/uarch-ram-entry.S b/uarch/uarch-ram-entry.S index f8fca7184..0d39dacd9 100644 --- a/uarch/uarch-ram-entry.S +++ b/uarch/uarch-ram-entry.S @@ -14,7 +14,7 @@ // with this program (see COPYING). If not, see . // -#include +#include #include .section .text.init; @@ -22,8 +22,8 @@ .global _start; _start: // Initialize stack - li sp, PMA_UARCH_RAM_START_DEF - li t0, PMA_UARCH_RAM_LENGTH_DEF + li sp, AR_UARCH_RAM_START_DEF + li t0, AR_UARCH_RAM_LENGTH_DEF add sp, sp, t0 // stack pointer at the end of RAM call interpret_next_mcycle_with_uarch diff --git a/uarch/uarch-ram.ld.in b/uarch/uarch-ram.ld.in index 3a883325d..55874fbaf 100644 --- a/uarch/uarch-ram.ld.in +++ b/uarch/uarch-ram.ld.in @@ -1,17 +1,17 @@ OUTPUT_ARCH( "riscv" ) ENTRY(_start) -#include "pma-defines.h" +#include "address-range-defines.h" SECTIONS { - . = PMA_UARCH_RAM_START_DEF; + . = AR_UARCH_RAM_START_DEF; .text.init : { *(.text.init) } .text : { *(.text) } - .rodata : { *(.rodata) } + .rodata : { *(.rodata) } .sdata : { *(.sdata) } - .bss : { *(.bss) } - .tdata : { *(.tdata) } - + .bss : { *(.bss) } + .tdata : { *(.tdata) } + _end = .; }