1 /* This file is tc-tahoe.c
3 Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1995, 2000, 2001, 2002
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 md_apply_fix3 (fixP
, valP
, seg
)
474 fixS
*fixP ATTRIBUTE_UNUSED
;
475 valueT
* valP ATTRIBUTE_UNUSED
;
476 segT seg ATTRIBUTE_UNUSED
:
478 /* Should never be called. */
482 void /* Knows about order of bytes in address. */
483 md_number_to_disp (con
, value
, nbytes
)
484 char con
[]; /* Return 'nbytes' of chars here. */
485 long int value
; /* The value of the bits. */
486 int nbytes
; /* Number of bytes in the output. */
488 md_number_to_chars (con
, value
, nbytes
);
491 void /* Knows about order of bytes in address. */
492 md_number_to_field (con
, value
, nbytes
)
493 char con
[]; /* Return 'nbytes' of chars here. */
494 long int value
; /* The value of the bits. */
495 int nbytes
; /* Number of bytes in the output. */
497 md_number_to_chars (con
, value
, nbytes
);
500 /* Put the bits in an order that a tahoe will understand, despite the ordering
501 of the native machine.
502 On Tahoe: first 4 bytes are normal unsigned big endian long,
503 next three bytes are symbolnum, in kind of 3 byte big endian (least sig. byte last).
504 The last byte is broken up with bit 7 as pcrel,
505 bits 6 & 5 as length,
506 bit 4 as extern and the last nibble as 'undefined'. */
510 md_ri_to_chars (ri_p
, ri
)
511 struct relocation_info
*ri_p
, ri
;
513 byte the_bytes
[sizeof (struct relocation_info
)];
514 /* The reason I can't just encode these directly into ri_p is that
515 ri_p may point to ri. */
518 md_number_to_chars (the_bytes
, ri
.r_address
, sizeof (ri
.r_address
));
520 /* now the fun stuff */
521 the_bytes
[4] = (ri
.r_symbolnum
>> 16) & 0x0ff;
522 the_bytes
[5] = (ri
.r_symbolnum
>> 8) & 0x0ff;
523 the_bytes
[6] = ri
.r_symbolnum
& 0x0ff;
524 the_bytes
[7] = (((ri
.r_extern
<< 4) & 0x10) | ((ri
.r_length
<< 5) & 0x60) |
525 ((ri
.r_pcrel
<< 7) & 0x80)) & 0xf0;
527 bcopy (the_bytes
, (char *) ri_p
, sizeof (struct relocation_info
));
532 /* Put the bits in an order that a tahoe will understand, despite the ordering
533 of the native machine.
534 On Tahoe: first 4 bytes are normal unsigned big endian long,
535 next three bytes are symbolnum, in kind of 3 byte big endian (least sig. byte last).
536 The last byte is broken up with bit 7 as pcrel,
537 bits 6 & 5 as length,
538 bit 4 as extern and the last nibble as 'undefined'. */
541 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
544 relax_addressT segment_address_in_file
;
548 know (fixP
->fx_addsy
!= NULL
);
550 md_number_to_chars (where
,
551 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
554 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
555 ? S_GET_TYPE (fixP
->fx_addsy
)
556 : fixP
->fx_addsy
->sy_number
);
558 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
559 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
560 where
[6] = r_symbolnum
& 0x0ff;
561 where
[7] = (((is_pcrel (fixP
) << 7) & 0x80)
562 | ((((fixP
->fx_type
== FX_8
|| fixP
->fx_type
== FX_PCREL8
564 : (fixP
->fx_type
== FX_16
|| fixP
->fx_type
== FX_PCREL16
566 : (fixP
->fx_type
== FX_32
|| fixP
->fx_type
== FX_PCREL32
568 : 42)))) << 5) & 0x60)
569 | ((!S_IS_DEFINED (fixP
->fx_addsy
) << 4) & 0x10));
572 /* Relocate byte stuff */
574 /* This is for broken word. */
575 const int md_short_jump_size
= 3;
578 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
580 addressT from_addr
, to_addr
;
586 offset
= to_addr
- (from_addr
+ 1);
588 md_number_to_chars (ptr
, offset
, 2);
591 const int md_long_jump_size
= 6;
592 const int md_reloc_size
= 8; /* Size of relocation record */
595 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
597 addressT from_addr
, to_addr
;
603 offset
= to_addr
- (from_addr
+ 4);
605 *ptr
++ = TAHOE_PC_REL_LONG
;
606 md_number_to_chars (ptr
, offset
, 4);
609 /* md_estimate_size_before_relax(), called just before relax().
610 Any symbol that is now undefined will not become defined.
611 Return the correct fr_subtype in the frag and the growth beyond
614 md_estimate_size_before_relax (fragP
, segment_type
)
615 register fragS
*fragP
;
616 segT segment_type
; /* N_DATA or N_TEXT. */
618 if (RELAX_LENGTH (fragP
->fr_subtype
) == STATE_UNDF
)
620 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
)
622 /* Non-relaxable cases. */
626 old_fr_fix
= fragP
->fr_fix
;
627 p
= fragP
->fr_literal
+ old_fr_fix
;
628 switch (RELAX_STATE (fragP
->fr_subtype
))
630 case STATE_PC_RELATIVE
:
631 *p
|= TAHOE_PC_OR_LONG
;
632 /* We now know how big it will be, one long word. */
633 fragP
->fr_fix
+= 1 + 4;
634 fix_new (fragP
, old_fr_fix
+ 1, fragP
->fr_symbol
,
635 fragP
->fr_offset
, FX_PCREL32
, NULL
);
638 case STATE_CONDITIONAL_BRANCH
:
639 *fragP
->fr_opcode
^= 0x10; /* Reverse sense of branch. */
642 *p
++ = TAHOE_PC_REL_LONG
;
643 fragP
->fr_fix
+= 1 + 1 + 1 + 4;
644 fix_new (fragP
, old_fr_fix
+ 3, fragP
->fr_symbol
,
645 fragP
->fr_offset
, FX_PCREL32
, NULL
);
648 case STATE_BIG_REV_BRANCH
:
649 *fragP
->fr_opcode
^= 0x10; /* Reverse sense of branch. */
653 *p
++ = TAHOE_PC_REL_LONG
;
654 fragP
->fr_fix
+= 2 + 2 + 4;
655 fix_new (fragP
, old_fr_fix
+ 4, fragP
->fr_symbol
,
656 fragP
->fr_offset
, FX_PCREL32
, NULL
);
659 case STATE_BIG_NON_REV_BRANCH
:
665 *p
++ = TAHOE_PC_REL_LONG
;
666 fragP
->fr_fix
+= 2 + 2 + 2 + 4;
667 fix_new (fragP
, old_fr_fix
+ 6, fragP
->fr_symbol
,
668 fragP
->fr_offset
, FX_PCREL32
, NULL
);
671 case STATE_ALWAYS_BRANCH
:
672 *fragP
->fr_opcode
= TAHOE_JMP
;
673 *p
++ = TAHOE_PC_REL_LONG
;
674 fragP
->fr_fix
+= 1 + 4;
675 fix_new (fragP
, old_fr_fix
+ 1, fragP
->fr_symbol
,
676 fragP
->fr_offset
, FX_PCREL32
, NULL
);
684 /* Return the growth in the fixed part of the frag. */
685 return fragP
->fr_fix
- old_fr_fix
;
688 /* Relaxable cases. Set up the initial guess for the variable
690 switch (RELAX_STATE (fragP
->fr_subtype
))
692 case STATE_PC_RELATIVE
:
693 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
);
695 case STATE_CONDITIONAL_BRANCH
:
696 fragP
->fr_subtype
= ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
);
698 case STATE_BIG_REV_BRANCH
:
699 fragP
->fr_subtype
= ENCODE_RELAX (STATE_BIG_REV_BRANCH
, STATE_WORD
);
701 case STATE_BIG_NON_REV_BRANCH
:
702 fragP
->fr_subtype
= ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
, STATE_WORD
);
704 case STATE_ALWAYS_BRANCH
:
705 fragP
->fr_subtype
= ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
);
710 if (fragP
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
713 /* Return the size of the variable part of the frag. */
714 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
720 * Called after relax() is finished.
721 * In: Address of frag.
722 * fr_type == rs_machine_dependent.
723 * fr_subtype is what the address relaxed to.
725 * Out: Any fixSs and constants are set up.
726 * Caller will turn frag into a ".space 0".
729 md_convert_frag (headers
, seg
, fragP
)
730 object_headers
*headers
;
732 register fragS
*fragP
;
734 register char *addressP
; /* -> _var to change. */
735 register char *opcodeP
; /* -> opcode char(s) to change. */
736 register short int extension
= 0; /* Size of relaxed address.
737 Added to fr_fix: incl. ALL var chars. */
738 register symbolS
*symbolP
;
739 register long int where
;
740 register long int address_of_var
;
741 /* Where, in file space, is _var of *fragP? */
742 register long int target_address
;
743 /* Where, in file space, does addr point? */
745 know (fragP
->fr_type
== rs_machine_dependent
);
746 where
= fragP
->fr_fix
;
747 addressP
= fragP
->fr_literal
+ where
;
748 opcodeP
= fragP
->fr_opcode
;
749 symbolP
= fragP
->fr_symbol
;
751 target_address
= S_GET_VALUE (symbolP
) + fragP
->fr_offset
;
752 address_of_var
= fragP
->fr_address
+ where
;
753 switch (fragP
->fr_subtype
)
755 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
):
756 /* *addressP holds the registers number, plus 0x10, if it's deferred
757 mode. To set up the right mode, just OR the size of this displacement */
758 /* Byte displacement. */
759 *addressP
++ |= TAHOE_PC_OR_BYTE
;
760 *addressP
= target_address
- (address_of_var
+ 2);
764 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_WORD
):
765 /* Word displacement. */
766 *addressP
++ |= TAHOE_PC_OR_WORD
;
767 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 3), 2);
771 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_LONG
):
772 /* Long word displacement. */
773 *addressP
++ |= TAHOE_PC_OR_LONG
;
774 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 5), 4);
778 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
):
779 *addressP
= target_address
- (address_of_var
+ 1);
783 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_WORD
):
784 *opcodeP
^= 0x10; /* Reverse sense of test. */
785 *addressP
++ = 3; /* Jump over word branch */
786 *addressP
++ = TAHOE_BRW
;
787 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 4), 2);
791 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_LONG
):
792 *opcodeP
^= 0x10; /* Reverse sense of test. */
794 *addressP
++ = TAHOE_JMP
;
795 *addressP
++ = TAHOE_PC_REL_LONG
;
796 md_number_to_chars (addressP
, target_address
, 4);
800 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
):
801 *addressP
= target_address
- (address_of_var
+ 1);
805 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_WORD
):
806 *opcodeP
= TAHOE_BRW
;
807 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 2), 2);
811 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_LONG
):
812 *opcodeP
= TAHOE_JMP
;
813 *addressP
++ = TAHOE_PC_REL_LONG
;
814 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 5), 4);
818 case ENCODE_RELAX (STATE_BIG_REV_BRANCH
, STATE_WORD
):
819 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 2), 2);
823 case ENCODE_RELAX (STATE_BIG_REV_BRANCH
, STATE_LONG
):
827 *addressP
++ = TAHOE_JMP
;
828 *addressP
++ = TAHOE_PC_REL_LONG
;
829 md_number_to_chars (addressP
, target_address
, 4);
833 case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
, STATE_WORD
):
834 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 2), 2);
838 case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
, STATE_LONG
):
841 *addressP
++ = TAHOE_BRB
;
843 *addressP
++ = TAHOE_JMP
;
844 *addressP
++ = TAHOE_PC_REL_LONG
;
845 md_number_to_chars (addressP
, target_address
, 4);
850 BAD_CASE (fragP
->fr_subtype
);
853 fragP
->fr_fix
+= extension
;
854 } /* md_convert_frag */
857 /* This is the stuff for md_assemble. */
861 #define BIGGESTREG PC_REG
864 * Parse the string pointed to by START
865 * If it represents a valid register, point START to the character after
866 * the last valid register char, and return the register number (0-15).
867 * If invalid, leave START alone, return -1.
868 * The format has to be exact. I don't do things like eat leading zeros
870 * Note: This doesn't check for the next character in the string making
871 * this invalid. Ex: R123 would return 12, it's the callers job to check
872 * what start is point to apon return.
874 * Valid registers are R1-R15, %1-%15, FP (13), SP (14), PC (15)
875 * Case doesn't matter.
878 tahoe_reg_parse (start
)
879 char **start
; /* A pointer to the string to parse. */
881 register char *regpoint
= *start
;
882 register int regnum
= -1;
886 case '%': /* Registers can start with a %,
887 R or r, and then a number. */
890 if (ISDIGIT (*regpoint
))
892 /* Got the first digit. */
893 regnum
= *regpoint
++ - '0';
894 if ((regnum
== 1) && ISDIGIT (*regpoint
))
896 /* Its a two digit number. */
897 regnum
= 10 + (*regpoint
++ - '0');
898 if (regnum
> BIGGESTREG
)
899 { /* Number too big? */
905 case 'F': /* Is it the FP */
914 case 's': /* How about the SP */
923 case 'p': /* OR the PC even */
935 { /* No error, so move string pointer */
938 return regnum
; /* Return results */
939 } /* tahoe_reg_parse */
942 * This chops up an operand and figures out its modes and stuff.
943 * It's a little touchy about extra characters.
944 * Optex to start with one extra character so it can be overwritten for
945 * the backward part of the parsing.
946 * You can't put a bunch of extra characters in side to
947 * make the command look cute. ie: * foo ( r1 ) [ r0 ]
948 * If you like doing a lot of typing, try COBOL!
949 * Actually, this parser is a little weak all around. It's designed to be
950 * used with compliers, so I emphisise correct decoding of valid code quickly
951 * rather that catching every possable error.
952 * Note: This uses the expression function, so save input_line_pointer before
955 * Sperry defines the semantics of address modes (and values)
956 * by a two-letter code, explained here.
958 * letter 1: access type
960 * a address calculation - no data access, registers forbidden
961 * b branch displacement
962 * m read - let go of bus - write back "modify"
965 * v bit field address: like 'a' but registers are OK
967 * letter 2: data type (i.e. width, alignment)
972 * q quadword (Even regs < 14 allowed) (if 12, you get a warning)
973 * - unconditional synthetic jbr operand
974 * ? simple synthetic reversable branch operand
975 * ! complex synthetic reversable branch operand
976 * : complex synthetic non-reversable branch operand
978 * The '-?!:' letter 2's are not for external consumption. They are used
979 * by GAS for psuedo ops relaxing code.
981 * After parsing topP has:
983 * top_ndx: -1, or the index register. eg 7=[R7]
984 * top_reg: -1, or register number. eg 7 = R7 or (R7)
985 * top_mode: The addressing mode byte. This byte, defines which of
986 * the 11 modes opcode is.
987 * top_access: Access type wanted for this opperand 'b'branch ' '
988 * no-instruction 'amrvw'
989 * top_width: Operand width expected, one of "bwlq?-:!"
990 * exp_of_operand: The expression as parsed by expression()
991 * top_dispsize: Number of bytes in the displacement if we can figure it
992 * out and it's relavent.
994 * Need syntax checks built.
999 char *optex
; /* The users text input, with one leading character */
1000 struct top
*topP
; /* The tahoe instruction with some fields already set:
1002 out: ndx, reg, mode, error, dispsize */
1005 int mode
= 0; /* This operand's mode. */
1006 char segfault
= *optex
; /* To keep the back parsing from freaking. */
1007 char *point
= optex
+ 1; /* Parsing from front to back. */
1008 char *end
; /* Parsing from back to front. */
1009 int reg
= -1; /* major register, -1 means absent */
1010 int imreg
= -1; /* Major register in immediate mode */
1011 int ndx
= -1; /* index register number, -1 means absent */
1012 char dec_inc
= ' '; /* Is the SP auto-incremented '+' or
1013 auto-decremented '-' or neither ' '. */
1014 int immediate
= 0; /* 1 if '$' immediate mode */
1015 int call_width
= 0; /* If the caller casts the displacement */
1016 int abs_width
= 0; /* The width of the absolute displacment */
1017 int com_width
= 0; /* Displacement width required by branch */
1018 int deferred
= 0; /* 1 if '*' deferral is used */
1019 byte disp_size
= 0; /* How big is this operand. 0 == don't know */
1020 char *op_bad
= ""; /* Bad operand error */
1022 char *tp
, *temp
, c
; /* Temporary holders */
1024 char access
= topP
->top_access
; /* Save on a deref. */
1025 char width
= topP
->top_width
;
1027 int really_none
= 0; /* Empty expressions evaluate to 0
1028 but I need to know if it's there or not */
1029 expressionS
*expP
; /* -> expression values for this operand */
1031 /* Does this command restrict the displacement size. */
1033 com_width
= (width
== 'b' ? 1 :
1035 (width
== 'l' ? 4 : 0)));
1037 *optex
= '\0'; /* This is kind of a back stop for all
1038 the searches to fail on if needed.*/
1040 { /* A dereference? */
1045 /* Force words into a certain mode */
1046 /* Bitch, Bitch, Bitch! */
1048 * Using the ^ operator is ambigous. If I have an absolute label
1049 * called 'w' set to, say 2, and I have the expression 'w^1', do I get
1050 * 1, forced to be in word displacement mode, or do I get the value of
1051 * 'w' or'ed with 1 (3 in this case).
1052 * The default is 'w' as an offset, so that's what I use.
1053 * Stick with `, it does the same, and isn't ambig.
1056 if (*point
!= '\0' && ((point
[1] == '^') || (point
[1] == '`')))
1066 as_warn (_("Casting a branch displacement is bad form, and is ignored."));
1069 c
= TOLOWER (*point
);
1070 call_width
= ((c
== 'b') ? 1 :
1071 ((c
== 'w') ? 2 : 4));
1077 /* Setting immediate mode */
1085 * I've pulled off all the easy stuff off the front, move to the end and
1089 for (end
= point
; *end
!= '\0'; end
++) /* Move to the end. */
1092 if (end
!= point
) /* Null string? */
1095 if (end
> point
&& *end
== ' ' && end
[-1] != '\'')
1096 end
--; /* Hop white space */
1098 /* Is this an index reg. */
1099 if ((*end
== ']') && (end
[-1] != '\''))
1103 /* Find opening brace. */
1104 for (--end
; (*end
!= '[' && end
!= point
); end
--)
1107 /* If I found the opening brace, get the index register number. */
1110 tp
= end
+ 1; /* tp should point to the start of a reg. */
1111 ndx
= tahoe_reg_parse (&tp
);
1113 { /* Reg. parse error. */
1118 end
--; /* Found it, move past brace. */
1122 op_bad
= _("Couldn't parse the [index] in this operand.");
1123 end
= point
; /* Force all the rest of the tests to fail. */
1128 op_bad
= _("Couldn't find the opening '[' for the index of this operand.");
1129 end
= point
; /* Force all the rest of the tests to fail. */
1133 /* Post increment? */
1141 /* register in parens? */
1142 if ((*end
== ')') && (end
[-1] != '\''))
1146 /* Find opening paren. */
1147 for (--end
; (*end
!= '(' && end
!= point
); end
--)
1150 /* If I found the opening paren, get the register number. */
1154 reg
= tahoe_reg_parse (&tp
);
1157 /* Not a register, but could be part of the expression. */
1159 end
= temp
; /* Rest the pointer back */
1163 end
--; /* Found the reg. move before opening paren. */
1168 op_bad
= _("Couldn't find the opening '(' for the deref of this operand.");
1169 end
= point
; /* Force all the rest of the tests to fail. */
1173 /* Pre decrement? */
1178 op_bad
= _("Operand can't be both pre-inc and post-dec.");
1190 * Everything between point and end is the 'expression', unless it's
1198 imreg
= tahoe_reg_parse (&point
); /* Get the immediate register
1202 /* If there is junk after point, then the it's not immediate reg. */
1207 if (imreg
!= -1 && reg
!= -1)
1208 op_bad
= _("I parsed 2 registers in this operand.");
1211 * Evaluate whats left of the expression to see if it's valid.
1212 * Note again: This assumes that the calling expression has saved
1213 * input_line_pointer. (Nag, nag, nag!)
1216 if (*op_bad
== '\0')
1218 /* Statement has no syntax goofs yet: let's sniff the expression. */
1219 input_line_pointer
= point
;
1220 expP
= &(topP
->exp_of_operand
);
1221 topP
->seg_of_operand
= expression (expP
);
1225 /* No expression. For BSD4.2 compatibility, missing expression is
1227 expP
->X_op
= O_constant
;
1228 expP
->X_add_number
= 0;
1231 /* for SEG_ABSOLUTE, we shouldnt need to set X_op_symbol,
1232 X_add_symbol to any particular value. */
1233 /* But, we will program defensively. Since this situation occurs
1234 rarely so it costs us little to do so. */
1235 expP
->X_add_symbol
= NULL
;
1236 expP
->X_op_symbol
= NULL
;
1237 /* How many bytes are needed to express this abs value? */
1239 ((((expP
->X_add_number
& 0xFFFFFF80) == 0) ||
1240 ((expP
->X_add_number
& 0xFFFFFF80) == 0xFFFFFF80)) ? 1 :
1241 (((expP
->X_add_number
& 0xFFFF8000) == 0) ||
1242 ((expP
->X_add_number
& 0xFFFF8000) == 0xFFFF8000)) ? 2 : 4);
1249 * Major bug. We can't handle the case of an operator
1250 * expression in a synthetic opcode variable-length
1251 * instruction. We don't have a frag type that is smart
1252 * enough to relax an operator, and so we just force all
1253 * operators to behave like SEG_PASS1s. Clearly, if there is
1254 * a demand we can invent a new or modified frag type and
1255 * then coding up a frag for this case will be easy.
1258 op_bad
= _("Can't relocate expression error.");
1262 /* This is an error. Tahoe doesn't allow any expressions
1263 bigger that a 32 bit long word. Any bigger has to be referenced
1265 op_bad
= _("Expression is too large for a 32 bits.");
1268 if (*input_line_pointer
!= '\0')
1270 op_bad
= _("Junk at end of expression.");
1276 /* I'm done, so restore optex */
1280 * At this point in the game, we (in theory) have all the components of
1281 * the operand at least parsed. Now it's time to check for syntax/semantic
1282 * errors, and build the mode.
1283 * This is what I have:
1284 * deferred = 1 if '*'
1285 * call_width = 0,1,2,4
1286 * abs_width = 0,1,2,4
1287 * com_width = 0,1,2,4
1288 * immediate = 1 if '$'
1289 * ndx = -1 or reg num
1290 * dec_inc = '-' or '+' or ' '
1291 * reg = -1 or reg num
1292 * imreg = -1 or reg num
1293 * topP->exp_of_operand
1296 /* Is there a displacement size? */
1297 disp_size
= (call_width
? call_width
:
1298 (com_width
? com_width
:
1299 abs_width
? abs_width
: 0));
1301 if (*op_bad
== '\0')
1306 mode
= TAHOE_DIRECT_REG
;
1307 if (deferred
|| immediate
|| (dec_inc
!= ' ') ||
1308 (reg
!= -1) || !really_none
)
1309 op_bad
= _("Syntax error in direct register mode.");
1311 op_bad
= _("You can't index a register in direct register mode.");
1312 else if (imreg
== SP_REG
&& access
== 'r')
1314 _("SP can't be the source operand with direct register addressing.");
1315 else if (access
== 'a')
1316 op_bad
= _("Can't take the address of a register.");
1317 else if (access
== 'b')
1318 op_bad
= _("Direct Register can't be used in a branch.");
1319 else if (width
== 'q' && ((imreg
% 2) || (imreg
> 13)))
1320 op_bad
= _("For quad access, the register must be even and < 14.");
1321 else if (call_width
)
1322 op_bad
= _("You can't cast a direct register.");
1324 if (*op_bad
== '\0')
1326 /* No errors, check for warnings */
1327 if (width
== 'q' && imreg
== 12)
1328 as_warn (_("Using reg 14 for quadwords can tromp the FP register."));
1333 /* We know: imm = -1 */
1335 else if (dec_inc
== '-')
1338 mode
= TAHOE_AUTO_DEC
;
1339 if (deferred
|| immediate
|| !really_none
)
1340 op_bad
= _("Syntax error in auto-dec mode.");
1342 op_bad
= _("You can't have an index auto dec mode.");
1343 else if (access
== 'r')
1344 op_bad
= _("Auto dec mode cant be used for reading.");
1345 else if (reg
!= SP_REG
)
1346 op_bad
= _("Auto dec only works of the SP register.");
1347 else if (access
== 'b')
1348 op_bad
= _("Auto dec can't be used in a branch.");
1349 else if (width
== 'q')
1350 op_bad
= _("Auto dec won't work with quadwords.");
1352 /* We know: imm = -1, dec_inc != '-' */
1354 else if (dec_inc
== '+')
1356 if (immediate
|| !really_none
)
1357 op_bad
= _("Syntax error in one of the auto-inc modes.");
1361 mode
= TAHOE_AUTO_INC_DEFERRED
;
1363 op_bad
= _("Auto inc deferred only works of the SP register.");
1365 op_bad
= _("You can't have an index auto inc deferred mode.");
1366 else if (access
== 'b')
1367 op_bad
= _("Auto inc can't be used in a branch.");
1372 mode
= TAHOE_AUTO_INC
;
1373 if (access
== 'm' || access
== 'w')
1374 op_bad
= _("You can't write to an auto inc register.");
1375 else if (reg
!= SP_REG
)
1376 op_bad
= _("Auto inc only works of the SP register.");
1377 else if (access
== 'b')
1378 op_bad
= _("Auto inc can't be used in a branch.");
1379 else if (width
== 'q')
1380 op_bad
= _("Auto inc won't work with quadwords.");
1382 op_bad
= _("You can't have an index in auto inc mode.");
1385 /* We know: imm = -1, dec_inc == ' ' */
1389 if ((ndx
!= -1) && (reg
== SP_REG
))
1390 op_bad
= _("You can't index the sp register.");
1394 mode
= TAHOE_REG_DISP_DEFERRED
;
1396 op_bad
= _("Syntax error in register displaced mode.");
1398 else if (really_none
)
1401 mode
= TAHOE_REG_DEFERRED
;
1402 /* if reg = SP then cant be indexed */
1407 mode
= TAHOE_REG_DISP
;
1410 /* We know: imm = -1, dec_inc == ' ', Reg = -1 */
1415 op_bad
= _("An offest is needed for this operand.");
1416 if (deferred
&& immediate
)
1419 mode
= TAHOE_ABSOLUTE_ADDR
;
1425 mode
= TAHOE_IMMEDIATE
;
1427 op_bad
= _("You can't index a register in immediate mode.");
1429 op_bad
= _("Immediate access can't be used as an address.");
1430 /* ponder the wisdom of a cast because it doesn't do any good. */
1435 mode
= TAHOE_DISP_REL_DEFERRED
;
1440 mode
= TAHOE_DISPLACED_RELATIVE
;
1446 * At this point, all the errors we can do have be checked for.
1447 * We can build the 'top'. */
1449 topP
->top_ndx
= ndx
;
1450 topP
->top_reg
= reg
;
1451 topP
->top_mode
= mode
;
1452 topP
->top_error
= op_bad
;
1453 topP
->top_dispsize
= disp_size
;
1459 * This converts a string into a tahoe instruction.
1460 * The string must be a bare single instruction in tahoe (with BSD4 frobs)
1462 * It provides at most one fatal error message (which stops the scan)
1463 * some warning messages as it finds them.
1464 * The tahoe instruction is returned in exploded form.
1466 * The exploded instruction is returned to a struct tit of your choice.
1467 * #include "tahoe-inst.h" to know what a struct tit is.
1472 tip (titP
, instring
)
1473 struct tit
*titP
; /* We build an exploded instruction here. */
1474 char *instring
; /* Text of a vax instruction: we modify. */
1476 register struct tot_wot
*twP
= NULL
; /* How to bit-encode this opcode. */
1477 register char *p
; /* 1/skip whitespace.2/scan vot_how */
1478 register char *q
; /* */
1479 register unsigned char count
; /* counts number of operands seen */
1480 register struct top
*operandp
;/* scan operands in struct tit */
1481 register char *alloperr
= ""; /* error over all operands */
1482 register char c
; /* Remember char, (we clobber it
1483 with '\0' temporarily). */
1484 char *save_input_line_pointer
;
1486 if (*instring
== ' ')
1487 ++instring
; /* Skip leading whitespace. */
1488 for (p
= instring
; *p
&& *p
!= ' '; p
++)
1489 ; /* MUST end in end-of-string or
1491 /* Scanned up to end of operation-code. */
1492 /* Operation-code is ended with whitespace. */
1495 titP
->tit_error
= _("No operator");
1497 titP
->tit_opcode
= 0;
1504 * Here with instring pointing to what better be an op-name, and p
1505 * pointing to character just past that.
1506 * We trust instring points to an op-name, with no whitespace.
1508 twP
= (struct tot_wot
*) hash_find (op_hash
, instring
);
1509 *p
= c
; /* Restore char after op-code. */
1512 titP
->tit_error
= _("Unknown operator");
1514 titP
->tit_opcode
= 0;
1519 * We found a match! So let's pick up as many operands as the
1520 * instruction wants, and even gripe if there are too many.
1521 * We expect comma to seperate each operand.
1522 * We let instring track the text, while p tracks a part of the
1526 count
= 0; /* no operands seen yet */
1527 instring
= p
+ (*p
!= '\0'); /* point past the operation code */
1528 /* tip_op() screws with the input_line_pointer, so save it before
1530 save_input_line_pointer
= input_line_pointer
;
1531 for (p
= twP
->args
, operandp
= titP
->tit_operand
;
1536 * Here to parse one operand. Leave instring pointing just
1537 * past any one ',' that marks the end of this operand.
1540 as_fatal (_("Compiler bug: ODD number of bytes in arg structure %s."),
1544 for (q
= instring
; (*q
!= ',' && *q
!= '\0'); q
++)
1546 if (*q
== '\'' && q
[1] != '\0') /* Jump quoted characters */
1551 * Q points to ',' or '\0' that ends argument. C is that
1555 operandp
->top_access
= p
[0];
1556 operandp
->top_width
= p
[1];
1557 tip_op (instring
- 1, operandp
);
1558 *q
= c
; /* Restore input text. */
1559 if (*(operandp
->top_error
))
1561 alloperr
= operandp
->top_error
;
1563 instring
= q
+ (c
? 1 : 0); /* next operand (if any) */
1564 count
++; /* won another argument, may have an operr */
1567 alloperr
= _("Not enough operands");
1569 /* Restore the pointer. */
1570 input_line_pointer
= save_input_line_pointer
;
1574 if (*instring
== ' ')
1575 instring
++; /* Skip whitespace. */
1577 alloperr
= _("Too many operands");
1579 titP
->tit_error
= alloperr
;
1583 titP
->tit_opcode
= twP
->code
; /* The op-code. */
1584 titP
->tit_operands
= count
;
1587 /* md_assemble() emit frags for 1 instruction */
1589 md_assemble (instruction_string
)
1590 char *instruction_string
; /* A string: assemble 1 instruction. */
1593 register struct top
*operandP
;/* An operand. Scans all operands. */
1594 /* char c_save; fixme: remove this line *//* What used to live after an expression. */
1595 /* struct frag *fragP; fixme: remove this line *//* Fragment of code we just made. */
1596 /* register struct top *end_operandP; fixme: remove this line *//* -> slot just after last operand
1597 Limit of the for (each operand). */
1598 register expressionS
*expP
; /* -> expression values for this operand */
1600 /* These refer to an instruction operand expression. */
1601 segT to_seg
; /* Target segment of the address. */
1603 register valueT this_add_number
;
1604 register symbolS
*this_add_symbol
; /* +ve (minuend) symbol. */
1606 /* tahoe_opcodeT opcode_as_number; fixme: remove this line *//* The opcode as a number. */
1607 char *opcodeP
; /* Where it is in a frag. */
1608 /* char *opmodeP; fixme: remove this line *//* Where opcode type is, in a frag. */
1610 int dispsize
; /* From top_dispsize: tahoe_operand_width
1612 int is_undefined
; /* 1 if operand expression's
1613 segment not known yet. */
1614 int pc_rel
; /* Is this operand pc relative? */
1616 /* Decode the operand. */
1617 tip (&t
, instruction_string
);
1620 * Check to see if this operand decode properly.
1621 * Notice that we haven't made any frags yet.
1622 * If it goofed, then this instruction will wedge in any pass,
1623 * and we can safely flush it, without causing interpass symbol phase
1624 * errors. That is, without changing label values in different passes.
1628 as_warn (_("Ignoring statement due to \"%s\""), t
.tit_error
);
1632 /* We saw no errors in any operands - try to make frag(s) */
1634 /* Remember where it is, in case we want to modify the op-code later. */
1635 opcodeP
= frag_more (1);
1636 *opcodeP
= t
.tit_opcode
;
1637 /* Now do each operand. */
1638 for (operandP
= t
.tit_operand
;
1639 operandP
< t
.tit_operand
+ t
.tit_operands
;
1641 { /* for each operand */
1642 expP
= &(operandP
->exp_of_operand
);
1643 if (operandP
->top_ndx
>= 0)
1645 /* Indexed addressing byte
1646 Legality of indexed mode already checked: it is OK */
1647 FRAG_APPEND_1_CHAR (0x40 + operandP
->top_ndx
);
1648 } /* if(top_ndx>=0) */
1650 /* Here to make main operand frag(s). */
1651 this_add_number
= expP
->X_add_number
;
1652 this_add_symbol
= expP
->X_add_symbol
;
1653 to_seg
= operandP
->seg_of_operand
;
1654 know (to_seg
== SEG_UNKNOWN
|| \
1655 to_seg
== SEG_ABSOLUTE
|| \
1656 to_seg
== SEG_DATA
|| \
1657 to_seg
== SEG_TEXT
|| \
1659 is_undefined
= (to_seg
== SEG_UNKNOWN
);
1660 /* Do we know how big this opperand is? */
1661 dispsize
= operandP
->top_dispsize
;
1663 /* Deal with the branch possabilities. (Note, this doesn't include
1665 if (operandP
->top_access
== 'b')
1667 /* Branches must be expressions. A psuedo branch can also jump to
1668 an absolute address. */
1669 if (to_seg
== now_seg
|| is_undefined
)
1671 /* If is_undefined, then it might BECOME now_seg by relax time. */
1674 /* I know how big the branch is supposed to be (it's a normal
1675 branch), so I set up the frag, and let GAS do the rest. */
1676 p
= frag_more (dispsize
);
1677 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1678 this_add_symbol
, this_add_number
,
1679 size_to_fx (dispsize
, 1),
1684 /* (to_seg==now_seg || to_seg == SEG_UNKNOWN) && dispsize==0 */
1685 /* If we don't know how big it is, then its a synthetic branch,
1686 so we set up a simple relax state. */
1687 switch (operandP
->top_width
)
1689 case TAHOE_WIDTH_CONDITIONAL_JUMP
:
1690 /* Simple (conditional) jump. I may have to reverse the
1691 condition of opcodeP, and then jump to my destination.
1692 I set 1 byte aside for the branch off set, and could need 6
1693 more bytes for the pc_rel jump */
1694 frag_var (rs_machine_dependent
, 7, 1,
1695 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
,
1696 is_undefined
? STATE_UNDF
: STATE_BYTE
),
1697 this_add_symbol
, this_add_number
, opcodeP
);
1699 case TAHOE_WIDTH_ALWAYS_JUMP
:
1700 /* Simple (unconditional) jump. I may have to convert this to
1701 a word branch, or an absolute jump. */
1702 frag_var (rs_machine_dependent
, 5, 1,
1703 ENCODE_RELAX (STATE_ALWAYS_BRANCH
,
1704 is_undefined
? STATE_UNDF
: STATE_BYTE
),
1705 this_add_symbol
, this_add_number
, opcodeP
);
1707 /* The smallest size for the next 2 cases is word. */
1708 case TAHOE_WIDTH_BIG_REV_JUMP
:
1709 frag_var (rs_machine_dependent
, 8, 2,
1710 ENCODE_RELAX (STATE_BIG_REV_BRANCH
,
1711 is_undefined
? STATE_UNDF
: STATE_WORD
),
1712 this_add_symbol
, this_add_number
,
1715 case TAHOE_WIDTH_BIG_NON_REV_JUMP
:
1716 frag_var (rs_machine_dependent
, 10, 2,
1717 ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH
,
1718 is_undefined
? STATE_UNDF
: STATE_WORD
),
1719 this_add_symbol
, this_add_number
,
1723 as_fatal (_("Compliler bug: Got a case (%d) I wasn't expecting."),
1724 operandP
->top_width
);
1730 /* to_seg != now_seg && to_seg != seg_unknown (still in branch)
1731 In other words, I'm jumping out of my segment so extend the
1732 branches to jumps, and let GAS fix them. */
1734 /* These are "branches" what will always be branches around a jump
1735 to the correct addresss in real life.
1736 If to_seg is SEG_ABSOLUTE, just encode the branch in,
1737 else let GAS fix the address. */
1739 switch (operandP
->top_width
)
1742 For SEG_ABSOLUTE, then mode is ABSOLUTE_ADDR, jump
1743 to that addresss (not pc_rel).
1744 For other segs, address is a long word PC rel jump. */
1745 case TAHOE_WIDTH_CONDITIONAL_JUMP
:
1747 /* To reverse the condition in a TAHOE branch,
1753 *p
++ = (operandP
->top_mode
==
1754 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1756 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1757 this_add_symbol
, this_add_number
,
1758 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1765 case TAHOE_WIDTH_ALWAYS_JUMP
:
1766 /* br, just turn it into a jump */
1767 *opcodeP
= TAHOE_JMP
;
1769 *p
++ = (operandP
->top_mode
==
1770 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1772 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1773 this_add_symbol
, this_add_number
,
1774 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1775 /* Now (eg) JMP foo */
1777 case TAHOE_WIDTH_BIG_REV_JUMP
:
1783 *p
++ = (operandP
->top_mode
==
1784 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1786 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1787 this_add_symbol
, this_add_number
,
1788 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1795 case TAHOE_WIDTH_BIG_NON_REV_JUMP
:
1802 *p
++ = (operandP
->top_mode
==
1803 TAHOE_ABSOLUTE_ADDR
? TAHOE_ABSOLUTE_ADDR
:
1805 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1806 this_add_symbol
, this_add_number
,
1807 (to_seg
!= SEG_ABSOLUTE
) ? FX_PCREL32
: FX_32
, NULL
);
1809 * Now (eg) xOBxxx 1f
1817 as_warn (_("Real branch displacements must be expressions."));
1820 as_fatal (_("Complier error: I got an unknown synthetic branch :%c"),
1821 operandP
->top_width
);
1828 /* It ain't a branch operand. */
1829 switch (operandP
->top_mode
)
1831 /* Auto-foo access, only works for one reg (SP)
1832 so the only thing needed is the mode. */
1833 case TAHOE_AUTO_DEC
:
1834 case TAHOE_AUTO_INC
:
1835 case TAHOE_AUTO_INC_DEFERRED
:
1836 FRAG_APPEND_1_CHAR (operandP
->top_mode
);
1839 /* Numbered Register only access. Only thing needed is the
1840 mode + Register number */
1841 case TAHOE_DIRECT_REG
:
1842 case TAHOE_REG_DEFERRED
:
1843 FRAG_APPEND_1_CHAR (operandP
->top_mode
+ operandP
->top_reg
);
1846 /* An absolute address. It's size is always 5 bytes.
1847 (mode_type + 4 byte address). */
1848 case TAHOE_ABSOLUTE_ADDR
:
1849 know ((this_add_symbol
== NULL
));
1851 *p
= TAHOE_ABSOLUTE_ADDR
;
1852 md_number_to_chars (p
+ 1, this_add_number
, 4);
1855 /* Immediate data. If the size isn't known, then it's an address
1856 + and offset, which is 4 bytes big. */
1857 case TAHOE_IMMEDIATE
:
1858 if (this_add_symbol
!= NULL
)
1861 *p
++ = TAHOE_IMMEDIATE_LONGWORD
;
1862 fix_new (frag_now
, p
- frag_now
->fr_literal
,
1863 this_add_symbol
, this_add_number
,
1868 /* It's an integer, and I know it's size. */
1869 if ((unsigned) this_add_number
< 0x40)
1871 /* Will it fit in a literal? */
1872 FRAG_APPEND_1_CHAR ((byte
) this_add_number
);
1876 p
= frag_more (dispsize
+ 1);
1880 *p
++ = TAHOE_IMMEDIATE_BYTE
;
1881 *p
= (byte
) this_add_number
;
1884 *p
++ = TAHOE_IMMEDIATE_WORD
;
1885 md_number_to_chars (p
, this_add_number
, 2);
1888 *p
++ = TAHOE_IMMEDIATE_LONGWORD
;
1889 md_number_to_chars (p
, this_add_number
, 4);
1896 /* Distance from the PC. If the size isn't known, we have to relax
1897 into it. The difference between this and disp(sp) is that
1898 this offset is pc_rel, and disp(sp) isn't.
1899 Note the drop through code. */
1901 case TAHOE_DISPLACED_RELATIVE
:
1902 case TAHOE_DISP_REL_DEFERRED
:
1903 operandP
->top_reg
= PC_REG
;
1906 /* Register, plus a displacement mode. Save the register number,
1907 and weather its deffered or not, and relax the size if it isn't
1909 case TAHOE_REG_DISP
:
1910 case TAHOE_REG_DISP_DEFERRED
:
1911 if (operandP
->top_mode
== TAHOE_DISP_REL_DEFERRED
||
1912 operandP
->top_mode
== TAHOE_REG_DISP_DEFERRED
)
1913 operandP
->top_reg
+= 0x10; /* deffered mode is always 0x10 higher
1914 than it's non-deffered sibling. */
1916 /* Is this a value out of this segment?
1917 The first part of this conditional is a cludge to make gas
1918 produce the same output as 'as' when there is a lable, in
1919 the current segment, displaceing a register. It's strange,
1920 and no one in their right mind would do it, but it's easy
1922 if ((dispsize
== 0 && !pc_rel
) ||
1923 (to_seg
!= now_seg
&& !is_undefined
&& to_seg
!= SEG_ABSOLUTE
))
1929 * We have a SEG_UNKNOWN symbol, or the size isn't cast.
1930 * It might turn out to be in the same segment as
1931 * the instruction, permitting relaxation.
1933 p
= frag_var (rs_machine_dependent
, 5, 2,
1934 ENCODE_RELAX (STATE_PC_RELATIVE
,
1935 is_undefined
? STATE_UNDF
: STATE_BYTE
),
1936 this_add_symbol
, this_add_number
, 0);
1937 *p
= operandP
->top_reg
;
1941 /* Either this is an abs, or a cast. */
1942 p
= frag_more (dispsize
+ 1);
1946 *p
= TAHOE_PC_OR_BYTE
+ operandP
->top_reg
;
1949 *p
= TAHOE_PC_OR_WORD
+ operandP
->top_reg
;
1952 *p
= TAHOE_PC_OR_LONG
+ operandP
->top_reg
;
1955 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
1956 this_add_symbol
, this_add_number
,
1957 size_to_fx (dispsize
, pc_rel
), NULL
);
1961 as_fatal (_("Barf, bad mode %x\n"), operandP
->top_mode
);
1964 } /* for(operandP) */
1965 } /* if(!need_pass_2 && !goofed) */
1966 } /* tahoe_assemble() */
1968 /* We have no need to default values of symbols. */
1971 md_undefined_symbol (name
)
1975 } /* md_undefined_symbol() */
1977 /* Round up a section size to the appropriate boundary. */
1979 md_section_align (segment
, size
)
1983 return ((size
+ 7) & ~7); /* Round all sects to multiple of 8 */
1984 } /* md_section_align() */
1986 /* Exactly what point is a PC-relative offset relative TO?
1987 On the sparc, they're relative to the address of the offset, plus
1988 its size. This gets us to the following instruction.
1989 (??? Is this right? FIXME-SOON) */
1991 md_pcrel_from (fixP
)
1994 return (((fixP
->fx_type
== FX_8
1995 || fixP
->fx_type
== FX_PCREL8
)
1997 : ((fixP
->fx_type
== FX_16
1998 || fixP
->fx_type
== FX_PCREL16
)
2000 : ((fixP
->fx_type
== FX_32
2001 || fixP
->fx_type
== FX_PCREL32
)
2003 : 0))) + fixP
->fx_where
+ fixP
->fx_frag
->fr_address
);
2004 } /* md_pcrel_from() */
2010 /* should never be called */
2013 } /* tc_is_pcrel() */