mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-26 22:38: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
28
third_party/xed/eamode.c
vendored
Normal file
28
third_party/xed/eamode.c
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/xed/x86.h"
|
||||
|
||||
const uint8_t kXedEamode[2][3] = {
|
||||
[0][XED_MODE_REAL] = XED_MODE_REAL,
|
||||
[0][XED_MODE_LEGACY] = XED_MODE_LEGACY,
|
||||
[0][XED_MODE_LONG] = XED_MODE_LONG,
|
||||
[1][XED_MODE_REAL] = XED_MODE_LEGACY,
|
||||
[1][XED_MODE_LEGACY] = XED_MODE_REAL,
|
||||
[1][XED_MODE_LONG] = XED_MODE_LEGACY,
|
||||
};
|
3
third_party/xed/x86.h
vendored
3
third_party/xed/x86.h
vendored
|
@ -487,7 +487,8 @@ forceinline void xed_set_chip_modes(struct XedDecodedInst *d,
|
|||
}
|
||||
|
||||
extern const char kXedErrorNames[];
|
||||
extern const uint64_t xed_chip_features[XED_CHIP_LAST][3];
|
||||
extern const uint64_t kXedChipFeatures[XED_CHIP_LAST][3];
|
||||
extern const uint8_t kXedEamode[2][3];
|
||||
|
||||
struct XedDecodedInst *xed_decoded_inst_zero_set_mode(struct XedDecodedInst *,
|
||||
enum XedMachineMode);
|
||||
|
|
3
third_party/xed/x86features.c
vendored
3
third_party/xed/x86features.c
vendored
|
@ -36,8 +36,7 @@ asm(".include \"libc/disclaimer.inc\"");
|
|||
* example, 0x2800000ul was calculated as: 1UL<<(XED_ISA_SET_I86-64) |
|
||||
* 1UL<<(XED_ISA_SET_LAHF-64).
|
||||
*/
|
||||
const uint64_t xed_chip_features[XED_CHIP_LAST][3] /* clang-format off */
|
||||
_Section(".text") = {
|
||||
const uint64_t kXedChipFeatures[XED_CHIP_LAST][3] /* clang-format off */ = {
|
||||
{0, 0, 0, },
|
||||
{0, 0x02800000, 0, }, /*I86*/
|
||||
{0, 0x02800000, 0x02000}, /*I86FP*/
|
||||
|
|
303
third_party/xed/x86ild.greg.c
vendored
303
third_party/xed/x86ild.greg.c
vendored
|
@ -111,7 +111,6 @@ extern const uint8_t xed_disp_bits_2d[XED_ILD_MAP2][256] hidden;
|
|||
|
||||
static const struct XedDenseMagnums {
|
||||
unsigned vex_prefix_recoding[4];
|
||||
xed_bits_t eamode[2][3];
|
||||
xed_bits_t BRDISPz_BRDISP_WIDTH[4];
|
||||
xed_bits_t MEMDISPv_DISP_WIDTH[4];
|
||||
xed_bits_t SIMMz_IMM_WIDTH[4];
|
||||
|
@ -136,186 +135,177 @@ static const struct XedDenseMagnums {
|
|||
.UIMMv_IMM_WIDTH = {0x00, 0x10, 0x20, 0x40},
|
||||
.ASZ_NONTERM_EASZ =
|
||||
{
|
||||
[0][0] = 0x1,
|
||||
[1][0] = 0x2,
|
||||
[0][1] = 0x2,
|
||||
[1][1] = 0x1,
|
||||
[0][2] = 0x3,
|
||||
[1][2] = 0x2,
|
||||
[0][0] = 1,
|
||||
[1][0] = 2,
|
||||
[0][1] = 2,
|
||||
[1][1] = 1,
|
||||
[0][2] = 3,
|
||||
[1][2] = 2,
|
||||
},
|
||||
.OSZ_NONTERM_CR_WIDTH_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x2,
|
||||
[1][0][0] = 0x2,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x2,
|
||||
[1][1][1] = 0x2,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x3,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 2,
|
||||
[1][0][0] = 2,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 2,
|
||||
[1][1][1] = 2,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 3,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_DF64_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x1,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 1,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_DF64_FORCE64_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x3,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 3,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_DF64_IMMUNE66_LOOP64_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x3,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 3,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x1,
|
||||
[0][0][2] = 0x2,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 1,
|
||||
[0][0][2] = 2,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_FORCE64_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x3,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 3,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_IGNORE66_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x1,
|
||||
[1][1][0] = 0x1,
|
||||
[0][1][1] = 0x2,
|
||||
[1][1][1] = 0x2,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x2,
|
||||
[0][0][2] = 0x2,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 1,
|
||||
[1][1][0] = 1,
|
||||
[0][1][1] = 2,
|
||||
[1][1][1] = 2,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 2,
|
||||
[0][0][2] = 2,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_IMMUNE66_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x2,
|
||||
[1][0][0] = 0x2,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x2,
|
||||
[1][1][1] = 0x2,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x2,
|
||||
[0][0][2] = 0x2,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 2,
|
||||
[1][0][0] = 2,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 2,
|
||||
[1][1][1] = 2,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 2,
|
||||
[0][0][2] = 2,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_IMMUNE_REXW_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x1,
|
||||
[1][1][1] = 0x1,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x1,
|
||||
[0][0][2] = 0x2,
|
||||
[1][1][2] = 0x2,
|
||||
[1][0][2] = 0x2,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 1,
|
||||
[1][1][1] = 1,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 1,
|
||||
[0][0][2] = 2,
|
||||
[1][1][2] = 2,
|
||||
[1][0][2] = 2,
|
||||
},
|
||||
.OSZ_NONTERM_REFINING66_CR_WIDTH_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x2,
|
||||
[1][0][0] = 0x2,
|
||||
[0][1][0] = 0x2,
|
||||
[1][1][0] = 0x2,
|
||||
[0][1][1] = 0x2,
|
||||
[1][1][1] = 0x2,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x3,
|
||||
[0][0][2] = 0x3,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
[0][0][0] = 2,
|
||||
[1][0][0] = 2,
|
||||
[0][1][0] = 2,
|
||||
[1][1][0] = 2,
|
||||
[0][1][1] = 2,
|
||||
[1][1][1] = 2,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 3,
|
||||
[0][0][2] = 3,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
.OSZ_NONTERM_REFINING66_EOSZ =
|
||||
{
|
||||
[0][0][0] = 0x1,
|
||||
[1][0][0] = 0x1,
|
||||
[0][1][0] = 0x1,
|
||||
[1][1][0] = 0x1,
|
||||
[0][1][1] = 0x2,
|
||||
[1][1][1] = 0x2,
|
||||
[0][0][1] = 0x2,
|
||||
[1][0][1] = 0x2,
|
||||
[0][1][2] = 0x2,
|
||||
[0][0][2] = 0x2,
|
||||
[1][1][2] = 0x3,
|
||||
[1][0][2] = 0x3,
|
||||
},
|
||||
.eamode =
|
||||
{
|
||||
[0][XED_MODE_REAL] = XED_MODE_REAL,
|
||||
[0][XED_MODE_LEGACY] = XED_MODE_LEGACY,
|
||||
[0][XED_MODE_LONG] = XED_MODE_LONG,
|
||||
[1][XED_MODE_REAL] = XED_MODE_LEGACY,
|
||||
[1][XED_MODE_LEGACY] = XED_MODE_REAL,
|
||||
[1][XED_MODE_LONG] = XED_MODE_LEGACY,
|
||||
[0][0][0] = 1,
|
||||
[1][0][0] = 1,
|
||||
[0][1][0] = 1,
|
||||
[1][1][0] = 1,
|
||||
[0][1][1] = 2,
|
||||
[1][1][1] = 2,
|
||||
[0][0][1] = 2,
|
||||
[1][0][1] = 2,
|
||||
[0][1][2] = 2,
|
||||
[0][0][2] = 2,
|
||||
[1][1][2] = 3,
|
||||
[1][0][2] = 3,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -633,7 +623,6 @@ privileged static void xed_get_next_as_opcode(struct XedDecodedInst *d) {
|
|||
b = d->bytes[length];
|
||||
d->op.opcode = b;
|
||||
d->length++;
|
||||
/* d->op.srm = xed_modrm_rm(b); */
|
||||
} else {
|
||||
xed_too_short(d);
|
||||
}
|
||||
|
@ -722,7 +711,6 @@ privileged static void xed_opcode_scanner(struct XedDecodedInst *d) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
/* d->op.srm = xed_modrm_rm(d->op.opcode); */
|
||||
}
|
||||
|
||||
privileged static bool xed_is_bound_instruction(struct XedDecodedInst *d) {
|
||||
|
@ -974,7 +962,7 @@ privileged static void xed_modrm_scanner(struct XedDecodedInst *d) {
|
|||
if (has_modrm != XED_ILD_HASMODRM_IGNORE_MOD) {
|
||||
asz = d->op.asz;
|
||||
mode = d->op.mode;
|
||||
eamode = kXed.eamode[asz][mode];
|
||||
eamode = kXedEamode[asz][mode];
|
||||
d->op.disp_width =
|
||||
xed_bytes2bits(xed_has_disp_regular[eamode][mod][rm]);
|
||||
d->op.has_sib = xed_has_sib_table[eamode][mod][rm];
|
||||
|
@ -1123,18 +1111,6 @@ privileged static void xed_decode_instruction_length(
|
|||
}
|
||||
}
|
||||
|
||||
privileged static void xed_encode_rde(struct XedDecodedInst *x) {
|
||||
const uint8_t kWordLog2[2][2][2] = {{{2, 3}, {1, 3}}, {{0, 0}, {0, 0}}};
|
||||
uint32_t osz = x->op.osz ^ x->op.realmode;
|
||||
x->op.rde = kWordLog2[~x->op.opcode & 1][osz][x->op.rexw] << 28 |
|
||||
x->op.mode << 26 | kXed.eamode[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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears instruction decoder state.
|
||||
*/
|
||||
|
@ -1160,7 +1136,6 @@ privileged enum XedError xed_instruction_length_decode(
|
|||
__builtin_memcpy(xedd->bytes, itext, MIN(15, bytes));
|
||||
xedd->op.max_bytes = MIN(15, bytes);
|
||||
xed_decode_instruction_length(xedd);
|
||||
xed_encode_rde(xedd);
|
||||
if (!xedd->op.out_of_bytes) {
|
||||
if (xedd->op.map != XED_ILD_MAP_INVALID) {
|
||||
return xedd->op.error;
|
||||
|
|
8
third_party/xed/x86isa.c
vendored
8
third_party/xed/x86isa.c
vendored
|
@ -29,7 +29,7 @@ bool xed_isa_set_is_valid_for_chip(enum XedIsaSet isa_set, enum XedChip chip) {
|
|||
unsigned n, r;
|
||||
n = isa_set / 64;
|
||||
r = isa_set - (64 * n);
|
||||
return !!(xed_chip_features[chip][n] & (1ul << r));
|
||||
return !!(kXedChipFeatures[chip][n] & (1ul << r));
|
||||
}
|
||||
|
||||
bool xed_test_chip_features(struct XedChipFeatures *p, enum XedIsaSet isa_set) {
|
||||
|
@ -42,9 +42,9 @@ bool xed_test_chip_features(struct XedChipFeatures *p, enum XedIsaSet isa_set) {
|
|||
void xed_get_chip_features(struct XedChipFeatures *p, enum XedChip chip) {
|
||||
if (p) {
|
||||
if (chip < XED_CHIP_LAST) {
|
||||
p->f[0] = xed_chip_features[chip][0];
|
||||
p->f[1] = xed_chip_features[chip][1];
|
||||
p->f[2] = xed_chip_features[chip][2];
|
||||
p->f[0] = kXedChipFeatures[chip][0];
|
||||
p->f[1] = kXedChipFeatures[chip][1];
|
||||
p->f[2] = kXedChipFeatures[chip][2];
|
||||
} else {
|
||||
p->f[0] = 0;
|
||||
p->f[1] = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue