Fix doxgyen comments
[gem5.git] / dev / ide_disk.cc
index 0d825b7233305c71665830cfdb3885f3dc01c1aa..dbb2792e135dabb57a779cac799281b9aff8fa6f 100644 (file)
@@ -35,7 +35,6 @@
 #include <deque>
 #include <string>
 
-#include "arch/alpha/pmap.h"
 #include "base/cprintf.hh" // csprintf
 #include "base/trace.hh"
 #include "dev/disk_image.hh"
 #include "mem/bus/pio_interface_impl.hh"
 #include "sim/builder.hh"
 #include "sim/sim_object.hh"
-#include "sim/universe.hh"
+#include "sim/root.hh"
+#include "targetarch/isa_traits.hh"
 
 using namespace std;
 
 IdeDisk::IdeDisk(const string &name, DiskImage *img, PhysicalMemory *phys,
-                 int id, int delay)
-    : SimObject(name), ctrl(NULL), image(img), physmem(phys),
+                 int id, Tick delay)
+    : SimObject(name), ctrl(NULL), image(img), physmem(phys), diskDelay(delay),
       dmaTransferEvent(this), dmaReadWaitEvent(this),
       dmaWriteWaitEvent(this), dmaPrdReadEvent(this),
       dmaReadEvent(this), dmaWriteEvent(this)
 {
-    // calculate disk delay in microseconds
-    diskDelay = (delay * ticksPerSecond / 100000);
-
-    // initialize the data buffer and shadow registers
-    dataBuffer = new uint8_t[MAX_DMA_SIZE];
-
-    memset(dataBuffer, 0, MAX_DMA_SIZE);
-    memset(&cmdReg, 0, sizeof(CommandReg_t));
-    memset(&curPrd.entry, 0, sizeof(PrdEntry_t));
-
-    dmaInterfaceBytes = 0;
-    curPrdAddr = 0;
-    curSector = 0;
-    curCommand = 0;
-    cmdBytesLeft = 0;
-    drqBytesLeft = 0;
-    dmaRead = false;
-    intrPending = false;
+    // Reset the device state
+    reset(id);
 
     // fill out the drive ID structure
-    memset(&driveID, 0, sizeof(struct hd_driveid));
+    memset(&driveID, 0, sizeof(struct ataparams));
 
     // Calculate LBA and C/H/S values
     uint16_t cylinders;
@@ -108,30 +92,56 @@ IdeDisk::IdeDisk(const string &name, DiskImage *img, PhysicalMemory *phys,
     }
 
     // Setup the model name
-    sprintf((char *)driveID.model, "5MI EDD si k");
+    sprintf((char *)driveID.atap_model, "5MI EDD si k");
     // Set the maximum multisector transfer size
-    driveID.max_multsect = MAX_MULTSECT;
+    driveID.atap_multi = MAX_MULTSECT;
     // IORDY supported, IORDY disabled, LBA enabled, DMA enabled
-    driveID.capability = 0x7;
+    driveID.atap_capabilities1 = 0x7;
     // UDMA support, EIDE support
-    driveID.field_valid = 0x6;
+    driveID.atap_extensions = 0x6;
     // Setup default C/H/S settings
-    driveID.cyls = cylinders;
-    driveID.sectors = sectors;
-    driveID.heads = heads;
+    driveID.atap_cylinders = cylinders;
+    driveID.atap_sectors = sectors;
+    driveID.atap_heads = heads;
     // Setup the current multisector transfer size
-    driveID.multsect = MAX_MULTSECT;
-    driveID.multsect_valid = 0x1;
+    driveID.atap_curmulti = MAX_MULTSECT;
+    driveID.atap_curmulti_valid = 0x1;
     // Number of sectors on disk
-    driveID.lba_capacity = lba_size;
+    driveID.atap_capacity = lba_size;
     // Multiword DMA mode 2 and below supported
-    driveID.dma_mword = 0x400;
+    driveID.atap_dmamode_supp = 0x400;
     // Set PIO mode 4 and 3 supported
-    driveID.eide_pio_modes = 0x3;
+    driveID.atap_piomode_supp = 0x3;
     // Set DMA mode 4 and below supported
-    driveID.dma_ultra = 0x10;
+    driveID.atap_udmamode_supp = 0x10;
     // Statically set hardware config word
-    driveID.hw_config = 0x4001;
+    driveID.atap_hwreset_res = 0x4001;
+}
+
+IdeDisk::~IdeDisk()
+{
+    // destroy the data buffer
+    delete [] dataBuffer;
+}
+
+void
+IdeDisk::reset(int id)
+{
+    // initialize the data buffer and shadow registers
+    dataBuffer = new uint8_t[MAX_DMA_SIZE];
+
+    memset(dataBuffer, 0, MAX_DMA_SIZE);
+    memset(&cmdReg, 0, sizeof(CommandReg_t));
+    memset(&curPrd.entry, 0, sizeof(PrdEntry_t));
+
+    dmaInterfaceBytes = 0;
+    curPrdAddr = 0;
+    curSector = 0;
+    cmdBytes = 0;
+    cmdBytesLeft = 0;
+    drqBytesLeft = 0;
+    dmaRead = false;
+    intrPending = false;
 
     // set the device state to idle
     dmaState = Dma_Idle;
@@ -147,24 +157,24 @@ IdeDisk::IdeDisk(const string &name, DiskImage *img, PhysicalMemory *phys,
     }
 
     // set the device ready bit
-    cmdReg.status |= STATUS_DRDY_BIT;
-}
-
-IdeDisk::~IdeDisk()
-{
-    // destroy the data buffer
-    delete [] dataBuffer;
+    status = STATUS_DRDY_BIT;
 }
 
 ////
 // Utility functions
 ////
 
+bool
+IdeDisk::isDEVSelect()
+{
+    return ctrl->isDiskSelected(this);
+}
+
 Addr
 IdeDisk::pciToDma(Addr pciAddr)
 {
     if (ctrl)
-        return ctrl->tsunami->pchip->translatePciToDma(pciAddr);
+        return ctrl->plat->pciToDma(pciAddr);
     else
         panic("Access to unset controller!\n");
 }
@@ -175,14 +185,14 @@ IdeDisk::bytesInDmaPage(Addr curAddr, uint32_t bytesLeft)
     uint32_t bytesInPage = 0;
 
     // First calculate how many bytes could be in the page
-    if (bytesLeft > ALPHA_PGBYTES)
-        bytesInPage = ALPHA_PGBYTES;
+    if (bytesLeft > TheISA::PageBytes)
+        bytesInPage = TheISA::PageBytes;
     else
         bytesInPage = bytesLeft;
 
     // Next, see if we have crossed a page boundary, and adjust
     Addr upperBound = curAddr + bytesInPage;
-    Addr pageBound = alpha_trunc_page(curAddr) + ALPHA_PGBYTES;
+    Addr pageBound = TheISA::TruncPage(curAddr) + TheISA::PageBytes;
 
     assert(upperBound >= curAddr && "DMA read wraps around address space!\n");
 
@@ -216,6 +226,7 @@ IdeDisk::read(const Addr &offset, bool byte, bool cmdBlk, uint8_t *data)
         // determine if an action needs to be taken on the state machine
         if (offset == STATUS_OFFSET) {
             action = ACT_STAT_READ;
+            *data = status; // status is in a shadow, explicity copy
         } else if (offset == DATA_OFFSET) {
             if (byte)
                 action = ACT_DATA_READ_BYTE;
@@ -230,7 +241,7 @@ IdeDisk::read(const Addr &offset, bool byte, bool cmdBlk, uint8_t *data)
         if (!byte)
             panic("Invalid 16-bit read from control block\n");
 
-        *data = ((uint8_t *)&cmdReg)[STATUS_OFFSET];
+        *data = status;
     }
 
     if (action != ACT_NONE)
