aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine/tests/testregisters.cpp
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-08-30 21:37:53 +0200
committerKarel Kočí <cynerd@email.cz>2017-08-30 21:42:02 +0200
commit9cf92379d5fcf0076c25dae0935daab446c992cd (patch)
treedd09a2e996db1e5a8117f01bec76f1e93eaca6e1 /qtmips_machine/tests/testregisters.cpp
downloadqtmips-9cf92379d5fcf0076c25dae0935daab446c992cd.tar.gz
qtmips-9cf92379d5fcf0076c25dae0935daab446c992cd.tar.bz2
qtmips-9cf92379d5fcf0076c25dae0935daab446c992cd.zip
Initial commit
Adding work done so far.
Diffstat (limited to 'qtmips_machine/tests/testregisters.cpp')
-rw-r--r--qtmips_machine/tests/testregisters.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/qtmips_machine/tests/testregisters.cpp b/qtmips_machine/tests/testregisters.cpp
new file mode 100644
index 0000000..4430beb
--- /dev/null
+++ b/qtmips_machine/tests/testregisters.cpp
@@ -0,0 +1,39 @@
+#include "tst_machine.h"
+#include <qtmipsexception.h>
+#include <registers.h>
+
+void MachineTests::registers_gp0() {
+ Registers r;
+ QCOMPARE(r.read_gp(0), (unsigned)0);
+ r.write_gp(0, 0xff);
+ QCOMPARE(r.read_gp(0), (unsigned)0);
+}
+
+void MachineTests::registers_rw_gp() {
+ Registers r;
+ for (int i = 1; i < 32; i++) {
+ r.write_gp(i, 0xf00 + i);
+ QCOMPARE(r.read_gp(i), (unsigned)(0xf00 + i));
+ }
+}
+
+void MachineTests::registers_rw_hi_lo() {
+ Registers r;
+ r.write_hi_lo(false, 0xee);
+ r.write_hi_lo(true, 0xaa);
+ QCOMPARE(r.read_hi_lo(false), (unsigned)0xee);
+ QCOMPARE(r.read_hi_lo(true), (unsigned)0xaa);
+}
+
+void MachineTests::registers_pc() {
+ Registers r;
+ QCOMPARE(r.read_pc(), (unsigned)0x80020000); // Check initial pc address
+ QCOMPARE(r.pc_inc(), (unsigned)0x80020004);
+ QCOMPARE(r.pc_inc(), (unsigned)0x80020008);
+ QCOMPARE(r.pc_jmp(-0x8), (unsigned)0x80020000);
+ QCOMPARE(r.pc_jmp(0xC), (unsigned)0x8002000C);
+ r.pc_abs_jmp(0x80020100);
+ QCOMPARE(r.read_pc(), (unsigned)0x80020100);
+ QVERIFY_EXCEPTION_THROWN(r.pc_jmp(0x1), QtMipsExceptionUnalignedJump);
+ QVERIFY_EXCEPTION_THROWN(r.pc_abs_jmp(0x80020101), QtMipsExceptionUnalignedJump);
+}