/src/CMake/Utilities/cmliblzma/liblzma/simple/sparc.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: 0BSD |
2 | | |
3 | | /////////////////////////////////////////////////////////////////////////////// |
4 | | // |
5 | | /// \file sparc.c |
6 | | /// \brief Filter for SPARC binaries |
7 | | /// |
8 | | // Authors: Igor Pavlov |
9 | | // Lasse Collin |
10 | | // |
11 | | /////////////////////////////////////////////////////////////////////////////// |
12 | | |
13 | | #include "simple_private.h" |
14 | | |
15 | | |
16 | | static size_t |
17 | | sparc_code(void *simple lzma_attribute((__unused__)), |
18 | | uint32_t now_pos, bool is_encoder, |
19 | | uint8_t *buffer, size_t size) |
20 | 172 | { |
21 | 172 | size_t i; |
22 | 528 | for (i = 0; i + 4 <= size; i += 4) { |
23 | | |
24 | 356 | if ((buffer[i] == 0x40 && (buffer[i + 1] & 0xC0) == 0x00) |
25 | 346 | || (buffer[i] == 0x7F |
26 | 12 | && (buffer[i + 1] & 0xC0) == 0xC0)) { |
27 | | |
28 | 12 | uint32_t src = ((uint32_t)buffer[i + 0] << 24) |
29 | 12 | | ((uint32_t)buffer[i + 1] << 16) |
30 | 12 | | ((uint32_t)buffer[i + 2] << 8) |
31 | 12 | | ((uint32_t)buffer[i + 3]); |
32 | | |
33 | 12 | src <<= 2; |
34 | | |
35 | 12 | uint32_t dest; |
36 | 12 | if (is_encoder) |
37 | 0 | dest = now_pos + (uint32_t)(i) + src; |
38 | 12 | else |
39 | 12 | dest = src - (now_pos + (uint32_t)(i)); |
40 | | |
41 | 12 | dest >>= 2; |
42 | | |
43 | 12 | dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) |
44 | 12 | | (dest & 0x3FFFFF) |
45 | 12 | | 0x40000000; |
46 | | |
47 | 12 | buffer[i + 0] = (uint8_t)(dest >> 24); |
48 | 12 | buffer[i + 1] = (uint8_t)(dest >> 16); |
49 | 12 | buffer[i + 2] = (uint8_t)(dest >> 8); |
50 | 12 | buffer[i + 3] = (uint8_t)(dest); |
51 | 12 | } |
52 | 356 | } |
53 | | |
54 | 172 | return i; |
55 | 172 | } |
56 | | |
57 | | |
58 | | static lzma_ret |
59 | | sparc_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, |
60 | | const lzma_filter_info *filters, bool is_encoder) |
61 | 56 | { |
62 | 56 | return lzma_simple_coder_init(next, allocator, filters, |
63 | 56 | &sparc_code, 0, 4, 4, is_encoder); |
64 | 56 | } |
65 | | |
66 | | |
67 | | #ifdef HAVE_ENCODER_SPARC |
68 | | extern lzma_ret |
69 | | lzma_simple_sparc_encoder_init(lzma_next_coder *next, |
70 | | const lzma_allocator *allocator, |
71 | | const lzma_filter_info *filters) |
72 | 0 | { |
73 | 0 | return sparc_coder_init(next, allocator, filters, true); |
74 | 0 | } |
75 | | #endif |
76 | | |
77 | | |
78 | | #ifdef HAVE_DECODER_SPARC |
79 | | extern lzma_ret |
80 | | lzma_simple_sparc_decoder_init(lzma_next_coder *next, |
81 | | const lzma_allocator *allocator, |
82 | | const lzma_filter_info *filters) |
83 | 56 | { |
84 | | return sparc_coder_init(next, allocator, filters, false); |
85 | 56 | } |
86 | | #endif |