Skip to content

Commit f225eb9

Browse files
committed
Fix invalid CPU halt without HALT command
HyperCPU emulator runs the executable code until HALT command is sent. If the end of the code is reached, and there is no HALT command, emulator will continue reading and executing the code and finally abort with error like "Interrupt was triggered, but failed to execute handler" with XIP exceeding the size of the executable code (binary size). This commit implements automatic CPU halt in case XIP exceeds the binary size. Signed-off-by: Ivan Movchan <ivan.movchan.07@gmail.com>
1 parent 8814cb4 commit f225eb9

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/Emulator/Core/CPU/CPU.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ HyperCPU::CPU::CPU(std::uint16_t core_count, std::uint64_t mem_size, char* binar
1010
: mem_controller(dynamic_cast<IMemoryController*>(new MemoryControllerST(mem_size, this))),
1111
core_count(core_count),
1212
total_mem(mem_size),
13+
binary_size(binary_size),
1314
halted(false),
1415
ivt_initialized(false),
1516
io_ctl(std::make_unique<SimpleIOImpl>()) {
@@ -251,6 +252,11 @@ void HyperCPU::CPU::Run() {
251252
pending_interrupt.reset();
252253
continue;
253254
}
255+
256+
if ((*xip) >= binary_size) {
257+
halted = true;
258+
break;
259+
}
254260

255261
buffer = m_decoder->FetchAndDecode();
256262

src/Emulator/Core/CPU/CPU.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace HyperCPU {
2929
// Data
3030
std::uint16_t core_count;
3131
std::uint64_t total_mem;
32+
std::uint64_t binary_size;
3233
bool halted;
3334

3435
// General space for registers

0 commit comments

Comments
 (0)