Skip to contentSkip to conversation

qemu curses driver

Qemu-devel andrzej zaborowski 2 participants 7 messages Dec 10, 2005 – Jan 10, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

Hello qemu,
I made this simple curses/ncurses interface for qemu. If anyone is interested in using it, I attach a patch, relative to CVS version from some two days ago. I think it is also safe to apply to the CVS, if you think this is a useful addition (which I think it is). I tried to make it rather portable, but I've only been able to test it on Linux and FreeBSD i386 (only ncurses) so I suppose it works on all unix, but I have no idea how ms windows would deal with it. There's a curses implementation for windows called PDcurses and it should be fine, but if the "configure" doesn't detect any curses library on the system, it will just compile without the curses driver, like if it wasn't there.

About how it works:
It adds a "-curses" command line switch which will suppress the SDL driver (just like "-nographics"). When qemu is running with "-curses" it displays everything in the current terminal, be it native console, linux framebuffer, xterm, or running over ssh, leaving the task of rendering characters to the terminal. This results in much less speed overhead compared to the SDL driver (this is important on my slow machine). This works as long as the virtual graphics adapter is in text-mode. When it switches to graphics, qemu displays something like "1024 x 768 Graphics mode" in the middle of the screen, until the virtual machine goes back to a text-mode. Similarly works the VGA Blank mode.
The qemu consoles work just like with the SDL interface, except you switch them with Alt+Number instead of Ctrl+Alt+Number because ncurses doesn't detect Ctrl and Alt keys together. So usually the virtual machine screen is at Alt+1, the qemu console at Alt+2, serial console at Alt+3 and parallel console at Alt+4.
Resizing the terminal (like when resizing the xterm window) is handled (at least with ncurses, this may not be implemented in other curses libraries). The virtual machine won't notice any resizing, only thing that changes is the portion of the screen displayed in the terminal. Normal text-mode character attributes are handled.
I think these are the most important things to mention.

Tell me if anything needs to be changed in the patch, then I will send corrected versions. I hope this is useful,
greetings,
Andrzej Zaborowski
--
balrog 2oo5

Dear Outlook users: Please remove me from your address books
http://www.newsforge.com/article.pl?sid=03/08/21/143258

Makefile.target +9 -1
diff -Naur qemu/Makefile.target qemu-ncurses/Makefile.target
@@ -341,6 +341,11 @@
 ifdef CONFIG_SDL
 VL_OBJS+=sdl.o
 endif
+ifdef CONFIG_CURSES
+ifeq ($(TARGET_BASE_ARCH), i386)
+VL_OBJS+=curses.o
+endif
+endif
 ifdef CONFIG_COCOA
 VL_OBJS+=cocoa.o
 COCOA_LIBS=-F/System/Library/Frameworks -framework Cocoa -framework IOKit
@@ -383,7 +388,7 @@
 endif
 
 $(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
-	$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS)
+	$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(VL_LIBS)
 
 cocoa.o: cocoa.m
 	$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
