From 1a556bba10f3ea1acde1a9edfa983dbd5a750651 Mon Sep 17 00:00:00 2001 From: Konstantin Nazarov Date: Thu, 19 Dec 2024 00:09:41 +0000 Subject: [PATCH] Make getreg/setreg functions more unified in naming --- src/debug.cpp | 10 +++++----- src/vm.cpp | 11 ++--------- src/vm.hpp | 7 ++----- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/debug.cpp b/src/debug.cpp index 227798c..00bd681 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -149,7 +149,7 @@ void GDBStub::handle_packet(const std::string &packet) { // Getting specific register int regnum = std::stoi(packet.substr(1), nullptr, 16); - uint32_t reg_value = vm.read_register(regnum); + uint32_t reg_value = vm.getreg(regnum); std::ostringstream response; for (int i = 0; i < 4; ++i) { @@ -278,11 +278,11 @@ bool GDBStub::parse_memory_request(const std::string &packet, size_t &addr, std::string GDBStub::read_registers() { std::ostringstream out; - for (int i = 0; i < 32; ++i) { - uint32_t reg_value = vm.read_register(i); - for (int i = 0; i < 4; ++i) { + for (size_t i = 0; i < 32; ++i) { + uint32_t reg_value = vm.getreg(i); + for (size_t j = 0; j < 4; ++j) { out << std::hex << std::setfill('0') << std::setw(2) - << ((reg_value >> (i * 8)) & 0xFF); + << ((reg_value >> (j * 8)) & 0xFF); } } return out.str(); diff --git a/src/vm.cpp b/src/vm.cpp index 13ac3e4..8fc0371 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -19,7 +19,7 @@ VM::VM(const std::vector& memory, const std::string& file_path) devices[1] = &uart; } -void VM::setreg(int regnum, uint32_t value) { +void VM::setreg(size_t regnum, uint32_t value) { if (regnum == 0) { return; } @@ -115,14 +115,7 @@ std::vector VM::read_memory(size_t start, size_t size) { return res; } -bool VM::is_mmap(size_t pos, size_t size) { - if (pos + size < UART_ADDR) return false; - if (pos >= UART_ADDR + 8) return false; - - return (pos < UART_ADDR + 8) && (pos + size >= UART_ADDR - 1); -} - -uint32_t VM::read_register(size_t regnum) { +uint32_t VM::getreg(size_t regnum) { if (regnum == 32) return pc; if (regnum >= NUM_REGISTERS) { diff --git a/src/vm.hpp b/src/vm.hpp index 53c5083..d8ce4b2 100644 --- a/src/vm.hpp +++ b/src/vm.hpp @@ -68,13 +68,10 @@ class VM { void read_mem(uint8_t *dst, size_t addr, size_t size); void write_mem(uint8_t *src, size_t addr, size_t size); - bool is_mmap(size_t pos, size_t size); - - uint32_t read_register(size_t regnum); - const std::string &get_file_path(); - void setreg(int regnum, uint32_t value); + uint32_t getreg(size_t regnum); + void setreg(size_t regnum, uint32_t value); private: RAM ram;