fdc: Use phase in fdctrl_write_data()

Instead of relying on a flag in the MSR to distinguish controller phases,
use the explicit phase that we store now. Assertions of the right MSR
flags are added.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Message-id: 1432214378-31891-5-git-send-email-kwolf@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>
This commit is contained in:
Kevin Wolf 2015-05-21 15:19:34 +02:00 committed by John Snow
parent 85d291a08c
commit 5b0a25e8d2

View File

@ -2059,8 +2059,12 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
return; return;
} }
fdctrl->dsr &= ~FD_DSR_PWRDOWN; fdctrl->dsr &= ~FD_DSR_PWRDOWN;
/* Is it write command time ? */
if (fdctrl->msr & FD_MSR_NONDMA) { switch (fdctrl->phase) {
case FD_PHASE_EXECUTION:
/* For DMA requests, RQM should be cleared during execution phase, so
* we would have errored out above. */
assert(fdctrl->msr & FD_MSR_NONDMA);
/* FIFO data write */ /* FIFO data write */
pos = fdctrl->data_pos++; pos = fdctrl->data_pos++;
pos %= FD_SECTOR_LEN; pos %= FD_SECTOR_LEN;
@ -2072,12 +2076,12 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
< 0) { < 0) {
FLOPPY_DPRINTF("error writing sector %d\n", FLOPPY_DPRINTF("error writing sector %d\n",
fd_sector(cur_drv)); fd_sector(cur_drv));
return; break;
} }
if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) { if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
FLOPPY_DPRINTF("error seeking to next sector %d\n", FLOPPY_DPRINTF("error seeking to next sector %d\n",
fd_sector(cur_drv)); fd_sector(cur_drv));
return; break;
} }
} }
/* Switch from transfer mode to status mode /* Switch from transfer mode to status mode
@ -2085,33 +2089,42 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
*/ */
if (fdctrl->data_pos == fdctrl->data_len) if (fdctrl->data_pos == fdctrl->data_len)
fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00); fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
return; break;
}
if (fdctrl->data_pos == 0) {
/* Command */
pos = command_to_handler[value & 0xff];
FLOPPY_DPRINTF("%s command\n", handlers[pos].name);
fdctrl->data_len = handlers[pos].parameters + 1;
fdctrl->msr |= FD_MSR_CMDBUSY;
}
FLOPPY_DPRINTF("%s: %02x\n", __func__, value); case FD_PHASE_COMMAND:
pos = fdctrl->data_pos++; assert(!(fdctrl->msr & FD_MSR_NONDMA));
pos %= FD_SECTOR_LEN;
fdctrl->fifo[pos] = value; if (fdctrl->data_pos == 0) {
if (fdctrl->data_pos == fdctrl->data_len) { /* Command */
/* We now have all parameters pos = command_to_handler[value & 0xff];
* and will be able to treat the command FLOPPY_DPRINTF("%s command\n", handlers[pos].name);
*/ fdctrl->data_len = handlers[pos].parameters + 1;
fdctrl->phase = FD_PHASE_EXECUTION; fdctrl->msr |= FD_MSR_CMDBUSY;
if (fdctrl->data_state & FD_STATE_FORMAT) {
fdctrl_format_sector(fdctrl);
return;
} }
pos = command_to_handler[fdctrl->fifo[0] & 0xff]; FLOPPY_DPRINTF("%s: %02x\n", __func__, value);
FLOPPY_DPRINTF("treat %s command\n", handlers[pos].name); pos = fdctrl->data_pos++;
(*handlers[pos].handler)(fdctrl, handlers[pos].direction); pos %= FD_SECTOR_LEN;
fdctrl->fifo[pos] = value;
if (fdctrl->data_pos == fdctrl->data_len) {
/* We now have all parameters
* and will be able to treat the command
*/
fdctrl->phase = FD_PHASE_EXECUTION;
if (fdctrl->data_state & FD_STATE_FORMAT) {
fdctrl_format_sector(fdctrl);
break;
}
pos = command_to_handler[fdctrl->fifo[0] & 0xff];
FLOPPY_DPRINTF("treat %s command\n", handlers[pos].name);
(*handlers[pos].handler)(fdctrl, handlers[pos].direction);
}
break;
case FD_PHASE_RESULT:
default:
abort();
} }
} }