Commit ea55ffb37378dcb16972aef6ef898b3d0ba17fb0
1 parent
aa328add
Move date/time init to the RTC implementation.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2229 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
25 additions
and
22 deletions
hw/mc146818rtc.c
... | ... | @@ -380,6 +380,29 @@ void rtc_set_date(RTCState *s, const struct tm *tm) |
380 | 380 | rtc_copy_date(s); |
381 | 381 | } |
382 | 382 | |
383 | +/* PC cmos mappings */ | |
384 | +#define REG_IBM_CENTURY_BYTE 0x32 | |
385 | +#define REG_IBM_PS2_CENTURY_BYTE 0x37 | |
386 | + | |
387 | +void rtc_set_date_from_host(RTCState *s) | |
388 | +{ | |
389 | + time_t ti; | |
390 | + struct tm *tm; | |
391 | + int val; | |
392 | + | |
393 | + /* set the CMOS date */ | |
394 | + time(&ti); | |
395 | + if (rtc_utc) | |
396 | + tm = gmtime(&ti); | |
397 | + else | |
398 | + tm = localtime(&ti); | |
399 | + rtc_set_date(s, tm); | |
400 | + | |
401 | + val = to_bcd(s, (tm->tm_year / 100) + 19); | |
402 | + rtc_set_memory(s, REG_IBM_CENTURY_BYTE, val); | |
403 | + rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val); | |
404 | +} | |
405 | + | |
383 | 406 | static void rtc_save(QEMUFile *f, void *opaque) |
384 | 407 | { |
385 | 408 | RTCState *s = opaque; |
... | ... | @@ -444,6 +467,8 @@ RTCState *rtc_init(int base, int irq) |
444 | 467 | s->cmos_data[RTC_REG_C] = 0x00; |
445 | 468 | s->cmos_data[RTC_REG_D] = 0x80; |
446 | 469 | |
470 | + rtc_set_date_from_host(s); | |
471 | + | |
447 | 472 | s->periodic_timer = qemu_new_timer(vm_clock, |
448 | 473 | rtc_periodic_timer, s); |
449 | 474 | s->second_timer = qemu_new_timer(vm_clock, | ... | ... |
hw/pc.c
... | ... | @@ -111,14 +111,6 @@ static void pic_irq_request(void *opaque, int level) |
111 | 111 | /* PC cmos mappings */ |
112 | 112 | |
113 | 113 | #define REG_EQUIPMENT_BYTE 0x14 |
114 | -#define REG_IBM_CENTURY_BYTE 0x32 | |
115 | -#define REG_IBM_PS2_CENTURY_BYTE 0x37 | |
116 | - | |
117 | - | |
118 | -static inline int to_bcd(RTCState *s, int a) | |
119 | -{ | |
120 | - return ((a / 10) << 4) | (a % 10); | |
121 | -} | |
122 | 114 | |
123 | 115 | static int cmos_get_fd_drive_type(int fd0) |
124 | 116 | { |
... | ... | @@ -167,22 +159,8 @@ static void cmos_init(int ram_size, int boot_device, BlockDriverState **hd_table |
167 | 159 | RTCState *s = rtc_state; |
168 | 160 | int val; |
169 | 161 | int fd0, fd1, nb; |
170 | - time_t ti; | |
171 | - struct tm *tm; | |
172 | 162 | int i; |
173 | 163 | |
174 | - /* set the CMOS date */ | |
175 | - time(&ti); | |
176 | - if (rtc_utc) | |
177 | - tm = gmtime(&ti); | |
178 | - else | |
179 | - tm = localtime(&ti); | |
180 | - rtc_set_date(s, tm); | |
181 | - | |
182 | - val = to_bcd(s, (tm->tm_year / 100) + 19); | |
183 | - rtc_set_memory(s, REG_IBM_CENTURY_BYTE, val); | |
184 | - rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val); | |
185 | - | |
186 | 164 | /* various important CMOS locations needed by PC/Bochs bios */ |
187 | 165 | |
188 | 166 | /* memory size */ | ... | ... |