qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [6310] Fix day of week in mc146818
Date: Wed, 14 Jan 2009 21:09:07 +0000	[thread overview]
Message-ID: <E1LNCz5-0003f9-OE@cvs.savannah.gnu.org> (raw)

Revision: 6310
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6310
Author:   aurel32
Date:     2009-01-14 21:09:07 +0000 (Wed, 14 Jan 2009)

Log Message:
-----------
Fix day of week in mc146818

According to mc146818 specification, Day of Week register (#6) is between 1
and 7, 1 representing Sunday. According C specification, tm_wday field in
struct tm is between 0 and 6, 0 representing Sunday.

Bit 2 of register B (#11) is named DM (data mode) and specifies if RTC
stores values in BCD or in binary form.

Signed-off-by: Herv?\195?\169 Poussineau <hpoussin@reactos.org>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

Modified Paths:
--------------
    trunk/hw/mc146818rtc.c

Modified: trunk/hw/mc146818rtc.c
===================================================================
--- trunk/hw/mc146818rtc.c	2009-01-14 21:02:59 UTC (rev 6309)
+++ trunk/hw/mc146818rtc.c	2009-01-14 21:09:07 UTC (rev 6310)
@@ -54,6 +54,7 @@
 #define REG_B_PIE 0x40
 #define REG_B_AIE 0x20
 #define REG_B_UIE 0x10
+#define REG_B_DM  0x04
 
 struct RTCState {
     uint8_t cmos_data[128];
@@ -186,7 +187,7 @@
 
 static inline int to_bcd(RTCState *s, int a)
 {
-    if (s->cmos_data[RTC_REG_B] & 0x04) {
+    if (s->cmos_data[RTC_REG_B] & REG_B_DM) {
         return a;
     } else {
         return ((a / 10) << 4) | (a % 10);
@@ -195,7 +196,7 @@
 
 static inline int from_bcd(RTCState *s, int a)
 {
-    if (s->cmos_data[RTC_REG_B] & 0x04) {
+    if (s->cmos_data[RTC_REG_B] & REG_B_DM) {
         return a;
     } else {
         return ((a >> 4) * 10) + (a & 0x0f);
@@ -213,7 +214,7 @@
         (s->cmos_data[RTC_HOURS] & 0x80)) {
         tm->tm_hour += 12;
     }
-    tm->tm_wday = from_bcd(s, s->cmos_data[RTC_DAY_OF_WEEK]);
+    tm->tm_wday = from_bcd(s, s->cmos_data[RTC_DAY_OF_WEEK]) - 1;
     tm->tm_mday = from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]);
     tm->tm_mon = from_bcd(s, s->cmos_data[RTC_MONTH]) - 1;
     tm->tm_year = from_bcd(s, s->cmos_data[RTC_YEAR]) + 100;
@@ -234,7 +235,7 @@
         if (tm->tm_hour >= 12)
             s->cmos_data[RTC_HOURS] |= 0x80;
     }
-    s->cmos_data[RTC_DAY_OF_WEEK] = to_bcd(s, tm->tm_wday);
+    s->cmos_data[RTC_DAY_OF_WEEK] = to_bcd(s, tm->tm_wday + 1);
     s->cmos_data[RTC_DAY_OF_MONTH] = to_bcd(s, tm->tm_mday);
     s->cmos_data[RTC_MONTH] = to_bcd(s, tm->tm_mon + 1);
     s->cmos_data[RTC_YEAR] = to_bcd(s, tm->tm_year % 100);

                 reply	other threads:[~2009-01-14 21:09 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=E1LNCz5-0003f9-OE@cvs.savannah.gnu.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).