VirtualBox

Changeset 82177 in vbox


Ignore:
Timestamp:
Nov 25, 2019 1:54:41 PM (5 years ago)
Author:
vboxsync
Message:

DevFdc: Saved state fixes (cannot just save two extra timers w/o loading them and bumping the version). Also, we don't call CFGMR3Xxxx directly any more.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DevFdc.cpp

    r82152 r82177  
    5656#include "VBoxDD.h"
    5757
    58 #define FDC_SAVESTATE_CURRENT   2       /* The new and improved saved state. */
    59 #define FDC_SAVESTATE_OLD       1       /* The original saved state. */
     58
     59/*********************************************************************************************************************************
     60*   Defined Constants And Macros                                                                                                 *
     61*********************************************************************************************************************************/
     62/** @name FDC saved state versions
     63 * @{ */
     64#define FDC_SAVESTATE_CURRENT   2       /**< Current version. */
     65#define FDC_SAVESTATE_PRE_DELAY 2       /**< Pre IRQDelay. */
     66#define FDC_SAVESTATE_OLD       1       /**< The original saved state. */
     67/** @}*/
    6068
    6169#define MAX_FD 2
     
    22782286static DECLCALLBACK(void) fdcTransferDelayTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    22792287{
    2280     RT_NOREF(pDevIns, pTimer);
    2281     fdctrl_t *fdctrl = (fdctrl_t *)pvUser;
     2288    fdctrl_t *fdctrl = PDMDEVINS_2_DATA(pDevIns, fdctrl_t *);
     2289    RT_NOREF(pvUser, pTimer);
    22822290    fdctrl_stop_transfer_now(fdctrl, fdctrl->st0, fdctrl->st1, fdctrl->st2);
    22832291}
     2292
    22842293
    22852294/**
     
    22882297static DECLCALLBACK(void) fdcIrqDelayTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
    22892298{
    2290     RT_NOREF(pDevIns, pTimer);
    2291     fdctrl_t *fdctrl = (fdctrl_t *)pvUser;
     2299    fdctrl_t *fdctrl = PDMDEVINS_2_DATA(pDevIns, fdctrl_t *);
     2300    RT_NOREF(pvUser, pTimer);
    22922301    fdctrl_raise_irq_now(fdctrl, fdctrl->st0);
    22932302}
     
    24042413    }
    24052414    rc = pHlp->pfnTimerSave(pDevIns, pThis->hXferDelayTimer, pSSM);
    2406     if (RT_FAILURE(rc))
    2407         return rc;
    2408 
     2415    AssertRCReturn(rc, rc);
    24092416    rc = pHlp->pfnTimerSave(pDevIns, pThis->hIrqDelayTimer, pSSM);
    2410     if (RT_FAILURE(rc))
    2411         return rc;
    2412 
     2417    AssertRCReturn(rc, rc);
    24132418    return pHlp->pfnTimerSave(pDevIns, pThis->hResultTimer, pSSM);
    24142419}
     
    24312436    Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
    24322437
    2433     /* The old saved state was significantly different. However, we can get
    2434      * back most of the controller state and fix the rest by pretending the
    2435      * disk in the drive (if any) has been replaced. At any rate there should
    2436      * be no difficulty unless the state was saved during a floppy operation.
    2437      */
    2438     if (uVersion == FDC_SAVESTATE_OLD)
     2438    if (uVersion > FDC_SAVESTATE_OLD)
    24392439    {
     2440        /* Load the FDC I/O registers... */
     2441        pHlp->pfnSSMGetU8(pSSM, &pThis->sra);
     2442        pHlp->pfnSSMGetU8(pSSM, &pThis->srb);
     2443        pHlp->pfnSSMGetU8(pSSM, &pThis->dor);
     2444        pHlp->pfnSSMGetU8(pSSM, &pThis->tdr);
     2445        pHlp->pfnSSMGetU8(pSSM, &pThis->dsr);
     2446        pHlp->pfnSSMGetU8(pSSM, &pThis->msr);
     2447        /* ...the status registers... */
     2448        pHlp->pfnSSMGetU8(pSSM, &pThis->status0);
     2449        pHlp->pfnSSMGetU8(pSSM, &pThis->status1);
     2450        pHlp->pfnSSMGetU8(pSSM, &pThis->status2);
     2451        /* ...the command FIFO, if the size matches... */
     2452        rc = pHlp->pfnSSMGetU32(pSSM, &val32);
     2453        AssertRCReturn(rc, rc);
     2454        AssertMsgReturn(sizeof(pThis->fifo) == val32,
     2455                        ("The size of FIFO in saved state doesn't match!\n"),
     2456                        VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
     2457        pHlp->pfnSSMGetMem(pSSM, &pThis->fifo, sizeof(pThis->fifo));
     2458        pHlp->pfnSSMGetU32(pSSM, &pThis->data_pos);
     2459        pHlp->pfnSSMGetU32(pSSM, &pThis->data_len);
     2460        pHlp->pfnSSMGetU8(pSSM, &pThis->data_state);
     2461        pHlp->pfnSSMGetU8(pSSM, &pThis->data_dir);
     2462        /* ...and miscellaneous internal FDC state. */
     2463        pHlp->pfnSSMGetU8(pSSM, &pThis->reset_sensei);
     2464        pHlp->pfnSSMGetU8(pSSM, &pThis->eot);
     2465        pHlp->pfnSSMGetU8(pSSM, &pThis->timer0);
     2466        pHlp->pfnSSMGetU8(pSSM, &pThis->timer1);
     2467        pHlp->pfnSSMGetU8(pSSM, &pThis->precomp_trk);
     2468        pHlp->pfnSSMGetU8(pSSM, &pThis->config);
     2469        pHlp->pfnSSMGetU8(pSSM, &pThis->lock);
     2470        pHlp->pfnSSMGetU8(pSSM, &pThis->pwrd);
     2471        pHlp->pfnSSMGetU8(pSSM, &pThis->version);
     2472
     2473        /* Validate the number of drives. */
     2474        rc = pHlp->pfnSSMGetU8(pSSM, &pThis->num_floppies);
     2475        AssertRCReturn(rc, rc);
     2476        AssertMsgReturn(RT_ELEMENTS(pThis->drives) == pThis->num_floppies,
     2477                        ("The number of drives in saved state doesn't match!\n"),
     2478                        VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
     2479
     2480        /* Load the per-drive state. */
     2481        for (i = 0; i < pThis->num_floppies; ++i)
     2482        {
     2483            fdrive_t *d = &pThis->drives[i];
     2484
     2485            pHlp->pfnSSMGetMem(pSSM, &d->Led, sizeof(d->Led));
     2486            rc = pHlp->pfnSSMGetU32(pSSM, &val32);
     2487            AssertRCReturn(rc, rc);
     2488            d->drive = (fdrive_type_t)val32;
     2489            pHlp->pfnSSMGetU8(pSSM, &d->dsk_chg);
     2490            pHlp->pfnSSMGetU8(pSSM, &d->perpendicular);
     2491            pHlp->pfnSSMGetU8(pSSM, &d->head);
     2492            pHlp->pfnSSMGetU8(pSSM, &d->track);
     2493            pHlp->pfnSSMGetU8(pSSM, &d->sect);
     2494        }
     2495
     2496        if (uVersion > FDC_SAVESTATE_PRE_DELAY)
     2497        {
     2498            pHlp->pfnTimerLoad(pDevIns, pThis->hXferDelayTimer, pSSM);
     2499            pHlp->pfnTimerLoad(pDevIns, pThis->hIrqDelayTimer, pSSM);
     2500        }
     2501    }
     2502    else if (uVersion == FDC_SAVESTATE_OLD)
     2503    {
     2504        /* The old saved state was significantly different. However, we can get
     2505         * back most of the controller state and fix the rest by pretending the
     2506         * disk in the drive (if any) has been replaced. At any rate there should
     2507         * be no difficulty unless the state was saved during a floppy operation.
     2508         */
     2509
    24402510        /* First verify a few assumptions. */
    24412511        AssertMsgReturn(sizeof(pThis->fifo) == FD_SECTOR_LEN,
     
    25002570        }
    25012571    }
    2502     else    /* New state - straightforward. */
    2503     {
    2504         Assert(uVersion == FDC_SAVESTATE_CURRENT);
    2505         /* Load the FDC I/O registers... */
    2506         pHlp->pfnSSMGetU8(pSSM, &pThis->sra);
    2507         pHlp->pfnSSMGetU8(pSSM, &pThis->srb);
    2508         pHlp->pfnSSMGetU8(pSSM, &pThis->dor);
    2509         pHlp->pfnSSMGetU8(pSSM, &pThis->tdr);
    2510         pHlp->pfnSSMGetU8(pSSM, &pThis->dsr);
    2511         pHlp->pfnSSMGetU8(pSSM, &pThis->msr);
    2512         /* ...the status registers... */
    2513         pHlp->pfnSSMGetU8(pSSM, &pThis->status0);
    2514         pHlp->pfnSSMGetU8(pSSM, &pThis->status1);
    2515         pHlp->pfnSSMGetU8(pSSM, &pThis->status2);
    2516         /* ...the command FIFO, if the size matches... */
    2517         rc = pHlp->pfnSSMGetU32(pSSM, &val32);
    2518         AssertRCReturn(rc, rc);
    2519         AssertMsgReturn(sizeof(pThis->fifo) == val32,
    2520                         ("The size of FIFO in saved state doesn't match!\n"),
    2521                         VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
    2522         pHlp->pfnSSMGetMem(pSSM, &pThis->fifo, sizeof(pThis->fifo));
    2523         pHlp->pfnSSMGetU32(pSSM, &pThis->data_pos);
    2524         pHlp->pfnSSMGetU32(pSSM, &pThis->data_len);
    2525         pHlp->pfnSSMGetU8(pSSM, &pThis->data_state);
    2526         pHlp->pfnSSMGetU8(pSSM, &pThis->data_dir);
    2527         /* ...and miscellaneous internal FDC state. */
    2528         pHlp->pfnSSMGetU8(pSSM, &pThis->reset_sensei);
    2529         pHlp->pfnSSMGetU8(pSSM, &pThis->eot);
    2530         pHlp->pfnSSMGetU8(pSSM, &pThis->timer0);
    2531         pHlp->pfnSSMGetU8(pSSM, &pThis->timer1);
    2532         pHlp->pfnSSMGetU8(pSSM, &pThis->precomp_trk);
    2533         pHlp->pfnSSMGetU8(pSSM, &pThis->config);
    2534         pHlp->pfnSSMGetU8(pSSM, &pThis->lock);
    2535         pHlp->pfnSSMGetU8(pSSM, &pThis->pwrd);
    2536         pHlp->pfnSSMGetU8(pSSM, &pThis->version);
    2537 
    2538         /* Validate the number of drives. */
    2539         rc = pHlp->pfnSSMGetU8(pSSM, &pThis->num_floppies);
    2540         AssertRCReturn(rc, rc);
    2541         AssertMsgReturn(RT_ELEMENTS(pThis->drives) == pThis->num_floppies,
    2542                         ("The number of drives in saved state doesn't match!\n"),
    2543                         VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
    2544 
    2545         /* Load the per-drive state. */
    2546         for (i = 0; i < pThis->num_floppies; ++i)
    2547         {
    2548             fdrive_t *d = &pThis->drives[i];
    2549 
    2550             pHlp->pfnSSMGetMem(pSSM, &d->Led, sizeof(d->Led));
    2551             rc = pHlp->pfnSSMGetU32(pSSM, &val32);
    2552             AssertRCReturn(rc, rc);
    2553             d->drive = (fdrive_type_t)val32;
    2554             pHlp->pfnSSMGetU8(pSSM, &d->dsk_chg);
    2555             pHlp->pfnSSMGetU8(pSSM, &d->perpendicular);
    2556             pHlp->pfnSSMGetU8(pSSM, &d->head);
    2557             pHlp->pfnSSMGetU8(pSSM, &d->track);
    2558             pHlp->pfnSSMGetU8(pSSM, &d->sect);
    2559         }
    2560     }
     2572    else
     2573        AssertFailedReturn(VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
    25612574    return pHlp->pfnTimerLoad(pDevIns, pThis->hResultTimer, pSSM);
    25622575}
     
    28502863
    28512864    uint16_t uIrqDelay;
    2852     rc = CFGMR3QueryU16Def(pCfg, "IRQDelay", &uIrqDelay, 0);
     2865    rc = pHlp->pfnCFGMQueryU16Def(pCfg, "IRQDelay", &uIrqDelay, 0);
    28532866    AssertMsgRCReturn(rc, ("Configuration error: Failed to read U16 IRQDelay, rc=%Rrc\n", rc), rc);
    28542867
     
    28972910     */
    28982911    rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL, fdcTimerCallback, pThis,
    2899                                 TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "FDC Timer", &pThis->hResultTimer);
     2912                              TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "FDC Timer", &pThis->hResultTimer);
    29002913    AssertRCReturn(rc, rc);
    29012914
     
    29052918    rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, fdcTransferDelayTimer, pThis,
    29062919                              TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "FDC Transfer Delay Timer", &pThis->hXferDelayTimer);
    2907     if (RT_FAILURE(rc))
    2908         return rc;
     2920    AssertRCReturn(rc, rc);
    29092921
    29102922    /*
     
    29132925    rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, fdcIrqDelayTimer, pThis,
    29142926                              TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "FDC IRQ Delay Timer", &pThis->hIrqDelayTimer);
    2915     if (RT_FAILURE(rc))
    2916         return rc;
     2927    AssertRCReturn(rc, rc);
    29172928
    29182929    pThis->uIrqDelayMsec = uIrqDelay;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette