1 /* This file is tc-tahoe.c
3 Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1995, 2000, 2001
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "safe-ctype.h"
26 /* This bit glommed from tahoe-inst.h. */
28 typedef unsigned char byte
;
29 typedef byte tahoe_opcodeT
;
31 /* This is part of tahoe-ins-parse.c & friends.
32 We want to parse a tahoe instruction text into a tree defined here. */
34 #define TIT_MAX_OPERANDS (4) /* maximum number of operands in one
35 single tahoe instruction */
37 struct top
/* tahoe instruction operand */
39 int top_ndx
; /* -1, or index register. eg 7=[R7] */
40 int top_reg
; /* -1, or register number. eg 7 = R7 or (R7) */
41 byte top_mode
; /* Addressing mode byte. This byte, defines
42 which of the 11 modes opcode is. */
44 char top_access
; /* Access type wanted for this opperand
45 'b'branch ' 'no-instruction 'amrvw' */
46 char top_width
; /* Operand width expected, one of "bwlq?-:!" */
48 char * top_error
; /* Say if operand is inappropriate */
50 segT seg_of_operand
; /* segment as returned by expression()*/
52 expressionS exp_of_operand
; /* The expression as parsed by expression()*/
54 byte top_dispsize
; /* Number of bytes in the displacement if we
58 /* The addressing modes for an operand. These numbers are the acutal values
59 for certain modes, so be carefull if you screw with them. */
60 #define TAHOE_DIRECT_REG (0x50)
61 #define TAHOE_REG_DEFERRED (0x60)
63 #define TAHOE_REG_DISP (0xE0)
64 #define TAHOE_REG_DISP_DEFERRED (0xF0)
66 #define TAHOE_IMMEDIATE (0x8F)
67 #define TAHOE_IMMEDIATE_BYTE (0x88)
68 #define TAHOE_IMMEDIATE_WORD (0x89)
69 #define TAHOE_IMMEDIATE_LONGWORD (0x8F)
70 #define TAHOE_ABSOLUTE_ADDR (0x9F)
72 #define TAHOE_DISPLACED_RELATIVE (0xEF)
73 #define TAHOE_DISP_REL_DEFERRED (0xFF)
75 #define TAHOE_AUTO_DEC (0x7E)
76 #define TAHOE_AUTO_INC (0x8E)
77 #define TAHOE_AUTO_INC_DEFERRED (0x9E)
78 /* INDEXED_REG is decided by the existance or lack of a [reg]. */
80 /* These are encoded into top_width when top_access=='b'
81 and it's a psuedo op. */
82 #define TAHOE_WIDTH_ALWAYS_JUMP '-'
83 #define TAHOE_WIDTH_CONDITIONAL_JUMP '?'
84 #define TAHOE_WIDTH_BIG_REV_JUMP '!'
85 #define TAHOE_WIDTH_BIG_NON_REV_JUMP ':'
87 /* The hex code for certain tahoe commands and modes.
88 This is just for readability. */
89 #define TAHOE_JMP (0x71)
90 #define TAHOE_PC_REL_LONG (0xEF)
91 #define TAHOE_BRB (0x11)
92 #define TAHOE_BRW (0x13)
93 /* These, when 'ored' with, or added to, a register number,
94 set up the number for the displacement mode. */
95 #define TAHOE_PC_OR_BYTE (0xA0)
96 #define TAHOE_PC_OR_WORD (0xC0)
97 #define TAHOE_PC_OR_LONG (0xE0)
99 struct tit
/* Get it out of the sewer, it stands for
100 tahoe instruction tree (Geeze!). */
102 tahoe_opcodeT tit_opcode
; /* The opcode. */
103 byte tit_operands
; /* How many operands are here. */
104 struct top tit_operand
[TIT_MAX_OPERANDS
]; /* Operands */
105 char *tit_error
; /* "" or fatal error text */
108 /* end: tahoe-inst.h */
110 /* tahoe.c - tahoe-specific -
114 #include "opcode/tahoe.h"
116 /* This is the number to put at the beginning of the a.out file */
117 long omagic
= OMAGIC
;
119 /* These chars start a comment anywhere in a source file (except inside
120 another comment or a quoted string. */
121 const char comment_chars
[] = "#;";
123 /* These chars only start a comment at the beginning of a line. */
124 const char line_comment_chars
[] = "#";
126 /* Chars that can be used to separate mant from exp in floating point nums */
127 const char EXP_CHARS
[] = "eE";
129 /* Chars that mean this number is a floating point constant
131 or 0d1.234E-12 (see exp chars above)
132 Note: The Tahoe port doesn't support floating point constants. This is
133 consistant with 'as' If it's needed, I can always add it later. */
134 const char FLT_CHARS
[] = "df";
136 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
137 changed in read.c . Ideally it shouldn't have to know about it at all,
138 but nothing is ideal around here.
139 (The tahoe has plenty of room, so the change currently isn't needed.)
142 static struct tit t
; /* A tahoe instruction after decoding. */
145 /* A table of pseudo ops (sans .), the function called, and an integer op
146 that the function is called with. */
148 const pseudo_typeS md_pseudo_table
[] =
150 {"dfloat", float_cons
, 'd'},
151 {"ffloat", float_cons
, 'f'},
156 * For Tahoe, relative addresses of "just the right length" are pretty easy.
157 * The branch displacement is always the last operand, even in
158 * synthetic instructions.
159 * For Tahoe, we encode the relax_substateTs (in e.g. fr_substate) as:
161 * 4 3 2 1 0 bit number
162 * ---/ /--+-------+-------+-------+-------+-------+
163 * | what state ? | how long ? |
164 * ---/ /--+-------+-------+-------+-------+-------+
166 * The "how long" bits are 00=byte, 01=word, 10=long.
167 * This is a Un*x convention.
168 * Not all lengths are legit for a given value of (what state).
169 * The four states are listed below.
170 * The "how long" refers merely to the displacement length.
171 * The address usually has some constant bytes in it as well.
174 States for Tahoe address relaxing.
175 1. TAHOE_WIDTH_ALWAYS_JUMP (-)
177 Tahoe opcodes are: (Hex)
181 Always, 1 byte opcode, then displacement/absolute.
182 If word or longword, change opcode to brw or jmp.
184 2. TAHOE_WIDTH_CONDITIONAL_JUMP (?)
185 J<cond> where <cond> is a simple flag test.
187 Tahoe opcodes are: (Hex)
200 Always, you complement 4th bit to reverse the condition.
201 Always, 1-byte opcode, then 1-byte displacement.
203 3. TAHOE_WIDTH_BIG_REV_JUMP (!)
204 Jbc/Jbs where cond tests a memory bit.
206 Tahoe opcodes are: (Hex)
209 Always, you complement 4th bit to reverse the condition.
210 Always, 1-byte opcde, longword, longword-address, 1-word-displacement
212 4. TAHOE_WIDTH_BIG_NON_REV_JUMP (:)
215 Tahoe opcodes are: (Hex)
221 Always, we cannot reverse the sense of the branch; we have a word
224 We need to modify the opcode is for class 1, 2 and 3 instructions.
225 After relax() we may complement the 4th bit of 2 or 3 to reverse sense of
228 We sometimes store context in the operand literal. This way we can figure out
229 after relax() what the original addressing mode was. (Was is pc_rel, or
230 pc_rel_disp? That sort of thing.) */
232 /* These displacements are relative to the START address of the
233 displacement which is at the start of the displacement, not the end of
234 the instruction. The hardware pc_rel is at the end of the instructions.
235 That's why all the displacements have the length of the displacement added
236 to them. (WF + length(word))
238 The first letter is Byte, Word.
239 2nd letter is Forward, Backward. */
242 #define WF (2+ 32767)
243 #define WB (2+-32768)
244 /* Dont need LF, LB because they always reach. [They are coded as 0.] */
246 #define C(a,b) ENCODE_RELAX(a,b)
247 /* This macro has no side-effects. */
248 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
249 #define RELAX_STATE(s) ((s) >> 2)
250 #define RELAX_LENGTH(s) ((s) & 3)
252 #define STATE_ALWAYS_BRANCH (1)
253 #define STATE_CONDITIONAL_BRANCH (2)
254 #define STATE_BIG_REV_BRANCH (3)
255 #define STATE_BIG_NON_REV_BRANCH (4)
256 #define STATE_PC_RELATIVE (5)
258 #define STATE_BYTE (0)
259 #define STATE_WORD (1)
260 #define STATE_LONG (2)
261 #define STATE_UNDF (3) /* Symbol undefined in pass1 */
263 /* This is the table used by gas to figure out relaxing modes. The fields are
264 forward_branch reach, backward_branch reach, number of bytes it would take,
265 where the next biggest branch is. */
266 const relax_typeS md_relax_table
[] =
270 }, /* error sentinel 0,0 */
280 /* Unconditional branch cases "jrb"
281 The relax part is the actual displacement */
284 }, /* brb B`foo 1,0 */
287 }, /* brw W`foo 1,1 */
290 }, /* Jmp L`foo 1,2 */
294 /* Reversible Conditional Branch. If the branch won't reach, reverse
295 it, and jump over a brw or a jmp that will reach. The relax part is the
299 }, /* b<cond> B`foo 2,0 */
301 WF
+ 2, WB
+ 2, 4, C (2, 2)
302 }, /* brev over, brw W`foo, over: 2,1 */
305 }, /* brev over, jmp L`foo, over: 2,2 */
309 /* Another type of reversable branch. But this only has a word
316 }, /* jbX W`foo 3,1 */
319 }, /* jrevX over, jmp L`foo, over: 3,2 */
323 /* These are the non reversable branches, all of which have a word
324 displacement. If I can't reach, branch over a byte branch, to a
325 jump that will reach. The jumped branch jumps over the reaching
326 branch, to continue with the flow of the program. It's like playing
333 }, /* aobl_ W`foo 4,1 */
336 }, /*aobl_ W`hop,br over,hop: jmp L^foo,over 4,2*/
340 /* Normal displacement mode, no jumping or anything like that.
341 The relax points to one byte before the address, thats why all
342 the numbers are up by one. */
344 BF
+ 1, BB
+ 1, 2, C (5, 1)
347 WF
+ 1, WB
+ 1, 3, C (5, 2)
362 /* End relax stuff */
364 /* Handle of the OPCODE hash table. NULL means any use before
365 md_begin() will crash. */
366 static struct hash_control
*op_hash
;
368 /* Init function. Build the hash table. */
374 int synthetic_too
= 1; /* If 0, just use real opcodes. */
376 op_hash
= hash_new ();
378 for (tP
= totstrs
; *tP
->name
&& !errorval
; tP
++)
379 errorval
= hash_insert (op_hash
, tP
->name
, &tP
->detail
);
382 for (tP
= synthetic_totstrs
; *tP
->name
&& !errorval
; tP
++)
383 errorval
= hash_insert (op_hash
, tP
->name
, &tP
->detail
);
389 CONST
char *md_shortopts
= "ad:STt:V";
390 struct option md_longopts
[] = {
391 {NULL
, no_argument
, NULL
, 0}
393 size_t md_longopts_size
= sizeof (md_longopts
);
396 md_parse_option (c
, arg
)
403 as_warn (_("The -a option doesn't exist. (Despite what the man page says!"));
407 as_warn (_("Displacement length %s ignored!"), arg
);
411 as_warn (_("SYMBOL TABLE not implemented"));
415 as_warn (_("TOKEN TRACE not implemented"));
419 as_warn (_("I don't need or use temp. file \"%s\"."), arg
);
423 as_warn (_("I don't use an interpass file! -V ignored"));
434 md_show_usage (stream
)
437 fprintf (stream
, _("\
448 /* The functions in this section take numbers in the machine format, and
449 munges them into Tahoe byte order.
450 They exist primarily for cross assembly purpose. */
451 void /* Knows about order of bytes in address. */
452 md_number_to_chars (con
, value
, nbytes
)
453 char con
[]; /* Return 'nbytes' of chars here. */
454 valueT value
; /* The value of the bits. */
455 int nbytes
; /* Number of bytes in the output. */
457 number_to_chars_bigendian (con
, value
, nbytes
);
461 void /* Knows about order of bytes in address. */
462 md_number_to_imm (con
, value
, nbytes
)
463 char con
[]; /* Return 'nbytes' of chars here. */
464 long int value
; /* The value of the bits. */
465 int nbytes
; /* Number of bytes in the output. */
467 md_number_to_chars (con
, value
, nbytes
);
473 tc_apply_fix (fixP
, val
)
477 /* should never be called */
481 void /* Knows about order of bytes in address. */
482 md_number_to_disp (con
, value
, nbytes
)
483 char con
[]; /* Return 'nbytes' of chars here. */
484 long int value
; /* The value of the bits. */
485 int nbytes
; /* Number of bytes in the output. */
487 md_number_to_chars (con
, value
, nbytes
);
490 void /* Knows about order of bytes in address. */
491 md_number_to_field (con
, value
, nbytes
)
492 char con
[]; /* Return 'nbytes' of chars here. */
493 long int value
; /* The value of the bits. */
494 int nbytes
; /* Number of bytes in the output. */
496 md_number_to_chars (con
, value
, nbytes
);
499 /* Put the bits in an order that a tahoe will understand, despite the ordering
500 of the native machine.
501 On Tahoe: first 4 bytes are normal unsigned big endian long,
502 next three bytes are symbolnum, in kind of 3 byte big endian (least sig. byte last).
503 The last byte is broken up with bit 7 as pcrel,
504 bits 6 & 5 as length,
505 bit 4 as extern and the last nibble as 'undefined'. */
509 md_ri_to_chars (ri_p
, ri
)
510 struct relocation_info
*ri_p
, ri
;
512 byte the_bytes
[sizeof (struct relocation_info
)];
513 /* The reason I can't just encode these directly into ri_p is that
514 ri_p may point to ri. */
517 md_number_to_chars (the_bytes
, ri
.r_address
, sizeof (ri
.r_address
));
519 /* now the fun stuff */
520 the_bytes
[4] = (ri
.r_symbolnum
>> 16) & 0x0ff;
521 the_bytes
[5] = (ri
.r_symbolnum
>> 8) & 0x0ff;
522 the_bytes
[6] = ri
.r_symbolnum
& 0x0ff;
523 the_bytes
[7] = (((ri
.r_extern
<< 4) & 0x10) | ((ri
.r_length
<< 5) & 0x60) |
524 ((ri
.r_pcrel
<< 7) & 0x80)) & 0xf0;
526 bcopy (the_bytes
, (char *) ri_p
, sizeof (struct relocation_info
));
531 /* Put the bits in an order that a tahoe will understand, despite the ordering
532 of the native machine.
533 On Tahoe: first 4 bytes are normal unsigned big endian long,
534 next three bytes are symbolnum, in kind of 3 byte big endian (least sig. byte last).
535 The last byte is broken up with bit 7 as pcrel,
536 bits 6 & 5 as length,
537 bit 4 as extern and the last nibble as 'undefined'. */
540 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
543 relax_addressT segment_address_in_file
;
547 know (fixP
->fx_addsy
!= NULL
);
549 md_number_to_chars (where
,
550 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
553 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
554 ? S_GET_TYPE (fixP
->fx_addsy
)
555 : fixP
->fx_addsy
->sy_number
);
557 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
558 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
559 where
[6] = r_symbolnum
& 0x0ff;
560 where
[7] = (((is_pcrel (fixP
) << 7) & 0x80)
561 | ((((fixP
->fx_type
== FX_8
|| fixP
->fx_type
== FX_PCREL8
563 : (fixP
->fx_type
== FX_16
|| fixP
->fx_type
== FX_PCREL16
565 : (fixP
->fx_type
== FX_32
|| fixP
->fx_type
== FX_PCREL32
567 : 42)))) << 5) & 0x60)
568 | ((!S_IS_DEFINED (fixP
->fx_addsy
) << 4) & 0x10));
571 /* Relocate byte stuff */
573 /* This is for broken word. */
574 const int md_short_jump_size
= 3;
577 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
579 addressT from_addr
, to_addr
;
585 offset
= to_addr
- (from_addr
+ 1);
587 md_number_to_chars (ptr
, offset
, 2);
590 const int md_long_jump_size
= 6;
591 const int md_reloc_size
= 8; /* Size of relocation record */
594 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
596 addressT from_addr
, to_addr
;
602 offset
= to_addr
- (from_addr
+ 4);
604 *ptr
++ = TAHOE_PC_REL_LONG
;
605 md_number_to_chars (ptr
, offset
, 4);
608 /* md_estimate_size_before_relax(), called just before relax().
609 Any symbol that is now undefined will not become defined.
610 Return the correct fr_subtype in the frag and the growth beyond
613 md_estimate_size_before_relax (fragP
, segment_type
)
614 register fragS
*fragP
;
615 segT segment_type
; /* N_DATA or N_TEXT. */
617 if (RELAX_LENGTH (fragP
->fr_subtype
) == STATE_UNDF
)
619 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
)
621 /* Non-relaxable cases. */
625 old_fr_fix
= fragP
->fr_fix
;
626 p
= fragP
->fr_literal
+ old_fr_fix
;
627 switch (RELAX_STATE (fragP
->fr_subtype
))
629 case STATE_PC_RELATIVE
:
630 *p
|= TAHOE_PC_OR_LONG
;
631 /* We now know how big it will be, one long word. */
632 fragP
->fr_fix
+= 1 + 4;
633 fix_new (fragP
, old_fr_fix
+ 1, fragP
->fr_symbol
,
634 fragP
->fr_offset
, FX_PCREL32
, NULL
);
637 case STATE_CONDITIONAL_BRANCH
:
638 *fragP
->fr_opcode
^= 0x10; /* Reverse sense of branch. */
641 *p
++ = TAHOE_PC_REL_LONG
;
642 fragP
->fr_fix
+= 1 + 1 + 1 + 4;
643 fix_new (fragP
, old_fr_fix
+ 3, fragP
->fr_symbol
,
644 fragP
->fr_offset
, FX_PCREL32
, NULL
);
647 case STATE_BIG_REV_BRANCH
:
648 *fragP
->fr_opcode
^= 0x10; /* Reverse sense of branch. */
652 *p
++ = TAHOE_PC_REL_LONG
;
653 fragP
->fr_fix
+= 2 + 2 + 4;
654 fix_new (fragP
, old_fr_fix
+ 4, fragP
->fr_symbol
,
655 fragP
->fr_offset
, FX_PCREL32
, NULL
);
658 case STATE_BIG_NON_REV_BRANCH
:
664 *p
++ = TAHOE_PC_REL_LONG
;
665 fragP
->fr_fix
+= 2 + 2 + 2 + 4;
666 fix_new (fragP
, old_fr_fix
+ 6, fragP
->fr_symbol
,
667 fragP
->fr_offset
, FX_PCREL32
, NULL
);
670 case STATE_ALWAYS_BRANCH
:
671 *fragP
->fr_opcode
= TAHOE_JMP
;
672 *p
++ = TAHOE_PC_REL_LONG
;
673 fragP
->fr_fix
+= 1 + 4;
674 fix_new (fragP
, old_fr_fix
+ 1, fragP
->fr_symbol
,
675 fragP
->fr_offset
, FX_PCREL32
, NULL
);
683 /* Return the growth in the fixed part of the frag. */
684 return fragP
->fr_fix
- old_fr_fix
;
687 /* Relaxable cases. Set up the initial guess for the variable
689 switch (RELAX_STATE (fragP
->fr_subtype
))
691 case STATE_PC_RELATIVE
:
692 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
);
694 case STATE_CONDITIONAL_BRANCH
:
695 fragP
->fr_subtype
= ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
);
697 case STATE_BIG_REV_BRANCH
:
698 fragP
->fr_subtype
= ENCODE_RELAX (STATE_BIG_REV_BRANCH
, STATE_WORD
);
700 case STATE_BIG_NON_REV_BRANCH
:
701 fragP
->fr_subtype
= ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
, STATE_WORD
);
703 case STATE_ALWAYS_BRANCH
:
704 fragP
->fr_subtype
= ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
);
709 if (fragP
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
712 /* Return the size of the variable part of the frag. */
713 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
719 * Called after relax() is finished.
720 * In: Address of frag.
721 * fr_type == rs_machine_dependent.
722 * fr_subtype is what the address relaxed to.
724 * Out: Any fixSs and constants are set up.
725 * Caller will turn frag into a ".space 0".
728 md_convert_frag (headers
, seg
, fragP
)
729 object_headers
*headers
;
731 register fragS
*fragP
;
733 register char *addressP
; /* -> _var to change. */
734 register char *opcodeP
; /* -> opcode char(s) to change. */
735 register short int extension
= 0; /* Size of relaxed address.
736 Added to fr_fix: incl. ALL var chars. */
737 register symbolS
*symbolP
;
738 register long int where
;
739 register long int address_of_var
;
740 /* Where, in file space, is _var of *fragP? */
741 register long int target_address
;
742 /* Where, in file space, does addr point? */
744 know (fragP
->fr_type
== rs_machine_dependent
);
745 where
= fragP
->fr_fix
;
746 addressP
= fragP
->fr_literal
+ where
;
747 opcodeP
= fragP
->fr_opcode
;
748 symbolP
= fragP
->fr_symbol
;
750 target_address
= S_GET_VALUE (symbolP
) + fragP
->fr_offset
;
751 address_of_var
= fragP
->fr_address
+ where
;
752 switch (fragP
->fr_subtype
)
754 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
):
755 /* *addressP holds the registers number, plus 0x10, if it's deferred
756 mode. To set up the right mode, just OR the size of this displacement */
757 /* Byte displacement. */
758 *addressP
++ |= TAHOE_PC_OR_BYTE
;
759 *addressP
= target_address
- (address_of_var
+ 2);
763 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_WORD
):
764 /* Word displacement. */
765 *addressP
++ |= TAHOE_PC_OR_WORD
;
766 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 3), 2);
770 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_LONG
):
771 /* Long word displacement. */
772 *addressP
++ |= TAHOE_PC_OR_LONG
;
773 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 5), 4);
777 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
):
778 *addressP
= target_address
- (address_of_var
+ 1);
782 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_WORD
):
783 *opcodeP
^= 0x10; /* Reverse sense of test. */
784 *addressP
++ = 3; /* Jump over word branch */
785 *addressP
++ = TAHOE_BRW
;
786 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 4), 2);
790 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_LONG
):
791 *opcodeP
^= 0x10; /* Reverse sense of test. */
793 *addressP
++ = TAHOE_JMP
;
794 *addressP
++ = TAHOE_PC_REL_LONG
;
795 md_number_to_chars (addressP
, target_address
, 4);
799 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
):
800 *addressP
= target_address
- (address_of_var
+ 1);
804 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_WORD
):
805 *opcodeP
= TAHOE_BRW
;
806 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 2), 2);
810 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_LONG
):
811 *opcodeP
= TAHOE_JMP
;
812 *addressP
++ = TAHOE_PC_REL_LONG
;
813 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 5), 4);
817 case ENCODE_RELAX (STATE_BIG_REV_BRANCH
, STATE_WORD
):
818 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 2), 2);
822 case ENCODE_RELAX (STATE_BIG_REV_BRANCH
, STATE_LONG
):
826 *addressP
++ = TAHOE_JMP
;
827 *addressP
++ = TAHOE_PC_REL_LONG
;
828 md_number_to_chars (addressP
, target_address
, 4);
832 case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
, STATE_WORD
):
833 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 2), 2);
837 case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
, STATE_LONG
):
840 *addressP
++ = TAHOE_BRB
;
842 *addressP
++ = TAHOE_JMP
;
843 *addressP
++ = TAHOE_PC_REL_LONG
;
844 md_number_to_chars (addressP
, target_address
, 4);
849 BAD_CASE (fragP
->fr_subtype
);
852 fragP
->fr_fix
+= extension
;
853 } /* md_convert_frag */
856 /* This is the stuff for md_assemble. */
860 #define BIGGESTREG PC_REG
863 * Parse the string pointed to by START
864 * If it represents a valid register, point START to the character after
865 * the last valid register char, and return the register number (0-15).
866 * If invalid, leave START alone, return -1.
867 * The format has to be exact. I don't do things like eat leading zeros
869 * Note: This doesn't check for the next character in the string making
870 * this invalid. Ex: R123 would return 12, it's the callers job to check
871 * what start is point to apon return.
873 * Valid registers are R1-R15, %1-%15, FP (13), SP (14), PC (15)
874 * Case doesn't matter.
877 tahoe_reg_parse (start
)
878 char **start
; /* A pointer to the string to parse. */
880 register char *regpoint
= *start
;
881 register int regnum
= -1;
885 case '%': /* Registers can start with a %,
886 R or r, and then a number. */
889 if (ISDIGIT (*regpoint
))
891 /* Got the first digit. */
892 regnum
= *regpoint
++ - '0';
893 if ((regnum
== 1) && ISDIGIT (*regpoint
))
895 /* Its a two digit number. */
896 regnum
= 10 + (*regpoint
++ - '0');
897 if (regnum
> BIGGESTREG
)
898 { /* Number too big? */
904 case 'F': /* Is it the FP */
913 case 's': /* How about the SP */
922 case 'p': /* OR the PC even */
934 { /* No error, so move string pointer */
937 return regnum
; /* Return results */
938 } /* tahoe_reg_parse */
941 * This chops up an operand and figures out its modes and stuff.
942 * It's a little touchy about extra characters.
943 * Optex to start with one extra character so it can be overwritten for
944 * the backward part of the parsing.
945 * You can't put a bunch of extra characters in side to
946 * make the command look cute. ie: * foo ( r1 ) [ r0 ]
947 * If you like doing a lot of typing, try COBOL!
948 * Actually, this parser is a little weak all around. It's designed to be
949 * used with compliers, so I emphisise correct decoding of valid code quickly
950 * rather that catching every possable error.
951 * Note: This uses the expression function, so save input_line_pointer before
954 * Sperry defines the semantics of address modes (and values)
955 * by a two-letter code, explained here.
957 * letter 1: access type
959 * a address calculation - no data access, registers forbidden
960 * b branch displacement
961 * m read - let go of bus - write back "modify"
964 * v bit field address: like 'a' but registers are OK
966 * letter 2: data type (i.e. width, alignment)
971 * q quadword (Even regs < 14 allowed) (if 12, you get a warning)
972 * - unconditional synthetic jbr operand
973 * ? simple synthetic reversable branch operand
974 * ! complex synthetic reversable branch operand
975 * : complex synthetic non-reversable branch operand
977 * The '-?!:' letter 2's are not for external consumption. They are used
978 * by GAS for psuedo ops relaxing code.
980 * After parsing topP has:
982 * top_ndx: -1, or the index register. eg 7=[R7]
983 * top_reg: -1, or register number. eg 7 = R7 or (R7)
984 * top_mode: The addressing mode byte. This byte, defines which of
985 * the 11 modes opcode is.
986 * top_access: Access type wanted for this opperand 'b'branch ' '
987 * no-instruction 'amrvw'
988 * top_width: Operand width expected, one of "bwlq?-:!"
989 * exp_of_operand: The expression as parsed by expression()
990 * top_dispsize: Number of bytes in the displacement if we can figure it
991 * out and it's relavent.
993 * Need syntax checks built.
998 char *optex
; /* The users text input, with one leading character */
999 struct top
*topP
; /* The tahoe instruction with some fields already set:
1001 out: ndx, reg, mode, error, dispsize */
1004 int mode
= 0; /* This operand's mode. */
1005 char segfault
= *optex
; /* To keep the back parsing from freaking. */
1006 char *point
= optex
+ 1; /* Parsing from front to back. */
1007 char *end
; /* Parsing from back to front. */
1008 int reg
= -1; /* major register, -1 means absent */
1009 int imreg
= -1; /* Major register in immediate mode */
1010 int ndx
= -1; /* index register number, -1 means absent */
1011 char dec_inc
= ' '; /* Is the SP auto-incremented '+' or
1012 auto-decremented '-' or neither ' '. */
1013 int immediate
= 0; /* 1 if '$' immediate mode */
1014 int call_width
= 0; /* If the caller casts the displacement */
1015 int abs_width
= 0; /* The width of the absolute displacment */
1016 int com_width
= 0; /* Displacement width required by branch */
1017 int deferred
= 0; /* 1 if '*' deferral is used */
1018 byte disp_size
= 0; /* How big is this operand. 0 == don't know */
1019 char *op_bad
= ""; /* Bad operand error */
1021 char *tp
, *temp
, c
; /* Temporary holders */
1023 char access
= topP
->top_access
; /* Save on a deref. */
1024 char width
= topP
->top_width
;
1026 int really_none
= 0; /* Empty expressions evaluate to 0
1027 but I need to know if it's there or not */
1028 expressionS
*expP
; /* -> expression values for this operand */
1030 /* Does this command restrict the displacement size. */
1032 com_width
= (width
== 'b' ? 1 :
1034 (width
== 'l' ? 4 : 0)));
1036 *optex
= '\0'; /* This is kind of a back stop for all
1037 the searches to fail on if needed.*/
1039 { /* A dereference? */
1044 /* Force words into a certain mode */
1045 /* Bitch, Bitch, Bitch! */
1047 * Using the ^ operator is ambigous. If I have an absolute label
1048 * called 'w' set to, say 2, and I have the expression 'w^1', do I get
1049 * 1, forced to be in word displacement mode, or do I get the value of
1050 * 'w' or'ed with 1 (3 in this case).
1051 * The default is 'w' as an offset, so that's what I use.
1052 * Stick with `, it does the same, and isn't ambig.
1055 if (*point
!= '\0' && ((point
[1] == '^') || (point
[1] == '`')))
1065 as_warn (_("Casting a branch displacement is bad form, and is ignored."));
1068 c
= TOLOWER (*point
);
1069 call_width
= ((c
== 'b') ? 1 :
1070 ((c
== 'w') ? 2 : 4));
1076 /* Setting immediate mode */
1084 * I've pulled off all the easy stuff off the front, move to the end and
1088 for (end
= point
; *end
!= '\0'; end
++) /* Move to the end. */
1091 if (end
!= point
) /* Null string? */
1094 if (end
> point
&& *end
== ' ' && end
[-1] != '\'')
1095 end
--; /* Hop white space */
1097 /* Is this an index reg. */
1098 if ((*end
== ']') && (end
[-1] != '\''))
1102 /* Find opening brace. */
1103 for (--end
; (*end
!= '[' && end
!= point
); end
--)
1106 /* If I found the opening brace, get the index register number. */
1109 tp
= end
+ 1; /* tp should point to the start of a reg. */
1110 ndx
= tahoe_reg_parse (&tp
);
1112 { /* Reg. parse error. */
1117 end
--; /* Found it, move past brace. */
1121 op_bad
= _("Couldn't parse the [index] in this operand.");
1122 end
= point
; /* Force all the rest of the tests to fail. */
1127 op_bad
= _("Couldn't find the opening '[' for the index of this operand.");
1128 end
= point
; /* Force all the rest of the tests to fail. */
1132 /* Post increment? */
1140 /* register in parens? */
1141 if ((*end
== ')') && (end
[-1] != '\''))
1145 /* Find opening paren. */
1146 for (--end
; (*end
!= '(' && end
!= point
); end
--)
1149 /* If I found the opening paren, get the register number. */
1153 reg
= tahoe_reg_parse (&tp
);
1156 /* Not a register, but could be part of the expression. */
1158 end
= temp
; /* Rest the pointer back */
1162 end
--; /* Found the reg. move before opening paren. */
1167 op_bad
= _("Couldn't find the opening '(' for the deref of this operand.");
1168 end
= point
; /* Force all the rest of the tests to fail. */
1172 /* Pre decrement? */
1177 op_bad
= _("Operand can't be both pre-inc and post-dec.");
1189 * Everything between point and end is the 'expression', unless it's
1197 imreg
= tahoe_reg_parse (&point
); /* Get the immediate register
1201 /* If there is junk after point, then the it's not immediate reg. */
1206 if (imreg
!= -1 && reg
!= -1)
1207 op_bad
= _("I parsed 2 registers in this operand.");
1210 * Evaluate whats left of the expression to see if it's valid.
1211 * Note again: This assumes that the calling expression has saved
1212 * input_line_pointer. (Nag, nag, nag!)
1215 if (*op_bad
== '\0')
1217 /* Statement has no syntax goofs yet: let's sniff the expression. */
1218 input_line_pointer
= point
;
1219 expP
= &(topP
->exp_of_operand
);
1220 topP
->seg_of_operand
= expression (expP
);
1224 /* No expression. For BSD4.2 compatibility, missing expression is
1226 expP
->X_op
= O_constant
;
1227 expP
->X_add_number
= 0;
1230 /* for SEG_ABSOLUTE, we shouldnt need to set X_op_symbol,
1231 X_add_symbol to any particular value. */
1232 /* But, we will program defensively. Since this situation occurs
1233 rarely so it costs us little to do so. */
1234 expP
->X_add_symbol
= NULL
;
1235 expP
->X_op_symbol
= NULL
;
1236 /* How many bytes are needed to express this abs value? */
1238 ((((expP
->X_add_number
& 0xFFFFFF80) == 0) ||
1239 ((expP
->X_add_number
& 0xFFFFFF80) == 0xFFFFFF80)) ? 1 :
1240 (((expP
->X_add_number
& 0xFFFF8000) == 0) ||
1241 ((expP
->X_add_number
& 0xFFFF8000) == 0xFFFF8000)) ? 2 : 4);
1248 * Major bug. We can't handle the case of an operator
1249 * expression in a synthetic opcode variable-length
1250 * instruction. We don't have a frag type that is smart
1251 * enough to relax an operator, and so we just force all
1252 * operators to behave like SEG_PASS1s. Clearly, if there is
1253 * a demand we can invent a new or modified frag type and
1254 * then coding up a frag for this case will be easy.
1257 op_bad
= _("Can't relocate expression error.");
1261 /* This is an error. Tahoe doesn't allow any expressions
1262 bigger that a 32 bit long word. Any bigger has to be referenced
1264 op_bad
= _("Expression is too large for a 32 bits.");
1267 if (*input_line_pointer
!= '\0')
1269 op_bad
= _("Junk at end of expression.");
1275 /* I'm done, so restore optex */
1279 * At this point in the game, we (in theory) have all the components of
1280 * the operand at least parsed. Now it's time to check for syntax/semantic
1281 * errors, and build the mode.
1282 * This is what I have:
1283 * deferred = 1 if '*'
1284 * call_width = 0,1,2,4
1285 * abs_width = 0,1,2,4
1286 * com_width = 0,1,2,4
1287 * immediate = 1 if '$'
1288 * ndx = -1 or reg num
1289 * dec_inc = '-' or '+' or ' '
1290 * reg = -1 or reg num
1291 * imreg = -1 or reg num
1292 * topP->exp_of_operand
1295 /* Is there a displacement size? */
1296 disp_size
= (call_width
? call_width
:
1297 (com_width
? com_width
:
1298 abs_width
? abs_width
: 0));
1300 if (*op_bad
== '\0')
1305 mode
= TAHOE_DIRECT_REG
;
1306 if (deferred
|| immediate
|| (dec_inc
!= ' ') ||
1307 (reg
!= -1) || !really_none
)
1308 op_bad
= _("Syntax error in direct register mode.");
1310 op_bad
= _("You can't index a register in direct register mode.");
1311 else if (imreg
== SP_REG
&& access
== 'r')
1313 _("SP can't be the source operand with direct register addressing.");
1314 else if (access
== 'a')
1315 op_bad
= _("Can't take the address of a register.");
1316 else if (access
== 'b')
1317 op_bad
= _("Direct Register can't be used in a branch.");
1318 else if (width
== 'q' && ((imreg
% 2) || (imreg
> 13)))
1319 op_bad
= _("For quad access, the register must be even and < 14.");
1320 else if (call_width
)
1321 op_bad
= _("You can't cast a direct register.");
1323 if (*op_bad
== '\0')
1325 /* No errors, check for warnings */
1326 if (width
== 'q' && imreg
== 12)
1327 as_warn (_("Using reg 14 for quadwords can tromp the FP register."));
1332 /* We know: imm = -1 */
1334 else if (dec_inc
== '-')
1337 mode
= TAHOE_AUTO_DEC
;
1338 if (deferred
|| immediate
|| !really_none
)
1339 op_bad
= _("Syntax error in auto-dec mode.");
1341 op_bad
= _("You can't have an index auto dec mode.");
1342 else if (access
== 'r')
1343 op_bad
= _("Auto dec mode cant be used for reading.");
1344 else if (reg
!= SP_REG
)
1345 op_bad
= _("Auto dec only works of the SP register.");
1346 else if (access
== 'b')
1347 op_bad
= _("Auto dec can't be used in a branch.");
1348 else if (width
== 'q')
1349 op_bad
= _("Auto dec won't work with quadwords.");
1351 /* We know: imm = -1, dec_inc != '-' */
1353 else if (dec_inc
== '+')
1355 if (immediate
|| !really_none
)
1356 op_bad
= _("Syntax error in one of the auto-inc modes.");
1360 mode
= TAHOE_AUTO_INC_DEFERRED
;
1362 op_bad
= _("Auto inc deferred only works of the SP register.");
1364 op_bad
= _("You can't have an index auto inc deferred mode.");
1365 else if (access
== 'b')
1366 op_bad
= _("Auto inc can't be used in a branch.");
1371 mode
= TAHOE_AUTO_INC
;
1372 if (access
== 'm' || access
== 'w')
1373 op_bad
= _("You can't write to an auto inc register.");
1374 else if (reg
!= SP_REG
)
1375 op_bad
= _("Auto inc only works of the SP register.");
1376 else if (access
== 'b')
1377 op_bad
= _("Auto inc can't be used in a branch.");
1378 else if (width
== 'q')
1379 op_bad
= _("Auto inc won't work with quadwords.");
1381 op_bad
= _("You can't have an index in auto inc mode.");
1384 /* We know: imm = -1, dec_inc == ' ' */
1388 if ((ndx
!= -1) && (reg
== SP_REG
))
1389 op_bad
= _("You can't index the sp register.");
1393 mode
= TAHOE_REG_DISP_DEFERRED
;
1395 op_bad
= _("Syntax error in register displaced mode.");
1397 else if (really_none
)
1400 mode
= TAHOE_REG_DEFERRED
;
1401 /* if reg = SP then cant be indexed */
1406 mode
= TAHOE_REG_DISP
;
1409 /* We know: imm = -1, dec_inc == ' ', Reg = -1 */
1414 op_bad
= _("An offest is needed for this operand.");
1415 if (deferred
&& immediate
)
1418 mode
= TAHOE_ABSOLUTE_ADDR
;
1424 mode
= TAHOE_IMMEDIATE
;
1426 op_bad
= _("You can't index a register in immediate mode.");
1428 op_bad
= _("Immediate access can't be used as an address.");
1429 /* ponder the wisdom of a cast because it doesn't do any good. */
1434 mode
= TAHOE_DISP_REL_DEFERRED
;
1439 mode
= TAHOE_DISPLACED_RELATIVE
;
1445 * At this point, all the errors we can do have be checked for.
1446 * We can build the 'top'. */
1448 topP
->top_ndx
= ndx
;
1449 topP
->top_reg
= reg
;
1450 topP
->top_mode
= mode
;
1451 topP
->top_error
= op_bad
;
1452 topP
->top_dispsize
= disp_size
;
1458 * This converts a string into a tahoe instruction.
1459 * The string must be a bare single instruction in tahoe (with BSD4 frobs)
1461 * It provides at most one fatal error message (which stops the scan)
1462 * some warning messages as it finds them.
1463 * The tahoe instruction is returned in exploded form.
1465 * The exploded instruction is returned to a struct tit of your choice.
1466 * #include "tahoe-inst.h" to know what a struct tit is.
1471 tip (titP
, instring
)
1472 struct tit
*titP
; /* We build an exploded instruction here. */
1473 char *instring
; /* Text of a vax instruction: we modify. */
1475 register struct tot_wot
*twP
= NULL
; /* How to bit-encode this opcode. */
1476 register char *p
; /* 1/skip whitespace.2/scan vot_how */
1477 register char *q
; /* */
1478 register unsigned char count
; /* counts number of operands seen */
1479 register struct top
*operandp
;/* scan operands in struct tit */
1480 register char *alloperr
= ""; /* error over all operands */
1481 register char c
; /* Remember char, (we clobber it
1482 with '\0' temporarily). */
1483 char *save_input_line_pointer
;
1485 if (*instring
== ' ')
1486 ++instring
; /* Skip leading whitespace. */
1487 for (p
= instring
; *p
&& *p
!= ' '; p
++)
1488 ; /* MUST end in end-of-string or
1490 /* Scanned up to end of operation-code. */
1491 /* Operation-code is ended with whitespace. */
1494 titP
->tit_error
= _("No operator");
1496 titP
->tit_opcode
= 0;
1503 * Here with instring pointing to what better be an op-name, and p
1504 * pointing to character just past that.
1505 * We trust instring points to an op-name, with no whitespace.
1507 twP
= (struct tot_wot
*) hash_find (op_hash
, instring
);
1508 *p
= c
; /* Restore char after op-code. */
1511 titP
->tit_error
= _("Unknown operator");
1513 titP
->tit_opcode
= 0;
1518 * We found a match! So let's pick up as many operands as the
1519 * instruction wants, and even gripe if there are too many.
1520 * We expect comma to seperate each operand.
1521 * We let instring track the text, while p tracks a part of the
1525 count
= 0; /* no operands seen yet */
1526 instring
= p
+ (*p
!= '\0'); /* point past the operation code */
1527 /* tip_op() screws with the input_line_pointer, so save it before
1529 save_input_line_pointer
= input_line_pointer
;
1530 for (p
= twP
->args
, operandp
= titP
->tit_operand
;
1535 * Here to parse one operand. Leave instring pointing just
1536 * past any one ',' that marks the end of this operand.
1539 as_fatal (_("Compiler bug: ODD number of bytes in arg structure %s."),
1543 for (q
= instring
; (*q
!= ',' && *q
!= '\0'); q
++)
1545 if (*q
== '\'' && q
[1] != '\0') /* Jump quoted characters */
1550 * Q points to ',' or '\0' that ends argument. C is that
1554 operandp
->top_access
= p
[0];
1555 operandp
->top_width
= p
[1];
1556 tip_op (instring
- 1, operandp
);
1557 *q
= c
; /* Restore input text. */
1558 if (*(operandp
->top_error
))
1560 alloperr
= operandp
->top_error
;
1562 instring
= q
+ (c
? 1 : 0); /* next operand (if any) */
1563 count
++; /* won another argument, may have an operr */
1566 alloperr
= _("Not enough operands");
1568 /* Restore the pointer. */
1569 input_line_pointer
= save_input_line_pointer
;
1573 if (*instring
== ' ')
1574 instring
++; /* Skip whitespace. */
1576 alloperr
= _("Too many operands");
1578 titP
->tit_error
= alloperr
;
1582 titP
->tit_opcode
= twP
->code
; /* The op-code. */
1583 titP
->tit_operands
= count
;
1586 /* md_assemble() emit frags for 1 instruction */
1588 md_assemble (instruction_string
)
1589 char *instruction_string
; /* A string: assemble 1 instruction. */
1592 register struct top
*operandP
;/* An operand. Scans all operands. */
1593 /* char c_save; fixme: remove this line *//* What used to live after an expression. */
1594 /* struct frag *fragP; fixme: remove this line *//* Fragment of code we just made. */
1595 /* register struct top *end_operandP; fixme: remove this line *//* -> slot just after last operand
1596 Limit of the for (each operand). */
1597 register expressionS
*expP
; /* -> expression values for this operand */
1599 /* These refer to an instruction operand expression. */
1600 segT to_seg
; /* Target segment of the address. */
1602 register valueT this_add_number
;
1603 register symbolS
*this_add_symbol
; /* +ve (minuend) symbol. */
1605 /* tahoe_opcodeT opcode_as_number; fixme: remove this line *//* The opcode as a number. */
1606 char *opcodeP
; /* Where it is in a frag. */
1607 /* char *opmodeP; fixme: remove this line *//* Where opcode type is, in a frag. */
1609 int dispsize
; /* From top_dispsize: tahoe_operand_width
1611 int is_undefined
; /* 1 if operand expression's
1612 segment not known yet. */
1613 int pc_rel
; /* Is this operand pc relative? */
1615 /* Decode the operand. */
1616 tip (&t
, instruction_string
);
1619 * Check to see if this operand decode properly.
1620 * Notice that we haven't made any frags yet.
1621 * If it goofed, then this instruction will wedge in any pass,
1622 * and we can safely flush it, without causing interpass symbol phase
1623 * errors. That is, without changing label values in different passes.
1627 as_warn (_("Ignoring statement due to \"%s\""), t
.tit_error
);
1631 /* We saw no errors in any operands - try to make frag(s) */
1633 /* Remember where it is, in case we want to modify the op-code later. */
1634 opcodeP
= frag_more (1);
1635 *opcodeP
= t
.tit_opcode
;
1636 /* Now do each operand. */
1637 for (operandP
= t
.tit_operand
;
1638 operandP
< t
.tit_operand
+ t
.tit_operands
;
1640 { /* for each operand */
1641 expP
= &(operandP
->exp_of_operand
);
1642 if (operandP
->top_ndx
>= 0)
1644 /* Indexed addressing byte
1645 Legality of indexed mode already checked: it is OK */
1646 FRAG_APPEND_1_CHAR (0x40 + operandP
->top_ndx
);
1647 } /* if(top_ndx>=0) */
1649 /* Here to make main operand frag(s). */
1650 this_add_number
= expP
->X_add_number
;
1651 this_add_symbol
= expP
->X_add_symbol
;
1652 to_seg
= operandP
->seg_of_operand
;
1653 know (to_seg
== SEG_UNKNOWN
|| \
1654 to_seg
== SEG_ABSOLUTE
|| \
1655 to_seg
== SEG_DATA
|| \
1656 to_seg
== SEG_TEXT
|| \
1658 is_undefined
= (to_seg
== SEG_UNKNOWN
);
1659 /* Do we know how big this opperand is? */
1660 dispsize
= operandP
->top_dispsize
;
1662 /* Deal with the branch possabilities. (Note, this doesn't include
1664 if (operandP
->top_access
== 'b')
1666 /* Branches must be expressions. A psuedo branch can also jump to
1667 an absolute address. */
1668 if (to_seg
== now_seg
|| is_undefined
)
1670 /* If is_undefined, then it might BECOME now_seg by relax time. */
1673 /* I know how big the branch is supposed to be (it's a normal
1674 branch), so I set up the frag, and let GAS do the rest. */
1675 p
= frag_more (dispsize
);
1676 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1677 this_add_symbol
, this_add_number
,
1678 size_to_fx (dispsize
, 1),
1683 /* (to_seg==now_seg || to_seg == SEG_UNKNOWN) && dispsize==0 */
1684 /* If we don't know how big it is, then its a synthetic branch,
1685 so we set up a simple relax state. */
1686 switch (operandP
->top_width
)
1688 case TAHOE_WIDTH_CONDITIONAL_JUMP
:
1689 /* Simple (conditional) jump. I may have to reverse the
1690 condition of opcodeP, and then jump to my destination.
1691 I set 1 byte aside for the branch off set, and could need 6
1692 more bytes for the pc_rel jump */
1693 frag_var (rs_machine_dependent
, 7, 1,
1694 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
,
1695 is_undefined
? STATE_UNDF
: STATE_BYTE
),
1696 this_add_symbol
, this_add_number
, opcodeP
);
1698 case TAHOE_WIDTH_ALWAYS_JUMP
:
1699 /* Simple (unconditional) jump. I may have to convert this to
1700 a word branch, or an absolute jump. */
1701 frag_var (rs_machine_dependent
, 5, 1,
1702 ENCODE_RELAX (STATE_ALWAYS_BRANCH
,
1703 is_undefined
? STATE_UNDF
: STATE_BYTE
),
1704 this_add_symbol
, this_add_number
, opcodeP
);
1706 /* The smallest size for the next 2 cases is word. */
1707 case TAHOE_WIDTH_BIG_REV_JUMP
:
1708 frag_var (rs_machine_dependent
, 8, 2,
1709 ENCODE_RELAX (STATE_BIG_REV_BRANCH
,
1710 is_undefined
? STATE_UNDF
: STATE_WORD
),
1711 this_add_symbol
, this_add_number
,
1714 case TAHOE_WIDTH_BIG_NON_REV_JUMP
:
1715 frag_var (rs_machine_dependent
, 10, 2,
1716 ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
,
1717 is_undefined
? STATE_UNDF
: STATE_WORD
),
1718 this_add_symbol
, this_add_number
,
1722 as_fatal (_("Compliler bug: Got a case (%d) I wasn't expecting."),
1723 operandP
->top_width
);
1729 /* to_seg != now_seg && to_seg != seg_unknown (still in branch)
1730 In other words, I'm jumping out of my segment so extend the
1731 branches to jumps, and let GAS fix them. */
1733 /* These are "branches" what will always be branches around a jump
1734 to the correct addresss in real life.
1735 If to_seg is SEG_ABSOLUTE, just encode the branch in,
1736 else let GAS fix the address. */
1738 switch (operandP
->top_width
)
1741 For SEG_ABSOLUTE, then mode is ABSOLUTE_ADDR, jump
1742 to that addresss (not pc_rel).
1743 For other segs, address is a long word PC rel jump. */
1744 case TAHOE_WIDTH_CONDITIONAL_JUMP
:
1746 /* To reverse the condition in a TAHOE branch,
1752 *p
++ = (operandP
->top_mode
==
1753 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1755 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1756 this_add_symbol
, this_add_number
,
1757 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1764 case TAHOE_WIDTH_ALWAYS_JUMP
:
1765 /* br, just turn it into a jump */
1766 *opcodeP
= TAHOE_JMP
;
1768 *p
++ = (operandP
->top_mode
==
1769 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1771 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1772 this_add_symbol
, this_add_number
,
1773 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1774 /* Now (eg) JMP foo */
1776 case TAHOE_WIDTH_BIG_REV_JUMP
:
1782 *p
++ = (operandP
->top_mode
==
1783 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1785 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1786 this_add_symbol
, this_add_number
,
1787 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1794 case TAHOE_WIDTH_BIG_NON_REV_JUMP
:
1801 *p
++ = (operandP
->top_mode
==
1802 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1804 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1805 this_add_symbol
, this_add_number
,
1806 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1808 * Now (eg) xOBxxx 1f
1816 as_warn (_("Real branch displacements must be expressions."));
1819 as_fatal (_("Complier error: I got an unknown synthetic branch :%c"),
1820 operandP
->top_width
);
1827 /* It ain't a branch operand. */
1828 switch (operandP
->top_mode
)
1830 /* Auto-foo access, only works for one reg (SP)
1831 so the only thing needed is the mode. */
1832 case TAHOE_AUTO_DEC
:
1833 case TAHOE_AUTO_INC
:
1834 case TAHOE_AUTO_INC_DEFERRED
:
1835 FRAG_APPEND_1_CHAR (operandP
->top_mode
);
1838 /* Numbered Register only access. Only thing needed is the
1839 mode + Register number */
1840 case TAHOE_DIRECT_REG
:
1841 case TAHOE_REG_DEFERRED
:
1842 FRAG_APPEND_1_CHAR (operandP
->top_mode
+ operandP
->top_reg
);
1845 /* An absolute address. It's size is always 5 bytes.
1846 (mode_type + 4 byte address). */
1847 case TAHOE_ABSOLUTE_ADDR
:
1848 know ((this_add_symbol
== NULL
));
1850 *p
= TAHOE_ABSOLUTE_ADDR
;
1851 md_number_to_chars (p
+ 1, this_add_number
, 4);
1854 /* Immediate data. If the size isn't known, then it's an address
1855 + and offset, which is 4 bytes big. */
1856 case TAHOE_IMMEDIATE
:
1857 if (this_add_symbol
!= NULL
)
1860 *p
++ = TAHOE_IMMEDIATE_LONGWORD
;
1861 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1862 this_add_symbol
, this_add_number
,
1867 /* It's an integer, and I know it's size. */
1868 if ((unsigned) this_add_number
< 0x40)
1870 /* Will it fit in a literal? */
1871 FRAG_APPEND_1_CHAR ((byte
) this_add_number
);
1875 p
= frag_more (dispsize
+ 1);
1879 *p
++ = TAHOE_IMMEDIATE_BYTE
;
1880 *p
= (byte
) this_add_number
;
1883 *p
++ = TAHOE_IMMEDIATE_WORD
;
1884 md_number_to_chars (p
, this_add_number
, 2);
1887 *p
++ = TAHOE_IMMEDIATE_LONGWORD
;
1888 md_number_to_chars (p
, this_add_number
, 4);
1895 /* Distance from the PC. If the size isn't known, we have to relax
1896 into it. The difference between this and disp(sp) is that
1897 this offset is pc_rel, and disp(sp) isn't.
1898 Note the drop through code. */
1900 case TAHOE_DISPLACED_RELATIVE
:
1901 case TAHOE_DISP_REL_DEFERRED
:
1902 operandP
->top_reg
= PC_REG
;
1905 /* Register, plus a displacement mode. Save the register number,
1906 and weather its deffered or not, and relax the size if it isn't
1908 case TAHOE_REG_DISP
:
1909 case TAHOE_REG_DISP_DEFERRED
:
1910 if (operandP
->top_mode
== TAHOE_DISP_REL_DEFERRED
||
1911 operandP
->top_mode
== TAHOE_REG_DISP_DEFERRED
)
1912 operandP
->top_reg
+= 0x10; /* deffered mode is always 0x10 higher
1913 than it's non-deffered sibling. */
1915 /* Is this a value out of this segment?
1916 The first part of this conditional is a cludge to make gas
1917 produce the same output as 'as' when there is a lable, in
1918 the current segment, displaceing a register. It's strange,
1919 and no one in their right mind would do it, but it's easy
1921 if ((dispsize
== 0 && !pc_rel
) ||
1922 (to_seg
!= now_seg
&& !is_undefined
&& to_seg
!= SEG_ABSOLUTE
))
1928 * We have a SEG_UNKNOWN symbol, or the size isn't cast.
1929 * It might turn out to be in the same segment as
1930 * the instruction, permitting relaxation.
1932 p
= frag_var (rs_machine_dependent
, 5, 2,
1933 ENCODE_RELAX (STATE_PC_RELATIVE
,
1934 is_undefined
? STATE_UNDF
: STATE_BYTE
),
1935 this_add_symbol
, this_add_number
, 0);
1936 *p
= operandP
->top_reg
;
1940 /* Either this is an abs, or a cast. */
1941 p
= frag_more (dispsize
+ 1);
1945 *p
= TAHOE_PC_OR_BYTE
+ operandP
->top_reg
;
1948 *p
= TAHOE_PC_OR_WORD
+ operandP
->top_reg
;
1951 *p
= TAHOE_PC_OR_LONG
+ operandP
->top_reg
;
1954 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
1955 this_add_symbol
, this_add_number
,
1956 size_to_fx (dispsize
, pc_rel
), NULL
);
1960 as_fatal (_("Barf, bad mode %x\n"), operandP
->top_mode
);
1963 } /* for(operandP) */
1964 } /* if(!need_pass_2 && !goofed) */
1965 } /* tahoe_assemble() */
1967 /* We have no need to default values of symbols. */
1970 md_undefined_symbol (name
)
1974 } /* md_undefined_symbol() */
1976 /* Round up a section size to the appropriate boundary. */
1978 md_section_align (segment
, size
)
1982 return ((size
+ 7) & ~7); /* Round all sects to multiple of 8 */
1983 } /* md_section_align() */
1985 /* Exactly what point is a PC-relative offset relative TO?
1986 On the sparc, they're relative to the address of the offset, plus
1987 its size. This gets us to the following instruction.
1988 (??? Is this right? FIXME-SOON) */
1990 md_pcrel_from (fixP
)
1993 return (((fixP
->fx_type
== FX_8
1994 || fixP
->fx_type
== FX_PCREL8
)
1996 : ((fixP
->fx_type
== FX_16
1997 || fixP
->fx_type
== FX_PCREL16
)
1999 : ((fixP
->fx_type
== FX_32
2000 || fixP
->fx_type
== FX_PCREL32
)
2002 : 0))) + fixP
->fx_where
+ fixP
->fx_frag
->fr_address
);
2003 } /* md_pcrel_from() */
2009 /* should never be called */
2012 } /* tc_is_pcrel() */