2 * arch/ubicom32/kernel/flat.c
3 * Ubicom32 architecture flat executable format support.
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
23 * Ubicom32 implementation derived from (with many thanks):
28 #include <linux/module.h>
29 #include <linux/types.h>
30 #include <linux/flat.h>
32 unsigned long ubicom32_flat_get_addr_from_rp(unsigned long *rp
,
35 unsigned long *persistent
)
37 u32_t relval_reloc_type
= relval
>> 27;
42 * relval holds the relocation that has to be adjusted.
51 if (relval_reloc_type
== R_UBICOM32_32
) {
53 * insn holds the relocation
59 * We don't know this one.
64 void ubicom32_flat_put_addr_at_rp(unsigned long *rp
,
67 unsigned long *persistent
)
69 u32_t reloc_type
= (relval
>> 27) & 0x1f;
73 * If persistent is set then it contains the relocation type.
77 * If persistent is set then it contains the relocation type.
79 reloc_type
= (*persistent
>> 27) & 0x1f;
85 * Store the 32 bits as is.
92 * 24 bit relocation that is part of the MOVEAI
93 * instruction. The 24 bits come from bits 7 - 30 of the
94 * relocation. The 24 bits eventually get split into 2
95 * fields in the instruction encoding.
97 * - Bits 7 - 27 of the relocation are encoded into bits
98 * 0 - 20 of the instruction.
100 * - Bits 28 - 30 of the relocation are encoded into bit
101 * 24 - 26 of the instruction.
103 u32_t mask
= 0x1fffff | (0x7 << 24);
104 u32_t valid24bits
= (val
>> 7) & 0xffffff;
105 u32_t bot_21
= valid24bits
& 0x1fffff;
106 u32_t upper_3_bits
= ((valid24bits
& 0xe00000) << 3);
110 insn
|= upper_3_bits
;
114 case R_UBICOM32_LO7_S
:
115 case R_UBICOM32_LO7_2_S
:
116 case R_UBICOM32_LO7_4_S
:
119 * Bits 0 - 6 of the relocation are encoded into the
120 * 7bit unsigned immediate fields of the SOURCE-1 field
121 * of the instruction. The immediate value is left
122 * shifted by (0, 1, 2) based on the operand size.
124 u32_t mask
= 0x1f | (0x3 << 8);
127 if (reloc_type
== R_UBICOM32_LO7_2_S
) {
129 } else if (reloc_type
== R_UBICOM32_LO7_4_S
) {
142 case R_UBICOM32_LO7_D
:
143 case R_UBICOM32_LO7_2_D
:
144 case R_UBICOM32_LO7_4_D
:
147 * Bits 0 - 6 of the relocation are encoded into the
148 * 7bit unsigned immediate fields of the DESTINATION
149 * field of the instruction. The immediate value is
150 * left shifted by (0, 1, 2) based on the operand size.
152 u32_t mask
= (0x1f | (0x3 << 8)) << 16;
155 if (reloc_type
== R_UBICOM32_LO7_2_D
) {
157 } else if (reloc_type
== R_UBICOM32_LO7_4_D
) {
160 bottom
= (val
& 0x1f) << 16;
161 top
= (val
>> 5) << 16;
169 case R_UBICOM32_LO7_CALLI
:
170 case R_UBICOM32_LO16_CALLI
:
173 * Extract the offset for a CALLI instruction. The
174 * offsets can be either 7 bits or 18 bits. Since all
175 * instructions in ubicom32 architecture are at work
176 * aligned addresses the truncated offset is right
177 * shifted by 2 before being encoded in the instruction.
179 if (reloc_type
== R_UBICOM32_LO7_CALLI
) {
188 insn
|= (val
& 0x1f) << 0;
190 insn
|= (val
& 0x07) << 8;
192 insn
|= (val
& 0x1f) << 16;
194 insn
|= (val
& 0x07) << 24;
195 if (reloc_type
== R_UBICOM32_LO7_CALLI
) {