fcml  1.2.2
Go to the documentation of this file.
1 /*
2  * FCML - Free Code Manipulation Library.
3  * Copyright (C) 2010-2020 Slawomir Wojtasiak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
26 #ifndef FCML_ASSEMBLER_H_
27 #define FCML_ASSEMBLER_H_
29 #include "fcml_lib_export.h"
31 #include "fcml_types.h"
32 #include "fcml_errors.h"
33 #include "fcml_common.h"
34 #include "fcml_dialect.h"
35 #include "fcml_optimizers.h"
36 #include "fcml_choosers.h"
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
48 typedef struct fcml_st_assembler_conf {
51  fcml_bool increment_ip;
64  fcml_bool force_rex_prefix;
73  fcml_uint16_t optimizer_flags;
91  fcml_uint8_t *code;
93  fcml_usize code_length;
94 #ifdef FCML_DEBUG
95  fcml_uint8_t __def_index;
96 #endif
100 typedef struct fcml_st_assembler_result {
133 LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_assembler_init(
134  const fcml_st_dialect *dialect, fcml_st_assembler **assembler);
154 LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_assemble(
155  fcml_st_assembler_context *context,
156  const fcml_st_instruction *instruction,
157  fcml_st_assembler_result *result);
172 LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_prepare(
173  fcml_st_assembler_result *result);
184 LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_free(
185  fcml_st_assembler_result *result);
193 LIB_EXPORT void LIB_CALL fcml_fn_assembler_instruction_free(
194  fcml_st_assembled_instruction *instruction);
211 LIB_EXPORT void LIB_CALL fcml_fn_assembler_instruction_detach(
213  fcml_st_assembled_instruction *instruction);
221 LIB_EXPORT void LIB_CALL fcml_fn_assembler_free(fcml_st_assembler *assembler);
223 #ifdef __cplusplus
224 }
225 #endif
227 #endif /* FCML_ASSEMBLER_H_ */
struct fcml_st_assembler_result fcml_st_assembler_result
Assembler result.
fcml_ptr(LIB_CALL * fcml_fnp_asm_instruction_chooser)(fcml_st_chooser_context *chooser_context)
Instruction chooser function pointer declaration.
Definition: fcml_choosers.h:68
fcml_bool choose_abs_encoding
If memory address can be encoded as relative or absolute value choose the absolute addressing...
Definition: fcml_assembler.h:60
API for assembler optimizers.
fcml_st_assembler_conf configuration
Assembler behavior can be configured here.
Definition: fcml_assembler.h:116
Assembler result.
Definition: fcml_assembler.h:100
fcml_st_assembled_instruction * instructions
Chain of assembled instructions.
Definition: fcml_assembler.h:104
Assembler runtime configuration.
Definition: fcml_assembler.h:48
Container for all collected errors and warnings.
Definition: fcml_errors.h:180
fcml_st_assembler * assembler
Assembler instance that should be used to assemble instructions.
Definition: fcml_assembler.h:114
struct fcml_st_assembled_instruction * next
Next assembled instruction in the chain.
Definition: fcml_assembler.h:87
Definitions of common structures used by FCML components.
struct fcml_st_dialect fcml_st_dialect
Assembler dialect.
Definition: fcml_dialect.h:36
Generic instruction model.
Definition: fcml_common.h:783
struct fcml_st_assembler_context fcml_st_assembler_context
Assembler runtime context.
LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_prepare(fcml_st_assembler_result *result)
Prepares reusable result holder for assembler.
fcml_uint16_t optimizer_flags
This field is passed to the chosen optimizer.
Definition: fcml_assembler.h:73
fcml_st_ceh_error_container warnings
Warning messages related to assembled instruction.
Definition: fcml_assembler.h:89
Handles Win32 DLL symbols importing/exporting.
fcml_st_entry_point entry_point
Instruction entry point configuration.
Definition: fcml_assembler.h:118
fcml_st_assembled_instruction * chosen_instruction
Instruction chosen by used instruction chooser; otherwise NULL.
Definition: fcml_assembler.h:106
struct fcml_st_assembler_conf fcml_st_assembler_conf
Assembler runtime configuration.
LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_free(fcml_st_assembler_result *result)
Cleans result holder.
fcml_bool enable_error_messages
True if optional error and warning messages should be collected during processing.
Definition: fcml_assembler.h:54
struct fcml_st_assembled_instruction fcml_st_assembled_instruction
Encoded instruction.
LIB_EXPORT void LIB_CALL fcml_fn_assembler_instruction_free(fcml_st_assembled_instruction *instruction)
Frees assembled instruction.
Assembler runtime context.
Definition: fcml_assembler.h:112
fcml_fnp_asm_instruction_chooser chooser
instruction chooser implementation that should be used by assembler to choose most appropriate instru...
Definition: fcml_assembler.h:77
fcml_fnp_asm_optimizer optimizer
Optimizer implementation that should be used by assembler.
Definition: fcml_assembler.h:70
fcml_bool force_rex_prefix
Sometimes REX prefix is useless so it is just omitted in the final machine code.
Definition: fcml_assembler.h:64
fcml_bool force_three_byte_VEX
Every 2 byte VEX/XOP prefix can be encoded using three byte form.
Definition: fcml_assembler.h:67
fcml_uint8_t * code
Instruction machine code.
Definition: fcml_assembler.h:91
LIB_EXPORT void LIB_CALL fcml_fn_assembler_free(fcml_st_assembler *assembler)
Frees assembler instance.
LIB_EXPORT void LIB_CALL fcml_fn_assembler_instruction_detach(fcml_st_assembled_instruction **chain, fcml_st_assembled_instruction *instruction)
Detaches given instruction from the instructions chain.
Describes address of an instruction code.
Definition: fcml_common.h:824
Encoded instruction.
Definition: fcml_assembler.h:85
Structures and functions related to dialects.
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_assembler_init(const fcml_st_dialect *dialect, fcml_st_assembler **assembler)
Initializes assembler for given dialect.
Global error handling related declarations.
fcml_bool choose_sib_encoding
If there are SIB and "ModR/M only" encodings available, choose the SIB based one. ...
Definition: fcml_assembler.h:57
fcml_usize number_of_instructions
Number of encoded instruction forms.
Definition: fcml_assembler.h:108
API for instruction choosers.
struct fcml_st_assembler fcml_st_assembler
Abstract assembler representation.
Definition: fcml_assembler.h:43
fcml_st_ceh_error_container errors
Error and warning messages from assembler.
Definition: fcml_assembler.h:102
fcml_uint16_t fcml_ceh_error
All error codes should be held in variables of this type.
Definition: fcml_errors.h:156
fcml_usize code_length
Instruction code length in bytes.
Definition: fcml_assembler.h:93
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_assemble(fcml_st_assembler_context *context, const fcml_st_instruction *instruction, fcml_st_assembler_result *result)
Assembles one instruction encoded in the generic instruction model.
Types declarations.
fcml_bool increment_ip
Set to true in order to force assembler to increment IP address by length of the assembled instructio...
Definition: fcml_assembler.h:51
fcml_ceh_error(LIB_CALL * fcml_fnp_asm_optimizer)(fcml_st_asm_optimizer_context *context, fcml_st_asm_optimizer_processing_details *ds_flags, fcml_fnp_asm_optimizer_callback callback, fcml_ptr args)
Function pointer declaration for optimizers.
Definition: fcml_optimizers.h:102