Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
linux
Commits
39f21ee5
Commit
39f21ee5
authored
Aug 18, 2010
by
Avi Kivity
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
KVM: x86 emulator: consolidate immediate decode into a function
Signed-off-by:
Avi Kivity
<
avi@redhat.com
>
parent
48bb5d3c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
45 deletions
+64
-45
arch/x86/kvm/emulate.c
arch/x86/kvm/emulate.c
+64
-45
No files found.
arch/x86/kvm/emulate.c
View file @
39f21ee5
...
@@ -2541,6 +2541,55 @@ static struct opcode twobyte_table[256] = {
...
@@ -2541,6 +2541,55 @@ static struct opcode twobyte_table[256] = {
#undef GD
#undef GD
#undef I
#undef I
static
unsigned
imm_size
(
struct
decode_cache
*
c
)
{
unsigned
size
;
size
=
(
c
->
d
&
ByteOp
)
?
1
:
c
->
op_bytes
;
if
(
size
==
8
)
size
=
4
;
return
size
;
}
static
int
decode_imm
(
struct
x86_emulate_ctxt
*
ctxt
,
struct
operand
*
op
,
unsigned
size
,
bool
sign_extension
)
{
struct
decode_cache
*
c
=
&
ctxt
->
decode
;
struct
x86_emulate_ops
*
ops
=
ctxt
->
ops
;
int
rc
=
X86EMUL_CONTINUE
;
op
->
type
=
OP_IMM
;
op
->
bytes
=
size
;
op
->
addr
.
mem
=
c
->
eip
;
/* NB. Immediates are sign-extended as necessary. */
switch
(
op
->
bytes
)
{
case
1
:
op
->
val
=
insn_fetch
(
s8
,
1
,
c
->
eip
);
break
;
case
2
:
op
->
val
=
insn_fetch
(
s16
,
2
,
c
->
eip
);
break
;
case
4
:
op
->
val
=
insn_fetch
(
s32
,
4
,
c
->
eip
);
break
;
}
if
(
!
sign_extension
)
{
switch
(
op
->
bytes
)
{
case
1
:
op
->
val
&=
0xff
;
break
;
case
2
:
op
->
val
&=
0xffff
;
break
;
case
4
:
op
->
val
&=
0xffffffff
;
break
;
}
}
done:
return
rc
;
}
int
int
x86_decode_insn
(
struct
x86_emulate_ctxt
*
ctxt
)
x86_decode_insn
(
struct
x86_emulate_ctxt
*
ctxt
)
{
{
...
@@ -2730,52 +2779,19 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt)
...
@@ -2730,52 +2779,19 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt)
c
->
src
=
memop
;
c
->
src
=
memop
;
break
;
break
;
case
SrcImmU16
:
case
SrcImmU16
:
c
->
src
.
bytes
=
2
;
rc
=
decode_imm
(
ctxt
,
&
c
->
src
,
2
,
false
);
goto
srcimm
;
case
SrcImm
:
case
SrcImmU
:
c
->
src
.
bytes
=
(
c
->
d
&
ByteOp
)
?
1
:
c
->
op_bytes
;
if
(
c
->
src
.
bytes
==
8
)
c
->
src
.
bytes
=
4
;
srcimm:
c
->
src
.
type
=
OP_IMM
;
c
->
src
.
addr
.
mem
=
c
->
eip
;
/* NB. Immediates are sign-extended as necessary. */
switch
(
c
->
src
.
bytes
)
{
case
1
:
c
->
src
.
val
=
insn_fetch
(
s8
,
1
,
c
->
eip
);
break
;
case
2
:
c
->
src
.
val
=
insn_fetch
(
s16
,
2
,
c
->
eip
);
break
;
break
;
case
4
:
case
SrcImm
:
c
->
src
.
val
=
insn_fetch
(
s32
,
4
,
c
->
eip
);
rc
=
decode_imm
(
ctxt
,
&
c
->
src
,
imm_size
(
c
),
true
);
break
;
}
if
((
c
->
d
&
SrcMask
)
==
SrcImmU
||
(
c
->
d
&
SrcMask
)
==
SrcImmU16
)
{
switch
(
c
->
src
.
bytes
)
{
case
1
:
c
->
src
.
val
&=
0xff
;
break
;
case
2
:
c
->
src
.
val
&=
0xffff
;
break
;
case
4
:
c
->
src
.
val
&=
0xffffffff
;
break
;
break
;
}
case
SrcImmU
:
}
rc
=
decode_imm
(
ctxt
,
&
c
->
src
,
imm_size
(
c
),
false
);
break
;
break
;
case
SrcImmByte
:
case
SrcImmByte
:
rc
=
decode_imm
(
ctxt
,
&
c
->
src
,
1
,
true
);
break
;
case
SrcImmUByte
:
case
SrcImmUByte
:
c
->
src
.
type
=
OP_IMM
;
rc
=
decode_imm
(
ctxt
,
&
c
->
src
,
1
,
false
);
c
->
src
.
addr
.
mem
=
c
->
eip
;
c
->
src
.
bytes
=
1
;
if
((
c
->
d
&
SrcMask
)
==
SrcImmByte
)
c
->
src
.
val
=
insn_fetch
(
s8
,
1
,
c
->
eip
);
else
c
->
src
.
val
=
insn_fetch
(
u8
,
1
,
c
->
eip
);
break
;
break
;
case
SrcAcc
:
case
SrcAcc
:
c
->
src
.
type
=
OP_REG
;
c
->
src
.
type
=
OP_REG
;
...
@@ -2807,6 +2823,9 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt)
...
@@ -2807,6 +2823,9 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt)
break
;
break
;
}
}
if
(
rc
!=
X86EMUL_CONTINUE
)
goto
done
;
/*
/*
* Decode and fetch the second source operand: register, memory
* Decode and fetch the second source operand: register, memory
* or immediate.
* or immediate.
...
@@ -2819,10 +2838,7 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt)
...
@@ -2819,10 +2838,7 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt)
c
->
src2
.
val
=
c
->
regs
[
VCPU_REGS_RCX
]
&
0x8
;
c
->
src2
.
val
=
c
->
regs
[
VCPU_REGS_RCX
]
&
0x8
;
break
;
break
;
case
Src2ImmByte
:
case
Src2ImmByte
:
c
->
src2
.
type
=
OP_IMM
;
rc
=
decode_imm
(
ctxt
,
&
c
->
src2
,
1
,
true
);
c
->
src2
.
addr
.
mem
=
c
->
eip
;
c
->
src2
.
bytes
=
1
;
c
->
src2
.
val
=
insn_fetch
(
u8
,
1
,
c
->
eip
);
break
;
break
;
case
Src2One
:
case
Src2One
:
c
->
src2
.
bytes
=
1
;
c
->
src2
.
bytes
=
1
;
...
@@ -2830,6 +2846,9 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt)
...
@@ -2830,6 +2846,9 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt)
break
;
break
;
}
}
if
(
rc
!=
X86EMUL_CONTINUE
)
goto
done
;
/* Decode and fetch the destination operand: register or memory. */
/* Decode and fetch the destination operand: register or memory. */
switch
(
c
->
d
&
DstMask
)
{
switch
(
c
->
d
&
DstMask
)
{
case
DstReg
:
case
DstReg
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment