mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40d0aa70da | ||
|
|
212cd58f40 | ||
|
|
5b54cd69ef | ||
|
|
501f24f0d3 | ||
|
|
2a79c9a63c | ||
|
|
c5f45c6f9a | ||
|
|
a8f400287a | ||
|
|
089645e830 | ||
|
|
4f3dd797be | ||
|
|
094d9a9c2f | ||
|
|
4da95a66d7 | ||
|
|
592d32017e | ||
|
|
7d8f4d4e61 | ||
|
|
a5ddb51a3b | ||
|
|
05330bc942 | ||
|
|
6f9ee10de5 | ||
|
|
0c1c59ffa7 | ||
|
|
048b4f5f20 | ||
|
|
085877a8bf | ||
|
|
bc59bf7c43 | ||
|
|
ed6c316c82 | ||
|
|
31b5290ac9 | ||
|
|
0375b6a687 | ||
|
|
d545780071 | ||
|
|
e7e28b4497 | ||
|
|
baa7f8b211 | ||
|
|
2f4a3b955e | ||
|
|
19ca37c4ba | ||
|
|
a4eb658309 | ||
|
|
508ef2eaa9 | ||
|
|
a5ef814ec4 | ||
|
|
ace19c0bdf | ||
|
|
3a9ed2671c | ||
|
|
3c787a87cd | ||
|
|
ce70b0f096 | ||
|
|
a0b43754a7 | ||
|
|
1adbf90e21 | ||
|
|
aa0f43d89f | ||
|
|
478ca1065f | ||
|
|
7628ec92c0 | ||
|
|
7f0acaf3d3 | ||
|
|
5961552ed9 | ||
|
|
2141a72b87 | ||
|
|
9683c660bc | ||
|
|
d8397906c2 | ||
|
|
fd0f8e2ef5 | ||
|
|
60f84ef0d9 | ||
|
|
2f8694e57c | ||
|
|
593230f326 | ||
|
|
680b437b74 | ||
|
|
3189876d41 | ||
|
|
2539faef7e | ||
|
|
42184213e9 | ||
|
|
bb3f4e596e | ||
|
|
014eefdf7e | ||
|
|
d8f7588693 | ||
|
|
2bac606365 | ||
|
|
df8ea1b276 | ||
|
|
9210244c0c | ||
|
|
358f018815 | ||
|
|
14d3874382 | ||
|
|
b230299076 | ||
|
|
79e3d398ba | ||
|
|
2f3938c23f | ||
|
|
dbbaf13a78 | ||
|
|
99641b1b5e | ||
|
|
5cba9c1dae | ||
|
|
180cb0d25f | ||
|
|
df39a59190 | ||
|
|
f0315e98ee | ||
|
|
6c6247b94f | ||
|
|
f61277e46d | ||
|
|
da3a6c71fd | ||
|
|
acfa09af65 | ||
|
|
54fcfca8e9 | ||
|
|
a775007d3a | ||
|
|
2be8e7b542 | ||
|
|
0e83ffe435 | ||
|
|
0c202b0c2d | ||
|
|
81b3c3c4a0 | ||
|
|
7be6cb30ac | ||
|
|
6124dfd897 | ||
|
|
b81de4af48 | ||
|
|
2b19b0b237 | ||
|
|
f417df0630 | ||
|
|
1fe9ffe3e5 | ||
|
|
dc58386237 | ||
|
|
6cc88d3b02 | ||
|
|
5d2f3ca3c0 | ||
|
|
3b29ff9514 | ||
|
|
fc50e3c4f6 | ||
|
|
353035e9ca | ||
|
|
660d227ac7 | ||
|
|
b9dcfef551 | ||
|
|
6b74e358dc |
No files matched your search
@@ -1,3 +1,7 @@
|
||||
[submodule "thirdparty/cubeb"]
|
||||
path = thirdparty/cubeb
|
||||
url = https://github.com/DingusDevOrg/cubeb.git
|
||||
[submodule "thirdparty/capstone"]
|
||||
path = thirdparty/capstone
|
||||
url = https://github.com/maximumspatium/capstone.git
|
||||
branch = next
|
||||
+97
-21
@@ -16,10 +16,50 @@ 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")
|
||||
@@ -40,6 +80,7 @@ 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")
|
||||
@@ -57,7 +98,9 @@ file(GLOB TEST_SOURCES "${PROJECT_SOURCE_DIR}/cpu/ppc/test/*.cpp")
|
||||
add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:execution>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
$<TARGET_OBJECTS:utils>
|
||||
$<TARGET_OBJECTS:loguru>)
|
||||
|
||||
if (WIN32)
|
||||
@@ -70,27 +113,60 @@ target_link_libraries(dingusppc cubeb ${SDL2_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE
|
||||
target_include_directories(dingusppc PRIVATE ${CLI11_ROOT})
|
||||
endif()
|
||||
|
||||
|
||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<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})
|
||||
if (ENABLE_68K_DEBUGGER)
|
||||
target_link_libraries(dingusppc capstone-static)
|
||||
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_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>)
|
||||
|
||||
install (TARGETS dingusppc DESTINATION ${EXECUTABLE_OUTPUT_PATH})
|
||||
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 (ENABLE_68K_DEBUGGER)
|
||||
target_link_libraries(testppc capstone-static)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
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)
|
||||
@@ -8,8 +8,7 @@ Be warned the program is highly unfinished and could use a lot of testing. Any f
|
||||
|
||||
While many other PowerPC emus exist (PearPC, Sheepshaver), none of them currently attempt emulation of PPC Macs accurately (except for QEMU).
|
||||
|
||||
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs,
|
||||
including those of the PowerMac G3 Beige.
|
||||
This program aims to not only improve upon what Sheepshaver, PearPC, and other PowerPC mac emulators have done, but also to provide a better debugging environment. This currently is designed to work best with PowerPC Old World ROMs, including those of the PowerMac G3 Beige.
|
||||
|
||||
## Implemented Features
|
||||
|
||||
@@ -21,23 +20,46 @@ This program currently uses the command prompt to work.
|
||||
|
||||
There are a few command line arguments one must enter when starting the program.
|
||||
|
||||
-realtime
|
||||
```
|
||||
-r, --realtime
|
||||
```
|
||||
|
||||
Run the emulator in runtime.
|
||||
|
||||
-debugger
|
||||
```
|
||||
-d, --debugger
|
||||
```
|
||||
|
||||
Enter the interactive debugger.
|
||||
|
||||
You must also provide config.txt.
|
||||
```
|
||||
-b, --bootrom TEXT:FILE
|
||||
```
|
||||
|
||||
Specifies the Boot ROM path (optional; looks for bootrom.bin by default)
|
||||
|
||||
```
|
||||
-m, --machine TEXT
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
## How to Compile
|
||||
|
||||
You'll need to install development tools first.
|
||||
You need to install development tools first.
|
||||
|
||||
At least, a C++ compiler and [CMake](https://cmake.org) are required.
|
||||
At least, a C++11 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
|
||||
For example, to build the project in a Unix-like environment, you'll need to run
|
||||
You will also have to recursive clone or run
|
||||
```
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
This is because the CubeB module is not included by default. All other components are already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
|
||||
For example, to build the project in a Unix-like environment, you will need to run
|
||||
the following commands in the OS terminal:
|
||||
```
|
||||
mkdir build
|
||||
@@ -47,9 +69,12 @@ make dingusppc
|
||||
```
|
||||
You may specify another build type using the variable CMAKE_BUILD_TYPE.
|
||||
|
||||
Due to the incomplete status of the program at this time, only Loguru is needed to compile the program. It is already included in the thirdparty folder and compiled along with the rest of DingusPPC.
|
||||
Future versions may drop SDL 2 as a requirement.
|
||||
|
||||
Future versions will include SDL 2 as a requirement.
|
||||
For Raspbian, you may also need the following command:
|
||||
```
|
||||
sudo apt install doxygen graphviz
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
#include <stdlib.h>
|
||||
#include <chrono>
|
||||
#include "cpu/ppc/ppcemu.h"
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "devices/mpc106.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
uint32_t cs_code[] = {
|
||||
0x3863FFFC, 0x7C861671, 0x41820090, 0x70600002, 0x41E2001C, 0xA0030004,
|
||||
0x3884FFFE, 0x38630002, 0x5486F0BF, 0x7CA50114, 0x41820070, 0x70C60003,
|
||||
0x41820014, 0x7CC903A6, 0x84030004, 0x7CA50114, 0x4200FFF8, 0x5486E13F,
|
||||
0x41820050, 0x80030004, 0x7CC903A6, 0x80C30008, 0x7CA50114, 0x80E3000C,
|
||||
0x7CA53114, 0x85030010, 0x7CA53914, 0x42400028, 0x80030004, 0x7CA54114,
|
||||
0x80C30008, 0x7CA50114, 0x80E3000C, 0x7CA53114, 0x85030010, 0x7CA53914,
|
||||
0x4200FFE0, 0x7CA54114, 0x70800002, 0x41E20010, 0xA0030004, 0x38630002,
|
||||
0x7CA50114, 0x70800001, 0x41E20010, 0x88030004, 0x5400402E, 0x7CA50114,
|
||||
0x7C650194, 0x4E800020
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int i;
|
||||
|
||||
/* initialize logging */
|
||||
loguru::g_preamble_date = false;
|
||||
loguru::g_preamble_time = false;
|
||||
loguru::g_preamble_thread = false;
|
||||
|
||||
loguru::g_stderr_verbosity = 0;
|
||||
loguru::init(argc, argv);
|
||||
|
||||
MPC106* grackle_obj = new MPC106;
|
||||
|
||||
/* we need some RAM */
|
||||
if (!grackle_obj->add_ram_region(0, 0x9000)) {
|
||||
LOG_F(ERROR, "Could not create RAM region");
|
||||
delete(grackle_obj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750);
|
||||
|
||||
/* load executable code into RAM at address 0 */
|
||||
for (i = 0; i < sizeof(cs_code); i++) {
|
||||
mem_write_dword(i*4, cs_code[i]);
|
||||
}
|
||||
|
||||
srand(0xCAFEBABE);
|
||||
|
||||
for (i = 0; i < 32768; i++) {
|
||||
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
|
||||
|
||||
ppc_exec_until(0xC4);
|
||||
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
|
||||
// run the clock once for cache fill etc.
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
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
|
||||
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
ppc_exec_until(0xC4);
|
||||
|
||||
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;
|
||||
}
|
||||
+126
-410
@@ -24,62 +24,42 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
|
||||
void power_abs() {
|
||||
// Affects the XER register's SO and OV Bits
|
||||
|
||||
inline void power_setsoov(uint32_t a, uint32_t b, uint32_t d) {
|
||||
if ((a ^ b) & (a ^ d) & 0x80000000UL) {
|
||||
ppc_state.spr[SPR::XER] |= 0xC0000000UL;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= 0xBFFFFFFFUL;
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::power_abs() {
|
||||
ppc_grab_regsda();
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
if (oe_flag)
|
||||
ppc_state.spr[SPR::XER] |= 0x40000000;
|
||||
|
||||
} else {
|
||||
ppc_result_d = ppc_result_a & 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
|
||||
void power_absdot() {
|
||||
ppc_grab_regsda();
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
|
||||
} else {
|
||||
ppc_result_d = ppc_result_a & 0x7FFFFFFF;
|
||||
}
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void power_abso() {
|
||||
ppc_grab_regsda();
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
ppc_state.spr[SPR::XER] |= 0x40000000;
|
||||
|
||||
} else {
|
||||
ppc_result_d = ppc_result_a & 0x7FFFFFFF;
|
||||
}
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void power_absodot() {
|
||||
ppc_grab_regsda();
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
ppc_state.spr[SPR::XER] |= 0x40000000;
|
||||
|
||||
} else {
|
||||
ppc_result_d = ppc_result_a & 0x7FFFFFFF;
|
||||
}
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void power_clcs() {
|
||||
void dppc_interpreter::power_clcs() {
|
||||
ppc_grab_regsda();
|
||||
switch (reg_a) {
|
||||
case 12:
|
||||
@@ -91,107 +71,56 @@ void power_clcs() {
|
||||
default:
|
||||
ppc_result_d = 0;
|
||||
}
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void power_clcsdot() {
|
||||
switch (reg_a) {
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
ppc_result_d = 65535;
|
||||
break;
|
||||
default:
|
||||
ppc_result_d = 0;
|
||||
if (rc_flag) {
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
printf("Does RC do anything here? (TODO) \n");
|
||||
}
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
printf("Does RC do anything here? (TODO) \n");
|
||||
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void power_div() {
|
||||
void dppc_interpreter::power_div() {
|
||||
ppc_grab_regsdab();
|
||||
ppc_result_d = (ppc_result_a | ppc_state.spr[SPR::MQ]) / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a | ppc_state.spr[SPR::MQ]) % ppc_result_b;
|
||||
|
||||
if (oe_flag)
|
||||
power_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void power_divdot() {
|
||||
ppc_result_d = (ppc_result_a | ppc_state.spr[SPR::MQ]) / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a | ppc_state.spr[SPR::MQ]) % ppc_result_b;
|
||||
}
|
||||
|
||||
void power_divo() {
|
||||
ppc_result_d = (ppc_result_a | ppc_state.spr[SPR::MQ]) / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a | ppc_state.spr[SPR::MQ]) % ppc_result_b;
|
||||
}
|
||||
|
||||
void power_divodot() {
|
||||
ppc_result_d = (ppc_result_a | ppc_state.spr[SPR::MQ]) / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a | ppc_state.spr[SPR::MQ]) % ppc_result_b;
|
||||
}
|
||||
|
||||
void power_divs() {
|
||||
void dppc_interpreter::power_divs() {
|
||||
ppc_grab_regsdab();
|
||||
ppc_result_d = ppc_result_a / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a % ppc_result_b);
|
||||
|
||||
if (oe_flag)
|
||||
power_setsoov(ppc_result_b, ppc_result_a, ppc_result_d);
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void power_divsdot() {
|
||||
ppc_result_d = ppc_result_a / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a % ppc_result_b);
|
||||
}
|
||||
|
||||
void power_divso() {
|
||||
ppc_result_d = ppc_result_a / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a % ppc_result_b);
|
||||
}
|
||||
|
||||
void power_divsodot() {
|
||||
ppc_result_d = ppc_result_a / ppc_result_b;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_a % ppc_result_b);
|
||||
}
|
||||
|
||||
void power_doz() {
|
||||
void dppc_interpreter::power_doz() {
|
||||
ppc_grab_regsdab();
|
||||
if (((int32_t)ppc_result_a) > ((int32_t)ppc_result_b)) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
ppc_result_d = ~ppc_result_a + ppc_result_b + 1;
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_dozdot() {
|
||||
ppc_grab_regsdab();
|
||||
if (((int32_t)ppc_result_a) > ((int32_t)ppc_result_b)) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
ppc_result_d = ~ppc_result_a + ppc_result_b + 1;
|
||||
}
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_dozo() {
|
||||
if (((int32_t)ppc_result_a) > ((int32_t)ppc_result_b)) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
ppc_result_d = ~ppc_result_a + ppc_result_b + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void power_dozodot() {
|
||||
if (((int32_t)ppc_result_a) > ((int32_t)ppc_result_b)) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
ppc_result_d = ~ppc_result_a + ppc_result_b + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void power_dozi() {
|
||||
void dppc_interpreter::power_dozi() {
|
||||
ppc_grab_regsdab();
|
||||
if (((int32_t)ppc_result_a) > simm) {
|
||||
ppc_result_d = 0;
|
||||
@@ -201,7 +130,7 @@ void power_dozi() {
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_lscbx() {
|
||||
void dppc_interpreter::power_lscbx() {
|
||||
ppc_grab_regsdab();
|
||||
uint32_t bytes_copied = 0;
|
||||
bool match_found = false;
|
||||
@@ -219,22 +148,26 @@ void power_lscbx() {
|
||||
if (match_found == false) {
|
||||
switch (shift_amount) {
|
||||
case 0:
|
||||
return_value = mem_grab_byte(ppc_effective_address);
|
||||
return_value = mmu_read_vmem<uint8_t>(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 = mem_grab_byte(ppc_effective_address);
|
||||
return_value = mmu_read_vmem<uint8_t>(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 = mem_grab_byte(ppc_effective_address);
|
||||
return_value = mmu_read_vmem<uint8_t>(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 = mem_grab_byte(ppc_effective_address);
|
||||
return_value = mmu_read_vmem<uint8_t>(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;
|
||||
@@ -254,14 +187,15 @@ void power_lscbx() {
|
||||
}
|
||||
} while (bytes_to_load > 0);
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & 0xFFFFFF80) | bytes_copied;
|
||||
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void power_lscbxdot() {
|
||||
printf("OOPS! Placeholder!!! \n");
|
||||
}
|
||||
|
||||
void power_maskg() {
|
||||
void dppc_interpreter::power_maskg() {
|
||||
ppc_grab_regssab();
|
||||
uint32_t mask_start = ppc_result_d & 31;
|
||||
uint32_t mask_end = ppc_result_b & 31;
|
||||
@@ -281,33 +215,14 @@ void power_maskg() {
|
||||
}
|
||||
|
||||
ppc_result_a = insert_mask;
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_maskgdot() {
|
||||
ppc_grab_regssab();
|
||||
uint32_t mask_start = ppc_result_d & 31;
|
||||
uint32_t mask_end = ppc_result_b & 31;
|
||||
uint32_t insert_mask = 0;
|
||||
|
||||
if (mask_start < (mask_end + 1)) {
|
||||
for (uint32_t i = mask_start; i < mask_end; i++) {
|
||||
insert_mask |= (0x80000000 >> i);
|
||||
}
|
||||
} else if (mask_start == (mask_end + 1)) {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
} else {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
for (uint32_t i = (mask_end + 1); i < (mask_start - 1); i++) {
|
||||
insert_mask &= (~(0x80000000 >> i));
|
||||
}
|
||||
}
|
||||
|
||||
ppc_result_a = insert_mask;
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_maskir() {
|
||||
void dppc_interpreter::power_maskir() {
|
||||
ppc_grab_regssab();
|
||||
uint32_t mask_insert = ppc_result_a;
|
||||
uint32_t insert_rot = 0x80000000;
|
||||
@@ -320,82 +235,38 @@ void power_maskir() {
|
||||
} while (insert_rot > 0);
|
||||
|
||||
ppc_result_a = (ppc_result_d & ppc_result_b);
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_maskirdot() {
|
||||
ppc_grab_regssab();
|
||||
uint32_t mask_insert = ppc_result_a;
|
||||
uint32_t insert_rot = 0x80000000;
|
||||
do {
|
||||
if (ppc_result_b & insert_rot) {
|
||||
mask_insert &= ~insert_rot;
|
||||
mask_insert |= (ppc_result_d & insert_rot);
|
||||
}
|
||||
insert_rot = insert_rot >> 1;
|
||||
} while (insert_rot > 0);
|
||||
|
||||
ppc_result_a = (ppc_result_d & ppc_result_b);
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_mul() {
|
||||
void dppc_interpreter::power_mul() {
|
||||
ppc_grab_regsdab();
|
||||
uint64_t product;
|
||||
|
||||
product = ((uint64_t)ppc_result_a) * ((uint64_t)ppc_result_b);
|
||||
ppc_result_d = ((uint32_t)(product >> 32));
|
||||
ppc_state.spr[SPR::MQ] = ((uint32_t)(product));
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void power_muldot() {
|
||||
ppc_grab_regsdab();
|
||||
uint64_t product;
|
||||
|
||||
product = ((uint64_t)ppc_result_a) * ((uint64_t)ppc_result_b);
|
||||
ppc_result_d = ((uint32_t)(product >> 32));
|
||||
ppc_state.spr[SPR::MQ] = ((uint32_t)(product));
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void power_mulo() {
|
||||
uint64_t product;
|
||||
|
||||
product = ((uint64_t)ppc_result_a) * ((uint64_t)ppc_result_b);
|
||||
ppc_result_d = ((uint32_t)(product >> 32));
|
||||
ppc_state.spr[SPR::MQ] = ((uint32_t)(product));
|
||||
}
|
||||
|
||||
void power_mulodot() {
|
||||
uint64_t product;
|
||||
|
||||
product = ((uint64_t)ppc_result_a) * ((uint64_t)ppc_result_b);
|
||||
ppc_result_d = ((uint32_t)(product >> 32));
|
||||
ppc_state.spr[SPR::MQ] = ((uint32_t)(product));
|
||||
}
|
||||
|
||||
void power_nabs() {
|
||||
void dppc_interpreter::power_nabs() {
|
||||
ppc_grab_regsda();
|
||||
ppc_result_d = (0x80000000 | ppc_result_a);
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
void power_nabsdot() {
|
||||
ppc_result_d = (0x80000000 | ppc_result_a);
|
||||
}
|
||||
|
||||
void power_nabso() {
|
||||
ppc_result_d = (0x80000000 | ppc_result_a);
|
||||
}
|
||||
|
||||
void power_nabsodot() {
|
||||
ppc_result_d = (0x80000000 | ppc_result_a);
|
||||
}
|
||||
|
||||
void power_rlmi() {
|
||||
void dppc_interpreter::power_rlmi() {
|
||||
ppc_grab_regssab();
|
||||
unsigned rot_mb = (ppc_cur_instruction >> 6) & 31;
|
||||
unsigned rot_me = (ppc_cur_instruction >> 1) & 31;
|
||||
@@ -420,28 +291,22 @@ void power_rlmi() {
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_rrib() {
|
||||
void dppc_interpreter::power_rrib() {
|
||||
ppc_grab_regssab();
|
||||
|
||||
if (ppc_result_d & 0x80000000) {
|
||||
ppc_result_a |= (0x80000000 >> ppc_result_b);
|
||||
} else {
|
||||
ppc_result_a &= ~(0x80000000 >> ppc_result_b);
|
||||
}
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_rribdot() {
|
||||
ppc_grab_regssab();
|
||||
if (ppc_result_d & 0x80000000) {
|
||||
ppc_result_a |= (0x80000000 >> ppc_result_b);
|
||||
} else {
|
||||
ppc_result_a &= ~(0x80000000 >> ppc_result_b);
|
||||
}
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_sle() {
|
||||
void dppc_interpreter::power_sle() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
uint32_t rot_amt = ppc_result_b & 31;
|
||||
@@ -451,24 +316,14 @@ void power_sle() {
|
||||
uint32_t insert_final = ((ppc_result_d << rot_amt) | (ppc_result_d >> (32 - rot_amt)));
|
||||
ppc_state.spr[SPR::MQ] = insert_final & insert_mask;
|
||||
ppc_result_a = insert_final & insert_mask;
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_sledot() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
uint32_t rot_amt = ppc_result_b & 31;
|
||||
for (uint32_t i = 31; i > rot_amt; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_final = ((ppc_result_d << rot_amt) | (ppc_result_d >> (32 - rot_amt)));
|
||||
ppc_state.spr[SPR::MQ] = insert_final & insert_mask;
|
||||
ppc_result_a = insert_final & insert_mask;
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_sleq() {
|
||||
void dppc_interpreter::power_sleq() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
uint32_t rot_amt = ppc_result_b & 31;
|
||||
@@ -487,33 +342,14 @@ void power_sleq() {
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_sleqdot() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
uint32_t rot_amt = ppc_result_b & 31;
|
||||
for (uint32_t i = 31; i > rot_amt; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_start = ((ppc_result_d << rot_amt) | (ppc_result_d >> (rot_amt - 31)));
|
||||
uint32_t insert_end = ppc_state.spr[SPR::MQ];
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (insert_mask & (1 << i)) {
|
||||
insert_end &= ~(1 << i);
|
||||
insert_end |= (insert_start & (1 << i));
|
||||
}
|
||||
}
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_sliq() {
|
||||
void dppc_interpreter::power_sliq() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
@@ -532,33 +368,14 @@ void power_sliq() {
|
||||
|
||||
ppc_result_a = insert_end & insert_mask;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_sliqdot() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
for (uint32_t i = 31; i > rot_sh; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_start = ((ppc_result_d << rot_sh) | (ppc_result_d >> (rot_sh - 31)));
|
||||
uint32_t insert_end = ppc_state.spr[SPR::MQ];
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (insert_mask & (1 << i)) {
|
||||
insert_end &= ~(1 << i);
|
||||
insert_end |= (insert_start & (1 << i));
|
||||
}
|
||||
}
|
||||
|
||||
ppc_result_a = insert_end & insert_mask;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_slliq() {
|
||||
void dppc_interpreter::power_slliq() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
@@ -577,65 +394,30 @@ void power_slliq() {
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_slliqdot() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
for (uint32_t i = 31; i > rot_sh; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_start = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t insert_end = ppc_state.spr[SPR::MQ];
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (insert_mask & (1 << i)) {
|
||||
insert_end &= ~(1 << i);
|
||||
insert_end |= (insert_start & (1 << i));
|
||||
}
|
||||
}
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_sllq() {
|
||||
void dppc_interpreter::power_sllq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for sllq!!! \n");
|
||||
}
|
||||
|
||||
void power_sllqdot() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for sllq.!!! \n");
|
||||
}
|
||||
|
||||
void power_slq() {
|
||||
void dppc_interpreter::power_slq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for slq!!! \n");
|
||||
}
|
||||
|
||||
void power_slqdot() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for slq.!!! \n");
|
||||
}
|
||||
|
||||
void power_sraiq() {
|
||||
void dppc_interpreter::power_sraiq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for sraiq!!! \n");
|
||||
}
|
||||
|
||||
void power_sraiqdot() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for sraiq.!!! \n");
|
||||
}
|
||||
|
||||
void power_sraq() {
|
||||
void dppc_interpreter::power_sraq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for sraq!!! \n");
|
||||
}
|
||||
|
||||
void power_sraqdot() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for sraq.!!! \n");
|
||||
}
|
||||
|
||||
void power_sre() {
|
||||
void dppc_interpreter::power_sre() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
uint32_t rot_amt = ppc_result_b & 31;
|
||||
@@ -645,32 +427,16 @@ void power_sre() {
|
||||
uint32_t insert_final = ((ppc_result_d >> rot_amt) | (ppc_result_d << (32 - rot_amt)));
|
||||
ppc_state.spr[SPR::MQ] = insert_final & insert_mask;
|
||||
ppc_result_a = insert_final;
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_sredot() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
uint32_t rot_amt = ppc_result_b & 31;
|
||||
for (uint32_t i = 31; i > rot_amt; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_final = ((ppc_result_d >> rot_amt) | (ppc_result_d << (32 - rot_amt)));
|
||||
ppc_state.spr[SPR::MQ] = insert_final & insert_mask;
|
||||
ppc_result_a = insert_final;
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_srea() {
|
||||
void dppc_interpreter::power_srea() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for srea!!! \n");
|
||||
}
|
||||
|
||||
void power_sreadot() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for srea.!!! \n");
|
||||
}
|
||||
|
||||
void power_sreq() {
|
||||
void dppc_interpreter::power_sreq() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
@@ -689,33 +455,14 @@ void power_sreq() {
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_sreqdot() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = ppc_result_b & 31;
|
||||
for (uint32_t i = 31; i > rot_sh; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_start = ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh)));
|
||||
uint32_t insert_end = ppc_state.spr[SPR::MQ];
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (insert_mask & (1 << i)) {
|
||||
insert_end &= ~(1 << i);
|
||||
insert_end |= (insert_start & (1 << i));
|
||||
}
|
||||
}
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_sriq() {
|
||||
void dppc_interpreter::power_sriq() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
@@ -734,52 +481,21 @@ void power_sriq() {
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
|
||||
if (rc_flag)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_sriqdot() {
|
||||
ppc_grab_regssa();
|
||||
uint32_t insert_mask = 0;
|
||||
unsigned rot_sh = (ppc_cur_instruction >> 11) & 31;
|
||||
for (uint32_t i = 31; i > rot_sh; i--) {
|
||||
insert_mask |= (1 << i);
|
||||
}
|
||||
uint32_t insert_start = ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh)));
|
||||
uint32_t insert_end = ppc_state.spr[SPR::MQ];
|
||||
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (insert_mask & (1 << i)) {
|
||||
insert_end &= ~(1 << i);
|
||||
insert_end |= (insert_start & (1 << i));
|
||||
}
|
||||
}
|
||||
|
||||
ppc_result_a = insert_end;
|
||||
ppc_state.spr[SPR::MQ] = insert_start;
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
ppc_store_result_rega();
|
||||
}
|
||||
|
||||
void power_srliq() {
|
||||
void dppc_interpreter::power_srliq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for slriq!!! \n");
|
||||
}
|
||||
|
||||
void power_srliqdot() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for slriq.!!! \n");
|
||||
}
|
||||
|
||||
void power_srlq() {
|
||||
void dppc_interpreter::power_srlq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for slrq!!! \n");
|
||||
}
|
||||
|
||||
void power_srlqdot() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for slrq.!!! \n");
|
||||
}
|
||||
|
||||
void power_srq() {
|
||||
void dppc_interpreter::power_srq() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for srq!!! \n");
|
||||
}
|
||||
|
||||
void power_srqdot() {
|
||||
LOG_F(WARNING, "OOPS! Placeholder for srq.!!! \n");
|
||||
}
|
||||
+75
-37
@@ -209,8 +209,8 @@ const char* opc_flt_ldst[8] = {/* integer load and store instructions */
|
||||
"lfdu",
|
||||
"stfs",
|
||||
"stfsu",
|
||||
"sftd",
|
||||
"sftdu"};
|
||||
"stfd",
|
||||
"stfdu"};
|
||||
|
||||
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,20 +1687,32 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
case 12: /* frsp */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, r%d", "frsp", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "frsp");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 14: /* fctiw */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, r%d", "fctiw", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "fctiw");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 15: /* fctiwz */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, r%d, r%d", "fctiwz", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "fctiwz");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 32: /* fcmpo */
|
||||
if (rs & 3)
|
||||
@@ -1725,7 +1737,7 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", opcode, rs, rb);
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
break;
|
||||
case 64:
|
||||
strcpy(opcode, "mcrfs");
|
||||
@@ -1738,31 +1750,52 @@ void opc_group63(PPCDisasmContext* ctx) {
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8scrb%d", opcode, rs);
|
||||
ctx->instr_str = my_sprintf("%-8s%d", opcode, rs);
|
||||
break;
|
||||
case 72: /* fmr */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sr%d, r%d", "fmr", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "fmr");
|
||||
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 134: /* mtfsfi */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, r%d", "mtfsfi", (rs >> 2), (rb >> 1));
|
||||
else {
|
||||
strcpy(opcode, "mtfsfi");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8scr%d, %d", opcode, (rs >> 2), (rb >> 1));
|
||||
}
|
||||
break;
|
||||
case 136: /* fnabs */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", "fnabs", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "fnabs");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 264: /* fabs */
|
||||
if (ra != 0)
|
||||
opc_illegal(ctx);
|
||||
else
|
||||
ctx->instr_str = my_sprintf("%-8s%d, f%d, f%d", "fabs", rs, rb);
|
||||
else {
|
||||
strcpy(opcode, "fabs");
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8sf%d, f%d", opcode, rs, rb);
|
||||
}
|
||||
break;
|
||||
case 583: /* mffs */
|
||||
strcpy(opcode, "mffs");
|
||||
@@ -1770,13 +1803,18 @@ 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 */
|
||||
ctx->instr_str = my_sprintf("%-8sfm%d, r%d", "mtfsf", fm, rb);
|
||||
strcpy(opcode, "mtfsf");
|
||||
|
||||
if (rc_set)
|
||||
strcat(opcode, ".");
|
||||
|
||||
ctx->instr_str = my_sprintf("%-8s%d, f%d", opcode, fm, rb);
|
||||
break;
|
||||
default:
|
||||
opc_illegal(ctx);
|
||||
|
||||
+37
-156
@@ -25,6 +25,7 @@ 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>
|
||||
|
||||
@@ -35,11 +36,13 @@ 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);
|
||||
@@ -153,9 +156,6 @@ 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,6 +215,14 @@ enum class Except_Type {
|
||||
EXC_TRACE = 13
|
||||
};
|
||||
|
||||
/** Programm Exception subclasses. */
|
||||
enum Exc_Cause : uint32_t {
|
||||
FPU_OFF = 1 << (31 - 11),
|
||||
ILLEGAL_OP = 1 << (31 - 12),
|
||||
NOT_ALLOWED = 1 << (31 - 13),
|
||||
TRAP = 1 << (31 - 14),
|
||||
};
|
||||
|
||||
// extern bool bb_end;
|
||||
extern BB_end_kind bb_kind;
|
||||
|
||||
@@ -226,26 +234,34 @@ extern bool grab_return;
|
||||
extern bool power_on;
|
||||
|
||||
extern bool is_601; // For PowerPC 601 Emulation
|
||||
extern bool is_gekko; // For GameCube Emulation
|
||||
extern bool is_altivec; // For Altivec Emulation
|
||||
extern bool is_64bit; // For PowerPC G5 Emulation
|
||||
|
||||
extern bool rc_flag; // Record flag
|
||||
extern bool oe_flag; // Overflow flag
|
||||
|
||||
// Important Addressing Integers
|
||||
extern uint32_t ppc_cur_instruction;
|
||||
extern uint32_t ppc_effective_address;
|
||||
extern uint32_t ppc_next_instruction_address;
|
||||
|
||||
// Profiling Stats
|
||||
extern uint32_t mmu_translations_num;
|
||||
extern uint32_t exceptions_performed;
|
||||
extern uint32_t supervisor_inst_num;
|
||||
#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
|
||||
|
||||
// Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version);
|
||||
extern void ppc_mmu_init();
|
||||
|
||||
void ppc_illegalop();
|
||||
void ppc_opcode4();
|
||||
[[noreturn]] void ppc_illegalop();
|
||||
[[noreturn]] void ppc_fpu_off();
|
||||
|
||||
//void ppc_opcode4();
|
||||
void ppc_opcode16();
|
||||
void ppc_opcode18();
|
||||
void ppc_opcode19();
|
||||
@@ -253,6 +269,8 @@ void ppc_opcode31();
|
||||
void ppc_opcode59();
|
||||
void ppc_opcode63();
|
||||
|
||||
void initialize_ppc_opcode_tables();
|
||||
|
||||
extern bool ppc_confirm_inf_nan(uint64_t input_a, uint64_t input_b, bool is_single, uint32_t op);
|
||||
extern double fp_return_double(uint32_t reg);
|
||||
extern uint64_t fp_return_uint64(uint32_t reg);
|
||||
@@ -271,23 +289,12 @@ 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();
|
||||
|
||||
void ppc_tbr_update();
|
||||
|
||||
/* Exception handlers. */
|
||||
[[noreturn]] void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits);
|
||||
@@ -295,7 +302,11 @@ void ppc_tbr_update();
|
||||
// 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();
|
||||
extern void ppc_bcctrl();
|
||||
extern void ppc_bclr();
|
||||
@@ -311,33 +322,15 @@ extern void ppc_crxor();
|
||||
extern void ppc_isync();
|
||||
|
||||
extern void ppc_add();
|
||||
extern void ppc_adddot();
|
||||
extern void ppc_addo();
|
||||
extern void ppc_addodot();
|
||||
extern void ppc_addc();
|
||||
extern void ppc_addcdot();
|
||||
extern void ppc_addco();
|
||||
extern void ppc_addcodot();
|
||||
extern void ppc_adde();
|
||||
extern void ppc_addedot();
|
||||
extern void ppc_addeo();
|
||||
extern void ppc_addeodot();
|
||||
extern void ppc_addme();
|
||||
extern void ppc_addmedot();
|
||||
extern void ppc_addmeo();
|
||||
extern void ppc_addmeodot();
|
||||
extern void ppc_addze();
|
||||
extern void ppc_addzedot();
|
||||
extern void ppc_addzeo();
|
||||
extern void ppc_addzeodot();
|
||||
extern void ppc_and();
|
||||
extern void ppc_anddot();
|
||||
extern void ppc_andc();
|
||||
extern void ppc_andcdot();
|
||||
extern void ppc_cmp();
|
||||
extern void ppc_cmpl();
|
||||
extern void ppc_cntlzw();
|
||||
extern void ppc_cntlzwdot();
|
||||
extern void ppc_dcbf();
|
||||
extern void ppc_dcbi();
|
||||
extern void ppc_dcbst();
|
||||
@@ -345,20 +338,11 @@ extern void ppc_dcbt();
|
||||
extern void ppc_dcbtst();
|
||||
extern void ppc_dcbz();
|
||||
extern void ppc_divw();
|
||||
extern void ppc_divwdot();
|
||||
extern void ppc_divwo();
|
||||
extern void ppc_divwodot();
|
||||
extern void ppc_divwu();
|
||||
extern void ppc_divwudot();
|
||||
extern void ppc_divwuo();
|
||||
extern void ppc_divwuodot();
|
||||
extern void ppc_eieio();
|
||||
extern void ppc_eqv();
|
||||
extern void ppc_eqvdot();
|
||||
extern void ppc_extsb();
|
||||
extern void ppc_extsbdot();
|
||||
extern void ppc_extsh();
|
||||
extern void ppc_extshdot();
|
||||
extern void ppc_icbi();
|
||||
extern void ppc_mftb();
|
||||
extern void ppc_lhzux();
|
||||
@@ -375,33 +359,17 @@ extern void ppc_lwzx();
|
||||
extern void ppc_mcrxr();
|
||||
extern void ppc_mfcr();
|
||||
extern void ppc_mulhwu();
|
||||
extern void ppc_mulhwudot();
|
||||
extern void ppc_mulhw();
|
||||
extern void ppc_mulhwdot();
|
||||
extern void ppc_mullw();
|
||||
extern void ppc_mullwdot();
|
||||
extern void ppc_mullwo();
|
||||
extern void ppc_mullwodot();
|
||||
extern void ppc_nand();
|
||||
extern void ppc_nanddot();
|
||||
extern void ppc_neg();
|
||||
extern void ppc_negdot();
|
||||
extern void ppc_nego();
|
||||
extern void ppc_negodot();
|
||||
extern void ppc_nor();
|
||||
extern void ppc_nordot();
|
||||
extern void ppc_or();
|
||||
extern void ppc_ordot();
|
||||
extern void ppc_orc();
|
||||
extern void ppc_orcdot();
|
||||
extern void ppc_slw();
|
||||
extern void ppc_slwdot();
|
||||
extern void ppc_srw();
|
||||
extern void ppc_srwdot();
|
||||
extern void ppc_sraw();
|
||||
extern void ppc_srawdot();
|
||||
extern void ppc_srawi();
|
||||
extern void ppc_srawidot();
|
||||
extern void ppc_stbx();
|
||||
extern void ppc_stbux();
|
||||
extern void ppc_stfiwx();
|
||||
@@ -413,25 +381,10 @@ extern void ppc_stwcx();
|
||||
extern void ppc_stwux();
|
||||
extern void ppc_stwbrx();
|
||||
extern void ppc_subf();
|
||||
extern void ppc_subfdot();
|
||||
extern void ppc_subfo();
|
||||
extern void ppc_subfodot();
|
||||
extern void ppc_subfc();
|
||||
extern void ppc_subfcdot();
|
||||
extern void ppc_subfco();
|
||||
extern void ppc_subfcodot();
|
||||
extern void ppc_subfe();
|
||||
extern void ppc_subfedot();
|
||||
extern void ppc_subfeo();
|
||||
extern void ppc_subfeodot();
|
||||
extern void ppc_subfme();
|
||||
extern void ppc_subfmedot();
|
||||
extern void ppc_subfmeo();
|
||||
extern void ppc_subfmeodot();
|
||||
extern void ppc_subfze();
|
||||
extern void ppc_subfzedot();
|
||||
extern void ppc_subfzeo();
|
||||
extern void ppc_subfzeodot();
|
||||
extern void ppc_sync();
|
||||
extern void ppc_tlbia();
|
||||
extern void ppc_tlbie();
|
||||
@@ -440,7 +393,6 @@ extern void ppc_tlbld();
|
||||
extern void ppc_tlbsync();
|
||||
extern void ppc_tw();
|
||||
extern void ppc_xor();
|
||||
extern void ppc_xordot();
|
||||
|
||||
extern void ppc_lswi();
|
||||
extern void ppc_lswx();
|
||||
@@ -452,6 +404,7 @@ 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();
|
||||
@@ -535,11 +488,11 @@ extern void ppc_stfdux();
|
||||
|
||||
extern void ppc_fadd();
|
||||
extern void ppc_fsub();
|
||||
extern void ppc_fmult();
|
||||
extern void ppc_fmul();
|
||||
extern void ppc_fdiv();
|
||||
extern void ppc_fadds();
|
||||
extern void ppc_fsubs();
|
||||
extern void ppc_fmults();
|
||||
extern void ppc_fmuls();
|
||||
extern void ppc_fdivs();
|
||||
extern void ppc_fmadd();
|
||||
extern void ppc_fmsub();
|
||||
@@ -561,111 +514,39 @@ extern void ppc_frsp();
|
||||
extern void ppc_fctiw();
|
||||
extern void ppc_fctiwz();
|
||||
|
||||
extern void ppc_fadddot();
|
||||
extern void ppc_fsubdot();
|
||||
extern void ppc_fmultdot();
|
||||
extern void ppc_fdivdot();
|
||||
extern void ppc_fmadddot();
|
||||
extern void ppc_fmsubdot();
|
||||
extern void ppc_fnmadddot();
|
||||
extern void ppc_fnmsubdot();
|
||||
extern void ppc_fabsdot();
|
||||
extern void ppc_fnabsdot();
|
||||
extern void ppc_fnegdot();
|
||||
extern void ppc_fseldot();
|
||||
extern void ppc_fsqrtdot();
|
||||
extern void ppc_frsqrtedot();
|
||||
extern void ppc_frspdot();
|
||||
extern void ppc_fctiwdot();
|
||||
extern void ppc_fctiwzdot();
|
||||
|
||||
extern void ppc_fresdot();
|
||||
extern void ppc_faddsdot();
|
||||
extern void ppc_fsubsdot();
|
||||
extern void ppc_fmultsdot();
|
||||
extern void ppc_fdivsdot();
|
||||
extern void ppc_fmaddsdot();
|
||||
extern void ppc_fmsubsdot();
|
||||
extern void ppc_fnmaddsdot();
|
||||
extern void ppc_fnmsubsdot();
|
||||
extern void ppc_fsqrtsdot();
|
||||
|
||||
extern void ppc_fcmpo();
|
||||
extern void ppc_fcmpu();
|
||||
|
||||
// Power-specific instructions
|
||||
extern void power_abs();
|
||||
extern void power_absdot();
|
||||
extern void power_abso();
|
||||
extern void power_absodot();
|
||||
extern void power_clcs();
|
||||
extern void power_clcsdot();
|
||||
extern void power_div();
|
||||
extern void power_divdot();
|
||||
extern void power_divo();
|
||||
extern void power_divodot();
|
||||
extern void power_divs();
|
||||
extern void power_divsdot();
|
||||
extern void power_divso();
|
||||
extern void power_divsodot();
|
||||
extern void power_doz();
|
||||
extern void power_dozdot();
|
||||
extern void power_dozo();
|
||||
extern void power_dozodot();
|
||||
extern void power_dozi();
|
||||
extern void power_lscbx();
|
||||
extern void power_lscbxdot();
|
||||
extern void power_maskg();
|
||||
extern void power_maskgdot();
|
||||
extern void power_maskir();
|
||||
extern void power_maskirdot();
|
||||
extern void power_mul();
|
||||
extern void power_muldot();
|
||||
extern void power_mulo();
|
||||
extern void power_mulodot();
|
||||
extern void power_nabs();
|
||||
extern void power_nabsdot();
|
||||
extern void power_nabso();
|
||||
extern void power_nabsodot();
|
||||
extern void power_rlmi();
|
||||
extern void power_rrib();
|
||||
extern void power_rribdot();
|
||||
extern void power_sle();
|
||||
extern void power_sledot();
|
||||
extern void power_sleq();
|
||||
extern void power_sleqdot();
|
||||
extern void power_sliq();
|
||||
extern void power_sliqdot();
|
||||
extern void power_slliq();
|
||||
extern void power_slliqdot();
|
||||
extern void power_sllq();
|
||||
extern void power_sllqdot();
|
||||
extern void power_slq();
|
||||
extern void power_slqdot();
|
||||
extern void power_sraiq();
|
||||
extern void power_sraiqdot();
|
||||
extern void power_sraq();
|
||||
extern void power_sraqdot();
|
||||
extern void power_sre();
|
||||
extern void power_sredot();
|
||||
extern void power_srea();
|
||||
extern void power_sreadot();
|
||||
extern void power_sreq();
|
||||
extern void power_sreqdot();
|
||||
extern void power_sriq();
|
||||
extern void power_sriqdot();
|
||||
extern void power_srliq();
|
||||
extern void power_srliqdot();
|
||||
extern void power_srlq();
|
||||
extern void power_srlqdot();
|
||||
extern void power_srq();
|
||||
extern void power_srqdot();
|
||||
|
||||
// Gekko instructions
|
||||
extern void ppc_psq_l();
|
||||
extern void ppc_psq_lu();
|
||||
extern void ppc_psq_st();
|
||||
extern void ppc_psq_stu();
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
// AltiVec instructions
|
||||
|
||||
@@ -677,9 +558,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,6 +22,7 @@ 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>
|
||||
@@ -30,8 +31,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 PROFILER
|
||||
exceptions_performed++;
|
||||
#ifdef CPU_PROFILING
|
||||
exceptions_processed++;
|
||||
#endif
|
||||
bb_kind = BB_end_kind::BB_EXCEPTION;
|
||||
|
||||
@@ -109,6 +110,8 @@ 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. */
|
||||
}
|
||||
|
||||
|
||||
+441
-414
@@ -35,6 +35,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define NEW_TBR_UPDATE_ALGO
|
||||
|
||||
using namespace std;
|
||||
using namespace dppc_interpreter;
|
||||
|
||||
MemCtrlBase* mem_ctrl_instance = 0;
|
||||
|
||||
@@ -42,6 +43,9 @@ bool power_on = 1;
|
||||
|
||||
SetPRS ppc_state;
|
||||
|
||||
bool rc_flag = 0; // Record flag
|
||||
bool oe_flag = 0; // Overflow flag
|
||||
|
||||
bool grab_exception;
|
||||
bool grab_return;
|
||||
bool grab_breakpoint;
|
||||
@@ -65,348 +69,92 @@ 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_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,
|
||||
ppc_ori, ppc_oris, ppc_xori, ppc_xoris, ppc_andidot, ppc_andisdot,
|
||||
ppc_illegalop, ppc_opcode31, ppc_lwz, ppc_lwzu, ppc_lbz, ppc_lbzu,
|
||||
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_psq_l, ppc_psq_lu, ppc_illegalop, ppc_illegalop,
|
||||
ppc_psq_st, ppc_psq_stu, ppc_illegalop, ppc_opcode63};
|
||||
ppc_illegalop, ppc_illegalop, ppc_illegalop, ppc_twi, ppc_illegalop, ppc_illegalop,
|
||||
ppc_illegalop, ppc_mulli, ppc_subfic, power_dozi, ppc_cmpli, ppc_cmpi,
|
||||
ppc_addic, ppc_addicdot, ppc_addi, ppc_addis, ppc_opcode16, ppc_sc,
|
||||
ppc_opcode18, ppc_opcode19, ppc_rlwimi, ppc_rlwinm, power_rlmi, ppc_rlwnm,
|
||||
ppc_ori, ppc_oris, ppc_xori, ppc_xoris, ppc_andidot, ppc_andisdot,
|
||||
ppc_illegalop, ppc_opcode31, ppc_lwz, ppc_lwzu, ppc_lbz, ppc_lbzu,
|
||||
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_illegalop, ppc_illegalop, ppc_illegalop, ppc_opcode63};
|
||||
|
||||
/** Lookup tables for branch instructions. */
|
||||
static PPCOpcode SubOpcode16Grabber[] = {ppc_bc, ppc_bcl, ppc_bca, ppc_bcla};
|
||||
static PPCOpcode SubOpcode16Grabber[] = {
|
||||
dppc_interpreter::ppc_bc,
|
||||
dppc_interpreter::ppc_bcl,
|
||||
dppc_interpreter::ppc_bca,
|
||||
dppc_interpreter::ppc_bcla};
|
||||
|
||||
static PPCOpcode SubOpcode18Grabber[] = {ppc_b, ppc_bl, ppc_ba, ppc_bla};
|
||||
static PPCOpcode SubOpcode18Grabber[] = {
|
||||
dppc_interpreter::ppc_b,
|
||||
dppc_interpreter::ppc_bl,
|
||||
dppc_interpreter::ppc_ba,
|
||||
dppc_interpreter::ppc_bla};
|
||||
|
||||
/** General conditional register instructions decoding table. */
|
||||
static std::unordered_map<uint16_t, PPCOpcode> SubOpcode19Grabber = {
|
||||
{32, &ppc_bclr},
|
||||
{33, &ppc_bclrl},
|
||||
{66, &ppc_crnor},
|
||||
{100, &ppc_rfi},
|
||||
{258, &ppc_crandc},
|
||||
{300, &ppc_isync},
|
||||
{386, &ppc_crxor},
|
||||
{450, &ppc_crnand},
|
||||
{514, &ppc_crand},
|
||||
{578, &ppc_creqv},
|
||||
{834, &ppc_crorc},
|
||||
{898, &ppc_cror},
|
||||
{1056, &ppc_bcctr},
|
||||
{1057, &ppc_bcctrl}};
|
||||
/** Instructions decoding tables for integer,
|
||||
single floating-point, and double-floating point ops respectively */
|
||||
|
||||
/** General integer instructions decoding table. */
|
||||
static std::unordered_map<uint16_t, PPCOpcode> SubOpcode31Grabber = {
|
||||
{0, &ppc_cmp}, {8, &ppc_tw},
|
||||
{16, &ppc_subfc}, {17, &ppc_subfcdot},
|
||||
{20, &ppc_addc}, {21, &ppc_addcdot},
|
||||
{22, &ppc_mulhwu}, {23, &ppc_mulhwudot},
|
||||
{38, &ppc_mfcr}, {40, &ppc_lwarx},
|
||||
{46, &ppc_lwzx}, {48, &ppc_slw},
|
||||
{49, &ppc_slwdot}, {52, &ppc_cntlzw},
|
||||
{53, &ppc_cntlzwdot}, {56, &ppc_and},
|
||||
{57, &ppc_anddot}, {58, &power_maskg},
|
||||
{59, &power_maskgdot}, {64, &ppc_cmpl},
|
||||
{80, &ppc_subf}, {81, &ppc_subfdot},
|
||||
{108, &ppc_dcbst}, {110, &ppc_lwzux},
|
||||
{120, &ppc_andc}, {121, &ppc_andcdot},
|
||||
{150, &ppc_mulhw}, {151, &ppc_mulhwdot},
|
||||
{166, &ppc_mfmsr}, {172, &ppc_dcbf},
|
||||
{174, &ppc_lbzx}, {208, &ppc_neg},
|
||||
{209, &ppc_negdot}, {214, &power_mul},
|
||||
{215, &power_muldot}, {238, &ppc_lbzux},
|
||||
{248, &ppc_nor}, {249, &ppc_nordot},
|
||||
{272, &ppc_subfe}, {273, &ppc_subfedot},
|
||||
{276, &ppc_adde}, {277, &ppc_addedot},
|
||||
{288, &ppc_mtcrf}, {292, &ppc_mtmsr},
|
||||
{301, &ppc_stwcx}, {302, &ppc_stwx},
|
||||
{304, &power_slq}, {305, &power_slqdot},
|
||||
{306, &power_sle}, {307, &power_sledot},
|
||||
{366, &ppc_stwux}, {368, &power_sliq},
|
||||
{400, &ppc_subfze}, {401, &ppc_subfzedot},
|
||||
{404, &ppc_addze}, {405, &ppc_addzedot},
|
||||
{420, &ppc_mtsr}, {430, &ppc_stbx},
|
||||
{432, &power_sllq}, {433, &power_sllqdot},
|
||||
{434, &power_sleq}, {436, &power_sleqdot},
|
||||
{464, &ppc_subfme}, {465, &ppc_subfmedot},
|
||||
{468, &ppc_addme}, {469, &ppc_addmedot},
|
||||
{470, &ppc_mullw}, {471, &ppc_mullwdot},
|
||||
{484, &ppc_mtsrin}, {492, &ppc_dcbtst},
|
||||
{494, &ppc_stbux}, {496, &power_slliq},
|
||||
{497, &power_slliqdot}, {528, &power_doz},
|
||||
{529, &power_dozdot}, {532, &ppc_add},
|
||||
{533, &ppc_adddot}, {554, &power_lscbx},
|
||||
{555, &power_lscbxdot}, {556, &ppc_dcbt},
|
||||
{558, &ppc_lhzx}, {568, &ppc_eqv},
|
||||
{569, &ppc_eqvdot}, {612, &ppc_tlbie},
|
||||
{622, &ppc_lhzux}, {632, &ppc_xor},
|
||||
{633, &ppc_xordot}, {662, &power_div},
|
||||
{663, &power_divdot}, {678, &ppc_mfspr},
|
||||
{686, &ppc_lhax}, {720, &power_abs},
|
||||
{721, &power_absdot}, {726, &power_divs},
|
||||
{727, &power_divsdot}, {740, &ppc_tlbia},
|
||||
{742, &ppc_mftb}, {750, &ppc_lhaux},
|
||||
{814, &ppc_sthx}, {824, &ppc_orc},
|
||||
{825, &ppc_orcdot}, {878, &ppc_sthx},
|
||||
{888, &ppc_or}, {889, &ppc_ordot},
|
||||
{918, &ppc_divwu}, {919, &ppc_divwudot},
|
||||
{934, &ppc_mtspr}, {940, &ppc_dcbi},
|
||||
{952, &ppc_nand}, {953, &ppc_nanddot},
|
||||
{976, &power_nabs}, {977, &power_nabsdot},
|
||||
{982, &ppc_divw}, {983, &ppc_divwdot},
|
||||
{1024, &ppc_mcrxr}, {1040, &ppc_subfco},
|
||||
{1041, &ppc_subfcodot}, {1044, &ppc_addco},
|
||||
{1045, &ppc_addcodot}, {1062, &power_clcs},
|
||||
{1063, &power_clcsdot}, {1066, &ppc_lswx},
|
||||
{1068, &ppc_lwbrx}, {1070, &ppc_lfsx},
|
||||
{1072, &ppc_srw}, {1073, &ppc_srwdot},
|
||||
{1074, &power_rrib}, {1075, &power_rribdot},
|
||||
{1082, &power_maskir}, {1083, &power_maskirdot},
|
||||
{1104, &ppc_subfo}, {1105, &ppc_subfodot},
|
||||
{1132, &ppc_tlbsync}, {1134, &ppc_lfsux},
|
||||
{1190, &ppc_mfsr}, {1194, &ppc_lswi},
|
||||
{1196, &ppc_sync}, {1198, &ppc_lfdx},
|
||||
{1232, &ppc_nego}, {1233, &ppc_negodot},
|
||||
{1238, &power_mulo}, {1239, &power_mulodot},
|
||||
{1262, &ppc_lfdux}, {1296, &ppc_subfeo},
|
||||
{1297, &ppc_subfeodot}, {1300, &ppc_addeo},
|
||||
{1301, &ppc_addeodot}, {1318, &ppc_mfsrin},
|
||||
{1322, &ppc_stswx}, {1324, &ppc_stwbrx},
|
||||
{1326, &ppc_stfsx}, {1328, &power_srq},
|
||||
{1329, &power_srqdot}, {1330, &power_sre},
|
||||
{1331, &power_sredot}, {1390, &ppc_stfsux},
|
||||
{1392, &power_sriq}, {1393, &power_sriqdot},
|
||||
{1424, &ppc_subfzeo}, {1425, &ppc_subfzeodot},
|
||||
{1428, &ppc_addzeo}, {1429, &ppc_addzeodot},
|
||||
{1450, &ppc_stswi}, {1454, &ppc_stfdx},
|
||||
{1456, &power_srlq}, {1457, &power_srlqdot},
|
||||
{1458, &power_sreq}, {1459, &power_sreqdot},
|
||||
{1488, &ppc_subfmeo}, {1489, &ppc_subfmeodot},
|
||||
{1492, &ppc_addmeo}, {1493, &ppc_addmeodot},
|
||||
{1494, &ppc_mullwo}, {1495, &ppc_mullwodot},
|
||||
{1518, &ppc_stfdux}, {1520, &power_srliq},
|
||||
{1521, &power_srliqdot}, {1552, &power_dozo},
|
||||
{1553, &power_dozodot}, {1556, &ppc_addo},
|
||||
{1557, &ppc_addodot}, {1580, &ppc_lhbrx},
|
||||
{1584, &ppc_sraw}, {1585, &ppc_srawdot},
|
||||
{1648, &ppc_srawi}, {1649, &ppc_srawidot},
|
||||
{1686, &power_divo}, {1687, &power_divodot},
|
||||
{1708, &ppc_eieio}, {1744, &power_abso},
|
||||
{1745, &power_absodot}, {1750, &power_divso},
|
||||
{1751, &power_divsodot}, {1836, &ppc_sthbrx},
|
||||
{1840, &power_sraq}, {1841, &power_sraqdot},
|
||||
{1842, &power_srea}, {1843, &power_sreadot},
|
||||
{1844, &ppc_extsh}, {1845, &ppc_extshdot},
|
||||
{1904, &power_sraiq}, {1905, &power_sraiqdot},
|
||||
{1908, &ppc_extsb}, {1909, &ppc_extsbdot},
|
||||
{1942, &ppc_divwuo}, {1943, &ppc_divwuodot},
|
||||
{1956, &ppc_tlbld}, {1964, &ppc_icbi},
|
||||
{1966, &ppc_stfiwx}, {2000, &power_nabso},
|
||||
{2001, &power_nabsodot}, {2006, &ppc_divwo},
|
||||
{2007, &ppc_divwodot}, {2020, &ppc_tlbli},
|
||||
{2028, &ppc_dcbz}};
|
||||
|
||||
/** Single-precision floating-point instructions decoding table. */
|
||||
static std::unordered_map<uint16_t, PPCOpcode> SubOpcode59Grabber = {
|
||||
{36, &ppc_fdivs}, {37, &ppc_fdivsdot}, {40, &ppc_fsubs}, {41, &ppc_fsubsdot},
|
||||
{42, &ppc_fadds}, {43, &ppc_faddsdot}, {44, &ppc_fsqrts}, {45, &ppc_fsqrtsdot},
|
||||
{48, &ppc_fres}, {49, &ppc_fresdot}, {50, &ppc_fmults}, {51, &ppc_fmultsdot},
|
||||
{56, &ppc_fmsubs}, {57, &ppc_fmsubsdot}, {58, &ppc_fmadds}, {59, &ppc_fmaddsdot},
|
||||
{60, &ppc_fnmsubs}, {61, &ppc_fnmsubsdot}, {62, &ppc_fnmadds}, {63, &ppc_fnmaddsdot},
|
||||
{114, &ppc_fmults}, {115, &ppc_fmultsdot}, {120, &ppc_fmsubs}, {121, &ppc_fmsubsdot},
|
||||
{122, &ppc_fmadds}, {123, &ppc_fmadds}, {124, &ppc_fnmsubs}, {125, &ppc_fnmsubsdot},
|
||||
{126, &ppc_fnmadds}, {127, &ppc_fnmaddsdot}, {178, &ppc_fmults}, {179, &ppc_fmultsdot},
|
||||
{184, &ppc_fmsubs}, {185, &ppc_fmsubsdot}, {186, &ppc_fmadds}, {187, &ppc_fmaddsdot},
|
||||
{188, &ppc_fnmsubs}, {189, &ppc_fnmsubsdot}, {190, &ppc_fnmadds}, {191, &ppc_fnmaddsdot},
|
||||
{242, &ppc_fmults}, {243, &ppc_fmultsdot}, {248, &ppc_fmsubs}, {249, &ppc_fmsubsdot},
|
||||
{250, &ppc_fmadds}, {251, &ppc_fmaddsdot}, {252, &ppc_fnmsubs}, {253, &ppc_fnmsubsdot},
|
||||
{254, &ppc_fnmadds}, {255, &ppc_fnmaddsdot}, {306, &ppc_fmults}, {307, &ppc_fmultsdot},
|
||||
{312, &ppc_fmsubs}, {313, &ppc_fmsubsdot}, {314, &ppc_fmadds}, {315, &ppc_fmaddsdot},
|
||||
{316, &ppc_fnmsubs}, {317, &ppc_fnmsubsdot}, {318, &ppc_fnmadds}, {319, &ppc_fnmaddsdot},
|
||||
{370, &ppc_fmults}, {371, &ppc_fmultsdot}, {376, &ppc_fmsubs}, {377, &ppc_fmsubsdot},
|
||||
{378, &ppc_fmadds}, {379, &ppc_fmaddsdot}, {380, &ppc_fnmsubs}, {381, &ppc_fnmsubsdot},
|
||||
{382, &ppc_fnmadds}, {383, &ppc_fnmaddsdot}, {434, &ppc_fmults}, {435, &ppc_fmultsdot},
|
||||
{440, &ppc_fmsubs}, {441, &ppc_fmsubsdot}, {442, &ppc_fmadds}, {443, &ppc_fmaddsdot},
|
||||
{444, &ppc_fnmsubs}, {445, &ppc_fnmsubsdot}, {446, &ppc_fnmadds}, {447, &ppc_fnmaddsdot},
|
||||
{498, &ppc_fmults}, {499, &ppc_fmultsdot}, {504, &ppc_fmsubs}, {505, &ppc_fmsubsdot},
|
||||
{506, &ppc_fmadds}, {507, &ppc_fmaddsdot}, {508, &ppc_fnmsubs}, {509, &ppc_fnmsubsdot},
|
||||
{510, &ppc_fnmadds}, {511, &ppc_fnmaddsdot}, {562, &ppc_fmults}, {563, &ppc_fmultsdot},
|
||||
{568, &ppc_fmsubs}, {569, &ppc_fmsubsdot}, {570, &ppc_fmadds}, {571, &ppc_fmaddsdot},
|
||||
{572, &ppc_fnmsubs}, {573, &ppc_fnmsubsdot}, {574, &ppc_fnmadds}, {575, &ppc_fnmaddsdot},
|
||||
{626, &ppc_fmults}, {627, &ppc_fmultsdot}, {632, &ppc_fmsubs}, {633, &ppc_fmsubsdot},
|
||||
{634, &ppc_fmadds}, {635, &ppc_fmaddsdot}, {636, &ppc_fnmsubs}, {637, &ppc_fnmsubsdot},
|
||||
{638, &ppc_fnmadds}, {639, &ppc_fnmaddsdot}, {690, &ppc_fmults}, {691, &ppc_fmultsdot},
|
||||
{696, &ppc_fmsubs}, {697, &ppc_fmsubsdot}, {698, &ppc_fmadds}, {699, &ppc_fmaddsdot},
|
||||
{700, &ppc_fnmsubs}, {701, &ppc_fnmsubsdot}, {702, &ppc_fnmadds}, {703, &ppc_fnmaddsdot},
|
||||
{754, &ppc_fmults}, {755, &ppc_fmultsdot}, {760, &ppc_fmsubs}, {761, &ppc_fmsubsdot},
|
||||
{762, &ppc_fmadds}, {763, &ppc_fmaddsdot}, {764, &ppc_fnmsubs}, {765, &ppc_fnmsubsdot},
|
||||
{766, &ppc_fnmadds}, {767, &ppc_fnmaddsdot}, {818, &ppc_fmults}, {819, &ppc_fmultsdot},
|
||||
{824, &ppc_fmsubs}, {825, &ppc_fmsubsdot}, {826, &ppc_fmadds}, {827, &ppc_fmaddsdot},
|
||||
{828, &ppc_fnmsubs}, {829, &ppc_fnmsubsdot}, {830, &ppc_fnmadds}, {831, &ppc_fnmaddsdot},
|
||||
{882, &ppc_fmults}, {883, &ppc_fmultsdot}, {888, &ppc_fmsubs}, {889, &ppc_fmsubsdot},
|
||||
{890, &ppc_fmadds}, {891, &ppc_fmaddsdot}, {892, &ppc_fnmsubs}, {893, &ppc_fnmsubsdot},
|
||||
{894, &ppc_fnmadds}, {895, &ppc_fnmaddsdot}, {946, &ppc_fmults}, {947, &ppc_fmultsdot},
|
||||
{952, &ppc_fmsubs}, {953, &ppc_fmsubsdot}, {954, &ppc_fmadds}, {955, &ppc_fmaddsdot},
|
||||
{957, &ppc_fnmsubs}, {958, &ppc_fnmsubsdot}, {958, &ppc_fnmadds}, {959, &ppc_fnmaddsdot},
|
||||
{1010, &ppc_fmults}, {1011, &ppc_fmultsdot}, {1016, &ppc_fmsubs}, {1017, &ppc_fmsubsdot},
|
||||
{1018, &ppc_fmadds}, {1019, &ppc_fmaddsdot}, {1020, &ppc_fnmsubs}, {1021, &ppc_fnmsubsdot},
|
||||
{1022, &ppc_fnmadds}, {1023, &ppc_fnmaddsdot}, {1074, &ppc_fmults}, {1075, &ppc_fmultsdot},
|
||||
{1080, &ppc_fmsubs}, {1081, &ppc_fmsubsdot}, {1082, &ppc_fmadds}, {1083, &ppc_fmaddsdot},
|
||||
{1084, &ppc_fnmsubs}, {1085, &ppc_fnmsubsdot}, {1086, &ppc_fnmadds}, {1087, &ppc_fnmaddsdot},
|
||||
{1138, &ppc_fmults}, {1139, &ppc_fmultsdot}, {1144, &ppc_fmsubs}, {1145, &ppc_fmsubsdot},
|
||||
{1146, &ppc_fmadds}, {1147, &ppc_fmaddsdot}, {1148, &ppc_fnmsubs}, {1149, &ppc_fnmsubsdot},
|
||||
{1150, &ppc_fnmadds}, {1151, &ppc_fnmaddsdot}, {1202, &ppc_fmults}, {1203, &ppc_fmultsdot},
|
||||
{1208, &ppc_fmsubs}, {1209, &ppc_fmsubsdot}, {1210, &ppc_fmadds}, {1211, &ppc_fmaddsdot},
|
||||
{1212, &ppc_fnmsubs}, {1213, &ppc_fnmsubsdot}, {1214, &ppc_fnmadds}, {1215, &ppc_fnmaddsdot},
|
||||
{1266, &ppc_fmults}, {1267, &ppc_fmultsdot}, {1272, &ppc_fmsubs}, {1273, &ppc_fmsubsdot},
|
||||
{1274, &ppc_fmadds}, {1275, &ppc_fmaddsdot}, {1276, &ppc_fnmsubs}, {1277, &ppc_fnmsubsdot},
|
||||
{1278, &ppc_fnmadds}, {1279, &ppc_fnmaddsdot}, {1330, &ppc_fmults}, {1331, &ppc_fmultsdot},
|
||||
{1336, &ppc_fmsubs}, {1337, &ppc_fmsubsdot}, {1338, &ppc_fmadds}, {1339, &ppc_fmaddsdot},
|
||||
{1340, &ppc_fnmsubs}, {1341, &ppc_fnmsubsdot}, {1342, &ppc_fnmadds}, {1343, &ppc_fnmaddsdot},
|
||||
{1394, &ppc_fmults}, {1395, &ppc_fmultsdot}, {1400, &ppc_fmsubs}, {1401, &ppc_fmsubsdot},
|
||||
{1402, &ppc_fmadds}, {1403, &ppc_fmaddsdot}, {1404, &ppc_fnmsubs}, {1405, &ppc_fnmsubsdot},
|
||||
{1406, &ppc_fnmadds}, {1407, &ppc_fnmaddsdot}, {1458, &ppc_fmults}, {1459, &ppc_fmultsdot},
|
||||
{1464, &ppc_fmsubs}, {1465, &ppc_fmsubsdot}, {1466, &ppc_fmadds}, {1467, &ppc_fmaddsdot},
|
||||
{1468, &ppc_fnmsubs}, {1469, &ppc_fnmsubsdot}, {1470, &ppc_fnmadds}, {1471, &ppc_fnmaddsdot},
|
||||
{1522, &ppc_fmults}, {1523, &ppc_fmultsdot}, {1528, &ppc_fmsubs}, {1529, &ppc_fmsubsdot},
|
||||
{1530, &ppc_fmadds}, {1531, &ppc_fmaddsdot}, {1532, &ppc_fnmsubs}, {1533, &ppc_fnmsubsdot},
|
||||
{1534, &ppc_fnmadds}, {1535, &ppc_fnmaddsdot}, {1586, &ppc_fmults}, {1587, &ppc_fmultsdot},
|
||||
{1592, &ppc_fmsubs}, {1593, &ppc_fmsubsdot}, {1594, &ppc_fmadds}, {1595, &ppc_fmaddsdot},
|
||||
{1596, &ppc_fnmsubs}, {1597, &ppc_fnmsubsdot}, {1598, &ppc_fnmadds}, {1599, &ppc_fnmaddsdot},
|
||||
{1650, &ppc_fmults}, {1651, &ppc_fmultsdot}, {1656, &ppc_fmsubs}, {1657, &ppc_fmsubsdot},
|
||||
{1658, &ppc_fmadds}, {1659, &ppc_fmaddsdot}, {1660, &ppc_fnmsubs}, {1661, &ppc_fnmsubsdot},
|
||||
{1662, &ppc_fnmadds}, {1663, &ppc_fnmaddsdot}, {1714, &ppc_fmults}, {1715, &ppc_fmultsdot},
|
||||
{1720, &ppc_fmsubs}, {1721, &ppc_fmsubsdot}, {1722, &ppc_fmadds}, {1723, &ppc_fmaddsdot},
|
||||
{1724, &ppc_fnmsubs}, {1725, &ppc_fnmsubsdot}, {1726, &ppc_fnmadds}, {1727, &ppc_fnmaddsdot},
|
||||
{1778, &ppc_fmults}, {1779, &ppc_fmultsdot}, {1784, &ppc_fmsubs}, {1785, &ppc_fmsubsdot},
|
||||
{1786, &ppc_fmadds}, {1787, &ppc_fmaddsdot}, {1788, &ppc_fnmsubs}, {1789, &ppc_fnmsubsdot},
|
||||
{1790, &ppc_fnmadds}, {1791, &ppc_fnmaddsdot}, {1842, &ppc_fmults}, {1843, &ppc_fmultsdot},
|
||||
{1848, &ppc_fmsubs}, {1849, &ppc_fmsubsdot}, {1850, &ppc_fmadds}, {1851, &ppc_fmaddsdot},
|
||||
{1852, &ppc_fnmsubs}, {1853, &ppc_fnmsubsdot}, {1854, &ppc_fnmadds}, {1855, &ppc_fnmaddsdot},
|
||||
{1906, &ppc_fmults}, {1907, &ppc_fmultsdot}, {1912, &ppc_fmsubs}, {1913, &ppc_fmsubsdot},
|
||||
{1914, &ppc_fmadds}, {1915, &ppc_fmaddsdot}, {1916, &ppc_fnmsubs}, {1917, &ppc_fnmsubsdot},
|
||||
{1918, &ppc_fnmadds}, {1919, &ppc_fnmaddsdot}, {1970, &ppc_fmults}, {1971, &ppc_fmultsdot},
|
||||
{1976, &ppc_fmsubs}, {1977, &ppc_fmsubsdot}, {1978, &ppc_fmadds}, {1979, &ppc_fmaddsdot},
|
||||
{1980, &ppc_fnmsubs}, {1981, &ppc_fnmsubsdot}, {1982, &ppc_fnmadds}, {1983, &ppc_fnmaddsdot},
|
||||
{2034, &ppc_fmults}, {2035, &ppc_fmultsdot}, {2040, &ppc_fmsubs}, {2041, &ppc_fmsubsdot},
|
||||
{2042, &ppc_fmadds}, {2043, &ppc_fmaddsdot}, {2044, &ppc_fnmsubs}, {2045, &ppc_fnmsubsdot},
|
||||
{2046, &ppc_fnmadds}, {2047, &ppc_fnmaddsdot}};
|
||||
|
||||
/** Double-precision floating-point instructions decoding table. */
|
||||
static std::unordered_map<uint16_t, PPCOpcode> SubOpcode63Grabber = {
|
||||
{0, &ppc_fcmpu}, {24, &ppc_frsp}, {25, &ppc_frspdot}, {28, &ppc_fctiw},
|
||||
{29, &ppc_fctiwdot}, {30, &ppc_fctiwz}, {31, &ppc_fctiwzdot}, {36, &ppc_fdiv},
|
||||
{37, &ppc_fdivdot}, {40, &ppc_fsub}, {41, &ppc_fsubdot}, {42, &ppc_fadd},
|
||||
{43, &ppc_fadddot}, {44, &ppc_fsqrt}, {45, &ppc_fsqrtdot}, {46, &ppc_fsel},
|
||||
{47, &ppc_fseldot}, {50, &ppc_fmult}, {51, &ppc_fmultdot}, {52, &ppc_frsqrte},
|
||||
{53, &ppc_frsqrtedot}, {56, &ppc_fmsub}, {57, &ppc_fmsubdot}, {58, &ppc_fmadd},
|
||||
{59, &ppc_fmadddot}, {60, &ppc_fnmsub}, {61, &ppc_fnmsubdot}, {62, &ppc_fnmadd},
|
||||
{63, &ppc_fnmadddot}, {64, &ppc_fcmpo}, {76, &ppc_mtfsb1}, {77, &ppc_mtfsb1dot},
|
||||
{80, &ppc_fneg}, {81, &ppc_fnegdot}, {110, &ppc_fsel}, {111, &ppc_fseldot},
|
||||
{114, &ppc_fmult}, {115, &ppc_fmultdot}, {120, &ppc_fmsub}, {121, &ppc_fmsubdot},
|
||||
{122, &ppc_fmadd}, {123, &ppc_fmadd}, {124, &ppc_fnmsub}, {125, &ppc_fnmsubdot},
|
||||
{126, &ppc_fnmadd}, {127, &ppc_fnmadddot}, {128, &ppc_mcrfs}, {140, &ppc_mtfsb0},
|
||||
{141, &ppc_mtfsb0dot}, {144, &ppc_fmr}, {174, &ppc_fsel}, {175, &ppc_fseldot},
|
||||
{178, &ppc_fmult}, {179, &ppc_fmultdot}, {184, &ppc_fmsub}, {185, &ppc_fmsubdot},
|
||||
{186, &ppc_fmadd}, {187, &ppc_fmadddot}, {188, &ppc_fnmsub}, {189, &ppc_fnmsubdot},
|
||||
{190, &ppc_fnmadd}, {191, &ppc_fnmadddot}, {238, &ppc_fsel}, {239, &ppc_fseldot},
|
||||
{242, &ppc_fmult}, {243, &ppc_fmultdot}, {248, &ppc_fmsub}, {249, &ppc_fmsubdot},
|
||||
{250, &ppc_fmadd}, {251, &ppc_fmadddot}, {252, &ppc_fnmsub}, {253, &ppc_fnmsubdot},
|
||||
{254, &ppc_fnmadd}, {255, &ppc_fnmadddot}, {268, &ppc_mtfsfi}, {272, &ppc_fnabs},
|
||||
{273, &ppc_fnabsdot}, {302, &ppc_fsel}, {303, &ppc_fseldot}, {306, &ppc_fmult},
|
||||
{307, &ppc_fmultdot}, {312, &ppc_fmsub}, {313, &ppc_fmsubdot}, {314, &ppc_fmadd},
|
||||
{315, &ppc_fmadddot}, {316, &ppc_fnmsub}, {317, &ppc_fnmsubdot}, {318, &ppc_fnmadd},
|
||||
{319, &ppc_fnmadddot}, {366, &ppc_fsel}, {367, &ppc_fseldot}, {370, &ppc_fmult},
|
||||
{371, &ppc_fmultdot}, {376, &ppc_fmsub}, {377, &ppc_fmsubdot}, {378, &ppc_fmadd},
|
||||
{379, &ppc_fmadddot}, {380, &ppc_fnmsub}, {381, &ppc_fnmsubdot}, {382, &ppc_fnmadd},
|
||||
{383, &ppc_fnmadddot}, {430, &ppc_fsel}, {431, &ppc_fseldot}, {434, &ppc_fmult},
|
||||
{435, &ppc_fmultdot}, {440, &ppc_fmsub}, {441, &ppc_fmsubdot}, {442, &ppc_fmadd},
|
||||
{443, &ppc_fmadddot}, {444, &ppc_fnmsub}, {445, &ppc_fnmsubdot}, {446, &ppc_fnmadd},
|
||||
{447, &ppc_fnmadddot}, {494, &ppc_fsel}, {495, &ppc_fseldot}, {498, &ppc_fmult},
|
||||
{499, &ppc_fmultdot}, {504, &ppc_fmsub}, {505, &ppc_fmsubdot}, {506, &ppc_fmadd},
|
||||
{507, &ppc_fmadddot}, {508, &ppc_fnmsub}, {509, &ppc_fnmsubdot}, {510, &ppc_fnmadd},
|
||||
{511, &ppc_fnmadddot}, {528, &ppc_fabs}, {529, &ppc_fabsdot}, {536, &ppc_mtfsfidot},
|
||||
{558, &ppc_fsel}, {559, &ppc_fseldot}, {562, &ppc_fmult}, {563, &ppc_fmultdot},
|
||||
{568, &ppc_fmsub}, {569, &ppc_fmsubdot}, {570, &ppc_fmadd}, {571, &ppc_fmadddot},
|
||||
{572, &ppc_fnmsub}, {573, &ppc_fnmsubdot}, {574, &ppc_fnmadd}, {575, &ppc_fnmadddot},
|
||||
{622, &ppc_fsel}, {623, &ppc_fseldot}, {626, &ppc_fmult}, {627, &ppc_fmultdot},
|
||||
{632, &ppc_fmsub}, {633, &ppc_fmsubdot}, {634, &ppc_fmadd}, {635, &ppc_fmadddot},
|
||||
{636, &ppc_fnmsub}, {637, &ppc_fnmsubdot}, {638, &ppc_fnmadd}, {639, &ppc_fnmadddot},
|
||||
{686, &ppc_fsel}, {687, &ppc_fseldot}, {690, &ppc_fmult}, {691, &ppc_fmultdot},
|
||||
{696, &ppc_fmsub}, {697, &ppc_fmsubdot}, {698, &ppc_fmadd}, {699, &ppc_fmadddot},
|
||||
{700, &ppc_fnmsub}, {701, &ppc_fnmsubdot}, {702, &ppc_fnmadd}, {703, &ppc_fnmadddot},
|
||||
{750, &ppc_fsel}, {751, &ppc_fseldot}, {754, &ppc_fmult}, {755, &ppc_fmultdot},
|
||||
{760, &ppc_fmsub}, {761, &ppc_fmsubdot}, {762, &ppc_fmadd}, {763, &ppc_fmadddot},
|
||||
{764, &ppc_fnmsub}, {765, &ppc_fnmsubdot}, {766, &ppc_fnmadd}, {767, &ppc_fnmadddot},
|
||||
{814, &ppc_fsel}, {815, &ppc_fseldot}, {818, &ppc_fmult}, {819, &ppc_fmultdot},
|
||||
{824, &ppc_fmsub}, {825, &ppc_fmsubdot}, {826, &ppc_fmadd}, {827, &ppc_fmadddot},
|
||||
{828, &ppc_fnmsub}, {829, &ppc_fnmsubdot}, {830, &ppc_fnmadd}, {831, &ppc_fnmadddot},
|
||||
{878, &ppc_fsel}, {879, &ppc_fseldot}, {882, &ppc_fmult}, {883, &ppc_fmultdot},
|
||||
{888, &ppc_fmsub}, {889, &ppc_fmsubdot}, {890, &ppc_fmadd}, {891, &ppc_fmadddot},
|
||||
{892, &ppc_fnmsub}, {893, &ppc_fnmsubdot}, {894, &ppc_fnmadd}, {895, &ppc_fnmadddot},
|
||||
{942, &ppc_fsel}, {943, &ppc_fseldot}, {946, &ppc_fmult}, {947, &ppc_fmultdot},
|
||||
{952, &ppc_fmsub}, {953, &ppc_fmsubdot}, {954, &ppc_fmadd}, {955, &ppc_fmadddot},
|
||||
{957, &ppc_fnmsub}, {958, &ppc_fnmsubdot}, {958, &ppc_fnmadd}, {959, &ppc_fnmadddot},
|
||||
{1006, &ppc_fsel}, {1007, &ppc_fseldot}, {1010, &ppc_fmult}, {1011, &ppc_fmultdot},
|
||||
{1016, &ppc_fmsub}, {1017, &ppc_fmsubdot}, {1018, &ppc_fmadd}, {1019, &ppc_fmadddot},
|
||||
{1020, &ppc_fnmsub}, {1021, &ppc_fnmsubdot}, {1022, &ppc_fnmadd}, {1023, &ppc_fnmadddot},
|
||||
{1070, &ppc_fsel}, {1071, &ppc_fseldot}, {1074, &ppc_fmult}, {1075, &ppc_fmultdot},
|
||||
{1080, &ppc_fmsub}, {1081, &ppc_fmsubdot}, {1082, &ppc_fmadd}, {1083, &ppc_fmadddot},
|
||||
{1084, &ppc_fnmsub}, {1085, &ppc_fnmsubdot}, {1086, &ppc_fnmadd}, {1087, &ppc_fnmadddot},
|
||||
{1134, &ppc_fsel}, {1135, &ppc_fseldot}, {1138, &ppc_fmult}, {1139, &ppc_fmultdot},
|
||||
{1144, &ppc_fmsub}, {1145, &ppc_fmsubdot}, {1146, &ppc_fmadd}, {1147, &ppc_fmadddot},
|
||||
{1148, &ppc_fnmsub}, {1149, &ppc_fnmsubdot}, {1150, &ppc_fnmadd}, {1151, &ppc_fnmadddot},
|
||||
{1166, &ppc_mffs}, {1167, &ppc_mffsdot}, {1198, &ppc_fsel}, {1199, &ppc_fseldot},
|
||||
{1202, &ppc_fmult}, {1203, &ppc_fmultdot}, {1208, &ppc_fmsub}, {1209, &ppc_fmsubdot},
|
||||
{1210, &ppc_fmadd}, {1211, &ppc_fmadddot}, {1212, &ppc_fnmsub}, {1213, &ppc_fnmsubdot},
|
||||
{1214, &ppc_fnmadd}, {1215, &ppc_fnmadddot}, {1262, &ppc_fsel}, {1263, &ppc_fseldot},
|
||||
{1266, &ppc_fmult}, {1267, &ppc_fmultdot}, {1272, &ppc_fmsub}, {1273, &ppc_fmsubdot},
|
||||
{1274, &ppc_fmadd}, {1275, &ppc_fmadddot}, {1276, &ppc_fnmsub}, {1277, &ppc_fnmsubdot},
|
||||
{1278, &ppc_fnmadd}, {1279, &ppc_fnmadddot}, {1326, &ppc_fsel}, {1327, &ppc_fseldot},
|
||||
{1330, &ppc_fmult}, {1331, &ppc_fmultdot}, {1336, &ppc_fmsub}, {1337, &ppc_fmsubdot},
|
||||
{1338, &ppc_fmadd}, {1339, &ppc_fmadddot}, {1340, &ppc_fnmsub}, {1341, &ppc_fnmsubdot},
|
||||
{1342, &ppc_fnmadd}, {1343, &ppc_fnmadddot}, {1390, &ppc_fsel}, {1391, &ppc_fseldot},
|
||||
{1394, &ppc_fmult}, {1395, &ppc_fmultdot}, {1400, &ppc_fmsub}, {1401, &ppc_fmsubdot},
|
||||
{1402, &ppc_fmadd}, {1403, &ppc_fmadddot}, {1404, &ppc_fnmsub}, {1405, &ppc_fnmsubdot},
|
||||
{1406, &ppc_fnmadd}, {1407, &ppc_fnmadddot}, {1422, &ppc_mtfsf}, {1423, &ppc_mtfsfdot},
|
||||
{1454, &ppc_fsel}, {1455, &ppc_fseldot}, {1458, &ppc_fmult}, {1459, &ppc_fmultdot},
|
||||
{1464, &ppc_fmsub}, {1465, &ppc_fmsubdot}, {1466, &ppc_fmadd}, {1467, &ppc_fmadddot},
|
||||
{1468, &ppc_fnmsub}, {1469, &ppc_fnmsubdot}, {1470, &ppc_fnmadd}, {1471, &ppc_fnmadddot},
|
||||
{1518, &ppc_fsel}, {1519, &ppc_fseldot}, {1522, &ppc_fmult}, {1523, &ppc_fmultdot},
|
||||
{1528, &ppc_fmsub}, {1529, &ppc_fmsubdot}, {1530, &ppc_fmadd}, {1531, &ppc_fmadddot},
|
||||
{1532, &ppc_fnmsub}, {1533, &ppc_fnmsubdot}, {1534, &ppc_fnmadd}, {1535, &ppc_fnmadddot},
|
||||
{1582, &ppc_fsel}, {1583, &ppc_fseldot}, {1586, &ppc_fmult}, {1587, &ppc_fmultdot},
|
||||
{1592, &ppc_fmsub}, {1593, &ppc_fmsubdot}, {1594, &ppc_fmadd}, {1595, &ppc_fmadddot},
|
||||
{1596, &ppc_fnmsub}, {1597, &ppc_fnmsubdot}, {1598, &ppc_fnmadd}, {1599, &ppc_fnmadddot},
|
||||
{1646, &ppc_fsel}, {1647, &ppc_fseldot}, {1650, &ppc_fmult}, {1651, &ppc_fmultdot},
|
||||
{1656, &ppc_fmsub}, {1657, &ppc_fmsubdot}, {1658, &ppc_fmadd}, {1659, &ppc_fmadddot},
|
||||
{1660, &ppc_fnmsub}, {1661, &ppc_fnmsubdot}, {1662, &ppc_fnmadd}, {1663, &ppc_fnmadddot},
|
||||
{1710, &ppc_fsel}, {1711, &ppc_fseldot}, {1714, &ppc_fmult}, {1715, &ppc_fmultdot},
|
||||
{1720, &ppc_fmsub}, {1721, &ppc_fmsubdot}, {1722, &ppc_fmadd}, {1723, &ppc_fmadddot},
|
||||
{1724, &ppc_fnmsub}, {1725, &ppc_fnmsubdot}, {1726, &ppc_fnmadd}, {1727, &ppc_fnmadddot},
|
||||
{1774, &ppc_fsel}, {1775, &ppc_fseldot}, {1778, &ppc_fmult}, {1779, &ppc_fmultdot},
|
||||
{1784, &ppc_fmsub}, {1785, &ppc_fmsubdot}, {1786, &ppc_fmadd}, {1787, &ppc_fmadddot},
|
||||
{1788, &ppc_fnmsub}, {1789, &ppc_fnmsubdot}, {1790, &ppc_fnmadd}, {1791, &ppc_fnmadddot},
|
||||
{1838, &ppc_fsel}, {1839, &ppc_fseldot}, {1842, &ppc_fmult}, {1843, &ppc_fmultdot},
|
||||
{1848, &ppc_fmsub}, {1849, &ppc_fmsubdot}, {1850, &ppc_fmadd}, {1851, &ppc_fmadddot},
|
||||
{1852, &ppc_fnmsub}, {1853, &ppc_fnmsubdot}, {1854, &ppc_fnmadd}, {1855, &ppc_fnmadddot},
|
||||
{1902, &ppc_fsel}, {1903, &ppc_fseldot}, {1906, &ppc_fmult}, {1907, &ppc_fmultdot},
|
||||
{1912, &ppc_fmsub}, {1913, &ppc_fmsubdot}, {1914, &ppc_fmadd}, {1915, &ppc_fmadddot},
|
||||
{1916, &ppc_fnmsub}, {1917, &ppc_fnmsubdot}, {1918, &ppc_fnmadd}, {1919, &ppc_fnmadddot},
|
||||
{1966, &ppc_fsel}, {1967, &ppc_fseldot}, {1970, &ppc_fmult}, {1971, &ppc_fmultdot},
|
||||
{1976, &ppc_fmsub}, {1977, &ppc_fmsubdot}, {1978, &ppc_fmadd}, {1979, &ppc_fmadddot},
|
||||
{1980, &ppc_fnmsub}, {1981, &ppc_fnmsubdot}, {1982, &ppc_fnmadd}, {1983, &ppc_fnmadddot},
|
||||
{2030, &ppc_fsel}, {2031, &ppc_fseldot}, {2034, &ppc_fmult}, {2035, &ppc_fmultdot},
|
||||
{2040, &ppc_fmsub}, {2041, &ppc_fmsubdot}, {2042, &ppc_fmadd}, {2043, &ppc_fmadddot},
|
||||
{2044, &ppc_fnmsub}, {2045, &ppc_fnmsubdot}, {2046, &ppc_fnmadd}, {2047, &ppc_fnmadddot}};
|
||||
PPCOpcode SubOpcode31Grabber[1024] = { ppc_illegalop };
|
||||
PPCOpcode SubOpcode59Grabber[32] = { ppc_illegalop };
|
||||
PPCOpcode SubOpcode63Grabber[1024] = { ppc_illegalop };
|
||||
|
||||
|
||||
#define UPDATE_TBR_DEC \
|
||||
@@ -420,22 +168,18 @@ static std::unordered_map<uint16_t, PPCOpcode> SubOpcode63Grabber = {
|
||||
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_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]();
|
||||
}
|
||||
@@ -445,72 +189,103 @@ void ppc_opcode18() {
|
||||
}
|
||||
|
||||
void ppc_opcode19() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 2047;
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x7FF;
|
||||
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 19 table subopcode entry \n", regrab);
|
||||
if (SubOpcode19Grabber.count(subop_grab) == 1) {
|
||||
SubOpcode19Grabber[subop_grab]();
|
||||
} else {
|
||||
LOG_F(ERROR, "ILLEGAL SUBOPCODE: %d \n", subop_grab);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x80000);
|
||||
}
|
||||
#else
|
||||
SubOpcode19Grabber[subop_grab]();
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
|
||||
if (subop_grab == 32) {
|
||||
ppc_bclr();
|
||||
} else if (subop_grab == 33) {
|
||||
ppc_bclrl();
|
||||
} else if (subop_grab == 1056) {
|
||||
ppc_bcctr();
|
||||
} else if (subop_grab == 1057) {
|
||||
ppc_bcctrl();
|
||||
|
||||
} else {
|
||||
switch (subop_grab) {
|
||||
case 0:
|
||||
ppc_mcrf();
|
||||
break;
|
||||
case 66:
|
||||
ppc_crnor();
|
||||
break;
|
||||
case 100:
|
||||
ppc_rfi();
|
||||
break;
|
||||
case 258:
|
||||
ppc_crandc();
|
||||
break;
|
||||
case 300:
|
||||
ppc_isync();
|
||||
break;
|
||||
case 386:
|
||||
ppc_crxor();
|
||||
break;
|
||||
case 450:
|
||||
ppc_crnand();
|
||||
break;
|
||||
case 514:
|
||||
ppc_crand();
|
||||
break;
|
||||
case 578:
|
||||
ppc_creqv();
|
||||
break;
|
||||
case 834:
|
||||
ppc_crorc();
|
||||
break;
|
||||
case 898:
|
||||
ppc_cror();
|
||||
break;
|
||||
default:
|
||||
ppc_illegalop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ppc_opcode31() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 2047;
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 31 table subopcode entry \n", regrab);
|
||||
if (SubOpcode31Grabber.count(subop_grab) == 1) {
|
||||
SubOpcode31Grabber[subop_grab]();
|
||||
} else {
|
||||
LOG_F(ERROR, "ILLEGAL SUBOPCODE: %d \n", subop_grab);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x80000);
|
||||
}
|
||||
#else
|
||||
SubOpcode31Grabber[subop_grab]();
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
}
|
||||
uint16_t subop_grab = (ppc_cur_instruction & 0x7FF) >> 1;
|
||||
|
||||
void ppc_opcode59() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 2047;
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 59 table subopcode entry \n", regrab);
|
||||
if (SubOpcode59Grabber.count(subop_grab) == 1) {
|
||||
SubOpcode59Grabber[subop_grab]();
|
||||
} else {
|
||||
LOG_F(ERROR, "ILLEGAL SUBOPCODE: %d \n", subop_grab);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x80000);
|
||||
}
|
||||
#else
|
||||
SubOpcode59Grabber[subop_grab]();
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
}
|
||||
rc_flag = ppc_cur_instruction & 0x1;
|
||||
oe_flag = ppc_cur_instruction & 0x400;
|
||||
|
||||
void ppc_opcode63() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 2047;
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 63 table subopcode entry \n", regrab);
|
||||
if (SubOpcode63Grabber.count(subop_grab) == 1) {
|
||||
SubOpcode63Grabber[subop_grab]();
|
||||
} else {
|
||||
LOG_F(ERROR, "ILLEGAL SUBOPCODE: %d \n", subop_grab);
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, 0x80000);
|
||||
}
|
||||
#else
|
||||
SubOpcode63Grabber[subop_grab]();
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
|
||||
SubOpcode31Grabber[subop_grab]();
|
||||
}
|
||||
|
||||
void ppc_opcode59() {
|
||||
uint16_t subop_grab = (ppc_cur_instruction >> 1) & 0x1F;
|
||||
rc_flag = ppc_cur_instruction & 1;
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 59 table subopcode entry \n", regrab);
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
SubOpcode59Grabber[subop_grab]();
|
||||
}
|
||||
|
||||
void ppc_opcode63() {
|
||||
uint16_t subop_grab = (ppc_cur_instruction >> 1) & 0x3FF;
|
||||
rc_flag = ppc_cur_instruction & 1;
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 63 table subopcode entry \n", regrab);
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
SubOpcode63Grabber[subop_grab]();
|
||||
}
|
||||
|
||||
/* Dispatch using main opcode */
|
||||
void ppc_main_opcode()
|
||||
{
|
||||
#ifdef CPU_PROFILING
|
||||
num_executed_instrs++;
|
||||
#endif
|
||||
OpcodeGrabber[(ppc_cur_instruction >> 26) & 0x3F]();
|
||||
}
|
||||
|
||||
@@ -534,7 +309,8 @@ 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 = quickinstruction_translate(bb_start_la);
|
||||
//pc_real = mmu_translate_imem(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;
|
||||
@@ -542,7 +318,8 @@ void ppc_exec()
|
||||
}
|
||||
|
||||
/* initial MMU translation for the current code page. */
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
//pc_real = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
|
||||
/* set current code page limits */
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
@@ -560,7 +337,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 = 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);
|
||||
@@ -593,7 +370,8 @@ void ppc_exec_single()
|
||||
return;
|
||||
}
|
||||
|
||||
quickinstruction_translate(ppc_state.pc);
|
||||
//quickinstruction_translate(ppc_state.pc);
|
||||
mmu_translate_imem(ppc_state.pc);
|
||||
ppc_main_opcode();
|
||||
if (bb_kind != BB_end_kind::BB_NONE) {
|
||||
ppc_state.pc = ppc_next_instruction_address;
|
||||
@@ -610,7 +388,7 @@ void ppc_exec_single()
|
||||
}
|
||||
|
||||
/** Execute PPC code until goal_addr is reached. */
|
||||
void ppc_exec_until(uint32_t goal_addr)
|
||||
void ppc_exec_until(volatile uint32_t goal_addr)
|
||||
{
|
||||
uint32_t bb_start_la, page_start, delta;
|
||||
uint8_t* pc_real;
|
||||
@@ -628,7 +406,7 @@ void ppc_exec_until(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 = 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;
|
||||
@@ -636,7 +414,8 @@ void ppc_exec_until(uint32_t goal_addr)
|
||||
}
|
||||
|
||||
/* initial MMU translation for the current code page. */
|
||||
pc_real = quickinstruction_translate(bb_start_la);
|
||||
//pc_real = quickinstruction_translate(bb_start_la);
|
||||
pc_real = mmu_translate_imem(bb_start_la);
|
||||
|
||||
/* set current code page limits */
|
||||
page_start = bb_start_la & 0xFFFFF000;
|
||||
@@ -654,7 +433,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 = 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);
|
||||
@@ -669,6 +448,70 @@ 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;
|
||||
|
||||
@@ -704,6 +547,195 @@ void test_timebase_update()
|
||||
|
||||
}
|
||||
|
||||
void initialize_ppc_opcode_tables() {
|
||||
SubOpcode31Grabber[0] = ppc_cmp;
|
||||
SubOpcode31Grabber[4] = ppc_tw;
|
||||
SubOpcode31Grabber[32] = ppc_cmpl;
|
||||
|
||||
SubOpcode31Grabber[8] = SubOpcode31Grabber[520] = ppc_subfc;
|
||||
SubOpcode31Grabber[40] = SubOpcode31Grabber[552] = ppc_subf;
|
||||
SubOpcode31Grabber[104] = SubOpcode31Grabber[616] = ppc_neg;
|
||||
SubOpcode31Grabber[136] = SubOpcode31Grabber[648] = ppc_subfe;
|
||||
SubOpcode31Grabber[200] = SubOpcode31Grabber[712] = ppc_subfze;
|
||||
SubOpcode31Grabber[232] = SubOpcode31Grabber[744] = ppc_subfme;
|
||||
|
||||
SubOpcode31Grabber[10] = SubOpcode31Grabber[522] = ppc_addc;
|
||||
SubOpcode31Grabber[138] = SubOpcode31Grabber[650] = ppc_adde;
|
||||
SubOpcode31Grabber[202] = SubOpcode31Grabber[714] = ppc_addze;
|
||||
SubOpcode31Grabber[234] = SubOpcode31Grabber[746] = ppc_addme;
|
||||
SubOpcode31Grabber[266] = SubOpcode31Grabber[778] = ppc_add;
|
||||
|
||||
SubOpcode31Grabber[11] = ppc_mulhwu;
|
||||
SubOpcode31Grabber[75] = ppc_mulhw;
|
||||
SubOpcode31Grabber[235] = SubOpcode31Grabber[747] = ppc_mullw;
|
||||
SubOpcode31Grabber[459] = SubOpcode31Grabber[971] = ppc_divwu;
|
||||
SubOpcode31Grabber[491] = SubOpcode31Grabber[1003] = ppc_divw;
|
||||
|
||||
SubOpcode31Grabber[20] = ppc_lwarx;
|
||||
SubOpcode31Grabber[23] = ppc_lwzx;
|
||||
SubOpcode31Grabber[55] = ppc_lwzux;
|
||||
SubOpcode31Grabber[87] = ppc_lbzx;
|
||||
SubOpcode31Grabber[119] = ppc_lbzux;
|
||||
SubOpcode31Grabber[279] = ppc_lhzx;
|
||||
SubOpcode31Grabber[311] = ppc_lhzux;
|
||||
SubOpcode31Grabber[343] = ppc_lhax;
|
||||
SubOpcode31Grabber[375] = ppc_lhaux;
|
||||
SubOpcode31Grabber[533] = ppc_lswx;
|
||||
SubOpcode31Grabber[534] = ppc_lwbrx;
|
||||
SubOpcode31Grabber[535] = ppc_lfsx;
|
||||
SubOpcode31Grabber[567] = ppc_lfsux;
|
||||
SubOpcode31Grabber[597] = ppc_lswi;
|
||||
SubOpcode31Grabber[599] = ppc_lfdx;
|
||||
SubOpcode31Grabber[631] = ppc_lfdux;
|
||||
SubOpcode31Grabber[790] = ppc_lhbrx;
|
||||
|
||||
SubOpcode31Grabber[150] = ppc_stwcx;
|
||||
SubOpcode31Grabber[151] = ppc_stwx;
|
||||
SubOpcode31Grabber[183] = ppc_stwux;
|
||||
SubOpcode31Grabber[215] = ppc_stbx;
|
||||
SubOpcode31Grabber[247] = ppc_stbux;
|
||||
SubOpcode31Grabber[407] = ppc_sthx;
|
||||
SubOpcode31Grabber[439] = ppc_sthux;
|
||||
SubOpcode31Grabber[661] = ppc_stswx;
|
||||
SubOpcode31Grabber[662] = ppc_stwbrx;
|
||||
SubOpcode31Grabber[663] = ppc_stfsx;
|
||||
SubOpcode31Grabber[695] = ppc_stfsux;
|
||||
SubOpcode31Grabber[725] = ppc_stswi;
|
||||
SubOpcode31Grabber[727] = ppc_stfdx;
|
||||
SubOpcode31Grabber[759] = ppc_stfdux;
|
||||
SubOpcode31Grabber[918] = ppc_sthbrx;
|
||||
SubOpcode31Grabber[983] = ppc_stfiwx;
|
||||
|
||||
SubOpcode31Grabber[24] = ppc_slw;
|
||||
SubOpcode31Grabber[28] = ppc_and;
|
||||
SubOpcode31Grabber[60] = ppc_andc;
|
||||
SubOpcode31Grabber[124] = ppc_nor;
|
||||
SubOpcode31Grabber[284] = ppc_eqv;
|
||||
SubOpcode31Grabber[316] = ppc_xor;
|
||||
SubOpcode31Grabber[412] = ppc_orc;
|
||||
SubOpcode31Grabber[444] = ppc_or;
|
||||
SubOpcode31Grabber[476] = ppc_nand;
|
||||
SubOpcode31Grabber[536] = ppc_srw;
|
||||
SubOpcode31Grabber[792] = ppc_sraw;
|
||||
SubOpcode31Grabber[824] = ppc_srawi;
|
||||
SubOpcode31Grabber[922] = ppc_extsh;
|
||||
SubOpcode31Grabber[954] = ppc_extsb;
|
||||
|
||||
SubOpcode31Grabber[26] = ppc_cntlzw;
|
||||
|
||||
SubOpcode31Grabber[19] = ppc_mfcr;
|
||||
SubOpcode31Grabber[83] = ppc_mfmsr;
|
||||
SubOpcode31Grabber[144] = ppc_mtcrf;
|
||||
SubOpcode31Grabber[146] = ppc_mtmsr;
|
||||
SubOpcode31Grabber[210] = ppc_mtsr;
|
||||
SubOpcode31Grabber[242] = ppc_mtsrin;
|
||||
SubOpcode31Grabber[339] = ppc_mfspr;
|
||||
SubOpcode31Grabber[371] = ppc_mftb;
|
||||
SubOpcode31Grabber[467] = ppc_mtspr;
|
||||
SubOpcode31Grabber[512] = ppc_mcrxr;
|
||||
SubOpcode31Grabber[595] = ppc_mfsr;
|
||||
SubOpcode31Grabber[659] = ppc_mfsrin;
|
||||
|
||||
SubOpcode31Grabber[54] = ppc_dcbst;
|
||||
SubOpcode31Grabber[86] = ppc_dcbf;
|
||||
SubOpcode31Grabber[246] = ppc_dcbtst;
|
||||
SubOpcode31Grabber[278] = ppc_dcbt;
|
||||
SubOpcode31Grabber[598] = ppc_sync;
|
||||
SubOpcode31Grabber[470] = ppc_dcbi;
|
||||
SubOpcode31Grabber[1014] = ppc_dcbz;
|
||||
|
||||
SubOpcode31Grabber[29] = power_maskg;
|
||||
SubOpcode31Grabber[107] = SubOpcode31Grabber[619] = power_mul;
|
||||
SubOpcode31Grabber[152] = power_slq;
|
||||
SubOpcode31Grabber[153] = power_sle;
|
||||
SubOpcode31Grabber[184] = power_sliq;
|
||||
SubOpcode31Grabber[216] = power_sllq;
|
||||
SubOpcode31Grabber[217] = power_sleq;
|
||||
SubOpcode31Grabber[248] = power_slliq;
|
||||
SubOpcode31Grabber[264] = SubOpcode31Grabber[776] = power_doz;
|
||||
SubOpcode31Grabber[277] = power_lscbx;
|
||||
SubOpcode31Grabber[331] = SubOpcode31Grabber[843] = power_div;
|
||||
SubOpcode31Grabber[360] = SubOpcode31Grabber[872] = power_abs;
|
||||
SubOpcode31Grabber[363] = SubOpcode31Grabber[875] = power_divs;
|
||||
SubOpcode31Grabber[488] = SubOpcode31Grabber[1000] = power_nabs;
|
||||
SubOpcode31Grabber[531] = power_clcs;
|
||||
SubOpcode31Grabber[537] = power_rrib;
|
||||
SubOpcode31Grabber[541] = power_maskir;
|
||||
SubOpcode31Grabber[664] = power_srq;
|
||||
SubOpcode31Grabber[665] = power_sre;
|
||||
SubOpcode31Grabber[696] = power_sriq;
|
||||
SubOpcode31Grabber[728] = power_srlq;
|
||||
SubOpcode31Grabber[729] = power_sreq;
|
||||
SubOpcode31Grabber[760] = power_srliq;
|
||||
SubOpcode31Grabber[920] = power_sraq;
|
||||
SubOpcode31Grabber[921] = power_srea;
|
||||
SubOpcode31Grabber[952] = power_sraiq;
|
||||
|
||||
SubOpcode31Grabber[306] = ppc_tlbie;
|
||||
SubOpcode31Grabber[370] = ppc_tlbia;
|
||||
SubOpcode31Grabber[566] = ppc_tlbsync;
|
||||
SubOpcode31Grabber[854] = ppc_eieio;
|
||||
SubOpcode31Grabber[982] = ppc_icbi;
|
||||
SubOpcode31Grabber[978] = ppc_tlbld;
|
||||
SubOpcode31Grabber[1010] = ppc_tlbli;
|
||||
|
||||
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;
|
||||
|
||||
SubOpcode63Grabber[0] = ppc_fcmpu;
|
||||
SubOpcode63Grabber[12] = ppc_frsp;
|
||||
SubOpcode63Grabber[14] = ppc_fctiw;
|
||||
SubOpcode63Grabber[15] = ppc_fctiwz;
|
||||
SubOpcode63Grabber[18] = ppc_fdiv;
|
||||
SubOpcode63Grabber[20] = ppc_fsub;
|
||||
SubOpcode63Grabber[21] = ppc_fadd;
|
||||
SubOpcode63Grabber[22] = ppc_fsqrt;
|
||||
SubOpcode63Grabber[26] = ppc_frsqrte;
|
||||
SubOpcode63Grabber[32] = ppc_fcmpo;
|
||||
SubOpcode63Grabber[38] = ppc_mtfsb1;
|
||||
SubOpcode63Grabber[40] = ppc_fneg;
|
||||
SubOpcode63Grabber[64] = ppc_mcrfs;
|
||||
SubOpcode63Grabber[70] = ppc_mtfsb0;
|
||||
SubOpcode63Grabber[72] = ppc_fmr;
|
||||
SubOpcode63Grabber[134] = ppc_mtfsfi;
|
||||
SubOpcode63Grabber[136] = ppc_fnabs;
|
||||
SubOpcode63Grabber[264] = ppc_fabs;
|
||||
SubOpcode63Grabber[583] = ppc_mffs;
|
||||
SubOpcode63Grabber[711] = ppc_mtfsf;
|
||||
|
||||
for (int i = 23; i < 1024; i += 32) {
|
||||
SubOpcode63Grabber[i] = ppc_fsel;
|
||||
}
|
||||
|
||||
for (int i = 25; i < 1024; i += 32) {
|
||||
SubOpcode63Grabber[i] = ppc_fmul;
|
||||
}
|
||||
|
||||
for (int i = 28; i < 1024; i += 32) {
|
||||
SubOpcode63Grabber[i] = ppc_fmsub;
|
||||
}
|
||||
|
||||
for (int i = 29; i < 1024; i += 32) {
|
||||
SubOpcode63Grabber[i] = ppc_fmadd;
|
||||
}
|
||||
|
||||
for (int i = 30; i < 1024; i += 32) {
|
||||
SubOpcode63Grabber[i] = ppc_fnmsub;
|
||||
}
|
||||
|
||||
for (int i = 31; i < 1024; i += 32) {
|
||||
SubOpcode63Grabber[i] = ppc_fnmadd;
|
||||
}
|
||||
}
|
||||
|
||||
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version) {
|
||||
int i;
|
||||
|
||||
@@ -711,6 +743,8 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version) {
|
||||
|
||||
//test_timebase_update();
|
||||
|
||||
initialize_ppc_opcode_tables();
|
||||
|
||||
/* initialize timer variables */
|
||||
#ifdef NEW_TBR_UPDATE_ALGO
|
||||
cycles_count = 0;
|
||||
@@ -767,18 +801,11 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t proc_version) {
|
||||
|
||||
/* redirect code execution to reset vector */
|
||||
ppc_state.pc = 0xFFF00100;
|
||||
}
|
||||
|
||||
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;
|
||||
#ifdef CPU_PROFILING
|
||||
gProfilerObj->register_profile("PPC_CPU",
|
||||
std::unique_ptr<BaseProfile>(new CPUProfile()));
|
||||
#endif
|
||||
}
|
||||
|
||||
void print_fprs() {
|
||||
|
||||
+453
-738
File diff suppressed because it is too large.
Load diff
+1457
-222
File diff suppressed because it is too large.
Load diff
+70
-6
@@ -19,14 +19,15 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// The opcodes for the processor - ppcopcodes.cpp
|
||||
/** @file PowerPC Memory Management Unit definitions. */
|
||||
|
||||
#ifndef PPCMEMORY_H
|
||||
#define PPCMEMORY_H
|
||||
#ifndef PPCMMU_H
|
||||
#define PPCMMU_H
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
#include "devices/memctrlbase.h"
|
||||
|
||||
/* Uncomment this to exhaustive MMU integrity checks. */
|
||||
//#define MMU_INTEGRITY_CHECKS
|
||||
@@ -36,17 +37,80 @@ 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 lo_mask; /* mask for low-order logical address bits */
|
||||
uint32_t hi_mask; /* mask for high-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);
|
||||
@@ -55,7 +119,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 // PPCMEMORY_H
|
||||
#endif // PPCMMU_H
|
||||
+771
-1011
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,sftd,f30,-0x10(r1)
|
||||
0xFFF00100,0xD8010860,sftd,f0,0x860(r1)
|
||||
0xFFF00100,0xDC180008,sftdu,f0,0x8(r24)
|
||||
0xFFF00100,0xDBC1FFF0,stfd,f30,-0x10(r1)
|
||||
0xFFF00100,0xD8010860,stfd,f0,0x860(r1)
|
||||
0xFFF00100,0xDC180008,stfdu,f0,0x8(r24)
|
||||
0xFFF00100,0xD01E0110,stfs,f0,0x110(r30)
|
||||
0xFFF00100,0xD58B0004,stfsu,f12,0x4(r11)
|
||||
0xFFF00100,0x7C1C5CAE,lfdx,f0,r28,r11
|
||||
@@ -362,9 +362,21 @@
|
||||
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
|
||||
@@ -384,6 +396,7 @@
|
||||
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
|
||||
|
||||
|
@@ -142,6 +142,8 @@ static void read_test_data() {
|
||||
}
|
||||
|
||||
int main() {
|
||||
initialize_ppc_opcode_tables(); //kludge
|
||||
|
||||
cout << "Running DingusPPC emulator tests..." << endl << endl;
|
||||
|
||||
ntested = 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/capstone/include")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
add_library(debugger OBJECT ${SOURCES})
|
||||
+321
-51
@@ -19,9 +19,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cpu/ppc/ppcdisasm.h"
|
||||
#include "../cpu/ppc/ppcemu.h"
|
||||
#include "../cpu/ppc/ppcmmu.h"
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
@@ -30,7 +28,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include "../cpu/ppc/ppcdisasm.h"
|
||||
#include "../cpu/ppc/ppcemu.h"
|
||||
#include "../cpu/ppc/ppcmmu.h"
|
||||
#include "utils/profiler.h"
|
||||
|
||||
#ifdef ENABLE_68K_DEBUGGER // optionally defined in CMakeLists.txt
|
||||
#include <capstone/capstone.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -52,42 +57,178 @@ static uint32_t str2num(string& num_str) {
|
||||
|
||||
static void show_help() {
|
||||
cout << "Debugger commands:" << 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;
|
||||
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;
|
||||
#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 << " 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 << " 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 << "Pressing ENTER will repeat last command." << endl;
|
||||
}
|
||||
|
||||
static void disasm(uint32_t count, uint32_t address) {
|
||||
PPCDisasmContext ctx;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
|
||||
ctx.instr_addr = address;
|
||||
ctx.simplified = true;
|
||||
static void disasm_68k(uint32_t count, uint32_t address) {
|
||||
csh cs_handle;
|
||||
uint8_t code[10];
|
||||
size_t code_size;
|
||||
uint64_t dis_addr;
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ctx.instr_code = mem_read_dbg(ctx.instr_addr, 4);
|
||||
cout << uppercase << hex << ctx.instr_addr;
|
||||
cout << " " << disassemble_single(&ctx) << endl;
|
||||
if (cs_open(CS_ARCH_M68K, CS_MODE_M68K_040, &cs_handle) != CS_ERR_OK) {
|
||||
cout << "Capstone initialization error" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
cs_insn* insn = cs_malloc(cs_handle);
|
||||
|
||||
for (; count > 0; count--) {
|
||||
/* prefetch opcode bytes (a 68k instruction can occupy 2...10 bytes) */
|
||||
for (int i = 0; i < sizeof(code); i++) {
|
||||
code[i] = mem_read_dbg(address + i, 1);
|
||||
}
|
||||
|
||||
const uint8_t *code_ptr = code;
|
||||
code_size = sizeof(code);
|
||||
dis_addr = address;
|
||||
|
||||
if (cs_disasm_iter(cs_handle, &code_ptr, &code_size, &dis_addr, insn)) {
|
||||
cout << uppercase << hex << insn->address << " ";
|
||||
cout << setfill(' ');
|
||||
cout << setw(10) << left << insn->mnemonic << insn->op_str << endl;
|
||||
address = dis_addr;
|
||||
} else {
|
||||
cout << "DS.W " << hex << ((code[0] << 8) | code[1]) << endl;
|
||||
address += 2;
|
||||
}
|
||||
}
|
||||
|
||||
cs_free(insn, 1);
|
||||
cs_close(&cs_handle);
|
||||
}
|
||||
|
||||
/* emulator opcode table size --> 512 KB */
|
||||
#define EMU_68K_TABLE_SIZE 0x80000
|
||||
|
||||
/** Execute one emulated 68k instruction. */
|
||||
void exec_single_68k()
|
||||
{
|
||||
string reg;
|
||||
uint32_t emu_table_virt, cur_68k_pc, cur_instr_tab_entry, ppc_pc;
|
||||
|
||||
/* PPC r24 contains 68k PC advanced by two bytes
|
||||
as part of instruction prefetching */
|
||||
reg = "R24";
|
||||
cur_68k_pc = get_reg(reg) - 2;
|
||||
|
||||
/* PPC r29 contains base address of the emulator opcode table */
|
||||
reg = "R29";
|
||||
emu_table_virt = get_reg(reg) & 0xFFF80000;
|
||||
|
||||
/* calculate address of the current opcode table entry as follows:
|
||||
get_word(68k_PC) * entry_size + table_base */
|
||||
cur_instr_tab_entry = 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";
|
||||
}
|
||||
}
|
||||
|
||||
void print_68k_regs()
|
||||
{
|
||||
int i;
|
||||
string reg;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
reg = "R" + to_string(i + 8);
|
||||
cout << "D" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
|
||||
}
|
||||
|
||||
for (i = 0; i < 7; i++) {
|
||||
reg = "R" + to_string(i + 16);
|
||||
cout << "A" << dec << i << " : " << uppercase << hex << get_reg(reg) << endl;
|
||||
}
|
||||
reg = "R1";
|
||||
cout << "A7 : " << uppercase << hex << get_reg(reg) << endl;
|
||||
|
||||
reg = "R24";
|
||||
cout << "PC: " << uppercase << hex << get_reg(reg) - 2 << endl;
|
||||
|
||||
reg = "R25";
|
||||
cout << "SR: " << uppercase << hex << ((get_reg(reg) & 0xFF) << 8) << endl;
|
||||
|
||||
reg = "R26";
|
||||
cout << "CCR: " << uppercase << hex << get_reg(reg) << endl;
|
||||
}
|
||||
|
||||
#endif // ENABLE_68K_DEBUGGER
|
||||
|
||||
static void dump_mem(string& params) {
|
||||
int cell_size, chars_per_line;
|
||||
bool is_char;
|
||||
@@ -169,7 +310,8 @@ static void dump_mem(string& params) {
|
||||
cout << (char)val;
|
||||
chars_per_line += cell_size;
|
||||
} else {
|
||||
cout << setw(cell_size * 2) << setfill('0') << uppercase << hex << val << " ";
|
||||
cout << setw(cell_size * 2) << setfill('0') << right;
|
||||
cout << uppercase << hex << val << " ";
|
||||
chars_per_line += cell_size * 2 + 2;
|
||||
}
|
||||
}
|
||||
@@ -181,18 +323,67 @@ 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;
|
||||
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str,
|
||||
inst_string, inst_num_str, profile_name, sub_cmd;
|
||||
uint32_t addr, inst_grab;
|
||||
std::stringstream ss;
|
||||
int log_level;
|
||||
int log_level, context;
|
||||
size_t separator_pos;
|
||||
|
||||
context = 1; /* start with the PowerPC context */
|
||||
|
||||
cout << "Welcome to the DingusPPC command line debugger." << endl;
|
||||
cout << "Please enter a command or 'help'." << endl << endl;
|
||||
|
||||
while (1) {
|
||||
cout << "ppcdbg> ";
|
||||
cout << "dingusdbg> ";
|
||||
|
||||
/* reset string stream */
|
||||
ss.str("");
|
||||
@@ -211,16 +402,26 @@ 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;
|
||||
}
|
||||
}
|
||||
#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 if (cmd == "regs") {
|
||||
print_gprs();
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
print_68k_regs();
|
||||
#endif
|
||||
} else {
|
||||
print_gprs();
|
||||
}
|
||||
} else if (cmd == "set") {
|
||||
ss >> expr_str;
|
||||
|
||||
@@ -248,7 +449,32 @@ void enter_debugger() {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else if (cmd == "step" || cmd == "si") {
|
||||
ppc_exec_single();
|
||||
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();
|
||||
}
|
||||
}
|
||||
} else if (cmd == "next" || cmd == "ni") {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str) + 4;
|
||||
@@ -257,11 +483,17 @@ void enter_debugger() {
|
||||
ss >> addr_str;
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
ppc_exec_until(addr);
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
exec_until_68k(addr);
|
||||
#endif
|
||||
} else {
|
||||
ppc_exec_until(addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else if (cmd == "disas") {
|
||||
} else if (cmd == "disas" || cmd == "da") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str.length() > 0) {
|
||||
@@ -270,35 +502,73 @@ void enter_debugger() {
|
||||
cout << "disas: not enough arguments specified." << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
inst_num_str = expr_str.substr(0, expr_str.find_first_of(","));
|
||||
inst_grab = stol(inst_num_str, NULL, 0);
|
||||
addr_str = expr_str.substr(expr_str.find_first_of(",") + 1);
|
||||
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);
|
||||
try {
|
||||
addr = str2addr(addr_str);
|
||||
} catch (invalid_argument& exc) {
|
||||
try {
|
||||
/* number conversion failed, trying reg name */
|
||||
addr = get_reg(addr_str);
|
||||
if (context == 2 && (addr_str == "pc" || addr_str == "PC")) {
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str) - 2;
|
||||
} else {
|
||||
addr = get_reg(addr_str);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
try {
|
||||
disasm(inst_grab, addr);
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
disasm_68k(inst_grab, addr);
|
||||
#endif
|
||||
} else {
|
||||
disasm(inst_grab, addr);
|
||||
}
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else {
|
||||
/* disas without arguments defaults to disas 1,pc */
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str);
|
||||
disasm(1, addr);
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
addr_str = "R24";
|
||||
addr = get_reg(addr_str);
|
||||
disasm_68k(1, addr - 2);
|
||||
#endif
|
||||
} else {
|
||||
addr_str = "PC";
|
||||
addr = get_reg(addr_str);
|
||||
disasm(1, addr);
|
||||
}
|
||||
}
|
||||
} else if (cmd == "dump") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
dump_mem(expr_str);
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
} else if (cmd == "context") {
|
||||
expr_str = "";
|
||||
ss >> expr_str;
|
||||
if (expr_str == "ppc" || expr_str == "PPC") {
|
||||
context = 1;
|
||||
} else if (expr_str == "68k" || expr_str == "68K") {
|
||||
context = 2;
|
||||
} else {
|
||||
cout << "Unknown debugging context: " << expr_str << endl;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
cout << "Unknown command: " << cmd << endl;
|
||||
continue;
|
||||
|
||||
+234
-131
@@ -21,23 +21,90 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "displayid.h"
|
||||
#include "endianswap.h"
|
||||
#include "memreadwrite.h"
|
||||
#include "memaccess.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];
|
||||
|
||||
/* 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);
|
||||
/* 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);
|
||||
|
||||
/* initialize display identification */
|
||||
this->disp_id = new DisplayID();
|
||||
@@ -52,123 +119,28 @@ ATIRage::~ATIRage()
|
||||
delete (this->disp_id);
|
||||
}
|
||||
|
||||
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";
|
||||
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";
|
||||
}
|
||||
|
||||
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] =
|
||||
@@ -188,10 +160,15 @@ uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) {
|
||||
get_reg_name(offset),
|
||||
offset,
|
||||
size,
|
||||
size_dep_read(&this->block_io_regs[offset], size));
|
||||
read_mem(&this->block_io_regs[offset], size));
|
||||
}
|
||||
|
||||
res = 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);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -200,10 +177,22 @@ 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 */
|
||||
size_dep_write(&this->block_io_regs[offset], value, size);
|
||||
write_mem(&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]);
|
||||
@@ -213,6 +202,19 @@ 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 */
|
||||
@@ -253,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 = size_dep_read(&this->pci_cfg[reg_offs], size);
|
||||
res = read_mem(&this->pci_cfg[reg_offs], size);
|
||||
|
||||
LOG_F(INFO, "Return value: 0x%X", res);
|
||||
return res;
|
||||
@@ -275,34 +277,42 @@ 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_LE_A(&this->pci_cfg[CFG_REG_BAR0], value);
|
||||
WRITE_DWORD_BE_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_LE_A(&this->pci_cfg[CFG_REG_BAR1], 0xFFFFFF01UL);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1], 0xFFFFFF01UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1], value);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1], value);
|
||||
}
|
||||
break;
|
||||
case 0x18: /* BAR 2 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], 0xFFFFF000UL);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR2], 0xFFFFF000UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR2], value);
|
||||
WRITE_DWORD_BE_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 */
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[reg_offs], 0);
|
||||
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);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
size_dep_write(&this->pci_cfg[reg_offs], value, size);
|
||||
write_mem(&this->pci_cfg[reg_offs], value, size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +323,7 @@ bool ATIRage::io_access_allowed(uint32_t offset, uint32_t* p_io_base) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t io_base = READ_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1]) & ~3;
|
||||
uint32_t io_base = READ_DWORD_LE_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);
|
||||
@@ -352,7 +362,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(INFO, "Reading ATI Rage PCI memory: region=%X, offset=%X, size %d", reg_start, offset, size);
|
||||
LOG_F(8, "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!");
|
||||
@@ -361,7 +371,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 size_dep_read(this->vram_ptr + offset, size);
|
||||
return read_mem(this->vram_ptr + offset, size);
|
||||
}
|
||||
else if (offset >= MEMMAP_OFFSET) {
|
||||
/* read from memory-mapped registers */
|
||||
@@ -376,7 +386,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(INFO, "Writing reg=%X, offset=%X, value=%X, size %d", reg_start, offset, value, size);
|
||||
LOG_F(8, "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!");
|
||||
@@ -385,7 +395,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 */
|
||||
size_dep_write(this->vram_ptr + offset, value, size);
|
||||
write_mem(this->vram_ptr + offset, value, size);
|
||||
} else if (offset >= MEMMAP_OFFSET) {
|
||||
/* write to memory-mapped registers */
|
||||
this->write_reg(offset - MEMMAP_OFFSET, value, size);
|
||||
@@ -394,3 +404,96 @@ 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;
|
||||
}
|
||||
+161
-77
@@ -26,8 +26,6 @@ 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,
|
||||
@@ -37,78 +35,159 @@ 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_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,
|
||||
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,
|
||||
};
|
||||
|
||||
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);
|
||||
@@ -135,23 +214,28 @@ 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:
|
||||
// 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 block_io_regs[512] = {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;
|
||||
|
||||
+18
-9
@@ -27,6 +27,7 @@ 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.
|
||||
|
||||
@@ -170,7 +171,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 & 0xFF) {
|
||||
switch (offset & 0xFC) {
|
||||
case 0x14:
|
||||
LOG_F(9, "read from MIO:Int_Mask2 register \n");
|
||||
res = this->int_mask2;
|
||||
@@ -196,14 +197,15 @@ 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? */
|
||||
res = 0xF0700000UL;
|
||||
LOG_F(9, "read from MIO:ID register at Address %x \n", ppc_state.pc);
|
||||
res = this->macio_id;
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "read from MIO:Feat_Ctrl register \n");
|
||||
res = this->feat_ctrl;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "unknown MIO register at %x \n", offset);
|
||||
LOG_F(WARNING, "read from unknown MIO register at %x \n", offset);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -211,17 +213,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 & 0xFF) {
|
||||
switch (offset & 0xFC) {
|
||||
case 0x14:
|
||||
LOG_F(9, "read from MIO:Int_Mask2 register \n");
|
||||
LOG_F(9, "write %x to MIO:Int_Mask2 register \n", value);
|
||||
this->int_mask2 = value;
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(9, "read from MIO:Int_Clear2 register \n");
|
||||
LOG_F(9, "write %x to MIO:Int_Clear2 register \n", value);
|
||||
this->int_clear2 = value;
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(9, "read from MIO:Int_Levels2 register \n");
|
||||
LOG_F(9, "write %x to MIO:Int_Levels2 register \n", value);
|
||||
this->int_levels2 = value;
|
||||
break;
|
||||
case 0x24:
|
||||
@@ -233,15 +235,22 @@ void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
this->int_clear1 = value;
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(9, "read from MIO:Int_Levels1 register \n");
|
||||
LOG_F(9, "write %x to MIO:Int_Levels1 register \n", value);
|
||||
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, "unknown MIO register at %x \n", offset);
|
||||
LOG_F(WARNING, "write %x to unknown MIO register at %x \n", value, offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
+9
-7
@@ -135,13 +135,15 @@ private:
|
||||
0x00 // unknown defaults
|
||||
};
|
||||
|
||||
uint32_t int_mask2;
|
||||
uint32_t int_clear2;
|
||||
uint32_t int_levels2;
|
||||
uint32_t int_mask1;
|
||||
uint32_t int_clear1;
|
||||
uint32_t int_levels1;
|
||||
uint32_t feat_ctrl; // features control register
|
||||
uint32_t int_mask2 = 0;
|
||||
uint32_t int_clear2 = 0;
|
||||
uint32_t int_levels2 = 0;
|
||||
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 */
|
||||
|
||||
+34
-23
@@ -28,6 +28,11 @@ 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);
|
||||
@@ -39,8 +44,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;
|
||||
@@ -49,7 +54,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))
|
||||
@@ -59,12 +64,14 @@ bool MemCtrlBase::add_mem_region(
|
||||
|
||||
this->mem_regions.push_back(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;
|
||||
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;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
@@ -83,18 +90,20 @@ 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.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 = 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;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
|
||||
@@ -118,18 +127,20 @@ 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.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 = 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;
|
||||
|
||||
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 */
|
||||
+6
-35
@@ -31,7 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "memctrlbase.h"
|
||||
#include "memreadwrite.h"
|
||||
#include "memaccess.h"
|
||||
#include "mmiodevice.h"
|
||||
#include "mpc106.h"
|
||||
|
||||
@@ -178,21 +178,7 @@ 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
|
||||
|
||||
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;
|
||||
return read_mem(&this->my_pci_cfg_hdr[reg_offs], size);
|
||||
}
|
||||
|
||||
void MPC106::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
@@ -201,23 +187,8 @@ void MPC106::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
#endif
|
||||
|
||||
// FIXME: implement write-protection for read-only registers
|
||||
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);
|
||||
}
|
||||
|
||||
write_mem(&this->my_pci_cfg_hdr[reg_offs], value, size);
|
||||
|
||||
if (this->my_pci_cfg_hdr[0xF2] & 8) {
|
||||
#ifdef MPC106_DEBUG
|
||||
@@ -271,8 +242,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(ERROR, "MPC106 error: RAM not contiguous! \n");
|
||||
ram_size += bank_end + 1;
|
||||
LOG_F(WARNING, "MPC106: RAM not contiguous! \n");
|
||||
ram_size += bank_end - bank_start + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(execution OBJECT ${SOURCES})
|
||||
target_link_libraries(execution PRIVATE cubeb)
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <interpreter_loop.h>
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
|
||||
std::chrono::high_resolution_clock::time_point global; // global timer
|
||||
std::chrono::high_resolution_clock::time_point cuda_timer; // updates every 11 ms
|
||||
std::chrono::high_resolution_clock::time_point disp_timer; // updates every 16 ms
|
||||
|
||||
using namespace std;
|
||||
|
||||
const uint64_t cuda_update = 11000;
|
||||
const uint64_t display_update = 16667;
|
||||
|
||||
bool cuda_priority = 0;
|
||||
bool disp_priority = 0;
|
||||
|
||||
uint64_t elapsed_times[3] = {0}; // Elapsed time to reach a cycle (for display)
|
||||
uint64_t routine_bench[3] = {0}; // Estimated time (in microseconds) to cycle through functions
|
||||
uint64_t routine_runtime[3] = {0, cuda_update, display_update}; // Time to elapse before execution
|
||||
|
||||
enum general_routine_timepoint { OVERALL_UPDATE_TIME, CUDA_UPDATE_TIME, DISPLAY_UPDATE_TIME };
|
||||
|
||||
void round_robin_bench() {
|
||||
// Benchmark how much time elapses during a minimal CPU block
|
||||
|
||||
std::chrono::high_resolution_clock::time_point dummy = std::chrono::high_resolution_clock::now();
|
||||
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
dppc_interpreter::ppc_ori(); //execute NOPs as a basic test
|
||||
}
|
||||
|
||||
std::chrono::high_resolution_clock::time_point dummy2 = std::chrono::high_resolution_clock::now();
|
||||
routine_bench[OVERALL_UPDATE_TIME] =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(dummy2 - dummy).count();
|
||||
std::cout << "Initial test: " << routine_bench[OVERALL_UPDATE_TIME] << endl;
|
||||
}
|
||||
|
||||
void interpreter_update_counters() {
|
||||
std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now();
|
||||
elapsed_times[OVERALL_UPDATE_TIME] =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(end - global).count();
|
||||
elapsed_times[CUDA_UPDATE_TIME] =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(end - cuda_timer).count();
|
||||
elapsed_times[DISPLAY_UPDATE_TIME] =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(end - disp_timer).count();
|
||||
|
||||
// Calculate if the threshold for updating a time-critical section has reached or is about to be reached
|
||||
if ((elapsed_times[CUDA_UPDATE_TIME] + routine_bench[OVERALL_UPDATE_TIME]) >=
|
||||
routine_runtime[CUDA_UPDATE_TIME]) {
|
||||
cuda_priority = true;
|
||||
elapsed_times[CUDA_UPDATE_TIME] = 0;
|
||||
cuda_timer = end;
|
||||
}
|
||||
|
||||
if ((elapsed_times[DISPLAY_UPDATE_TIME] + routine_bench[OVERALL_UPDATE_TIME]) >=
|
||||
routine_runtime[DISPLAY_UPDATE_TIME]) {
|
||||
disp_priority = true;
|
||||
elapsed_times[DISPLAY_UPDATE_TIME] = 0;
|
||||
disp_timer = end;
|
||||
}
|
||||
}
|
||||
|
||||
void interpreter_main_loop() {
|
||||
// Round robin algorithm goes here
|
||||
round_robin_bench();
|
||||
|
||||
global = std::chrono::high_resolution_clock::now();
|
||||
cuda_timer = global;
|
||||
disp_timer = global;
|
||||
|
||||
for (;;) {
|
||||
if (cuda_priority) {
|
||||
LOG_F(9, "Placeholder for Cuda Update function!\n");
|
||||
cuda_priority = false;
|
||||
}
|
||||
|
||||
if (disp_priority) {
|
||||
LOG_F(9, "Placeholder for Display Update function! \n");
|
||||
disp_priority = false;
|
||||
}
|
||||
|
||||
ppc_exec();
|
||||
|
||||
interpreter_update_counters();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,23 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// The uniquely Gekko opcodes for the processor - ppcgekkoopcodes.cpp
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
void ppc_psq_l() {
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_lu() {
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_st() {
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void ppc_psq_stu() {
|
||||
printf("Hello. There's no GameCube emulation...yet. Goodbye.");
|
||||
exit(0);
|
||||
}
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
void interpreter_update_counters();
|
||||
void interpreter_main_loop();
|
||||
@@ -26,7 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "machinefactory.h"
|
||||
#include "devices/memctrlbase.h"
|
||||
#include "memreadwrite.h"
|
||||
#include "memaccess.h"
|
||||
#include "machineproperties.h"
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
@@ -61,7 +61,6 @@ 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,9 +1,11 @@
|
||||
#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>
|
||||
|
||||
@@ -23,10 +23,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// This is where the magic begins
|
||||
|
||||
#include "debugger/debugger.h"
|
||||
#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>
|
||||
@@ -38,6 +41,21 @@ 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 "
|
||||
@@ -116,7 +134,7 @@ int main(int argc, char** argv) {
|
||||
loguru::init(argc, argv);
|
||||
loguru::add_file("dingusppc.log", loguru::Append, 0);
|
||||
} else {
|
||||
loguru::g_stderr_verbosity = 0;
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
|
||||
loguru::init(argc, argv);
|
||||
}
|
||||
|
||||
@@ -152,10 +170,26 @@ 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());
|
||||
@@ -165,9 +199,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
switch (execution_mode) {
|
||||
case 0:
|
||||
for (;;) {
|
||||
ppc_exec();
|
||||
}
|
||||
interpreter_main_loop();
|
||||
break;
|
||||
case 1:
|
||||
enter_debugger();
|
||||
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
/** @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
@@ -1,102 +0,0 @@
|
||||
/** @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 */
|
||||
+1
Submodule thirdparty/capstone added at bfb2e45d76.
@@ -0,0 +1,6 @@
|
||||
include_directories("${PROJECT_SOURCE_DIR}")
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
|
||||
add_library(utils OBJECT ${SOURCES})
|
||||
target_link_libraries(utils PRIVATE cubeb)
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
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();
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
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 */
|
||||
@@ -0,0 +1,23 @@
|
||||
## 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.
|
||||
@@ -0,0 +1,107 @@
|
||||
# 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