From 9d82517dea100d94fd8d0d5326ca5db7b5a1e595 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Sun, 17 Feb 2019 21:15:53 +0100 Subject: Pass arithmetic exception trough pipeline and implement trap support and instructions. Signed-off-by: Pavel Pisa --- qtmips_machine/tests/testalu.cpp | 71 +++++++++++++++++++++++++++++++++++--- qtmips_machine/tests/tst_machine.h | 2 ++ 2 files changed, 68 insertions(+), 5 deletions(-) (limited to 'qtmips_machine/tests') diff --git a/qtmips_machine/tests/testalu.cpp b/qtmips_machine/tests/testalu.cpp index b0e7073..4edd92a 100644 --- a/qtmips_machine/tests/testalu.cpp +++ b/qtmips_machine/tests/testalu.cpp @@ -216,6 +216,7 @@ void MachineTests::alu_data() { void MachineTests::alu() { bool discard; + enum ExceptionCause excause = EXCAUSE_NONE; QFETCH(AluOp, op); QFETCH(std::uint32_t, s); QFETCH(std::uint32_t, t); @@ -224,22 +225,80 @@ void MachineTests::alu() { QFETCH(Registers, regs_res); QFETCH(std::uint32_t, res); - QCOMPARE(alu_operate(op, s , t, sa, 0, ®s_init, discard), res); + QCOMPARE(alu_operate(op, s , t, sa, 0, ®s_init, discard, excause), res); QCOMPARE(regs_res, regs_init); + QCOMPARE(excause, EXCAUSE_NONE); } -void MachineTests::alu_except_data() { +void MachineTests::alu_trap_overflow_data() { QTest::addColumn("op"); QTest::addColumn("s"); QTest::addColumn("t"); + QTest::addColumn("excause"); // Note no sa as shift unstruction has no exceptions QTest::newRow("ADD") << (std::uint8_t)ALU_OP_ADD \ << (std::uint32_t)0x8fffffff \ - << (std::uint32_t)0x90000000; + << (std::uint32_t)0x90000000 \ + << EXCAUSE_OVERFLOW; QTest::newRow("SUB") << (std::uint8_t)ALU_OP_SUB \ << (std::uint32_t)0x80000003 \ - << (std::uint32_t)4; + << (std::uint32_t)4 \ + << EXCAUSE_OVERFLOW; + QTest::newRow("TEQ") << (std::uint8_t)ALU_OP_TEQ \ + << (std::uint32_t)0x12345678 \ + << (std::uint32_t)0x12345678 \ + << EXCAUSE_TRAP; + QTest::newRow("TEQ") << (std::uint8_t)ALU_OP_TEQ \ + << (std::uint32_t)0x12345679 \ + << (std::uint32_t)0x12345678 \ + << EXCAUSE_NONE; + QTest::newRow("TNE") << (std::uint8_t)ALU_OP_TNE \ + << (std::uint32_t)0x12345678 \ + << (std::uint32_t)0x12345679 \ + << EXCAUSE_TRAP; + QTest::newRow("TNE") << (std::uint8_t)ALU_OP_TNE \ + << (std::uint32_t)0x12345678 \ + << (std::uint32_t)0x12345678 \ + << EXCAUSE_NONE; + QTest::newRow("TGE") << (std::uint8_t)ALU_OP_TGE \ + << (std::uint32_t)0x12345679 \ + << (std::uint32_t)0x12345678 \ + << EXCAUSE_TRAP; + QTest::newRow("TGEU") << (std::uint8_t)ALU_OP_TGEU \ + << (std::uint32_t)0x12345679 \ + << (std::uint32_t)0x12345678 \ + << EXCAUSE_TRAP; + QTest::newRow("TLT") << (std::uint8_t)ALU_OP_TLT \ + << (std::uint32_t)0x12345678 \ + << (std::uint32_t)0x12345679 \ + << EXCAUSE_TRAP; + QTest::newRow("TLTU") << (std::uint8_t)ALU_OP_TLTU \ + << (std::uint32_t)0x12345678 \ + << (std::uint32_t)0x12345679 \ + << EXCAUSE_TRAP; +} + +void MachineTests::alu_trap_overflow() { + bool discard; + enum ExceptionCause exc = EXCAUSE_NONE; + QFETCH(std::uint8_t, op); + QFETCH(std::uint32_t, s); + QFETCH(std::uint32_t, t); + QFETCH(enum ExceptionCause, excause); + Registers regs; + + // Only runtime exception is expected as any other exception is a bug + alu_operate((enum AluOp)op, s , t, 0, 0, ®s, discard, exc); + QCOMPARE((uint)exc, (uint)excause); +} + + +void MachineTests::alu_except_data() { + QTest::addColumn("op"); + QTest::addColumn("s"); + QTest::addColumn("t"); + // Just test that we can throw unsupported ALU operation QTest::newRow("?") << (std::uint8_t)ALU_OP_LAST \ << (std::uint32_t)0 \ @@ -248,11 +307,13 @@ void MachineTests::alu_except_data() { void MachineTests::alu_except() { bool discard; + enum ExceptionCause excause = EXCAUSE_NONE; QFETCH(std::uint8_t, op); QFETCH(std::uint32_t, s); QFETCH(std::uint32_t, t); Registers regs; // Only runtime exception is expected as any other exception is a bug - QVERIFY_EXCEPTION_THROWN(alu_operate((enum AluOp)op, s , t, 0, 0, ®s, discard), QtMipsExceptionRuntime); + QVERIFY_EXCEPTION_THROWN(alu_operate((enum AluOp)op, s , t, 0, 0, ®s, discard, excause), + QtMipsExceptionRuntime); } diff --git a/qtmips_machine/tests/tst_machine.h b/qtmips_machine/tests/tst_machine.h index 07b5e42..0f9d753 100644 --- a/qtmips_machine/tests/tst_machine.h +++ b/qtmips_machine/tests/tst_machine.h @@ -66,6 +66,8 @@ private Q_SLOTS: // Alu void alu(); void alu_data(); + void alu_trap_overflow(); + void alu_trap_overflow_data(); void alu_except(); void alu_except_data(); // Core -- cgit v1.2.3