Skip to contentSkip to conversation

Implement PC port80 debug register.

PATCH In review Jordan Justen 8 participants 20 messages Jun 29, 2009 – Jul 9, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Implement PC port80 debug register.

From: jljusten <jljusten@jljusten-laptop.(none)>

In PC systems, the byte I/O port 0x80 is commonly made into a read/write byte. BIOS and/or system software will often use it as a simple checkpoint marker.

---
 Makefile.target |    2 +-
 hw/pc.c         |    6 +---
 hw/pc.h         |    7 ++++
 hw/port80.c     |   87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+), 6 deletions(-)
 create mode 100644 hw/port80.c
Makefile.target +1 -1
index a0f24fa..2173ce2 100644
@@ -572,7 +572,7 @@ OBJS += wdt_ib700.o wdt_i6300esb.o
 ifeq ($(TARGET_BASE_ARCH), i386)
 # Hardware support
 OBJS+= ide.o pckbd.o vga.o $(SOUND_HW) dma.o
-OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
+OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o port80.o pc.o
 OBJS+= cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 OBJS += device-hotplug.o pci-hotplug.o smbios.o
hw/pc.c +1 -5
index 86e5cfe..19d5017 100644
@@ -84,10 +84,6 @@ static void option_rom_setup_reset(target_phys_addr_t addr, unsigned size)
     qemu_register_reset(option_rom_reset, 0, rrd);
 }
 
-static void ioport80_write(void *opaque, uint32_t addr, uint32_t data)
-{
-}
-
 /* MSDOS compatibility mode FPU exception support */
 static qemu_irq ferr_irq;
 /* XXX: add IGNNE support */
@@ -1011,7 +1007,7 @@ static void pc_init1(ram_addr_t ram_size,
     }
 
     /* init basic PC hardware */
-    register_ioport_write(0x80, 1, 1, ioport80_write, NULL);
+    port80_init();
 
     register_ioport_write(0xf0, 1, 1, ioportF0_write, NULL);
 
hw/pc.h +7 -0
index 9fbae20..1d0423e 100644
@@ -166,4 +166,11 @@ void pci_piix4_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn,
 void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd);
 
 int cpu_is_bsp(CPUState *env);
+
+/* port80.c */
+
+typedef struct Port80State Port80State;
+
+Port80State *port80_init(void);
+
 #endif
hw/port80.c new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#1 lore raw
Quoted 6 lines · Jordan Justen

From: jljusten <jljusten@jljusten-laptop.(none)>

In PC systems, the byte I/O port 0x80 is commonly made into a read/write byte. BIOS and/or system software will often use it as a simple checkpoint marker.

What software does this? Typically, port80 is used as an IO delay mechanism. I'm not aware of it being used to read/write arbitrary data.

Regards,

Anthony Liguori

#2 lore raw
Quoted 9 lines · Anthony Liguori
Quoted 5 lines · Jordan Justen

From: jljusten <jljusten@jljusten-laptop.(none)>

In PC systems, the byte I/O port 0x80 is commonly made into a read/write byte. BIOS and/or system software will often use it as a simple checkpoint marker.

What software does this? Typically, port80 is used as an IO delay mechanism. I'm not aware of it being used to read/write arbitrary data.

Port 0x80 is generally the bios debug port. It's not uncommon for motherboards to display the values written to this port via an onboard 7-segment LED.

Paul

#3 lore raw
In reply to Anthony Liguori
Quoted 9 lines · Anthony Liguori
Quoted 5 lines · Jordan Justen

From: jljusten <jljusten@jljusten-laptop.(none)>

In PC systems, the byte I/O port 0x80 is commonly made into a read/write byte. BIOS and/or system software will often use it as a simple checkpoint marker.

What software does this? Typically, port80 is used as an IO delay mechanism. I'm not aware of it being used to read/write arbitrary data.

It's often used in BIOS code. There used to be seven-segment cards you'd plug into a computer that would show you port 80 in real time. I think it's a write-only port, though.

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Anthony Liguori
Quoted 2 lines · Jordan Justen

From: jljusten <jljusten@jljusten-laptop.(none)>

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

In PC systems, the byte I/O port 0x80 is commonly made into a read/write byte. BIOS and/or system software will often use it as a simple checkpoint marker.

