Make getreg/setreg functions more unified in naming
This commit is contained in:
parent
03bdb5091e
commit
1a556bba10
3 changed files with 9 additions and 19 deletions
|
@ -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();
|
||||
|
|
11
src/vm.cpp
11
src/vm.cpp
|
@ -19,7 +19,7 @@ VM::VM(const std::vector<uint8_t>& 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<uint8_t> 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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue