Skip to content

Commit

Permalink
fixup! feat!: Bump emulator and grpc-interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
vfusco committed Nov 21, 2023
1 parent 896b931 commit f0a1d8e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 29 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/grpc-interfaces"]
path = lib/grpc-interfaces
url = ../grpc-interfaces.git
[submodule "lib/machine-emulator-defines"]
path = lib/machine-emulator-defines
url = ../machine-emulator-defines.git
1 change: 0 additions & 1 deletion lib/machine-emulator-defines
Submodule machine-emulator-defines deleted from c30dfb
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ GRPC_INC=$(GRPC_INC_$(UNAME))
PROTOBUF_LIB=$(PROTOBUF_LIB_$(UNAME))
CARTESI_EXECUTABLE_LDFLAGS=$(CARTESI_EXECUTABLE_LDFLAGS_$(UNAME))

SERVER_MANAGER_LIBS:=$(CRYPTOPP_LIB) $(GRPC_LIB) $(BOOST_CORO_LIB) $(BOOST_LOG_LIB) -ldl
SERVER_MANAGER_LIBS:=$(CRYPTOPP_LIB) $(GRPC_LIB) $(BOOST_CORO_LIB) $(BOOST_LOG_LIB) $(BOOST_FILESYSTEM_LIB) -ldl
TEST_SERVER_MANAGER_LIBS:=$(CRYPTOPP_LIB) $(GRPC_LIB) -ldl

WARNS=-W -Wall -pedantic
Expand Down
55 changes: 55 additions & 0 deletions src/htif-defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef HTIF_DEFINES_H
#define HTIF_DEFINES_H

#include <cstdint>

/// \brief HTIF protocol shifts
enum HTIF_protocol_shift : uint64_t { HTIF_DEV_SHIFT = 56, HTIF_CMD_SHIFT = 48, HTIF_DATA_SHIFT = 0 };

/// \brief HTIF protocol masks
enum HTIF_protocol_mask : uint64_t {
HTIF_DEV_MASK = 0xFF00000000000000,
HTIF_CMD_MASK = 0x00FF000000000000,
HTIF_DATA_MASK = 0x0000FFFFFFFFFFFF
};

/// \brief HTIF device identifiers
enum HTIF_device : uint64_t { HTIF_DEVICE_HALT = 0, HTIF_DEVICE_CONSOLE = 1, HTIF_DEVICE_YIELD = 2 };

/// \brief HTIF device commands
enum HTIF_device_command : uint64_t {
HTIF_HALT_HALT = 0,
HTIF_CONSOLE_GETCHAR = 0,
HTIF_CONSOLE_PUTCHAR = 1,
HTIF_YIELD_AUTOMATIC = 0,
HTIF_YIELD_MANUAL = 1
};

/// \brief HTIF yield reasons
enum HTIF_yield_reason : uint64_t {
HTIF_YIELD_REASON_PROGRESS = 0,
HTIF_YIELD_REASON_RX_ACCEPTED = 1,
HTIF_YIELD_REASON_RX_REJECTED = 2,
HTIF_YIELD_REASON_TX_VOUCHER = 3,
HTIF_YIELD_REASON_TX_NOTICE = 4,
HTIF_YIELD_REASON_TX_REPORT = 5,
HTIF_YIELD_REASON_TX_EXCEPTION = 6,
};

#endif /* end of include guard: HTIF_DEFINES_H */
36 changes: 12 additions & 24 deletions src/server-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,12 @@
#pragma clang diagnostic pop
#endif

#include <htif-defines.h>

#include "complete-merkle-tree.h"
#include "htif-defines.h"
#include "keccak-256-hasher.h"
#include "merkle-tree-proof.h"
#include "protobuf-util.h"

/// \brief HTIF yield reasons
enum HTIF_yield_reason : uint64_t {
HTIF_YIELD_REASON_PROGRESS = HTIF_YIELD_REASON_PROGRESS_DEF,
HTIF_YIELD_REASON_RX_ACCEPTED = HTIF_YIELD_REASON_RX_ACCEPTED_DEF,
HTIF_YIELD_REASON_RX_REJECTED = HTIF_YIELD_REASON_RX_REJECTED_DEF,
HTIF_YIELD_REASON_TX_VOUCHER = HTIF_YIELD_REASON_TX_VOUCHER_DEF,
HTIF_YIELD_REASON_TX_NOTICE = HTIF_YIELD_REASON_TX_NOTICE_DEF,
HTIF_YIELD_REASON_TX_REPORT = HTIF_YIELD_REASON_TX_REPORT_DEF,
HTIF_YIELD_REASON_TX_EXCEPTION = HTIF_YIELD_REASON_TX_EXCEPTION_DEF,
};

