1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Filter for IA64 (Itanium) binaries
6 // Copyright (C) 1999-2006 Igor Pavlov
7 // Copyright (C) 2007 Lasse Collin
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 ///////////////////////////////////////////////////////////////////////////////
21 #include "simple_private.h"
25 ia64_code(lzma_simple *simple lzma_attribute((unused)),
26 uint32_t now_pos, bool is_encoder,
27 uint8_t *buffer, size_t size)
29 static const uint32_t BRANCH_TABLE[32] = {
30 0, 0, 0, 0, 0, 0, 0, 0,
31 0, 0, 0, 0, 0, 0, 0, 0,
32 4, 4, 6, 6, 0, 0, 7, 7,
33 4, 4, 0, 0, 4, 4, 0, 0
37 for (i = 0; i + 16 <= size; i += 16) {
38 const uint32_t instr_template = buffer[i] & 0x1F;
39 const uint32_t mask = BRANCH_TABLE[instr_template];
42 for (size_t slot = 0; slot < 3; ++slot, bit_pos += 41) {
43 if (((mask >> slot) & 1) == 0)
46 const size_t byte_pos = (bit_pos >> 3);
47 const uint32_t bit_res = bit_pos & 0x7;
48 uint64_t instruction = 0;
50 for (size_t j = 0; j < 6; ++j)
51 instruction += (uint64_t)(
52 buffer[i + j + byte_pos])
55 uint64_t inst_norm = instruction >> bit_res;
57 if (((inst_norm >> 37) & 0xF) == 0x5
58 && ((inst_norm >> 9) & 0x7) == 0
59 /* && (inst_norm & 0x3F)== 0 */
61 uint32_t src = (uint32_t)(
62 (inst_norm >> 13) & 0xFFFFF);
63 src |= ((inst_norm >> 36) & 1) << 20;
69 dest = now_pos + (uint32_t)(i) + src;
71 dest = src - (now_pos + (uint32_t)(i));
75 inst_norm &= ~((uint64_t)(0x8FFFFF) << 13);
76 inst_norm |= (uint64_t)(dest & 0xFFFFF) << 13;
77 inst_norm |= (uint64_t)(dest & 0x100000)
80 instruction &= (1 << bit_res) - 1;
81 instruction |= (inst_norm << bit_res);
83 for (size_t j = 0; j < 6; j++)
84 buffer[i + j + byte_pos] = (uint8_t)(
96 ia64_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
97 const lzma_filter_info *filters, bool is_encoder)
99 return lzma_simple_coder_init(next, allocator, filters,
100 &ia64_code, 0, 16, is_encoder);
105 lzma_simple_ia64_encoder_init(lzma_next_coder *next,
106 lzma_allocator *allocator, const lzma_filter_info *filters)
108 return ia64_coder_init(next, allocator, filters, true);
113 lzma_simple_ia64_decoder_init(lzma_next_coder *next,
114 lzma_allocator *allocator, const lzma_filter_info *filters)
116 return ia64_coder_init(next, allocator, filters, false);