chore: minor changes
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
		@@ -79,8 +79,8 @@ main(int argc, const char* argv[]) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Memory memory(std::move(bios), std::move(rom));
 | 
					        Memory memory(std::move(bios), std::move(rom));
 | 
				
			||||||
        Bus bus(std::make_shared<Memory>(memory));
 | 
					        Bus bus(memory);
 | 
				
			||||||
        Cpu cpu(std::make_shared<Bus>(bus));
 | 
					        Cpu cpu(bus);
 | 
				
			||||||
        cpu.step();
 | 
					        cpu.step();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,7 +38,7 @@
 | 
				
			|||||||
              ".cc"
 | 
					              ".cc"
 | 
				
			||||||
              ".build"
 | 
					              ".build"
 | 
				
			||||||
            ];
 | 
					            ];
 | 
				
			||||||
            outputs = [ "dev" "out" ];
 | 
					            outputs = [ "out" "dev" ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            inherit nativeBuildInputs;
 | 
					            inherit nativeBuildInputs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
#include "bus.hh"
 | 
					#include "bus.hh"
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Bus::Bus(std::shared_ptr<Memory> memory)
 | 
					Bus::Bus(Memory& memory)
 | 
				
			||||||
  : memory(memory) {}
 | 
					  : memory(std::make_shared<Memory>(memory)) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint8_t
 | 
					uint8_t
 | 
				
			||||||
Bus::read_byte(size_t address) {
 | 
					Bus::read_byte(size_t address) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class Bus {
 | 
					class Bus {
 | 
				
			||||||
  public:
 | 
					  public:
 | 
				
			||||||
    Bus(std::shared_ptr<Memory> memory);
 | 
					    Bus(Memory& memory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uint8_t read_byte(size_t address);
 | 
					    uint8_t read_byte(size_t address);
 | 
				
			||||||
    void write_byte(size_t address, uint8_t byte);
 | 
					    void write_byte(size_t address, uint8_t byte);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,11 +6,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
using namespace logger;
 | 
					using namespace logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Cpu::Cpu(std::shared_ptr<Bus> bus)
 | 
					Cpu::Cpu(Bus& bus)
 | 
				
			||||||
  : gpr(0)
 | 
					  : gpr(0)
 | 
				
			||||||
  , cpsr(0)
 | 
					  , cpsr(0)
 | 
				
			||||||
  , spsr(0)
 | 
					  , spsr(0)
 | 
				
			||||||
  , bus(bus)
 | 
					  , bus(std::make_shared<Bus>(bus))
 | 
				
			||||||
  , gpr_banked({ { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 } })
 | 
					  , gpr_banked({ { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 } })
 | 
				
			||||||
  , spsr_banked({ 0, 0, 0, 0, 0 }) {
 | 
					  , spsr_banked({ 0, 0, 0, 0, 0 }) {
 | 
				
			||||||
    cpsr.set_mode(Mode::System);
 | 
					    cpsr.set_mode(Mode::System);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,7 @@ using std::size_t;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class Cpu {
 | 
					class Cpu {
 | 
				
			||||||
  public:
 | 
					  public:
 | 
				
			||||||
    Cpu(std::shared_ptr<Bus> bus);
 | 
					    Cpu(Bus& bus);
 | 
				
			||||||
    void step();
 | 
					    void step();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private:
 | 
					  private:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@ Cpu::exec_arm(uint32_t insn) {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Branch and exhcange
 | 
					    // Branch and exhcange
 | 
				
			||||||
    if ((insn & 0x0ffffff0) == 0x012fff10) {
 | 
					    if ((insn & 0x0FFFFFF0) == 0x012FFF10) {
 | 
				
			||||||
        static constexpr char syn[] = "BX";
 | 
					        static constexpr char syn[] = "BX";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        uint8_t rn = insn & 0b1111;
 | 
					        uint8_t rn = insn & 0b1111;
 | 
				
			||||||
@@ -46,7 +46,7 @@ Cpu::exec_arm(uint32_t insn) {
 | 
				
			|||||||
                rst_nth_bit(gpr[15], 1);
 | 
					                rst_nth_bit(gpr[15], 1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Branch
 | 
					        // Branch
 | 
				
			||||||
    } else if ((insn & 0x0e000000) == 0x0a000000) {
 | 
					    } else if ((insn & 0x0E000000) == 0x0A000000) {
 | 
				
			||||||
        static constexpr char syn[] = "B";
 | 
					        static constexpr char syn[] = "B";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        bool link       = get_nth_bit(insn, 24);
 | 
					        bool link       = get_nth_bit(insn, 24);
 | 
				
			||||||
@@ -69,7 +69,7 @@ Cpu::exec_arm(uint32_t insn) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Multiply
 | 
					        // Multiply
 | 
				
			||||||
    } else if ((insn & 0x0fc000f0) == 0x00000090) {
 | 
					    } else if ((insn & 0x0FC000F0) == 0x00000090) {
 | 
				
			||||||
        static constexpr char syn[2][4] = { "MUL", "MLA" };
 | 
					        static constexpr char syn[2][4] = { "MUL", "MLA" };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        uint8_t rm = get_bit_range(insn, 0, 3);
 | 
					        uint8_t rm = get_bit_range(insn, 0, 3);
 | 
				
			||||||
@@ -116,7 +116,7 @@ Cpu::exec_arm(uint32_t insn) {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Multiply long
 | 
					        // Multiply long
 | 
				
			||||||
    } else if ((insn & 0x0f8000f0) == 0x00800090) {
 | 
					    } else if ((insn & 0x0F8000F0) == 0x00800090) {
 | 
				
			||||||
        static constexpr char syn[2][2][6] = { { "SMULL", "SMLAL" },
 | 
					        static constexpr char syn[2][2][6] = { { "SMULL", "SMLAL" },
 | 
				
			||||||
                                               { "UMULL", "UMLAL" } };
 | 
					                                               { "UMULL", "UMLAL" } };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -177,7 +177,7 @@ Cpu::exec_arm(uint32_t insn) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Single data swap
 | 
					        // Single data swap
 | 
				
			||||||
    } else if ((insn & 0x0fb00ff0) == 0x01000090) {
 | 
					    } else if ((insn & 0x0FB00FF0) == 0x01000090) {
 | 
				
			||||||
        static constexpr char syn[] = "SWP";
 | 
					        static constexpr char syn[] = "SWP";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        uint8_t rm = get_bit_range(insn, 0, 3);
 | 
					        uint8_t rm = get_bit_range(insn, 0, 3);
 | 
				
			||||||
@@ -205,7 +205,7 @@ Cpu::exec_arm(uint32_t insn) {
 | 
				
			|||||||
        // Halfword transfer
 | 
					        // Halfword transfer
 | 
				
			||||||
        // TODO: create abstraction to reuse for block data and single data
 | 
					        // TODO: create abstraction to reuse for block data and single data
 | 
				
			||||||
        // transfer
 | 
					        // transfer
 | 
				
			||||||
    } else if ((insn & 0x0e000090) == 0x00000090) {
 | 
					    } else if ((insn & 0x0E000090) == 0x00000090) {
 | 
				
			||||||
        static constexpr char syn[2][4] = { "STR", "LDR" };
 | 
					        static constexpr char syn[2][4] = { "STR", "LDR" };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        uint8_t rm = get_bit_range(insn, 0, 3);
 | 
					        uint8_t rm = get_bit_range(insn, 0, 3);
 | 
				
			||||||
@@ -265,13 +265,13 @@ Cpu::exec_arm(uint32_t insn) {
 | 
				
			|||||||
                        gpr[rd] = bus->read_halfword(address);
 | 
					                        gpr[rd] = bus->read_halfword(address);
 | 
				
			||||||
                        // sign extend the halfword
 | 
					                        // sign extend the halfword
 | 
				
			||||||
                        if (get_nth_bit(gpr[rd], 15))
 | 
					                        if (get_nth_bit(gpr[rd], 15))
 | 
				
			||||||
                            gpr[rd] |= 0xffff0000;
 | 
					                            gpr[rd] |= 0xFFFF0000;
 | 
				
			||||||
                        // byte
 | 
					                        // byte
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                        // sign extend the byte
 | 
					                        // sign extend the byte
 | 
				
			||||||
                        gpr[rd] = bus->read_byte(address);
 | 
					                        gpr[rd] = bus->read_byte(address);
 | 
				
			||||||
                        if (get_nth_bit(gpr[rd], 7))
 | 
					                        if (get_nth_bit(gpr[rd], 7))
 | 
				
			||||||
                            gpr[rd] |= 0xffffff00;
 | 
					                            gpr[rd] |= 0xFFFFFF00;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    // unsigned halfword
 | 
					                    // unsigned halfword
 | 
				
			||||||
                } else if (h) {
 | 
					                } else if (h) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user