Skip to contentSkip to conversation

QEMU Patch

Qemu-devel Jim Peterson 1 participant 1 message Sep 3, 2006

lore
Share & tools
lore
#0 lore raw

I'm not quite sure where to send this. I've added a slight modification to
qemu-0.8.2 that allows the user to specify the desired date and time to which to set the real time clock at startup. The patch is attached. The date is parsed using the getdate(3) function, so the DATEMSK environment variable must point to an appropriate file containing the formats to check for.

My need for this comes about as a side effect from the fact that, for some
reason, the "-loadvm" command locks up with an XP image on an Opteron 248 host. (but it does not seem to lock up on an Pentium 4 host)

--Jim

hw/pc.c +9 -4
diff -ruN qemu-0.8.2/hw/pc.c qemu-0.8.2.new/hw/pc.c
@@ -163,11 +163,16 @@
     int i;
 
     /* set the CMOS date */
-    time(&ti);
-    if (rtc_utc)
-        tm = gmtime(&ti);
+    if (rtc_use_time)
+        tm = &rtc_tm;
     else
-        tm = localtime(&ti);
+    {
+        time(&ti);
+        if (rtc_utc)
+            tm = gmtime(&ti);
+        else
+            tm = localtime(&ti);
+    }
     rtc_set_date(s, tm);
 
     val = to_bcd(s, (tm->tm_year / 100) + 19);
vl.c +16 -0
diff -ruN qemu-0.8.2/vl.c qemu-0.8.2.new/vl.c
@@ -128,6 +128,8 @@
 QEMUTimer *gui_timer;
 int vm_running;
 int rtc_utc = 1;
+int rtc_use_time = 0;
+struct tm rtc_tm;
 int cirrus_vga_enabled = 1;
 #ifdef TARGET_SPARC
 int graphic_width = 1024;
@@ -5150,6 +5152,7 @@
            "                use -soundhw all to enable all of them\n"
 #endif
            "-localtime      set the real time clock to local time [default=utc]\n"
+           "-date [date]    set the real time clock to given date using getdate(3)\n"
            "-full-screen    start in full screen\n"
 #ifdef TARGET_I386
            "-win2k-hack     use it when installing Windows 2000 to avoid a disk full bug\n"
@@ -5285,6 +5288,7 @@
     QEMU_OPTION_no_code_copy,
     QEMU_OPTION_k,
     QEMU_OPTION_localtime,
+    QEMU_OPTION_setdate,
     QEMU_OPTION_cirrusvga,
     QEMU_OPTION_g,
     QEMU_OPTION_std_vga,
@@ -5362,6 +5366,7 @@
     { "g", 1, QEMU_OPTION_g },
 #endif
     { "localtime", 0, QEMU_OPTION_localtime },
+    { "date", 1, QEMU_OPTION_setdate },
     { "std-vga", 0, QEMU_OPTION_std_vga },
     { "monitor", 1, QEMU_OPTION_monitor },
     { "serial", 1, QEMU_OPTION_serial },
@@ -5607,6 +5612,7 @@
     QEMUMachine *machine;
     char usb_devices[MAX_USB_CMDLINE][128];
     int usb_devices_index;
+    struct tm* tmp_tm;
 
     LIST_INIT (&vm_change_state_head);
 #ifndef _WIN32
@@ -5907,6 +5913,16 @@
             case QEMU_OPTION_localtime:
                 rtc_utc = 0;
                 break;
+            case QEMU_OPTION_setdate:
+                rtc_use_time = 1;
+		tmp_tm = getdate(optarg);
+                if (!tmp_tm)
+		{
+        		fprintf (stderr, "qemu: bad date format '%s'\n",optarg);
+			exit(1);
+		}
+		memcpy(&rtc_tm,tmp_tm,sizeof(rtc_tm));
+                break;
             case QEMU_OPTION_cirrusvga:
                 cirrus_vga_enabled = 1;
                 break;
vl.h +2 -0
diff -ruN qemu-0.8.2/vl.h qemu-0.8.2.new/vl.h
@@ -142,6 +142,8 @@
 extern int ram_size;
 extern int bios_size;
 extern int rtc_utc;
+extern int rtc_use_time;
+extern struct tm rtc_tm;
 extern int cirrus_vga_enabled;
 extern int graphic_width;
 extern int graphic_height;