Make getreg/setreg functions more unified in naming

This commit is contained in:
Konstantin Nazarov 2024-12-19 00:09:41 +00:00
parent 03bdb5091e
commit 1a556bba10
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
3 changed files with 9 additions and 19 deletions

View file

@ -149,7 +149,7 @@ void GDBStub::handle_packet(const std::string &packet) {
// Getting specific register // Getting specific register
int regnum = std::stoi(packet.substr(1), nullptr, 16); 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; std::ostringstream response;
for (int i = 0; i < 4; ++i) { 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::string GDBStub::read_registers() {
std::ostringstream out; std::ostringstream out;
for (int i = 0; i < 32; ++i) { for (size_t i = 0; i < 32; ++i) {
uint32_t reg_value = vm.read_register(i); uint32_t reg_value = vm.getreg(i);
for (int i = 0; i < 4; ++i) { for (size_t j = 0; j < 4; ++j) {
out << std::hex << std::setfill('0') << std::setw(2) out << std::hex << std::setfill('0') << std::setw(2)
<< ((reg_value >> (i * 8)) & 0xFF); << ((reg_value >> (j * 8)) & 0xFF);
} }
} }
return out.str(); return out.str();

View file

@ -19,7 +19,7 @@ VM::VM(const std::vector<uint8_t>& memory, const std::string& file_path)
devices[1] = &uart; devices[1] = &uart;
} }
void VM::setreg(int regnum, uint32_t value) { void VM::setreg(size_t regnum, uint32_t value) {
if (regnum == 0) { if (regnum == 0) {
return; return;
} }
@ -115,14 +115,7 @@ std::vector<uint8_t> VM::read_memory(size_t start, size_t size) {
return res; return res;
} }
bool VM::is_mmap(size_t pos, size_t size) { uint32_t VM::getreg(size_t regnum) {
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) {
if (regnum == 32) return pc; if (regnum == 32) return pc;
if (regnum >= NUM_REGISTERS) { if (regnum >= NUM_REGISTERS) {

View file

@ -68,13 +68,10 @@ class VM {
void read_mem(uint8_t *dst, size_t addr, size_t size); void read_mem(uint8_t *dst, size_t addr, size_t size);
void write_mem(uint8_t *src, 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(); 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: private:
RAM ram; RAM ram;