Skip to content

Commit

Permalink
refactor!: remove read/write APIs for x and f registers
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Sep 9, 2024
1 parent 6d3e876 commit 3ff3d10
Show file tree
Hide file tree
Showing 18 changed files with 17 additions and 930 deletions.
96 changes: 0 additions & 96 deletions src/clua-i-virtual-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,54 +96,6 @@ static int machine_obj_index_read_csr(lua_State *L) {
return 1;
}

/// \brief This is the machine:read_x() method implementation.
/// \param L Lua state.
static int machine_obj_index_read_x(lua_State *L) {
auto &m = clua_check<clua_managed_cm_ptr<cm_machine>>(L, 1);
const int i = static_cast<int>(luaL_checkinteger(L, 2));
if (i < 0 || i >= X_REG_COUNT) {
luaL_error(L, "register index out of range");
}
uint64_t val{};
if (cm_read_x(m.get(), i, &val) != 0) {
return luaL_error(L, "%s", cm_get_last_error_message());
}
lua_pushinteger(L, static_cast<lua_Integer>(val));
return 1;
}

/// \brief This is the machine:read_f() method implementation.
/// \param L Lua state.
static int machine_obj_index_read_f(lua_State *L) {
auto &m = clua_check<clua_managed_cm_ptr<cm_machine>>(L, 1);
const int i = static_cast<int>(luaL_checkinteger(L, 2));
if (i < 0 || i >= F_REG_COUNT) {
luaL_error(L, "register index out of range");
}
uint64_t val{};
if (cm_read_f(m.get(), i, &val) != 0) {
return luaL_error(L, "%s", cm_get_last_error_message());
}
lua_pushinteger(L, static_cast<lua_Integer>(val));
return 1;
}

/// \brief This is the machine:read_uarch_x() method implementation.
/// \param L Lua state.
static int machine_obj_index_read_uarch_x(lua_State *L) {
auto &m = clua_check<clua_managed_cm_ptr<cm_machine>>(L, 1);
const int i = static_cast<int>(luaL_checkinteger(L, 2));
if (i < 0 || i >= UARCH_X_REG_COUNT) {
luaL_error(L, "register index out of range");
}
uint64_t val{};
if (cm_read_uarch_x(m.get(), i, &val) != 0) {
return luaL_error(L, "%s", cm_get_last_error_message());
}
lua_pushinteger(L, static_cast<lua_Integer>(val));
return 1;
}