What software does this? Typically, port80 is used as an IO delay mechanism. I'm not aware of it being used to read/write arbitrary data.

It's often used in BIOS code. There used to be seven-segment cards

s/used to be/are/

http://www.biosman.com/port80.htm

(although only for ISA/PCI slots, which may be hard to find on modern motherboards)

Quoted 2 lines

you'd plug into a computer that would show you port 80 in real time. I think it's a write-only port, though.

Signature · 1 line
Chris Lalancette
#5 lore raw
In reply to Avi Kivity

Avi,

Well, I am not sure if this it globally the case for PC motherboards, but in my experience, it has been read/write.

At least for a system such as qemu, it make it difficult to use the port80 checkpoint of software without being able to read the last value written.

-Jordan

Quoted 23 lines · Avi Kivity
Quoted 4 lines · Anthony Liguori
Quoted 2 lines · Jordan Justen

From: jljusten <jljusten@jljusten-laptop.(none)>

Quoted 9 lines
Quoted 4 lines

In PC systems, the byte I/O port 0x80 is commonly made into a read/write byte. BIOS and/or system software will often use it as a simple checkpoint marker.

What software does this? Typically, port80 is used as an IO delay mechanism. I'm not aware of it being used to read/write arbitrary data.

It's often used in BIOS code. There used to be seven-segment cards you'd plug into a computer that would show you port 80 in real time. I think it's a write-only port, though.

--
error compiling committee.c: too many arguments to function

#6 lore raw
Quoted 5 lines · Jordan Justen

Avi,

Well, I am not sure if this it globally the case for PC motherboards, but in my experience, it has been read/write.

At least for a system such as qemu, it make it difficult to use the port80 checkpoint of software without being able to read the last value written.

It seems like the more logical thing to do is to save the port80 write and have it obtainable via the monitor.

But really, we have other debug mechanisms for BIOSes (like ports 50x/40x). That seems like a better thing to use if you're writing custom code for QEMU.

Regards,

Anthony Liguori

#7 lore raw

Anthony,

That seems like a reasonable request.

So, a 'info port80' command would be preferable to having i/o port 0x80 be read/write?

I still think the read/write port route would
* better emulate systems,
* be more flexible (allowing software the option to read it),
* and, be easier to implement :)

But, I think the most important part is to make the data accessible somehow. So, the monitor access method would work fine as well.

-Jordan

Quoted 23 lines · Anthony Liguori
Quoted 8 lines · Jordan Justen

Avi,

Well, I am not sure if this it globally the case for PC motherboards, but in my experience, it has been read/write.

At least for a system such as qemu, it make it difficult to use the port80 checkpoint of software without being able to read the last value written.

It seems like the more logical thing to do is to save the port80 write and have it obtainable via the monitor.

But really, we have other debug mechanisms for BIOSes (like ports 50x/40x).
That seems like a better thing to use if you're writing custom code for
QEMU.

Regards,

Anthony Liguori

#8 lore raw
Quoted 6 lines · Jordan Justen

Anthony,

That seems like a reasonable request.

So, a 'info port80' command would be preferable to having i/o port 0x80 be read/write?

Maybe, info debug-port.

Quoted 6 lines

I still think the read/write port route would
* better emulate systems,
* be more flexible (allowing software the option to read it),
* and, be easier to implement :)

But, I think the most important part is to make the data accessible somehow. So, the monitor access method would work fine as well.

I don't object to read/write access.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#9 lore raw
Quoted 8 lines · Avi Kivity
Quoted 6 lines

I still think the read/write port route would
* better emulate systems,
* be more flexible (allowing software the option to read it),
* and, be easier to implement :)

But, I think the most important part is to make the data accessible somehow. So, the monitor access method would work fine as well.

I don't object to read/write access.

If there's read and write access, it needs to be part of the savevm state. Is it per-cpu? If it's write only, then it doesn't need to be persisted in savevm.

I'd lean toward write-only unless there was a compelling reason to make it read/write.

Regards,

Anthony Liguori

#10 lore raw
Quoted 11 lines · Anthony Liguori
Quoted 8 lines · Avi Kivity
Quoted 6 lines

I still think the read/write port route would
* better emulate systems,
* be more flexible (allowing software the option to read it),
* and, be easier to implement :)

But, I think the most important part is to make the data accessible somehow. So, the monitor access method would work fine as well.

