aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hw/mc146818rtc.c13
-rw-r--r--qemu-doc.texi5
-rw-r--r--vl.c39
-rw-r--r--vl.h1
4 files changed, 54 insertions, 4 deletions
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 789ebd3f68..be9c63db20 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -393,11 +393,16 @@ void rtc_set_date_from_host(RTCState *s)
int val;
/* set the CMOS date */
- time(&ti);
- if (rtc_utc)
+ if (rtc_start_date == -1) {
+ time(&ti);
+ if (rtc_utc)
+ tm = gmtime(&ti);
+ else
+ tm = localtime(&ti);
+ } else {
+ ti = rtc_start_date;
tm = gmtime(&ti);
- else
- tm = localtime(&ti);
+ }
rtc_set_date(s, tm);
val = to_bcd(s, (tm->tm_year / 100) + 19);
diff --git a/qemu-doc.texi b/qemu-doc.texi
index 75ba3825f3..3645ba2c1f 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -268,6 +268,11 @@ Set the real time clock to local time (the default is to UTC
time). This option is needed to have correct date in MS-DOS or
Windows.
+@item -startdate date
+Set the initial date of the real time clock. Valid format for
+@var{date} are: @code{now} or @code{2006-06-17T16:01:21} or
+@code{2006-06-17}. The default value is @code{now}.
+
@item -pidfile file
Store the QEMU process PID in @var{file}. It is useful if you launch QEMU
from a script.
diff --git a/vl.c b/vl.c
index 73a22da5c9..c13b1a1f47 100644
--- a/vl.c
+++ b/vl.c
@@ -174,6 +174,7 @@ int nb_nics;
NICInfo nd_table[MAX_NICS];
int vm_running;
int rtc_utc = 1;
+int rtc_start_date = -1; /* -1 means now */
int cirrus_vga_enabled = 1;
int vmsvga_enabled = 0;
#ifdef TARGET_SPARC
@@ -7212,6 +7213,7 @@ enum {
QEMU_OPTION_prom_env,
QEMU_OPTION_old_param,
QEMU_OPTION_clock,
+ QEMU_OPTION_startdate,
};
typedef struct QEMUOption {
@@ -7318,6 +7320,7 @@ const QEMUOption qemu_options[] = {
{ "old-param", 0, QEMU_OPTION_old_param },
#endif
{ "clock", HAS_ARG, QEMU_OPTION_clock },
+ { "startdate", HAS_ARG, QEMU_OPTION_startdate },
{ NULL },
};
@@ -8107,6 +8110,42 @@ int main(int argc, char **argv)
case QEMU_OPTION_clock:
configure_alarms(optarg);
break;
+ case QEMU_OPTION_startdate:
+ {
+ struct tm tm;
+ if (!strcmp(optarg, "now")) {
+ rtc_start_date = -1;
+ } else {
+ if (sscanf(optarg, "%d-%d-%dT%d:%d:%d",
+ &tm.tm_year,
+ &tm.tm_mon,
+ &tm.tm_mday,
+ &tm.tm_hour,
+ &tm.tm_min,
+ &tm.tm_sec) == 6) {
+ /* OK */
+ } else if (sscanf(optarg, "%d-%d-%d",
+ &tm.tm_year,
+ &tm.tm_mon,
+ &tm.tm_mday) == 3) {
+ tm.tm_hour = 0;
+ tm.tm_min = 0;
+ tm.tm_sec = 0;
+ } else {
+ goto date_fail;
+ }
+ tm.tm_year -= 1900;
+ tm.tm_mon--;
+ rtc_start_date = timegm(&tm);
+ if (rtc_start_date == -1) {
+ date_fail:
+ fprintf(stderr, "Invalid date format. Valid format are:\n"
+ "'now' or '2006-06-17T16:01:21' or '2006-06-17'\n");
+ exit(1);
+ }
+ }
+ }
+ break;
}
}
}
diff --git a/vl.h b/vl.h
index 6df63eb205..92ffd3c84c 100644
--- a/vl.h
+++ b/vl.h
@@ -166,6 +166,7 @@ void main_loop_wait(int timeout);
extern int ram_size;
extern int bios_size;
extern int rtc_utc;
+extern int rtc_start_date;
extern int cirrus_vga_enabled;
extern int vmsvga_enabled;
extern int graphic_width;