From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LM1LZ-0002TP-EI for qemu-devel@nongnu.org; Sun, 11 Jan 2009 09:31:25 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LM1LW-0002R1-EK for qemu-devel@nongnu.org; Sun, 11 Jan 2009 09:31:23 -0500 Received: from [199.232.76.173] (port=33157 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LM1LW-0002Qv-B2 for qemu-devel@nongnu.org; Sun, 11 Jan 2009 09:31:22 -0500 Received: from smtp6-g21.free.fr ([212.27.42.6]:48946) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LM1LV-0005Tx-D9 for qemu-devel@nongnu.org; Sun, 11 Jan 2009 09:31:22 -0500 Received: from smtp6-g21.free.fr (localhost [127.0.0.1]) by smtp6-g21.free.fr (Postfix) with ESMTP id A4937E08197 for ; Sun, 11 Jan 2009 15:31:17 +0100 (CET) Received: from [192.168.0.32] (rob92-10-88-171-126-33.fbx.proxad.net [88.171.126.33]) by smtp6-g21.free.fr (Postfix) with ESMTP id AC2C8E08162 for ; Sun, 11 Jan 2009 15:31:14 +0100 (CET) Message-ID: <496A02B2.1000309@reactos.org> Date: Sun, 11 Jan 2009 15:31:14 +0100 From: =?ISO-8859-1?Q?Herv=E9_Poussineau?= MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010805090404070900010901" Subject: [Qemu-devel] [PATCH] Fix day of week in mc146818 Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------010805090404070900010901 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Hello, According to mc146818 specification, Day of Week register (#6) is=20 between 1 and 7, 1 representing Sunday. According C specification, tm_wday field in struct tm is between 0 and=20 6, 0 representing Sunday. Bit 2 of register B (#11) is named DM (data mode) and specifies if RTC=20 stores values in BCD or in binary form. Attached patch fixes the off by one error and replaces magic value 0x04=20 by REG_B_DM. Signed-off-by: Herv=E9 Poussineau Herv=E9 --------------010805090404070900010901 Content-Type: plain/text; name="mc146818.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mc146818.diff" Index: hw/mc146818rtc.c =================================================================== --- hw/mc146818rtc.c (revision 6267) +++ hw/mc146818rtc.c (working copy) @@ -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); --------------010805090404070900010901--