@@ -394,6 +399,9 @@
 sdlaudio.o: sdlaudio.c
 	$(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
 
+curses.o: curses.c
+	$(CC) $(CFLAGS) $(DEFINES) $(CURSES_CFLAGS) -c -o $@ $<
+
 depend: $(SRCS)
 	$(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
 
configure +32 -1
diff -Naur qemu/configure qemu-ncurses/configure
@@ -181,6 +181,8 @@
   ;;
   --enable-dsound) dsound="yes"
   ;;
+  --disable-curses) curses="no"
+  ;;
   --enable-fmod) fmod="yes"
   ;;
   --fmod-lib=*) fmod_lib=${opt#--fmod-lib=}
@@ -348,6 +350,24 @@
 fi # cross compilation
 fi # -z $sdl
 
+##########################################
+# curses probe
+
+if test -z "$curses" ; then
+
+curses=no
+
+cat > $TMPC << EOF
+#include <curses.h>
+int main( void ) { return curses_version (); }
+EOF
+
+if $cc -o $TMPE -lcurses $TMPC 2> /dev/null ; then
+curses=yes
+fi
+
+fi # -z $curses
+
 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
 cat << EOF
 
@@ -469,6 +489,7 @@
 if test "$sdl" != "no" ; then
     echo "SDL static link   $sdl_static"
 fi
+echo "curses support    $curses"
 echo "mingw32 support   $mingw32"
 echo "Adlib support     $adlib"
 echo "CoreAudio support $coreaudio"
@@ -680,7 +701,8 @@
         -a "$sdl" = "no" -a "$cocoa" = "no" ; then
     echo "ERROR: QEMU requires SDL or Cocoa for graphical output"
     echo "To build QEMU with graphical output configure with --disable-gfx-check"
-    echo "Note that this will disable all output from the virtual graphics card."
+    echo "Note that this will disable all output from the virtual graphics card"
+    echo "except for the curses interface."
     exit 1;
 fi
 
@@ -798,6 +820,15 @@
     echo "CONFIG_COCOA=yes" >> $config_mak
 fi
 
+if test "$curses" = "yes" ; then
+    if test "$target_cpu" = "i386" ; then
+        echo "#define CONFIG_CURSES 1" >> $config_h
+        echo "CONFIG_CURSES=yes" >> $config_mak
+        echo "CURSES_LIBS=-lcurses" >> $config_mak
+        echo "CURSES_CFLAGS=" >> $config_mak
+    fi
+fi
+
 done # for target in $targets
 
 # build tree in object directory if source path is different from current one
console.c +6 -42

61 lines not on this page · raw message

console.h +70 -0

70 lines not on this page · raw message

curses.c +277 -0

277 lines not on this page · raw message

curses_keys.h +243 -0

243 lines not on this page · raw message

hw/vga.c +165 -3

189 lines not on this page · raw message

vl.c +26 -2
diff -Naur qemu/vl.c qemu-ncurses/vl.c
@@ -115,6 +115,7 @@
 int bios_size;
 static DisplayState display_state;
 int nographic;
+int curses;
 const char* keyboard_layout = NULL;
 int64_t ticks_per_sec;
 int boot_device = 'c';
@@ -3840,6 +3841,9 @@
            "-hdachs c,h,s[,t]  force hard disk 0 physical geometry and the optional BIOS\n"
            "                translation (t=none or lba) (usually qemu can guess them)\n"
            "-L path         set the directory for the BIOS and VGA BIOS\n"
+#ifdef CONFIG_CURSES
+           "-curses         use a curses/ncurses interface instead of SDL\n"
+#endif
 #ifdef USE_KQEMU
            "-no-kqemu       disable KQEMU kernel module usage\n"
 #endif
@@ -3934,6 +3938,7 @@
     QEMU_OPTION_usb,
     QEMU_OPTION_usbdevice,
     QEMU_OPTION_smp,
+    QEMU_OPTION_curses,
 };
 
 typedef struct QEMUOption {
@@ -3984,6 +3989,9 @@
     { "hdachs", HAS_ARG, QEMU_OPTION_hdachs },
     { "L", HAS_ARG, QEMU_OPTION_L },
     { "no-code-copy", 0, QEMU_OPTION_no_code_copy },
+#ifdef CONFIG_CURSES
+    { "curses", 0, QEMU_OPTION_curses },
+#endif
 #ifdef USE_KQEMU
     { "no-kqemu", 0, QEMU_OPTION_no_kqemu },
 #endif
@@ -4202,6 +4210,7 @@
 #endif
     snapshot = 0;
     nographic = 0;
+    curses = 0;
     kernel_filename = NULL;
     kernel_cmdline = "";
 #ifdef TARGET_PPC
@@ -4335,7 +4344,16 @@
                 pstrcpy(monitor_device, sizeof(monitor_device), "stdio");
                 pstrcpy(serial_devices[0], sizeof(serial_devices[0]), "stdio");
                 nographic = 1;
+                curses = 0;
+                break;
+#ifdef CONFIG_CURSES
+            case QEMU_OPTION_curses:
+                pstrcpy(monitor_device, sizeof(monitor_device), "vc");
+                pstrcpy(serial_devices[0], sizeof(serial_devices[0]), "vc");
+                curses = 1;
+		nographic = 0;
                 break;
+#endif
             case QEMU_OPTION_kernel:
                 kernel_filename = optarg;
                 break;
@@ -4714,7 +4732,13 @@
     /* terminal init */
     if (nographic) {
         dumb_display_init(ds);
-    } else {
+    } else
+#if defined(CONFIG_CURSES)
+    if (curses) {
+        curses_display_init(ds, full_screen);
+    } else
+#endif
+    {
 #if defined(CONFIG_SDL)
         sdl_display_init(ds, full_screen);
 #elif defined(CONFIG_COCOA)
@@ -4725,7 +4749,7 @@
     }
 
     vga_console = graphic_console_init(ds);
-    
+
     monitor_hd = qemu_chr_open(monitor_device);
     if (!monitor_hd) {
         fprintf(stderr, "qemu: could not open monitor device '%s'\n", monitor_device);
vl.h +6 -0
diff -Naur qemu/vl.h qemu-ncurses/vl.h
@@ -265,6 +265,7 @@
 int is_active_console(TextConsole *s);
 CharDriverState *text_console_init(DisplayState *ds);
 void console_select(unsigned int index);
+TextConsole *get_active_console();
 
 /* serial ports */
 
@@ -652,6 +653,8 @@
 void vga_update_display(void);
 void vga_invalidate_display(void);
 void vga_screen_dump(const char *filename);
+void vga_update_text(uint8_t *chardata, void (*dpy_cursor)
+                      (DisplayState *s, int x, int y));
 
 /* cirrus_vga.c */
 void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, 
@@ -665,6 +668,9 @@
 /* cocoa.m */
 void cocoa_display_init(DisplayState *ds, int full_screen);
 
+/* curses.c */
+void curses_display_init(DisplayState *ds, int full_screen);
+
 /* ide.c */
 #define MAX_DISKS 4
 
#1 lore raw

Hi,

Quoted 10 lines · andrzej zaborowski

I made this simple curses/ncurses interface for qemu. If anyone is interested in using it, I attach a patch, relative to CVS version from some two days ago. I think it is also safe to apply to the CVS, if you think this is a useful addition (which I think it is). I tried to make it rather portable, but I've only been able to test it on Linux and FreeBSD i386 (only ncurses) so I suppose it works on all unix, but I have no idea how ms windows would deal with it. There's a curses implementation for windows called PDcurses and it should be fine, but if the "configure" doesn't detect any curses library on the system, it will just compile without the curses driver, like if it wasn't there.

Wow. That's cool! I just tested it and it works great!

A few questions:

- why do you enable it only if the target cpu is i386?
- is it possible to scroll inside the window?
(I started qemu in a 80x24 window, but the guest expected 80x25, so I
could not see the last line)
- any reason the Escape key does not work?

Quoted 5 lines

The qemu consoles work just like with the SDL interface, except you switch them with Alt+Number instead of Ctrl+Alt+Number because ncurses doesn't detect Ctrl and Alt keys together. So usually the virtual machine screen is at Alt+1, the qemu console at Alt+2, serial console at Alt+3 and parallel console at Alt+4.

Is it not possible to have the same key binding?

Quoted 3 lines

Resizing the terminal (like when resizing the xterm window) is handled (at least with ncurses, this may not be implemented in other curses libraries).

I have ncurses installed and it did not work. Have to investigate.

Quoted 1 line

I hope this is useful,

It sure is! Finally I can run qemu instances inside screen!

Ciao,
Dscho

#2 lore raw

Hi,
thanks for feedback!

Quoted 4 lines · Johannes Schindelin

A few questions:

- why do you enable it only if the target cpu is i386?

I didn't have any software that runs on different architectures to test, and I remember that there were linking problems for sparc (I think) because it didn't use the VGA emulator, which the curses driver depends on (SDL driver depends on it too). I'm going to look at it closer and enable curses for all targets that might work with curses.

Quoted 3 lines

- is it possible to scroll inside the window?
(I started qemu in a 80x24 window, but the guest expected 80x25, so I
could not see the last line)

I'm afraid the only way to see the last line in this case is by enlarging the window (this shouldn't need restarting qemu, also most terminal emulators and GNU screen support that). Native consoles usually use 80x25 anyway so I didn't find use for scrolling inside the guest screen, and I assumed working with the virtual machine would be a bit difficult when you're only seeing a fragment of the screen.

Quoted 1 line

- any reason the Escape key does not work?

Hm. I checked it in several terminal emulators and it always worked fine. Each time I ran the "Learn Keys" option in Midnight Commander inside the guest system and it would correctly recognise all keys except F19 and F20 (which I fixed now). I also fixed a small issue with the Enter key.
Note that on Linux you sometimes have to wait half a second before the system reacts to Escape (only the guest system, I disabled this delay on the host). Also note that leaving the Midnight Commander's builtin viewer/editor requires double Escape.

Quoted 7 lines
Quoted 5 lines

The qemu consoles work just like with the SDL interface, except you switch them with Alt+Number instead of Ctrl+Alt+Number because ncurses doesn't detect Ctrl and Alt keys together. So usually the virtual machine screen is at Alt+1, the qemu console at Alt+2, serial console at Alt+3 and parallel console at Alt+4.

Is it not possible to have the same key binding?

Unfortunately terminals don't receive any input when you're pressing both Control and Alt and some other key, so I'm afraid it is not possible.

Quoted 5 lines
Quoted 3 lines

Resizing the terminal (like when resizing the xterm window) is handled (at least with ncurses, this may not be implemented in other curses libraries).

I have ncurses installed and it did not work. Have to investigate.

I was trying to find out when ncurses registers its own handler for SIGWINCH (the signal that's sent when the terminal is resized) and when it doesn't do that, and I couldn't because the documentation is vague about it (it only says "ncurses can be configured to provide a handler for SIGWINCH" in all places in the documentation). As it worked fine on my system, I decided I would leave all signals handling tasks to ncurses to avoid #ifdefs excluding the signals handling code when compiling for Ms Windows.
Now I found out that it is a compile time switch for the "configure" script of ncurses that controls this behavior. So I'm going to add my own SIGWINCH handler to make sure it works the same way with all versions of ncurses in all cases. Hopefully I will send a corrected patch tomorrow.

Thanks for the positive opinion and for testing it, your remarks turned out very useful. I will be glad if you can also see how the corrected version works when I get it ready.
Cheers
--
balrog 2oo5

Dear Outlook users: Please remove me from your address books
http://www.newsforge.com/article.pl?sid=03/08/21/143258

#3 lore raw
In reply to andrzej zaborowski

Hi there,
This is a slightly corrected version of the previous patch. The changes are:

- fixed the terminal resize event handling, now it should work regardless of the curses library implementation,
- some keyboard input details,
- and changed the Makefile to compile the curses driver for all targets that use the VGA emulator (from hw/vga.c) - that means all targets except Sparc and ARM - I think it is also possible to make this work for Sparc and ARM but I don't know anything about these architectures and wouldn't have any way to perform any testing and I also don't know how useful this would be.

Any comments are welcome, especially if someone encounters any further bugs or malfunctioning of the interface. What do you think about including the curses interface in QEMU?

cheers,
Andrzej Zaborowski
--
balrog 2oo5

Dear Outlook users: Please remove me from your address books
http://www.newsforge.com/article.pl?sid=03/08/21/143258

Makefile.target +7 -1
diff -Naur qemu/Makefile.target qemu-curses/Makefile.target
@@ -341,6 +341,9 @@
 ifdef CONFIG_SDL
 VL_OBJS+=sdl.o
 endif
+ifdef CONFIG_CURSES
+VL_OBJS+=curses.o
+endif
 ifdef CONFIG_COCOA
 VL_OBJS+=cocoa.o
 COCOA_LIBS=-F/System/Library/Frameworks -framework Cocoa -framework IOKit
@@ -383,7 +386,7 @@
 endif
 
 $(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
-	$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS)
+	$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(VL_LIBS)
 
 cocoa.o: cocoa.m
 	$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
@@ -394,6 +397,9 @@
 sdlaudio.o: sdlaudio.c
 	$(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
 
+curses.o: curses.c
+	$(CC) $(CFLAGS) $(DEFINES) $(CURSES_CFLAGS) -c -o $@ $<
+
 depend: $(SRCS)
 	$(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
 
configure +32 -1
diff -Naur qemu/configure qemu-curses/configure
@@ -181,6 +181,8 @@
   ;;
   --enable-dsound) dsound="yes"
   ;;
+  --disable-curses) curses="no"
+  ;;
   --enable-fmod) fmod="yes"
   ;;
   --fmod-lib=*) fmod_lib=${opt#--fmod-lib=}
@@ -348,6 +350,24 @@
 fi # cross compilation
 fi # -z $sdl
 
+##########################################
+# curses probe
+
+if test -z "$curses" ; then
+
+curses=no
+
+cat > $TMPC << EOF
+#include <curses.h>
+int main( void ) { return curses_version (); }
+EOF
+
+if $cc -o $TMPE -lcurses $TMPC 2> /dev/null ; then
+curses=yes
+fi
+
+fi # -z $curses
+
 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
 cat << EOF
 
@@ -469,6 +489,7 @@
 if test "$sdl" != "no" ; then
     echo "SDL static link   $sdl_static"
 fi
+echo "curses support    $curses"
 echo "mingw32 support   $mingw32"
 echo "Adlib support     $adlib"
 echo "CoreAudio support $coreaudio"
@@ -680,7 +701,8 @@
         -a "$sdl" = "no" -a "$cocoa" = "no" ; then
     echo "ERROR: QEMU requires SDL or Cocoa for graphical output"
     echo "To build QEMU with graphical output configure with --disable-gfx-check"
-    echo "Note that this will disable all output from the virtual graphics card."
+    echo "Note that this will disable all output from the virtual graphics card"
+    echo "except for the curses interface."
     exit 1;
 fi
 
@@ -798,6 +820,15 @@
     echo "CONFIG_COCOA=yes" >> $config_mak
 fi
 
+if test "$curses" = "yes" ; then
+    if test "$target_cpu" != "sparc" -a "$target_cpu" != "arm" ; then
+        echo "#define CONFIG_CURSES 1" >> $config_h
+        echo "CONFIG_CURSES=yes" >> $config_mak
+        echo "CURSES_LIBS=-lcurses" >> $config_mak
+        echo "CURSES_CFLAGS=" >> $config_mak
+    fi
+fi
+
 done # for target in $targets
 
 # build tree in object directory if source path is different from current one
console.c +6 -42

61 lines not on this page · raw message

console.h +70 -0

70 lines not on this page · raw message

curses.c +319 -0

319 lines not on this page · raw message

curses_keys.h +241 -0

241 lines not on this page · raw message

hw/vga.c +165 -3

189 lines not on this page · raw message

vl.c +26 -2
diff -Naur qemu/vl.c qemu-curses/vl.c
@@ -115,6 +115,7 @@
 int bios_size;
 static DisplayState display_state;
 int nographic;
+int curses;
 const char* keyboard_layout = NULL;
 int64_t ticks_per_sec;
 int boot_device = 'c';
@@ -3840,6 +3841,9 @@
            "-hdachs c,h,s[,t]  force hard disk 0 physical geometry and the optional BIOS\n"
            "                translation (t=none or lba) (usually qemu can guess them)\n"
            "-L path         set the directory for the BIOS and VGA BIOS\n"
+#ifdef CONFIG_CURSES
+           "-curses         use a curses/ncurses interface instead of SDL\n"
+#endif
 #ifdef USE_KQEMU
            "-no-kqemu       disable KQEMU kernel module usage\n"
 #endif
@@ -3934,6 +3938,7 @@
     QEMU_OPTION_usb,
     QEMU_OPTION_usbdevice,
     QEMU_OPTION_smp,
+    QEMU_OPTION_curses,
 };
 
 typedef struct QEMUOption {
@@ -3984,6 +3989,9 @@
     { "hdachs", HAS_ARG, QEMU_OPTION_hdachs },
     { "L", HAS_ARG, QEMU_OPTION_L },
     { "no-code-copy", 0, QEMU_OPTION_no_code_copy },
+#ifdef CONFIG_CURSES
+    { "curses", 0, QEMU_OPTION_curses },
+#endif
 #ifdef USE_KQEMU
     { "no-kqemu", 0, QEMU_OPTION_no_kqemu },
 #endif
@@ -4202,6 +4210,7 @@
 #endif
     snapshot = 0;
     nographic = 0;
+    curses = 0;
     kernel_filename = NULL;
     kernel_cmdline = "";
 #ifdef TARGET_PPC
@@ -4335,7 +4344,16 @@
                 pstrcpy(monitor_device, sizeof(monitor_device), "stdio");
                 pstrcpy(serial_devices[0], sizeof(serial_devices[0]), "stdio");
                 nographic = 1;
+                curses = 0;
+                break;
+#ifdef CONFIG_CURSES
+            case QEMU_OPTION_curses:
+                pstrcpy(monitor_device, sizeof(monitor_device), "vc");
+                pstrcpy(serial_devices[0], sizeof(serial_devices[0]), "vc");
+                curses = 1;
+		nographic = 0;
                 break;
+#endif
             case QEMU_OPTION_kernel:
                 kernel_filename = optarg;
                 break;
@@ -4714,7 +4732,13 @@
     /* terminal init */
     if (nographic) {
         dumb_display_init(ds);
-    } else {
+    } else
+#if defined(CONFIG_CURSES)
+    if (curses) {
+        curses_display_init(ds, full_screen);
+    } else
+#endif
+    {
 #if defined(CONFIG_SDL)
         sdl_display_init(ds, full_screen);
 #elif defined(CONFIG_COCOA)
@@ -4725,7 +4749,7 @@
     }
 
     vga_console = graphic_console_init(ds);
-    
+
     monitor_hd = qemu_chr_open(monitor_device);
     if (!monitor_hd) {
         fprintf(stderr, "qemu: could not open monitor device '%s'\n", monitor_device);
vl.h +6 -0
diff -Naur qemu/vl.h qemu-curses/vl.h
@@ -265,6 +265,7 @@
 int is_active_console(TextConsole *s);
 CharDriverState *text_console_init(DisplayState *ds);
 void console_select(unsigned int index);
+TextConsole *get_active_console();
 
 /* serial ports */
 
@@ -652,6 +653,8 @@
 void vga_update_display(void);
 void vga_invalidate_display(void);
 void vga_screen_dump(const char *filename);
+void vga_update_text(uint8_t *chardata, void (*dpy_cursor)
+                      (DisplayState *s, int x, int y));
 
 /* cirrus_vga.c */
 void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, 
@@ -665,6 +668,9 @@
 /* cocoa.m */
 void cocoa_display_init(DisplayState *ds, int full_screen);
 
+/* curses.c */
+void curses_display_init(DisplayState *ds, int full_screen);
+
 /* ide.c */
 #define MAX_DISKS 4
 
#4 lore raw

Hi,

thank you for your quick reply!

Quoted 2 lines · andrzej zaborowski

- fixed the terminal resize event handling, now it should work regardless of the curses library implementation,

Unfortunately, it does not work here. ATM I am using a cygwin rxvt, and run qemu via SSH. I don't know if rxvt can resize, or if I have to allow it... Ideas?

Quoted 1 line

- some keyboard input details,

I usually test QEmu with a floppy image of Injector Linux. When I want to delete a word, I use Escape+d or Escape+BackSpace. I still do not get the desired result.

Quoted 6 lines

- and changed the Makefile to compile the curses driver for all targets that use the VGA emulator (from hw/vga.c) - that means all targets except Sparc and ARM - I think it is also possible to make this work for Sparc and ARM but I don't know anything about these architectures and wouldn't have any way to perform any testing and I also don't know how useful this would be.

That is very good!

Quoted 3 lines

Any comments are welcome, especially if someone encounters any further bugs or malfunctioning of the interface. What do you think about including the curses interface in QEMU?

I like it very much. It makes it especially easy to copy text from the guest. I am very much in favor of inclusion. Now let's see what our BDFL says ;-)

Ciao,
Dscho

#5 lore raw

Hi there,

Quoted 6 lines · Johannes Schindelin
Quoted 2 lines

- fixed the terminal resize event handling, now it should work regardless of the curses library implementation,

Unfortunately, it does not work here. ATM I am using a cygwin rxvt, and run qemu via SSH. I don't know if rxvt can resize, or if I have to allow it... Ideas?

I have never tried Cygwin, but the terminal resizing relies entirely on signals, which Ms Windows doesn't have but I suppose Cygwin should emulate signals somehow. Also I think SSH passes the WINCH signal correctly (Cygwin uses OpenSSH, right?). I now installed mrxvt and rxvt and indeed the terminal starts up with 80x24 characters by default, but the window is resizable and QEMU reacts correctly to resizing (good thing is that everything seems to work even much faster than in xterm or gnome-terminal - what I don't like is that the cursor is in one colour only and thus invisible on some backgrounds). It also works over "ssh localhost" on my Linux.
So I guess one of the elements between your terminal emulator and qemu is failing to pass the signal further, because there may be quite some elements working there:
- The terminal emulator (that initially should emit the signal),
- The shell in that terminal (that is the direct child process of the rxvt),
- The SSH client (direct child process of the shell),
- The SSH server (that should receive the signal over the network),
- The shell that is the direct child process of the server-side SSH,
- Finally QEMU that is a child process of the remote shell.
Can you check if for example Midnight Commander (mc) ran in the same configuration (outside QEMU) resizes correctly?
Is the current behaviour such that when you make the terminal window bigger than 80x24 while QEMU is running, the virtual machine's screen stays at only 80x24 characters and stays in the top-left corner of the terminal?

Quoted 5 lines
Quoted 1 line

- some keyboard input details,

I usually test QEmu with a floppy image of Injector Linux. When I want to delete a word, I use Escape+d or Escape+BackSpace. I still do not get the desired result.

O.o
Again I don't know why this might not work. Again can you check how MC would cope with it? Make sure that the TERM shell variable is set to "rxvt" or the correct value. I find MC very useful for this kind of testing (not only for this, ofcourse), with its "Learn keys" option. Do other programs running in your rxvt react to Escape+d and Escape+BackSpace?

Quoted 3 lines

I like it very much. It makes it especially easy to copy text from the guest. I am very much in favor of inclusion. Now let's see what our BDFL says ;-)

Thanks for positive opinion! :)
greetings,
--
balrog 2oo5

Dear Outlook users: Please remove me from your address books
http://www.newsforge.com/article.pl?sid=03/08/21/143258

#6 lore raw
In reply to andrzej zaborowski

Hi,
here's an iteration of the curses UI patch, for 0.9.1. This time it takes into account "such modern concepts" ;) like endianness and 64-bits, so it should work on PPC and on amd64, as opposed to previous versions. (ncurses apparently chose to not make a seamless transition to 64-bits).

I would like to merge this patch at some point if there's no objection. It was in Debian until now and recently broke and a number of users got annoyed.

The runtime UI switching trick is not included. The monitor history saving is not included but it is in the svn.openmoko.org tree and should apply ok. Switching between VCs is still done with <alt>+<number>.
Regards

Makefile +6 -0
index e76d617..b823bfa 100644
@@ -90,6 +90,9 @@ OBJS+=$(addprefix audio/, $(AUDIO_OBJS))
 ifdef CONFIG_SDL
 OBJS+=sdl.o x_keymap.o
 endif
+ifdef CONFIG_CURSES
+OBJS+=curses.o
+endif
 OBJS+=vnc.o d3des.o
 
 ifdef CONFIG_COCOA
@@ -113,6 +116,9 @@ sdl.o: sdl.c keymaps.c sdl_keysym.h
 vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h d3des.c d3des.h
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $(CONFIG_VNC_TLS_CFLAGS) -c -o $@ $<
 
+curses.o: curses.c keymaps.c curses_keys.h
+	$(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
+
 audio/sdlaudio.o: audio/sdlaudio.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(SDL_CFLAGS) $(BASE_CFLAGS) -c -o $@ $<
 
Makefile.target +1 -1
index acd6cda..caad4f0 100644
@@ -569,7 +569,7 @@ SDL_LIBS := $(filter-out -mwindows, $(SDL_LIBS)) -mconsole
 endif
 
 $(QEMU_SYSTEM): $(VL_OBJS) ../libqemu_common.a libqemu.a
-	$(CC) $(VL_LDFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS)
+	$(CC) $(VL_LDFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(CURSES_LIBS) $(VL_LIBS)
 
 depend: $(SRCS)
 	$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $^ 1>.depend
configure +27 -3
index d86020e..94b5e78 100755
@@ -105,6 +105,7 @@ linux_user="no"
 darwin_user="no"
 build_docs="no"
 uname_release=""
+curses="yes"
 
 # OS specific
 targetos=`uname -s`
@@ -316,6 +317,8 @@ for opt do
   ;;
   --disable-werror) werror="no"
   ;;
+  --disable-curses) curses="no"
+  ;;
   *) echo "ERROR: unknown option $opt"; show_help="yes"
   ;;
   esac
@@ -662,6 +665,20 @@ EOF
   fi
 fi
 
+##########################################
+# curses probe
+
+if test "$curses" = "yes" ; then
+  curses=no
+  cat > $TMPC << EOF
+#include <curses.h>
+int main(void) { return curses_version(); }
+EOF
+  if $cc -o $TMPE $TMPC -lcurses 2> /dev/null ; then
+    curses=yes
+  fi
+fi # test "$curses"
+
 # Check if tools are available to build documentation.
 if [ -x "`which texi2html 2>/dev/null`" ] && \
    [ -x "`which pod2man 2>/dev/null`" ]; then
@@ -712,6 +729,7 @@ echo "SDL support       $sdl"
 if test "$sdl" != "no" ; then
     echo "SDL static link   $sdl_static"
 fi
+echo "curses support    $curses"
 echo "mingw32 support   $mingw32"
 echo "Adlib support     $adlib"
 echo "CoreAudio support $coreaudio"
@@ -949,8 +967,13 @@ if test "$sdl1" = "yes" ; then
   fi
 fi
 if test "$cocoa" = "yes" ; then
-    echo "#define CONFIG_COCOA 1" >> $config_h
-    echo "CONFIG_COCOA=yes" >> $config_mak
+  echo "#define CONFIG_COCOA 1" >> $config_h
+  echo "CONFIG_COCOA=yes" >> $config_mak
+fi
+if test "$curses" = "yes" ; then
+  echo "#define CONFIG_CURSES 1" >> $config_h
+  echo "CONFIG_CURSES=yes" >> $config_mak
+  echo "CURSES_LIBS=-lcurses" >> $config_mak
 fi
 
 # XXX: suppress that
@@ -1015,7 +1038,8 @@ if test "$target_user_only" = "no" -a "$check_gfx" = "yes" \
         -a "$sdl" = "no" -a "$cocoa" = "no" ; then
     echo "ERROR: QEMU requires SDL or Cocoa for graphical output"
     echo "To build QEMU without graphical output configure with --disable-gfx-check"
-    echo "Note that this will disable all output from the virtual graphics card."
+    echo "Note that this will disable all output from the virtual graphics card"
+    echo "except through VNC or curses."
     exit 1;
 fi
 
console.c +97 -16

197 lines not on this page · raw message

console.h +19 -0
index 1ac74fa..b8a5c6d 100644
@@ -79,6 +79,7 @@ struct DisplayState {
                      int dst_x, int dst_y, int w, int h);
     void (*dpy_fill)(struct DisplayState *s, int x, int y,
                      int w, int h, uint32_t c);
+    void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
     void (*mouse_set)(int x, int y, int on);
     void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
                           uint8_t *image, uint8_t *mask);
@@ -94,17 +95,32 @@ static inline void dpy_resize(DisplayState *s, int w, int h)
     s->dpy_resize(s, w, h);
 }
 
+static inline void dpy_cursor(DisplayState *s, int x, int y)
+{
+    if (s->dpy_text_cursor)
+        s->dpy_text_cursor(s, x, y);
+}
+
+typedef unsigned long console_ch_t;
+static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
+{
+    cpu_to_le32wu((uint32_t *) dest, ch);
+}
+
 typedef void (*vga_hw_update_ptr)(void *);
 typedef void (*vga_hw_invalidate_ptr)(void *);
 typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
+typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
 
 TextConsole *graphic_console_init(DisplayState *ds, vga_hw_update_ptr update,
                                   vga_hw_invalidate_ptr invalidate,
                                   vga_hw_screen_dump_ptr screen_dump,
+                                  vga_hw_text_update_ptr text_update,
                                   void *opaque);
 void vga_hw_update(void);
 void vga_hw_invalidate(void);
 void vga_hw_screen_dump(const char *filename);
+void vga_hw_text_update(console_ch_t *chardata);
 
 int is_graphic_console(void);
 CharDriverState *text_console_init(DisplayState *ds, const char *p);
@@ -124,6 +140,9 @@ int vnc_display_open(DisplayState *ds, const char *display);
 int vnc_display_password(DisplayState *ds, const char *password);
 void do_info_vnc(void);
 
+/* curses.c */
+void curses_display_init(DisplayState *ds, int full_screen);
+
 /* x_keymap.c */
 extern uint8_t _translate_keycode(const int key);
 
curses.c new file +370 -0

370 lines not on this page · raw message

curses_keys.h new file +484 -0

