Skip to content

Commit

Permalink
Adding CP1 registers(MIPT-ILab#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
bova-ev committed Mar 22, 2019
1 parent 3de4a67 commit a159fa0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
13 changes: 12 additions & 1 deletion simulator/mips/mips_instr_decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ enum class Reg : uint8
{
RS, RT, RD,
CP0_RT, CP0_RD,
CP1_FS, CP1_FT,
CP1_FD,
ZERO, RA,
HI, LO, HI_LO
};
Expand All @@ -30,7 +32,10 @@ static inline bool is_explicit_register( Reg type)
|| type == Reg::RT
|| type == Reg::RD
|| type == Reg::CP0_RT
|| type == Reg::CP0_RD;
|| type == Reg::CP0_RD
|| type == Reg::CP1_FS
|| type == Reg::CP1_FT
|| type == Reg::CP1_FD;
}

struct MIPSInstrDecoder
Expand All @@ -44,6 +49,9 @@ struct MIPSInstrDecoder
const uint32 imm;
const uint32 jump;
const uint32 bytes;
const uint32 fs;
const uint32 ft;
const uint32 fd;

static constexpr uint32 apply_mask(uint32 bytes, uint32 mask) noexcept
{
Expand Down Expand Up @@ -87,6 +95,9 @@ struct MIPSInstrDecoder
case Reg::RD: return MIPSRegister::from_cpu_index( rd);
case Reg::CP0_RT: return MIPSRegister::from_cp0_index( rt);
case Reg::CP0_RD: return MIPSRegister::from_cp0_index( rd);
case Reg::CP1_FS: return MIPSRegister::from_cp1_index( fs);
case Reg::CP1_FT: return MIPSRegister::from_cp1_index( ft);
case Reg::CP1_FD: return MIPSRegister::from_cp1_index( fd);
default: assert(0); return MIPSRegister::zero();
}
}
Expand Down
3 changes: 3 additions & 0 deletions simulator/mips/mips_register/mips_register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ std::array<std::string_view, MIPSRegister::MAX_REG> MIPSRegister::regTable =
#define REGISTER(X) # X
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define CP0_REGISTER(X) # X
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define CP1_REGISTER(X) # X
#include "mips_register.def"
#undef CP1_REGISTER
#undef CP0_REGISTER
#undef REGISTER
}};
34 changes: 33 additions & 1 deletion simulator/mips/mips_register/mips_register.def
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,36 @@ CP0_REGISTER(CacheErr),
CP0_REGISTER(TagLo),
CP0_REGISTER(TagHi),
CP0_REGISTER(ErrorEPC),
CP0_REGISTER(DESAVE),
CP0_REGISTER(DESAVE),
CP1_REGISTER(f0),
CP1_REGISTER(f1),
CP1_REGISTER(f2),
CP1_REGISTER(f3),
CP1_REGISTER(f4),
CP1_REGISTER(f5),
CP1_REGISTER(f6),
CP1_REGISTER(f7),
CP1_REGISTER(f8),
CP1_REGISTER(f9),
CP1_REGISTER(f10),
CP1_REGISTER(f11),
CP1_REGISTER(f12),
CP1_REGISTER(f13),
CP1_REGISTER(f14),
CP1_REGISTER(f15),
CP1_REGISTER(f16),
CP1_REGISTER(f17),
CP1_REGISTER(f18),
CP1_REGISTER(f19),
CP1_REGISTER(f20),
CP1_REGISTER(f21),
CP1_REGISTER(f22),
CP1_REGISTER(f23),
CP1_REGISTER(f24),
CP1_REGISTER(f25),
CP1_REGISTER(f26),
CP1_REGISTER(f27),
CP1_REGISTER(f28),
CP1_REGISTER(f29),
CP1_REGISTER(f30),
CP1_REGISTER(f31),
8 changes: 8 additions & 0 deletions simulator/mips/mips_register/mips_register.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ class MIPSRegister {
#define REGISTER(X) MIPS_REG_ ## X
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define CP0_REGISTER(X) MIPS_CP0_REG_ ## X
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define CP0_REGISTER(X) MIPS_CP1_REG_ ## X
#include "mips_register.def"
#undef REGISTER
#undef CP0_REGISTER
#undef CP1_REGISTER
MAX_VAL_RegNum
};

Expand All @@ -51,6 +54,11 @@ class MIPSRegister {
return MIPSRegister( RegNum{ narrow_cast<uint8>( MIPS_CP0_REG_Context0 + id)});
}

static constexpr MIPSRegister from_cp1_index( uint8 id) noexcept
{
return MIPSRegister( RegNum{ narrow_cast<uint8>( MIPS_CP1_REG_f0 + id)});
}

static MIPSRegister from_gdb_index( uint8 id)
{
if (id < 32u)
Expand Down

0 comments on commit a159fa0

Please sign in to comment.