+ s->buf_data[RTC_DAY_OF_WEEK] = to_bcd(s, tm->tm_wday);
+ s->buf_data[RTC_DAY_OF_MONTH] = to_bcd(s, tm->tm_mday);
+ s->buf_data[RTC_MONTH] = to_bcd(s, tm->tm_mon + 1);
+ s->buf_data[RTC_YEAR] = to_bcd(s, tm->tm_year % 100);
+}
+
+static void rtc_copy_date(RTCState *s)
+{
+ s->cmos_data[RTC_SECONDS] = s->buf_data[RTC_SECONDS];
+ s->cmos_data[RTC_MINUTES] = s->buf_data[RTC_MINUTES];
+ s->cmos_data[RTC_HOURS] = s->buf_data[RTC_HOURS];
+ s->cmos_data[RTC_DAY_OF_WEEK] = s->buf_data[RTC_DAY_OF_WEEK];
+ s->cmos_data[RTC_DAY_OF_MONTH] = s->buf_data[RTC_DAY_OF_MONTH];
+ s->cmos_data[RTC_MONTH] = s->buf_data[RTC_MONTH];
+ s->cmos_data[RTC_YEAR] = s->buf_data[RTC_YEAR];
+}
+
+void rtc_set_memory(RTCState *s, int addr, int val)
+{
+ if (addr >= 0 && addr <= 127)
+ s->cmos_data[addr] = val;
+}
+
+void rtc_set_date(RTCState *s, const struct tm *tm)
+{
+ s->current_time = mktime((struct tm *)tm);
+ rtc_set_date_buf(s, tm);
+ rtc_copy_date(s);
+}
+
+static void rtc_save(QEMUFile *f, void *opaque)
+{
+ RTCState *s = opaque;
+
+ qemu_put_buffer(f, s->cmos_data, 128);
+ qemu_put_8s(f, &s->cmos_index);
+ qemu_put_be32s(f, &s->current_time);
+ qemu_put_buffer(f, s->buf_data, 10);
+
+ qemu_put_timer(f, s->periodic_timer);
+ qemu_put_be64s(f, &s->next_periodic_time);
+
+ qemu_put_be64s(f, &s->next_second_time);
+ qemu_put_timer(f, s->second_timer);
+ qemu_put_timer(f, s->second_timer2);