chore: enclose everything in namespace matar
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
#include "bus.hh"
 | 
			
		||||
#include <memory>
 | 
			
		||||
 | 
			
		||||
namespace matar {
 | 
			
		||||
Bus::Bus(const Memory& memory)
 | 
			
		||||
  : memory(std::make_shared<Memory>(memory)) {}
 | 
			
		||||
 | 
			
		||||
@@ -33,3 +34,4 @@ void
 | 
			
		||||
Bus::write_word(size_t address, uint32_t word) {
 | 
			
		||||
    memory->write_word(address, word);
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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() {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {};
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@
 | 
			
		||||
 | 
			
		||||
using namespace logger;
 | 
			
		||||
 | 
			
		||||
namespace matar {
 | 
			
		||||
Memory::Memory(std::array<uint8_t, BIOS_SIZE>&& bios,
 | 
			
		||||
               std::vector<uint8_t>&& rom)
 | 
			
		||||
  : bios(std::move(bios))
 | 
			
		||||
@@ -232,3 +233,4 @@ Memory::parse_header() {
 | 
			
		||||
 | 
			
		||||
    // multiboot not required right now
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ lib_sources = files(
 | 
			
		||||
subdir('cpu')
 | 
			
		||||
 | 
			
		||||
fmt = dependency('fmt', version : '>=10.1.0')
 | 
			
		||||
lib = static_library(
 | 
			
		||||
lib = library(
 | 
			
		||||
  meson.project_name(),
 | 
			
		||||
  lib_sources,
 | 
			
		||||
  dependencies: [fmt],
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user