Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
Bra.h
Go to the documentation of this file.
1/* Bra.h -- Branch converters for executables
22023-04-02 : Igor Pavlov : Public domain */
3
4#ifndef ZIP7_INC_BRA_H
5#define ZIP7_INC_BRA_H
6
7#include "7zTypes.h"
8
10
11#define Z7_BRANCH_CONV_DEC(name) z7_BranchConv_ ## name ## _Dec
12#define Z7_BRANCH_CONV_ENC(name) z7_BranchConv_ ## name ## _Enc
13#define Z7_BRANCH_CONV_ST_DEC(name) z7_BranchConvSt_ ## name ## _Dec
14#define Z7_BRANCH_CONV_ST_ENC(name) z7_BranchConvSt_ ## name ## _Enc
15
16#define Z7_BRANCH_CONV_DECL(name) Byte * name(Byte *data, SizeT size, UInt32 pc)
17#define Z7_BRANCH_CONV_ST_DECL(name) Byte * name(Byte *data, SizeT size, UInt32 pc, UInt32 *state)
18
19typedef Z7_BRANCH_CONV_DECL( (*z7_Func_BranchConv));
20typedef Z7_BRANCH_CONV_ST_DECL((*z7_Func_BranchConvSt));
21
22#define Z7_BRANCH_CONV_ST_X86_STATE_INIT_VAL 0
25
26#define Z7_BRANCH_FUNCS_DECL(name) \
27Z7_BRANCH_CONV_DECL(Z7_BRANCH_CONV_DEC(name)); \
28Z7_BRANCH_CONV_DECL(Z7_BRANCH_CONV_ENC(name));
29
36
37/*
38These functions convert data that contain CPU instructions.
39Each such function converts relative addresses to absolute addresses in some
40branch instructions: CALL (in all converters) and JUMP (X86 converter only).
41Such conversion allows to increase compression ratio, if we compress that data.
42
43There are 2 types of converters:
44 Byte * Conv_RISC (Byte *data, SizeT size, UInt32 pc);
45 Byte * ConvSt_X86(Byte *data, SizeT size, UInt32 pc, UInt32 *state);
46Each Converter supports 2 versions: one for encoding
47and one for decoding (_Enc/_Dec postfixes in function name).
48
49In params:
50 data : data buffer
51 size : size of data
52 pc : current virtual Program Counter (Instruction Pinter) value
53In/Out param:
54 state : pointer to state variable (for X86 converter only)
55
56Return:
57 The pointer to position in (data) buffer after last byte that was processed.
58 If the caller calls converter again, it must call it starting with that position.
59 But the caller is allowed to move data in buffer. so pointer to
60 current processed position also will be changed for next call.
61 Also the caller must increase internal (pc) value for next call.
62
63Each converter has some characteristics: Endian, Alignment, LookAhead.
64 Type Endian Alignment LookAhead
65
66 X86 little 1 4
67 ARMT little 2 2
68 ARM little 4 0
69 ARM64 little 4 0
70 PPC big 4 0
71 SPARC big 4 0
72 IA64 little 16 0
73
74 (data) must be aligned for (Alignment).
75 processed size can be calculated as:
76 SizeT processed = Conv(data, size, pc) - data;
77 if (processed == 0)
78 it means that converter needs more data for processing.
79 If (size < Alignment + LookAhead)
80 then (processed == 0) is allowed.
81
82Example code for conversion in loop:
83 UInt32 pc = 0;
84 size = 0;
85 for (;;)
86 {
87 size += Load_more_input_data(data + size);
88 SizeT processed = Conv(data, size, pc) - data;
89 if (processed == 0 && no_more_input_data_after_size)
90 break; // we stop convert loop
91 data += processed;
92 size -= processed;
93 pc += processed;
94 }
95*/
96
98
99#endif
#define EXTERN_C_BEGIN
Definition 7zTypes.h:20
#define EXTERN_C_END
Definition 7zTypes.h:21
#define Z7_BRANCH_FUNCS_DECL(name)
Definition Bra.h:30
#define Z7_BRANCH_CONV_DECL(name)
Definition Bra.h:20
#define Z7_BRANCH_CONV_ST_ENC(name)
Definition Bra.h:18
#define Z7_BRANCH_CONV_ST_DECL(name)
Definition Bra.h:21
#define Z7_BRANCH_CONV_ST_DEC(name)
Definition Bra.h:17