This commit is contained in:
folkert van heusden 2024-03-28 18:24:13 +01:00
parent 182a907182
commit 0bc17c628a
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
4 changed files with 29 additions and 11 deletions

10
cpu.cpp
View file

@ -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); 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_psw = 0;
uint16_t before_pc = 0; uint16_t before_pc = 0;
it_is_a_trap = true;
for(;;) { for(;;) {
try { try {
@ -1688,11 +1690,9 @@ void cpu::trap(uint16_t vector, const int new_ipl, const bool is_interrupt)
} }
else { else {
before_psw = getPSW(); before_psw = getPSW();
b->addToMMR1(-2, 6); b->addToMMR1(-2, 6);
before_pc = getPC(); before_pc = getPC();
b->addToMMR1(-2, 6); b->addToMMR1(-2, 6);
// TODO set MMR2? // TODO set MMR2?
@ -2224,6 +2224,8 @@ std::map<std::string, std::vector<std::string> > cpu::disassemble(const uint16_t
void cpu::step_a() void cpu::step_a()
{ {
it_is_a_trap = false;
if ((b->getMMR0() & 0160000) == 0) if ((b->getMMR0() & 0160000) == 0)
b->clearMMR1(); b->clearMMR1();

9
cpu.h
View file

@ -36,10 +36,10 @@ private:
uint16_t fpsr { 0 }; uint16_t fpsr { 0 };
uint16_t stackLimitRegister { 0377 }; uint16_t stackLimitRegister { 0377 };
int processing_trap_depth { 0 }; int processing_trap_depth { 0 };
uint64_t instruction_count { 0 }; uint64_t instruction_count { 0 };
uint64_t running_since { 0 }; uint64_t running_since { 0 };
bool it_is_a_trap { false };
uint64_t mtpi_count { 0 }; uint64_t mtpi_count { 0 };
// level, vector // level, vector
std::map<uint8_t, std::set<uint8_t> > queued_interrupts; std::map<uint8_t, std::set<uint8_t> > queued_interrupts;
@ -114,6 +114,7 @@ public:
void queue_interrupt(const uint8_t level, const uint8_t vector); 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); 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_c() const;
bool getPSW_v() const; bool getPSW_v() const;

View file

@ -74,7 +74,11 @@ class test_generator:
# TODO what is the maximum size of an instruction? # TODO what is the maximum size of an instruction?
mem_kv = [] 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 + 2, random.randint(0, 65536 - 8)))
mem_kv.append((addr + 4, 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))) mem_kv.append((addr + 6, random.randint(0, 65536 - 8)))
@ -142,7 +146,8 @@ fh = open(sys.argv[1], 'w')
t = test_generator() t = test_generator()
tests = [] tests = []
for i in range(0, 4096): for i in range(0, 131072):
print(f'{i}\r', end='')
test = t.create_test() test = t.create_test()
if test != None: if test != None:
tests.append(test) tests.append(test)

View file

@ -69,6 +69,8 @@ int run_cpu_validation(const std::string & filename)
cpu *c = new cpu(b, &event); cpu *c = new cpu(b, &event);
b->add_cpu(c); b->add_cpu(c);
uint16_t start_pc = 0;
{ {
// initialize // initialize
json_t *memory_before = json_object_get(test, "memory-before"); 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"); json_t *b_pc = json_object_get(registers_before, "pc");
assert(b_pc); assert(b_pc);
c->setPC(json_integer_value(b_pc)); start_pc = json_integer_value(b_pc);
c->setPC(start_pc);
} }
// TODO SP[] // TODO SP[]
@ -173,6 +176,13 @@ int run_cpu_validation(const std::string & filename)
} }
if (err) { 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); char *js = json_dumps(test, 0);
DOLOG(warning, true, "%s\n", js); // also emit empty line(!) DOLOG(warning, true, "%s\n", js); // also emit empty line(!)
free(js); free(js);