aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-12-17 13:31:25 +0100
committerKarel Kočí <cynerd@email.cz>2017-12-17 13:31:25 +0100
commite0c757926743ee21f1a60b4b6948ca3eb895c373 (patch)
treed2acad9475849d5abed15cdd4b6bf3b8d9030f06 /qtmips_machine
parent7fa050ddefca5373b09bdbcbb3aa0902eacd5d2f (diff)
downloadqtmips-e0c757926743ee21f1a60b4b6948ca3eb895c373.tar.gz
qtmips-e0c757926743ee21f1a60b4b6948ca3eb895c373.tar.bz2
qtmips-e0c757926743ee21f1a60b4b6948ca3eb895c373.zip
Put qtmips_machine to machine namespace
Diffstat (limited to 'qtmips_machine')
-rw-r--r--qtmips_machine/alu.cpp6
-rw-r--r--qtmips_machine/alu.h6
-rw-r--r--qtmips_machine/cache.cpp2
-rw-r--r--qtmips_machine/cache.h4
-rw-r--r--qtmips_machine/core.cpp2
-rw-r--r--qtmips_machine/core.h4
-rw-r--r--qtmips_machine/instruction.cpp2
-rw-r--r--qtmips_machine/instruction.h6
-rw-r--r--qtmips_machine/machineconfig.cpp2
-rw-r--r--qtmips_machine/machineconfig.h4
-rw-r--r--qtmips_machine/memory.cpp4
-rw-r--r--qtmips_machine/memory.h9
-rw-r--r--qtmips_machine/programloader.cpp2
-rw-r--r--qtmips_machine/programloader.h3
-rw-r--r--qtmips_machine/qtmipsexception.cpp2
-rw-r--r--qtmips_machine/qtmipsexception.h6
-rw-r--r--qtmips_machine/qtmipsmachine.cpp2
-rw-r--r--qtmips_machine/qtmipsmachine.h4
-rw-r--r--qtmips_machine/registers.cpp2
-rw-r--r--qtmips_machine/registers.h6
-rw-r--r--qtmips_machine/tests/testalu.cpp2
-rw-r--r--qtmips_machine/tests/testcore.cpp2
-rw-r--r--qtmips_machine/tests/testinstruction.cpp2
-rw-r--r--qtmips_machine/tests/testmemory.cpp2
-rw-r--r--qtmips_machine/tests/testprogramloader.cpp2
-rw-r--r--qtmips_machine/tests/testregisters.cpp2
26 files changed, 81 insertions, 9 deletions
diff --git a/qtmips_machine/alu.cpp b/qtmips_machine/alu.cpp
index d6e7254..f8b919b 100644
--- a/qtmips_machine/alu.cpp
+++ b/qtmips_machine/alu.cpp
@@ -1,7 +1,9 @@
#include "alu.h"
#include "qtmipsexception.h"
-std::uint32_t alu_operate(enum AluOp operation, std::uint32_t s, std::uint32_t t, std::uint8_t sa, Registers *regs) {
+using namespace machine;
+
+std::uint32_t machine::alu_operate(enum AluOp operation, std::uint32_t s, std::uint32_t t, std::uint8_t sa, Registers *regs) {
switch(operation) {
case ALU_OP_SLL:
return t << sa;
@@ -67,7 +69,7 @@ std::uint32_t alu_operate(enum AluOp operation, std::uint32_t s, std::uint32_t t
}
}
-QString alu_str(enum AluOp operation, std::uint32_t s, std::uint32_t t, std::uint8_t sa) {
+QString machine::alu_str(enum AluOp operation, std::uint32_t s, std::uint32_t t, std::uint8_t sa) {
// TODO
return QString("");
}
diff --git a/qtmips_machine/alu.h b/qtmips_machine/alu.h
index 4d09013..1f89acf 100644
--- a/qtmips_machine/alu.h
+++ b/qtmips_machine/alu.h
@@ -6,6 +6,8 @@
#include <QObject>
#include <registers.h>
+namespace machine {
+
// TODO Any other operations? We seems to be missing a lot of them.
enum AluOp : std::uint8_t {
ALU_OP_SLL = 0,
@@ -47,6 +49,8 @@ std::uint32_t alu_operate(enum AluOp operation, std::uint32_t s, std::uint32_t t
// Returns string representation of ALU instruction (internally used by Instruction::to_str)
QString alu_str(enum AluOp operation, std::uint32_t s, std::uint32_t t, std::uint8_t sa);
-Q_DECLARE_METATYPE(AluOp)
+}
+
+Q_DECLARE_METATYPE(machine::AluOp)
#endif // ALU_H
diff --git a/qtmips_machine/cache.cpp b/qtmips_machine/cache.cpp
index 05b26b0..152b1c7 100644
--- a/qtmips_machine/cache.cpp
+++ b/qtmips_machine/cache.cpp
@@ -1 +1,3 @@
#include "cache.h"
+
+using namespace machine;
diff --git a/qtmips_machine/cache.h b/qtmips_machine/cache.h
index 280ac05..4b91858 100644
--- a/qtmips_machine/cache.h
+++ b/qtmips_machine/cache.h
@@ -3,6 +3,8 @@
#include "memory.h"
+namespace machine {
+
class Cache : public MemoryAccess {
public:
Cache(Memory *m);
@@ -15,4 +17,6 @@ public:
// TODO other chaches
+}
+
#endif // CACHE_H
diff --git a/qtmips_machine/core.cpp b/qtmips_machine/core.cpp
index eba423f..000d76d 100644
--- a/qtmips_machine/core.cpp
+++ b/qtmips_machine/core.cpp
@@ -1,6 +1,8 @@
#include "core.h"
#include "programloader.h"
+using namespace machine;
+
#define DM_SUPPORTED (1L<<0)
#define DM_MEMWRITE (1L<<1)
#define DM_MEMREAD (1L<<2)
diff --git a/qtmips_machine/core.h b/qtmips_machine/core.h
index 07933ab..5c61ddb 100644
--- a/qtmips_machine/core.h
+++ b/qtmips_machine/core.h
@@ -8,6 +8,8 @@
#include "instruction.h"
#include "alu.h"
+namespace machine {
+
class Core : public QObject {
Q_OBJECT
public:
@@ -88,4 +90,6 @@ private:
struct Core::dtMemory dt_m;
};
+}
+
#endif // CORE_H
diff --git a/qtmips_machine/instruction.cpp b/qtmips_machine/instruction.cpp
index b6abebc..a90fd5a 100644
--- a/qtmips_machine/instruction.cpp
+++ b/qtmips_machine/instruction.cpp
@@ -1,6 +1,8 @@
#include "instruction.h"
#include "qtmipsexception.h"
+using namespace machine;
+
struct InstructionMap {
const char *name;
};
diff --git a/qtmips_machine/instruction.h b/qtmips_machine/instruction.h
index 0a87826..fc8dbf5 100644
--- a/qtmips_machine/instruction.h
+++ b/qtmips_machine/instruction.h
@@ -4,6 +4,8 @@
#include <QObject>
#include <qstring.h>
+namespace machine {
+
class Instruction : public QObject {
Q_OBJECT
public:
@@ -34,6 +36,8 @@ private:
std::uint32_t dt;
};
-Q_DECLARE_METATYPE(Instruction)
+}
+
+Q_DECLARE_METATYPE(machine::Instruction)
#endif // INSTRUCTION_H
diff --git a/qtmips_machine/machineconfig.cpp b/qtmips_machine/machineconfig.cpp
index 05624cc..2b4da34 100644
--- a/qtmips_machine/machineconfig.cpp
+++ b/qtmips_machine/machineconfig.cpp
@@ -1,5 +1,7 @@
#include "machineconfig.h"
+using namespace machine;
+
MachineConfig::MachineConfig() {
pipeline = false;
jumppred = false;
diff --git a/qtmips_machine/machineconfig.h b/qtmips_machine/machineconfig.h
index 352e62b..8e58d12 100644
--- a/qtmips_machine/machineconfig.h
+++ b/qtmips_machine/machineconfig.h
@@ -3,6 +3,8 @@
#include <QString>
+namespace machine {
+
class MachineConfig {
public:
MachineConfig();
@@ -37,4 +39,6 @@ private:
QString elf_path;
};
+}
+
#endif // MACHINECONFIG_H
diff --git a/qtmips_machine/memory.cpp b/qtmips_machine/memory.cpp
index 3d711cc..23743d5 100644
--- a/qtmips_machine/memory.cpp
+++ b/qtmips_machine/memory.cpp
@@ -1,5 +1,7 @@
#include "memory.h"
+using namespace machine;
+
// Note about endianness: Current memory implementation is expected to be a big endian.
// But we can be running on little endian so we should do conversion from bytes to word according that.
@@ -157,10 +159,12 @@ bool MemorySection::operator!=(const MemorySection &ms) const {
#error Memory tree have to be higher or in limit equal to two
#endif
+namespace machine {
union MemoryTree {
union MemoryTree *mt;
MemorySection *sec;
};
+}
Memory::Memory() {
this->mt_root = allocate_section_tree();
diff --git a/qtmips_machine/memory.h b/qtmips_machine/memory.h
index 7b14855..73ee534 100644
--- a/qtmips_machine/memory.h
+++ b/qtmips_machine/memory.h
@@ -6,6 +6,8 @@
#include <cstdint>
#include "qtmipsexception.h"
+namespace machine {
+
// Virtual class for common memory access
class MemoryAccess : public QObject {
Q_OBJECT
@@ -34,8 +36,6 @@ signals:
void byte_change(std::uint32_t address, std::uint32_t value);
};
-Q_DECLARE_METATYPE(MemoryAccess::AccessControl)
-
class MemorySection : public MemoryAccess {
public:
MemorySection(std::uint32_t length);
@@ -91,6 +91,9 @@ private:
static union MemoryTree *copy_section_tree(const union MemoryTree*, size_t depth);
};
-Q_DECLARE_METATYPE(Memory)
+}
+
+Q_DECLARE_METATYPE(machine::MemoryAccess::AccessControl)
+Q_DECLARE_METATYPE(machine::Memory)
#endif // MEMORY_H
diff --git a/qtmips_machine/programloader.cpp b/qtmips_machine/programloader.cpp
index bad0a82..4a10540 100644
--- a/qtmips_machine/programloader.cpp
+++ b/qtmips_machine/programloader.cpp
@@ -6,6 +6,8 @@
#include <cstring>
#include "qtmipsexception.h"
+using namespace machine;
+
ProgramLoader::ProgramLoader(const char *file) {
// Initialize elf library
if (elf_version(EV_CURRENT) == EV_NONE)
diff --git a/qtmips_machine/programloader.h b/qtmips_machine/programloader.h
index 7da241c..6c13d18 100644
--- a/qtmips_machine/programloader.h
+++ b/qtmips_machine/programloader.h
@@ -9,6 +9,7 @@
#include <qstring.h>
#include "memory.h"
+namespace machine {
class ProgramLoader {
public:
@@ -27,4 +28,6 @@ private:
QVector<size_t> map; // external index to phdrs index
};
+}
+
#endif // PROGRAM_H
diff --git a/qtmips_machine/qtmipsexception.cpp b/qtmips_machine/qtmipsexception.cpp
index bb852a8..76d0cc6 100644
--- a/qtmips_machine/qtmipsexception.cpp
+++ b/qtmips_machine/qtmipsexception.cpp
@@ -2,6 +2,8 @@
#include <iostream>
#include <cstring>
+using namespace machine;
+
QtMipsException::QtMipsException(QTMIPS_ARGS_COMMON) {
this->reason = reason;
this->ext = ext;
diff --git a/qtmips_machine/qtmipsexception.h b/qtmips_machine/qtmipsexception.h
index cfab81a..3f742ad 100644
--- a/qtmips_machine/qtmipsexception.h
+++ b/qtmips_machine/qtmipsexception.h
@@ -4,7 +4,9 @@
#include <exception>
#include <qstring.h>
-#define QTMIPS_EXCEPTION(TYPE, REASON, EXT) (QtMipsException ## TYPE (QString(REASON), QString(EXT), QString(__FILE__), __LINE__))
+namespace machine {
+
+#define QTMIPS_EXCEPTION(TYPE, REASON, EXT) (machine::QtMipsException ## TYPE (QString(REASON), QString(EXT), QString(__FILE__), __LINE__))
#define QTMIPS_ARGS_COMMON QString reason, QString ext, QString file, int line
// Base exception for all machine ones
@@ -82,4 +84,6 @@ public:
#define SANITY_ASSERT(COND, MSG) do { if (!(COND)) throw QTMIPS_EXCEPTION(Sanity, "Sanity check failed (" #COND ")", MSG); } while (false)
+}
+
#endif // QTMIPSEXCEPTION_H
diff --git a/qtmips_machine/qtmipsmachine.cpp b/qtmips_machine/qtmipsmachine.cpp
index 191a7c7..8d1a46a 100644
--- a/qtmips_machine/qtmipsmachine.cpp
+++ b/qtmips_machine/qtmipsmachine.cpp
@@ -1,6 +1,8 @@
#include "qtmipsmachine.h"
#include "programloader.h"
+using namespace machine;
+
QtMipsMachine::QtMipsMachine(const MachineConfig &cc) {
ProgramLoader program(cc.elf());
diff --git a/qtmips_machine/qtmipsmachine.h b/qtmips_machine/qtmipsmachine.h
index c185f28..15d62e9 100644
--- a/qtmips_machine/qtmipsmachine.h
+++ b/qtmips_machine/qtmipsmachine.h
@@ -11,6 +11,8 @@
#include "core.h"
#include "cache.h"
+namespace machine {
+
class QtMipsMachine : public QObject {
Q_OBJECT
public:
@@ -47,4 +49,6 @@ private:
bool program_ended;
};
+}
+
#endif // QTMIPSMACHINE_H
diff --git a/qtmips_machine/registers.cpp b/qtmips_machine/registers.cpp
index b77b1b7..f8961e1 100644
--- a/qtmips_machine/registers.cpp
+++ b/qtmips_machine/registers.cpp
@@ -1,6 +1,8 @@
#include "registers.h"
#include "qtmipsexception.h"
+using namespace machine;
+
// TODO should this be configurable?
//////////////////////////////////////////////////////////////////////////////
/// Program counter initial value
diff --git a/qtmips_machine/registers.h b/qtmips_machine/registers.h
index 4a693db..fa3e304 100644
--- a/qtmips_machine/registers.h
+++ b/qtmips_machine/registers.h
@@ -4,6 +4,8 @@
#include <QObject>
#include <cstdint>
+namespace machine {
+
class Registers : public QObject {
Q_OBJECT
public:
@@ -35,6 +37,8 @@ private:
std::uint32_t pc; // program counter
};
-Q_DECLARE_METATYPE(Registers)
+}
+
+Q_DECLARE_METATYPE(machine::Registers)
#endif // REGISTERS_H
diff --git a/qtmips_machine/tests/testalu.cpp b/qtmips_machine/tests/testalu.cpp
index 603a610..7668679 100644
--- a/qtmips_machine/tests/testalu.cpp
+++ b/qtmips_machine/tests/testalu.cpp
@@ -2,6 +2,8 @@
#include "alu.h"
#include "qtmipsexception.h"
+using namespace machine;
+
void MachineTests::alu_data() {
QTest::addColumn<AluOp>("op");
QTest::addColumn<std::uint32_t>("s");
diff --git a/qtmips_machine/tests/testcore.cpp b/qtmips_machine/tests/testcore.cpp
index efc06da..0bd18ba 100644
--- a/qtmips_machine/tests/testcore.cpp
+++ b/qtmips_machine/tests/testcore.cpp
@@ -1,6 +1,8 @@
#include "tst_machine.h"
#include "core.h"
+using namespace machine;
+
static void core_regs_data() {
QTest::addColumn<Instruction>("i");
QTest::addColumn<Registers>("init");
diff --git a/qtmips_machine/tests/testinstruction.cpp b/qtmips_machine/tests/testinstruction.cpp
index 4efedac..2cdf119 100644
--- a/qtmips_machine/tests/testinstruction.cpp
+++ b/qtmips_machine/tests/testinstruction.cpp
@@ -1,6 +1,8 @@
#include "tst_machine.h"
#include "instruction.h"
+using namespace machine;
+
// Test that we are correctly encoding instructions in constructor
void MachineTests::instruction() {
QCOMPARE(Instruction(0x00), Instruction(0,0));
diff --git a/qtmips_machine/tests/testmemory.cpp b/qtmips_machine/tests/testmemory.cpp
index f1c6b80..bef1a59 100644
--- a/qtmips_machine/tests/testmemory.cpp
+++ b/qtmips_machine/tests/testmemory.cpp
@@ -1,6 +1,8 @@
#include "tst_machine.h"
#include "memory.h"
+using namespace machine;
+
void MachineTests::memory_data() {
QTest::addColumn<std::uint32_t>("address");
diff --git a/qtmips_machine/tests/testprogramloader.cpp b/qtmips_machine/tests/testprogramloader.cpp
index 7ff1c54..057bf3f 100644
--- a/qtmips_machine/tests/testprogramloader.cpp
+++ b/qtmips_machine/tests/testprogramloader.cpp
@@ -3,6 +3,8 @@
#include "programloader.h"
#include "instruction.h"
+using namespace machine;
+
// This is common program start (initial value of program counter)
#define PC_INIT 0x80020000
diff --git a/qtmips_machine/tests/testregisters.cpp b/qtmips_machine/tests/testregisters.cpp
index b498c11..57a6479 100644
--- a/qtmips_machine/tests/testregisters.cpp
+++ b/qtmips_machine/tests/testregisters.cpp
@@ -2,6 +2,8 @@
#include <qtmipsexception.h>
#include <registers.h>
+using namespace machine;
+
void MachineTests::registers_gp0() {
Registers r;
QCOMPARE(r.read_gp(0), (unsigned)0);