Skip to content

Commit

Permalink
update PSEMU/Coprocessor.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Cherrytree56567 committed Oct 8, 2023
1 parent f98aa4c commit 271021e
Showing 1 changed file with 6 additions and 46 deletions.
52 changes: 6 additions & 46 deletions PSEMU/Coprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,16 @@
#include <fstream>
#include <bitset>

class Coprocessor {
class Coprocessor0 {
public:
virtual uint32_t readRegister(uint8_t reg) = 0;
virtual void writeRegister(uint8_t reg, uint32_t value) = 0;
};

class Coprocessor0 : public Coprocessor {
public:
enum C0Register {
STATUS = 12,
CAUSE = 13,
BAD_ADDRESS = 14,
EPC = 15
};

uint32_t readRegister(uint8_t reg) override {
switch (reg) {
case 12:
return status;
case 13:
return cause;
case 14:
return bad_address;
case 15:
return epc;
default:
return 0;
}
uint32_t readRegister(uint32_t rega) override {
return reg[rega];
}

void writeRegister(uint8_t reg, uint32_t value) override {
switch (reg) {
case 12:
status = value;
break;
case 13:
cause = value;
break;
case 14:
bad_address = value;
break;
case 15:
epc = value;
break;
}
void writeRegister(uint32_t reg, uint32_t value) override {
reg[reg] = value;
}

private:
uint32_t status = 0;
uint32_t cause = 0;
uint32_t bad_address = 0;
uint32_t epc = 0;
uint32_t reg[64];
};

0 comments on commit 271021e

Please sign in to comment.