This commit is contained in:
folkert van heusden 2024-03-28 16:17:50 +01:00
parent a0630fd485
commit d3bc4b5ff0
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
2 changed files with 20 additions and 11 deletions

View file

@ -181,6 +181,9 @@ uint16_t cpu::addRegister(const int nr, const rm_selection_t mode_selection, con
void cpu::lowlevel_register_set(const uint8_t set, const uint8_t reg, const uint16_t value)
{
assert(set < 2);
assert(reg < 8);
if (reg < 6)
regs0_5[set][reg] = value;
else if (reg == 6)
@ -191,6 +194,9 @@ void cpu::lowlevel_register_set(const uint8_t set, const uint8_t reg, const uint
uint16_t cpu::lowlevel_register_get(const uint8_t set, const uint8_t reg)
{
assert(set < 2);
assert(reg < 8);
if (reg < 6)
return regs0_5[set][reg];

View file

@ -54,7 +54,7 @@ void sw_handler(int s)
int run_cpu_validation(const std::string & filename)
{
json_error_t error;
json_t *json = json_load_file(filename.c_str(), 0, &error);
json_t *json = json_load_file(filename.c_str(), JSON_REJECT_DUPLICATES, &error);
if (!json)
error_exit(false, "%s", error.text);
@ -69,8 +69,6 @@ int run_cpu_validation(const std::string & filename)
cpu *c = new cpu(b, &event);
b->add_cpu(c);
// {"memory-before": {"512": 51435, "514": 45610, "516": 15091, "518": 43544}, "registers-before": {"0": 64423, "1": 1, "2": 41733, "3": 14269, "4": 48972, "5": 42770, "6": 57736, "7": 512}, "registers-after": {"0": 64423, "1": 1, "2": 41733, "3": 14269, "4": 48972, "5": 42770, "6": 57736, "7": 512}, "memory-after": {"512": 51435, "514": 45610, "516": 15091, "518": 43544}}
{
// initialize
json_t *memory_before = json_object_get(test, "memory-before");
@ -104,9 +102,10 @@ 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));
// TODO PS
}
// TODO SP[]
c->step_a();
disassemble(c, nullptr, c->getPC(), false);
c->step_b();
@ -146,7 +145,7 @@ int run_cpu_validation(const std::string & filename)
uint16_t should_be = json_integer_value(value);
if (register_is != should_be) {
DOLOG(warning, true, "set %d register %s mismatch (is: %06o, should be: %06o)", set_nr, key, register_is, should_be);
DOLOG(warning, true, "set %d register %s mismatch (is: %06o (%d), should be: %06o (%d))", set_nr, key, register_is, register_is, should_be, should_be);
err = true;
}
}
@ -157,28 +156,32 @@ int run_cpu_validation(const std::string & filename)
assert(a_pc);
uint16_t should_be_pc = json_integer_value(a_pc);
if (c->getPC() != should_be_pc) {
DOLOG(warning, true, "PC register mismatch (is: %06o, should be: %06o)", c->getPC(), should_be_pc);
DOLOG(warning, true, "PC register mismatch (is: %06o (%d), should be: %06o (%d))", c->getPC(), c->getPC(), should_be_pc, should_be_pc);
err = true;
}
}
// TODO check PS
// TODO check SP[]
{
json_t *a_psw = json_object_get(registers_after, "psw");
assert(a_psw);
uint16_t should_be_psw = json_integer_value(a_psw);
if (should_be_psw != psw) {
DOLOG(warning, true, "PSW register mismatch (is: %06o, should be: %06o)", psw, should_be_psw);
DOLOG(warning, true, "PSW register mismatch (is: %06o (%d), should be: %06o (%d))", psw, psw, should_be_psw, should_be_psw);
err = true;
}
}
if (err)
DOLOG(warning, true, "%s\n", json_dumps(test, 0)); // also emit empty line(!)
else
if (err) {
char *js = json_dumps(test, 0);
DOLOG(warning, true, "%s\n", js); // also emit empty line(!)
free(js);
}
else {
n_ok++;
}
}
// clean-up
delete b;