Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for builds without mnemonics. #99

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ option(BDD_INCLUDE_ISAGENERATOR_X86 "Include the x86 isagenerator target (if a p
option(BDD_INCLUDE_FUZZERS "Include the bdshemu fuzzer" OFF)
option(BDD_USE_EXTERNAL_VSNPRINTF "Expect nd_vsnprintf_s implementation from the integrator" OFF)
option(BDD_USE_EXTERNAL_MEMSET "Expect nd_memset implementation from the integrator" OFF)
option(BDD_NO_MNEMONIC "Exclude mnemonics - this option involves setting the BDDISASM_NO_FORMAT flag" OFF)
option(BDD_ASAN "Build with ASAN" OFF)
option(BDD_UBSAN "Build with UBSAN" OFF)

Expand Down Expand Up @@ -143,6 +144,11 @@ if (NOT BDD_USE_EXTERNAL_MEMSET)
endif ()
endif ()

if (BDD_NO_MNEMONIC)
target_compile_definitions(bddisasm PUBLIC -DBDDISASM_NO_MNEMONIC)
target_compile_definitions(bddisasm PUBLIC -DBDDISASM_NO_FORMAT)
endif()

set_target_properties(
bddisasm
PROPERTIES POSITION_INDEPENDENT_CODE ON
Expand Down
2 changes: 2 additions & 0 deletions bddisasm/bdx86_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -4308,7 +4308,9 @@ NdCopyInstructionInfo(
ND_IDBE *Idbe
)
{
#ifndef BDDISASM_NO_MNEMONIC
Instrux->Mnemonic = gMnemonics[Idbe->Mnemonic];
#endif // !BDDISASM_NO_MNEMONIC
Instrux->Attributes = Idbe->Attributes;
Instrux->Instruction = (ND_INS_CLASS)Idbe->Instruction;
Instrux->Category = (ND_INS_CATEGORY)Idbe->Category;
Expand Down
5 changes: 2 additions & 3 deletions bddisasm/bdx86_formatter.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include "../inc/bddisasm.h"



#ifndef BDDISASM_NO_FORMAT
#if !defined(BDDISASM_NO_MNEMONIC) && !defined(BDDISASM_NO_FORMAT)

static const char *const gReg8Bit[] =
{
Expand Down Expand Up @@ -1033,4 +1032,4 @@ NdToText(

return ND_STATUS_SUCCESS;
}
#endif // !BDDISASM_NO_FORMAT
#endif // !defined(BDDISASM_NO_MNEMONIC) && !defined(BDDISASM_NO_FORMAT)
4 changes: 4 additions & 0 deletions bddisasm/include/bdx86_mnemonics.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#ifndef BDX86_MNEMONICS_H
#define BDX86_MNEMONICS_H

#ifndef BDDISASM_NO_MNEMONIC

const char *gMnemonics[1786] =
{
"AAA", "AAD", "AADD", "AAM", "AAND", "AAS", "ADC", "ADCX", "ADD",
Expand Down Expand Up @@ -320,6 +322,8 @@ const char *gMnemonics[1786] =
"XSAVES", "XSAVES64", "XSETBV", "XSUSLDTRK", "XTEST",
};

#endif // !BDDISASM_NO_MNEMONIC


#endif

2 changes: 2 additions & 0 deletions inc/bdx86_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,9 @@ typedef struct _INSTRUX
// Aliased over low 4 bits inside the main opcode.
};

#ifndef BDDISASM_NO_MNEMONIC
const char *Mnemonic; // Instruction mnemonic.
#endif // !BDDISASM_NO_MNEMONIC
ND_UINT8 InstructionBytes[16]; // The entire instruction.
ND_UINT8 OpCodeBytes[3]; // Opcode bytes - escape codes and main opcode.

Expand Down
10 changes: 9 additions & 1 deletion isagenerator/generate_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,8 @@ def dump_mnemonics(mnemonics, prefixes, fname):
f.write('#ifndef BDX86_MNEMONICS_H\n')
f.write('#define BDX86_MNEMONICS_H\n')
f.write('\n')
f.write('#ifndef BDDISASM_NO_MNEMONIC\n')
f.write('\n')
f.write('const char *gMnemonics[%d] = \n' % len(mnemonics))
f.write('{\n')
f.write(' ')
Expand All @@ -815,7 +817,13 @@ def dump_mnemonics(mnemonics, prefixes, fname):
ln = 0
f.write('\n ')

f.write('\n};\n\n\n')

f.write('\n};\n')

f.write('\n')
f.write('#endif // !BDDISASM_NO_MNEMONIC\n')

f.write('\n\n')

f.write('#endif\n\n')

Expand Down