Skip to content

Commit

Permalink
Add MODE_SENSE_6 to ATAPI CD-ROM emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
dingusdev committed Nov 24, 2024
1 parent b3f2a6c commit f6dc704
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions devices/common/ata/atadefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ enum ATA_Cmd : uint8_t {
NOP = 0x00,
ATAPI_SOFT_RESET = 0x08,
RECALIBRATE = 0x10,
ATAPI_COMMAND_MODE_SENSE6 = 0x1A,
READ_SECTOR = 0x20,
READ_SECTOR_NR = 0x21,
READ_LONG = 0x22,
Expand All @@ -128,13 +129,15 @@ enum ATA_Cmd : uint8_t {
WRITE_SECTOR_NR = 0x31,
WRITE_LONG = 0x32,
READ_VERIFY = 0x40,
ATAPI_COMMAND_GET_CONFIG = 0x46,
FORMAT_TRACKS = 0x50,
IDE_SEEK = 0x70,
DIAGNOSTICS = 0x90,
INIT_DEV_PARAM = 0x91,
ATAPI_PACKET = 0xA0,
ATAPI_IDFY_DEV = 0xA1,
ATAPI_SERVICE = 0xA2,
ATAPI_READ_DVD_STRUCTURE = 0xAD,
READ_MULTIPLE = 0xC4,
WRITE_MULTIPLE = 0xC5,
SET_MULTIPLE_MODE = 0xC6,
Expand Down
13 changes: 12 additions & 1 deletion devices/common/ata/atapicdrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,19 @@ void AtapiCdrom::perform_packet_command() {
this->data_out_phase();
}
break;
case ScsiCommand::MODE_SENSE_6:
this->xfer_cnt = this->mode_sense_ex(true, this->cmd_pkt, this->data_buf);
if (!this->xfer_cnt) {
this->present_status();
} else {
this->r_byte_count = this->xfer_cnt;
this->data_ptr = (uint16_t*)this->data_buf;
this->status_good();
this->data_out_phase();
}
break;
case ScsiCommand::MODE_SENSE_10:
this->xfer_cnt = this->mode_sense_ex(this->cmd_pkt, this->data_buf);
this->xfer_cnt = this->mode_sense_ex(false, this->cmd_pkt, this->data_buf);
if (!this->xfer_cnt) {
this->present_status();
} else {
Expand Down
14 changes: 12 additions & 2 deletions devices/storage/cdromdrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ uint32_t CdromDrive::inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr) {
return 36;
}

uint32_t CdromDrive::mode_sense_ex(uint8_t *cmd_ptr, uint8_t *data_ptr) {
uint32_t CdromDrive::mode_sense_ex(bool is_sense_6, uint8_t* cmd_ptr, uint8_t* data_ptr) {
uint8_t *resp_ptr;

uint8_t page_code = cmd_ptr[2] & 0x3F;
uint8_t alloc_len = READ_WORD_BE_U(&cmd_ptr[7]);
uint8_t alloc_len = is_sense_6 ? READ_WORD_BE_U(&cmd_ptr[4]) : READ_WORD_BE_U(&cmd_ptr[7]);

std::memset(data_ptr, 0, alloc_len);

Expand Down Expand Up @@ -137,7 +137,17 @@ uint32_t CdromDrive::mode_sense_ex(uint8_t *cmd_ptr, uint8_t *data_ptr) {
WRITE_WORD_BE_A(&resp_ptr[14], 706); // report current speed (4x)
data_ptr[1] += 20; // adjust overall length
break;
case 0x31:
resp_ptr[1] = 14; // page data length
std::memset(&resp_ptr[2], 0, 14);
resp_ptr[8] = 0x31;
resp_ptr[9] = 6;
resp_ptr[10] = '.';
resp_ptr[11] = 'A';
resp_ptr[12] = 'p';
resp_ptr[13] = 'p';
default:
LOG_F(ERROR, "ATAPI CD-ROM: Invalid Page Code 0x%x", page_code);
this->set_error(ScsiSense::ILLEGAL_REQ, ScsiError::INVALID_CDB);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion devices/storage/cdromdrive.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CdromDrive : public BlockStorageDevice {
void insert_image(std::string filename);

virtual uint32_t inquiry(uint8_t *cmd_ptr, uint8_t *data_ptr);
virtual uint32_t mode_sense_ex(uint8_t *cmd_ptr, uint8_t *data_ptr);
virtual uint32_t mode_sense_ex(bool is_sense_6, uint8_t *cmd_ptr, uint8_t *data_ptr);
virtual uint32_t request_sense(uint8_t *data_ptr, uint8_t sense_key, uint8_t asc,
uint8_t ascq);
virtual uint32_t report_capacity(uint8_t *data_ptr);
Expand Down

0 comments on commit f6dc704

Please sign in to comment.