diff --git a/cpu.cpp b/cpu.cpp index 2bb4254..f2067ff 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -1664,8 +1664,10 @@ void cpu::trap(uint16_t vector, const int new_ipl, const bool is_interrupt) { DOLOG(debug, true, "*** CPU::TRAP %o, new-ipl: %d, is-interrupt: %d ***", vector, new_ipl, is_interrupt); - uint16_t before_psw = 0; - uint16_t before_pc = 0; + uint16_t before_psw = 0; + uint16_t before_pc = 0; + + it_is_a_trap = true; for(;;) { try { @@ -1688,11 +1690,9 @@ void cpu::trap(uint16_t vector, const int new_ipl, const bool is_interrupt) } else { before_psw = getPSW(); - b->addToMMR1(-2, 6); before_pc = getPC(); - b->addToMMR1(-2, 6); // TODO set MMR2? @@ -2224,6 +2224,8 @@ std::map > cpu::disassemble(const uint16_t void cpu::step_a() { + it_is_a_trap = false; + if ((b->getMMR0() & 0160000) == 0) b->clearMMR1(); diff --git a/cpu.h b/cpu.h index 48ff371..e064dcd 100644 --- a/cpu.h +++ b/cpu.h @@ -36,10 +36,10 @@ private: uint16_t fpsr { 0 }; uint16_t stackLimitRegister { 0377 }; int processing_trap_depth { 0 }; - uint64_t instruction_count { 0 }; - uint64_t running_since { 0 }; - - uint64_t mtpi_count { 0 }; + uint64_t instruction_count { 0 }; + uint64_t running_since { 0 }; + bool it_is_a_trap { false }; + uint64_t mtpi_count { 0 }; // level, vector std::map > queued_interrupts; @@ -114,6 +114,7 @@ public: void queue_interrupt(const uint8_t level, const uint8_t vector); void trap(uint16_t vector, const int new_ipl = -1, const bool is_interrupt = false); + bool is_it_a_trap() const { return it_is_a_trap; } bool getPSW_c() const; bool getPSW_v() const; diff --git a/json/produce-json.py b/json/produce-json.py index 2606614..d0d8eb3 100755 --- a/json/produce-json.py +++ b/json/produce-json.py @@ -74,7 +74,11 @@ class test_generator: # TODO what is the maximum size of an instruction? mem_kv = [] - mem_kv.append((addr + 0, random.randint(0, 65536 - 8))) + while True: + instr = random.randint(0, 65536 - 8) + if instr != 1: # TODO ignore 'WAIT' instruction + break + mem_kv.append((addr + 0, instr)) mem_kv.append((addr + 2, random.randint(0, 65536 - 8))) mem_kv.append((addr + 4, random.randint(0, 65536 - 8))) mem_kv.append((addr + 6, random.randint(0, 65536 - 8))) @@ -142,7 +146,8 @@ fh = open(sys.argv[1], 'w') t = test_generator() tests = [] -for i in range(0, 4096): +for i in range(0, 131072): + print(f'{i}\r', end='') test = t.create_test() if test != None: tests.append(test) diff --git a/main.cpp b/main.cpp index cc7a51e..c198af7 100644 --- a/main.cpp +++ b/main.cpp @@ -69,6 +69,8 @@ int run_cpu_validation(const std::string & filename) cpu *c = new cpu(b, &event); b->add_cpu(c); + uint16_t start_pc = 0; + { // initialize json_t *memory_before = json_object_get(test, "memory-before"); @@ -101,7 +103,8 @@ int run_cpu_validation(const std::string & filename) { json_t *b_pc = json_object_get(registers_before, "pc"); assert(b_pc); - c->setPC(json_integer_value(b_pc)); + start_pc = json_integer_value(b_pc); + c->setPC(start_pc); } // TODO SP[] @@ -173,6 +176,13 @@ int run_cpu_validation(const std::string & filename) } if (err) { + if (c->is_it_a_trap()) + DOLOG(warning, true, "Error by TRAP"); + else { + auto data = c->disassemble(start_pc); + DOLOG(warning, true, "Error by instruction %s", data["instruction-text"].at(0).c_str()); + } + char *js = json_dumps(test, 0); DOLOG(warning, true, "%s\n", js); // also emit empty line(!) free(js);