From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:51207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RSk16-0004Ma-86 for qemu-devel@nongnu.org; Tue, 22 Nov 2011 01:39:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RSk15-0004ta-8N for qemu-devel@nongnu.org; Tue, 22 Nov 2011 01:39:40 -0500 Received: from e28smtp08.in.ibm.com ([122.248.162.8]:57871) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RSk14-0004tG-Iz for qemu-devel@nongnu.org; Tue, 22 Nov 2011 01:39:39 -0500 Received: from /spool/local by e28smtp08.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 22 Nov 2011 12:09:29 +0530 Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pAM6dNZ52830494 for ; Tue, 22 Nov 2011 12:09:25 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pAM6dMw2027944 for ; Tue, 22 Nov 2011 17:39:22 +1100 Message-ID: <4ECB4399.3090603@linux.vnet.ibm.com> Date: Tue, 22 Nov 2011 14:39:21 +0800 From: Mark Wu MIME-Version: 1.0 References: <1321898431-18449-1-git-send-email-pbonzini@redhat.com> <1321898431-18449-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1321898431-18449-2-git-send-email-pbonzini@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/4] rtc: fix 12-hour mode List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org 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 > --- > 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; > }