Skip to contentSkip to conversation

patch to set rtc in format chosen by user

Qemu-devel John Stalker 1 participant 1 message Apr 14, 2007

lore
Share & tools
lore
#0 lore raw

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 renamed from qemu-doc.texi.orig +8 -0
@@ -297,6 +297,14 @@
 qemu -soundhw ?
 @end example
 
+@item -t time
+Set the real time clock to @var{time}.
+
+@item -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
mc146818rtc.c renamed from mc146818rtc.c.orig +8 -5
@@ -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 renamed from vl.c.orig +19 -0
@@ -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 renamed from vl.h.orig +4 -0
@@ -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;
Signature · 5 lines
John Stalker
School of Mathematics
Trinity College Dublin
tel +353 1 896 1983
fax +353 1 896 2282