mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
141
Commits
Alpha
...
nuterpreterx
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31ad4b28ed | ||
|
|
eb67b6ded0 | ||
|
|
cbaf0477f0 | ||
|
|
cbd24165bd | ||
|
|
e50a1a4d3e | ||
|
|
ce122da984 | ||
|
|
738b40c7b6 | ||
|
|
2a24b1c8f9 | ||
|
|
f1e6a2ce93 | ||
|
|
11de987ea9 | ||
|
|
804bb3da07 | ||
|
|
832d669890 | ||
|
|
262b7ccf68 | ||
|
|
de61c26484 | ||
|
|
cb39be991f | ||
|
|
55f9d08c30 | ||
|
|
f1a38e21d3 | ||
|
|
90536f79fe | ||
|
|
72308074da | ||
|
|
8c42685e26 | ||
|
|
01ceaef8d7 | ||
|
|
55d7c8f09d | ||
|
|
1f59eceacf | ||
|
|
e14ede2510 | ||
|
|
bc05593dd2 | ||
|
|
b5224ee805 | ||
|
|
3addc05ec4 | ||
|
|
f0cf315030 | ||
|
|
959e92e372 | ||
|
|
5ae9fcbd38 | ||
|
|
e2ed352533 | ||
|
|
4644ade362 | ||
|
|
4a71dbe7bb | ||
|
|
aed250a64d | ||
|
|
e2ad753f4a | ||
|
|
2ab23546ea | ||
|
|
9d9e826bb3 | ||
|
|
3c2887f8c3 | ||
|
|
8cc67b09c2 | ||
|
|
bb3e89e3af | ||
|
|
172dab7431 | ||
|
|
78da2457e8 | ||
|
|
7e70432495 | ||
|
|
c6060ad812 | ||
|
|
f09710a5f7 | ||
|
|
de727db4c6 | ||
|
|
671cd0c5da | ||
|
|
ef62e8b965 | ||
|
|
8c44da655c | ||
|
|
b5850f1cd2 | ||
|
|
0a61970b29 | ||
|
|
91a8e83f21 | ||
|
|
825314c869 | ||
|
|
8d9bc66a82 | ||
|
|
52f4d847dd | ||
|
|
ebf4b0e969 | ||
|
|
47237ff87b | ||
|
|
8d95aa5ed3 | ||
|
|
7ee8b9b2f0 | ||
|
|
1f2256ec81 | ||
|
|
0518f2ae2f | ||
|
|
3bf088f2c8 | ||
|
|
bd16b7c69e | ||
|
|
f5c91968a2 | ||
|
|
4e78ac33c5 | ||
|
|
e1acf5d160 | ||
|
|
047515d813 | ||
|
|
bdbeb742d4 | ||
|
|
e7d8e71297 | ||
|
|
a34e0a4737 | ||
|
|
2c026259b1 | ||
|
|
cd36df5500 | ||
|
|
5ea7b8c5f8 | ||
|
|
372b9cae7a | ||
|
|
595478ed6f | ||
|
|
a2776ddae1 | ||
|
|
f9338b8dd9 | ||
|
|
dee7090071 | ||
|
|
2a8e5538b2 | ||
|
|
20b2fb1bef | ||
|
|
f096eef66d | ||
|
|
899000b647 | ||
|
|
76824fb602 | ||
|
|
02af6da599 | ||
|
|
83afae5625 | ||
|
|
e5510dd9ae | ||
|
|
4d7c520f18 | ||
|
|
6f62f9dd98 | ||
|
|
31d7b056af | ||
|
|
9b49603c72 | ||
|
|
f192d11758 | ||
|
|
ae08c083ea | ||
|
|
dab9334c3a | ||
|
|
7fdfd6109f | ||
|
|
7d6e87a0d3 | ||
|
|
a20ebade09 | ||
|
|
8d6f77ea71 | ||
|
|
19ecc4f945 | ||
|
|
ebc618adea | ||
|
|
38669fd83b | ||
|
|
211f8adc0e | ||
|
|
bda85a66df | ||
|
|
babd8d974f | ||
|
|
9fc5bbb951 | ||
|
|
3fe6e3c09e | ||
|
|
289a14dc7a | ||
|
|
ba9fcd100d | ||
|
|
889dc32a0a | ||
|
|
f13f4e0023 | ||
|
|
4a425c4ecf | ||
|
|
293e869acb | ||
|
|
f3d7cd9dd7 | ||
|
|
fd5498e16b | ||
|
|
55f91c5d3f | ||
|
|
0831182e39 | ||
|
|
26153ca8ea | ||
|
|
7855770ca7 | ||
|
|
a81156c3e3 | ||
|
|
f31c71e430 | ||
|
|
7ba7bff3d5 | ||
|
|
11bb10b44b | ||
|
|
378965cc3d | ||
|
|
40b537767d | ||
|
|
e2e78c0682 | ||
|
|
0267fc82c9 | ||
|
|
c4022f466f | ||
|
|
17cdcc5560 | ||
|
|
5eaff7a8ce | ||
|
|
9d44ac0901 | ||
|
|
606c9dd9a8 | ||
|
|
ec7907ed71 | ||
|
|
d1e20a72e3 | ||
|
|
742662e4fc | ||
|
|
d3096ebaac | ||
|
|
c0e28b81a8 | ||
|
|
ce5edcb0c8 | ||
|
|
a3743f0293 | ||
|
|
92580f3515 | ||
|
|
50018010c7 | ||
|
|
e4294d78bf | ||
|
|
b73f5a157d |
No files matched your search
@@ -1,10 +1,14 @@
|
||||
# Ignore binary files
|
||||
out/
|
||||
vcpkg/
|
||||
*.bin
|
||||
|
||||
# Ignore compiled object files
|
||||
.vs/
|
||||
.vscode/
|
||||
*.o
|
||||
*.out
|
||||
*.obj
|
||||
*.d
|
||||
|
||||
# Ignore CMake system files
|
||||
@@ -16,6 +20,9 @@ CMakeSettings.json
|
||||
*.vcxproj
|
||||
*.vcxproj.filters
|
||||
|
||||
# Ignore Visual Studio auto-save recovery folder
|
||||
enc_temp_folder/
|
||||
|
||||
# Ignore CodeLite configuration files
|
||||
*.workspace
|
||||
*.workspace.*
|
||||
@@ -30,6 +37,7 @@ dingusppc.exe
|
||||
# Ignore system files
|
||||
.DS_Store
|
||||
Thumb.db
|
||||
ehthumbs.db
|
||||
|
||||
# IDE ignores
|
||||
build
|
||||
|
||||
+9
-3
@@ -114,7 +114,8 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
platform_glob(SOURCES "${PROJECT_SOURCE_DIR}/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/*.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/*.h")
|
||||
"${PROJECT_SOURCE_DIR}/*.h"
|
||||
"${PROJECT_SOURCE_DIR}/*.include")
|
||||
|
||||
if (APPLE)
|
||||
platform_glob(APPLE_SOURCES "${PROJECT_SOURCE_DIR}/*.m")
|
||||
@@ -180,9 +181,14 @@ if (DPPC_BUILD_PPC_TESTS)
|
||||
endif()
|
||||
|
||||
if (DPPC_BUILD_BENCHMARKS)
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp")
|
||||
add_compile_options("-DPPC_BENCHMARKS")
|
||||
file(GLOB BENCH_SOURCES "${PROJECT_SOURCE_DIR}/benchmark/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.h"
|
||||
"${PROJECT_SOURCE_DIR}/cpu/ppc/*.include"
|
||||
)
|
||||
add_executable(bench1 ${BENCH_SOURCES} $<TARGET_OBJECTS:core>
|
||||
$<TARGET_OBJECTS:cpu_ppc>
|
||||
# $<TARGET_OBJECTS:cpu_ppc>
|
||||
$<TARGET_OBJECTS:debugger>
|
||||
$<TARGET_OBJECTS:devices>
|
||||
$<TARGET_OBJECTS:machines>
|
||||
|
||||
+11
-2
@@ -8,12 +8,20 @@
|
||||
- joevt
|
||||
- mihaip
|
||||
|
||||
## Building
|
||||
## NT4/PPC fork
|
||||
|
||||
- Wack0
|
||||
|
||||
## DevOps
|
||||
|
||||
- Waqar144
|
||||
- webspacecreations
|
||||
- leap0x7b
|
||||
- sdkmap
|
||||
- dressupgeekout
|
||||
- kth5
|
||||
- dyharlan
|
||||
- roytam1
|
||||
|
||||
## Testing
|
||||
|
||||
@@ -29,6 +37,7 @@
|
||||
- Emaculation
|
||||
- GitHub
|
||||
- PenguinPPC
|
||||
- VirtuallyFun
|
||||
- The makers of Loguru, SDL2, Capstone, and CLI11
|
||||
- The developers of other PowerPC Mac emulators, past and present
|
||||
- All those preserving the software of 68k and PowerPC Macs
|
||||
- All those preserving the software and source code of 68k and PowerPC Macs
|
||||
+76
-31
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,6 +25,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include "cpu/ppc/ppcmmu.h"
|
||||
#include "devices/memctrl/mpc106.h"
|
||||
#include <thirdparty/loguru/loguru.hpp>
|
||||
#include <debugger/debugger.h>
|
||||
|
||||
#if defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
power_on = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t cs_code[] = {
|
||||
0x3863FFFC, 0x7C861671, 0x41820090, 0x70600002, 0x41E2001C, 0xA0030004,
|
||||
@@ -38,9 +45,12 @@ uint32_t cs_code[] = {
|
||||
0x7C650194, 0x4E800020
|
||||
};
|
||||
|
||||
constexpr uint32_t test_size = 0x8000; // 0x7FFFFFFC is the max
|
||||
constexpr uint32_t test_samples = 200;
|
||||
constexpr uint32_t test_iterations = 5;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int i;
|
||||
int i, j;
|
||||
|
||||
/* initialize logging */
|
||||
loguru::g_preamble_date = false;
|
||||
@@ -53,7 +63,7 @@ int main(int argc, char** argv) {
|
||||
MPC106* grackle_obj = new MPC106;
|
||||
|
||||
/* we need some RAM */
|
||||
if (!grackle_obj->add_ram_region(0, 0x9000)) {
|
||||
if (!grackle_obj->add_ram_region(0, 0x1000 + test_size)) {
|
||||
LOG_F(ERROR, "Could not create RAM region");
|
||||
delete(grackle_obj);
|
||||
return -1;
|
||||
@@ -61,51 +71,86 @@ int main(int argc, char** argv) {
|
||||
|
||||
constexpr uint64_t tbr_freq = 16705000;
|
||||
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, tbr_freq);
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, false, tbr_freq);
|
||||
|
||||
/* load executable code into RAM at address 0 */
|
||||
for (i = 0; i < sizeof(cs_code); i++) {
|
||||
mmu_write_vmem<uint32_t>(i*4, cs_code[i]);
|
||||
for (i = 0; i < sizeof(cs_code) / sizeof(cs_code[0]); i++) {
|
||||
mmu_write_vmem<uint32_t>(i * 4, 0, cs_code[i]);
|
||||
}
|
||||
|
||||
srand(0xCAFEBABE);
|
||||
|
||||
for (i = 0; i < 32768; i++) {
|
||||
mmu_write_vmem<uint8_t>(0x1000+i, rand() % 256);
|
||||
LOG_F(INFO, "Test size: 0x%X", test_size);
|
||||
LOG_F(INFO, "First few bytes:");
|
||||
bool did_lf = false;
|
||||
for (i = 0; i < test_size; i++) {
|
||||
uint8_t val = rand() % 256;
|
||||
mmu_write_vmem<uint8_t>(0x1000 + i, 0, val);
|
||||
if (i < 64) {
|
||||
printf("%02x", val);
|
||||
did_lf = false;
|
||||
if (i % 32 == 31) {
|
||||
printf("\n");
|
||||
did_lf = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!did_lf)
|
||||
printf("\n");
|
||||
|
||||
#if 0
|
||||
/* 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_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
enter_debugger();
|
||||
#endif
|
||||
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
power_on = true;
|
||||
ppc_exec_until(0xC4);
|
||||
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
uint32_t checksum = 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]);
|
||||
|
||||
uint64_t overhead = -1;
|
||||
for (j = 0; j < test_samples; j++) {
|
||||
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 (run #%d): %lld ns", i, time_elapsed.count());
|
||||
if (time_elapsed.count() < overhead)
|
||||
overhead = time_elapsed.count();
|
||||
}
|
||||
LOG_F(INFO, "Overhead Time: %lld ns", overhead);
|
||||
|
||||
for (int theproc = 0; theproc < 2; theproc++) {
|
||||
LOG_F(INFO, "Doing %s", theproc ? "ppc_exec_until" : "ppc_exec");
|
||||
for (i = 0; i < test_iterations; i++) {
|
||||
uint64_t best_sample = -1;
|
||||
for (j = 0; j < test_samples; j++) {
|
||||
ppc_state.pc = 0;
|
||||
ppc_state.gpr[3] = 0x1000; // buf
|
||||
ppc_state.gpr[4] = test_size; // len
|
||||
ppc_state.gpr[5] = 0; // sum
|
||||
power_on = true;
|
||||
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
(theproc) ? ppc_exec_until(0xC4) : ppc_exec();
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto time_elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
|
||||
if (time_elapsed.count() < best_sample)
|
||||
best_sample = time_elapsed.count();
|
||||
}
|
||||
if (ppc_state.gpr[3] != checksum)
|
||||
LOG_F(INFO, "Checksum: 0x%08X", ppc_state.gpr[3]);
|
||||
best_sample -= overhead;
|
||||
LOG_F(INFO, "(%d) %lld ns, %.4lf MiB/s", i+1, best_sample, 1E9 * test_size / (best_sample * 1024 * 1024));
|
||||
}
|
||||
}
|
||||
|
||||
delete(grackle_obj);
|
||||
|
||||
@@ -116,7 +116,6 @@ private:
|
||||
uint64_t unhandled_events = 0;
|
||||
uint64_t key_downs = 0;
|
||||
uint64_t key_ups = 0;
|
||||
uint64_t mouse_motions = 0;
|
||||
uint8_t buttons_state = 0;
|
||||
};
|
||||
|
||||
|
||||
+12
-2
@@ -41,7 +41,7 @@ void EventManager::poll_events()
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
power_on = false;
|
||||
power_off_reason = po_shut_down;
|
||||
power_off_reason = po_quit;
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT: {
|
||||
@@ -56,7 +56,7 @@ void EventManager::poll_events()
|
||||
case SDL_KEYUP: {
|
||||
// Internal shortcuts to trigger mouse grab, intentionally not
|
||||
// sent to the host.
|
||||
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() == KMOD_LCTRL) {
|
||||
if (event.key.keysym.sym == SDLK_g && SDL_GetModState() & KMOD_LCTRL) {
|
||||
if (event.type == SDL_KEYUP) {
|
||||
toggle_mouse_grab(event.key);
|
||||
}
|
||||
@@ -304,6 +304,16 @@ static int get_sdl_event_key_code(const SDL_KeyboardEvent &event)
|
||||
case 0XE8: return AdbKey_6; // E-grave
|
||||
case 0XEC: return AdbKey_LeftBracket; // I-grave
|
||||
case 0XF2: return AdbKey_KeypadMultiply; // O-grave
|
||||
|
||||
// Spanish keyboard
|
||||
case 0XA1: return AdbKey_Comma; // Inverted question mark
|
||||
case 0XBA: return AdbKey_6; // Backslash
|
||||
case 0XE7: return AdbKey_Slash; // C-cedilla
|
||||
case 0XF1: return AdbKey_Semicolon; // N-tilde
|
||||
case 0X4000002f:
|
||||
return AdbKey_LeftBracket; // Acute
|
||||
case 0X40000034:
|
||||
return AdbKey_Semicolon; // Acute
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
+5
-5
@@ -33,11 +33,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define NS_PER_SEC 1E9
|
||||
#define USEC_PER_SEC 1E6
|
||||
#define NS_PER_USEC 1000UL
|
||||
#define NS_PER_MSEC 1E6
|
||||
#define ONE_BILLION_NS 0x3B9ACA00UL
|
||||
#define NS_PER_SEC 1000000000
|
||||
#define USEC_PER_SEC 1000000
|
||||
#define NS_PER_USEC 1000
|
||||
#define NS_PER_MSEC 1000000
|
||||
#define ONE_BILLION_NS 1000000000
|
||||
|
||||
#define USECS_TO_NSECS(us) (us) * NS_PER_USEC
|
||||
#define MSECS_TO_NSECS(ms) (ms) * NS_PER_MSEC
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers
|
||||
// such as names of functions and macros.
|
||||
// For more information see https://go.microsoft.com/fwlink/?linkid=865984
|
||||
#define OPCODEREC(op, __VA_ARGS__) template <field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODESHIFT(op, __VA_ARGS__) template <field_shift shift> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODEOVREC(op, __VA_ARGS__) template <field_rc rec, field_ov ov> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODE(op, __VA_ARGS__) void dppc_interpreter::ppc_##op(uint32_t instr) {##__VA_ARGS__ }
|
||||
#define OPCODECARRY(op, __VA_ARGS__) template <field_carry carry, field_rc rec, field_ov ov> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define POWEROPCODEREC(op, __VA_ARGS__) template <field_rc rec> void dppc_interpreter::power_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define POWEROPCODEOVREC(op, __VA_ARGS__) template <field_rc rec, field_ov ov> void dppc_interpreter::power_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODELOGIC(op, __VA_ARGS__) template <logical_fun logical_op, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODELKAA(op, __VA_ARGS__) template <field_lk l, field_aa a> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODE601L(op, __VA_ARGS__) template <field_lk l, field_601 for601, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define POWEROPCODE(op, __VA_ARGS__) void dppc_interpreter::power_##op(uint32_t instr) {##__VA_ARGS__ }
|
||||
#define OPCODEMEM(op, __VA_ARGS__) template <class T> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODESHIFTREC(op, __VA_ARGS__) template <field_direction isleft, field_rc rec > void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODE601REC(op, __VA_ARGS__) template <field_601 for601, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define OPCODEEXTSIGN(op, __VA_ARGS__) template <class T, field_rc rec> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ }
|
||||
#define ppc_store_iresult_reg(reg, ppc_result) ppc_state.gpr[reg] = ppc_result
|
||||
#define ppc_set_xer(entry) ppc_state.spr[SPR::XER] |= entry#define OPCODEL(op, __VA_ARGS__) template <field_lk l> void dppc_interpreter::ppc_##op(uint32_t instr) { __VA_ARGS__ } template void dppc_interpreter::ppc_##op<LK0>(uint32_t instr); template void dppc_interpreter::ppc_##op<LK1>(uint32_t instr);
|
||||
#define OPCODEL(op, __VA_ARGS__) template <field_lk l> void dppc_interpreter::ppc_##op(uint32_t instr)
|
||||
@@ -3,6 +3,7 @@ include_directories("${PROJECT_SOURCE_DIR}"
|
||||
|
||||
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/*.include"
|
||||
)
|
||||
|
||||
add_library(cpu_ppc OBJECT ${SOURCES})
|
||||
+3
-635
@@ -23,7 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// Any shared opcodes are in ppcopcodes.cpp
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "ppcdecodemacros.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -34,637 +34,5 @@ static inline uint32_t power_rot_mask(unsigned rot_mb, unsigned rot_me) {
|
||||
return ((rot_mb <= rot_me) ? m2 & m1 : m1 | m2);
|
||||
}
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_abs() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_result_d = (int32_t(ppc_result_a) < 0) ? -ppc_result_a : ppc_result_a;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_abs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_abs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_abs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_abs<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_clcs() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_da(ppc_cur_instruction);
|
||||
switch (reg_a) {
|
||||
case 12: //instruction cache line size
|
||||
case 13: //data cache line size
|
||||
case 14: //minimum line size
|
||||
case 15: //maximum line size
|
||||
default: ppc_result_d = is_601 ? 64 : 32; break;
|
||||
case 7:
|
||||
case 23: ppc_result_d = is_601 ? 64 : 0; break;
|
||||
case 8:
|
||||
case 9:
|
||||
case 24:
|
||||
case 25: ppc_result_d = is_601 ? 64 : 4; break;
|
||||
case 10:
|
||||
case 11:
|
||||
case 26:
|
||||
case 27: ppc_result_d = is_601 ? 64 : 0x4000; break;
|
||||
}
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_div() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
|
||||
int64_t dividend = (uint64_t(ppc_result_a) << 32) | ppc_state.spr[SPR::MQ];
|
||||
int32_t divisor = ppc_result_b;
|
||||
int64_t quotient;
|
||||
int32_t remainder;
|
||||
|
||||
if (dividend == -0x80000000 && divisor == -1) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else if (!divisor) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
quotient = dividend / divisor;
|
||||
remainder = dividend % divisor;
|
||||
ppc_result_d = uint32_t(quotient);
|
||||
if (ov) {
|
||||
if (((quotient >> 31) + 1) & ~1) {
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_state.spr[SPR::MQ] = remainder;
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_div<RC0, OV0>();
|
||||
template void dppc_interpreter::power_div<RC0, OV1>();
|
||||
template void dppc_interpreter::power_div<RC1, OV0>();
|
||||
template void dppc_interpreter::power_div<RC1, OV1>();
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_divs() {
|
||||
uint32_t ppc_result_d;
|
||||
int32_t remainder;
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
|
||||
if (!ppc_result_b) { // handle the "anything / 0" case
|
||||
ppc_result_d = -1;
|
||||
remainder = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else if (ppc_result_a == 0x80000000U && ppc_result_b == 0xFFFFFFFFU) {
|
||||
ppc_result_d = 0x80000000U;
|
||||
remainder = 0;
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else { // normal signed devision
|
||||
ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b);
|
||||
remainder = (int32_t(ppc_result_a) % int32_t(ppc_result_b));
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
ppc_state.spr[SPR::MQ] = remainder;
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_divs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_divs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_divs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_divs<RC1, OV1>();
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_doz() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
|
||||
ppc_result_b - ppc_result_a : 0;
|
||||
|
||||
if (ov) {
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_doz<RC0, OV0>();
|
||||
template void dppc_interpreter::power_doz<RC0, OV1>();
|
||||
template void dppc_interpreter::power_doz<RC1, OV0>();
|
||||
template void dppc_interpreter::power_doz<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_dozi() {
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdasimm(ppc_cur_instruction);
|
||||
if (((int32_t)ppc_result_a) > simm) {
|
||||
ppc_result_d = 0;
|
||||
} else {
|
||||
ppc_result_d = simm - ppc_result_a;
|
||||
}
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_lscbx() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
ppc_effective_address = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
||||
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
|
||||
uint32_t bytes_remaining = bytes_to_load;
|
||||
uint8_t matching_byte = (uint8_t)(ppc_state.spr[SPR::XER] >> 8);
|
||||
uint32_t ppc_result_d = 0;
|
||||
bool is_match = false;
|
||||
|
||||
// for storing each byte
|
||||
uint8_t shift_amount = 24;
|
||||
|
||||
while (bytes_remaining > 0) {
|
||||
uint8_t return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
|
||||
ppc_result_d |= return_value << shift_amount;
|
||||
if (!shift_amount) {
|
||||
if (reg_d != reg_a && reg_d != reg_b)
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
reg_d = (reg_d + 1) & 0x1F;
|
||||
ppc_result_d = 0;
|
||||
shift_amount = 24;
|
||||
} else {
|
||||
shift_amount -= 8;
|
||||
}
|
||||
|
||||
ppc_effective_address++;
|
||||
bytes_remaining--;
|
||||
|
||||
if (return_value == matching_byte) {
|
||||
is_match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// store partially loaded register if any
|
||||
if (shift_amount != 24 && reg_d != reg_a && reg_d != reg_b)
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | (bytes_to_load - bytes_remaining);
|
||||
|
||||
if (rec) {
|
||||
ppc_state.cr =
|
||||
(ppc_state.cr & 0x0FFFFFFFUL) |
|
||||
(is_match ? CRx_bit::CR_EQ : 0) |
|
||||
((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
|
||||
}
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_lscbx<RC0>();
|
||||
template void dppc_interpreter::power_lscbx<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_maskg() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
uint32_t mask_start = ppc_result_d & 0x1F;
|
||||
uint32_t mask_end = ppc_result_b & 0x1F;
|
||||
uint32_t insert_mask = 0;
|
||||
|
||||
if (mask_start < (mask_end + 1)) {
|
||||
insert_mask = power_rot_mask(mask_start, mask_end);
|
||||
}
|
||||
else if (mask_start == (mask_end + 1)) {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
}
|
||||
else {
|
||||
insert_mask = ~(power_rot_mask(mask_end + 1, mask_start - 1));
|
||||
}
|
||||
|
||||
ppc_result_a = insert_mask;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskg<RC0>();
|
||||
template void dppc_interpreter::power_maskg<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_maskir() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_maskir<RC0>();
|
||||
template void dppc_interpreter::power_maskir<RC1>();
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_mul() {
|
||||
ppc_grab_regsdab(ppc_cur_instruction);
|
||||
int64_t product = int64_t(int32_t(ppc_result_a)) * int32_t(ppc_result_b);
|
||||
uint32_t ppc_result_d = uint32_t(uint64_t(product) >> 32);
|
||||
ppc_state.spr[SPR::MQ] = uint32_t(product);
|
||||
|
||||
if (ov) {
|
||||
if (uint64_t(product >> 31) + 1 & ~1) {
|
||||
ppc_state.spr[SPR::XER] |= XER::SO | XER::OV;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(uint32_t(product));
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_mul<RC0, OV0>();
|
||||
template void dppc_interpreter::power_mul<RC0, OV1>();
|
||||
template void dppc_interpreter::power_mul<RC1, OV0>();
|
||||
template void dppc_interpreter::power_mul<RC1, OV1>();
|
||||
|
||||
template <field_rc rec, field_ov ov>
|
||||
void dppc_interpreter::power_nabs() {
|
||||
ppc_grab_regsda(ppc_cur_instruction);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
|
||||
|
||||
if (ov)
|
||||
ppc_state.spr[SPR::XER] &= ~XER::OV;
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_store_iresult_reg(reg_d, ppc_result_d);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_nabs<RC0, OV0>();
|
||||
template void dppc_interpreter::power_nabs<RC0, OV1>();
|
||||
template void dppc_interpreter::power_nabs<RC1, OV0>();
|
||||
template void dppc_interpreter::power_nabs<RC1, OV1>();
|
||||
|
||||
void dppc_interpreter::power_rlmi() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_mb = (ppc_cur_instruction >> 6) & 0x1F;
|
||||
unsigned rot_me = (ppc_cur_instruction >> 1) & 0x1F;
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(rot_mb, rot_me);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
|
||||
|
||||
if ((ppc_cur_instruction & 0x01) == 1)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_rrib() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_result_a |= (0x80000000U >> rot_sh);
|
||||
} else {
|
||||
ppc_result_a &= ~(0x80000000U >> rot_sh);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_rrib<RC0>();
|
||||
template void dppc_interpreter::power_rrib<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sle() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sle<RC0>();
|
||||
template void dppc_interpreter::power_sle<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sleq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sleq<RC0>();
|
||||
template void dppc_interpreter::power_sleq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sliq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sliq<RC0>();
|
||||
template void dppc_interpreter::power_sliq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_slliq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slliq<RC0>();
|
||||
template void dppc_interpreter::power_slliq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sllq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = ppc_state.spr[SPR::MQ] & (-1U << rot_sh);
|
||||
} else {
|
||||
ppc_result_a = ((ppc_result_d << rot_sh) | (ppc_state.spr[SPR::MQ] & ((1 << rot_sh) - 1)));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sllq<RC0>();
|
||||
template void dppc_interpreter::power_sllq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_slq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_slq<RC0>();
|
||||
template void dppc_interpreter::power_slq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sraiq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraiq<RC0>();
|
||||
template void dppc_interpreter::power_sraiq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sraq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sraq<RC0>();
|
||||
template void dppc_interpreter::power_sraq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sre() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sre<RC0>();
|
||||
template void dppc_interpreter::power_sre<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srea() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
uint32_t r = ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh)));
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srea<RC0>();
|
||||
template void dppc_interpreter::power_srea<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sreq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sreq<RC0>();
|
||||
template void dppc_interpreter::power_sreq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_sriq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_sriq<RC0>();
|
||||
template void dppc_interpreter::power_sriq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srliq() {
|
||||
ppc_grab_regssash(ppc_cur_instruction);
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srliq<RC0>();
|
||||
template void dppc_interpreter::power_srliq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srlq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
} else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srlq<RC0>();
|
||||
template void dppc_interpreter::power_srlq<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::power_srq() {
|
||||
ppc_grab_regssab(ppc_cur_instruction);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_store_iresult_reg(reg_a, ppc_result_a);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::power_srq<RC0>();
|
||||
template void dppc_interpreter::power_srq<RC1>();
|
||||
#include "ppcopmacros.h"
|
||||
#include "poweropcodes.include"
|
||||
@@ -0,0 +1,531 @@
|
||||
POWEROPCODEOVREC (abs, 31, 360,
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsda(instr);
|
||||
if (ppc_result_a == 0x80000000) {
|
||||
ppc_result_d = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_result_d = (int32_t(ppc_result_a) < 0) ? -ppc_result_a : ppc_result_a;
|
||||
if (ov)
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODE31 (clcs, 31, 531,
|
||||
ppc_grab_da(instr);
|
||||
uint32_t ppc_result_d = 0;
|
||||
|
||||
switch (reg_a) {
|
||||
case 12: //instruction cache line size
|
||||
case 13: //data cache line size
|
||||
case 14: //minimum line size
|
||||
case 15: //maximum line size
|
||||
default:
|
||||
ppc_result_d = is_601 ? 64 : 32; break;
|
||||
case 7:
|
||||
case 23:
|
||||
ppc_result_d = is_601 ? 64 : 0; break;
|
||||
case 8:
|
||||
case 9:
|
||||
case 24:
|
||||
case 25:
|
||||
ppc_result_d = is_601 ? 64 : 4; break;
|
||||
case 10:
|
||||
case 11:
|
||||
case 26:
|
||||
case 27:
|
||||
ppc_result_d = is_601 ? 64 : 0x4000; break;
|
||||
}
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (div, 31, 331,
|
||||
uint32_t ppc_result_d;
|
||||
ppc_grab_regsdab(instr);
|
||||
|
||||
int64_t dividend = (uint64_t(ppc_result_a) << 32) | ppc_state.spr[SPR::MQ];
|
||||
int32_t divisor = ppc_result_b;
|
||||
int64_t quotient;
|
||||
int32_t remainder;
|
||||
|
||||
if (dividend == -0x80000000 && divisor == -1) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else if (!divisor) {
|
||||
remainder = 0;
|
||||
ppc_result_d = 0x80000000U; // -2^31 aka INT32_MIN
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
quotient = dividend / divisor;
|
||||
remainder = dividend % divisor;
|
||||
ppc_result_d = uint32_t(quotient);
|
||||
if (ov) {
|
||||
if (((quotient >> 31) + 1) & ~1) {
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
power_store_mq(remainder);
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (divs, 31, 363,
|
||||
uint32_t ppc_result_d;
|
||||
int32_t remainder;
|
||||
ppc_grab_regsdab(instr);
|
||||
|
||||
if (!ppc_result_b) { // handle the "anything / 0" case
|
||||
ppc_result_d = -1;
|
||||
remainder = ppc_result_a;
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else if (ppc_result_a == 0x80000000U && ppc_result_b == 0xFFFFFFFFU) {
|
||||
ppc_result_d = 0x80000000U;
|
||||
remainder = 0;
|
||||
if (ov)
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else { // normal signed devision
|
||||
ppc_result_d = int32_t(ppc_result_a) / int32_t(ppc_result_b);
|
||||
remainder = (int32_t(ppc_result_a) % int32_t(ppc_result_b));
|
||||
if (ov)
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(remainder);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
power_store_mq(remainder);;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (doz, 31, 264,
|
||||
ppc_grab_regsdab(instr);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < int32_t(ppc_result_b)) ?
|
||||
ppc_result_b - ppc_result_a : 0;
|
||||
|
||||
if (ov) {
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODE (dozi, , 9,
|
||||
ppc_grab_regsdasimm(instr);
|
||||
uint32_t ppc_result_d = 0;
|
||||
if (((int32_t)ppc_result_a) > simm) {
|
||||
ppc_result_d = 0;
|
||||
}
|
||||
else {
|
||||
ppc_result_d = simm - ppc_result_a;
|
||||
}
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (lscbx, 31, 277,
|
||||
ppc_grab_regsdab(instr);
|
||||
uint32_t ea = ppc_result_b + (reg_a ? ppc_result_a : 0);
|
||||
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7F);
|
||||
uint32_t bytes_remaining = bytes_to_load;
|
||||
uint8_t matching_byte = (uint8_t)(ppc_state.spr[SPR::XER] >> 8);
|
||||
uint32_t ppc_result_d = 0;
|
||||
bool is_match = false;
|
||||
|
||||
// for storing each byte
|
||||
uint8_t shift_amount = 24;
|
||||
|
||||
while (bytes_remaining > 0) {
|
||||
uint8_t return_value = mmu_read_vmem<uint8_t>(ea, instr);
|
||||
|
||||
ppc_result_d |= return_value << shift_amount;
|
||||
if (!shift_amount) {
|
||||
if (reg_d != reg_a && reg_d != reg_b) {
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
}
|
||||
reg_d = (reg_d + 1) & 0x1F;
|
||||
ppc_result_d = 0;
|
||||
shift_amount = 24;
|
||||
} else {
|
||||
shift_amount -= 8;
|
||||
}
|
||||
|
||||
ea++;
|
||||
bytes_remaining--;
|
||||
|
||||
if (return_value == matching_byte) {
|
||||
is_match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// store partially loaded register if any
|
||||
if (shift_amount != 24 && reg_d != reg_a && reg_d != reg_b) {
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & ~0x7F) | (bytes_to_load - bytes_remaining);
|
||||
|
||||
if (rec) { \
|
||||
ppc_state.cr = \
|
||||
(ppc_state.cr & 0x0FFFFFFFUL) | \
|
||||
(is_match ? CRx_bit::CR_EQ : 0) | \
|
||||
((ppc_state.spr[SPR::XER] & XER::SO) >> 3);
|
||||
}
|
||||
)
|
||||
|
||||
POWEROPCODEREC (maskg, 31, 29,
|
||||
ppc_grab_regssab(instr);
|
||||
uint32_t mask_start = ppc_result_d & 0x1F;
|
||||
uint32_t mask_end = ppc_result_b & 0x1F;
|
||||
uint32_t insert_mask = 0;
|
||||
|
||||
if (mask_start < (mask_end + 1)) {
|
||||
insert_mask = power_rot_mask(mask_start, mask_end);
|
||||
}
|
||||
else if (mask_start == (mask_end + 1)) {
|
||||
insert_mask = 0xFFFFFFFF;
|
||||
}
|
||||
else {
|
||||
insert_mask = ~(power_rot_mask(mask_end + 1, mask_start - 1));
|
||||
}
|
||||
|
||||
ppc_result_a = insert_mask;
|
||||
|
||||
if (rec){
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
}
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (maskir, 31, 541,
|
||||
ppc_grab_regssab(instr);
|
||||
ppc_result_a = (ppc_result_a & ~ppc_result_b) | (ppc_result_d & ppc_result_b);
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (mul, 31, 107,
|
||||
ppc_grab_regsdab(instr);
|
||||
int64_t product = int64_t(int32_t(ppc_result_a)) * int32_t(ppc_result_b);
|
||||
uint32_t ppc_result_d = uint32_t(uint64_t(product) >> 32);
|
||||
ppc_state.spr[SPR::MQ] = uint32_t(product);
|
||||
|
||||
if (ov) {
|
||||
if (uint64_t(product >> 31) + 1 & ~1) {
|
||||
ppc_set_xer(XER::SO | XER::OV);
|
||||
} else {
|
||||
ppc_unset_xer(XER::OV);
|
||||
}
|
||||
}
|
||||
if (rec)
|
||||
ppc_changecrf0(uint32_t(product));
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODEOVREC (nabs, 31, 488,
|
||||
ppc_grab_regsda(instr);
|
||||
uint32_t ppc_result_d = (int32_t(ppc_result_a) < 0) ? ppc_result_a : -ppc_result_a;
|
||||
|
||||
if (ov)
|
||||
ppc_unset_xer(XER::OV);
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_d);
|
||||
|
||||
ppc_state.gpr[reg_d] = ppc_result_d;
|
||||
)
|
||||
|
||||
POWEROPCODE (rlmi, , 22,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_mb = (instr >> 6) & 0x1F;
|
||||
unsigned rot_me = (instr >> 1) & 0x1F;
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(rot_mb, rot_me);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_result_a & ~mask));
|
||||
|
||||
if ((instr & 0x01) == 1)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (rrib, 31, 537,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (int32_t(ppc_result_d) < 0) {
|
||||
ppc_result_a |= (0x80000000U >> rot_sh);
|
||||
} else {
|
||||
ppc_result_a &= ~(0x80000000U >> rot_sh);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sle, 31, 153,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sleq, 31, 217,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sliq, 31, 184,
|
||||
ppc_grab_regssash(instr);
|
||||
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (slliq, 31, 248,
|
||||
ppc_grab_regssash(instr);
|
||||
uint32_t r = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
uint32_t mask = power_rot_mask(0, 31 - rot_sh);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sllq, 31, 216,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = ppc_state.spr[SPR::MQ] & (-1U << rot_sh);
|
||||
} else {
|
||||
ppc_result_a = ((ppc_result_d << rot_sh) | (ppc_state.spr[SPR::MQ] & ((1 << rot_sh) - 1)));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (slq, 31, 152,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d << rot_sh;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sraiq, 31, 952,
|
||||
ppc_grab_regssash(instr);
|
||||
uint32_t mask = (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sraq, 31, 920,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = (ppc_result_b & 0x20) ? -1 : (1 << rot_sh) - 1;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> ((ppc_result_b & 0x20) ? 31 : rot_sh);
|
||||
ppc_state.spr[SPR::MQ] = ((ppc_result_d << rot_sh) | (ppc_result_d >> (32 - rot_sh)));
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (ppc_result_d & mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sre, 31, 665,
|
||||
ppc_grab_regssab(instr);
|
||||
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srea, 31, 921,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
ppc_result_a = (int32_t)ppc_result_d >> rot_sh;
|
||||
uint32_t r = ((ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh)));
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
if ((int32_t(ppc_result_d) < 0) && (r & ~mask)) {
|
||||
ppc_state.spr[SPR::XER] |= XER::CA;
|
||||
} else {
|
||||
ppc_state.spr[SPR::XER] &= ~XER::CA;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sreq, 31, 729,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t mask = -1U >> rot_sh;
|
||||
|
||||
ppc_result_a = (ppc_result_d >> rot_sh) | (ppc_state.spr[SPR::MQ] & ~mask);
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (sriq, 31, 696,
|
||||
ppc_grab_regssash(instr);
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srliq, 31, 760,
|
||||
ppc_grab_regssash(instr);
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
ppc_state.spr[SPR::MQ] = r;
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srlq, 31, 728,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
uint32_t r = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
unsigned mask = power_rot_mask(rot_sh, 31);
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = (ppc_state.spr[SPR::MQ] & mask);
|
||||
} else {
|
||||
ppc_result_a = ((r & mask) | (ppc_state.spr[SPR::MQ] & ~mask));
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
|
||||
POWEROPCODEREC (srq, 31, 664,
|
||||
ppc_grab_regssab(instr);
|
||||
unsigned rot_sh = ppc_result_b & 0x1F;
|
||||
|
||||
if (ppc_result_b & 0x20) {
|
||||
ppc_result_a = 0;
|
||||
} else {
|
||||
ppc_result_a = ppc_result_d >> rot_sh;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::MQ] = (ppc_result_d >> rot_sh) | (ppc_result_d << (32 - rot_sh));
|
||||
|
||||
if (rec)
|
||||
ppc_changecrf0(ppc_result_a);
|
||||
|
||||
ppc_state.gpr[reg_a] = ppc_result_a;
|
||||
)
|
||||
@@ -23,6 +23,29 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define PPC_MACROS_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include "ppcemu.h"
|
||||
|
||||
|
||||
#define ppc_set_cr(entry) \
|
||||
ppc_state.cr |= entry
|
||||
|
||||
#define ppc_unset_cr(entry) \
|
||||
ppc_state.cr &= ~entry
|
||||
|
||||
#define ppc_set_xer(entry) \
|
||||
ppc_state.spr[SPR::XER] |= entry
|
||||
|
||||
#define ppc_unset_xer(entry) \
|
||||
ppc_state.spr[SPR::XER] &= ~entry
|
||||
|
||||
#define power_store_mq(entry) \
|
||||
ppc_state.spr[SPR::MQ] = entry
|
||||
|
||||
#define power_store_ctr(entry) \
|
||||
ppc_state.spr[SPR::CTR] = entry
|
||||
|
||||
#define power_store_mq(entry) \
|
||||
ppc_state.spr[SPR::MQ] = entry
|
||||
|
||||
#define ppc_grab_regsdasimm(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
@@ -54,6 +77,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
uint32_t uimm = uint16_t(opcode); \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_crfds(opcode) \
|
||||
int crf_d = (instr >> 21) & 0x1C; \
|
||||
int crf_s = (instr >> 16) & 0x1C;
|
||||
|
||||
#define ppc_grab_da(opcode)\
|
||||
int reg_d = (opcode >> 21) & 31;\
|
||||
int reg_a = (opcode >> 16) & 31;\
|
||||
@@ -80,7 +107,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssab_stswx(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsab(opcode) \
|
||||
int reg_a = (opcode >> 16) & 31;\
|
||||
@@ -88,12 +122,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];\
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regssa(opcode) \
|
||||
#define ppc_grab_regssa(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssa_stmw(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssash(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
@@ -101,44 +140,48 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssash_stswi(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_a = (opcode >> 16) & 31; \
|
||||
int rot_sh = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
#define ppc_grab_regssb(opcode) \
|
||||
int reg_s = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_d = ppc_state.gpr[reg_s]; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b]; \
|
||||
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_grab_regsda(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_a = (opcode >> 16) & 31; \
|
||||
uint32_t ppc_result_a = ppc_state.gpr[reg_a];
|
||||
|
||||
|
||||
#define ppc_grab_regsdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
uint32_t reg_b = (opcode >> 11) & 31; \
|
||||
uint32_t ppc_result_b = ppc_state.gpr[reg_b];
|
||||
|
||||
#define ppc_store_iresult_reg(reg, ppc_result)\
|
||||
ppc_state.gpr[reg] = ppc_result;
|
||||
#define ppc_store_iresult_reg(reg, ppc_result) \
|
||||
ppc_state.gpr[reg] = ppc_result
|
||||
|
||||
#define ppc_store_sfpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d;
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
|
||||
|
||||
#define ppc_store_sfpresult_flt(reg, ppc_dblresult64_d)\
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d;
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
|
||||
|
||||
#define ppc_store_dfpresult_int(reg, ppc_result64_d)\
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d;
|
||||
ppc_state.fpr[(reg)].int64_r = ppc_result64_d
|
||||
|
||||
#define ppc_store_dfpresult_flt(reg, ppc_dblresult64_d)\
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d;
|
||||
ppc_state.fpr[(reg)].dbl64_r = ppc_dblresult64_d
|
||||
|
||||
#define ppc_grab_regsfpdb(opcode) \
|
||||
int reg_d = (opcode >> 21) & 31; \
|
||||
int reg_b = (opcode >> 11) & 31;
|
||||
|
||||
#define GET_FPR(reg) \
|
||||
#define GET_FPR(reg) \
|
||||
ppc_state.fpr[(reg)].dbl64_r
|
||||
|
||||
#define ppc_grab_regsfpdiab(opcode) \
|
||||
@@ -195,4 +238,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
double val_reg_b = GET_FPR(reg_b); \
|
||||
double val_reg_c = GET_FPR(reg_c);
|
||||
|
||||
#define ppc_grab_mtfsf(opcode) \
|
||||
int reg_b = (opcode >> 11) & 0x1F; \
|
||||
uint8_t fm = (opcode >> 17) & 0xFF;
|
||||
|
||||
#define ppc_grab_mtfsfi(opcode) \
|
||||
int crf_d = (opcode >> 21) & 0x1C; \
|
||||
uint32_t imm = (opcode << 16) & 0xF0000000UL;
|
||||
|
||||
#define ppc_grab_crfd(opcode) \
|
||||
int crf_d = (opcode >> 21) & 0x1C;
|
||||
|
||||
#endif // PPC_MACROS_H
|
||||
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define _CRT_SECURE_NO_WARNINGS /* shut up MSVC regarding the unsafe strcpy/strcat */
|
||||
|
||||
#include "ppcdisasm.h"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <functional> /* without this, MSVC doesn't understand std::function */
|
||||
#include <iostream>
|
||||
|
||||
+19
-229
@@ -47,7 +47,7 @@ enum EXEC_MODE:uint32_t {
|
||||
|
||||
enum endian_switch { big_end = 0, little_end = 1 };
|
||||
|
||||
typedef void (*PPCOpcode)(void);
|
||||
typedef void (*PPCOpcode)(uint32_t);
|
||||
|
||||
union FPR_storage {
|
||||
double dbl64_r; // double floating-point representation
|
||||
@@ -303,15 +303,15 @@ extern unsigned exec_flags;
|
||||
|
||||
extern jmp_buf exc_env;
|
||||
|
||||
extern bool grab_return;
|
||||
|
||||
enum Po_Cause : int {
|
||||
po_none,
|
||||
po_starting_up,
|
||||
po_quit,
|
||||
po_quitting,
|
||||
po_shut_down,
|
||||
po_shutting_down,
|
||||
po_restarting,
|
||||
po_restart,
|
||||
po_restarting,
|
||||
po_disassemble_on,
|
||||
po_disassemble_off,
|
||||
po_enter_debugger,
|
||||
@@ -328,13 +328,10 @@ extern bool is_601; // For PowerPC 601 Emulation
|
||||
extern bool is_altivec; // For Altivec Emulation
|
||||
extern bool is_64bit; // For PowerPC G5 Emulation
|
||||
|
||||
// Important Addressing Integers
|
||||
extern uint32_t ppc_cur_instruction;
|
||||
extern uint32_t ppc_effective_address;
|
||||
extern uint32_t ppc_next_instruction_address;
|
||||
|
||||
inline void ppc_set_cur_instruction(const uint8_t* ptr) {
|
||||
ppc_cur_instruction = READ_DWORD_BE_A(ptr);
|
||||
inline uint32_t ppc_set_cur_instruction(const uint8_t* ptr) {
|
||||
return READ_DWORD_BE_A(ptr);
|
||||
}
|
||||
|
||||
// Profiling Stats
|
||||
@@ -402,19 +399,11 @@ typedef enum {
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq);
|
||||
extern void ppc_mmu_init();
|
||||
|
||||
void ppc_illegalop();
|
||||
void ppc_illegalop(uint32_t null_val=0);
|
||||
void ppc_fpu_off();
|
||||
void ppc_assert_int();
|
||||
void ppc_release_int();
|
||||
|
||||
//void ppc_opcode4();
|
||||
void ppc_opcode16();
|
||||
void ppc_opcode18();
|
||||
template <field_601 for601> void ppc_opcode19();
|
||||
void ppc_opcode31();
|
||||
void ppc_opcode59();
|
||||
void ppc_opcode63();
|
||||
|
||||
void initialize_ppc_opcode_tables(bool include_601);
|
||||
|
||||
extern double fp_return_double(uint32_t reg);
|
||||
@@ -427,8 +416,8 @@ void update_fpscr(uint32_t new_fpscr);
|
||||
/* Exception handlers. */
|
||||
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);
|
||||
void ppc_floating_point_exception();
|
||||
void ppc_alignment_exception(uint32_t ea);
|
||||
void ppc_floating_point_exception(uint32_t instr);
|
||||
void ppc_alignment_exception(uint32_t ea, uint32_t instr);
|
||||
|
||||
// MEMORY DECLARATIONS
|
||||
extern MemCtrlBase* mem_ctrl_instance;
|
||||
@@ -436,217 +425,9 @@ extern MemCtrlBase* mem_ctrl_instance;
|
||||
extern void add_ctx_sync_action(const std::function<void()> &);
|
||||
extern void do_ctx_sync(void);
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
|
||||
namespace dppc_interpreter {
|
||||
template <field_lk l, field_601 for601> extern void ppc_bcctr();
|
||||
template <field_lk l> extern void ppc_bclr();
|
||||
extern void ppc_crand();
|
||||
extern void ppc_crandc();
|
||||
extern void ppc_creqv();
|
||||
extern void ppc_crnand();
|
||||
extern void ppc_crnor();
|
||||
extern void ppc_cror();
|
||||
extern void ppc_crorc();
|
||||
extern void ppc_crxor();
|
||||
extern void ppc_isync();
|
||||
|
||||
template <logical_fun logical_op, field_rc rec> extern void ppc_logical();
|
||||
|
||||
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_add();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_adde();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_addme();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_addze();
|
||||
extern void ppc_cmp();
|
||||
extern void ppc_cmpl();
|
||||
template <field_rc rec> extern void ppc_cntlzw();
|
||||
extern void ppc_dcbf();
|
||||
extern void ppc_dcbi();
|
||||
extern void ppc_dcbst();
|
||||
extern void ppc_dcbt();
|
||||
extern void ppc_dcbtst();
|
||||
extern void ppc_dcbz();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_divw();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_divwu();
|
||||
extern void ppc_eciwx();
|
||||
extern void ppc_ecowx();
|
||||
extern void ppc_eieio();
|
||||
template <class T, field_rc rec>extern void ppc_exts();
|
||||
extern void ppc_icbi();
|
||||
extern void ppc_mftb();
|
||||
extern void ppc_lhaux();
|
||||
extern void ppc_lhax();
|
||||
extern void ppc_lhbrx();
|
||||
extern void ppc_lwarx();
|
||||
extern void ppc_lwbrx();
|
||||
template <class T> extern void ppc_lzx();
|
||||
template <class T> extern void ppc_lzux();
|
||||
extern void ppc_mcrxr();
|
||||
extern void ppc_mfcr();
|
||||
template <field_rc rec> extern void ppc_mulhwu();
|
||||
template <field_rc rec> extern void ppc_mulhw();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_mullw();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_neg();
|
||||
template <field_direction shift, field_rc rec> extern void ppc_shift();
|
||||
template <field_rc rec> extern void ppc_sraw();
|
||||
template <field_rc rec> extern void ppc_srawi();
|
||||
template <class T> extern void ppc_stx();
|
||||
template <class T> extern void ppc_stux();
|
||||
extern void ppc_stfiwx();
|
||||
extern void ppc_sthbrx();
|
||||
extern void ppc_stwcx();
|
||||
extern void ppc_stwbrx();
|
||||
template <field_carry carry, field_rc rec, field_ov ov> extern void ppc_subf();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfe();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfme();
|
||||
template <field_rc rec, field_ov ov> extern void ppc_subfze();
|
||||
extern void ppc_sync();
|
||||
extern void ppc_tlbia();
|
||||
extern void ppc_tlbie();
|
||||
extern void ppc_tlbli();
|
||||
extern void ppc_tlbld();
|
||||
extern void ppc_tlbsync();
|
||||
extern void ppc_tw();
|
||||
|
||||
extern void ppc_lswi();
|
||||
extern void ppc_lswx();
|
||||
extern void ppc_stswi();
|
||||
extern void ppc_stswx();
|
||||
|
||||
extern void ppc_mfsr();
|
||||
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();
|
||||
extern void ppc_mtmsr();
|
||||
extern void ppc_mtspr();
|
||||
|
||||
template <field_rc rec> extern void ppc_mtfsb0();
|
||||
template <field_rc rec> extern void ppc_mtfsb1();
|
||||
extern void ppc_mcrfs();
|
||||
template <field_rc rec> extern void ppc_fmr();
|
||||
template <field_601 for601, field_rc rec> extern void ppc_mffs();
|
||||
template <field_rc rec> extern void ppc_mtfsf();
|
||||
template <field_rc rec> extern void ppc_mtfsfi();
|
||||
|
||||
template <field_shift shift> extern void ppc_addi();
|
||||
template <field_rc rec> extern void ppc_addic();
|
||||
template <field_shift shift> extern void ppc_andirc();
|
||||
template <field_lk l, field_aa a> extern void ppc_b();
|
||||
template <field_lk l, field_aa a> extern void ppc_bc();
|
||||
extern void ppc_cmpi();
|
||||
extern void ppc_cmpli();
|
||||
template <class T> extern void ppc_lz();
|
||||
template <class T> extern void ppc_lzu();
|
||||
extern void ppc_lha();
|
||||
extern void ppc_lhau();
|
||||
extern void ppc_lmw();
|
||||
extern void ppc_mulli();
|
||||
template <field_shift shift> extern void ppc_ori();
|
||||
extern void ppc_rfi();
|
||||
extern void ppc_rlwimi();
|
||||
extern void ppc_rlwinm();
|
||||
extern void ppc_rlwnm();
|
||||
extern void ppc_sc();
|
||||
template <class T> extern void ppc_st();
|
||||
template <class T> extern void ppc_stu();
|
||||
extern void ppc_stmw();
|
||||
extern void ppc_subfic();
|
||||
extern void ppc_twi();
|
||||
template <field_shift shift> extern void ppc_xori();
|
||||
|
||||
extern void ppc_lfs();
|
||||
extern void ppc_lfsu();
|
||||
extern void ppc_lfsx();
|
||||
extern void ppc_lfsux();
|
||||
extern void ppc_lfd();
|
||||
extern void ppc_lfdu();
|
||||
extern void ppc_lfdx();
|
||||
extern void ppc_lfdux();
|
||||
extern void ppc_stfs();
|
||||
extern void ppc_stfsu();
|
||||
extern void ppc_stfsx();
|
||||
extern void ppc_stfsux();
|
||||
extern void ppc_stfd();
|
||||
extern void ppc_stfdu();
|
||||
extern void ppc_stfdx();
|
||||
extern void ppc_stfdux();
|
||||
|
||||
template <field_rc rec> extern void ppc_fadd();
|
||||
template <field_rc rec> extern void ppc_fsub();
|
||||
template <field_rc rec> extern void ppc_fmul();
|
||||
template <field_rc rec> extern void ppc_fdiv();
|
||||
template <field_rc rec> extern void ppc_fadds();
|
||||
template <field_rc rec> extern void ppc_fsubs();
|
||||
template <field_rc rec> extern void ppc_fmuls();
|
||||
template <field_rc rec> extern void ppc_fdivs();
|
||||
template <field_rc rec> extern void ppc_fmadd();
|
||||
template <field_rc rec> extern void ppc_fmsub();
|
||||
template <field_rc rec> extern void ppc_fnmadd();
|
||||
template <field_rc rec> extern void ppc_fnmsub();
|
||||
template <field_rc rec> extern void ppc_fmadds();
|
||||
template <field_rc rec> extern void ppc_fmsubs();
|
||||
template <field_rc rec> extern void ppc_fnmadds();
|
||||
template <field_rc rec> extern void ppc_fnmsubs();
|
||||
template <field_rc rec> extern void ppc_fabs();
|
||||
template <field_rc rec> extern void ppc_fnabs();
|
||||
template <field_rc rec> extern void ppc_fneg();
|
||||
template <field_rc rec> extern void ppc_fsel();
|
||||
template <field_rc rec> extern void ppc_fres();
|
||||
template <field_rc rec> extern void ppc_fsqrts();
|
||||
template <field_rc rec> extern void ppc_fsqrt();
|
||||
template <field_rc rec> extern void ppc_frsqrte();
|
||||
template <field_rc rec> extern void ppc_frsp();
|
||||
template <field_rc rec> extern void ppc_fctiw();
|
||||
template <field_rc rec> extern void ppc_fctiwz();
|
||||
|
||||
extern void ppc_fcmpo();
|
||||
extern void ppc_fcmpu();
|
||||
|
||||
// Power-specific instructions
|
||||
template <field_rc rec, field_ov ov> extern void power_abs();
|
||||
extern void power_clcs();
|
||||
template <field_rc rec, field_ov ov> extern void power_div();
|
||||
template <field_rc rec, field_ov ov> extern void power_divs();
|
||||
template <field_rc rec, field_ov ov> extern void power_doz();
|
||||
extern void power_dozi();
|
||||
template <field_rc rec> extern void power_lscbx();
|
||||
template <field_rc rec> extern void power_maskg();
|
||||
template <field_rc rec> extern void power_maskir();
|
||||
template <field_rc rec, field_ov ov> extern void power_mul();
|
||||
template <field_rc rec, field_ov ov> extern void power_nabs();
|
||||
extern void power_rlmi();
|
||||
template <field_rc rec> extern void power_rrib();
|
||||
template <field_rc rec> extern void power_sle();
|
||||
template <field_rc rec> extern void power_sleq();
|
||||
template <field_rc rec> extern void power_sliq();
|
||||
template <field_rc rec> extern void power_slliq();
|
||||
template <field_rc rec> extern void power_sllq();
|
||||
template <field_rc rec> extern void power_slq();
|
||||
template <field_rc rec> extern void power_sraiq();
|
||||
template <field_rc rec> extern void power_sraq();
|
||||
template <field_rc rec> extern void power_sre();
|
||||
template <field_rc rec> extern void power_srea();
|
||||
template <field_rc rec> extern void power_sreq();
|
||||
template <field_rc rec> extern void power_sriq();
|
||||
template <field_rc rec> extern void power_srliq();
|
||||
template <field_rc rec> extern void power_srlq();
|
||||
template <field_rc rec> extern void power_srq();
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
// AltiVec instructions
|
||||
|
||||
// 64-bit instructions
|
||||
|
||||
// G5+ instructions
|
||||
|
||||
extern uint64_t get_virt_time_ns(void);
|
||||
|
||||
extern void ppc_main_opcode(void);
|
||||
extern void ppc_main_opcode(uint32_t instr);
|
||||
extern void ppc_exec(void);
|
||||
extern void ppc_exec_single(void);
|
||||
extern void ppc_exec_until(uint32_t goal_addr);
|
||||
@@ -657,4 +438,13 @@ void print_fprs(void); /* print content of the floating-point
|
||||
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 */
|
||||
|
||||
// The functions used by the PowerPC processor
|
||||
#include "ppcmacros_prototypes.h"
|
||||
|
||||
namespace dppc_interpreter {
|
||||
#include "ppcopcodes.include"
|
||||
#include "poweropcodes.include"
|
||||
#include "ppcfpopcodes.include"
|
||||
} // namespace dppc_interpreter
|
||||
|
||||
#endif /* PPCEMU_H */
|
||||
+29
-29
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
jmp_buf exc_env; /* Global exception environment. */
|
||||
|
||||
#if !defined(PPC_TESTS) && !defined(PPC_BENCHMARKS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
#ifdef CPU_PROFILING
|
||||
exceptions_processed++;
|
||||
@@ -135,7 +136,7 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
longjmp(exc_env, 2); /* return to the main execution loop. */
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
[[noreturn]] void dbg_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
std::string exc_descriptor;
|
||||
@@ -195,17 +196,16 @@ void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
throw std::invalid_argument(exc_descriptor);
|
||||
}
|
||||
|
||||
void ppc_floating_point_exception() {
|
||||
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x",
|
||||
ppc_state.pc, ppc_cur_instruction);
|
||||
void ppc_floating_point_exception(uint32_t instr) {
|
||||
LOG_F(ERROR, "Floating point exception at 0x%08x for instruction 0x%08x", ppc_state.pc, instr);
|
||||
// mmu_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_EXCEPTION);
|
||||
}
|
||||
|
||||
void ppc_alignment_exception(uint32_t ea)
|
||||
void ppc_alignment_exception(uint32_t ea, uint32_t instr)
|
||||
{
|
||||
uint32_t dsisr;
|
||||
|
||||
switch (ppc_cur_instruction & 0xfc000000) {
|
||||
switch (instr & 0xfc000000) {
|
||||
case 0x80000000: // lwz
|
||||
case 0x90000000: // stw
|
||||
case 0xa0000000: // lhz
|
||||
@@ -226,12 +226,12 @@ void ppc_alignment_exception(uint32_t ea)
|
||||
case 0xcc000000: // lfdu
|
||||
case 0xd4000000: // stfsu
|
||||
case 0xdc000000: // stfdu
|
||||
indirect_with_immediate_index:
|
||||
dsisr = ((ppc_cur_instruction >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
|
||||
| ((ppc_cur_instruction >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
|
||||
// indirect with immediate index
|
||||
dsisr = ((instr >> 12) & 0x00004000) // bit 17 — Set to bit 5 of the instruction.
|
||||
| ((instr >> 17) & 0x00003c00); // bits 18–21 - set to bits 1–4 of the instruction.
|
||||
break;
|
||||
case 0x7c000000:
|
||||
switch (ppc_cur_instruction & 0xfc0007ff) {
|
||||
switch (instr & 0xfc0007ff) {
|
||||
case 0x7c000028: // lwarx (invalid form - bits 15-21 of DSISR are identical to those of lwz)
|
||||
case 0x7c0002aa: // lwax (64-bit only)
|
||||
case 0x7c00042a: // lswx
|
||||
@@ -265,12 +265,12 @@ indirect_with_immediate_index:
|
||||
case 0x7c00056e: // stfsux
|
||||
case 0x7c0005ee: // stfdux
|
||||
indirect_with_index:
|
||||
dsisr = ((ppc_cur_instruction << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
|
||||
| ((ppc_cur_instruction << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
|
||||
| ((ppc_cur_instruction << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
|
||||
dsisr = ((instr << 14) & 0x00018000) // bits 15–16 - set to bits 29–30 of the instruction.
|
||||
| ((instr << 8) & 0x00004000) // bit 17 - set to bit 25 of the instruction.
|
||||
| ((instr << 3) & 0x00003c00); // bits 18–21 - set to bits 21–24 of the instruction.
|
||||
break;
|
||||
case 0x7c0007ec:
|
||||
if ((ppc_cur_instruction & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
if ((instr & 0xffe007ff) == 0x7c0007ec) // dcbz
|
||||
goto indirect_with_index;
|
||||
/* fallthrough */
|
||||
default:
|
||||
@@ -281,31 +281,31 @@ indirect_with_index:
|
||||
unexpected_instruction:
|
||||
dsisr = 0;
|
||||
LOG_F(ERROR, "Alignment exception from unexpected instruction 0x%08x",
|
||||
ppc_cur_instruction);
|
||||
instr);
|
||||
}
|
||||
|
||||
// bits 22–26 - Set to bits 6–10 (source or destination) of the instruction.
|
||||
// Undefined for dcbz.
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x000003e0);
|
||||
dsisr |= ((instr >> 16) & 0x000003e0);
|
||||
|
||||
if ((ppc_cur_instruction & 0xfc000000) == 0xb8000000) { // lmw
|
||||
if ((instr & 0xfc000000) == 0xb8000000) { // lmw
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lmw). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c0004aa) { // lswi
|
||||
"What to set DSISR bits 27-31?", instr);
|
||||
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((instr & 0xfc0007ff) == 0x7c0004aa) { // lswi
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswi). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((ppc_cur_instruction & 0xfc0007ff) == 0x7c00042a) { // lswx
|
||||
"What to set DSISR bits 27-31?", instr);
|
||||
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else if ((instr & 0xfc0007ff) == 0x7c00042a) { // lswx
|
||||
LOG_F(ERROR, "Alignment exception from instruction 0x%08x (lswx). "
|
||||
"What to set DSISR bits 27-31?", ppc_cur_instruction);
|
||||
// dsisr |= ((ppc_cur_instruction >> ?) & 0x0000001f); // bits 27–31
|
||||
"What to set DSISR bits 27-31?", instr);
|
||||
// dsisr |= ((instr >> ?) & 0x0000001f); // bits 27–31
|
||||
}
|
||||
else {
|
||||
// bits 27–31 - Set to bits 11–15 of the instruction (rA)
|
||||
dsisr |= ((ppc_cur_instruction >> 16) & 0x0000001f);
|
||||
dsisr |= ((instr >> 16) & 0x0000001f);
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::DSISR] = dsisr;
|
||||
|
||||
+170
-326
@@ -23,6 +23,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <loguru.hpp>
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmmu.h"
|
||||
#include "ppcdisasm.h"
|
||||
#include "ppcoptablemacros.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
@@ -61,11 +63,6 @@ Po_Cause power_off_reason = po_enter_debugger;
|
||||
|
||||
SetPRS ppc_state;
|
||||
|
||||
bool grab_return;
|
||||
bool grab_breakpoint;
|
||||
|
||||
uint32_t ppc_cur_instruction; // Current instruction for the PPC
|
||||
uint32_t ppc_effective_address;
|
||||
uint32_t ppc_next_instruction_address; // Used for branching, setting up the NIA
|
||||
|
||||
unsigned exec_flags; // execution control flags
|
||||
@@ -83,7 +80,6 @@ uint32_t glob_bb_start_la;
|
||||
/* variables related to virtual time */
|
||||
const bool g_realtime = false;
|
||||
uint64_t g_nanoseconds_base;
|
||||
uint64_t g_icycles_base;
|
||||
uint64_t g_icycles;
|
||||
int icnt_factor;
|
||||
|
||||
@@ -109,6 +105,9 @@ uint64_t num_supervisor_instrs;
|
||||
uint64_t num_int_loads;
|
||||
uint64_t num_int_stores;
|
||||
uint64_t exceptions_processed;
|
||||
#ifdef CPU_PROFILING_OPS
|
||||
std::unordered_map<uint32_t, uint64_t> num_opcodes;
|
||||
#endif
|
||||
|
||||
#include "utils/profiler.h"
|
||||
#include <memory>
|
||||
@@ -139,6 +138,30 @@ public:
|
||||
vars.push_back({.name = "Exceptions processed",
|
||||
.format = ProfileVarFmt::DEC,
|
||||
.value = exceptions_processed});
|
||||
|
||||
// Generate top N op counts with readable names.
|
||||
#ifdef CPU_PROFILING_OPS
|
||||
PPCDisasmContext ctx;
|
||||
ctx.instr_addr = 0;
|
||||
ctx.simplified = false;
|
||||
std::vector<std::pair<std::string, uint64_t>> op_name_counts;
|
||||
for (const auto& pair : num_opcodes) {
|
||||
ctx.instr_code = pair.first;
|
||||
auto op_name = disassemble_single(&ctx);
|
||||
op_name_counts.emplace_back(op_name, pair.second);
|
||||
}
|
||||
size_t top_ops_size = std::min(op_name_counts.size(), size_t(20));
|
||||
std::partial_sort(op_name_counts.begin(), op_name_counts.begin() + top_ops_size, op_name_counts.end(), [](const auto& a, const auto& b) {
|
||||
return b.second < a.second;
|
||||
});
|
||||
op_name_counts.resize(top_ops_size);
|
||||
for (const auto& pair : op_name_counts) {
|
||||
vars.push_back({.name = "Instruction " + pair.first,
|
||||
.format = ProfileVarFmt::COUNT,
|
||||
.value = pair.second,
|
||||
.count_total = num_executed_instrs});
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
void reset() {
|
||||
@@ -147,6 +170,9 @@ public:
|
||||
num_int_loads = 0;
|
||||
num_int_stores = 0;
|
||||
exceptions_processed = 0;
|
||||
#ifdef CPU_PROFILING_OPS
|
||||
num_opcodes.clear();
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
@@ -158,28 +184,21 @@ public:
|
||||
static PPCOpcode OpcodeGrabber[64];
|
||||
|
||||
/** Lookup tables for branch instructions. */
|
||||
const static PPCOpcode SubOpcode16Grabber[] = {
|
||||
dppc_interpreter::ppc_bc<LK0, AA0>, // bc
|
||||
dppc_interpreter::ppc_bc<LK1, AA0>, // bcl
|
||||
dppc_interpreter::ppc_bc<LK0, AA1>, // bca
|
||||
dppc_interpreter::ppc_bc<LK1, AA1>}; // bcla
|
||||
static PPCOpcode Opcode16Grabber[4]; // bcla
|
||||
|
||||
const static PPCOpcode SubOpcode18Grabber[] = {
|
||||
dppc_interpreter::ppc_b<LK0, AA0>, // b
|
||||
dppc_interpreter::ppc_b<LK1, AA0>, // bl
|
||||
dppc_interpreter::ppc_b<LK0, AA1>, // ba
|
||||
dppc_interpreter::ppc_b<LK1, AA1>}; // bla
|
||||
static PPCOpcode Opcode18Grabber[4]; // bla
|
||||
|
||||
/** Instructions decoding tables for integer,
|
||||
single floating-point, and double-floating point ops respectively */
|
||||
|
||||
static PPCOpcode SubOpcode31Grabber[2048];
|
||||
static PPCOpcode SubOpcode59Grabber[64];
|
||||
static PPCOpcode SubOpcode63Grabber[2048];
|
||||
static PPCOpcode Opcode19Grabber[2048];
|
||||
static PPCOpcode Opcode31Grabber[2048];
|
||||
static PPCOpcode Opcode59Grabber[64];
|
||||
static PPCOpcode Opcode63Grabber[2048];
|
||||
|
||||
/** Exception helpers. */
|
||||
|
||||
void ppc_illegalop() {
|
||||
void ppc_illegalop(uint32_t null_val) {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
|
||||
@@ -203,97 +222,131 @@ void ppc_release_int() {
|
||||
|
||||
/** Opcode decoding functions. */
|
||||
|
||||
void ppc_opcode16() {
|
||||
SubOpcode16Grabber[ppc_cur_instruction & 3]();
|
||||
static void ppc_opcode16(uint32_t subop, uint32_t instr) {
|
||||
Opcode16Grabber[instr & 3](instr);
|
||||
}
|
||||
|
||||
void ppc_opcode18() {
|
||||
SubOpcode18Grabber[ppc_cur_instruction & 3]();
|
||||
static void ppc_opcode18(uint32_t instr) {
|
||||
Opcode18Grabber[instr & 3](instr);
|
||||
}
|
||||
|
||||
template<field_601 for601>
|
||||
void ppc_opcode19() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x7FF;
|
||||
void ppc_opcode19(uint32_t instr) {
|
||||
uint16_t subop_grab = instr & 0x7FF;
|
||||
|
||||
switch (subop_grab) {
|
||||
case 0:
|
||||
ppc_mcrf();
|
||||
ppc_mcrf(instr);
|
||||
break;
|
||||
case 32:
|
||||
ppc_bclr<LK0>();
|
||||
ppc_bclr<LK0>(instr);
|
||||
break;
|
||||
case 33:
|
||||
ppc_bclr<LK1>();
|
||||
ppc_bclr<LK1>(instr);
|
||||
break;
|
||||
case 66:
|
||||
ppc_crnor();
|
||||
ppc_crnor(instr);
|
||||
break;
|
||||
case 100:
|
||||
ppc_rfi();
|
||||
ppc_rfi(instr);
|
||||
break;
|
||||
case 258:
|
||||
ppc_crandc();
|
||||
ppc_crandc(instr);
|
||||
break;
|
||||
case 300:
|
||||
ppc_isync();
|
||||
ppc_isync(instr);
|
||||
break;
|
||||
case 386:
|
||||
ppc_crxor();
|
||||
ppc_crxor(instr);
|
||||
break;
|
||||
case 450:
|
||||
ppc_crnand();
|
||||
ppc_crnand(instr);
|
||||
break;
|
||||
case 514:
|
||||
ppc_crand();
|
||||
ppc_crand(instr);
|
||||
break;
|
||||
case 578:
|
||||
ppc_creqv();
|
||||
ppc_creqv(instr);
|
||||
break;
|
||||
case 834:
|
||||
ppc_crorc();
|
||||
ppc_crorc(instr);
|
||||
break;
|
||||
case 898:
|
||||
ppc_cror();
|
||||
ppc_cror(instr);
|
||||
break;
|
||||
case 1056:
|
||||
ppc_bcctr<LK0, for601>();
|
||||
ppc_bcctr<LK0, for601>(instr);
|
||||
break;
|
||||
case 1057:
|
||||
ppc_bcctr<LK1, for601>();
|
||||
ppc_bcctr<LK1, for601>(instr);
|
||||
break;
|
||||
default:
|
||||
ppc_illegalop();
|
||||
}
|
||||
}
|
||||
|
||||
template void ppc_opcode19<NOT601>();
|
||||
template void ppc_opcode19<IS601>();
|
||||
template void ppc_opcode19<NOT601>(uint32_t);
|
||||
template void ppc_opcode19<IS601>(uint32_t);
|
||||
|
||||
void ppc_opcode31() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x7FFUL;
|
||||
SubOpcode31Grabber[subop_grab]();
|
||||
void ppc_opcode31(uint32_t instr) {
|
||||
}
|
||||
|
||||
void ppc_opcode59() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x3FUL;
|
||||
SubOpcode59Grabber[subop_grab]();
|
||||
void ppc_opcode59(uint32_t instr) {
|
||||
uint16_t subop_grab = instr & 0x3FUL;
|
||||
Opcode59Grabber[subop_grab](instr);
|
||||
}
|
||||
|
||||
void ppc_opcode63() {
|
||||
uint16_t subop_grab = ppc_cur_instruction & 0x7FFUL;
|
||||
SubOpcode63Grabber[subop_grab]();
|
||||
void ppc_opcode63(uint32_t instr) {
|
||||
uint16_t subop_grab = instr & 0x7FFUL;
|
||||
Opcode63Grabber[subop_grab](instr);
|
||||
}
|
||||
|
||||
/* Dispatch using main opcode */
|
||||
void ppc_main_opcode()
|
||||
{
|
||||
void ppc_main_opcode(uint32_t instr) {
|
||||
#ifdef CPU_PROFILING
|
||||
num_executed_instrs++;
|
||||
#if defined(CPU_PROFILING_OPS)
|
||||
num_opcodes[instr]++;
|
||||
#endif
|
||||
#endif
|
||||
uint32_t opcode = (instr >> 26) & 63;
|
||||
switch (opcode) {
|
||||
case 16:
|
||||
Opcode16Grabber[instr & 3](instr);
|
||||
break;
|
||||
case 18:
|
||||
Opcode16Grabber[instr & 3](instr);
|
||||
break;
|
||||
case 19:
|
||||
if (is_601)
|
||||
ppc_opcode19<IS601>(instr);
|
||||
else
|
||||
ppc_opcode19<NOT601>(instr);
|
||||
break;
|
||||
case 31:
|
||||
uint16_t subop_grab = instr & 0x7FFUL;
|
||||
Opcode31Grabber[subop_grab](instr);
|
||||
break;
|
||||
case 59:
|
||||
uint16_t subop_grab = instr & 0x7FFUL;
|
||||
Opcode31Grabber[subop_grab](instr);
|
||||
break;
|
||||
case 63:
|
||||
uint16_t subop_grab = instr & 0x7FFUL;
|
||||
Opcode31Grabber[subop_grab](instr);
|
||||
break;
|
||||
default:
|
||||
OpcodeGrabber[opcode](instr);
|
||||
}
|
||||
|
||||
#ifdef CPU_PROFILING
|
||||
uint32_t load_chk = (instr >> 26);
|
||||
if ((load_chk > 31) && (load_chk < 59))
|
||||
num_int_loads++;
|
||||
#endif
|
||||
OpcodeGrabber[(ppc_cur_instruction >> 26) & 0x3F]();
|
||||
}
|
||||
|
||||
long long now_ns() {
|
||||
static long long cpu_now_ns() {
|
||||
#ifdef __APPLE__
|
||||
return ConvertHostTimeToNanos2(mach_absolute_time());
|
||||
#else
|
||||
@@ -305,25 +358,25 @@ long long now_ns() {
|
||||
uint64_t get_virt_time_ns()
|
||||
{
|
||||
if (g_realtime) {
|
||||
return now_ns() - g_nanoseconds_base;
|
||||
return cpu_now_ns() - g_nanoseconds_base;
|
||||
} else {
|
||||
return g_icycles << icnt_factor;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t process_events()
|
||||
static uint64_t process_events()
|
||||
{
|
||||
exec_timer = false;
|
||||
uint64_t slice_ns = TimerManager::get_instance()->process_timers();
|
||||
if (slice_ns == 0) {
|
||||
// execute 10.000 cycles
|
||||
// execute 25.000 cycles
|
||||
// if there are no pending timers
|
||||
return g_icycles + 10000;
|
||||
return g_icycles + 25000;
|
||||
}
|
||||
return g_icycles + ((slice_ns + (1ULL << icnt_factor)) >> icnt_factor);
|
||||
return g_icycles + (slice_ns >> icnt_factor) + 1;
|
||||
}
|
||||
|
||||
void force_cycle_counter_reload()
|
||||
static void force_cycle_counter_reload()
|
||||
{
|
||||
// tell the interpreter loop to reload cycle counter
|
||||
exec_timer = true;
|
||||
@@ -336,6 +389,9 @@ static void ppc_exec_inner()
|
||||
uint64_t max_cycles;
|
||||
uint32_t page_start, eb_start, eb_end;
|
||||
uint8_t* pc_real;
|
||||
uint32_t instr = 0;
|
||||
uint32_t i_params[5] = {0};
|
||||
double f_params[4] = {0};
|
||||
|
||||
max_cycles = 0;
|
||||
|
||||
@@ -347,11 +403,12 @@ static void ppc_exec_inner()
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
exec_flags = 0;
|
||||
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
|
||||
// interpret execution block
|
||||
while (power_on && ppc_state.pc < eb_end) {
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(instr);
|
||||
if (g_icycles++ >= max_cycles || exec_timer) {
|
||||
max_cycles = process_events();
|
||||
}
|
||||
@@ -361,18 +418,19 @@ static void ppc_exec_inner()
|
||||
eb_start = ppc_next_instruction_address;
|
||||
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
|
||||
pc_real += (int)eb_start - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
} else {
|
||||
page_start = eb_start & PPC_PAGE_MASK;
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
exec_flags = 0;
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
pc_real += 4;
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -404,7 +462,11 @@ void ppc_exec_single()
|
||||
}
|
||||
|
||||
mmu_translate_imem(ppc_state.pc);
|
||||
ppc_main_opcode();
|
||||
|
||||
uint8_t* pc_real = mmu_translate_imem(ppc_state.pc);
|
||||
uint32_t instr = ppc_set_cur_instruction(pc_real);
|
||||
ppc_main_opcode(instr);
|
||||
|
||||
g_icycles++;
|
||||
process_events();
|
||||
|
||||
@@ -424,6 +486,7 @@ static void ppc_exec_until_inner(const uint32_t goal_addr)
|
||||
uint64_t max_cycles;
|
||||
uint32_t page_start, eb_start, eb_end;
|
||||
uint8_t* pc_real;
|
||||
uint32_t instr;
|
||||
|
||||
max_cycles = 0;
|
||||
|
||||
@@ -435,11 +498,12 @@ static void ppc_exec_until_inner(const uint32_t goal_addr)
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
exec_flags = 0;
|
||||
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
|
||||
// interpret execution block
|
||||
while (power_on && ppc_state.pc < eb_end) {
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(instr);
|
||||
if (g_icycles++ >= max_cycles || exec_timer) {
|
||||
max_cycles = process_events();
|
||||
}
|
||||
@@ -449,18 +513,19 @@ static void ppc_exec_until_inner(const uint32_t goal_addr)
|
||||
eb_start = ppc_next_instruction_address;
|
||||
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
|
||||
pc_real += (int)eb_start - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
} else {
|
||||
page_start = eb_start & PPC_PAGE_MASK;
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
exec_flags = 0;
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
|
||||
if (ppc_state.pc == goal_addr)
|
||||
@@ -491,6 +556,7 @@ static void ppc_exec_dbg_inner(const uint32_t start_addr, const uint32_t size)
|
||||
uint64_t max_cycles;
|
||||
uint32_t page_start, eb_start, eb_end;
|
||||
uint8_t* pc_real;
|
||||
uint32_t instr = 0;
|
||||
|
||||
max_cycles = 0;
|
||||
|
||||
@@ -502,12 +568,13 @@ static void ppc_exec_dbg_inner(const uint32_t start_addr, const uint32_t size)
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
exec_flags = 0;
|
||||
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
|
||||
// interpret execution block
|
||||
while (power_on && (ppc_state.pc < start_addr || ppc_state.pc >= start_addr + size)
|
||||
&& (ppc_state.pc < eb_end)) {
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(instr);
|
||||
if (g_icycles++ >= max_cycles || exec_timer) {
|
||||
max_cycles = process_events();
|
||||
}
|
||||
@@ -517,18 +584,19 @@ static void ppc_exec_dbg_inner(const uint32_t start_addr, const uint32_t size)
|
||||
eb_start = ppc_next_instruction_address;
|
||||
if (!(exec_flags & EXEF_RFI) && (eb_start & PPC_PAGE_MASK) == page_start) {
|
||||
pc_real += (int)eb_start - (int)ppc_state.pc;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
} else {
|
||||
page_start = eb_start & PPC_PAGE_MASK;
|
||||
eb_end = page_start + PPC_PAGE_SIZE - 1;
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
pc_real = mmu_translate_imem(eb_start);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
ppc_state.pc = eb_start;
|
||||
exec_flags = 0;
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
pc_real += 4;
|
||||
ppc_set_cur_instruction(pc_real);
|
||||
instr = ppc_set_cur_instruction(pc_real);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -594,258 +662,34 @@ do { \
|
||||
opcode ## Grabber[1024+((subopcode)<<1)+1] = fn<carry, RC1, OV1>; \
|
||||
} while (0)
|
||||
|
||||
#define OP31(subopcode, fn) OPX(SubOpcode31, subopcode, fn)
|
||||
#define OP31d(subopcode, fn) OPXd(SubOpcode31, subopcode, fn)
|
||||
#define OP31od(subopcode, fn) OPXod(SubOpcode31, subopcode, fn)
|
||||
#define OP31dc(subopcode, fn, carry) OPXdc(SubOpcode31, subopcode, fn, carry)
|
||||
#define OP31cod(subopcode, fn, carry) OPXcod(SubOpcode31, subopcode, fn, carry)
|
||||
#define OP31(subopcode, fn) OPX(Opcode31, subopcode, fn)
|
||||
#define OP31d(subopcode, fn) OPXd(Opcode31, subopcode, fn)
|
||||
#define OP31od(subopcode, fn) OPXod(Opcode31, subopcode, fn)
|
||||
#define OP31dc(subopcode, fn, carry) OPXdc(Opcode31, subopcode, fn, carry)
|
||||
#define OP31cod(subopcode, fn, carry) OPXcod(Opcode31, subopcode, fn, carry)
|
||||
|
||||
#define OP59d(subopcode, fn) OPXd(SubOpcode59, subopcode, fn)
|
||||
#define OP59d(subopcode, fn) OPXd(Opcode59, subopcode, fn)
|
||||
|
||||
#define OP63(subopcode, fn) OPX(SubOpcode63, subopcode, fn)
|
||||
#define OP63d(subopcode, fn) OPXd(SubOpcode63, subopcode, fn)
|
||||
#define OP63dc(subopcode, fn, carry) OPXdc(SubOpcode63, subopcode, fn, carry)
|
||||
#define OP63(subopcode, fn) OPX(Opcode63, subopcode, fn)
|
||||
#define OP63d(subopcode, fn) OPXd(Opcode63, subopcode, fn)
|
||||
#define OP63dc(subopcode, fn, carry) OPXdc(Opcode63, subopcode, fn, carry)
|
||||
|
||||
void initialize_ppc_opcode_tables(bool include_601) {
|
||||
inline void initialize_ppc_opcode_tables(bool include_601) {
|
||||
std::fill_n(OpcodeGrabber, 64, ppc_illegalop);
|
||||
OP(3, ppc_twi);
|
||||
//OP(4, ppc_opcode4); - Altivec instructions not emulated yet. Uncomment once they're implemented.
|
||||
OP(7, ppc_mulli);
|
||||
OP(8, ppc_subfic);
|
||||
if (is_601 || include_601) OP(9, power_dozi);
|
||||
OP(10, ppc_cmpli);
|
||||
OP(11, ppc_cmpi);
|
||||
OP(12, ppc_addic<RC0>);
|
||||
OP(13, ppc_addic<RC1>);
|
||||
OP(14, ppc_addi<SHFT0>);
|
||||
OP(15, ppc_addi<SHFT1>);
|
||||
OP(16, ppc_opcode16);
|
||||
OP(17, ppc_sc);
|
||||
OP(18, ppc_opcode18);
|
||||
if (is_601) OP(19, ppc_opcode19<IS601>); else OP(19, ppc_opcode19<NOT601>);
|
||||
OP(20, ppc_rlwimi);
|
||||
OP(21, ppc_rlwinm);
|
||||
if (is_601 || include_601) OP(22, power_rlmi);
|
||||
OP(23, ppc_rlwnm);
|
||||
OP(24, ppc_ori<SHFT0>);
|
||||
OP(25, ppc_ori<SHFT1>);
|
||||
OP(26, ppc_xori<SHFT0>);
|
||||
OP(27, ppc_xori<SHFT1>);
|
||||
OP(28, ppc_andirc<SHFT0>);
|
||||
OP(29, ppc_andirc<SHFT1>);
|
||||
OP(31, ppc_opcode31);
|
||||
OP(32, ppc_lz<uint32_t>);
|
||||
OP(33, ppc_lzu<uint32_t>);
|
||||
OP(34, ppc_lz<uint8_t>);
|
||||
OP(35, ppc_lzu<uint8_t>);
|
||||
OP(36, ppc_st<uint32_t>);
|
||||
OP(37, ppc_stu<uint32_t>);
|
||||
OP(38, ppc_st<uint8_t>);
|
||||
OP(39, ppc_stu<uint8_t>);
|
||||
OP(40, ppc_lz<uint16_t>);
|
||||
OP(41, ppc_lzu<uint16_t>);
|
||||
OP(42, ppc_lha);
|
||||
OP(43, ppc_lhau);
|
||||
OP(44, ppc_st<uint16_t>);
|
||||
OP(45, ppc_stu<uint16_t>);
|
||||
OP(46, ppc_lmw);
|
||||
OP(47, ppc_stmw);
|
||||
OP(48, ppc_lfs);
|
||||
OP(49, ppc_lfsu);
|
||||
OP(50, ppc_lfd);
|
||||
OP(51, ppc_lfdu);
|
||||
OP(52, ppc_stfs);
|
||||
OP(53, ppc_stfsu);
|
||||
OP(54, ppc_stfd);
|
||||
OP(55, ppc_stfdu);
|
||||
OP(59, ppc_opcode59);
|
||||
OP(63, ppc_opcode63);
|
||||
std::fill_n(Opcode16Grabber, 3, ppc_illegalop);
|
||||
std::fill_n(Opcode18Grabber, 3, ppc_illegalop);
|
||||
std::fill_n(Opcode19Grabber, 2048, ppc_illegalop);
|
||||
std::fill_n(Opcode31Grabber, 2048, ppc_illegalop);
|
||||
std::fill_n(Opcode59Grabber, 64, ppc_illegalop);
|
||||
std::fill_n(Opcode63Grabber, 2048, ppc_illegalop);
|
||||
|
||||
std::fill_n(SubOpcode31Grabber, 2048, ppc_illegalop);
|
||||
OP31(0, ppc_cmp);
|
||||
OP31(4, ppc_tw);
|
||||
OP31(32, ppc_cmpl);
|
||||
|
||||
OP31cod(8, ppc_subf, CARRY1);
|
||||
OP31cod(40, ppc_subf, CARRY0);
|
||||
OP31od(104, ppc_neg);
|
||||
OP31od(136, ppc_subfe);
|
||||
OP31od(200, ppc_subfze);
|
||||
OP31od(232, ppc_subfme);
|
||||
|
||||
OP31cod(10, ppc_add, CARRY1);
|
||||
OP31od(138, ppc_adde);
|
||||
OP31od(202, ppc_addze);
|
||||
OP31od(234, ppc_addme);
|
||||
OP31cod(266, ppc_add, CARRY0);
|
||||
|
||||
OP31d(11, ppc_mulhwu);
|
||||
OP31d(75, ppc_mulhw);
|
||||
OP31od(235, ppc_mullw);
|
||||
OP31od(459, ppc_divwu);
|
||||
OP31od(491, ppc_divw);
|
||||
|
||||
OP31(20, ppc_lwarx);
|
||||
OP31(23, ppc_lzx<uint32_t>);
|
||||
OP31(55, ppc_lzux<uint32_t>);
|
||||
OP31(87, ppc_lzx<uint8_t>);
|
||||
OP31(119, ppc_lzux<uint8_t>);
|
||||
OP31(279, ppc_lzx<uint16_t>);
|
||||
OP31(311, ppc_lzux<uint16_t>);
|
||||
OP31(343, ppc_lhax);
|
||||
OP31(375, ppc_lhaux);
|
||||
OP31(533, ppc_lswx);
|
||||
OP31(534, ppc_lwbrx);
|
||||
OP31(535, ppc_lfsx);
|
||||
OP31(567, ppc_lfsux);
|
||||
OP31(597, ppc_lswi);
|
||||
OP31(599, ppc_lfdx);
|
||||
OP31(631, ppc_lfdux);
|
||||
OP31(790, ppc_lhbrx);
|
||||
|
||||
SubOpcode31Grabber[(150<<1)+1] = ppc_stwcx; // No Rc=0 variant.
|
||||
OP31(151, ppc_stx<uint32_t>);
|
||||
OP31(183, ppc_stux<uint32_t>);
|
||||
OP31(215, ppc_stx<uint8_t>);
|
||||
OP31(247, ppc_stux<uint8_t>);
|
||||
OP31(407, ppc_stx<uint16_t>);
|
||||
OP31(439, ppc_stux<uint16_t>);
|
||||
OP31(661, ppc_stswx);
|
||||
OP31(662, ppc_stwbrx);
|
||||
OP31(663, ppc_stfsx);
|
||||
OP31(695, ppc_stfsux);
|
||||
OP31(725, ppc_stswi);
|
||||
OP31(727, ppc_stfdx);
|
||||
OP31(759, ppc_stfdux);
|
||||
OP31(918, ppc_sthbrx);
|
||||
if (!is_601) OP31(983, ppc_stfiwx);
|
||||
|
||||
OP31(310, ppc_eciwx);
|
||||
OP31(438, ppc_ecowx);
|
||||
|
||||
OP31dc(24, ppc_shift, LEFT1); // slw
|
||||
OP31dc(28, ppc_logical, ppc_and);
|
||||
OP31dc(60, ppc_logical, ppc_andc);
|
||||
OP31dc(124, ppc_logical, ppc_nor);
|
||||
OP31dc(284, ppc_logical, ppc_eqv);
|
||||
OP31dc(316, ppc_logical, ppc_xor);
|
||||
OP31dc(412, ppc_logical, ppc_orc);
|
||||
OP31dc(444, ppc_logical, ppc_or);
|
||||
OP31dc(476, ppc_logical, ppc_nand);
|
||||
OP31dc(536, ppc_shift, RIGHT0); // srw
|
||||
OP31d(792, ppc_sraw);
|
||||
OP31d(824, ppc_srawi);
|
||||
OP31dc(922, ppc_exts, int16_t);
|
||||
OP31dc(954, ppc_exts, int8_t);
|
||||
|
||||
OP31d(26, ppc_cntlzw);
|
||||
|
||||
OP31(19, ppc_mfcr);
|
||||
OP31(83, ppc_mfmsr);
|
||||
OP31(144, ppc_mtcrf);
|
||||
OP31(146, ppc_mtmsr);
|
||||
OP31(210, ppc_mtsr);
|
||||
OP31(242, ppc_mtsrin);
|
||||
OP31(339, ppc_mfspr);
|
||||
if (!is_601) OP31(371, ppc_mftb);
|
||||
OP31(467, ppc_mtspr);
|
||||
OP31(512, ppc_mcrxr);
|
||||
OP31(595, ppc_mfsr);
|
||||
OP31(659, ppc_mfsrin);
|
||||
|
||||
OP31(54, ppc_dcbst);
|
||||
OP31(86, ppc_dcbf);
|
||||
OP31(246, ppc_dcbtst);
|
||||
OP31(278, ppc_dcbt);
|
||||
OP31(598, ppc_sync);
|
||||
OP31(470, ppc_dcbi);
|
||||
OP31(1014, ppc_dcbz);
|
||||
|
||||
if (is_601 || include_601) {
|
||||
OP31d(29, power_maskg);
|
||||
OP31od(107, power_mul);
|
||||
OP31d(152, power_slq);
|
||||
OP31d(153, power_sle);
|
||||
OP31d(184, power_sliq);
|
||||
OP31d(216, power_sllq);
|
||||
OP31d(217, power_sleq);
|
||||
OP31d(248, power_slliq);
|
||||
OP31od(264, power_doz);
|
||||
OP31d(277, power_lscbx);
|
||||
OP31od(331, power_div);
|
||||
OP31od(360, power_abs);
|
||||
OP31od(363, power_divs);
|
||||
OP31od(488, power_nabs);
|
||||
OP31(531, power_clcs);
|
||||
OP31d(537, power_rrib);
|
||||
OP31d(541, power_maskir);
|
||||
OP31d(664, power_srq);
|
||||
OP31d(665, power_sre);
|
||||
OP31d(696, power_sriq);
|
||||
OP31d(728, power_srlq);
|
||||
OP31d(729, power_sreq);
|
||||
OP31d(760, power_srliq);
|
||||
OP31d(920, power_sraq);
|
||||
OP31d(921, power_srea);
|
||||
OP31d(952, power_sraiq);
|
||||
}
|
||||
|
||||
OP31(306, ppc_tlbie);
|
||||
if (!is_601) OP31(370, ppc_tlbia);
|
||||
if (!is_601) OP31(566, ppc_tlbsync);
|
||||
OP31(854, ppc_eieio);
|
||||
OP31(982, ppc_icbi);
|
||||
if (!is_601) OP31(978, ppc_tlbld);
|
||||
if (!is_601) OP31(1010, ppc_tlbli);
|
||||
|
||||
std::fill_n(SubOpcode59Grabber, 64, ppc_illegalop);
|
||||
OP59d(18, ppc_fdivs);
|
||||
OP59d(20, ppc_fsubs);
|
||||
OP59d(21, ppc_fadds);
|
||||
if (ppc_state.spr[SPR::PVR] == PPC_VER::MPC970MP) OP59d(22, ppc_fsqrts);
|
||||
if (!is_601) OP59d(24, ppc_fres);
|
||||
OP59d(25, ppc_fmuls);
|
||||
OP59d(28, ppc_fmsubs);
|
||||
OP59d(29, ppc_fmadds);
|
||||
OP59d(30, ppc_fnmsubs);
|
||||
OP59d(31, ppc_fnmadds);
|
||||
|
||||
std::fill_n(SubOpcode63Grabber, 2048, ppc_illegalop);
|
||||
OP63(0, ppc_fcmpu);
|
||||
OP63d(12, ppc_frsp);
|
||||
OP63d(14, ppc_fctiw);
|
||||
OP63d(15, ppc_fctiwz);
|
||||
OP63d(18, ppc_fdiv);
|
||||
OP63d(20, ppc_fsub);
|
||||
OP63d(21, ppc_fadd);
|
||||
if (ppc_state.spr[SPR::PVR] == PPC_VER::MPC970MP) OP63d(22, ppc_fsqrt);
|
||||
if (!is_601) OP63d(26, ppc_frsqrte);
|
||||
OP63(32, ppc_fcmpo);
|
||||
OP63d(38, ppc_mtfsb1);
|
||||
OP63d(40, ppc_fneg);
|
||||
OP63(64, ppc_mcrfs);
|
||||
OP63d(70, ppc_mtfsb0);
|
||||
OP63d(72, ppc_fmr);
|
||||
OP63d(134, ppc_mtfsfi);
|
||||
OP63d(136, ppc_fnabs);
|
||||
OP63d(264, ppc_fabs);
|
||||
if (is_601) OP63dc(583, ppc_mffs, IS601); else OP63dc(583, ppc_mffs, NOT601);
|
||||
OP63d(711, ppc_mtfsf);
|
||||
|
||||
for (int i = 0; i < 1024; i += 32) {
|
||||
if (!is_601) OP63d(i + 23, ppc_fsel);
|
||||
OP63d(i + 25, ppc_fmul);
|
||||
OP63d(i + 28, ppc_fmsub);
|
||||
OP63d(i + 29, ppc_fmadd);
|
||||
OP63d(i + 30, ppc_fnmsub);
|
||||
OP63d(i + 31, ppc_fnmadd);
|
||||
}
|
||||
#include "ppcopcodes.include"
|
||||
#include "poweropcodes.include"
|
||||
#include "ppcfpopcodes.include"
|
||||
}
|
||||
|
||||
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601, uint64_t tb_freq)
|
||||
{
|
||||
int i;
|
||||
|
||||
mem_ctrl_instance = mem_ctrl;
|
||||
|
||||
std::memset(&ppc_state, 0, sizeof(ppc_state));
|
||||
@@ -864,8 +708,7 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601,
|
||||
#ifdef __APPLE__
|
||||
mach_timebase_info(&timebase_info);
|
||||
#endif
|
||||
g_nanoseconds_base = now_ns();
|
||||
g_icycles_base = 0;
|
||||
g_nanoseconds_base = cpu_now_ns();
|
||||
g_icycles = 0;
|
||||
//icnt_factor = 6;
|
||||
icnt_factor = 4;
|
||||
@@ -902,8 +745,9 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, bool include_601,
|
||||
}
|
||||
|
||||
void print_fprs() {
|
||||
for (int i = 0; i < 32; i++)
|
||||
for (int i = 0; i < 32; i++) {
|
||||
cout << "FPR " << dec << i << " : " << ppc_state.fpr[i].dbl64_r << endl;
|
||||
}
|
||||
}
|
||||
|
||||
static map<string, int> SPRName2Num = {
|
||||
@@ -926,7 +770,7 @@ static map<string, int> SPRName2Num = {
|
||||
{"SDA", SPR::SDA}, {"SIA", SPR::SIA}, {"MMCR1", SPR::MMCR1}
|
||||
};
|
||||
|
||||
uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
|
||||
static uint64_t reg_op(string& reg_name, uint64_t val, bool is_write) {
|
||||
string reg_name_u, reg_num_str;
|
||||
unsigned reg_num;
|
||||
map<string, int>::iterator spr;
|
||||
|
||||
+26
-825
@@ -22,7 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// The floating point opcodes for the processor - ppcfpopcodes.cpp
|
||||
|
||||
#include "ppcemu.h"
|
||||
#include "ppcmacros.h"
|
||||
#include "ppcdecodemacros.h"
|
||||
#include "ppcmmu.h"
|
||||
#include <stdlib.h>
|
||||
#include <cfenv>
|
||||
@@ -103,14 +103,20 @@ inline static void snan_double_check(int reg_a, int reg_b) {
|
||||
ppc_state.fpscr |= FX | VX | VXSNAN;
|
||||
}
|
||||
|
||||
inline static void max_double_check(double value_a, double value_b) {
|
||||
if (((value_a == DBL_MAX) && (value_b == DBL_MAX)) ||
|
||||
((value_a == -DBL_MAX) && (value_b == -DBL_MAX)))
|
||||
ppc_state.fpscr |= FX | OX | XX | FI;
|
||||
}
|
||||
|
||||
inline static bool check_qnan(int check_reg) {
|
||||
uint64_t check_int = ppc_state.fpr[check_reg].int64_r;
|
||||
return (((check_int & (0x7FFULL << 52)) == (0x7FFULL << 52)) &&
|
||||
((check_int & ~(0xFFFULL << 52)) == 0ULL) &&
|
||||
((check_int & ~(0xFFFULL << 52)) == 0ULL) &&
|
||||
((check_int & (0x1ULL << 51)) == (0x1ULL << 51)));
|
||||
}
|
||||
|
||||
static void fpresult_update(double set_result) {
|
||||
inline static void fpresult_update(double set_result) {
|
||||
if (std::isnan(set_result)) {
|
||||
ppc_state.fpscr |= FPCC_FUNAN | FPRCD;
|
||||
} else {
|
||||
@@ -122,12 +128,16 @@ static void fpresult_update(double set_result) {
|
||||
ppc_state.fpscr |= FPCC_ZERO;
|
||||
}
|
||||
|
||||
if (std::fetestexcept(FE_INEXACT)) {
|
||||
ppc_state.fpscr |= XX;
|
||||
}
|
||||
|
||||
if (std::isinf(set_result))
|
||||
ppc_state.fpscr |= FPCC_FUNAN;
|
||||
}
|
||||
}
|
||||
|
||||
static void ppc_update_vx() {
|
||||
inline static void ppc_update_vx() {
|
||||
uint32_t fpscr_check = ppc_state.fpscr & 0x1F80700U;
|
||||
if (fpscr_check)
|
||||
ppc_state.fpscr |= VX;
|
||||
@@ -135,8 +145,8 @@ static void ppc_update_vx() {
|
||||
ppc_state.fpscr &= ~VX;
|
||||
}
|
||||
|
||||
static void ppc_update_fex() {
|
||||
uint32_t fpscr_check = (((ppc_state.fpscr >> 25) & 0x1F) &
|
||||
inline static void ppc_update_fex() {
|
||||
uint32_t fpscr_check = (((ppc_state.fpscr >> 25) & 0x1F) &
|
||||
((ppc_state.fpscr >> 3) & 0x1F));
|
||||
|
||||
if (fpscr_check)
|
||||
@@ -145,473 +155,30 @@ static void ppc_update_fex() {
|
||||
ppc_state.fpscr &= ~VX;
|
||||
}
|
||||
|
||||
// Floating Point Arithmetic
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fadd() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a + val_reg_b;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fadd<RC0>();
|
||||
template void dppc_interpreter::ppc_fadd<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fsub() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a - val_reg_b;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fsub<RC0>();
|
||||
template void dppc_interpreter::ppc_fsub<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fdiv() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a / val_reg_b;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fdiv<RC0>();
|
||||
template void dppc_interpreter::ppc_fdiv<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmul() {
|
||||
ppc_grab_regsfpdac(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a * val_reg_c;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmul<RC0>();
|
||||
template void dppc_interpreter::ppc_fmul<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmadd() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmadd<RC0>();
|
||||
template void dppc_interpreter::ppc_fmadd<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmsub() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmsub<RC0>();
|
||||
template void dppc_interpreter::ppc_fmsub<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fnmadd() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fnmadd<RC0>();
|
||||
template void dppc_interpreter::ppc_fnmadd<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fnmsub() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fnmsub<RC0>();
|
||||
template void dppc_interpreter::ppc_fnmsub<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fadds() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a + val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fadds<RC0>();
|
||||
template void dppc_interpreter::ppc_fadds<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fsubs() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fsubs<RC0>();
|
||||
template void dppc_interpreter::ppc_fsubs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fdivs() {
|
||||
ppc_grab_regsfpdab(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fdivs<RC0>();
|
||||
template void dppc_interpreter::ppc_fdivs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmuls() {
|
||||
ppc_grab_regsfpdac(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a * val_reg_c);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmuls<RC0>();
|
||||
template void dppc_interpreter::ppc_fmuls<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmadds() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmadds<RC0>();
|
||||
template void dppc_interpreter::ppc_fmadds<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmsubs() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmsubs<RC0>();
|
||||
template void dppc_interpreter::ppc_fmsubs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fnmadds() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fnmadds<RC0>();
|
||||
template void dppc_interpreter::ppc_fnmadds<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fnmsubs() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fnmsubs<RC0>();
|
||||
template void dppc_interpreter::ppc_fnmsubs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fabs() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fabs<RC0>();
|
||||
template void dppc_interpreter::ppc_fabs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fnabs() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
||||
ppc_dblresult64_d = -ppc_dblresult64_d;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fnabs<RC0>();
|
||||
template void dppc_interpreter::ppc_fnabs<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fneg() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(GET_FPR(reg_b));
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fneg<RC0>();
|
||||
template void dppc_interpreter::ppc_fneg<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fsel() {
|
||||
ppc_grab_regsfpdabc(ppc_cur_instruction);
|
||||
|
||||
double ppc_dblresult64_d = (val_reg_a >= -0.0) ? val_reg_c : val_reg_b;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fsel<RC0>();
|
||||
template void dppc_interpreter::ppc_fsel<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fsqrt() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = std::sqrt(testd2);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fsqrt<RC0>();
|
||||
template void dppc_interpreter::ppc_fsqrt<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fsqrts() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = (float)std::sqrt(testd2);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fsqrts<RC0>();
|
||||
template void dppc_interpreter::ppc_fsqrts<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_frsqrte() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = 1.0 / sqrt(testd2);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_frsqrte<RC0>();
|
||||
template void dppc_interpreter::ppc_frsqrte<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_frsp() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(GET_FPR(reg_b));
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_frsp<RC0>();
|
||||
template void dppc_interpreter::ppc_frsp<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fres() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double start_num = GET_FPR(reg_b);
|
||||
double ppc_dblresult64_d = (float)(1.0 / start_num);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (start_num == 0.0) {
|
||||
ppc_state.fpscr |= FPSCR::ZX;
|
||||
}
|
||||
else if (std::isnan(start_num)) {
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
}
|
||||
else if (std::isinf(start_num)){
|
||||
ppc_state.fpscr &= 0xFFF9FFFF;
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fres<RC0>();
|
||||
template void dppc_interpreter::ppc_fres<RC1>();
|
||||
|
||||
static void round_to_int(const uint8_t mode, field_rc rec) {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
inline static void round_to_int(uint32_t instr, const uint8_t mode, field_rc rec) {
|
||||
ppc_grab_regsfpdb(instr);
|
||||
double val_reg_b = GET_FPR(reg_b);
|
||||
|
||||
if (std::isnan(val_reg_b)) {
|
||||
ppc_state.fpscr &= ~(FPSCR::FR | FPSCR::FI);
|
||||
ppc_state.fpscr |= (FPSCR::VXCVI | FPSCR::VX);
|
||||
|
||||
if (check_snan(reg_b)) // issnan
|
||||
if (check_snan(reg_b)) // issnan
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
|
||||
if (ppc_state.fpscr & FPSCR::VE) {
|
||||
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
|
||||
ppc_floating_point_exception();
|
||||
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
|
||||
ppc_floating_point_exception(instr);
|
||||
} else {
|
||||
ppc_state.fpr[reg_d].int64_r = 0xFFF8000080000000ULL;
|
||||
}
|
||||
} else if (val_reg_b > static_cast<double>(0x7fffffff) ||
|
||||
val_reg_b < -static_cast<double>(0x80000000)) {
|
||||
} else if (val_reg_b > static_cast<double>(0x7fffffff) || val_reg_b < -static_cast<double>(0x80000000)) {
|
||||
ppc_state.fpscr &= ~(FPSCR::FR | FPSCR::FI);
|
||||
ppc_state.fpscr |= (FPSCR::VXCVI | FPSCR::VX);
|
||||
|
||||
if (ppc_state.fpscr & FPSCR::VE) {
|
||||
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
|
||||
ppc_floating_point_exception();
|
||||
ppc_state.fpscr |= FPSCR::FEX; // VX=1 and VE=1 cause FEX to be set
|
||||
ppc_floating_point_exception(instr);
|
||||
} else {
|
||||
if (val_reg_b >= 0.0f)
|
||||
ppc_state.fpr[reg_d].int64_r = 0xFFF800007FFFFFFFULL;
|
||||
@@ -644,371 +211,5 @@ static void round_to_int(const uint8_t mode, field_rc rec) {
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fctiw() {
|
||||
round_to_int(ppc_state.fpscr & 0x3, rec);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fctiw<RC0>();
|
||||
template void dppc_interpreter::ppc_fctiw<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fctiwz() {
|
||||
round_to_int(1, rec);
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fctiwz<RC0>();
|
||||
template void dppc_interpreter::ppc_fctiwz<RC1>();
|
||||
|
||||
// Floating Point Store and Load
|
||||
|
||||
void dppc_interpreter::ppc_lfs() {
|
||||
ppc_grab_regsfpdia(ppc_cur_instruction);
|
||||
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
||||
ppc_effective_address += (reg_a) ? val_reg_a : 0;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfsu() {
|
||||
ppc_grab_regsfpdia(ppc_cur_instruction);
|
||||
if (reg_a) {
|
||||
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
||||
ppc_effective_address += (reg_a) ? val_reg_a : 0;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfsx() {
|
||||
ppc_grab_regsfpdiab(ppc_cur_instruction);
|
||||
ppc_effective_address = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfsux() {
|
||||
ppc_grab_regsfpdiab(ppc_cur_instruction);
|
||||
if (reg_a) {
|
||||
ppc_effective_address = val_reg_a + val_reg_b;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfd() {
|
||||
ppc_grab_regsfpdia(ppc_cur_instruction);
|
||||
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
||||
ppc_effective_address += (reg_a) ? val_reg_a : 0;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfdu() {
|
||||
ppc_grab_regsfpdia(ppc_cur_instruction);
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
||||
ppc_effective_address += val_reg_a;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfdx() {
|
||||
ppc_grab_regsfpdiab(ppc_cur_instruction);
|
||||
ppc_effective_address = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_lfdux() {
|
||||
ppc_grab_regsfpdiab(ppc_cur_instruction);
|
||||
if (reg_a) {
|
||||
ppc_effective_address = val_reg_a + val_reg_b;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ppc_effective_address);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfs() {
|
||||
ppc_grab_regsfpsia(ppc_cur_instruction);
|
||||
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
||||
ppc_effective_address += (reg_a) ? val_reg_a : 0;
|
||||
float result = ppc_state.fpr[reg_s].dbl64_r;
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, *(uint32_t*)(&result));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfsu() {
|
||||
ppc_grab_regsfpsia(ppc_cur_instruction);
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
||||
ppc_effective_address += val_reg_a;
|
||||
float result = ppc_state.fpr[reg_s].dbl64_r;
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, *(uint32_t*)(&result));
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfsx() {
|
||||
ppc_grab_regsfpsiab(ppc_cur_instruction);
|
||||
ppc_effective_address = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
float result = ppc_state.fpr[reg_s].dbl64_r;
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, *(uint32_t*)(&result));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfsux() {
|
||||
ppc_grab_regsfpsiab(ppc_cur_instruction);
|
||||
if (reg_a) {
|
||||
ppc_effective_address = val_reg_a + val_reg_b;
|
||||
float result = ppc_state.fpr[reg_s].dbl64_r;
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, *(uint32_t*)(&result));
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfd() {
|
||||
ppc_grab_regsfpsia(ppc_cur_instruction);
|
||||
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
||||
ppc_effective_address += reg_a ? val_reg_a : 0;
|
||||
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfdu() {
|
||||
ppc_grab_regsfpsia(ppc_cur_instruction);
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = int32_t(int16_t(ppc_cur_instruction));
|
||||
ppc_effective_address += val_reg_a;
|
||||
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfdx() {
|
||||
ppc_grab_regsfpsiab(ppc_cur_instruction);
|
||||
ppc_effective_address = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfdux() {
|
||||
ppc_grab_regsfpsiab(ppc_cur_instruction);
|
||||
if (reg_a != 0) {
|
||||
ppc_effective_address = val_reg_a + val_reg_b;
|
||||
mmu_write_vmem<uint64_t>(ppc_effective_address, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_state.gpr[reg_a] = ppc_effective_address;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_stfiwx() {
|
||||
ppc_grab_regsfpsiab(ppc_cur_instruction);
|
||||
ppc_effective_address = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
mmu_write_vmem<uint32_t>(ppc_effective_address, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
||||
}
|
||||
|
||||
// Floating Point Register Transfer
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_fmr() {
|
||||
ppc_grab_regsfpdb(ppc_cur_instruction);
|
||||
ppc_state.fpr[reg_d].dbl64_r = ppc_state.fpr[reg_b].dbl64_r;
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_fmr<RC0>();
|
||||
template void dppc_interpreter::ppc_fmr<RC1>();
|
||||
|
||||
template <field_601 for601, field_rc rec>
|
||||
void dppc_interpreter::ppc_mffs() {
|
||||
int reg_d = (ppc_cur_instruction >> 21) & 31;
|
||||
|
||||
ppc_state.fpr[reg_d].int64_r = uint64_t(ppc_state.fpscr) | (for601 ? 0xFFFFFFFF00000000ULL : 0xFFF8000000000000ULL);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_mffs<NOT601, RC0>();
|
||||
template void dppc_interpreter::ppc_mffs<NOT601, RC1>();
|
||||
template void dppc_interpreter::ppc_mffs<IS601, RC0>();
|
||||
template void dppc_interpreter::ppc_mffs<IS601, RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_mtfsf() {
|
||||
int reg_b = (ppc_cur_instruction >> 11) & 0x1F;
|
||||
uint8_t fm = (ppc_cur_instruction >> 17) & 0xFF;
|
||||
|
||||
uint32_t cr_mask = 0;
|
||||
|
||||
if (fm == 0xFFU) // the fast case
|
||||
cr_mask = 0xFFFFFFFFUL;
|
||||
else { // the slow case
|
||||
if (fm & 0x80) cr_mask |= 0xF0000000UL;
|
||||
if (fm & 0x40) cr_mask |= 0x0F000000UL;
|
||||
if (fm & 0x20) cr_mask |= 0x00F00000UL;
|
||||
if (fm & 0x10) cr_mask |= 0x000F0000UL;
|
||||
if (fm & 0x08) cr_mask |= 0x0000F000UL;
|
||||
if (fm & 0x04) cr_mask |= 0x00000F00UL;
|
||||
if (fm & 0x02) cr_mask |= 0x000000F0UL;
|
||||
if (fm & 0x01) cr_mask |= 0x0000000FUL;
|
||||
}
|
||||
|
||||
// ensure neither FEX nor VX will be changed
|
||||
cr_mask &= ~(FPSCR::FEX | FPSCR::VX);
|
||||
|
||||
// copy FPR[reg_b] to FPSCR under control of cr_mask
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~cr_mask) | (ppc_state.fpr[reg_b].int64_r & cr_mask);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_mtfsf<RC0>();
|
||||
template void dppc_interpreter::ppc_mtfsf<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_mtfsfi() {
|
||||
int crf_d = (ppc_cur_instruction >> 21) & 0x1C;
|
||||
uint32_t imm = (ppc_cur_instruction << 16) & 0xF0000000UL;
|
||||
|
||||
// prepare field mask and ensure that neither FEX nor VX will be changed
|
||||
uint32_t mask = (0xF0000000UL >> crf_d) & ~(FPSCR::FEX | FPSCR::VX);
|
||||
|
||||
// copy imm to FPSCR[crf_d] under control of the field mask
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~mask) | ((imm >> crf_d) & mask);
|
||||
|
||||
// Update FEX and VX according to the "usual rule"
|
||||
ppc_update_vx();
|
||||
ppc_update_fex();
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_mtfsfi<RC0>();
|
||||
template void dppc_interpreter::ppc_mtfsfi<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_mtfsb0() {
|
||||
int crf_d = (ppc_cur_instruction >> 21) & 0x1F;
|
||||
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly cleared
|
||||
ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_mtfsb0<RC0>();
|
||||
template void dppc_interpreter::ppc_mtfsb0<RC1>();
|
||||
|
||||
template <field_rc rec>
|
||||
void dppc_interpreter::ppc_mtfsb1() {
|
||||
int crf_d = (ppc_cur_instruction >> 21) & 0x1F;
|
||||
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly set
|
||||
ppc_state.fpscr |= (0x80000000UL >> crf_d);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
}
|
||||
|
||||
template void dppc_interpreter::ppc_mtfsb1<RC0>();
|
||||
template void dppc_interpreter::ppc_mtfsb1<RC1>();
|
||||
|
||||
void dppc_interpreter::ppc_mcrfs() {
|
||||
int crf_d = (ppc_cur_instruction >> 21) & 0x1C;
|
||||
int crf_s = (ppc_cur_instruction >> 16) & 0x1C;
|
||||
ppc_state.cr = (
|
||||
(ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
|
||||
(((ppc_state.fpscr << crf_s) & 0xF0000000UL) >> crf_d)
|
||||
);
|
||||
ppc_state.fpscr &= ~((0xF0000000UL >> crf_s) & (
|
||||
// keep only the FPSCR bits that can be explicitly cleared
|
||||
FPSCR::FX | FPSCR::OX |
|
||||
FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
|
||||
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ |
|
||||
FPSCR::VXVC |
|
||||
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI
|
||||
));
|
||||
}
|
||||
|
||||
// Floating Point Comparisons
|
||||
|
||||
void dppc_interpreter::ppc_fcmpo() {
|
||||
ppc_grab_regsfpsab(ppc_cur_instruction);
|
||||
|
||||
uint32_t cmp_c = 0;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= CRx_bit::CR_SO;
|
||||
ppc_state.fpscr |= FX | VX;
|
||||
if (check_snan(reg_a) || check_snan(reg_b)) {
|
||||
ppc_state.fpscr |= VXSNAN;
|
||||
}
|
||||
if (!(ppc_state.fpscr & FEX) || check_qnan(reg_a) || check_qnan(reg_b)) {
|
||||
ppc_state.fpscr |= VXVC;
|
||||
}
|
||||
}
|
||||
else if (db_test_a < db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_LT;
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_GT;
|
||||
}
|
||||
else {
|
||||
cmp_c |= CRx_bit::CR_EQ;
|
||||
}
|
||||
|
||||
ppc_state.fpscr &= ~VE; //kludge to pass tests
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | (cmp_c >> crf_d));
|
||||
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_fcmpu() {
|
||||
ppc_grab_regsfpsab(ppc_cur_instruction);
|
||||
|
||||
uint32_t cmp_c = 0;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= CRx_bit::CR_SO;
|
||||
if (check_snan(reg_a) || check_snan(reg_b)) {
|
||||
ppc_state.fpscr |= FX | VX | VXSNAN;
|
||||
}
|
||||
}
|
||||
else if (db_test_a < db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_LT;
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_GT;
|
||||
}
|
||||
else {
|
||||
cmp_c |= CRx_bit::CR_EQ;
|
||||
}
|
||||
|
||||
ppc_state.fpscr &= ~VE; //kludge to pass tests
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000UL >> crf_d)) | (cmp_c >> crf_d));
|
||||
|
||||
}
|
||||
#include "ppcopmacros.h"
|
||||
#include "ppcfpopcodes.include"
|
||||
@@ -0,0 +1,681 @@
|
||||
// Floating Point Arithmetic
|
||||
OPCODEREC (fadd, 63, 21,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
max_double_check(val_reg_a, val_reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a + val_reg_b;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
ppc_update_fex();
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fsub, 63, 20,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a - val_reg_b;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fdiv, 63, 18,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a / val_reg_b;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fmul, 63, 25,
|
||||
ppc_grab_regsfpdac(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
|
||||
double ppc_dblresult64_d = val_reg_a * val_reg_c;
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fmadd, 63, 29,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fmsub, 63, 28,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fnmadd, 63, 31,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF (fnmsub, 63, 30,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fadds, 59, 21,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a + val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fsubs, 59, 20,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a - val_reg_b);
|
||||
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fdivs, 59, 18,
|
||||
ppc_grab_regsfpdab(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a / val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fmuls, 59, 25,
|
||||
ppc_grab_regsfpdac(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
|
||||
double ppc_dblresult64_d = (float)(val_reg_a * val_reg_c);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fmadds, 59, 29,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fmsubs, 59, 28,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fnmadds, 59, 31,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fnmsubs, 59, 30,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
snan_double_check(reg_a, reg_c);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(float)std::fma(val_reg_a, val_reg_c, -val_reg_b);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
fpresult_update(ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fabs, 63, 264,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fnabs, 63, 136,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = abs(GET_FPR(reg_b));
|
||||
ppc_dblresult64_d = -ppc_dblresult64_d;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fneg, 63, 40,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = -(GET_FPR(reg_b));
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODERECF(fsel, 63, 23,
|
||||
ppc_grab_regsfpdabc(instr);
|
||||
|
||||
double ppc_dblresult64_d = (val_reg_a >= -0.0) ? val_reg_c : val_reg_b;
|
||||
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fsqrt, 63, 22,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = std::sqrt(testd2);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC(fsqrts, 59, 22,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = (float)std::sqrt(testd2);
|
||||
ppc_store_sfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (frsqrte, 63, 26,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double testd2 = (double)(GET_FPR(reg_b));
|
||||
double ppc_dblresult64_d = 1.0 / sqrt(testd2);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (frsp, 63, 12,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double ppc_dblresult64_d = (float)(GET_FPR(reg_b));
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fres, 63, 24,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
|
||||
snan_single_check(reg_b);
|
||||
|
||||
double start_num = GET_FPR(reg_b);
|
||||
double ppc_dblresult64_d = (float)(1.0 / start_num);
|
||||
ppc_store_dfpresult_flt(reg_d, ppc_dblresult64_d);
|
||||
|
||||
if (start_num == 0.0) {
|
||||
ppc_state.fpscr |= FPSCR::ZX;
|
||||
}
|
||||
else if (std::isnan(start_num)) {
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
}
|
||||
else if (std::isinf(start_num)){
|
||||
ppc_state.fpscr &= 0xFFF9FFFF;
|
||||
ppc_state.fpscr |= FPSCR::VXSNAN;
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (fctiw, 63, 14,
|
||||
round_to_int(instr, ppc_state.fpscr & 0x3, rec);
|
||||
)
|
||||
|
||||
OPCODEREC (fctiwz, 63, 15,
|
||||
round_to_int(instr, 1, rec);
|
||||
)
|
||||
|
||||
// Floating Point Store and Load
|
||||
|
||||
OPCODE (lfs, , 48,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
)
|
||||
|
||||
OPCODE (lfsu, , 49,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (lfsx, 31, 535,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
)
|
||||
|
||||
OPCODE31 (lfsux, 31, 567,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
uint32_t result = mmu_read_vmem<uint32_t>(ea, instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = *(float*)(&result);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE (lfd, , 50,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
)
|
||||
|
||||
OPCODE (lfdu, , 51,
|
||||
ppc_grab_regsfpdia(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += val_reg_a;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (lfdx, 31, 599,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
)
|
||||
|
||||
OPCODE31 (lfdux, 31, 631,
|
||||
ppc_grab_regsfpdiab(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
uint64_t ppc_result64_d = mmu_read_vmem<uint64_t>(ea, instr);
|
||||
ppc_store_dfpresult_int(reg_d, ppc_result64_d);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE (stfs, , 52,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += (reg_a) ? val_reg_a : 0;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
)
|
||||
|
||||
OPCODE (stfsu, , 53,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += val_reg_a;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (stfsx, 31, 663,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
)
|
||||
|
||||
OPCODE31 (stfsux, 31, 695,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
if (reg_a) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
float result = float(ppc_state.fpr[reg_s].dbl64_r);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, *(uint32_t*)(&result));
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE (stfd, , 54,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += reg_a ? val_reg_a : 0;
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
)
|
||||
|
||||
OPCODE (stfdu, , 55,
|
||||
ppc_grab_regsfpsia(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = int32_t(int16_t(instr));
|
||||
ea += val_reg_a;
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (stfdx, 31, 727,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
)
|
||||
|
||||
OPCODE31 (stfdux, 31, 759,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
if (reg_a != 0) {
|
||||
uint32_t ea = val_reg_a + val_reg_b;
|
||||
mmu_write_vmem<uint64_t>(ea, instr, ppc_state.fpr[reg_s].int64_r);
|
||||
ppc_state.gpr[reg_a] = ea;
|
||||
} else {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::ILLEGAL_OP);
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (stfiwx, 31, 983,
|
||||
ppc_grab_regsfpsiab(instr);
|
||||
uint32_t ea = val_reg_b + (reg_a ? val_reg_a : 0);
|
||||
mmu_write_vmem<uint32_t>(ea, instr, uint32_t(ppc_state.fpr[reg_s].int64_r));
|
||||
)
|
||||
|
||||
// Floating Point Register Transfer
|
||||
|
||||
OPCODEREC (fmr, 63, 72,
|
||||
ppc_grab_regsfpdb(instr);
|
||||
ppc_state.fpr[reg_d].dbl64_r = ppc_state.fpr[reg_b].dbl64_r;
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODE601REC (mffs, 63, 583,
|
||||
int reg_d = (instr >> 21) & 31;
|
||||
|
||||
ppc_state.fpr[reg_d].int64_r = uint64_t(ppc_state.fpscr) | (for601 ? 0xFFFFFFFF00000000ULL : 0xFFF8000000000000ULL);
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODEREC (mtfsf, 63, 711,
|
||||
ppc_grab_mtfsf(instr);
|
||||
|
||||
uint32_t cr_mask = 0;
|
||||
|
||||
if (fm == 0xFFU) { // the fast case
|
||||
cr_mask = 0xFFFFFFFFUL;
|
||||
}
|
||||
else { // the slow case
|
||||
if (fm & 0x80) cr_mask |= 0xF0000000UL;
|
||||
if (fm & 0x40) cr_mask |= 0x0F000000UL;
|
||||
if (fm & 0x20) cr_mask |= 0x00F00000UL;
|
||||
if (fm & 0x10) cr_mask |= 0x000F0000UL;
|
||||
if (fm & 0x08) cr_mask |= 0x0000F000UL;
|
||||
if (fm & 0x04) cr_mask |= 0x00000F00UL;
|
||||
if (fm & 0x02) cr_mask |= 0x000000F0UL;
|
||||
if (fm & 0x01) cr_mask |= 0x0000000FUL;
|
||||
}
|
||||
|
||||
// ensure neither FEX nor VX will be changed
|
||||
cr_mask &= ~(FPSCR::FEX | FPSCR::VX);
|
||||
|
||||
// copy FPR[reg_b] to FPSCR under control of cr_mask
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~cr_mask) | (ppc_state.fpr[reg_b].int64_r & cr_mask);
|
||||
|
||||
if (rec) {
|
||||
ppc_update_cr1();
|
||||
}
|
||||
)
|
||||
|
||||
OPCODEREC (mtfsfi, 63, 134,
|
||||
ppc_grab_mtfsfi(instr);
|
||||
|
||||
// prepare field mask and ensure that neither FEX nor VX will be changed
|
||||
uint32_t mask = (0xF0000000UL >> crf_d) & ~(FPSCR::FEX | FPSCR::VX);
|
||||
|
||||
// copy imm to FPSCR[crf_d] under control of the field mask
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~mask) | ((imm >> crf_d) & mask);
|
||||
|
||||
// Update FEX and VX according to the "usual rule"
|
||||
ppc_update_vx();
|
||||
ppc_update_fex();
|
||||
|
||||
if (rec) {
|
||||
ppc_update_cr1();
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (mtfsb0, 63, 70,
|
||||
int crf_d = (instr >> 21) & 0x1F;
|
||||
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly cleared
|
||||
ppc_state.fpscr &= ~(0x80000000UL >> crf_d);
|
||||
}
|
||||
|
||||
if (rec)
|
||||
ppc_update_cr1();
|
||||
)
|
||||
|
||||
OPCODE31 (mtfsb1, 63, 38,
|
||||
ppc_grab_crfd(instr);
|
||||
if (!crf_d || (crf_d > 2)) { // FEX and VX can't be explicitly set
|
||||
ppc_state.fpscr |= (0x80000000UL >> crf_d);
|
||||
}
|
||||
|
||||
if (rec) {
|
||||
ppc_update_cr1();
|
||||
}
|
||||
)
|
||||
|
||||
OPCODE31 (mcrfs, 63, 64,
|
||||
ppc_grab_crfds(instr);
|
||||
ppc_state.cr = (
|
||||
(ppc_state.cr & ~(0xF0000000UL >> crf_d)) |
|
||||
(((ppc_state.fpscr << crf_s) & 0xF0000000UL) >> crf_d)
|
||||
);
|
||||
ppc_state.fpscr &= ~((0xF0000000UL >> crf_s) & (
|
||||
// keep only the FPSCR bits that can be explicitly cleared
|
||||
FPSCR::FX | FPSCR::OX |
|
||||
FPSCR::UX | FPSCR::ZX | FPSCR::XX | FPSCR::VXSNAN |
|
||||
FPSCR::VXISI | FPSCR::VXIDI | FPSCR::VXZDZ | FPSCR::VXIMZ |
|
||||
FPSCR::VXVC |
|
||||
FPSCR::VXSOFT | FPSCR::VXSQRT | FPSCR::VXCVI
|
||||
));
|
||||
)
|
||||
|
||||
// Floating Point Comparisons
|
||||
|
||||
OPCODE31 (fcmpo, 63, 32,
|
||||
ppc_grab_regsfpsab(instr);
|
||||
|
||||
uint32_t cmp_c = 0;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= CRx_bit::CR_SO;
|
||||
ppc_state.fpscr |= FX | VX;
|
||||
if (check_snan(reg_a) || check_snan(reg_b)) {
|
||||
ppc_state.fpscr |= VXSNAN;
|
||||
}
|
||||
if (!(ppc_state.fpscr & FEX) || check_qnan(reg_a) || check_qnan(reg_b)) {
|
||||
ppc_state.fpscr |= VXVC;
|
||||
}
|
||||
}
|
||||
else if (db_test_a < db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_LT;
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_GT;
|
||||
}
|
||||
else {
|
||||
cmp_c |= CRx_bit::CR_EQ;
|
||||
}
|
||||
|
||||
ppc_state.fpscr &= ~VE; //kludge to pass tests
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000 >> crf_d)) | (cmp_c >> crf_d));
|
||||
|
||||
)
|
||||
|
||||
OPCODE (fcmpu, 63, 0,
|
||||
ppc_grab_regsfpsab(instr);
|
||||
|
||||
uint32_t cmp_c = 0;
|
||||
|
||||
if (std::isnan(db_test_a) || std::isnan(db_test_b)) {
|
||||
cmp_c |= CRx_bit::CR_SO;
|
||||
if (check_snan(reg_a) || check_snan(reg_b)) {
|
||||
ppc_state.fpscr |= FX | VX | VXSNAN;
|
||||
}
|
||||
}
|
||||
else if (db_test_a < db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_LT;
|
||||
}
|
||||
else if (db_test_a > db_test_b) {
|
||||
cmp_c |= CRx_bit::CR_GT;
|
||||
}
|
||||
else {
|
||||
cmp_c |= CRx_bit::CR_EQ;
|
||||
}
|
||||
|
||||
ppc_state.fpscr &= ~VE; //kludge to pass tests
|
||||
ppc_state.fpscr = (ppc_state.fpscr & ~FPSCR::FPCC_MASK) | (cmp_c >> 16); // update FPCC
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xF0000000UL >> crf_d)) | (cmp_c >> crf_d));
|
||||
|
||||
)
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 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/>.
|
||||
*/
|
||||
|
||||
#undef OPCODE
|
||||
#define OPCODE(op, grabber, number, ...) \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODE31
|
||||
#define OPCODE31(op, grabber, number, ...) \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODE
|
||||
#define POWEROPCODE(op, grabber, number, ...) \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODE31
|
||||
#define POWEROPCODE31(op, grabber, number, ...) \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODESHIFT
|
||||
#define OPCODESHIFT(op, grabber, number, ...) \
|
||||
template <field_shift shift> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODESHIFTREC
|
||||
#define OPCODESHIFTREC(op, grabber, number, ...) \
|
||||
template <field_direction isleft, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEOVREC
|
||||
#define OPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEEXTSIGN
|
||||
#define OPCODEEXTSIGN(op, grabber, number, ...) \
|
||||
template <class T, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODEOVREC
|
||||
#define POWEROPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEREC
|
||||
#define OPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODERECF
|
||||
#define OPCODERECF(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODEREC
|
||||
#define POWEROPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void power_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODELOGIC
|
||||
#define OPCODELOGIC(op, grabber, number, ...) \
|
||||
template <logical_fun logical_op, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODELKAA
|
||||
#define OPCODELKAA(op, grabber, number, ...) \
|
||||
template <field_lk l, field_aa a> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEM
|
||||
#define OPCODEMEM(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEMINDEXED
|
||||
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODE601REC
|
||||
#define OPCODE601REC(op, grabber, number, ...) \
|
||||
template <field_601 for601, field_rc rec> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODE601L
|
||||
#define OPCODE601L(op, grabber, number, ...) \
|
||||
template <field_lk l, field_601 for601> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
|
||||
#undef OPCODEL
|
||||
#define OPCODEL(op, grabber, number, ...) \
|
||||
template <field_lk l> \
|
||||
void ppc_##op(uint32_t instr);
|
||||
+54
-48
@@ -137,19 +137,19 @@ static BATResult ppc_block_address_translation(uint32_t la)
|
||||
PPC_BAT_entry *bat_array;
|
||||
|
||||
bool bat_hit = false;
|
||||
unsigned msr_pr = !!(ppc_state.msr & MSR::PR);
|
||||
unsigned msr_pr = (ppc_state.msr & MSR::PR) != 0;
|
||||
|
||||
bat_array = (type == BATType::IBAT) ? ibat_array : dbat_array;
|
||||
|
||||
// Format: %XY
|
||||
// X - supervisor access bit, Y - problem/user access bit
|
||||
// Those bits are mutually exclusive
|
||||
unsigned access_bits = ((msr_pr ^ 1) << 1) | msr_pr;
|
||||
unsigned access_bits = ((!msr_pr) << 1) | msr_pr;
|
||||
|
||||
for (int bat_index = 0; bat_index < 4; bat_index++) {
|
||||
PPC_BAT_entry* bat_entry = &bat_array[bat_index];
|
||||
|
||||
if ((bat_entry->access & access_bits) && ((la & bat_entry->hi_mask) == bat_entry->bepi)) {
|
||||
if ((bat_entry->access & access_bits) != 0 && ((la & bat_entry->hi_mask) == bat_entry->bepi)) {
|
||||
bat_hit = true;
|
||||
|
||||
#ifdef MMU_PROFILING
|
||||
@@ -372,7 +372,7 @@ uint32_t tlb_size_mask = TLB_SIZE - 1;
|
||||
|
||||
// fake TLB entry for handling of unmapped memory accesses
|
||||
uint64_t UnmappedVal = -1ULL;
|
||||
TLBEntry UnmappedMem = {TLB_INVALID_TAG, TLBFlags::PAGE_NOPHYS, 0, 0};
|
||||
TLBEntry UnmappedMem = {TLB_INVALID_TAG, TLBFlags::PAGE_NOPHYS, 0, {{0}}};
|
||||
|
||||
uint8_t CurITLBMode = {0xFF}; // current ITLB mode
|
||||
uint8_t CurDTLBMode = {0xFF}; // current DTLB mode
|
||||
@@ -741,7 +741,6 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr)
|
||||
host_va = (uint8_t *)(tlb1_entry->host_va_offs_r + vaddr);
|
||||
}
|
||||
|
||||
ppc_set_cur_instruction(host_va);
|
||||
if (paddr)
|
||||
*paddr = tlb1_entry->phys_tag | (vaddr & 0xFFFUL);
|
||||
|
||||
@@ -797,21 +796,28 @@ static void tlb_flush_entries(std::array<TLBEntry, N> &tlb, TLBFlags type) {
|
||||
template <const TLBType tlb_type>
|
||||
void tlb_flush_entries(TLBFlags type)
|
||||
{
|
||||
TLBEntry *m1_tlb, *m2_tlb, *m3_tlb;
|
||||
int i;
|
||||
|
||||
// Mode 1 is real addressing and thus can't contain any PAT entries by definition.
|
||||
bool flush_mode1 = type != TLBE_FROM_PAT;
|
||||
if (tlb_type == TLBType::ITLB) {
|
||||
tlb_flush_entries(itlb1_mode1, type);
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(itlb1_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(itlb1_mode2, type);
|
||||
tlb_flush_entries(itlb1_mode3, type);
|
||||
tlb_flush_entries(itlb2_mode1, type);
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(itlb2_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(itlb2_mode2, type);
|
||||
tlb_flush_entries(itlb2_mode3, type);
|
||||
} else {
|
||||
tlb_flush_entries(dtlb1_mode1, type);
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(dtlb1_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(dtlb1_mode2, type);
|
||||
tlb_flush_entries(dtlb1_mode3, type);
|
||||
tlb_flush_entries(dtlb2_mode1, type);
|
||||
if (flush_mode1) {
|
||||
tlb_flush_entries(dtlb2_mode1, type);
|
||||
}
|
||||
tlb_flush_entries(dtlb2_mode2, type);
|
||||
tlb_flush_entries(dtlb2_mode3, type);
|
||||
}
|
||||
@@ -978,13 +984,12 @@ void mmu_pat_ctx_changed()
|
||||
|
||||
// Forward declarations.
|
||||
template <class T>
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t *host_va);
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
template <class T>
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value);
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr, T value);
|
||||
|
||||
template <class T>
|
||||
inline T mmu_read_vmem(uint32_t guest_va)
|
||||
{
|
||||
inline T mmu_read_vmem(uint32_t guest_va, uint32_t instr) {
|
||||
TLBEntry *tlb1_entry, *tlb2_entry;
|
||||
uint8_t *host_va;
|
||||
|
||||
@@ -1027,7 +1032,7 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
#endif
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3)
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
|
||||
return (
|
||||
((T)tlb2_entry->rgn_desc->devobj->read(tlb2_entry->rgn_desc->start,
|
||||
@@ -1054,7 +1059,7 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
|
||||
// handle unaligned memory accesses
|
||||
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
|
||||
return read_unaligned<T>(guest_va, host_va);
|
||||
return read_unaligned<T>(guest_va, host_va, instr);
|
||||
}
|
||||
|
||||
// handle aligned memory accesses
|
||||
@@ -1071,14 +1076,13 @@ inline T mmu_read_vmem(uint32_t guest_va)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required mmu_read_vmem variants
|
||||
template uint8_t mmu_read_vmem<uint8_t>(uint32_t guest_va);
|
||||
template uint16_t mmu_read_vmem<uint16_t>(uint32_t guest_va);
|
||||
template uint32_t mmu_read_vmem<uint32_t>(uint32_t guest_va);
|
||||
template uint64_t mmu_read_vmem<uint64_t>(uint32_t guest_va);
|
||||
template uint8_t mmu_read_vmem<uint8_t>(uint32_t guest_va, uint32_t instr);
|
||||
template uint16_t mmu_read_vmem<uint16_t>(uint32_t guest_va, uint32_t instr);
|
||||
template uint32_t mmu_read_vmem<uint32_t>(uint32_t guest_va, uint32_t instr);
|
||||
template uint64_t mmu_read_vmem<uint64_t>(uint32_t guest_va, uint32_t instr);
|
||||
|
||||
template <class T>
|
||||
inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
{
|
||||
inline void mmu_write_vmem(uint32_t guest_va, uint32_t instr, T value) {
|
||||
TLBEntry *tlb1_entry, *tlb2_entry;
|
||||
uint8_t *host_va;
|
||||
|
||||
@@ -1149,7 +1153,7 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
#endif
|
||||
if (sizeof(T) == 8) {
|
||||
if (guest_va & 3)
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
|
||||
tlb2_entry->rgn_desc->devobj->write(tlb2_entry->rgn_desc->start,
|
||||
static_cast<uint32_t>(guest_va - tlb2_entry->dev_base_va),
|
||||
@@ -1172,7 +1176,7 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
|
||||
// handle unaligned memory accesses
|
||||
if (sizeof(T) > 1 && (guest_va & (sizeof(T) - 1))) {
|
||||
write_unaligned<T>(guest_va, host_va, value);
|
||||
write_unaligned<T>(guest_va, host_va, instr, value);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1194,17 +1198,16 @@ inline void mmu_write_vmem(uint32_t guest_va, T value)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required mmu_write_vmem variants
|
||||
template void mmu_write_vmem<uint8_t>(uint32_t guest_va, uint8_t value);
|
||||
template void mmu_write_vmem<uint16_t>(uint32_t guest_va, uint16_t value);
|
||||
template void mmu_write_vmem<uint32_t>(uint32_t guest_va, uint32_t value);
|
||||
template void mmu_write_vmem<uint64_t>(uint32_t guest_va, uint64_t value);
|
||||
template void mmu_write_vmem<uint8_t>(uint32_t guest_va, uint32_t instr, uint8_t value);
|
||||
template void mmu_write_vmem<uint16_t>(uint32_t guest_va, uint32_t instr, uint16_t value);
|
||||
template void mmu_write_vmem<uint32_t>(uint32_t guest_va, uint32_t instr, uint32_t value);
|
||||
template void mmu_write_vmem<uint64_t>(uint32_t guest_va, uint32_t instr, uint64_t value);
|
||||
|
||||
template <class T>
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
{
|
||||
static T read_unaligned(uint32_t guest_va, uint8_t* host_va, uint32_t instr) {
|
||||
if ((sizeof(T) == 8) && (guest_va & 3)) {
|
||||
#ifndef PPC_TESTS
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1219,7 +1222,7 @@ static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
// Because such accesses suffer a performance penalty, they will be
|
||||
// presumably very rare so don't waste time optimizing the code below.
|
||||
for (int i = 0; i < sizeof(T); guest_va++, i++) {
|
||||
result = (result << 8) | mmu_read_vmem<uint8_t>(guest_va);
|
||||
result = (result << 8) | mmu_read_vmem<uint8_t>(guest_va, instr);
|
||||
}
|
||||
} else {
|
||||
#ifdef MMU_PROFILING
|
||||
@@ -1240,16 +1243,16 @@ static T read_unaligned(uint32_t guest_va, uint8_t *host_va)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required read_unaligned variants
|
||||
template uint16_t read_unaligned<uint16_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
template uint32_t read_unaligned<uint32_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
template uint64_t read_unaligned<uint64_t>(uint32_t guest_va, uint8_t *host_va);
|
||||
template uint16_t read_unaligned<uint16_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
template uint32_t read_unaligned<uint32_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
template uint64_t read_unaligned<uint64_t>(uint32_t guest_va, uint8_t* host_va, uint32_t instr);
|
||||
|
||||
template <class T>
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
static void write_unaligned(uint32_t guest_va, uint8_t *host_va, uint32_t instr, T value)
|
||||
{
|
||||
if ((sizeof(T) == 8) && (guest_va & 3)) {
|
||||
#ifndef PPC_TESTS
|
||||
ppc_alignment_exception(guest_va);
|
||||
ppc_alignment_exception(guest_va, instr);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1265,7 +1268,7 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
uint32_t shift = (sizeof(T) - 1) * 8;
|
||||
|
||||
for (int i = 0; i < sizeof(T); shift -= 8, guest_va++, i++) {
|
||||
mmu_write_vmem<uint8_t>(guest_va, (value >> shift) & 0xFF);
|
||||
mmu_write_vmem<uint8_t>(guest_va, instr, ((value >> shift) & 0xFF));
|
||||
}
|
||||
} else {
|
||||
#ifdef MMU_PROFILING
|
||||
@@ -1289,9 +1292,12 @@ static void write_unaligned(uint32_t guest_va, uint8_t *host_va, T value)
|
||||
}
|
||||
|
||||
// explicitely instantiate all required write_unaligned variants
|
||||
template void write_unaligned<uint16_t>(uint32_t guest_va, uint8_t *host_va, uint16_t value);
|
||||
template void write_unaligned<uint32_t>(uint32_t guest_va, uint8_t *host_va, uint32_t value);
|
||||
template void write_unaligned<uint64_t>(uint32_t guest_va, uint8_t *host_va, uint64_t value);
|
||||
template void write_unaligned<uint16_t>(
|
||||
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint16_t value);
|
||||
template void write_unaligned<uint32_t>(
|
||||
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint32_t value);
|
||||
template void write_unaligned<uint64_t>(
|
||||
uint32_t guest_va, uint8_t* host_va, uint32_t instr, uint64_t value);
|
||||
|
||||
|
||||
/* MMU profiling. */
|
||||
@@ -1431,19 +1437,19 @@ uint64_t mem_read_dbg(uint32_t virt_addr, uint32_t size) {
|
||||
try {
|
||||
switch (size) {
|
||||
case 1:
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr, 0);
|
||||
break;
|
||||
case 2:
|
||||
ret_val = mmu_read_vmem<uint16_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint16_t>(virt_addr, 0);
|
||||
break;
|
||||
case 4:
|
||||
ret_val = mmu_read_vmem<uint32_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint32_t>(virt_addr, 0);
|
||||
break;
|
||||
case 8:
|
||||
ret_val = mmu_read_vmem<uint64_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint64_t>(virt_addr, 0);
|
||||
break;
|
||||
default:
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr);
|
||||
ret_val = mmu_read_vmem<uint8_t>(virt_addr, 0);
|
||||
}
|
||||
} catch (std::invalid_argument& exc) {
|
||||
/* restore MMU-related CPU state */
|
||||
|
||||
+2
-15
@@ -130,21 +130,8 @@ uint8_t *mmu_translate_imem(uint32_t vaddr, uint32_t *paddr = nullptr);
|
||||
bool mmu_translate_dbg(uint32_t guest_va, uint32_t &guest_pa);
|
||||
|
||||
template <class T>
|
||||
extern T mmu_read_vmem(uint32_t guest_va);
|
||||
extern T mmu_read_vmem(uint32_t guest_va, uint32_t instr);
|
||||
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);
|
||||
extern void mem_write_qword(uint32_t addr, uint64_t value);
|
||||
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 uint8_t* quickinstruction_translate(uint32_t address_grab);
|
||||
#endif
|
||||
extern void mmu_write_vmem(uint32_t guest_va, uint32_t instr, T value);
|
||||
|
||||
#endif // PPCMMU_H
|
||||
+15
-1842
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 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/>.
|
||||
*/
|
||||
|
||||
#undef OPCODE
|
||||
#define OPCODE(op, grabber, number, ...) \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef OPCODE31
|
||||
#define OPCODE31(op, grabber, number, ...) \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef POWEROPCODE
|
||||
#define POWEROPCODE(op, grabber, number, ...) \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef POWEROPCODE31
|
||||
#define POWEROPCODE31(op, grabber, number, ...) \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
}
|
||||
|
||||
#undef OPCODESHIFT
|
||||
#define OPCODESHIFT(op, grabber, number, ...) \
|
||||
template <field_shift shift> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<SHFT0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<SHFT1>(uint32_t instr);
|
||||
|
||||
#undef OPCODESHIFTREC
|
||||
#define OPCODESHIFTREC(op, grabber, number, ...) \
|
||||
template <field_direction isleft, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RIGHT0, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LEFT1, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RIGHT0, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LEFT1, RC1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEOVREC
|
||||
#define OPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RC0, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC0, OV1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1, OV1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEEXTSIGN
|
||||
#define OPCODEEXTSIGN(op, grabber, number, ...) \
|
||||
template <class T, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<int8_t, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<int16_t, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<int8_t, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<int16_t, RC1>(uint32_t instr);
|
||||
|
||||
#undef POWEROPCODEOVREC
|
||||
#define POWEROPCODEOVREC(op, grabber, number, ...) \
|
||||
template <field_rc rec, field_ov ov> \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::power_##op<RC0, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC1, OV0>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC0, OV1>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC1, OV1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEREC
|
||||
#define OPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1>(uint32_t instr); \
|
||||
|
||||
#undef OPCODERECF
|
||||
#define OPCODERECF(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<RC1>(uint32_t instr); \
|
||||
|
||||
#undef POWEROPCODEREC
|
||||
#define POWEROPCODEREC(op, grabber, number, ...) \
|
||||
template <field_rc rec> \
|
||||
void dppc_interpreter::power_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::power_##op<RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::power_##op<RC1>(uint32_t instr);
|
||||
|
||||
#undef OPCODELOGIC
|
||||
#define OPCODELOGIC(op, grabber, number, ...) \
|
||||
template <logical_fun logical_op, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<ppc_and, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_andc, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_eqv, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nand, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nor, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_or, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_orc, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_xor, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_and, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_andc, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_eqv, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nand, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_nor, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_or, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_orc, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<ppc_xor, RC1>(uint32_t instr);
|
||||
|
||||
#undef OPCODELKAA
|
||||
#define OPCODELKAA(op, grabber, number, ...) \
|
||||
template <field_lk l, field_aa a> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<LK0, AA0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK0, AA1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, AA0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, AA1>(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEM
|
||||
#define OPCODEMEM(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<uint8_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint16_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint32_t>(uint32_t instr);
|
||||
|
||||
#undef OPCODEMEMINDEXED
|
||||
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
|
||||
template <class T> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<uint8_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint16_t>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<uint32_t>(uint32_t instr);
|
||||
|
||||
#undef OPCODE601REC
|
||||
#define OPCODE601REC(op, grabber, number, ...) \
|
||||
template <field_601 for601, field_rc rec> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<NOT601, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<IS601, RC0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<NOT601, RC1>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<IS601, RC1>(uint32_t instr); \
|
||||
|
||||
#undef OPCODE601L
|
||||
#define OPCODE601L(op, grabber, number, ...) \
|
||||
template <field_lk l, field_601 for601> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<LK0, NOT601>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK0, IS601>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, NOT601>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1, IS601>(uint32_t instr); \
|
||||
|
||||
#undef OPCODEL
|
||||
#define OPCODEL(op, grabber, number, ...) \
|
||||
template <field_lk l> \
|
||||
void dppc_interpreter::ppc_##op(uint32_t instr) { \
|
||||
__VA_ARGS__ \
|
||||
} \
|
||||
template void dppc_interpreter::ppc_##op<LK0>(uint32_t instr); \
|
||||
template void dppc_interpreter::ppc_##op<LK1>(uint32_t instr);
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 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/>.
|
||||
*/
|
||||
|
||||
#undef OPCODE
|
||||
#define OPCODE(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number] = ppc_##op;
|
||||
|
||||
#undef OPCODE31
|
||||
#define OPCODE31(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number << 1] = ppc_##op;
|
||||
|
||||
#undef POWEROPCODE
|
||||
#define POWEROPCODE(op, grabber, number, ...) \
|
||||
if (is_601) \
|
||||
Opcode##grabber##Grabber[number] = power_##op;
|
||||
|
||||
#undef POWEROPCODE31
|
||||
#define POWEROPCODE31(op, grabber, number, ...) \
|
||||
if (is_601) \
|
||||
Opcode##grabber##Grabber[number << 1] = power_##op;
|
||||
|
||||
#undef OPCODESHIFT
|
||||
#define OPCODESHIFT(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<SHFT0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<SHFT1>;
|
||||
|
||||
#undef OPCODESHIFTREC
|
||||
#define OPCODESHIFTREC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LEFT1 , RC0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LEFT1 , RC1>; \
|
||||
Opcode##grabber##Grabber[number + (1 << 9) ] = ppc_##op<RIGHT0, RC0>; \
|
||||
Opcode##grabber##Grabber[number + (1 << 9) + 1] = ppc_##op<RIGHT0, RC1>; \
|
||||
|
||||
#undef OPCODEOVREC
|
||||
#define OPCODEOVREC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<RC0, OV0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<RC1, OV0>; \
|
||||
Opcode##grabber##Grabber[number + 2] = ppc_##op<RC0, OV1>; \
|
||||
Opcode##grabber##Grabber[number + 3] = ppc_##op<RC1, OV1>;
|
||||
|
||||
#undef OPCODEEXTSIGN
|
||||
#define OPCODEEXTSIGN(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<int16_t, RC0>; \
|
||||
Opcode##grabber##Grabber[( number << 1) + 1] = ppc_##op<int16_t, RC1>; \
|
||||
Opcode##grabber##Grabber[ (number + 32) << 1 ] = ppc_##op<int8_t, RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 32) << 1) + 1] = ppc_##op<int8_t, RC1>;
|
||||
|
||||
#undef POWEROPCODEOVREC
|
||||
#define POWEROPCODEOVREC(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = power_##op<RC0, OV0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 1] = power_##op<RC1, OV0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 2] = power_##op<RC0, OV1>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 3] = power_##op<RC1, OV1>; \
|
||||
}
|
||||
|
||||
#undef OPCODEREC
|
||||
#define OPCODEREC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<RC0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 1] = ppc_##op<RC1>; \
|
||||
|
||||
#undef OPCODERECF
|
||||
#define OPCODERECF(op, grabber, number, ...) \
|
||||
for (int i = 0; i < 2048; i += 32) { \
|
||||
Opcode##grabber##Grabber[(number + i) << 1 ] = ppc_##op<RC0>; \
|
||||
Opcode##grabber##Grabber[((number + i) << 1) + 1] = ppc_##op<RC1>; \
|
||||
}
|
||||
|
||||
#undef POWEROPCODEREC
|
||||
#define POWEROPCODEREC(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = power_##op<RC0>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + 1] = power_##op<RC1>; \
|
||||
}
|
||||
|
||||
#undef OPCODELOGIC
|
||||
#define OPCODELOGIC(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number ] = ppc_##op<ppc_and , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 1) << 1) ] = ppc_##op<ppc_and , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 32) << 1) ] = ppc_##op<ppc_andc, RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 32) << 1) + 1] = ppc_##op<ppc_andc, RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 96) << 1) ] = ppc_##op<ppc_nor , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 96) << 1) + 1] = ppc_##op<ppc_nor , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 256) << 1) ] = ppc_##op<ppc_eqv , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 256) << 1) + 1] = ppc_##op<ppc_eqv , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 288) << 1) ] = ppc_##op<ppc_xor , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 288) << 1) + 1] = ppc_##op<ppc_xor , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 384) << 1) ] = ppc_##op<ppc_orc , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 384) << 1) + 1] = ppc_##op<ppc_orc , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 416) << 1) ] = ppc_##op<ppc_or , RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 416) << 1) + 1] = ppc_##op<ppc_or , RC1>; \
|
||||
Opcode##grabber##Grabber[((number + 448) << 1) ] = ppc_##op<ppc_nand, RC0>; \
|
||||
Opcode##grabber##Grabber[((number + 448) << 1) + 1] = ppc_##op<ppc_nand, RC1>; \
|
||||
|
||||
#undef OPCODELKAA
|
||||
#define OPCODELKAA(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, AA0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, AA0>; \
|
||||
Opcode##grabber##Grabber[number + 2] = ppc_##op<LK0, AA1>; \
|
||||
Opcode##grabber##Grabber[number + 3] = ppc_##op<LK1, AA1>;
|
||||
|
||||
#undef OPCODEMEM
|
||||
#define OPCODEMEM(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<uint32_t>; \
|
||||
Opcode##grabber##Grabber[number + 2] = ppc_##op<uint8_t>; \
|
||||
Opcode##grabber##Grabber[number + 8] = ppc_##op<uint16_t>;
|
||||
|
||||
#undef OPCODEMEMINDEXED
|
||||
#define OPCODEMEMINDEXED(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[ number << 1 ] = ppc_##op<uint32_t>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + (1 << 6)] = ppc_##op<uint8_t>; \
|
||||
Opcode##grabber##Grabber[(number << 1) + (1 << 8)] = ppc_##op<uint16_t>;
|
||||
|
||||
#undef OPCODE601REC
|
||||
#define OPCODE601REC(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<IS601, RC0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<IS601, RC1>; \
|
||||
} else { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<NOT601, RC0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<NOT601, RC1>; \
|
||||
}
|
||||
|
||||
#undef OPCODE601L
|
||||
#define OPCODE601L(op, grabber, number, ...) \
|
||||
if (is_601) { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, IS601>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, IS601>; \
|
||||
} \
|
||||
else { \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0, NOT601>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1, NOT601>; \
|
||||
}
|
||||
|
||||
#undef OPCODEL
|
||||
#define OPCODEL(op, grabber, number, ...) \
|
||||
Opcode##grabber##Grabber[number ] = ppc_##op<LK0>; \
|
||||
Opcode##grabber##Grabber[number + 1] = ppc_##op<LK1>;
|
||||
@@ -36,12 +36,17 @@ using namespace std;
|
||||
int ntested; // number of tested instructions
|
||||
int nfailed; // number of failed instructions
|
||||
|
||||
void xer_ov_test(string mnem, uint32_t opcode) {
|
||||
#if defined(PPC_TESTS)
|
||||
void ppc_exception_handler(Except_Type exception_type, uint32_t srr1_bits) {
|
||||
power_on = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void xer_ov_test(string mnem, uint32_t opcode) {
|
||||
ppc_state.gpr[3] = 2;
|
||||
ppc_state.gpr[4] = 2;
|
||||
ppc_state.spr[SPR::XER] = 0xFFFFFFFF;
|
||||
ppc_cur_instruction = opcode;
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(opcode);
|
||||
if (ppc_state.spr[SPR::XER] & 0x40000000UL) {
|
||||
cout << "Invalid " << mnem << " emulation! XER[OV] should not be set." << endl;
|
||||
nfailed++;
|
||||
@@ -145,9 +150,7 @@ static void read_test_data() {
|
||||
ppc_state.spr[SPR::XER] = 0;
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(opcode);
|
||||
|
||||
ntested++;
|
||||
|
||||
@@ -289,9 +292,7 @@ static void read_test_float_data() {
|
||||
|
||||
ppc_state.cr = 0;
|
||||
|
||||
ppc_cur_instruction = opcode;
|
||||
|
||||
ppc_main_opcode();
|
||||
ppc_main_opcode(opcode);
|
||||
|
||||
ntested++;
|
||||
|
||||
|
||||
+14
-3
@@ -161,7 +161,7 @@ print_bin:
|
||||
#define EMU_68K_TABLE_SIZE 0x80000
|
||||
|
||||
/** Execute one emulated 68k instruction. */
|
||||
void exec_single_68k()
|
||||
void exec_single_68k(uint32_t instr)
|
||||
{
|
||||
uint32_t emu_table_virt, cur_68k_pc, cur_instr_tab_entry, ppc_pc;
|
||||
|
||||
@@ -174,7 +174,7 @@ void exec_single_68k()
|
||||
|
||||
/* 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;
|
||||
cur_instr_tab_entry = mmu_read_vmem<uint16_t>(cur_68k_pc, 0) * 8 + emu_table_virt;
|
||||
|
||||
/* grab the PPC PC too */
|
||||
ppc_pc = get_reg(string("PC"));
|
||||
@@ -447,7 +447,9 @@ void enter_debugger() {
|
||||
size_t separator_pos;
|
||||
bool did_message = false;
|
||||
uint32_t next_addr_ppc;
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
uint32_t next_addr_68k;
|
||||
#endif
|
||||
bool cmd_repeat;
|
||||
|
||||
unique_ptr<OfConfigUtils> ofnvram = unique_ptr<OfConfigUtils>(new OfConfigUtils);
|
||||
@@ -468,6 +470,10 @@ void enter_debugger() {
|
||||
power_off_reason = po_restarting;
|
||||
break;
|
||||
}
|
||||
if (power_off_reason == po_quit) {
|
||||
power_off_reason = po_quitting;
|
||||
break;
|
||||
}
|
||||
power_on = true;
|
||||
|
||||
if (power_off_reason == po_starting_up) {
|
||||
@@ -530,6 +536,11 @@ void enter_debugger() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (feof(stdin)) {
|
||||
printf("eof -> quit\n");
|
||||
cmd = "quit";
|
||||
}
|
||||
|
||||
cmd_repeat = cmd.empty() && !last_cmd.empty();
|
||||
if (cmd_repeat) {
|
||||
cmd = last_cmd;
|
||||
@@ -610,7 +621,7 @@ void enter_debugger() {
|
||||
if (context == 2) {
|
||||
#ifdef ENABLE_68K_DEBUGGER
|
||||
for (; --count >= 0;) {
|
||||
exec_single_68k();
|
||||
exec_single_68k(0);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
|
||||
@@ -100,7 +100,15 @@ bool AdbMouse::get_register_0() {
|
||||
this->y_rel = 0;
|
||||
this->changed = false;
|
||||
|
||||
this->host_obj->set_output_count(p - out_buf);
|
||||
uint8_t count = (uint8_t)(p - out_buf);
|
||||
// should never happen, but check just in case
|
||||
if (((size_t)p - (size_t)out_buf) > UINT8_MAX)
|
||||
count = UINT8_MAX;
|
||||
// if the mouse is in standard protocol then only send first 2 bytes
|
||||
// BUGBUG: what should tablet do here?
|
||||
if (this->device_class == MOUSE && this->dev_handler_id == 1)
|
||||
count = 2;
|
||||
this->host_obj->set_output_count(count);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,9 @@ void AtaBaseDevice::device_reset(bool is_soft_reset) {
|
||||
|
||||
// Diagnostic code
|
||||
this->r_error = 1; // device 0 passed, device 1 passed or not present
|
||||
|
||||
// disable interrupts
|
||||
this->r_dev_ctrl |= ATA_CTRL::IEN;
|
||||
}
|
||||
|
||||
void AtaBaseDevice::device_set_signature() {
|
||||
@@ -67,10 +70,11 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
this->xfer_cnt -= this->chunk_size;
|
||||
if (this->xfer_cnt <= 0)
|
||||
if (this->xfer_cnt <= 0) {
|
||||
this->xfer_cnt = 0;
|
||||
this->r_status &= ~DRQ;
|
||||
else {
|
||||
this->chunk_cnt = this->chunk_size;
|
||||
} else {
|
||||
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
|
||||
this->update_intrq(1);
|
||||
}
|
||||
}
|
||||
@@ -104,19 +108,20 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
if (this->has_data()) {
|
||||
if (is_selected() && this->has_data()) {
|
||||
*this->cur_data_ptr++ = BYTESWAP_16(value);
|
||||
this->chunk_cnt -= 2;
|
||||
if (this->chunk_cnt <= 0) {
|
||||
this->post_xfer_action();
|
||||
this->xfer_cnt -= this->chunk_size;
|
||||
if (this->xfer_cnt <= 0) { // transfer complete?
|
||||
this->xfer_cnt = 0;
|
||||
this->r_status &= ~DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
} else {
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
this->chunk_cnt = this->chunk_size;
|
||||
this->chunk_cnt = std::min(this->xfer_cnt, this->chunk_size);
|
||||
this->signal_data_ready();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,10 @@ public:
|
||||
AtaBaseDevice(const std::string name, uint8_t type);
|
||||
~AtaBaseDevice() = default;
|
||||
|
||||
void set_host(IdeChannel* host) { this->host_obj = host; };
|
||||
void set_host(IdeChannel* host, uint8_t dev_id) {
|
||||
this->host_obj = host;
|
||||
this->my_dev_id = dev_id;
|
||||
};
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) override;
|
||||
void write(const uint8_t reg_addr, const uint16_t value) override;
|
||||
@@ -89,10 +92,11 @@ protected:
|
||||
uint8_t r_command;
|
||||
uint8_t r_status;
|
||||
uint8_t r_status_save;
|
||||
uint8_t r_dev_ctrl = 0x08;
|
||||
uint8_t r_dev_ctrl = 0x08 | ata_interface::ATA_CTRL::IEN; // disable interrupts
|
||||
|
||||
uint16_t *data_ptr = nullptr;
|
||||
uint16_t *cur_data_ptr = nullptr;
|
||||
alignas(uint16_t)
|
||||
uint8_t data_buf[512] = {};
|
||||
int xfer_cnt = 0;
|
||||
int chunk_cnt = 0;
|
||||
|
||||
@@ -137,6 +137,7 @@ enum ATA_Cmd : uint8_t {
|
||||
ATAPI_SERVICE = 0xA2,
|
||||
READ_MULTIPLE = 0xC4,
|
||||
WRITE_MULTIPLE = 0xC5,
|
||||
SET_MULTIPLE_MODE = 0xC6,
|
||||
READ_DMA = 0xC8,
|
||||
WRITE_DMA = 0xCA,
|
||||
STANDBY_IMMEDIATE_E0 = 0xE0,
|
||||
|
||||
@@ -28,6 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <bitset>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@@ -84,38 +85,79 @@ int AtaHardDisk::perform_command() {
|
||||
switch (this->r_command) {
|
||||
case NOP:
|
||||
break;
|
||||
case RECALIBRATE:
|
||||
this->r_error = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
case ATAPI_SOFT_RESET: // for ATA devices, is a no-op
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
case RECALIBRATE: // is optional in ATA-3; disappeared in >= ATA-4
|
||||
// OF 3.1.1 won't boot off the drive that reports error for this command
|
||||
this->r_cylinder_hi = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_dev_head &= 0xF0;
|
||||
this->r_sect_num = (this->r_dev_head & ATA_Dev_Head::LBA) ? 0 : 1;
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case READ_MULTIPLE:
|
||||
case READ_SECTOR:
|
||||
case READ_SECTOR_NR: {
|
||||
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
|
||||
int xfer_size = sec_count * ATA_HD_SEC_SIZE;
|
||||
uint64_t offset = this->get_lba() * ATA_HD_SEC_SIZE;
|
||||
uint32_t ints_size = ATA_HD_SEC_SIZE;
|
||||
if (this->r_command == READ_MULTIPLE) {
|
||||
if (!this->sectors_per_int) {
|
||||
LOG_F(ERROR, "%s: READ_MULTIPLE disabled", this->name.c_str());
|
||||
this->r_status |= ERR;
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
}
|
||||
ints_size *= this->sectors_per_int;
|
||||
}
|
||||
hdd_img.read(buffer, offset, xfer_size);
|
||||
this->data_ptr = (uint16_t *)this->buffer;
|
||||
// those commands should generate IRQ for each sector
|
||||
this->prepare_xfer(xfer_size, ATA_HD_SEC_SIZE);
|
||||
this->prepare_xfer(xfer_size, ints_size);
|
||||
this->signal_data_ready();
|
||||
}
|
||||
break;
|
||||
case WRITE_MULTIPLE:
|
||||
case WRITE_SECTOR:
|
||||
case WRITE_SECTOR_NR: {
|
||||
uint16_t sec_count = this->r_sect_count ? this->r_sect_count : 256;
|
||||
this->cur_fpos = this->get_lba() * ATA_HD_SEC_SIZE;
|
||||
this->data_ptr = (uint16_t *)this->buffer;
|
||||
this->cur_data_ptr = this->data_ptr;
|
||||
this->prepare_xfer(sec_count * ATA_HD_SEC_SIZE, ATA_HD_SEC_SIZE);
|
||||
uint32_t xfer_size = sec_count * ATA_HD_SEC_SIZE;
|
||||
uint32_t ints_size = ATA_HD_SEC_SIZE;
|
||||
if (this->r_command == WRITE_MULTIPLE) {
|
||||
if (!this->sectors_per_int) {
|
||||
LOG_F(ERROR, "%s: WRITE_MULTIPLE disabled", this->name.c_str());
|
||||
this->r_status |= ERR;
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
}
|
||||
ints_size *= this->sectors_per_int;
|
||||
}
|
||||
this->prepare_xfer(xfer_size, ints_size);
|
||||
this->post_xfer_action = [this]() {
|
||||
this->hdd_img.write(this->data_ptr, this->cur_fpos, this->chunk_size);
|
||||
this->cur_fpos += this->chunk_size;
|
||||
uint64_t write_len = (this->cur_data_ptr - this->data_ptr) * sizeof(this->data_ptr[0]);
|
||||
this->hdd_img.write(this->data_ptr, this->cur_fpos, write_len);
|
||||
this->cur_fpos += write_len;
|
||||
};
|
||||
this->r_status |= DRQ;
|
||||
this->r_status &= ~BSY;
|
||||
}
|
||||
break;
|
||||
case DIAGNOSTICS:
|
||||
this->r_error = 1; // device 0 passed, device 1 passed or not present
|
||||
this->device_set_signature();
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case READ_VERIFY: // verify sectors are readable, just no-op
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case INIT_DEV_PARAM:
|
||||
// update fictive disk geometry with parameters from host
|
||||
this->sectors = this->r_sect_count;
|
||||
@@ -123,9 +165,20 @@ int AtaHardDisk::perform_command() {
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case DIAGNOSTICS:
|
||||
this->r_error = 1;
|
||||
this->device_set_signature();
|
||||
case SET_MULTIPLE_MODE: // this command is mandatory for ATA devices
|
||||
if (!this->r_sect_count || this->r_sect_count > SECTORS_PER_INT ||
|
||||
std::bitset<8>(this->r_sect_count).count() != 1) { // power of two?
|
||||
LOG_F(ERROR, "%s: invalid parameter %d for SET_MULTIPLE_MODE",
|
||||
this->name.c_str(), this->r_sect_count);
|
||||
this->r_error |= ABRT;
|
||||
this->r_status |= ERR;
|
||||
} else {
|
||||
LOG_F(9, "%s: SET_MULTIPLE_MODE, r_sect_count=%d", this->name.c_str(),
|
||||
this->r_sect_count);
|
||||
this->sectors_per_int = this->r_sect_count;
|
||||
}
|
||||
this->r_status &= ~BSY;
|
||||
this->update_intrq(1);
|
||||
break;
|
||||
case FLUSH_CACHE: // used by the XNU kernel driver
|
||||
this->r_status &= ~(BSY | DRQ | ERR);
|
||||
@@ -186,6 +239,16 @@ void AtaHardDisk::prepare_identify_info() {
|
||||
buf_ptr[ 0] = 0x0040; // ATA device, non-removable media, non-removable drive
|
||||
buf_ptr[49] = 0x0200; // report LBA support
|
||||
|
||||
// Maximum number of logical sectors per data block that the device supports
|
||||
// for READ_MULTIPLE/WRITE_MULTIPLE commands.
|
||||
buf_ptr[47] = 0x8000 | SECTORS_PER_INT;
|
||||
|
||||
// If bit 8 of word 59 is set to one, then bits 7:0 indicate the number of
|
||||
// logical sectors that shall be transferred per data block for
|
||||
// READ_MULTIPLE/WRITE_MULTIPLE commands.
|
||||
if (this->sectors_per_int)
|
||||
buf_ptr[59] = 0x100 | this->sectors_per_int;
|
||||
|
||||
buf_ptr[ 1] = this->cylinders;
|
||||
buf_ptr[ 3] = this->heads;
|
||||
buf_ptr[ 6] = this->sectors;
|
||||
|
||||
@@ -30,6 +30,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
|
||||
#define ATA_HD_SEC_SIZE 512
|
||||
#define SECTORS_PER_INT 16
|
||||
|
||||
// C:16383 x H:16 x S:63 = C:1032 x H:254 x S:63 = 8063.5078125 MiB = 8.46 GB
|
||||
#define ATA_BIOS_LIMIT 16514064
|
||||
@@ -69,9 +70,9 @@ private:
|
||||
uint8_t heads;
|
||||
uint8_t sectors;
|
||||
|
||||
char * buffer = new char[1 <<17];
|
||||
uint8_t sectors_per_int = 0; // sectors per interrupt for READ_MULTIPLE/WRITE_MULTIPLE
|
||||
|
||||
uint8_t hd_id_data[ATA_HD_SEC_SIZE] = {};
|
||||
char * buffer = new char[1 <<17];
|
||||
};
|
||||
|
||||
#endif // ATA_HARD_DISK_H
|
||||
@@ -149,6 +149,11 @@ int AtapiBaseDevice::perform_command() {
|
||||
this->r_status |= BSY;
|
||||
|
||||
switch (this->r_command) {
|
||||
case ATAPI_SOFT_RESET:
|
||||
this->device_reset(true);
|
||||
this->device_set_signature();
|
||||
this->r_status &= ~BSY;
|
||||
break;
|
||||
case ATAPI_PACKET:
|
||||
this->data_ptr = (uint16_t *)this->cmd_pkt;
|
||||
this->xfer_cnt = sizeof(this->cmd_pkt);
|
||||
|
||||
@@ -55,6 +55,7 @@ protected:
|
||||
uint16_t r_byte_count;
|
||||
bool status_expected = false;
|
||||
|
||||
alignas(uint16_t)
|
||||
uint8_t cmd_pkt[12] = {};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,8 +22,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** IDE Channel (aka IDE port) emulation.
|
||||
|
||||
One IDE channel is capable of controlling up to two IDE devices.
|
||||
This class handles device registration and passing of messages
|
||||
|
||||
IdeChannel class handles device registration and passing of messages
|
||||
from and to the host.
|
||||
|
||||
MacioIdeChannel class implements MacIO specific registers
|
||||
and interrupt handling.
|
||||
*/
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
@@ -51,62 +55,73 @@ IdeChannel::IdeChannel(const std::string name)
|
||||
this->devices[1] = this->device_stub.get();
|
||||
}
|
||||
|
||||
int IdeChannel::device_postinit() {
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(
|
||||
this->name == "IDE0" ? IntSrc::IDE0 : IntSrc::IDE1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void IdeChannel::register_device(int id, AtaInterface* dev_obj) {
|
||||
if (id < 0 || id >= 2)
|
||||
ABORT_F("%s: invalid device ID", this->name.c_str());
|
||||
|
||||
this->devices[id] = dev_obj;
|
||||
|
||||
((AtaBaseDevice*)dev_obj)->set_host(this);
|
||||
((AtaBaseDevice*)dev_obj)->set_host(this, id);
|
||||
}
|
||||
|
||||
uint32_t IdeChannel::read(const uint8_t reg_addr, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD read from the channel config", this->name.c_str());
|
||||
}
|
||||
return this->ch_config;
|
||||
} else {
|
||||
return this->devices[this->cur_dev]->read(reg_addr);
|
||||
}
|
||||
uint32_t IdeChannel::read(const uint8_t reg_addr, const int size) {
|
||||
return this->devices[this->cur_dev]->read(reg_addr);
|
||||
}
|
||||
|
||||
void IdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD write to the channel config", this->name.c_str());
|
||||
}
|
||||
this->ch_config = val;
|
||||
} else {
|
||||
// keep track of the currently selected device
|
||||
if (reg_addr == DEVICE_HEAD) {
|
||||
this->cur_dev = (val >> 4) & 1;
|
||||
}
|
||||
// keep track of the currently selected device
|
||||
if (reg_addr == DEVICE_HEAD) {
|
||||
this->cur_dev = (val >> 4) & 1;
|
||||
}
|
||||
|
||||
// redirect register writes to both devices
|
||||
for (auto& dev : this->devices) {
|
||||
dev->write(reg_addr, val);
|
||||
}
|
||||
// redirect register writes to both devices
|
||||
for (auto& dev : this->devices) {
|
||||
dev->write(reg_addr, val);
|
||||
}
|
||||
}
|
||||
|
||||
int MacioIdeChannel::device_postinit() {
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(
|
||||
this->name == "IDE0" ? IntSrc::IDE0 : IntSrc::IDE1);
|
||||
|
||||
this->irq_callback = [this](const uint8_t intrq_state) {
|
||||
this->int_ctrl->ack_int(this->irq_id, intrq_state);
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t MacioIdeChannel::read(const uint8_t reg_addr, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD read from TIME_CONFIG", this->name.c_str());
|
||||
}
|
||||
return this->ch_config;
|
||||
} else
|
||||
return IdeChannel::read(reg_addr, size);
|
||||
}
|
||||
|
||||
void MacioIdeChannel::write(const uint8_t reg_addr, const uint32_t val, const int size)
|
||||
{
|
||||
if (reg_addr == TIME_CONFIG) {
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "%s: non-DWORD write to TIME_CONFIG", this->name.c_str());
|
||||
}
|
||||
this->ch_config = val;
|
||||
} else
|
||||
IdeChannel::write(reg_addr, val, size);
|
||||
}
|
||||
|
||||
static const DeviceDescription Ide0_Descriptor = {
|
||||
IdeChannel::create_first, {}, {}
|
||||
MacioIdeChannel::create_first, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Ide1_Descriptor = {
|
||||
IdeChannel::create_second, {}, {}
|
||||
MacioIdeChannel::create_second, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -38,16 +39,6 @@ public:
|
||||
IdeChannel(const std::string name);
|
||||
~IdeChannel() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE0"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE1"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
void register_device(int id, AtaInterface* dev_obj);
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
@@ -55,26 +46,56 @@ public:
|
||||
|
||||
void assert_pdiag() {
|
||||
this->devices[0]->pdiag_callback();
|
||||
};
|
||||
}
|
||||
|
||||
bool is_device1_present() {
|
||||
return this->devices[1]->get_device_id() != ata_interface::DEVICE_ID_INVALID;
|
||||
}
|
||||
|
||||
void report_intrq(uint8_t intrq_state) {
|
||||
this->int_ctrl->ack_int(this->irq_id, intrq_state);
|
||||
void set_irq_callback(std::function<void(const uint8_t intrq_state)> cb) {
|
||||
this->irq_callback = cb;
|
||||
}
|
||||
|
||||
void report_intrq(uint8_t intrq_state) {
|
||||
this->irq_callback(intrq_state);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::function<void(const uint8_t intrq_state)> irq_callback = nullptr;
|
||||
|
||||
private:
|
||||
int cur_dev = 0;
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
AtaInterface* devices[2];
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
|
||||
std::unique_ptr<AtaInterface> device_stub;
|
||||
};
|
||||
|
||||
/** This class models an IDE channel specific to MacIO ASICs. */
|
||||
class MacioIdeChannel : public IdeChannel
|
||||
{
|
||||
public:
|
||||
MacioIdeChannel(const std::string name) : IdeChannel(name) {};
|
||||
~MacioIdeChannel() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<IdeChannel>(new MacioIdeChannel("IDE0"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<IdeChannel>(new MacioIdeChannel("IDE1"));
|
||||
}
|
||||
|
||||
int device_postinit() override;
|
||||
|
||||
uint32_t read(const uint8_t reg_addr, const int size);
|
||||
void write(const uint8_t reg_addr, const uint32_t val, const int size);
|
||||
|
||||
private:
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
|
||||
// interrupt stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
};
|
||||
|
||||
#endif // IDE_CHANNEL_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -102,6 +102,7 @@ uint8_t DMAChannel::interpret_cmd() {
|
||||
break;
|
||||
case DBDMA_Cmd::INPUT_MORE:
|
||||
case DBDMA_Cmd::INPUT_LAST:
|
||||
this->xfer_from_device();
|
||||
if (this->in_cb)
|
||||
this->in_cb();
|
||||
break;
|
||||
@@ -194,8 +195,7 @@ void DMAChannel::finish_cmd() {
|
||||
|
||||
// all INPUT and OUTPUT commands including LOAD_QUAD and STORE_QUAD update cmd.resCount
|
||||
if (this->cur_cmd < DBDMA_Cmd::NOP && res.is_writable) {
|
||||
WRITE_WORD_LE_A(&cmd_desc[12], this->res_count);
|
||||
this->queue_len = 0;
|
||||
WRITE_WORD_LE_A(&cmd_desc[12], this->queue_len);
|
||||
this->res_count = 0;
|
||||
}
|
||||
|
||||
@@ -339,7 +339,9 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
// That means we need to update memory before channel operation
|
||||
// is aborted to prevent data loss.
|
||||
if (new_stat & CH_STAT_FLUSH) {
|
||||
if (this->cur_cmd <= DBDMA_Cmd::INPUT_LAST && this->flush_cb && (new_stat & CH_STAT_ACTIVE) && !(this->ch_stat & CH_STAT_DEAD)) {
|
||||
if (this->cur_cmd <= DBDMA_Cmd::INPUT_LAST &&
|
||||
this->flush_cb && (new_stat & CH_STAT_ACTIVE) &&
|
||||
!(this->ch_stat & CH_STAT_DEAD)) {
|
||||
this->flush_cb();
|
||||
} else {
|
||||
// NOTE: because this implementation doesn't currently support
|
||||
@@ -378,7 +380,8 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
break; // ingore writes to ChannelStatus
|
||||
case DMAReg::CMD_PTR_HI:
|
||||
if (value != 0) {
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register write @%02x.%c = %0*x", this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel register write @%02x.%c = %0*x",
|
||||
this->get_name().c_str(), offset, SIZE_ARG(size), size * 2, value);
|
||||
}
|
||||
break;
|
||||
case DMAReg::CMD_PTR_LO:
|
||||
@@ -403,6 +406,20 @@ void DMAChannel::reg_write(uint32_t offset, uint32_t value, int size) {
|
||||
}
|
||||
}
|
||||
|
||||
void DMAChannel::xfer_from_device() {
|
||||
if (this->dev_obj == nullptr)
|
||||
return;
|
||||
|
||||
this->xfer_dir = DMA_DIR_FROM_DEV;
|
||||
|
||||
if (!this->dev_obj->xfer_from(this->queue_data, this->queue_len)) {
|
||||
this->queue_len = 0;
|
||||
this->finish_cmd();
|
||||
}
|
||||
|
||||
this->interpret_cmd();
|
||||
}
|
||||
|
||||
DmaPullResult DMAChannel::pull_data(uint32_t req_len, uint32_t *avail_len, uint8_t **p_data)
|
||||
{
|
||||
*avail_len = 0;
|
||||
@@ -472,7 +489,8 @@ int DMAChannel::push_data(const char* src_ptr, int len) {
|
||||
void DMAChannel::end_pull_data() {
|
||||
if (this->ch_stat & CH_STAT_DEAD || !(this->ch_stat & CH_STAT_ACTIVE)) {
|
||||
// dead or idle channel? -> no more data
|
||||
LOG_F(WARNING, "%s: Ending Dead/idle channel -> no more data", this->get_name().c_str());
|
||||
LOG_F(WARNING, "%s: Ending Dead/idle channel -> no more data",
|
||||
this->get_name().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -103,7 +103,7 @@ namespace DBDMA_Cmd {
|
||||
|
||||
typedef std::function<void(void)> DbdmaCallback;
|
||||
|
||||
class DMAChannel : public DmaBidirChannel {
|
||||
class DMAChannel : public DmaBidirChannel, public DmaChannel {
|
||||
public:
|
||||
DMAChannel(std::string name) : DmaBidirChannel(name) {}
|
||||
~DMAChannel() = default;
|
||||
@@ -134,6 +134,7 @@ protected:
|
||||
void finish_cmd();
|
||||
void xfer_quad(const DMACmd *cmd_desc, DMACmd *cmd_host);
|
||||
void update_irq();
|
||||
void xfer_from_device();
|
||||
|
||||
void start(void);
|
||||
void resume(void);
|
||||
@@ -164,4 +165,4 @@ private:
|
||||
uint32_t irq_id = 0;
|
||||
};
|
||||
|
||||
#endif /* DB_DMA_H */
|
||||
#endif // DB_DMA_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,6 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define DMA_CORE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
enum DmaPullResult : int {
|
||||
@@ -75,4 +76,52 @@ private:
|
||||
std::string name;
|
||||
};
|
||||
|
||||
// ---------------------- New DMA API -------------------------
|
||||
enum DmaMsg : unsigned {
|
||||
CH_START = 1,
|
||||
CH_STOP,
|
||||
DATA_AVAIL,
|
||||
};
|
||||
|
||||
enum XferDir : unsigned {
|
||||
DMA_DIR_UNDEF = 0,
|
||||
DMA_DIR_TO_DEV,
|
||||
DMA_DIR_FROM_DEV,
|
||||
};
|
||||
|
||||
class DmaChannel;
|
||||
|
||||
class DmaDevice {
|
||||
public:
|
||||
DmaDevice() = default;
|
||||
~DmaDevice() = default;
|
||||
|
||||
void connect(DmaChannel *ch_obj) { this->channel_obj = ch_obj; };
|
||||
void notify(DmaMsg msg) {};
|
||||
virtual int xfer_from(uint8_t *buf, int len) { return len; };
|
||||
|
||||
protected:
|
||||
DmaChannel* channel_obj = nullptr;
|
||||
};
|
||||
|
||||
class DmaChannel {
|
||||
public:
|
||||
DmaChannel() = default;
|
||||
~DmaChannel() = default;
|
||||
|
||||
void connect(DmaDevice *dev_obj) { this->dev_obj = dev_obj; };
|
||||
void notify(DmaMsg msg) {};
|
||||
|
||||
protected:
|
||||
DmaDevice* dev_obj = nullptr;
|
||||
XferDir xfer_dir = DMA_DIR_UNDEF;
|
||||
};
|
||||
|
||||
/*
|
||||
TODO: write CONNECT macro that
|
||||
- constructs both DmaChannel and DmaDevice objects
|
||||
- calls connect() method on both objects
|
||||
- initializes DMA interrupts
|
||||
*/
|
||||
|
||||
#endif // DMA_CORE_H
|
||||
@@ -46,6 +46,7 @@ enum HWCompType : uint64_t {
|
||||
SCSI_HOST = 1ULL << 21, // SCSI host adapter
|
||||
SCSI_DEV = 1ULL << 22, // SCSI device
|
||||
IDE_BUS = 1ULL << 23, // IDE bus
|
||||
IDE_HOST = 1ULL << 24, // IDE host controller
|
||||
IDE_DEV = 1ULL << 25, // IDE device
|
||||
SND_CODEC = 1ULL << 30, // sound codec
|
||||
SND_SERVER = 1ULL << 31, // host sound server
|
||||
|
||||
@@ -88,4 +88,9 @@ public:
|
||||
virtual void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state) = 0;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
InterruptCtrl *int_ctrl_obj;
|
||||
uint32_t irq_id;
|
||||
} IntDetails;
|
||||
|
||||
#endif // HW_INTERRUPT_H
|
||||
@@ -60,7 +60,7 @@ static uint32_t str2env(string& num_str) {
|
||||
|
||||
bool OfConfigAppl::validate() {
|
||||
int i;
|
||||
OfConfigHdrAppl hdr;
|
||||
OfConfigHdrAppl hdr{};
|
||||
|
||||
if (this->nvram_obj == nullptr)
|
||||
return false;
|
||||
@@ -151,9 +151,9 @@ const OfConfigImpl::config_dict& OfConfigAppl::get_config_vars() {
|
||||
|
||||
// populate the remaining variables
|
||||
for (auto& var : of_vars) {
|
||||
auto name = var.first;
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
auto& name = var.first;
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
|
||||
switch (type) {
|
||||
case OF_VAR_TYPE_INT:
|
||||
@@ -354,7 +354,7 @@ bool OfConfigChrp::validate()
|
||||
if (!of_part_found)
|
||||
return false;
|
||||
|
||||
OfConfigHdrChrp hdr;
|
||||
OfConfigHdrChrp hdr{};
|
||||
|
||||
// read OF partition header
|
||||
for (i = 0; i < sizeof(OfConfigHdrChrp); i++) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -142,7 +142,7 @@ protected:
|
||||
void unmap_exp_rom_mem();
|
||||
|
||||
std::string pci_name; // human-readable device name
|
||||
PCIHost* host_instance; // host bridge instance to call back
|
||||
PCIHost* host_instance; // host bridge instance to call back
|
||||
|
||||
// PCI configuration space state (type 0, 1, and 2)
|
||||
uint16_t vendor_id;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -165,14 +165,22 @@ void PCIBridge::pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &
|
||||
|
||||
bool PCIBridge::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
|
||||
if (!(this->command & 1))
|
||||
return false;
|
||||
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32)
|
||||
return false;
|
||||
|
||||
return this->pci_io_read_loop(offset, size, *res);
|
||||
}
|
||||
|
||||
bool PCIBridge::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
if (!(this->command & 1)) return false;
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32) return false;
|
||||
return this->pci_io_read_loop(offset, size, value);
|
||||
if (!(this->command & 1))
|
||||
return false;
|
||||
|
||||
if (offset < this->io_base_32 || offset + size >= this->io_limit_32)
|
||||
return false;
|
||||
|
||||
return this->pci_io_write_loop(offset, size, value);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
@@ -50,6 +50,10 @@ public:
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, AccessDetails &details);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, AccessDetails &details);
|
||||
|
||||
bool supports_io_space() {
|
||||
return true;
|
||||
};
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint8_t()> pci_rd_primary_bus;
|
||||
std::function<void(uint8_t)> pci_wr_primary_bus;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -145,6 +145,27 @@ PCIBase *PCIHost::attach_pci_device(const std::string& dev_name, int slot_id, co
|
||||
return dev;
|
||||
}
|
||||
|
||||
IntDetails PCIHost::register_pci_int(PCIBase* dev_instance) {
|
||||
bool dev_found = false;
|
||||
int dev_fun_num = 0;
|
||||
|
||||
for (auto& dev : this->dev_map) {
|
||||
if (dev.second == dev_instance) {
|
||||
dev_fun_num = dev.first;
|
||||
dev_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dev_found)
|
||||
ABORT_F("register_pci_int: requested device not found");
|
||||
|
||||
for (auto& irq : this->my_irq_map) {
|
||||
if (irq.dev_fun_num == dev_fun_num)
|
||||
return {this->int_ctrl, irq.irq_id};
|
||||
}
|
||||
ABORT_F("register_pci_int: no IRQ map for device 0x%X", dev_fun_num);
|
||||
}
|
||||
|
||||
bool PCIHost::pci_io_read_loop(uint32_t offset, int size, uint32_t &res)
|
||||
{
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
@@ -168,11 +189,13 @@ bool PCIHost::pci_io_write_loop(uint32_t offset, int size, uint32_t value)
|
||||
uint32_t PCIHost::pci_io_read_broadcast(uint32_t offset, int size)
|
||||
{
|
||||
uint32_t res;
|
||||
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
if (pci_io_read_loop (offset, size, res)) {
|
||||
if (pci_io_read_loop(offset, size, res))
|
||||
return res;
|
||||
}
|
||||
|
||||
// no device has accepted the request -> report error
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to read from unmapped PCI I/O space @%08x.%c",
|
||||
@@ -187,9 +210,10 @@ void PCIHost::pci_io_write_broadcast(uint32_t offset, int size, uint32_t value)
|
||||
{
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
if (pci_io_write_loop(offset, size, value)) {
|
||||
if (pci_io_write_loop(offset, size, value))
|
||||
return;
|
||||
}
|
||||
|
||||
// no device has accepted the request -> report error
|
||||
HWComponent *hwc = dynamic_cast<HWComponent*>(this);
|
||||
LOG_F(
|
||||
ERROR, "%s: Attempt to write to unmapped PCI I/O space @%08x.%c = %0*x",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,6 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <core/bitops.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <endianswap.h>
|
||||
|
||||
#include <cinttypes>
|
||||
@@ -49,6 +50,12 @@ typedef struct AccessDetails {
|
||||
|
||||
#define DEV_FUN(dev_num,fun_num) (((dev_num) << 3) | (fun_num))
|
||||
|
||||
typedef struct {
|
||||
const char * slot_name;
|
||||
int dev_fun_num;
|
||||
uint32_t irq_id;
|
||||
} PciIrqMap;
|
||||
|
||||
class PCIBase;
|
||||
class PCIBridgeBase;
|
||||
|
||||
@@ -81,10 +88,22 @@ public:
|
||||
|
||||
virtual void pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {}
|
||||
|
||||
virtual void set_irq_map(const std::vector<PciIrqMap> &irq_map) {
|
||||
this->my_irq_map = irq_map;
|
||||
};
|
||||
|
||||
virtual IntDetails register_pci_int(PCIBase* dev_instance);
|
||||
virtual void set_interrupt_controller(InterruptCtrl * int_ctrl_obj) {
|
||||
this->int_ctrl = int_ctrl_obj;
|
||||
};
|
||||
|
||||
protected:
|
||||
std::unordered_map<int, PCIBase*> dev_map;
|
||||
std::vector<PCIBase*> io_space_devs;
|
||||
std::vector<PCIBridgeBase*> bridge_devs;
|
||||
std::vector<PciIrqMap> my_irq_map;
|
||||
|
||||
InterruptCtrl *int_ctrl = nullptr;
|
||||
};
|
||||
|
||||
// Helpers for data conversion in the PCI Configuration space.
|
||||
|
||||
+130
-95
@@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file MESH (Macintosh Enhanced SCSI Hardware) controller emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
@@ -35,6 +36,10 @@ using namespace MeshScsi;
|
||||
|
||||
int MeshController::device_postinit() {
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("ScsiMesh"));
|
||||
if (bus_obj) {
|
||||
bus_obj->register_device(7, static_cast<ScsiDevice*>(this));
|
||||
bus_obj->attach_scsi_devices("2");
|
||||
}
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
@@ -45,15 +50,15 @@ int MeshController::device_postinit() {
|
||||
|
||||
void MeshController::reset(bool is_hard_reset) {
|
||||
this->cur_cmd = SeqCmd::NoOperation;
|
||||
this->fifo_cnt = 0;
|
||||
this->fifo_pos = 0;
|
||||
this->int_mask = 0;
|
||||
this->exception = 0;
|
||||
this->xfer_count = 0;
|
||||
this->src_id = 7;
|
||||
|
||||
if (is_hard_reset) {
|
||||
this->bus_stat = 0;
|
||||
this->sync_params = (0 << 16) | 2; // fast async operation (guessed)
|
||||
this->bus_stat = 0;
|
||||
this->sync_params = (0 << 16) | 2; // fast async operation (guessed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +68,8 @@ uint8_t MeshController::read(uint8_t reg_offset) {
|
||||
return this->xfer_count & 0xFFU;
|
||||
case MeshReg::XferCount1:
|
||||
return (this->xfer_count >> 8) & 0xFFU;
|
||||
case MeshReg::FIFO:
|
||||
return this->fifo_pop();
|
||||
case MeshReg::Sequence:
|
||||
return this->cur_cmd;
|
||||
case MeshReg::BusStatus0:
|
||||
@@ -70,7 +77,7 @@ uint8_t MeshController::read(uint8_t reg_offset) {
|
||||
case MeshReg::BusStatus1:
|
||||
return this->bus_obj->test_ctrl_lines(0xE000U) >> 8;
|
||||
case MeshReg::FIFOCount:
|
||||
return this->fifo_cnt;
|
||||
return this->fifo_pos;
|
||||
case MeshReg::Exception:
|
||||
return this->exception;
|
||||
case MeshReg::Error:
|
||||
@@ -93,25 +100,26 @@ uint8_t MeshController::read(uint8_t reg_offset) {
|
||||
}
|
||||
|
||||
void MeshController::write(uint8_t reg_offset, uint8_t value) {
|
||||
uint16_t new_stat;
|
||||
//uint16_t new_stat;
|
||||
|
||||
switch(reg_offset) {
|
||||
case MeshReg::XferCount0:
|
||||
this->xfer_count = (this->xfer_count & ~0xFFU) | value;
|
||||
break;
|
||||
case MeshReg::XferCount1:
|
||||
this->xfer_count = (this->xfer_count & ~0xFF00U) | (value << 8);
|
||||
break;
|
||||
case MeshReg::FIFO:
|
||||
this->fifo_push(value);
|
||||
break;
|
||||
case MeshReg::Sequence:
|
||||
perform_command(value);
|
||||
break;
|
||||
case MeshReg::BusStatus0:
|
||||
this->update_bus_status((this->bus_stat & 0xFF00U) | value);
|
||||
break;
|
||||
case MeshReg::BusStatus1:
|
||||
new_stat = value << 8;
|
||||
if (new_stat != this->bus_stat) {
|
||||
for (uint16_t mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) {
|
||||
if ((new_stat ^ this->bus_stat) & mask) {
|
||||
if (new_stat & mask)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(this->src_id, mask);
|
||||
}
|
||||
}
|
||||
this->bus_stat = new_stat;
|
||||
}
|
||||
this->update_bus_status((this->bus_stat & 0xFFU) | (value << 8));
|
||||
break;
|
||||
case MeshReg::IntMask:
|
||||
this->int_mask = value;
|
||||
@@ -143,21 +151,79 @@ void MeshController::perform_command(const uint8_t cmd) {
|
||||
|
||||
this->int_stat &= ~INT_CMD_DONE;
|
||||
|
||||
this->is_dma_cmd = !!(this->cur_cmd & 0x80);
|
||||
|
||||
switch (this->cur_cmd & 0xF) {
|
||||
case SeqCmd::Arbitrate:
|
||||
this->exception &= EXC_ARB_LOST;
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::Select:
|
||||
this->assert_atn = !!(this->cur_cmd & 0x20);
|
||||
this->exception &= EXC_SEL_TIMEOUT;
|
||||
this->cur_state = SeqState::SEL_BEGIN;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::SEL_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::Command:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::COMMAND)
|
||||
LOG_F(WARNING, "%s: not in COMMAND phase", this->name.c_str());
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::SEND_CMD;
|
||||
if (this->fifo_pos)
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::Status:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::STATUS)
|
||||
LOG_F(WARNING, "%s: not in STATUS phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::RCV_STATUS;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::DataOut:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::DATA_OUT)
|
||||
LOG_F(WARNING, "%s: not in DATA OUT phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count ? this->xfer_count : 65536;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::XFER_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::DataIn:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::DATA_IN)
|
||||
LOG_F(WARNING, "%s: not in DATA IN phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count ? this->xfer_count : 65536;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::XFER_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::MessageOut:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::MESSAGE_OUT)
|
||||
LOG_F(WARNING, "%s: not in MESSAGE OUT phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::SEND_MSG;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::MessageIn:
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::MESSAGE_IN)
|
||||
LOG_F(WARNING, "%s: not in MESSAGE IN phase", this->name.c_str());
|
||||
this->to_xfer = this->xfer_count;
|
||||
this->cur_state = Scsi_Bus_Controller::SeqState::RCV_MESSAGE;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::BusFree:
|
||||
LOG_F(INFO, "MESH: BusFree stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ACK);
|
||||
// generate phase mismatch exception
|
||||
// if the target is still connected
|
||||
if (this->bus_obj->test_ctrl_lines(SCSI_CTRL_BSY)) {
|
||||
this->exception |= EXC_PHASE_MM;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
} else // say ok because we got the expected bus free phase
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
this->update_irq();
|
||||
break;
|
||||
case SeqCmd::EnaParityCheck:
|
||||
this->check_parity = true;
|
||||
break;
|
||||
case SeqCmd::DisParityCheck:
|
||||
this->check_parity = false;
|
||||
break;
|
||||
case SeqCmd::EnaReselect:
|
||||
LOG_F(9, "MESH: EnaReselect stub invoked");
|
||||
@@ -170,93 +236,62 @@ void MeshController::perform_command(const uint8_t cmd) {
|
||||
case SeqCmd::ResetMesh:
|
||||
this->reset(false);
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
break;
|
||||
case SeqCmd::FlushFIFO:
|
||||
LOG_F(INFO, "MESH: FlushFIFO stub invoked");
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
this->fifo_pos = 0;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "MESH: unsupported sequencer command 0x%X", this->cur_cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::seq_defer_state(uint64_t delay_ns) {
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
void MeshController::update_bus_status(const uint16_t new_stat) {
|
||||
uint16_t mask;
|
||||
|
||||
// update the lower part (BusStatus0)
|
||||
if ((new_stat ^ this->bus_stat) & 0xFF) {
|
||||
for (mask = SCSI_CTRL_REQ; mask >= SCSI_CTRL_IO; mask >>= 1) {
|
||||
if ((new_stat ^ this->bus_stat) & mask) {
|
||||
if (new_stat & mask)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(this->src_id, mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update the upper part (BusStatus1)
|
||||
if ((new_stat ^ this->bus_stat) & 0xFF00U) {
|
||||
for (mask = SCSI_CTRL_RST; mask >= SCSI_CTRL_SEL; mask >>= 1) {
|
||||
if ((new_stat ^ this->bus_stat) & mask) {
|
||||
if (new_stat & mask)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(this->src_id, mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->bus_stat = new_stat;
|
||||
}
|
||||
|
||||
void MeshController::sequencer()
|
||||
{
|
||||
switch (this->cur_state) {
|
||||
case SeqState::IDLE:
|
||||
break;
|
||||
case SeqState::BUS_FREE:
|
||||
if (this->bus_obj->current_phase() == ScsiPhase::BUS_FREE) {
|
||||
this->next_state = SeqState::ARB_BEGIN;
|
||||
this->seq_defer_state(BUS_FREE_DELAY + BUS_SETTLE_DELAY);
|
||||
} else { // continue waiting
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_FREE_DELAY);
|
||||
}
|
||||
break;
|
||||
case SeqState::ARB_BEGIN:
|
||||
if (!this->bus_obj->begin_arbitration(this->src_id)) {
|
||||
LOG_F(ERROR, "MESH: arbitration error, bus not free!");
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY);
|
||||
break;
|
||||
}
|
||||
this->next_state = SeqState::ARB_END;
|
||||
this->seq_defer_state(ARB_DELAY);
|
||||
break;
|
||||
case SeqState::ARB_END:
|
||||
if (this->bus_obj->end_arbitration(this->src_id) &&
|
||||
!this->bus_obj->test_ctrl_lines(SCSI_CTRL_SEL)) { // arbitration won
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
} else { // arbitration lost
|
||||
LOG_F(INFO, "MESH: arbitration lost!");
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->exception |= EXC_ARB_LOST;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
}
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
break;
|
||||
case SeqState::SEL_BEGIN:
|
||||
this->bus_obj->begin_selection(this->src_id, this->dst_id, this->cur_cmd & 0x20);
|
||||
this->next_state = SeqState::SEL_END;
|
||||
this->seq_defer_state(SEL_TIME_OUT);
|
||||
break;
|
||||
case SeqState::SEL_END:
|
||||
if (this->bus_obj->end_selection(this->src_id, this->dst_id)) {
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
LOG_F(9, "MESH: selection completed");
|
||||
} else { // selection timeout
|
||||
this->bus_obj->disconnect(this->src_id);
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->exception |= EXC_SEL_TIMEOUT;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
}
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
void MeshController::step_completed() {
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
void MeshController::report_error(const int error) {
|
||||
switch(error) {
|
||||
case SEL_TIMEOUT:
|
||||
this->exception |= EXC_SEL_TIMEOUT;
|
||||
this->int_stat |= INT_EXCEPTION;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("MESH: unimplemented sequencer state %d", this->cur_state);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::update_irq() {
|
||||
uint8_t new_irq = !!(this->int_stat & this->int_mask);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
ABORT_F("%s: unhandled error %d", this->name.c_str(), error);
|
||||
}
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
update_irq();
|
||||
}
|
||||
|
||||
static const PropMap Mesh_properties = {
|
||||
|
||||
+78
-110
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,106 +25,96 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define MESH_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/scsi/scsibusctrl.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class InterruptCtrl;
|
||||
class ScsiBus;
|
||||
|
||||
// Chip ID returned by the MESH ASIC on TNT machines (Apple part 343S1146-a)
|
||||
#define TntMeshID 0xE2
|
||||
|
||||
// Chip ID returned by the MESH cell inside the Heathrow ASIC
|
||||
#define HeathrowMESHID 4
|
||||
#define HeathrowMeshID 4
|
||||
|
||||
namespace MeshScsi {
|
||||
/** MESH registers offsets. */
|
||||
enum MeshReg : uint8_t {
|
||||
XferCount0 = 0,
|
||||
XferCount1 = 1,
|
||||
FIFO = 2,
|
||||
Sequence = 3,
|
||||
BusStatus0 = 4,
|
||||
BusStatus1 = 5,
|
||||
FIFOCount = 6,
|
||||
Exception = 7,
|
||||
Error = 8,
|
||||
IntMask = 9,
|
||||
Interrupt = 0xA,
|
||||
SourceID = 0xB,
|
||||
DestID = 0xC,
|
||||
SyncParms = 0xD,
|
||||
MeshID = 0xE,
|
||||
SelTimeOut = 0xF
|
||||
};
|
||||
|
||||
// MESH registers offsets.
|
||||
enum MeshReg : uint8_t {
|
||||
XferCount0 = 0,
|
||||
XferCount1 = 1,
|
||||
FIFO = 2,
|
||||
Sequence = 3,
|
||||
BusStatus0 = 4,
|
||||
BusStatus1 = 5,
|
||||
FIFOCount = 6,
|
||||
Exception = 7,
|
||||
Error = 8,
|
||||
IntMask = 9,
|
||||
Interrupt = 0xA,
|
||||
SourceID = 0xB,
|
||||
DestID = 0xC,
|
||||
SyncParms = 0xD,
|
||||
MeshID = 0xE,
|
||||
SelTimeOut = 0xF
|
||||
};
|
||||
/** MESH Sequencer commands. */
|
||||
enum SeqCmd : uint8_t {
|
||||
NoOperation = 0x0,
|
||||
Arbitrate = 0x1,
|
||||
Select = 0x2,
|
||||
Command = 0x3,
|
||||
Status = 0x4,
|
||||
DataOut = 0x5,
|
||||
DataIn = 0x6,
|
||||
MessageOut = 0x7,
|
||||
MessageIn = 0x8,
|
||||
BusFree = 0x9,
|
||||
EnaParityCheck = 0xA,
|
||||
DisParityCheck = 0xB,
|
||||
EnaReselect = 0xC,
|
||||
DisReselect = 0xD,
|
||||
ResetMesh = 0xE,
|
||||
FlushFIFO = 0xF
|
||||
};
|
||||
|
||||
// MESH Sequencer commands.
|
||||
enum SeqCmd : uint8_t {
|
||||
NoOperation = 0,
|
||||
Arbitrate = 1,
|
||||
Select = 2,
|
||||
BusFree = 9,
|
||||
EnaReselect = 0xC,
|
||||
DisReselect = 0xD,
|
||||
ResetMesh = 0xE,
|
||||
FlushFIFO = 0xF,
|
||||
};
|
||||
|
||||
// Exception register bits.
|
||||
enum {
|
||||
EXC_SEL_TIMEOUT = 1 << 0,
|
||||
EXC_PHASE_MM = 1 << 1,
|
||||
EXC_ARB_LOST = 1 << 2,
|
||||
};
|
||||
|
||||
// Interrupt register bits.
|
||||
enum {
|
||||
INT_CMD_DONE = 1 << 0,
|
||||
INT_EXCEPTION = 1 << 1,
|
||||
INT_ERROR = 1 << 2,
|
||||
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
|
||||
};
|
||||
|
||||
|
||||
enum SeqState : uint32_t {
|
||||
IDLE = 0,
|
||||
BUS_FREE,
|
||||
ARB_BEGIN,
|
||||
ARB_END,
|
||||
SEL_BEGIN,
|
||||
SEL_END,
|
||||
SEND_MSG,
|
||||
SEND_CMD,
|
||||
CMD_COMPLETE,
|
||||
XFER_BEGIN,
|
||||
XFER_END,
|
||||
SEND_DATA,
|
||||
RCV_DATA,
|
||||
RCV_STATUS,
|
||||
RCV_MESSAGE,
|
||||
};
|
||||
/** Exception register bits. */
|
||||
enum {
|
||||
EXC_SEL_TIMEOUT = 1 << 0,
|
||||
EXC_PHASE_MM = 1 << 1,
|
||||
EXC_ARB_LOST = 1 << 2,
|
||||
};
|
||||
|
||||
/** Interrupt register bits. */
|
||||
enum {
|
||||
INT_CMD_DONE = 1 << 0,
|
||||
INT_EXCEPTION = 1 << 1,
|
||||
INT_ERROR = 1 << 2,
|
||||
INT_MASK = INT_CMD_DONE | INT_EXCEPTION | INT_ERROR
|
||||
};
|
||||
}; // namespace MeshScsi
|
||||
|
||||
class MeshStub : public HWComponent {
|
||||
class MeshBase {
|
||||
public:
|
||||
MeshBase() = default;
|
||||
~MeshBase() = default;
|
||||
virtual uint8_t read(uint8_t reg_offset) = 0;
|
||||
virtual void write(uint8_t reg_offset, uint8_t value) = 0;
|
||||
};
|
||||
|
||||
class MeshStub : public MeshBase {
|
||||
public:
|
||||
MeshStub() = default;
|
||||
~MeshStub() = default;
|
||||
|
||||
// registers access
|
||||
uint8_t read(uint8_t reg_offset) { return 0; };
|
||||
void write(uint8_t reg_offset, uint8_t value) {};
|
||||
uint8_t read(uint8_t reg_offset) override { return 0; };
|
||||
void write(uint8_t reg_offset, uint8_t value) override {};
|
||||
};
|
||||
|
||||
class MeshController : public HWComponent {
|
||||
class MeshController : public ScsiBusController, public MeshBase {
|
||||
public:
|
||||
MeshController(uint8_t mesh_id) {
|
||||
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
|
||||
MeshController(uint8_t mesh_id) : ScsiBusController("MESH", 7) {
|
||||
this->chip_id = mesh_id;
|
||||
this->set_name("MESH");
|
||||
this->reset(true);
|
||||
};
|
||||
~MeshController() = default;
|
||||
@@ -134,55 +124,33 @@ public:
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_for_heathrow() {
|
||||
return std::unique_ptr<MeshController>(new MeshController(HeathrowMESHID));
|
||||
return std::unique_ptr<MeshController>(new MeshController(HeathrowMeshID));
|
||||
}
|
||||
|
||||
// MESH registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
// MeshBase methods
|
||||
uint8_t read(uint8_t reg_offset) override;
|
||||
void write(uint8_t reg_offset, uint8_t value) override;
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
int device_postinit() override;
|
||||
|
||||
void set_dma_channel(DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch = dma_ch;
|
||||
};
|
||||
// ScsiBusController methods
|
||||
void step_completed() override;
|
||||
void report_error(const int error) override;
|
||||
|
||||
protected:
|
||||
void reset(bool is_hard_reset);
|
||||
void perform_command(const uint8_t cmd);
|
||||
void seq_defer_state(uint64_t delay_ns);
|
||||
void sequencer();
|
||||
void update_irq();
|
||||
void update_bus_status(const uint16_t new_stat);
|
||||
|
||||
private:
|
||||
uint8_t chip_id;
|
||||
uint8_t int_mask = 0;
|
||||
uint8_t int_stat = 0;
|
||||
uint8_t sync_params;
|
||||
uint8_t src_id;
|
||||
uint8_t dst_id;
|
||||
uint8_t cur_cmd;
|
||||
uint8_t error;
|
||||
uint8_t fifo_cnt;
|
||||
uint8_t exception = 0;
|
||||
uint32_t xfer_count;
|
||||
|
||||
ScsiBus* bus_obj;
|
||||
uint8_t exception = 0;
|
||||
uint16_t bus_stat;
|
||||
|
||||
// Sequencer state
|
||||
uint32_t seq_timer_id;
|
||||
uint32_t cur_state;
|
||||
uint32_t next_state;
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
|
||||
// DMA related stuff
|
||||
DmaBidirChannel* dma_ch;
|
||||
bool check_parity = true;
|
||||
};
|
||||
|
||||
#endif // MESH_H
|
||||
@@ -172,7 +172,7 @@ uint16_t Sc53C94::pseudo_dma_read()
|
||||
// remove one word from FIFO
|
||||
data_word = (this->data_fifo[0] << 8) | this->data_fifo[1];
|
||||
this->data_fifo_pos -= 2;
|
||||
std:memmove(this->data_fifo, &this->data_fifo[2], this->data_fifo_pos);
|
||||
std::memmove(this->data_fifo, &this->data_fifo[2], this->data_fifo_pos);
|
||||
|
||||
// update DMA status
|
||||
if (this->is_dma_cmd) {
|
||||
@@ -328,8 +328,7 @@ void Sc53C94::exec_command()
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
|
||||
this->int_status = INTSTAT_SR;
|
||||
this->int_status |= INTSTAT_DIS; // TODO: handle target disconnection properly
|
||||
this->int_status = INTSTAT_DIS; // TODO: handle target disconnection properly
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -403,7 +402,7 @@ uint8_t Sc53C94::fifo_pop()
|
||||
} else {
|
||||
data = this->data_fifo[0];
|
||||
this->data_fifo_pos--;
|
||||
std:memmove(this->data_fifo, &this->data_fifo[1], this->data_fifo_pos);
|
||||
std::memmove(this->data_fifo, &this->data_fifo[1], this->data_fifo_pos);
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
+13
-10
@@ -142,16 +142,17 @@ enum ScsiSense : int {
|
||||
};
|
||||
|
||||
enum ScsiError : int {
|
||||
NO_ERROR = 0x00,
|
||||
NO_SECTOR = 0x01,
|
||||
WRITE_FAULT = 0x03,
|
||||
DEV_NOT_READY = 0x04,
|
||||
INVALID_CMD = 0x20,
|
||||
INVALID_LBA = 0x21,
|
||||
INVALID_CDB = 0x24,
|
||||
INVALID_LUN = 0x25,
|
||||
WRITE_PROTECT = 0x27,
|
||||
MEDIUM_NOT_PRESENT = 0x3A,
|
||||
NO_ERROR = 0x00,
|
||||
NO_SECTOR = 0x01,
|
||||
WRITE_FAULT = 0x03,
|
||||
DEV_NOT_READY = 0x04,
|
||||
INVALID_CMD = 0x20,
|
||||
INVALID_LBA = 0x21,
|
||||
INVALID_CDB = 0x24,
|
||||
INVALID_LUN = 0x25,
|
||||
WRITE_PROTECT = 0x27,
|
||||
SAVING_NOT_SUPPORTED = 0x39,
|
||||
MEDIUM_NOT_PRESENT = 0x3A,
|
||||
};
|
||||
|
||||
/** Standard SCSI bus timing values measured in ns. */
|
||||
@@ -199,6 +200,8 @@ public:
|
||||
this->bus_obj = bus_obj_ptr;
|
||||
}
|
||||
|
||||
void report_error(uint8_t sense_key, uint8_t asc);
|
||||
|
||||
protected:
|
||||
uint8_t cmd_buf[16] = {};
|
||||
uint8_t msg_buf[16] = {}; // TODO: clarify how big this one should be
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file SCSI bus controller emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/scsi/scsibusctrl.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
using namespace Scsi_Bus_Controller;
|
||||
|
||||
void ScsiBusController::seq_defer_state(uint64_t delay_ns) {
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
delay_ns,
|
||||
[this]() {
|
||||
// re-enter the sequencer with the state specified in next_state
|
||||
this->cur_state = this->next_state;
|
||||
this->sequencer();
|
||||
});
|
||||
}
|
||||
|
||||
void ScsiBusController::sequencer() {
|
||||
switch (this->cur_state) {
|
||||
case SeqState::IDLE:
|
||||
break;
|
||||
case SeqState::BUS_FREE:
|
||||
if (this->bus_obj->current_phase() == ScsiPhase::BUS_FREE) {
|
||||
this->next_state = SeqState::ARB_BEGIN;
|
||||
this->seq_defer_state(BUS_FREE_DELAY + BUS_SETTLE_DELAY);
|
||||
} else { // continue waiting
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_FREE_DELAY);
|
||||
}
|
||||
break;
|
||||
case SeqState::ARB_BEGIN:
|
||||
if (!this->bus_obj->begin_arbitration(this->src_id)) {
|
||||
LOG_F(ERROR, "%s: arbitration error, bus not free!", this->name.c_str());
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->next_state = SeqState::BUS_FREE;
|
||||
this->seq_defer_state(BUS_CLEAR_DELAY);
|
||||
break;
|
||||
}
|
||||
this->next_state = SeqState::ARB_END;
|
||||
this->seq_defer_state(ARB_DELAY);
|
||||
break;
|
||||
case SeqState::ARB_END:
|
||||
if (this->bus_obj->end_arbitration(this->src_id) &&
|
||||
!this->bus_obj->test_ctrl_lines(SCSI_CTRL_SEL)) { // arbitration won
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
this->step_completed();
|
||||
} else { // arbitration lost
|
||||
LOG_F(ERROR, "%s: arbitration lost!", this->name.c_str());
|
||||
this->bus_obj->release_ctrl_lines(this->src_id);
|
||||
this->report_error(ARB_LOST);
|
||||
}
|
||||
break;
|
||||
case SeqState::SEL_BEGIN:
|
||||
this->bus_obj->begin_selection(this->src_id, this->dst_id, this->assert_atn);
|
||||
this->next_state = SeqState::SEL_END;
|
||||
this->seq_defer_state(SEL_TIME_OUT);
|
||||
break;
|
||||
case SeqState::SEL_END:
|
||||
if (this->bus_obj->end_selection(this->src_id, this->dst_id)) {
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_SEL);
|
||||
LOG_F(9, "%s: selection completed", this->name.c_str());
|
||||
this->step_completed();
|
||||
} else { // selection timeout
|
||||
this->bus_obj->disconnect(this->src_id);
|
||||
this->cur_state = SeqState::IDLE;
|
||||
this->report_error(SEL_TIMEOUT);
|
||||
}
|
||||
break;
|
||||
case SeqState::SEND_MSG:
|
||||
if (this->fifo_pos) {
|
||||
this->bus_obj->target_xfer_data();
|
||||
this->bus_obj->release_ctrl_line(this->src_id, SCSI_CTRL_ATN);
|
||||
if (this->to_xfer <= 0)
|
||||
this->step_completed();
|
||||
}
|
||||
break;
|
||||
case SeqState::SEND_CMD:
|
||||
this->bus_obj->target_xfer_data();
|
||||
if (!this->fifo_pos)
|
||||
this->step_completed();
|
||||
break;
|
||||
case SeqState::XFER_BEGIN:
|
||||
this->cur_bus_phase = this->bus_obj->current_phase();
|
||||
switch (this->cur_bus_phase) {
|
||||
case ScsiPhase::DATA_OUT:
|
||||
this->cur_state = SeqState::SEND_DATA;
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
|
||||
this->cur_state = SeqState::RCV_DATA;
|
||||
this->rcv_data();
|
||||
}
|
||||
break;
|
||||
case SeqState::XFER_END:
|
||||
if (this->is_initiator)
|
||||
this->bus_obj->target_next_step();
|
||||
this->step_completed();
|
||||
break;
|
||||
case SeqState::SEND_DATA:
|
||||
if (this->bus_obj->push_data(this->dst_id, this->data_fifo, this->fifo_pos)) {
|
||||
this->to_xfer -= this->fifo_pos;
|
||||
this->fifo_pos = 0;
|
||||
if (this->to_xfer <= 0) {
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SeqState::RCV_DATA:
|
||||
// check for unexpected bus phase changes
|
||||
if (this->bus_obj->current_phase() != this->cur_bus_phase) {
|
||||
LOG_F(WARNING, "%s: phase mismatch!", this->name.c_str());
|
||||
} else {
|
||||
if (!this->rcv_data()) {
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SeqState::RCV_STATUS:
|
||||
case SeqState::RCV_MESSAGE:
|
||||
this->bus_obj->negotiate_xfer(this->fifo_pos, this->bytes_out);
|
||||
this->rcv_data();
|
||||
if (this->is_initiator) {
|
||||
if (this->cur_state == SeqState::RCV_MESSAGE)
|
||||
this->bus_obj->assert_ctrl_line(this->src_id, SCSI_CTRL_ACK);
|
||||
this->bus_obj->target_next_step();
|
||||
this->step_completed();
|
||||
this->cur_state = SeqState::IDLE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT_F("%s: unimplemented sequencer state %d", this->name.c_str(),
|
||||
this->cur_state);
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBusController::notify(ScsiMsg msg_type, int param) {
|
||||
switch (msg_type) {
|
||||
case ScsiMsg::CONFIRM_SEL:
|
||||
if (this->dst_id == param) {
|
||||
// cancel selection timeout timer
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
seq_timer_id = 0;
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
this->sequencer();
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: ignore invalid selection confirmation message",
|
||||
this->name.c_str());
|
||||
}
|
||||
break;
|
||||
case ScsiMsg::BUS_PHASE_CHANGE:
|
||||
this->cur_bus_phase = param;
|
||||
#if 0
|
||||
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(),
|
||||
msg_type);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiBusController::rcv_data() {
|
||||
int req_count;
|
||||
|
||||
// return if REQ line is negated
|
||||
if (!this->bus_obj->test_ctrl_lines(SCSI_CTRL_REQ)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->to_xfer)
|
||||
return false;
|
||||
|
||||
req_count = std::min(this->to_xfer, DATA_FIFO_DEPTH - this->fifo_pos);
|
||||
|
||||
this->bus_obj->pull_data(this->dst_id, &this->data_fifo[this->fifo_pos], req_count);
|
||||
this->fifo_pos += req_count;
|
||||
this->to_xfer -= req_count;
|
||||
return true;
|
||||
}
|
||||
|
||||
int ScsiBusController::send_data(uint8_t* dst_ptr, int count) {
|
||||
if (dst_ptr == nullptr || !count)
|
||||
return 0;
|
||||
|
||||
int actual_count = std::min(this->fifo_pos, count);
|
||||
|
||||
// move data out of the data FIFO
|
||||
std::memcpy(dst_ptr, this->data_fifo, actual_count);
|
||||
|
||||
// remove the just readed data from the data FIFO
|
||||
this->fifo_pos -= actual_count;
|
||||
this->to_xfer -= actual_count;
|
||||
if (this->fifo_pos > 0)
|
||||
std::memmove(this->data_fifo, &this->data_fifo[actual_count], this->fifo_pos);
|
||||
|
||||
return actual_count;
|
||||
}
|
||||
|
||||
int ScsiBusController::xfer_from(uint8_t *buf, int len) {
|
||||
if (len > this->to_xfer + this->fifo_pos)
|
||||
LOG_F(WARNING, "%s: DMA xfer len > command xfer len", this->name.c_str());
|
||||
|
||||
if (this->fifo_pos) {
|
||||
int fifo_bytes = std::min(this->fifo_pos, len);
|
||||
std::memcpy(buf, this->data_fifo, fifo_bytes);
|
||||
this->fifo_pos -= fifo_bytes;
|
||||
len -= fifo_bytes;
|
||||
buf += fifo_bytes;
|
||||
}
|
||||
|
||||
int dma_bytes = std::min(this->to_xfer, len);
|
||||
|
||||
if (this->bus_obj->pull_data(this->dst_id, buf, dma_bytes)) {
|
||||
this->to_xfer -= dma_bytes;
|
||||
if (this->to_xfer <= 0) {
|
||||
this->xfer_count = this->to_xfer;
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void ScsiBusController::update_irq() {
|
||||
uint8_t new_irq = !!(this->int_stat & this->int_mask);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiBusController::fifo_push(const uint8_t data) {
|
||||
if (this->fifo_pos < DATA_FIFO_DEPTH) {
|
||||
this->data_fifo[this->fifo_pos++] = data;
|
||||
if (!this->xfer_count)
|
||||
LOG_F(WARNING, "%s: zero xfer_count!", this->name.c_str());
|
||||
if (--this->xfer_count == 0)
|
||||
this->sequencer();
|
||||
} else
|
||||
this->sequencer();
|
||||
}
|
||||
|
||||
uint8_t ScsiBusController::fifo_pop() {
|
||||
uint8_t data = 0;
|
||||
|
||||
if (this->fifo_pos) {
|
||||
data = this->data_fifo[0];
|
||||
if (--this->fifo_pos)
|
||||
std::memmove(this->data_fifo, &this->data_fifo[1], this->fifo_pos);
|
||||
}
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->fifo_pos)
|
||||
this->sequencer();
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file SCSI bus controller definitions. */
|
||||
|
||||
#ifndef SCSI_BUS_CTRL_H
|
||||
#define SCSI_BUS_CTRL_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
|
||||
namespace Scsi_Bus_Controller {
|
||||
/** SCSI sequencer states. */
|
||||
enum SeqState : uint32_t {
|
||||
IDLE = 0,
|
||||
BUS_FREE,
|
||||
ARB_BEGIN,
|
||||
ARB_END,
|
||||
SEL_BEGIN,
|
||||
SEL_END,
|
||||
SEND_MSG,
|
||||
SEND_CMD,
|
||||
CMD_COMPLETE,
|
||||
XFER_BEGIN,
|
||||
XFER_END,
|
||||
SEND_DATA,
|
||||
RCV_DATA,
|
||||
RCV_STATUS,
|
||||
RCV_MESSAGE,
|
||||
};
|
||||
};
|
||||
|
||||
/** Sequencer error codes. */
|
||||
enum : int {
|
||||
ARB_LOST = 1,
|
||||
SEL_TIMEOUT,
|
||||
};
|
||||
|
||||
#define DATA_FIFO_DEPTH 16
|
||||
|
||||
class ScsiBusController : public ScsiDevice, public DmaDevice {
|
||||
public:
|
||||
ScsiBusController(std::string name, uint8_t my_bus_id=7) : ScsiDevice(name, my_bus_id) {
|
||||
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
|
||||
}
|
||||
~ScsiBusController() = default;
|
||||
|
||||
// implements SCSI FSM
|
||||
void sequencer();
|
||||
|
||||
virtual void step_completed() = 0;
|
||||
virtual void report_error(const int error) = 0;
|
||||
|
||||
// ScsiDevice methods
|
||||
void notify(ScsiMsg msg_type, int param);
|
||||
bool prepare_data() { return false; };
|
||||
bool get_more_data() { return false; };
|
||||
bool has_data() { return false; };
|
||||
bool rcv_data();
|
||||
int send_data(uint8_t* dst_ptr, int count);
|
||||
void process_command() {};
|
||||
|
||||
// DmaDevice methods
|
||||
int xfer_from(uint8_t *buf, int len); // must be marked OVERRIDE!
|
||||
|
||||
protected:
|
||||
void seq_defer_state(uint64_t delay_ns);
|
||||
void update_irq();
|
||||
void fifo_push(const uint8_t data);
|
||||
uint8_t fifo_pop();
|
||||
|
||||
ScsiBus* bus_obj = nullptr;
|
||||
uint8_t src_id;
|
||||
uint8_t dst_id;
|
||||
bool is_dma_cmd = false;
|
||||
bool is_initiator = true;
|
||||
bool assert_atn = false;
|
||||
|
||||
// Data FIFO state
|
||||
int fifo_pos = 0;
|
||||
int to_xfer = 0;
|
||||
uint32_t xfer_count = 0;
|
||||
int bytes_out = 0;
|
||||
uint8_t data_fifo[DATA_FIFO_DEPTH] = {};
|
||||
|
||||
// Sequencer state
|
||||
uint32_t seq_timer_id = 0;
|
||||
uint32_t cur_state = Scsi_Bus_Controller::SeqState::IDLE;
|
||||
uint32_t next_state = Scsi_Bus_Controller::SeqState::IDLE;
|
||||
int cur_bus_phase = 0;
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
uint8_t int_mask = 0;
|
||||
uint8_t int_stat = 0;
|
||||
};
|
||||
|
||||
#endif // SCSI_BUS_CTRL_H
|
||||
@@ -34,6 +34,11 @@ using namespace std;
|
||||
|
||||
ScsiCdrom::ScsiCdrom(std::string name, int my_id) : CdromDrive(), ScsiDevice(name, my_id)
|
||||
{
|
||||
this->set_error_callback(
|
||||
[this](uint8_t sense_key, uint8_t asc) {
|
||||
this->report_error(sense_key, asc);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void ScsiCdrom::process_command()
|
||||
@@ -85,7 +90,11 @@ void ScsiCdrom::process_command()
|
||||
|
||||
// CD-ROM specific commands
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->read_toc();
|
||||
this->bytes_out = read_toc(cmd, this->data_buf);
|
||||
if (this->status == ScsiStatus::GOOD) {
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "%s: unsupported command 0x%X", this->name.c_str(), cmd[0]);
|
||||
@@ -239,7 +248,7 @@ void ScsiCdrom::mode_sense_6()
|
||||
LOG_F(WARNING, "%s: unsupported page 0x%02x in MODE_SENSE_6", this->name.c_str(), page_code);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x24; // Invalid Field in CDB
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 2;
|
||||
@@ -270,85 +279,6 @@ void ScsiCdrom::mode_select_6(uint8_t param_len)
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
}
|
||||
|
||||
void ScsiCdrom::read_toc()
|
||||
{
|
||||
int tot_tracks;
|
||||
uint8_t start_track = this->cmd_buf[6];
|
||||
uint16_t alloc_len = (this->cmd_buf[7] << 8) + this->cmd_buf[8];
|
||||
bool is_msf = !!(this->cmd_buf[1] & 2);
|
||||
|
||||
if (this->cmd_buf[2] & 0xF) {
|
||||
ABORT_F("%s: unsupported format in READ_TOC", this->name.c_str());
|
||||
}
|
||||
|
||||
if (!alloc_len) {
|
||||
LOG_F(WARNING, "%s: zero allocation length passed to READ_TOC", this->name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!start_track) { // special case: track zero (lead-in) as starting track
|
||||
// return all tracks starting with track 1 plus lead-out
|
||||
start_track = 1;
|
||||
tot_tracks = this->num_tracks + 1;
|
||||
} else if (start_track == LEAD_OUT_TRK_NUM) {
|
||||
start_track = this->num_tracks + 1;
|
||||
tot_tracks = 1;
|
||||
} else if (start_track <= this->num_tracks) {
|
||||
tot_tracks = (this->num_tracks - start_track) + 2;
|
||||
} else {
|
||||
LOG_F(ERROR, "%s: invalid starting track %d in READ_TOC", this->name.c_str(),
|
||||
start_track);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x24; // Invalid Field in CDB
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 6; // offset of start_track
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t* buf_ptr = this->data_buf;
|
||||
|
||||
int data_len = (tot_tracks * 8) + 2;
|
||||
|
||||
// write TOC data header
|
||||
*buf_ptr++ = (data_len >> 8) & 0xFFU;
|
||||
*buf_ptr++ = (data_len >> 0) & 0xFFU;
|
||||
*buf_ptr++ = 1; // 1st track number
|
||||
*buf_ptr++ = this->num_tracks; // last track number
|
||||
|
||||
for (int tx = 0; tx < tot_tracks; tx++) {
|
||||
if ((buf_ptr - this->data_buf + 8) > alloc_len)
|
||||
break; // exit the loop if the output buffer length is exhausted
|
||||
|
||||
TrackDescriptor& td = this->tracks[start_track + tx - 1];
|
||||
|
||||
*buf_ptr++ = 0; // reserved
|
||||
*buf_ptr++ = td.adr_ctrl;
|
||||
*buf_ptr++ = td.trk_num;
|
||||
*buf_ptr++ = 0; // reserved
|
||||
|
||||
if (is_msf) {
|
||||
AddrMsf msf = lba_to_msf(td.start_lba + 150);
|
||||
*buf_ptr++ = 0; // reserved
|
||||
*buf_ptr++ = msf.min;
|
||||
*buf_ptr++ = msf.sec;
|
||||
*buf_ptr++ = msf.frm;
|
||||
} else {
|
||||
*buf_ptr++ = (td.start_lba >> 24) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 16) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 8) & 0xFFU;
|
||||
*buf_ptr++ = (td.start_lba >> 0) & 0xFFU;
|
||||
}
|
||||
}
|
||||
|
||||
this->bytes_out = alloc_len;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
void ScsiCdrom::read_capacity_10()
|
||||
{
|
||||
uint32_t lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
|
||||
@@ -361,7 +291,7 @@ void ScsiCdrom::read_capacity_10()
|
||||
LOG_F(ERROR, "%s: non-zero LBA for PMI=0", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x24; // Invalid Field in CDB
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 8;
|
||||
|
||||
@@ -48,7 +48,6 @@ protected:
|
||||
void mode_select_6(uint8_t param_len);
|
||||
|
||||
void mode_sense_6();
|
||||
void read_toc();
|
||||
void read_capacity_10();
|
||||
|
||||
private:
|
||||
|
||||
@@ -95,6 +95,7 @@ void ScsiDevice::next_step()
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->bus_obj->release_ctrl_line(this->scsi_id, SCSI_CTRL_REQ);
|
||||
this->switch_phase(ScsiPhase::MESSAGE_IN);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
@@ -221,13 +222,12 @@ int ScsiDevice::rcv_data(const uint8_t* src_ptr, const int count)
|
||||
return count;
|
||||
}
|
||||
|
||||
bool ScsiDevice::check_lun()
|
||||
{
|
||||
bool ScsiDevice::check_lun() {
|
||||
if (this->cmd_buf[1] >> 5 != this->lun) {
|
||||
LOG_F(ERROR, "%s: non-matching LUN", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x25; // Logical Unit Not Supported
|
||||
this->asc = ScsiError::INVALID_LUN;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0;
|
||||
this->field = 0;
|
||||
@@ -237,14 +237,22 @@ bool ScsiDevice::check_lun()
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiDevice::illegal_command(const uint8_t *cmd)
|
||||
{
|
||||
void ScsiDevice::illegal_command(const uint8_t *cmd) {
|
||||
LOG_F(ERROR, "%s: unsupported command: 0x%02x", this->name.c_str(), cmd[0]);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x20; // Invalid command operation code
|
||||
this->asc = ScsiError::INVALID_CMD;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
|
||||
void ScsiDevice::report_error(uint8_t sense_key, uint8_t asc) {
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = sense_key;
|
||||
this->asc = asc;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
@@ -66,18 +66,12 @@ void ScsiHardDisk::process_command() {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
this->test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::REWIND:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
this->req_sense(cmd[4]);
|
||||
break;
|
||||
case ScsiCommand::FORMAT_UNIT:
|
||||
this->format();
|
||||
break;
|
||||
case ScsiCommand::READ_BLK_LIMITS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
this->read(lba, cmd[4], 6);
|
||||
@@ -86,36 +80,15 @@ void ScsiHardDisk::process_command() {
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
this->write(lba, cmd[4], 6);
|
||||
break;
|
||||
case ScsiCommand::SEEK_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->inquiry();
|
||||
break;
|
||||
case ScsiCommand::VERIFY_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
mode_select_6(cmd[4]);
|
||||
break;
|
||||
case ScsiCommand::RELEASE_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::ERASE_6:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->mode_sense_6();
|
||||
break;
|
||||
case ScsiCommand::START_STOP_UNIT:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::DIAG_RESULTS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SEND_DIAGS:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
this->eject_allowed = (cmd[4] & 1) == 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
@@ -135,29 +108,9 @@ void ScsiHardDisk::process_command() {
|
||||
this->write(lba, READ_WORD_BE_U(&cmd[7]), 10);
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
break;
|
||||
case ScsiCommand::VERIFY_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_BUFFER:
|
||||
read_buffer();
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_10:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_12:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
|
||||
// CD-ROM specific commands
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::SET_CD_SPEED:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
case ScsiCommand::READ_CD:
|
||||
this->illegal_command(cmd);
|
||||
break;
|
||||
default:
|
||||
this->illegal_command(cmd);
|
||||
}
|
||||
@@ -205,7 +158,7 @@ int ScsiHardDisk::req_sense(uint16_t alloc_len) {
|
||||
//if (!check_lun())
|
||||
// return;
|
||||
|
||||
int next_phase;
|
||||
//int next_phase;
|
||||
|
||||
int lun;
|
||||
if (this->last_selection_has_atention) {
|
||||
@@ -226,7 +179,7 @@ int ScsiHardDisk::req_sense(uint16_t alloc_len) {
|
||||
}
|
||||
else {
|
||||
this->data_buf[ 2] = this->sense; // Reserved:0xf0, Sense Key:0x0f ; e.g. ScsiSense::ILLEGAL_REQ
|
||||
this->data_buf[12] = 0x25; // addition sense code = Logical Unit Not Supported
|
||||
this->data_buf[12] = ScsiError::INVALID_LUN; // addition sense code = Logical Unit Not Supported
|
||||
this->data_buf[13] = 0; // additional sense qualifier
|
||||
this->data_buf[15] = 0; // SKSV:0x80, C/D:0x40, Reserved:0x30, BPV:8, Bit Pointer:7
|
||||
this->data_buf[16] = 0; // field pointer
|
||||
@@ -339,9 +292,9 @@ void ScsiHardDisk::mode_sense_6() {
|
||||
LOG_F(INFO, "%s: page_ctrl 1 CHANGEABLE VALUES is not implemented", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x24; // Invalid Field in CDB
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 2;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
@@ -351,9 +304,9 @@ void ScsiHardDisk::mode_sense_6() {
|
||||
LOG_F(ERROR, "%s: page_ctrl 2 DEFAULT VALUES is not implemented", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x24; // Invalid Field in CDB
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 2;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
@@ -363,7 +316,7 @@ void ScsiHardDisk::mode_sense_6() {
|
||||
LOG_F(INFO, "%s: page_ctrl 3 SAVED VALUES is not implemented", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x39; // Saving Parameters Not Supported
|
||||
this->asc = SAVING_NOT_SUPPORTED;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0;
|
||||
this->field = 0;
|
||||
@@ -428,9 +381,9 @@ void ScsiHardDisk::mode_sense_6() {
|
||||
LOG_F(WARNING, "%s: unsupported page 0x%02x in MODE_SENSE_6", this->name.c_str(), page_code);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x24; // Invalid Field in CDB
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 2;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
@@ -438,9 +391,9 @@ void ScsiHardDisk::mode_sense_6() {
|
||||
LOG_F(WARNING, "%s: unsupported page/subpage %02xh/%02xh in MODE_SENSE_6", this->name.c_str(), page_code, sub_page_code);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x24; // Invalid Field in CDB
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 3;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
@@ -465,9 +418,9 @@ void ScsiHardDisk::read_capacity_10() {
|
||||
LOG_F(ERROR, "%s: non-zero LBA for PMI=0", this->name.c_str());
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->asc = 0x24; // Invalid Field in CDB
|
||||
this->asc = ScsiError::INVALID_CDB;
|
||||
this->ascq = 0;
|
||||
this->sksv = 0xc0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->sksv = 0xC0; // sksv=1, C/D=Command, BPV=0, BP=0
|
||||
this->field = 8;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
|
||||
+141
-115
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -47,24 +47,21 @@ ViaCuda::ViaCuda() {
|
||||
// VIA reset clears all internal registers to logic 0
|
||||
// except timers/counters and the shift register
|
||||
// as stated in the 6522 datasheet
|
||||
this->via_regs[VIA_A] = 0;
|
||||
this->via_regs[VIA_B] = 0;
|
||||
this->via_regs[VIA_DIRB] = 0;
|
||||
this->via_regs[VIA_DIRA] = 0;
|
||||
this->via_regs[VIA_IER] = 0;
|
||||
this->via_regs[VIA_ACR] = 0;
|
||||
this->via_regs[VIA_PCR] = 0;
|
||||
this->via_regs[VIA_IFR] = 0;
|
||||
this->via_porta = 0;
|
||||
this->via_portb = 0;
|
||||
this->via_ddrb = 0;
|
||||
this->via_ddra = 0;
|
||||
this->via_acr = 0;
|
||||
this->via_pcr = 0;
|
||||
|
||||
// load maximum value into the timer registers for safety
|
||||
// (not prescribed in the 6522 datasheet)
|
||||
this->via_regs[VIA_T1LL] = 0xFF;
|
||||
this->via_regs[VIA_T1LH] = 0xFF;
|
||||
this->via_regs[VIA_T2CL] = 0xFF;
|
||||
this->via_regs[VIA_T2CH] = 0xFF;
|
||||
this->via_t1ll = 0xFF;
|
||||
this->via_t1lh = 0xFF;
|
||||
this->via_t2cl = 0xFF;
|
||||
|
||||
this->_via_ifr = 0; // all flags cleared
|
||||
this->_via_ier = 0; // all interrupts disabled
|
||||
this->_via_ifr = 0; // all flags cleared
|
||||
this->_via_ier = 0; // all interrupts disabled
|
||||
|
||||
// intialize counters/timers
|
||||
this->t1_counter = 0xFFFF;
|
||||
@@ -138,73 +135,151 @@ void ViaCuda::cuda_init() {
|
||||
|
||||
uint8_t ViaCuda::read(int reg) {
|
||||
uint8_t value;
|
||||
/* reading from some VIA registers triggers special actions */
|
||||
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
value = (this->via_regs[VIA_B]);
|
||||
break;
|
||||
return this->via_portb; //(this->via_portb & ~this->via_ddrb) | this->last_orb;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
value = this->via_regs[reg & 0xF];
|
||||
LOG_F(WARNING, "Attempted read from VIA Port A!");
|
||||
break;
|
||||
case VIA_IER:
|
||||
value = (this->_via_ier | 0x80); // bit 7 always reads as "1"
|
||||
break;
|
||||
case VIA_IFR:
|
||||
value = this->_via_ifr;
|
||||
break;
|
||||
return this->via_porta;
|
||||
case VIA_DIRB:
|
||||
return this->via_ddrb;
|
||||
case VIA_DIRA:
|
||||
return this->via_ddra;
|
||||
case VIA_T1CL:
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
value = this->calc_counter_val(this->t1_counter, this->t1_start_time) & 0xFFU;
|
||||
break;
|
||||
return this->calc_counter_val(this->t1_counter, this->t1_start_time) & 0xFFU;
|
||||
case VIA_T1CH:
|
||||
value = this->calc_counter_val(this->t1_counter, this->t1_start_time) >> 8;
|
||||
break;
|
||||
return this->calc_counter_val(this->t1_counter, this->t1_start_time) >> 8;
|
||||
case VIA_T1LL:
|
||||
return this->via_t1ll;
|
||||
case VIA_T1LH:
|
||||
return this->via_t1lh;
|
||||
case VIA_T2CL:
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
value = this->calc_counter_val(this->t2_counter, this->t2_start_time) & 0xFFU;
|
||||
break;
|
||||
return this->calc_counter_val(this->t2_counter, this->t2_start_time) & 0xFFU;
|
||||
case VIA_T2CH:
|
||||
value = this->calc_counter_val(this->t2_counter, this->t2_start_time) >> 8;
|
||||
break;
|
||||
return this->calc_counter_val(this->t2_counter, this->t2_start_time) >> 8;
|
||||
case VIA_SR:
|
||||
value = this->via_regs[reg & 0xF];
|
||||
value = this->via_sr;
|
||||
this->_via_ifr &= ~VIA_IF_SR;
|
||||
update_irq();
|
||||
break;
|
||||
default:
|
||||
value = this->via_regs[reg & 0xF];
|
||||
return value;
|
||||
case VIA_ACR:
|
||||
return this->via_acr;
|
||||
case VIA_PCR:
|
||||
return this->via_pcr;
|
||||
case VIA_IFR:
|
||||
return this->_via_ifr;
|
||||
case VIA_IER:
|
||||
return (this->_via_ier | 0x80); // bit 7 always reads as "1"
|
||||
}
|
||||
|
||||
return value;
|
||||
return 0; // should never happen!
|
||||
}
|
||||
|
||||
void ViaCuda::write(int reg, uint8_t value) {
|
||||
this->via_regs[reg & 0xF] = value;
|
||||
|
||||
switch (reg & 0xF) {
|
||||
case VIA_B:
|
||||
this->write(value);
|
||||
this->last_orb = value & this->via_ddrb;
|
||||
this->via_portb = (this->via_portb & ~this->via_ddrb) | this->last_orb;
|
||||
// ensure the proper VIA configuration before calling Cuda
|
||||
if ((this->via_ddrb & 0x38) == 0x30)
|
||||
this->write(this->via_portb);
|
||||
break;
|
||||
case VIA_A:
|
||||
case VIA_ANH:
|
||||
this->via_porta = value;
|
||||
LOG_F(WARNING, "Attempted write to VIA Port A!");
|
||||
break;
|
||||
case VIA_DIRB:
|
||||
this->via_ddrb = value;
|
||||
LOG_F(9, "VIA_DIRB = 0x%X", value);
|
||||
break;
|
||||
case VIA_DIRA:
|
||||
this->via_ddra = value;
|
||||
LOG_F(9, "VIA_DIRA = 0x%X", value);
|
||||
break;
|
||||
case VIA_PCR:
|
||||
LOG_F(9, "VIA_PCR = 0x%X", value);
|
||||
case VIA_T1CL:
|
||||
this->via_t1cl = value;
|
||||
break;
|
||||
case VIA_T1CH:
|
||||
if (this->via_acr & 0xC0) {
|
||||
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_acr);
|
||||
}
|
||||
// cancel active T1 timer task
|
||||
if (this->t1_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_timer_id = 0;
|
||||
}
|
||||
// clear T1 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
// load initial value into counter 1
|
||||
this->t1_counter = (value << 8) | this->via_t1cl;
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timout timer for T1
|
||||
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->t1_timer_id = 0;
|
||||
this->assert_t1_int();
|
||||
}
|
||||
);
|
||||
break;
|
||||
case VIA_T1LL:
|
||||
this->via_t1ll = value;
|
||||
break;
|
||||
case VIA_T1LH:
|
||||
this->via_t1lh = value;
|
||||
break;
|
||||
case VIA_T2CL:
|
||||
this->via_t2cl = value;
|
||||
break;
|
||||
case VIA_T2CH:
|
||||
if (this->via_acr & 0x20) {
|
||||
ABORT_F("VIA T2 pulse count mode not supported!");
|
||||
}
|
||||
// cancel active T2 timer task
|
||||
if (this->t2_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_timer_id = 0;
|
||||
}
|
||||
// clear T2 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
// load initial value into counter 2
|
||||
this->t2_counter = (value << 8) | this->via_t2cl;
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timeout timer for T2
|
||||
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t2_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->t2_timer_id = 0;
|
||||
this->assert_t2_int();
|
||||
}
|
||||
);
|
||||
break;
|
||||
case VIA_SR:
|
||||
this->via_sr = value;
|
||||
this->_via_ifr &= ~VIA_IF_SR;
|
||||
update_irq();
|
||||
break;
|
||||
case VIA_ACR:
|
||||
this->via_acr = value;
|
||||
LOG_F(9, "VIA_ACR = 0x%X", value);
|
||||
break;
|
||||
case VIA_PCR:
|
||||
this->via_pcr = value;
|
||||
LOG_F(9, "VIA_PCR = 0x%X", value);
|
||||
break;
|
||||
case VIA_IFR:
|
||||
// for each "1" in value clear the corresponding flags
|
||||
this->_via_ifr &= ~value;
|
||||
@@ -219,62 +294,6 @@ void ViaCuda::write(int reg, uint8_t value) {
|
||||
update_irq();
|
||||
print_enabled_ints();
|
||||
break;
|
||||
case VIA_T1CH:
|
||||
if (this->via_regs[VIA_ACR] & 0xC0) {
|
||||
ABORT_F("Unsupported VIA T1 mode, ACR=0x%X", this->via_regs[VIA_ACR]);
|
||||
}
|
||||
// cancel active T1 timer task
|
||||
if (this->t1_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t1_timer_id);
|
||||
this->t1_timer_id = 0;
|
||||
}
|
||||
// clear T1 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T1;
|
||||
update_irq();
|
||||
// load initial value into counter 1
|
||||
this->t1_counter = (value << 8) | this->via_regs[VIA_T1CL];
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t1_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timout timer for T1
|
||||
this->t1_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t1_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->t1_timer_id = 0;
|
||||
this->assert_t1_int();
|
||||
}
|
||||
);
|
||||
break;
|
||||
case VIA_T2CH:
|
||||
if (this->via_regs[VIA_ACR] & 0x20) {
|
||||
ABORT_F("VIA T2 pulse count mode not supported!");
|
||||
}
|
||||
// cancel active T2 timer task
|
||||
if (this->t2_timer_id) {
|
||||
TimerManager::get_instance()->cancel_timer(this->t2_timer_id);
|
||||
this->t2_timer_id = 0;
|
||||
}
|
||||
// clear T2 flag in IFR
|
||||
this->_via_ifr &= ~VIA_IF_T2;
|
||||
update_irq();
|
||||
// load initial value into counter 2
|
||||
this->t2_counter = (value << 8) | this->via_regs[VIA_T2CL];
|
||||
// TODO: delay for one phase 2 clock
|
||||
// sample current vCPU time and remember it
|
||||
this->t2_start_time = TimerManager::get_instance()->current_time_ns();
|
||||
// set up timeout timer for T2
|
||||
this->t2_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
static_cast<uint64_t>(this->via_clk_dur * (this->t2_counter + 3) + 0.5f),
|
||||
[this]() {
|
||||
this->t2_timer_id = 0;
|
||||
this->assert_t2_int();
|
||||
}
|
||||
);
|
||||
break;
|
||||
case VIA_SR:
|
||||
this->_via_ifr &= ~VIA_IF_SR;
|
||||
update_irq();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,7 +387,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
int new_tip = !!(new_state & CUDA_TIP);
|
||||
int new_byteack = !!(new_state & CUDA_BYTEACK);
|
||||
|
||||
/* return if there is no state change */
|
||||
// return if there is no state change
|
||||
if (new_tip == this->old_tip && new_byteack == this->old_byteack)
|
||||
return;
|
||||
|
||||
@@ -377,7 +396,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
|
||||
if (new_tip) {
|
||||
if (new_byteack) {
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->via_portb |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
|
||||
if (this->in_count) {
|
||||
@@ -387,7 +406,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
this->treq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
USECS_TO_NSECS(13), // delay TREQ assertion for New World
|
||||
[this]() {
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
|
||||
this->via_portb &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
this->treq_timer_id = 0;
|
||||
});
|
||||
@@ -396,7 +415,7 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
this->in_count = 0;
|
||||
} else {
|
||||
LOG_F(9, "Cuda: enter sync state");
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ; // assert TREQ
|
||||
this->via_portb &= ~CUDA_TREQ; // assert TREQ
|
||||
this->treq = 0;
|
||||
this->in_count = 0;
|
||||
this->out_count = 0;
|
||||
@@ -405,9 +424,9 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
// send dummy byte as idle acknowledge or attention
|
||||
schedule_sr_int(USECS_TO_NSECS(61));
|
||||
} else {
|
||||
if (this->via_regs[VIA_ACR] & 0x10) { // data transfer: Host --> Cuda
|
||||
if (this->via_acr & 0x10) { // data transfer: Host --> Cuda
|
||||
if (this->in_count < sizeof(this->in_buf)) {
|
||||
this->in_buf[this->in_count++] = this->via_regs[VIA_SR];
|
||||
this->in_buf[this->in_count++] = this->via_sr;
|
||||
// tell the system we've read the byte after 71 usecs
|
||||
schedule_sr_int(USECS_TO_NSECS(71));
|
||||
} else {
|
||||
@@ -423,22 +442,22 @@ void ViaCuda::write(uint8_t new_state) {
|
||||
|
||||
/* sends zeros to host ad infinitum */
|
||||
void ViaCuda::null_out_handler() {
|
||||
this->via_regs[VIA_SR] = 0;
|
||||
this->via_sr = 0;
|
||||
}
|
||||
|
||||
/* sends PRAM content to host ad infinitum */
|
||||
void ViaCuda::pram_out_handler()
|
||||
{
|
||||
this->via_regs[VIA_SR] = this->pram_obj->read_byte(this->cur_pram_addr++);
|
||||
this->via_sr = this->pram_obj->read_byte(this->cur_pram_addr++);
|
||||
}
|
||||
|
||||
/* sends data from out_buf until exhausted, then switches to next_out_handler */
|
||||
void ViaCuda::out_buf_handler() {
|
||||
if (this->out_pos < this->out_count) {
|
||||
this->via_regs[VIA_SR] = this->out_buf[this->out_pos++];
|
||||
this->via_sr = this->out_buf[this->out_pos++];
|
||||
if (!this->is_open_ended && this->out_pos >= this->out_count) {
|
||||
// tell the host this will be the last byte
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->via_portb |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
}
|
||||
} else if (this->is_open_ended) {
|
||||
@@ -447,7 +466,7 @@ void ViaCuda::out_buf_handler() {
|
||||
(this->*out_handler)();
|
||||
} else {
|
||||
this->out_count = 0;
|
||||
this->via_regs[VIA_B] |= CUDA_TREQ; // negate TREQ
|
||||
this->via_portb |= CUDA_TREQ; // negate TREQ
|
||||
this->treq = 1;
|
||||
}
|
||||
}
|
||||
@@ -533,7 +552,7 @@ void ViaCuda::autopoll_handler() {
|
||||
}
|
||||
|
||||
// assert TREQ
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ;
|
||||
this->via_portb &= ~CUDA_TREQ;
|
||||
this->treq = 0;
|
||||
|
||||
// draw guest system's attention
|
||||
@@ -562,7 +581,7 @@ void ViaCuda::autopoll_handler() {
|
||||
this->last_time = this_time;
|
||||
|
||||
// assert TREQ
|
||||
this->via_regs[VIA_B] &= ~CUDA_TREQ;
|
||||
this->via_portb &= ~CUDA_TREQ;
|
||||
this->treq = 0;
|
||||
|
||||
// draw guest system's attention
|
||||
@@ -691,6 +710,9 @@ void ViaCuda::pseudo_command() {
|
||||
this->one_sec_mode = this->in_buf[2];
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_SET_POWER_MESSAGES:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
break;
|
||||
case CUDA_READ_WRITE_I2C:
|
||||
response_header(CUDA_PKT_PSEUDO, 0);
|
||||
i2c_simple_transaction(this->in_buf[2], &this->in_buf[3], this->in_count - 3);
|
||||
@@ -711,8 +733,12 @@ void ViaCuda::pseudo_command() {
|
||||
power_on = false;
|
||||
power_off_reason = po_restart;
|
||||
break;
|
||||
case CUDA_WARM_START:
|
||||
case CUDA_POWER_DOWN:
|
||||
LOG_F(INFO, "Cuda: system shutdown");
|
||||
power_on = false;
|
||||
power_off_reason = po_shut_down;
|
||||
break;
|
||||
case CUDA_WARM_START:
|
||||
case CUDA_MONO_STABLE_RESET:
|
||||
/* really kludge temp code */
|
||||
LOG_F(INFO, "Cuda: Restart/Shutdown signal sent with command 0x%x!", cmd);
|
||||
@@ -733,7 +759,7 @@ uint32_t ViaCuda::calc_real_time() {
|
||||
|
||||
/* sends data from the current I2C to host ad infinitum */
|
||||
void ViaCuda::i2c_handler() {
|
||||
this->receive_byte(this->curr_i2c_addr, &this->via_regs[VIA_SR]);
|
||||
this->receive_byte(this->curr_i2c_addr, &this->via_sr);
|
||||
}
|
||||
|
||||
void ViaCuda::i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, int in_bytes) {
|
||||
|
||||
+63
-51
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -57,22 +57,22 @@ class InterruptCtrl;
|
||||
|
||||
/** VIA register offsets. */
|
||||
enum {
|
||||
VIA_B = 0x00, /* input/output register B */
|
||||
VIA_A = 0x01, /* input/output register A */
|
||||
VIA_DIRB = 0x02, /* direction B */
|
||||
VIA_DIRA = 0x03, /* direction A */
|
||||
VIA_T1CL = 0x04, /* low-order timer 1 counter */
|
||||
VIA_T1CH = 0x05, /* high-order timer 1 counter */
|
||||
VIA_T1LL = 0x06, /* low-order timer 1 latches */
|
||||
VIA_T1LH = 0x07, /* high-order timer 1 latches */
|
||||
VIA_T2CL = 0x08, /* low-order timer 2 latches */
|
||||
VIA_T2CH = 0x09, /* high-order timer 2 counter */
|
||||
VIA_SR = 0x0A, /* shift register */
|
||||
VIA_ACR = 0x0B, /* auxiliary control register */
|
||||
VIA_PCR = 0x0C, /* periheral control register */
|
||||
VIA_IFR = 0x0D, /* interrupt flag register */
|
||||
VIA_IER = 0x0E, /* interrupt enable register */
|
||||
VIA_ANH = 0x0F, /* input/output register A, no handshake */
|
||||
VIA_B = 0x00, // input/output register B
|
||||
VIA_A = 0x01, // input/output register A
|
||||
VIA_DIRB = 0x02, // direction B
|
||||
VIA_DIRA = 0x03, // direction A
|
||||
VIA_T1CL = 0x04, // low-order timer 1 counter
|
||||
VIA_T1CH = 0x05, // high-order timer 1 counter
|
||||
VIA_T1LL = 0x06, // low-order timer 1 latches
|
||||
VIA_T1LH = 0x07, // high-order timer 1 latches
|
||||
VIA_T2CL = 0x08, // low-order timer 2 latches
|
||||
VIA_T2CH = 0x09, // high-order timer 2 counter
|
||||
VIA_SR = 0x0A, // shift register
|
||||
VIA_ACR = 0x0B, // auxiliary control register
|
||||
VIA_PCR = 0x0C, // periheral control register
|
||||
VIA_IFR = 0x0D, // interrupt flag register
|
||||
VIA_IER = 0x0E, // interrupt enable register
|
||||
VIA_ANH = 0x0F, // input/output register A, no handshake
|
||||
};
|
||||
|
||||
/** VIA interrupt flags */
|
||||
@@ -93,11 +93,11 @@ enum class ViaLine {
|
||||
CB2
|
||||
};
|
||||
|
||||
/** Cuda communication signals. */
|
||||
/** Cuda communication signals (active low -> 0 - true, 1 - false). */
|
||||
enum {
|
||||
CUDA_TIP = 0x20, /* transaction in progress: 0 - true, 1 - false */
|
||||
CUDA_BYTEACK = 0x10, /* byte acknowledge: 0 - true, 1 - false */
|
||||
CUDA_TREQ = 0x08 /* Cuda requests transaction from host */
|
||||
CUDA_TIP = 0x20, // transaction in progress
|
||||
CUDA_BYTEACK = 0x10, // byte acknowledge/handshake
|
||||
CUDA_TREQ = 0x08 // Cuda requests transaction from host
|
||||
};
|
||||
|
||||
/** Cuda packet types. */
|
||||
@@ -111,40 +111,41 @@ enum {
|
||||
|
||||
/** Cuda pseudo commands. */
|
||||
enum {
|
||||
CUDA_WARM_START = 0x00, /* warm start */
|
||||
CUDA_START_STOP_AUTOPOLL = 0x01, /* start/stop device auto-polling */
|
||||
CUDA_READ_MCU_MEM = 0x02, /* read internal Cuda memory */
|
||||
CUDA_GET_REAL_TIME = 0x03, /* get real time */
|
||||
CUDA_READ_PRAM = 0x07, /* read parameter RAM */
|
||||
CUDA_WRITE_MCU_MEM = 0x08, /* write internal Cuda memory */
|
||||
CUDA_SET_REAL_TIME = 0x09, /* set real time */
|
||||
CUDA_POWER_DOWN = 0x0A, /* power down system */
|
||||
CUDA_WRITE_PRAM = 0x0C, /* write parameter RAM */
|
||||
CUDA_MONO_STABLE_RESET = 0x0D, /* mono stable reset */
|
||||
CUDA_RESTART_SYSTEM = 0x11, /* restart system */
|
||||
CUDA_FILE_SERVER_FLAG = 0x13, /* set file server flag */
|
||||
CUDA_SET_AUTOPOLL_RATE = 0x14, /* set auto-polling rate */
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, /* get auto-polling rate */
|
||||
CUDA_SET_DEVICE_LIST = 0x19, /* set device list */
|
||||
CUDA_GET_DEVICE_LIST = 0x1A, /* get device list */
|
||||
CUDA_ONE_SECOND_MODE = 0x1B, /* one second interrupt mode */
|
||||
CUDA_READ_WRITE_I2C = 0x22, /* read/write I2C device */
|
||||
CUDA_COMB_FMT_I2C = 0x25, /* combined format I2C transaction */
|
||||
CUDA_OUT_PB0 = 0x26, /* output one bit to Cuda's PB0 line */
|
||||
CUDA_WARM_START = 0x00, // warm start
|
||||
CUDA_START_STOP_AUTOPOLL = 0x01, // start/stop device auto-polling
|
||||
CUDA_READ_MCU_MEM = 0x02, // read internal Cuda memory
|
||||
CUDA_GET_REAL_TIME = 0x03, // get real time
|
||||
CUDA_READ_PRAM = 0x07, // read parameter RAM
|
||||
CUDA_WRITE_MCU_MEM = 0x08, // write internal Cuda memory
|
||||
CUDA_SET_REAL_TIME = 0x09, // set real time
|
||||
CUDA_POWER_DOWN = 0x0A, // power down system
|
||||
CUDA_WRITE_PRAM = 0x0C, // write parameter RAM
|
||||
CUDA_MONO_STABLE_RESET = 0x0D, // mono stable reset
|
||||
CUDA_RESTART_SYSTEM = 0x11, // restart system
|
||||
CUDA_FILE_SERVER_FLAG = 0x13, // set file server flag
|
||||
CUDA_SET_AUTOPOLL_RATE = 0x14, // set auto-polling rate
|
||||
CUDA_GET_AUTOPOLL_RATE = 0x16, // get auto-polling rate
|
||||
CUDA_SET_DEVICE_LIST = 0x19, // set device list
|
||||
CUDA_GET_DEVICE_LIST = 0x1A, // get device list
|
||||
CUDA_ONE_SECOND_MODE = 0x1B, // one second interrupt mode
|
||||
CUDA_SET_POWER_MESSAGES = 0x21, // set power message flag
|
||||
CUDA_READ_WRITE_I2C = 0x22, // read/write I2C device
|
||||
CUDA_COMB_FMT_I2C = 0x25, // combined format I2C transaction
|
||||
CUDA_OUT_PB0 = 0x26, // output one bit to Cuda's PB0 line
|
||||
};
|
||||
|
||||
/** Cuda error codes. */
|
||||
enum {
|
||||
CUDA_ERR_BAD_PKT = 1, /* invalid packet type */
|
||||
CUDA_ERR_BAD_CMD = 2, /* invalid pseudo command */
|
||||
CUDA_ERR_BAD_SIZE = 3, /* invalid packet size */
|
||||
CUDA_ERR_BAD_PAR = 4, /* invalid parameter */
|
||||
CUDA_ERR_I2C = 5 /* invalid I2C data or no acknowledge */
|
||||
CUDA_ERR_BAD_PKT = 1, // invalid packet type
|
||||
CUDA_ERR_BAD_CMD = 2, // invalid pseudo command
|
||||
CUDA_ERR_BAD_SIZE = 3, // invalid packet size
|
||||
CUDA_ERR_BAD_PAR = 4, // invalid parameter
|
||||
CUDA_ERR_I2C = 5 // invalid I2C data or no acknowledge
|
||||
};
|
||||
|
||||
#define CUDA_IN_BUF_SIZE 256
|
||||
|
||||
/** PRAM addresses within Cuda's internal memory */
|
||||
/** PRAM addresses within Cuda's internal memory. */
|
||||
#define CUDA_PRAM_START 0x100 // starting address of PRAM
|
||||
#define CUDA_PRAM_END 0x1FF // last byte of PRAM
|
||||
#define CUDA_ROM_START 0xF00 // starting address of ROM containing Cuda FW
|
||||
@@ -176,12 +177,23 @@ public:
|
||||
|
||||
private:
|
||||
// VIA virtual HW registers
|
||||
uint8_t via_regs[16];
|
||||
uint8_t via_portb = 0;
|
||||
uint8_t via_porta = 0;
|
||||
uint8_t via_ddrb = 0;
|
||||
uint8_t via_ddra = 0;
|
||||
uint8_t via_t1cl = 0xFF;
|
||||
uint8_t via_t1ll = 0xFF;
|
||||
uint8_t via_t1lh = 0xFF;
|
||||
uint8_t via_t2cl = 0xFF;
|
||||
uint8_t via_sr;
|
||||
uint8_t via_acr = 0;
|
||||
uint8_t via_pcr = 0;
|
||||
|
||||
float via_clk_dur; // one VIA clock duration = 1,27655 us
|
||||
|
||||
// VIA internal state
|
||||
uint32_t sr_timer_id = 0;
|
||||
uint8_t last_orb = 0; // last value written to the ORB register.
|
||||
|
||||
// timer 1 state
|
||||
uint16_t t1_counter;
|
||||
@@ -259,8 +271,8 @@ private:
|
||||
|
||||
/* I2C related methods */
|
||||
void i2c_simple_transaction(uint8_t dev_addr, const uint8_t* in_buf, int in_bytes);
|
||||
void i2c_comb_transaction(
|
||||
uint8_t dev_addr, uint8_t sub_addr, uint8_t dev_addr1, const uint8_t* in_buf, int in_bytes);
|
||||
void i2c_comb_transaction(uint8_t dev_addr, uint8_t sub_addr, uint8_t dev_addr1,
|
||||
const uint8_t* in_buf, int in_bytes);
|
||||
};
|
||||
|
||||
#endif /* VIACUDA_H */
|
||||
#endif // VIACUDA_H
|
||||
+65
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -32,11 +32,24 @@ using namespace MaceEnet;
|
||||
uint8_t MaceController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::Interrupt:
|
||||
LOG_F(INFO, "MACE: all interrupt flags cleared");
|
||||
return 0;
|
||||
case MaceReg::Rcv_Frame_Ctrl:
|
||||
return this->rcv_fc;
|
||||
case MaceReg::Interrupt: {
|
||||
uint8_t ret_val = this->int_stat;
|
||||
this->int_stat = 0;
|
||||
LOG_F(9, "%s: all interrupt flags cleared", this->name.c_str());
|
||||
return ret_val;
|
||||
}
|
||||
case MaceReg::Interrupt_Mask:
|
||||
return this->int_mask;
|
||||
case MaceReg::BIU_Config_Ctrl:
|
||||
return this->biu_ctrl;
|
||||
case MaceReg::Chip_ID_Lo:
|
||||
return this->chip_id & 0xFFU;
|
||||
case MaceReg::Chip_ID_Hi:
|
||||
return (this->chip_id >> 8) & 0xFFU;
|
||||
default:
|
||||
LOG_F(INFO, "Reading MACE register %d", reg_offset);
|
||||
LOG_F(INFO, "%s: reading from register %d", this->name.c_str(), reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -45,15 +58,57 @@ uint8_t MaceController::read(uint8_t reg_offset)
|
||||
void MaceController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MaceReg::Rcv_Frame_Ctrl:
|
||||
this->rcv_fc = value;
|
||||
break;
|
||||
case MaceReg::Interrupt_Mask:
|
||||
this->int_mask = value;
|
||||
break;
|
||||
case MaceReg::MAC_Config_Ctrl:
|
||||
this->mac_cfg = value;
|
||||
break;
|
||||
case MaceReg::BIU_Config_Ctrl:
|
||||
if (value & 1) {
|
||||
LOG_F(INFO, "MACE Reset issued");
|
||||
} else {
|
||||
LOG_F(INFO, "MACE BIU Config set to 0x%X", value);
|
||||
if (value & BIU_SWRST) {
|
||||
LOG_F(INFO, "%s: soft reset asserted", this->name.c_str());
|
||||
value &= ~BIU_SWRST; // acknowledge soft reset
|
||||
}
|
||||
this->biu_ctrl = value;
|
||||
break;
|
||||
case MaceReg::PLS_Config_Ctrl:
|
||||
if (value != 7)
|
||||
LOG_F(WARNING, "%s: unsupported transceiver interface 0x%X in PLSCC",
|
||||
this->name.c_str(), value);
|
||||
break;
|
||||
case MaceReg::Int_Addr_Config:
|
||||
if ((value & IAC_LOGADDR) && (value & IAC_PHYADDR))
|
||||
value &= ~IAC_PHYADDR;
|
||||
if (value & (IAC_LOGADDR | IAC_PHYADDR))
|
||||
this->addr_ptr = 0;
|
||||
this->addr_cfg = value;
|
||||
break;
|
||||
case MaceReg::Log_Addr_Flt:
|
||||
if (this->addr_cfg & IAC_LOGADDR) {
|
||||
uint64_t mask = ~(0xFFULL << (this->addr_ptr * 8));
|
||||
this->log_addr = (this->log_addr & mask) | ((uint64_t)value << (this->addr_ptr * 8));
|
||||
if (++this->addr_ptr >= 8) {
|
||||
this->addr_cfg &= ~IAC_LOGADDR;
|
||||
this->addr_ptr = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MaceReg::Phys_Addr:
|
||||
if (this->addr_cfg & IAC_PHYADDR) {
|
||||
uint64_t mask = ~(0xFFULL << (this->addr_ptr * 8));
|
||||
this->phys_addr = (this->phys_addr & mask) | ((uint64_t)value << (this->addr_ptr * 8));
|
||||
if (++this->addr_ptr >= 6) {
|
||||
this->addr_cfg &= ~IAC_PHYADDR;
|
||||
this->addr_ptr = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "Writing 0x%X to MACE register %d", value, reg_offset);
|
||||
LOG_F(INFO, "%s: writing 0x%X to register %d", this->name.c_str(),
|
||||
value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+64
-37
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,58 +24,74 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACE_H
|
||||
#define MACE_H
|
||||
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
// MACE Chip ID from AMD datasheet
|
||||
// TODO: compare with real HW
|
||||
#define MACE_ID 0x3940
|
||||
/** Known MACE chip IDs. */
|
||||
#define MACE_ID_REV_B0 0x0940 // Darwin-0.3 source
|
||||
#define MACE_ID_REV_A2 0x0941 // Darwin-0.3 source & Curio datasheet
|
||||
|
||||
// MACE registers offsets
|
||||
/** MACE registers offsets. */
|
||||
// Refer to the Am79C940 datasheet for details
|
||||
namespace MaceEnet {
|
||||
enum MaceReg : uint8_t {
|
||||
Rcv_FIFO = 0,
|
||||
Xmit_FIFO = 1,
|
||||
Xmit_Frame_Ctrl = 2,
|
||||
Xmit_Frame_Stat = 3,
|
||||
Xmit_Retry_Cnt = 4,
|
||||
Rcv_Frame_Ctrl = 5,
|
||||
Rcv_Frame_Stat = 6,
|
||||
FIFO_Frame_Cnt = 7,
|
||||
Interrupt = 8,
|
||||
Interrupt_Mask = 9,
|
||||
Poll = 10,
|
||||
BIU_Config_Ctrl = 11,
|
||||
FIFO_Config = 12,
|
||||
MAC_Config_Ctrl = 13,
|
||||
PLS_Config_Ctrl = 14,
|
||||
PHY_Config_Ctrl = 15,
|
||||
Chip_ID_Lo = 16,
|
||||
Chip_ID_Hi = 17,
|
||||
Int_Addr_Config = 18,
|
||||
Log_Addr_Flt = 20,
|
||||
Phys_Addr = 21,
|
||||
Missed_Pkt_Cnt = 24,
|
||||
Runt_Pkt_Cnt = 26, // not used in Macintosh?
|
||||
Rcv_Collis_Cnt = 27, // not used in Macintosh?
|
||||
User_Test = 29,
|
||||
Rsrvd_Test_1 = 30, // not used in Macintosh?
|
||||
Rsrvd_Test_2 = 31, // not used in Macintosh?
|
||||
};
|
||||
|
||||
enum MaceReg : uint8_t {
|
||||
Rcv_FIFO = 0,
|
||||
Xmit_FIFO = 1,
|
||||
Xmit_Frame_Ctrl = 2,
|
||||
Xmit_Frame_Stat = 3,
|
||||
Xmit_Retry_Cnt = 4,
|
||||
Rcv_Frame_Ctrl = 5,
|
||||
Rcv_Frame_Stat = 6,
|
||||
FIFO_Frame_Cnt = 7,
|
||||
Interrupt = 8,
|
||||
Interrupt_Mask = 9,
|
||||
Poll = 0x0A,
|
||||
BIU_Config_Ctrl = 0x0B,
|
||||
FIFO_Config = 0x0C,
|
||||
MAC_Config_Ctrl = 0x0D,
|
||||
PLS_Config_Ctrl = 0x0E,
|
||||
PHY_Config_Ctrl = 0x0F,
|
||||
Chip_ID_Lo = 0x10,
|
||||
Chip_ID_Hi = 0x11,
|
||||
Addr_Config = 0x12,
|
||||
Log_Addr_Flt = 0x14,
|
||||
Phys_Addr = 0x15,
|
||||
Missed_Pkt_Cnt = 0x18,
|
||||
Runt_Pkt_Cnt = 0x1A, // not used in Macintosh?
|
||||
Rcv_Collis_Cnt = 0x1B, // not used in Macintosh?
|
||||
User_Test = 0x1D,
|
||||
Rsrvd_Test_1 = 0x1E, // not used in Macintosh?
|
||||
Rsrvd_Test_2 = 0x1F, // not used in Macintosh?
|
||||
};
|
||||
/** Bit definitions for BIU_Config_Ctrl register. */
|
||||
enum {
|
||||
BIU_SWRST = 1 << 0,
|
||||
};
|
||||
|
||||
/** Bit definitions for the internal configuration register. */
|
||||
enum {
|
||||
IAC_LOGADDR = 1 << 1,
|
||||
IAC_PHYADDR = 1 << 2,
|
||||
IAC_ADDRCHG = 1 << 7
|
||||
};
|
||||
|
||||
}; // namespace MaceEnet
|
||||
|
||||
class MaceController : public HWComponent {
|
||||
class MaceController : public DmaDevice, public HWComponent {
|
||||
public:
|
||||
MaceController(uint16_t id) { this->chip_id = id; };
|
||||
MaceController(uint16_t id) {
|
||||
this->chip_id = id;
|
||||
this->set_name("MACE");
|
||||
this->supports_types(HWCompType::MMIO_DEV | HWCompType::ETHER_MAC);
|
||||
};
|
||||
~MaceController() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<MaceController>(new MaceController(MACE_ID));
|
||||
return std::unique_ptr<MaceController>(new MaceController(MACE_ID_REV_A2));
|
||||
}
|
||||
|
||||
// MACE registers access
|
||||
@@ -84,6 +100,17 @@ public:
|
||||
|
||||
private:
|
||||
uint16_t chip_id; // per-instance MACE Chip ID
|
||||
uint8_t addr_cfg = 0;
|
||||
uint8_t addr_ptr = 0;
|
||||
uint8_t rcv_fc = 1;
|
||||
uint8_t biu_ctrl = 0;
|
||||
uint8_t mac_cfg = 0;
|
||||
uint64_t phys_addr = 0;
|
||||
uint64_t log_addr = 0;
|
||||
|
||||
// interrupt stuff
|
||||
uint8_t int_stat = 0;
|
||||
uint8_t int_mask = 0;
|
||||
};
|
||||
|
||||
#endif // MACE_H
|
||||
@@ -311,7 +311,7 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
|
||||
fconv = new RawFloppyImg(img_path);
|
||||
}
|
||||
|
||||
if (fconv->calc_phys_params()) {
|
||||
if (fconv && fconv->calc_phys_params()) {
|
||||
delete fconv;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -107,15 +107,18 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
|
||||
this->escc->set_dma_channel(3, this->escc_b_rx_dma.get());
|
||||
|
||||
// connect MESH (internal SCSI)
|
||||
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name_optional("MeshTnt"));
|
||||
this->mesh = dynamic_cast<MeshBase*>(gMachineObj->get_comp_by_name_optional("MeshTnt"));
|
||||
if (this->mesh == nullptr) {
|
||||
LOG_F(WARNING, "%s: Mesh not found, using MeshStub instead", this->name.c_str());
|
||||
this->mesh_stub = std::unique_ptr<MeshStub>(new MeshStub());
|
||||
this->mesh = dynamic_cast<MeshController*>(this->mesh_stub.get());
|
||||
this->mesh = dynamic_cast<MeshBase*>(this->mesh_stub.get());
|
||||
} else {
|
||||
MeshController *mesh_obj =
|
||||
dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name_optional("MeshTnt"));
|
||||
this->mesh_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mesh_scsi"));
|
||||
this->mesh_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_SCSI_MESH));
|
||||
this->mesh->set_dma_channel(this->mesh_dma.get());
|
||||
this->mesh_dma->connect(mesh_obj);
|
||||
mesh_obj->connect(this->mesh_dma.get());
|
||||
}
|
||||
|
||||
// connect external SCSI controller (Curio) to its DMA channel
|
||||
@@ -126,6 +129,13 @@ GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
|
||||
|
||||
// connect Ethernet HW
|
||||
this->mace = dynamic_cast<MaceController*>(gMachineObj->get_comp_by_name("Mace"));
|
||||
this->enet_tx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mace_enet_tx"));
|
||||
this->enet_tx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_ETHERNET_Tx));
|
||||
this->enet_rx_dma = std::unique_ptr<DMAChannel> (new DMAChannel("mace_enet_rx"));
|
||||
this->enet_rx_dma->register_dma_int(this, this->register_dma_int(IntSrc::DMA_ETHERNET_Rx));
|
||||
this->enet_tx_dma->connect(this->mace);
|
||||
this->enet_rx_dma->connect(this->mace);
|
||||
this->mace->connect(this->enet_rx_dma.get());
|
||||
|
||||
// connect floppy disk HW
|
||||
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
|
||||
@@ -185,10 +195,7 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
case 7: // VIA-CUDA
|
||||
return this->viacuda->read((offset >> 9) & 0xF);
|
||||
case 8: // MESH SCSI
|
||||
if (this->mesh)
|
||||
return this->mesh->read((offset >> 4) & 0xF);
|
||||
else if (this->mesh_stub)
|
||||
return this->mesh_stub->read((offset >> 4) & 0xF);
|
||||
return this->mesh->read((offset >> 4) & 0xF);
|
||||
case 9: // ENET-ROM
|
||||
return ENET_ROM[(offset >> 4) & 0x7];
|
||||
case 0xA: // IOBus device #1 ; Board register 1 and bandit1 PRSNT bits
|
||||
@@ -221,6 +228,10 @@ uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
return this->curio_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_FLOPPY:
|
||||
return this->floppy_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ETH_XMIT:
|
||||
return this->enet_tx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ETH_RCV:
|
||||
return this->enet_rx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ESCC_A_XMIT:
|
||||
return this->escc_a_tx_dma->reg_read(offset & 0xFF, size);
|
||||
case MIO_GC_DMA_ESCC_A_RCV:
|
||||
@@ -296,10 +307,7 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
this->viacuda->write((offset >> 9) & 0xF, value);
|
||||
break;
|
||||
case 8: // MESH SCSI
|
||||
if (this->mesh)
|
||||
this->mesh->write((offset >> 4) & 0xF, value);
|
||||
else if (this->mesh_stub)
|
||||
this->mesh_stub->write((offset >> 4) & 0xF, value);
|
||||
this->mesh->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0xA: // IOBus device #1 ; Board register 1 and bandit1 PRSNT bits
|
||||
case 0xB: // IOBus device #2 ; RaDACal/DACula
|
||||
@@ -315,7 +323,9 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
default: val = 0; break;
|
||||
}
|
||||
if (offset & 15) {
|
||||
LOG_F(ERROR, "%s: Unexpected offset (0x%x) or size (%d) write (0x%x) to IOBus device #%d", this->name.c_str(), offset, size, value, subdev_num - 9);
|
||||
LOG_F(ERROR,
|
||||
"%s: Unexpected offset (0x%x) or size (%d) write (0x%x) to IOBus device #%d",
|
||||
this->name.c_str(), offset, size, value, subdev_num - 9);
|
||||
}
|
||||
if (this->iobus_devs[subdev_num - 10] != nullptr) {
|
||||
this->iobus_devs[subdev_num - 10]->iodev_write((offset >> 4) & 0x1F, val);
|
||||
@@ -338,6 +348,12 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
case MIO_GC_DMA_FLOPPY:
|
||||
this->floppy_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ETH_XMIT:
|
||||
this->enet_tx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ETH_RCV:
|
||||
this->enet_rx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_ESCC_A_XMIT:
|
||||
this->escc_a_tx_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
@@ -354,7 +370,8 @@ void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, in
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_AUDIO_IN:
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN write @%02x.%c = %0*x", this->name.c_str(), offset & 0xFF, SIZE_ARG(size), size * 2, value);
|
||||
LOG_F(WARNING, "%s: Unsupported DMA channel DMA_AUDIO_IN write @%02x.%c = %0*x",
|
||||
this->name.c_str(), offset & 0xFF, SIZE_ARG(size), size * 2, value);
|
||||
//this->snd_in_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case MIO_GC_DMA_SCSI_MESH:
|
||||
|
||||
@@ -175,10 +175,10 @@ private:
|
||||
std::unique_ptr<AwacsScreamer> awacs; // AWACS audio codec instance
|
||||
std::unique_ptr<MeshStub> mesh_stub = nullptr;
|
||||
|
||||
MaceController* mace;
|
||||
MaceController* mace; // Ethernet cell within Curio
|
||||
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
|
||||
EsccController* escc; // ESCC serial controller
|
||||
MeshController* mesh; // internal SCSI (fast)
|
||||
EsccController* escc; // ESCC serial controller cell within Curio
|
||||
MeshBase* mesh; // internal SCSI (fast)
|
||||
Sc53C94* curio; // external SCSI (slow)
|
||||
Swim3::Swim3Ctrl* swim3; // floppy disk controller
|
||||
|
||||
@@ -187,6 +187,8 @@ private:
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
std::unique_ptr<DMAChannel> snd_in_dma;
|
||||
std::unique_ptr<DMAChannel> floppy_dma;
|
||||
std::unique_ptr<DMAChannel> enet_tx_dma;
|
||||
std::unique_ptr<DMAChannel> enet_rx_dma;
|
||||
std::unique_ptr<DMAChannel> escc_a_tx_dma;
|
||||
std::unique_ptr<DMAChannel> escc_a_rx_dma;
|
||||
std::unique_ptr<DMAChannel> escc_b_tx_dma;
|
||||
|
||||
@@ -168,7 +168,18 @@ bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
|
||||
entry->devobj = nullptr;
|
||||
entry->mem_ptr = reg_content;
|
||||
|
||||
this->address_map.push_back(entry);
|
||||
// Keep address_map sorted, that way the RAM region (which starts at 0 and
|
||||
// is most often requested) will be found by find_range on the first
|
||||
// iteration.
|
||||
this->address_map.insert(
|
||||
std::upper_bound(
|
||||
this->address_map.begin(),
|
||||
this->address_map.end(),
|
||||
entry,
|
||||
[](const auto& lhs, const auto& rhs) {
|
||||
return lhs->start < rhs->start;
|
||||
}),
|
||||
entry);
|
||||
|
||||
LOG_F(INFO, "Added mem region 0x%X..0x%X (%s%s%s%s) -> 0x%X", start_addr, end,
|
||||
entry->type & RT_ROM ? "ROM," : "",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,10 +24,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
@@ -60,7 +60,9 @@ int MPC106::device_postinit()
|
||||
std::string pci_dev_name;
|
||||
|
||||
static const std::map<std::string, int> pci_slots = {
|
||||
{"pci_PERCH", DEV_FUN(0xC,0)}, {"pci_A1", DEV_FUN(0xD,0)}, {"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)}, {"pci_GPU", DEV_FUN(0x12,0)}
|
||||
{"pci_PERCH", DEV_FUN(0xC,0)}, {"pci_A1", DEV_FUN(0xD,0)},
|
||||
{"pci_B1", DEV_FUN(0xE,0)}, {"pci_C1", DEV_FUN(0xF,0)},
|
||||
{"pci_GPU", DEV_FUN(0x12,0)}
|
||||
};
|
||||
|
||||
for (auto& slot : pci_slots) {
|
||||
@@ -72,6 +74,7 @@ int MPC106::device_postinit()
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
|
||||
this->irq_id_PCI_A = this->int_ctrl->register_dev_int(IntSrc::PCI_A );
|
||||
this->irq_id_PCI_B = this->int_ctrl->register_dev_int(IntSrc::PCI_B );
|
||||
this->irq_id_PCI_C = this->int_ctrl->register_dev_int(IntSrc::PCI_C );
|
||||
@@ -87,7 +90,7 @@ void MPC106::pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {
|
||||
return p.second == dev;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
if (it == dev_map.end()) {
|
||||
LOG_F(ERROR, "Interrupt from unknown device %s", dev->get_name().c_str());
|
||||
}
|
||||
@@ -100,7 +103,8 @@ void MPC106::pci_interrupt(uint8_t irq_line_state, PCIBase *dev) {
|
||||
case DEV_FUN(0x0F,0): irq_id = this->irq_id_PCI_C ; break;
|
||||
case DEV_FUN(0x12,0): irq_id = this->irq_id_PCI_GPU ; break;
|
||||
default:
|
||||
LOG_F(ERROR, "Interrupt from device %s at unexpected device/function %02x.%x", dev->get_name().c_str(), it->first >> 3, it->first & 7);
|
||||
LOG_F(ERROR, "Interrupt from device %s at unexpected device/function %02x.%x",
|
||||
dev->get_name().c_str(), it->first >> 3, it->first & 7);
|
||||
return;
|
||||
}
|
||||
if (this->int_ctrl)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -36,6 +36,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,15 +23,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <devices/storage/blockstoragedevice.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace std;
|
||||
|
||||
BlockStorageDevice::BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size, const uint64_t max_blocks) {
|
||||
this->block_size = block_size;
|
||||
this->cache_size = cache_blocks * this->block_size;
|
||||
this->max_blocks = max_blocks;
|
||||
|
||||
// allocate device cache and fill it with zeroes
|
||||
this->data_cache = std::unique_ptr<char[]>(new char[this->cache_size] ());
|
||||
BlockStorageDevice::BlockStorageDevice(const uint32_t cache_blocks,
|
||||
const uint32_t block_size,
|
||||
const uint64_t max_blocks) {
|
||||
this->block_size = block_size;
|
||||
this->raw_blk_size = block_size;
|
||||
this->cache_blocks = cache_blocks;
|
||||
this->max_blocks = max_blocks;
|
||||
this->is_ready = false;
|
||||
this->cache_size = 0;
|
||||
this->data_offset = 0;
|
||||
}
|
||||
|
||||
BlockStorageDevice::~BlockStorageDevice() {
|
||||
@@ -41,29 +46,61 @@ BlockStorageDevice::~BlockStorageDevice() {
|
||||
int BlockStorageDevice::set_host_file(std::string file_path) {
|
||||
this->is_ready = false;
|
||||
|
||||
if (!this->img_file.open(file_path)) {
|
||||
if (!this->img_file.open(file_path))
|
||||
return -1;
|
||||
}
|
||||
|
||||
this->size_bytes = this->img_file.size();
|
||||
this->size_blocks = this->size_bytes / this->block_size;
|
||||
if (this->size_blocks > this->max_blocks)
|
||||
return -1;
|
||||
|
||||
this->set_fpos(0);
|
||||
|
||||
this->is_ready = true;
|
||||
|
||||
return this->set_block_size(this->block_size);
|
||||
}
|
||||
|
||||
int BlockStorageDevice::set_block_size(const int blk_size) {
|
||||
this->raw_blk_size = blk_size;
|
||||
|
||||
if (this->is_ready) {
|
||||
this->size_blocks = this->size_bytes / this->raw_blk_size;
|
||||
if (this->size_blocks > this->max_blocks)
|
||||
return -1;
|
||||
}
|
||||
|
||||
this->cache_size = this->cache_blocks * this->raw_blk_size;
|
||||
|
||||
// allocate data cache and fill it with zeroes
|
||||
this->data_cache = std::unique_ptr<char[]>(new char[this->cache_size] ());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BlockStorageDevice::set_fpos(const uint32_t lba) {
|
||||
this->cur_fpos = lba * this->block_size;
|
||||
this->cur_fpos = lba * this->raw_blk_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BlockStorageDevice::fill_cache(const int nblocks) {
|
||||
uint32_t read_size = nblocks * this->raw_blk_size;
|
||||
|
||||
this->img_file.read(this->data_cache.get(), this->cur_fpos, read_size);
|
||||
this->cur_fpos += read_size;
|
||||
|
||||
// extract block data from raw images while discarding anything else
|
||||
if (this->raw_blk_size > this->block_size) {
|
||||
char *cache_ptr = this->data_cache.get();
|
||||
|
||||
for (int blk = 0; blk < nblocks; blk++) {
|
||||
memcpy(cache_ptr + blk * this->block_size,
|
||||
cache_ptr + blk * this->raw_blk_size + this->data_offset,
|
||||
this->block_size
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int BlockStorageDevice::read_begin(int nblocks, uint32_t max_len) {
|
||||
uint32_t xfer_len = std::min(this->cache_size, max_len);
|
||||
uint32_t xfer_len = std::min(this->cache_blocks * this->block_size, max_len);
|
||||
uint32_t read_size = nblocks * this->block_size;
|
||||
if (read_size > xfer_len) {
|
||||
this->remain_size = read_size - xfer_len;
|
||||
@@ -72,28 +109,25 @@ int BlockStorageDevice::read_begin(int nblocks, uint32_t max_len) {
|
||||
this->remain_size = 0;
|
||||
}
|
||||
|
||||
this->img_file.read(this->data_cache.get(), this->cur_fpos, read_size);
|
||||
this->cur_fpos += read_size;
|
||||
this->fill_cache(read_size / this->block_size);
|
||||
|
||||
return read_size;
|
||||
}
|
||||
|
||||
int BlockStorageDevice::read_more() {
|
||||
uint32_t read_size;
|
||||
|
||||
if (!this->remain_size)
|
||||
return 0;
|
||||
|
||||
if (this->remain_size > this->cache_size) {
|
||||
this->remain_size -= this->cache_size;
|
||||
read_size = this->cache_size;
|
||||
uint32_t read_size = this->cache_blocks * this->block_size;
|
||||
|
||||
if (this->remain_size > read_size) {
|
||||
this->remain_size -= read_size;
|
||||
} else {
|
||||
read_size = this->remain_size;
|
||||
this->remain_size = 0;
|
||||
}
|
||||
|
||||
this->img_file.read(this->data_cache.get(), this->cur_fpos, read_size);
|
||||
this->cur_fpos += read_size;
|
||||
this->fill_cache(read_size / this->block_size);
|
||||
|
||||
return read_size;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -32,12 +32,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
class BlockStorageDevice {
|
||||
public:
|
||||
BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size=512, const uint64_t max_blocks=0xffffffffffffffff);
|
||||
BlockStorageDevice(const uint32_t cache_blocks, const uint32_t block_size=512,
|
||||
const uint64_t max_blocks=0xffffffffffffffff);
|
||||
~BlockStorageDevice();
|
||||
|
||||
void set_block_size(const int blk_size) { this->block_size = blk_size; };
|
||||
|
||||
int set_host_file(std::string file_path);
|
||||
int set_block_size(const int blk_size);
|
||||
|
||||
int set_fpos(const uint32_t lba);
|
||||
int read_begin(int nblocks, uint32_t max_len);
|
||||
@@ -46,12 +46,17 @@ public:
|
||||
int write_begin(char *buf, int nblocks);
|
||||
|
||||
protected:
|
||||
void fill_cache(const int nblocks);
|
||||
|
||||
ImgFile img_file;
|
||||
uint64_t size_bytes = 0; // image file size in bytes
|
||||
uint64_t size_blocks = 0; // image file size in blocks
|
||||
uint64_t max_blocks = 0; // maximum number of blocks supported
|
||||
uint64_t cur_fpos = 0; // current image file pointer position
|
||||
uint32_t block_size = 512; // physical block size
|
||||
uint32_t raw_blk_size = 512; // block size for raw images (CD-ROM)
|
||||
uint32_t data_offset = 0; // offset to block data for raw images
|
||||
uint32_t cache_blocks = 0;
|
||||
uint32_t cache_size = 0; // cache size
|
||||
uint32_t remain_size = 0;
|
||||
bool is_writeable = false;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -30,12 +30,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
CdromDrive::CdromDrive() : BlockStorageDevice(31, 2048, 0xfffffffe) {
|
||||
CdromDrive::CdromDrive() : BlockStorageDevice(31, CDR_STD_DATA_SIZE, 0xfffffffe) {
|
||||
this->is_writeable = false;
|
||||
}
|
||||
|
||||
void CdromDrive::insert_image(std::string filename) {
|
||||
this->set_host_file(filename);
|
||||
if (this->set_host_file(filename) < 0)
|
||||
ABORT_F("Could not open CD-ROM image file, %s", filename.c_str());
|
||||
|
||||
this->detect_raw_image();
|
||||
|
||||
// create single track descriptor
|
||||
this->tracks[0] = {1, /*.trk_num*/ 0x14, /*.adr_ctrl*/ 0 /*.start_lba*/};
|
||||
@@ -46,6 +49,29 @@ void CdromDrive::insert_image(std::string filename) {
|
||||
static_cast<uint32_t>(this->size_blocks + 1) /*.start_lba*/};
|
||||
}
|
||||
|
||||
bool CdromDrive::detect_raw_image() {
|
||||
uint8_t block_hdr[16];
|
||||
|
||||
// let's see if the image data starts with the Mode 1/2 sync pattern
|
||||
this->img_file.read(block_hdr, 0, sizeof(block_hdr));
|
||||
|
||||
for (int i = 1; i <= 10; i++)
|
||||
if (block_hdr[i] != 0xFF)
|
||||
return false;
|
||||
|
||||
if (block_hdr[0] != 0 || block_hdr[11] != 0)
|
||||
return false;
|
||||
|
||||
// for now, we only support Mode 1 images
|
||||
if (block_hdr[15] == 1) {
|
||||
this->set_block_size(2352);
|
||||
this->data_offset = 16;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static char cdrom_vendor_dingus_id[] = "DINGUS ";
|
||||
static char cdrom_product_id[] = "DINGUS CD-ROM ";
|
||||
static char cdrom_revision_id[] = "1.0 ";
|
||||
@@ -138,8 +164,17 @@ uint32_t CdromDrive::report_capacity(uint8_t *data_ptr) {
|
||||
return 8;
|
||||
}
|
||||
|
||||
uint8_t CdromDrive::hex_to_bcd(const uint8_t val) {
|
||||
uint8_t hi = val / 10;
|
||||
uint8_t lo = val % 10;
|
||||
return (hi << 4) | lo;
|
||||
}
|
||||
|
||||
AddrMsf CdromDrive::lba_to_msf(const int lba) {
|
||||
return {lba / 4500, /*.min*/ (lba / 75) % 60, /*.sec*/ lba % 75 /*.frm*/};
|
||||
return {hex_to_bcd( lba / 4500), /*.min*/
|
||||
hex_to_bcd((lba / 75) % 60), /*.sec*/
|
||||
hex_to_bcd( lba % 75) /*.frm*/
|
||||
};
|
||||
}
|
||||
|
||||
uint32_t CdromDrive::read_toc(uint8_t *cmd_ptr, uint8_t *data_ptr) {
|
||||
@@ -207,7 +242,7 @@ uint32_t CdromDrive::read_toc(uint8_t *cmd_ptr, uint8_t *data_ptr) {
|
||||
out_ptr += 4;
|
||||
}
|
||||
}
|
||||
return data_len;
|
||||
return alloc_len;
|
||||
case 1: // Multi-session info
|
||||
std::memset(data_ptr, 0, 12);
|
||||
data_ptr[1] = 10; // TOC data length
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
Copyright (C) 2018-24 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -46,6 +46,7 @@ typedef struct {
|
||||
|
||||
#define CDROM_MAX_TRACKS 100
|
||||
#define LEAD_OUT_TRK_NUM 0xAA
|
||||
#define CDR_STD_DATA_SIZE 2048
|
||||
|
||||
class CdromDrive : public BlockStorageDevice {
|
||||
public:
|
||||
@@ -69,7 +70,9 @@ public:
|
||||
|
||||
protected:
|
||||
std::function<void(uint8_t, uint8_t)> set_error;
|
||||
uint8_t hex_to_bcd(const uint8_t val);
|
||||
AddrMsf lba_to_msf(const int lba);
|
||||
bool detect_raw_image();
|
||||
|
||||
TrackDescriptor tracks[CDROM_MAX_TRACKS];
|
||||
int num_tracks;
|
||||
|
||||
@@ -164,6 +164,8 @@ AtiMach64Gx::AtiMach64Gx()
|
||||
insert_bits<uint32_t>(this->regs[ATI_GUI_STAT], 32, ATI_FIFO_CNT, ATI_FIFO_CNT_size);
|
||||
|
||||
set_bit(regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_DISPLAY_DIS); // because blank_on is true
|
||||
|
||||
this->draw_fb_is_dynamic = true;
|
||||
}
|
||||
|
||||
void AtiMach64Gx::change_one_bar(uint32_t &aperture, uint32_t aperture_size,
|
||||
|
||||
@@ -144,6 +144,8 @@ ATIRage::ATIRage(uint16_t dev_id)
|
||||
this->regs[ATI_GP_IO] = ((mon_code & 6) << 11) | ((mon_code & 1) << 8);
|
||||
insert_bits<uint32_t>(this->regs[ATI_GUI_STAT], 32, ATI_FIFO_CNT, ATI_FIFO_CNT_size);
|
||||
set_bit(regs[ATI_CRTC_GEN_CNTL], ATI_CRTC_DISPLAY_DIS); // because blank_on is true
|
||||
|
||||
this->draw_fb_is_dynamic = true;
|
||||
}
|
||||
|
||||
void ATIRage::change_one_bar(uint32_t &aperture, uint32_t aperture_size,
|
||||
|
||||
+11
-1
@@ -41,9 +41,19 @@ public:
|
||||
// Clears the display
|
||||
void blank();
|
||||
|
||||
|
||||
// Update the host framebuffer display. If the display adapter does its own
|
||||
// dirty tracking, fb_known_to_be_changed will be set to true, so that the
|
||||
// implementation can take that into account.
|
||||
void update(std::function<void(uint8_t *dst_buf, int dst_pitch)> convert_fb_cb,
|
||||
std::function<void(uint8_t *dst_buf, int dst_pitch)> cursor_ovl_cb,
|
||||
bool draw_hw_cursor, int cursor_x, int cursor_y);
|
||||
bool draw_hw_cursor, int cursor_x, int cursor_y,
|
||||
bool fb_known_to_be_changed);
|
||||
|
||||
// Called in cases where the framebuffer contents have not changed, so a
|
||||
// normal update() call is not happening. Allows implementations that need
|
||||
// to do per-frame bookkeeping to still do that.
|
||||
void update_skipped();
|
||||
|
||||
void handle_events(const WindowEvent& wnd_event);
|
||||
void setup_hw_cursor(std::function<void(uint8_t *dst_buf, int dst_pitch)> draw_hw_cursor,
|
||||
|
||||
@@ -97,6 +97,9 @@ void Display::handle_events(const WindowEvent& wnd_event) {
|
||||
if (wnd_event.sub_type == SDL_WINDOWEVENT_SIZE_CHANGED &&
|
||||
wnd_event.window_id == impl->disp_wnd_id)
|
||||
impl->resizing = false;
|
||||
if (wnd_event.sub_type == SDL_WINDOWEVENT_EXPOSED &&
|
||||
wnd_event.window_id == impl->disp_wnd_id)
|
||||
SDL_RenderPresent(impl->renderer);
|
||||
}
|
||||
|
||||
void Display::blank() {
|
||||
@@ -107,7 +110,8 @@ void Display::blank() {
|
||||
|
||||
void Display::update(std::function<void(uint8_t *dst_buf, int dst_pitch)> convert_fb_cb,
|
||||
std::function<void(uint8_t *dst_buf, int dst_pitch)> cursor_ovl_cb,
|
||||
bool draw_hw_cursor, int cursor_x, int cursor_y) {
|
||||
bool draw_hw_cursor, int cursor_x, int cursor_y,
|
||||
bool fb_known_to_be_changed) {
|
||||
if (impl->resizing)
|
||||
return;
|
||||
|
||||
@@ -137,6 +141,10 @@ void Display::update(std::function<void(uint8_t *dst_buf, int dst_pitch)> conver
|
||||
SDL_RenderPresent(impl->renderer);
|
||||
}
|
||||
|
||||
void Display::update_skipped() {
|
||||
// SDL implementation does not care about skipped updates.
|
||||
}
|
||||
|
||||
void Display::setup_hw_cursor(std::function<void(uint8_t *dst_buf, int dst_pitch)> draw_hw_cursor,
|
||||
int cursor_width, int cursor_height) {
|
||||
uint8_t* dst_buf;
|
||||
|
||||
+17
-3
@@ -91,7 +91,8 @@ uint32_t TaosVideo::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
case CRT_CTRL:
|
||||
return this->crt_ctrl;
|
||||
case GPIO_IN:
|
||||
return ((this->mon_id << 29) | (vsync_active << 25)) & ~this->gpio_cfg;
|
||||
return ((this->mon_id << GPIO_MONID) | (1 << GPIO_CDTRAY) |
|
||||
(vsync_active << GPIO_VSYNC)) & ~this->gpio_cfg;
|
||||
case INT_ENABLES:
|
||||
return this->int_enables;
|
||||
case TAOS_VERSION:
|
||||
@@ -120,7 +121,10 @@ void TaosVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int s
|
||||
this->row_words = value;
|
||||
break;
|
||||
case COLOR_MODE:
|
||||
this->color_mode = value;
|
||||
if (this->color_mode != value) {
|
||||
this->color_mode = value;
|
||||
enable_display();
|
||||
}
|
||||
break;
|
||||
case VIDEO_MODE:
|
||||
this->video_mode = value >> 30;
|
||||
@@ -129,6 +133,8 @@ void TaosVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int s
|
||||
if (bit_changed(this->crt_ctrl, value, ENABLE_VIDEO_OUT)) {
|
||||
if (bit_set(value, ENABLE_VIDEO_OUT))
|
||||
enable_display();
|
||||
else
|
||||
disable_display();
|
||||
}
|
||||
this->crt_ctrl = value;
|
||||
break;
|
||||
@@ -218,7 +224,15 @@ void TaosVideo::enable_display() {
|
||||
this->start_refresh_task();
|
||||
|
||||
this->blank_on = false;
|
||||
this->crtc_on = true;
|
||||
this->crtc_on = true;
|
||||
}
|
||||
|
||||
void TaosVideo::disable_display() {
|
||||
this->stop_refresh_task();
|
||||
this->blank_display();
|
||||
|
||||
this->blank_on = true;
|
||||
this->crtc_on = false;
|
||||
}
|
||||
|
||||
void TaosVideo::convert_frame_15bpp_indexed(uint8_t *dst_buf, int dst_pitch) {
|
||||
|
||||
@@ -111,6 +111,13 @@ enum {
|
||||
MON_ID_VGA = 6 // GPIO_0 = "1", GPIO_1 = "1", GPIO_2 = "0"
|
||||
};
|
||||
|
||||
/** Definitions for the GPIO pins. */
|
||||
enum {
|
||||
GPIO_MONID = 29, // GPIO 0..2 are monitor identification pins
|
||||
GPIO_CDTRAY = 27, // GPIO 4: "1" - CD-ROM tray is closed
|
||||
GPIO_VSYNC = 25, // GPIO 6: vertical synch input (active low)
|
||||
};
|
||||
|
||||
/** Broktree Bt856 digital video encoder. */
|
||||
class Bt856 : public I2CDevice, public HWComponent {
|
||||
public:
|
||||
@@ -174,6 +181,7 @@ public:
|
||||
|
||||
private:
|
||||
void enable_display();
|
||||
void disable_display();
|
||||
void convert_frame_15bpp_indexed(uint8_t *dst_buf, int dst_pitch);
|
||||
|
||||
std::unique_ptr<AthensClocks> clk_gen = nullptr;
|
||||
|
||||
@@ -81,7 +81,10 @@ void VideoCtrlBase::update_screen()
|
||||
}
|
||||
this->display.update(
|
||||
this->convert_fb_cb, this->cursor_ovl_cb,
|
||||
this->cursor_on, cursor_x, cursor_y);
|
||||
this->cursor_on, cursor_x, cursor_y,
|
||||
this->draw_fb_is_dynamic);
|
||||
} else if (this->draw_fb_is_dynamic) {
|
||||
this->display.update_skipped();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,12 @@ protected:
|
||||
int pixel_format;
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
|
||||
// Implementations may choose to track framebuffer writes and set draw_fb
|
||||
// to false if updates can be skipped. If the do this, they should set
|
||||
// draw_fb_is_dynamic at initialization time.
|
||||
bool draw_fb = true;
|
||||
bool draw_fb_is_dynamic = false;
|
||||
|
||||
uint32_t palette[256] = {0}; // internal DAC palette in RGBA format
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ int initialize_pdm(std::string& id)
|
||||
}
|
||||
|
||||
// Init virtual CPU and request MPC601
|
||||
ppc_cpu_init(hmc_obj, PPC_VER::MPC601, true, 7812500ULL);
|
||||
ppc_cpu_init(hmc_obj, PPC_VER::MPC601, true, 7833600ULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -93,8 +93,13 @@ int initialize_tnt(std::string& id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// plug 16MB RAM DIMM into slot #0
|
||||
memctrl_obj->insert_ram_dimm(0, DRAM_CAP_16MB);
|
||||
// populate RAM banks from configuration properties
|
||||
for (int bank_num = 0; bank_num <= 3; bank_num++) {
|
||||
std::string bn = {char('1' + bank_num)};
|
||||
int bank_size = GET_INT_PROP("rambank" + bn + "_size");
|
||||
if (bank_size)
|
||||
memctrl_obj->insert_ram_dimm(bank_num, bank_size * DRAM_CAP_1MB);
|
||||
}
|
||||
|
||||
// allocate and map physical RAM
|
||||
memctrl_obj->map_phys_ram();
|
||||
|
||||
@@ -52,13 +52,39 @@ int initialize_yosemite(std::string& id)
|
||||
// get pointer to the bridge of the secondary PCI bus
|
||||
DecPciBridge *sec_bridge = dynamic_cast<DecPciBridge*>(gMachineObj->get_comp_by_name("Dec21154"));
|
||||
|
||||
// connect PCI devices
|
||||
// attach PCI devices to the PCI bridges
|
||||
grackle_obj->pci_register_device(DEV_FUN(16,0),
|
||||
dynamic_cast<PCIBase*>(gMachineObj->get_comp_by_name("AtiRage128")));
|
||||
|
||||
grackle_obj->pci_register_device(DEV_FUN(13,0),
|
||||
dynamic_cast<PCIBase*>(gMachineObj->get_comp_by_name("Dec21154")));
|
||||
|
||||
sec_bridge->pci_register_device(DEV_FUN(5,0),
|
||||
dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("Heathrow")));
|
||||
|
||||
InterruptCtrl *int_ctrl_obj =
|
||||
dynamic_cast<InterruptCtrl*>(gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
|
||||
static const std::vector<PciIrqMap> grackle_irq_map = {
|
||||
{"pci_J12", DEV_FUN(0x10,0), 1 << 22} // GPU PCI slot, 66 MHz
|
||||
};
|
||||
|
||||
grackle_obj->set_interrupt_controller(int_ctrl_obj);
|
||||
grackle_obj->set_irq_map(grackle_irq_map);
|
||||
|
||||
// 33 MHz PCI devices behind the DEC21154 PCI-to-PCI bridge
|
||||
static const std::vector<PciIrqMap> pci_bridge_irq_map = {
|
||||
{"pci_FireWire", DEV_FUN(0x00,0), 1 << 21},
|
||||
{"pci_UltraATA", DEV_FUN(0x01,0), 1 << 26},
|
||||
{"pci_J11", DEV_FUN(0x02,0), 1 << 23},
|
||||
{"pci_J10", DEV_FUN(0x03,0), 1 << 24},
|
||||
{"pci_J9", DEV_FUN(0x04,0), 1 << 25},
|
||||
{"pci_USB", DEV_FUN(0x06,0), 1 << 28}
|
||||
};
|
||||
|
||||
sec_bridge->set_interrupt_controller(int_ctrl_obj);
|
||||
sec_bridge->set_irq_map(pci_bridge_irq_map);
|
||||
|
||||
// allocate ROM region
|
||||
if (!grackle_obj->add_rom_region(0xFFF00000, 0x100000)) {
|
||||
LOG_F(ERROR, "Could not allocate ROM region!");
|
||||
|
||||
@@ -62,7 +62,7 @@ static string appDescription = string(
|
||||
"\n"
|
||||
);
|
||||
|
||||
void run_machine(std::string machine_str, std::string bootrom_path, uint32_t execution_mode);
|
||||
void run_machine(std::string machine_str, std::string bootrom_path, uint32_t execution_mode, uint32_t profiling_interval_ms);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
@@ -72,19 +72,35 @@ int main(int argc, char** argv) {
|
||||
app.allow_windows_style_options(); /* we want Windows-style options */
|
||||
app.allow_extras();
|
||||
|
||||
bool realtime_enabled, debugger_enabled;
|
||||
string machine_str;
|
||||
bool realtime_enabled = false;
|
||||
bool debugger_enabled = false;
|
||||
string bootrom_path("bootrom.bin");
|
||||
|
||||
app.add_flag("-r,--realtime", realtime_enabled,
|
||||
"Run the emulator in real-time");
|
||||
|
||||
app.add_flag("-d,--debugger", debugger_enabled,
|
||||
"Enter the built-in debugger");
|
||||
|
||||
app.add_option("-b,--bootrom", bootrom_path, "Specifies BootROM path")
|
||||
->check(CLI::ExistingFile);
|
||||
|
||||
bool log_to_stderr = false;
|
||||
loguru::Verbosity log_verbosity = loguru::Verbosity_INFO;
|
||||
bool log_no_uptime = false;
|
||||
app.add_flag("--log-to-stderr", log_to_stderr,
|
||||
"Send internal logging to stderr (instead of dingusppc.log)");
|
||||
app.add_flag("--log-verbosity", log_verbosity,
|
||||
"Adjust logging verbosity (default is 0 a.k.a. INFO)")
|
||||
->check(CLI::Number);
|
||||
app.add_flag("--log-no-uptime", log_no_uptime,
|
||||
"Disable the uptime preamble of logged messages");
|
||||
|
||||
uint32_t profiling_interval_ms = 0;
|
||||
#ifdef CPU_PROFILING
|
||||
app.add_option("--profiling-interval-ms", profiling_interval_ms,
|
||||
"Specifies periodic interval (in ms) at which to output CPU profiling information");
|
||||
#endif
|
||||
|
||||
string machine_str;
|
||||
CLI::Option* machine_opt = app.add_option("-m,--machine",
|
||||
machine_str, "Specify machine ID");
|
||||
|
||||
@@ -112,20 +128,21 @@ int main(int argc, char** argv) {
|
||||
if (debugger_enabled) {
|
||||
if (realtime_enabled)
|
||||
cout << "Both realtime and debugger enabled! Using debugger" << endl;
|
||||
execution_mode = 1;
|
||||
execution_mode = debugger;
|
||||
}
|
||||
|
||||
/* initialize logging */
|
||||
loguru::g_preamble_date = false;
|
||||
loguru::g_preamble_time = false;
|
||||
loguru::g_preamble_thread = false;
|
||||
loguru::g_preamble_uptime = !log_no_uptime;
|
||||
|
||||
if (!execution_mode) {
|
||||
if (execution_mode == interpreter && !log_to_stderr) {
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_OFF;
|
||||
loguru::init(argc, argv);
|
||||
loguru::add_file("dingusppc.log", loguru::Append, 0);
|
||||
loguru::add_file("dingusppc.log", loguru::Append, log_verbosity);
|
||||
} else {
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
|
||||
loguru::g_stderr_verbosity = log_verbosity;
|
||||
loguru::init(argc, argv);
|
||||
}
|
||||
|
||||
@@ -188,12 +205,21 @@ int main(int argc, char** argv) {
|
||||
signal(SIGABRT, sigabrt_handler);
|
||||
|
||||
while (true) {
|
||||
run_machine(machine_str, bootrom_path, execution_mode);
|
||||
run_machine(machine_str, bootrom_path, execution_mode, profiling_interval_ms);
|
||||
if (power_off_reason == po_restarting) {
|
||||
LOG_F(INFO, "Restarting...");
|
||||
power_on = true;
|
||||
continue;
|
||||
}
|
||||
if (power_off_reason == po_shutting_down) {
|
||||
if (execution_mode != debugger) {
|
||||
LOG_F(INFO, "Shutdown.");
|
||||
break;
|
||||
}
|
||||
LOG_F(INFO, "Shutdown...");
|
||||
power_on = true;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -202,7 +228,7 @@ int main(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void run_machine(std::string machine_str, std::string bootrom_path, uint32_t execution_mode) {
|
||||
void run_machine(std::string machine_str, std::string bootrom_path, uint32_t execution_mode, uint32_t profiling_interval_ms) {
|
||||
if (MachineFactory::create_machine_for_id(machine_str, bootrom_path) < 0) {
|
||||
return;
|
||||
}
|
||||
@@ -213,11 +239,24 @@ void run_machine(std::string machine_str, std::string bootrom_path, uint32_t exe
|
||||
EventManager::get_instance()->poll_events();
|
||||
});
|
||||
|
||||
#ifdef CPU_PROFILING
|
||||
uint32_t profiling_timer;
|
||||
if (profiling_interval_ms > 0) {
|
||||
profiling_timer = TimerManager::get_instance()->add_cyclic_timer(MSECS_TO_NSECS(profiling_interval_ms), [] {
|
||||
gProfilerObj->print_profile("PPC_CPU");
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (execution_mode) {
|
||||
case interpreter:
|
||||
power_off_reason = po_starting_up;
|
||||
enter_debugger();
|
||||
break;
|
||||
case threaded_int:
|
||||
power_off_reason = po_starting_up;
|
||||
enter_debugger();
|
||||
break;
|
||||
case debugger:
|
||||
power_off_reason = po_enter_debugger;
|
||||
enter_debugger();
|
||||
@@ -229,6 +268,11 @@ void run_machine(std::string machine_str, std::string bootrom_path, uint32_t exe
|
||||
|
||||
LOG_F(INFO, "Cleaning up...");
|
||||
TimerManager::get_instance()->cancel_timer(event_timer);
|
||||
#ifdef CPU_PROFILING
|
||||
if (profiling_interval_ms > 0) {
|
||||
TimerManager::get_instance()->cancel_timer(profiling_timer);
|
||||
}
|
||||
#endif
|
||||
EventManager::get_instance()->disconnect_handlers();
|
||||
delete gMachineObj.release();
|
||||
}
|
||||
Vendored
+3
-3
@@ -515,7 +515,7 @@ namespace loguru
|
||||
argv[argc] = nullptr;
|
||||
}
|
||||
|
||||
static long long now_ns()
|
||||
static long long loguru_now_ns()
|
||||
{
|
||||
return duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
@@ -1578,7 +1578,7 @@ namespace loguru
|
||||
}
|
||||
}
|
||||
#if LOGURU_VERBOSE_SCOPE_ENDINGS
|
||||
auto duration_sec = static_cast<double>(now_ns() - _start_time_ns) / 1e9;
|
||||
auto duration_sec = static_cast<double>(loguru_now_ns() - _start_time_ns) / 1e9;
|
||||
#if LOGURU_USE_FMTLIB
|
||||
auto buff = textprintf("{:.{}f} s: {:s}", duration_sec, LOGURU_SCOPE_TIME_PRECISION, _name);
|
||||
#else
|
||||
@@ -1596,7 +1596,7 @@ namespace loguru
|
||||
if (_verbosity <= current_verbosity_cutoff()) {
|
||||
std::lock_guard<std::recursive_mutex> lock(s_mutex);
|
||||
_indent_stderr = (_verbosity <= g_stderr_verbosity);
|
||||
_start_time_ns = now_ns();
|
||||
_start_time_ns = loguru_now_ns();
|
||||
vsnprintf(_name, sizeof(_name), format, vlist);
|
||||
log_to_everywhere(1, _verbosity, _file, _line, "{ ", _name);
|
||||
|
||||
|
||||
+3
-3
@@ -37,10 +37,10 @@ public:
|
||||
bool open(const std::string& img_path);
|
||||
void close();
|
||||
|
||||
size_t size() const;
|
||||
uint64_t size() const;
|
||||
|
||||
size_t read(void* buf, off_t offset, size_t length) const;
|
||||
size_t write(const void* buf, off_t offset, size_t length);
|
||||
uint64_t read(void* buf, uint64_t offset, uint64_t length) const;
|
||||
uint64_t write(const void* buf, uint64_t offset, uint64_t length);
|
||||
private:
|
||||
class Impl; // Holds private fields
|
||||
std::unique_ptr<Impl> impl;
|
||||
|
||||
@@ -46,20 +46,20 @@ void ImgFile::close()
|
||||
impl->stream.close();
|
||||
}
|
||||
|
||||
size_t ImgFile::size() const
|
||||
uint64_t ImgFile::size() const
|
||||
{
|
||||
impl->stream.seekg(0, impl->stream.end);
|
||||
return impl->stream.tellg();
|
||||
}
|
||||
|
||||
size_t ImgFile::read(void* buf, off_t offset, size_t length) const
|
||||
uint64_t ImgFile::read(void* buf, uint64_t offset, uint64_t length) const
|
||||
{
|
||||
impl->stream.seekg(offset, std::ios::beg);
|
||||
impl->stream.read((char *)buf, length);
|
||||
return impl->stream.gcount();
|
||||
}
|
||||
|
||||
size_t ImgFile::write(const void* buf, off_t offset, size_t length)
|
||||
uint64_t ImgFile::write(const void* buf, uint64_t offset, uint64_t length)
|
||||
{
|
||||
impl->stream.seekg(offset, std::ios::beg);
|
||||
impl->stream.write((const char *)buf, length);
|
||||
|
||||
+19
-2
@@ -20,6 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "profiler.h"
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
@@ -50,6 +51,11 @@ void Profiler::print_profile(std::string name)
|
||||
return;
|
||||
}
|
||||
|
||||
// Set a locale so we get thousands separators when outputting numbers.
|
||||
// Would be nice if we could use the default locale, but that does not
|
||||
// appear to work.
|
||||
std::cout.imbue(std::locale("en_US.UTF-8"));
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << "Summary of the profile '" << name << "':" << std::endl;
|
||||
std::cout << "------------------------------------------" << std::endl;
|
||||
@@ -61,13 +67,24 @@ void Profiler::print_profile(std::string name)
|
||||
// ask the corresponding profile class to fill its variables for us
|
||||
prof_it->second->populate_variables(vars);
|
||||
|
||||
int name_width = 10;
|
||||
for (auto& var : vars) {
|
||||
name_width = std::max(name_width, int(var.name.length()));
|
||||
}
|
||||
|
||||
for (auto& var : vars) {
|
||||
std::cout << std::left << std::setw(name_width) << var.name << " : ";
|
||||
switch(var.format) {
|
||||
case ProfileVarFmt::DEC:
|
||||
std::cout << var.name << " : " << var.value << std::endl;
|
||||
std::cout << var.value << std::endl;
|
||||
break;
|
||||
case ProfileVarFmt::HEX:
|
||||
std::cout << var.name << " : " << std::hex << var.value << std::endl;
|
||||
std::cout << std::hex << var.value << std::endl;
|
||||
break;
|
||||
case ProfileVarFmt::COUNT:
|
||||
std::cout << var.value << std::fixed << std::setprecision(2) << " ("
|
||||
<< (double(var.value) / double(var.count_total) * 100)
|
||||
<< "%)" << std::endl;
|
||||
break;
|
||||
default:
|
||||
std::cout << "Unknown value in variable " << var.name << std::endl;
|
||||
|
||||
+2
-1
@@ -31,13 +31,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum class ProfileVarFmt { DEC, HEX };
|
||||
enum class ProfileVarFmt { DEC, HEX, COUNT };
|
||||
|
||||
/** Define a special data type for profile variables. */
|
||||
typedef struct ProfileVar {
|
||||
std::string name;
|
||||
ProfileVarFmt format;
|
||||
uint64_t value;
|
||||
uint64_t count_total;
|
||||
} ProfileVar;
|
||||
|
||||
/** Base class for user-defined profiles. */
|
||||
|
||||
@@ -2,6 +2,8 @@ The Apple Desktop Bus is a bit-serial peripheral bus, Apple themselves cited a 2
|
||||
|
||||
The device commands are in the form of single byte strings. The first four bits are to signal which of the 16 devices are to be used. The next two bits are for which action to execute (talk, listen, flush, or reset). These are followed by two bits which determine the register to reference (register 0 is usually a communications register, while register 3 is used for device info).
|
||||
|
||||
Heathrow and Paddington-based Macintoshes have a Master Cell, which is a fully-featured ADB implementation for hardware, but isn't used by Mac OS itself.
|
||||
|
||||
# Commands
|
||||
|
||||
| Command Name | Number |
|
||||
|
||||
@@ -26,6 +26,16 @@ All registers are 32-bit here.
|
||||
| Codec Status | 0x20 |
|
||||
| Clipping Count | 0x30 |
|
||||
| Byte Swapping | 0x40 |
|
||||
| Frame Count | 0x50 |
|
||||
|
||||
##Sound Control Register bits
|
||||
|
||||
| Register | Bit Mask |
|
||||
|:-------------------------:|:--------:|
|
||||
| Input Subframe Select | 0x000F |
|
||||
| Output Subframe Select | 0x00F0 |
|
||||
| Sound Rate | 0x0700 |
|
||||
| Error | 0x0800 |
|
||||
|
||||
|
||||
Separate volume controls exist for the CD drive and the microphone.
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
The following document is intended primarily as a documentation on how the BeBox operates. It is currently not implemented in DingusPPC.
|
||||
|
||||
## BeBox
|
||||
|
||||
The BeBox is a dual PowerPC 603(e) CPU setup. As it was designed with the intent of using standard PC parts, it has both three PCI slots and five ISA slots. As it was made with media production as its primary audience, it contains both input and output RCA jacks, a microphone input, and MIDI ports.
|
||||
|
||||
It also has a unique 37-pin connector dubbed the Geekport to allow hobbyists to create unique devices.
|
||||
|
||||
### Known components
|
||||
|
||||
* MPC105 PCI Bridge (Codename: Eagle) - Predecessor to the MPC106 (Grackle); Used for bridging between the motherboard and PCI slots
|
||||
* Intel 82378ZB - Used for bridging between the motherboard and ISA slots
|
||||
* SYM53C810A - SCSI I/O Processor
|
||||
* bq3285 - Used for the Real-Time Clock
|
||||
|
||||
### Motherboard registers
|
||||
|
||||
| Register name | Address | Default value |
|
||||
|:---------------------------:|:--------------:|:--------------:|
|
||||
| CPU 0 Interrupt Mask | 0x7FFFF0F0 | |
|
||||
| CPU 1 Interrupt Mask | 0x7FFFF1F0 | |
|
||||
| Interrupt sources | 0x7FFFF2F0 | |
|
||||
| Cross-proccessor interrupts | 0x7FFFF3F0 | |
|
||||
| Proc. resets, other stuff | 0x7FFFF4F0 | |
|
||||
|
||||
|
||||
### Memory Map
|
||||
|
||||
| Region | Starting Address | Ending Address |
|
||||
|:---------------------------:|:----------------:|:----------------:|
|
||||
| Main Memory | 0x00000000 | 0x3FFFFFFF |
|
||||
| Other Memory | 0x40000000 | 0x7FFFFFFF |
|
||||
| ISA I/O | 0x80000000 | 0x807FFFFF |
|
||||
| PCI I/O | 0x81000000 | 0xBEFFFFFF |
|
||||
| PCI/ISA Interrupt Ack | 0xBFFFFFF0 | 0xBFFFFFFF |
|
||||
| PCI Memory | 0xC0000000 | 0xFEFFFFFF |
|
||||
| ROM/Flash | 0xFF000000 | 0xFFFFFFFF |
|
||||
|
||||
### Sources
|
||||
|
||||
* https://www.haiku-os.org/legacy-docs/benewsletter/Issue1-27.html
|
||||
* https://www.cebix.net/downloads/bebox/82378zb.pdf
|
||||
@@ -84,7 +84,7 @@ 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
|
||||
slowest one. Fortunately, the probability that this path will be taken seems to be
|
||||
very low.
|
||||
|
||||
The complete algorithm looks like that:
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
The PowerPC is the main processor behind Power Macs. Currently, DingusPPC only implements the 32-bit variant.
|
||||
The PowerPC is the main processor used for Power Macs. Currently, DingusPPC only implements the 32-bit variant.
|
||||
|
||||
# General Notes
|
||||
|
||||
All instructions are 32 bits wide, regardless of whether the PowerPC is in 32-bit or 64-bit mode.
|
||||
|
||||
Code execution generally begins at 0xFFF00100, which the reset exception vector.
|
||||
|
||||
# BATs
|
||||
|
||||
The 601 BATs are emulated by the Open Firmware.
|
||||
@@ -27,17 +25,17 @@ Up to 128 instruction entries and 128 data entries can be stored at a time.
|
||||
|
||||
# Registers
|
||||
|
||||
| Register Type | Number | Purpose |
|
||||
| :-------------------------------- | :--------------------- | :---------------------------------------------------- |
|
||||
| General Purpose (GPR) | 32 | Calculate, Store, and Load 32-bit fixed-point numbers |
|
||||
| Floating Point (FPR) | 32 | Calculate, Store, and Load 32-bit or 64-bit floating-point numbers |
|
||||
| Special Purpose (SPR) | Up to 1024 (in theory) | Store and load specialized 32-bit fixed-point numbers |
|
||||
| Segment (SR) | 16 | Calculate, Store, and Load 32-bit fixed-point numbers |
|
||||
| Time Base Facility (TBR) | 2 | Calculate, Store, and Load 32-bit fixed-point numbers |
|
||||
| Condition Register | 1 | Stores conditions based on the results of fixed-point operations |
|
||||
| Floating Point Condition Register | 1 | Stores conditions based on the results of floating-point operations |
|
||||
| Vector Status and Control Register (VSCR) | 1 | Stores conditions based on the results of vector operations |
|
||||
| Machine State Register | 1 | |
|
||||
| Register Type | Number | Purpose |
|
||||
| :----------------------------------------- | :--------------------- | :------------------------------------------------------------------ |
|
||||
| General Purpose (GPR) | 32 | Calculate, Store, and Load 32-bit fixed-point numbers |
|
||||
| Floating Point (FPR) | 32 | Calculate, Store, and Load 32-bit or 64-bit floating-point numbers |
|
||||
| Special Purpose (SPR) | Up to 1024 (in theory) | Store and load specialized 32-bit fixed-point numbers |
|
||||
| Segment (SR) | 16 | Calculate, Store, and Load 32-bit fixed-point numbers |
|
||||
| Time Base Facility (TBR) | 2 | Calculate, Store, and Load 32-bit fixed-point numbers |
|
||||
| Condition Register | 1 | Stores conditions based on the results of fixed-point operations |
|
||||
| Floating Point Condition Register | 1 | Stores conditions based on the results of floating-point operations |
|
||||
| Vector Status and Control Register (VSCR) | 1 | Stores conditions based on the results of vector operations |
|
||||
| Machine State Register (MSR) | 1 | Stores the state of the processor |
|
||||
|
||||
|
||||
# Special Registers
|
||||
@@ -50,6 +48,9 @@ Up to 128 instruction entries and 128 data entries can be stored at a time.
|
||||
| RTC Lower Register (RTCL) | 5 | (601 only) |
|
||||
| Link Register (LR) | 8 | |
|
||||
| Counter Quotient Register (CTR) | 9 | |
|
||||
| Search Description Register (SDR1)| 25 | Specifies starting address of the page table |
|
||||
| Save and Restore Register 0 (SRR0)| 26 | |
|
||||
| Save and Restore Register 1 (SRR1)| 27 | |
|
||||
| Vector Save/Restore | 256 | (G4+) |
|
||||
| Time Base Lower (TBL) | 268 | (603+) |
|
||||
| Time Base Upper (TBU) | 269 | (603+) |
|
||||
@@ -58,7 +59,7 @@ Up to 128 instruction entries and 128 data entries can be stored at a time.
|
||||
| Hardware Implementation 0 (HID0) | 1008 | |
|
||||
| Hardware Implementation 1 (HID1) | 1009 | |
|
||||
|
||||
# HID 0
|
||||
## HID 0
|
||||
|
||||
| Model | Bits Enabled |
|
||||
| :------------ | :------------------ |
|
||||
@@ -70,6 +71,34 @@ Up to 128 instruction entries and 128 data entries can be stored at a time.
|
||||
| 604E | NHR |
|
||||
| 750 (G3) | NHR, DOZE/NAP/SLEEP |
|
||||
|
||||
# Exceptions
|
||||
|
||||
nnn is either 0x000 or 0xFFF, depending on the 25th bit (0x40) set in the MSR. Usually, the 25th bit is set when booting up a system and unset after it is set.
|
||||
|
||||
| Exception | Address |
|
||||
| :------------------------------------ | :--------- |
|
||||
| System Reset | 0xnnn00100 |
|
||||
| Machine Check | 0xnnn00200 |
|
||||
| DSI | 0xnnn00300 |
|
||||
| ISI | 0xnnn00400 |
|
||||
| External Interrupt | 0xnnn00500 |
|
||||
| Alignment | 0xnnn00600 |
|
||||
| Program | 0xnnn00700 |
|
||||
| Floating Point Unavailable | 0xnnn00800 |
|
||||
| Decrementer | 0xnnn00900 |
|
||||
| System Call | 0xnnn00C00 |
|
||||
| Trace | 0xnnn00D00 |
|
||||
| Performance Monitor (G3+) | 0xnnn00F00 |
|
||||
| AltiVec Unavailable (G4+) | 0xnnn00F20 |
|
||||
| Instruction Address Breakpoint (G3+) | 0xnnn01300 |
|
||||
| System Management Interrupt (G3+) | 0xnnn01400 |
|
||||
| AltiVec Assist (G4+) | 0xnnn01600 |
|
||||
| Thermal Management Interrupt (G3+) | 0xnnn01700 |
|
||||
|
||||
# Endianness
|
||||
|
||||
PowerPC supports both big-endian and little-endian modes. Mac OS largely operates in big-endian mode, due to its 68k heritage.
|
||||
|
||||
# Eccentricities
|
||||
|
||||
* The HW Init routine used in the ROMs uses the DEC (decrement; SPR 22) register to measure CPU speed. With a PowerPC 601, the DEC register operates on the same frequency as RTC - 7.8125 MHz but uses only 25 most significant bits. In other words, it decrements by 128 at 1/7.8125 MHz.
|
||||
@@ -80,4 +109,8 @@ Up to 128 instruction entries and 128 data entries can be stored at a time.
|
||||
|
||||
* The 603 relies on the instructions tlbld and tlbli to assist in TLB reloading.
|
||||
|
||||
* To accomodate for early programs compiled on PowerPC 601 Macs, the classic Mac OS has to emulate the POWER instructions that were removed from later processors.
|
||||
* To accommodate for early programs compiled on PowerPC 601 Macs, the classic Mac OS has to emulate the POWER instructions that were removed from later processors.
|
||||
|
||||
# References
|
||||
|
||||
http://www.ibmfiles.com/ibmfiles/powerpc/itso_powerpc_inside_view.pdf
|
||||
@@ -0,0 +1,71 @@
|
||||
The Description-Based Direct Memory Access (DBDMA) relies on memory-based descriptions, minimizing CPU interrupts.
|
||||
|
||||
| Channel | Number |
|
||||
|:-----------------:|:------:|
|
||||
| SCSI0 | 0x0 |
|
||||
| FLOPPY | 0x1 |
|
||||
| ETHERNET TRANSMIT | 0x2 |
|
||||
| ETHERNET RECIEVE | 0x3 |
|
||||
| SCC TRANSMIT A | 0x4 |
|
||||
| SCC RECIEVE A | 0x5 |
|
||||
| SCC TRANSMIT B | 0x6 |
|
||||
| SCC RECIEVE B | 0x7 |
|
||||
| AUDIO OUT | 0x8 |
|
||||
| AUDIO IN | 0x9 |
|
||||
| SCSI1 | 0xA |
|
||||
|
||||
What's notable about the registers is that they are in little-endian format, thus Mac OS uses the stwbrx and lwbrx instructions to store values.
|
||||
|
||||
| Register | Offset |
|
||||
|:-----------------:|:------:|
|
||||
| ChannelControl | 0x00 |
|
||||
| ChannelStatus | 0x04 |
|
||||
| CommandPtrHi | 0x08 |
|
||||
| CommandPtrLo | 0x0C |
|
||||
| InterruptSelect | 0x10 |
|
||||
| BranchSelect | 0x14 |
|
||||
| WaitSelect | 0x18 |
|
||||
| TransferMode | 0x1C |
|
||||
| Data2PtrHi | 0x20 |
|
||||
| Data2PtrLo | 0x24 |
|
||||
| BranchPtrHi | 0x2C |
|
||||
| BranchPtrLo | 0x30 |
|
||||
|
||||
| Command | Value |
|
||||
|:-----------------:|:------:|
|
||||
| OUTPUT_MORE | 0x0 |
|
||||
| OUTPUT_LAST | 0x1 |
|
||||
| INPUT_MORE | 0x2 |
|
||||
| INPUT_LAST | 0x3 |
|
||||
| STORE_QUAD | 0x4 |
|
||||
| LOAD_QUAD | 0x5 |
|
||||
| NOP | 0x6 |
|
||||
| STOP | 0x7 |
|
||||
|
||||
| Key Name | Value |
|
||||
|:-----------------:|:------:|
|
||||
| KEY_STREAM0 | 0x0 |
|
||||
| KEY_STREAM1 | 0x1 |
|
||||
| KEY_STREAM2 | 0x2 |
|
||||
| KEY_STREAM3 | 0x3 |
|
||||
| KEY_REGS | 0x5 |
|
||||
| KEY_SYSTEM | 0x6 |
|
||||
| KEY_DEVICE | 0x7 |
|
||||
|
||||
## Control Register
|
||||
|
||||
| Value | Offset |
|
||||
|:-----------:|:------:|
|
||||
| Branch | 0x100 |
|
||||
| Active | 0x400 |
|
||||
| Dead | 0x800 |
|
||||
| Wake | 0x1000 |
|
||||
| Flush | 0x2000 |
|
||||
| Pause | 0x4000 |
|
||||
| Run | 0x8000 |
|
||||
|
||||
|
||||
## References
|
||||
|
||||
* https://stuff.mit.edu/afs/sipb/contrib/doc/specs/protocol/chrp/chrp_io.pdf
|
||||
* https://stuff.mit.edu/afs/sipb/contrib/doc/specs/protocol/chrp/chrp_hrpa.pdf
|
||||
@@ -282,7 +282,7 @@ from "Writing FCode Programs For PCI"
|
||||
\ in the PCI node. If the add-range method is present in an Apple ROM, the map-in
|
||||
\ method is broken. If the add-range property is absent, the map-in method behaves
|
||||
\ correctly.
|
||||
\ The following methods allow the FCode driver to accomodate both broken and working
|
||||
\ The following methods allow the FCode driver to accommodate both broken and working
|
||||
\ map-in methods.
|
||||
|
||||
: map-in-broken? ( -- flag )
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Heathrow ASIC
|
||||
|
||||
The Heathrow ASIC is an intergrated I/O controller designed for use in Power
|
||||
The Heathrow ASIC is an integrated I/O controller designed for use in Power
|
||||
Macintosh G3 computers.
|
||||
|
||||
Its predecessors are Grand Central and O'Hare ASICs used in other Power Macintosh
|
||||
@@ -17,7 +17,7 @@ I/O hardware to the PCI-based Power Macintosh. That legacy hardware has
|
||||
existed long before Power Macintosh was introduced. It includes:
|
||||
- versatile interface adapter (VIA)
|
||||
- Sander-Woz integrated machine (SWIM) that is a floppy disk controller
|
||||
- CUDA MCU that controls ADB, parameter RAM, realtime clock and power management
|
||||
- CUDA MCU that controls ADB, parameter RAM, real time clock and power management
|
||||
- serial communication controller (SCC)
|
||||
- Macintosh Enhanced SCSI Hardware (MESH)
|
||||
|
||||
@@ -90,7 +90,7 @@ Macintosh firmware configures the Heathrow ASIC to live at address `0xF3000000`.
|
||||
| 0x30 | UnknownReg30 | Not much is known about this register |
|
||||
| 0x34 | HeathrowIDs | bits for identifying media bay features? |
|
||||
| 0x38 | FeatureControl | bits for controlling Heathrow operation |
|
||||
| 0x3C | AuxControl | auxilary control bits |
|
||||
| 0x3C | AuxControl | auxiliary control bits |
|
||||
|
||||
### Device DMA spaces
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
The following document is intended primarily as a documentation on how the IBM Personal Power series (and similar computers) operates. It is currently not implemented in DingusPPC.
|
||||
|
||||
## Sources
|
||||
|
||||
* http://ps-2.kev009.com/rs6000/redbook-cd/sg245120.pdf
|
||||
* http://ps-2.kev009.com/rs6000/rs6000_ps_pdf/Graphics/RS6000_Graphics_Handbook.pdf
|
||||
Loaded 100 of 106 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user