From 2add5df6e7f028e9edafecca7953505b52d73253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sun, 8 Apr 2018 13:44:03 +0200 Subject: Implement LUI --- qtmips_machine/alu.cpp | 2 ++ qtmips_machine/alu.h | 1 + qtmips_machine/core.cpp | 2 +- qtmips_machine/tests/testcore.cpp | 4 ++++ 4 files changed, 8 insertions(+), 1 deletion(-) (limited to 'qtmips_machine') diff --git a/qtmips_machine/alu.cpp b/qtmips_machine/alu.cpp index 24b1c02..3822955 100644 --- a/qtmips_machine/alu.cpp +++ b/qtmips_machine/alu.cpp @@ -65,6 +65,8 @@ std::uint32_t machine::alu_operate(enum AluOp operation, std::uint32_t s, std::u return ((std::int32_t)s < (std::int32_t)t) ? 1 : 0; case ALU_OP_SLTU: return (s < t) ? 1 : 0; + case ALU_OP_LUI: + return t << 16; default: throw QTMIPS_EXCEPTION(UnsupportedAluOperation, "Unknown ALU operation", QString::number(operation, 16)); } diff --git a/qtmips_machine/alu.h b/qtmips_machine/alu.h index 13f3d89..786bba0 100644 --- a/qtmips_machine/alu.h +++ b/qtmips_machine/alu.h @@ -33,6 +33,7 @@ enum AluOp : std::uint8_t { ALU_OP_NOR, ALU_OP_SLT = 42, ALU_OP_SLTU, + ALU_OP_LUI, // We don't care about exact index for this one ALU_OP_LAST = 64 // First impossible operation (just to be sure that we don't overflow) }; diff --git a/qtmips_machine/core.cpp b/qtmips_machine/core.cpp index 617f8c2..1e31584 100644 --- a/qtmips_machine/core.cpp +++ b/qtmips_machine/core.cpp @@ -39,7 +39,7 @@ static const struct DecodeMap dmap[] = { { .flags = FLAGS_ALU_I, .alu = ALU_OP_AND, NOMEM }, // ANDI { .flags = FLAGS_ALU_I, .alu = ALU_OP_OR, NOMEM }, // ORI { .flags = FLAGS_ALU_I, .alu = ALU_OP_XOR, NOMEM }, // XORI - NOPE, // LUI + { .flags = FLAGS_ALU_I, .alu = ALU_OP_LUI, NOMEM}, // LUI NOPE, // 16 NOPE, // 17 NOPE, // 18 diff --git a/qtmips_machine/tests/testcore.cpp b/qtmips_machine/tests/testcore.cpp index 30cf3c7..5e278b5 100644 --- a/qtmips_machine/tests/testcore.cpp +++ b/qtmips_machine/tests/testcore.cpp @@ -122,6 +122,10 @@ static void core_regs_data() { QTest::newRow("NOR") << Instruction(0, 24, 25, 26, 0, 39) \ << regs_init \ << regs_res; + regs_res.write_gp(26, 0xf00f0000); + QTest::newRow("LUI") << Instruction(15, 0, 26, 0xf00f) \ + << regs_init \ + << regs_res; } // Move instructions -- cgit v1.2.3