VMX support for MMIO/PIO in VM8086 mode
PATCH 1/1 VMX support for MMIO/PIO in VM8086 mode
Memory mapped and port I/O is currently broken under VMX when the partition is running in VM8086 mode. The reason is that the instruction decoding support uses 32-bit opcode/address decodes rather 16-bit decodes. This patch fixes that. In addition, the patch adds support for the "stos" instruction decoding because this is a frequently used way to clear MMIO areas such as the screen.
As an aside, vmx_platform.c should really reuse x86_emulate.c as much as possible.
===== tools/ioemu/iodev/cpu.cc 1.7 vs edited =====
tools/ioemu/iodev/cpu.cc +19 -6
@@ -51,7 +51,7 @@ if (req->state == STATE_IOREQ_READY) { req->state = STATE_IOREQ_INPROCESS; } else { - BX_INFO(("False I/O requrest ... in-service already: %lx, pvalid: %lx,port: %lx, data: %lx, count: %lx, size: %lx\n", req->state, req->pdata_valid, req->addr, req->u.data, req->count, req->size)); + BX_INFO(("False I/O request ... in-service already: %lx, pvalid: %lx,port: %lx, data: %lx, count: %lx, size: %lx\n", req->state, req->pdata_valid, req->addr, req->u.data, req->count, req->size)); req = NULL; }
@@ -95,6 +95,8 @@ } if (req->port_mm == 0){//port io if(req->dir == IOREQ_READ){//read + //BX_INFO(("pio: <READ>addr:%llx, value:%llx, size: %llx, count: %llx\n", req->addr, req->u.data, req->size, req->count)); + if (!req->pdata_valid) req->u.data = BX_INP(req->addr, req->size); else {
@@ -107,6 +109,8 @@ } } } else if(req->dir == IOREQ_WRITE) { + //BX_INFO(("pio: <WRITE>addr:%llx, value:%llx, size: %llx, count: %llx\n", req->addr, req->u.data, req->size, req->count)); + if (!req->pdata_valid) { BX_OUTP(req->addr, (dma_addr_t) req->u.data, req->size); } else {
@@ -123,20 +127,29 @@ } else if (req->port_mm == 1){//memory map io if (!req->pdata_valid) { if(req->dir == IOREQ_READ){//read - BX_MEM_READ_PHYSICAL(req->addr, req->size, &req->u.data); - } else if(req->dir == IOREQ_WRITE)//write - BX_MEM_WRITE_PHYSICAL(req->addr, req->size, &req->u.data); + //BX_INFO(("mmio[value]: <READ> addr:%llx, value:%llx, size: %llx, count: %llx\n", req->addr, req->u.data, req->size, req->count)); + + for (i = 0; i < req->count; i++) { + BX_MEM_READ_PHYSICAL(req->addr, req->size, &req->u.data); + } + } else if(req->dir == IOREQ_WRITE) {//write + //BX_INFO(("mmio[value]: <WRITE> addr:%llx, value:%llx, size: %llx, count: %llx\n", req->addr, req->u.data, req->size, req->count)); + + for (i = 0; i < req->count; i++) { + BX_MEM_WRITE_PHYSICAL(req->addr, req->size, &req->u.data); + } + } } else { //handle movs unsigned long tmp; if (req->dir == IOREQ_READ) { - //BX_INFO(("<READ>addr:%llx, pdata:%llx, size: %x, count: %x\n", req->addr, req->u.pdata, req->size, req->count)); + //BX_INFO(("mmio[pdata]: <READ>addr:%llx, pdata:%llx, size: %x, count: %x\n", req->addr, req->u.pdata, req->size, req->count)); for (i = 0; i < req->count; i++) { BX_MEM_READ_PHYSICAL(req->addr + (sign * i * req->size), req->size, &tmp); BX_MEM_WRITE_PHYSICAL((dma_addr_t) req->u.pdata + (sign * i * req->size), req->size, &tmp); } } else if (req->dir == IOREQ_WRITE) { - //BX_INFO(("<WRITE>addr:%llx, pdata:%llx, size: %x, count: %x\n", req->addr, req->u.pdata, req->size, req->count)); + //BX_INFO(("mmio[pdata]: <WRITE>addr:%llx, pdata:%llx, size: %x, count: %x\n", req->addr, req->u.pdata, req->size, req->count)); for (i = 0; i < req->count; i++) { BX_MEM_READ_PHYSICAL((dma_addr_t)req->u.pdata + (sign * i * req->size), req->size, &tmp); BX_MEM_WRITE_PHYSICAL(req->addr + (sign * i * req->size), req->size, &tmp);
===== xen/arch/x86/vmx.c 1.35 vs edited =====
xen/arch/x86/vmx.c +57 -19
151 lines not on this page · raw message
===== xen/arch/x86/vmx_platform.c 1.11 vs edited =====
xen/arch/x86/vmx_platform.c +129 -37
326 lines not on this page · raw message
Quoted 9 lines · Leendert van Doorn
Memory mapped and port I/O is currently broken under VMX when the partition is running in VM8086 mode. The reason is that the instruction decoding support uses 32-bit opcode/address decodes rather 16-bit decodes. This patch fixes that. In addition, the patch adds support for the "stos" instruction decoding because this is a frequently used way to clear MMIO areas such as the screen.
As an aside,
vmx_platform.cshould really reusex86_emulate.cas much as possible.
The memory-fault emulator needs proper support for 16-bit addressing and vm86 mode, which won't be hard to hard. I also need to pull the privileged-op emulator out of traps.c, and abstract out the action parts of it (e.g., actual move to/from CR, move to/from I/O port) in the same way I abstracted memory accesses in the mem-fault emulator.
There's less of a win in sharing the priv-op emulator since it is so much simpler, but it should still clean up the code a bunch.
-- Keir