From c050b34ff92ffe3f6b8a5255bfcfaceb76402e20 Mon Sep 17 00:00:00 2001 From: Alexis Engelke Date: Sun, 10 Jan 2021 15:04:37 +0100 Subject: [PATCH] instrs: Add support for undocumented instructions Undocumented instruction are not decoded by default. - SALC: undocumented in any recent manual and unsupported by newer Intel CPUs. Including as listed by [1,2]. - Undocumented FPU instructions: see [2]. [1]: http://www.rcollins.org/secrets/opcodes/SALC.html [2]: https://github.com/xoreaxeaxeax/sandsifter/issues/33 --- instrs.txt | 8 +++++++- meson.build | 3 +++ meson_options.txt | 1 + parseinstrs.py | 9 ++++++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/instrs.txt b/instrs.txt index c3a0095..14979ad 100644 --- a/instrs.txt +++ b/instrs.txt @@ -252,7 +252,7 @@ d3/6 MC GP GP8 - - SHL d3/7 MC GP GP8 - - SAR d4 I IMM - - - AAM ONLY32 SIZE_8 d5 I IMM - - - AAD ONLY32 SIZE_8 -#d6 unused +d6 NP - - - - SALC ONLY32 UNDOC d7 NP - - - - XLATB #d8-df FPU Escape e0 D IMM - - - LOOPNZ FORCE64 IMM_8 @@ -1357,8 +1357,11 @@ db/0r M FPU - - - FCMOVNB db/1r M FPU - - - FCMOVNE db/2r M FPU - - - FCMOVNBE db/3r M FPU - - - FCMOVNU +dbe0 NP - - - - FENI8087_NOP UNDOC +dbe1 NP - - - - FDISI8087_NOP UNDOC dbe2 NP - - - - FCLEX dbe3 NP - - - - FINIT +dbe4 NP - - - - FSETPM287_NOP UNDOC db/5r M FPU - - - FUCOMI db/6r M FPU - - - FCOMI dc/0m M MEM64 - - - FADD ENC_SEPSZ @@ -1371,6 +1374,8 @@ dc/6m M MEM64 - - - FDIV ENC_SEPSZ dc/7m M MEM64 - - - FDIVR ENC_SEPSZ dc/0r MA FPU FPU - - FADD dc/1r MA FPU FPU - - FMUL +dc/2r MA FPU FPU - - FCOM UNDOC +dc/3r MA FPU FPU - - FCOMP UNDOC dc/4r MA FPU FPU - - FSUBR dc/5r MA FPU FPU - - FSUB dc/6r MA FPU FPU - - FDIVR @@ -1410,6 +1415,7 @@ df/4m M FPU - - - FBLD df/5m M MEM64 - - - FILD ENC_SEPSZ df/6m M FPU - - - FBSTP df/7m M MEM64 - - - FISTP ENC_SEPSZ +df/0r M FPU - - - FFREEP UNDOC # FSTSW AX dfe0 A GP16 - - - FSTSW df/5r AM FPU FPU - - FUCOMIP diff --git a/meson.build b/meson.build index 75be6d2..aee61aa 100644 --- a/meson.build +++ b/meson.build @@ -35,6 +35,9 @@ endif if get_option('archmode') != 'only32' generate_args += ['--64'] endif +if get_option('with_undoc') + generate_args += ['--with-undoc'] +endif instr_data = custom_target('tables', command: [python3, '@INPUT0@', '@INPUT1@', '@OUTPUT@'] + generate_args, diff --git a/meson_options.txt b/meson_options.txt index 5f6a767..d80fd3d 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,2 @@ option('archmode', type: 'combo', choices: ['both', 'only32', 'only64']) +option('with_undoc', type: 'boolean', value: false) diff --git a/parseinstrs.py b/parseinstrs.py index df9c4b6..d201b61 100644 --- a/parseinstrs.py +++ b/parseinstrs.py @@ -471,7 +471,7 @@ def encode_table(entries): for opcode, desc in entries: if desc.mnemonic[:9] == "RESERVED_": continue - if "ONLY32" in desc.flags or "UNDOC" in desc.flags: + if "ONLY32" in desc.flags: continue opsizes = {8} if "SIZE_8" in desc.flags else {16, 32, 64} @@ -615,6 +615,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--32", dest="modes", action="append_const", const=32) parser.add_argument("--64", dest="modes", action="append_const", const=64) + parser.add_argument("--with-undoc", action="store_true") parser.add_argument("table", type=argparse.FileType('r')) parser.add_argument("decode_mnems", type=argparse.FileType('w')) parser.add_argument("decode_table", type=argparse.FileType('w')) @@ -625,8 +626,10 @@ if __name__ == "__main__": entries = [] for line in args.table.read().splitlines(): if not line or line[0] == "#": continue - opcode_string, desc = tuple(line.split(maxsplit=1)) - entries.append((Opcode.parse(opcode_string), InstrDesc.parse(desc))) + opcode_string, desc_string = tuple(line.split(maxsplit=1)) + opcode, desc = Opcode.parse(opcode_string), InstrDesc.parse(desc_string) + if "UNDOC" not in desc.flags or args.with_undoc: + entries.append((opcode, desc)) mnemonics = sorted({desc.mnemonic for _, desc in entries})