All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] move date/time initialization into mc146818rtc.c
Date: Sat, 18 Nov 2006 22:36:45 +0100	[thread overview]
Message-ID: <20061118213645.GA18149@bode.aurel32.net> (raw)

The patch below moves the initialisation of the RTC date/time, currently
into hw/pc.c into hw/mc146818rtc.c as this part of the initialization
is not guest specific. This avoid duplication of code in (future)
platforms emulation.

-- 
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   aurel32@debian.org         | aurelien@aurel32.net
   `-    people.debian.org/~aurel32 | www.aurel32.net


Index: mc146818rtc.c
===================================================================
RCS file: /sources/qemu/qemu/hw/mc146818rtc.c,v
retrieving revision 1.6
diff -u -d -p -r1.6 mc146818rtc.c
--- mc146818rtc.c	3 Jun 2004 12:51:19 -0000	1.6
+++ mc146818rtc.c	18 Nov 2006 21:26:38 -0000
@@ -380,6 +380,29 @@ void rtc_set_date(RTCState *s, const str
     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, 
Index: pc.c
===================================================================
RCS file: /sources/qemu/qemu/hw/pc.c,v
retrieving revision 1.62
diff -u -d -p -r1.62 pc.c
--- pc.c	24 Sep 2006 18:48:00 -0000	1.62
+++ pc.c	18 Nov 2006 21:26:38 -0000
@@ -111,14 +111,6 @@ static void pic_irq_request(void *opaque
 /* PC cmos mappings */
 
 #define REG_EQUIPMENT_BYTE          0x14
-#define REG_IBM_CENTURY_BYTE        0x32
-#define REG_IBM_PS2_CENTURY_BYTE    0x37
-
-
-static inline int to_bcd(RTCState *s, int a)
-{
-    return ((a / 10) << 4) | (a % 10);
-}
 
 static int cmos_get_fd_drive_type(int fd0)
 {
@@ -171,18 +163,6 @@ static void cmos_init(int ram_size, int 
     struct tm *tm;
     int i;
 
-    /* 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);
-
     /* various important CMOS locations needed by PC/Bochs bios */
 
     /* memory size */

                 reply	other threads:[~2006-11-18 21:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061118213645.GA18149@bode.aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.