2004-03-14 15:20:30 +03:00
|
|
|
/*
|
|
|
|
* QEMU PC keyboard emulation
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2004-03-14 15:20:30 +03:00
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2004-03-14 15:20:30 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
2019-08-12 08:23:38 +03:00
|
|
|
|
2016-01-26 21:17:30 +03:00
|
|
|
#include "qemu/osdep.h"
|
2021-05-25 21:14:35 +03:00
|
|
|
#include "qemu/error-report.h"
|
2018-06-26 19:50:40 +03:00
|
|
|
#include "qemu/log.h"
|
2021-05-25 21:14:35 +03:00
|
|
|
#include "qemu/timer.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/isa/isa.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2020-06-19 12:18:59 +03:00
|
|
|
#include "hw/acpi/aml-build.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/input/ps2.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.h"
|
2018-03-09 01:39:24 +03:00
|
|
|
#include "hw/input/i8042.h"
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-08-12 08:23:38 +03:00
|
|
|
#include "sysemu/reset.h"
|
2019-08-12 08:23:59 +03:00
|
|
|
#include "sysemu/runstate.h"
|
2004-03-14 15:20:30 +03:00
|
|
|
|
2018-10-16 14:22:32 +03:00
|
|
|
#include "trace.h"
|
2004-03-14 15:20:30 +03:00
|
|
|
|
|
|
|
/* Keyboard Controller Commands */
|
|
|
|
#define KBD_CCMD_READ_MODE 0x20 /* Read mode bits */
|
|
|
|
#define KBD_CCMD_WRITE_MODE 0x60 /* Write mode bits */
|
|
|
|
#define KBD_CCMD_GET_VERSION 0xA1 /* Get controller version */
|
|
|
|
#define KBD_CCMD_MOUSE_DISABLE 0xA7 /* Disable mouse interface */
|
|
|
|
#define KBD_CCMD_MOUSE_ENABLE 0xA8 /* Enable mouse interface */
|
|
|
|
#define KBD_CCMD_TEST_MOUSE 0xA9 /* Mouse interface test */
|
|
|
|
#define KBD_CCMD_SELF_TEST 0xAA /* Controller self test */
|
|
|
|
#define KBD_CCMD_KBD_TEST 0xAB /* Keyboard interface test */
|
|
|
|
#define KBD_CCMD_KBD_DISABLE 0xAD /* Keyboard interface disable */
|
|
|
|
#define KBD_CCMD_KBD_ENABLE 0xAE /* Keyboard interface enable */
|
|
|
|
#define KBD_CCMD_READ_INPORT 0xC0 /* read input port */
|
|
|
|
#define KBD_CCMD_READ_OUTPORT 0xD0 /* read output port */
|
|
|
|
#define KBD_CCMD_WRITE_OUTPORT 0xD1 /* write output port */
|
|
|
|
#define KBD_CCMD_WRITE_OBUF 0xD2
|
|
|
|
#define KBD_CCMD_WRITE_AUX_OBUF 0xD3 /* Write to output buffer as if
|
2018-12-14 01:37:37 +03:00
|
|
|
initiated by the auxiliary device */
|
2004-03-14 15:20:30 +03:00
|
|
|
#define KBD_CCMD_WRITE_MOUSE 0xD4 /* Write the following byte to the mouse */
|
|
|
|
#define KBD_CCMD_DISABLE_A20 0xDD /* HP vectra only ? */
|
|
|
|
#define KBD_CCMD_ENABLE_A20 0xDF /* HP vectra only ? */
|
2010-08-19 16:52:12 +04:00
|
|
|
#define KBD_CCMD_PULSE_BITS_3_0 0xF0 /* Pulse bits 3-0 of the output port P2. */
|
|
|
|
#define KBD_CCMD_RESET 0xFE /* Pulse bit 0 of the output port P2 = CPU reset. */
|
|
|
|
#define KBD_CCMD_NO_OP 0xFF /* Pulse no bits of the output port P2. */
|
2004-03-14 15:20:30 +03:00
|
|
|
|
|
|
|
/* Keyboard Commands */
|
|
|
|
#define KBD_CMD_SET_LEDS 0xED /* Set keyboard leds */
|
|
|
|
#define KBD_CMD_ECHO 0xEE
|
|
|
|
#define KBD_CMD_GET_ID 0xF2 /* get keyboard ID */
|
|
|
|
#define KBD_CMD_SET_RATE 0xF3 /* Set typematic rate */
|
|
|
|
#define KBD_CMD_ENABLE 0xF4 /* Enable scanning */
|
|
|
|
#define KBD_CMD_RESET_DISABLE 0xF5 /* reset and disable scanning */
|
|
|
|
#define KBD_CMD_RESET_ENABLE 0xF6 /* reset and enable scanning */
|
|
|
|
#define KBD_CMD_RESET 0xFF /* Reset */
|
|
|
|
|
|
|
|
/* Keyboard Replies */
|
|
|
|
#define KBD_REPLY_POR 0xAA /* Power on reset */
|
|
|
|
#define KBD_REPLY_ACK 0xFA /* Command ACK */
|
|
|
|
#define KBD_REPLY_RESEND 0xFE /* Command NACK, send the cmd again */
|
|
|
|
|
|
|
|
/* Status Register Bits */
|
|
|
|
#define KBD_STAT_OBF 0x01 /* Keyboard output buffer full */
|
|
|
|
#define KBD_STAT_IBF 0x02 /* Keyboard input buffer full */
|
|
|
|
#define KBD_STAT_SELFTEST 0x04 /* Self test successful */
|
|
|
|
#define KBD_STAT_CMD 0x08 /* Last write was a command write (0=data) */
|
|
|
|
#define KBD_STAT_UNLOCKED 0x10 /* Zero if keyboard locked */
|
|
|
|
#define KBD_STAT_MOUSE_OBF 0x20 /* Mouse output buffer full */
|
|
|
|
#define KBD_STAT_GTO 0x40 /* General receive/xmit timeout */
|
|
|
|
#define KBD_STAT_PERR 0x80 /* Parity error */
|
|
|
|
|
|
|
|
/* Controller Mode Register Bits */
|
|
|
|
#define KBD_MODE_KBD_INT 0x01 /* Keyboard data generate IRQ1 */
|
|
|
|
#define KBD_MODE_MOUSE_INT 0x02 /* Mouse data generate IRQ12 */
|
|
|
|
#define KBD_MODE_SYS 0x04 /* The system flag (?) */
|
|
|
|
#define KBD_MODE_NO_KEYLOCK 0x08 /* The keylock doesn't affect the keyboard if set */
|
|
|
|
#define KBD_MODE_DISABLE_KBD 0x10 /* Disable keyboard interface */
|
|
|
|
#define KBD_MODE_DISABLE_MOUSE 0x20 /* Disable mouse interface */
|
|
|
|
#define KBD_MODE_KCC 0x40 /* Scan code conversion to PC format */
|
|
|
|
#define KBD_MODE_RFU 0x80
|
|
|
|
|
2010-05-22 11:59:01 +04:00
|
|
|
/* Output Port Bits */
|
|
|
|
#define KBD_OUT_RESET 0x01 /* 1=normal mode, 0=reset */
|
|
|
|
#define KBD_OUT_A20 0x02 /* x86 only */
|
|
|
|
#define KBD_OUT_OBF 0x10 /* Keyboard output buffer full */
|
|
|
|
#define KBD_OUT_MOUSE_OBF 0x20 /* Mouse output buffer full */
|
|
|
|
|
2014-12-22 10:55:19 +03:00
|
|
|
/* OSes typically write 0xdd/0xdf to turn the A20 line off and on.
|
|
|
|
* We make the default value of the outport include these four bits,
|
|
|
|
* so that the subsection is rarely necessary.
|
|
|
|
*/
|
|
|
|
#define KBD_OUT_ONES 0xcc
|
|
|
|
|
2004-03-14 15:20:30 +03:00
|
|
|
/* Mouse Commands */
|
|
|
|
#define AUX_SET_SCALE11 0xE6 /* Set 1:1 scaling */
|
|
|
|
#define AUX_SET_SCALE21 0xE7 /* Set 2:1 scaling */
|
|
|
|
#define AUX_SET_RES 0xE8 /* Set resolution */
|
|
|
|
#define AUX_GET_SCALE 0xE9 /* Get scaling factor */
|
|
|
|
#define AUX_SET_STREAM 0xEA /* Set stream mode */
|
|
|
|
#define AUX_POLL 0xEB /* Poll */
|
|
|
|
#define AUX_RESET_WRAP 0xEC /* Reset wrap mode */
|
|
|
|
#define AUX_SET_WRAP 0xEE /* Set wrap mode */
|
|
|
|
#define AUX_SET_REMOTE 0xF0 /* Set remote mode */
|
|
|
|
#define AUX_GET_TYPE 0xF2 /* Get type */
|
|
|
|
#define AUX_SET_SAMPLE 0xF3 /* Set sample rate */
|
|
|
|
#define AUX_ENABLE_DEV 0xF4 /* Enable aux device */
|
|
|
|
#define AUX_DISABLE_DEV 0xF5 /* Disable aux device */
|
|
|
|
#define AUX_SET_DEFAULT 0xF6
|
|
|
|
#define AUX_RESET 0xFF /* Reset aux device */
|
|
|
|
#define AUX_ACK 0xFA /* Command byte ACK. */
|
|
|
|
|
|
|
|
#define MOUSE_STATUS_REMOTE 0x40
|
|
|
|
#define MOUSE_STATUS_ENABLED 0x20
|
|
|
|
#define MOUSE_STATUS_SCALE21 0x10
|
|
|
|
|
2005-11-26 13:14:03 +03:00
|
|
|
#define KBD_PENDING_KBD 1
|
|
|
|
#define KBD_PENDING_AUX 2
|
2004-03-14 15:20:30 +03:00
|
|
|
|
2021-05-25 21:14:35 +03:00
|
|
|
#define KBD_MIGR_TIMER_PENDING 0x1
|
|
|
|
|
2021-05-25 21:14:36 +03:00
|
|
|
#define KBD_OBSRC_KBD 0x01
|
|
|
|
#define KBD_OBSRC_MOUSE 0x02
|
|
|
|
|
2004-03-14 15:20:30 +03:00
|
|
|
typedef struct KBDState {
|
|
|
|
uint8_t write_cmd; /* if non zero, write data to port 60 is expected */
|
|
|
|
uint8_t status;
|
|
|
|
uint8_t mode;
|
2010-05-22 11:59:01 +04:00
|
|
|
uint8_t outport;
|
2021-05-25 21:14:35 +03:00
|
|
|
uint32_t migration_flags;
|
2021-05-25 21:14:36 +03:00
|
|
|
uint32_t obsrc;
|
2014-08-28 15:19:14 +04:00
|
|
|
bool outport_present;
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
bool extended_state;
|
2021-05-25 21:14:36 +03:00
|
|
|
bool extended_state_loaded;
|
2005-11-26 13:14:03 +03:00
|
|
|
/* Bitmask of devices with data available. */
|
2006-04-08 18:12:31 +04:00
|
|
|
uint8_t pending;
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
uint8_t obdata;
|
2005-11-26 13:14:03 +03:00
|
|
|
void *kbd;
|
|
|
|
void *mouse;
|
2021-05-25 21:14:35 +03:00
|
|
|
QEMUTimer *throttle_timer;
|
2007-02-18 03:08:44 +03:00
|
|
|
|
2007-04-07 22:14:41 +04:00
|
|
|
qemu_irq irq_kbd;
|
|
|
|
qemu_irq irq_mouse;
|
2016-06-22 15:24:51 +03:00
|
|
|
qemu_irq a20_out;
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr mask;
|
2004-03-14 15:20:30 +03:00
|
|
|
} KBDState;
|
|
|
|
|
|
|
|
/* XXX: not generating the irqs if KBD_MODE_DISABLE_KBD is set may be
|
|
|
|
incorrect, but it avoids having to simulate exact delays */
|
2021-05-25 21:14:33 +03:00
|
|
|
static void kbd_update_irq_lines(KBDState *s)
|
2004-03-14 15:20:30 +03:00
|
|
|
{
|
2007-02-18 03:08:44 +03:00
|
|
|
int irq_kbd_level, irq_mouse_level;
|
2004-03-14 15:20:30 +03:00
|
|
|
|
2007-02-18 03:08:44 +03:00
|
|
|
irq_kbd_level = 0;
|
|
|
|
irq_mouse_level = 0;
|
2021-05-25 21:14:33 +03:00
|
|
|
|
|
|
|
if (s->status & KBD_STAT_OBF) {
|
|
|
|
if (s->status & KBD_STAT_MOUSE_OBF) {
|
|
|
|
if (s->mode & KBD_MODE_MOUSE_INT) {
|
|
|
|
irq_mouse_level = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((s->mode & KBD_MODE_KBD_INT) &&
|
|
|
|
!(s->mode & KBD_MODE_DISABLE_KBD)) {
|
|
|
|
irq_kbd_level = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qemu_set_irq(s->irq_kbd, irq_kbd_level);
|
|
|
|
qemu_set_irq(s->irq_mouse, irq_mouse_level);
|
|
|
|
}
|
|
|
|
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
static void kbd_deassert_irq(KBDState *s)
|
|
|
|
{
|
|
|
|
s->status &= ~(KBD_STAT_OBF | KBD_STAT_MOUSE_OBF);
|
|
|
|
s->outport &= ~(KBD_OUT_OBF | KBD_OUT_MOUSE_OBF);
|
|
|
|
kbd_update_irq_lines(s);
|
|
|
|
}
|
|
|
|
|
2021-05-25 21:14:33 +03:00
|
|
|
/* update irq and KBD_STAT_[MOUSE_]OBF */
|
|
|
|
static void kbd_update_irq(KBDState *s)
|
|
|
|
{
|
2004-03-14 15:20:30 +03:00
|
|
|
s->status &= ~(KBD_STAT_OBF | KBD_STAT_MOUSE_OBF);
|
2010-05-22 11:59:01 +04:00
|
|
|
s->outport &= ~(KBD_OUT_OBF | KBD_OUT_MOUSE_OBF);
|
2005-11-26 13:14:03 +03:00
|
|
|
if (s->pending) {
|
2004-03-14 15:20:30 +03:00
|
|
|
s->status |= KBD_STAT_OBF;
|
2010-05-22 11:59:01 +04:00
|
|
|
s->outport |= KBD_OUT_OBF;
|
2005-11-26 13:14:03 +03:00
|
|
|
if (s->pending == KBD_PENDING_AUX) {
|
2004-03-14 15:20:30 +03:00
|
|
|
s->status |= KBD_STAT_MOUSE_OBF;
|
2010-05-22 11:59:01 +04:00
|
|
|
s->outport |= KBD_OUT_MOUSE_OBF;
|
2021-05-25 21:14:36 +03:00
|
|
|
s->obsrc = KBD_OBSRC_MOUSE;
|
|
|
|
} else {
|
|
|
|
s->obsrc = KBD_OBSRC_KBD;
|
2004-03-14 15:20:30 +03:00
|
|
|
}
|
|
|
|
}
|
2021-05-25 21:14:33 +03:00
|
|
|
kbd_update_irq_lines(s);
|
2004-03-14 15:20:30 +03:00
|
|
|
}
|
|
|
|
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
static void kbd_safe_update_irq(KBDState *s)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* with KBD_STAT_OBF set, a call to kbd_read_data() will eventually call
|
|
|
|
* kbd_update_irq()
|
|
|
|
*/
|
|
|
|
if (s->status & KBD_STAT_OBF) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-25 21:14:35 +03:00
|
|
|
/* the throttle timer is pending and will call kbd_update_irq() */
|
|
|
|
if (s->throttle_timer && timer_pending(s->throttle_timer)) {
|
|
|
|
return;
|
|
|
|
}
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
if (s->pending) {
|
|
|
|
kbd_update_irq(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-26 13:14:03 +03:00
|
|
|
static void kbd_update_kbd_irq(void *opaque, int level)
|
2004-03-14 15:20:30 +03:00
|
|
|
{
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
KBDState *s = opaque;
|
2004-03-14 15:20:30 +03:00
|
|
|
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
if (level) {
|
2005-11-26 13:14:03 +03:00
|
|
|
s->pending |= KBD_PENDING_KBD;
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
} else {
|
2005-11-26 13:14:03 +03:00
|
|
|
s->pending &= ~KBD_PENDING_KBD;
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
}
|
|
|
|
kbd_safe_update_irq(s);
|
2004-03-14 15:20:30 +03:00
|
|
|
}
|
|
|
|
|
2005-11-26 13:14:03 +03:00
|
|
|
static void kbd_update_aux_irq(void *opaque, int level)
|
2004-03-14 15:20:30 +03:00
|
|
|
{
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
KBDState *s = opaque;
|
2005-11-26 13:14:03 +03:00
|
|
|
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
if (level) {
|
2005-11-26 13:14:03 +03:00
|
|
|
s->pending |= KBD_PENDING_AUX;
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
} else {
|
2005-11-26 13:14:03 +03:00
|
|
|
s->pending &= ~KBD_PENDING_AUX;
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
}
|
|
|
|
kbd_safe_update_irq(s);
|
2004-03-14 15:20:30 +03:00
|
|
|
}
|
|
|
|
|
2021-05-25 21:14:35 +03:00
|
|
|
static void kbd_throttle_timeout(void *opaque)
|
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
|
|
|
|
if (s->pending) {
|
|
|
|
kbd_update_irq(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-08 15:30:08 +04:00
|
|
|
static uint64_t kbd_read_status(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
2004-03-14 15:20:30 +03:00
|
|
|
{
|
2004-03-15 00:46:48 +03:00
|
|
|
KBDState *s = opaque;
|
2004-03-14 15:20:30 +03:00
|
|
|
int val;
|
|
|
|
val = s->status;
|
2018-10-16 14:22:32 +03:00
|
|
|
trace_pckbd_kbd_read_status(val);
|
2004-03-14 15:20:30 +03:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2005-11-26 13:14:03 +03:00
|
|
|
static void kbd_queue(KBDState *s, int b, int aux)
|
|
|
|
{
|
|
|
|
if (aux)
|
|
|
|
ps2_queue(s->mouse, b);
|
|
|
|
else
|
|
|
|
ps2_queue(s->kbd, b);
|
|
|
|
}
|
|
|
|
|
2011-01-06 21:24:35 +03:00
|
|
|
static void outport_write(KBDState *s, uint32_t val)
|
2010-05-22 11:59:01 +04:00
|
|
|
{
|
2018-10-16 14:22:32 +03:00
|
|
|
trace_pckbd_outport_write(val);
|
2010-05-22 11:59:01 +04:00
|
|
|
s->outport = val;
|
2016-06-22 15:24:51 +03:00
|
|
|
qemu_set_irq(s->a20_out, (val >> 1) & 1);
|
2010-05-22 11:59:01 +04:00
|
|
|
if (!(val & 1)) {
|
2017-05-16 00:41:13 +03:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2010-05-22 11:59:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-08 15:30:08 +04:00
|
|
|
static void kbd_write_command(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
2004-03-14 15:20:30 +03:00
|
|
|
{
|
2004-03-15 00:46:48 +03:00
|
|
|
KBDState *s = opaque;
|
2004-03-14 15:20:30 +03:00
|
|
|
|
2018-10-16 14:22:32 +03:00
|
|
|
trace_pckbd_kbd_write_command(val);
|
2010-08-19 16:52:12 +04:00
|
|
|
|
|
|
|
/* Bits 3-0 of the output port P2 of the keyboard controller may be pulsed
|
|
|
|
* low for approximately 6 micro seconds. Bits 3-0 of the KBD_CCMD_PULSE
|
|
|
|
* command specify the output port bits to be pulsed.
|
|
|
|
* 0: Bit should be pulsed. 1: Bit should not be modified.
|
|
|
|
* The only useful version of this command is pulsing bit 0,
|
|
|
|
* which does a CPU reset.
|
|
|
|
*/
|
|
|
|
if((val & KBD_CCMD_PULSE_BITS_3_0) == KBD_CCMD_PULSE_BITS_3_0) {
|
|
|
|
if(!(val & 1))
|
|
|
|
val = KBD_CCMD_RESET;
|
|
|
|
else
|
|
|
|
val = KBD_CCMD_NO_OP;
|
|
|
|
}
|
|
|
|
|
2004-03-14 15:20:30 +03:00
|
|
|
switch(val) {
|
|
|
|
case KBD_CCMD_READ_MODE:
|
2008-07-19 18:16:20 +04:00
|
|
|
kbd_queue(s, s->mode, 0);
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_MODE:
|
|
|
|
case KBD_CCMD_WRITE_OBUF:
|
|
|
|
case KBD_CCMD_WRITE_AUX_OBUF:
|
|
|
|
case KBD_CCMD_WRITE_MOUSE:
|
|
|
|
case KBD_CCMD_WRITE_OUTPORT:
|
|
|
|
s->write_cmd = val;
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_MOUSE_DISABLE:
|
|
|
|
s->mode |= KBD_MODE_DISABLE_MOUSE;
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_MOUSE_ENABLE:
|
|
|
|
s->mode &= ~KBD_MODE_DISABLE_MOUSE;
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_TEST_MOUSE:
|
|
|
|
kbd_queue(s, 0x00, 0);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_SELF_TEST:
|
|
|
|
s->status |= KBD_STAT_SELFTEST;
|
|
|
|
kbd_queue(s, 0x55, 0);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_KBD_TEST:
|
|
|
|
kbd_queue(s, 0x00, 0);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_KBD_DISABLE:
|
|
|
|
s->mode |= KBD_MODE_DISABLE_KBD;
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_KBD_ENABLE:
|
|
|
|
s->mode &= ~KBD_MODE_DISABLE_KBD;
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
kbd_safe_update_irq(s);
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_READ_INPORT:
|
2014-02-12 02:46:03 +04:00
|
|
|
kbd_queue(s, 0x80, 0);
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_READ_OUTPORT:
|
2010-05-22 11:59:01 +04:00
|
|
|
kbd_queue(s, s->outport, 0);
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_ENABLE_A20:
|
2016-06-22 15:24:51 +03:00
|
|
|
qemu_irq_raise(s->a20_out);
|
2010-05-22 11:59:01 +04:00
|
|
|
s->outport |= KBD_OUT_A20;
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_DISABLE_A20:
|
2016-06-22 15:24:51 +03:00
|
|
|
qemu_irq_lower(s->a20_out);
|
2010-05-22 11:59:01 +04:00
|
|
|
s->outport &= ~KBD_OUT_A20;
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_RESET:
|
2017-05-16 00:41:13 +03:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
2010-08-19 16:52:12 +04:00
|
|
|
case KBD_CCMD_NO_OP:
|
|
|
|
/* ignore that */
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
default:
|
2018-06-26 19:50:40 +03:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"unsupported keyboard cmd=0x%02" PRIx64 "\n", val);
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-08 15:30:08 +04:00
|
|
|
static uint64_t kbd_read_data(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
2004-03-14 15:20:30 +03:00
|
|
|
{
|
2004-06-03 22:45:02 +04:00
|
|
|
KBDState *s = opaque;
|
2004-03-14 15:20:30 +03:00
|
|
|
|
2021-05-25 21:14:36 +03:00
|
|
|
if (s->status & KBD_STAT_OBF) {
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
kbd_deassert_irq(s);
|
2021-05-25 21:14:36 +03:00
|
|
|
if (s->obsrc & KBD_OBSRC_KBD) {
|
2021-05-25 21:14:35 +03:00
|
|
|
if (s->throttle_timer) {
|
|
|
|
timer_mod(s->throttle_timer,
|
|
|
|
qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) + 1000);
|
|
|
|
}
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
s->obdata = ps2_read_data(s->kbd);
|
2021-05-25 21:14:36 +03:00
|
|
|
} else if (s->obsrc & KBD_OBSRC_MOUSE) {
|
|
|
|
s->obdata = ps2_read_data(s->mouse);
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
}
|
|
|
|
}
|
2004-03-14 15:20:30 +03:00
|
|
|
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
trace_pckbd_kbd_read_data(s->obdata);
|
|
|
|
return s->obdata;
|
2004-03-14 15:20:30 +03:00
|
|
|
}
|
|
|
|
|
2012-10-08 15:30:08 +04:00
|
|
|
static void kbd_write_data(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
2004-03-14 15:20:30 +03:00
|
|
|
{
|
2004-03-15 00:46:48 +03:00
|
|
|
KBDState *s = opaque;
|
2004-03-14 15:20:30 +03:00
|
|
|
|
2018-10-16 14:22:32 +03:00
|
|
|
trace_pckbd_kbd_write_data(val);
|
2004-03-14 15:20:30 +03:00
|
|
|
|
|
|
|
switch(s->write_cmd) {
|
|
|
|
case 0:
|
2005-11-26 13:14:03 +03:00
|
|
|
ps2_write_keyboard(s->kbd, val);
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_MODE:
|
|
|
|
s->mode = val;
|
2006-02-08 07:42:17 +03:00
|
|
|
ps2_keyboard_set_translation(s->kbd, (s->mode & KBD_MODE_KCC) != 0);
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
/*
|
|
|
|
* a write to the mode byte interrupt enable flags directly updates
|
|
|
|
* the irq lines
|
|
|
|
*/
|
|
|
|
kbd_update_irq_lines(s);
|
|
|
|
/*
|
|
|
|
* a write to the mode byte disable interface flags may raise
|
|
|
|
* an irq if there is pending data in the PS/2 queues.
|
|
|
|
*/
|
|
|
|
kbd_safe_update_irq(s);
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_OBUF:
|
|
|
|
kbd_queue(s, val, 0);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_AUX_OBUF:
|
|
|
|
kbd_queue(s, val, 1);
|
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_OUTPORT:
|
2011-01-06 21:24:35 +03:00
|
|
|
outport_write(s, val);
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
case KBD_CCMD_WRITE_MOUSE:
|
2005-11-26 13:14:03 +03:00
|
|
|
ps2_write_mouse(s->mouse, val);
|
2004-03-14 15:20:30 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s->write_cmd = 0;
|
|
|
|
}
|
|
|
|
|
2004-06-20 16:58:36 +04:00
|
|
|
static void kbd_reset(void *opaque)
|
2004-03-14 15:20:30 +03:00
|
|
|
{
|
2004-06-20 16:58:36 +04:00
|
|
|
KBDState *s = opaque;
|
2004-03-14 15:20:30 +03:00
|
|
|
|
|
|
|
s->mode = KBD_MODE_KBD_INT | KBD_MODE_MOUSE_INT;
|
|
|
|
s->status = KBD_STAT_CMD | KBD_STAT_UNLOCKED;
|
2014-12-22 10:55:19 +03:00
|
|
|
s->outport = KBD_OUT_RESET | KBD_OUT_A20 | KBD_OUT_ONES;
|
2014-08-28 15:19:14 +04:00
|
|
|
s->outport_present = false;
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
s->pending = 0;
|
|
|
|
kbd_deassert_irq(s);
|
2021-05-25 21:14:35 +03:00
|
|
|
if (s->throttle_timer) {
|
|
|
|
timer_del(s->throttle_timer);
|
|
|
|
}
|
2014-08-28 15:19:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t kbd_outport_default(KBDState *s)
|
|
|
|
{
|
2014-12-22 10:55:19 +03:00
|
|
|
return KBD_OUT_RESET | KBD_OUT_A20 | KBD_OUT_ONES
|
2014-08-28 15:19:14 +04:00
|
|
|
| (s->status & KBD_STAT_OBF ? KBD_OUT_OBF : 0)
|
|
|
|
| (s->status & KBD_STAT_MOUSE_OBF ? KBD_OUT_MOUSE_OBF : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kbd_outport_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
s->outport_present = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-23 16:09:54 +04:00
|
|
|
static bool kbd_outport_needed(void *opaque)
|
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
return s->outport != kbd_outport_default(s);
|
|
|
|
}
|
|
|
|
|
2014-08-28 15:19:14 +04:00
|
|
|
static const VMStateDescription vmstate_kbd_outport = {
|
|
|
|
.name = "pckbd_outport",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.post_load = kbd_outport_post_load,
|
2014-09-23 16:09:54 +04:00
|
|
|
.needed = kbd_outport_needed,
|
2014-08-28 15:19:14 +04:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8(outport, KBDState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-25 21:14:35 +03:00
|
|
|
static int kbd_extended_state_pre_save(void *opaque)
|
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
|
|
|
|
s->migration_flags = 0;
|
|
|
|
if (s->throttle_timer && timer_pending(s->throttle_timer)) {
|
|
|
|
s->migration_flags |= KBD_MIGR_TIMER_PENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kbd_extended_state_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
|
|
|
|
if (s->migration_flags & KBD_MIGR_TIMER_PENDING) {
|
|
|
|
kbd_throttle_timeout(s);
|
|
|
|
}
|
2021-05-25 21:14:36 +03:00
|
|
|
s->extended_state_loaded = true;
|
2021-05-25 21:14:35 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
static bool kbd_extended_state_needed(void *opaque)
|
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
|
|
|
|
return s->extended_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_kbd_extended_state = {
|
|
|
|
.name = "pckbd/extended_state",
|
2021-05-25 21:14:35 +03:00
|
|
|
.post_load = kbd_extended_state_post_load,
|
|
|
|
.pre_save = kbd_extended_state_pre_save,
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
.needed = kbd_extended_state_needed,
|
|
|
|
.fields = (VMStateField[]) {
|
2021-05-25 21:14:35 +03:00
|
|
|
VMSTATE_UINT32(migration_flags, KBDState),
|
2021-05-25 21:14:36 +03:00
|
|
|
VMSTATE_UINT32(obsrc, KBDState),
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
VMSTATE_UINT8(obdata, KBDState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-25 21:14:36 +03:00
|
|
|
static int kbd_pre_load(void *opaque)
|
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
|
|
|
|
s->extended_state_loaded = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-28 15:19:14 +04:00
|
|
|
static int kbd_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
if (!s->outport_present) {
|
|
|
|
s->outport = kbd_outport_default(s);
|
|
|
|
}
|
|
|
|
s->outport_present = false;
|
2021-05-25 21:14:36 +03:00
|
|
|
if (!s->extended_state_loaded) {
|
|
|
|
s->obsrc = s->status & KBD_STAT_OBF ?
|
|
|
|
(s->status & KBD_STAT_MOUSE_OBF ? KBD_OBSRC_MOUSE : KBD_OBSRC_KBD) :
|
|
|
|
0;
|
|
|
|
}
|
2014-08-28 15:19:14 +04:00
|
|
|
return 0;
|
2004-03-14 15:20:30 +03:00
|
|
|
}
|
|
|
|
|
2009-09-10 05:04:41 +04:00
|
|
|
static const VMStateDescription vmstate_kbd = {
|
|
|
|
.name = "pckbd",
|
|
|
|
.version_id = 3,
|
|
|
|
.minimum_version_id = 3,
|
2021-05-25 21:14:36 +03:00
|
|
|
.pre_load = kbd_pre_load,
|
2014-08-28 15:19:14 +04:00
|
|
|
.post_load = kbd_post_load,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2009-09-10 05:04:41 +04:00
|
|
|
VMSTATE_UINT8(write_cmd, KBDState),
|
|
|
|
VMSTATE_UINT8(status, KBDState),
|
|
|
|
VMSTATE_UINT8(mode, KBDState),
|
|
|
|
VMSTATE_UINT8(pending, KBDState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
2014-08-28 15:19:14 +04:00
|
|
|
},
|
2014-09-23 16:09:54 +04:00
|
|
|
.subsections = (const VMStateDescription*[]) {
|
|
|
|
&vmstate_kbd_outport,
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
&vmstate_kbd_extended_state,
|
2014-09-23 16:09:54 +04:00
|
|
|
NULL
|
2009-09-10 05:04:41 +04:00
|
|
|
}
|
|
|
|
};
|
2004-07-10 17:39:53 +04:00
|
|
|
|
2007-04-16 21:20:48 +04:00
|
|
|
/* Memory mapped interface */
|
2018-06-15 16:57:13 +03:00
|
|
|
static uint64_t kbd_mm_readfn(void *opaque, hwaddr addr, unsigned size)
|
2007-04-16 21:20:48 +04:00
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
|
2008-12-10 18:02:07 +03:00
|
|
|
if (addr & s->mask)
|
2012-10-08 15:30:08 +04:00
|
|
|
return kbd_read_status(s, 0, 1) & 0xff;
|
2008-12-10 18:02:07 +03:00
|
|
|
else
|
2012-10-08 15:30:08 +04:00
|
|
|
return kbd_read_data(s, 0, 1) & 0xff;
|
2007-04-16 21:20:48 +04:00
|
|
|
}
|
|
|
|
|
2018-06-15 16:57:13 +03:00
|
|
|
static void kbd_mm_writefn(void *opaque, hwaddr addr,
|
|
|
|
uint64_t value, unsigned size)
|
2007-04-16 21:20:48 +04:00
|
|
|
{
|
|
|
|
KBDState *s = opaque;
|
|
|
|
|
2008-12-10 18:02:07 +03:00
|
|
|
if (addr & s->mask)
|
2012-10-08 15:30:08 +04:00
|
|
|
kbd_write_command(s, 0, value & 0xff, 1);
|
2008-12-10 18:02:07 +03:00
|
|
|
else
|
2012-10-08 15:30:08 +04:00
|
|
|
kbd_write_data(s, 0, value & 0xff, 1);
|
2007-04-16 21:20:48 +04:00
|
|
|
}
|
|
|
|
|
2018-06-15 16:57:13 +03:00
|
|
|
|
2011-08-11 02:28:17 +04:00
|
|
|
static const MemoryRegionOps i8042_mmio_ops = {
|
2018-06-15 16:57:13 +03:00
|
|
|
.read = kbd_mm_readfn,
|
|
|
|
.write = kbd_mm_writefn,
|
|
|
|
.valid.min_access_size = 1,
|
|
|
|
.valid.max_access_size = 4,
|
2011-08-11 02:28:17 +04:00
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-04-16 21:20:48 +04:00
|
|
|
};
|
|
|
|
|
2007-06-08 20:45:23 +04:00
|
|
|
void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
|
2011-08-11 02:28:17 +04:00
|
|
|
MemoryRegion *region, ram_addr_t size,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr mask)
|
2007-04-16 21:20:48 +04:00
|
|
|
{
|
2011-08-21 07:09:37 +04:00
|
|
|
KBDState *s = g_malloc0(sizeof(KBDState));
|
2007-04-16 21:20:48 +04:00
|
|
|
|
|
|
|
s->irq_kbd = kbd_irq;
|
|
|
|
s->irq_mouse = mouse_irq;
|
2008-12-10 18:02:07 +03:00
|
|
|
s->mask = mask;
|
2007-04-16 21:20:48 +04:00
|
|
|
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
s->extended_state = true;
|
|
|
|
|
2010-06-25 21:09:07 +04:00
|
|
|
vmstate_register(NULL, 0, &vmstate_kbd, s);
|
2011-08-11 02:28:17 +04:00
|
|
|
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init_io(region, NULL, &i8042_mmio_ops, s, "i8042", size);
|
2007-04-16 21:20:48 +04:00
|
|
|
|
|
|
|
s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
|
|
|
|
s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
|
2009-06-27 11:25:07 +04:00
|
|
|
qemu_register_reset(kbd_reset, s);
|
2007-04-16 21:20:48 +04:00
|
|
|
}
|
2009-07-31 14:30:15 +04:00
|
|
|
|
2019-10-17 18:06:05 +03:00
|
|
|
struct ISAKBDState {
|
2013-04-28 00:18:47 +04:00
|
|
|
ISADevice parent_obj;
|
|
|
|
|
2011-08-11 02:28:17 +04:00
|
|
|
KBDState kbd;
|
2021-05-25 21:14:35 +03:00
|
|
|
bool kbd_throttle;
|
2011-08-11 02:28:17 +04:00
|
|
|
MemoryRegion io[2];
|
2019-10-17 18:06:05 +03:00
|
|
|
};
|
2009-07-31 14:30:15 +04:00
|
|
|
|
2019-10-17 18:06:05 +03:00
|
|
|
void i8042_isa_mouse_fake_event(ISAKBDState *isa)
|
2010-05-22 11:59:01 +04:00
|
|
|
{
|
2013-04-28 00:18:47 +04:00
|
|
|
KBDState *s = &isa->kbd;
|
2010-05-22 11:59:01 +04:00
|
|
|
|
|
|
|
ps2_mouse_fake_event(s->mouse);
|
|
|
|
}
|
|
|
|
|
2016-07-15 19:42:05 +03:00
|
|
|
void i8042_setup_a20_line(ISADevice *dev, qemu_irq a20_out)
|
2010-05-22 11:59:01 +04:00
|
|
|
{
|
2016-07-15 19:42:05 +03:00
|
|
|
qdev_connect_gpio_out_named(DEVICE(dev), I8042_A20_LINE, 0, a20_out);
|
2010-05-22 11:59:01 +04:00
|
|
|
}
|
|
|
|
|
2009-12-04 23:44:44 +03:00
|
|
|
static const VMStateDescription vmstate_kbd_isa = {
|
2009-12-02 14:36:46 +03:00
|
|
|
.name = "pckbd",
|
|
|
|
.version_id = 3,
|
|
|
|
.minimum_version_id = 3,
|
2014-04-16 17:32:32 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2009-12-02 14:36:46 +03:00
|
|
|
VMSTATE_STRUCT(kbd, ISAKBDState, 0, vmstate_kbd, KBDState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-08-11 02:28:17 +04:00
|
|
|
static const MemoryRegionOps i8042_data_ops = {
|
2012-10-08 15:30:08 +04:00
|
|
|
.read = kbd_read_data,
|
|
|
|
.write = kbd_write_data,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 1,
|
|
|
|
},
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-11 02:28:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const MemoryRegionOps i8042_cmd_ops = {
|
2012-10-08 15:30:08 +04:00
|
|
|
.read = kbd_read_status,
|
|
|
|
.write = kbd_write_command,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 1,
|
|
|
|
},
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-11 02:28:17 +04:00
|
|
|
};
|
|
|
|
|
2012-11-25 05:37:14 +04:00
|
|
|
static void i8042_initfn(Object *obj)
|
2009-07-31 14:30:15 +04:00
|
|
|
{
|
2012-11-25 05:37:14 +04:00
|
|
|
ISAKBDState *isa_s = I8042(obj);
|
2011-08-11 02:28:17 +04:00
|
|
|
KBDState *s = &isa_s->kbd;
|
2009-07-31 14:30:15 +04:00
|
|
|
|
2013-06-07 05:25:08 +04:00
|
|
|
memory_region_init_io(isa_s->io + 0, obj, &i8042_data_ops, s,
|
|
|
|
"i8042-data", 1);
|
|
|
|
memory_region_init_io(isa_s->io + 1, obj, &i8042_cmd_ops, s,
|
|
|
|
"i8042-cmd", 1);
|
2016-06-22 15:24:51 +03:00
|
|
|
|
|
|
|
qdev_init_gpio_out_named(DEVICE(obj), &s->a20_out, I8042_A20_LINE, 1);
|
2012-11-25 05:37:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void i8042_realizefn(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
ISADevice *isadev = ISA_DEVICE(dev);
|
|
|
|
ISAKBDState *isa_s = I8042(dev);
|
|
|
|
KBDState *s = &isa_s->kbd;
|
|
|
|
|
|
|
|
isa_init_irq(isadev, &s->irq_kbd, 1);
|
|
|
|
isa_init_irq(isadev, &s->irq_mouse, 12);
|
|
|
|
|
|
|
|
isa_register_ioport(isadev, isa_s->io + 0, 0x60);
|
|
|
|
isa_register_ioport(isadev, isa_s->io + 1, 0x64);
|
2009-07-31 14:30:15 +04:00
|
|
|
|
|
|
|
s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
|
|
|
|
s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
|
2021-05-25 21:14:35 +03:00
|
|
|
if (isa_s->kbd_throttle && !isa_s->kbd.extended_state) {
|
|
|
|
warn_report(TYPE_I8042 ": can't enable kbd-throttle without"
|
|
|
|
" extended-state, disabling kbd-throttle");
|
|
|
|
} else if (isa_s->kbd_throttle) {
|
|
|
|
s->throttle_timer = timer_new_us(QEMU_CLOCK_VIRTUAL,
|
|
|
|
kbd_throttle_timeout, s);
|
|
|
|
}
|
2009-07-31 14:30:15 +04:00
|
|
|
qemu_register_reset(kbd_reset, s);
|
|
|
|
}
|
|
|
|
|
2020-06-19 12:18:59 +03:00
|
|
|
static void i8042_build_aml(ISADevice *isadev, Aml *scope)
|
|
|
|
{
|
|
|
|
Aml *kbd;
|
|
|
|
Aml *mou;
|
|
|
|
Aml *crs;
|
|
|
|
|
|
|
|
crs = aml_resource_template();
|
|
|
|
aml_append(crs, aml_io(AML_DECODE16, 0x0060, 0x0060, 0x01, 0x01));
|
|
|
|
aml_append(crs, aml_io(AML_DECODE16, 0x0064, 0x0064, 0x01, 0x01));
|
|
|
|
aml_append(crs, aml_irq_no_flags(1));
|
|
|
|
|
|
|
|
kbd = aml_device("KBD");
|
|
|
|
aml_append(kbd, aml_name_decl("_HID", aml_eisaid("PNP0303")));
|
|
|
|
aml_append(kbd, aml_name_decl("_STA", aml_int(0xf)));
|
|
|
|
aml_append(kbd, aml_name_decl("_CRS", crs));
|
|
|
|
|
|
|
|
crs = aml_resource_template();
|
|
|
|
aml_append(crs, aml_irq_no_flags(12));
|
|
|
|
|
|
|
|
mou = aml_device("MOU");
|
|
|
|
aml_append(mou, aml_name_decl("_HID", aml_eisaid("PNP0F13")));
|
|
|
|
aml_append(mou, aml_name_decl("_STA", aml_int(0xf)));
|
|
|
|
aml_append(mou, aml_name_decl("_CRS", crs));
|
|
|
|
|
|
|
|
aml_append(scope, kbd);
|
|
|
|
aml_append(scope, mou);
|
|
|
|
}
|
|
|
|
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
static Property i8042_properties[] = {
|
|
|
|
DEFINE_PROP_BOOL("extended-state", ISAKBDState, kbd.extended_state, true),
|
2021-05-25 21:14:35 +03:00
|
|
|
DEFINE_PROP_BOOL("kbd-throttle", ISAKBDState, kbd_throttle, false),
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2011-12-04 21:52:49 +04:00
|
|
|
static void i8042_class_initfn(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2020-06-19 12:18:59 +03:00
|
|
|
ISADeviceClass *isa = ISA_DEVICE_CLASS(klass);
|
2012-11-25 05:37:14 +04:00
|
|
|
|
pckbd: don't update OBF flags if KBD_STAT_OBF is set
Don't update the OBF flags in the status register and the cor-
responding IRQ lines if KBD_STAT_OBF is set. Otherwise this
may change the PS/2 event type. If the guest ISR was already
scheduled, the changed event type will be rather surprising for
the guest.
This fixes a mouse event stream corruption. To reproduce the
problem start a FreeDOS 1.2 guest with -machine pc,accel=kvm
and -display gtk. The KVM in-kernel irqchip has to be enabled.
Now open a text file with edit.exe in the guest and hold down
the cursor right key and at the same time move the mouse around.
You will quickly notice erratic mouse movements and unexpected
mouse clicks.
A trace file shows the mouse event stream corruption. Guest
rip 0xce93 (f000:ce93) is the in al,0x60 instruction in the
seabios mouse ISR, guest rip 0xceca (f000:ceca) is the
in al,0x60 instruction in the seabios keyboard ISR.
qemu-system-x86-5659 [007] .... 280.971116:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
# gtk queues a mouse event
qemu-system-x86-5665 [000] .... 280.971121:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971122:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971123:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x22da info 0 800000fd
qemu-system-x86-5665 [000] d..1 280.971124:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971126:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971176:
tracing_mark_write: pckbd_kbd_read_status 0x3d
# KBD_STAT_OBF and KBD_STAT_MOUSE_OBF set, the mouse ISR will
# read data from the PS/2 controller.
qemu-system-x86-5665 [000] d..1 280.971180:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971191:
kvm_exit: reason EXTERNAL_INTERRUPT rip 0x110c8d info 0 800000f6
qemu-system-x86-5665 [000] d..1 280.971191:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971193:
kvm_exit: reason IO_INSTRUCTION rip 0xce93 info 600048 0
# the mouse ISR wants to read data from the PS/2 controller
qemu-system-x86-5659 [007] .... 280.971231:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
qemu-system-x86-5659 [007] .... 280.971238:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# gtk queues a keyboard event 0xe0 0x4d (key right)
qemu-system-x86-5665 [000] .... 280.971257:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971262:
tracing_mark_write: pckbd_kbd_update_irq kbd=1 aux=0
# ps2_read_data() deasserts and reasserts the keyboard IRQ
qemu-system-x86-5665 [000] .... 280.971266:
tracing_mark_write: pckbd_kbd_read_data 0xe0 kbd
# -> the mouse ISR receives keyboard data
qemu-system-x86-5665 [000] d..1 280.971268:
kvm_entry: vcpu 0, rip 0xce95
qemu-system-x86-5665 [000] .... 280.971269:
kvm_exit: reason IO_INSTRUCTION rip 0xe828 info a00040 0
qemu-system-x86-5665 [000] .... 280.971270:
kvm_ack_irq: irqchip PIC slave pin 12
qemu-system-x86-5665 [000] d..1 280.971270:
kvm_entry: vcpu 0, rip 0xe82a
qemu-system-x86-5665 [000] .... 280.971271:
kvm_exit: reason IO_INSTRUCTION rip 0xe82a info 200040 0
qemu-system-x86-5665 [000] .... 280.971271:
kvm_ack_irq: irqchip PIC master pin 2
qemu-system-x86-5665 [000] d..1 280.971271:
kvm_entry: vcpu 0, rip 0xe82c
qemu-system-x86-5665 [000] .... 280.971272:
kvm_exit: reason PENDING_INTERRUPT rip 0x22da info 0 0
qemu-system-x86-5665 [000] d..1 280.971273:
kvm_entry: vcpu 0, rip 0x22da
qemu-system-x86-5665 [000] .... 280.971274:
kvm_exit: reason IO_INSTRUCTION rip 0x110c8c info 640008 0
qemu-system-x86-5665 [000] .... 280.971275:
tracing_mark_write: pckbd_kbd_read_status 0x1d
qemu-system-x86-5665 [000] d..1 280.971276:
kvm_entry: vcpu 0, rip 0x110c8d
qemu-system-x86-5665 [000] .... 280.971277:
kvm_exit: reason IO_INSTRUCTION rip 0xceca info 600048 0
# the keyboard ISR wants to read data from the PS/2 controller
qemu-system-x86-5665 [000] .... 280.971279:
tracing_mark_write: pckbd_kbd_update_irq kbd=0 aux=1
qemu-system-x86-5665 [000] .... 280.971282:
tracing_mark_write: pckbd_kbd_read_data 0x4d kbd
# the keyboard ISR receives the second byte of the keyboard event
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20210525181441.27768-5-vr_qemu@t-online.de>
[ kraxel: add missing include ]
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2021-05-25 21:14:34 +03:00
|
|
|
device_class_set_props(dc, i8042_properties);
|
2012-11-25 05:37:14 +04:00
|
|
|
dc->realize = i8042_realizefn;
|
2011-12-08 07:34:16 +04:00
|
|
|
dc->vmsd = &vmstate_kbd_isa;
|
2020-06-19 12:18:59 +03:00
|
|
|
isa->build_aml = i8042_build_aml;
|
2019-01-25 18:14:40 +03:00
|
|
|
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
|
2011-12-04 21:52:49 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo i8042_info = {
|
2013-04-28 00:18:47 +04:00
|
|
|
.name = TYPE_I8042,
|
2011-12-08 07:34:16 +04:00
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.instance_size = sizeof(ISAKBDState),
|
2012-11-25 05:37:14 +04:00
|
|
|
.instance_init = i8042_initfn,
|
2011-12-08 07:34:16 +04:00
|
|
|
.class_init = i8042_class_initfn,
|
2009-07-31 14:30:15 +04:00
|
|
|
};
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void i8042_register_types(void)
|
2009-07-31 14:30:15 +04:00
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
type_register_static(&i8042_info);
|
2009-07-31 14:30:15 +04:00
|
|
|
}
|
2012-02-09 18:20:55 +04:00
|
|
|
|
|
|
|
type_init(i8042_register_types)
|