DevRTC.cpp revision 3614117c1132a61599e6190939e775cafe549411
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Motorola MC146818 RTC/CMOS Device.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * available from http://www.virtualbox.org. This file is free software;
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * you can redistribute it and/or modify it under the terms of the GNU
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * General Public License (GPL) as published by the Free Software
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * additional information or have any questions.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * --------------------------------------------------------------------
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * This code is based on:
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * QEMU MC146818 RTC emulation
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Copyright (c) 2003-2004 Fabrice Bellard
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Permission is hereby granted, free of charge, to any person obtaining a copy
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * of this software and associated documentation files (the "Software"), to deal
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * in the Software without restriction, including without limitation the rights
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * copies of the Software, and to permit persons to whom the Software is
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * furnished to do so, subject to the following conditions:
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * The above copyright notice and this permission notice shall be included in
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * all copies or substantial portions of the Software.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * THE SOFTWARE.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/*******************************************************************************
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync* Header Files *
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync*******************************************************************************/
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync#endif /* IN_RING3 */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/*******************************************************************************
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync* Internal Functions *
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync*******************************************************************************/
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsyncPDMBOTHCBDECL(int) rtcIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsyncPDMBOTHCBDECL(int) rtcIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsyncPDMBOTHCBDECL(void) rtcTimerPeriodic(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsyncPDMBOTHCBDECL(void) rtcTimerSecond(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsyncPDMBOTHCBDECL(void) rtcTimerSecond2(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/*******************************************************************************
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync* Defined Constants And Macros *
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync*******************************************************************************/
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/*#define DEBUG_CMOS*/
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/** The saved state version. */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/** The saved state version used by VirtualBox 3.1 and earlier.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * This does not include disabled by HPET state. */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/** The saved state version used by VirtualBox 3.0 and earlier.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * This does not include the configuration. */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/*******************************************************************************
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync* Structures and Typedefs *
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync*******************************************************************************/
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/** @todo Replace struct my_tm with RTTIME. */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync /** The configured IRQ. */
bool fUTC;
#ifndef VBOX_DEVICE_STRUCT_TESTCASE
if (period_code != 0 &&
Log(("CMOS: Write idx %#04x: %#04x (old %#04x)\n", s->cmos_index, data, s->cmos_data[s->cmos_index]));
switch(s->cmos_index) {
case RTC_SECONDS_ALARM:
case RTC_MINUTES_ALARM:
case RTC_HOURS_ALARM:
case RTC_SECONDS:
case RTC_MINUTES:
case RTC_HOURS:
case RTC_DAY_OF_WEEK:
case RTC_DAY_OF_MONTH:
case RTC_MONTH:
case RTC_YEAR:
rtc_set_time(s);
case RTC_REG_A:
case RTC_REG_B:
rtc_set_time(s);
case RTC_REG_C:
case RTC_REG_D:
int days_in_month;
rtc_copy_date(s);
int ret;
switch(s->cmos_index) {
case RTC_SECONDS:
case RTC_MINUTES:
case RTC_HOURS:
case RTC_DAY_OF_WEEK:
case RTC_DAY_OF_MONTH:
case RTC_MONTH:
case RTC_YEAR:
case RTC_REG_A:
case RTC_REG_C:
rtc_raise_irq(s, 0);
return ret;
#ifdef IN_RING3
rtc_copy_date(s);
PDMBOTHCBDECL(int) rtcIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
return VINF_SUCCESS;
return VERR_IOM_IOPORT_UNUSED;
PDMBOTHCBDECL(int) rtcIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
return VINF_SUCCESS;
#ifdef IN_RING3
return VINF_SSM_DONT_CALL_AGAIN;
return VINF_SUCCESS;
static DECLCALLBACK(int) rtcLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
int rc;
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - u8Irq: saved=%#x config=%#x"), u8Irq, pThis->irq);
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - IOPortBase: saved=%RTiop config=%RTiop"), IOPortBase, pThis->IOPortBase);
bool fUTC;
return VINF_SUCCESS;
if ( period_code != 0
return VINF_SUCCESS;
return VINF_SUCCESS;
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
return VERR_INVALID_PARAMETER;
/* -=-=-=-=-=- based on bits from pc.c -=-=-=-=-=- */
return VINF_SUCCESS;
return NULL;
return VINF_SUCCESS;
int rc;
bool fGCEnabled;
bool fR0Enabled;
return rc;
return rc;
return rc;
return rc;
return rc;
if (fGCEnabled)
return rc;
if (fR0Enabled)
return rc;
rc = PDMDevHlpSSMRegister3(pDevIns, RTC_SAVED_STATE_VERSION, sizeof(*pThis), rtcLiveExec, rtcSaveExec, rtcLoadExec);
return rc;
return rc;
return VINF_SUCCESS;
PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_32_64 | PDM_DEVREG_FLAGS_PAE36 | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
sizeof(RTCState),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,