@@ -262,6 +273,8 @@ IdeDisk::write(const Addr &offset, bool byte, bool cmdBlk, const uint8_t *data)
                 action = ACT_DATA_WRITE_BYTE;
             else
                 action = ACT_DATA_WRITE_SHORT;
+        } else if (offset == SELECT_OFFSET) {
+            action = ACT_SELECT_WRITE;
         }
 
     } else {
@@ -271,8 +284,13 @@ IdeDisk::write(const Addr &offset, bool byte, bool cmdBlk, const uint8_t *data)
         if (!byte)
             panic("Invalid 16-bit write to control block\n");
 
-        if (*data & CONTROL_RST_BIT)
-            panic("Software reset not supported!\n");
+        if (*data & CONTROL_RST_BIT) {
+            // force the device into the reset state
+            devState = Device_Srst;
+            action = ACT_SRST_SET;
+        } else if (devState == Device_Srst && !(*data & CONTROL_RST_BIT)) {
+            action = ACT_SRST_CLEAR;
+        }
 
         nIENBit = (*data & CONTROL_IEN_BIT) ? true : false;
     }
@@ -315,7 +333,14 @@ IdeDisk::dmaPrdReadDone()
            physmem->dma_addr(curPrdAddr, sizeof(PrdEntry_t)),
            sizeof(PrdEntry_t));
 
-    curPrdAddr += sizeof(PrdEntry_t);
+    DPRINTF(IdeDisk,
+            "PRD: baseAddr:%#x (%#x) byteCount:%d (%d) eot:%#x sector:%d\n",
+            curPrd.getBaseAddr(), pciToDma(curPrd.getBaseAddr()),
+            curPrd.getByteCount(), (cmdBytesLeft/SectorSize),
+            curPrd.getEOT(), curSector);
+
+    // the prd pointer has already been translated, so just do an increment
+    curPrdAddr = curPrdAddr + sizeof(PrdEntry_t);
 
     if (dmaRead)
         doDmaRead();
@@ -326,8 +351,11 @@ IdeDisk::dmaPrdReadDone()
 void
 IdeDisk::doDmaRead()
 {
+    /** @TODO we need to figure out what the delay actually will be */
     Tick totalDiskDelay = diskDelay + (curPrd.getByteCount() / SectorSize);
 
+    DPRINTF(IdeDisk, "doDmaRead, diskDelay: %d totalDiskDelay: %d\n",
+            diskDelay, totalDiskDelay);
     if (dmaInterface) {
         if (dmaInterface->busy()) {
             // reschedule after waiting period
@@ -414,29 +442,8 @@ IdeDisk::dmaReadDone()
         writeDisk(curSector++, (uint8_t *)(dataBuffer + bytesWritten));
     }
 
-#if 0
-    // actually copy the data from memory to data buffer
-    Addr dmaAddr =
-        ctrl->tsunami->pchip->translatePciToDma(curPrd.getBaseAddr());
-    memcpy((void *)dataBuffer,
-           physmem->dma_addr(dmaAddr, curPrd.getByteCount()),
-           curPrd.getByteCount());
-
-    uint32_t bytesWritten = 0;
-
-    while (bytesWritten < curPrd.getByteCount()) {
-        if (cmdBytesLeft <= 0)
-            panic("DMA data is larger than # sectors specified\n");
-
-        writeDisk(curSector++, (uint8_t *)(dataBuffer + bytesWritten));
-
-        bytesWritten += SectorSize;
-        cmdBytesLeft -= SectorSize;
-    }
-#endif
-
     // check for the EOT
-    if (curPrd.getEOT()){
+    if (curPrd.getEOT()) {
         assert(cmdBytesLeft == 0);
         dmaState = Dma_Idle;
         updateState(ACT_DMA_DONE);
@@ -448,8 +455,12 @@ IdeDisk::dmaReadDone()
 void
 IdeDisk::doDmaWrite()
 {
+    /** @TODO we need to figure out what the delay actually will be */
     Tick totalDiskDelay = diskDelay + (curPrd.getByteCount() / SectorSize);
 
+    DPRINTF(IdeDisk, "doDmaWrite, diskDelay: %d totalDiskDelay: %d\n",
+            diskDelay, totalDiskDelay);
+
     if (dmaInterface) {
         if (dmaInterface->busy()) {
             // reschedule after waiting period
@@ -504,7 +515,7 @@ IdeDisk::dmaWriteDone()
 
     // setup the initial page and DMA address
     curAddr = curPrd.getBaseAddr();
-    pageAddr = alpha_trunc_page(curAddr);
+    pageAddr = TheISA::TruncPage(curAddr);
     dmaAddr = pciToDma(curAddr);
 
     // clear out the data buffer
@@ -512,14 +523,14 @@ IdeDisk::dmaWriteDone()
 
     while (bytesRead < curPrd.getByteCount()) {
         // see if we have crossed into a new page
-        if (pageAddr != alpha_trunc_page(curAddr)) {
+        if (pageAddr != TheISA::TruncPage(curAddr)) {
             // write the data to memory
             memcpy(physmem->dma_addr(dmaAddr, bytesInPage),
                    (void *)(dataBuffer + (bytesRead - bytesInPage)),
                    bytesInPage);
 
             // update the DMA address and page address
-            pageAddr = alpha_trunc_page(curAddr);
+            pageAddr = TheISA::TruncPage(curAddr);
             dmaAddr = pciToDma(curAddr);
 
             bytesInPage = 0;
@@ -543,14 +554,6 @@ IdeDisk::dmaWriteDone()
                bytesInPage);
     }
 
-#if 0
-    Addr dmaAddr = ctrl->tsunami->pchip->
-        translatePciToDma(curPrd.getBaseAddr());
-
-    memcpy(physmem->dma_addr(dmaAddr, curPrd.getByteCount()),
-           (void *)dataBuffer, curPrd.getByteCount());
-#endif
-
     // check for the EOT
     if (curPrd.getEOT()) {
         assert(cmdBytesLeft == 0);
@@ -598,7 +601,8 @@ IdeDisk::startDma(const uint32_t &prdTableBase)
     if (devState != Transfer_Data_Dma)
         panic("Inconsistent device state for DMA start!\n");
 
-    curPrdAddr = pciToDma((Addr)prdTableBase);
+    // PRD base address is given by bits 31:2
+    curPrdAddr = pciToDma((Addr)(prdTableBase & ~ULL(0x3)));
 
     dmaState = Dma_Transfer;
 
@@ -610,10 +614,10 @@ void
 IdeDisk::abortDma()
 {
     if (dmaState == Dma_Idle)
-        panic("Inconsistent DMA state, should be in Dma_Start or Dma_Transfer!\n");
+        panic("Inconsistent DMA state, should be Start or Transfer!");
 
     if (devState != Transfer_Data_Dma && devState != Prepare_Data_Dma)
-        panic("Inconsistent device state, should be in Transfer or Prepare!\n");
+        panic("Inconsistent device state, should be Transfer or Prepare!\n");
 
     updateState(ACT_CMD_ERROR);
 }
@@ -625,13 +629,10 @@ IdeDisk::startCommand()
     uint32_t size = 0;
     dmaRead = false;
 
-    // copy the command to the shadow
-    curCommand = cmdReg.command;
-
     // Decode commands
     switch (cmdReg.command) {
         // Supported non-data commands
-      case WIN_READ_NATIVE_MAX:
+      case WDSF_READ_NATIVE_MAX:
         size = image->size() - 1;
         cmdReg.sec_num = (size & 0xff);
         cmdReg.cyl_low = ((size & 0xff00) >> 8);
@@ -642,34 +643,34 @@ IdeDisk::startCommand()
         action = ACT_CMD_COMPLETE;
         break;
 
-      case WIN_RECAL:
-      case WIN_SPECIFY:
-      case WIN_STANDBYNOW1:
-      case WIN_FLUSH_CACHE:
-      case WIN_VERIFY:
-      case WIN_SEEK:
-      case WIN_SETFEATURES:
-      case WIN_SETMULT:
+      case WDCC_RECAL:
+      case WDCC_IDP:
+      case WDCC_STANDBY_IMMED:
+      case WDCC_FLUSHCACHE:
+      case WDSF_VERIFY:
+      case WDSF_SEEK:
+      case SET_FEATURES:
+      case WDCC_SETMULTI:
         devState = Command_Execution;
         action = ACT_CMD_COMPLETE;
         break;
 
         // Supported PIO data-in commands
-      case WIN_IDENTIFY:
-        cmdBytesLeft = sizeof(struct hd_driveid);
+      case WDCC_IDENTIFY:
+        cmdBytes = cmdBytesLeft = sizeof(struct ataparams);
         devState = Prepare_Data_In;
         action = ACT_DATA_READY;
         break;
 
-      case WIN_MULTREAD:
-      case WIN_READ:
+      case WDCC_READMULTI:
+      case WDCC_READ:
         if (!(cmdReg.drive & DRIVE_LBA_BIT))
             panic("Attempt to perform CHS access, only supports LBA\n");
 
         if (cmdReg.sec_count == 0)
-            cmdBytesLeft = (256 * SectorSize);
+            cmdBytes = cmdBytesLeft = (256 * SectorSize);
         else
-            cmdBytesLeft = (cmdReg.sec_count * SectorSize);
+            cmdBytes = cmdBytesLeft = (cmdReg.sec_count * SectorSize);
 
         curSector = getLBABase();
 
@@ -679,15 +680,15 @@ IdeDisk::startCommand()
         break;
 
         // Supported PIO data-out commands
-      case WIN_MULTWRITE:
-      case WIN_WRITE:
+      case WDCC_WRITEMULTI:
+      case WDCC_WRITE:
         if (!(cmdReg.drive & DRIVE_LBA_BIT))
             panic("Attempt to perform CHS access, only supports LBA\n");
 
         if (cmdReg.sec_count == 0)
-            cmdBytesLeft = (256 * SectorSize);
+            cmdBytes = cmdBytesLeft = (256 * SectorSize);
         else
-            cmdBytesLeft = (cmdReg.sec_count * SectorSize);
+            cmdBytes = cmdBytesLeft = (cmdReg.sec_count * SectorSize);
 
         curSector = getLBABase();
 
@@ -696,16 +697,16 @@ IdeDisk::startCommand()
         break;
 
         // Supported DMA commands
-      case WIN_WRITEDMA:
+      case WDCC_WRITEDMA:
         dmaRead = true;  // a write to the disk is a DMA read from memory
-      case WIN_READDMA:
+      case WDCC_READDMA:
         if (!(cmdReg.drive & DRIVE_LBA_BIT))
             panic("Attempt to perform CHS access, only supports LBA\n");
 
         if (cmdReg.sec_count == 0)
-            cmdBytesLeft = (256 * SectorSize);
+            cmdBytes = cmdBytesLeft = (256 * SectorSize);
         else
-            cmdBytesLeft = (cmdReg.sec_count * SectorSize);
+            cmdBytes = cmdBytesLeft = (cmdReg.sec_count * SectorSize);
 
         curSector = getLBABase();
 
@@ -719,9 +720,11 @@ IdeDisk::startCommand()
 
     if (action != ACT_NONE) {
         // set the BSY bit
-        cmdReg.status |= STATUS_BSY_BIT;
+        status |= STATUS_BSY_BIT;
         // clear the DRQ bit
-        cmdReg.status &= ~STATUS_DRQ_BIT;
+        status &= ~STATUS_DRQ_BIT;
+        // clear the DF bit
+        status &= ~STATUS_DF_BIT;
 
         updateState(action);
     }
@@ -734,6 +737,7 @@ IdeDisk::startCommand()
 void
 IdeDisk::intrPost()
 {
+    DPRINTF(IdeDisk, "Posting Interrupt\n");
     if (intrPending)
         panic("Attempt to post an interrupt with one pending\n");
 
@@ -747,6 +751,7 @@ IdeDisk::intrPost()
 void
 IdeDisk::intrClear()
 {
+    DPRINTF(IdeDisk, "Clearing Interrupt\n");
     if (!intrPending)
         panic("Attempt to clear a non-pending interrupt\n");
 
@@ -765,16 +770,30 @@ void
 IdeDisk::updateState(DevAction_t action)
 {
     switch (devState) {
+      case Device_Srst:
+        if (action == ACT_SRST_SET) {
+            // set the BSY bit
+            status |= STATUS_BSY_BIT;
+        } else if (action == ACT_SRST_CLEAR) {
+            // clear the BSY bit
+            status &= ~STATUS_BSY_BIT;
+
+            // reset the device state
+            reset(devID);
+        }
+        break;
+
       case Device_Idle_S:
-        if (!isDEVSelect())
+        if (action == ACT_SELECT_WRITE && !isDEVSelect()) {
             devState = Device_Idle_NS;
-        else if (action == ACT_CMD_WRITE)
+        } else if (action == ACT_CMD_WRITE) {
             startCommand();
+        }
 
         break;
 
       case Device_Idle_SI:
-        if (!isDEVSelect()) {
+        if (action == ACT_SELECT_WRITE && !isDEVSelect()) {
             devState = Device_Idle_NS;
             intrClear();
         } else if (action == ACT_STAT_READ || isIENSet()) {
@@ -788,7 +807,7 @@ IdeDisk::updateState(DevAction_t action)
         break;
 
       case Device_Idle_NS:
-        if (isDEVSelect()) {
+        if (action == ACT_SELECT_WRITE && isDEVSelect()) {
             if (!isIENSet() && intrPending) {
                 devState = Device_Idle_SI;
                 intrPost();
@@ -826,17 +845,17 @@ IdeDisk::updateState(DevAction_t action)
             }
         } else if (action == ACT_DATA_READY) {
             // clear the BSY bit
-            cmdReg.status &= ~STATUS_BSY_BIT;
+            status &= ~STATUS_BSY_BIT;
             // set the DRQ bit
-            cmdReg.status |= STATUS_DRQ_BIT;
+            status |= STATUS_DRQ_BIT;
 
             // copy the data into the data buffer
-            if (curCommand == WIN_IDENTIFY) {
+            if (cmdReg.command == WDCC_IDENTIFY) {
                 // Reset the drqBytes for this block
-                drqBytesLeft = sizeof(struct hd_driveid);
+                drqBytesLeft = sizeof(struct ataparams);
 
                 memcpy((void *)dataBuffer, (void *)&driveID,
-                       sizeof(struct hd_driveid));
+                       sizeof(struct ataparams));
             } else {
                 // Reset the drqBytes for this block
                 drqBytesLeft = SectorSize;
@@ -887,9 +906,9 @@ IdeDisk::updateState(DevAction_t action)
                 } else {
                     devState = Prepare_Data_In;
                     // set the BSY_BIT
-                    cmdReg.status |= STATUS_BSY_BIT;
+                    status |= STATUS_BSY_BIT;
                     // clear the DRQ_BIT
-                    cmdReg.status &= ~STATUS_DRQ_BIT;
+                    status &= ~STATUS_DRQ_BIT;
 
                     /** @todo change this to a scheduled event to simulate
                         disk delay */
@@ -910,20 +929,23 @@ IdeDisk::updateState(DevAction_t action)
             } else {
                 devState = Device_Idle_S;
             }
-        } else if (cmdBytesLeft != 0) {
+        } else if (action == ACT_DATA_READY && cmdBytesLeft != 0) {
             // clear the BSY bit
-            cmdReg.status &= ~STATUS_BSY_BIT;
+            status &= ~STATUS_BSY_BIT;
             // set the DRQ bit
-            cmdReg.status |= STATUS_DRQ_BIT;
+            status |= STATUS_DRQ_BIT;
 
             // clear the data buffer to get it ready for writes
             memset(dataBuffer, 0, MAX_DMA_SIZE);
 
-            if (!isIENSet()) {
+            // reset the drqBytes for this block
+            drqBytesLeft = SectorSize;
+
+            if (cmdBytesLeft == cmdBytes || isIENSet()) {
+                devState = Transfer_Data_Out;
+            } else {
                 devState = Data_Ready_INTRQ_Out;
                 intrPost();
-            } else {
-                devState = Transfer_Data_Out;
             }
         }
         break;
@@ -956,9 +978,11 @@ IdeDisk::updateState(DevAction_t action)
                 writeDisk(curSector++, dataBuffer);
 
                 // set the BSY bit
-                cmdReg.status |= STATUS_BSY_BIT;
+                status |= STATUS_BSY_BIT;
+                // set the seek bit
+                status |= STATUS_SEEK_BIT;
                 // clear the DRQ bit
-                cmdReg.status &= ~STATUS_DRQ_BIT;
+                status &= ~STATUS_DRQ_BIT;
 
                 devState = Prepare_Data_Out;
 
@@ -982,9 +1006,9 @@ IdeDisk::updateState(DevAction_t action)
             }
         } else if (action == ACT_DMA_READY) {
             // clear the BSY bit
-            cmdReg.status &= ~STATUS_BSY_BIT;
+            status &= ~STATUS_BSY_BIT;
             // set the DRQ bit
-            cmdReg.status |= STATUS_DRQ_BIT;
+            status |= STATUS_DRQ_BIT;
 
             devState = Transfer_Data_Dma;
 
@@ -1001,7 +1025,7 @@ IdeDisk::updateState(DevAction_t action)
             // clear the BSY bit
             setComplete();
             // set the seek bit
-            cmdReg.status |= 0x10;
+            status |= STATUS_SEEK_BIT;
             // clear the controller state for DMA transfer
             ctrl->setDmaComplete(this);
 
@@ -1027,26 +1051,41 @@ IdeDisk::serialize(ostream &os)
     Tick reschedule = 0;
     Events_t event = None;
 
+    int eventCount = 0;
+
     if (dmaTransferEvent.scheduled()) {
         reschedule = dmaTransferEvent.when();
         event = Transfer;
-    } else if (dmaReadWaitEvent.scheduled()) {
+        eventCount++;
+    }
+    if (dmaReadWaitEvent.scheduled()) {
         reschedule = dmaReadWaitEvent.when();
         event = ReadWait;
-    } else if (dmaWriteWaitEvent.scheduled()) {
+        eventCount++;
+    }
+    if (dmaWriteWaitEvent.scheduled()) {
         reschedule = dmaWriteWaitEvent.when();
         event = WriteWait;
-    } else if (dmaPrdReadEvent.scheduled()) {
+        eventCount++;
+    }
+    if (dmaPrdReadEvent.scheduled()) {
         reschedule = dmaPrdReadEvent.when();
         event = PrdRead;
-    } else if (dmaReadEvent.scheduled()) {
+        eventCount++;
+    }
+    if (dmaReadEvent.scheduled()) {
         reschedule = dmaReadEvent.when();
         event = DmaRead;
-    } else if (dmaWriteEvent.scheduled()) {
+        eventCount++;
+    }
+    if (dmaWriteEvent.scheduled()) {
         reschedule = dmaWriteEvent.when();
         event = DmaWrite;
+        eventCount++;
     }
 
+    assert(eventCount <= 1);
+
     SERIALIZE_SCALAR(reschedule);
     SERIALIZE_ENUM(event);
 
@@ -1058,7 +1097,8 @@ IdeDisk::serialize(ostream &os)
     SERIALIZE_SCALAR(cmdReg.cyl_low);
     SERIALIZE_SCALAR(cmdReg.cyl_high);
     SERIALIZE_SCALAR(cmdReg.drive);
-    SERIALIZE_SCALAR(cmdReg.status);
+    SERIALIZE_SCALAR(cmdReg.command);
+    SERIALIZE_SCALAR(status);
     SERIALIZE_SCALAR(nIENBit);
     SERIALIZE_SCALAR(devID);
 
@@ -1070,9 +1110,9 @@ IdeDisk::serialize(ostream &os)
 
     // Serialize current transfer related information
     SERIALIZE_SCALAR(cmdBytesLeft);
+    SERIALIZE_SCALAR(cmdBytes);
     SERIALIZE_SCALAR(drqBytesLeft);
     SERIALIZE_SCALAR(curSector);
-    SERIALIZE_SCALAR(curCommand);
     SERIALIZE_SCALAR(dmaRead);
     SERIALIZE_SCALAR(dmaInterfaceBytes);
     SERIALIZE_SCALAR(intrPending);
@@ -1110,7 +1150,8 @@ IdeDisk::unserialize(Checkpoint *cp, const string &section)
     UNSERIALIZE_SCALAR(cmdReg.cyl_low);
     UNSERIALIZE_SCALAR(cmdReg.cyl_high);
     UNSERIALIZE_SCALAR(cmdReg.drive);
-    UNSERIALIZE_SCALAR(cmdReg.status);
+    UNSERIALIZE_SCALAR(cmdReg.command);
+    UNSERIALIZE_SCALAR(status);
     UNSERIALIZE_SCALAR(nIENBit);
     UNSERIALIZE_SCALAR(devID);
 
@@ -1121,10 +1162,10 @@ IdeDisk::unserialize(Checkpoint *cp, const string &section)
     UNSERIALIZE_SCALAR(curPrdAddr);
 
     // Unserialize current transfer related information
+    UNSERIALIZE_SCALAR(cmdBytes);
     UNSERIALIZE_SCALAR(cmdBytesLeft);
     UNSERIALIZE_SCALAR(drqBytesLeft);
     UNSERIALIZE_SCALAR(curSector);
-    UNSERIALIZE_SCALAR(curCommand);
     UNSERIALIZE_SCALAR(dmaRead);
     UNSERIALIZE_SCALAR(dmaInterfaceBytes);
     UNSERIALIZE_SCALAR(intrPending);
@@ -1135,12 +1176,14 @@ IdeDisk::unserialize(Checkpoint *cp, const string &section)
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 
+enum DriveID { master, slave };
+static const char *DriveID_strings[] = { "master", "slave" };
 BEGIN_DECLARE_SIM_OBJECT_PARAMS(IdeDisk)
 
     SimObjectParam<DiskImage *> image;
     SimObjectParam<PhysicalMemory *> physmem;
-    Param<int> driveID;
-    Param<int> disk_delay;
+    SimpleEnumParam<DriveID> driveID;
+    Param<int> delay;
 
 END_DECLARE_SIM_OBJECT_PARAMS(IdeDisk)
 
@@ -1148,16 +1191,15 @@ BEGIN_INIT_SIM_OBJECT_PARAMS(IdeDisk)
 
     INIT_PARAM(image, "Disk image"),
     INIT_PARAM(physmem, "Physical memory"),
-    INIT_PARAM(driveID, "Drive ID (0=master 1=slave)"),
-    INIT_PARAM_DFLT(disk_delay, "Fixed disk delay in microseconds", 1)
+    INIT_ENUM_PARAM(driveID, "Drive ID (0=master 1=slave)", DriveID_strings),
+    INIT_PARAM_DFLT(delay, "Fixed disk delay in microseconds", 1)
 
 END_INIT_SIM_OBJECT_PARAMS(IdeDisk)
 
 
 CREATE_SIM_OBJECT(IdeDisk)
 {
-    return new IdeDisk(getInstanceName(), image, physmem, driveID,
-                       disk_delay);
+    return new IdeDisk(getInstanceName(), image, physmem, driveID, delay);
 }
 
 REGISTER_SIM_OBJECT("IdeDisk", IdeDisk)