/src/CMake/Utilities/cmliblzma/liblzma/simple/arm.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: 0BSD |
2 | | |
3 | | /////////////////////////////////////////////////////////////////////////////// |
4 | | // |
5 | | /// \file arm.c |
6 | | /// \brief Filter for ARM binaries |
7 | | /// |
8 | | // Authors: Igor Pavlov |
9 | | // Lasse Collin |
10 | | // |
11 | | /////////////////////////////////////////////////////////////////////////////// |
12 | | |
13 | | #include "simple_private.h" |
14 | | |
15 | | |
16 | | static size_t |
17 | | arm_code(void *simple lzma_attribute((__unused__)), |
18 | | uint32_t now_pos, bool is_encoder, |
19 | | uint8_t *buffer, size_t size) |
20 | 98 | { |
21 | 98 | size_t i; |
22 | 722 | for (i = 0; i + 4 <= size; i += 4) { |
23 | 624 | if (buffer[i + 3] == 0xEB) { |
24 | 16 | uint32_t src = ((uint32_t)(buffer[i + 2]) << 16) |
25 | 16 | | ((uint32_t)(buffer[i + 1]) << 8) |
26 | 16 | | (uint32_t)(buffer[i + 0]); |
27 | 16 | src <<= 2; |
28 | | |
29 | 16 | uint32_t dest; |
30 | 16 | if (is_encoder) |
31 | 0 | dest = now_pos + (uint32_t)(i) + 8 + src; |
32 | 16 | else |
33 | 16 | dest = src - (now_pos + (uint32_t)(i) + 8); |
34 | | |
35 | 16 | dest >>= 2; |
36 | 16 | buffer[i + 2] = (dest >> 16); |
37 | 16 | buffer[i + 1] = (dest >> 8); |
38 | 16 | buffer[i + 0] = dest; |
39 | 16 | } |
40 | 624 | } |
41 | | |
42 | 98 | return i; |
43 | 98 | } |
44 | | |
45 | | |
46 | | static lzma_ret |
47 | | arm_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, |
48 | | const lzma_filter_info *filters, bool is_encoder) |
49 | 32 | { |
50 | 32 | return lzma_simple_coder_init(next, allocator, filters, |
51 | 32 | &arm_code, 0, 4, 4, is_encoder); |
52 | 32 | } |
53 | | |
54 | | |
55 | | #ifdef HAVE_ENCODER_ARM |
56 | | extern lzma_ret |
57 | | lzma_simple_arm_encoder_init(lzma_next_coder *next, |
58 | | const lzma_allocator *allocator, |
59 | | const lzma_filter_info *filters) |
60 | 0 | { |
61 | 0 | return arm_coder_init(next, allocator, filters, true); |
62 | 0 | } |
63 | | #endif |
64 | | |
65 | | |
66 | | #ifdef HAVE_DECODER_ARM |
67 | | extern lzma_ret |
68 | | lzma_simple_arm_decoder_init(lzma_next_coder *next, |
69 | | const lzma_allocator *allocator, |
70 | | const lzma_filter_info *filters) |
71 | 32 | { |
72 | | return arm_coder_init(next, allocator, filters, false); |
73 | 32 | } |
74 | | #endif |