Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 80762
b: refs/heads/master
c: 6226686
h: refs/heads/master
v: v3
  • Loading branch information
Avi Kivity committed Jan 30, 2008
1 parent 319a437 commit e16fbe7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 93a0039c8d93074d5f92dfb69f6a7d453905d002
refs/heads/master: 6226686954c4cce3d63ffe1777e60360fcbf0b83
38 changes: 36 additions & 2 deletions trunk/drivers/kvm/x86_emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ static u16 twobyte_table[256] = {
/* Fetch next part of the instruction being emulated. */
#define insn_fetch(_type, _size, _eip) \
({ unsigned long _x; \
rc = ops->read_std((unsigned long)(_eip) + ctxt->cs_base, &_x, \
(_size), ctxt->vcpu); \
rc = do_insn_fetch(ctxt, ops, (_eip), &_x, (_size)); \
if (rc != 0) \
goto done; \
(_eip) += (_size); \
Expand Down Expand Up @@ -446,6 +445,41 @@ static u16 twobyte_table[256] = {
register_address_increment(c->eip, rel); \
} while (0)

static int do_fetch_insn_byte(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops,
unsigned long linear, u8 *dest)
{
struct fetch_cache *fc = &ctxt->decode.fetch;
int rc;
int size;

if (linear < fc->start || linear >= fc->end) {
size = min(15UL, PAGE_SIZE - offset_in_page(linear));
rc = ops->read_std(linear, fc->data, size, ctxt->vcpu);
if (rc)
return rc;
fc->start = linear;
fc->end = linear + size;
}
*dest = fc->data[linear - fc->start];
return 0;
}

static int do_insn_fetch(struct x86_emulate_ctxt *ctxt,
struct x86_emulate_ops *ops,
unsigned long eip, void *dest, unsigned size)
{
int rc = 0;

eip += ctxt->cs_base;
while (size--) {
rc = do_fetch_insn_byte(ctxt, ops, eip++, dest++);
if (rc)
return rc;
}
return 0;
}

/*
* Given the 'reg' portion of a ModRM byte, and a register block, return a
* pointer into the block that addresses the relevant register.
Expand Down
7 changes: 7 additions & 0 deletions trunk/drivers/kvm/x86_emulate.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ struct operand {
unsigned long val, orig_val, *ptr;
};

struct fetch_cache {
u8 data[15];
unsigned long start;
unsigned long end;
};

struct decode_cache {
u8 twobyte;
u8 b;
Expand All @@ -130,6 +136,7 @@ struct decode_cache {
u8 use_modrm_ea;
unsigned long modrm_ea;
unsigned long modrm_val;
struct fetch_cache fetch;
};

struct x86_emulate_ctxt {
Expand Down

0 comments on commit e16fbe7

Please sign in to comment.