From 65a343ce5c80d660e606d0aa6fcdb057a85d623d Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Mon, 4 Dec 2023 22:41:01 +0100 Subject: [PATCH] Clean up names for SCSI devices. --- devices/common/ata/atapicdrom.cpp | 2 +- devices/common/scsi/sc53c94.cpp | 43 +++++++++++++++++-------------- devices/common/scsi/scsi.h | 4 ++- devices/common/scsi/scsicdrom.cpp | 31 +++++++++++----------- devices/common/scsi/scsicdrom.h | 6 ++--- devices/common/scsi/scsihd.cpp | 29 +++++++++++---------- devices/common/scsi/scsihd.h | 6 ++--- devices/storage/cdromdrive.h | 3 +-- 8 files changed, 65 insertions(+), 59 deletions(-) diff --git a/devices/common/ata/atapicdrom.cpp b/devices/common/ata/atapicdrom.cpp index 0adcc09..aee9a7f 100644 --- a/devices/common/ata/atapicdrom.cpp +++ b/devices/common/ata/atapicdrom.cpp @@ -34,7 +34,7 @@ along with this program. If not, see . using namespace ata_interface; -AtapiCdrom::AtapiCdrom(std::string name) : AtapiBaseDevice(name) { +AtapiCdrom::AtapiCdrom(std::string name) : CdromDrive(), AtapiBaseDevice(name) { this->set_error_callback( [this](uint8_t sense_key, uint8_t asc) { this->status_error(sense_key, asc); diff --git a/devices/common/scsi/sc53c94.cpp b/devices/common/scsi/sc53c94.cpp index 0b3d474..03ed619 100644 --- a/devices/common/scsi/sc53c94.cpp +++ b/devices/common/scsi/sc53c94.cpp @@ -33,7 +33,7 @@ along with this program. If not, see . #include #include -Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice(my_id) +Sc53C94::Sc53C94(uint8_t chip_id, uint8_t my_id) : ScsiDevice("SC53C94", my_id) { this->chip_id = chip_id; this->my_bus_id = my_id; @@ -110,7 +110,7 @@ uint8_t Sc53C94::read(uint8_t reg_offset) } break; default: - LOG_F(INFO, "SC53C94: reading from register %d", reg_offset); + LOG_F(INFO, "%s: reading from register %d", this->name.c_str(), reg_offset); } return 0; } @@ -144,7 +144,7 @@ void Sc53C94::write(uint8_t reg_offset, uint8_t value) break; case Write::Reg53C94::Config_1: if ((value & 7) != this->my_bus_id) { - ABORT_F("SC53C94: HBA bus ID mismatch!"); + ABORT_F("%s: HBA bus ID mismatch!", this->name.c_str()); } this->config1 = value; break; @@ -155,7 +155,8 @@ void Sc53C94::write(uint8_t reg_offset, uint8_t value) this->config3 = value; break; default: - LOG_F(INFO, "SC53C94: writing 0x%X to %d register", value, reg_offset); + LOG_F(INFO, "%s: writing 0x%X to %d register", this->name.c_str(), value, + reg_offset); } } @@ -208,7 +209,7 @@ void Sc53C94::pseudo_dma_write(uint16_t data) { void Sc53C94::update_command_reg(uint8_t cmd) { if (this->on_reset && (cmd & 0x7F) != CMD_NOP) { - LOG_F(WARNING, "SC53C94: command register blocked after RESET!"); + LOG_F(WARNING, "%s: command register blocked after RESET!", this->name.c_str()); return; } @@ -228,7 +229,7 @@ void Sc53C94::update_command_reg(uint8_t cmd) exec_command(); } } else { - LOG_F(ERROR, "SC53C94: the top of the command FIFO overwritten!"); + LOG_F(ERROR, "%s: the top of the command FIFO overwritten!", this->name.c_str()); this->status |= STAT_GE; // signal IOE/Gross Error } } @@ -268,7 +269,7 @@ void Sc53C94::exec_command() this->on_reset = true; // block the command register return; case CMD_RESET_BUS: - LOG_F(INFO, "SC53C94: resetting SCSI bus..."); + LOG_F(INFO, "%s: resetting SCSI bus...", this->name.c_str()); // assert RST line this->bus_obj->assert_ctrl_line(this->my_bus_id, SCSI_CTRL_RST); // release RST line after 25 us @@ -278,7 +279,7 @@ void Sc53C94::exec_command() this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_RST); }); if (!(config1 & 0x40)) { - LOG_F(INFO, "SC53C94: reset interrupt issued"); + LOG_F(INFO, "%s: reset interrupt issued", this->name.c_str()); this->int_status |= INTSTAT_SRST; } exec_next_command(); @@ -303,7 +304,7 @@ void Sc53C94::exec_command() {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"); + ABORT_F("%s: complete steps only works in the STATUS phase", this->name.c_str()); } this->seq_step = 0; this->cmd_steps = complete_steps_desc; @@ -330,7 +331,7 @@ void Sc53C94::exec_command() this->cmd_steps = sel_no_atn_desc; this->cur_state = SeqState::BUS_FREE; this->sequencer(); - LOG_F(9, "SC53C94: SELECT W/O ATN command started"); + LOG_F(9, "%s: SELECT W/O ATN command started", this->name.c_str()); break; case CMD_SELECT_WITH_ATN: static SeqDesc * sel_with_atn_desc = new SeqDesc[4]{ @@ -344,13 +345,13 @@ void Sc53C94::exec_command() this->cmd_steps = sel_with_atn_desc; this->cur_state = SeqState::BUS_FREE; this->sequencer(); - LOG_F(9, "SC53C94: SELECT WITH ATN command started"); + LOG_F(9, "%s: SELECT WITH ATN command started", this->name.c_str()); break; case CMD_ENA_SEL_RESEL: exec_next_command(); break; default: - LOG_F(ERROR, "SC53C94: invalid/unimplemented command 0x%X", cmd); + LOG_F(ERROR, "%s: invalid/unimplemented command 0x%X", this->name.c_str(), cmd); this->cmd_fifo_pos--; // remove invalid command from FIFO this->int_status |= INTSTAT_ICMD; this->update_irq(); @@ -373,7 +374,7 @@ void Sc53C94::fifo_push(const uint8_t data) if (this->data_fifo_pos < DATA_FIFO_MAX) { this->data_fifo[this->data_fifo_pos++] = data; } else { - LOG_F(ERROR, "SC53C94: data FIFO overflow!"); + LOG_F(ERROR, "%s: data FIFO overflow!", this->name.c_str()); this->status |= STAT_GE; // signal IOE/Gross Error } } @@ -383,7 +384,7 @@ uint8_t Sc53C94::fifo_pop() uint8_t data = 0; if (this->data_fifo_pos < 1) { - LOG_F(ERROR, "SC53C94: data FIFO underflow!"); + LOG_F(ERROR, "%s: data FIFO underflow!", this->name.c_str()); this->status |= STAT_GE; // signal IOE/Gross Error } else { data = this->data_fifo[0]; @@ -421,7 +422,7 @@ void Sc53C94::sequencer() break; case SeqState::ARB_BEGIN: if (!this->bus_obj->begin_arbitration(this->my_bus_id)) { - LOG_F(ERROR, "SC53C94: arbitration error, bus not free!"); + LOG_F(ERROR, "%s: arbitration error, bus not free!", this->name.c_str()); this->bus_obj->release_ctrl_lines(this->my_bus_id); this->next_state = SeqState::BUS_FREE; this->seq_defer_state(BUS_CLEAR_DELAY); @@ -435,7 +436,7 @@ void Sc53C94::sequencer() this->next_state = this->cmd_steps->next_step; this->seq_defer_state(BUS_CLEAR_DELAY + BUS_SETTLE_DELAY); } else { // arbitration lost - LOG_F(INFO, "SC53C94: arbitration lost!"); + LOG_F(INFO, "%s: arbitration lost!", this->name.c_str()); this->bus_obj->release_ctrl_lines(this->my_bus_id); this->next_state = SeqState::BUS_FREE; this->seq_defer_state(BUS_CLEAR_DELAY); @@ -451,7 +452,7 @@ void Sc53C94::sequencer() case SeqState::SEL_END: if (this->bus_obj->end_selection(this->my_bus_id, this->target_id)) { this->bus_obj->release_ctrl_line(this->my_bus_id, SCSI_CTRL_SEL); - LOG_F(9, "SC53C94: selection completed"); + LOG_F(9, "%s: selection completed", this->name.c_str()); } else { // selection timeout this->seq_step = this->cmd_steps->step_num; this->int_status |= this->cmd_steps->status; @@ -545,7 +546,7 @@ void Sc53C94::sequencer() } break; default: - ABORT_F("SC53C94: unimplemented sequencer state %d", this->cur_state); + ABORT_F("%s: unimplemented sequencer state %d", this->name.c_str(), this->cur_state); } } @@ -569,7 +570,8 @@ void Sc53C94::notify(ScsiMsg msg_type, int param) this->cur_state = SeqState::SEL_END; this->sequencer(); } else { - LOG_F(WARNING, "SC53C94: ignore invalid selection confirmation message"); + LOG_F(WARNING, "%s: ignore invalid selection confirmation message", + this->name.c_str()); } break; case ScsiMsg::BUS_PHASE_CHANGE: @@ -581,7 +583,8 @@ void Sc53C94::notify(ScsiMsg msg_type, int param) } break; default: - LOG_F(9, "SC53C94: ignore notification message, type: %d", msg_type); + LOG_F(9, "%s: ignore notification message, type: %d", this->name.c_str(), + msg_type); } } diff --git a/devices/common/scsi/scsi.h b/devices/common/scsi/scsi.h index f05794d..84219ae 100644 --- a/devices/common/scsi/scsi.h +++ b/devices/common/scsi/scsi.h @@ -164,7 +164,9 @@ typedef std::function action_callback; class ScsiDevice : public HWComponent { public: - ScsiDevice(int my_id) { + ScsiDevice(std::string name, int my_id) { + this->set_name(name); + supports_types(HWCompType::SCSI_DEV); this->scsi_id = my_id; this->cur_phase = ScsiPhase::BUS_FREE; }; diff --git a/devices/common/scsi/scsicdrom.cpp b/devices/common/scsi/scsicdrom.cpp index 6b29dd2..d7ce0b5 100644 --- a/devices/common/scsi/scsicdrom.cpp +++ b/devices/common/scsi/scsicdrom.cpp @@ -1,6 +1,6 @@ /* DingusPPC - The Experimental PowerPC Macintosh emulator -Copyright (C) 2018-22 divingkatae and maximum +Copyright (C) 2018-23 divingkatae and maximum (theweirdo) spatium (Contact divingkatae#1017 or powermax#2286 on Discord for more info) @@ -37,9 +37,9 @@ 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) +ScsiCdrom::ScsiCdrom(std::string name, int my_id) : ScsiDevice(name, my_id) { - supports_types(HWCompType::SCSI_DEV); + //supports_types(HWCompType::SCSI_DEV); this->sector_size = 2048; @@ -50,7 +50,7 @@ ScsiCdrom::ScsiCdrom(int my_id) : ScsiDevice(my_id) void ScsiCdrom::insert_image(std::string filename) { if (!this->cdr_img.open(filename)) { - ABORT_F("SCSI-CDROM: could not open image file"); + ABORT_F("%s: could not open image file", this->name.c_str()); } this->img_size = this->cdr_img.size(); @@ -104,7 +104,7 @@ void ScsiCdrom::process_command() 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"); + ABORT_F("%s: RelAdr bit set in READ_10", this->name.c_str()); } read(lba, xfer_len, 10); break; @@ -112,7 +112,7 @@ void ScsiCdrom::process_command() this->read_toc(); break; default: - ABORT_F("SCSI_CDROM: unsupported command %d", this->cmd_buf[0]); + ABORT_F("%s: unsupported command %d", this->name.c_str(), this->cmd_buf[0]); } } @@ -130,7 +130,7 @@ bool ScsiCdrom::prepare_data() case ScsiPhase::STATUS: break; default: - LOG_F(WARNING, "SCSI_CDROM: unexpected phase in prepare_data"); + LOG_F(WARNING, "%s: unexpected phase in prepare_data", this->name.c_str()); return false; } return true; @@ -163,11 +163,11 @@ void ScsiCdrom::inquiry() int alloc_len = cmd_buf[4]; if (page_num) { - ABORT_F("SCSI_CDROM: invalid page number in INQUIRY"); + ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str()); } if (alloc_len > 36) { - LOG_F(WARNING, "SCSI_CDROM: more than 36 bytes requested in INQUIRY"); + LOG_F(WARNING, "%s: more than 36 bytes requested in INQUIRY", this->name.c_str()); } this->data_buf[0] = 5; // device type: CD-ROM @@ -225,7 +225,7 @@ void ScsiCdrom::mode_sense() this->data_buf[0] += 23; break; default: - ABORT_F("SCSI-HD: unsupported page %d in MODE_SENSE_6", page_code); + ABORT_F("%s: unsupported page %d in MODE_SENSE_6", this->name.c_str(), page_code); } this->bytes_out = this->data_buf[0]; @@ -242,11 +242,11 @@ void ScsiCdrom::read_toc() bool is_msf = !!(this->cmd_buf[1] & 2); if (this->cmd_buf[2] & 0xF) { - ABORT_F("SCSI-CDROM: unsupported format in READ_TOC"); + ABORT_F("%s: unsupported format in READ_TOC", this->name.c_str()); } if (!alloc_len) { - LOG_F(WARNING, "SCSI-CDROM: zero allocation length passed to READ_TOC"); + LOG_F(WARNING, "%s: zero allocation length passed to READ_TOC", this->name.c_str()); return; } @@ -260,7 +260,8 @@ void ScsiCdrom::read_toc() } 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); + LOG_F(ERROR, "%s: invalid starting track %d in READ_TOC", this->name.c_str(), + start_track); this->status = ScsiStatus::CHECK_CONDITION; this->sense = ScsiSense::ILLEGAL_REQ; this->switch_phase(ScsiPhase::STATUS); @@ -313,11 +314,11 @@ 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"); + ABORT_F("%s: RelAdr bit set in READ_CAPACITY_10", this->name.c_str()); } if (!(this->cmd_buf[8] & 1) && lba) { - LOG_F(ERROR, "SCSI-CDROM: non-zero LBA for PMI=0"); + LOG_F(ERROR, "%s: non-zero LBA for PMI=0", this->name.c_str()); this->status = ScsiStatus::CHECK_CONDITION; this->sense = ScsiSense::ILLEGAL_REQ; this->switch_phase(ScsiPhase::STATUS); diff --git a/devices/common/scsi/scsicdrom.h b/devices/common/scsi/scsicdrom.h index 0859617..8dc387b 100644 --- a/devices/common/scsi/scsicdrom.h +++ b/devices/common/scsi/scsicdrom.h @@ -1,6 +1,6 @@ /* DingusPPC - The Experimental PowerPC Macintosh emulator -Copyright (C) 2018-22 divingkatae and maximum +Copyright (C) 2018-23 divingkatae and maximum (theweirdo) spatium (Contact divingkatae#1017 or powermax#2286 on Discord for more info) @@ -51,11 +51,11 @@ typedef struct { class ScsiCdrom : public ScsiDevice { public: - ScsiCdrom(int my_id); + ScsiCdrom(std::string name, int my_id); ~ScsiCdrom() = default; static std::unique_ptr create() { - return std::unique_ptr(new ScsiCdrom(3)); + return std::unique_ptr(new ScsiCdrom("SCSI-CDROM", 3)); } void insert_image(std::string filename); diff --git a/devices/common/scsi/scsihd.cpp b/devices/common/scsi/scsihd.cpp index 3e81e5a..66fe329 100644 --- a/devices/common/scsi/scsihd.cpp +++ b/devices/common/scsi/scsihd.cpp @@ -36,15 +36,14 @@ along with this program. If not, see . using namespace std; -ScsiHardDisk::ScsiHardDisk(int my_id) : ScsiDevice(my_id) { - supports_types(HWCompType::SCSI_DEV); +ScsiHardDisk::ScsiHardDisk(std::string, int my_id) : ScsiDevice(name, my_id) { } 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. if (!this->hdd_img.open(filename)) - ABORT_F("SCSI-HD: could not open image file %s", filename.c_str()); + ABORT_F("%s: could not open image file %s", this->name.c_str(), filename.c_str()); this->img_size = this->hdd_img.size(); this->total_blocks = (this->img_size + HDD_SECTOR_SIZE - 1) / HDD_SECTOR_SIZE; @@ -122,7 +121,7 @@ void ScsiHardDisk::process_command() { read_buffer(); break; default: - LOG_F(WARNING, "SCSI-HD: unrecognized command: %x", cmd[0]); + LOG_F(WARNING, "%s: unrecognized command: %x", this->name.c_str(), cmd[0]); } } @@ -149,7 +148,7 @@ bool ScsiHardDisk::prepare_data() { this->data_size = 1; break; default: - LOG_F(WARNING, "SCSI-HD: unexpected phase in prepare_data"); + LOG_F(WARNING, "%s: unexpected phase in prepare_data", this->name.c_str()); return false; } @@ -163,7 +162,8 @@ int ScsiHardDisk::test_unit_ready() { int ScsiHardDisk::req_sense(uint16_t alloc_len) { if (alloc_len != 252) { - LOG_F(WARNING, "Inappropriate Allocation Length: %d", alloc_len); + LOG_F(WARNING, "%s: inappropriate Allocation Length: %d", this->name.c_str(), + alloc_len); } return ScsiError::NO_ERROR; // placeholder - no sense } @@ -173,7 +173,7 @@ void ScsiHardDisk::inquiry() { int alloc_len = cmd_buf[4]; if (page_num) { - ABORT_F("SCSI-HD: invalid page number in INQUIRY"); + ABORT_F("%s: invalid page number in INQUIRY", this->name.c_str()); } if (alloc_len >= 36) { @@ -194,7 +194,8 @@ void ScsiHardDisk::inquiry() { this->switch_phase(ScsiPhase::DATA_IN); } else { - LOG_F(WARNING, "Allocation length too small: %d", alloc_len); + LOG_F(WARNING, "%s: allocation length too small: %d", this->name.c_str(), + alloc_len); } } @@ -265,7 +266,7 @@ void ScsiHardDisk::mode_sense_6() { std::memcpy(&this->img_buffer[14], Apple_Copyright_Page_Data, 22); break; default: - ABORT_F("SCSI-HD: unsupported page %d in MODE_SENSE_6", page_code); + ABORT_F("%s: unsupported page %d in MODE_SENSE_6", this->name.c_str(), page_code); }; // adjust for overall mode sense data length @@ -280,11 +281,11 @@ 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"); + ABORT_F("%s: RelAdr bit set in READ_CAPACITY_10", this->name.c_str()); } if (!(this->cmd_buf[8] & 1) && lba) { - LOG_F(ERROR, "SCSI-HD: non-zero LBA for PMI=0"); + LOG_F(ERROR, "%s: non-zero LBA for PMI=0", this->name.c_str()); this->status = ScsiStatus::CHECK_CONDITION; this->sense = ScsiSense::ILLEGAL_REQ; this->switch_phase(ScsiPhase::STATUS); @@ -304,10 +305,10 @@ void ScsiHardDisk::read_capacity_10() { void ScsiHardDisk::format() { - LOG_F(WARNING, "SCSI-HD: attempt to format the disk!"); + LOG_F(WARNING, "%s: attempt to format the disk!", this->name.c_str()); if (this->cmd_buf[1] & 0x10) - ABORT_F("SCSI-HD: defect list isn't supported yet"); + ABORT_F("%s: defect list isn't supported yet", this->name.c_str()); TimerManager::get_instance()->add_oneshot_timer(NS_PER_SEC, [this]() { this->switch_phase(ScsiPhase::STATUS); @@ -368,7 +369,7 @@ void ScsiHardDisk::read_buffer() { WRITE_DWORD_BE_A(&this->img_buffer[0], 0x10000); // report buffer size of 64K break; default: - ABORT_F("SCSI-HD: unsupported mode %d in READ_BUFFER", mode); + ABORT_F("%s: unsupported mode %d in READ_BUFFER", this->name.c_str(), mode); } this->bytes_out = alloc_len; diff --git a/devices/common/scsi/scsihd.h b/devices/common/scsi/scsihd.h index df05ed3..680f656 100644 --- a/devices/common/scsi/scsihd.h +++ b/devices/common/scsi/scsihd.h @@ -1,6 +1,6 @@ /* DingusPPC - The Experimental PowerPC Macintosh emulator -Copyright (C) 2018-22 divingkatae and maximum +Copyright (C) 2018-23 divingkatae and maximum (theweirdo) spatium (Contact divingkatae#1017 or powermax#2286 on Discord for more info) @@ -33,11 +33,11 @@ along with this program. If not, see . class ScsiHardDisk : public ScsiDevice { public: - ScsiHardDisk(int my_id); + ScsiHardDisk(std::string name, int my_id); ~ScsiHardDisk() = default; static std::unique_ptr create() { - return std::unique_ptr(new ScsiHardDisk(0)); + return std::unique_ptr(new ScsiHardDisk("SCSI_HD", 0)); } void insert_image(std::string filename); diff --git a/devices/storage/cdromdrive.h b/devices/storage/cdromdrive.h index b5f59ad..f60dbeb 100644 --- a/devices/storage/cdromdrive.h +++ b/devices/storage/cdromdrive.h @@ -67,10 +67,9 @@ public: uint32_t report_capacity(uint8_t *data_ptr); uint32_t read_toc(uint8_t *cmd_ptr, uint8_t *data_ptr); - AddrMsf lba_to_msf(const int lba); - protected: std::function set_error; + AddrMsf lba_to_msf(const int lba); TrackDescriptor tracks[CDROM_MAX_TRACKS]; int num_tracks;