Skip to content

Commit 290d8d3

Browse files
atapibasedevice: fix packets for Rhapsody.
ATAPI devices use 12-byte packets by default. Support for bigger packets is indicated in the first word of the IDENTIFY ATAPI DEVICE response. Installers for Rhapsody/Mac OS X Server 1.x send 16-byte packets instead ignoring the device packet length. This fix will reject extraneous packet bytes so the Rhapsody installers will work as they do in the real hardware.
1 parent 265615e commit 290d8d3

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

devices/common/ata/atapibasedevice.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
6262
if (this->data_available()) {
6363
this->r_status &= ~DRQ;
6464
this->r_status |= BSY;
65-
this->update_intrq(1); // Is this going to work here? The interrupt happens before returning ret_data.
65+
// Is this going to work here?
66+
// The interrupt happens before returning ret_data.
67+
this->update_intrq(1);
6668
}
6769
else if (this->status_expected) {
6870
this->present_status();
@@ -102,13 +104,22 @@ uint16_t AtapiBaseDevice::read(const uint8_t reg_addr) {
102104
void AtapiBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
103105
switch (reg_addr) {
104106
case ATA_Reg::DATA:
105-
if (has_data()) {
106-
*this->data_ptr++ = BYTESWAP_16(value);
107-
this->xfer_cnt -= 2;
108-
if (this->xfer_cnt <= 0) {
109-
this->r_status &= ~DRQ;
110-
if (this->r_int_reason & CoD) {
111-
this->perform_packet_command();
107+
if (!(this->r_int_reason & ATAPI_Int_Reason::IO)) { // host --> device?
108+
if (this->r_int_reason & ATAPI_Int_Reason::CoD) { // command phase?
109+
if (this->xfer_cnt > 0) {
110+
*this->data_ptr++ = BYTESWAP_16(value);
111+
this->xfer_cnt -= 2;
112+
if (this->xfer_cnt <= 0) {
113+
this->r_status &= ~DRQ;
114+
this->perform_packet_command();
115+
}
116+
}
117+
} else { // data-out phase
118+
if (this->xfer_cnt > 0) {
119+
*this->data_ptr++ = BYTESWAP_16(value);
120+
this->xfer_cnt -= 2;
121+
if (this->xfer_cnt <= 0)
122+
this->r_status &= ~DRQ;
112123
}
113124
}
114125
}

0 commit comments

Comments
 (0)