qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] -serial option for 0.6.0


From: Rusty Russell
Subject: [Qemu-devel] [PATCH] -serial option for 0.6.0
Date: Wed, 18 Aug 2004 21:07:50 +1000

I had reason recently to use a tty as a serial console, so I added the
"-serial" option.  This also allows you to cleanly output the serial to
a file while still having a console on stdin.

Ideally it would allow use of a real serial port in future.

Thanks,
Rusty.
diff -ur qemu-0.6.0/hw/pc.c qemu-0.6.0-serial/hw/pc.c
--- qemu-0.6.0/hw/pc.c  2004-07-11 04:20:09.000000000 +1000
+++ qemu-0.6.0-serial/hw/pc.c   2004-08-18 14:43:35.000000000 +1000
@@ -321,7 +321,7 @@
 void pc_init(int ram_size, int vga_ram_size, int boot_device,
              DisplayState *ds, const char **fd_filename, int snapshot,
              const char *kernel_filename, const char *kernel_cmdline,
-             const char *initrd_filename)
+             const char *initrd_filename, const char *serial_filename)
 {
     char buf[1024];
     int ret, linux_boot, initrd_size, i, nb_nics1, fd;
@@ -471,7 +471,7 @@
     pic_init();
     pit = pit_init(0x40, 0);
 
-    fd = serial_open_device();
+    fd = serial_open_device(serial_filename);
     serial_init(0x3f8, 4, fd);
 
     if (pci_enabled) {
Only in qemu-0.6.0-serial/hw: pc.c.~1~
diff -ur qemu-0.6.0/hw/ppc.c qemu-0.6.0-serial/hw/ppc.c
--- qemu-0.6.0/hw/ppc.c 2004-07-11 04:20:09.000000000 +1000
+++ qemu-0.6.0-serial/hw/ppc.c  2004-08-18 14:44:08.000000000 +1000
@@ -446,16 +446,16 @@
 void ppc_init (int ram_size, int vga_ram_size, int boot_device,
               DisplayState *ds, const char **fd_filename, int snapshot,
               const char *kernel_filename, const char *kernel_cmdline,
-              const char *initrd_filename)
+              const char *initrd_filename, const char *serial_filename)
 {
     if (prep_enabled) {
         ppc_prep_init(ram_size, vga_ram_size, boot_device, ds, fd_filename,
                       snapshot, kernel_filename, kernel_cmdline,
-                      initrd_filename);
+                      initrd_filename, serial_filename);
     } else {
         ppc_chrp_init(ram_size, vga_ram_size, boot_device, ds, fd_filename,
                       snapshot, kernel_filename, kernel_cmdline,
-                      initrd_filename);
+                      initrd_filename, serial_filename);
     }
     /* Special port to get debug messages from Open-Firmware */
     register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
