VirtualBox

Changeset 27460 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 17, 2010 5:21:23 PM (15 years ago)
Author:
vboxsync
Message:

DevRTC: Added support for PIIX4 style second CMOS bank.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/DevRTC.cpp

    r27126 r27460  
    11/* $Id$ */
    22/** @file
    3  * Motorola MC146818 RTC/CMOS Device.
     3 * Motorola MC146818 RTC/CMOS Device with PIIX4 extensions.
    44 */
    55
     
    117117
    118118/** The saved state version. */
    119 #define RTC_SAVED_STATE_VERSION             3
     119#define RTC_SAVED_STATE_VERSION             4
     120/** The saved state version used by VirtualBox pre-3.2.
     121 * This does not include the second 128-byte bank. */
     122#define RTC_SAVED_STATE_VERSION_VBOX_32PRE  3
    120123/** The saved state version used by VirtualBox 3.1 and earlier.
    121  * This does not include disabled by HPET state.  */
     124 * This does not include disabled by HPET state. */
    122125#define RTC_SAVED_STATE_VERSION_VBOX_31     2
    123126/** The saved state version used by VirtualBox 3.0 and earlier.
     
    144147
    145148struct RTCState {
    146     uint8_t cmos_data[128];
    147     uint8_t cmos_index;
    148     uint8_t Alignment0[7];
     149    uint8_t cmos_data[256];
     150    uint8_t cmos_index[2];
     151    uint8_t Alignment0[6];
    149152    struct my_tm current_tm;
    150153    /** The configured IRQ. */
     
    258261{
    259262    RTCState *s = (RTCState*)opaque;
    260 
     263    uint32_t bank;
     264
     265    bank = (addr >> 1) & 1;
    261266    if ((addr & 1) == 0) {
    262         s->cmos_index = data & 0x7f;
     267        s->cmos_index[bank] = (data & 0x7f) + (bank * 128);
    263268    } else {
    264         Log(("CMOS: Write idx %#04x: %#04x (old %#04x)\n", s->cmos_index, data, s->cmos_data[s->cmos_index]));
    265         switch(s->cmos_index) {
     269        Log(("CMOS: Write bank %d idx %#04x: %#04x (old %#04x)\n", bank,
     270             s->cmos_index[bank], data, s->cmos_data[s->cmos_index[bank]]));
     271        switch(s->cmos_index[bank]) {
    266272        case RTC_SECONDS_ALARM:
    267273        case RTC_MINUTES_ALARM:
    268274        case RTC_HOURS_ALARM:
    269             s->cmos_data[s->cmos_index] = data;
     275            s->cmos_data[s->cmos_index[0]] = data;
    270276            break;
    271277        case RTC_SECONDS:
     
    276282        case RTC_MONTH:
    277283        case RTC_YEAR:
    278             s->cmos_data[s->cmos_index] = data;
     284            s->cmos_data[s->cmos_index[0]] = data;
    279285            /* if in set mode, do not update the time */
    280286            if (!(s->cmos_data[RTC_REG_B] & REG_B_SET)) {
     
    309315            break;
    310316        default:
    311             s->cmos_data[s->cmos_index] = data;
     317            s->cmos_data[s->cmos_index[bank]] = data;
    312318            break;
    313319        }
     
    488494    RTCState *s = (RTCState*)opaque;
    489495    int ret;
     496    unsigned bank;
     497
     498    bank = (addr >> 1) & 1;
    490499    if ((addr & 1) == 0) {
    491500        return 0xff;
    492501    } else {
    493         switch(s->cmos_index) {
     502        switch(s->cmos_index[bank]) {
    494503        case RTC_SECONDS:
    495504        case RTC_MINUTES:
     
    499508        case RTC_MONTH:
    500509        case RTC_YEAR:
    501             ret = s->cmos_data[s->cmos_index];
     510            ret = s->cmos_data[s->cmos_index[0]];
    502511            break;
    503512        case RTC_REG_A:
    504             ret = s->cmos_data[s->cmos_index];
     513            ret = s->cmos_data[s->cmos_index[0]];
    505514            break;
    506515        case RTC_REG_C:
    507             ret = s->cmos_data[s->cmos_index];
     516            ret = s->cmos_data[s->cmos_index[0]];
    508517            rtc_raise_irq(s, 0);
    509518            s->cmos_data[RTC_REG_C] = 0x00;
    510519            break;
    511520        default:
    512             ret = s->cmos_data[s->cmos_index];
     521            ret = s->cmos_data[s->cmos_index[bank]];
    513522            break;
    514523        }
    515         Log(("CMOS: Read idx %#04x: %#04x\n", s->cmos_index, ret));
     524        Log(("CMOS: Read bank %d idx %#04x: %#04x\n", bank, s->cmos_index[bank], ret));
    516525        return ret;
    517526    }
     
    645654    /* The state. */
    646655    SSMR3PutMem(pSSM, pThis->cmos_data, 128);
    647     SSMR3PutU8(pSSM, pThis->cmos_index);
     656    SSMR3PutU8(pSSM, pThis->cmos_index[0]);
    648657
    649658    SSMR3PutS32(pSSM, pThis->current_tm.tm_sec);
     
    663672    TMR3TimerSave(pThis->CTX_SUFF(pSecondTimer2), pSSM);
    664673
    665     return SSMR3PutBool(pSSM, pThis->fDisabledByHpet);
     674    SSMR3PutBool(pSSM, pThis->fDisabledByHpet);
     675
     676    SSMR3PutMem(pSSM, &pThis->cmos_data[128], 128);
     677    return SSMR3PutU8(pSSM, pThis->cmos_index[1]);
    666678}
    667679
     
    676688
    677689    if (    uVersion != RTC_SAVED_STATE_VERSION
     690        &&  uVersion != RTC_SAVED_STATE_VERSION_VBOX_32PRE
    678691        &&  uVersion != RTC_SAVED_STATE_VERSION_VBOX_31
    679692        &&  uVersion != RTC_SAVED_STATE_VERSION_VBOX_30)
     
    704717    /* The state. */
    705718    SSMR3GetMem(pSSM, pThis->cmos_data, 128);
    706     SSMR3GetU8(pSSM, &pThis->cmos_index);
     719    SSMR3GetU8(pSSM, &pThis->cmos_index[0]);
    707720
    708721    SSMR3GetS32(pSSM, &pThis->current_tm.tm_sec);
     
    724737    if (uVersion > RTC_SAVED_STATE_VERSION_VBOX_31)
    725738         SSMR3GetBool(pSSM, &pThis->fDisabledByHpet);
     739
     740    if (uVersion > RTC_SAVED_STATE_VERSION_VBOX_32PRE)
     741    {
     742        /* Second CMOS bank. */
     743        SSMR3GetMem(pSSM, &pThis->cmos_data[128], 128);
     744        SSMR3GetU8(pSSM, &pThis->cmos_index[1]);
     745    }
    726746
    727747    int period_code = pThis->cmos_data[RTC_REG_A] & 0x0f;
     
    767787 * @returns VBox status code.
    768788 * @param   pDevIns     Device instance of the RTC.
    769  * @param   iReg        The CMOS register index.
     789 * @param   iReg        The CMOS register index; bit 8 determines bank.
    770790 * @param   u8Value     The CMOS register value.
    771791 */
     
    794814 * @returns VBox status code.
    795815 * @param   pDevIns     Device instance of the RTC.
    796  * @param   iReg        The CMOS register index.
     816 * @param   iReg        The CMOS register index; bit 8 determines bank.
    797817 * @param   pu8Value    Where to store the CMOS register value.
    798818 */
     
    851871    rtcCalcCRC(pThis);
    852872
    853     Log(("CMOS: \n%16.128Rhxd\n", pThis->cmos_data));
     873    Log(("CMOS bank 0: \n%16.128Rhxd\n", &pThis->cmos_data[0]));
     874    Log(("CMOS bank 1: \n%16.128Rhxd\n", &pThis->cmos_data[128]));
    854875    return VINF_SUCCESS;
    855876}
     
    10001021        return rc;
    10011022
    1002     rc = PDMDevHlpIOPortRegister(pDevIns, pThis->IOPortBase, 2, NULL,
     1023    rc = PDMDevHlpIOPortRegister(pDevIns, pThis->IOPortBase, 4, NULL,
    10031024                                 rtcIOPortWrite, rtcIOPortRead, NULL, NULL, "MC146818 RTC/CMOS");
    10041025    if (RT_FAILURE(rc))
     
    10061027    if (fGCEnabled)
    10071028    {
    1008         rc = PDMDevHlpIOPortRegisterRC(pDevIns, pThis->IOPortBase, 2, 0,
     1029        rc = PDMDevHlpIOPortRegisterRC(pDevIns, pThis->IOPortBase, 4, 0,
    10091030                                       "rtcIOPortWrite", "rtcIOPortRead", NULL, NULL, "MC146818 RTC/CMOS");
    10101031        if (RT_FAILURE(rc))
     
    10131034    if (fR0Enabled)
    10141035    {
    1015         rc = PDMDevHlpIOPortRegisterR0(pDevIns, pThis->IOPortBase, 2, 0,
     1036        rc = PDMDevHlpIOPortRegisterR0(pDevIns, pThis->IOPortBase, 4, 0,
    10161037                                       "rtcIOPortWrite", "rtcIOPortRead", NULL, NULL, "MC146818 RTC/CMOS");
    10171038        if (RT_FAILURE(rc))
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