Skip to content

Major refactoring of address ranges (formerly PMAs) #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: refactor/uarch-state-accesses
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
third-party/** linguist-vendored
73 changes: 32 additions & 41 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ SLIRP_INC=-I$(BREW_PREFIX)/libslirp/include
# Macports installation
else ifneq (,$(PORT_PREFIX))
INSTALL_PREFIX=/opt/local
BOOST_LIB_DIR=-L$(INSTALL_PREFIX)/libexec/boost/1.81/lib
BOOST_INC=-I$(INSTALL_PREFIX)/libexec/boost/1.81/include
BOOST_LIB_DIR=-L$(INSTALL_PREFIX)/libexec/boost/1.87/lib
BOOST_INC=-I$(INSTALL_PREFIX)/libexec/boost/1.87/include
SLIRP_LIB=-L$(INSTALL_PREFIX)/lib -lslirp
SLIRP_INC=-I$(INSTALL_PREFIX)/include

Expand Down Expand Up @@ -133,8 +133,8 @@ ifeq ($(slirp),yes)
# Workaround for building with macports lua-luarocks installation
machine.o: INCS+=$(SLIRP_INC)
machine.clang-tidy: INCS+=$(SLIRP_INC)
virtio-net-carrier-slirp.o: INCS+=$(SLIRP_INC)
virtio-net-carrier-slirp.clang-tidy: INCS+=$(SLIRP_INC)
virtio-net-user-address-range.o: INCS+=$(SLIRP_INC)
virtio-net-user-address-range.clang-tidy: INCS+=$(SLIRP_INC)
#INCS+=$(SLIRP_INC)
LIBCARTESI_COMMON_LIBS+=$(SLIRP_LIB)
else
Expand Down Expand Up @@ -345,52 +345,43 @@ c-api: $(LIBCARTESI) $(LIBCARTESI_MERKLE_TREE) $(LIBCARTESI_JSONRPC)
.PHONY: all generate use clean lint format format-lua check-format check-format-lua luacartesi hash c-api compile_flags.txt

LIBCARTESI_OBJS:= \
pma-driver.o \
clint.o \
clint-factory.o \
plic.o \
plic-factory.o \
virtio-factory.o \
virtio-device.o \
virtio-console.o \
virtio-p9fs.o \
virtio-net.o \
virtio-net-carrier-tuntap.o \
virtio-net-carrier-slirp.o \
dtb.o \
os.o \
htif.o \
htif-factory.o \
shadow-state.o \
shadow-state-factory.o \
shadow-pmas-factory.o \
shadow-tlb.o \
shadow-tlb-factory.o \
shadow-uarch-state.o \
shadow-uarch-state-factory.o \
pma.o \
machine.o \
machine-config.o \
json-util.o \
base64.o \
clint-address-range.o \
dtb.o \
htif-address-range.o \
interpret.o \
virtual-machine.o \
sha3.o \
json-util.o \
machine-c-api.o \
machine-config.o \
machine-merkle-tree.o \
machine.o \
memory-address-range.o \
os.o \
plic-address-range.o \
pristine-merkle-tree.o \
machine-c-api.o \
replay-step-state-access-interop.o \
send-cmio-response.o \
sha3.o \
shadow-state-address-range.o \
shadow-tlb-address-range.o \
shadow-uarch-state-address-range.o \
uarch-pristine-hash.o \
uarch-pristine-ram.o \
uarch-pristine-state-hash.o \
uarch-pristine-hash.o \
uarch-interpret.o \
uarch-step.o \
uarch-reset-state.o \
send-cmio-response.o \
replay-step-state-access-interop.o
uarch-step.o \
local-machine.o \
uarch-interpret.o \
virtio-address-range.o \
virtio-console-address-range.o \
virtio-p9fs-address-range.o \
virtio-net-address-range.o \
virtio-net-tuntap-address-range.o \
virtio-net-user-address-range.o

CARTESI_CLUA_OBJS:= \
clua.o \
clua-i-virtual-machine.o \
clua-i-machine.o \
uarch-pristine-ram.o \
uarch-pristine-state-hash.o \
uarch-pristine-hash.o
Expand All @@ -411,7 +402,7 @@ MERKLE_TREE_HASH_OBJS:= \
merkle-tree-hash.o

LIBCARTESI_JSONRPC_OBJS:= \
jsonrpc-virtual-machine.o \
jsonrpc-machine.o \
os.o \
jsonrpc-machine-c-api.o \
uarch-pristine-ram.o \
Expand Down
77 changes: 77 additions & 0 deletions src/address-range-constants.h
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
//

#ifndef ADDRESS_RANGE_CONSTANTS_H
#define ADDRESS_RANGE_CONSTANTS_H

#include <cstdint>

#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), ///< Log<sub>2</sub> 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
58 changes: 58 additions & 0 deletions src/address-range-defines.h
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
//

#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 ///< log<sub>2</sub> 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 ///< log<sub>2</sub> 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 ///< log<sub>2</sub> 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 */
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
// with this program (see COPYING). If not, see <https://www.gnu.org/licenses/>.
//

#ifndef MACHINE_MEMORY_RANGE_DESCR_H
#define MACHINE_MEMORY_RANGE_DESCR_H
#ifndef ADDRESS_RANGE_DESCRIPTION_H
#define ADDRESS_RANGE_DESCRIPTION_H

#include <cstdint>
#include <string>
#include <vector>

namespace cartesi {

/// \brief Description of memory range used for introspection (i.e., get_memory_ranges())
struct machine_memory_range_descr {
/// \brief Description of an address range used for introspection (i.e., get_address_ranges())
struct address_range_description {
uint64_t start = 0; ///< Start of memory range
uint64_t length = 0; ///< Length of memory range
std::string description; ///< User-friendly description for memory range
};

/// \brief List of memory range descriptions used for introspection (i.e., get_memory_ranges())
using machine_memory_range_descrs = std::vector<machine_memory_range_descr>;
/// \brief List of address range descriptions used for introspection (i.e., get_address_ranges())
using address_range_descriptions = std::vector<address_range_description>;

} // namespace cartesi

Expand Down
Loading