blob: 7eb5e4355d25c467fd1241ffda14715dfc69c1c7 [file] [log] [blame]
Thiemo Seufere30ec452008-01-28 20:05:38 +00001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * A small micro-assembler. It is intentionally kept simple, does only
7 * support a subset of instructions, and does not try to hide pipeline
8 * effects like branch delay slots.
9 *
Ralf Baechle70342282013-01-22 12:59:30 +010010 * Copyright (C) 2004, 2005, 2006, 2008 Thiemo Seufer
Thiemo Seufere30ec452008-01-28 20:05:38 +000011 * Copyright (C) 2005, 2007 Maciej W. Rozycki
12 * Copyright (C) 2006 Ralf Baechle (ralf@linux-mips.org)
Steven J. Hillabc597f2013-02-05 16:52:01 -060013 * Copyright (C) 2012, 2013 MIPS Technologies, Inc. All rights reserved.
Thiemo Seufere30ec452008-01-28 20:05:38 +000014 */
15
Thiemo Seufere30ec452008-01-28 20:05:38 +000016enum fields {
17 RS = 0x001,
18 RT = 0x002,
19 RD = 0x004,
20 RE = 0x008,
21 SIMM = 0x010,
22 UIMM = 0x020,
23 BIMM = 0x040,
24 JIMM = 0x080,
25 FUNC = 0x100,
David Daney58b9e222010-02-18 16:13:03 -080026 SET = 0x200,
27 SCIMM = 0x400
Thiemo Seufere30ec452008-01-28 20:05:38 +000028};
29
30#define OP_MASK 0x3f
31#define OP_SH 26
Thiemo Seufere30ec452008-01-28 20:05:38 +000032#define RD_MASK 0x1f
33#define RD_SH 11
34#define RE_MASK 0x1f
35#define RE_SH 6
36#define IMM_MASK 0xffff
37#define IMM_SH 0
38#define JIMM_MASK 0x3ffffff
39#define JIMM_SH 0
40#define FUNC_MASK 0x3f
41#define FUNC_SH 0
42#define SET_MASK 0x7
43#define SET_SH 0
44
45enum opcode {
46 insn_invalid,
Steven J. Hill71a1c772012-06-19 19:59:29 +010047 insn_addiu, insn_addu, insn_and, insn_andi, insn_bbit0, insn_bbit1,
48 insn_beq, insn_beql, insn_bgez, insn_bgezl, insn_bltz, insn_bltzl,
49 insn_bne, insn_cache, insn_daddiu, insn_daddu, insn_dins, insn_dinsm,
50 insn_dmfc0, insn_dmtc0, insn_drotr, insn_drotr32, insn_dsll,
51 insn_dsll32, insn_dsra, insn_dsrl, insn_dsrl32, insn_dsubu, insn_eret,
Steven J. Hille6de1a02012-07-12 17:21:31 +000052 insn_ext, insn_ins, insn_j, insn_jal, insn_jr, insn_ld, insn_ldx,
53 insn_ll, insn_lld, insn_lui, insn_lw, insn_lwx, insn_mfc0, insn_mtc0,
54 insn_or, insn_ori, insn_pref, insn_rfe, insn_rotr, insn_sc, insn_scd,
55 insn_sd, insn_sll, insn_sra, insn_srl, insn_subu, insn_sw,
56 insn_syscall, insn_tlbp, insn_tlbr, insn_tlbwi, insn_tlbwr, insn_xor,
57 insn_xori,
Thiemo Seufere30ec452008-01-28 20:05:38 +000058};
59
60struct insn {
61 enum opcode opcode;
62 u32 match;
63 enum fields fields;
64};
65
David Daney22b07632010-07-23 18:41:43 -070066static inline __uasminit u32 build_rs(u32 arg)
Thiemo Seufere30ec452008-01-28 20:05:38 +000067{
David Daney8d662c82010-12-27 18:18:29 -080068 WARN(arg & ~RS_MASK, KERN_WARNING "Micro-assembler field overflow\n");
Thiemo Seufere30ec452008-01-28 20:05:38 +000069
70 return (arg & RS_MASK) << RS_SH;
71}
72
David Daney22b07632010-07-23 18:41:43 -070073static inline __uasminit u32 build_rt(u32 arg)
Thiemo Seufere30ec452008-01-28 20:05:38 +000074{
David Daney8d662c82010-12-27 18:18:29 -080075 WARN(arg & ~RT_MASK, KERN_WARNING "Micro-assembler field overflow\n");
Thiemo Seufere30ec452008-01-28 20:05:38 +000076
77 return (arg & RT_MASK) << RT_SH;
78}
79
David Daney22b07632010-07-23 18:41:43 -070080static inline __uasminit u32 build_rd(u32 arg)
Thiemo Seufere30ec452008-01-28 20:05:38 +000081{
David Daney8d662c82010-12-27 18:18:29 -080082 WARN(arg & ~RD_MASK, KERN_WARNING "Micro-assembler field overflow\n");
Thiemo Seufere30ec452008-01-28 20:05:38 +000083
84 return (arg & RD_MASK) << RD_SH;
85}
86
David Daney22b07632010-07-23 18:41:43 -070087static inline __uasminit u32 build_re(u32 arg)
Thiemo Seufere30ec452008-01-28 20:05:38 +000088{
David Daney8d662c82010-12-27 18:18:29 -080089 WARN(arg & ~RE_MASK, KERN_WARNING "Micro-assembler field overflow\n");
Thiemo Seufere30ec452008-01-28 20:05:38 +000090
91 return (arg & RE_MASK) << RE_SH;
92}
93
David Daney22b07632010-07-23 18:41:43 -070094static inline __uasminit u32 build_simm(s32 arg)
Thiemo Seufere30ec452008-01-28 20:05:38 +000095{
David Daney8d662c82010-12-27 18:18:29 -080096 WARN(arg > 0x7fff || arg < -0x8000,
97 KERN_WARNING "Micro-assembler field overflow\n");
Thiemo Seufere30ec452008-01-28 20:05:38 +000098
99 return arg & 0xffff;
100}
101
David Daney22b07632010-07-23 18:41:43 -0700102static inline __uasminit u32 build_uimm(u32 arg)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000103{
David Daney8d662c82010-12-27 18:18:29 -0800104 WARN(arg & ~IMM_MASK, KERN_WARNING "Micro-assembler field overflow\n");
Thiemo Seufere30ec452008-01-28 20:05:38 +0000105
106 return arg & IMM_MASK;
107}
108
David Daney22b07632010-07-23 18:41:43 -0700109static inline __uasminit u32 build_scimm(u32 arg)
David Daney58b9e222010-02-18 16:13:03 -0800110{
David Daney8d662c82010-12-27 18:18:29 -0800111 WARN(arg & ~SCIMM_MASK,
112 KERN_WARNING "Micro-assembler field overflow\n");
David Daney58b9e222010-02-18 16:13:03 -0800113
114 return (arg & SCIMM_MASK) << SCIMM_SH;
115}
116
David Daney22b07632010-07-23 18:41:43 -0700117static inline __uasminit u32 build_func(u32 arg)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000118{
David Daney8d662c82010-12-27 18:18:29 -0800119 WARN(arg & ~FUNC_MASK, KERN_WARNING "Micro-assembler field overflow\n");
Thiemo Seufere30ec452008-01-28 20:05:38 +0000120
121 return arg & FUNC_MASK;
122}
123
David Daney22b07632010-07-23 18:41:43 -0700124static inline __uasminit u32 build_set(u32 arg)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000125{
David Daney8d662c82010-12-27 18:18:29 -0800126 WARN(arg & ~SET_MASK, KERN_WARNING "Micro-assembler field overflow\n");
Thiemo Seufere30ec452008-01-28 20:05:38 +0000127
128 return arg & SET_MASK;
129}
130
Steven J. Hillabc597f2013-02-05 16:52:01 -0600131static void __uasminit build_insn(u32 **buf, enum opcode opc, ...);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000132
133#define I_u1u2u3(op) \
134Ip_u1u2u3(op) \
135{ \
136 build_insn(buf, insn##op, a, b, c); \
David Daney22b07632010-07-23 18:41:43 -0700137} \
138UASM_EXPORT_SYMBOL(uasm_i##op);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000139
140#define I_u2u1u3(op) \
141Ip_u2u1u3(op) \
142{ \
143 build_insn(buf, insn##op, b, a, c); \
David Daney22b07632010-07-23 18:41:43 -0700144} \
145UASM_EXPORT_SYMBOL(uasm_i##op);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000146
147#define I_u3u1u2(op) \
148Ip_u3u1u2(op) \
149{ \
150 build_insn(buf, insn##op, b, c, a); \
David Daney22b07632010-07-23 18:41:43 -0700151} \
152UASM_EXPORT_SYMBOL(uasm_i##op);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000153
154#define I_u1u2s3(op) \
155Ip_u1u2s3(op) \
156{ \
157 build_insn(buf, insn##op, a, b, c); \
David Daney22b07632010-07-23 18:41:43 -0700158} \
159UASM_EXPORT_SYMBOL(uasm_i##op);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000160
161#define I_u2s3u1(op) \
162Ip_u2s3u1(op) \
163{ \
164 build_insn(buf, insn##op, c, a, b); \
David Daney22b07632010-07-23 18:41:43 -0700165} \
166UASM_EXPORT_SYMBOL(uasm_i##op);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000167
168#define I_u2u1s3(op) \
169Ip_u2u1s3(op) \
170{ \
171 build_insn(buf, insn##op, b, a, c); \
David Daney22b07632010-07-23 18:41:43 -0700172} \
173UASM_EXPORT_SYMBOL(uasm_i##op);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000174
David Daney92078e02009-10-14 12:16:55 -0700175#define I_u2u1msbu3(op) \
176Ip_u2u1msbu3(op) \
177{ \
178 build_insn(buf, insn##op, b, a, c+d-1, c); \
David Daney22b07632010-07-23 18:41:43 -0700179} \
180UASM_EXPORT_SYMBOL(uasm_i##op);
David Daney92078e02009-10-14 12:16:55 -0700181
David Daneyc42aef02010-12-21 14:19:10 -0800182#define I_u2u1msb32u3(op) \
183Ip_u2u1msbu3(op) \
184{ \
185 build_insn(buf, insn##op, b, a, c+d-33, c); \
186} \
187UASM_EXPORT_SYMBOL(uasm_i##op);
188
Ralf Baechle70342282013-01-22 12:59:30 +0100189#define I_u2u1msbdu3(op) \
Steven J. Hille6de1a02012-07-12 17:21:31 +0000190Ip_u2u1msbu3(op) \
191{ \
192 build_insn(buf, insn##op, b, a, d-1, c); \
193} \
194UASM_EXPORT_SYMBOL(uasm_i##op);
195
Thiemo Seufere30ec452008-01-28 20:05:38 +0000196#define I_u1u2(op) \
197Ip_u1u2(op) \
198{ \
199 build_insn(buf, insn##op, a, b); \
David Daney22b07632010-07-23 18:41:43 -0700200} \
201UASM_EXPORT_SYMBOL(uasm_i##op);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000202
203#define I_u1s2(op) \
204Ip_u1s2(op) \
205{ \
206 build_insn(buf, insn##op, a, b); \
David Daney22b07632010-07-23 18:41:43 -0700207} \
208UASM_EXPORT_SYMBOL(uasm_i##op);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000209
210#define I_u1(op) \
211Ip_u1(op) \
212{ \
213 build_insn(buf, insn##op, a); \
David Daney22b07632010-07-23 18:41:43 -0700214} \
215UASM_EXPORT_SYMBOL(uasm_i##op);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000216
217#define I_0(op) \
218Ip_0(op) \
219{ \
220 build_insn(buf, insn##op); \
David Daney22b07632010-07-23 18:41:43 -0700221} \
222UASM_EXPORT_SYMBOL(uasm_i##op);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000223
224I_u2u1s3(_addiu)
225I_u3u1u2(_addu)
226I_u2u1u3(_andi)
227I_u3u1u2(_and)
228I_u1u2s3(_beq)
229I_u1u2s3(_beql)
230I_u1s2(_bgez)
231I_u1s2(_bgezl)
232I_u1s2(_bltz)
233I_u1s2(_bltzl)
234I_u1u2s3(_bne)
Thiemo Seuferfb2a27e72008-02-18 19:32:49 +0000235I_u2s3u1(_cache)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000236I_u1u2u3(_dmfc0)
237I_u1u2u3(_dmtc0)
238I_u2u1s3(_daddiu)
239I_u3u1u2(_daddu)
240I_u2u1u3(_dsll)
241I_u2u1u3(_dsll32)
242I_u2u1u3(_dsra)
243I_u2u1u3(_dsrl)
244I_u2u1u3(_dsrl32)
David Daney92078e02009-10-14 12:16:55 -0700245I_u2u1u3(_drotr)
David Daneyde6d5b552010-07-23 18:41:41 -0700246I_u2u1u3(_drotr32)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000247I_u3u1u2(_dsubu)
248I_0(_eret)
Steven J. Hille6de1a02012-07-12 17:21:31 +0000249I_u2u1msbdu3(_ext)
250I_u2u1msbu3(_ins)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000251I_u1(_j)
252I_u1(_jal)
253I_u1(_jr)
254I_u2s3u1(_ld)
255I_u2s3u1(_ll)
256I_u2s3u1(_lld)
257I_u1s2(_lui)
258I_u2s3u1(_lw)
259I_u1u2u3(_mfc0)
260I_u1u2u3(_mtc0)
261I_u2u1u3(_ori)
Ralf Baechle58081842010-03-23 15:54:50 +0100262I_u3u1u2(_or)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000263I_0(_rfe)
264I_u2s3u1(_sc)
265I_u2s3u1(_scd)
266I_u2s3u1(_sd)
267I_u2u1u3(_sll)
268I_u2u1u3(_sra)
269I_u2u1u3(_srl)
David Daney32546f32010-02-10 15:12:46 -0800270I_u2u1u3(_rotr)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000271I_u3u1u2(_subu)
272I_u2s3u1(_sw)
273I_0(_tlbp)
David Daney32546f32010-02-10 15:12:46 -0800274I_0(_tlbr)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000275I_0(_tlbwi)
276I_0(_tlbwr)
277I_u3u1u2(_xor)
278I_u2u1u3(_xori)
David Daney92078e02009-10-14 12:16:55 -0700279I_u2u1msbu3(_dins);
David Daneyc42aef02010-12-21 14:19:10 -0800280I_u2u1msb32u3(_dinsm);
David Daney58b9e222010-02-18 16:13:03 -0800281I_u1(_syscall);
David Daney5b97c3f2010-07-23 18:41:42 -0700282I_u1u2s3(_bbit0);
283I_u1u2s3(_bbit1);
David Daneybb3d68c2010-12-27 18:07:56 -0800284I_u3u1u2(_lwx)
285I_u3u1u2(_ldx)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000286
David Daneyc9941152010-10-07 16:03:53 -0700287#ifdef CONFIG_CPU_CAVIUM_OCTEON
288#include <asm/octeon/octeon.h>
Steven J. Hillabc597f2013-02-05 16:52:01 -0600289void __uasminit ISAFUNC(uasm_i_pref)(u32 **buf, unsigned int a, signed int b,
David Daneyc9941152010-10-07 16:03:53 -0700290 unsigned int c)
291{
292 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X) && a <= 24 && a != 5)
293 /*
294 * As per erratum Core-14449, replace prefetches 0-4,
295 * 6-24 with 'pref 28'.
296 */
297 build_insn(buf, insn_pref, c, 28, b);
298 else
299 build_insn(buf, insn_pref, c, a, b);
300}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600301UASM_EXPORT_SYMBOL(ISAFUNC(uasm_i_pref));
David Daneyc9941152010-10-07 16:03:53 -0700302#else
303I_u2s3u1(_pref)
304#endif
305
Thiemo Seufere30ec452008-01-28 20:05:38 +0000306/* Handle labels. */
Steven J. Hillabc597f2013-02-05 16:52:01 -0600307void __uasminit ISAFUNC(uasm_build_label)(struct uasm_label **lab, u32 *addr, int lid)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000308{
309 (*lab)->addr = addr;
310 (*lab)->lab = lid;
311 (*lab)++;
312}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600313UASM_EXPORT_SYMBOL(ISAFUNC(uasm_build_label));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000314
Steven J. Hillabc597f2013-02-05 16:52:01 -0600315int __uasminit ISAFUNC(uasm_in_compat_space_p)(long addr)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000316{
317 /* Is this address in 32bit compat space? */
318#ifdef CONFIG_64BIT
319 return (((addr) & 0xffffffff00000000L) == 0xffffffff00000000L);
320#else
321 return 1;
322#endif
323}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600324UASM_EXPORT_SYMBOL(ISAFUNC(uasm_in_compat_space_p));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000325
David Daney22b07632010-07-23 18:41:43 -0700326static int __uasminit uasm_rel_highest(long val)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000327{
328#ifdef CONFIG_64BIT
329 return ((((val + 0x800080008000L) >> 48) & 0xffff) ^ 0x8000) - 0x8000;
330#else
331 return 0;
332#endif
333}
334
David Daney22b07632010-07-23 18:41:43 -0700335static int __uasminit uasm_rel_higher(long val)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000336{
337#ifdef CONFIG_64BIT
338 return ((((val + 0x80008000L) >> 32) & 0xffff) ^ 0x8000) - 0x8000;
339#else
340 return 0;
341#endif
342}
343
Steven J. Hillabc597f2013-02-05 16:52:01 -0600344int __uasminit ISAFUNC(uasm_rel_hi)(long val)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000345{
346 return ((((val + 0x8000L) >> 16) & 0xffff) ^ 0x8000) - 0x8000;
347}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600348UASM_EXPORT_SYMBOL(ISAFUNC(uasm_rel_hi));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000349
Steven J. Hillabc597f2013-02-05 16:52:01 -0600350int __uasminit ISAFUNC(uasm_rel_lo)(long val)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000351{
352 return ((val & 0xffff) ^ 0x8000) - 0x8000;
353}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600354UASM_EXPORT_SYMBOL(ISAFUNC(uasm_rel_lo));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000355
Steven J. Hillabc597f2013-02-05 16:52:01 -0600356void __uasminit ISAFUNC(UASM_i_LA_mostly)(u32 **buf, unsigned int rs, long addr)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000357{
Steven J. Hillabc597f2013-02-05 16:52:01 -0600358 if (!ISAFUNC(uasm_in_compat_space_p)(addr)) {
359 ISAFUNC(uasm_i_lui)(buf, rs, uasm_rel_highest(addr));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000360 if (uasm_rel_higher(addr))
Steven J. Hillabc597f2013-02-05 16:52:01 -0600361 ISAFUNC(uasm_i_daddiu)(buf, rs, rs, uasm_rel_higher(addr));
362 if (ISAFUNC(uasm_rel_hi(addr))) {
363 ISAFUNC(uasm_i_dsll)(buf, rs, rs, 16);
364 ISAFUNC(uasm_i_daddiu)(buf, rs, rs,
365 ISAFUNC(uasm_rel_hi)(addr));
366 ISAFUNC(uasm_i_dsll)(buf, rs, rs, 16);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000367 } else
Steven J. Hillabc597f2013-02-05 16:52:01 -0600368 ISAFUNC(uasm_i_dsll32)(buf, rs, rs, 0);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000369 } else
Steven J. Hillabc597f2013-02-05 16:52:01 -0600370 ISAFUNC(uasm_i_lui)(buf, rs, ISAFUNC(uasm_rel_hi(addr)));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000371}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600372UASM_EXPORT_SYMBOL(ISAFUNC(UASM_i_LA_mostly));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000373
Steven J. Hillabc597f2013-02-05 16:52:01 -0600374void __uasminit ISAFUNC(UASM_i_LA)(u32 **buf, unsigned int rs, long addr)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000375{
Steven J. Hillabc597f2013-02-05 16:52:01 -0600376 ISAFUNC(UASM_i_LA_mostly)(buf, rs, addr);
377 if (ISAFUNC(uasm_rel_lo(addr))) {
378 if (!ISAFUNC(uasm_in_compat_space_p)(addr))
379 ISAFUNC(uasm_i_daddiu)(buf, rs, rs,
380 ISAFUNC(uasm_rel_lo(addr)));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000381 else
Steven J. Hillabc597f2013-02-05 16:52:01 -0600382 ISAFUNC(uasm_i_addiu)(buf, rs, rs,
383 ISAFUNC(uasm_rel_lo(addr)));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000384 }
385}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600386UASM_EXPORT_SYMBOL(ISAFUNC(UASM_i_LA));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000387
388/* Handle relocations. */
David Daney22b07632010-07-23 18:41:43 -0700389void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600390ISAFUNC(uasm_r_mips_pc16)(struct uasm_reloc **rel, u32 *addr, int lid)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000391{
392 (*rel)->addr = addr;
393 (*rel)->type = R_MIPS_PC16;
394 (*rel)->lab = lid;
395 (*rel)++;
396}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600397UASM_EXPORT_SYMBOL(ISAFUNC(uasm_r_mips_pc16));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000398
David Daney22b07632010-07-23 18:41:43 -0700399static inline void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600400__resolve_relocs(struct uasm_reloc *rel, struct uasm_label *lab);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000401
David Daney22b07632010-07-23 18:41:43 -0700402void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600403ISAFUNC(uasm_resolve_relocs)(struct uasm_reloc *rel, struct uasm_label *lab)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000404{
405 struct uasm_label *l;
406
407 for (; rel->lab != UASM_LABEL_INVALID; rel++)
408 for (l = lab; l->lab != UASM_LABEL_INVALID; l++)
409 if (rel->lab == l->lab)
410 __resolve_relocs(rel, l);
411}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600412UASM_EXPORT_SYMBOL(ISAFUNC(uasm_resolve_relocs));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000413
David Daney22b07632010-07-23 18:41:43 -0700414void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600415ISAFUNC(uasm_move_relocs)(struct uasm_reloc *rel, u32 *first, u32 *end, long off)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000416{
417 for (; rel->lab != UASM_LABEL_INVALID; rel++)
418 if (rel->addr >= first && rel->addr < end)
419 rel->addr += off;
420}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600421UASM_EXPORT_SYMBOL(ISAFUNC(uasm_move_relocs));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000422
David Daney22b07632010-07-23 18:41:43 -0700423void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600424ISAFUNC(uasm_move_labels)(struct uasm_label *lab, u32 *first, u32 *end, long off)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000425{
426 for (; lab->lab != UASM_LABEL_INVALID; lab++)
427 if (lab->addr >= first && lab->addr < end)
428 lab->addr += off;
429}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600430UASM_EXPORT_SYMBOL(ISAFUNC(uasm_move_labels));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000431
David Daney22b07632010-07-23 18:41:43 -0700432void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600433ISAFUNC(uasm_copy_handler)(struct uasm_reloc *rel, struct uasm_label *lab, u32 *first,
Thiemo Seufere30ec452008-01-28 20:05:38 +0000434 u32 *end, u32 *target)
435{
436 long off = (long)(target - first);
437
438 memcpy(target, first, (end - first) * sizeof(u32));
439
Steven J. Hillabc597f2013-02-05 16:52:01 -0600440 ISAFUNC(uasm_move_relocs(rel, first, end, off));
441 ISAFUNC(uasm_move_labels(lab, first, end, off));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000442}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600443UASM_EXPORT_SYMBOL(ISAFUNC(uasm_copy_handler));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000444
Steven J. Hillabc597f2013-02-05 16:52:01 -0600445int __uasminit ISAFUNC(uasm_insn_has_bdelay)(struct uasm_reloc *rel, u32 *addr)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000446{
447 for (; rel->lab != UASM_LABEL_INVALID; rel++) {
448 if (rel->addr == addr
449 && (rel->type == R_MIPS_PC16
450 || rel->type == R_MIPS_26))
451 return 1;
452 }
453
454 return 0;
455}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600456UASM_EXPORT_SYMBOL(ISAFUNC(uasm_insn_has_bdelay));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000457
458/* Convenience functions for labeled branches. */
David Daney22b07632010-07-23 18:41:43 -0700459void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600460ISAFUNC(uasm_il_bltz)(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000461{
462 uasm_r_mips_pc16(r, *p, lid);
Steven J. Hillabc597f2013-02-05 16:52:01 -0600463 ISAFUNC(uasm_i_bltz)(p, reg, 0);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000464}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600465UASM_EXPORT_SYMBOL(ISAFUNC(uasm_il_bltz));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000466
David Daney22b07632010-07-23 18:41:43 -0700467void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600468ISAFUNC(uasm_il_b)(u32 **p, struct uasm_reloc **r, int lid)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000469{
470 uasm_r_mips_pc16(r, *p, lid);
Steven J. Hillabc597f2013-02-05 16:52:01 -0600471 ISAFUNC(uasm_i_b)(p, 0);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000472}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600473UASM_EXPORT_SYMBOL(ISAFUNC(uasm_il_b));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000474
David Daney22b07632010-07-23 18:41:43 -0700475void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600476ISAFUNC(uasm_il_beqz)(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000477{
478 uasm_r_mips_pc16(r, *p, lid);
Steven J. Hillabc597f2013-02-05 16:52:01 -0600479 ISAFUNC(uasm_i_beqz)(p, reg, 0);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000480}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600481UASM_EXPORT_SYMBOL(ISAFUNC(uasm_il_beqz));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000482
David Daney22b07632010-07-23 18:41:43 -0700483void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600484ISAFUNC(uasm_il_beqzl)(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000485{
486 uasm_r_mips_pc16(r, *p, lid);
Steven J. Hillabc597f2013-02-05 16:52:01 -0600487 ISAFUNC(uasm_i_beqzl)(p, reg, 0);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000488}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600489UASM_EXPORT_SYMBOL(ISAFUNC(uasm_il_beqzl));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000490
David Daney22b07632010-07-23 18:41:43 -0700491void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600492ISAFUNC(uasm_il_bne)(u32 **p, struct uasm_reloc **r, unsigned int reg1,
Thiemo Seuferfb2a27e72008-02-18 19:32:49 +0000493 unsigned int reg2, int lid)
494{
495 uasm_r_mips_pc16(r, *p, lid);
Steven J. Hillabc597f2013-02-05 16:52:01 -0600496 ISAFUNC(uasm_i_bne)(p, reg1, reg2, 0);
Thiemo Seuferfb2a27e72008-02-18 19:32:49 +0000497}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600498UASM_EXPORT_SYMBOL(ISAFUNC(uasm_il_bne));
Thiemo Seuferfb2a27e72008-02-18 19:32:49 +0000499
David Daney22b07632010-07-23 18:41:43 -0700500void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600501ISAFUNC(uasm_il_bnez)(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000502{
503 uasm_r_mips_pc16(r, *p, lid);
Steven J. Hillabc597f2013-02-05 16:52:01 -0600504 ISAFUNC(uasm_i_bnez)(p, reg, 0);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000505}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600506UASM_EXPORT_SYMBOL(ISAFUNC(uasm_il_bnez));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000507
David Daney22b07632010-07-23 18:41:43 -0700508void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600509ISAFUNC(uasm_il_bgezl)(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000510{
511 uasm_r_mips_pc16(r, *p, lid);
Steven J. Hillabc597f2013-02-05 16:52:01 -0600512 ISAFUNC(uasm_i_bgezl)(p, reg, 0);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000513}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600514UASM_EXPORT_SYMBOL(ISAFUNC(uasm_il_bgezl));
Thiemo Seufere30ec452008-01-28 20:05:38 +0000515
David Daney22b07632010-07-23 18:41:43 -0700516void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600517ISAFUNC(uasm_il_bgez)(u32 **p, struct uasm_reloc **r, unsigned int reg, int lid)
Thiemo Seufere30ec452008-01-28 20:05:38 +0000518{
519 uasm_r_mips_pc16(r, *p, lid);
Steven J. Hillabc597f2013-02-05 16:52:01 -0600520 ISAFUNC(uasm_i_bgez)(p, reg, 0);
Thiemo Seufere30ec452008-01-28 20:05:38 +0000521}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600522UASM_EXPORT_SYMBOL(ISAFUNC(uasm_il_bgez));
David Daney5b97c3f2010-07-23 18:41:42 -0700523
David Daney22b07632010-07-23 18:41:43 -0700524void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600525ISAFUNC(uasm_il_bbit0)(u32 **p, struct uasm_reloc **r, unsigned int reg,
David Daney5b97c3f2010-07-23 18:41:42 -0700526 unsigned int bit, int lid)
527{
528 uasm_r_mips_pc16(r, *p, lid);
Steven J. Hillabc597f2013-02-05 16:52:01 -0600529 ISAFUNC(uasm_i_bbit0)(p, reg, bit, 0);
David Daney5b97c3f2010-07-23 18:41:42 -0700530}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600531UASM_EXPORT_SYMBOL(ISAFUNC(uasm_il_bbit0));
David Daney5b97c3f2010-07-23 18:41:42 -0700532
David Daney22b07632010-07-23 18:41:43 -0700533void __uasminit
Steven J. Hillabc597f2013-02-05 16:52:01 -0600534ISAFUNC(uasm_il_bbit1)(u32 **p, struct uasm_reloc **r, unsigned int reg,
David Daney5b97c3f2010-07-23 18:41:42 -0700535 unsigned int bit, int lid)
536{
537 uasm_r_mips_pc16(r, *p, lid);
Steven J. Hillabc597f2013-02-05 16:52:01 -0600538 ISAFUNC(uasm_i_bbit1)(p, reg, bit, 0);
David Daney5b97c3f2010-07-23 18:41:42 -0700539}
Steven J. Hillabc597f2013-02-05 16:52:01 -0600540UASM_EXPORT_SYMBOL(ISAFUNC(uasm_il_bbit1));