Better memory errors and in general more runtime memory
This commit is contained in:
parent
65e5011f7f
commit
2e9bb3fd76
3 changed files with 20 additions and 10 deletions
|
@ -158,7 +158,9 @@ std::vector<uint8_t> load_elf(const std::string& filename, size_t memory_size) {
|
||||||
for (const Elf32Section& shdr : sectionHeaders) {
|
for (const Elf32Section& shdr : sectionHeaders) {
|
||||||
if (should_load_section(shdr)) {
|
if (should_load_section(shdr)) {
|
||||||
if (shdr.sh_type == SHT_NOBITS) {
|
if (shdr.sh_type == SHT_NOBITS) {
|
||||||
throw std::runtime_error("Trying to load section without data");
|
// Section contains no data - just skip it. It will be initialized
|
||||||
|
// to zero.
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.seekg(shdr.sh_offset);
|
file.seekg(shdr.sh_offset);
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "vm.hpp"
|
#include "vm.hpp"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
const size_t MEMORY_SIZE = 512 * 1024;
|
const size_t MEMORY_SIZE = 64 * 1024 * 1024;
|
||||||
|
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
std::string program_filename = "";
|
std::string program_filename = "";
|
||||||
|
|
24
src/vm.cpp
24
src/vm.cpp
|
@ -32,7 +32,8 @@ void VM::setreg(size_t regnum, uint32_t value) {
|
||||||
|
|
||||||
void UART::read_mem_u8(uint8_t* dst, size_t addr) {
|
void UART::read_mem_u8(uint8_t* dst, size_t addr) {
|
||||||
if (addr < UART_ADDR || addr + 1 > UART_ADDR + 8) {
|
if (addr < UART_ADDR || addr + 1 > UART_ADDR + 8) {
|
||||||
throw std::runtime_error("Memory access out of bounds");
|
throw std::runtime_error(std::string("Memory access out of bounds: ") +
|
||||||
|
std::format("{:x}", addr));
|
||||||
}
|
}
|
||||||
addr -= UART_ADDR;
|
addr -= UART_ADDR;
|
||||||
switch (addr) {
|
switch (addr) {
|
||||||
|
@ -46,7 +47,8 @@ void UART::read_mem_u8(uint8_t* dst, size_t addr) {
|
||||||
|
|
||||||
void UART::write_mem_u8(uint8_t* src, size_t addr) {
|
void UART::write_mem_u8(uint8_t* src, size_t addr) {
|
||||||
if (addr < UART_ADDR || addr + 1 > UART_ADDR + 8) {
|
if (addr < UART_ADDR || addr + 1 > UART_ADDR + 8) {
|
||||||
throw std::runtime_error("Memory access out of bounds");
|
throw std::runtime_error(std::string("Memory access out of bounds: ") +
|
||||||
|
std::format("{:x}", addr));
|
||||||
}
|
}
|
||||||
addr -= UART_ADDR;
|
addr -= UART_ADDR;
|
||||||
switch (addr) {
|
switch (addr) {
|
||||||
|
@ -91,7 +93,8 @@ void VM::read_mem_u8(uint8_t* dst, size_t addr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Memory access out of bounds");
|
throw std::runtime_error(std::string("Memory access out of bounds: ") +
|
||||||
|
std::format("{:x}", addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VM::read_mem_u16(uint16_t* dst, size_t addr) {
|
void VM::read_mem_u16(uint16_t* dst, size_t addr) {
|
||||||
|
@ -101,7 +104,8 @@ void VM::read_mem_u16(uint16_t* dst, size_t addr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Memory access out of bounds");
|
throw std::runtime_error(std::string("Memory access out of bounds: ") +
|
||||||
|
std::format("{:x}", addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VM::read_mem_u32(uint32_t* dst, size_t addr) {
|
void VM::read_mem_u32(uint32_t* dst, size_t addr) {
|
||||||
|
@ -111,7 +115,8 @@ void VM::read_mem_u32(uint32_t* dst, size_t addr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Memory access out of bounds");
|
throw std::runtime_error(std::string("Memory access out of bounds: ") +
|
||||||
|
std::format("{:x}", addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VM::write_mem_u8(uint8_t* src, size_t addr) {
|
void VM::write_mem_u8(uint8_t* src, size_t addr) {
|
||||||
|
@ -121,7 +126,8 @@ void VM::write_mem_u8(uint8_t* src, size_t addr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Memory access out of bounds");
|
throw std::runtime_error(std::string("Memory access out of bounds: ") +
|
||||||
|
std::format("{:x}", addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VM::write_mem_u16(uint16_t* src, size_t addr) {
|
void VM::write_mem_u16(uint16_t* src, size_t addr) {
|
||||||
|
@ -131,7 +137,8 @@ void VM::write_mem_u16(uint16_t* src, size_t addr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Memory access out of bounds");
|
throw std::runtime_error(std::string("Memory access out of bounds: ") +
|
||||||
|
std::format("{:x}", addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VM::write_mem_u32(uint32_t* src, size_t addr) {
|
void VM::write_mem_u32(uint32_t* src, size_t addr) {
|
||||||
|
@ -141,7 +148,8 @@ void VM::write_mem_u32(uint32_t* src, size_t addr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Memory access out of bounds");
|
throw std::runtime_error(std::string("Memory access out of bounds: ") +
|
||||||
|
std::format("{:x}", addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> VM::read_memory(size_t start, size_t size) {
|
std::vector<uint8_t> VM::read_memory(size_t start, size_t size) {
|
||||||
|
|
Loading…
Reference in a new issue