DevRTC.cpp revision 2244ff160a626ebdb3164949d5f4da0d6f709486
715N/A * Motorola MC146818 RTC/CMOS Device with PIIX4 extensions. 715N/A * Copyright (C) 2006-2011 Oracle Corporation 715N/A * This file is part of VirtualBox Open Source Edition (OSE), as 715N/A * you can redistribute it and/or modify it under the terms of the GNU 715N/A * General Public License (GPL) as published by the Free Software 715N/A * Foundation, in version 2 as it comes in the "COPYING" file of the 715N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the 715N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 715N/A * -------------------------------------------------------------------- 715N/A * This code is based on: 715N/A * QEMU MC146818 RTC emulation 715N/A * Copyright (c) 2003-2004 Fabrice Bellard 715N/A * Permission is hereby granted, free of charge, to any person obtaining a copy 715N/A * of this software and associated documentation files (the "Software"), to deal 715N/A * in the Software without restriction, including without limitation the rights 858N/A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 857N/A * copies of the Software, and to permit persons to whom the Software is 715N/A * furnished to do so, subject to the following conditions: 715N/A * The above copyright notice and this permission notice shall be included in 715N/A * all copies or substantial portions of the Software. 715N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 715N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1402N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 715N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1403N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 715N/A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 715N/A/******************************************************************************* 844N/A*******************************************************************************/ 788N/A/******************************************************************************* 788N/A*******************************************************************************/ 715N/A#
endif /* !VBOX_DEVICE_STRUCT_TESTCASE */ 760N/A/******************************************************************************* 760N/A* Defined Constants And Macros * 851N/A*******************************************************************************/ 860N/A/** The saved state version. */ 803N/A/** The saved state version used by VirtualBox pre-3.2. 803N/A * This does not include the second 128-byte bank. */ 760N/A/** The saved state version used by VirtualBox 3.1 and earlier. 760N/A * This does not include disabled by HPET state. */ 760N/A/** The saved state version used by VirtualBox 3.0 and earlier. 833N/A * This does not include the configuration. */ 760N/A/******************************************************************************* 760N/A* Structures and Typedefs * 760N/A*******************************************************************************/ 760N/A/** @todo Replace struct my_tm with RTTIME. */ 788N/A /** The configured IRQ. */ 788N/A /** The configured I/O port base. */ 788N/A /** Use UTC or local time initially. */ 788N/A /** Disabled by HPET legacy mode. */ 1338N/A /** Pointer to the device instance - R3 Ptr. */ 1338N/A /** The periodic timer (rtcTimerPeriodic) - R3 Ptr. */ 1338N/A /** The second timer (rtcTimerSecond) - R3 Ptr. */ 793N/A /** The second second timer (rtcTimerSecond2) - R3 Ptr. */ 788N/A /** Pointer to the device instance - R0 Ptr. */ 793N/A /** The periodic timer (rtcTimerPeriodic) - R0 Ptr. */ 788N/A /** The second timer (rtcTimerSecond) - R0 Ptr. */ 803N/A /** The second second timer (rtcTimerSecond2) - R0 Ptr. */ 803N/A /** Pointer to the device instance - RC Ptr. */ 803N/A /** The periodic timer (rtcTimerPeriodic) - RC Ptr. */ 803N/A /** The second timer (rtcTimerSecond) - RC Ptr. */ 851N/A /** The second second timer (rtcTimerSecond2) - RC Ptr. */ 1402N/A /** The RTC registration structure. */ 715N/A /** The RTC device helpers. */ 715N/A /** Number of release log entries. Used to prevent flooding. */ 844N/A /** HPET legacy mode notification interface. */ 1421N/A /* period in 32 kHz cycles */ 803N/A /* compute 32 kHz clock */ 1402N/A return ((a /
10) <<
4) | (a %
10);
1402N/A return ((a >>
4) *
10) + (a &
0x0f);
720N/A/* -=-=-=-=-=- I/O Port Handlers -=-=-=-=-=- */ 1402N/A * Port I/O Handler for IN operations. 1402N/A * @returns VBox status code. 1402N/A * @param pDevIns The device instance. 1402N/A * @param pvUser User argument - ignored. 1402N/A * @param uPort Port number used for the IN operation. 1402N/A * @param pu32 Where to store the result. 1402N/A * @param cb Number of bytes read. 788N/A * Port I/O Handler for OUT operations. 788N/A * @returns VBox status code. 715N/A * @param pDevIns The device instance. 715N/A * @param pvUser User argument - ignored. 715N/A * @param uPort Port number used for the IN operation. 715N/A * @param u32 The value to output. 715N/A * @param cb The value size in bytes. 720N/A Log((
"CMOS: Write bank %d idx %#04x: %#04x (old %#04x)\n",
bank,
715N/A /* if in set mode, do not update the time */ 715N/A /* We need to acquire the clock lock, because of lock ordering 715N/A issues this means having to release the device lock. Since 715N/A we're letting IOM do the locking, we must not return without 715N/A holding the device lock.*/ 763N/A /* UIP bit is read only */ 763N/A /* set mode: reset UIP mode */ 763N/A#
if 0
/* This is probably wrong as it breaks changing the time/date in OS/2. */ 763N/A /* if disabling set mode, update the time */ 844N/A /* the caller leaves the other lock. */ 844N/A /* cannot write to them */ 844N/A/* -=-=-=-=-=- Timers and their support code -=-=-=-=-=- */ 844N/A * Device timer callback function, periodic. 844N/A * @param pDevIns Device instance of the device which registered the timer. 844N/A * @param pTimer The timer handle. 844N/A * @param pvUser Pointer to the RTC state. 844N/A/* month is between 0 and 11. */ 844N/A 31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31 856N/A/* update 'tm' to the next second */ 788N/A * Device timer callback function, second. 839N/A * @param pDevIns Device instance of the device which registered the timer. 788N/A * @param pTimer The timer handle. 763N/A * @param pvUser Pointer to the RTC state. 844N/A /* if the oscillator is not in normal operation, we do not update */ 839N/A /* update in progress bit */ 826N/A /* 244140 ns = 8 / 32768 seconds */ 1421N/A/* Used by rtc_set_date and rtcTimerSecond2. */ 715N/A * Device timer callback function, second2. 715N/A * @param pDevIns Device instance of the device which registered the timer. 715N/A * @param pTimer The timer handle. 715N/A * @param pvUser Pointer to the RTC state. 844N/A /* update ended interrupt */ 745N/A /* clear update in progress bit */ 745N/A/* -=-=-=-=-=- Saved State -=-=-=-=-=- */ 788N/A * @copydoc FNSSMDEVLIVEEXEC 844N/A * @copydoc FNSSMDEVSAVEEXEC 761N/A * @copydoc FNSSMDEVLOADEXEC 745N/A /* Second CMOS bank. */ 795N/A LogRel((
"RTC: stopped the periodic timer (restore)\n"));
795N/A/* -=-=-=-=-=- PDM Interface provided by the RTC device -=-=-=-=-=- */ 747N/A * Calculate and update the standard CMOS checksum. 747N/A * @param pThis Pointer to the RTC state data. 795N/A * Write to a CMOS register and update the checksum if necessary. 795N/A * @returns VBox status code. 795N/A * @param pDevIns Device instance of the RTC. 747N/A * @param iReg The CMOS register index; bit 8 determines bank. 880N/A * @param u8Value The CMOS register value. 747N/A /* does it require checksum update? */ 747N/A * Read a CMOS register. 747N/A * @returns VBox status code. 747N/A * @param pDevIns Device instance of the RTC. 747N/A * @param iReg The CMOS register index; bit 8 determines bank. 747N/A * @param pu8Value Where to store the CMOS register value. 880N/A * @interface_method_impl{PDMIHPETLEGACYNOTIFY,pfnModeChanged} 880N/A/* -=-=-=-=-=- based on bits from pc.c -=-=-=-=-=- */ 745N/A/** @copydoc FNPDMDEVINITCOMPLETE */ 745N/A /** @todo this should be (re)done at power on if we didn't load a state... */ 745N/A * Recalculate the checksum just in case. 715N/A/* -=-=-=-=-=- real code -=-=-=-=-=- */ 745N/A * @interface_method_impl{PDMIBASE,pfnQueryInterface} 1421N/A * @interface_method_impl{PDMDEVREG,pfnConstruct} 1421N/A N_(
"Configuration error: Querying \"Irq\" as a uint8_t failed"));
1230N/A N_(
"Configuration error: Querying \"Base\" as a RTIOPORT failed"));
745N/A N_(
"Configuration error: Querying \"UseUTC\" as a bool failed"));
745N/A N_(
"Configuration error: failed to read GCEnabled as boolean"));
745N/A N_(
"Configuration error: failed to read R0Enabled as boolean"));
715N/A Log((
"RTC: Irq=%#x Base=%#x fGCEnabled=%RTbool fR0Enabled=%RTbool\n",
844N/A /* IHpetLegacyNotify */ 844N/A * Create timers, arm them, register I/O Ports and save state. 844N/A * The device registration structure. 815N/A /* pfnQueryInterface */ 761N/A#
endif /* !VBOX_DEVICE_STRUCT_TESTCASE */