mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cae2a12b71 | ||
|
|
6356e5b4f9 | ||
|
|
ba20fc43b9 | ||
|
|
922c4abf5f | ||
|
|
00d8c64fc6 | ||
|
|
eb338ea886 | ||
|
|
95fb5d053d | ||
|
|
cc56e391bd | ||
|
|
d659253f91 |
No files matched your search
@@ -1,7 +1,3 @@
|
||||
[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
|
||||
+30
-93
@@ -16,50 +16,11 @@ if (UNIX AND NOT APPLE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(DPPC_BUILD_PPC_TESTS "Build PowerPC tests" OFF)
|
||||
option(DPPC_BUILD_BENCHMARKS "Build benchmarking programs" OFF)
|
||||
|
||||
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/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/execution")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/machines/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/utils/")
|
||||
add_subdirectory("${PROJECT_SOURCE_DIR}/thirdparty/loguru/")
|
||||
|
||||
#set(BUILD_EXAMPLE_PROGRAMS OFF CACHE BOOL "Build libsoundio example programs")
|
||||
@@ -80,7 +41,6 @@ set(CLI11_ROOT ${PROJECT_SOURCE_DIR}/thirdparty/CLI11)
|
||||
include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/devices"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc"
|
||||
"${PROJECT_SOURCE_DIR}/debugger"
|
||||
"${PROJECT_SOURCE_DIR}/utils"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/loguru/"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/")
|
||||
# "${PROJECT_SOURCE_DIR}/thirdparty/cubeb/include")
|
||||
@@ -100,7 +60,6 @@ add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
@@ -113,60 +72,38 @@ 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)
|
||||
|
||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(testppc "${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
|
||||
cubeb)
|
||||
else()
|
||||
#target_link_libraries(testppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
|
||||
target_link_libraries(testppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_PPC_TESTS)
|
||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
|
||||
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(testppc
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
|
||||
cubeb)
|
||||
else()
|
||||
#target_link_libraries(testppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
|
||||
target_link_libraries(testppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS}
|
||||
${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
target_link_libraries(bench1 cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
target_link_libraries(testppc capstone-static)
|
||||
endif()
|
||||
endif()
|
||||
add_custom_command(
|
||||
TARGET testppc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcinttests.csv"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcdisasmtest.csv"
|
||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
|
||||
|
||||
if (DPPC_BUILD_BENCHMARKS)
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
|
||||
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
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()
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_PPC_TESTS)
|
||||
add_custom_command(
|
||||
TARGET testppc POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcinttests.csv"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/test/ppcdisasmtest.csv"
|
||||
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
|
||||
endif()
|
||||
|
||||
install (TARGETS dingusppc DESTINATION ${PROJECT_SOURCE_DIR}/build)
|
||||
install (TARGETS dingusppc DESTINATION ${EXECUTABLE_OUTPUT_PATH})
|
||||
@@ -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 Power Macintosh G3 Beige is implemented.
|
||||
As of now, only the Beige G3 is implemented.
|
||||
|
||||
## How to Compile
|
||||
|
||||
You need to install development tools first.
|
||||
|
||||
At least, a C++11 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
At least, a C++ compiler and [CMake](https://cmake.org) are required.
|
||||
|
||||
You will also have to recursive clone or run
|
||||
```
|
||||
git submodule update --init --recursive
|
||||
git submodules --update
|
||||
```
|
||||
|
||||
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,11 +71,6 @@ 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
|
||||
|
||||
+41
-9
@@ -3,6 +3,8 @@
|
||||
#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[] = {
|
||||
@@ -17,6 +19,14 @@ 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;
|
||||
@@ -38,6 +48,8 @@ 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 */
|
||||
@@ -51,16 +63,22 @@ int main(int argc, char** argv) {
|
||||
mem_write_byte(0x1000+i, rand() % 256);
|
||||
}
|
||||
|
||||
/* 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
|
||||
setup_regs();
|
||||
|
||||
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();
|
||||
@@ -68,10 +86,7 @@ int main(int argc, char** argv) {
|
||||
LOG_F(INFO, "Time elapsed (dry run): %lld ns", time_elapsed.count());
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = 0x8000; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
setup_regs();
|
||||
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
@@ -85,6 +100,23 @@ 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;
|
||||
|
||||
@@ -0,0 +1,420 @@
|
||||
#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
@@ -0,0 +1,185 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#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 */
|
||||
@@ -0,0 +1,272 @@
|
||||
#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)
|
||||
@@ -0,0 +1,38 @@
|
||||
#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
|
||||
@@ -148,26 +148,22 @@ void dppc_interpreter::power_lscbx() {
|
||||
if (match_found == false) {
|
||||
switch (shift_amount) {
|
||||
case 0:
|
||||
return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
//return_value = mem_grab_byte(ppc_effective_address);
|
||||
return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & 0x00FFFFFF) | (return_value << 24);
|
||||
ppc_store_result_regd();
|
||||
break;
|
||||
case 1:
|
||||
return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
//return_value = mem_grab_byte(ppc_effective_address);
|
||||
return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & 0xFF00FFFF) | (return_value << 16);
|
||||
ppc_store_result_regd();
|
||||
break;
|
||||
case 2:
|
||||
return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
//return_value = mem_grab_byte(ppc_effective_address);
|
||||
return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & 0xFFFF00FF) | (return_value << 8);
|
||||
ppc_store_result_regd();
|
||||
break;
|
||||
case 3:
|
||||
return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
//return_value = mem_grab_byte(ppc_effective_address);
|
||||
return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & 0xFFFFFF00) | return_value;
|
||||
ppc_store_result_regd();
|
||||
break;
|
||||
@@ -498,4 +494,4 @@ void dppc_interpreter::power_srlq() {
|
||||
|
||||
void dppc_interpreter::power_srq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for srq!!! \n");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
#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 */
|
||||
+37
-75
@@ -209,8 +209,8 @@ const char* opc_flt_ldst[8] = {/* integer load and store instructions */
|
||||
"lfdu",
|
||||
"stfs",
|
||||
"stfsu",
|
||||
"stfd",
|
||||
"stfdu"};
|
||||
"sftd",
|
||||
"sftdu"};
|
||||
|
||||
const char* opc_flt_ext_arith[32] = {
|
||||
/* integer load and store instructions */
|
||||
@@ -347,10 +347,10 @@ void opc_ar_im(PPCDisasmContext* ctx) {
|
||||
int32_t imm = SIGNEXT(ctx->instr_code & 0xFFFF, 15);
|
||||
|
||||
if (ctx->simplified) {
|
||||
if (((ctx->instr_code >> 26) == 0xE) && !ra) {
|
||||
if (((ctx->instr_code >> 26) == 0xE) & !ra) {
|
||||
fmt_twoop_simm(ctx->instr_str, "li", rd, imm);
|
||||
return;
|
||||
} else if (((ctx->instr_code >> 26) == 0xF) && !ra) {
|
||||
} else if (((ctx->instr_code >> 26) == 0xF) & !ra) {
|
||||
fmt_twoop_simm(ctx->instr_str, "lis", rd, imm);
|
||||
return;
|
||||
}
|
||||
@@ -954,12 +954,12 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
} else if (index == 11) { /* tlbia */
|
||||
ctx->instr_str = my_sprintf("%-8s", "tlbia");
|
||||
} else if (index == 30) { /* tlbld - 603 only */
|
||||
if (!rs && !ra)
|
||||
if (!rs & !ra)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sr%s", "tlbld", rb);
|
||||
} else if (index == 30) { /* tlbli - 603 only */
|
||||
if (!rs && !ra)
|
||||
if (!rs & !ra)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sr%s", "tlbli", rb);
|
||||
@@ -973,10 +973,10 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
strcat(opcode, ".");
|
||||
|
||||
|
||||
if ((index == 0) || (index == 4) || (index == 6) || (index == 16) || (index == 20) ||
|
||||
(index == 22) || (index == 24) || (index == 28)) {
|
||||
if ((index == 0) | (index == 4) | (index == 6) | (index == 16) | (index == 20) |
|
||||
(index == 22) | (index == 24) | (index == 28)) {
|
||||
fmt_threeop(ctx->instr_str, opcode, ra, rs, rb);
|
||||
} else if ((index == 5) || (index == 7) || (index == 21) || (index == 23) || (index == 25) || (index == 29)) {
|
||||
} else if ((index == 5) | (index == 7) | (index == 21) | (index == 23) | (index == 25) | (index == 29)) {
|
||||
fmt_threeop_simm(ctx->instr_str, opcode, ra, rs, rb);
|
||||
} else {
|
||||
opc_illegal(ctx);
|
||||
@@ -990,7 +990,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((index == 4) || (index == 6) || (index == 16) || (index == 20) || (index == 22) ||
|
||||
if ((index == 4) | (index == 6) | (index == 16) | (index == 20) | (index == 22) |
|
||||
(index == 28)) {
|
||||
fmt_threeop(ctx->instr_str, opcode, ra, rs, rb);
|
||||
} else {
|
||||
@@ -1077,7 +1077,7 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
}
|
||||
}
|
||||
/* eciwx, ecowx, lhbrx, lwbrx, stwbrx, sthbrx */
|
||||
else if ((index == 9) || (index == 13) || (index == 16) || (index == 20) || (index == 24) || (index == 28)) {
|
||||
else if ((index == 9) | (index == 13) | (index == 16) | (index == 20) | (index == 24) | (index == 28)) {
|
||||
if (rc_set) {
|
||||
opc_illegal(ctx);
|
||||
return;
|
||||
@@ -1088,15 +1088,15 @@ void opc_group31(PPCDisasmContext* ctx) {
|
||||
fmt_threeop(ctx->instr_str, opcode, rs, ra, rb);
|
||||
return;
|
||||
}
|
||||
} else if ((index == 18) || (index == 26)) { /* sync, eieio */
|
||||
} else if ((index == 18) | (index == 26)) { /* sync, eieio */
|
||||
ctx->instr_str = my_sprintf("%-8s", opcode);
|
||||
return;
|
||||
}
|
||||
/* dcba, dcbf, dcbi, dcbst, dcbt, dcbz, icbi */
|
||||
else if (
|
||||
(index == 1) || (index == 2) || (index == 7) || (index == 8) || (index == 14) ||
|
||||
(index == 23) || (index == 30) || (index == 31)) {
|
||||
if (rc_set || (rs != 0)) {
|
||||
(index == 1) | (index == 2) | (index == 7) | (index == 8) | (index == 14) |
|
||||
(index == 23) | (index == 30) | (index == 31)) {
|
||||
if (rc_set | (rs != 0)) {
|
||||
opc_illegal(ctx);
|
||||
return;
|
||||
} else {
|
||||
@@ -1449,7 +1449,7 @@ void opc_group59(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((rc != 0) || (ra != 0))
|
||||
if ((rc != 0) | (ra != 0))
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
fmt_twoop_flt(ctx->instr_str, "fsqrts", rs, rb);
|
||||
@@ -1462,7 +1462,7 @@ void opc_group59(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((rc != 0) || (ra != 0))
|
||||
if ((rc != 0) | (ra != 0))
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
fmt_twoop_flt(ctx->instr_str, opcode, rs, rb);
|
||||
@@ -1590,7 +1590,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((rc != 0) || (ra != 0))
|
||||
if ((rc != 0) | (ra != 0))
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
fmt_threeop_flt(ctx->instr_str, opcode, rs, ra, rb);
|
||||
@@ -1627,7 +1627,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((rc != 0) || (ra != 0))
|
||||
if ((rc != 0) | (ra != 0))
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
@@ -1687,32 +1687,20 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
case 12: /* frsp */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
strcpy(opcode, "frsp");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, r%d", "frsp", rs, rb);
|
||||
break;
|
||||
case 14: /* fctiw */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
strcpy(opcode, "fctiw");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, r%d", "fctiw", rs, rb);
|
||||
break;
|
||||
case 15: /* fctiwz */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
strcpy(opcode, "fctiwz");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, r%d", "fctiwz", rs, rb);
|
||||
break;
|
||||
case 32: /* fcmpo */
|
||||
if (rs & 3)
|
||||
@@ -1737,7 +1725,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", opcode, rs, rb);
|
||||
break;
|
||||
case 64:
|
||||
strcpy(opcode, "mcrfs");
|
||||
@@ -1750,52 +1738,31 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-8scrb%d", opcode, rs);
|
||||
break;
|
||||
case 72: /* fmr */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
strcpy(opcode, "fmr");
|
||||
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", "fmr", rs, rb);
|
||||
break;
|
||||
case 134: /* mtfsfi */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
strcpy(opcode, "mtfsfi");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, %d", opcode, (rs >> 2), (rb >> 1));
|
||||
}
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, r%d", "mtfsfi", (rs >> 2), (rb >> 1));
|
||||
break;
|
||||
case 136: /* fnabs */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
strcpy(opcode, "fnabs");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", "fnabs", rs, rb);
|
||||
break;
|
||||
case 264: /* fabs */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else {
|
||||
strcpy(opcode, "fabs");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, f%d, f%d", "fabs", rs, rb);
|
||||
break;
|
||||
case 583: /* mffs */
|
||||
strcpy(opcode, "mffs");
|
||||
@@ -1803,18 +1770,13 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
if ((ra != 0) || (rb != 0))
|
||||
if ((ra != 0) | (rb != 0))
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sf%d", opcode, rs);
|
||||
break;
|
||||
case 711: /* mtfsf */
|
||||
strcpy(opcode, "mtfsf");
|
||||
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d, f%d", opcode, fm, rb);
|
||||
ctx->instr_str = my_sprintf("%-8sfm%d, r%d", "mtfsf", fm, rb);
|
||||
break;
|
||||
default:
|
||||
opc_illegal(ctx);
|
||||
|
||||
+25
-29
@@ -25,7 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include "devices/memctrlbase.h"
|
||||
#include "endianswap.h"
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <setjmp.h>
|
||||
#include <string>
|
||||
|
||||
@@ -36,13 +35,11 @@ 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
|
||||
|
||||
//#define CPU_PROFILING // enable CPU profiling
|
||||
|
||||
enum endian_switch { big_end = 0, little_end = 1 };
|
||||
|
||||
typedef void (*PPCOpcode)(void);
|
||||
@@ -156,6 +153,9 @@ extern int32_t simult_result;
|
||||
extern uint32_t uiadd_result;
|
||||
extern uint32_t uimult_result;
|
||||
|
||||
extern int32_t word_copy_location;
|
||||
extern uint32_t strwrd_replace_value;
|
||||
|
||||
extern uint32_t crf_d;
|
||||
extern uint32_t crf_s;
|
||||
extern uint32_t reg_s;
|
||||
@@ -215,14 +215,6 @@ 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,22 +238,21 @@ extern uint32_t ppc_effective_address;
|
||||
extern uint32_t ppc_next_instruction_address;
|
||||
|
||||
// Profiling Stats
|
||||
#ifdef CPU_PROFILING
|
||||
extern uint64_t num_executed_instrs;
|
||||
extern uint64_t num_supervisor_instrs;
|
||||
extern uint64_t num_int_loads;
|
||||
extern uint64_t num_int_stores;
|
||||
extern uint64_t exceptions_processed;
|
||||
#endif
|
||||
extern uint32_t mmu_translations_num;
|
||||
extern uint32_t exceptions_performed;
|
||||
extern uint32_t supervisor_inst_num;
|
||||
|
||||
// Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version);
|
||||
extern void ppc_mmu_init();
|
||||
|
||||
[[noreturn]] void ppc_illegalop();
|
||||
[[noreturn]] void ppc_fpu_off();
|
||||
void ppc_illegalop();
|
||||
void ppc_illegalsubop19();
|
||||
void ppc_illegalsubop31();
|
||||
void ppc_illegalsubop59();
|
||||
void ppc_illegalsubop63();
|
||||
|
||||
//void ppc_opcode4();
|
||||
void ppc_opcode4();
|
||||
void ppc_opcode16();
|
||||
void ppc_opcode18();
|
||||
void ppc_opcode19();
|
||||
@@ -289,8 +280,17 @@ extern void ppc_grab_regsdauimm();
|
||||
extern void ppc_grab_regsasimm();
|
||||
extern void ppc_grab_regssauimm();
|
||||
|
||||
extern void ppc_grab_regsfpdb(bool int_rep);
|
||||
extern void ppc_grab_regsfpdab(bool int_rep);
|
||||
extern void ppc_grab_regsfpdia(bool int_rep);
|
||||
extern void ppc_grab_regsfpdiab(bool int_rep);
|
||||
extern void ppc_grab_regsfpsia(bool int_rep);
|
||||
extern void ppc_grab_regsfpsiab(bool int_rep);
|
||||
|
||||
extern void ppc_store_result_regd();
|
||||
extern void ppc_store_result_rega();
|
||||
extern void ppc_store_sfpresult(bool int_rep);
|
||||
extern void ppc_store_dfpresult(bool int_rep);
|
||||
|
||||
void ppc_changecrf0(uint32_t set_result);
|
||||
void ppc_fp_changecrf1();
|
||||
@@ -302,9 +302,6 @@ void ppc_fp_changecrf1();
|
||||
// MEMORY DECLARATIONS
|
||||
extern MemCtrlBase* mem_ctrl_instance;
|
||||
|
||||
//typedef std::function<void()> CtxSyncCallback;
|
||||
extern void add_ctx_sync_action(const std::function<void()> &);
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
namespace dppc_interpreter {
|
||||
extern void ppc_bcctr();
|
||||
@@ -404,7 +401,6 @@ extern void ppc_mfsrin();
|
||||
extern void ppc_mtsr();
|
||||
extern void ppc_mtsrin();
|
||||
|
||||
extern void ppc_mcrf();
|
||||
extern void ppc_mtcrf();
|
||||
extern void ppc_mfmsr();
|
||||
extern void ppc_mfspr();
|
||||
@@ -488,11 +484,11 @@ extern void ppc_stfdux();
|
||||
|
||||
extern void ppc_fadd();
|
||||
extern void ppc_fsub();
|
||||
extern void ppc_fmul();
|
||||
extern void ppc_fmult();
|
||||
extern void ppc_fdiv();
|
||||
extern void ppc_fadds();
|
||||
extern void ppc_fsubs();
|
||||
extern void ppc_fmuls();
|
||||
extern void ppc_fmults();
|
||||
extern void ppc_fdivs();
|
||||
extern void ppc_fmadd();
|
||||
extern void ppc_fmsub();
|
||||
@@ -558,9 +554,9 @@ 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 */
|
||||
void print_fprs(void); /* print content of the floating-point registers */
|
||||
uint64_t get_reg(std::string& reg_name); /* get content of the register reg_name */
|
||||
void set_reg(std::string& reg_name, uint64_t val); /* set reg_name to val */
|
||||
|
||||
@@ -22,7 +22,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file Handling of low-level PPC exceptions. */
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <setjmp.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@@ -31,8 +30,8 @@ jmp_buf exc_env; /* Global exception environment. */
|
||||
|
||||
[[noreturn]] void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
grab_exception = true;
|
||||
#ifdef CPU_PROFILING
|
||||
exceptions_processed++;
|
||||
#ifdef PROFILER
|
||||
exceptions_performed++;
|
||||
#endif
|
||||
bb_kind = BB_end_kind::BB_EXCEPTION;
|
||||
|
||||
@@ -110,8 +109,6 @@ jmp_buf exc_env; /* Global exception environment. */
|
||||
ppc_next_instruction_address |= 0xFFF00000;
|
||||
}
|
||||
|
||||
mmu_change_mode();
|
||||
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
}
|
||||
|
||||
|
||||
+95
-175
@@ -69,62 +69,11 @@ uint32_t decr; /* current value of PPC DEC register */
|
||||
uint8_t old_decr_msb; /* MSB value for previous DEC value */
|
||||
uint8_t tbr_factor; /* cycles_count to TBR freq ratio in 2^x units */
|
||||
|
||||
#ifdef CPU_PROFILING
|
||||
|
||||
/* global variables for lightweight CPU profiling */
|
||||
uint64_t num_executed_instrs;
|
||||
uint64_t num_supervisor_instrs;
|
||||
uint64_t num_int_loads;
|
||||
uint64_t num_int_stores;
|
||||
uint64_t exceptions_processed;
|
||||
|
||||
#include "utils/profiler.h"
|
||||
#include <memory>
|
||||
|
||||
class CPUProfile : public BaseProfile {
|
||||
public:
|
||||
CPUProfile() : BaseProfile("PPC_CPU") {};
|
||||
|
||||
void populate_variables(std::vector<ProfileVar>& vars) {
|
||||
vars.clear();
|
||||
|
||||
vars.push_back({.name = "Executed Instructions Total",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = num_executed_instrs});
|
||||
|
||||
vars.push_back({.name = "Executed Supervisor Instructions",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = num_supervisor_instrs});
|
||||
|
||||
vars.push_back({.name = "Integer Load Instructions",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = num_int_loads});
|
||||
|
||||
vars.push_back({.name = "Integer Store Instructions",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = num_int_stores});
|
||||
|
||||
vars.push_back({.name = "Exceptions processed",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = exceptions_processed});
|
||||
};
|
||||
|
||||
void reset() {
|
||||
num_executed_instrs = 0;
|
||||
num_supervisor_instrs = 0;
|
||||
num_int_loads = 0;
|
||||
num_int_stores = 0;
|
||||
exceptions_processed = 0;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/** Opcode lookup tables. */
|
||||
|
||||
/** Primary opcode (bits 0...5) lookup table. */
|
||||
static PPCOpcode OpcodeGrabber[] = {
|
||||
ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_twi, ppc_illegalop, ppc_illegalop,
|
||||
ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_twi, ppc_opcode4, 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,
|
||||
@@ -133,28 +82,20 @@ static PPCOpcode OpcodeGrabber[] = {
|
||||
ppc_stw, ppc_stwu, ppc_stb, ppc_stbu, ppc_lhz, ppc_lhzu,
|
||||
ppc_lha, ppc_lhau, ppc_sth, ppc_sthu, ppc_lmw, ppc_stmw,
|
||||
ppc_lfs, ppc_lfsu, ppc_lfd, ppc_lfdu, ppc_stfs, ppc_stfsu,
|
||||
ppc_stfd, ppc_stfdu, ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_opcode59,
|
||||
ppc_stfd, ppc_stfdu, ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_illegalop,
|
||||
ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_opcode63};
|
||||
|
||||
/** Lookup tables for branch instructions. */
|
||||
static PPCOpcode SubOpcode16Grabber[] = {
|
||||
dppc_interpreter::ppc_bc,
|
||||
dppc_interpreter::ppc_bcl,
|
||||
dppc_interpreter::ppc_bca,
|
||||
dppc_interpreter::ppc_bcla};
|
||||
static PPCOpcode SubOpcode16Grabber[] = {ppc_bc, ppc_bcl, ppc_bca, ppc_bcla};
|
||||
|
||||
static PPCOpcode SubOpcode18Grabber[] = {
|
||||
dppc_interpreter::ppc_b,
|
||||
dppc_interpreter::ppc_bl,
|
||||
dppc_interpreter::ppc_ba,
|
||||
dppc_interpreter::ppc_bla};
|
||||
static PPCOpcode SubOpcode18Grabber[] = {ppc_b, ppc_bl, ppc_ba, ppc_bla};
|
||||
|
||||
/** Instructions decoding tables for integer,
|
||||
single floating-point, and double-floating point ops respectively */
|
||||
|
||||
PPCOpcode SubOpcode31Grabber[1024] = { ppc_illegalop };
|
||||
PPCOpcode SubOpcode59Grabber[32] = { ppc_illegalop };
|
||||
PPCOpcode SubOpcode63Grabber[1024] = { ppc_illegalop };
|
||||
PPCOpcode SubOpcode31Grabber[1024] = {ppc_illegalsubop19};
|
||||
PPCOpcode SubOpcode59Grabber[1024] = {ppc_illegalsubop19};
|
||||
PPCOpcode SubOpcode63Grabber[1024] = {ppc_illegalsubop19};
|
||||
|
||||
|
||||
#define UPDATE_TBR_DEC \
|
||||
@@ -168,18 +109,50 @@ PPCOpcode SubOpcode63Grabber[1024] = { ppc_illegalop };
|
||||
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]();
|
||||
}
|
||||
@@ -207,9 +180,6 @@ void ppc_opcode19() {
|
||||
|
||||
} else {
|
||||
switch (subop_grab) {
|
||||
case 0:
|
||||
ppc_mcrf();
|
||||
break;
|
||||
case 66:
|
||||
ppc_crnor();
|
||||
break;
|
||||
@@ -240,8 +210,8 @@ void ppc_opcode19() {
|
||||
case 898:
|
||||
ppc_cror();
|
||||
break;
|
||||
default:
|
||||
ppc_illegalop();
|
||||
default: // Illegal opcode - should never happen
|
||||
ppc_illegalsubop19();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -261,8 +231,8 @@ void ppc_opcode31() {
|
||||
}
|
||||
|
||||
void ppc_opcode59() {
|
||||
uint16_t subop_grab = (ppc_cur_instruction >> 1) & 0x1F;
|
||||
rc_flag = ppc_cur_instruction & 1;
|
||||
uint16_t subop_grab = (ppc_cur_instruction & 0x7FF) >> 1;
|
||||
rc_flag = subop_grab & 1;
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 59 table subopcode entry \n", regrab);
|
||||
@@ -271,8 +241,8 @@ void ppc_opcode59() {
|
||||
}
|
||||
|
||||
void ppc_opcode63() {
|
||||
uint16_t subop_grab = (ppc_cur_instruction >> 1) & 0x3FF;
|
||||
rc_flag = ppc_cur_instruction & 1;
|
||||
uint16_t subop_grab = (ppc_cur_instruction & 0x7FF) >> 1;
|
||||
rc_flag = subop_grab & 1;
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 63 table subopcode entry \n", regrab);
|
||||
@@ -283,9 +253,6 @@ void ppc_opcode63() {
|
||||
/* Dispatch using main opcode */
|
||||
void ppc_main_opcode()
|
||||
{
|
||||
#ifdef CPU_PROFILING
|
||||
num_executed_instrs++;
|
||||
#endif
|
||||
OpcodeGrabber[(ppc_cur_instruction >> 26) & 0x3F]();
|
||||
}
|
||||
|
||||
@@ -309,8 +276,7 @@ void ppc_exec()
|
||||
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 = mmu_translate_imem(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
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;
|
||||
@@ -318,8 +284,7 @@ void ppc_exec()
|
||||
}
|
||||
|
||||
/* initial MMU translation for the current code page. */
|
||||
//pc_real = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
|
||||
/* set current code page limits */
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
@@ -337,7 +302,7 @@ again:
|
||||
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 = mmu_translate_imem(bb_start_la);
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
} else {
|
||||
pc_real += (int)bb_start_la - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
@@ -370,8 +335,7 @@ void ppc_exec_single()
|
||||
return;
|
||||
}
|
||||
|
||||
//quickinstruction_translate(ppc_state.pc);
|
||||
mmu_translate_imem(ppc_state.pc);
|
||||
quickinstruction_translate(ppc_state.pc);
|
||||
ppc_main_opcode();
|
||||
if (bb_kind != BB_end_kind::BB_NONE) {
|
||||
ppc_state.pc = ppc_next_instruction_address;
|
||||
@@ -388,7 +352,7 @@ void ppc_exec_single()
|
||||
}
|
||||
|
||||
/** Execute PPC code until goal_addr is reached. */
|
||||
void ppc_exec_until(volatile uint32_t goal_addr)
|
||||
void ppc_exec_until(uint32_t goal_addr)
|
||||
{
|
||||
uint32_t bb_start_la, page_start, delta;
|
||||
uint8_t* pc_real;
|
||||
@@ -406,7 +370,7 @@ void ppc_exec_until(volatile uint32_t goal_addr)
|
||||
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 = mmu_translate_imem(bb_start_la);
|
||||
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;
|
||||
@@ -414,8 +378,7 @@ void ppc_exec_until(volatile uint32_t goal_addr)
|
||||
}
|
||||
|
||||
/* initial MMU translation for the current code page. */
|
||||
//pc_real = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
|
||||
/* set current code page limits */
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
@@ -433,7 +396,7 @@ again:
|
||||
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 = mmu_translate_imem(bb_start_la);
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
} else {
|
||||
pc_real += (int)bb_start_la - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
@@ -448,70 +411,6 @@ 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);
|
||||
pc_real = mmu_translate_imem(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 = mmu_translate_imem(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);
|
||||
pc_real = mmu_translate_imem(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;
|
||||
|
||||
@@ -681,14 +580,28 @@ void initialize_ppc_opcode_tables() {
|
||||
|
||||
SubOpcode59Grabber[18] = ppc_fdivs;
|
||||
SubOpcode59Grabber[20] = ppc_fsubs;
|
||||
SubOpcode59Grabber[21] = ppc_fadds;
|
||||
SubOpcode59Grabber[22] = ppc_fsqrts;
|
||||
SubOpcode59Grabber[24] = ppc_fres;
|
||||
SubOpcode59Grabber[25] = ppc_fmuls;
|
||||
SubOpcode59Grabber[28] = ppc_fmsubs;
|
||||
SubOpcode59Grabber[29] = ppc_fmadds;
|
||||
SubOpcode59Grabber[30] = ppc_fnmsubs;
|
||||
SubOpcode59Grabber[31] = ppc_fnmadds;
|
||||
|
||||
for (int i = 25; i < 1024; i += 32) {
|
||||
SubOpcode59Grabber[i] = ppc_fmults;
|
||||
}
|
||||
|
||||
for (int i = 28; i < 1024; i += 32) {
|
||||
SubOpcode59Grabber[i] = ppc_fmsubs;
|
||||
}
|
||||
|
||||
for (int i = 29; i < 1024; i += 32) {
|
||||
SubOpcode59Grabber[i] = ppc_fmadds;
|
||||
}
|
||||
|
||||
for (int i = 30; i < 1024; i += 32) {
|
||||
SubOpcode59Grabber[i] = ppc_fnmsubs;
|
||||
}
|
||||
|
||||
for (int i = 31; i < 1024; i += 32) {
|
||||
SubOpcode59Grabber[i] = ppc_fnmadds;
|
||||
}
|
||||
|
||||
SubOpcode63Grabber[0] = ppc_fcmpu;
|
||||
SubOpcode63Grabber[12] = ppc_frsp;
|
||||
@@ -716,7 +629,7 @@ void initialize_ppc_opcode_tables() {
|
||||
}
|
||||
|
||||
for (int i = 25; i < 1024; i += 32) {
|
||||
SubOpcode63Grabber[i] = ppc_fmul;
|
||||
SubOpcode63Grabber[i] = ppc_fmult;
|
||||
}
|
||||
|
||||
for (int i = 28; i < 1024; i += 32) {
|
||||
@@ -801,11 +714,18 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version) {
|
||||
|
||||
/* redirect code execution to reset vector */
|
||||
ppc_state.pc = 0xFFF00100;
|
||||
}
|
||||
|
||||
#ifdef CPU_PROFILING
|
||||
gProfilerObj->register_profile("PPC_CPU",
|
||||
std::unique_ptr<BaseProfile>(new CPUProfile()));
|
||||
#endif
|
||||
void print_gprs() {
|
||||
for (int i = 0; i < 32; i++)
|
||||
cout << "GPR " << dec << i << " : " << uppercase << hex << ppc_state.gpr[i] << endl;
|
||||
|
||||
cout << "PC: " << uppercase << hex << ppc_state.pc << endl;
|
||||
cout << "LR: " << uppercase << hex << ppc_state.spr[SPR::LR] << endl;
|
||||
cout << "CR: " << uppercase << hex << ppc_state.cr << endl;
|
||||
cout << "CTR: " << uppercase << hex << ppc_state.spr[SPR::CTR] << endl;
|
||||
cout << "XER: " << uppercase << hex << ppc_state.spr[SPR::XER] << endl;
|
||||
cout << "MSR: " << uppercase << hex << ppc_state.msr << endl;
|
||||
}
|
||||
|
||||
void print_fprs() {
|
||||
|
||||
+341
-312
File diff suppressed because it is too large.
Load diff
+233
-1468
File diff suppressed because it is too large.
Load diff
+6
-70
@@ -19,15 +19,14 @@ 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 PowerPC Memory Management Unit definitions. */
|
||||
// The opcodes for the processor - ppcopcodes.cpp
|
||||
|
||||
#ifndef PPCMMU_H
|
||||
#define PPCMMU_H
|
||||
#ifndef PPCMEMORY_H
|
||||
#define PPCMEMORY_H
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
#include "devices/memctrlbase.h"
|
||||
|
||||
/* Uncomment this to exhaustive MMU integrity checks. */
|
||||
//#define MMU_INTEGRITY_CHECKS
|
||||
@@ -37,80 +36,17 @@ typedef struct PPC_BAT_entry {
|
||||
uint8_t access; /* copy of Vs | Vp bits */
|
||||
uint8_t prot; /* copy of PP bits */
|
||||
uint32_t phys_hi; /* high-order bits for physical address generation */
|
||||
uint32_t hi_mask; /* mask for high-order logical address bits */
|
||||
uint32_t lo_mask; /* mask for low-order logical address bits */
|
||||
uint32_t bepi; /* copy of Block effective page index */
|
||||
} PPC_BAT_entry;
|
||||
|
||||
/** Block address translation types. */
|
||||
enum BATType : int {
|
||||
IBAT,
|
||||
DBAT
|
||||
};
|
||||
|
||||
/** TLB types. */
|
||||
enum TLBType : int {
|
||||
ITLB,
|
||||
DTLB
|
||||
};
|
||||
|
||||
/** Result of the block address translation. */
|
||||
typedef struct BATResult {
|
||||
bool hit;
|
||||
uint8_t prot;
|
||||
uint32_t phys;
|
||||
} BATResult;
|
||||
|
||||
/** Result of the page address translation. */
|
||||
typedef struct PATResult {
|
||||
uint32_t phys;
|
||||
uint8_t prot;
|
||||
uint8_t pte_c_status; // status of the C bit of the PTE
|
||||
} PATResult;
|
||||
|
||||
#define PAGE_SIZE_BITS 12
|
||||
#define TLB_SIZE 4096
|
||||
#define TLB2_WAYS 4
|
||||
#define TLB_INVALID_TAG 0xFFFFFFFF
|
||||
|
||||
typedef struct TLBEntry {
|
||||
uint32_t tag;
|
||||
uint16_t flags;
|
||||
uint16_t lru_bits;
|
||||
union {
|
||||
int64_t host_va_offset;
|
||||
AddressMapEntry* reg_desc;
|
||||
};
|
||||
} TLBEntry;
|
||||
|
||||
enum TLBFlags : uint16_t {
|
||||
PAGE_MEM = 1 << 0, // memory page backed by host memory
|
||||
PAGE_IO = 1 << 1, // memory mapped I/O page
|
||||
TLBE_FROM_BAT = 1 << 2, // TLB entry has been translated with BAT
|
||||
TLBE_FROM_PAT = 1 << 3, // TLB entry has been translated with PAT
|
||||
PAGE_WRITABLE = 1 << 4, // page is writable
|
||||
PTE_SET_C = 1 << 5, // tells if C bit of the PTE needs to be updated
|
||||
};
|
||||
|
||||
extern void ibat_update(uint32_t bat_reg);
|
||||
extern void dbat_update(uint32_t bat_reg);
|
||||
|
||||
extern uint8_t* mmu_get_dma_mem(uint32_t addr, uint32_t size);
|
||||
|
||||
extern void mmu_change_mode(void);
|
||||
extern void mmu_pat_ctx_changed();
|
||||
extern void tlb_flush_entry(uint32_t ea);
|
||||
|
||||
extern void ppc_set_cur_instruction(const uint8_t* ptr);
|
||||
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
|
||||
uint8_t *mmu_translate_imem(uint32_t vaddr);
|
||||
|
||||
template <class T>
|
||||
extern T mmu_read_vmem(uint32_t guest_va);
|
||||
template <class T>
|
||||
extern void mmu_write_vmem(uint32_t guest_va, T value);
|
||||
|
||||
//====================== Deprecated calls =========================
|
||||
#if 0
|
||||
extern void mem_write_byte(uint32_t addr, uint8_t value);
|
||||
extern void mem_write_word(uint32_t addr, uint16_t value);
|
||||
extern void mem_write_dword(uint32_t addr, uint32_t value);
|
||||
@@ -119,7 +55,7 @@ extern uint8_t mem_grab_byte(uint32_t addr);
|
||||
extern uint16_t mem_grab_word(uint32_t addr);
|
||||
extern uint32_t mem_grab_dword(uint32_t addr);
|
||||
extern uint64_t mem_grab_qword(uint32_t addr);
|
||||
extern uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size);
|
||||
extern uint8_t* quickinstruction_translate(uint32_t address_grab);
|
||||
#endif
|
||||
|
||||
#endif // PPCMMU_H
|
||||
#endif // PPCMEMORY_H
|
||||
+255
-444
File diff suppressed because it is too large.
Load diff
@@ -331,9 +331,9 @@
|
||||
0xFFF00100,0xCC1F0008,lfdu,f0,0x8(r31)
|
||||
0xFFF00100,0xC1628398,lfs,f11,-0x7C68(r2)
|
||||
0xFFF00100,0xC5BE0004,lfsu,f13,0x4(r30)
|
||||
0xFFF00100,0xDBC1FFF0,stfd,f30,-0x10(r1)
|
||||
0xFFF00100,0xD8010860,stfd,f0,0x860(r1)
|
||||
0xFFF00100,0xDC180008,stfdu,f0,0x8(r24)
|
||||
0xFFF00100,0xDBC1FFF0,sftd,f30,-0x10(r1)
|
||||
0xFFF00100,0xD8010860,sftd,f0,0x860(r1)
|
||||
0xFFF00100,0xDC180008,sftdu,f0,0x8(r24)
|
||||
0xFFF00100,0xD01E0110,stfs,f0,0x110(r30)
|
||||
0xFFF00100,0xD58B0004,stfsu,f12,0x4(r11)
|
||||
0xFFF00100,0x7C1C5CAE,lfdx,f0,r28,r11
|
||||
@@ -362,21 +362,9 @@
|
||||
0xFFF00100,0xEDA66279,fmsubs.,f13,f6,f9,f12
|
||||
0xFFF00100,0xEC00637C,fnmsubs,f0,f0,f13,f12
|
||||
0xFFF00100,0xFE0820AF,fsel.,f16,f8,f2,f4
|
||||
0xFFF00100,0xFDA06050,fneg,f13,f12
|
||||
0xFFF00100,0xFD80EA10,fabs,f12,f29
|
||||
0xFFF00100,0xFD600110,fnabs,f11,f0
|
||||
0xFFF00100,0xFD002034,frsqrte,f8,f4
|
||||
0xFFF00100,0x7FF957AE,stfiwx,f31,r25,r10
|
||||
0xFFF00100,0xFC40F818,frsp,f2,f31
|
||||
0xFFF00100,0xFC201019,frsp.,f1,f2
|
||||
0xFFF00100,0xFDA0F81E,fctiwz,f13,f31
|
||||
0xFFF00100,0xFCA0501D,fctiw.,f5,f10
|
||||
0xFFF00100,0xFD9C0080,mcrfs,cr3,cr7
|
||||
0xFFF00100,0xFDFE058E,mtfsf,255,f0
|
||||
0xFFF00100,0xFF80F10C,mtfsfi,cr7,15
|
||||
0xFFF00100,0xFF80F10D,mtfsfi.,cr7,15
|
||||
0xFFF00100,0xFC406890,fmr,f2,f13
|
||||
0xFFF00100,0xFC20E891,fmr.,f1,f29
|
||||
|
||||
# compare instructions
|
||||
0xFFF00100,0x7C15A000,cmpw,r21,r20
|
||||
@@ -396,7 +384,6 @@
|
||||
0xFFF00100,0x7CBC04AA,lswi,r5,r28,0x20
|
||||
0xFFF00100,0x7FEF2C2A,lswx,r31,r15,r5
|
||||
0xFFF00100,0x7E000400,mcrxr,cr4
|
||||
0xFFF00100,0xFDC0008C,mtfsb0,14
|
||||
0xFFF00100,0xFFE0004C,mtfsb1,31
|
||||
0xFFF00100,0xFFE0048F,mffs.,f31
|
||||
0xFFF00100,0x7C2000A6,mfmsr,r1
|
||||
|
||||
|
@@ -1,6 +1,5 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/capstone/include")
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
+51
-321
@@ -19,7 +19,9 @@ 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 <array>
|
||||
#include "../cpu/ppc/ppcdisasm.h"
|
||||
#include "../cpu/ppc/ppcemu.h"
|
||||
#include "../cpu/ppc/ppcmmu.h"
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
@@ -28,14 +30,7 @@ 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 "utils/profiler.h"
|
||||
|
||||
#ifdef ENABLE_68K_DEBUGGER // optionally defined in CMakeLists.txt
|
||||
#include <capstone/capstone.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -57,178 +52,42 @@ static uint32_t str2num(string& num_str) {
|
||||
|
||||
static void show_help() {
|
||||
cout << "Debugger commands:" << endl;
|
||||
cout << " step [N] -- execute single instruction" << endl;
|
||||
cout << " N is an optional step count" << endl;
|
||||
cout << " si [N] -- shortcut for step" << endl;
|
||||
cout << " next -- same as step but treats subroutine calls" << endl;
|
||||
cout << " as single instructions." << endl;
|
||||
cout << " ni -- shortcut for next" << endl;
|
||||
cout << " until X -- execute until address X is reached" << endl;
|
||||
cout << " regs -- dump content of the GRPs" << endl;
|
||||
cout << " set R=X -- assign value X to register R" << endl;
|
||||
cout << " if R=loglevel, set the internal" << endl;
|
||||
cout << " log level to X whose range is -2...9" << endl;
|
||||
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
|
||||
cout << " T can be b(byte), w(word), d(double)," << endl;
|
||||
cout << " q(quad) or c(character)." << endl;
|
||||
cout << " profile C N -- run subcommand C on profile N" << endl;
|
||||
cout << " supported subcommands:" << endl;
|
||||
cout << " 'show' - show profile report" << endl;
|
||||
cout << " 'reset' - reset profile variables" << endl;
|
||||
cout << " step -- execute single instruction" << endl;
|
||||
cout << " si -- shortcut for step" << endl;
|
||||
cout << " next -- same as step but treats subroutine calls" << endl;
|
||||
cout << " as single instructions." << endl;
|
||||
cout << " ni -- shortcut for next" << endl;
|
||||
cout << " until X -- execute until address X is reached" << endl;
|
||||
cout << " regs -- dump content of the GRPs" << endl;
|
||||
cout << " set R=X -- assign value X to register R" << endl;
|
||||
cout << " if R=loglevel, set the internal" << endl;
|
||||
cout << " log level to X whose range is -2...9" << endl;
|
||||
cout << " dump NT,X -- dump N memory cells of size T at address X" << endl;
|
||||
cout << " T can be b(byte), w(word), d(double)," << endl;
|
||||
cout << " q(quad) or c(character)." << endl;
|
||||
#ifdef PROFILER
|
||||
cout << " profiler -- show stats related to the processor" << endl;
|
||||
cout << " profiler -- show stats related to the processor" << endl;
|
||||
#endif
|
||||
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;
|
||||
cout << " da N,X -- shortcut for disas" << 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 << " 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;
|
||||
cout << " quit -- quit the debugger" << endl << endl;
|
||||
cout << "Pressing ENTER will repeat last command." << endl;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
static void disasm(uint32_t count, uint32_t address) {
|
||||
PPCDisasmContext ctx;
|
||||
|
||||
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;
|
||||
ctx.instr_addr = address;
|
||||
ctx.simplified = true;
|
||||
|
||||
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 = mmu_read_vmem<uint16_t>(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";
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -310,8 +169,7 @@ static void dump_mem(string& params) {
|
||||
cout << (char)val;
|
||||
chars_per_line += cell_size;
|
||||
} else {
|
||||
cout << setw(cell_size * 2) << setfill('0') << right;
|
||||
cout << uppercase << hex << val << " ";
|
||||
cout << setw(cell_size * 2) << setfill('0') << uppercase << hex << val << " ";
|
||||
chars_per_line += cell_size * 2 + 2;
|
||||
}
|
||||
}
|
||||
@@ -323,67 +181,18 @@ 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 = mem_read_dbg(ctx.instr_addr, 4);
|
||||
cout << uppercase << hex << ctx.instr_addr;
|
||||
cout << " " << disassemble_single(&ctx) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static void print_gprs() {
|
||||
string reg_name;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
reg_name = "R" + to_string(i);
|
||||
|
||||
cout << right << std::setw(3) << setfill(' ') << reg_name << " : " <<
|
||||
setw(8) << setfill('0') << right << uppercase << hex << get_reg(reg_name);
|
||||
|
||||
if (i & 1) {
|
||||
cout << endl;
|
||||
} else {
|
||||
cout << "\t\t";
|
||||
}
|
||||
}
|
||||
|
||||
array<string,6> sprs = {"PC", "LR", "CR", "CTR", "XER", "MSR"};
|
||||
|
||||
for (auto &spr : sprs) {
|
||||
cout << right << std::setw(3) << setfill(' ') << spr << " : " <<
|
||||
setw(8) << setfill('0') << uppercase << hex << get_reg(spr);
|
||||
|
||||
if (i & 1) {
|
||||
cout << endl;
|
||||
} else {
|
||||
cout << "\t\t";
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void enter_debugger() {
|
||||
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str,
|
||||
inst_string, inst_num_str, profile_name, sub_cmd;
|
||||
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, context;
|
||||
int log_level;
|
||||
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 << "dingusdbg> ";
|
||||
cout << "ppcdbg> ";
|
||||
|
||||
/* reset string stream */
|
||||
ss.str("");
|
||||
@@ -402,26 +211,16 @@ void enter_debugger() {
|
||||
show_help();
|
||||
} else if (cmd == "quit") {
|
||||
break;
|
||||
} else if (cmd == "profile") {
|
||||
ss >> sub_cmd;
|
||||
ss >> profile_name;
|
||||
|
||||
if (sub_cmd == "show") {
|
||||
gProfilerObj->print_profile(profile_name);
|
||||
} else if (sub_cmd == "reset") {
|
||||
gProfilerObj->reset_profile(profile_name);
|
||||
} else {
|
||||
cout << "Unknown/empty subcommand " << sub_cmd << endl;
|
||||
}
|
||||
}
|
||||
else if (cmd == "regs") {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
print_68k_regs();
|
||||
#ifdef PROFILER
|
||||
else if (cmd == "profiler") {
|
||||
cout << "Number of Supervisor Instructions Executed:" << supervisor_inst_num << endl;
|
||||
cout << "Exception Handler Ran:" << exceptions_performed << endl;
|
||||
cout << "Number of MMU Translations:" << mmu_translations_num << endl;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
print_gprs();
|
||||
}
|
||||
else if (cmd == "regs") {
|
||||
print_gprs();
|
||||
} else if (cmd == "set") {
|
||||
ss >> expr_str;
|
||||
|
||||
@@ -449,32 +248,7 @@ void enter_debugger() {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else if (cmd == "step" || cmd == "si") {
|
||||
int count;
|
||||
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str.length() > 0) {
|
||||
try {
|
||||
count = str2num(expr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
count = 1;
|
||||
}
|
||||
} else {
|
||||
count = 1;
|
||||
}
|
||||
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
for (; --count >= 0;) {
|
||||
exec_single_68k();
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
for (; --count >= 0;) {
|
||||
ppc_exec_single();
|
||||
}
|
||||
}
|
||||
ppc_exec_single();
|
||||
} else if (cmd == "next" || cmd == "ni") {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str) + 4;
|
||||
@@ -483,17 +257,11 @@ void enter_debugger() {
|
||||
ss >> addr_str;
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
exec_until_68k(addr);
|
||||
#endif
|
||||
} else {
|
||||
ppc_exec_until(addr);
|
||||
}
|
||||
ppc_exec_until(addr);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else if (cmd == "disas" || cmd == "da") {
|
||||
} else if (cmd == "disas") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str.length() > 0) {
|
||||
@@ -502,73 +270,35 @@ void enter_debugger() {
|
||||
cout << "disas: not enough arguments specified." << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
inst_num_str = expr_str.substr(0, expr_str.find_first_of(","));
|
||||
try {
|
||||
inst_grab = str2num(inst_num_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
addr_str = expr_str.substr(expr_str.find_first_of(",") + 1);
|
||||
inst_grab = stol(inst_num_str, NULL, 0);
|
||||
addr_str = expr_str.substr(expr_str.find_first_of(",") + 1);
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
try {
|
||||
/* number conversion failed, trying reg name */
|
||||
if (context == 2 && (addr_str == "pc" || addr_str == "PC")) {
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str) - 2;
|
||||
} else {
|
||||
addr = get_reg(addr_str);
|
||||
}
|
||||
addr = get_reg(addr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
disasm_68k(inst_grab, addr);
|
||||
#endif
|
||||
} else {
|
||||
disasm(inst_grab, addr);
|
||||
}
|
||||
disasm(inst_grab, addr);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else {
|
||||
/* disas without arguments defaults to disas 1,pc */
|
||||
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);
|
||||
}
|
||||
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;
|
||||
|
||||
+132
-233
@@ -21,90 +21,23 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "displayid.h"
|
||||
#include "endianswap.h"
|
||||
#include "memaccess.h"
|
||||
#include "memreadwrite.h"
|
||||
#include "pcidevice.h"
|
||||
#include <atirage.h>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
/* Mach64 post dividers. */
|
||||
static const int mach64_post_div[8] = {
|
||||
1, 2, 4, 8, // standard post dividers
|
||||
3, 5, 6, 12 // alternate post dividers
|
||||
};
|
||||
|
||||
/* Human readable Mach64 HW register names for easier debugging. */
|
||||
static const std::map<uint16_t, std::string> mach64_reg_names = {
|
||||
{0x0000, "CRTC_H_TOTAL_DISP"},
|
||||
{0x0004, "CRTC_H_SYNC_STRT_WID"},
|
||||
{0x0008, "CRTC_V_TOTAL_DISP"},
|
||||
{0x000C, "CRTC_V_SYNC_STRT_WID"},
|
||||
{0x0010, "CRTC_VLINE_CRNT_VLINE"},
|
||||
{0x0014, "CRTC_OFF_PITCH"},
|
||||
{0x0018, "CRTC_INT_CNTL"},
|
||||
{0x001C, "CRTC_GEN_CNTL"},
|
||||
{0x0020, "DSP_CONFIG"},
|
||||
{0x0024, "DSP_ON_OFF"},
|
||||
{0x002C, "MEM_BUF_CNTL"},
|
||||
{0x0034, "MEM_ADDR_CFG"},
|
||||
{0x0040, "OVR_CLR"},
|
||||
{0x0044, "OVR_WID_LEFT_RIGHT"},
|
||||
{0x0048, "OVR_WID_TOP_BOTTOM"},
|
||||
{0x0060, "CUR_CLR0"},
|
||||
{0x0064, "CUR_CLR1"},
|
||||
{0x0068, "CUR_OFFSET"},
|
||||
{0x006C, "CUR_HORZ_VERT_POSN"},
|
||||
{0x0078, "GP_IO"},
|
||||
{0x007C, "HW_DEBUG"},
|
||||
{0x0080, "SCRATCH_REG0"},
|
||||
{0x0084, "SCRATCH_REG1"},
|
||||
{0x0088, "SCRATCH_REG2"},
|
||||
{0x008C, "SCRATCH_REG3"},
|
||||
{0x0090, "CLOCK_CNTL"},
|
||||
{0x00A0, "BUS_CNTL"},
|
||||
{0x00AC, "EXT_MEM_CNTL"},
|
||||
{0x00B0, "MEM_CNTL"},
|
||||
{0x00C0, "DAC_REGS"},
|
||||
{0x00C4, "DAC_CNTL"},
|
||||
{0x00D0, "GEN_TEST_CNTL"},
|
||||
{0x00D4, "CUSTOM_MACRO_CNTL"},
|
||||
{0x00E0, "CONFIG_CHIP_ID"},
|
||||
{0x00E4, "CONFIG_STAT0"},
|
||||
{0x01B4, "SRC_CNTL"},
|
||||
{0x01FC, "SCALE_3D_CNTL"},
|
||||
{0x0310, "FIFO_STAT"},
|
||||
{0x0338, "GUI_STAT"},
|
||||
};
|
||||
|
||||
|
||||
ATIRage::ATIRage(uint16_t dev_id, uint32_t mem_amount) : PCIDevice("ati-rage") {
|
||||
uint8_t asic_id;
|
||||
|
||||
this->vram_size = mem_amount << 20;
|
||||
|
||||
/* allocate video RAM */
|
||||
/*allocate video RAM */
|
||||
this->vram_ptr = new uint8_t[this->vram_size];
|
||||
|
||||
/* ATI Rage driver needs to know ASIC ID (manufacturer's internal chip code)
|
||||
to operate properly */
|
||||
switch (dev_id) {
|
||||
case ATI_RAGE_PRO_DEV_ID:
|
||||
asic_id = 0x5C; // R3B/D/P-A4 fabricated by UMC
|
||||
break;
|
||||
default:
|
||||
asic_id = 0xDD;
|
||||
LOG_F(WARNING, "ATI Rage: bogus ASIC ID assigned!");
|
||||
}
|
||||
|
||||
/* set up PCI configuration space header */
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[0], (dev_id << 16) | ATI_PCI_VENDOR_ID);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[8], (0x030000 << 8) | asic_id);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[0x3C], 0x00080100);
|
||||
|
||||
/* stuff default values into chip registers */
|
||||
WRITE_DWORD_LE_A(&this->block_io_regs[ATI_CONFIG_CHIP_ID],
|
||||
(asic_id << 24) | dev_id);
|
||||
/* configure PCI parameters */
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[0], (dev_id << 16) | ATI_PCI_VENDOR_ID);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[8], 0x0300005C);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[0x3C], 0x00080100);
|
||||
|
||||
/* initialize display identification */
|
||||
this->disp_id = new DisplayID();
|
||||
@@ -119,28 +52,125 @@ ATIRage::~ATIRage()
|
||||
delete (this->disp_id);
|
||||
}
|
||||
|
||||
const char* ATIRage::get_reg_name(uint32_t reg_offset) {
|
||||
auto iter = mach64_reg_names.find(reg_offset & ~3);
|
||||
if (iter != mach64_reg_names.end()) {
|
||||
return iter->second.c_str();
|
||||
} else {
|
||||
return "unknown Mach64 register";
|
||||
uint32_t ATIRage::size_dep_read(uint8_t* buf, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
return READ_DWORD_LE_A(buf);
|
||||
break;
|
||||
case 2:
|
||||
return READ_WORD_LE_A(buf);
|
||||
break;
|
||||
case 1:
|
||||
return *buf;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "ATI Rage read: invalid size %d", size);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ATIRage::size_dep_write(uint8_t* buf, uint32_t value, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
WRITE_DWORD_BE_A(buf, value);
|
||||
break;
|
||||
case 2:
|
||||
WRITE_WORD_BE_A(buf, value & 0xFFFFU);
|
||||
break;
|
||||
case 1:
|
||||
*buf = value & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
const char* ATIRage::get_reg_name(uint32_t reg_offset) {
|
||||
const char* reg_name;
|
||||
|
||||
switch (reg_offset & ~3) {
|
||||
case ATI_CRTC_H_TOTAL_DISP:
|
||||
reg_name = "CRTC_H_TOTAL_DISP";
|
||||
break;
|
||||
case ATI_CRTC_H_SYNC_STRT_WID:
|
||||
reg_name = "CRTC_H_SYNC_STRT_WID";
|
||||
break;
|
||||
case ATI_CRTC_V_TOTAL_DISP:
|
||||
reg_name = "CRTC_V_TOTAL_DISP";
|
||||
break;
|
||||
case ATI_CRTC_V_SYNC_STRT_WID:
|
||||
reg_name = "CRTC_V_SYNC_STRT_WID";
|
||||
break;
|
||||
case ATI_CRTC_OFF_PITCH:
|
||||
reg_name = "CRTC_OFF_PITCH";
|
||||
break;
|
||||
case ATI_CRTC_INT_CNTL:
|
||||
reg_name = "CRTC_INT_CNTL";
|
||||
break;
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
reg_name = "CRTC_GEN_CNTL";
|
||||
break;
|
||||
case ATI_DSP_CONFIG:
|
||||
reg_name = "DSP_CONFIG";
|
||||
break;
|
||||
case ATI_DSP_ON_OFF:
|
||||
reg_name = "DSP_ON_OFF";
|
||||
break;
|
||||
case ATI_MEM_BUF_CNTL:
|
||||
reg_name = "MEM_BUF_CNTL";
|
||||
break;
|
||||
case ATI_MEM_ADDR_CFG:
|
||||
reg_name = "MEM_ADDR_CFG";
|
||||
break;
|
||||
case ATI_OVR_CLR:
|
||||
reg_name = "OVR_CLR";
|
||||
break;
|
||||
case ATI_OVR_WID_LEFT_RIGHT:
|
||||
reg_name = "OVR_WID_LEFT_RIGHT";
|
||||
break;
|
||||
case ATI_OVR_WID_TOP_BOTTOM:
|
||||
reg_name = "OVR_WID_TOP_BOTTOM";
|
||||
break;
|
||||
case ATI_GP_IO:
|
||||
reg_name = "GP_IO";
|
||||
break;
|
||||
case ATI_CLOCK_CNTL:
|
||||
reg_name = "CLOCK_CNTL";
|
||||
break;
|
||||
case ATI_BUS_CNTL:
|
||||
reg_name = "BUS_CNTL";
|
||||
break;
|
||||
case ATI_EXT_MEM_CNTL:
|
||||
reg_name = "EXT_MEM_CNTL";
|
||||
break;
|
||||
case ATI_MEM_CNTL:
|
||||
reg_name = "MEM_CNTL";
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
reg_name = "DAC_REGS";
|
||||
break;
|
||||
case ATI_DAC_CNTL:
|
||||
reg_name = "DAC_CNTL";
|
||||
break;
|
||||
case ATI_GEN_TEST_CNTL:
|
||||
reg_name = "GEN_TEST_CNTL";
|
||||
break;
|
||||
case ATI_CFG_CHIP_ID:
|
||||
reg_name = "CONFIG_CHIP_ID";
|
||||
break;
|
||||
case ATI_CFG_STAT0:
|
||||
reg_name = "CONFIG_STAT0";
|
||||
break;
|
||||
default:
|
||||
reg_name = "unknown";
|
||||
}
|
||||
|
||||
return reg_name;
|
||||
}
|
||||
|
||||
uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
|
||||
uint32_t res;
|
||||
|
||||
switch (offset & ~3) {
|
||||
case ATI_GP_IO:
|
||||
break;
|
||||
case ATI_CLOCK_CNTL:
|
||||
/* reading from internal PLL registers */
|
||||
if (offset == ATI_CLOCK_CNTL+2 && size == 1 &&
|
||||
!(this->block_io_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
|
||||
return this->plls[this->block_io_regs[ATI_CLOCK_CNTL+1] >> 2];
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
if (offset == ATI_DAC_DATA) {
|
||||
this->block_io_regs[ATI_DAC_DATA] =
|
||||
@@ -160,15 +190,10 @@ uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
|
||||
get_reg_name(offset),
|
||||
offset,
|
||||
size,
|
||||
read_mem(&this->block_io_regs[offset], size));
|
||||
size_dep_read(&this->block_io_regs[offset], size));
|
||||
}
|
||||
|
||||
if (offset > sizeof(this->block_io_regs)) {
|
||||
LOG_F(WARNING, "ATI Rage: register offset 0x%04X out of bounds!", offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
res = read_mem(&this->block_io_regs[offset], size);
|
||||
res = size_dep_read(&this->block_io_regs[offset], size);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -177,22 +202,10 @@ void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
uint32_t gpio_val;
|
||||
uint16_t gpio_dir;
|
||||
|
||||
if (offset > sizeof(this->block_io_regs)) {
|
||||
LOG_F(WARNING, "ATI Rage: register offset 0x%04X out of bounds!", offset);
|
||||
return;
|
||||
}
|
||||
|
||||
/* size-dependent endian conversion */
|
||||
write_mem(&this->block_io_regs[offset], value, size);
|
||||
size_dep_write(&this->block_io_regs[offset], value, size);
|
||||
|
||||
switch (offset & ~3) {
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
if (this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 2) {
|
||||
this->crtc_enable();
|
||||
} else {
|
||||
this->crtc_on = false;
|
||||
}
|
||||
break;
|
||||
case ATI_GP_IO:
|
||||
if (offset < (ATI_GP_IO + 2)) {
|
||||
gpio_val = READ_DWORD_LE_A(&this->block_io_regs[ATI_GP_IO]);
|
||||
@@ -202,19 +215,6 @@ void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
this->disp_id->read_monitor_sense(gpio_val, gpio_dir));
|
||||
}
|
||||
break;
|
||||
case ATI_CLOCK_CNTL:
|
||||
/* writing to internal PLL registers */
|
||||
if (offset == ATI_CLOCK_CNTL+2 && size == 1 &&
|
||||
(this->block_io_regs[ATI_CLOCK_CNTL+1] & 0x2)) {
|
||||
int pll_addr = this->block_io_regs[ATI_CLOCK_CNTL+1] >> 2;
|
||||
uint8_t pll_data = this->block_io_regs[ATI_CLOCK_CNTL+2];
|
||||
this->plls[pll_addr] = pll_data;
|
||||
LOG_F(INFO, "ATI Rage: PLL #%d set to 0x%02X", pll_addr, pll_data);
|
||||
} else if (offset == ATI_CLOCK_CNTL && size == 1) {
|
||||
LOG_F(INFO, "ATI Rage: CLOCK_SEL = 0x%02X",
|
||||
this->block_io_regs[ATI_CLOCK_CNTL] & 3);
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
switch (offset) {
|
||||
/* writing to read/write index registers resets color component index */
|
||||
@@ -255,7 +255,7 @@ uint32_t ATIRage::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
|
||||
LOG_F(INFO, "Reading ATI Rage config space, offset = 0x%X, size=%d", reg_offs, size);
|
||||
|
||||
res = read_mem(&this->pci_cfg[reg_offs], size);
|
||||
res = size_dep_read(&this->pci_cfg[reg_offs], size);
|
||||
|
||||
LOG_F(INFO, "Return value: 0x%X", res);
|
||||
return res;
|
||||
@@ -277,42 +277,34 @@ void ATIRage::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
else {
|
||||
this->aperture_base = BYTESWAP_32(value);
|
||||
LOG_F(INFO, "ATI Rage aperture address set to 0x%08X", this->aperture_base);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR0], value);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR0], value);
|
||||
this->host_instance->pci_register_mmio_region(this->aperture_base,
|
||||
APERTURE_SIZE, this);
|
||||
}
|
||||
break;
|
||||
case 0x14: /* BAR 1: I/O space base, 256 bytes wide */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1], 0xFFFFFF01UL);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1], 0xFFFFFF01UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1], value);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1], value);
|
||||
}
|
||||
break;
|
||||
case 0x18: /* BAR 2 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR2], 0xFFFFF000UL);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], 0xFFFFF000UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR2], value);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], value);
|
||||
}
|
||||
break;
|
||||
case CFG_REG_BAR3: /* unimplemented */
|
||||
case CFG_REG_BAR4: /* unimplemented */
|
||||
case CFG_REG_BAR5: /* unimplemented */
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[reg_offs], 0);
|
||||
break;
|
||||
case CFG_EXP_BASE: /* no expansion ROM */
|
||||
if (value == 0x00F8FFFFUL) {
|
||||
// return 0 (not implemented) when attempting to size the expansion ROM
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[reg_offs], 0);
|
||||
} else {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[reg_offs], value);
|
||||
}
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[reg_offs], 0);
|
||||
break;
|
||||
default:
|
||||
write_mem(&this->pci_cfg[reg_offs], value, size);
|
||||
size_dep_write(&this->pci_cfg[reg_offs], value, size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +315,7 @@ bool ATIRage::io_access_allowed(uint32_t offset, uint32_t* p_io_base) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t io_base = READ_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1]) & ~3;
|
||||
uint32_t io_base = READ_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1]) & ~3;
|
||||
|
||||
if (offset < io_base || offset > (io_base + 0x100)) {
|
||||
LOG_F(WARNING, "Rage: I/O out of range, base=0x%X, offset=0x%X", io_base, offset);
|
||||
@@ -362,7 +354,7 @@ bool ATIRage::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
|
||||
uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
{
|
||||
LOG_F(8, "Reading ATI Rage PCI memory: region=%X, offset=%X, size %d", reg_start, offset, size);
|
||||
//LOG_F(INFO, "Reading ATI Rage PCI memory: region=%X, offset=%X, size %d", reg_start, offset, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to read outside the aperture!");
|
||||
@@ -371,7 +363,7 @@ uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* read from little-endian VRAM region */
|
||||
return read_mem(this->vram_ptr + offset, size);
|
||||
return size_dep_read(this->vram_ptr + offset, size);
|
||||
}
|
||||
else if (offset >= MEMMAP_OFFSET) {
|
||||
/* read from memory-mapped registers */
|
||||
@@ -386,7 +378,7 @@ uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
|
||||
void ATIRage::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
LOG_F(8, "Writing reg=%X, offset=%X, value=%X, size %d", reg_start, offset, value, size);
|
||||
//LOG_F(INFO, "Writing reg=%X, offset=%X, value=%X, size %d", reg_start, offset, value, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to write outside the aperture!");
|
||||
@@ -395,7 +387,7 @@ void ATIRage::write(uint32_t reg_start, uint32_t offset, uint32_t value, int siz
|
||||
|
||||
if (offset < this->vram_size) {
|
||||
/* write to little-endian VRAM region */
|
||||
write_mem(this->vram_ptr + offset, value, size);
|
||||
size_dep_write(this->vram_ptr + offset, value, size);
|
||||
} else if (offset >= MEMMAP_OFFSET) {
|
||||
/* write to memory-mapped registers */
|
||||
this->write_reg(offset - MEMMAP_OFFSET, value, size);
|
||||
@@ -404,96 +396,3 @@ void ATIRage::write(uint32_t reg_start, uint32_t offset, uint32_t value, int siz
|
||||
LOG_F(WARNING, "ATI Rage: write attempt to unmapped aperture region at 0x%08X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
float ATIRage::calc_pll_freq(int scale, int fb_div) {
|
||||
return (ATI_XTAL * scale * fb_div) / this->plls[PLL_REF_DIV];
|
||||
}
|
||||
|
||||
void ATIRage::verbose_pixel_format(int crtc_index) {
|
||||
if (crtc_index) {
|
||||
LOG_F(ERROR, "CRTC2 not supported yet");
|
||||
return;
|
||||
}
|
||||
|
||||
const char* what = "Pixel format:";
|
||||
|
||||
switch (this->block_io_regs[ATI_CRTC_GEN_CNTL+1] & 7) {
|
||||
case 1:
|
||||
LOG_F(INFO, "%s 4 bpp with DAC palette", what);
|
||||
break;
|
||||
case 2:
|
||||
// check the undocumented DAC_DIRECT bit
|
||||
if (this->block_io_regs[ATI_DAC_CNTL+1] & 4) {
|
||||
LOG_F(INFO, "%s 8 bpp direct color (RGB322)", what);
|
||||
} else {
|
||||
LOG_F(INFO, "%s 8 bpp with DAC palette", what);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
LOG_F(INFO, "%s 15 bpp direct color (RGB555)", what);
|
||||
break;
|
||||
case 4:
|
||||
LOG_F(INFO, "%s 16 bpp direct color (RGB565)", what);
|
||||
break;
|
||||
case 5:
|
||||
LOG_F(INFO, "%s 24 bpp direct color (RGB888)", what);
|
||||
break;
|
||||
case 6:
|
||||
LOG_F(INFO, "%s 32 bpp direct color (ARGB8888)", what);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "ATI Rage: CRTC pixel format %d not supported",
|
||||
this->block_io_regs[ATI_CRTC_GEN_CNTL+2] & 7);
|
||||
}
|
||||
}
|
||||
|
||||
void ATIRage::crtc_enable() {
|
||||
/* active (visible) width is specified in characters (8 px) - 1 */
|
||||
this->active_width = (this->block_io_regs[ATI_CRTC_H_TOTAL_DISP+2] + 1) * 8;
|
||||
|
||||
/* active (visible) height is specified in lines - 1 */
|
||||
this->active_height =
|
||||
(READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_V_TOTAL_DISP+2]) & 0x7FFUL) + 1;
|
||||
|
||||
if ((this->plls[PLL_VCLK_CNTL] & 3) == 3) {
|
||||
/* look up which VPLL ouput is requested */
|
||||
int clock_sel = this->block_io_regs[ATI_CLOCK_CNTL] & 3;
|
||||
|
||||
/* calculate VPLL output frequency */
|
||||
float vpll_freq = calc_pll_freq(2, this->plls[VCLK0_FB_DIV + clock_sel]);
|
||||
|
||||
/* calculate post divider's index */
|
||||
/* NOTE: post divider's index has been extended by an additional
|
||||
bit in Rage Pro. This bit is resided in PLL_EXT_CNTL register.
|
||||
*/
|
||||
int post_div_idx = ((this->plls[PLL_EXT_CNTL] >> (clock_sel + 2)) & 4) |
|
||||
((this->plls[VCLK_POST_DIV] >> (clock_sel * 2)) & 3);
|
||||
|
||||
/* pixel clock = source_freq / post_div */
|
||||
this->pixel_clock = vpll_freq / mach64_post_div[post_div_idx];
|
||||
|
||||
/* calculate display refresh rate */
|
||||
int hori_total =
|
||||
((READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_H_TOTAL_DISP])
|
||||
& 0x1FFUL) + 1) * 8;
|
||||
|
||||
int vert_total =
|
||||
(READ_WORD_LE_A(&this->block_io_regs[ATI_CRTC_V_TOTAL_DISP]) & 0x7FFUL) + 1;
|
||||
|
||||
this->refresh_rate = pixel_clock / hori_total / vert_total;
|
||||
|
||||
LOG_F(INFO, "ATI Rage: primary CRT controller enabled:");
|
||||
LOG_F(INFO, "Video mode: %s",
|
||||
(this->block_io_regs[ATI_CRTC_GEN_CNTL+3] & 1) ? "extended" : "VGA");
|
||||
LOG_F(INFO, "Video width: %d px", this->active_width);
|
||||
LOG_F(INFO, "Video height: %d px", this->active_height);
|
||||
verbose_pixel_format(0);
|
||||
LOG_F(INFO, "VPLL frequency: %f MHz", vpll_freq * 1e-6);
|
||||
LOG_F(INFO, "Pixel (dot) clock: %f MHz", this->pixel_clock * 1e-6);
|
||||
LOG_F(INFO, "Refresh rate: %f Hz", this->refresh_rate);
|
||||
} else {
|
||||
LOG_F(WARNING, "ATI Rage: VLCK source != VPLL!");
|
||||
}
|
||||
|
||||
this->crtc_on = true;
|
||||
}
|
||||
+77
-161
@@ -26,6 +26,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include "pcidevice.h"
|
||||
#include <cinttypes>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* PCI related definitions. */
|
||||
enum {
|
||||
ATI_PCI_VENDOR_ID = 0x1002,
|
||||
@@ -35,159 +37,78 @@ enum {
|
||||
|
||||
/** Mach registers offsets. */
|
||||
enum {
|
||||
ATI_CRTC_H_TOTAL_DISP = 0x0000,
|
||||
ATI_CRTC_H_SYNC_STRT_WID = 0x0004,
|
||||
ATI_CRTC_V_TOTAL_DISP = 0x0008,
|
||||
ATI_CRTC_V_SYNC_STRT_WID = 0x000C,
|
||||
ATI_CRTC_VLINE_CRNT_VLINE = 0x0010,
|
||||
ATI_CRTC_OFF_PITCH = 0x0014,
|
||||
ATI_CRTC_INT_CNTL = 0x0018,
|
||||
ATI_CRTC_GEN_CNTL = 0x001C,
|
||||
ATI_DSP_CONFIG = 0x0020,
|
||||
ATI_DSP_ON_OFF = 0x0024,
|
||||
ATI_TIMER_CFG = 0x0028,
|
||||
ATI_MEM_BUF_CNTL = 0x002C,
|
||||
ATI_MEM_ADDR_CFG = 0x0034,
|
||||
ATI_CRT_TRAP = 0x0038,
|
||||
ATI_I2C_CNTL_0 = 0x003C,
|
||||
ATI_OVR_CLR = 0x0040,
|
||||
ATI_OVR_WID_LEFT_RIGHT = 0x0044,
|
||||
ATI_OVR_WID_TOP_BOTTOM = 0x0048,
|
||||
ATI_VGA_DSP_CFG = 0x004C,
|
||||
ATI_VGA_DSP_TGL = 0x0050,
|
||||
ATI_DSP2_CONFIG = 0x0054,
|
||||
ATI_DSP2_TOGGLE = 0x0058,
|
||||
ATI_CRTC2_OFF_PITCH = 0x005C,
|
||||
ATI_CUR_CLR0 = 0x0060,
|
||||
ATI_CUR_CLR1 = 0x0064,
|
||||
ATI_CUR_OFFSET = 0x0068,
|
||||
ATI_CUR_HORZ_VERT_POSN = 0x006C,
|
||||
ATI_CUR_HORZ_VERT_OFF = 0x0070,
|
||||
ATI_GP_IO = 0x0078,
|
||||
ATI_HW_DEBUG = 0x007C,
|
||||
ATI_SCRATCH_REG0 = 0x0080,
|
||||
ATI_SCRATCH_REG1 = 0x0084,
|
||||
ATI_SCRATCH_REG2 = 0x0088,
|
||||
ATI_SCRATCH_REG3 = 0x008C,
|
||||
ATI_CLOCK_CNTL = 0x0090,
|
||||
ATI_CONFIG_STAT1 = 0x0094,
|
||||
ATI_CONFIG_STAT2 = 0x0098,
|
||||
ATI_BUS_CNTL = 0x00A0,
|
||||
ATI_EXT_MEM_CNTL = 0x00AC,
|
||||
ATI_MEM_CNTL = 0x00B0,
|
||||
ATI_MEM_VGA_WP_SEL = 0x00B4,
|
||||
ATI_MEM_VGA_RP_SEL = 0x00B8,
|
||||
ATI_I2C_CNTL_1 = 0x00BC,
|
||||
ATI_DAC_REGS = 0x00C0,
|
||||
ATI_DAC_W_INDEX = 0x00C0,
|
||||
ATI_DAC_DATA = 0x00C1,
|
||||
ATI_DAC_MASK = 0x00C2,
|
||||
ATI_DAC_R_INDEX = 0x00C3,
|
||||
ATI_DAC_CNTL = 0x00C4,
|
||||
ATI_GEN_TEST_CNTL = 0x00D0,
|
||||
ATI_CUSTOM_MACRO_CNTL = 0x00D4,
|
||||
ATI_CONFIG_CNTL = 0x00DC,
|
||||
ATI_CONFIG_CHIP_ID = 0x00E0,
|
||||
ATI_CONFIG_STAT0 = 0x00E4,
|
||||
ATI_CRC_SIG = 0x00E8,
|
||||
ATI_DST_Y_X_ALIAS1 = 0x00F4,
|
||||
ATI_DST_OFF_PITCH = 0x0100,
|
||||
ATI_DST_X = 0x0104,
|
||||
ATI_DST_Y = 0x0108,
|
||||
ATI_DST_Y_X = 0x010C,
|
||||
ATI_DST_WIDTH = 0x0110,
|
||||
ATI_DST_HEIGHT = 0x0114,
|
||||
ATI_DST_HEIGHT_WIDTH = 0x0118,
|
||||
ATI_DST_X_WIDTH = 0x011C,
|
||||
ATI_DST_BRES_LNTH = 0x0120,
|
||||
ATI_DST_BRES_ERR = 0x0124,
|
||||
ATI_DST_BRES_INC = 0x0128,
|
||||
ATI_DST_BRES_DEC = 0x012C,
|
||||
ATI_DST_CNTL = 0x0130,
|
||||
ATI_DST_Y_X_ALIAS2 = 0x0134,
|
||||
ATI_TRAIL_BRES_ERR = 0x0138,
|
||||
ATI_TRAIL_BRES_INC = 0x013C,
|
||||
ATI_TRAIL_BRES_DEC = 0x0140,
|
||||
ATI_DST_BRES_LNTH_ALIAS1 = 0x0144,
|
||||
ATI_Z_OFF_PITCH = 0x0148,
|
||||
ATI_Z_CNTL = 0x014C,
|
||||
ATI_ALPHA_TST_CNTL = 0x0150,
|
||||
ATI_SRC_OFF_PITCH = 0x0180,
|
||||
ATI_SRC_X = 0x0184,
|
||||
ATI_SRC_Y = 0x0188,
|
||||
ATI_SRC_Y_X = 0x018C,
|
||||
ATI_SRC_WIDTH1 = 0x0190,
|
||||
ATI_SRC_HEIGHT1 = 0x0194,
|
||||
ATI_SRC_HEIGHT1_WIDTH1 = 0x0198,
|
||||
ATI_SRC_X_START = 0x019C,
|
||||
ATI_SRC_Y_START = 0x01A0,
|
||||
ATI_SRC_Y_X_START = 0x01A4,
|
||||
ATI_SRC_WIDTH2 = 0x01A8,
|
||||
ATI_SRC_HEIGHT2 = 0x01AC,
|
||||
ATI_SRC_HEIGHT2_WIDTH2 = 0x01B0,
|
||||
ATI_SRC_CNTL = 0x01B4,
|
||||
ATI_SCALE_OFF = 0x01C0,
|
||||
ATI_SCALE_WIDTH = 0x01DC,
|
||||
ATI_SCALE_HEIGHT = 0x01E0,
|
||||
ATI_SCALE_PITCH = 0x01EC,
|
||||
ATI_SCALE_X_INC = 0x01F0,
|
||||
ATI_SCALE_Y_INC = 0x01F4,
|
||||
ATI_SCALE_VACC = 0x01F8,
|
||||
ATI_SCALE_3D_CNTL = 0x01FC,
|
||||
ATI_HOST_CNTL = 0x0240,
|
||||
ATI_PAT_REG0 = 0x0280,
|
||||
ATI_PAT_REG1 = 0x0284,
|
||||
ATI_PAT_CNTL = 0x0288,
|
||||
ATI_SC_LEFT = 0x02A0,
|
||||
ATI_SC_RIGHT = 0x02A4,
|
||||
ATI_SC_LEFT_RIGHT = 0x02A8,
|
||||
ATI_SC_TOP = 0x02AC,
|
||||
ATI_SC_BOTTOM = 0x02B0,
|
||||
ATI_SC_TOP_BOTTOM = 0x02B4,
|
||||
ATI_DP_BKGD_CLR = 0x02C0,
|
||||
ATI_DP_FOG_CLR = 0x02C0,
|
||||
ATI_DP_WRITE_MSK = 0x02C8,
|
||||
ATI_DP_PIX_WIDTH = 0x02D0,
|
||||
ATI_DP_MIX = 0x02D4,
|
||||
ATI_DP_SRC = 0x02D8,
|
||||
ATI_FRGD_CLR_MIX = 0x02DC,
|
||||
ATI_FRGD_BKGD_CLR = 0x02E0,
|
||||
ATI_DST_X_Y = 0x02E8,
|
||||
ATI_DST_WIDTH_HEIGHT = 0x02EC,
|
||||
ATI_USR_DST_PITCH = 0x02F0,
|
||||
ATI_DP_SET_GUI_ENGINE2 = 0x02F4,
|
||||
ATI_DP_SET_GUI_ENGINE = 0x02F8,
|
||||
ATI_CLR_CMP_CLR = 0x0300,
|
||||
ATI_CLR_CMP_MSK = 0x0304,
|
||||
ATI_CLR_CMP_CNTL = 0x0308,
|
||||
ATI_FIFO_STAT = 0x0310,
|
||||
ATI_CONTEXT_MASK = 0x0320,
|
||||
ATI_GUI_TRAJ_CNTL = 0x0330,
|
||||
ATI_GUI_STAT = 0x0338,
|
||||
ATI_MPP_CONFIG = 0x04C0,
|
||||
ATI_MPP_STROBE_SEQ = 0x04C4,
|
||||
ATI_MPP_ADDR = 0x04C8,
|
||||
ATI_MPP_DATA = 0x04CC,
|
||||
ATI_TVO_CNTL = 0x0500,
|
||||
};
|
||||
|
||||
/* Mach64 PLL register indices. */
|
||||
enum {
|
||||
PLL_REF_DIV = 2, // reference divider, same for all Mach64 clocks
|
||||
PLL_VCLK_CNTL = 5,
|
||||
VCLK_POST_DIV = 6,
|
||||
VCLK0_FB_DIV = 7, // feedback divider for VCLK0
|
||||
VCLK1_FB_DIV = 8, // feedback divider for VCLK1
|
||||
VCLK2_FB_DIV = 9, // feedback divider for VCLK2
|
||||
VCLK3_FB_DIV = 10, // feedback divider for VCLK3
|
||||
PLL_EXT_CNTL = 11,
|
||||
ATI_CRTC_H_TOTAL_DISP = 0x0000,
|
||||
ATI_CRTC_H_SYNC_STRT_WID = 0x0004,
|
||||
ATI_CRTC_V_TOTAL_DISP = 0x0008,
|
||||
ATI_CRTC_V_SYNC_STRT_WID = 0x000C,
|
||||
ATI_CRTC_OFF_PITCH = 0x0014,
|
||||
ATI_CRTC_INT_CNTL = 0x0018,
|
||||
ATI_CRTC_GEN_CNTL = 0x001C,
|
||||
ATI_DSP_CONFIG = 0x0020,
|
||||
ATI_DSP_ON_OFF = 0x0024,
|
||||
ATI_TIMER_CFG = 0x0028,
|
||||
ATI_MEM_BUF_CNTL = 0x002C,
|
||||
ATI_MEM_ADDR_CFG = 0x0034,
|
||||
ATI_CRT_TRAP = 0x0038,
|
||||
ATI_I2C_CNTL_0 = 0x003C,
|
||||
ATI_OVR_CLR = 0x0040,
|
||||
ATI_OVR_WID_LEFT_RIGHT = 0x0044,
|
||||
ATI_OVR_WID_TOP_BOTTOM = 0x0048,
|
||||
ATI_VGA_DSP_CFG = 0x004C,
|
||||
ATI_VGA_DSP_TGL = 0x0050,
|
||||
ATI_DSP2_CONFIG = 0x0054,
|
||||
ATI_DSP2_TOGGLE = 0x0058,
|
||||
ATI_CRTC2_OFF_PITCH = 0x005C,
|
||||
ATI_CUR_CLR0 = 0x0060,
|
||||
ATI_CUR_CLR1 = 0x0064,
|
||||
ATI_CUR_OFFSET = 0x0068,
|
||||
ATI_CUR_HORZ_VERT_POSN = 0x006C,
|
||||
ATI_CUR_HORZ_VERT_OFF = 0x0070,
|
||||
ATI_GP_IO = 0x0078,
|
||||
ATI_HW_DEBUG = 0x007C,
|
||||
ATI_SCRATCH_REG0 = 0x0080,
|
||||
ATI_SCRATCH_REG1 = 0x0084,
|
||||
ATI_SCRATCH_REG2 = 0x0088,
|
||||
ATI_SCRATCH_REG3 = 0x008C,
|
||||
ATI_CLOCK_CNTL = 0x0090,
|
||||
ATI_CLONFIG_STAT1 = 0x0094,
|
||||
ATI_CLONFIG_STAT2 = 0x0098,
|
||||
ATI_BUS_CNTL = 0x00A0,
|
||||
ATI_EXT_MEM_CNTL = 0x00AC,
|
||||
ATI_MEM_CNTL = 0x00B0,
|
||||
ATI_VGA_WP_SEL = 0x00B4,
|
||||
ATI_VGA_RP_SEL = 0x00B8,
|
||||
ATI_I2C_CNTL_1 = 0x00BC,
|
||||
ATI_DAC_REGS = 0x00C0,
|
||||
ATI_DAC_W_INDEX = 0x00C0,
|
||||
ATI_DAC_DATA = 0x00C1,
|
||||
ATI_DAC_MASK = 0x00C2,
|
||||
ATI_DAC_R_INDEX = 0x00C3,
|
||||
ATI_DAC_CNTL = 0x00C4,
|
||||
ATI_GEN_TEST_CNTL = 0x00D0,
|
||||
ATI_CUSTOM_MACRO_CNTL = 0x00D4,
|
||||
ATI_CONFIG_CNTL = 0x00DC,
|
||||
ATI_CFG_CHIP_ID = 0x00E0,
|
||||
ATI_CFG_STAT0 = 0x00E4,
|
||||
ATI_CRC_SIG = 0x00E8,
|
||||
ATI_DST_OFF_PITCH = 0x0100,
|
||||
ATI_SRC_OFF_PITCH = 0x0180,
|
||||
ATI_HOST_CNTL = 0x0240,
|
||||
ATI_DP_WRITE_MSK = 0x02C8,
|
||||
ATI_DP_PIX_WIDTH = 0x02D0,
|
||||
ATI_DST_X_Y = 0x02E8,
|
||||
ATI_DST_WIDTH_HEIGHT = 0x02EC,
|
||||
ATI_CONTEXT_MASK = 0x0320,
|
||||
ATI_MPP_CONFIG = 0x04C0,
|
||||
ATI_MPP_STROBE_SEQ = 0x04C4,
|
||||
ATI_MPP_ADDR = 0x04C8,
|
||||
ATI_MPP_DATA = 0x04CC,
|
||||
ATI_TVO_CNTL = 0x0500,
|
||||
};
|
||||
|
||||
constexpr auto APERTURE_SIZE = 0x01000000UL; /* Mach64 aperture size */
|
||||
constexpr auto MEMMAP_OFFSET = 0x007FFC00UL; /* offset to memory mapped registers */
|
||||
|
||||
constexpr auto ATI_XTAL = 14318180.0f; // external crystal oscillator frequency
|
||||
|
||||
class ATIRage : public PCIDevice {
|
||||
public:
|
||||
ATIRage(uint16_t dev_id, uint32_t mem_amount);
|
||||
@@ -214,28 +135,23 @@ public:
|
||||
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
protected:
|
||||
uint32_t size_dep_read(uint8_t* buf, uint32_t size);
|
||||
void size_dep_write(uint8_t* buf, uint32_t val, uint32_t size);
|
||||
const char* get_reg_name(uint32_t reg_offset);
|
||||
bool io_access_allowed(uint32_t offset, uint32_t* p_io_base);
|
||||
uint32_t read_reg(uint32_t offset, uint32_t size);
|
||||
void write_reg(uint32_t offset, uint32_t value, uint32_t size);
|
||||
float calc_pll_freq(int scale, int fb_div);
|
||||
void verbose_pixel_format(int crtc_index);
|
||||
void crtc_enable();
|
||||
|
||||
private:
|
||||
uint8_t block_io_regs[512] = {0};
|
||||
// uint32_t atirage_membuf_regs[9]; /* ATI Rage Memory Buffer Registers */
|
||||
// uint32_t atirage_scratch_regs[4]; /* ATI Rage Scratch Registers */
|
||||
// uint32_t atirage_cmdfifo_regs[3]; /* ATI Rage Command FIFO Registers */
|
||||
// uint32_t atirage_datapath_regs[12]; /* ATI Rage Data Path Registers*/
|
||||
|
||||
uint8_t block_io_regs[256] = {0};
|
||||
|
||||
uint8_t pci_cfg[256] = {0}; /* PCI configuration space */
|
||||
|
||||
uint8_t plls[64] = {0}; // internal PLL registers
|
||||
|
||||
/* CRT controller parameters */
|
||||
bool crtc_on = false;
|
||||
int active_width; // width of the visible display area
|
||||
int active_height; // height of the visible display area
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
|
||||
/* Video RAM variables */
|
||||
uint32_t vram_size;
|
||||
uint8_t* vram_ptr;
|
||||
|
||||
+9
-18
@@ -27,7 +27,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <iostream>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
|
||||
/** Heathrow Mac I/O device emulation.
|
||||
|
||||
@@ -171,7 +170,7 @@ void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int
|
||||
uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
switch (offset & 0xFC) {
|
||||
switch (offset & 0xFF) {
|
||||
case 0x14:
|
||||
LOG_F(9, "read from MIO:Int_Mask2 register \n");
|
||||
res = this->int_mask2;
|
||||
@@ -197,15 +196,14 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
res = this->int_levels1;
|
||||
break;
|
||||
case 0x34: /* heathrowIDs / HEATHROW_MBCR (Linux): media bay config reg? */
|
||||
LOG_F(9, "read from MIO:ID register at Address %x \n", ppc_state.pc);
|
||||
res = this->macio_id;
|
||||
res = 0xF0700000UL;
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "read from MIO:Feat_Ctrl register \n");
|
||||
res = this->feat_ctrl;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "read from unknown MIO register at %x \n", offset);
|
||||
LOG_F(WARNING, "unknown MIO register at %x \n", offset);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -213,17 +211,17 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
}
|
||||
|
||||
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset & 0xFC) {
|
||||
switch (offset & 0xFF) {
|
||||
case 0x14:
|
||||
LOG_F(9, "write %x to MIO:Int_Mask2 register \n", value);
|
||||
LOG_F(9, "read from MIO:Int_Mask2 register \n");
|
||||
this->int_mask2 = value;
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(9, "write %x to MIO:Int_Clear2 register \n", value);
|
||||
LOG_F(9, "read from MIO:Int_Clear2 register \n");
|
||||
this->int_clear2 = value;
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(9, "write %x to MIO:Int_Levels2 register \n", value);
|
||||
LOG_F(9, "read from MIO:Int_Levels2 register \n");
|
||||
this->int_levels2 = value;
|
||||
break;
|
||||
case 0x24:
|
||||
@@ -235,22 +233,15 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->int_clear1 = value;
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(9, "write %x to MIO:Int_Levels1 register \n", value);
|
||||
LOG_F(9, "read from MIO:Int_Levels1 register \n");
|
||||
this->int_levels1 = value;
|
||||
break;
|
||||
case 0x34:
|
||||
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x \n", value, offset, ppc_state.pc);
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "write %x to MIO:Feat_Ctrl register \n", value);
|
||||
this->feat_ctrl = value;
|
||||
break;
|
||||
case 0x3C:
|
||||
LOG_F(9, "write %x to MIO:Aux_Ctrl register \n", value);
|
||||
this->aux_ctrl = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "write %x to unknown MIO register at %x \n", value, offset);
|
||||
LOG_F(WARNING, "unknown MIO register at %x \n", offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -141,9 +141,7 @@ private:
|
||||
uint32_t int_mask1 = 0;
|
||||
uint32_t int_clear1 = 0;
|
||||
uint32_t int_levels1 = 0;
|
||||
uint32_t macio_id = 0xF0700008UL;
|
||||
uint32_t feat_ctrl = 0; // features control register
|
||||
uint32_t aux_ctrl = 0; // aux features control register
|
||||
|
||||
/* device cells */
|
||||
ViaCuda* viacuda; /* VIA cell with Cuda MCU attached to it */
|
||||
|
||||
+23
-34
@@ -28,11 +28,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
MemCtrlBase::~MemCtrlBase() {
|
||||
for (auto& entry : address_map) {
|
||||
if (entry)
|
||||
delete(entry);
|
||||
}
|
||||
|
||||
for (auto& reg : mem_regions) {
|
||||
if (reg)
|
||||
delete (reg);
|
||||
@@ -44,8 +39,8 @@ MemCtrlBase::~MemCtrlBase() {
|
||||
|
||||
AddressMapEntry* MemCtrlBase::find_range(uint32_t addr) {
|
||||
for (auto& entry : address_map) {
|
||||
if (addr >= entry->start && addr <= entry->end)
|
||||
return entry;
|
||||
if (addr >= entry.start && addr <= entry.end)
|
||||
return &entry;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -54,7 +49,7 @@ AddressMapEntry* MemCtrlBase::find_range(uint32_t addr) {
|
||||
|
||||
bool MemCtrlBase::add_mem_region(
|
||||
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type, uint8_t init_val = 0) {
|
||||
AddressMapEntry *entry;
|
||||
AddressMapEntry entry;
|
||||
|
||||
/* error if a memory region for the given range already exists */
|
||||
if (find_range(start_addr) || find_range(start_addr + size))
|
||||
@@ -64,14 +59,12 @@ bool MemCtrlBase::add_mem_region(
|
||||
|
||||
this->mem_regions.push_back(reg_content);
|
||||
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + size - 1;
|
||||
entry->mirror = dest_addr;
|
||||
entry->type = type;
|
||||
entry->devobj = 0;
|
||||
entry->mem_ptr = reg_content;
|
||||
entry.start = start_addr;
|
||||
entry.end = start_addr + size - 1;
|
||||
entry.mirror = dest_addr;
|
||||
entry.type = type;
|
||||
entry.devobj = 0;
|
||||
entry.mem_ptr = reg_content;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
@@ -90,20 +83,18 @@ bool MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size) {
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
||||
AddressMapEntry *entry, *ref_entry;
|
||||
AddressMapEntry entry, *ref_entry;
|
||||
|
||||
ref_entry = find_range(dest_addr);
|
||||
if (!ref_entry)
|
||||
return false;
|
||||
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + (ref_entry->end - ref_entry->start) + 1;
|
||||
entry->mirror = dest_addr;
|
||||
entry->type = ref_entry->type | RT_MIRROR;
|
||||
entry->devobj = 0;
|
||||
entry->mem_ptr = ref_entry->mem_ptr;
|
||||
entry.start = start_addr;
|
||||
entry.end = start_addr + (ref_entry->end - ref_entry->start) + 1;
|
||||
entry.mirror = dest_addr;
|
||||
entry.type = ref_entry->type | RT_MIRROR;
|
||||
entry.devobj = 0;
|
||||
entry.mem_ptr = ref_entry->mem_ptr;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
@@ -127,20 +118,18 @@ bool MemCtrlBase::set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size
|
||||
|
||||
|
||||
bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance) {
|
||||
AddressMapEntry *entry;
|
||||
AddressMapEntry entry;
|
||||
|
||||
/* error if another region for the given range already exists */
|
||||
if (find_range(start_addr) || find_range(start_addr + size))
|
||||
return false;
|
||||
|
||||
entry = new AddressMapEntry;
|
||||
|
||||
entry->start = start_addr;
|
||||
entry->end = start_addr + size - 1;
|
||||
entry->mirror = 0;
|
||||
entry->type = RT_MMIO;
|
||||
entry->devobj = dev_instance;
|
||||
entry->mem_ptr = 0;
|
||||
entry.start = start_addr;
|
||||
entry.end = start_addr + size - 1;
|
||||
entry.mirror = 0;
|
||||
entry.type = RT_MMIO;
|
||||
entry.devobj = dev_instance;
|
||||
entry.mem_ptr = 0;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ protected:
|
||||
|
||||
private:
|
||||
std::vector<uint8_t*> mem_regions;
|
||||
std::vector<AddressMapEntry*> address_map;
|
||||
std::vector<AddressMapEntry> address_map;
|
||||
};
|
||||
|
||||
#endif /* MEMORY_CONTROLLER_BASE_H */
|
||||
+35
-6
@@ -31,7 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "memaccess.h"
|
||||
#include "memreadwrite.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "mpc106.h"
|
||||
|
||||
@@ -178,7 +178,21 @@ uint32_t MPC106::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
LOG_F(9, "read from Grackle register %08X\n", reg_offs);
|
||||
#endif
|
||||
|
||||
return read_mem(&this->my_pci_cfg_hdr[reg_offs], size);
|
||||
switch (size) {
|
||||
case 1:
|
||||
return this->my_pci_cfg_hdr[reg_offs];
|
||||
break;
|
||||
case 2:
|
||||
return READ_WORD_BE_A(&this->my_pci_cfg_hdr[reg_offs]);
|
||||
break;
|
||||
case 4:
|
||||
return READ_DWORD_BE_A(&this->my_pci_cfg_hdr[reg_offs]);
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "MPC106 read error: invalid size parameter %d \n", size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MPC106::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
@@ -187,8 +201,23 @@ void MPC106::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
#endif
|
||||
|
||||
// FIXME: implement write-protection for read-only registers
|
||||
|
||||
write_mem(&this->my_pci_cfg_hdr[reg_offs], value, size);
|
||||
switch (size) {
|
||||
case 1:
|
||||
this->my_pci_cfg_hdr[reg_offs] = value & 0xFF;
|
||||
break;
|
||||
case 2:
|
||||
this->my_pci_cfg_hdr[reg_offs] = (value >> 8) & 0xFF;
|
||||
this->my_pci_cfg_hdr[reg_offs + 1] = value & 0xFF;
|
||||
break;
|
||||
case 4:
|
||||
this->my_pci_cfg_hdr[reg_offs] = (value >> 24) & 0xFF;
|
||||
this->my_pci_cfg_hdr[reg_offs + 1] = (value >> 16) & 0xFF;
|
||||
this->my_pci_cfg_hdr[reg_offs + 2] = (value >> 8) & 0xFF;
|
||||
this->my_pci_cfg_hdr[reg_offs + 3] = value & 0xFF;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "MPC106 read error: invalid size parameter %d \n", size);
|
||||
}
|
||||
|
||||
if (this->my_pci_cfg_hdr[0xF2] & 8) {
|
||||
#ifdef MPC106_DEBUG
|
||||
@@ -242,8 +271,8 @@ void MPC106::setup_ram() {
|
||||
bank_end = (((ext_mem_end >> bank * 8) & 3) << 30) |
|
||||
(((mem_end >> bank * 8) & 0xFF) << 20) | 0xFFFFFUL;
|
||||
if (bank && bank_start != ram_size)
|
||||
LOG_F(WARNING, "MPC106: RAM not contiguous! \n");
|
||||
ram_size += bank_end - bank_start + 1;
|
||||
LOG_F(ERROR, "MPC106 error: RAM not contiguous! \n");
|
||||
ram_size += bank_end + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ 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>
|
||||
|
||||
@@ -351,6 +352,7 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "machinefactory.h"
|
||||
#include "devices/memctrlbase.h"
|
||||
#include "memaccess.h"
|
||||
#include "memreadwrite.h"
|
||||
#include "machineproperties.h"
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
@@ -61,6 +61,7 @@ static const map<uint32_t, std::tuple<string, const char*>> rom_identity = {
|
||||
{0x50444D20, {"pm6100", "Nubus Power Mac"}}, // Piltdown Man (6100/7100/8100)
|
||||
{0x50697020, {"pippin", "Bandai Pippin"}}, // Pippin
|
||||
//{"Powe", "Generic Power Mac"}, // PowerMac?
|
||||
//{"Spar", "20th Anniversay Mac"}, // Spartacus
|
||||
{0x544E5420, {"pm7200", "Power Mac 7xxxx/8xxx series"}}, // Trinitrotoluene :-)
|
||||
{0x5A616E7A, {"pm4400", "Power Mac 4400/7220"}}, // Zanzibar
|
||||
};
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include "endianswap.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -26,10 +26,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include "execution/interpreter_loop.h"
|
||||
#include "machines/machinefactory.h"
|
||||
#include "machines/machineproperties.h"
|
||||
#include "utils/profiler.h"
|
||||
#include "ppcemu.h"
|
||||
#include <cinttypes>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -41,21 +39,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace std;
|
||||
|
||||
void sigint_handler(int signum) {
|
||||
enter_debugger();
|
||||
|
||||
LOG_F(INFO, "Shutting down...");
|
||||
|
||||
delete gMachineObj.release();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void sigabrt_handler(int signum) {
|
||||
LOG_F(INFO, "Shutting down...");
|
||||
|
||||
delete gMachineObj.release();
|
||||
}
|
||||
|
||||
static string appDescription = string(
|
||||
"\nDingusPPC - Prototype 5bf5 (8/23/2020) "
|
||||
"\nWritten by divingkatae and maximumspatium "
|
||||
@@ -134,7 +117,7 @@ int main(int argc, char** argv) {
|
||||
loguru::init(argc, argv);
|
||||
loguru::add_file("dingusppc.log", loguru::Append, 0);
|
||||
} else {
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
|
||||
loguru::g_stderr_verbosity = 0;
|
||||
loguru::init(argc, argv);
|
||||
}
|
||||
|
||||
@@ -170,26 +153,10 @@ int main(int argc, char** argv) {
|
||||
cout << "BootROM path: " << bootrom_path << endl;
|
||||
cout << "Execution mode: " << execution_mode << endl;
|
||||
|
||||
// initialize global profiler object
|
||||
gProfilerObj.reset(new Profiler());
|
||||
|
||||
if (create_machine_for_id(machine_str, bootrom_path) < 0) {
|
||||
goto bail;
|
||||
}
|
||||
|
||||
// graceful handling of fatal errors
|
||||
loguru::set_fatal_handler([](const loguru::Message& message) {
|
||||
enter_debugger();
|
||||
|
||||
abort();
|
||||
});
|
||||
|
||||
// redirect SIGINT to our own handler
|
||||
signal(SIGINT, sigint_handler);
|
||||
|
||||
// redirect SIGABRT to our own handler
|
||||
signal(SIGABRT, sigabrt_handler);
|
||||
|
||||
#ifdef SDL
|
||||
if (SDL_Init(SDL_INIT_AUDIO)){
|
||||
LOG_F(ERROR, "SDL_Init error: %s", SDL_GetError());
|
||||
|
||||
-197
@@ -1,197 +0,0 @@
|
||||
/** @file Set of macros for accessing host memory in units of various sizes
|
||||
and endianness.
|
||||
*/
|
||||
|
||||
#ifndef MEM_ACCESS_H
|
||||
#define MEM_ACCESS_H
|
||||
|
||||
#include "endianswap.h"
|
||||
#include <cinttypes>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
/* read an aligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_A(addr) (BYTESWAP_16(*((uint16_t*)((addr)))))
|
||||
|
||||
/* read an aligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_A(addr) (BYTESWAP_32(*((uint32_t*)((addr)))))
|
||||
|
||||
/* read an aligned big-endian QWORD (64bit) */
|
||||
#define READ_QWORD_BE_A(addr) (BYTESWAP_64(*((uint64_t*)((addr)))))
|
||||
|
||||
/* read an aligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_A(addr) (*(uint16_t*)((addr)))
|
||||
|
||||
/* read an aligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_A(addr) (*(uint32_t*)((addr)))
|
||||
|
||||
/* read an aligned little-endian QWORD (64bit) */
|
||||
#define READ_QWORD_LE_A(addr) (*(uint64_t*)((addr)))
|
||||
|
||||
/* read an unaligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_U(addr) (((addr)[0] << 8) | (addr)[1])
|
||||
|
||||
/* read an unaligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_U(addr) \
|
||||
(((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3])
|
||||
|
||||
/* read an unaligned big-endian QWORD (32bit) */
|
||||
#define READ_QWORD_BE_U(addr) \
|
||||
((uint64_t((addr)[0]) << 56) | (uint64_t((addr)[1]) << 48) | \
|
||||
(uint64_t((addr)[2]) << 40) | (uint64_t((addr)[3]) << 32) | \
|
||||
((addr)[4] << 24) | ((addr)[5] << 16) | ((addr)[6] << 8) | (addr)[7])
|
||||
|
||||
/* read an unaligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_U(addr) (((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* read an unaligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_U(addr) \
|
||||
(((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* read an unaligned little-endian DWORD (64bit) */
|
||||
#define READ_QWORD_LE_U(addr) \
|
||||
((uint64_t((addr)[7]) << 56) | (uint64_t((addr)[6]) << 48) | \
|
||||
(uint64_t((addr)[5]) << 40) | (uint64_t((addr)[4]) << 32) | \
|
||||
((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* write an aligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_A(addr, val) (*((uint16_t*)((addr))) = BYTESWAP_16(val))
|
||||
|
||||
/* write an aligned big-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_BE_A(addr, val) (*((uint32_t*)((addr))) = BYTESWAP_32(val))
|
||||
|
||||
/* write an aligned big-endian QWORD (64bit) */
|
||||
#define WRITE_QWORD_BE_A(addr, val) (*((uint64_t*)((addr))) = BYTESWAP_64(val))
|
||||
|
||||
/* write an unaligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[1] = (val) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an unaligned big-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 24) & 0xFF; \
|
||||
(addr)[1] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[3] = (val) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an unaligned big-endian DWORD (64bit) */
|
||||
#define WRITE_QWORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((uint64_t)(val) >> 56) & 0xFF; \
|
||||
(addr)[1] = ((uint64_t)(val) >> 48) & 0xFF; \
|
||||
(addr)[2] = ((uint64_t)(val) >> 40) & 0xFF; \
|
||||
(addr)[3] = ((uint64_t)(val) >> 32) & 0xFF; \
|
||||
(addr)[4] = ((val) >> 24) & 0xFF; \
|
||||
(addr)[5] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[6] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[7] = (val) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an aligned little-endian WORD (16bit) */
|
||||
#define WRITE_WORD_LE_A(addr, val) (*((uint16_t*)((addr))) = (val))
|
||||
|
||||
/* write an aligned little-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_LE_A(addr, val) (*((uint32_t*)((addr))) = (val))
|
||||
|
||||
/* write an aligned little-endian QWORD (64bit) */
|
||||
#define WRITE_QWORD_LE_A(addr, val) (*((uint64_t*)((addr))) = (val))
|
||||
|
||||
/* write an unaligned little-endian WORD (16bit) */
|
||||
#define WRITE_WORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val)&0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an unaligned little-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val)&0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[3] = ((val) >> 24) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* read value of the specified size from memory starting at addr,
|
||||
perform byte swapping when necessary so that the source
|
||||
byte order remains unchanged. */
|
||||
inline uint32_t read_mem(const uint8_t* buf, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
return READ_DWORD_BE_A(buf);
|
||||
break;
|
||||
case 2:
|
||||
return READ_WORD_BE_A(buf);
|
||||
break;
|
||||
case 1:
|
||||
return *buf;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "READ_MEM: invalid size %d!", size);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* read value of the specified size from memory starting at addr,
|
||||
perform byte swapping when necessary so that the destination data
|
||||
will be in the reversed byte order. */
|
||||
inline uint32_t read_mem_rev(const uint8_t* buf, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
return READ_DWORD_LE_A(buf);
|
||||
break;
|
||||
case 2:
|
||||
return READ_WORD_LE_A(buf);
|
||||
break;
|
||||
case 1:
|
||||
return *buf;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "READ_MEM_REV: invalid size %d!", size);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* write the specified value of the specified size to memory pointed
|
||||
to by addr, perform necessary byte swapping so that the byte order
|
||||
of the destination remains unchanged. */
|
||||
inline void write_mem(uint8_t* buf, uint32_t value, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
WRITE_DWORD_BE_A(buf, value);
|
||||
break;
|
||||
case 2:
|
||||
WRITE_WORD_BE_A(buf, value & 0xFFFFU);
|
||||
break;
|
||||
case 1:
|
||||
*buf = value & 0xFF;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "WRITE_MEM: invalid size %d!", size);
|
||||
}
|
||||
}
|
||||
|
||||
/* write the specified value of the specified size to memory pointed
|
||||
to by addr, perform necessary byte swapping so that the destination
|
||||
data in memory will be in the reversed byte order. */
|
||||
inline void write_mem_rev(uint8_t* buf, uint32_t value, uint32_t size) {
|
||||
switch (size) {
|
||||
case 4:
|
||||
WRITE_DWORD_LE_A(buf, value);
|
||||
break;
|
||||
case 2:
|
||||
WRITE_WORD_LE_A(buf, value & 0xFFFFU);
|
||||
break;
|
||||
case 1:
|
||||
*buf = value & 0xFF;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "WRITE_MEM_REV: invalid size %d!", size);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MEM_ACCESS_H */
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/** @file Set of macros for accessing integers of various sizes and endianness
|
||||
in host memory.
|
||||
*/
|
||||
|
||||
#ifndef MEM_READ_WRITE_H
|
||||
#define MEM_READ_WRITE_H
|
||||
|
||||
#include "endianswap.h"
|
||||
#include <cinttypes>
|
||||
|
||||
/* read an aligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_A(addr) (BYTESWAP_16(*((uint16_t*)((addr)))))
|
||||
|
||||
/* read an aligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_A(addr) (BYTESWAP_32(*((uint32_t*)((addr)))))
|
||||
|
||||
/* read an aligned big-endian QWORD (64bit) */
|
||||
#define READ_QWORD_BE_A(addr) (BYTESWAP_64(*((uint64_t*)((addr)))))
|
||||
|
||||
/* read an aligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_A(addr) (*(uint16_t*)((addr)))
|
||||
|
||||
/* read an aligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_A(addr) (*(uint32_t*)((addr)))
|
||||
|
||||
/* read an aligned little-endian QWORD (64bit) */
|
||||
#define READ_QWORD_LE_A(addr) (*(uint64_t*)((addr)))
|
||||
|
||||
/* read an unaligned big-endian WORD (16bit) */
|
||||
#define READ_WORD_BE_U(addr) (((addr)[0] << 8) | (addr)[1])
|
||||
|
||||
/* read an unaligned big-endian DWORD (32bit) */
|
||||
#define READ_DWORD_BE_U(addr) (((addr)[0] << 24) | ((addr)[1] << 16) | ((addr)[2] << 8) | (addr)[3])
|
||||
|
||||
/* read an unaligned big-endian QWORD (32bit) */
|
||||
#define READ_QWORD_BE_U(addr) \
|
||||
(((addr)[0] << 56) | ((addr)[1] << 48) | ((addr)[2] << 40) | ((addr)[3] << 32) | \
|
||||
((addr)[4] << 24) | ((addr)[5] << 16) | ((addr)[6] << 8) | (addr)[7])
|
||||
|
||||
/* read an unaligned little-endian WORD (16bit) */
|
||||
#define READ_WORD_LE_U(addr) (((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* read an unaligned little-endian DWORD (32bit) */
|
||||
#define READ_DWORD_LE_U(addr) (((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
/* read an unaligned little-endian DWORD (32bit) */
|
||||
#define READ_QWORD_LE_U(addr) \
|
||||
(((addr)[7] << 56) | ((addr)[6] << 48) | ((addr)[5] << 40) | ((addr)[4] << 32) | \
|
||||
((addr)[3] << 24) | ((addr)[2] << 16) | ((addr)[1] << 8) | (addr)[0])
|
||||
|
||||
|
||||
/* write an aligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_A(addr, val) (*((uint16_t*)((addr))) = BYTESWAP_16(val))
|
||||
|
||||
/* write an aligned big-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_BE_A(addr, val) (*((uint32_t*)((addr))) = BYTESWAP_32(val))
|
||||
|
||||
/* write an aligned big-endian QWORD (64bit) */
|
||||
#define WRITE_QWORD_BE_A(addr, val) (*((uint64_t*)((addr))) = BYTESWAP_64(val))
|
||||
|
||||
/* write an unaligned big-endian WORD (16bit) */
|
||||
#define WRITE_WORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[1] = (val)&0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an unaligned big-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_BE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = ((val) >> 24) & 0xFF; \
|
||||
(addr)[1] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[3] = (val)&0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an aligned little-endian WORD (16bit) */
|
||||
#define WRITE_WORD_LE_A(addr, val) (*((uint16_t*)((addr))) = (val))
|
||||
|
||||
/* write an aligned little-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_LE_A(addr, val) (*((uint32_t*)((addr))) = (val))
|
||||
|
||||
/* write an aligned little-endian QWORD (64bit) */
|
||||
#define WRITE_QWORD_LE_A(addr, val) (*((uint64_t*)((addr))) = (val))
|
||||
|
||||
/* write an unaligned little-endian WORD (16bit) */
|
||||
#define WRITE_WORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val)&0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
/* write an unaligned little-endian DWORD (32bit) */
|
||||
#define WRITE_DWORD_LE_U(addr, val) \
|
||||
do { \
|
||||
(addr)[0] = (val)&0xFF; \
|
||||
(addr)[1] = ((val) >> 8) & 0xFF; \
|
||||
(addr)[2] = ((val) >> 16) & 0xFF; \
|
||||
(addr)[3] = ((val) >> 24) & 0xFF; \
|
||||
} while (0)
|
||||
|
||||
#endif /* MEM_READ_WRITE_H */
|
||||
Vendored
-1
Submodule thirdparty/capstone deleted from bfb2e45d76.
@@ -1,6 +0,0 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(utils OBJECT ${SOURCES})
|
||||
target_link_libraries(utils PRIVATE cubeb)
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
#include "profiler.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
/** global profiler object */
|
||||
std::unique_ptr<Profiler> gProfilerObj = 0;
|
||||
|
||||
Profiler::Profiler()
|
||||
{
|
||||
this->profiles_map.clear();
|
||||
}
|
||||
|
||||
bool Profiler::register_profile(std::string name,
|
||||
std::unique_ptr<BaseProfile> profile_obj)
|
||||
{
|
||||
// bail out if a profile corresponding to 'name' already exists
|
||||
if (this->profiles_map.find(name) != this->profiles_map.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->profiles_map[name] = std::move(profile_obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Profiler::print_profile(std::string name)
|
||||
{
|
||||
if (this->profiles_map.find(name) == this->profiles_map.end()) {
|
||||
std::cout << "Profile " << name << " not found." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Summary of the profile '" << name << "':" << std::endl;
|
||||
std::cout << "------------------------------------------" << std::endl;
|
||||
|
||||
auto prof_it = this->profiles_map.find(name);
|
||||
|
||||
std::vector<ProfileVar> vars;
|
||||
|
||||
// ask the corresponding profile class to fill its variables for us
|
||||
prof_it->second->populate_variables(vars);
|
||||
|
||||
for (auto& var : vars) {
|
||||
switch(var.format) {
|
||||
case ProfileVarFmt::DEC:
|
||||
std::cout << var.name << " : " << var.value << std::endl;
|
||||
break;
|
||||
case ProfileVarFmt::HEX:
|
||||
std::cout << var.name << " : " << std::hex << var.value << std::endl;
|
||||
break;
|
||||
default:
|
||||
std::cout << "Unknown value in variable " << var.name << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void Profiler::reset_profile(std::string name)
|
||||
{
|
||||
if (this->profiles_map.find(name) == this->profiles_map.end()) {
|
||||
std::cout << "Profile " << name << " not found." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
this->profiles_map.find(name)->second->reset();
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 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/>.
|
||||
*/
|
||||
|
||||
/** Interface definition for the Profiler.
|
||||
*/
|
||||
|
||||
#ifndef PROFILER_H
|
||||
#define PROFILER_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum class ProfileVarFmt { DEC, HEX };
|
||||
|
||||
/** Define a special data type for profile variables. */
|
||||
typedef struct ProfileVar {
|
||||
std::string name;
|
||||
ProfileVarFmt format;
|
||||
uint64_t value;
|
||||
} ProfileVar;
|
||||
|
||||
/** Base class for user-defined profiles. */
|
||||
class BaseProfile {
|
||||
public:
|
||||
BaseProfile(std::string name) { this->name = name; };
|
||||
|
||||
virtual ~BaseProfile() = default;
|
||||
|
||||
virtual void populate_variables(std::vector<ProfileVar>& vars) = 0;
|
||||
|
||||
virtual void reset(void) = 0; // reset profile counters
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
/** Profiler class for managing of user-defined profiles. */
|
||||
class Profiler {
|
||||
public:
|
||||
Profiler();
|
||||
|
||||
virtual ~Profiler() = default;
|
||||
|
||||
bool register_profile(std::string name, std::unique_ptr<BaseProfile> profile_obj);
|
||||
|
||||
void print_profile(std::string name);
|
||||
|
||||
void reset_profile(std::string name);
|
||||
|
||||
private:
|
||||
std::map<std::string, std::unique_ptr<BaseProfile>> profiles_map;
|
||||
};
|
||||
|
||||
extern std::unique_ptr<Profiler> gProfilerObj;
|
||||
|
||||
#endif /* PROFILER_H */
|
||||
@@ -1,23 +0,0 @@
|
||||
## Disabling BAT translation
|
||||
|
||||
BAT translation can be disabled by invalidating BAT registers. This is somewhat CPU specific.
|
||||
MPC601 implements its own format for BAT registers that differs from the PowerPC specification.
|
||||
|
||||
MPC601-specific lower BAT registers has the "V" bit. If it's cleared, the corresponding BAT pair
|
||||
is invalid and won't be used for address translation. To invalidate BATs on MPC601, it's enough
|
||||
to write NULL to lower BAT registers. That's exactly what PowerMac 6100 ROM does:
|
||||
```
|
||||
li r0, 0
|
||||
mtspr ibat0l, r0
|
||||
mtspr ibat1l, r0
|
||||
mtspr ibat2l, r0
|
||||
```
|
||||
|
||||
PowerPC CPUs starting with 603 uses the BAT register format described in the PowerPC specification.
|
||||
The upper BAT registers contain two bits: Vs (supervisor state valid bit) and Vp (problem/user state valid bit).
|
||||
PowerPC Architecture First Edition from 1993 gives the following code:
|
||||
|
||||
```BAT_entry_valid = (Vs & ~MSR_PR) | (Vp & MSR_PR)```
|
||||
|
||||
If neither Vs nor Vp is set, the corresponding BAT pair isn't valid and doesn't participate in address translation.
|
||||
To invalidate BATs on non-601, it's sufficient to set the upper BAT register to 0x00000000.
|
||||
@@ -1,107 +0,0 @@
|
||||
# PowerPC Memory Management Unit Emulation
|
||||
|
||||
Emulation of a [memory management unit](https://en.wikipedia.org/wiki/Memory_management_unit)
|
||||
(MMU) in a full system emulator is considered a hard task. The biggest challenge is to do it fast.
|
||||
|
||||
In this article, I'm going to present a solution for a reasonably fast emulation
|
||||
of the PowerPC MMU.
|
||||
|
||||
This article is based on ideas presented in the paper "Optimizing Memory Emulation
|
||||
in Full System Emulators" by Xin Tong and Motohiro Kawahito (IBM Research Laboratory).
|
||||
|
||||
## PowerPC MMU operation
|
||||
|
||||
The operation of the PowerPC MMU can be described using the following pseudocode:
|
||||
|
||||
```
|
||||
VA is the virtual address of some memory to be accessed
|
||||
PA is the physical address of some memory translated by the MMU
|
||||
AT is access type we want to perform
|
||||
|
||||
if address translation is enabled:
|
||||
PA = block_address_translation(VA)
|
||||
if not PA:
|
||||
PA = page_address_translation(VA)
|
||||
else:
|
||||
PA = VA
|
||||
|
||||
if access_permitted(PA, AT):
|
||||
perfom_phys_access(PA)
|
||||
else:
|
||||
generate_mmu_exception(VA, PA, AT)
|
||||
```
|
||||
|
||||
A HW MMU usually performs several operations in a parallel fashion so the final
|
||||
address translation and memory access only take a few CPU cycles.
|
||||
The slowest part is the page address translation because it requires accessing
|
||||
system memory that is usually an order of magnitudes slower than the CPU.
|
||||
To mitigate this, a PowerPC CPU includes some very fast on-chip memory used for
|
||||
building various [caches](https://en.wikipedia.org/wiki/CPU_cache) like
|
||||
instruction/data cache as well as
|
||||
[translation lookaside buffers (TLB)](https://en.wikipedia.org/wiki/Translation_lookaside_buffer).
|
||||
|
||||
## PowerPC MMU emulation
|
||||
|
||||
### Issues
|
||||
|
||||
An attempt to mimic the HW MMU operation in software will likely have a poor
|
||||
performance. That's because modern hardware can perform several tasks in parallel.
|
||||
However, software has to do almost everything serially. Thus, accessing some memory
|
||||
with address translation enabled can take up to 300 host instructions! Considering
|
||||
the fact that every 10th instruction is a load and every 15th instruction is a store,
|
||||
it will be nearly impossible to achieve a performance comparable to that of the
|
||||
original system.
|
||||
|
||||
Off-loading some operations to the MMU of the host CPU for speeding up emulation
|
||||
isn't feasible because Apple's computers often have hardware being accessed like an
|
||||
usual memory. Thus, an emulator needs to distinguish between accesses to real memory
|
||||
(ROM or RAM) from accesses to memory-mapped peripheral devices. The only way to
|
||||
do that is to maintain special software descriptors for each virtual memory region
|
||||
and consult them on each memory access.
|
||||
|
||||
### Solution
|
||||
|
||||
My solution for a reasonable fast MMU emulation employs a software TLB. It's
|
||||
used for all memory accesses even when address translation is disabled.
|
||||
|
||||
The first stage of the SoftTLB uses a
|
||||
[direct-mapped cache](https://en.wikipedia.org/wiki/Cache_placement_policies#Direct-mapped_cache)
|
||||
called **primary TLB** in my implementation. That's because this kind of cache
|
||||
is the fastest one - one lookup requires up to 15 host instructions. Unfortunately,
|
||||
this cache is not enough to cover all memory accesses due to a high number of
|
||||
collisions, i.e. when several distinct memory pages are mapped to the same cache
|
||||
location.
|
||||
|
||||
That's why, the so-called **secondary TLB** was introduced. Secondary TLB is a
|
||||
4-way fully associative cache. A lookup in this cache is slower than a lookup in the
|
||||
primary TLB. But it's still much faster than performing a full page table walk
|
||||
requiring hundreds of host instructions.
|
||||
|
||||
All translations for memory-mapped I/O go into the secondary TLB because accesses
|
||||
to such devices tend to be slower than real memory accesses in the real HW anyways.
|
||||
Moreover, they usually bypass CPU caches (cache-inhibited accesses). But there
|
||||
are exceptions from this rule, for example, video memory.
|
||||
|
||||
When no translation for a virtual address was found in either cache, a full address
|
||||
translation including the full page table walk is performed. This path is the
|
||||
slowest one. Fortunately, the probabilty that this path will be taken seems to be
|
||||
very low.
|
||||
|
||||
The complete algorithm looks like that:
|
||||
```
|
||||
VA is the virtual address of some memory to be accessed
|
||||
PA is the physical address of some memory translated by the MMU
|
||||
AT is access type we want to perform
|
||||
|
||||
PA = lookup_primary_tlb(VA)
|
||||
if VA in the primary TLB:
|
||||
perform_memory_access(PA, ART)
|
||||
else:
|
||||
PA = lookup_secondary_tlb(VA)
|
||||
if VA not in the secondary TLB:
|
||||
PA = perform_full_address_translation(VA)
|
||||
refill_secondary_tlb(VA, PA)
|
||||
if is_real_memory(PA):
|
||||
refill_primary_tlb(VA, PA)
|
||||
perform_memory_access(PA, ART)
|
||||
```
|
||||
Reference in new issue
Block a user