/// \brief This is the machine:read_iflags_H() method implementation.
/// \param L Lua state.
static int machine_obj_index_read_iflags_H(lua_State *L) {
Expand Down Expand Up @@ -399,48 +351,6 @@ static int machine_obj_index_write_csr(lua_State *L) {
return 0;
}

/// \brief This is the machine:write_x() method implementation.
/// \param L Lua state.
static int machine_obj_index_write_x(lua_State *L) {
auto &m = clua_check<clua_managed_cm_ptr<cm_machine>>(L, 1);
const int i = static_cast<int>(luaL_checkinteger(L, 2));
if (i < 1 || i >= X_REG_COUNT) {
luaL_error(L, "register index out of range");
}
if (cm_write_x(m.get(), i, luaL_checkinteger(L, 3)) != 0) {
return luaL_error(L, "%s", cm_get_last_error_message());
}
return 0;
}

/// \brief This is the machine:write_f() method implementation.
/// \param L Lua state.
static int machine_obj_index_write_f(lua_State *L) {
auto &m = clua_check<clua_managed_cm_ptr<cm_machine>>(L, 1);
const int i = static_cast<int>(luaL_checkinteger(L, 2));
if (i < 0 || i >= F_REG_COUNT) {
luaL_error(L, "register index out of range");
}
if (cm_write_f(m.get(), i, luaL_checkinteger(L, 3)) != 0) {
return luaL_error(L, "%s", cm_get_last_error_message());
}
return 0;
}

/// \brief This is the machine:write_uarch_x() method implementation.
/// \param L Lua state.
static int machine_obj_index_write_uarch_x(lua_State *L) {
auto &m = clua_check<clua_managed_cm_ptr<cm_machine>>(L, 1);
const int i = static_cast<int>(luaL_checkinteger(L, 2));
if (i < 1 || i >= UARCH_X_REG_COUNT) {
luaL_error(L, "register index out of range");
}
if (cm_write_uarch_x(m.get(), i, luaL_checkinteger(L, 3)) != 0) {
return luaL_error(L, "%s", cm_get_last_error_message());
}
return 0;
}

/// \brief This is the machine:write_memory() method implementation.
/// \param L Lua state.
static int machine_obj_index_write_memory(lua_State *L) {
Expand Down Expand Up @@ -578,7 +488,6 @@ static const auto machine_obj_index = cartesi::clua_make_luaL_Reg_array({
{"get_root_hash", machine_obj_index_get_root_hash},
{"read_csr", machine_obj_index_read_csr},
{"read_uarch_cycle", machine_obj_index_read_uarch_cycle},
{"read_uarch_x", machine_obj_index_read_uarch_x},
{"read_iflags_H", machine_obj_index_read_iflags_H},
{"read_iflags_Y", machine_obj_index_read_iflags_Y},
{"read_iflags_X", machine_obj_index_read_iflags_X},
Expand All @@ -588,8 +497,6 @@ static const auto machine_obj_index = cartesi::clua_make_luaL_Reg_array({
{"read_memory", machine_obj_index_read_memory},
{"read_virtual_memory", machine_obj_index_read_virtual_memory},
{"read_word", machine_obj_index_read_word},
{"read_x", machine_obj_index_read_x},
{"read_f", machine_obj_index_read_f},
{"run", machine_obj_index_run},
{"run_uarch", machine_obj_index_run_uarch},
{"log_step_uarch", machine_obj_index_log_step_uarch},
Expand All @@ -598,12 +505,9 @@ static const auto machine_obj_index = cartesi::clua_make_luaL_Reg_array({
{"verify_merkle_tree", machine_obj_index_verify_merkle_tree},
{"write_csr", machine_obj_index_write_csr},
{"write_uarch_cycle", machine_obj_index_write_uarch_cycle},
{"write_uarch_x", machine_obj_index_write_uarch_x},
{"write_mcycle", machine_obj_index_write_mcycle},
{"write_memory", machine_obj_index_write_memory},
{"write_virtual_memory", machine_obj_index_write_virtual_memory},
{"write_x", machine_obj_index_write_x},
{"write_f", machine_obj_index_write_f},
{"translate_virtual_address", machine_obj_index_translate_virtual_address},
{"replace_memory_range", machine_obj_index_replace_memory_range},
{"destroy", machine_obj_index_destroy},
Expand Down
42 changes: 0 additions & 42 deletions src/clua-jsonrpc-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,45 +123,6 @@ static int jsonrpc_machine_class_verify_reset_uarch_state_transition(lua_State *
return 1;
}

/// \brief This is the machine.get_x_address() method implementation.
static int jsonrpc_machine_class_get_x_address(lua_State *L) {
auto &managed_jsonrpc_mgr =
clua_check<clua_managed_cm_ptr<cm_jsonrpc_mgr>>(L, lua_upvalueindex(1), lua_upvalueindex(2));
const int i = static_cast<int>(luaL_checkinteger(L, 1));
uint64_t reg_address{};
if (cm_jsonrpc_get_x_address(managed_jsonrpc_mgr.get(), i, &reg_address) != 0) {
return luaL_error(L, "%s", cm_get_last_error_message());
}
lua_pushinteger(L, static_cast<lua_Integer>(reg_address));
return 1;
}

/// \brief This is the machine.get_f_address() method implementation.
static int jsonrpc_machine_class_get_f_address(lua_State *L) {
auto &managed_jsonrpc_mgr =
clua_check<clua_managed_cm_ptr<cm_jsonrpc_mgr>>(L, lua_upvalueindex(1), lua_upvalueindex(2));
const int i = static_cast<int>(luaL_checkinteger(L, 1));
uint64_t reg_address{};
if (cm_jsonrpc_get_f_address(managed_jsonrpc_mgr.get(), i, &reg_address) != 0) {
return luaL_error(L, "%s", cm_get_last_error_message());
}
lua_pushinteger(L, static_cast<lua_Integer>(reg_address));
return 1;
}

/// \brief This is the machine.get_uarch_x_address() method implementation.
static int jsonrpc_machine_class_get_uarch_x_address(lua_State *L) {
auto &managed_jsonrpc_mgr =
clua_check<clua_managed_cm_ptr<cm_jsonrpc_mgr>>(L, lua_upvalueindex(1), lua_upvalueindex(2));
const int i = static_cast<int>(luaL_checkinteger(L, 1));
uint64_t reg_address{};
if (cm_jsonrpc_get_uarch_x_address(managed_jsonrpc_mgr.get(), i, &reg_address) != 0) {
return luaL_error(L, "%s", cm_get_last_error_message());
}
lua_pushinteger(L, static_cast<lua_Integer>(reg_address));
return 1;
}

/// \brief This is the machine.get_csr_address() method implementation.
static int jsonrpc_machine_class_get_csr_address(lua_State *L) {
auto &managed_jsonrpc_mgr =
Expand Down Expand Up @@ -233,9 +194,6 @@ static const auto jsonrpc_machine_static_methods = cartesi::clua_make_luaL_Reg_a
{"verify_step_uarch_state_transition", jsonrpc_machine_class_verify_step_uarch_state_transition},
{"verify_reset_uarch_log", jsonrpc_machine_class_verify_reset_uarch_log},
{"verify_reset_uarch_state_transition", jsonrpc_machine_class_verify_reset_uarch_state_transition},
{"get_x_address", jsonrpc_machine_class_get_x_address},
{"get_f_address", jsonrpc_machine_class_get_f_address},
{"get_uarch_x_address", jsonrpc_machine_class_get_uarch_x_address},
{"get_csr_address", jsonrpc_machine_class_get_csr_address},
{"verify_send_cmio_response_log", jsonrpc_machine_class_verify_send_cmio_response_log},
{"verify_send_cmio_response_state_transition", jsonrpc_machine_class_verify_send_cmio_response_state_transition},
Expand Down
33 changes: 0 additions & 33 deletions src/clua-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,36 +89,6 @@ static int machine_class_index_verify_reset_uarch_state_transition(lua_State *L)
return 1;
}

/// \brief This is the machine.get_x_address() method implementation.
static int machine_class_index_get_x_address(lua_State *L) {
const int i = static_cast<int>(luaL_checkinteger(L, 1));
if (i < 0 || i >= X_REG_COUNT) {
luaL_error(L, "register index out of range");
}
lua_pushinteger(L, static_cast<lua_Integer>(cm_get_x_address(i)));
return 1;
}

/// \brief This is the machine.get_uarch_x_address() method implementation.
static int machine_class_index_get_uarch_x_address(lua_State *L) {
const int i = static_cast<int>(luaL_checkinteger(L, 1));
if (i < 0 || i >= UARCH_X_REG_COUNT) {
luaL_error(L, "register index out of range");
}
lua_pushinteger(L, static_cast<lua_Integer>(cm_get_uarch_x_address(i)));
return 1;
}

/// \brief This is the machine.get_f_address() method implementation.
static int machine_class_index_get_f_address(lua_State *L) {
const int i = static_cast<int>(luaL_checkinteger(L, 1));
if (i < 0 || i >= F_REG_COUNT) {
luaL_error(L, "register index out of range");
}
lua_pushinteger(L, static_cast<lua_Integer>(cm_get_f_address(i)));
return 1;
}

/// \brief This is the machine.get_csr_address() method implementation.
static int machine_class_index_get_csr_address(lua_State *L) {
lua_pushinteger(L, static_cast<lua_Integer>(cm_get_csr_address(clua_check_cm_proc_csr(L, 1))));
Expand Down Expand Up @@ -170,9 +140,6 @@ static const auto machine_class_index = cartesi::clua_make_luaL_Reg_array({
{"verify_step_uarch_state_transition", machine_class_index_verify_step_uarch_state_transition},
{"verify_reset_uarch_log", machine_class_index_verify_reset_uarch_log},
{"verify_reset_uarch_state_transition", machine_class_index_verify_reset_uarch_state_transition},
{"get_x_address", machine_class_index_get_x_address},
{"get_uarch_x_address", machine_class_index_get_uarch_x_address},
{"get_f_address", machine_class_index_get_f_address},
{"get_csr_address", machine_class_index_get_csr_address},
{"verify_send_cmio_response_log", machine_class_index_verify_send_cmio_response_log},
{"verify_send_cmio_response_state_transition", machine_class_index_verify_send_cmio_response_state_transition},
Expand Down
40 changes: 0 additions & 40 deletions src/i-virtual-machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,6 @@ class i_virtual_machine {
return do_translate_virtual_address(vaddr);
}

/// \brief Reads the value of a general-purpose register.
uint64_t read_x(int i) const {
return do_read_x(i);
}

/// \brief Writes the value of a general-purpose register.
void write_x(int i, uint64_t val) {
do_write_x(i, val);
}

/// \brief Reads the value of a floating-point register.
uint64_t read_f(int i) const {
return do_read_f(i);
}

/// \brief Writes the value of a floating-point register.
void write_f(int i, uint64_t val) {
do_write_f(i, val);
}

/// \brief Replaces a flash drive.
void replace_memory_range(const memory_range_config &new_range) {
do_replace_memory_range(new_range);
Expand Down Expand Up @@ -211,20 +191,6 @@ class i_virtual_machine {
return do_reset_iflags_Y();
}

/// \brief Reads the value of a microarchitecture register.
/// \param i Register index. Between 0 and UARCH_X_REG_COUNT-1, inclusive.
/// \returns The value of the register.
uint64_t read_uarch_x(int i) const {
return do_read_uarch_x(i);
}

/// \brief Writes the value of a of a microarchitecture register.
/// \param i Register index. Between 0 and UARCH_X_REG_COUNT-1, inclusive.
/// \param val New register value.
void write_uarch_x(int i, uint64_t val) {
return do_write_uarch_x(i, val);
}

/// \brief Reads the value of the microarchitecture cycle counter register.
/// \returns The current microarchitecture cycle.
uint64_t read_uarch_cycle(void) const {
Expand Down Expand Up @@ -297,10 +263,6 @@ class i_virtual_machine {
virtual void do_read_virtual_memory(uint64_t address, unsigned char *data, uint64_t length) const = 0;
virtual void do_write_virtual_memory(uint64_t address, const unsigned char *data, size_t length) = 0;
virtual uint64_t do_translate_virtual_address(uint64_t vaddr) const = 0;
virtual uint64_t do_read_x(int i) const = 0;
virtual void do_write_x(int i, uint64_t val) = 0;
virtual uint64_t do_read_f(int i) const = 0;
virtual void do_write_f(int i, uint64_t val) = 0;
virtual uint64_t do_read_mcycle(void) const = 0;
virtual void do_write_mcycle(uint64_t val) = 0;
virtual bool do_read_iflags_H(void) const = 0;
Expand All @@ -316,8 +278,6 @@ class i_virtual_machine {
virtual void do_destroy() = 0;
virtual void do_commit() = 0;
virtual void do_rollback() = 0;
virtual uint64_t do_read_uarch_x(int i) const = 0;
virtual void do_write_uarch_x(int i, uint64_t val) = 0;
virtual uint64_t do_read_uarch_cycle(void) const = 0;
virtual void do_write_uarch_cycle(uint64_t val) = 0;
virtual bool do_read_uarch_halt_flag(void) const = 0;
Expand Down
Loading

0 comments on commit 3ff3d10

Please sign in to comment.