Skip to content

Commit

Permalink
x86/ioemul: Misc improvements to ioport_emulate.c
Browse files Browse the repository at this point in the history
Put the opcode into an array and use memcpy.  This allows the compiled code to
be written with two movs, rather than 10 mov $imm8's.  Also, drop trailing
whitespace in the file.

Signed-off-by: Andrew Cooper <[email protected]>
Reviewed-by: Jan Beulich <[email protected]>
  • Loading branch information
andyhhp committed Feb 1, 2018
1 parent 98dc960 commit f2f6843
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions xen/arch/x86/ioport_emulate.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
* ioport_emulate.c
*
*
* Handle I/O port access quirks of various platforms.
*/

Expand All @@ -11,32 +11,24 @@
static bool ioemul_handle_proliant_quirk(
u8 opcode, char *io_emul_stub, struct cpu_user_regs *regs)
{
static const char stub[] = {
0x9c, /* pushf */
0xfa, /* cli */
0xee, /* out %al, %dx */
0xec, /* 1: in %dx, %al */
0xa8, 0x80, /* test $0x80, %al */
0x75, 0xfb, /* jnz 1b */
0x9d, /* popf */
0xc3, /* ret */
};
uint16_t port = regs->dx;
uint8_t value = regs->al;

if ( (opcode != 0xee) || (port != 0xcd4) || !(value & 0x80) )
return false;

/* pushf */
io_emul_stub[0] = 0x9c;
/* cli */
io_emul_stub[1] = 0xfa;
/* out %al,%dx */
io_emul_stub[2] = 0xee;
/* 1: in %dx,%al */
io_emul_stub[3] = 0xec;
/* test $0x80,%al */
io_emul_stub[4] = 0xa8;
io_emul_stub[5] = 0x80;
/* jnz 1b */
io_emul_stub[6] = 0x75;
io_emul_stub[7] = 0xfb;
/* popf */
io_emul_stub[8] = 0x9d;
/* ret */
io_emul_stub[9] = 0xc3;

BUILD_BUG_ON(IOEMUL_QUIRK_STUB_BYTES < 10);
memcpy(io_emul_stub, stub, sizeof(stub));
BUILD_BUG_ON(IOEMUL_QUIRK_STUB_BYTES < sizeof(stub));

return true;
}
Expand Down

0 comments on commit f2f6843

Please sign in to comment.