Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-mcore.c -- Assemble code for M*Core |
5d6255fe | 2 | Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
252b5132 RH |
3 | |
4 | This file is part of GAS, the GNU Assembler. | |
5 | ||
6 | GAS is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GAS is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
d7f1f2b0 ILT |
17 | along with GAS; see the file COPYING. If not, write to the Free |
18 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
19 | 02111-1307, USA. */ | |
252b5132 RH |
20 | |
21 | #include <stdio.h> | |
22 | #include "as.h" | |
23 | #include "bfd.h" | |
24 | #include "subsegs.h" | |
25 | #define DEFINE_TABLE | |
26 | #include "../opcodes/mcore-opc.h" | |
3882b010 | 27 | #include "safe-ctype.h" |
252b5132 RH |
28 | #include <string.h> |
29 | ||
30 | #ifdef OBJ_ELF | |
31 | #include "elf/mcore.h" | |
32 | #endif | |
33 | ||
34 | #ifndef streq | |
35 | #define streq(a,b) (strcmp (a, b) == 0) | |
36 | #endif | |
37 | ||
38 | /* Forward declarations for dumb compilers. */ | |
39 | static void mcore_s_literals PARAMS ((int)); | |
40 | static void mcore_cons PARAMS ((int)); | |
41 | static void mcore_float_cons PARAMS ((int)); | |
42 | static void mcore_stringer PARAMS ((int)); | |
bcef92fa | 43 | static void mcore_fill PARAMS ((int)); |
252b5132 | 44 | static int log2 PARAMS ((unsigned int)); |
9cac79d3 NC |
45 | static char * parse_reg PARAMS ((char *, unsigned *)); |
46 | static char * parse_creg PARAMS ((char *, unsigned *)); | |
47 | static char * parse_exp PARAMS ((char *, expressionS *)); | |
48 | static char * parse_rt PARAMS ((char *, char **, int, expressionS *)); | |
49 | static char * parse_imm PARAMS ((char *, unsigned *, unsigned, unsigned)); | |
50 | static char * parse_mem PARAMS ((char *, unsigned *, unsigned *, unsigned)); | |
bec50466 | 51 | static char * parse_psrmod PARAMS ((char *, unsigned *)); |
252b5132 RH |
52 | static void make_name PARAMS ((char *, char *, int)); |
53 | static int enter_literal PARAMS ((expressionS *, int)); | |
252b5132 RH |
54 | static void dump_literals PARAMS ((int)); |
55 | static void check_literals PARAMS ((int, int)); | |
56 | static void mcore_s_text PARAMS ((int)); | |
57 | static void mcore_s_data PARAMS ((int)); | |
252b5132 | 58 | static void mcore_s_section PARAMS ((int)); |
16b93d88 NC |
59 | static void mcore_s_bss PARAMS ((int)); |
60 | #ifdef OBJ_ELF | |
61 | static void mcore_s_comm PARAMS ((int)); | |
252b5132 RH |
62 | #endif |
63 | ||
64 | /* Several places in this file insert raw instructions into the | |
65 | object. They should use MCORE_INST_XXX macros to get the opcodes | |
66 | and then use these two macros to crack the MCORE_INST value into | |
67 | the appropriate byte values. */ | |
bec50466 NC |
68 | #define INST_BYTE0(x) (target_big_endian ? (((x) >> 8) & 0xFF) : ((x) & 0xFF)) |
69 | #define INST_BYTE1(x) (target_big_endian ? ((x) & 0xFF) : (((x) >> 8) & 0xFF)) | |
252b5132 RH |
70 | |
71 | const char comment_chars[] = "#/"; | |
72 | const char line_separator_chars[] = ";"; | |
73 | const char line_comment_chars[] = "#/"; | |
74 | ||
75 | const int md_reloc_size = 8; | |
76 | ||
eaa15ab8 | 77 | static int do_jsri2bsr = 0; /* Change here from 1 by Cruess 19 August 97. */ |
252b5132 RH |
78 | static int sifilter_mode = 0; |
79 | ||
80 | const char EXP_CHARS[] = "eE"; | |
81 | ||
eaa15ab8 NC |
82 | /* Chars that mean this number is a floating point constant |
83 | As in 0f12.456 | |
84 | or 0d1.2345e12 */ | |
252b5132 RH |
85 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; |
86 | ||
87 | #define C(what,length) (((what) << 2) + (length)) | |
88 | #define GET_WHAT(x) ((x >> 2)) | |
89 | ||
90 | /* These are the two types of relaxable instruction */ | |
91 | #define COND_JUMP 1 | |
92 | #define UNCD_JUMP 2 | |
93 | ||
94 | #define UNDEF_DISP 0 | |
93c2a809 AM |
95 | #define DISP12 1 |
96 | #define DISP32 2 | |
97 | #define UNDEF_WORD_DISP 3 | |
252b5132 RH |
98 | |
99 | #define C12_LEN 2 | |
100 | #define C32_LEN 10 /* allow for align */ | |
101 | #define U12_LEN 2 | |
102 | #define U32_LEN 8 /* allow for align */ | |
103 | ||
bec50466 NC |
104 | typedef enum |
105 | { | |
106 | M210, | |
107 | M340 | |
108 | } | |
109 | cpu_type; | |
110 | ||
111 | cpu_type cpu = M340; | |
252b5132 | 112 | |
eaa15ab8 | 113 | /* Initialize the relax table. */ |
e66457fb AM |
114 | const relax_typeS md_relax_table[] = { |
115 | { 0, 0, 0, 0 }, | |
116 | { 0, 0, 0, 0 }, | |
117 | { 0, 0, 0, 0 }, | |
118 | { 0, 0, 0, 0 }, | |
119 | ||
120 | /* COND_JUMP */ | |
121 | { 0, 0, 0, 0 }, /* UNDEF_DISP */ | |
122 | { 2048, -2046, C12_LEN, C(COND_JUMP, DISP32) }, /* DISP12 */ | |
123 | { 0, 0, C32_LEN, 0 }, /* DISP32 */ | |
124 | { 0, 0, C32_LEN, 0 }, /* UNDEF_WORD_DISP */ | |
125 | ||
126 | /* UNCD_JUMP */ | |
5d6255fe KH |
127 | { 0, 0, 0, 0 }, /* UNDEF_DISP */ |
128 | { 2048, -2046, U12_LEN, C(UNCD_JUMP, DISP32) }, /* DISP12 */ | |
129 | { 0, 0, U32_LEN, 0 }, /* DISP32 */ | |
e66457fb AM |
130 | { 0, 0, U32_LEN, 0 } /* UNDEF_WORD_DISP */ |
131 | ||
252b5132 RH |
132 | }; |
133 | ||
eaa15ab8 | 134 | /* Literal pool data structures. */ |
252b5132 RH |
135 | struct literal |
136 | { | |
137 | unsigned short refcnt; | |
138 | unsigned char ispcrel; | |
139 | unsigned char unused; | |
140 | expressionS e; | |
141 | }; | |
142 | ||
143 | #define MAX_POOL_SIZE (1024/4) | |
144 | static struct literal litpool [MAX_POOL_SIZE]; | |
145 | static unsigned poolsize; | |
146 | static unsigned poolnumber; | |
147 | static unsigned long poolspan; | |
148 | ||
149 | /* SPANPANIC: the point at which we get too scared and force a dump | |
150 | of the literal pool, and perhaps put a branch in place. | |
151 | Calculated as: | |
152 | 1024 span of lrw/jmpi/jsri insn (actually span+1) | |
153 | -2 possible alignment at the insn. | |
154 | -2 possible alignment to get the table aligned. | |
155 | -2 an inserted branch around the table. | |
156 | == 1018 | |
157 | at 1018, we might be in trouble. | |
158 | -- so we have to be smaller than 1018 and since we deal with 2-byte | |
159 | instructions, the next good choice is 1016. | |
160 | -- Note we have a test case that fails when we've got 1018 here. */ | |
eaa15ab8 | 161 | #define SPANPANIC (1016) /* 1024 - 1 entry - 2 byte rounding. */ |
252b5132 RH |
162 | #define SPANCLOSE (900) |
163 | #define SPANEXIT (600) | |
eaa15ab8 | 164 | static symbolS * poolsym; /* label for current pool. */ |
252b5132 | 165 | static char poolname[8]; |
eaa15ab8 | 166 | static struct hash_control * opcode_hash_control; /* Opcode mnemonics. */ |
252b5132 RH |
167 | |
168 | /* This table describes all the machine specific pseudo-ops the assembler | |
169 | has to support. The fields are: | |
170 | Pseudo-op name without dot | |
171 | Function to call to execute this pseudo-op | |
eaa15ab8 | 172 | Integer arg to pass to the function. */ |
252b5132 RH |
173 | const pseudo_typeS md_pseudo_table[] = |
174 | { | |
175 | { "export", s_globl, 0 }, | |
176 | { "import", s_ignore, 0 }, | |
177 | { "literals", mcore_s_literals, 0 }, | |
178 | { "page", listing_eject, 0 }, | |
252b5132 RH |
179 | |
180 | /* The following are to intercept the placement of data into the text | |
181 | section (eg addresses for a switch table), so that the space they | |
182 | occupy can be taken into account when deciding whether or not to | |
183 | dump the current literal pool. | |
184 | XXX - currently we do not cope with the .space and .dcb.d directives. */ | |
185 | { "ascii", mcore_stringer, 0 }, | |
186 | { "asciz", mcore_stringer, 1 }, | |
187 | { "byte", mcore_cons, 1 }, | |
188 | { "dc", mcore_cons, 2 }, | |
189 | { "dc.b", mcore_cons, 1 }, | |
bcef92fa | 190 | { "dc.d", mcore_float_cons, 'd'}, |
252b5132 | 191 | { "dc.l", mcore_cons, 4 }, |
bcef92fa | 192 | { "dc.s", mcore_float_cons, 'f'}, |
252b5132 | 193 | { "dc.w", mcore_cons, 2 }, |
bcef92fa | 194 | { "dc.x", mcore_float_cons, 'x'}, |
252b5132 RH |
195 | { "double", mcore_float_cons, 'd'}, |
196 | { "float", mcore_float_cons, 'f'}, | |
197 | { "hword", mcore_cons, 2 }, | |
198 | { "int", mcore_cons, 4 }, | |
199 | { "long", mcore_cons, 4 }, | |
200 | { "octa", mcore_cons, 16 }, | |
201 | { "quad", mcore_cons, 8 }, | |
202 | { "short", mcore_cons, 2 }, | |
203 | { "single", mcore_float_cons, 'f'}, | |
204 | { "string", mcore_stringer, 1 }, | |
205 | { "word", mcore_cons, 2 }, | |
bcef92fa | 206 | { "fill", mcore_fill, 0 }, |
252b5132 RH |
207 | |
208 | /* Allow for the effect of section changes. */ | |
209 | { "text", mcore_s_text, 0 }, | |
210 | { "data", mcore_s_data, 0 }, | |
16b93d88 NC |
211 | { "bss", mcore_s_bss, 1 }, |
212 | #ifdef OBJ_EF | |
213 | { "comm", mcore_s_comm, 0 }, | |
214 | #endif | |
252b5132 RH |
215 | { "section", mcore_s_section, 0 }, |
216 | { "section.s", mcore_s_section, 0 }, | |
217 | { "sect", mcore_s_section, 0 }, | |
218 | { "sect.s", mcore_s_section, 0 }, | |
a75214e5 | 219 | |
252b5132 RH |
220 | { 0, 0, 0 } |
221 | }; | |
222 | ||
223 | static void | |
224 | mcore_s_literals (ignore) | |
225 | int ignore; | |
226 | { | |
227 | dump_literals (0); | |
228 | demand_empty_rest_of_line (); | |
229 | } | |
230 | ||
252b5132 RH |
231 | static void |
232 | mcore_cons (nbytes) | |
233 | int nbytes; | |
234 | { | |
235 | if (now_seg == text_section) | |
236 | { | |
237 | char * ptr = input_line_pointer; | |
238 | int commas = 1; | |
a75214e5 | 239 | |
252b5132 | 240 | /* Count the number of commas on the line. */ |
b75c0c92 | 241 | while (! is_end_of_line [(unsigned char) * ptr]) |
252b5132 | 242 | commas += * ptr ++ == ','; |
a75214e5 | 243 | |
252b5132 RH |
244 | poolspan += nbytes * commas; |
245 | } | |
a75214e5 | 246 | |
252b5132 RH |
247 | cons (nbytes); |
248 | ||
249 | /* In theory we ought to call check_literals (2,0) here in case | |
250 | we need to dump the literal table. We cannot do this however, | |
251 | as the directives that we are intercepting may be being used | |
252 | to build a switch table, and we must not interfere with its | |
a75214e5 | 253 | contents. Instead we cross our fingers and pray... */ |
252b5132 RH |
254 | } |
255 | ||
256 | static void | |
257 | mcore_float_cons (float_type) | |
258 | int float_type; | |
259 | { | |
260 | if (now_seg == text_section) | |
261 | { | |
262 | char * ptr = input_line_pointer; | |
263 | int commas = 1; | |
264 | ||
265 | #ifdef REPEAT_CONS_EXPRESSIONS | |
266 | #error REPEAT_CONS_EXPRESSIONS not handled | |
267 | #endif | |
a75214e5 | 268 | |
252b5132 | 269 | /* Count the number of commas on the line. */ |
b75c0c92 | 270 | while (! is_end_of_line [(unsigned char) * ptr]) |
252b5132 RH |
271 | commas += * ptr ++ == ','; |
272 | ||
273 | /* We would like to compute "hex_float (float_type) * commas" | |
274 | but hex_float is not exported from read.c */ | |
275 | float_type == 'f' ? 4 : (float_type == 'd' ? 8 : 12); | |
276 | poolspan += float_type * commas; | |
277 | } | |
278 | ||
279 | float_cons (float_type); | |
a75214e5 | 280 | |
252b5132 RH |
281 | /* See the comment in mcore_cons () about calling check_literals. |
282 | It is unlikely that a switch table will be constructed using | |
283 | floating point values, but it is still likely that an indexed | |
284 | table of floating point constants is being created by these | |
285 | directives, so again we must not interfere with their placement. */ | |
286 | } | |
287 | ||
288 | static void | |
289 | mcore_stringer (append_zero) | |
290 | int append_zero; | |
291 | { | |
292 | if (now_seg == text_section) | |
293 | { | |
294 | char * ptr = input_line_pointer; | |
a75214e5 | 295 | |
252b5132 RH |
296 | /* In theory we should compute how many bytes are going to |
297 | be occupied by the string(s) and add this to the poolspan. | |
298 | To keep things simple however, we just add the number of | |
299 | bytes left on the current line. This will be an over- | |
300 | estimate, which is OK, and automatically allows for the | |
301 | appending a zero byte, since the real string(s) is/are | |
302 | required to be enclosed in double quotes. */ | |
b75c0c92 | 303 | while (! is_end_of_line [(unsigned char) * ptr]) |
252b5132 RH |
304 | ptr ++; |
305 | ||
306 | poolspan += ptr - input_line_pointer; | |
307 | } | |
a75214e5 | 308 | |
252b5132 RH |
309 | stringer (append_zero); |
310 | ||
311 | /* We call check_literals here in case a large number of strings are | |
312 | being placed into the text section with a sequence of stringer | |
313 | directives. In theory we could be upsetting something if these | |
314 | strings are actually in an indexed table instead of referenced by | |
315 | individual labels. Let us hope that that never happens. */ | |
316 | check_literals (2, 0); | |
317 | } | |
318 | ||
bcef92fa NC |
319 | static void |
320 | mcore_fill (unused) | |
321 | int unused; | |
322 | { | |
323 | if (now_seg == text_section) | |
324 | { | |
325 | char * str = input_line_pointer; | |
326 | int size = 1; | |
327 | int repeat; | |
328 | ||
329 | repeat = atoi (str); | |
a75214e5 | 330 | |
bcef92fa NC |
331 | /* Look to see if a size has been specified. */ |
332 | while (*str != '\n' && *str != 0 && *str != ',') | |
333 | ++ str; | |
a75214e5 | 334 | |
bcef92fa NC |
335 | if (* str == ',') |
336 | { | |
337 | size = atoi (str + 1); | |
338 | ||
339 | if (size > 8) | |
340 | size = 8; | |
341 | else if (size < 0) | |
342 | size = 0; | |
343 | } | |
344 | ||
345 | poolspan += size * repeat; | |
346 | } | |
a75214e5 | 347 | |
bcef92fa NC |
348 | s_fill (unused); |
349 | ||
4c1102fd | 350 | check_literals (2, 0); |
bcef92fa NC |
351 | } |
352 | ||
16b93d88 NC |
353 | /* Handle the section changing pseudo-ops. These call through to the |
354 | normal implementations, but they dump the literal pool first. */ | |
252b5132 RH |
355 | static void |
356 | mcore_s_text (ignore) | |
357 | int ignore; | |
358 | { | |
359 | dump_literals (0); | |
a75214e5 | 360 | |
16b93d88 NC |
361 | #ifdef OBJ_ELF |
362 | obj_elf_text (ignore); | |
363 | #else | |
252b5132 | 364 | s_text (ignore); |
16b93d88 | 365 | #endif |
252b5132 RH |
366 | } |
367 | ||
368 | static void | |
369 | mcore_s_data (ignore) | |
370 | int ignore; | |
371 | { | |
372 | dump_literals (0); | |
a75214e5 | 373 | |
16b93d88 NC |
374 | #ifdef OBJ_ELF |
375 | obj_elf_data (ignore); | |
376 | #else | |
252b5132 | 377 | s_data (ignore); |
16b93d88 NC |
378 | #endif |
379 | } | |
380 | ||
381 | static void | |
382 | mcore_s_section (ignore) | |
383 | int ignore; | |
384 | { | |
bcef92fa NC |
385 | /* Scan forwards to find the name of the section. If the section |
386 | being switched to is ".line" then this is a DWARF1 debug section | |
387 | which is arbitarily placed inside generated code. In this case | |
388 | do not dump the literal pool because it is a) inefficient and | |
389 | b) would require the generation of extra code to jump around the | |
390 | pool. */ | |
391 | char * ilp = input_line_pointer; | |
392 | ||
3882b010 | 393 | while (*ilp != 0 && ISSPACE (*ilp)) |
bcef92fa NC |
394 | ++ ilp; |
395 | ||
396 | if (strncmp (ilp, ".line", 5) == 0 | |
3882b010 | 397 | && (ISSPACE (ilp[5]) || *ilp == '\n' || *ilp == '\r')) |
bcef92fa NC |
398 | ; |
399 | else | |
400 | dump_literals (0); | |
16b93d88 NC |
401 | |
402 | #ifdef OBJ_ELF | |
403 | obj_elf_section (ignore); | |
404 | #endif | |
405 | #ifdef OBJ_COFF | |
406 | obj_coff_section (ignore); | |
407 | #endif | |
252b5132 RH |
408 | } |
409 | ||
16b93d88 NC |
410 | static void |
411 | mcore_s_bss (needs_align) | |
412 | int needs_align; | |
413 | { | |
414 | dump_literals (0); | |
a75214e5 | 415 | |
16b93d88 NC |
416 | s_lcomm_bytes (needs_align); |
417 | } | |
418 | ||
419 | #ifdef OBJ_ELF | |
420 | static void | |
421 | mcore_s_comm (needs_align) | |
422 | int needs_align; | |
423 | { | |
424 | dump_literals (0); | |
a75214e5 | 425 | |
16b93d88 NC |
426 | obj_elf_common (needs_align); |
427 | } | |
428 | #endif | |
429 | ||
252b5132 | 430 | /* This function is called once, at assembler startup time. This should |
bcef92fa | 431 | set up all the tables, etc that the MD part of the assembler needs. */ |
252b5132 RH |
432 | void |
433 | md_begin () | |
434 | { | |
435 | mcore_opcode_info * opcode; | |
436 | char * prev_name = ""; | |
437 | ||
438 | opcode_hash_control = hash_new (); | |
439 | ||
440 | /* Insert unique names into hash table */ | |
441 | for (opcode = mcore_table; opcode->name; opcode ++) | |
442 | { | |
443 | if (streq (prev_name, opcode->name)) | |
444 | { | |
445 | /* Make all the opcodes with the same name point to the same | |
446 | string. */ | |
447 | opcode->name = prev_name; | |
448 | } | |
449 | else | |
450 | { | |
451 | prev_name = opcode->name; | |
452 | hash_insert (opcode_hash_control, opcode->name, (char *) opcode); | |
453 | } | |
454 | } | |
455 | } | |
456 | ||
457 | static int reg_m; | |
458 | static int reg_n; | |
459 | static expressionS immediate; /* absolute expression */ | |
460 | ||
461 | /* Get a log2(val). */ | |
462 | static int | |
463 | log2 (val) | |
464 | unsigned int val; | |
465 | { | |
466 | int log = -1; | |
467 | while (val != 0) | |
468 | { | |
469 | log ++; | |
470 | val >>= 1; | |
471 | } | |
a75214e5 | 472 | |
252b5132 RH |
473 | return log; |
474 | } | |
475 | ||
476 | /* Try to parse a reg name. */ | |
477 | static char * | |
478 | parse_reg (s, reg) | |
479 | char * s; | |
480 | unsigned * reg; | |
481 | { | |
482 | /* Strip leading whitespace. */ | |
3882b010 | 483 | while (ISSPACE (* s)) |
252b5132 | 484 | ++ s; |
a75214e5 | 485 | |
3882b010 | 486 | if (TOLOWER (s[0]) == 'r') |
252b5132 RH |
487 | { |
488 | if (s[1] == '1' && s[2] >= '0' && s[2] <= '5') | |
489 | { | |
490 | *reg = 10 + s[2] - '0'; | |
491 | return s + 3; | |
492 | } | |
a75214e5 | 493 | |
252b5132 RH |
494 | if (s[1] >= '0' && s[1] <= '9') |
495 | { | |
496 | *reg = s[1] - '0'; | |
497 | return s + 2; | |
498 | } | |
499 | } | |
3882b010 L |
500 | else if ( TOLOWER (s[0]) == 's' |
501 | && TOLOWER (s[1]) == 'p' | |
502 | && ! ISALNUM (s[2])) | |
252b5132 RH |
503 | { |
504 | * reg = 0; | |
505 | return s + 2; | |
506 | } | |
a75214e5 | 507 | |
252b5132 RH |
508 | as_bad (_("register expected, but saw '%.6s'"), s); |
509 | return s; | |
510 | } | |
511 | ||
512 | static struct Cregs | |
513 | { | |
514 | char * name; | |
515 | unsigned int crnum; | |
516 | } | |
517 | cregs[] = | |
518 | { | |
519 | { "psr", 0}, | |
520 | { "vbr", 1}, | |
521 | { "epsr", 2}, | |
522 | { "fpsr", 3}, | |
523 | { "epc", 4}, | |
524 | { "fpc", 5}, | |
525 | { "ss0", 6}, | |
526 | { "ss1", 7}, | |
527 | { "ss2", 8}, | |
528 | { "ss3", 9}, | |
529 | { "ss4", 10}, | |
530 | { "gcr", 11}, | |
531 | { "gsr", 12}, | |
532 | { "", 0} | |
533 | }; | |
534 | ||
535 | static char * | |
536 | parse_creg (s, reg) | |
537 | char * s; | |
538 | unsigned * reg; | |
539 | { | |
540 | int i; | |
541 | ||
542 | /* Strip leading whitespace. */ | |
3882b010 | 543 | while (ISSPACE (* s)) |
252b5132 | 544 | ++s; |
a75214e5 | 545 | |
3882b010 | 546 | if ((TOLOWER (s[0]) == 'c' && TOLOWER (s[1]) == 'r')) |
252b5132 RH |
547 | { |
548 | if (s[2] == '3' && s[3] >= '0' && s[3] <= '1') | |
549 | { | |
550 | *reg = 30 + s[3] - '0'; | |
551 | return s + 4; | |
552 | } | |
a75214e5 | 553 | |
252b5132 RH |
554 | if (s[2] == '2' && s[3] >= '0' && s[3] <= '9') |
555 | { | |
556 | *reg = 20 + s[3] - '0'; | |
557 | return s + 4; | |
558 | } | |
a75214e5 | 559 | |
252b5132 RH |
560 | if (s[2] == '1' && s[3] >= '0' && s[3] <= '9') |
561 | { | |
562 | *reg = 10 + s[3] - '0'; | |
563 | return s + 4; | |
564 | } | |
a75214e5 | 565 | |
252b5132 RH |
566 | if (s[2] >= '0' && s[2] <= '9') |
567 | { | |
568 | *reg = s[2] - '0'; | |
569 | return s + 3; | |
570 | } | |
571 | } | |
a75214e5 | 572 | |
252b5132 RH |
573 | /* Look at alternate creg names before giving error. */ |
574 | for (i = 0; cregs[i].name[0] != '\0'; i++) | |
575 | { | |
576 | char buf [10]; | |
577 | int length; | |
578 | int j; | |
a75214e5 | 579 | |
252b5132 | 580 | length = strlen (cregs[i].name); |
a75214e5 | 581 | |
252b5132 | 582 | for (j = 0; j < length; j++) |
3882b010 | 583 | buf[j] = TOLOWER (s[j]); |
a75214e5 | 584 | |
252b5132 RH |
585 | if (strncmp (cregs[i].name, buf, length) == 0) |
586 | { | |
587 | *reg = cregs[i].crnum; | |
588 | return s + length; | |
589 | } | |
590 | } | |
a75214e5 | 591 | |
252b5132 | 592 | as_bad (_("control register expected, but saw '%.6s'"), s); |
a75214e5 | 593 | |
252b5132 RH |
594 | return s; |
595 | } | |
596 | ||
bec50466 NC |
597 | static char * |
598 | parse_psrmod (s, reg) | |
599 | char * s; | |
600 | unsigned * reg; | |
601 | { | |
602 | int i; | |
603 | char buf[10]; | |
604 | static struct psrmods | |
605 | { | |
606 | char * name; | |
607 | unsigned int value; | |
608 | } | |
609 | psrmods[] = | |
610 | { | |
611 | { "ie", 1 }, | |
612 | { "fe", 2 }, | |
613 | { "ee", 4 }, | |
614 | { "af", 8 } /* Really 0 and non-combinable. */ | |
615 | }; | |
a75214e5 | 616 | |
bec50466 | 617 | for (i = 0; i < 2; i++) |
3882b010 | 618 | buf[i] = TOLOWER (s[i]); |
a75214e5 | 619 | |
bec50466 NC |
620 | for (i = sizeof (psrmods) / sizeof (psrmods[0]); i--;) |
621 | { | |
622 | if (! strncmp (psrmods[i].name, buf, 2)) | |
623 | { | |
624 | * reg = psrmods[i].value; | |
a75214e5 | 625 | |
bec50466 NC |
626 | return s + 2; |
627 | } | |
628 | } | |
a75214e5 | 629 | |
bec50466 | 630 | as_bad (_("bad/missing psr specifier")); |
a75214e5 | 631 | |
bec50466 | 632 | * reg = 0; |
a75214e5 | 633 | |
bec50466 NC |
634 | return s; |
635 | } | |
636 | ||
252b5132 RH |
637 | static char * |
638 | parse_exp (s, e) | |
639 | char * s; | |
640 | expressionS * e; | |
641 | { | |
642 | char * save; | |
643 | char * new; | |
644 | ||
645 | /* Skip whitespace. */ | |
3882b010 | 646 | while (ISSPACE (* s)) |
252b5132 | 647 | ++ s; |
a75214e5 | 648 | |
252b5132 RH |
649 | save = input_line_pointer; |
650 | input_line_pointer = s; | |
651 | ||
652 | expression (e); | |
a75214e5 | 653 | |
252b5132 RH |
654 | if (e->X_op == O_absent) |
655 | as_bad (_("missing operand")); | |
a75214e5 | 656 | |
252b5132 RH |
657 | new = input_line_pointer; |
658 | input_line_pointer = save; | |
a75214e5 | 659 | |
252b5132 RH |
660 | return new; |
661 | } | |
662 | ||
663 | static void | |
664 | make_name (s, p, n) | |
665 | char * s; | |
666 | char * p; | |
667 | int n; | |
668 | { | |
669 | static const char hex[] = "0123456789ABCDEF"; | |
670 | ||
671 | s[0] = p[0]; | |
672 | s[1] = p[1]; | |
673 | s[2] = p[2]; | |
674 | s[3] = hex[(n >> 12) & 0xF]; | |
675 | s[4] = hex[(n >> 8) & 0xF]; | |
676 | s[5] = hex[(n >> 4) & 0xF]; | |
677 | s[6] = hex[(n) & 0xF]; | |
678 | s[7] = 0; | |
679 | } | |
680 | ||
b8a40f53 NC |
681 | #define POOL_END_LABEL ".LE" |
682 | #define POOL_START_LABEL ".LS" | |
683 | ||
252b5132 RH |
684 | static void |
685 | dump_literals (isforce) | |
686 | int isforce; | |
687 | { | |
688 | int i; | |
689 | struct literal * p; | |
49309057 | 690 | symbolS * brarsym; |
a75214e5 | 691 | |
252b5132 RH |
692 | if (poolsize == 0) |
693 | return; | |
694 | ||
695 | /* Must we branch around the literal table? */ | |
696 | if (isforce) | |
697 | { | |
698 | char * output; | |
699 | char brarname[8]; | |
a75214e5 | 700 | |
b8a40f53 | 701 | make_name (brarname, POOL_END_LABEL, poolnumber); |
a75214e5 | 702 | |
252b5132 | 703 | brarsym = symbol_make (brarname); |
a75214e5 | 704 | |
252b5132 | 705 | symbol_table_insert (brarsym); |
a75214e5 | 706 | |
252b5132 | 707 | output = frag_var (rs_machine_dependent, |
93c2a809 AM |
708 | md_relax_table[C (UNCD_JUMP, DISP32)].rlx_length, |
709 | md_relax_table[C (UNCD_JUMP, DISP12)].rlx_length, | |
252b5132 RH |
710 | C (UNCD_JUMP, 0), brarsym, 0, 0); |
711 | output[0] = INST_BYTE0 (MCORE_INST_BR); /* br .+xxx */ | |
712 | output[1] = INST_BYTE1 (MCORE_INST_BR); | |
713 | } | |
a75214e5 | 714 | |
252b5132 RH |
715 | /* Make sure that the section is sufficiently aligned and that |
716 | the literal table is aligned within it. */ | |
717 | record_alignment (now_seg, 2); | |
718 | frag_align (2, 0, 0); | |
a75214e5 | 719 | |
252b5132 | 720 | colon (S_GET_NAME (poolsym)); |
a75214e5 | 721 | |
252b5132 RH |
722 | for (i = 0, p = litpool; i < poolsize; i++, p++) |
723 | emit_expr (& p->e, 4); | |
a75214e5 | 724 | |
252b5132 RH |
725 | if (isforce) |
726 | colon (S_GET_NAME (brarsym)); | |
a75214e5 | 727 | |
252b5132 RH |
728 | poolsize = 0; |
729 | } | |
730 | ||
731 | static void | |
732 | check_literals (kind, offset) | |
733 | int kind; | |
734 | int offset; | |
735 | { | |
736 | poolspan += offset; | |
a75214e5 | 737 | |
252b5132 RH |
738 | /* SPANCLOSE and SPANEXIT are smaller numbers than SPANPANIC. |
739 | SPANPANIC means that we must dump now. | |
740 | kind == 0 is any old instruction. | |
741 | kind > 0 means we just had a control transfer instruction. | |
742 | kind == 1 means within a function | |
743 | kind == 2 means we just left a function | |
a75214e5 | 744 | |
252b5132 RH |
745 | The dump_literals (1) call inserts a branch around the table, so |
746 | we first look to see if its a situation where we won't have to | |
747 | insert a branch (e.g., the previous instruction was an unconditional | |
748 | branch). | |
a75214e5 | 749 | |
252b5132 RH |
750 | SPANPANIC is the point where we must dump a single-entry pool. |
751 | it accounts for alignments and an inserted branch. | |
752 | the 'poolsize*2' accounts for the scenario where we do: | |
753 | lrw r1,lit1; lrw r2,lit2; lrw r3,lit3 | |
754 | Note that the 'lit2' reference is 2 bytes further along | |
755 | but the literal it references will be 4 bytes further along, | |
756 | so we must consider the poolsize into this equation. | |
757 | This is slightly over-cautious, but guarantees that we won't | |
758 | panic because a relocation is too distant. */ | |
a75214e5 | 759 | |
252b5132 RH |
760 | if (poolspan > SPANCLOSE && kind > 0) |
761 | dump_literals (0); | |
4c1102fd | 762 | else if (poolspan > SPANEXIT && kind > 1) |
252b5132 RH |
763 | dump_literals (0); |
764 | else if (poolspan >= (SPANPANIC - poolsize * 2)) | |
765 | dump_literals (1); | |
766 | } | |
767 | ||
768 | static int | |
769 | enter_literal (e, ispcrel) | |
770 | expressionS * e; | |
771 | int ispcrel; | |
772 | { | |
773 | int i; | |
774 | struct literal * p; | |
775 | ||
776 | if (poolsize >= MAX_POOL_SIZE - 2) | |
777 | { | |
778 | /* The literal pool is as full as we can handle. We have | |
779 | to be 2 entries shy of the 1024/4=256 entries because we | |
780 | have to allow for the branch (2 bytes) and the alignment | |
781 | (2 bytes before the first insn referencing the pool and | |
782 | 2 bytes before the pool itself) == 6 bytes, rounds up | |
a75214e5 | 783 | to 2 entries. */ |
252b5132 RH |
784 | dump_literals (1); |
785 | } | |
786 | ||
787 | if (poolsize == 0) | |
788 | { | |
789 | /* Create new literal pool. */ | |
790 | if (++ poolnumber > 0xFFFF) | |
791 | as_fatal (_("more than 65K literal pools")); | |
a75214e5 | 792 | |
b8a40f53 | 793 | make_name (poolname, POOL_START_LABEL, poolnumber); |
252b5132 RH |
794 | poolsym = symbol_make (poolname); |
795 | symbol_table_insert (poolsym); | |
796 | poolspan = 0; | |
797 | } | |
a75214e5 | 798 | |
252b5132 RH |
799 | /* Search pool for value so we don't have duplicates. */ |
800 | for (p = litpool, i = 0; i < poolsize; i++, p++) | |
801 | { | |
802 | if (e->X_op == p->e.X_op | |
803 | && e->X_add_symbol == p->e.X_add_symbol | |
804 | && e->X_add_number == p->e.X_add_number | |
805 | && ispcrel == p->ispcrel) | |
806 | { | |
807 | p->refcnt ++; | |
808 | return i; | |
809 | } | |
810 | } | |
811 | ||
812 | p->refcnt = 1; | |
813 | p->ispcrel = ispcrel; | |
814 | p->e = * e; | |
a75214e5 | 815 | |
252b5132 RH |
816 | poolsize ++; |
817 | ||
a75214e5 | 818 | return i; |
252b5132 RH |
819 | } |
820 | ||
821 | /* Parse a literal specification. -- either new or old syntax. | |
822 | old syntax: the user supplies the label and places the literal. | |
823 | new syntax: we put it into the literal pool. */ | |
824 | static char * | |
825 | parse_rt (s, outputp, ispcrel, ep) | |
826 | char * s; | |
827 | char ** outputp; | |
828 | int ispcrel; | |
829 | expressionS * ep; | |
830 | { | |
831 | expressionS e; | |
832 | int n; | |
a75214e5 | 833 | |
252b5132 RH |
834 | if (ep) |
835 | /* Indicate nothing there. */ | |
836 | ep->X_op = O_absent; | |
a75214e5 | 837 | |
252b5132 RH |
838 | if (*s == '[') |
839 | { | |
840 | s = parse_exp (s + 1, & e); | |
a75214e5 | 841 | |
252b5132 RH |
842 | if (*s == ']') |
843 | s++; | |
844 | else | |
845 | as_bad (_("missing ']'")); | |
846 | } | |
847 | else | |
848 | { | |
849 | s = parse_exp (s, & e); | |
a75214e5 | 850 | |
252b5132 | 851 | n = enter_literal (& e, ispcrel); |
a75214e5 | 852 | |
252b5132 RH |
853 | if (ep) |
854 | *ep = e; | |
855 | ||
856 | /* Create a reference to pool entry. */ | |
857 | e.X_op = O_symbol; | |
858 | e.X_add_symbol = poolsym; | |
859 | e.X_add_number = n << 2; | |
860 | } | |
a75214e5 | 861 | |
252b5132 RH |
862 | * outputp = frag_more (2); |
863 | ||
864 | fix_new_exp (frag_now, (*outputp) - frag_now->fr_literal, 2, & e, 1, | |
865 | BFD_RELOC_MCORE_PCREL_IMM8BY4); | |
866 | ||
867 | return s; | |
868 | } | |
869 | ||
870 | static char * | |
871 | parse_imm (s, val, min, max) | |
872 | char * s; | |
873 | unsigned * val; | |
874 | unsigned min; | |
875 | unsigned max; | |
876 | { | |
877 | char * new; | |
878 | expressionS e; | |
a75214e5 | 879 | |
252b5132 | 880 | new = parse_exp (s, & e); |
a75214e5 | 881 | |
252b5132 RH |
882 | if (e.X_op == O_absent) |
883 | ; /* An error message has already been emitted. */ | |
884 | else if (e.X_op != O_constant) | |
885 | as_bad (_("operand must be a constant")); | |
886 | else if (e.X_add_number < min || e.X_add_number > max) | |
887 | as_bad (_("operand must be absolute in range %d..%d, not %d"), | |
888 | min, max, e.X_add_number); | |
889 | ||
890 | * val = e.X_add_number; | |
a75214e5 | 891 | |
252b5132 RH |
892 | return new; |
893 | } | |
894 | ||
895 | static char * | |
896 | parse_mem (s, reg, off, siz) | |
897 | char * s; | |
898 | unsigned * reg; | |
899 | unsigned * off; | |
900 | unsigned siz; | |
901 | { | |
902 | char * new; | |
903 | ||
904 | * off = 0; | |
a75214e5 | 905 | |
3882b010 | 906 | while (ISSPACE (* s)) |
252b5132 | 907 | ++ s; |
a75214e5 | 908 | |
252b5132 RH |
909 | if (* s == '(') |
910 | { | |
911 | s = parse_reg (s + 1, reg); | |
912 | ||
3882b010 | 913 | while (ISSPACE (* s)) |
252b5132 | 914 | ++ s; |
a75214e5 | 915 | |
252b5132 RH |
916 | if (* s == ',') |
917 | { | |
918 | s = parse_imm (s + 1, off, 0, 63); | |
a75214e5 | 919 | |
252b5132 RH |
920 | if (siz > 1) |
921 | { | |
922 | if (siz > 2) | |
923 | { | |
924 | if (* off & 0x3) | |
925 | as_bad (_("operand must be a multiple of 4")); | |
a75214e5 | 926 | |
252b5132 RH |
927 | * off >>= 2; |
928 | } | |
929 | else | |
930 | { | |
931 | if (* off & 0x1) | |
932 | as_bad (_("operand must be a multiple of 2")); | |
a75214e5 | 933 | |
252b5132 RH |
934 | * off >>= 1; |
935 | } | |
936 | } | |
937 | } | |
a75214e5 | 938 | |
3882b010 | 939 | while (ISSPACE (* s)) |
252b5132 | 940 | ++ s; |
a75214e5 | 941 | |
252b5132 RH |
942 | if (* s == ')') |
943 | s ++; | |
944 | } | |
945 | else | |
946 | as_bad (_("base register expected")); | |
a75214e5 | 947 | |
252b5132 RH |
948 | return s; |
949 | } | |
950 | ||
951 | /* This is the guts of the machine-dependent assembler. STR points to a | |
952 | machine dependent instruction. This function is supposed to emit | |
953 | the frags/bytes it assembles to. */ | |
954 | ||
955 | void | |
956 | md_assemble (str) | |
957 | char * str; | |
958 | { | |
959 | char * op_start; | |
960 | char * op_end; | |
961 | mcore_opcode_info * opcode; | |
962 | char * output; | |
963 | int nlen = 0; | |
964 | unsigned short inst; | |
965 | unsigned reg; | |
966 | unsigned off; | |
967 | unsigned isize; | |
968 | expressionS e; | |
969 | char name[20]; | |
970 | ||
971 | /* Drop leading whitespace. */ | |
3882b010 | 972 | while (ISSPACE (* str)) |
252b5132 RH |
973 | str ++; |
974 | ||
975 | /* Find the op code end. */ | |
976 | for (op_start = op_end = str; | |
b75c0c92 | 977 | nlen < 20 && !is_end_of_line [(unsigned char) *op_end] && *op_end != ' '; |
252b5132 RH |
978 | op_end++) |
979 | { | |
980 | name[nlen] = op_start[nlen]; | |
981 | nlen++; | |
982 | } | |
a75214e5 | 983 | |
252b5132 | 984 | name [nlen] = 0; |
a75214e5 | 985 | |
252b5132 RH |
986 | if (nlen == 0) |
987 | { | |
988 | as_bad (_("can't find opcode ")); | |
989 | return; | |
990 | } | |
991 | ||
992 | opcode = (mcore_opcode_info *) hash_find (opcode_hash_control, name); | |
993 | if (opcode == NULL) | |
994 | { | |
995 | as_bad (_("unknown opcode \"%s\""), name); | |
996 | return; | |
997 | } | |
a75214e5 | 998 | |
252b5132 RH |
999 | inst = opcode->inst; |
1000 | isize = 2; | |
a75214e5 | 1001 | |
252b5132 RH |
1002 | switch (opcode->opclass) |
1003 | { | |
1004 | case O0: | |
1005 | output = frag_more (2); | |
1006 | break; | |
a75214e5 | 1007 | |
252b5132 RH |
1008 | case OT: |
1009 | op_end = parse_imm (op_end + 1, & reg, 0, 3); | |
1010 | inst |= reg; | |
1011 | output = frag_more (2); | |
1012 | break; | |
a75214e5 | 1013 | |
252b5132 RH |
1014 | case O1: |
1015 | op_end = parse_reg (op_end + 1, & reg); | |
1016 | inst |= reg; | |
1017 | output = frag_more (2); | |
1018 | break; | |
a75214e5 | 1019 | |
252b5132 RH |
1020 | case JMP: |
1021 | op_end = parse_reg (op_end + 1, & reg); | |
1022 | inst |= reg; | |
1023 | output = frag_more (2); | |
1024 | /* In a sifilter mode, we emit this insn 2 times, | |
a75214e5 | 1025 | fixes problem of an interrupt during a jmp.. */ |
252b5132 RH |
1026 | if (sifilter_mode) |
1027 | { | |
b8a40f53 NC |
1028 | output[0] = INST_BYTE0 (inst); |
1029 | output[1] = INST_BYTE1 (inst); | |
252b5132 RH |
1030 | output = frag_more (2); |
1031 | } | |
1032 | break; | |
a75214e5 | 1033 | |
252b5132 RH |
1034 | case JSR: |
1035 | op_end = parse_reg (op_end + 1, & reg); | |
a75214e5 | 1036 | |
252b5132 RH |
1037 | if (reg == 15) |
1038 | as_bad (_("invalid register: r15 illegal")); | |
a75214e5 | 1039 | |
252b5132 RH |
1040 | inst |= reg; |
1041 | output = frag_more (2); | |
a75214e5 | 1042 | |
252b5132 RH |
1043 | if (sifilter_mode) |
1044 | { | |
1045 | /* Replace with: bsr .+2 ; addi r15,6; jmp rx ; jmp rx */ | |
1046 | inst = MCORE_INST_BSR; /* with 0 displacement */ | |
b8a40f53 NC |
1047 | output[0] = INST_BYTE0 (inst); |
1048 | output[1] = INST_BYTE1 (inst); | |
252b5132 RH |
1049 | |
1050 | output = frag_more (2); | |
1051 | inst = MCORE_INST_ADDI; | |
1052 | inst |= 15; /* addi r15,6 */ | |
1053 | inst |= (6 - 1) << 4; /* over the jmp's */ | |
b8a40f53 NC |
1054 | output[0] = INST_BYTE0 (inst); |
1055 | output[1] = INST_BYTE1 (inst); | |
252b5132 RH |
1056 | |
1057 | output = frag_more (2); | |
1058 | inst = MCORE_INST_JMP | reg; | |
b8a40f53 NC |
1059 | output[0] = INST_BYTE0 (inst); |
1060 | output[1] = INST_BYTE1 (inst); | |
252b5132 RH |
1061 | |
1062 | output = frag_more (2); /* 2nd emitted in fallthru */ | |
1063 | } | |
1064 | break; | |
a75214e5 | 1065 | |
252b5132 RH |
1066 | case OC: |
1067 | op_end = parse_reg (op_end + 1, & reg); | |
1068 | inst |= reg; | |
a75214e5 | 1069 | |
252b5132 | 1070 | /* Skip whitespace. */ |
3882b010 | 1071 | while (ISSPACE (* op_end)) |
252b5132 | 1072 | ++ op_end; |
a75214e5 | 1073 | |
252b5132 RH |
1074 | if (*op_end == ',') |
1075 | { | |
1076 | op_end = parse_creg (op_end + 1, & reg); | |
1077 | inst |= reg << 4; | |
1078 | } | |
a75214e5 | 1079 | |
252b5132 RH |
1080 | output = frag_more (2); |
1081 | break; | |
1082 | ||
bec50466 NC |
1083 | case MULSH: |
1084 | if (cpu == M210) | |
1085 | { | |
1086 | as_bad (_("M340 specific opcode used when assembling for M210")); | |
1087 | break; | |
1088 | } | |
a75214e5 | 1089 | /* drop through... */ |
252b5132 RH |
1090 | case O2: |
1091 | op_end = parse_reg (op_end + 1, & reg); | |
1092 | inst |= reg; | |
a75214e5 | 1093 | |
252b5132 | 1094 | /* Skip whitespace. */ |
3882b010 | 1095 | while (ISSPACE (* op_end)) |
252b5132 | 1096 | ++ op_end; |
a75214e5 | 1097 | |
252b5132 RH |
1098 | if (* op_end == ',') |
1099 | { | |
1100 | op_end = parse_reg (op_end + 1, & reg); | |
1101 | inst |= reg << 4; | |
1102 | } | |
1103 | else | |
1104 | as_bad (_("second operand missing")); | |
a75214e5 | 1105 | |
252b5132 RH |
1106 | output = frag_more (2); |
1107 | break; | |
a75214e5 | 1108 | |
252b5132 RH |
1109 | case X1: /* Handle both syntax-> xtrb- r1,rx OR xtrb- rx */ |
1110 | op_end = parse_reg (op_end + 1, & reg); | |
a75214e5 | 1111 | |
252b5132 | 1112 | /* Skip whitespace. */ |
3882b010 | 1113 | while (ISSPACE (* op_end)) |
252b5132 | 1114 | ++ op_end; |
a75214e5 | 1115 | |
252b5132 RH |
1116 | if (* op_end == ',') /* xtrb- r1,rx */ |
1117 | { | |
1118 | if (reg != 1) | |
1119 | as_bad (_("destination register must be r1")); | |
a75214e5 | 1120 | |
252b5132 RH |
1121 | op_end = parse_reg (op_end + 1, & reg); |
1122 | } | |
a75214e5 | 1123 | |
252b5132 RH |
1124 | inst |= reg; |
1125 | output = frag_more (2); | |
1126 | break; | |
a75214e5 | 1127 | |
252b5132 RH |
1128 | case O1R1: /* div- rx,r1 */ |
1129 | op_end = parse_reg (op_end + 1, & reg); | |
1130 | inst |= reg; | |
a75214e5 | 1131 | |
252b5132 | 1132 | /* Skip whitespace. */ |
3882b010 | 1133 | while (ISSPACE (* op_end)) |
252b5132 | 1134 | ++ op_end; |
a75214e5 | 1135 | |
252b5132 RH |
1136 | if (* op_end == ',') |
1137 | { | |
1138 | op_end = parse_reg (op_end + 1, & reg); | |
1139 | if (reg != 1) | |
1140 | as_bad (_("source register must be r1")); | |
1141 | } | |
1142 | else | |
1143 | as_bad (_("second operand missing")); | |
a75214e5 | 1144 | |
252b5132 RH |
1145 | output = frag_more (2); |
1146 | break; | |
a75214e5 | 1147 | |
252b5132 RH |
1148 | case OI: |
1149 | op_end = parse_reg (op_end + 1, & reg); | |
1150 | inst |= reg; | |
a75214e5 | 1151 | |
252b5132 | 1152 | /* Skip whitespace. */ |
3882b010 | 1153 | while (ISSPACE (* op_end)) |
252b5132 | 1154 | ++ op_end; |
a75214e5 | 1155 | |
252b5132 RH |
1156 | if (* op_end == ',') |
1157 | { | |
1158 | op_end = parse_imm (op_end + 1, & reg, 1, 32); | |
1159 | inst |= (reg - 1) << 4; | |
1160 | } | |
1161 | else | |
1162 | as_bad (_("second operand missing")); | |
a75214e5 | 1163 | |
252b5132 RH |
1164 | output = frag_more (2); |
1165 | break; | |
a75214e5 | 1166 | |
252b5132 RH |
1167 | case OB: |
1168 | op_end = parse_reg (op_end + 1, & reg); | |
1169 | inst |= reg; | |
a75214e5 | 1170 | |
252b5132 | 1171 | /* Skip whitespace. */ |
3882b010 | 1172 | while (ISSPACE (* op_end)) |
252b5132 | 1173 | ++ op_end; |
a75214e5 | 1174 | |
252b5132 RH |
1175 | if (* op_end == ',') |
1176 | { | |
1177 | op_end = parse_imm (op_end + 1, & reg, 0, 31); | |
1178 | inst |= reg << 4; | |
1179 | } | |
1180 | else | |
1181 | as_bad (_("second operand missing")); | |
a75214e5 | 1182 | |
252b5132 RH |
1183 | output = frag_more (2); |
1184 | break; | |
a75214e5 | 1185 | |
252b5132 RH |
1186 | case OB2: /* like OB, but arg is 2^n instead of n */ |
1187 | op_end = parse_reg (op_end + 1, & reg); | |
1188 | inst |= reg; | |
a75214e5 | 1189 | |
252b5132 | 1190 | /* Skip whitespace. */ |
3882b010 | 1191 | while (ISSPACE (* op_end)) |
252b5132 | 1192 | ++ op_end; |
a75214e5 | 1193 | |
252b5132 RH |
1194 | if (* op_end == ',') |
1195 | { | |
1196 | op_end = parse_imm (op_end + 1, & reg, 1, 1 << 31); | |
a75214e5 | 1197 | /* Further restrict the immediate to a power of two. */ |
252b5132 RH |
1198 | if ((reg & (reg - 1)) == 0) |
1199 | reg = log2 (reg); | |
1200 | else | |
1201 | { | |
1202 | reg = 0; | |
1203 | as_bad (_("immediate is not a power of two")); | |
1204 | } | |
1205 | inst |= (reg) << 4; | |
1206 | } | |
1207 | else | |
1208 | as_bad (_("second operand missing")); | |
a75214e5 | 1209 | |
252b5132 RH |
1210 | output = frag_more (2); |
1211 | break; | |
a75214e5 KH |
1212 | |
1213 | case OBRa: /* Specific for bgeni: imm of 0->6 translate to movi. */ | |
252b5132 RH |
1214 | case OBRb: |
1215 | case OBRc: | |
1216 | op_end = parse_reg (op_end + 1, & reg); | |
1217 | inst |= reg; | |
a75214e5 | 1218 | |
252b5132 | 1219 | /* Skip whitespace. */ |
3882b010 | 1220 | while (ISSPACE (* op_end)) |
252b5132 | 1221 | ++ op_end; |
a75214e5 | 1222 | |
252b5132 RH |
1223 | if (* op_end == ',') |
1224 | { | |
1225 | op_end = parse_imm (op_end + 1, & reg, 0, 31); | |
1226 | /* immediate values of 0 -> 6 translate to movi */ | |
1227 | if (reg <= 6) | |
1228 | { | |
1229 | inst = (inst & 0xF) | MCORE_INST_BGENI_ALT; | |
1230 | reg = 0x1 << reg; | |
1231 | as_warn (_("translating bgeni to movi")); | |
1232 | } | |
1233 | inst &= ~ 0x01f0; | |
1234 | inst |= reg << 4; | |
1235 | } | |
1236 | else | |
1237 | as_bad (_("second operand missing")); | |
a75214e5 | 1238 | |
252b5132 RH |
1239 | output = frag_more (2); |
1240 | break; | |
a75214e5 | 1241 | |
252b5132 RH |
1242 | case OBR2: /* like OBR, but arg is 2^n instead of n */ |
1243 | op_end = parse_reg (op_end + 1, & reg); | |
1244 | inst |= reg; | |
a75214e5 | 1245 | |
252b5132 | 1246 | /* Skip whitespace. */ |
3882b010 | 1247 | while (ISSPACE (* op_end)) |
252b5132 | 1248 | ++ op_end; |
a75214e5 | 1249 | |
252b5132 RH |
1250 | if (* op_end == ',') |
1251 | { | |
1252 | op_end = parse_imm (op_end + 1, & reg, 1, 1 << 31); | |
a75214e5 | 1253 | |
252b5132 RH |
1254 | /* Further restrict the immediate to a power of two. */ |
1255 | if ((reg & (reg - 1)) == 0) | |
1256 | reg = log2 (reg); | |
1257 | else | |
1258 | { | |
1259 | reg = 0; | |
1260 | as_bad (_("immediate is not a power of two")); | |
1261 | } | |
a75214e5 KH |
1262 | |
1263 | /* Immediate values of 0 -> 6 translate to movi. */ | |
252b5132 RH |
1264 | if (reg <= 6) |
1265 | { | |
1266 | inst = (inst & 0xF) | MCORE_INST_BGENI_ALT; | |
1267 | reg = 0x1 << reg; | |
1268 | as_warn (_("translating mgeni to movi")); | |
1269 | } | |
a75214e5 | 1270 | |
252b5132 RH |
1271 | inst |= reg << 4; |
1272 | } | |
1273 | else | |
1274 | as_bad (_("second operand missing")); | |
a75214e5 | 1275 | |
252b5132 RH |
1276 | output = frag_more (2); |
1277 | break; | |
a75214e5 | 1278 | |
252b5132 RH |
1279 | case OMa: /* Specific for bmaski: imm 1->7 translate to movi. */ |
1280 | case OMb: | |
1281 | case OMc: | |
1282 | op_end = parse_reg (op_end + 1, & reg); | |
1283 | inst |= reg; | |
a75214e5 | 1284 | |
252b5132 | 1285 | /* Skip whitespace. */ |
3882b010 | 1286 | while (ISSPACE (* op_end)) |
252b5132 | 1287 | ++ op_end; |
a75214e5 | 1288 | |
252b5132 RH |
1289 | if (* op_end == ',') |
1290 | { | |
1291 | op_end = parse_imm (op_end + 1, & reg, 1, 32); | |
a75214e5 KH |
1292 | |
1293 | /* Immediate values of 1 -> 7 translate to movi. */ | |
252b5132 RH |
1294 | if (reg <= 7) |
1295 | { | |
1296 | inst = (inst & 0xF) | MCORE_INST_BMASKI_ALT; | |
1297 | reg = (0x1 << reg) - 1; | |
1298 | inst |= reg << 4; | |
a75214e5 | 1299 | |
252b5132 RH |
1300 | as_warn (_("translating bmaski to movi")); |
1301 | } | |
1302 | else | |
1303 | { | |
1304 | inst &= ~ 0x01F0; | |
1305 | inst |= (reg & 0x1F) << 4; | |
1306 | } | |
1307 | } | |
1308 | else | |
1309 | as_bad (_("second operand missing")); | |
a75214e5 | 1310 | |
252b5132 RH |
1311 | output = frag_more (2); |
1312 | break; | |
a75214e5 | 1313 | |
252b5132 RH |
1314 | case SI: |
1315 | op_end = parse_reg (op_end + 1, & reg); | |
1316 | inst |= reg; | |
a75214e5 | 1317 | |
252b5132 | 1318 | /* Skip whitespace. */ |
3882b010 | 1319 | while (ISSPACE (* op_end)) |
252b5132 | 1320 | ++ op_end; |
a75214e5 | 1321 | |
252b5132 RH |
1322 | if (* op_end == ',') |
1323 | { | |
1324 | op_end = parse_imm (op_end + 1, & reg, 1, 31); | |
1325 | inst |= reg << 4; | |
1326 | } | |
1327 | else | |
1328 | as_bad (_("second operand missing")); | |
a75214e5 | 1329 | |
252b5132 RH |
1330 | output = frag_more (2); |
1331 | break; | |
1332 | ||
1333 | case I7: | |
1334 | op_end = parse_reg (op_end + 1, & reg); | |
1335 | inst |= reg; | |
a75214e5 | 1336 | |
252b5132 | 1337 | /* Skip whitespace. */ |
3882b010 | 1338 | while (ISSPACE (* op_end)) |
252b5132 | 1339 | ++ op_end; |
a75214e5 | 1340 | |
252b5132 RH |
1341 | if (* op_end == ',') |
1342 | { | |
1343 | op_end = parse_imm (op_end + 1, & reg, 0, 0x7F); | |
1344 | inst |= reg << 4; | |
1345 | } | |
1346 | else | |
1347 | as_bad (_("second operand missing")); | |
a75214e5 | 1348 | |
252b5132 RH |
1349 | output = frag_more (2); |
1350 | break; | |
a75214e5 | 1351 | |
252b5132 RH |
1352 | case LS: |
1353 | op_end = parse_reg (op_end + 1, & reg); | |
1354 | inst |= reg << 8; | |
a75214e5 | 1355 | |
252b5132 | 1356 | /* Skip whitespace. */ |
3882b010 | 1357 | while (ISSPACE (* op_end)) |
252b5132 | 1358 | ++ op_end; |
a75214e5 | 1359 | |
252b5132 RH |
1360 | if (* op_end == ',') |
1361 | { | |
1362 | int size; | |
a75214e5 | 1363 | |
252b5132 RH |
1364 | if ((inst & 0x6000) == 0) |
1365 | size = 4; | |
1366 | else if ((inst & 0x6000) == 0x4000) | |
1367 | size = 2; | |
1368 | else if ((inst & 0x6000) == 0x2000) | |
1369 | size = 1; | |
a75214e5 | 1370 | |
252b5132 | 1371 | op_end = parse_mem (op_end + 1, & reg, & off, size); |
a75214e5 | 1372 | |
252b5132 RH |
1373 | if (off > 16) |
1374 | as_bad (_("displacement too large (%d)"), off); | |
1375 | else | |
1376 | inst |= (reg) | (off << 4); | |
1377 | } | |
1378 | else | |
1379 | as_bad (_("second operand missing")); | |
a75214e5 | 1380 | |
252b5132 RH |
1381 | output = frag_more (2); |
1382 | break; | |
a75214e5 | 1383 | |
252b5132 RH |
1384 | case LR: |
1385 | op_end = parse_reg (op_end + 1, & reg); | |
a75214e5 | 1386 | |
252b5132 RH |
1387 | if (reg == 0 || reg == 15) |
1388 | as_bad (_("Invalid register: r0 and r15 illegal")); | |
a75214e5 | 1389 | |
252b5132 | 1390 | inst |= (reg << 8); |
a75214e5 | 1391 | |
252b5132 | 1392 | /* Skip whitespace. */ |
3882b010 | 1393 | while (ISSPACE (* op_end)) |
252b5132 | 1394 | ++ op_end; |
a75214e5 | 1395 | |
252b5132 | 1396 | if (* op_end == ',') |
2d473ce9 NC |
1397 | { |
1398 | /* parse_rt calls frag_more() for us. */ | |
1399 | input_line_pointer = parse_rt (op_end + 1, & output, 0, 0); | |
1400 | op_end = input_line_pointer; | |
1401 | } | |
252b5132 RH |
1402 | else |
1403 | { | |
1404 | as_bad (_("second operand missing")); | |
1405 | output = frag_more (2); /* save its space */ | |
1406 | } | |
1407 | break; | |
a75214e5 | 1408 | |
252b5132 RH |
1409 | case LJ: |
1410 | input_line_pointer = parse_rt (op_end + 1, & output, 1, 0); | |
1411 | /* parse_rt() calls frag_more() for us. */ | |
2d473ce9 | 1412 | op_end = input_line_pointer; |
252b5132 | 1413 | break; |
a75214e5 | 1414 | |
252b5132 RH |
1415 | case RM: |
1416 | op_end = parse_reg (op_end + 1, & reg); | |
a75214e5 | 1417 | |
252b5132 RH |
1418 | if (reg == 0 || reg == 15) |
1419 | as_bad (_("bad starting register: r0 and r15 invalid")); | |
a75214e5 | 1420 | |
252b5132 | 1421 | inst |= reg; |
a75214e5 | 1422 | |
252b5132 | 1423 | /* Skip whitespace. */ |
3882b010 | 1424 | while (ISSPACE (* op_end)) |
252b5132 | 1425 | ++ op_end; |
a75214e5 | 1426 | |
252b5132 RH |
1427 | if (* op_end == '-') |
1428 | { | |
1429 | op_end = parse_reg (op_end + 1, & reg); | |
a75214e5 | 1430 | |
252b5132 RH |
1431 | if (reg != 15) |
1432 | as_bad (_("ending register must be r15")); | |
a75214e5 | 1433 | |
252b5132 | 1434 | /* Skip whitespace. */ |
3882b010 | 1435 | while (ISSPACE (* op_end)) |
252b5132 RH |
1436 | ++ op_end; |
1437 | } | |
a75214e5 | 1438 | |
252b5132 RH |
1439 | if (* op_end == ',') |
1440 | { | |
1441 | op_end ++; | |
a75214e5 | 1442 | |
252b5132 | 1443 | /* Skip whitespace. */ |
3882b010 | 1444 | while (ISSPACE (* op_end)) |
252b5132 | 1445 | ++ op_end; |
a75214e5 | 1446 | |
252b5132 RH |
1447 | if (* op_end == '(') |
1448 | { | |
1449 | op_end = parse_reg (op_end + 1, & reg); | |
a75214e5 | 1450 | |
252b5132 RH |
1451 | if (reg != 0) |
1452 | as_bad (_("bad base register: must be r0")); | |
a75214e5 | 1453 | |
252b5132 RH |
1454 | if (* op_end == ')') |
1455 | op_end ++; | |
1456 | } | |
1457 | else | |
1458 | as_bad (_("base register expected")); | |
1459 | } | |
1460 | else | |
1461 | as_bad (_("second operand missing")); | |
a75214e5 | 1462 | |
252b5132 RH |
1463 | output = frag_more (2); |
1464 | break; | |
a75214e5 | 1465 | |
252b5132 RH |
1466 | case RQ: |
1467 | op_end = parse_reg (op_end + 1, & reg); | |
a75214e5 | 1468 | |
252b5132 RH |
1469 | if (reg != 4) |
1470 | as_fatal (_("first register must be r4")); | |
a75214e5 | 1471 | |
252b5132 | 1472 | /* Skip whitespace. */ |
3882b010 | 1473 | while (ISSPACE (* op_end)) |
252b5132 | 1474 | ++ op_end; |
a75214e5 | 1475 | |
252b5132 RH |
1476 | if (* op_end == '-') |
1477 | { | |
1478 | op_end = parse_reg (op_end + 1, & reg); | |
a75214e5 | 1479 | |
252b5132 RH |
1480 | if (reg != 7) |
1481 | as_fatal (_("last register must be r7")); | |
a75214e5 | 1482 | |
252b5132 | 1483 | /* Skip whitespace. */ |
3882b010 | 1484 | while (ISSPACE (* op_end)) |
252b5132 | 1485 | ++ op_end; |
a75214e5 | 1486 | |
252b5132 RH |
1487 | if (* op_end == ',') |
1488 | { | |
1489 | op_end ++; | |
a75214e5 | 1490 | |
252b5132 | 1491 | /* Skip whitespace. */ |
3882b010 | 1492 | while (ISSPACE (* op_end)) |
252b5132 | 1493 | ++ op_end; |
a75214e5 | 1494 | |
252b5132 RH |
1495 | if (* op_end == '(') |
1496 | { | |
1497 | op_end = parse_reg (op_end + 1, & reg); | |
a75214e5 | 1498 | |
252b5132 RH |
1499 | if (reg >= 4 && reg <= 7) |
1500 | as_fatal ("base register cannot be r4, r5, r6, or r7"); | |
a75214e5 | 1501 | |
252b5132 | 1502 | inst |= reg; |
a75214e5 | 1503 | |
252b5132 | 1504 | /* Skip whitespace. */ |
3882b010 | 1505 | while (ISSPACE (* op_end)) |
252b5132 | 1506 | ++ op_end; |
a75214e5 | 1507 | |
252b5132 RH |
1508 | if (* op_end == ')') |
1509 | op_end ++; | |
1510 | } | |
1511 | else | |
1512 | as_bad (_("base register expected")); | |
1513 | } | |
1514 | else | |
1515 | as_bad (_("second operand missing")); | |
1516 | } | |
1517 | else | |
1518 | as_bad (_("reg-reg expected")); | |
a75214e5 | 1519 | |
252b5132 RH |
1520 | output = frag_more (2); |
1521 | break; | |
a75214e5 | 1522 | |
252b5132 RH |
1523 | case BR: |
1524 | input_line_pointer = parse_exp (op_end + 1, & e); | |
2d473ce9 | 1525 | op_end = input_line_pointer; |
a75214e5 | 1526 | |
252b5132 | 1527 | output = frag_more (2); |
a75214e5 KH |
1528 | |
1529 | fix_new_exp (frag_now, output-frag_now->fr_literal, | |
252b5132 RH |
1530 | 2, & e, 1, BFD_RELOC_MCORE_PCREL_IMM11BY2); |
1531 | break; | |
a75214e5 | 1532 | |
252b5132 RH |
1533 | case BL: |
1534 | op_end = parse_reg (op_end + 1, & reg); | |
1535 | inst |= reg << 4; | |
a75214e5 | 1536 | |
252b5132 | 1537 | /* Skip whitespace. */ |
3882b010 | 1538 | while (ISSPACE (* op_end)) |
252b5132 | 1539 | ++ op_end; |
a75214e5 | 1540 | |
252b5132 RH |
1541 | if (* op_end == ',') |
1542 | { | |
1543 | op_end = parse_exp (op_end + 1, & e); | |
1544 | output = frag_more (2); | |
a75214e5 KH |
1545 | |
1546 | fix_new_exp (frag_now, output-frag_now->fr_literal, | |
252b5132 RH |
1547 | 2, & e, 1, BFD_RELOC_MCORE_PCREL_IMM4BY2); |
1548 | } | |
1549 | else | |
1550 | { | |
1551 | as_bad (_("second operand missing")); | |
1552 | output = frag_more (2); | |
1553 | } | |
1554 | break; | |
a75214e5 | 1555 | |
252b5132 RH |
1556 | case JC: |
1557 | input_line_pointer = parse_exp (op_end + 1, & e); | |
2d473ce9 | 1558 | op_end = input_line_pointer; |
a75214e5 | 1559 | |
252b5132 | 1560 | output = frag_var (rs_machine_dependent, |
93c2a809 AM |
1561 | md_relax_table[C (COND_JUMP, DISP32)].rlx_length, |
1562 | md_relax_table[C (COND_JUMP, DISP12)].rlx_length, | |
252b5132 RH |
1563 | C (COND_JUMP, 0), e.X_add_symbol, e.X_add_number, 0); |
1564 | isize = C32_LEN; | |
1565 | break; | |
a75214e5 | 1566 | |
252b5132 RH |
1567 | case JU: |
1568 | input_line_pointer = parse_exp (op_end + 1, & e); | |
2d473ce9 NC |
1569 | op_end = input_line_pointer; |
1570 | ||
252b5132 | 1571 | output = frag_var (rs_machine_dependent, |
93c2a809 AM |
1572 | md_relax_table[C (UNCD_JUMP, DISP32)].rlx_length, |
1573 | md_relax_table[C (UNCD_JUMP, DISP12)].rlx_length, | |
252b5132 RH |
1574 | C (UNCD_JUMP, 0), e.X_add_symbol, e.X_add_number, 0); |
1575 | isize = U32_LEN; | |
1576 | break; | |
a75214e5 | 1577 | |
252b5132 RH |
1578 | case JL: |
1579 | inst = MCORE_INST_JSRI; /* jsri */ | |
1580 | input_line_pointer = parse_rt (op_end + 1, & output, 1, & e); | |
bcef92fa | 1581 | /* parse_rt() calls frag_more for us. */ |
2d473ce9 | 1582 | op_end = input_line_pointer; |
a75214e5 KH |
1583 | |
1584 | /* Only do this if we know how to do it ... */ | |
252b5132 RH |
1585 | if (e.X_op != O_absent && do_jsri2bsr) |
1586 | { | |
1587 | /* Look at adding the R_PCREL_JSRIMM11BY2. */ | |
a75214e5 | 1588 | fix_new_exp (frag_now, output-frag_now->fr_literal, |
252b5132 RH |
1589 | 2, & e, 1, BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2); |
1590 | } | |
1591 | break; | |
1592 | ||
1593 | case RSI: /* SI, but imm becomes 32-imm */ | |
1594 | op_end = parse_reg (op_end + 1, & reg); | |
1595 | inst |= reg; | |
a75214e5 | 1596 | |
252b5132 | 1597 | /* Skip whitespace. */ |
3882b010 | 1598 | while (ISSPACE (* op_end)) |
252b5132 | 1599 | ++ op_end; |
a75214e5 | 1600 | |
252b5132 RH |
1601 | if (* op_end == ',') |
1602 | { | |
1603 | op_end = parse_imm (op_end + 1, & reg, 1, 31); | |
a75214e5 | 1604 | |
252b5132 RH |
1605 | reg = 32 - reg; |
1606 | inst |= reg << 4; | |
1607 | } | |
1608 | else | |
1609 | as_bad (_("second operand missing")); | |
a75214e5 | 1610 | |
252b5132 RH |
1611 | output = frag_more (2); |
1612 | break; | |
a75214e5 | 1613 | |
252b5132 RH |
1614 | case DO21: /* O2, dup rd, lit must be 1 */ |
1615 | op_end = parse_reg (op_end + 1, & reg); | |
1616 | inst |= reg; | |
1617 | inst |= reg << 4; | |
a75214e5 | 1618 | |
252b5132 | 1619 | /* Skip whitespace. */ |
3882b010 | 1620 | while (ISSPACE (* op_end)) |
252b5132 | 1621 | ++ op_end; |
a75214e5 | 1622 | |
252b5132 RH |
1623 | if (* op_end == ',') |
1624 | { | |
1625 | op_end = parse_imm (op_end + 1, & reg, 1, 31); | |
a75214e5 | 1626 | |
252b5132 RH |
1627 | if (reg != 1) |
1628 | as_bad (_("second operand must be 1")); | |
1629 | } | |
1630 | else | |
1631 | as_bad (_("second operand missing")); | |
a75214e5 | 1632 | |
252b5132 RH |
1633 | output = frag_more (2); |
1634 | break; | |
a75214e5 | 1635 | |
252b5132 RH |
1636 | case SIa: |
1637 | op_end = parse_reg (op_end + 1, & reg); | |
1638 | inst |= reg; | |
a75214e5 | 1639 | |
252b5132 | 1640 | /* Skip whitespace. */ |
3882b010 | 1641 | while (ISSPACE (* op_end)) |
252b5132 | 1642 | ++ op_end; |
a75214e5 | 1643 | |
252b5132 RH |
1644 | if (* op_end == ',') |
1645 | { | |
1646 | op_end = parse_imm (op_end + 1, & reg, 1, 31); | |
1647 | ||
1648 | if (reg == 0) | |
1649 | as_bad (_("zero used as immediate value")); | |
a75214e5 | 1650 | |
252b5132 RH |
1651 | inst |= reg << 4; |
1652 | } | |
1653 | else | |
1654 | as_bad (_("second operand missing")); | |
a75214e5 | 1655 | |
252b5132 RH |
1656 | output = frag_more (2); |
1657 | break; | |
1658 | ||
bec50466 NC |
1659 | case OPSR: |
1660 | if (cpu == M210) | |
1661 | { | |
1662 | as_bad (_("M340 specific opcode used when assembling for M210")); | |
1663 | break; | |
1664 | } | |
a75214e5 | 1665 | |
bec50466 | 1666 | op_end = parse_psrmod (op_end + 1, & reg); |
a75214e5 | 1667 | |
bec50466 NC |
1668 | /* Look for further selectors. */ |
1669 | while (* op_end == ',') | |
1670 | { | |
1671 | unsigned value; | |
a75214e5 | 1672 | |
bec50466 | 1673 | op_end = parse_psrmod (op_end + 1, & value); |
a75214e5 | 1674 | |
bec50466 NC |
1675 | if (value & reg) |
1676 | as_bad (_("duplicated psr bit specifier")); | |
a75214e5 | 1677 | |
bec50466 NC |
1678 | reg |= value; |
1679 | } | |
a75214e5 | 1680 | |
bec50466 NC |
1681 | if (reg > 8) |
1682 | as_bad (_("`af' must appear alone")); | |
a75214e5 | 1683 | |
bec50466 NC |
1684 | inst |= (reg & 0x7); |
1685 | output = frag_more (2); | |
1686 | break; | |
a75214e5 | 1687 | |
252b5132 RH |
1688 | default: |
1689 | as_bad (_("unimplemented opcode \"%s\""), name); | |
1690 | } | |
2d473ce9 NC |
1691 | |
1692 | /* Drop whitespace after all the operands have been parsed. */ | |
3882b010 | 1693 | while (ISSPACE (* op_end)) |
2d473ce9 NC |
1694 | op_end ++; |
1695 | ||
a75214e5 | 1696 | /* Give warning message if the insn has more operands than required. */ |
2d473ce9 NC |
1697 | if (strcmp (op_end, opcode->name) && strcmp (op_end, "")) |
1698 | as_warn (_("ignoring operands: %s "), op_end); | |
a75214e5 | 1699 | |
b8a40f53 NC |
1700 | output[0] = INST_BYTE0 (inst); |
1701 | output[1] = INST_BYTE1 (inst); | |
a75214e5 | 1702 | |
252b5132 RH |
1703 | check_literals (opcode->transfer, isize); |
1704 | } | |
1705 | ||
1706 | symbolS * | |
1707 | md_undefined_symbol (name) | |
1708 | char * name; | |
1709 | { | |
1710 | return 0; | |
1711 | } | |
1712 | ||
1713 | void | |
1714 | md_mcore_end () | |
1715 | { | |
1716 | dump_literals (0); | |
1717 | subseg_set (text_section, 0); | |
1718 | } | |
1719 | ||
1720 | /* Various routines to kill one day. */ | |
1721 | /* Equal to MAX_PRECISION in atof-ieee.c */ | |
1722 | #define MAX_LITTLENUMS 6 | |
1723 | ||
1724 | /* Turn a string in input_line_pointer into a floating point constant of type | |
1725 | type, and store the appropriate bytes in *litP. The number of LITTLENUMS | |
1726 | emitted is stored in *sizeP. An error message is returned, or NULL on OK.*/ | |
1727 | char * | |
1728 | md_atof (type, litP, sizeP) | |
1729 | int type; | |
1730 | char * litP; | |
1731 | int * sizeP; | |
1732 | { | |
1733 | int prec; | |
1734 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
b8a40f53 | 1735 | int i; |
252b5132 RH |
1736 | char * t; |
1737 | char * atof_ieee (); | |
1738 | ||
1739 | switch (type) | |
1740 | { | |
1741 | case 'f': | |
1742 | case 'F': | |
1743 | case 's': | |
1744 | case 'S': | |
1745 | prec = 2; | |
1746 | break; | |
1747 | ||
1748 | case 'd': | |
1749 | case 'D': | |
1750 | case 'r': | |
1751 | case 'R': | |
1752 | prec = 4; | |
1753 | break; | |
1754 | ||
1755 | case 'x': | |
1756 | case 'X': | |
1757 | prec = 6; | |
1758 | break; | |
1759 | ||
1760 | case 'p': | |
1761 | case 'P': | |
1762 | prec = 6; | |
1763 | break; | |
1764 | ||
1765 | default: | |
1766 | *sizeP = 0; | |
1767 | return _("Bad call to MD_NTOF()"); | |
1768 | } | |
a75214e5 | 1769 | |
252b5132 | 1770 | t = atof_ieee (input_line_pointer, type, words); |
a75214e5 | 1771 | |
252b5132 RH |
1772 | if (t) |
1773 | input_line_pointer = t; | |
1774 | ||
1775 | *sizeP = prec * sizeof (LITTLENUM_TYPE); | |
a75214e5 | 1776 | |
bec50466 NC |
1777 | if (! target_big_endian) |
1778 | { | |
1779 | for (i = prec - 1; i >= 0; i--) | |
1780 | { | |
1781 | md_number_to_chars (litP, (valueT) words[i], | |
1782 | sizeof (LITTLENUM_TYPE)); | |
1783 | litP += sizeof (LITTLENUM_TYPE); | |
1784 | } | |
1785 | } | |
1786 | else | |
b8a40f53 NC |
1787 | for (i = 0; i < prec; i++) |
1788 | { | |
1789 | md_number_to_chars (litP, (valueT) words[i], | |
1790 | sizeof (LITTLENUM_TYPE)); | |
1791 | litP += sizeof (LITTLENUM_TYPE); | |
1792 | } | |
a75214e5 | 1793 | |
252b5132 RH |
1794 | return 0; |
1795 | } | |
1796 | \f | |
5a38dc70 | 1797 | const char * md_shortopts = ""; |
252b5132 | 1798 | |
b8a40f53 NC |
1799 | #define OPTION_JSRI2BSR_ON (OPTION_MD_BASE + 0) |
1800 | #define OPTION_JSRI2BSR_OFF (OPTION_MD_BASE + 1) | |
1801 | #define OPTION_SIFILTER_ON (OPTION_MD_BASE + 2) | |
1802 | #define OPTION_SIFILTER_OFF (OPTION_MD_BASE + 3) | |
bec50466 NC |
1803 | #define OPTION_CPU (OPTION_MD_BASE + 4) |
1804 | #define OPTION_EB (OPTION_MD_BASE + 5) | |
1805 | #define OPTION_EL (OPTION_MD_BASE + 6) | |
252b5132 RH |
1806 | |
1807 | struct option md_longopts[] = | |
1808 | { | |
252b5132 RH |
1809 | { "no-jsri2bsr", no_argument, NULL, OPTION_JSRI2BSR_OFF}, |
1810 | { "jsri2bsr", no_argument, NULL, OPTION_JSRI2BSR_ON}, | |
1811 | { "sifilter", no_argument, NULL, OPTION_SIFILTER_ON}, | |
1812 | { "no-sifilter", no_argument, NULL, OPTION_SIFILTER_OFF}, | |
bec50466 NC |
1813 | { "cpu", required_argument, NULL, OPTION_CPU}, |
1814 | { "EB", no_argument, NULL, OPTION_EB}, | |
1815 | { "EL", no_argument, NULL, OPTION_EL}, | |
252b5132 RH |
1816 | { NULL, no_argument, NULL, 0} |
1817 | }; | |
1818 | ||
1819 | size_t md_longopts_size = sizeof (md_longopts); | |
1820 | ||
1821 | int | |
1822 | md_parse_option (c, arg) | |
1823 | int c; | |
1824 | char * arg; | |
1825 | { | |
1826 | int i; | |
1827 | char * p; | |
1828 | ||
1829 | switch (c) | |
1830 | { | |
bec50466 NC |
1831 | case OPTION_CPU: |
1832 | if (streq (arg, "210")) | |
1833 | { | |
1834 | cpu = M210; | |
1835 | target_big_endian = 1; | |
1836 | } | |
1837 | else if (streq (arg, "340")) | |
1838 | cpu = M340; | |
1839 | else | |
1840 | as_warn (_("unrecognised cpu type '%s'"), arg); | |
1841 | break; | |
a75214e5 | 1842 | |
bec50466 NC |
1843 | case OPTION_EB: target_big_endian = 1; break; |
1844 | case OPTION_EL: target_big_endian = 0; cpu = M340; break; | |
252b5132 RH |
1845 | case OPTION_JSRI2BSR_ON: do_jsri2bsr = 1; break; |
1846 | case OPTION_JSRI2BSR_OFF: do_jsri2bsr = 0; break; | |
1847 | case OPTION_SIFILTER_ON: sifilter_mode = 1; break; | |
1848 | case OPTION_SIFILTER_OFF: sifilter_mode = 0; break; | |
1849 | default: return 0; | |
1850 | } | |
1851 | ||
1852 | return 1; | |
1853 | } | |
1854 | ||
1855 | void | |
1856 | md_show_usage (stream) | |
1857 | FILE * stream; | |
1858 | { | |
1859 | fprintf (stream, _("\ | |
1860 | MCORE specific options:\n\ | |
b8a40f53 | 1861 | -{no-}jsri2bsr {dis}able jsri to bsr transformation (def: dis)\n\ |
bec50466 NC |
1862 | -{no-}sifilter {dis}able silicon filter behavior (def: dis)\n\ |
1863 | -cpu=[210|340] select CPU type\n\ | |
1864 | -EB assemble for a big endian system (default)\n\ | |
1865 | -EL assemble for a little endian system\n")); | |
252b5132 RH |
1866 | } |
1867 | \f | |
1868 | int md_short_jump_size; | |
1869 | ||
1870 | void | |
1871 | md_create_short_jump (ptr, from_Nddr, to_Nddr, frag, to_symbol) | |
1872 | char * ptr; | |
1873 | addressT from_Nddr; | |
1874 | addressT to_Nddr; | |
1875 | fragS * frag; | |
1876 | symbolS * to_symbol; | |
1877 | { | |
1878 | as_fatal (_("failed sanity check: short_jump")); | |
1879 | } | |
1880 | ||
1881 | void | |
1882 | md_create_long_jump (ptr, from_Nddr, to_Nddr, frag, to_symbol) | |
1883 | char * ptr; | |
1884 | addressT from_Nddr; | |
1885 | addressT to_Nddr; | |
1886 | fragS * frag; | |
1887 | symbolS * to_symbol; | |
1888 | { | |
1889 | as_fatal (_("failed sanity check: long_jump")); | |
1890 | } | |
1891 | ||
1892 | /* Called after relaxing, change the frags so they know how big they are. */ | |
1893 | void | |
1894 | md_convert_frag (abfd, sec, fragP) | |
1895 | bfd * abfd; | |
1896 | segT sec; | |
1897 | register fragS * fragP; | |
1898 | { | |
1899 | unsigned char * buffer; | |
1900 | int targ_addr = S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset; | |
a75214e5 | 1901 | |
252b5132 | 1902 | buffer = (unsigned char *) (fragP->fr_fix + fragP->fr_literal); |
252b5132 RH |
1903 | |
1904 | switch (fragP->fr_subtype) | |
1905 | { | |
93c2a809 AM |
1906 | case C (COND_JUMP, DISP12): |
1907 | case C (UNCD_JUMP, DISP12): | |
252b5132 | 1908 | { |
bcef92fa | 1909 | /* Get the address of the end of the instruction. */ |
252b5132 RH |
1910 | int next_inst = fragP->fr_fix + fragP->fr_address + 2; |
1911 | unsigned char t0; | |
1912 | int disp = targ_addr - next_inst; | |
a75214e5 | 1913 | |
252b5132 | 1914 | if (disp & 1) |
b8a40f53 | 1915 | as_bad (_("odd displacement at %x"), next_inst - 2); |
a75214e5 | 1916 | |
252b5132 | 1917 | disp >>= 1; |
a75214e5 | 1918 | |
bec50466 NC |
1919 | if (! target_big_endian) |
1920 | { | |
1921 | t0 = buffer[1] & 0xF8; | |
a75214e5 | 1922 | |
bec50466 | 1923 | md_number_to_chars (buffer, disp, 2); |
a75214e5 | 1924 | |
bec50466 NC |
1925 | buffer[1] = (buffer[1] & 0x07) | t0; |
1926 | } | |
1927 | else | |
b8a40f53 NC |
1928 | { |
1929 | t0 = buffer[0] & 0xF8; | |
a75214e5 | 1930 | |
b8a40f53 | 1931 | md_number_to_chars (buffer, disp, 2); |
a75214e5 | 1932 | |
b8a40f53 NC |
1933 | buffer[0] = (buffer[0] & 0x07) | t0; |
1934 | } | |
a75214e5 | 1935 | |
252b5132 | 1936 | fragP->fr_fix += 2; |
252b5132 RH |
1937 | } |
1938 | break; | |
1939 | ||
93c2a809 | 1940 | case C (COND_JUMP, DISP32): |
252b5132 RH |
1941 | case C (COND_JUMP, UNDEF_WORD_DISP): |
1942 | { | |
1943 | /* A conditional branch wont fit into 12 bits so: | |
1944 | * b!cond 1f | |
1945 | * jmpi 0f | |
1946 | * .align 2 | |
1947 | * 0: .long disp | |
1948 | * 1: | |
1949 | * | |
1950 | * if the b!cond is 4 byte aligned, the literal which would | |
1951 | * go at x+4 will also be aligned. | |
1952 | */ | |
1953 | int first_inst = fragP->fr_fix + fragP->fr_address; | |
1954 | int needpad = (first_inst & 3); | |
1955 | ||
bec50466 NC |
1956 | if (! target_big_endian) |
1957 | buffer[1] ^= 0x08; | |
1958 | else | |
b8a40f53 | 1959 | buffer[0] ^= 0x08; /* Toggle T/F bit */ |
252b5132 RH |
1960 | |
1961 | buffer[2] = INST_BYTE0 (MCORE_INST_JMPI); /* Build jmpi */ | |
1962 | buffer[3] = INST_BYTE1 (MCORE_INST_JMPI); | |
a75214e5 | 1963 | |
252b5132 RH |
1964 | if (needpad) |
1965 | { | |
bec50466 NC |
1966 | if (! target_big_endian) |
1967 | { | |
1968 | buffer[0] = 4; /* branch over jmpi, pad, and ptr */ | |
1969 | buffer[2] = 1; /* jmpi offset of 1 gets the pointer */ | |
1970 | } | |
1971 | else | |
b8a40f53 NC |
1972 | { |
1973 | buffer[1] = 4; /* branch over jmpi, pad, and ptr */ | |
1974 | buffer[3] = 1; /* jmpi offset of 1 gets the pointer */ | |
1975 | } | |
a75214e5 | 1976 | |
252b5132 RH |
1977 | buffer[4] = 0; /* alignment/pad */ |
1978 | buffer[5] = 0; | |
1979 | buffer[6] = 0; /* space for 32 bit address */ | |
1980 | buffer[7] = 0; | |
1981 | buffer[8] = 0; | |
1982 | buffer[9] = 0; | |
a75214e5 | 1983 | |
252b5132 RH |
1984 | /* Make reloc for the long disp */ |
1985 | fix_new (fragP, fragP->fr_fix + 6, 4, | |
1986 | fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_32); | |
a75214e5 | 1987 | |
252b5132 RH |
1988 | fragP->fr_fix += C32_LEN; |
1989 | } | |
1990 | else | |
1991 | { | |
1992 | /* See comment below about this given gas' limitations for | |
1993 | shrinking the fragment. '3' is the amount of code that | |
1994 | we inserted here, but '4' is right for the space we reserved | |
a75214e5 | 1995 | for this fragment. */ |
bec50466 NC |
1996 | if (! target_big_endian) |
1997 | { | |
1998 | buffer[0] = 3; /* branch over jmpi, and ptr */ | |
1999 | buffer[2] = 0; /* jmpi offset of 0 gets the pointer */ | |
2000 | } | |
2001 | else | |
b8a40f53 NC |
2002 | { |
2003 | buffer[1] = 3; /* branch over jmpi, and ptr */ | |
2004 | buffer[3] = 0; /* jmpi offset of 0 gets the pointer */ | |
2005 | } | |
a75214e5 | 2006 | |
252b5132 RH |
2007 | buffer[4] = 0; /* space for 32 bit address */ |
2008 | buffer[5] = 0; | |
2009 | buffer[6] = 0; | |
2010 | buffer[7] = 0; | |
a75214e5 | 2011 | |
252b5132 RH |
2012 | /* Make reloc for the long disp. */ |
2013 | fix_new (fragP, fragP->fr_fix + 4, 4, | |
2014 | fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_32); | |
2015 | fragP->fr_fix += C32_LEN; | |
2016 | ||
b8a40f53 NC |
2017 | /* Frag is actually shorter (see the other side of this ifdef) |
2018 | but gas isn't prepared for that. We have to re-adjust | |
a75214e5 | 2019 | the branch displacement so that it goes beyond the |
252b5132 RH |
2020 | full length of the fragment, not just what we actually |
2021 | filled in. */ | |
bec50466 NC |
2022 | if (! target_big_endian) |
2023 | buffer[0] = 4; /* jmpi, ptr, and the 'tail pad' */ | |
2024 | else | |
b8a40f53 | 2025 | buffer[1] = 4; /* jmpi, ptr, and the 'tail pad' */ |
252b5132 | 2026 | } |
252b5132 RH |
2027 | } |
2028 | break; | |
2029 | ||
93c2a809 | 2030 | case C (UNCD_JUMP, DISP32): |
252b5132 RH |
2031 | case C (UNCD_JUMP, UNDEF_WORD_DISP): |
2032 | { | |
2033 | /* An unconditional branch will not fit in 12 bits, make code which | |
2034 | looks like: | |
2035 | jmpi 0f | |
2036 | .align 2 | |
2037 | 0: .long disp | |
2038 | we need a pad if "first_inst" is 4 byte aligned. | |
2039 | [because the natural literal place is x + 2] */ | |
2040 | int first_inst = fragP->fr_fix + fragP->fr_address; | |
2041 | int needpad = !(first_inst & 3); | |
2042 | ||
2043 | buffer[0] = INST_BYTE0 (MCORE_INST_JMPI); /* Build jmpi */ | |
2044 | buffer[1] = INST_BYTE1 (MCORE_INST_JMPI); | |
2045 | ||
2046 | if (needpad) | |
2047 | { | |
bec50466 NC |
2048 | if (! target_big_endian) |
2049 | buffer[0] = 1; /* jmpi offset of 1 since padded */ | |
2050 | else | |
b8a40f53 | 2051 | buffer[1] = 1; /* jmpi offset of 1 since padded */ |
252b5132 RH |
2052 | buffer[2] = 0; /* alignment */ |
2053 | buffer[3] = 0; | |
2054 | buffer[4] = 0; /* space for 32 bit address */ | |
2055 | buffer[5] = 0; | |
2056 | buffer[6] = 0; | |
2057 | buffer[7] = 0; | |
a75214e5 | 2058 | |
bcef92fa | 2059 | /* Make reloc for the long disp. */ |
252b5132 RH |
2060 | fix_new (fragP, fragP->fr_fix + 4, 4, |
2061 | fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_32); | |
a75214e5 | 2062 | |
252b5132 RH |
2063 | fragP->fr_fix += U32_LEN; |
2064 | } | |
2065 | else | |
2066 | { | |
bec50466 NC |
2067 | if (! target_big_endian) |
2068 | buffer[0] = 0; /* jmpi offset of 0 if no pad */ | |
2069 | else | |
b8a40f53 | 2070 | buffer[1] = 0; /* jmpi offset of 0 if no pad */ |
252b5132 RH |
2071 | buffer[2] = 0; /* space for 32 bit address */ |
2072 | buffer[3] = 0; | |
2073 | buffer[4] = 0; | |
2074 | buffer[5] = 0; | |
a75214e5 | 2075 | |
bcef92fa | 2076 | /* Make reloc for the long disp. */ |
252b5132 RH |
2077 | fix_new (fragP, fragP->fr_fix + 2, 4, |
2078 | fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_32); | |
2079 | fragP->fr_fix += U32_LEN; | |
2080 | } | |
252b5132 RH |
2081 | } |
2082 | break; | |
2083 | ||
2084 | default: | |
2085 | abort (); | |
2086 | } | |
2087 | } | |
2088 | ||
2089 | /* Applies the desired value to the specified location. | |
2090 | Also sets up addends for 'rela' type relocations. */ | |
94f592af NC |
2091 | |
2092 | void | |
2093 | md_apply_fix3 (fixP, valP, segment) | |
252b5132 | 2094 | fixS * fixP; |
94f592af | 2095 | valueT * valP; |
252b5132 RH |
2096 | segT segment; |
2097 | { | |
2098 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
2099 | char * file = fixP->fx_file ? fixP->fx_file : _("unknown"); | |
2100 | const char * symname; | |
2101 | /* Note: use offsetT because it is signed, valueT is unsigned. */ | |
94f592af | 2102 | offsetT val = * (offsetT *) valP; |
a75214e5 | 2103 | |
252b5132 RH |
2104 | symname = fixP->fx_addsy ? S_GET_NAME (fixP->fx_addsy) : _("<unknown>"); |
2105 | /* Save this for the addend in the relocation record. */ | |
2106 | fixP->fx_addnumber = val; | |
2107 | ||
2108 | /* If the fix is relative to a symbol which is not defined, or not | |
2109 | in the same segment as the fix, we cannot resolve it here. */ | |
2110 | if (fixP->fx_addsy != NULL | |
2111 | && ( ! S_IS_DEFINED (fixP->fx_addsy) | |
2112 | || (S_GET_SEGMENT (fixP->fx_addsy) != segment))) | |
2113 | { | |
2114 | fixP->fx_done = 0; | |
2115 | #ifdef OBJ_ELF | |
2116 | /* For ELF we can just return and let the reloc that will be generated | |
2117 | take care of everything. For COFF we still have to insert 'val' | |
2118 | into the insn since the addend field will be ignored. */ | |
94f592af | 2119 | return; |
252b5132 RH |
2120 | #endif |
2121 | } | |
2122 | else | |
2123 | fixP->fx_done = 1; | |
a75214e5 | 2124 | |
252b5132 RH |
2125 | switch (fixP->fx_r_type) |
2126 | { | |
2127 | case BFD_RELOC_MCORE_PCREL_IMM11BY2: /* second byte of 2 byte opcode */ | |
2128 | if ((val & 1) != 0) | |
2129 | as_bad_where (file, fixP->fx_line, | |
2130 | _("odd distance branch (0x%x bytes)"), val); | |
2131 | val /= 2; | |
2132 | if (((val & ~0x3ff) != 0) && ((val | 0x3ff) != -1)) | |
2133 | as_bad_where (file, fixP->fx_line, | |
2134 | _("pcrel for branch to %s too far (0x%x)"), | |
2135 | symname, val); | |
bec50466 NC |
2136 | if (target_big_endian) |
2137 | { | |
2138 | buf[0] |= ((val >> 8) & 0x7); | |
2139 | buf[1] |= (val & 0xff); | |
2140 | } | |
2141 | else | |
2142 | { | |
eaa15ab8 NC |
2143 | buf[1] |= ((val >> 8) & 0x7); |
2144 | buf[0] |= (val & 0xff); | |
bec50466 | 2145 | } |
b8a40f53 | 2146 | break; |
252b5132 RH |
2147 | |
2148 | case BFD_RELOC_MCORE_PCREL_IMM8BY4: /* lower 8 bits of 2 byte opcode */ | |
2149 | val += 3; | |
2150 | val /= 4; | |
2151 | if (val & ~0xff) | |
2152 | as_bad_where (file, fixP->fx_line, | |
2153 | _("pcrel for lrw/jmpi/jsri to %s too far (0x%x)"), | |
2154 | symname, val); | |
bec50466 NC |
2155 | else if (! target_big_endian) |
2156 | buf[0] |= (val & 0xff); | |
252b5132 RH |
2157 | else |
2158 | buf[1] |= (val & 0xff); | |
b8a40f53 | 2159 | break; |
252b5132 RH |
2160 | |
2161 | case BFD_RELOC_MCORE_PCREL_IMM4BY2: /* loopt instruction */ | |
2162 | if ((val < -32) || (val > -2)) | |
2163 | as_bad_where (file, fixP->fx_line, | |
2164 | _("pcrel for loopt too far (0x%x)"), val); | |
2165 | val /= 2; | |
bec50466 NC |
2166 | if (! target_big_endian) |
2167 | buf[0] |= (val & 0xf); | |
2168 | else | |
2d473ce9 | 2169 | buf[1] |= (val & 0xf); |
252b5132 RH |
2170 | break; |
2171 | ||
2172 | case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2: | |
2173 | /* Conditional linker map jsri to bsr. */ | |
a75214e5 | 2174 | /* If its a local target and close enough, fix it. |
252b5132 RH |
2175 | NB: >= -2k for backwards bsr; < 2k for forwards... */ |
2176 | if (fixP->fx_addsy == 0 && val >= -2048 && val < 2048) | |
2177 | { | |
2178 | long nval = (val / 2) & 0x7ff; | |
2179 | nval |= MCORE_INST_BSR; | |
a75214e5 | 2180 | |
252b5132 | 2181 | /* REPLACE the instruction, don't just modify it. */ |
b8a40f53 NC |
2182 | buf[0] = INST_BYTE0 (nval); |
2183 | buf[1] = INST_BYTE1 (nval); | |
252b5132 RH |
2184 | } |
2185 | else | |
2186 | fixP->fx_done = 0; | |
2187 | break; | |
2188 | ||
2189 | case BFD_RELOC_MCORE_PCREL_32: | |
2190 | case BFD_RELOC_VTABLE_INHERIT: | |
2191 | case BFD_RELOC_VTABLE_ENTRY: | |
2192 | fixP->fx_done = 0; | |
2193 | break; | |
a75214e5 | 2194 | |
252b5132 RH |
2195 | default: |
2196 | if (fixP->fx_addsy != NULL) | |
2197 | { | |
2198 | /* If the fix is an absolute reloc based on a symbol's | |
2199 | address, then it cannot be resolved until the final link. */ | |
2200 | fixP->fx_done = 0; | |
2201 | } | |
a75214e5 | 2202 | #ifdef OBJ_ELF |
252b5132 RH |
2203 | else |
2204 | #endif | |
2205 | { | |
2206 | if (fixP->fx_size == 4) | |
b8a40f53 | 2207 | ; |
252b5132 | 2208 | else if (fixP->fx_size == 2 && val >= -32768 && val <= 32767) |
b8a40f53 | 2209 | ; |
252b5132 | 2210 | else if (fixP->fx_size == 1 && val >= -256 && val <= 255) |
b8a40f53 | 2211 | ; |
252b5132 RH |
2212 | else |
2213 | abort (); | |
b8a40f53 | 2214 | md_number_to_chars (buf, val, fixP->fx_size); |
252b5132 RH |
2215 | } |
2216 | break; | |
2217 | } | |
252b5132 RH |
2218 | } |
2219 | ||
2220 | void | |
2221 | md_operand (expressionP) | |
2222 | expressionS * expressionP; | |
2223 | { | |
2224 | /* Ignore leading hash symbol, if poresent. */ | |
2225 | if (* input_line_pointer == '#') | |
2226 | { | |
2227 | input_line_pointer ++; | |
2228 | expression (expressionP); | |
2229 | } | |
2230 | } | |
2231 | ||
2232 | int md_long_jump_size; | |
2233 | ||
2234 | /* Called just before address relaxation, return the length | |
2235 | by which a fragment must grow to reach it's destination. */ | |
2236 | int | |
2237 | md_estimate_size_before_relax (fragP, segment_type) | |
2238 | register fragS * fragP; | |
2239 | register segT segment_type; | |
2240 | { | |
2241 | switch (fragP->fr_subtype) | |
2242 | { | |
93c2a809 AM |
2243 | default: |
2244 | abort (); | |
2245 | ||
252b5132 RH |
2246 | case C (UNCD_JUMP, UNDEF_DISP): |
2247 | /* Used to be a branch to somewhere which was unknown. */ | |
2248 | if (!fragP->fr_symbol) | |
2249 | { | |
93c2a809 | 2250 | fragP->fr_subtype = C (UNCD_JUMP, DISP12); |
252b5132 RH |
2251 | } |
2252 | else if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type) | |
2253 | { | |
93c2a809 | 2254 | fragP->fr_subtype = C (UNCD_JUMP, DISP12); |
252b5132 RH |
2255 | } |
2256 | else | |
2257 | { | |
2258 | fragP->fr_subtype = C (UNCD_JUMP, UNDEF_WORD_DISP); | |
252b5132 RH |
2259 | } |
2260 | break; | |
2261 | ||
252b5132 | 2262 | case C (COND_JUMP, UNDEF_DISP): |
a75214e5 | 2263 | /* Used to be a branch to somewhere which was unknown. */ |
252b5132 RH |
2264 | if (fragP->fr_symbol |
2265 | && S_GET_SEGMENT (fragP->fr_symbol) == segment_type) | |
2266 | { | |
2267 | /* Got a symbol and it's defined in this segment, become byte | |
2268 | sized - maybe it will fix up */ | |
93c2a809 | 2269 | fragP->fr_subtype = C (COND_JUMP, DISP12); |
252b5132 RH |
2270 | } |
2271 | else if (fragP->fr_symbol) | |
2272 | { | |
2273 | /* Its got a segment, but its not ours, so it will always be long. */ | |
2274 | fragP->fr_subtype = C (COND_JUMP, UNDEF_WORD_DISP); | |
252b5132 RH |
2275 | } |
2276 | else | |
2277 | { | |
2278 | /* We know the abs value. */ | |
93c2a809 | 2279 | fragP->fr_subtype = C (COND_JUMP, DISP12); |
252b5132 | 2280 | } |
93c2a809 | 2281 | break; |
252b5132 | 2282 | |
93c2a809 | 2283 | case C (UNCD_JUMP, DISP12): |
e66457fb | 2284 | case C (UNCD_JUMP, DISP32): |
93c2a809 AM |
2285 | case C (UNCD_JUMP, UNDEF_WORD_DISP): |
2286 | case C (COND_JUMP, DISP12): | |
e66457fb | 2287 | case C (COND_JUMP, DISP32): |
93c2a809 AM |
2288 | case C (COND_JUMP, UNDEF_WORD_DISP): |
2289 | /* When relaxing a section for the second time, we don't need to | |
e66457fb | 2290 | do anything besides return the current size. */ |
252b5132 RH |
2291 | break; |
2292 | } | |
a75214e5 | 2293 | |
606ab118 | 2294 | return md_relax_table[fragP->fr_subtype].rlx_length; |
252b5132 RH |
2295 | } |
2296 | ||
bcef92fa | 2297 | /* Put number into target byte order. */ |
252b5132 RH |
2298 | void |
2299 | md_number_to_chars (ptr, use, nbytes) | |
2300 | char * ptr; | |
2301 | valueT use; | |
2302 | int nbytes; | |
2303 | { | |
bec50466 NC |
2304 | if (! target_big_endian) |
2305 | switch (nbytes) | |
2306 | { | |
2307 | case 4: ptr[3] = (use >> 24) & 0xff; /* fall through */ | |
2308 | case 3: ptr[2] = (use >> 16) & 0xff; /* fall through */ | |
2309 | case 2: ptr[1] = (use >> 8) & 0xff; /* fall through */ | |
2310 | case 1: ptr[0] = (use >> 0) & 0xff; break; | |
2311 | default: abort (); | |
2312 | } | |
2313 | else | |
b8a40f53 NC |
2314 | switch (nbytes) |
2315 | { | |
2316 | case 4: *ptr++ = (use >> 24) & 0xff; /* fall through */ | |
2317 | case 3: *ptr++ = (use >> 16) & 0xff; /* fall through */ | |
2318 | case 2: *ptr++ = (use >> 8) & 0xff; /* fall through */ | |
2319 | case 1: *ptr++ = (use >> 0) & 0xff; break; | |
2320 | default: abort (); | |
2321 | } | |
252b5132 RH |
2322 | } |
2323 | ||
2324 | /* Round up a section size to the appropriate boundary. */ | |
2325 | valueT | |
2326 | md_section_align (segment, size) | |
2327 | segT segment; | |
2328 | valueT size; | |
2329 | { | |
2330 | return size; /* Byte alignment is fine */ | |
2331 | } | |
2332 | ||
252b5132 RH |
2333 | /* The location from which a PC relative jump should be calculated, |
2334 | given a PC relative reloc. */ | |
2335 | long | |
2336 | md_pcrel_from_section (fixp, sec) | |
2337 | fixS * fixp; | |
2338 | segT sec; | |
2339 | { | |
2340 | #ifdef OBJ_ELF | |
2341 | /* If the symbol is undefined or defined in another section | |
2342 | we leave the add number alone for the linker to fix it later. | |
a75214e5 | 2343 | Only account for the PC pre-bump (which is 2 bytes on the MCore). */ |
252b5132 RH |
2344 | if (fixp->fx_addsy != (symbolS *) NULL |
2345 | && (! S_IS_DEFINED (fixp->fx_addsy) | |
2346 | || (S_GET_SEGMENT (fixp->fx_addsy) != sec))) | |
a75214e5 | 2347 | |
252b5132 RH |
2348 | { |
2349 | assert (fixp->fx_size == 2); /* must be an insn */ | |
2350 | return fixp->fx_size; | |
2351 | } | |
2352 | #endif | |
2353 | ||
a75214e5 | 2354 | /* The case where we are going to resolve things... */ |
252b5132 RH |
2355 | return fixp->fx_size + fixp->fx_where + fixp->fx_frag->fr_address; |
2356 | } | |
2357 | ||
2358 | #define F(SZ,PCREL) (((SZ) << 1) + (PCREL)) | |
2359 | #define MAP(SZ,PCREL,TYPE) case F (SZ, PCREL): code = (TYPE); break | |
2360 | ||
2361 | arelent * | |
2362 | tc_gen_reloc (section, fixp) | |
2363 | asection * section; | |
2364 | fixS * fixp; | |
2365 | { | |
2366 | arelent * rel; | |
2367 | bfd_reloc_code_real_type code; | |
2368 | int handled = 0; | |
2369 | ||
2370 | switch (fixp->fx_r_type) | |
2371 | { | |
a75214e5 | 2372 | /* These confuse the size/pcrel macro approach. */ |
252b5132 RH |
2373 | case BFD_RELOC_VTABLE_INHERIT: |
2374 | case BFD_RELOC_VTABLE_ENTRY: | |
2375 | case BFD_RELOC_MCORE_PCREL_IMM4BY2: | |
2376 | case BFD_RELOC_MCORE_PCREL_IMM8BY4: | |
2377 | case BFD_RELOC_MCORE_PCREL_IMM11BY2: | |
2378 | case BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2: | |
a75214e5 | 2379 | case BFD_RELOC_RVA: |
252b5132 RH |
2380 | code = fixp->fx_r_type; |
2381 | break; | |
a75214e5 | 2382 | |
252b5132 RH |
2383 | default: |
2384 | switch (F (fixp->fx_size, fixp->fx_pcrel)) | |
2385 | { | |
2386 | MAP (1, 0, BFD_RELOC_8); | |
2387 | MAP (2, 0, BFD_RELOC_16); | |
2388 | MAP (4, 0, BFD_RELOC_32); | |
2389 | MAP (1, 1, BFD_RELOC_8_PCREL); | |
2390 | MAP (2, 1, BFD_RELOC_16_PCREL); | |
2391 | MAP (4, 1, BFD_RELOC_32_PCREL); | |
2392 | default: | |
2393 | code = fixp->fx_r_type; | |
2394 | as_bad (_("Can not do %d byte %srelocation"), | |
2395 | fixp->fx_size, | |
2396 | fixp->fx_pcrel ? _("pc-relative") : ""); | |
2397 | } | |
2398 | break; | |
2399 | } | |
2400 | ||
2401 | rel = (arelent *) xmalloc (sizeof (arelent)); | |
310b5aa2 ILT |
2402 | rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
2403 | *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
2404 | rel->address = fixp->fx_frag->fr_address + fixp->fx_where; |
2405 | /* Always pass the addend along! */ | |
2406 | rel->addend = fixp->fx_addnumber; | |
2407 | ||
2408 | rel->howto = bfd_reloc_type_lookup (stdoutput, code); | |
a75214e5 | 2409 | |
252b5132 RH |
2410 | if (rel->howto == NULL) |
2411 | { | |
2412 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
2413 | _("Cannot represent relocation type %s"), | |
2414 | bfd_get_reloc_code_name (code)); | |
a75214e5 | 2415 | |
252b5132 RH |
2416 | /* Set howto to a garbage value so that we can keep going. */ |
2417 | rel->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32); | |
2418 | assert (rel->howto != NULL); | |
2419 | } | |
2420 | ||
2421 | return rel; | |
2422 | } | |
2423 | ||
2424 | #ifdef OBJ_ELF | |
2425 | /* See whether we need to force a relocation into the output file. | |
2426 | This is used to force out switch and PC relative relocations when | |
2427 | relaxing. */ | |
2428 | int | |
2429 | mcore_force_relocation (fix) | |
2430 | fixS * fix; | |
2431 | { | |
2432 | if ( fix->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
f11900d0 | 2433 | || fix->fx_r_type == BFD_RELOC_VTABLE_ENTRY |
2d473ce9 | 2434 | || fix->fx_r_type == BFD_RELOC_RVA) |
252b5132 RH |
2435 | return 1; |
2436 | ||
2437 | return 0; | |
2438 | } | |
2439 | ||
2440 | /* Return true if the fix can be handled by GAS, false if it must | |
2441 | be passed through to the linker. */ | |
2442 | boolean | |
2443 | mcore_fix_adjustable (fixP) | |
2444 | fixS * fixP; | |
2445 | { | |
2446 | if (fixP->fx_addsy == NULL) | |
2447 | return 1; | |
a75214e5 | 2448 | |
252b5132 RH |
2449 | /* We need the symbol name for the VTABLE entries. */ |
2450 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
2451 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
2452 | return 0; | |
2453 | ||
2454 | return 1; | |
2455 | } | |
252b5132 | 2456 | #endif /* OBJ_ELF */ |