aboutsummaryrefslogtreecommitdiff
path: root/hw/mc146818rtc.c
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2006-12-07 17:16:55 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2006-12-07 17:16:55 +0000
commitea55ffb37378dcb16972aef6ef898b3d0ba17fb0 (patch)
treee8bc6443d39bbe58c5ec66675a53b0a874ca3dc0 /hw/mc146818rtc.c
parentaa328addc0ed51751baa758c1eeb978c6fb77c74 (diff)
Move date/time init to the RTC implementation.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2229 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'hw/mc146818rtc.c')
-rw-r--r--hw/mc146818rtc.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 9d4cbed90b..bad4cbd864 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -380,6 +380,29 @@ void rtc_set_date(RTCState *s, const struct tm *tm)
rtc_copy_date(s);
}
+/* PC cmos mappings */
+#define REG_IBM_CENTURY_BYTE 0x32
+#define REG_IBM_PS2_CENTURY_BYTE 0x37
+
+void rtc_set_date_from_host(RTCState *s)
+{
+ time_t ti;
+ struct tm *tm;
+ int val;
+
+ /* set the CMOS date */
+ time(&ti);
+ if (rtc_utc)
+ tm = gmtime(&ti);
+ else
+ tm = localtime(&ti);
+ rtc_set_date(s, tm);
+
+ val = to_bcd(s, (tm->tm_year / 100) + 19);
+ rtc_set_memory(s, REG_IBM_CENTURY_BYTE, val);
+ rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val);
+}
+
static void rtc_save(QEMUFile *f, void *opaque)
{
RTCState *s = opaque;
@@ -444,6 +467,8 @@ RTCState *rtc_init(int base, int irq)
s->cmos_data[RTC_REG_C] = 0x00;
s->cmos_data[RTC_REG_D] = 0x80;
+ rtc_set_date_from_host(s);
+
s->periodic_timer = qemu_new_timer(vm_clock,
rtc_periodic_timer, s);
s->second_timer = qemu_new_timer(vm_clock,