1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00

Permit TRAP, TRAPV and CHK to push the next PC rather than the current.

This commit is contained in:
Thomas Harte 2022-05-07 20:32:39 -04:00
parent ad6cf5e401
commit bf8c97abbb
4 changed files with 9 additions and 8 deletions

View File

@ -39,13 +39,14 @@ template <Model model, typename BusHandler> class Executor {
// Flow control. // Flow control.
void consume_cycles(int) {} void consume_cycles(int) {}
void raise_exception(int);
void stop();
void set_pc(uint32_t); void set_pc(uint32_t);
void add_pc(uint32_t); void add_pc(uint32_t);
void decline_branch() {} void decline_branch() {}
void raise_exception(int, bool use_current_instruction_pc = true);
void did_update_status(); void did_update_status();
void stop();
void bsr(uint32_t offset); void bsr(uint32_t offset);
void jsr(uint32_t offset); void jsr(uint32_t offset);
void link(Preinstruction instruction, uint32_t offset); void link(Preinstruction instruction, uint32_t offset);

View File

@ -330,7 +330,7 @@ void Executor<model, BusHandler>::set_state(const Registers &state) {
// TODO: flow control, all below here. // TODO: flow control, all below here.
template <Model model, typename BusHandler> template <Model model, typename BusHandler>
void Executor<model, BusHandler>::raise_exception(int index) { void Executor<model, BusHandler>::raise_exception(int index, bool use_current_instruction_pc) {
const uint32_t address = index << 2; const uint32_t address = index << 2;
// Grab the status to store, then switch into supervisor mode. // Grab the status to store, then switch into supervisor mode.
@ -339,7 +339,7 @@ void Executor<model, BusHandler>::raise_exception(int index) {
did_update_status(); did_update_status();
// Push status and the program counter at instruction start. // Push status and the program counter at instruction start.
bus_handler_.template write<uint32_t>(sp.l - 4, instruction_address_); bus_handler_.template write<uint32_t>(sp.l - 4, use_current_instruction_pc ? instruction_address_ : program_counter_.l);
bus_handler_.template write<uint16_t>(sp.l - 6, status); bus_handler_.template write<uint16_t>(sp.l - 6, status);
sp.l -= 6; sp.l -= 6;

View File

@ -652,12 +652,12 @@ template <
// TRAP, which is a nicer form of ILLEGAL. // TRAP, which is a nicer form of ILLEGAL.
case Operation::TRAP: case Operation::TRAP:
flow_controller.raise_exception(src.l + 32); flow_controller.raise_exception(src.l + 32, false);
break; break;
case Operation::TRAPV: { case Operation::TRAPV: {
if(status.overflow_flag_) { if(status.overflow_flag_) {
flow_controller.raise_exception(7); flow_controller.raise_exception(7, false);
} }
} break; } break;
@ -683,7 +683,7 @@ template <
} else { } else {
flow_controller.consume_cycles(12); flow_controller.consume_cycles(12);
} }
flow_controller.raise_exception(6); flow_controller.raise_exception(6, false);
} }
} break; } break;

View File

@ -83,7 +83,7 @@
- (void)setUp { - (void)setUp {
// To limit tests run to a subset of files and/or of tests, uncomment and fill in below. // To limit tests run to a subset of files and/or of tests, uncomment and fill in below.
// _fileSet = [NSSet setWithArray:@[@"link_unlk.json"]]; _fileSet = [NSSet setWithArray:@[@"ext.json"]];
// _testSet = [NSSet setWithArray:@[@"NEGX 00c0"]]; // _testSet = [NSSet setWithArray:@[@"NEGX 00c0"]];
// _fileSet = [NSSet setWithArray:@[@"jmp_jsr.json"]]; // _fileSet = [NSSet setWithArray:@[@"jmp_jsr.json"]];
// _testSet = [NSSet setWithArray:@[@"CHK 41a8"]]; // _testSet = [NSSet setWithArray:@[@"CHK 41a8"]];