2020-02-28 09:04:28 -07:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2023-11-23 11:58:00 -08:00
|
|
|
Copyright (C) 2018-24 divingkatae and maximum
|
2020-02-28 09:04:28 -07:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2019-12-28 01:58:51 +01:00
|
|
|
#ifndef PPCEMU_H
|
|
|
|
#define PPCEMU_H
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2021-10-23 20:17:47 +02:00
|
|
|
#include <devices/memctrl/memctrlbase.h>
|
|
|
|
#include <endianswap.h>
|
2023-12-02 15:12:02 -08:00
|
|
|
#include <memaccess.h>
|
2021-10-23 20:17:47 +02:00
|
|
|
|
2024-03-26 19:25:05 -07:00
|
|
|
#include <atomic>
|
2020-01-28 01:24:12 +01:00
|
|
|
#include <cinttypes>
|
2021-08-03 16:01:32 +02:00
|
|
|
#include <functional>
|
2020-01-11 21:48:56 +01:00
|
|
|
#include <setjmp.h>
|
2020-05-12 23:55:45 +05:00
|
|
|
#include <string>
|
2019-08-21 08:33:01 +02:00
|
|
|
|
2020-05-12 23:55:45 +05:00
|
|
|
// Uncomment this to have a more graceful approach to illegal opcodes
|
2019-07-19 14:24:39 -07:00
|
|
|
//#define ILLEGAL_OP_SAFE 1
|
|
|
|
|
2021-04-29 02:26:17 +02:00
|
|
|
//#define CPU_PROFILING // enable CPU profiling
|
|
|
|
|
2023-06-19 22:36:27 -07:00
|
|
|
/** type of compiler used during execution */
|
|
|
|
enum EXEC_MODE:uint32_t {
|
|
|
|
interpreter = 0,
|
|
|
|
debugger = 1,
|
|
|
|
threaded_int = 2,
|
|
|
|
jit = 3
|
|
|
|
};
|
|
|
|
|
2020-01-25 19:30:55 -07:00
|
|
|
enum endian_switch { big_end = 0, little_end = 1 };
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2024-11-28 23:30:01 +01:00
|
|
|
typedef void (*PPCOpcode)(uint32_t opcode);
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2020-01-22 12:42:22 +01:00
|
|
|
union FPR_storage {
|
2020-05-12 23:55:45 +05:00
|
|
|
double dbl64_r; // double floating-point representation
|
|
|
|
uint64_t int64_r; // double integer representation
|
2020-01-21 19:25:50 -07:00
|
|
|
};
|
|
|
|
|
2019-07-01 19:15:33 -07:00
|
|
|
/**
|
|
|
|
Except for the floating-point registers, all registers require
|
|
|
|
32 bits for representation. Floating-point registers need 64 bits.
|
|
|
|
|
|
|
|
gpr = General Purpose Register
|
|
|
|
fpr = Floating Point (FP) Register
|
|
|
|
cr = Condition Register
|
|
|
|
tbr = Time Base Register
|
|
|
|
fpscr = FP Status and Condition Register
|
|
|
|
spr = Special Register
|
|
|
|
msr = Machine State Register
|
|
|
|
sr = Segment Register
|
|
|
|
**/
|
|
|
|
|
|
|
|
typedef struct struct_ppc_state {
|
2020-03-04 21:29:04 -07:00
|
|
|
FPR_storage fpr[32];
|
2020-05-12 23:55:45 +05:00
|
|
|
uint32_t pc; // Referred as the CIA in the PPC manual
|
2020-03-04 21:29:04 -07:00
|
|
|
uint32_t gpr[32];
|
|
|
|
uint32_t cr;
|
|
|
|
uint32_t fpscr;
|
|
|
|
uint32_t tbr[2];
|
|
|
|
uint32_t spr[1024];
|
|
|
|
uint32_t msr;
|
|
|
|
uint32_t sr[16];
|
2020-05-12 23:55:45 +05:00
|
|
|
bool reserve; // reserve bit used for lwarx and stcwx
|
2019-07-01 19:15:33 -07:00
|
|
|
} SetPRS;
|
|
|
|
|
|
|
|
extern SetPRS ppc_state;
|
|
|
|
|
2020-01-28 01:24:12 +01:00
|
|
|
/** symbolic names for frequently used SPRs */
|
|
|
|
enum SPR : int {
|
ppcopcodes: Fixes for SPRs.
- Rename DEC to DEC_S and add DEC_U.
- MQ, RTCL_U, RTCU_U, and DEC_U should cause an illegal instruction program exception for non-MPC601 CPUs. The exception handler of classic Mac OS uses this to emulate the instruction.
- For mtspr, the SPRs RTCL_U, RTCU_U, and DEC_U are treated as no-op on MPC601.
- For debugging, use the supervisor instead of the user SPR number as the index for storing the values for RTC, TB, and DEC.
- For debugging, RTC, TB, and DEC should be updated after each access. Previously, mfspr and mtspr would only update the half of RTC and TB that was being accessed instead of both halves.
2024-04-09 00:57:51 -07:00
|
|
|
MQ = 0, // MQ (601)
|
2022-03-22 12:23:54 +01:00
|
|
|
XER = 1,
|
ppcopcodes: Fixes for SPRs.
- Rename DEC to DEC_S and add DEC_U.
- MQ, RTCL_U, RTCU_U, and DEC_U should cause an illegal instruction program exception for non-MPC601 CPUs. The exception handler of classic Mac OS uses this to emulate the instruction.
- For mtspr, the SPRs RTCL_U, RTCU_U, and DEC_U are treated as no-op on MPC601.
- For debugging, use the supervisor instead of the user SPR number as the index for storing the values for RTC, TB, and DEC.
- For debugging, RTC, TB, and DEC should be updated after each access. Previously, mfspr and mtspr would only update the half of RTC and TB that was being accessed instead of both halves.
2024-04-09 00:57:51 -07:00
|
|
|
RTCU_U = 4, // user mode RTCU (601)
|
|
|
|
RTCL_U = 5, // user mode RTCL (601)
|
|
|
|
DEC_U = 6, // user mode decrementer (601)
|
2022-03-22 12:23:54 +01:00
|
|
|
LR = 8,
|
|
|
|
CTR = 9,
|
|
|
|
DSISR = 18,
|
|
|
|
DAR = 19,
|
ppcopcodes: Fixes for SPRs.
- Rename DEC to DEC_S and add DEC_U.
- MQ, RTCL_U, RTCU_U, and DEC_U should cause an illegal instruction program exception for non-MPC601 CPUs. The exception handler of classic Mac OS uses this to emulate the instruction.
- For mtspr, the SPRs RTCL_U, RTCU_U, and DEC_U are treated as no-op on MPC601.
- For debugging, use the supervisor instead of the user SPR number as the index for storing the values for RTC, TB, and DEC.
- For debugging, RTC, TB, and DEC should be updated after each access. Previously, mfspr and mtspr would only update the half of RTC and TB that was being accessed instead of both halves.
2024-04-09 00:57:51 -07:00
|
|
|
RTCU_S = 20, // supervisor RTCU (601)
|
|
|
|
RTCL_S = 21, // supervisor RTCL (601)
|
|
|
|
DEC_S = 22, // supervisor decrementer
|
2022-03-22 12:23:54 +01:00
|
|
|
SDR1 = 25,
|
|
|
|
SRR0 = 26,
|
|
|
|
SRR1 = 27,
|
|
|
|
TBL_U = 268, // user mode TBL
|
|
|
|
TBU_U = 269, // user mode TBU
|
2023-08-07 11:38:18 -07:00
|
|
|
SPRG0 = 272,
|
|
|
|
SPRG1 = 273,
|
|
|
|
SPRG2 = 274,
|
|
|
|
SPRG3 = 275,
|
2022-03-22 12:23:54 +01:00
|
|
|
TBL_S = 284, // supervisor TBL
|
|
|
|
TBU_S = 285, // supervisor TBU
|
2022-08-15 14:45:55 +02:00
|
|
|
PVR = 287,
|
2023-08-07 11:38:18 -07:00
|
|
|
MMCR0 = 952,
|
|
|
|
PMC1 = 953,
|
|
|
|
PMC2 = 954,
|
|
|
|
SIA = 955,
|
|
|
|
MMCR1 = 956,
|
|
|
|
SDA = 959,
|
2022-08-15 14:45:55 +02:00
|
|
|
HID0 = 1008,
|
|
|
|
HID1 = 1009,
|
2020-01-28 01:24:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** symbolic names for common PPC processors */
|
|
|
|
enum PPC_VER : uint32_t {
|
2022-12-23 16:56:54 +01:00
|
|
|
MPC601 = 0x00010001,
|
|
|
|
MPC603 = 0x00030001,
|
|
|
|
MPC604 = 0x00040001,
|
|
|
|
MPC603E = 0x00060101,
|
|
|
|
MPC603EV = 0x00070101,
|
2023-12-03 20:02:32 +01:00
|
|
|
MPC750 = 0x00080200,
|
|
|
|
MPC604E = 0x00090202,
|
2023-12-17 05:26:26 -08:00
|
|
|
MPC970MP = 0x00440100,
|
2020-01-28 01:24:12 +01:00
|
|
|
};
|
|
|
|
|
2019-07-01 19:15:33 -07:00
|
|
|
/**
|
|
|
|
typedef struct struct_ppc64_state {
|
2020-03-04 21:29:04 -07:00
|
|
|
FPR_storage fpr [32];
|
2020-03-05 07:48:10 -07:00
|
|
|
uint64_t pc; //Referred as the CIA in the PPC manual
|
2020-03-04 21:29:04 -07:00
|
|
|
uint64_t gpr [32];
|
|
|
|
uint32_t cr;
|
|
|
|
uint32_t fpscr;
|
|
|
|
uint32_t tbr [2];
|
|
|
|
uint64_t spr [1024];
|
|
|
|
uint32_t msr;
|
|
|
|
uint32_t sr [16];
|
|
|
|
bool reserve; //reserve bit used for lwarx and stcwx
|
2019-07-01 19:15:33 -07:00
|
|
|
} SetPRS64;
|
|
|
|
|
|
|
|
extern SetPRS64 ppc_state64;
|
|
|
|
**/
|
|
|
|
|
|
|
|
/**
|
|
|
|
Specific SPRS to be weary of:
|
|
|
|
|
|
|
|
USER MODEL
|
|
|
|
SPR 1 - XER
|
|
|
|
SPR 8 - Link Register / Branch
|
|
|
|
b0 - Summary Overflow
|
|
|
|
b1 - Overflow
|
|
|
|
b2 - Carry
|
|
|
|
b25-31 - Number of bytes to transfer
|
|
|
|
SPR 9 - Count
|
|
|
|
|
|
|
|
SUPERVISOR MODEL
|
|
|
|
19 is the Data Address Register
|
|
|
|
22 is the Decrementer
|
|
|
|
26, 27 are the Save and Restore Registers (SRR0, SRR1)
|
|
|
|
272 - 275 are the SPRGs
|
|
|
|
284 - 285 for writing to the TBR's.
|
|
|
|
528 - 535 are the Instruction BAT registers
|
|
|
|
536 - 543 are the Data BAT registers
|
|
|
|
**/
|
|
|
|
|
2021-12-20 00:10:02 +01:00
|
|
|
extern uint64_t timebase_counter;
|
|
|
|
extern uint64_t tbr_wr_timestamp;
|
2023-02-09 01:38:55 +01:00
|
|
|
extern uint64_t dec_wr_timestamp;
|
2022-09-15 20:21:54 -07:00
|
|
|
extern uint64_t rtc_timestamp;
|
2021-12-20 00:10:02 +01:00
|
|
|
extern uint64_t tbr_wr_value;
|
2023-02-09 01:38:55 +01:00
|
|
|
extern uint32_t dec_wr_value;
|
2022-09-15 21:22:37 -07:00
|
|
|
extern uint32_t tbr_freq_ghz;
|
2023-08-07 11:11:02 -07:00
|
|
|
extern uint64_t tbr_period_ns;
|
2022-03-22 12:23:54 +01:00
|
|
|
extern uint32_t rtc_lo, rtc_hi;
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2022-03-02 16:55:20 +01:00
|
|
|
/* Flags for controlling interpreter execution. */
|
|
|
|
enum {
|
|
|
|
EXEF_BRANCH = 1 << 0,
|
|
|
|
EXEF_EXCEPTION = 1 << 1,
|
|
|
|
EXEF_RFI = 1 << 2,
|
2020-01-03 21:01:02 +01:00
|
|
|
};
|
|
|
|
|
2021-10-10 07:48:49 -07:00
|
|
|
enum CR_select : int32_t {
|
2021-10-09 15:08:53 -07:00
|
|
|
CR0_field = (0xF << 28),
|
2021-10-09 19:42:25 -07:00
|
|
|
CR1_field = (0xF << 24),
|
2021-10-09 15:08:53 -07:00
|
|
|
};
|
|
|
|
|
2023-12-19 14:26:51 +01:00
|
|
|
// Define bit masks for CR0.
|
|
|
|
// To use them in other CR fields, just right shift it by 4*CR_num bits.
|
2021-12-20 00:10:02 +01:00
|
|
|
enum CRx_bit : uint32_t {
|
2023-12-19 14:26:51 +01:00
|
|
|
CR_SO = 1UL << 28,
|
|
|
|
CR_EQ = 1UL << 29,
|
|
|
|
CR_GT = 1UL << 30,
|
|
|
|
CR_LT = 1UL << 31
|
|
|
|
};
|
2021-10-09 15:08:53 -07:00
|
|
|
|
2021-10-10 07:48:49 -07:00
|
|
|
enum CR1_bit : uint32_t {
|
2021-10-23 20:17:47 +02:00
|
|
|
CR1_OX = 24,
|
2021-10-09 15:08:53 -07:00
|
|
|
CR1_VX,
|
|
|
|
CR1_FEX,
|
|
|
|
CR1_FX,
|
|
|
|
};
|
|
|
|
|
2021-10-10 07:48:49 -07:00
|
|
|
enum FPSCR : uint32_t {
|
2023-11-30 11:47:07 +01:00
|
|
|
RN_MASK = 0x3,
|
|
|
|
NI = 1UL << 2,
|
|
|
|
XE = 1UL << 3,
|
|
|
|
ZE = 1UL << 4,
|
|
|
|
UE = 1UL << 5,
|
|
|
|
OE = 1UL << 6,
|
|
|
|
VE = 1UL << 7,
|
|
|
|
VXCVI = 1UL << 8,
|
|
|
|
VXSQRT = 1UL << 9,
|
|
|
|
VXSOFT = 1UL << 10,
|
|
|
|
FPCC_FUNAN = 1UL << 12,
|
|
|
|
FPCC_ZERO = 1UL << 13,
|
|
|
|
FPCC_POS = 1UL << 14,
|
|
|
|
FPCC_NEG = 1UL << 15,
|
2023-12-19 11:58:12 +01:00
|
|
|
FPCC_MASK = FPCC_NEG | FPCC_POS | FPCC_ZERO | FPCC_FUNAN,
|
|
|
|
FPRCD = 1UL << 16,
|
|
|
|
FPRF_MASK = FPRCD | FPCC_MASK,
|
2023-11-30 11:47:07 +01:00
|
|
|
FI = 1UL << 17,
|
|
|
|
FR = 1UL << 18,
|
|
|
|
VXVC = 1UL << 19,
|
|
|
|
VXIMZ = 1UL << 20,
|
|
|
|
VXZDZ = 1UL << 21,
|
|
|
|
VXIDI = 1UL << 22,
|
|
|
|
VXISI = 1UL << 23,
|
|
|
|
VXSNAN = 1UL << 24,
|
|
|
|
XX = 1UL << 25,
|
|
|
|
ZX = 1UL << 26,
|
|
|
|
UX = 1UL << 27,
|
|
|
|
OX = 1UL << 28,
|
|
|
|
VX = 1UL << 29,
|
|
|
|
FEX = 1UL << 30,
|
|
|
|
FX = 1UL << 31
|
2021-10-09 15:08:53 -07:00
|
|
|
};
|
|
|
|
|
2023-11-21 08:06:50 -07:00
|
|
|
enum MSR : int {
|
|
|
|
LE = 0x1, //little endian mode
|
|
|
|
RI = 0x2,
|
|
|
|
DR = 0x10,
|
|
|
|
IR = 0x20,
|
|
|
|
IP = 0x40,
|
|
|
|
FE1 = 0x100,
|
|
|
|
BE = 0x200,
|
|
|
|
SE = 0x400,
|
|
|
|
FE0 = 0x800,
|
|
|
|
ME = 0x1000,
|
|
|
|
FP = 0x2000,
|
|
|
|
PR = 0x4000,
|
|
|
|
EE = 0x8000, //external interrupt
|
|
|
|
ILE = 0x10000,
|
|
|
|
POW = 0x40000
|
|
|
|
};
|
|
|
|
|
2023-12-19 14:47:14 +01:00
|
|
|
enum XER : uint32_t {
|
|
|
|
CA = 1UL << 29,
|
|
|
|
OV = 1UL << 30,
|
|
|
|
SO = 1UL << 31
|
|
|
|
};
|
|
|
|
|
2021-10-09 15:08:53 -07:00
|
|
|
//for inf and nan checks
|
|
|
|
enum FPOP : int {
|
2023-11-19 17:56:30 -07:00
|
|
|
DIV = 0x12,
|
|
|
|
SUB = 0x14,
|
|
|
|
ADD = 0x15,
|
|
|
|
SQRT = 0x16,
|
2024-01-05 15:11:37 -07:00
|
|
|
MUL = 0x19
|
2021-10-09 15:08:53 -07:00
|
|
|
};
|
|
|
|
|
2020-01-11 21:48:56 +01:00
|
|
|
/** PowerPC exception types. */
|
|
|
|
enum class Except_Type {
|
|
|
|
EXC_SYSTEM_RESET = 1,
|
|
|
|
EXC_MACHINE_CHECK,
|
|
|
|
EXC_DSI,
|
|
|
|
EXC_ISI,
|
|
|
|
EXC_EXT_INT,
|
|
|
|
EXC_ALIGNMENT,
|
|
|
|
EXC_PROGRAM,
|
|
|
|
EXC_NO_FPU,
|
|
|
|
EXC_DECR,
|
|
|
|
EXC_SYSCALL = 12,
|
2020-05-12 23:55:45 +05:00
|
|
|
EXC_TRACE = 13
|
2020-01-11 21:48:56 +01:00
|
|
|
};
|
|
|
|
|
2023-12-02 15:12:02 -08:00
|
|
|
/** Program Exception subclasses. */
|
2020-11-30 20:59:36 +01:00
|
|
|
enum Exc_Cause : uint32_t {
|
|
|
|
FPU_OFF = 1 << (31 - 11),
|
|
|
|
ILLEGAL_OP = 1 << (31 - 12),
|
|
|
|
NOT_ALLOWED = 1 << (31 - 13),
|
|
|
|
TRAP = 1 << (31 - 14),
|
|
|
|
};
|
|
|
|
|
2022-03-02 16:55:20 +01:00
|
|
|
extern unsigned exec_flags;
|
2020-01-11 21:48:56 +01:00
|
|
|
|
|
|
|
extern jmp_buf exc_env;
|
2020-01-03 21:01:02 +01:00
|
|
|
|
2023-11-21 16:57:28 -08:00
|
|
|
enum Po_Cause : int {
|
|
|
|
po_none,
|
|
|
|
po_starting_up,
|
2024-05-05 23:40:32 -07:00
|
|
|
po_quit,
|
|
|
|
po_quitting,
|
2023-11-21 16:57:28 -08:00
|
|
|
po_shut_down,
|
|
|
|
po_shutting_down,
|
2024-03-07 23:30:55 -08:00
|
|
|
po_restart,
|
2024-05-05 23:40:32 -07:00
|
|
|
po_restarting,
|
2023-11-21 16:57:28 -08:00
|
|
|
po_disassemble_on,
|
|
|
|
po_disassemble_off,
|
|
|
|
po_enter_debugger,
|
|
|
|
po_entered_debugger,
|
|
|
|
po_signal_interrupt,
|
|
|
|
};
|
|
|
|
|
2019-12-28 02:49:58 +01:00
|
|
|
extern bool power_on;
|
2023-11-21 16:57:28 -08:00
|
|
|
extern Po_Cause power_off_reason;
|
2022-08-24 12:51:43 +02:00
|
|
|
extern bool int_pin;
|
2023-08-07 11:11:02 -07:00
|
|
|
extern bool dec_exception_pending;
|
2019-12-28 02:49:58 +01:00
|
|
|
|
2020-05-12 23:55:45 +05:00
|
|
|
extern bool is_601; // For PowerPC 601 Emulation
|
2024-11-27 03:24:52 -08:00
|
|
|
extern bool include_601; // For non-PowerPC 601 emulation with 601 extras (matches Mac OS 9 environment which can emulate MPC 601 instructions)
|
2020-05-12 23:55:45 +05:00
|
|
|
extern bool is_altivec; // For Altivec Emulation
|
|
|
|
extern bool is_64bit; // For PowerPC G5 Emulation
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2024-11-09 22:25:48 -08:00
|
|
|
// Make execution deterministic (ignore external input, used a fixed date, etc.)
|
|
|
|
extern bool is_deterministic;
|
|
|
|
|
2020-05-12 23:55:45 +05:00
|
|
|
// Important Addressing Integers
|
2019-07-01 19:15:33 -07:00
|
|
|
extern uint32_t ppc_next_instruction_address;
|
|
|
|
|
2024-11-28 23:30:01 +01:00
|
|
|
inline uint32_t ppc_read_instruction(const uint8_t* ptr) {
|
|
|
|
return READ_DWORD_BE_A(ptr);
|
2023-12-02 15:12:02 -08:00
|
|
|
}
|
|
|
|
|
2020-05-12 23:55:45 +05:00
|
|
|
// Profiling Stats
|
2021-04-29 02:26:17 +02:00
|
|
|
#ifdef CPU_PROFILING
|
|
|
|
extern uint64_t num_executed_instrs;
|
|
|
|
extern uint64_t num_supervisor_instrs;
|
|
|
|
extern uint64_t num_int_loads;
|
|
|
|
extern uint64_t num_int_stores;
|
|
|
|
extern uint64_t exceptions_processed;
|
|
|
|
#endif
|
2020-01-11 18:43:47 -07:00
|
|
|
|
2024-03-26 01:14:23 -07:00
|
|
|
// instruction enums
|
|
|
|
typedef enum {
|
2024-03-26 18:51:42 -07:00
|
|
|
ppc_and = 1,
|
|
|
|
ppc_andc = 2,
|
|
|
|
ppc_eqv = 3,
|
|
|
|
ppc_nand = 4,
|
|
|
|
ppc_nor = 5,
|
|
|
|
ppc_or = 6,
|
|
|
|
ppc_orc = 7,
|
|
|
|
ppc_xor = 8,
|
|
|
|
} logical_fun;
|
2024-03-26 01:14:23 -07:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LK0,
|
|
|
|
LK1,
|
|
|
|
} field_lk;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
AA0,
|
|
|
|
AA1,
|
|
|
|
} field_aa;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
SHFT0,
|
|
|
|
SHFT1,
|
|
|
|
} field_shift;
|
|
|
|
|
2024-03-26 18:53:11 -07:00
|
|
|
typedef enum {
|
|
|
|
RIGHT0,
|
|
|
|
LEFT1,
|
|
|
|
} field_direction;
|
|
|
|
|
2024-03-26 01:14:23 -07:00
|
|
|
typedef enum {
|
|
|
|
RC0,
|
|
|
|
RC1,
|
|
|
|
} field_rc;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
OV0,
|
|
|
|
OV1,
|
|
|
|
} field_ov;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
CARRY0,
|
|
|
|
CARRY1,
|
|
|
|
} field_carry;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
NOT601,
|
|
|
|
IS601,
|
|
|
|
} field_601;
|
|
|
|
|
2024-11-29 18:17:24 +01:00
|
|
|
// Placeholder value for cases where we don't have a currently-executing instruction.
|
|
|
|
constexpr uint32_t NO_OPCODE = 0;
|
|
|
|
|
2020-05-12 23:55:45 +05:00
|
|
|
// Function prototypes
|
2024-04-08 21:18:45 -07:00
|
|
|
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq);
|
2023-09-18 20:43:53 +02:00
|
|
|
extern void ppc_mmu_init();
|
2020-01-28 01:24:12 +01:00
|
|
|
|
2024-11-28 23:30:01 +01:00
|
|
|
void ppc_illegalop(uint32_t opcode);
|
2022-08-24 12:51:43 +02:00
|
|
|
void ppc_assert_int();
|
|
|
|
void ppc_release_int();
|
2020-10-17 14:30:37 -07:00
|
|
|
|
2024-11-30 18:54:20 +01:00
|
|
|
void initialize_ppc_opcode_table();
|
2020-10-17 14:30:37 -07:00
|
|
|
|
2019-07-01 19:15:33 -07:00
|
|
|
void ppc_changecrf0(uint32_t set_result);
|
2023-11-30 12:00:50 +01:00
|
|
|
void set_host_rounding_mode(uint8_t mode);
|
|
|
|
void update_fpscr(uint32_t new_fpscr);
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2020-02-23 16:41:44 +01:00
|
|
|
/* Exception handlers. */
|
2022-01-10 17:27:27 +01:00
|
|
|
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
2020-05-12 23:55:45 +05:00
|
|
|
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
2024-11-28 23:30:01 +01:00
|
|
|
void ppc_floating_point_exception(uint32_t opcode);
|
|
|
|
void ppc_alignment_exception(uint32_t opcode, uint32_t ea);
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2020-05-12 23:55:45 +05:00
|
|
|
// MEMORY DECLARATIONS
|
2020-01-25 19:30:55 -07:00
|
|
|
extern MemCtrlBase* mem_ctrl_instance;
|
2019-08-21 08:33:01 +02:00
|
|
|
|
2021-08-03 16:01:32 +02:00
|
|
|
extern void add_ctx_sync_action(const std::function<void()> &);
|
2021-10-13 20:58:09 +02:00
|
|
|
extern void do_ctx_sync(void);
|
2021-08-03 16:01:32 +02:00
|
|
|
|
2020-05-12 23:55:45 +05:00
|
|
|
// The functions used by the PowerPC processor
|
2024-03-24 12:21:19 -07:00
|
|
|
|
2020-10-17 21:46:38 -07:00
|
|
|
namespace dppc_interpreter {
|
2024-11-28 23:30:01 +01:00
|
|
|
template <field_lk l, field_601 for601> extern void ppc_bcctr(uint32_t opcode);
|
|
|
|
template <field_lk l> extern void ppc_bclr(uint32_t opcode);
|
|
|
|
extern void ppc_crand(uint32_t opcode);
|
|
|
|
extern void ppc_crandc(uint32_t opcode);
|
|
|
|
extern void ppc_creqv(uint32_t opcode);
|
|
|
|
extern void ppc_crnand(uint32_t opcode);
|
|
|
|
extern void ppc_crnor(uint32_t opcode);
|
|
|
|
extern void ppc_cror(uint32_t opcode);
|
|
|
|
extern void ppc_crorc(uint32_t opcode);
|
|
|
|
extern void ppc_crxor(uint32_t opcode);
|
|
|
|
extern void ppc_isync(uint32_t opcode);
|
|
|
|
|
|
|
|
template <logical_fun logical_op, field_rc rec> extern void ppc_logical(uint32_t opcode);
|
|
|
|
|
|
|
|
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_add(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void ppc_adde(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void ppc_addme(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void ppc_addze(uint32_t opcode);
|
|
|
|
extern void ppc_cmp(uint32_t opcode);
|
|
|
|
extern void ppc_cmpl(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_cntlzw(uint32_t opcode);
|
|
|
|
extern void ppc_dcbf(uint32_t opcode);
|
|
|
|
extern void ppc_dcbi(uint32_t opcode);
|
|
|
|
extern void ppc_dcbst(uint32_t opcode);
|
|
|
|
extern void ppc_dcbt(uint32_t opcode);
|
|
|
|
extern void ppc_dcbtst(uint32_t opcode);
|
|
|
|
extern void ppc_dcbz(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void ppc_divw(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void ppc_divwu(uint32_t opcode);
|
|
|
|
extern void ppc_eciwx(uint32_t opcode);
|
|
|
|
extern void ppc_ecowx(uint32_t opcode);
|
|
|
|
extern void ppc_eieio(uint32_t opcode);
|
|
|
|
template <class T, field_rc rec>extern void ppc_exts(uint32_t opcode);
|
|
|
|
extern void ppc_icbi(uint32_t opcode);
|
|
|
|
extern void ppc_mftb(uint32_t opcode);
|
|
|
|
extern void ppc_lhaux(uint32_t opcode);
|
|
|
|
extern void ppc_lhax(uint32_t opcode);
|
|
|
|
extern void ppc_lhbrx(uint32_t opcode);
|
|
|
|
extern void ppc_lwarx(uint32_t opcode);
|
|
|
|
extern void ppc_lwbrx(uint32_t opcode);
|
|
|
|
template <class T> extern void ppc_lzx(uint32_t opcode);
|
|
|
|
template <class T> extern void ppc_lzux(uint32_t opcode);
|
|
|
|
extern void ppc_mcrxr(uint32_t opcode);
|
|
|
|
extern void ppc_mfcr(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_mulhwu(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_mulhw(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void ppc_mullw(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void ppc_neg(uint32_t opcode);
|
|
|
|
template <field_direction shift, field_rc rec> extern void ppc_shift(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_sraw(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_srawi(uint32_t opcode);
|
|
|
|
template <class T> extern void ppc_stx(uint32_t opcode);
|
|
|
|
template <class T> extern void ppc_stux(uint32_t opcode);
|
|
|
|
extern void ppc_stfiwx(uint32_t opcode);
|
|
|
|
extern void ppc_sthbrx(uint32_t opcode);
|
|
|
|
extern void ppc_stwcx(uint32_t opcode);
|
|
|
|
extern void ppc_stwbrx(uint32_t opcode);
|
|
|
|
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_subf(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void ppc_subfe(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void ppc_subfme(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void ppc_subfze(uint32_t opcode);
|
|
|
|
extern void ppc_sync(uint32_t opcode);
|
|
|
|
extern void ppc_tlbia(uint32_t opcode);
|
|
|
|
extern void ppc_tlbie(uint32_t opcode);
|
|
|
|
extern void ppc_tlbli(uint32_t opcode);
|
|
|
|
extern void ppc_tlbld(uint32_t opcode);
|
|
|
|
extern void ppc_tlbsync(uint32_t opcode);
|
|
|
|
extern void ppc_tw(uint32_t opcode);
|
|
|
|
|
|
|
|
extern void ppc_lswi(uint32_t opcode);
|
|
|
|
extern void ppc_lswx(uint32_t opcode);
|
|
|
|
extern void ppc_stswi(uint32_t opcode);
|
|
|
|
extern void ppc_stswx(uint32_t opcode);
|
|
|
|
|
|
|
|
extern void ppc_mfsr(uint32_t opcode);
|
|
|
|
extern void ppc_mfsrin(uint32_t opcode);
|
|
|
|
extern void ppc_mtsr(uint32_t opcode);
|
|
|
|
extern void ppc_mtsrin(uint32_t opcode);
|
|
|
|
|
|
|
|
extern void ppc_mcrf(uint32_t opcode);
|
|
|
|
extern void ppc_mtcrf(uint32_t opcode);
|
|
|
|
extern void ppc_mfmsr(uint32_t opcode);
|
|
|
|
extern void ppc_mfspr(uint32_t opcode);
|
|
|
|
extern void ppc_mtmsr(uint32_t opcode);
|
|
|
|
extern void ppc_mtspr(uint32_t opcode);
|
|
|
|
|
|
|
|
template <field_rc rec> extern void ppc_mtfsb0(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_mtfsb1(uint32_t opcode);
|
|
|
|
extern void ppc_mcrfs(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fmr(uint32_t opcode);
|
|
|
|
template <field_601 for601, field_rc rec> extern void ppc_mffs(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_mtfsf(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_mtfsfi(uint32_t opcode);
|
|
|
|
|
|
|
|
template <field_shift shift> extern void ppc_addi(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_addic(uint32_t opcode);
|
|
|
|
template <field_shift shift> extern void ppc_andirc(uint32_t opcode);
|
|
|
|
template <field_lk l, field_aa a> extern void ppc_b(uint32_t opcode);
|
|
|
|
template <field_lk l, field_aa a> extern void ppc_bc(uint32_t opcode);
|
|
|
|
extern void ppc_cmpi(uint32_t opcode);
|
|
|
|
extern void ppc_cmpli(uint32_t opcode);
|
|
|
|
template <class T> extern void ppc_lz(uint32_t opcode);
|
|
|
|
template <class T> extern void ppc_lzu(uint32_t opcode);
|
|
|
|
extern void ppc_lha(uint32_t opcode);
|
|
|
|
extern void ppc_lhau(uint32_t opcode);
|
|
|
|
extern void ppc_lmw(uint32_t opcode);
|
|
|
|
extern void ppc_mulli(uint32_t opcode);
|
|
|
|
template <field_shift shift> extern void ppc_ori(uint32_t opcode);
|
|
|
|
extern void ppc_rfi(uint32_t opcode);
|
|
|
|
extern void ppc_rlwimi(uint32_t opcode);
|
|
|
|
extern void ppc_rlwinm(uint32_t opcode);
|
|
|
|
extern void ppc_rlwnm(uint32_t opcode);
|
|
|
|
extern void ppc_sc(uint32_t opcode);
|
|
|
|
template <class T> extern void ppc_st(uint32_t opcode);
|
|
|
|
template <class T> extern void ppc_stu(uint32_t opcode);
|
|
|
|
extern void ppc_stmw(uint32_t opcode);
|
|
|
|
extern void ppc_subfic(uint32_t opcode);
|
|
|
|
extern void ppc_twi(uint32_t opcode);
|
|
|
|
template <field_shift shift> extern void ppc_xori(uint32_t opcode);
|
|
|
|
|
|
|
|
extern void ppc_lfs(uint32_t opcode);
|
|
|
|
extern void ppc_lfsu(uint32_t opcode);
|
|
|
|
extern void ppc_lfsx(uint32_t opcode);
|
|
|
|
extern void ppc_lfsux(uint32_t opcode);
|
|
|
|
extern void ppc_lfd(uint32_t opcode);
|
|
|
|
extern void ppc_lfdu(uint32_t opcode);
|
|
|
|
extern void ppc_lfdx(uint32_t opcode);
|
|
|
|
extern void ppc_lfdux(uint32_t opcode);
|
|
|
|
extern void ppc_stfs(uint32_t opcode);
|
|
|
|
extern void ppc_stfsu(uint32_t opcode);
|
|
|
|
extern void ppc_stfsx(uint32_t opcode);
|
|
|
|
extern void ppc_stfsux(uint32_t opcode);
|
|
|
|
extern void ppc_stfd(uint32_t opcode);
|
|
|
|
extern void ppc_stfdu(uint32_t opcode);
|
|
|
|
extern void ppc_stfdx(uint32_t opcode);
|
|
|
|
extern void ppc_stfdux(uint32_t opcode);
|
|
|
|
|
|
|
|
template <field_rc rec> extern void ppc_fadd(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fsub(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fmul(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fdiv(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fadds(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fsubs(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fmuls(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fdivs(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fmadd(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fmsub(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fnmadd(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fnmsub(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fmadds(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fmsubs(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fnmadds(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fnmsubs(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fabs(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fnabs(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fneg(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fsel(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fres(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fsqrts(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fsqrt(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_frsqrte(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_frsp(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fctiw(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void ppc_fctiwz(uint32_t opcode);
|
|
|
|
|
|
|
|
extern void ppc_fcmpo(uint32_t opcode);
|
|
|
|
extern void ppc_fcmpu(uint32_t opcode);
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2020-05-12 23:55:45 +05:00
|
|
|
// Power-specific instructions
|
2024-11-28 23:30:01 +01:00
|
|
|
template <field_rc rec, field_ov ov> extern void power_abs(uint32_t opcode);
|
|
|
|
extern void power_clcs(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void power_div(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void power_divs(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void power_doz(uint32_t opcode);
|
|
|
|
extern void power_dozi(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_lscbx(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_maskg(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_maskir(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void power_mul(uint32_t opcode);
|
|
|
|
template <field_rc rec, field_ov ov> extern void power_nabs(uint32_t opcode);
|
|
|
|
extern void power_rlmi(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_rrib(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_sle(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_sleq(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_sliq(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_slliq(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_sllq(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_slq(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_sraiq(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_sraq(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_sre(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_srea(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_sreq(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_sriq(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_srliq(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_srlq(uint32_t opcode);
|
|
|
|
template <field_rc rec> extern void power_srq(uint32_t opcode);
|
2020-10-17 21:46:38 -07:00
|
|
|
} // namespace dppc_interpreter
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2020-05-12 23:55:45 +05:00
|
|
|
// AltiVec instructions
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2020-05-12 23:55:45 +05:00
|
|
|
// 64-bit instructions
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2020-05-12 23:55:45 +05:00
|
|
|
// G5+ instructions
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2021-12-20 00:10:02 +01:00
|
|
|
extern uint64_t get_virt_time_ns(void);
|
|
|
|
|
2024-11-28 23:30:01 +01:00
|
|
|
extern void ppc_main_opcode(uint32_t opcode);
|
2019-12-28 02:49:58 +01:00
|
|
|
extern void ppc_exec(void);
|
|
|
|
extern void ppc_exec_single(void);
|
|
|
|
extern void ppc_exec_until(uint32_t goal_addr);
|
2020-07-16 14:26:34 +02:00
|
|
|
extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size);
|
2019-07-01 19:15:33 -07:00
|
|
|
|
2020-02-23 15:24:49 +01:00
|
|
|
/* debugging support API */
|
2020-05-12 23:55:45 +05:00
|
|
|
void print_fprs(void); /* print content of the floating-point registers */
|
2022-02-23 17:06:20 +01:00
|
|
|
uint64_t get_reg(std::string reg_name); /* get content of the register reg_name */
|
|
|
|
void set_reg(std::string reg_name, uint64_t val); /* set reg_name to val */
|
2020-02-23 15:24:49 +01:00
|
|
|
|
2020-01-26 20:37:15 +01:00
|
|
|
#endif /* PPCEMU_H */
|