constexpr const uint64_t ROLLUP_ADVANCE_STATE = 0;
constexpr const uint64_t ROLLUP_INSPECT_STATE = 1;

Expand Down Expand Up @@ -1554,25 +1542,25 @@ void trigger_and_wait_checkin(handler_context &hctx, async_context &actx, T trig
/// \param data New data field
/// \return Register value with replaced data field
static constexpr uint64_t htif_replace_data_field(uint64_t reg, uint64_t data) {
return (reg & (~HTIF_DATA_MASK_DEF)) | ((data << HTIF_DATA_SHIFT_DEF) & HTIF_DATA_MASK_DEF);
return (reg & (~HTIF_DATA_MASK)) | ((data << HTIF_DATA_SHIFT) & HTIF_DATA_MASK);
}

/// \brief Obtains the dev field in HTIF's fromhost/tohost register value
/// \return Dev data field in register
static constexpr uint64_t htif_dev_field(uint64_t reg) {
return (reg & HTIF_DEV_MASK_DEF) >> HTIF_DEV_SHIFT_DEF;
return (reg & HTIF_DEV_MASK) >> HTIF_DEV_SHIFT;
}

/// \brief Extracts the cmd field in HTIF's fromhost/tohost register value
/// \return cmd data field in register
static constexpr uint64_t htif_cmd_field(uint64_t reg) {
return (reg & HTIF_CMD_MASK_DEF) >> HTIF_CMD_SHIFT_DEF;
return (reg & HTIF_CMD_MASK) >> HTIF_CMD_SHIFT;
}

/// \brief Extracts the data field in HTIF's fromhost/tohost register value
/// \return cmd data field in register
static constexpr uint64_t htif_data_field(uint64_t reg) {
return (reg & HTIF_DATA_MASK_DEF) >> HTIF_DATA_SHIFT_DEF;
return (reg & HTIF_DATA_MASK) >> HTIF_DATA_SHIFT;
}

/// \brief Checks if HTIF's tohost/fromhost matches an yield device manual command
Expand All @@ -1581,15 +1569,15 @@ static constexpr uint64_t htif_data_field(uint64_t reg) {
/// \param value Register value
static void check_htif_yield_manual(async_context &actx, const std::string &regname, uint64_t value) {
auto dev = htif_dev_field(value);
if (dev != HTIF_DEVICE_YIELD_DEF) {
if (dev != HTIF_DEVICE_YIELD) {
THROW((taint_session{actx.session, grpc::StatusCode::INTERNAL,
"invalid dev field in " + regname + " (expected " + std::to_string(HTIF_DEVICE_YIELD_DEF) + ", got " +
"invalid dev field in " + regname + " (expected " + std::to_string(HTIF_DEVICE_YIELD) + ", got " +
std::to_string(dev) + ")"}));
}
auto cmd = htif_cmd_field(value);
if (cmd != HTIF_YIELD_MANUAL_DEF) {
if (cmd != HTIF_YIELD_MANUAL) {
THROW((taint_session{actx.session, grpc::StatusCode::INTERNAL,
"invalid cmd field in " + regname + " (expected " + std::to_string(HTIF_YIELD_MANUAL_DEF) + ", got " +
"invalid cmd field in " + regname + " (expected " + std::to_string(HTIF_YIELD_MANUAL) + ", got " +
std::to_string(cmd) + ")"}));
}
}
Expand All @@ -1598,10 +1586,10 @@ static void check_htif_yield_manual(async_context &actx, const std::string &regn
/// \param value Register value
static void check_yield_reason_accepted(uint64_t value) {
auto data = htif_data_field(value) << 16 >> 48;
if (data != HTIF_YIELD_REASON_RX_ACCEPTED_DEF) {
if (data != HTIF_YIELD_REASON_RX_ACCEPTED) {
THROW((finish_error_yield_none{grpc::StatusCode::INVALID_ARGUMENT,
"invalid data field in htif.tohost (expected " + std::to_string(HTIF_YIELD_REASON_RX_ACCEPTED_DEF) +
", got " + std::to_string(data) + ")"}));
"invalid data field in htif.tohost (expected " + std::to_string(HTIF_YIELD_REASON_RX_ACCEPTED) + ", got " +
std::to_string(data) + ")"}));
}
}

Expand Down

0 comments on commit f0a1d8e

Please sign in to comment.