aboutsummaryrefslogtreecommitdiff
path: root/hw/mc146818rtc.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2011-11-21 19:00:28 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2012-01-13 10:20:49 -0600
commit3b89eb43b66eec34277fddfce610ac1ec7c78dba (patch)
tree7deb256e9e0ae76f24e570f7f9784622845bcfb7 /hw/mc146818rtc.c
parent024a6fbdb9d8cbc4d7f833b23db51c9d1004bc47 (diff)
rtc: fix 12-hour mode
Hours in 12-hour mode are in the 1-12 range, not 0-11. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/mc146818rtc.c')
-rw-r--r--hw/mc146818rtc.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 9cbd052694..65ed779045 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 +322,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;
}