DevRTC.cpp revision 0c34933fc8f84dd5183d1897881bbc7683d24541
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * Motorola MC146818 RTC/CMOS Device.
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * Copyright (C) 2006-2007 innotek GmbH
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * available from http://www.virtualbox.org. This file is free software;
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * you can redistribute it and/or modify it under the terms of the GNU
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * General Public License as published by the Free Software Foundation,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * --------------------------------------------------------------------
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * This code is based on:
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * QEMU MC146818 RTC emulation
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * Copyright (c) 2003-2004 Fabrice Bellard
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * Permission is hereby granted, free of charge, to any person obtaining a copy
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * of this software and associated documentation files (the "Software"), to deal
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * in the Software without restriction, including without limitation the rights
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * copies of the Software, and to permit persons to whom the Software is
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * furnished to do so, subject to the following conditions:
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * The above copyright notice and this permission notice shall be included in
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * all copies or substantial portions of the Software.
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync * THE SOFTWARE.
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync/*******************************************************************************
#include "vl_vbox.h"
#include <time.h>
struct RTCState;
#ifndef VBOX_DEVICE_STRUCT_TESTCASE
PDMBOTHCBDECL(int) rtcIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
PDMBOTHCBDECL(int) rtcIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
#define RTC_SECONDS 0
struct RTCState {
# if !defined(RT_OS_WINDOWS)
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:
return ret;
#ifdef IN_RING3
rtc_copy_date(s);
if ( period_code != 0
s->CurPeriod = 0;
s->cRelLogEntries = 0;
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_SUCCESS;
static DECLCALLBACK(int) rtcLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t u32Version)
return VINF_SUCCESS;
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
return VERR_INVALID_PARAMETER;
/* -=-=-=-=-=- based on bits from pc.c -=-=-=-=-=- */
return VINF_SUCCESS;
int rc;
bool fGCEnabled;
bool fR0Enabled;
fR0Enabled = true;
rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, rtcTimerPeriodic, "MC146818 RTC/CMOS - Periodic", &pData->pPeriodicTimerHC);
return rc;
rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, rtcTimerSecond, "MC146818 RTC/CMOS - Second", &pData->pSecondTimerHC);
return rc;
rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL_SYNC, rtcTimerSecond2, "MC146818 RTC/CMOS - Second2", &pData->pSecondTimer2HC);
return rc;
pData->next_second_time = TMTimerGet(pData->CTXSUFF(pSecondTimer2)) + (TMTimerGetFreq(pData->CTXSUFF(pSecondTimer2)) * 99) / 100;
rc = PDMDevHlpIOPortRegister(pDevIns, u16Base, 2, NULL, rtcIOPortWrite, rtcIOPortRead, NULL, NULL, "MC146818 RTC/CMOS");
return rc;
if (fGCEnabled)
rc = PDMDevHlpIOPortRegisterGC(pDevIns, u16Base, 2, 0, "rtcIOPortWrite", "rtcIOPortRead", NULL, NULL, "MC146818 RTC/CMOS");
return rc;
if (fR0Enabled)
rc = PDMDevHlpIOPortRegisterR0(pDevIns, u16Base, 2, 0, "rtcIOPortWrite", "rtcIOPortRead", NULL, NULL, "MC146818 RTC/CMOS");
return rc;
rc = PDMDevHlpSSMRegister(pDevIns, pDevIns->pDevReg->szDeviceName, iInstance, 1 /* version */, sizeof(*pData),
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_GC | PDM_DEVREG_FLAGS_R0,
sizeof(RTCState),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,