aboutsummaryrefslogtreecommitdiff
path: root/C/Bra.h
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2023-06-21 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2023-12-17 14:59:19 +0500
commit5b39dc76f1bc82f941d5c800ab9f34407a06b53a (patch)
treefe5e17420300b715021a76328444088d32047963 /C/Bra.h
parent93be7d4abfd4233228f58ee1fbbcd76d91be66a4 (diff)
download7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.tar.gz
7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.tar.bz2
7zip-5b39dc76f1bc82f941d5c800ab9f34407a06b53a.zip
23.0123.01
Diffstat (limited to 'C/Bra.h')
-rw-r--r--C/Bra.h115
1 files changed, 75 insertions, 40 deletions
diff --git a/C/Bra.h b/C/Bra.h
index 855e37a..a4ee568 100644
--- a/C/Bra.h
+++ b/C/Bra.h
@@ -1,64 +1,99 @@
1/* Bra.h -- Branch converters for executables 1/* Bra.h -- Branch converters for executables
22013-01-18 : Igor Pavlov : Public domain */ 22023-04-02 : Igor Pavlov : Public domain */
3 3
4#ifndef __BRA_H 4#ifndef ZIP7_INC_BRA_H
5#define __BRA_H 5#define ZIP7_INC_BRA_H
6 6
7#include "7zTypes.h" 7#include "7zTypes.h"
8 8
9EXTERN_C_BEGIN 9EXTERN_C_BEGIN
10 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
23Z7_BRANCH_CONV_ST_DECL(Z7_BRANCH_CONV_ST_DEC(X86));
24Z7_BRANCH_CONV_ST_DECL(Z7_BRANCH_CONV_ST_ENC(X86));
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
30Z7_BRANCH_FUNCS_DECL(ARM64)
31Z7_BRANCH_FUNCS_DECL(ARM)
32Z7_BRANCH_FUNCS_DECL(ARMT)
33Z7_BRANCH_FUNCS_DECL(PPC)
34Z7_BRANCH_FUNCS_DECL(SPARC)
35Z7_BRANCH_FUNCS_DECL(IA64)
36
11/* 37/*
12These functions convert relative addresses to absolute addresses 38These functions convert data that contain CPU instructions.
13in CALL instructions to increase the compression ratio. 39Each such function converts relative addresses to absolute addresses in some
14 40branch instructions: CALL (in all converters) and JUMP (X86 converter only).
15 In: 41Such conversion allows to increase compression ratio, if we compress that data.
16 data - data buffer 42
17 size - size of data 43There are 2 types of converters:
18 ip - current virtual Instruction Pinter (IP) value 44 Byte * Conv_RISC (Byte *data, SizeT size, UInt32 pc);
19 state - state variable for x86 converter 45 Byte * ConvSt_X86(Byte *data, SizeT size, UInt32 pc, UInt32 *state);
20 encoding - 0 (for decoding), 1 (for encoding) 46Each Converter supports 2 versions: one for encoding
21 47and one for decoding (_Enc/_Dec postfixes in function name).
22 Out:
23 state - state variable for x86 converter
24 48
25 Returns: 49In params:
26 The number of processed bytes. If you call these functions with multiple calls, 50 data : data buffer
27 you must start next call with first byte after block of processed bytes. 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.
28 62
63Each converter has some characteristics: Endian, Alignment, LookAhead.
29 Type Endian Alignment LookAhead 64 Type Endian Alignment LookAhead
30 65
31 x86 little 1 4 66 X86 little 1 4
32 ARMT little 2 2 67 ARMT little 2 2
33 ARM little 4 0 68 ARM little 4 0
69 ARM64 little 4 0
34 PPC big 4 0 70 PPC big 4 0
35 SPARC big 4 0 71 SPARC big 4 0
36 IA64 little 16 0 72 IA64 little 16 0
37 73
38 size must be >= Alignment + LookAhead, if it's not last block. 74 (data) must be aligned for (Alignment).
39 If (size < Alignment + LookAhead), converter returns 0. 75 processed size can be calculated as:
40 76 SizeT processed = Conv(data, size, pc) - data;
41 Example: 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.
42 81
43 UInt32 ip = 0; 82Example code for conversion in loop:
44 for () 83 UInt32 pc = 0;
45 { 84 size = 0;
46 ; size must be >= Alignment + LookAhead, if it's not last block 85 for (;;)
47 SizeT processed = Convert(data, size, ip, 1); 86 {
48 data += processed; 87 size += Load_more_input_data(data + size);
49 size -= processed; 88 SizeT processed = Conv(data, size, pc) - data;
50 ip += processed; 89 if (processed == 0 && no_more_input_data_after_size)
51 } 90 break; // we stop convert loop
91 data += processed;
92 size -= processed;
93 pc += processed;
94 }
52*/ 95*/
53 96
54#define x86_Convert_Init(state) { state = 0; }
55SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
56SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
57SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
58SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
59SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
60SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
61
62EXTERN_C_END 97EXTERN_C_END
63 98
64#endif 99#endif