484 lines not on this page · raw message

hw/cirrus_vga.c +2 -1
index 59bfdff..07e52b0 100644
@@ -3257,7 +3257,8 @@ void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
                     ds, vga_ram_base, vga_ram_offset, vga_ram_size);
     cirrus_init_common(s, device_id, 1);
 
-    graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump, s);
+    graphic_console_init(s->ds, s->update, s->invalidate, s->screen_dump,
+                         s->text_update, s);
 
     s->pci_dev = (PCIDevice *)d;
 
hw/jazz_led.c +19 -1
index a0eea26..d547138 100644
@@ -285,6 +285,22 @@ static void jazz_led_screen_dump(void *opaque, const char *filename)
     printf("jazz_led_screen_dump() not implemented\n");
 }
 
+static void jazz_led_text_update(void *opaque, console_ch_t *chardata)
+{
+    LedState *s = opaque;
+    char buf[2];
+
+    dpy_cursor(s->ds, -1, -1);
+    dpy_resize(s->ds, 2, 1);
+
+    /* TODO: draw the segments */
+    snprintf(buf, 2, "%02hhx\n", s->segments);
+    console_write_ch(chardata++, 0x00200100 | buf[0]);
+    console_write_ch(chardata++, 0x00200100 | buf[1]);
+
+    dpy_update(s->ds, 0, 0, 2, 1);
+}
+
 void jazz_led_init(DisplayState *ds, target_phys_addr_t base)
 {
     LedState *s;
@@ -301,5 +317,7 @@ void jazz_led_init(DisplayState *ds, target_phys_addr_t base)
     io = cpu_register_io_memory(0, led_read, led_write, s);
     cpu_register_physical_memory(s->base, 1, io);
 
-    graphic_console_init(ds, jazz_led_update_display, jazz_led_invalidate_display, jazz_led_screen_dump, s);
+    graphic_console_init(ds, jazz_led_update_display,
+                         jazz_led_invalidate_display, jazz_led_screen_dump,
+                         jazz_led_text_update, s);
 }
hw/omap_lcdc.c +1 -1
index c79d244..42174f7 100644
@@ -495,7 +495,7 @@ struct omap_lcd_panel_s *omap_lcdc_init(target_phys_addr_t base, qemu_irq irq,
     cpu_register_physical_memory(s->base, 0x100, iomemtype);
 
     graphic_console_init(ds, omap_update_display,
-                    omap_invalidate_display, omap_screen_dump, s);
+                    omap_invalidate_display, omap_screen_dump, NULL, s);
 
     return s;
 }
hw/pl110.c +1 -1
index e5b2b23..7f45085 100644
@@ -426,7 +426,7 @@ void *pl110_init(DisplayState *ds, uint32_t base, qemu_irq irq,
     s->versatile = versatile;
     s->irq = irq;
     graphic_console_init(ds, pl110_update_display, pl110_invalidate_display,
-                         NULL, s);
+                         NULL, NULL, s);
     /* ??? Save/restore.  */
     return s;
 }
hw/pxa2xx_lcd.c +1 -1
index 5855435..7203a3f 100644
@@ -1002,7 +1002,7 @@ struct pxa2xx_lcdc_s *pxa2xx_lcdc_init(target_phys_addr_t base, qemu_irq irq,
     cpu_register_physical_memory(base, 0x00100000, iomemtype);
 
     graphic_console_init(ds, pxa2xx_update_display,
-                    pxa2xx_invalidate_display, pxa2xx_screen_dump, s);
+                    pxa2xx_invalidate_display, pxa2xx_screen_dump, NULL, s);
 
     switch (s->ds->depth) {
     case 0:
hw/ssd0303.c +1 -1
index 383a623..daa9292 100644
@@ -270,6 +270,6 @@ void ssd0303_init(DisplayState *ds, i2c_bus *bus, int address)
     s->i2c.recv = ssd0303_recv;
     s->i2c.send = ssd0303_send;
     graphic_console_init(ds, ssd0303_update_display, ssd0303_invalidate_display,
-                         NULL, s);
+                         NULL, NULL, s);
     dpy_resize(s->ds, 96 * MAGNIFY, 16 * MAGNIFY);
 }
hw/ssd0323.c +1 -1
index 4706b05..e2e619f 100644
@@ -280,7 +280,7 @@ void *ssd0323_init(DisplayState *ds, qemu_irq *cmd_p)
     s = (ssd0323_state *)qemu_mallocz(sizeof(ssd0323_state));
     s->ds = ds;
     graphic_console_init(ds, ssd0323_update_display, ssd0323_invalidate_display,
-                         NULL, s);
+                         NULL, NULL, s);
     dpy_resize(s->ds, 128 * MAGNIFY, 64 * MAGNIFY);
     s->col_end = 63;
     s->row_end = 79;
hw/tcx.c +3 -2
index afafa2a..f6d3d4c 100644
@@ -537,12 +537,13 @@ void tcx_init(DisplayState *ds, target_phys_addr_t addr, uint8_t *vram_base,
         s->cplane_offset = vram_offset;
         cpu_register_physical_memory(addr + 0x0a000000ULL, size, vram_offset);
         graphic_console_init(s->ds, tcx24_update_display,
-                             tcx24_invalidate_display, tcx24_screen_dump, s);
+                             tcx24_invalidate_display,
+                             tcx24_screen_dump, NULL, s);
     } else {
         cpu_register_physical_memory(addr + 0x00300000ULL, TCX_THC_NREGS_8,
                                      dummy_memory);
         graphic_console_init(s->ds, tcx_update_display, tcx_invalidate_display,
-                             tcx_screen_dump, s);
+                             tcx_screen_dump, NULL, s);
     }
     // NetBSD writes here even with 8-bit display
     cpu_register_physical_memory(addr + 0x00301000ULL, TCX_THC_NREGS_24,
hw/vga.c +166 -3

199 lines not on this page · raw message

hw/vga_int.h +1 -0
index a94162d..5d11a7a 100644
@@ -139,6 +139,7 @@
     vga_hw_update_ptr update;                                           \
     vga_hw_invalidate_ptr invalidate;                                   \
     vga_hw_screen_dump_ptr screen_dump;                                 \
+    vga_hw_text_update_ptr text_update;                                 \
     /* hardware mouse cursor support */                                 \
     uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32];                  \
     void (*cursor_invalidate)(struct VGAState *s);                      \