I don't object to read/write access.

If there's read and write access, it needs to be part of the savevm state.

That's true even if it's write only, as long as it is observable somehow (in our case, from the monitor).

Quoted 1 line

Is it per-cpu?

No, it's a normal pci/isa card.

Quoted 1 line

I'd lean toward write-only unless there was a compelling reason to make it read/write.

I can't say there's a compelling reason for that.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#11 lore raw
In reply to Anthony Liguori
Quoted 6 lines · Anthony Liguori
Quoted 5 lines · Avi Kivity
Quoted 5 lines

I still think the read/write port route would
* better emulate systems,
* be more flexible (allowing software the option to read it),
* and, be easier to implement :)

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

But, I think the most important part is to make the data accessible somehow. So, the monitor access method would work fine as well.

I don't object to read/write access.

If there's read and write access, it needs to be part of the savevm state. Is it per-cpu? If it's write only, then it doesn't need to be persisted in savevm.

I'd lean toward write-only unless there was a compelling reason to make it read/write.

Well it was write-only before, so I don't see any harm in keeping it that way. Or am I mistaken there?

Alex

#12 lore raw
Quoted 2 lines · Alexander Graf

Well it was write-only before, so I don't see any harm in keeping it that way. Or am I mistaken there?

We could compromise by making even bits write-only and odd bits read-only.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#13 lore raw
In reply to Alexander Graf

Alex,

Well it was write-only before, so I don't see any harm in keeping it that

Quoted 2 lines

way. Or am I mistaken there?

As I noted, I have seen it be read/write on real systems. But, for qemu it was previously write-only and ignored.

-Jordan

Quoted 31 lines · Alexander Graf

On 29.06.2009, at 20:39, Anthony Liguori wrote:

Quoted 13 lines · Avi Kivity
Quoted 6 lines

I still think the read/write port route would

Quoted 4 lines

* better emulate systems,
* be more flexible (allowing software the option to read it),
* and, be easier to implement :)

Quoted 6 lines
Quoted 3 lines

But, I think the most important part is to make the data accessible somehow. So, the monitor access method would work fine as well.

I don't object to read/write access.

Quoted 7 lines

If there's read and write access, it needs to be part of the savevm state.
Is it per-cpu? If it's write only, then it doesn't need to be persisted in
savevm.

I'd lean toward write-only unless there was a compelling reason to make it read/write.

Well it was write-only before, so I don't see any harm in keeping it that way. Or am I mistaken there?

Alex

#14 lore raw
In reply to Anthony Liguori

Anthony,

If there's read and write access, it needs to be part of the savevm state.

Quoted 3 lines

Is it per-cpu? If it's write only, then it doesn't need to be persisted in
savevm.

I did implement and test the savevm/loadvm functionality.

-Jordan

Quoted 26 lines · Anthony Liguori
Quoted 11 lines · Avi Kivity

I still think the read/write port route would

Quoted 7 lines

* better emulate systems,
* be more flexible (allowing software the option to read it),
* and, be easier to implement :)

But, I think the most important part is to make the data accessible somehow. So, the monitor access method would work fine as well.

I don't object to read/write access.

If there's read and write access, it needs to be part of the savevm state.
Is it per-cpu? If it's write only, then it doesn't need to be persisted in
savevm.

I'd lean toward write-only unless there was a compelling reason to make it read/write.

Regards,

Anthony Liguori

#15 lore raw

PATCH 1/1 Implement PC port80 debug register.

In reply to Anthony Liguori

In PC systems, the byte I/O port 0x80 is commonly written to by BIOS and/or system software as a simple checkpoint method.

This change adds an 'info port80' monitor command to retrieve the last value written out to port80.

---
 Makefile.target |    2 +-
 hw/pc.c         |    6 +---
 hw/pc.h         |    7 ++++
 hw/port80.c     |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 monitor.c       |    6 +++
 5 files changed, 119 insertions(+), 6 deletions(-)
 create mode 100644 hw/port80.c
Makefile.target +1 -1
index a593503..155d9c3 100644
@@ -563,7 +563,7 @@ obj-y += wdt_ib700.o wdt_i6300esb.o
 ifeq ($(TARGET_BASE_ARCH), i386)
 # Hardware support
 obj-y += ide.o pckbd.o vga.o $(sound-obj-y) dma.o
-obj-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
+obj-y += fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o port80.o pc.o
 obj-y += cirrus_vga.o apic.o ioapic.o parallel.o acpi.o piix_pci.o
 obj-y += usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
 obj-y += device-hotplug.o pci-hotplug.o smbios.o
hw/pc.c +1 -5
index 553ba5c..95ea295 100644
@@ -87,10 +87,6 @@ static void option_rom_setup_reset(target_phys_addr_t addr, unsigned size)
     qemu_register_reset(option_rom_reset, rrd);
 }
 
-static void ioport80_write(void *opaque, uint32_t addr, uint32_t data)
-{
-}
-
 /* MSDOS compatibility mode FPU exception support */
 static qemu_irq ferr_irq;
 /* XXX: add IGNNE support */
@@ -1253,7 +1249,7 @@ static void pc_init1(ram_addr_t ram_size,
     }
 
     /* init basic PC hardware */
-    register_ioport_write(0x80, 1, 1, ioport80_write, NULL);
+    port80_init();
 
     register_ioport_write(0xf0, 1, 1, ioportF0_write, NULL);
 
hw/pc.h +7 -0
index 9fbae20..1d0423e 100644
@@ -166,4 +166,11 @@ void pci_piix4_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn,
 void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd);
 
 int cpu_is_bsp(CPUState *env);
+
+/* port80.c */
+
+typedef struct Port80State Port80State;
+
+Port80State *port80_init(void);
+
 #endif
hw/port80.c new file +104 -0

104 lines not on this page · raw message

monitor.c +6 -0
index bad79fe..a128d43 100644
@@ -1677,6 +1677,10 @@ static void do_acl_remove(Monitor *mon, const char *aclname, const char *match)
     }
 }
 
+#if defined(TARGET_I386)
+void do_monitor_info_port80(Monitor *mon);
+#endif
+
 static const mon_cmd_t mon_cmds[] = {
 #include "qemu-monitor.h"
     { NULL, NULL, },
@@ -1715,6 +1719,8 @@ static const mon_cmd_t info_cmds[] = {
       "", "show the active virtual memory mappings", },
     { "hpet", "", do_info_hpet,
       "", "show state of HPET", },
+    { "port80", "", do_monitor_info_port80,
+      "", "show value of the last write to i/o port 0x80", },
 #endif
     { "jit", "", do_info_jit,
       "", "show dynamic compiler info", },
Signature · 1 line
1.6.0.4
#16 lore raw
Quoted 6 lines · Jordan Justen

In PC systems, the byte I/O port 0x80 is commonly written to by BIOS and/or system software as a simple checkpoint method.

This change adds an 'info port80' monitor command to retrieve the last value written out to port80.

Avi had suggested something like info debugreg. I think something like that would be better as using the name "port80" makes it a very i386 centric monitor option.

hw/pc.c static void pc_init1(ram_addr_t ram_size, · line 1252

Quoted 5 lines
 
     /* init basic PC hardware */
hw/pc.c +1 -1
-    register_ioport_write(0x80, 1, 1, ioport80_write, NULL);
+    port80_init();

We really ought to make this a SysBus qdev device. To do this, right here you would call:

sysbus_create_simple("pc,port80", -1, NULL);

Quoted 8 lines
     register_ioport_write(0xf0, 1, 1, ioportF0_write, NULL);
hw/pc.h +0 -0
index 9fbae20..1d0423e 100644
@@ -166,4 +166,11 @@ void pci_piix4_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn,
 void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd);

hw/pc.h void pci_piix4_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn, · line 176

Quoted 10 lines
hw/pc.h +7 -0
 
 int cpu_is_bsp(CPUState *env);
+
+/* port80.c */
+
+typedef struct Port80State Port80State;
+
+Port80State *port80_init(void);
+
 

You would no longer need this.

Quoted 32 lines

#endif

hw/port80.c new file +24 -0
new file mode 100644
index 0000000..947b3cd
@@ -0,0 +1,104 @@
+/*
+ * QEMU debug port 80 emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2009 Jordan Justen
+ *
+ * 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.
+ */

hw/port80.c line 34

Quoted 10 lines
hw/port80.c new file +10 -0
+#include "hw.h"
+#include "sysemu.h"
+#include "pc.h"
+#include "isa.h"
+#include "monitor.h"
+
+void do_monitor_info_port80(Monitor *mon);
+
+//#define DEBUG_PORT80
+//#define PORT80_READ_SUPPORT

I'd rather not have the device model change based on #defines. Either remove read support or enable it unconditionally.

hw/port80.c line 38

Quoted 3 lines
hw/port80.c new file +3 -0
+struct Port80State {
+    uint8_t data;
+};

Add a SysBusDevice to this.

hw/port80.c line 89

Quoted 2 lines
hw/port80.c new file +1 -0
+Port80State *port80_init()

This becomes:

static void port80_init(SysBusDevice *dev)

hw/port80.c line 94

Quoted 6 lines
hw/port80.c new file +5 -0
+{
+    Port80State *s;
+
+    s = qemu_mallocz(sizeof(Port80State));
+    state = s;

This becomes:

s = FROM_SYSBUS(Port80State, dev);

hw/port80.c line 103

Quoted 9 lines
hw/port80.c new file +8 -0
+    register_ioport_write(0x80, 1, 1, port80_ioport_write, s);
+#ifdef PORT80_READ_SUPPORT
+    register_ioport_read(0x80, 1, 1, port80_ioport_read, s);
+#endif
+
+    register_savevm("port80", 0x80, 1, port80_save, port80_load, s);
+    return s;
+}

Then you need to add a device_init() that calls sysbus_register_dev().

Regards,

Anthony Liguori

#17 lore raw
In reply to Jordan Justen
Quoted 3 lines · Jordan Justen

Avi,

Well, I am not sure if this it globally the case for PC motherboards, but in my experience, it has been read/write.

It's just some random memory that might not actually be grounded in reality.

Quoted 2 lines

At least for a system such as qemu, it make it difficult to use the port80 checkpoint of software without being able to read the last value written.

Why would software ever need to read it? You want a monitor command so the user can read it. I don't recall ever seeing a read of port 80 (I don't have any objections to that though).

Signature · 1 line
error compiling committee.c: too many arguments to function
#18 lore raw
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Jordan Justen

Avi,

Well, I am not sure if this it globally the case for PC motherboards, but in my experience, it has been read/write.

It's just some random memory that might not actually be grounded in reality.

It is not memory, and it's not even an I/O port.

On many PCs, at least historically, it resolves to an ISA bus cycle which no device responds to, and therefore takes about 1 microsecond with side effects which help some ISA devices (on other I/O ports) to work. Including 2MHz ISA devices on an 8MHz ISA bus... so it has to be a port which isn't on the device it's helping :-)

(Good) modern chipsets tend to not need the delay or side effects, but they emulate the delay anyway.

When an ISA BIOS POST debugging card is plugged in, or if there's one on the motherboard, then it catches the writes and displays them as hex on LEDs. That changes the timing and can in principle break some things...

Some Linux distros write to port 0xed instead of 0x80 now, because some HP/Compaq laptops break when writing to port 0x80 after ACPI is enabled. (Silly BIOS bugs). But 0xed breaks some old ISA systems, because it doesn't have quite the same bus side effects. Enjoy.

Quoted 7 lines
Quoted 3 lines

At least for a system such as qemu, it make it difficult to use the port80 checkpoint of software without being able to read the last value written.

Why would software ever need to read it? You want a monitor command so the user can read it. I don't recall ever seeing a read of port 80 (I don't have any objections to that though).

Because most ISA PCs don't have anything there, reading won't return anything interesting. It won't return the value written.

But maybe with a BIOS POST debugging card, and/or maybe with some chipsets which are emulating the port... I don't know.

-- Jamie

#19 lore raw
In reply to Avi Kivity
Quoted 7 lines · Avi Kivity
Quoted 2 lines · Jordan Justen

Well, I am not sure if this it globally the case for PC motherboards, but in my experience, it has been read/write.

Why would software ever need to read it? You want a monitor command so the user can read it. I don't recall ever seeing a read of port 80 (I don't have any objections to that though).

AFAIK some Linux versions use port 0x80 reads (instead of writes) for some delays (grep for REALLY_SLOW_IO) because some hardware vendors started abusing writes to port 0x80 for communication with embedded controllers.

Regards,
Carl-Daniel

Signature · 1 line
http://www.hailfinger.org/