mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cc1ac5731 | ||
|
|
68b8da2182 | ||
|
|
18a19cd52f | ||
|
|
282940e580 | ||
|
|
dbbaf13a78 | ||
|
|
99641b1b5e | ||
|
|
5cba9c1dae | ||
|
|
180cb0d25f | ||
|
|
df39a59190 | ||
|
|
f0315e98ee | ||
|
|
6c6247b94f | ||
|
|
f61277e46d | ||
|
|
da3a6c71fd | ||
|
|
acfa09af65 | ||
|
|
54fcfca8e9 | ||
|
|
a775007d3a | ||
|
|
2be8e7b542 | ||
|
|
0e83ffe435 | ||
|
|
0c202b0c2d | ||
|
|
7be6cb30ac | ||
|
|
f417df0630 | ||
|
|
353035e9ca | ||
|
|
660d227ac7 | ||
|
|
b9dcfef551 | ||
|
|
6b74e358dc |
No files matched your search
@@ -1,3 +1,7 @@
|
||||
[submodule "thirdparty/cubeb"]
|
||||
path = thirdparty/cubeb
|
||||
url = https://github.com/DingusDevOrg/cubeb.git
|
||||
[submodule "thirdparty/capstone"]
|
||||
path = thirdparty/capstone
|
||||
url = https://github.com/maximumspatium/capstone.git
|
||||
branch = next
|
||||
+48
-1
@@ -16,6 +16,41 @@ if (UNIX AND NOT APPLE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(ENABLE_68K_DEBUGGER "Enable 68k debugging" OFF)
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
# Build capstone as static library.
|
||||
set(CAPSTONE_BUILD_STATIC ON CACHE BOOL "")
|
||||
|
||||
# Turn off anything unnecessary.
|
||||
set(CAPSTONE_BUILD_SHARED OFF CACHE BOOL "")
|
||||
set(CAPSTONE_BUILD_TESTS OFF CACHE BOOL "")
|
||||
set(CAPSTONE_BUILD_CSTOOL OFF CACHE BOOL "")
|
||||
set(CAPSTONE_BUILD_DIET OFF CACHE BOOL "")
|
||||
set(CAPSTONE_OSXKERNEL_SUPPORT OFF CACHE BOOL "")
|
||||
|
||||
# Disable unused Capstone architectures.
|
||||
set(CAPSTONE_ARM_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_ARM64_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_MIPS_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_PPC_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_SPARC_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_SYSZ_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_XCORE_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_X86_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_TMS320C64X_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_M680X_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_EVM_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_MOS65XX_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_WASM_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_BPF_SUPPORT OFF CACHE BOOL "")
|
||||
set(CAPSTONE_RISCV_SUPPORT OFF CACHE BOOL "")
|
||||
|
||||
ADD_DEFINITIONS(-DENABLE_68K_DEBUGGER)
|
||||
|
||||
add_subdirectory(thirdparty/capstone EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/cpu/ppc/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/debugger/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/devices/")
|
||||
@@ -72,6 +107,10 @@ target_link_libraries(dingusppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE
|
||||
target_include_directories(dingusppc PRIVATE ${CLI11_ROOT})
|
||||
endif()
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
target_link_libraries(dingusppc capstone-static)
|
||||
endif()
|
||||
|
||||
|
||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
@@ -89,6 +128,10 @@ else()
|
||||
target_link_libraries(testppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
target_link_libraries(testppc capstone-static)
|
||||
endif()
|
||||
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
|
||||
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
@@ -99,6 +142,10 @@ add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
|
||||
target_link_libraries(bench1 cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
target_link_libraries(bench1 capstone-static)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
TARGET testppc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
@@ -106,4 +153,4 @@ add_custom_command(
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcdisasmtest.csv"
|
||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
|
||||
|
||||
install (TARGETS dingusppc DESTINATION ${EXECUTABLE_OUTPUT_PATH})
|
||||
install (TARGETS dingusppc DESTINATION ${PROJECT_SOURCE_DIR}/build)
|
||||
@@ -44,17 +44,17 @@ Specifies the Boot ROM path (optional; looks for bootrom.bin by default)
|
||||
|
||||
Specify machine ID (optional; will attempt to determine machine ID from the boot rom otherwise)
|
||||
|
||||
As of now, only the Beige G3 is implemented.
|
||||
As of now, only the Power Macintosh G3 Beige is implemented.
|
||||
|
||||
## How to Compile
|
||||
|
||||
You need to install development tools first.
|
||||
|
||||
At least, a C++ compiler and [CMake](https://cmake.org) are required.
|
||||
At least, a C++11 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
|
||||
You will also have to recursive clone or run
|
||||
```
|
||||
git submodules --update
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
This is because the CubeB module is not included by default. All other components are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
@@ -71,6 +71,11 @@ You may specify another build type using the variable CMAKE_BUILD_TYPE.
|
||||
|
||||
Future versions may drop SDL 2 as a requirement.
|
||||
|
||||
For Raspbian, you may also need the following command:
|
||||
```
|
||||
sudo apt install doxygen graphviz
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
DingusPPC includes a test suite for verifying the correctness of its PowerPC CPU
|
||||
|
||||
+9
-41
@@ -3,8 +3,6 @@
|
||||
#include "cpu/ppc/ppcemu.h"
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "devices/mpc106.h"
|
||||
#include "jittables.h"
|
||||
#include "nuinterpreter.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
uint32_t cs_code[] = {
|
||||
@@ -19,14 +17,6 @@ uint32_t cs_code[] = {
|
||||
0x7C650194, 0x4E800020
|
||||
};
|
||||
|
||||
/* set up vCPU registers for benchmark code execution */
|
||||
void setup_regs() {
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = 0x8000; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int i;
|
||||
@@ -48,8 +38,6 @@ int main(int argc, char** argv) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
init_jit_tables();
|
||||
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750);
|
||||
|
||||
/* load executable code into RAM at address 0 */
|
||||
@@ -63,22 +51,16 @@ int main(int argc, char** argv) {
|
||||
mem_write_byte(0x1000+i, rand() % 256);
|
||||
}
|
||||
|
||||
setup_regs();
|
||||
/* prepare benchmark code execution */
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = 0x8000; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
|
||||
ppc_exec_until(0xC4);
|
||||
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
|
||||
LOG_F(INFO, "\nRunning with the NuInterpreter");
|
||||
|
||||
setup_regs();
|
||||
|
||||
NuInterpExec(0);
|
||||
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
|
||||
LOG_F(INFO, "\nBenchmarking the old Interpreter:");
|
||||
|
||||
// run the clock once for cache fill etc.
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
@@ -86,7 +68,10 @@ int main(int argc, char** argv) {
|
||||
LOG_F(INFO, "Time elapsed (dry run): %lld ns", time_elapsed.count());
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
setup_regs();
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = 0x8000; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
@@ -100,23 +85,6 @@ int main(int argc, char** argv) {
|
||||
LOG_F(INFO, "Time elapsed (run #%d): %lld ns", i, time_elapsed.count());
|
||||
}
|
||||
|
||||
LOG_F(INFO, "\nBenchmarking the NuInterpreter:");
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
setup_regs();
|
||||
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
NuInterpExec(0);
|
||||
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
LOG_F(INFO, "Time elapsed (run #%d): %lld ns", i, time_elapsed.count());
|
||||
}
|
||||
|
||||
delete(grackle_obj);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,420 +0,0 @@
|
||||
#include <cinttypes>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
#include "ppcdefs.h"
|
||||
#include "jittables.h"
|
||||
#include "nuinterpreter.h"
|
||||
|
||||
#if defined(USE_DTC)
|
||||
|
||||
#define CAST(name) &&lab_##name
|
||||
|
||||
struct InterpInstr {
|
||||
void* emu_fn;
|
||||
InstrInfo info;
|
||||
};
|
||||
|
||||
#define REG_D(opcode) ((opcode >> 21) & 0x1F)
|
||||
#define REG_A(opcode) ((opcode >> 16) & 0x1F)
|
||||
#define REG_B(opcode) ((opcode >> 11) & 0x1F)
|
||||
#define REG_S REG_D
|
||||
#define BR_BO REG_D
|
||||
#define BR_BI REG_A
|
||||
#define SIMM(opcode) ((int32_t)((int16_t)(opcode & 0xFFFF)))
|
||||
#define UIMM(opcode) ((uint32_t)((uint16_t)(opcode & 0xFFFF)))
|
||||
#define REG_TO(opcode) ((opcode >> 21) & 0x1F)
|
||||
#define REG_CRFD(opcode) (((opcode >> 23) & 7) << 2)
|
||||
#define REG_CRFS(opcode) (((opcode >> 18) & 7) << 2)
|
||||
#define REG_SR(opcode) (opcode >> 16) & 15
|
||||
#define LI(opcode) (opcode >> 2) & 0xFFFFFF
|
||||
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
static inline uint32_t rot_mask(unsigned rot_mb, unsigned rot_me) {
|
||||
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
|
||||
uint32_t m2 = 0xFFFFFFFFUL << (31 - rot_me);
|
||||
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
||||
}
|
||||
|
||||
CachedInstr code_block[256];
|
||||
|
||||
void NuInterpExec(uint32_t next_pc) {
|
||||
/* WARNING: entries in this table MUST be in the same order as constants in PPCInstr! */
|
||||
InterpInstr interp_tab[] = {
|
||||
{nullptr, {InstrOps::opNone, CFlowType::CFL_NONE, 0}},
|
||||
{CAST(addi), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(adde), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addze), {InstrOps::opDA, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(andidot), {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lwz), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lwzu), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lbz), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lhz), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(rlwinm), {InstrOps::opRot, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(srawidot), {InstrOps::opSASh, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(bc), {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{CAST(bdnz), {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{CAST(bdz), {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{CAST(bclr), {InstrOps::opBrLink, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{CAST(mtspr), {InstrOps::opSSpr, CFlowType::CFL_NONE, 2}},
|
||||
{CAST(bexit), {InstrOps::opNone, CFlowType::CFL_UNCOND_BRANCH, 0}},
|
||||
{CAST(twi), {InstrOps::opTOASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(mulli), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(cmpli), {InstrOps::opCrfDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(cmpi), {InstrOps::opCrfDAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addic), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addicdot), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(sc), {InstrOps::opNone, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(rlwimix), {InstrOps::opRot, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(rlwnmx), {InstrOps::opRot, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(ori), {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(oris), {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(xori), {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(xoris), {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(andisdot), {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lbzu), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stw), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stwu), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stb), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stbu), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lhzu), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lha), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lhau), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(sth), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(sthu), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lmw), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stmw), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lfs), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lfsu), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lfd), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lfdu), {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stfs), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stfsu), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stfd), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stfdu), {InstrOps::opSASimm, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(bcl), {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{CAST(bca), {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{CAST(bcla), {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{CAST(b), {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{CAST(bl), {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{CAST(ba), {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{CAST(bla), {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{CAST(crnor), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(rfi), {InstrOps::opNone, CFlowType::CFL_COND_BRANCH, 1}},
|
||||
{CAST(crandc), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(isync), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(crxor), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(crnand), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(crand), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(creqv), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(crorc), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(cror), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(bcctr), {InstrOps::opBrRel, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(bcctrl), {InstrOps::opBrRel, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(cmp), {InstrOps::opCrfDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(tw), {InstrOps::opTOAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(subfc), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(subfcdot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addc), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addcdot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(mulhwu), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(mulhwudot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(mfcr), {InstrOps::opD, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lwarx), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lwzx), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(slw), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(slwdot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(cntlzw), {InstrOps::opSA, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(cntlzwdot), {InstrOps::opSA, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(ppc_and), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(anddot), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(cmpl), {InstrOps::opCrfDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(subf), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(subfdot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(dcbst), {InstrOps::opAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lwzux), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(andc), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(andcdot), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(mulhw), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(mulhwdot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
/*
|
||||
|
||||
{CAST(lbzux), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lbzx), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lfdux), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lfdx), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lfsux), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lfsx), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lhaux), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lhax), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lhbrx), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lhzux), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lhzx), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lswi), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lswx), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(lwbrx), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
|
||||
{CAST(add), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(adddot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addc), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addcdot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addedot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addme), {InstrOps::opDA, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addmedot), {InstrOps::opDA, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addze), {InstrOps::opDA, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addzedot), {InstrOps::opDA, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(and), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(anddot), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(divw), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(divwdot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(divwu), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(divwudot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(eieio), {InstrOps::opNone, CFlowType::CFL_NONE, 1}},
|
||||
|
||||
{CAST(cmpl), {InstrOps::opCrfDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(eqv), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(eqvdot), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(extsb), {InstrOps::opSA, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(extsbdot), {InstrOps::opSA, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(extsh), {InstrOps::opSA, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(extshdot), {InstrOps::opSA, CFlowType::CFL_NONE, 1}},
|
||||
|
||||
{CAST(fmr), {InstrOps::opDB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(icbi), {InstrOps::opAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(isync), {InstrOps::opNone, CFlowType::CFL_NONE, 1}},
|
||||
|
||||
{CAST(mtcrf), {InstrOps::opNone, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(mulhwu), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(mullw), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(nand), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(nanddot), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(neg), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(negdot), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(nor), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(nordot), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(or), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(ordot), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(orc), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(orcdot), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(slw), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(slwdot), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(sraw), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(srawdot), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(srawi), {InstrOps::opSASh, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stbux), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stbx), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stfdux), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stfdx), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stfiwx), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stfsux), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stfsx), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(sthbrx), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(sthux), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(sthx), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stswi), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stswx), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stwbrx), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stwcx), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stwux), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(stwx), {InstrOps::opSAB, CFlowType::CFL_NONE, 1}},
|
||||
|
||||
{CAST(addedot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addeo), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{CAST(addeodot), {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
|
||||
*/
|
||||
};
|
||||
|
||||
CachedInstr* c_instr;
|
||||
uint32_t opcode, main_opcode;
|
||||
unsigned instr_index;
|
||||
uint8_t* pc_real;
|
||||
bool done;
|
||||
|
||||
pc_real = quickinstruction_translate(next_pc);
|
||||
|
||||
c_instr = &code_block[0];
|
||||
|
||||
done = false;
|
||||
|
||||
while (!done) {
|
||||
opcode = ppc_cur_instruction;
|
||||
main_opcode = opcode >> 26;
|
||||
|
||||
instr_index = main_index_tab[main_opcode];
|
||||
if (!instr_index) {
|
||||
switch (main_opcode) {
|
||||
case 16:
|
||||
instr_index = subgrp16_index_tab[opcode & 3];
|
||||
break;
|
||||
case 18:
|
||||
instr_index = subgrp18_index_tab[opcode & 3];
|
||||
break;
|
||||
case 19:
|
||||
instr_index = subgrp19_index_tab[opcode & 0x7FF];
|
||||
break;
|
||||
case 31:
|
||||
instr_index = subgrp31_index_tab[opcode & 0x7FF];
|
||||
break;
|
||||
case 59:
|
||||
instr_index = subgrp59_index_tab[opcode & 0x3F];
|
||||
break;
|
||||
case 63:
|
||||
instr_index = subgrp63_index_tab[opcode & 0x7FF];
|
||||
break;
|
||||
default:
|
||||
instr_index = 0;
|
||||
}
|
||||
|
||||
if (!instr_index) {
|
||||
LOG_F(INFO, "Illegal opcode 0x%08X - Program exception!", opcode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const InterpInstr* p_instr = &interp_tab[instr_index];
|
||||
|
||||
c_instr->call_me = p_instr->emu_fn;
|
||||
|
||||
/* pre-decode operands, immediate values etc. */
|
||||
switch (p_instr->info.ops_fmt) {
|
||||
case InstrOps::opDA:
|
||||
case InstrOps::opSA:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
break;
|
||||
case InstrOps::opDAB:
|
||||
case InstrOps::opSAB:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->d3 = REG_B(opcode);
|
||||
break;
|
||||
case InstrOps::opAB:
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->d3 = REG_B(opcode);
|
||||
break;
|
||||
case InstrOps::opTOAB:
|
||||
c_instr->d1 = REG_TO(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->d3 = REG_B(opcode);
|
||||
break;
|
||||
case InstrOps::opCrfDAB:
|
||||
c_instr->d1 = REG_CRFD(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->d3 = REG_B(opcode);
|
||||
break;
|
||||
case InstrOps::opDASimm:
|
||||
case InstrOps::opSASimm:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->simm = SIMM(opcode);
|
||||
break;
|
||||
case InstrOps::opSAUimm:
|
||||
c_instr->d1 = REG_S(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->uimm = UIMM(opcode);
|
||||
break;
|
||||
case InstrOps::opSASh:
|
||||
c_instr->d1 = REG_S(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->d3 = (opcode >> 11) & 0x1F; // shift
|
||||
c_instr->uimm = (1 << c_instr->d3) - 1; // mask
|
||||
break;
|
||||
case InstrOps::opRot:
|
||||
c_instr->d1 = REG_S(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->d3 = (opcode >> 11) & 0x1F; // shift
|
||||
c_instr->d4 = opcode & 1; // Rc bit
|
||||
c_instr->uimm = rot_mask((opcode >> 6) & 31, (opcode >> 1) & 31); //mask
|
||||
break;
|
||||
case InstrOps::opSSpr:
|
||||
c_instr->d1 = REG_S(opcode);
|
||||
c_instr->uimm = (REG_B(opcode) << 5) | REG_A(opcode);
|
||||
break;
|
||||
case InstrOps::opD:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
break;
|
||||
case InstrOps::opTOASimm:
|
||||
c_instr->d1 = REG_TO(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->simm = SIMM(opcode);
|
||||
break;
|
||||
case InstrOps::opTOB:
|
||||
c_instr->d1 = REG_TO(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->d3 = REG_B(opcode);
|
||||
break;
|
||||
case InstrOps::opCrfDASimm:
|
||||
c_instr->d1 = REG_CRFD(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->simm = SIMM(opcode);
|
||||
break;
|
||||
case InstrOps::opCrfDAUimm:
|
||||
c_instr->d1 = REG_CRFD(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->simm = UIMM(opcode);
|
||||
break;
|
||||
case InstrOps::opDSR:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
c_instr->d2 = REG_SR(opcode);
|
||||
case InstrOps::opDB:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
c_instr->d2 = REG_B(opcode);
|
||||
case InstrOps::opNone:
|
||||
break;
|
||||
case InstrOps::opBrRel:
|
||||
c_instr->bt = SIMM(opcode) >> 2;
|
||||
switch (BR_BO(opcode) & 0x1E) {
|
||||
case 12:
|
||||
case 14:
|
||||
c_instr->call_me = interp_tab[PPCInstr::bc].emu_fn;
|
||||
c_instr->uimm = 0x80000000UL >> BR_BI(opcode);
|
||||
break;
|
||||
case 16:
|
||||
c_instr->call_me = interp_tab[PPCInstr::bdnz].emu_fn;
|
||||
break;
|
||||
case 18:
|
||||
c_instr->call_me = interp_tab[PPCInstr::bdz].emu_fn;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unsupported opcode 0x%08X - Program exception!", opcode);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case InstrOps::opBrLink:
|
||||
switch (BR_BO(opcode) & 0x1E) {
|
||||
case 20: // blr
|
||||
c_instr->call_me = interp_tab[PPCInstr::bexit].emu_fn;
|
||||
c_instr->uimm = next_pc;
|
||||
done = true;
|
||||
continue;
|
||||
default:
|
||||
LOG_F(ERROR, "Unsupported opcode 0x%08X - Program exception!", opcode);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unknown opcode format %d!", p_instr->info.ops_fmt);
|
||||
return;
|
||||
}
|
||||
|
||||
c_instr++;
|
||||
|
||||
next_pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
} // while
|
||||
|
||||
//LOG_F(INFO, "PreDecode completed!");
|
||||
|
||||
CachedInstr* code = &code_block[0];
|
||||
|
||||
goto *(code->call_me); // begin code execution
|
||||
|
||||
#define GEN_OP(name,body) lab_##name: { body; }
|
||||
#define NEXT goto *((++code)->call_me)
|
||||
|
||||
#include "interpops.h" // auto-generate labeled emulation blocks
|
||||
}
|
||||
|
||||
#endif
|
||||
-1613
File diff suppressed because it is too large.
Load diff
@@ -1,185 +0,0 @@
|
||||
#include <cinttypes>
|
||||
#include <map>
|
||||
#include "jittables.h"
|
||||
#include "ppcdefs.h"
|
||||
|
||||
uint16_t main_index_tab[64] = {
|
||||
PPCInstr::illegal, PPCInstr::illegal, PPCInstr::illegal,
|
||||
PPCInstr::twi, PPCInstr::illegal, PPCInstr::illegal,
|
||||
PPCInstr::illegal, PPCInstr::mulli, PPCInstr::subfic,
|
||||
PPCInstr::dozi, PPCInstr::cmpli, PPCInstr::cmpi,
|
||||
PPCInstr::addic, PPCInstr::addicdot, PPCInstr::addi,
|
||||
PPCInstr::addis, PPCInstr::illegal, PPCInstr::sc,
|
||||
PPCInstr::illegal, PPCInstr::illegal, PPCInstr::rlwimix,
|
||||
PPCInstr::rlwinmx, PPCInstr::rlmi, PPCInstr::rlwnmx,
|
||||
PPCInstr::ori, PPCInstr::oris, PPCInstr::xori,
|
||||
PPCInstr::xoris, PPCInstr::andidot, PPCInstr::andisdot,
|
||||
PPCInstr::illegal, PPCInstr::illegal, PPCInstr::lwz,
|
||||
PPCInstr::lwzu, PPCInstr::lbz, PPCInstr::lbzu,
|
||||
PPCInstr::stw, PPCInstr::stwu, PPCInstr::stb,
|
||||
PPCInstr::stbu, PPCInstr::lhz, PPCInstr::lhzu,
|
||||
PPCInstr::lha, PPCInstr::lhau, PPCInstr::sth,
|
||||
PPCInstr::sthu, PPCInstr::lmw, PPCInstr::stmw,
|
||||
PPCInstr::lfs, PPCInstr::lfsu, PPCInstr::lfd,
|
||||
PPCInstr::lfdu, PPCInstr::stfs, PPCInstr::stfsu,
|
||||
PPCInstr::stfd, PPCInstr::stfdu, PPCInstr::illegal,
|
||||
PPCInstr::illegal, PPCInstr::illegal, PPCInstr::illegal,
|
||||
PPCInstr::illegal, PPCInstr::illegal, PPCInstr::illegal,
|
||||
PPCInstr::illegal
|
||||
};
|
||||
|
||||
uint16_t subgrp16_index_tab[4] = {
|
||||
PPCInstr::bc, PPCInstr::bcl, PPCInstr::bca, PPCInstr::bcla
|
||||
};
|
||||
|
||||
uint16_t subgrp18_index_tab[4] = {
|
||||
PPCInstr::b, PPCInstr::bl, PPCInstr::ba, PPCInstr::bla
|
||||
};
|
||||
|
||||
uint16_t subgrp19_index_tab[2048] = { PPCInstr::illegal };
|
||||
|
||||
uint16_t subgrp31_index_tab[2048] = { PPCInstr::illegal };
|
||||
|
||||
uint16_t subgrp59_index_tab[64] = { PPCInstr::illegal };
|
||||
|
||||
uint16_t subgrp63_index_tab[2048] = { PPCInstr::illegal };
|
||||
|
||||
static std::map<uint16_t, PPCInstr> Subop19Init = {
|
||||
{ 32, PPCInstr::bclr },
|
||||
{ 33, PPCInstr::bclrl },
|
||||
{ 66, PPCInstr::crnor },
|
||||
{ 100, PPCInstr::rfi },
|
||||
{ 258, PPCInstr::crandc },
|
||||
{ 300, PPCInstr::isync },
|
||||
{ 386, PPCInstr::crxor },
|
||||
{ 450, PPCInstr::crnand },
|
||||
{ 514, PPCInstr::crand },
|
||||
{ 578, PPCInstr::creqv },
|
||||
{ 834, PPCInstr::crorc },
|
||||
{ 898, PPCInstr::cror },
|
||||
{ 1056, PPCInstr::bcctr },
|
||||
{ 1057, PPCInstr::bcctrl }
|
||||
};
|
||||
|
||||
static std::map<uint16_t, PPCInstr> Subop31Init = {
|
||||
{ 0, PPCInstr::cmp}, { 8, PPCInstr::tw},
|
||||
{ 16, PPCInstr::subfc}, { 17, PPCInstr::subfcdot},
|
||||
{ 20, PPCInstr::addc}, { 21, PPCInstr::addcdot},
|
||||
{ 22, PPCInstr::mulhwu}, { 23, PPCInstr::mulhwudot},
|
||||
{ 38, PPCInstr::mfcr}, { 40, PPCInstr::lwarx},
|
||||
{ 46, PPCInstr::lwzx}, { 48, PPCInstr::slw},
|
||||
{ 49, PPCInstr::slwdot}, { 52, PPCInstr::cntlzw},
|
||||
{ 53, PPCInstr::cntlzwdot}, { 56, PPCInstr::ppc_and},
|
||||
{ 57, PPCInstr::anddot}, { 58, PPCInstr::maskg},
|
||||
{ 59, PPCInstr::maskgdot}, { 64, PPCInstr::cmpl},
|
||||
{ 80, PPCInstr::subf}, { 81, PPCInstr::subfdot},
|
||||
{ 108, PPCInstr::dcbst}, { 110, PPCInstr::lwzux},
|
||||
{ 120, PPCInstr::andc}, { 121, PPCInstr::andcdot},
|
||||
{ 150, PPCInstr::mulhw}, { 151, PPCInstr::mulhwdot},
|
||||
{ 166, PPCInstr::mfmsr}, { 172, PPCInstr::dcbf},
|
||||
{ 174, PPCInstr::lbzx}, { 208, PPCInstr::neg},
|
||||
{ 209, PPCInstr::negdot}, { 214, PPCInstr::mul},
|
||||
{ 215, PPCInstr::muldot}, { 238, PPCInstr::lbzux},
|
||||
{ 248, PPCInstr::nor}, { 249, PPCInstr::nordot},
|
||||
{ 272, PPCInstr::subfe}, { 273, PPCInstr::subfedot},
|
||||
{ 276, PPCInstr::adde}, { 277, PPCInstr::addedot},
|
||||
{ 288, PPCInstr::mtcrf}, { 292, PPCInstr::mtmsr},
|
||||
{ 301, PPCInstr::stwcx}, { 302, PPCInstr::stwx},
|
||||
{ 304, PPCInstr::slq}, { 305, PPCInstr::slqdot},
|
||||
{ 306, PPCInstr::sle}, { 307, PPCInstr::sledot},
|
||||
{ 366, PPCInstr::stwux}, { 368, PPCInstr::sliq},
|
||||
{ 400, PPCInstr::subfze}, { 401, PPCInstr::subfzedot},
|
||||
{ 404, PPCInstr::addze}, { 405, PPCInstr::addzedot},
|
||||
{ 420, PPCInstr::mtsr}, { 430, PPCInstr::stbx},
|
||||
{ 432, PPCInstr::sllq}, { 433, PPCInstr::sllqdot},
|
||||
{ 434, PPCInstr::sleq}, { 436, PPCInstr::sleqdot},
|
||||
{ 464, PPCInstr::subfme}, { 465, PPCInstr::subfmedot},
|
||||
{ 468, PPCInstr::addme}, { 469, PPCInstr::addmedot},
|
||||
{ 470, PPCInstr::mullw}, { 471, PPCInstr::mullwdot},
|
||||
{ 484, PPCInstr::mtsrin}, { 492, PPCInstr::dcbtst},
|
||||
{ 494, PPCInstr::stbux}, { 496, PPCInstr::slliq},
|
||||
{ 497, PPCInstr::slliqdot}, { 528, PPCInstr::doz},
|
||||
{ 529, PPCInstr::dozdot}, { 532, PPCInstr::add},
|
||||
{ 533, PPCInstr::adddot}, { 554, PPCInstr::lscbx},
|
||||
{ 555, PPCInstr::lscbxdot}, { 556, PPCInstr::dcbt},
|
||||
{ 558, PPCInstr::lhzx}, { 568, PPCInstr::eqv},
|
||||
{ 569, PPCInstr::eqvdot}, { 612, PPCInstr::tlbie},
|
||||
{ 622, PPCInstr::lhzux}, { 632, PPCInstr::ppc_xor},
|
||||
{ 633, PPCInstr::xordot}, { 662, PPCInstr::ppc_div},
|
||||
{ 663, PPCInstr::divdot}, { 678, PPCInstr::mfspr},
|
||||
{ 686, PPCInstr::lhax}, { 720, PPCInstr::ppc_abs},
|
||||
{ 721, PPCInstr::absdot}, { 726, PPCInstr::divs},
|
||||
{ 727, PPCInstr::divsdot}, { 740, PPCInstr::tlbia},
|
||||
{ 742, PPCInstr::mftb}, { 750, PPCInstr::lhaux},
|
||||
{ 814, PPCInstr::sthx}, { 824, PPCInstr::orc},
|
||||
{ 825, PPCInstr::orcdot}, { 878, PPCInstr::sthux},
|
||||
{ 888, PPCInstr::ppc_or}, { 889, PPCInstr::ordot},
|
||||
{ 918, PPCInstr::divwu}, { 919, PPCInstr::divwudot},
|
||||
{ 934, PPCInstr::mtspr}, { 940, PPCInstr::dcbi},
|
||||
{ 952, PPCInstr::nand}, { 953, PPCInstr::nanddot},
|
||||
{ 976, PPCInstr::nabs}, { 977, PPCInstr::nabsdot},
|
||||
{ 982, PPCInstr::divw}, { 983, PPCInstr::divwdot},
|
||||
{ 1024, PPCInstr::mcrxr}, { 1040, PPCInstr::subfco},
|
||||
{ 1041, PPCInstr::subfcodot}, { 1044, PPCInstr::addco},
|
||||
{ 1045, PPCInstr::addcodot}, { 1062, PPCInstr::clcs},
|
||||
{ 1063, PPCInstr::clcsdot}, { 1066, PPCInstr::lswx},
|
||||
{ 1068, PPCInstr::lwbrx}, { 1070, PPCInstr::lfsx},
|
||||
{ 1072, PPCInstr::srw}, { 1073, PPCInstr::srwdot},
|
||||
{ 1074, PPCInstr::rrib}, { 1075, PPCInstr::rribdot},
|
||||
{ 1082, PPCInstr::maskir}, { 1083, PPCInstr::maskirdot},
|
||||
{ 1104, PPCInstr::subfo}, { 1105, PPCInstr::subfodot},
|
||||
{ 1132, PPCInstr::tlbsync}, { 1134, PPCInstr::lfsux},
|
||||
{ 1190, PPCInstr::mfsr}, { 1194, PPCInstr::lswi},
|
||||
{ 1196, PPCInstr::ppc_sync}, { 1198, PPCInstr::lfdx},
|
||||
{ 1232, PPCInstr::nego}, { 1233, PPCInstr::negodot},
|
||||
{ 1238, PPCInstr::mulo}, { 1239, PPCInstr::mulodot},
|
||||
{ 1262, PPCInstr::lfdux}, { 1296, PPCInstr::subfeo},
|
||||
{ 1297, PPCInstr::subfeodot}, { 1300, PPCInstr::addeo},
|
||||
{ 1301, PPCInstr::addeodot}, { 1318, PPCInstr::mfsrin},
|
||||
{ 1322, PPCInstr::stswx}, { 1324, PPCInstr::stwbrx},
|
||||
{ 1326, PPCInstr::stfsx}, { 1328, PPCInstr::srq},
|
||||
{ 1329, PPCInstr::srqdot}, { 1330, PPCInstr::sre},
|
||||
{ 1331, PPCInstr::sredot}, { 1390, PPCInstr::stfsux},
|
||||
{ 1392, PPCInstr::sriq}, { 1393, PPCInstr::sriqdot},
|
||||
{ 1424, PPCInstr::subfzeo}, { 1425, PPCInstr::subfzeodot},
|
||||
{ 1428, PPCInstr::addzeo}, { 1429, PPCInstr::addzeodot},
|
||||
{ 1450, PPCInstr::stswi}, { 1454, PPCInstr::stfdx},
|
||||
{ 1456, PPCInstr::srlq}, { 1457, PPCInstr::srlqdot},
|
||||
{ 1458, PPCInstr::sreq }, { 1459, PPCInstr::sreqdot},
|
||||
{ 1488, PPCInstr::subfmeo }, { 1489, PPCInstr::subfmeodot},
|
||||
{ 1492, PPCInstr::addmeo }, { 1493, PPCInstr::addmeodot},
|
||||
{ 1494, PPCInstr::mullwo }, { 1495, PPCInstr::mullwodot},
|
||||
{ 1518, PPCInstr::stfdux }, { 1520, PPCInstr::srliq},
|
||||
{ 1521, PPCInstr::srliqdot }, { 1552, PPCInstr::dozo},
|
||||
{ 1553, PPCInstr::dozodot }, { 1556, PPCInstr::addo},
|
||||
{ 1557, PPCInstr::addodot }, { 1580, PPCInstr::lhbrx},
|
||||
{ 1584, PPCInstr::sraw }, { 1585, PPCInstr::srawdot},
|
||||
{ 1648, PPCInstr::srawi }, { 1649, PPCInstr::srawidot},
|
||||
{ 1686, PPCInstr::divo }, { 1687, PPCInstr::divodot},
|
||||
{ 1708, PPCInstr::eieio }, { 1744, PPCInstr::abso},
|
||||
{ 1745, PPCInstr::absodot }, { 1750, PPCInstr::divso},
|
||||
{ 1751, PPCInstr::divsodot }, { 1836, PPCInstr::sthbrx},
|
||||
{ 1840, PPCInstr::sraq }, { 1841, PPCInstr::sraqdot},
|
||||
{ 1842, PPCInstr::srea }, { 1843, PPCInstr::sreadot},
|
||||
{ 1844, PPCInstr::extsh }, { 1845, PPCInstr::extshdot},
|
||||
{ 1904, PPCInstr::sraiq }, { 1905, PPCInstr::sraiqdot},
|
||||
{ 1908, PPCInstr::extsb }, { 1909, PPCInstr::extsbdot},
|
||||
{ 1942, PPCInstr::divwuo }, { 1943, PPCInstr::divwuodot},
|
||||
{ 1956, PPCInstr::tlbld }, { 1964, PPCInstr::icbi},
|
||||
{ 1966, PPCInstr::stfiwx }, { 2000, PPCInstr::nabso},
|
||||
{ 2001, PPCInstr::nabsodot }, { 2006, PPCInstr::divwo},
|
||||
{ 2007, PPCInstr::divwodot }, { 2020, PPCInstr::tlbli},
|
||||
{ 2028, PPCInstr::dcbz }
|
||||
};
|
||||
|
||||
void init_jit_tables() {
|
||||
std::map<uint16_t, PPCInstr>::iterator it;
|
||||
|
||||
for (it = Subop19Init.begin(); it != Subop19Init.end(); it++ ) {
|
||||
subgrp19_index_tab[it->first] = it->second;
|
||||
}
|
||||
|
||||
for (it = Subop31Init.begin(); it != Subop31Init.end(); it++ ) {
|
||||
subgrp31_index_tab[it->first] = it->second;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
#ifndef JIT_TABLES_H
|
||||
#define JIT_TABLES_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include "ppcemu.h"
|
||||
|
||||
/** Instruction operands formats. */
|
||||
enum class InstrOps {
|
||||
opNone,
|
||||
opDA,
|
||||
opDAB,
|
||||
opAB,
|
||||
opDASimm,
|
||||
opSAUimm,
|
||||
opSASh,
|
||||
opRot,
|
||||
opSSpr,
|
||||
opBrRel,
|
||||
opBrLink,
|
||||
opD,
|
||||
opTOASimm,
|
||||
opTOB,
|
||||
opCrfDAB,
|
||||
opCrfDASimm,
|
||||
opCrfDAUimm,
|
||||
opDSR,
|
||||
opDB,
|
||||
opSASimm,
|
||||
opSA,
|
||||
opSAB,
|
||||
opTOAB
|
||||
};
|
||||
|
||||
/* Control flow kind. */
|
||||
enum class CFlowType {
|
||||
CFL_NONE,
|
||||
CFL_COND_BRANCH,
|
||||
CFL_UNCOND_BRANCH,
|
||||
CFL_TRAP,
|
||||
};
|
||||
|
||||
struct InstrInfo {
|
||||
InstrOps ops_fmt; // describes operands format
|
||||
CFlowType cflow_type; // control flow type
|
||||
int num_cycles;
|
||||
|
||||
// Required by JIT
|
||||
//int flags; // flags updated by this instruction
|
||||
};
|
||||
|
||||
extern uint16_t main_index_tab[];
|
||||
extern uint16_t subgrp16_index_tab[];
|
||||
extern uint16_t subgrp18_index_tab[];
|
||||
extern uint16_t subgrp19_index_tab[];
|
||||
extern uint16_t subgrp31_index_tab[];
|
||||
extern uint16_t subgrp59_index_tab[];
|
||||
extern uint16_t subgrp63_index_tab[];
|
||||
|
||||
void init_jit_tables(void);
|
||||
|
||||
#endif /* JIT_TABLES_H */
|
||||
@@ -1,272 +0,0 @@
|
||||
#include <cinttypes>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
#include "ppcdefs.h"
|
||||
#include "jittables.h"
|
||||
#include "nuinterpreter.h"
|
||||
|
||||
#if !defined(USE_DTC)
|
||||
|
||||
CachedInstr* interp_tpc;
|
||||
bool interp_running;
|
||||
|
||||
#define GEN_OP(name,body) void impl_##name(const CachedInstr* code) {body}
|
||||
#define NEXT interp_tpc++
|
||||
|
||||
#include "interpops.h"
|
||||
|
||||
struct InterpInstr {
|
||||
ImplSubr emu_fn; // pointer to the instruction emulation routine
|
||||
InstrInfo info;
|
||||
};
|
||||
|
||||
/* WARNING: entries in this table MUST be in the same order as constants in PPCInstr! */
|
||||
InterpInstr interp_tab[] = {
|
||||
{nullptr, {InstrOps::opNone, CFlowType::CFL_NONE, 0}},
|
||||
{impl_addi, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_adde, {InstrOps::opDAB, CFlowType::CFL_NONE, 1}},
|
||||
{impl_addze, {InstrOps::opDA, CFlowType::CFL_NONE, 1}},
|
||||
{impl_andidot, {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_lwz, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_lwzu, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_lbz, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_lhz, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_rlwinm, {InstrOps::opRot, CFlowType::CFL_NONE, 1}},
|
||||
{impl_srawidot, {InstrOps::opSASh, CFlowType::CFL_NONE, 1}},
|
||||
{impl_bc, {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{impl_bdnz, {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{impl_bdz, {InstrOps::opBrRel, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{impl_bclr, {InstrOps::opBrLink, CFlowType::CFL_COND_BRANCH, 0}},
|
||||
{impl_mtspr, {InstrOps::opSSpr, CFlowType::CFL_NONE, 2}},
|
||||
{impl_bexit, {InstrOps::opNone, CFlowType::CFL_UNCOND_BRANCH, 0}},
|
||||
{impl_twi, {InstrOps::opTOASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_mulli, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_cmpli, {InstrOps::opCrfDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_cmpi, {InstrOps::opCrfDAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_addic, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_addicdot, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_sc, {InstrOps::opSC, CFlowType::CFL_NONE, 1}},
|
||||
{impl_rlwimix, {InstrOps::opRot, CFlowType::CFL_NONE, 1}},
|
||||
{impl_rlwnmx, {InstrOps::opRot, CFlowType::CFL_NONE, 1}},
|
||||
{impl_ori, {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_oris, {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_xori, {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_xoris, {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_andisdot, {InstrOps::opSAUimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_lbzu, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_stw, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_stwu, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_stb, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_stbu, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_lhzu, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_lha, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_lhau, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_sth, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
{impl_sthu, {InstrOps::opDASimm, CFlowType::CFL_NONE, 1}},
|
||||
};
|
||||
|
||||
CachedInstr code_block[256];
|
||||
|
||||
#define REG_D(opcode) ((opcode >> 21) & 0x1F)
|
||||
#define REG_A(opcode) ((opcode >> 16) & 0x1F)
|
||||
#define REG_B(opcode) ((opcode >> 11) & 0x1F)
|
||||
#define REG_S REG_D
|
||||
#define BR_BO REG_D
|
||||
#define BR_BI REG_A
|
||||
#define SIMM(opcode) ((int32_t)((int16_t)(opcode & 0xFFFF)))
|
||||
#define UIMM(opcode) ((uint32_t)((uint16_t)(opcode & 0xFFFF)))
|
||||
#define REG_TO(opcode) REG_D
|
||||
#define REG_CRFD(opcode) (((opcode >> 23) & 7) << 2)
|
||||
#define REG_SR(opcode) (opcode >> 16) & 15
|
||||
|
||||
/** mask generator for rotate and shift instructions (§ 4.2.1.4 PowerpC PEM) */
|
||||
static inline uint32_t rot_mask(unsigned rot_mb, unsigned rot_me) {
|
||||
uint32_t m1 = 0xFFFFFFFFUL >> rot_mb;
|
||||
uint32_t m2 = 0xFFFFFFFFUL << (31 - rot_me);
|
||||
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
||||
}
|
||||
|
||||
|
||||
bool PreDecode(uint32_t next_pc, CachedInstr* c_instr)
|
||||
{
|
||||
uint32_t opcode, main_opcode;
|
||||
unsigned instr_index;
|
||||
uint8_t* pc_real;
|
||||
bool done;
|
||||
|
||||
pc_real = quickinstruction_translate(next_pc);
|
||||
|
||||
//CachedInstr* c_instr = &code[0];
|
||||
|
||||
done = false;
|
||||
|
||||
while (!done) {
|
||||
opcode = ppc_cur_instruction;
|
||||
main_opcode = opcode >> 26;
|
||||
|
||||
instr_index = main_index_tab[main_opcode];
|
||||
if (!instr_index) {
|
||||
switch (main_opcode) {
|
||||
case 16:
|
||||
instr_index = subgrp16_index_tab[opcode & 3];
|
||||
break;
|
||||
case 18:
|
||||
instr_index = subgrp18_index_tab[opcode & 3];
|
||||
break;
|
||||
case 19:
|
||||
instr_index = subgrp19_index_tab[opcode & 0x7FF];
|
||||
break;
|
||||
case 31:
|
||||
instr_index = subgrp31_index_tab[opcode & 0x7FF];
|
||||
break;
|
||||
case 59:
|
||||
instr_index = subgrp59_index_tab[opcode & 0x3F];
|
||||
break;
|
||||
case 63:
|
||||
instr_index = subgrp63_index_tab[opcode & 0x7FF];
|
||||
break;
|
||||
default:
|
||||
instr_index = 0;
|
||||
}
|
||||
|
||||
if (!instr_index) {
|
||||
LOG_F(ERROR, "Illegal opcode 0x%08X - Program exception!", opcode);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const InterpInstr* p_instr = &interp_tab[instr_index];
|
||||
|
||||
c_instr->call_me = p_instr->emu_fn;
|
||||
|
||||
/* pre-decode operands, immediate values etc. */
|
||||
switch (p_instr->info.ops_fmt) {
|
||||
case InstrOps::opDA:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
break;
|
||||
case InstrOps::opDAB:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->d3 = REG_B(opcode);
|
||||
break;
|
||||
case InstrOps::opDASimm:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->simm = SIMM(opcode);
|
||||
break;
|
||||
case InstrOps::opSAUimm:
|
||||
c_instr->d1 = REG_S(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->uimm = UIMM(opcode);
|
||||
break;
|
||||
case InstrOps::opSASh:
|
||||
c_instr->d1 = REG_S(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->d3 = (opcode >> 11) & 0x1F; // shift
|
||||
c_instr->uimm = (1 << c_instr->d3) - 1; // mask
|
||||
break;
|
||||
case InstrOps::opRot:
|
||||
c_instr->d1 = REG_S(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->d3 = (opcode >> 11) & 0x1F; // shift
|
||||
c_instr->d4 = opcode & 1; // Rc bit
|
||||
c_instr->uimm = rot_mask((opcode >> 6) & 31, (opcode >> 1) & 31); //mask
|
||||
break;
|
||||
case InstrOps::opSSpr:
|
||||
c_instr->d1 = REG_S(opcode);
|
||||
c_instr->uimm = (REG_B(opcode) << 5) | REG_A(opcode);
|
||||
break;
|
||||
case InstrOps::opD:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
break;
|
||||
case InstrOps::opTOASimm:
|
||||
c_instr->d1 = REG_TO(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->simm = SIMM(opcode);
|
||||
break;
|
||||
case InstrOps::opTOB:
|
||||
c_instr->d1 = REG_TO(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->d3 = REG_B(opcode);
|
||||
break;
|
||||
case InstrOps::opCrfDASimm:
|
||||
c_instr->d1 = REG_CRFD(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->simm = SIMM(opcode);
|
||||
break;
|
||||
case InstrOps::opCrfDAUimm:
|
||||
c_instr->d1 = REG_CRFD(opcode);
|
||||
c_instr->d2 = REG_A(opcode);
|
||||
c_instr->simm = UIMM(opcode);
|
||||
break;
|
||||
case InstrOps::opDSR:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
c_instr->d2 = REG_SR(opcode);
|
||||
case InstrOps::opDB:
|
||||
c_instr->d1 = REG_D(opcode);
|
||||
c_instr->d2 = REG_B(opcode);
|
||||
case InstrOps::opSC:
|
||||
break;
|
||||
case InstrOps::opBrRel:
|
||||
c_instr->bt = SIMM(opcode) >> 2;
|
||||
switch (BR_BO(opcode) & 0x1E) {
|
||||
case 12:
|
||||
case 14:
|
||||
c_instr->call_me = interp_tab[PPCInstr::bc].emu_fn;
|
||||
c_instr->uimm = 0x80000000UL >> BR_BI(opcode);
|
||||
break;
|
||||
case 16:
|
||||
c_instr->call_me = interp_tab[PPCInstr::bdnz].emu_fn;
|
||||
break;
|
||||
case 18:
|
||||
c_instr->call_me = interp_tab[PPCInstr::bdz].emu_fn;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unsupported opcode 0x%08X - Program exception!", opcode);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case InstrOps::opBrLink:
|
||||
switch (BR_BO(opcode) & 0x1E) {
|
||||
case 20: // blr
|
||||
c_instr->call_me = interp_tab[PPCInstr::bexit].emu_fn;
|
||||
c_instr->uimm = next_pc;
|
||||
done = true;
|
||||
continue;
|
||||
default:
|
||||
LOG_F(ERROR, "Unsupported opcode 0x%08X - Program exception!", opcode);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unknown opcode format %d!", p_instr->info.ops_fmt);
|
||||
return false;
|
||||
}
|
||||
|
||||
c_instr++;
|
||||
|
||||
next_pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
} // while
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NuInterpExec(uint32_t start_addr) {
|
||||
interp_tpc = &code_block[0];
|
||||
|
||||
if (!PreDecode(start_addr, interp_tpc)) {
|
||||
return;
|
||||
}
|
||||
|
||||
interp_running = true;
|
||||
|
||||
while(interp_running) {
|
||||
interp_tpc->call_me(interp_tpc);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // if !defined(USE_DTC)
|
||||
@@ -1,38 +0,0 @@
|
||||
#ifndef NU_INTERPRETER_H
|
||||
#define NU_INTERPRETER_H
|
||||
|
||||
#include "ppcdefs.h"
|
||||
|
||||
#define USE_DTC
|
||||
|
||||
struct CachedInstr; // forward declaration
|
||||
|
||||
typedef void (*ImplSubr)(const CachedInstr *);
|
||||
|
||||
struct CachedInstr {
|
||||
#if defined(USE_DTC)
|
||||
void* call_me;
|
||||
#else
|
||||
ImplSubr call_me;
|
||||
#endif
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint8_t d1;
|
||||
uint8_t d2;
|
||||
uint8_t d3;
|
||||
uint8_t d4;
|
||||
};
|
||||
int32_t bt; // branch target
|
||||
};
|
||||
|
||||
union {
|
||||
int32_t simm;
|
||||
uint32_t uimm;
|
||||
};
|
||||
};
|
||||
|
||||
bool PreDecode(uint32_t next_pc, CachedInstr* c_instr);
|
||||
void NuInterpExec(uint32_t start_addr);
|
||||
|
||||
#endif // NU_INTERPRETER_H
|
||||
@@ -1,297 +0,0 @@
|
||||
#ifndef PPC_DEFS_H
|
||||
#define PPC_DEFS_H
|
||||
|
||||
/* Enumerate all supported PowerPC instructions. */
|
||||
enum PPCInstr : int {
|
||||
illegal = 0,
|
||||
addi,
|
||||
adde,
|
||||
addze,
|
||||
andidot,
|
||||
lwz,
|
||||
lwzu,
|
||||
lbz,
|
||||
lhz,
|
||||
rlwinmx,
|
||||
srawidot,
|
||||
bc,
|
||||
bdnz,
|
||||
bdz,
|
||||
bclr,
|
||||
mtspr,
|
||||
bexit, // arificial block exit opcode
|
||||
|
||||
twi,
|
||||
mulli,
|
||||
subfic,
|
||||
cmpli,
|
||||
cmpi,
|
||||
addic,
|
||||
addicdot,
|
||||
addis,
|
||||
sc,
|
||||
rlwimix,
|
||||
rlwnmx,
|
||||
ori,
|
||||
oris,
|
||||
xori,
|
||||
xoris,
|
||||
andisdot,
|
||||
lbzu,
|
||||
stw,
|
||||
stwu,
|
||||
stb,
|
||||
stbu,
|
||||
lhzu,
|
||||
lha,
|
||||
lhau,
|
||||
sth,
|
||||
sthu,
|
||||
lmw,
|
||||
stmw,
|
||||
lfs,
|
||||
lfsu,
|
||||
lfd,
|
||||
lfdu,
|
||||
stfs,
|
||||
stfsu,
|
||||
stfd,
|
||||
stfdu,
|
||||
bcl,
|
||||
bca,
|
||||
bcla,
|
||||
b,
|
||||
bl,
|
||||
ba,
|
||||
bla,
|
||||
bclrl,
|
||||
crnor,
|
||||
rfi,
|
||||
crandc,
|
||||
isync,
|
||||
crxor,
|
||||
crnand,
|
||||
crand,
|
||||
creqv,
|
||||
crorc,
|
||||
cror,
|
||||
bcctr,
|
||||
bcctrl,
|
||||
cmp,
|
||||
tw,
|
||||
subfc,
|
||||
subfcdot,
|
||||
addc,
|
||||
addcdot,
|
||||
mulhwu,
|
||||
mulhwudot,
|
||||
mfcr,
|
||||
lwarx,
|
||||
lwzx,
|
||||
slw,
|
||||
slwdot,
|
||||
cntlzw,
|
||||
cntlzwdot,
|
||||
ppc_and,
|
||||
anddot,
|
||||
cmpl,
|
||||
subf,
|
||||
subfdot,
|
||||
dcbst,
|
||||
lwzux,
|
||||
andc,
|
||||
andcdot,
|
||||
mulhw,
|
||||
mulhwdot,
|
||||
mfmsr,
|
||||
dcbf,
|
||||
lbzx,
|
||||
neg,
|
||||
negdot,
|
||||
mul,
|
||||
muldot,
|
||||
lbzux,
|
||||
nor,
|
||||
nordot,
|
||||
subfe,
|
||||
subfedot,
|
||||
addedot,
|
||||
mtcrf,
|
||||
mtmsr,
|
||||
stwcx,
|
||||
stwx,
|
||||
stwux,
|
||||
subfze,
|
||||
subfzedot,
|
||||
addzedot,
|
||||
mtsr,
|
||||
stbx,
|
||||
subfme,
|
||||
subfmedot,
|
||||
addme,
|
||||
addmedot,
|
||||
mullw,
|
||||
mullwdot,
|
||||
mtsrin,
|
||||
dcbtst,
|
||||
stbux,
|
||||
add,
|
||||
adddot,
|
||||
lscbx,
|
||||
lscbxdot,
|
||||
dcbt,
|
||||
lhzx,
|
||||
eqv,
|
||||
eqvdot,
|
||||
tlbie,
|
||||
lhzux,
|
||||
ppc_xor,
|
||||
xordot,
|
||||
ppc_div,
|
||||
divdot,
|
||||
mfspr,
|
||||
lhax,
|
||||
ppc_abs,
|
||||
absdot,
|
||||
divs,
|
||||
divsdot,
|
||||
tlbia,
|
||||
mftb,
|
||||
lhaux,
|
||||
sthx,
|
||||
orc,
|
||||
orcdot,
|
||||
sthux,
|
||||
ppc_or,
|
||||
ordot,
|
||||
divwu,
|
||||
divwudot,
|
||||
dcbi,
|
||||
nand,
|
||||
nanddot,
|
||||
divw,
|
||||
divwdot,
|
||||
mcrxr,
|
||||
subfco,
|
||||
subfcodot,
|
||||
addco,
|
||||
addcodot,
|
||||
lswx,
|
||||
lwbrx,
|
||||
lfsx,
|
||||
srw,
|
||||
srwdot,
|
||||
subfo,
|
||||
subfodot,
|
||||
tlbsync,
|
||||
lfsux,
|
||||
mfsr,
|
||||
lswi,
|
||||
ppc_sync,
|
||||
lfdx,
|
||||
nego,
|
||||
negodot,
|
||||
mulo,
|
||||
mulodot,
|
||||
lfdux,
|
||||
subfeo,
|
||||
subfeodot,
|
||||
addeo,
|
||||
addeodot,
|
||||
mfsrin,
|
||||
stswx,
|
||||
stwbrx,
|
||||
stfsx,
|
||||
stfsux,
|
||||
subfzeo,
|
||||
subfzeodot,
|
||||
addzeo,
|
||||
addzeodot,
|
||||
stswi,
|
||||
stfdx,
|
||||
subfmeo,
|
||||
subfmeodot,
|
||||
addmeo,
|
||||
addmeodot,
|
||||
mullwo,
|
||||
mullwodot,
|
||||
stfdux,
|
||||
addo,
|
||||
addodot,
|
||||
lhbrx,
|
||||
sraw,
|
||||
srawdot,
|
||||
srawi,
|
||||
eieio,
|
||||
sthbrx,
|
||||
extsh,
|
||||
extshdot,
|
||||
extsb,
|
||||
extsbdot,
|
||||
divwuo,
|
||||
divwuodot,
|
||||
tlbld,
|
||||
icbi,
|
||||
stfiwx,
|
||||
divwo,
|
||||
divwodot,
|
||||
tlbli,
|
||||
dcbz,
|
||||
|
||||
// POWER-specific
|
||||
dozi,
|
||||
rlmi,
|
||||
maskg,
|
||||
maskgdot,
|
||||
slq,
|
||||
slqdot,
|
||||
sle,
|
||||
sledot,
|
||||
sliq,
|
||||
sllq,
|
||||
sllqdot,
|
||||
sleq,
|
||||
sleqdot,
|
||||
slliq,
|
||||
slliqdot,
|
||||
doz,
|
||||
dozdot,
|
||||
nabs,
|
||||
nabsdot,
|
||||
clcs,
|
||||
clcsdot,
|
||||
rrib,
|
||||
rribdot,
|
||||
maskir,
|
||||
maskirdot,
|
||||
srq,
|
||||
srqdot,
|
||||
sre,
|
||||
sredot,
|
||||
sriq,
|
||||
sriqdot,
|
||||
srlq,
|
||||
srlqdot,
|
||||
sreq,
|
||||
sreqdot,
|
||||
srliq,
|
||||
srliqdot,
|
||||
dozo,
|
||||
dozodot,
|
||||
divo,
|
||||
divodot,
|
||||
abso,
|
||||
absodot,
|
||||
divso,
|
||||
divsodot,
|
||||
sraq,
|
||||
sraqdot,
|
||||
srea,
|
||||
sreadot,
|
||||
sraiq,
|
||||
sraiqdot,
|
||||
nabso,
|
||||
nabsodot,
|
||||
};
|
||||
|
||||
#endif /* PPC_DEFS_H */
|
||||
+12
-2
@@ -35,7 +35,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
//#define ILLEGAL_OP_SAFE 1
|
||||
|
||||
// Uncomment this to use GCC built-in functions.
|
||||
//#define USE_GCC_BUILTINS 1
|
||||
#define USE_GCC_BUILTINS 1
|
||||
|
||||
// Uncomment this to use Visual Studio built-in functions.
|
||||
//#define USE_VS_BUILTINS 1
|
||||
@@ -215,6 +215,14 @@ enum class Except_Type {
|
||||
EXC_TRACE = 13
|
||||
};
|
||||
|
||||
/** Programm Exception subclasses. */
|
||||
enum Exc_Cause : uint32_t {
|
||||
FPU_OFF = 1 << (31 - 11),
|
||||
ILLEGAL_OP = 1 << (31 - 12),
|
||||
NOT_ALLOWED = 1 << (31 - 13),
|
||||
TRAP = 1 << (31 - 14),
|
||||
};
|
||||
|
||||
// extern bool bb_end;
|
||||
extern BB_end_kind bb_kind;
|
||||
|
||||
@@ -246,7 +254,8 @@ extern uint32_t supervisor_inst_num;
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version);
|
||||
extern void ppc_mmu_init();
|
||||
|
||||
void ppc_illegalop();
|
||||
[[noreturn]] void ppc_illegalop();
|
||||
[[noreturn]] void ppc_fpu_off();
|
||||
void ppc_illegalsubop19();
|
||||
void ppc_illegalsubop31();
|
||||
void ppc_illegalsubop59();
|
||||
@@ -554,6 +563,7 @@ extern void ppc_main_opcode(void);
|
||||
extern void ppc_exec(void);
|
||||
extern void ppc_exec_single(void);
|
||||
extern void ppc_exec_until(uint32_t goal_addr);
|
||||
extern void ppc_exec_dbg(uint32_t start_addr, uint32_t size);
|
||||
|
||||
/* debugging support API */
|
||||
void print_gprs(void); /* print content of the general purpose registers */
|
||||
|
||||
+89
-51
@@ -73,7 +73,7 @@ uint8_t tbr_factor; /* cycles_count to TBR freq ratio in 2^x units */
|
||||
|
||||
/** Primary opcode (bits 0...5) lookup table. */
|
||||
static PPCOpcode OpcodeGrabber[] = {
|
||||
ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_twi, ppc_opcode4, ppc_illegalop,
|
||||
ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_twi, ppc_illegalop, ppc_illegalop,
|
||||
ppc_illegalop, ppc_mulli, ppc_subfic, power_dozi, ppc_cmpli, ppc_cmpi,
|
||||
ppc_addic, ppc_addicdot, ppc_addi, ppc_addis, ppc_opcode16, ppc_sc,
|
||||
ppc_opcode18, ppc_opcode19, ppc_rlwimi, ppc_rlwinm, power_rlmi, ppc_rlwnm,
|
||||
@@ -86,16 +86,24 @@ static PPCOpcode OpcodeGrabber[] = {
|
||||
ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_opcode63};
|
||||
|
||||
/** Lookup tables for branch instructions. */
|
||||
static PPCOpcode SubOpcode16Grabber[] = {ppc_bc, ppc_bcl, ppc_bca, ppc_bcla};
|
||||
static PPCOpcode SubOpcode16Grabber[] = {
|
||||
dppc_interpreter::ppc_bc,
|
||||
dppc_interpreter::ppc_bcl,
|
||||
dppc_interpreter::ppc_bca,
|
||||
dppc_interpreter::ppc_bcla};
|
||||
|
||||
static PPCOpcode SubOpcode18Grabber[] = {ppc_b, ppc_bl, ppc_ba, ppc_bla};
|
||||
static PPCOpcode SubOpcode18Grabber[] = {
|
||||
dppc_interpreter::ppc_b,
|
||||
dppc_interpreter::ppc_bl,
|
||||
dppc_interpreter::ppc_ba,
|
||||
dppc_interpreter::ppc_bla};
|
||||
|
||||
/** Instructions decoding tables for integer,
|
||||
single floating-point, and double-floating point ops respectively */
|
||||
|
||||
PPCOpcode SubOpcode31Grabber[1024] = {ppc_illegalsubop19};
|
||||
PPCOpcode SubOpcode59Grabber[1024] = {ppc_illegalsubop19};
|
||||
PPCOpcode SubOpcode63Grabber[1024] = {ppc_illegalsubop19};
|
||||
PPCOpcode SubOpcode31Grabber[1024] = { ppc_illegalop };
|
||||
PPCOpcode SubOpcode59Grabber[1024] = { ppc_fpu_off };
|
||||
PPCOpcode SubOpcode63Grabber[1024] = { ppc_fpu_off };
|
||||
|
||||
|
||||
#define UPDATE_TBR_DEC \
|
||||
@@ -109,50 +117,18 @@ PPCOpcode SubOpcode63Grabber[1024] = {ppc_illegalsubop19};
|
||||
old_cycles_count += delta << tbr_factor; \
|
||||
}
|
||||
|
||||
/** Exception helpers. */
|
||||
|
||||
[[noreturn]] void ppc_illegalop() {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
|
||||
[[noreturn]] void ppc_fpu_off() {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_OFF);
|
||||
}
|
||||
|
||||
/** Opcode decoding functions. */
|
||||
|
||||
void ppc_illegalop() {
|
||||
LOG_F(ERROR, "Illegal opcode reported: 0x%X Report this! \n", ppc_cur_instruction);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void ppc_illegalsubop19() {
|
||||
uint16_t illegal_subcode = ppc_cur_instruction & 0x7FF;
|
||||
uint32_t grab_it = (uint32_t)illegal_subcode;
|
||||
LOG_F(ERROR, "Illegal subopcode for 19 reported: %d Report this! \n", grab_it);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void ppc_illegalsubop31() {
|
||||
uint16_t illegal_subcode = ppc_cur_instruction & 0x7FF;
|
||||
uint32_t grab_it = (uint32_t)illegal_subcode;
|
||||
LOG_F(ERROR, "Illegal subopcode for 31 reported: %d Report this! \n", grab_it);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void ppc_illegalsubop59() {
|
||||
uint16_t illegal_subcode = ppc_cur_instruction & 0x7FF;
|
||||
uint32_t grab_it = (uint32_t)illegal_subcode;
|
||||
LOG_F(ERROR, "Illegal subopcode for 59 reported: %d Report this! \n", grab_it);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void ppc_illegalsubop63() {
|
||||
uint16_t illegal_subcode = ppc_cur_instruction & 0x7FF;
|
||||
uint32_t grab_it = (uint32_t)illegal_subcode;
|
||||
LOG_F(ERROR, "Illegal subopcode for 63 reported: %d Report this! \n", grab_it);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void ppc_opcode4() {
|
||||
LOG_F(INFO, "Reading from Opcode 4 table \n");
|
||||
uint8_t subop_grab = ppc_cur_instruction & 3;
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(ERROR, "Executing subopcode entry %d \n"
|
||||
".. or would if I bothered to implement it. SORRY!", regrab);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void ppc_opcode16() {
|
||||
SubOpcode16Grabber[ppc_cur_instruction & 3]();
|
||||
}
|
||||
@@ -210,8 +186,8 @@ void ppc_opcode19() {
|
||||
case 898:
|
||||
ppc_cror();
|
||||
break;
|
||||
default: // Illegal opcode - should never happen
|
||||
ppc_illegalsubop19();
|
||||
default:
|
||||
ppc_illegalop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -352,7 +328,7 @@ void ppc_exec_single()
|
||||
}
|
||||
|
||||
/** Execute PPC code until goal_addr is reached. */
|
||||
void ppc_exec_until(uint32_t goal_addr)
|
||||
void ppc_exec_until(volatile uint32_t goal_addr)
|
||||
{
|
||||
uint32_t bb_start_la, page_start, delta;
|
||||
uint8_t* pc_real;
|
||||
@@ -411,6 +387,68 @@ again:
|
||||
}
|
||||
}
|
||||
|
||||
/** Execute PPC code until control is reached the specified region. */
|
||||
void ppc_exec_dbg(volatile uint32_t start_addr, volatile uint32_t size)
|
||||
{
|
||||
uint32_t bb_start_la, page_start, delta;
|
||||
uint8_t* pc_real;
|
||||
|
||||
/* start new basic block */
|
||||
glob_bb_start_la = bb_start_la = ppc_state.pc;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
|
||||
if (setjmp(exc_env)) {
|
||||
/* reaching here means we got a low-level exception */
|
||||
#ifdef NEW_TBR_UPDATE_ALGO
|
||||
cycles_count += ((ppc_state.pc - glob_bb_start_la) >> 2) + 1;
|
||||
UPDATE_TBR_DEC
|
||||
#else
|
||||
timebase_counter += ((ppc_state.pc - glob_bb_start_la) >> 2) + 1;
|
||||
#endif
|
||||
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
ppc_state.pc = bb_start_la;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
//printf("DBG Exec: got exception, continue at %X\n", ppc_state.pc);
|
||||
goto again;
|
||||
}
|
||||
|
||||
/* initial MMU translation for the current code page. */
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
|
||||
/* set current code page limits */
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
|
||||
again:
|
||||
while (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size) {
|
||||
ppc_main_opcode();
|
||||
if (bb_kind != BB_end_kind::BB_NONE) {
|
||||
#ifdef NEW_TBR_UPDATE_ALGO
|
||||
cycles_count += ((ppc_state.pc - bb_start_la) >> 2) + 1;
|
||||
UPDATE_TBR_DEC
|
||||
#else
|
||||
timebase_counter += ((ppc_state.pc - bb_start_la) >> 2) + 1;
|
||||
#endif
|
||||
glob_bb_start_la = bb_start_la = ppc_next_instruction_address;
|
||||
if ((ppc_next_instruction_address & 0xFFFFF000) != page_start) {
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
} else {
|
||||
pc_real += (int)bb_start_la - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
ppc_state.pc = bb_start_la;
|
||||
bb_kind = BB_end_kind::BB_NONE;
|
||||
//printf("DBG Exec: new basic block at %X, start_addr=%X\n", ppc_state.pc, start_addr);
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint64_t instr_count, old_instr_count;
|
||||
|
||||
|
||||
+17
-17
@@ -767,7 +767,7 @@ void dppc_interpreter::ppc_lfs() {
|
||||
|
||||
void dppc_interpreter::ppc_lfsu() {
|
||||
ppc_grab_regsfpdia(true);
|
||||
if (reg_a == 0) {
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += (reg_a > 0) ? ppc_result_a : 0;
|
||||
ppc_result64_d = mem_grab_dword(ppc_effective_address);
|
||||
@@ -775,7 +775,7 @@ void dppc_interpreter::ppc_lfsu() {
|
||||
ppc_store_dfpresult(true);
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -788,14 +788,14 @@ void dppc_interpreter::ppc_lfsx() {
|
||||
|
||||
void dppc_interpreter::ppc_lfsux() {
|
||||
ppc_grab_regsfpdiab(true);
|
||||
if (reg_a == 0) {
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = ppc_result_a + ppc_result_b;
|
||||
ppc_result64_d = mem_grab_dword(ppc_effective_address);
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_dfpresult(true);
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -809,7 +809,7 @@ void dppc_interpreter::ppc_lfd() {
|
||||
|
||||
void dppc_interpreter::ppc_lfdu() {
|
||||
ppc_grab_regsfpdia(true);
|
||||
if (reg_a == 0) {
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += ppc_result_a;
|
||||
ppc_result64_d = mem_grab_qword(ppc_effective_address);
|
||||
@@ -817,27 +817,27 @@ void dppc_interpreter::ppc_lfdu() {
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfdx() {
|
||||
ppc_grab_regsfpdia(true);
|
||||
ppc_effective_address += (reg_a > 0) ? ppc_result_a + ppc_result_b : ppc_result_b;
|
||||
ppc_effective_address = (reg_a > 0) ? ppc_result_a + ppc_result_b : ppc_result_b;
|
||||
ppc_result64_d = mem_grab_qword(ppc_effective_address);
|
||||
ppc_store_dfpresult(true);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfdux() {
|
||||
ppc_grab_regsfpdiab(true);
|
||||
if (reg_a == 0) {
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = ppc_result_a + ppc_result_b;
|
||||
ppc_result64_d = mem_grab_qword(ppc_effective_address);
|
||||
ppc_store_dfpresult(true);
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -850,14 +850,14 @@ void dppc_interpreter::ppc_stfs() {
|
||||
|
||||
void dppc_interpreter::ppc_stfsu() {
|
||||
ppc_grab_regsfpsia(true);
|
||||
if (reg_a == 0) {
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += ppc_result_a;
|
||||
mem_write_dword(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -869,13 +869,13 @@ void dppc_interpreter::ppc_stfsx() {
|
||||
|
||||
void dppc_interpreter::ppc_stfsux() {
|
||||
ppc_grab_regsfpsiab(true);
|
||||
if (reg_a == 0) {
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = ppc_result_a + ppc_result_b;
|
||||
mem_write_dword(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -888,14 +888,14 @@ void dppc_interpreter::ppc_stfd() {
|
||||
|
||||
void dppc_interpreter::ppc_stfdu() {
|
||||
ppc_grab_regsfpsia(true);
|
||||
if (reg_a == 0) {
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = (int32_t)((int16_t)(ppc_cur_instruction & 0xFFFF));
|
||||
ppc_effective_address += ppc_result_a;
|
||||
mem_write_qword(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -907,13 +907,13 @@ void dppc_interpreter::ppc_stfdx() {
|
||||
|
||||
void dppc_interpreter::ppc_stfdux() {
|
||||
ppc_grab_regsfpsiab(true);
|
||||
if (reg_a == 0) {
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = ppc_result_a + ppc_result_b;
|
||||
mem_write_qword(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+49
-9
@@ -55,6 +55,8 @@ AddressMapEntry last_ptab_area = {0xFFFFFFFF, 0xFFFFFFFF};
|
||||
AddressMapEntry last_dma_area = {0xFFFFFFFF, 0xFFFFFFFF};
|
||||
|
||||
|
||||
#define WRITE_BYTE(addr, val) (*(addr) = val)
|
||||
|
||||
/* macro for generating code reading from physical memory */
|
||||
#define READ_PHYS_MEM(ENTRY, ADDR, OP, SIZE, UNVAL) \
|
||||
{ \
|
||||
@@ -371,13 +373,32 @@ static uint32_t ppc_mmu_addr_translate(uint32_t la, int is_write) {
|
||||
}
|
||||
|
||||
static void mem_write_unaligned(uint32_t addr, uint32_t value, uint32_t size) {
|
||||
//LOG_F(WARNING, "Attempt to write unaligned %d bytes to 0x%08X\n", size, addr);
|
||||
#ifdef MMU_DEBUG
|
||||
LOG_F(WARNING, "Attempt to write unaligned %d bytes to 0x%08X\n", size, addr);
|
||||
#endif
|
||||
|
||||
if (((addr & 0xFFF) + size) > 0x1000) {
|
||||
LOG_F(ERROR, "SOS! Cross-page unaligned write, addr=%08X, size=%d\n", addr, size);
|
||||
exit(-1); // FIXME!
|
||||
// Special case: unaligned cross-page writes
|
||||
LOG_F(WARNING, "Cross-page unaligned write, addr=%08X, size=%d\n",
|
||||
addr, size);
|
||||
|
||||
uint32_t phys_addr;
|
||||
uint32_t shift = (size - 1) * 8;
|
||||
|
||||
// Break misaligned memory accesses into multiple, smaller accesses
|
||||
// and retranslate on page boundary.
|
||||
// Because such accesses suffer a performance penalty, they will be
|
||||
// presumably very rare so don't care much about performance.
|
||||
for (int i = 0; i < size; shift -= 8, addr++, phys_addr++, i++) {
|
||||
if ((ppc_state.msr & 0x10) && (!i || !(addr & 0xFFF))) {
|
||||
phys_addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
WRITE_PHYS_MEM(last_write_area, phys_addr, WRITE_BYTE,
|
||||
(value >> shift) & 0xFF, 1);
|
||||
}
|
||||
} else {
|
||||
/* data address translation if enabled */
|
||||
// data address translation if enabled
|
||||
if (ppc_state.msr & 0x10) {
|
||||
addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
@@ -396,8 +417,6 @@ void mem_write_byte(uint32_t addr, uint8_t value) {
|
||||
addr = ppc_mmu_addr_translate(addr, 1);
|
||||
}
|
||||
|
||||
#define WRITE_BYTE(addr, val) (*(addr) = val)
|
||||
|
||||
WRITE_PHYS_MEM(last_write_area, addr, WRITE_BYTE, value, 1);
|
||||
}
|
||||
|
||||
@@ -444,11 +463,32 @@ void mem_write_qword(uint32_t addr, uint64_t value) {
|
||||
static uint32_t mem_grab_unaligned(uint32_t addr, uint32_t size) {
|
||||
uint32_t ret = 0;
|
||||
|
||||
//LOG_F(WARNING, "Attempt to read unaligned %d bytes from 0x%08X\n", size, addr);
|
||||
#ifdef MMU_DEBUG
|
||||
LOG_F(WARNING, "Attempt to read unaligned %d bytes from 0x%08X\n", size, addr);
|
||||
#endif
|
||||
|
||||
if (((addr & 0xFFF) + size) > 0x1000) {
|
||||
LOG_F(ERROR, "SOS! Cross-page unaligned read, addr=%08X, size=%d\n", addr, size);
|
||||
exit(-1); // FIXME!
|
||||
// Special case: misaligned cross-page reads
|
||||
LOG_F(WARNING, "Cross-page unaligned read, addr=%08X, size=%d\n",
|
||||
addr, size);
|
||||
|
||||
uint32_t phys_addr;
|
||||
uint32_t res = 0;
|
||||
|
||||
// Break misaligned memory accesses into multiple, smaller accesses
|
||||
// and retranslate on page boundary.
|
||||
// Because such accesses suffer a performance penalty, they will be
|
||||
// presumably very rare so don't care much about performance.
|
||||
for (int i = 0; i < size; addr++, phys_addr++, i++) {
|
||||
if ((ppc_state.msr & 0x10) && (!i || !(addr & 0xFFF))) {
|
||||
phys_addr = ppc_mmu_addr_translate(addr, 0);
|
||||
}
|
||||
|
||||
READ_PHYS_MEM(last_read_area, phys_addr, *, 1, 0xFFU);
|
||||
res = (res << 8) | ret;
|
||||
}
|
||||
return res;
|
||||
|
||||
} else {
|
||||
/* data address translation if enabled */
|
||||
if (ppc_state.msr & 0x10) {
|
||||
|
||||
+34
-33
@@ -295,7 +295,7 @@ void dppc_interpreter::ppc_addze() {
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xDFFFFFFFUL;
|
||||
}
|
||||
|
||||
|
||||
if (oe_flag)
|
||||
ppc_setsoov(ppc_result_a, 0xFFFFFFFFUL, ppc_result_d);
|
||||
if (rc_flag)
|
||||
@@ -355,7 +355,7 @@ void dppc_interpreter::ppc_subfme() {
|
||||
uint32_t grab_xer = !!(ppc_state.spr[SPR::XER] & 0x20000000);
|
||||
ppc_result_d = ~ppc_result_a + grab_xer - 1;
|
||||
ppc_carry(~ppc_result_a, ppc_result_d);
|
||||
|
||||
|
||||
if (oe_flag)
|
||||
ppc_setsoov(0xFFFFFFFF, ppc_result_a, ppc_result_d);
|
||||
if (rc_flag)
|
||||
@@ -506,7 +506,7 @@ void dppc_interpreter::ppc_neg() {
|
||||
else
|
||||
ppc_state.spr[SPR::XER] &= 0xBFFFFFFF;
|
||||
}
|
||||
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
@@ -516,15 +516,16 @@ void dppc_interpreter::ppc_neg() {
|
||||
void dppc_interpreter::ppc_cntlzw() {
|
||||
ppc_grab_regssa();
|
||||
|
||||
uint32_t lead = 0;
|
||||
uint32_t bit_check = ppc_result_d;
|
||||
|
||||
#ifdef USE_GCC_BUILTINS
|
||||
lead = __builtin_clz(bit_check);
|
||||
uint32_t lead = !bit_check ? 32 : __builtin_clz(bit_check);
|
||||
#elif defined USE_VS_BUILTINS
|
||||
lead = __lzcnt(bit_check);
|
||||
uint32_t lead = __lzcnt(bit_check);
|
||||
#else
|
||||
for (uint32_t mask = 0x80000000UL; mask; lead++, mask >>= 1) {
|
||||
uint32_t lead, mask;
|
||||
|
||||
for (mask = 0x80000000UL, lead = 0; mask != 0; lead++, mask >>= 1) {
|
||||
if (bit_check & mask)
|
||||
break;
|
||||
}
|
||||
@@ -602,7 +603,7 @@ void dppc_interpreter::ppc_divw() {
|
||||
if (oe_flag)
|
||||
ppc_state.spr[SPR::XER] |= 0xC0000000;
|
||||
|
||||
}
|
||||
}
|
||||
else { /* normal signed devision */
|
||||
ppc_result_d = (int32_t)ppc_result_a / (int32_t)ppc_result_b;
|
||||
|
||||
@@ -811,7 +812,7 @@ void dppc_interpreter::ppc_mfmsr() {
|
||||
supervisor_inst_num++;
|
||||
#endif
|
||||
if (ppc_state.msr & 0x4000) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x00040000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
||||
}
|
||||
reg_d = (ppc_cur_instruction >> 21) & 31;
|
||||
ppc_state.gpr[reg_d] = ppc_state.msr;
|
||||
@@ -822,7 +823,7 @@ void dppc_interpreter::ppc_mtmsr() {
|
||||
supervisor_inst_num++;
|
||||
#endif
|
||||
if (ppc_state.msr & 0x4000) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x00040000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::NOT_ALLOWED);
|
||||
}
|
||||
reg_s = (ppc_cur_instruction >> 21) & 31;
|
||||
ppc_state.msr = ppc_state.gpr[reg_s];
|
||||
@@ -1288,12 +1289,12 @@ void dppc_interpreter::ppc_tw() {
|
||||
reg_a = (ppc_cur_instruction >> 11) & 31;
|
||||
reg_b = (ppc_cur_instruction >> 16) & 31;
|
||||
ppc_to = (ppc_cur_instruction >> 21) & 31;
|
||||
if ((((int32_t)ppc_state.gpr[reg_a] < (int32_t)ppc_state.gpr[reg_b]) && (ppc_to & 0x10)) ||
|
||||
(((int32_t)ppc_state.gpr[reg_a] > (int32_t)ppc_state.gpr[reg_b]) && (ppc_to & 0x08)) ||
|
||||
(((int32_t)ppc_state.gpr[reg_a] == (int32_t)ppc_state.gpr[reg_b]) && (ppc_to & 0x04)) ||
|
||||
((ppc_state.gpr[reg_a] < ppc_state.gpr[reg_b]) && (ppc_to & 0x02)) ||
|
||||
((ppc_state.gpr[reg_a] > ppc_state.gpr[reg_b]) && (ppc_to & 0x01))) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
if ((((int32_t)ppc_state.gpr[reg_a] < (int32_t)ppc_state.gpr[reg_b]) & (ppc_to & 0x10)) ||
|
||||
(((int32_t)ppc_state.gpr[reg_a] > (int32_t)ppc_state.gpr[reg_b]) & (ppc_to & 0x08)) ||
|
||||
(((int32_t)ppc_state.gpr[reg_a] == (int32_t)ppc_state.gpr[reg_b]) & (ppc_to & 0x04)) ||
|
||||
((ppc_state.gpr[reg_a] < ppc_state.gpr[reg_b]) & (ppc_to & 0x02)) ||
|
||||
((ppc_state.gpr[reg_a] > ppc_state.gpr[reg_b]) & (ppc_to & 0x01))) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::TRAP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1306,7 +1307,7 @@ void dppc_interpreter::ppc_twi() {
|
||||
(((int32_t)ppc_state.gpr[reg_a] == simm) && (ppc_to & 0x04)) ||
|
||||
((ppc_state.gpr[reg_a] < (uint32_t)simm) && (ppc_to & 0x02)) ||
|
||||
((ppc_state.gpr[reg_a] > (uint32_t)simm) && (ppc_to & 0x01))) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::TRAP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1390,7 +1391,7 @@ void dppc_interpreter::ppc_stbu() {
|
||||
mem_write_byte(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1401,7 +1402,7 @@ void dppc_interpreter::ppc_stbux() {
|
||||
mem_write_byte(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1420,7 +1421,7 @@ void dppc_interpreter::ppc_sthu() {
|
||||
mem_write_word(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1431,7 +1432,7 @@ void dppc_interpreter::ppc_sthux() {
|
||||
mem_write_word(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1463,7 +1464,7 @@ void dppc_interpreter::ppc_stwx() {
|
||||
void dppc_interpreter::ppc_stwcx() {
|
||||
// PLACEHOLDER CODE FOR STWCX - We need to check for reserve memory
|
||||
if (rc_flag == 0) {
|
||||
ppc_illegalsubop31();
|
||||
ppc_illegalop();
|
||||
} else {
|
||||
ppc_grab_regssab();
|
||||
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
||||
@@ -1485,7 +1486,7 @@ void dppc_interpreter::ppc_stwu() {
|
||||
mem_write_dword(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1496,7 +1497,7 @@ void dppc_interpreter::ppc_stwux() {
|
||||
mem_write_dword(ppc_effective_address, ppc_result_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1541,7 +1542,7 @@ void dppc_interpreter::ppc_lbzu() {
|
||||
ppc_store_result_regd();
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1561,7 +1562,7 @@ void dppc_interpreter::ppc_lbzux() {
|
||||
ppc_store_result_regd();
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1584,7 +1585,7 @@ void dppc_interpreter::ppc_lhzu() {
|
||||
ppc_store_result_regd();
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1604,7 +1605,7 @@ void dppc_interpreter::ppc_lhzux() {
|
||||
ppc_store_result_regd();
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1636,7 +1637,7 @@ void dppc_interpreter::ppc_lhau() {
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1698,7 +1699,7 @@ void dppc_interpreter::ppc_lwzu() {
|
||||
ppc_result_a = ppc_effective_address;
|
||||
ppc_store_result_rega();
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1714,7 +1715,7 @@ void dppc_interpreter::ppc_lwzux() {
|
||||
if ((reg_a != reg_d) || reg_a != 0) {
|
||||
ppc_effective_address = ppc_result_a + ppc_result_b;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x20000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
ppc_result_d = mem_grab_dword(ppc_effective_address);
|
||||
ppc_result_a = ppc_effective_address;
|
||||
@@ -1790,10 +1791,10 @@ void dppc_interpreter::ppc_lswx() {
|
||||
ppc_grab_regsdab();
|
||||
// Invalid instruction forms
|
||||
if ((ppc_result_d == 0) && (ppc_result_a == 0)) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x100000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
if ((ppc_result_d == ppc_result_a) || (ppc_result_a == ppc_result_b)) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x100000);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
ppc_effective_address = (reg_a == 0) ? ppc_result_b : (ppc_result_a + ppc_result_b);
|
||||
grab_inb = ppc_state.spr[SPR::XER] & 127;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/capstone/include")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
+221
-22
@@ -19,9 +19,6 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cpu/ppc/ppcdisasm.h"
|
||||
#include "../cpu/ppc/ppcemu.h"
|
||||
#include "../cpu/ppc/ppcmmu.h"
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
@@ -30,7 +27,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "../cpu/ppc/ppcdisasm.h"
|
||||
#include "../cpu/ppc/ppcemu.h"
|
||||
#include "../cpu/ppc/ppcmmu.h"
|
||||
#include "memreadwrite.h"
|
||||
|
||||
#ifdef ENABLE_68K_DEBUGGER // optionally defined in CMakeLists.txt
|
||||
#include <capstone/capstone.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -71,23 +75,153 @@ static void show_help() {
|
||||
cout << " disas N,X -- disassemble N instructions starting at address X" << endl;
|
||||
cout << " X can be any number or a known register name" << endl;
|
||||
cout << " disas with no arguments defaults to disas 1,pc" << endl;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
cout << " context X -- switch to the debugging context X." << endl;
|
||||
cout << " X can be either 'ppc' (default) or '68k'" << endl;
|
||||
cout << " Use 68k for debugging emulated 68k code only." << endl;
|
||||
#endif
|
||||
cout << " quit -- quit the debugger" << endl << endl;
|
||||
cout << "Pressing ENTER will repeat last command." << endl;
|
||||
}
|
||||
|
||||
static void disasm(uint32_t count, uint32_t address) {
|
||||
PPCDisasmContext ctx;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
|
||||
ctx.instr_addr = address;
|
||||
ctx.simplified = true;
|
||||
static void disasm_68k(uint32_t count, uint32_t address) {
|
||||
csh cs_handle;
|
||||
uint8_t code[10];
|
||||
size_t code_size;
|
||||
uint64_t dis_addr;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ctx.instr_code = mem_read_dbg(ctx.instr_addr, 4);
|
||||
cout << uppercase << hex << ctx.instr_addr;
|
||||
cout << " " << disassemble_single(&ctx) << endl;
|
||||
if (cs_open(CS_ARCH_M68K, CS_MODE_M68K_040, &cs_handle) != CS_ERR_OK) {
|
||||
cout << "Capstone initialization error" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
cs_insn* insn = cs_malloc(cs_handle);
|
||||
|
||||
for (; count > 0; count--) {
|
||||
/* prefetch opcode bytes (a 68k instruction can occupy 2...10 bytes) */
|
||||
for (int i = 0; i < sizeof(code); i++) {
|
||||
code[i] = mem_read_dbg(address + i, 1);
|
||||
}
|
||||
|
||||
const uint8_t *code_ptr = code;
|
||||
code_size = sizeof(code);
|
||||
dis_addr = address;
|
||||
|
||||
if (cs_disasm_iter(cs_handle, &code_ptr, &code_size, &dis_addr, insn)) {
|
||||
cout << uppercase << hex << insn->address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
|
||||
address = dis_addr;
|
||||
} else {
|
||||
cout << "DS.W " << hex << ((code[0] << 8) | code[1]) << endl;
|
||||
address += 2;
|
||||
}
|
||||
}
|
||||
|
||||
cs_free(insn, 1);
|
||||
cs_close(&cs_handle);
|
||||
}
|
||||
|
||||
/* emulator opcode table size --> 512 KB */
|
||||
#define EMU_68K_TABLE_SIZE 0x80000
|
||||
|
||||
/** Execute one emulated 68k instruction. */
|
||||
void exec_single_68k()
|
||||
{
|
||||
string reg;
|
||||
uint32_t emu_table_virt, cur_68k_pc, cur_instr_tab_entry, ppc_pc;
|
||||
|
||||
/* PPC r24 contains 68k PC advanced by two bytes
|
||||
as part of instruction prefetching */
|
||||
reg = "R24";
|
||||
cur_68k_pc = get_reg(reg) - 2;
|
||||
|
||||
/* PPC r29 contains base address of the emulator opcode table */
|
||||
reg = "R29";
|
||||
emu_table_virt = get_reg(reg) & 0xFFF80000;
|
||||
|
||||
/* calculate address of the current opcode table entry as follows:
|
||||
get_word(68k_PC) * entry_size + table_base */
|
||||
cur_instr_tab_entry = mem_grab_word(cur_68k_pc) * 8 + emu_table_virt;
|
||||
|
||||
/* grab the PPC PC too */
|
||||
reg = "PC";
|
||||
ppc_pc = get_reg(reg);
|
||||
|
||||
//printf("cur_instr_tab_entry = %X\n", cur_instr_tab_entry);
|
||||
|
||||
/* because the first two PPC instructions for each emulated 68k once
|
||||
are resided in the emulator opcode table, we need to execute them
|
||||
one by one until the execution goes outside the opcode table. */
|
||||
while (ppc_pc >= cur_instr_tab_entry && ppc_pc < cur_instr_tab_entry + 8) {
|
||||
ppc_exec_single();
|
||||
reg = "PC";
|
||||
ppc_pc = get_reg(reg);
|
||||
LOG_F(9, "Tracing within emulator table, PC = %X\n", ppc_pc);
|
||||
}
|
||||
|
||||
/* Getting here means we're outside the emualtor opcode table.
|
||||
Execute PPC code until we hit the opcode table again. */
|
||||
LOG_F(9, "Tracing outside the emulator table, PC = %X\n", ppc_pc);
|
||||
ppc_exec_dbg(emu_table_virt, EMU_68K_TABLE_SIZE - 1);
|
||||
}
|
||||
|
||||
/** Execute emulated 68k code until target_addr is reached. */
|
||||
void exec_until_68k(uint32_t target_addr)
|
||||
{
|
||||
string reg;
|
||||
uint32_t emu_table_virt, ppc_pc;
|
||||
|
||||
reg = "R29";
|
||||
emu_table_virt = get_reg(reg) & 0xFFF80000;
|
||||
|
||||
reg = "R24";
|
||||
while (target_addr != (get_reg(reg) - 2)) {
|
||||
reg = "PC";
|
||||
ppc_pc = get_reg(reg);
|
||||
|
||||
if (ppc_pc >= emu_table_virt && ppc_pc < (emu_table_virt + EMU_68K_TABLE_SIZE - 1)) {
|
||||
LOG_F(9, "Tracing within emulator table, PC = %X\n", ppc_pc);
|
||||
ppc_exec_single();
|
||||
} else {
|
||||
LOG_F(9, "Tracing outside the emulator table, PC = %X\n", ppc_pc);
|
||||
ppc_exec_dbg(emu_table_virt, EMU_68K_TABLE_SIZE - 1);
|
||||
}
|
||||
reg = "R24";
|
||||
}
|
||||
}
|
||||
|
||||
void print_68k_regs()
|
||||
{
|
||||
int i;
|
||||
string reg;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
reg = "R" + to_string(i + 8);
|
||||
cout << "D" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
|
||||
}
|
||||
|
||||
for (i = 0; i < 7; i++) {
|
||||
reg = "R" + to_string(i + 16);
|
||||
cout << "A" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
|
||||
}
|
||||
reg = "R1";
|
||||
cout << "A7 : " << uppercase << hex << get_reg(reg) << endl;
|
||||
|
||||
reg = "R24";
|
||||
cout << "PC: " << uppercase << hex << get_reg(reg) - 2 << endl;
|
||||
|
||||
reg = "R25";
|
||||
cout << "SR: " << uppercase << hex << ((get_reg(reg) & 0xFF) << 8) << endl;
|
||||
|
||||
reg = "R26";
|
||||
cout << "CCR: " << uppercase << hex << get_reg(reg) << endl;
|
||||
}
|
||||
|
||||
#endif // ENABLE_68K_DEBUGGER
|
||||
|
||||
static void dump_mem(string& params) {
|
||||
int cell_size, chars_per_line;
|
||||
bool is_char;
|
||||
@@ -169,7 +303,8 @@ static void dump_mem(string& params) {
|
||||
cout << (char)val;
|
||||
chars_per_line += cell_size;
|
||||
} else {
|
||||
cout << setw(cell_size * 2) << setfill('0') << uppercase << hex << val << " ";
|
||||
cout << setw(cell_size * 2) << setfill('0') << right;
|
||||
cout << uppercase << hex << val << " ";
|
||||
chars_per_line += cell_size * 2 + 2;
|
||||
}
|
||||
}
|
||||
@@ -181,18 +316,33 @@ static void dump_mem(string& params) {
|
||||
cout << endl << endl;
|
||||
}
|
||||
|
||||
static void disasm(uint32_t count, uint32_t address) {
|
||||
PPCDisasmContext ctx;
|
||||
|
||||
ctx.instr_addr = address;
|
||||
ctx.simplified = true;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ctx.instr_code = READ_DWORD_BE_A(quickinstruction_translate(ctx.instr_addr));
|
||||
cout << uppercase << hex << ctx.instr_addr;
|
||||
cout << " " << disassemble_single(&ctx) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void enter_debugger() {
|
||||
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str, inst_string, inst_num_str;
|
||||
uint32_t addr, inst_grab;
|
||||
std::stringstream ss;
|
||||
int log_level;
|
||||
int log_level, context;
|
||||
size_t separator_pos;
|
||||
|
||||
context = 1; /* start with the PowerPC context */
|
||||
|
||||
cout << "Welcome to the DingusPPC command line debugger." << endl;
|
||||
cout << "Please enter a command or 'help'." << endl << endl;
|
||||
|
||||
while (1) {
|
||||
cout << "ppcdbg> ";
|
||||
cout << "dingusdbg> ";
|
||||
|
||||
/* reset string stream */
|
||||
ss.str("");
|
||||
@@ -220,7 +370,13 @@ void enter_debugger() {
|
||||
}
|
||||
#endif
|
||||
else if (cmd == "regs") {
|
||||
print_gprs();
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
print_68k_regs();
|
||||
#endif
|
||||
} else {
|
||||
print_gprs();
|
||||
}
|
||||
} else if (cmd == "set") {
|
||||
ss >> expr_str;
|
||||
|
||||
@@ -248,7 +404,13 @@ void enter_debugger() {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else if (cmd == "step" || cmd == "si") {
|
||||
ppc_exec_single();
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
exec_single_68k();
|
||||
#endif
|
||||
} else {
|
||||
ppc_exec_single();
|
||||
}
|
||||
} else if (cmd == "next" || cmd == "ni") {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str) + 4;
|
||||
@@ -257,7 +419,13 @@ void enter_debugger() {
|
||||
ss >> addr_str;
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
ppc_exec_until(addr);
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
exec_until_68k(addr);
|
||||
#endif
|
||||
} else {
|
||||
ppc_exec_until(addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
@@ -278,27 +446,58 @@ void enter_debugger() {
|
||||
} catch (invalid_argument& exc) {
|
||||
try {
|
||||
/* number conversion failed, trying reg name */
|
||||
addr = get_reg(addr_str);
|
||||
if (context == 2 && (addr_str == "pc" || addr_str == "PC")) {
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str) - 2;
|
||||
} else {
|
||||
addr = get_reg(addr_str);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
disasm(inst_grab, addr);
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
disasm_68k(inst_grab, addr);
|
||||
#endif
|
||||
} else {
|
||||
disasm(inst_grab, addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else {
|
||||
/* disas without arguments defaults to disas 1,pc */
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str);
|
||||
disasm(1, addr);
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str);
|
||||
disasm_68k(1, addr - 2);
|
||||
#endif
|
||||
} else {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str);
|
||||
disasm(1, addr);
|
||||
}
|
||||
}
|
||||
} else if (cmd == "dump") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
dump_mem(expr_str);
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
} else if (cmd == "context") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str == "ppc" || expr_str == "PPC") {
|
||||
context = 1;
|
||||
} else if (expr_str == "68k" || expr_str == "68K") {
|
||||
context = 2;
|
||||
} else {
|
||||
cout << "Unknown debugging context: " << expr_str << endl;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
cout << "Unknown command: " << cmd << endl;
|
||||
continue;
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(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/>.
|
||||
*/
|
||||
|
||||
/** Highspeed Memory Controller emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include "hmc.h"
|
||||
|
||||
HMC::HMC() : MemCtrlBase()
|
||||
{
|
||||
this->name = "Highspeed Memory Controller";
|
||||
|
||||
/* add memory mapped I/O region for the HMC control register */
|
||||
add_mmio_region(0x50F40000, 0xFFFF, this);
|
||||
|
||||
this->config_reg = 0ULL;
|
||||
this->bit_pos = 0;
|
||||
}
|
||||
|
||||
bool HMC::supports_type(HWCompType type) {
|
||||
if (type == HWCompType::MEM_CTRL || type == HWCompType::MMIO_DEV) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HMC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
if (!offset)
|
||||
return !!(this->config_reg & (1ULL << this->bit_pos++));
|
||||
else
|
||||
return 0; /* FIXME: what should be returned for invalid offsets? */
|
||||
}
|
||||
|
||||
void HMC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
uint64_t bit;
|
||||
|
||||
switch(offset) {
|
||||
case 0:
|
||||
bit = 1ULL << this->bit_pos++;
|
||||
this->config_reg = (value & 1) ? this->config_reg | bit :
|
||||
this->config_reg & ~bit;
|
||||
break;
|
||||
case 8: /* writing to HMCBase + 8 resets internal bit position */
|
||||
this->bit_pos = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(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/>.
|
||||
*/
|
||||
|
||||
/** Highspeed Memory Controller emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
|
||||
Highspeed Memory Controller (HMC) is a custom memory
|
||||
and L2 cache controller designed especially for the
|
||||
first generation of the PowerMacintosh computer.
|
||||
*/
|
||||
|
||||
#ifndef HMC_H
|
||||
#define HMC_H
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "mmiodevice.h"
|
||||
|
||||
class HMC : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
HMC();
|
||||
~HMC() = default;
|
||||
|
||||
bool supports_type(HWCompType type);
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
private:
|
||||
int bit_pos;
|
||||
uint64_t config_reg;
|
||||
};
|
||||
|
||||
#endif // HMC_H
|
||||
@@ -90,7 +90,7 @@ bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
||||
return false;
|
||||
|
||||
entry.start = start_addr;
|
||||
entry.end = start_addr + (ref_entry->end - ref_entry->start) + 1;
|
||||
entry.end = start_addr + (ref_entry->end - ref_entry->start);
|
||||
entry.mirror = dest_addr;
|
||||
entry.type = ref_entry->type | RT_MIRROR;
|
||||
entry.devobj = 0;
|
||||
|
||||
@@ -26,7 +26,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "viacuda.h"
|
||||
#include "adb.h"
|
||||
//#include "cpu/ppc/ppcemu.h"
|
||||
#include <cinttypes>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
@@ -352,7 +351,6 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Cuda: unsupported pseudo command 0x%x \n", cmd);
|
||||
//LOG_F(ERROR, "Cuda: unsupported pseudo command 0x%x - Address: 0x%x \n", cmd, ppc_state.pc);
|
||||
error_response(CUDA_ERR_BAD_CMD);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
@@ -77,6 +78,13 @@ static const PropMap GossamerSettings = {
|
||||
new IntProperty( 2, vector<uint32_t>({2, 4, 6}))},
|
||||
};
|
||||
|
||||
static const PropMap PDMSettings = {
|
||||
{"rambank1_size",
|
||||
new IntProperty(0, vector<uint32_t>({0, 8, 16, 32, 64, 128}))},
|
||||
{"rambank2_size",
|
||||
new IntProperty(0, vector<uint32_t>({0, 8, 16, 32, 64, 128}))},
|
||||
};
|
||||
|
||||
static const map<string, string> PropHelp = {
|
||||
{"rambank1_size", "specifies RAM bank 1 size in MB"},
|
||||
{"rambank2_size", "specifies RAM bank 2 size in MB"},
|
||||
@@ -84,8 +92,9 @@ static const map<string, string> PropHelp = {
|
||||
{"gfxmem_size", "specifies video memory size in MB"},
|
||||
};
|
||||
|
||||
static const map<string, tuple<PropMap, function<int(void)>, string>> machines = {
|
||||
{"pmg3", {GossamerSettings, create_gossamer, "Power Macintosh G3 (Beige)"}},
|
||||
static const map<string, tuple<PropMap, function<int(string&)>, string>> machines = {
|
||||
{"pm6100", {PDMSettings, create_pdm, "PowerMacintosh 6100"}},
|
||||
{"pmg3", {GossamerSettings, create_gossamer, "Power Macintosh G3 (Beige)"}},
|
||||
};
|
||||
|
||||
string machine_name_from_rom(string& rom_filepath) {
|
||||
@@ -268,7 +277,7 @@ int create_machine_for_id(string& id, string& rom_filepath) {
|
||||
auto machine = machines.at(id);
|
||||
|
||||
/* build machine and load boot ROM */
|
||||
if (get<1>(machine)() < 0 || load_boot_rom(rom_filepath) < 0) {
|
||||
if (get<1>(machine)(id) < 0 || load_boot_rom(rom_filepath) < 0) {
|
||||
return -1;
|
||||
}
|
||||
} catch(out_of_range ex) {
|
||||
|
||||
@@ -42,6 +42,7 @@ void list_machines(void);
|
||||
void list_properties(void);
|
||||
|
||||
/* Machine-specific factory functions. */
|
||||
int create_gossamer(void);
|
||||
int create_gossamer(string& id);
|
||||
int create_pdm(string& id);
|
||||
|
||||
#endif /* MACHINE_FACTORY_H */
|
||||
@@ -35,6 +35,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include "machinebase.h"
|
||||
#include "machineproperties.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <string>
|
||||
|
||||
|
||||
static void setup_ram_slot(std::string name, int i2c_addr, int capacity_megs) {
|
||||
@@ -51,7 +52,7 @@ static void setup_ram_slot(std::string name, int i2c_addr, int capacity_megs) {
|
||||
}
|
||||
|
||||
|
||||
int create_gossamer() {
|
||||
int create_gossamer(std::string& id) {
|
||||
if (gMachineObj) {
|
||||
LOG_F(ERROR, "Global machine object not empty!");
|
||||
return -1;
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(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/>.
|
||||
*/
|
||||
|
||||
/** @file Construct a PDM-style PowerMacintosh machine.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include "cpu/ppc/ppcemu.h"
|
||||
#include "devices/hmc.h"
|
||||
#include "machinebase.h"
|
||||
#include "machineproperties.h"
|
||||
#include <string>
|
||||
|
||||
int create_pdm(std::string& id) {
|
||||
if (gMachineObj) {
|
||||
LOG_F(ERROR, "PDM Factory: global machine object not empty!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Initializing the %s hardware...", id.c_str());
|
||||
|
||||
/* initialize the global machine object */
|
||||
gMachineObj.reset(new MachineBase("PDM"));
|
||||
|
||||
/* register HMC memory controller */
|
||||
gMachineObj->add_component("HMC", new HMC);
|
||||
|
||||
/* get raw pointer to HMC object */
|
||||
HMC* hmc_obj = dynamic_cast<HMC*>(gMachineObj->get_comp_by_name("HMC"));
|
||||
|
||||
/* allocate ROM region */
|
||||
if (!hmc_obj->add_rom_region(0x40000000, 0x400000)) {
|
||||
LOG_F(ERROR, "Could not allocate ROM region!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* mirror ROM to 0xFFC00000 for a PowerPC CPU to start */
|
||||
if (!hmc_obj->add_mem_mirror(0xFFC00000, 0x40000000)) {
|
||||
LOG_F(ERROR, "Could not create ROM mirror!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* add 8MB of soldered on-board RAM */
|
||||
if (!hmc_obj->add_ram_region(0x00000000, 0x800000)) {
|
||||
LOG_F(ERROR, "Could not allocate built-in RAM region!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Init virtual CPU and request MPC601 */
|
||||
ppc_cpu_init(hmc_obj, PPC_VER::MPC601);
|
||||
|
||||
LOG_F(INFO, "Initialization completed.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
+1
Submodule thirdparty/capstone added at bfb2e45d76.
Reference in new issue
Block a user