Skip to contentSkip to conversation

KVM: emulate AAM, XLAT, SALC

PATCH Superseded Paolo Bonzini 2 participants 4 messages May 9, 2013 1 message not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover KVM: emulate AAM, XLAT, SALC

These three instructions are not emulated, but can be found in real mode code.

These are also good for stable, but they conflict before 3.9 and are not really useful since emulate_invalid_guest_state defaulted to false. So I'm not marking them for earlier releases.

Paolo Bonzini (3):
KVM: emulator: emulate AAM
KVM: emulator: emulate XLAT
KVM: emulator: emulate SALC

 arch/x86/kvm/emulate.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.1.4

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Re: [PATCH 3/3] KVM: emulator: emulate SALC

Quoted 22 lines · Paolo Bonzini

This is an almost-undocumented instruction available in 32-bit mode. I say "almost" undocumented because AMD documents it in their opcode maps just to say that it is unavailable in 64-bit mode (sections "A.2.1 One-Byte Opcodes" and "B.3 Invalid and Reassigned Instructions in 64-Bit Mode").

It is roughly equivalent to "sbb %al, %al" except it does not set the flags. Use fastop to emulate it, but do not use the opcode directly because it would fail if the host is 64-bit!

---
 arch/x86/kvm/emulate.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kvm/emulate.c +0 -0
index 210bb4e..f62d4c8 100644

arch/x86/kvm/emulate.c FOP_SETCC(setle) · line 537

Quoted 4 lines
arch/x86/kvm/emulate.c +1 -0
@@ -534,6 +534,9 @@ FOP_SETCC(setle)
 FOP_SETCC(setnle)
 FOP_END;
 
+FOP_START(salc) "pushf; sbb %al, %al; popf; ret \n\t"

FOP_RET

