qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/4] rtc: fix 12-hour mode


From: Mark Wu
Subject: Re: [Qemu-devel] [PATCH 1/4] rtc: fix 12-hour mode
Date: Tue, 22 Nov 2011 14:39:21 +0800
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110927 Red Hat/3.1.15-1.el6_1 Thunderbird/3.1.15

On 11/22/2011 02:00 AM, Paolo Bonzini wrote:
Hours in 12-hour mode are in the 1-12 range, not 0-11.
Interesting. I would like to know how you could find this problem. It seems linux driver never changes the format and 24-hour is default in rtc emulation code. So how did it expose and how to test it?

Thanks.
Signed-off-by: Paolo Bonzini<address@hidden>
---
  hw/mc146818rtc.c |   11 +++++++----
  1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 2aaca2f..14c8cb9 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -296,9 +296,11 @@ static void rtc_set_time(RTCState *s)
      tm->tm_sec = rtc_from_bcd(s, s->cmos_data[RTC_SECONDS]);
      tm->tm_min = rtc_from_bcd(s, s->cmos_data[RTC_MINUTES]);
      tm->tm_hour = rtc_from_bcd(s, s->cmos_data[RTC_HOURS]&  0x7f);
-    if (!(s->cmos_data[RTC_REG_B]&  REG_B_24H)&&
-        (s->cmos_data[RTC_HOURS]&  0x80)) {
-        tm->tm_hour += 12;
+    if (!(s->cmos_data[RTC_REG_B]&  REG_B_24H)) {
+        tm->tm_hour %= 12;
+        if (s->cmos_data[RTC_HOURS]&  0x80) {
+            tm->tm_hour += 12;
+        }
      }
      tm->tm_wday = rtc_from_bcd(s, s->cmos_data[RTC_DAY_OF_WEEK]) - 1;
      tm->tm_mday = rtc_from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]);
@@ -320,7 +324,8 @@ static void rtc_copy_date(RTCState *s)
          s->cmos_data[RTC_HOURS] = rtc_to_bcd(s, tm->tm_hour);
      } else {
          /* 12 hour format */
-        s->cmos_data[RTC_HOURS] = rtc_to_bcd(s, tm->tm_hour % 12);
+        int h = (tm->tm_hour % 12) ? tm->tm_hour % 12 : 12;
+        s->cmos_data[RTC_HOURS] = rtc_to_bcd(s, h);
          if (tm->tm_hour>= 12)
              s->cmos_data[RTC_HOURS] |= 0x80;
      }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]