fcml  1.1.3
fcml_assembler.h
Go to the documentation of this file.
1 /*
2  * FCML - Free Code Manipulation Library.
3  * Copyright (C) 2010-2015 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
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
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  */
19 
26 #ifndef FCML_ASSEMBLER_H_
27 #define FCML_ASSEMBLER_H_
28 
29 #include "fcml_lib_export.h"
30 
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"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
44 
48 typedef struct fcml_st_assembler_conf {
50  fcml_bool increment_ip;
58  fcml_bool force_rex_prefix;
64  fcml_uint16_t optimizer_flags;
69 
81  fcml_uint8_t *code;
83  fcml_usize code_length;
84 #ifdef FCML_DEBUG
85  fcml_uint8_t __def_index;
86 #endif
88 
90 typedef struct fcml_st_assembler_result {
100 
110 
123 LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_assembler_init( const fcml_st_dialect *dialect, fcml_st_assembler **assembler );
124 
142 LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_assemble( fcml_st_assembler_context *context, const fcml_st_instruction *instruction,
143  fcml_st_assembler_result *result );
144 
157 LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_prepare( fcml_st_assembler_result *result );
158 
167 LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_free( fcml_st_assembler_result *result );
168 
174 LIB_EXPORT void LIB_CALL fcml_fn_assembler_instruction_free( fcml_st_assembled_instruction *instruction );
175 
192 
199 LIB_EXPORT void LIB_CALL fcml_fn_assembler_free( fcml_st_assembler *assembler );
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 
205 #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:67
fcml_bool choose_abs_encoding
If memory address can be encoded as relative or absolute value choose the absolute addressing...
Definition: fcml_assembler.h:56
API for assembler optimizers.
fcml_st_assembler_conf configuration
Assembler behaviour can be configured here.
Definition: fcml_assembler.h:106
Assembler result.
Definition: fcml_assembler.h:90
fcml_st_assembled_instruction * instructions
Chain of assembled instructions.
Definition: fcml_assembler.h:94
Assembler runtime configuration.
Definition: fcml_assembler.h:48
Container for all collected errors and warnings.
Definition: fcml_errors.h:162
fcml_st_assembler * assembler
Assembler instance that should be used to assemble instructions.
Definition: fcml_assembler.h:104
struct fcml_st_assembled_instruction * next
Next assembled instruction in the chain.
Definition: fcml_assembler.h:77
Definitions of common structures used by FCML components.
struct fcml_st_dialect fcml_st_dialect
Assembler dialect.
Definition: fcml_dialect.h:34
Generic instruction model.
Definition: fcml_common.h:611
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:64
fcml_st_ceh_error_container warnings
Warning messages related to assembled instruction.
Definition: fcml_assembler.h:79
Handles Win32 DLL symbols importing/exporting.
fcml_st_entry_point entry_point
Instruction entry point configuration.
Definition: fcml_assembler.h:108
fcml_st_assembled_instruction * chosen_instruction
Instruction chosen by used instruction chooser; otherwise NULL.
Definition: fcml_assembler.h:96
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:52
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:102
fcml_fnp_asm_instruction_chooser chooser
instruction chooser implementation that should be used by assembler to choose most appropriate instru...
Definition: fcml_assembler.h:67
fcml_fnp_asm_optimizer optimizer
Optimizer implementation that should be used by assembler.
Definition: fcml_assembler.h:62
fcml_bool force_rex_prefix
Sometimes REX prefix is useless so it is just omitted in the final machine code.
Definition: fcml_assembler.h:58
fcml_bool force_three_byte_VEX
Every 2 byte VEX/XOP prefix can be encoded using three byte form.
Definition: fcml_assembler.h:60
fcml_uint8_t * code
Instruction machine code.
Definition: fcml_assembler.h:81
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:649
Encoded instruction.
Definition: fcml_assembler.h:75
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:54
fcml_usize number_of_instructions
Number of encoded instruction forms.
Definition: fcml_assembler.h:98
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:92
fcml_uint16_t fcml_ceh_error
All error codes should be held in variables of this type.
Definition: fcml_errors.h:139
fcml_usize code_length
Instruction code length in bytes.
Definition: fcml_assembler.h:83
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:50
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:94