From 2be9570aa99080419532210db3330d8c71bebe79 Mon Sep 17 00:00:00 2001 From: iris Date: Tue, 12 May 2026 14:27:59 +0200 Subject: [PATCH] getting to my first branch now --- CMakeLists.txt | 2 ++ core/broadway.cpp | 8 +++++--- core/broadway.hpp | 4 ++++ core/broadway/instructions.cpp | 11 +++++++++-- core/broadway/utils.hpp | 11 +++++++++++ external/ircolib/types.hpp | 19 +++++++++++++++++++ 6 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 core/broadway/utils.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 18b9e2c..f50441c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,10 +9,12 @@ option(BUILD_SHARED_LIBS OFF) include_directories(external/ELFIO) include_directories(external/capstone/include) include_directories(external/cflags/include) +include_directories(external/xbyak) include_directories(external) if(WIN32) add_compile_definitions(_CRT_SECURE_NO_WARNINGS) + add_compile_definitions(NOMINMAX) endif() set(CAPSTONE_ARCHITECTURE_DEFAULT OFF) diff --git a/core/broadway.cpp b/core/broadway.cpp index 09535f4..51ac944 100644 --- a/core/broadway.cpp +++ b/core/broadway.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -29,11 +29,13 @@ ircolib::u32 broadway::fetch(mem &mem) { } void broadway::execute(ircolib::u32 instr, mem &mem) { - ircolib::u8 primary = (instr >> 26) & 0x3f; - switch (primary) { + switch (utils::primary(instr)) { case 15: // addis rd, ra, simm addis(instr); break; + case 24: // ori ra, rs, uimm + ori(instr); + break; default: std::println("broadway::execute unimplemented instruction 0x{:08X} / 0b{:032b}", instr, instr); std::println("disassembly:"); diff --git a/core/broadway.hpp b/core/broadway.hpp index 8d663d0..4cc228a 100644 --- a/core/broadway.hpp +++ b/core/broadway.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include namespace weee::core { @@ -18,9 +19,12 @@ struct broadway { bool disasm_available = true; ircolib::u32 pc = 0; std::array gpr{}; + // ircolib::u32 const_gpr_lookup{}; csh capstone; + // Xbyak::CodeGenerator code; // instructions void addis(ircolib::u32); + void ori(ircolib::u32); }; } // namespace weee::core diff --git a/core/broadway/instructions.cpp b/core/broadway/instructions.cpp index 23a5f3c..416d800 100644 --- a/core/broadway/instructions.cpp +++ b/core/broadway/instructions.cpp @@ -1,7 +1,14 @@ -#include +#include namespace weee::core { void broadway::addis(ircolib::u32 instr) { - + if (utils::RA(instr) == 0) { // lis + gpr[utils::RD(instr)] = ircolib::s32(utils::SIMM(instr)) << 16; + return; + } + + gpr[utils::RD(instr)] = gpr[utils::RA(instr)] + (ircolib::s32(utils::SIMM(instr)) << 16); } + +void broadway::ori(ircolib::u32 instr) { gpr[utils::RA(instr)] = gpr[utils::RS(instr)] | utils::UIMM(instr); } } // namespace weee::core diff --git a/core/broadway/utils.hpp b/core/broadway/utils.hpp new file mode 100644 index 0000000..365442c --- /dev/null +++ b/core/broadway/utils.hpp @@ -0,0 +1,11 @@ +#pragma once +#include + +namespace weee::core::utils { +static inline ircolib::u8 primary(ircolib::u32 instr) { return (instr >> 26) & 0x3f; } +static inline ircolib::u8 RD(ircolib::u32 instr) { return (instr >> 21) & 0x1f; } +static inline ircolib::u8 RS(ircolib::u32 instr) { return RD(instr); } +static inline ircolib::u8 RA(ircolib::u32 instr) { return (instr >> 16) & 0x1f; } +static inline ircolib::u16 UIMM(ircolib::u32 instr) { return instr & 0xffff; } +static inline ircolib::s16 SIMM(ircolib::u32 instr) { return UIMM(instr); } +} // namespace weee::core::utils diff --git a/external/ircolib/types.hpp b/external/ircolib/types.hpp index b96d7de..b03443d 100644 --- a/external/ircolib/types.hpp +++ b/external/ircolib/types.hpp @@ -11,6 +11,25 @@ using s16 = int16_t; using s32 = int32_t; using s64 = int64_t; +template +static constexpr bool is_bit_set(const T &val) { + return val & (1 << bit); +} + +template +static constexpr void set_bit(T &val) { + val |= 1 << bit; +} + +template +inline bool is_bit_set(const T &val, const size_t &bit) { + return val & (1 << bit); +} + +template +inline void set_bit(T &val, const size_t &bit) { + val |= 1 << bit; +} } // namespace ircolib constexpr ircolib::u32 operator""_kib(const unsigned long long v) { return v * 1024; }