Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2010-01-08 Thread Anthony Liguori

On 12/29/2009 03:51 PM, H. Peter Anvin wrote:

Add generic support for debugging consoles (simple I/O ports which
when written to cause debugging output to be written to a target.)
The current implementation matches Bochs' port 0xe9, allowing the same
debugging code to be used for both Bochs and Qemu.

There is no vm state associated with the debugging port, simply
because it has none -- the entire interface is a single, stateless,
write-only port.

Most of the code was cribbed from the serial port driver.

v2: removed non-ISA variants (they can be introduced when/if someone
wants them, using code from the serial port); added configurable
readback (Bochs returns 0xe9 on a read from this register, mimic that
by default)  This retains the apparently somewhat controversial user
friendly option, however.

v3: reimplemented the user friendly option as a synthetic option
("-debugcon foo" basically ends up being a parser-level shorthand for
"-chardev stdio,id=debugcon -device isa-debugcon,chardev=debugcon") --
this dramatically reduced the complexity while keeping the same level
of user friendliness.

v4: spaces, not tabs.

v5: update to match current top of tree.  Calling qemu_chr_open()
already during parsing no longer works; defer until we are parsing the
other console-like devices.

Signed-off-by: H. Peter Anvin
   


Applied.  Thanks.

Regards,

Anthony Liguori

---
  Makefile.target |2 +-
  hw/debugcon.c   |  107 +++
  qemu-options.hx |   11 ++
  vl.c|   23 
  4 files changed, 142 insertions(+), 1 deletions(-)
  create mode 100644 hw/debugcon.c

diff --git a/Makefile.target b/Makefile.target
index 7c1f30c..0a803ef 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -194,7 +194,7 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o 
pcspk.o pc.o
  obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
  obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
  obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
-obj-i386-y += ne2000-isa.o
+obj-i386-y += ne2000-isa.o debugcon.o

  # shared objects
  obj-ppc-y = ppc.o ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/macio.o
diff --git a/hw/debugcon.c b/hw/debugcon.c
new file mode 100644
index 000..d549091
--- /dev/null
+++ b/hw/debugcon.c
@@ -0,0 +1,107 @@
+/*
+ * QEMU Bochs-style debug console ("port E9") emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2008 Citrix Systems, Inc.
+ * Copyright (c) Intel Corporation; author: H. Peter Anvin
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw.h"
+#include "qemu-char.h"
+#include "isa.h"
+#include "pc.h"
+
+//#define DEBUG_DEBUGCON
+
+typedef struct DebugconState {
+CharDriverState *chr;
+uint32_t readback;
+} DebugconState;
+
+typedef struct ISADebugconState {
+ISADevice dev;
+uint32_t iobase;
+DebugconState state;
+} ISADebugconState;
+
+static void debugcon_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+{
+DebugconState *s = opaque;
+unsigned char ch = val;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: write addr=0x%04x val=0x%02x\n", addr, val);
+#endif
+
+qemu_chr_write(s->chr,&ch, 1);
+}
+
+
+static uint32_t debugcon_ioport_read(void *opaque, uint32_t addr)
+{
+DebugconState *s = opaque;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: read addr=0x%04x\n", addr, val);
+#endif
+
+return s->readback;
+}
+
+static void debugcon_init_core(DebugconState *s)
+{
+if (!s->chr) {
+fprintf(stderr, "Can't create debugcon device, empty char device\n");
+exit(1);
+}
+
+qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
+}
+
+static int debugcon_isa_initfn(ISADevice *dev)
+{
+ISADebugconState *isa = DO_UPCAST(ISADebugconState, dev, dev);
+DebugconState *s =&isa->state;
+
+debugcon_init_core(s);
+register_ioport_write(isa->io

Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2010-01-02 Thread François Revol
> Makes sense.  Either way, it works with my patch looking something
> like:
>
>   -chardev stdio,id=seabios \
>   -device isa-debugcon,iobase=0x402,chardev=seabios
>
> ... should do the job.

Btw,
I once added another method of debug output to ZETA, that was using the
low-level protocol used by laplink (nibble mode). I needed this for a
laptop that didn't have a serial port but still had a // one. This
allowed bidirectionnal debugging (including sending kernel debugger
commands) with a null-printer cable.
I also wrote code to support it in Haiku, though I'm not sure I've
added the receiving driver yet.
See:
http://dev.haiku-os.org/browser/haiku/trunk/src/add-ons/kernel/debugger/laplinkll

I don't know if the parallel port emulation in QEMU supports dumping
bytes at nibble mode yet, it might be interesting to add this anyway.
Though it should also be possible to just use 8bit mode and dump data
straight to it as with the 0x402 port.

François.




Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2010-01-02 Thread H. Peter Anvin
On 01/02/2010 09:53 AM, Kevin O'Connor wrote:
> On Fri, Jan 01, 2010 at 07:02:59PM -0800, H. Peter Anvin wrote:
>> On 12/30/2009 08:49 AM, Kevin O'Connor wrote:
>>> SeaBIOS writes debugging info to port 0x0402.  Unfortunately, qemu has
>>> to be recompiled in order to display this info.  Will your patch
>>> enable one to get at the 0x0402 data without recompiling?
>>
>> Incidentally, it's somewhat unusual choice of ports... port 0x80 is the
>> normal port for BIOSes to display debugging information on.
> 
> Port 0x0402 is a carry over from Bochs bios.
> 
> Port 0x80 isn't generally used to emit a stream of ascii data, and it
> can be used by other programs besides the bios.  I'd guess that's why
> Bochs chose a different port.
> 
> -Kevin

Makes sense.  Either way, it works with my patch looking something like:

-chardev stdio,id=seabios \
-device isa-debugcon,iobase=0x402,chardev=seabios

... should do the job.

-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.





Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2010-01-02 Thread Kevin O'Connor
On Fri, Jan 01, 2010 at 07:02:59PM -0800, H. Peter Anvin wrote:
> On 12/30/2009 08:49 AM, Kevin O'Connor wrote:
> > SeaBIOS writes debugging info to port 0x0402.  Unfortunately, qemu has
> > to be recompiled in order to display this info.  Will your patch
> > enable one to get at the 0x0402 data without recompiling?
> 
> Incidentally, it's somewhat unusual choice of ports... port 0x80 is the
> normal port for BIOSes to display debugging information on.

Port 0x0402 is a carry over from Bochs bios.

Port 0x80 isn't generally used to emit a stream of ascii data, and it
can be used by other programs besides the bios.  I'd guess that's why
Bochs chose a different port.

-Kevin




Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2010-01-01 Thread H. Peter Anvin
On 12/30/2009 08:49 AM, Kevin O'Connor wrote:
> 
> Hi,
> 
> SeaBIOS writes debugging info to port 0x0402.  Unfortunately, qemu has
> to be recompiled in order to display this info.  Will your patch
> enable one to get at the 0x0402 data without recompiling?
> 
> -Kevin
> 

Incidentally, it's somewhat unusual choice of ports... port 0x80 is the
normal port for BIOSes to display debugging information on.

-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.





Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2010-01-01 Thread H. Peter Anvin
On 12/30/2009 08:49 AM, Kevin O'Connor wrote:
> On Tue, Dec 29, 2009 at 01:51:36PM -0800, H. Peter Anvin wrote:
>> Add generic support for debugging consoles (simple I/O ports which
>> when written to cause debugging output to be written to a target.)
>> The current implementation matches Bochs' port 0xe9, allowing the same
>> debugging code to be used for both Bochs and Qemu.
>>
>> There is no vm state associated with the debugging port, simply
>> because it has none -- the entire interface is a single, stateless,
>> write-only port.
>>
>> Most of the code was cribbed from the serial port driver.
> 
> Hi,
> 
> SeaBIOS writes debugging info to port 0x0402.  Unfortunately, qemu has
> to be recompiled in order to display this info.  Will your patch
> enable one to get at the 0x0402 data without recompiling?
> 

Yes.

-hpa

-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.





Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-12-30 Thread Kevin O'Connor
On Tue, Dec 29, 2009 at 01:51:36PM -0800, H. Peter Anvin wrote:
> Add generic support for debugging consoles (simple I/O ports which
> when written to cause debugging output to be written to a target.)
> The current implementation matches Bochs' port 0xe9, allowing the same
> debugging code to be used for both Bochs and Qemu.
> 
> There is no vm state associated with the debugging port, simply
> because it has none -- the entire interface is a single, stateless,
> write-only port.
> 
> Most of the code was cribbed from the serial port driver.

Hi,

SeaBIOS writes debugging info to port 0x0402.  Unfortunately, qemu has
to be recompiled in order to display this info.  Will your patch
enable one to get at the 0x0402 data without recompiling?

-Kevin




[Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-12-29 Thread H. Peter Anvin
Add generic support for debugging consoles (simple I/O ports which
when written to cause debugging output to be written to a target.)
The current implementation matches Bochs' port 0xe9, allowing the same
debugging code to be used for both Bochs and Qemu.

There is no vm state associated with the debugging port, simply
because it has none -- the entire interface is a single, stateless,
write-only port.

Most of the code was cribbed from the serial port driver.

v2: removed non-ISA variants (they can be introduced when/if someone
wants them, using code from the serial port); added configurable
readback (Bochs returns 0xe9 on a read from this register, mimic that
by default)  This retains the apparently somewhat controversial user
friendly option, however.

v3: reimplemented the user friendly option as a synthetic option
("-debugcon foo" basically ends up being a parser-level shorthand for
"-chardev stdio,id=debugcon -device isa-debugcon,chardev=debugcon") --
this dramatically reduced the complexity while keeping the same level
of user friendliness.

v4: spaces, not tabs.

v5: update to match current top of tree.  Calling qemu_chr_open()
already during parsing no longer works; defer until we are parsing the
other console-like devices.

Signed-off-by: H. Peter Anvin 
---
 Makefile.target |2 +-
 hw/debugcon.c   |  107 +++
 qemu-options.hx |   11 ++
 vl.c|   23 
 4 files changed, 142 insertions(+), 1 deletions(-)
 create mode 100644 hw/debugcon.c

diff --git a/Makefile.target b/Makefile.target
index 7c1f30c..0a803ef 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -194,7 +194,7 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o 
pcspk.o pc.o
 obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
-obj-i386-y += ne2000-isa.o
+obj-i386-y += ne2000-isa.o debugcon.o
 
 # shared objects
 obj-ppc-y = ppc.o ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/macio.o
diff --git a/hw/debugcon.c b/hw/debugcon.c
new file mode 100644
index 000..d549091
--- /dev/null
+++ b/hw/debugcon.c
@@ -0,0 +1,107 @@
+/*
+ * QEMU Bochs-style debug console ("port E9") emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2008 Citrix Systems, Inc.
+ * Copyright (c) Intel Corporation; author: H. Peter Anvin
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw.h"
+#include "qemu-char.h"
+#include "isa.h"
+#include "pc.h"
+
+//#define DEBUG_DEBUGCON
+
+typedef struct DebugconState {
+CharDriverState *chr;
+uint32_t readback;
+} DebugconState;
+
+typedef struct ISADebugconState {
+ISADevice dev;
+uint32_t iobase;
+DebugconState state;
+} ISADebugconState;
+
+static void debugcon_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+{
+DebugconState *s = opaque;
+unsigned char ch = val;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: write addr=0x%04x val=0x%02x\n", addr, val);
+#endif
+
+qemu_chr_write(s->chr, &ch, 1);
+}
+
+
+static uint32_t debugcon_ioport_read(void *opaque, uint32_t addr)
+{
+DebugconState *s = opaque;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: read addr=0x%04x\n", addr, val);
+#endif
+
+return s->readback;
+}
+
+static void debugcon_init_core(DebugconState *s)
+{
+if (!s->chr) {
+fprintf(stderr, "Can't create debugcon device, empty char device\n");
+exit(1);
+}
+
+qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
+}
+
+static int debugcon_isa_initfn(ISADevice *dev)
+{
+ISADebugconState *isa = DO_UPCAST(ISADebugconState, dev, dev);
+DebugconState *s = &isa->state;
+
+debugcon_init_core(s);
+register_ioport_write(isa->iobase, 1, 1, debugcon_ioport_write, s);
+register_ioport_read(isa->iobase, 1, 1, debugcon_ioport_read, s

Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-12-29 Thread H. Peter Anvin
On 12/29/2009 01:39 PM, H. Peter Anvin wrote:
>  8 files changed, 187 insertions(+), 1 deletions(-)

Sorry everyone, re-sent an old version by mistake.  Correctly updated
patch will follow.

-hpa





[Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-12-29 Thread H. Peter Anvin
From: H. Peter Anvin 

Add generic support for debugging consoles (simple I/O ports which
when written to cause debugging output to be written to a target.)
The current implementation matches Bochs' port 0xe9, allowing the same
debugging code to be used for both Bochs and Qemu.

There is no vm state associated with the debugging port, simply
because it has none -- the entire interface is a single, stateless,
write-only port.

Most of the code was cribbed from the serial port driver.

v2: removed non-ISA variants (they can be introduced when/if someone
wants them, using code from the serial port); added configurable
readback (Bochs returns 0xe9 on a read from this register, mimic that
by default)  This retains the apparently somewhat controversial user
friendly option, however.

Signed-off-by: H. Peter Anvin 
---
 Makefile.target |2 +-
 hw/debugcon.c   |  118 +++
 hw/pc.c |6 +++
 hw/pc.h |4 ++
 qemu-common.h   |1 +
 qemu-options.hx |   11 +
 sysemu.h|6 +++
 vl.c|   40 +++
 8 files changed, 187 insertions(+), 1 deletions(-)
 create mode 100644 hw/debugcon.c

diff --git a/Makefile.target b/Makefile.target
index 2985658..df4a7b2 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -197,7 +197,7 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o 
pcspk.o pc.o
 obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
-obj-i386-y += ne2000-isa.o
+obj-i386-y += ne2000-isa.o debugcon.o
 
 # shared objects
 obj-ppc-y = ppc.o ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/macio.o
diff --git a/hw/debugcon.c b/hw/debugcon.c
new file mode 100644
index 000..a0c2923
--- /dev/null
+++ b/hw/debugcon.c
@@ -0,0 +1,118 @@
+/*
+ * QEMU Bochs-style debug console ("port E9") emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2008 Citrix Systems, Inc.
+ * Copyright (c) Intel Corporation; author: H. Peter Anvin
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw.h"
+#include "qemu-char.h"
+#include "isa.h"
+#include "pc.h"
+
+//#define DEBUG_DEBUGCON
+
+struct DebugconState {
+CharDriverState *chr;
+uint32_t readback;
+};
+
+typedef struct ISADebugconState {
+ISADevice dev;
+uint32_t iobase;
+DebugconState state;
+} ISADebugconState;
+
+static void debugcon_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+{
+DebugconState *s = opaque;
+unsigned char ch = val;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: write addr=0x%04x val=0x%02x\n", addr, val);
+#endif
+
+qemu_chr_write(s->chr, &ch, 1);
+}
+
+
+static uint32_t debugcon_ioport_read(void *opaque, uint32_t addr)
+{
+DebugconState *s = opaque;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: read addr=0x%04x\n", addr, val);
+#endif
+
+return s->readback;
+}
+
+static void debugcon_init_core(DebugconState *s)
+{
+if (!s->chr) {
+fprintf(stderr, "Can't create debugcon device, empty char device\n");
+   exit(1);
+}
+
+qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
+}
+
+static int debugcon_isa_initfn(ISADevice *dev)
+{
+ISADebugconState *isa = DO_UPCAST(ISADebugconState, dev, dev);
+DebugconState *s = &isa->state;
+
+debugcon_init_core(s);
+register_ioport_write(isa->iobase, 1, 1, debugcon_ioport_write, s);
+register_ioport_read(isa->iobase, 1, 1, debugcon_ioport_read, s);
+return 0;
+}
+
+DebugconState *debugcon_isa_init(int index, CharDriverState *chr)
+{
+ISADevice *dev;
+
+dev = isa_create("isa-debugcon");
+qdev_prop_set_chr(&dev->qdev, "chardev", chr);
+if (qdev_init(&dev->qdev) < 0)
+return NULL;
+return &DO_UPCAST(ISADebugconState, dev, dev)->state;
+}
+
+static ISADeviceInfo debugcon_isa_info 

[Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-12-02 Thread H. Peter Anvin
Add generic support for debugging consoles (simple I/O ports which
when written to cause debugging output to be written to a target.)
The current implementation matches Bochs' port 0xe9, allowing the same
debugging code to be used for both Bochs and Qemu.

There is no vm state associated with the debugging port, simply
because it has none -- the entire interface is a single, stateless,
write-only port.

Most of the code was cribbed from the serial port driver.

v2: removed non-ISA variants (they can be introduced when/if someone
wants them, using code from the serial port); added configurable
readback (Bochs returns 0xe9 on a read from this register, mimic that
by default)  This retains the apparently somewhat controversial user
friendly option, however.

v3: reimplemented the user friendly option as a synthetic option
("-debugcon foo" basically ends up being a parser-level shorthand for
"-chardev stdio,id=debugcon -device isa-debugcon,chardev=debugcon") --
this dramatically reduced the complexity while keeping the same level
of user friendliness.

v4: spaces, not tabs.

Signed-off-by: H. Peter Anvin 
---
 Makefile.target |2 +-
 hw/debugcon.c   |  107 +++
 qemu-options.hx |   11 ++
 vl.c|   12 ++
 4 files changed, 131 insertions(+), 1 deletions(-)
 create mode 100644 hw/debugcon.c

diff --git a/Makefile.target b/Makefile.target
index 2985658..df4a7b2 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -197,7 +197,7 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o 
pcspk.o pc.o
 obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
-obj-i386-y += ne2000-isa.o
+obj-i386-y += ne2000-isa.o debugcon.o
 
 # shared objects
 obj-ppc-y = ppc.o ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/macio.o
diff --git a/hw/debugcon.c b/hw/debugcon.c
new file mode 100644
index 000..d549091
--- /dev/null
+++ b/hw/debugcon.c
@@ -0,0 +1,107 @@
+/*
+ * QEMU Bochs-style debug console ("port E9") emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2008 Citrix Systems, Inc.
+ * Copyright (c) Intel Corporation; author: H. Peter Anvin
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw.h"
+#include "qemu-char.h"
+#include "isa.h"
+#include "pc.h"
+
+//#define DEBUG_DEBUGCON
+
+typedef struct DebugconState {
+CharDriverState *chr;
+uint32_t readback;
+} DebugconState;
+
+typedef struct ISADebugconState {
+ISADevice dev;
+uint32_t iobase;
+DebugconState state;
+} ISADebugconState;
+
+static void debugcon_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+{
+DebugconState *s = opaque;
+unsigned char ch = val;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: write addr=0x%04x val=0x%02x\n", addr, val);
+#endif
+
+qemu_chr_write(s->chr, &ch, 1);
+}
+
+
+static uint32_t debugcon_ioport_read(void *opaque, uint32_t addr)
+{
+DebugconState *s = opaque;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: read addr=0x%04x\n", addr, val);
+#endif
+
+return s->readback;
+}
+
+static void debugcon_init_core(DebugconState *s)
+{
+if (!s->chr) {
+fprintf(stderr, "Can't create debugcon device, empty char device\n");
+exit(1);
+}
+
+qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
+}
+
+static int debugcon_isa_initfn(ISADevice *dev)
+{
+ISADebugconState *isa = DO_UPCAST(ISADebugconState, dev, dev);
+DebugconState *s = &isa->state;
+
+debugcon_init_core(s);
+register_ioport_write(isa->iobase, 1, 1, debugcon_ioport_write, s);
+register_ioport_read(isa->iobase, 1, 1, debugcon_ioport_read, s);
+return 0;
+}
+
+static ISADeviceInfo debugcon_isa_info = {
+.qdev.name  = "isa-debugcon",
+.qdev.size  = sizeof(ISADebugconState),
+.init   = debugc

Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-12-02 Thread malc
On Wed, 2 Dec 2009, H. Peter Anvin wrote:

> Add generic support for debugging consoles (simple I/O ports which
> when written to cause debugging output to be written to a target.)
> The current implementation matches Bochs' port 0xe9, allowing the same
> debugging code to be used for both Bochs and Qemu.
> 
> There is no vm state associated with the debugging port, simply
> because it has none -- the entire interface is a single, stateless,
> write-only port.
> 
> Most of the code was cribbed from the serial port driver.
> 
> v2: removed non-ISA variants (they can be introduced when/if someone
> wants them, using code from the serial port); added configurable
> readback (Bochs returns 0xe9 on a read from this register, mimic that
> by default)  This retains the apparently somewhat controversial user
> friendly option, however.
> 
> v3: reimplemented the user friendly option as a synthetic option
> ("-debugcon foo" basically ends up being a parser-level shorthand for
> "-chardev stdio,id=debugcon -device isa-debugcon,chardev=debugcon") --
> this dramatically reduced the complexity while keeping the same level
> of user friendliness.
> 

[..snip..]

> +
> +static ISADeviceInfo debugcon_isa_info = {
> +.qdev.name  = "isa-debugcon",
> +.qdev.size  = sizeof(ISADebugconState),
> +.init   = debugcon_isa_initfn,
> +.qdev.props = (Property[]) {
> +DEFINE_PROP_HEX32("iobase", ISADebugconState, iobase, 0xe9),
> +DEFINE_PROP_CHR("chardev",  ISADebugconState, state.chr),
> + DEFINE_PROP_HEX32("readback", ISADebugconState, state.readback, 0xe9),
> +DEFINE_PROP_END_OF_LIST(),
> +},
> +};

The above is tab damaged.

[..snip..]

-- 
mailto:av1...@comtv.ru




[Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-12-02 Thread H. Peter Anvin
Add generic support for debugging consoles (simple I/O ports which
when written to cause debugging output to be written to a target.)
The current implementation matches Bochs' port 0xe9, allowing the same
debugging code to be used for both Bochs and Qemu.

There is no vm state associated with the debugging port, simply
because it has none -- the entire interface is a single, stateless,
write-only port.

Most of the code was cribbed from the serial port driver.

v2: removed non-ISA variants (they can be introduced when/if someone
wants them, using code from the serial port); added configurable
readback (Bochs returns 0xe9 on a read from this register, mimic that
by default)  This retains the apparently somewhat controversial user
friendly option, however.

v3: reimplemented the user friendly option as a synthetic option
("-debugcon foo" basically ends up being a parser-level shorthand for
"-chardev stdio,id=debugcon -device isa-debugcon,chardev=debugcon") --
this dramatically reduced the complexity while keeping the same level
of user friendliness.

Signed-off-by: H. Peter Anvin 
---
 Makefile.target |2 +-
 hw/debugcon.c   |  107 +++
 qemu-options.hx |   11 ++
 vl.c|   12 ++
 4 files changed, 131 insertions(+), 1 deletions(-)
 create mode 100644 hw/debugcon.c

diff --git a/Makefile.target b/Makefile.target
index 2985658..df4a7b2 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -197,7 +197,7 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o 
pcspk.o pc.o
 obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
-obj-i386-y += ne2000-isa.o
+obj-i386-y += ne2000-isa.o debugcon.o
 
 # shared objects
 obj-ppc-y = ppc.o ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/macio.o
diff --git a/hw/debugcon.c b/hw/debugcon.c
new file mode 100644
index 000..8a4c2a2
--- /dev/null
+++ b/hw/debugcon.c
@@ -0,0 +1,107 @@
+/*
+ * QEMU Bochs-style debug console ("port E9") emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2008 Citrix Systems, Inc.
+ * Copyright (c) Intel Corporation; author: H. Peter Anvin
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw.h"
+#include "qemu-char.h"
+#include "isa.h"
+#include "pc.h"
+
+//#define DEBUG_DEBUGCON
+
+typedef struct DebugconState {
+CharDriverState *chr;
+uint32_t readback;
+} DebugconState;
+
+typedef struct ISADebugconState {
+ISADevice dev;
+uint32_t iobase;
+DebugconState state;
+} ISADebugconState;
+
+static void debugcon_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+{
+DebugconState *s = opaque;
+unsigned char ch = val;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: write addr=0x%04x val=0x%02x\n", addr, val);
+#endif
+
+qemu_chr_write(s->chr, &ch, 1);
+}
+
+
+static uint32_t debugcon_ioport_read(void *opaque, uint32_t addr)
+{
+DebugconState *s = opaque;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: read addr=0x%04x\n", addr, val);
+#endif
+
+return s->readback;
+}
+
+static void debugcon_init_core(DebugconState *s)
+{
+if (!s->chr) {
+fprintf(stderr, "Can't create debugcon device, empty char device\n");
+   exit(1);
+}
+
+qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
+}
+
+static int debugcon_isa_initfn(ISADevice *dev)
+{
+ISADebugconState *isa = DO_UPCAST(ISADebugconState, dev, dev);
+DebugconState *s = &isa->state;
+
+debugcon_init_core(s);
+register_ioport_write(isa->iobase, 1, 1, debugcon_ioport_write, s);
+register_ioport_read(isa->iobase, 1, 1, debugcon_ioport_read, s);
+return 0;
+}
+
+static ISADeviceInfo debugcon_isa_info = {
+.qdev.name  = "isa-debugcon",
+.qdev.size  = sizeof(ISADebugconState),
+.init   = debugcon_isa_initfn,
+.qde

Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-26 Thread Markus Armbruster
Gerd Hoffmann  writes:

> On 11/25/09 23:31, H. Peter Anvin wrote:
>> On 11/25/2009 02:26 PM, H. Peter Anvin wrote:
>>>
>>> As such, I think there is still a place for the simple command line
>>> options like "-hda", "-serial" and my proposed "-debugcon", in addition
>>> to the full-featured connect-anything options and configuration files.
>>> That's all.
>>>
>>
>> I guess one question is if the simplified options could be better
>> implemented via some kind of builtin macros or translation submodule
>> rather than being treated as first-class options which they basically
>> are now.  Still, that's a future development task.
>
> Wouldn't be that hard I think.  Something along the lines of
>
> case QEMU_OPTION_debugcon:
>  opts = qemu_chr_parse_compat("debugcon", optarg);
>  if (NULL == opts) {
>   fprintf(stderr, "already have a debugcon chardev\");
>   exit(1);
>  }
>  opts = qemu_opts_create(&qemu_device_opts, "debugcon", 1);
>  if (NULL == opts) {
>   fprintf(stderr, "already have a debugcon device\");
>   exit(1);
>  }
>  qemu_opt_set(opts, "driver", isa-debugcon);
>  qemu_opt_set(opts, "chardev", "debugcon");
>  break;
>
> should do the trick.  Depends on the chardev fix mentioned in this
> thread too.  Allows to define a single device with the default port
> via shortcut.

There's precedence for this method to implement convenience options;
look for uses of qemu_opts_create() / qemu_opt_set().  Expanding the
convenience option into longhand that way saves code and avoids subtle
differences between the two.  Just avoid NULL == opts kraxelism ;)

[...]




Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-25 Thread Gerd Hoffmann

On 11/25/09 23:31, H. Peter Anvin wrote:

On 11/25/2009 02:26 PM, H. Peter Anvin wrote:


As such, I think there is still a place for the simple command line
options like "-hda", "-serial" and my proposed "-debugcon", in addition
to the full-featured connect-anything options and configuration files.
That's all.



I guess one question is if the simplified options could be better
implemented via some kind of builtin macros or translation submodule
rather than being treated as first-class options which they basically
are now.  Still, that's a future development task.


Wouldn't be that hard I think.  Something along the lines of

case QEMU_OPTION_debugcon:
 opts = qemu_chr_parse_compat("debugcon", optarg);
 if (NULL == opts) {
  fprintf(stderr, "already have a debugcon chardev\");
  exit(1);
 }
 opts = qemu_opts_create(&qemu_device_opts, "debugcon", 1);
 if (NULL == opts) {
  fprintf(stderr, "already have a debugcon device\");
  exit(1);
 }
 qemu_opt_set(opts, "driver", isa-debugcon);
 qemu_opt_set(opts, "chardev", "debugcon");
 break;

should do the trick.  Depends on the chardev fix mentioned in this 
thread too.  Allows to define a single device with the default port via 
shortcut.


I tend to not add new command line switches for every little new device. 
 For this one it might be reasonable nevertheless given the use cases.


cheers,
  Gerd





[Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-25 Thread H. Peter Anvin
From: H. Peter Anvin 

Add generic support for debugging consoles (simple I/O ports which
when written to cause debugging output to be written to a target.)
The current implementation matches Bochs' port 0xe9, allowing the same
debugging code to be used for both Bochs and Qemu.

There is no vm state associated with the debugging port, simply
because it has none -- the entire interface is a single, stateless,
write-only port.

Most of the code was cribbed from the serial port driver.

v2: removed non-ISA variants (they can be introduced when/if someone
wants them, using code from the serial port); added configurable
readback (Bochs returns 0xe9 on a read from this register, mimic that
by default)  This retains the apparently somewhat controversial user
friendly option, however.

Signed-off-by: H. Peter Anvin 
---
 Makefile.target |2 +-
 hw/debugcon.c   |  118 +++
 hw/pc.c |6 +++
 hw/pc.h |4 ++
 qemu-common.h   |1 +
 qemu-options.hx |   11 +
 sysemu.h|6 +++
 vl.c|   40 +++
 8 files changed, 187 insertions(+), 1 deletions(-)
 create mode 100644 hw/debugcon.c

diff --git a/Makefile.target b/Makefile.target
index 2985658..df4a7b2 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -197,7 +197,7 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o 
pcspk.o pc.o
 obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
-obj-i386-y += ne2000-isa.o
+obj-i386-y += ne2000-isa.o debugcon.o
 
 # shared objects
 obj-ppc-y = ppc.o ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/macio.o
diff --git a/hw/debugcon.c b/hw/debugcon.c
new file mode 100644
index 000..a0c2923
--- /dev/null
+++ b/hw/debugcon.c
@@ -0,0 +1,118 @@
+/*
+ * QEMU Bochs-style debug console ("port E9") emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2008 Citrix Systems, Inc.
+ * Copyright (c) Intel Corporation; author: H. Peter Anvin
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw.h"
+#include "qemu-char.h"
+#include "isa.h"
+#include "pc.h"
+
+//#define DEBUG_DEBUGCON
+
+struct DebugconState {
+CharDriverState *chr;
+uint32_t readback;
+};
+
+typedef struct ISADebugconState {
+ISADevice dev;
+uint32_t iobase;
+DebugconState state;
+} ISADebugconState;
+
+static void debugcon_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+{
+DebugconState *s = opaque;
+unsigned char ch = val;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: write addr=0x%04x val=0x%02x\n", addr, val);
+#endif
+
+qemu_chr_write(s->chr, &ch, 1);
+}
+
+
+static uint32_t debugcon_ioport_read(void *opaque, uint32_t addr)
+{
+DebugconState *s = opaque;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: read addr=0x%04x\n", addr, val);
+#endif
+
+return s->readback;
+}
+
+static void debugcon_init_core(DebugconState *s)
+{
+if (!s->chr) {
+fprintf(stderr, "Can't create debugcon device, empty char device\n");
+   exit(1);
+}
+
+qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
+}
+
+static int debugcon_isa_initfn(ISADevice *dev)
+{
+ISADebugconState *isa = DO_UPCAST(ISADebugconState, dev, dev);
+DebugconState *s = &isa->state;
+
+debugcon_init_core(s);
+register_ioport_write(isa->iobase, 1, 1, debugcon_ioport_write, s);
+register_ioport_read(isa->iobase, 1, 1, debugcon_ioport_read, s);
+return 0;
+}
+
+DebugconState *debugcon_isa_init(int index, CharDriverState *chr)
+{
+ISADevice *dev;
+
+dev = isa_create("isa-debugcon");
+qdev_prop_set_chr(&dev->qdev, "chardev", chr);
+if (qdev_init(&dev->qdev) < 0)
+return NULL;
+return &DO_UPCAST(ISADebugconState, dev, dev)->state;
+}
+
+static ISADeviceInfo debugcon_isa_info 

Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-25 Thread H. Peter Anvin
On 11/25/2009 02:26 PM, H. Peter Anvin wrote:
> 
> As such, I think there is still a place for the simple command line
> options like "-hda", "-serial" and my proposed "-debugcon", in addition
> to the full-featured connect-anything options and configuration files.
> That's all.
> 

I guess one question is if the simplified options could be better
implemented via some kind of builtin macros or translation submodule
rather than being treated as first-class options which they basically
are now.  Still, that's a future development task.

-hpa





Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-25 Thread H. Peter Anvin
On 11/25/2009 02:21 PM, Gerd Hoffmann wrote:
> 
> You can happily mixup things as you like.  Use pure command line.  Use 
> pure config file (well, at least is that the plan, it doesn't fully work 
> yet).  Mix cmd line switches and config file.  Reading multiple config 
> files works just fine too, so you can split your vm config into multiple 
> parts and enable/disable parts by reading/not reading the file in 
> question ...
> 

Right, of course; I didn't mean to imply that your config file would
make the command line be unavailable, nor did I mean to imply that it
isn't useful (quite on the contrary.)

What I meant was that the presence of config file does not avoid the
user-hostility of options like "-chardev stdio,id=debug -device
isa-debugcon,chardev=debug" ... for a command line user, the situation
is still the same, and when using Qemu for debugging and testing, this
is one case when you would be likely to run into the command line.

As such, I think there is still a place for the simple command line
options like "-hda", "-serial" and my proposed "-debugcon", in addition
to the full-featured connect-anything options and configuration files.
That's all.

-hpa




Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-25 Thread Gerd Hoffmann

On 11/25/09 19:01, H. Peter Anvin wrote:

Gerd Hoffmann wrote:


You can stick it into a config file[1] like this:

[chardev "debuglog"]
backend = "file"
path = "/path/to/debug.log"

[device]
driver = "isa-debugcon"
chardev = "debuglog"

Then use "qemu -readconfig $file".



Great... at least in my opinion, one of the things that makes Qemu so
much easier to use than Bochs is that one has a comprehensive (and
comprehensable) command line and don't have to set up a configuration
file for every trivial little thing. It's a good thing for long-living
virtualization instances, but I would be sad if the command line will
end up being neglected.


You can happily mixup things as you like.  Use pure command line.  Use 
pure config file (well, at least is that the plan, it doesn't fully work 
yet).  Mix cmd line switches and config file.  Reading multiple config 
files works just fine too, so you can split your vm config into multiple 
parts and enable/disable parts by reading/not reading the file in 
question ...


cheers,
  Gerd




Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-25 Thread H. Peter Anvin

Gerd Hoffmann wrote:


You can stick it into a config file[1] like this:

[chardev "debuglog"]
  backend = "file"
  path = "/path/to/debug.log"

[device]
  driver = "isa-debugcon"
  chardev = "debuglog"

Then use "qemu -readconfig $file".



Great... at least in my opinion, one of the things that makes Qemu so 
much easier to use than Bochs is that one has a comprehensive (and 
comprehensable) command line and don't have to set up a configuration 
file for every trivial little thing.  It's a good thing for long-living 
virtualization instances, but I would be sad if the command line will 
end up being neglected.


-hpa





Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-25 Thread Gerd Hoffmann

On 11/25/09 00:05, H. Peter Anvin wrote:

On 11/23/2009 12:11 PM, H. Peter Anvin wrote:

On 11/23/2009 02:52 AM, Gerd Hoffmann wrote:


All not needed.  Simply registering as qdev device is enougth.  You can
then add a debug port like this, without adding new cmd line options:

-chardev vc,id=debug -device isa-debugcon,chardev=debug

Adding a second one on a non-default port works this way:

-chardev vc,id=d2 -device isa-debugcon,iobase=0xea,chardev=d2



Sure, but is that user friendly?



Question still stands... if this is The Way It Is Done, then I'll do it
that way, but I will personally never be able to remember to type the
above stuff without looking it up every time, whereas "-debugcon stdio"
is something I can remember in my sleep.


You can stick it into a config file[1] like this:

[chardev "debuglog"]
  backend = "file"
  path = "/path/to/debug.log"

[device]
  driver = "isa-debugcon"
  chardev = "debuglog"

Then use "qemu -readconfig $file".

cheers,
  Gerd

[1] Well, almost, fix to make this actually work went to the list today.




Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-24 Thread Alexander Graf

On 25.11.2009, at 00:05, H. Peter Anvin wrote:

> On 11/23/2009 12:11 PM, H. Peter Anvin wrote:
>> On 11/23/2009 02:52 AM, Gerd Hoffmann wrote:
>>> 
>>> All not needed.  Simply registering as qdev device is enougth.  You can 
>>> then add a debug port like this, without adding new cmd line options:
>>> 
>>>   -chardev vc,id=debug -device isa-debugcon,chardev=debug
>>> 
>>> Adding a second one on a non-default port works this way:
>>> 
>>>   -chardev vc,id=d2 -device isa-debugcon,iobase=0xea,chardev=d2
>>> 
>> 
>> Sure, but is that user friendly?
>> 
> 
> Question still stands... if this is The Way It Is Done, then I'll do it
> that way, but I will personally never be able to remember to type the
> above stuff without looking it up every time, whereas "-debugcon stdio"
> is something I can remember in my sleep.

I agree with hpa here. While the -device syntax is nice for development and 
hacky stuff, let's please not force any user to use it!

Alex



Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-24 Thread H. Peter Anvin
On 11/23/2009 12:11 PM, H. Peter Anvin wrote:
> On 11/23/2009 02:52 AM, Gerd Hoffmann wrote:
>>
>> All not needed.  Simply registering as qdev device is enougth.  You can 
>> then add a debug port like this, without adding new cmd line options:
>>
>>-chardev vc,id=debug -device isa-debugcon,chardev=debug
>>
>> Adding a second one on a non-default port works this way:
>>
>>-chardev vc,id=d2 -device isa-debugcon,iobase=0xea,chardev=d2
>>
> 
> Sure, but is that user friendly?
> 

Question still stands... if this is The Way It Is Done, then I'll do it
that way, but I will personally never be able to remember to type the
above stuff without looking it up every time, whereas "-debugcon stdio"
is something I can remember in my sleep.

-hpa




Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-23 Thread H. Peter Anvin
On 11/23/2009 02:52 AM, Gerd Hoffmann wrote:
> 
> All not needed.  Simply registering as qdev device is enougth.  You can 
> then add a debug port like this, without adding new cmd line options:
> 
>-chardev vc,id=debug -device isa-debugcon,chardev=debug
> 
> Adding a second one on a non-default port works this way:
> 
>-chardev vc,id=d2 -device isa-debugcon,iobase=0xea,chardev=d2
> 

Sure, but is that user friendly?

-hpa




Re: [Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-23 Thread Gerd Hoffmann

On 11/20/09 22:33, H. Peter Anvin wrote:


+static const uint16_t isa_debugcon_iobase[MAX_DEBUGCON_PORTS] = { 0xe9 };


Not needed here.


+if (isa->index == -1)
+isa->index = index;
+if (isa->index>= MAX_DEBUGCON_PORTS)
+return -1;
+if (isa->iobase == -1)
+   isa->iobase = isa_debugcon_iobase[isa->index];
+index++;


Also not needed.


+debugcon_init_core(s);
+register_ioport_write(isa->iobase, 1, 1, debugcon_ioport_write, s);
+return 0;
+}
+
+DebugconState *debugcon_isa_init(int index, CharDriverState *chr)
+{
+ISADevice *dev;
+
+dev = isa_create("isa-debugcon");
+qdev_prop_set_chr(&dev->qdev, "chardev", chr);
+if (qdev_init(&dev->qdev)<  0)
+return NULL;
+return&DO_UPCAST(ISADebugconState, dev, dev)->state;
+}


Can be dropped too.


+static ISADeviceInfo debugcon_isa_info = {
+.qdev.name  = "isa-debugcon",
+.qdev.size  = sizeof(ISADebugconState),
+.init   = debugcon_isa_initfn,
+.qdev.props = (Property[]) {
+DEFINE_PROP_HEX32("index",  ISADebugconState, index,   -1),


Drop index property.


+DEFINE_PROP_HEX32("iobase", ISADebugconState, iobase,  -1),


Last arg is the default value, simply place 0xe9 there.


+DEFINE_PROP_CHR("chardev",  ISADebugconState, state.chr),
+DEFINE_PROP_END_OF_LIST(),
+},
+};
+
+static void debugcon_register_devices(void)
+{
+isa_qdev_register(&debugcon_isa_info);
+}



diff --git a/hw/pc.c b/hw/pc.c
diff --git a/hw/pc.h b/hw/pc.h
diff --git a/qemu-common.h b/qemu-common.h
diff --git a/qemu-options.hx b/qemu-options.hx
diff --git a/sysemu.h b/sysemu.h
diff --git a/vl.c b/vl.c


All not needed.  Simply registering as qdev device is enougth.  You can 
then add a debug port like this, without adding new cmd line options:


  -chardev vc,id=debug -device isa-debugcon,chardev=debug

Adding a second one on a non-default port works this way:

  -chardev vc,id=d2 -device isa-debugcon,iobase=0xea,chardev=d2

cheers,
  Gerd




[Qemu-devel] [PATCH] debugcon: support for debugging consoles (e.g. Bochs port 0xe9)

2009-11-21 Thread H. Peter Anvin
Add generic support for debugging consoles (simple I/O ports which
when written to cause debugging output to be written to a target.)
The current implementation matches Bochs' port 0xe9, allowing the same
debugging code to be used for both Bochs and Qemu.

There is no vm state associated with the debugging port, simply
because it has none -- the entire interface is a single, stateless,
write-only port.

Most of the code was cribbed from the serial port driver.

Signed-off-by: H. Peter Anvin 
---
 Makefile.target |2 +-
 hw/debugcon.c   |  189 +++
 hw/pc.c |6 ++
 hw/pc.h |4 +
 qemu-common.h   |1 +
 qemu-options.hx |   11 +++
 sysemu.h|6 ++
 vl.c|   40 
 8 files changed, 258 insertions(+), 1 deletions(-)
 create mode 100644 hw/debugcon.c

diff --git a/Makefile.target b/Makefile.target
index ab774e5..689cbf0 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -197,7 +197,7 @@ obj-i386-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o 
pcspk.o pc.o
 obj-i386-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-i386-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
-obj-i386-y += ne2000-isa.o
+obj-i386-y += ne2000-isa.o debugcon.o
 
 # shared objects
 obj-ppc-y = ppc.o ide/core.o ide/qdev.o ide/isa.o ide/pci.o ide/macio.o
diff --git a/hw/debugcon.c b/hw/debugcon.c
new file mode 100644
index 000..6a724bb
--- /dev/null
+++ b/hw/debugcon.c
@@ -0,0 +1,189 @@
+/*
+ * QEMU Bochs-style debug console ("port E9") emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2008 Citrix Systems, Inc.
+ * Copyright (c) Intel Corporation; author: H. Peter Anvin
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw.h"
+#include "qemu-char.h"
+#include "isa.h"
+#include "pc.h"
+
+//#define DEBUG_DEBUGCON
+
+struct DebugconState {
+CharDriverState *chr;
+};
+
+typedef struct ISADebugconState {
+ISADevice dev;
+uint32_t index;
+uint32_t iobase;
+DebugconState state;
+} ISADebugconState;
+
+static void debugcon_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+{
+DebugconState *s = opaque;
+unsigned char ch = val;
+
+#ifdef DEBUG_DEBUGCON
+printf("debugcon: write addr=0x%04x val=0x%02x\n", addr, val);
+#endif
+
+qemu_chr_write(s->chr, &ch, 1);
+}
+
+static void debugcon_init_core(DebugconState *s)
+{
+if (!s->chr) {
+fprintf(stderr, "Can't create debugcon device, empty char device\n");
+   exit(1);
+}
+
+qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
+}
+
+static const uint16_t isa_debugcon_iobase[MAX_DEBUGCON_PORTS] = { 0xe9 };
+
+static int debugcon_isa_initfn(ISADevice *dev)
+{
+static int index;
+ISADebugconState *isa = DO_UPCAST(ISADebugconState, dev, dev);
+DebugconState *s = &isa->state;
+
+if (isa->index == -1)
+isa->index = index;
+if (isa->index >= MAX_DEBUGCON_PORTS)
+return -1;
+if (isa->iobase == -1)
+   isa->iobase = isa_debugcon_iobase[isa->index];
+index++;
+
+debugcon_init_core(s);
+register_ioport_write(isa->iobase, 1, 1, debugcon_ioport_write, s);
+return 0;
+}
+
+DebugconState *debugcon_isa_init(int index, CharDriverState *chr)
+{
+ISADevice *dev;
+
+dev = isa_create("isa-debugcon");
+qdev_prop_set_chr(&dev->qdev, "chardev", chr);
+if (qdev_init(&dev->qdev) < 0)
+return NULL;
+return &DO_UPCAST(ISADebugconState, dev, dev)->state;
+}
+
+#if 0 /* Non-ISA interfaces, available for the future */
+
+DebugconState *debugcon_init(int base, qemu_irq irq, int baudbase,
+ CharDriverState *chr)
+{
+DebugconState *s;
+
+s = qemu_mallocz(sizeof(DebugconState));
+
+s->chr = chr;
+debugcon_init_core(s);
+
+register_ioport_write(base, 8, 1, debugcon_ioport_writ