diff -ur qemu-0.6.0/hw/ppc_chrp.c qemu-0.6.0-serial/hw/ppc_chrp.c
--- qemu-0.6.0/hw/ppc_chrp.c    2004-07-11 04:20:09.000000000 +1000
+++ qemu-0.6.0-serial/hw/ppc_chrp.c     2004-08-18 14:44:34.000000000 +1000
@@ -120,7 +120,7 @@
 void ppc_chrp_init(int ram_size, int vga_ram_size, int boot_device,
                   DisplayState *ds, const char **fd_filename, int snapshot,
                   const char *kernel_filename, const char *kernel_cmdline,
-                  const char *initrd_filename)
+                  const char *initrd_filename, const char *serial_filename)
 {
     char buf[1024];
     openpic_t *openpic;
@@ -200,7 +200,7 @@
     pic_init();
 
     /* XXX: use Mac Serial port */
-    fd = serial_open_device();
+    fd = serial_open_device(serial_filename);
     serial_init(0x3f8, 4, fd);
 
     for(i = 0; i < nb_nics; i++) {
Only in qemu-0.6.0-serial/hw: ppc_chrp.c.~1~
diff -ur qemu-0.6.0/hw/ppc_prep.c qemu-0.6.0-serial/hw/ppc_prep.c
--- qemu-0.6.0/hw/ppc_prep.c    2004-07-11 04:20:09.000000000 +1000
+++ qemu-0.6.0-serial/hw/ppc_prep.c     2004-08-18 14:44:50.000000000 +1000
@@ -410,7 +410,7 @@
 void ppc_prep_init(int ram_size, int vga_ram_size, int boot_device,
                   DisplayState *ds, const char **fd_filename, int snapshot,
                   const char *kernel_filename, const char *kernel_cmdline,
-                  const char *initrd_filename)
+                  const char *initrd_filename, const char *serial_filename)
 {
     char buf[1024];
     m48t59_t *nvram;
@@ -492,7 +492,7 @@
     pic_init();
     //    pit = pit_init(0x40, 0);
 
-    fd = serial_open_device();
+    fd = serial_open_device(serial_filename);
     serial_init(0x3f8, 4, fd);
     nb_nics1 = nb_nics;
     if (nb_nics1 > NE2000_NB_MAX)
Only in qemu-0.6.0-serial/hw: ppc_prep.c.~1~
diff -ur qemu-0.6.0/hw/serial.c qemu-0.6.0-serial/hw/serial.c
--- qemu-0.6.0/hw/serial.c      2004-07-11 04:20:09.000000000 +1000
+++ qemu-0.6.0-serial/hw/serial.c       2004-08-18 21:01:33.000000000 +1000
@@ -125,9 +125,11 @@
 
             if (s->out_fd >= 0) {
                 ch = val;
+               /* Most likely nonblocking (we do that to stdin), so
+                * we spin, unless it's really dead. */
                 do {
                     ret = write(s->out_fd, &ch, 1);
-                } while (ret != 1);
+                } while (ret == 0 || (ret < 0 && errno == EAGAIN));
             }
             s->thr_ipending = 1;
             s->lsr |= UART_LSR_THRE;
diff -ur qemu-0.6.0/qemu-doc.texi qemu-0.6.0-serial/qemu-doc.texi
--- qemu-0.6.0/qemu-doc.texi    2004-07-11 04:20:09.000000000 +1000
+++ qemu-0.6.0-serial/qemu-doc.texi     2004-08-18 15:07:39.000000000 +1000
@@ -178,6 +178,9 @@
 @item -initrd file
 Use @var{file} as initial ram disk.
 
address@hidden -serial file
+Use @var{file} as serial device: create it for output if neccessary.
+
 @item -nographic
 
 Normally, QEMU uses SDL to display the VGA output. With this option,
diff -ur qemu-0.6.0/vl.c qemu-0.6.0-serial/vl.c
--- qemu-0.6.0/vl.c     2004-07-11 04:20:09.000000000 +1000
+++ qemu-0.6.0-serial/vl.c      2004-08-18 21:03:29.000000000 +1000
@@ -953,36 +953,30 @@
 
 #ifdef _WIN32
 
-int serial_open_device(void)
+int serial_open_device(const char *serial_filename)
 {
     return -1;
 }
 
 #else
 
-int serial_open_device(void)
+int serial_open_device(const char *serial_filename)
 {
+    int fd = -1;
+
+    if (serial_filename) {
+       fd = open(serial_filename, O_RDWR|O_CREAT, 0666);
+       if (fd < 0)
+           fprintf(stderr, "Failed to open serial port %s\n",
+                   serial_filename);
+    }
+
     if (serial_console == NULL && nographic) {
         /* use console for serial port */
-        return 0;
-    } else {
-#if 0
-        char slave_name[1024];
-        int master_fd, slave_fd;
-        
-        /* Not satisfying */
-        if (openpty(&master_fd, &slave_fd, slave_name, NULL, NULL) < 0) {
-            fprintf(stderr, "warning: could not create pseudo terminal for 
serial port\n");
-            return -1;
-        }
-        fprintf(stderr, "Serial port redirected to %s\n", slave_name);
-        return master_fd;
-#else
-        return -1;
-#endif
+        fd = 0;
     }
+    return fd;
 }
-
 #endif
 
 /***********************************************************/
@@ -2169,6 +2163,7 @@
     QEMU_OPTION_kernel,
     QEMU_OPTION_append,
     QEMU_OPTION_initrd,
+    QEMU_OPTION_serial,
 
     QEMU_OPTION_S,
     QEMU_OPTION_s,
@@ -2220,6 +2215,7 @@
     { "kernel", HAS_ARG, QEMU_OPTION_kernel },
     { "append", HAS_ARG, QEMU_OPTION_append },
     { "initrd", HAS_ARG, QEMU_OPTION_initrd },
+    { "serial", HAS_ARG, QEMU_OPTION_serial },
 
     { "S", 0, QEMU_OPTION_S },
     { "s", 0, QEMU_OPTION_s },
@@ -2263,7 +2259,7 @@
     int i, has_cdrom;
     int snapshot, linux_boot;
     CPUState *env;
-    const char *initrd_filename;
+    const char *initrd_filename, *serial_filename;
     const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
@@ -2279,6 +2275,7 @@
     mallopt(M_MMAP_THRESHOLD, 4096 * 1024);
 #endif
     initrd_filename = NULL;
+    serial_filename = NULL;
     for(i = 0; i < MAX_FD; i++)
         fd_filename[i] = NULL;
     for(i = 0; i < MAX_DISKS; i++)
@@ -2346,6 +2343,9 @@
             case QEMU_OPTION_initrd:
                 initrd_filename = optarg;
                 break;
+            case QEMU_OPTION_serial:
+                serial_filename = optarg;
+                break;
             case QEMU_OPTION_hda:
                 hd_filename[0] = optarg;
                 break;
@@ -2798,11 +2798,11 @@
 #if defined(TARGET_I386)
     pc_init(ram_size, vga_ram_size, boot_device,
             ds, fd_filename, snapshot,
-            kernel_filename, kernel_cmdline, initrd_filename);
+            kernel_filename, kernel_cmdline, initrd_filename, serial_filename);
 #elif defined(TARGET_PPC)
     ppc_init(ram_size, vga_ram_size, boot_device,
             ds, fd_filename, snapshot,
-            kernel_filename, kernel_cmdline, initrd_filename);
+            kernel_filename, kernel_cmdline, initrd_filename, serial_filename);
 #endif
 
     /* launched after the device init so that it can display or not a
diff -ur qemu-0.6.0/vl.h qemu-0.6.0-serial/vl.h
--- qemu-0.6.0/vl.h     2004-07-11 04:20:09.000000000 +1000
+++ qemu-0.6.0-serial/vl.h      2004-08-18 14:45:35.000000000 +1000
@@ -216,7 +216,7 @@
 void pstrcpy(char *buf, int buf_size, const char *str);
 char *pstrcat(char *buf, int buf_size, const char *s);
 
-int serial_open_device(void);
+int serial_open_device(const char *serial_filename);
 
 extern int vm_running;
 
@@ -675,21 +675,21 @@
 void pc_init(int ram_size, int vga_ram_size, int boot_device,
              DisplayState *ds, const char **fd_filename, int snapshot,
              const char *kernel_filename, const char *kernel_cmdline,
-             const char *initrd_filename);
+             const char *initrd_filename, const char *serial_filename);
 
 /* ppc.c */
 void ppc_init (int ram_size, int vga_ram_size, int boot_device,
               DisplayState *ds, const char **fd_filename, int snapshot,
               const char *kernel_filename, const char *kernel_cmdline,
-              const char *initrd_filename);
+              const char *initrd_filename, const char *serial_filename);
 void ppc_prep_init (int ram_size, int vga_ram_size, int boot_device,
                    DisplayState *ds, const char **fd_filename, int snapshot,
                    const char *kernel_filename, const char *kernel_cmdline,
-                   const char *initrd_filename);
+                   const char *initrd_filename, const char *serial_filename);
 void ppc_chrp_init(int ram_size, int vga_ram_size, int boot_device,
                   DisplayState *ds, const char **fd_filename, int snapshot,
                   const char *kernel_filename, const char *kernel_cmdline,
-                  const char *initrd_filename);
+                  const char *initrd_filename, const char *serial_filename);
 #ifdef TARGET_PPC
 ppc_tb_t *cpu_ppc_tb_init (CPUState *env, uint32_t freq);
 #endif

-- 
Anyone who quotes me in their signature is an idiot -- Rusty Russell





reply via email to

[Prev in Thread] Current Thread [Next in Thread]