hw/vmware_vga.c +10 -1
index 6cae25c..29e36d6 100644
@@ -949,6 +949,14 @@ static void vmsvga_screen_dump(void *opaque, const char *filename)
     }
 }
 
+static void vmsvga_text_update(void *opaque, console_ch_t *chardata)
+{
+    struct vmsvga_state_s *s = (struct vmsvga_state_s *) opaque;
+
+    if (s->text_update)
+        s->text_update(opaque, chardata);
+}
+
 #ifdef DIRECT_VRAM
 static uint32_t vmsvga_vram_readb(void *opaque, target_phys_addr_t addr)
 {
@@ -1114,7 +1122,8 @@ static void vmsvga_init(struct vmsvga_state_s *s, DisplayState *ds,
                     1, 4, vmsvga_bios_write, s);
 
     graphic_console_init(ds, vmsvga_update_display,
-                    vmsvga_invalidate_display, vmsvga_screen_dump, s);
+                    vmsvga_invalidate_display, vmsvga_screen_dump,
+                    vmsvga_text_update, s);
 
 #ifdef EMBED_STDVGA
     vga_common_init((VGAState *) s, ds,
monitor.c +2 -0
index 0783eaf..025025b 100644
@@ -824,6 +824,8 @@ static const KeyDef key_defs[] = {
     { 0x31, "n" },
     { 0x32, "m" },
 
+    { 0x37, "asterisk" },
+
     { 0x39, "spc" },
     { 0x3a, "caps_lock" },
     { 0x3b, "f1" },
vl.c +25 -1
index a04edbc..70b9656 100644
@@ -172,6 +172,7 @@ BlockDriverState *bs_snapshots;
 int vga_ram_size;
 static DisplayState display_state;
 int nographic;
+int curses;
 const char* keyboard_layout = NULL;
 int64_t ticks_per_sec;
 int ram_size;
@@ -7605,6 +7606,9 @@ static void help(int exitcode)
            "                (default is CL-GD5446 PCI VGA)\n"
            "-no-acpi        disable ACPI\n"
 #endif
+#ifdef CONFIG_CURSES
+           "-curses         use a curses/ncurses interface instead of SDL\n"
+#endif
            "-no-reboot      exit instead of rebooting\n"
            "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
 	   "-vnc display    start a VNC server on display\n"
@@ -7709,6 +7713,7 @@ enum {
     QEMU_OPTION_smp,
     QEMU_OPTION_vnc,
     QEMU_OPTION_no_acpi,
+    QEMU_OPTION_curses,
     QEMU_OPTION_no_reboot,
     QEMU_OPTION_show_cursor,
     QEMU_OPTION_daemonize,
@@ -7805,6 +7810,9 @@ const QEMUOption qemu_options[] = {
     { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
     { "smp", HAS_ARG, QEMU_OPTION_smp },
     { "vnc", HAS_ARG, QEMU_OPTION_vnc },
+#ifdef CONFIG_CURSES
+    { "curses", 0, QEMU_OPTION_curses },
+#endif
 
     /* temporary options */
     { "usb", 0, QEMU_OPTION_usb },
@@ -8131,6 +8139,7 @@ int main(int argc, char **argv)
 #endif
     snapshot = 0;
     nographic = 0;
+    curses = 0;
     kernel_filename = NULL;
     kernel_cmdline = "";
     cyls = heads = secs = 0;
@@ -8307,6 +8316,11 @@ int main(int argc, char **argv)
                 pstrcpy(monitor_device, sizeof(monitor_device), "stdio");
                 nographic = 1;
                 break;
+#ifdef CONFIG_CURSES
+            case QEMU_OPTION_curses:
+                curses = 1;
+                break;
+#endif
             case QEMU_OPTION_portrait:
                 graphic_rotate = 1;
                 break;
@@ -8847,13 +8861,23 @@ int main(int argc, char **argv)
     /* terminal init */
     memset(&display_state, 0, sizeof(display_state));
     if (nographic) {
+        if (curses) {
+            fprintf(stderr, "fatal: -nographic can't be used with -curses\n");
+            exit(1);
+        }
         /* nearly nothing to do */
         dumb_display_init(ds);
     } else if (vnc_display != NULL) {
         vnc_display_init(ds);
         if (vnc_display_open(ds, vnc_display) < 0)
             exit(1);
-    } else {
+    } else
+#if defined(CONFIG_CURSES)
+    if (curses) {
+        curses_display_init(ds, full_screen);
+    } else
+#endif
+    {
 #if defined(CONFIG_SDL)
         sdl_display_init(ds, full_screen, no_frame);
 #elif defined(CONFIG_COCOA)
vnc.c +1 -0
index 9fb8c85..dea9a39 100644
@@ -954,6 +954,7 @@ static void do_key_event(VncState *vs, int down, uint32_t sym)
             return;
         }
         break;
+    case 0x3a:			/* CapsLock */
     case 0x45:			/* NumLock */
         if (!down)
             vs->modifiers_state[keycode] ^= 1;