chore: enclose everything in namespace matar

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2023-09-21 10:52:40 +05:30
parent 1eb4a9545b
commit 1e8966553f
20 changed files with 61 additions and 17 deletions

View File

@@ -4,9 +4,10 @@
using namespace logger;
namespace matar {
void
CpuImpl::exec_arm(const arm::Instruction instruction) {
Condition cond = instruction.condition;
arm::Condition cond = instruction.condition;
arm::InstructionData data = instruction.data;
debug(cpsr.condition(cond));
@@ -537,3 +538,4 @@ CpuImpl::exec_arm(const arm::Instruction instruction) {
} },
data);
}
}

View File

@@ -3,7 +3,8 @@
#include "util/bits.hh"
#include <iterator>
using namespace arm;
namespace matar {
namespace arm {
Instruction::Instruction(uint32_t insn)
: condition(static_cast<Condition>(bit_range(insn, 28, 31))) {
@@ -495,3 +496,5 @@ Instruction::disassemble() {
[](auto) { return std::string("unknown instruction"); } },
data);
}
}
}

View File

@@ -1,3 +1,4 @@
#pragma once
#include "cpu/utility.hh"
#include <cstdint>
#include <variant>
@@ -9,6 +10,7 @@ struct overloaded : Ts... {
template<class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
namespace matar {
namespace arm {
static constexpr size_t INSTRUCTION_SIZE = 4;
@@ -165,3 +167,4 @@ struct Instruction {
std::string disassemble();
};
}
}

View File

@@ -7,6 +7,7 @@
using namespace logger;
namespace matar {
CpuImpl::CpuImpl(const Bus& bus) noexcept
: bus(std::make_shared<Bus>(bus))
, gpr({ 0 })
@@ -142,3 +143,4 @@ CpuImpl::step() {
}
}
}
}

View File

@@ -6,6 +6,7 @@
#include <cstdint>
namespace matar {
class CpuImpl {
public:
CpuImpl(const Bus& bus) noexcept;
@@ -55,3 +56,4 @@ class CpuImpl {
Psr und;
} spsr_banked; // banked saved program status registers
};
}

View File

@@ -1,6 +1,7 @@
#include "cpu/cpu.hh"
#include "cpu-impl.hh"
namespace matar {
Cpu::Cpu(const Bus& bus) noexcept
: impl(std::make_unique<CpuImpl>(bus)){};
@@ -10,3 +11,4 @@ void
Cpu::step() {
impl->step();
};
}

View File

@@ -2,6 +2,7 @@
#include "util/bits.hh"
#include "util/log.hh"
namespace matar {
Psr::Psr(uint32_t raw)
: psr(raw & PSR_CLEAR_RESERVED) {}
@@ -59,7 +60,9 @@ GET_SET_NTH_BIT_FUNCTIONS(n, 31);
#undef GET_SET_NTH_BIT_FUNCTIONS
bool
Psr::condition(Condition cond) const {
Psr::condition(arm::Condition cond) const {
using arm::Condition;
switch (cond) {
case Condition::EQ:
return z();
@@ -95,3 +98,4 @@ Psr::condition(Condition cond) const {
return false;
}
}

View File

@@ -1,8 +1,10 @@
#pragma once
#include "arm/instruction.hh"
#include "utility.hh"
#include <cstdint>
namespace matar {
class Psr {
public:
// clear the reserved bits i.e, [8:27]
@@ -45,7 +47,7 @@ class Psr {
#undef GET_SET_NTH_BIT_FUNCTIONS
bool condition(Condition cond) const;
bool condition(arm::Condition cond) const;
private:
static constexpr uint32_t PSR_CLEAR_RESERVED = 0xF00000FF;
@@ -53,3 +55,4 @@ class Psr {
uint32_t psr;
};
}

View File

@@ -2,6 +2,8 @@
#include "util/bits.hh"
#include <bit>
namespace matar {
namespace arm {
std::ostream&
operator<<(std::ostream& os, const Condition cond) {
@@ -133,3 +135,5 @@ operator<<(std::ostream& os, const ShiftType shift_type) {
return os;
}
}
}

View File

@@ -5,6 +5,7 @@
static constexpr size_t THUMB_INSTRUCTION_SIZE = 2;
namespace matar {
enum class Mode {
/* M[4:0] in PSR */
User = 0b10000,
@@ -21,6 +22,7 @@ enum class State {
Thumb = 1
};
namespace arm {
enum class Condition {
EQ = 0b0000,
NE = 0b0001,
@@ -42,8 +44,6 @@ enum class Condition {
// https://fmt.dev/dev/api.html#std-ostream-support
std::ostream&
operator<<(std::ostream& os, const Condition cond);
template<>
struct fmt::formatter<Condition> : ostream_formatter {};
enum class OpCode {
AND = 0b0000,
@@ -67,8 +67,6 @@ enum class OpCode {
// https://fmt.dev/dev/api.html#std-ostream-support
std::ostream&
operator<<(std::ostream& os, const OpCode cond);
template<>
struct fmt::formatter<OpCode> : ostream_formatter {};
enum class ShiftType {
LSL = 0b00,
@@ -94,5 +92,12 @@ eval_shift(ShiftType shift_type, uint32_t value, uint8_t amount, bool& carry);
// https://fmt.dev/dev/api.html#std-ostream-support
std::ostream&
operator<<(std::ostream& os, const ShiftType cond);
}
}
template<>
struct fmt::formatter<ShiftType> : ostream_formatter {};
struct fmt::formatter<matar::arm::Condition> : ostream_formatter {};
template<>
struct fmt::formatter<matar::arm::OpCode> : ostream_formatter {};
template<>
struct fmt::formatter<matar::arm::ShiftType> : ostream_formatter {};