I find it useful occasionally to play with the guests' notion of time, for example to see if a program copes sanely with daylight savings time transitions. The following patches allow this, at least on FreeBSD, which is the only system I tested them on. Share and enjoy.
John --- qemu-doc.texi.orig Mon Feb 5 23:01:54 2007 +++ qemu-doc.texi Sat Apr 7 03:44:06 2007 @@ -297,6 +297,14 @@ qemu -soundhw ? @end example [EMAIL PROTECTED] -t time +Set the real time clock to @var{time}. + [EMAIL PROTECTED] -tfmt format +Format for the argument to -t as specified in strptime(3). +Defaults to "%c", i.e. the output format of date(1) in the +current locale. + @item -localtime 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 --- hw/mc146818rtc.c.orig Fri Apr 6 22:31:58 2007 +++ hw/mc146818rtc.c Sat Apr 7 02:57:04 2007 @@ -391,11 +391,14 @@ int val; /* set the CMOS date */ - time(&ti); - if (rtc_utc) - tm = gmtime(&ti); - else - tm = localtime(&ti); + if (rtc_given) { + time(&ti); + tm = localtime(&ti); + strptime(boot_time, tfmt, tm); + } else { + time(&ti); + tm = ( rtc_utc ? gmtime(&ti) : localtime(&ti) ) ; + } rtc_set_date(s, tm); val = to_bcd(s, (tm->tm_year / 100) + 19); --- vl.c.orig Fri Apr 6 22:37:53 2007 +++ vl.c Sat Apr 7 03:35:42 2007 @@ -144,6 +144,9 @@ NICInfo nd_table[MAX_NICS]; QEMUTimer *gui_timer; int vm_running; +int rtc_given = 0; +const char *tfmt = "%c"; +const char *boot_time = NULL; int rtc_utc = 1; int cirrus_vga_enabled = 1; #ifdef TARGET_SPARC @@ -6190,6 +6193,11 @@ " use -soundhw ? to get the list of supported cards\n" " use -soundhw all to enable all of them\n" #endif + "-t time set the CMOS clock to 'time' at boot\n" + "-tfmt format format for the argument to -t as specified in strptime(3)\n" + " defaults to \"%%c\", i.e. the output format of date(1) in the\n" + " current locale\n" + "-localtime set the real time clock to local time [default=utc]\n" "-full-screen start in full screen\n" #ifdef TARGET_I386 @@ -6331,6 +6339,8 @@ QEMU_OPTION_L, QEMU_OPTION_no_code_copy, QEMU_OPTION_k, + QEMU_OPTION_t, + QEMU_OPTION_tfmt, QEMU_OPTION_localtime, QEMU_OPTION_cirrusvga, QEMU_OPTION_g, @@ -6414,6 +6424,8 @@ #if defined(TARGET_PPC) || defined(TARGET_SPARC) { "g", 1, QEMU_OPTION_g }, #endif + { "t", HAS_ARG, QEMU_OPTION_t }, + { "tfmt", HAS_ARG, QEMU_OPTION_tfmt }, { "localtime", 0, QEMU_OPTION_localtime }, { "std-vga", 0, QEMU_OPTION_std_vga }, { "monitor", 1, QEMU_OPTION_monitor }, @@ -6972,6 +6984,13 @@ case QEMU_OPTION_k: keyboard_layout = optarg; break; + case QEMU_OPTION_t: + boot_time = optarg; + rtc_given = 1; + break; + case QEMU_OPTION_tfmt: + tfmt = optarg; + break; case QEMU_OPTION_localtime: rtc_utc = 0; break; --- vl.h.orig Fri Apr 6 22:51:01 2007 +++ vl.h Sat Apr 7 01:35:27 2007 @@ -119,6 +119,9 @@ extern const char *bios_dir; +extern const char *boot_time; +extern const char *tfmt; + extern int vm_running; typedef struct vm_change_state_entry VMChangeStateEntry; @@ -152,6 +155,7 @@ extern int ram_size; extern int bios_size; +extern int rtc_given; extern int rtc_utc; extern int cirrus_vga_enabled; extern int graphic_width; -- John Stalker School of Mathematics Trinity College Dublin tel +353 1 896 1983 fax +353 1 896 2282