From a95b06f703f392dc0bd9d6107c35d4408d32fec2 Mon Sep 17 00:00:00 2001 From: dingusdev <52434309+dingusdev@users.noreply.github.com> Date: Wed, 8 May 2024 07:07:32 -0700 Subject: [PATCH] Minor code clean-up --- cpu/ppc/poweropcodes.cpp | 2 +- cpu/ppc/ppcmacros.h | 44 ++++++++++++++++++++++----------- cpu/ppc/ppcopcodes.cpp | 7 +++--- devices/common/ata/atapicdrom.h | 2 +- devices/common/scsi/scsicdrom.h | 2 +- main.cpp | 4 +-- 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/cpu/ppc/poweropcodes.cpp b/cpu/ppc/poweropcodes.cpp index 919fb0c..4986bc0 100644 --- a/cpu/ppc/poweropcodes.cpp +++ b/cpu/ppc/poweropcodes.cpp @@ -61,7 +61,7 @@ template void dppc_interpreter::power_abs(); void dppc_interpreter::power_clcs() { uint32_t ppc_result_d; - ppc_grab_regsda(ppc_cur_instruction); + ppc_grab_da(ppc_cur_instruction); switch (reg_a) { case 12: //instruction cache line size case 13: //data cache line size diff --git a/cpu/ppc/ppcmacros.h b/cpu/ppc/ppcmacros.h index 69a20f8..5676101 100644 --- a/cpu/ppc/ppcmacros.h +++ b/cpu/ppc/ppcmacros.h @@ -36,54 +36,68 @@ along with this program. If not, see . uint32_t uimm = uint16_t(opcode); \ uint32_t ppc_result_a = ppc_state.gpr[reg_a]; -# define ppc_grab_regsasimm(opcode) \ +#define ppc_grab_regsasimm(opcode) \ int reg_a = (opcode >> 16) & 31; \ int32_t simm = int32_t(int16_t(opcode)); \ uint32_t ppc_result_a = ppc_state.gpr[reg_a]; -# define ppc_grab_regssauimm(opcode) \ +#define ppc_grab_regssauimm(opcode) \ int reg_s = (opcode >> 21) & 31; \ int reg_a = (opcode >> 16) & 31; \ uint32_t uimm = uint16_t(opcode); \ uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \ uint32_t ppc_result_a = ppc_state.gpr[reg_a]; +#define ppc_grab_da(opcode)\ + int reg_d = (opcode >> 21) & 31;\ + int reg_a = (opcode >> 16) & 31;\ + #define ppc_grab_dab(opcode) \ int reg_d = (opcode >> 21) & 31; \ int reg_a = (opcode >> 16) & 31; \ int reg_b = (opcode >> 11) & 31; +#define ppc_grab_s(opcode) \ + int reg_s = (opcode >> 21) & 31; \ + uint32_t ppc_result_d = ppc_state.gpr[reg_s]; + #define ppc_grab_regsdab(opcode) \ int reg_d = (opcode >> 21) & 31; \ - uint32_t reg_a = (opcode >> 16) & 31; \ - uint32_t reg_b = (opcode >> 11) & 31; \ + int reg_a = (opcode >> 16) & 31; \ + int reg_b = (opcode >> 11) & 31; \ uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \ uint32_t ppc_result_b = ppc_state.gpr[reg_b]; #define ppc_grab_regssab(opcode) \ - uint32_t reg_s = (opcode >> 21) & 31; \ - uint32_t reg_a = (opcode >> 16) & 31; \ - uint32_t reg_b = (opcode >> 11) & 31; \ + int reg_s = (opcode >> 21) & 31; \ + int reg_a = (opcode >> 16) & 31; \ + int reg_b = (opcode >> 11) & 31; \ uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \ uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \ uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \ -#define ppc_grab_regssa(opcode) \ - uint32_t reg_s = (opcode >> 21) & 31; \ - uint32_t reg_a = (opcode >> 16) & 31; \ +#define ppc_grab_regsab(opcode) \ + int reg_a = (opcode >> 16) & 31;\ + int reg_b = (opcode >> 11) & 31;\ + uint32_t ppc_result_a = ppc_state.gpr[reg_a];\ + uint32_t ppc_result_b = ppc_state.gpr[reg_b]; + + #define ppc_grab_regssa(opcode) \ + int reg_s = (opcode >> 21) & 31; \ + int reg_a = (opcode >> 16) & 31; \ uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \ uint32_t ppc_result_a = ppc_state.gpr[reg_a]; #define ppc_grab_regssash(opcode) \ - uint32_t reg_s = (opcode >> 21) & 31; \ - uint32_t reg_a = (opcode >> 16) & 31; \ - uint32_t rot_sh = (opcode >> 11) & 31; \ + int reg_s = (opcode >> 21) & 31; \ + int reg_a = (opcode >> 16) & 31; \ + int rot_sh = (opcode >> 11) & 31; \ uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \ uint32_t ppc_result_a = ppc_state.gpr[reg_a]; #define ppc_grab_regssb(opcode) \ - uint32_t reg_s = (opcode >> 21) & 31; \ - uint32_t reg_b = (opcode >> 11) & 31; \ + int reg_s = (opcode >> 21) & 31; \ + int reg_b = (opcode >> 11) & 31; \ uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \ uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \ diff --git a/cpu/ppc/ppcopcodes.cpp b/cpu/ppc/ppcopcodes.cpp index 4889f66..1d5ea9c 100644 --- a/cpu/ppc/ppcopcodes.cpp +++ b/cpu/ppc/ppcopcodes.cpp @@ -1048,7 +1048,7 @@ void dppc_interpreter::ppc_mftb() { } void dppc_interpreter::ppc_mtcrf() { - ppc_grab_regssa(ppc_cur_instruction); + ppc_grab_s(ppc_cur_instruction); uint8_t crm = (ppc_cur_instruction >> 12) & 0xFFU; uint32_t cr_mask = 0; @@ -1215,7 +1215,7 @@ void dppc_interpreter::ppc_cmp() { #endif int crf_d = (ppc_cur_instruction >> 21) & 0x1C; - ppc_grab_regssab(ppc_cur_instruction); + ppc_grab_regsab(ppc_cur_instruction); uint32_t xercon = (ppc_state.spr[SPR::XER] & XER::SO) >> 3; uint32_t cmp_c = (int32_t(ppc_result_a) == int32_t(ppc_result_b)) ? 0x20000000UL : \ (int32_t(ppc_result_a) > int32_t(ppc_result_b)) ? 0x40000000UL : 0x80000000UL; @@ -1247,7 +1247,7 @@ void dppc_interpreter::ppc_cmpl() { #endif int crf_d = (ppc_cur_instruction >> 21) & 0x1C; - ppc_grab_regssab(ppc_cur_instruction); + ppc_grab_regsab(ppc_cur_instruction); uint32_t xercon = (ppc_state.spr[SPR::XER] & XER::SO) >> 3; uint32_t cmp_c = (ppc_result_a == ppc_result_b) ? 0x20000000UL : \ (ppc_result_a > ppc_result_b) ? 0x40000000UL : 0x80000000UL; @@ -1261,7 +1261,6 @@ void dppc_interpreter::ppc_cmpli() { return; } #endif - int crf_d = (ppc_cur_instruction >> 21) & 0x1C; ppc_grab_regssauimm(ppc_cur_instruction); uint32_t xercon = (ppc_state.spr[SPR::XER] & XER::SO) >> 3; diff --git a/devices/common/ata/atapicdrom.h b/devices/common/ata/atapicdrom.h index c67b8a8..563edc5 100644 --- a/devices/common/ata/atapicdrom.h +++ b/devices/common/ata/atapicdrom.h @@ -29,7 +29,7 @@ along with this program. If not, see . #include -class AtapiCdrom : public AtapiBaseDevice, public CdromDrive { +class AtapiCdrom : public CdromDrive, public AtapiBaseDevice { public: AtapiCdrom(std::string name); ~AtapiCdrom() = default; diff --git a/devices/common/scsi/scsicdrom.h b/devices/common/scsi/scsicdrom.h index 766cc72..7dc84f0 100644 --- a/devices/common/scsi/scsicdrom.h +++ b/devices/common/scsi/scsicdrom.h @@ -32,7 +32,7 @@ along with this program. If not, see . #include #include -class ScsiCdrom : public ScsiDevice, public CdromDrive { +class ScsiCdrom : public CdromDrive, public ScsiDevice { public: ScsiCdrom(std::string name, int my_id); ~ScsiCdrom() = default; diff --git a/main.cpp b/main.cpp index 4ac507b..93ba4a2 100644 --- a/main.cpp +++ b/main.cpp @@ -40,12 +40,12 @@ along with this program. If not, see . using namespace std; -void sigint_handler(int signum) { +static void sigint_handler(int signum) { power_on = false; power_off_reason = po_signal_interrupt; } -void sigabrt_handler(int signum) { +static void sigabrt_handler(int signum) { LOG_F(INFO, "Shutting down..."); delete gMachineObj.release();