mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Perform some code cleanup
This commit is contained in:
parent
3e17c7b20f
commit
19d0c15e03
41 changed files with 321 additions and 459 deletions
|
@ -219,6 +219,7 @@ static long DisAppendOpLines(struct Dis *d, struct Machine *m, int64_t addr) {
|
|||
}
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, m->mode);
|
||||
xed_instruction_length_decode(d->xedd, p, n);
|
||||
d->xedd->op.rde = EncodeRde(d->xedd);
|
||||
n = d->xedd->op.error ? 1 : d->xedd->length;
|
||||
op.addr = addr;
|
||||
op.size = n;
|
||||
|
@ -255,6 +256,7 @@ const char *DisGetLine(struct Dis *d, struct Machine *m, size_t i) {
|
|||
xed_instruction_length_decode(
|
||||
d->xedd, AccessRam(m, d->ops.p[i].addr, d->ops.p[i].size, r, b, true),
|
||||
d->ops.p[i].size);
|
||||
d->xedd->op.rde = EncodeRde(d->xedd);
|
||||
d->m = m;
|
||||
d->addr = d->ops.p[i].addr;
|
||||
CHECK_LT(DisLineCode(d, d->buf) - d->buf, sizeof(d->buf));
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "tool/build/lib/endian.h"
|
||||
#include "tool/build/lib/machine.h"
|
||||
#include "tool/build/lib/memory.h"
|
||||
#include "tool/build/lib/modrm.h"
|
||||
#include "tool/build/lib/stats.h"
|
||||
#include "tool/build/lib/throw.h"
|
||||
|
||||
|
@ -45,6 +46,7 @@ static void DecodeInstruction(struct Machine *m, uint8_t *p, unsigned n) {
|
|||
struct XedDecodedInst xedd[1];
|
||||
xed_decoded_inst_zero_set_mode(xedd, m->mode);
|
||||
if (!xed_instruction_length_decode(xedd, p, n)) {
|
||||
xedd->op.rde = EncodeRde(xedd);
|
||||
memcpy(m->xedd, xedd, sizeof(m->icache[0]));
|
||||
} else {
|
||||
HaltMachine(m, kMachineDecodeError);
|
||||
|
|
|
@ -25,6 +25,21 @@
|
|||
#include "tool/build/lib/modrm.h"
|
||||
#include "tool/build/lib/throw.h"
|
||||
|
||||
/**
|
||||
* Compactly represents important parts of xed ild result.
|
||||
*/
|
||||
uint32_t EncodeRde(struct XedDecodedInst *x) {
|
||||
uint8_t kWordLog2[2][2][2] = {{{2, 3}, {1, 3}}, {{0, 0}, {0, 0}}};
|
||||
uint32_t osz = x->op.osz ^ x->op.realmode;
|
||||
return kWordLog2[~x->op.opcode & 1][osz][x->op.rexw] << 28 |
|
||||
x->op.mode << 26 | kXedEamode[x->op.asz][x->op.mode] << 24 |
|
||||
x->op.rep << 30 | x->op.mod << 22 | x->op.asz << 17 |
|
||||
x->op.seg_ovd << 18 | x->op.rexw << 6 | osz << 5 |
|
||||
(x->op.rex << 4 | x->op.rexb << 3 | x->op.srm) << 12 |
|
||||
(x->op.rex << 4 | x->op.rexb << 3 | x->op.rm) << 7 |
|
||||
(x->op.rex << 4 | x->op.rexr << 3 | x->op.reg);
|
||||
}
|
||||
|
||||
struct AddrSeg LoadEffectiveAddress(const struct Machine *m, uint32_t rde) {
|
||||
uint8_t *s = m->ds;
|
||||
uint64_t i = m->xedd->op.disp;
|
||||
|
|
|
@ -57,6 +57,7 @@ struct AddrSeg {
|
|||
|
||||
extern const uint8_t kByteReg[32];
|
||||
|
||||
uint32_t EncodeRde(struct XedDecodedInst *);
|
||||
int64_t ComputeAddress(const struct Machine *, uint32_t);
|
||||
struct AddrSeg LoadEffectiveAddress(const struct Machine *, uint32_t);
|
||||
void *ComputeReserveAddressRead(struct Machine *, uint32_t, size_t);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue