Skip to content

Commit

Permalink
refactor: trim read/write CSR methods implementation in C API
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Sep 26, 2024
1 parent 4728580 commit 700e318
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 364 deletions.
56 changes: 0 additions & 56 deletions src/i-virtual-machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,53 +156,6 @@ class i_virtual_machine {
do_rollback();
}

/// \brief Reads the mcycle register
uint64_t read_mcycle(void) const {
return do_read_mcycle();
}

/// \brief Reads the H iflag
bool read_iflags_H(void) const {
return do_read_iflags_H();
}

/// \brief Reads the Y iflag
bool read_iflags_Y(void) const {
return do_read_iflags_Y();
}

/// \brief Reads the X iflag
bool read_iflags_X(void) const {
return do_read_iflags_X();
}

/// \brief Sets the Y iflag
void set_iflags_Y(void) {
return do_set_iflags_Y();
}

/// \brief Resets the Y iflag
void reset_iflags_Y(void) {
return do_reset_iflags_Y();
}

/// \brief Reads the value of the microarchitecture cycle counter register.
/// \returns The current microarchitecture cycle.
uint64_t read_uarch_cycle(void) const {
return do_read_uarch_cycle();
}

/// \brief Gets the value of the microarchitecture halt flag
/// \returns The current microarchitecture cycle.
bool read_uarch_halt_flag(void) const {
return do_read_uarch_halt_flag();
}

/// \brief Sets the microarchitecture halt flag
void set_uarch_halt_flag() {
return do_set_uarch_halt_flag();
}

/// \brief Resets the microarchitecture state to pristine value
void reset_uarch() {
return do_reset_uarch();
Expand Down Expand Up @@ -252,12 +205,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, uint64_t length) = 0;
virtual uint64_t do_translate_virtual_address(uint64_t vaddr) const = 0;
virtual uint64_t do_read_mcycle(void) const = 0;
virtual bool do_read_iflags_H(void) const = 0;
virtual bool do_read_iflags_Y(void) const = 0;
virtual bool do_read_iflags_X(void) const = 0;
virtual void do_set_iflags_Y(void) = 0;
virtual void do_reset_iflags_Y(void) = 0;
virtual void do_replace_memory_range(const memory_range_config &new_range) = 0;
virtual uint64_t do_read_word(uint64_t address) const = 0;
virtual bool do_verify_dirty_page_maps(void) const = 0;
Expand All @@ -266,9 +213,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_cycle(void) const = 0;
virtual bool do_read_uarch_halt_flag(void) const = 0;
virtual void do_set_uarch_halt_flag() = 0;
virtual void do_reset_uarch() = 0;
virtual access_log do_log_reset_uarch(const access_log::type &log_type, bool one_based = false) = 0;
virtual uarch_interpreter_break_reason do_run_uarch(uint64_t uarch_cycle_end) = 0;
Expand Down
91 changes: 0 additions & 91 deletions src/jsonrpc-discover.json
Original file line number Diff line number Diff line change
Expand Up @@ -695,97 +695,6 @@
}
},

{
"name": "machine.set_iflags_Y",
"summary": "Sets iflags.Y to true",
"params": [],
"result": {
"name": "status",
"description": "True when operation succeeded",
"schema": {
"type": "boolean"
}
}
},

{
"name": "machine.reset_iflags_Y",
"summary": "Sets iflags.Y to false",
"params": [],
"result": {
"name": "status",
"description": "True when operation succeeded",
"schema": {
"type": "boolean"
}
}
},

{
"name": "machine.read_iflags_Y",
"summary": "Returns value of iflags.Y",
"params": [],
"result": {
"name": "value",
"description": "Value of flag",
"schema": {
"type": "boolean"
}
}
},

{
"name": "machine.read_iflags_X",
"summary": "Returns value of iflags.X",
"params": [],
"result": {
"name": "value",
"description": "Value of flag",
"schema": {
"type": "boolean"
}
}
},

{
"name": "machine.read_iflags_H",
"summary": "Returns value of iflags.H",
"params": [],
"result": {
"name": "value",
"description": "Value of flag",
"schema": {
"type": "boolean"
}
}
},

{
"name": "machine.set_uarch_halt_flag",
"summary": "Sets iflags.H to true",
"params": [],
"result": {
"name": "status",
"description": "True when operation succeeded",
"schema": {
"type": "boolean"
}
}
},

{
"name": "machine.read_uarch_halt_flag",
"summary": "Returns value of iflags.H",
"params": [],
"result": {
"name": "value",
"description": "Value of flag",
"schema": {
"type": "boolean"
}
}
},

