Commit 6f1bf24d1bd8d3fcea4f118b15781aee1932364a

Authored by aurel32
1 parent 5b7141a1

Fix day of week in mc146818

According to mc146818 specification, Day of Week register (#6) is between 1
and 7, 1 representing Sunday. According C specification, tm_wday field in
struct tm is between 0 and 6, 0 representing Sunday.

Bit 2 of register B (#11) is named DM (data mode) and specifies if RTC
stores values in BCD or in binary form.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6310 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 5 additions and 4 deletions
hw/mc146818rtc.c
... ... @@ -54,6 +54,7 @@
54 54 #define REG_B_PIE 0x40
55 55 #define REG_B_AIE 0x20
56 56 #define REG_B_UIE 0x10
  57 +#define REG_B_DM 0x04
57 58  
58 59 struct RTCState {
59 60 uint8_t cmos_data[128];
... ... @@ -186,7 +187,7 @@ static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data)
186 187  
187 188 static inline int to_bcd(RTCState *s, int a)
188 189 {
189   - if (s->cmos_data[RTC_REG_B] & 0x04) {
  190 + if (s->cmos_data[RTC_REG_B] & REG_B_DM) {
190 191 return a;
191 192 } else {
192 193 return ((a / 10) << 4) | (a % 10);
... ... @@ -195,7 +196,7 @@ static inline int to_bcd(RTCState *s, int a)
195 196  
196 197 static inline int from_bcd(RTCState *s, int a)
197 198 {
198   - if (s->cmos_data[RTC_REG_B] & 0x04) {
  199 + if (s->cmos_data[RTC_REG_B] & REG_B_DM) {
199 200 return a;
200 201 } else {
201 202 return ((a >> 4) * 10) + (a & 0x0f);
... ... @@ -213,7 +214,7 @@ static void rtc_set_time(RTCState *s)
213 214 (s->cmos_data[RTC_HOURS] & 0x80)) {
214 215 tm->tm_hour += 12;
215 216 }
216   - tm->tm_wday = from_bcd(s, s->cmos_data[RTC_DAY_OF_WEEK]);
  217 + tm->tm_wday = from_bcd(s, s->cmos_data[RTC_DAY_OF_WEEK]) - 1;
217 218 tm->tm_mday = from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]);
218 219 tm->tm_mon = from_bcd(s, s->cmos_data[RTC_MONTH]) - 1;
219 220 tm->tm_year = from_bcd(s, s->cmos_data[RTC_YEAR]) + 100;
... ... @@ -234,7 +235,7 @@ static void rtc_copy_date(RTCState *s)
234 235 if (tm->tm_hour >= 12)
235 236 s->cmos_data[RTC_HOURS] |= 0x80;
236 237 }
237   - s->cmos_data[RTC_DAY_OF_WEEK] = to_bcd(s, tm->tm_wday);
  238 + s->cmos_data[RTC_DAY_OF_WEEK] = to_bcd(s, tm->tm_wday + 1);
238 239 s->cmos_data[RTC_DAY_OF_MONTH] = to_bcd(s, tm->tm_mday);
239 240 s->cmos_data[RTC_MONTH] = to_bcd(s, tm->tm_mon + 1);
240 241 s->cmos_data[RTC_YEAR] = to_bcd(s, tm->tm_year % 100);
... ...