Commit | Line | Data |
---|---|---|
025b0302 ME |
1 | /* tc-sh.c -- Assemble code for the Hitachi Super-H |
2 | ||
3 | Copyright (C) 1993 Free Software Foundation. | |
4 | ||
5 | This file is part of GAS, the GNU Assembler. | |
6 | ||
7 | GAS is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GAS is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GAS; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* | |
351efc81 SC |
22 | Written By Steve Chamberlain |
23 | sac@cygnus.com | |
24 | */ | |
025b0302 ME |
25 | |
26 | #include <stdio.h> | |
27 | #include "as.h" | |
28 | #include "bfd.h" | |
29 | #include "subsegs.h" | |
30 | #define DEFINE_TABLE | |
9cc7c60b | 31 | #include "opcodes/sh-opc.h" |
025b0302 | 32 | #include <ctype.h> |
025b0302 ME |
33 | const char comment_chars[] = "!"; |
34 | const char line_separator_chars[] = ";"; | |
d6905776 | 35 | const char line_comment_chars[] = "!#"; |
025b0302 ME |
36 | |
37 | /* This table describes all the machine specific pseudo-ops the assembler | |
38 | has to support. The fields are: | |
39 | pseudo-op name without dot | |
40 | function to call to execute this pseudo-op | |
41 | Integer arg to pass to the function | |
351efc81 | 42 | */ |
025b0302 ME |
43 | |
44 | void cons (); | |
45 | void s_align_bytes (); | |
46 | ||
d6905776 KR |
47 | int shl = 0; |
48 | ||
49 | static void little() | |
50 | { | |
51 | shl = 1; | |
52 | } | |
53 | ||
025b0302 ME |
54 | const pseudo_typeS md_pseudo_table[] = |
55 | { | |
56 | {"int", cons, 4}, | |
57 | {"word", cons, 2}, | |
58 | {"form", listing_psize, 0}, | |
d6905776 | 59 | {"little", little,0}, |
025b0302 ME |
60 | {"heading", listing_title, 0}, |
61 | {"import", s_ignore, 0}, | |
62 | {"page", listing_eject, 0}, | |
63 | {"program", s_ignore, 0}, | |
64 | {0, 0, 0} | |
65 | }; | |
66 | ||
351efc81 | 67 | /*int md_reloc_size; */ |
025b0302 ME |
68 | |
69 | static int relax; /* set if -relax seen */ | |
70 | ||
71 | const char EXP_CHARS[] = "eE"; | |
72 | ||
73 | /* Chars that mean this number is a floating point constant */ | |
74 | /* As in 0f12.456 */ | |
75 | /* or 0d1.2345e12 */ | |
76 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
77 | ||
78 | #define C(a,b) ENCODE_RELAX(a,b) | |
79 | ||
80 | #define JREG 14 /* Register used as a temp when relaxing */ | |
81 | #define ENCODE_RELAX(what,length) (((what) << 4) + (length)) | |
82 | #define GET_WHAT(x) ((x>>4)) | |
83 | ||
84 | /* These are the two types of relaxable instrction */ | |
85 | #define COND_JUMP 1 | |
86 | #define UNCOND_JUMP 2 | |
87 | ||
88 | #define UNDEF_DISP 0 | |
89 | #define COND8 1 | |
90 | #define COND12 2 | |
91 | #define COND32 3 | |
92 | #define UNCOND12 1 | |
93 | #define UNCOND32 2 | |
94 | #define UNDEF_WORD_DISP 4 | |
95 | #define END 5 | |
96 | ||
97 | #define UNCOND12 1 | |
98 | #define UNCOND32 2 | |
99 | ||
100 | #define COND8_F 254 | |
101 | #define COND8_M -256 | |
102 | #define COND8_LENGTH 2 | |
103 | #define COND12_F (4094 - 4) /* -4 since there are two extra */ | |
104 | /* instructions needed */ | |
105 | #define COND12_M -4096 | |
106 | #define COND12_LENGTH 6 | |
107 | #define COND32_F (1<<30) | |
108 | #define COND32_M -(1<<30) | |
109 | #define COND32_LENGTH 14 | |
110 | ||
111 | #define COND8_RANGE(x) ((x) > COND8_M && (x) < COND8_F) | |
112 | #define COND12_RANGE(x) ((x) > COND12_M && (x) < COND12_F) | |
113 | ||
114 | #define UNCOND12_F 4094 | |
115 | #define UNCOND12_M -4096 | |
116 | #define UNCOND12_LENGTH 2 | |
117 | ||
118 | #define UNCOND32_F (1<<30) | |
119 | #define UNCOND32_M -(1<<30) | |
120 | #define UNCOND32_LENGTH 14 | |
121 | ||
122 | ||
d6905776 KR |
123 | const relax_typeS md_relax_table[C (END, 0)] = { |
124 | { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, | |
125 | { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, | |
126 | ||
127 | { 0 }, | |
128 | /* C (COND_JUMP, COND8) */ | |
129 | { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP, COND12) }, | |
130 | /* C (COND_JUMP, COND12) */ | |
131 | { COND12_F, COND12_M, COND12_LENGTH, C (COND_JUMP, COND32), }, | |
132 | /* C (COND_JUMP, COND32) */ | |
133 | { COND32_F, COND32_M, COND32_LENGTH, 0, }, | |
134 | { 0 }, { 0 }, { 0 }, { 0 }, | |
135 | { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, | |
136 | ||
137 | { 0 }, | |
138 | /* C (UNCOND_JUMP, UNCOND12) */ | |
139 | { UNCOND12_F, UNCOND12_M, UNCOND12_LENGTH, C (UNCOND_JUMP, UNCOND32), }, | |
140 | /* C (UNCOND_JUMP, UNCOND32) */ | |
141 | { UNCOND32_F, UNCOND32_M, UNCOND32_LENGTH, 0, }, | |
142 | { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, | |
143 | { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, | |
144 | }; | |
025b0302 ME |
145 | |
146 | static struct hash_control *opcode_hash_control; /* Opcode mnemonics */ | |
147 | ||
148 | /* | |
351efc81 SC |
149 | This function is called once, at assembler startup time. This should |
150 | set up all the tables, etc that the MD part of the assembler needs | |
151 | */ | |
025b0302 ME |
152 | |
153 | void | |
154 | md_begin () | |
155 | { | |
156 | sh_opcode_info *opcode; | |
157 | char *prev_name = ""; | |
158 | ||
159 | opcode_hash_control = hash_new (); | |
160 | ||
161 | /* Insert unique names into hash table */ | |
162 | for (opcode = sh_table; opcode->name; opcode++) | |
163 | { | |
164 | if (strcmp (prev_name, opcode->name)) | |
165 | { | |
166 | prev_name = opcode->name; | |
167 | hash_insert (opcode_hash_control, opcode->name, (char *) opcode); | |
168 | } | |
169 | else | |
170 | { | |
171 | /* Make all the opcodes with the same name point to the same | |
351efc81 | 172 | string */ |
025b0302 ME |
173 | opcode->name = prev_name; |
174 | } | |
175 | } | |
025b0302 ME |
176 | } |
177 | ||
178 | static int reg_m; | |
179 | static int reg_n; | |
180 | static expressionS immediate; /* absolute expression */ | |
181 | ||
182 | typedef struct | |
351efc81 SC |
183 | { |
184 | sh_arg_type type; | |
185 | int reg; | |
186 | } | |
025b0302 ME |
187 | |
188 | sh_operand_info; | |
189 | ||
190 | /* try and parse a reg name, returns number of chars consumed */ | |
191 | static int | |
192 | parse_reg (src, mode, reg) | |
193 | char *src; | |
194 | int *mode; | |
195 | int *reg; | |
196 | { | |
197 | if (src[0] == 'r') | |
198 | { | |
199 | if (src[1] == '1') | |
200 | { | |
201 | if (src[2] >= '0' && src[2] <= '5') | |
202 | { | |
203 | *mode = A_REG_N; | |
204 | *reg = 10 + src[2] - '0'; | |
205 | return 3; | |
206 | } | |
207 | } | |
208 | if (src[1] >= '0' && src[1] <= '9') | |
209 | { | |
210 | *mode = A_REG_N; | |
211 | *reg = (src[1] - '0'); | |
212 | return 2; | |
213 | } | |
214 | } | |
215 | ||
216 | if (src[0] == 's' && src[1] == 'r') | |
217 | { | |
218 | *mode = A_SR; | |
219 | return 2; | |
220 | } | |
221 | ||
222 | if (src[0] == 's' && src[1] == 'p') | |
223 | { | |
224 | *mode = A_REG_N; | |
225 | *reg = 15; | |
226 | return 2; | |
227 | } | |
228 | ||
229 | if (src[0] == 'p' && src[1] == 'r') | |
230 | { | |
231 | *mode = A_PR; | |
232 | return 2; | |
233 | } | |
234 | if (src[0] == 'p' && src[1] == 'c') | |
235 | { | |
236 | *mode = A_DISP_PC; | |
237 | return 2; | |
238 | } | |
239 | if (src[0] == 'g' && src[1] == 'b' && src[2] == 'r') | |
240 | { | |
241 | *mode = A_GBR; | |
242 | return 3; | |
243 | } | |
244 | if (src[0] == 'v' && src[1] == 'b' && src[2] == 'r') | |
245 | { | |
246 | *mode = A_VBR; | |
247 | return 3; | |
248 | } | |
249 | ||
250 | if (src[0] == 'm' && src[1] == 'a' && src[2] == 'c') | |
251 | { | |
252 | if (src[3] == 'l') | |
253 | { | |
254 | *mode = A_MACL; | |
255 | return 4; | |
256 | } | |
257 | if (src[3] == 'h') | |
258 | { | |
259 | *mode = A_MACH; | |
260 | return 4; | |
261 | } | |
262 | } | |
263 | ||
264 | return 0; | |
265 | } | |
266 | ||
351efc81 SC |
267 | static symbolS *dot() |
268 | { | |
269 | const char *fake; | |
270 | ||
271 | /* JF: '.' is pseudo symbol with value of current location | |
272 | in current segment. */ | |
273 | fake = FAKE_LABEL_NAME; | |
274 | return symbol_new (fake, | |
275 | now_seg, | |
276 | (valueT) frag_now_fix (), | |
277 | frag_now); | |
278 | ||
279 | } | |
280 | ||
281 | ||
025b0302 ME |
282 | static |
283 | char * | |
284 | parse_exp (s) | |
285 | char *s; | |
286 | { | |
287 | char *save; | |
288 | char *new; | |
025b0302 ME |
289 | |
290 | save = input_line_pointer; | |
025b0302 | 291 | input_line_pointer = s; |
351efc81 SC |
292 | expression (&immediate); |
293 | if (immediate.X_op == O_absent) | |
294 | as_bad ("missing operand"); | |
025b0302 ME |
295 | new = input_line_pointer; |
296 | input_line_pointer = save; | |
351efc81 | 297 | return new; |
025b0302 ME |
298 | } |
299 | ||
300 | ||
301 | /* The many forms of operand: | |
302 | ||
351efc81 SC |
303 | Rn Register direct |
304 | @Rn Register indirect | |
305 | @Rn+ Autoincrement | |
306 | @-Rn Autodecrement | |
025b0302 ME |
307 | @(disp:4,Rn) |
308 | @(disp:8,GBR) | |
309 | @(disp:8,PC) | |
310 | ||
311 | @(R0,Rn) | |
312 | @(R0,GBR) | |
313 | ||
314 | disp:8 | |
315 | disp:12 | |
316 | #imm8 | |
317 | pr, gbr, vbr, macl, mach | |
318 | ||
319 | */ | |
320 | ||
321 | static | |
322 | char * | |
323 | parse_at (src, op) | |
324 | char *src; | |
325 | sh_operand_info *op; | |
326 | { | |
327 | int len; | |
328 | int mode; | |
329 | src++; | |
330 | if (src[0] == '-') | |
331 | { | |
332 | /* Must be predecrement */ | |
333 | src++; | |
334 | ||
335 | len = parse_reg (src, &mode, &(op->reg)); | |
336 | if (mode != A_REG_N) | |
337 | as_bad ("illegal register after @-"); | |
338 | ||
339 | op->type = A_DEC_N; | |
340 | src += len; | |
341 | } | |
342 | else if (src[0] == '(') | |
343 | { | |
344 | /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or | |
351efc81 | 345 | @(r0, rn) */ |
025b0302 ME |
346 | src++; |
347 | len = parse_reg (src, &mode, &(op->reg)); | |
348 | if (len && mode == A_REG_N) | |
349 | { | |
350 | src += len; | |
351 | if (op->reg != 0) | |
352 | { | |
353 | as_bad ("must be @(r0,...)"); | |
354 | } | |
355 | if (src[0] == ',') | |
356 | src++; | |
357 | /* Now can be rn or gbr */ | |
358 | len = parse_reg (src, &mode, &(op->reg)); | |
359 | if (mode == A_GBR) | |
360 | { | |
361 | op->type = A_R0_GBR; | |
362 | } | |
363 | else if (mode == A_REG_N) | |
364 | { | |
365 | op->type = A_IND_R0_REG_N; | |
366 | } | |
367 | else | |
368 | { | |
369 | as_bad ("syntax error in @(r0,...)"); | |
370 | } | |
371 | } | |
372 | else | |
373 | { | |
374 | /* Must be an @(disp,.. thing) */ | |
375 | src = parse_exp (src); | |
376 | if (src[0] == ',') | |
377 | src++; | |
378 | /* Now can be rn, gbr or pc */ | |
379 | len = parse_reg (src, &mode, &op->reg); | |
380 | if (len) | |
381 | { | |
382 | if (mode == A_REG_N) | |
383 | { | |
384 | op->type = A_DISP_REG_N; | |
385 | } | |
386 | else if (mode == A_GBR) | |
387 | { | |
388 | op->type = A_DISP_GBR; | |
389 | } | |
390 | else if (mode == A_DISP_PC) | |
391 | { | |
351efc81 SC |
392 | /* Turn a plain @(4,pc) into @(.+4,pc) */ |
393 | if (immediate.X_op == O_constant) { | |
394 | immediate.X_add_symbol = dot(); | |
395 | immediate.X_op = O_symbol; | |
396 | } | |
025b0302 ME |
397 | op->type = A_DISP_PC; |
398 | } | |
399 | else | |
400 | { | |
401 | as_bad ("syntax error in @(disp,[Rn, gbr, pc])"); | |
402 | } | |
403 | } | |
404 | else | |
405 | { | |
406 | as_bad ("syntax error in @(disp,[Rn, gbr, pc])"); | |
407 | } | |
408 | } | |
409 | src += len; | |
410 | if (src[0] != ')') | |
411 | as_bad ("expecting )"); | |
412 | else | |
413 | src++; | |
414 | } | |
415 | else | |
416 | { | |
417 | src += parse_reg (src, &mode, &(op->reg)); | |
418 | if (mode != A_REG_N) | |
419 | { | |
420 | as_bad ("illegal register after @"); | |
421 | } | |
422 | if (src[0] == '+') | |
423 | { | |
424 | op->type = A_INC_N; | |
425 | src++; | |
426 | } | |
427 | else | |
428 | { | |
429 | op->type = A_IND_N; | |
430 | } | |
431 | } | |
432 | return src; | |
433 | } | |
434 | ||
435 | static void | |
436 | get_operand (ptr, op) | |
437 | char **ptr; | |
438 | sh_operand_info *op; | |
439 | { | |
440 | char *src = *ptr; | |
441 | int mode = -1; | |
442 | unsigned int len; | |
443 | ||
444 | if (src[0] == '#') | |
445 | { | |
446 | src++; | |
447 | *ptr = parse_exp (src); | |
448 | op->type = A_IMM; | |
449 | return; | |
450 | } | |
451 | ||
452 | else if (src[0] == '@') | |
453 | { | |
454 | *ptr = parse_at (src, op); | |
455 | return; | |
456 | } | |
457 | len = parse_reg (src, &mode, &(op->reg)); | |
458 | if (len) | |
459 | { | |
460 | *ptr = src + len; | |
461 | op->type = mode; | |
462 | return; | |
463 | } | |
464 | else | |
465 | { | |
466 | /* Not a reg, the only thing left is a displacement */ | |
467 | *ptr = parse_exp (src); | |
468 | op->type = A_DISP_PC; | |
469 | return; | |
470 | } | |
471 | } | |
472 | ||
473 | static | |
474 | char * | |
475 | get_operands (info, args, operand) | |
476 | sh_opcode_info *info; | |
477 | char *args; | |
478 | sh_operand_info *operand; | |
479 | ||
480 | { | |
481 | char *ptr = args; | |
482 | if (info->arg[0]) | |
483 | { | |
484 | ptr++; | |
485 | ||
486 | get_operand (&ptr, operand + 0); | |
487 | if (info->arg[1]) | |
488 | { | |
489 | if (*ptr == ',') | |
490 | { | |
491 | ptr++; | |
492 | } | |
493 | get_operand (&ptr, operand + 1); | |
494 | } | |
495 | else | |
496 | { | |
497 | operand[1].type = 0; | |
498 | } | |
499 | } | |
500 | else | |
501 | { | |
502 | operand[0].type = 0; | |
503 | operand[1].type = 0; | |
504 | } | |
505 | return ptr; | |
506 | } | |
507 | ||
508 | /* Passed a pointer to a list of opcodes which use different | |
509 | addressing modes, return the opcode which matches the opcodes | |
510 | provided | |
351efc81 | 511 | */ |
025b0302 ME |
512 | |
513 | static | |
514 | sh_opcode_info * | |
515 | get_specific (opcode, operands) | |
516 | sh_opcode_info *opcode; | |
517 | sh_operand_info *operands; | |
518 | { | |
519 | sh_opcode_info *this_try = opcode; | |
520 | char *name = opcode->name; | |
521 | int arg_to_test = 0; | |
522 | int n = 0; | |
523 | while (opcode->name) | |
524 | { | |
525 | this_try = opcode++; | |
526 | if (this_try->name != name) | |
527 | { | |
528 | /* We've looked so far down the table that we've run out of | |
529 | opcodes with the same name */ | |
530 | return 0; | |
531 | } | |
532 | /* look at both operands needed by the opcodes and provided by | |
351efc81 SC |
533 | the user - since an arg test will often fail on the same arg |
534 | again and again, we'll try and test the last failing arg the | |
535 | first on each opcode try */ | |
025b0302 ME |
536 | |
537 | for (n = 0; this_try->arg[n]; n++) | |
538 | { | |
539 | sh_operand_info *user = operands + arg_to_test; | |
540 | sh_arg_type arg = this_try->arg[arg_to_test]; | |
541 | switch (arg) | |
542 | { | |
543 | case A_IMM: | |
544 | case A_BDISP12: | |
545 | case A_BDISP8: | |
546 | case A_DISP_GBR: | |
547 | case A_DISP_PC: | |
548 | case A_MACH: | |
549 | case A_PR: | |
550 | case A_MACL: | |
551 | if (user->type != arg) | |
552 | goto fail; | |
553 | break; | |
554 | case A_R0: | |
555 | /* opcode needs r0 */ | |
556 | if (user->type != A_REG_N || user->reg != 0) | |
557 | goto fail; | |
558 | break; | |
559 | case A_R0_GBR: | |
560 | if (user->type != A_R0_GBR || user->reg != 0) | |
561 | goto fail; | |
562 | break; | |
563 | ||
564 | case A_REG_N: | |
565 | case A_INC_N: | |
566 | case A_DEC_N: | |
567 | case A_IND_N: | |
568 | case A_IND_R0_REG_N: | |
569 | case A_DISP_REG_N: | |
570 | /* Opcode needs rn */ | |
571 | if (user->type != arg) | |
572 | goto fail; | |
573 | reg_n = user->reg; | |
574 | break; | |
575 | case A_GBR: | |
576 | case A_SR: | |
577 | case A_VBR: | |
578 | if (user->type != arg) | |
579 | goto fail; | |
580 | break; | |
581 | ||
582 | case A_REG_M: | |
583 | case A_INC_M: | |
584 | case A_DEC_M: | |
585 | case A_IND_M: | |
586 | case A_IND_R0_REG_M: | |
587 | case A_DISP_REG_M: | |
588 | /* Opcode needs rn */ | |
589 | if (user->type != arg - A_REG_M + A_REG_N) | |
590 | goto fail; | |
591 | reg_m = user->reg; | |
592 | break; | |
593 | default: | |
594 | printf ("unhandled %d\n", arg); | |
595 | goto fail; | |
596 | } | |
597 | /* If we did 0, test 1 next, else 0 */ | |
598 | arg_to_test = 1 - arg_to_test; | |
599 | } | |
600 | return this_try; | |
601 | fail:; | |
602 | } | |
603 | ||
604 | return 0; | |
605 | } | |
606 | ||
607 | int | |
608 | check (operand, low, high) | |
609 | expressionS *operand; | |
610 | int low; | |
611 | int high; | |
612 | { | |
351efc81 | 613 | if (operand->X_op != O_constant |
025b0302 ME |
614 | || operand->X_add_number < low |
615 | || operand->X_add_number > high) | |
616 | { | |
617 | as_bad ("operand must be absolute in range %d..%d", low, high); | |
618 | } | |
619 | return operand->X_add_number; | |
620 | } | |
621 | ||
622 | ||
623 | static void | |
624 | insert (where, how, pcrel) | |
625 | char *where; | |
626 | int how; | |
627 | int pcrel; | |
628 | { | |
351efc81 SC |
629 | fix_new_exp (frag_now, |
630 | where - frag_now->fr_literal, | |
631 | 4, | |
632 | &immediate, | |
633 | pcrel, | |
634 | how); | |
025b0302 ME |
635 | |
636 | } | |
637 | ||
638 | static void | |
639 | build_relax (opcode) | |
640 | sh_opcode_info *opcode; | |
641 | { | |
642 | int len; | |
d6905776 | 643 | int high_byte = shl ? 1 : 0 ; |
025b0302 | 644 | char *p; |
d6905776 | 645 | |
025b0302 ME |
646 | if (opcode->arg[0] == A_BDISP8) |
647 | { | |
648 | p = frag_var (rs_machine_dependent, | |
649 | md_relax_table[C (COND_JUMP, COND32)].rlx_length, | |
650 | len = md_relax_table[C (COND_JUMP, COND8)].rlx_length, | |
651 | C (COND_JUMP, 0), | |
652 | immediate.X_add_symbol, | |
653 | immediate.X_add_number, | |
654 | 0); | |
d6905776 | 655 | p[high_byte] = (opcode->nibbles[0] << 4) | (opcode->nibbles[1]); |
025b0302 ME |
656 | } |
657 | else if (opcode->arg[0] == A_BDISP12) | |
658 | { | |
659 | p = frag_var (rs_machine_dependent, | |
660 | md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length, | |
d6905776 | 661 | len = md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length, |
025b0302 ME |
662 | C (UNCOND_JUMP, 0), |
663 | immediate.X_add_symbol, | |
664 | immediate.X_add_number, | |
665 | 0); | |
d6905776 | 666 | p[high_byte] = (opcode->nibbles[0] << 4); |
025b0302 ME |
667 | } |
668 | ||
669 | } | |
670 | ||
671 | /* Now we know what sort of opcodes it is, lets build the bytes - | |
672 | */ | |
673 | static void | |
674 | build_Mytes (opcode, operand) | |
675 | sh_opcode_info *opcode; | |
676 | sh_operand_info *operand; | |
677 | ||
678 | { | |
679 | int index; | |
680 | char nbuf[4]; | |
681 | char *output = frag_more (2); | |
d6905776 | 682 | int low_byte = shl ? 0 : 1; |
025b0302 ME |
683 | nbuf[0] = 0; |
684 | nbuf[1] = 0; | |
685 | nbuf[2] = 0; | |
686 | nbuf[3] = 0; | |
687 | ||
688 | for (index = 0; index < 4; index++) | |
689 | { | |
690 | sh_nibble_type i = opcode->nibbles[index]; | |
691 | if (i < 16) | |
692 | { | |
693 | nbuf[index] = i; | |
694 | } | |
695 | else | |
696 | { | |
697 | switch (i) | |
698 | { | |
699 | case REG_N: | |
700 | nbuf[index] = reg_n; | |
701 | break; | |
702 | case REG_M: | |
703 | nbuf[index] = reg_m; | |
704 | break; | |
705 | case DISP_4: | |
d6905776 | 706 | insert (output + low_byte, R_SH_IMM4, 0); |
025b0302 ME |
707 | break; |
708 | case IMM_4BY4: | |
d6905776 | 709 | insert (output + low_byte, R_SH_IMM4BY4, 0); |
025b0302 ME |
710 | break; |
711 | case IMM_4BY2: | |
d6905776 | 712 | insert (output + low_byte, R_SH_IMM4BY2, 0); |
025b0302 ME |
713 | break; |
714 | case IMM_4: | |
d6905776 | 715 | insert (output + low_byte, R_SH_IMM4, 0); |
025b0302 ME |
716 | break; |
717 | case IMM_8BY4: | |
d6905776 | 718 | insert (output + low_byte, R_SH_IMM8BY4, 0); |
025b0302 ME |
719 | break; |
720 | case IMM_8BY2: | |
d6905776 | 721 | insert (output + low_byte, R_SH_IMM8BY2, 0); |
025b0302 ME |
722 | break; |
723 | case IMM_8: | |
d6905776 | 724 | insert (output + low_byte, R_SH_IMM8, 0); |
025b0302 ME |
725 | break; |
726 | case PCRELIMM_8BY4: | |
d6905776 | 727 | insert (output, R_SH_PCRELIMM8BY4, 1); |
025b0302 ME |
728 | break; |
729 | case PCRELIMM_8BY2: | |
d6905776 | 730 | insert (output, R_SH_PCRELIMM8BY2, 1); |
025b0302 ME |
731 | break; |
732 | default: | |
733 | printf ("failed for %d\n", i); | |
734 | } | |
735 | } | |
736 | } | |
d6905776 KR |
737 | if (shl) { |
738 | output[1] = (nbuf[0] << 4) | (nbuf[1]); | |
739 | output[0] = (nbuf[2] << 4) | (nbuf[3]); | |
740 | } | |
741 | else { | |
742 | output[0] = (nbuf[0] << 4) | (nbuf[1]); | |
743 | output[1] = (nbuf[2] << 4) | (nbuf[3]); | |
744 | } | |
025b0302 ME |
745 | } |
746 | ||
747 | /* This is the guts of the machine-dependent assembler. STR points to a | |
748 | machine dependent instruction. This function is supposed to emit | |
749 | the frags/bytes it assembles to. | |
351efc81 | 750 | */ |
025b0302 ME |
751 | |
752 | void | |
753 | md_assemble (str) | |
754 | char *str; | |
755 | { | |
756 | unsigned char *op_start; | |
757 | unsigned char *op_end; | |
758 | sh_operand_info operand[2]; | |
759 | sh_opcode_info *opcode; | |
351efc81 | 760 | char name[20]; |
025b0302 | 761 | int nlen = 0; |
025b0302 ME |
762 | /* Drop leading whitespace */ |
763 | while (*str == ' ') | |
764 | str++; | |
765 | ||
766 | /* find the op code end */ | |
351efc81 SC |
767 | for (op_start = op_end = (unsigned char *) (str); |
768 | *op_end | |
769 | && nlen < 20 | |
770 | && !is_end_of_line[*op_end] && *op_end != ' '; | |
025b0302 ME |
771 | op_end++) |
772 | { | |
351efc81 | 773 | name[nlen] = op_start[nlen]; |
025b0302 ME |
774 | nlen++; |
775 | } | |
776 | name[nlen] = 0; | |
777 | ||
351efc81 | 778 | if (nlen == 0) |
025b0302 ME |
779 | { |
780 | as_bad ("can't find opcode "); | |
781 | } | |
782 | ||
783 | opcode = (sh_opcode_info *) hash_find (opcode_hash_control, name); | |
784 | ||
785 | if (opcode == NULL) | |
786 | { | |
787 | as_bad ("unknown opcode"); | |
788 | return; | |
789 | } | |
790 | ||
791 | if (opcode->arg[0] == A_BDISP12 | |
792 | || opcode->arg[0] == A_BDISP8) | |
793 | { | |
351efc81 | 794 | parse_exp (op_end + 1); |
025b0302 ME |
795 | build_relax (opcode); |
796 | } | |
797 | else | |
798 | { | |
351efc81 SC |
799 | if (opcode->arg[0] != A_END) |
800 | { | |
801 | get_operands (opcode, op_end, operand); | |
802 | } | |
025b0302 ME |
803 | opcode = get_specific (opcode, operand); |
804 | ||
805 | if (opcode == 0) | |
806 | { | |
807 | /* Couldn't find an opcode which matched the operands */ | |
808 | char *where = frag_more (2); | |
809 | ||
810 | where[0] = 0x0; | |
811 | where[1] = 0x0; | |
812 | as_bad ("invalid operands for opcode"); | |
813 | return; | |
814 | } | |
815 | ||
816 | build_Mytes (opcode, operand); | |
817 | } | |
818 | ||
819 | } | |
820 | ||
821 | void | |
822 | DEFUN (tc_crawl_symbol_chain, (headers), | |
823 | object_headers * headers) | |
824 | { | |
825 | printf ("call to tc_crawl_symbol_chain \n"); | |
826 | } | |
827 | ||
828 | symbolS * | |
829 | DEFUN (md_undefined_symbol, (name), | |
830 | char *name) | |
831 | { | |
832 | return 0; | |
833 | } | |
834 | ||
835 | void | |
836 | DEFUN (tc_headers_hook, (headers), | |
837 | object_headers * headers) | |
838 | { | |
839 | printf ("call to tc_headers_hook \n"); | |
840 | } | |
841 | ||
025b0302 ME |
842 | /* Various routines to kill one day */ |
843 | /* Equal to MAX_PRECISION in atof-ieee.c */ | |
844 | #define MAX_LITTLENUMS 6 | |
845 | ||
846 | /* Turn a string in input_line_pointer into a floating point constant of type | |
847 | type, and store the appropriate bytes in *litP. The number of LITTLENUMS | |
848 | emitted is stored in *sizeP . An error message is returned, or NULL on OK. | |
351efc81 | 849 | */ |
025b0302 ME |
850 | char * |
851 | md_atof (type, litP, sizeP) | |
d6905776 | 852 | int type; |
025b0302 ME |
853 | char *litP; |
854 | int *sizeP; | |
855 | { | |
856 | int prec; | |
d6905776 | 857 | LITTLENUM_TYPE words[4]; |
025b0302 | 858 | char *t; |
d6905776 | 859 | int i; |
025b0302 ME |
860 | |
861 | switch (type) | |
862 | { | |
863 | case 'f': | |
025b0302 ME |
864 | prec = 2; |
865 | break; | |
866 | ||
867 | case 'd': | |
025b0302 ME |
868 | prec = 4; |
869 | break; | |
870 | ||
025b0302 ME |
871 | default: |
872 | *sizeP = 0; | |
d6905776 | 873 | return "bad call to md_atof"; |
025b0302 | 874 | } |
d6905776 | 875 | |
025b0302 ME |
876 | t = atof_ieee (input_line_pointer, type, words); |
877 | if (t) | |
878 | input_line_pointer = t; | |
879 | ||
d6905776 KR |
880 | *sizeP = prec * 2; |
881 | ||
882 | if (shl) | |
025b0302 | 883 | { |
d6905776 KR |
884 | for (i = prec - 1; i >= 0; i--) |
885 | { | |
886 | md_number_to_chars (litP, (valueT) words[i], 2); | |
887 | litP += 2; | |
888 | } | |
025b0302 | 889 | } |
d6905776 KR |
890 | else |
891 | { | |
892 | for (i = 0; i < prec; i++) | |
893 | { | |
894 | md_number_to_chars (litP, (valueT) words[i], 2); | |
895 | litP += 2; | |
896 | } | |
897 | } | |
898 | ||
899 | return NULL; | |
025b0302 | 900 | } |
d6905776 KR |
901 | |
902 | ||
351efc81 SC |
903 | \f |
904 | CONST char *md_shortopts = ""; | |
905 | struct option md_longopts[] = { | |
d6905776 KR |
906 | |
907 | #define OPTION_RELAX (OPTION_MD_BASE) | |
908 | #define OPTION_LITTLE (OPTION_MD_BASE+1) | |
909 | ||
351efc81 | 910 | {"relax", no_argument, NULL, OPTION_RELAX}, |
d6905776 | 911 | {"little", no_argument, NULL, OPTION_LITTLE}, |
351efc81 SC |
912 | {NULL, no_argument, NULL, 0} |
913 | }; | |
914 | size_t md_longopts_size = sizeof(md_longopts); | |
025b0302 ME |
915 | |
916 | int | |
351efc81 SC |
917 | md_parse_option (c, arg) |
918 | int c; | |
919 | char *arg; | |
025b0302 | 920 | { |
351efc81 | 921 | switch (c) |
025b0302 | 922 | { |
351efc81 | 923 | case OPTION_RELAX: |
025b0302 | 924 | relax = 1; |
351efc81 | 925 | break; |
d6905776 KR |
926 | case OPTION_LITTLE: |
927 | shl = 1; | |
928 | break; | |
351efc81 SC |
929 | |
930 | default: | |
931 | return 0; | |
025b0302 | 932 | } |
351efc81 | 933 | |
025b0302 ME |
934 | return 1; |
935 | } | |
936 | ||
351efc81 SC |
937 | void |
938 | md_show_usage (stream) | |
939 | FILE *stream; | |
940 | { | |
941 | fprintf(stream, "\ | |
942 | SH options:\n\ | |
943 | -relax alter jump instructions for long displacements\n"); | |
944 | } | |
945 | \f | |
025b0302 ME |
946 | int md_short_jump_size; |
947 | ||
948 | void | |
949 | tc_Nout_fix_to_chars () | |
950 | { | |
951 | printf ("call to tc_Nout_fix_to_chars \n"); | |
952 | abort (); | |
953 | } | |
954 | ||
955 | void | |
956 | md_create_short_jump (ptr, from_Nddr, to_Nddr, frag, to_symbol) | |
957 | char *ptr; | |
958 | addressT from_Nddr; | |
959 | addressT to_Nddr; | |
960 | fragS *frag; | |
961 | symbolS *to_symbol; | |
962 | { | |
963 | as_fatal ("failed sanity check."); | |
964 | } | |
965 | ||
966 | void | |
967 | md_create_long_jump (ptr, from_Nddr, to_Nddr, frag, to_symbol) | |
968 | char *ptr; | |
969 | addressT from_Nddr, to_Nddr; | |
970 | fragS *frag; | |
971 | symbolS *to_symbol; | |
972 | { | |
973 | as_fatal ("failed sanity check."); | |
974 | } | |
975 | ||
976 | /* | |
351efc81 SC |
977 | called after relaxing, change the frags so they know how big they are |
978 | */ | |
025b0302 ME |
979 | void |
980 | md_convert_frag (headers, fragP) | |
981 | object_headers *headers; | |
982 | fragS *fragP; | |
983 | ||
984 | { | |
985 | unsigned char *buffer = (unsigned char *) (fragP->fr_fix + fragP->fr_literal); | |
986 | int donerelax = 0; | |
d6905776 KR |
987 | int highbyte = shl ? 1 : 0; |
988 | int lowbyte = shl ? 0 : 1; | |
025b0302 ME |
989 | int targ_addr = ((fragP->fr_symbol ? S_GET_VALUE (fragP->fr_symbol) : 0) + fragP->fr_offset); |
990 | switch (fragP->fr_subtype) | |
991 | { | |
992 | case C (COND_JUMP, COND8): | |
993 | { | |
994 | /* Get the address of the end of the instruction */ | |
995 | int next_inst = fragP->fr_fix + fragP->fr_address + 2; | |
996 | ||
997 | int disp = targ_addr - next_inst - 2; | |
998 | disp /= 2; | |
351efc81 | 999 | |
d6905776 | 1000 | md_number_to_chars (buffer + lowbyte, disp & 0xff, 1); |
025b0302 ME |
1001 | fragP->fr_fix += 2; |
1002 | fragP->fr_var = 0; | |
1003 | } | |
1004 | break; | |
1005 | ||
1006 | case C (UNCOND_JUMP, UNCOND12): | |
1007 | { | |
1008 | /* Get the address of the end of the instruction */ | |
1009 | int next_inst = fragP->fr_fix + fragP->fr_address + 2; | |
1010 | ||
1011 | int t; | |
1012 | int disp = targ_addr - next_inst - 2; | |
1013 | ||
1014 | disp /= 2; | |
d6905776 | 1015 | t = buffer[highbyte] & 0xf0; |
351efc81 | 1016 | md_number_to_chars (buffer, disp & 0xfff, 2); |
d6905776 | 1017 | buffer[highbyte] = (buffer[highbyte] & 0xf) | t; |
025b0302 ME |
1018 | fragP->fr_fix += 2; |
1019 | fragP->fr_var = 0; | |
1020 | } | |
1021 | break; | |
1022 | ||
1023 | case C (UNCOND_JUMP, UNCOND32): | |
1024 | case C (UNCOND_JUMP, UNDEF_WORD_DISP): | |
1025 | { | |
1026 | /* A jump wont fit in 12 bits, make code which looks like | |
1027 | bra foo | |
1028 | mov.w @(0, PC), r14 | |
1029 | .long disp | |
1030 | foo: bra @r14 | |
351efc81 | 1031 | */ |
025b0302 ME |
1032 | |
1033 | int next_inst = | |
1034 | fragP->fr_fix + fragP->fr_address + UNCOND32_LENGTH; | |
1035 | ||
1036 | int disp = targ_addr - next_inst; | |
1037 | int t = buffer[0] & 0x10; | |
1038 | ||
1039 | disp /= 2; | |
d6905776 KR |
1040 | abort(); |
1041 | buffer[highbyte] = 0xa0; /* branch over move and disp */ | |
1042 | buffer[lowbyte] = 3; | |
1043 | buffer[highbyte+2] = 0xd0 | JREG; /* Build mov insn */ | |
1044 | buffer[lowbyte+2] = 0x00; | |
025b0302 | 1045 | |
d6905776 KR |
1046 | buffer[highbyte+4] = 0; /* space for 32 bit jump disp */ |
1047 | buffer[lowbyte+4] = 0; | |
1048 | buffer[highbyte+6] = 0; | |
1049 | buffer[lowbyte+6] = 0; | |
025b0302 | 1050 | |
d6905776 KR |
1051 | buffer[highbyte+8] = 0x40 | JREG; /* Build jmp @JREG */ |
1052 | buffer[lowbyte+8] = t ? 0xb : 0x2b; | |
025b0302 | 1053 | |
d6905776 KR |
1054 | buffer[highbyte+10] = 0x20; /* build nop */ |
1055 | buffer[lowbyte+10] = 0x0b; | |
025b0302 ME |
1056 | |
1057 | /* Make reloc for the long disp */ | |
1058 | fix_new (fragP, | |
1059 | fragP->fr_fix + 4, | |
1060 | 4, | |
1061 | fragP->fr_symbol, | |
025b0302 ME |
1062 | fragP->fr_offset, |
1063 | 0, | |
1064 | R_SH_IMM32); | |
1065 | fragP->fr_fix += UNCOND32_LENGTH; | |
1066 | fragP->fr_var = 0; | |
1067 | donerelax = 1; | |
1068 | ||
1069 | } | |
1070 | break; | |
1071 | ||
1072 | case C (COND_JUMP, COND12): | |
1073 | { | |
1074 | /* A bcond won't fit, so turn it into a b!cond; bra disp; nop */ | |
1075 | int next_inst = | |
1076 | fragP->fr_fix + fragP->fr_address + 6; | |
1077 | ||
1078 | int disp = targ_addr - next_inst; | |
1079 | disp /= 2; | |
351efc81 | 1080 | md_number_to_chars (buffer + 2, disp & 0xfff, 2); |
d6905776 KR |
1081 | buffer[highbyte] ^= 0x2; /* Toggle T/F bit */ |
1082 | buffer[lowbyte] = 1; /* branch over jump and nop */ | |
1083 | buffer[highbyte+2] = (buffer[highbyte+2] & 0xf) | 0xa0; /* Build jump insn */ | |
1084 | buffer[lowbyte+5] = 0x20; /* Build nop */ | |
1085 | buffer[lowbyte+5] = 0x0b; | |
025b0302 ME |
1086 | fragP->fr_fix += 6; |
1087 | fragP->fr_var = 0; | |
1088 | donerelax = 1; | |
1089 | } | |
1090 | break; | |
1091 | ||
1092 | case C (COND_JUMP, COND32): | |
1093 | case C (COND_JUMP, UNDEF_WORD_DISP): | |
1094 | { | |
1095 | /* A bcond won't fit and it won't go into a 12 bit | |
1096 | displacement either, the code sequence looks like: | |
1097 | b!cond foop | |
1098 | mov.w @(n, PC), r14 | |
351efc81 | 1099 | jmp @r14 |
025b0302 ME |
1100 | nop |
1101 | .long where | |
1102 | foop: | |
351efc81 | 1103 | */ |
025b0302 ME |
1104 | |
1105 | int next_inst = | |
1106 | fragP->fr_fix + fragP->fr_address + COND32_LENGTH; | |
1107 | ||
1108 | int disp = targ_addr - next_inst; | |
1109 | disp /= 2; | |
d6905776 | 1110 | abort(); |
025b0302 ME |
1111 | buffer[0] ^= 0x2; /* Toggle T/F bit */ |
1112 | #define JREG 14 | |
1113 | buffer[1] = 5; /* branch over mov, jump, nop and ptr */ | |
351efc81 | 1114 | buffer[2] = 0xd0 | JREG; /* Build mov insn */ |
025b0302 | 1115 | buffer[3] = 0x2; |
351efc81 | 1116 | buffer[4] = 0x40 | JREG; /* Build jmp @JREG */ |
025b0302 ME |
1117 | buffer[5] = 0x0b; |
1118 | buffer[6] = 0x20; /* build nop */ | |
1119 | buffer[7] = 0x0b; | |
1120 | buffer[8] = 0; /* space for 32 bit jump disp */ | |
1121 | buffer[9] = 0; | |
1122 | buffer[10] = 0; | |
1123 | buffer[11] = 0; | |
1124 | buffer[12] = 0; | |
1125 | buffer[13] = 0; | |
1126 | /* Make reloc for the long disp */ | |
1127 | fix_new (fragP, | |
1128 | fragP->fr_fix + 8, | |
1129 | 4, | |
1130 | fragP->fr_symbol, | |
025b0302 ME |
1131 | fragP->fr_offset, |
1132 | 0, | |
1133 | R_SH_IMM32); | |
1134 | fragP->fr_fix += COND32_LENGTH; | |
1135 | fragP->fr_var = 0; | |
1136 | donerelax = 1; | |
1137 | } | |
1138 | break; | |
1139 | ||
1140 | default: | |
1141 | abort (); | |
1142 | } | |
1143 | ||
1144 | if (donerelax && !relax) | |
1145 | { | |
9cc7c60b ILT |
1146 | as_warn ("Offset doesn't fit at 0x%lx, trying to get to %s+0x%x", |
1147 | (unsigned long) fragP->fr_address, | |
351efc81 SC |
1148 | fragP->fr_symbol ? S_GET_NAME(fragP->fr_symbol): "", |
1149 | targ_addr); | |
025b0302 ME |
1150 | } |
1151 | ||
1152 | } | |
1153 | ||
1154 | valueT | |
1155 | DEFUN (md_section_align, (seg, size), | |
1156 | segT seg AND | |
1157 | valueT size) | |
1158 | { | |
1159 | return ((size + (1 << section_alignment[(int) seg]) - 1) | |
1160 | & (-1 << section_alignment[(int) seg])); | |
1161 | ||
1162 | } | |
1163 | ||
1164 | void | |
1165 | md_apply_fix (fixP, val) | |
1166 | fixS *fixP; | |
1167 | long val; | |
1168 | { | |
1169 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
1170 | int addr = fixP->fx_frag->fr_address + fixP->fx_where; | |
d6905776 | 1171 | int lowbyte = shl ? 0 : 1; |
025b0302 ME |
1172 | if (fixP->fx_r_type == 0) |
1173 | { | |
351efc81 SC |
1174 | if (fixP->fx_size == 2) |
1175 | fixP->fx_r_type = R_SH_IMM16; | |
1176 | else | |
1177 | fixP->fx_r_type = R_SH_IMM32; | |
025b0302 ME |
1178 | } |
1179 | ||
1180 | switch (fixP->fx_r_type) | |
1181 | { | |
1182 | ||
1183 | case R_SH_IMM4: | |
1184 | *buf = (*buf & 0xf0) | (val & 0xf); | |
1185 | break; | |
1186 | ||
1187 | case R_SH_IMM4BY2: | |
1188 | *buf = (*buf & 0xf0) | ((val >> 1) & 0xf); | |
1189 | break; | |
1190 | ||
1191 | case R_SH_IMM4BY4: | |
1192 | *buf = (*buf & 0xf0) | ((val >> 2) & 0xf); | |
1193 | break; | |
1194 | ||
1195 | case R_SH_IMM8BY2: | |
1196 | *buf = val >> 1; | |
1197 | break; | |
1198 | ||
1199 | case R_SH_IMM8BY4: | |
1200 | *buf = val >> 2; | |
1201 | break; | |
1202 | ||
1203 | case R_SH_IMM8: | |
1204 | *buf++ = val; | |
1205 | break; | |
1206 | ||
1207 | case R_SH_PCRELIMM8BY4: | |
1208 | addr &= ~1; | |
351efc81 | 1209 | #if 0 |
025b0302 ME |
1210 | if (val & 0x3) |
1211 | as_warn ("non aligned displacement at %x\n", addr); | |
351efc81 SC |
1212 | #endif |
1213 | /* val -= (addr + 4); */ | |
d6905776 KR |
1214 | if (shl||1) |
1215 | val += 1; | |
1216 | else | |
1217 | val += 3; | |
025b0302 ME |
1218 | val /= 4; |
1219 | if (val & ~0xff) | |
9cc7c60b | 1220 | as_warn_where (fixP->fx_file, fixP->fx_line, "pcrel too far"); |
d6905776 | 1221 | buf[lowbyte] = val; |
025b0302 ME |
1222 | break; |
1223 | ||
1224 | case R_SH_PCRELIMM8BY2: | |
1225 | addr &= ~1; | |
d6905776 KR |
1226 | /* if ((val & 0x1) != shl) |
1227 | as_bad ("odd displacement at %x\n", addr);*/ | |
351efc81 | 1228 | /* val -= (addr + 4); */ |
d6905776 KR |
1229 | /* if (!shl) |
1230 | val++;*/ | |
025b0302 ME |
1231 | val /= 2; |
1232 | if (val & ~0xff) | |
9cc7c60b | 1233 | as_warn_where (fixP->fx_file, fixP->fx_line, "pcrel too far"); |
d6905776 | 1234 | buf[lowbyte] = val; |
025b0302 ME |
1235 | break; |
1236 | ||
1237 | case R_SH_IMM32: | |
d6905776 KR |
1238 | if (shl) |
1239 | { | |
1240 | *buf++ = val >> 0; | |
1241 | *buf++ = val >> 8; | |
1242 | *buf++ = val >> 16; | |
1243 | *buf++ = val >> 24; | |
1244 | } | |
1245 | else | |
1246 | { | |
1247 | *buf++ = val >> 24; | |
1248 | *buf++ = val >> 16; | |
1249 | *buf++ = val >> 8; | |
1250 | *buf++ = val >> 0; | |
1251 | } | |
025b0302 ME |
1252 | break; |
1253 | ||
351efc81 | 1254 | case R_SH_IMM16: |
d6905776 KR |
1255 | if (shl) |
1256 | { | |
1257 | *buf++ = val >> 0; | |
1258 | *buf++ = val >> 8; | |
1259 | } | |
1260 | else | |
1261 | { | |
1262 | *buf++ = val >> 8; | |
1263 | *buf++ = val >> 0; | |
1264 | } | |
351efc81 SC |
1265 | break; |
1266 | ||
025b0302 ME |
1267 | default: |
1268 | abort (); | |
1269 | } | |
1270 | } | |
1271 | ||
1272 | void | |
1273 | DEFUN (md_operand, (expressionP), expressionS * expressionP) | |
1274 | { | |
1275 | } | |
1276 | ||
1277 | int md_long_jump_size; | |
1278 | ||
1279 | /* | |
351efc81 SC |
1280 | called just before address relaxation, return the length |
1281 | by which a fragment must grow to reach it's destination | |
1282 | */ | |
025b0302 ME |
1283 | int |
1284 | md_estimate_size_before_relax (fragP, segment_type) | |
1285 | register fragS *fragP; | |
1286 | register segT segment_type; | |
1287 | { | |
1288 | switch (fragP->fr_subtype) | |
1289 | { | |
1290 | case C (UNCOND_JUMP, UNDEF_DISP): | |
1291 | /* used to be a branch to somewhere which was unknown */ | |
1292 | if (!fragP->fr_symbol) | |
1293 | { | |
1294 | fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12); | |
1295 | fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length; | |
1296 | } | |
1297 | else if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type) | |
1298 | { | |
1299 | fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12); | |
1300 | fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length; | |
1301 | } | |
1302 | else | |
1303 | { | |
1304 | fragP->fr_subtype = C (UNCOND_JUMP, UNDEF_WORD_DISP); | |
1305 | fragP->fr_var = md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length; | |
1306 | return md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length; | |
1307 | } | |
1308 | break; | |
1309 | ||
1310 | default: | |
1311 | abort (); | |
1312 | case C (COND_JUMP, UNDEF_DISP): | |
1313 | /* used to be a branch to somewhere which was unknown */ | |
1314 | if (fragP->fr_symbol | |
1315 | && S_GET_SEGMENT (fragP->fr_symbol) == segment_type) | |
1316 | { | |
1317 | /* Got a symbol and it's defined in this segment, become byte | |
351efc81 | 1318 | sized - maybe it will fix up */ |
025b0302 ME |
1319 | fragP->fr_subtype = C (COND_JUMP, COND8); |
1320 | fragP->fr_var = md_relax_table[C (COND_JUMP, COND8)].rlx_length; | |
1321 | } | |
1322 | else if (fragP->fr_symbol) | |
1323 | { | |
1324 | /* Its got a segment, but its not ours, so it will always be long */ | |
1325 | fragP->fr_subtype = C (COND_JUMP, UNDEF_WORD_DISP); | |
1326 | fragP->fr_var = md_relax_table[C (COND_JUMP, COND32)].rlx_length; | |
1327 | return md_relax_table[C (COND_JUMP, COND32)].rlx_length; | |
1328 | } | |
1329 | else | |
1330 | { | |
1331 | /* We know the abs value */ | |
1332 | fragP->fr_subtype = C (COND_JUMP, COND8); | |
1333 | fragP->fr_var = md_relax_table[C (COND_JUMP, COND8)].rlx_length; | |
1334 | } | |
1335 | ||
1336 | break; | |
1337 | } | |
1338 | return fragP->fr_var; | |
1339 | } | |
1340 | ||
1341 | /* Put number into target byte order */ | |
1342 | ||
1343 | void | |
1344 | md_number_to_chars (ptr, use, nbytes) | |
1345 | char *ptr; | |
1346 | valueT use; | |
1347 | int nbytes; | |
1348 | { | |
d6905776 KR |
1349 | if (shl) |
1350 | number_to_chars_littleendian (ptr, use, nbytes); | |
1351 | else | |
1352 | number_to_chars_bigendian (ptr, use, nbytes); | |
025b0302 | 1353 | } |
351efc81 | 1354 | |
025b0302 ME |
1355 | long |
1356 | md_pcrel_from (fixP) | |
1357 | fixS *fixP; | |
025b0302 | 1358 | { |
351efc81 | 1359 | int gap = fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address - 1 ; |
025b0302 ME |
1360 | return gap; |
1361 | } | |
1362 | ||
025b0302 ME |
1363 | short |
1364 | tc_coff_fix2rtype (fix_ptr) | |
1365 | fixS *fix_ptr; | |
1366 | { | |
025b0302 ME |
1367 | if (fix_ptr->fx_r_type == RELOC_32) |
1368 | { | |
1369 | /* cons likes to create reloc32's whatever the size of the reloc.. | |
1370 | */ | |
1371 | switch (fix_ptr->fx_size) | |
1372 | { | |
1373 | case 2: | |
d6905776 | 1374 | return R_SH_IMM16; |
025b0302 ME |
1375 | break; |
1376 | case 1: | |
d6905776 | 1377 | return R_SH_IMM8; |
025b0302 ME |
1378 | break; |
1379 | default: | |
1380 | abort (); | |
1381 | } | |
1382 | } | |
d6905776 | 1383 | return R_SH_IMM32; |
025b0302 ME |
1384 | } |
1385 | ||
1386 | int | |
1387 | tc_coff_sizemachdep (frag) | |
1388 | fragS *frag; | |
1389 | { | |
1390 | return md_relax_table[frag->fr_subtype].rlx_length; | |
1391 | } |