{
"name": "machine.reset_uarch",
"summary": "Reset uarch to pristine state",
Expand Down
94 changes: 0 additions & 94 deletions src/jsonrpc-remote-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,81 +1310,6 @@ static json jsonrpc_machine_get_csr_address_handler(const json &j, const std::sh
return jsonrpc_response_ok(j, cartesi::machine::get_csr_address(std::get<0>(args)));
}

/// \brief JSONRPC handler for the machine.reset_iflags_Y method
/// \param j JSON request object
/// \param session HTTP session
/// \returns JSON response object
static json jsonrpc_machine_reset_iflags_Y_handler(const json &j, const std::shared_ptr<http_session> &session) {
if (!session->handler->machine) {
return jsonrpc_response_invalid_request(j, "no machine");
}
jsonrpc_check_no_params(j);
session->handler->machine->reset_iflags_Y();
return jsonrpc_response_ok(j);
}

/// \brief JSONRPC handler for the machine.set_iflags_Y method
/// \param j JSON request object
/// \param session HTTP session
/// \returns JSON response object
static json jsonrpc_machine_set_iflags_Y_handler(const json &j, const std::shared_ptr<http_session> &session) {
if (!session->handler->machine) {
return jsonrpc_response_invalid_request(j, "no machine");
}
jsonrpc_check_no_params(j);
session->handler->machine->set_iflags_Y();
return jsonrpc_response_ok(j);
}

/// \brief JSONRPC handler for the machine.read_iflags_Y method
/// \param j JSON request object
/// \param session HTTP session
/// \returns JSON response object
static json jsonrpc_machine_read_iflags_Y_handler(const json &j, const std::shared_ptr<http_session> &session) {
if (!session->handler->machine) {
return jsonrpc_response_invalid_request(j, "no machine");
}
jsonrpc_check_no_params(j);
return jsonrpc_response_ok(j, session->handler->machine->read_iflags_Y());
}

/// \brief JSONRPC handler for the machine.read_iflags_X method
/// \param j JSON request object
/// \param session HTTP session
/// \returns JSON response object
static json jsonrpc_machine_read_iflags_X_handler(const json &j, const std::shared_ptr<http_session> &session) {
if (!session->handler->machine) {
return jsonrpc_response_invalid_request(j, "no machine");
}
jsonrpc_check_no_params(j);
return jsonrpc_response_ok(j, session->handler->machine->read_iflags_X());
}

/// \brief JSONRPC handler for the machine.read_iflags_H method
/// \param j JSON request object
/// \param session HTTP session
/// \returns JSON response object
static json jsonrpc_machine_read_iflags_H_handler(const json &j, const std::shared_ptr<http_session> &session) {
if (!session->handler->machine) {
return jsonrpc_response_invalid_request(j, "no machine");
}
jsonrpc_check_no_params(j);
return jsonrpc_response_ok(j, session->handler->machine->read_iflags_H());
}

/// \brief JSONRPC handler for the machine.set_uarch_halt_flag method
/// \param j JSON request object
/// \param session HTTP session
/// \returns JSON response object
static json jsonrpc_machine_set_uarch_halt_flag_handler(const json &j, const std::shared_ptr<http_session> &session) {
if (!session->handler->machine) {
return jsonrpc_response_invalid_request(j, "no machine");
}
jsonrpc_check_no_params(j);
session->handler->machine->set_uarch_halt_flag();
return jsonrpc_response_ok(j);
}

/// \brief JSONRPC handler for the machine.reset_uarch method
/// \param j JSON request object
/// \param session HTTP session
Expand All @@ -1398,18 +1323,6 @@ static json jsonrpc_machine_reset_uarch_handler(const json &j, const std::shared
return jsonrpc_response_ok(j);
}

/// \brief JSONRPC handler for the machine.read_uarch_halt_flag method
/// \param j JSON request object
/// \param session HTTP session
/// \returns JSON response object
static json jsonrpc_machine_read_uarch_halt_flag_handler(const json &j, const std::shared_ptr<http_session> &session) {
if (!session->handler->machine) {
return jsonrpc_response_invalid_request(j, "no machine");
}
jsonrpc_check_no_params(j);
return jsonrpc_response_ok(j, session->handler->machine->read_uarch_halt_flag());
}

/// \brief JSONRPC handler for the machine.get_initial_config method
/// \param j JSON request object
/// \param session HTTP session
Expand Down Expand Up @@ -1646,13 +1559,6 @@ static json jsonrpc_dispatch_method(const json &j, const std::shared_ptr<http_se
{"machine.read_csr", jsonrpc_machine_read_csr_handler},
{"machine.write_csr", jsonrpc_machine_write_csr_handler},
{"machine.get_csr_address", jsonrpc_machine_get_csr_address_handler},
{"machine.set_iflags_Y", jsonrpc_machine_set_iflags_Y_handler},
{"machine.reset_iflags_Y", jsonrpc_machine_reset_iflags_Y_handler},
{"machine.read_iflags_Y", jsonrpc_machine_read_iflags_Y_handler},
{"machine.read_iflags_X", jsonrpc_machine_read_iflags_X_handler},
{"machine.read_iflags_H", jsonrpc_machine_read_iflags_H_handler},
{"machine.read_uarch_halt_flag", jsonrpc_machine_read_uarch_halt_flag_handler},
{"machine.set_uarch_halt_flag", jsonrpc_machine_set_uarch_halt_flag_handler},
{"machine.get_initial_config", jsonrpc_machine_get_initial_config_handler},
{"machine.get_default_config", jsonrpc_machine_get_default_config_handler},
{"machine.verify_merkle_tree", jsonrpc_machine_verify_merkle_tree_handler},
Expand Down
49 changes: 0 additions & 49 deletions src/jsonrpc-virtual-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,51 +514,6 @@ uint64_t jsonrpc_virtual_machine::do_translate_virtual_address(uint64_t vaddr) c
return result;
}

uint64_t jsonrpc_virtual_machine::do_read_mcycle(void) const {
return read_csr(csr::mcycle);
}

bool jsonrpc_virtual_machine::do_read_iflags_H(void) const {
bool result = false;
jsonrpc_request(m_mgr->get_stream(), m_mgr->get_remote_address(), "machine.read_iflags_H", std::tie(), result);
return result;
}

bool jsonrpc_virtual_machine::do_read_iflags_Y(void) const {
bool result = false;
jsonrpc_request(m_mgr->get_stream(), m_mgr->get_remote_address(), "machine.read_iflags_Y", std::tie(), result);
return result;
}

bool jsonrpc_virtual_machine::do_read_iflags_X(void) const {
bool result = false;
jsonrpc_request(m_mgr->get_stream(), m_mgr->get_remote_address(), "machine.read_iflags_X", std::tie(), result);
return result;
}

void jsonrpc_virtual_machine::do_set_iflags_Y(void) {
bool result = false;
jsonrpc_request(m_mgr->get_stream(), m_mgr->get_remote_address(), "machine.set_iflags_Y", std::tie(), result);
}

void jsonrpc_virtual_machine::do_reset_iflags_Y(void) {
bool result = false;
jsonrpc_request(m_mgr->get_stream(), m_mgr->get_remote_address(), "machine.reset_iflags_Y", std::tie(), result);
}

bool jsonrpc_virtual_machine::do_read_uarch_halt_flag(void) const {
bool result = false;
jsonrpc_request(m_mgr->get_stream(), m_mgr->get_remote_address(), "machine.read_uarch_halt_flag", std::tie(),
result);
return result;
}

void jsonrpc_virtual_machine::do_set_uarch_halt_flag(void) {
bool result = false;
jsonrpc_request(m_mgr->get_stream(), m_mgr->get_remote_address(), "machine.set_uarch_halt_flag", std::tie(),
result);
}

void jsonrpc_virtual_machine::do_reset_uarch(void) {
bool result = false;
jsonrpc_request(m_mgr->get_stream(), m_mgr->get_remote_address(), "machine.reset_uarch", std::tie(), result);
Expand Down Expand Up @@ -628,10 +583,6 @@ bool jsonrpc_virtual_machine::do_verify_merkle_tree(void) const {
return result;
}

uint64_t jsonrpc_virtual_machine::do_read_uarch_cycle(void) const {
return read_csr(csr::uarch_cycle);
}

void jsonrpc_virtual_machine::do_snapshot(void) {
m_mgr->snapshot();
}
Expand Down
9 changes: 0 additions & 9 deletions src/jsonrpc-virtual-machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ class jsonrpc_virtual_machine final : public i_virtual_machine {
void do_read_virtual_memory(uint64_t address, unsigned char *data, uint64_t length) const override;
void do_write_virtual_memory(uint64_t address, const unsigned char *data, uint64_t length) override;
uint64_t do_translate_virtual_address(uint64_t vaddr) const override;
uint64_t do_read_mcycle(void) const override;
bool do_read_iflags_H(void) const override;
bool do_read_iflags_Y(void) const override;
bool do_read_iflags_X(void) const override;
void do_set_iflags_Y(void) override;
void do_reset_iflags_Y(void) override;
bool do_read_uarch_halt_flag(void) const override;
void do_set_uarch_halt_flag(void) override;
void do_reset_uarch(void) override;
access_log do_log_reset_uarch(const access_log::type &log_type, bool /*one_based = false*/) override;
void do_get_root_hash(hash_type &hash) const override;
Expand All @@ -112,7 +104,6 @@ class jsonrpc_virtual_machine final : public i_virtual_machine {
bool do_verify_dirty_page_maps(void) const override;
uint64_t do_read_word(uint64_t address) const override;
bool do_verify_merkle_tree(void) const override;
uint64_t do_read_uarch_cycle(void) const override;
uarch_interpreter_break_reason do_run_uarch(uint64_t uarch_cycle_end) override;
machine_memory_range_descrs do_get_memory_ranges(void) const override;
void do_send_cmio_response(uint16_t reason, const unsigned char *data, uint64_t length) override;
Expand Down
Loading

0 comments on commit 700e318

Please sign in to comment.