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