Quoted 17 lines
arch/x86/kvm/emulate.c +4 -1
+FOP_END;
+
 #define __emulate_1op_rax_rdx(ctxt, _op, _suffix, _ex)			\
 	do {								\
 		unsigned long _tmp;					\
@@ -3951,7 +3954,8 @@ static const struct opcode opcode_table[256] = {
 	G(Src2One | ByteOp, group2), G(Src2One, group2),
 	G(Src2CL | ByteOp, group2), G(Src2CL, group2),
 	I(DstAcc | SrcImmUByte | No64, em_aam),
-	I(DstAcc | SrcImmUByte | No64, em_aad), N,
+	I(DstAcc | SrcImmUByte | No64, em_aad),
+	F(DstAcc | ByteOp | No64, em_salc),
 	I(DstAcc | SrcXLat | ByteOp, em_mov),
 	/* 0xD8 - 0xDF */
 	N, E(0, &escape_d9), N, E(0, &escape_db), N, E(0, &escape_dd), N, N,
Signature · 1 line
1.8.1.4

--
Gleb.

#3 lore raw

Re: [PATCH 3/3] KVM: emulator: emulate SALC

Il 09/05/2013 11:25, Gleb Natapov ha scritto:

Quoted 26 lines · Paolo Bonzini
Quoted 25 lines

This is an almost-undocumented instruction available in 32-bit mode. I say "almost" undocumented because AMD documents it in their opcode maps just to say that it is unavailable in 64-bit mode (sections "A.2.1 One-Byte Opcodes" and "B.3 Invalid and Reassigned Instructions in 64-Bit Mode").

It is roughly equivalent to "sbb %al, %al" except it does not set the flags. Use fastop to emulate it, but do not use the opcode directly because it would fail if the host is 64-bit!

---
 arch/x86/kvm/emulate.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kvm/emulate.c +0 -0
index 210bb4e..f62d4c8 100644
@@ -534,6 +534,9 @@ FOP_SETCC(setle)
 FOP_SETCC(setnle)
 FOP_END;
 
Quoted 3 lines

arch/x86/kvm/emulate.c FOP_SETCC(setle) · line 537

Quoted 1 line
arch/x86/kvm/emulate.c +1 -0
+FOP_START(salc) "pushf; sbb %al, %al; popf; ret \n\t"

FOP_RET

Ah, I missed that macro. I was mimicking FOP_SETCC which doesn't use it. Will resend.

Paolo

Quoted 21 lines
Quoted 17 lines
arch/x86/kvm/emulate.c +4 -1
+FOP_END;
+
 #define __emulate_1op_rax_rdx(ctxt, _op, _suffix, _ex)			\
 	do {								\
 		unsigned long _tmp;					\
@@ -3951,7 +3954,8 @@ static const struct opcode opcode_table[256] = {
 	G(Src2One | ByteOp, group2), G(Src2One, group2),
 	G(Src2CL | ByteOp, group2), G(Src2CL, group2),
 	I(DstAcc | SrcImmUByte | No64, em_aam),
-	I(DstAcc | SrcImmUByte | No64, em_aad), N,
+	I(DstAcc | SrcImmUByte | No64, em_aad),
+	F(DstAcc | ByteOp | No64, em_salc),
 	I(DstAcc | SrcXLat | ByteOp, em_mov),
 	/* 0xD8 - 0xDF */
 	N, E(0, &escape_d9), N, E(0, &escape_db), N, E(0, &escape_dd), N, N,
Signature · 1 line
1.8.1.4

--
Gleb.

#4 lore raw

Re: [PATCH 3/3] KVM: emulator: emulate SALC

Quoted 27 lines · Paolo Bonzini

Il 09/05/2013 11:25, Gleb Natapov ha scritto:

Quoted 26 lines · Paolo Bonzini
Quoted 25 lines

This is an almost-undocumented instruction available in 32-bit mode. I say "almost" undocumented because AMD documents it in their opcode maps just to say that it is unavailable in 64-bit mode (sections "A.2.1 One-Byte Opcodes" and "B.3 Invalid and Reassigned Instructions in 64-Bit Mode").

It is roughly equivalent to "sbb %al, %al" except it does not set the flags. Use fastop to emulate it, but do not use the opcode directly because it would fail if the host is 64-bit!

---
 arch/x86/kvm/emulate.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kvm/emulate.c +0 -0
index 210bb4e..f62d4c8 100644
@@ -534,6 +534,9 @@ FOP_SETCC(setle)
 FOP_SETCC(setnle)
 FOP_END;
 
Quoted 7 lines
Quoted 3 lines

arch/x86/kvm/emulate.c FOP_SETCC(setle) · line 537

Quoted 1 line
arch/x86/kvm/emulate.c +1 -0
+FOP_START(salc) "pushf; sbb %al, %al; popf; ret \n\t"

FOP_RET

Ah, I missed that macro. I was mimicking FOP_SETCC which doesn't use it. Will resend.

I think it does not use it by mistake.

Quoted 23 lines

Paolo

Quoted 21 lines
Quoted 17 lines
arch/x86/kvm/emulate.c +4 -1
+FOP_END;
+
 #define __emulate_1op_rax_rdx(ctxt, _op, _suffix, _ex)			\
 	do {								\
 		unsigned long _tmp;					\
@@ -3951,7 +3954,8 @@ static const struct opcode opcode_table[256] = {
 	G(Src2One | ByteOp, group2), G(Src2One, group2),
 	G(Src2CL | ByteOp, group2), G(Src2CL, group2),
 	I(DstAcc | SrcImmUByte | No64, em_aam),
-	I(DstAcc | SrcImmUByte | No64, em_aad), N,
+	I(DstAcc | SrcImmUByte | No64, em_aad),
+	F(DstAcc | ByteOp | No64, em_salc),
 	I(DstAcc | SrcXLat | ByteOp, em_mov),
 	/* 0xD8 - 0xDF */
 	N, E(0, &escape_d9), N, E(0, &escape_db), N, E(0, &escape_dd), N, N,
Signature · 1 line
1.8.1.4

--
Gleb.

--
Gleb.