2 Not part of GAS yet. */
7 /* this bit glommed from tahoe-inst.h */
9 typedef unsigned char byte
;
10 typedef byte tahoe_opcodeT
;
13 * This is part of tahoe-ins-parse.c & friends.
14 * We want to parse a tahoe instruction text into a tree defined here.
17 #define TIT_MAX_OPERANDS (4) /* maximum number of operands in one
18 single tahoe instruction */
20 struct top
/* tahoe instruction operand */
22 int top_ndx
; /* -1, or index register. eg 7=[R7] */
23 int top_reg
; /* -1, or register number. eg 7 = R7 or (R7) */
24 byte top_mode
; /* Addressing mode byte. This byte, defines
25 which of the 11 modes opcode is. */
27 char top_access
; /* Access type wanted for this opperand
28 'b'branch ' 'no-instruction 'amrvw' */
29 char top_width
; /* Operand width expected, one of "bwlq?-:!" */
31 char *top_error
; /* Say if operand is inappropriate */
33 segT seg_of_operand
; /* segment as returned by expression()*/
35 expressionS exp_of_operand
; /* The expression as parsed by expression()*/
37 byte top_dispsize
; /* Number of bytes in the displacement if we
41 /* The addressing modes for an operand. These numbers are the acutal values
42 for certain modes, so be carefull if you screw with them. */
43 #define TAHOE_DIRECT_REG (0x50)
44 #define TAHOE_REG_DEFERRED (0x60)
46 #define TAHOE_REG_DISP (0xE0)
47 #define TAHOE_REG_DISP_DEFERRED (0xF0)
49 #define TAHOE_IMMEDIATE (0x8F)
50 #define TAHOE_IMMEDIATE_BYTE (0x88)
51 #define TAHOE_IMMEDIATE_WORD (0x89)
52 #define TAHOE_IMMEDIATE_LONGWORD (0x8F)
53 #define TAHOE_ABSOLUTE_ADDR (0x9F)
55 #define TAHOE_DISPLACED_RELATIVE (0xEF)
56 #define TAHOE_DISP_REL_DEFERRED (0xFF)
58 #define TAHOE_AUTO_DEC (0x7E)
59 #define TAHOE_AUTO_INC (0x8E)
60 #define TAHOE_AUTO_INC_DEFERRED (0x9E)
61 /* INDEXED_REG is decided by the existance or lack of a [reg] */
63 /* These are encoded into top_width when top_access=='b'
64 and it's a psuedo op.*/
65 #define TAHOE_WIDTH_ALWAYS_JUMP '-'
66 #define TAHOE_WIDTH_CONDITIONAL_JUMP '?'
67 #define TAHOE_WIDTH_BIG_REV_JUMP '!'
68 #define TAHOE_WIDTH_BIG_NON_REV_JUMP ':'
70 /* The hex code for certain tahoe commands and modes.
71 This is just for readability. */
72 #define TAHOE_JMP (0x71)
73 #define TAHOE_PC_REL_LONG (0xEF)
74 #define TAHOE_BRB (0x11)
75 #define TAHOE_BRW (0x13)
76 /* These, when 'ored' with, or added to, a register number,
77 set up the number for the displacement mode. */
78 #define TAHOE_PC_OR_BYTE (0xA0)
79 #define TAHOE_PC_OR_WORD (0xC0)
80 #define TAHOE_PC_OR_LONG (0xE0)
82 struct tit
/* get it out of the sewer, it stands for
83 tahoe instruction tree (Geeze!) */
85 tahoe_opcodeT tit_opcode
; /* The opcode. */
86 byte tit_operands
; /* How many operands are here. */
87 struct top tit_operand
[TIT_MAX_OPERANDS
]; /* Operands */
88 char *tit_error
; /* "" or fatal error text */
91 /* end: tahoe-inst.h */
93 /* tahoe.c - tahoe-specific -
97 #include "opcode/tahoe.h"
99 /* This is the number to put at the beginning of the a.out file */
100 long omagic
= OMAGIC
;
102 /* These chars start a comment anywhere in a source file (except inside
103 another comment or a quoted string. */
104 const char comment_chars
[] = "#;";
106 /* These chars only start a comment at the beginning of a line. */
107 const char line_comment_chars
[] = "#";
109 /* Chars that can be used to separate mant from exp in floating point nums */
110 const char EXP_CHARS
[] = "eE";
112 /* Chars that mean this number is a floating point constant
114 or 0d1.234E-12 (see exp chars above)
115 Note: The Tahoe port doesn't support floating point constants. This is
116 consistant with 'as' If it's needed, I can always add it later. */
117 const char FLT_CHARS
[] = "df";
119 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
120 changed in read.c . Ideally it shouldn't have to know about it at all,
121 but nothing is ideal around here.
122 (The tahoe has plenty of room, so the change currently isn't needed.)
125 static struct tit t
; /* A tahoe instruction after decoding. */
128 /* A table of pseudo ops (sans .), the function called, and an integer op
129 that the function is called with. */
131 const pseudo_typeS md_pseudo_table
[] =
133 {"dfloat", float_cons
, 'd'},
134 {"ffloat", float_cons
, 'f'},
139 * For Tahoe, relative addresses of "just the right length" are pretty easy.
140 * The branch displacement is always the last operand, even in
141 * synthetic instructions.
142 * For Tahoe, we encode the relax_substateTs (in e.g. fr_substate) as:
144 * 4 3 2 1 0 bit number
145 * ---/ /--+-------+-------+-------+-------+-------+
146 * | what state ? | how long ? |
147 * ---/ /--+-------+-------+-------+-------+-------+
149 * The "how long" bits are 00=byte, 01=word, 10=long.
150 * This is a Un*x convention.
151 * Not all lengths are legit for a given value of (what state).
152 * The four states are listed below.
153 * The "how long" refers merely to the displacement length.
154 * The address usually has some constant bytes in it as well.
157 States for Tahoe address relaxing.
158 1. TAHOE_WIDTH_ALWAYS_JUMP (-)
160 Tahoe opcodes are: (Hex)
164 Always, 1 byte opcode, then displacement/absolute.
165 If word or longword, change opcode to brw or jmp.
168 2. TAHOE_WIDTH_CONDITIONAL_JUMP (?)
169 J<cond> where <cond> is a simple flag test.
171 Tahoe opcodes are: (Hex)
184 Always, you complement 4th bit to reverse the condition.
185 Always, 1-byte opcode, then 1-byte displacement.
187 3. TAHOE_WIDTH_BIG_REV_JUMP (!)
188 Jbc/Jbs where cond tests a memory bit.
190 Tahoe opcodes are: (Hex)
193 Always, you complement 4th bit to reverse the condition.
194 Always, 1-byte opcde, longword, longword-address, 1-word-displacement
196 4. TAHOE_WIDTH_BIG_NON_REV_JUMP (:)
199 Tahoe opcodes are: (Hex)
205 Always, we cannot reverse the sense of the branch; we have a word
208 We need to modify the opcode is for class 1, 2 and 3 instructions.
209 After relax() we may complement the 4th bit of 2 or 3 to reverse sense of
212 We sometimes store context in the operand literal. This way we can figure out
213 after relax() what the original addressing mode was. (Was is pc_rel, or
214 pc_rel_disp? That sort of thing.) */
216 /* These displacements are relative to the START address of the
217 displacement which is at the start of the displacement, not the end of
218 the instruction. The hardware pc_rel is at the end of the instructions.
219 That's why all the displacements have the length of the displacement added
220 to them. (WF + length(word))
222 The first letter is Byte, Word.
223 2nd letter is Forward, Backward. */
226 #define WF (2+ 32767)
227 #define WB (2+-32768)
228 /* Dont need LF, LB because they always reach. [They are coded as 0.] */
230 #define C(a,b) ENCODE_RELAX(a,b)
231 /* This macro has no side-effects. */
232 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
233 #define RELAX_STATE(what) ((what) >> 2)
234 #define RELAX_LENGTH(length) ((length) && 3)
236 #define STATE_ALWAYS_BRANCH (1)
237 #define STATE_CONDITIONAL_BRANCH (2)
238 #define STATE_BIG_REV_BRANCH (3)
239 #define STATE_BIG_NON_REV_BRANCH (4)
240 #define STATE_PC_RELATIVE (5)
242 #define STATE_BYTE (0)
243 #define STATE_WORD (1)
244 #define STATE_LONG (2)
245 #define STATE_UNDF (3) /* Symbol undefined in pass1 */
247 /* This is the table used by gas to figure out relaxing modes. The fields are
248 forward_branch reach, backward_branch reach, number of bytes it would take,
249 where the next biggest branch is. */
255 }, /* error sentinel 0,0 */
265 /* Unconditional branch cases "jrb"
266 The relax part is the actual displacement */
269 }, /* brb B`foo 1,0 */
272 }, /* brw W`foo 1,1 */
275 }, /* Jmp L`foo 1,2 */
279 /* Reversible Conditional Branch. If the branch won't reach, reverse
280 it, and jump over a brw or a jmp that will reach. The relax part is the
284 }, /* b<cond> B`foo 2,0 */
286 WF
+ 2, WB
+ 2, 4, C (2, 2)
287 }, /* brev over, brw W`foo, over: 2,1 */
290 }, /* brev over, jmp L`foo, over: 2,2 */
294 /* Another type of reversable branch. But this only has a word
301 }, /* jbX W`foo 3,1 */
304 }, /* jrevX over, jmp L`foo, over: 3,2 */
308 /* These are the non reversable branches, all of which have a word
309 displacement. If I can't reach, branch over a byte branch, to a
310 jump that will reach. The jumped branch jumps over the reaching
311 branch, to continue with the flow of the program. It's like playing
318 }, /* aobl_ W`foo 4,1 */
321 }, /*aobl_ W`hop,br over,hop: jmp L^foo,over 4,2*/
325 /* Normal displacement mode, no jumping or anything like that.
326 The relax points to one byte before the address, thats why all
327 the numbers are up by one. */
329 BF
+ 1, BB
+ 1, 2, C (5, 1)
332 WF
+ 1, WB
+ 1, 3, C (5, 2)
347 /* End relax stuff */
349 /* Handle of the OPCODE hash table. NULL means any use before
350 md_begin() will crash. */
351 static struct hash_control
*op_hash
;
353 /* Init function. Build the hash table. */
359 int synthetic_too
= 1; /* If 0, just use real opcodes. */
361 op_hash
= hash_new ();
363 for (tP
= totstrs
; *tP
->name
&& !errorval
; tP
++)
364 errorval
= hash_insert (op_hash
, tP
->name
, &tP
->detail
);
367 for (tP
= synthetic_totstrs
; *tP
->name
&& !errorval
; tP
++)
368 errorval
= hash_insert (op_hash
, tP
->name
, &tP
->detail
);
380 md_parse_option (argP
, cntP
, vecP
)
385 char *temp_name
; /* name for -t or -d options */
391 as_warn ("The -a option doesn't exits. (Dispite what the man page says!");
394 as_warn ("JUMPIFY (-J) not implemented, use psuedo ops instead.");
398 as_warn ("SYMBOL TABLE not implemented");
399 break; /* SYMBOL TABLE not implemented */
402 as_warn ("TOKEN TRACE not implemented");
403 break; /* TOKEN TRACE not implemented */
409 { /* Rest of argument is filename. */
419 temp_name
= *++(*vecP
);
420 **vecP
= NULL
; /* Remember this is not a file-name. */
424 as_warn ("I expected a filename after -%c.", opt
);
425 temp_name
= "{absent}";
429 as_warn ("Displacement length %s ignored!", temp_name
);
431 as_warn ("I don't need or use temp. file \"%s\".", temp_name
);
435 as_warn ("I don't use an interpass file! -V ignored");
445 /* The functions in this section take numbers in the machine format, and
446 munges them into Tahoe byte order.
447 They exist primarily for cross assembly purpose. */
448 void /* Knows about order of bytes in address. */
449 md_number_to_chars (con
, value
, nbytes
)
450 char con
[]; /* Return 'nbytes' of chars here. */
451 valueT value
; /* The value of the bits. */
452 int nbytes
; /* Number of bytes in the output. */
454 number_to_chars_bigendian (con
, value
, nbytes
);
458 void /* Knows about order of bytes in address. */
459 md_number_to_imm (con
, value
, nbytes
)
460 char con
[]; /* Return 'nbytes' of chars here. */
461 long int value
; /* The value of the bits. */
462 int nbytes
; /* Number of bytes in the output. */
464 md_number_to_chars (con
, value
, nbytes
);
470 tc_apply_fix (fixP
, val
)
474 /* should never be called */
478 void /* Knows about order of bytes in address. */
479 md_number_to_disp (con
, value
, nbytes
)
480 char con
[]; /* Return 'nbytes' of chars here. */
481 long int value
; /* The value of the bits. */
482 int nbytes
; /* Number of bytes in the output. */
484 md_number_to_chars (con
, value
, nbytes
);
487 void /* Knows about order of bytes in address. */
488 md_number_to_field (con
, value
, nbytes
)
489 char con
[]; /* Return 'nbytes' of chars here. */
490 long int value
; /* The value of the bits. */
491 int nbytes
; /* Number of bytes in the output. */
493 md_number_to_chars (con
, value
, nbytes
);
496 /* Put the bits in an order that a tahoe will understand, despite the ordering
497 of the native machine.
498 On Tahoe: first 4 bytes are normal unsigned big endian long,
499 next three bytes are symbolnum, in kind of 3 byte big endian (least sig. byte last).
500 The last byte is broken up with bit 7 as pcrel,
501 bits 6 & 5 as length,
502 bit 4 as extern and the last nibble as 'undefined'. */
506 md_ri_to_chars (ri_p
, ri
)
507 struct relocation_info
*ri_p
, ri
;
509 byte the_bytes
[sizeof (struct relocation_info
)];
510 /* The reason I can't just encode these directly into ri_p is that
511 ri_p may point to ri. */
514 md_number_to_chars (the_bytes
, ri
.r_address
, sizeof (ri
.r_address
));
516 /* now the fun stuff */
517 the_bytes
[4] = (ri
.r_symbolnum
>> 16) & 0x0ff;
518 the_bytes
[5] = (ri
.r_symbolnum
>> 8) & 0x0ff;
519 the_bytes
[6] = ri
.r_symbolnum
& 0x0ff;
520 the_bytes
[7] = (((ri
.r_extern
<< 4) & 0x10) | ((ri
.r_length
<< 5) & 0x60) |
521 ((ri
.r_pcrel
<< 7) & 0x80)) & 0xf0;
523 bcopy (the_bytes
, (char *) ri_p
, sizeof (struct relocation_info
));
528 /* Put the bits in an order that a tahoe will understand, despite the ordering
529 of the native machine.
530 On Tahoe: first 4 bytes are normal unsigned big endian long,
531 next three bytes are symbolnum, in kind of 3 byte big endian (least sig. byte last).
532 The last byte is broken up with bit 7 as pcrel,
533 bits 6 & 5 as length,
534 bit 4 as extern and the last nibble as 'undefined'. */
537 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
540 relax_addressT segment_address_in_file
;
544 know (fixP
->fx_addsy
!= NULL
);
546 md_number_to_chars (where
,
547 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
550 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
551 ? S_GET_TYPE (fixP
->fx_addsy
)
552 : fixP
->fx_addsy
->sy_number
);
554 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
555 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
556 where
[6] = r_symbolnum
& 0x0ff;
557 where
[7] = (((is_pcrel (fixP
) << 7) & 0x80)
558 | ((((fixP
->fx_type
== FX_8
|| fixP
->fx_type
== FX_PCREL8
560 : (fixP
->fx_type
== FX_16
|| fixP
->fx_type
== FX_PCREL16
562 : (fixP
->fx_type
== FX_32
|| fixP
->fx_type
== FX_PCREL32
564 : 42)))) << 5) & 0x60)
565 | ((!S_IS_DEFINED (fixP
->fx_addsy
) << 4) & 0x10));
568 /* Relocate byte stuff */
570 /* This is for broken word. */
571 const int md_short_jump_size
= 3;
574 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
576 addressT from_addr
, to_addr
;
582 offset
= to_addr
- (from_addr
+ 1);
584 md_number_to_chars (ptr
, offset
, 2);
587 const int md_long_jump_size
= 6;
588 const int md_reloc_size
= 8; /* Size of relocation record */
591 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
593 addressT from_addr
, to_addr
;
599 offset
= to_addr
- (from_addr
+ 4);
601 *ptr
++ = TAHOE_PC_REL_LONG
;
602 md_number_to_chars (ptr
, offset
, 4);
606 * md_estimate_size_before_relax()
608 * Called just before relax().
609 * Any symbol that is now undefined will not become defined, so we assumed
610 * that it will be resolved by the linker.
611 * Return the correct fr_subtype in the frag, for relax()
612 * Return the initial "guess for fr_var" to caller. (How big I think this
614 * The guess for fr_var is ACTUALLY the growth beyond fr_fix.
615 * Whatever we do to grow fr_fix or fr_var contributes to our returned value.
616 * Although it may not be explicit in the frag, pretend fr_var starts with a
620 md_estimate_size_before_relax (fragP
, segment_type
)
621 register fragS
*fragP
;
622 segT segment_type
; /* N_DATA or N_TEXT. */
625 register int old_fr_fix
;
626 /* int pc_rel; FIXME: remove this */
628 old_fr_fix
= fragP
->fr_fix
;
629 switch (fragP
->fr_subtype
)
631 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_UNDF
):
632 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
634 /* The symbol was in the same segment as the opcode, and it's
635 a real pc_rel case so it's a relaxable case. */
636 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
);
640 /* This case is still undefined, so asume it's a long word for the
642 p
= fragP
->fr_literal
+ old_fr_fix
;
643 *p
|= TAHOE_PC_OR_LONG
;
644 /* We now know how big it will be, one long word. */
645 fragP
->fr_fix
+= 1 + 4;
646 fix_new (fragP
, old_fr_fix
+ 1, fragP
->fr_symbol
,
647 fragP
->fr_offset
, FX_PCREL32
, NULL
);
652 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_UNDF
):
653 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
655 fragP
->fr_subtype
= ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
);
659 p
= fragP
->fr_literal
+ old_fr_fix
;
660 *fragP
->fr_opcode
^= 0x10; /* Reverse sense of branch. */
663 *p
++ = TAHOE_PC_REL_LONG
;
664 fragP
->fr_fix
+= 1 + 1 + 1 + 4;
665 fix_new (fragP
, old_fr_fix
+ 3, fragP
->fr_symbol
,
666 fragP
->fr_offset
, FX_PCREL32
, NULL
);
671 case ENCODE_RELAX (STATE_BIG_REV_BRANCH
, STATE_UNDF
):
672 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
675 ENCODE_RELAX (STATE_BIG_REV_BRANCH
, STATE_WORD
);
679 p
= fragP
->fr_literal
+ old_fr_fix
;
680 *fragP
->fr_opcode
^= 0x10; /* Reverse sense of branch. */
684 *p
++ = TAHOE_PC_REL_LONG
;
685 fragP
->fr_fix
+= 2 + 2 + 4;
686 fix_new (fragP
, old_fr_fix
+ 4, fragP
->fr_symbol
,
687 fragP
->fr_offset
, FX_PCREL32
, NULL
);
692 case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
, STATE_UNDF
):
693 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
695 fragP
->fr_subtype
= ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
, STATE_WORD
);
699 p
= fragP
->fr_literal
+ old_fr_fix
;
705 *p
++ = TAHOE_PC_REL_LONG
;
706 fragP
->fr_fix
+= 2 + 2 + 2 + 4;
707 fix_new (fragP
, old_fr_fix
+ 6, fragP
->fr_symbol
,
708 fragP
->fr_offset
, FX_PCREL32
, NULL
);
713 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_UNDF
):
714 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment_type
)
716 fragP
->fr_subtype
= ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
);
720 p
= fragP
->fr_literal
+ old_fr_fix
;
721 *fragP
->fr_opcode
= TAHOE_JMP
;
722 *p
++ = TAHOE_PC_REL_LONG
;
723 fragP
->fr_fix
+= 1 + 4;
724 fix_new (fragP
, old_fr_fix
+ 1, fragP
->fr_symbol
,
725 fragP
->fr_offset
, FX_PCREL32
, NULL
);
733 return (fragP
->fr_var
+ fragP
->fr_fix
- old_fr_fix
);
734 } /* md_estimate_size_before_relax() */
739 * Called after relax() is finished.
740 * In: Address of frag.
741 * fr_type == rs_machine_dependent.
742 * fr_subtype is what the address relaxed to.
744 * Out: Any fixSs and constants are set up.
745 * Caller will turn frag into a ".space 0".
748 md_convert_frag (headers
, fragP
)
749 object_headers
*headers
;
750 register fragS
*fragP
;
752 register char *addressP
; /* -> _var to change. */
753 register char *opcodeP
; /* -> opcode char(s) to change. */
754 register short int length_code
; /* 2=long 1=word 0=byte */
755 register short int extension
= 0; /* Size of relaxed address.
756 Added to fr_fix: incl. ALL var chars. */
757 register symbolS
*symbolP
;
758 register long int where
;
759 register long int address_of_var
;
760 /* Where, in file space, is _var of *fragP? */
761 register long int target_address
;
762 /* Where, in file space, does addr point? */
764 know (fragP
->fr_type
== rs_machine_dependent
);
765 length_code
= RELAX_LENGTH (fragP
->fr_subtype
);
766 know (length_code
>= 0 && length_code
< 3);
767 where
= fragP
->fr_fix
;
768 addressP
= fragP
->fr_literal
+ where
;
769 opcodeP
= fragP
->fr_opcode
;
770 symbolP
= fragP
->fr_symbol
;
772 target_address
= S_GET_VALUE (symbolP
) + fragP
->fr_offset
;
773 address_of_var
= fragP
->fr_address
+ where
;
774 switch (fragP
->fr_subtype
)
776 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
):
777 /* *addressP holds the registers number, plus 0x10, if it's deferred
778 mode. To set up the right mode, just OR the size of this displacement */
779 /* Byte displacement. */
780 *addressP
++ |= TAHOE_PC_OR_BYTE
;
781 *addressP
= target_address
- (address_of_var
+ 2);
785 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_WORD
):
786 /* Word displacement. */
787 *addressP
++ |= TAHOE_PC_OR_WORD
;
788 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 3), 2);
792 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_LONG
):
793 /* Long word displacement. */
794 *addressP
++ |= TAHOE_PC_OR_LONG
;
795 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 5), 4);
799 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
):
800 *addressP
= target_address
- (address_of_var
+ 1);
804 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_WORD
):
805 *opcodeP
^= 0x10; /* Reverse sense of test. */
806 *addressP
++ = 3; /* Jump over word branch */
807 *addressP
++ = TAHOE_BRW
;
808 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 4), 2);
812 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_LONG
):
813 *opcodeP
^= 0x10; /* Reverse sense of test. */
815 *addressP
++ = TAHOE_JMP
;
816 *addressP
++ = TAHOE_PC_REL_LONG
;
817 md_number_to_chars (addressP
, target_address
, 4);
821 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
):
822 *addressP
= target_address
- (address_of_var
+ 1);
826 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_WORD
):
827 *opcodeP
= TAHOE_BRW
;
828 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 2), 2);
832 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_LONG
):
833 *opcodeP
= TAHOE_JMP
;
834 *addressP
++ = TAHOE_PC_REL_LONG
;
835 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 5), 4);
839 case ENCODE_RELAX (STATE_BIG_REV_BRANCH
, STATE_WORD
):
840 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 2), 2);
844 case ENCODE_RELAX (STATE_BIG_REV_BRANCH
, STATE_LONG
):
848 *addressP
++ = TAHOE_JMP
;
849 *addressP
++ = TAHOE_PC_REL_LONG
;
850 md_number_to_chars (addressP
, target_address
, 4);
854 case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
, STATE_WORD
):
855 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 2), 2);
859 case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
, STATE_LONG
):
862 *addressP
++ = TAHOE_BRB
;
864 *addressP
++ = TAHOE_JMP
;
865 *addressP
++ = TAHOE_PC_REL_LONG
;
866 md_number_to_chars (addressP
, target_address
, 4);
871 BAD_CASE (fragP
->fr_subtype
);
874 fragP
->fr_fix
+= extension
;
875 } /* md_convert_frag */
878 /* This is the stuff for md_assemble. */
882 #define BIGGESTREG PC_REG
885 * Parse the string pointed to by START
886 * If it represents a valid register, point START to the character after
887 * the last valid register char, and return the register number (0-15).
888 * If invalid, leave START alone, return -1.
889 * The format has to be exact. I don't do things like eat leading zeros
891 * Note: This doesn't check for the next character in the string making
892 * this invalid. Ex: R123 would return 12, it's the callers job to check
893 * what start is point to apon return.
895 * Valid registers are R1-R15, %1-%15, FP (13), SP (14), PC (15)
896 * Case doesn't matter.
899 tahoe_reg_parse (start
)
900 char **start
; /* A pointer to the string to parse. */
902 register char *regpoint
= *start
;
903 register int regnum
= -1;
907 case '%': /* Registers can start with a %,
908 R or r, and then a number. */
911 if (isdigit (*regpoint
))
913 /* Got the first digit. */
914 regnum
= *regpoint
++ - '0';
915 if ((regnum
== 1) && isdigit (*regpoint
))
917 /* Its a two digit number. */
918 regnum
= 10 + (*regpoint
++ - '0');
919 if (regnum
> BIGGESTREG
)
920 { /* Number too big? */
926 case 'F': /* Is it the FP */
935 case 's': /* How about the SP */
944 case 'p': /* OR the PC even */
956 { /* No error, so move string pointer */
959 return regnum
; /* Return results */
960 } /* tahoe_reg_parse */
963 * This chops up an operand and figures out its modes and stuff.
964 * It's a little touchy about extra characters.
965 * Optex to start with one extra character so it can be overwritten for
966 * the backward part of the parsing.
967 * You can't put a bunch of extra characters in side to
968 * make the command look cute. ie: * foo ( r1 ) [ r0 ]
969 * If you like doing a lot of typing, try COBOL!
970 * Actually, this parser is a little weak all around. It's designed to be
971 * used with compliers, so I emphisise correct decoding of valid code quickly
972 * rather that catching every possable error.
973 * Note: This uses the expression function, so save input_line_pointer before
976 * Sperry defines the semantics of address modes (and values)
977 * by a two-letter code, explained here.
979 * letter 1: access type
981 * a address calculation - no data access, registers forbidden
982 * b branch displacement
983 * m read - let go of bus - write back "modify"
986 * v bit field address: like 'a' but registers are OK
988 * letter 2: data type (i.e. width, alignment)
993 * q quadword (Even regs < 14 allowed) (if 12, you get a warning)
994 * - unconditional synthetic jbr operand
995 * ? simple synthetic reversable branch operand
996 * ! complex synthetic reversable branch operand
997 * : complex synthetic non-reversable branch operand
999 * The '-?!:' letter 2's are not for external consumption. They are used
1000 * by GAS for psuedo ops relaxing code.
1002 * After parsing topP has:
1004 * top_ndx: -1, or the index register. eg 7=[R7]
1005 * top_reg: -1, or register number. eg 7 = R7 or (R7)
1006 * top_mode: The addressing mode byte. This byte, defines which of
1007 * the 11 modes opcode is.
1008 * top_access: Access type wanted for this opperand 'b'branch ' '
1009 * no-instruction 'amrvw'
1010 * top_width: Operand width expected, one of "bwlq?-:!"
1011 * exp_of_operand: The expression as parsed by expression()
1012 * top_dispsize: Number of bytes in the displacement if we can figure it
1013 * out and it's relavent.
1015 * Need syntax checks built.
1019 tip_op (optex
, topP
)
1020 char *optex
; /* The users text input, with one leading character */
1021 struct top
*topP
; /* The tahoe instruction with some fields already set:
1023 out: ndx, reg, mode, error, dispsize */
1026 int mode
= 0; /* This operand's mode. */
1027 char segfault
= *optex
; /* To keep the back parsing from freaking. */
1028 char *point
= optex
+ 1; /* Parsing from front to back. */
1029 char *end
; /* Parsing from back to front. */
1030 int reg
= -1; /* major register, -1 means absent */
1031 int imreg
= -1; /* Major register in immediate mode */
1032 int ndx
= -1; /* index register number, -1 means absent */
1033 char dec_inc
= ' '; /* Is the SP auto-incremented '+' or
1034 auto-decremented '-' or neither ' '. */
1035 int immediate
= 0; /* 1 if '$' immediate mode */
1036 int call_width
= 0; /* If the caller casts the displacement */
1037 int abs_width
= 0; /* The width of the absolute displacment */
1038 int com_width
= 0; /* Displacement width required by branch */
1039 int deferred
= 0; /* 1 if '*' deferral is used */
1040 byte disp_size
= 0; /* How big is this operand. 0 == don't know */
1041 char *op_bad
= ""; /* Bad operand error */
1043 char *tp
, *temp
, c
; /* Temporary holders */
1045 char access
= topP
->top_access
; /* Save on a deref. */
1046 char width
= topP
->top_width
;
1048 int really_none
= 0; /* Empty expressions evaluate to 0
1049 but I need to know if it's there or not */
1050 expressionS
*expP
; /* -> expression values for this operand */
1052 /* Does this command restrict the displacement size. */
1054 com_width
= (width
== 'b' ? 1 :
1056 (width
== 'l' ? 4 : 0)));
1058 *optex
= '\0'; /* This is kind of a back stop for all
1059 the searches to fail on if needed.*/
1061 { /* A dereference? */
1066 /* Force words into a certain mode */
1067 /* Bitch, Bitch, Bitch! */
1069 * Using the ^ operator is ambigous. If I have an absolute label
1070 * called 'w' set to, say 2, and I have the expression 'w^1', do I get
1071 * 1, forced to be in word displacement mode, or do I get the value of
1072 * 'w' or'ed with 1 (3 in this case).
1073 * The default is 'w' as an offset, so that's what I use.
1074 * Stick with `, it does the same, and isn't ambig.
1077 if (*point
!= '\0' && ((point
[1] == '^') || (point
[1] == '`')))
1087 as_warn ("Casting a branch displacement is bad form, and is ignored.");
1090 c
= (isupper (*point
) ? tolower (*point
) : *point
);
1091 call_width
= ((c
== 'b') ? 1 :
1092 ((c
== 'w') ? 2 : 4));
1098 /* Setting immediate mode */
1106 * I've pulled off all the easy stuff off the front, move to the end and
1110 for (end
= point
; *end
!= '\0'; end
++) /* Move to the end. */
1113 if (end
!= point
) /* Null string? */
1116 if (end
> point
&& *end
== ' ' && end
[-1] != '\'')
1117 end
--; /* Hop white space */
1119 /* Is this an index reg. */
1120 if ((*end
== ']') && (end
[-1] != '\''))
1124 /* Find opening brace. */
1125 for (--end
; (*end
!= '[' && end
!= point
); end
--)
1128 /* If I found the opening brace, get the index register number. */
1131 tp
= end
+ 1; /* tp should point to the start of a reg. */
1132 ndx
= tahoe_reg_parse (&tp
);
1134 { /* Reg. parse error. */
1139 end
--; /* Found it, move past brace. */
1143 op_bad
= "Couldn't parse the [index] in this operand.";
1144 end
= point
; /* Force all the rest of the tests to fail. */
1149 op_bad
= "Couldn't find the opening '[' for the index of this operand.";
1150 end
= point
; /* Force all the rest of the tests to fail. */
1154 /* Post increment? */
1162 /* register in parens? */
1163 if ((*end
== ')') && (end
[-1] != '\''))
1167 /* Find opening paren. */
1168 for (--end
; (*end
!= '(' && end
!= point
); end
--)
1171 /* If I found the opening paren, get the register number. */
1175 reg
= tahoe_reg_parse (&tp
);
1178 /* Not a register, but could be part of the expression. */
1180 end
= temp
; /* Rest the pointer back */
1184 end
--; /* Found the reg. move before opening paren. */
1189 op_bad
= "Couldn't find the opening '(' for the deref of this operand.";
1190 end
= point
; /* Force all the rest of the tests to fail. */
1194 /* Pre decrement? */
1199 op_bad
= "Operand can't be both pre-inc and post-dec.";
1211 * Everything between point and end is the 'expression', unless it's
1219 imreg
= tahoe_reg_parse (&point
); /* Get the immediate register
1223 /* If there is junk after point, then the it's not immediate reg. */
1228 if (imreg
!= -1 && reg
!= -1)
1229 op_bad
= "I parsed 2 registers in this operand.";
1232 * Evaluate whats left of the expression to see if it's valid.
1233 * Note again: This assumes that the calling expression has saved
1234 * input_line_pointer. (Nag, nag, nag!)
1237 if (*op_bad
== '\0')
1239 /* statement has no syntax goofs yet: lets sniff the expression */
1240 input_line_pointer
= point
;
1241 expP
= &(topP
->exp_of_operand
);
1242 topP
->seg_of_operand
= expression (expP
);
1246 /* No expression. For BSD4.2 compatibility, missing expression is
1248 expP
->X_op
= O_constant
;
1249 expP
->X_add_number
= 0;
1252 /* for SEG_ABSOLUTE, we shouldnt need to set X_op_symbol,
1253 X_add_symbol to any particular value. */
1254 /* But, we will program defensively. Since this situation occurs
1255 rarely so it costs us little to do so. */
1256 expP
->X_add_symbol
= NULL
;
1257 expP
->X_op_symbol
= NULL
;
1258 /* How many bytes are needed to express this abs value? */
1260 ((((expP
->X_add_number
& 0xFFFFFF80) == 0) ||
1261 ((expP
->X_add_number
& 0xFFFFFF80) == 0xFFFFFF80)) ? 1 :
1262 (((expP
->X_add_number
& 0xFFFF8000) == 0) ||
1263 ((expP
->X_add_number
& 0xFFFF8000) == 0xFFFF8000)) ? 2 : 4);
1270 * Major bug. We can't handle the case of a operator
1271 * expression in a synthetic opcode variable-length
1272 * instruction. We don't have a frag type that is smart
1273 * enough to relax a operator, and so we just force all
1274 * operators to behave like SEG_PASS1s. Clearly, if there is
1275 * a demand we can invent a new or modified frag type and
1276 * then coding up a frag for this case will be easy.
1279 op_bad
= "Can't relocate expression error.";
1283 /* This is an error. Tahoe doesn't allow any expressions
1284 bigger that a 32 bit long word. Any bigger has to be referenced
1286 op_bad
= "Expression is too large for a 32 bits.";
1289 if (*input_line_pointer
!= '\0')
1291 op_bad
= "Junk at end of expression.";
1297 /* I'm done, so restore optex */
1302 * At this point in the game, we (in theory) have all the components of
1303 * the operand at least parsed. Now it's time to check for syntax/semantic
1304 * errors, and build the mode.
1305 * This is what I have:
1306 * deferred = 1 if '*'
1307 * call_width = 0,1,2,4
1308 * abs_width = 0,1,2,4
1309 * com_width = 0,1,2,4
1310 * immediate = 1 if '$'
1311 * ndx = -1 or reg num
1312 * dec_inc = '-' or '+' or ' '
1313 * reg = -1 or reg num
1314 * imreg = -1 or reg num
1315 * topP->exp_of_operand
1318 /* Is there a displacement size? */
1319 disp_size
= (call_width
? call_width
:
1320 (com_width
? com_width
:
1321 abs_width
? abs_width
: 0));
1323 if (*op_bad
== '\0')
1328 mode
= TAHOE_DIRECT_REG
;
1329 if (deferred
|| immediate
|| (dec_inc
!= ' ') ||
1330 (reg
!= -1) || !really_none
)
1331 op_bad
= "Syntax error in direct register mode.";
1333 op_bad
= "You can't index a register in direct register mode.";
1334 else if (imreg
== SP_REG
&& access
== 'r')
1336 "SP can't be the source operand with direct register addressing.";
1337 else if (access
== 'a')
1338 op_bad
= "Can't take the address of a register.";
1339 else if (access
== 'b')
1340 op_bad
= "Direct Register can't be used in a branch.";
1341 else if (width
== 'q' && ((imreg
% 2) || (imreg
> 13)))
1342 op_bad
= "For quad access, the register must be even and < 14.";
1343 else if (call_width
)
1344 op_bad
= "You can't cast a direct register.";
1346 if (*op_bad
== '\0')
1348 /* No errors, check for warnings */
1349 if (width
== 'q' && imreg
== 12)
1350 as_warn ("Using reg 14 for quadwords can tromp the FP register.");
1355 /* We know: imm = -1 */
1357 else if (dec_inc
== '-')
1360 mode
= TAHOE_AUTO_DEC
;
1361 if (deferred
|| immediate
|| !really_none
)
1362 op_bad
= "Syntax error in auto-dec mode.";
1364 op_bad
= "You can't have an index auto dec mode.";
1365 else if (access
== 'r')
1366 op_bad
= "Auto dec mode cant be used for reading.";
1367 else if (reg
!= SP_REG
)
1368 op_bad
= "Auto dec only works of the SP register.";
1369 else if (access
== 'b')
1370 op_bad
= "Auto dec can't be used in a branch.";
1371 else if (width
== 'q')
1372 op_bad
= "Auto dec won't work with quadwords.";
1374 /* We know: imm = -1, dec_inc != '-' */
1376 else if (dec_inc
== '+')
1378 if (immediate
|| !really_none
)
1379 op_bad
= "Syntax error in one of the auto-inc modes.";
1383 mode
= TAHOE_AUTO_INC_DEFERRED
;
1385 op_bad
= "Auto inc deferred only works of the SP register.";
1387 op_bad
= "You can't have an index auto inc deferred mode.";
1388 else if (access
== 'b')
1389 op_bad
= "Auto inc can't be used in a branch.";
1394 mode
= TAHOE_AUTO_INC
;
1395 if (access
== 'm' || access
== 'w')
1396 op_bad
= "You can't write to an auto inc register.";
1397 else if (reg
!= SP_REG
)
1398 op_bad
= "Auto inc only works of the SP register.";
1399 else if (access
== 'b')
1400 op_bad
= "Auto inc can't be used in a branch.";
1401 else if (width
== 'q')
1402 op_bad
= "Auto inc won't work with quadwords.";
1404 op_bad
= "You can't have an index in auto inc mode.";
1407 /* We know: imm = -1, dec_inc == ' ' */
1411 if ((ndx
!= -1) && (reg
== SP_REG
))
1412 op_bad
= "You can't index the sp register.";
1416 mode
= TAHOE_REG_DISP_DEFERRED
;
1418 op_bad
= "Syntax error in register displaced mode.";
1420 else if (really_none
)
1423 mode
= TAHOE_REG_DEFERRED
;
1424 /* if reg = SP then cant be indexed */
1429 mode
= TAHOE_REG_DISP
;
1432 /* We know: imm = -1, dec_inc == ' ', Reg = -1 */
1437 op_bad
= "An offest is needed for this operand.";
1438 if (deferred
&& immediate
)
1441 mode
= TAHOE_ABSOLUTE_ADDR
;
1447 mode
= TAHOE_IMMEDIATE
;
1449 op_bad
= "You can't index a register in immediate mode.";
1451 op_bad
= "Immediate access can't be used as an address.";
1452 /* ponder the wisdom of a cast because it doesn't do any good. */
1457 mode
= TAHOE_DISP_REL_DEFERRED
;
1462 mode
= TAHOE_DISPLACED_RELATIVE
;
1468 * At this point, all the errors we can do have be checked for.
1469 * We can build the 'top'. */
1471 topP
->top_ndx
= ndx
;
1472 topP
->top_reg
= reg
;
1473 topP
->top_mode
= mode
;
1474 topP
->top_error
= op_bad
;
1475 topP
->top_dispsize
= disp_size
;
1481 * This converts a string into a tahoe instruction.
1482 * The string must be a bare single instruction in tahoe (with BSD4 frobs)
1484 * It provides at most one fatal error message (which stops the scan)
1485 * some warning messages as it finds them.
1486 * The tahoe instruction is returned in exploded form.
1488 * The exploded instruction is returned to a struct tit of your choice.
1489 * #include "tahoe-inst.h" to know what a struct tit is.
1494 tip (titP
, instring
)
1495 struct tit
*titP
; /* We build an exploded instruction here. */
1496 char *instring
; /* Text of a vax instruction: we modify. */
1498 register struct tot_wot
*twP
= NULL
; /* How to bit-encode this opcode. */
1499 register char *p
; /* 1/skip whitespace.2/scan vot_how */
1500 register char *q
; /* */
1501 register unsigned char count
; /* counts number of operands seen */
1502 register struct top
*operandp
;/* scan operands in struct tit */
1503 register char *alloperr
= ""; /* error over all operands */
1504 register char c
; /* Remember char, (we clobber it
1505 with '\0' temporarily). */
1506 char *save_input_line_pointer
;
1508 if (*instring
== ' ')
1509 ++instring
; /* Skip leading whitespace. */
1510 for (p
= instring
; *p
&& *p
!= ' '; p
++)
1511 ; /* MUST end in end-of-string or
1513 /* Scanned up to end of operation-code. */
1514 /* Operation-code is ended with whitespace. */
1517 titP
->tit_error
= "No operator";
1519 titP
->tit_opcode
= 0;
1526 * Here with instring pointing to what better be an op-name, and p
1527 * pointing to character just past that.
1528 * We trust instring points to an op-name, with no whitespace.
1530 twP
= (struct tot_wot
*) hash_find (op_hash
, instring
);
1531 *p
= c
; /* Restore char after op-code. */
1534 titP
->tit_error
= "Unknown operator";
1536 titP
->tit_opcode
= 0;
1541 * We found a match! So lets pick up as many operands as the
1542 * instruction wants, and even gripe if there are too many.
1543 * We expect comma to seperate each operand.
1544 * We let instring track the text, while p tracks a part of the
1548 count
= 0; /* no operands seen yet */
1549 instring
= p
+ (*p
!= '\0'); /* point past the operation code */
1550 /* tip_op() screws with the input_line_pointer, so save it before
1552 save_input_line_pointer
= input_line_pointer
;
1553 for (p
= twP
->args
, operandp
= titP
->tit_operand
;
1558 * Here to parse one operand. Leave instring pointing just
1559 * past any one ',' that marks the end of this operand.
1562 as_fatal ("Compiler bug: ODD number of bytes in arg structure %s.",
1566 for (q
= instring
; (*q
!= ',' && *q
!= '\0'); q
++)
1568 if (*q
== '\'' && q
[1] != '\0') /* Jump quoted characters */
1573 * Q points to ',' or '\0' that ends argument. C is that
1577 operandp
->top_access
= p
[0];
1578 operandp
->top_width
= p
[1];
1579 tip_op (instring
- 1, operandp
);
1580 *q
= c
; /* Restore input text. */
1581 if (*(operandp
->top_error
))
1583 alloperr
= operandp
->top_error
;
1585 instring
= q
+ (c
? 1 : 0); /* next operand (if any) */
1586 count
++; /* won another argument, may have an operr */
1589 alloperr
= "Not enough operands";
1591 /* Restore the pointer. */
1592 input_line_pointer
= save_input_line_pointer
;
1596 if (*instring
== ' ')
1597 instring
++; /* Skip whitespace. */
1599 alloperr
= "Too many operands";
1601 titP
->tit_error
= alloperr
;
1605 titP
->tit_opcode
= twP
->code
; /* The op-code. */
1606 titP
->tit_operands
= count
;
1609 /* md_assemble() emit frags for 1 instruction */
1611 md_assemble (instruction_string
)
1612 char *instruction_string
; /* A string: assemble 1 instruction. */
1615 register struct top
*operandP
;/* An operand. Scans all operands. */
1616 /* char c_save; fixme: remove this line *//* What used to live after an expression. */
1617 /* struct frag *fragP; fixme: remove this line *//* Fragment of code we just made. */
1618 /* register struct top *end_operandP; fixme: remove this line *//* -> slot just after last operand
1619 Limit of the for (each operand). */
1620 register expressionS
*expP
; /* -> expression values for this operand */
1622 /* These refer to an instruction operand expression. */
1623 segT to_seg
; /* Target segment of the address. */
1625 register valueT this_add_number
;
1626 register struct symbol
*this_add_symbol
; /* +ve (minuend) symbol. */
1628 /* tahoe_opcodeT opcode_as_number; fixme: remove this line *//* The opcode as a number. */
1629 char *opcodeP
; /* Where it is in a frag. */
1630 /* char *opmodeP; fixme: remove this line *//* Where opcode type is, in a frag. */
1632 int dispsize
; /* From top_dispsize: tahoe_operand_width
1634 int is_undefined
; /* 1 if operand expression's
1635 segment not known yet. */
1636 int pc_rel
; /* Is this operand pc relative? */
1638 /* Decode the operand. */
1639 tip (&t
, instruction_string
);
1642 * Check to see if this operand decode properly.
1643 * Notice that we haven't made any frags yet.
1644 * If it goofed, then this instruction will wedge in any pass,
1645 * and we can safely flush it, without causing interpass symbol phase
1646 * errors. That is, without changing label values in different passes.
1650 as_warn ("Ignoring statement due to \"%s\"", t
.tit_error
);
1654 /* We saw no errors in any operands - try to make frag(s) */
1656 /* Remember where it is, in case we want to modify the op-code later. */
1657 opcodeP
= frag_more (1);
1658 *opcodeP
= t
.tit_opcode
;
1659 /* Now do each operand. */
1660 for (operandP
= t
.tit_operand
;
1661 operandP
< t
.tit_operand
+ t
.tit_operands
;
1663 { /* for each operand */
1664 expP
= &(operandP
->exp_of_operand
);
1665 if (operandP
->top_ndx
>= 0)
1667 /* Indexed addressing byte
1668 Legality of indexed mode already checked: it is OK */
1669 FRAG_APPEND_1_CHAR (0x40 + operandP
->top_ndx
);
1670 } /* if(top_ndx>=0) */
1672 /* Here to make main operand frag(s). */
1673 this_add_number
= expP
->X_add_number
;
1674 this_add_symbol
= expP
->X_add_symbol
;
1675 to_seg
= operandP
->seg_of_operand
;
1676 know (to_seg
== SEG_UNKNOWN
|| \
1677 to_seg
== SEG_ABSOLUTE
|| \
1678 to_seg
== SEG_DATA
|| \
1679 to_seg
== SEG_TEXT
|| \
1681 is_undefined
= (to_seg
== SEG_UNKNOWN
);
1682 /* Do we know how big this opperand is? */
1683 dispsize
= operandP
->top_dispsize
;
1685 /* Deal with the branch possabilities. (Note, this doesn't include
1687 if (operandP
->top_access
== 'b')
1689 /* Branches must be expressions. A psuedo branch can also jump to
1690 an absolute address. */
1691 if (to_seg
== now_seg
|| is_undefined
)
1693 /* If is_undefined, then it might BECOME now_seg by relax time. */
1696 /* I know how big the branch is supposed to be (it's a normal
1697 branch), so I set up the frag, and let GAS do the rest. */
1698 p
= frag_more (dispsize
);
1699 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1700 this_add_symbol
, this_add_number
,
1701 size_to_fx (dispsize
, 1),
1706 /* (to_seg==now_seg || to_seg == SEG_UNKNOWN) && dispsize==0 */
1707 /* If we don't know how big it is, then its a synthetic branch,
1708 so we set up a simple relax state. */
1709 switch (operandP
->top_width
)
1711 case TAHOE_WIDTH_CONDITIONAL_JUMP
:
1712 /* Simple (conditional) jump. I may have to reverse the
1713 condition of opcodeP, and then jump to my destination.
1714 I set 1 byte aside for the branch off set, and could need 6
1715 more bytes for the pc_rel jump */
1716 frag_var (rs_machine_dependent
, 7, 1,
1717 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
,
1718 is_undefined
? STATE_UNDF
: STATE_BYTE
),
1719 this_add_symbol
, this_add_number
, opcodeP
);
1721 case TAHOE_WIDTH_ALWAYS_JUMP
:
1722 /* Simple (unconditional) jump. I may have to convert this to
1723 a word branch, or an absolute jump. */
1724 frag_var (rs_machine_dependent
, 5, 1,
1725 ENCODE_RELAX (STATE_ALWAYS_BRANCH
,
1726 is_undefined
? STATE_UNDF
: STATE_BYTE
),
1727 this_add_symbol
, this_add_number
, opcodeP
);
1729 /* The smallest size for the next 2 cases is word. */
1730 case TAHOE_WIDTH_BIG_REV_JUMP
:
1731 frag_var (rs_machine_dependent
, 8, 2,
1732 ENCODE_RELAX (STATE_BIG_REV_BRANCH
,
1733 is_undefined
? STATE_UNDF
: STATE_WORD
),
1734 this_add_symbol
, this_add_number
,
1737 case TAHOE_WIDTH_BIG_NON_REV_JUMP
:
1738 frag_var (rs_machine_dependent
, 10, 2,
1739 ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
,
1740 is_undefined
? STATE_UNDF
: STATE_WORD
),
1741 this_add_symbol
, this_add_number
,
1745 as_fatal ("Compliler bug: Got a case (%d) I wasn't expecting.",
1746 operandP
->top_width
);
1752 /* to_seg != now_seg && to_seg != seg_unknown (still in branch)
1753 In other words, I'm jumping out of my segment so extend the
1754 branches to jumps, and let GAS fix them. */
1756 /* These are "branches" what will always be branches around a jump
1757 to the correct addresss in real life.
1758 If to_seg is SEG_ABSOLUTE, just encode the branch in,
1759 else let GAS fix the address. */
1761 switch (operandP
->top_width
)
1764 For SEG_ABSOLUTE, then mode is ABSOLUTE_ADDR, jump
1765 to that addresss (not pc_rel).
1766 For other segs, address is a long word PC rel jump. */
1767 case TAHOE_WIDTH_CONDITIONAL_JUMP
:
1769 /* To reverse the condition in a TAHOE branch,
1775 *p
++ = (operandP
->top_mode
==
1776 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1778 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1779 this_add_symbol
, this_add_number
,
1780 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1787 case TAHOE_WIDTH_ALWAYS_JUMP
:
1788 /* br, just turn it into a jump */
1789 *opcodeP
= TAHOE_JMP
;
1791 *p
++ = (operandP
->top_mode
==
1792 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1794 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1795 this_add_symbol
, this_add_number
,
1796 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1797 /* Now (eg) JMP foo */
1799 case TAHOE_WIDTH_BIG_REV_JUMP
:
1805 *p
++ = (operandP
->top_mode
==
1806 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1808 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1809 this_add_symbol
, this_add_number
,
1810 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1817 case TAHOE_WIDTH_BIG_NON_REV_JUMP
:
1824 *p
++ = (operandP
->top_mode
==
1825 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1827 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1828 this_add_symbol
, this_add_number
,
1829 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1831 * Now (eg) xOBxxx 1f
1839 as_warn ("Real branch displacements must be expressions.");
1842 as_fatal ("Complier error: I got an unknown synthetic branch :%c",
1843 operandP
->top_width
);
1850 /* It ain't a branch operand. */
1851 switch (operandP
->top_mode
)
1853 /* Auto-foo access, only works for one reg (SP)
1854 so the only thing needed is the mode. */
1855 case TAHOE_AUTO_DEC
:
1856 case TAHOE_AUTO_INC
:
1857 case TAHOE_AUTO_INC_DEFERRED
:
1858 FRAG_APPEND_1_CHAR (operandP
->top_mode
);
1861 /* Numbered Register only access. Only thing needed is the
1862 mode + Register number */
1863 case TAHOE_DIRECT_REG
:
1864 case TAHOE_REG_DEFERRED
:
1865 FRAG_APPEND_1_CHAR (operandP
->top_mode
+ operandP
->top_reg
);
1868 /* An absolute address. It's size is always 5 bytes.
1869 (mode_type + 4 byte address). */
1870 case TAHOE_ABSOLUTE_ADDR
:
1871 know ((this_add_symbol
== NULL
));
1873 *p
= TAHOE_ABSOLUTE_ADDR
;
1874 md_number_to_chars (p
+ 1, this_add_number
, 4);
1877 /* Immediate data. If the size isn't known, then it's an address
1878 + and offset, which is 4 bytes big. */
1879 case TAHOE_IMMEDIATE
:
1880 if (this_add_symbol
!= NULL
)
1883 *p
++ = TAHOE_IMMEDIATE_LONGWORD
;
1884 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1885 this_add_symbol
, this_add_number
,
1890 /* It's a integer, and I know it's size. */
1891 if ((unsigned) this_add_number
< 0x40)
1893 /* Will it fit in a literal? */
1894 FRAG_APPEND_1_CHAR ((byte
) this_add_number
);
1898 p
= frag_more (dispsize
+ 1);
1902 *p
++ = TAHOE_IMMEDIATE_BYTE
;
1903 *p
= (byte
) this_add_number
;
1906 *p
++ = TAHOE_IMMEDIATE_WORD
;
1907 md_number_to_chars (p
, this_add_number
, 2);
1910 *p
++ = TAHOE_IMMEDIATE_LONGWORD
;
1911 md_number_to_chars (p
, this_add_number
, 4);
1918 /* Distance from the PC. If the size isn't known, we have to relax
1919 into it. The difference between this and disp(sp) is that
1920 this offset is pc_rel, and disp(sp) isn't.
1921 Note the drop through code. */
1923 case TAHOE_DISPLACED_RELATIVE
:
1924 case TAHOE_DISP_REL_DEFERRED
:
1925 operandP
->top_reg
= PC_REG
;
1928 /* Register, plus a displacement mode. Save the register number,
1929 and weather its deffered or not, and relax the size if it isn't
1931 case TAHOE_REG_DISP
:
1932 case TAHOE_REG_DISP_DEFERRED
:
1933 if (operandP
->top_mode
== TAHOE_DISP_REL_DEFERRED
||
1934 operandP
->top_mode
== TAHOE_REG_DISP_DEFERRED
)
1935 operandP
->top_reg
+= 0x10; /* deffered mode is always 0x10 higher
1936 than it's non-deffered sibling. */
1938 /* Is this a value out of this segment?
1939 The first part of this conditional is a cludge to make gas
1940 produce the same output as 'as' when there is a lable, in
1941 the current segment, displaceing a register. It's strange,
1942 and no one in their right mind would do it, but it's easy
1944 if ((dispsize
== 0 && !pc_rel
) ||
1945 (to_seg
!= now_seg
&& !is_undefined
&& to_seg
!= SEG_ABSOLUTE
))
1951 * We have a SEG_UNKNOWN symbol, or the size isn't cast.
1952 * It might turn out to be in the same segment as
1953 * the instruction, permitting relaxation.
1955 p
= frag_var (rs_machine_dependent
, 5, 2,
1956 ENCODE_RELAX (STATE_PC_RELATIVE
,
1957 is_undefined
? STATE_UNDF
: STATE_BYTE
),
1958 this_add_symbol
, this_add_number
, 0);
1959 *p
= operandP
->top_reg
;
1963 /* Either this is an abs, or a cast. */
1964 p
= frag_more (dispsize
+ 1);
1968 *p
= TAHOE_PC_OR_BYTE
+ operandP
->top_reg
;
1971 *p
= TAHOE_PC_OR_WORD
+ operandP
->top_reg
;
1974 *p
= TAHOE_PC_OR_LONG
+ operandP
->top_reg
;
1977 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
1978 this_add_symbol
, this_add_number
,
1979 size_to_fx (dispsize
, pc_rel
), NULL
);
1983 as_fatal ("Barf, bad mode %x\n", operandP
->top_mode
);
1986 } /* for(operandP) */
1987 } /* if(!need_pass_2 && !goofed) */
1988 } /* tahoe_assemble() */
1991 /* We have no need to default values of symbols. */
1995 md_undefined_symbol (name
)
1999 } /* md_undefined_symbol() */
2001 /* Parse an operand that is machine-specific.
2002 We just return without modifying the expression if we have nothing
2007 md_operand (expressionP
)
2008 expressionS
*expressionP
;
2010 } /* md_operand() */
2012 /* Round up a section size to the appropriate boundary. */
2014 md_section_align (segment
, size
)
2018 return ((size
+ 7) & ~7); /* Round all sects to multiple of 8 */
2019 } /* md_section_align() */
2021 /* Exactly what point is a PC-relative offset relative TO?
2022 On the sparc, they're relative to the address of the offset, plus
2023 its size. This gets us to the following instruction.
2024 (??? Is this right? FIXME-SOON) */
2026 md_pcrel_from (fixP
)
2029 return (((fixP
->fx_type
== FX_8
2030 || fixP
->fx_type
== FX_PCREL8
)
2032 : ((fixP
->fx_type
== FX_16
2033 || fixP
->fx_type
== FX_PCREL16
)
2035 : ((fixP
->fx_type
== FX_32
2036 || fixP
->fx_type
== FX_PCREL32
)
2038 : 0))) + fixP
->fx_where
+ fixP
->fx_frag
->fr_address
);
2039 } /* md_pcrel_from() */
2045 /* should never be called */
2048 } /* tc_is_pcrel() */
2050 /* end of tc-tahoe.c */