Changeset 43474 in vbox for trunk/src/VBox
- Timestamp:
- Sep 30, 2012 11:31:15 AM (12 years ago)
- Location:
- trunk/src/VBox/Devices/Storage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/VBoxSCSI.cpp
r40676 r43474 98 98 case 1: 99 99 { 100 if (pVBoxSCSI->cbBuf > 0) 100 /* If we're not in the 'command ready' state, there may not even be a buffer yet. */ 101 if ((pVBoxSCSI->enmState == VBOXSCSISTATE_COMMAND_READY) && pVBoxSCSI->cbBuf > 0) 101 102 { 102 103 AssertMsg(pVBoxSCSI->pBuf, ("pBuf is NULL\n")); 104 Assert(pVBoxSCSI->enmState == VBOXSCSISTATE_COMMAND_READY); 105 Assert(!pVBoxSCSI->fBusy); 103 106 uVal = pVBoxSCSI->pBuf[pVBoxSCSI->iBuf]; 104 107 pVBoxSCSI->iBuf++; … … 163 166 else 164 167 { 165 pVBoxSCSI->enmState = VBOXSCSISTATE_READ_CDB_SIZE ;168 pVBoxSCSI->enmState = VBOXSCSISTATE_READ_CDB_SIZE_BUFHI; 166 169 pVBoxSCSI->uTxDir = uVal; 167 170 } 168 171 } 169 else if (pVBoxSCSI->enmState == VBOXSCSISTATE_READ_CDB_SIZE) 170 { 171 if (uVal > VBOXSCSI_CDB_SIZE_MAX) 172 else if (pVBoxSCSI->enmState == VBOXSCSISTATE_READ_CDB_SIZE_BUFHI) 173 { 174 uint8_t cbCDB = uVal & 0x0F; 175 176 if (cbCDB > VBOXSCSI_CDB_SIZE_MAX) 172 177 vboxscsiReset(pVBoxSCSI); 173 178 else 174 179 { 175 pVBoxSCSI->enmState = VBOXSCSISTATE_READ_BUFFER_SIZE_LOW; 176 pVBoxSCSI->cbCDB = uVal; 180 pVBoxSCSI->enmState = VBOXSCSISTATE_READ_BUFFER_SIZE_LSB; 181 pVBoxSCSI->cbCDB = cbCDB; 182 pVBoxSCSI->cbBuf = (uVal & 0xF0) << 12; /* Bits 16-19 of buffer size. */ 177 183 } 178 184 } 179 else if (pVBoxSCSI->enmState == VBOXSCSISTATE_READ_BUFFER_SIZE_L OW)180 { 181 pVBoxSCSI->enmState = VBOXSCSISTATE_READ_BUFFER_SIZE_ HIGH;182 pVBoxSCSI->cbBuf = uVal;183 } 184 else if (pVBoxSCSI->enmState == VBOXSCSISTATE_READ_BUFFER_SIZE_ HIGH)185 else if (pVBoxSCSI->enmState == VBOXSCSISTATE_READ_BUFFER_SIZE_LSB) 186 { 187 pVBoxSCSI->enmState = VBOXSCSISTATE_READ_BUFFER_SIZE_MID; 188 pVBoxSCSI->cbBuf |= uVal; /* Bits 0-7 of buffer size. */ 189 } 190 else if (pVBoxSCSI->enmState == VBOXSCSISTATE_READ_BUFFER_SIZE_MID) 185 191 { 186 192 pVBoxSCSI->enmState = VBOXSCSISTATE_READ_COMMAND; 187 pVBoxSCSI->cbBuf |= (((uint16_t)uVal) << 8); 193 pVBoxSCSI->cbBuf |= (((uint16_t)uVal) << 8); /* Bits 8-15 of buffer size. */ 188 194 } 189 195 else if (pVBoxSCSI->enmState == VBOXSCSISTATE_READ_COMMAND) … … 351 357 return VINF_SUCCESS; 352 358 353 int rc = PGMPhysSimpleDirtyWriteGCPtr(PDMDevHlpGetVMCPU(pDevIns), GCDst, pVBoxSCSI->pBuf, cbTransfer); 359 /* Also ignore attempts to read more data than is available. */ 360 Assert(cbTransfer <= pVBoxSCSI->cbBuf); 361 if (cbTransfer > pVBoxSCSI->cbBuf) 362 cbTransfer = pVBoxSCSI->cbBuf; /* Ignore excess data (not supposed to happen). */ 363 364 int rc = PGMPhysSimpleDirtyWriteGCPtr(PDMDevHlpGetVMCPU(pDevIns), GCDst, pVBoxSCSI->pBuf + pVBoxSCSI->iBuf, cbTransfer); 354 365 AssertRC(rc); 355 366 … … 357 368 *pcTransfer = 0; 358 369 359 RTMemFree(pVBoxSCSI->pBuf); 360 pVBoxSCSI->pBuf = NULL; 361 pVBoxSCSI->cbBuf = 0; 362 pVBoxSCSI->cbCDB = 0; 363 pVBoxSCSI->iCDB = 0; 364 pVBoxSCSI->iBuf = 0; 365 pVBoxSCSI->uTargetDevice = 0; 366 pVBoxSCSI->enmState = VBOXSCSISTATE_NO_COMMAND; 367 memset(pVBoxSCSI->aCDB, 0, sizeof(pVBoxSCSI->aCDB)); 370 /* Advance current buffer position. */ 371 pVBoxSCSI->iBuf += cbTransfer; 372 pVBoxSCSI->cbBuf -= cbTransfer; 373 374 if (pVBoxSCSI->cbBuf == 0) 375 { 376 /** The guest read the last byte from the data in buffer. 377 * Clear everything and reset command buffer. 378 */ 379 RTMemFree(pVBoxSCSI->pBuf); 380 pVBoxSCSI->pBuf = NULL; 381 pVBoxSCSI->cbCDB = 0; 382 pVBoxSCSI->iCDB = 0; 383 pVBoxSCSI->iBuf = 0; 384 pVBoxSCSI->uTargetDevice = 0; 385 pVBoxSCSI->enmState = VBOXSCSISTATE_NO_COMMAND; 386 memset(pVBoxSCSI->aCDB, 0, sizeof(pVBoxSCSI->aCDB)); 387 } 368 388 369 389 return rc; … … 383 403 return VINF_SUCCESS; 384 404 385 Assert(cbTransfer == pVBoxSCSI->cbBuf);405 Assert(cbTransfer <= pVBoxSCSI->cbBuf); 386 406 if (cbTransfer > pVBoxSCSI->cbBuf) 387 407 cbTransfer = pVBoxSCSI->cbBuf; /* Ignore excess data (not supposed to happen). */ 388 408 389 int rc = PDMDevHlpPhysReadGCVirt(pDevIns, pVBoxSCSI->pBuf , GCSrc, cbTransfer);409 int rc = PDMDevHlpPhysReadGCVirt(pDevIns, pVBoxSCSI->pBuf + pVBoxSCSI->iBuf, GCSrc, cbTransfer); 390 410 AssertRC(rc); 411 412 /* Advance current buffer position. */ 413 pVBoxSCSI->iBuf += cbTransfer; 414 pVBoxSCSI->cbBuf -= cbTransfer; 391 415 392 416 *pGCPtrSrc = (RTGCPTR)((RTGCUINTPTR)GCSrc + cbTransfer); … … 409 433 } 410 434 } 411 -
trunk/src/VBox/Devices/Storage/VBoxSCSI.h
r35346 r43474 71 71 VBOXSCSISTATE_NO_COMMAND = 0x00, 72 72 VBOXSCSISTATE_READ_TXDIR = 0x01, 73 VBOXSCSISTATE_READ_CDB_SIZE 74 VBOXSCSISTATE_READ_BUFFER_SIZE_L OW= 0x03,75 VBOXSCSISTATE_READ_BUFFER_SIZE_ HIGH= 0x04,73 VBOXSCSISTATE_READ_CDB_SIZE_BUFHI = 0x02, 74 VBOXSCSISTATE_READ_BUFFER_SIZE_LSB = 0x03, 75 VBOXSCSISTATE_READ_BUFFER_SIZE_MID = 0x04, 76 76 VBOXSCSISTATE_READ_COMMAND = 0x05, 77 77 VBOXSCSISTATE_COMMAND_READY = 0x06
Note:
See TracChangeset
for help on using the changeset viewer.