nscsi: use chd idnt metadata for inquiry

Also use logmacro.h logging.
This commit is contained in:
Patrick Mackinlay 2017-12-20 08:45:09 +07:00
parent ac0083d4e0
commit 09a8ca238e
3 changed files with 87 additions and 72 deletions

View File

@ -3,6 +3,15 @@
#include "emu.h" #include "emu.h"
#include "nscsi_bus.h" #include "nscsi_bus.h"
#define LOG_GENERAL (1U << 0)
#define LOG_STATE (1U << 1)
#define LOG_CONTROL (1U << 2)
//#define VERBOSE (LOG_GENERAL | LOG_STATE | LOG_CONTROL)
#define VERBOSE (LOG_GENERAL)
#include "logmacro.h"
DEFINE_DEVICE_TYPE(NSCSI_BUS, nscsi_bus_device, "nscsi_bus", "SCSI Bus (new)") DEFINE_DEVICE_TYPE(NSCSI_BUS, nscsi_bus_device, "nscsi_bus", "SCSI Bus (new)")
DEFINE_DEVICE_TYPE(NSCSI_CONNECTOR, nscsi_connector, "nscsi_connector", "SCSI Connector Abstraction (new)") DEFINE_DEVICE_TYPE(NSCSI_CONNECTOR, nscsi_connector, "nscsi_connector", "SCSI Connector Abstraction (new)")
@ -49,9 +58,8 @@ void nscsi_bus_device::regen_ctrl(int refid)
for(int i=0; i<devcnt; i++) for(int i=0; i<devcnt; i++)
ctrl |= dev[i].ctrl; ctrl |= dev[i].ctrl;
if(0) { if(VERBOSE & LOG_CONTROL) {
logerror("%s: ctrl %c%c%c%c%c%c%c%c%c %s %04x -", LOGMASKED(LOG_CONTROL, "ctrl %c%c%c%c%c%c%c%c%c %s %04x\n",
tag(),
ctrl & nscsi_device::S_RST ? 'R' : '.', ctrl & nscsi_device::S_RST ? 'R' : '.',
ctrl & nscsi_device::S_ATN ? 'A' : '.', ctrl & nscsi_device::S_ATN ? 'A' : '.',
ctrl & nscsi_device::S_ACK ? 'K' : '.', ctrl & nscsi_device::S_ACK ? 'K' : '.',
@ -65,8 +73,7 @@ void nscsi_bus_device::regen_ctrl(int refid)
data); data);
for(int i=0; i<devcnt; i++) for(int i=0; i<devcnt; i++)
if(dev[i].ctrl) { if(dev[i].ctrl) {
logerror(" %d=", i); LOGMASKED(LOG_CONTROL, "%d=%s%s%s%s%s%s%s%s%s\n", i,
logerror("%s%s%s%s%s%s%s%s%s",
dev[i].ctrl & nscsi_device::S_RST ? "R" : "", dev[i].ctrl & nscsi_device::S_RST ? "R" : "",
dev[i].ctrl & nscsi_device::S_ATN ? "A" : "", dev[i].ctrl & nscsi_device::S_ATN ? "A" : "",
dev[i].ctrl & nscsi_device::S_ACK ? "K" : "", dev[i].ctrl & nscsi_device::S_ACK ? "K" : "",
@ -77,7 +84,6 @@ void nscsi_bus_device::regen_ctrl(int refid)
dev[i].ctrl & nscsi_device::S_SEL ? "S" : "", dev[i].ctrl & nscsi_device::S_SEL ? "S" : "",
dev[i].ctrl & nscsi_device::S_BSY ? "B" : ""); dev[i].ctrl & nscsi_device::S_BSY ? "B" : "");
} }
logerror("\n");
} }
octrl = octrl ^ ctrl; octrl = octrl ^ ctrl;
@ -265,14 +271,13 @@ void nscsi_full_device::step(bool timeout)
scsi_bus->data_w(scsi_refid, 0); scsi_bus->data_w(scsi_refid, 0);
scsi_bus->ctrl_w(scsi_refid, 0, S_ALL); scsi_bus->ctrl_w(scsi_refid, 0, S_ALL);
scsi_state = IDLE; scsi_state = IDLE;
logerror("%s: scsi bus reset\n", tag()); LOG("scsi bus reset\n");
return; return;
} }
if(0) LOGMASKED(LOG_STATE, "state=%d.%d %s\n",
logerror("%s: state=%d.%d %s\n", scsi_state & STATE_MASK, (scsi_state & SUB_MASK) >> SUB_SHIFT,
tag(), scsi_state & STATE_MASK, (scsi_state & SUB_MASK) >> SUB_SHIFT, timeout ? "timeout" : "change");
timeout ? "timeout" : "change");
switch(scsi_state & SUB_MASK ? scsi_state & SUB_MASK : scsi_state & STATE_MASK) { switch(scsi_state & SUB_MASK ? scsi_state & SUB_MASK : scsi_state & STATE_MASK) {
case IDLE: case IDLE:
@ -417,7 +422,7 @@ void nscsi_full_device::step(bool timeout)
if(ctrl & S_SEL) if(ctrl & S_SEL)
return; return;
if(ctrl & S_ATN) { if(ctrl & S_ATN) {
logerror("%s: Parity error? Say what?\n", tag()); LOG("Parity error? Say what?\n");
scsi_state = IDLE; scsi_state = IDLE;
break; break;
} }
@ -433,9 +438,8 @@ void nscsi_full_device::step(bool timeout)
break; break;
default: default:
logerror("%s: step() unexpected state %d.%d\n", LOG("step() unexpected state %d.%d\n",
tag(), scsi_state & STATE_MASK, (scsi_state & SUB_MASK) >> SUB_SHIFT);
scsi_state & STATE_MASK, (scsi_state & SUB_MASK) >> SUB_SHIFT);
exit(0); exit(0);
} }
} }
@ -568,7 +572,7 @@ void nscsi_full_device::sense(bool deferred, uint8_t key)
void nscsi_full_device::scsi_unknown_command() void nscsi_full_device::scsi_unknown_command()
{ {
logerror("%s: Unhandled command %s", tag(), command_names[scsi_cmdbuf[0]]); LOG("Unhandled command %s", command_names[scsi_cmdbuf[0]]);
for(int i=0; i != scsi_cmdsize; i++) for(int i=0; i != scsi_cmdsize; i++)
logerror(" %02x", scsi_cmdbuf[i]); logerror(" %02x", scsi_cmdbuf[i]);
logerror("\n"); logerror("\n");
@ -581,7 +585,7 @@ void nscsi_full_device::scsi_command()
{ {
switch(scsi_cmdbuf[0]) { switch(scsi_cmdbuf[0]) {
case SC_REQUEST_SENSE: case SC_REQUEST_SENSE:
logerror("%s: command REQUEST SENSE\n", tag()); LOG("command REQUEST SENSE\n");
scsi_data_in(SBUF_SENSE, 8); scsi_data_in(SBUF_SENSE, 8);
scsi_status_complete(SS_GOOD); scsi_status_complete(SS_GOOD);
break; break;
@ -598,7 +602,7 @@ void nscsi_full_device::scsi_message()
return; return;
} }
logerror("%s: Unknown message", tag()); LOG("Unknown message");
for(int i=0; i != scsi_cmdsize; i++) for(int i=0; i != scsi_cmdsize; i++)
logerror(" %02x", scsi_cmdbuf[i]); logerror(" %02x", scsi_cmdbuf[i]);
logerror("\n"); logerror("\n");

View File

@ -4,6 +4,13 @@
#include "machine/nscsi_hd.h" #include "machine/nscsi_hd.h"
#include "imagedev/harddriv.h" #include "imagedev/harddriv.h"
#define LOG_GENERAL (1U << 0)
#define LOG_COMMAND (1U << 1)
#define VERBOSE (LOG_GENERAL)
#include "logmacro.h"
DEFINE_DEVICE_TYPE(NSCSI_HARDDISK, nscsi_harddisk_device, "scsi_harddisk", "SCSI Hard Disk") DEFINE_DEVICE_TYPE(NSCSI_HARDDISK, nscsi_harddisk_device, "scsi_harddisk", "SCSI Hard Disk")
nscsi_harddisk_device::nscsi_harddisk_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : nscsi_harddisk_device::nscsi_harddisk_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
@ -37,6 +44,10 @@ void nscsi_harddisk_device::device_reset()
} else { } else {
const hard_disk_info *hdinfo = hard_disk_get_info(harddisk); const hard_disk_info *hdinfo = hard_disk_get_info(harddisk);
bytes_per_sector = hdinfo->sectorbytes; bytes_per_sector = hdinfo->sectorbytes;
chd_file *chd = hd->get_chd_file();
if (chd != nullptr)
chd->read_metadata(HARD_DISK_IDENT_METADATA_TAG, 0, m_inquiry_data);
} }
cur_lba = -1; cur_lba = -1;
} }
@ -55,7 +66,7 @@ uint8_t nscsi_harddisk_device::scsi_get_data(int id, int pos)
if(clba != cur_lba) { if(clba != cur_lba) {
cur_lba = clba; cur_lba = clba;
if(!hard_disk_read(harddisk, cur_lba, block)) { if(!hard_disk_read(harddisk, cur_lba, block)) {
logerror("%s: HD READ ERROR !\n", tag()); LOG("HD READ ERROR !\n");
memset(block, 0, sizeof(block)); memset(block, 0, sizeof(block));
} }
} }
@ -74,27 +85,23 @@ void nscsi_harddisk_device::scsi_put_data(int id, int pos, uint8_t data)
int clba = lba + pos / bytes_per_sector; int clba = lba + pos / bytes_per_sector;
if(offset == bytes_per_sector-1) { if(offset == bytes_per_sector-1) {
if(!hard_disk_write(harddisk, clba, block)) if(!hard_disk_write(harddisk, clba, block))
logerror("%s: HD WRITE ERROR !\n", tag()); LOG("HD WRITE ERROR !\n");
} }
} }
void nscsi_harddisk_device::scsi_command() void nscsi_harddisk_device::scsi_command()
{ {
#if 0
if (scsi_cmdbuf[0] != SC_READ) if ((VERBOSE & LOG_COMMAND) && scsi_cmdbuf[0] != SC_READ_6)
{ {
logerror("%s: ", tag()); LOGMASKED(LOG_COMMAND, "%02x %02x %02x %02x %02x %02x\n",
for (int i = 0; i < 6; i++) scsi_cmdbuf[0], scsi_cmdbuf[1], scsi_cmdbuf[2],
{ scsi_cmdbuf[3], scsi_cmdbuf[4], scsi_cmdbuf[5]);
logerror("%02x ", scsi_cmdbuf[i]);
}
logerror("\n");
} }
#endif
switch(scsi_cmdbuf[0]) { switch(scsi_cmdbuf[0]) {
case SC_TEST_UNIT_READY: case SC_TEST_UNIT_READY:
logerror("%s: command TEST UNIT READY\n", tag()); LOG("command TEST UNIT READY\n");
scsi_status_complete(SS_GOOD); scsi_status_complete(SS_GOOD);
break; break;
@ -104,8 +111,7 @@ void nscsi_harddisk_device::scsi_command()
if(!blocks) if(!blocks)
blocks = 256; blocks = 256;
logerror("%s: command READ start=%08x blocks=%04x\n", LOG("command READ start=%08x blocks=%04x\n", lba, blocks);
tag(), lba, blocks);
scsi_data_in(2, blocks*bytes_per_sector); scsi_data_in(2, blocks*bytes_per_sector);
scsi_status_complete(SS_GOOD); scsi_status_complete(SS_GOOD);
@ -117,8 +123,7 @@ void nscsi_harddisk_device::scsi_command()
if(!blocks) if(!blocks)
blocks = 256; blocks = 256;
logerror("%s: command WRITE start=%08x blocks=%04x\n", LOG("command WRITE start=%08x blocks=%04x\n", lba, blocks);
tag(), lba, blocks);
scsi_data_out(2, blocks*bytes_per_sector); scsi_data_out(2, blocks*bytes_per_sector);
scsi_status_complete(SS_GOOD); scsi_status_complete(SS_GOOD);
@ -126,9 +131,8 @@ void nscsi_harddisk_device::scsi_command()
case SC_INQUIRY: { case SC_INQUIRY: {
int lun = get_lun(scsi_cmdbuf[1] >> 5); int lun = get_lun(scsi_cmdbuf[1] >> 5);
logerror("%s: command INQUIRY lun=%d EVPD=%d page=%d alloc=%02x link=%02x\n", LOG("command INQUIRY lun=%d EVPD=%d page=%d alloc=%02x link=%02x\n",
tag(), lun, scsi_cmdbuf[1] & 1, scsi_cmdbuf[2], scsi_cmdbuf[4], scsi_cmdbuf[5]);
lun, scsi_cmdbuf[1] & 1, scsi_cmdbuf[2], scsi_cmdbuf[4], scsi_cmdbuf[5]);
int page = scsi_cmdbuf[2]; int page = scsi_cmdbuf[2];
int size = scsi_cmdbuf[4]; int size = scsi_cmdbuf[4];
@ -146,30 +150,38 @@ void nscsi_harddisk_device::scsi_command()
scsi_cmdbuf[1] = 0x00; // media is not removable scsi_cmdbuf[1] = 0x00; // media is not removable
scsi_cmdbuf[2] = 0x05; // device complies with SPC-3 standard scsi_cmdbuf[2] = 0x05; // device complies with SPC-3 standard
scsi_cmdbuf[3] = 0x01; // response data format = CCS scsi_cmdbuf[3] = 0x01; // response data format = CCS
// Apple HD SC setup utility needs to see this if (m_inquiry_data.empty())
strcpy((char *)&scsi_cmdbuf[8], " SEAGATE"); {
strcpy((char *)&scsi_cmdbuf[15], " ST225N"); LOG("IDNT tag not found in chd metadata, using default inquiry data\n");
strcpy((char *)&scsi_cmdbuf[31], "1.00");
scsi_cmdbuf[36] = 0x00; // # of extents high // Apple HD SC setup utility needs to see this
scsi_cmdbuf[37] = 0x08; // # of extents low strcpy((char *)&scsi_cmdbuf[8], " SEAGATE");
scsi_cmdbuf[38] = 0x00; // group 0 commands 0-1f strcpy((char *)&scsi_cmdbuf[15], " ST225N");
scsi_cmdbuf[39] = 0x99; // commands 0,3,4,7 strcpy((char *)&scsi_cmdbuf[31], "1.00");
scsi_cmdbuf[40] = 0xa0; // commands 8, a scsi_cmdbuf[36] = 0x00; // # of extents high
scsi_cmdbuf[41] = 0x27; // commands 12,15,16,17 scsi_cmdbuf[37] = 0x08; // # of extents low
scsi_cmdbuf[42] = 0x34; // commands 1a,1b,1d scsi_cmdbuf[38] = 0x00; // group 0 commands 0-1f
scsi_cmdbuf[43] = 0x01; // group 1 commands 20-3f scsi_cmdbuf[39] = 0x99; // commands 0,3,4,7
scsi_cmdbuf[44] = 0x04; scsi_cmdbuf[40] = 0xa0; // commands 8, a
scsi_cmdbuf[45] = 0xa0; scsi_cmdbuf[41] = 0x27; // commands 12,15,16,17
scsi_cmdbuf[46] = 0x01; scsi_cmdbuf[42] = 0x34; // commands 1a,1b,1d
scsi_cmdbuf[47] = 0x18; scsi_cmdbuf[43] = 0x01; // group 1 commands 20-3f
scsi_cmdbuf[48] = 0x07; // group 7 commands e0-ff scsi_cmdbuf[44] = 0x04;
scsi_cmdbuf[49] = 0x00; scsi_cmdbuf[45] = 0xa0;
scsi_cmdbuf[50] = 0xa0; // commands 8, a scsi_cmdbuf[46] = 0x01;
scsi_cmdbuf[51] = 0x00; scsi_cmdbuf[47] = 0x18;
scsi_cmdbuf[52] = 0x00; scsi_cmdbuf[48] = 0x07; // group 7 commands e0-ff
scsi_cmdbuf[53] = 0xff; // end of list scsi_cmdbuf[49] = 0x00;
if(size > 54) scsi_cmdbuf[50] = 0xa0; // commands 8, a
size = 54; scsi_cmdbuf[51] = 0x00;
scsi_cmdbuf[52] = 0x00;
scsi_cmdbuf[53] = 0xff; // end of list
}
else
std::copy_n(m_inquiry_data.begin(), std::min(m_inquiry_data.size(), size_t(48)), &scsi_cmdbuf[8]);
if(size > 56)
size = 56;
scsi_data_in(0, size); scsi_data_in(0, size);
break; break;
} }
@ -179,9 +191,8 @@ void nscsi_harddisk_device::scsi_command()
case SC_MODE_SENSE_6: { case SC_MODE_SENSE_6: {
int lun = get_lun(scsi_cmdbuf[1] >> 5); int lun = get_lun(scsi_cmdbuf[1] >> 5);
logerror("%s: command MODE SENSE 6 lun=%d page=%02x alloc=%02x link=%02x\n", LOG("command MODE SENSE 6 lun=%d page=%02x alloc=%02x link=%02x\n",
tag(), lun, scsi_cmdbuf[2] & 0x3f, scsi_cmdbuf[4], scsi_cmdbuf[5]);
lun, scsi_cmdbuf[2] & 0x3f, scsi_cmdbuf[4], scsi_cmdbuf[5]);
if(lun) { if(lun) {
bad_lun(); bad_lun();
return; return;
@ -301,7 +312,7 @@ void nscsi_harddisk_device::scsi_command()
} }
default: default:
logerror("%s: mode sense page %02x unhandled\n", tag(), page); LOG("mode sense page %02x unhandled\n", page);
break; break;
} }
} }
@ -315,12 +326,12 @@ void nscsi_harddisk_device::scsi_command()
} }
case SC_START_STOP_UNIT: case SC_START_STOP_UNIT:
logerror("%s: command START STOP UNIT\n", tag()); LOG("command START STOP UNIT\n");
scsi_status_complete(SS_GOOD); scsi_status_complete(SS_GOOD);
break; break;
case SC_READ_CAPACITY: { case SC_READ_CAPACITY: {
logerror("%s: command READ CAPACITY\n", tag()); LOG("command READ CAPACITY\n");
hard_disk_info *info = hard_disk_get_info(harddisk); hard_disk_info *info = hard_disk_get_info(harddisk);
uint32_t size = info->cylinders * info->heads * info->sectors - 1; uint32_t size = info->cylinders * info->heads * info->sectors - 1;
@ -343,8 +354,7 @@ void nscsi_harddisk_device::scsi_command()
lba = (scsi_cmdbuf[2]<<24) | (scsi_cmdbuf[3]<<16) | (scsi_cmdbuf[4]<<8) | scsi_cmdbuf[5]; lba = (scsi_cmdbuf[2]<<24) | (scsi_cmdbuf[3]<<16) | (scsi_cmdbuf[4]<<8) | scsi_cmdbuf[5];
blocks = (scsi_cmdbuf[7] << 8) | scsi_cmdbuf[8]; blocks = (scsi_cmdbuf[7] << 8) | scsi_cmdbuf[8];
logerror("%s: command READ EXTENDED start=%08x blocks=%04x\n", LOG("command READ EXTENDED start=%08x blocks=%04x\n",lba, blocks);
tag(), lba, blocks);
scsi_data_in(2, blocks*bytes_per_sector); scsi_data_in(2, blocks*bytes_per_sector);
scsi_status_complete(SS_GOOD); scsi_status_complete(SS_GOOD);
@ -354,15 +364,14 @@ void nscsi_harddisk_device::scsi_command()
lba = (scsi_cmdbuf[2]<<24) | (scsi_cmdbuf[3]<<16) | (scsi_cmdbuf[4]<<8) | scsi_cmdbuf[5]; lba = (scsi_cmdbuf[2]<<24) | (scsi_cmdbuf[3]<<16) | (scsi_cmdbuf[4]<<8) | scsi_cmdbuf[5];
blocks = (scsi_cmdbuf[7] << 8) | scsi_cmdbuf[8]; blocks = (scsi_cmdbuf[7] << 8) | scsi_cmdbuf[8];
logerror("%s: command WRITE EXTENDED start=%08x blocks=%04x\n", LOG("command WRITE EXTENDED start=%08x blocks=%04x\n", lba, blocks);
tag(), lba, blocks);
scsi_data_out(2, blocks*bytes_per_sector); scsi_data_out(2, blocks*bytes_per_sector);
scsi_status_complete(SS_GOOD); scsi_status_complete(SS_GOOD);
break; break;
default: default:
logerror("%s: command %02x ***UNKNOWN***\n", tag(), scsi_cmdbuf[0]); LOG("command %02x ***UNKNOWN***\n", scsi_cmdbuf[0]);
nscsi_full_device::scsi_command(); nscsi_full_device::scsi_command();
break; break;
} }

View File

@ -28,6 +28,8 @@ protected:
hard_disk_file *harddisk; hard_disk_file *harddisk;
int lba, cur_lba, blocks; int lba, cur_lba, blocks;
int bytes_per_sector; int bytes_per_sector;
std::vector<u8> m_inquiry_data;
}; };
DECLARE_DEVICE_TYPE(NSCSI_HARDDISK, nscsi_harddisk_device) DECLARE_DEVICE_TYPE(NSCSI_HARDDISK, nscsi_harddisk_device)