mirror of
https://github.com/dingusdev/dingusppc.git
synced 2026-12-01 06:23:18 -10:00
Compare commits
234
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b6716be5c | ||
|
|
449cc96612 | ||
|
|
bcd443779a | ||
|
|
6b6e92d3d9 | ||
|
|
a189c94980 | ||
|
|
dee225ee8f | ||
|
|
52bb87b72a | ||
|
|
0dd9a3d9b1 | ||
|
|
86b0174b13 | ||
|
|
daf3ecde4e | ||
|
|
1e9ec5d7ae | ||
|
|
2537751fa7 | ||
|
|
df1a56305a | ||
|
|
6173a782f2 | ||
|
|
a892842b8f | ||
|
|
58908621e6 | ||
|
|
311538b81d | ||
|
|
a58ce8aeb3 | ||
|
|
8f99510af0 | ||
|
|
13684f7c0b | ||
|
|
5f0358a347 | ||
|
|
647ae456e5 | ||
|
|
1b7ff084ab | ||
|
|
1ed6e25d1b | ||
|
|
db17e19699 | ||
|
|
3de89eaaf7 | ||
|
|
d50152dd1a | ||
|
|
2f02ea4276 | ||
|
|
b2ef809de1 | ||
|
|
c87fc10376 | ||
|
|
a00b87790b | ||
|
|
ca5f81417f | ||
|
|
40a02cc0f7 | ||
|
|
49331635b2 | ||
|
|
0c4da80c93 | ||
|
|
7bc4b8840a | ||
|
|
5a59b97257 | ||
|
|
5a33fba75e | ||
|
|
0c74ebbc45 | ||
|
|
2865a611e7 | ||
|
|
f2be286515 | ||
|
|
2c3a5c3b8f | ||
|
|
c54c1cdb65 | ||
|
|
8abefb8f8d | ||
|
|
6ffe28a8a4 | ||
|
|
7ab44886c4 | ||
|
|
fbfae98d6d | ||
|
|
c7ceb9d6b9 | ||
|
|
3f2b77fd59 | ||
|
|
3050986164 | ||
|
|
c28fd138c2 | ||
|
|
b480903c7a | ||
|
|
46a0e82258 | ||
|
|
a58c9b1a62 | ||
|
|
f3cd5b8b36 | ||
|
|
2065f3588b | ||
|
|
f792b38ea3 | ||
|
|
4f6bd16f3a | ||
|
|
c51ea575ca | ||
|
|
9efac80271 | ||
|
|
eeb576a927 | ||
|
|
3af9729e5b | ||
|
|
a085d55d13 | ||
|
|
c2abc89a3b | ||
|
|
aa1d23e08b | ||
|
|
ee9573327c | ||
|
|
a61dd5701a | ||
|
|
5b08f283e5 | ||
|
|
50053a52dc | ||
|
|
4a8a712868 | ||
|
|
e41b196977 | ||
|
|
6c59bf4203 | ||
|
|
bb77b2d525 | ||
|
|
293c5a40f3 | ||
|
|
994f8d7155 | ||
|
|
b38d00ce2d | ||
|
|
141a276c5b | ||
|
|
1c1300ce5a | ||
|
|
1ccc8d1a25 | ||
|
|
67b7c86755 | ||
|
|
3ee2ea1871 | ||
|
|
3b4f40635a | ||
|
|
c644d1609f | ||
|
|
d843091a4d | ||
|
|
6fad095730 | ||
|
|
6af8b52376 | ||
|
|
fca6cb11b6 | ||
|
|
753427f262 | ||
|
|
6fbe03adb3 | ||
|
|
f78db220bc | ||
|
|
63248b0fa2 | ||
|
|
cd122ce263 | ||
|
|
e097b7a0a1 | ||
|
|
32b8c8ed43 | ||
|
|
5220b03f0f | ||
|
|
336ea14422 | ||
|
|
56c54e4c8c | ||
|
|
f4c0499078 | ||
|
|
4964008511 | ||
|
|
c5ecdb840d | ||
|
|
0dbcda5710 | ||
|
|
8c0f391548 | ||
|
|
7f57e96335 | ||
|
|
93fae1ee68 | ||
|
|
650c2c88dd | ||
|
|
3f3af68582 | ||
|
|
8cdbd9f81f | ||
|
|
b76bfedf4b | ||
|
|
eecb5a0f42 | ||
|
|
b67644ba35 | ||
|
|
56db0426a4 | ||
|
|
5463c8e6cb | ||
|
|
fd41cafc4b | ||
|
|
8dfdf55dff | ||
|
|
a0e660f6b4 | ||
|
|
cd1d0031e6 | ||
|
|
4216c412b3 | ||
|
|
bd19914132 | ||
|
|
9a6336adb9 | ||
|
|
e3900b9062 | ||
|
|
ea0fb3b410 | ||
|
|
c3939e3b25 | ||
|
|
f0553720d6 | ||
|
|
3c062443f6 | ||
|
|
b9fb0b9c5f | ||
|
|
65512dc434 | ||
|
|
b8915f11a2 | ||
|
|
c0078ce97d | ||
|
|
9971052a78 | ||
|
|
7db0a31cc5 | ||
|
|
5e6f3a51b5 | ||
|
|
c37893847a | ||
|
|
1d37982d02 | ||
|
|
41a314d6d6 | ||
|
|
2dfc160e30 | ||
|
|
5f8a927846 | ||
|
|
97b3b9a6f8 | ||
|
|
cb68b70d52 | ||
|
|
66debbc730 | ||
|
|
9056d53474 | ||
|
|
ca51c34157 | ||
|
|
7fc28baf96 | ||
|
|
439029cafe | ||
|
|
dc5373ae27 | ||
|
|
f9ec73cd05 | ||
|
|
5668fc161f | ||
|
|
1d6f296d10 | ||
|
|
913944c607 | ||
|
|
fd3ff7b703 | ||
|
|
cdc670268a | ||
|
|
06001a778f | ||
|
|
f93df3b5c3 | ||
|
|
fcd2ddcc14 | ||
|
|
51e6ffb24f | ||
|
|
0c77cccb9e | ||
|
|
d928d3ff55 | ||
|
|
4c9001901e | ||
|
|
da25e72668 | ||
|
|
16bf46506a | ||
|
|
0df1b2c408 | ||
|
|
226b51d8db | ||
|
|
cd7624feb5 | ||
|
|
bd24b644c9 | ||
|
|
ed02a06bb8 | ||
|
|
5b7e79b979 | ||
|
|
bfd48eeeb2 | ||
|
|
4225f0aec2 | ||
|
|
6b686e402e | ||
|
|
dd79ec38e4 | ||
|
|
898c677ffb | ||
|
|
a7e06f4e4b | ||
|
|
4b2f3cedc7 | ||
|
|
32891867f2 | ||
|
|
0ab4f4a7f9 | ||
|
|
b47de8b042 | ||
|
|
934f794d20 | ||
|
|
9317719814 | ||
|
|
4676cfeee2 | ||
|
|
8be44dad82 | ||
|
|
617f75851b | ||
|
|
fc3901676b | ||
|
|
fcfb2372b9 | ||
|
|
36098af5eb | ||
|
|
d863fa0c80 | ||
|
|
1f67a57d7b | ||
|
|
9d7d9f3103 | ||
|
|
8d9691cc6f | ||
|
|
6c564cb720 | ||
|
|
4b32e9bd30 | ||
|
|
23a046d889 | ||
|
|
cdb34032bc | ||
|
|
74f4dbd7e6 | ||
|
|
8889759f33 | ||
|
|
372a5dfe1a | ||
|
|
22988f9e28 | ||
|
|
533edf6ef5 | ||
|
|
9d89c5f64e | ||
|
|
b26baaaeff | ||
|
|
e0b94e0b47 | ||
|
|
d4c08bbe31 | ||
|
|
be4f835e6c | ||
|
|
57b102dae2 | ||
|
|
0e09ecdfa4 | ||
|
|
8fcdc5298a | ||
|
|
3a4f22f459 | ||
|
|
b78f17c161 | ||
|
|
4bba61a920 | ||
|
|
d64f901f85 | ||
|
|
883aac2d05 | ||
|
|
f6e5d72e3c | ||
|
|
c967eb3c65 | ||
|
|
89d453b4be | ||
|
|
ba8e3b657c | ||
|
|
4d87ed9b38 | ||
|
|
d71a7b8694 | ||
|
|
e01d0e3d59 | ||
|
|
1d86375061 | ||
|
|
4525fd50cc | ||
|
|
29ce960dbf | ||
|
|
ac5078f133 | ||
|
|
276cd37cfe | ||
|
|
1500c63e26 | ||
|
|
4c45b3dfa2 | ||
|
|
574677490f | ||
|
|
e47b66e1af | ||
|
|
73aa68bc30 | ||
|
|
3bce7bb1ea | ||
|
|
6d004f0bf8 | ||
|
|
e913f39812 | ||
|
|
3235018260 | ||
|
|
a7e4dc9d83 | ||
|
|
13f18c416d | ||
|
|
400ce0b713 | ||
|
|
289df32817 |
No files matched your search
@@ -112,6 +112,7 @@ add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:core>
|
||||
if (WIN32)
|
||||
target_link_libraries(dingusppc "${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2.lib"
|
||||
"${PROJECT_SOURCE_DIR}/thirdparty/SDL2/lib/x64/SDL2main.lib"
|
||||
ws2_32
|
||||
cubeb)
|
||||
else()
|
||||
#target_link_libraries(dingusppc libsoundio_static ${LIBSOUNDIO_LIBS} ${SDL2_LIBRARIES})
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "x64-Debug",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Debug",
|
||||
"inheritEnvironments": [ "clang_cl_x64" ],
|
||||
"buildRoot": "${projectDir}\\out\\build\\${name}",
|
||||
"installRoot": "${projectDir}\\out\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": "",
|
||||
"variables": []
|
||||
},
|
||||
{
|
||||
"name": "x64-Release",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Release",
|
||||
"buildRoot": "${projectDir}\\out\\build\\${name}",
|
||||
"installRoot": "${projectDir}\\out\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": "",
|
||||
"inheritEnvironments": [ "clang_cl_x64" ],
|
||||
"variables": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -12,7 +12,7 @@ This program aims to not only improve upon what Sheepshaver, PearPC, and other P
|
||||
|
||||
## Implemented Features
|
||||
|
||||
This emulator has a debugging environment, complete with a disassembler. We also have implemented enough to allow OpenFirmware to boot, going so far as to allow audio playback of the boot-up jingles.
|
||||
This emulator has a debugging environment, complete with a disassembler. We also have implemented enough to allow Open Firmware to boot, going so far as to allow audio playback of the boot-up jingles.
|
||||
|
||||
## How to Use
|
||||
|
||||
@@ -52,7 +52,7 @@ You need to install development tools first.
|
||||
|
||||
At least, a C++11 compliant compiler and [CMake](https://cmake.org) are required.
|
||||
|
||||
You will also have to recursive clone or run
|
||||
You will also have to recursive clone or run
|
||||
```
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
+2
-1
@@ -33,7 +33,8 @@ using namespace std;
|
||||
|
||||
#define MIN_TIMEOUT_NS 200
|
||||
|
||||
#define NS_PER_SEC 1E9
|
||||
#define NS_PER_SEC 1E9
|
||||
#define ONE_BILLION_NS 0x3B9ACA00UL
|
||||
|
||||
#define USECS_TO_NSECS(us) (us) * 1000
|
||||
|
||||
|
||||
+19
-43
@@ -136,64 +136,40 @@ void dppc_interpreter::power_dozi() {
|
||||
|
||||
void dppc_interpreter::power_lscbx() {
|
||||
ppc_grab_regsdab();
|
||||
ppc_effective_address = (reg_a == 0) ? ppc_result_b : ppc_result_a + ppc_result_b;
|
||||
ppc_effective_address = (reg_a == 0) ? ppc_result_b : ppc_result_a + ppc_result_b;
|
||||
//ppc_result_d = 0xFFFFFFFF;
|
||||
|
||||
uint8_t return_value = 0;
|
||||
uint32_t bytes_to_load = (ppc_state.spr[SPR::XER] & 0x7f);
|
||||
uint32_t bytes_copied = 0;
|
||||
uint8_t matching_byte = (uint8_t)((ppc_state.spr[SPR::XER] & 0xFF00) >> 8);
|
||||
uint32_t byte_offset = 0;
|
||||
|
||||
//for storing each byte
|
||||
uint32_t bitmask = 0;
|
||||
uint32_t shift_amount = 0;
|
||||
// for storing each byte
|
||||
uint32_t bitmask = 0xFF000000;
|
||||
uint8_t shift_amount = 24;
|
||||
|
||||
while (bytes_to_load > 0) {
|
||||
if (byte_offset == 24) {
|
||||
reg_d = (reg_d + 1) % 32;
|
||||
ppc_result_d = 0xFFFFFFFF;
|
||||
ppc_store_result_regd();
|
||||
}
|
||||
|
||||
|
||||
switch (byte_offset) {
|
||||
case 0:
|
||||
bitmask = 0x00FFFFFF;
|
||||
shift_amount = 24;
|
||||
break;
|
||||
case 8:
|
||||
bitmask = 0xFF00FFFF;
|
||||
shift_amount = 16;
|
||||
break;
|
||||
case 16:
|
||||
bitmask = 0xFFFF00FF;
|
||||
shift_amount = 8;
|
||||
break;
|
||||
case 24:
|
||||
bitmask = 0xFFFFFF00;
|
||||
shift_amount = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return_value = mmu_read_vmem<uint8_t>(ppc_effective_address);
|
||||
// return_value = mem_grab_byte(ppc_effective_address);
|
||||
ppc_result_d = (ppc_result_d & bitmask) | (return_value << shift_amount);
|
||||
ppc_result_d = (ppc_result_d & ~(bitmask)) | (return_value << shift_amount);
|
||||
ppc_store_result_regd();
|
||||
bytes_copied++;
|
||||
|
||||
if (return_value == matching_byte) {
|
||||
//Match has been found - Time to break out
|
||||
break;
|
||||
}
|
||||
|
||||
byte_offset += 8;
|
||||
|
||||
if (byte_offset == 32) {
|
||||
byte_offset = 0;
|
||||
if (bitmask == 0x000000FF) {
|
||||
reg_d = (reg_d + 1) & 31;
|
||||
//ppc_result_d = 0xFFFFFFFF;
|
||||
bitmask = 0xFF000000;
|
||||
shift_amount = 24;
|
||||
}
|
||||
else {
|
||||
bitmask >>= 8;
|
||||
shift_amount -= 8;
|
||||
}
|
||||
|
||||
ppc_effective_address++;
|
||||
bytes_copied++;
|
||||
bytes_to_load--;
|
||||
|
||||
if (return_value == matching_byte)
|
||||
break;
|
||||
}
|
||||
|
||||
ppc_state.spr[SPR::XER] = (ppc_state.spr[SPR::XER] & 0xFFFFFF80) | bytes_copied;
|
||||
|
||||
+26
-16
@@ -84,22 +84,29 @@ extern SetPRS ppc_state;
|
||||
|
||||
/** symbolic names for frequently used SPRs */
|
||||
enum SPR : int {
|
||||
MQ = 0,
|
||||
XER = 1,
|
||||
LR = 8,
|
||||
CTR = 9,
|
||||
DSISR = 18,
|
||||
DAR = 19,
|
||||
DEC = 22,
|
||||
SDR1 = 25,
|
||||
SRR0 = 26,
|
||||
SRR1 = 27,
|
||||
PVR = 287
|
||||
MQ = 0,
|
||||
XER = 1,
|
||||
RTCU_U = 4, // user RTCU
|
||||
RTCL_U = 5, // user RTCL
|
||||
LR = 8,
|
||||
CTR = 9,
|
||||
DSISR = 18,
|
||||
DAR = 19,
|
||||
RTCU_S = 20, // supervisor RTCU
|
||||
RTCL_S = 21, // supervisor RTCL
|
||||
DEC = 22,
|
||||
SDR1 = 25,
|
||||
SRR0 = 26,
|
||||
SRR1 = 27,
|
||||
TBL_U = 268, // user mode TBL
|
||||
TBU_U = 269, // user mode TBU
|
||||
TBL_S = 284, // supervisor TBL
|
||||
TBU_S = 285, // supervisor TBU
|
||||
PVR = 287,
|
||||
HID0 = 1008,
|
||||
HID1 = 1009,
|
||||
};
|
||||
|
||||
/** symbolic names for frequently used SPRs */
|
||||
enum TBR : int { TBL = 0, TBU = 1 };
|
||||
|
||||
/** symbolic names for common PPC processors */
|
||||
enum PPC_VER : uint32_t {
|
||||
MPC601 = 0x00010001,
|
||||
@@ -154,6 +161,7 @@ extern uint64_t timebase_counter;
|
||||
extern uint64_t tbr_wr_timestamp;
|
||||
extern uint64_t tbr_wr_value;
|
||||
extern uint64_t tbr_freq_hz;
|
||||
extern uint32_t rtc_lo, rtc_hi;
|
||||
|
||||
// Additional steps to prevent overflow?
|
||||
extern int32_t add_result;
|
||||
@@ -298,6 +306,7 @@ extern jmp_buf exc_env;
|
||||
extern bool grab_return;
|
||||
|
||||
extern bool power_on;
|
||||
extern bool int_pin;
|
||||
|
||||
extern bool is_601; // For PowerPC 601 Emulation
|
||||
extern bool is_altivec; // For Altivec Emulation
|
||||
@@ -321,12 +330,13 @@ extern uint64_t exceptions_processed;
|
||||
#endif
|
||||
|
||||
// Function prototypes
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version);
|
||||
extern void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, uint64_t tb_freq);
|
||||
extern void ppc_mmu_init(uint32_t cpu_version);
|
||||
|
||||
void ppc_illegalop();
|
||||
void ppc_fpu_off();
|
||||
void ppc_ext_int();
|
||||
void ppc_assert_int();
|
||||
void ppc_release_int();
|
||||
|
||||
//void ppc_opcode4();
|
||||
void ppc_opcode16();
|
||||
|
||||
+27
-15
@@ -43,8 +43,8 @@ bool power_on = 1;
|
||||
|
||||
SetPRS ppc_state;
|
||||
|
||||
bool rc_flag = 0; // Record flag
|
||||
bool oe_flag = 0; // Overflow flag
|
||||
bool rc_flag = 0; // Record flag
|
||||
bool oe_flag = 0; // Overflow flag
|
||||
|
||||
bool grab_return;
|
||||
bool grab_breakpoint;
|
||||
@@ -53,7 +53,8 @@ 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;
|
||||
unsigned exec_flags; // execution control flags
|
||||
bool int_pin = false; // interrupt request pin state: true - asserted
|
||||
|
||||
/* copy of local variable bb_start_la. Need for correct
|
||||
calculation of CPU cycles after setjmp that clobbers
|
||||
@@ -65,11 +66,13 @@ uint64_t g_icycles;
|
||||
int icnt_factor;
|
||||
|
||||
/* global variables related to the timebase facility */
|
||||
uint64_t tbr_wr_timestamp; // stores vCPU virtual time of the last TBR write
|
||||
uint64_t tbr_wr_timestamp; // stores vCPU virtual time of the last TBR/RTC write
|
||||
uint64_t tbr_wr_value; // last value written to the TBR
|
||||
uint64_t tbr_freq_hz; // TBR driving frequency in Hz
|
||||
uint64_t tbr_freq_hz; // TBR/RTC driving frequency in Hz
|
||||
uint64_t timebase_counter; // internal timebase counter
|
||||
uint32_t decr; // current value of PPC DEC register
|
||||
uint32_t rtc_lo; // MPC601 RTC lower, counts nanoseconds
|
||||
uint32_t rtc_hi; // MPC601 RTC upper, counts seconds
|
||||
|
||||
#ifdef CPU_PROFILING
|
||||
|
||||
@@ -168,12 +171,20 @@ void ppc_fpu_off() {
|
||||
ppc_exception_handler(Except_Type::EXC_PROGRAM, Exc_Cause::FPU_OFF);
|
||||
}
|
||||
|
||||
void ppc_ext_int() {
|
||||
void ppc_assert_int() {
|
||||
int_pin = true;
|
||||
if (ppc_state.msr & 0x8000) {
|
||||
LOG_F(5, "CPU ExtIntHandler called");
|
||||
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
|
||||
} else {
|
||||
LOG_F(5, "CPU IRQ ignored!");
|
||||
}
|
||||
}
|
||||
|
||||
void ppc_release_int() {
|
||||
int_pin = false;
|
||||
}
|
||||
|
||||
/** Opcode decoding functions. */
|
||||
|
||||
void ppc_opcode16() {
|
||||
@@ -189,7 +200,7 @@ void ppc_opcode19() {
|
||||
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
uint32_t regrab = (uint32_t)subop_grab;
|
||||
LOG_F(INFO, "Executing Opcode 19 table subopcode entry \n", regrab);
|
||||
LOG_F(INFO, "Executing Opcode 19 table subopcode entry", regrab);
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
|
||||
if (subop_grab == 32) {
|
||||
@@ -249,7 +260,7 @@ void ppc_opcode31() {
|
||||
oe_flag = ppc_cur_instruction & 0x400;
|
||||
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
LOG_F(INFO, "Executing Opcode 31 table subopcode entry %n \n", (uint32_t)subop_grab);
|
||||
LOG_F(INFO, "Executing Opcode 31 table subopcode entry %n", (uint32_t)subop_grab);
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
|
||||
SubOpcode31Grabber[subop_grab]();
|
||||
@@ -259,7 +270,7 @@ void ppc_opcode59() {
|
||||
uint16_t subop_grab = (ppc_cur_instruction >> 1) & 0x1F;
|
||||
rc_flag = ppc_cur_instruction & 1;
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
LOG_F(INFO, "Executing Opcode 59 table subopcode entry %n \n", (uint32_t)subop_grab);
|
||||
LOG_F(INFO, "Executing Opcode 59 table subopcode entry %n", (uint32_t)subop_grab);
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
SubOpcode59Grabber[subop_grab]();
|
||||
}
|
||||
@@ -268,7 +279,7 @@ void ppc_opcode63() {
|
||||
uint16_t subop_grab = (ppc_cur_instruction >> 1) & 0x3FF;
|
||||
rc_flag = ppc_cur_instruction & 1;
|
||||
#ifdef EXHAUSTIVE_DEBUG
|
||||
LOG_F(INFO, "Executing Opcode 63 table subopcode entry %n \n", (uint32_t)subop_grab);
|
||||
LOG_F(INFO, "Executing Opcode 63 table subopcode entry %n", (uint32_t)subop_grab);
|
||||
#endif // EXHAUSTIVE_DEBUG
|
||||
SubOpcode63Grabber[subop_grab]();
|
||||
}
|
||||
@@ -393,6 +404,9 @@ void ppc_exec_single()
|
||||
|
||||
mmu_translate_imem(ppc_state.pc);
|
||||
ppc_main_opcode();
|
||||
g_icycles++;
|
||||
process_events();
|
||||
|
||||
if (exec_flags) {
|
||||
if (exec_flags & EXEF_TIMER) {
|
||||
ppc_state.pc += 4;
|
||||
@@ -403,7 +417,6 @@ void ppc_exec_single()
|
||||
} else {
|
||||
ppc_state.pc += 4;
|
||||
}
|
||||
g_icycles++;
|
||||
}
|
||||
|
||||
/** Execute PPC code until goal_addr is reached. */
|
||||
@@ -734,13 +747,12 @@ void initialize_ppc_opcode_tables() {
|
||||
}
|
||||
}
|
||||
|
||||
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version) {
|
||||
void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version, uint64_t tb_freq)
|
||||
{
|
||||
int i;
|
||||
|
||||
mem_ctrl_instance = mem_ctrl;
|
||||
|
||||
//test_timebase_update();
|
||||
|
||||
initialize_ppc_opcode_tables();
|
||||
|
||||
// initialize emulator timers
|
||||
@@ -752,7 +764,7 @@ void ppc_cpu_init(MemCtrlBase* mem_ctrl, uint32_t cpu_version) {
|
||||
icnt_factor = 4;
|
||||
tbr_wr_timestamp = 0;
|
||||
tbr_wr_value = 0;
|
||||
tbr_freq_hz = 16705000; // FIXME: this should be set properly during machine initialization
|
||||
tbr_freq_hz = tb_freq;
|
||||
|
||||
exec_flags = 0;
|
||||
|
||||
|
||||
+11
-11
@@ -615,7 +615,7 @@ static TLBEntry* dtlb2_refill(uint32_t guest_va, int is_write)
|
||||
}
|
||||
return tlb_entry;
|
||||
} else {
|
||||
LOG_F(WARNING, "Access to unmapped physical memory, phys_addr=0x%08X\n", phys_addr);
|
||||
LOG_F(WARNING, "Access to unmapped physical memory, phys_addr=0x%08X", phys_addr);
|
||||
return &UnmappedMem;
|
||||
}
|
||||
}
|
||||
@@ -947,7 +947,7 @@ void mmu_pat_ctx_changed()
|
||||
void mmu_print_regs()
|
||||
{
|
||||
LOG_SCOPE_FUNCTION(INFO);
|
||||
LOG_F(INFO, "MSR = 0x%X\n", ppc_state.msr);
|
||||
LOG_F(INFO, "MSR = 0x%X", ppc_state.msr);
|
||||
|
||||
LOG_F(INFO, "BAT registers:");
|
||||
|
||||
@@ -966,7 +966,7 @@ void mmu_print_regs()
|
||||
}
|
||||
|
||||
LOG_F(INFO, "");
|
||||
LOG_F(INFO, "SDR1 = 0x%X\n", ppc_state.spr[SPR::SDR1]);
|
||||
LOG_F(INFO, "SDR1 = 0x%X", ppc_state.spr[SPR::SDR1]);
|
||||
LOG_F(INFO, "Segment registers:");
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
@@ -1372,7 +1372,7 @@ static inline T read_phys_mem(AddressMapEntry *mru_rgn, uint32_t addr)
|
||||
if (entry) {
|
||||
*mru_rgn = *entry;
|
||||
} else {
|
||||
LOG_F(ERROR, "Read from unmapped memory at 0x%08X!\n", addr);
|
||||
LOG_F(ERROR, "Read from unmapped memory at 0x%08X!", addr);
|
||||
return (-1ULL ? sizeof(T) == 8 : -1UL);
|
||||
}
|
||||
}
|
||||
@@ -1402,7 +1402,7 @@ static inline T read_phys_mem(AddressMapEntry *mru_rgn, uint32_t addr)
|
||||
return READ_QWORD_BE_A(mru_rgn->mem_ptr + (addr - mru_rgn->start));
|
||||
}
|
||||
default:
|
||||
LOG_F(ERROR, "READ_PHYS: invalid size %lu passed\n", sizeof(T));
|
||||
LOG_F(ERROR, "READ_PHYS: invalid size %lu passed", sizeof(T));
|
||||
return (-1ULL ? sizeof(T) == 8 : -1UL);
|
||||
}
|
||||
} else if (mru_rgn->type & RT_MMIO) {
|
||||
@@ -1413,7 +1413,7 @@ static inline T read_phys_mem(AddressMapEntry *mru_rgn, uint32_t addr)
|
||||
return (mru_rgn->devobj->read(mru_rgn->start,
|
||||
addr - mru_rgn->start, sizeof(T)));
|
||||
} else {
|
||||
LOG_F(ERROR, "READ_PHYS: invalid region type!\n");
|
||||
LOG_F(ERROR, "READ_PHYS: invalid region type!");
|
||||
return (-1ULL ? sizeof(T) == 8 : -1UL);
|
||||
}
|
||||
}
|
||||
@@ -1426,7 +1426,7 @@ static inline void write_phys_mem(AddressMapEntry *mru_rgn, uint32_t addr, T val
|
||||
if (entry) {
|
||||
*mru_rgn = *entry;
|
||||
} else {
|
||||
LOG_F(ERROR, "Write to unmapped memory at 0x%08X!\n", addr);
|
||||
LOG_F(ERROR, "Write to unmapped memory at 0x%08X!", addr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1460,7 +1460,7 @@ static inline void write_phys_mem(AddressMapEntry *mru_rgn, uint32_t addr, T val
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "WRITE_PHYS: invalid size %lu passed\n", sizeof(T));
|
||||
LOG_F(ERROR, "WRITE_PHYS: invalid size %lu passed", sizeof(T));
|
||||
return;
|
||||
}
|
||||
} else if (mru_rgn->type & RT_MMIO) {
|
||||
@@ -1471,7 +1471,7 @@ static inline void write_phys_mem(AddressMapEntry *mru_rgn, uint32_t addr, T val
|
||||
mru_rgn->devobj->write(mru_rgn->start, addr - mru_rgn->start, value,
|
||||
sizeof(T));
|
||||
} else {
|
||||
LOG_F(ERROR, "WRITE_PHYS: invalid region type!\n");
|
||||
LOG_F(ERROR, "WRITE_PHYS: invalid region type!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1525,7 +1525,7 @@ static uint32_t ppc_mmu_addr_translate(uint32_t la, int is_write)
|
||||
|
||||
static void mem_write_unaligned(uint32_t addr, uint32_t value, uint32_t size) {
|
||||
#ifdef MMU_DEBUG
|
||||
LOG_F(WARNING, "Attempt to write unaligned %d bytes to 0x%08X\n", size, addr);
|
||||
LOG_F(WARNING, "Attempt to write unaligned %d bytes to 0x%08X", size, addr);
|
||||
#endif
|
||||
|
||||
if (((addr & 0xFFF) + size) > 0x1000) {
|
||||
@@ -1627,7 +1627,7 @@ static uint32_t mem_grab_unaligned(uint32_t addr, uint32_t size) {
|
||||
uint32_t ret = 0;
|
||||
|
||||
#ifdef MMU_DEBUG
|
||||
LOG_F(WARNING, "Attempt to read unaligned %d bytes from 0x%08X\n", size, addr);
|
||||
LOG_F(WARNING, "Attempt to read unaligned %d bytes from 0x%08X", size, addr);
|
||||
#endif
|
||||
|
||||
if (((addr & 0xFFF) + size) > 0x1000) {
|
||||
|
||||
+76
-28
@@ -844,7 +844,29 @@ void dppc_interpreter::ppc_mtmsr() {
|
||||
}
|
||||
reg_s = (ppc_cur_instruction >> 21) & 31;
|
||||
ppc_state.msr = ppc_state.gpr[reg_s];
|
||||
mmu_change_mode();
|
||||
|
||||
// generate External Interrupt Exception
|
||||
// if CPU interrupt line is asserted
|
||||
if (ppc_state.msr & 0x8000 && int_pin) {
|
||||
LOG_F(WARNING, "MTMSR: CPU INT pending, generate CPU exception");
|
||||
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
|
||||
} else {
|
||||
mmu_change_mode();
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint64_t calc_rtcl_value()
|
||||
{
|
||||
uint64_t diff = get_virt_time_ns() - tbr_wr_timestamp;
|
||||
uint64_t rtc_inc = diff * tbr_freq_hz / NS_PER_SEC;
|
||||
uint64_t rtc_l = rtc_lo + (rtc_inc << 7);
|
||||
if (rtc_l >= ONE_BILLION_NS) { // check RTCL overflow
|
||||
rtc_hi += rtc_l / ONE_BILLION_NS;
|
||||
rtc_lo = rtc_l % ONE_BILLION_NS;
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
rtc_l = rtc_lo;
|
||||
}
|
||||
return rtc_l & 0x3FFFFF80UL;
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_mfspr() {
|
||||
@@ -855,8 +877,17 @@ void dppc_interpreter::ppc_mfspr() {
|
||||
num_supervisor_instrs++;
|
||||
}
|
||||
#endif
|
||||
reg_d = (ppc_cur_instruction >> 21) & 31;
|
||||
ppc_state.gpr[reg_d] = ppc_state.spr[ref_spr];
|
||||
|
||||
switch (ref_spr) {
|
||||
case SPR::RTCL_U:
|
||||
ppc_state.spr[SPR::RTCL_U] = calc_rtcl_value();
|
||||
break;
|
||||
case SPR::RTCU_U:
|
||||
ppc_state.spr[SPR::RTCL_U] = rtc_hi;
|
||||
break;
|
||||
}
|
||||
|
||||
ppc_state.gpr[(ppc_cur_instruction >> 21) & 31] = ppc_state.spr[ref_spr];
|
||||
}
|
||||
|
||||
static inline uint64_t calc_tbr_value()
|
||||
@@ -871,7 +902,6 @@ static void update_timebase(uint64_t mask, uint64_t new_val)
|
||||
uint64_t tbr_value = calc_tbr_value();
|
||||
tbr_wr_value = (tbr_value & mask) | new_val;
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
LOG_F(9, "New TBR value = 0x%llu", tbr_wr_value);
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_mtspr() {
|
||||
@@ -884,20 +914,30 @@ void dppc_interpreter::ppc_mtspr() {
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ref_spr != 287) {
|
||||
ppc_state.spr[ref_spr] = ppc_state.gpr[reg_s];
|
||||
uint32_t val = ppc_state.gpr[reg_s];
|
||||
|
||||
if (ref_spr != SPR::PVR) { // prevent writes to the read-only PVR
|
||||
ppc_state.spr[ref_spr] = val;
|
||||
}
|
||||
|
||||
if (ref_spr == SPR::SDR1) {
|
||||
if (ref_spr == SPR::SDR1) { // adapt to SDR1 changes
|
||||
mmu_pat_ctx_changed();
|
||||
}
|
||||
|
||||
switch (ref_spr) {
|
||||
case 284:
|
||||
update_timebase(0xFFFFFFFF00000000ULL, ppc_state.gpr[reg_s]);
|
||||
case SPR::RTCL_S:
|
||||
rtc_lo = val & 0x3FFFFF80UL;
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
break;
|
||||
case 285:
|
||||
update_timebase(0x00000000FFFFFFFFULL, (uint64_t)(ppc_state.gpr[reg_s]) << 32);
|
||||
case SPR::RTCU_S:
|
||||
rtc_hi = val;
|
||||
tbr_wr_timestamp = get_virt_time_ns();
|
||||
break;
|
||||
case SPR::TBL_S:
|
||||
update_timebase(0xFFFFFFFF00000000ULL, val);
|
||||
break;
|
||||
case SPR::TBU_S:
|
||||
update_timebase(0x00000000FFFFFFFFULL, (uint64_t)(val) << 32);
|
||||
break;
|
||||
case 528:
|
||||
case 529:
|
||||
@@ -928,10 +968,10 @@ void dppc_interpreter::ppc_mftb() {
|
||||
uint64_t tbr_value = calc_tbr_value();
|
||||
|
||||
switch (ref_spr) {
|
||||
case 268:
|
||||
case SPR::TBL_U:
|
||||
ppc_state.gpr[reg_d] = tbr_value & 0xFFFFFFFFUL;
|
||||
break;
|
||||
case 269:
|
||||
case SPR::TBU_U:
|
||||
ppc_state.gpr[reg_d] = (tbr_value >> 32) & 0xFFFFFFFFUL;
|
||||
break;
|
||||
default:
|
||||
@@ -1167,7 +1207,7 @@ void dppc_interpreter::ppc_bclrl() {
|
||||
void dppc_interpreter::ppc_cmp() {
|
||||
#ifdef CHECK_INVALID
|
||||
if (ppc_cur_instruction & 0x200000) {
|
||||
LOG_F(WARNING, "Invalid CMP instruction form (L=1)!\n");
|
||||
LOG_F(WARNING, "Invalid CMP instruction form (L=1)!");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -1184,7 +1224,7 @@ void dppc_interpreter::ppc_cmp() {
|
||||
void dppc_interpreter::ppc_cmpi() {
|
||||
#ifdef CHECK_INVALID
|
||||
if (ppc_cur_instruction & 0x200000) {
|
||||
LOG_F(WARNING, "Invalid CMPI instruction form (L=1)!\n");
|
||||
LOG_F(WARNING, "Invalid CMPI instruction form (L=1)!");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -1201,7 +1241,7 @@ void dppc_interpreter::ppc_cmpi() {
|
||||
void dppc_interpreter::ppc_cmpl() {
|
||||
#ifdef CHECK_INVALID
|
||||
if (ppc_cur_instruction & 0x200000) {
|
||||
LOG_F(WARNING, "Invalid CMPL instruction form (L=1)!\n");
|
||||
LOG_F(WARNING, "Invalid CMPL instruction form (L=1)!");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -1218,7 +1258,7 @@ void dppc_interpreter::ppc_cmpl() {
|
||||
void dppc_interpreter::ppc_cmpli() {
|
||||
#ifdef CHECK_INVALID
|
||||
if (ppc_cur_instruction & 0x200000) {
|
||||
LOG_F(WARNING, "Invalid CMPLI instruction form (L=1)!\n");
|
||||
LOG_F(WARNING, "Invalid CMPLI instruction form (L=1)!");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -1236,9 +1276,11 @@ void dppc_interpreter::ppc_cmpli() {
|
||||
void dppc_interpreter::ppc_mcrf() {
|
||||
int crf_d = (ppc_cur_instruction >> 21) & 0x1C;
|
||||
int crf_s = (ppc_cur_instruction >> 16) & 0x1C;
|
||||
uint32_t grab_s = ppc_state.cr & (0xf0000000UL >> crf_s);
|
||||
|
||||
ppc_state.cr = ((ppc_state.cr & ~(0xf0000000UL >> crf_d)) | (grab_s >> crf_d));
|
||||
// extract and right justify source flags field
|
||||
uint32_t grab_s = (ppc_state.cr >> (28 - crf_s)) & 0xF;
|
||||
|
||||
ppc_state.cr = (ppc_state.cr & ~(0xf0000000UL >> crf_d)) | (grab_s << (28 - crf_d));
|
||||
}
|
||||
|
||||
void dppc_interpreter::ppc_crand() {
|
||||
@@ -1325,6 +1367,16 @@ void dppc_interpreter::ppc_rfi() {
|
||||
uint32_t new_srr1_val = (ppc_state.spr[SPR::SRR1] & 0x87C0FF73UL);
|
||||
uint32_t new_msr_val = (ppc_state.msr & ~(0x87C0FF73UL));
|
||||
ppc_state.msr = (new_msr_val | new_srr1_val) & 0xFFFBFFFFUL;
|
||||
|
||||
// generate External Interrupt Exception
|
||||
// if CPU interrupt line is still asserted
|
||||
if (ppc_state.msr & 0x8000 && int_pin) {
|
||||
uint32_t save_srr0 = ppc_state.spr[SPR::SRR0] & 0xFFFFFFFCUL;
|
||||
ppc_exception_handler(Except_Type::EXC_EXT_INT, 0);
|
||||
ppc_state.spr[SPR::SRR0] = save_srr0;
|
||||
return;
|
||||
}
|
||||
|
||||
ppc_next_instruction_address = ppc_state.spr[SPR::SRR0] & 0xFFFFFFFCUL;
|
||||
|
||||
do_ctx_sync(); // RFI is context synchronizing
|
||||
@@ -1949,7 +2001,6 @@ void dppc_interpreter::ppc_lswi() {
|
||||
ppc_effective_address = reg_a ? ppc_result_a : 0;
|
||||
grab_inb = (ppc_cur_instruction >> 11) & 0x1F;
|
||||
grab_inb = grab_inb ? grab_inb : 32;
|
||||
uint32_t stringed_word = 0;
|
||||
|
||||
while (grab_inb > 0) {
|
||||
switch (grab_inb) {
|
||||
@@ -1962,9 +2013,8 @@ void dppc_interpreter::ppc_lswi() {
|
||||
grab_inb = 0;
|
||||
break;
|
||||
case 3:
|
||||
stringed_word = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
|
||||
stringed_word += mmu_read_vmem<uint8_t>(ppc_effective_address + 2) << 8;
|
||||
ppc_state.gpr[reg_d] = stringed_word;
|
||||
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
|
||||
ppc_state.gpr[reg_d] += mmu_read_vmem<uint8_t>(ppc_effective_address + 2) << 8;
|
||||
grab_inb = 0;
|
||||
break;
|
||||
default:
|
||||
@@ -1992,7 +2042,6 @@ void dppc_interpreter::ppc_lswx() {
|
||||
|
||||
ppc_effective_address = reg_a ? (ppc_result_a + ppc_result_b) : ppc_result_b;
|
||||
grab_inb = ppc_state.spr[SPR::XER] & 0x7F;
|
||||
uint32_t stringed_word = 0;
|
||||
|
||||
while (grab_inb > 0) {
|
||||
switch (grab_inb) {
|
||||
@@ -2005,10 +2054,9 @@ void dppc_interpreter::ppc_lswx() {
|
||||
grab_inb = 0;
|
||||
break;
|
||||
case 3:
|
||||
stringed_word = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
|
||||
stringed_word += mmu_read_vmem<uint8_t>(ppc_effective_address + 2) << 8;
|
||||
ppc_state.gpr[reg_d] = stringed_word;
|
||||
grab_inb = 0;
|
||||
ppc_state.gpr[reg_d] = mmu_read_vmem<uint16_t>(ppc_effective_address) << 16;
|
||||
ppc_state.gpr[reg_d] += mmu_read_vmem<uint8_t>(ppc_effective_address + 2) << 8;
|
||||
grab_inb = 0;
|
||||
break;
|
||||
default:
|
||||
ppc_state.gpr[reg_d] = mmu_read_vmem<uint32_t>(ppc_effective_address);
|
||||
|
||||
+134
-5
@@ -19,20 +19,30 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcdisasm.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/ofnvram.h>
|
||||
#include "memaccess.h"
|
||||
#include <utils/profiler.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include "../cpu/ppc/ppcdisasm.h"
|
||||
#include "../cpu/ppc/ppcemu.h"
|
||||
#include "../cpu/ppc/ppcmmu.h"
|
||||
#include "memaccess.h"
|
||||
#include "utils/profiler.h"
|
||||
|
||||
#ifdef DEBUG_CPU_INT
|
||||
#include <machines/machinebase.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_68K_DEBUGGER // optionally defined in CMakeLists.txt
|
||||
#include <capstone/capstone.h>
|
||||
@@ -89,6 +99,8 @@ static void show_help() {
|
||||
cout << " X can be either 'ppc' (default) or '68k'" << endl;
|
||||
cout << " Use 68k for debugging emulated 68k code only." << endl;
|
||||
#endif
|
||||
cout << " printenv -- print current NVRAM settings." << endl;
|
||||
cout << " setenv V N -- set NVRAM variable V to value N." << endl;
|
||||
cout << " quit -- quit the debugger" << endl << endl;
|
||||
cout << "Pressing ENTER will repeat last command." << endl;
|
||||
}
|
||||
@@ -364,6 +376,32 @@ static void print_gprs() {
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static struct sigaction old_act_sigint, new_act_sigint;
|
||||
static struct sigaction old_act_sigterm, new_act_sigterm;
|
||||
static struct termios orig_termios;
|
||||
|
||||
static void mysig_handler(int signum)
|
||||
{
|
||||
// restore original terminal state
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios);
|
||||
|
||||
// restore original signal handler for SIGINT
|
||||
signal(SIGINT, old_act_sigint.sa_handler);
|
||||
signal(SIGTERM, old_act_sigterm.sa_handler);
|
||||
|
||||
LOG_F(INFO, "Old terminal state restored, SIG#=%d", signum);
|
||||
|
||||
// re-post signal
|
||||
raise(signum);
|
||||
}
|
||||
#endif
|
||||
|
||||
void enter_debugger() {
|
||||
string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str,
|
||||
inst_string, inst_num_str, profile_name, sub_cmd;
|
||||
@@ -372,6 +410,8 @@ void enter_debugger() {
|
||||
int log_level, context;
|
||||
size_t separator_pos;
|
||||
|
||||
unique_ptr<OfNvramUtils> ofnvram = unique_ptr<OfNvramUtils>(new OfNvramUtils);
|
||||
|
||||
context = 1; /* start with the PowerPC context */
|
||||
|
||||
cout << "Welcome to the DingusPPC command line debugger." << endl;
|
||||
@@ -489,6 +529,7 @@ void enter_debugger() {
|
||||
cout << exc.what() << endl;
|
||||
}
|
||||
} else if (cmd == "go") {
|
||||
power_on = true;
|
||||
ppc_exec(); // won't return!
|
||||
} else if (cmd == "disas" || cmd == "da") {
|
||||
expr_str = "";
|
||||
@@ -569,6 +610,94 @@ void enter_debugger() {
|
||||
} else {
|
||||
cout << "Unknown debugging context: " << expr_str << endl;
|
||||
}
|
||||
#endif
|
||||
} else if (cmd == "printenv") {
|
||||
if (ofnvram->init())
|
||||
continue;
|
||||
ofnvram->printenv();
|
||||
} else if (cmd == "setenv") {
|
||||
string var_name, value;
|
||||
ss >> var_name;
|
||||
ss >> value;
|
||||
if (ofnvram->init())
|
||||
continue;
|
||||
ofnvram->setenv(var_name, value);
|
||||
#ifndef _WIN32
|
||||
} else if (cmd == "nvedit") {
|
||||
cout << "===== press CNTRL-C to save =====" << endl;
|
||||
|
||||
// save original terminal state
|
||||
tcgetattr(STDIN_FILENO, &orig_termios);
|
||||
struct termios new_termios = orig_termios;
|
||||
|
||||
new_termios.c_cflag &= ~(CSIZE | PARENB);
|
||||
new_termios.c_cflag |= CS8;
|
||||
|
||||
new_termios.c_lflag &= ~(ISIG | NOFLSH | ICANON | ECHOCTL);
|
||||
new_termios.c_lflag |= NOFLSH | ECHONL;
|
||||
|
||||
// new_termios.c_iflag &= ~(ICRNL | IGNCR);
|
||||
// new_termios.c_iflag |= INLCR;
|
||||
|
||||
// new_termios.c_oflag &= ~(ONOCR | ONLCR);
|
||||
// new_termios.c_oflag |= OPOST | OCRNL | ONLRET;
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);
|
||||
|
||||
// save original signal handler for SIGINT
|
||||
// then redirect SIGINT to new handler
|
||||
memset(&new_act_sigint, 0, sizeof(new_act_sigint));
|
||||
new_act_sigint.sa_handler = mysig_handler;
|
||||
sigaction(SIGINT, &new_act_sigint, &old_act_sigint);
|
||||
|
||||
// save original signal handler for SIGTERM
|
||||
// then redirect SIGTERM to new handler
|
||||
memset(&new_act_sigterm, 0, sizeof(new_act_sigterm));
|
||||
new_act_sigterm.sa_handler = mysig_handler;
|
||||
sigaction(SIGTERM, &new_act_sigterm, &old_act_sigterm);
|
||||
|
||||
getline(cin, inp, '\x03');
|
||||
|
||||
// restore original terminal state
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios);
|
||||
|
||||
// restore original signal handler for SIGINT
|
||||
signal(SIGINT, old_act_sigint.sa_handler);
|
||||
|
||||
// restore original signal handler for SIGTERM
|
||||
signal(SIGTERM, old_act_sigterm.sa_handler);
|
||||
|
||||
if (ofnvram->init())
|
||||
continue;
|
||||
ofnvram->setenv("nvramrc", inp);
|
||||
#endif
|
||||
#ifdef DEBUG_CPU_INT
|
||||
} else if (cmd == "amicint") {
|
||||
string value;
|
||||
int irq_id;
|
||||
ss >> value;
|
||||
try {
|
||||
irq_id = str2num(value);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
InterruptCtrl* int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
int_ctrl->ack_int(irq_id, 1);
|
||||
} else if (cmd == "viaint") {
|
||||
string value;
|
||||
int irq_bit;
|
||||
ss >> value;
|
||||
try {
|
||||
irq_bit = str2num(value);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
continue;
|
||||
}
|
||||
ViaCuda* via_obj = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
ppc_state.pc -= 4;
|
||||
via_obj->assert_int(irq_bit);
|
||||
#endif
|
||||
} else {
|
||||
cout << "Unknown command: " << cmd << endl;
|
||||
|
||||
@@ -6,6 +6,7 @@ file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/adb/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/i2c/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/ata/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/pci/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/common/scsi/*.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/ethernet/*.cpp"
|
||||
|
||||
@@ -402,7 +402,7 @@ bool ADB_Bus::adb_keybd_listen(int reg) {
|
||||
}
|
||||
|
||||
bool ADB_Bus::adb_mouse_listen(int reg) {
|
||||
if ((reg != 0) | (reg != 3)) {
|
||||
if ((reg != 0) || (reg != 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Heathrow hard drive controller */
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtaBaseDevice::AtaBaseDevice(const std::string name)
|
||||
{
|
||||
this->set_name(name);
|
||||
supports_types(HWCompType::IDE_DEV);
|
||||
|
||||
device_reset();
|
||||
}
|
||||
|
||||
void AtaBaseDevice::device_reset(const uint8_t dev_head_val)
|
||||
{
|
||||
this->r_error = 1; // Device 0 passed, Device 1 passed or not present
|
||||
|
||||
this->r_sect_count = 1;
|
||||
this->r_sect_num = 1;
|
||||
this->r_dev_ctrl = 0;
|
||||
|
||||
// set protocol signature
|
||||
if (this->device_type == DEVICE_TYPE_ATAPI) {
|
||||
this->r_cylinder_lo = 0x14;
|
||||
this->r_cylinder_hi = 0xEB;
|
||||
this->r_dev_head = dev_head_val;
|
||||
} else { // assume ATA by default
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
this->r_dev_head = 0;
|
||||
this->r_status = DRDY | DSC;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
LOG_F(WARNING, "Retrieving data from %s", this->name.c_str());
|
||||
return 0xFFFFU;
|
||||
case ATA_Reg::ERROR:
|
||||
return this->r_error;
|
||||
case ATA_Reg::SEC_COUNT:
|
||||
return this->r_sect_count;
|
||||
case ATA_Reg::SEC_NUM:
|
||||
return this->r_sect_num;
|
||||
case ATA_Reg::CYL_LOW:
|
||||
return this->r_cylinder_lo;
|
||||
case ATA_Reg::CYL_HIGH:
|
||||
return this->r_cylinder_hi;
|
||||
case ATA_Reg::DEVICE_HEAD:
|
||||
return this->r_dev_head;
|
||||
case ATA_Reg::STATUS:
|
||||
// TODO: clear pending interrupt
|
||||
return this->r_status;
|
||||
case ATA_Reg::ALT_STATUS:
|
||||
return this->r_status;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to read unknown IDE register: %x", reg_addr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
|
||||
switch (reg_addr) {
|
||||
case ATA_Reg::DATA:
|
||||
LOG_F(WARNING, "Pushing data to %s", this->name.c_str());
|
||||
break;
|
||||
case ATA_Reg::FEATURES:
|
||||
this->r_features = value;
|
||||
break;
|
||||
case ATA_Reg::SEC_COUNT:
|
||||
this->r_sect_count = value;
|
||||
break;
|
||||
case ATA_Reg::SEC_NUM:
|
||||
this->r_sect_num = value;
|
||||
break;
|
||||
case ATA_Reg::CYL_LOW:
|
||||
this->r_cylinder_lo = value;
|
||||
break;
|
||||
case ATA_Reg::CYL_HIGH:
|
||||
this->r_cylinder_hi = value;
|
||||
break;
|
||||
case ATA_Reg::DEVICE_HEAD:
|
||||
this->r_dev_head = value;
|
||||
break;
|
||||
case ATA_Reg::COMMAND:
|
||||
this->r_command = value;
|
||||
if (is_selected() || this->r_command == DIAGNOSTICS) {
|
||||
perform_command();
|
||||
}
|
||||
break;
|
||||
case ATA_Reg::DEV_CTRL:
|
||||
if (!(this->r_dev_ctrl & SRST) && (value & SRST)) {
|
||||
LOG_F(INFO, "%s: soft reset triggered", this->name.c_str());
|
||||
this->r_status |= BSY;
|
||||
}
|
||||
this->r_dev_ctrl = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Attempted to write unknown IDE register: %x", reg_addr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Base class for ATA devices. */
|
||||
|
||||
#ifndef ATA_BASE_DEVICE_H
|
||||
#define ATA_BASE_DEVICE_H
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
class AtaBaseDevice : public HWComponent, public AtaInterface
|
||||
{
|
||||
public:
|
||||
AtaBaseDevice(const std::string name);
|
||||
~AtaBaseDevice() = default;
|
||||
|
||||
uint16_t read(const uint8_t reg_addr);
|
||||
void write(const uint8_t reg_addr, const uint16_t value);
|
||||
|
||||
virtual int perform_command() = 0;
|
||||
|
||||
int get_device_id() { return this->my_dev_id; };
|
||||
|
||||
void device_reset(const uint8_t dev_head_val = 0);
|
||||
|
||||
private:
|
||||
bool is_selected() { return ((this->r_dev_head >> 4) & 1) == this->my_dev_id; };
|
||||
|
||||
protected:
|
||||
uint8_t my_dev_id = 0; // my IDE device ID configured by the host
|
||||
uint8_t device_type = ata_interface::DEVICE_TYPE_UNKNOWN;
|
||||
|
||||
// IDE aka task file registers
|
||||
uint8_t r_error;
|
||||
uint8_t r_features;
|
||||
uint8_t r_sect_count;
|
||||
uint8_t r_sect_num;
|
||||
uint8_t r_cylinder_lo;
|
||||
uint8_t r_cylinder_hi;
|
||||
uint8_t r_dev_head;
|
||||
uint8_t r_command;
|
||||
uint8_t r_status;
|
||||
uint8_t r_dev_ctrl;
|
||||
};
|
||||
|
||||
#endif // ATA_BASE_DEVICE_H
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 ATA interface definitions. */
|
||||
|
||||
#ifndef ATA_INTERFACE_H
|
||||
#define ATA_INTERFACE_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
namespace ata_interface {
|
||||
|
||||
/** Device IDs according with the Apple ATA zero/one specification. */
|
||||
enum {
|
||||
DEVICE_ID_INVALID = -1,
|
||||
DEVICE_ID_ZERO = 0,
|
||||
DEVICE_ID_ONE = 1
|
||||
};
|
||||
|
||||
/** Device types. */
|
||||
enum {
|
||||
DEVICE_TYPE_UNKNOWN = -1,
|
||||
DEVICE_TYPE_ATA = 0,
|
||||
DEVICE_TYPE_ATAPI = 1,
|
||||
};
|
||||
|
||||
/** ATA register offsets. */
|
||||
enum ATA_Reg : int {
|
||||
DATA = 0x0,
|
||||
ERROR = 0x1, // error (read)
|
||||
FEATURES = 0x1, // features (write)
|
||||
SEC_COUNT = 0x2, // sector count
|
||||
SEC_NUM = 0x3, // sector number
|
||||
CYL_LOW = 0x4, // cylinder low
|
||||
CYL_HIGH = 0x5, // cylinder high
|
||||
DEVICE_HEAD = 0x6, // device/head
|
||||
STATUS = 0x7, // status (read)
|
||||
COMMAND = 0x7, // command (write)
|
||||
ALT_STATUS = 0x16, // alt status (read)
|
||||
DEV_CTRL = 0x16, // device control (write)
|
||||
TIME_CONFIG = 0x20 // Apple ASIC specific timing configuration
|
||||
};
|
||||
|
||||
/** Status register bits. */
|
||||
enum ATA_Status : int {
|
||||
ERR = 0x1,
|
||||
IDX = 0x2,
|
||||
CORR = 0x4,
|
||||
DRQ = 0x8,
|
||||
DSC = 0x10,
|
||||
DWF = 0x20,
|
||||
DRDY = 0x40,
|
||||
BSY = 0x80
|
||||
};
|
||||
|
||||
/** Error register bits. */
|
||||
enum ATA_Error : int {
|
||||
ANMF = 0x1, //no address mark
|
||||
TK0NF = 0x2, //track 0 not found
|
||||
ABRT = 0x4, //abort command
|
||||
MCR = 0x8,
|
||||
IDNF = 0x10, //id mark not found
|
||||
MC = 0x20, //media change request
|
||||
UNC = 0x40,
|
||||
BBK = 0x80 //bad block
|
||||
};
|
||||
|
||||
/** Bit definition for the device control register. */
|
||||
enum ATA_CTRL : int{
|
||||
IEN = 0x2,
|
||||
SRST = 0x4,
|
||||
HOB = 0x80,
|
||||
};
|
||||
|
||||
/* ATA commands. */
|
||||
enum ATA_Cmd : int {
|
||||
NOP = 0x00,
|
||||
RESET_ATAPI = 0x08,
|
||||
RECALIBRATE = 0x10,
|
||||
READ_SECTOR = 0x20,
|
||||
READ_SECTOR_NR = 0x21,
|
||||
READ_LONG = 0x22,
|
||||
READ_SECTOR_EXT = 0x24,
|
||||
WRITE_SECTOR = 0x30,
|
||||
WRITE_SECTOR_NR = 0x31,
|
||||
WRITE_LONG = 0x32,
|
||||
READ_VERIFY = 0x40,
|
||||
FORMAT_TRACKS = 0x50,
|
||||
IDE_SEEK = 0x70,
|
||||
DIAGNOSTICS = 0x90,
|
||||
INIT_DEV_PARAM = 0x91,
|
||||
PACKET = 0xA0,
|
||||
IDFY_PKT_DEV = 0xA1,
|
||||
READ_MULTIPLE = 0xC4,
|
||||
WRITE_MULTIPLE = 0xC5,
|
||||
READ_DMA = 0xC8,
|
||||
WRITE_DMA = 0xCA,
|
||||
WRITE_BUFFER_DMA = 0xE9,
|
||||
READ_BUFFER_DMA = 0xEB,
|
||||
IDENTIFY_DEVICE = 0xEC,
|
||||
};
|
||||
|
||||
}; // namespace ata_interface
|
||||
|
||||
/** Interface for ATA devices. */
|
||||
class AtaInterface {
|
||||
public:
|
||||
AtaInterface() = default;
|
||||
virtual ~AtaInterface() = default;
|
||||
virtual uint16_t read(const uint8_t reg_addr) = 0;
|
||||
virtual void write(const uint8_t reg_addr, const uint16_t val) = 0;
|
||||
|
||||
virtual int get_device_id() = 0;
|
||||
};
|
||||
|
||||
/** Dummy ATA device. */
|
||||
class AtaNullDevice : public AtaInterface {
|
||||
public:
|
||||
AtaNullDevice() = default;
|
||||
~AtaNullDevice() = default;
|
||||
|
||||
uint16_t read(const uint8_t reg_addr) {
|
||||
// return all one's except DD7 if no device is present
|
||||
// DD7 corresponds to the BSY bit of the status register
|
||||
// The host should have a pull-down resistor on DD7
|
||||
// to prevent the software from waiting for a long time
|
||||
// for empty slots
|
||||
return 0xFF7FU;
|
||||
};
|
||||
|
||||
void write(const uint8_t reg_addr, const uint16_t val) {};
|
||||
|
||||
// invalid device ID means no real device is present
|
||||
int get_device_id() { return ata_interface::DEVICE_ID_INVALID; };
|
||||
};
|
||||
|
||||
#endif // ATA_INTERFACE_H
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 ATA hard disk emulation. */
|
||||
|
||||
#include <devices/common/ata/atahd.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <sys/stat.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <loguru.hpp>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
AtaHardDisk::AtaHardDisk() : AtaBaseDevice("ATA-HD")
|
||||
{
|
||||
}
|
||||
|
||||
void AtaHardDisk::insert_image(std::string filename) {
|
||||
this->hdd_img.open(filename, std::fstream::out | std::fstream::in | std::fstream::binary);
|
||||
|
||||
struct stat stat_buf;
|
||||
int rc = stat(filename.c_str(), &stat_buf);
|
||||
if (!rc) {
|
||||
this->img_size = stat_buf.st_size;
|
||||
} else {
|
||||
ABORT_F("AtaHardDisk: could not determine file size using stat()");
|
||||
}
|
||||
this->hdd_img.seekg(0, std::ios_base::beg);
|
||||
}
|
||||
|
||||
int AtaHardDisk::perform_command()
|
||||
{
|
||||
LOG_F(INFO, "%s: command 0x%x requested", this->name.c_str(), this->r_command);
|
||||
this->r_status |= BSY;
|
||||
this->r_status &= ~(DRDY);
|
||||
switch (this->r_command) {
|
||||
case NOP:
|
||||
break;
|
||||
case RESET_ATAPI: {
|
||||
device_reset();
|
||||
break;
|
||||
}
|
||||
case RECALIBRATE:
|
||||
hdd_img.seekg(0, std::ios::beg);
|
||||
this->r_error = 0;
|
||||
this->r_cylinder_lo = 0;
|
||||
this->r_cylinder_hi = 0;
|
||||
break;
|
||||
case READ_SECTOR:
|
||||
case READ_SECTOR_NR: {
|
||||
this->r_status |= DRQ;
|
||||
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
|
||||
uint32_t sector = (r_sect_num << 16);
|
||||
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
|
||||
uint64_t offset = sector * 512;
|
||||
hdd_img.seekg(offset, std::ios::beg);
|
||||
hdd_img.read(buffer, sec_count * 512);
|
||||
this->r_status &= ~(DRQ);
|
||||
break;
|
||||
}
|
||||
case WRITE_SECTOR:
|
||||
case WRITE_SECTOR_NR: {
|
||||
this->r_status |= DRQ;
|
||||
uint16_t sec_count = (this->r_sect_count == 0) ? 256 : this->r_sect_count;
|
||||
uint32_t sector = (r_sect_num << 16);
|
||||
sector |= ((this->r_cylinder_lo) << 8) + (this->r_cylinder_hi);
|
||||
uint64_t offset = sector * 512;
|
||||
hdd_img.seekg(offset, std::ios::beg);
|
||||
hdd_img.write(buffer, sec_count * 512);
|
||||
this->r_status &= ~(DRQ);
|
||||
break;
|
||||
}
|
||||
case INIT_DEV_PARAM:
|
||||
break;
|
||||
case DIAGNOSTICS: {
|
||||
this->r_status |= DRQ;
|
||||
int ret_code = this->r_error;
|
||||
this->r_status &= ~(DRQ);
|
||||
return ret_code;
|
||||
break;
|
||||
}
|
||||
case IDENTIFY_DEVICE: {
|
||||
this->r_status |= DRQ;
|
||||
std::memcpy(buffer, ide_hd_id, 512);
|
||||
this->r_status &= ~(DRQ);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_F(INFO, "Unknown ATA command 0x%x", this->r_command);
|
||||
this->r_status &= ~(BSY);
|
||||
this->r_status |= ERR;
|
||||
return -1;
|
||||
}
|
||||
this->r_status &= ~(BSY);
|
||||
this->r_status |= DRDY;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 TA hard disk definitions. */
|
||||
|
||||
#ifndef ATA_HARD_DISK_H
|
||||
#define ATA_HARD_DISK_H
|
||||
|
||||
#include <devices/common/ata/atabasedevice.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
class AtaHardDisk : public AtaBaseDevice
|
||||
{
|
||||
public:
|
||||
AtaHardDisk();
|
||||
~AtaHardDisk() = default;
|
||||
|
||||
void insert_image(std::string filename);
|
||||
int perform_command();
|
||||
|
||||
private:
|
||||
std::fstream hdd_img;
|
||||
uint64_t img_size;
|
||||
char * buffer = new char[1 <<17];
|
||||
|
||||
char* ide_hd_id = {
|
||||
0x0
|
||||
};
|
||||
};
|
||||
|
||||
#endif // ATA_HARD_DISK_H
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** 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
|
||||
from and to the host.
|
||||
*/
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using namespace ata_interface;
|
||||
|
||||
IdeChannel::IdeChannel(const std::string name)
|
||||
{
|
||||
this->set_name(name);
|
||||
this->supports_types(HWCompType::IDE_BUS);
|
||||
|
||||
this->devices[0] = std::unique_ptr<AtaNullDevice>(new AtaNullDevice());
|
||||
this->devices[1] = std::unique_ptr<AtaNullDevice>(new AtaNullDevice());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// redirect register writes to both devices
|
||||
for (auto& dev : this->devices) {
|
||||
dev->write(reg_addr, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Ide0_Descriptor = {
|
||||
IdeChannel::create_first, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Ide1_Descriptor = {
|
||||
IdeChannel::create_second, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Ide0, Ide0_Descriptor);
|
||||
REGISTER_DEVICE(Ide1, Ide1_Descriptor);
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 IDE Channel (aka IDE port) definitions. */
|
||||
|
||||
#ifndef IDE_CHANNEL_H
|
||||
#define IDE_CHANNEL_H
|
||||
|
||||
#include <devices/common/ata/atadefs.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class IdeChannel : public HWComponent
|
||||
{
|
||||
public:
|
||||
IdeChannel(const std::string name);
|
||||
~IdeChannel() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDEO"));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_second() {
|
||||
return std::unique_ptr<IdeChannel>(new IdeChannel("IDE1"));
|
||||
}
|
||||
|
||||
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:
|
||||
int cur_dev = 0;
|
||||
uint32_t ch_config = 0; // timing configuration for this channel
|
||||
|
||||
std::unique_ptr<AtaInterface> devices[2];
|
||||
};
|
||||
|
||||
#endif // IDE_CHANNEL_H
|
||||
@@ -29,6 +29,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
enum HWCompType {
|
||||
UNKNOWN = 0ULL, /* unknown component type */
|
||||
MEM_CTRL = 1ULL << 0, /* memory controller */
|
||||
NVRAM = 1ULL << 1, /* non-volatile random access memory */
|
||||
ROM = 1ULL << 2, /* read-only memory */
|
||||
RAM = 1ULL << 3, /* random access memory */
|
||||
MMIO_DEV = 1ULL << 4, /* memory mapped I/O device */
|
||||
@@ -42,6 +43,8 @@ enum HWCompType {
|
||||
SCSI_BUS = 1ULL << 20, /* SCSI bus */
|
||||
SCSI_HOST = 1ULL << 21, /* SCSI host adapter */
|
||||
SCSI_DEV = 1ULL << 22, /* SCSI device */
|
||||
IDE_BUS = 1ULL << 23, /* IDE bus */
|
||||
IDE_DEV = 1ULL << 25, /* IDE device */
|
||||
SND_SERVER = 1ULL << 31, /* host sound server */
|
||||
FLOPPY_CTRL = 1ULL << 32, /* floppy disk controller */
|
||||
FLOPPY_DRV = 1ULL << 33, /* floppy disk drive */
|
||||
|
||||
@@ -24,6 +24,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
//#define DEBUG_CPU_INT // uncomment this to enable hacks for debugging HW interrupts
|
||||
|
||||
/** Enumerator for various interrupt sources. */
|
||||
enum IntSrc : int {
|
||||
VIA_CUDA = 1,
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Athens clock generator emulation. */
|
||||
|
||||
/**
|
||||
Athens (Apple part# 343S1191) is a programmable clock generator ASIC
|
||||
used in the PCI Power Macintosh computers.
|
||||
It has two outputs: system clock and video aka dot clock. Both can be
|
||||
programmed using HW jumpers or I2C interface.
|
||||
This high-level emulator focuses on the Athen's I2C interface providing
|
||||
methods for querying the resulting virtual frequences.
|
||||
This is helpful especially for calculating video parameters.
|
||||
*/
|
||||
|
||||
#include <devices/common/i2c/athens.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
|
||||
AthensClocks::AthensClocks(uint8_t dev_addr)
|
||||
{
|
||||
supports_types(HWCompType::I2C_DEV);
|
||||
|
||||
this->my_addr = dev_addr;
|
||||
|
||||
// set up power on values
|
||||
this->regs[AthensRegs::P2_MUX2] = 0x62;
|
||||
}
|
||||
|
||||
void AthensClocks::start_transaction()
|
||||
{
|
||||
this->pos = 0; // reset read/write position
|
||||
}
|
||||
|
||||
bool AthensClocks::send_subaddress(uint8_t sub_addr)
|
||||
{
|
||||
LOG_F(INFO, "Athens: subaddress set to 0x%X", sub_addr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AthensClocks::send_byte(uint8_t data)
|
||||
{
|
||||
switch (this->pos) {
|
||||
case 0:
|
||||
this->reg_num = data;
|
||||
this->pos++;
|
||||
break;
|
||||
case 1:
|
||||
if (this->reg_num >= ATHENS_NUM_REGS) {
|
||||
LOG_F(WARNING, "Athens: invalid register number %d", this->reg_num);
|
||||
return false; // return NACK
|
||||
}
|
||||
this->regs[this->reg_num] = data;
|
||||
if (reg_num == 3) {
|
||||
LOG_F(INFO, "Athens: dot clock frequency set to %d Hz", get_dot_freq());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Athens: too much data received!");
|
||||
return false; // return NACK
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AthensClocks::receive_byte(uint8_t* p_data)
|
||||
{
|
||||
*p_data = 0x41; // return my ID (value has been guessed)
|
||||
return true;
|
||||
}
|
||||
|
||||
int AthensClocks::get_sys_freq()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AthensClocks::get_dot_freq()
|
||||
{
|
||||
static std::vector<int> D2_commons = {7, 11, 13, 14, 15, 17, 23, 31};
|
||||
static std::vector<int> N2_commons = {
|
||||
22, 27, 28, 31, 35, 37, 38, 42, 49, 55, 56, 78, 125
|
||||
};
|
||||
|
||||
if (this->regs[AthensRegs::P2_MUX2] & 0xC0) {
|
||||
LOG_F(INFO, "Athens: dot clock disabled");
|
||||
return 0;
|
||||
}
|
||||
|
||||
float out_freq = 0.0f;
|
||||
|
||||
int d2 = this->regs[AthensRegs::D2];
|
||||
int n2 = this->regs[AthensRegs::N2];
|
||||
|
||||
int post_div = 1 << (3 - (this->regs[AthensRegs::P2_MUX2] & 3));
|
||||
|
||||
if (std::find(D2_commons.begin(), D2_commons.end(), d2) == D2_commons.end()) {
|
||||
LOG_F(WARNING, "Athens: untested D2 value %d", d2);
|
||||
}
|
||||
|
||||
if (std::find(N2_commons.begin(), N2_commons.end(), n2) == N2_commons.end()) {
|
||||
LOG_F(WARNING, "Athens: untested N2 value %d", d2);
|
||||
}
|
||||
|
||||
int mux = (this->regs[AthensRegs::P2_MUX2] >> 4) & 3;
|
||||
|
||||
switch (mux) {
|
||||
case 0: // clock source -> dot cock VCO
|
||||
out_freq = ATHENS_XTAL * ((float)n2 / (float)(d2 * post_div));
|
||||
break;
|
||||
case 1: // clock source -> system clock VCO
|
||||
LOG_F(WARNING, "Athens: system clock VCO not supported yet!");
|
||||
break;
|
||||
case 2: // clock source -> crystal frequency
|
||||
out_freq = ATHENS_XTAL / post_div;
|
||||
break;
|
||||
case 3:
|
||||
LOG_F(WARNING, "Athens: attempt to use reserved Mux value!");
|
||||
break;
|
||||
}
|
||||
|
||||
return static_cast<int>(out_freq + 0.5f);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Athens clock generator definitions. */
|
||||
|
||||
#ifndef ATHENS_H
|
||||
#define ATHENS_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#define ATHENS_NUM_REGS 8
|
||||
|
||||
constexpr auto ATHENS_XTAL = 31334400.0f; // external crystal oscillator frequency
|
||||
|
||||
namespace AthensRegs {
|
||||
|
||||
enum AthensRegs: uint8_t {
|
||||
ID = 0,
|
||||
D2 = 1,
|
||||
N2 = 2,
|
||||
P2_MUX2 = 3,
|
||||
VN_CTRL = 4, // vendor specific control bits
|
||||
BD1 = 5,
|
||||
BN1 = 6,
|
||||
P1 = 7
|
||||
};
|
||||
|
||||
}; // namespace AthensRegs
|
||||
|
||||
class AthensClocks : public I2CDevice, public HWComponent
|
||||
{
|
||||
public:
|
||||
AthensClocks(uint8_t dev_addr);
|
||||
~AthensClocks() = default;
|
||||
|
||||
// I2CDevice methods
|
||||
void start_transaction();
|
||||
bool send_subaddress(uint8_t sub_addr);
|
||||
bool send_byte(uint8_t data);
|
||||
bool receive_byte(uint8_t* p_data);
|
||||
|
||||
// methods for querying virtual frequences
|
||||
int get_sys_freq();
|
||||
int get_dot_freq();
|
||||
|
||||
private:
|
||||
uint8_t my_addr = 0;
|
||||
uint8_t reg_num = 0;
|
||||
int pos = 0;
|
||||
|
||||
uint8_t regs[ATHENS_NUM_REGS];
|
||||
};
|
||||
|
||||
#endif // ATHENS_H
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Generic PROM device programmable over I2C. */
|
||||
|
||||
#include <devices/common/i2c/i2cprom.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
I2CProm::I2CProm(uint8_t dev_addr, int size)
|
||||
{
|
||||
supports_types(HWCompType::I2C_DEV);
|
||||
|
||||
this->my_addr = dev_addr;
|
||||
this->rom_size = size;
|
||||
|
||||
// allocate storage for ROM data
|
||||
this->data = std::unique_ptr<uint8_t[]> (new uint8_t[this->rom_size]);
|
||||
}
|
||||
|
||||
void I2CProm::fill_memory(int start, int size, uint8_t c)
|
||||
{
|
||||
if ((start + size) <= this->rom_size) {
|
||||
std::memset(&this->data[start], c, size);
|
||||
}
|
||||
}
|
||||
|
||||
void I2CProm::set_memory(int start, const uint8_t* in_data, int size)
|
||||
{
|
||||
if ((start + size) <= this->rom_size) {
|
||||
std::memcpy(&this->data[start], in_data, size);
|
||||
}
|
||||
}
|
||||
|
||||
void I2CProm::start_transaction() {
|
||||
this->pos = 0;
|
||||
};
|
||||
|
||||
bool I2CProm::send_subaddress(uint8_t sub_addr) {
|
||||
this->pos = sub_addr;
|
||||
return true;
|
||||
};
|
||||
|
||||
bool I2CProm::send_byte(uint8_t data) {
|
||||
LOG_F(9, "I2CRom: 0x%X received", data);
|
||||
return true;
|
||||
};
|
||||
|
||||
bool I2CProm::receive_byte(uint8_t* p_data) {
|
||||
if (this->pos >= this->rom_size) {
|
||||
this->pos = 0; // attempt to read past last byte should wrap around
|
||||
}
|
||||
*p_data = this->data[this->pos++];
|
||||
return true;
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Generic PROM device programmable over I2C. */
|
||||
|
||||
#ifndef I2C_PROM_H
|
||||
#define I2C_PROM_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class I2CProm : public I2CDevice, public HWComponent
|
||||
{
|
||||
public:
|
||||
I2CProm(uint8_t dev_addr, int size);
|
||||
~I2CProm() = default;
|
||||
|
||||
// I2CDevice methods
|
||||
void start_transaction();
|
||||
bool send_subaddress(uint8_t sub_addr);
|
||||
bool send_byte(uint8_t data);
|
||||
bool receive_byte(uint8_t* p_data);
|
||||
|
||||
// data management methods
|
||||
void fill_memory(int start, int size, uint8_t c);
|
||||
void set_memory(int start, const uint8_t* in_data, int size);
|
||||
|
||||
private:
|
||||
std::unique_ptr<uint8_t[]> data;
|
||||
|
||||
int rom_size = 0;
|
||||
int pos = 0;
|
||||
uint8_t my_addr = 0xA0;
|
||||
};
|
||||
|
||||
#endif // I2C_PROM_H
|
||||
@@ -55,12 +55,12 @@ public:
|
||||
};
|
||||
~NubusMacID() = default;
|
||||
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
return (offset < 4 ? this->id[offset] : 0);
|
||||
};
|
||||
|
||||
/* not writable */
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {};
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
|
||||
|
||||
private:
|
||||
uint8_t id[4];
|
||||
@@ -70,8 +70,7 @@ private:
|
||||
The machine ID for the Gossamer board is accesible at 0xFF000004 (phys).
|
||||
It contains a 16-bit value revealing machine's capabilities like bus speed,
|
||||
ROM speed, I/O configuration etc.
|
||||
Because the meaning of these bits is poorly documented, the code below
|
||||
simply return a raw value obtained from real hardware.
|
||||
See machines/machinegossamer.cpp for further details.
|
||||
*/
|
||||
class GossamerID : public MMIODevice {
|
||||
public:
|
||||
@@ -81,12 +80,12 @@ public:
|
||||
};
|
||||
~GossamerID() = default;
|
||||
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
return ((!offset && size == 2) ? this->id : 0);
|
||||
};
|
||||
|
||||
/* not writable */
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {};
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {};
|
||||
|
||||
private:
|
||||
uint16_t id;
|
||||
|
||||
@@ -31,8 +31,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
class MMIODevice : public HWComponent {
|
||||
public:
|
||||
MMIODevice() = default;
|
||||
virtual uint32_t read(uint32_t reg_start, uint32_t offset, int size) = 0;
|
||||
virtual void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) = 0;
|
||||
virtual uint32_t read(uint32_t rgn_start, uint32_t offset, int size) = 0;
|
||||
virtual void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) = 0;
|
||||
virtual ~MMIODevice() = default;
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,9 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/nvram.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
@@ -35,7 +37,12 @@ using namespace std;
|
||||
/** the signature for NVRAM backing file identification. */
|
||||
static char NVRAM_FILE_ID[] = "DINGUSPPCNVRAM";
|
||||
|
||||
NVram::NVram(std::string file_name, uint32_t ram_size) {
|
||||
NVram::NVram(std::string file_name, uint32_t ram_size)
|
||||
{
|
||||
this->name = "NVRAM";
|
||||
|
||||
supports_types(HWCompType::NVRAM);
|
||||
|
||||
this->file_name = file_name;
|
||||
this->ram_size = ram_size;
|
||||
|
||||
@@ -68,8 +75,8 @@ void NVram::init() {
|
||||
!f.read((char*)&data_size, sizeof(data_size)) ||
|
||||
memcmp(sig, NVRAM_FILE_ID, sizeof(NVRAM_FILE_ID)) || data_size != this->ram_size ||
|
||||
!f.read((char*)this->storage, this->ram_size)) {
|
||||
LOG_F(WARNING, "Could not restore NVRAM content from the given file. \n");
|
||||
memset(this->storage, 0, sizeof(this->ram_size));
|
||||
LOG_F(WARNING, "Could not restore NVRAM content from the given file.");
|
||||
memset(this->storage, 0, this->ram_size);
|
||||
}
|
||||
|
||||
f.close();
|
||||
@@ -87,3 +94,9 @@ void NVram::save() {
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
static const DeviceDescription Nvram_Descriptor = {
|
||||
NVram::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(NVRAM, Nvram_Descriptor);
|
||||
+11
-4
@@ -22,7 +22,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef NVRAM_H
|
||||
#define NVRAM_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** @file Non-volatile RAM emulation.
|
||||
@@ -31,18 +34,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
automatically saved to and restored from the dedicated file.
|
||||
*/
|
||||
|
||||
class NVram {
|
||||
class NVram : public HWComponent {
|
||||
public:
|
||||
NVram(std::string file_name = "nvram.bin", uint32_t ram_size = 8192);
|
||||
~NVram();
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<NVram>(new NVram());
|
||||
}
|
||||
|
||||
uint8_t read_byte(uint32_t offset);
|
||||
void write_byte(uint32_t offset, uint8_t value);
|
||||
|
||||
private:
|
||||
std::string file_name; /* file name for the backing file. */
|
||||
uint16_t ram_size; /* NVRAM size. */
|
||||
uint8_t* storage;
|
||||
std::string file_name; // file name for the backing file
|
||||
uint16_t ram_size; // NVRAM size
|
||||
uint8_t* storage;
|
||||
|
||||
void init();
|
||||
void save();
|
||||
|
||||
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Utilities for working with the Apple Open Firmware NVRAM partition. */
|
||||
|
||||
#include <devices/common/ofnvram.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static uint32_t str2env(string& num_str) {
|
||||
try {
|
||||
return stoul(num_str, NULL, 0);
|
||||
} catch (invalid_argument& exc) {
|
||||
try {
|
||||
string num_str2 = string("0x") + num_str;
|
||||
return std::stoul(num_str2, NULL, 0);
|
||||
} catch (invalid_argument& exc) {
|
||||
throw invalid_argument(string("Cannot convert ") + num_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int OfNvramUtils::init()
|
||||
{
|
||||
this->nvram_obj = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
|
||||
return this->nvram_obj == nullptr;
|
||||
}
|
||||
|
||||
bool OfNvramUtils::validate()
|
||||
{
|
||||
int i;
|
||||
OfNvramHdr hdr;
|
||||
|
||||
if (this->nvram_obj == nullptr)
|
||||
return false;
|
||||
|
||||
// read OF partition header
|
||||
for (i = 0; i < sizeof(OfNvramHdr); i++) {
|
||||
((uint8_t*)&hdr)[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
|
||||
}
|
||||
|
||||
// validate partition signature and version
|
||||
if (BYTESWAP_16(hdr.sig) != OF_NVRAM_SIG || hdr.version != 5)
|
||||
return false;
|
||||
|
||||
this->size = hdr.num_pages * 256;
|
||||
|
||||
if (this->size != 0x800)
|
||||
return false;
|
||||
|
||||
// read the entire partition into the local buffer
|
||||
for (i = 0; i < this->size; i++) {
|
||||
this->buf[i] = this->nvram_obj->read_byte(OF_NVRAM_OFFSET + i);
|
||||
}
|
||||
|
||||
// verify partition checksum
|
||||
if (this->checksum_partition() ^ 0xFFFFU)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t OfNvramUtils::checksum_partition()
|
||||
{
|
||||
uint32_t acc = 0;
|
||||
|
||||
for (int i = 0; i < this->size; i += 2) {
|
||||
acc += READ_WORD_BE_A(&this->buf[i]);
|
||||
}
|
||||
|
||||
return acc + (acc >> 16);
|
||||
}
|
||||
|
||||
void OfNvramUtils::update_partition()
|
||||
{
|
||||
// set checksum in the header to zero
|
||||
this->buf[4] = 0;
|
||||
this->buf[5] = 0;
|
||||
|
||||
// calculate new checksum
|
||||
uint16_t checksum = this->checksum_partition();
|
||||
checksum = checksum ? ~checksum : 0xFFFFU;
|
||||
|
||||
// stuff it into the header
|
||||
WRITE_WORD_BE_A(&this->buf[4], checksum);
|
||||
|
||||
// write the entire partition back to NVRAM
|
||||
for (int i = 0; i < this->size; i++) {
|
||||
this->nvram_obj->write_byte(OF_NVRAM_OFFSET + i, this->buf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static const string flag_names[8] = {
|
||||
"little-endian?",
|
||||
"real-mode?",
|
||||
"auto-boot?",
|
||||
"diag-switch?",
|
||||
"fcode-debug?",
|
||||
"oem-banner?",
|
||||
"oem-logo?",
|
||||
"use-nvramrc?"
|
||||
};
|
||||
|
||||
static const map<string, std::tuple<int, uint16_t>> of_vars = {
|
||||
// name, type, offset
|
||||
{"real-base", {OF_VAR_TYPE_INT, 0x10}},
|
||||
{"real-size", {OF_VAR_TYPE_INT, 0x14}},
|
||||
{"virt-base", {OF_VAR_TYPE_INT, 0x18}},
|
||||
{"virt-size", {OF_VAR_TYPE_INT, 0x1C}},
|
||||
{"load-base", {OF_VAR_TYPE_INT, 0x20}},
|
||||
{"pci-probe-list", {OF_VAR_TYPE_INT, 0x24}},
|
||||
{"screen-#columns", {OF_VAR_TYPE_INT, 0x28}},
|
||||
{"screen-#rows", {OF_VAR_TYPE_INT, 0x2C}},
|
||||
{"selftest-#megs", {OF_VAR_TYPE_INT, 0x30}},
|
||||
{"boot-device", {OF_VAR_TYPE_STR, 0x34}},
|
||||
{"boot-file", {OF_VAR_TYPE_STR, 0x38}},
|
||||
{"diag-device", {OF_VAR_TYPE_STR, 0x3C}},
|
||||
{"diag-file", {OF_VAR_TYPE_STR, 0x40}},
|
||||
{"input-device", {OF_VAR_TYPE_STR, 0x44}},
|
||||
{"output-device", {OF_VAR_TYPE_STR, 0x48}},
|
||||
{"oem-banner", {OF_VAR_TYPE_STR, 0x4C}},
|
||||
{"oem-logo", {OF_VAR_TYPE_STR, 0x50}},
|
||||
{"nvramrc", {OF_VAR_TYPE_STR, 0x54}},
|
||||
{"boot-command", {OF_VAR_TYPE_STR, 0x58}},
|
||||
};
|
||||
|
||||
void OfNvramUtils::printenv()
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!this->validate()) {
|
||||
cout << "Invalid Open Firmware partition content!" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t of_flags = this->buf[12];
|
||||
|
||||
cout << endl;
|
||||
|
||||
// print flags
|
||||
for (i = 0; i < 8; i++) {
|
||||
cout << setw(20) << left << flag_names[i] <<
|
||||
(((of_flags << i) & 0x80) ? "true" : "false") << endl;
|
||||
}
|
||||
|
||||
// print the remaining variables
|
||||
for (auto& var : of_vars) {
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
|
||||
cout << setw(20) << left << var.first;
|
||||
|
||||
switch (type) {
|
||||
case OF_VAR_TYPE_INT:
|
||||
cout << hex << READ_DWORD_BE_A(&this->buf[offset]) << endl;
|
||||
break;
|
||||
case OF_VAR_TYPE_STR:
|
||||
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]) - OF_NVRAM_OFFSET;
|
||||
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
|
||||
for (i = 0; i < str_len; i++) {
|
||||
char ch = *(char *)&(this->buf[str_offset + i]);
|
||||
if (ch == '\x0D') cout << endl; else cout << ch;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void OfNvramUtils::setenv(string var_name, string value)
|
||||
{
|
||||
int i, flag;
|
||||
|
||||
if (!this->validate()) {
|
||||
cout << "Invalid Open Firmware partition content!" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// check if the user tries to change a flag
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (var_name == flag_names[i]) {
|
||||
if (value == "true")
|
||||
flag = 1;
|
||||
else if (value == "false")
|
||||
flag = 0;
|
||||
else {
|
||||
cout << "Invalid property value: " << value << endl;
|
||||
return;
|
||||
}
|
||||
uint8_t flag_bit = 0x80U >> i;
|
||||
uint8_t of_flags = this->buf[12];
|
||||
|
||||
if (flag)
|
||||
of_flags |= flag_bit;
|
||||
else
|
||||
of_flags &= ~flag_bit;
|
||||
|
||||
this->buf[12] = of_flags;
|
||||
this->update_partition();
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// see if one of the standard properties should be changed
|
||||
if (of_vars.find(var_name) == of_vars.end()) {
|
||||
cout << "Attempt to change unknown variable " << var_name << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto type = std::get<0>(of_vars.at(var_name));
|
||||
auto offset = std::get<1>(of_vars.at(var_name));
|
||||
|
||||
if (type == OF_VAR_TYPE_INT) {
|
||||
uint32_t num;
|
||||
try {
|
||||
num = str2env(value);
|
||||
} catch (invalid_argument& exc) {
|
||||
cout << exc.what() << endl;
|
||||
return;
|
||||
}
|
||||
WRITE_DWORD_BE_A(&this->buf[offset], num);
|
||||
this->update_partition();
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
} else {
|
||||
uint16_t str_offset = READ_WORD_BE_A(&this->buf[offset]);
|
||||
uint16_t str_len = READ_WORD_BE_A(&this->buf[offset+2]);
|
||||
|
||||
OfNvramHdr *hdr = (OfNvramHdr *)&this->buf[0];
|
||||
uint16_t here = READ_WORD_BE_A(&hdr->here);
|
||||
uint16_t top = READ_WORD_BE_A(&hdr->top);
|
||||
|
||||
// check if there is enough space in the heap for the new string
|
||||
// the heap is grown down from offset 0x2000 and cannot be lower than here (0x185c)
|
||||
uint16_t new_top = top + str_len - value.length();
|
||||
if (new_top < here) {
|
||||
cout << "No room in the heap!" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// remove the old string
|
||||
std::memmove(&this->buf[top + str_len - OF_NVRAM_OFFSET], &this->buf[top - OF_NVRAM_OFFSET], str_offset - top);
|
||||
for (auto& var : of_vars) {
|
||||
auto type = std::get<0>(var.second);
|
||||
auto offset = std::get<1>(var.second);
|
||||
if (type == OF_VAR_TYPE_STR) {
|
||||
uint16_t i_str_offset = READ_WORD_BE_A(&this->buf[offset]);
|
||||
if (i_str_offset < str_offset) {
|
||||
WRITE_WORD_BE_A(&this->buf[offset], i_str_offset + str_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
top = new_top;
|
||||
|
||||
// copy new string into NVRAM buffer char by char
|
||||
i = 0;
|
||||
for(char& ch : value) {
|
||||
this->buf[top + i - OF_NVRAM_OFFSET] = ch == '\x0A' ? '\x0D' : ch;
|
||||
i++;
|
||||
}
|
||||
|
||||
// stuff new values into the variable state
|
||||
WRITE_WORD_BE_A(&this->buf[offset+0], top);
|
||||
WRITE_WORD_BE_A(&this->buf[offset+2], value.length());
|
||||
|
||||
// update partition header
|
||||
WRITE_WORD_BE_A(&hdr->top, top);
|
||||
|
||||
// update physical NVRAM
|
||||
this->update_partition();
|
||||
cout << " ok" << endl; // mimic Forth
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
#ifndef OF_NVRAM_H
|
||||
#define OF_NVRAM_H
|
||||
|
||||
#include <devices/common/nvram.h>
|
||||
|
||||
/** @file Utilities for working with the Apple Open Firmware NVRAM partition. */
|
||||
|
||||
#define OF_NVRAM_OFFSET 0x1800
|
||||
#define OF_NVRAM_SIG 0x1275
|
||||
|
||||
// OF Variable types
|
||||
enum {
|
||||
OF_VAR_TYPE_INT = 1,
|
||||
OF_VAR_TYPE_STR = 2,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint16_t sig; // >nv.1275 partition signature (= 0x1275)
|
||||
uint8_t version; // >nv.version header version (= 5)
|
||||
uint8_t num_pages; // >nv.pages number of memory pages (= 8 pages 0x100 bytes each)
|
||||
uint16_t checksum; // >nv.checksum partition checksum
|
||||
uint16_t here; // >nv.here offset to the next free byte (offset of after last string length; = 0x185c)
|
||||
uint16_t top; // >nv.top offset to the last free byte (offset of string with lowest offset; < 0x2000)
|
||||
} OfNvramHdr;
|
||||
|
||||
class OfNvramUtils {
|
||||
public:
|
||||
OfNvramUtils() = default;
|
||||
~OfNvramUtils() = default;
|
||||
|
||||
int init();
|
||||
void printenv();
|
||||
void setenv(std::string var_name, std::string value);
|
||||
|
||||
protected:
|
||||
bool validate();
|
||||
uint16_t checksum_partition();
|
||||
void update_partition();
|
||||
|
||||
private:
|
||||
NVram* nvram_obj = nullptr;
|
||||
int size = 0;
|
||||
uint8_t buf[0x800];
|
||||
};
|
||||
|
||||
#endif // OF_NVRAM_H
|
||||
@@ -0,0 +1,405 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Bandit ARBus-to-PCI Bridge emulation. */
|
||||
|
||||
#include <devices/common/pci/bandit.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
const int MultiplyDeBruijnBitPosition2[] =
|
||||
{
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
|
||||
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
|
||||
};
|
||||
|
||||
/** finds the position of the bit that is set */
|
||||
#define WHAT_BIT_SET(val) (MultiplyDeBruijnBitPosition2[(uint32_t)(val * 0x077CB531U) >> 27])
|
||||
|
||||
Bandit::Bandit(int bridge_num, std::string name) : PCIHost(), PCIDevice(name)
|
||||
{
|
||||
supports_types(HWCompType::PCI_HOST | HWCompType::PCI_DEV);
|
||||
|
||||
this->base_addr = 0xF0000000 + ((bridge_num & 3) << 25);
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
// add memory mapped I/O region for Bandit control registers
|
||||
// This region has the following layout:
|
||||
// base_addr + 0x000000 --> I/O space
|
||||
// base_addr + 0x800000 --> CONFIG_ADDR
|
||||
// base_addr + 0xC00000 --> CONFIG_DATA
|
||||
// base_addr + 0x1000000 --> pass-through memory space (not included below)
|
||||
mem_ctrl->add_mmio_region(base_addr, 0x01000000, this);
|
||||
|
||||
// prepare the PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = 0x0001;
|
||||
this->class_rev = 0x06000003;
|
||||
this->cache_ln_sz = 8;
|
||||
this->command = 0x16;
|
||||
|
||||
// make several PCI config space registers read-only
|
||||
this->pci_wr_cmd = [](uint16_t cmd) {}; // command register
|
||||
this->pci_wr_cache_lnsz = [](uint8_t val) {}; // cache line size register
|
||||
|
||||
// set the bits in the fine address space field of the address mask register
|
||||
// that correspond to the 32MB assigned PCI address space of this Bandit.
|
||||
// This initialization is implied by the device functionality.
|
||||
this->addr_mask = 3 << ((bridge_num & 3) * 2);
|
||||
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
uint32_t Bandit::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, size);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case BANDIT_ADDR_MASK:
|
||||
return BYTESWAP_32(this->addr_mask);
|
||||
default:
|
||||
LOG_F(WARNING, "%s: reading from unimplemented config register at 0x%X",
|
||||
this->pci_name.c_str(), reg_offs);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Bandit::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, size);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case BANDIT_ADDR_MASK:
|
||||
this->addr_mask = BYTESWAP_32(value);
|
||||
this->verbose_address_space();
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "%s: writing to unimplemented config register at 0x%X",
|
||||
this->pci_name.c_str(), reg_offs);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Bandit::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
uint32_t result, idsel;
|
||||
|
||||
if (offset & BANDIT_CONFIG_SPACE) {
|
||||
if (offset & 0x00400000) {
|
||||
fun_num = (this->config_addr >> 8) & 7;
|
||||
reg_offs = this->config_addr & 0xFCU;
|
||||
|
||||
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) {
|
||||
bus_num = (this->config_addr >> 16) & 255;
|
||||
dev_num = (this->config_addr >> 11) & 31;
|
||||
LOG_F(
|
||||
WARNING, "%s: read config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
|
||||
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
|
||||
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
LOG_F(
|
||||
ERROR, "%s: read invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c",
|
||||
this->name.c_str(), idsel, this->config_addr,
|
||||
fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
|
||||
if (idsel == BANDIT_ID_SEL) { // access to myself
|
||||
result = this->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
if (this->dev_map.count(idsel)) {
|
||||
result = this->dev_map[idsel]->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
dev_num = WHAT_BIT_SET(idsel) + 11;
|
||||
LOG_F(
|
||||
ERROR, "%s err: read attempt from non-existing PCI device ??:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = this->config_addr;
|
||||
}
|
||||
} else { // I/O space access
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_read(offset, size, &result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
LOG_F(ERROR, "%s: attempt to read from unmapped PCI I/O space, offset=0x%X",
|
||||
this->name.c_str(), offset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Bandit::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
uint32_t idsel;
|
||||
|
||||
if (offset & BANDIT_CONFIG_SPACE) {
|
||||
if (offset & 0x00400000) {
|
||||
fun_num = (this->config_addr >> 8) & 7;
|
||||
reg_offs = this->config_addr & 0xFCU;
|
||||
|
||||
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) {
|
||||
bus_num = (this->config_addr >> 16) & 255;
|
||||
dev_num = (this->config_addr >> 11) & 31;
|
||||
LOG_F(
|
||||
WARNING, "%s: write config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
|
||||
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
LOG_F(
|
||||
ERROR, "%s: write invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c = %0*x",
|
||||
this->name.c_str(), idsel, this->config_addr,
|
||||
fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (idsel == BANDIT_ID_SEL) { // access to myself
|
||||
this->pci_cfg_write(reg_offs, value, size);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->dev_map.count(idsel)) {
|
||||
this->dev_map[idsel]->pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
dev_num = WHAT_BIT_SET(idsel) + 11;
|
||||
LOG_F(
|
||||
ERROR, "%s err: write attempt to non-existing PCI device ??:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this->config_addr = BYTESWAP_32(value);
|
||||
}
|
||||
} else { // I/O space access
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_write(offset, value, size)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
LOG_F(ERROR, "%s: attempt to write to unmapped PCI I/O space, offset=0x%X",
|
||||
this->name.c_str(), offset);
|
||||
}
|
||||
}
|
||||
|
||||
void Bandit::verbose_address_space()
|
||||
{
|
||||
uint32_t mask;
|
||||
int bit_pos;
|
||||
|
||||
LOG_F(INFO, "%s address spaces:", this->pci_name.c_str());
|
||||
|
||||
// verbose coarse aka 256MB memory regions
|
||||
for (mask = 0x10000, bit_pos = 0; mask != 0x80000000UL; mask <<= 1, bit_pos++) {
|
||||
if (this->addr_mask & mask) {
|
||||
uint32_t start_addr = bit_pos << 28;
|
||||
LOG_F(INFO, "- 0x%X ... 0x%X", start_addr, start_addr + 0x0FFFFFFFU);
|
||||
}
|
||||
}
|
||||
|
||||
// verbose fine aka 16MB memory regions
|
||||
for (mask = 0x1, bit_pos = 0; mask != 0x10000UL; mask <<= 1, bit_pos++) {
|
||||
if (this->addr_mask & mask) {
|
||||
uint32_t start_addr = (bit_pos << 24) + 0xF0000000UL;
|
||||
LOG_F(INFO, "- 0x%X ... 0x%X", start_addr, start_addr + 0x00FFFFFFU);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Chaos::Chaos(std::string name) : PCIHost()
|
||||
{
|
||||
supports_types(HWCompType::PCI_HOST);
|
||||
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
// add memory mapped I/O region for Chaos control registers
|
||||
// This region has the following layout:
|
||||
// base_addr + 0x800000 --> CONFIG_ADDR
|
||||
// base_addr + 0xC00000 --> CONFIG_DATA
|
||||
mem_ctrl->add_mmio_region(0xF0000000UL, 0x01000000, this);
|
||||
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
uint32_t Chaos::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
uint32_t result, idsel;
|
||||
|
||||
if (offset & BANDIT_CONFIG_SPACE) {
|
||||
if (offset & 0x00400000) {
|
||||
fun_num = (this->config_addr >> 8) & 7;
|
||||
reg_offs = this->config_addr & 0xFCU;
|
||||
|
||||
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) {
|
||||
bus_num = (this->config_addr >> 16) & 255;
|
||||
dev_num = (this->config_addr >> 11) & 31;
|
||||
LOG_F(
|
||||
WARNING, "%s: read config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
|
||||
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
|
||||
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
LOG_F(
|
||||
ERROR, "%s: read invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c",
|
||||
this->name.c_str(), idsel, this->config_addr,
|
||||
fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
|
||||
if (this->dev_map.count(idsel)) {
|
||||
result = this->dev_map[idsel]->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
dev_num = WHAT_BIT_SET(idsel) + 11;
|
||||
LOG_F(
|
||||
ERROR, "%s err: read attempt from non-existing VCI device ??:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
} else {
|
||||
result = this->config_addr;
|
||||
}
|
||||
} else { // I/O space access
|
||||
LOG_F(ERROR, "%s: I/O space not supported", this->name.c_str());
|
||||
return 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Chaos::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
int bus_num, dev_num, fun_num;
|
||||
uint8_t reg_offs;
|
||||
uint32_t idsel;
|
||||
|
||||
if (offset & BANDIT_CONFIG_SPACE) {
|
||||
if (offset & 0x00400000) {
|
||||
fun_num = (this->config_addr >> 8) & 7;
|
||||
reg_offs = this->config_addr & 0xFCU;
|
||||
|
||||
// access to the CONFIG_DATA pseudo-register causes a Config Cycle
|
||||
if (this->config_addr & BANDIT_CAR_TYPE) {
|
||||
bus_num = (this->config_addr >> 16) & 255;
|
||||
dev_num = (this->config_addr >> 11) & 31;
|
||||
LOG_F(
|
||||
WARNING, "%s: write config cycle type 1 not supported yet %02x:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
idsel = (this->config_addr >> 11) & 0x1FFFFFU;
|
||||
|
||||
if (!SINGLE_BIT_SET(idsel)) {
|
||||
LOG_F(
|
||||
ERROR, "%s: write invalid IDSEL=0x%X config:0x%X ??:??.%x? @%02x?.%c = %0*x",
|
||||
this->name.c_str(), idsel, this->config_addr,
|
||||
fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->dev_map.count(idsel)) {
|
||||
this->dev_map[idsel]->pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
dev_num = WHAT_BIT_SET(idsel) + 11;
|
||||
LOG_F(
|
||||
ERROR, "%s err: write attempt to non-existing VCI device ??:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), dev_num, fun_num, reg_offs + (offset & 3),
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this->config_addr = BYTESWAP_32(value);
|
||||
}
|
||||
} else { // I/O space access
|
||||
LOG_F(ERROR, "%s: I/O space not supported", this->name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Bandit1_Descriptor = {
|
||||
Bandit::create_first, {}, {}
|
||||
};
|
||||
|
||||
static const DeviceDescription Chaos_Descriptor = {
|
||||
Chaos::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Bandit1, Bandit1_Descriptor);
|
||||
REGISTER_DEVICE(Chaos, Chaos_Descriptor);
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Bandit ARBus-to-PCI bridge definitions.
|
||||
|
||||
The Bandit ASIC is a custom ARBus-to-PCI bridge used in the second
|
||||
generation of the Power Macintosh computer equipped with the PCI bus.
|
||||
*/
|
||||
|
||||
#ifndef BANDIT_PCI_H
|
||||
#define BANDIT_PCI_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#define BANDIT_ID_SEL (1 << 0) // Bandit's own IDSEL
|
||||
#define BANDIT_CAR_TYPE (1 << 0) // Bandit config address type bit
|
||||
#define BANDIT_CONFIG_SPACE 0x00800000 // Bandit Config Space bit
|
||||
|
||||
/** Bandit specific configuration registers. */
|
||||
enum {
|
||||
BANDIT_ADDR_MASK = 0x48,
|
||||
};
|
||||
|
||||
/** checks if one bit is set at time, return 0 if not */
|
||||
#define SINGLE_BIT_SET(val) ((val) && !((val) & ((val)-1)))
|
||||
|
||||
class Bandit : public PCIHost, public PCIDevice {
|
||||
public:
|
||||
Bandit(int bridge_num, std::string name);
|
||||
~Bandit() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_first() {
|
||||
return std::unique_ptr<Bandit>(new Bandit(1, "Bandit-PCI1"));
|
||||
};
|
||||
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
protected:
|
||||
void verbose_address_space();
|
||||
|
||||
private:
|
||||
uint32_t base_addr;
|
||||
uint32_t config_addr;
|
||||
uint32_t addr_mask;
|
||||
};
|
||||
|
||||
/** Chaos is a custom ARBus-to-PCI bridge that provides a specialized
|
||||
PCI-like bus for video called VCI. This 64-bit bus runs at the same
|
||||
frequency as the CPU bus (40-50 MHz) and provides an interface
|
||||
between video input/output devices and the CPU bus.
|
||||
*/
|
||||
class Chaos : public PCIHost, public MMIODevice {
|
||||
public:
|
||||
Chaos(std::string name);
|
||||
~Chaos() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<Chaos>(new Chaos("VCI0"));
|
||||
};
|
||||
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
uint32_t config_addr;
|
||||
};
|
||||
|
||||
#endif // BANDIT_PCI_H
|
||||
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
PCIDevice::PCIDevice(std::string name)
|
||||
{
|
||||
this->pci_name = name;
|
||||
|
||||
this->pci_rd_stat = [this]() { return this->status; };
|
||||
this->pci_rd_cmd = [this]() { return this->command; };
|
||||
this->pci_rd_bist = []() { return 0; };
|
||||
this->pci_rd_lat_timer = [this]() { return this->lat_timer; };
|
||||
this->pci_rd_cache_lnsz = [this]() { return this->cache_ln_sz; };
|
||||
|
||||
this->pci_wr_stat = [](uint16_t val) {};
|
||||
this->pci_wr_cmd = [this](uint16_t cmd) { this->command = cmd; };
|
||||
this->pci_wr_bist = [](uint8_t val) {};
|
||||
this->pci_wr_lat_timer = [this](uint8_t val) { this->lat_timer = val; };
|
||||
this->pci_wr_cache_lnsz = [this](uint8_t val) { this->cache_ln_sz = val; };
|
||||
|
||||
this->pci_notify_bar_change = [](int bar_num) {};
|
||||
};
|
||||
|
||||
uint32_t PCIDevice::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_DEV_ID:
|
||||
result = (this->device_id << 16) | (this->vendor_id);
|
||||
break;
|
||||
case PCI_CFG_STAT_CMD:
|
||||
result = (this->pci_rd_stat() << 16) | (this->pci_rd_cmd());
|
||||
break;
|
||||
case PCI_CFG_CLASS_REV:
|
||||
result = this->class_rev;
|
||||
break;
|
||||
case PCI_CFG_DWORD_3:
|
||||
result = (pci_rd_bist() << 24) | (this->hdr_type << 16) |
|
||||
(pci_rd_lat_timer() << 8) | pci_rd_cache_lnsz();
|
||||
break;
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
case PCI_CFG_BAR2:
|
||||
case PCI_CFG_BAR3:
|
||||
case PCI_CFG_BAR4:
|
||||
case PCI_CFG_BAR5:
|
||||
result = this->bars[(reg_offs - 0x10) >> 2];
|
||||
break;
|
||||
case PCI_CFG_SUBSYS_ID:
|
||||
result = (this->subsys_id << 16) | (this->subsys_vndr);
|
||||
break;
|
||||
case PCI_CFG_ROM_BAR:
|
||||
result = this->exp_rom_bar;
|
||||
break;
|
||||
case PCI_CFG_DWORD_15:
|
||||
result = (max_lat << 24) | (min_gnt << 16) | (irq_pin << 8) | irq_line;
|
||||
break;
|
||||
case PCI_CFG_CAP_PTR:
|
||||
result = cap_ptr;
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
WARNING, "%s: attempt to read from reserved/unimplemented register @%02x.%c",
|
||||
this->pci_name.c_str(), reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (size == 4) {
|
||||
return BYTESWAP_32(result);
|
||||
} else {
|
||||
return read_mem_rev(((uint8_t *)&result) + (reg_offs & 3), size);
|
||||
}
|
||||
}
|
||||
|
||||
void PCIDevice::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
{
|
||||
uint32_t data;
|
||||
|
||||
if (size == 4) {
|
||||
data = BYTESWAP_32(value);
|
||||
} else {
|
||||
// get current register content as DWORD and update it partially
|
||||
data = BYTESWAP_32(this->pci_cfg_read(reg_offs, 4));
|
||||
write_mem_rev(((uint8_t *)&data) + (reg_offs & 3), value, size);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case PCI_CFG_STAT_CMD:
|
||||
this->pci_wr_stat(data >> 16);
|
||||
this->pci_wr_cmd(data & 0xFFFFU);
|
||||
break;
|
||||
case PCI_CFG_DWORD_3:
|
||||
this->pci_wr_bist(data >> 24);
|
||||
this->pci_wr_lat_timer((data >> 8) & 0xFF);
|
||||
this->pci_wr_cache_lnsz(data & 0xFF);
|
||||
break;
|
||||
case PCI_CFG_BAR0:
|
||||
case PCI_CFG_BAR1:
|
||||
case PCI_CFG_BAR2:
|
||||
case PCI_CFG_BAR3:
|
||||
case PCI_CFG_BAR4:
|
||||
case PCI_CFG_BAR5:
|
||||
if (data == 0xFFFFFFFFUL) {
|
||||
this->do_bar_sizing((reg_offs - 0x10) >> 2);
|
||||
} else {
|
||||
this->set_bar_value((reg_offs - 0x10) >> 2, data);
|
||||
}
|
||||
break;
|
||||
case PCI_CFG_ROM_BAR:
|
||||
if (data == 0xFFFFF800UL) {
|
||||
this->exp_rom_bar = this->exp_bar_cfg;
|
||||
} else {
|
||||
this->exp_rom_bar = (data & 0xFFFFF801UL);
|
||||
if (this->exp_rom_bar & 1) {
|
||||
this->map_exp_rom_mem();
|
||||
} else {
|
||||
LOG_F(WARNING, "%s: unmapping of expansion ROM not implemented yet",
|
||||
this->pci_name.c_str());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PCI_CFG_DWORD_15:
|
||||
this->irq_line = data >> 24;
|
||||
break;
|
||||
default:
|
||||
LOG_F(
|
||||
WARNING, "%s: attempt to write to reserved/unimplemented register @%02x.%c = %0*x",
|
||||
this->pci_name.c_str(), reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size, size * 2, value
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
int PCIDevice::attach_exp_rom_image(const std::string img_path)
|
||||
{
|
||||
std::ifstream img_file;
|
||||
|
||||
int result = 0;
|
||||
|
||||
this->exp_bar_cfg = 0; // tell the world we got no ROM for now
|
||||
|
||||
try {
|
||||
img_file.open(img_path, std::ios::in | std::ios::binary);
|
||||
if (img_file.fail()) {
|
||||
throw std::runtime_error("could not open specified ROM dump image");
|
||||
}
|
||||
|
||||
// validate image file
|
||||
uint8_t buf[4] = { 0 };
|
||||
|
||||
img_file.seekg(0, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
if (buf[0] != 0x55 || buf[1] != 0xAA) {
|
||||
throw std::runtime_error("invalid expansion ROM signature");
|
||||
}
|
||||
|
||||
// determine image size
|
||||
img_file.seekg(0, std::ios::end);
|
||||
uint32_t exp_rom_image_size = img_file.tellg();
|
||||
|
||||
// verify PCI struct offset
|
||||
uint32_t pci_struct_offset = 0;
|
||||
img_file.seekg(0x18, std::ios::beg);
|
||||
img_file.read((char *)&pci_struct_offset, sizeof(pci_struct_offset));
|
||||
|
||||
if (pci_struct_offset > exp_rom_image_size) {
|
||||
throw std::runtime_error("invalid PCI structure offset");
|
||||
}
|
||||
|
||||
// verify PCI struct signature
|
||||
img_file.seekg(pci_struct_offset, std::ios::beg);
|
||||
img_file.read((char *)buf, sizeof(buf));
|
||||
|
||||
if (buf[0] != 'P' || buf[1] != 'C' || buf[2] != 'I' || buf[3] != 'R') {
|
||||
throw std::runtime_error("unexpected PCI struct signature");
|
||||
}
|
||||
|
||||
// find minimum rom size for the rom file (power of 2 >= 0x800)
|
||||
for (this->exp_rom_size = 1 << 11; this->exp_rom_size < exp_rom_image_size; this->exp_rom_size <<= 1) {}
|
||||
|
||||
// ROM image ok - go ahead and load it
|
||||
this->exp_rom_data = std::unique_ptr<uint8_t[]> (new uint8_t[this->exp_rom_size]);
|
||||
img_file.seekg(0, std::ios::beg);
|
||||
img_file.read((char *)this->exp_rom_data.get(), exp_rom_image_size);
|
||||
memset(&this->exp_rom_data[exp_rom_image_size], 0xff, this->exp_rom_size - exp_rom_image_size);
|
||||
|
||||
if (exp_rom_image_size == this->exp_rom_size) {
|
||||
LOG_F(INFO, "%s: loaded expansion rom (%d bytes).", this->pci_name.c_str(), this->exp_rom_size);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "%s: loaded expansion rom (%d bytes adjusted to %d bytes).", this->pci_name.c_str(), exp_rom_image_size, this->exp_rom_size);
|
||||
}
|
||||
|
||||
this->exp_bar_cfg = ~(this->exp_rom_size - 1);
|
||||
}
|
||||
catch (const std::exception& exc) {
|
||||
LOG_F(ERROR, "PCIDevice: %s", exc.what());
|
||||
result = -1;
|
||||
}
|
||||
|
||||
img_file.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void PCIDevice::do_bar_sizing(int bar_num)
|
||||
{
|
||||
this->bars[bar_num] = this->bars_cfg[bar_num];
|
||||
}
|
||||
|
||||
void PCIDevice::set_bar_value(int bar_num, uint32_t value)
|
||||
{
|
||||
uint32_t bar_cfg = this->bars_cfg[bar_num];
|
||||
if (bar_cfg & 1) {
|
||||
this->bars[bar_num] = (value & 0xFFFFFFFCUL) | 1;
|
||||
} else {
|
||||
if (bar_cfg & 6) {
|
||||
ABORT_F("Invalid or unsupported PCI space type: %d", (bar_cfg >> 1) & 3);
|
||||
}
|
||||
this->bars[bar_num] = (value & 0xFFFFFFF0UL) | (bar_cfg & 0xF);
|
||||
}
|
||||
this->pci_notify_bar_change(bar_num);
|
||||
}
|
||||
|
||||
void PCIDevice::map_exp_rom_mem()
|
||||
{
|
||||
uint32_t rom_addr, rom_size;
|
||||
|
||||
rom_addr = this->exp_rom_bar & 0xFFFFF800UL;
|
||||
rom_size = ~this->exp_bar_cfg + 1;
|
||||
|
||||
if (!this->exp_rom_addr || this->exp_rom_addr != rom_addr) {
|
||||
this->host_instance->pci_register_mmio_region(rom_addr, rom_size, this);
|
||||
this->exp_rom_addr = rom_addr;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -26,32 +26,46 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/* convert little-endian DWORD to big-endian DWORD */
|
||||
#define LE2BE(x) (x >> 24) | ((x & 0x00FF0000) >> 8) | ((x & 0x0000FF00) << 8) | (x << 24)
|
||||
|
||||
/** PCI configuration space registers offsets */
|
||||
enum {
|
||||
CFG_REG_CMD = 0x04, // command/status register
|
||||
CFG_REG_BAR0 = 0x10, // base address register 0
|
||||
CFG_REG_BAR1 = 0x14, // base address register 1
|
||||
CFG_REG_BAR2 = 0x18, // base address register 2
|
||||
CFG_REG_BAR3 = 0x1C, // base address register 3
|
||||
CFG_REG_BAR4 = 0x20, // base address register 4
|
||||
CFG_REG_BAR5 = 0x24, // base address register 5
|
||||
CFG_EXP_BASE = 0x30, // expansion ROM base
|
||||
PCI_CFG_DEV_ID = 0x00, // device and vendor IDs
|
||||
PCI_CFG_STAT_CMD = 0x04, // command/status register
|
||||
PCI_CFG_CLASS_REV = 0x08, // class code and revision ID
|
||||
PCI_CFG_DWORD_3 = 0x0C, // BIST, HeaderType, Lat_Timer and Cache_Line_Size
|
||||
PCI_CFG_BAR0 = 0x10, // base address register 0
|
||||
PCI_CFG_BAR1 = 0x14, // base address register 1
|
||||
PCI_CFG_BAR2 = 0x18, // base address register 2
|
||||
PCI_CFG_BAR3 = 0x1C, // base address register 3
|
||||
PCI_CFG_BAR4 = 0x20, // base address register 4
|
||||
PCI_CFG_BAR5 = 0x24, // base address register 5
|
||||
PCI_CFG_CIS_PTR = 0x28, // Cardbus CIS Pointer
|
||||
PCI_CFG_SUBSYS_ID = 0x2C, // Subsysten IDs
|
||||
PCI_CFG_ROM_BAR = 0x30, // expansion ROM base address
|
||||
PCI_CFG_CAP_PTR = 0x34, // capabilities pointer
|
||||
PCI_CFG_DWORD_14 = 0x38, // reserved
|
||||
PCI_CFG_DWORD_15 = 0x3C, // Max_Lat, Min_Gnt, Int_Pin and Int_Line registers
|
||||
};
|
||||
|
||||
/** PCI Vendor IDs for devices used in Power Macintosh computers. */
|
||||
enum {
|
||||
PCI_VENDOR_ATI = 0x1002,
|
||||
PCI_VENDOR_MOTOROLA = 0x1057,
|
||||
PCI_VENDOR_APPLE = 0x106B,
|
||||
};
|
||||
|
||||
|
||||
class PCIDevice : public MMIODevice {
|
||||
public:
|
||||
PCIDevice(std::string name) {
|
||||
this->pci_name = name;
|
||||
};
|
||||
PCIDevice(std::string name);
|
||||
virtual ~PCIDevice() = default;
|
||||
|
||||
virtual bool supports_io_space(void) = 0;
|
||||
virtual bool supports_io_space() {
|
||||
return false;
|
||||
};
|
||||
|
||||
/* I/O space access methods */
|
||||
virtual bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
||||
@@ -62,18 +76,64 @@ public:
|
||||
return false;
|
||||
};
|
||||
|
||||
/* configuration space access methods */
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size) = 0;
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) = 0;
|
||||
// configuration space access methods
|
||||
virtual uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
virtual void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
|
||||
// plugin interface for using in the derived classes
|
||||
std::function<uint16_t()> pci_rd_stat;
|
||||
std::function<void(uint16_t)> pci_wr_stat;
|
||||
std::function<uint16_t()> pci_rd_cmd;
|
||||
std::function<void(uint16_t)> pci_wr_cmd;
|
||||
std::function<uint8_t()> pci_rd_bist;
|
||||
std::function<void(uint8_t)> pci_wr_bist;
|
||||
std::function<uint8_t()> pci_rd_lat_timer;
|
||||
std::function<void(uint8_t)> pci_wr_lat_timer;
|
||||
std::function<uint8_t()> pci_rd_cache_lnsz;
|
||||
std::function<void(uint8_t)> pci_wr_cache_lnsz;
|
||||
|
||||
std::function<void(int)> pci_notify_bar_change;
|
||||
|
||||
int attach_exp_rom_image(const std::string img_path);
|
||||
|
||||
virtual void set_host(PCIHost* host_instance) {
|
||||
this->host_instance = host_instance;
|
||||
};
|
||||
|
||||
protected:
|
||||
void do_bar_sizing(int bar_num);
|
||||
void set_bar_value(int bar_num, uint32_t value);
|
||||
void map_exp_rom_mem();
|
||||
|
||||
std::string pci_name; // human-readable device name
|
||||
PCIHost* host_instance; // host bridge instance to call back
|
||||
uint32_t base_addr; // base address register 0
|
||||
|
||||
// PCI configuration space state
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
uint32_t class_rev; // class code and revision id
|
||||
uint16_t status = 0;
|
||||
uint16_t command = 0;
|
||||
uint8_t hdr_type = 0; // header type
|
||||
uint8_t lat_timer = 0; // latency timer
|
||||
uint8_t cache_ln_sz = 0; // cache line size
|
||||
uint16_t subsys_id = 0;
|
||||
uint16_t subsys_vndr = 0;
|
||||
uint8_t cap_ptr = 0;
|
||||
uint8_t max_lat = 0;
|
||||
uint8_t min_gnt = 0;
|
||||
uint8_t irq_pin = 0;
|
||||
uint8_t irq_line = 0;
|
||||
|
||||
uint32_t bars[6] = { 0 }; // base address registers
|
||||
uint32_t bars_cfg[6] = { 0 }; // configuration values for base address registers
|
||||
|
||||
uint32_t exp_bar_cfg = 0; // expansion ROM configuration
|
||||
uint32_t exp_rom_bar = 0; // expansion ROM base address register
|
||||
uint32_t exp_rom_addr = 0; // expansion ROM base address
|
||||
uint32_t exp_rom_size = 0; // expansion ROM size in bytes
|
||||
|
||||
std::unique_ptr<uint8_t[]> exp_rom_data;
|
||||
};
|
||||
|
||||
#endif /* PCI_DEVICE_H */
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
bool PCIHost::pci_register_device(int dev_num, PCIDevice* dev_instance)
|
||||
{
|
||||
// return false if dev_num already registered
|
||||
if (this->dev_map.count(dev_num))
|
||||
return false;
|
||||
|
||||
this->dev_map[dev_num] = dev_instance;
|
||||
|
||||
dev_instance->set_host(this);
|
||||
|
||||
if (dev_instance->supports_io_space()) {
|
||||
this->io_space_devs.push_back(dev_instance);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PCIHost::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj)
|
||||
{
|
||||
MemCtrlBase *mem_ctrl = dynamic_cast<MemCtrlBase *>
|
||||
(gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
// FIXME: add sanity checks!
|
||||
return mem_ctrl->add_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
void PCIHost::attach_pci_device(std::string& dev_name, int slot_id)
|
||||
{
|
||||
if (!DeviceRegistry::device_registered(dev_name)) {
|
||||
LOG_F(WARNING, "PCIHost: specified PCI device %s doesn't exist", dev_name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// attempt to create device object
|
||||
auto dev_obj = DeviceRegistry::get_descriptor(dev_name).m_create_func();
|
||||
|
||||
if (!dev_obj->supports_type(HWCompType::PCI_DEV)) {
|
||||
LOG_F(WARNING, "PCIHost: cannot attach non-PCI device %s", dev_name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// add device to the machine object
|
||||
gMachineObj->add_device(dev_name, std::move(dev_obj));
|
||||
|
||||
// register device with the PCI host
|
||||
this->pci_register_device(
|
||||
slot_id, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name(dev_name)));
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -22,14 +22,32 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef PCI_HOST_H
|
||||
#define PCI_HOST_H
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class PCIDevice; // forward declaration to prevent errors
|
||||
|
||||
class PCIHost {
|
||||
public:
|
||||
virtual bool pci_register_device(int dev_num, PCIDevice* dev_instance) = 0;
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj) = 0;
|
||||
PCIHost() {
|
||||
this->dev_map.clear();
|
||||
io_space_devs.clear();
|
||||
};
|
||||
~PCIHost() = default;
|
||||
|
||||
virtual bool pci_register_device(int dev_num, PCIDevice* dev_instance);
|
||||
|
||||
virtual bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
|
||||
virtual void attach_pci_device(std::string& dev_name, int slot_id);
|
||||
|
||||
protected:
|
||||
std::unordered_map<int, PCIDevice*> dev_map;
|
||||
std::vector<PCIDevice*> io_space_devs;
|
||||
};
|
||||
|
||||
#endif /* PCI_HOST_H */
|
||||
+190
-14
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,49 +21,225 @@ 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/hwinterrupt.h>
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <loguru.hpp>
|
||||
|
||||
uint8_t MESHController::read(uint8_t reg_offset)
|
||||
using namespace MeshScsi;
|
||||
|
||||
int MeshController::device_postinit()
|
||||
{
|
||||
this->bus_obj = dynamic_cast<ScsiBus*>(gMachineObj->get_comp_by_name("SCSI0"));
|
||||
|
||||
this->int_ctrl = dynamic_cast<InterruptCtrl*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::SCSI1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MeshController::reset(bool is_hard_reset)
|
||||
{
|
||||
this->cur_cmd = SeqCmd::NoOperation;
|
||||
this->int_mask = 0;
|
||||
|
||||
if (is_hard_reset) {
|
||||
this->bus_stat = 0;
|
||||
this->sync_params = 2; // guessed
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MeshController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
case MeshReg::Sequence:
|
||||
return this->cur_cmd;
|
||||
case MeshReg::BusStatus0:
|
||||
LOG_F(9, "MESH: read from BusStatus0 register");
|
||||
return this->bus_obj->test_ctrl_lines(0xFFU);
|
||||
case MeshReg::BusStatus1:
|
||||
return this->bus_obj->test_ctrl_lines(0xE000U) >> 8;
|
||||
case MeshReg::Exception:
|
||||
return 0;
|
||||
case MeshReg::Error:
|
||||
return 0;
|
||||
case MeshReg::IntMask:
|
||||
return this->int_mask;
|
||||
case MeshReg::Interrupt:
|
||||
return this->int_stat;
|
||||
case MeshReg::MeshID:
|
||||
LOG_F(INFO, "MESH: read from MeshID register");
|
||||
return this->chip_id; // tell them who we are
|
||||
default:
|
||||
LOG_F(WARNING, "MESH: read from unimplemented register at offset %d", reg_offset);
|
||||
LOG_F(WARNING, "MESH: read from unimplemented register at offset 0x%x", reg_offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MESHController::write(uint8_t reg_offset, uint8_t value)
|
||||
void MeshController::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
uint16_t new_stat;
|
||||
|
||||
switch(reg_offset) {
|
||||
case MeshReg::Sequence:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to Sequence register", value);
|
||||
perform_command(value);
|
||||
break;
|
||||
case MeshReg::BusStatus1:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to BusStatus1 register", value);
|
||||
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(new_stat, mask);
|
||||
else
|
||||
this->bus_obj->release_ctrl_line(new_stat, mask);
|
||||
}
|
||||
}
|
||||
this->bus_stat = new_stat;
|
||||
}
|
||||
break;
|
||||
case MeshReg::IntMask:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to IntMask register", value);
|
||||
this->int_mask = value;
|
||||
break;
|
||||
case MeshReg::Interrupt:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to Interrupt register", value);
|
||||
this->int_stat &= ~(value & INT_MASK); // clear requested interrupt bits
|
||||
update_irq();
|
||||
break;
|
||||
case MeshReg::SourceID:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to SourceID register", value);
|
||||
this->src_id = value;
|
||||
break;
|
||||
case MeshReg::DestID:
|
||||
this->dst_id = value;
|
||||
break;
|
||||
case MeshReg::SyncParms:
|
||||
LOG_F(INFO, "MESH: write 0x%02X to SyncParms register", value);
|
||||
this->sync_params = value;
|
||||
break;
|
||||
case MeshReg::SelTimeOut:
|
||||
LOG_F(9, "MESH: selection timeout set to 0x%x", value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "MESH: write to unimplemented register at offset %d", reg_offset);
|
||||
LOG_F(WARNING, "MESH: write to unimplemented register at offset 0x%x",
|
||||
reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
void MeshController::perform_command(const uint8_t cmd)
|
||||
{
|
||||
this->cur_cmd = cmd;
|
||||
|
||||
this->int_stat &= ~INT_CMD_DONE;
|
||||
|
||||
switch (this->cur_cmd & 0xF) {
|
||||
case SeqCmd::Arbitrate:
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::Select:
|
||||
this->cur_state = SeqState::SEL_BEGIN;
|
||||
this->sequencer();
|
||||
break;
|
||||
case SeqCmd::DisReselect:
|
||||
LOG_F(INFO, "MESH: DisReselect command requested");
|
||||
break;
|
||||
case SeqCmd::ResetMesh:
|
||||
this->reset(false);
|
||||
this->int_stat |= INT_CMD_DONE;
|
||||
break;
|
||||
case SeqCmd::FlushFIFO:
|
||||
LOG_F(INFO, "MESH: FlushFIFO command requested");
|
||||
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::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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Mesh_Descriptor = {
|
||||
MeshController::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Mesh, Mesh_Descriptor);
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-23 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,12 +24,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MESH_H
|
||||
#define MESH_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
// Chip ID returned by the MESH cell inside the Heathrow ASIC
|
||||
#define HeathrowMESHID 4
|
||||
|
||||
// MESH registers offsets
|
||||
namespace MeshScsi {
|
||||
|
||||
// MESH registers offsets.
|
||||
enum MeshReg : uint8_t {
|
||||
XferCount0 = 0,
|
||||
XferCount1 = 1,
|
||||
@@ -49,17 +56,102 @@ enum MeshReg : uint8_t {
|
||||
SelTimeOut = 0xF
|
||||
};
|
||||
|
||||
class MESHController {
|
||||
// MESH Sequencer commands.
|
||||
enum SeqCmd : uint8_t {
|
||||
NoOperation = 0,
|
||||
Arbitrate = 1,
|
||||
Select = 2,
|
||||
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,
|
||||
};
|
||||
|
||||
}; // namespace MeshScsi
|
||||
|
||||
class MeshController : public HWComponent {
|
||||
public:
|
||||
MESHController(uint8_t mesh_id) { this->chip_id = mesh_id; };
|
||||
~MESHController() = default;
|
||||
MeshController(uint8_t mesh_id) {
|
||||
supports_types(HWCompType::SCSI_HOST | HWCompType::SCSI_DEV);
|
||||
this->chip_id = mesh_id;
|
||||
this->reset(true);
|
||||
};
|
||||
~MeshController() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
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);
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
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();
|
||||
|
||||
private:
|
||||
uint8_t chip_id; // Chip ID for the MESH controller
|
||||
uint8_t chip_id;
|
||||
uint8_t int_mask;
|
||||
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 exception;
|
||||
|
||||
ScsiBus* bus_obj;
|
||||
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;
|
||||
};
|
||||
|
||||
#endif // MESH_H
|
||||
+317
-17
@@ -25,12 +25,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/scsi/sc53c94.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id)
|
||||
Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice(my_id)
|
||||
{
|
||||
this->chip_id = chip_id;
|
||||
this->my_bus_id = my_id;
|
||||
@@ -73,13 +75,20 @@ void Sc53C94::reset_device()
|
||||
|
||||
uint8_t Sc53C94::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t int_status;
|
||||
uint8_t status, int_status;
|
||||
|
||||
switch (reg_offset) {
|
||||
case Read::Reg53C94::Xfer_Cnt_LSB:
|
||||
return this->xfer_count & 0xFFU;
|
||||
case Read::Reg53C94::Xfer_Cnt_MSB:
|
||||
return (this->xfer_count >> 8) & 0xFFU;
|
||||
case Read::Reg53C94::FIFO:
|
||||
return this->fifo_pop();
|
||||
case Read::Reg53C94::Command:
|
||||
return this->cmd_fifo[0];
|
||||
case Read::Reg53C94::Status:
|
||||
return this->status;
|
||||
status = bus_obj->test_ctrl_lines(SCSI_CTRL_MSG | SCSI_CTRL_CD | SCSI_CTRL_IO);
|
||||
return (this->status & 0xF8) | status;
|
||||
case Read::Reg53C94::Int_Status:
|
||||
int_status = this->int_status;
|
||||
this->seq_step = 0;
|
||||
@@ -90,6 +99,8 @@ uint8_t Sc53C94::read(uint8_t reg_offset)
|
||||
return this->seq_step;
|
||||
case Read::Reg53C94::FIFO_Flags:
|
||||
return (this->seq_step << 5) | (this->data_fifo_pos & 0x1F);
|
||||
case Read::Reg53C94::Config_1:
|
||||
return this->config1;
|
||||
case Read::Reg53C94::Config_3:
|
||||
return this->config3;
|
||||
case Read::Reg53C94::Xfer_Cnt_Hi:
|
||||
@@ -106,6 +117,12 @@ uint8_t Sc53C94::read(uint8_t reg_offset)
|
||||
void Sc53C94::write(uint8_t reg_offset, uint8_t value)
|
||||
{
|
||||
switch (reg_offset) {
|
||||
case Write::Reg53C94::Xfer_Cnt_LSB:
|
||||
this->set_xfer_count = (this->set_xfer_count & ~0xFFU) | value;
|
||||
break;
|
||||
case Write::Reg53C94::Xfer_Cnt_MSB:
|
||||
this->set_xfer_count = (this->set_xfer_count & ~0xFF00U) | (value << 8);
|
||||
break;
|
||||
case Write::Reg53C94::Command:
|
||||
update_command_reg(value);
|
||||
break;
|
||||
@@ -141,6 +158,37 @@ void Sc53C94::write(uint8_t reg_offset, uint8_t value)
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Sc53C94::pseudo_dma_read()
|
||||
{
|
||||
uint16_t data_word;
|
||||
bool is_done = false;
|
||||
|
||||
if (this->data_fifo_pos >= 2) {
|
||||
// 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);
|
||||
|
||||
// update DMA status
|
||||
if ((this->cmd_fifo[0] & 0x80)) {
|
||||
this->xfer_count -= 2;
|
||||
if (!this->xfer_count) {
|
||||
is_done = true;
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->data_fifo_pos && !is_done) {
|
||||
this->sequencer();
|
||||
}
|
||||
|
||||
return data_word;
|
||||
}
|
||||
|
||||
void Sc53C94::update_command_reg(uint8_t cmd)
|
||||
{
|
||||
if (this->on_reset && (cmd & 0x7F) != CMD_NOP) {
|
||||
@@ -165,13 +213,13 @@ void Sc53C94::update_command_reg(uint8_t cmd)
|
||||
}
|
||||
} else {
|
||||
LOG_F(ERROR, "SC53C94: the top of the command FIFO overwritten!");
|
||||
this->status |= 0x40; // signal IOE/Gross Error
|
||||
this->status |= STAT_GE; // signal IOE/Gross Error
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::exec_command()
|
||||
{
|
||||
uint8_t cmd = this->cmd_fifo[0] & 0x7F;
|
||||
uint8_t cmd = this->cur_cmd = this->cmd_fifo[0] & 0x7F;
|
||||
bool is_dma_cmd = !!(this->cmd_fifo[0] & 0x80);
|
||||
|
||||
if (is_dma_cmd) {
|
||||
@@ -179,6 +227,9 @@ void Sc53C94::exec_command()
|
||||
this->xfer_count = this->set_xfer_count & 0xFFFFFFUL;
|
||||
} else { // standard mode: 16-bit
|
||||
this->xfer_count = this->set_xfer_count & 0xFFFFUL;
|
||||
if (!this->xfer_count) {
|
||||
this->xfer_count = 65536;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +242,7 @@ void Sc53C94::exec_command()
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_CLEAR_FIFO:
|
||||
this->data_fifo_pos = 0; // set the bottom of the FIFO to zero
|
||||
this->data_fifo_pos = 0; // set the bottom of the data FIFO to zero
|
||||
this->data_fifo[0] = 0;
|
||||
exec_next_command();
|
||||
break;
|
||||
@@ -215,26 +266,77 @@ void Sc53C94::exec_command()
|
||||
}
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_XFER:
|
||||
if (!this->is_initiator) {
|
||||
// clear command FIFO
|
||||
this->cmd_fifo_pos = 0;
|
||||
this->int_status |= INTSTAT_ICMD;
|
||||
this->update_irq();
|
||||
} else {
|
||||
this->seq_step = 0;
|
||||
this->cmd_steps = nullptr;
|
||||
this->cur_state = SeqState::XFER_BEGIN;
|
||||
this->sequencer();
|
||||
}
|
||||
break;
|
||||
case CMD_COMPLETE_STEPS:
|
||||
static SeqDesc * complete_steps_desc = new SeqDesc[3]{
|
||||
{SeqState::RCV_STATUS, 0, 0},
|
||||
{SeqState::RCV_MESSAGE, 0, 0},
|
||||
{SeqState::CMD_COMPLETE, 0, INTSTAT_SR}
|
||||
};
|
||||
if (this->bus_obj->current_phase() != ScsiPhase::STATUS) {
|
||||
ABORT_F("Sc53C94: complete steps only works in the STATUS phase");
|
||||
}
|
||||
this->seq_step = 0;
|
||||
this->cmd_steps = complete_steps_desc;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
break;
|
||||
case CMD_MSG_ACCEPTED:
|
||||
if (this->is_initiator) {
|
||||
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->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
case CMD_SELECT_NO_ATN:
|
||||
static SeqDesc * sel_no_atn_desc = new SeqDesc[3]{
|
||||
{SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
|
||||
{SeqState::CMD_BEGIN, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
|
||||
};
|
||||
this->seq_step = 0;
|
||||
this->cmd_steps = sel_no_atn_desc;
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
sequencer();
|
||||
LOG_F(INFO, "SC53C94: SELECT W/O ATN command started");
|
||||
this->sequencer();
|
||||
LOG_F(9, "SC53C94: SELECT W/O ATN command started");
|
||||
break;
|
||||
case CMD_SELECT_WITH_ATN:
|
||||
static SeqDesc * sel_with_atn_desc = new SeqDesc[4]{
|
||||
{SeqState::SEL_BEGIN, 0, INTSTAT_DIS },
|
||||
{SeqState::SEND_MSG, 2, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::SEND_CMD, 3, INTSTAT_SR | INTSTAT_SO},
|
||||
{SeqState::CMD_COMPLETE, 4, INTSTAT_SR | INTSTAT_SO},
|
||||
};
|
||||
this->seq_step = 0;
|
||||
this->bytes_out = 1; // set message length
|
||||
this->cmd_steps = sel_with_atn_desc;
|
||||
this->cur_state = SeqState::BUS_FREE;
|
||||
this->sequencer();
|
||||
LOG_F(9, "SC53C94: SELECT WITH ATN command started");
|
||||
break;
|
||||
case CMD_ENA_SEL_RESEL:
|
||||
LOG_F(INFO, "SC53C94: ENABLE SELECTION/RESELECTION command executed");
|
||||
exec_next_command();
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "SC53C94: invalid/unimplemented command 0x%X", cmd);
|
||||
this->cmd_fifo_pos--; // remove invalid command from FIFO
|
||||
this->int_status |= INTSTAT_ICMD;
|
||||
this->update_irq();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,14 +353,30 @@ void Sc53C94::exec_next_command()
|
||||
|
||||
void Sc53C94::fifo_push(const uint8_t data)
|
||||
{
|
||||
if (this->data_fifo_pos < 16) {
|
||||
if (this->data_fifo_pos < DATA_FIFO_MAX) {
|
||||
this->data_fifo[this->data_fifo_pos++] = data;
|
||||
} else {
|
||||
LOG_F(ERROR, "SC53C94: data FIFO overflow!");
|
||||
this->status |= 0x40; // signal IOE/Gross Error
|
||||
this->status |= STAT_GE; // signal IOE/Gross Error
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Sc53C94::fifo_pop()
|
||||
{
|
||||
uint8_t data = 0;
|
||||
|
||||
if (this->data_fifo_pos < 1) {
|
||||
LOG_F(ERROR, "SC53C94: data FIFO underflow!");
|
||||
this->status |= STAT_GE; // signal IOE/Gross Error
|
||||
} else {
|
||||
data = this->data_fifo[0];
|
||||
this->data_fifo_pos--;
|
||||
std:memmove(this->data_fifo, &this->data_fifo[1], this->data_fifo_pos);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void Sc53C94::seq_defer_state(uint64_t delay_ns)
|
||||
{
|
||||
seq_timer_id = TimerManager::get_instance()->add_oneshot_timer(
|
||||
@@ -315,8 +433,8 @@ void Sc53C94::sequencer()
|
||||
break;
|
||||
case SeqState::SEL_END:
|
||||
if (this->bus_obj->end_selection(this->my_bus_id, this->target_id)) {
|
||||
LOG_F(INFO, "SC53C94: selection completed");
|
||||
this->cmd_steps++;
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_SEL);
|
||||
LOG_F(9, "SC53C94: selection completed");
|
||||
} else { // selection timeout
|
||||
this->seq_step = this->cmd_steps->step_num;
|
||||
this->int_status |= this->cmd_steps->status;
|
||||
@@ -326,6 +444,84 @@ void Sc53C94::sequencer()
|
||||
exec_next_command();
|
||||
}
|
||||
break;
|
||||
case SeqState::SEND_MSG:
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->bytes_out);
|
||||
this->data_fifo_pos -= this->bytes_out;
|
||||
if (this->data_fifo_pos > 0) {
|
||||
std::memmove(this->data_fifo, &this->data_fifo[this->bytes_out], this->data_fifo_pos);
|
||||
}
|
||||
this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_ATN);
|
||||
break;
|
||||
case SeqState::SEND_CMD:
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
|
||||
this->data_fifo_pos = 0;
|
||||
break;
|
||||
case SeqState::CMD_COMPLETE:
|
||||
this->seq_step = this->cmd_steps->step_num;
|
||||
this->int_status |= this->cmd_steps->status;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
case SeqState::XFER_BEGIN:
|
||||
this->cur_bus_phase = this->bus_obj->current_phase();
|
||||
switch (this->cur_bus_phase) {
|
||||
case ScsiPhase::DATA_OUT:
|
||||
if (this->cmd_fifo[0] & 0x80) {
|
||||
this->cur_state = SeqState::SEND_DATA;
|
||||
break;
|
||||
}
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
|
||||
this->data_fifo_pos = 0;
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->cur_state = SeqState::RCV_DATA;
|
||||
this->rcv_data();
|
||||
if (!(this->cmd_fifo[0] & 0x80)) {
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SeqState::XFER_END:
|
||||
if (this->is_initiator) {
|
||||
this->bus_obj->target_next_step();
|
||||
}
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
exec_next_command();
|
||||
break;
|
||||
case SeqState::SEND_DATA:
|
||||
break;
|
||||
case SeqState::RCV_DATA:
|
||||
// check for unexpected bus phase changes
|
||||
if (this->bus_obj->current_phase() != this->cur_bus_phase) {
|
||||
this->cmd_fifo_pos = 0; // clear command FIFO
|
||||
this->int_status |= INTSTAT_SR;
|
||||
this->update_irq();
|
||||
} else {
|
||||
this->rcv_data();
|
||||
}
|
||||
break;
|
||||
case SeqState::RCV_STATUS:
|
||||
case SeqState::RCV_MESSAGE:
|
||||
this->bus_obj->negotiate_xfer(this->data_fifo_pos, this->bytes_out);
|
||||
this->rcv_data();
|
||||
if (this->is_initiator) {
|
||||
if (this->cur_state == SeqState::RCV_STATUS) {
|
||||
this->bus_obj->target_next_step();
|
||||
} else if (this->cur_state == SeqState::RCV_MESSAGE) {
|
||||
this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_ACK);
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ABORT_F("SC53C94: unimplemented sequencer state %d", this->cur_state);
|
||||
}
|
||||
@@ -341,7 +537,7 @@ void Sc53C94::update_irq()
|
||||
}
|
||||
}
|
||||
|
||||
void Sc53C94::notify(ScsiMsg msg_type, int param)
|
||||
void Sc53C94::notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param)
|
||||
{
|
||||
switch (msg_type) {
|
||||
case ScsiMsg::CONFIRM_SEL:
|
||||
@@ -349,12 +545,116 @@ void Sc53C94::notify(ScsiMsg msg_type, int param)
|
||||
// cancel selection timeout timer
|
||||
TimerManager::get_instance()->cancel_timer(this->seq_timer_id);
|
||||
this->cur_state = SeqState::SEL_END;
|
||||
sequencer();
|
||||
this->sequencer();
|
||||
} else {
|
||||
LOG_F(WARNING, "SC53C94: ignore invalid selection confirmation message");
|
||||
}
|
||||
break;
|
||||
case ScsiMsg::BUS_PHASE_CHANGE:
|
||||
if (param != ScsiPhase::BUS_FREE && this->cmd_steps != nullptr) {
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "SC53C94: ignore notification message, type: %d", msg_type);
|
||||
LOG_F(9, "SC53C94: ignore notification message, type: %d", msg_type);
|
||||
}
|
||||
}
|
||||
|
||||
int Sc53C94::send_data(uint8_t* dst_ptr, int count)
|
||||
{
|
||||
if (dst_ptr == nullptr || !count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int actual_count = std::min(this->data_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->data_fifo_pos -= actual_count;
|
||||
if (this->data_fifo_pos > 0) {
|
||||
std::memmove(this->data_fifo, &this->data_fifo[actual_count], this->data_fifo_pos);
|
||||
} else {
|
||||
this->cmd_steps++;
|
||||
this->cur_state = this->cmd_steps->next_step;
|
||||
this->sequencer();
|
||||
}
|
||||
|
||||
return actual_count;
|
||||
}
|
||||
|
||||
bool Sc53C94::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->cmd_fifo[0] & 0x80) && this->cur_bus_phase == ScsiPhase::DATA_IN) {
|
||||
req_count = std::min((int)this->xfer_count, DATA_FIFO_MAX - this->data_fifo_pos);
|
||||
} else {
|
||||
req_count = 1;
|
||||
}
|
||||
|
||||
this->bus_obj->pull_data(this->target_id, &this->data_fifo[this->data_fifo_pos], req_count);
|
||||
this->data_fifo_pos += req_count;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Sc53C94::real_dma_xfer(int direction)
|
||||
{
|
||||
bool is_done = false;
|
||||
|
||||
if (direction) {
|
||||
uint32_t got_bytes;
|
||||
uint8_t* src_ptr;
|
||||
|
||||
while (this->xfer_count) {
|
||||
this->dma_ch->pull_data(std::min((int)this->xfer_count, DATA_FIFO_MAX),
|
||||
&got_bytes, &src_ptr);
|
||||
std::memcpy(this->data_fifo, src_ptr, got_bytes);
|
||||
this->data_fifo_pos = got_bytes;
|
||||
this->bus_obj->push_data(this->target_id, this->data_fifo, this->data_fifo_pos);
|
||||
|
||||
this->xfer_count -= this->data_fifo_pos;
|
||||
this->data_fifo_pos = 0;
|
||||
if (!this->xfer_count) {
|
||||
is_done = true;
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
} else { // transfer data from target to host's memory
|
||||
while (this->xfer_count) {
|
||||
if (this->data_fifo_pos) {
|
||||
this->dma_ch->push_data((char*)this->data_fifo, this->data_fifo_pos);
|
||||
|
||||
this->xfer_count -= this->data_fifo_pos;
|
||||
this->data_fifo_pos = 0;
|
||||
if (!this->xfer_count) {
|
||||
is_done = true;
|
||||
this->status |= STAT_TC; // signal zero transfer count
|
||||
this->cur_state = SeqState::XFER_END;
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
|
||||
// see if we need to refill FIFO
|
||||
if (!this->data_fifo_pos && !is_done) {
|
||||
this->sequencer();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Sc53C94_Descriptor = {
|
||||
Sc53C94::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Sc53C94, Sc53C94_Descriptor);
|
||||
@@ -29,10 +29,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef SC_53C94_H
|
||||
#define SC_53C94_H
|
||||
|
||||
#include "scsi.h"
|
||||
#include "devices/common/hwinterrupt.h"
|
||||
#include <devices/common/dmacore.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
#define DATA_FIFO_MAX 16
|
||||
|
||||
/** 53C94 read registers */
|
||||
namespace Read {
|
||||
@@ -77,13 +81,23 @@ namespace Write {
|
||||
|
||||
/** NCR53C94/Am53CF94 commands. */
|
||||
enum {
|
||||
CMD_NOP = 0,
|
||||
CMD_CLEAR_FIFO = 1,
|
||||
CMD_RESET_DEVICE = 2,
|
||||
CMD_RESET_BUS = 3,
|
||||
CMD_DMA_STOP = 4,
|
||||
CMD_SELECT_NO_ATN = 0x41,
|
||||
CMD_ENA_SEL_RESEL = 0x44,
|
||||
CMD_NOP = 0,
|
||||
CMD_CLEAR_FIFO = 1,
|
||||
CMD_RESET_DEVICE = 2,
|
||||
CMD_RESET_BUS = 3,
|
||||
CMD_DMA_STOP = 4,
|
||||
CMD_XFER = 0x10,
|
||||
CMD_COMPLETE_STEPS = 0x11,
|
||||
CMD_MSG_ACCEPTED = 0x12,
|
||||
CMD_SELECT_NO_ATN = 0x41,
|
||||
CMD_SELECT_WITH_ATN = 0x42,
|
||||
CMD_ENA_SEL_RESEL = 0x44,
|
||||
};
|
||||
|
||||
/** Status register bits. **/
|
||||
enum {
|
||||
STAT_TC = 1 << 4, // Terminal count (NCR) / count to zero (AMD)
|
||||
STAT_GE = 1 << 6, // Gross Error (NCR) / Illegal Operation Error (AMD)
|
||||
};
|
||||
|
||||
/** Interrupt status register bits. */
|
||||
@@ -111,8 +125,15 @@ namespace SeqState {
|
||||
ARB_END,
|
||||
SEL_BEGIN,
|
||||
SEL_END,
|
||||
CMD_BEGIN,
|
||||
SEND_MSG,
|
||||
SEND_CMD,
|
||||
CMD_COMPLETE,
|
||||
XFER_BEGIN,
|
||||
XFER_END,
|
||||
SEND_DATA,
|
||||
RCV_DATA,
|
||||
RCV_STATUS,
|
||||
RCV_MESSAGE,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -128,15 +149,31 @@ public:
|
||||
Sc53C94(uint8_t chip_id=12, uint8_t my_id=7);
|
||||
~Sc53C94() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<Sc53C94>(new Sc53C94());
|
||||
}
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
// 53C94 registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
uint16_t pseudo_dma_read();
|
||||
|
||||
// real DMA control
|
||||
void real_dma_xfer(int direction);
|
||||
|
||||
void set_dma_channel(DmaBidirChannel *dma_ch) {
|
||||
this->dma_ch = dma_ch;
|
||||
};
|
||||
|
||||
// ScsiDevice methods
|
||||
void notify(ScsiMsg msg_type, int param);
|
||||
void notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param);
|
||||
bool prepare_data() { return false; };
|
||||
bool has_data() { return this->data_fifo_pos != 0; };
|
||||
int send_data(uint8_t* dst_ptr, int count);
|
||||
void process_command() {};
|
||||
|
||||
protected:
|
||||
void reset_device();
|
||||
@@ -144,10 +181,13 @@ protected:
|
||||
void exec_command();
|
||||
void exec_next_command();
|
||||
void fifo_push(const uint8_t data);
|
||||
uint8_t fifo_pop();
|
||||
|
||||
void sequencer();
|
||||
void seq_defer_state(uint64_t delay_ns);
|
||||
|
||||
bool rcv_data();
|
||||
|
||||
void update_irq();
|
||||
|
||||
private:
|
||||
@@ -160,6 +200,7 @@ private:
|
||||
uint8_t data_fifo[16];
|
||||
int cmd_fifo_pos;
|
||||
int data_fifo_pos;
|
||||
int bytes_out;
|
||||
bool on_reset = false;
|
||||
uint32_t xfer_count;
|
||||
uint32_t set_xfer_count;
|
||||
@@ -181,11 +222,15 @@ private:
|
||||
SeqDesc* cmd_steps;
|
||||
bool is_initiator;
|
||||
uint8_t cur_cmd;
|
||||
int cur_bus_phase;
|
||||
|
||||
// interrupt related stuff
|
||||
InterruptCtrl* int_ctrl = nullptr;
|
||||
uint32_t irq_id = 0;
|
||||
uint8_t irq = 0;
|
||||
|
||||
// DMA related stuff
|
||||
DmaBidirChannel* dma_ch;
|
||||
};
|
||||
|
||||
#endif // SC_53C94_H
|
||||
+145
-20
@@ -28,6 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <array>
|
||||
#include <cinttypes>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
/** SCSI control signals.
|
||||
@@ -40,22 +41,102 @@ enum {
|
||||
SCSI_CTRL_ATN = 1 << 3,
|
||||
SCSI_CTRL_ACK = 1 << 4,
|
||||
SCSI_CTRL_REQ = 1 << 5,
|
||||
SCSI_CTRL_SEL = 1 << 6,
|
||||
SCSI_CTRL_BSY = 1 << 7,
|
||||
SCSI_CTRL_RST = 1 << 8,
|
||||
SCSI_CTRL_SEL = 1 << 13,
|
||||
SCSI_CTRL_BSY = 1 << 14,
|
||||
SCSI_CTRL_RST = 1 << 15,
|
||||
};
|
||||
|
||||
enum ScsiPhase : int {
|
||||
BUS_FREE = 0,
|
||||
ARBITRATION,
|
||||
SELECTION,
|
||||
RESELECTION,
|
||||
RESET,
|
||||
namespace ScsiPhase {
|
||||
enum : int {
|
||||
BUS_FREE = 0,
|
||||
ARBITRATION,
|
||||
SELECTION,
|
||||
RESELECTION,
|
||||
COMMAND,
|
||||
DATA_IN,
|
||||
DATA_OUT,
|
||||
STATUS,
|
||||
MESSAGE_IN,
|
||||
MESSAGE_OUT,
|
||||
RESET,
|
||||
};
|
||||
};
|
||||
|
||||
namespace ScsiStatus {
|
||||
enum : uint8_t {
|
||||
GOOD = 0,
|
||||
CHECK_CONDITION = 2,
|
||||
};
|
||||
};
|
||||
|
||||
namespace ScsiMessage {
|
||||
enum : uint8_t {
|
||||
COMMAND_COMPLETE = 0,
|
||||
};
|
||||
};
|
||||
|
||||
enum ScsiMsg : int {
|
||||
CONFIRM_SEL = 1,
|
||||
BUS_PHASE_CHANGE,
|
||||
SEND_CMD_BEGIN,
|
||||
SEND_CMD_END,
|
||||
MESSAGE_BEGIN,
|
||||
MESSAGE_END,
|
||||
};
|
||||
|
||||
enum ScsiCommand : int {
|
||||
TEST_UNIT_READY = 0x0,
|
||||
REWIND = 0x1,
|
||||
REQ_SENSE = 0x3,
|
||||
FORMAT = 0x4,
|
||||
READ_BLK_LIMITS = 0x5,
|
||||
READ_6 = 0x8,
|
||||
WRITE_6 = 0xA,
|
||||
SEEK_6 = 0xB,
|
||||
INQUIRY = 0x12,
|
||||
VERIFY_6 = 0x13,
|
||||
MODE_SELECT_6 = 0x15,
|
||||
RELEASE_UNIT = 0x17,
|
||||
ERASE_6 = 0x19,
|
||||
MODE_SENSE_6 = 0x1A,
|
||||
DIAG_RESULTS = 0x1C,
|
||||
SEND_DIAGS = 0x1D,
|
||||
PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
|
||||
READ_CAPACITY_10 = 0x25,
|
||||
READ_10 = 0x28,
|
||||
WRITE_10 = 0x2A,
|
||||
VERIFY_10 = 0x2F,
|
||||
READ_LONG_10 = 0x35,
|
||||
|
||||
// CD-ROM specific commands
|
||||
READ_TOC = 0x43,
|
||||
};
|
||||
|
||||
enum ScsiSense : int {
|
||||
NO_SENSE = 0x0,
|
||||
RECOVERED = 0x1,
|
||||
NOT_READY = 0x2,
|
||||
MEDIUM_ERR = 0x3,
|
||||
HW_ERROR = 0x4,
|
||||
ILLEGAL_REQ = 0x5,
|
||||
UNIT_ATTENTION = 0x6,
|
||||
DATA_PROTECT = 0x7,
|
||||
BLANK_CHECK = 0x8,
|
||||
VOL_OVERFLOW = 0xD,
|
||||
MISCOMPARE = 0xE,
|
||||
COMPLETED = 0xF
|
||||
};
|
||||
|
||||
enum ScsiError : int {
|
||||
NO_ERROR = 0x0,
|
||||
NO_SECTOR = 0x1,
|
||||
WRITE_FAULT = 0x3,
|
||||
DEV_NOT_READY = 0x4,
|
||||
INVALID_CMD = 0x20,
|
||||
INVALID_LBA = 0x21,
|
||||
INVALID_CDB = 0x24,
|
||||
INVALID_LUN = 0x25,
|
||||
WRITE_PROTECT = 0x27
|
||||
};
|
||||
|
||||
/** Standard SCSI bus timing values measured in ns. */
|
||||
@@ -68,15 +149,46 @@ enum ScsiMsg : int {
|
||||
|
||||
#define SCSI_MAX_DEVS 8
|
||||
|
||||
class ScsiBus;
|
||||
|
||||
typedef std::function<void()> action_callback;
|
||||
|
||||
class ScsiDevice : public HWComponent {
|
||||
public:
|
||||
ScsiDevice() = default;
|
||||
ScsiDevice(int my_id) {
|
||||
this->scsi_id = my_id;
|
||||
this->cur_phase = ScsiPhase::BUS_FREE;
|
||||
};
|
||||
~ScsiDevice() = default;
|
||||
|
||||
virtual void notify(ScsiMsg msg_type, int param) = 0;
|
||||
virtual void notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param);
|
||||
virtual void next_step(ScsiBus* bus_obj);
|
||||
virtual void prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out);
|
||||
virtual void switch_phase(const int new_phase);
|
||||
|
||||
private:
|
||||
int scsi_id;
|
||||
virtual bool has_data() { return this->data_size != 0; };
|
||||
virtual int send_data(uint8_t* dst_ptr, int count);
|
||||
virtual int rcv_data(const uint8_t* src_ptr, const int count);
|
||||
|
||||
virtual bool prepare_data() = 0;
|
||||
virtual void process_command() = 0;
|
||||
|
||||
protected:
|
||||
uint8_t cmd_buf[16] = {};
|
||||
uint8_t msg_buf[16] = {}; // TODO: clarify how big this one should be
|
||||
int scsi_id;
|
||||
int initiator_id;
|
||||
int cur_phase;
|
||||
uint8_t* data_ptr = nullptr;
|
||||
int data_size;
|
||||
int incoming_size;
|
||||
uint8_t status;
|
||||
int sense;
|
||||
|
||||
ScsiBus* bus_obj;
|
||||
|
||||
action_callback pre_xfer_action = nullptr;
|
||||
action_callback post_xfer_action = nullptr;
|
||||
};
|
||||
|
||||
/** This class provides a higher level abstraction for the SCSI bus. */
|
||||
@@ -85,20 +197,33 @@ public:
|
||||
ScsiBus();
|
||||
~ScsiBus() = default;
|
||||
|
||||
// low-level control/status
|
||||
void register_device(int id, ScsiDevice* dev_obj);
|
||||
void assert_ctrl_line(int id, uint16_t mask);
|
||||
void release_ctrl_line(int id, uint16_t mask);
|
||||
void release_ctrl_lines(int id);
|
||||
int current_phase() { return this->cur_phase; };
|
||||
// low-level state management
|
||||
void register_device(int id, ScsiDevice* dev_obj);
|
||||
int current_phase() { return this->cur_phase; };
|
||||
int get_initiator_id() { return this->initiator_id; };
|
||||
int get_target_id() { return this->target_id; };
|
||||
|
||||
// reading/writing control lines
|
||||
void assert_ctrl_line(int id, uint16_t mask);
|
||||
void release_ctrl_line(int id, uint16_t mask);
|
||||
void release_ctrl_lines(int id);
|
||||
uint16_t test_ctrl_lines(uint16_t mask);
|
||||
|
||||
// reading/writing data lines
|
||||
uint8_t get_data_lines() { return this->data_lines; };
|
||||
|
||||
// high-level control/status
|
||||
int switch_phase(int id, int new_phase);
|
||||
bool begin_arbitration(int id);
|
||||
bool end_arbitration(int id);
|
||||
bool begin_selection(int initiator_id, int target_id, bool atn);
|
||||
void confirm_selection(int target_id);
|
||||
bool end_selection(int initiator_id, int target_id);
|
||||
void disconnect(int dev_id);
|
||||
bool pull_data(const int id, uint8_t* dst_ptr, const int size);
|
||||
bool push_data(const int id, const uint8_t* src_ptr, const int size);
|
||||
void target_next_step();
|
||||
bool negotiate_xfer(int& bytes_in, int& bytes_out);
|
||||
|
||||
protected:
|
||||
void change_bus_phase(int initiator_id);
|
||||
@@ -110,7 +235,7 @@ private:
|
||||
std::array<ScsiDevice*, SCSI_MAX_DEVS> devices;
|
||||
|
||||
// per-device state of the control lines
|
||||
uint16_t dev_ctrl_lines[SCSI_MAX_DEVS];
|
||||
uint16_t dev_ctrl_lines[SCSI_MAX_DEVS] = {};
|
||||
|
||||
uint16_t ctrl_lines;
|
||||
int cur_phase;
|
||||
|
||||
@@ -36,11 +36,11 @@ ScsiBus::ScsiBus()
|
||||
this->dev_ctrl_lines[i] = 0;
|
||||
}
|
||||
|
||||
this->ctrl_lines = 0; // all control lines released
|
||||
this->data_lines = 0; // data lines released
|
||||
this->ctrl_lines = 0; // all control lines released
|
||||
this->data_lines = 0; // data lines released
|
||||
this->arb_winner_id = -1;
|
||||
this->initiator_id = -1;
|
||||
this->target_id = -1;
|
||||
this->initiator_id = -1;
|
||||
this->target_id = -1;
|
||||
}
|
||||
|
||||
void ScsiBus::register_device(int id, ScsiDevice* dev_obj)
|
||||
@@ -58,7 +58,7 @@ void ScsiBus::change_bus_phase(int initiator_id)
|
||||
if (i == initiator_id)
|
||||
continue; // don't notify the initiator
|
||||
if (this->devices[i] != nullptr) {
|
||||
this->devices[i]->notify(ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
|
||||
this->devices[i]->notify(this, ScsiMsg::BUS_PHASE_CHANGE, this->cur_phase);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,15 +67,14 @@ void ScsiBus::assert_ctrl_line(int initiator_id, uint16_t mask)
|
||||
{
|
||||
uint16_t new_state = 0xFFFFU & mask;
|
||||
|
||||
this->dev_ctrl_lines[initiator_id] = new_state;
|
||||
this->dev_ctrl_lines[initiator_id] |= new_state;
|
||||
|
||||
if (new_state == this->ctrl_lines) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->ctrl_lines = new_state;
|
||||
|
||||
if (new_state & SCSI_CTRL_RST) {
|
||||
this->ctrl_lines |= SCSI_CTRL_RST;
|
||||
this->cur_phase = ScsiPhase::RESET;
|
||||
change_bus_phase(initiator_id);
|
||||
}
|
||||
@@ -98,6 +97,8 @@ void ScsiBus::release_ctrl_line(int id, uint16_t mask)
|
||||
this->cur_phase = ScsiPhase::BUS_FREE;
|
||||
change_bus_phase(id);
|
||||
}
|
||||
} else {
|
||||
this->ctrl_lines = new_state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +107,61 @@ void ScsiBus::release_ctrl_lines(int id)
|
||||
this->release_ctrl_line(id, 0xFFFFUL);
|
||||
}
|
||||
|
||||
uint16_t ScsiBus::test_ctrl_lines(uint16_t mask)
|
||||
{
|
||||
uint16_t new_state = 0;
|
||||
|
||||
// OR control lines of all devices together
|
||||
for (int i = 0; i < SCSI_MAX_DEVS; i++) {
|
||||
new_state |= this->dev_ctrl_lines[i];
|
||||
}
|
||||
|
||||
return new_state & mask;
|
||||
}
|
||||
|
||||
int ScsiBus::switch_phase(int id, int new_phase)
|
||||
{
|
||||
int old_phase = this->cur_phase;
|
||||
|
||||
// leave the current phase (low-level)
|
||||
switch (old_phase) {
|
||||
case ScsiPhase::COMMAND:
|
||||
this->release_ctrl_line(id, SCSI_CTRL_CD);
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->release_ctrl_line(id, SCSI_CTRL_IO);
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->release_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_IO);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
this->release_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_MSG);
|
||||
break;
|
||||
}
|
||||
|
||||
// enter new phase (low-level)
|
||||
switch (new_phase) {
|
||||
case ScsiPhase::COMMAND:
|
||||
this->assert_ctrl_line(id, SCSI_CTRL_CD);
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->assert_ctrl_line(id, SCSI_CTRL_IO);
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->assert_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_IO);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
this->assert_ctrl_line(id, SCSI_CTRL_CD | SCSI_CTRL_MSG);
|
||||
break;
|
||||
}
|
||||
|
||||
// switch the bus to the new phase (high-level)
|
||||
this->cur_phase = new_phase;
|
||||
change_bus_phase(id);
|
||||
|
||||
return old_phase;
|
||||
}
|
||||
|
||||
bool ScsiBus::begin_arbitration(int initiator_id)
|
||||
{
|
||||
if (this->cur_phase == ScsiPhase::BUS_FREE) {
|
||||
@@ -143,7 +199,9 @@ bool ScsiBus::begin_selection(int initiator_id, int target_id, bool atn)
|
||||
if (this->cur_phase != ScsiPhase::ARBITRATION || this->arb_winner_id != initiator_id)
|
||||
return false;
|
||||
|
||||
this->data_lines |= (1 << initiator_id) | (1 << target_id);
|
||||
this->assert_ctrl_line(initiator_id, SCSI_CTRL_SEL);
|
||||
|
||||
this->data_lines = (1 << initiator_id) | (1 << target_id);
|
||||
|
||||
if (atn) {
|
||||
assert_ctrl_line(initiator_id, SCSI_CTRL_ATN);
|
||||
@@ -161,7 +219,7 @@ void ScsiBus::confirm_selection(int target_id)
|
||||
|
||||
// notify initiator about selection confirmation from target
|
||||
if (this->initiator_id >= 0) {
|
||||
this->devices[this->initiator_id]->notify(ScsiMsg::CONFIRM_SEL, target_id);
|
||||
this->devices[this->initiator_id]->notify(this, ScsiMsg::CONFIRM_SEL, target_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,6 +229,42 @@ bool ScsiBus::end_selection(int initiator_id, int target_id)
|
||||
return this->target_id == target_id;
|
||||
}
|
||||
|
||||
bool ScsiBus::pull_data(const int id, uint8_t* dst_ptr, const int size)
|
||||
{
|
||||
if (dst_ptr == nullptr || !size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->devices[id]->send_data(dst_ptr, size)) {
|
||||
LOG_F(ERROR, "ScsiBus: error while transferring T->I data!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScsiBus::push_data(const int id, const uint8_t* src_ptr, const int size)
|
||||
{
|
||||
if (!this->devices[id]->rcv_data(src_ptr, size)) {
|
||||
LOG_F(ERROR, "ScsiBus: error while transferring I->T data!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiBus::target_next_step()
|
||||
{
|
||||
this->devices[this->target_id]->next_step(this);
|
||||
}
|
||||
|
||||
bool ScsiBus::negotiate_xfer(int& bytes_in, int& bytes_out)
|
||||
{
|
||||
this->devices[this->target_id]->prepare_xfer(this, bytes_in, bytes_out);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiBus::disconnect(int dev_id)
|
||||
{
|
||||
this->release_ctrl_lines(dev_id);
|
||||
|
||||
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 CD-ROM emulation. */
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/scsi/scsicdrom.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static char cdrom_vendor_sony_id[] = "SONY ";
|
||||
static char cdu8003a_product_id[] = "CD-ROM CDU-8003A";
|
||||
static char cdu8003a_revision_id[] = "1.9a";
|
||||
|
||||
ScsiCdrom::ScsiCdrom(int my_id) : ScsiDevice(my_id)
|
||||
{
|
||||
supports_types(HWCompType::SCSI_DEV);
|
||||
|
||||
this->sector_size = 2048;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
}
|
||||
|
||||
void ScsiCdrom::insert_image(std::string filename)
|
||||
{
|
||||
this->cdr_img.open(filename, ios::out | ios::in | ios::binary);
|
||||
|
||||
struct stat stat_buf;
|
||||
int rc = stat(filename.c_str(), &stat_buf);
|
||||
if (!rc) {
|
||||
this->img_size = stat_buf.st_size;
|
||||
this->total_frames = (this->img_size + this->sector_size - 1) / this->sector_size;
|
||||
|
||||
// create single track descriptor
|
||||
this->tracks[0] = {.trk_num = 1, .adr_ctrl = 0x14, .start_lba = 0};
|
||||
this->num_tracks = 1;
|
||||
|
||||
// create Lead-out descriptor containing all data
|
||||
this->tracks[1] = {.trk_num = LEAD_OUT_TRK_NUM, .adr_ctrl = 0x14,
|
||||
.start_lba = static_cast<uint32_t>(this->total_frames)};
|
||||
} else {
|
||||
ABORT_F("SCSI-CDROM: could not determine file size using stat()");
|
||||
}
|
||||
this->cdr_img.seekg(0, std::ios_base::beg);
|
||||
}
|
||||
|
||||
void ScsiCdrom::process_command()
|
||||
{
|
||||
uint32_t lba, xfer_len;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
|
||||
// assume successful command execution
|
||||
this->status = ScsiStatus::GOOD;
|
||||
|
||||
switch (cmd_buf[0]) {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd_buf[1] & 0x1F) << 16) + (cmd_buf[2] << 8) + cmd_buf[3];
|
||||
this->read(lba, cmd_buf[4], 6);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
this->inquiry();
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
this->incoming_size = this->cmd_buf[4];
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
this->mode_sense();
|
||||
break;
|
||||
case ScsiCommand::PREVENT_ALLOW_MEDIUM_REMOVAL:
|
||||
this->eject_allowed = (this->cmd_buf[4] & 1) == 0;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
this->read_capacity();
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
|
||||
xfer_len = READ_WORD_BE_U(&this->cmd_buf[7]);
|
||||
if (this->cmd_buf[1] & 1) {
|
||||
ABORT_F("SCSI-CDROM: RelAdr bit set in READ_10");
|
||||
}
|
||||
read(lba, xfer_len, 10);
|
||||
break;
|
||||
case ScsiCommand::READ_TOC:
|
||||
this->read_toc();
|
||||
break;
|
||||
default:
|
||||
ABORT_F("SCSI_CDROM: unsupported command %d", this->cmd_buf[0]);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiCdrom::prepare_data()
|
||||
{
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_size = this->bytes_out;
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
this->data_ptr = (uint8_t*)this->data_buf;
|
||||
this->data_size = 0;
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "SCSI_CDROM: unexpected phase in prepare_data");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScsiCdrom::read(const uint32_t lba, const uint16_t transfer_len, const uint8_t cmd_len)
|
||||
{
|
||||
uint32_t transfer_size = transfer_len;
|
||||
|
||||
std::memset(this->data_buf, 0, sizeof(this->data_buf));
|
||||
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= this->sector_size;
|
||||
uint64_t device_offset = lba * this->sector_size;
|
||||
|
||||
this->cdr_img.seekg(device_offset, this->cdr_img.beg);
|
||||
this->cdr_img.read(this->data_buf, transfer_size);
|
||||
|
||||
this->bytes_out = transfer_size;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
void ScsiCdrom::inquiry()
|
||||
{
|
||||
int page_num = cmd_buf[2];
|
||||
int alloc_len = cmd_buf[4];
|
||||
|
||||
if (page_num) {
|
||||
ABORT_F("SCSI_CDROM: invalid page number in INQUIRY");
|
||||
}
|
||||
|
||||
if (alloc_len > 36) {
|
||||
LOG_F(WARNING, "SCSI_CDROM: more than 36 bytes requested in INQUIRY");
|
||||
}
|
||||
|
||||
this->data_buf[0] = 5; // device type: CD-ROM
|
||||
this->data_buf[1] = 0x80; // removable media
|
||||
this->data_buf[2] = 2; // ANSI version: SCSI-2
|
||||
this->data_buf[3] = 1; // response data format
|
||||
this->data_buf[4] = 0x1F; // additional length
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = 0;
|
||||
this->data_buf[7] = 0x18; // supports synchronous xfers and linked commands
|
||||
std::memcpy(&this->data_buf[8], cdrom_vendor_sony_id, 8);
|
||||
std::memcpy(&this->data_buf[16], cdu8003a_product_id, 16);
|
||||
std::memcpy(&this->data_buf[32], cdu8003a_revision_id, 4);
|
||||
|
||||
this->bytes_out = 36;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
static char Apple_Copyright_Page_Data[] = "APPLE COMPUTER, INC ";
|
||||
|
||||
void ScsiCdrom::mode_sense()
|
||||
{
|
||||
uint8_t page_code = this->cmd_buf[2] & 0x3F;
|
||||
uint8_t alloc_len = this->cmd_buf[4];
|
||||
|
||||
int num_blocks = (this->img_size + this->sector_size) / this->sector_size;
|
||||
|
||||
this->data_buf[ 0] = 13; // initial data size
|
||||
this->data_buf[ 1] = 0; // medium type
|
||||
this->data_buf[ 2] = 0x80; // medium is write protected
|
||||
this->data_buf[ 3] = 8; // block description length
|
||||
|
||||
this->data_buf[ 4] = 0; // density code
|
||||
this->data_buf[ 5] = (num_blocks >> 16) & 0xFFU;
|
||||
this->data_buf[ 6] = (num_blocks >> 8) & 0xFFU;
|
||||
this->data_buf[ 7] = (num_blocks ) & 0xFFU;
|
||||
this->data_buf[ 8] = 0;
|
||||
this->data_buf[ 9] = 0;
|
||||
this->data_buf[10] = (this->sector_size >> 8) & 0xFFU;
|
||||
this->data_buf[11] = (this->sector_size ) & 0xFFU;
|
||||
|
||||
this->data_buf[12] = page_code;
|
||||
|
||||
switch (page_code) {
|
||||
case 0x01:
|
||||
this->data_buf[13] = 6; // data size
|
||||
std::memset(&this->data_buf[14], 0, 6);
|
||||
this->data_buf[0] += 7;
|
||||
break;
|
||||
case 0x30:
|
||||
this->data_buf[13] = 22; // data size
|
||||
std::memcpy(&this->data_buf[14], Apple_Copyright_Page_Data, 22);
|
||||
this->data_buf[0] += 23;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("SCSI-HD: unsupported page %d in MODE_SENSE_6", page_code);
|
||||
}
|
||||
|
||||
this->bytes_out = this->data_buf[0];
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
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("SCSI-CDROM: unsupported format in READ_TOC");
|
||||
}
|
||||
|
||||
if (!alloc_len) {
|
||||
LOG_F(WARNING, "SCSI-CDROM: zero allocation length passed to READ_TOC");
|
||||
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, "SCSI-CDROM: invalid starting track %d in READ_TOC", start_track);
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
char* 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()
|
||||
{
|
||||
uint32_t lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
|
||||
|
||||
if (this->cmd_buf[1] & 1) {
|
||||
ABORT_F("SCSI-CDROM: RelAdr bit set in READ_CAPACITY_10");
|
||||
}
|
||||
|
||||
if (!(this->cmd_buf[8] & 1) && lba) {
|
||||
LOG_F(ERROR, "SCSI-CDROM: non-zero LBA for PMI=0");
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
int last_lba = this->total_frames - 1;
|
||||
|
||||
this->data_buf[0] = (last_lba >> 24) & 0xFFU;
|
||||
this->data_buf[1] = (last_lba >> 16) & 0xFFU;
|
||||
this->data_buf[2] = (last_lba >> 8) & 0xFFU;
|
||||
this->data_buf[3] = (last_lba >> 0) & 0xFFU;
|
||||
this->data_buf[4] = 0;
|
||||
this->data_buf[5] = 0;
|
||||
this->data_buf[6] = (this->sector_size >> 8) & 0xFFU;
|
||||
this->data_buf[7] = this->sector_size & 0xFFU;
|
||||
|
||||
this->bytes_out = 8;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
AddrMsf ScsiCdrom::lba_to_msf(const int lba)
|
||||
{
|
||||
return {.min = lba / 4500, .sec = (lba / 75) % 60, .frm = lba % 75};
|
||||
}
|
||||
|
||||
static const PropMap ScsiCdromProperties = {
|
||||
{"cdr_img", new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription ScsiCdromDescriptor =
|
||||
{ScsiCdrom::create, {}, ScsiCdromProperties};
|
||||
|
||||
REGISTER_DEVICE(ScsiCdrom, ScsiCdromDescriptor);
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 CD-ROM definitions. */
|
||||
|
||||
#ifndef SCSI_CDROM_H
|
||||
#define SCSI_CDROM_H
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/* Original CD-ROM addressing mode expressed
|
||||
in minutes, seconds and frames */
|
||||
typedef struct {
|
||||
int min;
|
||||
int sec;
|
||||
int frm;
|
||||
} AddrMsf;
|
||||
|
||||
/* Descriptor for CD-ROM tracks in TOC */
|
||||
typedef struct {
|
||||
uint8_t trk_num;
|
||||
uint8_t adr_ctrl;
|
||||
uint32_t start_lba;
|
||||
} TrackDescriptor;
|
||||
|
||||
#define CDROM_MAX_TRACKS 100
|
||||
#define LEAD_OUT_TRK_NUM 0xAA
|
||||
|
||||
class ScsiCdrom : public ScsiDevice {
|
||||
public:
|
||||
ScsiCdrom(int my_id);
|
||||
~ScsiCdrom() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<ScsiCdrom>(new ScsiCdrom(3));
|
||||
}
|
||||
|
||||
void insert_image(std::string filename);
|
||||
|
||||
virtual void process_command();
|
||||
virtual bool prepare_data();
|
||||
|
||||
protected:
|
||||
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
void inquiry();
|
||||
void mode_sense();
|
||||
void read_toc();
|
||||
void read_capacity();
|
||||
|
||||
private:
|
||||
AddrMsf lba_to_msf(const int lba);
|
||||
|
||||
private:
|
||||
std::fstream cdr_img;
|
||||
uint64_t img_size;
|
||||
int total_frames;
|
||||
int num_tracks;
|
||||
int sector_size;
|
||||
bool eject_allowed = true;
|
||||
int bytes_out = 0;
|
||||
TrackDescriptor tracks[CDROM_MAX_TRACKS];
|
||||
|
||||
char data_buf[1 << 18]; // TODO: proper buffer management
|
||||
};
|
||||
|
||||
#endif // SCSI_CDROM_H
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
void ScsiDevice::notify(ScsiBus* bus_obj, ScsiMsg msg_type, int param)
|
||||
{
|
||||
if (msg_type == ScsiMsg::BUS_PHASE_CHANGE) {
|
||||
switch (param) {
|
||||
case ScsiPhase::RESET:
|
||||
LOG_F(9, "ScsiDevice %d: bus reset aknowledged", this->scsi_id);
|
||||
break;
|
||||
case ScsiPhase::SELECTION:
|
||||
// check if something tries to select us
|
||||
if (bus_obj->get_data_lines() & (1 << scsi_id)) {
|
||||
LOG_F(9, "ScsiDevice %d selected", this->scsi_id);
|
||||
TimerManager::get_instance()->add_oneshot_timer(
|
||||
BUS_SETTLE_DELAY,
|
||||
[this, bus_obj]() {
|
||||
// don't confirm selection if BSY or I/O are asserted
|
||||
if (bus_obj->test_ctrl_lines(SCSI_CTRL_BSY | SCSI_CTRL_IO))
|
||||
return;
|
||||
bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_BSY);
|
||||
bus_obj->confirm_selection(this->scsi_id);
|
||||
this->initiator_id = bus_obj->get_initiator_id();
|
||||
this->bus_obj = bus_obj;
|
||||
if (bus_obj->test_ctrl_lines(SCSI_CTRL_ATN)) {
|
||||
this->switch_phase(ScsiPhase::MESSAGE_OUT);
|
||||
if (this->msg_buf[0] != 0x80) {
|
||||
LOG_F(INFO, "ScsiDevice: received message 0x%X", this->msg_buf[0]);
|
||||
}
|
||||
}
|
||||
this->switch_phase(ScsiPhase::COMMAND);
|
||||
this->process_command();
|
||||
if (this->prepare_data()) {
|
||||
bus_obj->assert_ctrl_line(this->scsi_id, SCSI_CTRL_REQ);
|
||||
} else {
|
||||
ABORT_F("ScsiDevice: prepare_data() failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiDevice::switch_phase(const int new_phase)
|
||||
{
|
||||
this->cur_phase = new_phase;
|
||||
this->bus_obj->switch_phase(this->scsi_id, this->cur_phase);
|
||||
}
|
||||
|
||||
void ScsiDevice::next_step(ScsiBus* bus_obj)
|
||||
{
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::COMMAND:
|
||||
this->process_command();
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
if (this->data_size >= this->incoming_size) {
|
||||
if (this->post_xfer_action != nullptr) {
|
||||
this->post_xfer_action();
|
||||
}
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
if (!this->has_data()) {
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
}
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->switch_phase(ScsiPhase::MESSAGE_IN);
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
case ScsiPhase::BUS_FREE:
|
||||
bus_obj->release_ctrl_lines(this->scsi_id);
|
||||
this->switch_phase(ScsiPhase::BUS_FREE);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "ScsiDevice: nothing to do for phase %d", this->cur_phase);
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiDevice::prepare_xfer(ScsiBus* bus_obj, int& bytes_in, int& bytes_out)
|
||||
{
|
||||
this->cur_phase = bus_obj->current_phase();
|
||||
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::COMMAND:
|
||||
this->data_ptr = this->cmd_buf;
|
||||
this->data_size = bytes_in;
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
this->data_ptr = &this->status;
|
||||
this->data_size = 1;
|
||||
bytes_out = 1;
|
||||
break;
|
||||
case ScsiPhase::DATA_IN:
|
||||
bytes_out = this->data_size;
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_OUT:
|
||||
this->data_ptr = this->msg_buf;
|
||||
this->data_size = bytes_in;
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->data_ptr = this->msg_buf;
|
||||
this->data_size = 1;
|
||||
bytes_out = 1;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("ScsiDevice: unhandled phase %d in prepare_xfer()", this->cur_phase);
|
||||
}
|
||||
}
|
||||
|
||||
int ScsiDevice::send_data(uint8_t* dst_ptr, const int count)
|
||||
{
|
||||
if (dst_ptr == nullptr || !count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int actual_count = std::min(this->data_size, count);
|
||||
|
||||
std::memcpy(dst_ptr, this->data_ptr, actual_count);
|
||||
this->data_ptr += actual_count;
|
||||
this->data_size -= actual_count;
|
||||
|
||||
return actual_count;
|
||||
}
|
||||
|
||||
int ScsiDevice::rcv_data(const uint8_t* src_ptr, const int count)
|
||||
{
|
||||
// accumulating incoming data in the pre-configured buffer
|
||||
std::memcpy(this->data_ptr, src_ptr, count);
|
||||
this->data_ptr += count;
|
||||
this->data_size += count;
|
||||
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Generic SCSI Hard Disk emulation. */
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/common/scsi/scsihd.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define HDD_SECTOR_SIZE 512
|
||||
|
||||
using namespace std;
|
||||
|
||||
ScsiHardDisk::ScsiHardDisk(int my_id) : ScsiDevice(my_id) {
|
||||
supports_types(HWCompType::SCSI_DEV);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::insert_image(std::string filename) {
|
||||
//We don't want to store everything in memory, but
|
||||
//we want to keep the hard disk available.
|
||||
this->hdd_img.open(filename, ios::out | ios::in | ios::binary);
|
||||
|
||||
struct stat stat_buf;
|
||||
int rc = stat(filename.c_str(), &stat_buf);
|
||||
if (!rc) {
|
||||
this->img_size = stat_buf.st_size;
|
||||
this->total_blocks = (this->img_size + HDD_SECTOR_SIZE - 1) / HDD_SECTOR_SIZE;
|
||||
} else {
|
||||
ABORT_F("ScsiHardDisk: could not determine file size using stat()");
|
||||
}
|
||||
this->hdd_img.seekg(0, std::ios_base::beg);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::process_command() {
|
||||
uint32_t lba = 0;
|
||||
uint16_t transfer_len = 0;
|
||||
uint16_t alloc_len = 0;
|
||||
uint8_t param_len = 0;
|
||||
|
||||
uint8_t page_code = 0;
|
||||
uint8_t subpage_code = 0;
|
||||
|
||||
this->pre_xfer_action = nullptr;
|
||||
this->post_xfer_action = nullptr;
|
||||
|
||||
// assume successful command execution
|
||||
this->status = ScsiStatus::GOOD;
|
||||
|
||||
uint8_t* cmd = this->cmd_buf;
|
||||
|
||||
if (cmd[0] != 0 && cmd[0] != 8 && cmd[0] != 0xA && cmd[0] != 0x28
|
||||
&& cmd[0] != 0x2A && cmd[0] != 0x25) {
|
||||
ABORT_F("SCSI-HD: untested command 0x%X", cmd[0]);
|
||||
}
|
||||
|
||||
switch (cmd[0]) {
|
||||
case ScsiCommand::TEST_UNIT_READY:
|
||||
test_unit_ready();
|
||||
break;
|
||||
case ScsiCommand::REWIND:
|
||||
rewind();
|
||||
break;
|
||||
case ScsiCommand::REQ_SENSE:
|
||||
alloc_len = cmd[4];
|
||||
req_sense(alloc_len);
|
||||
break;
|
||||
case ScsiCommand::INQUIRY:
|
||||
alloc_len = (cmd[3] << 8) + cmd[4];
|
||||
inquiry(alloc_len);
|
||||
break;
|
||||
case ScsiCommand::READ_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
transfer_len = cmd[4];
|
||||
read(lba, transfer_len, 6);
|
||||
break;
|
||||
case ScsiCommand::READ_10:
|
||||
lba = (cmd[2] << 24) + (cmd[3] << 16) + (cmd[4] << 8) + cmd[5];
|
||||
transfer_len = (cmd[7] << 8) + cmd[8];
|
||||
read(lba, transfer_len, 10);
|
||||
break;
|
||||
case ScsiCommand::WRITE_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
transfer_len = cmd[4];
|
||||
write(lba, transfer_len, 6);
|
||||
break;
|
||||
case ScsiCommand::WRITE_10:
|
||||
lba = (cmd[2] << 24) + (cmd[3] << 16) + (cmd[4] << 8) + cmd[5];
|
||||
transfer_len = (cmd[7] << 8) + cmd[8];
|
||||
write(lba, transfer_len, 10);
|
||||
this->switch_phase(ScsiPhase::DATA_OUT);
|
||||
break;
|
||||
case ScsiCommand::SEEK_6:
|
||||
lba = ((cmd[1] & 0x1F) << 16) + (cmd[2] << 8) + cmd[3];
|
||||
seek(lba);
|
||||
break;
|
||||
case ScsiCommand::MODE_SELECT_6:
|
||||
param_len = cmd[4];
|
||||
mode_select_6(param_len);
|
||||
break;
|
||||
case ScsiCommand::MODE_SENSE_6:
|
||||
page_code = cmd[2] & 0x1F;
|
||||
subpage_code = cmd[3];
|
||||
alloc_len = cmd[4];
|
||||
mode_sense_6(page_code, subpage_code, alloc_len);
|
||||
break;
|
||||
case ScsiCommand::READ_CAPACITY_10:
|
||||
read_capacity_10();
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "SCSI_HD: unrecognized command: %x", cmd[0]);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScsiHardDisk::prepare_data() {
|
||||
switch (this->cur_phase) {
|
||||
case ScsiPhase::DATA_IN:
|
||||
this->data_ptr = (uint8_t*)this->img_buffer;
|
||||
this->data_size = this->cur_buf_cnt;
|
||||
break;
|
||||
case ScsiPhase::DATA_OUT:
|
||||
this->data_ptr = (uint8_t*)this->img_buffer;
|
||||
this->data_size = 0;
|
||||
break;
|
||||
case ScsiPhase::STATUS:
|
||||
if (!error) {
|
||||
this->img_buffer[0] = ScsiStatus::GOOD;
|
||||
} else {
|
||||
this->img_buffer[0] = ScsiStatus::CHECK_CONDITION;
|
||||
}
|
||||
this->cur_buf_cnt = 1;
|
||||
break;
|
||||
case ScsiPhase::MESSAGE_IN:
|
||||
this->img_buffer[0] = this->msg_code;
|
||||
this->cur_buf_cnt = 1;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "SCSI_HD: unexpected phase in prepare_data");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int ScsiHardDisk::test_unit_ready() {
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return ScsiError::NO_ERROR;
|
||||
}
|
||||
|
||||
int ScsiHardDisk::req_sense(uint16_t alloc_len) {
|
||||
if (alloc_len != 252) {
|
||||
LOG_F(WARNING, "Inappropriate Allocation Length: %d", alloc_len);
|
||||
}
|
||||
return ScsiError::NO_ERROR; // placeholder - no sense
|
||||
}
|
||||
|
||||
void ScsiHardDisk::inquiry(uint16_t alloc_len) {
|
||||
if (alloc_len >= 48) {
|
||||
uint8_t empty_filler[1 << 17] = {0x0};
|
||||
std::memcpy(img_buffer, empty_filler, (1 << 17));
|
||||
img_buffer[2] = 0x1;
|
||||
img_buffer[3] = 0x2;
|
||||
img_buffer[4] = 0x31;
|
||||
img_buffer[7] = 0x1C;
|
||||
std::memcpy(img_buffer + 8, vendor_info, 8);
|
||||
std::memcpy(img_buffer + 16, prod_info, 16);
|
||||
std::memcpy(img_buffer + 32, rev_info, 8);
|
||||
std::memcpy(img_buffer + 40, serial_info, 8);
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "Inappropriate Allocation Length: %d", alloc_len);
|
||||
}
|
||||
}
|
||||
|
||||
int ScsiHardDisk::send_diagnostic() {
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
int ScsiHardDisk::mode_select_6(uint8_t param_len) {
|
||||
if (param_len == 0) {
|
||||
return 0x0;
|
||||
}
|
||||
else {
|
||||
LOG_F(WARNING, "Mode Select calling for param length of: %d", param_len);
|
||||
return param_len;
|
||||
}
|
||||
}
|
||||
|
||||
void ScsiHardDisk::mode_sense_6(uint8_t page_code, uint8_t subpage_code, uint8_t alloc_len) {
|
||||
LOG_F(WARNING, "Page Code %d; Subpage Code: %d", page_code, subpage_code);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read_capacity_10() {
|
||||
uint32_t lba = READ_DWORD_BE_U(&this->cmd_buf[2]);
|
||||
|
||||
if (this->cmd_buf[1] & 1) {
|
||||
ABORT_F("SCSI-HD: RelAdr bit set in READ_CAPACITY_10");
|
||||
}
|
||||
|
||||
if (!(this->cmd_buf[8] & 1) && lba) {
|
||||
LOG_F(ERROR, "SCSI-HD: non-zero LBA for PMI=0");
|
||||
this->status = ScsiStatus::CHECK_CONDITION;
|
||||
this->sense = ScsiSense::ILLEGAL_REQ;
|
||||
this->switch_phase(ScsiPhase::STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t last_lba = this->total_blocks - 1;
|
||||
uint32_t blk_len = HDD_SECTOR_SIZE;
|
||||
|
||||
WRITE_DWORD_BE_A(&img_buffer[0], last_lba);
|
||||
WRITE_DWORD_BE_A(&img_buffer[4], blk_len);
|
||||
|
||||
this->cur_buf_cnt = 8;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
|
||||
void ScsiHardDisk::format() {
|
||||
}
|
||||
|
||||
void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
uint32_t transfer_size = transfer_len;
|
||||
|
||||
std::memset(img_buffer, 0, sizeof(img_buffer));
|
||||
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= HDD_SECTOR_SIZE;
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
this->hdd_img.read(img_buffer, transfer_size);
|
||||
|
||||
this->cur_buf_cnt = transfer_size;
|
||||
this->msg_buf[0] = ScsiMessage::COMMAND_COMPLETE;
|
||||
|
||||
this->switch_phase(ScsiPhase::DATA_IN);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) {
|
||||
uint32_t transfer_size = transfer_len;
|
||||
|
||||
if (cmd_len == 6 && transfer_len == 0) {
|
||||
transfer_size = 256;
|
||||
}
|
||||
|
||||
transfer_size *= HDD_SECTOR_SIZE;
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
|
||||
this->incoming_size = transfer_size;
|
||||
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
|
||||
this->post_xfer_action = [this]() {
|
||||
this->hdd_img.write(this->img_buffer, this->incoming_size);
|
||||
};
|
||||
}
|
||||
|
||||
void ScsiHardDisk::seek(uint32_t lba) {
|
||||
uint64_t device_offset = lba * HDD_SECTOR_SIZE;
|
||||
this->hdd_img.seekg(device_offset, this->hdd_img.beg);
|
||||
}
|
||||
|
||||
void ScsiHardDisk::rewind() {
|
||||
this->hdd_img.seekg(0, this->hdd_img.beg);
|
||||
}
|
||||
|
||||
static const PropMap SCSI_HD_Properties = {
|
||||
{"hdd_img", new StrProperty("")},
|
||||
{"hdd_wr_prot", new BinProperty(0)},
|
||||
};
|
||||
|
||||
static const DeviceDescription SCSI_HD_Descriptor =
|
||||
{ScsiHardDisk::create, {}, SCSI_HD_Properties};
|
||||
|
||||
REGISTER_DEVICE(ScsiHD, SCSI_HD_Descriptor);
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 hard drive definitions. */
|
||||
|
||||
#ifndef SCSI_HD_H
|
||||
#define SCSI_HD_H
|
||||
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
class ScsiHardDisk : public ScsiDevice {
|
||||
public:
|
||||
ScsiHardDisk(int my_id);
|
||||
~ScsiHardDisk() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<ScsiHardDisk>(new ScsiHardDisk(0));
|
||||
}
|
||||
|
||||
void insert_image(std::string filename);
|
||||
void process_command();
|
||||
bool prepare_data();
|
||||
|
||||
protected:
|
||||
int test_unit_ready();
|
||||
int req_sense(uint16_t alloc_len);
|
||||
int send_diagnostic();
|
||||
int mode_select_6(uint8_t param_len);
|
||||
|
||||
void mode_sense_6(uint8_t page_code, uint8_t subpage_code, uint8_t alloc_len);
|
||||
void format();
|
||||
void inquiry(uint16_t alloc_len);
|
||||
void read_capacity_10();
|
||||
void read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
void write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len);
|
||||
void seek(uint32_t lba);
|
||||
void rewind();
|
||||
|
||||
private:
|
||||
std::fstream hdd_img;
|
||||
uint64_t img_size;
|
||||
int total_blocks;
|
||||
uint64_t file_offset = 0;
|
||||
|
||||
char img_buffer[1 << 21]; // TODO: add proper buffer management!
|
||||
|
||||
uint32_t cur_buf_cnt = 0;
|
||||
uint8_t error = ScsiError::NO_ERROR;
|
||||
uint8_t msg_code = 0;
|
||||
|
||||
//inquiry info
|
||||
char vendor_info[8] = {'D', 'i', 'n', 'g', 'u', 's', 'D', '\0'};
|
||||
char prod_info[16] = {'E', 'm', 'u', 'l', 'a', 't', 'e', 'd', ' ', 'D', 'i', 's', 'k', '\0'};
|
||||
char rev_info[8] = {'d', 'i', '0', '0', '0', '0', '0', '1'};
|
||||
char serial_info[8] = {'0', '0', '0', '0', '0', '0', '0', '0'};
|
||||
};
|
||||
|
||||
#endif // SCSI_HD_H
|
||||
@@ -26,6 +26,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/common/adb/adb.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <memaccess.h>
|
||||
@@ -61,7 +62,6 @@ ViaCuda::ViaCuda() {
|
||||
|
||||
this->_via_ifr = 0; // all flags cleared
|
||||
this->_via_ier = 0; // all interrupts disabled
|
||||
this->irq = 0; // IRQ is not active
|
||||
|
||||
// intialize counters/timers
|
||||
this->t1_counter = 0xFFFF;
|
||||
@@ -248,11 +248,14 @@ void ViaCuda::print_enabled_ints() {
|
||||
}
|
||||
}
|
||||
|
||||
inline void ViaCuda::update_irq() {
|
||||
uint8_t new_irq = !!(this->_via_ifr & this->_via_ier & 0x7F);
|
||||
this->_via_ifr = (this->_via_ifr & 0x7F) | (new_irq << 7);
|
||||
if (new_irq != this->irq) {
|
||||
this->irq = new_irq;
|
||||
void ViaCuda::update_irq()
|
||||
{
|
||||
uint8_t active_ints = this->_via_ifr & this->_via_ier & 0x7F;
|
||||
if (active_ints != this->old_ifr) {
|
||||
uint8_t new_irq = !!active_ints;
|
||||
this->_via_ifr = (active_ints) | (new_irq << 7);
|
||||
this->old_ifr = active_ints;
|
||||
LOG_F(6, "VIA: assert IRQ, IFR=0x%02X", this->_via_ifr);
|
||||
this->int_ctrl->ack_int(this->irq_id, new_irq);
|
||||
}
|
||||
}
|
||||
@@ -279,6 +282,13 @@ void ViaCuda::assert_t2_int() {
|
||||
update_irq();
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CPU_INT
|
||||
void ViaCuda::assert_int(uint8_t flags) {
|
||||
this->_via_ifr |= (flags & 0x7F);
|
||||
update_irq();
|
||||
}
|
||||
#endif
|
||||
|
||||
void ViaCuda::assert_ctrl_line(ViaLine line)
|
||||
{
|
||||
switch (line) {
|
||||
@@ -434,7 +444,7 @@ void ViaCuda::process_packet() {
|
||||
|
||||
switch (this->in_buf[0]) {
|
||||
case CUDA_PKT_ADB:
|
||||
LOG_F(9, "Cuda: ADB packet received \n");
|
||||
LOG_F(9, "Cuda: ADB packet received");
|
||||
process_adb_command(this->in_buf[1], this->in_count - 2);
|
||||
break;
|
||||
case CUDA_PKT_PSEUDO:
|
||||
@@ -623,7 +633,7 @@ void ViaCuda::pseudo_command(int cmd, int data_count) {
|
||||
case CUDA_MONO_STABLE_RESET:
|
||||
case CUDA_RESTART_SYSTEM:
|
||||
/* really kludge temp code */
|
||||
LOG_F(INFO, "Cuda: Restart/Shutdown signal sent with command 0x%x! \n", cmd);
|
||||
LOG_F(INFO, "Cuda: Restart/Shutdown signal sent with command 0x%x!", cmd);
|
||||
//exit(0);
|
||||
break;
|
||||
default:
|
||||
@@ -709,3 +719,9 @@ void ViaCuda::i2c_comb_transaction(
|
||||
this->is_open_ended = true;
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription ViaCuda_Descriptor = {
|
||||
ViaCuda::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(ViaCuda, ViaCuda_Descriptor);
|
||||
@@ -156,6 +156,10 @@ public:
|
||||
ViaCuda();
|
||||
~ViaCuda() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<ViaCuda>(new ViaCuda());
|
||||
}
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
@@ -164,6 +168,10 @@ public:
|
||||
|
||||
void assert_ctrl_line(ViaLine line);
|
||||
|
||||
#ifdef DEBUG_CPU_INT
|
||||
void assert_int(uint8_t flags);
|
||||
#endif
|
||||
|
||||
private:
|
||||
// VIA virtual HW registers
|
||||
uint8_t via_regs[16];
|
||||
@@ -191,7 +199,7 @@ private:
|
||||
uint32_t irq_id;
|
||||
uint8_t _via_ifr;
|
||||
uint8_t _via_ier;
|
||||
uint8_t irq;
|
||||
uint8_t old_ifr = 0;
|
||||
|
||||
/* Cuda state. */
|
||||
uint8_t old_tip;
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Device registry implementation. */
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
bool DeviceRegistry::add(const std::string name, DeviceDescription desc)
|
||||
{
|
||||
if (device_registered(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
get_registry()[name] = desc;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceRegistry::device_registered(const string dev_name)
|
||||
{
|
||||
if (get_registry().find(dev_name) != get_registry().end()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
unique_ptr<HWComponent> DeviceRegistry::create(const std::string& name)
|
||||
{
|
||||
auto it = get_registry().find(name);
|
||||
if (it != get_registry().end()) {
|
||||
return it->second.m_create_func();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DeviceDescription& DeviceRegistry::get_descriptor(const std::string& name)
|
||||
{
|
||||
auto it = get_registry().find(name);
|
||||
if (it != get_registry().end()) {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
static DeviceDescription empty_descriptor = {};
|
||||
|
||||
return empty_descriptor;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Device registry definitions. */
|
||||
|
||||
#ifndef DEVICE_REGISTRY_H
|
||||
#define DEVICE_REGISTRY_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
typedef std::function<unique_ptr<HWComponent> ()> CreateFunc;
|
||||
|
||||
struct DeviceDescription {
|
||||
CreateFunc m_create_func;
|
||||
vector<string> subdev_list;
|
||||
PropMap properties;
|
||||
};
|
||||
|
||||
class DeviceRegistry
|
||||
{
|
||||
public:
|
||||
DeviceRegistry() = delete;
|
||||
|
||||
static bool add(const string name, DeviceDescription desc);
|
||||
|
||||
static bool device_registered(const string dev_name);
|
||||
|
||||
static unique_ptr<HWComponent> create(const string& name);
|
||||
|
||||
static DeviceDescription& get_descriptor(const std::string& name);
|
||||
|
||||
private:
|
||||
static map<string, DeviceDescription> & get_registry() {
|
||||
static map<string, DeviceDescription> device_registry;
|
||||
return device_registry;
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_DEVICE(dev_name, dev_desc) \
|
||||
static bool dev_name ## _registered = DeviceRegistry::add(#dev_name, (dev_desc))
|
||||
|
||||
#endif // DEVICE_REGISTRY_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -21,11 +21,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Media Access Controller for Ethernet (MACE) emulation. */
|
||||
|
||||
#include "mace.h"
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
using namespace MaceEnet;
|
||||
|
||||
uint8_t MaceController::read(uint8_t reg_offset)
|
||||
{
|
||||
switch(reg_offset) {
|
||||
@@ -53,3 +56,9 @@ void MaceController::write(uint8_t reg_offset, uint8_t value)
|
||||
LOG_F(INFO, "Writing 0x%X to MACE register %d", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Mace_Descriptor = {
|
||||
MaceController::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Mace, Mace_Descriptor);
|
||||
+13
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,7 +24,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACE_H
|
||||
#define MACE_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
// MACE Chip ID from AMD datasheet
|
||||
// TODO: compare with real HW
|
||||
@@ -32,6 +35,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// MACE registers offsets
|
||||
// Refer to the Am79C940 datasheet for details
|
||||
namespace MaceEnet {
|
||||
|
||||
enum MaceReg : uint8_t {
|
||||
Rcv_FIFO = 0,
|
||||
Xmit_FIFO = 1,
|
||||
@@ -62,11 +67,17 @@ enum MaceReg : uint8_t {
|
||||
Rsrvd_Test_2 = 0x1F, // not used in Macintosh?
|
||||
};
|
||||
|
||||
class MaceController {
|
||||
}; // namespace MaceEnet
|
||||
|
||||
class MaceController : public HWComponent {
|
||||
public:
|
||||
MaceController(uint16_t id) { this->chip_id = id; };
|
||||
~MaceController() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<MaceController>(new MaceController(MACE_ID));
|
||||
}
|
||||
|
||||
// MACE registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
@@ -242,7 +242,7 @@ FloppyImgConverter* open_floppy_image(std::string& img_path)
|
||||
break;
|
||||
case FlopImgType::WOZ1:
|
||||
case FlopImgType::WOZ2:
|
||||
LOG_F(INFO, "WOZ v%s image\n", (itype == FlopImgType::WOZ2) ? "2" : "1");
|
||||
LOG_F(INFO, "WOZ v%s image", (itype == FlopImgType::WOZ2) ? "2" : "1");
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unknown/unsupported image format!");
|
||||
|
||||
@@ -131,7 +131,7 @@ uint8_t MacSuperDrive::status(uint8_t addr)
|
||||
}
|
||||
}
|
||||
|
||||
int MacSuperDrive::insert_disk(std::string& img_path, bool write_flag = 0)
|
||||
int MacSuperDrive::insert_disk(std::string& img_path, int write_flag = 0)
|
||||
{
|
||||
if (this->has_disk) {
|
||||
LOG_F(ERROR, "Superdrive: drive is not empty!");
|
||||
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
|
||||
void command(uint8_t addr, uint8_t value);
|
||||
uint8_t status(uint8_t addr);
|
||||
int insert_disk(std::string& img_path, bool write_flag);
|
||||
int insert_disk(std::string& img_path, int write_flag);
|
||||
double get_current_track_delay();
|
||||
double get_sector_delay();
|
||||
void init_track_search(int pos);
|
||||
|
||||
@@ -22,14 +22,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
/** @file Sander-Wozniak Machine 3 (SWIM3) emulation. */
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/hwinterrupt.h>
|
||||
#include <devices/floppy/superdrive.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using namespace Swim3;
|
||||
|
||||
@@ -51,7 +54,6 @@ Swim3Ctrl::Swim3Ctrl()
|
||||
// TODO: make SWIM3/drive wiring user selectable
|
||||
this->int_drive = std::unique_ptr<MacSuperdrive::MacSuperDrive>
|
||||
(new MacSuperdrive::MacSuperDrive());
|
||||
gMachineObj->add_subdevice("Superdrive", this->int_drive.get());
|
||||
}
|
||||
|
||||
int Swim3Ctrl::device_postinit()
|
||||
@@ -60,12 +62,19 @@ int Swim3Ctrl::device_postinit()
|
||||
gMachineObj->get_comp_by_type(HWCompType::INT_CTRL));
|
||||
this->irq_id = this->int_ctrl->register_dev_int(IntSrc::SWIM3);
|
||||
|
||||
// if a floppy image was given "insert" it into the virtual superdrive
|
||||
std::string fd_image_path = GET_STR_PROP("fdd_img");
|
||||
int fd_write_prot = GET_BIN_PROP("fdd_wr_prot");
|
||||
if (!fd_image_path.empty()) {
|
||||
this->int_drive->insert_disk(fd_image_path, fd_write_prot);
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
{
|
||||
uint8_t status_addr, old_int_flags, old_error;
|
||||
uint8_t status_addr, status_val, old_int_flags, old_error;
|
||||
|
||||
switch(reg_offset) {
|
||||
case Swim3Reg::Error:
|
||||
@@ -79,7 +88,11 @@ uint8_t Swim3Ctrl::read(uint8_t reg_offset)
|
||||
case Swim3Reg::Handshake_Mode1:
|
||||
if (this->mode_reg & 2) { // internal drive?
|
||||
status_addr = ((this->mode_reg & 0x20) >> 2) | (this->phase_lines & 7);
|
||||
return ((this->int_drive->status(status_addr) & 1) << 2);
|
||||
status_val = this->int_drive->status(status_addr) & 1;
|
||||
|
||||
// transfer status_val to both bit 2 (RDDATA) and bit 3 (SENSE)
|
||||
// because those signals seem to be historically wired together
|
||||
return ((status_val << 2) | (status_val << 3));
|
||||
}
|
||||
return 4;
|
||||
case Swim3Reg::Interrupt_Flags:
|
||||
@@ -321,3 +334,16 @@ void Swim3Ctrl::stop_disk_access()
|
||||
}
|
||||
this->access_timer_id = 0;
|
||||
}
|
||||
|
||||
static const PropMap Swim3_Properties = {
|
||||
{"fdd_img",
|
||||
new StrProperty("")},
|
||||
{"fdd_wr_prot",
|
||||
new BinProperty(0)},
|
||||
};
|
||||
|
||||
static const DeviceDescription Swim3_Descriptor = {
|
||||
Swim3Ctrl::create, {}, Swim3_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Swim3, Swim3_Descriptor);
|
||||
@@ -74,6 +74,10 @@ public:
|
||||
Swim3Ctrl();
|
||||
~Swim3Ctrl() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<Swim3Ctrl>(new Swim3Ctrl());
|
||||
}
|
||||
|
||||
int device_postinit();
|
||||
|
||||
// SWIM3 registers access
|
||||
|
||||
+121
-24
@@ -27,6 +27,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <core/timermanager.h>
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <cpu/ppc/ppcmmu.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/scsi/sc53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
@@ -50,14 +51,19 @@ AMIC::AMIC() : MMIODevice()
|
||||
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
// register I/O devices
|
||||
this->scsi = std::unique_ptr<Sc53C94> (new Sc53C94());
|
||||
gMachineObj->add_subdevice("Curio_SCSI0", this->scsi.get());
|
||||
// connect internal SCSI controller
|
||||
this->scsi = dynamic_cast<Sc53C94*>(gMachineObj->get_comp_by_name("Sc53C94"));
|
||||
this->scsi_dma = std::unique_ptr<AmicScsiDma> (new AmicScsiDma());
|
||||
this->scsi->set_dma_channel(this->scsi_dma.get());
|
||||
|
||||
this->escc = std::unique_ptr<EsccController> (new EsccController());
|
||||
this->mace = std::unique_ptr<MaceController> (new MaceController(MACE_ID));
|
||||
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda.get());
|
||||
// connect serial HW
|
||||
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
|
||||
|
||||
// connect Ethernet HW
|
||||
this->mace = dynamic_cast<MaceController*>(gMachineObj->get_comp_by_name("Mace"));
|
||||
|
||||
// connect Cuda
|
||||
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
|
||||
// initialize sound HW
|
||||
this->snd_out_dma = std::unique_ptr<AmicSndOutDma> (new AmicSndOutDma());
|
||||
@@ -68,11 +74,10 @@ AMIC::AMIC() : MMIODevice()
|
||||
this->disp_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
this->def_vid = std::unique_ptr<PdmOnboardVideo> (new PdmOnboardVideo());
|
||||
|
||||
// intialize floppy disk HW
|
||||
this->swim3 = std::unique_ptr<Swim3::Swim3Ctrl> (new Swim3::Swim3Ctrl());
|
||||
// initialize floppy disk HW
|
||||
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
|
||||
this->floppy_dma = std::unique_ptr<AmicFloppyDma> (new AmicFloppyDma());
|
||||
this->swim3->set_dma_channel(this->floppy_dma.get());
|
||||
gMachineObj->add_subdevice("SWIM3", this->swim3.get());
|
||||
}
|
||||
|
||||
int AMIC::device_postinit()
|
||||
@@ -92,10 +97,13 @@ int AMIC::device_postinit()
|
||||
this->viacuda->assert_ctrl_line(ViaLine::CA1);
|
||||
});
|
||||
|
||||
// set EMMO pin status (active low)
|
||||
this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
uint32_t AMIC::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
uint32_t phase_val;
|
||||
|
||||
@@ -105,11 +113,15 @@ uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
case 1:
|
||||
return this->viacuda->read(offset >> 9);
|
||||
case 4: // SCC registers
|
||||
return this->escc->read((offset >> 1) & 0xF);
|
||||
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
|
||||
case 0xA: // MACE registers
|
||||
return this->mace->read((offset >> 4) & 0xF);
|
||||
return this->mace->read((offset >> 4) & 0x1F);
|
||||
case 0x10: // SCSI registers
|
||||
return this->scsi->read((offset >> 4) & 0xF);
|
||||
if (offset & 0x100) {
|
||||
return this->scsi->pseudo_dma_read();
|
||||
} else {
|
||||
return this->scsi->read((offset >> 4) & 0xF);
|
||||
}
|
||||
case 0x14: // Sound registers
|
||||
switch (offset) {
|
||||
case AMICReg::Snd_Stat_0:
|
||||
@@ -153,14 +165,14 @@ uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
case AMICReg::Int_Ctrl:
|
||||
return (this->int_ctrl & 0xC0) | (this->dev_irq_lines & 0x3F);
|
||||
case AMICReg::Diag_Reg:
|
||||
return 0xFFU; // this value allows the machine to boot normally
|
||||
return 0xFE | this->emmo_pin;
|
||||
case AMICReg::DMA_Base_Addr_0:
|
||||
case AMICReg::DMA_Base_Addr_1:
|
||||
case AMICReg::DMA_Base_Addr_2:
|
||||
case AMICReg::DMA_Base_Addr_3:
|
||||
return (this->dma_base >> (3 - (offset & 3)) * 8) & 0xFF;
|
||||
case AMICReg::SCSI_DMA_Ctrl:
|
||||
return this->scsi_dma_cs;
|
||||
return this->scsi_dma->read_stat();
|
||||
case AMICReg::Floppy_Addr_Ptr_0:
|
||||
case AMICReg::Floppy_Addr_Ptr_1:
|
||||
case AMICReg::Floppy_Addr_Ptr_2:
|
||||
@@ -174,7 +186,7 @@ uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
void AMIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
uint32_t mask;
|
||||
|
||||
@@ -185,10 +197,10 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
this->viacuda->write(offset >> 9, value);
|
||||
return;
|
||||
case 4:
|
||||
this->escc->write((offset >> 1) & 0xF, value);
|
||||
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
|
||||
return;
|
||||
case 0xA: // MACE registers
|
||||
this->mace->write((offset >> 4) & 0xF, value);
|
||||
this->mace->write((offset >> 4) & 0x1F, value);
|
||||
return;
|
||||
case 0x10:
|
||||
this->scsi->write((offset >> 4) & 0xF, value);
|
||||
@@ -245,6 +257,12 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
}
|
||||
|
||||
switch(offset) {
|
||||
case AMICReg::VIA2_IFR:
|
||||
// for each "1" in value clear the corresponding IRQ bit
|
||||
// TODO: is bit 7 read only?
|
||||
// TODO: update interrupts?
|
||||
this->via2_ifr &= ~(value & 0x7F);
|
||||
break;
|
||||
case AMICReg::VIA2_Slot_IER:
|
||||
LOG_F(INFO, "AMIC VIA2 Slot Interrupt Enable Register updated, val=%x", value);
|
||||
break;
|
||||
@@ -287,7 +305,11 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
case AMICReg::Int_Ctrl:
|
||||
// reset CPU interrupt bit if requested
|
||||
if (value & AMIC_INT_CLR) {
|
||||
this->int_ctrl &= ~AMIC_INT_CLR;
|
||||
if (this->int_ctrl & 0x80) {
|
||||
this->int_ctrl &= ~AMIC_INT_CLR;
|
||||
ppc_release_int();
|
||||
LOG_F(5, "AMIC: CPU INT latch cleared");
|
||||
}
|
||||
}
|
||||
// keep interrupt mode bit
|
||||
// and discard read-only IQR state bits
|
||||
@@ -304,9 +326,24 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
case AMICReg::Enet_DMA_Xmt_Ctrl:
|
||||
LOG_F(INFO, "AMIC Ethernet Transmit DMA Ctrl updated, val=%x", value);
|
||||
break;
|
||||
case AMICReg::SCSI_DMA_Base_0:
|
||||
case AMICReg::SCSI_DMA_Base_1:
|
||||
case AMICReg::SCSI_DMA_Base_2:
|
||||
case AMICReg::SCSI_DMA_Base_3:
|
||||
SET_ADDR_BYTE(this->scsi_dma_base, offset, value);
|
||||
this->scsi_dma_base &= 0xFFFFFFF8UL;
|
||||
LOG_F(9, "AMIC: SCSI DMA base address set to 0x%X", this->scsi_dma_base);
|
||||
break;
|
||||
case AMICReg::SCSI_DMA_Ctrl:
|
||||
LOG_F(INFO, "AMIC SCSI DMA Ctrl updated, val=%x", value);
|
||||
this->scsi_dma_cs = value;
|
||||
if (value & 1) { // RST bit set?
|
||||
this->scsi_addr_ptr = this->scsi_dma_base;
|
||||
this->scsi_dma->reset(this->scsi_addr_ptr);
|
||||
}
|
||||
if (value & 2) { // RUN bit set?
|
||||
this->scsi_dma->reinit(this->scsi_dma_base);
|
||||
this->scsi->real_dma_xfer((value >> 6) & 1);
|
||||
}
|
||||
this->scsi_dma->write_ctrl(value);
|
||||
break;
|
||||
case AMICReg::Enet_DMA_Rcv_Ctrl:
|
||||
LOG_F(INFO, "AMIC Ethernet Receive DMA Ctrl updated, val=%x", value);
|
||||
@@ -394,13 +431,19 @@ void AMIC::ack_via2_int(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
|
||||
void AMIC::ack_cpu_int(uint32_t irq_id, uint8_t irq_line_state) {
|
||||
if (this->int_ctrl & AMIC_INT_MODE) { // 68k interrupt emulation mode?
|
||||
this->int_ctrl |= 0x80; // set CPU interrupt bit
|
||||
if (irq_line_state) {
|
||||
this->dev_irq_lines |= irq_id;
|
||||
} else {
|
||||
this->dev_irq_lines &= ~irq_id;
|
||||
}
|
||||
ppc_ext_int();
|
||||
if (!(this->int_ctrl & 0x80)) {
|
||||
this->int_ctrl |= 0x80; // set CPU interrupt bit
|
||||
ppc_assert_int();
|
||||
LOG_F(5, "AMIC: CPU INT asserted, source: %d", irq_id);
|
||||
} else {
|
||||
LOG_F(5, "AMIC: CPU INT already latched");
|
||||
}
|
||||
|
||||
} else {
|
||||
ABORT_F("AMIC: interrupt mode 0 not implemented");
|
||||
}
|
||||
@@ -527,3 +570,57 @@ DmaPullResult AmicFloppyDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
{
|
||||
return DmaPullResult::NoMoreData;
|
||||
}
|
||||
|
||||
// ============================ SCSI DMA stuff ================================
|
||||
void AmicScsiDma::reset(const uint32_t addr_ptr)
|
||||
{
|
||||
this->stat &= 0x48; // clear interrupt flag, RUN and RST bits
|
||||
this->addr_ptr = addr_ptr;
|
||||
this->byte_count = 0;
|
||||
}
|
||||
|
||||
void AmicScsiDma::reinit(const uint32_t addr_ptr)
|
||||
{
|
||||
this->addr_ptr = addr_ptr;
|
||||
this->byte_count = 0;
|
||||
}
|
||||
|
||||
void AmicScsiDma::write_ctrl(uint8_t value)
|
||||
{
|
||||
// copy over DIR, IE and RUN bits
|
||||
this->stat = (this->stat & 0x81) | (value & 0x4A);
|
||||
|
||||
// clear interrupt flag if requested
|
||||
if (value & 0x80) {
|
||||
this->stat &= 0x7F;
|
||||
}
|
||||
}
|
||||
|
||||
int AmicScsiDma::push_data(const char* src_ptr, int len)
|
||||
{
|
||||
uint8_t *p_data = mmu_get_dma_mem(this->addr_ptr, len);
|
||||
std::memcpy(p_data, src_ptr, len);
|
||||
|
||||
this->addr_ptr += len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DmaPullResult AmicScsiDma::pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data)
|
||||
{
|
||||
*p_data = mmu_get_dma_mem(this->addr_ptr, req_len);
|
||||
this->addr_ptr += req_len;
|
||||
*avail_len = req_len;
|
||||
return DmaPullResult::MoreData;
|
||||
}
|
||||
|
||||
static vector<string> Amic_Subdevices = {
|
||||
"Sc53C94", "Escc", "Mace", "ViaCuda", "Swim3"
|
||||
};
|
||||
|
||||
static const DeviceDescription Amic_Descriptor = {
|
||||
AMIC::create, Amic_Subdevices, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Amic, Amic_Descriptor);
|
||||
+57
-15
@@ -102,6 +102,27 @@ private:
|
||||
uint8_t stat;
|
||||
};
|
||||
|
||||
/** AMIC-specific SCSI DMA implementation. */
|
||||
class AmicScsiDma : public DmaBidirChannel {
|
||||
public:
|
||||
AmicScsiDma() = default;
|
||||
~AmicScsiDma() = default;
|
||||
|
||||
void reinit(const uint32_t addr_ptr);
|
||||
void reset(const uint32_t addr_ptr);
|
||||
void write_ctrl(const uint8_t value);
|
||||
uint8_t read_stat() { return this->stat; };
|
||||
|
||||
int push_data(const char* src_ptr, int len);
|
||||
DmaPullResult pull_data(uint32_t req_len, uint32_t *avail_len,
|
||||
uint8_t **p_data);
|
||||
|
||||
private:
|
||||
uint32_t addr_ptr;
|
||||
uint16_t byte_count;
|
||||
uint8_t stat;
|
||||
};
|
||||
|
||||
// macro for byte wise updating of AMIC DMA address registers
|
||||
#define SET_ADDR_BYTE(reg, offset, value) \
|
||||
mask = 0xFF000000UL >> (8 * ((offset) & 3)); \
|
||||
@@ -150,6 +171,10 @@ enum AMICReg : uint32_t {
|
||||
|
||||
// Interrupt registers
|
||||
Int_Ctrl = 0x2A000,
|
||||
DMA_Int_0 = 0x2A008,
|
||||
Bus_Err_Int_0 = 0x2A009,
|
||||
DMA_Int_1 = 0x2A00A,
|
||||
Bus_Err_Int_1 = 0x2A00B,
|
||||
|
||||
// Undocumented diagnostics register
|
||||
Diag_Reg = 0x2C000,
|
||||
@@ -160,9 +185,15 @@ enum AMICReg : uint32_t {
|
||||
DMA_Base_Addr_2 = 0x31002,
|
||||
DMA_Base_Addr_3 = 0x31003,
|
||||
Enet_DMA_Xmt_Ctrl = 0x31C20,
|
||||
SCSI_DMA_Ctrl = 0x32008,
|
||||
Enet_DMA_Rcv_Ctrl = 0x32028,
|
||||
|
||||
// SCSI DMA registers
|
||||
SCSI_DMA_Base_0 = 0x32000,
|
||||
SCSI_DMA_Base_1 = 0x32001,
|
||||
SCSI_DMA_Base_2 = 0x32002,
|
||||
SCSI_DMA_Base_3 = 0x32003,
|
||||
SCSI_DMA_Ctrl = 0x32008,
|
||||
|
||||
// Floppy (SWIM3) DMA registers
|
||||
Floppy_Addr_Ptr_0 = 0x32060,
|
||||
Floppy_Addr_Ptr_1 = 0x32061,
|
||||
@@ -184,12 +215,16 @@ public:
|
||||
AMIC();
|
||||
~AMIC() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AMIC>(new AMIC());
|
||||
}
|
||||
|
||||
// HWComponent methods
|
||||
int device_postinit();
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
// InterruptCtrl methods
|
||||
uint32_t register_dev_int(IntSrc src_id);
|
||||
@@ -204,16 +239,23 @@ protected:
|
||||
private:
|
||||
uint8_t imm_snd_regs[4]; // temporary storage for sound control registers
|
||||
|
||||
uint32_t dma_base = 0; // DMA physical base address
|
||||
uint16_t snd_buf_size = 0; // sound buffer size in bytes
|
||||
uint8_t snd_out_ctrl = 0;
|
||||
uint8_t emmo_pin; // EMMO aka factory tester pin status, active low
|
||||
|
||||
uint32_t dma_base = 0; // DMA physical base address
|
||||
uint32_t scsi_dma_base = 0; // physical base address for SCSI DMA
|
||||
uint16_t snd_buf_size = 0; // sound buffer size in bytes
|
||||
uint8_t snd_out_ctrl = 0;
|
||||
|
||||
// floppy DMA state
|
||||
uint32_t floppy_addr_ptr;
|
||||
uint16_t floppy_byte_cnt;
|
||||
|
||||
uint8_t scsi_dma_cs = 0; // SCSI DMA control/status register value
|
||||
// SCSI DMA state
|
||||
uint32_t scsi_addr_ptr;
|
||||
|
||||
//uint8_t scsi_dma_cs = 0; // SCSI DMA control/status register value
|
||||
|
||||
// interrupt state
|
||||
uint8_t int_ctrl = 0;
|
||||
uint8_t dev_irq_lines = 0; // state of the IRQ lines
|
||||
|
||||
@@ -224,22 +266,22 @@ private:
|
||||
|
||||
uint32_t pseudo_vbl_tid; // ID for the pseudo-VBL timer
|
||||
|
||||
// AMIC subdevices instances
|
||||
std::unique_ptr<Sc53C94> scsi;
|
||||
std::unique_ptr<EsccController> escc;
|
||||
std::unique_ptr<MaceController> mace;
|
||||
std::unique_ptr<ViaCuda> viacuda;
|
||||
std::unique_ptr<AwacDevicePdm> awacs;
|
||||
// AMIC subdevice instances
|
||||
Sc53C94* scsi;
|
||||
EsccController* escc;
|
||||
MaceController* mace;
|
||||
ViaCuda* viacuda;
|
||||
Swim3::Swim3Ctrl* swim3;
|
||||
|
||||
std::unique_ptr<AwacDevicePdm> awacs;
|
||||
std::unique_ptr<AmicSndOutDma> snd_out_dma;
|
||||
std::unique_ptr<AmicFloppyDma> floppy_dma;
|
||||
std::unique_ptr<AmicScsiDma> scsi_dma;
|
||||
|
||||
// on-board video
|
||||
std::unique_ptr<DisplayID> disp_id;
|
||||
std::unique_ptr<PdmOnboardVideo> def_vid;
|
||||
uint8_t mon_id;
|
||||
|
||||
std::unique_ptr<Swim3::Swim3Ctrl> swim3;
|
||||
};
|
||||
|
||||
#endif // AMIC_H
|
||||
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/scsi/sc53c94.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
GrandCentral::GrandCentral() : PCIDevice("mac-io/grandcentral"), InterruptCtrl()
|
||||
{
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
// populate my PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = 0x0002;
|
||||
this->class_rev = 0xFF000002;
|
||||
this->cache_ln_sz = 8;
|
||||
this->bars_cfg[0] = 0xFFFE0000UL; // declare 128Kb of memory-mapped I/O space
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
};
|
||||
|
||||
// NVRAM connection
|
||||
this->nvram = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
|
||||
|
||||
// connect Cuda
|
||||
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
|
||||
// initialize sound chip and its DMA output channel, then wire them together
|
||||
this->awacs = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
|
||||
this->snd_out_dma = std::unique_ptr<DMAChannel> (new DMAChannel());
|
||||
this->awacs->set_dma_out(this->snd_out_dma.get());
|
||||
this->snd_out_dma->set_callbacks(
|
||||
std::bind(&AwacsScreamer::dma_start, this->awacs.get()),
|
||||
std::bind(&AwacsScreamer::dma_end, this->awacs.get())
|
||||
);
|
||||
|
||||
// connect serial HW
|
||||
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
|
||||
|
||||
// connect SCSI HW
|
||||
this->scsi_0 = dynamic_cast<Sc53C94*>(gMachineObj->get_comp_by_name("Sc53C94"));
|
||||
|
||||
// connect Ethernet HW
|
||||
this->mace = dynamic_cast<MaceController*>(gMachineObj->get_comp_by_name("Mace"));
|
||||
|
||||
// connect floppy disk HW
|
||||
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
|
||||
|
||||
// set EMMO pin status (active low)
|
||||
this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
|
||||
}
|
||||
|
||||
void GrandCentral::notify_bar_change(int bar_num)
|
||||
{
|
||||
if (bar_num) // only BAR0 is supported
|
||||
return;
|
||||
|
||||
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
if (this->base_addr) {
|
||||
LOG_F(WARNING, "GC: deallocating I/O memory not implemented");
|
||||
}
|
||||
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, 0x20000, this);
|
||||
LOG_F(INFO, "%s: base address set to 0x%X", this->pci_name.c_str(), this->base_addr);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GrandCentral::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
if (offset & 0x10000) { // Device register space
|
||||
unsigned subdev_num = (offset >> 12) & 0xF;
|
||||
|
||||
switch (subdev_num) {
|
||||
case 0: // Curio SCSI
|
||||
return this->scsi_0->read((offset >> 4) & 0xF);
|
||||
case 1: // MACE
|
||||
return this->mace->read((offset >> 4) & 0x1F);
|
||||
case 2: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 16) {
|
||||
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
|
||||
}
|
||||
// fallthrough
|
||||
case 3: // ESCC MacRISC addressing
|
||||
return this->escc->read((offset >> 4) & 0xF);
|
||||
case 4: // AWACS
|
||||
return this->awacs->snd_ctrl_read(offset & 0xFF, size);
|
||||
case 5: // SWIM3
|
||||
return this->swim3->read((offset >> 4) & 0xF);
|
||||
case 6:
|
||||
case 7: // VIA-CUDA
|
||||
return this->viacuda->read((offset >> 9) & 0xF);
|
||||
case 0xA: // Board register 1 (IOBus dev #1)
|
||||
return BYTESWAP_32(this->emmo_pin << 8);
|
||||
case 0xB: // IOBus dev #2
|
||||
case 0xC: // IOBus dev #3
|
||||
case 0xE: // IOBus dev #5
|
||||
if (this->iobus_devs[subdev_num - 10] != nullptr) {
|
||||
return BYTESWAP_16(this->iobus_devs[subdev_num - 10]->iodev_read(
|
||||
(offset >> 4) & 0x1F));
|
||||
} else {
|
||||
LOG_F(ERROR, "GC: IOBus device #%d doesn't exist", subdev_num - 9);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case 0xF: // NVRAM Data (IOBus dev #6)
|
||||
return this->nvram->read_byte(
|
||||
(this->nvram_addr_hi << 5) + ((offset >> 4) & 0x1F));
|
||||
}
|
||||
} else if (offset & 0x8000) { // DMA register space
|
||||
unsigned subdev_num = (offset >> 12) & 0xF;
|
||||
|
||||
switch (subdev_num) {
|
||||
case 8:
|
||||
return this->snd_out_dma->reg_read(offset & 0xFF, size);
|
||||
default:
|
||||
LOG_F(WARNING, "GC: unimplemented DMA register at 0x%X",
|
||||
this->base_addr + offset);
|
||||
}
|
||||
} else { // Interrupt related registers
|
||||
switch (offset) {
|
||||
case MIO_INT_MASK1:
|
||||
return BYTESWAP_32(this->int_mask);
|
||||
case MIO_INT_LEVELS1:
|
||||
return BYTESWAP_32(this->int_levels);
|
||||
case MIO_INT_EVENTS1:
|
||||
return BYTESWAP_32(this->int_events);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_F(WARNING, "GC: reading from unmapped I/O memory 0x%X", this->base_addr + offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GrandCentral::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
if (offset & 0x10000) { // Device register space
|
||||
unsigned subdev_num = (offset >> 12) & 0xF;
|
||||
|
||||
switch (subdev_num) {
|
||||
case 0: // Curio SCSI
|
||||
this->scsi_0->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 1: // MACE registers
|
||||
this->mace->write((offset >> 4) & 0x1F, value);
|
||||
break;
|
||||
case 2: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 16) {
|
||||
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
case 3: // ESCC MacRISC addressing
|
||||
this->escc->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 4: // AWACS
|
||||
this->awacs->snd_ctrl_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
case 5:
|
||||
this->swim3->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 6:
|
||||
case 7: // VIA-CUDA
|
||||
this->viacuda->write((offset >> 9) & 0xF, value);
|
||||
break;
|
||||
case 0xA: // IOBus dev #1
|
||||
case 0xB: // IOBus dev #2
|
||||
case 0xC: // IOBus dev #3
|
||||
case 0xE: // IOBus dev #5
|
||||
if (this->iobus_devs[subdev_num - 10] != nullptr) {
|
||||
this->iobus_devs[subdev_num - 10]->iodev_write(
|
||||
(offset >> 4) & 0x1F, value);
|
||||
} else {
|
||||
LOG_F(ERROR, "GC: IOBus device #%d doesn't exist", subdev_num - 9);
|
||||
}
|
||||
break;
|
||||
case 0xD: // NVRAM High Address (IOBus dev #4)
|
||||
switch (size) {
|
||||
case 4:
|
||||
this->nvram_addr_hi = BYTESWAP_32(value);
|
||||
break;
|
||||
case 2:
|
||||
this->nvram_addr_hi = BYTESWAP_16(value);
|
||||
break;
|
||||
default:
|
||||
this->nvram_addr_hi = value;
|
||||
}
|
||||
break;
|
||||
case 0xF: // NVRAM Data (IOBus dev #6)
|
||||
this->nvram->write_byte(
|
||||
(this->nvram_addr_hi << 5) + ((offset >> 4) & 0x1F), value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "GC: writing to unmapped I/O memory 0x%X",
|
||||
this->base_addr + offset);
|
||||
}
|
||||
} else if (offset & 0x8000) { // DMA register space
|
||||
unsigned subdev_num = (offset >> 12) & 0xF;
|
||||
|
||||
switch (subdev_num) {
|
||||
case 8:
|
||||
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "GC: unimplemented DMA register at 0x%X",
|
||||
this->base_addr + offset);
|
||||
}
|
||||
} else { // Interrupt related registers
|
||||
switch (offset) {
|
||||
case MIO_INT_MASK1:
|
||||
this->int_mask = BYTESWAP_32(value);
|
||||
break;
|
||||
case MIO_INT_CLEAR1:
|
||||
if (value & MACIO_INT_CLR) {
|
||||
this->int_events = 0;
|
||||
this->cpu_int_latch = false;
|
||||
ppc_release_int();
|
||||
LOG_F(5, "GC: CPU INT latch cleared");
|
||||
} else {
|
||||
this->int_events &= BYTESWAP_32(value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "GC: writing to unmapped I/O memory 0x%X",
|
||||
this->base_addr + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GrandCentral::attach_iodevice(int dev_num, IobusDevice* dev_obj)
|
||||
{
|
||||
if (dev_num >= 0 && dev_num < 6) {
|
||||
this->iobus_devs[dev_num] = dev_obj;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GrandCentral::register_dev_int(IntSrc src_id)
|
||||
{
|
||||
switch (src_id) {
|
||||
case IntSrc::VIA_CUDA:
|
||||
return 1 << 18;
|
||||
case IntSrc::SCSI1:
|
||||
return 1 << 12;
|
||||
case IntSrc::SWIM3:
|
||||
return 1 << 19;
|
||||
default:
|
||||
ABORT_F("GC: unknown interrupt source %d", src_id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t GrandCentral::register_dma_int(IntSrc src_id)
|
||||
{
|
||||
ABORT_F("GC: register_dma_int() not implemened");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GrandCentral::ack_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
if (this->int_mask & MACIO_INT_MODE) { // 68k interrupt emulation mode?
|
||||
this->int_events |= irq_id; // signal IRQ line change
|
||||
this->int_events &= this->int_mask;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels |= irq_id;
|
||||
} else {
|
||||
this->int_levels &= ~irq_id;
|
||||
}
|
||||
// signal CPU interrupt
|
||||
if (this->int_events) {
|
||||
if (!this->cpu_int_latch) {
|
||||
this->cpu_int_latch = true;
|
||||
ppc_assert_int();
|
||||
LOG_F(5, "GC: CPU INT asserted, source: %d", irq_id);
|
||||
} else {
|
||||
LOG_F(5, "GC: CPU INT already latched");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ABORT_F("GC: native interrupt mode not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
void GrandCentral::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
ABORT_F("GC: ack_dma_int() not implemened");
|
||||
}
|
||||
|
||||
static const vector<string> GCSubdevices = {
|
||||
"NVRAM", "ViaCuda", "Escc", "Sc53C94", "Mace", "Swim3"
|
||||
};
|
||||
|
||||
static const DeviceDescription GC_Descriptor = {
|
||||
GrandCentral::create, GCSubdevices, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(GrandCentral, GC_Descriptor);
|
||||
+197
-93
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -20,6 +20,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
@@ -43,13 +45,27 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace std;
|
||||
|
||||
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
|
||||
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow"), InterruptCtrl()
|
||||
{
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::INT_CTRL);
|
||||
|
||||
this->nvram = std::unique_ptr<NVram> (new NVram());
|
||||
// populate my PCI config header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = 0x0010;
|
||||
this->class_rev = 0xFF000001;
|
||||
this->cache_ln_sz = 8;
|
||||
this->lat_timer = 0x40;
|
||||
this->bars_cfg[0] = 0xFFF80000UL; // declare 512Kb of memory-mapped I/O space
|
||||
|
||||
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
|
||||
gMachineObj->add_subdevice("ViaCuda", this->viacuda.get());
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
};
|
||||
|
||||
// NVRAM connection
|
||||
this->nvram = dynamic_cast<NVram*>(gMachineObj->get_comp_by_name("NVRAM"));
|
||||
|
||||
// connect Cuda
|
||||
this->viacuda = dynamic_cast<ViaCuda*>(gMachineObj->get_comp_by_name("ViaCuda"));
|
||||
|
||||
// initialize sound chip and its DMA output channel, then wire them together
|
||||
this->screamer = std::unique_ptr<AwacsScreamer> (new AwacsScreamer());
|
||||
@@ -60,35 +76,35 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow") {
|
||||
std::bind(&AwacsScreamer::dma_end, this->screamer.get())
|
||||
);
|
||||
|
||||
this->mesh = std::unique_ptr<MESHController> (new MESHController(HeathrowMESHID));
|
||||
this->escc = std::unique_ptr<EsccController> (new EsccController());
|
||||
this->swim3 = std::unique_ptr<Swim3::Swim3Ctrl> (new Swim3::Swim3Ctrl());
|
||||
// connect SCSI HW
|
||||
this->mesh = dynamic_cast<MeshController*>(gMachineObj->get_comp_by_name("Mesh"));
|
||||
|
||||
// connect IDE HW
|
||||
this->ide_0 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide0"));
|
||||
this->ide_1 = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name("Ide1"));
|
||||
|
||||
// connect serial HW
|
||||
this->escc = dynamic_cast<EsccController*>(gMachineObj->get_comp_by_name("Escc"));
|
||||
|
||||
// connect floppy disk HW
|
||||
this->swim3 = dynamic_cast<Swim3::Swim3Ctrl*>(gMachineObj->get_comp_by_name("Swim3"));
|
||||
|
||||
// set EMMO pin status (active low)
|
||||
this->emmo_pin = GET_BIN_PROP("emmo") ^ 1;
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
return this->pci_cfg_hdr[reg_offs & 0xFF];
|
||||
}
|
||||
void HeathrowIC::notify_bar_change(int bar_num)
|
||||
{
|
||||
if (bar_num) // only BAR0 is supported
|
||||
return;
|
||||
|
||||
void HeathrowIC::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
switch (reg_offs) {
|
||||
case CFG_REG_BAR0: // base address register
|
||||
value = LE2BE(value);
|
||||
if (value == 0xFFFFFFFF) {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: BAR0 block size determination not \
|
||||
implemented yet \n",
|
||||
this->name.c_str());
|
||||
} else if (value & 1) {
|
||||
LOG_F(ERROR, "%s err: BAR0 I/O space not supported! \n", this->name.c_str());
|
||||
} else if (value & 0x06) {
|
||||
LOG_F(ERROR, "%s err: BAR0 64-bit I/O space not supported! \n", this->name.c_str());
|
||||
} else {
|
||||
this->base_addr = value & 0xFFF80000;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
|
||||
LOG_F(INFO, "%s base address set to %x \n", this->name.c_str(), this->base_addr);
|
||||
if (this->base_addr != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
if (this->base_addr) {
|
||||
LOG_F(WARNING, "Heathrow: deallocating I/O memory not implemented");
|
||||
}
|
||||
break;
|
||||
this->base_addr = this->bars[0] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
|
||||
LOG_F(INFO, "%s: base address set to 0x%X", this->pci_name.c_str(), this->base_addr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,10 +133,10 @@ void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size) {
|
||||
}
|
||||
|
||||
|
||||
uint32_t HeathrowIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
uint32_t HeathrowIC::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
LOG_F(9, "%s: reading from offset %x \n", this->name.c_str(), offset);
|
||||
LOG_F(9, "%s: reading from offset %x", this->name.c_str(), offset);
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
@@ -136,7 +152,7 @@ uint32_t HeathrowIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
break;
|
||||
case 0x12: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 16) {
|
||||
return this->escc->read((offset >> 1) & 0xF);
|
||||
return this->escc->read(compat_to_macrisc[(offset >> 1) & 0xF]);
|
||||
}
|
||||
// fallthrough
|
||||
case 0x13: // ESCC MacRISC addressing
|
||||
@@ -145,24 +161,30 @@ uint32_t HeathrowIC::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
res = this->screamer->snd_ctrl_read(offset - 0x14000, size);
|
||||
break;
|
||||
case 0x15: // SWIM3
|
||||
return this->swim3->read(offset & 0xF);
|
||||
case 0x16:
|
||||
return this->swim3->read((offset >> 4 )& 0xF);
|
||||
case 0x16: // VIA-CUDA
|
||||
case 0x17:
|
||||
res = this->viacuda->read((offset - 0x16000) >> 9);
|
||||
break;
|
||||
case 0x20: // IDE 0
|
||||
res = this->ide_0->read((offset >> 4) & 0x1F, size);
|
||||
break;
|
||||
case 0x21: // IDE 1
|
||||
res = this->ide_1->read((offset >> 4) & 0x1F, size);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
res = this->nvram->read_byte((offset - 0x60000) >> 4);
|
||||
} else {
|
||||
LOG_F(WARNING, "Attempting to read unmapped I/O space: %x \n", offset);
|
||||
LOG_F(WARNING, "Attempting to read unmapped I/O space: %x", offset);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {
|
||||
LOG_F(9, "%s: writing to offset %x \n", this->name.c_str(), offset);
|
||||
void HeathrowIC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {
|
||||
LOG_F(9, "%s: writing to offset %x", this->name.c_str(), offset);
|
||||
|
||||
unsigned sub_addr = (offset >> 12) & 0x7F;
|
||||
|
||||
@@ -178,7 +200,7 @@ void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int
|
||||
break;
|
||||
case 0x12: // ESCC compatible addressing
|
||||
if ((offset & 0xFF) < 16) {
|
||||
this->escc->write((offset >> 1) & 0xF, value);
|
||||
this->escc->write(compat_to_macrisc[(offset >> 1) & 0xF], value);
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
@@ -188,18 +210,24 @@ void HeathrowIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int
|
||||
case 0x14:
|
||||
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
|
||||
break;
|
||||
case 0x15:
|
||||
this->swim3->write(offset & 0xF, value);
|
||||
case 0x15: // SWIM3
|
||||
this->swim3->write((offset >> 4) & 0xF, value);
|
||||
break;
|
||||
case 0x16:
|
||||
case 0x16: // VIA-CUDA
|
||||
case 0x17:
|
||||
this->viacuda->write((offset - 0x16000) >> 9, value);
|
||||
break;
|
||||
case 0x20: // IDE O
|
||||
this->ide_0->write((offset >> 4) & 0x1F, value, size);
|
||||
break;
|
||||
case 0x21: // IDE 1
|
||||
this->ide_1->write((offset >> 4) & 0x1F, value, size);
|
||||
break;
|
||||
default:
|
||||
if (sub_addr >= 0x60) {
|
||||
this->nvram->write_byte((offset - 0x60000) >> 4, value);
|
||||
} else {
|
||||
LOG_F(WARNING, "Attempting to write to unmapped I/O space: %x \n", offset);
|
||||
LOG_F(WARNING, "Attempting to write to unmapped I/O space: %x", offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -208,91 +236,86 @@ uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
switch (offset & 0xFC) {
|
||||
case 0x14:
|
||||
LOG_F(9, "read from MIO:Int_Mask2 register \n");
|
||||
case MIO_INT_EVENTS2:
|
||||
res = this->int_events2;
|
||||
break;
|
||||
case MIO_INT_MASK2:
|
||||
res = this->int_mask2;
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(9, "read from MIO:Int_Clear2 register \n");
|
||||
res = this->int_clear2;
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(9, "read from MIO:Int_Levels2 register \n");
|
||||
case MIO_INT_LEVELS2:
|
||||
res = this->int_levels2;
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(9, "read from MIO:Int_Mask1 register \n");
|
||||
case MIO_INT_EVENTS1:
|
||||
res = this->int_events1;
|
||||
break;
|
||||
case MIO_INT_MASK1:
|
||||
res = this->int_mask1;
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(9, "read from MIO:Int_Clear1 register \n");
|
||||
res = this->int_clear1;
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(9, "read from MIO:Int_Levels1 register \n");
|
||||
case MIO_INT_LEVELS1:
|
||||
res = this->int_levels1;
|
||||
break;
|
||||
case 0x34: /* heathrowIDs / HEATHROW_MBCR (Linux): media bay config reg? */
|
||||
LOG_F(9, "read from MIO:ID register at Address %x \n", ppc_state.pc);
|
||||
res = this->macio_id;
|
||||
case MIO_HEAT_ID:
|
||||
LOG_F(9, "read from MIO:ID register at Address %x", ppc_state.pc);
|
||||
res = (this->fp_id << 24) | (this->mon_id << 16) | (this->mb_id << 8) |
|
||||
(this->cpu_id | (this->emmo_pin << 4));
|
||||
break;
|
||||
case 0x38:
|
||||
LOG_F(9, "read from MIO:Feat_Ctrl register \n");
|
||||
res = BYTESWAP_32(this->feat_ctrl);
|
||||
case MIO_HEAT_FEAT_CTRL:
|
||||
LOG_F(9, "read from MIO:Feat_Ctrl register");
|
||||
res = this->feat_ctrl;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "read from unknown MIO register at %x \n", offset);
|
||||
LOG_F(WARNING, "read from unknown MIO register at %x", offset);
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
return BYTESWAP_32(res);
|
||||
}
|
||||
|
||||
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size) {
|
||||
switch (offset & 0xFC) {
|
||||
case 0x14:
|
||||
LOG_F(9, "write %x to MIO:Int_Mask2 register \n", value);
|
||||
this->int_mask2 = value;
|
||||
case MIO_INT_MASK2:
|
||||
this->int_mask2 |= BYTESWAP_32(value) & ~MACIO_INT_MODE;
|
||||
break;
|
||||
case 0x18:
|
||||
LOG_F(9, "write %x to MIO:Int_Clear2 register \n", value);
|
||||
this->int_clear2 = value;
|
||||
case MIO_INT_CLEAR2:
|
||||
if (value & MACIO_INT_CLR) {
|
||||
this->int_events2 = 0;
|
||||
clear_cpu_int();
|
||||
} else {
|
||||
this->int_events2 &= BYTESWAP_32(value);
|
||||
}
|
||||
break;
|
||||
case 0x1C:
|
||||
LOG_F(9, "write %x to MIO:Int_Levels2 register \n", value);
|
||||
this->int_levels2 = value;
|
||||
case MIO_INT_MASK1:
|
||||
this->int_mask1 = BYTESWAP_32(value);
|
||||
// copy IntMode bit to InterruptMask2 register
|
||||
this->int_mask2 = (this->int_mask2 & ~MACIO_INT_MODE) | (this->int_mask1 & MACIO_INT_MODE);
|
||||
break;
|
||||
case 0x24:
|
||||
LOG_F(9, "write %x to MIO:Int_Mask1 register \n", value);
|
||||
this->int_mask1 = value;
|
||||
case MIO_INT_CLEAR1:
|
||||
if (value & MACIO_INT_CLR) {
|
||||
this->int_events1 = 0;
|
||||
clear_cpu_int();
|
||||
} else {
|
||||
this->int_events1 &= BYTESWAP_32(value);
|
||||
}
|
||||
break;
|
||||
case 0x28:
|
||||
LOG_F(9, "write %x to MIO:Int_Clear1 register \n", value);
|
||||
this->int_clear1 = value;
|
||||
case MIO_HEAT_ID:
|
||||
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x", value, offset, ppc_state.pc);
|
||||
break;
|
||||
case 0x2C:
|
||||
LOG_F(9, "write %x to MIO:Int_Levels1 register \n", value);
|
||||
this->int_levels1 = value;
|
||||
break;
|
||||
case 0x34:
|
||||
LOG_F(WARNING, "Attempted to write %x to MIO:ID at %x; Address : %x \n", value, offset, ppc_state.pc);
|
||||
break;
|
||||
case 0x38:
|
||||
case MIO_HEAT_FEAT_CTRL:
|
||||
this->feature_control(BYTESWAP_32(value));
|
||||
break;
|
||||
case 0x3C:
|
||||
LOG_F(9, "write %x to MIO:Aux_Ctrl register \n", value);
|
||||
LOG_F(9, "write %x to MIO:Aux_Ctrl register", value);
|
||||
this->aux_ctrl = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "write %x to unknown MIO register at %x \n", value, offset);
|
||||
LOG_F(WARNING, "write %x to unknown MIO register at %x", value, offset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void HeathrowIC::feature_control(const uint32_t value)
|
||||
{
|
||||
LOG_F(9, "write %x to MIO:Feat_Ctrl register \n", value);
|
||||
LOG_F(9, "write %x to MIO:Feat_Ctrl register", value);
|
||||
|
||||
this->feat_ctrl = value;
|
||||
|
||||
@@ -302,3 +325,84 @@ void HeathrowIC::feature_control(const uint32_t value)
|
||||
LOG_F(9, "Heathrow: Monitor sense disabled");
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::register_dev_int(IntSrc src_id)
|
||||
{
|
||||
switch (src_id) {
|
||||
case IntSrc::VIA_CUDA:
|
||||
return 1 << 7;
|
||||
case IntSrc::SCSI1:
|
||||
return 1 << 1;
|
||||
case IntSrc::SWIM3:
|
||||
return 1 << 8;
|
||||
default:
|
||||
ABORT_F("Heathrow: unknown interrupt source %d", src_id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t HeathrowIC::register_dma_int(IntSrc src_id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HeathrowIC::ack_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
if (this->int_mask1 & MACIO_INT_MODE) { // 68k interrupt emulation mode?
|
||||
if (irq_id > 0x200000) {
|
||||
irq_id >>= 21;
|
||||
this->int_events2 |= irq_id; // signal IRQ line change
|
||||
this->int_events2 &= this->int_mask2;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels2 |= irq_id;
|
||||
} else {
|
||||
this->int_levels2 &= ~irq_id;
|
||||
}
|
||||
} else {
|
||||
irq_id <<= 11;
|
||||
this->int_events1 |= irq_id; // signal IRQ line change
|
||||
this->int_events1 &= this->int_mask1;
|
||||
// update IRQ line state
|
||||
if (irq_line_state) {
|
||||
this->int_levels1 |= irq_id;
|
||||
} else {
|
||||
this->int_levels1 &= ~irq_id;
|
||||
}
|
||||
}
|
||||
// signal CPU interrupt
|
||||
if (this->int_events1 || this->int_events2) {
|
||||
if (!this->cpu_int_latch) {
|
||||
this->cpu_int_latch = true;
|
||||
ppc_assert_int();
|
||||
LOG_F(5, "Heathrow: CPU INT asserted, source: %d", irq_id);
|
||||
} else {
|
||||
LOG_F(5, "Heathrow: CPU INT already latched");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ABORT_F("Heathrow: native interrupt mode not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
void HeathrowIC::ack_dma_int(uint32_t irq_id, uint8_t irq_line_state)
|
||||
{
|
||||
}
|
||||
|
||||
void HeathrowIC::clear_cpu_int()
|
||||
{
|
||||
if (!this->int_events1 && !this->int_events2) {
|
||||
this->cpu_int_latch = false;
|
||||
ppc_release_int();
|
||||
LOG_F(5, "Heathrow: CPU INT latch cleared");
|
||||
}
|
||||
}
|
||||
|
||||
static const vector<string> Heathrow_Subdevices = {
|
||||
"NVRAM", "ViaCuda", "Mesh", "Escc", "Swim3", "Ide0", "Ide1"};
|
||||
|
||||
static const DeviceDescription Heathrow_Descriptor = {
|
||||
HeathrowIC::create, Heathrow_Subdevices, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Heathrow, Heathrow_Descriptor);
|
||||
+124
-47
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -51,13 +51,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACIO_H
|
||||
#define MACIO_H
|
||||
|
||||
#include <devices/common/ata/idechannel.h>
|
||||
#include <devices/common/dbdma.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/common/nvram.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/common/pci/pcihost.h>
|
||||
#include <devices/common/scsi/mesh.h>
|
||||
#include <devices/common/scsi/sc53c94.h>
|
||||
#include <devices/common/viacuda.h>
|
||||
#include <devices/ethernet/mace.h>
|
||||
#include <devices/floppy/swim3.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/serial/escc.h>
|
||||
@@ -66,11 +69,84 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** Interrupt related constants. */
|
||||
#define MACIO_INT_CLR 0x80UL // clears bits in the interrupt events registers
|
||||
#define MACIO_INT_MODE 0x80000000UL // interrupt mode: 0 - native, 1 - 68k-style
|
||||
|
||||
/** Offsets to common MacIO interrupt registers. */
|
||||
enum {
|
||||
MIO_INT_EVENTS2 = 0x10,
|
||||
MIO_INT_MASK2 = 0x14,
|
||||
MIO_INT_CLEAR2 = 0x18,
|
||||
MIO_INT_LEVELS2 = 0x1C,
|
||||
MIO_INT_EVENTS1 = 0x20,
|
||||
MIO_INT_MASK1 = 0x24,
|
||||
MIO_INT_CLEAR1 = 0x28,
|
||||
MIO_INT_LEVELS1 = 0x2C
|
||||
};
|
||||
|
||||
class IobusDevice {
|
||||
public:
|
||||
virtual uint16_t iodev_read(uint32_t address) = 0;
|
||||
virtual void iodev_write(uint32_t address, uint16_t value) = 0;
|
||||
};
|
||||
|
||||
class GrandCentral : public PCIDevice, public InterruptCtrl {
|
||||
public:
|
||||
GrandCentral();
|
||||
~GrandCentral() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<GrandCentral>(new GrandCentral());
|
||||
}
|
||||
|
||||
// MMIO device methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
// InterruptCtrl methods
|
||||
uint32_t register_dev_int(IntSrc src_id);
|
||||
uint32_t register_dma_int(IntSrc src_id);
|
||||
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
|
||||
void attach_iodevice(int dev_num, IobusDevice* dev_obj);
|
||||
|
||||
protected:
|
||||
void notify_bar_change(int bar_num);
|
||||
|
||||
private:
|
||||
uint32_t base_addr = 0;
|
||||
|
||||
uint8_t emmo_pin; // factory tester status, active low
|
||||
|
||||
// interrupt state
|
||||
uint32_t int_mask = 0;
|
||||
uint32_t int_levels = 0;
|
||||
uint32_t int_events = 0;
|
||||
bool cpu_int_latch = false;
|
||||
|
||||
uint32_t nvram_addr_hi;
|
||||
|
||||
// IOBus devices
|
||||
IobusDevice* iobus_devs[6] = { nullptr };
|
||||
|
||||
// subdevice objects
|
||||
std::unique_ptr<AwacsScreamer> awacs; // AWACS audio codec instance
|
||||
|
||||
NVram* nvram; // NVRAM module
|
||||
MaceController* mace;
|
||||
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
|
||||
EsccController* escc; // ESCC serial controller
|
||||
Sc53C94* scsi_0; // external SCSI
|
||||
Swim3::Swim3Ctrl* swim3; // floppy disk controller
|
||||
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
};
|
||||
|
||||
/**
|
||||
Heathrow ASIC emulation
|
||||
|
||||
Author: Max Poliakovski
|
||||
|
||||
Heathrow is a MIO-compliant ASIC used in the Gossamer architecture. It's
|
||||
hard-wired to PCI device number 16. Its I/O memory (512Kb) will be configured
|
||||
by the Macintosh firmware to live at 0xF3000000.
|
||||
@@ -92,22 +168,30 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
VIA-CUDA register space: 0x00016000, size: 0x00002000
|
||||
*/
|
||||
|
||||
class HeathrowIC : public PCIDevice {
|
||||
/** Heathrow specific registers. */
|
||||
enum {
|
||||
MIO_HEAT_ID = 0x34, // IDs register
|
||||
MIO_HEAT_FEAT_CTRL = 0x38, // feature control register
|
||||
};
|
||||
|
||||
class HeathrowIC : public PCIDevice, public InterruptCtrl {
|
||||
public:
|
||||
HeathrowIC();
|
||||
~HeathrowIC() = default;
|
||||
|
||||
/* PCI device methods */
|
||||
bool supports_io_space(void) {
|
||||
return false;
|
||||
};
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<HeathrowIC>(new HeathrowIC());
|
||||
}
|
||||
|
||||
uint32_t pci_cfg_read(uint32_t reg_offs, uint32_t size);
|
||||
void pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size);
|
||||
// MMIO device methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
/* MMIO device methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
// InterruptCtrl methods
|
||||
uint32_t register_dev_int(IntSrc src_id);
|
||||
uint32_t register_dma_int(IntSrc src_id);
|
||||
void ack_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
void ack_dma_int(uint32_t irq_id, uint8_t irq_line_state);
|
||||
|
||||
protected:
|
||||
uint32_t dma_read(uint32_t offset, int size);
|
||||
@@ -116,46 +200,39 @@ protected:
|
||||
uint32_t mio_ctrl_read(uint32_t offset, int size);
|
||||
void mio_ctrl_write(uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void notify_bar_change(int bar_num);
|
||||
|
||||
void feature_control(const uint32_t value);
|
||||
void clear_cpu_int();
|
||||
|
||||
private:
|
||||
uint8_t pci_cfg_hdr[256] = {
|
||||
0x6B,
|
||||
0x10, // vendor ID: Apple Computer Inc.
|
||||
0x10,
|
||||
0x00, // device ID: Heathrow Mac I/O
|
||||
0x00,
|
||||
0x00, // PCI command (set to 0 at power-up?)
|
||||
0x00,
|
||||
0x00, // PCI status (set to 0 at power-up?)
|
||||
0x01, // revision ID
|
||||
// class code is reported in OF property "class-code" as 0xff0000
|
||||
0x00, // standard programming
|
||||
0x00, // subclass code
|
||||
0xFF, // class code: unassigned
|
||||
0x00,
|
||||
0x00, // unknown defaults
|
||||
0x00,
|
||||
0x00 // unknown defaults
|
||||
};
|
||||
uint32_t base_addr = 0;
|
||||
uint32_t int_events2 = 0;
|
||||
uint32_t int_mask2 = 0;
|
||||
uint32_t int_levels2 = 0;
|
||||
uint32_t int_events1 = 0;
|
||||
uint32_t int_mask1 = 0;
|
||||
uint32_t int_levels1 = 0;
|
||||
uint32_t feat_ctrl = 0; // features control register
|
||||
uint32_t aux_ctrl = 0; // aux features control register
|
||||
bool cpu_int_latch = false;
|
||||
|
||||
uint32_t int_mask2 = 0;
|
||||
uint32_t int_clear2 = 0;
|
||||
uint32_t int_levels2 = 0;
|
||||
uint32_t int_mask1 = 0;
|
||||
uint32_t int_clear1 = 0;
|
||||
uint32_t int_levels1 = 0;
|
||||
uint32_t macio_id = 0xF0700008UL;
|
||||
uint32_t feat_ctrl = 0; // features control register
|
||||
uint32_t aux_ctrl = 0; // aux features control register
|
||||
uint8_t cpu_id = 0xE0; // CPUID field (LSB of the MIO_HEAT_ID)
|
||||
uint8_t mb_id = 0x70; // Media Bay ID (bits 15:8 of the MIO_HEAT_ID)
|
||||
uint8_t mon_id = 0x10; // Monitor ID (bits 23:16 of the MIO_HEAT_ID)
|
||||
uint8_t fp_id = 0x70; // Flat panel ID (MSB of the MIO_HEAT_ID)
|
||||
uint8_t emmo_pin; // factory tester status, active low
|
||||
|
||||
/* device cells */
|
||||
std::unique_ptr<ViaCuda> viacuda; // VIA cell with Cuda MCU attached to it
|
||||
std::unique_ptr<NVram> nvram; // NVRAM cell
|
||||
// subdevice objects
|
||||
std::unique_ptr<AwacsScreamer> screamer; // Screamer audio codec instance
|
||||
std::unique_ptr<MESHController> mesh; // MESH SCSI cell instance
|
||||
std::unique_ptr<EsccController> escc; // ESCC serial controller
|
||||
std::unique_ptr<Swim3::Swim3Ctrl> swim3; // floppy disk controller
|
||||
|
||||
NVram* nvram; // NVRAM
|
||||
ViaCuda* viacuda; // VIA cell with Cuda MCU attached to it
|
||||
MeshController* mesh; // MESH SCSI cell instance
|
||||
EsccController* escc; // ESCC serial controller
|
||||
IdeChannel* ide_0; // Internal ATA
|
||||
IdeChannel* ide_1; // Media Bay ATA
|
||||
Swim3::Swim3Ctrl* swim3; // floppy disk controller
|
||||
|
||||
std::unique_ptr<DMAChannel> snd_out_dma;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Hammerhead Memory Controller emulation. */
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/hammerhead.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
using namespace Hammerhead;
|
||||
|
||||
HammerheadCtrl::HammerheadCtrl() : MemCtrlBase()
|
||||
{
|
||||
this->name = "Hammerhead Memory Controller";
|
||||
|
||||
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
|
||||
|
||||
// add MMIO region for the configuration and status registers
|
||||
add_mmio_region(0xF8000000, 0x500, this);
|
||||
}
|
||||
|
||||
uint32_t HammerheadCtrl::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
if (offset >= HammerheadReg::BANK_0_BASE_MSB &&
|
||||
offset <= HammerheadReg::BANK_25_BASE_LSB) {
|
||||
offset = (offset - HammerheadReg::BANK_0_BASE_MSB) >> 4;
|
||||
if (offset & 1) { // return the LSB part
|
||||
result = bank_base[offset >> 1] & 0xFFU;
|
||||
} else { // return the MSB part
|
||||
result = bank_base[offset >> 1] >> 8;
|
||||
}
|
||||
goto finish;
|
||||
}
|
||||
|
||||
switch (offset) {
|
||||
case HammerheadReg::CPU_ID:
|
||||
result = HH_CPU_ID_TNT;
|
||||
break;
|
||||
case HammerheadReg::MOTHERBOARD_ID:
|
||||
result = MBID_VCI0_PRESENT << 5;
|
||||
break;
|
||||
case HammerheadReg::CPU_SPEED:
|
||||
result = BUS_SPEED_33_MHZ << 5;
|
||||
break;
|
||||
case HammerheadReg::ARBITER_CONFIG:
|
||||
result = this->arb_config;
|
||||
break;
|
||||
case HammerheadReg::WHO_AM_I:
|
||||
result = BM_PRIMARY_CPU << 3;
|
||||
break;
|
||||
case HammerheadReg::L2_CACHE_CONFIG:
|
||||
result = 0; // say there is no L2 cache
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Hammerhead: unknown register read at offset 0x%X", offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Hammerhead registers are one byte wide so always place
|
||||
// the result in the MSB of a multibyte read
|
||||
finish:
|
||||
return result << ((size - 1) << 3);
|
||||
}
|
||||
|
||||
void HammerheadCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
// extract byte value from the MSB of a multibyte value
|
||||
value = value >> ((size - 1) << 3);
|
||||
|
||||
if (offset >= HammerheadReg::BANK_0_BASE_MSB &&
|
||||
offset <= HammerheadReg::BANK_25_BASE_LSB) {
|
||||
offset = (offset - HammerheadReg::BANK_0_BASE_MSB) >> 4;
|
||||
if (offset & 1) { // update the LSB part
|
||||
bank_base[offset >> 1] = (bank_base[offset >> 1] & 0xFF00U) | value;
|
||||
} else { // update the MSB part
|
||||
bank_base[offset >> 1] = (bank_base[offset >> 1] & 0x00FFU) | (value << 8);
|
||||
}
|
||||
LOG_F(INFO, "Hammerhead: bank base #%d set to 0x%X", offset >> 1, bank_base[offset >> 1]);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (offset) {
|
||||
case HammerheadReg::MEM_TIMING_0:
|
||||
LOG_F(9, "Hammerhead: MEM_TIMING_0 set to 0x%X", value);
|
||||
break;
|
||||
case HammerheadReg::MEM_TIMING_1:
|
||||
LOG_F(9, "Hammerhead: MEM_TIMING_1 set to 0x%X", value);
|
||||
break;
|
||||
case HammerheadReg::REFRESH_TIMING:
|
||||
LOG_F(9, "Hammerhead: REFRESH_TIMING set to 0x%X", value);
|
||||
break;
|
||||
case HammerheadReg::ROM_TIMING:
|
||||
LOG_F(9, "Hammerhead: ROM_TIMING set to 0x%X", value);
|
||||
break;
|
||||
case HammerheadReg::ARBITER_CONFIG:
|
||||
this->arb_config = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Hammerhead: unknown register write at offset 0x%X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
void HammerheadCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
|
||||
{
|
||||
if (slot_num < 0 || slot_num >= 26) {
|
||||
ABORT_F("Hammerhead: invalid DIMM slot number %d", slot_num);
|
||||
}
|
||||
|
||||
switch (capacity) {
|
||||
case DRAM_CAP_2MB:
|
||||
case DRAM_CAP_4MB:
|
||||
case DRAM_CAP_8MB:
|
||||
case DRAM_CAP_16MB:
|
||||
case DRAM_CAP_32MB:
|
||||
case DRAM_CAP_64MB:
|
||||
this->bank_size[slot_num * 2 + 0] = capacity;
|
||||
break;
|
||||
case DRAM_CAP_128MB:
|
||||
this->bank_size[slot_num * 2 + 0] = DRAM_CAP_64MB;
|
||||
this->bank_size[slot_num * 2 + 1] = DRAM_CAP_64MB;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("Hammerhead: unsupported DRAM capacity %d", capacity);
|
||||
}
|
||||
}
|
||||
|
||||
void HammerheadCtrl::map_phys_ram()
|
||||
{
|
||||
uint32_t total_ram = 0;
|
||||
|
||||
for (int i = 0; i < 26; i++) {
|
||||
total_ram += this->bank_size[i];
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Hammerhead: total RAM size = %d bytes", total_ram);
|
||||
|
||||
if (!add_ram_region(0x00000000, total_ram)) {
|
||||
ABORT_F("Hammerhead: could not allocate physical RAM storage");
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Hammerhead_Descriptor = {
|
||||
HammerheadCtrl::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Hammerhead, Hammerhead_Descriptor);
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Hammerhead Memory Controller definitions.
|
||||
|
||||
Author: Max Poliakovski
|
||||
|
||||
Hammerhead is a custom memory controller and ARBus arbiter
|
||||
designed especially for the TNT family of Power Macintosh computers.
|
||||
*/
|
||||
|
||||
#ifndef HAMMERHEAD_MEMCTRL_H
|
||||
#define HAMMERHEAD_MEMCTRL_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
namespace Hammerhead {
|
||||
|
||||
#define RISC_MACHINE 0x3
|
||||
#define MACH_TYPE_TNT 0x1
|
||||
#define HH_CPU_ID_TNT ((RISC_MACHINE << 4) | (1 << 3) | MACH_TYPE_TNT)
|
||||
|
||||
// contants for the MBID field of the MOTHERBOARD_ID register
|
||||
enum {
|
||||
MBID_VCI0_PRESENT = 4,
|
||||
MBID_PCI2_PRESENT = 2,
|
||||
};
|
||||
|
||||
// ARBus speed constants for the CPU_SPEED register
|
||||
enum {
|
||||
BUS_SPEED_40_MHZ = 0,
|
||||
BUS_SPEED_33_MHZ = 1,
|
||||
BUS_SPEED_44_MHZ = 2,
|
||||
BUS_SPEED_50_MHZ = 3
|
||||
};
|
||||
|
||||
// bus master IDs for the WHO_AM_I register
|
||||
enum {
|
||||
BM_VIDEO_BRIDGE = 1 << 4,
|
||||
BM_PCI_BRIDGE_1 = 1 << 3,
|
||||
BM_PCI_BRIDGE_2 = 1 << 2,
|
||||
BM_PRIMARY_CPU = 1 << 1,
|
||||
BM_SECONDARY_CPU = 1 << 0
|
||||
};
|
||||
|
||||
// Configuration and status registers.
|
||||
enum HammerheadReg : uint16_t {
|
||||
CPU_ID = 0x00,
|
||||
ASIC_REVISION = 0x10,
|
||||
MOTHERBOARD_ID = 0x20,
|
||||
CPU_SPEED = 0x30,
|
||||
MB_DRAM_CONFIG = 0x40,
|
||||
MEM_TIMING_0 = 0x50,
|
||||
MEM_TIMING_1 = 0x60,
|
||||
REFRESH_TIMING = 0x70,
|
||||
ROM_TIMING = 0x80,
|
||||
ARBITER_CONFIG = 0x90,
|
||||
ARBUS_TIMEOUT = 0xA0,
|
||||
WHO_AM_I = 0xB0,
|
||||
L2_CACHE_CONFIG = 0xE0,
|
||||
BANK_0_BASE_MSB = 0x1C0,
|
||||
BANK_25_BASE_LSB = 0x4F0,
|
||||
};
|
||||
|
||||
}; // namespace Hammerhead
|
||||
|
||||
class HammerheadCtrl : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
HammerheadCtrl();
|
||||
~HammerheadCtrl() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<HammerheadCtrl>(new HammerheadCtrl());
|
||||
}
|
||||
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void insert_ram_dimm(int slot_num, uint32_t capacity);
|
||||
void map_phys_ram();
|
||||
|
||||
private:
|
||||
uint8_t arb_config = 0;
|
||||
|
||||
uint16_t bank_base[26];
|
||||
uint32_t bank_size[26] = { 0 };
|
||||
};
|
||||
|
||||
#endif // HAMMERHEAD_MEMCTRL_H
|
||||
@@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/memctrl/hmc.h>
|
||||
|
||||
@@ -40,7 +41,7 @@ HMC::HMC() : MemCtrlBase()
|
||||
this->bit_pos = 0;
|
||||
}
|
||||
|
||||
uint32_t HMC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
uint32_t HMC::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
if (!offset)
|
||||
return !!(this->ctrl_reg & (1ULL << this->bit_pos++));
|
||||
@@ -48,7 +49,7 @@ uint32_t HMC::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
return 0; /* FIXME: what should be returned for invalid offsets? */
|
||||
}
|
||||
|
||||
void HMC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
void HMC::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
uint64_t bit;
|
||||
|
||||
@@ -63,3 +64,9 @@ void HMC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Hmc_Descriptor = {
|
||||
HMC::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(HMC, Hmc_Descriptor);
|
||||
@@ -35,6 +35,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/** Bit in the HMC control register telling us where the frame bufffer
|
||||
for the on-board video is located. */
|
||||
@@ -45,9 +46,13 @@ public:
|
||||
HMC();
|
||||
~HMC() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<HMC>(new HMC());
|
||||
}
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
uint64_t get_control_reg(void) {
|
||||
return this->ctrl_reg;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -28,6 +28,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Common DRAM capacities.
|
||||
enum {
|
||||
DRAM_CAP_2MB = (1 << 21),
|
||||
DRAM_CAP_4MB = (1 << 22),
|
||||
DRAM_CAP_8MB = (1 << 23),
|
||||
DRAM_CAP_16MB = (1 << 24),
|
||||
DRAM_CAP_32MB = (1 << 25),
|
||||
DRAM_CAP_64MB = (1 << 26),
|
||||
DRAM_CAP_128MB = (1 << 27),
|
||||
};
|
||||
|
||||
enum RangeType {
|
||||
RT_ROM = 1, /* read-only memory */
|
||||
RT_RAM = 2, /* random access memory */
|
||||
|
||||
+105
-77
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,13 +19,11 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** MPC106 (Grackle) emulation
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
/** MPC106 (Grackle) emulation. */
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <memaccess.h>
|
||||
@@ -34,34 +32,54 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <loguru.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle PCI host bridge") {
|
||||
MPC106::MPC106() : MemCtrlBase(), PCIDevice("Grackle"), PCIHost()
|
||||
{
|
||||
this->name = "Grackle";
|
||||
|
||||
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV |
|
||||
HWCompType::PCI_HOST | HWCompType::PCI_DEV);
|
||||
|
||||
/* add PCI/ISA I/O space, 64K for now */
|
||||
// populate PCI config header
|
||||
this->vendor_id = PCI_VENDOR_MOTOROLA;
|
||||
this->device_id = 0x0002;
|
||||
this->class_rev = 0x06000040;
|
||||
this->cache_ln_sz = 8;
|
||||
this->command = 6;
|
||||
this->status = 0x80;
|
||||
|
||||
// add PCI/ISA I/O space, 64K for now
|
||||
add_mmio_region(0xFE000000, 0x10000, this);
|
||||
|
||||
/* add memory mapped I/O region for MPC106 registers */
|
||||
// add memory mapped I/O region for MPC106 registers
|
||||
add_mmio_region(0xFEC00000, 0x300000, this);
|
||||
|
||||
this->pci_0_bus.clear();
|
||||
this->io_space_devs.clear();
|
||||
}
|
||||
|
||||
MPC106::~MPC106() {
|
||||
this->pci_0_bus.clear();
|
||||
int MPC106::device_postinit()
|
||||
{
|
||||
std::string pci_dev_name;
|
||||
|
||||
static const std::map<std::string, int> pci_slots = {
|
||||
{"pci_A1", 0xD}, {"pci_B1", 0xE}, {"pci_C1", 0xF}
|
||||
};
|
||||
|
||||
for (auto& slot : pci_slots) {
|
||||
pci_dev_name = GET_STR_PROP(slot.first);
|
||||
if (!pci_dev_name.empty()) {
|
||||
this->attach_pci_device(pci_dev_name, slot.second);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t MPC106::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
uint32_t MPC106::read(uint32_t rgn_start, uint32_t offset, int size) {
|
||||
uint32_t result;
|
||||
|
||||
if (reg_start == 0xFE000000) {
|
||||
/* broadcast I/O request to devices that support I/O space
|
||||
until a device returns true that means "request accepted" */
|
||||
if (rgn_start == 0xFE000000) {
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_read(offset, size, &result)) {
|
||||
return result;
|
||||
@@ -75,15 +93,15 @@ uint32_t MPC106::read(uint32_t reg_start, uint32_t offset, int size) {
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME: reading from CONFIG_ADDR is ignored for now */
|
||||
// FIXME: reading from CONFIG_ADDR is ignored for now
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MPC106::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) {
|
||||
if (reg_start == 0xFE000000) {
|
||||
/* broadcast I/O request to devices that support I/O space
|
||||
until a device returns true that means "request accepted" */
|
||||
void MPC106::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size) {
|
||||
if (rgn_start == 0xFE000000) {
|
||||
// broadcast I/O request to devices that support I/O space
|
||||
// until a device returns true that means "request accepted"
|
||||
for (auto& dev : this->io_space_devs) {
|
||||
if (dev->pci_io_write(offset, value, size)) {
|
||||
return;
|
||||
@@ -104,31 +122,33 @@ uint32_t MPC106::pci_read(uint32_t size) {
|
||||
int bus_num, dev_num, fun_num, reg_offs;
|
||||
|
||||
bus_num = (this->config_addr >> 8) & 0xFF;
|
||||
if (bus_num) {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: read attempt from non-local PCI bus, config_addr = %x \n",
|
||||
this->name.c_str(),
|
||||
this->config_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dev_num = (this->config_addr >> 19) & 0x1F;
|
||||
fun_num = (this->config_addr >> 16) & 0x07;
|
||||
reg_offs = (this->config_addr >> 24) & 0xFC;
|
||||
|
||||
if (bus_num) {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: read attempt from non-local PCI bus, config_addr = %x %02x:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), this->config_addr, bus_num, dev_num, fun_num, reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
|
||||
if (dev_num == 0 && fun_num == 0) { // dev_num 0 is assigned to myself
|
||||
return this->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
if (this->pci_0_bus.count(dev_num)) {
|
||||
return this->pci_0_bus[dev_num]->pci_cfg_read(reg_offs, size);
|
||||
if (this->dev_map.count(dev_num)) {
|
||||
return this->dev_map[dev_num]->pci_cfg_read(reg_offs, size);
|
||||
} else {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: read attempt from non-existing PCI device %d \n",
|
||||
this->name.c_str(),
|
||||
dev_num);
|
||||
return 0;
|
||||
"%s err: read attempt from non-existing PCI device %02x:%02x.%x @%02x.%c",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size
|
||||
);
|
||||
return 0xFFFFFFFFUL; // PCI spec §6.1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,79 +159,72 @@ void MPC106::pci_write(uint32_t value, uint32_t size) {
|
||||
int bus_num, dev_num, fun_num, reg_offs;
|
||||
|
||||
bus_num = (this->config_addr >> 8) & 0xFF;
|
||||
if (bus_num) {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: write attempt to non-local PCI bus, config_addr = %x \n",
|
||||
this->name.c_str(),
|
||||
this->config_addr);
|
||||
return;
|
||||
}
|
||||
|
||||
dev_num = (this->config_addr >> 19) & 0x1F;
|
||||
fun_num = (this->config_addr >> 16) & 0x07;
|
||||
reg_offs = (this->config_addr >> 24) & 0xFC;
|
||||
|
||||
if (bus_num) {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: write attempt to non-local PCI bus, config_addr = %x %02x:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), this->config_addr, bus_num, dev_num, fun_num, reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size,
|
||||
size * 2, value
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dev_num == 0 && fun_num == 0) { // dev_num 0 is assigned to myself
|
||||
this->pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
if (this->pci_0_bus.count(dev_num)) {
|
||||
this->pci_0_bus[dev_num]->pci_cfg_write(reg_offs, value, size);
|
||||
if (this->dev_map.count(dev_num)) {
|
||||
this->dev_map[dev_num]->pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
LOG_F(
|
||||
ERROR,
|
||||
"%s err: write attempt to non-existing PCI device %d \n",
|
||||
this->name.c_str(),
|
||||
dev_num);
|
||||
"%s err: write attempt to non-existing PCI device %02x:%02x.%x @%02x.%c = %0*x",
|
||||
this->name.c_str(), bus_num, dev_num, fun_num, reg_offs,
|
||||
size == 4 ? 'l' : size == 2 ? 'w' : size == 1 ? 'b' : '0' + size,
|
||||
size * 2, value
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t MPC106::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
#ifdef MPC106_DEBUG
|
||||
LOG_F(9, "read from Grackle register %08X\n", reg_offs);
|
||||
LOG_F(9, "read from Grackle register %08X", reg_offs);
|
||||
#endif
|
||||
|
||||
if (reg_offs < 64) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, size);
|
||||
}
|
||||
|
||||
return read_mem(&this->my_pci_cfg_hdr[reg_offs], size);
|
||||
}
|
||||
|
||||
void MPC106::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
#ifdef MPC106_DEBUG
|
||||
LOG_F(9, "write %08X to Grackle register %08X\n", value, reg_offs);
|
||||
LOG_F(9, "write %08X to Grackle register %08X", value, reg_offs);
|
||||
#endif
|
||||
|
||||
if (reg_offs < 64) {
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, size);
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: implement write-protection for read-only registers
|
||||
|
||||
write_mem(&this->my_pci_cfg_hdr[reg_offs], value, size);
|
||||
|
||||
if (this->my_pci_cfg_hdr[0xF2] & 8) {
|
||||
#ifdef MPC106_DEBUG
|
||||
LOG_F(9, "MPC106: MCCR1[MEMGO] was set! \n");
|
||||
LOG_F(9, "MPC106: MCCR1[MEMGO] was set!");
|
||||
#endif
|
||||
setup_ram();
|
||||
}
|
||||
}
|
||||
|
||||
bool MPC106::pci_register_device(int dev_num, PCIDevice* dev_instance) {
|
||||
if (this->pci_0_bus.count(dev_num)) // is dev_num already registered?
|
||||
return false;
|
||||
|
||||
this->pci_0_bus[dev_num] = dev_instance;
|
||||
|
||||
dev_instance->set_host(this);
|
||||
|
||||
if (dev_instance->supports_io_space()) {
|
||||
this->io_space_devs.push_back(dev_instance);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MPC106::pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj) {
|
||||
// FIXME: add sanity checks!
|
||||
return this->add_mmio_region(start_addr, size, obj);
|
||||
}
|
||||
|
||||
void MPC106::setup_ram() {
|
||||
uint32_t mem_start, mem_end, ext_mem_start, ext_mem_end, bank_start, bank_end;
|
||||
uint32_t ram_size = 0;
|
||||
@@ -236,12 +249,27 @@ void MPC106::setup_ram() {
|
||||
bank_end = (((ext_mem_end >> bank * 8) & 3) << 30) |
|
||||
(((mem_end >> bank * 8) & 0xFF) << 20) | 0xFFFFFUL;
|
||||
if (bank && bank_start != ram_size)
|
||||
LOG_F(WARNING, "MPC106: RAM not contiguous! \n");
|
||||
LOG_F(WARNING, "MPC106: RAM not contiguous!");
|
||||
ram_size += bank_end - bank_start + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->add_ram_region(0, ram_size)) {
|
||||
LOG_F(ERROR, "MPC106 RAM allocation failed! \n");
|
||||
LOG_F(ERROR, "MPC106 RAM allocation failed!");
|
||||
}
|
||||
}
|
||||
|
||||
static const PropMap Grackle_Properties = {
|
||||
{"pci_A1",
|
||||
new StrProperty("")},
|
||||
{"pci_B1",
|
||||
new StrProperty("")},
|
||||
{"pci_C1",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription Grackle_Descriptor = {
|
||||
MPC106::create, {}, Grackle_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Grackle, Grackle_Descriptor);
|
||||
+11
-15
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -18,9 +18,8 @@ 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/>.
|
||||
*/
|
||||
/** MPC106 (Grackle) emulation
|
||||
|
||||
Author: Max Poliakovski
|
||||
/** MPC106 (Grackle) emulation
|
||||
|
||||
Grackle IC is a combined memory and PCI controller manufactured by Motorola.
|
||||
It's the central device in the Gossamer architecture.
|
||||
@@ -41,19 +40,22 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
class MPC106 : public MemCtrlBase, public PCIDevice, public PCIHost {
|
||||
public:
|
||||
MPC106();
|
||||
~MPC106();
|
||||
~MPC106() = default;
|
||||
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<MPC106>(new MPC106());
|
||||
}
|
||||
|
||||
/* PCI host bridge API */
|
||||
bool pci_register_device(int dev_num, PCIDevice* dev_instance);
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
int device_postinit();
|
||||
|
||||
protected:
|
||||
/* PCI access */
|
||||
@@ -68,8 +70,6 @@ protected:
|
||||
return true;
|
||||
};
|
||||
|
||||
bool pci_register_mmio_region(uint32_t start_addr, uint32_t size, PCIDevice* obj);
|
||||
|
||||
void setup_ram(void);
|
||||
|
||||
private:
|
||||
@@ -159,10 +159,6 @@ private:
|
||||
};
|
||||
|
||||
uint32_t config_addr;
|
||||
// uint32_t config_data;
|
||||
|
||||
std::unordered_map<int, PCIDevice*> pci_0_bus;
|
||||
std::vector<PCIDevice*> io_space_devs;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Platinum Memory/Display Controller emulation. */
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/platinum.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
using namespace Platinum;
|
||||
|
||||
PlatinumCtrl::PlatinumCtrl() : MemCtrlBase()
|
||||
{
|
||||
this->name = "Platinum Memory Controller";
|
||||
|
||||
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
|
||||
|
||||
// add MMIO region for the configuration and status registers
|
||||
add_mmio_region(0xF8000000, 0x500, this);
|
||||
|
||||
// determine actual VRAM size (min. 1MB, max. 4MB)
|
||||
this->vram_size = 1 << 20;
|
||||
|
||||
// insert video memory region into the main memory map
|
||||
this->add_ram_region(0xF1000000UL, this->vram_size);
|
||||
|
||||
// initialize the CPUID register with the following CPU:
|
||||
// PowerPC 601 @ 75 MHz, bus frequency: 37,5 MHz
|
||||
this->cpu_id = (0x3001 << 16) | ClkSrc3 | (CpuSpeed3::CPU_75_BUS_38 << 8);
|
||||
|
||||
this->display_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
}
|
||||
|
||||
uint32_t PlatinumCtrl::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
if (size != 4) {
|
||||
LOG_F(WARNING, "Platinum: unsupported register access size %d!", size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (offset) {
|
||||
case PlatinumReg::CPU_ID:
|
||||
return this->cpu_id;
|
||||
case PlatinumReg::DRAM_REFRESH:
|
||||
return this->dram_refresh;
|
||||
case PlatinumReg::BANK_0_BASE:
|
||||
case PlatinumReg::BANK_1_BASE:
|
||||
case PlatinumReg::BANK_2_BASE:
|
||||
case PlatinumReg::BANK_3_BASE:
|
||||
case PlatinumReg::BANK_4_BASE:
|
||||
case PlatinumReg::BANK_5_BASE:
|
||||
case PlatinumReg::BANK_6_BASE:
|
||||
case PlatinumReg::BANK_7_BASE:
|
||||
return this->bank_base[(offset - PlatinumReg::BANK_0_BASE) >> 4];
|
||||
case PlatinumReg::CACHE_CONFIG:
|
||||
return 0; // report no L2 cache installed
|
||||
case PlatinumReg::FB_BASE_ADDR:
|
||||
return this->fb_addr;
|
||||
case PlatinumReg::MON_ID_SENSE:
|
||||
LOG_F(INFO, "Platinum: display sense read");
|
||||
return (this->cur_mon_id ^ 7);
|
||||
default:
|
||||
LOG_F(WARNING, "Platinum: unknown register read at offset 0x%X", offset);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PlatinumCtrl::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
switch (offset) {
|
||||
case PlatinumReg::ROM_TIMING:
|
||||
this->rom_timing = value;
|
||||
break;
|
||||
case PlatinumReg::DRAM_TIMING:
|
||||
this->dram_timing = value;
|
||||
break;
|
||||
case PlatinumReg::DRAM_REFRESH:
|
||||
this->dram_refresh = value;
|
||||
break;
|
||||
case PlatinumReg::BANK_0_BASE:
|
||||
case PlatinumReg::BANK_1_BASE:
|
||||
case PlatinumReg::BANK_2_BASE:
|
||||
case PlatinumReg::BANK_3_BASE:
|
||||
case PlatinumReg::BANK_4_BASE:
|
||||
case PlatinumReg::BANK_5_BASE:
|
||||
case PlatinumReg::BANK_6_BASE:
|
||||
case PlatinumReg::BANK_7_BASE:
|
||||
this->bank_base[(offset - PlatinumReg::BANK_0_BASE) >> 4] = value;
|
||||
break;
|
||||
case PlatinumReg::FB_BASE_ADDR:
|
||||
this->fb_addr = value;
|
||||
LOG_F(INFO, "Platinum: Framebuffer address set to 0x%X", value);
|
||||
break;
|
||||
case PlatinumReg::FB_CONFIG_1:
|
||||
this->fb_config_1 = value;
|
||||
break;
|
||||
case PlatinumReg::FB_CONFIG_2:
|
||||
this->fb_config_2 = value;
|
||||
break;
|
||||
case PlatinumReg::VMEM_PAGE_MODE:
|
||||
this->vmem_fp_mode = value;
|
||||
break;
|
||||
case PlatinumReg::MON_ID_SENSE:
|
||||
LOG_F(INFO, "Platinum: display sense written with 0x%X", value);
|
||||
this->cur_mon_id = this->display_id->read_monitor_sense(value & 7, value ^ 7);
|
||||
break;
|
||||
case PlatinumReg::FB_RESET:
|
||||
this->fb_reset = value;
|
||||
break;
|
||||
case PlatinumReg::VRAM_REFRESH:
|
||||
this->vram_refresh = value;
|
||||
break;
|
||||
case PlatinumReg::SWATCH_CONFIG:
|
||||
this->swatch_config = value;
|
||||
break;
|
||||
case PlatinumReg::SWATCH_INT_MASK:
|
||||
this->swatch_int_mask = value;
|
||||
break;
|
||||
case PlatinumReg::SWATCH_HAL:
|
||||
LOG_F(INFO, "Swatch HAL set to 0x%X", value);
|
||||
break;
|
||||
case PlatinumReg::SWATCH_HFP:
|
||||
LOG_F(INFO, "Swatch HFP set to 0x%X", value);
|
||||
break;
|
||||
case PlatinumReg::SWATCH_HPIX:
|
||||
LOG_F(INFO, "Swatch HPIX set to 0x%X", value);
|
||||
break;
|
||||
case PlatinumReg::SWATCH_VAL:
|
||||
LOG_F(INFO, "Swatch VAL set to 0x%X", value);
|
||||
break;
|
||||
case PlatinumReg::SWATCH_VFP:
|
||||
LOG_F(INFO, "Swatch VFP set to 0x%X", value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "Platinum: unknown register write at offset 0x%X", offset);
|
||||
}
|
||||
}
|
||||
|
||||
void PlatinumCtrl::insert_ram_dimm(int slot_num, uint32_t capacity)
|
||||
{
|
||||
if (slot_num < 0 || slot_num >= 4) {
|
||||
ABORT_F("Platinum: invalid DIMM slot %d", slot_num);
|
||||
}
|
||||
|
||||
switch (capacity) {
|
||||
case DRAM_CAP_2MB:
|
||||
case DRAM_CAP_4MB:
|
||||
case DRAM_CAP_8MB:
|
||||
case DRAM_CAP_16MB:
|
||||
case DRAM_CAP_32MB:
|
||||
case DRAM_CAP_64MB:
|
||||
this->bank_size[slot_num * 2 + 0] = capacity;
|
||||
break;
|
||||
case DRAM_CAP_128MB:
|
||||
this->bank_size[slot_num * 2 + 0] = DRAM_CAP_64MB;
|
||||
this->bank_size[slot_num * 2 + 1] = DRAM_CAP_64MB;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("Platinum: unsupported DRAM capacity %d", capacity);
|
||||
}
|
||||
}
|
||||
|
||||
void PlatinumCtrl::map_phys_ram()
|
||||
{
|
||||
uint32_t total_ram = 0;
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
total_ram += this->bank_size[i];
|
||||
}
|
||||
|
||||
if (total_ram > DRAM_CAP_64MB) {
|
||||
ABORT_F("Platinum: RAM bigger than 64MB not supported yet");
|
||||
}
|
||||
|
||||
if (!add_ram_region(0x00000000, total_ram)) {
|
||||
ABORT_F("Platinum: could not allocate RAM storage");
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription Platinum_Descriptor = {
|
||||
PlatinumCtrl::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Platinum, Platinum_Descriptor);
|
||||
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Platinum Memory Controller definitions.
|
||||
|
||||
Author: Max Poliakovski
|
||||
|
||||
Platinum is a single chip memory and video subsystem controller designed
|
||||
especially for the Power Macintosh 7200 computer, code name Catalyst.
|
||||
*/
|
||||
|
||||
#ifndef PLATINUM_MEMCTRL_H
|
||||
#define PLATINUM_MEMCTRL_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/mmiodevice.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/video/displayid.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
namespace Platinum {
|
||||
|
||||
/** Clock source encoding in the CPUID register */
|
||||
enum {
|
||||
ClkSrc0 = 0x0000, // 33 MHz
|
||||
ClkSrc2 = 0x8000, // 20 MHz
|
||||
ClkSrc3 = 0x8040 // 31,3344 MHz
|
||||
};
|
||||
|
||||
/** CPU/Bus speed encoding for ClkSrc0 */
|
||||
enum CpuSpeed0 {
|
||||
CPU_66_BUS_33 = 0,
|
||||
CPU_80_BUS_40_1 = 1,
|
||||
CPU_80_BUS_27_1 = 2,
|
||||
CPU_100_BUS_50 = 3,
|
||||
CPU_100_BUS_33 = 4,
|
||||
CPU_120_BUS_60 = 5,
|
||||
CPU_120_BUS_40 = 6,
|
||||
CPU_120_BUS_30 = 7,
|
||||
CPU_133_BUS_66 = 8,
|
||||
CPU_133_BUS_44 = 9,
|
||||
CPU_133_BUS_33 = 10,
|
||||
CPU_150_BUS_75 = 11,
|
||||
CPU_150_BUS_50 = 12,
|
||||
CPU_150_BUS_37 = 13
|
||||
};
|
||||
|
||||
/** CPU/Bus speed encoding for ClkSrc2 */
|
||||
enum CpuSpeed2 {
|
||||
CPU_40_BUS_20 = 0,
|
||||
CPU_48_BUS_24 = 1,
|
||||
CPU_48_BUS_16 = 2,
|
||||
CPU_60_BUS_30 = 3,
|
||||
CPU_60_BUS_20 = 4,
|
||||
CPU_72_BUS_36 = 5,
|
||||
CPU_72_BUS_24 = 6,
|
||||
CPU_72_BUS_18 = 7,
|
||||
CPU_80_BUS_40_2 = 8,
|
||||
CPU_80_BUS_27_2 = 9,
|
||||
CPU_80_BUS_20 = 10,
|
||||
CPU_90_BUS_45 = 11,
|
||||
CPU_90_BUS_30 = 12,
|
||||
CPU_90_BUS_22 = 13
|
||||
};
|
||||
|
||||
/** CPU/Bus speed encoding for ClkSrc3 */
|
||||
enum CpuSpeed3 {
|
||||
CPU_62_BUS_31 = 0,
|
||||
CPU_75_BUS_38 = 1, // actual bus frequency: 37500000 Hz
|
||||
CPU_75_BUS_25 = 2,
|
||||
CPU_94_BUS_47 = 3,
|
||||
CPU_94_BUS_31 = 4,
|
||||
CPU_113_BUS_56 = 5,
|
||||
CPU_113_BUS_38 = 6, // actual bus frequency: 37500000 Hz
|
||||
CPU_113_BUS_28 = 7,
|
||||
CPU_125_BUS_64 = 8, // actual bus frequency: 63500000 Hz
|
||||
CPU_125_BUS_42 = 9,
|
||||
CPU_125_BUS_31 = 10,
|
||||
CPU_141_BUS_72 = 11, // actual bus frequency: 71500000 Hz
|
||||
CPU_141_BUS_47 = 12,
|
||||
CPU_141_BUS_35 = 13
|
||||
};
|
||||
|
||||
/** Configuration and status register offsets. */
|
||||
enum PlatinumReg : uint32_t {
|
||||
CPU_ID = 0x000,
|
||||
ASIC_REVISION = 0x010,
|
||||
ROM_TIMING = 0x020,
|
||||
CACHE_CONFIG = 0x030,
|
||||
DRAM_TIMING = 0x040,
|
||||
DRAM_REFRESH = 0x050,
|
||||
BANK_0_BASE = 0x060,
|
||||
BANK_1_BASE = 0x070,
|
||||
BANK_2_BASE = 0x080,
|
||||
BANK_3_BASE = 0x090,
|
||||
BANK_4_BASE = 0x0A0,
|
||||
BANK_5_BASE = 0x0B0,
|
||||
BANK_6_BASE = 0x0C0,
|
||||
BANK_7_BASE = 0x0D0,
|
||||
GP_SW_SCRATCH = 0x0E0,
|
||||
PCI_ADDR_MASK = 0x0F0,
|
||||
FB_BASE_ADDR = 0x100,
|
||||
FB_CONFIG_1 = 0x140,
|
||||
FB_CONFIG_2 = 0x150,
|
||||
VMEM_PAGE_MODE = 0x160,
|
||||
MON_ID_SENSE = 0x170,
|
||||
FB_RESET = 0x180,
|
||||
VRAM_REFRESH = 0x1B0,
|
||||
SWATCH_CONFIG = 0x200,
|
||||
SWATCH_INT_MASK = 0x210,
|
||||
SWATCH_HAL = 0x300,
|
||||
SWATCH_HFP = 0x310,
|
||||
SWATCH_HPIX = 0x320,
|
||||
SWATCH_VAL = 0x370,
|
||||
SWATCH_VFP = 0x380,
|
||||
IRIDIUM_CONFIG = 0x4A0,
|
||||
};
|
||||
|
||||
// FB_RESET register bits.
|
||||
enum {
|
||||
VRAM_SM_RESET = (1 << 0), // VRAM state machine reset
|
||||
VREFRESH_SM_RESET = (1 << 1), // Video refresh state machine reset
|
||||
SWATCH_RESET = (1 << 2), // Swatch reset
|
||||
};
|
||||
|
||||
}; // namespace Platinum
|
||||
|
||||
class PlatinumCtrl : public MemCtrlBase, public MMIODevice {
|
||||
public:
|
||||
PlatinumCtrl();
|
||||
~PlatinumCtrl() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<PlatinumCtrl>(new PlatinumCtrl());
|
||||
}
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
void insert_ram_dimm(int slot_num, uint32_t capacity);
|
||||
void map_phys_ram();
|
||||
|
||||
private:
|
||||
uint32_t cpu_id;
|
||||
uint8_t cpu_type; // 0 - MPC601, 1 - 603/604 CPU
|
||||
|
||||
// memory controller state
|
||||
uint32_t rom_timing = 0;
|
||||
uint32_t dram_timing = 0xEFF;
|
||||
uint32_t dram_refresh = 0x1F4;
|
||||
uint32_t bank_base[8];
|
||||
uint32_t bank_size[8] = { 0 };
|
||||
|
||||
// display controller state
|
||||
uint32_t fb_addr = 0xF1000000;
|
||||
uint32_t fb_config_1 = 0x1F00;
|
||||
uint32_t fb_config_2 = 0x1FFF;
|
||||
uint32_t fb_reset = 7;
|
||||
uint32_t vram_refresh = 0x1F4;
|
||||
uint32_t vram_size = 0;
|
||||
uint8_t vmem_fp_mode = 0;
|
||||
uint8_t cur_mon_id = 0;
|
||||
|
||||
// video timing generator (Swatch) state
|
||||
uint32_t swatch_config = 0xFFD;
|
||||
uint32_t swatch_int_mask = 0;
|
||||
|
||||
std::unique_ptr<DisplayID> display_id;
|
||||
};
|
||||
|
||||
#endif // PLATINUM_MEMCTRL_H
|
||||
@@ -0,0 +1,480 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Character I/O backend implementations. */
|
||||
|
||||
#include <devices/serial/chario.h>
|
||||
#include <loguru.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
bool CharIoNull::rcv_char_available()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int CharIoNull::xmit_char(uint8_t c)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CharIoNull::rcv_char(uint8_t *c)
|
||||
{
|
||||
*c = 0xFF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//======================== STDIO character I/O backend ========================
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
|
||||
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD old_in_mode, old_out_mode;
|
||||
int old_stdin_trans_mode;
|
||||
|
||||
void CharIoStdin::mysig_handler(int signum) {
|
||||
SetStdHandle(signum, hInput);
|
||||
SetStdHandle(signum, hOutput);
|
||||
}
|
||||
|
||||
int CharIoStdin::rcv_enable() {
|
||||
if (this->stdio_inited)
|
||||
return 0;
|
||||
|
||||
GetConsoleMode(hInput, &old_in_mode);
|
||||
GetConsoleMode(hOutput, &old_out_mode);
|
||||
|
||||
DWORD new_in_mode = old_in_mode;
|
||||
new_in_mode &= ~ENABLE_ECHO_INPUT;
|
||||
new_in_mode &= ~ENABLE_LINE_INPUT;
|
||||
new_in_mode &= ~ENABLE_PROCESSED_INPUT;
|
||||
|
||||
new_in_mode |= ENABLE_EXTENDED_FLAGS;
|
||||
new_in_mode |= ENABLE_INSERT_MODE;
|
||||
new_in_mode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
|
||||
|
||||
SetConsoleMode(hInput, new_in_mode);
|
||||
|
||||
SetConsoleMode(hOutput, old_out_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
|
||||
|
||||
// disable automatic CRLF translation
|
||||
old_stdin_trans_mode = _setmode(_fileno(stdin), _O_BINARY);
|
||||
|
||||
this->stdio_inited = true;
|
||||
|
||||
LOG_F(INFO, "Winterm: receiver initialized");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CharIoStdin::rcv_disable() {
|
||||
if (!this->stdio_inited)
|
||||
return;
|
||||
|
||||
// restore original console mode
|
||||
SetConsoleMode(hInput, old_in_mode);
|
||||
SetConsoleMode(hOutput, old_out_mode);
|
||||
|
||||
// restore original translation mode
|
||||
_setmode(_fileno(stdin), old_stdin_trans_mode);
|
||||
|
||||
this->stdio_inited = false;
|
||||
|
||||
LOG_F(INFO, "Winterm: receiver disabled");
|
||||
}
|
||||
|
||||
bool CharIoStdin::rcv_char_available() {
|
||||
DWORD events;
|
||||
INPUT_RECORD buffer;
|
||||
|
||||
PeekConsoleInput(hInput, &buffer, 1, &events);
|
||||
return !!(events > 0);
|
||||
}
|
||||
|
||||
int CharIoStdin::xmit_char(uint8_t c) {
|
||||
_write(_fileno(stdout), &c, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CharIoStdin::rcv_char(uint8_t* c) {
|
||||
_read(_fileno(stdin), c, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else // non-Windows OS (Linux, mac OS etc.)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/select.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static struct sigaction old_act_sigint, new_act_sigint;
|
||||
static struct sigaction old_act_sigterm, new_act_sigterm;
|
||||
static struct termios orig_termios;
|
||||
|
||||
void CharIoStdin::mysig_handler(int signum)
|
||||
{
|
||||
// restore original terminal state
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios);
|
||||
|
||||
// restore original signal handler for SIGINT
|
||||
signal(SIGINT, old_act_sigint.sa_handler);
|
||||
signal(SIGTERM, old_act_sigterm.sa_handler);
|
||||
|
||||
LOG_F(INFO, "Old terminal state restored, SIG#=%d", signum);
|
||||
|
||||
// re-post signal
|
||||
raise(signum);
|
||||
}
|
||||
|
||||
int CharIoStdin::rcv_enable()
|
||||
{
|
||||
if (this->stdio_inited)
|
||||
return 0;
|
||||
|
||||
// save original terminal state
|
||||
tcgetattr(STDIN_FILENO, &orig_termios);
|
||||
|
||||
struct termios new_termios = orig_termios;
|
||||
|
||||
new_termios.c_cflag &= ~(CSIZE | PARENB);
|
||||
new_termios.c_cflag |= CS8;
|
||||
new_termios.c_lflag &= ~(ECHO | ICANON | ISIG);
|
||||
new_termios.c_iflag &= ~(ICRNL);
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new_termios);
|
||||
|
||||
// save original signal handler for SIGINT
|
||||
// then redirect SIGINT to new handler
|
||||
memset(&new_act_sigint, 0, sizeof(new_act_sigint));
|
||||
new_act_sigint.sa_handler = mysig_handler;
|
||||
sigaction(SIGINT, &new_act_sigint, &old_act_sigint);
|
||||
|
||||
// save original signal handler for SIGTERM
|
||||
// then redirect SIGTERM to new handler
|
||||
memset(&new_act_sigterm, 0, sizeof(new_act_sigterm));
|
||||
new_act_sigterm.sa_handler = mysig_handler;
|
||||
sigaction(SIGTERM, &new_act_sigterm, &old_act_sigterm);
|
||||
|
||||
this->stdio_inited = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CharIoStdin::rcv_disable()
|
||||
{
|
||||
if (!this->stdio_inited)
|
||||
return;
|
||||
|
||||
// restore original terminal state
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &orig_termios);
|
||||
|
||||
// restore original signal handler for SIGINT
|
||||
signal(SIGINT, old_act_sigint.sa_handler);
|
||||
|
||||
// restore original signal handler for SIGTERM
|
||||
signal(SIGTERM, old_act_sigterm.sa_handler);
|
||||
|
||||
this->stdio_inited = false;
|
||||
}
|
||||
|
||||
bool CharIoStdin::rcv_char_available()
|
||||
{
|
||||
static int consecutivechars = 0;
|
||||
|
||||
if (consecutivechars >= 15) {
|
||||
consecutivechars++;
|
||||
if (consecutivechars >= 400)
|
||||
consecutivechars = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
fd_set readfds;
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(STDIN_FILENO, &readfds);
|
||||
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
int sel_rv = select(1, &readfds, NULL, NULL, &timeout);
|
||||
if (sel_rv > 0)
|
||||
consecutivechars++;
|
||||
else
|
||||
consecutivechars = 0;
|
||||
return sel_rv > 0;
|
||||
}
|
||||
|
||||
int CharIoStdin::xmit_char(uint8_t c)
|
||||
{
|
||||
write(STDOUT_FILENO, &c, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CharIoStdin::rcv_char(uint8_t *c)
|
||||
{
|
||||
read(STDIN_FILENO, c, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//======================== SOCKET character I/O backend ========================
|
||||
#ifdef _WIN32
|
||||
|
||||
#else // non-Windows OS (Linux, mac OS etc.)
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/errno.h>
|
||||
|
||||
|
||||
CharIoSocket::CharIoSocket()
|
||||
{
|
||||
int rc;
|
||||
|
||||
path = "dingussocket";
|
||||
|
||||
do {
|
||||
rc = unlink(path);
|
||||
if (rc == 0) {
|
||||
LOG_F(INFO, "socket unlinked %s", path);
|
||||
}
|
||||
else if (errno != ENOENT) {
|
||||
LOG_F(INFO, "socket unlink err: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
sockaddr_un address;
|
||||
memset(&address, 0, sizeof(address));
|
||||
address.sun_family = AF_UNIX;
|
||||
strcpy(address.sun_path, path);
|
||||
|
||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sockfd == -1) {
|
||||
LOG_F(INFO, "socket create err: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
rc = bind(sockfd, (sockaddr*)(&address), sizeof(address));
|
||||
if (rc == -1) {
|
||||
LOG_F(INFO, "socket bind err: %s", strerror(errno));
|
||||
close(sockfd);
|
||||
sockfd = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
rc = listen(sockfd, 100);
|
||||
if (rc == -1) {
|
||||
LOG_F(INFO, "socket listen err: %s", strerror(errno));
|
||||
close(sockfd);
|
||||
sockfd = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "socket listen %d", sockfd);
|
||||
|
||||
} while (0);
|
||||
};
|
||||
|
||||
|
||||
CharIoSocket::~CharIoSocket() {
|
||||
unlink(path);
|
||||
if (errno != ENOENT) {
|
||||
LOG_F(INFO, "socket unlink err: %s", strerror(errno));
|
||||
}
|
||||
if (sockfd != -1) {
|
||||
close(sockfd);
|
||||
sockfd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int CharIoSocket::rcv_enable()
|
||||
{
|
||||
if (this->socket_inited)
|
||||
return 0;
|
||||
|
||||
this->socket_inited = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CharIoSocket::rcv_disable()
|
||||
{
|
||||
if (!this->socket_inited)
|
||||
return;
|
||||
|
||||
this->socket_inited = false;
|
||||
}
|
||||
|
||||
bool CharIoSocket::rcv_char_available()
|
||||
{
|
||||
static int consecutivechars = 0;
|
||||
static int count = 0;
|
||||
|
||||
if (consecutivechars >= 15) {
|
||||
consecutivechars++;
|
||||
if (consecutivechars >= 800)
|
||||
consecutivechars = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sel_rv = 0;
|
||||
bool havechars = false;
|
||||
fd_set readfds;
|
||||
fd_set writefds;
|
||||
fd_set errorfds;
|
||||
|
||||
int sockmax = 0;
|
||||
if (sockfd != -1) {
|
||||
FD_ZERO(&readfds);
|
||||
FD_SET(sockfd, &readfds);
|
||||
if (sockfd > sockmax) sockmax = sockfd;
|
||||
if (acceptfd != -1) {
|
||||
FD_SET(acceptfd, &readfds);
|
||||
if (acceptfd > sockmax) sockmax = acceptfd;
|
||||
}
|
||||
writefds = readfds;
|
||||
errorfds = readfds;
|
||||
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
sel_rv = select(sockmax + 1, &readfds, &writefds, &errorfds, &timeout);
|
||||
if (sel_rv == -1) {
|
||||
LOG_F(INFO, "socket select err: %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
if (sel_rv > 0) {
|
||||
if (sockfd != -1) {
|
||||
if (FD_ISSET(sockfd, &readfds)) {
|
||||
uint8_t c;
|
||||
int received = recv(sockfd, &c, 1, 0);
|
||||
if (received == -1) {
|
||||
if (acceptfd == -1) {
|
||||
//LOG_F(INFO, "socket sock read (not accepted yet) err: %s", strerror(errno)); // this happens once before accept
|
||||
}
|
||||
else {
|
||||
LOG_F(INFO, "socket sock read err: %s", strerror(errno)); // should never happen
|
||||
}
|
||||
}
|
||||
else if (received == 1) {
|
||||
LOG_F(INFO, "socket sock read '%c'", c); // should never happen
|
||||
}
|
||||
else {
|
||||
LOG_F(INFO, "socket sock read %d", received); // should never happen
|
||||
}
|
||||
|
||||
if (acceptfd == -1) {
|
||||
sockaddr_un acceptfdaddr;
|
||||
memset(&acceptfdaddr, 0, sizeof(acceptfdaddr));
|
||||
socklen_t len = sizeof(acceptfdaddr);
|
||||
acceptfd = accept(sockfd, (struct sockaddr *) &acceptfdaddr, &len);
|
||||
if (acceptfd == -1){
|
||||
LOG_F(INFO, "socket accept err: %s", strerror(errno));
|
||||
}
|
||||
else {
|
||||
LOG_F(INFO, "socket accept %d", acceptfd);
|
||||
}
|
||||
}
|
||||
} // if read
|
||||
|
||||
if (FD_ISSET(sockfd, &writefds)) {
|
||||
LOG_F(INFO, "socket sock write");
|
||||
}
|
||||
|
||||
if (FD_ISSET(sockfd, &errorfds)) {
|
||||
LOG_F(INFO, "socket sock error");
|
||||
}
|
||||
} // if sockfd
|
||||
|
||||
if (acceptfd != -1) {
|
||||
if (FD_ISSET(acceptfd, &readfds)) {
|
||||
// LOG_F(INFO, "socket accept read havechars");
|
||||
havechars = true;
|
||||
consecutivechars++;
|
||||
} // if read
|
||||
|
||||
if (FD_ISSET(acceptfd, &writefds)) {
|
||||
// LOG_F(INFO, "socket accept write"); // this is usually always true
|
||||
}
|
||||
|
||||
if (FD_ISSET(acceptfd, &errorfds)) {
|
||||
LOG_F(INFO, "socket accept error");
|
||||
}
|
||||
} // if acceptfd
|
||||
}
|
||||
else
|
||||
consecutivechars = 0;
|
||||
return havechars;
|
||||
}
|
||||
|
||||
int CharIoSocket::xmit_char(uint8_t c)
|
||||
{
|
||||
if (acceptfd == -1)
|
||||
CharIoSocket::rcv_char_available();
|
||||
|
||||
if (acceptfd != -1) {
|
||||
int sent = send(acceptfd, &c, 1, 0);
|
||||
if (sent == -1) {
|
||||
LOG_F(INFO, "socket accept write err: %s", strerror(errno));
|
||||
}
|
||||
if (sent == 1) {
|
||||
// LOG_F(INFO, "socket accept write '%c'", c);
|
||||
}
|
||||
else {
|
||||
LOG_F(INFO, "socket accept write %d", sent);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CharIoSocket::rcv_char(uint8_t *c)
|
||||
{
|
||||
if (acceptfd == -1)
|
||||
CharIoSocket::rcv_char_available();
|
||||
|
||||
if (acceptfd != -1) {
|
||||
int received = recv(acceptfd, c, 1, 0);
|
||||
if (received == -1) {
|
||||
LOG_F(INFO, "socket accept read err: %s", strerror(errno));
|
||||
}
|
||||
else if (received == 1) {
|
||||
// LOG_F(INFO, "socket accept read '%c'", c ? *c : 0);
|
||||
}
|
||||
else {
|
||||
LOG_F(INFO, "socket accept read %d", received);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** Character I/O definitions. */
|
||||
|
||||
#ifndef CHAR_IO_H
|
||||
#define CHAR_IO_H
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#ifdef _WIN32
|
||||
#else
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
enum {
|
||||
CHARIO_BE_NULL = 0, // NULL backend: swallows everything, receives nothing
|
||||
CHARIO_BE_STDIO = 1, // STDIO backend: uses STDIN for input and STDOUT for output
|
||||
CHARIO_BE_SOCKET = 2, // socket backend: uses a socket for input and output
|
||||
};
|
||||
|
||||
/** Interface for character I/O backends. */
|
||||
class CharIoBackEnd {
|
||||
public:
|
||||
CharIoBackEnd() = default;
|
||||
virtual ~CharIoBackEnd() = default;
|
||||
|
||||
virtual int rcv_enable() { return 0; };
|
||||
virtual void rcv_disable() {};
|
||||
virtual bool rcv_char_available() = 0;
|
||||
virtual int xmit_char(uint8_t c) = 0;
|
||||
virtual int rcv_char(uint8_t *c) = 0;
|
||||
};
|
||||
|
||||
/** Null character I/O backend. */
|
||||
class CharIoNull : public CharIoBackEnd {
|
||||
public:
|
||||
CharIoNull() = default;
|
||||
~CharIoNull() = default;
|
||||
|
||||
bool rcv_char_available();
|
||||
int xmit_char(uint8_t c);
|
||||
int rcv_char(uint8_t *c);
|
||||
};
|
||||
|
||||
/** Stdin character I/O backend. */
|
||||
class CharIoStdin : public CharIoBackEnd {
|
||||
public:
|
||||
CharIoStdin() { this->stdio_inited = false; };
|
||||
~CharIoStdin() = default;
|
||||
|
||||
int rcv_enable();
|
||||
void rcv_disable();
|
||||
bool rcv_char_available();
|
||||
int xmit_char(uint8_t c);
|
||||
int rcv_char(uint8_t *c);
|
||||
|
||||
private:
|
||||
static void mysig_handler(int signum);
|
||||
bool stdio_inited;
|
||||
};
|
||||
|
||||
/** Socket character I/O backend. */
|
||||
class CharIoSocket : public CharIoBackEnd {
|
||||
public:
|
||||
CharIoSocket();
|
||||
~CharIoSocket();
|
||||
|
||||
int rcv_enable();
|
||||
void rcv_disable();
|
||||
bool rcv_char_available();
|
||||
int xmit_char(uint8_t c);
|
||||
int rcv_char(uint8_t *c);
|
||||
|
||||
private:
|
||||
bool socket_inited = false;
|
||||
int sockfd = -1;
|
||||
int acceptfd = -1;
|
||||
const char* path = 0;
|
||||
};
|
||||
|
||||
#endif // CHAR_IO_H
|
||||
+93
-12
@@ -21,17 +21,43 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** @file Enhanced Serial Communications Controller (ESCC) emulation. */
|
||||
|
||||
#include "escc.h"
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/serial/chario.h>
|
||||
#include <devices/serial/escc.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/** Remap the compatible addressing scheme to MacRISC one. */
|
||||
const uint8_t compat_to_macrisc[6] = {
|
||||
EsccReg::Port_B_Cmd, EsccReg::Port_A_Cmd,
|
||||
EsccReg::Port_B_Data, EsccReg::Port_A_Data,
|
||||
EsccReg::Enh_Reg_B, EsccReg::Enh_Reg_A
|
||||
};
|
||||
|
||||
EsccController::EsccController()
|
||||
{
|
||||
// allocate channels
|
||||
this->ch_a = std::unique_ptr<EsccChannel> (new EsccChannel("A"));
|
||||
this->ch_b = std::unique_ptr<EsccChannel> (new EsccChannel("B"));
|
||||
|
||||
// attach backends
|
||||
std::string backend_name = GET_STR_PROP("serial_backend");
|
||||
|
||||
this->ch_a->attach_backend(
|
||||
(backend_name == "stdio") ? CHARIO_BE_STDIO :
|
||||
#ifdef _WIN32
|
||||
#else
|
||||
(backend_name == "socket") ? CHARIO_BE_SOCKET :
|
||||
#endif
|
||||
CHARIO_BE_NULL
|
||||
);
|
||||
this->ch_b->attach_backend(CHARIO_BE_NULL);
|
||||
|
||||
this->reg_ptr = 0;
|
||||
}
|
||||
|
||||
@@ -73,7 +99,7 @@ uint8_t EsccController::read(uint8_t reg_offset)
|
||||
case EsccReg::Port_A_Data:
|
||||
return this->ch_a->receive_byte();
|
||||
default:
|
||||
LOG_F(9, "ESCC: reading from unimplemented register %d", reg_offset);
|
||||
LOG_F(9, "ESCC: reading from unimplemented register 0x%x", reg_offset);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -95,7 +121,7 @@ void EsccController::write(uint8_t reg_offset, uint8_t value)
|
||||
this->ch_a->send_byte(value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(9, "ESCC: writing 0x%X to unimplemented register %d", value, reg_offset);
|
||||
LOG_F(9, "ESCC: writing 0x%X to unimplemented register 0x%x", value, reg_offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,9 +163,31 @@ void EsccController::write_internal(EsccChannel *ch, uint8_t value)
|
||||
}
|
||||
|
||||
// ======================== ESCC Channel methods ==============================
|
||||
void EsccChannel::attach_backend(int id)
|
||||
{
|
||||
switch(id) {
|
||||
case CHARIO_BE_NULL:
|
||||
this->chario = std::unique_ptr<CharIoBackEnd> (new CharIoNull);
|
||||
break;
|
||||
case CHARIO_BE_STDIO:
|
||||
this->chario = std::unique_ptr<CharIoBackEnd> (new CharIoStdin);
|
||||
break;
|
||||
#ifdef _WIN32
|
||||
#else
|
||||
case CHARIO_BE_SOCKET:
|
||||
this->chario = std::unique_ptr<CharIoBackEnd> (new CharIoSocket);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
LOG_F(ERROR, "ESCC: unknown backend ID %d, using NULL instead", id);
|
||||
this->chario = std::unique_ptr<CharIoBackEnd> (new CharIoNull);
|
||||
}
|
||||
}
|
||||
|
||||
void EsccChannel::reset(bool hw_reset)
|
||||
{
|
||||
this->chario->rcv_disable();
|
||||
|
||||
this->write_regs[1] &= 0x24;
|
||||
this->write_regs[3] &= 0xFE;
|
||||
this->write_regs[4] |= 0x04;
|
||||
@@ -177,15 +225,22 @@ void EsccChannel::write_reg(int reg_num, uint8_t value)
|
||||
{
|
||||
switch (reg_num) {
|
||||
case 3:
|
||||
if (value & 0x11) {
|
||||
if ((this->write_regs[3] ^ value) & 0x10) {
|
||||
this->write_regs[3] |= 0x10;
|
||||
this->read_regs[0] |= 0x10; // set SYNC_HUNT flag
|
||||
LOG_F(9, "ESCC: Hunt mode entered.");
|
||||
}
|
||||
if ((this->write_regs[3] ^ value) & 0x10) {
|
||||
this->write_regs[3] |= 0x10;
|
||||
this->read_regs[0] |= 0x10; // set SYNC_HUNT flag
|
||||
LOG_F(9, "ESCC: Hunt mode entered.");
|
||||
}
|
||||
if ((this->write_regs[3] ^ value) & 1) {
|
||||
if (value & 1) {
|
||||
this->write_regs[3] |= 0x1;
|
||||
this->chario->rcv_enable();
|
||||
LOG_F(9, "ESCC: receiver enabled.");
|
||||
} else {
|
||||
this->write_regs[3] ^= 0x1;
|
||||
this->chario->rcv_disable();
|
||||
LOG_F(9, "ESCC: receiver disabled.");
|
||||
this->write_regs[3] |= 0x10; // enter HUNT mode
|
||||
this->read_regs[0] |= 0x10; // set SYNC_HUNT flag
|
||||
}
|
||||
}
|
||||
this->write_regs[3] = (this->write_regs[3] & 0x11) | (value & 0xEE);
|
||||
@@ -198,6 +253,8 @@ void EsccChannel::write_reg(int reg_num, uint8_t value)
|
||||
break;
|
||||
case 14:
|
||||
switch (value >> 5) {
|
||||
case DPLL_NULL_CMD:
|
||||
break;
|
||||
case DPLL_ENTER_SRC_MODE:
|
||||
this->dpll_active = 1;
|
||||
this->read_regs[10] &= 0x3F;
|
||||
@@ -238,16 +295,40 @@ void EsccChannel::write_reg(int reg_num, uint8_t value)
|
||||
|
||||
uint8_t EsccChannel::read_reg(int reg_num)
|
||||
{
|
||||
if (!reg_num) {
|
||||
if (this->chario->rcv_char_available()) {
|
||||
this->read_regs[0] |= 1;
|
||||
}
|
||||
}
|
||||
return this->read_regs[reg_num];
|
||||
}
|
||||
|
||||
void EsccChannel::send_byte(uint8_t value)
|
||||
{
|
||||
// Put one byte into the Data FIFO
|
||||
// TODO: put one byte into the Data FIFO
|
||||
|
||||
this->chario->xmit_char(value);
|
||||
}
|
||||
|
||||
uint8_t EsccChannel::receive_byte()
|
||||
{
|
||||
// Remove one byte from the Receive FIFO
|
||||
return 0xFF;
|
||||
// TODO: remove one byte from the Receive FIFO
|
||||
|
||||
uint8_t c;
|
||||
|
||||
this->chario->rcv_char(&c);
|
||||
this->read_regs[0] &= ~1;
|
||||
return c;
|
||||
}
|
||||
|
||||
static const vector<string> CharIoBackends = {"null", "stdio", "socket"};
|
||||
|
||||
static const PropMap Escc_Properties = {
|
||||
{"serial_backend", new StrProperty("null", CharIoBackends)},
|
||||
};
|
||||
|
||||
static const DeviceDescription Escc_Descriptor = {
|
||||
EsccController::create, {}, Escc_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(Escc, Escc_Descriptor);
|
||||
+26
-7
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,24 +24,35 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef ESCC_H
|
||||
#define ESCC_H
|
||||
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/serial/chario.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
/** ESCC register positions */
|
||||
/* Please note that the registers below are provided
|
||||
by Apple I/O controllers for accessing ESCC in a
|
||||
more convenient way. Actual physical addresses
|
||||
are controller dependent. */
|
||||
by the Apple I/O controllers for accessing ESCC
|
||||
in a more convenient way. Actual physical addresses
|
||||
are controller dependent.
|
||||
The registers are ordered according with the MacRISC
|
||||
scheme used in the PCI Power Macintosh models.
|
||||
Pre-PCI Macs uses the so-called compatibility
|
||||
addressing. Please use compat_to_macrisc table
|
||||
below for converting from compat to MacRISC.
|
||||
*/
|
||||
enum EsccReg : uint8_t {
|
||||
Port_B_Cmd = 0,
|
||||
Port_A_Cmd = 1,
|
||||
Port_B_Data = 2, // direct access to WR8/RR8
|
||||
Port_B_Data = 1, // direct access to WR8/RR8
|
||||
Port_A_Cmd = 2,
|
||||
Port_A_Data = 3, // direct access to WR8/RR8
|
||||
Enh_Reg_B = 4, // undocumented Apple extension
|
||||
Enh_Reg_A = 5, // undocumented Apple extension
|
||||
};
|
||||
|
||||
extern const uint8_t compat_to_macrisc[6];
|
||||
|
||||
/** LocalTalk LTPC registers provided by a MacIO controller. */
|
||||
enum LocalTalkReg : uint8_t {
|
||||
Rec_Count = 8,
|
||||
@@ -63,6 +74,7 @@ enum {
|
||||
|
||||
/** DPLL commands in WR14. */
|
||||
enum {
|
||||
DPLL_NULL_CMD = 0,
|
||||
DPLL_ENTER_SRC_MODE = 1,
|
||||
DPLL_RST_MISSING_CLK = 2,
|
||||
DPLL_DISABLE = 3,
|
||||
@@ -83,6 +95,7 @@ public:
|
||||
EsccChannel(std::string name) { this->name = name; };
|
||||
~EsccChannel() = default;
|
||||
|
||||
void attach_backend(int id);
|
||||
void reset(bool hw_reset);
|
||||
uint8_t read_reg(int reg_num);
|
||||
void write_reg(int reg_num, uint8_t value);
|
||||
@@ -99,14 +112,20 @@ private:
|
||||
uint8_t dpll_clock_src;
|
||||
uint8_t brg_active;
|
||||
uint8_t brg_clock_src;
|
||||
|
||||
std::unique_ptr<CharIoBackEnd> chario;
|
||||
};
|
||||
|
||||
/** ESCC Controller class. */
|
||||
class EsccController {
|
||||
class EsccController : public HWComponent {
|
||||
public:
|
||||
EsccController();
|
||||
~EsccController() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<EsccController>(new EsccController());
|
||||
}
|
||||
|
||||
// ESCC registers access
|
||||
uint8_t read(uint8_t reg_offset);
|
||||
void write(uint8_t reg_offset, uint8_t value);
|
||||
|
||||
@@ -46,14 +46,6 @@ AwacsBase::AwacsBase()
|
||||
this->out_stream_ready = false;
|
||||
}
|
||||
|
||||
AwacsBase::~AwacsBase()
|
||||
{
|
||||
// disconnect from SoundServer
|
||||
if (this->out_stream_ready) {
|
||||
snd_server->close_out_stream();
|
||||
}
|
||||
}
|
||||
|
||||
void AwacsBase::set_sample_rate(int sr_id)
|
||||
{
|
||||
if (sr_id > this->max_sr_id) {
|
||||
@@ -164,7 +156,7 @@ void AwacsScreamer::snd_ctrl_write(uint32_t offset, uint32_t value, int size)
|
||||
subframe = (value >> 14) & 3;
|
||||
reg_num = (value >> 20) & 7;
|
||||
data = ((value >> 8) & 0xF00) | ((value >> 24) & 0xFF);
|
||||
LOG_F(9, "Screamer subframe = %d, reg = %d, data = %08X\n",
|
||||
LOG_F(9, "Screamer subframe = %d, reg = %d, data = %08X",
|
||||
subframe, reg_num, data);
|
||||
if (!subframe)
|
||||
this->control_regs[reg_num] = data;
|
||||
|
||||
@@ -21,7 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
/** AWAC sound devices family definitions.
|
||||
|
||||
Audio Waveform Aplifier and Converters (AWACs) is a family of custom audio
|
||||
Audio Waveform Amplifier and Converters (AWACs) is a family of custom audio
|
||||
chips used in Power Macintosh.
|
||||
*/
|
||||
|
||||
@@ -40,7 +40,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
class AwacsBase {
|
||||
public:
|
||||
AwacsBase();
|
||||
~AwacsBase();
|
||||
~AwacsBase() = default;
|
||||
|
||||
void set_dma_out(DmaOutChannel *dma_out_ch) {
|
||||
this->dma_out_ch = dma_out_ch;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -114,8 +114,10 @@ int SoundServer::start()
|
||||
void SoundServer::shutdown()
|
||||
{
|
||||
switch (this->status) {
|
||||
case SND_STREAM_OPENED:
|
||||
close_out_stream();
|
||||
/* fall through */
|
||||
case SND_SERVER_UP:
|
||||
//soundio_device_unref(this->out_device);
|
||||
/* fall through */
|
||||
case SND_API_READY:
|
||||
cubeb_destroy(this->cubeb_ctx);
|
||||
@@ -203,6 +205,8 @@ int SoundServer::open_out_stream(uint32_t sample_rate, void *user_data)
|
||||
|
||||
LOG_F(INFO, "Sound output stream opened.");
|
||||
|
||||
this->status = SND_STREAM_OPENED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ enum {
|
||||
SND_SERVER_DOWN = 0,
|
||||
SND_API_READY,
|
||||
SND_SERVER_UP,
|
||||
SND_STREAM_OPENED
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
#ifndef ATI_MACH64_DEFS_H
|
||||
#define ATI_MACH64_DEFS_H
|
||||
|
||||
/* ATI PCI device IDs. */
|
||||
enum {
|
||||
ATI_RAGE_PRO_DEV_ID = 0x4750,
|
||||
ATI_RAGE_GT_DEV_ID = 0x4754,
|
||||
ATI_MACH64_GX_DEV_ID = 0x4758,
|
||||
};
|
||||
|
||||
/** Mach64 register offsets. */
|
||||
enum {
|
||||
ATI_CRTC_H_TOTAL_DISP = 0x0000,
|
||||
ATI_CRTC_H_SYNC_STRT_WID = 0x0004,
|
||||
ATI_CRTC_V_TOTAL_DISP = 0x0008,
|
||||
ATI_CRTC_V_SYNC_STRT_WID = 0x000C,
|
||||
ATI_CRTC_VLINE_CRNT_VLINE = 0x0010,
|
||||
ATI_CRTC_OFF_PITCH = 0x0014,
|
||||
ATI_CRTC_INT_CNTL = 0x0018,
|
||||
ATI_CRTC_GEN_CNTL = 0x001C,
|
||||
ATI_DSP_CONFIG = 0x0020,
|
||||
ATI_DSP_ON_OFF = 0x0024,
|
||||
ATI_TIMER_CFG = 0x0028,
|
||||
ATI_MEM_BUF_CNTL = 0x002C,
|
||||
ATI_MEM_ADDR_CFG = 0x0034,
|
||||
ATI_CRT_TRAP = 0x0038,
|
||||
ATI_I2C_CNTL_0 = 0x003C,
|
||||
ATI_OVR_CLR = 0x0040,
|
||||
ATI_OVR_WID_LEFT_RIGHT = 0x0044,
|
||||
ATI_OVR_WID_TOP_BOTTOM = 0x0048,
|
||||
ATI_VGA_DSP_CFG = 0x004C,
|
||||
ATI_VGA_DSP_TGL = 0x0050,
|
||||
ATI_DSP2_CONFIG = 0x0054,
|
||||
ATI_DSP2_TOGGLE = 0x0058,
|
||||
ATI_CRTC2_OFF_PITCH = 0x005C,
|
||||
ATI_CUR_CLR0 = 0x0060,
|
||||
ATI_CUR_CLR1 = 0x0064,
|
||||
ATI_CUR_OFFSET = 0x0068,
|
||||
ATI_CUR_HORZ_VERT_POSN = 0x006C,
|
||||
ATI_CUR_HORZ_VERT_OFF = 0x0070,
|
||||
ATI_GP_IO = 0x0078,
|
||||
ATI_HW_DEBUG = 0x007C,
|
||||
ATI_SCRATCH_REG0 = 0x0080,
|
||||
ATI_SCRATCH_REG1 = 0x0084,
|
||||
ATI_SCRATCH_REG2 = 0x0088,
|
||||
ATI_SCRATCH_REG3 = 0x008C,
|
||||
ATI_CLOCK_CNTL = 0x0090,
|
||||
ATI_CONFIG_STAT1 = 0x0094,
|
||||
ATI_CONFIG_STAT2 = 0x0098,
|
||||
ATI_BUS_CNTL = 0x00A0,
|
||||
ATI_EXT_MEM_CNTL = 0x00AC,
|
||||
ATI_MEM_CNTL = 0x00B0,
|
||||
ATI_MEM_VGA_WP_SEL = 0x00B4,
|
||||
ATI_MEM_VGA_RP_SEL = 0x00B8,
|
||||
ATI_I2C_CNTL_1 = 0x00BC,
|
||||
ATI_DAC_REGS = 0x00C0,
|
||||
ATI_DAC_W_INDEX = 0x00C0,
|
||||
ATI_DAC_DATA = 0x00C1,
|
||||
ATI_DAC_MASK = 0x00C2,
|
||||
ATI_DAC_R_INDEX = 0x00C3,
|
||||
ATI_DAC_CNTL = 0x00C4,
|
||||
ATI_GEN_TEST_CNTL = 0x00D0,
|
||||
ATI_CUSTOM_MACRO_CNTL = 0x00D4,
|
||||
ATI_CONFIG_CNTL = 0x00DC,
|
||||
ATI_CONFIG_CHIP_ID = 0x00E0,
|
||||
ATI_CONFIG_STAT0 = 0x00E4,
|
||||
ATI_GX_CONFIG_STAT1 = 0x00E8, // GX only
|
||||
ATI_CRC_SIG = 0x00E8,
|
||||
ATI_DST_Y_X_ALIAS1 = 0x00F4,
|
||||
ATI_DST_OFF_PITCH = 0x0100,
|
||||
ATI_DST_X = 0x0104,
|
||||
ATI_DST_Y = 0x0108,
|
||||
ATI_DST_Y_X = 0x010C,
|
||||
ATI_DST_WIDTH = 0x0110,
|
||||
ATI_DST_HEIGHT = 0x0114,
|
||||
ATI_DST_HEIGHT_WIDTH = 0x0118,
|
||||
ATI_DST_X_WIDTH = 0x011C,
|
||||
ATI_DST_BRES_LNTH = 0x0120,
|
||||
ATI_DST_BRES_ERR = 0x0124,
|
||||
ATI_DST_BRES_INC = 0x0128,
|
||||
ATI_DST_BRES_DEC = 0x012C,
|
||||
ATI_DST_CNTL = 0x0130,
|
||||
ATI_DST_Y_X_ALIAS2 = 0x0134,
|
||||
ATI_TRAIL_BRES_ERR = 0x0138,
|
||||
ATI_TRAIL_BRES_INC = 0x013C,
|
||||
ATI_TRAIL_BRES_DEC = 0x0140,
|
||||
ATI_DST_BRES_LNTH_ALIAS1 = 0x0144,
|
||||
ATI_Z_OFF_PITCH = 0x0148,
|
||||
ATI_Z_CNTL = 0x014C,
|
||||
ATI_ALPHA_TST_CNTL = 0x0150,
|
||||
ATI_SRC_OFF_PITCH = 0x0180,
|
||||
ATI_SRC_X = 0x0184,
|
||||
ATI_SRC_Y = 0x0188,
|
||||
ATI_SRC_Y_X = 0x018C,
|
||||
ATI_SRC_WIDTH1 = 0x0190,
|
||||
ATI_SRC_HEIGHT1 = 0x0194,
|
||||
ATI_SRC_HEIGHT1_WIDTH1 = 0x0198,
|
||||
ATI_SRC_X_START = 0x019C,
|
||||
ATI_SRC_Y_START = 0x01A0,
|
||||
ATI_SRC_Y_X_START = 0x01A4,
|
||||
ATI_SRC_WIDTH2 = 0x01A8,
|
||||
ATI_SRC_HEIGHT2 = 0x01AC,
|
||||
ATI_SRC_HEIGHT2_WIDTH2 = 0x01B0,
|
||||
ATI_SRC_CNTL = 0x01B4,
|
||||
ATI_SCALE_OFF = 0x01C0,
|
||||
ATI_SCALE_WIDTH = 0x01DC,
|
||||
ATI_SCALE_HEIGHT = 0x01E0,
|
||||
ATI_SCALE_PITCH = 0x01EC,
|
||||
ATI_SCALE_X_INC = 0x01F0,
|
||||
ATI_SCALE_Y_INC = 0x01F4,
|
||||
ATI_SCALE_VACC = 0x01F8,
|
||||
ATI_SCALE_3D_CNTL = 0x01FC,
|
||||
ATI_HOST_CNTL = 0x0240,
|
||||
ATI_PAT_REG0 = 0x0280,
|
||||
ATI_PAT_REG1 = 0x0284,
|
||||
ATI_PAT_CNTL = 0x0288,
|
||||
ATI_SC_LEFT = 0x02A0,
|
||||
ATI_SC_RIGHT = 0x02A4,
|
||||
ATI_SC_LEFT_RIGHT = 0x02A8,
|
||||
ATI_SC_TOP = 0x02AC,
|
||||
ATI_SC_BOTTOM = 0x02B0,
|
||||
ATI_SC_TOP_BOTTOM = 0x02B4,
|
||||
ATI_DP_BKGD_CLR = 0x02C0,
|
||||
ATI_DP_FOG_CLR = 0x02C0,
|
||||
ATI_DP_WRITE_MSK = 0x02C8,
|
||||
ATI_DP_PIX_WIDTH = 0x02D0,
|
||||
ATI_DP_MIX = 0x02D4,
|
||||
ATI_DP_SRC = 0x02D8,
|
||||
ATI_FRGD_CLR_MIX = 0x02DC,
|
||||
ATI_FRGD_BKGD_CLR = 0x02E0,
|
||||
ATI_DST_X_Y = 0x02E8,
|
||||
ATI_DST_WIDTH_HEIGHT = 0x02EC,
|
||||
ATI_USR_DST_PITCH = 0x02F0,
|
||||
ATI_DP_SET_GUI_ENGINE2 = 0x02F4,
|
||||
ATI_DP_SET_GUI_ENGINE = 0x02F8,
|
||||
ATI_CLR_CMP_CLR = 0x0300,
|
||||
ATI_CLR_CMP_MSK = 0x0304,
|
||||
ATI_CLR_CMP_CNTL = 0x0308,
|
||||
ATI_FIFO_STAT = 0x0310,
|
||||
ATI_CONTEXT_MASK = 0x0320,
|
||||
ATI_GUI_TRAJ_CNTL = 0x0330,
|
||||
ATI_GUI_STAT = 0x0338,
|
||||
ATI_MPP_CONFIG = 0x04C0,
|
||||
ATI_MPP_STROBE_SEQ = 0x04C4,
|
||||
ATI_MPP_ADDR = 0x04C8,
|
||||
ATI_MPP_DATA = 0x04CC,
|
||||
ATI_TVO_CNTL = 0x0500,
|
||||
ATI_SETUP_CNTL = 0x0704,
|
||||
ATI_INVALID = 0xFFFF
|
||||
};
|
||||
|
||||
constexpr auto APERTURE_SIZE = 0x01000000UL; /* Mach64 aperture size */
|
||||
constexpr auto MM_REGS_0_OFF = 0x007FFC00UL; /* offset to memory mapped registers, block 0 */
|
||||
constexpr auto MM_REGS_1_OFF = 0x007FF800UL; /* offset to memory mapped registers, block 1 */
|
||||
constexpr auto MM_REGS_2_OFF = 0x003FFC00UL; /* offset to memory mapped registers, 4MB aperture */
|
||||
constexpr auto BE_FB_OFFSET = 0x00800000UL; /* Offset to the big-endian frame buffer */
|
||||
|
||||
constexpr auto ATI_XTAL = 14318180.0f; // external crystal oscillator frequency
|
||||
|
||||
#endif // ATI_MACH64_DEFS_H
|
||||
@@ -0,0 +1,365 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** ATI Mach64 GX emulation.
|
||||
It emulates an ATI88800GX controller with an IBM RGB514 style RAMDAC.
|
||||
Emulation is limited to a basic framebuffer for now.
|
||||
*/
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/video/atimach64defs.h>
|
||||
#include <devices/video/atimach64gx.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/rgb514defs.h>
|
||||
#include <loguru.hpp>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
AtiMach64Gx::AtiMach64Gx()
|
||||
: PCIDevice("ati-mach64-gx"), VideoCtrlBase(1024, 768)
|
||||
{
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV);
|
||||
|
||||
/* set up PCI configuration space header */
|
||||
this->vendor_id = PCI_VENDOR_ATI;
|
||||
this->device_id = ATI_MACH64_GX_DEV_ID;
|
||||
this->class_rev = (0x030000 << 8) | 3;
|
||||
this->bars_cfg[0] = 0xFF000000UL; // declare main aperture (16MB)
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
};
|
||||
|
||||
// declare expansion ROM containing FCode and Mac OS drivers
|
||||
if (this->attach_exp_rom_image(std::string("113-32900-004_Apple_MACH64.bin"))) {
|
||||
LOG_F(WARNING, "AtiMach64Gx: could not load ROM - this device won't work properly!");
|
||||
}
|
||||
|
||||
// initialize display identification
|
||||
this->disp_id = std::unique_ptr<DisplayID> (new DisplayID(0x07, 0x3A));
|
||||
|
||||
// allocate video RAM
|
||||
this->vram_size = 2 << 20;
|
||||
this->vram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[this->vram_size]);
|
||||
}
|
||||
|
||||
void AtiMach64Gx::notify_bar_change(int bar_num)
|
||||
{
|
||||
if (bar_num) // only BAR0 is supported
|
||||
return;
|
||||
|
||||
if (this->aperture_base != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
if (this->aperture_base) {
|
||||
LOG_F(WARNING, "AtiMach64Gx: deallocating I/O memory not implemented");
|
||||
}
|
||||
|
||||
this->aperture_base = this->bars[0] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->aperture_base,
|
||||
APERTURE_SIZE, this);
|
||||
|
||||
// copy aperture address to CONFIG_CNTL:CFG_MEM_AP_LOC
|
||||
this->config_cntl = (this->config_cntl & 0xFFFFC00FUL) |
|
||||
((this->aperture_base >> 18) & 0x3FF0U);
|
||||
|
||||
LOG_F(INFO, "AtiMach64Gx: aperture address set to 0x%08X", this->aperture_base);
|
||||
}
|
||||
}
|
||||
|
||||
// map I/O register index to MMIO register offset
|
||||
static const uint32_t io_idx_to_reg_offset[32] = {
|
||||
ATI_CRTC_H_TOTAL_DISP, ATI_CRTC_H_SYNC_STRT_WID,
|
||||
ATI_CRTC_V_TOTAL_DISP, ATI_CRTC_V_SYNC_STRT_WID,
|
||||
ATI_CRTC_VLINE_CRNT_VLINE, ATI_CRTC_OFF_PITCH,
|
||||
ATI_CRTC_INT_CNTL, ATI_CRTC_GEN_CNTL,
|
||||
ATI_OVR_CLR, ATI_OVR_WID_LEFT_RIGHT,
|
||||
ATI_OVR_WID_TOP_BOTTOM, ATI_CUR_CLR0,
|
||||
ATI_CUR_CLR1, ATI_CUR_OFFSET,
|
||||
ATI_CUR_HORZ_VERT_POSN, ATI_CUR_HORZ_VERT_OFF,
|
||||
ATI_SCRATCH_REG0, ATI_SCRATCH_REG1,
|
||||
ATI_CLOCK_CNTL, ATI_BUS_CNTL,
|
||||
ATI_MEM_CNTL, ATI_MEM_VGA_WP_SEL,
|
||||
ATI_MEM_VGA_RP_SEL, ATI_DAC_REGS,
|
||||
ATI_DAC_CNTL, ATI_GEN_TEST_CNTL,
|
||||
ATI_CONFIG_CNTL, ATI_CONFIG_CHIP_ID,
|
||||
ATI_CONFIG_STAT0, ATI_GX_CONFIG_STAT1,
|
||||
ATI_INVALID, ATI_INVALID
|
||||
};
|
||||
|
||||
bool AtiMach64Gx::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res)
|
||||
{
|
||||
*res = 0;
|
||||
|
||||
// check for valid I/O base and I/O access permission
|
||||
if ((offset & 0x3FC) != 0x2EC || !(this->command & 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// convert ISA-style I/O address to MMIO register offset
|
||||
offset = io_idx_to_reg_offset[(offset >> 10) & 0x1F] + (offset & 3);
|
||||
|
||||
// CONFIG_CNTL is accessible from I/O space only
|
||||
if ((offset & ~3) == ATI_CONFIG_CNTL) {
|
||||
*res = read_mem(((uint8_t *)&this->config_cntl) + (offset & 3), size);
|
||||
} else {
|
||||
*res = this->read_reg(offset, size);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AtiMach64Gx::pci_io_write(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
// check for valid I/O base and I/O access permission
|
||||
if ((offset & 0x3FC) != 0x2EC || !(this->command & 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// convert ISA-style I/O address to MMIO register offset
|
||||
offset = io_idx_to_reg_offset[(offset >> 10) & 0x1F] + (offset & 3);
|
||||
|
||||
// CONFIG_CNTL is accessible from I/O space only
|
||||
if ((offset & ~3) == ATI_CONFIG_CNTL) {
|
||||
write_mem(((uint8_t *)&this->config_cntl) + (offset & 3), value, size);
|
||||
switch (this->config_cntl & 3) {
|
||||
case 0:
|
||||
LOG_F(WARNING, "AtiMach64Gx: linear aperture disabled!");
|
||||
break;
|
||||
case 1:
|
||||
LOG_F(INFO, "AtiMach64Gx: aperture size set to 4MB");
|
||||
this->mm_regs_offset = MM_REGS_2_OFF;
|
||||
break;
|
||||
case 2:
|
||||
LOG_F(INFO, "AtiMach64Gx: aperture size set to 8MB");
|
||||
this->mm_regs_offset = MM_REGS_0_OFF;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "AtiMach64Gx: invalid aperture size in CONFIG_CNTL");
|
||||
}
|
||||
} else {
|
||||
this->write_reg(offset, value, size);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t AtiMach64Gx::read_reg(uint32_t offset, uint32_t size)
|
||||
{
|
||||
LOG_F(INFO, "AtiMach64Gx: read from I/O mapped reg at 0x%X", offset);
|
||||
|
||||
return read_mem(&this->mm_regs[offset], size);
|
||||
}
|
||||
|
||||
void AtiMach64Gx::write_reg(uint32_t offset, uint32_t value, uint32_t size)
|
||||
{
|
||||
uint8_t gpio_dirs, gpio_levels;
|
||||
int crtc_en;
|
||||
|
||||
// write value to internal registers with endian conversion
|
||||
write_mem(&this->mm_regs[offset], value, size);
|
||||
|
||||
switch (offset & ~3) {
|
||||
case ATI_CRTC_GEN_CNTL:
|
||||
crtc_en = (this->mm_regs[ATI_CRTC_GEN_CNTL+3] >> 1) & 1;
|
||||
if (crtc_en != this->crtc_enable) {
|
||||
if (!crtc_en) {
|
||||
this->disable_crtc_internal();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_REGS:
|
||||
if (size == 1) { // only byte accesses are allowed for DAC registers
|
||||
int dac_reg_addr = ((this->mm_regs[ATI_DAC_CNTL] & 1) << 2) | (offset & 3);
|
||||
rgb514_write_reg(dac_reg_addr, value);
|
||||
}
|
||||
break;
|
||||
case ATI_DAC_CNTL:
|
||||
// monitor ID is usually accessed using 8bit writes
|
||||
if ((offset & 3) == 3) {
|
||||
gpio_dirs = (value >> 3) & 7;
|
||||
gpio_levels = value & 7;
|
||||
gpio_levels = this->disp_id->read_monitor_sense(gpio_levels, gpio_dirs);
|
||||
this->mm_regs[ATI_DAC_CNTL+3] = (this->mm_regs[ATI_DAC_CNTL+3] & 0xF8U) | gpio_levels;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "AtiMach64Gx: write 0x%X to I/O mapped reg at 0x%X", value, offset);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t AtiMach64Gx::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
if (rgn_start == this->aperture_base) {
|
||||
if (offset < this->vram_size) {
|
||||
return read_mem(&this->vram_ptr[offset], size);
|
||||
} else if (offset >= this->mm_regs_offset) {
|
||||
return read_reg(offset - this->mm_regs_offset, size);
|
||||
}
|
||||
}
|
||||
|
||||
// memory mapped expansion ROM region
|
||||
if (rgn_start == this->exp_rom_addr && offset < this->exp_rom_size) {
|
||||
return read_mem(&this->exp_rom_data[offset], size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AtiMach64Gx::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
if (rgn_start == this->aperture_base) {
|
||||
if (offset < this->vram_size) {
|
||||
write_mem(&this->vram_ptr[offset], value, size);
|
||||
} else if (offset >= this->mm_regs_offset) {
|
||||
write_reg(offset - this->mm_regs_offset, value, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AtiMach64Gx::enable_crtc_internal()
|
||||
{
|
||||
int new_width = (this->mm_regs[ATI_CRTC_H_TOTAL_DISP+2] + 1) * 8;
|
||||
|
||||
int new_height = (READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_V_TOTAL_DISP+2]) & 0x7FFUL) + 1;
|
||||
|
||||
if (new_width != this->active_width || new_height != this->active_height) {
|
||||
LOG_F(WARNING, "AtiMach64Gx: display window resizing not implemented yet!");
|
||||
}
|
||||
|
||||
/* calculate display refresh rate */
|
||||
int hori_total = (this->mm_regs[ATI_CRTC_H_TOTAL_DISP] + 1) * 8;
|
||||
|
||||
int vert_total = (READ_WORD_LE_A(&this->mm_regs[ATI_CRTC_V_TOTAL_DISP]) & 0x7FFUL) + 1;
|
||||
|
||||
this->refresh_rate = this->pixel_clock / hori_total / vert_total;
|
||||
|
||||
int32_t src_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFFFU) * 8;
|
||||
|
||||
this->fb_pitch = ((READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8U;
|
||||
|
||||
this->fb_ptr = &this->vram_ptr[src_offset];
|
||||
|
||||
// specify framebuffer converter
|
||||
switch (this->pixel_depth) {
|
||||
case 8:
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->convert_frame_8bpp(dst_buf, dst_pitch);
|
||||
};
|
||||
break;
|
||||
default:
|
||||
ABORT_F("AtiMach64Gx: unsupported pixel depth %d", this->pixel_depth);
|
||||
}
|
||||
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / this->refresh_rate * NS_PER_SEC + 0.5);
|
||||
TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
|
||||
this->update_screen();
|
||||
|
||||
this->crtc_on = true;
|
||||
|
||||
this->crtc_enable = 1;
|
||||
}
|
||||
|
||||
void AtiMach64Gx::disable_crtc_internal()
|
||||
{
|
||||
this->crtc_enable = 0;
|
||||
}
|
||||
|
||||
// ========================== IBM RGB514 related code ==========================
|
||||
void AtiMach64Gx::rgb514_write_reg(uint8_t reg_addr, uint8_t value)
|
||||
{
|
||||
switch (reg_addr) {
|
||||
case Rgb514::CLUT_ADDR_WR:
|
||||
this->clut_index = value;
|
||||
break;
|
||||
case Rgb514::CLUT_DATA:
|
||||
this->clut_color[this->comp_index++] = value;
|
||||
if (this->comp_index >= 3) {
|
||||
// TODO: combine separate components into a single ARGB value
|
||||
this->palette[this->clut_index][0] = this->clut_color[0];
|
||||
this->palette[this->clut_index][1] = this->clut_color[1];
|
||||
this->palette[this->clut_index][2] = this->clut_color[2];
|
||||
this->palette[this->clut_index][3] = 255;
|
||||
this->clut_index++;
|
||||
this->comp_index = 0;
|
||||
}
|
||||
break;
|
||||
case Rgb514::CLUT_MASK:
|
||||
if (value != 0xFF) {
|
||||
LOG_F(WARNING, "RGB514: pixel mask set to 0x%X", value);
|
||||
}
|
||||
break;
|
||||
case Rgb514::INDEX_LOW:
|
||||
this->dac_idx_lo = value;
|
||||
break;
|
||||
case Rgb514::INDEX_HIGH:
|
||||
this->dac_idx_hi = value;
|
||||
break;
|
||||
case Rgb514::INDEX_DATA:
|
||||
this->rgb514_write_ind_reg((this->dac_idx_hi << 8) + this->dac_idx_lo, value);
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "RGB514: access to unimplemented register at 0x%X", reg_addr);
|
||||
}
|
||||
}
|
||||
|
||||
void AtiMach64Gx::rgb514_write_ind_reg(uint8_t reg_addr, uint8_t value)
|
||||
{
|
||||
LOG_F(INFO, "RGB514: write 0x%X to register 0x%X", value, reg_addr);
|
||||
|
||||
this->dac_regs[reg_addr] = value;
|
||||
|
||||
switch (reg_addr) {
|
||||
case Rgb514::MISC_CLK_CNTL:
|
||||
if (value & PLL_ENAB) {
|
||||
if ((this->dac_regs[Rgb514::PLL_CTL_1] & 3) != 1)
|
||||
ABORT_F("RGB514: unsupported PLL source");
|
||||
|
||||
int m = 8 >> (this->dac_regs[Rgb514::F0_M0] >> 6);
|
||||
int vco_div = (this->dac_regs[Rgb514::F0_M0] & 0x3F) + 65;
|
||||
int ref_div = (this->dac_regs[Rgb514::F1_N0] & 0x1F) * m;
|
||||
this->pixel_clock = ATI_XTAL * vco_div / ref_div;
|
||||
LOG_F(INFO, "RGB514: dot clock set to %f Hz", this->pixel_clock);
|
||||
}
|
||||
break;
|
||||
case Rgb514::PIX_FORMAT:
|
||||
if (value == 3) {
|
||||
this->pixel_depth = 8;
|
||||
// HACK: not the best place for enabling display output!
|
||||
this->enable_crtc_internal();
|
||||
} else {
|
||||
ABORT_F("RGB514: unimplemented pixel format %d", value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const DeviceDescription AtiMach64Gx_Descriptor = {
|
||||
AtiMach64Gx::create, {}, {}
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AtiMach64Gx, AtiMach64Gx_Descriptor);
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** ATI Mach64 GX definitions. */
|
||||
|
||||
#ifndef ATI_MACH64_GX_H
|
||||
#define ATI_MACH64_GX_H
|
||||
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/video/atimach64defs.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/videoctrl.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
class AtiMach64Gx : public PCIDevice, public VideoCtrlBase {
|
||||
public:
|
||||
AtiMach64Gx();
|
||||
~AtiMach64Gx() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<AtiMach64Gx>(new AtiMach64Gx());
|
||||
}
|
||||
|
||||
/* PCI device methods */
|
||||
bool supports_io_space(void) {
|
||||
return true;
|
||||
};
|
||||
|
||||
/* I/O space access methods */
|
||||
bool pci_io_read(uint32_t offset, uint32_t size, uint32_t* res);
|
||||
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
protected:
|
||||
void notify_bar_change(int bar_num);
|
||||
uint32_t read_reg(uint32_t offset, uint32_t size);
|
||||
void write_reg(uint32_t offset, uint32_t value, uint32_t size);
|
||||
void enable_crtc_internal();
|
||||
void disable_crtc_internal();
|
||||
|
||||
void rgb514_write_reg(uint8_t reg_addr, uint8_t value);
|
||||
void rgb514_write_ind_reg(uint8_t reg_addr, uint8_t value);
|
||||
|
||||
private:
|
||||
uint8_t mm_regs[2048] = { 0 }; // internal registers
|
||||
|
||||
int vram_size;
|
||||
uint32_t aperture_base;
|
||||
uint32_t config_cntl;
|
||||
uint32_t mm_regs_offset;
|
||||
int crtc_enable = 0;
|
||||
|
||||
// RGB514 RAMDAC state
|
||||
uint8_t dac_idx_lo;
|
||||
uint8_t dac_idx_hi;
|
||||
uint8_t clut_index;
|
||||
uint8_t comp_index;
|
||||
uint8_t clut_color[3];
|
||||
uint8_t dac_regs[256];
|
||||
|
||||
std::unique_ptr<DisplayID> disp_id;
|
||||
std::unique_ptr<uint8_t[]> vram_ptr;
|
||||
};
|
||||
|
||||
#endif /* ATI_MACH64_GX_H */
|
||||
+126
-103
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -19,8 +19,10 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/hwcomponent.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/video/atirage.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <endianswap.h>
|
||||
@@ -88,14 +90,14 @@ static const std::map<uint16_t, std::string> mach64_reg_names = {
|
||||
};
|
||||
|
||||
|
||||
ATIRage::ATIRage(uint16_t dev_id, uint32_t vmem_size_mb)
|
||||
: PCIDevice("ati-rage"), VideoCtrlBase()
|
||||
ATIRage::ATIRage(uint16_t dev_id)
|
||||
: PCIDevice("ati-rage"), VideoCtrlBase(1024, 768)
|
||||
{
|
||||
uint8_t asic_id;
|
||||
|
||||
supports_types(HWCompType::MMIO_DEV | HWCompType::PCI_DEV);
|
||||
|
||||
this->vram_size = vmem_size_mb << 20; // convert MBs to bytes
|
||||
this->vram_size = GET_INT_PROP("gfxmem_size") << 20; // convert MBs to bytes
|
||||
|
||||
/* allocate video RAM */
|
||||
this->vram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[this->vram_size]);
|
||||
@@ -115,9 +117,20 @@ ATIRage::ATIRage(uint16_t dev_id, uint32_t vmem_size_mb)
|
||||
}
|
||||
|
||||
/* set up PCI configuration space header */
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[0], (dev_id << 16) | ATI_PCI_VENDOR_ID);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[8], (0x030000 << 8) | asic_id);
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[0x3C], 0x00080100);
|
||||
this->vendor_id = PCI_VENDOR_ATI;
|
||||
this->device_id = dev_id;
|
||||
this->subsys_vndr = PCI_VENDOR_ATI;
|
||||
this->subsys_id = 0x6987; // adapter ID
|
||||
this->class_rev = (0x030000 << 8) | asic_id;
|
||||
this->min_gnt = 8;
|
||||
this->irq_pin = 1;
|
||||
this->bars_cfg[0] = 0xFF000000UL; // declare main aperture (16MB)
|
||||
this->bars_cfg[1] = 0xFFFFFF01UL; // declare I/O region (256 bytes)
|
||||
this->bars_cfg[2] = 0xFFFFF000UL; // declare register aperture (4KB)
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
};
|
||||
|
||||
/* stuff default values into chip registers */
|
||||
WRITE_DWORD_LE_A(&this->mm_regs[ATI_CONFIG_CHIP_ID],
|
||||
@@ -127,6 +140,58 @@ ATIRage::ATIRage(uint16_t dev_id, uint32_t vmem_size_mb)
|
||||
this->disp_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
}
|
||||
|
||||
void ATIRage::notify_bar_change(int bar_num)
|
||||
{
|
||||
switch (bar_num) {
|
||||
case 0:
|
||||
if (this->aperture_base != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
this->aperture_base = this->bars[0] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->aperture_base,
|
||||
APERTURE_SIZE, this);
|
||||
LOG_F(INFO, "ATIRage: aperture address set to 0x%08X", this->aperture_base);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
this->io_base = this->bars[1] & ~3;
|
||||
LOG_F(INFO, "ATIRage: I/O space address set to 0x%08X", this->io_base);
|
||||
break;
|
||||
case 2:
|
||||
LOG_F(INFO, "ATIRage: register aperture address set to 0x%08X", this->bars[2]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ATIRage::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
return PCIDevice::pci_cfg_read(reg_offs, size);
|
||||
}
|
||||
|
||||
switch (reg_offs) {
|
||||
case 0x40:
|
||||
return this->user_cfg;
|
||||
default:
|
||||
LOG_F(WARNING, "ATIRage: reading from unimplemented config register at 0x%X", reg_offs);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ATIRage::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
||||
{
|
||||
if (reg_offs < 64) {
|
||||
PCIDevice::pci_cfg_write(reg_offs, value, size);
|
||||
} else {
|
||||
switch (reg_offs) {
|
||||
case 0x40:
|
||||
this->user_cfg = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(WARNING, "ATIRage: writing to unimplemented config register at 0x%X", reg_offs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char* ATIRage::get_reg_name(uint32_t reg_offset) {
|
||||
auto iter = mach64_reg_names.find(reg_offset & ~3);
|
||||
if (iter != mach64_reg_names.end()) {
|
||||
@@ -267,133 +332,57 @@ void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size)
|
||||
READ_DWORD_LE_A(&this->mm_regs[offset & ~3]));
|
||||
}
|
||||
|
||||
if ((this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 2) &&
|
||||
!(this->mm_regs[ATI_CRTC_GEN_CNTL] & 0x40)) {
|
||||
int32_t src_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFF) * 8;
|
||||
//if ((this->mm_regs[ATI_CRTC_GEN_CNTL+3] & 2) &&
|
||||
// !(this->mm_regs[ATI_CRTC_GEN_CNTL] & 0x40)) {
|
||||
// int32_t src_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFF) * 8;
|
||||
|
||||
this->fb_pitch = ((READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
|
||||
// this->fb_pitch = ((READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
|
||||
|
||||
this->fb_ptr = &this->vram_ptr[src_offset];
|
||||
this->update_screen();
|
||||
}
|
||||
// this->fb_ptr = &this->vram_ptr[src_offset];
|
||||
// this->update_screen();
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
uint32_t ATIRage::pci_cfg_read(uint32_t reg_offs, uint32_t size) {
|
||||
uint32_t res = 0;
|
||||
|
||||
LOG_F(INFO, "Reading ATI Rage config space, offset = 0x%X, size=%d", reg_offs, size);
|
||||
|
||||
res = read_mem(&this->pci_cfg[reg_offs], size);
|
||||
|
||||
LOG_F(INFO, "Return value: 0x%X", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
void ATIRage::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size) {
|
||||
LOG_F(
|
||||
INFO,
|
||||
"Writing into ATI Rage PCI config space, offset = 0x%X, val=0x%X size=%d",
|
||||
reg_offs,
|
||||
BYTESWAP_32(value),
|
||||
size);
|
||||
|
||||
switch (reg_offs) {
|
||||
case 0x10: /* BAR 0 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR0], 0xFF000000UL);
|
||||
}
|
||||
else {
|
||||
this->aperture_base = BYTESWAP_32(value);
|
||||
LOG_F(INFO, "ATI Rage aperture address set to 0x%08X", this->aperture_base);
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR0], value);
|
||||
this->host_instance->pci_register_mmio_region(this->aperture_base,
|
||||
APERTURE_SIZE, this);
|
||||
}
|
||||
break;
|
||||
case 0x14: /* BAR 1: I/O space base, 256 bytes wide */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1], 0xFFFFFF01UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR1], value);
|
||||
}
|
||||
break;
|
||||
case 0x18: /* BAR 2 */
|
||||
if (value == 0xFFFFFFFFUL) {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR2], 0xFFFFF000UL);
|
||||
}
|
||||
else {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[CFG_REG_BAR2], value);
|
||||
}
|
||||
break;
|
||||
case CFG_REG_BAR3: /* unimplemented */
|
||||
case CFG_REG_BAR4: /* unimplemented */
|
||||
case CFG_REG_BAR5: /* unimplemented */
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[reg_offs], 0);
|
||||
break;
|
||||
case CFG_EXP_BASE: /* no expansion ROM */
|
||||
if (value == 0x00F8FFFFUL) {
|
||||
// return 0 (not implemented) when attempting to size the expansion ROM
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[reg_offs], 0);
|
||||
} else {
|
||||
WRITE_DWORD_BE_A(&this->pci_cfg[reg_offs], value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
write_mem(&this->pci_cfg[reg_offs], value, size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::io_access_allowed(uint32_t offset, uint32_t* p_io_base) {
|
||||
if (!(this->pci_cfg[CFG_REG_CMD] & 1)) {
|
||||
bool ATIRage::io_access_allowed(uint32_t offset) {
|
||||
if (!(this->command & 1)) {
|
||||
LOG_F(WARNING, "ATI I/O space disabled in the command reg");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t io_base = READ_DWORD_LE_A(&this->pci_cfg[CFG_REG_BAR1]) & ~3;
|
||||
|
||||
if (offset < io_base || offset > (io_base + 0x100)) {
|
||||
if (offset < this->io_base || offset > (this->io_base + 0x100)) {
|
||||
LOG_F(WARNING, "Rage: I/O out of range, base=0x%X, offset=0x%X", io_base, offset);
|
||||
return false;
|
||||
}
|
||||
|
||||
*p_io_base = io_base;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::pci_io_read(uint32_t offset, uint32_t size, uint32_t* res) {
|
||||
uint32_t io_base;
|
||||
|
||||
if (!this->io_access_allowed(offset, &io_base)) {
|
||||
if (!this->io_access_allowed(offset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*res = this->read_reg(offset - io_base, size);
|
||||
*res = this->read_reg(offset - this->io_base, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ATIRage::pci_io_write(uint32_t offset, uint32_t value, uint32_t size) {
|
||||
uint32_t io_base;
|
||||
|
||||
if (!this->io_access_allowed(offset, &io_base)) {
|
||||
if (!this->io_access_allowed(offset)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->write_reg(offset - io_base, value, size);
|
||||
this->write_reg(offset - this->io_base, value, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
uint32_t ATIRage::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
LOG_F(8, "Reading ATI Rage PCI memory: region=%X, offset=%X, size %d", reg_start, offset, size);
|
||||
LOG_F(8, "Reading ATI Rage PCI memory: region=%X, offset=%X, size %d", rgn_start, offset, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
if (rgn_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to read outside the aperture!");
|
||||
return 0;
|
||||
}
|
||||
@@ -421,11 +410,11 @@ uint32_t ATIRage::read(uint32_t reg_start, uint32_t offset, int size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ATIRage::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
||||
void ATIRage::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
LOG_F(8, "Writing reg=%X, offset=%X, value=%X, size %d", reg_start, offset, value, size);
|
||||
LOG_F(8, "Writing reg=%X, offset=%X, value=%X, size %d", rgn_start, offset, value, size);
|
||||
|
||||
if (reg_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
if (rgn_start < this->aperture_base || offset > APERTURE_SIZE) {
|
||||
LOG_F(WARNING, "ATI Rage: attempt to write outside the aperture!");
|
||||
return;
|
||||
}
|
||||
@@ -528,6 +517,12 @@ void ATIRage::crtc_enable() {
|
||||
|
||||
this->refresh_rate = pixel_clock / hori_total / vert_total;
|
||||
|
||||
int32_t src_offset = (READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH]) & 0xFFFF) * 8;
|
||||
|
||||
this->fb_pitch = ((READ_DWORD_LE_A(&this->mm_regs[ATI_CRTC_OFF_PITCH])) >> 19) & 0x1FF8;
|
||||
|
||||
this->fb_ptr = &this->vram_ptr[src_offset];
|
||||
|
||||
// specify framebuffer converter (hardcoded for now)
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->convert_frame_8bpp(dst_buf, dst_pitch);
|
||||
@@ -542,6 +537,16 @@ void ATIRage::crtc_enable() {
|
||||
LOG_F(INFO, "VPLL frequency: %f MHz", vpll_freq * 1e-6);
|
||||
LOG_F(INFO, "Pixel (dot) clock: %f MHz", this->pixel_clock * 1e-6);
|
||||
LOG_F(INFO, "Refresh rate: %f Hz", this->refresh_rate);
|
||||
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / this->refresh_rate * NS_PER_SEC + 0.5);
|
||||
TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
|
||||
this->update_screen();
|
||||
} else {
|
||||
LOG_F(WARNING, "ATI Rage: VLCK source != VPLL!");
|
||||
}
|
||||
@@ -586,3 +591,21 @@ void ATIRage::draw_hw_cursor(uint8_t *dst_buf, int dst_pitch) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const PropMap AtiRage_Properties = {
|
||||
{"gfxmem_size",
|
||||
new IntProperty( 2, vector<uint32_t>({2, 4, 6}))},
|
||||
{"mon_id",
|
||||
new StrProperty("")},
|
||||
};
|
||||
|
||||
static const DeviceDescription AtiRageGT_Descriptor = {
|
||||
ATIRage::create_gt, {}, AtiRage_Properties
|
||||
};
|
||||
|
||||
static const DeviceDescription AtiRagePro_Descriptor = {
|
||||
ATIRage::create_pro, {}, AtiRage_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(AtiRageGT, AtiRageGT_Descriptor);
|
||||
REGISTER_DEVICE(AtiRagePro, AtiRagePro_Descriptor);
|
||||
+19
-161
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -23,158 +23,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#define ATI_RAGE_H
|
||||
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/video/atimach64defs.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/videoctrl.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
/* PCI related definitions. */
|
||||
enum {
|
||||
ATI_PCI_VENDOR_ID = 0x1002,
|
||||
ATI_RAGE_PRO_DEV_ID = 0x4750,
|
||||
ATI_RAGE_GT_DEV_ID = 0x4754,
|
||||
};
|
||||
|
||||
/** Mach registers offsets. */
|
||||
enum {
|
||||
ATI_CRTC_H_TOTAL_DISP = 0x0000,
|
||||
ATI_CRTC_H_SYNC_STRT_WID = 0x0004,
|
||||
ATI_CRTC_V_TOTAL_DISP = 0x0008,
|
||||
ATI_CRTC_V_SYNC_STRT_WID = 0x000C,
|
||||
ATI_CRTC_VLINE_CRNT_VLINE = 0x0010,
|
||||
ATI_CRTC_OFF_PITCH = 0x0014,
|
||||
ATI_CRTC_INT_CNTL = 0x0018,
|
||||
ATI_CRTC_GEN_CNTL = 0x001C,
|
||||
ATI_DSP_CONFIG = 0x0020,
|
||||
ATI_DSP_ON_OFF = 0x0024,
|
||||
ATI_TIMER_CFG = 0x0028,
|
||||
ATI_MEM_BUF_CNTL = 0x002C,
|
||||
ATI_MEM_ADDR_CFG = 0x0034,
|
||||
ATI_CRT_TRAP = 0x0038,
|
||||
ATI_I2C_CNTL_0 = 0x003C,
|
||||
ATI_OVR_CLR = 0x0040,
|
||||
ATI_OVR_WID_LEFT_RIGHT = 0x0044,
|
||||
ATI_OVR_WID_TOP_BOTTOM = 0x0048,
|
||||
ATI_VGA_DSP_CFG = 0x004C,
|
||||
ATI_VGA_DSP_TGL = 0x0050,
|
||||
ATI_DSP2_CONFIG = 0x0054,
|
||||
ATI_DSP2_TOGGLE = 0x0058,
|
||||
ATI_CRTC2_OFF_PITCH = 0x005C,
|
||||
ATI_CUR_CLR0 = 0x0060,
|
||||
ATI_CUR_CLR1 = 0x0064,
|
||||
ATI_CUR_OFFSET = 0x0068,
|
||||
ATI_CUR_HORZ_VERT_POSN = 0x006C,
|
||||
ATI_CUR_HORZ_VERT_OFF = 0x0070,
|
||||
ATI_GP_IO = 0x0078,
|
||||
ATI_HW_DEBUG = 0x007C,
|
||||
ATI_SCRATCH_REG0 = 0x0080,
|
||||
ATI_SCRATCH_REG1 = 0x0084,
|
||||
ATI_SCRATCH_REG2 = 0x0088,
|
||||
ATI_SCRATCH_REG3 = 0x008C,
|
||||
ATI_CLOCK_CNTL = 0x0090,
|
||||
ATI_CONFIG_STAT1 = 0x0094,
|
||||
ATI_CONFIG_STAT2 = 0x0098,
|
||||
ATI_BUS_CNTL = 0x00A0,
|
||||
ATI_EXT_MEM_CNTL = 0x00AC,
|
||||
ATI_MEM_CNTL = 0x00B0,
|
||||
ATI_MEM_VGA_WP_SEL = 0x00B4,
|
||||
ATI_MEM_VGA_RP_SEL = 0x00B8,
|
||||
ATI_I2C_CNTL_1 = 0x00BC,
|
||||
ATI_DAC_REGS = 0x00C0,
|
||||
ATI_DAC_W_INDEX = 0x00C0,
|
||||
ATI_DAC_DATA = 0x00C1,
|
||||
ATI_DAC_MASK = 0x00C2,
|
||||
ATI_DAC_R_INDEX = 0x00C3,
|
||||
ATI_DAC_CNTL = 0x00C4,
|
||||
ATI_GEN_TEST_CNTL = 0x00D0,
|
||||
ATI_CUSTOM_MACRO_CNTL = 0x00D4,
|
||||
ATI_CONFIG_CNTL = 0x00DC,
|
||||
ATI_CONFIG_CHIP_ID = 0x00E0,
|
||||
ATI_CONFIG_STAT0 = 0x00E4,
|
||||
ATI_CRC_SIG = 0x00E8,
|
||||
ATI_DST_Y_X_ALIAS1 = 0x00F4,
|
||||
ATI_DST_OFF_PITCH = 0x0100,
|
||||
ATI_DST_X = 0x0104,
|
||||
ATI_DST_Y = 0x0108,
|
||||
ATI_DST_Y_X = 0x010C,
|
||||
ATI_DST_WIDTH = 0x0110,
|
||||
ATI_DST_HEIGHT = 0x0114,
|
||||
ATI_DST_HEIGHT_WIDTH = 0x0118,
|
||||
ATI_DST_X_WIDTH = 0x011C,
|
||||
ATI_DST_BRES_LNTH = 0x0120,
|
||||
ATI_DST_BRES_ERR = 0x0124,
|
||||
ATI_DST_BRES_INC = 0x0128,
|
||||
ATI_DST_BRES_DEC = 0x012C,
|
||||
ATI_DST_CNTL = 0x0130,
|
||||
ATI_DST_Y_X_ALIAS2 = 0x0134,
|
||||
ATI_TRAIL_BRES_ERR = 0x0138,
|
||||
ATI_TRAIL_BRES_INC = 0x013C,
|
||||
ATI_TRAIL_BRES_DEC = 0x0140,
|
||||
ATI_DST_BRES_LNTH_ALIAS1 = 0x0144,
|
||||
ATI_Z_OFF_PITCH = 0x0148,
|
||||
ATI_Z_CNTL = 0x014C,
|
||||
ATI_ALPHA_TST_CNTL = 0x0150,
|
||||
ATI_SRC_OFF_PITCH = 0x0180,
|
||||
ATI_SRC_X = 0x0184,
|
||||
ATI_SRC_Y = 0x0188,
|
||||
ATI_SRC_Y_X = 0x018C,
|
||||
ATI_SRC_WIDTH1 = 0x0190,
|
||||
ATI_SRC_HEIGHT1 = 0x0194,
|
||||
ATI_SRC_HEIGHT1_WIDTH1 = 0x0198,
|
||||
ATI_SRC_X_START = 0x019C,
|
||||
ATI_SRC_Y_START = 0x01A0,
|
||||
ATI_SRC_Y_X_START = 0x01A4,
|
||||
ATI_SRC_WIDTH2 = 0x01A8,
|
||||
ATI_SRC_HEIGHT2 = 0x01AC,
|
||||
ATI_SRC_HEIGHT2_WIDTH2 = 0x01B0,
|
||||
ATI_SRC_CNTL = 0x01B4,
|
||||
ATI_SCALE_OFF = 0x01C0,
|
||||
ATI_SCALE_WIDTH = 0x01DC,
|
||||
ATI_SCALE_HEIGHT = 0x01E0,
|
||||
ATI_SCALE_PITCH = 0x01EC,
|
||||
ATI_SCALE_X_INC = 0x01F0,
|
||||
ATI_SCALE_Y_INC = 0x01F4,
|
||||
ATI_SCALE_VACC = 0x01F8,
|
||||
ATI_SCALE_3D_CNTL = 0x01FC,
|
||||
ATI_HOST_CNTL = 0x0240,
|
||||
ATI_PAT_REG0 = 0x0280,
|
||||
ATI_PAT_REG1 = 0x0284,
|
||||
ATI_PAT_CNTL = 0x0288,
|
||||
ATI_SC_LEFT = 0x02A0,
|
||||
ATI_SC_RIGHT = 0x02A4,
|
||||
ATI_SC_LEFT_RIGHT = 0x02A8,
|
||||
ATI_SC_TOP = 0x02AC,
|
||||
ATI_SC_BOTTOM = 0x02B0,
|
||||
ATI_SC_TOP_BOTTOM = 0x02B4,
|
||||
ATI_DP_BKGD_CLR = 0x02C0,
|
||||
ATI_DP_FOG_CLR = 0x02C0,
|
||||
ATI_DP_WRITE_MSK = 0x02C8,
|
||||
ATI_DP_PIX_WIDTH = 0x02D0,
|
||||
ATI_DP_MIX = 0x02D4,
|
||||
ATI_DP_SRC = 0x02D8,
|
||||
ATI_FRGD_CLR_MIX = 0x02DC,
|
||||
ATI_FRGD_BKGD_CLR = 0x02E0,
|
||||
ATI_DST_X_Y = 0x02E8,
|
||||
ATI_DST_WIDTH_HEIGHT = 0x02EC,
|
||||
ATI_USR_DST_PITCH = 0x02F0,
|
||||
ATI_DP_SET_GUI_ENGINE2 = 0x02F4,
|
||||
ATI_DP_SET_GUI_ENGINE = 0x02F8,
|
||||
ATI_CLR_CMP_CLR = 0x0300,
|
||||
ATI_CLR_CMP_MSK = 0x0304,
|
||||
ATI_CLR_CMP_CNTL = 0x0308,
|
||||
ATI_FIFO_STAT = 0x0310,
|
||||
ATI_CONTEXT_MASK = 0x0320,
|
||||
ATI_GUI_TRAJ_CNTL = 0x0330,
|
||||
ATI_GUI_STAT = 0x0338,
|
||||
ATI_MPP_CONFIG = 0x04C0,
|
||||
ATI_MPP_STROBE_SEQ = 0x04C4,
|
||||
ATI_MPP_ADDR = 0x04C8,
|
||||
ATI_MPP_DATA = 0x04CC,
|
||||
ATI_TVO_CNTL = 0x0500,
|
||||
ATI_SETUP_CNTL = 0x0704,
|
||||
};
|
||||
|
||||
/* Mach64 PLL register indices. */
|
||||
enum {
|
||||
PLL_REF_DIV = 2, // reference divider, same for all Mach64 clocks
|
||||
@@ -187,21 +42,22 @@ enum {
|
||||
PLL_EXT_CNTL = 11,
|
||||
};
|
||||
|
||||
constexpr auto APERTURE_SIZE = 0x01000000UL; /* Mach64 aperture size */
|
||||
constexpr auto MM_REGS_0_OFF = 0x007FFC00UL; /* offset to memory mapped registers, block 0 */
|
||||
constexpr auto MM_REGS_1_OFF = 0x007FF800UL; /* offset to memory mapped registers, block 1 */
|
||||
constexpr auto BE_FB_OFFSET = 0x00800000UL; /* Offset to the big-endian frame buffer */
|
||||
|
||||
constexpr auto ATI_XTAL = 14318180.0f; // external crystal oscillator frequency
|
||||
|
||||
class ATIRage : public PCIDevice, public VideoCtrlBase {
|
||||
public:
|
||||
ATIRage(uint16_t dev_id, uint32_t vmem_size_mb);
|
||||
ATIRage(uint16_t dev_id);
|
||||
~ATIRage() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create_gt() {
|
||||
return std::unique_ptr<ATIRage>(new ATIRage(ATI_RAGE_GT_DEV_ID));
|
||||
}
|
||||
|
||||
static std::unique_ptr<HWComponent> create_pro() {
|
||||
return std::unique_ptr<ATIRage>(new ATIRage(ATI_RAGE_PRO_DEV_ID));
|
||||
}
|
||||
|
||||
/* MMIODevice methods */
|
||||
uint32_t read(uint32_t reg_start, uint32_t offset, int size);
|
||||
void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size);
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
/* PCI device methods */
|
||||
bool supports_io_space(void) {
|
||||
@@ -216,8 +72,9 @@ public:
|
||||
bool pci_io_write(uint32_t offset, uint32_t value, uint32_t size);
|
||||
|
||||
protected:
|
||||
void notify_bar_change(int bar_num);
|
||||
const char* get_reg_name(uint32_t reg_offset);
|
||||
bool io_access_allowed(uint32_t offset, uint32_t* p_io_base);
|
||||
bool io_access_allowed(uint32_t offset);
|
||||
uint32_t read_reg(uint32_t offset, uint32_t size);
|
||||
void write_reg(uint32_t offset, uint32_t value, uint32_t size);
|
||||
float calc_pll_freq(int scale, int fb_div);
|
||||
@@ -228,18 +85,19 @@ protected:
|
||||
private:
|
||||
uint8_t mm_regs[2048] = {0}; // internal registers
|
||||
|
||||
uint8_t pci_cfg[256] = {0}; // PCI configuration space
|
||||
|
||||
uint8_t plls[64] = {0}; // internal PLL registers
|
||||
|
||||
/* Video RAM variables */
|
||||
std::unique_ptr<uint8_t[]> vram_ptr;
|
||||
uint32_t vram_size;
|
||||
|
||||
uint32_t aperture_base;
|
||||
uint32_t aperture_base = 0;
|
||||
uint32_t io_base = 0;
|
||||
uint8_t user_cfg = 8;
|
||||
|
||||
std::unique_ptr<DisplayID> disp_id;
|
||||
|
||||
int comp_index; /* color component index for DAC palette access */
|
||||
};
|
||||
|
||||
#endif /* ATI_RAGE_H */
|
||||
@@ -0,0 +1,368 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 TNT on-board video output emulation. */
|
||||
|
||||
/** TNT on-board video comprises several components:
|
||||
- Chaos ASIC that provides data bus buffering between the video subsystem
|
||||
and the processor bus
|
||||
- Control ASIC that provides addressing and control for the video subsystem
|
||||
- RaDACal RAMDAC ASIC for generating video stream to the monitor
|
||||
- Athens clock generator for generating pixel clock
|
||||
|
||||
Kudos to joevt#3510 for his precious technical help and HW hacking.
|
||||
*/
|
||||
|
||||
#include <core/timermanager.h>
|
||||
#include <devices/common/i2c/athens.h>
|
||||
#include <devices/common/i2c/i2c.h>
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/video/control.h>
|
||||
#include <endianswap.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
ControlVideo::ControlVideo()
|
||||
: PCIDevice("Control-Video"), VideoCtrlBase(640, 480)
|
||||
{
|
||||
supports_types(HWCompType::PCI_HOST | HWCompType::PCI_DEV);
|
||||
|
||||
// get VRAM size in MBs and convert it to bytes
|
||||
this->vram_size = GET_INT_PROP("gfxmem_size") << 20;
|
||||
|
||||
// allocate VRAM
|
||||
this->vram_ptr = std::unique_ptr<uint8_t[]> (new uint8_t[this->vram_size]);
|
||||
|
||||
// set up PCI configuration space header
|
||||
this->vendor_id = PCI_VENDOR_APPLE;
|
||||
this->device_id = 3;
|
||||
this->class_rev = 0;
|
||||
this->bars_cfg[1] = 0xFFFFF000UL; // base address for the HW registers (4KB)
|
||||
this->bars_cfg[2] = 0xFC000000UL; // base address for the VRAM (64MB)
|
||||
|
||||
this->pci_notify_bar_change = [this](int bar_num) {
|
||||
this->notify_bar_change(bar_num);
|
||||
};
|
||||
|
||||
// initialize the video clock generator
|
||||
this->clk_gen = std::unique_ptr<AthensClocks> (new AthensClocks(0x28));
|
||||
|
||||
// register the video clock generator with the I2C host
|
||||
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
i2c_bus->register_device(0x28, this->clk_gen.get());
|
||||
|
||||
// register RaDACal with the I/O controller
|
||||
GrandCentral* gc_obj = dynamic_cast<GrandCentral*>(gMachineObj->get_comp_by_name("GrandCentral"));
|
||||
gc_obj->attach_iodevice(1, this);
|
||||
|
||||
// initialize display identification
|
||||
this->display_id = std::unique_ptr<DisplayID> (new DisplayID());
|
||||
}
|
||||
|
||||
void ControlVideo::notify_bar_change(int bar_num)
|
||||
{
|
||||
switch (bar_num) {
|
||||
case 1:
|
||||
if (this->regs_base != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
this->regs_base = this->bars[bar_num] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->regs_base,
|
||||
0x1000, this);
|
||||
LOG_F(INFO, "Control: register aperture set to 0x%08X", this->regs_base);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (this->vram_base != (this->bars[bar_num] & 0xFFFFFFF0UL)) {
|
||||
this->vram_base = this->bars[bar_num] & 0xFFFFFFF0UL;
|
||||
this->host_instance->pci_register_mmio_region(this->vram_base,
|
||||
0x04000000, this);
|
||||
LOG_F(INFO, "Control: VRAM aperture set to 0x%08X", this->vram_base);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ControlVideo::read(uint32_t rgn_start, uint32_t offset, int size)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
if (rgn_start == this->vram_base) {
|
||||
if (offset >= 0x800000) {
|
||||
return read_mem_rev(&this->vram_ptr[offset - 0x800000], size);
|
||||
} else {
|
||||
LOG_F(INFO, "Control: little-endian access to VRAM not supported yet");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
switch (offset >> 4) {
|
||||
case ControlRegs::TEST:
|
||||
result = this->test;
|
||||
break;
|
||||
case ControlRegs::MON_SENSE:
|
||||
result = this->cur_mon_id << 6;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "read from 0x%08X:0x%08X", rgn_start, offset);
|
||||
}
|
||||
|
||||
return BYTESWAP_32(result);
|
||||
}
|
||||
|
||||
void ControlVideo::write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size)
|
||||
{
|
||||
if (rgn_start == this->vram_base) {
|
||||
if (offset >= 0x800000) {
|
||||
write_mem_rev(&this->vram_ptr[offset - 0x800000], value, size);
|
||||
} else {
|
||||
LOG_F(INFO, "Control: little-endian access to VRAM not supported yet");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
value = BYTESWAP_32(value);
|
||||
|
||||
switch (offset >> 4) {
|
||||
case ControlRegs::VFPEQ:
|
||||
case ControlRegs::VFP:
|
||||
case ControlRegs::VAL:
|
||||
case ControlRegs::VBP:
|
||||
case ControlRegs::VBPEQ:
|
||||
case ControlRegs::VSYNC:
|
||||
case ControlRegs::VHLINE:
|
||||
case ControlRegs::PIPED:
|
||||
case ControlRegs::HPIX:
|
||||
case ControlRegs::HFP:
|
||||
case ControlRegs::HAL:
|
||||
case ControlRegs::HBWAY:
|
||||
case ControlRegs::HSP:
|
||||
case ControlRegs::HEQ:
|
||||
case ControlRegs::HLFLN:
|
||||
case ControlRegs::HSERR:
|
||||
this->swatch_params[(offset >> 4) - 1] = value;
|
||||
break;
|
||||
case ControlRegs::TEST:
|
||||
if (this->test != value) {
|
||||
if ((this->test & ~TEST_STROBE) != (value & ~TEST_STROBE)) {
|
||||
this->test = value;
|
||||
this->test_shift = 0;
|
||||
LOG_F(9, "New TEST value: 0x%08X", this->test);
|
||||
} else {
|
||||
LOG_F(9, "TEST strobe bit flipped, new value: 0x%08X", value);
|
||||
this->test = value;
|
||||
if (++this->test_shift >= 3) {
|
||||
LOG_F(9, "Received TEST reg value: 0x%08X", this->test & ~TEST_STROBE);
|
||||
if ((this->test ^ this->prev_test) & 0x400) {
|
||||
if (this->test & 0x400) {
|
||||
this->disable_display();
|
||||
} else {
|
||||
this->enable_display();
|
||||
}
|
||||
this->prev_test = this->test;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ControlRegs::GBASE:
|
||||
this->fb_base = value;
|
||||
break;
|
||||
case ControlRegs::ROW_WORDS:
|
||||
this->row_words = value;
|
||||
break;
|
||||
case ControlRegs::MON_SENSE:
|
||||
LOG_F(9, "Control: monitor sense written with 0x%X", value);
|
||||
value = (value >> 3) & 7;
|
||||
this->cur_mon_id = this->display_id->read_monitor_sense(value & 7, value ^ 7);
|
||||
break;
|
||||
case ControlRegs::ENABLE:
|
||||
this->flags = value;
|
||||
break;
|
||||
case ControlRegs::GSC_DIVIDE:
|
||||
this->clock_divider = value;
|
||||
break;
|
||||
case ControlRegs::REFRESH_COUNT:
|
||||
LOG_F(INFO, "Control: refresh count set to 0x%08X", value);
|
||||
break;
|
||||
case ControlRegs::INT_ENABLE:
|
||||
this->int_enable = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "write 0x%08X to 0x%08X:0x%08X", value, rgn_start, offset);
|
||||
}
|
||||
}
|
||||
|
||||
void ControlVideo::enable_display()
|
||||
{
|
||||
int new_width, new_height, hori_blank, vert_blank, clk_divisor;
|
||||
|
||||
// get pixel frequency from Athens
|
||||
this->pixel_clock = this->clk_gen->get_dot_freq();
|
||||
|
||||
// get RaDACal clock divisor
|
||||
clk_divisor = 1 << ((rad_cr >> 6) + 1);
|
||||
|
||||
// calculate active_width and active_height from video timing parameters
|
||||
new_width = swatch_params[ControlRegs::HFP-1] - swatch_params[ControlRegs::HAL-1];
|
||||
new_height = swatch_params[ControlRegs::VFP-1] - swatch_params[ControlRegs::VAL-1];
|
||||
|
||||
new_width *= clk_divisor;
|
||||
new_height >>= 1; // FIXME: assume non-interlaced mode for now
|
||||
|
||||
if (new_width != this->active_width || new_height != this->active_height) {
|
||||
LOG_F(WARNING, "Display window resizing not implemented yet!");
|
||||
}
|
||||
|
||||
this->active_width = new_width;
|
||||
this->active_height = new_height;
|
||||
|
||||
// get pixel depth from RaDACal
|
||||
switch ((this->rad_cr >> 2) & 3) {
|
||||
case 0:
|
||||
this->pixel_depth = 8;
|
||||
break;
|
||||
case 1:
|
||||
this->pixel_depth = 16;
|
||||
break;
|
||||
case 2:
|
||||
this->pixel_depth = 32;
|
||||
break;
|
||||
default:
|
||||
ABORT_F("Invalid RaDACal pixel depth code!");
|
||||
}
|
||||
|
||||
if (pixel_depth == 8) {
|
||||
this->convert_fb_cb = [this](uint8_t *dst_buf, int dst_pitch) {
|
||||
this->convert_frame_8bpp(dst_buf, dst_pitch);
|
||||
};
|
||||
} else {
|
||||
ABORT_F("Control: 16bpp and 32bpp formats not supported yet!");
|
||||
}
|
||||
|
||||
// set framebuffer parameters
|
||||
this->fb_ptr = &this->vram_ptr[this->fb_base];
|
||||
this->fb_pitch = this->row_words;
|
||||
|
||||
// calculate display refresh rate
|
||||
hori_blank = swatch_params[ControlRegs::HAL-1] +
|
||||
(swatch_params[ControlRegs::HSP-1] - swatch_params[ControlRegs::HFP-1]);
|
||||
|
||||
hori_blank *= clk_divisor;
|
||||
|
||||
vert_blank = swatch_params[ControlRegs::VAL-1] +
|
||||
(swatch_params[ControlRegs::VSYNC-1] - swatch_params[ControlRegs::VFP-1]);
|
||||
|
||||
vert_blank >>= 1;
|
||||
|
||||
this->refresh_rate = (double)(this->pixel_clock) / (new_width + hori_blank)
|
||||
/ (new_height + vert_blank);
|
||||
LOG_F(INFO, "Control: refresh rate set to %f Hz", this->refresh_rate);
|
||||
|
||||
// set up periodic timer for display updates
|
||||
uint64_t refresh_interval = static_cast<uint64_t>(1.0f / refresh_rate * NS_PER_SEC + 0.5);
|
||||
TimerManager::get_instance()->add_cyclic_timer(
|
||||
refresh_interval,
|
||||
[this]() {
|
||||
this->update_screen();
|
||||
}
|
||||
);
|
||||
|
||||
this->update_screen();
|
||||
|
||||
LOG_F(INFO, "Control: display enabled");
|
||||
this->crtc_on = true;
|
||||
}
|
||||
|
||||
void ControlVideo::disable_display()
|
||||
{
|
||||
this->crtc_on = false;
|
||||
LOG_F(INFO, "Control: display disabled");
|
||||
}
|
||||
|
||||
// ========================== RaDACal related stuff ==========================
|
||||
|
||||
uint16_t ControlVideo::iodev_read(uint32_t address)
|
||||
{
|
||||
LOG_F(INFO, "RaDACal: read from 0x%08X", address);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ControlVideo::iodev_write(uint32_t address, uint16_t value)
|
||||
{
|
||||
switch (address) {
|
||||
case RadacalRegs::ADDRESS:
|
||||
this->rad_addr = value;
|
||||
this->comp_index = 0;
|
||||
break;
|
||||
case RadacalRegs::CURSOR_DATA:
|
||||
break;
|
||||
case RadacalRegs::MULTI:
|
||||
switch (this->rad_addr) {
|
||||
case RadacalRegs::CURSOR_POS_HI:
|
||||
this->rad_cur_pos_hi = value;
|
||||
break;
|
||||
case RadacalRegs::CURSOR_POS_LO:
|
||||
this->rad_cur_pos_lo = value;
|
||||
break;
|
||||
case RadacalRegs::MISC_CTRL:
|
||||
this->rad_cr = value;
|
||||
break;
|
||||
case RadacalRegs::DBL_BUF_CTRL:
|
||||
this->rad_dbl_buf_cr = value;
|
||||
break;
|
||||
default:
|
||||
LOG_F(ERROR, "Unsupported RaDACal register %d", this->rad_addr);
|
||||
}
|
||||
break;
|
||||
case RadacalRegs::CLUT_DATA:
|
||||
this->clut_color[this->comp_index++] = value;
|
||||
if (this->comp_index >= 3) {
|
||||
// TODO: combine separate components into a single ARGB value
|
||||
this->palette[this->rad_addr][0] = this->clut_color[0];
|
||||
this->palette[this->rad_addr][1] = this->clut_color[1];
|
||||
this->palette[this->rad_addr][2] = this->clut_color[2];
|
||||
this->palette[this->rad_addr][3] = 255;
|
||||
this->rad_addr++; // auto-increment CLUT address
|
||||
this->comp_index = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_F(INFO, "RaDACal: write to non-existent register at 0x%08X", address);
|
||||
}
|
||||
}
|
||||
|
||||
// ========================== Device registry stuff ==========================
|
||||
|
||||
static const PropMap Control_Properties = {
|
||||
{"gfxmem_size",
|
||||
new IntProperty( 2, vector<uint32_t>({2, 4}))},
|
||||
{"mon_id",
|
||||
new StrProperty("AppleVision1710")},
|
||||
};
|
||||
|
||||
static const DeviceDescription Control_Descriptor = {
|
||||
ControlVideo::create, {}, Control_Properties
|
||||
};
|
||||
|
||||
REGISTER_DEVICE(ControlVideo, Control_Descriptor);
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 TNT on-board video output definitions. */
|
||||
|
||||
#ifndef CONTROL_VIDEO_H
|
||||
#define CONTROL_VIDEO_H
|
||||
|
||||
#include <devices/common/i2c/athens.h>
|
||||
#include <devices/common/pci/pcidevice.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/video/displayid.h>
|
||||
#include <devices/video/videoctrl.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
|
||||
#define TEST_STROBE (1 << 3) // strobe bit
|
||||
|
||||
// Memory-mapped registers.
|
||||
namespace ControlRegs {
|
||||
|
||||
enum ControlRegs : int {
|
||||
CUR_LINE = 0x00, // current active video line
|
||||
VFPEQ = 0x01,
|
||||
VFP = 0x02,
|
||||
VAL = 0x03, // vertical active line
|
||||
VBP = 0x04,
|
||||
VBPEQ = 0x05, // begin of th vertical back porch with equalization
|
||||
VSYNC = 0x06,
|
||||
VHLINE = 0x07,
|
||||
PIPED = 0x08,
|
||||
HPIX = 0x09,
|
||||
HFP = 0x0A,
|
||||
HAL = 0x0B, // horizontal active line
|
||||
HBWAY = 0x0C,
|
||||
HSP = 0x0D,
|
||||
HEQ = 0x0E,
|
||||
HLFLN = 0x0F,
|
||||
HSERR = 0x10,
|
||||
CNTTST = 0x11, // Swatch counter test
|
||||
TEST = 0x12,
|
||||
GBASE = 0x13, // Graphics base address
|
||||
ROW_WORDS = 0x14,
|
||||
MON_SENSE = 0x15, // Monitor sense control & status
|
||||
ENABLE = 0x16,
|
||||
GSC_DIVIDE = 0x17, // graphics clock divide count
|
||||
REFRESH_COUNT = 0x18,
|
||||
INT_ENABLE = 0x19,
|
||||
INT_STATUS = 0x1A
|
||||
};
|
||||
|
||||
}; // namespace ControlRegs
|
||||
|
||||
namespace RadacalRegs {
|
||||
|
||||
enum RadacalRegs : uint8_t {
|
||||
ADDRESS = 0, // address register
|
||||
CURSOR_DATA = 1, // cursor data
|
||||
MULTI = 2, // multipurpose section
|
||||
CLUT_DATA = 3, // color palette data
|
||||
|
||||
// multipurpose section registers
|
||||
CURSOR_POS_HI = 0x10, // cursor position, high-order byte
|
||||
CURSOR_POS_LO = 0x11, // cursor position, low-order byte
|
||||
MISC_CTRL = 0x20, // miscellaneus control bits
|
||||
DBL_BUF_CTRL = 0x21, // double buffer control bits
|
||||
};
|
||||
|
||||
}; // namespace RadacalRegs
|
||||
|
||||
class ControlVideo : public PCIDevice, public VideoCtrlBase, public IobusDevice {
|
||||
public:
|
||||
ControlVideo();
|
||||
~ControlVideo() = default;
|
||||
|
||||
static std::unique_ptr<HWComponent> create() {
|
||||
return std::unique_ptr<ControlVideo>(new ControlVideo());
|
||||
}
|
||||
|
||||
// MMIODevice methods
|
||||
uint32_t read(uint32_t rgn_start, uint32_t offset, int size);
|
||||
void write(uint32_t rgn_start, uint32_t offset, uint32_t value, int size);
|
||||
|
||||
protected:
|
||||
void notify_bar_change(int bar_num);
|
||||
|
||||
void enable_display();
|
||||
void disable_display();
|
||||
|
||||
// IobusDevice methods for RaDACal
|
||||
uint16_t iodev_read(uint32_t address);
|
||||
void iodev_write(uint32_t address, uint16_t value);
|
||||
|
||||
private:
|
||||
std::unique_ptr<DisplayID> display_id;
|
||||
std::unique_ptr<AthensClocks> clk_gen;
|
||||
|
||||
std::unique_ptr<uint8_t[]> vram_ptr;
|
||||
|
||||
uint32_t vram_size;
|
||||
uint32_t vram_base = 0;
|
||||
uint32_t regs_base = 0;
|
||||
uint32_t prev_test = 0x433;
|
||||
uint32_t test = 0;
|
||||
uint32_t clock_divider = 0;
|
||||
uint32_t row_words = 0;
|
||||
uint32_t fb_base = 0;
|
||||
uint16_t swatch_params[16];
|
||||
int test_shift = 0;
|
||||
uint8_t cur_mon_id = 0;
|
||||
uint8_t flags = 0;
|
||||
uint8_t int_enable = 0;
|
||||
|
||||
// RaDACal internal state
|
||||
uint8_t rad_addr = 0;
|
||||
uint8_t rad_cr = 0;
|
||||
uint8_t rad_dbl_buf_cr = 0;
|
||||
uint8_t rad_cur_pos_hi = 0;
|
||||
uint8_t rad_cur_pos_lo = 0;
|
||||
uint8_t comp_index;
|
||||
uint8_t clut_color[3];
|
||||
};
|
||||
|
||||
#endif // CONTROL_VIDEO_H
|
||||
@@ -77,6 +77,14 @@ DisplayID::DisplayID()
|
||||
this->data_ptr = 0;
|
||||
}
|
||||
|
||||
DisplayID::DisplayID(uint8_t std_code, uint8_t ext_code)
|
||||
{
|
||||
this->id_kind = Disp_Id_Kind::AppleSense;
|
||||
|
||||
this->std_sense_code = std_code;
|
||||
this->ext_sense_code = ext_code;
|
||||
}
|
||||
|
||||
uint8_t DisplayID::read_monitor_sense(uint8_t levels, uint8_t dirs)
|
||||
{
|
||||
uint8_t scl, sda;
|
||||
|
||||
@@ -56,6 +56,7 @@ enum I2CState : uint8_t {
|
||||
class DisplayID {
|
||||
public:
|
||||
DisplayID();
|
||||
DisplayID(uint8_t std_code, uint8_t ext_code);
|
||||
~DisplayID() = default;
|
||||
|
||||
uint8_t read_monitor_sense(uint8_t levels, uint8_t dirs);
|
||||
@@ -81,6 +82,7 @@ private:
|
||||
uint8_t reg_addr; /* current register address */
|
||||
uint8_t* data_ptr; /* ptr to data byte to be transferred next */
|
||||
|
||||
/*
|
||||
uint8_t edid[128] = {
|
||||
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x06, 0x10, 0x02, 0x9d, 0x01, 0x01, 0x01,
|
||||
0x01, 0x08, 0x09, 0x01, 0x01, 0x68, 0x20, 0x18, 0x28, 0xe8, 0x04, 0x89, 0xa0, 0x57, 0x4a,
|
||||
@@ -90,7 +92,21 @@ private:
|
||||
0x32, 0x62, 0xb0, 0x32, 0x40, 0x40, 0xc2, 0x13, 0x00, 0x38, 0xea, 0x10, 0x00, 0x00, 0x18,
|
||||
0x00, 0x00, 0x00, 0xfd, 0x00, 0x30, 0xa0, 0x1e, 0x55, 0x10, 0x00, 0x0a, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x53, 0x74, 0x75, 0x64, 0x69, 0x6f, 0x44,
|
||||
0x73, 0x70, 0x6c, 0x79, 0x31, 0x37, 0x00, 0x19};
|
||||
0x73, 0x70, 0x6c, 0x79, 0x31, 0x37, 0x00, 0x19};*/
|
||||
|
||||
uint8_t edid[128] = {
|
||||
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x34, 0x38, 0x09, 0x06,
|
||||
0x1b, 0x06, 0x00, 0x00, 0x03, 0x0c, 0x01, 0x02, 0x68, 0x1e, 0x17, 0x78,
|
||||
0xea, 0x6d, 0x8c, 0x98, 0x59, 0x50, 0x93, 0x26, 0x20, 0x4c, 0x52, 0xbf,
|
||||
0xee, 0x00, 0x31, 0x4f, 0x45, 0x4f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
|
||||
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xc3, 0x1e, 0x00, 0x20, 0x41, 0x00,
|
||||
0x20, 0x30, 0x10, 0x60, 0x13, 0x00, 0x30, 0xe4, 0x10, 0x00, 0x00, 0x1e,
|
||||
0x00, 0x00, 0x00, 0xfd, 0x00, 0x37, 0x4b, 0x1f, 0x3c, 0x08, 0x00, 0x0a,
|
||||
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x31,
|
||||
0x30, 0x20, 0x31, 0x35, 0x20, 0x34, 0x35, 0x0a, 0x20, 0x20, 0x20, 0x20,
|
||||
0x00, 0x00, 0x00, 0xfe, 0x00, 0x4d, 0x61, 0x78, 0x64, 0x61, 0x74, 0x61,
|
||||
0x31, 0x30, 0x31, 0x35, 0x34, 0x35, 0x00, 0xf4
|
||||
};
|
||||
|
||||
/* More EDID:
|
||||
00ff ffff ffff ff00 5a63 5151 0341 0000
|
||||
|
||||
@@ -69,7 +69,6 @@ protected:
|
||||
|
||||
private:
|
||||
uint8_t video_mode;
|
||||
uint8_t pixel_depth;
|
||||
uint8_t blanking;
|
||||
uint8_t vdac_mode;
|
||||
uint8_t clut_index;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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/>.
|
||||
*/
|
||||
|
||||
/** IBM RGB514 RAMDAC definitions. */
|
||||
|
||||
#include <cinttypes>
|
||||
|
||||
#ifndef IBM_RGB514_DEFS_H
|
||||
#define IBM_RGB514_DEFS_H
|
||||
|
||||
namespace Rgb514 {
|
||||
|
||||
#define PLL_ENAB 1
|
||||
|
||||
/** RGB514 direct register addresses. */
|
||||
enum {
|
||||
// standard VGA registers
|
||||
CLUT_ADDR_WR = 0,
|
||||
CLUT_DATA = 1,
|
||||
CLUT_MASK = 2,
|
||||
CLUT_ADDR_RD = 3,
|
||||
|
||||
// extended registers
|
||||
INDEX_LOW = 4,
|
||||
INDEX_HIGH = 5,
|
||||
INDEX_DATA = 6,
|
||||
INDEX_CNTL = 7
|
||||
};
|
||||
|
||||
/** RGB514 indirect registers. */
|
||||
enum {
|
||||
MISC_CLK_CNTL = 0x0002,
|
||||
HOR_SYNC_POS = 0x0004,
|
||||
PWR_MNMGMT = 0x0005,
|
||||
PIX_FORMAT = 0x000A,
|
||||
PLL_CTL_1 = 0x0010,
|
||||
F0_M0 = 0x0020,
|
||||
F1_N0 = 0x0021,
|
||||
MISC_CNTL_1 = 0x0070,
|
||||
MISC_CNTL_2 = 0x0071,
|
||||
VRAM_MASK_LO = 0x0090,
|
||||
VRAM_MASK_HI = 0x0091,
|
||||
};
|
||||
|
||||
}; // namespace Rgb514
|
||||
|
||||
#endif // IBM_RGB514_DEFS_H
|
||||
@@ -46,12 +46,12 @@ VideoCtrlBase::VideoCtrlBase(int width, int height)
|
||||
);
|
||||
|
||||
if (this->display_wnd == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateWindow failed with %s\n", SDL_GetError());
|
||||
LOG_F(ERROR, "Display: SDL_CreateWindow failed with %s", SDL_GetError());
|
||||
}
|
||||
|
||||
this->renderer = SDL_CreateRenderer(this->display_wnd, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (this->renderer == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateRenderer failed with %s\n", SDL_GetError());
|
||||
LOG_F(ERROR, "Display: SDL_CreateRenderer failed with %s", SDL_GetError());
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(this->renderer, 0, 0, 0, 255);
|
||||
@@ -69,11 +69,11 @@ VideoCtrlBase::VideoCtrlBase(int width, int height)
|
||||
this->renderer,
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
640, 480
|
||||
width, height
|
||||
);
|
||||
|
||||
if (this->disp_texture == NULL) {
|
||||
LOG_F(ERROR, "Display: SDL_CreateTexture failed with %s\n", SDL_GetError());
|
||||
LOG_F(ERROR, "Display: SDL_CreateTexture failed with %s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +119,6 @@ void VideoCtrlBase::update_screen()
|
||||
//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, "Display uodate took: %lld ns", time_elapsed.count());
|
||||
|
||||
SDL_Delay(15);
|
||||
}
|
||||
|
||||
void VideoCtrlBase::convert_frame_1bpp(uint8_t *dst_buf, int dst_pitch)
|
||||
|
||||
@@ -45,6 +45,7 @@ protected:
|
||||
bool crtc_on = false;
|
||||
int active_width; // width of the visible display area
|
||||
int active_height; // height of the visible display area
|
||||
int pixel_depth;
|
||||
float pixel_clock;
|
||||
float refresh_rate;
|
||||
|
||||
|
||||
+16
-64
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -33,59 +33,28 @@ MachineBase::MachineBase(std::string name) {
|
||||
this->name = name;
|
||||
|
||||
/* initialize internal maps */
|
||||
this->comp_map.clear();
|
||||
this->subdev_map.clear();
|
||||
this->aliases.clear();
|
||||
this->device_map.clear();
|
||||
}
|
||||
|
||||
MachineBase::~MachineBase() {
|
||||
for (auto it = this->comp_map.begin(); it != this->comp_map.end(); it++) {
|
||||
delete it->second;
|
||||
}
|
||||
this->comp_map.clear();
|
||||
this->aliases.clear();
|
||||
this->subdev_map.clear();
|
||||
this->device_map.clear();
|
||||
}
|
||||
|
||||
bool MachineBase::add_component(std::string name, HWComponent* dev_obj) {
|
||||
if (this->comp_map.count(name)) {
|
||||
LOG_F(ERROR, "Component %s already exists!", name.c_str());
|
||||
return false;
|
||||
void MachineBase::add_device(std::string name, std::unique_ptr<HWComponent> dev_obj) {
|
||||
if (this->device_map.count(name)) {
|
||||
LOG_F(ERROR, "Device %s already exists!", name.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
this->comp_map[name] = dev_obj;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MachineBase::add_subdevice(std::string name, HWComponent* dev_obj) {
|
||||
if (this->subdev_map.count(name)) {
|
||||
LOG_F(ERROR, "Subdevice %s already exists!", name.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
this->subdev_map[name] = dev_obj;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MachineBase::add_alias(std::string name, std::string alias) {
|
||||
this->aliases[alias] = name;
|
||||
this->device_map[name] = std::move(dev_obj);
|
||||
}
|
||||
|
||||
HWComponent* MachineBase::get_comp_by_name(std::string name) {
|
||||
if (this->aliases.count(name)) {
|
||||
name = this->aliases[name];
|
||||
}
|
||||
|
||||
if (this->comp_map.count(name)) {
|
||||
return this->comp_map[name];
|
||||
}
|
||||
|
||||
if (this->subdev_map.count(name)) {
|
||||
return this->subdev_map[name];
|
||||
if (this->device_map.count(name)) {
|
||||
return this->device_map[name].get();
|
||||
} else {
|
||||
return NULL;
|
||||
LOG_F(WARNING, "Component name %s not found!", name.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,19 +62,7 @@ HWComponent* MachineBase::get_comp_by_type(HWCompType type) {
|
||||
std::string comp_name;
|
||||
bool found = false;
|
||||
|
||||
for (auto it = this->comp_map.begin(); it != this->comp_map.end(); it++) {
|
||||
if (it->second->supports_type(type)) {
|
||||
comp_name = it->first;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
return this->get_comp_by_name(comp_name);
|
||||
}
|
||||
|
||||
for (auto it = this->subdev_map.begin(); it != this->subdev_map.end(); it++) {
|
||||
for (auto it = this->device_map.begin(); it != this->device_map.end(); it++) {
|
||||
if (it->second->supports_type(type)) {
|
||||
comp_name = it->first;
|
||||
found = true;
|
||||
@@ -116,19 +73,14 @@ HWComponent* MachineBase::get_comp_by_type(HWCompType type) {
|
||||
if (found) {
|
||||
return this->get_comp_by_name(comp_name);
|
||||
} else {
|
||||
return NULL;
|
||||
LOG_F(WARNING, "No component of type %lu was found!", type);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int MachineBase::postinit_devices()
|
||||
{
|
||||
for (auto it = this->comp_map.begin(); it != this->comp_map.end(); it++) {
|
||||
if (it->second->device_postinit()) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = this->subdev_map.begin(); it != this->subdev_map.end(); it++) {
|
||||
for (auto it = this->device_map.begin(); it != this->device_map.end(); it++) {
|
||||
if (it->second->device_postinit()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -38,18 +38,14 @@ public:
|
||||
MachineBase(std::string name);
|
||||
~MachineBase();
|
||||
|
||||
bool add_component(std::string name, HWComponent* dev_obj);
|
||||
bool add_subdevice(std::string name, HWComponent* dev_obj);
|
||||
void add_alias(std::string name, std::string alias);
|
||||
void add_device(std::string name, std::unique_ptr<HWComponent> dev_obj);
|
||||
HWComponent* get_comp_by_name(std::string name);
|
||||
HWComponent* get_comp_by_type(HWCompType type);
|
||||
int postinit_devices();
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
std::map<std::string, HWComponent*> comp_map;
|
||||
std::map<std::string, HWComponent*> subdev_map;
|
||||
std::map<std::string, std::string> aliases;
|
||||
std::map<std::string, std::unique_ptr<HWComponent>> device_map;
|
||||
};
|
||||
|
||||
extern std::unique_ptr<MachineBase> gMachineObj;
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-22 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 Constructs a Catalyst (Power Macintosh 7200) machine. */
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/pci/bandit.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/memctrl/platinum.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
int initialize_catalyst(std::string& id)
|
||||
{
|
||||
PlatinumCtrl* platinum_obj;
|
||||
|
||||
PCIHost *pci_host = dynamic_cast<PCIHost*>(gMachineObj->get_comp_by_name("Bandit1"));
|
||||
|
||||
// add the GrandCentral I/O controller
|
||||
pci_host->pci_register_device(
|
||||
32, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("GrandCentral")));
|
||||
|
||||
// get (raw) pointer to the memory controller
|
||||
platinum_obj = dynamic_cast<PlatinumCtrl*>(gMachineObj->get_comp_by_name("Platinum"));
|
||||
|
||||
// allocate ROM region
|
||||
if (!platinum_obj->add_rom_region(0xFFC00000, 0x400000)) {
|
||||
LOG_F(ERROR, "Could not allocate ROM region!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// plug 8MB RAM DIMM into slot #0
|
||||
platinum_obj->insert_ram_dimm(0, DRAM_CAP_8MB);
|
||||
|
||||
// allocate and map physical RAM
|
||||
platinum_obj->map_phys_ram();
|
||||
|
||||
// add single SCSI bus
|
||||
gMachineObj->add_device("SCSI0", std::unique_ptr<ScsiBus>(new ScsiBus()));
|
||||
|
||||
// init virtual CPU and request MPC601
|
||||
ppc_cpu_init(platinum_obj, PPC_VER::MPC601, 7833600ULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const PropMap pm7200_settings = {
|
||||
{"rambank1_size",
|
||||
new IntProperty(16, vector<uint32_t>({4, 8, 16, 32, 64, 128}))},
|
||||
{"rambank2_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
|
||||
{"rambank3_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
|
||||
{"rambank4_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 4, 8, 16, 32, 64, 128}))},
|
||||
{"gfxmem_size",
|
||||
new IntProperty( 1, vector<uint32_t>({1, 2, 4}))},
|
||||
{"mon_id",
|
||||
new StrProperty("HiRes12-14in")},
|
||||
{"emmo",
|
||||
new BinProperty(0)},
|
||||
};
|
||||
|
||||
static vector<string> pm7200_devices = {
|
||||
"Platinum", "Bandit1", "GrandCentral"
|
||||
};
|
||||
|
||||
static const MachineDescription pm7200_descriptor = {
|
||||
.name = "pm7200",
|
||||
.description = "Power Macintosh 7200",
|
||||
.devices = pm7200_devices,
|
||||
.settings = pm7200_settings,
|
||||
.init_func = &initialize_catalyst
|
||||
};
|
||||
|
||||
REGISTER_MACHINE(pm7200, pm7200_descriptor);
|
||||
+199
-148
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -24,8 +24,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <devices/memctrl/memctrlbase.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <machines/machineproperties.h>
|
||||
#include <memaccess.h>
|
||||
@@ -56,7 +59,7 @@ static const map<uint32_t, std::tuple<string, const char*>> rom_identity = {
|
||||
//{"Come", "PowerBook 2400"}, // Comet
|
||||
{0x436F7264, {"pm5200", "Power Mac 5200/6200 series"}}, // Cordyceps
|
||||
{0x47617A65, {"pm6500", "Power Mac 6500"}}, // Gazelle
|
||||
{0x476F7373, {"pmg3", "Power Mac G3 Beige"}}, // Gossamer
|
||||
{0x476F7373, {"pmg3dt", "Power Mac G3 Beige"}}, // Gossamer
|
||||
{0x47525820, {"pbg3", "PowerBook G3 Wallstreet"}},
|
||||
//{"Hoop", "PowerBook 3400"}, // Hooper
|
||||
{0x50425820, {"pb-preg3", "PowerBook Pre-G3"}},
|
||||
@@ -67,61 +70,206 @@ static const map<uint32_t, std::tuple<string, const char*>> rom_identity = {
|
||||
{0x5A616E7A, {"pm4400", "Power Mac 4400/7220"}}, // Zanzibar
|
||||
};
|
||||
|
||||
static const vector<string> WriteToggle = {"ON", "on", "OFF", "off"};
|
||||
|
||||
static const PropMap GossamerSettings = {
|
||||
{"rambank1_size",
|
||||
new IntProperty(256, vector<uint32_t>({8, 16, 32, 64, 128, 256}))},
|
||||
{"rambank2_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"rambank3_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"gfxmem_size",
|
||||
new IntProperty( 2, vector<uint32_t>({2, 4, 6}))},
|
||||
{"mon_id",
|
||||
new StrProperty("")},
|
||||
{"fdd_img",
|
||||
new StrProperty("")},
|
||||
{"fdd_wr_prot", new StrProperty("OFF", WriteToggle)},
|
||||
};
|
||||
|
||||
/** Monitors supported by the PDM on-board video. */
|
||||
/* see displayid.cpp for the full list of supported monitor IDs. */
|
||||
static const vector<string> PDMBuiltinMonitorIDs = {
|
||||
"PortraitGS", "MacRGB12in", "MacRGB15in", "HiRes12-14in", "VGA-SVGA",
|
||||
"MacRGB16in", "Multiscan15in", "Multiscan17in", "Multiscan20in",
|
||||
"NotConnected"
|
||||
};
|
||||
|
||||
static const PropMap PDMSettings = {
|
||||
{"rambank1_size",
|
||||
new IntProperty(0, vector<uint32_t>({0, 8, 16, 32, 64, 128}))},
|
||||
{"rambank2_size",
|
||||
new IntProperty(0, vector<uint32_t>({0, 8, 16, 32, 64, 128}))},
|
||||
{"mon_id",
|
||||
new StrProperty("HiRes12-14in", PDMBuiltinMonitorIDs)},
|
||||
{"fdd_img",
|
||||
new StrProperty("")},
|
||||
{"fdd_wr_prot",
|
||||
new StrProperty("OFF", WriteToggle)},
|
||||
};
|
||||
|
||||
static const map<string, string> PropHelp = {
|
||||
{"rambank1_size", "specifies RAM bank 1 size in MB"},
|
||||
{"rambank2_size", "specifies RAM bank 2 size in MB"},
|
||||
{"rambank3_size", "specifies RAM bank 3 size in MB"},
|
||||
{"rambank4_size", "specifies RAM bank 4 size in MB"},
|
||||
{"gfxmem_size", "specifies video memory size in MB"},
|
||||
{"fdd_img", "specifies path to floppy disk image"},
|
||||
{"fdd_wr_prot", "toggles floppy disks write protection"},
|
||||
{"fdd_wr_prot", "toggles floppy disk's write protection"},
|
||||
{"hdd_img", "specifies path to hard disk image"},
|
||||
{"hdd_wr_prot", "toggles hard disk's write protection"},
|
||||
{"cdr_img", "specifies path to CD-ROM image"},
|
||||
{"mon_id", "specifies which monitor to emulate"},
|
||||
{"pci_A1", "insert a PCI device into A1 slot"},
|
||||
{"pci_B1", "insert a PCI device into B1 slot"},
|
||||
{"pci_C1", "insert a PCI device into C1 slot"},
|
||||
{"serial_backend", "specifies the backend for the serial port"},
|
||||
{"emmo", "enables/disables factory HW tests during startup"},
|
||||
};
|
||||
|
||||
static const map<string, tuple<PropMap, function<int(string&)>, string>> machines = {
|
||||
{"pm6100", {PDMSettings, create_pdm, "PowerMacintosh 6100"}},
|
||||
{"pmg3", {GossamerSettings, create_gossamer, "Power Macintosh G3 (Beige)"}},
|
||||
};
|
||||
bool MachineFactory::add(const string& machine_id, MachineDescription desc)
|
||||
{
|
||||
if (get_registry().find(machine_id) != get_registry().end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
string machine_name_from_rom(string& rom_filepath) {
|
||||
get_registry()[machine_id] = desc;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MachineFactory::list_machines()
|
||||
{
|
||||
cout << endl << "Supported machines:" << endl << endl;
|
||||
|
||||
for (auto& m : get_registry()) {
|
||||
cout << setw(13) << m.first << "\t\t" << m.second.description << endl;
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void MachineFactory::create_device(string& dev_name, DeviceDescription& dev)
|
||||
{
|
||||
for (auto& subdev_name : dev.subdev_list) {
|
||||
create_device(subdev_name, DeviceRegistry::get_descriptor(subdev_name));
|
||||
}
|
||||
|
||||
gMachineObj->add_device(dev_name, dev.m_create_func());
|
||||
}
|
||||
|
||||
int MachineFactory::create(string& mach_id)
|
||||
{
|
||||
auto it = get_registry().find(mach_id);
|
||||
if (it == get_registry().end()) {
|
||||
LOG_F(ERROR, "Unknown machine id %s", mach_id.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Initializing %s hardware...", it->second.description.c_str());
|
||||
|
||||
// initialize global machine object
|
||||
gMachineObj.reset(new MachineBase(it->second.name));
|
||||
|
||||
// create and register sound server
|
||||
gMachineObj->add_device("SoundServer", std::unique_ptr<SoundServer>(new SoundServer()));
|
||||
|
||||
// recursively create device objects
|
||||
for (auto& dev_name : it->second.devices) {
|
||||
create_device(dev_name, DeviceRegistry::get_descriptor(dev_name));
|
||||
}
|
||||
|
||||
if (it->second.init_func(mach_id)) {
|
||||
LOG_F(ERROR, "Machine initialization function failed!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// post-initialize all devices
|
||||
if (gMachineObj->postinit_devices()) {
|
||||
LOG_F(ERROR, "Could not post-initialize devices!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Initialization completed.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MachineFactory::list_properties()
|
||||
{
|
||||
cout << endl;
|
||||
|
||||
for (auto& mach : get_registry()) {
|
||||
cout << mach.second.description << " supported properties:" << endl << endl;
|
||||
|
||||
print_settings(mach.second.settings);
|
||||
|
||||
for (auto& d : mach.second.devices) {
|
||||
list_device_settings(DeviceRegistry::get_descriptor(d));
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void MachineFactory::list_device_settings(DeviceDescription& dev)
|
||||
{
|
||||
for (auto& d : dev.subdev_list) {
|
||||
list_device_settings(DeviceRegistry::get_descriptor(d));
|
||||
}
|
||||
|
||||
print_settings(dev.properties);
|
||||
}
|
||||
|
||||
void MachineFactory::print_settings(PropMap& prop_map)
|
||||
{
|
||||
string help;
|
||||
|
||||
for (auto& p : prop_map) {
|
||||
if (PropHelp.find(p.first) != PropHelp.end())
|
||||
help = PropHelp.at(p.first);
|
||||
else
|
||||
help = "";
|
||||
|
||||
cout << setw(13) << p.first << "\t\t" << help << endl;
|
||||
|
||||
cout << setw(13) << "\t\t\t" "Valid values: ";
|
||||
|
||||
switch(p.second->get_type()) {
|
||||
case PROP_TYPE_INTEGER:
|
||||
cout << dynamic_cast<IntProperty*>(p.second)->get_valid_values_as_str()
|
||||
<< endl;
|
||||
break;
|
||||
case PROP_TYPE_STRING:
|
||||
cout << dynamic_cast<StrProperty*>(p.second)->get_valid_values_as_str()
|
||||
<< endl;
|
||||
break;
|
||||
case PROP_TYPE_BINARY:
|
||||
cout << dynamic_cast<BinProperty*>(p.second)->get_valid_values_as_str()
|
||||
<< endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void MachineFactory::get_device_settings(DeviceDescription& dev, map<string, string> &settings)
|
||||
{
|
||||
for (auto& d : dev.subdev_list) {
|
||||
get_device_settings(DeviceRegistry::get_descriptor(d), settings);
|
||||
}
|
||||
|
||||
for (auto& p : dev.properties) {
|
||||
settings[p.first] = p.second->get_string();
|
||||
|
||||
// populate dynamic machine settings from presets
|
||||
gMachineSettings[p.first] = unique_ptr<BasicProperty>(p.second->clone());
|
||||
}
|
||||
}
|
||||
|
||||
int MachineFactory::get_machine_settings(const string& id, map<string, string> &settings)
|
||||
{
|
||||
auto it = get_registry().find(id);
|
||||
if (it != get_registry().end()) {
|
||||
auto props = it->second.settings;
|
||||
|
||||
gMachineSettings.clear();
|
||||
|
||||
for (auto& p : props) {
|
||||
settings[p.first] = p.second->get_string();
|
||||
|
||||
// populate dynamic machine settings from presets
|
||||
gMachineSettings[p.first] = unique_ptr<BasicProperty>(p.second->clone());
|
||||
}
|
||||
|
||||
for (auto& dev : it->second.devices) {
|
||||
get_device_settings(DeviceRegistry::get_descriptor(dev), settings);
|
||||
}
|
||||
} else {
|
||||
LOG_F(ERROR, "Unknown machine id %s", id.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MachineFactory::set_machine_settings(map<string, string> &settings) {
|
||||
for (auto& s : settings) {
|
||||
gMachineSettings.at(s.first)->set_string(s.second);
|
||||
}
|
||||
|
||||
// print machine settings summary
|
||||
cout << endl << "Machine settings summary: " << endl;
|
||||
|
||||
for (auto& p : gMachineSettings) {
|
||||
cout << p.first << " : " << p.second->get_string() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
string MachineFactory::machine_name_from_rom(string& rom_filepath) {
|
||||
ifstream rom_file;
|
||||
uint32_t file_size, config_info_offset, rom_id;
|
||||
char rom_id_str[17];
|
||||
@@ -166,7 +314,7 @@ string machine_name_from_rom(string& rom_filepath) {
|
||||
rom_id = (rom_id_str[5] << 24) | (rom_id_str[6] << 16) |
|
||||
(rom_id_str[7] << 8) | rom_id_str[8];
|
||||
|
||||
LOG_F(INFO, "The machine is identified as... %s\n",
|
||||
LOG_F(INFO, "The machine is identified as... %s",
|
||||
std::get<1>(rom_identity.at(rom_id)));
|
||||
|
||||
machine_name = std::get<0>(rom_identity.at(rom_id));
|
||||
@@ -177,96 +325,8 @@ bail_out:
|
||||
return machine_name;
|
||||
}
|
||||
|
||||
int get_machine_settings(string& id, map<string, string> &settings) {
|
||||
try {
|
||||
auto props = get<0>(machines.at(id));
|
||||
|
||||
gMachineSettings.clear();
|
||||
|
||||
for (auto& p : props) {
|
||||
settings[p.first] = p.second->get_string();
|
||||
|
||||
/* populate dynamic machine settings from presets */
|
||||
gMachineSettings[p.first] = unique_ptr<BasicProperty>(p.second->clone());
|
||||
}
|
||||
}
|
||||
catch(out_of_range ex) {
|
||||
LOG_F(ERROR, "Unknown machine id %s", id.c_str());
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set_machine_settings(map<string, string> &settings) {
|
||||
for (auto& s : settings) {
|
||||
gMachineSettings.at(s.first)->set_string(s.second);
|
||||
}
|
||||
|
||||
/* print machine settings summary */
|
||||
cout << endl << "Machine settings summary: " << endl;
|
||||
|
||||
for (auto& p : gMachineSettings) {
|
||||
cout << p.first << " : " << p.second->get_string() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void list_machines() {
|
||||
cout << endl << "Supported machines:" << endl << endl;
|
||||
|
||||
for (auto& mach : machines) {
|
||||
cout << setw(13) << mach.first << "\t\t" << get<2>(mach.second) << endl;
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void list_properties() {
|
||||
cout << endl;
|
||||
|
||||
for (auto& mach : machines) {
|
||||
cout << get<2>(mach.second) << " supported properties:" << endl << endl;
|
||||
|
||||
for (auto& p : get<0>(mach.second)) {
|
||||
cout << setw(13) << p.first << "\t\t" << PropHelp.at(p.first)
|
||||
<< endl;
|
||||
|
||||
cout << setw(13) << "\t\t\t" "Valid values: ";
|
||||
|
||||
switch(p.second->get_type()) {
|
||||
case PROP_TYPE_INTEGER:
|
||||
cout << dynamic_cast<IntProperty*>(p.second)->get_valid_values_as_str()
|
||||
<< endl;
|
||||
break;
|
||||
case PROP_TYPE_STRING:
|
||||
cout << dynamic_cast<StrProperty*>(p.second)->get_valid_values_as_str()
|
||||
<< endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
/* Read ROM file content and transfer it to the dedicated ROM region */
|
||||
void load_rom(std::ifstream& rom_file, uint32_t file_size) {
|
||||
unsigned char* sysrom_mem = new unsigned char[file_size];
|
||||
|
||||
rom_file.seekg(0, ios::beg);
|
||||
rom_file.read((char*)sysrom_mem, file_size);
|
||||
|
||||
MemCtrlBase* mem_ctrl = dynamic_cast<MemCtrlBase*>(
|
||||
gMachineObj->get_comp_by_type(HWCompType::MEM_CTRL));
|
||||
|
||||
mem_ctrl->set_data(0xFFC00000, sysrom_mem, file_size);
|
||||
delete[] sysrom_mem;
|
||||
}
|
||||
|
||||
/* Read ROM file content and transfer it to the dedicated ROM region */
|
||||
int load_boot_rom(string& rom_filepath) {
|
||||
int MachineFactory::load_boot_rom(string& rom_filepath) {
|
||||
ifstream rom_file;
|
||||
size_t file_size;
|
||||
int result;
|
||||
@@ -311,17 +371,8 @@ int load_boot_rom(string& rom_filepath) {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int create_machine_for_id(string& id, string& rom_filepath) {
|
||||
try {
|
||||
auto machine = machines.at(id);
|
||||
|
||||
/* build machine and load boot ROM */
|
||||
if (get<1>(machine)(id) < 0 || load_boot_rom(rom_filepath) < 0) {
|
||||
return -1;
|
||||
}
|
||||
} catch(out_of_range ex) {
|
||||
LOG_F(ERROR, "Unknown machine id %s", id.c_str());
|
||||
int MachineFactory::create_machine_for_id(string& id, string& rom_filepath) {
|
||||
if (MachineFactory::create(id) < 0 || load_boot_rom(rom_filepath) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
+45
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -27,23 +27,58 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#ifndef MACHINE_FACTORY_H
|
||||
#define MACHINE_FACTORY_H
|
||||
|
||||
#include <devices/deviceregistry.h>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
std::string machine_name_from_rom(std::string& rom_filepath);
|
||||
struct MachineDescription {
|
||||
string name;
|
||||
string description;
|
||||
vector<string> devices;
|
||||
PropMap settings;
|
||||
function<int(string&)> init_func;
|
||||
};
|
||||
|
||||
int get_machine_settings(string& id, map<string, string> &settings);
|
||||
void set_machine_settings(map<string, string> &settings);
|
||||
int create_machine_for_id(string& id, string& rom_filepath);
|
||||
void list_machines(void);
|
||||
void list_properties(void);
|
||||
class MachineFactory
|
||||
{
|
||||
public:
|
||||
MachineFactory() = delete;
|
||||
|
||||
/* Machine-specific factory functions. */
|
||||
int create_gossamer(string& id);
|
||||
int create_pdm(string& id);
|
||||
static bool add(const string& machine_id, MachineDescription desc);
|
||||
|
||||
static string machine_name_from_rom(string& rom_filepath);
|
||||
|
||||
static int create(string& mach_id);
|
||||
static int create_machine_for_id(string& id, string& rom_filepath);
|
||||
|
||||
static int get_machine_settings(const string& id, map<string, string> &settings);
|
||||
static void set_machine_settings(map<string, string> &settings);
|
||||
|
||||
static void list_machines();
|
||||
static void list_properties();
|
||||
|
||||
private:
|
||||
static void create_device(string& dev_name, DeviceDescription& dev);
|
||||
static void print_settings(PropMap& p);
|
||||
static void list_device_settings(DeviceDescription& dev);
|
||||
static void get_device_settings(DeviceDescription& dev, map<string, string> &settings);
|
||||
static int load_boot_rom(string& rom_filepath);
|
||||
|
||||
static map<string, MachineDescription> & get_registry() {
|
||||
static map<string, MachineDescription> machine_registry;
|
||||
return machine_registry;
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_MACHINE(mach_name, mach_desc) \
|
||||
static bool mach_name ## _registered = MachineFactory::add(#mach_name, (mach_desc))
|
||||
|
||||
#endif /* MACHINE_FACTORY_H */
|
||||
+109
-53
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-21 divingkatae and maximum
|
||||
Copyright (C) 2018-22 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
@@ -25,98 +25,154 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cpu/ppc/ppcemu.h>
|
||||
#include <devices/common/i2c/athens.h>
|
||||
#include <devices/common/i2c/i2cprom.h>
|
||||
#include <devices/common/machineid.h>
|
||||
#include <devices/floppy/floppyimg.h>
|
||||
#include <devices/common/scsi/scsi.h>
|
||||
#include <devices/ioctrl/macio.h>
|
||||
#include <devices/memctrl/mpc106.h>
|
||||
#include <devices/memctrl/spdram.h>
|
||||
#include <devices/sound/soundserver.h>
|
||||
#include <devices/video/atirage.h>
|
||||
#include <loguru.hpp>
|
||||
#include <machines/machinebase.h>
|
||||
#include <machines/machinefactory.h>
|
||||
#include <machines/machineproperties.h>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
// Bit definitions for the Gossamer system register at 0xFF000004
|
||||
enum : uint16_t {
|
||||
FDC_TYPE_SWIM3 = (1 << 15), // Macintosh style floppy disk controller
|
||||
FDC_TYPE_MFDC = (0 << 15), // PC style floppy disk controller
|
||||
BURST_ROM_FALSE = (1 << 14), // burst ROM not present
|
||||
BURST_ROM_TRUE = (0 << 14), // burst ROM present
|
||||
PCI_C_PRSNT_POS = 12, // PRSNT bits for the PCI Slot C
|
||||
PCI_B_PRSNT_POS = 10, // PRSNT bits for the PCI Slot B
|
||||
PCI_A_PRSNT_POS = 8, // PRSNT bits for the PCI Slot A
|
||||
PCM_PID_POS = 5, // Processor und Cache module ID
|
||||
PCM_PID_MASK = 0xE0,
|
||||
AIO_PRSNT_FALSE = (1 << 4), // Whisper/Wings style card in the PERCH slot
|
||||
AIO_PRSNT_TRUE = (0 << 4), // All-in-one style card in the PERCH slot
|
||||
BUS_SPEED_POS = 1, // bus speed code, see below
|
||||
BUS_SPEED_MASK = 0x0E,
|
||||
UNKNOWN_BIT_0 = 1 // Don't know what this bit is for
|
||||
};
|
||||
|
||||
// Gossamer bus speed frequency codes
|
||||
enum : uint8_t {
|
||||
BUS_FREQ_75P00A = 0, // 75.00 MHz
|
||||
BUS_FREQ_70P00 = 1, // 70.00 MHz
|
||||
BUS_FREQ_78P75 = 2, // 78.75 MHz
|
||||
BUS_FREQ_TRI = 3, // clock output tristated
|
||||
BUS_FREQ_75P00B = 4, // 75.00 MHz
|
||||
BUS_FREQ_60P00 = 5, // 60.00 MHz
|
||||
BUS_FREQ_66P82 = 6, // 66.82 MHz
|
||||
BUS_FREQ_83P00 = 7, // 83.00 MHz
|
||||
};
|
||||
|
||||
// EEPROM ID content for a Whisper personality card.
|
||||
const uint8_t WhisperID[16] = {
|
||||
0x0F, 0xAA, 0x55, 0xAA, 0x57, 0x68, 0x69, 0x73, 0x70, 0x65, 0x72, 0x00,
|
||||
0x00, 0x00, 0x00, 0x02
|
||||
};
|
||||
|
||||
static void setup_ram_slot(std::string name, int i2c_addr, int capacity_megs) {
|
||||
if (!capacity_megs)
|
||||
return;
|
||||
|
||||
gMachineObj->add_component(name, new SpdSdram168(i2c_addr));
|
||||
gMachineObj->add_device(name, std::unique_ptr<SpdSdram168>(new SpdSdram168(i2c_addr)));
|
||||
SpdSdram168* ram_dimm = dynamic_cast<SpdSdram168*>(gMachineObj->get_comp_by_name(name));
|
||||
ram_dimm->set_capacity(capacity_megs);
|
||||
|
||||
/* register RAM DIMM with the I2C bus */
|
||||
// register RAM DIMM with the I2C bus
|
||||
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
i2c_bus->register_device(i2c_addr, ram_dimm);
|
||||
}
|
||||
|
||||
|
||||
int create_gossamer(std::string& id) {
|
||||
if (gMachineObj) {
|
||||
LOG_F(ERROR, "Global machine object not empty!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
LOG_F(INFO, "Initializing the Gossamer hardware...");
|
||||
|
||||
/* initialize the global machine object */
|
||||
gMachineObj.reset(new MachineBase("Gossamer"));
|
||||
|
||||
/* register MPC106 aka Grackle as memory controller and PCI host */
|
||||
gMachineObj->add_component("Grackle", new MPC106);
|
||||
gMachineObj->add_alias("Grackle", "PCI_Host");
|
||||
|
||||
/* get raw pointer to MPC106 object */
|
||||
int initialize_gossamer(std::string& id)
|
||||
{
|
||||
// get pointer to the memory controller/PCI host bridge object
|
||||
MPC106* grackle_obj = dynamic_cast<MPC106*>(gMachineObj->get_comp_by_name("Grackle"));
|
||||
|
||||
/* add the machine ID register */
|
||||
gMachineObj->add_component("MachineID", new GossamerID(0x3d8c));
|
||||
// configure the Gossamer system register
|
||||
uint16_t sys_reg = FDC_TYPE_SWIM3 | BURST_ROM_TRUE
|
||||
| (0x3F << PCI_A_PRSNT_POS) // pull up all PRSNT bits
|
||||
| (1 << PCM_PID_POS) // CPU/Cache speed ratio = 2:1
|
||||
| AIO_PRSNT_FALSE // this machine is not All-in-one
|
||||
| (BUS_FREQ_66P82 << BUS_SPEED_POS) // set bus frequency
|
||||
| UNKNOWN_BIT_0; // pull up bit 0
|
||||
|
||||
gMachineObj->add_device("MachineID", std::unique_ptr<GossamerID>(new GossamerID(sys_reg)));
|
||||
grackle_obj->add_mmio_region(
|
||||
0xFF000004, 4096, dynamic_cast<MMIODevice*>(gMachineObj->get_comp_by_name("MachineID")));
|
||||
|
||||
gMachineObj->add_component("SoundServer", new SoundServer());
|
||||
|
||||
/* add the Heathrow I/O controller */
|
||||
gMachineObj->add_component("Heathrow", new HeathrowIC);
|
||||
grackle_obj->pci_register_device(
|
||||
16, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("Heathrow")));
|
||||
|
||||
/* allocate ROM region */
|
||||
// allocate ROM region
|
||||
if (!grackle_obj->add_rom_region(0xFFC00000, 0x400000)) {
|
||||
LOG_F(ERROR, "Could not allocate ROM region!\n");
|
||||
LOG_F(ERROR, "Could not allocate ROM region!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* configure RAM slots */
|
||||
// configure RAM slots
|
||||
setup_ram_slot("RAM_DIMM_1", 0x57, GET_INT_PROP("rambank1_size"));
|
||||
setup_ram_slot("RAM_DIMM_2", 0x56, GET_INT_PROP("rambank2_size"));
|
||||
setup_ram_slot("RAM_DIMM_3", 0x55, GET_INT_PROP("rambank3_size"));
|
||||
|
||||
/* register ATI 3D Rage Pro video card with the PCI host bridge */
|
||||
gMachineObj->add_component("ATIRage",
|
||||
new ATIRage(ATI_RAGE_PRO_DEV_ID, GET_INT_PROP("gfxmem_size")));
|
||||
// add pci devices
|
||||
grackle_obj->pci_register_device(
|
||||
18, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("ATIRage")));
|
||||
16, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name("Heathrow")));
|
||||
grackle_obj->pci_register_device(
|
||||
18, dynamic_cast<PCIDevice*>(gMachineObj->get_comp_by_name(id == "pmg3twr" ? "AtiRagePro" : "AtiRageGT")));
|
||||
|
||||
/* Init virtual CPU and request MPC750 CPU aka G3 */
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750);
|
||||
gMachineObj->add_device("SCSI0", std::unique_ptr<ScsiBus>(new ScsiBus()));
|
||||
|
||||
// post-initialize all devices
|
||||
if (gMachineObj->postinit_devices()) {
|
||||
LOG_F(ERROR, "Could not post-initialize devices!\n");
|
||||
return -1;
|
||||
}
|
||||
// add Athens clock generator device and register it with the I2C host
|
||||
gMachineObj->add_device("Athens", std::unique_ptr<AthensClocks>(new AthensClocks(0x28)));
|
||||
I2CBus* i2c_bus = dynamic_cast<I2CBus*>(gMachineObj->get_comp_by_type(HWCompType::I2C_HOST));
|
||||
i2c_bus->register_device(0x28, dynamic_cast<I2CDevice*>(gMachineObj->get_comp_by_name("Athens")));
|
||||
|
||||
/* check for a floppy image to be inserted into the virtual superdrive */
|
||||
std::string fdd_path = GET_STR_PROP("fdd_img");
|
||||
std::string fd_write_prot = GET_STR_PROP("fdd_wr_prot");
|
||||
if (!fdd_path.empty()) {
|
||||
open_floppy_image(fdd_path);
|
||||
}
|
||||
// create ID EEPROM for the Whisper personality card and register it with the I2C host
|
||||
gMachineObj->add_device("Perch", std::unique_ptr<I2CProm>(new I2CProm(0x53, 256)));
|
||||
I2CProm* perch_id = dynamic_cast<I2CProm*>(gMachineObj->get_comp_by_name("Perch"));
|
||||
perch_id->fill_memory(0, 256, 0);
|
||||
perch_id->fill_memory(32, 223, 0xFF);
|
||||
perch_id->set_memory(0, WhisperID, sizeof(WhisperID));
|
||||
i2c_bus->register_device(0x53, perch_id);
|
||||
|
||||
LOG_F(INFO, "Initialization complete.\n");
|
||||
// configure CPU clocks
|
||||
uint64_t bus_freq = 66820000ULL;
|
||||
uint64_t timebase_freq = bus_freq / 4;
|
||||
|
||||
// initialize virtual CPU and request MPC750 CPU aka G3
|
||||
ppc_cpu_init(grackle_obj, PPC_VER::MPC750, timebase_freq);
|
||||
|
||||
// set CPU PLL ratio to 3.5
|
||||
ppc_state.spr[SPR::HID1] = 0xE << 28;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const PropMap gossamer_settings = {
|
||||
{"rambank1_size",
|
||||
new IntProperty(256, vector<uint32_t>({8, 16, 32, 64, 128, 256}))},
|
||||
{"rambank2_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"rambank3_size",
|
||||
new IntProperty( 0, vector<uint32_t>({0, 8, 16, 32, 64, 128, 256}))},
|
||||
{"emmo",
|
||||
new BinProperty(0)},
|
||||
};
|
||||
|
||||
static vector<string> pmg3_devices = {
|
||||
"Grackle", "Heathrow", "AtiRageGT"
|
||||
};
|
||||
|
||||
static const MachineDescription pmg3dt_descriptor = {
|
||||
.name = "pmg3dt",
|
||||
.description = "Power Macintosh G3 (Beige) Desktop",
|
||||
.devices = pmg3_devices,
|
||||
.settings = gossamer_settings,
|
||||
.init_func = &initialize_gossamer
|
||||
};
|
||||
|
||||
REGISTER_MACHINE(pmg3dt, pmg3dt_descriptor);
|
||||
Loaded 100 of 118 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user