mirror of
https://github.com/qemu/qemu.git
synced 2024-11-26 21:33:40 +08:00
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>
This commit is contained in:
parent
024a6fbdb9
commit
3b89eb43b6
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user